j2k_types/lib.rs
1//! Shared JPEG 2000 encode-stage contract types for j2k.
2//!
3//! This crate is the neutral public contract between the `j2k`
4//! adapter surface and the `j2k-native` codec engine: job, output,
5//! and report types cross the boundary here so neither crate mirrors the
6//! other's definitions. It intentionally contains plain data types only -
7//! codec behavior stays in `j2k-native` and adapter traits stay in
8//! their owning crates.
9
10#![no_std]
11#![forbid(unsafe_code)]
12#![forbid(missing_docs)]
13
14extern crate alloc;
15
16use alloc::vec::Vec;
17use core::ops::Range;
18
19/// Adapter classic J2K sub-band kind for backend experimentation.
20#[derive(Debug, Clone, Copy, PartialEq, Eq)]
21pub enum J2kSubBandType {
22 /// Low-low sub-band.
23 LowLow,
24 /// High-low sub-band.
25 HighLow,
26 /// Low-high sub-band.
27 LowHigh,
28 /// High-high sub-band.
29 HighHigh,
30}
31
32/// Adapter classic J2K code-block style for backend experimentation.
33#[derive(Debug, Clone, Copy)]
34#[allow(clippy::struct_excessive_bools)] // models the five independent COD code-block style flags
35pub struct J2kCodeBlockStyle {
36 /// Selective arithmetic coding bypass was enabled.
37 pub selective_arithmetic_coding_bypass: bool,
38 /// Context probabilities reset after each pass.
39 pub reset_context_probabilities: bool,
40 /// Coding terminated after each pass.
41 pub termination_on_each_pass: bool,
42 /// Vertically causal context was enabled.
43 pub vertically_causal_context: bool,
44 /// Segmentation symbols were enabled.
45 pub segmentation_symbols: bool,
46}
47
48/// Adapter classic J2K coded segment for backend experimentation.
49#[derive(Debug, Clone, Copy, PartialEq, Eq)]
50pub struct J2kCodeBlockSegment {
51 /// Byte offset of this segment within the combined payload.
52 pub data_offset: u32,
53 /// Segment payload length in bytes.
54 pub data_length: u32,
55 /// First coding pass covered by this segment.
56 pub start_coding_pass: u8,
57 /// One-past-last coding pass covered by this segment.
58 pub end_coding_pass: u8,
59 /// Whether this segment is decoded through the arithmetic path.
60 pub use_arithmetic: bool,
61}
62
63/// Adapter encoded classic J2K code-block payload for backend experimentation.
64#[derive(Debug, Clone)]
65pub struct EncodedJ2kCodeBlock {
66 /// Combined payload bytes for all coded segments in this code block.
67 pub data: Vec<u8>,
68 /// Coded segments for the code block.
69 pub segments: Vec<J2kCodeBlockSegment>,
70 /// Number of coding passes present for this code block.
71 pub number_of_coding_passes: u8,
72 /// Missing most-significant bit planes for this code block.
73 pub missing_bit_planes: u8,
74}
75
76/// Adapter encoded HTJ2K cleanup/refinement code-block payload for backend experimentation.
77#[derive(Debug, Clone)]
78pub struct EncodedHtJ2kCodeBlock {
79 /// Combined cleanup/refinement bytes for this code block.
80 pub data: Vec<u8>,
81 /// Cleanup segment length in bytes.
82 pub cleanup_length: u32,
83 /// Refinement segment length in bytes.
84 pub refinement_length: u32,
85 /// Number of coding passes present for this code block.
86 pub num_coding_passes: u8,
87 /// Number of zero most-significant bitplanes before first inclusion.
88 pub num_zero_bitplanes: u8,
89}
90
91/// Adapter pixel deinterleave/level-shift job for backend experimentation.
92#[derive(Debug, Clone, Copy)]
93pub struct J2kDeinterleaveToF32Job<'a> {
94 /// Interleaved source pixel bytes.
95 pub pixels: &'a [u8],
96 /// Number of pixels to convert.
97 pub num_pixels: usize,
98 /// Number of interleaved components per pixel.
99 pub num_components: u16,
100 /// Source sample bit depth.
101 pub bit_depth: u8,
102 /// Whether source samples are signed.
103 pub signed: bool,
104}
105
106/// Adapter forward RCT job for backend experimentation.
107#[derive(Debug)]
108pub struct J2kForwardRctJob<'a> {
109 /// First component plane, updated in place.
110 pub plane0: &'a mut [f32],
111 /// Second component plane, updated in place.
112 pub plane1: &'a mut [f32],
113 /// Third component plane, updated in place.
114 pub plane2: &'a mut [f32],
115}
116
117/// Adapter forward ICT job for backend experimentation.
118#[derive(Debug)]
119pub struct J2kForwardIctJob<'a> {
120 /// First component plane, updated in place.
121 pub plane0: &'a mut [f32],
122 /// Second component plane, updated in place.
123 pub plane1: &'a mut [f32],
124 /// Third component plane, updated in place.
125 pub plane2: &'a mut [f32],
126}
127
128/// Adapter forward 5/3 DWT job for backend experimentation.
129#[derive(Debug, Clone, Copy)]
130pub struct J2kForwardDwt53Job<'a> {
131 /// Source samples in row-major order.
132 pub samples: &'a [f32],
133 /// Source width in samples.
134 pub width: u32,
135 /// Source height in samples.
136 pub height: u32,
137 /// Number of decomposition levels requested.
138 pub num_levels: u8,
139}
140
141/// Adapter forward 5/3 DWT output for backend experimentation.
142#[derive(Debug, Clone)]
143pub struct J2kForwardDwt53Output {
144 /// LL subband coefficients from the lowest decomposition level.
145 pub ll: Vec<f32>,
146 /// LL subband width.
147 pub ll_width: u32,
148 /// LL subband height.
149 pub ll_height: u32,
150 /// Higher resolution detail levels, ordered from lowest to highest.
151 pub levels: Vec<J2kForwardDwt53Level>,
152}
153
154/// Adapter forward 5/3 DWT detail level for backend experimentation.
155#[derive(Debug, Clone)]
156pub struct J2kForwardDwt53Level {
157 /// HL subband coefficients.
158 pub hl: Vec<f32>,
159 /// LH subband coefficients.
160 pub lh: Vec<f32>,
161 /// HH subband coefficients.
162 pub hh: Vec<f32>,
163 /// Full-resolution width represented by this level.
164 pub width: u32,
165 /// Full-resolution height represented by this level.
166 pub height: u32,
167 /// Low-pass width at this level.
168 pub low_width: u32,
169 /// Low-pass height at this level.
170 pub low_height: u32,
171 /// High-pass width at this level.
172 pub high_width: u32,
173 /// High-pass height at this level.
174 pub high_height: u32,
175}
176
177/// Adapter forward irreversible 9/7 DWT job for backend experimentation.
178#[derive(Debug, Clone, Copy)]
179pub struct J2kForwardDwt97Job<'a> {
180 /// Source samples in row-major order.
181 pub samples: &'a [f32],
182 /// Source width in samples.
183 pub width: u32,
184 /// Source height in samples.
185 pub height: u32,
186 /// Number of decomposition levels requested.
187 pub num_levels: u8,
188}
189
190/// Adapter forward 9/7 DWT output for backend experimentation.
191#[derive(Debug, Clone)]
192pub struct J2kForwardDwt97Output {
193 /// LL subband coefficients from the lowest decomposition level.
194 pub ll: Vec<f32>,
195 /// LL subband width.
196 pub ll_width: u32,
197 /// LL subband height.
198 pub ll_height: u32,
199 /// Higher resolution detail levels, ordered from lowest to highest.
200 pub levels: Vec<J2kForwardDwt97Level>,
201}
202
203/// Adapter forward 9/7 DWT detail level for backend experimentation.
204#[derive(Debug, Clone)]
205pub struct J2kForwardDwt97Level {
206 /// HL subband coefficients.
207 pub hl: Vec<f32>,
208 /// LH subband coefficients.
209 pub lh: Vec<f32>,
210 /// HH subband coefficients.
211 pub hh: Vec<f32>,
212 /// Full-resolution width represented by this level.
213 pub width: u32,
214 /// Full-resolution height represented by this level.
215 pub height: u32,
216 /// Low-pass width at this level.
217 pub low_width: u32,
218 /// Low-pass height at this level.
219 pub low_height: u32,
220 /// High-pass width at this level.
221 pub high_width: u32,
222 /// High-pass height at this level.
223 pub high_height: u32,
224}
225
226/// Adapter sub-band quantization job for backend experimentation.
227#[derive(Debug, Clone, Copy)]
228pub struct J2kQuantizeSubbandJob<'a> {
229 /// Source sub-band coefficients in row-major order.
230 pub coefficients: &'a [f32],
231 /// Quantization step-size exponent.
232 pub step_exponent: u16,
233 /// Quantization step-size mantissa.
234 pub step_mantissa: u16,
235 /// Nominal range bits for this sub-band.
236 pub range_bits: u8,
237 /// Whether to use reversible integer quantization.
238 pub reversible: bool,
239}
240
241/// Adapter Tier-1 classic J2K code-block encode job for backend experimentation.
242#[derive(Debug, Clone, Copy)]
243pub struct J2kTier1CodeBlockEncodeJob<'a> {
244 /// Quantized coefficients in row-major order.
245 pub coefficients: &'a [i32],
246 /// Code-block width in samples.
247 pub width: u32,
248 /// Code-block height in samples.
249 pub height: u32,
250 /// Subband kind containing this code-block.
251 pub sub_band_type: J2kSubBandType,
252 /// Total bitplanes for this subband/code-block.
253 pub total_bitplanes: u8,
254 /// Classic J2K code-block style flags.
255 pub style: J2kCodeBlockStyle,
256}
257
258/// Adapter HTJ2K code-block encode job for backend experimentation.
259#[derive(Debug, Clone, Copy)]
260pub struct J2kHtCodeBlockEncodeJob<'a> {
261 /// Quantized coefficients in row-major order.
262 pub coefficients: &'a [i32],
263 /// Code-block width in samples.
264 pub width: u32,
265 /// Code-block height in samples.
266 pub height: u32,
267 /// Total bitplanes for this subband/code-block.
268 pub total_bitplanes: u8,
269 /// Requested HT coding passes for this contribution.
270 ///
271 /// `1` is cleanup-only. `2` requests cleanup plus significance-propagation
272 /// refinement on the native CPU path. `3` additionally requests one
273 /// magnitude-refinement pass. Higher values require an accelerator and
274 /// must not be silently reduced by CPU fallback.
275 pub target_coding_passes: u8,
276}
277
278/// Adapter HTJ2K cleanup/refinement encode job for one unquantized sub-band.
279#[derive(Debug, Clone, Copy)]
280pub struct J2kHtSubbandEncodeJob<'a> {
281 /// Source sub-band coefficients in row-major order.
282 pub coefficients: &'a [f32],
283 /// Sub-band width in samples.
284 pub width: u32,
285 /// Sub-band height in samples.
286 pub height: u32,
287 /// Quantization step-size exponent.
288 pub step_exponent: u16,
289 /// Quantization step-size mantissa.
290 pub step_mantissa: u16,
291 /// Nominal range bits for this sub-band.
292 pub range_bits: u8,
293 /// Whether to use reversible integer quantization.
294 pub reversible: bool,
295 /// Code-block width in samples.
296 pub code_block_width: u32,
297 /// Code-block height in samples.
298 pub code_block_height: u32,
299 /// Total coded bitplanes for this sub-band.
300 pub total_bitplanes: u8,
301}
302
303/// Adapter HTJ2K tile-body encode job for backend-resident full-tile paths.
304#[derive(Debug, Clone, Copy)]
305pub struct J2kHtj2kTileEncodeJob<'a> {
306 /// Interleaved source pixel bytes.
307 pub pixels: &'a [u8],
308 /// Tile/image width in samples.
309 pub width: u32,
310 /// Tile/image height in samples.
311 pub height: u32,
312 /// Number of interleaved image components.
313 pub num_components: u16,
314 /// Source component bit depth.
315 pub bit_depth: u8,
316 /// Whether source samples are signed.
317 pub signed: bool,
318 /// Number of DWT decomposition levels.
319 pub num_decomposition_levels: u8,
320 /// Whether the codestream uses reversible coding.
321 pub reversible: bool,
322 /// Whether a multi-component transform should be applied.
323 pub use_mct: bool,
324 /// JPEG 2000 guard bits used to derive total coded bitplanes.
325 pub guard_bits: u8,
326 /// Code-block width in samples.
327 pub code_block_width: u32,
328 /// Code-block height in samples.
329 pub code_block_height: u32,
330 /// Packet progression order to emit.
331 pub progression_order: J2kPacketizationProgressionOrder,
332 /// Per-component sampling factors, as `(x_rsiz, y_rsiz)`.
333 pub component_sampling: &'a [(u8, u8)],
334 /// Quantization step sizes, as `(exponent, mantissa)`, in codestream order.
335 pub quantization_steps: &'a [(u16, u16)],
336}
337
338/// Adapter LRCP packetization code-block contribution for backend experimentation.
339#[derive(Debug, Clone, Copy, PartialEq, Eq)]
340pub struct J2kPacketizationCodeBlock<'a> {
341 /// Encoded Tier-1 bitstream bytes for this packet contribution.
342 pub data: &'a [u8],
343 /// HTJ2K cleanup segment length in bytes when using high-throughput coding.
344 pub ht_cleanup_length: u32,
345 /// HTJ2K refinement segment length in bytes when using high-throughput coding.
346 pub ht_refinement_length: u32,
347 /// Number of coding passes in this contribution.
348 pub num_coding_passes: u8,
349 /// Number of zero most-significant bitplanes before first inclusion.
350 pub num_zero_bitplanes: u8,
351 /// Whether this code-block was included in a previous packet.
352 pub previously_included: bool,
353 /// L-block value used for segment length coding.
354 pub l_block: u32,
355 /// Block coder used for this contribution.
356 pub block_coding_mode: J2kPacketizationBlockCodingMode,
357}
358
359/// Adapter packetization block coding mode for backend experimentation.
360#[derive(Debug, Clone, Copy, PartialEq, Eq)]
361pub enum J2kPacketizationBlockCodingMode {
362 /// Classic JPEG 2000 Part 1 EBCOT block coding.
363 Classic,
364 /// High-throughput JPEG 2000 Part 15 block coding.
365 HighThroughput,
366}
367
368/// Adapter packet progression order for backend packetization experimentation.
369#[derive(Debug, Clone, Copy, PartialEq, Eq)]
370pub enum J2kPacketizationProgressionOrder {
371 /// Layer-resolution-component-position progression.
372 Lrcp,
373 /// Resolution-layer-component-position progression.
374 Rlcp,
375 /// Resolution-position-component-layer progression.
376 Rpcl,
377 /// Position-component-resolution-layer progression.
378 Pcrl,
379 /// Component-position-resolution-layer progression.
380 Cprl,
381}
382
383/// Adapter LRCP packetization subband precinct for backend experimentation.
384#[derive(Debug, Clone, PartialEq, Eq)]
385pub struct J2kPacketizationSubband<'a> {
386 /// Code-block contributions in row-major order.
387 pub code_blocks: Vec<J2kPacketizationCodeBlock<'a>>,
388 /// Number of code-blocks in the x direction.
389 pub num_cbs_x: u32,
390 /// Number of code-blocks in the y direction.
391 pub num_cbs_y: u32,
392}
393
394/// Adapter LRCP packetization resolution packet for backend experimentation.
395#[derive(Debug, Clone, PartialEq, Eq)]
396pub struct J2kPacketizationResolution<'a> {
397 /// Subbands in packet order: LL for resolution 0, then HL/LH/HH.
398 pub subbands: Vec<J2kPacketizationSubband<'a>>,
399}
400
401/// Adapter explicit packet descriptor for backend packetization experimentation.
402#[derive(Debug, Clone, Copy, PartialEq, Eq)]
403pub struct J2kPacketizationPacketDescriptor {
404 /// Index into the packet contribution array.
405 pub packet_index: u32,
406 /// Persistent packet-state index for repeated layer/precinct packets.
407 pub state_index: u32,
408 /// Quality layer for inclusion tag-tree thresholds.
409 pub layer: u8,
410 /// Resolution index in the output progression.
411 pub resolution: u32,
412 /// Component index in the output progression.
413 pub component: u16,
414 /// Precinct index in the output progression.
415 pub precinct: u64,
416}
417
418/// Adapter LRCP packetization job for backend experimentation.
419#[derive(Debug, Clone, Copy, PartialEq, Eq)]
420pub struct J2kPacketizationEncodeJob<'a> {
421 /// Number of resolution packets prepared for packetization.
422 pub resolution_count: u32,
423 /// Number of layers to write.
424 pub num_layers: u8,
425 /// Number of image components.
426 pub num_components: u16,
427 /// Total number of code-block contributions.
428 pub code_block_count: u32,
429 /// Packet progression order to emit.
430 pub progression_order: J2kPacketizationProgressionOrder,
431 /// Explicit packet descriptors in output progression order.
432 pub packet_descriptors: &'a [J2kPacketizationPacketDescriptor],
433 /// Packet payload prepared by Tier-1, in LRCP packet order.
434 pub resolutions: &'a [J2kPacketizationResolution<'a>],
435}
436
437/// Adapter encode-stage dispatch counters for backend experimentation.
438#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
439pub struct J2kEncodeDispatchReport {
440 /// Pixel deinterleave/level-shift dispatch count.
441 pub deinterleave: usize,
442 /// Forward RCT kernel dispatch count.
443 pub forward_rct: usize,
444 /// Forward ICT kernel dispatch count.
445 pub forward_ict: usize,
446 /// Forward reversible 5/3 DWT kernel dispatch count.
447 pub forward_dwt53: usize,
448 /// Forward irreversible 9/7 DWT kernel dispatch count.
449 pub forward_dwt97: usize,
450 /// Sub-band quantization dispatch count.
451 pub quantize_subband: usize,
452 /// Tier-1 code-block encode dispatch count.
453 pub tier1_code_block: usize,
454 /// HTJ2K code-block encode dispatch count.
455 pub ht_code_block: usize,
456 /// Packetization dispatch count.
457 pub packetization: usize,
458}
459
460impl J2kEncodeDispatchReport {
461 /// Return the saturating per-stage delta from `before` to `self`.
462 #[must_use]
463 pub fn saturating_delta(self, before: Self) -> Self {
464 Self {
465 deinterleave: self.deinterleave.saturating_sub(before.deinterleave),
466 forward_rct: self.forward_rct.saturating_sub(before.forward_rct),
467 forward_ict: self.forward_ict.saturating_sub(before.forward_ict),
468 forward_dwt53: self.forward_dwt53.saturating_sub(before.forward_dwt53),
469 forward_dwt97: self.forward_dwt97.saturating_sub(before.forward_dwt97),
470 quantize_subband: self
471 .quantize_subband
472 .saturating_sub(before.quantize_subband),
473 tier1_code_block: self
474 .tier1_code_block
475 .saturating_sub(before.tier1_code_block),
476 ht_code_block: self.ht_code_block.saturating_sub(before.ht_code_block),
477 packetization: self.packetization.saturating_sub(before.packetization),
478 }
479 }
480
481 /// Return total dispatches across all encode stages.
482 #[must_use]
483 pub fn total(self) -> usize {
484 self.forward_rct
485 .saturating_add(self.deinterleave)
486 .saturating_add(self.forward_ict)
487 .saturating_add(self.forward_dwt53)
488 .saturating_add(self.forward_dwt97)
489 .saturating_add(self.quantize_subband)
490 .saturating_add(self.tier1_code_block)
491 .saturating_add(self.ht_code_block)
492 .saturating_add(self.packetization)
493 }
494
495 /// Return whether at least one encode stage dispatched.
496 #[must_use]
497 pub fn any(self) -> bool {
498 self.total() > 0
499 }
500}
501
502/// Adapter CPU-only encode accelerator that always falls back to native stages.
503#[derive(Debug, Default, Clone, Copy)]
504pub struct CpuOnlyJ2kEncodeStageAccelerator;
505
506/// Multipliers applied to irreversible 9/7 quantization step sizes by subband.
507#[derive(Debug, Clone, Copy, PartialEq)]
508pub struct IrreversibleQuantizationSubbandScales {
509 /// Multiplier for the LL subband.
510 pub low_low: f32,
511 /// Multiplier for HL subbands.
512 pub high_low: f32,
513 /// Multiplier for LH subbands.
514 pub low_high: f32,
515 /// Multiplier for HH subbands.
516 pub high_high: f32,
517}
518
519/// Public JPEG 2000 irreversible quantization step-size tuple.
520#[derive(Debug, Clone, Copy, PartialEq, Eq)]
521pub struct IrreversibleQuantizationStep {
522 /// Quantization step-size exponent.
523 pub exponent: u8,
524 /// Quantization step-size mantissa.
525 pub mantissa: u16,
526}
527
528impl Default for IrreversibleQuantizationSubbandScales {
529 fn default() -> Self {
530 Self {
531 low_low: 1.0,
532 high_low: 1.0,
533 low_high: 1.0,
534 high_high: 1.0,
535 }
536 }
537}
538
539/// Precomputed reversible 5/3 wavelet coefficients for one component.
540#[derive(Debug, Clone)]
541pub struct PrecomputedHtj2k53Component {
542 /// Horizontal SIZ sampling factor (`XRsiz`).
543 pub x_rsiz: u8,
544 /// Vertical SIZ sampling factor (`YRsiz`).
545 pub y_rsiz: u8,
546 /// Forward 5/3 DWT output, ordered as the encoder expects.
547 pub dwt: J2kForwardDwt53Output,
548}
549
550/// Precomputed reversible 5/3 wavelet image.
551#[derive(Debug, Clone)]
552pub struct PrecomputedHtj2k53Image {
553 /// Reference-grid image width.
554 pub width: u32,
555 /// Reference-grid image height.
556 pub height: u32,
557 /// Component precision in bits.
558 pub bit_depth: u8,
559 /// Whether component samples are signed.
560 pub signed: bool,
561 /// Components at their native resolution.
562 pub components: Vec<PrecomputedHtj2k53Component>,
563}
564
565/// Precomputed irreversible 9/7 wavelet coefficients for one component.
566#[derive(Debug, Clone)]
567pub struct PrecomputedHtj2k97Component {
568 /// Horizontal SIZ sampling factor (`XRsiz`).
569 pub x_rsiz: u8,
570 /// Vertical SIZ sampling factor (`YRsiz`).
571 pub y_rsiz: u8,
572 /// Forward 9/7 DWT output, ordered as the encoder expects.
573 pub dwt: J2kForwardDwt97Output,
574}
575
576/// Precomputed irreversible 9/7 wavelet image.
577#[derive(Debug, Clone)]
578pub struct PrecomputedHtj2k97Image {
579 /// Reference-grid image width.
580 pub width: u32,
581 /// Reference-grid image height.
582 pub height: u32,
583 /// Component precision in bits.
584 pub bit_depth: u8,
585 /// Whether component samples are signed.
586 pub signed: bool,
587 /// Components at their native resolution.
588 pub components: Vec<PrecomputedHtj2k97Component>,
589}
590
591/// Prequantized irreversible 9/7 HTJ2K code-block image.
592#[derive(Debug, Clone)]
593pub struct PrequantizedHtj2k97Image {
594 /// Reference-grid image width.
595 pub width: u32,
596 /// Reference-grid image height.
597 pub height: u32,
598 /// Component precision in bits.
599 pub bit_depth: u8,
600 /// Whether component samples are signed.
601 pub signed: bool,
602 /// Components at their native resolution.
603 pub components: Vec<PrequantizedHtj2k97Component>,
604}
605
606/// Prequantized irreversible 9/7 HTJ2K component.
607#[derive(Debug, Clone)]
608pub struct PrequantizedHtj2k97Component {
609 /// Horizontal SIZ sampling factor (`XRsiz`).
610 pub x_rsiz: u8,
611 /// Vertical SIZ sampling factor (`YRsiz`).
612 pub y_rsiz: u8,
613 /// Resolution packets for this component, ordered from lowest to highest.
614 pub resolutions: Vec<PrequantizedHtj2k97Resolution>,
615}
616
617/// One component resolution's prequantized HTJ2K subbands.
618#[derive(Debug, Clone)]
619pub struct PrequantizedHtj2k97Resolution {
620 /// Subbands in packet order: LL for resolution 0, then HL/LH/HH.
621 pub subbands: Vec<PrequantizedHtj2k97Subband>,
622}
623
624/// One prequantized HTJ2K subband split into code-blocks.
625#[derive(Debug, Clone)]
626pub struct PrequantizedHtj2k97Subband {
627 /// Subband kind.
628 pub sub_band_type: J2kSubBandType,
629 /// Number of code-blocks in the x direction.
630 pub num_cbs_x: u32,
631 /// Number of code-blocks in the y direction.
632 pub num_cbs_y: u32,
633 /// Total bitplanes declared for every code-block in this subband.
634 pub total_bitplanes: u8,
635 /// Code-block coefficients in row-major code-block order.
636 pub code_blocks: Vec<PrequantizedHtj2k97CodeBlock>,
637}
638
639/// One prequantized HTJ2K code-block.
640#[derive(Debug, Clone)]
641pub struct PrequantizedHtj2k97CodeBlock {
642 /// Quantized coefficients in row-major order.
643 pub coefficients: Vec<i32>,
644 /// Code-block width in coefficients.
645 pub width: u32,
646 /// Code-block height in coefficients.
647 pub height: u32,
648}
649
650/// Preencoded irreversible 9/7 HTJ2K code-block image.
651#[derive(Debug, Clone)]
652pub struct PreencodedHtj2k97Image {
653 /// Reference-grid image width.
654 pub width: u32,
655 /// Reference-grid image height.
656 pub height: u32,
657 /// Component precision in bits.
658 pub bit_depth: u8,
659 /// Whether component samples are signed.
660 pub signed: bool,
661 /// Components at their native resolution.
662 pub components: Vec<PreencodedHtj2k97Component>,
663}
664
665/// Preencoded irreversible 9/7 HTJ2K component.
666#[derive(Debug, Clone)]
667pub struct PreencodedHtj2k97Component {
668 /// Horizontal SIZ sampling factor (`XRsiz`).
669 pub x_rsiz: u8,
670 /// Vertical SIZ sampling factor (`YRsiz`).
671 pub y_rsiz: u8,
672 /// Resolution packets for this component, ordered from lowest to highest.
673 pub resolutions: Vec<PreencodedHtj2k97Resolution>,
674}
675
676/// One component resolution's preencoded HTJ2K subbands.
677#[derive(Debug, Clone)]
678pub struct PreencodedHtj2k97Resolution {
679 /// Subbands in packet order: LL for resolution 0, then HL/LH/HH.
680 pub subbands: Vec<PreencodedHtj2k97Subband>,
681}
682
683/// One preencoded HTJ2K subband split into code-blocks.
684#[derive(Debug, Clone)]
685pub struct PreencodedHtj2k97Subband {
686 /// Subband kind.
687 pub sub_band_type: J2kSubBandType,
688 /// Number of code-blocks in the x direction.
689 pub num_cbs_x: u32,
690 /// Number of code-blocks in the y direction.
691 pub num_cbs_y: u32,
692 /// Total bitplanes declared for every code-block in this subband.
693 pub total_bitplanes: u8,
694 /// Encoded code-block payloads in row-major code-block order.
695 pub code_blocks: Vec<PreencodedHtj2k97CodeBlock>,
696}
697
698/// One preencoded HTJ2K code-block.
699#[derive(Debug, Clone)]
700pub struct PreencodedHtj2k97CodeBlock {
701 /// Code-block width in coefficients.
702 pub width: u32,
703 /// Code-block height in coefficients.
704 pub height: u32,
705 /// Encoded cleanup/refinement payload and packet metadata.
706 pub encoded: EncodedHtJ2kCodeBlock,
707}
708
709/// Preencoded irreversible 9/7 HTJ2K code-block image backed by one compact
710/// payload buffer.
711#[derive(Debug, Clone)]
712pub struct PreencodedHtj2k97CompactImage {
713 /// Reference-grid image width.
714 pub width: u32,
715 /// Reference-grid image height.
716 pub height: u32,
717 /// Component precision in bits.
718 pub bit_depth: u8,
719 /// Whether component samples are signed.
720 pub signed: bool,
721 /// Contiguous encoded code-block payload bytes.
722 pub payload: Vec<u8>,
723 /// Components at their native resolution.
724 pub components: Vec<PreencodedHtj2k97CompactComponent>,
725}
726
727/// Preencoded compact irreversible 9/7 HTJ2K component.
728#[derive(Debug, Clone)]
729pub struct PreencodedHtj2k97CompactComponent {
730 /// Horizontal SIZ sampling factor (`XRsiz`).
731 pub x_rsiz: u8,
732 /// Vertical SIZ sampling factor (`YRsiz`).
733 pub y_rsiz: u8,
734 /// Resolution packets for this component, ordered from lowest to highest.
735 pub resolutions: Vec<PreencodedHtj2k97CompactResolution>,
736}
737
738/// One component resolution's compact preencoded HTJ2K subbands.
739#[derive(Debug, Clone)]
740pub struct PreencodedHtj2k97CompactResolution {
741 /// Subbands in packet order: LL for resolution 0, then HL/LH/HH.
742 pub subbands: Vec<PreencodedHtj2k97CompactSubband>,
743}
744
745/// One compact preencoded HTJ2K subband split into code-blocks.
746#[derive(Debug, Clone)]
747pub struct PreencodedHtj2k97CompactSubband {
748 /// Subband kind.
749 pub sub_band_type: J2kSubBandType,
750 /// Number of code-blocks in the x direction.
751 pub num_cbs_x: u32,
752 /// Number of code-blocks in the y direction.
753 pub num_cbs_y: u32,
754 /// Total bitplanes declared for every code-block in this subband.
755 pub total_bitplanes: u8,
756 /// Code-block metadata in row-major code-block order.
757 pub code_blocks: Vec<PreencodedHtj2k97CompactCodeBlock>,
758}
759
760/// One compact preencoded HTJ2K code-block.
761#[derive(Debug, Clone)]
762pub struct PreencodedHtj2k97CompactCodeBlock {
763 /// Code-block width in coefficients.
764 pub width: u32,
765 /// Code-block height in coefficients.
766 pub height: u32,
767 /// Byte range into the image-level compact payload.
768 pub payload_range: Range<usize>,
769 /// HTJ2K cleanup segment length in bytes.
770 pub cleanup_length: u32,
771 /// HTJ2K refinement segment length in bytes.
772 pub refinement_length: u32,
773 /// Number of coding passes in the encoded payload.
774 pub num_coding_passes: u8,
775 /// Number of missing most-significant bitplanes.
776 pub num_zero_bitplanes: u8,
777}