#[non_exhaustive]pub enum DecodeError {
Show 14 variants
OutOfMemory,
InvalidParam,
BitstreamError,
UnsupportedFeature,
Suspended,
UserAbort,
NotEnoughData,
FrameFailed,
InvalidCrop {
left: u32,
top: u32,
width: u32,
height: u32,
},
InvalidScale {
width: u32,
height: u32,
},
InvalidStride {
plane: Plane,
stride: usize,
},
BufferTooShort {
plane: Plane,
len: usize,
needed: usize,
},
OutputMismatch {
mode: ColorMode,
},
InvalidParameter {
name: &'static str,
},
}Expand description
Why a decoding or one of its inputs failed.
The variants up to DecodeError::NotEnoughData are libwebp’s
VP8StatusCode values 1 to 7; DecodeError::code returns the C code.
DecodeError::FrameFailed is a failed animation frame, for which libwebp
reports no status. The others are the API’s own validation, which runs
before the translation is called.
§Examples
use webp::api::decode::{ColorMode, Config, DecodeError};
let error = Config::new(ColorMode::Rgb).crop(1, 0, 8, 8).validate().unwrap_err();
assert_eq!(error, DecodeError::InvalidCrop { left: 1, top: 0, width: 8, height: 8 });
assert_eq!(error.code(), None);
assert_eq!(DecodeError::BitstreamError.to_string(), "invalid bitstream");Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
OutOfMemory
Memory could not be allocated (C: VP8_STATUS_OUT_OF_MEMORY).
InvalidParam
libwebp refused a parameter (C: VP8_STATUS_INVALID_PARAM): for the
incremental decoder, a caller output that does not fit the image, or
a crop outside it, which it learns from the header; mixed calls of
IncrementalDecoder::append and IncrementalDecoder::update, or a
shorter buffer passed to update.
BitstreamError
The bitstream is invalid or truncated (C: VP8_STATUS_BITSTREAM_ERROR).
UnsupportedFeature
The bitstream uses a feature that this decoder does not support, such
as an animation given to decode (C: VP8_STATUS_UNSUPPORTED_FEATURE).
Suspended
The incremental decoding has not completed: the error of
IncrementalDecoder::into_image before that (C:
VP8_STATUS_SUSPENDED, which the decoding steps report as
Status::NeedsMoreData).
UserAbort
The decoding was aborted by an I/O hook (C: VP8_STATUS_USER_ABORT);
the API sets no hooks, so it does not return this code.
NotEnoughData
The data ends before the information asked for (C:
VP8_STATUS_NOT_ENOUGH_DATA): read more and try again.
FrameFailed
The animation decoder failed on a frame; libwebp’s
WebPAnimDecoderGetNext reports no status.
InvalidCrop
The crop has a zero size, an odd left or top, a value above
i32::MAX, or does not lie inside the image.
Fields
InvalidScale
A scaled width or height is 0 or above 16383.
InvalidStride
A stride is 0, shorter than a row of the output, longer than
i32::MAX, or so long that the plane’s extent does not fit in usize.
BufferTooShort
A buffer is shorter than its rows: (rows - 1) * stride + row length
bytes, or empty.
Fields
OutputMismatch
The output does not match the color mode: Output::Rows for a YUV
mode, Output::Planes for an RGB mode, an alpha plane missing for
ColorMode::Yuva or given for ColorMode::Yuv, or caller memory
asked to become an Image.
InvalidParameter
A parameter is outside the range the API accepts: dithering or
alpha_dithering above 100.
Implementations§
Source§impl DecodeError
impl DecodeError
Sourcepub const fn code(&self) -> Option<VP8StatusCode>
pub const fn code(&self) -> Option<VP8StatusCode>
The VP8StatusCode of this error, or None for DecodeError::FrameFailed
and the API’s own validation errors.
§Examples
use webp::api::decode::DecodeError;
use webp::webp::decode::VP8StatusCode;
assert_eq!(DecodeError::NotEnoughData.code(), Some(VP8StatusCode::VP8_STATUS_NOT_ENOUGH_DATA));
assert_eq!(DecodeError::FrameFailed.code(), None);Trait Implementations§
Source§impl Clone for DecodeError
impl Clone for DecodeError
impl Copy for DecodeError
Source§impl Debug for DecodeError
impl Debug for DecodeError
Source§impl Display for DecodeError
impl Display for DecodeError
impl Eq for DecodeError
Source§impl Error for DecodeError
impl Error for DecodeError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()