Keep fcTL after PLTE (#626)

Fixes #625

---------

Co-authored-by: Alejandro González <me@alegon.dev>
This commit is contained in:
andrews05 2024-06-23 11:38:02 +12:00 committed by GitHub
parent 90ceef9796
commit 3759ca85ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

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