enable all progression orders
[openjpeg.git] / libopenjpeg / pi.c
index f01bab75e5cb96dfdb12dcbd5ab0585ed726c9b3..f601c7697bd9d05f75453b4c98594088739744ee 100644 (file)
@@ -115,11 +115,9 @@ void get_all_encoding_parameters(
  * @param      p_cp            the coding parameters.
  * @param      p_tile_no       the index of the tile from which creating the packet iterator.
  */
-opj_pi_iterator_t * pi_create(
-                                                               const opj_image_t *image,
+opj_pi_iterator_t * pi_create( const opj_image_t *image,
                                                                const opj_cp_v2_t *cp,
-                                                               OPJ_UINT32 tileno
-                                                       );
+                                                               OPJ_UINT32 tileno );
 
 void pi_update_decode_not_poc (opj_pi_iterator_t * p_pi,opj_tcp_v2_t * p_tcp,OPJ_UINT32 p_max_precision,OPJ_UINT32 p_max_res);
 void pi_update_decode_poc (opj_pi_iterator_t * p_pi,opj_tcp_v2_t * p_tcp,OPJ_UINT32 p_max_precision,OPJ_UINT32 p_max_res);
@@ -596,8 +594,7 @@ opj_pi_iterator_t *pi_create_decode(opj_image_t *image, opj_cp_t *cp, int tileno
 }
 
 
-opj_pi_iterator_t *pi_create_decode_v2(
-                                                                               opj_image_t *p_image,
+opj_pi_iterator_t *pi_create_decode_v2(        opj_image_t *p_image,
                                                                                opj_cp_v2_t *p_cp,
                                                                                OPJ_UINT32 p_tile_no
                                                                                )
@@ -655,10 +652,8 @@ opj_pi_iterator_t *pi_create_decode_v2(
        }
 
        // memory allocation for pi
-       l_pi = pi_create(p_image,p_cp,p_tile_no);
-       if
-               (!l_pi)
-       {
+       l_pi = pi_create(p_image, p_cp, p_tile_no);
+       if (!l_pi) {
                opj_free(l_tmp_data);
                opj_free(l_tmp_ptr);
                return 00;
@@ -685,7 +680,7 @@ opj_pi_iterator_t *pi_create_decode_v2(
        l_current_pi = l_pi;
 
        // memory allocation for include
-       l_current_pi->include = (OPJ_INT16*) opj_calloc(l_tcp->numlayers * l_step_l, sizeof(OPJ_INT16));
+       l_current_pi->include = (OPJ_INT16*) opj_calloc((l_tcp->numlayers +1) * l_step_l, sizeof(OPJ_INT16));
        if
                (!l_current_pi->include)
        {
@@ -694,7 +689,7 @@ opj_pi_iterator_t *pi_create_decode_v2(
                pi_destroy_v2(l_pi, l_bound);
                return 00;
        }
-       memset(l_current_pi->include,0,l_tcp->numlayers * l_step_l* sizeof(OPJ_INT16));
+       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;
@@ -1376,11 +1371,9 @@ void get_all_encoding_parameters(
  * @param      p_cp            the coding parameters.
  * @param      p_tile_no       the index of the tile from which creating the packet iterator.
  */
-opj_pi_iterator_t * pi_create(
-                                                               const opj_image_t *image,
+opj_pi_iterator_t * pi_create( const opj_image_t *image,
                                                                const opj_cp_v2_t *cp,
-                                                               OPJ_UINT32 tileno
-                                                       )
+                                                               OPJ_UINT32 tileno )
 {
        // loop
        OPJ_UINT32 pino, compno;
@@ -1404,41 +1397,36 @@ opj_pi_iterator_t * pi_create(
        tcp = &cp->tcps[tileno];
        l_poc_bound = tcp->numpocs+1;
 
-
        // memory allocations
        l_pi = (opj_pi_iterator_t*) opj_calloc((l_poc_bound), sizeof(opj_pi_iterator_t));
-
-       if
-               (!l_pi)
-       {
-               return 00;
+       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)
-       {
+       for (pino = 0; pino < l_poc_bound ; ++pino) {
+
                l_current_pi->comps = (opj_pi_comp_t*) opj_calloc(image->numcomps, sizeof(opj_pi_comp_t));
-               if
-                       (! l_current_pi->comps)
-               {
+               if (! l_current_pi->comps) {
                        pi_destroy_v2(l_pi, l_poc_bound);
-                       return 00;
+                       return NULL;
                }
+
                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)
-               {
+
+               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));
-                       if
-                               (!comp->resolutions)
-                       {
+                       if (!comp->resolutions) {
                                pi_destroy_v2(l_pi, l_poc_bound);
                                return 00;
                        }
+
                        comp->numresolutions = tccp->numresolutions;
                        memset(comp->resolutions,0,tccp->numresolutions * sizeof(opj_pi_resolution_t));
                }