Skip to content

Commit

Permalink
Fix unfiltering of first scan line in each pass of an interlaced inpu…
Browse files Browse the repository at this point in the history
…t file

Closes #92
  • Loading branch information
Josh Holmer committed Dec 23, 2017
1 parent 833611b commit f8c62de
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Version 0.18.2 (unreleased)
- Bump `image` to 0.18
- Fix unfiltering of scan lines in interlaced images ([#92](https://github.com/shssoichiro/oxipng/issues/92))

### Version 0.18.1
- Bump `rayon` to 0.9
Expand Down
7 changes: 7 additions & 0 deletions src/png.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,14 @@ impl PngData {
8f32)
.ceil() as usize;
let mut last_line: Vec<u8> = Vec::new();
let mut last_pass = 1;
for line in self.scan_lines() {
if let Some(pass) = line.pass {
if pass != last_pass {
last_line = Vec::new();
last_pass = pass;
}
}
let unfiltered_line = unfilter_line(line.filter, bpp, &line.data, &last_line);
unfiltered.push(0);
unfiltered.extend_from_slice(&unfiltered_line);
Expand Down
Binary file added tests/files/issue-92.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,41 @@ fn issue_89() {
BitDepth::Eight,
);
}

#[test]
fn issue_92_filter_0() {
let input = PathBuf::from("tests/files/issue-92.png");
let opts = get_opts(&input);
let output = opts.out_file.clone();

test_it_converts(
&input,
&output,
&opts,
ColorType::Grayscale,
BitDepth::Eight,
ColorType::Grayscale,
BitDepth::Eight,
);
}

#[test]
fn issue_92_filter_5() {
let input = PathBuf::from("tests/files/issue-92.png");
let mut opts = get_opts(&input);
let mut filter = HashSet::new();
filter.insert(5);
opts.filter = filter;
opts.out_file = input.with_extension("-f5-out.png").to_owned();
let output = opts.out_file.clone();

test_it_converts(
&input,
&output,
&opts,
ColorType::Grayscale,
BitDepth::Eight,
ColorType::Grayscale,
BitDepth::Eight,
);
}

0 comments on commit f8c62de

Please sign in to comment.