Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure_min_length_buffer! #197

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

ensure_min_length_buffer! #197

wants to merge 2 commits into from

Conversation

kornelski
Copy link
Contributor

@kornelski kornelski commented Jan 5, 2025

Improvement over #196

More info: image-rs/image-png#534 (comment)

@fintelia
Copy link
Contributor

Sorry, I've mean meaning to write up a reply for this.

I think this is an improvement over the gif crate's current byte-at-a-time state machine loop. It reduces the number of states and makes the decoding portion clearer. I'm not a big fan of using macros for control flow, but uh, that's what goto! is already doing so I think it is fine having ensure_min_length_buffer! do the same.

As far as the broader question of how to structure decoders, I'm less convinced that a single forward pass state machine is necessarily best. There's a bunch of different options with different tradeoffs. Some of the simple decoders in image directly use read_exact to pull data they need. The decoder in image-webp scans through the file at the start to discover metadata and the locations of chunks and then later seeks back when it needs to read those chunks, which seems to work pretty well there. And there's also the possibility of hybrid schemes. libpng decodes most chunks using a high level state machine, but handles all the (consecutive) IDAT chunks within a single function.

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