From 15e7723477271111fd893a4ae9e30efc8990dbe1 Mon Sep 17 00:00:00 2001 From: Matteo Paonessa Date: Thu, 23 Jun 2022 13:14:15 +0200 Subject: [PATCH] Input components fix --- Cargo.toml | 6 +++++- src/jpeg.rs | 18 ++++++++++++++---- src/main.rs | 12 ++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 src/main.rs diff --git a/Cargo.toml b/Cargo.toml index 45459ac..f91d078 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libcaesium" -version = "0.8.2" +version = "0.8.3" authors = ["Matteo Paonessa "] edition = "2021" categories = ["multimedia::images"] @@ -36,6 +36,10 @@ bytes = "1.1" dssim = "3.2.0" kamadak-exif = "0.5.4" +[[bin]] +name = "main" +path = "src/main.rs" + [lib] name = "caesium" path = "src/lib.rs" diff --git a/src/jpeg.rs b/src/jpeg.rs index ef7dbaa..d0c98c2 100644 --- a/src/jpeg.rs +++ b/src/jpeg.rs @@ -1,11 +1,13 @@ -use std::fs::File; use std::{io, mem}; -use mozjpeg_sys::*; -use crate::CSParameters; use std::fs; +use std::fs::File; use std::io::Write; + use image::ImageOutputFormat::Jpeg; use img_parts::{DynImage, ImageEXIF, ImageICC}; +use mozjpeg_sys::*; + +use crate::CSParameters; use crate::resize::resize; pub struct Parameters { @@ -134,7 +136,15 @@ unsafe fn lossy(in_file: Vec, parameters: CSParameters) -> Result<(*mut u8, dst_info.image_width = width; dst_info.image_height = height; dst_info.in_color_space = color_space; - dst_info.input_components = if color_space == J_COLOR_SPACE::JCS_GRAYSCALE { 1 } else { 3 }; + let input_components = match color_space { + J_COLOR_SPACE::JCS_GRAYSCALE => 1, + J_COLOR_SPACE::JCS_RGB => 3, + J_COLOR_SPACE::JCS_YCbCr => 3, + J_COLOR_SPACE::JCS_CMYK => 4, + J_COLOR_SPACE::JCS_YCCK => 4, + _ => 3 + }; + dst_info.input_components = input_components; jpeg_set_defaults(&mut dst_info); let row_stride = dst_info.image_width as usize * dst_info.input_components as usize; diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..0511409 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,12 @@ +use std::env; +use caesium::{compress, initialize_parameters}; + +fn main() { + let args: Vec = env::args().collect(); + + let input = args[1].clone(); + let output = args[2].clone(); + + let parameters = initialize_parameters(); + compress(input, output, parameters).unwrap(); +} \ No newline at end of file