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