diff options
-rw-r--r-- | fitz/filt_dctd.c | 12 | ||||
-rw-r--r-- | fitz/filt_faxd.c | 43 | ||||
-rw-r--r-- | fitz/filt_lzwd.c | 12 | ||||
-rw-r--r-- | fitz/filt_predict.c | 30 | ||||
-rw-r--r-- | fitz/fitz.h | 10 | ||||
-rw-r--r-- | pdf/pdf_stream.c | 50 | ||||
-rw-r--r-- | xps/xps_tiff.c | 35 |
7 files changed, 81 insertions, 111 deletions
diff --git a/fitz/filt_dctd.c b/fitz/filt_dctd.c index 650adac6..03dfe87c 100644 --- a/fitz/filt_dctd.c +++ b/fitz/filt_dctd.c @@ -212,12 +212,12 @@ skip: fz_free(ctx, state); } +/* Default: color_transform = -1 (unset) */ fz_stream * -fz_open_dctd(fz_stream *chain, fz_obj *params) +fz_open_dctd(fz_stream *chain, int color_transform) { - fz_dctd *state = NULL; - fz_obj *obj; fz_context *ctx = chain->ctx; + fz_dctd *state = NULL; fz_var(state); @@ -227,12 +227,8 @@ fz_open_dctd(fz_stream *chain, fz_obj *params) memset(state, 0, sizeof(fz_dctd)); state->ctx = ctx; state->chain = chain; - state->color_transform = -1; /* unset */ + state->color_transform = color_transform; state->init = 0; - - obj = fz_dict_gets(params, "ColorTransform"); - if (obj) - state->color_transform = fz_to_int(obj); } fz_catch(ctx) { diff --git a/fitz/filt_faxd.c b/fitz/filt_faxd.c index 7ccebddb..4e522eb5 100644 --- a/fitz/filt_faxd.c +++ b/fitz/filt_faxd.c @@ -659,12 +659,14 @@ close_faxd(fz_context *ctx, void *state_) fz_free(ctx, fax); } +/* Default: columns = 1728, end_of_block = 1, the rest = 0 */ fz_stream * -fz_open_faxd(fz_stream *chain, fz_obj *params) +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) { - fz_faxd *fax = NULL; - fz_obj *obj; fz_context *ctx = chain->ctx; + fz_faxd *fax = NULL; fz_var(fax); @@ -676,34 +678,13 @@ fz_open_faxd(fz_stream *chain, fz_obj *params) fax->ref = NULL; fax->dst = NULL; - fax->k = 0; - fax->end_of_line = 0; - fax->encoded_byte_align = 0; - fax->columns = 1728; - fax->rows = 0; - fax->end_of_block = 1; - fax->black_is_1 = 0; - - obj = fz_dict_gets(params, "K"); - if (obj) fax->k = fz_to_int(obj); - - obj = fz_dict_gets(params, "EndOfLine"); - if (obj) fax->end_of_line = fz_to_bool(obj); - - obj = fz_dict_gets(params, "EncodedByteAlign"); - if (obj) fax->encoded_byte_align = fz_to_bool(obj); - - obj = fz_dict_gets(params, "Columns"); - if (obj) fax->columns = fz_to_int(obj); - - obj = fz_dict_gets(params, "Rows"); - if (obj) fax->rows = fz_to_int(obj); - - obj = fz_dict_gets(params, "EndOfBlock"); - if (obj) fax->end_of_block = fz_to_bool(obj); - - obj = fz_dict_gets(params, "BlackIs1"); - if (obj) fax->black_is_1 = fz_to_bool(obj); + fax->k = k; + fax->end_of_line = end_of_line; + fax->encoded_byte_align = encoded_byte_align; + fax->columns = columns; + fax->rows = rows; + fax->end_of_block = end_of_block; + fax->black_is_1 = black_is_1; fax->stride = ((fax->columns - 1) >> 3) + 1; fax->ridx = 0; diff --git a/fitz/filt_lzwd.c b/fitz/filt_lzwd.c index 04aec9c4..ac952ccf 100644 --- a/fitz/filt_lzwd.c +++ b/fitz/filt_lzwd.c @@ -163,13 +163,13 @@ close_lzwd(fz_context *ctx, void *state_) fz_free(ctx, lzw); } +/* Default: early_change = 1 */ fz_stream * -fz_open_lzwd(fz_stream *chain, fz_obj *params) +fz_open_lzwd(fz_stream *chain, int early_change) { + fz_context *ctx = chain->ctx; fz_lzwd *lzw = NULL; - fz_obj *obj; int i; - fz_context *ctx = chain->ctx; fz_var(lzw); @@ -178,11 +178,7 @@ fz_open_lzwd(fz_stream *chain, fz_obj *params) lzw = fz_malloc_struct(ctx, fz_lzwd); lzw->chain = chain; lzw->eod = 0; - lzw->early_change = 1; - - obj = fz_dict_gets(params, "EarlyChange"); - if (obj) - lzw->early_change = !!fz_to_int(obj); + lzw->early_change = early_change; for (i = 0; i < 256; i++) { diff --git a/fitz/filt_predict.c b/fitz/filt_predict.c index 30393e54..45baf86b 100644 --- a/fitz/filt_predict.c +++ b/fitz/filt_predict.c @@ -187,12 +187,12 @@ close_predict(fz_context *ctx, void *state_) fz_free(ctx, state); } +/* Default values: predictor = 1, columns = 1, colors = 1, bpc = 8 */ fz_stream * -fz_open_predict(fz_stream *chain, fz_obj *params) +fz_open_predict(fz_stream *chain, int predictor, int columns, int colors, int bpc) { - fz_predict *state = NULL; - fz_obj *obj; fz_context *ctx = chain->ctx; + fz_predict *state = NULL; fz_var(state); @@ -203,14 +203,10 @@ fz_open_predict(fz_stream *chain, fz_obj *params) state->out = NULL; state->chain = chain; - state->predictor = 1; - state->columns = 1; - state->colors = 1; - state->bpc = 8; - - obj = fz_dict_gets(params, "Predictor"); - if (obj) - state->predictor = fz_to_int(obj); + state->predictor = predictor; + state->columns = columns; + state->colors = colors; + state->bpc = bpc; if (state->predictor != 1 && state->predictor != 2 && state->predictor != 10 && state->predictor != 11 && @@ -221,18 +217,6 @@ fz_open_predict(fz_stream *chain, fz_obj *params) state->predictor = 1; } - obj = fz_dict_gets(params, "Columns"); - if (obj) - state->columns = fz_to_int(obj); - - obj = fz_dict_gets(params, "Colors"); - if (obj) - state->colors = fz_to_int(obj); - - obj = fz_dict_gets(params, "BitsPerComponent"); - if (obj) - state->bpc = fz_to_int(obj); - state->stride = (state->bpc * state->colors * state->columns + 7) / 8; state->bpp = (state->bpc * state->colors + 7) / 8; diff --git a/fitz/fitz.h b/fitz/fitz.h index e156cb27..fe764afd 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -897,11 +897,13 @@ 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, fz_obj *param); -fz_stream *fz_open_faxd(fz_stream *chain, fz_obj *param); +fz_stream *fz_open_dctd(fz_stream *chain, int color_transform); +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); fz_stream *fz_open_flated(fz_stream *chain); -fz_stream *fz_open_lzwd(fz_stream *chain, fz_obj *param); -fz_stream *fz_open_predict(fz_stream *chain, fz_obj *param); +fz_stream *fz_open_lzwd(fz_stream *chain, int early_change); +fz_stream *fz_open_predict(fz_stream *chain, int predictor, int columns, int colors, int bpc); fz_stream *fz_open_jbig2d(fz_stream *chain, fz_buffer *global); /* diff --git a/pdf/pdf_stream.c b/pdf/pdf_stream.c index 75c0f59c..8a1caa9c 100644 --- a/pdf/pdf_stream.c +++ b/pdf/pdf_stream.c @@ -56,6 +56,16 @@ build_filter(fz_stream *chain, pdf_document * xref, fz_obj * f, fz_obj * p, int s = fz_to_name(f); + int predictor = fz_to_int(fz_dict_gets(p, "Predictor")); + int columns = fz_to_int(fz_dict_gets(p, "Columns")); + int colors = fz_to_int(fz_dict_gets(p, "Colors")); + int bpc = fz_to_int(fz_dict_gets(p, "BitsPerComponent")); + + if (predictor == 0) predictor = 1; + if (columns == 0) columns = 1; + if (colors == 0) colors = 1; + if (bpc == 0) bpc = 8; + if (!strcmp(s, "ASCIIHexDecode") || !strcmp(s, "AHx")) return fz_open_ahxd(chain); @@ -63,28 +73,48 @@ build_filter(fz_stream *chain, pdf_document * xref, fz_obj * f, fz_obj * p, int return fz_open_a85d(chain); else if (!strcmp(s, "CCITTFaxDecode") || !strcmp(s, "CCF")) - return fz_open_faxd(chain, p); + { + fz_obj *k = fz_dict_gets(p, "K"); + fz_obj *eol = fz_dict_gets(p, "EndOfLine"); + fz_obj *eba = fz_dict_gets(p, "EncodedByteAlign"); + fz_obj *columns = fz_dict_gets(p, "Columns"); + fz_obj *rows = fz_dict_gets(p, "Rows"); + fz_obj *eob = fz_dict_gets(p, "EndOfBlock"); + fz_obj *bi1 = fz_dict_gets(p, "BlackIs1"); + return fz_open_faxd(chain, + k ? fz_to_int(k) : 0, + eol ? fz_to_bool(eol) : 0, + eba ? fz_to_bool(eba) : 0, + columns ? fz_to_int(columns) : 1728, + rows ? fz_to_int(rows) : 0, + eob ? fz_to_bool(eob) : 1, + bi1 ? fz_to_bool(bi1) : 0); + } else if (!strcmp(s, "DCTDecode") || !strcmp(s, "DCT")) - return fz_open_dctd(chain, p); + { + fz_obj *ct = fz_dict_gets(p, "ColorTransform"); + return fz_open_dctd(chain, ct ? fz_to_int(ct) : -1); + } else if (!strcmp(s, "RunLengthDecode") || !strcmp(s, "RL")) return fz_open_rld(chain); else if (!strcmp(s, "FlateDecode") || !strcmp(s, "Fl")) { - fz_obj *obj = fz_dict_gets(p, "Predictor"); - if (fz_to_int(obj) > 1) - return fz_open_predict(fz_open_flated(chain), p); - return fz_open_flated(chain); + chain = fz_open_flated(chain); + if (predictor > 1) + chain = fz_open_predict(chain, predictor, columns, colors, bpc); + return chain; } else if (!strcmp(s, "LZWDecode") || !strcmp(s, "LZW")) { - fz_obj *obj = fz_dict_gets(p, "Predictor"); - if (fz_to_int(obj) > 1) - return fz_open_predict(fz_open_lzwd(chain, p), p); - return fz_open_lzwd(chain, p); + fz_obj *ec = fz_dict_gets(p, "EarlyChange"); + chain = fz_open_lzwd(chain, ec ? fz_to_int(ec) : 1); + if (predictor > 1) + chain = fz_open_predict(chain, predictor, columns, colors, bpc); + return chain; } else if (!strcmp(s, "JBIG2Decode")) diff --git a/xps/xps_tiff.c b/xps/xps_tiff.c index 9fae5e2d..934dcc24 100644 --- a/xps/xps_tiff.c +++ b/xps/xps_tiff.c @@ -153,7 +153,7 @@ xps_decode_tiff_packbits(struct tiff *tiff, fz_stream *chain, byte *wp, int wlen static void xps_decode_tiff_lzw(struct tiff *tiff, fz_stream *chain, byte *wp, int wlen) { - fz_stream *stm = fz_open_lzwd(chain, NULL); + fz_stream *stm = fz_open_lzwd(chain, 1); fz_read(stm, wp, wlen); fz_close(stm); } @@ -169,40 +169,21 @@ xps_decode_tiff_flate(struct tiff *tiff, fz_stream *chain, byte *wp, int wlen) static void xps_decode_tiff_fax(struct tiff *tiff, int comp, fz_stream *chain, byte *wp, int wlen) { - fz_context *ctx = tiff->ctx; fz_stream *stm; - fz_obj *params; - fz_obj *columns, *rows, *black_is_1, *k, *encoded_byte_align; - - columns = fz_new_int(ctx, tiff->imagewidth); - rows = fz_new_int(ctx, tiff->imagelength); - black_is_1 = fz_new_bool(ctx, tiff->photometric == 0); - k = fz_new_int(ctx, comp == 4 ? -1 : 0); - encoded_byte_align = fz_new_bool(ctx, comp == 2); - - params = fz_new_dict(ctx, 5); - fz_dict_puts(params, "Columns", columns); - fz_dict_puts(params, "Rows", rows); - fz_dict_puts(params, "BlackIs1", black_is_1); - fz_dict_puts(params, "K", k); - fz_dict_puts(params, "EncodedByteAlign", encoded_byte_align); - - fz_drop_obj(columns); - fz_drop_obj(rows); - fz_drop_obj(black_is_1); - fz_drop_obj(k); - fz_drop_obj(encoded_byte_align); - - stm = fz_open_faxd(chain, params); + int black_is_1 = tiff->photometric == 0; + int k = comp == 4 ? -1 : 0; + int encoded_byte_align = comp == 2; + stm = fz_open_faxd(chain, + k, 0, encoded_byte_align, + tiff->imagewidth, tiff->imagelength, 0, black_is_1); fz_read(stm, wp, wlen); fz_close(stm); - fz_drop_obj(params); } static void xps_decode_tiff_jpeg(struct tiff *tiff, fz_stream *chain, byte *wp, int wlen) { - fz_stream *stm = fz_open_dctd(chain, NULL); + fz_stream *stm = fz_open_dctd(chain, -1); fz_read(stm, wp, wlen); fz_close(stm); } |