gif_dispose/lib.rs
1//! Implements GIF disposal method for the [gif crate](https://lib.rs/crates/gif).
2//!
3//! The gif crate only exposes raw frame data that is not sufficient
4//! to render GIFs properly. GIF requires special composing of frames
5//! which, as this crate shows, is non-trivial.
6//!
7//! ```rust,no_run
8//! let file = std::fs::File::open("example.gif")?;
9//!
10//! let mut gif_opts = gif::DecodeOptions::new();
11//! // Important:
12//! gif_opts.set_color_output(gif::ColorOutput::Indexed);
13//!
14//! let mut decoder = gif_opts.read_info(file)?;
15//! let mut screen = gif_dispose::Screen::new_decoder(&decoder);
16//!
17//! while let Some(frame) = decoder.read_next_frame()? {
18//! screen.blit_frame(&frame)?;
19//! let _ = screen.pixels_rgba().clone(); // that's the frame now in RGBA format
20//! let _ = screen.pixels_rgba().to_contiguous_buf(); // that works too
21//! }
22//! # Ok::<_, Box<dyn std::error::Error>>(())
23//! ```
24
25mod disposal;
26mod screen;
27
28pub use crate::screen::Screen;
29pub use crate::screen::TempDisposedStateScreen;
30pub use imgref::ImgRef;
31pub use rgb::{RGB8, RGBA8};
32
33use std::error::Error as StdError;
34use std::fmt;
35
36#[derive(Eq, PartialEq, Copy, Clone, Debug)]
37#[non_exhaustive]
38pub enum Error {
39 /// GIF must have either a global palette set, or per-frame palette set. If there is none, it's not possible to render.
40 NoPalette,
41}
42
43impl fmt::Display for Error {
44 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45 f.write_str("No palette")
46 }
47}
48
49impl StdError for Error {}