From 1737b8f6d794f90ff90c9603f57ee119da314ad0 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 20 Jun 2024 09:58:50 +1200 Subject: [PATCH] Keep fcTL after PLTE --- src/png/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/png/mod.rs b/src/png/mod.rs index a2135c47..f71846e6 100644 --- a/src/png/mod.rs +++ b/src/png/mod.rs @@ -186,9 +186,11 @@ 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: fcTL does not strictly need to be after PLTE but some software may expect it 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 +225,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); }