[trunk] added option to force output bit depth in opj_decompress (fixes issue 283)
[openjpeg.git] / src / bin / jp2 / opj_dump.c
index 6abbec78db01f4ad42801919abb4b18d959d620d..a85cfe9069bc997a3382751837cc00ebe64afea6 100644 (file)
@@ -91,19 +91,14 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
 
 /* -------------------------------------------------------------------------- */
 static void decode_help_display(void) {
-       fprintf(stdout,"HELP for opj_dump\n----\n\n");
-       fprintf(stdout,"- the -h option displays this help information on screen\n\n");
-
-/* UniPG>> */
-       fprintf(stdout,"List of parameters for the JPEG 2000 "
-#ifdef USE_JPWL
-               "+ JPWL "
-#endif /* USE_JPWL */
-               "decoder:\n");
-/* <<UniPG */
-       fprintf(stdout,"\n");
-       fprintf(stdout,"\n");
-       fprintf(stdout,"  -ImgDir \n");
+    fprintf(stdout,"\nThis is the opj_dump utility from the OpenJPEG project.\n"
+            "It dumps JPEG 2000 codestream info to stdout or a given file.\n"
+            "It has been compiled against openjp2 library v%s.\n\n",opj_version());
+
+    fprintf(stdout,"Parameters:\n");
+    fprintf(stdout,"-----------\n");
+    fprintf(stdout,"\n");
+    fprintf(stdout,"  -ImgDir <directory>\n");
        fprintf(stdout,"        Image file Directory path \n");
        fprintf(stdout,"  -i <compressed file>\n");
        fprintf(stdout,"    REQUIRED only if an Input image directory not specified\n");
@@ -113,10 +108,10 @@ static void decode_help_display(void) {
        fprintf(stdout,"    OPTIONAL\n");
        fprintf(stdout,"    Output file where file info will be dump.\n");
        fprintf(stdout,"    By default it will be in the stdout.\n");
-       fprintf(stdout,"  -v "); /* FIXME WIP_MSD */
+    fprintf(stdout,"  -v "); /* FIXME WIP_MSD */
        fprintf(stdout,"    OPTIONAL\n");
-       fprintf(stdout,"    Activate or not the verbose mode (display info and warning message)\n");
-       fprintf(stdout,"    By default verbose mode is off.\n");
+    fprintf(stdout,"    Enable informative messages\n");
+    fprintf(stdout,"    By default verbose mode is off.\n");
        fprintf(stdout,"\n");
 }
 
@@ -277,9 +272,9 @@ static int infile_format(const char *fname)
 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'},
+        {"ImgDir",REQ_ARG, NULL ,'y'}
        };
-       const char optlist[] = "i:o:f:hv";
+    const char optlist[] = "i:o:f:hv";
 
        totlen=sizeof(long_option);
        img_fol->set_out_format = 0;
@@ -298,12 +293,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);
                        }
@@ -340,38 +336,40 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
 
                        /* ----------------------------------------------------- */
 
-                       case 'v':               /* Verbose mode */
+            case 'v':                  /* Verbose mode */
                        {
-                               parameters->m_verbose = 1;
+                parameters->m_verbose = 1;
                        }
                        break;
                        
                                /* ----------------------------------------------------- */
-                       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, "Only one format allowed! Valid format PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA!!\n");
+            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");
+            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, "    Try: %s -h\n",argv[0]);
+            fprintf(stderr, "   Help: %s -h\n",argv[0]);
                        return 1;
                }
        }
@@ -497,7 +495,7 @@ int main(int argc, char *argv[])
                /* Read the input file and put it in memory */
                /* ---------------------------------------- */
 
-               l_stream = opj_stream_create_default_file_stream_v3(parameters.infile,1);
+               l_stream = opj_stream_create_default_file_stream(parameters.infile,1);
                if (!l_stream){
                        fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n",parameters.infile);
                        return EXIT_FAILURE;
@@ -527,7 +525,7 @@ int main(int argc, char *argv[])
                        }
                        default:
                                fprintf(stderr, "skipping file..\n");
-                               opj_stream_destroy_v3(l_stream);
+                               opj_stream_destroy(l_stream);
                                continue;
                }
 
@@ -539,7 +537,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_v3(l_stream);
+                       opj_stream_destroy(l_stream);
                        opj_destroy_codec(l_codec);
                        fclose(fout);
                        return EXIT_FAILURE;
@@ -548,7 +546,7 @@ 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_v3(l_stream);
+                       opj_stream_destroy(l_stream);
                        opj_destroy_codec(l_codec);
                        opj_image_destroy(image);
                        fclose(fout);
@@ -562,7 +560,7 @@ int main(int argc, char *argv[])
                cstr_index = opj_get_cstr_index(l_codec);
 
                /* close the byte stream */
-               opj_stream_destroy_v3(l_stream);
+               opj_stream_destroy(l_stream);
 
                /* free remaining structures */
                if (l_codec) {