File tree Expand file tree Collapse file tree 1 file changed +3
-0
lines changed Expand file tree Collapse file tree 1 file changed +3
-0
lines changed Original file line number Diff line number Diff line change @@ -387,8 +387,11 @@ pub(crate) fn apply_color_indexing_transform(
387
387
table_data : & [ u8 ] ,
388
388
) {
389
389
if table_size > 16 {
390
+ // convert the table of colors into a Vec of color values that can be directly indexed, and that the compiler knows are always 4 bytes in size
390
391
let mut table: Vec < [ u8 ; 4 ] > = table_data. chunks_exact ( 4 ) . map ( |c| TryInto :: < [ u8 ; 4 ] > :: try_into ( c) . unwrap ( ) ) . collect ( ) ;
392
+ // pad the table to 256 values if it's smaller than that so we could index into it by u8 without bounds checks
391
393
table. resize ( 256 , [ 0 ; 4 ] ) ;
394
+ // convince the compiler that the length of the table is 256 to avoid bounds checks in the loop below
392
395
let table: & [ [ u8 ; 4 ] ; 256 ] = table. as_slice ( ) . try_into ( ) . unwrap ( ) ;
393
396
394
397
for pixel in image_data. chunks_exact_mut ( 4 ) {
You can’t perform that action at this time.
0 commit comments