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];
- int length = tbl->ac_table_length[lookup];
- int r = tbl->ac_table_skip[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) {
coeff[unzigzag[i]] = extend(read_bits(bits, s), s);
} else {
- assert(r >= 0);
+ unsigned length = tbl->ac_table_length[lookup];
+ int r = tbl->ac_table_skip[lookup];
+ assert(r >= 1);
i += r;
assert(bits->bits_available >= length);
read_bits(bits, length);