pub struct WebPDecoder<R> {Show 13 fields
r: R,
memory_limit: usize,
width: u32,
height: u32,
kind: ImageKind,
animation: AnimationState,
is_lossy: bool,
has_alpha: bool,
num_frames: u32,
loop_count: LoopCount,
loop_duration: u64,
chunks: HashMap<WebPRiffChunk, Range<u64>>,
webp_decode_options: WebPDecodeOptions,
}
Expand description
WebP image format decoder.
Fields§
§r: R
§memory_limit: usize
§width: u32
§height: u32
§kind: ImageKind
§animation: AnimationState
§is_lossy: bool
§has_alpha: bool
§num_frames: u32
§loop_count: LoopCount
§loop_duration: u64
§chunks: HashMap<WebPRiffChunk, Range<u64>>
§webp_decode_options: WebPDecodeOptions
Implementations§
Source§impl<R: BufRead + Seek> WebPDecoder<R>
impl<R: BufRead + Seek> WebPDecoder<R>
Sourcepub fn new(r: R) -> Result<Self, DecodingError>
pub 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.
Sourcepub fn new_with_options(
r: R,
webp_decode_options: WebPDecodeOptions,
) -> Result<Self, DecodingError>
pub 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 read_data(&mut self) -> Result<(), DecodingError>
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 background_color_hint(&self) -> Option<[u8; 4]>
pub 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.
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.
fn read_chunk( &mut self, chunk: WebPRiffChunk, max_size: usize, ) -> Result<Option<Vec<u8>>, DecodingError>
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.
Fails with ImageTooLarge
if buf
has length different than output_buffer_size()
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.
Sourcepub fn reset_animation(&mut self)
pub fn reset_animation(&mut self)
Sourcepub fn set_lossy_upsampling(&mut self, upsampling_method: UpsamplingMethod)
pub fn set_lossy_upsampling(&mut self, upsampling_method: UpsamplingMethod)
Sets the upsampling method that is used in lossy decoding