WIP: begin to test opj_read_tile_header with V2 style
[openjpeg.git] / applications / codec / j2k_to_image.c
index 3da8311922dd053a1d168b46ba74dd605899b81a..85bca04ccb8e65d0d66652359ce047372c463248 100644 (file)
@@ -51,7 +51,7 @@
 
 #include "opj_config.h"
 #include "openjpeg.h"
-#include "getopt.h"
+#include "opj_getopt.h"
 #include "convert.h"
 #include "index.h"
 
@@ -85,7 +85,7 @@ typedef struct img_folder{
 
 }img_fol_t;
 
-void decode_help_display() {
+void decode_help_display(void) {
        fprintf(stdout,"HELP for j2k_to_image\n----\n\n");
        fprintf(stdout,"- the -h option displays this help information on screen\n\n");
 
@@ -237,8 +237,8 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparamet
 /* -------------------------------------------------------------------------- */
 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[]={
+       int totlen, c;
+       opj_option_t long_option[]={
                {"ImgDir",REQ_ARG, NULL ,'y'},
                {"OutFor",REQ_ARG, NULL ,'O'},
        };
@@ -253,14 +253,14 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
                        "h"             ;
        totlen=sizeof(long_option);
        img_fol->set_out_format = 0;
-       while (1) {
-               int c = getopt_long(argc, argv,optlist,long_option,totlen);
+       do {
+               c = opj_getopt_long(argc, argv,optlist,long_option,totlen);
                if (c == -1)
                        break;
                switch (c) {
                        case 'i':                       /* input file */
                        {
-                               char *infile = optarg;
+                               char *infile = opj_optarg;
                                parameters->decod_format = get_file_format(infile);
                                switch(parameters->decod_format) {
                                        case J2K_CFMT:
@@ -281,7 +281,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
 
                        case 'o':                       /* output file */
                        {
-                               char *outfile = optarg;
+                               char *outfile = opj_optarg;
                                parameters->cod_format = get_file_format(outfile);
                                switch(parameters->cod_format) {
                                        case PGX_DFMT:
@@ -305,7 +305,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
                        case 'O':                       /* output format */
                        {
                                char outformat[50];
-                               char *of = optarg;
+                               char *of = opj_optarg;
                                sprintf(outformat,".%s",of);
                                img_fol->set_out_format = 1;
                                parameters->cod_format = get_file_format(outformat);
@@ -344,7 +344,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
 
                        case 'r':               /* reduce option */
                        {
-                               sscanf(optarg, "%d", &parameters->cp_reduce);
+                               sscanf(opj_optarg, "%d", &parameters->cp_reduce);
                        }
                        break;
                        
@@ -353,7 +353,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
 
                        case 'l':               /* layering option */
                        {
-                               sscanf(optarg, "%d", &parameters->cp_layer);
+                               sscanf(opj_optarg, "%d", &parameters->cp_layer);
                        }
                        break;
                        
@@ -367,15 +367,15 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
 
                        case 'y':                       /* Image Directory path */
                                {
-                                       img_fol->imgdirpath = (char*)malloc(strlen(optarg) + 1);
-                                       strcpy(img_fol->imgdirpath,optarg);
+                                       img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
+                                       strcpy(img_fol->imgdirpath,opj_optarg);
                                        img_fol->set_imgdir=1;
                                }
                                break;
                                /* ----------------------------------------------------- */                                                             
                        case 'x':                       /* Creation of index file */
                                {
-                                       char *index = optarg;
+                                       char *index = opj_optarg;
                                        strncpy(indexfilename, index, OPJ_PATH_LEN);
                                }
                                break;
@@ -387,7 +387,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
                        {
                                char *token = NULL;
 
-                               token = strtok(optarg, ",");
+                               token = strtok(opj_optarg, ",");
                                while(token != NULL) {
 
                                        /* search expected number of components */
@@ -454,10 +454,10 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
                                /* ----------------------------------------------------- */
                        
                        default:
-                               fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, optarg);
+                               fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, opj_optarg);
                                break;
                }
-       }
+       }while(c != -1);
 
        /* check for possible errors */
        if(img_fol->set_imgdir==1){
@@ -641,7 +641,7 @@ int main(int argc, char **argv) {
 
                        /* Write the index to disk */
                        if (*indexfilename) {
-                               char bSuccess;
+                               opj_bool bSuccess;
                                bSuccess = write_index_file(&cstr_info, indexfilename);
                                if (bSuccess) {
                                        fprintf(stderr, "Failed to output index file\n");
@@ -683,7 +683,7 @@ int main(int argc, char **argv) {
 
                        /* Write the index to disk */
                        if (*indexfilename) {
-                               char bSuccess;
+                               opj_bool bSuccess;
                                bSuccess = write_index_file(&cstr_info, indexfilename);
                                if (bSuccess) {
                                        fprintf(stderr, "Failed to output index file\n");
@@ -725,7 +725,7 @@ int main(int argc, char **argv) {
 
                        /* Write the index to disk */
                        if (*indexfilename) {
-                               char bSuccess;
+                               opj_bool bSuccess;
                                bSuccess = write_index_file(&cstr_info, indexfilename);
                                if (bSuccess) {
                                        fprintf(stderr, "Failed to output index file\n");