diff --git a/CHANGELOG.md b/CHANGELOG.md index 0aac5423..ee3258c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/png.rs b/src/png.rs index 0c0f19c4..5449d8a3 100644 --- a/src/png.rs +++ b/src/png.rs @@ -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 diff --git a/tests/files/issue-80.png b/tests/files/issue-80.png new file mode 100644 index 00000000..15c81914 Binary files /dev/null and b/tests/files/issue-80.png differ diff --git a/tests/regression.rs b/tests/regression.rs index d8cf6d65..aaa63820 100644 --- a/tests/regression.rs +++ b/tests/regression.rs @@ -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, + ); +}