Skip to content

Commit 792fd45

Browse files
Store huffman table code lens and symbols separately
1 parent 1c45cab commit 792fd45

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/jpeg/decoder.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ impl<'a> JpegDecoder<'a> {
8383

8484
Ok(JFIF {
8585
quantization_tables,
86-
huffman_tables,
86+
huffman_tables: {
87+
ensure!(huffman_tables.len() == 4);
88+
huffman_tables
89+
},
8790
start_of_frame: start_of_frame.ok_or_else(|| anyhow!("expected start of frame"))?,
8891
start_of_scan: start_of_scan.ok_or_else(|| anyhow!("expected start of scan"))?,
8992
image_data: image_data.ok_or_else(|| anyhow!("expected image data"))?,
@@ -158,7 +161,17 @@ impl<'a> JpegDecoder<'a> {
158161

159162
let huffman_table = HuffmanTable {
160163
flag,
161-
element_range: Range {
164+
code_lengths: {
165+
let code_lengths = Range {
166+
start: self.cursor,
167+
end: self.cursor + 16,
168+
};
169+
170+
self.cursor += 16;
171+
172+
code_lengths
173+
},
174+
symbols: Range {
162175
start: self.cursor,
163176
end: offset + length,
164177
},

src/jpeg/grammar.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ impl QuantizationTable {
4141
#[derive(Debug)]
4242
pub struct HuffmanTable {
4343
pub flag: u8,
44-
pub element_range: Range<usize>,
44+
pub code_lengths: Range<usize>,
45+
pub symbols: Range<usize>,
4546
}
4647

4748
#[derive(Debug)]

0 commit comments

Comments
 (0)