oxigdal_jpeg2000/
error.rs1use thiserror::Error;
4
5#[derive(Error, Debug)]
7pub enum Jpeg2000Error {
8 #[error("Invalid JP2 signature: expected JP2 magic bytes")]
10 InvalidSignature,
11
12 #[error("Invalid or unsupported box type: {0}")]
14 InvalidBoxType(String),
15
16 #[error("Failed to parse box {box_type}: {reason}")]
18 BoxParseError {
19 box_type: String,
21 reason: String,
23 },
24
25 #[error("Invalid JPEG2000 codestream marker: 0x{0:04X}")]
27 InvalidMarker(u16),
28
29 #[error("Failed to parse codestream: {0}")]
31 CodestreamError(String),
32
33 #[error("Unsupported JPEG2000 feature: {0}")]
35 UnsupportedFeature(String),
36
37 #[error("Invalid image header: {0}")]
39 InvalidImageHeader(String),
40
41 #[error("Invalid tile parameters: {0}")]
43 InvalidTile(String),
44
45 #[error("Wavelet transform error: {0}")]
47 WaveletError(String),
48
49 #[error("Tier-1 (EBCOT) decoding error: {0}")]
51 Tier1Error(String),
52
53 #[error("Tier-2 (packet) decoding error: {0}")]
55 Tier2Error(String),
56
57 #[error("Color space conversion error: {0}")]
59 ColorError(String),
60
61 #[error("Invalid metadata: {0}")]
63 InvalidMetadata(String),
64
65 #[error("IO error: {0}")]
67 IoError(#[from] std::io::Error),
68
69 #[error("Insufficient data: expected {expected} bytes, got {actual}")]
71 InsufficientData {
72 expected: usize,
74 actual: usize,
76 },
77
78 #[error("Invalid dimension: {0}")]
80 InvalidDimension(String),
81
82 #[error("Failed to allocate memory: {0}")]
84 AllocationError(String),
85
86 #[error("{0}")]
88 Other(String),
89}
90
91pub type Result<T> = std::result::Result<T, Jpeg2000Error>;
93
94#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
98pub enum ResilienceMode {
99 #[default]
101 None,
102 Basic,
104 Full,
106}
107
108impl ResilienceMode {
109 pub fn is_enabled(&self) -> bool {
111 !matches!(self, Self::None)
112 }
113
114 pub fn is_full(&self) -> bool {
116 matches!(self, Self::Full)
117 }
118
119 pub fn is_basic_or_higher(&self) -> bool {
121 matches!(self, Self::Basic | Self::Full)
122 }
123}