pub struct AvifParser<'data> { /* private fields */ }Expand description
Zero-copy AVIF parser backed by a borrowed or owned byte buffer.
AvifParser records byte offsets during parsing but does not copy
mdat payload data. Data access methods return Cow<[u8]> — borrowed
when the item is a single contiguous extent, owned when extents must
be concatenated.
§Constructors
| Method | Lifetime | Zero-copy? |
|---|---|---|
from_bytes | 'data | Yes — borrows the slice |
from_owned | 'static | Within the owned buffer |
from_reader | 'static | Reads all, then owned |
§Example
use zenavif_parse::AvifParser;
let bytes = std::fs::read("image.avif")?;
let parser = AvifParser::from_bytes(&bytes)?;
let primary = parser.primary_data()?; // Cow::Borrowed for single-extentImplementations§
Source§impl<'data> AvifParser<'data>
impl<'data> AvifParser<'data>
Sourcepub fn from_bytes(data: &'data [u8]) -> Result<Self>
pub fn from_bytes(data: &'data [u8]) -> Result<Self>
Parse AVIF from a borrowed byte slice (true zero-copy).
The returned parser borrows data — single-extent items will be
returned as Cow::Borrowed slices into this buffer.
Sourcepub fn from_bytes_with_config(
data: &'data [u8],
config: &DecodeConfig,
stop: &dyn Stop,
) -> Result<Self>
pub fn from_bytes_with_config( data: &'data [u8], config: &DecodeConfig, stop: &dyn Stop, ) -> Result<Self>
Parse AVIF from a borrowed byte slice with resource limits.
Sourcepub fn from_owned(data: Vec<u8>) -> Result<AvifParser<'static>>
pub fn from_owned(data: Vec<u8>) -> Result<AvifParser<'static>>
Parse AVIF from an owned buffer.
The returned parser owns the data — single-extent items will still
be returned as Cow::Borrowed slices (borrowing from the internal buffer).
Sourcepub fn from_owned_with_config(
data: Vec<u8>,
config: &DecodeConfig,
stop: &dyn Stop,
) -> Result<AvifParser<'static>>
pub fn from_owned_with_config( data: Vec<u8>, config: &DecodeConfig, stop: &dyn Stop, ) -> Result<AvifParser<'static>>
Parse AVIF from an owned buffer with resource limits.
Sourcepub fn from_reader<R: Read>(reader: &mut R) -> Result<AvifParser<'static>>
pub fn from_reader<R: Read>(reader: &mut R) -> Result<AvifParser<'static>>
Parse AVIF from a reader (reads all bytes, then parses).
Sourcepub fn from_reader_with_config<R: Read>(
reader: &mut R,
config: &DecodeConfig,
stop: &dyn Stop,
) -> Result<AvifParser<'static>>
pub fn from_reader_with_config<R: Read>( reader: &mut R, config: &DecodeConfig, stop: &dyn Stop, ) -> Result<AvifParser<'static>>
Parse AVIF from a reader with resource limits.
Sourcepub fn primary_data(&self) -> Result<Cow<'_, [u8]>>
pub fn primary_data(&self) -> Result<Cow<'_, [u8]>>
Get primary item data.
Returns Cow::Borrowed for single-extent items, Cow::Owned for multi-extent.
Sourcepub fn frame(&self, index: usize) -> Result<FrameRef<'_>>
pub fn frame(&self, index: usize) -> Result<FrameRef<'_>>
Get a single animation frame by index.
Sourcepub fn frames(&self) -> FrameIterator<'_> ⓘ
pub fn frames(&self) -> FrameIterator<'_> ⓘ
Iterate over all animation frames.
Sourcepub fn animation_info(&self) -> Option<AnimationInfo>
pub fn animation_info(&self) -> Option<AnimationInfo>
Get animation metadata (if animated).
Sourcepub fn grid_config(&self) -> Option<&GridConfig>
pub fn grid_config(&self) -> Option<&GridConfig>
Get grid configuration (if grid image).
Sourcepub fn grid_tile_count(&self) -> usize
pub fn grid_tile_count(&self) -> usize
Get number of grid tiles.
Sourcepub fn premultiplied_alpha(&self) -> bool
pub fn premultiplied_alpha(&self) -> bool
Check if alpha channel uses premultiplied alpha.
Sourcepub fn primary_metadata(&self) -> Result<AV1Metadata>
pub fn primary_metadata(&self) -> Result<AV1Metadata>
Parse AV1 metadata from the primary item.
Sourcepub fn alpha_metadata(&self) -> Option<Result<AV1Metadata>>
pub fn alpha_metadata(&self) -> Option<Result<AV1Metadata>>
Parse AV1 metadata from the alpha item, if present.
Sourcepub fn to_avif_data(&self) -> Result<AvifData>
👎Deprecated since 1.5.0: Use AvifParser methods directly instead of converting to AvifData
pub fn to_avif_data(&self) -> Result<AvifData>
Convert to AvifData (eagerly loads all frames and tiles).
Provided for migration from the eager API. Prefer using AvifParser
methods directly.