Skip to content

Commit

Permalink
Don't write larger file if moving from interlaced to non-interlaced
Browse files Browse the repository at this point in the history
Closes #62
  • Loading branch information
Josh Holmer committed Mar 7, 2017
1 parent 848a737 commit 6499933
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
**Version 0.15.0 (unreleased)**
- [SEMVER_MINOR] Check images for correctness before writing result ([#60](https://github.com/shssoichiro/oxipng/issues/60))
- Fix invalid output when reducing image to a different color type but file size does not improve ([#60](https://github.com/shssoichiro/oxipng/issues/60))
- Don't write new file if moving from interlaced to non-interlaced if new file would be larger

**Version 0.14.4**
- Fix bug when reducing RGBA to Indexed if image has 256 colors plus a background color
Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,7 @@ fn optimize_png(png: &mut PngData,
let filters: HashMap<u8, Vec<u8>> = filters_tmp.into_iter().collect();

let original_len = original_png.idat_data.len();
let interlacing_changed = opts.interlace.is_some() &&
opts.interlace != Some(original_png.ihdr_data.interlaced);
let added_interlacing = opts.interlace == Some(1) && original_png.ihdr_data.interlaced == 0;

let best: Option<TrialWithData> = results.into_par_iter()
.weight_max()
Expand All @@ -551,7 +550,7 @@ fn optimize_png(png: &mut PngData,
.ok();
}

if new_idat.len() < original_len || interlacing_changed || opts.force {
if new_idat.len() < original_len || added_interlacing || opts.force {
Some((trial.0, trial.1, trial.2, trial.3, new_idat))
} else {
None
Expand Down

0 comments on commit 6499933

Please # to comment.