use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum JpegError {
UnexpectedEof,
InvalidSoi,
MissingEoi,
UnsupportedMarker(u8),
InvalidMarkerData(&'static str),
HuffmanDecode,
InvalidQuantTableId(u8),
InvalidHuffmanTableId(u8),
UnknownComponentId(u8),
InvalidDimensions,
UnsupportedPrecision(u8),
}
impl fmt::Display for JpegError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::UnexpectedEof => write!(f, "unexpected end of JPEG data"),
Self::InvalidSoi => write!(f, "missing SOI marker (not a JPEG)"),
Self::MissingEoi => write!(f, "missing EOI marker"),
Self::UnsupportedMarker(m) => write!(f, "unsupported JPEG marker: 0xFF{m:02X}"),
Self::InvalidMarkerData(msg) => write!(f, "invalid marker data: {msg}"),
Self::HuffmanDecode => write!(f, "Huffman decode error"),
Self::InvalidQuantTableId(id) => write!(f, "invalid quantization table ID: {id}"),
Self::InvalidHuffmanTableId(id) => write!(f, "invalid Huffman table ID: {id}"),
Self::UnknownComponentId(id) => write!(f, "unknown component ID in SOS: {id}"),
Self::InvalidDimensions => write!(f, "invalid image dimensions or sampling factors"),
Self::UnsupportedPrecision(p) => write!(f, "unsupported sample precision: {p}-bit"),
}
}
}
impl std::error::Error for JpegError {}
pub type Result<T> = std::result::Result<T, JpegError>;