X-Git-Url: https://git.sesse.net/?p=fjl;a=blobdiff_plain;f=driver.c;h=6db737ff7d585033109f1ba58253c71e500cd83d;hp=04e236912ca45d56bc4f1a34f16b3c04185112d9;hb=8389f95d5750d6fcb202181005954829e64865b4;hpb=fde0dcd1b9f8b92cc564f485ad0952461463c0eb diff --git a/driver.c b/driver.c index 04e2369..6db737f 100644 --- a/driver.c +++ b/driver.c @@ -164,7 +164,7 @@ void read_scan(struct byte_source* source, struct jpeg_image* image, huffman_tab // decode DC component unsigned dc_category = read_huffman_symbol(dc_table, &bits); - possibly_refill(&bits, dc_category); + possibly_refill(&bits, dc_category + DEHUF_TABLE_BITS); last_dc[c] += extend(read_bits(&bits, dc_category), dc_category); int16_t coeff[DCTSIZE2] = { 0 }; @@ -172,7 +172,7 @@ void read_scan(struct byte_source* source, struct jpeg_image* image, huffman_tab // decode AC components for (unsigned i = 1; i < DCTSIZE2; ++i) { - unsigned rs = read_huffman_symbol(ac_table, &bits); + unsigned rs = read_huffman_symbol_no_refill(ac_table, &bits); unsigned r = rs >> 4; unsigned s = rs & 0xf; @@ -182,12 +182,13 @@ void read_scan(struct byte_source* source, struct jpeg_image* image, huffman_tab } if (rs == 0xf0) { /* 16 zero coefficients */ + possibly_refill(&bits, DEHUF_TABLE_BITS); i += 15; continue; } i += r; - possibly_refill(&bits, s); + possibly_refill(&bits, s + DEHUF_TABLE_BITS); coeff[unzigzag[i]] = extend(read_bits(&bits, s), s); }