Fix bug with fast flag and update tests

This commit is contained in:
Andrew 2023-07-11 08:51:02 +12:00 committed by Josh Holmer
parent 27d6fe5eb3
commit 59e04cd755
6 changed files with 8 additions and 3 deletions

View file

@ -160,7 +160,7 @@ pub struct Options {
///
/// `Some(x)` will change the file to interlacing mode `x`.
///
/// Default: `Some(None)`
/// Default: `Some(Interlacing::None)`
pub interlace: Option<Interlacing>,
/// Whether to allow transparent pixels to be altered to improve compression.
pub optimize_alpha: bool,

View file

@ -446,7 +446,10 @@ fn parse_opts_into_struct(
opts.scale_16 = matches.get_flag("scale16");
opts.fast_evaluation = matches.get_flag("fast");
// The default value for fast depends on the preset - make sure we don't change when not provided
if matches.get_flag("fast") {
opts.fast_evaluation = matches.get_flag("fast");
}
opts.backup = matches.get_flag("backup");

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 63 KiB

View file

@ -11,6 +11,7 @@ use std::ops::Deref;
use std::path::Path;
use std::path::PathBuf;
const GRAYSCALE: u8 = 0;
const RGB: u8 = 2;
const INDEXED: u8 = 3;
const RGBA: u8 = 6;
@ -598,7 +599,7 @@ fn fix_errors() {
}
};
assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED);
assert_eq!(png.raw.ihdr.color_type.png_header_code(), GRAYSCALE);
assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight);
// Cannot check if pixels are equal because image crate cannot read corrupt (input) PNGs

View file

@ -15,6 +15,7 @@ fn get_opts(input: &Path) -> (OutFile, oxipng::Options) {
let mut options = oxipng::Options {
force: true,
fast_evaluation: false,
interlace: None,
..Default::default()
};
let mut filter = IndexSet::new();