pub mod marker {
pub const SOF0: u8 = 0xC0; pub const SOF1: u8 = 0xC1; pub const SOF2: u8 = 0xC2; pub const SOF3: u8 = 0xC3; pub const DHT: u8 = 0xC4; pub const SOF5: u8 = 0xC5; pub const SOF6: u8 = 0xC6; pub const SOF7: u8 = 0xC7; pub const SOF9: u8 = 0xC9; pub const SOF10: u8 = 0xCA; pub const SOF11: u8 = 0xCB; pub const SOF13: u8 = 0xCD; pub const SOF14: u8 = 0xCE; pub const SOF15: u8 = 0xCF; pub const SOI: u8 = 0xD8; pub const EOI: u8 = 0xD9; pub const SOS: u8 = 0xDA; pub const DQT: u8 = 0xDB; pub const DRI: u8 = 0xDD; pub const RST0: u8 = 0xD0; pub const RST7: u8 = 0xD7; pub const APP1: u8 = 0xE1; }
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SamplingFactor {
pub h: u8,
pub v: u8,
}
#[derive(Debug, Clone, Copy)]
pub struct Component {
pub id: u8,
pub sampling: SamplingFactor,
pub quant_table_id: u8,
pub dc_table_id: u8,
pub ac_table_id: u8,
}
#[derive(Debug, Clone)]
pub struct ImageHeader {
pub width: u16,
pub height: u16,
pub components: Vec<Component>,
pub max_h_samp: u8,
pub max_v_samp: u8,
pub is_progressive: bool,
}
impl ImageHeader {
pub fn mcu_width(&self) -> usize {
self.max_h_samp as usize * 8
}
pub fn mcu_height(&self) -> usize {
self.max_v_samp as usize * 8
}
pub fn mcus_x(&self) -> usize {
(self.width as usize).div_ceil(self.mcu_width())
}
pub fn mcus_y(&self) -> usize {
(self.height as usize).div_ceil(self.mcu_height())
}
}
#[derive(Debug, Clone)]
pub struct QuantTable {
pub values: [u16; 64],
}
impl Default for QuantTable {
fn default() -> Self {
Self { values: [1; 64] }
}
}
pub const ZIGZAG: [u8; 64] = [
0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, 12, 19, 26, 33, 40, 48, 41, 34, 27, 20,
13, 6, 7, 14, 21, 28, 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51, 58, 59,
52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63,
];