Input components fix
This commit is contained in:
parent
7702de7612
commit
15e7723477
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "libcaesium"
|
||||
version = "0.8.2"
|
||||
version = "0.8.3"
|
||||
authors = ["Matteo Paonessa <matteo.paonessa@gmail.com>"]
|
||||
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"
|
||||
|
|
18
src/jpeg.rs
18
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<u8>, 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;
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
use std::env;
|
||||
use caesium::{compress, initialize_parameters};
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
let input = args[1].clone();
|
||||
let output = args[2].clone();
|
||||
|
||||
let parameters = initialize_parameters();
|
||||
compress(input, output, parameters).unwrap();
|
||||
}
|
Loading…
Reference in New Issue