From 716b5bf1353be315ddb5cd3a343efecbd8ae46c0 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 4 Dec 2022 18:25:59 +1300 Subject: [PATCH] Black alpha before color type reductions --- src/lib.rs | 7 +++++++ src/reduction/mod.rs | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 9728245e..cd74186a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -726,6 +726,13 @@ fn perform_reductions( } if opts.color_type_reduction { + // Perform a black alpha reduction before color type reductions + // This can allow reductions from alpha to indexed which may not have been possible otherwise + if !opts.alphas.is_empty() { + if let Some(reduced) = filtered_alpha_channel(&png, AlphaOptim::Black) { + png = Arc::new(reduced); + } + } if let Some(reduced) = reduce_color_type(&png, opts.grayscale_reduction) { png = Arc::new(reduced); eval.try_image(png.clone()); diff --git a/src/reduction/mod.rs b/src/reduction/mod.rs index d261549a..b775f753 100644 --- a/src/reduction/mod.rs +++ b/src/reduction/mod.rs @@ -12,7 +12,7 @@ use crate::bit_depth::reduce_bit_depth_8_or_less; pub mod color; use crate::color::*; -pub(crate) use crate::alpha::try_alpha_reductions; +pub(crate) use crate::alpha::{filtered_alpha_channel, try_alpha_reductions}; pub(crate) use crate::bit_depth::reduce_bit_depth; /// Attempt to reduce the number of colors in the palette