diff --git a/Cargo.toml b/Cargo.toml index 4f65598..a32a971 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/lib.rs b/src/lib.rs index faf93a8..0929b92 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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();