image-rs / image

Encoding and decoding images in Rust
Apache License 2.0
4.98k stars 618 forks source link

Looping animated images #1893

Open sophie-h opened 1 year ago

sophie-h commented 1 year ago

While implementing animated images, I noticed two things:

  1. The Frames iterator seems to decode the animation frame by frame for GIF and PNG. But for WebP it looks like the complete image is decoded first. Is this correct? Is this a format or an implementation limitation?
  2. The typical way to show GIFs etc is, of course, to loop them. It looks like with image-rs there is no way around creating a new decoder each time the animation has finished (if the decoded frames are not all kept in memory). I wonder if it would be possible to either create an alternative to into_frames(self) that takes &mut self or make Frames implement Clone. But maybe I just overlooked an existing solution.
sophie-h commented 1 year ago

There is an as_frames API in #1925 that would allow easier looping