Fix a bug in reducing palettes with a bit depth of two

Closes #80
This commit is contained in:
Josh Holmer 2017-09-10 22:58:03 -04:00
parent 0db03c6faf
commit e3a26b77a4
4 changed files with 23 additions and 5 deletions

View file

@ -7,6 +7,7 @@
trials for optimizing the alpha channel, using the previously mentioned fast heuristic.
This option will make optimization of images with transparency somewhat slower,
but may improve compression.
- Fixed a bug in reducing palettes for images with bit depth of two([#80](https://github.com/shssoichiro/oxipng/issues/80))
- Code cleanup
### Version 0.16.3

View file

@ -543,7 +543,7 @@ impl PngData {
for (i, bit) in bitvec.iter().enumerate() {
let mod_i = i % 4;
if bit {
current += 2u8.pow(3u32 - mod_i as u32);
current += 1u8 << (3 - mod_i);
}
if mod_i == 3 {
seen.insert(current);
@ -557,7 +557,7 @@ impl PngData {
for (i, bit) in bitvec.iter().enumerate() {
let mod_i = i % 2;
if bit {
current += 2u8.pow(1u32 - mod_i as u32);
current += 1u8 << (1 - mod_i);
}
if mod_i == 1 {
seen.insert(current);
@ -649,17 +649,17 @@ impl PngData {
new_byte |= if let Some(new_idx) = index_map.get(&one) {
*new_idx << 6
} else {
one << 6
one
};
new_byte |= if let Some(new_idx) = index_map.get(&two) {
*new_idx << 4
} else {
two << 4
two
};
new_byte |= if let Some(new_idx) = index_map.get(&three) {
*new_idx << 2
} else {
three << 2
three
};
new_byte |= if let Some(new_idx) = index_map.get(&four) {
*new_idx

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

View file

@ -274,3 +274,20 @@ fn issue_60() {
BitDepth::Eight,
);
}
#[test]
fn issue_80() {
let input = PathBuf::from("tests/files/issue-80.png");
let opts = get_opts(&input);
let output = opts.out_file.clone();
test_it_converts(
&input,
&output,
&opts,
ColorType::Indexed,
BitDepth::Two,
ColorType::Indexed,
BitDepth::One,
);
}