From 8389f95d5750d6fcb202181005954829e64865b4 Mon Sep 17 00:00:00 2001 From: "sgunderson@bigfoot.com" <> Date: Mon, 1 Jun 2009 00:38:50 +0200 Subject: [PATCH] Save one refill from inner coefficient-reading loop. --- dehuff.h | 13 ++++++++++--- driver.c | 7 ++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/dehuff.h b/dehuff.h index a6a431a..9243e10 100644 --- a/dehuff.h +++ b/dehuff.h @@ -48,10 +48,10 @@ void read_huffman_tables(huffman_tables_t* dst, input_func_t* input_func, void* 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]; @@ -65,6 +65,13 @@ static inline unsigned read_huffman_symbol(const struct huffman_table* table, 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)). diff --git a/driver.c b/driver.c index 04e2369..6db737f 100644 --- a/driver.c +++ b/driver.c @@ -164,7 +164,7 @@ void read_scan(struct byte_source* source, struct jpeg_image* image, huffman_tab // 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 }; @@ -172,7 +172,7 @@ void read_scan(struct byte_source* source, struct jpeg_image* image, huffman_tab // 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; @@ -182,12 +182,13 @@ void read_scan(struct byte_source* source, struct jpeg_image* image, huffman_tab } 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); } -- 2.39.2