#gif #frames #animation

gif-dispose

Implements GIF disposal method for the gif crate. The gif crate only exposes raw frame data that is not sufficient to render GIFs properly. GIF requires special composing of frames which, as this crate shows, is non-trivial.

14 stable releases (3 major)

4.0.0 Nov 17, 2022
3.2.0 Nov 17, 2022
3.1.1 Jan 25, 2021
3.0.1 Nov 3, 2020
1.0.1 Mar 1, 2017

#38 in Video

Download history 463/week @ 2022-10-17 552/week @ 2022-10-24 631/week @ 2022-10-31 862/week @ 2022-11-07 871/week @ 2022-11-14 608/week @ 2022-11-21 737/week @ 2022-11-28 1049/week @ 2022-12-05 798/week @ 2022-12-12 624/week @ 2022-12-19 510/week @ 2022-12-26 874/week @ 2023-01-02 1009/week @ 2023-01-09 915/week @ 2023-01-16 860/week @ 2023-01-23 861/week @ 2023-01-30

3,721 downloads per month
Used in 25 crates (10 directly)

MIT/Apache

13KB
167 lines

Please dispose of GIF frames properly

This crate implements GIF disposal method for the gif crate.

The gif crate only exposes raw frame data that is not sufficient to render animated GIFs properly. GIF requires special composing of frames which is non-trivial.

Usage

let file = File::open("example.gif")?;

let mut gif_opts = gif::DecodeOptions::new();
// Important:
gif_opts.set_color_output(gif::ColorOutput::Indexed);

let mut decoder = gif_opts.read_info(file)?;
let mut screen = gif_dispose::Screen::new_decoder(&decoder);

while let Some(frame) = decoder.read_next_frame()? {
    screen.blit_frame(&frame)?;
    screen.pixels // that's the frame now in RGBA format
}

The screen.pixels buffer uses ImgVec to represent a 2D image.

See examples/explode.rs for more.

Requirements

  • Latest stable Rust (1.45+)

lib.rs:

Implements GIF disposal method for the gif crate.

The gif crate only exposes raw frame data that is not sufficient to render GIFs properly. GIF requires special composing of frames which, as this crate shows, is non-trivial.

let file = std::fs::File::open("example.gif")?;

let mut gif_opts = gif::DecodeOptions::new();
// Important:
gif_opts.set_color_output(gif::ColorOutput::Indexed);

let mut decoder = gif_opts.read_info(file)?;
let mut screen = gif_dispose::Screen::new_decoder(&decoder);

while let Some(frame) = decoder.read_next_frame()? {
    screen.blit_frame(&frame)?;
    screen.pixels.clone(); // that's the frame now in RGBA format
}
# Ok::<_, Box<dyn std::error::Error>>(())

Dependencies

~1MB