Skip to main content

j2k_types/prepared_plan/
mod.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! Owned, move-only prepared HTJ2K encode values.
4
5use alloc::vec::Vec;
6use core::ops::Range;
7
8use crate::{EncodedHtJ2kCodeBlock, J2kForwardDwt53Output, J2kForwardDwt97Output, J2kSubBandType};
9
10/// Precomputed reversible 5/3 wavelet coefficients for one component.
11#[derive(Debug)]
12pub struct PrecomputedHtj2k53Component {
13    /// Horizontal SIZ sampling factor (`XRsiz`).
14    pub x_rsiz: u8,
15    /// Vertical SIZ sampling factor (`YRsiz`).
16    pub y_rsiz: u8,
17    /// Forward 5/3 DWT output, ordered as the encoder expects.
18    pub dwt: J2kForwardDwt53Output,
19}
20
21/// Precomputed reversible 5/3 wavelet image.
22#[derive(Debug)]
23pub struct PrecomputedHtj2k53Image {
24    /// Reference-grid image width.
25    pub width: u32,
26    /// Reference-grid image height.
27    pub height: u32,
28    /// Component precision in bits.
29    pub bit_depth: u8,
30    /// Whether component samples are signed.
31    pub signed: bool,
32    /// Components at their native resolution.
33    pub components: Vec<PrecomputedHtj2k53Component>,
34}
35
36/// Precomputed irreversible 9/7 wavelet coefficients for one component.
37#[derive(Debug)]
38pub struct PrecomputedHtj2k97Component {
39    /// Horizontal SIZ sampling factor (`XRsiz`).
40    pub x_rsiz: u8,
41    /// Vertical SIZ sampling factor (`YRsiz`).
42    pub y_rsiz: u8,
43    /// Forward 9/7 DWT output, ordered as the encoder expects.
44    pub dwt: J2kForwardDwt97Output,
45}
46
47/// Precomputed irreversible 9/7 wavelet image.
48#[derive(Debug)]
49pub struct PrecomputedHtj2k97Image {
50    /// Reference-grid image width.
51    pub width: u32,
52    /// Reference-grid image height.
53    pub height: u32,
54    /// Component precision in bits.
55    pub bit_depth: u8,
56    /// Whether component samples are signed.
57    pub signed: bool,
58    /// Components at their native resolution.
59    pub components: Vec<PrecomputedHtj2k97Component>,
60}
61
62/// Prequantized irreversible 9/7 HTJ2K code-block image.
63#[derive(Debug)]
64pub struct PrequantizedHtj2k97Image {
65    /// Reference-grid image width.
66    pub width: u32,
67    /// Reference-grid image height.
68    pub height: u32,
69    /// Component precision in bits.
70    pub bit_depth: u8,
71    /// Whether component samples are signed.
72    pub signed: bool,
73    /// Components at their native resolution.
74    pub components: Vec<PrequantizedHtj2k97Component>,
75}
76
77/// Prequantized irreversible 9/7 HTJ2K component.
78#[derive(Debug)]
79pub struct PrequantizedHtj2k97Component {
80    /// Horizontal SIZ sampling factor (`XRsiz`).
81    pub x_rsiz: u8,
82    /// Vertical SIZ sampling factor (`YRsiz`).
83    pub y_rsiz: u8,
84    /// Resolution packets for this component, ordered from lowest to highest.
85    pub resolutions: Vec<PrequantizedHtj2k97Resolution>,
86}
87
88/// One component resolution's prequantized HTJ2K subbands.
89#[derive(Debug)]
90pub struct PrequantizedHtj2k97Resolution {
91    /// Subbands in packet order: LL for resolution 0, then HL/LH/HH.
92    pub subbands: Vec<PrequantizedHtj2k97Subband>,
93}
94
95/// One prequantized HTJ2K subband split into code blocks.
96#[derive(Debug)]
97pub struct PrequantizedHtj2k97Subband {
98    /// Subband kind.
99    pub sub_band_type: J2kSubBandType,
100    /// Number of code blocks in the x direction.
101    pub num_cbs_x: u32,
102    /// Number of code blocks in the y direction.
103    pub num_cbs_y: u32,
104    /// Total bitplanes declared for every code block in this subband.
105    pub total_bitplanes: u8,
106    /// Code-block coefficients in row-major code-block order.
107    pub code_blocks: Vec<PrequantizedHtj2k97CodeBlock>,
108}
109
110/// One prequantized HTJ2K code block.
111#[derive(Debug)]
112pub struct PrequantizedHtj2k97CodeBlock {
113    /// Quantized coefficients in row-major order.
114    pub coefficients: Vec<i32>,
115    /// Code-block width in coefficients.
116    pub width: u32,
117    /// Code-block height in coefficients.
118    pub height: u32,
119}
120
121/// Preencoded irreversible 9/7 HTJ2K code-block image.
122#[derive(Debug)]
123pub struct PreencodedHtj2k97Image {
124    /// Reference-grid image width.
125    pub width: u32,
126    /// Reference-grid image height.
127    pub height: u32,
128    /// Component precision in bits.
129    pub bit_depth: u8,
130    /// Whether component samples are signed.
131    pub signed: bool,
132    /// Components at their native resolution.
133    pub components: Vec<PreencodedHtj2k97Component>,
134}
135
136/// Preencoded irreversible 9/7 HTJ2K component.
137#[derive(Debug)]
138pub struct PreencodedHtj2k97Component {
139    /// Horizontal SIZ sampling factor (`XRsiz`).
140    pub x_rsiz: u8,
141    /// Vertical SIZ sampling factor (`YRsiz`).
142    pub y_rsiz: u8,
143    /// Resolution packets for this component, ordered from lowest to highest.
144    pub resolutions: Vec<PreencodedHtj2k97Resolution>,
145}
146
147/// One component resolution's preencoded HTJ2K subbands.
148#[derive(Debug)]
149pub struct PreencodedHtj2k97Resolution {
150    /// Subbands in packet order: LL for resolution 0, then HL/LH/HH.
151    pub subbands: Vec<PreencodedHtj2k97Subband>,
152}
153
154/// One preencoded HTJ2K subband split into code blocks.
155#[derive(Debug)]
156pub struct PreencodedHtj2k97Subband {
157    /// Subband kind.
158    pub sub_band_type: J2kSubBandType,
159    /// Number of code blocks in the x direction.
160    pub num_cbs_x: u32,
161    /// Number of code blocks in the y direction.
162    pub num_cbs_y: u32,
163    /// Total bitplanes declared for every code block in this subband.
164    pub total_bitplanes: u8,
165    /// Encoded code-block payloads in row-major code-block order.
166    pub code_blocks: Vec<PreencodedHtj2k97CodeBlock>,
167}
168
169/// One preencoded HTJ2K code block.
170#[derive(Debug)]
171pub struct PreencodedHtj2k97CodeBlock {
172    /// Code-block width in coefficients.
173    pub width: u32,
174    /// Code-block height in coefficients.
175    pub height: u32,
176    /// Encoded cleanup/refinement payload and packet metadata.
177    pub encoded: EncodedHtJ2kCodeBlock,
178}
179
180/// Preencoded irreversible 9/7 HTJ2K image backed by one compact payload buffer.
181#[derive(Debug)]
182pub struct PreencodedHtj2k97CompactImage {
183    /// Reference-grid image width.
184    pub width: u32,
185    /// Reference-grid image height.
186    pub height: u32,
187    /// Component precision in bits.
188    pub bit_depth: u8,
189    /// Whether component samples are signed.
190    pub signed: bool,
191    /// Contiguous encoded code-block payload bytes.
192    pub payload: Vec<u8>,
193    /// Components at their native resolution.
194    pub components: Vec<PreencodedHtj2k97CompactComponent>,
195}
196
197/// Preencoded compact irreversible 9/7 HTJ2K component.
198#[derive(Debug)]
199pub struct PreencodedHtj2k97CompactComponent {
200    /// Horizontal SIZ sampling factor (`XRsiz`).
201    pub x_rsiz: u8,
202    /// Vertical SIZ sampling factor (`YRsiz`).
203    pub y_rsiz: u8,
204    /// Resolution packets for this component, ordered from lowest to highest.
205    pub resolutions: Vec<PreencodedHtj2k97CompactResolution>,
206}
207
208/// One component resolution's compact preencoded HTJ2K subbands.
209#[derive(Debug)]
210pub struct PreencodedHtj2k97CompactResolution {
211    /// Subbands in packet order: LL for resolution 0, then HL/LH/HH.
212    pub subbands: Vec<PreencodedHtj2k97CompactSubband>,
213}
214
215/// One compact preencoded HTJ2K subband split into code blocks.
216#[derive(Debug)]
217pub struct PreencodedHtj2k97CompactSubband {
218    /// Subband kind.
219    pub sub_band_type: J2kSubBandType,
220    /// Number of code blocks in the x direction.
221    pub num_cbs_x: u32,
222    /// Number of code blocks in the y direction.
223    pub num_cbs_y: u32,
224    /// Total bitplanes declared for every code block in this subband.
225    pub total_bitplanes: u8,
226    /// Code-block metadata in row-major code-block order.
227    pub code_blocks: Vec<PreencodedHtj2k97CompactCodeBlock>,
228}
229
230/// One compact preencoded HTJ2K code block.
231#[derive(Debug)]
232pub struct PreencodedHtj2k97CompactCodeBlock {
233    /// Code-block width in coefficients.
234    pub width: u32,
235    /// Code-block height in coefficients.
236    pub height: u32,
237    /// Byte range into the image-level compact payload.
238    pub payload_range: Range<usize>,
239    /// HTJ2K cleanup segment length in bytes.
240    pub cleanup_length: u32,
241    /// HTJ2K refinement segment length in bytes.
242    pub refinement_length: u32,
243    /// Number of coding passes in the encoded payload.
244    pub num_coding_passes: u8,
245    /// Number of missing most-significant bitplanes.
246    pub num_zero_bitplanes: u8,
247}
248
249crate::move_only::assert_move_only!(
250    PrecomputedHtj2k53Component,
251    PrecomputedHtj2k53Image,
252    PrecomputedHtj2k97Component,
253    PrecomputedHtj2k97Image,
254    PrequantizedHtj2k97Image,
255    PrequantizedHtj2k97Component,
256    PrequantizedHtj2k97Resolution,
257    PrequantizedHtj2k97Subband,
258    PrequantizedHtj2k97CodeBlock,
259    PreencodedHtj2k97Image,
260    PreencodedHtj2k97Component,
261    PreencodedHtj2k97Resolution,
262    PreencodedHtj2k97Subband,
263    PreencodedHtj2k97CodeBlock,
264    PreencodedHtj2k97CompactImage,
265    PreencodedHtj2k97CompactComponent,
266    PreencodedHtj2k97CompactResolution,
267    PreencodedHtj2k97CompactSubband,
268    PreencodedHtj2k97CompactCodeBlock,
269);