diff options
author | Robin Watts <robin.watts@artifex.com> | 2011-12-17 00:49:23 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2011-12-17 00:49:23 +0000 |
commit | 3eae1449777c4ecccc73a156c7dfff42f927ccc4 (patch) | |
tree | b0cd1bc08b3af218dd06c501402782db91ad0523 /fitz/filt_predict.c | |
parent | c53b6af33c996a7ae6815ac15254297d43f43a9c (diff) | |
download | mupdf-3eae1449777c4ecccc73a156c7dfff42f927ccc4.tar.xz |
More memsqueezing fixes; stream creation.
Diffstat (limited to 'fitz/filt_predict.c')
-rw-r--r-- | fitz/filt_predict.c | 88 |
1 files changed, 53 insertions, 35 deletions
diff --git a/fitz/filt_predict.c b/fitz/filt_predict.c index ab4a2eaa..30393e54 100644 --- a/fitz/filt_predict.c +++ b/fitz/filt_predict.c @@ -190,53 +190,71 @@ close_predict(fz_context *ctx, void *state_) fz_stream * fz_open_predict(fz_stream *chain, fz_obj *params) { - fz_predict *state; + fz_predict *state = NULL; fz_obj *obj; fz_context *ctx = chain->ctx; - state = fz_malloc_struct(ctx, fz_predict); - state->chain = chain; + fz_var(state); - 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); - - if (state->predictor != 1 && state->predictor != 2 && - state->predictor != 10 && state->predictor != 11 && - state->predictor != 12 && state->predictor != 13 && - state->predictor != 14 && state->predictor != 15) + fz_try(ctx) { - fz_warn(ctx, "invalid predictor: %d", state->predictor); + state = fz_malloc_struct(ctx, fz_predict); + state->in = NULL; + 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); + + if (state->predictor != 1 && state->predictor != 2 && + state->predictor != 10 && state->predictor != 11 && + state->predictor != 12 && state->predictor != 13 && + state->predictor != 14 && state->predictor != 15) + { + fz_warn(ctx, "invalid predictor: %d", state->predictor); + state->predictor = 1; + } - obj = fz_dict_gets(params, "Columns"); - if (obj) - state->columns = fz_to_int(obj); + 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, "Colors"); + if (obj) + state->colors = fz_to_int(obj); - obj = fz_dict_gets(params, "BitsPerComponent"); - if (obj) - state->bpc = 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; + state->stride = (state->bpc * state->colors * state->columns + 7) / 8; + state->bpp = (state->bpc * state->colors + 7) / 8; - state->in = fz_malloc(ctx, state->stride + 1); - state->out = fz_malloc(ctx, state->stride); - state->ref = fz_malloc(ctx, state->stride); - state->rp = state->out; - state->wp = state->out; + state->in = fz_malloc(ctx, state->stride + 1); + state->out = fz_malloc(ctx, state->stride); + state->ref = fz_malloc(ctx, state->stride); + state->rp = state->out; + state->wp = state->out; - memset(state->ref, 0, state->stride); + memset(state->ref, 0, state->stride); + } + fz_catch(ctx) + { + if (state) + { + fz_free(ctx, state->in); + fz_free(ctx, state->out); + } + fz_free(ctx, state); + fz_close(chain); + fz_rethrow(ctx); + } return fz_new_stream(ctx, state, read_predict, close_predict); } |