#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct Jp2Metadata {
pub color: ColorSpace,
pub channels: Vec<ChannelDefinition>,
pub palette_applied: bool,
pub channel_definitions: Option<Vec<ChannelDefinitionEntry>>,
pub palette: Option<Palette>,
pub channel_mapping: Option<Vec<ChannelMapping>>,
pub resolution: Resolution,
pub xml: Vec<XmlBox>,
pub uuid: Vec<UuidBox>,
pub ipr: Vec<IprBox>,
pub uuid_info: Vec<UuidInfo>,
pub image_header: ImageHeader,
pub color_specifications: Vec<ColorSpecification>,
pub file_type: FileType,
pub reader_requirements: Option<ReaderRequirements>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct ImageHeader {
pub compression: u8,
pub unknown_color_space: u8,
pub ipr_flag: u8,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
#[doc(alias = "ColourSpecification")]
pub struct ColorSpecification {
pub method: u8,
pub precedence: u8,
pub approximation: u8,
pub payload: Vec<u8>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct FileType {
pub brand: [u8; 4],
pub minor_version: u32,
pub compatibility: Vec<[u8; 4]>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct ReaderRequirements {
pub mask_length: u8,
pub fully_understand: Vec<u8>,
pub decode_completely: Vec<u8>,
pub standard_features: Vec<StandardFeature>,
pub vendor_features: Vec<VendorFeature>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct StandardFeature {
pub feature: u16,
pub mask: Vec<u8>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct VendorFeature {
pub id: [u8; 16],
pub mask: Vec<u8>,
}
use super::palette::{ChannelMapping, Palette};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[non_exhaustive]
pub struct Resolution {
pub capture: Option<Res>,
pub display: Option<Res>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct Res {
pub vertical: Ratio,
pub horizontal: Ratio,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct Ratio {
pub numerator: u16,
pub denominator: u16,
pub exponent: i8,
}
impl Ratio {
#[must_use]
pub fn grid_points_per_meter(self) -> Option<f64> {
if self.denominator == 0 {
return None;
}
Some(
f64::from(self.numerator) / f64::from(self.denominator)
* 10f64.powi(i32::from(self.exponent)),
)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct XmlBox {
pub payload: Vec<u8>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct IprBox {
pub payload: Vec<u8>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct UuidBox {
pub id: [u8; 16],
pub payload: Vec<u8>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct UuidInfo {
pub ids: Vec<[u8; 16]>,
pub version: u8,
pub flags: [u8; 3],
pub location: Vec<u8>,
}
impl UuidInfo {
#[must_use]
pub fn location_str(&self) -> Option<&str> {
let text = self.location.strip_suffix(&[0]).unwrap_or(&self.location);
if text.contains(&0) {
return None;
}
std::str::from_utf8(text).ok()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
#[doc(alias = "ColourSpace")]
pub enum ColorSpace {
Srgb,
Grayscale,
Sycc,
RestrictedIcc(Vec<u8>),
Enumerated(u32),
Unknown,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ChannelDefinition {
pub kind: ChannelType,
pub association: Association,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct ChannelDefinitionEntry {
pub channel: u16,
pub definition: ChannelDefinition,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum ChannelType {
Color,
Opacity,
PremultipliedOpacity,
ApplicationDefined,
Unspecified,
Other(u16),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Association {
WholeImage,
Color(u16),
None,
ApplicationDefined(u16),
}