use crate::encode_image::MAX_DIMENSION;
use std::fmt;
#[derive(Debug, Clone, PartialEq)]
pub enum EncodeError {
EmptyImage,
InputSizeMismatch { expected: usize, actual: usize },
AlphaSizeMismatch { expected: usize, actual: usize },
InvalidDistance(f32),
QualityIsNaN,
DimensionTooLarge { width: usize, height: usize },
UnsupportedAlphaBitDepth(u8),
IccProfileNotSupported,
}
impl fmt::Display for EncodeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::EmptyImage => write!(f, "image dimensions must be non-zero"),
Self::InputSizeMismatch { expected, actual } => write!(
f,
"input buffer size mismatch: expected {expected} bytes, got {actual}"
),
Self::AlphaSizeMismatch { expected, actual } => write!(
f,
"alpha plane size mismatch: expected {expected} pixels, got {actual}"
),
Self::InvalidDistance(d) => write!(
f,
"butteraugli distance must be a positive finite number, got {d}"
),
Self::QualityIsNaN => write!(f, "quality value must not be NaN"),
Self::DimensionTooLarge { width, height } => write!(
f,
"image dimensions {width}×{height} exceed the maximum ({})",
MAX_DIMENSION
),
Self::UnsupportedAlphaBitDepth(bits) => {
write!(
f,
"unsupported alpha bit depth: {bits} (must be 8, 10, or 12)"
)
}
Self::IccProfileNotSupported => {
write!(f, "ICC profile injection is not yet supported by jixel")
}
}
}
}
impl std::error::Error for EncodeError {}