unsigned read_huffman_symbol_slow_path(const struct huffman_table* table,
struct bit_source* source);
-static inline unsigned read_huffman_symbol(const struct huffman_table* table,
- struct bit_source* source)
+static inline unsigned read_huffman_symbol_no_refill(
+ const struct huffman_table* table,
+ struct bit_source* source)
{
- possibly_refill(source, DEHUF_TABLE_BITS);
assert(source->bits_available >= DEHUF_TABLE_BITS);
unsigned lookup = peek_bits(source, DEHUF_TABLE_BITS);
int code = table->lookup_table_codes[lookup];
return code;
}
+static inline unsigned read_huffman_symbol(const struct huffman_table* table,
+ struct bit_source* source)
+{
+ possibly_refill(source, DEHUF_TABLE_BITS);
+ return read_huffman_symbol_no_refill(table, source);
+}
+
// procedure EXTEND (figure F.12)
// Fast lookup table for (1 << (bits - 1)).
// 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 };
// 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;
}
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);
}