Fix issue with alpha optim on interlaced images

Closes #113
This commit is contained in:
Josh Holmer 2018-07-27 23:03:36 -04:00
parent b948264c32
commit 7303b94afc
4 changed files with 29 additions and 2 deletions

View file

@ -1,3 +1,6 @@
### Version 2.0.2
- Fix an issue in alpha optimization on interlaced images ([#113](https://github.com/shssoichiro/oxipng/issues/113))
### Version 2.0.1
- Revert making Cloudflare zlib the default, as it introduced a major memory leak. It will be put back behind a feature flag, and reenabled when the issue is fixed.

View file

@ -713,10 +713,14 @@ impl PngData {
fn reduce_alpha_to_up(&self, bpc: usize, bpp: usize) -> Vec<u8> {
let mut lines = Vec::new();
let scan_lines = self.scan_lines().collect::<Vec<ScanLine>>();
let scan_lines = self.scan_lines()
.collect::<Vec<ScanLine>>()
.into_iter()
.rev()
.collect::<Vec<ScanLine>>();
let mut last_line = vec![0; scan_lines[0].data.len()];
let mut current_line = Vec::with_capacity(last_line.len());
for line in scan_lines.into_iter().rev() {
for line in scan_lines.into_iter() {
current_line.push(line.filter);
for (pixel, last_pixel) in line.data.chunks(bpp).zip(last_line.chunks(bpp)) {
if pixel.iter().skip(bpp - bpc).fold(0, |sum, i| sum | i) == 0 {

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View file

@ -289,3 +289,23 @@ fn issue_92_filter_5() {
BitDepth::Eight,
);
}
#[test]
fn issue_113() {
let input = "tests/files/issue-113.png";
let (_, mut opts) = get_opts(Path::new(input));
opts.interlace = Some(1);
opts.alphas = HashSet::new();
opts.alphas.insert(AlphaOptim::Up);
let output = OutFile::Path(Some(
Path::new(input).with_extension("-f5-out.png").to_owned(),
));
test_it_converts(
input,
Some((output, opts)),
ColorType::RGBA,
BitDepth::Eight,
ColorType::GrayscaleAlpha,
BitDepth::Eight,
);
}