pub fn decode(data: &[u8], config: &Config) -> Result<Image, DecodeError>Expand description
Decodes a still WebP image into memory that libwebp allocates (C:
WebPDecode with an output buffer without memory). WebPDecodeRGBA and
the other simple functions of libwebp are this function with
Config::new(mode).
§Errors
The errors of Config::validate and Config::output_size first; then
libwebp’s status: DecodeError::BitstreamError for an invalid file or
one that ends before the image’s dimensions, DecodeError::NotEnoughData
or DecodeError::BitstreamError for one that ends later,
DecodeError::UnsupportedFeature for an animation (use
AnimationDecoder), DecodeError::OutOfMemory.
§Examples
use webp::api::decode::{decode, ColorMode, Config, DecodeError};
let image = decode(&file, &Config::new(ColorMode::Rgb))?;
assert_eq!(image.rows().unwrap().row(3), Some(&[10_u8, 20, 30].repeat(4)[..]));
// A prefix without the image's dimensions.
assert_eq!(decode(&file[..10], &Config::new(ColorMode::Rgb)), Err(DecodeError::BitstreamError));