@@ -143,22 +143,23 @@ pub(crate) fn perform_reductions(
143
143
144
144
// Attempt to reduce to a lower bit depth
145
145
if opts. bit_depth_reduction && !deadline. passed ( ) {
146
- // First try reducing the `png` var (could be grayscale or indexed)
146
+ // First try the `png` var
147
147
let reduced = reduced_bit_depth_8_or_less ( & png) ;
148
- // It's possible that an indexed version will be smaller (it might reach a lower depth),
149
- // but grayscale is usually better so we'll skip it if we're doing cheap evaluations and
150
- // already have a reduced image.
151
- let try_indexed = !cheap || reduced. is_none ( ) ;
148
+ // Then try the `indexed` var, unless we're doing cheap evaluations and already have a reduction
149
+ if ( !cheap || reduced. is_none ( ) ) && !deadline. passed ( ) {
150
+ if let Some ( indexed) = indexed. and_then ( |png| reduced_bit_depth_8_or_less ( & png) ) {
151
+ // Only evaluate this if it's different from the first result (which must be grayscale if it exists)
152
+ if reduced. as_ref ( ) . map_or ( true , |r| r. data != indexed. data ) {
153
+ eval. try_image ( Arc :: new ( indexed) ) ;
154
+ evaluation_added = true ;
155
+ }
156
+ }
157
+ }
158
+ // Enter the first result into the evaluator
152
159
if let Some ( reduced) = reduced {
153
160
eval. try_image ( Arc :: new ( reduced) ) ;
154
161
evaluation_added = true ;
155
162
}
156
- if try_indexed && !deadline. passed ( ) {
157
- if let Some ( reduced) = indexed. and_then ( |png| reduced_bit_depth_8_or_less ( & png) ) {
158
- eval. try_image ( Arc :: new ( reduced) ) ;
159
- evaluation_added = true ;
160
- }
161
- }
162
163
}
163
164
164
165
if evaluation_added {
0 commit comments