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

15 stable releases (4 major)

5.0.0-beta.2 Jan 23, 2024
4.0.1 Sep 21, 2023
4.0.0 Nov 17, 2022
3.2.0 Nov 17, 2022
1.0.1 Mar 1, 2017

#10 in Video

Download history 58455/week @ 2023-12-07 79323/week @ 2023-12-14 29878/week @ 2023-12-21 40290/week @ 2023-12-28 81747/week @ 2024-01-04 60601/week @ 2024-01-11 20700/week @ 2024-01-18 21126/week @ 2024-01-25 26866/week @ 2024-02-01 24512/week @ 2024-02-08 32072/week @ 2024-02-15 32345/week @ 2024-02-22 32069/week @ 2024-02-29 31134/week @ 2024-03-07 31758/week @ 2024-03-14 20609/week @ 2024-03-21

121,667 downloads per month
Used in 28 crates (10 directly)

MIT/Apache

13KB
154 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)?;
    let _ = screen.pixels_rgba().clone(); // that's the frame now in RGBA format
    let _ = screen.pixels_rgba().to_contiguous_buf(); // that works too
}

Dependencies

~350KB