Add test for image with truncated palette

This commit is contained in:
Andrew 2024-03-28 18:17:15 +13:00 committed by andrews05
parent eae53362b2
commit a30ee05ca8
2 changed files with 37 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 B

View file

@ -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(