pub struct WebPDecoder<R> { /* private fields */ }
Expand description
WebP image format decoder.
Implementations§
source§impl<R: BufRead + Seek> WebPDecoder<R>
impl<R: BufRead + Seek> WebPDecoder<R>
sourcepub fn new(r: R) -> Result<WebPDecoder<R>, DecodingError>
pub fn new(r: R) -> Result<WebPDecoder<R>, DecodingError>
Create a new WebPDecoder from the reader r
. The decoder performs many small reads, so the
reader should be buffered.
sourcepub fn set_memory_limit(&mut self, limit: usize)
pub 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.
sourcepub fn set_background_color(
&mut self,
color: [u8; 4],
) -> Result<(), DecodingError>
pub fn set_background_color( &mut self, color: [u8; 4], ) -> Result<(), DecodingError>
Sets the background color if the image is an extended and animated webp.
sourcepub fn dimensions(&self) -> (u32, u32)
pub fn dimensions(&self) -> (u32, u32)
Returns the (width, height) of the image in pixels.
sourcepub fn has_alpha(&self) -> bool
pub fn has_alpha(&self) -> bool
Returns whether the image has an alpha channel. If so, the pixel format is Rgba8 and otherwise Rgb8.
sourcepub fn is_animated(&self) -> bool
pub fn is_animated(&self) -> bool
Returns true if the image is animated.
sourcepub fn is_lossy(&mut self) -> bool
pub fn is_lossy(&mut self) -> bool
Returns whether the image is lossy. For animated images, this is true if any frame is lossy.
sourcepub fn num_frames(&self) -> u32
pub 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.
sourcepub fn loop_count(&self) -> LoopCount
pub fn loop_count(&self) -> LoopCount
Returns the number of times the animation should loop.
sourcepub fn loop_duration(&self) -> u64
pub 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.
sourcepub fn icc_profile(&mut self) -> Result<Option<Vec<u8>>, DecodingError>
pub 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.
sourcepub fn exif_metadata(&mut self) -> Result<Option<Vec<u8>>, DecodingError>
pub 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.
sourcepub fn xmp_metadata(&mut self) -> Result<Option<Vec<u8>>, DecodingError>
pub 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.
sourcepub fn output_buffer_size(&self) -> Option<usize>
pub 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.
sourcepub fn read_image(&mut self, buf: &mut [u8]) -> Result<(), DecodingError>
pub 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.
sourcepub fn read_frame(&mut self, buf: &mut [u8]) -> Result<u32, DecodingError>
pub 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.