Don't use battiato

This commit is contained in:
Andrew 2026-06-02 17:36:46 +12:00
parent 4faef9c4e3
commit 144b0a710c
2 changed files with 10 additions and 36 deletions

View file

@ -1,6 +1,6 @@
use std::sync::Arc; use std::sync::Arc;
use crate::{ColorType, Deadline, Deflater, Options, evaluate::Evaluator, png::PngImage}; use crate::{Deadline, Deflater, Options, evaluate::Evaluator, png::PngImage};
pub mod alpha; pub mod alpha;
use crate::alpha::*; use crate::alpha::*;
@ -134,43 +134,15 @@ pub(crate) fn perform_reductions(
} }
} }
// Attempt additional palette sorting techniques // Attempt to sort the palette using the ezeng method
if !cheap && opts.palette_reduction { if !cheap && opts.palette_reduction && !deadline.passed() {
// Collect a list of palettes so we can avoid evaluating the same one twice
let mut palettes = Vec::new();
if let ColorType::Indexed { palette } = &baseline.ihdr.color_type {
palettes.push(palette.clone());
}
// Make sure we use the `indexed` var as input if it exists // Make sure we use the `indexed` var as input if it exists
// This one doesn't need to be kept in the palette list as the sorters will fail if there's no change
let input = indexed.as_ref().unwrap_or(&png); let input = indexed.as_ref().unwrap_or(&png);
if let Some(reduced) = sorted_palette_ezeng(input) {
// Attempt to sort the palette using the battiato method // Skip evaluation if the palette is the same as the baseline
if !deadline.passed() { if reduced.ihdr.color_type != baseline.ihdr.color_type {
if let Some(reduced) = sorted_palette_battiato(input) { eval.try_image_with_description(Arc::new(reduced), "Indexed (ezeng sort)");
if let ColorType::Indexed { palette } = &reduced.ihdr.color_type { evaluation_added = true;
if !palettes.contains(palette) {
palettes.push(palette.clone());
eval.try_image_with_description(
Arc::new(reduced),
"Indexed (battiato sort)",
);
evaluation_added = true;
}
}
}
}
// Attempt to sort the palette using the ezeng method
if !deadline.passed() {
if let Some(reduced) = sorted_palette_ezeng(input) {
if let ColorType::Indexed { palette } = &reduced.ihdr.color_type {
if !palettes.contains(palette) {
palettes.push(palette.clone());
eval.try_image_with_description(Arc::new(reduced), "Indexed (ezeng sort)");
evaluation_added = true;
}
}
} }
} }
} }

View file

@ -130,6 +130,7 @@ pub fn sorted_palette(png: &PngImage) -> Option<PngImage> {
} }
/// Sort the colors in the palette using the mzeng technique, returning the sorted image if successful /// Sort the colors in the palette using the mzeng technique, returning the sorted image if successful
// (Note: This is currently unused as it is outclassed by the ezeng method)
#[must_use] #[must_use]
pub fn sorted_palette_mzeng(png: &PngImage) -> Option<PngImage> { pub fn sorted_palette_mzeng(png: &PngImage) -> Option<PngImage> {
// Interlacing not currently supported // Interlacing not currently supported
@ -178,6 +179,7 @@ pub fn sorted_palette_ezeng(png: &PngImage) -> Option<PngImage> {
} }
/// Sort the colors in the palette using the battiato technique, returning the sorted image if successful /// Sort the colors in the palette using the battiato technique, returning the sorted image if successful
// (Note: This is currently unused as it is outclassed by the ezeng method)
#[must_use] #[must_use]
pub fn sorted_palette_battiato(png: &PngImage) -> Option<PngImage> { pub fn sorted_palette_battiato(png: &PngImage) -> Option<PngImage> {
// Interlacing not currently supported // Interlacing not currently supported