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); }