[trunk] Add internal implementation to dump all tiles/comp info
[openjpeg.git] / src / bin / jp2 / opj_dump.c
index 2bc1893ac50a26d45385862f4acf7fac1f9d2885..1742f3ebb76f1fb7a0cc4ed41b9b7c0c99b91e40 100644 (file)
@@ -71,18 +71,18 @@ typedef struct img_folder{
        /** Enable Cod Format for output*/
        char set_out_format;
 
+  int flag;
 }img_fol_t;
 
 /* -------------------------------------------------------------------------- */
 /* Declarations                                                               */
-int get_num_images(char *imgdirpath);
-int load_images(dircnt_t *dirptr, char *imgdirpath);
-int get_file_format(const char *filename);
-char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters);
+static int get_num_images(char *imgdirpath);
+static int load_images(dircnt_t *dirptr, char *imgdirpath);
+static int get_file_format(const char *filename);
+static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters);
 static int infile_format(const char *fname);
 
-int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol);
-int parse_DA_values( char* inArg, unsigned int *DA_x0, unsigned int *DA_y0, unsigned int *DA_x1, unsigned int *DA_y1);
+static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol);
 
 /* -------------------------------------------------------------------------- */
 static void decode_help_display(void) {
@@ -116,7 +116,7 @@ static void decode_help_display(void) {
 }
 
 /* -------------------------------------------------------------------------- */
-int get_num_images(char *imgdirpath){
+static int get_num_images(char *imgdirpath){
        DIR *dir;
        struct dirent* content; 
        int num_images = 0;
@@ -138,7 +138,7 @@ int get_num_images(char *imgdirpath){
 }
 
 /* -------------------------------------------------------------------------- */
-int load_images(dircnt_t *dirptr, char *imgdirpath){
+static int load_images(dircnt_t *dirptr, char *imgdirpath){
        DIR *dir;
        struct dirent* content; 
        int i = 0;
@@ -164,7 +164,7 @@ int load_images(dircnt_t *dirptr, char *imgdirpath){
 }
 
 /* -------------------------------------------------------------------------- */
-int get_file_format(const char *filename) {
+static int get_file_format(const char *filename) {
        unsigned int i;
        static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc"  };
        static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT };
@@ -184,7 +184,7 @@ int get_file_format(const char *filename) {
 }
 
 /* -------------------------------------------------------------------------- */
-char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters){
+static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters){
        char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN];
        char *temp_p, temp1[OPJ_PATH_LEN]="";
 
@@ -221,7 +221,7 @@ static int infile_format(const char *fname)
        const char *s, *magic_s;
        int ext_format, magic_format;
        unsigned char buf[12];
-       unsigned int l_nb_read; 
+       size_t l_nb_read; 
 
        reader = fopen(fname, "rb");
 
@@ -269,12 +269,12 @@ static int infile_format(const char *fname)
  * Parse the command line
  */
 /* -------------------------------------------------------------------------- */
-int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol) {
+static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol) {
        int totlen, c;
        opj_option_t long_option[]={
                {"ImgDir",REQ_ARG, NULL ,'y'},
        };
-       const char optlist[] = "i:o:hv";
+       const char optlist[] = "i:o:f:hv";
 
        totlen=sizeof(long_option);
        img_fol->set_out_format = 0;
@@ -314,6 +314,10 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
                        break;
                                
                                /* ----------------------------------------------------- */
+      case 'f':                        /* flag */
+        img_fol->flag = atoi(opj_optarg);
+        break;
+                               /* ----------------------------------------------------- */
 
                        case 'h':                       /* display an help description */
                                decode_help_display();
@@ -401,7 +405,7 @@ static void info_callback(const char *msg, void *client_data) {
 /* -------------------------------------------------------------------------- */
 int main(int argc, char *argv[])
 {
-       FILE *fsrc = NULL, *fout = NULL;
+       FILE *fout = NULL;
 
        opj_dparameters_t parameters;                   /* Decompression parameters */
        opj_image_t* image = NULL;                                      /* Image structure */
@@ -425,6 +429,7 @@ int main(int argc, char *argv[])
 
        /* Initialize img_fol */
        memset(&img_fol,0,sizeof(img_fol_t));
+  img_fol.flag = OPJ_IMG_INFO | OPJ_J2K_MH_INFO | OPJ_J2K_MH_IND;
 
        /* Parse input and get user encoding parameters */
        if(parse_cmdline_decoder(argc, argv, &parameters,&img_fol) == 1) {
@@ -438,8 +443,8 @@ int main(int argc, char *argv[])
 
                dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
                if(dirptr){
-                       dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char));     /* Stores at max 10 image file names*/
-                       dirptr->filename = (char**) malloc(num_images*sizeof(char*));
+                       dirptr->filename_buf = (char*)malloc((size_t)num_images*OPJ_PATH_LEN*sizeof(char));     /* Stores at max 10 image file names*/
+                       dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*));
 
                        if(!dirptr->filename_buf){
                                return EXIT_FAILURE;
@@ -486,16 +491,10 @@ int main(int argc, char *argv[])
 
                /* Read the input file and put it in memory */
                /* ---------------------------------------- */
-               fsrc = fopen(parameters.infile, "rb");
-               if (!fsrc) {
-                       fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile);
-                       return EXIT_FAILURE;
-               }
 
-               l_stream = opj_stream_create_default_file_stream(fsrc,1);
+               l_stream = opj_stream_create_default_file_stream_v3(parameters.infile,1);
                if (!l_stream){
-                       fclose(fsrc);
-                       fprintf(stderr, "ERROR -> failed to create the stream from the file\n");
+                       fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n",parameters.infile);
                        return EXIT_FAILURE;
                }
 
@@ -523,7 +522,7 @@ int main(int argc, char *argv[])
                        }
                        default:
                                fprintf(stderr, "skipping file..\n");
-                               opj_stream_destroy(l_stream);
+                               opj_stream_destroy_v3(l_stream);
                                continue;
                }
 
@@ -535,8 +534,7 @@ int main(int argc, char *argv[])
                /* Setup the decoder decoding parameters using user parameters */
                if ( !opj_setup_decoder(l_codec, &parameters) ){
                        fprintf(stderr, "ERROR -> opj_dump: failed to setup the decoder\n");
-                       opj_stream_destroy(l_stream);
-                       fclose(fsrc);
+                       opj_stream_destroy_v3(l_stream);
                        opj_destroy_codec(l_codec);
                        fclose(fout);
                        return EXIT_FAILURE;
@@ -545,23 +543,21 @@ int main(int argc, char *argv[])
                /* Read the main header of the codestream and if necessary the JP2 boxes*/
                if(! opj_read_header(l_stream, l_codec, &image)){
                        fprintf(stderr, "ERROR -> opj_dump: failed to read the header\n");
-                       opj_stream_destroy(l_stream);
-                       fclose(fsrc);
+                       opj_stream_destroy_v3(l_stream);
                        opj_destroy_codec(l_codec);
                        opj_image_destroy(image);
                        fclose(fout);
                        return EXIT_FAILURE;
                }
 
-               opj_dump_codec(l_codec, OPJ_IMG_INFO | OPJ_J2K_MH_INFO | OPJ_J2K_MH_IND, fout );
+               opj_dump_codec(l_codec, img_fol.flag, fout );
 
                cstr_info = opj_get_cstr_info(l_codec);
 
                cstr_index = opj_get_cstr_index(l_codec);
 
                /* close the byte stream */
-               opj_stream_destroy(l_stream);
-               fclose(fsrc);
+               opj_stream_destroy_v3(l_stream);
 
                /* free remaining structures */
                if (l_codec) {