diff options
| author | Francois-Olivier Devaux <fodevaux@users.noreply.github.com> | 2007-09-07 15:01:55 +0000 |
|---|---|---|
| committer | Francois-Olivier Devaux <fodevaux@users.noreply.github.com> | 2007-09-07 15:01:55 +0000 |
| commit | 3816e0edf40b766ab78cdbf3ba5634b684630d0f (patch) | |
| tree | af0ef564292e21011947790793b59f79a16940d3 /codec | |
| parent | e7149e0c567d38e61b69db44ecda7f228310291d (diff) | |
Indexes can now be generated when decoding J2K codestreams.
Diffstat (limited to 'codec')
| -rw-r--r-- | codec/convert.c | 4 | ||||
| -rw-r--r-- | codec/image_to_j2k.c | 113 | ||||
| -rw-r--r-- | codec/j2k_to_image.c | 294 |
3 files changed, 332 insertions, 79 deletions
diff --git a/codec/convert.c b/codec/convert.c index d074909f..013bc152 100644 --- a/codec/convert.c +++ b/codec/convert.c @@ -1795,7 +1795,7 @@ opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters, raw opj_image_t * image = NULL; unsigned short ch; - if((raw_cp->rawWidth * raw_cp->rawHeight * raw_cp->rawComp * raw_cp->rawBitDepth) == 0) + if((! (raw_cp->rawWidth & raw_cp->rawHeight & raw_cp->rawComp & raw_cp->rawBitDepth)) == 0) { fprintf(stderr,"\nError: invalid raw image parameters\n"); fprintf(stderr,"Please use the Format option -F:\n"); @@ -1834,7 +1834,6 @@ opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters, raw fclose(f); return NULL; } - /* set image offset and reference grid */ image->x0 = parameters->image_offset_x0; image->y0 = parameters->image_offset_y0; @@ -1871,7 +1870,6 @@ opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters, raw if (fread(&ch, 1, 1, f)) { fprintf(stderr,"Warning. End of raw file not reached... processing anyway\n"); } - fclose(f); return image; diff --git a/codec/image_to_j2k.c b/codec/image_to_j2k.c index 14737424..eb559f3c 100644 --- a/codec/image_to_j2k.c +++ b/codec/image_to_j2k.c @@ -582,11 +582,11 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) { fprintf(stream, "%d\n", cstr_info->prog); fprintf(stream, "%d %d\n", cstr_info->tile_x, cstr_info->tile_y); fprintf(stream, "%d %d\n", cstr_info->tw, cstr_info->th); - fprintf(stream, "%d\n", cstr_info->comp); - fprintf(stream, "%d\n", cstr_info->layer); - fprintf(stream, "%d\n", cstr_info->decomposition); + 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->decomposition; resno >= 0; resno--) { + for (resno = cstr_info->numdecompos; 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 */ } @@ -598,26 +598,16 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) { fprintf(stream, "%d\n", cstr_info->codestream_size); fprintf(stream, "\nINFO ON TILES\n"); - fprintf(stream, "tileno start_pos end_hd end_tile" -/* UniPG>> */ - " nbparts" -/* <<UniPG */ - " disto nbpix disto/nbpix\n"); + fprintf(stream, "tileno start_pos end_hd end_tile nbparts disto nbpix disto/nbpix\n"); for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) { - fprintf(stream, "%4d %9d %9d %9d " -/* UniPG>> */ - "%9d " -/* <<UniPG */ - "%9e %9d %9e\n", - cstr_info->tile[tileno].num_tile, + fprintf(stream, "%4d %9d %9d %9d %9d %9e %9d %9e\n", + cstr_info->tile[tileno].tileno, cstr_info->tile[tileno].start_pos, cstr_info->tile[tileno].end_header, cstr_info->tile[tileno].end_pos, -/* UniPG>> */ cstr_info->tile[tileno].num_tps, -/* <<UniPG */ - cstr_info->tile[tileno].distotile, cstr_info->tile[tileno].nbpix, - cstr_info->tile[tileno].distotile / cstr_info->tile[tileno].nbpix); + cstr_info->tile[tileno].distotile, cstr_info->tile[tileno].numpix, + cstr_info->tile[tileno].distotile / cstr_info->tile[tileno].numpix); } for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) { @@ -626,24 +616,21 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) { pack_nb = 0; fprintf(stream, "\nTILE %d DETAILS\n", tileno); -/* UniPG>> */ - fprintf(stream, "part_nb tileno pack_nb start_pos end_tph_pos end_pos\n"); + 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++) - fprintf(stream, "%4d %9d %9d %9d %11d %9d\n", + fprintf(stream, "%4d %9d %9d %9d %11d %9d\n", tilepartno, tileno, - cstr_info->tile[tileno].tp_num[tilepartno], - cstr_info->tile[tileno].tp_start_pos[tilepartno], - cstr_info->tile[tileno].tp_end_header[tilepartno], - cstr_info->tile[tileno].tp_end_pos[tilepartno] + cstr_info->tile[tileno].tp[tilepartno].tp_numpacks, + cstr_info->tile[tileno].tp[tilepartno].tp_start_pos, + cstr_info->tile[tileno].tp[tilepartno].tp_end_header, + cstr_info->tile[tileno].tp[tilepartno].tp_end_pos ); -/* <<UniPG */ if (cstr_info->prog == LRCP) { /* LRCP */ - 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->layer; layno++) { - for (resno = 0; resno < cstr_info->decomposition + 1; resno++) { - for (compno = 0; compno < cstr_info->comp; compno++) { + for (layno = 0; layno < cstr_info->numlayers; layno++) { + for (resno = 0; resno < cstr_info->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]; for (precno = 0; precno < prec_max; precno++) { start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; @@ -663,9 +650,9 @@ 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->decomposition + 1; resno++) { - for (layno = 0; layno < cstr_info->layer; layno++) { - for (compno = 0; compno < cstr_info->comp; compno++) { + for (resno = 0; resno < cstr_info->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]; for (precno = 0; precno < prec_max; precno++) { start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; @@ -685,25 +672,25 @@ 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->decomposition + 1; resno++) { + for (resno = 0; resno < cstr_info->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->comp; compno++) { + for (compno = 0; compno < cstr_info->numcomps; compno++) { 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->decomposition - resno ); - int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->decomposition - 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 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++) { if (precno_y*pcy == y ) { for (x = x0; x < x1; x++) { if (precno_x*pcx == x ) { - for (layno = 0; layno < cstr_info->layer; layno++) { + for (layno = 0; layno < cstr_info->numlayers; layno++) { start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; @@ -730,20 +717,20 @@ 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->comp; compno++) { - for (resno = 0; resno < cstr_info->decomposition + 1; resno++) { + for (compno = 0; compno < cstr_info->numcomps; compno++) { + for (resno = 0; resno < cstr_info->numdecompos + 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->decomposition - resno ); - int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->decomposition - 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 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++) { if (precno_y*pcy == y ) { for (x = x0; x < x1; x++) { if (precno_x*pcx == x ) { - for (layno = 0; layno < cstr_info->layer; layno++) { + for (layno = 0; layno < cstr_info->numlayers; layno++) { start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; @@ -765,26 +752,26 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) { fprintf(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos disto\n"); - for (compno = 0; compno < cstr_info->comp; compno++) { + for (compno = 0; compno < cstr_info->numcomps; compno++) { /* 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 (resno = 0; resno < cstr_info->decomposition + 1; resno++) { + for (resno = 0; resno < cstr_info->numdecompos + 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->decomposition - resno ); - int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->decomposition - 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 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++) { if (precno_y*pcy == y ) { for (x = x0; x < x1; x++) { if (precno_x*pcx == x ) { - for (layno = 0; layno < cstr_info->layer; layno++) { + for (layno = 0; layno < cstr_info->numlayers; layno++) { start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; @@ -816,7 +803,7 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) { /* ------------------------------------------------------------------------------------ */ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters, - img_fol_t *img_fol, raw_cparameters_t *raw_cp) { + img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename) { int i, j,totlen; option_t long_option[]={ {"cinema2K",REQ_ARG, NULL ,'w'}, @@ -1087,8 +1074,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters, case 'x': /* creation of index file */ { char *index = optarg; - strncpy(parameters->index, index, sizeof(parameters->index)-1); - parameters->index_on = 1; + strncpy(indexfilename, index, OPJ_PATH_LEN); } break; @@ -1302,9 +1288,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters, int hprot, pprot, sens, addr, size, range; /* we need to enable indexing */ - if (!parameters->index_on) { + if (!indexfilename) { strncpy(parameters->index, JPWL_PRIVATEINDEX_NAME, sizeof(parameters->index)-1); - parameters->index_on = 1; } /* search for different protection methods */ @@ -1731,7 +1716,8 @@ int main(int argc, char **argv) { int imageno; dircnt_t *dirptr; raw_cparameters_t raw_cp; - opj_codestream_info_t cstr_info; + opj_codestream_info_t cstr_info; /* Codestream information structure */ + char indexfilename[OPJ_PATH_LEN]; /* index file name */ /* configure the event callbacks (not required) @@ -1745,11 +1731,12 @@ int main(int argc, char **argv) { /* set encoding parameters to default values */ opj_set_default_encoder_parameters(¶meters); - /* need to initialize img_fol since parameters will be read in parse_cmdline_decoder */ + /* Initialize indexfilename and img_fol */ + *indexfilename = 0; memset(&img_fol,0,sizeof(img_fol_t)); /* parse input and get user encoding parameters */ - if(parse_cmdline_encoder(argc, argv, ¶meters,&img_fol, &raw_cp) == 1) { + if(parse_cmdline_encoder(argc, argv, ¶meters,&img_fol, &raw_cp, indexfilename) == 1) { return 1; } @@ -1929,8 +1916,8 @@ int main(int argc, char **argv) { opj_cio_close(cio); /* Write the index to disk */ - if (parameters.index_on) { - bSuccess = write_index_file(&cstr_info, parameters.index); + if (*indexfilename) { + bSuccess = write_index_file(&cstr_info, indexfilename); if (bSuccess) { fprintf(stderr, "Failed to output index file\n"); } @@ -1938,6 +1925,8 @@ int main(int argc, char **argv) { /* free remaining compression structures */ opj_destroy_compress(cinfo); + opj_destroy_cstr_info(&cstr_info); + } else { /* JP2 format output */ int codestream_length; opj_cio_t *cio = NULL; @@ -1978,8 +1967,8 @@ int main(int argc, char **argv) { opj_cio_close(cio); /* Write the index to disk */ - if (parameters.index_on) { - bSuccess = write_index_file(&cstr_info, parameters.index); + if (*indexfilename) { + bSuccess = write_index_file(&cstr_info, indexfilename); if (bSuccess) { fprintf(stderr, "Failed to output index file\n"); } @@ -1987,7 +1976,7 @@ int main(int argc, char **argv) { /* free remaining compression structures */ opj_destroy_compress(cinfo); - + opj_destroy_cstr_info(&cstr_info); } /* free image data */ diff --git a/codec/j2k_to_image.c b/codec/j2k_to_image.c index 677bf98e..182420f5 100644 --- a/codec/j2k_to_image.c +++ b/codec/j2k_to_image.c @@ -32,6 +32,7 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> +#include <math.h> #include "openjpeg.h" #include "compat/getopt.h" @@ -120,6 +121,9 @@ void decode_help_display() { fprintf(stdout," Set the maximum number of quality layers to decode. If there are\n"); fprintf(stdout," less quality layers than the specified number, all the quality layers\n"); fprintf(stdout," are decoded.\n"); + fprintf(stdout," -x \n"); + fprintf(stdout," Create an index file *.Idx (-x index_name.Idx) \n"); + fprintf(stdout,"\n"); /* UniPG>> */ #ifdef USE_JPWL fprintf(stdout," -W <options>\n"); @@ -225,10 +229,237 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparamet return 0; } +/* ------------------------------------------------------------------------------------ */ -/* -------------------------------------------------------------------------- */ +/** +Create an index and write it to a file +@param cstr_info Codestream information +@param index Index filename +@return Returns 0 if successful, returns 1 otherwise +*/ +int write_index_file(opj_codestream_info_t *cstr_info, char *index) { + int tileno, compno, layno, resno, precno, pack_nb, x, y; + FILE *stream = NULL; + int tilepartno; + + if (!cstr_info) + return 1; + + stream = fopen(index, "w"); + if (!stream) { + fprintf(stderr, "failed to open index file [%s] for writing\n", index); + return 1; + } + + fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h); + fprintf(stream, "%d\n", cstr_info->prog); + fprintf(stream, "%d %d\n", cstr_info->tile_x, cstr_info->tile_y); + fprintf(stream, "%d %d\n", cstr_info->tw, cstr_info->th); + 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--) { + fprintf(stream, "[%d,%d] ", + (1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 */ + } + fprintf(stream, "\n"); + fprintf(stream, "%d\n", cstr_info->main_head_start); + fprintf(stream, "%d\n", cstr_info->main_head_end); + fprintf(stream, "%d\n", cstr_info->codestream_size); + + fprintf(stream, "\nINFO ON TILES\n"); + fprintf(stream, "tileno start_pos end_hd end_tile nbparts\n"); + for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) { + fprintf(stream, "%4d %9d %9d %9d %9d\n", + cstr_info->tile[tileno].tileno, + cstr_info->tile[tileno].start_pos, + cstr_info->tile[tileno].end_header, + cstr_info->tile[tileno].end_pos, + cstr_info->tile[tileno].num_tps); + } + + for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) { + int start_pos, end_ph_pos, end_pos; + pack_nb = 0; + + 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++) + fprintf(stream, "%4d %9d %9d %9d %11d %9d\n", + tilepartno, tileno, + cstr_info->tile[tileno].tp[tilepartno].tp_numpacks, + cstr_info->tile[tileno].tp[tilepartno].tp_start_pos, + cstr_info->tile[tileno].tp[tilepartno].tp_end_header, + cstr_info->tile[tileno].tp[tilepartno].tp_end_pos + ); + if (cstr_info->prog == LRCP) { /* LRCP */ + 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 (compno = 0; compno < cstr_info->numcomps; compno++) { + int 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; + end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; + fprintf(stream, "%4d %6d %7d %5d %6d %6d %6d %6d %7d\n", + pack_nb, tileno, layno, resno, compno, precno, start_pos, end_ph_pos, end_pos); + pack_nb++; + } + } + } + } + } /* LRCP */ + else if (cstr_info->prog == RLCP) { /* RLCP */ + + 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 (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]; + 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; + end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; + fprintf(stream, "%4d %6d %5d %7d %6d %6d %9d %9d %7d\n", + pack_nb, tileno, resno, layno, compno, precno, start_pos, end_ph_pos, end_pos); + pack_nb++; + } + } + } + } + } /* RLCP */ + else if (cstr_info->prog == RPCL) { /* RPCL */ + + 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++) { + /* 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]; + 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 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++) { + if (precno_y*pcy == y ) { + for (x = x0; x < x1; x++) { + if (precno_x*pcx == x ) { + for (layno = 0; layno < cstr_info->numlayers; layno++) { + start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; + end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; + end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; + fprintf(stream, "%4d %6d %5d %6d %6d %7d %9d %9d %7d\n", + pack_nb, tileno, resno, precno, compno, layno, start_pos, end_ph_pos, end_pos); + pack_nb++; + } + } + }/* x = x0..x1 */ + } + } /* y = y0..y1 */ + } /* precno */ + } /* compno */ + } /* resno */ + } /* RPCL */ + else if (cstr_info->prog == PCRL) { /* PCRL */ + /* 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; + + 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++) { + 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 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++) { + if (precno_y*pcy == y ) { + for (x = x0; x < x1; x++) { + if (precno_x*pcx == x ) { + for (layno = 0; layno < cstr_info->numlayers; layno++) { + start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; + end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; + end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; + fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %7d\n", + pack_nb, tileno, precno, compno, resno, layno, start_pos, end_ph_pos, end_pos); + pack_nb++; + } + } + }/* x = x0..x1 */ + } + } /* y = y0..y1 */ + } /* precno */ + } /* resno */ + } /* compno */ + } /* PCRL */ + else { /* CPRL */ + + fprintf(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos\n"); + + for (compno = 0; compno < cstr_info->numcomps; compno++) { + /* 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 (resno = 0; resno < cstr_info->numdecompos + 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 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++) { + if (precno_y*pcy == y ) { + for (x = x0; x < x1; x++) { + if (precno_x*pcx == x ) { + for (layno = 0; layno < cstr_info->numlayers; layno++) { + start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; + end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; + end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; + fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %7d\n", + pack_nb, tileno, compno, precno, resno, layno, start_pos, end_ph_pos, end_pos); + pack_nb++; + } + } + }/* x = x0..x1 */ + } + } /* y = y0..y1 */ + } /* precno */ + } /* resno */ + } /* compno */ + } /* CPRL */ + } /* tileno */ + + fclose(stream); + + fprintf(stderr,"Generated index file %s\n", index); + + return 0; +} + +/* ------------------------------------------------------------------------------------ */ -int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol) { +/* -------------------------------------------------------------------------- */ +int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename) { /* parse the command line */ int totlen; option_t long_option[]={ @@ -236,7 +467,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i {"OutFor",REQ_ARG, NULL ,'O'}, }; - const char optlist[] = "i:o:r:l:h" + const char optlist[] = "i:o:r:l:hx:" /* UniPG>> */ #ifdef USE_JPWL @@ -361,8 +592,15 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i img_fol->set_imgdir=1; } break; + /* ----------------------------------------------------- */ + case 'x': /* Creation of index file */ + { + char *index = optarg; + strncpy(indexfilename, index, OPJ_PATH_LEN); + } + break; /* ----------------------------------------------------- */ -/* UniPG>> */ + /* UniPG>> */ #ifdef USE_JPWL case 'W': /* activate JPWL correction */ @@ -507,6 +745,8 @@ int main(int argc, char **argv) { dircnt_t *dirptr; opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */ opj_cio_t *cio = NULL; + opj_codestream_info_t cstr_info; /* Codestream information structure */ + char indexfilename[OPJ_PATH_LEN]; /* index file name */ /* configure the event callbacks (not required) */ memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); @@ -517,14 +757,16 @@ int main(int argc, char **argv) { /* set decoding parameters to default values */ opj_set_default_decoder_parameters(¶meters); - /* need to initialize img_fol since parameters will be read in parse_cmdline_decoder */ + /* Initialize indexfilename and img_fol */ + *indexfilename = 0; memset(&img_fol,0,sizeof(img_fol_t)); /* parse input and get user encoding parameters */ - if(parse_cmdline_decoder(argc, argv, ¶meters,&img_fol) == 1) { + if(parse_cmdline_decoder(argc, argv, ¶meters,&img_fol, indexfilename) == 1) { return 1; } + /* Initialize reading of directory */ if(img_fol.set_imgdir==1){ num_images=get_num_images(img_fol.imgdirpath); @@ -552,9 +794,7 @@ int main(int argc, char **argv) { } /*Encoding image one by one*/ - for(imageno = 0; imageno < num_images ; imageno++) - { - + for(imageno = 0; imageno < num_images ; imageno++) { image = NULL; fprintf(stderr,"\n"); @@ -563,10 +803,8 @@ int main(int argc, char **argv) { fprintf(stderr,"skipping file...\n"); continue; } - } - /* read the input file and put it in memory */ /* ---------------------------------------- */ fsrc = fopen(parameters.infile, "rb"); @@ -604,7 +842,7 @@ int main(int argc, char **argv) { cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length); /* decode the stream and fill the image structure */ - image = opj_decode(dinfo, cio); + image = opj_decode(dinfo, cio, &cstr_info); if(!image) { fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n"); opj_destroy_decompress(dinfo); @@ -614,6 +852,15 @@ int main(int argc, char **argv) { /* close the byte stream */ opj_cio_close(cio); + + /* Write the index to disk */ + if (*indexfilename) { + char bSuccess; + bSuccess = write_index_file(&cstr_info, indexfilename); + if (bSuccess) { + fprintf(stderr, "Failed to output index file\n"); + } + } } break; @@ -634,7 +881,7 @@ int main(int argc, char **argv) { cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length); /* decode the stream and fill the image structure */ - image = opj_decode(dinfo, cio); + image = opj_decode(dinfo, cio, &cstr_info); if(!image) { fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n"); opj_destroy_decompress(dinfo); @@ -645,6 +892,14 @@ int main(int argc, char **argv) { /* close the byte stream */ opj_cio_close(cio); + /* Write the index to disk */ + if (*indexfilename) { + char bSuccess; + bSuccess = write_index_file(&cstr_info, indexfilename); + if (bSuccess) { + fprintf(stderr, "Failed to output index file\n"); + } + } } break; @@ -665,7 +920,7 @@ int main(int argc, char **argv) { cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length); /* decode the stream and fill the image structure */ - image = opj_decode(dinfo, cio); + image = opj_decode(dinfo, cio, &cstr_info); if(!image) { fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n"); opj_destroy_decompress(dinfo); @@ -675,6 +930,15 @@ int main(int argc, char **argv) { /* close the byte stream */ opj_cio_close(cio); + + /* Write the index to disk */ + if (*indexfilename) { + char bSuccess; + bSuccess = write_index_file(&cstr_info, indexfilename); + if (bSuccess) { + fprintf(stderr, "Failed to output index file\n"); + } + } } break; @@ -749,6 +1013,8 @@ int main(int argc, char **argv) { if(dinfo) { opj_destroy_decompress(dinfo); } + /* free codestream information structure */ + opj_destroy_cstr_info(&cstr_info); /* free image data structure */ opj_image_destroy(image); |
