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 00000000..3434291f Binary files /dev/null and b/tests/files/grayscale_alpha_8_should_be_grayscale_trns_1.png differ diff --git a/tests/reduction.rs b/tests/reduction.rs index 8a1a1e34..7176ccca 100644 --- a/tests/reduction.rs +++ b/tests/reduction.rs @@ -916,6 +916,18 @@ fn grayscale_alpha_8_should_be_grayscale_trns_8() { ); } +#[test] +fn grayscale_alpha_8_should_be_grayscale_trns_1() { + test_it_converts( + "tests/files/grayscale_alpha_8_should_be_grayscale_trns_1.png", + true, + GRAYSCALE_ALPHA, + BitDepth::Eight, + GRAYSCALE, + BitDepth::One, + ); +} + #[test] fn small_files() { test_it_converts(