[trunk] fixed some warning and errors formatting and add a '-version'

option to opj_compress and opj_decompress binaries
This commit is contained in:
Antonin Descampe 2014-04-22 21:22:49 +00:00
parent 9a3d660d1b
commit 8d93eae64a
3 changed files with 70 additions and 50 deletions

View File

@ -467,7 +467,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
{"POC",REQ_ARG, NULL ,'P'},
{"ROI",REQ_ARG, NULL ,'R'},
{"jpip",NO_ARG, NULL, 'J'},
{"mct",REQ_ARG, NULL, 'Y'}
{"mct",REQ_ARG, NULL, 'Y'},
{"version",NO_ARG, NULL, 'v'}
};
/* parse the command line */
@ -475,7 +476,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
#ifdef USE_JPWL
"W:"
#endif /* USE_JPWL */
"h";
"hv";
totlen=sizeof(long_option);
img_fol->set_out_format=0;
@ -502,8 +503,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
break;
default:
fprintf(stderr,
"!! Unrecognized format for infile : %s "
"[accept only *.pnm, *.pgm, *.ppm, *.pgx, *png, *.bmp, *.tif, *.raw or *.tga] !!\n\n",
"[ERROR] Unknown input file format: %s \n"
" Known file formats are *.pnm, *.pgm, *.ppm, *.pgx, *png, *.bmp, *.tif, *.raw or *.tga\n",
infile);
return 1;
}
@ -842,6 +843,13 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'v': /* display the openjpeg library version in use */
fprintf(stdout,"This is the opj_compress utility from the OpenJPEG project.\n"
"It has been compiled against openjp2 library v%s.\n",opj_version());
return 1;
/* ----------------------------------------------------- */
case 'P': /* POC */
{
int numpocs = 0; /* number of progression order change (POC) default 0 */
@ -1412,37 +1420,38 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
default:
fprintf(stderr, "ERROR -> Command line not valid\n");
return 1;
fprintf(stderr, "[WARNING] An invalid option has been ignored\n");
break;
}
}while(c != -1);
if(img_fol->set_imgdir == 1){
if(!(parameters->infile[0] == 0)){
fprintf(stderr, "Error: options -ImgDir and -i cannot be used together !!\n");
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, "[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used !!\n");
fprintf(stderr, "Only one format allowed! Valid formats are j2k and jp2!!\n");
return 1;
}
if(!((parameters->outfile[0] == 0))){
fprintf(stderr, "Error: options -ImgDir and -o cannot be used together !!\n");
fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together !!\n");
fprintf(stderr, "Specify OutputFormat using -OutFor<FORMAT> !!\n");
return 1;
}
}else{
if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) {
fprintf(stderr, "Example: %s -i image.ppm -o image.j2k\n",argv[0]);
fprintf(stderr, " Try: %s -h\n",argv[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;
}
}
if ( (parameters->decod_format == RAW_DFMT && raw_cp->rawWidth == 0)
|| (parameters->decod_format == RAWL_DFMT && raw_cp->rawWidth == 0)) {
fprintf(stderr,"\nError: invalid raw image parameters\n");
fprintf(stderr,"[ERROR] invalid raw image parameters\n");
fprintf(stderr,"Please use the Format option -F:\n");
fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n");
fprintf(stderr,"Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n");
@ -1452,7 +1461,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
if ((parameters->cp_disto_alloc || parameters->cp_fixed_alloc || parameters->cp_fixed_quality)
&& (!(parameters->cp_disto_alloc ^ parameters->cp_fixed_alloc ^ parameters->cp_fixed_quality))) {
fprintf(stderr, "Error: options -r -q and -f cannot be used together !!\n");
fprintf(stderr, "[ERROR] options -r -q and -f cannot be used together !!\n");
return 1;
} /* mod fixed_quality */
@ -1465,7 +1474,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
if((parameters->cp_tx0 > parameters->image_offset_x0) || (parameters->cp_ty0 > parameters->image_offset_y0)) {
fprintf(stderr,
"Error: Tile offset dimension is unnappropriate --> TX0(%d)<=IMG_X0(%d) TYO(%d)<=IMG_Y0(%d) \n",
"[ERROR] Tile offset dimension is unnappropriate --> TX0(%d)<=IMG_X0(%d) TYO(%d)<=IMG_Y0(%d) \n",
parameters->cp_tx0, parameters->image_offset_x0, parameters->cp_ty0, parameters->image_offset_y0);
return 1;
}
@ -1803,7 +1812,7 @@ int main(int argc, char **argv) {
return 1;
}
fprintf(stderr,"Generated outfile %s\n",parameters.outfile);
fprintf(stdout,"[INFO] Generated outfile %s\n",parameters.outfile);
/* close and free the byte stream */
opj_stream_destroy_v3(l_stream);

View File

@ -332,6 +332,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
opj_option_t long_option[]={
{"ImgDir",REQ_ARG, NULL ,'y'},
{"OutFor",REQ_ARG, NULL ,'O'},
{"version",NO_ARG, NULL ,'v'}
};
const char optlist[] = "i:o:r:l:x:d:t:"
@ -341,7 +342,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
"W:"
#endif /* USE_JPWL */
/* <<UniPG */
"h" ;
"hv" ;
totlen=sizeof(long_option);
img_fol->set_out_format = 0;
do {
@ -367,7 +368,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
return 1;
default:
fprintf(stderr,
"!! Unrecognized format for infile: %s [accept only *.j2k, *.jp2, *.jpc or *.jpt] !!\n\n",
"[ERROR] Unknown input file format: %s \n"
" Known file formats are *.j2k, *.jp2, *.jpc or *.jpt\n",
infile);
return 1;
}
@ -472,10 +474,17 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
decode_help_display();
return 1;
/* ------------------------------------------------------ */
/* ------------------------------------------------------ */
case 'v': /* display the openjpeg library version in use */
fprintf(stdout,"This is the opj_decompress utility from the OpenJPEG project.\n"
"It has been compiled against openjp2 library v%s.\n",opj_version());
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;
@ -589,31 +598,32 @@ 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, opj_optarg);
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");
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, "[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");
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]);
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;
}
}
@ -877,81 +887,81 @@ int main(int argc, char **argv)
switch (parameters.cod_format) {
case PXM_DFMT: /* PNM PGM PPM */
if (imagetopnm(image, parameters.outfile)) {
fprintf(stderr,"Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
case PGX_DFMT: /* PGX */
if(imagetopgx(image, parameters.outfile)){
fprintf(stderr,"Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
case BMP_DFMT: /* BMP */
if(imagetobmp(image, parameters.outfile)){
fprintf(stderr,"Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
#ifdef OPJ_HAVE_LIBTIFF
case TIF_DFMT: /* TIFF */
if(imagetotif(image, parameters.outfile)){
fprintf(stderr,"Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
#endif /* OPJ_HAVE_LIBTIFF */
case RAW_DFMT: /* RAW */
if(imagetoraw(image, parameters.outfile)){
fprintf(stderr,"Error generating raw file. Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"[ERROR] Error generating raw file. Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
case RAWL_DFMT: /* RAWL */
if(imagetorawl(image, parameters.outfile)){
fprintf(stderr,"Error generating rawl file. Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"[ERROR] Error generating rawl file. Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
case TGA_DFMT: /* TGA */
if(imagetotga(image, parameters.outfile)){
fprintf(stderr,"Error generating tga file. Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"[ERROR] Error generating tga file. Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
#ifdef OPJ_HAVE_LIBPNG
case PNG_DFMT: /* PNG */
if(imagetopng(image, parameters.outfile)){
fprintf(stderr,"Error generating png file. Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"[ERROR] Error generating png file. Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
#endif /* OPJ_HAVE_LIBPNG */
@ -959,7 +969,7 @@ int main(int argc, char **argv)
* and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined
*/
default:
fprintf(stderr,"Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile);
failed = 1;
}

View File

@ -298,12 +298,13 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
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;
break;
default:
fprintf(stderr,
"[ERROR] Unknown input file format: %s \n"
" Known file formats are *.j2k, *.jp2, *.jpc or *.jpt\n",
infile);
return 1;
}
strncpy(parameters->infile, infile, sizeof(parameters->infile)-1);
}