X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=driver.c;h=f24b0f50964d18d4271fc1f104f59597f9928f4f;hb=8326dff1cbad02c5d660696648e15a0f575c9afd;hp=c5ae87e3b003cc2b060ccfe3fa1571ff817a2246;hpb=a1596fbb6a92217ff5eb57600b36a9d695ca1ae8;p=fjl diff --git a/driver.c b/driver.c index c5ae87e..f24b0f5 100644 --- a/driver.c +++ b/driver.c @@ -116,45 +116,38 @@ void read_sof(struct byte_source* source, struct jpeg_image* image) void decode_ac_coefficients(const struct huffman_table* tbl, struct bit_source* bits, int16_t* coeff) { - for (unsigned i = 1; i < DCTSIZE2; ++i) { + for (unsigned i = 0; i < DCTSIZE2 - 1; ) { possibly_refill(bits, DEHUF_AC_TABLE_BITS); unsigned lookup = peek_bits(bits, DEHUF_AC_TABLE_BITS); int code = tbl->ac_table_codes[lookup]; - assert(length == AC_DEHUF_SLOW_PATH || (length > 0 && length <= DEHUF_AC_TABLE_BITS)); - if (__builtin_expect(code == AC_DEHUF_SLOW_PATH, 0)) { unsigned rs = read_huffman_symbol_no_refill(tbl, bits); unsigned r = rs >> 4; unsigned s = rs & 0xf; - i += r; + i += r + 1; possibly_refill(bits, s); if (rs == 0x00) { - assert(code == AC_DEHUF_SLOW_PATH || code == AC_END_OF_BLOCK); /* end of block */ break; } if (rs == 0xf0) { - assert(code == AC_DEHUF_SLOW_PATH || code == AC_SIXTEEN_ZEROS); /* 16 zero coefficients */ continue; } coeff[unzigzag[i]] = extend(read_bits(bits, s), s); } else { - int length = tbl->ac_table_length[lookup]; + unsigned length = tbl->ac_table_length[lookup]; int r = tbl->ac_table_skip[lookup]; - assert(r >= 0); + assert(r >= 1); i += r; assert(bits->bits_available >= length); read_bits(bits, length); if (code == AC_END_OF_BLOCK) { break; } - if (code == AC_SIXTEEN_ZEROS) { - continue; - } coeff[unzigzag[i]] = code; } }