Skip to content

Commit 3759ca8

Browse files
Keep fcTL after PLTE (#626)
Fixes #625 --------- Co-authored-by: Alejandro González <[email protected]>
1 parent 90ceef9 commit 3759ca8

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/png/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,12 @@ impl PngData {
186186
// Ancillary chunks - split into those that come before IDAT and those that come after
187187
let mut aux_split = self.aux_chunks.split(|c| &c.name == b"IDAT");
188188
let aux_pre = aux_split.next().unwrap();
189+
// Many chunks need to be before PLTE, so write all except those that explicitly need to be after
190+
// Note: the PNG spec does not say that fcTL needs to be after PLTE, but some decoders expect
191+
// that (see issue #625)
189192
for chunk in aux_pre
190193
.iter()
191-
.filter(|c| !(&c.name == b"bKGD" || &c.name == b"hIST" || &c.name == b"tRNS"))
194+
.filter(|c| !matches!(&c.name, b"bKGD" | b"hIST" | b"tRNS" | b"fcTL"))
192195
{
193196
write_png_block(&chunk.name, &chunk.data, &mut output);
194197
}
@@ -223,7 +226,7 @@ impl PngData {
223226
// Special ancillary chunks that need to come after PLTE but before IDAT
224227
for chunk in aux_pre
225228
.iter()
226-
.filter(|c| &c.name == b"bKGD" || &c.name == b"hIST" || &c.name == b"tRNS")
229+
.filter(|c| matches!(&c.name, b"bKGD" | b"hIST" | b"tRNS" | b"fcTL"))
227230
{
228231
write_png_block(&chunk.name, &chunk.data, &mut output);
229232
}

0 commit comments

Comments
 (0)