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

webp frames iterator is now ending iteration if no more frames are decodable #2228

Merged
merged 4 commits into from May 16, 2024

Conversation

EmiOnGit
Copy link
Contributor

@EmiOnGit EmiOnGit commented May 4, 2024

Fixes #2226

The iterator returns None as soon as a DecodingError::NoMoreFrames is found.

Debatable

The current implementation returns every Frame only once regardless of the specified LoopCount. I believe this is what most people would expect, especially since LoopCount::Forever is the most used variant.

It would be a bit more performant to return the iterator at the start since the allocation of one RgbaImage/RgbImage can be saved.
(Thank you for this awesome project btw :))

…e instead of indefinitely returning an error.
Copy link
Member

@HeroicKatora HeroicKatora left a comment

Choose a reason for hiding this comment

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

There are probably existing images applicable as a test here, e.g. this one.

Would you mind expanding the regression test suite for this behavior?

@EmiOnGit
Copy link
Contributor Author

EmiOnGit commented May 5, 2024

Changes to the iterator

After benchmarking the iterator on DecodingError::NoMoreFrames again returning early I found that the early return is constantly around 8-10 percent faster on a webp animation with 6 frames (tested on two machines and 10_000 iterations). Therefore I changed the implementation to check at the start using a internal counter.

Testing

I also implemented a simple test which is checking against the internal framecount of the image_webp::WebPDecoder::num_frames(). The test is run against the 3 files in webp/extended_images which I believe to be a good representation of the expected behaviour.

advertises_rgba_but_frames_are_rgb.webp: returns the first two frames and the rest as a EOF decoding error. The iterator still exists after the specified frame-count of 12 .
anim.webp returns all frames.
lossy_alpha.webp: (not animated webp) returns one frame.

Let me know if something else should be implemented let me now. We could also check the first returned frame against the image returned by image::open, which would also be expected to be for all inputs. I wasn't sure if more tests are welcomed.

(Also I'm not sure about the clippy check failing. It also fails on my computer on the main branch so I assume it's not my fault)

@EmiOnGit EmiOnGit requested a review from HeroicKatora May 5, 2024 11:34
Copy link
Member

@HeroicKatora HeroicKatora left a comment

Choose a reason for hiding this comment

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

LGTM

@HeroicKatora
Copy link
Member

(Also I'm not sure about the clippy check failing. It also fails on my computer on the main branch so I assume it's not my fault)

clippy is linting that there are some cfg-options that do not correspond to actual features we have in Cargo.toml. Huh, weird, but definitely not your fault.

@fintelia fintelia merged commit 1207aca into image-rs:main May 16, 2024
30 of 31 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.

WebPDecoder.into_frames() always returns an error at the end of the file instead of ending iteration normally
3 participants