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 av1_config(&self) -> Option<&AV1Config>
pub fn av1_config(&self) -> Option<&AV1Config>
Get the AV1 codec configuration for the primary item, if present.
This is parsed from the av1C property box in the container.
Sourcepub fn color_info(&self) -> Option<&ColorInformation>
pub fn color_info(&self) -> Option<&ColorInformation>
Get colour information for the primary item, if present.
This is parsed from the colr property box in the container.
For CICP/nclx values, this is the authoritative source and may
differ from values in the AV1 bitstream sequence header.
Sourcepub fn rotation(&self) -> Option<&ImageRotation>
pub fn rotation(&self) -> Option<&ImageRotation>
Get rotation for the primary item, if present.
Sourcepub fn mirror(&self) -> Option<&ImageMirror>
pub fn mirror(&self) -> Option<&ImageMirror>
Get mirror for the primary item, if present.
Sourcepub fn clean_aperture(&self) -> Option<&CleanAperture>
pub fn clean_aperture(&self) -> Option<&CleanAperture>
Get clean aperture (crop) for the primary item, if present.
Sourcepub fn pixel_aspect_ratio(&self) -> Option<&PixelAspectRatio>
pub fn pixel_aspect_ratio(&self) -> Option<&PixelAspectRatio>
Get pixel aspect ratio for the primary item, if present.
Sourcepub fn content_light_level(&self) -> Option<&ContentLightLevel>
pub fn content_light_level(&self) -> Option<&ContentLightLevel>
Get content light level info for the primary item, if present.
Sourcepub fn mastering_display(&self) -> Option<&MasteringDisplayColourVolume>
pub fn mastering_display(&self) -> Option<&MasteringDisplayColourVolume>
Get mastering display colour volume for the primary item, if present.
Sourcepub fn content_colour_volume(&self) -> Option<&ContentColourVolume>
pub fn content_colour_volume(&self) -> Option<&ContentColourVolume>
Get content colour volume for the primary item, if present.
Sourcepub fn ambient_viewing(&self) -> Option<&AmbientViewingEnvironment>
pub fn ambient_viewing(&self) -> Option<&AmbientViewingEnvironment>
Get ambient viewing environment for the primary item, if present.
Sourcepub fn operating_point(&self) -> Option<&OperatingPointSelector>
pub fn operating_point(&self) -> Option<&OperatingPointSelector>
Get operating point selector for the primary item, if present.
Sourcepub fn layer_selector(&self) -> Option<&LayerSelector>
pub fn layer_selector(&self) -> Option<&LayerSelector>
Get layer selector for the primary item, if present.
Sourcepub fn layered_image_indexing(&self) -> Option<&AV1LayeredImageIndexing>
pub fn layered_image_indexing(&self) -> Option<&AV1LayeredImageIndexing>
Get AV1 layered image indexing for the primary item, if present.
Sourcepub fn exif(&self) -> Option<Result<Cow<'_, [u8]>>>
pub fn exif(&self) -> Option<Result<Cow<'_, [u8]>>>
Get EXIF metadata for the primary item, if present.
Returns raw EXIF data (TIFF header onwards), with the 4-byte AVIF offset prefix stripped.
Sourcepub fn xmp(&self) -> Option<Result<Cow<'_, [u8]>>>
pub fn xmp(&self) -> Option<Result<Cow<'_, [u8]>>>
Get XMP metadata for the primary item, if present.
Returns raw XMP/XML data.
Sourcepub fn major_brand(&self) -> &[u8; 4]
pub fn major_brand(&self) -> &[u8; 4]
Get the major brand from the ftyp box (e.g., *b"avif" or *b"avis").
Sourcepub fn compatible_brands(&self) -> &[[u8; 4]]
pub fn compatible_brands(&self) -> &[[u8; 4]]
Get the compatible brands from the ftyp box.
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.