/* -------------------------------------------------------------------------- */ 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[]={ {"ImgDir",REQ_ARG, NULL ,'y'}, }; const char optlist[] = "i:h"; totlen=sizeof(long_option); img_fol->set_out_format = 0; while (1) { int c = getopt_long(argc, argv,optlist,long_option,totlen); if (c == -1) break; switch (c) { case 'i': /* input file */ { char *infile = optarg; parameters->decod_format = get_file_format(infile); switch(parameters->decod_format) { case J2K_CFMT: case JP2_CFMT: case JPT_CFMT: break; default: fprintf(stderr, "!! Unrecognized format for infile : %s [accept only *.j2k, *.jp2, *.jpc or *.jpt] !!\n\n", infile); return 1; } strncpy(parameters->infile, infile, sizeof(parameters->infile)-1); } break; /* ----------------------------------------------------- */ case 'h': /* display an help description */ decode_help_display(); return 1; /* ------------------------------------------------------ */ case 'y': /* Image Directory path */ { img_fol->imgdirpath = (char*)malloc(strlen(optarg) + 1); strcpy(img_fol->imgdirpath,optarg); img_fol->set_imgdir=1; } break; /* ----------------------------------------------------- */ default: fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, optarg); break; } } /* check for possible errors */ if(img_fol->set_imgdir==1){ if(!(parameters->infile[0]==0)){ fprintf(stderr, "Error: options -ImgDir and -i cannot be used together !!\n"); return 1; } if(img_fol->set_out_format == 0){ fprintf(stderr, "Error: When -ImgDir is used, -OutFor <FORMAT> must be used !!\n"); fprintf(stderr, "Only one format allowed! Valid format PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA!!\n"); return 1; } if(!((parameters->outfile[0] == 0))){ fprintf(stderr, "Error: options -ImgDir and -o cannot be used together !!\n"); return 1; } }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"); return 1; } } 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 */ int totlen, c; opj_option_t long_option[]={ {"ImgDir",REQ_ARG, NULL ,'y'}, {"OutFor",REQ_ARG, NULL ,'O'}, }; const char optlist[] = "i:o:r:l:x:d:t:" /* UniPG>> */ #ifdef USE_JPWL "W:" #endif /* USE_JPWL */ /* <<UniPG */ "h" ; totlen=sizeof(long_option); img_fol->set_out_format = 0; do { c = opj_getopt_long(argc, argv,optlist,long_option,totlen); if (c == -1) break; switch (c) { case 'i': /* input file */ { char *infile = opj_optarg; parameters->decod_format = infile_format(infile); switch(parameters->decod_format) { case J2K_CFMT: break; case JP2_CFMT: break; case JPT_CFMT: break; case -2: fprintf(stderr, "!! infile cannot be read: %s !!\n\n", infile); return 1; default: fprintf(stderr, "!! Unrecognized format for infile: %s [accept only *.j2k, *.jp2, *.jpc or *.jpt] !!\n\n", infile); return 1; } strncpy(parameters->infile, infile, sizeof(parameters->infile)-1); } break; /* ----------------------------------------------------- */ case 'o': /* output file */ { char *outfile = opj_optarg; parameters->cod_format = get_file_format(outfile); switch(parameters->cod_format) { case PGX_DFMT: break; case PXM_DFMT: break; case BMP_DFMT: break; case TIF_DFMT: break; case RAW_DFMT: break; case RAWL_DFMT: break; case TGA_DFMT: break; case PNG_DFMT: break; default: fprintf(stderr, "Unknown output format image %s [only *.pnm, *.pgm, *.ppm, *.pgx, *.bmp, *.tif, *.raw or *.tga]!! \n", outfile); return 1; } strncpy(parameters->outfile, outfile, sizeof(parameters->outfile)-1); } break; /* ----------------------------------------------------- */ case 'O': /* output format */ { char outformat[50]; char *of = opj_optarg; sprintf(outformat,".%s",of); img_fol->set_out_format = 1; parameters->cod_format = get_file_format(outformat); switch(parameters->cod_format) { case PGX_DFMT: img_fol->out_format = "pgx"; break; case PXM_DFMT: img_fol->out_format = "ppm"; break; case BMP_DFMT: img_fol->out_format = "bmp"; break; case TIF_DFMT: img_fol->out_format = "tif"; break; case RAW_DFMT: img_fol->out_format = "raw"; break; case RAWL_DFMT: img_fol->out_format = "rawl"; break; case TGA_DFMT: img_fol->out_format = "raw"; break; case PNG_DFMT: img_fol->out_format = "png"; break; default: fprintf(stderr, "Unknown output format image %s [only *.pnm, *.pgm, *.ppm, *.pgx, *.bmp, *.tif, *.raw or *.tga]!! \n", outformat); return 1; break; } } break; /* ----------------------------------------------------- */ case 'r': /* reduce option */ { sscanf(opj_optarg, "%ud", ¶meters->cp_reduce); } break; /* ----------------------------------------------------- */ case 'l': /* layering option */ { sscanf(opj_optarg, "%ud", ¶meters->cp_layer); } break; /* ----------------------------------------------------- */ case 'h': /* display an help description */ decode_help_display(); return 1; /* ------------------------------------------------------ */ case 'y': /* Image Directory path */ { img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1); strcpy(img_fol->imgdirpath,opj_optarg); img_fol->set_imgdir=1; } break; /* ----------------------------------------------------- */ case 'd': /* Input decode ROI */ { int size_optarg = (int)strlen(opj_optarg) + 1; char *ROI_values = (char*) malloc((size_t)size_optarg); ROI_values[0] = '\0'; strncpy(ROI_values, opj_optarg, strlen(opj_optarg)); ROI_values[strlen(opj_optarg)] = '\0'; /*printf("ROI_values = %s [%d / %d]\n", ROI_values, strlen(ROI_values), size_optarg ); */ parse_DA_values( ROI_values, ¶meters->DA_x0, ¶meters->DA_y0, ¶meters->DA_x1, ¶meters->DA_y1); free(ROI_values); } break; /* ----------------------------------------------------- */ case 't': /* Input tile index */ { sscanf(opj_optarg, "%ud", ¶meters->tile_index); parameters->nb_tile_to_decode = 1; } break; /* ----------------------------------------------------- */ case 'x': /* Creation of index file */ { char *index = opj_optarg; strncpy(indexfilename, index, OPJ_PATH_LEN); } break; /* ----------------------------------------------------- */ /* UniPG>> */ #ifdef USE_JPWL case 'W': /* activate JPWL correction */ { char *token = NULL; token = strtok(opj_optarg, ","); while(token != NULL) { /* search expected number of components */ if (*token == 'c') { static int compno; compno = JPWL_EXPECTED_COMPONENTS; /* predefined no. of components */ if(sscanf(token, "c=%d", &compno) == 1) { /* Specified */ if ((compno < 1) || (compno > 256)) { fprintf(stderr, "ERROR -> invalid number of components c = %d\n", compno); return 1; } parameters->jpwl_exp_comps = compno; } else if (!strcmp(token, "c")) { /* default */ parameters->jpwl_exp_comps = compno; /* auto for default size */ } else { fprintf(stderr, "ERROR -> invalid components specified = %s\n", token); return 1; }; } /* search maximum number of tiles */ if (*token == 't') { static int tileno; tileno = JPWL_MAXIMUM_TILES; /* maximum no. of tiles */ if(sscanf(token, "t=%d", &tileno) == 1) { /* Specified */ if ((tileno < 1) || (tileno > JPWL_MAXIMUM_TILES)) { fprintf(stderr, "ERROR -> invalid number of tiles t = %d\n", tileno); return 1; } parameters->jpwl_max_tiles = tileno; } else if (!strcmp(token, "t")) { /* default */ parameters->jpwl_max_tiles = tileno; /* auto for default size */ } else { fprintf(stderr, "ERROR -> invalid tiles specified = %s\n", token); return 1; }; } /* next token or bust */ token = strtok(NULL, ","); }; parameters->jpwl_correct = OPJ_TRUE; fprintf(stdout, "JPWL correction capability activated\n"); fprintf(stdout, "- expecting %d components\n", parameters->jpwl_exp_comps); } break; #endif /* USE_JPWL */ /* <<UniPG */ /* ----------------------------------------------------- */ default: 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){ if(!(parameters->infile[0]==0)){ fprintf(stderr, "Error: options -ImgDir and -i cannot be used together !!\n"); return 1; } if(img_fol->set_out_format == 0){ fprintf(stderr, "Error: When -ImgDir is used, -OutFor <FORMAT> must be used !!\n"); fprintf(stderr, "Only one format allowed! Valid format PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA!!\n"); return 1; } if(!((parameters->outfile[0] == 0))){ fprintf(stderr, "Error: options -ImgDir and -o cannot be used together !!\n"); return 1; } }else{ if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) { fprintf(stderr, "Example: %s -i image.j2k -o image.pgm\n",argv[0]); fprintf(stderr, " Try: %s -h\n",argv[0]); return 1; } } return 0; }
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol) { /* parse the command line */ int totlen; opj_option_t long_option[]={ {"ImgDir",REQ_ARG, NULL ,'y'}, {"OutFor",REQ_ARG, NULL ,'O'}, }; /* UniPG>> */ const char optlist[] = "i:o:r:l:hx:" #ifdef USE_JPWL "W:" #endif /* USE_JPWL */ ; /*for (i=0; i<argc; i++) { printf("[%s]",argv[i]); } printf("\n");*/ /* <<UniPG */ totlen=sizeof(long_option); img_fol->set_out_format = 0; reset_options_reading(); while (1) { int c = opj_getopt_long(argc, argv,optlist,long_option,totlen); if (c == -1) break; switch (c) { case 'i': /* input file */ { char *infile = opj_optarg; parameters->decod_format = get_file_format(infile); switch(parameters->decod_format) { case J2K_CFMT: case JP2_CFMT: case JPT_CFMT: break; default: fprintf(stderr, "!! Unrecognized format for infile : %s [accept only *.j2k, *.jp2, *.jpc or *.jpt] !!\n\n", infile); return 1; } strncpy(parameters->infile, infile, sizeof(parameters->infile)-1); } break; /* ----------------------------------------------------- */ case 'o': /* output file */ { char *outfile = opj_optarg; parameters->cod_format = get_file_format(outfile); switch(parameters->cod_format) { case PGX_DFMT: case PXM_DFMT: case BMP_DFMT: case TIF_DFMT: case RAW_DFMT: case TGA_DFMT: break; default: fprintf(stderr, "Unknown output format image %s [only *.pnm, *.pgm, *.ppm, *.pgx, *.bmp, *.tif, *.raw or *.tga]!! \n", outfile); return 1; } strncpy(parameters->outfile, outfile, sizeof(parameters->outfile)-1); } break; /* ----------------------------------------------------- */ case 'O': /* output format */ { char outformat[50]; char *of = opj_optarg; sprintf(outformat,".%s",of); img_fol->set_out_format = 1; parameters->cod_format = get_file_format(outformat); switch(parameters->cod_format) { case PGX_DFMT: img_fol->out_format = "pgx"; break; case PXM_DFMT: img_fol->out_format = "ppm"; break; case BMP_DFMT: img_fol->out_format = "bmp"; break; case TIF_DFMT: img_fol->out_format = "tif"; break; case RAW_DFMT: img_fol->out_format = "raw"; break; case TGA_DFMT: img_fol->out_format = "raw"; break; default: fprintf(stderr, "Unknown output format image %s [only *.pnm, *.pgm, *.ppm, *.pgx, *.bmp, *.tif, *.raw or *.tga]!! \n", outformat); return 1; break; } } break; /* ----------------------------------------------------- */ case 'r': /* reduce option */ { sscanf(opj_optarg, "%d", ¶meters->cp_reduce); } break; /* ----------------------------------------------------- */ case 'l': /* layering option */ { sscanf(opj_optarg, "%d", ¶meters->cp_layer); } break; /* ----------------------------------------------------- */ case 'h': /* display an help description */ decode_help_display(); return 1; /* ------------------------------------------------------ */ case 'y': /* Image Directory path */ { img_fol->imgdirpath = (char*)opj_malloc(strlen(opj_optarg) + 1); strcpy(img_fol->imgdirpath,opj_optarg); img_fol->set_imgdir=1; } break; /* ----------------------------------------------------- */ /* UniPG>> */ #ifdef USE_JPWL case 'W': /* activate JPWL correction */ { char *token = NULL; token = strtok(opj_optarg, ","); while(token != NULL) { /* search expected number of components */ if (*token == 'c') { static int compno; compno = JPWL_EXPECTED_COMPONENTS; /* predefined no. of components */ if(sscanf(token, "c=%d", &compno) == 1) { /* Specified */ if ((compno < 1) || (compno > 256)) { fprintf(stderr, "ERROR -> invalid number of components c = %d\n", compno); return 1; } parameters->jpwl_exp_comps = compno; } else if (!strcmp(token, "c")) { /* default */ parameters->jpwl_exp_comps = compno; /* auto for default size */ } else { fprintf(stderr, "ERROR -> invalid components specified = %s\n", token); return 1; }; } /* search maximum number of tiles */ if (*token == 't') { static int tileno; tileno = JPWL_MAXIMUM_TILES; /* maximum no. of tiles */ if(sscanf(token, "t=%d", &tileno) == 1) { /* Specified */ if ((tileno < 1) || (tileno > JPWL_MAXIMUM_TILES)) { fprintf(stderr, "ERROR -> invalid number of tiles t = %d\n", tileno); return 1; } parameters->jpwl_max_tiles = tileno; } else if (!strcmp(token, "t")) { /* default */ parameters->jpwl_max_tiles = tileno; /* auto for default size */ } else { fprintf(stderr, "ERROR -> invalid tiles specified = %s\n", token); return 1; }; } /* next token or bust */ token = strtok(NULL, ","); }; parameters->jpwl_correct = true; fprintf(stdout, "JPWL correction capability activated\n"); fprintf(stdout, "- expecting %d components\n", parameters->jpwl_exp_comps); } break; #endif /* USE_JPWL */ /* <<UniPG */ /* ----------------------------------------------------- */ default: fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, opj_optarg); break; } } /* No check for possible errors before the -i and -o options are of course not mandatory*/ return 0; }
/* -------------------------------------------------------------------------- */ 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:f:hv"; totlen=sizeof(long_option); img_fol->set_out_format = 0; do { c = opj_getopt_long(argc, argv,optlist,long_option,totlen); if (c == -1) break; switch (c) { case 'i': { /* input file */ char *infile = opj_optarg; parameters->decod_format = infile_format(infile); switch(parameters->decod_format) { case J2K_CFMT: break; case JP2_CFMT: break; case JPT_CFMT: break; default: fprintf(stderr, "[ERROR] Unknown input file format: %s \n" " Known file formats are *.j2k, *.jp2, *.jpc or *.jpt\n", infile); return 1; } if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infile) != 0) { fprintf(stderr, "[ERROR] Path is too long\n"); return 1; } } break; /* ------------------------------------------------------ */ case 'o': { /* output file */ if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), opj_optarg) != 0) { fprintf(stderr, "[ERROR] Path is too long\n"); return 1; } } break; /* ----------------------------------------------------- */ case 'f': /* flag */ img_fol->flag = atoi(opj_optarg); break; /* ----------------------------------------------------- */ case 'h': /* display an help description */ decode_help_display(); return 1; /* ------------------------------------------------------ */ case 'y': { /* Image Directory path */ img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1); strcpy(img_fol->imgdirpath,opj_optarg); img_fol->set_imgdir=1; } break; /* ----------------------------------------------------- */ case 'v': { /* Verbose mode */ parameters->m_verbose = 1; } break; /* ----------------------------------------------------- */ default: fprintf(stderr, "[WARNING] An invalid option has been ignored.\n"); break; } } while(c != -1); /* check for possible errors */ if(img_fol->set_imgdir==1) { if(!(parameters->infile[0]==0)) { fprintf(stderr, "[ERROR] options -ImgDir and -i cannot be used together.\n"); return 1; } if(img_fol->set_out_format == 0) { fprintf(stderr, "[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used.\n"); fprintf(stderr, "Only one format allowed.\n" "Valid format are PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA.\n"); return 1; } if(!(parameters->outfile[0] == 0)) { fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together\n"); return 1; } } else { if(parameters->infile[0] == 0) { fprintf(stderr, "[ERROR] Required parameter is missing\n"); fprintf(stderr, "Example: %s -i image.j2k\n",argv[0]); fprintf(stderr, " Help: %s -h\n",argv[0]); return 1; } } return 0; }
/* -------------------------------------------------------------------------- */ 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"; totlen=sizeof(long_option); img_fol->set_out_format = 0; do { c = opj_getopt_long(argc, argv,optlist,long_option,totlen); if (c == -1) break; switch (c) { case 'i': /* input file */ { char *infile = opj_optarg; parameters->decod_format = infile_format(infile); switch(parameters->decod_format) { case J2K_CFMT: break; case JP2_CFMT: break; case JPT_CFMT: break; default: fprintf(stderr, "!! Unrecognized format for infile : %s [accept only *.j2k, *.jp2, *.jpc or *.jpt] !!\n\n", infile); return 1; } strncpy(parameters->infile, infile, sizeof(parameters->infile)-1); } break; /* ------------------------------------------------------ */ case 'o': /* output file */ { char *outfile = opj_optarg; strncpy(parameters->outfile, outfile, sizeof(parameters->outfile)-1); } break; /* ----------------------------------------------------- */ case 'h': /* display an help description */ decode_help_display(); return 1; /* ------------------------------------------------------ */ case 'y': /* Image Directory path */ { img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1); strcpy(img_fol->imgdirpath,opj_optarg); img_fol->set_imgdir=1; } break; /* ----------------------------------------------------- */ case 'v': /* Verbose mode */ { parameters->m_verbose = 1; } break; /* ----------------------------------------------------- */ default: 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){ if(!(parameters->infile[0]==0)){ fprintf(stderr, "Error: options -ImgDir and -i cannot be used together !!\n"); return 1; } if(img_fol->set_out_format == 0){ fprintf(stderr, "Error: When -ImgDir is used, -OutFor <FORMAT> must be used !!\n"); fprintf(stderr, "Only one format allowed! Valid format PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA!!\n"); return 1; } if(!(parameters->outfile[0] == 0)){ fprintf(stderr, "Error: options -ImgDir and -o cannot be used together !!\n"); return 1; } }else{ if(parameters->infile[0] == 0) { fprintf(stderr, "Example: %s -i image.j2k\n",argv[0]); fprintf(stderr, " Try: %s -h\n",argv[0]); return 1; } } return 0; }
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters) { /* parse the command line */ /* UniPG>> */ const char optlist[] = "i:o:r:l:h" #ifdef USE_JPWL "W:" #endif /* USE_JPWL */ ; /* <<UniPG */ while (1) { int c = getopt(argc, argv, optlist); /* >>JPWL<< */ if (c == -1) break; switch (c) { case 'i': /* input file */ { char *infile = optarg; parameters->decod_format = get_file_format(infile); switch(parameters->decod_format) { case J2K_CFMT: case JP2_CFMT: case JPT_CFMT: break; default: fprintf(stderr, "!! Unrecognized format for infile : %s [accept only *.j2k, *.jp2, *.jpc or *.jpt] !!\n\n", infile); return 1; } strncpy(parameters->infile, infile, OPJ_PATH_LEN); } break; /* ----------------------------------------------------- */ case 'o': /* output file */ { char *outfile = optarg; parameters->cod_format = get_file_format(outfile); switch(parameters->cod_format) { case PGX_DFMT: case PXM_DFMT: case BMP_DFMT: break; default: fprintf(stderr, "Unknown output format image %s [only *.pnm, *.pgm, *.ppm, *.pgx or *.bmp]!! \n", outfile); return 1; } strncpy(parameters->outfile, outfile, OPJ_PATH_LEN); } break; /* ----------------------------------------------------- */ case 'r': /* reduce option */ { sscanf(optarg, "%d", ¶meters->cp_reduce); } break; /* ----------------------------------------------------- */ case 'l': /* layering option */ { sscanf(optarg, "%d", ¶meters->cp_layer); } break; /* ----------------------------------------------------- */ case 'h': /* display an help description */ decode_help_display(); return 1; /* UniPG>> */ #ifdef USE_JPWL /* ----------------------------------------------------- */ case 'W': /* activate JPWL correction */ { char *token = NULL; token = strtok(optarg, ","); while(token != NULL) { /* search expected number of components */ if (*token == 'c') { static int compno; compno = JPWL_EXPECTED_COMPONENTS; /* predefined no. of components */ if(sscanf(token, "c=%d", &compno) == 1) { /* Specified */ if ((compno < 1) || (compno > 256)) { fprintf(stderr, "ERROR -> invalid number of components c = %d\n", compno); return 1; } parameters->jpwl_exp_comps = compno; } else if (!strcmp(token, "c")) { /* default */ parameters->jpwl_exp_comps = compno; /* auto for default size */ } else { fprintf(stderr, "ERROR -> invalid components specified = %s\n", token); return 1; }; } /* search maximum number of tiles */ if (*token == 't') { static int tileno; tileno = JPWL_MAXIMUM_TILES; /* maximum no. of tiles */ if(sscanf(token, "t=%d", &tileno) == 1) { /* Specified */ if ((tileno < 1) || (tileno > JPWL_MAXIMUM_TILES)) { fprintf(stderr, "ERROR -> invalid number of tiles t = %d\n", tileno); return 1; } parameters->jpwl_max_tiles = tileno; } else if (!strcmp(token, "t")) { /* default */ parameters->jpwl_max_tiles = tileno; /* auto for default size */ } else { fprintf(stderr, "ERROR -> invalid tiles specified = %s\n", token); return 1; }; } /* next token or bust */ token = strtok(NULL, ","); }; parameters->jpwl_correct = true; fprintf(stdout, "JPWL correction capability activated\n"); fprintf(stdout, "- expecting %d components\n", parameters->jpwl_exp_comps); } break; #endif /* USE_JPWL */ /* <<UniPG */ /* ----------------------------------------------------- */ default: fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, optarg); break; } } /* check for possible errors */ if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) { fprintf(stderr,"ERROR -> At least one required argument is missing\nCheck j2k_to_image -h for usage information\n"); return 1; } return 0; }
/* -------------------------------------------------------------------------- */ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *parameters,img_fol_t *img_fol) { /* parse the command line */ int totlen, c; opj_option_t long_option[]={ {"ImgDir", REQ_ARG, NULL,'y'}, {"OutFor", REQ_ARG, NULL,'O'}, {"force-rgb", NO_ARG, NULL, 1}, {"upsample", NO_ARG, NULL, 1}, {"split-pnm", NO_ARG, NULL, 1} }; const char optlist[] = "i:o:r:l:x:d:t:p:" /* UniPG>> */ #ifdef USE_JPWL "W:" #endif /* USE_JPWL */ /* <<UniPG */ "h" ; long_option[2].flag = &(parameters->force_rgb); long_option[3].flag = &(parameters->upsample); long_option[4].flag = &(parameters->split_pnm); totlen=sizeof(long_option); opj_reset_options_reading(); img_fol->set_out_format = 0; do { c = opj_getopt_long(argc, argv,optlist,long_option,totlen); if (c == -1) break; switch (c) { case 0: /* long opt with flag */ break; case 'i': /* input file */ { char *infile = opj_optarg; parameters->decod_format = infile_format(infile); switch(parameters->decod_format) { case J2K_CFMT: break; case JP2_CFMT: break; case JPT_CFMT: break; case -2: fprintf(stderr, "!! infile cannot be read: %s !!\n\n", infile); return 1; default: fprintf(stderr, "[ERROR] Unknown input file format: %s \n" " Known file formats are *.j2k, *.jp2, *.jpc or *.jpt\n", infile); return 1; } if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infile) != 0) { fprintf(stderr, "[ERROR] Path is too long\n"); return 1; } } break; /* ----------------------------------------------------- */ case 'o': /* output file */ { char *outfile = opj_optarg; parameters->cod_format = get_file_format(outfile); switch(parameters->cod_format) { case PGX_DFMT: break; case PXM_DFMT: break; case BMP_DFMT: break; case TIF_DFMT: break; case RAW_DFMT: break; case RAWL_DFMT: break; case TGA_DFMT: break; case PNG_DFMT: break; default: fprintf(stderr, "Unknown output format image %s [only *.png, *.pnm, *.pgm, *.ppm, *.pgx, *.bmp, *.tif, *.raw or *.tga]!!\n", outfile); return 1; } if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), outfile) != 0) { fprintf(stderr, "[ERROR] Path is too long\n"); return 1; } } break; /* ----------------------------------------------------- */ case 'O': /* output format */ { char outformat[50]; char *of = opj_optarg; sprintf(outformat,".%s",of); img_fol->set_out_format = 1; parameters->cod_format = get_file_format(outformat); switch(parameters->cod_format) { case PGX_DFMT: img_fol->out_format = "pgx"; break; case PXM_DFMT: img_fol->out_format = "ppm"; break; case BMP_DFMT: img_fol->out_format = "bmp"; break; case TIF_DFMT: img_fol->out_format = "tif"; break; case RAW_DFMT: img_fol->out_format = "raw"; break; case RAWL_DFMT: img_fol->out_format = "rawl"; break; case TGA_DFMT: img_fol->out_format = "raw"; break; case PNG_DFMT: img_fol->out_format = "png"; break; default: fprintf(stderr, "Unknown output format image %s [only *.png, *.pnm, *.pgm, *.ppm, *.pgx, *.bmp, *.tif, *.raw or *.tga]!!\n", outformat); return 1; break; } } break; /* ----------------------------------------------------- */ case 'r': /* reduce option */ { sscanf(opj_optarg, "%u", &(parameters->core.cp_reduce)); } break; /* ----------------------------------------------------- */ case 'l': /* layering option */ { sscanf(opj_optarg, "%u", &(parameters->core.cp_layer)); } break; /* ----------------------------------------------------- */ case 'h': /* display an help description */ decode_help_display(); return 1; /* ----------------------------------------------------- */ case 'y': /* Image Directory path */ { img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1); strcpy(img_fol->imgdirpath,opj_optarg); img_fol->set_imgdir=1; } break; /* ----------------------------------------------------- */ case 'd': /* Input decode ROI */ { size_t size_optarg = (size_t)strlen(opj_optarg) + 1U; char *ROI_values = (char*) malloc(size_optarg); if (ROI_values == NULL) { fprintf(stderr, "[ERROR] Couldn't allocate memory\n"); return 1; } ROI_values[0] = '\0'; memcpy(ROI_values, opj_optarg, size_optarg); /*printf("ROI_values = %s [%d / %d]\n", ROI_values, strlen(ROI_values), size_optarg ); */ parse_DA_values( ROI_values, ¶meters->DA_x0, ¶meters->DA_y0, ¶meters->DA_x1, ¶meters->DA_y1); free(ROI_values); } break; /* ----------------------------------------------------- */ case 't': /* Input tile index */ { sscanf(opj_optarg, "%u", ¶meters->tile_index); parameters->nb_tile_to_decode = 1; } break; /* ----------------------------------------------------- */ case 'x': /* Creation of index file */ { if (opj_strcpy_s(parameters->indexfilename, sizeof(parameters->indexfilename), opj_optarg) != 0) { fprintf(stderr, "[ERROR] Path is too long\n"); return 1; } } break; /* ----------------------------------------------------- */ case 'p': /* Force precision */ { if (!parse_precision(opj_optarg, parameters)) { return 1; } } break; /* ----------------------------------------------------- */ /* UniPG>> */ #ifdef USE_JPWL case 'W': /* activate JPWL correction */ { char *token = NULL; token = strtok(opj_optarg, ","); while(token != NULL) { /* search expected number of components */ if (*token == 'c') { static int compno; compno = JPWL_EXPECTED_COMPONENTS; /* predefined no. of components */ if(sscanf(token, "c=%d", &compno) == 1) { /* Specified */ if ((compno < 1) || (compno > 256)) { fprintf(stderr, "ERROR -> invalid number of components c = %d\n", compno); return 1; } parameters->jpwl_exp_comps = compno; } else if (!strcmp(token, "c")) { /* default */ parameters->jpwl_exp_comps = compno; /* auto for default size */ } else { fprintf(stderr, "ERROR -> invalid components specified = %s\n", token); return 1; }; } /* search maximum number of tiles */ if (*token == 't') { static int tileno; tileno = JPWL_MAXIMUM_TILES; /* maximum no. of tiles */ if(sscanf(token, "t=%d", &tileno) == 1) { /* Specified */ if ((tileno < 1) || (tileno > JPWL_MAXIMUM_TILES)) { fprintf(stderr, "ERROR -> invalid number of tiles t = %d\n", tileno); return 1; } parameters->jpwl_max_tiles = tileno; } else if (!strcmp(token, "t")) { /* default */ parameters->jpwl_max_tiles = tileno; /* auto for default size */ } else { fprintf(stderr, "ERROR -> invalid tiles specified = %s\n", token); return 1; }; } /* next token or bust */ token = strtok(NULL, ","); }; parameters->jpwl_correct = OPJ_TRUE; fprintf(stdout, "JPWL correction capability activated\n"); fprintf(stdout, "- expecting %d components\n", parameters->jpwl_exp_comps); } break; #endif /* USE_JPWL */ /* <<UniPG */ /* ----------------------------------------------------- */ default: fprintf(stderr, "[WARNING] An invalid option has been ignored.\n"); break; } }while(c != -1); /* check for possible errors */ if(img_fol->set_imgdir==1){ if(!(parameters->infile[0]==0)){ fprintf(stderr, "[ERROR] options -ImgDir and -i cannot be used together.\n"); return 1; } if(img_fol->set_out_format == 0){ fprintf(stderr, "[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used.\n"); fprintf(stderr, "Only one format allowed.\n" "Valid format are PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA.\n"); return 1; } if(!((parameters->outfile[0] == 0))){ fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together.\n"); return 1; } }else{ if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) { fprintf(stderr, "[ERROR] Required parameters are missing\n" "Example: %s -i image.j2k -o image.pgm\n",argv[0]); fprintf(stderr, " Help: %s -h\n",argv[0]); return 1; } } return 0; }