1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
//! Pure-Rust JPEG 2000 codec, built GRIB2-decode-first toward OpenJPEG-level
//! coverage. No C dependency, so it cross-compiles cleanly to every target.
//!
//! The decoder reads a **raw codestream** (ISO/IEC 15444-1 Annex A, not yet
//! the JP2 file format) into **integer** samples: one grid per component,
//! signed up to 32 bits, unsigned up to 31 (an `i32` container), each with its
//! own bit depth, sign, and sub-sampling. Both wavelet paths decode — the
//! reversible 5/3 bit-exactly, the irreversible 9/7 within the standard's
//! compliance bounds — as do tiling and tile-parts, precincts, quality layers,
//! all five progression orders and POC changes between them, packed packet
//! headers (PPM/PPT), every Part 1 code-block coding style, region of interest
//! (maxshift), non-zero canvas offsets, resolution-reduced decoding, and the
//! reversible (RCT) and irreversible (ICT) colour transforms.
//!
//! JP2 boxes, HTJ2K, and an encoder are later work, not permanent non-goals.
//! See `docs/roadmap.md` and `docs/scope.md`.
//!
//! # Pipeline
//!
//! ```text
//! bytes ─▶ codestream ─▶ tier-2 ─▶ tier-1 ─▶ dequant ─▶ inverse DWT ─▶ Image
//! (markers) (packets) (MQ+EBCOT) (quant) (5/3 | 9/7)
//! ```
//!
//! Each stage is a module below. [`decode`] wires them together.
//!
//! # Example
//!
//! The entire public surface is [`decode`]: codestream bytes in, an [`Image`]
//! out. An [`Image`] is the image area on the reference grid plus one
//! [`Component`] per codestream component; a sub-sampled component holds fewer
//! samples than that area, so size sample buffers from the component, not from
//! the image. Malformed input never panics; it comes back as a typed [`Error`].
//!
//! ```
//! use rust_j2k::{decode, Error};
//!
//! // In real use these are the bytes of a `.j2k` codestream, or the GRIB2 §7
//! // data section of a `grid_jpeg` message. Invalid input is rejected cleanly:
//! match decode(b"not a codestream") {
//! Ok(image) => {
//! let first = image.component(0).expect("at least one component");
//! println!(
//! "image area {}x{}, first component {}x{}",
//! image.width, image.height, first.width, first.height,
//! );
//! }
//! Err(Error::Unsupported(what)) => println!("outside the decoded subset: {what}"),
//! Err(e) => println!("decode failed: {e}"),
//! }
//! ```
//!
//! # Status
//!
//! All 23 entries of the ISO/IEC 15444-4 conformance suite decode within their
//! class-1 error bounds, and that gate runs in `tests/` against committed
//! oracle snapshots, with no external tools. Correctness is defined by
//! cross-checking a reference decoder (OpenJPEG / eccodes), not by
//! self-consistency. A codestream using a feature outside the decoded set — a
//! JP2 wrapper, HTJ2K, a Part 2 extension — is rejected with
//! [`Error::Unsupported`], never half-decoded. GRIB2 §5.40 (`grid_jpeg`)
//! payloads, the crate's original target, are raw codestreams and decode
//! directly. See each module's docs for the ISO §reference and what it owns;
//! the feature map is in `docs/scope.md`.
// The pipeline modules are crate-internal: the public API is `decode`, `Image`,
// `Error`, and `Result`. Keeping the stages private lets each one evolve freely
// (the roadmap widens all of them) without churning the crate's committed
// surface, and keeps the docs.rs page to what a caller can actually use.
pub
pub
pub
pub
pub
pub
pub
pub
// Structured fuzz entry points for the detached fuzz/ workspace. Compiled
// unconditionally so that workspace builds under plain cargo (rust-analyzer,
// `cargo check` in fuzz/), but hidden from docs and exempt from semver: this
// is a test seam, not public API.
pub use ;
pub use ;
/// Decode a JPEG 2000 **codestream** (Annex A, no JP2 wrapper) into an
/// [`Image`]: the reference-grid image area plus one [`Component`] per SIZ
/// component, each on its own sample grid.
///
/// This is the whole public surface for the GRIB2 use case: the §7 data
/// section of a `grid_jpeg` message is exactly such a codestream. That subset is
/// single-component, so its images carry one component; a codestream declaring
/// more decodes each component onto its own grid, independently.
///
/// Pass the bare codestream, not a `.jp2` file: a JP2 wrapper is valid JPEG 2000
/// but is rejected with [`Error::Unsupported`] rather than unwrapped. Anything
/// else outside the decoded subset is rejected the same way, never half-decoded.
/// Options for [`decode_with`]. The default decodes at full resolution —
/// [`decode`] is exactly that.
///
/// Start from [`DecodeOptions::default`] and set what differs, with the
/// `with_*` methods or the fields directly. The struct is `#[non_exhaustive]`,
/// so a new option is not a breaking change.
/// Decode a JPEG 2000 codestream like [`decode`], governed by `options`.