Use mzeng in reductions
This commit is contained in:
parent
4b2bc1c59d
commit
c88a67a2ca
1 changed files with 36 additions and 7 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{evaluate::Evaluator, png::PngImage, Deadline, Deflaters, Options};
|
use crate::{evaluate::Evaluator, png::PngImage, ColorType, Deadline, Deflaters, Options};
|
||||||
|
|
||||||
pub mod alpha;
|
pub mod alpha;
|
||||||
use crate::alpha::*;
|
use crate::alpha::*;
|
||||||
|
|
@ -132,14 +132,43 @@ pub(crate) fn perform_reductions(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to sort the palette using an alternative method
|
// Attempt additional palette sorting techniques
|
||||||
if !cheap && opts.palette_reduction && !deadline.passed() {
|
if !cheap && opts.palette_reduction {
|
||||||
// Make sure we use the `indexed` var if it exists
|
// Collect a list of palettes so we can avoid evaluating the same one twice
|
||||||
if let Some(reduced) = sorted_palette_battiato(indexed.as_ref().unwrap_or(&png)) {
|
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
|
||||||
|
// 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(Arc::new(reduced));
|
eval.try_image(Arc::new(reduced));
|
||||||
evaluation_added = true;
|
evaluation_added = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attempt to sort the palette using the mzeng method
|
||||||
|
if !deadline.passed() {
|
||||||
|
if let Some(reduced) = sorted_palette_mzeng(input) {
|
||||||
|
if let ColorType::Indexed { palette } = &reduced.ihdr.color_type {
|
||||||
|
if !palettes.contains(palette) {
|
||||||
|
palettes.push(palette.clone());
|
||||||
|
eval.try_image(Arc::new(reduced));
|
||||||
|
evaluation_added = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Attempt to reduce to a lower bit depth
|
// Attempt to reduce to a lower bit depth
|
||||||
if opts.bit_depth_reduction && !deadline.passed() {
|
if opts.bit_depth_reduction && !deadline.passed() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue