Also drop chunks if depth changes

This commit is contained in:
Andrew 2023-05-21 14:01:10 +12:00
parent 526429a522
commit 4e08aa707d

View file

@ -878,10 +878,11 @@ fn postprocess_chunks(png: &mut PngData, opts: &Options, orig_ihdr: &IhdrData) {
}
}
// If the color type has changed, some chunks may be invalid and should be dropped
// While these could potentially be converted, they have no known use case today and
// are generally more trouble than they're worth
if orig_ihdr.color_type != png.raw.ihdr.color_type {
// If the depth/color type has changed, some chunks may be invalid and should be dropped
// While these could potentially be converted, they have no known use case today and are
// generally more trouble than they're worth
let ihdr = &png.raw.ihdr;
if orig_ihdr.bit_depth != ihdr.bit_depth || orig_ihdr.color_type != ihdr.color_type {
png.aux_chunks.retain(|c| {
let invalid = &c.name == b"bKGD" || &c.name == b"sBIT" || &c.name == b"hIST";
if invalid {