summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mupdf/fitz/filter.h2
-rw-r--r--source/fitz/compressed-buffer.c2
-rw-r--r--source/fitz/filter-lzw.c9
-rw-r--r--source/fitz/load-tiff.c2
4 files changed, 10 insertions, 5 deletions
diff --git a/include/mupdf/fitz/filter.h b/include/mupdf/fitz/filter.h
index 8926d65d..8d5c6eb2 100644
--- a/include/mupdf/fitz/filter.h
+++ b/include/mupdf/fitz/filter.h
@@ -23,7 +23,7 @@ fz_stream *fz_open_faxd(fz_context *ctx, fz_stream *chain,
int k, int end_of_line, int encoded_byte_align,
int columns, int rows, int end_of_block, int black_is_1);
fz_stream *fz_open_flated(fz_context *ctx, fz_stream *chain, int window_bits);
-fz_stream *fz_open_lzwd(fz_context *ctx, fz_stream *chain, int early_change, int min_bits);
+fz_stream *fz_open_lzwd(fz_context *ctx, fz_stream *chain, int early_change, int min_bits, int reverse_bits);
fz_stream *fz_open_predict(fz_context *ctx, fz_stream *chain, int predictor, int columns, int colors, int bpc);
fz_stream *fz_open_jbig2d(fz_context *ctx, fz_stream *chain, fz_jbig2_globals *globals);
diff --git a/source/fitz/compressed-buffer.c b/source/fitz/compressed-buffer.c
index 2dbdc694..db1225e4 100644
--- a/source/fitz/compressed-buffer.c
+++ b/source/fitz/compressed-buffer.c
@@ -54,7 +54,7 @@ fz_open_image_decomp_stream(fz_context *ctx, fz_stream *chain, fz_compression_pa
chain = fz_open_predict(ctx, chain, params->u.flate.predictor, params->u.flate.columns, params->u.flate.colors, params->u.flate.bpc);
return chain;
case FZ_IMAGE_LZW:
- chain = fz_open_lzwd(ctx, chain, params->u.lzw.early_change, 9);
+ chain = fz_open_lzwd(ctx, chain, params->u.lzw.early_change, 9, 0);
if (params->u.lzw.predictor > 1)
chain = fz_open_predict(ctx, chain, params->u.lzw.predictor, params->u.lzw.columns, params->u.lzw.colors, params->u.lzw.bpc);
return chain;
diff --git a/source/fitz/filter-lzw.c b/source/fitz/filter-lzw.c
index ddc11f20..ff655c9e 100644
--- a/source/fitz/filter-lzw.c
+++ b/source/fitz/filter-lzw.c
@@ -32,6 +32,7 @@ struct fz_lzwd_s
int early_change;
+ int reverse_bits;
int min_bits; /* minimum num bits/code */
int code_bits; /* num bits/code */
int code; /* current code */
@@ -74,7 +75,10 @@ next_lzwd(fz_context *ctx, fz_stream *stm, int len)
if (lzw->eod)
return EOF;
- code = fz_read_bits(ctx, lzw->chain, code_bits);
+ if (lzw->reverse_bits)
+ code = fz_read_rbits(ctx, lzw->chain, code_bits);
+ else
+ code = fz_read_bits(ctx, lzw->chain, code_bits);
if (fz_is_eof_bits(ctx, lzw->chain))
{
@@ -196,7 +200,7 @@ close_lzwd(fz_context *ctx, void *state_)
/* Default: early_change = 1 */
fz_stream *
-fz_open_lzwd(fz_context *ctx, fz_stream *chain, int early_change, int min_bits)
+fz_open_lzwd(fz_context *ctx, fz_stream *chain, int early_change, int min_bits, int reverse_bits)
{
fz_lzwd *lzw = NULL;
int i;
@@ -215,6 +219,7 @@ fz_open_lzwd(fz_context *ctx, fz_stream *chain, int early_change, int min_bits)
lzw->chain = chain;
lzw->eod = 0;
lzw->early_change = early_change;
+ lzw->reverse_bits = reverse_bits;
lzw->min_bits = min_bits;
lzw->code_bits = lzw->min_bits;
lzw->code = -1;
diff --git a/source/fitz/load-tiff.c b/source/fitz/load-tiff.c
index c2799f7c..16d9908e 100644
--- a/source/fitz/load-tiff.c
+++ b/source/fitz/load-tiff.c
@@ -157,7 +157,7 @@ fz_decode_tiff_packbits(fz_context *ctx, struct tiff *tiff, fz_stream *chain, un
static void
fz_decode_tiff_lzw(fz_context *ctx, struct tiff *tiff, fz_stream *chain, unsigned char *wp, int wlen)
{
- fz_stream *stm = fz_open_lzwd(ctx, chain, 1, 9);
+ fz_stream *stm = fz_open_lzwd(ctx, chain, 1, 9, 0);
fz_read(ctx, stm, wp, wlen);
fz_drop_stream(ctx, stm);
}