From b846a2e9092cf1c2aaf489e9c240e56840fd6652 Mon Sep 17 00:00:00 2001 From: andrews05 Date: Sat, 8 Jul 2023 12:56:15 +1200 Subject: [PATCH] Try to pick tRNS value that's valid at low depth (#520) --- src/reduction/alpha.rs | 10 +++++++++- ...yscale_alpha_8_should_be_grayscale_trns_1.png | Bin 0 -> 2361 bytes tests/reduction.rs | 12 ++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/files/grayscale_alpha_8_should_be_grayscale_trns_1.png 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 }; diff --git a/tests/files/grayscale_alpha_8_should_be_grayscale_trns_1.png b/tests/files/grayscale_alpha_8_should_be_grayscale_trns_1.png new file mode 100644 index 0000000000000000000000000000000000000000..3434291fc4ad3bcb0042b29f26da7f024c70a6b3 GIT binary patch literal 2361 zcmeHI&1(}u6o1>K5K~hH3zimPjo5>d{i=y(*(}7wnuuF!tTh#pZqrR&Om>&uE!lbs zDpo;gk5Y;h1@)rnO?oQyFA$*@FCMG(B*lXib!PL?H8vN|8F@;3BG~^S5>Y-FzLG3cM{>eG)AU$Qz2s%Los17NRp&r z&J_7vdZbQAt3>#=Z5upIS1J{%GEC{_EX~H_ahl<1j*B3Vh&8X-vJ=s)6SW|XIBCTy zn5to`x<=x-^0Yo@C&FR8QFGMuEE~;@G^>6pbUxaV4VtAGdOwolsC()C#ln`hG+QmU zpI_d1TR=82sCauPXpGv+eJ}( zi$PTG##0f4-7mQx=p(b7O((~lTic(A5HNvt#{B(k@zCbz#?bcZ>zjjLgcqsm$K&f; zho|fS!~6S>bv@}NMi!t0cWTmUi2r{L^5<7R{5yr@ug&{6dqa