#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum AppMarkerType {
Unknown = 0,
Icc = 1,
Exif = 2,
Xmp = 3,
}
#[derive(Debug, Clone)]
pub struct JpegQuantTable {
pub values: [i32; 64],
pub precision: u32,
pub index: u32,
pub is_last: bool,
}
#[derive(Debug, Clone)]
pub struct JpegHuffmanCode {
pub is_ac: bool,
pub id: u32,
pub is_last: bool,
pub counts: [u32; 16],
pub values: Vec<u8>,
}
#[derive(Debug, Clone)]
pub struct JpegComponent {
pub id: u32,
pub h_samp_factor: u32,
pub v_samp_factor: u32,
pub quant_idx: u32,
pub width_in_blocks: u32,
pub height_in_blocks: u32,
pub coeffs: Vec<i16>,
}
#[derive(Debug, Clone)]
pub struct JpegScanInfo {
pub num_components: u32,
pub component_indices: Vec<u32>,
pub dc_tbl_idx: Vec<u32>,
pub ac_tbl_idx: Vec<u32>,
pub ss: u32,
pub se: u32,
pub ah: u32,
pub al: u32,
pub reset_points: Vec<u32>,
pub extra_zero_runs: Vec<(u32, u32)>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum JpegComponentType {
Gray = 0,
YCbCr = 1,
Rgb = 2,
Custom = 3,
}
#[derive(Debug, Clone)]
pub struct JpegData {
pub width: u32,
pub height: u32,
pub restart_interval: u32,
pub app_data: Vec<Vec<u8>>,
pub app_marker_type: Vec<AppMarkerType>,
pub com_data: Vec<Vec<u8>>,
pub quant: Vec<JpegQuantTable>,
pub huffman_code: Vec<JpegHuffmanCode>,
pub components: Vec<JpegComponent>,
pub scan_info: Vec<JpegScanInfo>,
pub marker_order: Vec<u8>,
pub inter_marker_data: Vec<Vec<u8>>,
pub tail_data: Vec<u8>,
pub has_zero_padding_bit: bool,
pub padding_bits: Vec<u8>,
pub component_type: JpegComponentType,
}
pub const JPEG_NATURAL_ORDER: [usize; 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,
];
#[cfg(test)]
pub const JPEG_ZIGZAG_ORDER: [usize; 64] = {
let mut table = [0usize; 64];
let mut i = 0;
while i < 64 {
table[JPEG_NATURAL_ORDER[i]] = i;
i += 1;
}
table
};