+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 (image->idct_data[table] != NULL) {
+ idct_choice_free(image->idct_data[table]);
+ }
+
+ 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);
+ }
+ }
+
+ image->idct_data[table] = idct_choice_alloc(image->qvalues[table]);
+}
+