diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2018-05-16 12:35:34 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2018-05-16 12:48:07 +0200 |
commit | 43fa518a6981e2b392b1c11fa547d12ee300c62e (patch) | |
tree | f12444aac44aa8c5065555ed9f475231ce41b18f /source | |
parent | 085b6f8a6c2519c132dc328e5a73da334f3bd16d (diff) | |
download | mupdf-43fa518a6981e2b392b1c11fa547d12ee300c62e.tar.xz |
Keep JBIG2 image data compressed in fz_compressed_buffer.
Diffstat (limited to 'source')
-rw-r--r-- | source/fitz/compressed-buffer.c | 6 | ||||
-rw-r--r-- | source/fitz/filter-jbig2.c | 16 | ||||
-rw-r--r-- | source/pdf/pdf-stream.c | 29 |
3 files changed, 36 insertions, 15 deletions
diff --git a/source/fitz/compressed-buffer.c b/source/fitz/compressed-buffer.c index e8ea08e0..35b0868b 100644 --- a/source/fitz/compressed-buffer.c +++ b/source/fitz/compressed-buffer.c @@ -8,6 +8,8 @@ fz_drop_compressed_buffer(fz_context *ctx, fz_compressed_buffer *buf) { if (buf) { + if (buf->params.type == FZ_IMAGE_JBIG2) + fz_drop_jbig2_globals(ctx, buf->params.u.jbig2.globals); fz_drop_buffer(ctx, buf->buffer); fz_free(ctx, buf); } @@ -66,6 +68,10 @@ fz_open_image_decomp_stream(fz_context *ctx, fz_stream *tail, fz_compression_par head = fz_open_dctd(ctx, tail, params->u.jpeg.color_transform, our_l2factor, NULL); break; + case FZ_IMAGE_JBIG2: + head = fz_open_jbig2d(ctx, tail, fz_keep_jbig2_globals(ctx, params->u.jbig2.globals)); + break; + case FZ_IMAGE_RLD: head = fz_open_rld(ctx, tail); break; diff --git a/source/fitz/filter-jbig2.c b/source/fitz/filter-jbig2.c index 0d581b95..599f94c0 100644 --- a/source/fitz/filter-jbig2.c +++ b/source/fitz/filter-jbig2.c @@ -28,7 +28,13 @@ struct fz_jbig2d_s int idx; }; -static void +fz_jbig2_globals * +fz_keep_jbig2_globals(fz_context *ctx, fz_jbig2_globals *globals) +{ + return fz_keep_storable(ctx, &globals->storable); +} + +void fz_drop_jbig2_globals(fz_context *ctx, fz_jbig2_globals *globals) { fz_drop_storable(ctx, &globals->storable); @@ -268,7 +274,13 @@ struct fz_jbig2d_s unsigned char buffer[4096]; }; -static void +fz_jbig2_globals * +fz_keep_jbig2_globals(fz_context *ctx, fz_jbig2_globals *globals) +{ + return fz_keep_storable(ctx, &globals->storable); +} + +void fz_drop_jbig2_globals(fz_context *ctx, fz_jbig2_globals *globals) { fz_drop_storable(ctx, &globals->storable); diff --git a/source/pdf/pdf-stream.c b/source/pdf/pdf-stream.c index 839f9b5e..04f1ed46 100644 --- a/source/pdf/pdf-stream.c +++ b/source/pdf/pdf-stream.c @@ -58,7 +58,7 @@ pdf_stream_has_crypt(fz_context *ctx, pdf_obj *stm) } static fz_jbig2_globals * -pdf_load_jbig2_globals(fz_context *ctx, pdf_document *doc, pdf_obj *dict) +pdf_load_jbig2_globals(fz_context *ctx, pdf_obj *dict) { fz_jbig2_globals *globals; fz_buffer *buf = NULL; @@ -149,6 +149,20 @@ build_compression_params(fz_context *ctx, pdf_obj *f, pdf_obj *p, fz_compression params->u.lzw.bpc = bpc; params->u.lzw.early_change = (ec ? pdf_to_int(ctx, ec) : 1); } + else if (pdf_name_eq(ctx, f, PDF_NAME(JBIG2Decode))) + { + pdf_obj *g = pdf_dict_get(ctx, p, PDF_NAME(JBIG2Globals)); + + params->type = FZ_IMAGE_JBIG2; + params->u.jbig2.globals = NULL; + if (g) + { + if (!pdf_is_stream(ctx, g)) + fz_warn(ctx, "jbig2 globals is not a stream, skipping globals"); + else + params->u.jbig2.globals = pdf_load_jbig2_globals(ctx, g); + } + } } /* @@ -180,18 +194,7 @@ build_filter(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_obj *f, p return fz_open_a85d(ctx, chain); else if (pdf_name_eq(ctx, f, PDF_NAME(JBIG2Decode))) - { - fz_jbig2_globals *globals = NULL; - pdf_obj *obj = pdf_dict_get(ctx, p, PDF_NAME(JBIG2Globals)); - if (obj) - { - if (!pdf_is_stream(ctx, obj)) - fz_warn(ctx, "jbig2 globals is not a stream, skipping globals"); - else - globals = pdf_load_jbig2_globals(ctx, doc, obj); - } - return fz_open_jbig2d(ctx, chain, globals); /* takes ownership of jbig2_globals */ - } + return fz_open_jbig2d(ctx, chain, params->u.jbig2.globals); /* takes ownership of jbig2_globals */ else if (pdf_name_eq(ctx, f, PDF_NAME(JPXDecode))) return fz_keep_stream(ctx, chain); /* JPX decoding is special cased in the image loading code */ |