diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2020-10-14 11:39:48 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2020-11-05 15:02:59 +0100 |
commit | a7e4c904b2a42a3ee79b82db49233f14208689ca (patch) | |
tree | b1810c6bf84ebb6851f229fa1972e55a88c8b844 | |
parent | b59abd05df94365b4786b5969d91f076145ecba2 (diff) |
Add 'embedded' option to JBIG2 compressed buffers.
This value needs to be passed along to the decoder, to allow it to
distinguish between naked JBIG2Decode streams in PDF and JBIG2 images
with file headers.
-rw-r--r-- | include/mupdf/fitz/compressed-buffer.h | 1 | ||||
-rw-r--r-- | include/mupdf/fitz/filter.h | 2 | ||||
-rw-r--r-- | source/fitz/compressed-buffer.c | 2 | ||||
-rw-r--r-- | source/fitz/filter-jbig2.c | 9 | ||||
-rw-r--r-- | source/pdf/pdf-stream.c | 1 |
5 files changed, 11 insertions, 4 deletions
diff --git a/include/mupdf/fitz/compressed-buffer.h b/include/mupdf/fitz/compressed-buffer.h index 2d98c10ff..e76b19c7b 100644 --- a/include/mupdf/fitz/compressed-buffer.h +++ b/include/mupdf/fitz/compressed-buffer.h | |||
@@ -23,6 +23,7 @@ typedef struct | |||
23 | } jpx; | 23 | } jpx; |
24 | struct { | 24 | struct { |
25 | fz_jbig2_globals *globals; | 25 | fz_jbig2_globals *globals; |
26 | int embedded; | ||
26 | } jbig2; | 27 | } jbig2; |
27 | struct { | 28 | struct { |
28 | int columns; | 29 | int columns; |
diff --git a/include/mupdf/fitz/filter.h b/include/mupdf/fitz/filter.h index dbcff0d02..a55514ff4 100644 --- a/include/mupdf/fitz/filter.h +++ b/include/mupdf/fitz/filter.h | |||
@@ -162,7 +162,7 @@ fz_stream *fz_open_predict(fz_context *ctx, fz_stream *chain, int predictor, int | |||
162 | Open a filter that performs jbig2 decompression on the chained | 162 | Open a filter that performs jbig2 decompression on the chained |
163 | stream, using the optional globals record. | 163 | stream, using the optional globals record. |
164 | */ | 164 | */ |
165 | fz_stream *fz_open_jbig2d(fz_context *ctx, fz_stream *chain, fz_jbig2_globals *globals); | 165 | fz_stream *fz_open_jbig2d(fz_context *ctx, fz_stream *chain, fz_jbig2_globals *globals, int embedded); |
166 | 166 | ||
167 | /** | 167 | /** |
168 | Create a jbig2 globals record from a buffer. | 168 | Create a jbig2 globals record from a buffer. |
diff --git a/source/fitz/compressed-buffer.c b/source/fitz/compressed-buffer.c index de7b8b90e..de6dd4ac6 100644 --- a/source/fitz/compressed-buffer.c +++ b/source/fitz/compressed-buffer.c | |||
@@ -69,7 +69,7 @@ fz_open_image_decomp_stream(fz_context *ctx, fz_stream *tail, fz_compression_par | |||
69 | break; | 69 | break; |
70 | 70 | ||
71 | case FZ_IMAGE_JBIG2: | 71 | case FZ_IMAGE_JBIG2: |
72 | head = fz_open_jbig2d(ctx, tail, params->u.jbig2.globals); | 72 | head = fz_open_jbig2d(ctx, tail, params->u.jbig2.globals, params->u.jbig2.embedded); |
73 | break; | 73 | break; |
74 | 74 | ||
75 | case FZ_IMAGE_RLD: | 75 | case FZ_IMAGE_RLD: |
diff --git a/source/fitz/filter-jbig2.c b/source/fitz/filter-jbig2.c index b74097852..7af2e9bb1 100644 --- a/source/fitz/filter-jbig2.c +++ b/source/fitz/filter-jbig2.c | |||
@@ -179,9 +179,10 @@ fz_drop_jbig2_globals_imp(fz_context *ctx, fz_storable *globals_) | |||
179 | } | 179 | } |
180 | 180 | ||
181 | fz_stream * | 181 | fz_stream * |
182 | fz_open_jbig2d(fz_context *ctx, fz_stream *chain, fz_jbig2_globals *globals) | 182 | fz_open_jbig2d(fz_context *ctx, fz_stream *chain, fz_jbig2_globals *globals, int embedded) |
183 | { | 183 | { |
184 | fz_jbig2d *state = NULL; | 184 | fz_jbig2d *state = NULL; |
185 | Jbig2Options options; | ||
185 | 186 | ||
186 | fz_var(state); | 187 | fz_var(state); |
187 | 188 | ||
@@ -192,7 +193,11 @@ fz_open_jbig2d(fz_context *ctx, fz_stream *chain, fz_jbig2_globals *globals) | |||
192 | state->alloc.alloc.free = fz_jbig2_free; | 193 | state->alloc.alloc.free = fz_jbig2_free; |
193 | state->alloc.alloc.realloc = fz_jbig2_realloc; | 194 | state->alloc.alloc.realloc = fz_jbig2_realloc; |
194 | 195 | ||
195 | state->ctx = jbig2_ctx_new((Jbig2Allocator *) &state->alloc, JBIG2_OPTIONS_EMBEDDED, globals ? globals->gctx : NULL, error_callback, ctx); | 196 | options = 0; |
197 | if (embedded) | ||
198 | options |= JBIG2_OPTIONS_EMBEDDED; | ||
199 | |||
200 | state->ctx = jbig2_ctx_new((Jbig2Allocator *) &state->alloc, options, globals ? globals->gctx : NULL, error_callback, ctx); | ||
196 | if (state->ctx == NULL) | 201 | if (state->ctx == NULL) |
197 | { | 202 | { |
198 | fz_drop_jbig2_globals(ctx, state->gctx); | 203 | fz_drop_jbig2_globals(ctx, state->gctx); |
diff --git a/source/pdf/pdf-stream.c b/source/pdf/pdf-stream.c index 6c5643455..f19219542 100644 --- a/source/pdf/pdf-stream.c +++ b/source/pdf/pdf-stream.c | |||
@@ -158,6 +158,7 @@ build_compression_params(fz_context *ctx, pdf_obj *f, pdf_obj *p, fz_compression | |||
158 | 158 | ||
159 | params->type = FZ_IMAGE_JBIG2; | 159 | params->type = FZ_IMAGE_JBIG2; |
160 | params->u.jbig2.globals = NULL; | 160 | params->u.jbig2.globals = NULL; |
161 | params->u.jbig2.embedded = 1; /* jbig2 streams are always embedded without file headers */ | ||
161 | if (g) | 162 | if (g) |
162 | { | 163 | { |
163 | if (!pdf_is_stream(ctx, g)) | 164 | if (!pdf_is_stream(ctx, g)) |