Allow passing a format description to the evaluator

This commit is contained in:
Andrew 2024-04-06 12:33:33 +13:00 committed by andrews05
parent 2d3555fe0f
commit 268499b0db
2 changed files with 18 additions and 8 deletions

View file

@ -108,6 +108,12 @@ impl Evaluator {
/// Check if the image is smaller than others
pub fn try_image(&self, image: Arc<PngImage>) {
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<PngImage>, 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
);

View file

@ -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;
}
}