From 268499b0db60873ef6252a3ba767b6621348eaba Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 6 Apr 2024 12:33:33 +1300 Subject: [PATCH] Allow passing a format description to the evaluator --- src/evaluate.rs | 15 +++++++++++---- src/reduction/mod.rs | 11 +++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/evaluate.rs b/src/evaluate.rs index d797f075..e67f14bf 100644 --- a/src/evaluate.rs +++ b/src/evaluate.rs @@ -108,6 +108,12 @@ impl Evaluator { /// Check if the image is smaller than others pub fn try_image(&self, image: Arc) { + let description = format!("{}", image.ihdr.color_type); + self.try_image_with_description(image, &description); + } + + /// Check if the image is smaller than others, with a description for verbose mode + pub fn try_image_with_description(&self, image: Arc, description: &str) { let nth = self.nth.fetch_add(1, SeqCst); // These clones are only cheap refcounts let deadline = self.deadline.clone(); @@ -116,6 +122,7 @@ impl Evaluator { let optimize_alpha = self.optimize_alpha; let executed = self.executed.clone(); let best_candidate_size = self.best_candidate_size.clone(); + let description = description.to_string(); // sends it off asynchronously for compression, // but results will be collected via the message queue #[cfg(feature = "parallel")] @@ -138,9 +145,9 @@ impl Evaluator { let size = idat_data.len() + image.key_chunks_size(); best_candidate_size.set_min(size); trace!( - "Eval: {}-bit {:20} {:8} {} bytes", + "Eval: {}-bit {:23} {:8} {} bytes", image.ihdr.bit_depth, - image.ihdr.color_type, + description, filter, size ); @@ -166,9 +173,9 @@ impl Evaluator { } } else if let Err(PngError::DeflatedDataTooLong(size)) = idat_data { trace!( - "Eval: {}-bit {:20} {:8} >{} bytes", + "Eval: {}-bit {:23} {:8} >{} bytes", image.ihdr.bit_depth, - image.ihdr.color_type, + description, filter, size ); diff --git a/src/reduction/mod.rs b/src/reduction/mod.rs index 1857bc87..9b860c5f 100644 --- a/src/reduction/mod.rs +++ b/src/reduction/mod.rs @@ -83,7 +83,7 @@ pub(crate) fn perform_reductions( } // If either action changed the data then enter this into the evaluator if !Arc::ptr_eq(&png, &baseline) { - eval.try_image(png.clone()); + eval.try_image_with_description(png.clone(), "Indexed (luma sort)"); evaluation_added = true; } } @@ -123,7 +123,7 @@ pub(crate) fn perform_reductions( // For relatively small differences, enter this into the evaluator // Otherwise we're confident enough for it to become the baseline if png.data.len() - new.data.len() <= INDEXED_MAX_DIFF { - eval.try_image(new.clone()); + eval.try_image_with_description(new.clone(), "Indexed (luma sort)"); evaluation_added = true; } else { baseline = new.clone(); @@ -149,7 +149,10 @@ pub(crate) fn perform_reductions( if let ColorType::Indexed { palette } = &reduced.ihdr.color_type { if !palettes.contains(palette) { palettes.push(palette.clone()); - eval.try_image(Arc::new(reduced)); + eval.try_image_with_description( + Arc::new(reduced), + "Indexed (battiato sort)", + ); evaluation_added = true; } } @@ -162,7 +165,7 @@ pub(crate) fn perform_reductions( if let ColorType::Indexed { palette } = &reduced.ihdr.color_type { if !palettes.contains(palette) { palettes.push(palette.clone()); - eval.try_image(Arc::new(reduced)); + eval.try_image_with_description(Arc::new(reduced), "Indexed (mzeng sort)"); evaluation_added = true; } }