diff options
author | Simon Bünzli <zeniko@gmail.com> | 2013-08-30 16:07:53 +0200 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-09-10 14:09:02 +0100 |
commit | fa56dd76da7aa65862ee1db0b1147c899f2e8144 (patch) | |
tree | f94efe8801a8137cb159ca967e972344ce340020 | |
parent | 527afcaa0744472d7ad2ef84ce79ab34a036ad85 (diff) | |
download | mupdf-fa56dd76da7aa65862ee1db0b1147c899f2e8144.tar.xz |
support jpegtables for TIFF images
This is required e.g. for 2314 - jpeg tables in tiff.xps.
This folds fz_open_resized_dct back into fz_open_dct instead of adding
further variations for calls with and without the jpegtables argument.
-rw-r--r-- | include/mupdf/fitz/filter.h | 3 | ||||
-rw-r--r-- | source/fitz/compressed-buffer.c | 2 | ||||
-rw-r--r-- | source/fitz/filter-dct.c | 48 | ||||
-rw-r--r-- | source/fitz/load-tiff.c | 7 | ||||
-rw-r--r-- | source/pdf/pdf-stream.c | 2 |
5 files changed, 38 insertions, 24 deletions
diff --git a/include/mupdf/fitz/filter.h b/include/mupdf/fitz/filter.h index a0a470b9..0a62fb2d 100644 --- a/include/mupdf/fitz/filter.h +++ b/include/mupdf/fitz/filter.h @@ -15,8 +15,7 @@ fz_stream *fz_open_aesd(fz_stream *chain, unsigned char *key, unsigned keylen); fz_stream *fz_open_a85d(fz_stream *chain); fz_stream *fz_open_ahxd(fz_stream *chain); fz_stream *fz_open_rld(fz_stream *chain); -fz_stream *fz_open_dctd(fz_stream *chain, int color_transform); -fz_stream *fz_open_resized_dctd(fz_stream *chain, int color_transform, int l2factor); +fz_stream *fz_open_dctd(fz_stream *chain, int color_transform, int l2factor, fz_stream *jpegtables); fz_stream *fz_open_faxd(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); diff --git a/source/fitz/compressed-buffer.c b/source/fitz/compressed-buffer.c index acdf2747..e62feee0 100644 --- a/source/fitz/compressed-buffer.c +++ b/source/fitz/compressed-buffer.c @@ -34,7 +34,7 @@ fz_open_image_decomp_stream(fz_context *ctx, fz_compressed_buffer *buffer, int * case FZ_IMAGE_JPEG: if (*l2factor > 3) *l2factor = 3; - return fz_open_resized_dctd(chain, params->u.jpeg.color_transform, *l2factor); + return fz_open_dctd(chain, params->u.jpeg.color_transform, *l2factor, NULL); case FZ_IMAGE_RLD: *l2factor = 0; return fz_open_rld(chain); diff --git a/source/fitz/filter-dct.c b/source/fitz/filter-dct.c index 189d2aae..adc3206c 100644 --- a/source/fitz/filter-dct.c +++ b/source/fitz/filter-dct.c @@ -8,6 +8,8 @@ typedef struct fz_dctd_s fz_dctd; struct fz_dctd_s { fz_stream *chain; + fz_stream *jpegtables; + fz_stream *curr_stm; fz_context *ctx; int color_transform; int init; @@ -43,21 +45,21 @@ static boolean fill_input_buffer(j_decompress_ptr cinfo) { struct jpeg_source_mgr *src = cinfo->src; fz_dctd *state = cinfo->client_data; - fz_stream *chain = state->chain; - fz_context *ctx = chain->ctx; + fz_stream *curr_stm = state->curr_stm; + fz_context *ctx = curr_stm->ctx; - chain->rp = chain->wp; + curr_stm->rp = curr_stm->wp; fz_try(ctx) { - fz_fill_buffer(chain); + fz_fill_buffer(curr_stm); } fz_catch(ctx) { fz_rethrow_if(ctx, FZ_ERROR_TRYLATER); return 0; } - src->next_input_byte = chain->rp; - src->bytes_in_buffer = chain->wp - chain->rp; + src->next_input_byte = curr_stm->rp; + src->bytes_in_buffer = curr_stm->wp - curr_stm->rp; if (src->bytes_in_buffer == 0) { @@ -96,7 +98,7 @@ read_dctd(fz_stream *stm, unsigned char *buf, int len) if (setjmp(state->jb)) { if (cinfo->src) - state->chain->rp = state->chain->wp - cinfo->src->bytes_in_buffer; + state->curr_stm->rp = state->curr_stm->wp - cinfo->src->bytes_in_buffer; fz_throw(stm->ctx, FZ_ERROR_GENERIC, "jpeg error: %s", state->msg); } @@ -120,8 +122,20 @@ read_dctd(fz_stream *stm, unsigned char *buf, int len) cinfo->src->skip_input_data = skip_input_data; cinfo->src->resync_to_restart = jpeg_resync_to_restart; cinfo->src->term_source = term_source; - cinfo->src->next_input_byte = state->chain->rp; - cinfo->src->bytes_in_buffer = state->chain->wp - state->chain->rp; + + /* optionally load additional JPEG tables first */ + if (state->jpegtables) + { + state->curr_stm = state->jpegtables; + cinfo->src->next_input_byte = state->curr_stm->rp; + cinfo->src->bytes_in_buffer = state->curr_stm->wp - state->curr_stm->rp; + jpeg_read_header(cinfo, 0); + state->curr_stm->rp = state->curr_stm->wp - state->cinfo.src->bytes_in_buffer; + state->curr_stm = state->chain; + } + + cinfo->src->next_input_byte = state->curr_stm->rp; + cinfo->src->bytes_in_buffer = state->curr_stm->wp - state->curr_stm->rp; jpeg_read_header(cinfo, 1); @@ -212,24 +226,19 @@ close_dctd(fz_context *ctx, void *state_) skip: if (state->cinfo.src) - state->chain->rp = state->chain->wp - state->cinfo.src->bytes_in_buffer; + state->curr_stm->rp = state->curr_stm->wp - state->cinfo.src->bytes_in_buffer; if (state->init) jpeg_destroy_decompress(&state->cinfo); fz_free(ctx, state->scanline); fz_close(state->chain); + fz_close(state->jpegtables); fz_free(ctx, state); } -/* Default: color_transform = -1 (unset) */ -fz_stream * -fz_open_dctd(fz_stream *chain, int color_transform) -{ - return fz_open_resized_dctd(chain, color_transform, 0); -} - +/* Default: color_transform = -1 (unset), l2factor = 0, jpegtables = NULL */ fz_stream * -fz_open_resized_dctd(fz_stream *chain, int color_transform, int l2factor) +fz_open_dctd(fz_stream *chain, int color_transform, int l2factor, fz_stream *jpegtables) { fz_context *ctx = chain->ctx; fz_dctd *state = NULL; @@ -241,6 +250,8 @@ fz_open_resized_dctd(fz_stream *chain, int color_transform, int l2factor) state = fz_malloc_struct(chain->ctx, fz_dctd); state->ctx = ctx; state->chain = chain; + state->jpegtables = jpegtables; + state->curr_stm = chain; state->color_transform = color_transform; state->init = 0; state->l2factor = l2factor; @@ -249,6 +260,7 @@ fz_open_resized_dctd(fz_stream *chain, int color_transform, int l2factor) { fz_free(ctx, state); fz_close(chain); + fz_close(jpegtables); fz_rethrow(ctx); } diff --git a/source/fitz/load-tiff.c b/source/fitz/load-tiff.c index a7d10d00..fbe84740 100644 --- a/source/fitz/load-tiff.c +++ b/source/fitz/load-tiff.c @@ -186,7 +186,11 @@ fz_decode_tiff_fax(struct tiff *tiff, int comp, fz_stream *chain, unsigned char static void fz_decode_tiff_jpeg(struct tiff *tiff, fz_stream *chain, unsigned char *wp, int wlen) { - fz_stream *stm = fz_open_dctd(chain, -1); + fz_stream *stm; + fz_stream *jpegtables = NULL; + if (tiff->jpegtables && (int)tiff->jpegtableslen > 0) + jpegtables = fz_open_memory(tiff->ctx, tiff->jpegtables, (int)tiff->jpegtableslen); + stm = fz_open_dctd(chain, -1, 0, jpegtables); fz_read(stm, wp, wlen); fz_close(stm); } @@ -660,7 +664,6 @@ fz_read_tiff_tag(struct tiff *tiff, unsigned offset) break; case JPEGTables: - fz_warn(tiff->ctx, "jpeg tables in tiff not implemented"); tiff->jpegtables = tiff->bp + value; tiff->jpegtableslen = count; break; diff --git a/source/pdf/pdf-stream.c b/source/pdf/pdf-stream.c index 88a7559f..bf7f64f2 100644 --- a/source/pdf/pdf-stream.c +++ b/source/pdf/pdf-stream.c @@ -108,7 +108,7 @@ build_filter(fz_stream *chain, pdf_document *doc, pdf_obj *f, pdf_obj *p, int nu params->u.jpeg.color_transform = (ct ? pdf_to_int(ct) : -1); return chain; } - return fz_open_dctd(chain, ct ? pdf_to_int(ct) : -1); + return fz_open_dctd(chain, ct ? pdf_to_int(ct) : -1, 0, NULL); } else if (!strcmp(s, "RunLengthDecode") || !strcmp(s, "RL")) |