diff options
author | Robin Watts <robin.watts@artifex.com> | 2016-09-27 16:08:57 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2016-09-27 16:52:27 +0100 |
commit | 9a78bfb8698061e22e3d460b8c15825992e44def (patch) | |
tree | d1350b9c7a02da811ec438eae175ca9689bf9d4c /openjpeg/src/lib/openjp2/pi.c | |
parent | b4cc6d28e9a456a34a7348d98ff78ada9da727bb (diff) | |
download | ghostpdl-9a78bfb8698061e22e3d460b8c15825992e44def.tar.gz |
Import new OpenJPEG version.
Squashed version of openjpeg-update-20160927
This squashes the following commits:
* Import new OpenJPEG version.
From https://github.com/uclouvain/openjpeg
Final commit is:
commit 34dae137a9a8c04feaa9763ae7e09a86ecb10400
Author: Mathieu Malaterre <mathieu.malaterre@gmail.com>
Date: Mon Sep 26 12:01:31 2016 +0200
OPENJPEG_NAMESPACE is configurable by user
* Zap the OpenJPEG stuff we don't need
* Add predefined openjpeg headers.
* Import patches from Sumatra's tree.
* Update Makefiles for new openjpeg
* Update MSVC for new files
* OpenJPEG allocation fixes.
The old version of openjpeg allocates using malloc/free.
The new version of openjpeg allocates via opj_malloc (and co).
We can capture these and pass them down to our own allocators,
but we cannot get openjpeg to pass us a gs_memory_t * to use.
We therefore resort to using a static to hold 'the current
gs_memory_t *' before we call openjpeg. To keep this threadsafe
we add some private data to the gslibctx, which the openjpeg
implementation can use to hold a lock.
We add calls to both jpx decode implementations to init this
private data (where the luratech implementation is null).
Diffstat (limited to 'openjpeg/src/lib/openjp2/pi.c')
-rw-r--r-- | openjpeg/src/lib/openjp2/pi.c | 86 |
1 files changed, 47 insertions, 39 deletions
diff --git a/openjpeg/src/lib/openjp2/pi.c b/openjpeg/src/lib/openjp2/pi.c index 1d8db41b0..41a2f046f 100644 --- a/openjpeg/src/lib/openjp2/pi.c +++ b/openjpeg/src/lib/openjp2/pi.c @@ -136,10 +136,10 @@ static void opj_pi_update_encode_not_poc ( opj_cp_t *p_cp, * @param p_tx1 pointer that will hold the X1 parameter for the tile * @param p_ty0 pointer that will hold the Y0 parameter for the tile * @param p_ty1 pointer that will hold the Y1 parameter for the tile - * @param p_max_prec pointer that will hold the the maximum precision for all the bands of the tile - * @param p_max_res pointer that will hold the the maximum number of resolutions for all the poc inside the tile. - * @param p_dx_min pointer that will hold the the minimum dx of all the components of all the resolutions for the tile. - * @param p_dy_min pointer that will hold the the minimum dy of all the components of all the resolutions for the tile. + * @param p_max_prec pointer that will hold the maximum precision for all the bands of the tile + * @param p_max_res pointer that will hold the maximum number of resolutions for all the poc inside the tile. + * @param p_dx_min pointer that will hold the minimum dx of all the components of all the resolutions for the tile. + * @param p_dy_min pointer that will hold the minimum dy of all the components of all the resolutions for the tile. */ static void opj_get_encoding_parameters(const opj_image_t *p_image, const opj_cp_t *p_cp, @@ -167,10 +167,10 @@ static void opj_get_encoding_parameters(const opj_image_t *p_image, * @param p_tx1 pointer that will hold the X1 parameter for the tile * @param p_ty0 pointer that will hold the Y0 parameter for the tile * @param p_ty1 pointer that will hold the Y1 parameter for the tile - * @param p_max_prec pointer that will hold the the maximum precision for all the bands of the tile - * @param p_max_res pointer that will hold the the maximum number of resolutions for all the poc inside the tile. - * @param p_dx_min pointer that will hold the the minimum dx of all the components of all the resolutions for the tile. - * @param p_dy_min pointer that will hold the the minimum dy of all the components of all the resolutions for the tile. + * @param p_max_prec pointer that will hold the maximum precision for all the bands of the tile + * @param p_max_res pointer that will hold the maximum number of resolutions for all the poc inside the tile. + * @param p_dx_min pointer that will hold the minimum dx of all the components of all the resolutions for the tile. + * @param p_dy_min pointer that will hold the minimum dy of all the components of all the resolutions for the tile. * @param p_resolutions pointer to an area corresponding to the one described above. */ static void opj_get_all_encoding_parameters(const opj_image_t *p_image, @@ -214,7 +214,7 @@ static void opj_pi_update_decode_poc ( opj_pi_iterator_t * p_pi, /** * FIXME DOC */ -OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos, +static OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos, opj_cp_t *cp, OPJ_UINT32 tileno, OPJ_UINT32 pino, @@ -230,7 +230,7 @@ OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos, ========================================================== */ -OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi) { +static OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi) { opj_pi_comp_t *comp = NULL; opj_pi_resolution_t *res = NULL; OPJ_UINT32 index = 0; @@ -270,7 +270,7 @@ LABEL_SKIP:; return OPJ_FALSE; } -OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi) { +static OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi) { opj_pi_comp_t *comp = NULL; opj_pi_resolution_t *res = NULL; OPJ_UINT32 index = 0; @@ -309,7 +309,7 @@ LABEL_SKIP:; return OPJ_FALSE; } -OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi) { +static OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi) { opj_pi_comp_t *comp = NULL; opj_pi_resolution_t *res = NULL; OPJ_UINT32 index = 0; @@ -392,7 +392,7 @@ LABEL_SKIP:; return OPJ_FALSE; } -OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) { +static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) { opj_pi_comp_t *comp = NULL; opj_pi_resolution_t *res = NULL; OPJ_UINT32 index = 0; @@ -473,7 +473,7 @@ LABEL_SKIP:; return OPJ_FALSE; } -OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) { +static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) { opj_pi_comp_t *comp = NULL; opj_pi_resolution_t *res = NULL; OPJ_UINT32 index = 0; @@ -552,7 +552,7 @@ LABEL_SKIP:; return OPJ_FALSE; } -void opj_get_encoding_parameters( const opj_image_t *p_image, +static void opj_get_encoding_parameters( const opj_image_t *p_image, const opj_cp_t *p_cp, OPJ_UINT32 p_tileno, OPJ_INT32 * p_tx0, @@ -666,7 +666,7 @@ void opj_get_encoding_parameters( const opj_image_t *p_image, } -void opj_get_all_encoding_parameters( const opj_image_t *p_image, +static void opj_get_all_encoding_parameters( const opj_image_t *p_image, const opj_cp_t *p_cp, OPJ_UINT32 tileno, OPJ_INT32 * p_tx0, @@ -693,6 +693,9 @@ void opj_get_all_encoding_parameters( const opj_image_t *p_image, /* position in x and y of tile*/ OPJ_UINT32 p, q; + /* non-corrected (in regard to image offset) tile offset */ + OPJ_UINT32 l_tx0, l_ty0; + /* preconditions in debug*/ assert(p_cp != 00); assert(p_image != 00); @@ -708,10 +711,12 @@ void opj_get_all_encoding_parameters( const opj_image_t *p_image, q = tileno / p_cp->tw; /* here calculation of tx0, tx1, ty0, ty1, maxprec, l_dx and l_dy */ - *p_tx0 = opj_int_max((OPJ_INT32)(p_cp->tx0 + p * p_cp->tdx), (OPJ_INT32)p_image->x0); - *p_tx1 = opj_int_min((OPJ_INT32)(p_cp->tx0 + (p + 1) * p_cp->tdx), (OPJ_INT32)p_image->x1); - *p_ty0 = opj_int_max((OPJ_INT32)(p_cp->ty0 + q * p_cp->tdy), (OPJ_INT32)p_image->y0); - *p_ty1 = opj_int_min((OPJ_INT32)(p_cp->ty0 + (q + 1) * p_cp->tdy), (OPJ_INT32)p_image->y1); + l_tx0 = p_cp->tx0 + p * p_cp->tdx; /* can't be greater than p_image->x1 so won't overflow */ + *p_tx0 = (OPJ_INT32)opj_uint_max(l_tx0, p_image->x0); + *p_tx1 = (OPJ_INT32)opj_uint_min(opj_uint_adds(l_tx0, p_cp->tdx), p_image->x1); + l_ty0 = p_cp->ty0 + q * p_cp->tdy; /* can't be greater than p_image->y1 so won't overflow */ + *p_ty0 = (OPJ_INT32)opj_uint_max(l_ty0, p_image->y0); + *p_ty1 = (OPJ_INT32)opj_uint_min(opj_uint_adds(l_ty0, p_cp->tdy), p_image->y1); /* max precision and resolution is 0 (can only grow)*/ *p_max_prec = 0; @@ -742,10 +747,12 @@ void opj_get_all_encoding_parameters( const opj_image_t *p_image, } /* use custom size for precincts*/ - l_level_no = l_tccp->numresolutions - 1; + l_level_no = l_tccp->numresolutions; for (resno = 0; resno < l_tccp->numresolutions; ++resno) { OPJ_UINT32 l_dx, l_dy; + --l_level_no; + /* precinct width and height*/ l_pdx = l_tccp->prcw[resno]; l_pdy = l_tccp->prch[resno]; @@ -777,14 +784,13 @@ void opj_get_all_encoding_parameters( const opj_image_t *p_image, *p_max_prec = l_product; } - --l_level_no; } ++l_tccp; ++l_img_comp; } } -opj_pi_iterator_t * opj_pi_create( const opj_image_t *image, +static opj_pi_iterator_t * opj_pi_create( const opj_image_t *image, const opj_cp_t *cp, OPJ_UINT32 tileno ) { @@ -815,7 +821,6 @@ opj_pi_iterator_t * opj_pi_create( const opj_image_t *image, if (!l_pi) { return NULL; } - memset(l_pi,0,l_poc_bound * sizeof(opj_pi_iterator_t)); l_current_pi = l_pi; for (pino = 0; pino < l_poc_bound ; ++pino) { @@ -827,28 +832,26 @@ opj_pi_iterator_t * opj_pi_create( const opj_image_t *image, } l_current_pi->numcomps = image->numcomps; - memset(l_current_pi->comps,0,image->numcomps * sizeof(opj_pi_comp_t)); for (compno = 0; compno < image->numcomps; ++compno) { opj_pi_comp_t *comp = &l_current_pi->comps[compno]; tccp = &tcp->tccps[compno]; - comp->resolutions = (opj_pi_resolution_t*) opj_malloc(tccp->numresolutions * sizeof(opj_pi_resolution_t)); + comp->resolutions = (opj_pi_resolution_t*) opj_calloc(tccp->numresolutions, sizeof(opj_pi_resolution_t)); if (!comp->resolutions) { opj_pi_destroy(l_pi, l_poc_bound); return 00; } comp->numresolutions = tccp->numresolutions; - memset(comp->resolutions,0,tccp->numresolutions * sizeof(opj_pi_resolution_t)); } ++l_current_pi; } return l_pi; } -void opj_pi_update_encode_poc_and_final ( opj_cp_t *p_cp, +static void opj_pi_update_encode_poc_and_final ( opj_cp_t *p_cp, OPJ_UINT32 p_tileno, OPJ_INT32 p_tx0, OPJ_INT32 p_tx1, @@ -926,7 +929,7 @@ void opj_pi_update_encode_poc_and_final ( opj_cp_t *p_cp, } } -void opj_pi_update_encode_not_poc ( opj_cp_t *p_cp, +static void opj_pi_update_encode_not_poc ( opj_cp_t *p_cp, OPJ_UINT32 p_num_comps, OPJ_UINT32 p_tileno, OPJ_INT32 p_tx0, @@ -981,7 +984,7 @@ void opj_pi_update_encode_not_poc ( opj_cp_t *p_cp, } } -void opj_pi_update_decode_poc (opj_pi_iterator_t * p_pi, +static void opj_pi_update_decode_poc (opj_pi_iterator_t * p_pi, opj_tcp_t * p_tcp, OPJ_UINT32 p_max_precision, OPJ_UINT32 p_max_res) @@ -1023,7 +1026,7 @@ void opj_pi_update_decode_poc (opj_pi_iterator_t * p_pi, } } -void opj_pi_update_decode_not_poc (opj_pi_iterator_t * p_pi, +static void opj_pi_update_decode_not_poc (opj_pi_iterator_t * p_pi, opj_tcp_t * p_tcp, OPJ_UINT32 p_max_precision, OPJ_UINT32 p_max_res) @@ -1060,7 +1063,7 @@ void opj_pi_update_decode_not_poc (opj_pi_iterator_t * p_pi, -OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos, +static OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos, opj_cp_t *cp, OPJ_UINT32 tileno, OPJ_UINT32 pino, @@ -1108,7 +1111,8 @@ OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos, break; case 'P': switch(tcp->prg){ - case OPJ_LRCP||OPJ_RLCP: + case OPJ_LRCP: /* fall through */ + case OPJ_RLCP: if(tcp->prc_t == tcp->prcE){ if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)){ return OPJ_TRUE; @@ -1233,16 +1237,21 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image, l_current_pi = l_pi; /* memory allocation for include */ - l_current_pi->include = (OPJ_INT16*) opj_calloc((l_tcp->numlayers +1) * l_step_l, sizeof(OPJ_INT16)); - if - (!l_current_pi->include) + /* prevent an integer overflow issue */ + /* 0 < l_tcp->numlayers < 65536 c.f. opj_j2k_read_cod in j2k.c */ + l_current_pi->include = 00; + if (l_step_l <= (SIZE_MAX / (l_tcp->numlayers + 1U))) + { + l_current_pi->include = (OPJ_INT16*) opj_calloc((size_t)(l_tcp->numlayers + 1U) * l_step_l, sizeof(OPJ_INT16)); + } + + if (!l_current_pi->include) { opj_free(l_tmp_data); opj_free(l_tmp_ptr); opj_pi_destroy(l_pi, l_bound); return 00; } - memset(l_current_pi->include,0, (l_tcp->numlayers + 1) * l_step_l* sizeof(OPJ_INT16)); /* special treatment for the first packet iterator */ l_current_comp = l_current_pi->comps; @@ -1428,7 +1437,7 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image, l_step_l = l_max_res * l_step_r; /* set values for first packet iterator*/ - l_pi->tp_on = p_cp->m_specific_param.m_enc.m_tp_on; + l_pi->tp_on = (OPJ_BYTE)p_cp->m_specific_param.m_enc.m_tp_on; l_current_pi = l_pi; /* memory allocation for include*/ @@ -1439,7 +1448,6 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image, opj_pi_destroy(l_pi, l_bound); return 00; } - memset(l_current_pi->include,0,l_tcp->numlayers * l_step_l* sizeof(OPJ_INT16)); /* special treatment for the first packet iterator*/ l_current_comp = l_current_pi->comps; |