[trunk] split into two config files config options related to the lib and to the...
[openjpeg.git] / tests / comparePGXimages.c
index dc3d938077880a5f0c8b99f07e2d9012d6277ff2..29300d51d0cf96a5b217dd70e02e6a4843400b3f 100644 (file)
@@ -1,3 +1,29 @@
+/*
+ * 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
+ * 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
  *
 #include <string.h>
 #include <ctype.h>
 
-#include "opj_config.h"
-#include "getopt.h"
+#include "opj_apps_config.h"
+#include "opj_getopt.h"
 
 #include "openjpeg.h"
 #include "format_defs.h"
 #include "convert.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
+#ifdef OPJ_HAVE_LIBPNG
 int imageToPNG(const opj_image_t* image, const char* filename, int num_comp_select);
 #endif
 
@@ -49,7 +75,7 @@ typedef struct test_cmp_parameters
 /*******************************************************************************
  * Command line help function
  *******************************************************************************/
-void comparePGXimages_help_display() {
+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");
@@ -67,7 +93,7 @@ void comparePGXimages_help_display() {
 /*******************************************************************************
  * Parse command line
  *******************************************************************************/
-int parse_cmdline_cmp(int argc, char **argv, 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;
@@ -76,7 +102,7 @@ int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
   const char optlist[] = "b:t:n:m:p:s:d";
   int c;
 
-  // Init parameters
+  /* Init parameters*/
   param->base_filename = NULL;
   param->test_filename = NULL;
   param->nbcomp = 0;
@@ -84,60 +110,60 @@ int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
   param->tabPEAKvalues = NULL;
   param->nr_flag = 0;
 
-  opterr = 0;
+  opj_opterr = 0;
 
-  while ((c = getopt(argc, argv, optlist)) != -1)
+  while ((c = opj_getopt(argc, argv, optlist)) != -1)
     switch (c)
       {
       case 'b':
-        sizemembasefile = (int)strlen(optarg)+1;
+        sizemembasefile = (int)strlen(opj_optarg)+1;
         param->base_filename = (char*) malloc(sizemembasefile);
         param->base_filename[0] = '\0';
-        strncpy(param->base_filename, optarg, strlen(optarg));
-        param->base_filename[strlen(optarg)] = '\0';
-        //printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );
+        strncpy(param->base_filename, opj_optarg, strlen(opj_optarg));
+        param->base_filename[strlen(opj_optarg)] = '\0';
+        /*printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );*/
         break;
       case 't':
-        sizememtestfile = (int) strlen(optarg) + 1;
+        sizememtestfile = (int) strlen(opj_optarg) + 1;
         param->test_filename = (char*) malloc(sizememtestfile);
         param->test_filename[0] = '\0';
-        strncpy(param->test_filename, optarg, strlen(optarg));
-        param->test_filename[strlen(optarg)] = '\0';
-        //printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);
+        strncpy(param->test_filename, opj_optarg, strlen(opj_optarg));
+        param->test_filename[strlen(opj_optarg)] = '\0';
+        /*printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);*/
        break;
       case 'n':
-        param->nbcomp = atoi(optarg);
+        param->nbcomp = atoi(opj_optarg);
         break;
       case 'm':
-        MSElistvalues = optarg;
+        MSElistvalues = opj_optarg;
         flagM = 1;
         break;
       case 'p':
-        PEAKlistvalues = optarg;
+        PEAKlistvalues = opj_optarg;
         flagP = 1;
         break;
       case 'd':
         param->nr_flag = 1;
         break;
       case 's':
-        separatorList = optarg;
+        separatorList = opj_optarg;
         break;
       case '?':
-        if ((optopt == 'b') || (optopt == 't') || (optopt == 'n') || (optopt == 'p') || (optopt == 'm') || (optopt
+        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", optopt);
+          fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt);
         else
-          if (isprint(optopt)) fprintf(stderr, "Unknown option `-%c'.\n", optopt);
-          else fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
+          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, optarg);
+        fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, opj_optarg);
         break;
       }
 
-  if (optind != argc)
+  if (opj_optind != argc)
     {
-    for (index = optind; index < argc; index++)
+    for (index = opj_optind; index < argc; index++)
       fprintf(stderr,"Non-option argument %s\n", argv[index]);
     return EXIT_FAILURE;
     }
@@ -165,24 +191,24 @@ int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
       }*/
     }
 
-  // Get separators after corresponding letter (b or t)
+  /* Get separators after corresponding letter (b or t)*/
   if (separatorList != NULL)
     {
     if( (strlen(separatorList) ==2) || (strlen(separatorList) ==4) )
       {
-      // keep original string
+      /* keep original string*/
       int sizeseplist = (int)strlen(separatorList)+1;
       char* separatorList2 = (char*)malloc( sizeseplist );
       separatorList2[0] = '\0';
       strncpy(separatorList2, separatorList, strlen(separatorList));
       separatorList2[strlen(separatorList)] = '\0';
-      //printf("separatorList2 = %s [%d / %d]\n", separatorList2, strlen(separatorList2), sizeseplist);
+      /*printf("separatorList2 = %s [%d / %d]\n", separatorList2, strlen(separatorList2), sizeseplist);*/
 
-      if (strlen(separatorList) == 2) // one separator behind b or t
+      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
+        if (strlen(resultT) == strlen(separatorList)) /* didn't find t character, try to find b*/
           {
           char *resultB = NULL;
           resultB = strtok(resultT, "b");
@@ -191,48 +217,48 @@ int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
             param->separator_base[0] = separatorList[1];param->separator_base[1] = '\0';
             param->separator_test[0] ='\0';
             }
-          else // not found b
+          else /* not found b*/
             {
             free(separatorList2);
             return EXIT_FAILURE;
             }
           }
-        else // found t
+        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) );
+        /*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
+      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
+        if (strlen(resultT) == 3) /* found t in first place*/
           {
           char *resultB = NULL;
           resultB = strtok(resultT, "b");
-          if (strlen(resultB) == 1) // found b after t
+          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
+          else /* didn't find b after t*/
             {
             free(separatorList2);
             return EXIT_FAILURE;
             }
           }
-        else // == 2, didn't find t in first place
+        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
+          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
+          else /* didn't found b in first place => problem*/
             {
             free(separatorList2);
             return EXIT_FAILURE;
@@ -241,7 +267,7 @@ int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
         }
       free(separatorList2);
       }
-    else // wrong number of argument after -s
+    else /* wrong number of argument after -s*/
       {
       return EXIT_FAILURE;
       }
@@ -295,7 +321,10 @@ double* parseToleranceValues( char* inArg, const int nbcomp)
     }
 
   if (it_comp != nbcomp)
+  {
+       free(outArgs);
     return NULL;
+  }
   else
     return outArgs;
 }
@@ -303,28 +332,28 @@ double* parseToleranceValues( char* inArg, const int nbcomp)
  * Create filenames from a filename by used separator and nb components
  * (begin to 0)
  *******************************************************************************/
-char* createMultiComponentsFilename(const char* inFilename, const int indexF, const char* separator)
+static char* createMultiComponentsFilename(const char* inFilename, const int indexF, const char* separator)
 {
   char s[255];
   char *outFilename, *ptr;
   char token = '.';
   int posToken = 0;
 
-  //printf("inFilename = %s\n", inFilename);
+  /*printf("inFilename = %s\n", inFilename);*/
   if ((ptr = strrchr(inFilename, token)) != NULL)
     {
     posToken = (int) (strlen(inFilename) - strlen(ptr));
-    //printf("Position of %c character inside inFilename = %d\n", token, posToken);
+    /*printf("Position of %c character inside inFilename = %d\n", token, posToken);*/
     }
   else
     {
-    //printf("Token %c not found\n", token);
+    /*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);
 
@@ -337,7 +366,7 @@ char* createMultiComponentsFilename(const char* inFilename, const int indexF, co
 
   strcat(outFilename, ".pgx");
 
-  //printf("outfilename: %s\n", outFilename);
+  /*printf("outfilename: %s\n", outFilename);*/
   return outFilename;
 }
 /*******************************************************************************
@@ -352,7 +381,7 @@ opj_image_t* readImageFromFilePGX(char* filename, int nbFilenamePGX, char *separ
   opj_image_cmptparm_t* param_image_read;
   int** data;
 
-  // If separator is empty => nb file to read is equal to one
+  /* If separator is empty => nb file to read is equal to one*/
   if ( strlen(separator) == 0 )
       nbFilenamePGX = 1;
 
@@ -361,14 +390,14 @@ opj_image_t* readImageFromFilePGX(char* filename, int nbFilenamePGX, char *separ
   parameters.decod_format = PGX_DFMT;
   strncpy(parameters.infile, filename, sizeof(parameters.infile)-1);
 
-  // Allocate memory
+  /* Allocate memory*/
   param_image_read = malloc(nbFilenamePGX * sizeof(opj_image_cmptparm_t));
   data = malloc(nbFilenamePGX * sizeof(*data));
 
   it_file = 0;
   for (it_file = 0; it_file < nbFilenamePGX; it_file++)
     {
-    // Create the right filename
+    /* Create the right filename*/
     char *filenameComponentPGX;
     if (strlen(separator) == 0)
       {
@@ -378,15 +407,26 @@ opj_image_t* readImageFromFilePGX(char* filename, int nbFilenamePGX, char *separ
     else
       filenameComponentPGX = createMultiComponentsFilename(filename, it_file, separator);
 
-    // Read the pgx file corresponding to the component
+    /* Read the pgx file corresponding to the component */
     image_read = pgxtoimage(filenameComponentPGX, &parameters);
     if (!image_read)
-      {
-      fprintf(stderr, "Unable to load pgx file\n");
-      return NULL;
-      }
+    {
+       int it_free_data;
+               fprintf(stderr, "Unable to load pgx file\n");
 
-    // Set the image_read parameters
+               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;
@@ -397,24 +437,24 @@ opj_image_t* readImageFromFilePGX(char* filename, int nbFilenamePGX, char *separ
     param_image_read[it_file].prec = image_read->comps->prec;
     param_image_read[it_file].sgnd = image_read->comps->sgnd;
 
-    // Copy data
+    /* 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
+    /* Free memory*/
     opj_image_destroy(image_read);
     free(filenameComponentPGX);
     }
 
-  image = opj_image_create(nbFilenamePGX, param_image_read, CLRSPC_UNSPECIFIED);
+  image = opj_image_create(nbFilenamePGX, param_image_read, OPJ_CLRSPC_UNSPECIFIED);
   for (it_file = 0; it_file < nbFilenamePGX; it_file++)
     {
-    // Copy data into output image and free memory
+    /* 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 memory*/
   free(param_image_read);
   free(data);
 
@@ -424,7 +464,7 @@ opj_image_t* readImageFromFilePGX(char* filename, int nbFilenamePGX, char *separ
 /*******************************************************************************
  *
  *******************************************************************************/
-#ifdef HAVE_LIBPNG
+#ifdef OPJ_HAVE_LIBPNG
 int imageToPNG(const opj_image_t* image, const char* filename, int num_comp_select)
 {
   opj_image_cmptparm_t param_image_write;
@@ -440,7 +480,7 @@ int imageToPNG(const opj_image_t* image, const char* filename, int num_comp_sele
   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(1, &param_image_write, CLRSPC_GRAY);
+  image_write = opj_image_create(1, &param_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);
@@ -457,29 +497,29 @@ int imageToPNG(const opj_image_t* image, const char* filename, int num_comp_sele
 int main(int argc, char **argv)
 {
   test_cmp_parameters inParam;
-  int it_comp, itpxl;
+  OPJ_UINT32 it_comp, itpxl;
   int failed = 0;
   int nbFilenamePGXbase, nbFilenamePGXtest;
   char *filenamePNGtest= NULL, *filenamePNGbase = NULL, *filenamePNGdiff = NULL;
   int memsizebasefilename, memsizetestfilename, memsizedifffilename;
   int valueDiff = 0, nbPixelDiff = 0;
   double sumDiff = 0.0;
-  // Structures to store image parameters and data
+  /* Structures to store image parameters and data*/
   opj_image_t *imageBase = NULL, *imageTest = NULL, *imageDiff = NULL;
   opj_image_cmptparm_t* param_image_diff;
 
-  // Get parameters from command line
+  /* Get parameters from command line*/
   if( parse_cmdline_cmp(argc, argv, &inParam) == EXIT_FAILURE )
     {
     comparePGXimages_help_display();
-    if (!inParam.tabMSEvalues) free(inParam.tabMSEvalues);
-    if (!inParam.tabPEAKvalues) free(inParam.tabPEAKvalues);
-    if (!inParam.base_filename) free(inParam.base_filename);
-    if (!inParam.test_filename) free(inParam.test_filename);
+    if (inParam.tabMSEvalues) free(inParam.tabMSEvalues);
+    if (inParam.tabPEAKvalues) free(inParam.tabPEAKvalues);
+    if (inParam.base_filename) free(inParam.base_filename);
+    if (inParam.test_filename) free(inParam.test_filename);
     return EXIT_FAILURE;
     }
 
-  // Display Parameters
+  /* Display Parameters*/
   printf("******Parameters********* \n");
   printf(" base_filename = %s\n"
          " test_filename = %s\n"
@@ -491,7 +531,8 @@ int main(int argc, char **argv)
          inParam.nr_flag, inParam.separator_base, inParam.separator_test);
 
   if ( (inParam.tabMSEvalues != NULL) && (inParam.tabPEAKvalues != NULL))
-  {
+    {
+    int it_comp;
     printf(" MSE values = [");
     for (it_comp = 0; it_comp < inParam.nbcomp; it_comp++)
       printf(" %f ", inParam.tabMSEvalues[it_comp]);
@@ -517,8 +558,7 @@ int main(int argc, char **argv)
   printf(" NbFilename to generate from test filename = %d\n", nbFilenamePGXtest);
   printf("************************* \n");
 
-  //----------BASELINE IMAGE--------
-  //
+  /*----------BASELINE IMAGE--------*/
   memsizebasefilename = (int)strlen(inParam.test_filename) + 1 + 5 + 2 + 4;
   memsizetestfilename = (int)strlen(inParam.test_filename) + 1 + 5 + 2 + 4;
 
@@ -530,19 +570,18 @@ int main(int argc, char **argv)
     strncpy(filenamePNGbase, inParam.test_filename, strlen(inParam.test_filename));
     filenamePNGbase[strlen(inParam.test_filename)] = '\0';
     strcat(filenamePNGbase, ".base");
-    //printf("filenamePNGbase = %s [%d / %d octets]\n",filenamePNGbase, strlen(filenamePNGbase),memsizebasefilename );
+    /*printf("filenamePNGbase = %s [%d / %d octets]\n",filenamePNGbase, strlen(filenamePNGbase),memsizebasefilename );*/
     }
   else
     {
-    if (!inParam.tabMSEvalues) free(inParam.tabMSEvalues);
-    if (!inParam.tabPEAKvalues) free(inParam.tabPEAKvalues);
-    if (!inParam.base_filename) free(inParam.base_filename);
-    if (!inParam.test_filename) free(inParam.test_filename);
+    if (inParam.tabMSEvalues) free(inParam.tabMSEvalues);
+    if (inParam.tabPEAKvalues) free(inParam.tabPEAKvalues);
+    if (inParam.base_filename) free(inParam.base_filename);
+    if (inParam.test_filename) free(inParam.test_filename);
     return EXIT_FAILURE;
     }
 
-  //----------TEST IMAGE--------
-  //
+  /*----------TEST IMAGE--------*/
 
   imageTest = readImageFromFilePGX(inParam.test_filename, nbFilenamePGXtest, inParam.separator_test);
   if ( imageTest != NULL)
@@ -552,25 +591,24 @@ int main(int argc, char **argv)
     strncpy(filenamePNGtest, inParam.test_filename, strlen(inParam.test_filename));
     filenamePNGtest[strlen(inParam.test_filename)] = '\0';
     strcat(filenamePNGtest, ".test");
-    //printf("filenamePNGtest = %s [%d / %d octets]\n",filenamePNGtest, strlen(filenamePNGtest),memsizetestfilename );
+    /*printf("filenamePNGtest = %s [%d / %d octets]\n",filenamePNGtest, strlen(filenamePNGtest),memsizetestfilename );*/
     }
   else
     {
-    if (!inParam.tabMSEvalues) free(inParam.tabMSEvalues);
-    if (!inParam.tabPEAKvalues) free(inParam.tabPEAKvalues);
-    if (!inParam.base_filename) free(inParam.base_filename);
-    if (!inParam.test_filename) free(inParam.test_filename);
+    if (inParam.tabMSEvalues) free(inParam.tabMSEvalues);
+    if (inParam.tabPEAKvalues) free(inParam.tabPEAKvalues);
+    if (inParam.base_filename) free(inParam.base_filename);
+    if (inParam.test_filename) free(inParam.test_filename);
     free(filenamePNGbase);
     return EXIT_FAILURE;
     }
 
-  //----------DIFF IMAGE--------
-  //
+  /*----------DIFF IMAGE--------*/
 
-  // Allocate memory
+  /* Allocate memory*/
   param_image_diff = malloc( imageBase->numcomps * sizeof(opj_image_cmptparm_t));
 
-  // Comparison of header parameters
+  /* Comparison of header parameters*/
   printf("Step 1 -> Header comparison\n");
 
   for (it_comp = 0; it_comp < imageBase->numcomps; it_comp++)
@@ -621,7 +659,7 @@ int main(int argc, char **argv)
       param_image_diff[it_comp].w = imageBase->comps[it_comp].w ;
     }
 
-   // If only one parameter is different, we stop the test
+   /* If only one parameter is different, we stop the test*/
    if (failed)
      {
      free(inParam.tabMSEvalues);
@@ -640,11 +678,11 @@ int main(int argc, char **argv)
      return EXIT_FAILURE;
      }
 
-   imageDiff = opj_image_create(imageBase->numcomps, param_image_diff, CLRSPC_UNSPECIFIED);
-   // Free memory
+   imageDiff = opj_image_create(imageBase->numcomps, param_image_diff, OPJ_CLRSPC_UNSPECIFIED);
+   /* Free memory*/
    free(param_image_diff);
 
-   // Measurement computation
+   /* Measurement computation*/
    printf("Step 2 -> measurement comparison\n");
 
    memsizedifffilename = strlen(inParam.test_filename) + 1 + 5 + 2 + 4;
@@ -653,9 +691,9 @@ int main(int argc, char **argv)
    strncpy(filenamePNGdiff, inParam.test_filename, strlen(inParam.test_filename));
    filenamePNGdiff[strlen(inParam.test_filename)] = '\0';
    strcat(filenamePNGdiff, ".diff");
-   //printf("filenamePNGdiff = %s [%d / %d octets]\n",filenamePNGdiff, strlen(filenamePNGdiff),memsizedifffilename );
+   /*printf("filenamePNGdiff = %s [%d / %d octets]\n",filenamePNGdiff, strlen(filenamePNGdiff),memsizedifffilename );*/
 
-   // Compute pixel diff
+   /* Compute pixel diff*/
    for (it_comp = 0; it_comp < imageDiff->numcomps; it_comp++)
      {
      double SE=0,PEAK=0;
@@ -691,12 +729,12 @@ int main(int argc, char **argv)
          }
        else
          ((imageDiff->comps)[it_comp]).data[itpxl] = 0;
-       }// h*w loop
+       }/* 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
+       { /* 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);
 
@@ -708,25 +746,25 @@ int main(int argc, char **argv)
          failed = 1;
          }
        }
-     else  // Non regression-test
+     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);
 
-#ifdef HAVE_LIBPNG
-         it_compc[0] = '\0';
+#ifdef OPJ_HAVE_LIBPNG
          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 );
+         /*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 );
+         /*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 );
+         /*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 )
            {
@@ -749,10 +787,10 @@ int main(int argc, char **argv)
      free(filenamePNGbase_it_comp);
      free(filenamePNGtest_it_comp);
      free(filenamePNGdiff_it_comp);
-     } // it_comp loop
+     } /* it_comp loop */
 
-  //-----------------------------
-  // Free memory
+  /*-----------------------------*/
+  /* Free memory */
   opj_image_destroy(imageBase);
   opj_image_destroy(imageTest);
   opj_image_destroy(imageDiff);