use alloc::vec::Vec;
use j2k_core::{CompressedPayloadKind, CompressedTransferSyntax, Info};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct J2kComponentInfo {
pub bit_depth: u8,
pub signed: bool,
pub x_rsiz: u8,
pub y_rsiz: u8,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct J2kSupportInfo {
pub info: Info,
pub transfer_syntax: CompressedTransferSyntax,
pub payload_kind: CompressedPayloadKind,
pub components: Vec<J2kComponentInfo>,
pub file_metadata: Option<J2kFileMetadata>,
}
impl J2kSupportInfo {
#[must_use]
pub fn component_count(&self) -> u16 {
self.info.components
}
#[must_use]
pub fn has_signed_components(&self) -> bool {
self.components.iter().any(|component| component.signed)
}
#[must_use]
pub fn has_mixed_bit_depths(&self) -> bool {
let Some(first) = self.components.first() else {
return false;
};
self.components
.iter()
.any(|component| component.bit_depth != first.bit_depth)
}
#[must_use]
pub fn has_component_subsampling(&self) -> bool {
self.components
.iter()
.any(|component| component.x_rsiz != 1 || component.y_rsiz != 1)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct J2kFileMetadata {
pub bits_per_component: Vec<J2kComponentInfo>,
pub color_specs: Vec<J2kColorSpec>,
pub palette: Option<J2kPaletteMetadata>,
pub component_mappings: Vec<J2kComponentMapping>,
pub channel_definitions: Vec<J2kChannelDefinition>,
pub has_palette: bool,
pub has_component_mapping: bool,
pub has_channel_definition: bool,
}
impl J2kFileMetadata {
#[must_use]
pub fn has_icc_profile(&self) -> bool {
self.color_specs
.iter()
.any(|color_spec| matches!(color_spec, J2kColorSpec::IccProfile { .. }))
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct J2kPaletteMetadata {
pub columns: Vec<J2kPaletteColumn>,
pub entries: Vec<Vec<u64>>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct J2kPaletteColumn {
pub bit_depth: u8,
pub signed: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct J2kComponentMapping {
pub component_index: u16,
pub mapping_type: J2kComponentMappingType,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum J2kComponentMappingType {
Direct,
Palette {
column: u8,
},
Unknown {
value: u8,
column: u8,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct J2kChannelDefinition {
pub channel_index: u16,
pub channel_type: J2kChannelType,
pub association: J2kChannelAssociation,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum J2kChannelType {
Color,
Opacity,
PremultipliedOpacity,
Unspecified,
Unknown {
value: u16,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum J2kChannelAssociation {
WholeImage,
Color {
index: u16,
},
Unspecified,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum J2kColorSpec {
Enumerated {
value: u32,
},
IccProfile {
profile: Vec<u8>,
},
Unknown {
method: u8,
},
}