Created the file index.c in the codec directory. This file handles the creation of...
authorFrancois-Olivier Devaux <fodevaux@users.noreply.github.com>
Tue, 27 Nov 2007 12:38:52 +0000 (12:38 +0000)
committerFrancois-Olivier Devaux <fodevaux@users.noreply.github.com>
Tue, 27 Nov 2007 12:38:52 +0000 (12:38 +0000)
Fixed bugs during the creation of the index (PCRL progression order)

ChangeLog
codec/CMakeLists.txt
codec/Makefile
codec/image_to_j2k.c
codec/image_to_j2k.sln
codec/image_to_j2k.vcproj
codec/index.c [new file with mode: 0644]
codec/index.h [new file with mode: 0644]
codec/j2k_to_image.c
codec/j2k_to_image.vcproj

index 1b6550e410adc185c4fba0fb2602b1e6228499b0..44142241d2c6742362586c2ae41a2af96f6fc79e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,10 @@ What's New for OpenJPEG
 ! : changed
 + : added
 
+November 14, 2007
++ [FOD] Created the file index.c in the codec directory. This file handles the creation of index files, 
+               at encoding and decoding. 
+* [FOD] Fixed bugs during the creation of the index (PCRL progression order)
 
 November 14, 2007
 ! [FOD] - First Patch by Callum Lerwick. Instead of reinventing realloc, j2k_read_sod now just uses opj_realloc in j2k.c
index ecc31bdd69bcbdffb75f36ed0ec2558f3b57797e..26cd7eebbc323efb168c413cd74451c75e044393 100644 (file)
@@ -3,7 +3,9 @@
 # First thing define the common source:
 SET(common_SRCS
   convert.c
-  )
+  index.c
+)
+
 # Then check if getopt is present:
 INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
 SET(DONT_HAVE_GETOPT 1)
@@ -24,7 +26,6 @@ IF(DONT_HAVE_GETOPT)
   )
 ENDIF(DONT_HAVE_GETOPT)
 
-
 # Headers file are located here:
 INCLUDE_DIRECTORIES(
   ${OPENJPEG_SOURCE_DIR}/libopenjpeg
index f38ff762ad9b3af27e1f24a8d9e040badbabae05..14487a5f231ee5469071b1b8af98fc5cbca25767 100644 (file)
@@ -5,10 +5,10 @@ CFLAGS = -O3 -lstdc++ # -g -p -pg
 all: j2k_to_image image_to_j2k
 
 j2k_to_image: j2k_to_image.c ../libopenjpeg.a
-       gcc $(CFLAGS) compat/getopt.c convert.c j2k_to_image.c -o j2k_to_image -L.. -lopenjpeg -I ../libopenjpeg/ -lm -ltiff
+       gcc $(CFLAGS) compat/getopt.c index.c convert.c j2k_to_image.c -o j2k_to_image -L.. -lopenjpeg -I ../libopenjpeg/ -lm -ltiff
 
 image_to_j2k: image_to_j2k.c ../libopenjpeg.a
-       gcc $(CFLAGS) compat/getopt.c convert.c image_to_j2k.c -o image_to_j2k -L.. -lopenjpeg -I ../libopenjpeg/ -lm -ltiff
+       gcc $(CFLAGS) compat/getopt.c index.c convert.c image_to_j2k.c -o image_to_j2k -L.. -lopenjpeg -I ../libopenjpeg/ -lm -ltiff
 
 clean:
        rm -f j2k_to_image image_to_j2k
index 54ca14a1a5c47bc5bd42a691b662d4cf60653e61..f505e99704961b51fe73c6aee3477f9debe9b431 100644 (file)
@@ -38,6 +38,7 @@
 #include "compat/getopt.h"
 #include "convert.h"
 #include "dirent.h"
+#include "index.h"
 
 #ifndef WIN32
 #define stricmp strcasecmp
@@ -566,282 +567,6 @@ void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image, img_
 
 /* ------------------------------------------------------------------------------------ */
 
-/**
-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;
-       double total_disto = 0;
-/* UniPG>> */
-       int tilepartno;
-
-#ifdef USE_JPWL
-       if (!strcmp(index, JPWL_PRIVATEINDEX_NAME))
-               return 0;
-#endif /* USE_JPWL */
-/* <<UniPG */
-
-       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[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 and component 0 */
-       }
-
-       fprintf(stream, "\n");
-/* UniPG>> */
-       fprintf(stream, "%d\n", cstr_info->main_head_start);
-/* <<UniPG */
-       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         disto     nbpix   disto/nbpix\n");
-       for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
-               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,
-                       cstr_info->tile[tileno].num_tps,
-                       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++) {
-               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  start_pack 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  %9d %11d %9d\n",
-                               tilepartno, tileno,
-                               cstr_info->tile[tileno].tp[tilepartno].tp_start_pack,
-                               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 disto\n");
-
-                       for (layno = 0; layno < cstr_info->numlayers; layno++) {
-                               for (resno = 0; resno < max_numdecompos + 1; resno++) {
-                                       for (compno = 0; compno < cstr_info->numcomps; compno++) {
-                                               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;
-                                                       end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
-                                                       disto = cstr_info->tile[tileno].packet[pack_nb].disto;
-                                                       fprintf(stream, "%4d %6d %7d %5d %6d  %6d    %6d     %6d %7d %8e\n",
-                                                               pack_nb, tileno, layno, resno, compno, precno, start_pos, end_ph_pos, end_pos, disto);
-                                                       total_disto += disto;
-                                                       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 disto\n");
-
-                       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; 
-                                               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;
-                                                       end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
-                                                       disto = cstr_info->tile[tileno].packet[pack_nb].disto;
-                                                       fprintf(stream, "%4d %6d %5d %7d %6d %6d %9d   %9d %7d %8e\n",
-                                                               pack_nb, tileno, resno, layno, compno, precno, start_pos, end_ph_pos, end_pos, disto);
-                                                       total_disto += disto;
-                                                       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 disto\n"); 
-
-                       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];
-                                       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[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++) {                                                      
-                                                       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;
-                                                                                       disto = cstr_info->tile[tileno].packet[pack_nb].disto;
-                                                                                       fprintf(stream, "%4d %6d %5d %6d %6d %7d %9d   %9d %7d %8e\n",
-                                                                                               pack_nb, tileno, resno, precno, compno, layno, start_pos, end_ph_pos, end_pos, disto); 
-                                                                                       total_disto += disto;
-                                                                                       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 disto\n"); 
-
-                       for (compno = 0; compno < cstr_info->numcomps; compno++) {
-                               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[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++) {                                                      
-                                                       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;
-                                                                                       disto = cstr_info->tile[tileno].packet[pack_nb].disto;
-                                                                                       fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d   %9d %7d %8e\n",
-                                                                                               pack_nb, tileno, precno, compno, resno, layno, start_pos, end_ph_pos, end_pos, disto); 
-                                                                                       total_disto += disto;
-                                                                                       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 disto\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[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[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++) {
-                                                       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;
-                                                                                       disto = cstr_info->tile[tileno].packet[pack_nb].disto;
-                                                                                       fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d   %9d %7d %8e\n",
-                                                                                               pack_nb, tileno, compno, precno, resno, layno, start_pos, end_ph_pos, end_pos, disto); 
-                                                                                       total_disto += disto;
-                                                                                       pack_nb++; 
-                                                                               }
-                                                                       }
-                                                               }/* x = x0..x1 */
-                                                       }
-                                               } /* y = y0..y1 */
-                                       } /* precno */
-                               } /* resno */
-                       } /* compno */
-               } /* CPRL */   
-       } /* tileno */
-       
-       fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */
-       fprintf(stream, "%.8e\n", total_disto); /* SE totale */
-/* UniPG>> */
-       /* print the markers' list */
-       fprintf(stream, "\nMARKER LIST\n");
-       fprintf(stream, "%d\n", cstr_info->marknum);
-       fprintf(stream, "type\tstart_pos    length\n");
-       for (x = 0; x < cstr_info->marknum; x++)
-               fprintf(stream, "%X\t%9d %9d\n", cstr_info->marker[x].type, cstr_info->marker[x].pos, cstr_info->marker[x].len);
-/* <<UniPG */
-       fclose(stream);
-
-       fprintf(stderr,"Generated index file %s\n", index);
-
-       return 0;
-}
-
-/* ------------------------------------------------------------------------------------ */
-
 int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                                                                                                        img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename) {
        int i, j,totlen;
index 196e53c6bb7778e9057a41b86ff5f03dd9ac3565..de773c8d50dde46e6a463af8a5d1d4928eae6336 100644 (file)
Binary files a/codec/image_to_j2k.sln and b/codec/image_to_j2k.sln differ
index f98df8931e9f97932859b719eebb055f88cd21a5..8968eb4b6308b4b21cc4ce6ce96cde8b1777a188 100644 (file)
                                />\r
                        </FileConfiguration>\r
                </File>\r
+               <File\r
+                       RelativePath=".\index.c"\r
+                       >\r
+               </File>\r
+               <File\r
+                       RelativePath=".\index.h"\r
+                       >\r
+               </File>\r
        </Files>\r
        <Globals>\r
        </Globals>\r
diff --git a/codec/index.c b/codec/index.c
new file mode 100644 (file)
index 0000000..985c18a
--- /dev/null
@@ -0,0 +1,390 @@
+/*\r
+ * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium\r
+ * Copyright (c) 2002-2007, Professor Benoit Macq\r
+ * Copyright (c) 2003-2007, Francois-Olivier Devaux \r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'\r
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\r
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#include <stdio.h>\r
+#include <math.h>\r
+#include "openjpeg.h"\r
+#include "index.h"\r
+\r
+/* ------------------------------------------------------------------------------------ */\r
+\r
+/**\r
+Write a structured index to a file\r
+@param cstr_info Codestream information \r
+@param index Index filename\r
+@return Returns 0 if successful, returns 1 otherwise\r
+*/\r
+int write_index_file(opj_codestream_info_t *cstr_info, char *index) {\r
+       int tileno, compno, layno, resno, precno, pack_nb, x, y;\r
+       FILE *stream = NULL;\r
+       double total_disto = 0;\r
+/* UniPG>> */\r
+       int tilepartno;\r
+       char disto_on, numpix_on;\r
+\r
+#ifdef USE_JPWL\r
+       if (!strcmp(index, JPWL_PRIVATEINDEX_NAME))\r
+               return 0;\r
+#endif /* USE_JPWL */\r
+/* <<UniPG */\r
+\r
+       if (!cstr_info)         \r
+               return 1;\r
+\r
+       stream = fopen(index, "w");\r
+       if (!stream) {\r
+               fprintf(stderr, "failed to open index file [%s] for writing\n", index);\r
+               return 1;\r
+       }\r
+       \r
+       if (cstr_info->tile[0].distotile)\r
+               disto_on = 1;\r
+       else \r
+               disto_on = 0;\r
+\r
+       if (cstr_info->tile[0].numpix)\r
+               numpix_on = 1;\r
+       else \r
+               numpix_on = 0;\r
+\r
+       fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h);\r
+       fprintf(stream, "%d\n", cstr_info->prog);\r
+       fprintf(stream, "%d %d\n", cstr_info->tile_x, cstr_info->tile_y);\r
+       fprintf(stream, "%d %d\n", cstr_info->tw, cstr_info->th);\r
+       fprintf(stream, "%d\n", cstr_info->numcomps);\r
+       fprintf(stream, "%d\n", cstr_info->numlayers);\r
+       fprintf(stream, "%d\n", cstr_info->numdecompos);\r
+\r
+       for (resno = cstr_info->numdecompos[0]; resno >= 0; resno--) {\r
+               fprintf(stream, "[%d,%d] ", \r
+                       (1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno]));    /* based on tile 0 and component 0 */\r
+       }\r
+\r
+       fprintf(stream, "\n");\r
+/* UniPG>> */\r
+       fprintf(stream, "%d\n", cstr_info->main_head_start);\r
+/* <<UniPG */\r
+       fprintf(stream, "%d\n", cstr_info->main_head_end);\r
+       fprintf(stream, "%d\n", cstr_info->codestream_size);\r
+       \r
+       fprintf(stream, "\nINFO ON TILES\n");\r
+       fprintf(stream, "tileno start_pos  end_hd  end_tile   nbparts");\r
+       if (disto_on)\r
+               fprintf(stream,"         disto");\r
+       if (numpix_on)\r
+               fprintf(stream,"     nbpix");\r
+       if (disto_on && numpix_on)\r
+               fprintf(stream,"  disto/nbpix");\r
+       fprintf(stream, "\n");\r
+\r
+       for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {\r
+               fprintf(stream, "%4d %9d %9d %9d %9d", \r
+                       cstr_info->tile[tileno].tileno,\r
+                       cstr_info->tile[tileno].start_pos,\r
+                       cstr_info->tile[tileno].end_header,\r
+                       cstr_info->tile[tileno].end_pos,\r
+                       cstr_info->tile[tileno].num_tps);\r
+               if (disto_on)\r
+                       fprintf(stream," %9e", cstr_info->tile[tileno].distotile);\r
+               if (numpix_on)\r
+                       fprintf(stream," %9d", cstr_info->tile[tileno].numpix);\r
+               if (disto_on && numpix_on)\r
+                       fprintf(stream," %9e", cstr_info->tile[tileno].distotile / cstr_info->tile[tileno].numpix);\r
+               fprintf(stream, "\n");\r
+       }\r
+               \r
+       for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {\r
+               int start_pos, end_ph_pos, end_pos;\r
+               double disto = 0;\r
+               int max_numdecompos = 0;\r
+               pack_nb = 0;\r
+\r
+               for (compno = 0; compno < cstr_info->numcomps; compno++) {\r
+                       if (max_numdecompos < cstr_info->numdecompos[compno])\r
+                               max_numdecompos = cstr_info->numdecompos[compno];\r
+               }       \r
+\r
+               fprintf(stream, "\nTILE %d DETAILS\n", tileno); \r
+               fprintf(stream, "part_nb tileno  start_pack num_packs  start_pos end_tph_pos   end_pos\n");\r
+               for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++)\r
+                       fprintf(stream, "%4d %9d   %9d %9d  %9d %11d %9d\n",\r
+                               tilepartno, tileno,\r
+                               cstr_info->tile[tileno].tp[tilepartno].tp_start_pack,\r
+                               cstr_info->tile[tileno].tp[tilepartno].tp_numpacks,\r
+                               cstr_info->tile[tileno].tp[tilepartno].tp_start_pos,\r
+                               cstr_info->tile[tileno].tp[tilepartno].tp_end_header,\r
+                               cstr_info->tile[tileno].tp[tilepartno].tp_end_pos\r
+                               );\r
+\r
+               if (cstr_info->prog == LRCP) {  /* LRCP */\r
+                       fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos");\r
+                       if (disto_on)\r
+                               fprintf(stream, " disto");\r
+                       fprintf(stream,"\n");\r
+\r
+                       for (layno = 0; layno < cstr_info->numlayers; layno++) {\r
+                               for (resno = 0; resno < max_numdecompos + 1; resno++) {\r
+                                       for (compno = 0; compno < cstr_info->numcomps; compno++) {\r
+                                               int prec_max;\r
+                                               if (resno > cstr_info->numdecompos[compno])\r
+                                                       break;\r
+                                               prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];\r
+                                               for (precno = 0; precno < prec_max; precno++) {\r
+                                                       start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;\r
+                                                       end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;\r
+                                                       end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;\r
+                                                       disto = cstr_info->tile[tileno].packet[pack_nb].disto;\r
+                                                       fprintf(stream, "%4d %6d %7d %5d %6d  %6d    %6d     %6d %7d",\r
+                                                               pack_nb, tileno, layno, resno, compno, precno, start_pos, end_ph_pos, end_pos);\r
+                                                       if (disto_on)\r
+                                                               fprintf(stream, " %8e", disto);\r
+                                                       fprintf(stream, "\n");\r
+                                                       total_disto += disto;\r
+                                                       pack_nb++;\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               } /* LRCP */\r
+\r
+               else if (cstr_info->prog == RLCP) {     /* RLCP */                      \r
+                       fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos\n");\r
+                       if (disto_on)\r
+                               fprintf(stream, " disto");\r
+                       fprintf(stream,"\n");\r
+\r
+                       for (resno = 0; resno < max_numdecompos + 1; resno++) {\r
+                               for (layno = 0; layno < cstr_info->numlayers; layno++) {\r
+                                       for (compno = 0; compno < cstr_info->numcomps; compno++) {\r
+                                               int prec_max; \r
+                                               if (resno > cstr_info->numdecompos[compno])\r
+                                                       break;\r
+                                               prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];\r
+                                               for (precno = 0; precno < prec_max; precno++) {\r
+                                                       start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;\r
+                                                       end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;\r
+                                                       end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;\r
+                                                       disto = cstr_info->tile[tileno].packet[pack_nb].disto;\r
+                                                       fprintf(stream, "%4d %6d %5d %7d %6d %6d %9d   %9d %7d",\r
+                                                               pack_nb, tileno, resno, layno, compno, precno, start_pos, end_ph_pos, end_pos);\r
+                                                       if (disto_on)\r
+                                                               fprintf(stream, " %8e", disto);\r
+                                                       fprintf(stream, "\n");\r
+                                                       total_disto += disto;\r
+                                                       pack_nb++;\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               } /* RLCP */\r
+\r
+               else if (cstr_info->prog == RPCL) {     /* RPCL */\r
+\r
+                       fprintf(stream, "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos"); \r
+                       if (disto_on)\r
+                               fprintf(stream, " disto");\r
+                       fprintf(stream,"\n");\r
+\r
+                       for (resno = 0; resno < max_numdecompos + 1; resno++) {\r
+                               int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];\r
+                               for (precno = 0; precno < numprec; precno++) {                                                          \r
+                                       /* I suppose components have same XRsiz, YRsiz */\r
+                                       int x0 = cstr_info->tile_Ox + tileno - (int)floor((float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;\r
+                                       int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;\r
+                                       int x1 = x0 + cstr_info->tile_x;\r
+                                       int y1 = y0 + cstr_info->tile_y;\r
+                                       for (compno = 0; compno < cstr_info->numcomps; compno++) {                                      \r
+                                               int pcnx = cstr_info->tile[tileno].pw[resno];\r
+                                               int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno );\r
+                                               int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno );\r
+                                               int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;\r
+                                               int precno_y = (int) floor( (float)precno/(float)pcnx );\r
+                                               if (resno > cstr_info->numdecompos[compno])\r
+                                                       break;\r
+                                               for(y = y0; y < y1; y++) {                                                      \r
+                                                       if (precno_y*pcy == y ) {\r
+                                                               for (x = x0; x < x1; x++) {                                                                     \r
+                                                                       if (precno_x*pcx == x ) {\r
+                                                                               for (layno = 0; layno < cstr_info->numlayers; layno++) {\r
+                                                                                       start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;\r
+                                                                                       end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;\r
+                                                                                       end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;\r
+                                                                                       disto = cstr_info->tile[tileno].packet[pack_nb].disto;\r
+                                                                                       fprintf(stream, "%4d %6d %5d %6d %6d %7d %9d   %9d %7d",\r
+                                                                                               pack_nb, tileno, resno, precno, compno, layno, start_pos, end_ph_pos, end_pos); \r
+                                                                                       if (disto_on)\r
+                                                                                               fprintf(stream, " %8e", disto);\r
+                                                                                       fprintf(stream, "\n");\r
+                                                                                       total_disto += disto;\r
+                                                                                       pack_nb++; \r
+                                                                               }\r
+                                                                       }\r
+                                                               }/* x = x0..x1 */\r
+                                                       } \r
+                                               }  /* y = y0..y1 */\r
+                                       } /* precno */\r
+                               } /* compno */\r
+                       } /* resno */\r
+               } /* RPCL */\r
+\r
+               else if (cstr_info->prog == PCRL) {     /* PCRL */\r
+                       /* I suppose components have same XRsiz, YRsiz */\r
+                       int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;\r
+                       int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;\r
+                       int x1 = x0 + cstr_info->tile_x;\r
+                       int y1 = y0 + cstr_info->tile_y;\r
+\r
+                       // Count the maximum number of precincts \r
+                       int max_numprec = 0;\r
+                       for (resno = 0; resno < max_numdecompos + 1; resno++) {\r
+                               int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];\r
+                               if (numprec > max_numprec)\r
+                                       max_numprec = numprec;\r
+                       }\r
+\r
+                       fprintf(stream, "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos"); \r
+                       if (disto_on)\r
+                               fprintf(stream, " disto");\r
+                       fprintf(stream,"\n");\r
+\r
+                       for (precno = 0; precno < max_numprec; precno++) {\r
+                               for (compno = 0; compno < cstr_info->numcomps; compno++) {\r
+                                       for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) {\r
+                                               int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];\r
+                                               int pcnx = cstr_info->tile[tileno].pw[resno];\r
+                                               int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno );\r
+                                               int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno );\r
+                                               int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;\r
+                                               int precno_y = (int) floor( (float)precno/(float)pcnx );\r
+                                               if (precno >= numprec)\r
+                                                       continue;\r
+                                               for(y = y0; y < y1; y++) {                                                      \r
+                                                       if (precno_y*pcy == y ) {\r
+                                                               for (x = x0; x < x1; x++) {                                                                     \r
+                                                                       if (precno_x*pcx == x ) {\r
+                                                                               for (layno = 0; layno < cstr_info->numlayers; layno++) {\r
+                                                                                       start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;\r
+                                                                                       end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;\r
+                                                                                       end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;\r
+                                                                                       disto = cstr_info->tile[tileno].packet[pack_nb].disto;\r
+                                                                                       fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d   %9d %7d",\r
+                                                                                               pack_nb, tileno, precno, compno, resno, layno, start_pos, end_ph_pos, end_pos); \r
+                                                                                       if (disto_on)\r
+                                                                                               fprintf(stream, " %8e", disto);\r
+                                                                                       fprintf(stream, "\n");\r
+                                                                                       total_disto += disto;\r
+                                                                                       pack_nb++; \r
+                                                                               }\r
+                                                                       }\r
+                                                               }/* x = x0..x1 */\r
+                                                       } \r
+                                               }  /* y = y0..y1 */\r
+                                       } /* resno */\r
+                               } /* compno */\r
+                       } /* precno */\r
+               } /* PCRL */\r
+\r
+               else {  /* CPRL */\r
+                       // Count the maximum number of precincts \r
+                       int max_numprec = 0;\r
+                       for (resno = 0; resno < max_numdecompos + 1; resno++) {\r
+                               int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];\r
+                               if (numprec > max_numprec)\r
+                                       max_numprec = numprec;\r
+                       }\r
+\r
+                       fprintf(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos"); \r
+                       if (disto_on)\r
+                               fprintf(stream, " disto");\r
+                       fprintf(stream,"\n");\r
+\r
+                       for (compno = 0; compno < cstr_info->numcomps; compno++) {\r
+                               /* I suppose components have same XRsiz, YRsiz */\r
+                               int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;\r
+                               int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;\r
+                               int x1 = x0 + cstr_info->tile_x;\r
+                               int y1 = y0 + cstr_info->tile_y;\r
+\r
+                               for (precno = 0; precno < max_numprec; precno++) {\r
+                                       for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) {\r
+                                               int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];\r
+                                               int pcnx = cstr_info->tile[tileno].pw[resno];\r
+                                               int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno );\r
+                                               int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno );\r
+                                               int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;\r
+                                               int precno_y = (int) floor( (float)precno/(float)pcnx );\r
+                                               if (precno >= numprec)\r
+                                                       continue;\r
+\r
+                                               for(y = y0; y < y1; y++) {\r
+                                                       if (precno_y*pcy == y ) {\r
+                                                               for (x = x0; x < x1; x++) {\r
+                                                                       if (precno_x*pcx == x ) {\r
+                                                                               for (layno = 0; layno < cstr_info->numlayers; layno++) {\r
+                                                                                       start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;\r
+                                                                                       end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;\r
+                                                                                       end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;\r
+                                                                                       disto = cstr_info->tile[tileno].packet[pack_nb].disto;\r
+                                                                                       fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d   %9d %7d",\r
+                                                                                               pack_nb, tileno, compno, precno, resno, layno, start_pos, end_ph_pos, end_pos); \r
+                                                                                       if (disto_on)\r
+                                                                                               fprintf(stream, " %8e", disto);\r
+                                                                                       fprintf(stream, "\n");\r
+                                                                                       total_disto += disto;\r
+                                                                                       pack_nb++; \r
+                                                                               }\r
+                                                                       }\r
+                                                               }/* x = x0..x1 */\r
+                                                       }\r
+                                               } /* y = y0..y1 */\r
+                                       } /* resno */\r
+                               } /* precno */\r
+                       } /* compno */\r
+               } /* CPRL */   \r
+       } /* tileno */\r
+       \r
+       if (disto_on) {\r
+               fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */        \r
+               fprintf(stream, "%.8e\n", total_disto); /* SE totale */\r
+       }\r
+/* UniPG>> */\r
+       /* print the markers' list */\r
+       if (cstr_info->marknum) {\r
+               fprintf(stream, "\nMARKER LIST\n");\r
+               fprintf(stream, "%d\n", cstr_info->marknum);\r
+               fprintf(stream, "type\tstart_pos    length\n");\r
+               for (x = 0; x < cstr_info->marknum; x++)\r
+                       fprintf(stream, "%X\t%9d %9d\n", cstr_info->marker[x].type, cstr_info->marker[x].pos, cstr_info->marker[x].len);\r
+       }\r
+/* <<UniPG */\r
+       fclose(stream);\r
+\r
+       fprintf(stderr,"Generated index file %s\n", index);\r
+\r
+       return 0;\r
+}\r
diff --git a/codec/index.h b/codec/index.h
new file mode 100644 (file)
index 0000000..aed61e6
--- /dev/null
@@ -0,0 +1,41 @@
+/*\r
+ * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium\r
+ * Copyright (c) 2002-2007, Professor Benoit Macq\r
+ * Copyright (c) 2003-2007, Francois-Olivier Devaux\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'\r
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\r
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef __J2K_INDEX_H\r
+#define __J2K_INDEX_H\r
+\r
+/**\r
+Write a structured index to a file\r
+@param cstr_info Codestream information \r
+@param index Index filename\r
+@return Returns 0 if successful, returns 1 otherwise\r
+*/\r
+int write_index_file(opj_codestream_info_t *cstr_info, char *index);\r
+\r
+#endif /* __J2K_INDEX_H */\r
+\r
index f265894e6fe8bd04cd6b8b8eb48c92dc65cd170d..feee30a0671c59f61718238e31455515ed4b9bcd 100644 (file)
@@ -38,6 +38,7 @@
 #include "compat/getopt.h"
 #include "convert.h"
 #include "dirent.h"
+#include "index.h"
 
 #ifndef WIN32
 #define stricmp strcasecmp
@@ -229,250 +230,6 @@ 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[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 and component 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;
-               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++)
-                       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 < max_numdecompos + 1; resno++) {
-                                       for (compno = 0; compno < cstr_info->numcomps; compno++) {
-                                               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;
-                                                       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 < max_numdecompos + 1; resno++) {
-                               for (layno = 0; layno < cstr_info->numlayers; layno++) {
-                                       for (compno = 0; compno < cstr_info->numcomps; compno++) {
-                                               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;
-                                                       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 < 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;
-                                       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[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++) {                                                      
-                                                       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[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[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++) {                                                      
-                                                       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[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[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++) {
-                                                       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, char *indexfilename) {
        /* parse the command line */
index eef2ae33dcd62affdef34db9189cd6501d5681c0..efed88581252f1cbd0ab3f2b0fa2eeb6bab605ad 100644 (file)
                        RelativePath="compat\getopt.h"\r
                        >\r
                </File>\r
+               <File\r
+                       RelativePath=".\index.c"\r
+                       >\r
+               </File>\r
+               <File\r
+                       RelativePath=".\index.h"\r
+                       >\r
+               </File>\r
                <File\r
                        RelativePath="j2k_to_image.c"\r
                        >\r