[trunk] rework code to avoid a warning. this also remove a division and prefer bit...
[openjpeg.git] / src / lib / openjp2 / pi.c
index 79a1f538c21703abc5934bf6e6adf873deb8638e..d0af76529e20e9ddbfb1bc79eb98bf5d96651dd3 100644 (file)
@@ -43,31 +43,31 @@ Get next packet in layer-resolution-component-precinct order.
 @param pi packet iterator to modify
 @return returns false if pi pointed to the last packet or else returns true
 */
-static opj_bool opj_pi_next_lrcp(opj_pi_iterator_t * pi);
+static OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi);
 /**
 Get next packet in resolution-layer-component-precinct order.
 @param pi packet iterator to modify
 @return returns false if pi pointed to the last packet or else returns true
 */
-static opj_bool opj_pi_next_rlcp(opj_pi_iterator_t * pi);
+static OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi);
 /**
 Get next packet in resolution-precinct-component-layer order.
 @param pi packet iterator to modify
 @return returns false if pi pointed to the last packet or else returns true
 */
-static opj_bool opj_pi_next_rpcl(opj_pi_iterator_t * pi);
+static OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi);
 /**
 Get next packet in precinct-component-resolution-layer order.
 @param pi packet iterator to modify
 @return returns false if pi pointed to the last packet or else returns true
 */
-static opj_bool opj_pi_next_pcrl(opj_pi_iterator_t * pi);
+static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi);
 /**
 Get next packet in component-precinct-resolution-layer order.
 @param pi packet iterator to modify
 @return returns false if pi pointed to the last packet or else returns true
 */
-static opj_bool opj_pi_next_cprl(opj_pi_iterator_t * pi);
+static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi);
 
 /**
  * Updates the coding parameters if the encoding is used with Progression order changes and final (or cinema parameters are used).
@@ -83,7 +83,7 @@ static opj_bool opj_pi_next_cprl(opj_pi_iterator_t * pi);
  * @param      p_dx_min                the minimum dx of all the components of all the resolutions for the tile.
  * @param      p_dy_min                the minimum dy of all the components of all the resolutions for the tile.
  */
-static void opj_pi_update_encode_poc_and_final ( opj_cp_v2_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,
@@ -98,6 +98,7 @@ static void opj_pi_update_encode_poc_and_final ( opj_cp_v2_t *p_cp,
  * Updates the coding parameters if the encoding is not used with Progression order changes and final (and cinema parameters are used).
  *
  * @param      p_cp            the coding parameters to modify
+ * @param      p_num_comps             the number of components
  * @param      p_tileno        the tile index being concerned.
  * @param      p_tx0           X0 parameter for the tile
  * @param      p_tx1           X1 parameter for the tile
@@ -105,10 +106,10 @@ static void opj_pi_update_encode_poc_and_final ( opj_cp_v2_t *p_cp,
  * @param      p_ty1           Y1 parameter for the tile
  * @param      p_max_prec      the maximum precision for all the bands of the tile
  * @param      p_max_res       the maximum number of resolutions for all the poc inside the tile.
- * @param      dx_min          the minimum dx of all the components of all the resolutions for the tile.
- * @param      dy_min          the minimum dy of all the components of all the resolutions for the tile.
+ * @param      p_dx_min                the minimum dx of all the components of all the resolutions for the tile.
+ * @param      p_dy_min                the minimum dy of all the components of all the resolutions for the tile.
  */
-static void opj_pi_update_encode_not_poc (  opj_cp_v2_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,
@@ -124,18 +125,18 @@ static void opj_pi_update_encode_not_poc (  opj_cp_v2_t *p_cp,
  * 
  * @param      p_image                 the image being encoded.
  * @param      p_cp                    the coding parameters.
- * @param      p_tileno                        the tile index of the tile being encoded.
+ * @param      tileno                  the tile index of the tile being encoded.
  * @param      p_tx0                   pointer that will hold the X0 parameter for the tile
  * @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      dx_min                  pointer that will hold the the minimum dx of all the components of all the resolutions for the tile.
- * @param      dy_min                  pointer that will hold the the minimum dy of all the components of all the resolutions for 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.
  */
 static void opj_get_encoding_parameters(const opj_image_t *p_image,
-                                        const opj_cp_v2_t *p_cp,
+                                        const opj_cp_t *p_cp,
                                         OPJ_UINT32  tileno,
                                         OPJ_INT32  * p_tx0,
                                         OPJ_INT32 * p_tx1,
@@ -167,7 +168,7 @@ static void opj_get_encoding_parameters(const opj_image_t *p_image,
  * @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,
-                                            const opj_cp_v2_t *p_cp,
+                                            const opj_cp_t *p_cp,
                                             OPJ_UINT32 tileno,
                                             OPJ_INT32 * p_tx0,
                                             OPJ_INT32 * p_tx1,
@@ -184,31 +185,31 @@ static void opj_get_all_encoding_parameters(const opj_image_t *p_image,
  * 
  * @param      p_image         the image used to initialize the packet iterator (in fact only the number of components is relevant.
  * @param      p_cp            the coding parameters.
- * @param      p_tile_no       the index of the tile from which creating the packet iterator.
+ * @param      tileno  the index of the tile from which creating the packet iterator.
  */
-static opj_pi_iterator_t * opj_pi_create(      const opj_image_t *image,
-                                            const opj_cp_v2_t *cp,
+static opj_pi_iterator_t * opj_pi_create(      const opj_image_t *p_image,
+                                            const opj_cp_t *p_cp,
                                             OPJ_UINT32 tileno );
 /**
  * FIXME DOC
  */
 static void opj_pi_update_decode_not_poc (opj_pi_iterator_t * p_pi,
-                                          opj_tcp_v2_t * p_tcp,
+                                          opj_tcp_t * p_tcp,
                                           OPJ_UINT32 p_max_precision,
                                           OPJ_UINT32 p_max_res);
 /**
  * FIXME DOC
  */
 static void opj_pi_update_decode_poc (  opj_pi_iterator_t * p_pi,
-                                        opj_tcp_v2_t * p_tcp,
+                                        opj_tcp_t * p_tcp,
                                         OPJ_UINT32 p_max_precision,
                                         OPJ_UINT32 p_max_res);
 
 /**
  * FIXME DOC
  */
-opj_bool opj_pi_check_next_level(      OPJ_INT32 pos,
-                                                               opj_cp_v2_t *cp,
+OPJ_BOOL opj_pi_check_next_level(      OPJ_INT32 pos,
+                                                               opj_cp_t *cp,
                                                                OPJ_UINT32 tileno,
                                                                OPJ_UINT32 pino,
                                                                const OPJ_CHAR *prog);
@@ -223,7 +224,7 @@ opj_bool opj_pi_check_next_level(   OPJ_INT32 pos,
 ==========================================================
 */
 
-opj_bool opj_pi_next_lrcp(opj_pi_iterator_t * pi) {
+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;
@@ -263,7 +264,7 @@ LABEL_SKIP:;
        return OPJ_FALSE;
 }
 
-opj_bool opj_pi_next_rlcp(opj_pi_iterator_t * pi) {
+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;
@@ -302,7 +303,7 @@ LABEL_SKIP:;
        return OPJ_FALSE;
 }
 
-opj_bool opj_pi_next_rpcl(opj_pi_iterator_t * pi) {
+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;
@@ -321,8 +322,8 @@ opj_bool opj_pi_next_rpcl(opj_pi_iterator_t * pi) {
                                res = &comp->resolutions[resno];
                                dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
                                dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
-                               pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
-                               pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
+                               pi->dx = !pi->dx ? dx : opj_uint_min(pi->dx, dx);
+                               pi->dy = !pi->dy ? dy : opj_uint_min(pi->dy, dy);
                        }
                }
        }
@@ -347,10 +348,10 @@ if (!pi->tp_on){
                                        }
                                        res = &comp->resolutions[pi->resno];
                                        levelno = comp->numresolutions - 1 - pi->resno;
-                                       trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
-                                       try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
-                                       trx1 = int_ceildiv(pi->tx1, comp->dx << levelno);
-                                       try1 = int_ceildiv(pi->ty1, comp->dy << levelno);
+                                       trx0 = opj_int_ceildiv(pi->tx0, comp->dx << levelno);
+                                       try0 = opj_int_ceildiv(pi->ty0, comp->dy << levelno);
+                                       trx1 = opj_int_ceildiv(pi->tx1, comp->dx << levelno);
+                                       try1 = opj_int_ceildiv(pi->ty1, comp->dy << levelno);
                                        rpx = res->pdx + levelno;
                                        rpy = res->pdy + levelno;
                                        if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){
@@ -364,10 +365,10 @@ if (!pi->tp_on){
                                        
                                        if ((trx0==trx1)||(try0==try1)) continue;
                                        
-                                       prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno), res->pdx)
-                                                - int_floordivpow2(trx0, res->pdx);
-                                       prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy)
-                                                - int_floordivpow2(try0, res->pdy);
+                                       prci = opj_int_floordivpow2(opj_int_ceildiv(pi->x, comp->dx << levelno), res->pdx)
+                                                - opj_int_floordivpow2(trx0, res->pdx);
+                                       prcj = opj_int_floordivpow2(opj_int_ceildiv(pi->y, comp->dy << levelno), res->pdy)
+                                                - opj_int_floordivpow2(try0, res->pdy);
                                        pi->precno = prci + prcj * res->pw;
                                        for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
                                                index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
@@ -385,7 +386,7 @@ LABEL_SKIP:;
        return OPJ_FALSE;
 }
 
-opj_bool opj_pi_next_pcrl(opj_pi_iterator_t * pi) {
+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;
@@ -405,8 +406,8 @@ opj_bool opj_pi_next_pcrl(opj_pi_iterator_t * pi) {
                                res = &comp->resolutions[resno];
                                dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
                                dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
-                               pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
-                               pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
+                               pi->dx = !pi->dx ? dx : opj_uint_min(pi->dx, dx);
+                               pi->dy = !pi->dy ? dy : opj_uint_min(pi->dy, dy);
                        }
                }
        }
@@ -420,7 +421,7 @@ opj_bool opj_pi_next_pcrl(opj_pi_iterator_t * pi) {
                for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += pi->dx - (pi->x % pi->dx)) {
                        for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
                                comp = &pi->comps[pi->compno];
-                               for (pi->resno = pi->poc.resno0; pi->resno < uint_min(pi->poc.resno1, comp->numresolutions); pi->resno++) {
+                               for (pi->resno = pi->poc.resno0; pi->resno < opj_uint_min(pi->poc.resno1, comp->numresolutions); pi->resno++) {
                                        OPJ_UINT32 levelno;
                                        OPJ_INT32 trx0, try0;
                                        OPJ_INT32 trx1, try1;
@@ -428,10 +429,10 @@ opj_bool opj_pi_next_pcrl(opj_pi_iterator_t * pi) {
                                        OPJ_INT32 prci, prcj;
                                        res = &comp->resolutions[pi->resno];
                                        levelno = comp->numresolutions - 1 - pi->resno;
-                                       trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
-                                       try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
-                                       trx1 = int_ceildiv(pi->tx1, comp->dx << levelno);
-                                       try1 = int_ceildiv(pi->ty1, comp->dy << levelno);
+                                       trx0 = opj_int_ceildiv(pi->tx0, comp->dx << levelno);
+                                       try0 = opj_int_ceildiv(pi->ty0, comp->dy << levelno);
+                                       trx1 = opj_int_ceildiv(pi->tx1, comp->dx << levelno);
+                                       try1 = opj_int_ceildiv(pi->ty1, comp->dy << levelno);
                                        rpx = res->pdx + levelno;
                                        rpy = res->pdy + levelno;
                                        if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){
@@ -445,10 +446,10 @@ opj_bool opj_pi_next_pcrl(opj_pi_iterator_t * pi) {
                                        
                                        if ((trx0==trx1)||(try0==try1)) continue;
                                        
-                                       prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno), res->pdx)
-                                                - int_floordivpow2(trx0, res->pdx);
-                                       prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy)
-                                                - int_floordivpow2(try0, res->pdy);
+                                       prci = opj_int_floordivpow2(opj_int_ceildiv(pi->x, comp->dx << levelno), res->pdx)
+                                                - opj_int_floordivpow2(trx0, res->pdx);
+                                       prcj = opj_int_floordivpow2(opj_int_ceildiv(pi->y, comp->dy << levelno), res->pdy)
+                                                - opj_int_floordivpow2(try0, res->pdy);
                                        pi->precno = prci + prcj * res->pw;
                                        for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
                                                index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
@@ -466,7 +467,7 @@ LABEL_SKIP:;
        return OPJ_FALSE;
 }
 
-opj_bool opj_pi_next_cprl(opj_pi_iterator_t * pi) {
+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;
@@ -488,8 +489,8 @@ opj_bool opj_pi_next_cprl(opj_pi_iterator_t * pi) {
                        res = &comp->resolutions[resno];
                        dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
                        dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
-                       pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
-                       pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
+                       pi->dx = !pi->dx ? dx : opj_uint_min(pi->dx, dx);
+                       pi->dy = !pi->dy ? dy : opj_uint_min(pi->dy, dy);
                }
                if (!pi->tp_on){
                        pi->poc.ty0 = pi->ty0;
@@ -499,7 +500,7 @@ opj_bool opj_pi_next_cprl(opj_pi_iterator_t * pi) {
                }
                for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += pi->dy - (pi->y % pi->dy)) {
                        for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += pi->dx - (pi->x % pi->dx)) {
-                               for (pi->resno = pi->poc.resno0; pi->resno < uint_min(pi->poc.resno1, comp->numresolutions); pi->resno++) {
+                               for (pi->resno = pi->poc.resno0; pi->resno < opj_uint_min(pi->poc.resno1, comp->numresolutions); pi->resno++) {
                                        OPJ_UINT32 levelno;
                                        OPJ_INT32 trx0, try0;
                                        OPJ_INT32 trx1, try1;
@@ -507,10 +508,10 @@ opj_bool opj_pi_next_cprl(opj_pi_iterator_t * pi) {
                                        OPJ_INT32 prci, prcj;
                                        res = &comp->resolutions[pi->resno];
                                        levelno = comp->numresolutions - 1 - pi->resno;
-                                       trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
-                                       try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
-                                       trx1 = int_ceildiv(pi->tx1, comp->dx << levelno);
-                                       try1 = int_ceildiv(pi->ty1, comp->dy << levelno);
+                                       trx0 = opj_int_ceildiv(pi->tx0, comp->dx << levelno);
+                                       try0 = opj_int_ceildiv(pi->ty0, comp->dy << levelno);
+                                       trx1 = opj_int_ceildiv(pi->tx1, comp->dx << levelno);
+                                       try1 = opj_int_ceildiv(pi->ty1, comp->dy << levelno);
                                        rpx = res->pdx + levelno;
                                        rpy = res->pdy + levelno;
                                        if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){
@@ -524,10 +525,10 @@ opj_bool opj_pi_next_cprl(opj_pi_iterator_t * pi) {
                                        
                                        if ((trx0==trx1)||(try0==try1)) continue;
                                        
-                                       prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno), res->pdx)
-                                                - int_floordivpow2(trx0, res->pdx);
-                                       prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy)
-                                                - int_floordivpow2(try0, res->pdy);
+                                       prci = opj_int_floordivpow2(opj_int_ceildiv(pi->x, comp->dx << levelno), res->pdx)
+                                                - opj_int_floordivpow2(trx0, res->pdx);
+                                       prcj = opj_int_floordivpow2(opj_int_ceildiv(pi->y, comp->dy << levelno), res->pdy)
+                                                - opj_int_floordivpow2(try0, res->pdy);
                                        pi->precno = prci + prcj * res->pw;
                                        for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
                                                index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
@@ -546,7 +547,7 @@ LABEL_SKIP:;
 }
 
 void opj_get_encoding_parameters(      const opj_image_t *p_image,
-                                    const opj_cp_v2_t *p_cp,
+                                    const opj_cp_t *p_cp,
                                     OPJ_UINT32 p_tileno,
                                     OPJ_INT32 * p_tx0,
                                     OPJ_INT32  * p_tx1,
@@ -560,7 +561,7 @@ void opj_get_encoding_parameters(   const opj_image_t *p_image,
        /* loop */
        OPJ_UINT32  compno, resno;
        /* pointers */
-       const opj_tcp_v2_t *l_tcp = 00;
+       const opj_tcp_t *l_tcp = 00;
        const opj_tccp_t * l_tccp = 00;
        const opj_image_comp_t * l_img_comp = 00;
 
@@ -582,10 +583,10 @@ void opj_get_encoding_parameters( const opj_image_t *p_image,
        q = p_tileno / p_cp->tw;
 
        /* find extent of tile */
-       *p_tx0 = int_max(p_cp->tx0 + p * p_cp->tdx, p_image->x0);
-       *p_tx1 = int_min(p_cp->tx0 + (p + 1) * p_cp->tdx, p_image->x1);
-       *p_ty0 = int_max(p_cp->ty0 + q * p_cp->tdy, p_image->y0);
-       *p_ty1 = int_min(p_cp->ty0 + (q + 1) * p_cp->tdy, p_image->y1);
+       *p_tx0 = opj_int_max(p_cp->tx0 + p * p_cp->tdx, p_image->x0);
+       *p_tx1 = opj_int_min(p_cp->tx0 + (p + 1) * p_cp->tdx, p_image->x1);
+       *p_ty0 = opj_int_max(p_cp->ty0 + q * p_cp->tdy, p_image->y0);
+       *p_ty1 = opj_int_min(p_cp->ty0 + (q + 1) * p_cp->tdy, p_image->y1);
 
        /* max precision is 0 (can only grow) */
        *p_max_prec = 0;
@@ -605,10 +606,10 @@ void opj_get_encoding_parameters( const opj_image_t *p_image,
                OPJ_UINT32 l_product;
                OPJ_INT32 l_tcx0, l_tcy0, l_tcx1, l_tcy1;
 
-               l_tcx0 = int_ceildiv(*p_tx0, l_img_comp->dx);
-               l_tcy0 = int_ceildiv(*p_ty0, l_img_comp->dy);
-               l_tcx1 = int_ceildiv(*p_tx1, l_img_comp->dx);
-               l_tcy1 = int_ceildiv(*p_ty1, l_img_comp->dy);
+               l_tcx0 = opj_int_ceildiv(*p_tx0, l_img_comp->dx);
+               l_tcy0 = opj_int_ceildiv(*p_ty0, l_img_comp->dy);
+               l_tcx1 = opj_int_ceildiv(*p_tx1, l_img_comp->dx);
+               l_tcy1 = opj_int_ceildiv(*p_ty1, l_img_comp->dy);
 
                if (l_tccp->numresolutions > *p_max_res) {
                        *p_max_res = l_tccp->numresolutions;
@@ -626,22 +627,22 @@ void opj_get_encoding_parameters( const opj_image_t *p_image,
                        l_dy = l_img_comp->dy * (1 << (l_pdy + l_tccp->numresolutions - 1 - resno));
 
                        /* take the minimum size for dx for each comp and resolution */
-                       *p_dx_min = uint_min(*p_dx_min, l_dx);
-                       *p_dy_min = uint_min(*p_dy_min, l_dy);
+                       *p_dx_min = opj_uint_min(*p_dx_min, l_dx);
+                       *p_dy_min = opj_uint_min(*p_dy_min, l_dy);
 
                        /* various calculations of extents */
                        l_level_no = l_tccp->numresolutions - 1 - resno;
 
-                       l_rx0 = int_ceildivpow2(l_tcx0, l_level_no);
-                       l_ry0 = int_ceildivpow2(l_tcy0, l_level_no);
-                       l_rx1 = int_ceildivpow2(l_tcx1, l_level_no);
-                       l_ry1 = int_ceildivpow2(l_tcy1, l_level_no);
+                       l_rx0 = opj_int_ceildivpow2(l_tcx0, l_level_no);
+                       l_ry0 = opj_int_ceildivpow2(l_tcy0, l_level_no);
+                       l_rx1 = opj_int_ceildivpow2(l_tcx1, l_level_no);
+                       l_ry1 = opj_int_ceildivpow2(l_tcy1, l_level_no);
 
-                       l_px0 = int_floordivpow2(l_rx0, l_pdx) << l_pdx;
-                       l_py0 = int_floordivpow2(l_ry0, l_pdy) << l_pdy;
-                       l_px1 = int_ceildivpow2(l_rx1, l_pdx) << l_pdx;
+                       l_px0 = opj_int_floordivpow2(l_rx0, l_pdx) << l_pdx;
+                       l_py0 = opj_int_floordivpow2(l_ry0, l_pdy) << l_pdy;
+                       l_px1 = opj_int_ceildivpow2(l_rx1, l_pdx) << l_pdx;
 
-                       py1 = int_ceildivpow2(l_ry1, l_pdy) << l_pdy;
+                       py1 = opj_int_ceildivpow2(l_ry1, l_pdy) << l_pdy;
 
                        l_pw = (l_rx0==l_rx1)?0:((l_px1 - l_px0) >> l_pdx);
                        l_ph = (l_ry0==l_ry1)?0:((py1 - l_py0) >> l_pdy);
@@ -660,7 +661,7 @@ void opj_get_encoding_parameters(   const opj_image_t *p_image,
 
 
 void opj_get_all_encoding_parameters(   const opj_image_t *p_image,
-                                        const opj_cp_v2_t *p_cp,
+                                        const opj_cp_t *p_cp,
                                         OPJ_UINT32 tileno,
                                         OPJ_INT32 * p_tx0,
                                         OPJ_INT32 * p_tx1,
@@ -676,7 +677,7 @@ void opj_get_all_encoding_parameters(   const opj_image_t *p_image,
        OPJ_UINT32 compno, resno;
 
        /* pointers*/
-       const opj_tcp_v2_t *tcp = 00;
+       const opj_tcp_t *tcp = 00;
        const opj_tccp_t * l_tccp = 00;
        const opj_image_comp_t * l_img_comp = 00;
 
@@ -701,10 +702,10 @@ 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 = int_max(p_cp->tx0 + p * p_cp->tdx, p_image->x0);
-       *p_tx1 = int_min(p_cp->tx0 + (p + 1) * p_cp->tdx, p_image->x1);
-       *p_ty0 = int_max(p_cp->ty0 + q * p_cp->tdy, p_image->y0);
-       *p_ty1 = int_min(p_cp->ty0 + (q + 1) * p_cp->tdy, p_image->y1);
+       *p_tx0 = opj_int_max(p_cp->tx0 + p * p_cp->tdx, p_image->x0);
+       *p_tx1 = opj_int_min(p_cp->tx0 + (p + 1) * p_cp->tdx, p_image->x1);
+       *p_ty0 = opj_int_max(p_cp->ty0 + q * p_cp->tdy, p_image->y0);
+       *p_ty1 = opj_int_min(p_cp->ty0 + (q + 1) * p_cp->tdy, p_image->y1);
 
        /* max precision and resolution is 0 (can only grow)*/
        *p_max_prec = 0;
@@ -725,10 +726,10 @@ void opj_get_all_encoding_parameters(   const opj_image_t *p_image,
 
                lResolutionPtr = p_resolutions[compno];
 
-               l_tcx0 = int_ceildiv(*p_tx0, l_img_comp->dx);
-               l_tcy0 = int_ceildiv(*p_ty0, l_img_comp->dy);
-               l_tcx1 = int_ceildiv(*p_tx1, l_img_comp->dx);
-               l_tcy1 = int_ceildiv(*p_ty1, l_img_comp->dy);
+               l_tcx0 = opj_int_ceildiv(*p_tx0, l_img_comp->dx);
+               l_tcy0 = opj_int_ceildiv(*p_ty0, l_img_comp->dy);
+               l_tcx1 = opj_int_ceildiv(*p_tx1, l_img_comp->dx);
+               l_tcy1 = opj_int_ceildiv(*p_ty1, l_img_comp->dy);
 
                if (l_tccp->numresolutions > *p_max_res) {
                        *p_max_res = l_tccp->numresolutions;
@@ -747,18 +748,18 @@ void opj_get_all_encoding_parameters(   const opj_image_t *p_image,
                        l_dx = l_img_comp->dx * (1 << (l_pdx + l_level_no));
                        l_dy = l_img_comp->dy * (1 << (l_pdy + l_level_no));
                        /* take the minimum size for l_dx for each comp and resolution*/
-                       *p_dx_min = int_min(*p_dx_min, l_dx);
-                       *p_dy_min = int_min(*p_dy_min, l_dy);
+                       *p_dx_min = opj_int_min(*p_dx_min, l_dx);
+                       *p_dy_min = opj_int_min(*p_dy_min, l_dy);
 
                        /* various calculations of extents*/
-                       l_rx0 = int_ceildivpow2(l_tcx0, l_level_no);
-                       l_ry0 = int_ceildivpow2(l_tcy0, l_level_no);
-                       l_rx1 = int_ceildivpow2(l_tcx1, l_level_no);
-                       l_ry1 = int_ceildivpow2(l_tcy1, l_level_no);
-                       l_px0 = int_floordivpow2(l_rx0, l_pdx) << l_pdx;
-                       l_py0 = int_floordivpow2(l_ry0, l_pdy) << l_pdy;
-                       l_px1 = int_ceildivpow2(l_rx1, l_pdx) << l_pdx;
-                       py1 = int_ceildivpow2(l_ry1, l_pdy) << l_pdy;
+                       l_rx0 = opj_int_ceildivpow2(l_tcx0, l_level_no);
+                       l_ry0 = opj_int_ceildivpow2(l_tcy0, l_level_no);
+                       l_rx1 = opj_int_ceildivpow2(l_tcx1, l_level_no);
+                       l_ry1 = opj_int_ceildivpow2(l_tcy1, l_level_no);
+                       l_px0 = opj_int_floordivpow2(l_rx0, l_pdx) << l_pdx;
+                       l_py0 = opj_int_floordivpow2(l_ry0, l_pdy) << l_pdy;
+                       l_px1 = opj_int_ceildivpow2(l_rx1, l_pdx) << l_pdx;
+                       py1 = opj_int_ceildivpow2(l_ry1, l_pdy) << l_pdy;
                        l_pw = (l_rx0==l_rx1)?0:((l_px1 - l_px0) >> l_pdx);
                        l_ph = (l_ry0==l_ry1)?0:((py1 - l_py0) >> l_pdy);
                        *lResolutionPtr++ = l_pw;
@@ -778,7 +779,7 @@ void opj_get_all_encoding_parameters(   const opj_image_t *p_image,
 }
 
 opj_pi_iterator_t * opj_pi_create(     const opj_image_t *image,
-                                    const opj_cp_v2_t *cp,
+                                    const opj_cp_t *cp,
                                     OPJ_UINT32 tileno )
 {
        /* loop*/
@@ -788,7 +789,7 @@ opj_pi_iterator_t * opj_pi_create(  const opj_image_t *image,
 
        /* pointers to tile coding parameters and components.*/
        opj_pi_iterator_t *l_pi = 00;
-       opj_tcp_v2_t *tcp = 00;
+       opj_tcp_t *tcp = 00;
        const opj_tccp_t *tccp = 00;
 
        /* current packet iterator being allocated*/
@@ -841,7 +842,7 @@ opj_pi_iterator_t * opj_pi_create(  const opj_image_t *image,
        return l_pi;
 }
 
-void opj_pi_update_encode_poc_and_final (   opj_cp_v2_t *p_cp,
+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,
@@ -855,13 +856,15 @@ void opj_pi_update_encode_poc_and_final (   opj_cp_v2_t *p_cp,
        /* loop*/
        OPJ_UINT32 pino;
        /* tile coding parameter*/
-       opj_tcp_v2_t *l_tcp = 00;
+       opj_tcp_t *l_tcp = 00;
        /* current poc being updated*/
        opj_poc_t * l_current_poc = 00;
 
        /* number of pocs*/
        OPJ_UINT32 l_poc_bound;
 
+    OPJ_ARG_NOT_USED(p_max_res);
+
        /* preconditions in debug*/
        assert(p_cp != 00);
        assert(p_tileno < p_cp->tw * p_cp->th);
@@ -917,7 +920,7 @@ void opj_pi_update_encode_poc_and_final (   opj_cp_v2_t *p_cp,
        }
 }
 
-void opj_pi_update_encode_not_poc (    opj_cp_v2_t *p_cp,
+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,
@@ -932,7 +935,7 @@ void opj_pi_update_encode_not_poc ( opj_cp_v2_t *p_cp,
        /* loop*/
        OPJ_UINT32 pino;
        /* tile coding parameter*/
-       opj_tcp_v2_t *l_tcp = 00;
+       opj_tcp_t *l_tcp = 00;
        /* current poc being updated*/
        opj_poc_t * l_current_poc = 00;
        /* number of pocs*/
@@ -973,7 +976,7 @@ void opj_pi_update_encode_not_poc ( opj_cp_v2_t *p_cp,
 }
 
 void opj_pi_update_decode_poc (opj_pi_iterator_t * p_pi,
-                               opj_tcp_v2_t * p_tcp,
+                               opj_tcp_t * p_tcp,
                                OPJ_UINT32 p_max_precision,
                                OPJ_UINT32 p_max_res)
 {
@@ -986,6 +989,8 @@ void opj_pi_update_decode_poc (opj_pi_iterator_t * p_pi,
        opj_pi_iterator_t * l_current_pi = 00;
        opj_poc_t* l_current_poc = 0;
 
+    OPJ_ARG_NOT_USED(p_max_res);
+
        /* preconditions in debug*/
        assert(p_pi != 00);
        assert(p_tcp != 00);
@@ -1013,7 +1018,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,
-                                   opj_tcp_v2_t * p_tcp,
+                                   opj_tcp_t * p_tcp,
                                    OPJ_UINT32 p_max_precision,
                                    OPJ_UINT32 p_max_res)
 {
@@ -1049,14 +1054,14 @@ void opj_pi_update_decode_not_poc (opj_pi_iterator_t * p_pi,
 
 
 
-opj_bool opj_pi_check_next_level(      OPJ_INT32 pos,
-                                                               opj_cp_v2_t *cp,
+OPJ_BOOL opj_pi_check_next_level(      OPJ_INT32 pos,
+                                                               opj_cp_t *cp,
                                                                OPJ_UINT32 tileno,
                                                                OPJ_UINT32 pino,
                                                                const OPJ_CHAR *prog)
 {
        OPJ_INT32 i;
-       opj_tcp_v2_t *tcps =&cp->tcps[tileno];
+       opj_tcp_t *tcps =&cp->tcps[tileno];
        opj_poc_t *tcp = &tcps->pocs[pino];
 
        if(pos>=0){
@@ -1097,7 +1102,7 @@ opj_bool opj_pi_check_next_level( OPJ_INT32 pos,
                            break;
                    case 'P':
                            switch(tcp->prg){
-                                   case LRCP||RLCP:
+                                   case OPJ_LRCP||OPJ_RLCP:
                                            if(tcp->prc_t == tcp->prcE){
                                                    if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)){
                                                            return OPJ_TRUE;
@@ -1138,7 +1143,7 @@ opj_bool opj_pi_check_next_level( OPJ_INT32 pos,
 ==========================================================
 */
 opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
-                                                                               opj_cp_v2_t *p_cp,
+                                                                               opj_cp_t *p_cp,
                                                                                OPJ_UINT32 p_tile_no)
 {
        /* loop */
@@ -1160,7 +1165,7 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
 
        /* pointers */
        opj_pi_iterator_t *l_pi = 00;
-       opj_tcp_v2_t *l_tcp = 00;
+       opj_tcp_t *l_tcp = 00;
        const opj_tccp_t *l_tccp = 00;
        opj_pi_comp_t *l_current_comp = 00;
        opj_image_comp_t * l_img_comp = 00;
@@ -1176,7 +1181,7 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
        l_tcp = &p_cp->tcps[p_tile_no];
        l_bound = l_tcp->numpocs+1;
 
-       l_data_stride = 4 * J2K_MAXRLVLS;
+       l_data_stride = 4 * OPJ_J2K_MAXRLVLS;
        l_tmp_data = (OPJ_UINT32*)opj_malloc(
                l_data_stride * p_image->numcomps * sizeof(OPJ_UINT32));
        if
@@ -1276,11 +1281,10 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
        }
        ++l_current_pi;
 
-       for
-               (pino = 1 ; pino<l_bound ; ++pino )
+       for (pino = 1 ; pino<l_bound ; ++pino )
        {
-               opj_pi_comp_t *l_current_comp = l_current_pi->comps;
-               opj_image_comp_t * l_img_comp = p_image->comps;
+               l_current_comp = l_current_pi->comps;
+               l_img_comp = p_image->comps;
                l_tccp = l_tcp->tccps;
 
                l_current_pi->tx0 = l_tx0;
@@ -1340,7 +1344,7 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
 
 
 opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image,
-                                            opj_cp_v2_t *p_cp,
+                                            opj_cp_t *p_cp,
                                             OPJ_UINT32 p_tile_no,
                                             J2K_T2_MODE p_t2_mode )
 {
@@ -1363,7 +1367,7 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image,
 
        /* pointers*/
        opj_pi_iterator_t *l_pi = 00;
-       opj_tcp_v2_t *l_tcp = 00;
+       opj_tcp_t *l_tcp = 00;
        const opj_tccp_t *l_tccp = 00;
        opj_pi_comp_t *l_current_comp = 00;
        opj_image_comp_t * l_img_comp = 00;
@@ -1379,7 +1383,7 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image,
        l_tcp = &p_cp->tcps[p_tile_no];
        l_bound = l_tcp->numpocs+1;
 
-       l_data_stride = 4 * J2K_MAXRLVLS;
+       l_data_stride = 4 * OPJ_J2K_MAXRLVLS;
        l_tmp_data = (OPJ_UINT32*)opj_malloc(
                l_data_stride * p_image->numcomps * sizeof(OPJ_UINT32));
        if (! l_tmp_data) {
@@ -1470,8 +1474,8 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image,
        ++l_current_pi;
 
        for (pino = 1 ; pino<l_bound ; ++pino ) {
-               opj_pi_comp_t *l_current_comp = l_current_pi->comps;
-               opj_image_comp_t * l_img_comp = p_image->comps;
+               l_current_comp = l_current_pi->comps;
+               l_img_comp = p_image->comps;
                l_tccp = l_tcp->tccps;
 
                l_current_pi->tx0 = l_tx0;
@@ -1526,7 +1530,7 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image,
 }
 
 void opj_pi_create_encode(     opj_pi_iterator_t *pi,
-                                                       opj_cp_v2_t *cp,
+                                                       opj_cp_t *cp,
                                                        OPJ_UINT32 tileno,
                                                        OPJ_UINT32 pino,
                                                        OPJ_UINT32 tpnum,
@@ -1536,7 +1540,7 @@ void opj_pi_create_encode(        opj_pi_iterator_t *pi,
        const OPJ_CHAR *prog;
        OPJ_INT32 i;
        OPJ_UINT32 incr_top=1,resetX=0;
-       opj_tcp_v2_t *tcps =&cp->tcps[tileno];
+       opj_tcp_t *tcps =&cp->tcps[tileno];
        opj_poc_t *tcp= &tcps->pocs[pino];
 
        prog = opj_j2k_convert_progression_order(tcp->prg);
@@ -1574,8 +1578,8 @@ void opj_pi_create_encode(        opj_pi_iterator_t *pi,
                                break;
                        case 'P':
                                switch(tcp->prg){
-                               case LRCP:
-                               case RLCP:
+                               case OPJ_LRCP:
+                               case OPJ_RLCP:
                                        pi[pino].poc.precno0 = tcp->prcS;
                                        pi[pino].poc.precno1 = tcp->prcE;
                                        break;
@@ -1613,8 +1617,8 @@ void opj_pi_create_encode(        opj_pi_iterator_t *pi,
                                        break;
                                case 'P':
                                        switch(tcp->prg){
-                                       case LRCP:
-                                       case RLCP:
+                                       case OPJ_LRCP:
+                                       case OPJ_RLCP:
                                                tcp->prc_t = tcp->prcS;
                                                pi[pino].poc.precno0 = tcp->prc_t;
                                                pi[pino].poc.precno1 = tcp->prc_t+1;
@@ -1652,8 +1656,8 @@ void opj_pi_create_encode(        opj_pi_iterator_t *pi,
                                        break;
                                case 'P':
                                        switch(tcp->prg){
-                                       case LRCP:
-                                       case RLCP:
+                                       case OPJ_LRCP:
+                                       case OPJ_RLCP:
                                                pi[pino].poc.precno0 = tcp->prc_t-1;
                                                pi[pino].poc.precno1 = tcp->prc_t;
                                                break;
@@ -1724,8 +1728,8 @@ void opj_pi_create_encode(        opj_pi_iterator_t *pi,
                                                break;
                                        case 'P':
                                                switch(tcp->prg){
-                                               case LRCP:
-                                               case RLCP:
+                                               case OPJ_LRCP:
+                                               case OPJ_RLCP:
                                                        if(tcp->prc_t == tcp->prcE){
                                                                if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)){
                                                                        tcp->prc_t = tcp->prcS;
@@ -1816,7 +1820,7 @@ void opj_pi_destroy(opj_pi_iterator_t *p_pi,
 
 
 void opj_pi_update_encoding_parameters(        const opj_image_t *p_image,
-                                        opj_cp_v2_t *p_cp,
+                                        opj_cp_t *p_cp,
                                         OPJ_UINT32 p_tile_no )
 {
        /* encoding parameters to set */
@@ -1826,7 +1830,7 @@ void opj_pi_update_encoding_parameters(   const opj_image_t *p_image,
        OPJ_UINT32 l_dx_min,l_dy_min;
 
        /* pointers */
-       opj_tcp_v2_t *l_tcp = 00;
+       opj_tcp_t *l_tcp = 00;
 
        /* preconditions */
        assert(p_cp != 00);
@@ -1846,21 +1850,21 @@ void opj_pi_update_encoding_parameters( const opj_image_t *p_image,
        }
 }
 
-opj_bool opj_pi_next(opj_pi_iterator_t * pi) {
+OPJ_BOOL opj_pi_next(opj_pi_iterator_t * pi) {
        switch (pi->poc.prg) {
-               case LRCP:
+               case OPJ_LRCP:
                        return opj_pi_next_lrcp(pi);
-               case RLCP:
+               case OPJ_RLCP:
                        return opj_pi_next_rlcp(pi);
-               case RPCL:
+               case OPJ_RPCL:
                        return opj_pi_next_rpcl(pi);
-               case PCRL:
+               case OPJ_PCRL:
                        return opj_pi_next_pcrl(pi);
-               case CPRL:
+               case OPJ_CPRL:
                        return opj_pi_next_cprl(pi);
-               case PROG_UNKNOWN:
+               case OPJ_PROG_UNKNOWN:
                        return OPJ_FALSE;
        }
        
        return OPJ_FALSE;
-}
\ No newline at end of file
+}