j2k_types/tier1/classic.rs
1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! Classic JPEG 2000 Tier-1 coding values.
4
5use alloc::vec::Vec;
6
7/// Classic JPEG 2000 subband kind.
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum J2kSubBandType {
10 /// Low-low subband.
11 LowLow,
12 /// High-low subband.
13 HighLow,
14 /// Low-high subband.
15 LowHigh,
16 /// High-high subband.
17 HighHigh,
18}
19
20/// Classic JPEG 2000 code-block style flags.
21#[derive(Debug, Clone, Copy)]
22#[expect(
23 clippy::struct_excessive_bools,
24 reason = "the five booleans model independent JPEG 2000 COD code-block style flags"
25)]
26pub struct J2kCodeBlockStyle {
27 /// Selective arithmetic coding bypass was enabled.
28 pub selective_arithmetic_coding_bypass: bool,
29 /// Context probabilities reset after each pass.
30 pub reset_context_probabilities: bool,
31 /// Coding terminated after each pass.
32 pub termination_on_each_pass: bool,
33 /// Vertically causal context was enabled.
34 pub vertically_causal_context: bool,
35 /// Segmentation symbols were enabled.
36 pub segmentation_symbols: bool,
37}
38
39/// One coded segment in a classic JPEG 2000 code block.
40#[derive(Debug, Clone, Copy, PartialEq, Eq)]
41pub struct J2kCodeBlockSegment {
42 /// Byte offset of this segment within the combined payload.
43 pub data_offset: u32,
44 /// Segment payload length in bytes.
45 pub data_length: u32,
46 /// First coding pass covered by this segment.
47 pub start_coding_pass: u8,
48 /// One-past-last coding pass covered by this segment.
49 pub end_coding_pass: u8,
50 /// Whether this segment is decoded through the arithmetic path.
51 pub use_arithmetic: bool,
52}
53
54/// Encoded classic JPEG 2000 code-block payload.
55#[derive(Debug)]
56pub struct EncodedJ2kCodeBlock {
57 /// Combined payload bytes for all coded segments in this code block.
58 pub data: Vec<u8>,
59 /// Coded segments for the code block.
60 pub segments: Vec<J2kCodeBlockSegment>,
61 /// Number of coding passes present for this code block.
62 pub number_of_coding_passes: u8,
63 /// Missing most-significant bit planes for this code block.
64 pub missing_bit_planes: u8,
65}
66
67/// Classic JPEG 2000 Tier-1 code-block encode job.
68#[derive(Debug, Clone, Copy)]
69pub struct J2kTier1CodeBlockEncodeJob<'a> {
70 /// Quantized coefficients in row-major order.
71 pub coefficients: &'a [i32],
72 /// Code-block width in samples.
73 pub width: u32,
74 /// Code-block height in samples.
75 pub height: u32,
76 /// Subband kind containing this code block.
77 pub sub_band_type: J2kSubBandType,
78 /// Total bitplanes for this subband/code block.
79 pub total_bitplanes: u8,
80 /// Classic JPEG 2000 code-block style flags.
81 pub style: J2kCodeBlockStyle,
82}
83
84crate::move_only::assert_move_only!(EncodedJ2kCodeBlock);