Remove an increment from the fast path of the AC coefficient decoding.
authorSteinar H. Gunderson <sesse@debian.org>
Mon, 1 Jun 2009 17:08:00 +0000 (19:08 +0200)
committerSteinar H. Gunderson <sesse@debian.org>
Mon, 1 Jun 2009 17:08:00 +0000 (19:08 +0200)
dehuff.c
driver.c

index 50fb53e..8cdc2c8 100644 (file)
--- a/dehuff.c
+++ b/dehuff.c
@@ -135,14 +135,14 @@ void read_huffman_tables(huffman_tables_t* dst, input_func_t* input_func, void*
                                // End of block.
                                tbl->ac_table_codes[i] = AC_END_OF_BLOCK;
                                tbl->ac_table_length[i] = length;
-                               tbl->ac_table_skip[i] = 0;
+                               tbl->ac_table_skip[i] = 1;
                                continue;
                        }
                        if (rs == 0xf0) {
                                // 16 zero coefficients.
                                tbl->ac_table_codes[i] = AC_SIXTEEN_ZEROS;
                                tbl->ac_table_length[i] = length;
-                               tbl->ac_table_skip[i] = 15;
+                               tbl->ac_table_skip[i] = 16;
                                continue;
                        }
                        
@@ -157,7 +157,7 @@ void read_huffman_tables(huffman_tables_t* dst, input_func_t* input_func, void*
 
                        tbl->ac_table_codes[i] = extend(bits, s);
                        tbl->ac_table_length[i] = length + s;
-                       tbl->ac_table_skip[i] = r;
+                       tbl->ac_table_skip[i] = r + 1;
 
                        assert(tbl->ac_table_length[i] <= DEHUF_AC_TABLE_BITS);
                }       
index 6dcc8b3..fcd9f7f 100644 (file)
--- 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,7 +125,7 @@ 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) {
@@ -143,7 +143,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);