Fix failure to optimize on certain grayscale images

Closes #89
This commit is contained in:
Josh Holmer 2017-11-21 12:37:31 -05:00
parent c36cc240e2
commit 4d62f9f7f9
4 changed files with 23 additions and 1 deletions

View file

@ -1,5 +1,6 @@
### Version 0.18.1 (unreleased)
- Bump `rayon` to 0.9
- Fix failure to optimize on certain grayscale images ([#89](https://github.com/shssoichiro/oxipng/issues/89))
### Version 0.18.0
- Bump `itertools` to 0.7

View file

@ -10,7 +10,11 @@ pub fn reduce_bit_depth_8_or_less(png: &mut PngData) -> bool {
for line in png.scan_lines() {
let bit_vec = BitVec::from_bytes(&line.data);
for (i, bit) in bit_vec.iter().enumerate() {
let bit_index = bit_depth - (i % bit_depth);
let bit_index = if png.ihdr_data.color_type == ColorType::Indexed {
bit_depth - (i % bit_depth)
} else {
i % bit_depth
};
if bit && bit_index > allowed_bits {
allowed_bits = bit_index.next_power_of_two();
if allowed_bits == bit_depth {

BIN
tests/files/issue-89.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 B

View file

@ -308,3 +308,20 @@ fn issue_82() {
BitDepth::Four,
);
}
#[test]
fn issue_89() {
let input = PathBuf::from("tests/files/issue-89.png");
let opts = get_opts(&input);
let output = opts.out_file.clone();
test_it_converts(
&input,
&output,
&opts,
ColorType::RGBA,
BitDepth::Eight,
ColorType::Grayscale,
BitDepth::Eight,
);
}