diff options
author | dcommander <dcommander@632fc199-4ca6-4c93-a231-07263d6284db> | 2009-09-28 00:33:02 +0000 |
---|---|---|
committer | dcommander <dcommander@632fc199-4ca6-4c93-a231-07263d6284db> | 2009-09-28 00:33:02 +0000 |
commit | e0e0919c7f28a6b4a0077f41ebb13f79cb05059b (patch) | |
tree | 2d036ab8281184b6c562c45d97cb989caf37bcd7 /jdhuff.h | |
parent | 01d039fd938c51991a5c62ad1bf31ac188e140d1 (diff) |
Greatly improve performance of Huffman decoding
git-svn-id: svn://svn.code.sf.net/p/libjpeg-turbo/code/trunk@64 632fc199-4ca6-4c93-a231-07263d6284db
Diffstat (limited to 'jdhuff.h')
-rw-r--r-- | jdhuff.h | 21 |
1 files changed, 12 insertions, 9 deletions
@@ -36,13 +36,17 @@ typedef struct { /* Link to public Huffman table (needed only in jpeg_huff_decode) */ JHUFF_TBL *pub; - /* Lookahead tables: indexed by the next HUFF_LOOKAHEAD bits of + /* Lookahead table: indexed by the next HUFF_LOOKAHEAD bits of * the input data stream. If the next Huffman code is no more * than HUFF_LOOKAHEAD bits long, we can obtain its length and - * the corresponding symbol directly from these tables. + * the corresponding symbol directly from this tables. + * + * The lower 8 bits of each table entry contain the number of + * bits in the corresponding Huffman code, or HUFF_LOOKAHEAD + 1 + * if too long. The next 8 bits of each entry contain the + * symbol. */ - int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */ - UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */ + int lookup[1<<HUFF_LOOKAHEAD]; } d_derived_tbl; /* Expand a Huffman table definition into the derived format */ @@ -69,8 +73,8 @@ EXTERN(void) jpeg_make_d_derived_tbl * necessary. */ -typedef INT32 bit_buf_type; /* type of bit-extraction buffer */ -#define BIT_BUF_SIZE 32 /* size of buffer in bits */ +typedef long bit_buf_type; /* type of bit-extraction buffer */ +#define BIT_BUF_SIZE __WORDSIZE /* size of buffer in bits */ /* If long is > 32 bits on your machine, and shifting/masking longs is * reasonably fast, making bit_buf_type be long and setting BIT_BUF_SIZE @@ -183,11 +187,10 @@ EXTERN(boolean) jpeg_fill_bit_buffer } \ } \ look = PEEK_BITS(HUFF_LOOKAHEAD); \ - if ((nb = htbl->look_nbits[look]) != 0) { \ + if ((nb = (htbl->lookup[look] >> HUFF_LOOKAHEAD)) <= HUFF_LOOKAHEAD) { \ DROP_BITS(nb); \ - result = htbl->look_sym[look]; \ + result = htbl->lookup[look] & ((1 << HUFF_LOOKAHEAD) - 1); \ } else { \ - nb = HUFF_LOOKAHEAD+1; \ slowlabel: \ if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \ { failaction; } \ |