mod allocation;
mod referenced;
use alloc::vec::Vec;
use crate::{J2kCodeBlockSegment, J2kCodeBlockStyle, J2kSubBandType};
pub use allocation::DecodePlanAllocationError;
pub use referenced::{
J2kReferencedClassicPlan, J2kReferencedHtj2kPlan, J2kReferencedImageGeometry,
J2kReferencedPayloadRecordSpan, J2kReferencedTileGeometry, J2kReferencedTilePlan,
};
pub const DEFAULT_MAX_CODEC_BYTES: usize = 512 * 1024 * 1024;
pub const DEFAULT_MAX_DECODE_BYTES: usize = DEFAULT_MAX_CODEC_BYTES;
pub type J2kDirectBandId = u32;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct J2kRect {
pub x0: u32,
pub y0: u32,
pub x1: u32,
pub y1: u32,
}
impl J2kRect {
#[must_use]
pub const fn width(self) -> u32 {
self.x1.saturating_sub(self.x0)
}
#[must_use]
pub const fn height(self) -> u32 {
self.y1.saturating_sub(self.y0)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum J2kWaveletTransform {
Reversible53,
Irreversible97,
}
#[derive(Debug)]
pub enum J2kDirectGrayscaleStep {
ClassicSubBand(J2kOwnedSubBandPlan),
HtSubBand(HtOwnedSubBandPlan),
Idwt(J2kDirectIdwtStep),
Store(J2kDirectStoreStep),
}
#[derive(Debug)]
pub struct J2kDirectGrayscalePlan {
pub dimensions: (u32, u32),
pub bit_depth: u8,
pub steps: Vec<J2kDirectGrayscaleStep>,
}
#[derive(Debug)]
pub struct J2kDirectColorPlan {
pub dimensions: (u32, u32),
pub bit_depths: [u8; 3],
pub mct: bool,
pub transform: J2kWaveletTransform,
pub component_plans: Vec<J2kDirectGrayscalePlan>,
}
#[derive(Debug)]
pub struct J2kDirectRgbaPlan {
pub dimensions: (u32, u32),
pub bit_depths: [u8; 4],
pub mct: bool,
pub transform: J2kWaveletTransform,
pub component_plans: Vec<J2kDirectGrayscalePlan>,
}
#[derive(Debug)]
pub struct J2kOwnedSubBandPlan {
pub band_id: J2kDirectBandId,
pub rect: J2kRect,
pub width: u32,
pub height: u32,
pub irreversible_midpoint: bool,
pub jobs: Vec<J2kOwnedCodeBlockBatchJob>,
}
#[derive(Debug)]
pub struct HtOwnedSubBandPlan {
pub band_id: J2kDirectBandId,
pub rect: J2kRect,
pub width: u32,
pub height: u32,
pub irreversible_midpoint: bool,
pub jobs: Vec<HtOwnedCodeBlockBatchJob>,
}
#[derive(Debug)]
pub struct J2kOwnedCodeBlockBatchJob {
pub output_x: u32,
pub output_y: u32,
pub data: Vec<u8>,
pub segments: Vec<J2kCodeBlockSegment>,
pub width: u32,
pub height: u32,
pub output_stride: usize,
pub missing_bit_planes: u8,
pub number_of_coding_passes: u8,
pub total_bitplanes: u8,
pub roi_shift: u8,
pub sub_band_type: J2kSubBandType,
pub style: J2kCodeBlockStyle,
pub strict: bool,
pub dequantization_step: f32,
}
#[derive(Debug)]
pub struct HtOwnedCodeBlockBatchJob {
pub output_x: u32,
pub output_y: u32,
pub data: Vec<u8>,
pub cleanup_length: u32,
pub refinement_length: u32,
pub width: u32,
pub height: u32,
pub output_stride: usize,
pub missing_bit_planes: u8,
pub number_of_coding_passes: u8,
pub num_bitplanes: u8,
pub roi_shift: u8,
pub stripe_causal: bool,
pub strict: bool,
pub dequantization_step: f32,
}
#[derive(Debug, Clone, Copy)]
pub struct J2kDirectIdwtStep {
pub output_band_id: J2kDirectBandId,
pub rect: J2kRect,
pub transform: J2kWaveletTransform,
pub ll_band_id: J2kDirectBandId,
pub ll: J2kRect,
pub hl_band_id: J2kDirectBandId,
pub hl: J2kRect,
pub lh_band_id: J2kDirectBandId,
pub lh: J2kRect,
pub hh_band_id: J2kDirectBandId,
pub hh: J2kRect,
}
#[derive(Debug, Clone, Copy)]
pub struct J2kDirectStoreStep {
pub input_band_id: J2kDirectBandId,
pub input_rect: J2kRect,
pub source_x: u32,
pub source_y: u32,
pub copy_width: u32,
pub copy_height: u32,
pub output_width: u32,
pub output_height: u32,
pub output_x: u32,
pub output_y: u32,
pub addend: f32,
}