Struct WebPDecoder

pub struct WebPDecoder<R> { /* private fields */ }

WebP image format decoder.

Implementations

impl<R: BufRead + Seek> WebPDecoder<R>

fn new(r: R) -> Result<Self, DecodingError>

Create a new WebPDecoder from the reader r. The decoder performs many small reads, so the reader should be buffered.

fn new_with_options(r: R, webp_decode_options: WebPDecodeOptions) -> Result<Self, DecodingError>

Create a new WebPDecoder from the reader r with the options WebPDecodeOptions. The decoder performs many small reads, so the reader should be buffered.

fn set_memory_limit(&mut self, limit: usize)

Sets the maximum amount of memory that the decoder is allowed to allocate at once.

TODO: Some allocations currently ignore this limit.

fn background_color_hint(&self) -> Option<[u8; 4]>

Get the background color specified in the image file if the image is extended and animated webp.

fn set_background_color(&mut self, color: [u8; 4]) -> Result<(), DecodingError>

Sets the background color if the image is an extended and animated webp.

fn dimensions(&self) -> (u32, u32)

Returns the (width, height) of the image in pixels.

fn has_alpha(&self) -> bool

Returns whether the image has an alpha channel. If so, the pixel format is Rgba8 and otherwise Rgb8.

fn is_animated(&self) -> bool

Returns true if the image is animated.

fn is_lossy(&mut self) -> bool

Returns whether the image is lossy. For animated images, this is true if any frame is lossy.

fn num_frames(&self) -> u32

Returns the number of frames of a single loop of the animation, or zero if the image is not animated.

fn loop_count(&self) -> LoopCount

Returns the number of times the animation should loop.

fn loop_duration(&self) -> u64

Returns the total duration of one loop through the animation in milliseconds, or zero if the image is not animated.

This is the sum of the durations of all individual frames of the image.

fn icc_profile(&mut self) -> Result<Option<Vec<u8>>, DecodingError>

Returns the raw bytes of the ICC profile, or None if there is no ICC profile.

fn exif_metadata(&mut self) -> Result<Option<Vec<u8>>, DecodingError>

Returns the raw bytes of the EXIF metadata, or None if there is no EXIF metadata.

fn xmp_metadata(&mut self) -> Result<Option<Vec<u8>>, DecodingError>

Returns the raw bytes of the XMP metadata, or None if there is no XMP metadata.

fn output_buffer_size(&self) -> Option<usize>

Returns the number of bytes required to store the image or a single frame, or None if that would take more than usize::MAX bytes.

fn read_image(&mut self, buf: &mut [u8]) -> Result<(), DecodingError>

Returns the raw bytes of the image. For animated images, this is the first frame.

Fails with ImageTooLarge if buf has length different than output_buffer_size()

fn read_frame(&mut self, buf: &mut [u8]) -> Result<u32, DecodingError>

Reads the next frame of the animation.

The frame contents are written into buf and the method returns the duration of the frame in milliseconds. If there are no more frames, the method returns DecodingError::NoMoreFrames and buf is left unchanged.

Panics

Panics if the image is not animated.

fn reset_animation(&mut self)

Resets the animation to the first frame.

Panics

Panics if the image is not animated.

fn set_lossy_upsampling(&mut self, upsampling_method: UpsamplingMethod)

Sets the upsampling method that is used in lossy decoding

Auto Trait Implementations

impl<R> Freeze for WebPDecoder<R> where R: Freeze,

impl<R> RefUnwindSafe for WebPDecoder<R> where R: RefUnwindSafe,

impl<R> Send for WebPDecoder<R> where R: Send,

impl<R> Sync for WebPDecoder<R> where R: Sync,

impl<R> Unpin for WebPDecoder<R> where R: Unpin,

impl<R> UnsafeUnpin for WebPDecoder<R> where R: UnsafeUnpin,

impl<R> UnwindSafe for WebPDecoder<R> where R: UnwindSafe,

Blanket Implementations

impl<T> Any for WebPDecoder<R> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for WebPDecoder<R> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for WebPDecoder<R> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> From<T> for WebPDecoder<R>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into<U> for WebPDecoder<R> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for WebPDecoder<R> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for WebPDecoder<R> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>