]> granicus.if.org Git - openjpeg/commitdiff
add new decode tests based on conformance data and tolerance. Non regression is also...
authorMickael Savinaud <savmickael@users.noreply.github.com>
Thu, 21 Jul 2011 15:23:31 +0000 (15:23 +0000)
committerMickael Savinaud <savmickael@users.noreply.github.com>
Thu, 21 Jul 2011 15:23:31 +0000 (15:23 +0000)
CHANGES
CMakeLists.txt
applications/codec/CMakeLists.txt
tests/CMakeLists.txt [new file with mode: 0644]
tests/comparePGXimages.c [new file with mode: 0644]
tests/conformance/CMakeLists.txt [new file with mode: 0644]
thirdparty/CMakeLists.txt

diff --git a/CHANGES b/CHANGES
index f6b0ae06d76c25da2d97869cb67b29a72fcce165..5ef91e23b22fd86fee04b8e048248e3a79473cd9 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,9 +6,8 @@ What's New for OpenJPEG
 + : added
 
 July 21, 2011
+!+ [mickael] add new decode tests based on conformance data and tolerance. Non regression is also added on the decoder output. Deactivate old tests.
 ! [mickael] to follow last version of conformance data about component separator for pgx file, we changed - to _ separator even if nb component = 1
-
-July 21, 2011
 ! [mickael] removed unused warning configuration message
 
 July 18, 2011
index 032b8ab44a18b2689c9e33d3d192d7bc57e8a04a..4fcbca9ce18bff3dbe4de64ba8c21529723de618 100644 (file)
@@ -203,14 +203,6 @@ IF(NOT HAVE_UNISTD_H_FOUND STREQUAL "HAVE_UNISTD_H_FOUND-NOTFOUND")
   SET(HAS_UNISTD_H 1)
 ENDIF()
 
-#-----------------------------------------------------------------------------
-# CDash+CMake : to be updated
-OPTION(BUILD_TESTING "Build the tests." OFF)
-IF(BUILD_TESTING)
-  ENABLE_TESTING()
-  INCLUDE(CTest)
-ENDIF(BUILD_TESTING)
-
 #-----------------------------------------------------------------------------
 # Build Library
 INCLUDE_DIRECTORIES(BEFORE ${OPENJPEG_BINARY_DIR})
@@ -242,6 +234,27 @@ OPTION(BUILD_JPWL "Build the JPWL library and executables" OFF)
 # Build DOCUMENTATION (not in ALL target and only if Doxygen is found)
 ADD_SUBDIRECTORY(doc)
 
+#-----------------------------------------------------------------------------
+# Buld Testing
+OPTION(BUILD_TESTING "Build the tests." OFF)
+IF(BUILD_TESTING)
+  IF(BUILD_CODEC)
+    ENABLE_TESTING()
+    INCLUDE(CTest)
+  
+    # Add repository where to find tests
+    ADD_SUBDIRECTORY(tests)
+  
+    # Search openjpeg data needed for the tests
+    # They could be found via svn on the OpenJPEG google code project
+    # svn checkout http://openjpeg.googlecode.com/svn/data (about 70 Mo) 
+    FIND_PATH(OPJ_DATA_ROOT README-OPJ-Data 
+              PATHS $ENV{OPJ_DATA_ROOT} ${CMAKE_SOURCE_DIR}/../opj-data)
+  ELSE(BUILD_CODEC)
+    message(FATAL_ERROR "You need build codec to run the tests")
+  ENDIF(BUILD_CODEC)
+ENDIF(BUILD_TESTING)
+
 #-----------------------------------------------------------------------------
 # Tests data
 IF(BUILD_TESTING)
index e39f41f30c8b23a6dcf8a84cfa10f24daf99b847..f56ee0b556cf5b92a1fed09ae458b4c8e2f4197a 100644 (file)
@@ -101,38 +101,38 @@ IF(BUILD_JPWL)
   )
 ENDIF(BUILD_JPWL)
 
-if(BUILD_TESTING)
-# Do testing here, once we know the examples are being built:
-FILE(GLOB_RECURSE OPENJPEG_DATA_IMAGES_GLOB
-  "${JPEG2000_CONFORMANCE_DATA_ROOT}/*.j2k"
-  "${JPEG2000_CONFORMANCE_DATA_ROOT}/*.j2c"
-  "${JPEG2000_CONFORMANCE_DATA_ROOT}/*.jp2"
-  )
+#if(BUILD_TESTING)
+## Do testing here, once we know the examples are being built:
+#FILE(GLOB_RECURSE OPENJPEG_DATA_IMAGES_GLOB
+#  "${JPEG2000_CONFORMANCE_DATA_ROOT}/*.j2k"
+#  "${JPEG2000_CONFORMANCE_DATA_ROOT}/*.j2c"
+#  "${JPEG2000_CONFORMANCE_DATA_ROOT}/*.jp2"
+#  )
 
-foreach(filename ${OPENJPEG_DATA_IMAGES_GLOB})
-  get_filename_component(filename_temp ${filename} NAME)
-  get_filename_component(filename_ext ${filename} EXT)
-  execute_process(COMMAND ${EXECUTABLE_OUTPUT_PATH}/j2k_dump -i ${filename}
-    OUTPUT_VARIABLE dump_success
-    OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/${filename_temp}.dump
-    ERROR_QUIET
-  )
-  if(dump_success)
-  file(READ ${CMAKE_CURRENT_BINARY_DIR}/${filename_temp}.dump numcomp_file)
-  string(REGEX REPLACE ".*numcomps=([0-9]+).*" "\\1"
-    numcomps "${numcomp_file}")
-  #message( "found:${output_variable} for ${filename_temp}" )
-  endif()
-  ADD_TEST(dump-${filename_temp} ${EXECUTABLE_OUTPUT_PATH}/j2k_dump -i ${filename})
-  foreach(codec_type ppm pgx bmp tif raw tga png)
-    ADD_TEST(j2i-${filename_temp}-${codec_type} ${EXECUTABLE_OUTPUT_PATH}/j2k_to_image -i ${filename} -o ${filename_temp}.${codec_type})
-  endforeach(codec_type)
-  foreach(codec_type ppm bmp tif tga png)
-    ADD_TEST(i2j-${filename_temp}-${codec_type} ${EXECUTABLE_OUTPUT_PATH}/image_to_j2k -i ${filename_temp}.${codec_type} -o ${filename_temp}.${codec_type}${filename_ext})
-    SET_TESTS_PROPERTIES(i2j-${filename_temp}-${codec_type} PROPERTIES DEPENDS j2i-${filename_temp}-${codec_type})
-    #if(UNIX)
-    #  ADD_TEST(cmp-${filename_temp}-${codec_type} cmp ${filename} ${filename_temp}.${codec_type}${filename_ext})
-    #endif(UNIX)
-  endforeach(codec_type)
-endforeach(filename)
-endif(BUILD_TESTING)
+#foreach(filename ${OPENJPEG_DATA_IMAGES_GLOB})
+#  get_filename_component(filename_temp ${filename} NAME)
+#  get_filename_component(filename_ext ${filename} EXT)
+#  execute_process(COMMAND ${EXECUTABLE_OUTPUT_PATH}/j2k_dump -i ${filename}
+#    OUTPUT_VARIABLE dump_success
+#    OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/${filename_temp}.dump
+#    ERROR_QUIET
+#  )
+#  if(dump_success)
+#  file(READ ${CMAKE_CURRENT_BINARY_DIR}/${filename_temp}.dump numcomp_file)
+#  string(REGEX REPLACE ".*numcomps=([0-9]+).*" "\\1"
+#    numcomps "${numcomp_file}")
+#  #message( "found:${output_variable} for ${filename_temp}" )
+#  endif()
+#  ADD_TEST(dump-${filename_temp} ${EXECUTABLE_OUTPUT_PATH}/j2k_dump -i ${filename})
+#  foreach(codec_type ppm pgx bmp tif raw tga png)
+#    ADD_TEST(j2i-${filename_temp}-${codec_type} ${EXECUTABLE_OUTPUT_PATH}/j2k_to_image -i ${filename} -o ${filename_temp}.${codec_type})
+#  endforeach(codec_type)
+#  foreach(codec_type ppm bmp tif tga png)
+#    ADD_TEST(i2j-${filename_temp}-${codec_type} ${EXECUTABLE_OUTPUT_PATH}/image_to_j2k -i ${filename_temp}.${codec_type} -o ${filename_temp}.${codec_type}${filename_ext})
+#    SET_TESTS_PROPERTIES(i2j-${filename_temp}-${codec_type} PROPERTIES DEPENDS j2i-${filename_temp}-${codec_type})
+#    #if(UNIX)
+#    #  ADD_TEST(cmp-${filename_temp}-${codec_type} cmp ${filename} ${filename_temp}.${codec_type}${filename_ext})
+#    #endif(UNIX)
+#  endforeach(codec_type)
+#endforeach(filename)
+#endif(BUILD_TESTING)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..29879b8
--- /dev/null
@@ -0,0 +1,31 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+INCLUDE_DIRECTORIES(${OPENJPEG_SOURCE_DIR}/libopenjpeg
+                    ${OPENJPEG_SOURCE_DIR}/applications/codec
+                    ${OPENJPEG_SOURCE_DIR}/applications/common
+                    )
+
+# First thing define the common source:
+SET(comparePGXimages_SRCS comparePGXimages.c ${OPENJPEG_SOURCE_DIR}/applications/codec/convert.c)
+
+# If not getopt was found then add it to the exe:
+IF(DONT_HAVE_GETOPT)
+  message("dont have getopt, we will add it")
+  SET(common_SRCS
+    ${common_SRCS}
+    ${OPENJPEG_SOURCE_DIR}/applications/common/getopt.c
+  )
+ENDIF(DONT_HAVE_GETOPT)
+
+ADD_EXECUTABLE(comparePGXimages ${comparePGXimages_SRCS})
+TARGET_LINK_LIBRARIES(comparePGXimages ${OPENJPEG_LIBRARY_NAME}
+                                        ${PNG_LIBNAME}
+                                        ${TIFF_LIBNAME}
+                                        )
+
+# No image send to the dashboard if lib PNG is not available.
+IF(NOT HAVE_LIBPNG)
+  MESSAGE(WARNING "Lib PNG seems to be not available: if you want run the non-regression tests with images reported to the dashboard, you need it (try BUILD_THIRDPARTY)") 
+ENDIF(NOT HAVE_LIBPNG)
+
+ADD_SUBDIRECTORY(conformance)
\ No newline at end of file
diff --git a/tests/comparePGXimages.c b/tests/comparePGXimages.c
new file mode 100644 (file)
index 0000000..ad3b58f
--- /dev/null
@@ -0,0 +1,774 @@
+/*
+ * compareImagesPGX2.c
+ *
+ *  Created on: 8 juil. 2011
+ *      Author: mickael
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <string.h>
+
+//#include <unistd.h>
+
+#include "opj_config.h"
+#include "getopt.h"
+
+#include "openjpeg.h"
+#include "format_defs.h"
+#include "convert.h"
+
+//#include "commonTesting.h"
+
+double* parseToleranceValues( char* inArg, const int nbcomp);
+void comparePGXimages_help_display();
+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);
+#endif
+
+typedef struct test_cmp_parameters
+{
+  /**  */
+  char* base_filename;
+  /**  */
+  char* test_filename;
+  /** Number of components */
+  int nbcomp;
+  /**  */
+  double* tabMSEvalues;
+  /**  */
+  double* tabPEAKvalues;
+  /**  */
+  int nr_flag;
+  /**  */
+  char separator_base[2];
+  /**  */
+  char separator_test[2];
+
+} test_cmp_parameters;
+
+void comparePGXimages_help_display() {
+  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");
+  fprintf(stdout,"  -t \t REQUIRED \t filename to the test PGX image\n");
+  fprintf(stdout,"  -n \t REQUIRED \t number of component of the image (used to generate correct filename)\n");
+  fprintf(stdout,"  -m \t OPTIONAL \t list of MSE tolerances, separated by : (size must correspond to the number of component) of \n");
+  fprintf(stdout,"  -p \t OPTIONAL \t list of PEAK tolerances, separated by : (size must correspond to the number of component) \n");
+  fprintf(stdout,"  -s \t OPTIONAL \t 1 or 2 filename separator to take into account PGX image with different components, "
+                                      "please indicate b or t before separator to indicate respectively the separator "
+                                      "for ref/base file and for test file.  \n");
+  fprintf(stdout,"  -r \t OPTIONAL \t indicate if you want to run this function as conformance test or as non regression test\n");
+  fprintf(stdout,"\n");
+}
+
+/*******************************************************************************
+ * Parse command line
+ *******************************************************************************/
+int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
+{
+  char *MSElistvalues = NULL;  char *PEAKlistvalues= NULL;
+  char *separatorList = NULL;
+  int sizemembasefile, sizememtestfile;
+  int index, flagM=0, flagP=0;
+  const char optlist[] = "b:t:n:m:p:s:d";
+  int c;
+
+  // Init parameters
+  param->base_filename = NULL;
+  param->test_filename = NULL;
+  param->nbcomp = 0;
+  param->tabMSEvalues = NULL;
+  param->tabPEAKvalues = NULL;
+  param->nr_flag = 0;
+
+  opterr = 0;
+
+  while ((c = getopt(argc, argv, optlist)) != -1)
+    switch (c)
+      {
+      case 'b':
+        sizemembasefile = (int)strlen(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 );
+        break;
+      case 't':
+        sizememtestfile = (int) strlen(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);
+       break;
+      case 'n':
+        param->nbcomp = atoi(optarg);
+        break;
+      case 'm':
+        MSElistvalues = optarg;
+        flagM = 1;
+        break;
+      case 'p':
+        PEAKlistvalues = optarg;
+        flagP = 1;
+        break;
+      case 'd':
+        param->nr_flag = 1;
+        break;
+      case 's':
+        separatorList = optarg;
+        break;
+      case '?':
+        if ((optopt == 'b') || (optopt == 't') || (optopt == 'n') || (optopt == 'p') || (optopt == 'm') || (optopt
+            == 's'))
+          fprintf(stderr, "Option -%c requires an argument.\n", optopt);
+        else
+          if (isprint(optopt)) fprintf(stderr, "Unknown option `-%c'.\n", optopt);
+          else fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
+        return 1;
+      default:
+        fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, optarg);
+        break;
+      }
+
+  if (optind != argc)
+    {
+    for (index = optind; index < argc; index++)
+      fprintf(stderr,"Non-option argument %s\n", argv[index]);
+    return EXIT_FAILURE;
+    }
+
+  if (param->nbcomp == 0)
+    {
+    fprintf(stderr,"Need to indicate the number of components !\n");
+    return EXIT_FAILURE;
+    }
+  else
+    {
+    if ( flagM && flagP )
+      {
+      param->tabMSEvalues = parseToleranceValues( MSElistvalues, param->nbcomp);
+      param->tabPEAKvalues = parseToleranceValues( PEAKlistvalues, param->nbcomp);
+      if ( (param->tabMSEvalues == NULL) || (param->tabPEAKvalues == NULL))
+        {
+        fprintf(stderr,"MSE and PEAK values are not correct (respectively need %d values)\n",param->nbcomp);
+        return EXIT_FAILURE;
+        }
+      }
+    /*else
+      {
+
+      }*/
+    }
+
+  // Get separators after corresponding letter (b or t)
+  if (separatorList != NULL)
+    {
+    if( (strlen(separatorList) ==2) || (strlen(separatorList) ==4) )
+      {
+      // 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);
+
+      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
+          {
+          char *resultB = NULL;
+          resultB = strtok(resultT, "b");
+          if (strlen(resultB) == 1)
+            {
+            param->separator_base[0] = separatorList[1];param->separator_base[1] = '\0';
+            param->separator_test[0] ='\0';
+            }
+          else // not found b
+            {
+            free(separatorList2);
+            return EXIT_FAILURE;
+            }
+          }
+        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) );
+        }
+      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
+          {
+          char *resultB = NULL;
+          resultB = strtok(resultT, "b");
+          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
+            {
+            free(separatorList2);
+            return EXIT_FAILURE;
+            }
+          }
+        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
+            {
+            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
+            {
+            free(separatorList2);
+            return EXIT_FAILURE;
+            }
+          }
+        }
+      free(separatorList2);
+      }
+    else // wrong number of argument after -s
+      {
+      return EXIT_FAILURE;
+      }
+    }
+  else
+    {
+    if (param->nbcomp == 1)
+      {
+      param->separator_base[0] = '\0';
+      param->separator_test[0] = '\0';
+      }
+    else
+      {
+      fprintf(stderr,"If number of component is > 1, we need separator\n");
+      return EXIT_FAILURE;
+      }
+    }
+
+
+  if ( (param->nr_flag) && (flagP || flagM) )
+    {
+    fprintf(stderr,"Wrong input parameters list: it is non-regression test or tolerance comparison\n");
+    return EXIT_FAILURE;
+    }
+  if ( (!param->nr_flag) && (!flagP || !flagM) )
+    {
+    fprintf(stderr,"Wrong input parameters list: it is non-regression test or tolerance comparison\n");
+    return EXIT_FAILURE;
+    }
+
+  return EXIT_SUCCESS;
+}
+
+/*******************************************************************************
+ * Parse MSE and PEAK input values (
+ * separator = ":"
+ *******************************************************************************/
+double* parseToleranceValues( char* inArg, const int nbcomp)
+{
+  double* outArgs= malloc(nbcomp * sizeof(double));
+  int it_comp = 0;
+  char delims[] = ":";
+  char *result = NULL;
+  result = strtok( inArg, delims );
+
+  while( (result != NULL) && (it_comp < nbcomp ))
+    {
+      outArgs[it_comp] = atof(result);
+      result = strtok( NULL, delims );
+      it_comp++;
+    }
+
+  if (it_comp != nbcomp)
+    return NULL;
+  else
+    return outArgs;
+}
+/*******************************************************************************
+ * 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)
+{
+  char s[255];
+  char *outFilename, *ptr;
+  char token = '.';
+  int posToken = 0;
+
+  //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);
+    }
+  else
+    {
+    //printf("Token %c not found\n", token);
+    return outFilename;
+    }
+
+  outFilename = (char*)malloc((posToken + 7) * sizeof(char)); //6
+
+  strncpy(outFilename, inFilename, posToken);
+
+  outFilename[posToken] = '\0';
+
+  strcat(outFilename, separator);
+
+  sprintf(s, "%i", indexF);
+  strcat(outFilename, s);
+
+  strcat(outFilename, ".pgx");
+
+  //printf("outfilename: %s\n", outFilename);
+  return outFilename;
+}
+/*******************************************************************************
+ *
+ *******************************************************************************/
+opj_image_t* readImageFromFilePGX(char* filename, int nbFilenamePGX, char *separator)
+{
+  int it_file;
+  opj_image_t* image_read = NULL;
+  opj_image_t* image = NULL;
+  opj_cparameters_t parameters;
+  opj_image_cmptparm_t* param_image_read;
+  int** data;
+
+  // If separator is empty => nb file to read is equal to one
+  if ( strlen(separator) == 0 )
+      nbFilenamePGX = 1;
+
+  /* set encoding parameters to default values */
+  opj_set_default_encoder_parameters(&parameters);
+  parameters.decod_format = PGX_DFMT;
+  strncpy(parameters.infile, filename, sizeof(parameters.infile)-1);
+
+  // 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
+    char *filenameComponentPGX;
+    if (strlen(separator) == 0)
+      {
+      filenameComponentPGX = malloc((strlen(filename) + 1) * sizeof(*filenameComponentPGX));
+      strcpy(filenameComponentPGX, filename);
+      }
+    else
+      filenameComponentPGX = createMultiComponentsFilename(filename, it_file, separator);
+
+    // 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;
+      }
+
+    // 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;
+    param_image_read[it_file].dy = 0;
+    param_image_read[it_file].h = image_read->comps->h;
+    param_image_read[it_file].w = image_read->comps->w;
+    param_image_read[it_file].bpp = image_read->comps->bpp;
+    param_image_read[it_file].prec = image_read->comps->prec;
+    param_image_read[it_file].sgnd = image_read->comps->sgnd;
+
+    // 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
+    opj_image_destroy(image_read);
+    free(filenameComponentPGX);
+    }
+
+  image = opj_image_create(nbFilenamePGX, param_image_read, CLRSPC_UNSPECIFIED);
+  for (it_file = 0; it_file < nbFilenamePGX; it_file++)
+    {
+    // 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(param_image_read);
+  free(data);
+
+  return image;
+}
+
+/*******************************************************************************
+ *
+ *******************************************************************************/
+#ifdef HAVE_LIBPNG
+int imageToPNG(const opj_image_t* image, const char* filename, int num_comp_select)
+{
+  opj_image_cmptparm_t param_image_write;
+  opj_image_t* image_write = NULL;
+
+  param_image_write.x0 = 0;
+  param_image_write.y0 = 0;
+  param_image_write.dx = 0;
+  param_image_write.dy = 0;
+  param_image_write.h = image->comps[num_comp_select].h;
+  param_image_write.w = image->comps[num_comp_select].w;
+  param_image_write.bpp = image->comps[num_comp_select].bpp;
+  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);
+  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);
+
+  opj_image_destroy(image_write);
+
+  return EXIT_SUCCESS;
+}
+#endif
+
+/*******************************************************************************
+ * MAIN
+ *******************************************************************************/
+int main(int argc, char **argv)
+{
+  test_cmp_parameters inParam;
+  int 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
+  opj_image_t *imageBase = NULL, *imageTest = NULL, *imageDiff = NULL;
+  opj_image_cmptparm_t* param_image_diff;
+
+  // 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);
+    return EXIT_FAILURE;
+    }
+
+  // Display Parameters
+  printf("******Parameters********* \n");
+  printf(" base_filename = %s\n"
+         " test_filename = %s\n"
+         " nb of Components = %d\n"
+         " Non regression test = %d\n"
+         " separator Base = %s\n"
+         " separator Test = %s\n",
+         inParam.base_filename, inParam.test_filename, inParam.nbcomp,
+         inParam.nr_flag, inParam.separator_base, inParam.separator_test);
+
+  if ( (inParam.tabMSEvalues != NULL) && (inParam.tabPEAKvalues != NULL))
+  {
+    printf(" MSE values = [");
+    for (it_comp = 0; it_comp < inParam.nbcomp; it_comp++)
+      printf(" %f ", inParam.tabMSEvalues[it_comp]);
+    printf("]\n");
+    printf(" PEAK values = [");
+    for (it_comp = 0; it_comp < inParam.nbcomp; it_comp++)
+      printf(" %f ", inParam.tabPEAKvalues[it_comp]);
+    printf("]\n");
+    printf(" Non-regression test = %d\n", inParam.nr_flag);
+    }
+
+  if (strlen(inParam.separator_base) == 0)
+    nbFilenamePGXbase = 0;
+  else
+    nbFilenamePGXbase = inParam.nbcomp;
+
+  if (strlen(inParam.separator_test) == 0)
+    nbFilenamePGXtest = 0;
+  else
+    nbFilenamePGXtest = inParam.nbcomp;
+
+  printf(" NbFilename to generate from base filename = %d\n", nbFilenamePGXbase);
+  printf(" NbFilename to generate from test filename = %d\n", nbFilenamePGXtest);
+  printf("************************* \n");
+
+  //----------BASELINE IMAGE--------
+  //
+  memsizebasefilename = (int)strlen(inParam.test_filename) + 1 + 5 + 2 + 4;
+  memsizetestfilename = (int)strlen(inParam.test_filename) + 1 + 5 + 2 + 4;
+
+  imageBase = readImageFromFilePGX( inParam.base_filename, nbFilenamePGXbase, inParam.separator_base);
+  if ( imageBase != NULL)
+    {
+    filenamePNGbase = (char*) malloc(memsizebasefilename);
+    filenamePNGbase[0] = '\0';
+    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 );
+    }
+  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);
+    return EXIT_FAILURE;
+    }
+
+  //----------TEST IMAGE--------
+  //
+
+  imageTest = readImageFromFilePGX(inParam.test_filename, nbFilenamePGXtest, inParam.separator_test);
+  if ( imageTest != NULL)
+    {
+    filenamePNGtest = (char*) malloc(memsizetestfilename);
+    filenamePNGtest[0] = '\0';
+    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 );
+    }
+  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);
+    free(filenamePNGbase);
+    return EXIT_FAILURE;
+    }
+
+  //----------DIFF IMAGE--------
+  //
+
+  // Allocate memory
+  param_image_diff = malloc( imageBase->numcomps * sizeof(opj_image_cmptparm_t));
+
+  // Comparison of header parameters
+  printf("Step 1 -> Header comparison\n");
+
+  for (it_comp = 0; it_comp < imageBase->numcomps; it_comp++)
+    {
+    param_image_diff[it_comp].x0 = 0;
+    param_image_diff[it_comp].y0 = 0;
+    param_image_diff[it_comp].dx = 0;
+    param_image_diff[it_comp].dy = 0;
+
+    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;
+      }
+    else
+      param_image_diff[it_comp].sgnd = 0 ;
+
+    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;
+      }
+    else
+      param_image_diff[it_comp].prec = 8 ;
+
+    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;
+      }
+    else
+      param_image_diff[it_comp].bpp = 1 ;
+
+    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;
+      }
+    else
+      param_image_diff[it_comp].h = imageBase->comps[it_comp].h ;
+
+    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;
+      }
+    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, CLRSPC_UNSPECIFIED);
+   // Free memory
+   free(param_image_diff);
+
+   // Measurement computation
+   printf("Step 2 -> measurement comparison\n");
+
+   memsizedifffilename = strlen(inParam.test_filename) + 1 + 5 + 2 + 4;
+   filenamePNGdiff = (char*) malloc(memsizedifffilename);
+   filenamePNGdiff[0] = '\0';
+   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 );
+
+   // Compute pixel diff
+   for (it_comp = 0; it_comp < imageDiff->numcomps; it_comp++)
+     {
+     double SE=0,PEAK=0;
+     double MSE=0,PSNR=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)
+         {
+         valueDiff = ((imageBase->comps)[it_comp]).data[itpxl] - ((imageTest->comps)[it_comp]).data[itpxl];
+         ((imageDiff->comps)[it_comp]).data[itpxl] = abs(valueDiff);
+         sumDiff += (double)valueDiff;
+         nbPixelDiff++;
+
+         SE += (double)(valueDiff * valueDiff);
+         PEAK = (PEAK > abs(valueDiff)) ? PEAK : abs(valueDiff);
+         }
+       else
+         ((imageDiff->comps)[it_comp]).data[itpxl] = 0;
+       }// 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
+       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);
+
+       if ( (MSE > inParam.tabMSEvalues[it_comp]) || (PEAK > inParam.tabPEAKvalues[it_comp]) )
+         {
+         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;
+         }
+       }
+     else  // Non regression-test
+       {
+       if ( nbPixelDiff > 0)
+         {
+         char it_compc[255];
+
+         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);
+         //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 );
+         strcat(filenamePNGdiff_it_comp, it_compc);
+         //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 )
+           {
+           printf("<DartMeasurementFile name=\"BaselineImage_%d\" type=\"image/png\"> %s </DartMeasurementFile> \n", it_comp, filenamePNGbase_it_comp);
+           }
+
+         if ( imageToPNG(imageTest, filenamePNGtest_it_comp, it_comp) == EXIT_SUCCESS )
+           {
+           printf("<DartMeasurementFile name=\"TestImage_%d\" type=\"image/png\"> %s </DartMeasurementFile> \n", it_comp, filenamePNGtest_it_comp);
+           }
+
+         if ( imageToPNG(imageDiff, filenamePNGdiff_it_comp, it_comp) == EXIT_SUCCESS )
+           {
+           printf("<DartMeasurementFile name=\"DiffferenceImage_%d\" type=\"image/png\"> %s </DartMeasurementFile> \n", it_comp, filenamePNGdiff_it_comp);
+           }
+#endif
+         failed = 1;
+         }
+       }
+     free(filenamePNGbase_it_comp);
+     free(filenamePNGtest_it_comp);
+     free(filenamePNGdiff_it_comp);
+     } // it_comp loop
+
+  //-----------------------------
+  // Free memory
+  opj_image_destroy(imageBase);
+  opj_image_destroy(imageTest);
+  opj_image_destroy(imageDiff);
+
+  free(filenamePNGbase);
+  free(filenamePNGtest);
+  free(filenamePNGdiff);
+
+  free(inParam.tabMSEvalues);
+  free(inParam.tabPEAKvalues);
+  free(inParam.base_filename);
+  free(inParam.test_filename);
+
+  if (failed)
+    return EXIT_FAILURE;
+  else
+    {
+    printf("---- TEST SUCCEED ----\n");
+    return EXIT_SUCCESS;
+    }
+}
diff --git a/tests/conformance/CMakeLists.txt b/tests/conformance/CMakeLists.txt
new file mode 100644 (file)
index 0000000..600b9bb
--- /dev/null
@@ -0,0 +1,420 @@
+# CONFORMANCE TESTS AND NON-REGRESSION ON THIS DATASET
+
+FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Temporary)
+
+SET(TEMP ${CMAKE_CURRENT_BINARY_DIR}/Temporary)
+SET(BASELINE_CONF ${OPJ_DATA_ROOT}/baseline/conformance)
+SET(BASELINE_NR ${OPJ_DATA_ROOT}/baseline/nonregression)
+SET(INPUT_CONF ${OPJ_DATA_ROOT}/input/conformance)
+
+
+# List of components by file (normaly p0_13.j2k have 257 components but for this 
+#set of test we consider only 4)
+SET( CP0_nbC_list "not_used;1;1;1;3;4;4;3;3;1;3;1;1;4;3;1;1")
+SET( CP1_nbC_list "not_used;1;3;4;1;3;3;2")
+
+SET(COMMENTCODEVAR FALSE)
+
+
+#--------------------------------------------------------------------------
+# Tests about class 0 profile 0
+# try to decode
+# compare to ref file provided by the Executable Test Suite
+# non regression comparison
+
+# Parameters and tolerances given by Table C.1
+SET( C0P0_ResFactor_list "not_used;0;0;0;3;3;3;0;5;2;0;0;0;0;2;0;0")
+SET( C0P0_PEAK_list "not_used;0;0;0;33;54;109;10;7;4;10;0;0;0;0;0;0")
+SET( C0P0_MSE_list "not_used;0;0;0;55.8;68;743;0.34;6.72;1.47;2.84;0;0;0;0;0;0")
+
+FOREACH(numFileC0P0 RANGE 1 16) 
+
+  # Build filenames
+  IF(${numFileC0P0} LESS 10)
+    SET( filenameInput p0_0${numFileC0P0}.j2k )
+    SET( filenameRef   c0p0_0${numFileC0P0}.pgx )
+  ELSE(${numFileC0P0} LESS 10)
+    SET( filenameInput p0_${numFileC0P0}.j2k )
+    SET( filenameRef   c0p0_${numFileC0P0}.pgx )
+  ENDIF(${numFileC0P0} LESS 10)
+  
+  # Get corresponding tests parameters
+  list(GET C0P0_ResFactor_list ${numFileC0P0}  ResFactor)
+  list(GET CP0_nbC_list ${numFileC0P0}  nbComponents)
+  list(GET C0P0_PEAK_list ${numFileC0P0}  PEAK_limit)
+  list(GET C0P0_MSE_list ${numFileC0P0}  MSE_limit)
+  
+  # Manage cases which need to try different resolution reduction
+  IF (numFileC0P0 EQUAL 3 OR numFileC0P0 EQUAL 15)
+   
+    get_filename_component(filenameRefSub ${filenameRef} NAME_WE)
+    
+    #r = 0
+    ADD_TEST(ETS-C0P0-${filenameInput}-r0-decode 
+        ${EXECUTABLE_OUTPUT_PATH}/j2k_to_image 
+        -i ${INPUT_CONF}/${filenameInput}
+        -o ${TEMP}/c0${filenameInput}-r0.pgx
+        -r 0
+        )
+     
+    ADD_TEST(ETS-C0P0-${filenameInput}-r0-compare2ref
+        ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
+        -b ${BASELINE_CONF}/${filenameRefSub}r0.pgx
+        -t ${TEMP}/c0${filenameInput}-r0.pgx
+        -n ${nbComponents}
+        -p ${PEAK_limit}
+        -m ${MSE_limit}
+        -s t_
+        )
+      
+    SET_TESTS_PROPERTIES(ETS-C0P0-${filenameInput}-r0-compare2ref  
+                         PROPERTIES DEPENDS 
+                         ETS-C0P0-${filenameInput}-r0-decode)    
+                       
+    ADD_TEST(NR-C0P0-${filenameInput}-r0-compare2base
+        ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
+        -b ${BASELINE_NR}/opj_${filenameRefSub}-r0.pgx
+        -t ${TEMP}/c0${filenameInput}-r0.pgx
+        -n ${nbComponents}
+        -d 
+        -s b_t_
+        )
+    SET_TESTS_PROPERTIES(NR-C0P0-${filenameInput}-r0-compare2base  
+                         PROPERTIES DEPENDS 
+                         ETS-C0P0-${filenameInput}-r0-decode)  
+     
+    #r = 1
+    ADD_TEST(ETS-C0P0-${filenameInput}-r1-decode
+        ${EXECUTABLE_OUTPUT_PATH}/j2k_to_image 
+        -i ${INPUT_CONF}/${filenameInput}
+        -o ${TEMP}/c0${filenameInput}-r1.pgx
+        -r 1
+        )
+     
+    ADD_TEST(ETS-C0P0-${filenameInput}-r1-compare2ref
+        ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
+        -b ${BASELINE_CONF}/${filenameRefSub}r1.pgx
+        -t ${TEMP}/c0${filenameInput}-r1.pgx
+        -n ${nbComponents}
+        -p ${PEAK_limit}
+        -m ${MSE_limit}
+        -s t_
+        )
+      
+    SET_TESTS_PROPERTIES(ETS-C0P0-${filenameInput}-r1-compare2ref  
+                         PROPERTIES DEPENDS 
+                         ETS-C0P0-${filenameInput}-r1-decode)    
+                       
+    ADD_TEST(NR-C0P0-${filenameInput}-r1-compare2base
+        ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
+        -b ${BASELINE_NR}/opj_${filenameRefSub}-r1.pgx
+        -t ${TEMP}/c0${filenameInput}-r1.pgx
+        -n ${nbComponents}
+        -d 
+        -s b_t_
+        )
+    SET_TESTS_PROPERTIES(NR-C0P0-${filenameInput}-r1-compare2base  
+                         PROPERTIES DEPENDS 
+                         ETS-C0P0-${filenameInput}-r1-decode)  
+
+  ELSE(numFileC0P0 EQUAL 3 OR numFileC0P0 EQUAL 15)
+  
+    ADD_TEST(ETS-C0P0-${filenameInput}-decode
+        ${EXECUTABLE_OUTPUT_PATH}/j2k_to_image 
+        -i ${INPUT_CONF}/${filenameInput}
+        -o ${TEMP}/c0${filenameInput}.pgx
+        -r ${ResFactor}
+        )
+   
+    ADD_TEST(ETS-C0P0-${filenameInput}-compare2ref
+        ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
+        -b ${BASELINE_CONF}/${filenameRef}
+        -t ${TEMP}/c0${filenameInput}.pgx
+        -n ${nbComponents}
+        -p ${PEAK_limit}
+        -m ${MSE_limit}
+        -s t_
+        )
+      
+    SET_TESTS_PROPERTIES(ETS-C0P0-${filenameInput}-compare2ref  
+                         PROPERTIES DEPENDS 
+                         ETS-C0P0-${filenameInput}-decode)    
+                       
+    ADD_TEST(NR-C0P0-${filenameInput}-compare2base
+        ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
+        -b ${BASELINE_NR}/opj_${filenameRef}
+        -t ${TEMP}/c0${filenameInput}.pgx
+        -n ${nbComponents}
+        -d 
+        -s b_t_
+        )
+    SET_TESTS_PROPERTIES(NR-C0P0-${filenameInput}-compare2base  
+                         PROPERTIES DEPENDS 
+                         ETS-C0P0-${filenameInput}-decode)    
+   
+  ENDIF(numFileC0P0 EQUAL 3 OR numFileC0P0 EQUAL 15)
+
+ENDFOREACH(numFileC0P0)
+
+#--------------------------------------------------------------------------
+# Tests about class 0 profile 1
+# try to decode
+# compare to ref file
+# non regression comparison
+
+# Parameters and tolerances given by Table C.4
+SET( C0P1_ResFactor_list "not_used;0;3;3;0;4;1;0")
+SET( C0P1_PEAK_list "not_used;0;35;28;2;128;128;0")
+SET( C0P1_MSE_list "not_used;0;74;18.8;0.550;16384;16384;0")
+
+FOREACH(numFileC0P1 RANGE 1 7) 
+
+  # Build filenames
+  SET( filenameInput p1_0${numFileC0P1}.j2k )
+  SET( filenameRef   c0p1_0${numFileC0P1}.pgx )
+
+  # Get corresponding tests parameters 
+  list(GET C0P1_ResFactor_list ${numFileC0P1}  ResFactor)
+  list(GET CP1_nbC_list ${numFileC0P1}  nbComponents)
+  list(GET C0P1_PEAK_list ${numFileC0P1}  PEAK_limit)
+  list(GET C0P1_MSE_list ${numFileC0P1}  MSE_limit) 
+  
+
+  # Manage cases which need to try different resolution reduction
+  IF (numFileC0P1 EQUAL 4 )
+     
+    get_filename_component(filenameRefSub ${filenameRef} NAME_WE)
+  
+    #r = 0
+    ADD_TEST(ETS-C0P1-${filenameInput}-r0-decode 
+        ${EXECUTABLE_OUTPUT_PATH}/j2k_to_image 
+        -i ${INPUT_CONF}/${filenameInput}
+        -o ${TEMP}/c0${filenameInput}-r0.pgx
+        -r 0
+        )
+    
+    ADD_TEST(ETS-C0P1-${filenameInput}-r0-compare2ref
+        ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
+        -b ${BASELINE_CONF}/${filenameRefSub}r0.pgx
+        -t ${TEMP}/c0${filenameInput}-r0.pgx
+        -n ${nbComponents}
+        -p ${PEAK_limit}
+        -m ${MSE_limit}
+        -s t_
+        )
+      
+    SET_TESTS_PROPERTIES(ETS-C0P1-${filenameInput}-r0-compare2ref  
+                         PROPERTIES DEPENDS 
+                         ETS-C0P1-${filenameInput}-r0-decode)    
+                       
+    ADD_TEST(NR-C0P1-${filenameInput}-r0-compare2base
+        ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
+        -b ${BASELINE_NR}/opj_${filenameRefSub}-r0.pgx
+        -t ${TEMP}/c0${filenameInput}-r0.pgx
+        -n ${nbComponents}
+        -d 
+        -s b_t_
+        )
+    SET_TESTS_PROPERTIES(NR-C0P1-${filenameInput}-r0-compare2base  
+                         PROPERTIES DEPENDS 
+                         ETS-C0P1-${filenameInput}-r0-decode)    
+        
+    #r = 3
+    ADD_TEST(ETS-C0P1-${filenameInput}-r3-decode
+        ${EXECUTABLE_OUTPUT_PATH}/j2k_to_image 
+        -i ${INPUT_CONF}/${filenameInput}
+        -o ${TEMP}/c0${filenameInput}-r3.pgx
+        -r 3
+        )
+        
+    ADD_TEST(ETS-C0P1-${filenameInput}-r3-compare2ref
+        ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
+        -b ${BASELINE_CONF}/${filenameRefSub}r3.pgx
+        -t ${TEMP}/c0${filenameInput}-r3.pgx
+        -n ${nbComponents}
+        -p ${PEAK_limit}
+        -m ${MSE_limit}
+        -s t_
+        )
+      
+    SET_TESTS_PROPERTIES(ETS-C0P1-${filenameInput}-r3-compare2ref  
+                         PROPERTIES DEPENDS 
+                         ETS-C0P1-${filenameInput}-r3-decode)    
+                       
+    ADD_TEST(NR-C0P1-${filenameInput}-r3-compare2base
+        ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
+        -b ${BASELINE_NR}/opj_${filenameRefSub}-r3.pgx
+        -t ${TEMP}/c0${filenameInput}-r3.pgx
+        -n ${nbComponents}
+        -d 
+        -s b_t_
+        )
+    SET_TESTS_PROPERTIES(NR-C0P1-${filenameInput}-r3-compare2base  
+                         PROPERTIES DEPENDS 
+                         ETS-C0P1-${filenameInput}-r3-decode)    
+
+  ELSE(numFileC0P1 EQUAL 4)
+
+    ADD_TEST(ETS-C0P1-${filenameInput}-decode
+        ${EXECUTABLE_OUTPUT_PATH}/j2k_to_image 
+        -i ${INPUT_CONF}/${filenameInput}
+        -o ${TEMP}/c0${filenameInput}.pgx
+        -r ${ResFactor}
+        )
+            
+    ADD_TEST(ETS-C0P1-${filenameInput}-compare2ref
+        ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
+        -b ${BASELINE_CONF}/${filenameRef}
+        -t ${TEMP}/c0${filenameInput}.pgx
+        -n ${nbComponents}
+        -p ${PEAK_limit}
+        -m ${MSE_limit}
+        -s t_
+        )
+      
+    SET_TESTS_PROPERTIES(ETS-C0P1-${filenameInput}-compare2ref  
+                         PROPERTIES DEPENDS 
+                         ETS-C0P1-${filenameInput}-decode)    
+                       
+    ADD_TEST(NR-C0P1-${filenameInput}-compare2base
+        ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
+        -b ${BASELINE_NR}/opj_${filenameRef}
+        -t ${TEMP}/c0${filenameInput}.pgx
+        -n ${nbComponents}
+        -d 
+        -s b_t_
+        )
+    SET_TESTS_PROPERTIES(NR-C0P1-${filenameInput}-compare2base  
+                         PROPERTIES DEPENDS 
+                         ETS-C0P1-${filenameInput}-decode)          
+        
+  ENDIF(numFileC0P1 EQUAL 4)
+
+ENDFOREACH(numFileC0P1)
+
+#--------------------------------------------------------------------------
+# Tests about class 1 profile 0
+# try to decode
+# compare to ref file
+# non regression comparison
+
+# Parameters and tolerances given by Table C.6
+SET( C1P0_ResFactor_list "not_used;0;0;0;0;0;0;0;1;0;0;0;0;0;0;0;0")
+SET( C1P0_PEAK_list "not_used;0;0;0;5:4:6;2:2:2:0;635:403:378:0;0:0:0;0:0:0;0;0:0:0;0;0;0:0:0:0;0:0:0;0;0")
+SET( C1P0_MSE_list  "not_used;0;0;0;0.776:0.626:1.070;0.302:0.307:0.269:0;11287:6124:3968:0;0:0:0;0:0:0;0;0:0:0;0;0;0:0:0:0;0:0:0;0;0")
+
+FOREACH(numFileC1P0 RANGE 1 16) 
+
+  # Build filenames
+  IF(${numFileC1P0} LESS 10)
+    SET( filenameInput p0_0${numFileC1P0}.j2k )
+    SET( filenameRef   c1p0_0${numFileC1P0}.pgx )
+  ELSE(${numFileC1P0} LESS 10)
+    SET( filenameInput p0_${numFileC1P0}.j2k )
+    SET( filenameRef   c1p0_${numFileC1P0}.pgx )
+  ENDIF(${numFileC1P0} LESS 10)
+  
+  # Get corresponding tests parameters 
+  list(GET CP0_nbC_list ${numFileC1P0}  nbComponents)
+  list(GET C1P0_ResFactor_list ${numFileC1P0}  ResFactor)
+  list(GET C1P0_PEAK_list ${numFileC1P0}  PEAK_limit)
+  list(GET C1P0_MSE_list ${numFileC1P0}  MSE_limit)
+  
+  ADD_TEST(ETS-C1P0-${filenameInput}-decode
+      ${EXECUTABLE_OUTPUT_PATH}/j2k_to_image 
+      -i ${INPUT_CONF}/${filenameInput}
+      -o ${TEMP}/c1${filenameInput}.pgx
+      -r ${ResFactor}
+      )
+      
+  ADD_TEST(ETS-C1P0-${filenameInput}-compare2ref
+      ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
+     -b ${BASELINE_CONF}/${filenameRef}
+     -t ${TEMP}/c1${filenameInput}.pgx
+     -n ${nbComponents}
+     -p ${PEAK_limit}
+     -m ${MSE_limit}
+     -s b_t_
+     )
+      
+  SET_TESTS_PROPERTIES(ETS-C1P0-${filenameInput}-compare2ref  
+                       PROPERTIES DEPENDS 
+                       ETS-C1P0-${filenameInput}-decode)    
+                       
+  ADD_TEST(NR-C1P0-${filenameInput}-compare2base
+      ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
+     -b ${BASELINE_NR}/opj_${filenameRef}
+     -t ${TEMP}/c1${filenameInput}.pgx
+     -n ${nbComponents}
+     -d 
+     -s b_t_
+     )
+  SET_TESTS_PROPERTIES(NR-C1P0-${filenameInput}-compare2base  
+                       PROPERTIES DEPENDS 
+                       ETS-C1P0-${filenameInput}-decode)      
+  
+ENDFOREACH(numFileC1P0)
+
+#--------------------------------------------------------------------------
+# Tests about class 1 profile 1
+# try to decode
+# compare to ref file
+# non regression comparison
+
+# Parameters and tolerances given by Table C.7
+SET( C1P1_PEAK_list "not_used;0;5:4:6;2:2:1:0;624;40:40:40;2:2:2;0:0")
+SET( C1P1_MSE_list  "not_used;0;0.765:0.616:1.051;0.3:0.210:0.200:0;3080;8.458:9.816:10.154;0.6:0.6:0.6;0:0")
+
+FOREACH(numFileC1P1 RANGE 1 7) 
+
+  # Build filenames
+  SET( filenameInput p1_0${numFileC1P1}.j2k )
+  SET( filenameRef   c1p1_0${numFileC1P1}.pgx )
+  
+  # Get corresponding tests parameters
+  list(GET CP1_nbC_list ${numFileC1P1}  nbComponents)
+  list(GET C1P1_PEAK_list ${numFileC1P1}  PEAK_limit)
+  list(GET C1P1_MSE_list ${numFileC1P1}  MSE_limit)
+  
+  ADD_TEST(ETS-C1P1-${filenameInput}-decode
+      ${EXECUTABLE_OUTPUT_PATH}/j2k_to_image 
+      -i ${INPUT_CONF}/${filenameInput}
+      -o ${TEMP}/c1${filenameInput}.pgx
+      -r 0
+      )
+  ADD_TEST(ETS-C1P1-${filenameInput}-compare2ref
+      ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
+     -b ${BASELINE_CONF}/${filenameRef}
+     -t ${TEMP}/c1${filenameInput}.pgx
+     -n ${nbComponents}
+     -p ${PEAK_limit}
+     -m ${MSE_limit}
+     -s b_t_
+     )
+      
+  SET_TESTS_PROPERTIES(ETS-C1P1-${filenameInput}-compare2ref  
+                       PROPERTIES DEPENDS 
+                       ETS-C1P1-${filenameInput}-decode)    
+                       
+  ADD_TEST(NR-C1P1-${filenameInput}-compare2base
+      ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
+     -b ${BASELINE_NR}/opj_${filenameRef}
+     -t ${TEMP}/c1${filenameInput}.pgx
+     -n ${nbComponents}
+     -d 
+     -s b_t_
+     )
+      
+  SET_TESTS_PROPERTIES(NR-C1P1-${filenameInput}-compare2base  
+                       PROPERTIES DEPENDS 
+                       ETS-C1P1-${filenameInput}-decode)                                              
+                       
+ENDFOREACH(numFileC1P1)
\ No newline at end of file
index b129d0e5d3d9c687d6f262bf06d9da978fc3e38b..b8c6b3874a5f7c1895b63a6d4e3bb8924f1bf65b 100644 (file)
@@ -46,7 +46,7 @@ IF (ZLIB_FOUND)
     SET(HAVE_PNG_H 1 PARENT_SCOPE)
     SET(HAVE_LIBPNG 1 PARENT_SCOPE)
     SET(PNG_LIBNAME ${PNG_LIBRARIES} PARENT_SCOPE)
-    SET(PNG_INCLUDE_DIRNAME ${PNG_INCLUDE_DIR} PARENT_SCOPE) 
+    SET(PNG_INCLUDE_DIRNAME ${PNG_PNG_INCLUDE_DIR} PARENT_SCOPE) 
     
   ELSE(PNG_FOUND) # not found