j2k_transcode/
htj2k97_codeblock_error.rs1use core::fmt;
6
7#[derive(Clone, Copy, Debug, Eq, PartialEq)]
9pub enum Htj2k97CodeBlockAxis {
10 Width,
12 Height,
14}
15
16impl fmt::Display for Htj2k97CodeBlockAxis {
17 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
18 match self {
19 Self::Width => formatter.write_str("width"),
20 Self::Height => formatter.write_str("height"),
21 }
22 }
23}
24
25#[derive(Clone, Copy, Debug, Eq, PartialEq)]
27#[non_exhaustive]
28pub enum Htj2k97CodeBlockOptionsError {
29 NumericOptionsOutOfRange,
31 QuantizationOptionsOutOfRange,
33 DimensionExponentUnsupported {
35 axis: Htj2k97CodeBlockAxis,
37 exponent_minus_two: u8,
39 },
40 DimensionsExceedLimits {
42 width: usize,
44 height: usize,
46 },
47}
48
49impl Htj2k97CodeBlockOptionsError {
50 #[must_use]
52 pub const fn reason(self) -> &'static str {
53 match self {
54 Self::NumericOptionsOutOfRange => {
55 "9/7 code-block options are outside supported numeric range"
56 }
57 Self::QuantizationOptionsOutOfRange => {
58 "9/7 code-block quantization options are outside supported range"
59 }
60 Self::DimensionExponentUnsupported { .. } => {
61 "9/7 code-block dimension exponent is unsupported"
62 }
63 Self::DimensionsExceedLimits { .. } => "9/7 code-block dimensions exceed HTJ2K limits",
64 }
65 }
66}
67
68impl fmt::Display for Htj2k97CodeBlockOptionsError {
69 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
70 match *self {
71 Self::NumericOptionsOutOfRange | Self::QuantizationOptionsOutOfRange => {
72 formatter.write_str(self.reason())
73 }
74 Self::DimensionExponentUnsupported {
75 axis,
76 exponent_minus_two,
77 } => write!(
78 formatter,
79 "{}: {axis} exponent-minus-two {exponent_minus_two}",
80 self.reason()
81 ),
82 Self::DimensionsExceedLimits { width, height } => {
83 write!(formatter, "{}: {width}x{height}", self.reason())
84 }
85 }
86 }
87}
88
89impl std::error::Error for Htj2k97CodeBlockOptionsError {}