Struct webp_animation::Decoder[][src]

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

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

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();

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();

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

Formats the value using the given formatter. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.