Try to pick tRNS value that's valid at low depth (#520)
This commit is contained in:
parent
75a0f0de95
commit
b846a2e909
3 changed files with 21 additions and 1 deletions
|
|
@ -57,8 +57,16 @@ pub fn reduced_alpha_channel(png: &PngImage, optimize_alpha: bool) -> Option<Png
|
|||
}
|
||||
|
||||
let transparency_pixel = if has_transparency {
|
||||
// For grayscale, start by checking 4 specific values in the hope that we may reduce depth
|
||||
let unused = match png.ihdr.color_type {
|
||||
ColorType::GrayscaleAlpha => [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
|
||||
};
|
||||
|
|
|
|||
BIN
tests/files/grayscale_alpha_8_should_be_grayscale_trns_1.png
Normal file
BIN
tests/files/grayscale_alpha_8_should_be_grayscale_trns_1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in a new issue