Struct webp_animation::Decoder
source · [−]pub struct Decoder<'a> { /* private fields */ }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
sourceimpl<'a> Decoder<'a>
impl<'a> Decoder<'a>
sourcepub fn new(buffer: &'a [u8]) -> Result<Self, Error>
pub fn new(buffer: &'a [u8]) -> Result<Self, Error>
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();sourcepub fn new_with_options(
buffer: &'a [u8],
options: DecoderOptions
) -> Result<Self, Error>
pub fn new_with_options(
buffer: &'a [u8],
options: DecoderOptions
) -> Result<Self, Error>
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();Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more