use core::fmt;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Htj2k97CodeBlockAxis {
Width,
Height,
}
impl fmt::Display for Htj2k97CodeBlockAxis {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Width => formatter.write_str("width"),
Self::Height => formatter.write_str("height"),
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum Htj2k97CodeBlockOptionsError {
NumericOptionsOutOfRange,
QuantizationOptionsOutOfRange,
DimensionExponentUnsupported {
axis: Htj2k97CodeBlockAxis,
exponent_minus_two: u8,
},
DimensionsExceedLimits {
width: usize,
height: usize,
},
}
impl Htj2k97CodeBlockOptionsError {
#[must_use]
pub const fn reason(self) -> &'static str {
match self {
Self::NumericOptionsOutOfRange => {
"9/7 code-block options are outside supported numeric range"
}
Self::QuantizationOptionsOutOfRange => {
"9/7 code-block quantization options are outside supported range"
}
Self::DimensionExponentUnsupported { .. } => {
"9/7 code-block dimension exponent is unsupported"
}
Self::DimensionsExceedLimits { .. } => "9/7 code-block dimensions exceed HTJ2K limits",
}
}
}
impl fmt::Display for Htj2k97CodeBlockOptionsError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Self::NumericOptionsOutOfRange | Self::QuantizationOptionsOutOfRange => {
formatter.write_str(self.reason())
}
Self::DimensionExponentUnsupported {
axis,
exponent_minus_two,
} => write!(
formatter,
"{}: {axis} exponent-minus-two {exponent_minus_two}",
self.reason()
),
Self::DimensionsExceedLimits { width, height } => {
write!(formatter, "{}: {width}x{height}", self.reason())
}
}
}
}
impl std::error::Error for Htj2k97CodeBlockOptionsError {}