[trunk] move to the new API for function opj_stream_create_default_file_stream. Use...
authorMickael Savinaud <savmickael@users.noreply.github.com>
Sun, 17 Feb 2013 10:34:31 +0000 (10:34 +0000)
committerMickael Savinaud <savmickael@users.noreply.github.com>
Sun, 17 Feb 2013 10:34:31 +0000 (10:34 +0000)
src/bin/jp2/opj_compress.c
src/bin/jp2/opj_decompress.c
src/bin/jp2/opj_dump.c
tests/j2k_random_tile_access.c
tests/test_tile_decoder.c
tests/test_tile_encoder.c
tests/unit/testempty1.c
tests/unit/testempty2.c

index 5101d841d6201efcdf4c1018a1cabfdda9d8ddd3..24217aa3de7af8d4d1a96947697c4ab88dbac98c 100644 (file)
@@ -1588,7 +1588,6 @@ static void info_callback(const char *msg, void *client_data) {
  */
 /* -------------------------------------------------------------------------- */
 int main(int argc, char **argv) {
-       FILE *fout = NULL;
 
        opj_cparameters_t parameters;   /* compression parameters */
 
@@ -1824,16 +1823,8 @@ int main(int argc, char **argv) {
     }
                opj_setup_encoder(l_codec, &parameters, image);
 
-               /* Open the output file*/
-               fout = fopen(parameters.outfile, "wb");
-               if (! fout) {
-                       fprintf(stderr, "Not enable to create output file!\n");
-                       opj_stream_destroy_v3(l_stream);
-                       return 1;
-               }
-
                /* open a byte stream for writing and allocate memory for all tiles */
-               l_stream = opj_stream_create_default_file_stream(fout,OPJ_FALSE);
+               l_stream = opj_stream_create_default_file_stream_v3(parameters.outfile,OPJ_FALSE);
                if (! l_stream){
                        return 1;
                }
@@ -1853,7 +1844,6 @@ int main(int argc, char **argv) {
         if (! opj_write_tile(l_codec,i,l_data,l_data_size,l_stream)) {
           fprintf(stderr, "ERROR -> test_tile_encoder: failed to write the tile %d!\n",i);
           opj_stream_destroy_v3(l_stream);
-          fclose(fout);
           opj_destroy_codec(l_codec);
           opj_image_destroy(image);
           return 1;
@@ -1874,7 +1864,6 @@ int main(int argc, char **argv) {
 
                if (!bSuccess)  {
                        opj_stream_destroy_v3(l_stream);
-                       fclose(fout);
       opj_destroy_codec(l_codec);
       opj_image_destroy(image);
                        fprintf(stderr, "failed to encode image\n");
@@ -1884,7 +1873,6 @@ int main(int argc, char **argv) {
                fprintf(stderr,"Generated outfile %s\n",parameters.outfile);
                /* close and free the byte stream */
                opj_stream_destroy_v3(l_stream);
-               fclose(fout);
 
                /* free remaining compression structures */
                opj_destroy_codec(l_codec);
index e462fb5e472ccc2af875db93398ecbe6a5b1d8dd..9e4f3103aff703b463781397bf075738fd0e13cf 100644 (file)
@@ -676,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;
@@ -746,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;
                }
 
@@ -796,7 +789,6 @@ int main(int argc, char **argv)
                if ( !opj_setup_decoder(l_codec, &parameters) ){
                        fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n");
                        opj_stream_destroy_v3(l_stream);
-                       fclose(fsrc);
                        opj_destroy_codec(l_codec);
                        return EXIT_FAILURE;
                }
@@ -806,7 +798,6 @@ int main(int argc, char **argv)
                if(! opj_read_header(l_stream, l_codec, &image)){
                        fprintf(stderr, "ERROR -> opj_decompress: failed to read the header\n");
                        opj_stream_destroy_v3(l_stream);
-                       fclose(fsrc);
                        opj_destroy_codec(l_codec);
                        opj_image_destroy(image);
                        return EXIT_FAILURE;
@@ -820,7 +811,6 @@ int main(int argc, char **argv)
                                opj_stream_destroy_v3(l_stream);
                                opj_destroy_codec(l_codec);
                                opj_image_destroy(image);
-                               fclose(fsrc);
                                return EXIT_FAILURE;
                        }
 
@@ -830,7 +820,6 @@ int main(int argc, char **argv)
                                opj_destroy_codec(l_codec);
                                opj_stream_destroy_v3(l_stream);
                                opj_image_destroy(image);
-                               fclose(fsrc);
                                return EXIT_FAILURE;
                        }
                }
@@ -842,7 +831,6 @@ int main(int argc, char **argv)
                                opj_destroy_codec(l_codec);
                                opj_stream_destroy_v3(l_stream);
                                opj_image_destroy(image);
-                               fclose(fsrc);
                                return EXIT_FAILURE;
                        }*/
 
@@ -851,7 +839,6 @@ int main(int argc, char **argv)
                                opj_destroy_codec(l_codec);
                                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);
@@ -859,7 +846,6 @@ int main(int argc, char **argv)
 
                /* Close the byte stream */
                opj_stream_destroy_v3(l_stream);
-               fclose(fsrc);
 
                if(image->color_space == OPJ_CLRSPC_SYCC){
                        color_sycc_to_rgb(image); /* FIXME */
index 0fb5d1175a9880560e4baa25e6c8bb83d18bc55a..2391389914485c284d6a762927ba8971bd9c6e0d 100644 (file)
@@ -401,7 +401,7 @@ static void info_callback(const char *msg, void *client_data) {
 /* -------------------------------------------------------------------------- */
 int main(int argc, char *argv[])
 {
-       FILE *fsrc = NULL, *fout = NULL;
+       FILE *fout = NULL;
 
        opj_dparameters_t parameters;                   /* Decompression parameters */
        opj_image_t* image = NULL;                                      /* Image structure */
@@ -486,16 +486,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;
                }
 
@@ -536,7 +530,6 @@ int main(int argc, char *argv[])
                if ( !opj_setup_decoder(l_codec, &parameters) ){
                        fprintf(stderr, "ERROR -> opj_dump: failed to setup the decoder\n");
                        opj_stream_destroy_v3(l_stream);
-                       fclose(fsrc);
                        opj_destroy_codec(l_codec);
                        fclose(fout);
                        return EXIT_FAILURE;
@@ -546,7 +539,6 @@ int main(int argc, char *argv[])
                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);
-                       fclose(fsrc);
                        opj_destroy_codec(l_codec);
                        opj_image_destroy(image);
                        fclose(fout);
@@ -561,7 +553,6 @@ int main(int argc, char *argv[])
 
                /* close the byte stream */
                opj_stream_destroy_v3(l_stream);
-               fclose(fsrc);
 
                /* free remaining structures */
                if (l_codec) {
index 065a955cfacb88ddd5d8a09d2283f473f652fc38..b76bf35994a184cc7572c5a09f571b6e399e91bf 100644 (file)
@@ -150,9 +150,7 @@ static int infile_format(const char *fname)
 /* -------------------------------------------------------------------------- */
 int main(int argc, char **argv)
 {
-       FILE *fsrc = NULL;
-
-  OPJ_UINT32 index;
+    OPJ_UINT32 index;
        opj_dparameters_t parameters;                   /* decompression parameters */
        opj_image_t* image = NULL;
        opj_stream_t *l_stream = NULL;                          /* Stream */
@@ -175,13 +173,6 @@ int main(int argc, char **argv)
 
        strncpy(parameters.infile, argv[1], OPJ_PATH_LEN - 1);
 
-       /* read the input file */
-       /* ------------------- */
-       fsrc = fopen(parameters.infile, "rb");
-       if (!fsrc) {
-               fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile);
-               return EXIT_FAILURE;
-       }
 
        /* decode the JPEG2000 stream */
        /* -------------------------- */
@@ -218,10 +209,9 @@ int main(int argc, char **argv)
        opj_set_warning_handler(l_codec, warning_callback,00);
        opj_set_error_handler(l_codec, error_callback,00);
 
-       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;
        }
 
@@ -229,7 +219,6 @@ int main(int argc, char **argv)
        if ( !opj_setup_decoder(l_codec, &parameters) ){
                fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n");
                opj_stream_destroy_v3(l_stream);
-               fclose(fsrc);
                opj_destroy_codec(l_codec);
                return EXIT_FAILURE;
        }
@@ -238,7 +227,6 @@ int main(int argc, char **argv)
        if(! opj_read_header(l_stream, l_codec, &image)){
                fprintf(stderr, "ERROR -> j2k_to_image: failed to read the header\n");
                opj_stream_destroy_v3(l_stream);
-               fclose(fsrc);
                opj_destroy_codec(l_codec);
                opj_image_destroy(image);
                return EXIT_FAILURE;
@@ -262,7 +250,6 @@ int main(int argc, char **argv)
                opj_destroy_cstr_info(&cstr_info); \
                opj_destroy_codec(l_codec); \
                opj_image_destroy(image); \
-               fclose(fsrc); \
                return EXIT_FAILURE; \
        } \
   for(index = 0; index < image->numcomps; ++index) { \
@@ -272,7 +259,6 @@ int main(int argc, char **argv)
                opj_destroy_cstr_info(&cstr_info); \
                opj_destroy_codec(l_codec); \
                opj_image_destroy(image); \
-               fclose(fsrc); \
         return EXIT_FAILURE; \
         } \
   } \
@@ -297,9 +283,6 @@ int main(int argc, char **argv)
        /* Free image data structure */
        opj_image_destroy(image);
 
-       /* Close the input file */
-       fclose(fsrc);
-
        return EXIT_SUCCESS;
 }
 /*end main*/
index 1dd3382ff84b24c911bcb824b5961f12e95a8984..5a53beea46dee896ee2203bfe69a5b592c0412f7 100644 (file)
@@ -179,7 +179,6 @@ int main (int argc, char *argv[])
         opj_dparameters_t l_param;
         opj_codec_t * l_codec;
         opj_image_t * l_image;
-        FILE * l_file;
         opj_stream_t * l_stream;
         OPJ_UINT32 l_data_size;
         OPJ_UINT32 l_max_data_size = 1000;
@@ -219,17 +218,8 @@ int main (int argc, char *argv[])
                 return EXIT_FAILURE;
         }
 
-        l_file = fopen(input_file,"rb");
-        if (! l_file)
-        {
-                fprintf(stdout, "ERROR while opening input file\n");
-                free(l_data);
-                return EXIT_FAILURE;
-        }
-
-        l_stream = opj_stream_create_default_file_stream(l_file,OPJ_TRUE);
+        l_stream = opj_stream_create_default_file_stream_v3(input_file,OPJ_TRUE);
         if (!l_stream){
-                fclose(l_file);
                 free(l_data);
                 fprintf(stderr, "ERROR -> failed to create the stream from the file\n");
                 return EXIT_FAILURE;
@@ -268,7 +258,6 @@ int main (int argc, char *argv[])
                 default:
                         {    
                                 fprintf(stderr, "ERROR -> Not a valid JPEG2000 file!\n");
-                                fclose(l_file);
                                 free(l_data);
                                 opj_stream_destroy_v3(l_stream);
                                 return EXIT_FAILURE;
@@ -284,7 +273,6 @@ int main (int argc, char *argv[])
         if (! opj_setup_decoder(l_codec, &l_param))
         {
                 fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n");
-                fclose(l_file);
                 free(l_data);
                 opj_stream_destroy_v3(l_stream);
                 opj_destroy_codec(l_codec);
@@ -295,7 +283,6 @@ int main (int argc, char *argv[])
         if (! opj_read_header(l_stream, l_codec, &l_image))
         {
                 fprintf(stderr, "ERROR -> j2k_to_image: failed to read the header\n");
-                fclose(l_file);
                 free(l_data);
                 opj_stream_destroy_v3(l_stream);
                 opj_destroy_codec(l_codec);
@@ -304,7 +291,6 @@ int main (int argc, char *argv[])
 
         if (!opj_set_decode_area(l_codec, l_image, da_x0, da_y0,da_x1, da_y1)){
                 fprintf(stderr,        "ERROR -> j2k_to_image: failed to set the decoded area\n");
-                fclose(l_file);
                 free(l_data);
                 opj_stream_destroy_v3(l_stream);
                 opj_destroy_codec(l_codec);
@@ -326,7 +312,6 @@ int main (int argc, char *argv[])
                                         &l_nb_comps,
                                         &l_go_on))
                 {
-                        fclose(l_file);
                         free(l_data);
                         opj_stream_destroy_v3(l_stream);
                         opj_destroy_codec(l_codec);
@@ -341,7 +326,6 @@ int main (int argc, char *argv[])
                                 OPJ_BYTE *l_new_data = (OPJ_BYTE *) realloc(l_data, l_data_size);
                                 if (! l_new_data)
                                 {
-                                        fclose(l_file);
                                         free(l_new_data);
                                         opj_stream_destroy_v3(l_stream);
                                         opj_destroy_codec(l_codec);
@@ -354,7 +338,6 @@ int main (int argc, char *argv[])
 
                         if (! opj_decode_tile_data(l_codec,l_tile_index,l_data,l_data_size,l_stream))
                         {
-                                fclose(l_file);
                                 free(l_data);
                                 opj_stream_destroy_v3(l_stream);
                                 opj_destroy_codec(l_codec);
@@ -367,7 +350,6 @@ int main (int argc, char *argv[])
 
         if (! opj_end_decompress(l_codec,l_stream))
         {
-                fclose(l_file);
                 free(l_data);
                 opj_stream_destroy_v3(l_stream);
                 opj_destroy_codec(l_codec);
@@ -376,7 +358,6 @@ int main (int argc, char *argv[])
         }
 
         /* Free memory */
-        fclose(l_file);
         free(l_data);
         opj_stream_destroy_v3(l_stream);
         opj_destroy_codec(l_codec);
index 54710369b00d7ab9a857db373fb8d02876e82a72..dbc3f037c1cd948f9ba686bb3fc0574dcc5522dd 100644 (file)
@@ -80,7 +80,6 @@ int main (int argc, char *argv[])
        opj_codec_t * l_codec;
        opj_image_t * l_image;
        opj_image_cmptparm_t l_params [NUM_COMPS_MAX];
-       FILE * l_file;
        opj_stream_t * l_stream;
        OPJ_UINT32 l_nb_tiles;
        OPJ_UINT32 l_data_size;
@@ -278,20 +277,17 @@ int main (int argc, char *argv[])
                return 1;
        }
 
-       l_file = fopen(output_file,"wb");
-       if (! l_file) {
-               fprintf(stderr, "ERROR -> test_tile_encoder: failed to create the output file!\n");
+       l_stream = opj_stream_create_default_file_stream_v3(output_file, OPJ_FALSE);
+    if (! l_stream) {
+               fprintf(stderr, "ERROR -> test_tile_encoder: failed to create the stream from the output file %s !\n",output_file );
                opj_destroy_codec(l_codec);
                opj_image_destroy(l_image);
                return 1;
        }
 
-       l_stream = opj_stream_create_default_file_stream(l_file, OPJ_FALSE);
-
        if (! opj_start_compress(l_codec,l_image,l_stream)) {
                fprintf(stderr, "ERROR -> test_tile_encoder: failed to start compress!\n");
                opj_stream_destroy_v3(l_stream);
-               fclose(l_file);
                opj_destroy_codec(l_codec);
                opj_image_destroy(l_image);
                return 1;
@@ -301,7 +297,6 @@ int main (int argc, char *argv[])
                if (! opj_write_tile(l_codec,i,l_data,l_data_size,l_stream)) {
                        fprintf(stderr, "ERROR -> test_tile_encoder: failed to write the tile %d!\n",i);
                        opj_stream_destroy_v3(l_stream);
-                       fclose(l_file);
                        opj_destroy_codec(l_codec);
                        opj_image_destroy(l_image);
                        return 1;
@@ -311,14 +306,12 @@ int main (int argc, char *argv[])
        if (! opj_end_compress(l_codec,l_stream)) {
                fprintf(stderr, "ERROR -> test_tile_encoder: failed to end compress!\n");
                opj_stream_destroy_v3(l_stream);
-               fclose(l_file);
                opj_destroy_codec(l_codec);
                opj_image_destroy(l_image);
                return 1;
        }
 
        opj_stream_destroy_v3(l_stream);
-       fclose(l_file);
        opj_destroy_codec(l_codec);
        opj_image_destroy(l_image);
 
index 3273648524147a5753f7e9efad90b20dfc898a0e..17d16a17df222bfd4424b5ef741402a9b0ac29d2 100644 (file)
@@ -71,7 +71,6 @@ int main(int argc, char *argv[])
   opj_image_t *image;
   opj_codec_t* l_codec = 00;
   OPJ_BOOL bSuccess;
-  FILE *f;
        opj_stream_t *l_stream = 00;
   (void)argc;
   (void)argv;
@@ -111,11 +110,7 @@ int main(int argc, char *argv[])
 
   opj_setup_encoder(l_codec, &parameters, image);
 
-  strcpy(parameters.outfile, "testempty1.j2k");
-  f = fopen(parameters.outfile, "wb");
-  assert( f );
-
-  l_stream = opj_stream_create_default_file_stream(f,OPJ_FALSE);
+  l_stream = opj_stream_create_default_file_stream_v3("testempty1.j2k",OPJ_FALSE);
   assert(l_stream);
   bSuccess = opj_start_compress(l_codec,image,l_stream);
 
@@ -126,7 +121,6 @@ int main(int argc, char *argv[])
   assert( bSuccess );
 
   opj_stream_destroy_v3(l_stream);
-  fclose(f);
 
   opj_destroy_codec(l_codec);
   opj_image_destroy(image);
index 3b0952b2eb40104eb1cfc40ac06824c9d81a7b4e..8d9bc282b883f032417e298ed1b3c26382cdd663 100644 (file)
@@ -73,7 +73,6 @@ int main(int argc, char *argv[])
   opj_image_t *image;
   opj_codec_t* l_codec = 00;
   OPJ_BOOL bSuccess;
-  FILE *f;
        opj_stream_t *l_stream = 00;
   (void)argc;
   (void)argv;
@@ -113,11 +112,7 @@ int main(int argc, char *argv[])
 
   opj_setup_encoder(l_codec, &parameters, image);
 
-  strcpy(parameters.outfile, outputfile);
-  f = fopen(parameters.outfile, "wb");
-  assert( f );
-
-  l_stream = opj_stream_create_default_file_stream(f,OPJ_FALSE);
+  l_stream = opj_stream_create_default_file_stream_v3(parameters.outfile,OPJ_FALSE);
   assert(l_stream);
   bSuccess = opj_start_compress(l_codec,image,l_stream);
 
@@ -128,7 +123,6 @@ int main(int argc, char *argv[])
   assert( bSuccess );
 
   opj_stream_destroy_v3(l_stream);
-  fclose(f);
 
   opj_destroy_codec(l_codec);
   opj_image_destroy(image);
@@ -136,10 +130,8 @@ int main(int argc, char *argv[])
 
   /* read back the generated file */
 {
-  FILE *fsrc = fopen(outputfile, "rb");
   opj_codec_t* d_codec = 00;
        opj_dparameters_t dparameters;
-  assert( fsrc );
 
   d_codec = opj_create_decompress(OPJ_CODEC_J2K);
   opj_set_info_handler(d_codec, info_callback,00);
@@ -149,7 +141,7 @@ int main(int argc, char *argv[])
   bSuccess = opj_setup_decoder(d_codec, &dparameters);
   assert( bSuccess );
 
-  l_stream = opj_stream_create_default_file_stream(fsrc,1);
+  l_stream = opj_stream_create_default_file_stream_v3(outputfile,1);
   assert( l_stream );
 
   bSuccess = opj_read_header(l_stream, d_codec, &image);
@@ -162,7 +154,7 @@ int main(int argc, char *argv[])
   assert( bSuccess );
 
   opj_stream_destroy_v3(l_stream);
-  fclose(fsrc);
+
   opj_destroy_codec(d_codec);
 
   opj_image_destroy(image);