X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=driver.c;h=e8a78e021fcbf03016a340ebc54861158dfe3b37;hb=aaa51b9ca2687377006a7d850079bdc501efee65;hp=6dcc8b3da676161ecd60e05898a27ebe3d19bf3f;hpb=707b73cb6536bc977eaca6033a93a749c4d89b19;p=fjl diff --git a/driver.c b/driver.c index 6dcc8b3..e8a78e0 100644 --- a/driver.c +++ b/driver.c @@ -116,7 +116,7 @@ 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]; @@ -125,16 +125,14 @@ void decode_ac_coefficients(const struct huffman_table* tbl, struct bit_source* 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; } @@ -143,7 +141,7 @@ void decode_ac_coefficients(const struct huffman_table* tbl, struct bit_source* } else { 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);