[trunk] split into two config files config options related to the lib and to the...
[openjpeg.git] / src / bin / jp2 / opj_decompress.c
index ac5e79c34a0cb5b0d886d35c73a89e162cf120ce..3fced21d4b4d9be7db1ed8ca6581fc912f2f58a8 100644 (file)
@@ -6,6 +6,8 @@
  * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
  * Copyright (c) 2005, Herve Drolon, FreeImage Team
  * Copyright (c) 2006-2007, Parvatha Elangovan
+ * Copyright (c) 2008;2011-2012, Centre National d'Etudes Spatiales (CNES), France 
+ * Copyright (c) 2012, CS Systemes d'Information, France
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,7 +31,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
-#include "opj_config.h"
+#include "opj_apps_config.h"
 
 #include <stdio.h>
 #include <string.h>
@@ -674,7 +676,6 @@ static void info_callback(const char *msg, void *client_data) {
 /* -------------------------------------------------------------------------- */
 int main(int argc, char **argv)
 {
-       FILE *fsrc = NULL;
 
        opj_dparameters_t parameters;                   /* decompression parameters */
        opj_image_t* image = NULL;
@@ -744,16 +745,10 @@ int main(int argc, char **argv)
 
                /* read the input file and put it in memory */
                /* ---------------------------------------- */
-               fsrc = fopen(parameters.infile, "rb");
-               if (!fsrc) {
-                       fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile);
-                       return EXIT_FAILURE;
-               }
 
-               l_stream = opj_stream_create_default_file_stream(fsrc,1);
+               l_stream = opj_stream_create_default_file_stream_v3(parameters.infile,1);
                if (!l_stream){
-                       fclose(fsrc);
-                       fprintf(stderr, "ERROR -> failed to create the stream from the file\n");
+                       fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n", parameters.infile);
                        return EXIT_FAILURE;
                }
 
@@ -764,24 +759,24 @@ int main(int argc, char **argv)
                        case J2K_CFMT:  /* JPEG-2000 codestream */
                        {
                                /* Get a decoder handle */
-                               l_codec = opj_create_decompress(CODEC_J2K);
+                               l_codec = opj_create_decompress(OPJ_CODEC_J2K);
                                break;
                        }
                        case JP2_CFMT:  /* JPEG 2000 compressed image data */
                        {
                                /* Get a decoder handle */
-                               l_codec = opj_create_decompress(CODEC_JP2);
+                               l_codec = opj_create_decompress(OPJ_CODEC_JP2);
                                break;
                        }
                        case JPT_CFMT:  /* JPEG 2000, JPIP */
                        {
                                /* Get a decoder handle */
-                               l_codec = opj_create_decompress(CODEC_JPT);
+                               l_codec = opj_create_decompress(OPJ_CODEC_JPT);
                                break;
                        }
                        default:
                                fprintf(stderr, "skipping file..\n");
-                               opj_stream_destroy(l_stream);
+                               opj_stream_destroy_v3(l_stream);
                                continue;
                }
 
@@ -793,8 +788,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 -> j2k_dump: failed to setup the decoder\n");
-                       opj_stream_destroy(l_stream);
-                       fclose(fsrc);
+                       opj_stream_destroy_v3(l_stream);
                        opj_destroy_codec(l_codec);
                        return EXIT_FAILURE;
                }
@@ -803,8 +797,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_decompress: failed to read the header\n");
-                       opj_stream_destroy(l_stream);
-                       fclose(fsrc);
+                       opj_stream_destroy_v3(l_stream);
                        opj_destroy_codec(l_codec);
                        opj_image_destroy(image);
                        return EXIT_FAILURE;
@@ -815,10 +808,9 @@ int main(int argc, char **argv)
                        if (!opj_set_decode_area(l_codec, image, parameters.DA_x0,
                                        parameters.DA_y0, parameters.DA_x1, parameters.DA_y1)){
                                fprintf(stderr, "ERROR -> opj_decompress: failed to set the decoded area\n");
-                               opj_stream_destroy(l_stream);
+                               opj_stream_destroy_v3(l_stream);
                                opj_destroy_codec(l_codec);
                                opj_image_destroy(image);
-                               fclose(fsrc);
                                return EXIT_FAILURE;
                        }
 
@@ -826,9 +818,8 @@ int main(int argc, char **argv)
                        if (!(opj_decode(l_codec, l_stream, image) && opj_end_decompress(l_codec,       l_stream))) {
                                fprintf(stderr,"ERROR -> opj_decompress: failed to decode image!\n");
                                opj_destroy_codec(l_codec);
-                               opj_stream_destroy(l_stream);
+                               opj_stream_destroy_v3(l_stream);
                                opj_image_destroy(image);
-                               fclose(fsrc);
                                return EXIT_FAILURE;
                        }
                }
@@ -838,28 +829,25 @@ int main(int argc, char **argv)
                        /*if (!opj_set_decoded_resolution_factor(l_codec, 5)) {
                                fprintf(stderr, "ERROR -> opj_decompress: failed to set the resolution factor tile!\n");
                                opj_destroy_codec(l_codec);
-                               opj_stream_destroy(l_stream);
+                               opj_stream_destroy_v3(l_stream);
                                opj_image_destroy(image);
-                               fclose(fsrc);
                                return EXIT_FAILURE;
                        }*/
 
                        if (!opj_get_decoded_tile(l_codec, l_stream, image, parameters.tile_index)) {
                                fprintf(stderr, "ERROR -> opj_decompress: failed to decode tile!\n");
                                opj_destroy_codec(l_codec);
-                               opj_stream_destroy(l_stream);
+                               opj_stream_destroy_v3(l_stream);
                                opj_image_destroy(image);
-                               fclose(fsrc);
                                return EXIT_FAILURE;
                        }
                        fprintf(stdout, "tile %d is decoded!\n\n", parameters.tile_index);
                }
 
                /* Close the byte stream */
-               opj_stream_destroy(l_stream);
-               fclose(fsrc);
+               opj_stream_destroy_v3(l_stream);
 
-               if(image->color_space == CLRSPC_SYCC){
+               if(image->color_space == OPJ_CLRSPC_SYCC){
                        color_sycc_to_rgb(image); /* FIXME */
                }
 
@@ -900,7 +888,7 @@ int main(int argc, char **argv)
                                fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
                        }
                        break;
-#ifdef HAVE_LIBTIFF
+#ifdef OPJ_HAVE_LIBTIFF
                case TIF_DFMT:                  /* TIFF */
                        if(imagetotif(image, parameters.outfile)){
                                fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
@@ -909,7 +897,7 @@ int main(int argc, char **argv)
                                fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
                        }
                        break;
-#endif /* HAVE_LIBTIFF */
+#endif /* OPJ_HAVE_LIBTIFF */
                case RAW_DFMT:                  /* RAW */
                        if(imagetoraw(image, parameters.outfile)){
                                fprintf(stdout,"Error generating raw file. Outfile %s not generated\n",parameters.outfile);
@@ -936,7 +924,7 @@ int main(int argc, char **argv)
                                fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
                        }
                        break;
-#ifdef HAVE_LIBPNG
+#ifdef OPJ_HAVE_LIBPNG
                case PNG_DFMT:                  /* PNG */
                        if(imagetopng(image, parameters.outfile)){
                                fprintf(stdout,"Error generating png file. Outfile %s not generated\n",parameters.outfile);
@@ -945,9 +933,9 @@ int main(int argc, char **argv)
                                fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
                        }
                        break;
-#endif /* HAVE_LIBPNG */
+#endif /* OPJ_HAVE_LIBPNG */
 /* Can happen if output file is TIFF or PNG
- * and HAVE_LIBTIF or HAVE_LIBPNG is undefined
+ * and HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined
 */
                        default:
                                fprintf(stderr,"Outfile %s not generated\n",parameters.outfile);