fixed a segfault with fgets return value for some cases inside test function compare_...
[openjpeg.git] / tests / comparePGXimages.c
index ad3b58fba1046eca6de6d7404d6d820b5ad92fea..7839e299d5867352bfdd778a9216750c0770aafd 100644 (file)
@@ -1,5 +1,31 @@
 /*
- * compareImagesPGX2.c
+ * Copyright (c) 2011, Mickael Savinaud, Communications & Systemes <mickael.savinaud@c-s.fr>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * comparePGXimages.c
  *
  *  Created on: 8 juil. 2011
  *      Author: mickael
@@ -9,8 +35,7 @@
 #include <stdlib.h>
 #include <math.h>
 #include <string.h>
-
-//#include <unistd.h>
+#include <ctype.h>
 
 #include "opj_config.h"
 #include "getopt.h"
 #include "format_defs.h"
 #include "convert.h"
 
-//#include "commonTesting.h"
-
 double* parseToleranceValues( char* inArg, const int nbcomp);
-void comparePGXimages_help_display();
+void comparePGXimages_help_display(void);
 opj_image_t* readImageFromFilePGX(char* filename, int nbFilenamePGX, char *separator);
 #ifdef HAVE_LIBPNG
 int imageToPNG(const opj_image_t* image, const char* filename, int num_comp_select);
@@ -49,7 +72,10 @@ typedef struct test_cmp_parameters
 
 } test_cmp_parameters;
 
-void comparePGXimages_help_display() {
+/*******************************************************************************
+ * Command line help function
+ *******************************************************************************/
+void comparePGXimages_help_display(void) {
   fprintf(stdout,"\nList of parameters for the comparePGX function  \n");
   fprintf(stdout,"\n");
   fprintf(stdout,"  -b \t REQUIRED \t filename to the reference/baseline PGX image \n");
@@ -319,6 +345,8 @@ char* createMultiComponentsFilename(const char* inFilename, const int indexF, co
   else
     {
     //printf("Token %c not found\n", token);
+    outFilename = (char*)malloc(1);
+    outFilename[0] = '\0';
     return outFilename;
     }
 
@@ -657,7 +685,7 @@ int main(int argc, char **argv)
    for (it_comp = 0; it_comp < imageDiff->numcomps; it_comp++)
      {
      double SE=0,PEAK=0;
-     double MSE=0,PSNR=0;
+     double MSE=0;
      char *filenamePNGbase_it_comp, *filenamePNGtest_it_comp, *filenamePNGdiff_it_comp;
 
      filenamePNGbase_it_comp = (char*) malloc(memsizebasefilename);
@@ -711,12 +739,12 @@ int main(int argc, char **argv)
        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);
 
 #ifdef HAVE_LIBPNG
-         it_compc[0] = '\0';
          sprintf(it_compc, "_%i", it_comp);
          strcat(it_compc,".png");
          strcat(filenamePNGbase_it_comp, it_compc);