remove deprecated v1 style function j2k_read_sot
[openjpeg.git] / tests / j2k_random_tile_access.c
index ab08760af9d1e2a15b8f0e9fa4063049a69b3ebf..5a36d8071ce670b84f004d5d58074983fdbb21ce 100644 (file)
@@ -158,23 +158,22 @@ int main(int argc, char **argv)
        FILE *fsrc = NULL;
 
        opj_dparameters_t parameters;                   /* decompression parameters */
-       opj_event_mgr_t event_mgr;                              /* event manager */
        opj_image_t* image = NULL;
-       opj_stream_t *cio = NULL;                               /* Stream */
-       opj_codec_t* dinfo = NULL;                              /* Handle to a decompressor */
+       opj_stream_t *l_stream = NULL;                          /* Stream */
+       opj_codec_t* l_codec = NULL;                            /* Handle to a decompressor */
        opj_codestream_info_v2_t* cstr_info = NULL;
 
+       /* Index of corner tiles */
+       OPJ_UINT32 tile_ul = 0;
+       OPJ_UINT32 tile_ur = 0;
+       OPJ_UINT32 tile_lr = 0;
+       OPJ_UINT32 tile_ll = 0;
+
        if (argc != 2) {
                fprintf(stderr, "Usage: %s <input_file>\n", argv[0]);
                return EXIT_FAILURE;
        }
 
-       /* Set event mgr */
-       event_mgr.error_handler = error_callback;
-       event_mgr.warning_handler = warning_callback;
-       event_mgr.info_handler = info_callback;
-       opj_initialize_default_event_handler(&event_mgr, 1);
-
        /* Set decoding parameters to default values */
        opj_set_default_decoder_parameters(&parameters);
 
@@ -196,19 +195,19 @@ int main(int argc, char **argv)
                case J2K_CFMT:  /* JPEG-2000 codestream */
                {
                        /* Get a decoder handle */
-                       dinfo = opj_create_decompress_v2(CODEC_J2K);
+                       l_codec = opj_create_decompress(CODEC_J2K);
                        break;
                }
                case JP2_CFMT:  /* JPEG 2000 compressed image data */
                {
                        /* Get a decoder handle */
-                       dinfo = opj_create_decompress_v2(CODEC_JP2);
+                       l_codec = opj_create_decompress(CODEC_JP2);
                        break;
                }
                case JPT_CFMT:  /* JPEG 2000, JPIP */
                {
                        /* Get a decoder handle */
-                       dinfo = opj_create_decompress_v2(CODEC_JPT);
+                       l_codec = opj_create_decompress(CODEC_JPT);
                        break;
                }
                default:
@@ -218,49 +217,54 @@ int main(int argc, char **argv)
                        return EXIT_FAILURE;
        }
 
-       cio = opj_stream_create_default_file_stream(fsrc,1);
-       if (!cio){
+       /* catch events using our callbacks and give a local context */         
+       opj_set_info_handler(l_codec, info_callback,00);
+       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);
+       if (!l_stream){
                fclose(fsrc);
                fprintf(stderr, "ERROR -> failed to create the stream from the file\n");
                return EXIT_FAILURE;
        }
 
        /* Setup the decoder decoding parameters using user parameters */
-       if ( !opj_setup_decoder_v2(dinfo, &parameters, &event_mgr) ){
+       if ( !opj_setup_decoder(l_codec, &parameters) ){
                fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n");
-               opj_stream_destroy(cio);
+               opj_stream_destroy(l_stream);
                fclose(fsrc);
-               opj_destroy_codec(dinfo);
+               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(cio, dinfo, &image)){
+       if(! opj_read_header(l_stream, l_codec, &image)){
                fprintf(stderr, "ERROR -> j2k_to_image: failed to read the header\n");
-               opj_stream_destroy(cio);
+               opj_stream_destroy(l_stream);
                fclose(fsrc);
-               opj_destroy_codec(dinfo);
+               opj_destroy_codec(l_codec);
                opj_image_destroy(image);
                return EXIT_FAILURE;
        }
 
        /* Extract some info from the code stream */
-       cstr_info = opj_get_cstr_info(dinfo);
+       cstr_info = opj_get_cstr_info(l_codec);
 
        fprintf(stdout, "The file contains %dx%d tiles\n", cstr_info->tw, cstr_info->th);
 
-       OPJ_UINT32 tile_ul = 0;
-       OPJ_UINT32 tile_ur = cstr_info->tw - 1;
-       OPJ_UINT32 tile_lr = cstr_info->tw * cstr_info->th - 1;
-       OPJ_UINT32 tile_ll = tile_lr - cstr_info->tw;
+       tile_ul = 0;
+       tile_ur = cstr_info->tw - 1;
+       tile_lr = cstr_info->tw * cstr_info->th - 1;
+       tile_ll = tile_lr - cstr_info->tw;
 
 #define TEST_TILE( tile_index ) \
        fprintf(stdout, "Decoding tile %d ...\n", tile_index); \
-       if(!opj_get_decoded_tile(dinfo, cio, image, tile_index )){ \
+       if(!opj_get_decoded_tile(l_codec, l_stream, image, tile_index )){ \
                fprintf(stderr, "ERROR -> j2k_to_image: failed to decode tile %d\n", tile_index); \
-               opj_stream_destroy(cio); \
-               opj_destroy_cstr_info_v2(cstr_info); \
-               opj_destroy_codec(dinfo); \
+               opj_stream_destroy(l_stream); \
+               opj_destroy_cstr_info(&cstr_info); \
+               opj_destroy_codec(l_codec); \
                opj_image_destroy(image); \
                fclose(fsrc); \
                return EXIT_FAILURE; \
@@ -275,13 +279,13 @@ int main(int argc, char **argv)
        TEST_TILE(tile_lr)
 
        /* Close the byte stream */
-       opj_stream_destroy(cio);
+       opj_stream_destroy(l_stream);
 
        /* Destroy code stream info */
-       opj_destroy_cstr_info_v2(cstr_info);
+       opj_destroy_cstr_info(&cstr_info);
 
        /* Free remaining structures */
-       opj_destroy_codec(dinfo);
+       opj_destroy_codec(l_codec);
 
        /* Free image data structure */
        opj_image_destroy(image);