From 3759ca85ecd2d7c17c10d1f8a4bb0766a0ca0c76 Mon Sep 17 00:00:00 2001 From: andrews05 Date: Sun, 23 Jun 2024 11:38:02 +1200 Subject: [PATCH] Keep fcTL after PLTE (#626) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #625 --------- Co-authored-by: Alejandro González --- src/png/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/png/mod.rs b/src/png/mod.rs index a2135c47..df695973 100644 --- a/src/png/mod.rs +++ b/src/png/mod.rs @@ -186,9 +186,12 @@ impl PngData { // Ancillary chunks - split into those that come before IDAT and those that come after let mut aux_split = self.aux_chunks.split(|c| &c.name == b"IDAT"); let aux_pre = aux_split.next().unwrap(); + // Many chunks need to be before PLTE, so write all except those that explicitly need to be after + // Note: the PNG spec does not say that fcTL needs to be after PLTE, but some decoders expect + // that (see issue #625) for chunk in aux_pre .iter() - .filter(|c| !(&c.name == b"bKGD" || &c.name == b"hIST" || &c.name == b"tRNS")) + .filter(|c| !matches!(&c.name, b"bKGD" | b"hIST" | b"tRNS" | b"fcTL")) { write_png_block(&chunk.name, &chunk.data, &mut output); } @@ -223,7 +226,7 @@ impl PngData { // Special ancillary chunks that need to come after PLTE but before IDAT for chunk in aux_pre .iter() - .filter(|c| &c.name == b"bKGD" || &c.name == b"hIST" || &c.name == b"tRNS") + .filter(|c| matches!(&c.name, b"bKGD" | b"hIST" | b"tRNS" | b"fcTL")) { write_png_block(&chunk.name, &chunk.data, &mut output); }