remove deprecated v1 style function j2k_read_cod
[openjpeg.git] / libopenjpeg / j2k.c
index 14b9be2cde6e47e14d325365bd83ac0aebf5eccb..6fcf4c4b3b325e00960081a172aed103fbfdb2f1 100644 (file)
@@ -392,12 +392,6 @@ static opj_bool j2k_write_soc_v2(  opj_j2k_v2_t *p_j2k,
                                                                        struct opj_stream_private *p_stream,
                                                                        struct opj_event_mgr * p_manager );
 
-/**
-Read the SOC marker (Start of Codestream)
-@param j2k J2K handle
-*/
-static void j2k_read_soc(opj_j2k_t *j2k);
-
 /**
  * Reads a SOC marker (Start of Codestream)
  * @param      p_header_data   the data contained in the SOC box.
@@ -405,7 +399,7 @@ static void j2k_read_soc(opj_j2k_t *j2k);
  * @param      p_header_size   the size of the data contained in the SOC marker.
  * @param      p_manager               the user event manager.
 */
-static opj_bool j2k_read_soc_v2(
+static opj_bool opj_j2k_read_soc(
                                        opj_j2k_v2_t *p_j2k,
                                        struct opj_stream_private *p_stream,
                                        struct opj_event_mgr * p_manager
@@ -428,12 +422,6 @@ static opj_bool j2k_write_siz_v2(  opj_j2k_v2_t *p_j2k,
                                                                        struct opj_stream_private *p_stream,
                                                                        struct opj_event_mgr * p_manager );
 
-/**
-Read the SIZ marker (image and tile size)
-@param j2k J2K handle
-*/
-static void j2k_read_siz(opj_j2k_t *j2k);
-
 /**
  * Reads a SIZ marker (image and tile size)
  * @param      p_header_data   the data contained in the SIZ box.
@@ -441,12 +429,10 @@ static void j2k_read_siz(opj_j2k_t *j2k);
  * @param      p_header_size   the size of the data contained in the SIZ marker.
  * @param      p_manager               the user event manager.
 */
-static opj_bool j2k_read_siz_v2 (
-                                                 opj_j2k_v2_t *p_j2k,
-                                                 OPJ_BYTE * p_header_data,
-                                                 OPJ_UINT32 p_header_size,
-                                                 struct opj_event_mgr * p_manager
-                                       );
+static opj_bool opj_j2k_read_siz(opj_j2k_v2_t *p_j2k,
+                                 OPJ_BYTE * p_header_data,
+                                 OPJ_UINT32 p_header_size,
+                                 opj_event_mgr_t * p_manager);
 
 /**
 Write the COM marker (comment)
@@ -512,12 +498,6 @@ static opj_bool j2k_write_cod_v2(  opj_j2k_v2_t *p_j2k,
                                                                        struct opj_stream_private *p_stream,
                                                                        struct opj_event_mgr * p_manager );
 
-/**
-Read the COD marker (coding style default)
-@param j2k J2K handle
-*/
-static void j2k_read_cod(opj_j2k_t *j2k);
-
 /**
  * Reads a COD marker (Coding Styke defaults)
  * @param      p_header_data   the data contained in the COD box.
@@ -525,7 +505,7 @@ static void j2k_read_cod(opj_j2k_t *j2k);
  * @param      p_header_size   the size of the data contained in the COD marker.
  * @param      p_manager               the user event manager.
 */
-static opj_bool j2k_read_cod_v2 (
+static opj_bool opj_j2k_read_cod (
                                        opj_j2k_v2_t *p_j2k,
                                        OPJ_BYTE * p_header_data,
                                        OPJ_UINT32 p_header_size,
@@ -926,11 +906,6 @@ Write the SOT marker (start of tile-part)
 @param j2k J2K handle
 */
 static void j2k_write_sot(opj_j2k_t *j2k);
-/**
-Read the SOT marker (start of tile-part)
-@param j2k J2K handle
-*/
-static void j2k_read_sot(opj_j2k_t *j2k);
 
 /**
  * Writes the SOT marker (Start of tile-part)
@@ -953,12 +928,11 @@ static opj_bool j2k_write_sot_v2( opj_j2k_v2_t *p_j2k,
  * @param      p_header_size   the size of the data contained in the PPT marker.
  * @param      p_manager               the user event manager.
 */
-static opj_bool j2k_read_sot_v2 (
-                                               opj_j2k_v2_t *p_j2k,
-                                               OPJ_BYTE * p_header_data,
-                                               OPJ_UINT32 p_header_size,
-                                               struct opj_event_mgr * p_manager
-                                       );
+static opj_bool opj_j2k_read_sot (  opj_j2k_v2_t *p_j2k,
+                                    OPJ_BYTE * p_header_data,
+                                    OPJ_UINT32 p_header_size,
+                                    opj_event_mgr_t * p_manager );
+
 /**
 Write the SOD marker (start of data)
 @param j2k J2K handle
@@ -981,12 +955,6 @@ static opj_bool j2k_write_sod_v2(  opj_j2k_v2_t *p_j2k,
                                                                        const struct opj_stream_private *p_stream,
                                                                        struct opj_event_mgr * p_manager );
 
-/**
-Read the SOD marker (start of data)
-@param j2k J2K handle
-*/
-static void j2k_read_sod(opj_j2k_t *j2k);
-
 /**
  * Reads a SOD marker (Start Of Data)
  *
@@ -995,11 +963,9 @@ static void j2k_read_sod(opj_j2k_t *j2k);
  * @param      p_header_size   the size of the data contained in the SOD marker.
  * @param      p_manager               the user event manager.
 */
-static opj_bool j2k_read_sod_v2 (
-                                               opj_j2k_v2_t *p_j2k,
-                                               struct opj_stream_private *p_stream,
-                                               struct opj_event_mgr * p_manager
-                                       );
+static opj_bool opj_j2k_read_sod(   opj_j2k_v2_t *p_j2k,
+                                    opj_stream_private_t *p_stream,
+                                    opj_event_mgr_t * p_manager );
 
 /**
  * Updates the Tile Length Marker.
@@ -1475,14 +1441,14 @@ const opj_dec_memory_marker_handler_t j2k_memory_marker_handler_tab [] =
   {J2K_MS_MCC, J2K_DEC_STATE_MH | J2K_DEC_STATE_TPH, j2k_read_mcc},
   {J2K_MS_MCO, J2K_DEC_STATE_MH | J2K_DEC_STATE_TPH, j2k_read_mco},
 #endif
-  {J2K_MS_SOT, J2K_STATE_MH | J2K_STATE_TPHSOT, j2k_read_sot_v2},
+  {J2K_MS_SOT, J2K_STATE_MH | J2K_STATE_TPHSOT, opj_j2k_read_sot},
   {J2K_MS_COD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_cod_v2},
   {J2K_MS_COC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_coc_v2},
   {J2K_MS_RGN, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_rgn_v2},
   {J2K_MS_QCD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_qcd_v2},
   {J2K_MS_QCC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_qcc_v2},
   {J2K_MS_POC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_poc_v2},
-  {J2K_MS_SIZ, J2K_STATE_MHSIZ , j2k_read_siz_v2},
+  {J2K_MS_SIZ, J2K_STATE_MHSIZ , opj_j2k_read_siz},
   {J2K_MS_TLM, J2K_STATE_MH, j2k_read_tlm_v2},
   {J2K_MS_PLM, J2K_STATE_MH, j2k_read_plm_v2},
   {J2K_MS_PLT, J2K_STATE_TPH, j2k_read_plt_v2},
@@ -2115,14 +2081,7 @@ opj_bool j2k_write_soc_v2(       opj_j2k_v2_t *p_j2k,
        return OPJ_TRUE;
 }
 
-static void j2k_read_soc(opj_j2k_t *j2k) {     
-       j2k->state = J2K_STATE_MHSIZ;
-       /* Index */
-       if (j2k->cstr_info) {
-               j2k->cstr_info->main_head_start = cio_tell(j2k->cio) - 2;
-               j2k->cstr_info->codestream_size = cio_numbytesleft(j2k->cio) + 2 - j2k->cstr_info->main_head_start;
-       }
-}
+
 
 /**
  * Reads a SOC marker (Start of Codestream)
@@ -2131,7 +2090,7 @@ static void j2k_read_soc(opj_j2k_t *j2k) {
  * @param      p_header_size   the size of the data contained in the SOC marker.
  * @param      p_manager               the user event manager.
 */
-static opj_bool j2k_read_soc_v2(       opj_j2k_v2_t *p_j2k,
+static opj_bool opj_j2k_read_soc(      opj_j2k_v2_t *p_j2k,
                                                                        struct opj_stream_private *p_stream,
                                                                        struct opj_event_mgr * p_manager )
 {
@@ -2302,220 +2261,6 @@ opj_bool j2k_write_siz_v2(      opj_j2k_v2_t *p_j2k,
        return OPJ_TRUE;
 }
 
-static void j2k_read_siz(opj_j2k_t *j2k) {
-       int len;
-       OPJ_UINT32 i;
-       
-       opj_cio_t *cio = j2k->cio;
-       opj_image_t *image = j2k->image;
-       opj_cp_t *cp = j2k->cp;
-       
-       len = cio_read(cio, 2);                 /* Lsiz */
-       cio_read(cio, 2);                               /* Rsiz (capabilities) */
-       image->x1 = cio_read(cio, 4);   /* Xsiz */
-       image->y1 = cio_read(cio, 4);   /* Ysiz */
-       image->x0 = cio_read(cio, 4);   /* X0siz */
-       image->y0 = cio_read(cio, 4);   /* Y0siz */
-       cp->tdx = cio_read(cio, 4);             /* XTsiz */
-       cp->tdy = cio_read(cio, 4);             /* YTsiz */
-       cp->tx0 = cio_read(cio, 4);             /* XT0siz */
-       cp->ty0 = cio_read(cio, 4);             /* YT0siz */
-       
-  /* the following code triggers: */
-  /* warning: comparison of unsigned expression < 0 is always false */
-#if 0
-       if ((image->x0<0)||(image->x1<0)||(image->y0<0)||(image->y1<0)) {
-               opj_event_msg(j2k->cinfo, EVT_ERROR,
-                                                                       "%s: invalid image size (x0:%d, x1:%d, y0:%d, y1:%d)\n",
-                                                                       image->x0,image->x1,image->y0,image->y1);
-               return;
-       }
-#endif
-       
-       image->numcomps = cio_read(cio, 2);     /* Csiz */
-
-#ifdef USE_JPWL
-       if (j2k->cp->correct) {
-               /* if JPWL is on, we check whether TX errors have damaged
-                 too much the SIZ parameters */
-               if (!(image->x1 * image->y1)) {
-                       opj_event_msg(j2k->cinfo, EVT_ERROR,
-                               "JPWL: bad image size (%d x %d)\n",
-                               image->x1, image->y1);
-                       if (!JPWL_ASSUME || JPWL_ASSUME) {
-                               opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
-                               return;
-                       }
-               }
-    assert( len >= 38 );
-               if (image->numcomps != (OPJ_UINT32)((len - 38) / 3)) {
-                       opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR,
-                               "JPWL: Csiz is %d => space in SIZ only for %d comps.!!!\n",
-                               image->numcomps, ((len - 38) / 3));
-                       if (!JPWL_ASSUME) {
-                               opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
-                               return;
-                       }
-                       /* we try to correct */
-                       opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust this\n");
-                       if (image->numcomps < (OPJ_UINT32)((len - 38) / 3)) {
-                               len = 38 + 3 * image->numcomps;
-                               opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting Lsiz to %d => HYPOTHESIS!!!\n",
-                                       len);                           
-                       } else {
-                               image->numcomps = ((len - 38) / 3);
-                               opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting Csiz to %d => HYPOTHESIS!!!\n",
-                                       image->numcomps);                               
-                       }
-               }
-
-               /* update components number in the jpwl_exp_comps filed */
-               cp->exp_comps = image->numcomps;
-       }
-#endif /* USE_JPWL */
-
-       image->comps = (opj_image_comp_t*) opj_calloc(image->numcomps, sizeof(opj_image_comp_t));
-       for (i = 0; i < image->numcomps; i++) {
-               int tmp, w, h;
-               tmp = cio_read(cio, 1);         /* Ssiz_i */
-               image->comps[i].prec = (tmp & 0x7f) + 1;
-               image->comps[i].sgnd = tmp >> 7;
-               image->comps[i].dx = cio_read(cio, 1);  /* XRsiz_i */
-               image->comps[i].dy = cio_read(cio, 1);  /* YRsiz_i */
-               
-#ifdef USE_JPWL
-               if (j2k->cp->correct) {
-               /* if JPWL is on, we check whether TX errors have damaged
-                       too much the SIZ parameters, again */
-                       if (!(image->comps[i].dx * image->comps[i].dy)) {
-                               opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR,
-                                       "JPWL: bad XRsiz_%d/YRsiz_%d (%d x %d)\n",
-                                       i, i, image->comps[i].dx, image->comps[i].dy);
-                               if (!JPWL_ASSUME) {
-                                       opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
-                                       return;
-                               }
-                               /* we try to correct */
-                               opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust them\n");
-                               if (!image->comps[i].dx) {
-                                       image->comps[i].dx = 1;
-                                       opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting XRsiz_%d to %d => HYPOTHESIS!!!\n",
-                                               i, image->comps[i].dx);
-                               }
-                               if (!image->comps[i].dy) {
-                                       image->comps[i].dy = 1;
-                                       opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting YRsiz_%d to %d => HYPOTHESIS!!!\n",
-                                               i, image->comps[i].dy);
-                               }
-                       }
-                       
-               }
-#endif /* USE_JPWL */
-
-               /* TODO: unused ? */
-               w = int_ceildiv(image->x1 - image->x0, image->comps[i].dx);
-               h = int_ceildiv(image->y1 - image->y0, image->comps[i].dy);
-
-               image->comps[i].resno_decoded = 0;      /* number of resolution decoded */
-               image->comps[i].factor = cp->reduce; /* reducing factor per component */
-       }
-       
-       cp->tw = int_ceildiv(image->x1 - cp->tx0, cp->tdx);
-       cp->th = int_ceildiv(image->y1 - cp->ty0, cp->tdy);
-
-#ifdef USE_JPWL
-       if (j2k->cp->correct) {
-               /* if JPWL is on, we check whether TX errors have damaged
-                 too much the SIZ parameters */
-               if ((cp->tw < 1) || (cp->th < 1) || (cp->tw > cp->max_tiles) || (cp->th > cp->max_tiles)) {
-                       opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR,
-                               "JPWL: bad number of tiles (%d x %d)\n",
-                               cp->tw, cp->th);
-                       if (!JPWL_ASSUME) {
-                               opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
-                               return;
-                       }
-                       /* we try to correct */
-                       opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust them\n");
-                       if (cp->tw < 1) {
-                               cp->tw= 1;
-                               opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting %d tiles in x => HYPOTHESIS!!!\n",
-                                       cp->tw);
-                       }
-                       if (cp->tw > cp->max_tiles) {
-                               cp->tw= 1;
-                               opj_event_msg(j2k->cinfo, EVT_WARNING, "- too large x, increase expectance of %d\n"
-                                       "- setting %d tiles in x => HYPOTHESIS!!!\n",
-                                       cp->max_tiles, cp->tw);
-                       }
-                       if (cp->th < 1) {
-                               cp->th= 1;
-                               opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting %d tiles in y => HYPOTHESIS!!!\n",
-                                       cp->th);
-                       }
-                       if (cp->th > cp->max_tiles) {
-                               cp->th= 1;
-                               opj_event_msg(j2k->cinfo, EVT_WARNING, "- too large y, increase expectance of %d to continue\n",
-                                       "- setting %d tiles in y => HYPOTHESIS!!!\n",
-                                       cp->max_tiles, cp->th);
-                       }
-               }
-       }
-#endif /* USE_JPWL */
-
-       cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t));
-       cp->tileno = (int*) opj_malloc(cp->tw * cp->th * sizeof(int));
-       cp->tileno_size = 0;
-       
-#ifdef USE_JPWL
-       if (j2k->cp->correct) {
-               if (!cp->tcps) {
-                       opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR,
-                               "JPWL: could not alloc tcps field of cp\n");
-                       if (!JPWL_ASSUME || JPWL_ASSUME) {
-                               opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
-                               return;
-                       }
-               }
-       }
-#endif /* USE_JPWL */
-
-       for (i = 0; i < (OPJ_UINT32)cp->tw * cp->th; i++) {
-               cp->tcps[i].POC = 0;
-               cp->tcps[i].numpocs = 0;
-               cp->tcps[i].first = 1;
-       }
-       
-       /* Initialization for PPM marker */
-       cp->ppm = 0;
-       cp->ppm_data = NULL;
-       cp->ppm_data_first = NULL;
-       cp->ppm_previous = 0;
-       cp->ppm_store = 0;
-
-       j2k->default_tcp->tccps = (opj_tccp_t*) opj_calloc(image->numcomps, sizeof(opj_tccp_t));
-       for (i = 0; i < (OPJ_UINT32)cp->tw * cp->th; i++) {
-               cp->tcps[i].tccps = (opj_tccp_t*) opj_malloc(image->numcomps * sizeof(opj_tccp_t));
-       }       
-       j2k->tile_data = (unsigned char**) opj_calloc(cp->tw * cp->th, sizeof(unsigned char*));
-       j2k->tile_len = (int*) opj_calloc(cp->tw * cp->th, sizeof(int));
-       j2k->state = J2K_STATE_MH;
-
-       /* Index */
-       if (j2k->cstr_info) {
-               opj_codestream_info_t *cstr_info = j2k->cstr_info;
-               cstr_info->image_w = image->x1 - image->x0;
-               cstr_info->image_h = image->y1 - image->y0;
-               cstr_info->numcomps = image->numcomps;
-               cstr_info->tw = cp->tw;
-               cstr_info->th = cp->th;
-               cstr_info->tile_x = cp->tdx;    
-               cstr_info->tile_y = cp->tdy;    
-               cstr_info->tile_Ox = cp->tx0;   
-               cstr_info->tile_Oy = cp->ty0;                   
-               cstr_info->tile = (opj_tile_info_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tile_info_t));              
-       }
-}
 
 
 /**
@@ -2525,12 +2270,11 @@ static void j2k_read_siz(opj_j2k_t *j2k) {
  * @param      p_header_size   the size of the data contained in the SIZ marker.
  * @param      p_manager               the user event manager.
 */
-opj_bool j2k_read_siz_v2 (
-                                   opj_j2k_v2_t *p_j2k,
-                                       OPJ_BYTE * p_header_data,
-                                       OPJ_UINT32 p_header_size,
-                                       struct opj_event_mgr * p_manager
-                                       )
+static opj_bool opj_j2k_read_siz(opj_j2k_v2_t *p_j2k,
+                                 OPJ_BYTE * p_header_data,
+                                 OPJ_UINT32 p_header_size,
+                                 opj_event_mgr_t * p_manager
+                                 )
 {
        OPJ_UINT32 l_size, i;
        OPJ_UINT32 l_nb_comp;
@@ -3126,39 +2870,6 @@ opj_bool j2k_write_cod_v2(       opj_j2k_v2_t *p_j2k,
        return OPJ_TRUE;
 }
 
-static void j2k_read_cod(opj_j2k_t *j2k) {
-       int len, pos;
-  OPJ_UINT32 i;
-       
-       opj_cio_t *cio = j2k->cio;
-       opj_cp_t *cp = j2k->cp;
-       opj_tcp_t *tcp = j2k->state == J2K_STATE_TPH ? &cp->tcps[j2k->curtileno] : j2k->default_tcp;
-       opj_image_t *image = j2k->image;
-       
-       len = cio_read(cio, 2);                         /* Lcod */
-       tcp->csty = cio_read(cio, 1);           /* Scod */
-       tcp->prg = (OPJ_PROG_ORDER)cio_read(cio, 1);            /* SGcod (A) */
-       tcp->numlayers = cio_read(cio, 2);      /* SGcod (B) */
-       tcp->mct = cio_read(cio, 1);            /* SGcod (C) */
-       
-       pos = cio_tell(cio);
-       for (i = 0; i < image->numcomps; i++) {
-               tcp->tccps[i].csty = tcp->csty & J2K_CP_CSTY_PRT;
-               cio_seek(cio, pos);
-               j2k_read_cox(j2k, i);
-       }
-
-       /* Index */
-       if (j2k->cstr_info) {
-               opj_codestream_info_t *cstr_info = j2k->cstr_info;
-               cstr_info->prog = tcp->prg;
-               cstr_info->numlayers = tcp->numlayers;
-               cstr_info->numdecompos = (int*) opj_malloc(image->numcomps * sizeof(int));
-               for (i = 0; i < image->numcomps; i++) {
-                       cstr_info->numdecompos[i] = tcp->tccps[i].numresolutions - 1;
-               }
-       }
-}
 
 /**
  * Reads a COD marker (Coding Styke defaults)
@@ -5208,157 +4919,7 @@ opj_bool j2k_write_sot_v2(      opj_j2k_v2_t *p_j2k,
 }
 
 
-static void j2k_read_sot(opj_j2k_t *j2k) {
-       int len, tileno, totlen, partno, numparts;
-  OPJ_UINT32 i;
-       opj_tcp_t *tcp = NULL;
-       char status = 0;
 
-       opj_cp_t *cp = j2k->cp;
-       opj_cio_t *cio = j2k->cio;
-
-       len = cio_read(cio, 2);
-       tileno = cio_read(cio, 2);
-
-#ifdef USE_JPWL
-       if (j2k->cp->correct) {
-
-               static int backup_tileno = 0;
-
-               /* tileno is negative or larger than the number of tiles!!! */
-               if ((tileno < 0) || (tileno >= (cp->tw * cp->th))) {
-                       opj_event_msg(j2k->cinfo, EVT_ERROR,
-                               "JPWL: bad tile number (%d out of a maximum of %d)\n",
-                               tileno, (cp->tw * cp->th));
-                       if (!JPWL_ASSUME) {
-                               opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
-                               return;
-                       }
-                       /* we try to correct */
-                       tileno = backup_tileno;
-                       opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust this\n"
-                               "- setting tile number to %d\n",
-                               tileno);
-               }
-
-               /* keep your private count of tiles */
-               backup_tileno++;
-       }
-  else
-#endif /* USE_JPWL */
-  {
-    /* tileno is negative or larger than the number of tiles!!! */
-    if ((tileno < 0) || (tileno >= (cp->tw * cp->th))) {
-      opj_event_msg(j2k->cinfo, EVT_ERROR,
-        "JPWL: bad tile number (%d out of a maximum of %d)\n",
-        tileno, (cp->tw * cp->th));
-      return;
-    }
-  }
-       
-       if (cp->tileno_size == 0) {
-               cp->tileno[cp->tileno_size] = tileno;
-               cp->tileno_size++;
-       } else {
-               i = 0;
-               assert(cp->tileno_size >= 0);
-               while (i < (OPJ_UINT32)cp->tileno_size && status == 0) {
-                       status = cp->tileno[i] == tileno ? 1 : 0;
-                       i++;
-               }
-               if (status == 0) {
-                       cp->tileno[cp->tileno_size] = tileno;
-                       cp->tileno_size++;
-               }
-       }
-       
-       totlen = cio_read(cio, 4);
-
-#ifdef USE_JPWL
-       if (j2k->cp->correct) {
-
-               /* totlen is negative or larger than the bytes left!!! */
-               if ((totlen < 0) || (totlen > (cio_numbytesleft(cio) + 8))) {
-                       opj_event_msg(j2k->cinfo, EVT_ERROR,
-                               "JPWL: bad tile byte size (%d bytes against %d bytes left)\n",
-                               totlen, cio_numbytesleft(cio) + 8);
-                       if (!JPWL_ASSUME) {
-                               opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
-                               return;
-                       }
-                       /* we try to correct */
-                       totlen = 0;
-                       opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust this\n"
-                               "- setting Psot to %d => assuming it is the last tile\n",
-                               totlen);
-               }
-
-       }
-  else
-#endif /* USE_JPWL */
-  {
-    /* totlen is negative or larger than the bytes left!!! */
-    if ((totlen < 0) || (totlen > (cio_numbytesleft(cio) + 8))) {
-      opj_event_msg(j2k->cinfo, EVT_ERROR,
-        "JPWL: bad tile byte size (%d bytes against %d bytes left)\n",
-        totlen, cio_numbytesleft(cio) + 8);
-      return;
-    }
-  }
-
-       if (!totlen)
-               totlen = cio_numbytesleft(cio) + 8;
-       
-       partno = cio_read(cio, 1);
-       numparts = cio_read(cio, 1);
-  
-  if (partno >= numparts) {
-    opj_event_msg(j2k->cinfo, EVT_WARNING, "SOT marker inconsistency in tile %d: tile-part index greater (%d) than number of tile-parts (%d)\n", tileno, partno, numparts);
-    numparts = partno+1;
-  }
-       
-       j2k->curtileno = tileno;
-       j2k->cur_tp_num = partno;
-       j2k->eot = cio_getbp(cio) - 12 + totlen;
-       j2k->state = J2K_STATE_TPH;
-       tcp = &cp->tcps[j2k->curtileno];
-
-       /* Index */
-       if (j2k->cstr_info) {
-               if (tcp->first) {
-                       if (tileno == 0) 
-                               j2k->cstr_info->main_head_end = cio_tell(cio) - 13;
-                       j2k->cstr_info->tile[tileno].tileno = tileno;
-                       j2k->cstr_info->tile[tileno].start_pos = cio_tell(cio) - 12;
-                       j2k->cstr_info->tile[tileno].end_pos = j2k->cstr_info->tile[tileno].start_pos + totlen - 1;                             
-    } else {
-                       j2k->cstr_info->tile[tileno].end_pos += totlen;
-               }
-    j2k->cstr_info->tile[tileno].num_tps = numparts;
-    if (numparts)
-      j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_realloc(j2k->cstr_info->tile[tileno].tp, numparts * sizeof(opj_tp_info_t));
-    else
-      j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_realloc(j2k->cstr_info->tile[tileno].tp, 10 * sizeof(opj_tp_info_t)); /* Fixme (10)*/
-               j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos = cio_tell(cio) - 12;
-               j2k->cstr_info->tile[tileno].tp[partno].tp_end_pos = 
-                       j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos + totlen - 1;
-       }
-       
-       if (tcp->first == 1) {          
-               /* Initialization PPT */
-               opj_tccp_t *tmp = tcp->tccps;
-               memcpy(tcp, j2k->default_tcp, sizeof(opj_tcp_t));
-               tcp->ppt = 0;
-               tcp->ppt_data = NULL;
-               tcp->ppt_data_first = NULL;
-               tcp->tccps = tmp;
-
-               for (i = 0; i < j2k->image->numcomps; i++) {
-                       tcp->tccps[i] = j2k->default_tcp->tccps[i];
-               }
-               cp->tcps[j2k->curtileno].first = 0;
-       }
-}
 
 /**
  * Reads a PPT marker (Packed packet headers, tile-part header)
@@ -5368,14 +4929,11 @@ static void j2k_read_sot(opj_j2k_t *j2k) {
  * @param      p_header_size   the size of the data contained in the PPT marker.
  * @param      p_manager               the user event manager.
 */
-opj_bool j2k_read_sot_v2 (
-                                               opj_j2k_v2_t *p_j2k,
-                                               OPJ_BYTE * p_header_data,
-                                               OPJ_UINT32 p_header_size,
-                                               struct opj_event_mgr * p_manager
-                                       )
+opj_bool opj_j2k_read_sot ( opj_j2k_v2_t *p_j2k,
+                            OPJ_BYTE * p_header_data,
+                            OPJ_UINT32 p_header_size,
+                            opj_event_mgr_t * p_manager )
 {
-
        opj_cp_v2_t *l_cp = 00;
        opj_tcp_v2_t *l_tcp = 00;
        OPJ_UINT32 l_tot_len, l_num_parts = 0;
@@ -5762,46 +5320,7 @@ opj_bool j2k_write_sod_v2(       opj_j2k_v2_t *p_j2k,
 }
 
 
-static void j2k_read_sod(opj_j2k_t *j2k) {
-       int len, truncate = 0, i;
-       unsigned char *data = NULL, *data_ptr = NULL;
-
-       opj_cio_t *cio = j2k->cio;
-       int curtileno = j2k->curtileno;
-
-       /* Index */
-       if (j2k->cstr_info) {
-               j2k->cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_end_header =
-                       cio_tell(cio) + j2k->pos_correction - 1;
-               if (j2k->cur_tp_num == 0)
-                       j2k->cstr_info->tile[j2k->curtileno].end_header = cio_tell(cio) + j2k->pos_correction - 1;
-               j2k->cstr_info->packno = 0;
-       }
-       
-       len = int_min(j2k->eot - cio_getbp(cio), cio_numbytesleft(cio) + 1);
-
-       if (len == cio_numbytesleft(cio) + 1) {
-               truncate = 1;           /* Case of a truncate codestream */
-       }       
-
-       data = j2k->tile_data[curtileno];
-       data = (unsigned char*) opj_realloc(data, (j2k->tile_len[curtileno] + len) * sizeof(unsigned char));
-
-       data_ptr = data + j2k->tile_len[curtileno];
-       for (i = 0; i < len; i++) {
-               data_ptr[i] = cio_read(cio, 1);
-       }
 
-       j2k->tile_len[curtileno] += len;
-       j2k->tile_data[curtileno] = data;
-       
-       if (!truncate) {
-               j2k->state = J2K_STATE_TPHSOT;
-       } else {
-               j2k->state = J2K_STATE_NEOC;    /* RAJOUTE !! */
-       }
-       j2k->cur_tp_num++;
-}
 
 /**
  * Reads a SOD marker (Start Of Data)
@@ -5811,11 +5330,10 @@ static void j2k_read_sod(opj_j2k_t *j2k) {
  * @param      p_header_size   the size of the data contained in the SOD marker.
  * @param      p_manager               the user event manager.
 */
-opj_bool j2k_read_sod_v2 (
-                                               opj_j2k_v2_t *p_j2k,
-                                               struct opj_stream_private *p_stream,
-                                               struct opj_event_mgr * p_manager
-                                       )
+opj_bool opj_j2k_read_sod (opj_j2k_v2_t *p_j2k,
+                           opj_stream_private_t *p_stream,
+                                                  opj_event_mgr_t * p_manager
+                           )
 {
        OPJ_UINT32 l_current_read_size;
        opj_codestream_index_t * l_cstr_index = 00;
@@ -6609,12 +6127,12 @@ typedef struct opj_dec_mstabent {
 } opj_dec_mstabent_t;
 
 opj_dec_mstabent_t j2k_dec_mstab[] = {
-  {J2K_MS_SOC, J2K_STATE_MHSOC, j2k_read_soc},
-  {J2K_MS_SOT, J2K_STATE_MH | J2K_STATE_TPHSOT, j2k_read_sot},
-  {J2K_MS_SOD, J2K_STATE_TPH, j2k_read_sod},
+  /*{J2K_MS_SOC, J2K_STATE_MHSOC, j2k_read_soc},*/
+  /*{J2K_MS_SOT, J2K_STATE_MH | J2K_STATE_TPHSOT, j2k_read_sot},*/
+  /*{J2K_MS_SOD, J2K_STATE_TPH, j2k_read_sod},*/
   {J2K_MS_EOC, J2K_STATE_TPHSOT, j2k_read_eoc},
-  {J2K_MS_SIZ, J2K_STATE_MHSIZ, j2k_read_siz},
-  {J2K_MS_COD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_cod},
+  /*{J2K_MS_SIZ, J2K_STATE_MHSIZ, j2k_read_siz},*/
+  /*{J2K_MS_COD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_cod},*/
   {J2K_MS_COC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_coc},
   {J2K_MS_RGN, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_rgn},
   {J2K_MS_QCD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_qcd},
@@ -9153,7 +8671,7 @@ opj_bool j2k_read_header_procedure(       opj_j2k_v2_t *p_j2k,
        p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_MHSOC;
 
        /* Try to read the SOC marker, the codestream must begin with SOC marker */
-       if (! j2k_read_soc_v2(p_j2k,p_stream,p_manager)) {
+       if (! opj_j2k_read_soc(p_j2k,p_stream,p_manager)) {
                opj_event_msg_v2(p_manager, EVT_ERROR, "Expected a SOC marker \n");
                return OPJ_FALSE;
        }
@@ -9819,7 +9337,7 @@ opj_bool j2k_read_tile_header(    opj_j2k_v2_t * p_j2k,
                /* If we didn't skip data before, we need to read the SOD marker*/
                if (! p_j2k->m_specific_param.m_decoder.m_skip_data) {
                        /* Try to read the SOD marker and skip data ? FIXME */
-                       if (! j2k_read_sod_v2(p_j2k, p_stream, p_manager)) {
+                       if (! opj_j2k_read_sod(p_j2k, p_stream, p_manager)) {
                                return OPJ_FALSE;
                        }