Skip to main content

webp_rust/decoder/
mod.rs

1//! Lower-level WebP parsing and decoding APIs.
2
3pub mod alpha;
4pub mod animation;
5pub mod header;
6pub mod lossless;
7pub mod lossy;
8pub mod quant;
9pub mod tree;
10pub mod vp8;
11pub mod vp8i;
12
13use std::fmt::{Display, Formatter, Result as FmtResult};
14
15pub use alpha::{apply_alpha_plane, decode_alpha_plane, AlphaHeader};
16pub use animation::{decode_animation_webp, DecodedAnimation, DecodedAnimationFrame};
17pub use header::{
18    get_features, parse_animation_webp, parse_still_webp, AnimationHeader, ChunkHeader,
19    ParsedAnimationFrame, ParsedAnimationWebp, ParsedWebp, Vp8xHeader, WebpFeatures,
20};
21pub use lossless::{decode_lossless_vp8l_to_rgba, decode_lossless_webp_to_rgba};
22pub use lossy::{
23    decode_lossy_vp8_to_rgba, decode_lossy_vp8_to_yuv, decode_lossy_webp_to_rgba,
24    decode_lossy_webp_to_yuv, DecodedImage, DecodedYuvImage,
25};
26pub use vp8::{
27    parse_lossy_headers, parse_macroblock_data, parse_macroblock_headers, LosslessInfo,
28    LossyHeader, MacroBlockData, MacroBlockDataFrame, MacroBlockHeaders,
29};
30pub use vp8i::WebpFormat;
31
32/// Error type used by decoding and parsing entry points.
33#[derive(Debug, Clone, Copy, PartialEq, Eq)]
34pub enum DecoderError {
35    /// A caller-provided buffer size or dimension is invalid.
36    InvalidParam(&'static str),
37    /// The input ended before a required structure was fully available.
38    NotEnoughData(&'static str),
39    /// The bitstream violates the WebP container or codec format.
40    Bitstream(&'static str),
41    /// The input uses a feature that is intentionally not implemented.
42    Unsupported(&'static str),
43}
44
45impl Display for DecoderError {
46    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
47        match self {
48            Self::InvalidParam(msg) => write!(f, "invalid parameter: {msg}"),
49            Self::NotEnoughData(msg) => write!(f, "not enough data: {msg}"),
50            Self::Bitstream(msg) => write!(f, "bitstream error: {msg}"),
51            Self::Unsupported(msg) => write!(f, "unsupported feature: {msg}"),
52        }
53    }
54}
55
56impl std::error::Error for DecoderError {}