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
use alloc::vec::Vec;
use crate::{J2kRect, J2kWaveletTransform};
mod allocation;
/// Adapter identifier for one device-owned grayscale coefficient band.
pub type J2kDirectBandId = u32;
/// Adapter grayscale-only direct device-plan step for backend experimentation.
#[derive(Debug)]
pub enum J2kDirectGrayscaleStep {
/// Decode one classic J2K sub-band into a device-owned coefficient buffer.
ClassicSubBand(J2kOwnedSubBandPlan),
/// Decode one HTJ2K sub-band into a device-owned coefficient buffer.
HtSubBand(HtOwnedSubBandPlan),
/// Apply one single-decomposition IDWT level on device-owned buffers.
Idwt(J2kDirectIdwtStep),
/// Store the final component plane into an output plane buffer.
Store(J2kDirectStoreStep),
}
/// Adapter grayscale-only direct device plan for backend experimentation.
#[derive(Debug)]
pub struct J2kDirectGrayscalePlan {
/// Final output dimensions.
pub dimensions: (u32, u32),
/// Final output bit depth.
pub bit_depth: u8,
/// Ordered execution steps for the direct device pipeline.
pub steps: Vec<J2kDirectGrayscaleStep>,
}
/// Adapter RGB direct device plan for backend experimentation.
#[derive(Debug)]
pub struct J2kDirectColorPlan {
/// Final output dimensions.
pub dimensions: (u32, u32),
/// Final output bit depths for the first three color components.
pub bit_depths: [u8; 3],
/// Whether inverse MCT must be applied after component stores.
pub mct: bool,
/// Wavelet transform used by the codestream's color transform.
pub transform: J2kWaveletTransform,
/// Per-component direct plans. RGB plans currently contain exactly three components.
pub component_plans: Vec<J2kDirectGrayscalePlan>,
}
/// Adapter owned classic J2K sub-band decode job.
#[derive(Debug)]
pub struct J2kOwnedSubBandPlan {
/// Stable identifier for the decoded coefficient band produced by this step.
pub band_id: J2kDirectBandId,
/// Absolute sub-band rect in component coordinates.
pub rect: J2kRect,
/// Sub-band width in samples.
pub width: u32,
/// Sub-band height in samples.
pub height: u32,
/// Owned code-block jobs for this sub-band.
pub jobs: Vec<J2kOwnedCodeBlockBatchJob>,
}
/// Adapter owned HTJ2K sub-band decode job.
#[derive(Debug)]
pub struct HtOwnedSubBandPlan {
/// Stable identifier for the decoded coefficient band produced by this step.
pub band_id: J2kDirectBandId,
/// Absolute sub-band rect in component coordinates.
pub rect: J2kRect,
/// Sub-band width in samples.
pub width: u32,
/// Sub-band height in samples.
pub height: u32,
/// Owned code-block jobs for this sub-band.
pub jobs: Vec<HtOwnedCodeBlockBatchJob>,
}
/// Adapter owned classic J2K batched code-block decode job.
#[derive(Debug)]
pub struct J2kOwnedCodeBlockBatchJob {
/// X offset within the target sub-band coefficient buffer.
pub output_x: u32,
/// Y offset within the target sub-band coefficient buffer.
pub output_y: u32,
/// Combined payload bytes for all coded segments in this code block.
pub data: Vec<u8>,
/// Coded segments for the code block.
pub segments: Vec<crate::J2kCodeBlockSegment>,
/// Code-block width in samples.
pub width: u32,
/// Code-block height in samples.
pub height: u32,
/// Output row stride, in samples, for the target sub-band storage.
pub output_stride: usize,
/// Missing most-significant bit planes for this code block.
pub missing_bit_planes: u8,
/// Number of coding passes present for this code block.
pub number_of_coding_passes: u8,
/// Total coded bitplanes for the parent sub-band.
pub total_bitplanes: u8,
/// Region-of-interest maxshift value from RGN marker metadata.
pub roi_shift: u8,
/// The sub-band type containing this code block.
pub sub_band_type: crate::J2kSubBandType,
/// The code-block style flags.
pub style: crate::J2kCodeBlockStyle,
/// Whether strict decode validation is enabled for the parent image.
pub strict: bool,
/// Dequantization step to apply to decoded coefficients.
pub dequantization_step: f32,
}
define_ht_code_block_job! {
/// Adapter owned HTJ2K batched code-block decode job.
#[derive(Debug)]
pub struct HtOwnedCodeBlockBatchJob {
/// X offset within the target sub-band coefficient buffer.
pub output_x: u32,
/// Y offset within the target sub-band coefficient buffer.
pub output_y: u32,
/// Combined cleanup/refinement bytes for the code block.
pub data: Vec<u8>,
}
}
/// Adapter single grayscale IDWT step for a direct device plan.
#[derive(Debug, Clone, Copy)]
pub struct J2kDirectIdwtStep {
/// Stable identifier of the output coefficient band produced by this step.
pub output_band_id: J2kDirectBandId,
/// Output rect of this decomposition level.
pub rect: J2kRect,
/// Transform to apply.
pub transform: J2kWaveletTransform,
/// Stable identifier of the LL input band.
pub ll_band_id: J2kDirectBandId,
/// LL band rect.
pub ll: J2kRect,
/// Stable identifier of the HL input band.
pub hl_band_id: J2kDirectBandId,
/// HL band rect.
pub hl: J2kRect,
/// Stable identifier of the LH input band.
pub lh_band_id: J2kDirectBandId,
/// LH band rect.
pub lh: J2kRect,
/// Stable identifier of the HH input band.
pub hh_band_id: J2kDirectBandId,
/// HH band rect.
pub hh: J2kRect,
}
/// Adapter grayscale store step for a direct device plan.
#[derive(Debug, Clone, Copy)]
pub struct J2kDirectStoreStep {
/// Stable identifier of the input coefficient band.
pub input_band_id: J2kDirectBandId,
/// Source rect of the input plane.
pub input_rect: J2kRect,
/// Source x offset to begin copying from.
pub source_x: u32,
/// Source y offset to begin copying from.
pub source_y: u32,
/// Number of samples to copy per row.
pub copy_width: u32,
/// Number of rows to copy.
pub copy_height: u32,
/// Destination row width.
pub output_width: u32,
/// Destination height.
pub output_height: u32,
/// Destination x offset to begin writing at.
pub output_x: u32,
/// Destination y offset to begin writing at.
pub output_y: u32,
/// Constant value added to every copied sample.
pub addend: f32,
}