use crate::resources::{font::FontError, image::ImageResourceError};
use thiserror::Error;
pub type Error = TakumiError;
#[derive(Error, Debug)]
pub enum WebPError {
#[error("failed to construct WebP config")]
ConfigConstruction,
#[error("invalid WebP config")]
InvalidConfig,
#[error("failed to initialize WebP picture")]
PictureInitialization,
#[error("WebP import error: {error_code}")]
Import {
error_code: String,
},
#[error("WebP encode error")]
Encode,
#[error("WebP encode error: {error_code}")]
EncodeWithCode {
error_code: String,
},
#[error("{name} must be in 1..={max}, got {value}")]
InvalidDimension {
name: &'static str,
value: u32,
max: u32,
},
#[error("WebP animation frame dimensions must be in 1..={max}, got {width}x{height}")]
InvalidFrameDimensions {
width: u32,
height: u32,
max: u32,
},
#[error("animation must contain at least one frame")]
EmptyAnimation,
#[error(
"frame {index} dimensions {frame_width}x{frame_height} exceed canvas {canvas_width}x{canvas_height}"
)]
FrameExceedsCanvas {
index: usize,
frame_width: u32,
frame_height: u32,
canvas_width: u32,
canvas_height: u32,
},
#[error("all animation frames must have the same dimensions")]
MixedFrameDimensions,
#[error("VP8/VP8L chunk not found")]
MissingVp8Chunk,
#[error("VP8/VP8L chunk not found in encoded frame")]
MissingVp8ChunkInEncodedFrame,
#[error("missing VP8/VP8L chunk tag")]
MissingVp8ChunkTag,
#[error("invalid VP8/VP8L chunk tag")]
InvalidVp8ChunkTag,
#[error("VP8/VP8L payload size overflows u32")]
Vp8PayloadSizeOverflow,
#[error("VP8/VP8L padding size overflows u32")]
Vp8PaddingSizeOverflow,
#[error("estimated VP8/VP8L payload size overflow")]
EstimatedVp8PayloadSizeOverflow,
#[error("estimated RIFF size overflow")]
EstimatedRiffSizeOverflow,
#[error("RIFF payload size overflow")]
RiffPayloadSizeOverflow,
#[error("RIFF payload size overflows u32")]
RiffPayloadSizeTooLarge,
#[error("ANMF chunk size overflow")]
AnmfChunkSizeOverflow,
#[error("ANMF payload size overflow")]
AnmfPayloadSizeOverflow,
#[error("ANMF payload size overflows u32")]
AnmfPayloadSizeTooLarge,
#[error("VP8 payload size overflows u32")]
Vp8PayloadSizeTooLarge,
}
#[derive(Error, Debug)]
pub enum TakumiError {
#[error("Image resolution error: {0}")]
ImageResolveError(#[from] ImageResourceError),
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
#[error("PNG encoding error: {0}")]
PngError(#[from] png::EncodingError),
#[error("WebP encoding error: {0}")]
WebPEncodingError(#[from] image_webp::EncodingError),
#[error("WebP error: {0}")]
WebPError(#[from] WebPError),
#[error("GIF encoding error: {0}")]
GifEncodingError(#[from] gif::EncodingError),
#[error("Image error: {0}")]
ImageError(#[from] image::ImageError),
#[error("Invalid viewport: width or height cannot be 0")]
InvalidViewport,
#[error("{format} animation must contain at least one frame")]
EmptyAnimationFrames {
format: &'static str,
},
#[error("all {format} animation frames must share the same dimensions")]
MixedAnimationFrameDimensions {
format: &'static str,
},
#[error("GIF frame dimensions must be <= {max}x{max}, got {width}x{height}")]
GifFrameDimensionsTooLarge {
width: u32,
height: u32,
max: u16,
},
#[error("Font error: {0}")]
FontError(#[from] FontError),
#[error("Layout error: {0}")]
LayoutError(taffy::TaffyError),
}
impl From<taffy::TaffyError> for TakumiError {
fn from(err: taffy::TaffyError) -> Self {
Self::LayoutError(err)
}
}
pub type Result<T> = std::result::Result<T, TakumiError>;