Struct webp_animation::Decoder[][src]

pub struct Decoder<'a> { /* fields omitted */ }

A decoder for webp animation data

Will take a webp buffer, and try to decode it to frame(s)

use webp_animation::prelude::*;

let buffer = std::fs::read("./data/animated.webp").unwrap();
let decoder = Decoder::new(&buffer).unwrap();

for frame in decoder.into_iter() {
  assert_eq!(frame.dimensions(), (400, 400));
  assert_eq!(frame.data().len(), 400 * 400 * 4); // w * h * rgba
}

See also documentation for the item produced by iterator: Frame

If image feature is enabled, frames can be produced in [image::ImageBuffer] format:

use webp_animation::prelude::*;
for frame in decoder.into_iter() {
  #[cfg(feature = "image")]
  assert_eq!(frame.into_image().unwrap().dimensions(), (400, 400));
}

Implementations

impl<'a> Decoder<'a>[src]

pub fn new(buffer: &'a [u8]) -> Result<Self, Error>[src]

Construct a new decoder from webp buffer

Returns an Error in case of a decoding failure (e.g. malformed input)

let buffer = std::fs::read("./data/animated.webp").unwrap();
let decoder = Decoder::new(&buffer).unwrap();

pub fn new_with_options(
    buffer: &'a [u8],
    options: DecoderOptions
) -> Result<Self, Error>
[src]

Construct a new decoder from webp buffer

Returns an Error in case of a decoding failure (e.g. malformed input)

let buf = std::fs::read("./data/animated.webp").unwrap();
let decoder = Decoder::new_with_options(&buf, DecoderOptions {
  use_threads: false,
  color_mode: ColorMode::Bgra
}).unwrap();

pub fn dimensions(&self) -> (u32, u32)[src]

Returns dimensions for webp frames (width, height)

let buffer = std::fs::read("./data/animated.webp").unwrap();
let decoder = Decoder::new(&buffer).unwrap();
assert_eq!(decoder.dimensions(), (400, 400));

Trait Implementations

impl<'a> Debug for Decoder<'a>[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<'a> IntoIterator for Decoder<'a>[src]

type Item = Frame

The type of the elements being iterated over.

type IntoIter = DecoderIterator<'a>

Which kind of iterator are we turning this into?

fn into_iter(self) -> Self::IntoIter[src]

Creates an iterator from a value. Read more

Auto Trait Implementations

impl<'a> RefUnwindSafe for Decoder<'a>

impl<'a> !Send for Decoder<'a>

impl<'a> !Sync for Decoder<'a>

impl<'a> Unpin for Decoder<'a>

impl<'a> UnwindSafe for Decoder<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.