]> git.sesse.net Git - fjl/blobdiff - driver.c
Kill AC_END_OF_BLOCK as well.
[fjl] / driver.c
index f24b0f50964d18d4271fc1f104f59597f9928f4f..f07e63e2679edc37263dddeafeb3a71071d712c0 100644 (file)
--- a/driver.c
+++ b/driver.c
@@ -116,38 +116,33 @@ 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)
 {
+       possibly_refill(bits, DEHUF_AC_TABLE_BITS);
        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];
+               unsigned length = tbl->ac_table_length[lookup];
+               unsigned r = tbl->ac_table_skip[lookup];
 
                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 + 1;
-                       possibly_refill(bits, s);
-
                        if (rs == 0x00) {
                                /* end of block */
                                break;
                        }
-                       if (rs == 0xf0) {
-                               /* 16 zero coefficients */
-                               continue;
-                       }
 
+                       unsigned r = rs >> 4;
+                       unsigned s = rs & 0xf;
+                       i += r + 1;
+                       possibly_refill(bits, s);
                        coeff[unzigzag[i]] = extend(read_bits(bits, s), s);
+                       possibly_refill(bits, DEHUF_AC_TABLE_BITS);
                } else {
-                       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;
-                       }
+                       possibly_refill(bits, DEHUF_AC_TABLE_BITS);
+
+                       assert(r >= 1);
+                       i += r;
                        coeff[unzigzag[i]] = code;
                }
        }