[trunk] fix error with new way to detect kdu_expand
[openjpeg.git] / tests / comparePGXimages.c
index 7a1e8f1c319c7f6d9a4c0ee874f017a5b4d57bcc..48189156bbd41cc29c77ee638f51781aa20cc6c8 100644 (file)
@@ -1,3 +1,29 @@
+/*
+ * 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
  *
@@ -12,7 +38,7 @@
 #include <ctype.h>
 
 #include "opj_config.h"
-#include "getopt.h"
+#include "opj_getopt.h"
 
 #include "openjpeg.h"
 #include "format_defs.h"
@@ -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';
+        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';
+        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;
     }
@@ -295,7 +321,10 @@ double* parseToleranceValues( char* inArg, const int nbcomp)
     }
 
   if (it_comp != nbcomp)
+  {
+       free(outArgs);
     return NULL;
+  }
   else
     return outArgs;
 }
@@ -381,10 +410,21 @@ opj_image_t* readImageFromFilePGX(char* filename, int nbFilenamePGX, char *separ
     // 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");
+
+               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;
@@ -472,10 +512,10 @@ int main(int argc, char **argv)
   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;
     }
 
@@ -534,10 +574,10 @@ int main(int argc, char **argv)
     }
   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;
     }
 
@@ -556,10 +596,10 @@ int main(int argc, char **argv)
     }
   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;
     }