Ensure evaluator returns no result when all candidates are too large
This commit is contained in:
parent
f99ce277da
commit
1c85de29b0
1 changed files with 13 additions and 4 deletions
|
|
@ -154,6 +154,19 @@ impl Evaluator {
|
||||||
let idat_data = deflater.deflate(&filtered, best_candidate_size.get());
|
let idat_data = deflater.deflate(&filtered, best_candidate_size.get());
|
||||||
if let Ok(idat_data) = idat_data {
|
if let Ok(idat_data) = idat_data {
|
||||||
let estimated_output_size = image.estimated_output_size(&idat_data);
|
let estimated_output_size = image.estimated_output_size(&idat_data);
|
||||||
|
trace!(
|
||||||
|
"Eval: {}-bit {:23} {:8} {} bytes",
|
||||||
|
image.ihdr.bit_depth, description, filter, estimated_output_size
|
||||||
|
);
|
||||||
|
|
||||||
|
// Skip if it exceeds best known size. (This is important to ensure
|
||||||
|
// the evaluator returns no result when all candidates are too large.)
|
||||||
|
if let Some(max) = best_candidate_size.get() {
|
||||||
|
if estimated_output_size > max {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// We only need to retain the IDAT data in the final round
|
// We only need to retain the IDAT data in the final round
|
||||||
let new = Candidate {
|
let new = Candidate {
|
||||||
image: image.clone(),
|
image: image.clone(),
|
||||||
|
|
@ -164,10 +177,6 @@ impl Evaluator {
|
||||||
nth,
|
nth,
|
||||||
};
|
};
|
||||||
best_candidate_size.set_min(estimated_output_size);
|
best_candidate_size.set_min(estimated_output_size);
|
||||||
trace!(
|
|
||||||
"Eval: {}-bit {:23} {:8} {} bytes",
|
|
||||||
image.ihdr.bit_depth, description, filter, estimated_output_size
|
|
||||||
);
|
|
||||||
|
|
||||||
#[cfg(feature = "parallel")]
|
#[cfg(feature = "parallel")]
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue