Skip to main content

AvifParser

Struct AvifParser 

Source
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

MethodLifetimeZero-copy?
from_bytes'dataYes — borrows the slice
from_owned'staticWithin the owned buffer
from_reader'staticReads 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-extent

Implementations§

Source§

impl<'data> AvifParser<'data>

Source

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.

Source

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.

Source

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).

Source

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.

Source

pub fn from_reader<R: Read>(reader: &mut R) -> Result<AvifParser<'static>>

Parse AVIF from a reader (reads all bytes, then parses).

Source

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.

Source

pub fn primary_data(&self) -> Result<Cow<'_, [u8]>>

Get primary item data.

Returns Cow::Borrowed for single-extent items, Cow::Owned for multi-extent.

Source

pub fn alpha_data(&self) -> Option<Result<Cow<'_, [u8]>>>

Get alpha item data, if present.

Source

pub fn tile_data(&self, index: usize) -> Result<Cow<'_, [u8]>>

Get grid tile data by index.

Source

pub fn frame(&self, index: usize) -> Result<FrameRef<'_>>

Get a single animation frame by index.

Source

pub fn frames(&self) -> FrameIterator<'_>

Iterate over all animation frames.

Source

pub fn animation_info(&self) -> Option<AnimationInfo>

Get animation metadata (if animated).

Source

pub fn grid_config(&self) -> Option<&GridConfig>

Get grid configuration (if grid image).

Source

pub fn grid_tile_count(&self) -> usize

Get number of grid tiles.

Source

pub fn premultiplied_alpha(&self) -> bool

Check if alpha channel uses premultiplied alpha.

Source

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.

Source

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.

Source

pub fn rotation(&self) -> Option<&ImageRotation>

Get rotation for the primary item, if present.

Source

pub fn mirror(&self) -> Option<&ImageMirror>

Get mirror for the primary item, if present.

Source

pub fn clean_aperture(&self) -> Option<&CleanAperture>

Get clean aperture (crop) for the primary item, if present.

Source

pub fn pixel_aspect_ratio(&self) -> Option<&PixelAspectRatio>

Get pixel aspect ratio for the primary item, if present.

Source

pub fn content_light_level(&self) -> Option<&ContentLightLevel>

Get content light level info for the primary item, if present.

Source

pub fn mastering_display(&self) -> Option<&MasteringDisplayColourVolume>

Get mastering display colour volume for the primary item, if present.

Source

pub fn content_colour_volume(&self) -> Option<&ContentColourVolume>

Get content colour volume for the primary item, if present.

Source

pub fn ambient_viewing(&self) -> Option<&AmbientViewingEnvironment>

Get ambient viewing environment for the primary item, if present.

Source

pub fn operating_point(&self) -> Option<&OperatingPointSelector>

Get operating point selector for the primary item, if present.

Source

pub fn layer_selector(&self) -> Option<&LayerSelector>

Get layer selector for the primary item, if present.

Source

pub fn layered_image_indexing(&self) -> Option<&AV1LayeredImageIndexing>

Get AV1 layered image indexing for the primary item, if present.

Source

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.

Source

pub fn xmp(&self) -> Option<Result<Cow<'_, [u8]>>>

Get XMP metadata for the primary item, if present.

Returns raw XMP/XML data.

Source

pub fn gain_map_metadata(&self) -> Option<&GainMapMetadata>

Gain map metadata, if a tmap derived image item is present.

Describes how to apply a gain map to reconstruct an HDR rendition from the SDR base image. See ISO 21496-1.

Source

pub fn gain_map_data(&self) -> Option<Result<Cow<'_, [u8]>>>

Gain map image data (AV1-encoded), if present.

Source

pub fn gain_map_color_info(&self) -> Option<&ColorInformation>

Color information for the alternate (typically HDR) rendition.

This comes from the tmap item’s colr property and describes the colour space of the tone-mapped output.

Source

pub fn major_brand(&self) -> &[u8; 4]

Get the major brand from the ftyp box (e.g., *b"avif" or *b"avis").

Source

pub fn compatible_brands(&self) -> &[[u8; 4]]

Get the compatible brands from the ftyp box.

Source

pub fn primary_metadata(&self) -> Result<AV1Metadata>

Parse AV1 metadata from the primary item.

Source

pub fn alpha_metadata(&self) -> Option<Result<AV1Metadata>>

Parse AV1 metadata from the alpha item, if present.

Source

pub fn to_avif_data(&self) -> Result<AvifData>

👎Deprecated since 1.5.0: Use AvifParser methods directly instead of converting to AvifData

Convert to AvifData (eagerly loads all frames and tiles).

Provided for migration from the eager API. Prefer using AvifParser methods directly.

Auto Trait Implementations§

§

impl<'data> Freeze for AvifParser<'data>

§

impl<'data> RefUnwindSafe for AvifParser<'data>

§

impl<'data> Send for AvifParser<'data>

§

impl<'data> Sync for AvifParser<'data>

§

impl<'data> Unpin for AvifParser<'data>

§

impl<'data> UnwindSafe for AvifParser<'data>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.