#gif #animation #frame

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.

17 stable releases (4 major)

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

#7 in Video

Download history 76565/week @ 2024-08-02 59868/week @ 2024-08-09 57777/week @ 2024-08-16 56216/week @ 2024-08-23 47469/week @ 2024-08-30 43953/week @ 2024-09-06 46540/week @ 2024-09-13 46597/week @ 2024-09-20 50650/week @ 2024-09-27 47547/week @ 2024-10-04 37083/week @ 2024-10-11 12573/week @ 2024-10-18 10949/week @ 2024-10-25 9755/week @ 2024-11-01 10958/week @ 2024-11-08 12355/week @ 2024-11-15

46,263 downloads per month
Used in 30 crates (11 directly)

MIT/Apache

13KB
162 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

~555KB