Skip to main content

GifDecoder

Trait GifDecoder 

Source
pub trait GifDecoder: Send + Sync {
    type FrameIter: Iterator<Item = Result<DecodedFrame>>;

    // Required methods
    fn decode_file(&self, path: impl AsRef<Path>) -> Result<Self::FrameIter>;
    fn decode_bytes(&self, data: &[u8]) -> Result<Self::FrameIter>;
    fn decode_reader<R: Read + Send>(
        &self,
        reader: R,
    ) -> Result<Self::FrameIter>;
    fn metadata_from_bytes(&self, data: &[u8]) -> Result<GifMetadata>;
    fn metadata_from_file(&self, path: impl AsRef<Path>) -> Result<GifMetadata>;
    fn name(&self) -> &'static str;
}
Expand description

Trait for decoding GIF files into frames.

Implementations can choose different strategies:

  • Buffered: Load all frames into memory at once
  • Streaming: Decode frames lazily on-demand

§Example

use figif_core::traits::GifDecoder;
use figif_core::decoders::BufferedDecoder;

let decoder = BufferedDecoder::new();
let frames = decoder.decode_file("animation.gif")?;

Required Associated Types§

Source

type FrameIter: Iterator<Item = Result<DecodedFrame>>

The type of iterator returned by decode operations.

Required Methods§

Source

fn decode_file(&self, path: impl AsRef<Path>) -> Result<Self::FrameIter>

Decode a GIF from a file path.

Returns an iterator over decoded frames.

Source

fn decode_bytes(&self, data: &[u8]) -> Result<Self::FrameIter>

Decode a GIF from a byte slice.

Returns an iterator over decoded frames.

Source

fn decode_reader<R: Read + Send>(&self, reader: R) -> Result<Self::FrameIter>

Decode a GIF from any reader.

Returns an iterator over decoded frames.

Source

fn metadata_from_bytes(&self, data: &[u8]) -> Result<GifMetadata>

Extract metadata without fully decoding all frames.

This is useful for getting dimensions, frame count, and duration without the overhead of decoding all pixel data.

Source

fn metadata_from_file(&self, path: impl AsRef<Path>) -> Result<GifMetadata>

Extract metadata from a file.

Source

fn name(&self) -> &'static str

Get the name of this decoder for logging/debugging.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§