Skip to content

Refactor BMP row decoding to work on byte slices#2737

Merged
197g merged 3 commits intoimage-rs:mainfrom
telecos:refactor/bmp-rowread-byte-slice
Jan 21, 2026
Merged

Refactor BMP row decoding to work on byte slices#2737
197g merged 3 commits intoimage-rs:mainfrom
telecos:refactor/bmp-rowread-byte-slice

Conversation

@telecos
Copy link
Contributor

@telecos telecos commented Jan 20, 2026

Refactors BMP row decoding functions to separate I/O operations from pixel processing logic using pre-allocated buffers.

Changes

Uncompressed and bitfield formats (read_full_byte_pixel_data, read_16_bit_pixel_data, read_32_bit_pixel_data):

  • Allocate a single row buffer outside the with_rows closure
  • Read entire rows with one read_exact() call per row
  • Process pixels from the buffer without additional I/O

RLE-compressed formats (read_rle_data):

  • Introduced RleReader struct with 8KB internal buffer
  • Reads compressed data in chunks to minimize system calls
  • Provides read_byte() and read_bytes() methods for RLE instruction parsing

read_palettized_pixel_data already uses this pattern (row buffer allocated outside closure).

This changeset is going towards #2696

@telecos telecos marked this pull request as ready for review January 20, 2026 18:17
@telecos telecos requested a review from anforowicz January 20, 2026 23:03
@telecos telecos force-pushed the refactor/bmp-rowread-byte-slice branch from 807082d to cb86a22 Compare January 21, 2026 00:55
@telecos telecos requested a review from 197g January 21, 2026 00:57
@197g 197g merged commit 7ce18df into image-rs:main Jan 21, 2026
32 checks passed
@telecos telecos deleted the refactor/bmp-rowread-byte-slice branch January 21, 2026 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants