From 569bbb00776f08211f7184ea4ea94571b652adae Mon Sep 17 00:00:00 2001 From: Francois-Olivier Devaux Date: Mon, 17 Sep 2007 14:00:43 +0000 Subject: [PATCH] Fixed issues with cstr_info when codestream has components with different number of resolutions. --- ChangeLog | 3 +++ codec/image_to_j2k.c | 47 +++++++++++++++++++++++++------------- codec/j2k_to_image.c | 51 ++++++++++++++++++++++++++++-------------- libopenjpeg/j2k.c | 25 ++++++++++++++++----- libopenjpeg/openjpeg.h | 4 ++-- libopenjpeg/t2.c | 4 +++- libopenjpeg/tcd.c | 38 +++++++++++++++++-------------- 7 files changed, 113 insertions(+), 59 deletions(-) diff --git a/ChangeLog b/ChangeLog index ceb369bf..20acfaa9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,9 @@ What's New for OpenJPEG ! : changed + : added +September 17, 2007 +* [FOD] Fixed issues with cstr_info when codestream has components with different number of resolutions. + September 12, 2007 * [FOD] Patch from Callum Lerwick. Fixed the library linking so it links with the soversion properly set. diff --git a/codec/image_to_j2k.c b/codec/image_to_j2k.c index 9c579193..40ec2af0 100644 --- a/codec/image_to_j2k.c +++ b/codec/image_to_j2k.c @@ -595,11 +595,12 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) { fprintf(stream, "%d\n", cstr_info->numcomps); fprintf(stream, "%d\n", cstr_info->numlayers); fprintf(stream, "%d\n", cstr_info->numdecompos); - - for (resno = cstr_info->numdecompos; resno >= 0; resno--) { + + for (resno = cstr_info->numdecompos[0]; resno >= 0; resno--) { fprintf(stream, "[%d,%d] ", - (1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 */ + (1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 and component 0 */ } + fprintf(stream, "\n"); /* UniPG>> */ fprintf(stream, "%d\n", cstr_info->main_head_start); @@ -623,8 +624,14 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) { for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) { int start_pos, end_ph_pos, end_pos; double disto = 0; + int max_numdecompos = 0; pack_nb = 0; + for (compno = 0; compno < cstr_info->numcomps; compno++) { + if (max_numdecompos < cstr_info->numdecompos[compno]) + max_numdecompos = cstr_info->numdecompos[compno]; + } + fprintf(stream, "\nTILE %d DETAILS\n", tileno); fprintf(stream, "part_nb tileno num_packs start_pos end_tph_pos end_pos\n"); for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++) @@ -639,9 +646,12 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) { fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos disto\n"); for (layno = 0; layno < cstr_info->numlayers; layno++) { - for (resno = 0; resno < cstr_info->numdecompos + 1; resno++) { + for (resno = 0; resno < max_numdecompos + 1; resno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) { - int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; + int prec_max; + if (resno > cstr_info->numdecompos[compno]) + break; + prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; for (precno = 0; precno < prec_max; precno++) { start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; @@ -660,10 +670,13 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) { fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos disto\n"); - for (resno = 0; resno < cstr_info->numdecompos + 1; resno++) { + for (resno = 0; resno < max_numdecompos + 1; resno++) { for (layno = 0; layno < cstr_info->numlayers; layno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) { - int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; + int prec_max; + if (resno > cstr_info->numdecompos[compno]) + break; + prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; for (precno = 0; precno < prec_max; precno++) { start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; @@ -682,7 +695,7 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) { fprintf(stream, "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos disto\n"); - for (resno = 0; resno < cstr_info->numdecompos + 1; resno++) { + for (resno = 0; resno < max_numdecompos + 1; resno++) { /* I suppose components have same XRsiz, YRsiz */ int x0 = cstr_info->tile_Ox + tileno - (int)floor((float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x; int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y; @@ -690,10 +703,12 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) { int y1 = y0 + cstr_info->tile_y; for (compno = 0; compno < cstr_info->numcomps; compno++) { int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; + if (resno > cstr_info->numdecompos[compno]) + break; for (precno = 0; precno < prec_max; precno++) { int pcnx = cstr_info->tile[tileno].pw[resno]; - int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos - resno ); - int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos - resno ); + int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno ); + int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno ); int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; int precno_y = (int) floor( (float)precno/(float)pcnx ); for(y = y0; y < y1; y++) { @@ -728,12 +743,12 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) { fprintf(stream, "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos disto\n"); for (compno = 0; compno < cstr_info->numcomps; compno++) { - for (resno = 0; resno < cstr_info->numdecompos + 1; resno++) { + for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) { int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; for (precno = 0; precno < prec_max; precno++) { int pcnx = cstr_info->tile[tileno].pw[resno]; - int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos - resno ); - int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos - resno ); + int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno ); + int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno ); int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; int precno_y = (int) floor( (float)precno/(float)pcnx ); for(y = y0; y < y1; y++) { @@ -769,12 +784,12 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) { int x1 = x0 + cstr_info->tile_x; int y1 = y0 + cstr_info->tile_y; - for (resno = 0; resno < cstr_info->numdecompos + 1; resno++) { + for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) { int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; for (precno = 0; precno < prec_max; precno++) { int pcnx = cstr_info->tile[tileno].pw[resno]; - int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos - resno ); - int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos - resno ); + int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno ); + int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno ); int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; int precno_y = (int) floor( (float)precno/(float)pcnx ); for(y = y0; y < y1; y++) { diff --git a/codec/j2k_to_image.c b/codec/j2k_to_image.c index 182420f5..98eae955 100644 --- a/codec/j2k_to_image.c +++ b/codec/j2k_to_image.c @@ -259,9 +259,9 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) { fprintf(stream, "%d\n", cstr_info->numlayers); fprintf(stream, "%d\n", cstr_info->numdecompos); - for (resno = cstr_info->numdecompos; resno >= 0; resno--) { + for (resno = cstr_info->numdecompos[0]; resno >= 0; resno--) { fprintf(stream, "[%d,%d] ", - (1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 */ + (1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 and component 0*/ } fprintf(stream, "\n"); fprintf(stream, "%d\n", cstr_info->main_head_start); @@ -281,7 +281,13 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) { for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) { int start_pos, end_ph_pos, end_pos; - pack_nb = 0; + int max_numdecompos = 0; + pack_nb = 0; + + for (compno = 0; compno < cstr_info->numcomps; compno++) { + if (max_numdecompos < cstr_info->numdecompos[compno]) + max_numdecompos = cstr_info->numdecompos[compno]; + } fprintf(stream, "\nTILE %d DETAILS\n", tileno); fprintf(stream, "part_nb tileno num_packs start_pos end_tph_pos end_pos\n"); @@ -297,9 +303,12 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) { fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos\n"); for (layno = 0; layno < cstr_info->numlayers; layno++) { - for (resno = 0; resno < cstr_info->numdecompos + 1; resno++) { + for (resno = 0; resno < max_numdecompos + 1; resno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) { - int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; + int prec_max; + if (resno > cstr_info->numdecompos[compno]) + break; + prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; for (precno = 0; precno < prec_max; precno++) { start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; @@ -316,10 +325,13 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) { fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos\n"); - for (resno = 0; resno < cstr_info->numdecompos + 1; resno++) { + for (resno = 0; resno < max_numdecompos + 1; resno++) { for (layno = 0; layno < cstr_info->numlayers; layno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) { - int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; + int prec_max; + if (resno > cstr_info->numdecompos[compno]) + break; + prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; for (precno = 0; precno < prec_max; precno++) { start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; @@ -336,18 +348,21 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) { fprintf(stream, "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos\n"); - for (resno = 0; resno < cstr_info->numdecompos + 1; resno++) { + for (resno = 0; resno < max_numdecompos + 1; resno++) { /* I suppose components have same XRsiz, YRsiz */ int x0 = cstr_info->tile_Ox + tileno - (int)floor((float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x; int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y; int x1 = x0 + cstr_info->tile_x; int y1 = y0 + cstr_info->tile_y; for (compno = 0; compno < cstr_info->numcomps; compno++) { - int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; + int prec_max; + if (resno > cstr_info->numdecompos[compno]) + break; + prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; for (precno = 0; precno < prec_max; precno++) { int pcnx = cstr_info->tile[tileno].pw[resno]; - int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos - resno ); - int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos - resno ); + int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno ); + int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno ); int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; int precno_y = (int) floor( (float)precno/(float)pcnx ); for(y = y0; y < y1; y++) { @@ -380,12 +395,12 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) { fprintf(stream, "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos\n"); for (compno = 0; compno < cstr_info->numcomps; compno++) { - for (resno = 0; resno < cstr_info->numdecompos + 1; resno++) { + for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) { int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; for (precno = 0; precno < prec_max; precno++) { int pcnx = cstr_info->tile[tileno].pw[resno]; - int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos - resno ); - int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos - resno ); + int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno ); + int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno ); int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; int precno_y = (int) floor( (float)precno/(float)pcnx ); for(y = y0; y < y1; y++) { @@ -419,12 +434,12 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) { int x1 = x0 + cstr_info->tile_x; int y1 = y0 + cstr_info->tile_y; - for (resno = 0; resno < cstr_info->numdecompos + 1; resno++) { + for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) { int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; for (precno = 0; precno < prec_max; precno++) { int pcnx = cstr_info->tile[tileno].pw[resno]; - int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos - resno ); - int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos - resno ); + int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno ); + int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno ); int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; int precno_y = (int) floor( (float)precno/(float)pcnx ); for(y = y0; y < y1; y++) { @@ -1024,3 +1039,5 @@ int main(int argc, char **argv) { //end main + + diff --git a/libopenjpeg/j2k.c b/libopenjpeg/j2k.c index 651ef215..a58ab6c3 100644 --- a/libopenjpeg/j2k.c +++ b/libopenjpeg/j2k.c @@ -675,7 +675,7 @@ static void j2k_read_siz(opj_j2k_t *j2k) { 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_malloc(cp->tw * cp->th * sizeof(opj_tile_info_t)); + cstr_info->tile = (opj_tile_info_t*) opj_malloc(cp->tw * cp->th * sizeof(opj_tile_info_t)); } } @@ -824,7 +824,10 @@ static void j2k_read_cod(opj_j2k_t *j2k) { opj_codestream_info_t *cstr_info = j2k->cstr_info; cstr_info->prog = tcp->prg; cstr_info->numlayers = tcp->numlayers; - cstr_info->numdecompos = tcp->tccps[0].numresolutions - 1; + cstr_info->numdecompos = (int*) malloc (image->numcomps * sizeof(int)); + for (i = 0; i < image->numcomps; i++) { + cstr_info->numdecompos[i] = tcp->tccps[i].numresolutions - 1; + } } } @@ -1376,10 +1379,14 @@ static void j2k_read_sot(opj_j2k_t *j2k) { 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; j2k->cstr_info->tile[tileno].num_tps = numparts; - j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_malloc(numparts * sizeof(opj_tp_info_t)); + if (numparts) + j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_malloc(numparts * sizeof(opj_tp_info_t)); + else + j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_malloc(10 * sizeof(opj_tp_info_t)); // Fixme (10) } - else + else { j2k->cstr_info->tile[tileno].end_pos += totlen; + } 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; @@ -1477,7 +1484,7 @@ static void j2k_read_sod(opj_j2k_t *j2k) { if (len == cio_numbytesleft(cio) + 1) { truncate = 1; /* Case of a truncate codestream */ - } + } data = (unsigned char *) opj_malloc((j2k->tile_len[curtileno] + len) * sizeof(unsigned char)); @@ -2278,6 +2285,7 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestre /* INDEX >> */ j2k->cstr_info = cstr_info; if (cstr_info) { + int compno; cstr_info->tile = (opj_tile_info_t *) opj_malloc(cp->tw * cp->th * sizeof(opj_tile_info_t)); cstr_info->image_w = image->x1 - image->x0; cstr_info->image_h = image->y1 - image->y0; @@ -2290,7 +2298,10 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestre cstr_info->tile_Oy = cp->ty0; /* new version parser */ cstr_info->numcomps = image->numcomps; cstr_info->numlayers = (&cp->tcps[0])->numlayers; - cstr_info->numdecompos = (&cp->tcps[0])->tccps->numresolutions - 1; + cstr_info->numdecompos = (int*) malloc (image->numcomps * sizeof(int)); + for (compno=0; compno < image->numcomps; compno++) { + cstr_info->numdecompos[compno] = (&cp->tcps[0])->tccps->numresolutions - 1; + } cstr_info->D_max = 0; /* ADD Marcela */ cstr_info->main_head_start = cio_tell(cio); /* position of SOC */ } @@ -2469,3 +2480,5 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestre + + diff --git a/libopenjpeg/openjpeg.h b/libopenjpeg/openjpeg.h index 876c0ab1..20ff7cf7 100644 --- a/libopenjpeg/openjpeg.h +++ b/libopenjpeg/openjpeg.h @@ -690,8 +690,8 @@ typedef struct opj_codestream_info { int numcomps; /** number of layer */ int numlayers; - /** number of decomposition of first component */ - int numdecompos; + /** number of decomposition for each component */ + int *numdecompos; /* UniPG>> */ /** number of markers */ int marknum; diff --git a/libopenjpeg/t2.c b/libopenjpeg/t2.c index 5d0d9856..5692a1ec 100644 --- a/libopenjpeg/t2.c +++ b/libopenjpeg/t2.c @@ -748,7 +748,7 @@ int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj return e; } - return (c - src); + return (c - src); } /* ----------------------------------------------------------------------- */ @@ -771,3 +771,5 @@ void t2_destroy(opj_t2_t *t2) { } + + diff --git a/libopenjpeg/tcd.c b/libopenjpeg/tcd.c index 767e7f3d..8f59caa4 100644 --- a/libopenjpeg/tcd.c +++ b/libopenjpeg/tcd.c @@ -1309,25 +1309,27 @@ bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, op /* INDEX >> */ if(cstr_info) { - int i, numpacks = 0; - opj_tcp_t *tcp = &tcd->cp->tcps[0]; - opj_tccp_t *tccp = &tcp->tccps[0]; - opj_tcd_tilecomp_t *tilec_idx = &tile->comps[0]; /* based on component 0 */ - for (i = 0; i < tilec_idx->numresolutions; i++) { - opj_tcd_resolution_t *res_idx = &tilec_idx->resolutions[i]; - cstr_info->tile[tileno].pw[i] = res_idx->pw; - cstr_info->tile[tileno].ph[i] = res_idx->ph; - numpacks += res_idx->pw * res_idx->ph; - if (tccp->csty & J2K_CP_CSTY_PRT) { - cstr_info->tile[tileno].pdx[i] = tccp->prcw[i]; - cstr_info->tile[tileno].pdy[i] = tccp->prch[i]; - } - else { - cstr_info->tile[tileno].pdx[i] = 15; - cstr_info->tile[tileno].pdx[i] = 15; + 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].pdx[resno] = 15; + } } } - cstr_info->tile[tileno].packet = (opj_packet_info_t *) opj_malloc(cstr_info->numcomps * cstr_info->numlayers * numpacks * sizeof(opj_packet_info_t)); + 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 */ @@ -1472,3 +1474,5 @@ void tcd_free_decode_tile(opj_tcd_t *tcd, int tileno) { + +