image-rs / image

Encoding and decoding images in Rust
Apache License 2.0
4.76k stars 589 forks source link

Animated WebP's cannot actually be loaded #2263

Open SludgePhD opened 2 weeks ago

SludgePhD commented 2 weeks ago

WebPDecoder fails to decode WebP animations.

Expected

It should probably work?

Actual behaviour

Reproduction steps

WebPDecoder::new(BufReader::new(File::open(path)?))?.into_frames().collect_frames()?

piston.zip

porkbrain commented 3 days ago

I believe this to be a regression introduced in 0.25.

My code using 0.24 plays the image fine (also tested using this repo's tests/images/webp/extended_images/anim.webp), albeit the has_animation method returns false.

After update to 0.25 (wrapping the bytes in Cursor instead of passing them as &[u8]) I cannot play my test webp nor the one I mentioned above. As mentioned in the issue description, collect_frames runs into

Format error decoding WebP: No more frames

Although ironically, after the update, the has_animation method now returns correctly true.

porkbrain commented 3 days ago

~This commit breaks the webp animation loader.~

EDIT: That's impossible, probably some caching issue when I was bisecting the culprit commit. Going to try again

porkbrain commented 3 days ago

This issue is actually quite straightforward. The iterator now returns an error if there are no more frames instead of None.

decoder
            .into_frames()
            .take_while(|frame| frame.is_ok())
            .collect()

Collecting the frames manually this way works. I will send an MR with a suggested fix as I believe NoMoreFrames should be caught in the iterator and converted to None.