[trunk] Simplify code to centralize code cleanup

This commit is contained in:
Mathieu Malaterre 2014-02-28 14:17:30 +00:00
parent ecbebe2847
commit 82647e79c7
1 changed files with 61 additions and 89 deletions

View File

@ -502,7 +502,7 @@ int main(int argc, char **argv)
{
test_cmp_parameters inParam;
OPJ_UINT32 it_comp, itpxl;
int failed = 0;
int failed = 1;
int nbFilenamePGXbase, nbFilenamePGXtest;
char *filenamePNGtest= NULL, *filenamePNGbase = NULL, *filenamePNGdiff = NULL;
int memsizebasefilename, memsizetestfilename;
@ -511,17 +511,13 @@ int main(int argc, char **argv)
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;
opj_image_cmptparm_t* param_image_diff = NULL;
/* Get parameters from command line*/
if( parse_cmdline_cmp(argc, argv, &inParam) )
{
comparePGXimages_help_display();
free(inParam.tabMSEvalues);
free(inParam.tabPEAKvalues);
free(inParam.base_filename);
free(inParam.test_filename);
return EXIT_FAILURE;
goto cleanup;
}
/* Display Parameters*/
@ -573,17 +569,13 @@ int main(int argc, char **argv)
filenamePNGbase = (char*) malloc(memsizebasefilename);
filenamePNGbase[0] = '\0';
strncpy(filenamePNGbase, inParam.test_filename, strlen(inParam.test_filename));
filenamePNGbase[strlen(inParam.test_filename)] = '\0';
filenamePNGbase[strlen(inParam.test_filename)] = 0;
strcat(filenamePNGbase, ".base");
/*printf("filenamePNGbase = %s [%d / %d octets]\n",filenamePNGbase, strlen(filenamePNGbase),memsizebasefilename );*/
}
else
{
free(inParam.tabMSEvalues);
free(inParam.tabPEAKvalues);
free(inParam.base_filename);
free(inParam.test_filename);
return EXIT_FAILURE;
goto cleanup;
}
/*----------TEST IMAGE--------*/
@ -594,18 +586,13 @@ int main(int argc, char **argv)
filenamePNGtest = (char*) malloc(memsizetestfilename);
filenamePNGtest[0] = '\0';
strncpy(filenamePNGtest, inParam.test_filename, strlen(inParam.test_filename));
filenamePNGtest[strlen(inParam.test_filename)] = '\0';
filenamePNGtest[strlen(inParam.test_filename)] = 0;
strcat(filenamePNGtest, ".test");
/*printf("filenamePNGtest = %s [%d / %d octets]\n",filenamePNGtest, strlen(filenamePNGtest),memsizetestfilename );*/
}
else
{
free(inParam.tabMSEvalues);
free(inParam.tabPEAKvalues);
free(inParam.base_filename);
free(inParam.test_filename);
free(filenamePNGbase);
return EXIT_FAILURE;
goto cleanup;
}
/*----------DIFF IMAGE--------*/
@ -626,7 +613,7 @@ int main(int argc, char **argv)
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);
failed = 1;
goto cleanup;
}
else
param_image_diff[it_comp].sgnd = 0 ;
@ -634,7 +621,7 @@ int main(int argc, char **argv)
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);
failed = 1;
goto cleanup;
}
else
param_image_diff[it_comp].prec = 8 ;
@ -642,7 +629,7 @@ int main(int argc, char **argv)
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);
failed = 1;
goto cleanup;
}
else
param_image_diff[it_comp].bpp = 1 ;
@ -650,7 +637,7 @@ int main(int argc, char **argv)
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);
failed = 1;
goto cleanup;
}
else
param_image_diff[it_comp].h = imageBase->comps[it_comp].h ;
@ -658,43 +645,24 @@ int main(int argc, char **argv)
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);
failed = 1;
goto cleanup;
}
else
param_image_diff[it_comp].w = imageBase->comps[it_comp].w ;
}
/* If only one parameter is different, we stop the test*/
if (failed)
{
free(inParam.tabMSEvalues);
free(inParam.tabPEAKvalues);
free(inParam.base_filename);
free(inParam.test_filename);
free(filenamePNGbase);
free(filenamePNGtest);
opj_image_destroy(imageBase);
opj_image_destroy(imageTest);
free(param_image_diff);
return EXIT_FAILURE;
}
imageDiff = opj_image_create(imageBase->numcomps, param_image_diff, OPJ_CLRSPC_UNSPECIFIED);
/* Free memory*/
free(param_image_diff);
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);
filenamePNGdiff[0] = '\0';
filenamePNGdiff[0] = 0;
strncpy(filenamePNGdiff, inParam.test_filename, strlen(inParam.test_filename));
filenamePNGdiff[strlen(inParam.test_filename)] = '\0';
filenamePNGdiff[strlen(inParam.test_filename)] = 0;
strcat(filenamePNGdiff, ".diff");
/*printf("filenamePNGdiff = %s [%d / %d octets]\n",filenamePNGdiff, strlen(filenamePNGdiff),memsizedifffilename );*/
@ -703,23 +671,6 @@ int main(int argc, char **argv)
{
double SE=0,PEAK=0;
double MSE=0;
char *filenamePNGbase_it_comp, *filenamePNGtest_it_comp, *filenamePNGdiff_it_comp;
filenamePNGbase_it_comp = (char*) malloc(memsizebasefilename);
filenamePNGbase_it_comp[0] = 0;
strncpy(filenamePNGbase_it_comp,filenamePNGbase,strlen(filenamePNGbase));
filenamePNGbase_it_comp[strlen(filenamePNGbase)] = 0;
filenamePNGtest_it_comp = (char*) malloc(memsizetestfilename);
filenamePNGtest_it_comp[0] = 0;
strncpy(filenamePNGtest_it_comp,filenamePNGtest,strlen(filenamePNGtest));
filenamePNGtest_it_comp[strlen(filenamePNGtest)] = 0;
filenamePNGdiff_it_comp = (char*) malloc(memsizedifffilename);
filenamePNGdiff_it_comp[0] = 0;
strncpy(filenamePNGdiff_it_comp,filenamePNGdiff,strlen(filenamePNGdiff));
filenamePNGdiff_it_comp[strlen(filenamePNGdiff)] = 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)
@ -748,7 +699,7 @@ int main(int argc, char **argv)
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]);
failed = 1;
goto cleanup;
}
}
else /* Non regression-test */
@ -756,12 +707,31 @@ int main(int argc, char **argv)
if ( nbPixelDiff > 0)
{
char it_compc[255];
it_compc[0] = '\0';
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);
#ifdef OPJ_HAVE_LIBPNG
{
char *filenamePNGbase_it_comp, *filenamePNGtest_it_comp, *filenamePNGdiff_it_comp;
filenamePNGbase_it_comp = (char*) malloc(memsizebasefilename);
filenamePNGbase_it_comp[0] = 0;
strncpy(filenamePNGbase_it_comp,filenamePNGbase,strlen(filenamePNGbase));
filenamePNGbase_it_comp[strlen(filenamePNGbase)] = 0;
filenamePNGtest_it_comp = (char*) malloc(memsizetestfilename);
filenamePNGtest_it_comp[0] = 0;
strncpy(filenamePNGtest_it_comp,filenamePNGtest,strlen(filenamePNGtest));
filenamePNGtest_it_comp[strlen(filenamePNGtest)] = 0;
filenamePNGdiff_it_comp = (char*) malloc(memsizedifffilename);
filenamePNGdiff_it_comp[0] = 0;
strncpy(filenamePNGdiff_it_comp,filenamePNGdiff,strlen(filenamePNGdiff));
filenamePNGdiff_it_comp[strlen(filenamePNGdiff)] = 0;
sprintf(it_compc, "_%i", it_comp);
strcat(it_compc,".png");
strcat(filenamePNGbase_it_comp, it_compc);
@ -788,16 +758,21 @@ int main(int argc, char **argv)
}
*/
#endif
failed = 1;
}
}
free(filenamePNGbase_it_comp);
free(filenamePNGtest_it_comp);
free(filenamePNGdiff_it_comp);
}
#endif
goto cleanup;
}
}
} /* it_comp loop */
printf("---- TEST SUCCEED ----\n");
failed = 0;
cleanup:
/*-----------------------------*/
free(param_image_diff);
/* Free memory */
opj_image_destroy(imageBase);
opj_image_destroy(imageTest);
@ -812,8 +787,5 @@ int main(int argc, char **argv)
free(inParam.base_filename);
free(inParam.test_filename);
if (failed) return EXIT_FAILURE;
printf("---- TEST SUCCEED ----\n");
return EXIT_SUCCESS;
return failed ? EXIT_FAILURE : EXIT_SUCCESS;
}