From a30ee05ca862e5596913e1bfb57d42e143e5d8c6 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 28 Mar 2024 18:17:15 +1300 Subject: [PATCH] Add test for image with truncated palette --- ...palette_should_be_reduced_with_missing.png | Bin 0 -> 138 bytes tests/reduction.rs | 37 ++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tests/files/palette_should_be_reduced_with_missing.png diff --git a/tests/files/palette_should_be_reduced_with_missing.png b/tests/files/palette_should_be_reduced_with_missing.png new file mode 100644 index 0000000000000000000000000000000000000000..fd6d61b8be64b0a25f2ec01d506a89470208c4f6 GIT binary patch literal 138 zcmeAS@N?(olHy`uVBq!ia0vp^0U*r53?z4+XPOVB*aCb)TswdIJ8t-P`^1cYKoNUS z7srr@*0*OAg%}igST-K|FW<{jXuQ@T?eDU0&$&2Qm>Lf(7wsyBu$EacH##T?+-P_# c36{Cd$e}5_QG0*XYM@aJp00i_>zopr0LbqvZ2$lO literal 0 HcmV?d00001 diff --git a/tests/reduction.rs b/tests/reduction.rs index 221e320d..7a6292c4 100644 --- a/tests/reduction.rs +++ b/tests/reduction.rs @@ -1049,6 +1049,43 @@ fn palette_should_be_reduced_with_both() { remove_file(output).ok(); } +#[test] +fn palette_should_be_reduced_with_missing() { + let input = PathBuf::from("tests/files/palette_should_be_reduced_with_missing.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::Eight); + if let ColorType::Indexed { palette } = &png.raw.ihdr.color_type { + assert_eq!(palette.len(), 2); + } + + 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::Two); + if let ColorType::Indexed { palette } = &png.raw.ihdr.color_type { + assert_eq!(palette.len(), 3); + } + + remove_file(output).ok(); +} + #[test] fn rgba_16_reduce_alpha() { test_it_converts(