Skip to content

Commit

Permalink
Round palette sizes in --extra
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Jan 22, 2024
1 parent d4cd635 commit 5bf8b1a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ required-features = ["binary"]
clap = { version = "4.3.24", features = ["cargo"], optional = true }
gif = { version = "0.13.0-beta.1", default-features = false, features = ["std", "raii_no_panic"] }
gif-dispose = "5.0.0-beta.1"
imagequant = "4.2.2"
imgref = "1.10.0"
lodepng = { version = "3.9.3", optional = true }
imagequant = "4.3.0"
lodepng = { version = "3.10.1", optional = true }
pbr = { version = "1.1.1", optional = true }
resize = { version = "0.8.3", features = ["rayon"] }
rgb = "0.8.37"
Expand Down
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,18 @@ impl Writer {
}

let mut res = liq.quantize(&mut img)?;

// GIF only stores power-of-two palette sizes
if self.settings.extra_effort {
let len = res.palette_len();
// it has little impact on compression (128c -> 64c is only 7% smaller)
if (len < 128 || len > 220) && len != len.next_power_of_two() {
liq.set_max_colors(len.next_power_of_two() as _)?;
liq.set_quality(0, 100)?;
res = liq.quantize(&mut img)?;
}
}

res.set_dithering_level((f32::from(self.settings.s.quality) / 50.0 - 1.).max(0.2))?;

let mut out = Vec::new();
Expand Down

0 comments on commit 5bf8b1a

Please sign in to comment.