Skip to main content

AnimationEncoder

Struct AnimationEncoder 

Source
pub struct AnimationEncoder { /* private fields */ }
Expand description

Sequential animated-WebP encoder for full-canvas RGBA frames.

Self::add_frame accepts frames in presentation order. It converts each frame’s duration to the cumulative millisecond timestamp required by WebP, then Self::finish writes the final timestamp needed to retain the last frame’s duration.

Implementations§

Source§

impl AnimationEncoder

Source

pub fn new( canvas: CanvasSize, options: AnimationEncoderOptions, ) -> Result<Self, EncodeError>

Creates an encoder for full-canvas RGBA frames of the given dimensions.

Frames must be added in presentation order and must use exactly canvas.width * canvas.height * 4 bytes. At least one frame is required before Self::finish can produce output.

Source

pub const fn canvas(&self) -> CanvasSize

Returns the canvas dimensions required by every frame.

Source

pub const fn frame_count(&self) -> u32

Returns the number of frames accepted so far.

Source

pub fn add_frame(&mut self, frame: &AnimationFrame) -> Result<(), EncodeError>

Adds one full-canvas frame in presentation order.

Source

pub fn add_rgba( &mut self, rgba: &[u8], duration: Duration, ) -> Result<(), EncodeError>

Adds one full-canvas RGBA frame without allocating an AnimationFrame.

Source

pub fn finish(self) -> Result<Vec<u8>, EncodeError>

Flushes the final frame duration and returns the encoded WebP bytes.

Trait Implementations§

Source§

impl Drop for AnimationEncoder

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

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.