euv_core/media/image/struct.rs
1use super::*;
2
3/// Decoded 8-bit sRGB/linear RGBA raster image produced by pure-Rust codecs.
4#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
5pub struct DecodedRgbaImage {
6 /// Image width in pixels.
7 #[get(type(copy))]
8 pub(crate) width: u32,
9 /// Image height in pixels.
10 #[get(type(copy))]
11 pub(crate) height: u32,
12 /// Packed RGBA8 pixel data (`width * height * 4` bytes).
13 pub(crate) pixels: Vec<u8>,
14 /// Source container format.
15 #[get(type(copy))]
16 pub(crate) format: DecodedImageFormat,
17}
18
19/// Decoded 32-bit floating-point linear HDR RGBA image for IBL environments and HDR textures.
20#[derive(Clone, Data, Debug, Default, PartialEq)]
21pub struct DecodedHdrImage {
22 /// Image width in pixels.
23 #[get(type(copy))]
24 pub(crate) width: u32,
25 /// Image height in pixels.
26 #[get(type(copy))]
27 pub(crate) height: u32,
28 /// Packed linear RGBA32F pixel data (`width * height * 4` floats).
29 pub(crate) pixels: Vec<f32>,
30 /// Source HDR container format.
31 #[get(type(copy))]
32 pub(crate) format: DecodedImageFormat,
33}
34
35/// LSB-first bitstream reader used by RFC 1951 DEFLATE decompression.
36#[derive(Clone, Debug)]
37pub(crate) struct DeflateBitReader<'a> {
38 /// Underlying compressed byte slice.
39 pub(crate) data: &'a [u8],
40 /// Current byte cursor position.
41 pub(crate) byte_pos: usize,
42 /// Buffered unread bits in LSB-first order.
43 pub(crate) bit_buf: u64,
44 /// Number of valid bits currently held in `bit_buf`.
45 pub(crate) bit_count: u8,
46}
47
48/// Canonical Huffman decoding table for RFC 1951 DEFLATE symbols.
49#[derive(Clone, Debug, Default)]
50pub(crate) struct DeflateHuffmanTable {
51 /// Count of codes for each bit length `1..=15`.
52 pub(crate) counts: [u16; 16],
53 /// Symbols ordered canonically by `(bit_length, symbol)`.
54 pub(crate) symbols: Vec<u16>,
55 /// Maximum active code bit length.
56 pub(crate) max_bits: u8,
57}
58
59/// Canonical MSB-first Huffman decoding table for Baseline JPEG entropy coding.
60#[derive(Clone, Debug, Default)]
61pub(crate) struct JpegHuffmanTable {
62 /// Maximum code value + 1 for each bit length `1..=16`.
63 pub(crate) max_code: [i32; 17],
64 /// Offset into `values` minus minimum code value for each bit length `1..=16`.
65 pub(crate) val_offset: [i32; 17],
66 /// Symbol byte table ordered canonically.
67 pub(crate) values: Vec<u8>,
68 /// Whether this table slot has been populated by a DHT marker.
69 pub(crate) valid: bool,
70}
71
72/// Canonical MSB-first Huffman encoding table for Baseline JPEG output.
73#[derive(Clone, Debug)]
74pub(crate) struct JpegHuffmanEncodeTable {
75 /// Bit code per symbol `0..=255`.
76 pub(crate) codes: [u16; 256],
77 /// Bit length per symbol `0..=255` (`0` = unused).
78 pub(crate) lengths: [u8; 256],
79}
80
81/// Single color component descriptor parsed from a JPEG SOF0 frame header.
82#[derive(Clone, Copy, Debug, Default)]
83pub(crate) struct JpegComponentSpec {
84 /// Component identifier from SOF0.
85 pub(crate) id: u8,
86 /// Horizontal sampling factor (`1..=4`).
87 pub(crate) h_samp: u8,
88 /// Vertical sampling factor (`1..=4`).
89 pub(crate) v_samp: u8,
90 /// Quantization table slot (`0..=3`).
91 pub(crate) quant_id: u8,
92 /// DC Huffman table slot (`0..=3`).
93 pub(crate) dc_table_id: u8,
94 /// AC Huffman table slot (`0..=3`).
95 pub(crate) ac_table_id: u8,
96 /// Running DC predictor value across MCUs.
97 pub(crate) dc_pred: i32,
98}
99
100/// MSB-first entropy bitstream reader handling JPEG `0xFF 0x00` byte stuffing.
101#[derive(Clone, Debug)]
102pub(crate) struct JpegBitReader<'a> {
103 /// Underlying JPEG file slice.
104 pub(crate) data: &'a [u8],
105 /// Current byte index inside `data`.
106 pub(crate) pos: usize,
107 /// Buffered unread bits in MSB-first alignment at the top of `bit_buf`.
108 pub(crate) bit_buf: u32,
109 /// Number of valid bits currently in `bit_buf`.
110 pub(crate) bit_count: u8,
111}
112
113/// MSB-first entropy bitstream writer emitting JPEG `0xFF 0x00` stuffed bytes.
114#[derive(Clone, Debug, Default)]
115pub(crate) struct JpegBitWriter {
116 /// Output byte stream.
117 pub(crate) out: Vec<u8>,
118 /// Pending partial bits accumulated MSB-first.
119 pub(crate) bit_buf: u32,
120 /// Number of valid bits accumulated in `bit_buf`.
121 pub(crate) bit_count: u8,
122}
123
124/// Channel descriptor parsed from an OpenEXR `channels` header attribute.
125#[derive(Clone, Debug)]
126pub(crate) struct ExrChannelDesc {
127 /// ASCII channel name (`"R"`, `"G"`, `"B"`, `"A"`, etc.).
128 pub(crate) name: String,
129 /// OpenEXR pixel data type (`0` = UINT, `1` = HALF, `2` = FLOAT).
130 pub(crate) pixel_type: i32,
131}