From 4e08aa707d1085a563654567bebe7761e80a5330 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 21 May 2023 14:01:10 +1200 Subject: [PATCH] Also drop chunks if depth changes --- src/lib.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8918e558..46886f33 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 {