summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2016-10-29 20:47:31 +0800
committerSebastian Rasmussen <sebras@gmail.com>2016-12-14 20:39:19 +0100
commit2c9b27cf0d29362973cef56bf7abf60ff7e72f10 (patch)
treedc8ae69ff4d1bf49146c764bd6ac54b31127d871
parentfd2d1c8dc1d55d32111b3390130d269691fc39bc (diff)
downloadmupdf-2c9b27cf0d29362973cef56bf7abf60ff7e72f10.tar.xz
jpx: Max components is known, so avoid allocating arrays.
-rw-r--r--source/fitz/load-jpx.c36
1 files changed, 13 insertions, 23 deletions
diff --git a/source/fitz/load-jpx.c b/source/fitz/load-jpx.c
index 04e640fa..1e5fad3b 100644
--- a/source/fitz/load-jpx.c
+++ b/source/fitz/load-jpx.c
@@ -7,6 +7,11 @@ typedef struct stream_block_s stream_block;
#include <lwf_jp2.h>
+#define MAX_COLORS 4
+#define MAX_ALPHAS 1
+#define MAX_COMPONENTS (MAX_COLORS + MAX_ALPHAS)
+
+
struct fz_jpxd_s
{
JP2_Decomp_Handle doc;
@@ -21,12 +26,12 @@ struct fz_jpxd_s
unsigned long yres;
JP2_Property_Value nchans;
- JP2_Property_Value *widths;
- JP2_Property_Value *heights;
- JP2_Property_Value *hstep;
- JP2_Property_Value *vstep;
- JP2_Property_Value *bpss;
- JP2_Property_Value *signs;
+ JP2_Property_Value widths[MAX_COMPONENTS];
+ JP2_Property_Value heights[MAX_COMPONENTS];
+ JP2_Property_Value hstep[MAX_COMPONENTS];
+ JP2_Property_Value vstep[MAX_COMPONENTS];
+ JP2_Property_Value bpss[MAX_COMPONENTS];
+ JP2_Property_Value signs[MAX_COMPONENTS];
};
struct stream_block_s
@@ -296,18 +301,11 @@ jpx_read_image(fz_context *ctx, fz_jpxd *state, unsigned char *data, size_t size
if (prealphas> 0)
alphas = prealphas;
- colors = fz_clampi(colors, 0, 4);
- alphas = fz_clampi(alphas, 0, 1);
+ colors = fz_clampi(colors, 0, MAX_COLORS);
+ alphas = fz_clampi(alphas, 0, MAX_ALPHAS);
state->nchans = colors + alphas;
- state->widths = fz_malloc(ctx, state->nchans * sizeof (JP2_Property_Value));
- state->heights = fz_malloc(ctx, state->nchans * sizeof (JP2_Property_Value));
- state->hstep = fz_malloc(ctx, state->nchans * sizeof (JP2_Property_Value));
- state->vstep = fz_malloc(ctx, state->nchans * sizeof (JP2_Property_Value));
- state->bpss = fz_malloc(ctx, state->nchans * sizeof (JP2_Property_Value));
- state->signs = fz_malloc(ctx, state->nchans * sizeof (JP2_Property_Value));
-
if (state->palette)
{
err = JP2_Decompress_GetProp(state->doc, cJP2_Prop_Width, &state->width, -1, 0);
@@ -436,15 +434,7 @@ jpx_read_image(fz_context *ctx, fz_jpxd *state, unsigned char *data, size_t size
}
}
fz_always(ctx)
- {
JP2_Decompress_End(state->doc);
- fz_free(ctx, state->signs);
- fz_free(ctx, state->widths);
- fz_free(ctx, state->heights);
- fz_free(ctx, state->hstep);
- fz_free(ctx, state->vstep);
- fz_free(ctx, state->bpss);
- }
fz_catch(ctx)
{
fz_drop_pixmap(ctx, state->pix);