opj_jp2_read_header(): move setting icc_profile here instead in opj_jp2_decode()...
[openjpeg.git] / tests / test_tile_decoder.c
index 1dd3382ff84b24c911bcb824b5961f12e95a8984..e5b851e8fde1bdb3ac8afa614b65bf19f469e18d 100644 (file)
@@ -99,7 +99,7 @@ static int infile_format(const char *fname)
                 return -1;
 
         memset(buf, 0, 12);
-        l_nb_read = fread(buf, 1, 12, reader);
+        l_nb_read = (unsigned int)fread(buf, 1, 12, reader);
         fclose(reader);
         if (l_nb_read != 12)
                 return -1;
@@ -136,20 +136,6 @@ static int infile_format(const char *fname)
 
 /* -------------------------------------------------------------------------- */
 
-/**
-  sample error callback expecting a FILE* client object
- */
-static void error_callback_file(const char *msg, void *client_data) {
-        FILE *stream = (FILE*)client_data;
-        fprintf(stream, "[ERROR] %s", msg);
-}
-/**
-  sample warning callback expecting a FILE* client object
- */
-static void warning_callback_file(const char *msg, void *client_data) {
-        FILE *stream = (FILE*)client_data;
-        fprintf(stream, "[WARNING] %s", msg);
-}
 /**
   sample error debug callback expecting no client object
  */
@@ -179,22 +165,20 @@ 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;
         OPJ_UINT32 l_tile_index;
         OPJ_BYTE * l_data = (OPJ_BYTE *) malloc(1000);
         OPJ_BOOL l_go_on = OPJ_TRUE;
-        OPJ_INT32 l_tile_x0=0, l_tile_y0=0 ;
-        OPJ_UINT32 l_tile_width=0, l_tile_height=0, l_nb_tiles_x=0, l_nb_tiles_y=0, l_nb_comps=0 ;
+        OPJ_UINT32 l_nb_comps=0 ;
         OPJ_INT32 l_current_tile_x0,l_current_tile_y0,l_current_tile_x1,l_current_tile_y1;
 
         int da_x0=0;
         int da_y0=0;
         int da_x1=1000;
         int da_y1=1000;
-        char input_file[64];
+        const char *input_file;
 
         /* should be test_tile_decoder 0 0 1000 1000 tte1.j2k */
         if( argc == 6 )
@@ -203,7 +187,7 @@ int main (int argc, char *argv[])
                 da_y0=atoi(argv[2]);
                 da_x1=atoi(argv[3]);
                 da_y1=atoi(argv[4]);
-                strcpy(input_file,argv[5]);
+                input_file = argv[5];
 
         }
         else
@@ -212,24 +196,15 @@ int main (int argc, char *argv[])
                 da_y0=0;
                 da_x1=1000;
                 da_y1=1000;
-                strcpy(input_file,"test.j2k");
+                input_file = "test.j2k";
         }
 
         if (! l_data) {
                 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(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,9 +243,8 @@ 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);
+                                opj_stream_destroy(l_stream);
                                 return EXIT_FAILURE;
                         }
         }
@@ -284,9 +258,8 @@ 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_stream_destroy(l_stream);
                 opj_destroy_codec(l_codec);
                 return EXIT_FAILURE;
         }
@@ -295,18 +268,16 @@ 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_stream_destroy(l_stream);
                 opj_destroy_codec(l_codec);
                 return EXIT_FAILURE;
         }
 
         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_stream_destroy(l_stream);
                 opj_destroy_codec(l_codec);
                 opj_image_destroy(l_image);
                 return EXIT_FAILURE;
@@ -326,9 +297,8 @@ 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_stream_destroy(l_stream);
                         opj_destroy_codec(l_codec);
                         opj_image_destroy(l_image);
                         return EXIT_FAILURE;
@@ -341,9 +311,8 @@ 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_stream_destroy(l_stream);
                                         opj_destroy_codec(l_codec);
                                         opj_image_destroy(l_image);
                                         return EXIT_FAILURE;
@@ -354,9 +323,8 @@ 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_stream_destroy(l_stream);
                                 opj_destroy_codec(l_codec);
                                 opj_image_destroy(l_image);
                                 return EXIT_FAILURE;
@@ -367,18 +335,16 @@ 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_stream_destroy(l_stream);
                 opj_destroy_codec(l_codec);
                 opj_image_destroy(l_image);
                 return EXIT_FAILURE;
         }
 
         /* Free memory */
-        fclose(l_file);
         free(l_data);
-        opj_stream_destroy_v3(l_stream);
+        opj_stream_destroy(l_stream);
         opj_destroy_codec(l_codec);
         opj_image_destroy(l_image);