@@ -350,11 +350,19 @@ pub(crate) fn apply_color_transform(
350
350
let width = usize:: from ( width) ;
351
351
352
352
for ( y, row) in image_data. chunks_exact_mut ( width * 4 ) . enumerate ( ) {
353
- for ( block_x, block) in row. chunks_mut ( 4 << size_bits) . enumerate ( ) {
354
- let block_index = ( y >> size_bits) * block_xsize + block_x;
355
- let red_to_blue = transform_data[ block_index * 4 ] ;
356
- let green_to_blue = transform_data[ block_index * 4 + 1 ] ;
357
- let green_to_red = transform_data[ block_index * 4 + 2 ] ;
353
+ let row_transform_data_start = ( y >> size_bits) * block_xsize * 4 ;
354
+ // the length of block_tf_data should be `block_xsize * 4`, so we could slice it with [..block_xsize * 4]
355
+ // but there is no point - `.zip()` runs until either of the iterators is consumed,
356
+ // so the extra slicing operation would be doing more work for no reason
357
+ let row_tf_data = & transform_data[ row_transform_data_start..] ;
358
+
359
+ for ( block, transform) in row
360
+ . chunks_mut ( 4 << size_bits)
361
+ . zip ( row_tf_data. chunks_exact ( 4 ) )
362
+ {
363
+ let red_to_blue = transform[ 0 ] ;
364
+ let green_to_blue = transform[ 1 ] ;
365
+ let green_to_red = transform[ 2 ] ;
358
366
359
367
for pixel in block. chunks_exact_mut ( 4 ) {
360
368
let green = u32:: from ( pixel[ 1 ] ) ;
0 commit comments