Skip to main content

j2k_types/packetization/
jobs.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! Packetization input values and jobs.
4
5use alloc::vec::Vec;
6
7use super::J2kPacketizationProgressionOrder;
8
9/// One encoded Tier-1 code-block contribution to a packet.
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub struct J2kPacketizationCodeBlock<'a> {
12    /// Encoded Tier-1 bitstream bytes for this packet contribution.
13    pub data: &'a [u8],
14    /// HTJ2K cleanup segment length in bytes when using high-throughput coding.
15    pub ht_cleanup_length: u32,
16    /// HTJ2K refinement segment length in bytes when using high-throughput coding.
17    pub ht_refinement_length: u32,
18    /// Number of coding passes in this contribution.
19    pub num_coding_passes: u8,
20    /// Number of zero most-significant bitplanes before first inclusion.
21    pub num_zero_bitplanes: u8,
22    /// Whether this code block was included in a previous packet.
23    pub previously_included: bool,
24    /// L-block value used for segment length coding.
25    pub l_block: u32,
26    /// Block coder used for this contribution.
27    pub block_coding_mode: J2kPacketizationBlockCodingMode,
28}
29
30/// Packetization block coding mode.
31#[derive(Debug, Clone, Copy, PartialEq, Eq)]
32pub enum J2kPacketizationBlockCodingMode {
33    /// Classic JPEG 2000 Part 1 EBCOT block coding.
34    Classic,
35    /// High-throughput JPEG 2000 Part 15 block coding.
36    HighThroughput,
37}
38
39/// One packetization subband precinct.
40#[derive(Debug, PartialEq, Eq)]
41pub struct J2kPacketizationSubband<'a> {
42    /// Code-block contributions in row-major order.
43    pub code_blocks: Vec<J2kPacketizationCodeBlock<'a>>,
44    /// Number of code blocks in the x direction.
45    pub num_cbs_x: u32,
46    /// Number of code blocks in the y direction.
47    pub num_cbs_y: u32,
48}
49
50/// One packetization resolution packet.
51#[derive(Debug, PartialEq, Eq)]
52pub struct J2kPacketizationResolution<'a> {
53    /// Subbands in packet order: LL for resolution 0, then HL/LH/HH.
54    pub subbands: Vec<J2kPacketizationSubband<'a>>,
55}
56
57/// Explicit packet descriptor.
58#[derive(Debug, Clone, Copy, PartialEq, Eq)]
59pub struct J2kPacketizationPacketDescriptor {
60    /// Index into the packet contribution array.
61    pub packet_index: u32,
62    /// Persistent packet-state index for repeated layer/precinct packets.
63    pub state_index: u32,
64    /// Quality layer for inclusion tag-tree thresholds.
65    pub layer: u8,
66    /// Resolution index in the output progression.
67    pub resolution: u32,
68    /// Component index in the output progression.
69    pub component: u16,
70    /// Precinct index in the output progression.
71    pub precinct: u64,
72}
73
74/// Packetization encode job.
75#[derive(Debug, Clone, Copy, PartialEq, Eq)]
76pub struct J2kPacketizationEncodeJob<'a> {
77    /// Number of resolution packets prepared for packetization.
78    pub resolution_count: u32,
79    /// Number of layers to write.
80    pub num_layers: u8,
81    /// Number of image components.
82    pub num_components: u16,
83    /// Total number of code-block contributions.
84    pub code_block_count: u32,
85    /// Packet progression order to emit.
86    pub progression_order: J2kPacketizationProgressionOrder,
87    /// Explicit packet descriptors in output progression order.
88    pub packet_descriptors: &'a [J2kPacketizationPacketDescriptor],
89    /// Packet payload prepared by Tier-1, in LRCP packet order.
90    pub resolutions: &'a [J2kPacketizationResolution<'a>],
91}
92
93crate::move_only::assert_move_only!(
94    J2kPacketizationSubband<'static>,
95    J2kPacketizationResolution<'static>,
96);