return OPJ_TRUE;
}
-
-
-opj_bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, opj_codestream_info_t *cstr_info) {
- int l;
- int compno;
- int eof = 0;
- double tile_time, t1_time, dwt_time;
- opj_tcd_tile_t *tile = NULL;
-
- opj_t1_t *t1 = NULL; /* T1 component */
- opj_t2_t *t2 = NULL; /* T2 component */
-
- tcd->tcd_tileno = tileno;
- tcd->tcd_tile = &(tcd->tcd_image->tiles[tileno]);
- tcd->tcp = &(tcd->cp->tcps[tileno]);
- tile = tcd->tcd_tile;
-
- tile_time = opj_clock(); /* time needed to decode a tile */
- opj_event_msg(tcd->cinfo, EVT_INFO, "tile %d of %d\n", tileno + 1, tcd->cp->tw * tcd->cp->th);
-
- /* INDEX >> */
- if(cstr_info) {
- int resno, compno, numprec = 0;
- for (compno = 0; compno < cstr_info->numcomps; compno++) {
- opj_tcp_t *tcp = &tcd->cp->tcps[0];
- opj_tccp_t *tccp = &tcp->tccps[compno];
- opj_tcd_tilecomp_t *tilec_idx = &tile->comps[compno];
- for (resno = 0; resno < tilec_idx->numresolutions; resno++) {
- opj_tcd_resolution_t *res_idx = &tilec_idx->resolutions[resno];
- cstr_info->tile[tileno].pw[resno] = res_idx->pw;
- cstr_info->tile[tileno].ph[resno] = res_idx->ph;
- numprec += res_idx->pw * res_idx->ph;
- if (tccp->csty & J2K_CP_CSTY_PRT) {
- cstr_info->tile[tileno].pdx[resno] = tccp->prcw[resno];
- cstr_info->tile[tileno].pdy[resno] = tccp->prch[resno];
- }
- else {
- cstr_info->tile[tileno].pdx[resno] = 15;
- cstr_info->tile[tileno].pdy[resno] = 15;
- }
- }
- }
- cstr_info->tile[tileno].packet = (opj_packet_info_t *) opj_malloc(cstr_info->numlayers * numprec * sizeof(opj_packet_info_t));
- cstr_info->packno = 0;
- }
- /* << INDEX */
-
- /*--------------TIER2------------------*/
-
- t2 = t2_create(tcd->cinfo, tcd->image, tcd->cp);
- l = t2_decode_packets(t2, src, len, tileno, tile, cstr_info);
- t2_destroy(t2);
-
- if (l == -999) {
- eof = 1;
- opj_event_msg(tcd->cinfo, EVT_ERROR, "tcd_decode: incomplete bistream\n");
- }
-
- /*------------------TIER1-----------------*/
-
- t1_time = opj_clock(); /* time needed to decode a tile */
- t1 = t1_create(tcd->cinfo);
- for (compno = 0; compno < tile->numcomps; ++compno) {
- opj_tcd_tilecomp_t* tilec = &tile->comps[compno];
- /* The +3 is headroom required by the vectorized DWT */
- tilec->data = (int*) opj_aligned_malloc((((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0))+3) * sizeof(int));
- t1_decode_cblks(t1, tilec, &tcd->tcp->tccps[compno]);
- }
- t1_destroy(t1);
- t1_time = opj_clock() - t1_time;
- opj_event_msg(tcd->cinfo, EVT_INFO, "- tiers-1 took %f s\n", t1_time);
-
- /*----------------DWT---------------------*/
-
- dwt_time = opj_clock(); /* time needed to decode a tile */
- for (compno = 0; compno < tile->numcomps; compno++) {
- opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
- int numres2decode;
-
- if (tcd->cp->reduce != 0) {
- tcd->image->comps[compno].resno_decoded =
- tile->comps[compno].numresolutions - tcd->cp->reduce - 1;
- if (tcd->image->comps[compno].resno_decoded < 0) {
- opj_event_msg(tcd->cinfo, EVT_ERROR, "Error decoding tile. The number of resolutions to remove [%d+1] is higher than the number "
- " of resolutions in the original codestream [%d]\nModify the cp_reduce parameter.\n", tcd->cp->reduce, tile->comps[compno].numresolutions);
- return OPJ_FALSE;
- }
- }
-
- numres2decode = tcd->image->comps[compno].resno_decoded + 1;
- if(numres2decode > 0){
- if (tcd->tcp->tccps[compno].qmfbid == 1) {
- dwt_decode(tilec, numres2decode);
- } else {
- dwt_decode_real(tilec, numres2decode);
- }
- }
- }
- dwt_time = opj_clock() - dwt_time;
- opj_event_msg(tcd->cinfo, EVT_INFO, "- dwt took %f s\n", dwt_time);
-
- /*----------------MCT-------------------*/
-
- if (tcd->tcp->mct) {
- int n = (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0);
-
- if (tile->numcomps >= 3 ){
- if (tcd->tcp->tccps[0].qmfbid == 1) {
- mct_decode(
- tile->comps[0].data,
- tile->comps[1].data,
- tile->comps[2].data,
- n);
- } else {
- mct_decode_real(
- (float*)tile->comps[0].data,
- (float*)tile->comps[1].data,
- (float*)tile->comps[2].data,
- n);
- }
- } else{
- opj_event_msg(tcd->cinfo, EVT_WARNING,"Number of components (%d) is inconsistent with a MCT. Skip the MCT step.\n",tile->numcomps);
- }
- }
-
- /*---------------TILE-------------------*/
-
- for (compno = 0; compno < tile->numcomps; ++compno) {
- opj_tcd_tilecomp_t* tilec = &tile->comps[compno];
- opj_image_comp_t* imagec = &tcd->image->comps[compno];
- opj_tcd_resolution_t* res = &tilec->resolutions[imagec->resno_decoded];
- int adjust = imagec->sgnd ? 0 : 1 << (imagec->prec - 1);
- int min = imagec->sgnd ? -(1 << (imagec->prec - 1)) : 0;
- int max = imagec->sgnd ? (1 << (imagec->prec - 1)) - 1 : (1 << imagec->prec) - 1;
-
- int tw = tilec->x1 - tilec->x0;
- int w = imagec->w;
-
- int offset_x = int_ceildivpow2(imagec->x0, imagec->factor);
- int offset_y = int_ceildivpow2(imagec->y0, imagec->factor);
-
- int i, j;
- if(!imagec->data){
- imagec->data = (int*) opj_malloc(imagec->w * imagec->h * sizeof(int));
- }
- if(tcd->tcp->tccps[compno].qmfbid == 1) {
- for(j = res->y0; j < res->y1; ++j) {
- for(i = res->x0; i < res->x1; ++i) {
- int v = tilec->data[i - res->x0 + (j - res->y0) * tw];
- v += adjust;
- imagec->data[(i - offset_x) + (j - offset_y) * w] = int_clamp(v, min, max);
- }
- }
- }else{
- for(j = res->y0; j < res->y1; ++j) {
- for(i = res->x0; i < res->x1; ++i) {
- float tmp = ((float*)tilec->data)[i - res->x0 + (j - res->y0) * tw];
- int v = lrintf(tmp);
- v += adjust;
- imagec->data[(i - offset_x) + (j - offset_y) * w] = int_clamp(v, min, max);
- }
- }
- }
- opj_aligned_free(tilec->data);
- }
-
- tile_time = opj_clock() - tile_time; /* time needed to decode a tile */
- opj_event_msg(tcd->cinfo, EVT_INFO, "- tile decoded in %f s\n", tile_time);
-
- if (eof) {
- return OPJ_FALSE;
- }
-
- return OPJ_TRUE;
-}
-
-void tcd_free_decode(opj_tcd_t *tcd) {
- opj_tcd_image_t *tcd_image = tcd->tcd_image;
- opj_free(tcd_image->tiles);
-}
-
-void tcd_free_decode_tile(opj_tcd_t *tcd, int tileno) {
- int compno,resno,bandno,precno;
-
- opj_tcd_image_t *tcd_image = tcd->tcd_image;
-
- opj_tcd_tile_t *tile = &tcd_image->tiles[tileno];
- for (compno = 0; compno < tile->numcomps; compno++) {
- opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
- for (resno = 0; resno < tilec->numresolutions; resno++) {
- opj_tcd_resolution_t *res = &tilec->resolutions[resno];
- for (bandno = 0; bandno < res->numbands; bandno++) {
- opj_tcd_band_t *band = &res->bands[bandno];
- for (precno = 0; precno < res->ph * res->pw; precno++) {
- opj_tcd_precinct_t *prec = &band->precincts[precno];
- if (prec->imsbtree != NULL) tgt_destroy(prec->imsbtree);
- if (prec->incltree != NULL) tgt_destroy(prec->incltree);
- }
- opj_free(band->precincts);
- }
- }
- opj_free(tilec->resolutions);
- }
- opj_free(tile->comps);
-}
-
-
opj_bool opj_tcd_init( opj_tcd_v2_t *p_tcd,
opj_image_t * p_image,
opj_cp_v2_t * p_cp )
return OPJ_TRUE;
}
-opj_bool tcd_decode_tile_v2(
- opj_tcd_v2_t *p_tcd,
- OPJ_BYTE *p_src,
- OPJ_UINT32 p_max_length,
- OPJ_UINT32 p_tile_no,
- opj_codestream_index_t *p_cstr_index)
+opj_bool opj_tcd_decode_tile( opj_tcd_v2_t *p_tcd,
+ OPJ_BYTE *p_src,
+ OPJ_UINT32 p_max_length,
+ OPJ_UINT32 p_tile_no,
+ opj_codestream_index_t *p_cstr_index
+ )
{
OPJ_UINT32 l_data_read;
p_tcd->tcd_tileno = p_tile_no;