]> git.sesse.net Git - fjl/blobdiff - driver.c
Get rid of AC_SIXTEEN_ZEROS.
[fjl] / driver.c
index cda257e3c90ba023ed8b465eeedf2e1417768aff..f24b0f50964d18d4271fc1f104f59597f9928f4f 100644 (file)
--- 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];
-               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) {
-                               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 {
-                       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);
                        if (code == AC_END_OF_BLOCK) {
                                break;
                        }
-                       if (code == AC_SIXTEEN_ZEROS) {
-                               continue;
-                       }
                        coeff[unzigzag[i]] = code;
                }
        }