From 685331cddafd8d2c988905e18df40ae29a0896b2 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 15 Jun 2023 11:32:24 +1200 Subject: [PATCH] Try to pick tRNS value that's valid at low depth --- src/reduction/alpha.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/reduction/alpha.rs b/src/reduction/alpha.rs index 3045ddf6..3115c6cd 100644 --- a/src/reduction/alpha.rs +++ b/src/reduction/alpha.rs @@ -57,8 +57,16 @@ pub fn reduced_alpha_channel(png: &PngImage, optimize_alpha: bool) -> Option [0x00, 0xFF, 0x55, 0xAA] + .into_iter() + .find(|&v| !used_colors[v as usize]), + _ => None, + } + .or_else(|| used_colors.iter().position(|&u| !u).map(|v| v as u8)); // If no unused color was found we will have to fail here - Some(used_colors.iter().position(|b| !*b)? as u8) + Some(unused?) } else { None };