#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.

13 stable releases

3.1.1 Jan 25, 2021
3.0.1 Nov 3, 2020
2.4.2 Nov 4, 2020
2.4.1 Jul 6, 2020
1.0.1 Mar 1, 2017

#36 in Video

Download history 549/week @ 2022-03-12 628/week @ 2022-03-19 494/week @ 2022-03-26 1814/week @ 2022-04-02 707/week @ 2022-04-09 703/week @ 2022-04-16 949/week @ 2022-04-23 805/week @ 2022-04-30 575/week @ 2022-05-07 827/week @ 2022-05-14 530/week @ 2022-05-21 586/week @ 2022-05-28 628/week @ 2022-06-04 567/week @ 2022-06-11 562/week @ 2022-06-18 498/week @ 2022-06-25

2,344 downloads per month
Used in 22 crates (8 directly)

MIT/Apache

12KB
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