diff --git a/benches/reductions.rs b/benches/reductions.rs index 3e05a2e1..28803a38 100644 --- a/benches/reductions.rs +++ b/benches/reductions.rs @@ -158,7 +158,7 @@ fn reductions_rgba_to_grayscale_alpha_16(b: &mut Bencher) { )); let png = PngData::new(&input, false).unwrap(); - b.iter(|| color::reduce_rgb_to_grayscale(&png.raw)); + b.iter(|| color::reduced_rgb_to_grayscale(&png.raw)); } #[bench] @@ -168,7 +168,7 @@ fn reductions_rgba_to_grayscale_alpha_8(b: &mut Bencher) { )); let png = PngData::new(&input, false).unwrap(); - b.iter(|| color::reduce_rgb_to_grayscale(&png.raw)); + b.iter(|| color::reduced_rgb_to_grayscale(&png.raw)); } #[bench] @@ -179,7 +179,7 @@ fn reductions_rgba_to_grayscale_16(b: &mut Bencher) { let png = PngData::new(&input, false).unwrap(); b.iter(|| { - color::reduce_rgb_to_grayscale(&png.raw) + color::reduced_rgb_to_grayscale(&png.raw) .and_then(|r| alpha::reduced_alpha_channel(&r, false)) }); } @@ -192,7 +192,7 @@ fn reductions_rgba_to_grayscale_8(b: &mut Bencher) { let png = PngData::new(&input, false).unwrap(); b.iter(|| { - color::reduce_rgb_to_grayscale(&png.raw) + color::reduced_rgb_to_grayscale(&png.raw) .and_then(|r| alpha::reduced_alpha_channel(&r, false)) }); } @@ -204,7 +204,7 @@ fn reductions_rgb_to_grayscale_16(b: &mut Bencher) { )); let png = PngData::new(&input, false).unwrap(); - b.iter(|| color::reduce_rgb_to_grayscale(&png.raw)); + b.iter(|| color::reduced_rgb_to_grayscale(&png.raw)); } #[bench] @@ -212,7 +212,7 @@ fn reductions_rgb_to_grayscale_8(b: &mut Bencher) { let input = test::black_box(PathBuf::from("tests/files/rgb_8_should_be_grayscale_8.png")); let png = PngData::new(&input, false).unwrap(); - b.iter(|| color::reduce_rgb_to_grayscale(&png.raw)); + b.iter(|| color::reduced_rgb_to_grayscale(&png.raw)); } #[bench] @@ -220,7 +220,7 @@ fn reductions_rgba_to_palette_8(b: &mut Bencher) { let input = test::black_box(PathBuf::from("tests/files/rgba_8_should_be_palette_8.png")); let png = PngData::new(&input, false).unwrap(); - b.iter(|| color::reduce_to_palette(&png.raw)); + b.iter(|| color::reduced_to_indexed(&png.raw)); } #[bench] @@ -228,7 +228,27 @@ fn reductions_rgb_to_palette_8(b: &mut Bencher) { let input = test::black_box(PathBuf::from("tests/files/rgb_8_should_be_palette_8.png")); let png = PngData::new(&input, false).unwrap(); - b.iter(|| color::reduce_to_palette(&png.raw)); + b.iter(|| color::reduced_to_indexed(&png.raw)); +} + +#[bench] +fn reductions_grayscale_8_to_palette_8(b: &mut Bencher) { + let input = test::black_box(PathBuf::from( + "tests/files/grayscale_8_should_be_palette_8.png", + )); + let png = PngData::new(&input, false).unwrap(); + + b.iter(|| color::reduced_to_indexed(&png.raw)); +} + +#[bench] +fn reductions_palette_8_to_grayscale_8(b: &mut Bencher) { + let input = test::black_box(PathBuf::from( + "tests/files/palette_8_should_be_grayscale_8.png", + )); + let png = PngData::new(&input, false).unwrap(); + + b.iter(|| color::indexed_to_channels(&png.raw)); } #[bench] diff --git a/tests/files/grayscale_8_should_be_grayscale_4.png b/tests/files/grayscale_8_should_be_grayscale_4.png index c561432e..e5e62cb1 100644 Binary files a/tests/files/grayscale_8_should_be_grayscale_4.png and b/tests/files/grayscale_8_should_be_grayscale_4.png differ diff --git a/tests/files/grayscale_8_should_be_palette_8.png b/tests/files/grayscale_8_should_be_palette_8.png new file mode 100644 index 00000000..ff94dfb8 Binary files /dev/null and b/tests/files/grayscale_8_should_be_palette_8.png differ diff --git a/tests/files/palette_8_should_be_rgb.png b/tests/files/palette_8_should_be_rgb.png new file mode 100644 index 00000000..cb6b1678 Binary files /dev/null and b/tests/files/palette_8_should_be_rgb.png differ diff --git a/tests/files/palette_8_should_be_rgba.png b/tests/files/palette_8_should_be_rgba.png new file mode 100644 index 00000000..351a7a1b Binary files /dev/null and b/tests/files/palette_8_should_be_rgba.png differ diff --git a/tests/flags.rs b/tests/flags.rs index 3690f21a..ebb2108e 100644 --- a/tests/flags.rs +++ b/tests/flags.rs @@ -427,8 +427,8 @@ fn interlacing_0_to_1_small_files() { }; assert_eq!(png.raw.ihdr.interlaced, Interlacing::Adam7); - assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED); - assert_eq!(png.raw.ihdr.bit_depth, BitDepth::One); + assert_eq!(png.raw.ihdr.color_type.png_header_code(), RGB); + assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight); remove_file(output).ok(); } @@ -461,8 +461,8 @@ fn interlacing_1_to_0_small_files() { }; assert_eq!(png.raw.ihdr.interlaced, Interlacing::None); - assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED); - // the depth can't be asserted reliably, because on such small file different zlib implementations pick different depth as the best + assert_eq!(png.raw.ihdr.color_type.png_header_code(), RGB); + assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight); remove_file(output).ok(); } diff --git a/tests/interlaced.rs b/tests/interlaced.rs index ff884b1a..52540a85 100644 --- a/tests/interlaced.rs +++ b/tests/interlaced.rs @@ -546,6 +546,17 @@ fn interlaced_palette_1_should_be_palette_1() { ); } +#[test] +fn interlaced_palette_8_should_be_grayscale_8() { + test_it_converts( + "tests/files/interlaced_palette_8_should_be_grayscale_8.png", + INDEXED, + BitDepth::Eight, + GRAYSCALE, + BitDepth::Eight, + ); +} + #[test] fn interlaced_grayscale_alpha_16_should_be_grayscale_alpha_16() { test_it_converts( @@ -651,8 +662,8 @@ fn interlaced_small_files() { "tests/files/interlaced_small_files.png", INDEXED, BitDepth::Eight, - INDEXED, - BitDepth::One, + RGB, + BitDepth::Eight, ); } diff --git a/tests/reduction.rs b/tests/reduction.rs index a7fe5e39..3d6577eb 100644 --- a/tests/reduction.rs +++ b/tests/reduction.rs @@ -556,6 +556,42 @@ fn palette_4_should_be_palette_2() { ); } +#[test] +fn palette_8_should_be_grayscale_8() { + test_it_converts( + "tests/files/palette_8_should_be_grayscale_8.png", + false, + INDEXED, + BitDepth::Eight, + GRAYSCALE, + BitDepth::Eight, + ); +} + +#[test] +fn palette_8_should_be_rgb() { + test_it_converts( + "tests/files/palette_8_should_be_rgb.png", + false, + INDEXED, + BitDepth::Eight, + RGB, + BitDepth::Eight, + ); +} + +#[test] +fn palette_8_should_be_rgba() { + test_it_converts( + "tests/files/palette_8_should_be_rgba.png", + false, + INDEXED, + BitDepth::Eight, + RGBA, + BitDepth::Eight, + ); +} + #[test] fn palette_2_should_be_palette_2() { test_it_converts( @@ -808,6 +844,54 @@ fn grayscale_2_should_be_grayscale_1() { ); } +#[test] +fn grayscale_8_should_be_palette_8() { + test_it_converts( + "tests/files/grayscale_8_should_be_palette_8.png", + false, + GRAYSCALE, + BitDepth::Eight, + INDEXED, + BitDepth::Eight, + ); +} + +#[test] +fn grayscale_8_should_be_palette_4() { + test_it_converts( + "tests/files/grayscale_8_should_be_palette_4.png", + false, + GRAYSCALE, + BitDepth::Eight, + INDEXED, + BitDepth::Four, + ); +} + +#[test] +fn grayscale_8_should_be_palette_2() { + test_it_converts( + "tests/files/grayscale_8_should_be_palette_2.png", + false, + GRAYSCALE, + BitDepth::Eight, + INDEXED, + BitDepth::Two, + ); +} + +#[test] +fn grayscale_8_should_be_palette_1() { + test_it_converts( + "tests/files/grayscale_8_should_be_palette_1.png", + false, + GRAYSCALE, + BitDepth::Eight, + INDEXED, + BitDepth::One, + ); +} + #[test] fn grayscale_alpha_16_should_be_grayscale_trns_16() { test_it_converts( @@ -834,33 +918,14 @@ fn grayscale_alpha_8_should_be_grayscale_trns_8() { #[test] fn small_files() { - let input = PathBuf::from("tests/files/small_files.png"); - let (output, opts) = get_opts(&input); - - let png = PngData::new(&input, opts.fix_errors).unwrap(); - - assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED); - assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight); - - match oxipng::optimize(&InFile::Path(input), &output, &opts) { - Ok(_) => (), - Err(x) => panic!("{}", x), - }; - let output = output.path().unwrap(); - assert!(output.exists()); - - let png = match PngData::new(output, opts.fix_errors) { - Ok(x) => x, - Err(x) => { - remove_file(output).ok(); - panic!("{}", x) - } - }; - - assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED); - // depth varies depending on zlib implementation used - - remove_file(output).ok(); + test_it_converts( + "tests/files/small_files.png", + false, + INDEXED, + BitDepth::Eight, + RGB, + BitDepth::Eight, + ); } #[test]