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§
Sourcetype FrameIter: Iterator<Item = Result<DecodedFrame>>
type FrameIter: Iterator<Item = Result<DecodedFrame>>
The type of iterator returned by decode operations.
Required Methods§
Sourcefn decode_file(&self, path: impl AsRef<Path>) -> Result<Self::FrameIter>
fn decode_file(&self, path: impl AsRef<Path>) -> Result<Self::FrameIter>
Decode a GIF from a file path.
Returns an iterator over decoded frames.
Sourcefn decode_bytes(&self, data: &[u8]) -> Result<Self::FrameIter>
fn decode_bytes(&self, data: &[u8]) -> Result<Self::FrameIter>
Decode a GIF from a byte slice.
Returns an iterator over decoded frames.
Sourcefn decode_reader<R: Read + Send>(&self, reader: R) -> Result<Self::FrameIter>
fn decode_reader<R: Read + Send>(&self, reader: R) -> Result<Self::FrameIter>
Decode a GIF from any reader.
Returns an iterator over decoded frames.
Sourcefn metadata_from_bytes(&self, data: &[u8]) -> Result<GifMetadata>
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.
Sourcefn metadata_from_file(&self, path: impl AsRef<Path>) -> Result<GifMetadata>
fn metadata_from_file(&self, path: impl AsRef<Path>) -> Result<GifMetadata>
Extract metadata from a file.
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.