Skip to content

Commit a426fab

Browse files
committed
Fix secondary palette sort
This was only working if the input image was already indexed
1 parent 0608ab9 commit a426fab

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/reduction/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ pub(crate) fn perform_reductions(
114114
}
115115

116116
// Attempt to reduce to indexed
117+
// Keep the existing `png` var in case it is grayscale - we can test both for depth reduction later
117118
let mut indexed = None;
118119
if opts.color_type_reduction && !deadline.passed() {
119120
if let Some(reduced) = reduced_to_indexed(&png, opts.grayscale_reduction) {
@@ -133,7 +134,8 @@ pub(crate) fn perform_reductions(
133134

134135
// Attempt to sort the palette using an alternative method
135136
if !cheap && opts.palette_reduction && !deadline.passed() {
136-
if let Some(reduced) = sorted_palette_battiato(&png) {
137+
// Make sure we use the `indexed` var if it exists
138+
if let Some(reduced) = sorted_palette_battiato(indexed.as_ref().unwrap_or(&png)) {
137139
eval.try_image(Arc::new(reduced));
138140
evaluation_added = true;
139141
}

0 commit comments

Comments
 (0)