j2k_native/direct_plan.rs
1use alloc::vec::Vec;
2
3use crate::{J2kRect, J2kWaveletTransform};
4
5/// Adapter identifier for one device-owned grayscale coefficient band.
6pub type J2kDirectBandId = u32;
7
8/// Adapter grayscale-only direct device-plan step for backend experimentation.
9#[derive(Debug, Clone)]
10pub enum J2kDirectGrayscaleStep {
11 /// Decode one classic J2K sub-band into a device-owned coefficient buffer.
12 ClassicSubBand(J2kOwnedSubBandPlan),
13 /// Decode one HTJ2K sub-band into a device-owned coefficient buffer.
14 HtSubBand(HtOwnedSubBandPlan),
15 /// Apply one single-decomposition IDWT level on device-owned buffers.
16 Idwt(J2kDirectIdwtStep),
17 /// Store the final component plane into an output plane buffer.
18 Store(J2kDirectStoreStep),
19}
20
21/// Adapter grayscale-only direct device plan for backend experimentation.
22#[derive(Debug, Clone)]
23pub struct J2kDirectGrayscalePlan {
24 /// Final output dimensions.
25 pub dimensions: (u32, u32),
26 /// Final output bit depth.
27 pub bit_depth: u8,
28 /// Ordered execution steps for the direct device pipeline.
29 pub steps: Vec<J2kDirectGrayscaleStep>,
30}
31
32/// Adapter RGB direct device plan for backend experimentation.
33#[derive(Debug, Clone)]
34pub struct J2kDirectColorPlan {
35 /// Final output dimensions.
36 pub dimensions: (u32, u32),
37 /// Final output bit depths for the first three color components.
38 pub bit_depths: [u8; 3],
39 /// Whether inverse MCT must be applied after component stores.
40 pub mct: bool,
41 /// Wavelet transform used by the codestream's color transform.
42 pub transform: J2kWaveletTransform,
43 /// Per-component direct plans. RGB plans currently contain exactly three components.
44 pub component_plans: Vec<J2kDirectGrayscalePlan>,
45}
46
47/// Adapter owned classic J2K sub-band decode job.
48#[derive(Debug, Clone)]
49pub struct J2kOwnedSubBandPlan {
50 /// Stable identifier for the decoded coefficient band produced by this step.
51 pub band_id: J2kDirectBandId,
52 /// Absolute sub-band rect in component coordinates.
53 pub rect: J2kRect,
54 /// Sub-band width in samples.
55 pub width: u32,
56 /// Sub-band height in samples.
57 pub height: u32,
58 /// Owned code-block jobs for this sub-band.
59 pub jobs: Vec<J2kOwnedCodeBlockBatchJob>,
60}
61
62/// Adapter owned HTJ2K sub-band decode job.
63#[derive(Debug, Clone)]
64pub struct HtOwnedSubBandPlan {
65 /// Stable identifier for the decoded coefficient band produced by this step.
66 pub band_id: J2kDirectBandId,
67 /// Absolute sub-band rect in component coordinates.
68 pub rect: J2kRect,
69 /// Sub-band width in samples.
70 pub width: u32,
71 /// Sub-band height in samples.
72 pub height: u32,
73 /// Owned code-block jobs for this sub-band.
74 pub jobs: Vec<HtOwnedCodeBlockBatchJob>,
75}
76
77/// Adapter owned classic J2K batched code-block decode job.
78#[derive(Debug, Clone)]
79pub struct J2kOwnedCodeBlockBatchJob {
80 /// X offset within the target sub-band coefficient buffer.
81 pub output_x: u32,
82 /// Y offset within the target sub-band coefficient buffer.
83 pub output_y: u32,
84 /// Combined payload bytes for all coded segments in this code block.
85 pub data: Vec<u8>,
86 /// Coded segments for the code block.
87 pub segments: Vec<crate::J2kCodeBlockSegment>,
88 /// Code-block width in samples.
89 pub width: u32,
90 /// Code-block height in samples.
91 pub height: u32,
92 /// Output row stride, in samples, for the target sub-band storage.
93 pub output_stride: usize,
94 /// Missing most-significant bit planes for this code block.
95 pub missing_bit_planes: u8,
96 /// Number of coding passes present for this code block.
97 pub number_of_coding_passes: u8,
98 /// Total coded bitplanes for the parent sub-band.
99 pub total_bitplanes: u8,
100 /// Region-of-interest maxshift value from RGN marker metadata.
101 pub roi_shift: u8,
102 /// The sub-band type containing this code block.
103 pub sub_band_type: crate::J2kSubBandType,
104 /// The code-block style flags.
105 pub style: crate::J2kCodeBlockStyle,
106 /// Whether strict decode validation is enabled for the parent image.
107 pub strict: bool,
108 /// Dequantization step to apply to decoded coefficients.
109 pub dequantization_step: f32,
110}
111
112/// Adapter owned HTJ2K batched code-block decode job.
113#[derive(Debug, Clone)]
114pub struct HtOwnedCodeBlockBatchJob {
115 /// X offset within the target sub-band coefficient buffer.
116 pub output_x: u32,
117 /// Y offset within the target sub-band coefficient buffer.
118 pub output_y: u32,
119 /// Combined cleanup/refinement bytes for the code block.
120 pub data: Vec<u8>,
121 /// Cleanup segment length in bytes.
122 pub cleanup_length: u32,
123 /// Refinement segment length in bytes.
124 pub refinement_length: u32,
125 /// Code-block width in samples.
126 pub width: u32,
127 /// Code-block height in samples.
128 pub height: u32,
129 /// Output row stride, in samples, for the target sub-band storage.
130 pub output_stride: usize,
131 /// Missing most-significant bit planes for this code block.
132 pub missing_bit_planes: u8,
133 /// Number of coding passes present for this code block.
134 pub number_of_coding_passes: u8,
135 /// Total coded bitplanes for the parent sub-band.
136 pub num_bitplanes: u8,
137 /// Region-of-interest maxshift value from RGN marker metadata.
138 pub roi_shift: u8,
139 /// Whether vertically causal context was enabled.
140 pub stripe_causal: bool,
141 /// Whether strict decode validation is enabled for the parent image.
142 pub strict: bool,
143 /// Dequantization step to apply to decoded coefficients.
144 pub dequantization_step: f32,
145}
146
147/// Adapter single grayscale IDWT step for a direct device plan.
148#[derive(Debug, Clone, Copy)]
149pub struct J2kDirectIdwtStep {
150 /// Stable identifier of the output coefficient band produced by this step.
151 pub output_band_id: J2kDirectBandId,
152 /// Output rect of this decomposition level.
153 pub rect: J2kRect,
154 /// Transform to apply.
155 pub transform: J2kWaveletTransform,
156 /// Stable identifier of the LL input band.
157 pub ll_band_id: J2kDirectBandId,
158 /// LL band rect.
159 pub ll: J2kRect,
160 /// Stable identifier of the HL input band.
161 pub hl_band_id: J2kDirectBandId,
162 /// HL band rect.
163 pub hl: J2kRect,
164 /// Stable identifier of the LH input band.
165 pub lh_band_id: J2kDirectBandId,
166 /// LH band rect.
167 pub lh: J2kRect,
168 /// Stable identifier of the HH input band.
169 pub hh_band_id: J2kDirectBandId,
170 /// HH band rect.
171 pub hh: J2kRect,
172}
173
174/// Adapter grayscale store step for a direct device plan.
175#[derive(Debug, Clone, Copy)]
176pub struct J2kDirectStoreStep {
177 /// Stable identifier of the input coefficient band.
178 pub input_band_id: J2kDirectBandId,
179 /// Source rect of the input plane.
180 pub input_rect: J2kRect,
181 /// Source x offset to begin copying from.
182 pub source_x: u32,
183 /// Source y offset to begin copying from.
184 pub source_y: u32,
185 /// Number of samples to copy per row.
186 pub copy_width: u32,
187 /// Number of rows to copy.
188 pub copy_height: u32,
189 /// Destination row width.
190 pub output_width: u32,
191 /// Destination height.
192 pub output_height: u32,
193 /// Destination x offset to begin writing at.
194 pub output_x: u32,
195 /// Destination y offset to begin writing at.
196 pub output_y: u32,
197 /// Constant value added to every copied sample.
198 pub addend: f32,
199}