From 144b0a710c2d2fda3a43ab3724706a06aa3306bb Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 2 Jun 2026 17:36:46 +1200 Subject: [PATCH] Don't use battiato --- src/reduction/mod.rs | 44 ++++++++-------------------------------- src/reduction/palette.rs | 2 ++ 2 files changed, 10 insertions(+), 36 deletions(-) diff --git a/src/reduction/mod.rs b/src/reduction/mod.rs index fcb7e6fc..ffc3f8fe 100644 --- a/src/reduction/mod.rs +++ b/src/reduction/mod.rs @@ -1,6 +1,6 @@ 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; use crate::alpha::*; @@ -134,43 +134,15 @@ pub(crate) fn perform_reductions( } } - // Attempt additional palette sorting techniques - if !cheap && opts.palette_reduction { - // 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()); - } + // Attempt to sort the palette using the ezeng method + if !cheap && opts.palette_reduction && !deadline.passed() { // 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); - - // Attempt to sort the palette using the battiato method - if !deadline.passed() { - if let Some(reduced) = sorted_palette_battiato(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 (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; - } - } + if let Some(reduced) = sorted_palette_ezeng(input) { + // Skip evaluation if the palette is the same as the baseline + if reduced.ihdr.color_type != baseline.ihdr.color_type { + eval.try_image_with_description(Arc::new(reduced), "Indexed (ezeng sort)"); + evaluation_added = true; } } } diff --git a/src/reduction/palette.rs b/src/reduction/palette.rs index ff53bff9..9b4fd62d 100644 --- a/src/reduction/palette.rs +++ b/src/reduction/palette.rs @@ -130,6 +130,7 @@ pub fn sorted_palette(png: &PngImage) -> Option { } /// 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] pub fn sorted_palette_mzeng(png: &PngImage) -> Option { // Interlacing not currently supported @@ -178,6 +179,7 @@ pub fn sorted_palette_ezeng(png: &PngImage) -> Option { } /// 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] pub fn sorted_palette_battiato(png: &PngImage) -> Option { // Interlacing not currently supported