* 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
* 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>
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv)
{
- FILE *fsrc = NULL;
opj_dparameters_t parameters; /* decompression parameters */
opj_image_t* image = NULL;
/* 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;
}
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;
}
/* Setup the decoder decoding parameters using user parameters */
if ( !opj_setup_decoder(l_codec, ¶meters) ){
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;
}
/* 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;
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;
}
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;
}
}
/*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 */
}
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);
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);
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);
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);