diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e7686d7..0807932b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/png/mod.rs b/src/png/mod.rs index 72a2b06e..c17b7215 100644 --- a/src/png/mod.rs +++ b/src/png/mod.rs @@ -713,10 +713,14 @@ impl PngData { fn reduce_alpha_to_up(&self, bpc: usize, bpp: usize) -> Vec { let mut lines = Vec::new(); - let scan_lines = self.scan_lines().collect::>(); + let scan_lines = self.scan_lines() + .collect::>() + .into_iter() + .rev() + .collect::>(); 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 { diff --git a/tests/files/issue-113.png b/tests/files/issue-113.png new file mode 100644 index 00000000..a039b00b Binary files /dev/null and b/tests/files/issue-113.png differ diff --git a/tests/regression.rs b/tests/regression.rs index 0175cb99..8ccfa6c6 100644 --- a/tests/regression.rs +++ b/tests/regression.rs @@ -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, + ); +}