2 * Copyright (c) 2011, Mickael Savinaud, Communications & Systemes <mickael.savinaud@c-s.fr>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
30 * Created on: 8 juil. 2011
40 #include "opj_config.h"
41 #include "opj_getopt.h"
44 #include "format_defs.h"
47 double* parseToleranceValues( char* inArg, const int nbcomp);
48 void comparePGXimages_help_display(void);
49 opj_image_t* readImageFromFilePGX(char* filename, int nbFilenamePGX, char *separator);
51 int imageToPNG(const opj_image_t* image, const char* filename, int num_comp_select);
54 typedef struct test_cmp_parameters
60 /** Number of components */
65 double* tabPEAKvalues;
69 char separator_base[2];
71 char separator_test[2];
73 } test_cmp_parameters;
75 /*******************************************************************************
76 * Command line help function
77 *******************************************************************************/
78 void comparePGXimages_help_display(void) {
79 fprintf(stdout,"\nList of parameters for the comparePGX function \n");
81 fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline PGX image \n");
82 fprintf(stdout," -t \t REQUIRED \t filename to the test PGX image\n");
83 fprintf(stdout," -n \t REQUIRED \t number of component of the image (used to generate correct filename)\n");
84 fprintf(stdout," -m \t OPTIONAL \t list of MSE tolerances, separated by : (size must correspond to the number of component) of \n");
85 fprintf(stdout," -p \t OPTIONAL \t list of PEAK tolerances, separated by : (size must correspond to the number of component) \n");
86 fprintf(stdout," -s \t OPTIONAL \t 1 or 2 filename separator to take into account PGX image with different components, "
87 "please indicate b or t before separator to indicate respectively the separator "
88 "for ref/base file and for test file. \n");
89 fprintf(stdout," -r \t OPTIONAL \t indicate if you want to run this function as conformance test or as non regression test\n");
93 /*******************************************************************************
95 *******************************************************************************/
96 int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
98 char *MSElistvalues = NULL; char *PEAKlistvalues= NULL;
99 char *separatorList = NULL;
100 int sizemembasefile, sizememtestfile;
101 int index, flagM=0, flagP=0;
102 const char optlist[] = "b:t:n:m:p:s:d";
106 param->base_filename = NULL;
107 param->test_filename = NULL;
109 param->tabMSEvalues = NULL;
110 param->tabPEAKvalues = NULL;
115 while ((c = opj_getopt(argc, argv, optlist)) != -1)
119 sizemembasefile = (int)strlen(opj_optarg)+1;
120 param->base_filename = (char*) malloc(sizemembasefile);
121 param->base_filename[0] = '\0';
122 strncpy(param->base_filename, opj_optarg, strlen(opj_optarg));
123 param->base_filename[strlen(opj_optarg)] = '\0';
124 //printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );
127 sizememtestfile = (int) strlen(opj_optarg) + 1;
128 param->test_filename = (char*) malloc(sizememtestfile);
129 param->test_filename[0] = '\0';
130 strncpy(param->test_filename, opj_optarg, strlen(opj_optarg));
131 param->test_filename[strlen(opj_optarg)] = '\0';
132 //printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);
135 param->nbcomp = atoi(opj_optarg);
138 MSElistvalues = opj_optarg;
142 PEAKlistvalues = opj_optarg;
149 separatorList = opj_optarg;
152 if ((opj_optopt == 'b') || (opj_optopt == 't') || (opj_optopt == 'n') || (opj_optopt == 'p') || (opj_optopt == 'm') || (opj_optopt
154 fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt);
156 if (isprint(opj_optopt)) fprintf(stderr, "Unknown option `-%c'.\n", opj_optopt);
157 else fprintf(stderr, "Unknown option character `\\x%x'.\n", opj_optopt);
160 fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, opj_optarg);
164 if (opj_optind != argc)
166 for (index = opj_optind; index < argc; index++)
167 fprintf(stderr,"Non-option argument %s\n", argv[index]);
171 if (param->nbcomp == 0)
173 fprintf(stderr,"Need to indicate the number of components !\n");
178 if ( flagM && flagP )
180 param->tabMSEvalues = parseToleranceValues( MSElistvalues, param->nbcomp);
181 param->tabPEAKvalues = parseToleranceValues( PEAKlistvalues, param->nbcomp);
182 if ( (param->tabMSEvalues == NULL) || (param->tabPEAKvalues == NULL))
184 fprintf(stderr,"MSE and PEAK values are not correct (respectively need %d values)\n",param->nbcomp);
194 // Get separators after corresponding letter (b or t)
195 if (separatorList != NULL)
197 if( (strlen(separatorList) ==2) || (strlen(separatorList) ==4) )
199 // keep original string
200 int sizeseplist = (int)strlen(separatorList)+1;
201 char* separatorList2 = (char*)malloc( sizeseplist );
202 separatorList2[0] = '\0';
203 strncpy(separatorList2, separatorList, strlen(separatorList));
204 separatorList2[strlen(separatorList)] = '\0';
205 //printf("separatorList2 = %s [%d / %d]\n", separatorList2, strlen(separatorList2), sizeseplist);
207 if (strlen(separatorList) == 2) // one separator behind b or t
209 char *resultT = NULL;
210 resultT = strtok(separatorList2, "t");
211 if (strlen(resultT) == strlen(separatorList)) // didn't find t character, try to find b
213 char *resultB = NULL;
214 resultB = strtok(resultT, "b");
215 if (strlen(resultB) == 1)
217 param->separator_base[0] = separatorList[1];param->separator_base[1] = '\0';
218 param->separator_test[0] ='\0';
222 free(separatorList2);
228 param->separator_base[0] ='\0';
229 param->separator_test[0] = separatorList[1];param->separator_test[1] = '\0';
231 //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) );
233 else // == 4 characters we must found t and b
235 char *resultT = NULL;
236 resultT = strtok(separatorList2, "t");
237 if (strlen(resultT) == 3) // found t in first place
239 char *resultB = NULL;
240 resultB = strtok(resultT, "b");
241 if (strlen(resultB) == 1) // found b after t
243 param->separator_test[0] = separatorList[1];param->separator_test[1] = '\0';
244 param->separator_base[0] = separatorList[3];param->separator_base[1] = '\0';
246 else // didn't find b after t
248 free(separatorList2);
252 else // == 2, didn't find t in first place
254 char *resultB = NULL;
255 resultB = strtok(resultT, "b");
256 if (strlen(resultB) == 1) // found b in first place
258 param->separator_base[0] = separatorList[1]; param->separator_base[1] = '\0';
259 param->separator_test[0] = separatorList[3]; param->separator_test[1] = '\0';
261 else // didn't found b in first place => problem
263 free(separatorList2);
268 free(separatorList2);
270 else // wrong number of argument after -s
277 if (param->nbcomp == 1)
279 param->separator_base[0] = '\0';
280 param->separator_test[0] = '\0';
284 fprintf(stderr,"If number of component is > 1, we need separator\n");
290 if ( (param->nr_flag) && (flagP || flagM) )
292 fprintf(stderr,"Wrong input parameters list: it is non-regression test or tolerance comparison\n");
295 if ( (!param->nr_flag) && (!flagP || !flagM) )
297 fprintf(stderr,"Wrong input parameters list: it is non-regression test or tolerance comparison\n");
304 /*******************************************************************************
305 * Parse MSE and PEAK input values (
307 *******************************************************************************/
308 double* parseToleranceValues( char* inArg, const int nbcomp)
310 double* outArgs= malloc(nbcomp * sizeof(double));
314 result = strtok( inArg, delims );
316 while( (result != NULL) && (it_comp < nbcomp ))
318 outArgs[it_comp] = atof(result);
319 result = strtok( NULL, delims );
323 if (it_comp != nbcomp)
328 /*******************************************************************************
329 * Create filenames from a filename by used separator and nb components
331 *******************************************************************************/
332 char* createMultiComponentsFilename(const char* inFilename, const int indexF, const char* separator)
335 char *outFilename, *ptr;
339 //printf("inFilename = %s\n", inFilename);
340 if ((ptr = strrchr(inFilename, token)) != NULL)
342 posToken = (int) (strlen(inFilename) - strlen(ptr));
343 //printf("Position of %c character inside inFilename = %d\n", token, posToken);
347 //printf("Token %c not found\n", token);
348 outFilename = (char*)malloc(1);
349 outFilename[0] = '\0';
353 outFilename = (char*)malloc((posToken + 7) * sizeof(char)); //6
355 strncpy(outFilename, inFilename, posToken);
357 outFilename[posToken] = '\0';
359 strcat(outFilename, separator);
361 sprintf(s, "%i", indexF);
362 strcat(outFilename, s);
364 strcat(outFilename, ".pgx");
366 //printf("outfilename: %s\n", outFilename);
369 /*******************************************************************************
371 *******************************************************************************/
372 opj_image_t* readImageFromFilePGX(char* filename, int nbFilenamePGX, char *separator)
375 opj_image_t* image_read = NULL;
376 opj_image_t* image = NULL;
377 opj_cparameters_t parameters;
378 opj_image_cmptparm_t* param_image_read;
381 // If separator is empty => nb file to read is equal to one
382 if ( strlen(separator) == 0 )
385 /* set encoding parameters to default values */
386 opj_set_default_encoder_parameters(¶meters);
387 parameters.decod_format = PGX_DFMT;
388 strncpy(parameters.infile, filename, sizeof(parameters.infile)-1);
391 param_image_read = malloc(nbFilenamePGX * sizeof(opj_image_cmptparm_t));
392 data = malloc(nbFilenamePGX * sizeof(*data));
395 for (it_file = 0; it_file < nbFilenamePGX; it_file++)
397 // Create the right filename
398 char *filenameComponentPGX;
399 if (strlen(separator) == 0)
401 filenameComponentPGX = malloc((strlen(filename) + 1) * sizeof(*filenameComponentPGX));
402 strcpy(filenameComponentPGX, filename);
405 filenameComponentPGX = createMultiComponentsFilename(filename, it_file, separator);
407 // Read the pgx file corresponding to the component
408 image_read = pgxtoimage(filenameComponentPGX, ¶meters);
411 fprintf(stderr, "Unable to load pgx file\n");
415 // Set the image_read parameters
416 param_image_read[it_file].x0 = 0;
417 param_image_read[it_file].y0 = 0;
418 param_image_read[it_file].dx = 0;
419 param_image_read[it_file].dy = 0;
420 param_image_read[it_file].h = image_read->comps->h;
421 param_image_read[it_file].w = image_read->comps->w;
422 param_image_read[it_file].bpp = image_read->comps->bpp;
423 param_image_read[it_file].prec = image_read->comps->prec;
424 param_image_read[it_file].sgnd = image_read->comps->sgnd;
427 data[it_file] = malloc(param_image_read[it_file].h * param_image_read[it_file].w * sizeof(int));
428 memcpy(data[it_file], image_read->comps->data, image_read->comps->h * image_read->comps->w * sizeof(int));
431 opj_image_destroy(image_read);
432 free(filenameComponentPGX);
435 image = opj_image_create(nbFilenamePGX, param_image_read, CLRSPC_UNSPECIFIED);
436 for (it_file = 0; it_file < nbFilenamePGX; it_file++)
438 // Copy data into output image and free memory
439 memcpy(image->comps[it_file].data, data[it_file], image->comps[it_file].h * image->comps[it_file].w * sizeof(int));
444 free(param_image_read);
450 /*******************************************************************************
452 *******************************************************************************/
454 int imageToPNG(const opj_image_t* image, const char* filename, int num_comp_select)
456 opj_image_cmptparm_t param_image_write;
457 opj_image_t* image_write = NULL;
459 param_image_write.x0 = 0;
460 param_image_write.y0 = 0;
461 param_image_write.dx = 0;
462 param_image_write.dy = 0;
463 param_image_write.h = image->comps[num_comp_select].h;
464 param_image_write.w = image->comps[num_comp_select].w;
465 param_image_write.bpp = image->comps[num_comp_select].bpp;
466 param_image_write.prec = image->comps[num_comp_select].prec;
467 param_image_write.sgnd = image->comps[num_comp_select].sgnd;
469 image_write = opj_image_create(1, ¶m_image_write, CLRSPC_GRAY);
470 memcpy(image_write->comps->data, image->comps[num_comp_select].data, param_image_write.h * param_image_write.w * sizeof(int));
472 imagetopng(image_write, filename);
474 opj_image_destroy(image_write);
480 /*******************************************************************************
482 *******************************************************************************/
483 int main(int argc, char **argv)
485 test_cmp_parameters inParam;
488 int nbFilenamePGXbase, nbFilenamePGXtest;
489 char *filenamePNGtest= NULL, *filenamePNGbase = NULL, *filenamePNGdiff = NULL;
490 int memsizebasefilename, memsizetestfilename, memsizedifffilename;
491 int valueDiff = 0, nbPixelDiff = 0;
492 double sumDiff = 0.0;
493 // Structures to store image parameters and data
494 opj_image_t *imageBase = NULL, *imageTest = NULL, *imageDiff = NULL;
495 opj_image_cmptparm_t* param_image_diff;
497 // Get parameters from command line
498 if( parse_cmdline_cmp(argc, argv, &inParam) == EXIT_FAILURE )
500 comparePGXimages_help_display();
501 if (!inParam.tabMSEvalues) free(inParam.tabMSEvalues);
502 if (!inParam.tabPEAKvalues) free(inParam.tabPEAKvalues);
503 if (!inParam.base_filename) free(inParam.base_filename);
504 if (!inParam.test_filename) free(inParam.test_filename);
508 // Display Parameters
509 printf("******Parameters********* \n");
510 printf(" base_filename = %s\n"
511 " test_filename = %s\n"
512 " nb of Components = %d\n"
513 " Non regression test = %d\n"
514 " separator Base = %s\n"
515 " separator Test = %s\n",
516 inParam.base_filename, inParam.test_filename, inParam.nbcomp,
517 inParam.nr_flag, inParam.separator_base, inParam.separator_test);
519 if ( (inParam.tabMSEvalues != NULL) && (inParam.tabPEAKvalues != NULL))
521 printf(" MSE values = [");
522 for (it_comp = 0; it_comp < inParam.nbcomp; it_comp++)
523 printf(" %f ", inParam.tabMSEvalues[it_comp]);
525 printf(" PEAK values = [");
526 for (it_comp = 0; it_comp < inParam.nbcomp; it_comp++)
527 printf(" %f ", inParam.tabPEAKvalues[it_comp]);
529 printf(" Non-regression test = %d\n", inParam.nr_flag);
532 if (strlen(inParam.separator_base) == 0)
533 nbFilenamePGXbase = 0;
535 nbFilenamePGXbase = inParam.nbcomp;
537 if (strlen(inParam.separator_test) == 0)
538 nbFilenamePGXtest = 0;
540 nbFilenamePGXtest = inParam.nbcomp;
542 printf(" NbFilename to generate from base filename = %d\n", nbFilenamePGXbase);
543 printf(" NbFilename to generate from test filename = %d\n", nbFilenamePGXtest);
544 printf("************************* \n");
546 //----------BASELINE IMAGE--------
548 memsizebasefilename = (int)strlen(inParam.test_filename) + 1 + 5 + 2 + 4;
549 memsizetestfilename = (int)strlen(inParam.test_filename) + 1 + 5 + 2 + 4;
551 imageBase = readImageFromFilePGX( inParam.base_filename, nbFilenamePGXbase, inParam.separator_base);
552 if ( imageBase != NULL)
554 filenamePNGbase = (char*) malloc(memsizebasefilename);
555 filenamePNGbase[0] = '\0';
556 strncpy(filenamePNGbase, inParam.test_filename, strlen(inParam.test_filename));
557 filenamePNGbase[strlen(inParam.test_filename)] = '\0';
558 strcat(filenamePNGbase, ".base");
559 //printf("filenamePNGbase = %s [%d / %d octets]\n",filenamePNGbase, strlen(filenamePNGbase),memsizebasefilename );
563 if (!inParam.tabMSEvalues) free(inParam.tabMSEvalues);
564 if (!inParam.tabPEAKvalues) free(inParam.tabPEAKvalues);
565 if (!inParam.base_filename) free(inParam.base_filename);
566 if (!inParam.test_filename) free(inParam.test_filename);
570 //----------TEST IMAGE--------
573 imageTest = readImageFromFilePGX(inParam.test_filename, nbFilenamePGXtest, inParam.separator_test);
574 if ( imageTest != NULL)
576 filenamePNGtest = (char*) malloc(memsizetestfilename);
577 filenamePNGtest[0] = '\0';
578 strncpy(filenamePNGtest, inParam.test_filename, strlen(inParam.test_filename));
579 filenamePNGtest[strlen(inParam.test_filename)] = '\0';
580 strcat(filenamePNGtest, ".test");
581 //printf("filenamePNGtest = %s [%d / %d octets]\n",filenamePNGtest, strlen(filenamePNGtest),memsizetestfilename );
585 if (!inParam.tabMSEvalues) free(inParam.tabMSEvalues);
586 if (!inParam.tabPEAKvalues) free(inParam.tabPEAKvalues);
587 if (!inParam.base_filename) free(inParam.base_filename);
588 if (!inParam.test_filename) free(inParam.test_filename);
589 free(filenamePNGbase);
593 //----------DIFF IMAGE--------
597 param_image_diff = malloc( imageBase->numcomps * sizeof(opj_image_cmptparm_t));
599 // Comparison of header parameters
600 printf("Step 1 -> Header comparison\n");
602 for (it_comp = 0; it_comp < imageBase->numcomps; it_comp++)
604 param_image_diff[it_comp].x0 = 0;
605 param_image_diff[it_comp].y0 = 0;
606 param_image_diff[it_comp].dx = 0;
607 param_image_diff[it_comp].dy = 0;
609 if (imageBase->comps[it_comp].sgnd != imageTest->comps[it_comp].sgnd)
611 printf("ERROR: sign mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).sgnd, ((imageTest->comps)[it_comp]).sgnd);
615 param_image_diff[it_comp].sgnd = 0 ;
617 if (((imageBase->comps)[it_comp]).prec != ((imageTest->comps)[it_comp]).prec)
619 printf("ERROR: prec mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).prec, ((imageTest->comps)[it_comp]).prec);
623 param_image_diff[it_comp].prec = 8 ;
625 if (((imageBase->comps)[it_comp]).bpp != ((imageTest->comps)[it_comp]).bpp)
627 printf("ERROR: byte per pixel mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).bpp, ((imageTest->comps)[it_comp]).bpp);
631 param_image_diff[it_comp].bpp = 1 ;
633 if (((imageBase->comps)[it_comp]).h != ((imageTest->comps)[it_comp]).h)
635 printf("ERROR: height mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).h, ((imageTest->comps)[it_comp]).h);
639 param_image_diff[it_comp].h = imageBase->comps[it_comp].h ;
641 if (((imageBase->comps)[it_comp]).w != ((imageTest->comps)[it_comp]).w)
643 printf("ERROR: width mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).w, ((imageTest->comps)[it_comp]).w);
647 param_image_diff[it_comp].w = imageBase->comps[it_comp].w ;
650 // If only one parameter is different, we stop the test
653 free(inParam.tabMSEvalues);
654 free(inParam.tabPEAKvalues);
655 free(inParam.base_filename);
656 free(inParam.test_filename);
658 free(filenamePNGbase);
659 free(filenamePNGtest);
661 opj_image_destroy(imageBase);
662 opj_image_destroy(imageTest);
664 free(param_image_diff);
669 imageDiff = opj_image_create(imageBase->numcomps, param_image_diff, CLRSPC_UNSPECIFIED);
671 free(param_image_diff);
673 // Measurement computation
674 printf("Step 2 -> measurement comparison\n");
676 memsizedifffilename = strlen(inParam.test_filename) + 1 + 5 + 2 + 4;
677 filenamePNGdiff = (char*) malloc(memsizedifffilename);
678 filenamePNGdiff[0] = '\0';
679 strncpy(filenamePNGdiff, inParam.test_filename, strlen(inParam.test_filename));
680 filenamePNGdiff[strlen(inParam.test_filename)] = '\0';
681 strcat(filenamePNGdiff, ".diff");
682 //printf("filenamePNGdiff = %s [%d / %d octets]\n",filenamePNGdiff, strlen(filenamePNGdiff),memsizedifffilename );
684 // Compute pixel diff
685 for (it_comp = 0; it_comp < imageDiff->numcomps; it_comp++)
689 char *filenamePNGbase_it_comp, *filenamePNGtest_it_comp, *filenamePNGdiff_it_comp;
691 filenamePNGbase_it_comp = (char*) malloc(memsizebasefilename);
692 filenamePNGbase_it_comp[0] = '\0';
693 strncpy(filenamePNGbase_it_comp,filenamePNGbase,strlen(filenamePNGbase));
694 filenamePNGbase_it_comp[strlen(filenamePNGbase)] = '\0';
696 filenamePNGtest_it_comp = (char*) malloc(memsizetestfilename);
697 filenamePNGtest_it_comp[0] = '\0';
698 strncpy(filenamePNGtest_it_comp,filenamePNGtest,strlen(filenamePNGtest));
699 filenamePNGtest_it_comp[strlen(filenamePNGtest)] = '\0';
701 filenamePNGdiff_it_comp = (char*) malloc(memsizedifffilename);
702 filenamePNGdiff_it_comp[0] = '\0';
703 strncpy(filenamePNGdiff_it_comp,filenamePNGdiff,strlen(filenamePNGdiff));
704 filenamePNGdiff_it_comp[strlen(filenamePNGdiff)] = '\0';
706 for (itpxl = 0; itpxl < ((imageDiff->comps)[it_comp]).w * ((imageDiff->comps)[it_comp]).h; itpxl++)
708 if (abs( ((imageBase->comps)[it_comp]).data[itpxl] - ((imageTest->comps)[it_comp]).data[itpxl] ) > 0)
710 valueDiff = ((imageBase->comps)[it_comp]).data[itpxl] - ((imageTest->comps)[it_comp]).data[itpxl];
711 ((imageDiff->comps)[it_comp]).data[itpxl] = abs(valueDiff);
712 sumDiff += (double)valueDiff;
715 SE += (double)(valueDiff * valueDiff);
716 PEAK = (PEAK > abs(valueDiff)) ? PEAK : abs(valueDiff);
719 ((imageDiff->comps)[it_comp]).data[itpxl] = 0;
722 MSE = SE / ( ((imageDiff->comps)[it_comp]).w * ((imageDiff->comps)[it_comp]).h );
724 if (!inParam.nr_flag && (inParam.tabMSEvalues != NULL) && (inParam.tabPEAKvalues != NULL))
725 { // Conformance test
726 printf("<DartMeasurement name=\"PEAK_%d\" type=\"numeric/double\"> %f </DartMeasurement> \n", it_comp, PEAK);
727 printf("<DartMeasurement name=\"MSE_%d\" type=\"numeric/double\"> %f </DartMeasurement> \n", it_comp, MSE);
729 if ( (MSE > inParam.tabMSEvalues[it_comp]) || (PEAK > inParam.tabPEAKvalues[it_comp]) )
731 printf("ERROR: MSE (%f) or PEAK (%f) values produced by the decoded file are greater "
732 "than the allowable error (respectively %f and %f) \n",
733 MSE, PEAK, inParam.tabMSEvalues[it_comp], inParam.tabPEAKvalues[it_comp]);
737 else // Non regression-test
739 if ( nbPixelDiff > 0)
744 printf("<DartMeasurement name=\"NumberOfPixelsWithDifferences_%d\" type=\"numeric/int\"> %d </DartMeasurement> \n", it_comp, nbPixelDiff);
745 printf("<DartMeasurement name=\"ComponentError_%d\" type=\"numeric/double\"> %f </DartMeasurement> \n", it_comp, sumDiff);
748 sprintf(it_compc, "_%i", it_comp);
749 strcat(it_compc,".png");
750 strcat(filenamePNGbase_it_comp, it_compc);
751 //printf("filenamePNGbase_it = %s [%d / %d octets]\n",filenamePNGbase_it_comp, strlen(filenamePNGbase_it_comp),memsizebasefilename );
752 strcat(filenamePNGtest_it_comp, it_compc);
753 //printf("filenamePNGtest_it = %s [%d / %d octets]\n",filenamePNGtest_it_comp, strlen(filenamePNGtest_it_comp),memsizetestfilename );
754 strcat(filenamePNGdiff_it_comp, it_compc);
755 //printf("filenamePNGdiff_it = %s [%d / %d octets]\n",filenamePNGdiff_it_comp, strlen(filenamePNGdiff_it_comp),memsizedifffilename );
757 if ( imageToPNG(imageBase, filenamePNGbase_it_comp, it_comp) == EXIT_SUCCESS )
759 printf("<DartMeasurementFile name=\"BaselineImage_%d\" type=\"image/png\"> %s </DartMeasurementFile> \n", it_comp, filenamePNGbase_it_comp);
762 if ( imageToPNG(imageTest, filenamePNGtest_it_comp, it_comp) == EXIT_SUCCESS )
764 printf("<DartMeasurementFile name=\"TestImage_%d\" type=\"image/png\"> %s </DartMeasurementFile> \n", it_comp, filenamePNGtest_it_comp);
767 if ( imageToPNG(imageDiff, filenamePNGdiff_it_comp, it_comp) == EXIT_SUCCESS )
769 printf("<DartMeasurementFile name=\"DiffferenceImage_%d\" type=\"image/png\"> %s </DartMeasurementFile> \n", it_comp, filenamePNGdiff_it_comp);
775 free(filenamePNGbase_it_comp);
776 free(filenamePNGtest_it_comp);
777 free(filenamePNGdiff_it_comp);
780 //-----------------------------
782 opj_image_destroy(imageBase);
783 opj_image_destroy(imageTest);
784 opj_image_destroy(imageDiff);
786 free(filenamePNGbase);
787 free(filenamePNGtest);
788 free(filenamePNGdiff);
790 free(inParam.tabMSEvalues);
791 free(inParam.tabPEAKvalues);
792 free(inParam.base_filename);
793 free(inParam.test_filename);
799 printf("---- TEST SUCCEED ----\n");