Skip to content

Commit

Permalink
Fix lossless not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Lymphatus committed Jan 2, 2025
1 parent e7fce9a commit 191c655
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ homepage = "https://github.com/Lymphatus/caesium-clt"
repository = "https://github.com/Lymphatus/caesium-clt"

[dependencies]
indicatif = {version= "0.17", features = ["rayon"]}
indicatif = { version = "0.17", features = ["rayon"] }
walkdir = "2.5"
infer = "0.16"
rayon = "1.10"
Expand Down
12 changes: 12 additions & 0 deletions src/compressor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct CompressionResult {
pub struct CompressionOptions {
pub quality: Option<u32>,
pub max_size: Option<usize>,
pub lossless: bool,
pub exif: bool,
pub png_opt_level: u8,
pub zopfli: bool,
Expand Down Expand Up @@ -243,6 +244,8 @@ fn build_compression_parameters(
parameters.webp.quality = quality;
parameters.gif.quality = quality;

parameters.optimize = options.lossless;

parameters.keep_metadata = options.exif;

parameters.png.optimization_level = options.png_opt_level;
Expand Down Expand Up @@ -703,6 +706,13 @@ mod tests {
assert!(results.iter().all(|r| matches!(r.status, CompressionStatus::Success)));
assert!(results.iter().all(|r| fs::exists(&r.output_path).unwrap_or(false)));

options.quality = Some(100);
options.lossless = true;
options.overwrite_policy = OverwritePolicy::All;
results = start_compression(&input_files, &options, progress_bar.clone(), true);
assert!(results.iter().all(|r| matches!(r.status, CompressionStatus::Success)));
assert!(results.iter().all(|r| fs::exists(&r.output_path).unwrap_or(false)));

options.quality = Some(80);
options.keep_dates = true;
results = start_compression(&input_files, &options, progress_bar.clone(), false);
Expand Down Expand Up @@ -740,9 +750,11 @@ mod tests {
}));
assert!(results.iter().all(|r| fs::exists(&r.output_path).unwrap_or(false)));
}

fn setup_options() -> CompressionOptions {
CompressionOptions {
quality: Some(80),
lossless: false,
output_folder: None,
same_folder_as_input: false,
overwrite_policy: OverwritePolicy::All,
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ fn setup_progress_bar(len: usize, verbose: VerboseLevel) -> ProgressBar {
fn build_compression_options(args: &CommandLineArgs, base_path: &Path) -> CompressionOptions {
CompressionOptions {
quality: args.compression.quality,
lossless: args.compression.lossless,
output_folder: args.output_destination.output.clone(),
same_folder_as_input: args.output_destination.same_folder_as_input,
overwrite_policy: args.overwrite,
Expand Down

0 comments on commit 191c655

Please sign in to comment.