(thanks to Winfried for his help)
[openjpeg.git] / codec / j2k_dump.c
index 6d92bcbb48f51fcd15bae846eb065ce86b34a3e5..3c3e8d9148650c2f01b07b4afbc28d0d9a3aef6d 100644 (file)
 #include <stdlib.h>
 #include <math.h>
 
-#include "openjpeg.h"
-#include "j2k.h"
-#include "jp2.h"
-#include "compat/getopt.h"
-#include "convert.h"
-#include "dirent.h"
-#include "index.h"
-
-#ifndef WIN32
+#ifdef _WIN32
+#include "windirent.h"
+#else
+#include <dirent.h>
+#endif /* _WIN32 */
+
+#ifdef _WIN32
+#include <windows.h>
+#else
 #include <strings.h>
 #define _stricmp strcasecmp
 #define _strnicmp strncasecmp
-#endif
+#endif /* _WIN32 */
 
-/* ----------------------------------------------------------------------- */
-
-#define J2K_CFMT 0
-#define JP2_CFMT 1
-#define JPT_CFMT 2
+#include "opj_config.h"
+#include "openjpeg.h"
+#include "../libopenjpeg/j2k.h"
+#include "../libopenjpeg/jp2.h"
+#include "getopt.h"
+#include "convert.h"
+#include "index.h"
 
-#define PXM_DFMT 10
-#define PGX_DFMT 11
-#define BMP_DFMT 12
-#define YUV_DFMT 13
-#define TIF_DFMT 14
-#define RAW_DFMT 15
-#define TGA_DFMT 16
-#define PNG_DFMT 17
-/* ----------------------------------------------------------------------- */
+#include "format_defs.h"
 
 typedef struct dircnt{
        /** Buffer for holding images read from Directory*/
@@ -80,7 +74,7 @@ typedef struct img_folder{
 }img_fol_t;
 
 void decode_help_display() {
-       fprintf(stdout,"HELP\n----\n\n");
+       fprintf(stdout,"HELP for j2k_dump\n----\n\n");
        fprintf(stdout,"- the -h option displays this help information on screen\n\n");
 
 /* UniPG>> */
@@ -269,8 +263,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
                }
        }else{
                if((parameters->infile[0] == 0) ) {
-                       fprintf(stderr, "Error: One of the options -i or -ImgDir must be specified\n");
-                       fprintf(stderr, "usage: image_to_j2k -i *.j2k/jp2/j2c (+ options)\n");
+                       fprintf(stderr, "Example: %s -i image.j2k\n",argv[0]);
+                       fprintf(stderr, "    Try: %s -h\n",argv[0]);
                        return 1;
                }
        }
@@ -302,8 +296,6 @@ void info_callback(const char *msg, void *client_data) {
        fprintf(stdout, "[INFO] %s", msg);
 }
 
-//void j2k_dump_cp(FILE *fd, opj_image_t * img, opj_cp_t * cp);
-
 /* -------------------------------------------------------------------------- */
 
 int main(int argc, char *argv[])
@@ -317,7 +309,7 @@ int main(int argc, char *argv[])
        int file_length;
        int num_images;
        int i,imageno;
-       dircnt_t *dirptr;
+       dircnt_t *dirptr = NULL;
        opj_dinfo_t* dinfo = NULL;      /* handle to a decompressor */
        opj_cio_t *cio = NULL;
        opj_codestream_info_t cstr_info;  /* Codestream information structure */
@@ -351,25 +343,26 @@ int main(int argc, char *argv[])
                        dirptr->filename = (char**) malloc(num_images*sizeof(char*));
 
                        if(!dirptr->filename_buf){
-                               return 0;
+                               return 1;
                        }
                        for(i=0;i<num_images;i++){
                                dirptr->filename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN;
                        }
                }
                if(load_images(dirptr,img_fol.imgdirpath)==1){
-                       return 0;
+                       return 1;
                }
                if (num_images==0){
                        fprintf(stdout,"Folder is empty\n");
-                       return 0;
+                       return 1;
                }
        }else{
                num_images=1;
        }
 
        /*Encoding image one by one*/
-       for(imageno = 0; imageno < num_images ; imageno++)      {
+       for(imageno = 0; imageno < num_images ; imageno++)
+  {
                image = NULL;
                fprintf(stderr,"\n");
 
@@ -425,7 +418,10 @@ int main(int argc, char *argv[])
                                opj_cio_close(cio);
                                return 1;
                        }
-                       /* dump */
+                       /* dump image */
+      j2k_dump_image(stdout, image);
+
+                       /* dump cp */
       j2k_dump_cp(stdout, image, ((opj_j2k_t*)dinfo->j2k_handle)->cp);
 
                        /* close the byte stream */
@@ -469,7 +465,14 @@ int main(int argc, char *argv[])
                                opj_cio_close(cio);
                                return 1;
                        }
-                       /* dump */
+                       /* dump image */
+         if(image->icc_profile_buf)
+        {
+         free(image->icc_profile_buf); image->icc_profile_buf = NULL;
+        }      
+      j2k_dump_image(stdout, image);
+
+                       /* dump cp */
       j2k_dump_cp(stdout, image, ((opj_jp2_t*)dinfo->jp2_handle)->j2k->cp);
 
                        /* close the byte stream */