use alloc::string::String;
use thiserror::Error;
use crate::decoder::DecodeError;
use crate::encoder::EncodeError;
pub type MuxResult<T> = core::result::Result<T, whereat::At<MuxError>>;
impl From<whereat::At<MuxError>> for MuxError {
fn from(at: whereat::At<MuxError>) -> Self {
at.decompose().0
}
}
impl From<whereat::At<EncodeError>> for MuxError {
fn from(at: whereat::At<EncodeError>) -> Self {
Self::EncodeError(at.decompose().0)
}
}
impl From<whereat::At<DecodeError>> for MuxError {
fn from(at: whereat::At<DecodeError>) -> Self {
Self::DecodeError(at.decompose().0)
}
}
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum MuxError {
#[error("Invalid WebP format: {0}")]
InvalidFormat(String),
#[error("Invalid dimensions: {width}x{height}")]
InvalidDimensions {
width: u32,
height: u32,
},
#[error("Frame {index} out of bounds (total: {total})")]
FrameOutOfBounds {
index: u32,
total: u32,
},
#[error("Encoding error: {0}")]
EncodeError(#[from] EncodeError),
#[error("Decoding error: {0}")]
DecodeError(#[from] DecodeError),
#[error("No frames to assemble")]
NoFrames,
#[error("Frame offset must be even: ({x}, {y})")]
OddFrameOffset {
x: u32,
y: u32,
},
#[error(
"Frame at ({x}, {y}) size {width}x{height} exceeds canvas {canvas_width}x{canvas_height}"
)]
FrameOutsideCanvas {
x: u32,
y: u32,
width: u32,
height: u32,
canvas_width: u32,
canvas_height: u32,
},
}