use thiserror::Error;
#[derive(Error, Debug)]
pub enum Jpeg2000Error {
#[error("Invalid JP2 signature: expected JP2 magic bytes")]
InvalidSignature,
#[error("Invalid or unsupported box type: {0}")]
InvalidBoxType(String),
#[error("Failed to parse box {box_type}: {reason}")]
BoxParseError {
box_type: String,
reason: String,
},
#[error("Invalid JPEG2000 codestream marker: 0x{0:04X}")]
InvalidMarker(u16),
#[error("Failed to parse codestream: {0}")]
CodestreamError(String),
#[error("Unsupported JPEG2000 feature: {0}")]
UnsupportedFeature(String),
#[error("Invalid image header: {0}")]
InvalidImageHeader(String),
#[error("Invalid tile parameters: {0}")]
InvalidTile(String),
#[error("Wavelet transform error: {0}")]
WaveletError(String),
#[error("Tier-1 (EBCOT) decoding error: {0}")]
Tier1Error(String),
#[error("Tier-2 (packet) decoding error: {0}")]
Tier2Error(String),
#[error("Color space conversion error: {0}")]
ColorError(String),
#[error("Invalid metadata: {0}")]
InvalidMetadata(String),
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
#[error("Insufficient data: expected {expected} bytes, got {actual}")]
InsufficientData {
expected: usize,
actual: usize,
},
#[error("Invalid dimension: {0}")]
InvalidDimension(String),
#[error("Failed to allocate memory: {0}")]
AllocationError(String),
#[error("{0}")]
Other(String),
}
pub type Result<T> = std::result::Result<T, Jpeg2000Error>;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ResilienceMode {
#[default]
None,
Basic,
Full,
}
impl ResilienceMode {
pub fn is_enabled(&self) -> bool {
!matches!(self, Self::None)
}
pub fn is_full(&self) -> bool {
matches!(self, Self::Full)
}
pub fn is_basic_or_higher(&self) -> bool {
matches!(self, Self::Basic | Self::Full)
}
}