Skip to content

Commit 577d02f

Browse files
Shnatselkornelski
authored andcommitted
Add comments
1 parent d11922e commit 577d02f

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/lossless_transform.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,11 @@ pub(crate) fn apply_color_indexing_transform(
387387
table_data: &[u8],
388388
) {
389389
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
390391
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
391393
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
392395
let table: &[[u8; 4]; 256] = table.as_slice().try_into().unwrap();
393396

394397
for pixel in image_data.chunks_exact_mut(4) {

0 commit comments

Comments
 (0)