diff options
author | Tor Andersson <tor@ghostscript.com> | 2011-02-23 23:44:10 +0000 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2011-02-23 23:44:10 +0000 |
commit | bdf838fae7d9dbba45163521efb80348a1741298 (patch) | |
tree | 9afe343ffa6e66267f9c62a4e84e8521840ba4c4 /fitz | |
parent | 7aab191974af3c05d8c2d6595378f6c6e7899b3e (diff) | |
download | mupdf-bdf838fae7d9dbba45163521efb80348a1741298.tar.xz |
Use readbits function in LZW decoder.
Diffstat (limited to 'fitz')
-rw-r--r-- | fitz/filt_lzwd.c | 48 |
1 files changed, 6 insertions, 42 deletions
diff --git a/fitz/filt_lzwd.c b/fitz/filt_lzwd.c index f03c28bc..5d2bd663 100644 --- a/fitz/filt_lzwd.c +++ b/fitz/filt_lzwd.c @@ -32,38 +32,17 @@ struct fz_lzwd_s int earlychange; - unsigned int word; /* bits loaded from data */ - int bidx; - int codebits; /* num bits/code */ int code; /* current code */ int oldcode; /* previously recognized code */ int nextcode; /* next free entry */ + lzw_code table[NUMCODES]; unsigned char bp[MAXLENGTH]; unsigned char *rp, *wp; }; -static inline void eatbits(fz_lzwd *lzw, int nbits) -{ - lzw->word <<= nbits; - lzw->bidx += nbits; -} - -static inline int fillbits(fz_lzwd *lzw) -{ - while (lzw->bidx >= 8) - { - int c = fz_readbyte(lzw->chain); - if (c == EOF) - return EOF; - lzw->bidx -= 8; - lzw->word |= c << lzw->bidx; - } - return 0; -} - static int readlzwd(fz_stream *stm, unsigned char *buf, int len) { @@ -87,19 +66,14 @@ readlzwd(fz_stream *stm, unsigned char *buf, int len) if (lzw->eod) return 0; - if (fillbits(lzw)) + code = fz_readbits(lzw->chain, codebits); + + if (fz_peekbyte(lzw->chain) == EOF) { - if (lzw->bidx > 32 - codebits) - { - lzw->eod = 1; - break; - } + lzw->eod = 1; + break; } - code = lzw->word >> (32 - codebits); - code &= (1 << codebits) - 1; - eatbits(lzw, codebits); - if (code == LZW_EOD) { lzw->eod = 1; @@ -185,13 +159,6 @@ static void closelzwd(fz_stream *stm) { fz_lzwd *lzw = stm->state; - int i; - - /* if we read any extra bytes, try to put them back */ - i = (32 - lzw->bidx) / 8; - while (i--) - fz_unreadbyte(lzw->chain); - fz_close(lzw->chain); fz_free(lzw); } @@ -212,9 +179,6 @@ fz_openlzwd(fz_stream *chain, fz_obj *params) if (obj) lzw->earlychange = !!fz_toint(obj); - lzw->bidx = 32; - lzw->word = 0; - for (i = 0; i < 256; i++) { lzw->table[i].value = i; |