From 37161bf05d0bba22ebde81a6b7e7d7393f67c84b Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 28 Nov 2022 18:50:04 +1300 Subject: [PATCH] Make sure correct bKGD is retained --- src/reduction/mod.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/reduction/mod.rs b/src/reduction/mod.rs index 89aec38b..8fd258f7 100644 --- a/src/reduction/mod.rs +++ b/src/reduction/mod.rs @@ -76,6 +76,13 @@ pub fn reduced_palette(png: &PngImage) -> Option { color_val(a.0).cmp(&color_val(b.0)) }); + // Make sure the background is also included, but only after sorting since it may not be used in idat + if let Some(&idx) = png.aux_headers.get(b"bKGD").and_then(|b| b.first()) { + if !used[idx as usize] { + used_enumerated.push((idx as usize, &true)); + } + } + let mut next_index = 0_u16; let mut seen = IndexMap::with_capacity(palette.len()); for (i, used) in used_enumerated.iter().cloned() {