use crate::codestream::markers::Siz;
use crate::jp2::Jp2Metadata;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct Header {
pub width: u32,
pub height: u32,
pub components: Vec<ComponentInfo>,
pub max_reduction: u8,
pub jp2: Option<Jp2Metadata>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct ComponentInfo {
pub bit_depth: u8,
pub signed: bool,
pub x_sampling: u8,
pub y_sampling: u8,
pub width: u32,
pub height: u32,
}
impl ComponentInfo {
pub(crate) fn on_grid(
siz: &Siz,
bit_depth: u8,
signed: bool,
x_sampling: u8,
y_sampling: u8,
reduction: u8,
) -> Self {
let (width, height) = siz
.sampled_extent_at(x_sampling, y_sampling, reduction)
.unwrap_or((0, 0));
ComponentInfo {
bit_depth,
signed,
x_sampling,
y_sampling,
width,
height,
}
}
pub(crate) fn of_siz(siz: &Siz, reduction: u8) -> Vec<Self> {
siz.components
.iter()
.map(|c| {
Self::on_grid(
siz,
c.bit_depth,
c.signed,
c.x_sampling,
c.y_sampling,
reduction,
)
})
.collect()
}
}