From 4f5e260fc1163b9383c565035e73f30bedbeec92 Mon Sep 17 00:00:00 2001 From: "sgunderson@bigfoot.com" <> Date: Sun, 31 May 2009 01:50:46 +0200 Subject: [PATCH] Add DQT parsing. --- driver.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/driver.c b/driver.c index dd1b1ae..bbc569e 100644 --- a/driver.c +++ b/driver.c @@ -12,6 +12,7 @@ struct jpeg_image { unsigned width, height; unsigned num_components; unsigned hsample[256], vsample[256], qtable[256]; + uint32_t qvalues[256][DCTSIZE2]; }; ssize_t stdio_read(void* userdata, uint8_t* buf, size_t count) @@ -19,6 +20,33 @@ ssize_t stdio_read(void* userdata, uint8_t* buf, size_t count) return fread(buf, 1, count, (FILE*)userdata); } +void read_dqt(struct byte_source* source, struct jpeg_image* image) +{ + unsigned len = read_uint16(byte_source_input_func, source); + assert(len >= 67); + uint8_t precision_table = read_uint8(byte_source_input_func, source); + int precision = precision_table >> 4; // 0 = 8 bits, otherwise 16 bits. + int table = precision_table & 0x0f; + + if (precision != 0) { + assert(len == 131); + fprintf(stderr, "Quantization table %u: 16 bits/entry\n", table); + } else { + assert(len == 67); + fprintf(stderr, "Quantization table %u: 8 bits/entry\n", table); + } + + for (unsigned i = 0; i < 64; ++i) { + if (precision != 0) { + image->qvalues[table][unzigzag[i]] = + read_uint16(byte_source_input_func, source); + } else { + image->qvalues[table][unzigzag[i]] = + read_uint8(byte_source_input_func, source); + } + } +} + void read_sof(struct byte_source* source, struct jpeg_image* image) { unsigned len = read_uint16(byte_source_input_func, source); @@ -193,9 +221,11 @@ int main(void) /* comment */ case 0xff: /* ignore */ + skip_segment(&source); + break; case 0xdb: /* DQT */ - skip_segment(&source); + read_dqt(&source, &jpeg); break; case 0xc0: /* SOF0 (baseline DCT, Huffman encoded) */ -- 2.39.2