Skip to content

bitmaptools: readinto() reads whole rows from streams like sockets - #11627

Merged
dhalbert merged 1 commit into
adafruit:mainfrom
MakerClassCZ:bitmaptools-readinto-short-reads
Oct 18, 2026
Merged

dhalbert merged 1 commit into
adafruit:mainfrom
MakerClassCZ:bitmaptools-readinto-short-reads

Conversation

@lynt-smitka

Copy link
Copy Markdown

readinto() read each row with one call and treated a short read as end of file. A socket returns what has arrived, so a row split across TCP segments raised EOFError. It now reads until the row is complete with mp_stream_read_exactly(), like jpegio and audiocore.

Tested on a PicoPad (RP2040): a 312×276 4-bit BMP streamed from a socket into a Bitmap takes about 0.63 s, against 2.2 s for the same decode in Python, with identical pixels. Reading from a file is unchanged. Flash: +16 bytes

readinto() read each row with one call and took a short read as the end
of the file. A socket returns what has arrived, so a row split across TCP
segments raised EOFError. It now reads until the row is complete, with
mp_stream_read_exactly(), as jpegio and audiocore do.

On a PicoPad (RP2040), a 312x276 4-bit BMP streamed from a socket into a
Bitmap now takes about 0.63 s instead of 2.2 s for the same decode in
Python, with the same pixels. Reading from a file is unchanged. +16 bytes.
@lynt-smitka

Copy link
Copy Markdown
Author

Related: adafruit/Adafruit_CircuitPython_Requests#219 adds Response.raw. I have a follow-up to this PR that lets bitmaptools.readinto() also take objects with a readinto() method, like Response.raw or adafruit_esp32spi sockets. On a PicoPad that loads a 43 KB page from Requests into a Bitmap in about 0.72 s instead of 2.55 s.

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you!

@dhalbert
dhalbert enabled auto-merge October 18, 2026 23:05
@dhalbert
dhalbert merged commit 7c47a32 into adafruit:main Oct 18, 2026
1176 of 1178 checks passed
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.

2 participants