X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=tests%2Fj2k_random_tile_access.c;h=b76bf35994a184cc7572c5a09f571b6e399e91bf;hb=ff1a30d80a8b9817f00656173a2a883bb47ffaee;hp=123207f98b21c7e0d3aec7e63d6ab1db62ab2ba2;hpb=52f414669a854c7c719b768c2a1792c055ff22c8;p=openjpeg.git diff --git a/tests/j2k_random_tile_access.c b/tests/j2k_random_tile_access.c index 123207f9..b76bf359 100644 --- a/tests/j2k_random_tile_access.c +++ b/tests/j2k_random_tile_access.c @@ -1,11 +1,6 @@ /* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * 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) 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 @@ -48,7 +43,7 @@ #include "format_defs.h" /* -------------------------------------------------------------------------- */ -int get_file_format(const char *filename) { +static int get_file_format(const char *filename) { unsigned int i; static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" }; static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT }; @@ -72,21 +67,21 @@ int get_file_format(const char *filename) { /** sample error callback expecting a FILE* client object */ -void error_callback(const char *msg, void *client_data) { - FILE *stream = (FILE*)client_data; - fprintf(stream, "[ERROR] %s", msg); +static void error_callback(const char *msg, void *client_data) { + (void)client_data; + fprintf(stdout, "[ERROR] %s", msg); } /** sample warning callback expecting a FILE* client object */ -void warning_callback(const char *msg, void *client_data) { - FILE *stream = (FILE*)client_data; - fprintf(stream, "[WARNING] %s", msg); +static void warning_callback(const char *msg, void *client_data) { + (void)client_data; + fprintf(stdout, "[WARNING] %s", msg); } /** sample debug callback expecting no client object */ -void info_callback(const char *msg, void *client_data) { +static void info_callback(const char *msg, void *client_data) { (void)client_data; fprintf(stdout, "[INFO] %s", msg); } @@ -104,7 +99,7 @@ static int infile_format(const char *fname) const char *s, *magic_s; int ext_format, magic_format; unsigned char buf[12]; - unsigned int l_nb_read; + OPJ_SIZE_T l_nb_read; reader = fopen(fname, "rb"); @@ -155,8 +150,7 @@ static int infile_format(const char *fname) /* -------------------------------------------------------------------------- */ int main(int argc, char **argv) { - FILE *fsrc = NULL; - + OPJ_UINT32 index; opj_dparameters_t parameters; /* decompression parameters */ opj_image_t* image = NULL; opj_stream_t *l_stream = NULL; /* Stream */ @@ -179,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 */ /* -------------------------- */ @@ -195,19 +182,19 @@ 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: @@ -222,18 +209,16 @@ 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; } /* 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; } @@ -241,8 +226,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 -> j2k_to_image: 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; @@ -262,13 +246,22 @@ int main(int argc, char **argv) fprintf(stdout, "Decoding tile %d ...\n", 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(l_stream); \ - opj_destroy_cstr_info_v2(&cstr_info); \ + opj_stream_destroy_v3(l_stream); \ + 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) { \ + if( image->comps[index].data == NULL ){ \ + fprintf(stderr, "ERROR -> j2k_to_image: failed to decode tile %d\n", tile_index); \ + opj_stream_destroy_v3(l_stream); \ + opj_destroy_cstr_info(&cstr_info); \ + opj_destroy_codec(l_codec); \ + opj_image_destroy(image); \ + return EXIT_FAILURE; \ + } \ + } \ fprintf(stdout, "Tile %d is decoded successfully\n", tile_index); TEST_TILE(tile_ul) @@ -279,10 +272,10 @@ int main(int argc, char **argv) TEST_TILE(tile_lr) /* Close the byte stream */ - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(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(l_codec); @@ -290,12 +283,9 @@ 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 +/*end main*/