use crate::MAX_DIM;
use std::fmt;
#[derive(Debug)]
pub enum EncodeError {
InvalidDimensions { width: u32, height: u32 },
InvalidInput,
DctError(String),
BitstreamError(String),
IsobmffError(String),
Io(std::io::Error),
DimensionTooLarge { width: usize, height: usize },
}
impl fmt::Display for EncodeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
EncodeError::InvalidDimensions { width, height } => {
write!(f, "Invalid image dimensions: {width}x{height}")
}
EncodeError::InvalidInput => write!(
f,
"Invalid input: plane sizes or parameters are inconsistent"
),
EncodeError::DctError(msg) => write!(f, "DCT block error: {msg}"),
EncodeError::BitstreamError(msg) => write!(f, "Bitstream write error: {msg}"),
EncodeError::IsobmffError(msg) => write!(f, "ISOBMFF error: {msg}"),
EncodeError::Io(e) => write!(f, "IO error: {e}"),
Self::DimensionTooLarge { width, height } => write!(
f,
"image dimensions {width}×{height} exceed the maximum ({})",
MAX_DIM
),
}
}
}
impl std::error::Error for EncodeError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
EncodeError::Io(e) => Some(e),
_ => None,
}
}
}
impl From<std::io::Error> for EncodeError {
fn from(e: std::io::Error) -> Self {
EncodeError::Io(e)
}
}