diff options
| author | Antonin Descampe <antonin@gmail.com> | 2016-01-25 23:22:06 +0100 |
|---|---|---|
| committer | Antonin Descampe <antonin@gmail.com> | 2016-01-25 23:22:06 +0100 |
| commit | 0febbff19e05cb1a6c2613eee76ad46a669c96cd (patch) | |
| tree | b6442d01348e2ba6404d0fd6abcc4eb6d6cc1390 /tests | |
| parent | bede1568b197021bb576b935422af6c1d0a79e21 (diff) | |
processed all c/h files through astyle with opj_astyle.cfgcodingstyle
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/compare_dump_files.c | 217 | ||||
| -rw-r--r-- | tests/compare_images.c | 1409 | ||||
| -rw-r--r-- | tests/compare_raw_files.c | 236 | ||||
| -rw-r--r-- | tests/j2k_random_tile_access.c | 325 | ||||
| -rw-r--r-- | tests/pdf2jp2.c | 147 | ||||
| -rw-r--r-- | tests/ppm2rgb3.c | 150 | ||||
| -rw-r--r-- | tests/test_tile_decoder.c | 447 | ||||
| -rw-r--r-- | tests/test_tile_encoder.c | 410 | ||||
| -rw-r--r-- | tests/unit/testempty0.c | 9 | ||||
| -rw-r--r-- | tests/unit/testempty1.c | 168 | ||||
| -rw-r--r-- | tests/unit/testempty2.c | 235 |
11 files changed, 1814 insertions, 1939 deletions
diff --git a/tests/compare_dump_files.c b/tests/compare_dump_files.c index 946c92a5..c14cb716 100644 --- a/tests/compare_dump_files.c +++ b/tests/compare_dump_files.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France + * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -39,75 +39,72 @@ #include "opj_getopt.h" -typedef struct test_cmp_parameters -{ - /** */ - char* base_filename; - /** */ - char* test_filename; +typedef struct test_cmp_parameters { + /** */ + char* base_filename; + /** */ + char* test_filename; } test_cmp_parameters; /******************************************************************************* * Command line help function *******************************************************************************/ -static void compare_dump_files_help_display(void) { - fprintf(stdout,"\nList of parameters for the compare_dump_files function \n"); - fprintf(stdout,"\n"); - fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline dump file \n"); - fprintf(stdout," -t \t REQUIRED \t filename to the test dump file image\n"); - fprintf(stdout,"\n"); +static void compare_dump_files_help_display(void) +{ + fprintf(stdout,"\nList of parameters for the compare_dump_files function \n"); + fprintf(stdout,"\n"); + fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline dump file \n"); + fprintf(stdout," -t \t REQUIRED \t filename to the test dump file image\n"); + fprintf(stdout,"\n"); } /******************************************************************************* * Parse command line *******************************************************************************/ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) { - size_t sizemembasefile, sizememtestfile; - int index; - const char optlist[] = "b:t:"; - int c; - - /* Init parameters */ - param->base_filename = NULL; - param->test_filename = NULL; - - opj_opterr = 0; - - while ((c = opj_getopt(argc, argv, optlist)) != -1) - switch (c) - { - case 'b': - sizemembasefile = strlen(opj_optarg) + 1; - param->base_filename = (char*) malloc(sizemembasefile); - strcpy(param->base_filename, opj_optarg); - /*printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );*/ - break; - case 't': - sizememtestfile = strlen(opj_optarg) + 1; - param->test_filename = (char*) malloc(sizememtestfile); - strcpy(param->test_filename, opj_optarg); - /*printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);*/ - break; - case '?': - if ( (opj_optopt == 'b') || (opj_optopt == 't') ) - fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt); - else - if (isprint(opj_optopt)) fprintf(stderr, "Unknown option `-%c'.\n", opj_optopt); - else fprintf(stderr, "Unknown option character `\\x%x'.\n", opj_optopt); - return 1; - default: - fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, opj_optarg); - break; - } - - if (opj_optind != argc) - { - for (index = opj_optind; index < argc; index++) - fprintf(stderr,"Non-option argument %s\n", argv[index]); - return 1; + size_t sizemembasefile, sizememtestfile; + int index; + const char optlist[] = "b:t:"; + int c; + + /* Init parameters */ + param->base_filename = NULL; + param->test_filename = NULL; + + opj_opterr = 0; + + while ((c = opj_getopt(argc, argv, optlist)) != -1) + switch (c) { + case 'b': + sizemembasefile = strlen(opj_optarg) + 1; + param->base_filename = (char*) malloc(sizemembasefile); + strcpy(param->base_filename, opj_optarg); + /*printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );*/ + break; + case 't': + sizememtestfile = strlen(opj_optarg) + 1; + param->test_filename = (char*) malloc(sizememtestfile); + strcpy(param->test_filename, opj_optarg); + /*printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);*/ + break; + case '?': + if ( (opj_optopt == 'b') || (opj_optopt == 't') ) + fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt); + else if (isprint(opj_optopt)) fprintf(stderr, "Unknown option `-%c'.\n", opj_optopt); + else fprintf(stderr, "Unknown option character `\\x%x'.\n", opj_optopt); + return 1; + default: + fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, opj_optarg); + break; + } + + if (opj_optind != argc) { + for (index = opj_optind; index < argc; index++) + fprintf(stderr,"Non-option argument %s\n", argv[index]); + return 1; } - return 0; + return 0; } /******************************************************************************* @@ -115,70 +112,64 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) *******************************************************************************/ int main(int argc, char **argv) { - test_cmp_parameters inParam; - FILE *fbase=NULL, *ftest=NULL; - int same = 0; - char lbase[256]; - char strbase[256]; - char ltest[256]; - char strtest[256]; - - if( parse_cmdline_cmp(argc, argv, &inParam) == 1 ) - { - compare_dump_files_help_display(); - goto cleanup; + test_cmp_parameters inParam; + FILE *fbase=NULL, *ftest=NULL; + int same = 0; + char lbase[256]; + char strbase[256]; + char ltest[256]; + char strtest[256]; + + if( parse_cmdline_cmp(argc, argv, &inParam) == 1 ) { + compare_dump_files_help_display(); + goto cleanup; } - /* Display Parameters*/ - printf("******Parameters********* \n"); - printf(" base_filename = %s\n" - " test_filename = %s\n", - inParam.base_filename, inParam.test_filename); - printf("************************* \n"); - - /* open base file */ - printf("Try to open: %s for reading ... ", inParam.base_filename); - if((fbase = fopen(inParam.base_filename, "rb"))==NULL) - { - goto cleanup; + /* Display Parameters*/ + printf("******Parameters********* \n"); + printf(" base_filename = %s\n" + " test_filename = %s\n", + inParam.base_filename, inParam.test_filename); + printf("************************* \n"); + + /* open base file */ + printf("Try to open: %s for reading ... ", inParam.base_filename); + if((fbase = fopen(inParam.base_filename, "rb"))==NULL) { + goto cleanup; } - printf("Ok.\n"); + printf("Ok.\n"); - /* open test file */ - printf("Try to open: %s for reading ... ", inParam.test_filename); - if((ftest = fopen(inParam.test_filename, "rb"))==NULL) - { - goto cleanup; + /* open test file */ + printf("Try to open: %s for reading ... ", inParam.test_filename); + if((ftest = fopen(inParam.test_filename, "rb"))==NULL) { + goto cleanup; } - printf("Ok.\n"); - - while (fgets(lbase, sizeof(lbase), fbase) && fgets(ltest,sizeof(ltest),ftest)) - { - int nbase = sscanf(lbase, "%255[^\r\n]", strbase); - int ntest = sscanf(ltest, "%255[^\r\n]", strtest); - assert( nbase != 255 && ntest != 255 ); - if( nbase != 1 || ntest != 1 ) - { - fprintf(stderr, "could not parse line from files\n" ); - goto cleanup; - } - if( strcmp( strbase, strtest ) != 0 ) - { - fprintf(stderr,"<%s> vs. <%s>\n", strbase, strtest); - goto cleanup; - } + printf("Ok.\n"); + + while (fgets(lbase, sizeof(lbase), fbase) && fgets(ltest,sizeof(ltest),ftest)) { + int nbase = sscanf(lbase, "%255[^\r\n]", strbase); + int ntest = sscanf(ltest, "%255[^\r\n]", strtest); + assert( nbase != 255 && ntest != 255 ); + if( nbase != 1 || ntest != 1 ) { + fprintf(stderr, "could not parse line from files\n" ); + goto cleanup; + } + if( strcmp( strbase, strtest ) != 0 ) { + fprintf(stderr,"<%s> vs. <%s>\n", strbase, strtest); + goto cleanup; + } } - same = 1; - printf("\n***** TEST SUCCEED: Files are the same. *****\n"); + same = 1; + printf("\n***** TEST SUCCEED: Files are the same. *****\n"); cleanup: - /*Close File*/ - if(fbase) fclose(fbase); - if(ftest) fclose(ftest); + /*Close File*/ + if(fbase) fclose(fbase); + if(ftest) fclose(ftest); - /* Free memory*/ - free(inParam.base_filename); - free(inParam.test_filename); + /* Free memory*/ + free(inParam.base_filename); + free(inParam.test_filename); - return same ? EXIT_SUCCESS : EXIT_FAILURE; + return same ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/compare_images.c b/tests/compare_images.c index b28d4957..ccd3ab45 100644 --- a/tests/compare_images.c +++ b/tests/compare_images.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France + * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -55,25 +55,23 @@ *******************************************************************************/ static double* parseToleranceValues( char* inArg, const int nbcomp) { - double* outArgs= malloc((size_t)nbcomp * sizeof(double)); - int it_comp = 0; - const char delims[] = ":"; - char *result = strtok( inArg, delims ); - - while( (result != NULL) && (it_comp < nbcomp )) - { - outArgs[it_comp] = atof(result); - result = strtok( NULL, delims ); - it_comp++; + double* outArgs= malloc((size_t)nbcomp * sizeof(double)); + int it_comp = 0; + const char delims[] = ":"; + char *result = strtok( inArg, delims ); + + while( (result != NULL) && (it_comp < nbcomp )) { + outArgs[it_comp] = atof(result); + result = strtok( NULL, delims ); + it_comp++; } - if (it_comp != nbcomp) - { - free(outArgs); - return NULL; + if (it_comp != nbcomp) { + free(outArgs); + return NULL; } - /* else */ - return outArgs; + /* else */ + return outArgs; } /******************************************************************************* @@ -81,28 +79,28 @@ static double* parseToleranceValues( char* inArg, const int nbcomp) *******************************************************************************/ static void compare_images_help_display(void) { - fprintf(stdout,"\nList of parameters for the compare_images function \n"); - fprintf(stdout,"\n"); - fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline PGX/TIF/PNM image \n"); - fprintf(stdout," -t \t REQUIRED \t filename to the test PGX/TIF/PNM image\n"); - fprintf(stdout," -n \t REQUIRED \t number of component of the image (used to generate correct filename, not used when both input files are TIF)\n"); - fprintf(stdout," -m \t OPTIONAL \t list of MSE tolerances, separated by : (size must correspond to the number of component) of \n"); - fprintf(stdout," -p \t OPTIONAL \t list of PEAK tolerances, separated by : (size must correspond to the number of component) \n"); - fprintf(stdout," -s \t OPTIONAL \t 1 or 2 filename separator to take into account PGX/PNM image with different components, " - "please indicate b or t before separator to indicate respectively the separator " - "for ref/base file and for test file. \n"); - fprintf(stdout," -d \t OPTIONAL \t indicate if you want to run this function as conformance test or as non regression test\n"); - fprintf(stdout,"\n"); + fprintf(stdout,"\nList of parameters for the compare_images function \n"); + fprintf(stdout,"\n"); + fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline PGX/TIF/PNM image \n"); + fprintf(stdout," -t \t REQUIRED \t filename to the test PGX/TIF/PNM image\n"); + fprintf(stdout," -n \t REQUIRED \t number of component of the image (used to generate correct filename, not used when both input files are TIF)\n"); + fprintf(stdout," -m \t OPTIONAL \t list of MSE tolerances, separated by : (size must correspond to the number of component) of \n"); + fprintf(stdout," -p \t OPTIONAL \t list of PEAK tolerances, separated by : (size must correspond to the number of component) \n"); + fprintf(stdout," -s \t OPTIONAL \t 1 or 2 filename separator to take into account PGX/PNM image with different components, " + "please indicate b or t before separator to indicate respectively the separator " + "for ref/base file and for test file. \n"); + fprintf(stdout," -d \t OPTIONAL \t indicate if you want to run this function as conformance test or as non regression test\n"); + fprintf(stdout,"\n"); } static int get_decod_format_from_string(const char *filename) { - const int dot = '.'; - char * ext = strrchr(filename, dot); - if( strcmp(ext,".pgx") == 0 ) return PGX_DFMT; - if( strcmp(ext,".tif") == 0 ) return TIF_DFMT; - if( strcmp(ext,".ppm") == 0 ) return PXM_DFMT; - return -1; + const int dot = '.'; + char * ext = strrchr(filename, dot); + if( strcmp(ext,".pgx") == 0 ) return PGX_DFMT; + if( strcmp(ext,".tif") == 0 ) return TIF_DFMT; + if( strcmp(ext,".ppm") == 0 ) return PXM_DFMT; + return -1; } @@ -112,46 +110,40 @@ static int get_decod_format_from_string(const char *filename) *******************************************************************************/ static char* createMultiComponentsFilename(const char* inFilename, const int indexF, const char* separator) { - char s[255]; - char *outFilename, *ptr; - const char token = '.'; - size_t posToken = 0; - int decod_format; - - /*printf("inFilename = %s\n", inFilename);*/ - if ((ptr = strrchr(inFilename, token)) != NULL) - { - posToken = strlen(inFilename) - strlen(ptr); - /*printf("Position of %c character inside inFilename = %d\n", token, posToken);*/ - } - else - { - /*printf("Token %c not found\n", token);*/ - outFilename = (char*)malloc(1); - outFilename[0] = '\0'; - return outFilename; + char s[255]; + char *outFilename, *ptr; + const char token = '.'; + size_t posToken = 0; + int decod_format; + + /*printf("inFilename = %s\n", inFilename);*/ + if ((ptr = strrchr(inFilename, token)) != NULL) { + posToken = strlen(inFilename) - strlen(ptr); + /*printf("Position of %c character inside inFilename = %d\n", token, posToken);*/ + } else { + /*printf("Token %c not found\n", token);*/ + outFilename = (char*)malloc(1); + outFilename[0] = '\0'; + return outFilename; } - outFilename = (char*)malloc((posToken + 7) * sizeof(char)); /*6*/ + outFilename = (char*)malloc((posToken + 7) * sizeof(char)); /*6*/ - strncpy(outFilename, inFilename, posToken); - outFilename[posToken] = '\0'; - strcat(outFilename, separator); - sprintf(s, "%i", indexF); - strcat(outFilename, s); + strncpy(outFilename, inFilename, posToken); + outFilename[posToken] = '\0'; + strcat(outFilename, separator); + sprintf(s, "%i", indexF); + strcat(outFilename, s); - decod_format = get_decod_format_from_string(inFilename); - if( decod_format == PGX_DFMT ) - { - strcat(outFilename, ".pgx"); - } - else if( decod_format == PXM_DFMT ) - { - strcat(outFilename, ".pgm"); + decod_format = get_decod_format_from_string(inFilename); + if( decod_format == PGX_DFMT ) { + strcat(outFilename, ".pgx"); + } else if( decod_format == PXM_DFMT ) { + strcat(outFilename, ".pgm"); } - /*printf("outfilename: %s\n", outFilename);*/ - return outFilename; + /*printf("outfilename: %s\n", outFilename);*/ + return outFilename; } /******************************************************************************* @@ -159,215 +151,204 @@ static char* createMultiComponentsFilename(const char* inFilename, const int ind *******************************************************************************/ static opj_image_t* readImageFromFilePPM(const char* filename, int nbFilenamePGX, const char *separator) { - int it_file; - opj_image_t* image_read = NULL; - opj_image_t* image = NULL; - opj_cparameters_t parameters; - opj_image_cmptparm_t* param_image_read; - int** data; - - /* If separator is empty => nb file to read is equal to one*/ - if ( strlen(separator) == 0 ) - nbFilenamePGX = 1; - - /* set encoding parameters to default values */ - opj_set_default_encoder_parameters(¶meters); - parameters.decod_format = PXM_DFMT; - strcpy(parameters.infile, filename); - - /* Allocate memory*/ - param_image_read = malloc((size_t)nbFilenamePGX * sizeof(opj_image_cmptparm_t)); - data = malloc((size_t)nbFilenamePGX * sizeof(*data)); - - for (it_file = 0; it_file < nbFilenamePGX; it_file++) - { - /* Create the right filename*/ - char *filenameComponentPGX; - if (strlen(separator) == 0) - { - filenameComponentPGX = malloc((strlen(filename) + 1) * sizeof(*filenameComponentPGX)); - strcpy(filenameComponentPGX, filename); - } - else - filenameComponentPGX = createMultiComponentsFilename(filename, it_file, separator); + int it_file; + opj_image_t* image_read = NULL; + opj_image_t* image = NULL; + opj_cparameters_t parameters; + opj_image_cmptparm_t* param_image_read; + int** data; + + /* If separator is empty => nb file to read is equal to one*/ + if ( strlen(separator) == 0 ) + nbFilenamePGX = 1; + + /* set encoding parameters to default values */ + opj_set_default_encoder_parameters(¶meters); + parameters.decod_format = PXM_DFMT; + strcpy(parameters.infile, filename); + + /* Allocate memory*/ + param_image_read = malloc((size_t)nbFilenamePGX * sizeof(opj_image_cmptparm_t)); + data = malloc((size_t)nbFilenamePGX * sizeof(*data)); + + for (it_file = 0; it_file < nbFilenamePGX; it_file++) { + /* Create the right filename*/ + char *filenameComponentPGX; + if (strlen(separator) == 0) { + filenameComponentPGX = malloc((strlen(filename) + 1) * sizeof(*filenameComponentPGX)); + strcpy(filenameComponentPGX, filename); + } else + filenameComponentPGX = createMultiComponentsFilename(filename, it_file, separator); + + /* Read the tif file corresponding to the component */ + image_read = pnmtoimage(filenameComponentPGX, ¶meters); + if (!image_read) { + int it_free_data; + fprintf(stderr, "Unable to load ppm file: %s\n", filenameComponentPGX); + + free(param_image_read); + + for (it_free_data = 0; it_free_data < it_file; it_free_data++) { + free(data[it_free_data]); + } + free(data); - /* Read the tif file corresponding to the component */ - image_read = pnmtoimage(filenameComponentPGX, ¶meters); - if (!image_read) - { - int it_free_data; - fprintf(stderr, "Unable to load ppm file: %s\n", filenameComponentPGX); - - free(param_image_read); - - for (it_free_data = 0; it_free_data < it_file; it_free_data++) { - free(data[it_free_data]); - } - free(data); - - free(filenameComponentPGX); - - return NULL; - } - - /* Set the image_read parameters*/ - param_image_read[it_file].x0 = 0; - param_image_read[it_file].y0 = 0; - param_image_read[it_file].dx = 0; - param_image_read[it_file].dy = 0; - param_image_read[it_file].h = image_read->comps->h; - param_image_read[it_file].w = image_read->comps->w; - param_image_read[it_file].bpp = image_read->comps->bpp; - param_image_read[it_file].prec = image_read->comps->prec; - param_image_read[it_file].sgnd = image_read->comps->sgnd; - - /* Copy data*/ - data[it_file] = malloc(param_image_read[it_file].h * param_image_read[it_file].w * sizeof(int)); - memcpy(data[it_file], image_read->comps->data, image_read->comps->h * image_read->comps->w * sizeof(int)); + free(filenameComponentPGX); - /* Free memory*/ - opj_image_destroy(image_read); - free(filenameComponentPGX); + return NULL; + } + + /* Set the image_read parameters*/ + param_image_read[it_file].x0 = 0; + param_image_read[it_file].y0 = 0; + param_image_read[it_file].dx = 0; + param_image_read[it_file].dy = 0; + param_image_read[it_file].h = image_read->comps->h; + param_image_read[it_file].w = image_read->comps->w; + param_image_read[it_file].bpp = image_read->comps->bpp; + param_image_read[it_file].prec = image_read->comps->prec; + param_image_read[it_file].sgnd = image_read->comps->sgnd; + + /* Copy data*/ + data[it_file] = malloc(param_image_read[it_file].h * param_image_read[it_file].w * sizeof(int)); + memcpy(data[it_file], image_read->comps->data, image_read->comps->h * image_read->comps->w * sizeof(int)); + + /* Free memory*/ + opj_image_destroy(image_read); + free(filenameComponentPGX); } - image = opj_image_create((OPJ_UINT32)nbFilenamePGX, param_image_read, OPJ_CLRSPC_UNSPECIFIED); - for (it_file = 0; it_file < nbFilenamePGX; it_file++) - { - /* Copy data into output image and free memory*/ - memcpy(image->comps[it_file].data, data[it_file], image->comps[it_file].h * image->comps[it_file].w * sizeof(int)); - free(data[it_file]); + image = opj_image_create((OPJ_UINT32)nbFilenamePGX, param_image_read, OPJ_CLRSPC_UNSPECIFIED); + for (it_file = 0; it_file < nbFilenamePGX; it_file++) { + /* Copy data into output image and free memory*/ + memcpy(image->comps[it_file].data, data[it_file], image->comps[it_file].h * image->comps[it_file].w * sizeof(int)); + free(data[it_file]); } - /* Free memory*/ - free(param_image_read); - free(data); + /* Free memory*/ + free(param_image_read); + free(data); - return image; + return image; } static opj_image_t* readImageFromFileTIF(const char* filename, int nbFilenamePGX, const char *separator) { - opj_image_t* image_read = NULL; - opj_cparameters_t parameters; - (void)nbFilenamePGX; - (void)separator; - - /* conformance test suite produce annoying warning/error: - * TIFFReadDirectory: Warning, /.../data/baseline/conformance/jp2_1.tif: unknown field with tag 37724 (0x935c) encountered. - * TIFFOpen: /.../data/baseline/nonregression/opj_jp2_1.tif: Cannot open. - * On Win32 this open a message box by default, so remove it from the test suite: - */ + opj_image_t* image_read = NULL; + opj_cparameters_t parameters; + (void)nbFilenamePGX; + (void)separator; + + /* conformance test suite produce annoying warning/error: + * TIFFReadDirectory: Warning, /.../data/baseline/conformance/jp2_1.tif: unknown field with tag 37724 (0x935c) encountered. + * TIFFOpen: /.../data/baseline/nonregression/opj_jp2_1.tif: Cannot open. + * On Win32 this open a message box by default, so remove it from the test suite: + */ #ifdef OPJ_HAVE_LIBTIFF - TIFFSetWarningHandler(NULL); - TIFFSetErrorHandler(NULL); + TIFFSetWarningHandler(NULL); + TIFFSetErrorHandler(NULL); #endif - if ( strlen(separator) != 0 ) return NULL; + if ( strlen(separator) != 0 ) return NULL; - /* set encoding parameters to default values */ - opj_set_default_encoder_parameters(¶meters); - parameters.decod_format = TIF_DFMT; - strcpy(parameters.infile, filename); + /* set encoding parameters to default values */ + opj_set_default_encoder_parameters(¶meters); + parameters.decod_format = TIF_DFMT; + strcpy(parameters.infile, filename); - /* Read the tif file corresponding to the component */ + /* Read the tif file corresponding to the component */ #ifdef OPJ_HAVE_LIBTIFF - image_read = tiftoimage(filename, ¶meters); + image_read = tiftoimage(filename, ¶meters); #endif - if (!image_read) - { - fprintf(stderr, "Unable to load TIF file\n"); - return NULL; + if (!image_read) { + fprintf(stderr, "Unable to load TIF file\n"); + return NULL; } - return image_read; + return image_read; } static opj_image_t* readImageFromFilePGX(const char* filename, int nbFilenamePGX, const char *separator) { - int it_file; - opj_image_t* image_read = NULL; - opj_image_t* image = NULL; - opj_cparameters_t parameters; - opj_image_cmptparm_t* param_image_read; - int** data; - - /* If separator is empty => nb file to read is equal to one*/ - if ( strlen(separator) == 0 ) - nbFilenamePGX = 1; - - /* set encoding parameters to default values */ - opj_set_default_encoder_parameters(¶meters); - parameters.decod_format = PGX_DFMT; - strcpy(parameters.infile, filename); - - /* Allocate memory*/ - param_image_read = malloc((size_t)nbFilenamePGX * sizeof(opj_image_cmptparm_t)); - data = malloc((size_t)nbFilenamePGX * sizeof(*data)); - - for (it_file = 0; it_file < nbFilenamePGX; it_file++) - { - /* Create the right filename*/ - char *filenameComponentPGX; - if (strlen(separator) == 0) - { - filenameComponentPGX = malloc((strlen(filename) + 1) * sizeof(*filenameComponentPGX)); - strcpy(filenameComponentPGX, filename); - } - else - filenameComponentPGX = createMultiComponentsFilename(filename, it_file, separator); - - /* Read the pgx file corresponding to the component */ - image_read = pgxtoimage(filenameComponentPGX, ¶meters); - if (!image_read) - { - int it_free_data; - fprintf(stderr, "Unable to load pgx file\n"); - - free(param_image_read); - - for (it_free_data = 0; it_free_data < it_file; it_free_data++) { - free(data[it_free_data]); - } - free(data); - - free(filenameComponentPGX); - - return NULL; - } - - /* Set the image_read parameters*/ - param_image_read[it_file].x0 = 0; - param_image_read[it_file].y0 = 0; - param_image_read[it_file].dx = 0; - param_image_read[it_file].dy = 0; - param_image_read[it_file].h = image_read->comps->h; - param_image_read[it_file].w = image_read->comps->w; - param_image_read[it_file].bpp = image_read->comps->bpp; - param_image_read[it_file].prec = image_read->comps->prec; - param_image_read[it_file].sgnd = image_read->comps->sgnd; - - /* Copy data*/ - data[it_file] = malloc(param_image_read[it_file].h * param_image_read[it_file].w * sizeof(int)); - memcpy(data[it_file], image_read->comps->data, image_read->comps->h * image_read->comps->w * sizeof(int)); + int it_file; + opj_image_t* image_read = NULL; + opj_image_t* image = NULL; + opj_cparameters_t parameters; + opj_image_cmptparm_t* param_image_read; + int** data; + + /* If separator is empty => nb file to read is equal to one*/ + if ( strlen(separator) == 0 ) + nbFilenamePGX = 1; + + /* set encoding parameters to default values */ + opj_set_default_encoder_parameters(¶meters); + parameters.decod_format = PGX_DFMT; + strcpy(parameters.infile, filename); + + /* Allocate memory*/ + param_image_read = malloc((size_t)nbFilenamePGX * sizeof(opj_image_cmptparm_t)); + data = malloc((size_t)nbFilenamePGX * sizeof(*data)); + + for (it_file = 0; it_file < nbFilenamePGX; it_file++) { + /* Create the right filename*/ + char *filenameComponentPGX; + if (strlen(separator) == 0) { + filenameComponentPGX = malloc((strlen(filename) + 1) * sizeof(*filenameComponentPGX)); + strcpy(filenameComponentPGX, filename); + } else + filenameComponentPGX = createMultiComponentsFilename(filename, it_file, separator); + + /* Read the pgx file corresponding to the component */ + image_read = pgxtoimage(filenameComponentPGX, ¶meters); + if (!image_read) { + int it_free_data; + fprintf(stderr, "Unable to load pgx file\n"); + + free(param_image_read); + + for (it_free_data = 0; it_free_data < it_file; it_free_data++) { + free(data[it_free_data]); + } + free(data); - /* Free memory*/ - opj_image_destroy(image_read); - free(filenameComponentPGX); + free(filenameComponentPGX); + + return NULL; + } + + /* Set the image_read parameters*/ + param_image_read[it_file].x0 = 0; + param_image_read[it_file].y0 = 0; + param_image_read[it_file].dx = 0; + param_image_read[it_file].dy = 0; + param_image_read[it_file].h = image_read->comps->h; + param_image_read[it_file].w = image_read->comps->w; + param_image_read[it_file].bpp = image_read->comps->bpp; + param_image_read[it_file].prec = image_read->comps->prec; + param_image_read[it_file].sgnd = image_read->comps->sgnd; + + /* Copy data*/ + data[it_file] = malloc(param_image_read[it_file].h * param_image_read[it_file].w * sizeof(int)); + memcpy(data[it_file], image_read->comps->data, image_read->comps->h * image_read->comps->w * sizeof(int)); + + /* Free memory*/ + opj_image_destroy(image_read); + free(filenameComponentPGX); } - image = opj_image_create((OPJ_UINT32)nbFilenamePGX, param_image_read, OPJ_CLRSPC_UNSPECIFIED); - for (it_file = 0; it_file < nbFilenamePGX; it_file++) - { - /* Copy data into output image and free memory*/ - memcpy(image->comps[it_file].data, data[it_file], image->comps[it_file].h * image->comps[it_file].w * sizeof(int)); - free(data[it_file]); + image = opj_image_create((OPJ_UINT32)nbFilenamePGX, param_image_read, OPJ_CLRSPC_UNSPECIFIED); + for (it_file = 0; it_file < nbFilenamePGX; it_file++) { + /* Copy data into output image and free memory*/ + memcpy(image->comps[it_file].data, data[it_file], image->comps[it_file].h * image->comps[it_file].w * sizeof(int)); + free(data[it_file]); } - /* Free memory*/ - free(param_image_read); - free(data); + /* Free memory*/ + free(param_image_read); + free(data); - return image; + return image; } #if defined(OPJ_HAVE_LIBPNG) && 0 /* remove for now */ @@ -376,59 +357,58 @@ static opj_image_t* readImageFromFilePGX(const char* filename, int nbFilenamePGX *******************************************************************************/ static int imageToPNG(const opj_image_t* image, const char* filename, int num_comp_select) { - opj_image_cmptparm_t param_image_write; - opj_image_t* image_write = NULL; + opj_image_cmptparm_t param_image_write; + opj_image_t* image_write = NULL; - param_image_write.x0 = 0; - param_image_write.y0 = 0; - param_image_write.dx = 0; - param_image_write.dy = 0; - param_image_write.h = image->comps[num_comp_select].h; - param_image_write.w = image->comps[num_comp_select].w; - param_image_write.bpp = image->comps[num_comp_select].bpp; - param_image_write.prec = image->comps[num_comp_select].prec; - param_image_write.sgnd = image->comps[num_comp_select].sgnd; + param_image_write.x0 = 0; + param_image_write.y0 = 0; + param_image_write.dx = 0; + param_image_write.dy = 0; + param_image_write.h = image->comps[num_comp_select].h; + param_image_write.w = image->comps[num_comp_select].w; + param_image_write.bpp = image->comps[num_comp_select].bpp; + param_image_write.prec = image->comps[num_comp_select].prec; + param_image_write.sgnd = image->comps[num_comp_select].sgnd; - image_write = opj_image_create(1u, ¶m_image_write, OPJ_CLRSPC_GRAY); - memcpy(image_write->comps->data, image->comps[num_comp_select].data, param_image_write.h * param_image_write.w * sizeof(int)); + image_write = opj_image_create(1u, ¶m_image_write, OPJ_CLRSPC_GRAY); + memcpy(image_write->comps->data, image->comps[num_comp_select].data, param_image_write.h * param_image_write.w * sizeof(int)); - imagetopng(image_write, filename); + imagetopng(image_write, filename); - opj_image_destroy(image_write); + opj_image_destroy(image_write); - return EXIT_SUCCESS; + return EXIT_SUCCESS; } #endif -typedef struct test_cmp_parameters -{ - /** */ - char* base_filename; - /** */ - char* test_filename; - /** Number of components */ - int nbcomp; - /** */ - double* tabMSEvalues; - /** */ - double* tabPEAKvalues; - /** */ - int nr_flag; - /** */ - char separator_base[2]; - /** */ - char separator_test[2]; +typedef struct test_cmp_parameters { + /** */ + char* base_filename; + /** */ + char* test_filename; + /** Number of components */ + int nbcomp; + /** */ + double* tabMSEvalues; + /** */ + double* tabPEAKvalues; + /** */ + int nr_flag; + /** */ + char separator_base[2]; + /** */ + char separator_test[2]; } test_cmp_parameters; /* return decode format PGX / TIF / PPM , return -1 on error */ static int get_decod_format(test_cmp_parameters* param) { - int base_format = get_decod_format_from_string( param->base_filename ); - int test_format = get_decod_format_from_string( param->test_filename ); - if( base_format != test_format ) return -1; - /* handle case -1: */ - return base_format; + int base_format = get_decod_format_from_string( param->base_filename ); + int test_format = get_decod_format_from_string( param->test_filename ); + if( base_format != test_format ) return -1; + /* handle case -1: */ + return base_format; } /******************************************************************************* @@ -436,206 +416,172 @@ static int get_decod_format(test_cmp_parameters* param) *******************************************************************************/ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) { - char *MSElistvalues = NULL; char *PEAKlistvalues= NULL; - char *separatorList = NULL; - size_t sizemembasefile, sizememtestfile; - int index, flagM=0, flagP=0; - const char optlist[] = "b:t:n:m:p:s:d"; - int c; - - /* Init parameters*/ - param->base_filename = NULL; - param->test_filename = NULL; - param->nbcomp = 0; - param->tabMSEvalues = NULL; - param->tabPEAKvalues = NULL; - param->nr_flag = 0; - param->separator_base[0] = 0; - param->separator_test[0] = 0; - - opj_opterr = 0; - - while ((c = opj_getopt(argc, argv, optlist)) != -1) - switch (c) - { - case 'b': - sizemembasefile = strlen(opj_optarg) + 1; - param->base_filename = (char*) malloc(sizemembasefile); - strcpy(param->base_filename, opj_optarg); - /*printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );*/ - break; - case 't': - sizememtestfile = strlen(opj_optarg) + 1; - param->test_filename = (char*) malloc(sizememtestfile); - strcpy(param->test_filename, opj_optarg); - /*printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);*/ - break; - case 'n': - param->nbcomp = atoi(opj_optarg); - break; - case 'm': - MSElistvalues = opj_optarg; - flagM = 1; - break; - case 'p': - PEAKlistvalues = opj_optarg; - flagP = 1; - break; - case 'd': - param->nr_flag = 1; - break; - case 's': - separatorList = opj_optarg; - break; - case '?': - if ((opj_optopt == 'b') || (opj_optopt == 't') || (opj_optopt == 'n') || (opj_optopt == 'p') || (opj_optopt == 'm') || (opj_optopt - == 's')) - fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt); - else - if (isprint(opj_optopt)) fprintf(stderr, "Unknown option `-%c'.\n", opj_optopt); - else fprintf(stderr, "Unknown option character `\\x%x'.\n", opj_optopt); + char *MSElistvalues = NULL; + char *PEAKlistvalues= NULL; + char *separatorList = NULL; + size_t sizemembasefile, sizememtestfile; + int index, flagM=0, flagP=0; + const char optlist[] = "b:t:n:m:p:s:d"; + int c; + + /* Init parameters*/ + param->base_filename = NULL; + param->test_filename = NULL; + param->nbcomp = 0; + param->tabMSEvalues = NULL; + param->tabPEAKvalues = NULL; + param->nr_flag = 0; + param->separator_base[0] = 0; + param->separator_test[0] = 0; + + opj_opterr = 0; + + while ((c = opj_getopt(argc, argv, optlist)) != -1) + switch (c) { + case 'b': + sizemembasefile = strlen(opj_optarg) + 1; + param->base_filename = (char*) malloc(sizemembasefile); + strcpy(param->base_filename, opj_optarg); + /*printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );*/ + break; + case 't': + sizememtestfile = strlen(opj_optarg) + 1; + param->test_filename = (char*) malloc(sizememtestfile); + strcpy(param->test_filename, opj_optarg); + /*printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);*/ + break; + case 'n': + param->nbcomp = atoi(opj_optarg); + break; + case 'm': + MSElistvalues = opj_optarg; + flagM = 1; + break; + case 'p': + PEAKlistvalues = opj_optarg; + flagP = 1; + break; + case 'd': + param->nr_flag = 1; + break; + case 's': + separatorList = opj_optarg; + break; + case '?': + if ((opj_optopt == 'b') || (opj_optopt == 't') || (opj_optopt == 'n') || (opj_optopt == 'p') || (opj_optopt == 'm') || (opj_optopt + == 's')) + fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt); + else if (isprint(opj_optopt)) fprintf(stderr, "Unknown option `-%c'.\n", opj_optopt); + else fprintf(stderr, "Unknown option character `\\x%x'.\n", opj_optopt); + return 1; + default: + fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, opj_optarg); + break; + } + + if (opj_optind != argc) { + for (index = opj_optind; index < argc; index++) + fprintf(stderr,"Non-option argument %s\n", argv[index]); return 1; - default: - fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, opj_optarg); - break; - } - - if (opj_optind != argc) - { - for (index = opj_optind; index < argc; index++) - fprintf(stderr,"Non-option argument %s\n", argv[index]); - return 1; } - if (param->nbcomp == 0) - { - fprintf(stderr,"Need to indicate the number of components !\n"); - return 1; + if (param->nbcomp == 0) { + fprintf(stderr,"Need to indicate the number of components !\n"); + return 1; } - /* else */ - if ( flagM && flagP ) - { - param->tabMSEvalues = parseToleranceValues( MSElistvalues, param->nbcomp); - param->tabPEAKvalues = parseToleranceValues( PEAKlistvalues, param->nbcomp); - if ( (param->tabMSEvalues == NULL) || (param->tabPEAKvalues == NULL)) - { - fprintf(stderr,"MSE and PEAK values are not correct (respectively need %d values)\n",param->nbcomp); - return 1; - } + /* else */ + if ( flagM && flagP ) { + param->tabMSEvalues = parseToleranceValues( MSElistvalues, param->nbcomp); + param->tabPEAKvalues = parseToleranceValues( PEAKlistvalues, param->nbcomp); + if ( (param->tabMSEvalues == NULL) || (param->tabPEAKvalues == NULL)) { + fprintf(stderr,"MSE and PEAK values are not correct (respectively need %d values)\n",param->nbcomp); + return 1; + } } - /* Get separators after corresponding letter (b or t)*/ - if (separatorList != NULL) - { - if( (strlen(separatorList) ==2) || (strlen(separatorList) ==4) ) - { - /* keep original string*/ - size_t sizeseplist = strlen(separatorList)+1; - char* separatorList2 = (char*)malloc( sizeseplist ); - strcpy(separatorList2, separatorList); - /*printf("separatorList2 = %s [%d / %d]\n", separatorList2, strlen(separatorList2), sizeseplist);*/ - - if (strlen(separatorList) == 2) /* one separator behind b or t*/ - { - char *resultT = NULL; - resultT = strtok(separatorList2, "t"); - if (strlen(resultT) == strlen(separatorList)) /* didn't find t character, try to find b*/ - { - char *resultB = NULL; - resultB = strtok(resultT, "b"); - if (strlen(resultB) == 1) - { - param->separator_base[0] = separatorList[1]; - param->separator_base[1] = 0; - param->separator_test[0] = 0; + /* Get separators after corresponding letter (b or t)*/ + if (separatorList != NULL) { + if( (strlen(separatorList) ==2) || (strlen(separatorList) ==4) ) { + /* keep original string*/ + size_t sizeseplist = strlen(separatorList)+1; + char* separatorList2 = (char*)malloc( sizeseplist ); + strcpy(separatorList2, separatorList); + /*printf("separatorList2 = %s [%d / %d]\n", separatorList2, strlen(separatorList2), sizeseplist);*/ + + if (strlen(separatorList) == 2) { /* one separator behind b or t*/ + char *resultT = NULL; + resultT = strtok(separatorList2, "t"); + if (strlen(resultT) == strlen(separatorList)) { /* didn't find t character, try to find b*/ + char *resultB = NULL; + resultB = strtok(resultT, "b"); + if (strlen(resultB) == 1) { + param->separator_base[0] = separatorList[1]; + param->separator_base[1] = 0; + param->separator_test[0] = 0; + } else { /* not found b*/ + free(separatorList2); + return 1; + } + } else { /* found t*/ + param->separator_base[0] = 0; + param->separator_test[0] = separatorList[1]; + param->separator_test[1] = 0; + } + /*printf("sep b = %s [%d] and sep t = %s [%d]\n",param->separator_base, strlen(param->separator_base), param->separator_test, strlen(param->separator_test) );*/ + } else { /* == 4 characters we must found t and b*/ + char *resultT = NULL; + resultT = strtok(separatorList2, "t"); + if (strlen(resultT) == 3) { /* found t in first place*/ + char *resultB = NULL; + resultB = strtok(resultT, "b"); + if (strlen(resultB) == 1) { /* found b after t*/ + param->separator_test[0] = separatorList[1]; + param->separator_test[1] = 0; + param->separator_base[0] = separatorList[3]; + param->separator_base[1] = 0; + } else { /* didn't find b after t*/ + free(separatorList2); + return 1; + } + } else { /* == 2, didn't find t in first place*/ + char *resultB = NULL; + resultB = strtok(resultT, "b"); + if (strlen(resultB) == 1) { /* found b in first place*/ + param->separator_base[0] = separatorList[1]; + param->separator_base[1] = 0; + param->separator_test[0] = separatorList[3]; + param->separator_test[1] = 0; + } else { /* didn't found b in first place => problem*/ + free(separatorList2); + return 1; + } + } } - else /* not found b*/ - { free(separatorList2); + } else { /* wrong number of argument after -s*/ return 1; - } - } - else /* found t*/ - { - param->separator_base[0] = 0; - param->separator_test[0] = separatorList[1]; - param->separator_test[1] = 0; - } - /*printf("sep b = %s [%d] and sep t = %s [%d]\n",param->separator_base, strlen(param->separator_base), param->separator_test, strlen(param->separator_test) );*/ } - else /* == 4 characters we must found t and b*/ - { - char *resultT = NULL; - resultT = strtok(separatorList2, "t"); - if (strlen(resultT) == 3) /* found t in first place*/ - { - char *resultB = NULL; - resultB = strtok(resultT, "b"); - if (strlen(resultB) == 1) /* found b after t*/ - { - param->separator_test[0] = separatorList[1]; - param->separator_test[1] = 0; - param->separator_base[0] = separatorList[3]; - param->separator_base[1] = 0; - } - else /* didn't find b after t*/ - { - free(separatorList2); + } else { + if (param->nbcomp == 1) { + assert( param->separator_base[0] == 0 ); + assert( param->separator_test[0] == 0 ); + } else { + fprintf(stderr,"If number of component is > 1, we need separator\n"); return 1; - } - } - else /* == 2, didn't find t in first place*/ - { - char *resultB = NULL; - resultB = strtok(resultT, "b"); - if (strlen(resultB) == 1) /* found b in first place*/ - { - param->separator_base[0] = separatorList[1]; - param->separator_base[1] = 0; - param->separator_test[0] = separatorList[3]; - param->separator_test[1] = 0; - } - else /* didn't found b in first place => problem*/ - { - free(separatorList2); - return 1; - } - } } - free(separatorList2); - } - else /* wrong number of argument after -s*/ - { - return 1; - } - } - else - { - if (param->nbcomp == 1) - { - assert( param->separator_base[0] == 0 ); - assert( param->separator_test[0] == 0 ); - } - else - { - fprintf(stderr,"If number of component is > 1, we need separator\n"); - return 1; - } } - if ( (param->nr_flag) && (flagP || flagM) ) - { - fprintf(stderr,"Wrong input parameters list: it is non-regression test or tolerance comparison\n"); - return 1; + if ( (param->nr_flag) && (flagP || flagM) ) { + fprintf(stderr,"Wrong input parameters list: it is non-regression test or tolerance comparison\n"); + return 1; } - if ( (!param->nr_flag) && (!flagP || !flagM) ) - { - fprintf(stderr,"Wrong input parameters list: it is non-regression test or tolerance comparison\n"); - return 1; + if ( (!param->nr_flag) && (!flagP || !flagM) ) { + fprintf(stderr,"Wrong input parameters list: it is non-regression test or tolerance comparison\n"); + return 1; } - return 0; + return 0; } /******************************************************************************* @@ -643,308 +589,281 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) *******************************************************************************/ int main(int argc, char **argv) { - test_cmp_parameters inParam; - OPJ_UINT32 it_comp, itpxl; - int failed = 1; - int nbFilenamePGXbase = 0, nbFilenamePGXtest = 0; - char *filenamePNGtest= NULL, *filenamePNGbase = NULL, *filenamePNGdiff = NULL; - size_t memsizebasefilename, memsizetestfilename; - size_t memsizedifffilename; - int valueDiff = 0, nbPixelDiff = 0; - double sumDiff = 0.0; - /* Structures to store image parameters and data*/ - opj_image_t *imageBase = NULL, *imageTest = NULL, *imageDiff = NULL; - opj_image_cmptparm_t* param_image_diff = NULL; - int decod_format; - - /* Get parameters from command line*/ - if( parse_cmdline_cmp(argc, argv, &inParam) ) - { - compare_images_help_display(); - goto cleanup; + test_cmp_parameters inParam; + OPJ_UINT32 it_comp, itpxl; + int failed = 1; + int nbFilenamePGXbase = 0, nbFilenamePGXtest = 0; + char *filenamePNGtest= NULL, *filenamePNGbase = NULL, *filenamePNGdiff = NULL; + size_t memsizebasefilename, memsizetestfilename; + size_t memsizedifffilename; + int valueDiff = 0, nbPixelDiff = 0; + double sumDiff = 0.0; + /* Structures to store image parameters and data*/ + opj_image_t *imageBase = NULL, *imageTest = NULL, *imageDiff = NULL; + opj_image_cmptparm_t* param_image_diff = NULL; + int decod_format; + + /* Get parameters from command line*/ + if( parse_cmdline_cmp(argc, argv, &inParam) ) { + compare_images_help_display(); + goto cleanup; } - /* Display Parameters*/ - printf("******Parameters********* \n"); - printf(" base_filename = %s\n" - " test_filename = %s\n" - " nb of Components = %d\n" - " Non regression test = %d\n" - " separator Base = %s\n" - " separator Test = %s\n", - inParam.base_filename, inParam.test_filename, inParam.nbcomp, - inParam.nr_flag, inParam.separator_base, inParam.separator_test); - - if ( (inParam.tabMSEvalues != NULL) && (inParam.tabPEAKvalues != NULL)) - { - int it_comp2; - printf(" MSE values = ["); - for (it_comp2 = 0; it_comp2 < inParam.nbcomp; it_comp2++) - printf(" %f ", inParam.tabMSEvalues[it_comp2]); - printf("]\n"); - printf(" PEAK values = ["); - for (it_comp2 = 0; it_comp2 < inParam.nbcomp; it_comp2++) - printf(" %f ", inParam.tabPEAKvalues[it_comp2]); - printf("]\n"); - printf(" Non-regression test = %d\n", inParam.nr_flag); + /* Display Parameters*/ + printf("******Parameters********* \n"); + printf(" base_filename = %s\n" + " test_filename = %s\n" + " nb of Components = %d\n" + " Non regression test = %d\n" + " separator Base = %s\n" + " separator Test = %s\n", + inParam.base_filename, inParam.test_filename, inParam.nbcomp, + inParam.nr_flag, inParam.separator_base, inParam.separator_test); + + if ( (inParam.tabMSEvalues != NULL) && (inParam.tabPEAKvalues != NULL)) { + int it_comp2; + printf(" MSE values = ["); + for (it_comp2 = 0; it_comp2 < inParam.nbcomp; it_comp2++) + printf(" %f ", inParam.tabMSEvalues[it_comp2]); + printf("]\n"); + printf(" PEAK values = ["); + for (it_comp2 = 0; it_comp2 < inParam.nbcomp; it_comp2++) + printf(" %f ", inParam.tabPEAKvalues[it_comp2]); + printf("]\n"); + printf(" Non-regression test = %d\n", inParam.nr_flag); } - if (strlen(inParam.separator_base) != 0) - nbFilenamePGXbase = inParam.nbcomp; - - if (strlen(inParam.separator_test) != 0) - nbFilenamePGXtest = inParam.nbcomp; + if (strlen(inParam.separator_base) != 0) + nbFilenamePGXbase = inParam.nbcomp; - printf(" NbFilename to generate from base filename = %d\n", nbFilenamePGXbase); - printf(" NbFilename to generate from test filename = %d\n", nbFilenamePGXtest); - printf("************************* \n"); + if (strlen(inParam.separator_test) != 0) + nbFilenamePGXtest = inParam.nbcomp; - /*----------BASELINE IMAGE--------*/ - memsizebasefilename = strlen(inParam.test_filename) + 1 + 5 + 2 + 4; - memsizetestfilename = strlen(inParam.test_filename) + 1 + 5 + 2 + 4; + printf(" NbFilename to generate from base filename = %d\n", nbFilenamePGXbase); + printf(" NbFilename to generate from test filename = %d\n", nbFilenamePGXtest); + printf("************************* \n"); - decod_format = get_decod_format(&inParam); - if( decod_format == -1 ) - { - fprintf( stderr, "Unhandled file format\n" ); - goto cleanup; - } - assert( decod_format == PGX_DFMT || decod_format == TIF_DFMT || decod_format == PXM_DFMT ); + /*----------BASELINE IMAGE--------*/ + memsizebasefilename = strlen(inParam.test_filename) + 1 + 5 + 2 + 4; + memsizetestfilename = strlen(inParam.test_filename) + 1 + 5 + 2 + 4; - if( decod_format == PGX_DFMT ) - { - imageBase = readImageFromFilePGX( inParam.base_filename, nbFilenamePGXbase, inParam.separator_base); - if ( imageBase == NULL ) - goto cleanup; + decod_format = get_decod_format(&inParam); + if( decod_format == -1 ) { + fprintf( stderr, "Unhandled file format\n" ); + goto cleanup; } - else if( decod_format == TIF_DFMT ) - { - imageBase = readImageFromFileTIF( inParam.base_filename, nbFilenamePGXbase, ""); - if ( imageBase == NULL ) - goto cleanup; + assert( decod_format == PGX_DFMT || decod_format == TIF_DFMT || decod_format == PXM_DFMT ); + + if( decod_format == PGX_DFMT ) { + imageBase = readImageFromFilePGX( inParam.base_filename, nbFilenamePGXbase, inParam.separator_base); + if ( imageBase == NULL ) + goto cleanup; + } else if( decod_format == TIF_DFMT ) { + imageBase = readImageFromFileTIF( inParam.base_filename, nbFilenamePGXbase, ""); + if ( imageBase == NULL ) + goto cleanup; + } else if( decod_format == PXM_DFMT ) { + imageBase = readImageFromFilePPM( inParam.base_filename, nbFilenamePGXbase, inParam.separator_base); + if ( imageBase == NULL ) + goto cleanup; } - else if( decod_format == PXM_DFMT ) - { - imageBase = readImageFromFilePPM( inParam.base_filename, nbFilenamePGXbase, inParam.separator_base); - if ( imageBase == NULL ) - goto cleanup; + + filenamePNGbase = (char*) malloc(memsizebasefilename); + strcpy(filenamePNGbase, inParam.test_filename); + strcat(filenamePNGbase, ".base"); + /*printf("filenamePNGbase = %s [%d / %d octets]\n",filenamePNGbase, strlen(filenamePNGbase),memsizebasefilename );*/ + + /*----------TEST IMAGE--------*/ + + if( decod_format == PGX_DFMT ) { + imageTest = readImageFromFilePGX(inParam.test_filename, nbFilenamePGXtest, inParam.separator_test); + if ( imageTest == NULL ) + goto cleanup; + } else if( decod_format == TIF_DFMT ) { + imageTest = readImageFromFileTIF(inParam.test_filename, nbFilenamePGXtest, ""); + if ( imageTest == NULL ) + goto cleanup; + } else if( decod_format == PXM_DFMT ) { + imageTest = readImageFromFilePPM(inParam.test_filename, nbFilenamePGXtest, inParam.separator_test); + if ( imageTest == NULL ) + goto cleanup; } - filenamePNGbase = (char*) malloc(memsizebasefilename); - strcpy(filenamePNGbase, inParam.test_filename); - strcat(filenamePNGbase, ".base"); - /*printf("filenamePNGbase = %s [%d / %d octets]\n",filenamePNGbase, strlen(filenamePNGbase),memsizebasefilename );*/ + filenamePNGtest = (char*) malloc(memsizetestfilename); + strcpy(filenamePNGtest, inParam.test_filename); + strcat(filenamePNGtest, ".test"); + /*printf("filenamePNGtest = %s [%d / %d octets]\n",filenamePNGtest, strlen(filenamePNGtest),memsizetestfilename );*/ - /*----------TEST IMAGE--------*/ + /*----------DIFF IMAGE--------*/ - if( decod_format == PGX_DFMT ) - { - imageTest = readImageFromFilePGX(inParam.test_filename, nbFilenamePGXtest, inParam.separator_test); - if ( imageTest == NULL ) - goto cleanup; - } - else if( decod_format == TIF_DFMT ) - { - imageTest = readImageFromFileTIF(inParam.test_filename, nbFilenamePGXtest, ""); - if ( imageTest == NULL ) - goto cleanup; - } - else if( decod_format == PXM_DFMT ) - { - imageTest = readImageFromFilePPM(inParam.test_filename, nbFilenamePGXtest, inParam.separator_test); - if ( imageTest == NULL ) - goto cleanup; + /* Allocate memory*/ + param_image_diff = malloc( imageBase->numcomps * sizeof(opj_image_cmptparm_t)); + + /* Comparison of header parameters*/ + printf("Step 1 -> Header comparison\n"); + + /* check dimensions (issue 286)*/ + if(imageBase->numcomps != imageTest->numcomps ) { + printf("ERROR: dim mismatch (%d><%d)\n", imageBase->numcomps, imageTest->numcomps); + goto cleanup; } - filenamePNGtest = (char*) malloc(memsizetestfilename); - strcpy(filenamePNGtest, inParam.test_filename); - strcat(filenamePNGtest, ".test"); - /*printf("filenamePNGtest = %s [%d / %d octets]\n",filenamePNGtest, strlen(filenamePNGtest),memsizetestfilename );*/ + for (it_comp = 0; it_comp < imageBase->numcomps; it_comp++) { + param_image_diff[it_comp].x0 = 0; + param_image_diff[it_comp].y0 = 0; + param_image_diff[it_comp].dx = 0; + param_image_diff[it_comp].dy = 0; + param_image_diff[it_comp].sgnd = 0; + param_image_diff[it_comp].prec = 8; + param_image_diff[it_comp].bpp = 1; + param_image_diff[it_comp].h = imageBase->comps[it_comp].h; + param_image_diff[it_comp].w = imageBase->comps[it_comp].w; + + if (imageBase->comps[it_comp].sgnd != imageTest->comps[it_comp].sgnd) { + printf("ERROR: sign mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).sgnd, ((imageTest->comps)[it_comp]).sgnd); + goto cleanup; + } - /*----------DIFF IMAGE--------*/ + if (((imageBase->comps)[it_comp]).prec != ((imageTest->comps)[it_comp]).prec) { + printf("ERROR: prec mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).prec, ((imageTest->comps)[it_comp]).prec); + goto cleanup; + } - /* Allocate memory*/ - param_image_diff = malloc( imageBase->numcomps * sizeof(opj_image_cmptparm_t)); + if (((imageBase->comps)[it_comp]).bpp != ((imageTest->comps)[it_comp]).bpp) { + printf("ERROR: byte per pixel mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).bpp, ((imageTest->comps)[it_comp]).bpp); + goto cleanup; + } - /* Comparison of header parameters*/ - printf("Step 1 -> Header comparison\n"); + if (((imageBase->comps)[it_comp]).h != ((imageTest->comps)[it_comp]).h) { + printf("ERROR: height mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).h, ((imageTest->comps)[it_comp]).h); + goto cleanup; + } - /* check dimensions (issue 286)*/ - if(imageBase->numcomps != imageTest->numcomps ) - { - printf("ERROR: dim mismatch (%d><%d)\n", imageBase->numcomps, imageTest->numcomps); - goto cleanup; + if (((imageBase->comps)[it_comp]).w != ((imageTest->comps)[it_comp]).w) { + printf("ERROR: width mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).w, ((imageTest->comps)[it_comp]).w); + goto cleanup; + } } - for (it_comp = 0; it_comp < imageBase->numcomps; it_comp++) - { - param_image_diff[it_comp].x0 = 0; - param_image_diff[it_comp].y0 = 0; - param_image_diff[it_comp].dx = 0; - param_image_diff[it_comp].dy = 0; - param_image_diff[it_comp].sgnd = 0; - param_image_diff[it_comp].prec = 8; - param_image_diff[it_comp].bpp = 1; - param_image_diff[it_comp].h = imageBase->comps[it_comp].h; - param_image_diff[it_comp].w = imageBase->comps[it_comp].w; - - if (imageBase->comps[it_comp].sgnd != imageTest->comps[it_comp].sgnd) - { - printf("ERROR: sign mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).sgnd, ((imageTest->comps)[it_comp]).sgnd); - goto cleanup; - } - - if (((imageBase->comps)[it_comp]).prec != ((imageTest->comps)[it_comp]).prec) - { - printf("ERROR: prec mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).prec, ((imageTest->comps)[it_comp]).prec); - goto cleanup; - } - - if (((imageBase->comps)[it_comp]).bpp != ((imageTest->comps)[it_comp]).bpp) - { - printf("ERROR: byte per pixel mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).bpp, ((imageTest->comps)[it_comp]).bpp); - goto cleanup; - } - - if (((imageBase->comps)[it_comp]).h != ((imageTest->comps)[it_comp]).h) - { - printf("ERROR: height mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).h, ((imageTest->comps)[it_comp]).h); - goto cleanup; - } - - if (((imageBase->comps)[it_comp]).w != ((imageTest->comps)[it_comp]).w) - { - printf("ERROR: width mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).w, ((imageTest->comps)[it_comp]).w); - goto cleanup; - } - } + imageDiff = opj_image_create(imageBase->numcomps, param_image_diff, OPJ_CLRSPC_UNSPECIFIED); + /* Free memory*/ + free(param_image_diff); + param_image_diff = NULL; + + /* Measurement computation*/ + printf("Step 2 -> measurement comparison\n"); + + memsizedifffilename = strlen(inParam.test_filename) + 1 + 5 + 2 + 4; + filenamePNGdiff = (char*) malloc(memsizedifffilename); + strcpy(filenamePNGdiff, inParam.test_filename); + strcat(filenamePNGdiff, ".diff"); + /*printf("filenamePNGdiff = %s [%d / %d octets]\n",filenamePNGdiff, strlen(filenamePNGdiff),memsizedifffilename );*/ + + /* Compute pixel diff*/ + for (it_comp = 0; it_comp < imageDiff->numcomps; it_comp++) { + double SE=0,PEAK=0; + double MSE=0; + for (itpxl = 0; itpxl < ((imageDiff->comps)[it_comp]).w * ((imageDiff->comps)[it_comp]).h; itpxl++) { + if (abs( ((imageBase->comps)[it_comp]).data[itpxl] - ((imageTest->comps)[it_comp]).data[itpxl] ) > 0) { + valueDiff = ((imageBase->comps)[it_comp]).data[itpxl] - ((imageTest->comps)[it_comp]).data[itpxl]; + ((imageDiff->comps)[it_comp]).data[itpxl] = abs(valueDiff); + sumDiff += valueDiff; + nbPixelDiff++; + + SE += (double)valueDiff * valueDiff; + PEAK = (PEAK > abs(valueDiff)) ? PEAK : abs(valueDiff); + } else + ((imageDiff->comps)[it_comp]).data[itpxl] = 0; + }/* h*w loop */ + + MSE = SE / ( ((imageDiff->comps)[it_comp]).w * ((imageDiff->comps)[it_comp]).h ); + + if (!inParam.nr_flag && (inParam.tabMSEvalues != NULL) && (inParam.tabPEAKvalues != NULL)) { + /* Conformance test*/ + printf("<DartMeasurement name=\"PEAK_%d\" type=\"numeric/double\"> %f </DartMeasurement> \n", it_comp, PEAK); + printf("<DartMeasurement name=\"MSE_%d\" type=\"numeric/double\"> %f </DartMeasurement> \n", it_comp, MSE); + + if ( (MSE > inParam.tabMSEvalues[it_comp]) || (PEAK > inParam.tabPEAKvalues[it_comp]) ) { + printf("ERROR: MSE (%f) or PEAK (%f) values produced by the decoded file are greater " + "than the allowable error (respectively %f and %f) \n", + MSE, PEAK, inParam.tabMSEvalues[it_comp], inParam.tabPEAKvalues[it_comp]); + goto cleanup; + } + } else { /* Non regression-test */ + if ( nbPixelDiff > 0) { + char it_compc[255]; + it_compc[0] = 0; - imageDiff = opj_image_create(imageBase->numcomps, param_image_diff, OPJ_CLRSPC_UNSPECIFIED); - /* Free memory*/ - free(param_image_diff); param_image_diff = NULL; - - /* Measurement computation*/ - printf("Step 2 -> measurement comparison\n"); - - memsizedifffilename = strlen(inParam.test_filename) + 1 + 5 + 2 + 4; - filenamePNGdiff = (char*) malloc(memsizedifffilename); - strcpy(filenamePNGdiff, inParam.test_filename); - strcat(filenamePNGdiff, ".diff"); - /*printf("filenamePNGdiff = %s [%d / %d octets]\n",filenamePNGdiff, strlen(filenamePNGdiff),memsizedifffilename );*/ - - /* Compute pixel diff*/ - for (it_comp = 0; it_comp < imageDiff->numcomps; it_comp++) - { - double SE=0,PEAK=0; - double MSE=0; - for (itpxl = 0; itpxl < ((imageDiff->comps)[it_comp]).w * ((imageDiff->comps)[it_comp]).h; itpxl++) - { - if (abs( ((imageBase->comps)[it_comp]).data[itpxl] - ((imageTest->comps)[it_comp]).data[itpxl] ) > 0) - { - valueDiff = ((imageBase->comps)[it_comp]).data[itpxl] - ((imageTest->comps)[it_comp]).data[itpxl]; - ((imageDiff->comps)[it_comp]).data[itpxl] = abs(valueDiff); - sumDiff += valueDiff; - nbPixelDiff++; - - SE += (double)valueDiff * valueDiff; - PEAK = (PEAK > abs(valueDiff)) ? PEAK : abs(valueDiff); - } - else - ((imageDiff->comps)[it_comp]).data[itpxl] = 0; - }/* h*w loop */ - - MSE = SE / ( ((imageDiff->comps)[it_comp]).w * ((imageDiff->comps)[it_comp]).h ); - - if (!inParam.nr_flag && (inParam.tabMSEvalues != NULL) && (inParam.tabPEAKvalues != NULL)) - { /* Conformance test*/ - printf("<DartMeasurement name=\"PEAK_%d\" type=\"numeric/double\"> %f </DartMeasurement> \n", it_comp, PEAK); - printf("<DartMeasurement name=\"MSE_%d\" type=\"numeric/double\"> %f </DartMeasurement> \n", it_comp, MSE); - - if ( (MSE > inParam.tabMSEvalues[it_comp]) || (PEAK > inParam.tabPEAKvalues[it_comp]) ) - { - printf("ERROR: MSE (%f) or PEAK (%f) values produced by the decoded file are greater " - "than the allowable error (respectively %f and %f) \n", - MSE, PEAK, inParam.tabMSEvalues[it_comp], inParam.tabPEAKvalues[it_comp]); - goto cleanup; - } - } - else /* Non regression-test */ - { - if ( nbPixelDiff > 0) - { - char it_compc[255]; - it_compc[0] = 0; - - printf("<DartMeasurement name=\"NumberOfPixelsWithDifferences_%d\" type=\"numeric/int\"> %d </DartMeasurement> \n", it_comp, nbPixelDiff); - printf("<DartMeasurement name=\"ComponentError_%d\" type=\"numeric/double\"> %f </DartMeasurement> \n", it_comp, sumDiff); + printf("<DartMeasurement name=\"NumberOfPixelsWithDifferences_%d\" type=\"numeric/int\"> %d </DartMeasurement> \n", it_comp, nbPixelDiff); + printf("<DartMeasurement name=\"ComponentError_%d\" type=\"numeric/double\"> %f </DartMeasurement> \n", it_comp, sumDiff); #ifdef OPJ_HAVE_LIBPNG - { - char *filenamePNGbase_it_comp, *filenamePNGtest_it_comp, *filenamePNGdiff_it_comp; - - filenamePNGbase_it_comp = (char*) malloc(memsizebasefilename); - strcpy(filenamePNGbase_it_comp,filenamePNGbase); - - filenamePNGtest_it_comp = (char*) malloc(memsizetestfilename); - strcpy(filenamePNGtest_it_comp,filenamePNGtest); - - filenamePNGdiff_it_comp = (char*) malloc(memsizedifffilename); - strcpy(filenamePNGdiff_it_comp,filenamePNGdiff); - - sprintf(it_compc, "_%i", it_comp); - strcat(it_compc,".png"); - strcat(filenamePNGbase_it_comp, it_compc); - /*printf("filenamePNGbase_it = %s [%d / %d octets]\n",filenamePNGbase_it_comp, strlen(filenamePNGbase_it_comp),memsizebasefilename );*/ - strcat(filenamePNGtest_it_comp, it_compc); - /*printf("filenamePNGtest_it = %s [%d / %d octets]\n",filenamePNGtest_it_comp, strlen(filenamePNGtest_it_comp),memsizetestfilename );*/ - strcat(filenamePNGdiff_it_comp, it_compc); - /*printf("filenamePNGdiff_it = %s [%d / %d octets]\n",filenamePNGdiff_it_comp, strlen(filenamePNGdiff_it_comp),memsizedifffilename );*/ - - /* - if ( imageToPNG(imageBase, filenamePNGbase_it_comp, it_comp) == EXIT_SUCCESS ) - { - printf("<DartMeasurementFile name=\"BaselineImage_%d\" type=\"image/png\"> %s </DartMeasurementFile> \n", it_comp, filenamePNGbase_it_comp); - } - - if ( imageToPNG(imageTest, filenamePNGtest_it_comp, it_comp) == EXIT_SUCCESS ) - { - printf("<DartMeasurementFile name=\"TestImage_%d\" type=\"image/png\"> %s </DartMeasurementFile> \n", it_comp, filenamePNGtest_it_comp); - } - - if ( imageToPNG(imageDiff, filenamePNGdiff_it_comp, it_comp) == EXIT_SUCCESS ) - { - printf("<DartMeasurementFile name=\"DiffferenceImage_%d\" type=\"image/png\"> %s </DartMeasurementFile> \n", it_comp, filenamePNGdiff_it_comp); - } - */ - - free(filenamePNGbase_it_comp); - free(filenamePNGtest_it_comp); - free(filenamePNGdiff_it_comp); - } + { + char *filenamePNGbase_it_comp, *filenamePNGtest_it_comp, *filenamePNGdiff_it_comp; + + filenamePNGbase_it_comp = (char*) malloc(memsizebasefilename); + strcpy(filenamePNGbase_it_comp,filenamePNGbase); + + filenamePNGtest_it_comp = (char*) malloc(memsizetestfilename); + strcpy(filenamePNGtest_it_comp,filenamePNGtest); + + filenamePNGdiff_it_comp = (char*) malloc(memsizedifffilename); + strcpy(filenamePNGdiff_it_comp,filenamePNGdiff); + + sprintf(it_compc, "_%i", it_comp); + strcat(it_compc,".png"); + strcat(filenamePNGbase_it_comp, it_compc); + /*printf("filenamePNGbase_it = %s [%d / %d octets]\n",filenamePNGbase_it_comp, strlen(filenamePNGbase_it_comp),memsizebasefilename );*/ + strcat(filenamePNGtest_it_comp, it_compc); + /*printf("filenamePNGtest_it = %s [%d / %d octets]\n",filenamePNGtest_it_comp, strlen(filenamePNGtest_it_comp),memsizetestfilename );*/ + strcat(filenamePNGdiff_it_comp, it_compc); + /*printf("filenamePNGdiff_it = %s [%d / %d octets]\n",filenamePNGdiff_it_comp, strlen(filenamePNGdiff_it_comp),memsizedifffilename );*/ + + /* + if ( imageToPNG(imageBase, filenamePNGbase_it_comp, it_comp) == EXIT_SUCCESS ) + { + printf("<DartMeasurementFile name=\"BaselineImage_%d\" type=\"image/png\"> %s </DartMeasurementFile> \n", it_comp, filenamePNGbase_it_comp); + } + + if ( imageToPNG(imageTest, filenamePNGtest_it_comp, it_comp) == EXIT_SUCCESS ) + { + printf("<DartMeasurementFile name=\"TestImage_%d\" type=\"image/png\"> %s </DartMeasurementFile> \n", it_comp, filenamePNGtest_it_comp); + } + + if ( imageToPNG(imageDiff, filenamePNGdiff_it_comp, it_comp) == EXIT_SUCCESS ) + { + printf("<DartMeasurementFile name=\"DiffferenceImage_%d\" type=\"image/png\"> %s </DartMeasurementFile> \n", it_comp, filenamePNGdiff_it_comp); + } + */ + + free(filenamePNGbase_it_comp); + free(filenamePNGtest_it_comp); + free(filenamePNGdiff_it_comp); + } #endif - goto cleanup; - } - } - } /* it_comp loop */ + goto cleanup; + } + } + } /* it_comp loop */ - printf("---- TEST SUCCEED ----\n"); - failed = 0; + printf("---- TEST SUCCEED ----\n"); + failed = 0; cleanup: - /*-----------------------------*/ - free(param_image_diff); - /* Free memory */ - opj_image_destroy(imageBase); - opj_image_destroy(imageTest); - opj_image_destroy(imageDiff); - - free(filenamePNGbase); - free(filenamePNGtest); - free(filenamePNGdiff); - - free(inParam.tabMSEvalues); - free(inParam.tabPEAKvalues); - free(inParam.base_filename); - free(inParam.test_filename); - - return failed ? EXIT_FAILURE : EXIT_SUCCESS; + /*-----------------------------*/ + free(param_image_diff); + /* Free memory */ + opj_image_destroy(imageBase); + opj_image_destroy(imageTest); + opj_image_destroy(imageDiff); + + free(filenamePNGbase); + free(filenamePNGtest); + free(filenamePNGdiff); + + free(inParam.tabMSEvalues); + free(inParam.tabPEAKvalues); + free(inParam.base_filename); + free(inParam.test_filename); + + return failed ? EXIT_FAILURE : EXIT_SUCCESS; } diff --git a/tests/compare_raw_files.c b/tests/compare_raw_files.c index 01b2122d..c87f1f8c 100644 --- a/tests/compare_raw_files.c +++ b/tests/compare_raw_files.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France + * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,23 +40,23 @@ #include "opj_getopt.h" -typedef struct test_cmp_parameters -{ - /** */ - char* base_filename; - /** */ - char* test_filename; +typedef struct test_cmp_parameters { + /** */ + char* base_filename; + /** */ + char* test_filename; } test_cmp_parameters; /******************************************************************************* * Command line help function *******************************************************************************/ -static void compare_raw_files_help_display(void) { - fprintf(stdout,"\nList of parameters for the compare_raw_files function \n"); - fprintf(stdout,"\n"); - fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline RAW image \n"); - fprintf(stdout," -t \t REQUIRED \t filename to the test RAW image\n"); - fprintf(stdout,"\n"); +static void compare_raw_files_help_display(void) +{ + fprintf(stdout,"\nList of parameters for the compare_raw_files function \n"); + fprintf(stdout,"\n"); + fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline RAW image \n"); + fprintf(stdout," -t \t REQUIRED \t filename to the test RAW image\n"); + fprintf(stdout,"\n"); } /******************************************************************************* @@ -64,52 +64,50 @@ static void compare_raw_files_help_display(void) { *******************************************************************************/ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) { - size_t sizemembasefile, sizememtestfile; - int index; - const char optlist[] = "b:t:"; - int c; - - /* Init parameters*/ - param->base_filename = NULL; - param->test_filename = NULL; - - opj_opterr = 0; - while ((c = opj_getopt(argc, argv, optlist)) != -1) - switch (c) - { - case 'b': - sizemembasefile = strlen(opj_optarg)+1; - free(param->base_filename); /* handle dup option */ - param->base_filename = (char*) malloc(sizemembasefile); - strcpy(param->base_filename, opj_optarg); - /*printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );*/ - break; - case 't': - sizememtestfile = strlen(opj_optarg) + 1; - free(param->test_filename); /* handle dup option */ - param->test_filename = (char*) malloc(sizememtestfile); - strcpy(param->test_filename, opj_optarg); - /*printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);*/ - break; - case '?': - if ((opj_optopt == 'b') || (opj_optopt == 't')) - fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt); - else - if (isprint(opj_optopt)) fprintf(stderr, "Unknown option `-%c'.\n", opj_optopt); - else fprintf(stderr, "Unknown option character `\\x%x'.\n", opj_optopt); - return 1; - default: - fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, opj_optarg); - break; - } - - if (opj_optind != argc) { - for (index = opj_optind; index < argc; index++) - fprintf(stderr,"Non-option argument %s\n", argv[index]); - return 1; - } - - return 0; + size_t sizemembasefile, sizememtestfile; + int index; + const char optlist[] = "b:t:"; + int c; + + /* Init parameters*/ + param->base_filename = NULL; + param->test_filename = NULL; + + opj_opterr = 0; + while ((c = opj_getopt(argc, argv, optlist)) != -1) + switch (c) { + case 'b': + sizemembasefile = strlen(opj_optarg)+1; + free(param->base_filename); /* handle dup option */ + param->base_filename = (char*) malloc(sizemembasefile); + strcpy(param->base_filename, opj_optarg); + /*printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );*/ + break; + case 't': + sizememtestfile = strlen(opj_optarg) + 1; + free(param->test_filename); /* handle dup option */ + param->test_filename = (char*) malloc(sizememtestfile); + strcpy(param->test_filename, opj_optarg); + /*printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);*/ + break; + case '?': + if ((opj_optopt == 'b') || (opj_optopt == 't')) + fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt); + else if (isprint(opj_optopt)) fprintf(stderr, "Unknown option `-%c'.\n", opj_optopt); + else fprintf(stderr, "Unknown option character `\\x%x'.\n", opj_optopt); + return 1; + default: + fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, opj_optarg); + break; + } + + if (opj_optind != argc) { + for (index = opj_optind; index < argc; index++) + fprintf(stderr,"Non-option argument %s\n", argv[index]); + return 1; + } + + return 0; } /******************************************************************************* @@ -117,77 +115,73 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) *******************************************************************************/ int main(int argc, char **argv) { - int pos = 0; - test_cmp_parameters inParam; - FILE *file_test=NULL, *file_base=NULL; - unsigned char equal = 0U; /* returns error by default */ - - /* Get parameters from command line*/ - if (parse_cmdline_cmp(argc, argv, &inParam)) - { - compare_raw_files_help_display(); - goto cleanup; - } - - file_test = fopen(inParam.test_filename, "rb"); - if (!file_test) { - fprintf(stderr, "Failed to open %s for reading !!\n", inParam.test_filename); - goto cleanup; - } - - file_base = fopen(inParam.base_filename, "rb"); - if (!file_base) { - fprintf(stderr, "Failed to open %s for reading !!\n", inParam.base_filename); - goto cleanup; - } - - /* Read simultaneously the two files*/ - equal = 1U; - while (equal) - { - unsigned char value_test = 0; - unsigned char eof_test = 0; - unsigned char value_base = 0; - unsigned char eof_base = 0; - - /* Read one byte*/ - if (!fread(&value_test, 1, 1, file_test)) { - eof_test = 1; + int pos = 0; + test_cmp_parameters inParam; + FILE *file_test=NULL, *file_base=NULL; + unsigned char equal = 0U; /* returns error by default */ + + /* Get parameters from command line*/ + if (parse_cmdline_cmp(argc, argv, &inParam)) { + compare_raw_files_help_display(); + goto cleanup; } - /* Read one byte*/ - if (!fread(&value_base, 1, 1, file_base)) { - eof_base = 1; + file_test = fopen(inParam.test_filename, "rb"); + if (!file_test) { + fprintf(stderr, "Failed to open %s for reading !!\n", inParam.test_filename); + goto cleanup; } - /* End of file reached by the two files?*/ - if (eof_test && eof_base) - break; - - /* End of file reached only by one file?*/ - if (eof_test || eof_base) - { - fprintf(stdout,"Files have different sizes.\n"); - equal = 0; + file_base = fopen(inParam.base_filename, "rb"); + if (!file_base) { + fprintf(stderr, "Failed to open %s for reading !!\n", inParam.base_filename); + goto cleanup; } - /* Binary values are equal?*/ - if (value_test != value_base) - { - fprintf(stdout,"Binary values read in the file are different %x vs %x at position %d.\n", value_test, value_base, pos); - equal = 0; + /* Read simultaneously the two files*/ + equal = 1U; + while (equal) { + unsigned char value_test = 0; + unsigned char eof_test = 0; + unsigned char value_base = 0; + unsigned char eof_base = 0; + + /* Read one byte*/ + if (!fread(&value_test, 1, 1, file_test)) { + eof_test = 1; + } + + /* Read one byte*/ + if (!fread(&value_base, 1, 1, file_base)) { + eof_base = 1; + } + + /* End of file reached by the two files?*/ + if (eof_test && eof_base) + break; + + /* End of file reached only by one file?*/ + if (eof_test || eof_base) { + fprintf(stdout,"Files have different sizes.\n"); + equal = 0; + } + + /* Binary values are equal?*/ + if (value_test != value_base) { + fprintf(stdout,"Binary values read in the file are different %x vs %x at position %d.\n", value_test, value_base, pos); + equal = 0; + } + pos++; } - pos++; - } - if(equal) fprintf(stdout,"---- TEST SUCCEED: Files are equal ----\n"); + if(equal) fprintf(stdout,"---- TEST SUCCEED: Files are equal ----\n"); cleanup: - if(file_test) fclose(file_test); - if(file_base) fclose(file_base); + if(file_test) fclose(file_test); + if(file_base) fclose(file_base); - /* Free Memory */ - free(inParam.base_filename); - free(inParam.test_filename); + /* Free Memory */ + free(inParam.base_filename); + free(inParam.test_filename); - return equal ? EXIT_SUCCESS : EXIT_FAILURE; + return equal ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/j2k_random_tile_access.c b/tests/j2k_random_tile_access.c index b53c6005..8fe58cb2 100644 --- a/tests/j2k_random_tile_access.c +++ b/tests/j2k_random_tile_access.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France + * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France * Copyright (c) 2012, CS Systemes d'Information, France * All rights reserved. * @@ -43,23 +43,24 @@ #include "format_defs.h" /* -------------------------------------------------------------------------- */ -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 }; - char * ext = strrchr(filename, '.'); - if (ext == NULL) - return -1; - ext++; - if(ext) { - for(i = 0; i < sizeof(format)/sizeof(*format); i++) { - if(_strnicmp(ext, extension[i], 3) == 0) { - return format[i]; - } - } - } - - return -1; +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 }; + char * ext = strrchr(filename, '.'); + if (ext == NULL) + return -1; + ext++; + if(ext) { + for(i = 0; i < sizeof(format)/sizeof(*format); i++) { + if(_strnicmp(ext, extension[i], 3) == 0) { + return format[i]; + } + } + } + + return -1; } /* -------------------------------------------------------------------------- */ @@ -67,23 +68,26 @@ static int get_file_format(const char *filename) { /** sample error callback expecting a FILE* client object */ -static void error_callback(const char *msg, void *client_data) { - (void)client_data; - fprintf(stdout, "[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 */ -static void warning_callback(const char *msg, void *client_data) { - (void)client_data; - fprintf(stdout, "[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 */ -static void info_callback(const char *msg, void *client_data) { - (void)client_data; - fprintf(stdout, "[INFO] %s", msg); +static void info_callback(const char *msg, void *client_data) +{ + (void)client_data; + fprintf(stdout, "[INFO] %s", msg); } @@ -95,52 +99,50 @@ static void info_callback(const char *msg, void *client_data) { static int infile_format(const char *fname) { - FILE *reader; - const char *s, *magic_s; - int ext_format, magic_format; - unsigned char buf[12]; - OPJ_SIZE_T l_nb_read; + FILE *reader; + const char *s, *magic_s; + int ext_format, magic_format; + unsigned char buf[12]; + OPJ_SIZE_T l_nb_read; - reader = fopen(fname, "rb"); + reader = fopen(fname, "rb"); - if (reader == NULL) - return -1; + if (reader == NULL) + return -1; - memset(buf, 0, 12); - l_nb_read = fread(buf, 1, 12, reader); - fclose(reader); - if (l_nb_read != 12) - return -1; + memset(buf, 0, 12); + l_nb_read = fread(buf, 1, 12, reader); + fclose(reader); + if (l_nb_read != 12) + return -1; - ext_format = get_file_format(fname); + ext_format = get_file_format(fname); - if (ext_format == JPT_CFMT) - return JPT_CFMT; + if (ext_format == JPT_CFMT) + return JPT_CFMT; - if (memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 || memcmp(buf, JP2_MAGIC, 4) == 0) { - magic_format = JP2_CFMT; - magic_s = ".jp2"; - } - else if (memcmp(buf, J2K_CODESTREAM_MAGIC, 4) == 0) { - magic_format = J2K_CFMT; - magic_s = ".j2k or .jpc or .j2c"; - } - else - return -1; + if (memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 || memcmp(buf, JP2_MAGIC, 4) == 0) { + magic_format = JP2_CFMT; + magic_s = ".jp2"; + } else if (memcmp(buf, J2K_CODESTREAM_MAGIC, 4) == 0) { + magic_format = J2K_CFMT; + magic_s = ".j2k or .jpc or .j2c"; + } else + return -1; - if (magic_format == ext_format) - return ext_format; + if (magic_format == ext_format) + return ext_format; - s = fname + strlen(fname) - 4; + s = fname + strlen(fname) - 4; - fputs("\n===========================================\n", stderr); - fprintf(stderr, "The extension of this file is incorrect.\n" - "FOUND %s. SHOULD BE %s\n", s, magic_s); - fputs("===========================================\n", stderr); + fputs("\n===========================================\n", stderr); + fprintf(stderr, "The extension of this file is incorrect.\n" + "FOUND %s. SHOULD BE %s\n", s, magic_s); + fputs("===========================================\n", stderr); - return magic_format; + return magic_format; } /* -------------------------------------------------------------------------- */ @@ -151,96 +153,93 @@ static int infile_format(const char *fname) int main(int argc, char **argv) { OPJ_UINT32 index; - opj_dparameters_t parameters; /* decompression parameters */ - opj_image_t* image = NULL; - 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 decoding parameters to default values */ - opj_set_default_decoder_parameters(¶meters); - - strncpy(parameters.infile, argv[1], OPJ_PATH_LEN - 1); - - - /* decode the JPEG2000 stream */ - /* -------------------------- */ - parameters.decod_format = infile_format(parameters.infile); - - switch(parameters.decod_format) { - case J2K_CFMT: /* JPEG-2000 codestream */ - { - /* Get a decoder handle */ - 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(OPJ_CODEC_JP2); - break; - } - case JPT_CFMT: /* JPEG 2000, JPIP */ - { - /* Get a decoder handle */ - l_codec = opj_create_decompress(OPJ_CODEC_JPT); - break; - } - default: - fprintf(stderr, - "Unrecognized format for input %s [accept only *.j2k, *.jp2, *.jpc or *.jpt]\n\n", - parameters.infile); - return EXIT_FAILURE; - } - - /* 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); + opj_dparameters_t parameters; /* decompression parameters */ + opj_image_t* image = NULL; + 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 decoding parameters to default values */ + opj_set_default_decoder_parameters(¶meters); + + strncpy(parameters.infile, argv[1], OPJ_PATH_LEN - 1); + + + /* decode the JPEG2000 stream */ + /* -------------------------- */ + parameters.decod_format = infile_format(parameters.infile); + + switch(parameters.decod_format) { + case J2K_CFMT: { /* JPEG-2000 codestream */ + /* Get a decoder handle */ + 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(OPJ_CODEC_JP2); + break; + } + case JPT_CFMT: { /* JPEG 2000, JPIP */ + /* Get a decoder handle */ + l_codec = opj_create_decompress(OPJ_CODEC_JPT); + break; + } + default: + fprintf(stderr, + "Unrecognized format for input %s [accept only *.j2k, *.jp2, *.jpc or *.jpt]\n\n", + parameters.infile); + return EXIT_FAILURE; + } + + /* 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(parameters.infile,1); - if (!l_stream){ + if (!l_stream) { 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); - 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 -> j2k_to_image: failed to read the header\n"); - opj_stream_destroy(l_stream); - 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(l_codec); - - fprintf(stdout, "The file contains %dx%d tiles\n", cstr_info->tw, cstr_info->th); - - 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; + 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); + 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 -> j2k_to_image: failed to read the header\n"); + opj_stream_destroy(l_stream); + 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(l_codec); + + fprintf(stdout, "The file contains %dx%d tiles\n", cstr_info->tw, cstr_info->th); + + 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); \ @@ -264,26 +263,26 @@ int main(int argc, char **argv) } \ fprintf(stdout, "Tile %d is decoded successfully\n", tile_index); - TEST_TILE(tile_ul) - TEST_TILE(tile_lr) - TEST_TILE(tile_ul) - TEST_TILE(tile_ll) - TEST_TILE(tile_ur) - TEST_TILE(tile_lr) + TEST_TILE(tile_ul) + TEST_TILE(tile_lr) + TEST_TILE(tile_ul) + TEST_TILE(tile_ll) + TEST_TILE(tile_ur) + TEST_TILE(tile_lr) - /* Close the byte stream */ - opj_stream_destroy(l_stream); + /* Close the byte stream */ + opj_stream_destroy(l_stream); - /* Destroy code stream info */ - opj_destroy_cstr_info(&cstr_info); + /* Destroy code stream info */ + opj_destroy_cstr_info(&cstr_info); - /* Free remaining structures */ - opj_destroy_codec(l_codec); + /* Free remaining structures */ + opj_destroy_codec(l_codec); - /* Free image data structure */ - opj_image_destroy(image); + /* Free image data structure */ + opj_image_destroy(image); - return EXIT_SUCCESS; + return EXIT_SUCCESS; } /*end main*/ diff --git a/tests/pdf2jp2.c b/tests/pdf2jp2.c index 38aa739f..3fa3d9d4 100644 --- a/tests/pdf2jp2.c +++ b/tests/pdf2jp2.c @@ -39,7 +39,7 @@ /* * Add support for other signatures: - * + * * obj<</Subtype/Image/Length 110494/Filter/JPXDecode/BitsPerComponent 8/ColorSpace/DeviceRGB/Width 712/Height 1052>>stream */ #define _GNU_SOURCE @@ -51,92 +51,87 @@ int main(int argc, char *argv[]) { #define NUMJP2 32 - int i, c = 0; - long offets[NUMJP2]; - char buffer[512]; + int i, c = 0; + long offets[NUMJP2]; + char buffer[512]; #define BUFLEN 4096 - int cont = 1; - FILE *f; - size_t nread; - char haystack[BUFLEN]; - const char needle[] = "JPXDecode"; + int cont = 1; + FILE *f; + size_t nread; + char haystack[BUFLEN]; + const char needle[] = "JPXDecode"; - const size_t nlen = strlen( needle ); - const size_t flen = BUFLEN - nlen; - char *fpos = haystack + nlen; - const char *filename; - if( argc < 2 ) return 1; + const size_t nlen = strlen( needle ); + const size_t flen = BUFLEN - nlen; + char *fpos = haystack + nlen; + const char *filename; + if( argc < 2 ) return 1; - filename = argv[1]; + filename = argv[1]; - memset( haystack, 0, nlen ); + memset( haystack, 0, nlen ); - f = fopen( filename, "rb" ); - while( cont ) - { - const char *ret; - size_t hlen; - nread = fread(fpos, 1, flen, f); - hlen = nlen + nread; - ret = memmem( haystack, hlen, needle, nlen); - if( ret ) - { - const long cpos = ftell(f); - const ptrdiff_t diff = ret - haystack; - assert( diff >= 0 ); - /*fprintf( stdout, "Found it: %lx\n", (ptrdiff_t)cpos - (ptrdiff_t)hlen + diff);*/ - offets[c++] = (ptrdiff_t)cpos - (ptrdiff_t)hlen + diff; - } - cont = (nread == flen); - memcpy( haystack, haystack + nread, nlen ); + f = fopen( filename, "rb" ); + while( cont ) { + const char *ret; + size_t hlen; + nread = fread(fpos, 1, flen, f); + hlen = nlen + nread; + ret = memmem( haystack, hlen, needle, nlen); + if( ret ) { + const long cpos = ftell(f); + const ptrdiff_t diff = ret - haystack; + assert( diff >= 0 ); + /*fprintf( stdout, "Found it: %lx\n", (ptrdiff_t)cpos - (ptrdiff_t)hlen + diff);*/ + offets[c++] = (ptrdiff_t)cpos - (ptrdiff_t)hlen + diff; + } + cont = (nread == flen); + memcpy( haystack, haystack + nread, nlen ); } - assert( feof( f ) ); + assert( feof( f ) ); - for( i = 0; i < c; ++i ) - { - int s, len = 0; - char *r; - const int ret = fseek(f, offets[i], SEEK_SET); - assert( ret == 0 ); - r = fgets(buffer, sizeof(buffer), f); - assert( r ); - /*fprintf( stderr, "DEBUG: %s", r );*/ - s = sscanf(r, "JPXDecode]/Length %d/Width %*d/BitsPerComponent %*d/Height %*d", &len); - if( s == 0 ) - { // try again harder - const int ret = fseek(f, offets[i] - 40, SEEK_SET); // 40 is magic number - assert( ret == 0 ); - r = fgets(buffer, sizeof(buffer), f); - assert( r ); - const char needle2[] = "/Length"; - char * s2 = strstr(buffer, needle2); - s = sscanf(s2, "/Length %d/", &len); - } - if( s == 1 ) - { - FILE *jp2; - int j; - char jp2fn[512]; - sprintf( jp2fn, "%s.%d.jp2", filename, i ); - jp2 = fopen( jp2fn, "wb" ); - for( j = 0; j < len; ++j ) - { - int v = fgetc(f); - int ret2 = fputc(v, jp2); - assert( ret2 != EOF ); + for( i = 0; i < c; ++i ) { + int s, len = 0; + char *r; + const int ret = fseek(f, offets[i], SEEK_SET); + assert( ret == 0 ); + r = fgets(buffer, sizeof(buffer), f); + assert( r ); + /*fprintf( stderr, "DEBUG: %s", r );*/ + s = sscanf(r, "JPXDecode]/Length %d/Width %*d/BitsPerComponent %*d/Height %*d", &len); + if( s == 0 ) { + // try again harder + const int ret = fseek(f, offets[i] - 40, SEEK_SET); // 40 is magic number + assert( ret == 0 ); + r = fgets(buffer, sizeof(buffer), f); + assert( r ); + const char needle2[] = "/Length"; + char * s2 = strstr(buffer, needle2); + s = sscanf(s2, "/Length %d/", &len); } - fclose( jp2 ); + if( s == 1 ) { + FILE *jp2; + int j; + char jp2fn[512]; + sprintf( jp2fn, "%s.%d.jp2", filename, i ); + jp2 = fopen( jp2fn, "wb" ); + for( j = 0; j < len; ++j ) { + int v = fgetc(f); + int ret2 = fputc(v, jp2); + assert( ret2 != EOF ); + } + fclose( jp2 ); #if 0 - /* TODO need to check we reached endstream */ - r = fgets(buffer, sizeof(buffer), f); - fprintf( stderr, "DEBUG: [%s]", r ); - r = fgets(buffer, sizeof(buffer), f); - fprintf( stderr, "DEBUG: [%s]", r ); + /* TODO need to check we reached endstream */ + r = fgets(buffer, sizeof(buffer), f); + fprintf( stderr, "DEBUG: [%s]", r ); + r = fgets(buffer, sizeof(buffer), f); + fprintf( stderr, "DEBUG: [%s]", r ); #endif - } + } } - fclose(f); + fclose(f); - return 0; + return 0; } diff --git a/tests/ppm2rgb3.c b/tests/ppm2rgb3.c index 58e7102c..3bbca81a 100644 --- a/tests/ppm2rgb3.c +++ b/tests/ppm2rgb3.c @@ -37,103 +37,99 @@ static const char magic[] = "P6"; static int readheader( FILE *ppm, int *X, int *Y, int *bpp ) { - char buffer[256]; - char strbuffer[256]; - char *line; - int n; - - *X = *Y = *bpp = 0; - - line = fgets(buffer, sizeof(buffer), ppm); - if( !line ) return 0; - n = sscanf(buffer, "%255[^\r\n]", strbuffer); - if( n != 1 ) return 0; - if( strcmp(strbuffer, magic ) != 0 ) return 0; - - /* skip comments */ - while( fgets(buffer, sizeof(buffer), ppm) && *buffer == '#' ) - { + char buffer[256]; + char strbuffer[256]; + char *line; + int n; + + *X = *Y = *bpp = 0; + + line = fgets(buffer, sizeof(buffer), ppm); + if( !line ) return 0; + n = sscanf(buffer, "%255[^\r\n]", strbuffer); + if( n != 1 ) return 0; + if( strcmp(strbuffer, magic ) != 0 ) return 0; + + /* skip comments */ + while( fgets(buffer, sizeof(buffer), ppm) && *buffer == '#' ) { } - n = sscanf(buffer, "%d %d", X,Y); - if( n != 2 ) return 0; - line = fgets(buffer, sizeof(buffer), ppm); - if( !line ) return 0; - n = sscanf(buffer, "%d", bpp); - if( n != 1 ) return 0; - if( *bpp != 255 ) return 0; - - return 1; + n = sscanf(buffer, "%d %d", X,Y); + if( n != 2 ) return 0; + line = fgets(buffer, sizeof(buffer), ppm); + if( !line ) return 0; + n = sscanf(buffer, "%d", bpp); + if( n != 1 ) return 0; + if( *bpp != 255 ) return 0; + + return 1; } static int writeoutput( const char *fn, FILE *ppm, int X, int Y, int bpp ) { - FILE *outf[] = {NULL, NULL, NULL}; - int i, x, y = 0; - char outfn[256]; - static const char *exts[3] = { - "red", - "grn", - "blu" - }; - char *image_line = NULL; - int ok = 0; - - /* write single comp as PGM: P5 */ - for( i = 0; i < 3; ++i ) - { + FILE *outf[] = {NULL, NULL, NULL}; + int i, x, y = 0; + char outfn[256]; + static const char *exts[3] = { + "red", + "grn", + "blu" + }; + char *image_line = NULL; + int ok = 0; + + /* write single comp as PGM: P5 */ + for( i = 0; i < 3; ++i ) { #ifdef _MSC_VER #define snprintf _snprintf /* Visual Studio */ #endif - snprintf( outfn, sizeof(outfn), "%s.%s.pgm", fn, exts[i] ); - outf[i] = fopen( outfn, "wb" ); - if( !outf[i] ) goto cleanup; - /* write header */ - fprintf( outf[i], "P5\n" ); - fprintf( outf[i], "%d %d\n", X, Y ); - fprintf( outf[i], "%d\n", bpp ); + snprintf( outfn, sizeof(outfn), "%s.%s.pgm", fn, exts[i] ); + outf[i] = fopen( outfn, "wb" ); + if( !outf[i] ) goto cleanup; + /* write header */ + fprintf( outf[i], "P5\n" ); + fprintf( outf[i], "%d %d\n", X, Y ); + fprintf( outf[i], "%d\n", bpp ); } - /* write pixel data */ - image_line = (char*)malloc( (size_t)X * 3 * sizeof(char) ); - if( !image_line ) goto cleanup; - while( fread(image_line, sizeof(char), (size_t)X * 3, ppm) == (size_t)X * 3 ) - { - for( x = 0; x < X; ++x ) - for( i = 0; i < 3; ++i ) - if( fputc( image_line[3*x+i], outf[i] ) == EOF ) goto cleanup; - ++y; + /* write pixel data */ + image_line = (char*)malloc( (size_t)X * 3 * sizeof(char) ); + if( !image_line ) goto cleanup; + while( fread(image_line, sizeof(char), (size_t)X * 3, ppm) == (size_t)X * 3 ) { + for( x = 0; x < X; ++x ) + for( i = 0; i < 3; ++i ) + if( fputc( image_line[3*x+i], outf[i] ) == EOF ) goto cleanup; + ++y; } - if( y == Y ) - ok = 1; + if( y == Y ) + ok = 1; cleanup: - free(image_line); - for( i = 0; i < 3; ++i ) - if( outf[i] ) fclose( outf[i] ); + free(image_line); + for( i = 0; i < 3; ++i ) + if( outf[i] ) fclose( outf[i] ); - return ok; + return ok; } int main(int argc, char *argv[]) { - const char *fn; - FILE *ppm = NULL; - int X, Y, bpp; - int ok = 0; - - if( argc < 2 ) - { - fprintf( stderr, "%s input.ppm\n", argv[0] ); - goto cleanup; + const char *fn; + FILE *ppm = NULL; + int X, Y, bpp; + int ok = 0; + + if( argc < 2 ) { + fprintf( stderr, "%s input.ppm\n", argv[0] ); + goto cleanup; } - fn = argv[1]; - ppm = fopen( fn, "rb" ); + fn = argv[1]; + ppm = fopen( fn, "rb" ); - if( !readheader( ppm, &X, &Y, &bpp ) ) goto cleanup; + if( !readheader( ppm, &X, &Y, &bpp ) ) goto cleanup; - if( !writeoutput(fn, ppm, X, Y, bpp ) ) goto cleanup; + if( !writeoutput(fn, ppm, X, Y, bpp ) ) goto cleanup; - ok = 1; + ok = 1; cleanup: - if(ppm) fclose(ppm); - return ok ? EXIT_SUCCESS : EXIT_FAILURE; + if(ppm) fclose(ppm); + return ok ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/test_tile_decoder.c b/tests/test_tile_decoder.c index 26d3a16c..2d50bdda 100644 --- a/tests/test_tile_decoder.c +++ b/tests/test_tile_decoder.c @@ -55,28 +55,29 @@ /* -------------------------------------------------------------------------- */ -/* Declarations */ +/* Declarations */ int get_file_format(const char *filename); static int infile_format(const char *fname); /* -------------------------------------------------------------------------- */ -int get_file_format(const char *filename) { - unsigned int i; - static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "rawl", "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, RAWL_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT }; - char * ext = strrchr(filename, '.'); - if (ext == NULL) - return -1; - ext++; - if(ext) { - for(i = 0; i < sizeof(format)/sizeof(*format); i++) { - if(strcasecmp(ext, extension[i]) == 0) { - return format[i]; - } - } +int get_file_format(const char *filename) +{ + unsigned int i; + static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "rawl", "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, RAWL_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT }; + char * ext = strrchr(filename, '.'); + if (ext == NULL) + return -1; + ext++; + if(ext) { + for(i = 0; i < sizeof(format)/sizeof(*format); i++) { + if(strcasecmp(ext, extension[i]) == 0) { + return format[i]; + } } + } - return -1; + return -1; } /* -------------------------------------------------------------------------- */ @@ -87,50 +88,48 @@ int get_file_format(const char *filename) { static int infile_format(const char *fname) { - FILE *reader; - const char *s, *magic_s; - int ext_format, magic_format; - unsigned char buf[12]; - unsigned int l_nb_read; + FILE *reader; + const char *s, *magic_s; + int ext_format, magic_format; + unsigned char buf[12]; + unsigned int l_nb_read; - reader = fopen(fname, "rb"); + reader = fopen(fname, "rb"); - if (reader == NULL) - return -1; + if (reader == NULL) + return -1; - memset(buf, 0, 12); - l_nb_read = (unsigned int)fread(buf, 1, 12, reader); - fclose(reader); - if (l_nb_read != 12) - return -1; + memset(buf, 0, 12); + l_nb_read = (unsigned int)fread(buf, 1, 12, reader); + fclose(reader); + if (l_nb_read != 12) + return -1; - ext_format = get_file_format(fname); + ext_format = get_file_format(fname); - if (ext_format == JPT_CFMT) - return JPT_CFMT; + if (ext_format == JPT_CFMT) + return JPT_CFMT; - if (memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 || memcmp(buf, JP2_MAGIC, 4) == 0) { - magic_format = JP2_CFMT; - magic_s = ".jp2"; - } - else if (memcmp(buf, J2K_CODESTREAM_MAGIC, 4) == 0) { - magic_format = J2K_CFMT; - magic_s = ".j2k or .jpc or .j2c"; - } - else - return -1; + if (memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 || memcmp(buf, JP2_MAGIC, 4) == 0) { + magic_format = JP2_CFMT; + magic_s = ".jp2"; + } else if (memcmp(buf, J2K_CODESTREAM_MAGIC, 4) == 0) { + magic_format = J2K_CFMT; + magic_s = ".j2k or .jpc or .j2c"; + } else + return -1; - if (magic_format == ext_format) - return ext_format; + if (magic_format == ext_format) + return ext_format; - s = fname + strlen(fname) - 4; + s = fname + strlen(fname) - 4; - fputs("\n===========================================\n", stderr); - fprintf(stderr, "The extension of this file is incorrect.\n" - "FOUND %s. SHOULD BE %s\n", s, magic_s); - fputs("===========================================\n", stderr); + fputs("\n===========================================\n", stderr); + fprintf(stderr, "The extension of this file is incorrect.\n" + "FOUND %s. SHOULD BE %s\n", s, magic_s); + fputs("===========================================\n", stderr); - return magic_format; + return magic_format; } @@ -139,218 +138,206 @@ static int infile_format(const char *fname) /** sample error debug callback expecting no client object */ -static void error_callback(const char *msg, void *client_data) { - (void)client_data; - fprintf(stdout, "[ERROR] %s", msg); +static void error_callback(const char *msg, void *client_data) +{ + (void)client_data; + fprintf(stdout, "[ERROR] %s", msg); } /** sample warning debug callback expecting no client object */ -static void warning_callback(const char *msg, void *client_data) { - (void)client_data; - fprintf(stdout, "[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 */ -static void info_callback(const char *msg, void *client_data) { - (void)client_data; - fprintf(stdout, "[INFO] %s", msg); +static void info_callback(const char *msg, void *client_data) +{ + (void)client_data; + fprintf(stdout, "[INFO] %s", msg); } /* -------------------------------------------------------------------------- */ int main (int argc, char *argv[]) { - opj_dparameters_t l_param; - opj_codec_t * l_codec; - opj_image_t * l_image; - 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_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]; - - /* should be test_tile_decoder 0 0 1000 1000 tte1.j2k */ - if( argc == 6 ) - { - da_x0=atoi(argv[1]); - da_y0=atoi(argv[2]); - da_x1=atoi(argv[3]); - da_y1=atoi(argv[4]); - strcpy(input_file,argv[5]); - - } - else - { - da_x0=0; - da_y0=0; - da_x1=1000; - da_y1=1000; - strcpy(input_file,"test.j2k"); - } - - if (! l_data) { - return EXIT_FAILURE; - } - - l_stream = opj_stream_create_default_file_stream(input_file,OPJ_TRUE); - if (!l_stream){ - free(l_data); - fprintf(stderr, "ERROR -> failed to create the stream from the file\n"); - return EXIT_FAILURE; - } - - /* Set the default decoding parameters */ - opj_set_default_decoder_parameters(&l_param); - - /* */ - l_param.decod_format = infile_format(input_file); - - /** you may here add custom decoding parameters */ - /* do not use layer decoding limitations */ - l_param.cp_layer = 0; - - /* do not use resolutions reductions */ - l_param.cp_reduce = 0; - - /* to decode only a part of the image data */ - /*opj_restrict_decoding(&l_param,0,0,1000,1000);*/ - - - switch(l_param.decod_format) { - case J2K_CFMT: /* JPEG-2000 codestream */ - { - /* Get a decoder handle */ - 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(OPJ_CODEC_JP2); - break; - } - default: - { - fprintf(stderr, "ERROR -> Not a valid JPEG2000 file!\n"); - free(l_data); - opj_stream_destroy(l_stream); - return EXIT_FAILURE; - } - } - - /* 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); - - /* Setup the decoder decoding parameters using user parameters */ - if (! opj_setup_decoder(l_codec, &l_param)) - { - fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n"); - free(l_data); - opj_stream_destroy(l_stream); - opj_destroy_codec(l_codec); - return EXIT_FAILURE; - } + opj_dparameters_t l_param; + opj_codec_t * l_codec; + opj_image_t * l_image; + 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_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]; + + /* should be test_tile_decoder 0 0 1000 1000 tte1.j2k */ + if( argc == 6 ) { + da_x0=atoi(argv[1]); + da_y0=atoi(argv[2]); + da_x1=atoi(argv[3]); + da_y1=atoi(argv[4]); + strcpy(input_file,argv[5]); + + } else { + da_x0=0; + da_y0=0; + da_x1=1000; + da_y1=1000; + strcpy(input_file,"test.j2k"); + } + + if (! l_data) { + return EXIT_FAILURE; + } + + l_stream = opj_stream_create_default_file_stream(input_file,OPJ_TRUE); + if (!l_stream) { + free(l_data); + fprintf(stderr, "ERROR -> failed to create the stream from the file\n"); + return EXIT_FAILURE; + } + + /* Set the default decoding parameters */ + opj_set_default_decoder_parameters(&l_param); + + /* */ + l_param.decod_format = infile_format(input_file); + + /** you may here add custom decoding parameters */ + /* do not use layer decoding limitations */ + l_param.cp_layer = 0; + + /* do not use resolutions reductions */ + l_param.cp_reduce = 0; + + /* to decode only a part of the image data */ + /*opj_restrict_decoding(&l_param,0,0,1000,1000);*/ + + + switch(l_param.decod_format) { + case J2K_CFMT: { /* JPEG-2000 codestream */ + /* Get a decoder handle */ + 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(OPJ_CODEC_JP2); + break; + } + default: { + fprintf(stderr, "ERROR -> Not a valid JPEG2000 file!\n"); + free(l_data); + opj_stream_destroy(l_stream); + return EXIT_FAILURE; + } + } + + /* 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); + + /* Setup the decoder decoding parameters using user parameters */ + if (! opj_setup_decoder(l_codec, &l_param)) { + fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n"); + free(l_data); + opj_stream_destroy(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, &l_image)) - { - fprintf(stderr, "ERROR -> j2k_to_image: failed to read the header\n"); - free(l_data); - opj_stream_destroy(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, &l_image)) { + fprintf(stderr, "ERROR -> j2k_to_image: failed to read the header\n"); + free(l_data); + 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"); - free(l_data); - opj_stream_destroy(l_stream); - opj_destroy_codec(l_codec); - opj_image_destroy(l_image); - 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"); + free(l_data); + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); + opj_image_destroy(l_image); + return EXIT_FAILURE; + } + + + while (l_go_on) { + if (! opj_read_tile_header( l_codec, + l_stream, + &l_tile_index, + &l_data_size, + &l_current_tile_x0, + &l_current_tile_y0, + &l_current_tile_x1, + &l_current_tile_y1, + &l_nb_comps, + &l_go_on)) { + free(l_data); + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); + opj_image_destroy(l_image); + return EXIT_FAILURE; } - - while (l_go_on) - { - if (! opj_read_tile_header( l_codec, - l_stream, - &l_tile_index, - &l_data_size, - &l_current_tile_x0, - &l_current_tile_y0, - &l_current_tile_x1, - &l_current_tile_y1, - &l_nb_comps, - &l_go_on)) - { - free(l_data); - opj_stream_destroy(l_stream); - opj_destroy_codec(l_codec); - opj_image_destroy(l_image); - return EXIT_FAILURE; + if (l_go_on) { + if (l_data_size > l_max_data_size) { + OPJ_BYTE *l_new_data = (OPJ_BYTE *) realloc(l_data, l_data_size); + if (! l_new_data) { + free(l_new_data); + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); + opj_image_destroy(l_image); + return EXIT_FAILURE; } + l_data = l_new_data; + l_max_data_size = l_data_size; + } - if (l_go_on) - { - if (l_data_size > l_max_data_size) - { - OPJ_BYTE *l_new_data = (OPJ_BYTE *) realloc(l_data, l_data_size); - if (! l_new_data) - { - free(l_new_data); - opj_stream_destroy(l_stream); - opj_destroy_codec(l_codec); - opj_image_destroy(l_image); - return EXIT_FAILURE; - } - l_data = l_new_data; - l_max_data_size = l_data_size; - } - - if (! opj_decode_tile_data(l_codec,l_tile_index,l_data,l_data_size,l_stream)) - { - free(l_data); - opj_stream_destroy(l_stream); - opj_destroy_codec(l_codec); - opj_image_destroy(l_image); - return EXIT_FAILURE; - } - /** now should inspect image to know the reduction factor and then how to behave with data */ - } - } - - if (! opj_end_decompress(l_codec,l_stream)) - { + if (! opj_decode_tile_data(l_codec,l_tile_index,l_data,l_data_size,l_stream)) { free(l_data); opj_stream_destroy(l_stream); opj_destroy_codec(l_codec); opj_image_destroy(l_image); return EXIT_FAILURE; + } + /** now should inspect image to know the reduction factor and then how to behave with data */ } + } - /* Free memory */ + if (! opj_end_decompress(l_codec,l_stream)) { free(l_data); opj_stream_destroy(l_stream); opj_destroy_codec(l_codec); opj_image_destroy(l_image); + return EXIT_FAILURE; + } + + /* Free memory */ + free(l_data); + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); + opj_image_destroy(l_image); - /* Print profiling*/ - /*PROFPRINT();*/ + /* Print profiling*/ + /*PROFPRINT();*/ - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/tests/test_tile_encoder.c b/tests/test_tile_encoder.c index 6ce628b5..d40b5aa9 100644 --- a/tests/test_tile_encoder.c +++ b/tests/test_tile_encoder.c @@ -38,23 +38,26 @@ /** sample error debug callback expecting no client object */ -static void error_callback(const char *msg, void *client_data) { - (void)client_data; - fprintf(stdout, "[ERROR] %s", msg); +static void error_callback(const char *msg, void *client_data) +{ + (void)client_data; + fprintf(stdout, "[ERROR] %s", msg); } /** sample warning debug callback expecting no client object */ -static void warning_callback(const char *msg, void *client_data) { - (void)client_data; - fprintf(stdout, "[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 */ -static void info_callback(const char *msg, void *client_data) { - (void)client_data; - fprintf(stdout, "[INFO] %s", msg); +static void info_callback(const char *msg, void *client_data) +{ + (void)client_data; + fprintf(stdout, "[INFO] %s", msg); } /* -------------------------------------------------------------------------- */ @@ -62,251 +65,242 @@ static void info_callback(const char *msg, void *client_data) { #define NUM_COMPS_MAX 4 int main (int argc, char *argv[]) { - opj_cparameters_t l_param; - opj_codec_t * l_codec; - opj_image_t * l_image; - opj_image_cmptparm_t l_params [NUM_COMPS_MAX]; - opj_stream_t * l_stream; - OPJ_UINT32 l_nb_tiles; - OPJ_UINT32 l_data_size; - unsigned char len; + opj_cparameters_t l_param; + opj_codec_t * l_codec; + opj_image_t * l_image; + opj_image_cmptparm_t l_params [NUM_COMPS_MAX]; + opj_stream_t * l_stream; + OPJ_UINT32 l_nb_tiles; + OPJ_UINT32 l_data_size; + unsigned char len; #ifdef USING_MCT - const OPJ_FLOAT32 l_mct [] = - { - 1 , 0 , 0 , - 0 , 1 , 0 , - 0 , 0 , 1 - }; - - const OPJ_INT32 l_offsets [] = - { - 128 , 128 , 128 - }; + const OPJ_FLOAT32 l_mct [] = { + 1 , 0 , 0 , + 0 , 1 , 0 , + 0 , 0 , 1 + }; + + const OPJ_INT32 l_offsets [] = { + 128 , 128 , 128 + }; #endif - opj_image_cmptparm_t * l_current_param_ptr; - OPJ_UINT32 i; - OPJ_BYTE *l_data; - - OPJ_UINT32 num_comps; - int image_width; - int image_height; - int tile_width; - int tile_height; - int comp_prec; - int irreversible; - char output_file[64]; - - /* should be test_tile_encoder 3 2000 2000 1000 1000 8 tte1.j2k */ - if( argc == 9 ) - { - num_comps = (OPJ_UINT32)atoi( argv[1] ); - image_width = atoi( argv[2] ); - image_height = atoi( argv[3] ); - tile_width = atoi( argv[4] ); - tile_height = atoi( argv[5] ); - comp_prec = atoi( argv[6] ); - irreversible = atoi( argv[7] ); - strcpy(output_file, argv[8] ); + opj_image_cmptparm_t * l_current_param_ptr; + OPJ_UINT32 i; + OPJ_BYTE *l_data; + + OPJ_UINT32 num_comps; + int image_width; + int image_height; + int tile_width; + int tile_height; + int comp_prec; + int irreversible; + char output_file[64]; + + /* should be test_tile_encoder 3 2000 2000 1000 1000 8 tte1.j2k */ + if( argc == 9 ) { + num_comps = (OPJ_UINT32)atoi( argv[1] ); + image_width = atoi( argv[2] ); + image_height = atoi( argv[3] ); + tile_width = atoi( argv[4] ); + tile_height = atoi( argv[5] ); + comp_prec = atoi( argv[6] ); + irreversible = atoi( argv[7] ); + strcpy(output_file, argv[8] ); + } else { + num_comps = 3; + image_width = 2000; + image_height = 2000; + tile_width = 1000; + tile_height = 1000; + comp_prec = 8; + irreversible = 1; + strcpy(output_file, "test.j2k" ); } - else - { - num_comps = 3; - image_width = 2000; - image_height = 2000; - tile_width = 1000; - tile_height = 1000; - comp_prec = 8; - irreversible = 1; - strcpy(output_file, "test.j2k" ); + if( num_comps > NUM_COMPS_MAX ) { + return 1; } - if( num_comps > NUM_COMPS_MAX ) - { - return 1; - } - l_nb_tiles = (OPJ_UINT32)(image_width/tile_width) * (OPJ_UINT32)(image_height/tile_height); - l_data_size = (OPJ_UINT32)tile_width * (OPJ_UINT32)tile_height * (OPJ_UINT32)num_comps * (OPJ_UINT32)(comp_prec/8); + l_nb_tiles = (OPJ_UINT32)(image_width/tile_width) * (OPJ_UINT32)(image_height/tile_height); + l_data_size = (OPJ_UINT32)tile_width * (OPJ_UINT32)tile_height * (OPJ_UINT32)num_comps * (OPJ_UINT32)(comp_prec/8); - l_data = (OPJ_BYTE*) malloc(l_data_size * sizeof(OPJ_BYTE)); + l_data = (OPJ_BYTE*) malloc(l_data_size * sizeof(OPJ_BYTE)); - fprintf(stdout, "Encoding random values -> keep in mind that this is very hard to compress\n"); - for (i=0;i<l_data_size;++i) { - l_data[i] = (OPJ_BYTE)i; /*rand();*/ - } + fprintf(stdout, "Encoding random values -> keep in mind that this is very hard to compress\n"); + for (i=0; i<l_data_size; ++i) { + l_data[i] = (OPJ_BYTE)i; /*rand();*/ + } - opj_set_default_encoder_parameters(&l_param); - /** you may here add custom encoding parameters */ - /* rate specifications */ - /** number of quality layers in the stream */ - l_param.tcp_numlayers = 1; - l_param.cp_fixed_quality = 1; - l_param.tcp_distoratio[0] = 20; - /* is using others way of calculation */ - /* l_param.cp_disto_alloc = 1 or l_param.cp_fixed_alloc = 1 */ - /* l_param.tcp_rates[0] = ... */ + opj_set_default_encoder_parameters(&l_param); + /** you may here add custom encoding parameters */ + /* rate specifications */ + /** number of quality layers in the stream */ + l_param.tcp_numlayers = 1; + l_param.cp_fixed_quality = 1; + l_param.tcp_distoratio[0] = 20; + /* is using others way of calculation */ + /* l_param.cp_disto_alloc = 1 or l_param.cp_fixed_alloc = 1 */ + /* l_param.tcp_rates[0] = ... */ - /* tile definitions parameters */ - /* position of the tile grid aligned with the image */ - l_param.cp_tx0 = 0; - l_param.cp_ty0 = 0; - /* tile size, we are using tile based encoding */ - l_param.tile_size_on = OPJ_TRUE; - l_param.cp_tdx = tile_width; - l_param.cp_tdy = tile_height; + /* tile definitions parameters */ + /* position of the tile grid aligned with the image */ + l_param.cp_tx0 = 0; + l_param.cp_ty0 = 0; + /* tile size, we are using tile based encoding */ + l_param.tile_size_on = OPJ_TRUE; + l_param.cp_tdx = tile_width; + l_param.cp_tdy = tile_height; - /* use irreversible encoding ?*/ - l_param.irreversible = irreversible; + /* use irreversible encoding ?*/ + l_param.irreversible = irreversible; - /* do not bother with mct, the rsiz is set when calling opj_set_MCT*/ - /*l_param.cp_rsiz = OPJ_STD_RSIZ;*/ + /* do not bother with mct, the rsiz is set when calling opj_set_MCT*/ + /*l_param.cp_rsiz = OPJ_STD_RSIZ;*/ - /* no cinema */ - /*l_param.cp_cinema = 0;*/ + /* no cinema */ + /*l_param.cp_cinema = 0;*/ - /* no not bother using SOP or EPH markers, do not use custom size precinct */ - /* number of precincts to specify */ - /* l_param.csty = 0;*/ - /* l_param.res_spec = ... */ - /* l_param.prch_init[i] = .. */ - /* l_param.prcw_init[i] = .. */ + /* no not bother using SOP or EPH markers, do not use custom size precinct */ + /* number of precincts to specify */ + /* l_param.csty = 0;*/ + /* l_param.res_spec = ... */ + /* l_param.prch_init[i] = .. */ + /* l_param.prcw_init[i] = .. */ - /* do not use progression order changes */ - /*l_param.numpocs = 0;*/ - /* l_param.POC[i].... */ + /* do not use progression order changes */ + /*l_param.numpocs = 0;*/ + /* l_param.POC[i].... */ - /* do not restrain the size for a component.*/ - /* l_param.max_comp_size = 0; */ + /* do not restrain the size for a component.*/ + /* l_param.max_comp_size = 0; */ - /** block encoding style for each component, do not use at the moment */ - /** J2K_CCP_CBLKSTY_TERMALL, J2K_CCP_CBLKSTY_LAZY, J2K_CCP_CBLKSTY_VSC, J2K_CCP_CBLKSTY_SEGSYM, J2K_CCP_CBLKSTY_RESET */ - /* l_param.mode = 0;*/ + /** block encoding style for each component, do not use at the moment */ + /** J2K_CCP_CBLKSTY_TERMALL, J2K_CCP_CBLKSTY_LAZY, J2K_CCP_CBLKSTY_VSC, J2K_CCP_CBLKSTY_SEGSYM, J2K_CCP_CBLKSTY_RESET */ + /* l_param.mode = 0;*/ - /** number of resolutions */ - l_param.numresolution = 6; + /** number of resolutions */ + l_param.numresolution = 6; - /** progression order to use*/ - /** OPJ_LRCP, OPJ_RLCP, OPJ_RPCL, PCRL, CPRL */ - l_param.prog_order = OPJ_LRCP; + /** progression order to use*/ + /** OPJ_LRCP, OPJ_RLCP, OPJ_RPCL, PCRL, CPRL */ + l_param.prog_order = OPJ_LRCP; - /** no "region" of interest, more precisally component */ - /* l_param.roi_compno = -1; */ - /* l_param.roi_shift = 0; */ + /** no "region" of interest, more precisally component */ + /* l_param.roi_compno = -1; */ + /* l_param.roi_shift = 0; */ - /* we are not using multiple tile parts for a tile. */ - /* l_param.tp_on = 0; */ - /* l_param.tp_flag = 0; */ + /* we are not using multiple tile parts for a tile. */ + /* l_param.tp_on = 0; */ + /* l_param.tp_flag = 0; */ - /* if we are using mct */ + /* if we are using mct */ #ifdef USING_MCT - opj_set_MCT(&l_param,l_mct,l_offsets,NUM_COMPS); + opj_set_MCT(&l_param,l_mct,l_offsets,NUM_COMPS); #endif - /* image definition */ - l_current_param_ptr = l_params; - for (i=0;i<num_comps;++i) { - /* do not bother bpp useless */ - /*l_current_param_ptr->bpp = COMP_PREC;*/ - l_current_param_ptr->dx = 1; - l_current_param_ptr->dy = 1; + /* image definition */ + l_current_param_ptr = l_params; + for (i=0; i<num_comps; ++i) { + /* do not bother bpp useless */ + /*l_current_param_ptr->bpp = COMP_PREC;*/ + l_current_param_ptr->dx = 1; + l_current_param_ptr->dy = 1; - l_current_param_ptr->h = (OPJ_UINT32)image_height; - l_current_param_ptr->w = (OPJ_UINT32)image_width; + l_current_param_ptr->h = (OPJ_UINT32)image_height; + l_current_param_ptr->w = (OPJ_UINT32)image_width; - l_current_param_ptr->sgnd = 0; - l_current_param_ptr->prec = (OPJ_UINT32)comp_prec; + l_current_param_ptr->sgnd = 0; + l_current_param_ptr->prec = (OPJ_UINT32)comp_prec; - l_current_param_ptr->x0 = 0; - l_current_param_ptr->y0 = 0; + l_current_param_ptr->x0 = 0; + l_current_param_ptr->y0 = 0; + + ++l_current_param_ptr; + } + + /* should we do j2k or jp2 ?*/ + len = (unsigned char)strlen( output_file ); + if( strcmp( output_file + len - 4, ".jp2" ) == 0 ) { + l_codec = opj_create_compress(OPJ_CODEC_JP2); + } else { + l_codec = opj_create_compress(OPJ_CODEC_J2K); + } + if (!l_codec) { + return 1; + } - ++l_current_param_ptr; - } + /* 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); - /* should we do j2k or jp2 ?*/ - len = (unsigned char)strlen( output_file ); - if( strcmp( output_file + len - 4, ".jp2" ) == 0 ) - { - l_codec = opj_create_compress(OPJ_CODEC_JP2); + l_image = opj_image_tile_create(num_comps,l_params,OPJ_CLRSPC_SRGB); + if (! l_image) { + opj_destroy_codec(l_codec); + return 1; } - else - { - l_codec = opj_create_compress(OPJ_CODEC_J2K); + + l_image->x0 = 0; + l_image->y0 = 0; + l_image->x1 = (OPJ_UINT32)image_width; + l_image->y1 = (OPJ_UINT32)image_height; + l_image->color_space = OPJ_CLRSPC_SRGB; + + if (! opj_setup_encoder(l_codec,&l_param,l_image)) { + fprintf(stderr, "ERROR -> test_tile_encoder: failed to setup the codec!\n"); + opj_destroy_codec(l_codec); + opj_image_destroy(l_image); + return 1; } - if (!l_codec) { - return 1; - } - - /* 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_image = opj_image_tile_create(num_comps,l_params,OPJ_CLRSPC_SRGB); - if (! l_image) { - opj_destroy_codec(l_codec); - return 1; - } - - l_image->x0 = 0; - l_image->y0 = 0; - l_image->x1 = (OPJ_UINT32)image_width; - l_image->y1 = (OPJ_UINT32)image_height; - l_image->color_space = OPJ_CLRSPC_SRGB; - - if (! opj_setup_encoder(l_codec,&l_param,l_image)) { - fprintf(stderr, "ERROR -> test_tile_encoder: failed to setup the codec!\n"); - opj_destroy_codec(l_codec); - opj_image_destroy(l_image); - return 1; - } l_stream = opj_stream_create_default_file_stream(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; - } - - if (! opj_start_compress(l_codec,l_image,l_stream)) { - fprintf(stderr, "ERROR -> test_tile_encoder: failed to start compress!\n"); + 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; + } + + if (! opj_start_compress(l_codec,l_image,l_stream)) { + fprintf(stderr, "ERROR -> test_tile_encoder: failed to start compress!\n"); opj_stream_destroy(l_stream); - opj_destroy_codec(l_codec); - opj_image_destroy(l_image); - return 1; - } - - for (i=0;i<l_nb_tiles;++i) { - 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_destroy_codec(l_codec); + opj_image_destroy(l_image); + return 1; + } + + for (i=0; i<l_nb_tiles; ++i) { + 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(l_stream); - opj_destroy_codec(l_codec); - opj_image_destroy(l_image); - return 1; - } - } - - if (! opj_end_compress(l_codec,l_stream)) { - fprintf(stderr, "ERROR -> test_tile_encoder: failed to end compress!\n"); + opj_destroy_codec(l_codec); + opj_image_destroy(l_image); + return 1; + } + } + + if (! opj_end_compress(l_codec,l_stream)) { + fprintf(stderr, "ERROR -> test_tile_encoder: failed to end compress!\n"); opj_stream_destroy(l_stream); - opj_destroy_codec(l_codec); - opj_image_destroy(l_image); - return 1; - } + opj_destroy_codec(l_codec); + opj_image_destroy(l_image); + return 1; + } opj_stream_destroy(l_stream); - opj_destroy_codec(l_codec); - opj_image_destroy(l_image); + opj_destroy_codec(l_codec); + opj_image_destroy(l_image); - free(l_data); + free(l_data); - /* Print profiling*/ - /*PROFPRINT();*/ + /* Print profiling*/ + /*PROFPRINT();*/ - return 0; + return 0; } diff --git a/tests/unit/testempty0.c b/tests/unit/testempty0.c index 09850604..d984a42a 100644 --- a/tests/unit/testempty0.c +++ b/tests/unit/testempty0.c @@ -1,7 +1,8 @@ #include "openjpeg.h" -int main(int argc, char **argv) { - (void)argc; - (void)argv; - return 0; +int main(int argc, char **argv) +{ + (void)argc; + (void)argv; + return 0; } diff --git a/tests/unit/testempty1.c b/tests/unit/testempty1.c index fc961c22..d682d4fe 100644 --- a/tests/unit/testempty1.c +++ b/tests/unit/testempty1.c @@ -36,102 +36,102 @@ void error_callback(const char *msg, void *v); void warning_callback(const char *msg, void *v); void info_callback(const char *msg, void *v); -void error_callback(const char *msg, void *v) { -(void)msg; -(void)v; -puts(msg); +void error_callback(const char *msg, void *v) +{ + (void)msg; + (void)v; + puts(msg); } -void warning_callback(const char *msg, void *v) { -(void)msg; -(void)v; -puts(msg); +void warning_callback(const char *msg, void *v) +{ + (void)msg; + (void)v; + puts(msg); } -void info_callback(const char *msg, void *v) { -(void)msg; -(void)v; -puts(msg); +void info_callback(const char *msg, void *v) +{ + (void)msg; + (void)v; + puts(msg); } int main(int argc, char *argv[]) { - const char * v = opj_version(); - - const OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_GRAY; - unsigned int numcomps = 1; - unsigned int i; - unsigned int image_width = 256; - unsigned int image_height = 256; - - opj_cparameters_t parameters; - - unsigned int subsampling_dx = 0; - unsigned int subsampling_dy = 0; - - opj_image_cmptparm_t cmptparm; - opj_image_t *image; - opj_codec_t* l_codec = 00; - OPJ_BOOL bSuccess; - opj_stream_t *l_stream = 00; - (void)argc; - (void)argv; - - opj_set_default_encoder_parameters(¶meters); - parameters.cod_format = J2K_CFMT; - puts(v); - cmptparm.prec = 8; - cmptparm.bpp = 8; - cmptparm.sgnd = 0; - cmptparm.dx = subsampling_dx; - cmptparm.dy = subsampling_dy; - cmptparm.w = image_width; - cmptparm.h = image_height; - - image = opj_image_create(numcomps, &cmptparm, color_space); - assert( image ); - - for (i = 0; i < image_width * image_height; i++) - { - unsigned int compno; - for(compno = 0; compno < numcomps; compno++) - { - image->comps[compno].data[i] = 0; - } + const char * v = opj_version(); + + const OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_GRAY; + unsigned int numcomps = 1; + unsigned int i; + unsigned int image_width = 256; + unsigned int image_height = 256; + + opj_cparameters_t parameters; + + unsigned int subsampling_dx = 0; + unsigned int subsampling_dy = 0; + + opj_image_cmptparm_t cmptparm; + opj_image_t *image; + opj_codec_t* l_codec = 00; + OPJ_BOOL bSuccess; + opj_stream_t *l_stream = 00; + (void)argc; + (void)argv; + + opj_set_default_encoder_parameters(¶meters); + parameters.cod_format = J2K_CFMT; + puts(v); + cmptparm.prec = 8; + cmptparm.bpp = 8; + cmptparm.sgnd = 0; + cmptparm.dx = subsampling_dx; + cmptparm.dy = subsampling_dy; + cmptparm.w = image_width; + cmptparm.h = image_height; + + image = opj_image_create(numcomps, &cmptparm, color_space); + assert( image ); + + for (i = 0; i < image_width * image_height; i++) { + unsigned int compno; + for(compno = 0; compno < numcomps; compno++) { + image->comps[compno].data[i] = 0; + } } - /* 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_codec = opj_create_compress(OPJ_CODEC_J2K); - 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); + /* 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_codec = opj_create_compress(OPJ_CODEC_J2K); + 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); + + opj_setup_encoder(l_codec, ¶meters, image); + + l_stream = opj_stream_create_default_file_stream("testempty1.j2k",OPJ_FALSE); + assert(l_stream); + bSuccess = opj_start_compress(l_codec,image,l_stream); + if( !bSuccess ) { + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); + opj_image_destroy(image); + return 0; + } - opj_setup_encoder(l_codec, ¶meters, image); + assert( bSuccess ); + bSuccess = opj_encode(l_codec, l_stream); + assert( bSuccess ); + bSuccess = opj_end_compress(l_codec, l_stream); + assert( bSuccess ); - l_stream = opj_stream_create_default_file_stream("testempty1.j2k",OPJ_FALSE); - assert(l_stream); - bSuccess = opj_start_compress(l_codec,image,l_stream); - if( !bSuccess ) - { opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); opj_image_destroy(image); - return 0; - } - - assert( bSuccess ); - bSuccess = opj_encode(l_codec, l_stream); - assert( bSuccess ); - bSuccess = opj_end_compress(l_codec, l_stream); - assert( bSuccess ); - opj_stream_destroy(l_stream); - - opj_destroy_codec(l_codec); - opj_image_destroy(image); - - puts( "end" ); - return 0; + puts( "end" ); + return 0; } diff --git a/tests/unit/testempty2.c b/tests/unit/testempty2.c index 6b395480..28a92f1f 100644 --- a/tests/unit/testempty2.c +++ b/tests/unit/testempty2.c @@ -37,147 +37,146 @@ void error_callback(const char *msg, void *v); void warning_callback(const char *msg, void *v); void info_callback(const char *msg, void *v); -void error_callback(const char *msg, void *v) { -(void)msg; -(void)v; -puts(msg); +void error_callback(const char *msg, void *v) +{ + (void)msg; + (void)v; + puts(msg); } -void warning_callback(const char *msg, void *v) { -(void)msg; -(void)v; -puts(msg); +void warning_callback(const char *msg, void *v) +{ + (void)msg; + (void)v; + puts(msg); } -void info_callback(const char *msg, void *v) { -(void)msg; -(void)v; -puts(msg); +void info_callback(const char *msg, void *v) +{ + (void)msg; + (void)v; + puts(msg); } int main(int argc, char *argv[]) { - const char * v = opj_version(); - - const OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_GRAY; - unsigned int numcomps = 1; - unsigned int i; - unsigned int image_width = 256; - unsigned int image_height = 256; - - opj_cparameters_t parameters; - - unsigned int subsampling_dx; - unsigned int subsampling_dy; - const char outputfile[] = "testempty2.j2k"; - - opj_image_cmptparm_t cmptparm; - opj_image_t *image; - opj_codec_t* l_codec = 00; - OPJ_BOOL bSuccess; - opj_stream_t *l_stream = 00; - (void)argc; - (void)argv; - - opj_set_default_encoder_parameters(¶meters); - parameters.cod_format = J2K_CFMT; - puts(v); - subsampling_dx = (unsigned int)parameters.subsampling_dx; - subsampling_dy = (unsigned int)parameters.subsampling_dy; - cmptparm.prec = 8; - cmptparm.bpp = 8; - cmptparm.sgnd = 0; - cmptparm.dx = subsampling_dx; - cmptparm.dy = subsampling_dy; - cmptparm.w = image_width; - cmptparm.h = image_height; - strncpy(parameters.outfile, outputfile, sizeof(parameters.outfile)-1); - - image = opj_image_create(numcomps, &cmptparm, color_space); - assert( image ); - - for (i = 0; i < image_width * image_height; i++) - { - unsigned int compno; - for(compno = 0; compno < numcomps; compno++) - { - image->comps[compno].data[i] = 0; - } + const char * v = opj_version(); + + const OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_GRAY; + unsigned int numcomps = 1; + unsigned int i; + unsigned int image_width = 256; + unsigned int image_height = 256; + + opj_cparameters_t parameters; + + unsigned int subsampling_dx; + unsigned int subsampling_dy; + const char outputfile[] = "testempty2.j2k"; + + opj_image_cmptparm_t cmptparm; + opj_image_t *image; + opj_codec_t* l_codec = 00; + OPJ_BOOL bSuccess; + opj_stream_t *l_stream = 00; + (void)argc; + (void)argv; + + opj_set_default_encoder_parameters(¶meters); + parameters.cod_format = J2K_CFMT; + puts(v); + subsampling_dx = (unsigned int)parameters.subsampling_dx; + subsampling_dy = (unsigned int)parameters.subsampling_dy; + cmptparm.prec = 8; + cmptparm.bpp = 8; + cmptparm.sgnd = 0; + cmptparm.dx = subsampling_dx; + cmptparm.dy = subsampling_dy; + cmptparm.w = image_width; + cmptparm.h = image_height; + strncpy(parameters.outfile, outputfile, sizeof(parameters.outfile)-1); + + image = opj_image_create(numcomps, &cmptparm, color_space); + assert( image ); + + for (i = 0; i < image_width * image_height; i++) { + unsigned int compno; + for(compno = 0; compno < numcomps; compno++) { + image->comps[compno].data[i] = 0; + } } - /* 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_codec = opj_create_compress(OPJ_CODEC_J2K); - 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); - - opj_setup_encoder(l_codec, ¶meters, image); - - l_stream = opj_stream_create_default_file_stream(parameters.outfile,OPJ_FALSE); - if( !l_stream ) - { - fprintf( stderr, "Something went wrong during creation of stream\n" ); - opj_destroy_codec(l_codec); - opj_image_destroy(image); - opj_stream_destroy(l_stream); - return 1; + /* 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_codec = opj_create_compress(OPJ_CODEC_J2K); + 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); + + opj_setup_encoder(l_codec, ¶meters, image); + + l_stream = opj_stream_create_default_file_stream(parameters.outfile,OPJ_FALSE); + if( !l_stream ) { + fprintf( stderr, "Something went wrong during creation of stream\n" ); + opj_destroy_codec(l_codec); + opj_image_destroy(image); + opj_stream_destroy(l_stream); + return 1; } - assert(l_stream); - bSuccess = opj_start_compress(l_codec,image,l_stream); - if( !bSuccess ) - { - opj_stream_destroy(l_stream); - opj_destroy_codec(l_codec); - opj_image_destroy(image); - return 0; + assert(l_stream); + bSuccess = opj_start_compress(l_codec,image,l_stream); + if( !bSuccess ) { + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); + opj_image_destroy(image); + return 0; } - assert( bSuccess ); - bSuccess = opj_encode(l_codec, l_stream); - assert( bSuccess ); - bSuccess = opj_end_compress(l_codec, l_stream); - assert( bSuccess ); + assert( bSuccess ); + bSuccess = opj_encode(l_codec, l_stream); + assert( bSuccess ); + bSuccess = opj_end_compress(l_codec, l_stream); + assert( bSuccess ); - opj_stream_destroy(l_stream); + opj_stream_destroy(l_stream); - opj_destroy_codec(l_codec); - opj_image_destroy(image); + opj_destroy_codec(l_codec); + opj_image_destroy(image); - /* read back the generated file */ -{ - opj_codec_t* d_codec = 00; - opj_dparameters_t dparameters; + /* read back the generated file */ + { + opj_codec_t* d_codec = 00; + opj_dparameters_t dparameters; - d_codec = opj_create_decompress(OPJ_CODEC_J2K); - opj_set_info_handler(d_codec, info_callback,00); - opj_set_warning_handler(d_codec, warning_callback,00); - opj_set_error_handler(d_codec, error_callback,00); + d_codec = opj_create_decompress(OPJ_CODEC_J2K); + opj_set_info_handler(d_codec, info_callback,00); + opj_set_warning_handler(d_codec, warning_callback,00); + opj_set_error_handler(d_codec, error_callback,00); - bSuccess = opj_setup_decoder(d_codec, &dparameters); - assert( bSuccess ); + bSuccess = opj_setup_decoder(d_codec, &dparameters); + assert( bSuccess ); - l_stream = opj_stream_create_default_file_stream(outputfile,1); - assert( l_stream ); + l_stream = opj_stream_create_default_file_stream(outputfile,1); + assert( l_stream ); - bSuccess = opj_read_header(l_stream, d_codec, &image); - assert( bSuccess ); + bSuccess = opj_read_header(l_stream, d_codec, &image); + assert( bSuccess ); - bSuccess = opj_decode(l_codec, l_stream, image); - assert( bSuccess ); + bSuccess = opj_decode(l_codec, l_stream, image); + assert( bSuccess ); - bSuccess = opj_end_decompress(l_codec, l_stream); - assert( bSuccess ); + bSuccess = opj_end_decompress(l_codec, l_stream); + assert( bSuccess ); - opj_stream_destroy(l_stream); + opj_stream_destroy(l_stream); - opj_destroy_codec(d_codec); + opj_destroy_codec(d_codec); - opj_image_destroy(image); -} + opj_image_destroy(image); + } - puts( "end" ); - return 0; + puts( "end" ); + return 0; } |
