diff --git a/tests/files/fix_errors.png b/tests/files/fix_errors.png index 93e822fd..46f778cc 100644 Binary files a/tests/files/fix_errors.png and b/tests/files/fix_errors.png differ diff --git a/tests/files/grayscale_alpha_8_should_be_palette_8.png b/tests/files/grayscale_alpha_8_should_be_palette_8.png new file mode 100644 index 00000000..69aedf34 Binary files /dev/null and b/tests/files/grayscale_alpha_8_should_be_palette_8.png differ diff --git a/tests/files/grayscale_trns_8_should_be_grayscale_1.png b/tests/files/grayscale_trns_8_should_be_grayscale_1.png new file mode 100644 index 00000000..a322aadb Binary files /dev/null and b/tests/files/grayscale_trns_8_should_be_grayscale_1.png differ diff --git a/tests/files/interlaced_vertical_filters.png b/tests/files/interlaced_vertical_filters.png new file mode 100644 index 00000000..e7aa76d9 Binary files /dev/null and b/tests/files/interlaced_vertical_filters.png differ diff --git a/tests/files/issue-113.png b/tests/files/issue-113.png deleted file mode 100644 index a039b00b..00000000 Binary files a/tests/files/issue-113.png and /dev/null differ diff --git a/tests/files/issue-129.png b/tests/files/issue-129.png deleted file mode 100644 index 1cf61e01..00000000 Binary files a/tests/files/issue-129.png and /dev/null differ diff --git a/tests/files/issue-141.png b/tests/files/issue-141.png deleted file mode 100644 index 586f7155..00000000 Binary files a/tests/files/issue-141.png and /dev/null differ diff --git a/tests/files/issue-153.png b/tests/files/issue-153.png deleted file mode 100644 index 99fc7e0f..00000000 Binary files a/tests/files/issue-153.png and /dev/null differ diff --git a/tests/files/issue-159.png b/tests/files/issue-159.png deleted file mode 100644 index cd5585ab..00000000 Binary files a/tests/files/issue-159.png and /dev/null differ diff --git a/tests/files/issue-195.png b/tests/files/issue-195.png deleted file mode 100644 index 283f14c4..00000000 Binary files a/tests/files/issue-195.png and /dev/null differ diff --git a/tests/files/issue-29.png b/tests/files/issue-29.png deleted file mode 100644 index b52b0f41..00000000 Binary files a/tests/files/issue-29.png and /dev/null differ diff --git a/tests/files/issue-426-01.png b/tests/files/issue-426-01.png deleted file mode 100644 index 7349d388..00000000 Binary files a/tests/files/issue-426-01.png and /dev/null differ diff --git a/tests/files/issue-426-02.png b/tests/files/issue-426-02.png deleted file mode 100644 index e3031723..00000000 Binary files a/tests/files/issue-426-02.png and /dev/null differ diff --git a/tests/files/issue-52-01.png b/tests/files/issue-52-01.png deleted file mode 100644 index b4e7f96f..00000000 Binary files a/tests/files/issue-52-01.png and /dev/null differ diff --git a/tests/files/issue-52-02.png b/tests/files/issue-52-02.png deleted file mode 100644 index 7076ac11..00000000 Binary files a/tests/files/issue-52-02.png and /dev/null differ diff --git a/tests/files/issue-52-03.png b/tests/files/issue-52-03.png deleted file mode 100644 index d7648d87..00000000 Binary files a/tests/files/issue-52-03.png and /dev/null differ diff --git a/tests/files/issue-52-04.png b/tests/files/issue-52-04.png deleted file mode 100644 index a9eb8ac9..00000000 Binary files a/tests/files/issue-52-04.png and /dev/null differ diff --git a/tests/files/issue-52-05.png b/tests/files/issue-52-05.png deleted file mode 100644 index 929a0ec8..00000000 Binary files a/tests/files/issue-52-05.png and /dev/null differ diff --git a/tests/files/issue-52-06.png b/tests/files/issue-52-06.png deleted file mode 100644 index 7a25e9ca..00000000 Binary files a/tests/files/issue-52-06.png and /dev/null differ diff --git a/tests/files/issue-553.png b/tests/files/issue-553.png deleted file mode 100644 index b42a9f50..00000000 Binary files a/tests/files/issue-553.png and /dev/null differ diff --git a/tests/files/issue-80.png b/tests/files/issue-80.png deleted file mode 100644 index 15c81914..00000000 Binary files a/tests/files/issue-80.png and /dev/null differ diff --git a/tests/files/issue-82.png b/tests/files/issue-82.png deleted file mode 100644 index d1f4df99..00000000 Binary files a/tests/files/issue-82.png and /dev/null differ diff --git a/tests/files/issue-92.png b/tests/files/issue-92.png deleted file mode 100644 index e1b5f96c..00000000 Binary files a/tests/files/issue-92.png and /dev/null differ diff --git a/tests/files/palette_should_be_reduced_with_bkgd.png b/tests/files/palette_should_be_reduced_with_bkgd.png new file mode 100644 index 00000000..773b4d1e Binary files /dev/null and b/tests/files/palette_should_be_reduced_with_bkgd.png differ diff --git a/tests/files/rgb_trns_8_should_be_palette_8.png b/tests/files/rgb_trns_8_should_be_palette_8.png new file mode 100644 index 00000000..f3bdd70a Binary files /dev/null and b/tests/files/rgb_trns_8_should_be_palette_8.png differ diff --git a/tests/files/zopfli_mode.png b/tests/files/zopfli_mode.png index 82ca1f07..4f3ba4f7 100644 Binary files a/tests/files/zopfli_mode.png and b/tests/files/zopfli_mode.png differ diff --git a/tests/flags.rs b/tests/flags.rs index 887da87c..85da071f 100644 --- a/tests/flags.rs +++ b/tests/flags.rs @@ -12,10 +12,8 @@ use std::{ use indexmap::indexset; use oxipng::{internal_tests::*, *}; -const GRAYSCALE: u8 = 0; const RGB: u8 = 2; const INDEXED: u8 = 3; -const RGBA: u8 = 6; fn get_opts(input: &Path) -> (OutFile, oxipng::Options) { let mut options = oxipng::Options { @@ -582,7 +580,7 @@ fn fix_errors() { let png = PngData::new(&input, &opts).unwrap(); - assert_eq!(png.raw.ihdr.color_type.png_header_code(), RGBA); + 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) { @@ -600,7 +598,7 @@ fn fix_errors() { } }; - assert_eq!(png.raw.ihdr.color_type.png_header_code(), GRAYSCALE); + assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED); assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight); // Cannot check if pixels are equal because image crate cannot read corrupt (input) PNGs @@ -688,9 +686,9 @@ fn zopfli_mode() { input, &output, &opts, - INDEXED, + RGB, BitDepth::Eight, - INDEXED, + RGB, BitDepth::Eight, ); } diff --git a/tests/interlaced.rs b/tests/interlaced.rs index 43b3d6a7..a8931419 100644 --- a/tests/interlaced.rs +++ b/tests/interlaced.rs @@ -666,6 +666,17 @@ fn interlaced_small_files() { ); } +#[test] +fn interlaced_vertical_filters() { + test_it_converts( + "tests/files/interlaced_vertical_filters.png", + RGB, + BitDepth::Eight, + RGB, + BitDepth::Eight, + ); +} + #[test] fn interlaced_odd_width() { test_it_converts( diff --git a/tests/reduction.rs b/tests/reduction.rs index 7a6292c4..88f7fc0a 100644 --- a/tests/reduction.rs +++ b/tests/reduction.rs @@ -386,6 +386,18 @@ fn rgb_8_should_be_palette_8() { ); } +#[test] +fn rgb_trns_8_should_be_palette_8() { + test_it_converts( + "tests/files/rgb_trns_8_should_be_palette_8.png", + false, + RGB, + BitDepth::Eight, + INDEXED, + BitDepth::Eight, + ); +} + #[test] fn rgb_16_should_be_palette_4() { test_it_converts( @@ -722,6 +734,18 @@ fn grayscale_alpha_8_should_be_grayscale_8() { ); } +#[test] +fn grayscale_alpha_8_should_be_palette_8() { + test_it_converts( + "tests/files/grayscale_alpha_8_should_be_palette_8.png", + false, + GRAYSCALE_ALPHA, + BitDepth::Eight, + INDEXED, + BitDepth::Eight, + ); +} + #[test] fn grayscale_16_should_be_grayscale_16() { test_it_converts( @@ -926,6 +950,18 @@ fn grayscale_alpha_8_should_be_grayscale_trns_1() { ); } +#[test] +fn grayscale_trns_8_should_be_grayscale_1() { + test_it_converts( + "tests/files/grayscale_trns_8_should_be_grayscale_1.png", + true, + GRAYSCALE, + BitDepth::Eight, + GRAYSCALE, + BitDepth::One, + ); +} + #[test] fn small_files() { test_it_converts( @@ -1012,6 +1048,45 @@ fn palette_should_be_reduced_with_unused() { remove_file(output).ok(); } +#[test] +fn palette_should_be_reduced_with_bkgd() { + let input = PathBuf::from("tests/files/palette_should_be_reduced_with_bkgd.png"); + let (output, opts) = get_opts(&input); + + let png = PngData::new(&input, &opts).unwrap(); + + assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED); + assert_eq!(png.raw.ihdr.bit_depth, BitDepth::One); + assert_eq!(&png.aux_chunks[0].name, b"bKGD"); + if let ColorType::Indexed { palette } = &png.raw.ihdr.color_type { + assert_eq!(palette.len(), 3); + } + + 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) { + Ok(x) => x, + Err(x) => { + remove_file(output).ok(); + panic!("{}", x) + } + }; + + assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED); + assert_eq!(png.raw.ihdr.bit_depth, BitDepth::One); + assert_ne!(&png.aux_chunks[0].name, b"bKGD"); + if let ColorType::Indexed { palette } = &png.raw.ihdr.color_type { + assert_eq!(palette.len(), 2); + } + + remove_file(output).ok(); +} + #[test] fn palette_should_be_reduced_with_both() { let input = PathBuf::from("tests/files/palette_should_be_reduced_with_both.png"); diff --git a/tests/regression.rs b/tests/regression.rs index f21bd97c..765a04f5 100644 --- a/tests/regression.rs +++ b/tests/regression.rs @@ -7,7 +7,6 @@ use std::{ use oxipng::{internal_tests::*, *}; const GRAYSCALE: u8 = 0; -const RGB: u8 = 2; const INDEXED: u8 = 3; const GRAYSCALE_ALPHA: u8 = 4; const RGBA: u8 = 6; @@ -75,18 +74,6 @@ fn test_it_converts( Arc::try_unwrap(png.raw).unwrap() } -#[test] -fn issue_29() { - test_it_converts( - "tests/files/issue-29.png", - None, - RGB, - BitDepth::Eight, - RGB, - BitDepth::Eight, - ); -} - #[test] fn issue_42() { let input = "tests/files/issue-42.png"; @@ -102,78 +89,6 @@ fn issue_42() { ); } -#[test] -fn issue_52_01() { - test_it_converts( - "tests/files/issue-52-01.png", - None, - RGBA, - BitDepth::Eight, - INDEXED, - BitDepth::Eight, - ); -} - -#[test] -fn issue_52_02() { - test_it_converts( - "tests/files/issue-52-02.png", - None, - RGBA, - BitDepth::Eight, - RGBA, - BitDepth::Eight, - ); -} - -#[test] -fn issue_52_03() { - test_it_converts( - "tests/files/issue-52-03.png", - None, - RGBA, - BitDepth::Eight, - RGBA, - BitDepth::Eight, - ); -} - -#[test] -fn issue_52_04() { - test_it_converts( - "tests/files/issue-52-04.png", - None, - RGBA, - BitDepth::Eight, - RGB, - BitDepth::Eight, - ); -} - -#[test] -fn issue_52_05() { - test_it_converts( - "tests/files/issue-52-05.png", - None, - RGBA, - BitDepth::Eight, - RGB, - BitDepth::Eight, - ); -} - -#[test] -fn issue_52_06() { - test_it_converts( - "tests/files/issue-52-06.png", - None, - RGBA, - BitDepth::Eight, - RGBA, - BitDepth::Eight, - ); -} - #[test] fn issue_56() { test_it_converts( @@ -222,30 +137,6 @@ fn issue_60() { ); } -#[test] -fn issue_80() { - test_it_converts( - "tests/files/issue-80.png", - None, - INDEXED, - BitDepth::Two, - INDEXED, - BitDepth::One, - ); -} - -#[test] -fn issue_82() { - test_it_converts( - "tests/files/issue-82.png", - None, - INDEXED, - BitDepth::Four, - INDEXED, - BitDepth::Eight, - ); -} - #[test] fn issue_89() { test_it_converts( @@ -258,63 +149,6 @@ fn issue_89() { ); } -#[test] -fn issue_92_filter_0() { - test_it_converts( - "tests/files/issue-92.png", - None, - GRAYSCALE, - BitDepth::Eight, - GRAYSCALE, - BitDepth::Eight, - ); -} - -#[test] -fn issue_92_filter_5() { - let input = "tests/files/issue-92.png"; - let (_, mut opts) = get_opts(Path::new(input)); - opts.filter = [RowFilter::MinSum].iter().cloned().collect(); - let output = OutFile::from_path(Path::new(input).with_extension("-f5-out.png")); - - test_it_converts( - input, - Some((output, opts)), - GRAYSCALE, - BitDepth::Eight, - GRAYSCALE, - BitDepth::Eight, - ); -} - -#[test] -fn issue_113() { - let input = "tests/files/issue-113.png"; - let (output, mut opts) = get_opts(Path::new(input)); - opts.interlace = Some(Interlacing::Adam7); - opts.optimize_alpha = true; - test_it_converts( - input, - Some((output, opts)), - RGBA, - BitDepth::Eight, - GRAYSCALE_ALPHA, - BitDepth::Eight, - ); -} - -#[test] -fn issue_129() { - test_it_converts( - "tests/files/issue-129.png", - None, - RGB, - BitDepth::Eight, - INDEXED, - BitDepth::Eight, - ); -} - #[test] fn issue_140() { test_it_converts( @@ -327,42 +161,6 @@ fn issue_140() { ); } -#[test] -fn issue_141() { - test_it_converts( - "tests/files/issue-141.png", - None, - RGBA, - BitDepth::Eight, - RGB, - BitDepth::Eight, - ); -} - -#[test] -fn issue_153() { - test_it_converts( - "tests/files/issue-153.png", - None, - RGBA, - BitDepth::Eight, - INDEXED, - BitDepth::Eight, - ); -} - -#[test] -fn issue_159() { - test_it_converts( - "tests/files/issue-159.png", - None, - INDEXED, - BitDepth::One, - INDEXED, - BitDepth::One, - ); -} - #[test] fn issue_171() { test_it_converts( @@ -402,55 +200,3 @@ fn issue_182() { BitDepth::One, ); } - -#[test] -fn issue_195() { - test_it_converts( - "tests/files/issue-195.png", - None, - RGBA, - BitDepth::Eight, - INDEXED, - BitDepth::Eight, - ); -} - -#[test] -fn issue_426_01() { - test_it_converts( - "tests/files/issue-426-01.png", - None, - GRAYSCALE, - BitDepth::Eight, - GRAYSCALE, - BitDepth::One, - ); -} - -#[test] -fn issue_426_02() { - test_it_converts( - "tests/files/issue-426-02.png", - None, - GRAYSCALE, - BitDepth::Eight, - GRAYSCALE, - BitDepth::One, - ); -} - -#[test] -fn issue_553() { - let png = test_it_converts( - "tests/files/issue-553.png", - None, - INDEXED, - BitDepth::Eight, - INDEXED, - BitDepth::Eight, - ); - match png.ihdr.color_type { - ColorType::Indexed { palette } => assert_eq!(palette.len(), 256), - _ => unreachable!(), - }; -}