Move lcms2 into third_party
authorTom Sepez <tsepez@chromium.org>
Wed, 17 Jun 2015 17:48:05 +0000 (10:48 -0700)
committerTom Sepez <tsepez@chromium.org>
Wed, 17 Jun 2015 17:48:05 +0000 (10:48 -0700)
Second CL to apply less restrictive flags to third party.

R=thestig@chromium.org

Review URL: https://codereview.chromium.org/1181943008.

91 files changed:
BUILD.gn
core/src/fxcodec/codec/fx_codec_icc.cpp
core/src/fxcodec/codec/fx_codec_jpx_opj.cpp
core/src/fxcodec/lcms2/fx_lcms2.h [new file with mode: 0644]
core/src/fxcodec/lcms2/fx_lcms2_plugin.h [new file with mode: 0644]
core/src/fxcodec/lcms2/include/fx_lcms2.h [deleted file]
core/src/fxcodec/lcms2/include/fx_lcms2_plugin.h [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/include/lcms2.h [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/include/lcms2_plugin.h [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmscam02.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmscgats.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmscnvrt.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmserr.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmsgamma.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmsgmt.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmshalf.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmsintrp.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmsio0.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmsio1.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmslut.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmsmd5.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmsmtrx.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmsnamed.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmsopt.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmspack.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmspcs.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmsplugin.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmsps2.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmssamp.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmssm.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmstypes.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmsvirt.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmswtpnt.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/cmsxform.c [deleted file]
core/src/fxcodec/lcms2/lcms2-2.6/src/lcms2_internal.h [deleted file]
core/src/fxcodec/lcms2/src/fx_cmscam02.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmscgats.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmscnvrt.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmserr.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmsgamma.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmsgmt.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmshalf.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmsintrp.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmsio0.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmsio1.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmslut.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmsmd5.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmsmtrx.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmsnamed.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmsopt.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmspack.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmspcs.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmsplugin.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmsps2.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmssamp.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmssm.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmstypes.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmsvirt.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmswtpnt.c [deleted file]
core/src/fxcodec/lcms2/src/fx_cmsxform.c [deleted file]
pdfium.gyp
third_party/BUILD.gn
third_party/lcms2-2.6/include/lcms2.h [new file with mode: 0644]
third_party/lcms2-2.6/include/lcms2_plugin.h [new file with mode: 0644]
third_party/lcms2-2.6/src/cmscam02.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmscgats.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmscnvrt.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmserr.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmsgamma.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmsgmt.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmshalf.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmsintrp.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmsio0.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmsio1.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmslut.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmsmd5.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmsmtrx.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmsnamed.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmsopt.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmspack.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmspcs.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmsplugin.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmsps2.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmssamp.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmssm.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmstypes.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmsvirt.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmswtpnt.c [new file with mode: 0644]
third_party/lcms2-2.6/src/cmsxform.c [new file with mode: 0644]
third_party/lcms2-2.6/src/lcms2_internal.h [new file with mode: 0644]
third_party/third_party.gyp

index d0f2920..f38c1be 100644 (file)
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -335,6 +335,9 @@ static_library("fpdftext") {
 }
 
 static_library("fxcodec") {
+  deps = [
+    "third_party:fx_lcms2",
+  ]
   sources = [
     "core/include/fxcodec/fx_codec.h",
     "core/include/fxcodec/fx_codec_def.h",
@@ -414,31 +417,8 @@ static_library("fxcodec") {
     "core/src/fxcodec/jbig2/JBig2_Segment.h",
     "core/src/fxcodec/jbig2/JBig2_SymbolDict.cpp",
     "core/src/fxcodec/jbig2/JBig2_SymbolDict.h",
-    "core/src/fxcodec/lcms2/src/fx_cmscam02.c",
-    "core/src/fxcodec/lcms2/src/fx_cmscgats.c",
-    "core/src/fxcodec/lcms2/src/fx_cmscnvrt.c",
-    "core/src/fxcodec/lcms2/src/fx_cmserr.c",
-    "core/src/fxcodec/lcms2/src/fx_cmsgamma.c",
-    "core/src/fxcodec/lcms2/src/fx_cmsgmt.c",
-    "core/src/fxcodec/lcms2/src/fx_cmshalf.c",
-    "core/src/fxcodec/lcms2/src/fx_cmsintrp.c",
-    "core/src/fxcodec/lcms2/src/fx_cmsio0.c",
-    "core/src/fxcodec/lcms2/src/fx_cmsio1.c",
-    "core/src/fxcodec/lcms2/src/fx_cmslut.c",
-    "core/src/fxcodec/lcms2/src/fx_cmsmd5.c",
-    "core/src/fxcodec/lcms2/src/fx_cmsmtrx.c",
-    "core/src/fxcodec/lcms2/src/fx_cmsnamed.c",
-    "core/src/fxcodec/lcms2/src/fx_cmsopt.c",
-    "core/src/fxcodec/lcms2/src/fx_cmspack.c",
-    "core/src/fxcodec/lcms2/src/fx_cmspcs.c",
-    "core/src/fxcodec/lcms2/src/fx_cmsplugin.c",
-    "core/src/fxcodec/lcms2/src/fx_cmsps2.c",
-    "core/src/fxcodec/lcms2/src/fx_cmssamp.c",
-    "core/src/fxcodec/lcms2/src/fx_cmssm.c",
-    "core/src/fxcodec/lcms2/src/fx_cmstypes.c",
-    "core/src/fxcodec/lcms2/src/fx_cmsvirt.c",
-    "core/src/fxcodec/lcms2/src/fx_cmswtpnt.c",
-    "core/src/fxcodec/lcms2/src/fx_cmsxform.c",
+    "core/src/fxcodec/lcms2/fx_lcms2.h",
+    "core/src/fxcodec/lcms2/fx_lcms2_plugin.h",
     "core/src/fxcodec/libjpeg/cderror.h",
     "core/src/fxcodec/libjpeg/cdjpeg.h",
     "core/src/fxcodec/libjpeg/fpdfapi_jcapimin.c",
index 3b3b54b..f33d085 100644 (file)
@@ -5,8 +5,9 @@
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
 #include "../../../include/fxcodec/fx_codec.h"
+#include "../lcms2/fx_lcms2.h"
 #include "codec_int.h"
-#include "../lcms2/include/fx_lcms2.h"
+
 const FX_DWORD N_COMPONENT_LAB = 3;
 const FX_DWORD N_COMPONENT_GRAY = 1;
 const FX_DWORD N_COMPONENT_RGB = 3;
index 4f548ea..4457f18 100644 (file)
@@ -9,7 +9,7 @@
 
 #include "../../../include/fxcodec/fx_codec.h"
 #include "../fx_libopenjpeg/libopenjpeg20/openjpeg.h"
-#include "../lcms2/include/fx_lcms2.h"
+#include "../lcms2/fx_lcms2.h"
 #include "codec_int.h"
 
 static void fx_error_callback(const char *msg, void *client_data)
diff --git a/core/src/fxcodec/lcms2/fx_lcms2.h b/core/src/fxcodec/lcms2/fx_lcms2.h
new file mode 100644 (file)
index 0000000..86b4fad
--- /dev/null
@@ -0,0 +1,12 @@
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_SRC_FXCODEC_LCMS2_INCLUDE_FX_LCMS2_H_
+#define CORE_SRC_FXCODEC_LCMS2_INCLUDE_FX_LCMS2_H_
+
+#include "../../../../third_party/lcms2-2.6/include/lcms2.h"
+
+#endif  // CORE_SRC_FXCODEC_LCMS2_INCLUDE_FX_LCMS2_H_
diff --git a/core/src/fxcodec/lcms2/fx_lcms2_plugin.h b/core/src/fxcodec/lcms2/fx_lcms2_plugin.h
new file mode 100644 (file)
index 0000000..86b722d
--- /dev/null
@@ -0,0 +1,12 @@
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_SRC_FXCODEC_LCMS2_INCLUDE_FX_LCMS2_PLUGIN_H_
+#define CORE_SRC_FXCODEC_LCMS2_INCLUDE_FX_LCMS2_PLUGIN_H_
+
+#include "../../../../third_party/lcms2-2.6/include/lcms2_plugin.h"
+
+#endif  // CORE_SRC_FXCODEC_LCMS2_INCLUDE_FX_LCMS2_PLUGIN_H_
diff --git a/core/src/fxcodec/lcms2/include/fx_lcms2.h b/core/src/fxcodec/lcms2/include/fx_lcms2.h
deleted file mode 100644 (file)
index ca1ed2a..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef CORE_SRC_FXCODEC_LCMS2_INCLUDE_FX_LCMS2_H_
-#define CORE_SRC_FXCODEC_LCMS2_INCLUDE_FX_LCMS2_H_
-
-#include "../lcms2-2.6/include/lcms2.h"
-
-#endif  // CORE_SRC_FXCODEC_LCMS2_INCLUDE_FX_LCMS2_H_
diff --git a/core/src/fxcodec/lcms2/include/fx_lcms2_plugin.h b/core/src/fxcodec/lcms2/include/fx_lcms2_plugin.h
deleted file mode 100644 (file)
index 92fd8a6..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef CORE_SRC_FXCODEC_LCMS2_INCLUDE_FX_LCMS2_PLUGIN_H_
-#define CORE_SRC_FXCODEC_LCMS2_INCLUDE_FX_LCMS2_PLUGIN_H_
-
-#include "../lcms2-2.6/include/lcms2_plugin.h"
-
-#endif  // CORE_SRC_FXCODEC_LCMS2_INCLUDE_FX_LCMS2_PLUGIN_H_
diff --git a/core/src/fxcodec/lcms2/lcms2-2.6/include/lcms2.h b/core/src/fxcodec/lcms2/lcms2-2.6/include/lcms2.h
deleted file mode 100644 (file)
index 8595f70..0000000
+++ /dev/null
@@ -1,1882 +0,0 @@
-//---------------------------------------------------------------------------------
-//
-//  Little Color Management System
-//  Copyright (c) 1998-2014 Marti Maria Saguer
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the "Software"),
-// to deal in the Software without restriction, including without limitation
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,
-// and/or sell copies of the Software, and to permit persons to whom the Software
-// is furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
-// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-//---------------------------------------------------------------------------------
-//
-// Version 2.6
-//
-
-#ifndef _lcms2_H
-
-// ********** Configuration toggles ****************************************
-
-// Uncomment this one if you are using big endian machines
-// #define CMS_USE_BIG_ENDIAN   1
-
-// Uncomment this one if your compiler/machine does NOT support the
-// "long long" type.
-// #define CMS_DONT_USE_INT64        1
-
-// Uncomment this if your compiler doesn't work with fast floor function
-// #define CMS_DONT_USE_FAST_FLOOR 1
-
-// Uncomment this line if you want lcms to use the black point tag in profile,
-// if commented, lcms will compute the black point by its own.
-// It is safer to leave it commented out
-// #define CMS_USE_PROFILE_BLACK_POINT_TAG    1
-
-// Uncomment this line if you are compiling as C++ and want a C++ API
-// #define CMS_USE_CPP_API
-
-// Uncomment this line if you need strict CGATS syntax. Makes CGATS files to
-// require "KEYWORD" on undefined identifiers, keep it comented out unless needed
-// #define CMS_STRICT_CGATS  1
-
-// Uncomment to get rid of the tables for "half" float support
-// #define CMS_NO_HALF_SUPPORT 1
-
-// Uncomment to get rid of pthreads/windows dependency
-// #define CMS_NO_PTHREADS  1
-
-// ********** End of configuration toggles ******************************
-
-// Needed for streams
-#include <stdio.h>
-
-// Needed for portability (C99 per 7.1.2)
-#include <limits.h>
-#include <time.h>
-#include <stddef.h>
-
-#ifndef CMS_USE_CPP_API
-#   ifdef __cplusplus
-extern "C" {
-#   endif
-#endif
-
-// Version/release
-#define LCMS_VERSION        2060
-
-// I will give the chance of redefining basic types for compilers that are not fully C99 compliant
-#ifndef CMS_BASIC_TYPES_ALREADY_DEFINED
-
-// Base types
-typedef unsigned char        cmsUInt8Number;   // That is guaranteed by the C99 spec
-typedef signed char          cmsInt8Number;    // That is guaranteed by the C99 spec
-
-#if CHAR_BIT != 8
-#  error "Unable to find 8 bit type, unsupported compiler"
-#endif
-
-// IEEE float storage numbers
-typedef float                cmsFloat32Number;
-typedef double               cmsFloat64Number;
-
-// 16-bit base types
-#if (USHRT_MAX == 65535U)
- typedef unsigned short      cmsUInt16Number;
-#elif (UINT_MAX == 65535U)
- typedef unsigned int        cmsUInt16Number;
-#else
-#  error "Unable to find 16 bits unsigned type, unsupported compiler"
-#endif
-
-#if (SHRT_MAX == 32767)
-  typedef  short             cmsInt16Number;
-#elif (INT_MAX == 32767)
-  typedef  int               cmsInt16Number;
-#else
-#  error "Unable to find 16 bits signed type, unsupported compiler"
-#endif
-
-// 32-bit base type
-#if (UINT_MAX == 4294967295U)
- typedef unsigned int        cmsUInt32Number;
-#elif (ULONG_MAX == 4294967295U)
- typedef unsigned long       cmsUInt32Number;
-#else
-#  error "Unable to find 32 bit unsigned type, unsupported compiler"
-#endif
-
-#if (INT_MAX == +2147483647)
- typedef  int                cmsInt32Number;
-#elif (LONG_MAX == +2147483647)
- typedef  long               cmsInt32Number;
-#else
-#  error "Unable to find 32 bit signed type, unsupported compiler"
-#endif
-
-// 64-bit base types
-#ifndef CMS_DONT_USE_INT64
-#  if (ULONG_MAX  == 18446744073709551615U)
-    typedef unsigned long   cmsUInt64Number;
-#  elif (ULLONG_MAX == 18446744073709551615U)
-      typedef unsigned long long   cmsUInt64Number;
-#  else
-#     define CMS_DONT_USE_INT64 1
-#  endif
-#  if (LONG_MAX == +9223372036854775807)
-      typedef  long          cmsInt64Number;
-#  elif (LLONG_MAX == +9223372036854775807)
-      typedef  long long     cmsInt64Number;
-#  else
-#     define CMS_DONT_USE_INT64 1
-#  endif
-#endif
-#endif
-
-// In the case 64 bit numbers are not supported by the compiler
-#ifdef CMS_DONT_USE_INT64
-    typedef cmsUInt32Number      cmsUInt64Number[2];
-    typedef cmsInt32Number       cmsInt64Number[2];
-#endif
-
-// Derivative types
-typedef cmsUInt32Number      cmsSignature;
-typedef cmsUInt16Number      cmsU8Fixed8Number;
-typedef cmsInt32Number       cmsS15Fixed16Number;
-typedef cmsUInt32Number      cmsU16Fixed16Number;
-
-// Boolean type, which will be using the native integer
-typedef int                  cmsBool;
-
-// Try to detect windows
-#if defined (_WIN32) || defined(_WIN64) || defined(WIN32) || defined(_WIN32_)
-#  define CMS_IS_WINDOWS_ 1
-#endif
-
-#ifdef _MSC_VER
-#  define CMS_IS_WINDOWS_ 1
-#endif
-
-#ifdef __BORLANDC__
-#  define CMS_IS_WINDOWS_ 1
-#endif
-
-// Try to detect big endian platforms. This list can be endless, so only some checks are performed over here.
-// you can pass this toggle to the compiler by using -DCMS_USE_BIG_ENDIAN or something similar
-
-#if defined(__sgi__) || defined(__sgi) || defined(sparc)
-#   define CMS_USE_BIG_ENDIAN      1
-#endif
-
-#if defined(__s390__) || defined(__s390x__)
-#   define CMS_USE_BIG_ENDIAN   1
-#endif
-
-#  ifdef TARGET_CPU_PPC
-#    if TARGET_CPU_PPC
-#      define CMS_USE_BIG_ENDIAN   1
-#    endif
-#  endif
-
-#if defined(__powerpc__) || defined(__ppc__) || defined(TARGET_CPU_PPC)
-#   define CMS_USE_BIG_ENDIAN   1
-#   if defined (__GNUC__) && defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN)
-#       if __BYTE_ORDER  == __LITTLE_ENDIAN
-//               // Don't use big endian for PowerPC little endian mode
-#                undef CMS_USE_BIG_ENDIAN
-#       endif
-#   endif
-#endif
-
-// WORDS_BIGENDIAN takes precedence
-#if defined(_HOST_BIG_ENDIAN) || defined(__BIG_ENDIAN__) || defined(WORDS_BIGENDIAN)
-#   define CMS_USE_BIG_ENDIAN      1
-#endif
-
-#ifdef macintosh
-# ifdef __BIG_ENDIAN__
-#   define CMS_USE_BIG_ENDIAN      1
-# endif
-# ifdef __LITTLE_ENDIAN__
-#   undef CMS_USE_BIG_ENDIAN
-# endif
-#endif
-
-// Calling convention -- this is hardly platform and compiler dependent
-#ifdef CMS_IS_WINDOWS_
-#  if defined(CMS_DLL) || defined(CMS_DLL_BUILD)
-#     ifdef __BORLANDC__
-#        define CMSEXPORT       __stdcall _export
-#        define CMSAPI
-#     else
-#        define CMSEXPORT      _stdcall
-#        ifdef CMS_DLL_BUILD
-#            define CMSAPI    __declspec(dllexport)
-#        else
-#           define CMSAPI     __declspec(dllimport)
-#       endif
-#     endif
-#  else
-#       define CMSEXPORT
-#       define CMSAPI
-#  endif
-#else
-# define CMSEXPORT
-# define CMSAPI
-#endif
-
-#ifdef HasTHREADS
-# if HasTHREADS == 1
-#    undef CMS_NO_PTHREADS
-# else
-#    define CMS_NO_PTHREADS 1
-# endif
-#endif
-
-// Some common definitions
-#define cmsMAX_PATH     256
-
-#ifndef FALSE
-#       define FALSE 0
-#endif
-#ifndef TRUE
-#       define TRUE  1
-#endif
-
-// D50 XYZ normalized to Y=1.0
-#define cmsD50X             0.9642
-#define cmsD50Y             1.0
-#define cmsD50Z             0.8249
-
-// V4 perceptual black
-#define cmsPERCEPTUAL_BLACK_X  0.00336
-#define cmsPERCEPTUAL_BLACK_Y  0.0034731
-#define cmsPERCEPTUAL_BLACK_Z  0.00287
-
-// Definitions in ICC spec
-#define cmsMagicNumber      0x61637370     // 'acsp'
-#define lcmsSignature       0x6c636d73     // 'lcms'
-
-
-// Base ICC type definitions
-typedef enum {
-    cmsSigChromaticityType                  = 0x6368726D,  // 'chrm'
-    cmsSigColorantOrderType                 = 0x636C726F,  // 'clro'
-    cmsSigColorantTableType                 = 0x636C7274,  // 'clrt'
-    cmsSigCrdInfoType                       = 0x63726469,  // 'crdi'
-    cmsSigCurveType                         = 0x63757276,  // 'curv'
-    cmsSigDataType                          = 0x64617461,  // 'data'
-    cmsSigDictType                          = 0x64696374,  // 'dict'
-    cmsSigDateTimeType                      = 0x6474696D,  // 'dtim'
-    cmsSigDeviceSettingsType                = 0x64657673,  // 'devs'
-    cmsSigLut16Type                         = 0x6d667432,  // 'mft2'
-    cmsSigLut8Type                          = 0x6d667431,  // 'mft1'
-    cmsSigLutAtoBType                       = 0x6d414220,  // 'mAB '
-    cmsSigLutBtoAType                       = 0x6d424120,  // 'mBA '
-    cmsSigMeasurementType                   = 0x6D656173,  // 'meas'
-    cmsSigMultiLocalizedUnicodeType         = 0x6D6C7563,  // 'mluc'
-    cmsSigMultiProcessElementType           = 0x6D706574,  // 'mpet'
-    cmsSigNamedColorType                    = 0x6E636f6C,  // 'ncol' -- DEPRECATED!
-    cmsSigNamedColor2Type                   = 0x6E636C32,  // 'ncl2'
-    cmsSigParametricCurveType               = 0x70617261,  // 'para'
-    cmsSigProfileSequenceDescType           = 0x70736571,  // 'pseq'
-    cmsSigProfileSequenceIdType             = 0x70736964,  // 'psid'
-    cmsSigResponseCurveSet16Type            = 0x72637332,  // 'rcs2'
-    cmsSigS15Fixed16ArrayType               = 0x73663332,  // 'sf32'
-    cmsSigScreeningType                     = 0x7363726E,  // 'scrn'
-    cmsSigSignatureType                     = 0x73696720,  // 'sig '
-    cmsSigTextType                          = 0x74657874,  // 'text'
-    cmsSigTextDescriptionType               = 0x64657363,  // 'desc'
-    cmsSigU16Fixed16ArrayType               = 0x75663332,  // 'uf32'
-    cmsSigUcrBgType                         = 0x62666420,  // 'bfd '
-    cmsSigUInt16ArrayType                   = 0x75693136,  // 'ui16'
-    cmsSigUInt32ArrayType                   = 0x75693332,  // 'ui32'
-    cmsSigUInt64ArrayType                   = 0x75693634,  // 'ui64'
-    cmsSigUInt8ArrayType                    = 0x75693038,  // 'ui08'
-    cmsSigVcgtType                          = 0x76636774,  // 'vcgt'
-    cmsSigViewingConditionsType             = 0x76696577,  // 'view'
-    cmsSigXYZType                           = 0x58595A20   // 'XYZ '
-
-
-} cmsTagTypeSignature;
-
-// Base ICC tag definitions
-typedef enum {
-    cmsSigAToB0Tag                          = 0x41324230,  // 'A2B0'
-    cmsSigAToB1Tag                          = 0x41324231,  // 'A2B1'
-    cmsSigAToB2Tag                          = 0x41324232,  // 'A2B2'
-    cmsSigBlueColorantTag                   = 0x6258595A,  // 'bXYZ'
-    cmsSigBlueMatrixColumnTag               = 0x6258595A,  // 'bXYZ'
-    cmsSigBlueTRCTag                        = 0x62545243,  // 'bTRC'
-    cmsSigBToA0Tag                          = 0x42324130,  // 'B2A0'
-    cmsSigBToA1Tag                          = 0x42324131,  // 'B2A1'
-    cmsSigBToA2Tag                          = 0x42324132,  // 'B2A2'
-    cmsSigCalibrationDateTimeTag            = 0x63616C74,  // 'calt'
-    cmsSigCharTargetTag                     = 0x74617267,  // 'targ'
-    cmsSigChromaticAdaptationTag            = 0x63686164,  // 'chad'
-    cmsSigChromaticityTag                   = 0x6368726D,  // 'chrm'
-    cmsSigColorantOrderTag                  = 0x636C726F,  // 'clro'
-    cmsSigColorantTableTag                  = 0x636C7274,  // 'clrt'
-    cmsSigColorantTableOutTag               = 0x636C6F74,  // 'clot'
-    cmsSigColorimetricIntentImageStateTag   = 0x63696973,  // 'ciis'
-    cmsSigCopyrightTag                      = 0x63707274,  // 'cprt'
-    cmsSigCrdInfoTag                        = 0x63726469,  // 'crdi'
-    cmsSigDataTag                           = 0x64617461,  // 'data'
-    cmsSigDateTimeTag                       = 0x6474696D,  // 'dtim'
-    cmsSigDeviceMfgDescTag                  = 0x646D6E64,  // 'dmnd'
-    cmsSigDeviceModelDescTag                = 0x646D6464,  // 'dmdd'
-    cmsSigDeviceSettingsTag                 = 0x64657673,  // 'devs'
-    cmsSigDToB0Tag                          = 0x44324230,  // 'D2B0'
-    cmsSigDToB1Tag                          = 0x44324231,  // 'D2B1'
-    cmsSigDToB2Tag                          = 0x44324232,  // 'D2B2'
-    cmsSigDToB3Tag                          = 0x44324233,  // 'D2B3'
-    cmsSigBToD0Tag                          = 0x42324430,  // 'B2D0'
-    cmsSigBToD1Tag                          = 0x42324431,  // 'B2D1'
-    cmsSigBToD2Tag                          = 0x42324432,  // 'B2D2'
-    cmsSigBToD3Tag                          = 0x42324433,  // 'B2D3'
-    cmsSigGamutTag                          = 0x67616D74,  // 'gamt'
-    cmsSigGrayTRCTag                        = 0x6b545243,  // 'kTRC'
-    cmsSigGreenColorantTag                  = 0x6758595A,  // 'gXYZ'
-    cmsSigGreenMatrixColumnTag              = 0x6758595A,  // 'gXYZ'
-    cmsSigGreenTRCTag                       = 0x67545243,  // 'gTRC'
-    cmsSigLuminanceTag                      = 0x6C756d69,  // 'lumi'
-    cmsSigMeasurementTag                    = 0x6D656173,  // 'meas'
-    cmsSigMediaBlackPointTag                = 0x626B7074,  // 'bkpt'
-    cmsSigMediaWhitePointTag                = 0x77747074,  // 'wtpt'
-    cmsSigNamedColorTag                     = 0x6E636f6C,  // 'ncol' // Deprecated by the ICC
-    cmsSigNamedColor2Tag                    = 0x6E636C32,  // 'ncl2'
-    cmsSigOutputResponseTag                 = 0x72657370,  // 'resp'
-    cmsSigPerceptualRenderingIntentGamutTag = 0x72696730,  // 'rig0'
-    cmsSigPreview0Tag                       = 0x70726530,  // 'pre0'
-    cmsSigPreview1Tag                       = 0x70726531,  // 'pre1'
-    cmsSigPreview2Tag                       = 0x70726532,  // 'pre2'
-    cmsSigProfileDescriptionTag             = 0x64657363,  // 'desc'
-    cmsSigProfileDescriptionMLTag           = 0x6473636d,  // 'dscm'
-    cmsSigProfileSequenceDescTag            = 0x70736571,  // 'pseq'
-    cmsSigProfileSequenceIdTag              = 0x70736964,  // 'psid'
-    cmsSigPs2CRD0Tag                        = 0x70736430,  // 'psd0'
-    cmsSigPs2CRD1Tag                        = 0x70736431,  // 'psd1'
-    cmsSigPs2CRD2Tag                        = 0x70736432,  // 'psd2'
-    cmsSigPs2CRD3Tag                        = 0x70736433,  // 'psd3'
-    cmsSigPs2CSATag                         = 0x70733273,  // 'ps2s'
-    cmsSigPs2RenderingIntentTag             = 0x70733269,  // 'ps2i'
-    cmsSigRedColorantTag                    = 0x7258595A,  // 'rXYZ'
-    cmsSigRedMatrixColumnTag                = 0x7258595A,  // 'rXYZ'
-    cmsSigRedTRCTag                         = 0x72545243,  // 'rTRC'
-    cmsSigSaturationRenderingIntentGamutTag = 0x72696732,  // 'rig2'
-    cmsSigScreeningDescTag                  = 0x73637264,  // 'scrd'
-    cmsSigScreeningTag                      = 0x7363726E,  // 'scrn'
-    cmsSigTechnologyTag                     = 0x74656368,  // 'tech'
-    cmsSigUcrBgTag                          = 0x62666420,  // 'bfd '
-    cmsSigViewingCondDescTag                = 0x76756564,  // 'vued'
-    cmsSigViewingConditionsTag              = 0x76696577,  // 'view'
-    cmsSigVcgtTag                           = 0x76636774,  // 'vcgt'
-    cmsSigMetaTag                           = 0x6D657461   // 'meta'
-
-} cmsTagSignature;
-
-
-// ICC Technology tag
-typedef enum {
-    cmsSigDigitalCamera                     = 0x6463616D,  // 'dcam'
-    cmsSigFilmScanner                       = 0x6673636E,  // 'fscn'
-    cmsSigReflectiveScanner                 = 0x7273636E,  // 'rscn'
-    cmsSigInkJetPrinter                     = 0x696A6574,  // 'ijet'
-    cmsSigThermalWaxPrinter                 = 0x74776178,  // 'twax'
-    cmsSigElectrophotographicPrinter        = 0x6570686F,  // 'epho'
-    cmsSigElectrostaticPrinter              = 0x65737461,  // 'esta'
-    cmsSigDyeSublimationPrinter             = 0x64737562,  // 'dsub'
-    cmsSigPhotographicPaperPrinter          = 0x7270686F,  // 'rpho'
-    cmsSigFilmWriter                        = 0x6670726E,  // 'fprn'
-    cmsSigVideoMonitor                      = 0x7669646D,  // 'vidm'
-    cmsSigVideoCamera                       = 0x76696463,  // 'vidc'
-    cmsSigProjectionTelevision              = 0x706A7476,  // 'pjtv'
-    cmsSigCRTDisplay                        = 0x43525420,  // 'CRT '
-    cmsSigPMDisplay                         = 0x504D4420,  // 'PMD '
-    cmsSigAMDisplay                         = 0x414D4420,  // 'AMD '
-    cmsSigPhotoCD                           = 0x4B504344,  // 'KPCD'
-    cmsSigPhotoImageSetter                  = 0x696D6773,  // 'imgs'
-    cmsSigGravure                           = 0x67726176,  // 'grav'
-    cmsSigOffsetLithography                 = 0x6F666673,  // 'offs'
-    cmsSigSilkscreen                        = 0x73696C6B,  // 'silk'
-    cmsSigFlexography                       = 0x666C6578,  // 'flex'
-    cmsSigMotionPictureFilmScanner          = 0x6D706673,  // 'mpfs'
-    cmsSigMotionPictureFilmRecorder         = 0x6D706672,  // 'mpfr'
-    cmsSigDigitalMotionPictureCamera        = 0x646D7063,  // 'dmpc'
-    cmsSigDigitalCinemaProjector            = 0x64636A70   // 'dcpj'
-
-} cmsTechnologySignature;
-
-
-// ICC Color spaces
-typedef enum {
-    cmsSigXYZData                           = 0x58595A20,  // 'XYZ '
-    cmsSigLabData                           = 0x4C616220,  // 'Lab '
-    cmsSigLuvData                           = 0x4C757620,  // 'Luv '
-    cmsSigYCbCrData                         = 0x59436272,  // 'YCbr'
-    cmsSigYxyData                           = 0x59787920,  // 'Yxy '
-    cmsSigRgbData                           = 0x52474220,  // 'RGB '
-    cmsSigGrayData                          = 0x47524159,  // 'GRAY'
-    cmsSigHsvData                           = 0x48535620,  // 'HSV '
-    cmsSigHlsData                           = 0x484C5320,  // 'HLS '
-    cmsSigCmykData                          = 0x434D594B,  // 'CMYK'
-    cmsSigCmyData                           = 0x434D5920,  // 'CMY '
-    cmsSigMCH1Data                          = 0x4D434831,  // 'MCH1'
-    cmsSigMCH2Data                          = 0x4D434832,  // 'MCH2'
-    cmsSigMCH3Data                          = 0x4D434833,  // 'MCH3'
-    cmsSigMCH4Data                          = 0x4D434834,  // 'MCH4'
-    cmsSigMCH5Data                          = 0x4D434835,  // 'MCH5'
-    cmsSigMCH6Data                          = 0x4D434836,  // 'MCH6'
-    cmsSigMCH7Data                          = 0x4D434837,  // 'MCH7'
-    cmsSigMCH8Data                          = 0x4D434838,  // 'MCH8'
-    cmsSigMCH9Data                          = 0x4D434839,  // 'MCH9'
-    cmsSigMCHAData                          = 0x4D434841,  // 'MCHA'
-    cmsSigMCHBData                          = 0x4D434842,  // 'MCHB'
-    cmsSigMCHCData                          = 0x4D434843,  // 'MCHC'
-    cmsSigMCHDData                          = 0x4D434844,  // 'MCHD'
-    cmsSigMCHEData                          = 0x4D434845,  // 'MCHE'
-    cmsSigMCHFData                          = 0x4D434846,  // 'MCHF'
-    cmsSigNamedData                         = 0x6e6d636c,  // 'nmcl'
-    cmsSig1colorData                        = 0x31434C52,  // '1CLR'
-    cmsSig2colorData                        = 0x32434C52,  // '2CLR'
-    cmsSig3colorData                        = 0x33434C52,  // '3CLR'
-    cmsSig4colorData                        = 0x34434C52,  // '4CLR'
-    cmsSig5colorData                        = 0x35434C52,  // '5CLR'
-    cmsSig6colorData                        = 0x36434C52,  // '6CLR'
-    cmsSig7colorData                        = 0x37434C52,  // '7CLR'
-    cmsSig8colorData                        = 0x38434C52,  // '8CLR'
-    cmsSig9colorData                        = 0x39434C52,  // '9CLR'
-    cmsSig10colorData                       = 0x41434C52,  // 'ACLR'
-    cmsSig11colorData                       = 0x42434C52,  // 'BCLR'
-    cmsSig12colorData                       = 0x43434C52,  // 'CCLR'
-    cmsSig13colorData                       = 0x44434C52,  // 'DCLR'
-    cmsSig14colorData                       = 0x45434C52,  // 'ECLR'
-    cmsSig15colorData                       = 0x46434C52,  // 'FCLR'
-    cmsSigLuvKData                          = 0x4C75764B   // 'LuvK'
-
-} cmsColorSpaceSignature;
-
-// ICC Profile Class
-typedef enum {
-    cmsSigInputClass                        = 0x73636E72,  // 'scnr'
-    cmsSigDisplayClass                      = 0x6D6E7472,  // 'mntr'
-    cmsSigOutputClass                       = 0x70727472,  // 'prtr'
-    cmsSigLinkClass                         = 0x6C696E6B,  // 'link'
-    cmsSigAbstractClass                     = 0x61627374,  // 'abst'
-    cmsSigColorSpaceClass                   = 0x73706163,  // 'spac'
-    cmsSigNamedColorClass                   = 0x6e6d636c   // 'nmcl'
-
-} cmsProfileClassSignature;
-
-// ICC Platforms
-typedef enum {
-    cmsSigMacintosh                         = 0x4150504C,  // 'APPL'
-    cmsSigMicrosoft                         = 0x4D534654,  // 'MSFT'
-    cmsSigSolaris                           = 0x53554E57,  // 'SUNW'
-    cmsSigSGI                               = 0x53474920,  // 'SGI '
-    cmsSigTaligent                          = 0x54474E54,  // 'TGNT'
-    cmsSigUnices                            = 0x2A6E6978   // '*nix'   // From argyll -- Not official
-
-} cmsPlatformSignature;
-
-// Reference gamut
-#define  cmsSigPerceptualReferenceMediumGamut         0x70726d67  //'prmg'
-
-// For cmsSigColorimetricIntentImageStateTag
-#define  cmsSigSceneColorimetryEstimates              0x73636F65  //'scoe'
-#define  cmsSigSceneAppearanceEstimates               0x73617065  //'sape'
-#define  cmsSigFocalPlaneColorimetryEstimates         0x66706365  //'fpce'
-#define  cmsSigReflectionHardcopyOriginalColorimetry  0x72686F63  //'rhoc'
-#define  cmsSigReflectionPrintOutputColorimetry       0x72706F63  //'rpoc'
-
-// Multi process elements types
-typedef enum {
-    cmsSigCurveSetElemType              = 0x63767374,  //'cvst'
-    cmsSigMatrixElemType                = 0x6D617466,  //'matf'
-    cmsSigCLutElemType                  = 0x636C7574,  //'clut'
-
-    cmsSigBAcsElemType                  = 0x62414353,  // 'bACS'
-    cmsSigEAcsElemType                  = 0x65414353,  // 'eACS'
-
-    // Custom from here, not in the ICC Spec
-    cmsSigXYZ2LabElemType               = 0x6C327820,  // 'l2x '
-    cmsSigLab2XYZElemType               = 0x78326C20,  // 'x2l '
-    cmsSigNamedColorElemType            = 0x6E636C20,  // 'ncl '
-    cmsSigLabV2toV4                     = 0x32203420,  // '2 4 '
-    cmsSigLabV4toV2                     = 0x34203220,  // '4 2 '
-
-    // Identities
-    cmsSigIdentityElemType              = 0x69646E20,  // 'idn '
-
-    // Float to floatPCS
-    cmsSigLab2FloatPCS                  = 0x64326C20,  // 'd2l '
-    cmsSigFloatPCS2Lab                  = 0x6C326420,  // 'l2d '
-    cmsSigXYZ2FloatPCS                  = 0x64327820,  // 'd2x '
-    cmsSigFloatPCS2XYZ                  = 0x78326420   // 'x2d '
-
-} cmsStageSignature;
-
-// Types of CurveElements
-typedef enum {
-
-    cmsSigFormulaCurveSeg               = 0x70617266, // 'parf'
-    cmsSigSampledCurveSeg               = 0x73616D66, // 'samf'
-    cmsSigSegmentedCurve                = 0x63757266  // 'curf'
-
-} cmsCurveSegSignature;
-
-// Used in ResponseCurveType
-#define  cmsSigStatusA                    0x53746141 //'StaA'
-#define  cmsSigStatusE                    0x53746145 //'StaE'
-#define  cmsSigStatusI                    0x53746149 //'StaI'
-#define  cmsSigStatusT                    0x53746154 //'StaT'
-#define  cmsSigStatusM                    0x5374614D //'StaM'
-#define  cmsSigDN                         0x444E2020 //'DN  '
-#define  cmsSigDNP                        0x444E2050 //'DN P'
-#define  cmsSigDNN                        0x444E4E20 //'DNN '
-#define  cmsSigDNNP                       0x444E4E50 //'DNNP'
-
-// Device attributes, currently defined values correspond to the low 4 bytes
-// of the 8 byte attribute quantity
-#define cmsReflective     0
-#define cmsTransparency   1
-#define cmsGlossy         0
-#define cmsMatte          2
-
-// Common structures in ICC tags
-typedef struct {
-    cmsUInt32Number len;
-    cmsUInt32Number flag;
-    cmsUInt8Number  data[1];
-
-} cmsICCData;
-
-// ICC date time
-typedef struct {
-    cmsUInt16Number      year;
-    cmsUInt16Number      month;
-    cmsUInt16Number      day;
-    cmsUInt16Number      hours;
-    cmsUInt16Number      minutes;
-    cmsUInt16Number      seconds;
-
-} cmsDateTimeNumber;
-
-// ICC XYZ
-typedef struct {
-    cmsS15Fixed16Number  X;
-    cmsS15Fixed16Number  Y;
-    cmsS15Fixed16Number  Z;
-
-} cmsEncodedXYZNumber;
-
-
-// Profile ID as computed by MD5 algorithm
-typedef union {
-    cmsUInt8Number       ID8[16];
-    cmsUInt16Number      ID16[8];
-    cmsUInt32Number      ID32[4];
-
-} cmsProfileID;
-
-
-// ----------------------------------------------------------------------------------------------
-// ICC profile internal base types. Strictly, shouldn't be declared in this header, but maybe
-// somebody want to use this info for accessing profile header directly, so here it is.
-
-// Profile header -- it is 32-bit aligned, so no issues are expected on alignment
-typedef struct {
-    cmsUInt32Number              size;           // Profile size in bytes
-    cmsSignature                 cmmId;          // CMM for this profile
-    cmsUInt32Number              version;        // Format version number
-    cmsProfileClassSignature     deviceClass;    // Type of profile
-    cmsColorSpaceSignature       colorSpace;     // Color space of data
-    cmsColorSpaceSignature       pcs;            // PCS, XYZ or Lab only
-    cmsDateTimeNumber            date;           // Date profile was created
-    cmsSignature                 magic;          // Magic Number to identify an ICC profile
-    cmsPlatformSignature         platform;       // Primary Platform
-    cmsUInt32Number              flags;          // Various bit settings
-    cmsSignature                 manufacturer;   // Device manufacturer
-    cmsUInt32Number              model;          // Device model number
-    cmsUInt64Number              attributes;     // Device attributes
-    cmsUInt32Number              renderingIntent;// Rendering intent
-    cmsEncodedXYZNumber          illuminant;     // Profile illuminant
-    cmsSignature                 creator;        // Profile creator
-    cmsProfileID                 profileID;      // Profile ID using MD5
-    cmsInt8Number                reserved[28];   // Reserved for future use
-
-} cmsICCHeader;
-
-// ICC base tag
-typedef struct {
-    cmsTagTypeSignature  sig;
-    cmsInt8Number        reserved[4];
-
-} cmsTagBase;
-
-// A tag entry in directory
-typedef struct {
-    cmsTagSignature      sig;            // The tag signature
-    cmsUInt32Number      offset;         // Start of tag
-    cmsUInt32Number      size;           // Size in bytes
-
-} cmsTagEntry;
-
-// ----------------------------------------------------------------------------------------------
-
-// Little CMS specific typedefs
-
-typedef void* cmsHANDLE ;              // Generic handle
-typedef void* cmsHPROFILE;             // Opaque typedefs to hide internals
-typedef void* cmsHTRANSFORM;
-
-#define cmsMAXCHANNELS  16                // Maximum number of channels in ICC profiles
-
-// Format of pixel is defined by one cmsUInt32Number, using bit fields as follows
-//
-//                               2                1          0
-//                          3 2 10987 6 5 4 3 2 1 098 7654 321
-//                          A O TTTTT U Y F P X S EEE CCCC BBB
-//
-//            A: Floating point -- With this flag we can differentiate 16 bits as float and as int
-//            O: Optimized -- previous optimization already returns the final 8-bit value
-//            T: Pixeltype
-//            F: Flavor  0=MinIsBlack(Chocolate) 1=MinIsWhite(Vanilla)
-//            P: Planar? 0=Chunky, 1=Planar
-//            X: swap 16 bps endianess?
-//            S: Do swap? ie, BGR, KYMC
-//            E: Extra samples
-//            C: Channels (Samples per pixel)
-//            B: bytes per sample
-//            Y: Swap first - changes ABGR to BGRA and KCMY to CMYK
-
-#define FLOAT_SH(a)            ((a) << 22)
-#define OPTIMIZED_SH(s)        ((s) << 21)
-#define COLORSPACE_SH(s)       ((s) << 16)
-#define SWAPFIRST_SH(s)        ((s) << 14)
-#define FLAVOR_SH(s)           ((s) << 13)
-#define PLANAR_SH(p)           ((p) << 12)
-#define ENDIAN16_SH(e)         ((e) << 11)
-#define DOSWAP_SH(e)           ((e) << 10)
-#define EXTRA_SH(e)            ((e) << 7)
-#define CHANNELS_SH(c)         ((c) << 3)
-#define BYTES_SH(b)            (b)
-
-// These macros unpack format specifiers into integers
-#define T_FLOAT(a)            (((a)>>22)&1)
-#define T_OPTIMIZED(o)        (((o)>>21)&1)
-#define T_COLORSPACE(s)       (((s)>>16)&31)
-#define T_SWAPFIRST(s)        (((s)>>14)&1)
-#define T_FLAVOR(s)           (((s)>>13)&1)
-#define T_PLANAR(p)           (((p)>>12)&1)
-#define T_ENDIAN16(e)         (((e)>>11)&1)
-#define T_DOSWAP(e)           (((e)>>10)&1)
-#define T_EXTRA(e)            (((e)>>7)&7)
-#define T_CHANNELS(c)         (((c)>>3)&15)
-#define T_BYTES(b)            ((b)&7)
-
-
-// Pixel types
-#define PT_ANY       0    // Don't check colorspace
-                          // 1 & 2 are reserved
-#define PT_GRAY      3
-#define PT_RGB       4
-#define PT_CMY       5
-#define PT_CMYK      6
-#define PT_YCbCr     7
-#define PT_YUV       8      // Lu'v'
-#define PT_XYZ       9
-#define PT_Lab       10
-#define PT_YUVK      11     // Lu'v'K
-#define PT_HSV       12
-#define PT_HLS       13
-#define PT_Yxy       14
-
-#define PT_MCH1      15
-#define PT_MCH2      16
-#define PT_MCH3      17
-#define PT_MCH4      18
-#define PT_MCH5      19
-#define PT_MCH6      20
-#define PT_MCH7      21
-#define PT_MCH8      22
-#define PT_MCH9      23
-#define PT_MCH10     24
-#define PT_MCH11     25
-#define PT_MCH12     26
-#define PT_MCH13     27
-#define PT_MCH14     28
-#define PT_MCH15     29
-
-#define PT_LabV2     30     // Identical to PT_Lab, but using the V2 old encoding
-
-// Some (not all!) representations
-
-#ifndef TYPE_RGB_8      // TYPE_RGB_8 is a very common identifier, so don't include ours
-                        // if user has it already defined.
-
-#define TYPE_GRAY_8            (COLORSPACE_SH(PT_GRAY)|CHANNELS_SH(1)|BYTES_SH(1))
-#define TYPE_GRAY_8_REV        (COLORSPACE_SH(PT_GRAY)|CHANNELS_SH(1)|BYTES_SH(1)|FLAVOR_SH(1))
-#define TYPE_GRAY_16           (COLORSPACE_SH(PT_GRAY)|CHANNELS_SH(1)|BYTES_SH(2))
-#define TYPE_GRAY_16_REV       (COLORSPACE_SH(PT_GRAY)|CHANNELS_SH(1)|BYTES_SH(2)|FLAVOR_SH(1))
-#define TYPE_GRAY_16_SE        (COLORSPACE_SH(PT_GRAY)|CHANNELS_SH(1)|BYTES_SH(2)|ENDIAN16_SH(1))
-#define TYPE_GRAYA_8           (COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|BYTES_SH(1))
-#define TYPE_GRAYA_16          (COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|BYTES_SH(2))
-#define TYPE_GRAYA_16_SE       (COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|BYTES_SH(2)|ENDIAN16_SH(1))
-#define TYPE_GRAYA_8_PLANAR    (COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|BYTES_SH(1)|PLANAR_SH(1))
-#define TYPE_GRAYA_16_PLANAR   (COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|BYTES_SH(2)|PLANAR_SH(1))
-
-#define TYPE_RGB_8             (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(1))
-#define TYPE_RGB_8_PLANAR      (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(1)|PLANAR_SH(1))
-#define TYPE_BGR_8             (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(1)|DOSWAP_SH(1))
-#define TYPE_BGR_8_PLANAR      (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(1)|DOSWAP_SH(1)|PLANAR_SH(1))
-#define TYPE_RGB_16            (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(2))
-#define TYPE_RGB_16_PLANAR     (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(2)|PLANAR_SH(1))
-#define TYPE_RGB_16_SE         (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(2)|ENDIAN16_SH(1))
-#define TYPE_BGR_16            (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1))
-#define TYPE_BGR_16_PLANAR     (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1)|PLANAR_SH(1))
-#define TYPE_BGR_16_SE         (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1))
-
-#define TYPE_RGBA_8            (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(1))
-#define TYPE_RGBA_8_PLANAR     (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(1)|PLANAR_SH(1))
-#define TYPE_RGBA_16           (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2))
-#define TYPE_RGBA_16_PLANAR    (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|PLANAR_SH(1))
-#define TYPE_RGBA_16_SE        (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|ENDIAN16_SH(1))
-
-#define TYPE_ARGB_8            (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(1)|SWAPFIRST_SH(1))
-#define TYPE_ARGB_8_PLANAR     (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(1)|SWAPFIRST_SH(1)|PLANAR_SH(1))
-#define TYPE_ARGB_16           (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|SWAPFIRST_SH(1))
-
-#define TYPE_ABGR_8            (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(1)|DOSWAP_SH(1))
-#define TYPE_ABGR_8_PLANAR     (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(1)|DOSWAP_SH(1)|PLANAR_SH(1))
-#define TYPE_ABGR_16           (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1))
-#define TYPE_ABGR_16_PLANAR    (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1)|PLANAR_SH(1))
-#define TYPE_ABGR_16_SE        (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1))
-
-#define TYPE_BGRA_8            (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(1)|DOSWAP_SH(1)|SWAPFIRST_SH(1))
-#define TYPE_BGRA_8_PLANAR     (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(1)|DOSWAP_SH(1)|SWAPFIRST_SH(1)|PLANAR_SH(1))
-#define TYPE_BGRA_16           (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1)|SWAPFIRST_SH(1))
-#define TYPE_BGRA_16_SE        (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|ENDIAN16_SH(1)|DOSWAP_SH(1)|SWAPFIRST_SH(1))
-
-#define TYPE_CMY_8             (COLORSPACE_SH(PT_CMY)|CHANNELS_SH(3)|BYTES_SH(1))
-#define TYPE_CMY_8_PLANAR      (COLORSPACE_SH(PT_CMY)|CHANNELS_SH(3)|BYTES_SH(1)|PLANAR_SH(1))
-#define TYPE_CMY_16            (COLORSPACE_SH(PT_CMY)|CHANNELS_SH(3)|BYTES_SH(2))
-#define TYPE_CMY_16_PLANAR     (COLORSPACE_SH(PT_CMY)|CHANNELS_SH(3)|BYTES_SH(2)|PLANAR_SH(1))
-#define TYPE_CMY_16_SE         (COLORSPACE_SH(PT_CMY)|CHANNELS_SH(3)|BYTES_SH(2)|ENDIAN16_SH(1))
-
-#define TYPE_CMYK_8            (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(1))
-#define TYPE_CMYKA_8           (COLORSPACE_SH(PT_CMYK)|EXTRA_SH(1)|CHANNELS_SH(4)|BYTES_SH(1))
-#define TYPE_CMYK_8_REV        (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(1)|FLAVOR_SH(1))
-#define TYPE_YUVK_8            TYPE_CMYK_8_REV
-#define TYPE_CMYK_8_PLANAR     (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(1)|PLANAR_SH(1))
-#define TYPE_CMYK_16           (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2))
-#define TYPE_CMYK_16_REV       (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|FLAVOR_SH(1))
-#define TYPE_YUVK_16           TYPE_CMYK_16_REV
-#define TYPE_CMYK_16_PLANAR    (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|PLANAR_SH(1))
-#define TYPE_CMYK_16_SE        (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|ENDIAN16_SH(1))
-
-#define TYPE_KYMC_8            (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(1)|DOSWAP_SH(1))
-#define TYPE_KYMC_16           (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|DOSWAP_SH(1))
-#define TYPE_KYMC_16_SE        (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1))
-
-#define TYPE_KCMY_8            (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(1)|SWAPFIRST_SH(1))
-#define TYPE_KCMY_8_REV        (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(1)|FLAVOR_SH(1)|SWAPFIRST_SH(1))
-#define TYPE_KCMY_16           (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|SWAPFIRST_SH(1))
-#define TYPE_KCMY_16_REV       (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|FLAVOR_SH(1)|SWAPFIRST_SH(1))
-#define TYPE_KCMY_16_SE        (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|ENDIAN16_SH(1)|SWAPFIRST_SH(1))
-
-#define TYPE_CMYK5_8           (COLORSPACE_SH(PT_MCH5)|CHANNELS_SH(5)|BYTES_SH(1))
-#define TYPE_CMYK5_16          (COLORSPACE_SH(PT_MCH5)|CHANNELS_SH(5)|BYTES_SH(2))
-#define TYPE_CMYK5_16_SE       (COLORSPACE_SH(PT_MCH5)|CHANNELS_SH(5)|BYTES_SH(2)|ENDIAN16_SH(1))
-#define TYPE_KYMC5_8           (COLORSPACE_SH(PT_MCH5)|CHANNELS_SH(5)|BYTES_SH(1)|DOSWAP_SH(1))
-#define TYPE_KYMC5_16          (COLORSPACE_SH(PT_MCH5)|CHANNELS_SH(5)|BYTES_SH(2)|DOSWAP_SH(1))
-#define TYPE_KYMC5_16_SE       (COLORSPACE_SH(PT_MCH5)|CHANNELS_SH(5)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1))
-#define TYPE_CMYK6_8           (COLORSPACE_SH(PT_MCH6)|CHANNELS_SH(6)|BYTES_SH(1))
-#define TYPE_CMYK6_8_PLANAR    (COLORSPACE_SH(PT_MCH6)|CHANNELS_SH(6)|BYTES_SH(1)|PLANAR_SH(1))
-#define TYPE_CMYK6_16          (COLORSPACE_SH(PT_MCH6)|CHANNELS_SH(6)|BYTES_SH(2))
-#define TYPE_CMYK6_16_PLANAR   (COLORSPACE_SH(PT_MCH6)|CHANNELS_SH(6)|BYTES_SH(2)|PLANAR_SH(1))
-#define TYPE_CMYK6_16_SE       (COLORSPACE_SH(PT_MCH6)|CHANNELS_SH(6)|BYTES_SH(2)|ENDIAN16_SH(1))
-#define TYPE_CMYK7_8           (COLORSPACE_SH(PT_MCH7)|CHANNELS_SH(7)|BYTES_SH(1))
-#define TYPE_CMYK7_16          (COLORSPACE_SH(PT_MCH7)|CHANNELS_SH(7)|BYTES_SH(2))
-#define TYPE_CMYK7_16_SE       (COLORSPACE_SH(PT_MCH7)|CHANNELS_SH(7)|BYTES_SH(2)|ENDIAN16_SH(1))
-#define TYPE_KYMC7_8           (COLORSPACE_SH(PT_MCH7)|CHANNELS_SH(7)|BYTES_SH(1)|DOSWAP_SH(1))
-#define TYPE_KYMC7_16          (COLORSPACE_SH(PT_MCH7)|CHANNELS_SH(7)|BYTES_SH(2)|DOSWAP_SH(1))
-#define TYPE_KYMC7_16_SE       (COLORSPACE_SH(PT_MCH7)|CHANNELS_SH(7)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1))
-#define TYPE_CMYK8_8           (COLORSPACE_SH(PT_MCH8)|CHANNELS_SH(8)|BYTES_SH(1))
-#define TYPE_CMYK8_16          (COLORSPACE_SH(PT_MCH8)|CHANNELS_SH(8)|BYTES_SH(2))
-#define TYPE_CMYK8_16_SE       (COLORSPACE_SH(PT_MCH8)|CHANNELS_SH(8)|BYTES_SH(2)|ENDIAN16_SH(1))
-#define TYPE_KYMC8_8           (COLORSPACE_SH(PT_MCH8)|CHANNELS_SH(8)|BYTES_SH(1)|DOSWAP_SH(1))
-#define TYPE_KYMC8_16          (COLORSPACE_SH(PT_MCH8)|CHANNELS_SH(8)|BYTES_SH(2)|DOSWAP_SH(1))
-#define TYPE_KYMC8_16_SE       (COLORSPACE_SH(PT_MCH8)|CHANNELS_SH(8)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1))
-#define TYPE_CMYK9_8           (COLORSPACE_SH(PT_MCH9)|CHANNELS_SH(9)|BYTES_SH(1))
-#define TYPE_CMYK9_16          (COLORSPACE_SH(PT_MCH9)|CHANNELS_SH(9)|BYTES_SH(2))
-#define TYPE_CMYK9_16_SE       (COLORSPACE_SH(PT_MCH9)|CHANNELS_SH(9)|BYTES_SH(2)|ENDIAN16_SH(1))
-#define TYPE_KYMC9_8           (COLORSPACE_SH(PT_MCH9)|CHANNELS_SH(9)|BYTES_SH(1)|DOSWAP_SH(1))
-#define TYPE_KYMC9_16          (COLORSPACE_SH(PT_MCH9)|CHANNELS_SH(9)|BYTES_SH(2)|DOSWAP_SH(1))
-#define TYPE_KYMC9_16_SE       (COLORSPACE_SH(PT_MCH9)|CHANNELS_SH(9)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1))
-#define TYPE_CMYK10_8          (COLORSPACE_SH(PT_MCH10)|CHANNELS_SH(10)|BYTES_SH(1))
-#define TYPE_CMYK10_16         (COLORSPACE_SH(PT_MCH10)|CHANNELS_SH(10)|BYTES_SH(2))
-#define TYPE_CMYK10_16_SE      (COLORSPACE_SH(PT_MCH10)|CHANNELS_SH(10)|BYTES_SH(2)|ENDIAN16_SH(1))
-#define TYPE_KYMC10_8          (COLORSPACE_SH(PT_MCH10)|CHANNELS_SH(10)|BYTES_SH(1)|DOSWAP_SH(1))
-#define TYPE_KYMC10_16         (COLORSPACE_SH(PT_MCH10)|CHANNELS_SH(10)|BYTES_SH(2)|DOSWAP_SH(1))
-#define TYPE_KYMC10_16_SE      (COLORSPACE_SH(PT_MCH10)|CHANNELS_SH(10)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1))
-#define TYPE_CMYK11_8          (COLORSPACE_SH(PT_MCH11)|CHANNELS_SH(11)|BYTES_SH(1))
-#define TYPE_CMYK11_16         (COLORSPACE_SH(PT_MCH11)|CHANNELS_SH(11)|BYTES_SH(2))
-#define TYPE_CMYK11_16_SE      (COLORSPACE_SH(PT_MCH11)|CHANNELS_SH(11)|BYTES_SH(2)|ENDIAN16_SH(1))
-#define TYPE_KYMC11_8          (COLORSPACE_SH(PT_MCH11)|CHANNELS_SH(11)|BYTES_SH(1)|DOSWAP_SH(1))
-#define TYPE_KYMC11_16         (COLORSPACE_SH(PT_MCH11)|CHANNELS_SH(11)|BYTES_SH(2)|DOSWAP_SH(1))
-#define TYPE_KYMC11_16_SE      (COLORSPACE_SH(PT_MCH11)|CHANNELS_SH(11)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1))
-#define TYPE_CMYK12_8          (COLORSPACE_SH(PT_MCH12)|CHANNELS_SH(12)|BYTES_SH(1))
-#define TYPE_CMYK12_16         (COLORSPACE_SH(PT_MCH12)|CHANNELS_SH(12)|BYTES_SH(2))
-#define TYPE_CMYK12_16_SE      (COLORSPACE_SH(PT_MCH12)|CHANNELS_SH(12)|BYTES_SH(2)|ENDIAN16_SH(1))
-#define TYPE_KYMC12_8          (COLORSPACE_SH(PT_MCH12)|CHANNELS_SH(12)|BYTES_SH(1)|DOSWAP_SH(1))
-#define TYPE_KYMC12_16         (COLORSPACE_SH(PT_MCH12)|CHANNELS_SH(12)|BYTES_SH(2)|DOSWAP_SH(1))
-#define TYPE_KYMC12_16_SE      (COLORSPACE_SH(PT_MCH12)|CHANNELS_SH(12)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1))
-
-// Colorimetric
-#define TYPE_XYZ_16            (COLORSPACE_SH(PT_XYZ)|CHANNELS_SH(3)|BYTES_SH(2))
-#define TYPE_Lab_8             (COLORSPACE_SH(PT_Lab)|CHANNELS_SH(3)|BYTES_SH(1))
-#define TYPE_LabV2_8           (COLORSPACE_SH(PT_LabV2)|CHANNELS_SH(3)|BYTES_SH(1))
-
-#define TYPE_ALab_8            (COLORSPACE_SH(PT_Lab)|CHANNELS_SH(3)|BYTES_SH(1)|EXTRA_SH(1)|SWAPFIRST_SH(1))
-#define TYPE_ALabV2_8          (COLORSPACE_SH(PT_LabV2)|CHANNELS_SH(3)|BYTES_SH(1)|EXTRA_SH(1)|SWAPFIRST_SH(1))
-#define TYPE_Lab_16            (COLORSPACE_SH(PT_Lab)|CHANNELS_SH(3)|BYTES_SH(2))
-#define TYPE_LabV2_16          (COLORSPACE_SH(PT_LabV2)|CHANNELS_SH(3)|BYTES_SH(2))
-#define TYPE_Yxy_16            (COLORSPACE_SH(PT_Yxy)|CHANNELS_SH(3)|BYTES_SH(2))
-
-// YCbCr
-#define TYPE_YCbCr_8           (COLORSPACE_SH(PT_YCbCr)|CHANNELS_SH(3)|BYTES_SH(1))
-#define TYPE_YCbCr_8_PLANAR    (COLORSPACE_SH(PT_YCbCr)|CHANNELS_SH(3)|BYTES_SH(1)|PLANAR_SH(1))
-#define TYPE_YCbCr_16          (COLORSPACE_SH(PT_YCbCr)|CHANNELS_SH(3)|BYTES_SH(2))
-#define TYPE_YCbCr_16_PLANAR   (COLORSPACE_SH(PT_YCbCr)|CHANNELS_SH(3)|BYTES_SH(2)|PLANAR_SH(1))
-#define TYPE_YCbCr_16_SE       (COLORSPACE_SH(PT_YCbCr)|CHANNELS_SH(3)|BYTES_SH(2)|ENDIAN16_SH(1))
-
-// YUV
-#define TYPE_YUV_8             (COLORSPACE_SH(PT_YUV)|CHANNELS_SH(3)|BYTES_SH(1))
-#define TYPE_YUV_8_PLANAR      (COLORSPACE_SH(PT_YUV)|CHANNELS_SH(3)|BYTES_SH(1)|PLANAR_SH(1))
-#define TYPE_YUV_16            (COLORSPACE_SH(PT_YUV)|CHANNELS_SH(3)|BYTES_SH(2))
-#define TYPE_YUV_16_PLANAR     (COLORSPACE_SH(PT_YUV)|CHANNELS_SH(3)|BYTES_SH(2)|PLANAR_SH(1))
-#define TYPE_YUV_16_SE         (COLORSPACE_SH(PT_YUV)|CHANNELS_SH(3)|BYTES_SH(2)|ENDIAN16_SH(1))
-
-// HLS
-#define TYPE_HLS_8             (COLORSPACE_SH(PT_HLS)|CHANNELS_SH(3)|BYTES_SH(1))
-#define TYPE_HLS_8_PLANAR      (COLORSPACE_SH(PT_HLS)|CHANNELS_SH(3)|BYTES_SH(1)|PLANAR_SH(1))
-#define TYPE_HLS_16            (COLORSPACE_SH(PT_HLS)|CHANNELS_SH(3)|BYTES_SH(2))
-#define TYPE_HLS_16_PLANAR     (COLORSPACE_SH(PT_HLS)|CHANNELS_SH(3)|BYTES_SH(2)|PLANAR_SH(1))
-#define TYPE_HLS_16_SE         (COLORSPACE_SH(PT_HLS)|CHANNELS_SH(3)|BYTES_SH(2)|ENDIAN16_SH(1))
-
-// HSV
-#define TYPE_HSV_8             (COLORSPACE_SH(PT_HSV)|CHANNELS_SH(3)|BYTES_SH(1))
-#define TYPE_HSV_8_PLANAR      (COLORSPACE_SH(PT_HSV)|CHANNELS_SH(3)|BYTES_SH(1)|PLANAR_SH(1))
-#define TYPE_HSV_16            (COLORSPACE_SH(PT_HSV)|CHANNELS_SH(3)|BYTES_SH(2))
-#define TYPE_HSV_16_PLANAR     (COLORSPACE_SH(PT_HSV)|CHANNELS_SH(3)|BYTES_SH(2)|PLANAR_SH(1))
-#define TYPE_HSV_16_SE         (COLORSPACE_SH(PT_HSV)|CHANNELS_SH(3)|BYTES_SH(2)|ENDIAN16_SH(1))
-
-// Named color index. Only 16 bits allowed (don't check colorspace)
-#define TYPE_NAMED_COLOR_INDEX (CHANNELS_SH(1)|BYTES_SH(2))
-
-// Float formatters.
-#define TYPE_XYZ_FLT          (FLOAT_SH(1)|COLORSPACE_SH(PT_XYZ)|CHANNELS_SH(3)|BYTES_SH(4))
-#define TYPE_Lab_FLT          (FLOAT_SH(1)|COLORSPACE_SH(PT_Lab)|CHANNELS_SH(3)|BYTES_SH(4))
-#define TYPE_LabA_FLT         (FLOAT_SH(1)|COLORSPACE_SH(PT_Lab)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(4))
-#define TYPE_GRAY_FLT         (FLOAT_SH(1)|COLORSPACE_SH(PT_GRAY)|CHANNELS_SH(1)|BYTES_SH(4))
-#define TYPE_RGB_FLT          (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(4))
-
-#define TYPE_RGBA_FLT         (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(4))
-#define TYPE_ARGB_FLT         (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(4)|SWAPFIRST_SH(1))
-#define TYPE_BGR_FLT          (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(4)|DOSWAP_SH(1))
-#define TYPE_BGRA_FLT         (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(4)|DOSWAP_SH(1)|SWAPFIRST_SH(1))
-#define TYPE_ABGR_FLT         (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(4)|DOSWAP_SH(1))
-
-#define TYPE_CMYK_FLT         (FLOAT_SH(1)|COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(4))
-
-// Floating point formatters.
-// NOTE THAT 'BYTES' FIELD IS SET TO ZERO ON DLB because 8 bytes overflows the bitfield
-#define TYPE_XYZ_DBL          (FLOAT_SH(1)|COLORSPACE_SH(PT_XYZ)|CHANNELS_SH(3)|BYTES_SH(0))
-#define TYPE_Lab_DBL          (FLOAT_SH(1)|COLORSPACE_SH(PT_Lab)|CHANNELS_SH(3)|BYTES_SH(0))
-#define TYPE_GRAY_DBL         (FLOAT_SH(1)|COLORSPACE_SH(PT_GRAY)|CHANNELS_SH(1)|BYTES_SH(0))
-#define TYPE_RGB_DBL          (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(0))
-#define TYPE_BGR_DBL          (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(0)|DOSWAP_SH(1))
-#define TYPE_CMYK_DBL         (FLOAT_SH(1)|COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(0))
-
-// IEEE 754-2008 "half"
-#define TYPE_GRAY_HALF_FLT    (FLOAT_SH(1)|COLORSPACE_SH(PT_GRAY)|CHANNELS_SH(1)|BYTES_SH(2))
-#define TYPE_RGB_HALF_FLT     (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(2))
-#define TYPE_RGBA_HALF_FLT    (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2))
-#define TYPE_CMYK_HALF_FLT    (FLOAT_SH(1)|COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2))
-
-#define TYPE_RGBA_HALF_FLT    (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2))
-#define TYPE_ARGB_HALF_FLT    (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|SWAPFIRST_SH(1))
-#define TYPE_BGR_HALF_FLT     (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1))
-#define TYPE_BGRA_HALF_FLT    (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1)|SWAPFIRST_SH(1))
-#define TYPE_ABGR_HALF_FLT    (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1))
-
-#endif
-
-// Colorspaces
-typedef struct {
-        cmsFloat64Number X;
-        cmsFloat64Number Y;
-        cmsFloat64Number Z;
-
-    } cmsCIEXYZ;
-
-typedef struct {
-        cmsFloat64Number x;
-        cmsFloat64Number y;
-        cmsFloat64Number Y;
-
-    } cmsCIExyY;
-
-typedef struct {
-        cmsFloat64Number L;
-        cmsFloat64Number a;
-        cmsFloat64Number b;
-
-    } cmsCIELab;
-
-typedef struct {
-        cmsFloat64Number L;
-        cmsFloat64Number C;
-        cmsFloat64Number h;
-
-    } cmsCIELCh;
-
-typedef struct {
-        cmsFloat64Number J;
-        cmsFloat64Number C;
-        cmsFloat64Number h;
-
-    } cmsJCh;
-
-typedef struct {
-        cmsCIEXYZ  Red;
-        cmsCIEXYZ  Green;
-        cmsCIEXYZ  Blue;
-
-    } cmsCIEXYZTRIPLE;
-
-typedef struct {
-        cmsCIExyY  Red;
-        cmsCIExyY  Green;
-        cmsCIExyY  Blue;
-
-    } cmsCIExyYTRIPLE;
-
-// Illuminant types for structs below
-#define cmsILLUMINANT_TYPE_UNKNOWN 0x0000000
-#define cmsILLUMINANT_TYPE_D50     0x0000001
-#define cmsILLUMINANT_TYPE_D65     0x0000002
-#define cmsILLUMINANT_TYPE_D93     0x0000003
-#define cmsILLUMINANT_TYPE_F2      0x0000004
-#define cmsILLUMINANT_TYPE_D55     0x0000005
-#define cmsILLUMINANT_TYPE_A       0x0000006
-#define cmsILLUMINANT_TYPE_E       0x0000007
-#define cmsILLUMINANT_TYPE_F8      0x0000008
-
-typedef struct {
-        cmsUInt32Number  Observer;    // 0 = unknown, 1=CIE 1931, 2=CIE 1964
-        cmsCIEXYZ        Backing;     // Value of backing
-        cmsUInt32Number  Geometry;    // 0=unknown, 1=45/0, 0/45 2=0d, d/0
-        cmsFloat64Number Flare;       // 0..1.0
-        cmsUInt32Number  IlluminantType;
-
-    } cmsICCMeasurementConditions;
-
-typedef struct {
-        cmsCIEXYZ       IlluminantXYZ;   // Not the same struct as CAM02,
-        cmsCIEXYZ       SurroundXYZ;     // This is for storing the tag
-        cmsUInt32Number IlluminantType;  // viewing condition
-
-    } cmsICCViewingConditions;
-
-// Support of non-standard functions --------------------------------------------------------------------------------------
-
-CMSAPI int               CMSEXPORT cmsstrcasecmp(const char* s1, const char* s2);
-CMSAPI long int          CMSEXPORT cmsfilelength(FILE* f);
-
-
-// Context handling --------------------------------------------------------------------------------------------------------
-
-// Each context holds its owns globals and its own plug-ins. There is a global context with the id = 0 for lecacy compatibility
-// though using the global context is not recomended. Proper context handling makes lcms more thread-safe.
-
-typedef struct _cmsContext_struct* cmsContext;
-
-CMSAPI cmsContext       CMSEXPORT cmsCreateContext(void* Plugin, void* UserData);
-CMSAPI void             CMSEXPORT cmsDeleteContext(cmsContext ContexID);
-CMSAPI cmsContext       CMSEXPORT cmsDupContext(cmsContext ContextID, void* NewUserData);
-CMSAPI void*            CMSEXPORT cmsGetContextUserData(cmsContext ContextID);
-
-// Plug-In registering  --------------------------------------------------------------------------------------------------
-
-CMSAPI cmsBool           CMSEXPORT cmsPlugin(void* Plugin);
-CMSAPI cmsBool           CMSEXPORT cmsPluginTHR(cmsContext ContextID, void* Plugin);
-CMSAPI void              CMSEXPORT cmsUnregisterPlugins(void);
-CMSAPI void              CMSEXPORT cmsUnregisterPluginsTHR(cmsContext ContextID);
-
-// Error logging ----------------------------------------------------------------------------------------------------------
-
-// There is no error handling at all. When a function fails, it returns proper value.
-// For example, all create functions does return NULL on failure. Other may return FALSE.
-// It may be interesting, for the developer, to know why the function is failing.
-// for that reason, lcms2 does offer a logging function. This function will get
-// an ENGLISH string with some clues on what is going wrong. You can show this
-// info to the end user if you wish, or just create some sort of log on disk.
-// The logging function should NOT terminate the program, as this obviously can leave
-// unfreed resources. It is the programmer's responsibility to check each function
-// return code to make sure it didn't fail.
-
-#define cmsERROR_UNDEFINED                    0
-#define cmsERROR_FILE                         1
-#define cmsERROR_RANGE                        2
-#define cmsERROR_INTERNAL                     3
-#define cmsERROR_NULL                         4
-#define cmsERROR_READ                         5
-#define cmsERROR_SEEK                         6
-#define cmsERROR_WRITE                        7
-#define cmsERROR_UNKNOWN_EXTENSION            8
-#define cmsERROR_COLORSPACE_CHECK             9
-#define cmsERROR_ALREADY_DEFINED              10
-#define cmsERROR_BAD_SIGNATURE                11
-#define cmsERROR_CORRUPTION_DETECTED          12
-#define cmsERROR_NOT_SUITABLE                 13
-
-// Error logger is called with the ContextID when a message is raised. This gives the
-// chance to know which thread is responsible of the warning and any environment associated
-// with it. Non-multithreading applications may safely ignore this parameter.
-// Note that under certain special circumstances, ContextID may be NULL.
-typedef void  (* cmsLogErrorHandlerFunction)(cmsContext ContextID, cmsUInt32Number ErrorCode, const char *Text);
-
-// Allows user to set any specific logger
-CMSAPI void              CMSEXPORT cmsSetLogErrorHandler(cmsLogErrorHandlerFunction Fn);
-CMSAPI void              CMSEXPORT cmsSetLogErrorHandlerTHR(cmsContext ContextID, cmsLogErrorHandlerFunction Fn);
-
-// Conversions --------------------------------------------------------------------------------------------------------------
-
-// Returns pointers to constant structs
-CMSAPI const cmsCIEXYZ*  CMSEXPORT cmsD50_XYZ(void);
-CMSAPI const cmsCIExyY*  CMSEXPORT cmsD50_xyY(void);
-
-// Colorimetric space conversions
-CMSAPI void              CMSEXPORT cmsXYZ2xyY(cmsCIExyY* Dest, const cmsCIEXYZ* Source);
-CMSAPI void              CMSEXPORT cmsxyY2XYZ(cmsCIEXYZ* Dest, const cmsCIExyY* Source);
-CMSAPI void              CMSEXPORT cmsXYZ2Lab(const cmsCIEXYZ* WhitePoint, cmsCIELab* Lab, const cmsCIEXYZ* xyz);
-CMSAPI void              CMSEXPORT cmsLab2XYZ(const cmsCIEXYZ* WhitePoint, cmsCIEXYZ* xyz, const cmsCIELab* Lab);
-CMSAPI void              CMSEXPORT cmsLab2LCh(cmsCIELCh*LCh, const cmsCIELab* Lab);
-CMSAPI void              CMSEXPORT cmsLCh2Lab(cmsCIELab* Lab, const cmsCIELCh* LCh);
-
-// Encoding /Decoding on PCS
-CMSAPI void              CMSEXPORT cmsLabEncoded2Float(cmsCIELab* Lab, const cmsUInt16Number wLab[3]);
-CMSAPI void              CMSEXPORT cmsLabEncoded2FloatV2(cmsCIELab* Lab, const cmsUInt16Number wLab[3]);
-CMSAPI void              CMSEXPORT cmsFloat2LabEncoded(cmsUInt16Number wLab[3], const cmsCIELab* Lab);
-CMSAPI void              CMSEXPORT cmsFloat2LabEncodedV2(cmsUInt16Number wLab[3], const cmsCIELab* Lab);
-CMSAPI void              CMSEXPORT cmsXYZEncoded2Float(cmsCIEXYZ* fxyz, const cmsUInt16Number XYZ[3]);
-CMSAPI void              CMSEXPORT cmsFloat2XYZEncoded(cmsUInt16Number XYZ[3], const cmsCIEXYZ* fXYZ);
-
-// DeltaE metrics
-CMSAPI cmsFloat64Number  CMSEXPORT cmsDeltaE(const cmsCIELab* Lab1, const cmsCIELab* Lab2);
-CMSAPI cmsFloat64Number  CMSEXPORT cmsCIE94DeltaE(const cmsCIELab* Lab1, const cmsCIELab* Lab2);
-CMSAPI cmsFloat64Number  CMSEXPORT cmsBFDdeltaE(const cmsCIELab* Lab1, const cmsCIELab* Lab2);
-CMSAPI cmsFloat64Number  CMSEXPORT cmsCMCdeltaE(const cmsCIELab* Lab1, const cmsCIELab* Lab2, cmsFloat64Number l, cmsFloat64Number c);
-CMSAPI cmsFloat64Number  CMSEXPORT cmsCIE2000DeltaE(const cmsCIELab* Lab1, const cmsCIELab* Lab2, cmsFloat64Number Kl, cmsFloat64Number Kc, cmsFloat64Number Kh);
-
-// Temperature <-> Chromaticity (Black body)
-CMSAPI cmsBool           CMSEXPORT cmsWhitePointFromTemp(cmsCIExyY* WhitePoint, cmsFloat64Number  TempK);
-CMSAPI cmsBool           CMSEXPORT cmsTempFromWhitePoint(cmsFloat64Number* TempK, const cmsCIExyY* WhitePoint);
-
-// Chromatic adaptation
-CMSAPI cmsBool           CMSEXPORT cmsAdaptToIlluminant(cmsCIEXYZ* Result, const cmsCIEXYZ* SourceWhitePt,
-                                                                           const cmsCIEXYZ* Illuminant,
-                                                                           const cmsCIEXYZ* Value);
-
-// CIECAM02 ---------------------------------------------------------------------------------------------------
-
-// Viewing conditions. Please note those are CAM model viewing conditions, and not the ICC tag viewing
-// conditions, which I'm naming cmsICCViewingConditions to make differences evident. Unfortunately, the tag
-// cannot deal with surround La, Yb and D value so is basically useless to store CAM02 viewing conditions.
-
-
-#define AVG_SURROUND       1
-#define DIM_SURROUND       2
-#define DARK_SURROUND      3
-#define CUTSHEET_SURROUND  4
-
-#define D_CALCULATE        (-1)
-
-typedef struct {
-    cmsCIEXYZ        whitePoint;
-    cmsFloat64Number Yb;
-    cmsFloat64Number La;
-    int              surround;
-    cmsFloat64Number D_value;
-
-    } cmsViewingConditions;
-
-CMSAPI cmsHANDLE         CMSEXPORT cmsCIECAM02Init(cmsContext ContextID, const cmsViewingConditions* pVC);
-CMSAPI void              CMSEXPORT cmsCIECAM02Done(cmsHANDLE hModel);
-CMSAPI void              CMSEXPORT cmsCIECAM02Forward(cmsHANDLE hModel, const cmsCIEXYZ* pIn, cmsJCh* pOut);
-CMSAPI void              CMSEXPORT cmsCIECAM02Reverse(cmsHANDLE hModel, const cmsJCh* pIn,    cmsCIEXYZ* pOut);
-
-
-// Tone curves -----------------------------------------------------------------------------------------
-
-// This describes a curve segment. For a table of supported types, see the manual. User can increase the number of
-// available types by using a proper plug-in. Parametric segments allow 10 parameters at most
-
-typedef struct {
-    cmsFloat32Number   x0, x1;           // Domain; for x0 < x <= x1
-    cmsInt32Number     Type;             // Parametric type, Type == 0 means sampled segment. Negative values are reserved
-    cmsFloat64Number   Params[10];       // Parameters if Type != 0
-    cmsUInt32Number    nGridPoints;      // Number of grid points if Type == 0
-    cmsFloat32Number*  SampledPoints;    // Points to an array of floats if Type == 0
-
-} cmsCurveSegment;
-
-// The internal representation is none of your business.
-typedef struct _cms_curve_struct cmsToneCurve;
-
-CMSAPI cmsToneCurve*     CMSEXPORT cmsBuildSegmentedToneCurve(cmsContext ContextID, cmsInt32Number nSegments, const cmsCurveSegment Segments[]);
-CMSAPI cmsToneCurve*     CMSEXPORT cmsBuildParametricToneCurve(cmsContext ContextID, cmsInt32Number Type, const cmsFloat64Number Params[]);
-CMSAPI cmsToneCurve*     CMSEXPORT cmsBuildGamma(cmsContext ContextID, cmsFloat64Number Gamma);
-CMSAPI cmsToneCurve*     CMSEXPORT cmsBuildTabulatedToneCurve16(cmsContext ContextID, cmsInt32Number nEntries, const cmsUInt16Number values[]);
-CMSAPI cmsToneCurve*     CMSEXPORT cmsBuildTabulatedToneCurveFloat(cmsContext ContextID, cmsUInt32Number nEntries, const cmsFloat32Number values[]);
-CMSAPI void              CMSEXPORT cmsFreeToneCurve(cmsToneCurve* Curve);
-CMSAPI void              CMSEXPORT cmsFreeToneCurveTriple(cmsToneCurve* Curve[3]);
-CMSAPI cmsToneCurve*     CMSEXPORT cmsDupToneCurve(const cmsToneCurve* Src);
-CMSAPI cmsToneCurve*     CMSEXPORT cmsReverseToneCurve(const cmsToneCurve* InGamma);
-CMSAPI cmsToneCurve*     CMSEXPORT cmsReverseToneCurveEx(cmsInt32Number nResultSamples, const cmsToneCurve* InGamma);
-CMSAPI cmsToneCurve*     CMSEXPORT cmsJoinToneCurve(cmsContext ContextID, const cmsToneCurve* X,  const cmsToneCurve* Y, cmsUInt32Number nPoints);
-CMSAPI cmsBool           CMSEXPORT cmsSmoothToneCurve(cmsToneCurve* Tab, cmsFloat64Number lambda);
-CMSAPI cmsFloat32Number  CMSEXPORT cmsEvalToneCurveFloat(const cmsToneCurve* Curve, cmsFloat32Number v);
-CMSAPI cmsUInt16Number   CMSEXPORT cmsEvalToneCurve16(const cmsToneCurve* Curve, cmsUInt16Number v);
-CMSAPI cmsBool           CMSEXPORT cmsIsToneCurveMultisegment(const cmsToneCurve* InGamma);
-CMSAPI cmsBool           CMSEXPORT cmsIsToneCurveLinear(const cmsToneCurve* Curve);
-CMSAPI cmsBool           CMSEXPORT cmsIsToneCurveMonotonic(const cmsToneCurve* t);
-CMSAPI cmsBool           CMSEXPORT cmsIsToneCurveDescending(const cmsToneCurve* t);
-CMSAPI cmsInt32Number    CMSEXPORT cmsGetToneCurveParametricType(const cmsToneCurve* t);
-CMSAPI cmsFloat64Number  CMSEXPORT cmsEstimateGamma(const cmsToneCurve* t, cmsFloat64Number Precision);
-
-// Tone curve tabular estimation
-CMSAPI cmsUInt32Number         CMSEXPORT cmsGetToneCurveEstimatedTableEntries(const cmsToneCurve* t);
-CMSAPI const cmsUInt16Number*  CMSEXPORT cmsGetToneCurveEstimatedTable(const cmsToneCurve* t);
-
-
-// Implements pipelines of multi-processing elements -------------------------------------------------------------
-
-// Nothing to see here, move along
-typedef struct _cmsPipeline_struct cmsPipeline;
-typedef struct _cmsStage_struct cmsStage;
-
-// Those are hi-level pipelines
-CMSAPI cmsPipeline*      CMSEXPORT cmsPipelineAlloc(cmsContext ContextID, cmsUInt32Number InputChannels, cmsUInt32Number OutputChannels);
-CMSAPI void              CMSEXPORT cmsPipelineFree(cmsPipeline* lut);
-CMSAPI cmsPipeline*      CMSEXPORT cmsPipelineDup(const cmsPipeline* Orig);
-
-CMSAPI cmsContext        CMSEXPORT cmsGetPipelineContextID(const cmsPipeline* lut);
-CMSAPI cmsUInt32Number   CMSEXPORT cmsPipelineInputChannels(const cmsPipeline* lut);
-CMSAPI cmsUInt32Number   CMSEXPORT cmsPipelineOutputChannels(const cmsPipeline* lut);
-
-CMSAPI cmsUInt32Number   CMSEXPORT cmsPipelineStageCount(const cmsPipeline* lut);
-CMSAPI cmsStage*         CMSEXPORT cmsPipelineGetPtrToFirstStage(const cmsPipeline* lut);
-CMSAPI cmsStage*         CMSEXPORT cmsPipelineGetPtrToLastStage(const cmsPipeline* lut);
-
-CMSAPI void              CMSEXPORT cmsPipelineEval16(const cmsUInt16Number In[], cmsUInt16Number Out[], const cmsPipeline* lut);
-CMSAPI void              CMSEXPORT cmsPipelineEvalFloat(const cmsFloat32Number In[], cmsFloat32Number Out[], const cmsPipeline* lut);
-CMSAPI cmsBool           CMSEXPORT cmsPipelineEvalReverseFloat(cmsFloat32Number Target[], cmsFloat32Number Result[], cmsFloat32Number Hint[], const cmsPipeline* lut);
-CMSAPI cmsBool           CMSEXPORT cmsPipelineCat(cmsPipeline* l1, const cmsPipeline* l2);
-CMSAPI cmsBool           CMSEXPORT cmsPipelineSetSaveAs8bitsFlag(cmsPipeline* lut, cmsBool On);
-
-// Where to place/locate the stages in the pipeline chain
-typedef enum { cmsAT_BEGIN, cmsAT_END } cmsStageLoc;
-
-CMSAPI int               CMSEXPORT cmsPipelineInsertStage(cmsPipeline* lut, cmsStageLoc loc, cmsStage* mpe);
-CMSAPI void              CMSEXPORT cmsPipelineUnlinkStage(cmsPipeline* lut, cmsStageLoc loc, cmsStage** mpe);
-
-// This function is quite useful to analyze the structure of a Pipeline and retrieve the Stage elements
-// that conform the Pipeline. It should be called with the Pipeline, the number of expected elements and
-// then a list of expected types followed with a list of double pointers to Stage elements. If
-// the function founds a match with current pipeline, it fills the pointers and returns TRUE
-// if not, returns FALSE without touching anything.
-CMSAPI cmsBool           CMSEXPORT cmsPipelineCheckAndRetreiveStages(const cmsPipeline* Lut, cmsUInt32Number n, ...);
-
-// Matrix has double precision and CLUT has only float precision. That is because an ICC profile can encode
-// matrices with far more precision that CLUTS
-CMSAPI cmsStage*         CMSEXPORT cmsStageAllocIdentity(cmsContext ContextID, cmsUInt32Number nChannels);
-CMSAPI cmsStage*         CMSEXPORT cmsStageAllocToneCurves(cmsContext ContextID, cmsUInt32Number nChannels, cmsToneCurve* const Curves[]);
-CMSAPI cmsStage*         CMSEXPORT cmsStageAllocMatrix(cmsContext ContextID, cmsUInt32Number Rows, cmsUInt32Number Cols, const cmsFloat64Number* Matrix, const cmsFloat64Number* Offset);
-
-CMSAPI cmsStage*         CMSEXPORT cmsStageAllocCLut16bit(cmsContext ContextID, cmsUInt32Number nGridPoints, cmsUInt32Number inputChan, cmsUInt32Number outputChan, const cmsUInt16Number* Table);
-CMSAPI cmsStage*         CMSEXPORT cmsStageAllocCLutFloat(cmsContext ContextID, cmsUInt32Number nGridPoints, cmsUInt32Number inputChan, cmsUInt32Number outputChan, const cmsFloat32Number* Table);
-
-CMSAPI cmsStage*         CMSEXPORT cmsStageAllocCLut16bitGranular(cmsContext ContextID, const cmsUInt32Number clutPoints[], cmsUInt32Number inputChan, cmsUInt32Number outputChan, const cmsUInt16Number* Table);
-CMSAPI cmsStage*         CMSEXPORT cmsStageAllocCLutFloatGranular(cmsContext ContextID, const cmsUInt32Number clutPoints[], cmsUInt32Number inputChan, cmsUInt32Number outputChan, const cmsFloat32Number* Table);
-
-CMSAPI cmsStage*         CMSEXPORT cmsStageDup(cmsStage* mpe);
-CMSAPI void              CMSEXPORT cmsStageFree(cmsStage* mpe);
-CMSAPI cmsStage*         CMSEXPORT cmsStageNext(const cmsStage* mpe);
-
-CMSAPI cmsUInt32Number   CMSEXPORT cmsStageInputChannels(const cmsStage* mpe);
-CMSAPI cmsUInt32Number   CMSEXPORT cmsStageOutputChannels(const cmsStage* mpe);
-CMSAPI cmsStageSignature CMSEXPORT cmsStageType(const cmsStage* mpe);
-CMSAPI void*             CMSEXPORT cmsStageData(const cmsStage* mpe);
-
-// Sampling
-typedef cmsInt32Number (* cmsSAMPLER16)   (register const cmsUInt16Number In[],
-                                            register cmsUInt16Number Out[],
-                                            register void * Cargo);
-
-typedef cmsInt32Number (* cmsSAMPLERFLOAT)(register const cmsFloat32Number In[],
-                                            register cmsFloat32Number Out[],
-                                            register void * Cargo);
-
-// Use this flag to prevent changes being written to destination
-#define SAMPLER_INSPECT     0x01000000
-
-// For CLUT only
-CMSAPI cmsBool           CMSEXPORT cmsStageSampleCLut16bit(cmsStage* mpe,    cmsSAMPLER16 Sampler, void* Cargo, cmsUInt32Number dwFlags);
-CMSAPI cmsBool           CMSEXPORT cmsStageSampleCLutFloat(cmsStage* mpe, cmsSAMPLERFLOAT Sampler, void* Cargo, cmsUInt32Number dwFlags);
-
-// Slicers
-CMSAPI cmsBool           CMSEXPORT cmsSliceSpace16(cmsUInt32Number nInputs, const cmsUInt32Number clutPoints[],
-                                                   cmsSAMPLER16 Sampler, void * Cargo);
-
-CMSAPI cmsBool           CMSEXPORT cmsSliceSpaceFloat(cmsUInt32Number nInputs, const cmsUInt32Number clutPoints[],
-                                                   cmsSAMPLERFLOAT Sampler, void * Cargo);
-
-// Multilocalized Unicode management ---------------------------------------------------------------------------------------
-
-typedef struct _cms_MLU_struct cmsMLU;
-
-#define  cmsNoLanguage "\0\0"
-#define  cmsNoCountry  "\0\0"
-
-CMSAPI cmsMLU*           CMSEXPORT cmsMLUalloc(cmsContext ContextID, cmsUInt32Number nItems);
-CMSAPI void              CMSEXPORT cmsMLUfree(cmsMLU* mlu);
-CMSAPI cmsMLU*           CMSEXPORT cmsMLUdup(const cmsMLU* mlu);
-
-CMSAPI cmsBool           CMSEXPORT cmsMLUsetASCII(cmsMLU* mlu,
-                                                  const char LanguageCode[3], const char CountryCode[3],
-                                                  const char* ASCIIString);
-CMSAPI cmsBool           CMSEXPORT cmsMLUsetWide(cmsMLU* mlu,
-                                                  const char LanguageCode[3], const char CountryCode[3],
-                                                  const wchar_t* WideString);
-
-CMSAPI cmsUInt32Number   CMSEXPORT cmsMLUgetASCII(const cmsMLU* mlu,
-                                                  const char LanguageCode[3], const char CountryCode[3],
-                                                  char* Buffer,    cmsUInt32Number BufferSize);
-
-CMSAPI cmsUInt32Number   CMSEXPORT cmsMLUgetWide(const cmsMLU* mlu,
-                                                 const char LanguageCode[3], const char CountryCode[3],
-                                                 wchar_t* Buffer, cmsUInt32Number BufferSize);
-
-CMSAPI cmsBool           CMSEXPORT cmsMLUgetTranslation(const cmsMLU* mlu,
-                                                         const char LanguageCode[3], const char CountryCode[3],
-                                                         char ObtainedLanguage[3], char ObtainedCountry[3]);
-
-CMSAPI cmsUInt32Number   CMSEXPORT cmsMLUtranslationsCount(const cmsMLU* mlu);
-
-CMSAPI cmsBool           CMSEXPORT cmsMLUtranslationsCodes(const cmsMLU* mlu,
-                                                             cmsUInt32Number idx,
-                                                             char LanguageCode[3],
-                                                             char CountryCode[3]);
-// Undercolorremoval & black generation -------------------------------------------------------------------------------------
-
-typedef struct {
-        cmsToneCurve* Ucr;
-        cmsToneCurve* Bg;
-        cmsMLU*       Desc;
-
-} cmsUcrBg;
-
-// Screening ----------------------------------------------------------------------------------------------------------------
-
-#define cmsPRINTER_DEFAULT_SCREENS     0x0001
-#define cmsFREQUENCE_UNITS_LINES_CM    0x0000
-#define cmsFREQUENCE_UNITS_LINES_INCH  0x0002
-
-#define cmsSPOT_UNKNOWN         0
-#define cmsSPOT_PRINTER_DEFAULT 1
-#define cmsSPOT_ROUND           2
-#define cmsSPOT_DIAMOND         3
-#define cmsSPOT_ELLIPSE         4
-#define cmsSPOT_LINE            5
-#define cmsSPOT_SQUARE          6
-#define cmsSPOT_CROSS           7
-
-typedef struct {
-    cmsFloat64Number  Frequency;
-    cmsFloat64Number  ScreenAngle;
-    cmsUInt32Number   SpotShape;
-
-} cmsScreeningChannel;
-
-typedef struct {
-    cmsUInt32Number Flag;
-    cmsUInt32Number nChannels;
-    cmsScreeningChannel Channels[cmsMAXCHANNELS];
-
-} cmsScreening;
-
-
-// Named color -----------------------------------------------------------------------------------------------------------------
-
-typedef struct _cms_NAMEDCOLORLIST_struct cmsNAMEDCOLORLIST;
-
-CMSAPI cmsNAMEDCOLORLIST* CMSEXPORT cmsAllocNamedColorList(cmsContext ContextID,
-                                                           cmsUInt32Number n,
-                                                           cmsUInt32Number ColorantCount,
-                                                           const char* Prefix, const char* Suffix);
-
-CMSAPI void               CMSEXPORT cmsFreeNamedColorList(cmsNAMEDCOLORLIST* v);
-CMSAPI cmsNAMEDCOLORLIST* CMSEXPORT cmsDupNamedColorList(const cmsNAMEDCOLORLIST* v);
-CMSAPI cmsBool            CMSEXPORT cmsAppendNamedColor(cmsNAMEDCOLORLIST* v, const char* Name,
-                                                            cmsUInt16Number PCS[3],
-                                                            cmsUInt16Number Colorant[cmsMAXCHANNELS]);
-
-CMSAPI cmsUInt32Number    CMSEXPORT cmsNamedColorCount(const cmsNAMEDCOLORLIST* v);
-CMSAPI cmsInt32Number     CMSEXPORT cmsNamedColorIndex(const cmsNAMEDCOLORLIST* v, const char* Name);
-
-CMSAPI cmsBool            CMSEXPORT cmsNamedColorInfo(const cmsNAMEDCOLORLIST* NamedColorList, cmsUInt32Number nColor,
-                                                      char* Name,
-                                                      char* Prefix,
-                                                      char* Suffix,
-                                                      cmsUInt16Number* PCS,
-                                                      cmsUInt16Number* Colorant);
-
-// Retrieve named color list from transform
-CMSAPI cmsNAMEDCOLORLIST* CMSEXPORT cmsGetNamedColorList(cmsHTRANSFORM xform);
-
-// Profile sequence -----------------------------------------------------------------------------------------------------
-
-// Profile sequence descriptor. Some fields come from profile sequence descriptor tag, others
-// come from Profile Sequence Identifier Tag
-typedef struct {
-
-    cmsSignature           deviceMfg;
-    cmsSignature           deviceModel;
-    cmsUInt64Number        attributes;
-    cmsTechnologySignature technology;
-    cmsProfileID           ProfileID;
-    cmsMLU*                Manufacturer;
-    cmsMLU*                Model;
-    cmsMLU*                Description;
-
-} cmsPSEQDESC;
-
-typedef struct {
-
-    cmsUInt32Number n;
-    cmsContext     ContextID;
-    cmsPSEQDESC*    seq;
-
-} cmsSEQ;
-
-CMSAPI cmsSEQ*           CMSEXPORT cmsAllocProfileSequenceDescription(cmsContext ContextID, cmsUInt32Number n);
-CMSAPI cmsSEQ*           CMSEXPORT cmsDupProfileSequenceDescription(const cmsSEQ* pseq);
-CMSAPI void              CMSEXPORT cmsFreeProfileSequenceDescription(cmsSEQ* pseq);
-
-// Dictionaries --------------------------------------------------------------------------------------------------------
-
-typedef struct _cmsDICTentry_struct {
-
-    struct _cmsDICTentry_struct* Next;
-
-    cmsMLU *DisplayName;
-    cmsMLU *DisplayValue;
-    wchar_t* Name;
-    wchar_t* Value;
-
-} cmsDICTentry;
-
-CMSAPI cmsHANDLE           CMSEXPORT cmsDictAlloc(cmsContext ContextID);
-CMSAPI void                CMSEXPORT cmsDictFree(cmsHANDLE hDict);
-CMSAPI cmsHANDLE           CMSEXPORT cmsDictDup(cmsHANDLE hDict);
-
-CMSAPI cmsBool             CMSEXPORT cmsDictAddEntry(cmsHANDLE hDict, const wchar_t* Name, const wchar_t* Value, const cmsMLU *DisplayName, const cmsMLU *DisplayValue);
-CMSAPI const cmsDICTentry* CMSEXPORT cmsDictGetEntryList(cmsHANDLE hDict);
-CMSAPI const cmsDICTentry* CMSEXPORT cmsDictNextEntry(const cmsDICTentry* e);
-
-// Access to Profile data ----------------------------------------------------------------------------------------------
-CMSAPI cmsHPROFILE       CMSEXPORT cmsCreateProfilePlaceholder(cmsContext ContextID);
-
-CMSAPI cmsContext        CMSEXPORT cmsGetProfileContextID(cmsHPROFILE hProfile);
-CMSAPI cmsInt32Number    CMSEXPORT cmsGetTagCount(cmsHPROFILE hProfile);
-CMSAPI cmsTagSignature   CMSEXPORT cmsGetTagSignature(cmsHPROFILE hProfile, cmsUInt32Number n);
-CMSAPI cmsBool           CMSEXPORT cmsIsTag(cmsHPROFILE hProfile, cmsTagSignature sig);
-
-// Read and write pre-formatted data
-CMSAPI void*             CMSEXPORT cmsReadTag(cmsHPROFILE hProfile, cmsTagSignature sig);
-CMSAPI cmsBool           CMSEXPORT cmsWriteTag(cmsHPROFILE hProfile, cmsTagSignature sig, const void* data);
-CMSAPI cmsBool           CMSEXPORT cmsLinkTag(cmsHPROFILE hProfile, cmsTagSignature sig, cmsTagSignature dest);
-CMSAPI cmsTagSignature   CMSEXPORT cmsTagLinkedTo(cmsHPROFILE hProfile, cmsTagSignature sig);
-
-// Read and write raw data
-CMSAPI cmsInt32Number    CMSEXPORT cmsReadRawTag(cmsHPROFILE hProfile, cmsTagSignature sig, void* Buffer, cmsUInt32Number BufferSize);
-CMSAPI cmsBool           CMSEXPORT cmsWriteRawTag(cmsHPROFILE hProfile, cmsTagSignature sig, const void* data, cmsUInt32Number Size);
-
-// Access header data
-#define cmsEmbeddedProfileFalse    0x00000000
-#define cmsEmbeddedProfileTrue     0x00000001
-#define cmsUseAnywhere             0x00000000
-#define cmsUseWithEmbeddedDataOnly 0x00000002
-
-CMSAPI cmsUInt32Number   CMSEXPORT cmsGetHeaderFlags(cmsHPROFILE hProfile);
-CMSAPI void              CMSEXPORT cmsGetHeaderAttributes(cmsHPROFILE hProfile, cmsUInt64Number* Flags);
-CMSAPI void              CMSEXPORT cmsGetHeaderProfileID(cmsHPROFILE hProfile, cmsUInt8Number* ProfileID);
-CMSAPI cmsBool           CMSEXPORT cmsGetHeaderCreationDateTime(cmsHPROFILE hProfile, struct tm *Dest);
-CMSAPI cmsUInt32Number   CMSEXPORT cmsGetHeaderRenderingIntent(cmsHPROFILE hProfile);
-
-CMSAPI void              CMSEXPORT cmsSetHeaderFlags(cmsHPROFILE hProfile, cmsUInt32Number Flags);
-CMSAPI cmsUInt32Number   CMSEXPORT cmsGetHeaderManufacturer(cmsHPROFILE hProfile);
-CMSAPI void              CMSEXPORT cmsSetHeaderManufacturer(cmsHPROFILE hProfile, cmsUInt32Number manufacturer);
-CMSAPI cmsUInt32Number   CMSEXPORT cmsGetHeaderCreator(cmsHPROFILE hProfile);
-CMSAPI cmsUInt32Number   CMSEXPORT cmsGetHeaderModel(cmsHPROFILE hProfile);
-CMSAPI void              CMSEXPORT cmsSetHeaderModel(cmsHPROFILE hProfile, cmsUInt32Number model);
-CMSAPI void              CMSEXPORT cmsSetHeaderAttributes(cmsHPROFILE hProfile, cmsUInt64Number Flags);
-CMSAPI void              CMSEXPORT cmsSetHeaderProfileID(cmsHPROFILE hProfile, cmsUInt8Number* ProfileID);
-CMSAPI void              CMSEXPORT cmsSetHeaderRenderingIntent(cmsHPROFILE hProfile, cmsUInt32Number RenderingIntent);
-
-CMSAPI cmsColorSpaceSignature
-                         CMSEXPORT cmsGetPCS(cmsHPROFILE hProfile);
-CMSAPI void              CMSEXPORT cmsSetPCS(cmsHPROFILE hProfile, cmsColorSpaceSignature pcs);
-CMSAPI cmsColorSpaceSignature
-                         CMSEXPORT cmsGetColorSpace(cmsHPROFILE hProfile);
-CMSAPI void              CMSEXPORT cmsSetColorSpace(cmsHPROFILE hProfile, cmsColorSpaceSignature sig);
-CMSAPI cmsProfileClassSignature
-                         CMSEXPORT cmsGetDeviceClass(cmsHPROFILE hProfile);
-CMSAPI void              CMSEXPORT cmsSetDeviceClass(cmsHPROFILE hProfile, cmsProfileClassSignature sig);
-CMSAPI void              CMSEXPORT cmsSetProfileVersion(cmsHPROFILE hProfile, cmsFloat64Number Version);
-CMSAPI cmsFloat64Number  CMSEXPORT cmsGetProfileVersion(cmsHPROFILE hProfile);
-
-CMSAPI cmsUInt32Number   CMSEXPORT cmsGetEncodedICCversion(cmsHPROFILE hProfile);
-CMSAPI void              CMSEXPORT cmsSetEncodedICCversion(cmsHPROFILE hProfile, cmsUInt32Number Version);
-
-// How profiles may be used
-#define LCMS_USED_AS_INPUT      0
-#define LCMS_USED_AS_OUTPUT     1
-#define LCMS_USED_AS_PROOF      2
-
-CMSAPI cmsBool           CMSEXPORT cmsIsIntentSupported(cmsHPROFILE hProfile, cmsUInt32Number Intent, cmsUInt32Number UsedDirection);
-CMSAPI cmsBool           CMSEXPORT cmsIsMatrixShaper(cmsHPROFILE hProfile);
-CMSAPI cmsBool           CMSEXPORT cmsIsCLUT(cmsHPROFILE hProfile, cmsUInt32Number Intent, cmsUInt32Number UsedDirection);
-
-// Translate form/to our notation to ICC
-CMSAPI cmsColorSpaceSignature   CMSEXPORT _cmsICCcolorSpace(int OurNotation);
-CMSAPI int                      CMSEXPORT _cmsLCMScolorSpace(cmsColorSpaceSignature ProfileSpace);
-
-CMSAPI cmsUInt32Number   CMSEXPORT cmsChannelsOf(cmsColorSpaceSignature ColorSpace);
-
-// Build a suitable formatter for the colorspace of this profile
-CMSAPI cmsUInt32Number   CMSEXPORT cmsFormatterForColorspaceOfProfile(cmsHPROFILE hProfile, cmsUInt32Number nBytes, cmsBool lIsFloat);
-CMSAPI cmsUInt32Number   CMSEXPORT cmsFormatterForPCSOfProfile(cmsHPROFILE hProfile, cmsUInt32Number nBytes, cmsBool lIsFloat);
-
-
-// Localized info
-typedef enum {
-             cmsInfoDescription  = 0,
-             cmsInfoManufacturer = 1,
-             cmsInfoModel        = 2,
-             cmsInfoCopyright    = 3
-} cmsInfoType;
-
-CMSAPI cmsUInt32Number   CMSEXPORT cmsGetProfileInfo(cmsHPROFILE hProfile, cmsInfoType Info,
-                                                            const char LanguageCode[3], const char CountryCode[3],
-                                                            wchar_t* Buffer, cmsUInt32Number BufferSize);
-
-CMSAPI cmsUInt32Number   CMSEXPORT cmsGetProfileInfoASCII(cmsHPROFILE hProfile, cmsInfoType Info,
-                                                            const char LanguageCode[3], const char CountryCode[3],
-                                                            char* Buffer, cmsUInt32Number BufferSize);
-
-// IO handlers ----------------------------------------------------------------------------------------------------------
-
-typedef struct _cms_io_handler cmsIOHANDLER;
-
-CMSAPI cmsIOHANDLER*     CMSEXPORT cmsOpenIOhandlerFromFile(cmsContext ContextID, const char* FileName, const char* AccessMode);
-CMSAPI cmsIOHANDLER*     CMSEXPORT cmsOpenIOhandlerFromStream(cmsContext ContextID, FILE* Stream);
-CMSAPI cmsIOHANDLER*     CMSEXPORT cmsOpenIOhandlerFromMem(cmsContext ContextID, void *Buffer, cmsUInt32Number size, const char* AccessMode);
-CMSAPI cmsIOHANDLER*     CMSEXPORT cmsOpenIOhandlerFromNULL(cmsContext ContextID);
-CMSAPI cmsBool           CMSEXPORT cmsCloseIOhandler(cmsIOHANDLER* io);
-
-// MD5 message digest --------------------------------------------------------------------------------------------------
-
-CMSAPI cmsBool           CMSEXPORT cmsMD5computeID(cmsHPROFILE hProfile);
-CMSAPI cmsBool                  CMSEXPORT cmsMD5computeIDExt(const void* buf, unsigned long size, unsigned char ProfileID[16]);
-
-// Profile high level funtions ------------------------------------------------------------------------------------------
-
-CMSAPI cmsHPROFILE      CMSEXPORT cmsOpenProfileFromFile(const char *ICCProfile, const char *sAccess);
-CMSAPI cmsHPROFILE      CMSEXPORT cmsOpenProfileFromFileTHR(cmsContext ContextID, const char *ICCProfile, const char *sAccess);
-CMSAPI cmsHPROFILE      CMSEXPORT cmsOpenProfileFromStream(FILE* ICCProfile, const char* sAccess);
-CMSAPI cmsHPROFILE      CMSEXPORT cmsOpenProfileFromStreamTHR(cmsContext ContextID, FILE* ICCProfile, const char* sAccess);
-CMSAPI cmsHPROFILE      CMSEXPORT cmsOpenProfileFromMem(const void * MemPtr, cmsUInt32Number dwSize);
-CMSAPI cmsHPROFILE      CMSEXPORT cmsOpenProfileFromMemTHR(cmsContext ContextID, const void * MemPtr, cmsUInt32Number dwSize);
-CMSAPI cmsHPROFILE      CMSEXPORT cmsOpenProfileFromIOhandlerTHR(cmsContext ContextID, cmsIOHANDLER* io);
-CMSAPI cmsHPROFILE      CMSEXPORT cmsOpenProfileFromIOhandler2THR(cmsContext ContextID, cmsIOHANDLER* io, cmsBool write);
-CMSAPI cmsBool          CMSEXPORT cmsCloseProfile(cmsHPROFILE hProfile);
-
-CMSAPI cmsBool          CMSEXPORT cmsSaveProfileToFile(cmsHPROFILE hProfile, const char* FileName);
-CMSAPI cmsBool          CMSEXPORT cmsSaveProfileToStream(cmsHPROFILE hProfile, FILE* Stream);
-CMSAPI cmsBool          CMSEXPORT cmsSaveProfileToMem(cmsHPROFILE hProfile, void *MemPtr, cmsUInt32Number* BytesNeeded);
-CMSAPI cmsUInt32Number  CMSEXPORT cmsSaveProfileToIOhandler(cmsHPROFILE hProfile, cmsIOHANDLER* io);
-
-// Predefined virtual profiles ------------------------------------------------------------------------------------------
-
-CMSAPI cmsHPROFILE      CMSEXPORT cmsCreateRGBProfileTHR(cmsContext ContextID,
-                                                   const cmsCIExyY* WhitePoint,
-                                                   const cmsCIExyYTRIPLE* Primaries,
-                                                   cmsToneCurve* const TransferFunction[3]);
-
-CMSAPI cmsHPROFILE      CMSEXPORT cmsCreateRGBProfile(const cmsCIExyY* WhitePoint,
-                                                   const cmsCIExyYTRIPLE* Primaries,
-                                                   cmsToneCurve* const TransferFunction[3]);
-
-CMSAPI cmsHPROFILE      CMSEXPORT cmsCreateGrayProfileTHR(cmsContext ContextID,
-                                                    const cmsCIExyY* WhitePoint,
-                                                    const cmsToneCurve* TransferFunction);
-
-CMSAPI cmsHPROFILE      CMSEXPORT cmsCreateGrayProfile(const cmsCIExyY* WhitePoint,
-                                                    const cmsToneCurve* TransferFunction);
-
-CMSAPI cmsHPROFILE      CMSEXPORT cmsCreateLinearizationDeviceLinkTHR(cmsContext ContextID,
-                                                                cmsColorSpaceSignature ColorSpace,
-                                                                cmsToneCurve* const TransferFunctions[]);
-
-CMSAPI cmsHPROFILE      CMSEXPORT cmsCreateLinearizationDeviceLink(cmsColorSpaceSignature ColorSpace,
-                                                                cmsToneCurve* const TransferFunctions[]);
-
-CMSAPI cmsHPROFILE      CMSEXPORT cmsCreateInkLimitingDeviceLinkTHR(cmsContext ContextID,
-                                                              cmsColorSpaceSignature ColorSpace, cmsFloat64Number Limit);
-
-CMSAPI cmsHPROFILE      CMSEXPORT cmsCreateInkLimitingDeviceLink(cmsColorSpaceSignature ColorSpace, cmsFloat64Number Limit);
-
-
-CMSAPI cmsHPROFILE      CMSEXPORT cmsCreateLab2ProfileTHR(cmsContext ContextID, const cmsCIExyY* WhitePoint);
-CMSAPI cmsHPROFILE      CMSEXPORT cmsCreateLab2Profile(const cmsCIExyY* WhitePoint);
-CMSAPI cmsHPROFILE      CMSEXPORT cmsCreateLab4ProfileTHR(cmsContext ContextID, const cmsCIExyY* WhitePoint);
-CMSAPI cmsHPROFILE      CMSEXPORT cmsCreateLab4Profile(const cmsCIExyY* WhitePoint);
-
-CMSAPI cmsHPROFILE      CMSEXPORT cmsCreateXYZProfileTHR(cmsContext ContextID);
-CMSAPI cmsHPROFILE      CMSEXPORT cmsCreateXYZProfile(void);
-
-CMSAPI cmsHPROFILE      CMSEXPORT cmsCreate_sRGBProfileTHR(cmsContext ContextID);
-CMSAPI cmsHPROFILE      CMSEXPORT cmsCreate_sRGBProfile(void);
-
-CMSAPI cmsHPROFILE      CMSEXPORT cmsCreateBCHSWabstractProfileTHR(cmsContext ContextID,
-                                                             int nLUTPoints,
-                                                             cmsFloat64Number Bright,
-                                                             cmsFloat64Number Contrast,
-                                                             cmsFloat64Number Hue,
-                                                             cmsFloat64Number Saturation,
-                                                             int TempSrc,
-                                                             int TempDest);
-
-CMSAPI cmsHPROFILE      CMSEXPORT cmsCreateBCHSWabstractProfile(int nLUTPoints,
-                                                             cmsFloat64Number Bright,
-                                                             cmsFloat64Number Contrast,
-                                                             cmsFloat64Number Hue,
-                                                             cmsFloat64Number Saturation,
-                                                             int TempSrc,
-                                                             int TempDest);
-
-CMSAPI cmsHPROFILE      CMSEXPORT cmsCreateNULLProfileTHR(cmsContext ContextID);
-CMSAPI cmsHPROFILE      CMSEXPORT cmsCreateNULLProfile(void);
-
-// Converts a transform to a devicelink profile
-CMSAPI cmsHPROFILE      CMSEXPORT cmsTransform2DeviceLink(cmsHTRANSFORM hTransform, cmsFloat64Number Version, cmsUInt32Number dwFlags);
-
-// Intents ----------------------------------------------------------------------------------------------
-
-// ICC Intents
-#define INTENT_PERCEPTUAL                              0
-#define INTENT_RELATIVE_COLORIMETRIC                   1
-#define INTENT_SATURATION                              2
-#define INTENT_ABSOLUTE_COLORIMETRIC                   3
-
-// Non-ICC intents
-#define INTENT_PRESERVE_K_ONLY_PERCEPTUAL             10
-#define INTENT_PRESERVE_K_ONLY_RELATIVE_COLORIMETRIC  11
-#define INTENT_PRESERVE_K_ONLY_SATURATION             12
-#define INTENT_PRESERVE_K_PLANE_PERCEPTUAL            13
-#define INTENT_PRESERVE_K_PLANE_RELATIVE_COLORIMETRIC 14
-#define INTENT_PRESERVE_K_PLANE_SATURATION            15
-
-// Call with NULL as parameters to get the intent count
-CMSAPI cmsUInt32Number  CMSEXPORT cmsGetSupportedIntents(cmsUInt32Number nMax, cmsUInt32Number* Codes, char** Descriptions);
-CMSAPI cmsUInt32Number  CMSEXPORT cmsGetSupportedIntentsTHR(cmsContext ContextID, cmsUInt32Number nMax, cmsUInt32Number* Codes, char** Descriptions);
-
-// Flags
-
-#define cmsFLAGS_NOCACHE                  0x0040    // Inhibit 1-pixel cache
-#define cmsFLAGS_NOOPTIMIZE               0x0100    // Inhibit optimizations
-#define cmsFLAGS_NULLTRANSFORM            0x0200    // Don't transform anyway
-
-// Proofing flags
-#define cmsFLAGS_GAMUTCHECK               0x1000    // Out of Gamut alarm
-#define cmsFLAGS_SOFTPROOFING             0x4000    // Do softproofing
-
-// Misc
-#define cmsFLAGS_BLACKPOINTCOMPENSATION   0x2000
-#define cmsFLAGS_NOWHITEONWHITEFIXUP      0x0004    // Don't fix scum dot
-#define cmsFLAGS_HIGHRESPRECALC           0x0400    // Use more memory to give better accurancy
-#define cmsFLAGS_LOWRESPRECALC            0x0800    // Use less memory to minimize resouces
-
-// For devicelink creation
-#define cmsFLAGS_8BITS_DEVICELINK         0x0008   // Create 8 bits devicelinks
-#define cmsFLAGS_GUESSDEVICECLASS         0x0020   // Guess device class (for transform2devicelink)
-#define cmsFLAGS_KEEP_SEQUENCE            0x0080   // Keep profile sequence for devicelink creation
-
-// Specific to a particular optimizations
-#define cmsFLAGS_FORCE_CLUT               0x0002    // Force CLUT optimization
-#define cmsFLAGS_CLUT_POST_LINEARIZATION  0x0001    // create postlinearization tables if possible
-#define cmsFLAGS_CLUT_PRE_LINEARIZATION   0x0010    // create prelinearization tables if possible
-
-// Fine-tune control over number of gridpoints
-#define cmsFLAGS_GRIDPOINTS(n)           (((n) & 0xFF) << 16)
-
-// CRD special
-#define cmsFLAGS_NODEFAULTRESOURCEDEF     0x01000000
-
-// Transforms ---------------------------------------------------------------------------------------------------
-
-CMSAPI cmsHTRANSFORM    CMSEXPORT cmsCreateTransformTHR(cmsContext ContextID,
-                                                  cmsHPROFILE Input,
-                                                  cmsUInt32Number InputFormat,
-                                                  cmsHPROFILE Output,
-                                                  cmsUInt32Number OutputFormat,
-                                                  cmsUInt32Number Intent,
-                                                  cmsUInt32Number dwFlags);
-
-CMSAPI cmsHTRANSFORM    CMSEXPORT cmsCreateTransform(cmsHPROFILE Input,
-                                                  cmsUInt32Number InputFormat,
-                                                  cmsHPROFILE Output,
-                                                  cmsUInt32Number OutputFormat,
-                                                  cmsUInt32Number Intent,
-                                                  cmsUInt32Number dwFlags);
-
-CMSAPI cmsHTRANSFORM    CMSEXPORT cmsCreateProofingTransformTHR(cmsContext ContextID,
-                                                  cmsHPROFILE Input,
-                                                  cmsUInt32Number InputFormat,
-                                                  cmsHPROFILE Output,
-                                                  cmsUInt32Number OutputFormat,
-                                                  cmsHPROFILE Proofing,
-                                                  cmsUInt32Number Intent,
-                                                  cmsUInt32Number ProofingIntent,
-                                                  cmsUInt32Number dwFlags);
-
-CMSAPI cmsHTRANSFORM    CMSEXPORT cmsCreateProofingTransform(cmsHPROFILE Input,
-                                                  cmsUInt32Number InputFormat,
-                                                  cmsHPROFILE Output,
-                                                  cmsUInt32Number OutputFormat,
-                                                  cmsHPROFILE Proofing,
-                                                  cmsUInt32Number Intent,
-                                                  cmsUInt32Number ProofingIntent,
-                                                  cmsUInt32Number dwFlags);
-
-CMSAPI cmsHTRANSFORM    CMSEXPORT cmsCreateMultiprofileTransformTHR(cmsContext ContextID,
-                                                  cmsHPROFILE hProfiles[],
-                                                  cmsUInt32Number nProfiles,
-                                                  cmsUInt32Number InputFormat,
-                                                  cmsUInt32Number OutputFormat,
-                                                  cmsUInt32Number Intent,
-                                                  cmsUInt32Number dwFlags);
-
-
-CMSAPI cmsHTRANSFORM    CMSEXPORT cmsCreateMultiprofileTransform(cmsHPROFILE hProfiles[],
-                                                  cmsUInt32Number nProfiles,
-                                                  cmsUInt32Number InputFormat,
-                                                  cmsUInt32Number OutputFormat,
-                                                  cmsUInt32Number Intent,
-                                                  cmsUInt32Number dwFlags);
-
-
-CMSAPI cmsHTRANSFORM    CMSEXPORT cmsCreateExtendedTransform(cmsContext ContextID,
-                                                   cmsUInt32Number nProfiles, cmsHPROFILE hProfiles[],
-                                                   cmsBool  BPC[],
-                                                   cmsUInt32Number Intents[],
-                                                   cmsFloat64Number AdaptationStates[],
-                                                   cmsHPROFILE hGamutProfile,
-                                                   cmsUInt32Number nGamutPCSposition,
-                                                   cmsUInt32Number InputFormat,
-                                                   cmsUInt32Number OutputFormat,
-                                                   cmsUInt32Number dwFlags);
-
-CMSAPI void             CMSEXPORT cmsDeleteTransform(cmsHTRANSFORM hTransform);
-
-CMSAPI void             CMSEXPORT cmsDoTransform(cmsHTRANSFORM Transform,
-                                                 const void * InputBuffer,
-                                                 void * OutputBuffer,
-                                                 cmsUInt32Number Size);
-
-CMSAPI void             CMSEXPORT cmsDoTransformStride(cmsHTRANSFORM Transform,
-                                                 const void * InputBuffer,
-                                                 void * OutputBuffer,
-                                                 cmsUInt32Number Size,
-                                                 cmsUInt32Number Stride);
-
-
-CMSAPI void             CMSEXPORT cmsSetAlarmCodes(const cmsUInt16Number NewAlarm[cmsMAXCHANNELS]);
-CMSAPI void             CMSEXPORT cmsGetAlarmCodes(cmsUInt16Number NewAlarm[cmsMAXCHANNELS]);
-
-
-CMSAPI void             CMSEXPORT cmsSetAlarmCodesTHR(cmsContext ContextID, 
-                                                          const cmsUInt16Number AlarmCodes[cmsMAXCHANNELS]);
-CMSAPI void             CMSEXPORT cmsGetAlarmCodesTHR(cmsContext ContextID, 
-                                                          cmsUInt16Number AlarmCodes[cmsMAXCHANNELS]);
-
-
-
-// Adaptation state for absolute colorimetric intent
-CMSAPI cmsFloat64Number CMSEXPORT cmsSetAdaptationState(cmsFloat64Number d);
-CMSAPI cmsFloat64Number CMSEXPORT cmsSetAdaptationStateTHR(cmsContext ContextID, cmsFloat64Number d);
-
-
-
-// Grab the ContextID from an open transform. Returns NULL if a NULL transform is passed
-CMSAPI cmsContext       CMSEXPORT cmsGetTransformContextID(cmsHTRANSFORM hTransform);
-
-// Grab the input/output formats
-CMSAPI cmsUInt32Number CMSEXPORT cmsGetTransformInputFormat(cmsHTRANSFORM hTransform);
-CMSAPI cmsUInt32Number CMSEXPORT cmsGetTransformOutputFormat(cmsHTRANSFORM hTransform);
-
-// For backwards compatibility
-CMSAPI cmsBool          CMSEXPORT cmsChangeBuffersFormat(cmsHTRANSFORM hTransform,
-                                                         cmsUInt32Number InputFormat,
-                                                         cmsUInt32Number OutputFormat);
-
-
-
-// PostScript ColorRenderingDictionary and ColorSpaceArray ----------------------------------------------------
-
-typedef enum { cmsPS_RESOURCE_CSA, cmsPS_RESOURCE_CRD } cmsPSResourceType;
-
-// lcms2 unified method to access postscript color resources
-CMSAPI cmsUInt32Number  CMSEXPORT cmsGetPostScriptColorResource(cmsContext ContextID,
-                                                                cmsPSResourceType Type,
-                                                                cmsHPROFILE hProfile,
-                                                                cmsUInt32Number Intent,
-                                                                cmsUInt32Number dwFlags,
-                                                                cmsIOHANDLER* io);
-
-CMSAPI cmsUInt32Number  CMSEXPORT cmsGetPostScriptCSA(cmsContext ContextID, cmsHPROFILE hProfile, cmsUInt32Number Intent, cmsUInt32Number dwFlags, void* Buffer, cmsUInt32Number dwBufferLen);
-CMSAPI cmsUInt32Number  CMSEXPORT cmsGetPostScriptCRD(cmsContext ContextID, cmsHPROFILE hProfile, cmsUInt32Number Intent, cmsUInt32Number dwFlags, void* Buffer, cmsUInt32Number dwBufferLen);
-
-
-// IT8.7 / CGATS.17-200x handling -----------------------------------------------------------------------------
-
-CMSAPI cmsHANDLE        CMSEXPORT cmsIT8Alloc(cmsContext ContextID);
-CMSAPI void             CMSEXPORT cmsIT8Free(cmsHANDLE hIT8);
-
-// Tables
-CMSAPI cmsUInt32Number  CMSEXPORT cmsIT8TableCount(cmsHANDLE hIT8);
-CMSAPI cmsInt32Number   CMSEXPORT cmsIT8SetTable(cmsHANDLE hIT8, cmsUInt32Number nTable);
-
-// Persistence
-CMSAPI cmsHANDLE        CMSEXPORT cmsIT8LoadFromFile(cmsContext ContextID, const char* cFileName);
-CMSAPI cmsHANDLE        CMSEXPORT cmsIT8LoadFromMem(cmsContext ContextID, void *Ptr, cmsUInt32Number len);
-// CMSAPI cmsHANDLE        CMSEXPORT cmsIT8LoadFromIOhandler(cmsContext ContextID, cmsIOHANDLER* io);
-
-CMSAPI cmsBool          CMSEXPORT cmsIT8SaveToFile(cmsHANDLE hIT8, const char* cFileName);
-CMSAPI cmsBool          CMSEXPORT cmsIT8SaveToMem(cmsHANDLE hIT8, void *MemPtr, cmsUInt32Number* BytesNeeded);
-
-// Properties
-CMSAPI const char*      CMSEXPORT cmsIT8GetSheetType(cmsHANDLE hIT8);
-CMSAPI cmsBool          CMSEXPORT cmsIT8SetSheetType(cmsHANDLE hIT8, const char* Type);
-
-CMSAPI cmsBool          CMSEXPORT cmsIT8SetComment(cmsHANDLE hIT8, const char* cComment);
-
-CMSAPI cmsBool          CMSEXPORT cmsIT8SetPropertyStr(cmsHANDLE hIT8, const char* cProp, const char *Str);
-CMSAPI cmsBool          CMSEXPORT cmsIT8SetPropertyDbl(cmsHANDLE hIT8, const char* cProp, cmsFloat64Number Val);
-CMSAPI cmsBool          CMSEXPORT cmsIT8SetPropertyHex(cmsHANDLE hIT8, const char* cProp, cmsUInt32Number Val);
-CMSAPI cmsBool          CMSEXPORT cmsIT8SetPropertyMulti(cmsHANDLE hIT8, const char* Key, const char* SubKey, const char *Buffer);
-CMSAPI cmsBool          CMSEXPORT cmsIT8SetPropertyUncooked(cmsHANDLE hIT8, const char* Key, const char* Buffer);
-
-
-CMSAPI const char*      CMSEXPORT cmsIT8GetProperty(cmsHANDLE hIT8, const char* cProp);
-CMSAPI cmsFloat64Number CMSEXPORT cmsIT8GetPropertyDbl(cmsHANDLE hIT8, const char* cProp);
-CMSAPI const char*      CMSEXPORT cmsIT8GetPropertyMulti(cmsHANDLE hIT8, const char* Key, const char *SubKey);
-CMSAPI cmsUInt32Number  CMSEXPORT cmsIT8EnumProperties(cmsHANDLE hIT8, char ***PropertyNames);
-CMSAPI cmsUInt32Number  CMSEXPORT cmsIT8EnumPropertyMulti(cmsHANDLE hIT8, const char* cProp, const char ***SubpropertyNames);
-
-// Datasets
-CMSAPI const char*      CMSEXPORT cmsIT8GetDataRowCol(cmsHANDLE hIT8, int row, int col);
-CMSAPI cmsFloat64Number CMSEXPORT cmsIT8GetDataRowColDbl(cmsHANDLE hIT8, int row, int col);
-
-CMSAPI cmsBool          CMSEXPORT cmsIT8SetDataRowCol(cmsHANDLE hIT8, int row, int col,
-                                                const char* Val);
-
-CMSAPI cmsBool          CMSEXPORT cmsIT8SetDataRowColDbl(cmsHANDLE hIT8, int row, int col,
-                                                cmsFloat64Number Val);
-
-CMSAPI const char*      CMSEXPORT cmsIT8GetData(cmsHANDLE hIT8, const char* cPatch, const char* cSample);
-
-
-CMSAPI cmsFloat64Number CMSEXPORT cmsIT8GetDataDbl(cmsHANDLE hIT8, const char* cPatch, const char* cSample);
-
-CMSAPI cmsBool          CMSEXPORT cmsIT8SetData(cmsHANDLE hIT8, const char* cPatch,
-                                                const char* cSample,
-                                                const char *Val);
-
-CMSAPI cmsBool          CMSEXPORT cmsIT8SetDataDbl(cmsHANDLE hIT8, const char* cPatch,
-                                                const char* cSample,
-                                                cmsFloat64Number Val);
-
-CMSAPI int              CMSEXPORT cmsIT8FindDataFormat(cmsHANDLE hIT8, const char* cSample);
-CMSAPI cmsBool          CMSEXPORT cmsIT8SetDataFormat(cmsHANDLE hIT8, int n, const char *Sample);
-CMSAPI int              CMSEXPORT cmsIT8EnumDataFormat(cmsHANDLE hIT8, char ***SampleNames);
-
-CMSAPI const char*      CMSEXPORT cmsIT8GetPatchName(cmsHANDLE hIT8, int nPatch, char* buffer);
-CMSAPI int              CMSEXPORT cmsIT8GetPatchByName(cmsHANDLE hIT8, const char *cPatch);
-
-// The LABEL extension
-CMSAPI int              CMSEXPORT cmsIT8SetTableByLabel(cmsHANDLE hIT8, const char* cSet, const char* cField, const char* ExpectedType);
-
-CMSAPI cmsBool          CMSEXPORT cmsIT8SetIndexColumn(cmsHANDLE hIT8, const char* cSample);
-
-// Formatter for double
-CMSAPI void             CMSEXPORT cmsIT8DefineDblFormat(cmsHANDLE hIT8, const char* Formatter);
-
-// Gamut boundary description routines ------------------------------------------------------------------------------
-
-CMSAPI cmsHANDLE        CMSEXPORT cmsGBDAlloc(cmsContext ContextID);
-CMSAPI void             CMSEXPORT cmsGBDFree(cmsHANDLE hGBD);
-CMSAPI cmsBool          CMSEXPORT cmsGDBAddPoint(cmsHANDLE hGBD, const cmsCIELab* Lab);
-CMSAPI cmsBool          CMSEXPORT cmsGDBCompute(cmsHANDLE  hGDB, cmsUInt32Number dwFlags);
-CMSAPI cmsBool          CMSEXPORT cmsGDBCheckPoint(cmsHANDLE hGBD, const cmsCIELab* Lab);
-
-// Feature detection  ----------------------------------------------------------------------------------------------
-
-// Estimate the black point
-CMSAPI cmsBool          CMSEXPORT cmsDetectBlackPoint(cmsCIEXYZ* BlackPoint, cmsHPROFILE hProfile, cmsUInt32Number Intent, cmsUInt32Number dwFlags);
-CMSAPI cmsBool          CMSEXPORT cmsDetectDestinationBlackPoint(cmsCIEXYZ* BlackPoint, cmsHPROFILE hProfile, cmsUInt32Number Intent, cmsUInt32Number dwFlags);
-
-// Estimate total area coverage
-CMSAPI cmsFloat64Number CMSEXPORT cmsDetectTAC(cmsHPROFILE hProfile);
-
-
-// Poor man's gamut mapping
-CMSAPI cmsBool          CMSEXPORT cmsDesaturateLab(cmsCIELab* Lab,
-                                                   double amax, double amin,
-                                                   double bmax, double bmin);
-
-#ifndef CMS_USE_CPP_API
-#   ifdef __cplusplus
-    }
-#   endif
-#endif
-
-#define _lcms2_H
-#endif
diff --git a/core/src/fxcodec/lcms2/lcms2-2.6/include/lcms2_plugin.h b/core/src/fxcodec/lcms2/lcms2-2.6/include/lcms2_plugin.h
deleted file mode 100644 (file)
index 0c95d1f..0000000
+++ /dev/null
@@ -1,637 +0,0 @@
-//---------------------------------------------------------------------------------
-//
-//  Little Color Management System
-//  Copyright (c) 1998-2011 Marti Maria Saguer
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the "Software"),
-// to deal in the Software without restriction, including without limitation
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,
-// and/or sell copies of the Software, and to permit persons to whom the Software
-// is furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
-// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-//---------------------------------------------------------------------------------
-//
-// This is the plug-in header file. Normal LittleCMS clients should not use it.
-// It is provided for plug-in writters that may want to access the support
-// functions to do low level operations. All plug-in related structures
-// are defined here. Including this file forces to include the standard API too.
-
-#ifndef _lcms_plugin_H
-
-// Deal with Microsoft's attempt at deprecating C standard runtime functions
-#ifdef _MSC_VER
-#    if (_MSC_VER >= 1400)
-#      ifndef _CRT_SECURE_NO_DEPRECATE
-#        define _CRT_SECURE_NO_DEPRECATE
-#      endif
-#      ifndef _CRT_SECURE_NO_WARNINGS
-#        define _CRT_SECURE_NO_WARNINGS
-#      endif
-#    endif
-#endif
-
-#ifndef _lcms2_H
-#include "lcms2.h"
-#endif
-
-// We need some standard C functions.
-#include <stdlib.h>
-#include <math.h>
-#include <stdarg.h>
-#include <memory.h>
-#include <string.h>
-
-
-#ifndef CMS_USE_CPP_API
-#   ifdef __cplusplus
-extern "C" {
-#   endif
-#endif
-
-// Vector & Matrix operations -----------------------------------------------------------------------
-
-// Axis of the matrix/array. No specific meaning at all.
-#define VX      0
-#define VY      1
-#define VZ      2
-
-// Vectors
-typedef struct {
-    cmsFloat64Number n[3];
-
-    } cmsVEC3;
-
-// 3x3 Matrix
-typedef struct {
-    cmsVEC3 v[3];
-
-    } cmsMAT3;
-
-CMSAPI void               CMSEXPORT _cmsVEC3init(cmsVEC3* r, cmsFloat64Number x, cmsFloat64Number y, cmsFloat64Number z);
-CMSAPI void               CMSEXPORT _cmsVEC3minus(cmsVEC3* r, const cmsVEC3* a, const cmsVEC3* b);
-CMSAPI void               CMSEXPORT _cmsVEC3cross(cmsVEC3* r, const cmsVEC3* u, const cmsVEC3* v);
-CMSAPI cmsFloat64Number   CMSEXPORT _cmsVEC3dot(const cmsVEC3* u, const cmsVEC3* v);
-CMSAPI cmsFloat64Number   CMSEXPORT _cmsVEC3length(const cmsVEC3* a);
-CMSAPI cmsFloat64Number   CMSEXPORT _cmsVEC3distance(const cmsVEC3* a, const cmsVEC3* b);
-
-CMSAPI void               CMSEXPORT _cmsMAT3identity(cmsMAT3* a);
-CMSAPI cmsBool            CMSEXPORT _cmsMAT3isIdentity(const cmsMAT3* a);
-CMSAPI void               CMSEXPORT _cmsMAT3per(cmsMAT3* r, const cmsMAT3* a, const cmsMAT3* b);
-CMSAPI cmsBool            CMSEXPORT _cmsMAT3inverse(const cmsMAT3* a, cmsMAT3* b);
-CMSAPI cmsBool            CMSEXPORT _cmsMAT3solve(cmsVEC3* x, cmsMAT3* a, cmsVEC3* b);
-CMSAPI void               CMSEXPORT _cmsMAT3eval(cmsVEC3* r, const cmsMAT3* a, const cmsVEC3* v);
-
-
-// Error logging  -------------------------------------------------------------------------------------
-
-CMSAPI void               CMSEXPORT  cmsSignalError(cmsContext ContextID, cmsUInt32Number ErrorCode, const char *ErrorText, ...);
-
-// Memory management ----------------------------------------------------------------------------------
-
-CMSAPI void*              CMSEXPORT _cmsMalloc(cmsContext ContextID, cmsUInt32Number size);
-CMSAPI void*              CMSEXPORT _cmsMallocZero(cmsContext ContextID, cmsUInt32Number size);
-CMSAPI void*              CMSEXPORT _cmsCalloc(cmsContext ContextID, cmsUInt32Number num, cmsUInt32Number size);
-CMSAPI void*              CMSEXPORT _cmsRealloc(cmsContext ContextID, void* Ptr, cmsUInt32Number NewSize);
-CMSAPI void               CMSEXPORT _cmsFree(cmsContext ContextID, void* Ptr);
-CMSAPI void*              CMSEXPORT _cmsDupMem(cmsContext ContextID, const void* Org, cmsUInt32Number size);
-
-// I/O handler ----------------------------------------------------------------------------------
-
-struct _cms_io_handler {
-
-    void* stream;   // Associated stream, which is implemented differently depending on media.
-
-    cmsContext        ContextID;
-    cmsUInt32Number   UsedSpace;
-    cmsUInt32Number   ReportedSize;
-    char              PhysicalFile[cmsMAX_PATH];
-
-    cmsUInt32Number   (* Read)(struct _cms_io_handler* iohandler, void *Buffer,
-                                                                  cmsUInt32Number size,
-                                                                  cmsUInt32Number count);
-    cmsBool           (* Seek)(struct _cms_io_handler* iohandler, cmsUInt32Number offset);
-    cmsBool           (* Close)(struct _cms_io_handler* iohandler);
-    cmsUInt32Number   (* Tell)(struct _cms_io_handler* iohandler);
-    cmsBool           (* Write)(struct _cms_io_handler* iohandler, cmsUInt32Number size,
-                                                                   const void* Buffer);
-};
-
-// Endianess adjust functions
-CMSAPI cmsUInt16Number   CMSEXPORT  _cmsAdjustEndianess16(cmsUInt16Number Word);
-CMSAPI cmsUInt32Number   CMSEXPORT  _cmsAdjustEndianess32(cmsUInt32Number Value);
-CMSAPI void              CMSEXPORT  _cmsAdjustEndianess64(cmsUInt64Number* Result, cmsUInt64Number* QWord);
-
-// Helper IO functions
-CMSAPI cmsBool           CMSEXPORT  _cmsReadUInt8Number(cmsIOHANDLER* io,  cmsUInt8Number* n);
-CMSAPI cmsBool           CMSEXPORT  _cmsReadUInt16Number(cmsIOHANDLER* io, cmsUInt16Number* n);
-CMSAPI cmsBool           CMSEXPORT  _cmsReadUInt32Number(cmsIOHANDLER* io, cmsUInt32Number* n);
-CMSAPI cmsBool           CMSEXPORT  _cmsReadFloat32Number(cmsIOHANDLER* io, cmsFloat32Number* n);
-CMSAPI cmsBool           CMSEXPORT  _cmsReadUInt64Number(cmsIOHANDLER* io, cmsUInt64Number* n);
-CMSAPI cmsBool           CMSEXPORT  _cmsRead15Fixed16Number(cmsIOHANDLER* io, cmsFloat64Number* n);
-CMSAPI cmsBool           CMSEXPORT  _cmsReadXYZNumber(cmsIOHANDLER* io, cmsCIEXYZ* XYZ);
-CMSAPI cmsBool           CMSEXPORT  _cmsReadUInt16Array(cmsIOHANDLER* io, cmsUInt32Number n, cmsUInt16Number* Array);
-
-CMSAPI cmsBool           CMSEXPORT  _cmsWriteUInt8Number(cmsIOHANDLER* io, cmsUInt8Number n);
-CMSAPI cmsBool           CMSEXPORT  _cmsWriteUInt16Number(cmsIOHANDLER* io, cmsUInt16Number n);
-CMSAPI cmsBool           CMSEXPORT  _cmsWriteUInt32Number(cmsIOHANDLER* io, cmsUInt32Number n);
-CMSAPI cmsBool           CMSEXPORT  _cmsWriteFloat32Number(cmsIOHANDLER* io, cmsFloat32Number n);
-CMSAPI cmsBool           CMSEXPORT  _cmsWriteUInt64Number(cmsIOHANDLER* io, cmsUInt64Number* n);
-CMSAPI cmsBool           CMSEXPORT  _cmsWrite15Fixed16Number(cmsIOHANDLER* io, cmsFloat64Number n);
-CMSAPI cmsBool           CMSEXPORT  _cmsWriteXYZNumber(cmsIOHANDLER* io, const cmsCIEXYZ* XYZ);
-CMSAPI cmsBool           CMSEXPORT  _cmsWriteUInt16Array(cmsIOHANDLER* io, cmsUInt32Number n, const cmsUInt16Number* Array);
-
-// ICC base tag
-typedef struct {
-    cmsTagTypeSignature  sig;
-    cmsInt8Number        reserved[4];
-
-} _cmsTagBase;
-
-// Type base helper functions
-CMSAPI cmsTagTypeSignature  CMSEXPORT _cmsReadTypeBase(cmsIOHANDLER* io);
-CMSAPI cmsBool              CMSEXPORT _cmsWriteTypeBase(cmsIOHANDLER* io, cmsTagTypeSignature sig);
-
-// Alignment functions
-CMSAPI cmsBool             CMSEXPORT _cmsReadAlignment(cmsIOHANDLER* io);
-CMSAPI cmsBool             CMSEXPORT _cmsWriteAlignment(cmsIOHANDLER* io);
-
-// To deal with text streams. 2K at most
-CMSAPI cmsBool             CMSEXPORT _cmsIOPrintf(cmsIOHANDLER* io, const char* frm, ...);
-
-// Fixed point helper functions
-CMSAPI cmsFloat64Number    CMSEXPORT _cms8Fixed8toDouble(cmsUInt16Number fixed8);
-CMSAPI cmsUInt16Number     CMSEXPORT _cmsDoubleTo8Fixed8(cmsFloat64Number val);
-
-CMSAPI cmsFloat64Number    CMSEXPORT _cms15Fixed16toDouble(cmsS15Fixed16Number fix32);
-CMSAPI cmsS15Fixed16Number CMSEXPORT _cmsDoubleTo15Fixed16(cmsFloat64Number v);
-
-// Date/time helper functions
-CMSAPI void                CMSEXPORT _cmsEncodeDateTimeNumber(cmsDateTimeNumber *Dest, const struct tm *Source);
-CMSAPI void                CMSEXPORT _cmsDecodeDateTimeNumber(const cmsDateTimeNumber *Source, struct tm *Dest);
-
-//----------------------------------------------------------------------------------------------------------
-
-// Shared callbacks for user data
-typedef void     (* _cmsFreeUserDataFn)(cmsContext ContextID, void* Data);
-typedef void*    (* _cmsDupUserDataFn)(cmsContext ContextID, const void* Data);
-
-//----------------------------------------------------------------------------------------------------------
-
-// Plug-in foundation
-#define cmsPluginMagicNumber                 0x61637070     // 'acpp'
-
-#define cmsPluginMemHandlerSig               0x6D656D48     // 'memH'
-#define cmsPluginInterpolationSig            0x696E7048     // 'inpH'
-#define cmsPluginParametricCurveSig          0x70617248     // 'parH'
-#define cmsPluginFormattersSig               0x66726D48     // 'frmH
-#define cmsPluginTagTypeSig                  0x74797048     // 'typH'
-#define cmsPluginTagSig                      0x74616748     // 'tagH'
-#define cmsPluginRenderingIntentSig          0x696E7448     // 'intH'
-#define cmsPluginMultiProcessElementSig      0x6D706548     // 'mpeH'
-#define cmsPluginOptimizationSig             0x6F707448     // 'optH'
-#define cmsPluginTransformSig                0x7A666D48     // 'xfmH'
-#define cmsPluginMutexSig                    0x6D747A48     // 'mtxH'
-
-typedef struct _cmsPluginBaseStruct {
-
-        cmsUInt32Number                Magic;               // 'acpp' signature
-        cmsUInt32Number                ExpectedVersion;     // Expected version of LittleCMS
-        cmsUInt32Number                Type;                // Type of plug-in
-        struct _cmsPluginBaseStruct*   Next;                // For multiple plugin definition. NULL for end of list.
-
-} cmsPluginBase;
-
-// Maximum number of types in a plugin array
-#define MAX_TYPES_IN_LCMS_PLUGIN    20
-
-//----------------------------------------------------------------------------------------------------------
-
-// Memory handler. Each new plug-in type replaces current behaviour
-
-typedef void* (* _cmsMallocFnPtrType)(cmsContext ContextID, cmsUInt32Number size); 
-typedef void  (* _cmsFreeFnPtrType)(cmsContext ContextID, void *Ptr);
-typedef void* (* _cmsReallocFnPtrType)(cmsContext ContextID, void* Ptr, cmsUInt32Number NewSize);
-
-typedef void* (* _cmsMalloZerocFnPtrType)(cmsContext ContextID, cmsUInt32Number size); 
-typedef void* (* _cmsCallocFnPtrType)(cmsContext ContextID, cmsUInt32Number num, cmsUInt32Number size);
-typedef void* (* _cmsDupFnPtrType)(cmsContext ContextID, const void* Org, cmsUInt32Number size);
-
-typedef struct {
-
-        cmsPluginBase base;
-
-        // Required
-        _cmsMallocFnPtrType  MallocPtr;
-        _cmsFreeFnPtrType    FreePtr;
-        _cmsReallocFnPtrType ReallocPtr;
-
-        // Optional
-       _cmsMalloZerocFnPtrType MallocZeroPtr;
-       _cmsCallocFnPtrType     CallocPtr;
-       _cmsDupFnPtrType        DupPtr;
-
-} cmsPluginMemHandler;
-
-
-// ------------------------------------------------------------------------------------------------------------------
-
-// Interpolation. 16 bits and floating point versions.
-struct _cms_interp_struc;
-
-// Interpolation callbacks
-
-// 16 bits forward interpolation. This function performs precision-limited linear interpolation
-// and is supposed to be quite fast. Implementation may be tetrahedral or trilinear, and plug-ins may
-// choose to implement any other interpolation algorithm.
-typedef void (* _cmsInterpFn16)(register const cmsUInt16Number Input[],
-                                register cmsUInt16Number Output[],
-                                register const struct _cms_interp_struc* p);
-
-// Floating point forward interpolation. Full precision interpolation using floats. This is not a
-// time critical function. Implementation may be tetrahedral or trilinear, and plug-ins may
-// choose to implement any other interpolation algorithm.
-typedef void (* _cmsInterpFnFloat)(cmsFloat32Number const Input[],
-                                   cmsFloat32Number Output[],
-                                   const struct _cms_interp_struc* p);
-
-
-
-// This type holds a pointer to an interpolator that can be either 16 bits or float
-typedef union {
-    _cmsInterpFn16       Lerp16;            // Forward interpolation in 16 bits
-    _cmsInterpFnFloat    LerpFloat;         // Forward interpolation in floating point
-} cmsInterpFunction;
-
-// Flags for interpolator selection
-#define CMS_LERP_FLAGS_16BITS             0x0000        // The default
-#define CMS_LERP_FLAGS_FLOAT              0x0001        // Requires different implementation
-#define CMS_LERP_FLAGS_TRILINEAR          0x0100        // Hint only
-
-
-#define MAX_INPUT_DIMENSIONS 8
-
-typedef struct _cms_interp_struc {  // Used on all interpolations. Supplied by lcms2 when calling the interpolation function
-
-    cmsContext ContextID;     // The calling thread
-
-    cmsUInt32Number dwFlags;  // Keep original flags
-    cmsUInt32Number nInputs;  // != 1 only in 3D interpolation
-    cmsUInt32Number nOutputs; // != 1 only in 3D interpolation
-
-    cmsUInt32Number nSamples[MAX_INPUT_DIMENSIONS];  // Valid on all kinds of tables
-    cmsUInt32Number Domain[MAX_INPUT_DIMENSIONS];    // Domain = nSamples - 1
-
-    cmsUInt32Number opta[MAX_INPUT_DIMENSIONS];     // Optimization for 3D CLUT. This is the number of nodes premultiplied for each
-                                                    // dimension. For example, in 7 nodes, 7, 7^2 , 7^3, 7^4, etc. On non-regular
-                                                    // Samplings may vary according of the number of nodes for each dimension.
-
-    const void *Table;                // Points to the actual interpolation table
-    cmsInterpFunction Interpolation;  // Points to the function to do the interpolation
-
- } cmsInterpParams;
-
-// Interpolators factory
-typedef cmsInterpFunction (* cmsInterpFnFactory)(cmsUInt32Number nInputChannels, cmsUInt32Number nOutputChannels, cmsUInt32Number dwFlags);
-
-// The plug-in
-typedef struct {
-    cmsPluginBase base;
-
-    // Points to a user-supplied function which implements the factory
-    cmsInterpFnFactory InterpolatorsFactory;
-
-} cmsPluginInterpolation;
-
-//----------------------------------------------------------------------------------------------------------
-
-// Parametric curves. A negative type means same function but analytically inverted. Max. number of params is 10
-
-// Evaluator callback for user-suplied parametric curves. May implement more than one type
-typedef  cmsFloat64Number (* cmsParametricCurveEvaluator)(cmsInt32Number Type, const cmsFloat64Number Params[10], cmsFloat64Number R);
-
-// Plug-in may implement an arbitrary number of parametric curves
-typedef struct {
-    cmsPluginBase base;
-
-    cmsUInt32Number nFunctions;                                     // Number of supported functions
-    cmsUInt32Number FunctionTypes[MAX_TYPES_IN_LCMS_PLUGIN];        // The identification types
-    cmsUInt32Number ParameterCount[MAX_TYPES_IN_LCMS_PLUGIN];       // Number of parameters for each function
-
-    cmsParametricCurveEvaluator    Evaluator;                       // The evaluator
-
-} cmsPluginParametricCurves;
-//----------------------------------------------------------------------------------------------------------
-
-// Formatters. This plug-in adds new handlers, replacing them if they already exist. Formatters dealing with
-// cmsFloat32Number (bps = 4) or double (bps = 0) types are requested via FormatterFloat callback. Others come across
-// Formatter16 callback
-
-struct _cmstransform_struct;
-
-typedef cmsUInt8Number* (* cmsFormatter16)(register struct _cmstransform_struct* CMMcargo,
-                                           register cmsUInt16Number Values[],
-                                           register cmsUInt8Number*  Buffer,
-                                           register cmsUInt32Number  Stride);
-
-typedef cmsUInt8Number* (* cmsFormatterFloat)(struct _cmstransform_struct* CMMcargo,
-                                              cmsFloat32Number Values[],
-                                              cmsUInt8Number*  Buffer,
-                                              cmsUInt32Number  Stride);
-
-// This type holds a pointer to a formatter that can be either 16 bits or cmsFloat32Number
-typedef union {
-    cmsFormatter16    Fmt16;
-    cmsFormatterFloat FmtFloat;
-
-} cmsFormatter;
-
-#define CMS_PACK_FLAGS_16BITS       0x0000
-#define CMS_PACK_FLAGS_FLOAT        0x0001
-
-typedef enum { cmsFormatterInput=0, cmsFormatterOutput=1 } cmsFormatterDirection;
-
-typedef cmsFormatter (* cmsFormatterFactory)(cmsUInt32Number Type,           // Specific type, i.e. TYPE_RGB_8
-                                             cmsFormatterDirection Dir,
-                                             cmsUInt32Number dwFlags);      // precision
-
-// Plug-in may implement an arbitrary number of formatters
-typedef struct {
-    cmsPluginBase          base;
-    cmsFormatterFactory    FormattersFactory;
-
-} cmsPluginFormatters;
-
-//----------------------------------------------------------------------------------------------------------
-
-// Tag type handler. Each type is free to return anything it wants, and it is up to the caller to
-// know in advance what is the type contained in the tag.
-typedef struct _cms_typehandler_struct {
-
-        cmsTagTypeSignature Signature;     // The signature of the type
-
-        // Allocates and reads items
-        void *   (* ReadPtr)(struct _cms_typehandler_struct* self,
-                             cmsIOHANDLER*      io,
-                             cmsUInt32Number*   nItems,
-                             cmsUInt32Number    SizeOfTag);
-
-        // Writes n Items
-        cmsBool  (* WritePtr)(struct _cms_typehandler_struct* self,
-                              cmsIOHANDLER*     io,
-                              void*             Ptr,
-                              cmsUInt32Number   nItems);
-
-        // Duplicate an item or array of items
-        void*   (* DupPtr)(struct _cms_typehandler_struct* self,
-                           const void *Ptr,
-                           cmsUInt32Number n);
-
-        // Free all resources
-        void    (* FreePtr)(struct _cms_typehandler_struct* self,
-                            void *Ptr);
-
-        // Additional parameters used by the calling thread
-        cmsContext       ContextID;
-        cmsUInt32Number  ICCVersion;
-
-} cmsTagTypeHandler;
-
-// Each plug-in implements a single type
-typedef struct {
-        cmsPluginBase      base;
-        cmsTagTypeHandler  Handler;
-
-} cmsPluginTagType;
-
-//----------------------------------------------------------------------------------------------------------
-
-// This is the tag plugin, which identifies tags. For writing, a pointer to function is provided.
-// This function should return the desired type for this tag, given the version of profile
-// and the data being serialized.
-typedef struct {
-
-    cmsUInt32Number     ElemCount;          // If this tag needs an array, how many elements should keep
-
-    // For reading.
-    cmsUInt32Number     nSupportedTypes;    // In how many types this tag can come (MAX_TYPES_IN_LCMS_PLUGIN maximum)
-    cmsTagTypeSignature SupportedTypes[MAX_TYPES_IN_LCMS_PLUGIN];
-
-    // For writting
-    cmsTagTypeSignature (* DecideType)(cmsFloat64Number ICCVersion, const void *Data);
-
-} cmsTagDescriptor;
-
-// Plug-in implements a single tag
-typedef struct {
-    cmsPluginBase    base;
-
-    cmsTagSignature  Signature;
-    cmsTagDescriptor Descriptor;
-
-} cmsPluginTag;
-
-//----------------------------------------------------------------------------------------------------------
-
-// Custom intents. This function should join all profiles specified in the array in
-// a single LUT. Any custom intent in the chain redirects to custom function. If more than
-// one custom intent is found, the one located first is invoked. Usually users should use only one
-// custom intent, so mixing custom intents in same multiprofile transform is not supported.
-
-typedef cmsPipeline* (* cmsIntentFn)( cmsContext       ContextID,
-                                      cmsUInt32Number  nProfiles,
-                                      cmsUInt32Number  Intents[],
-                                      cmsHPROFILE      hProfiles[],
-                                      cmsBool          BPC[],
-                                      cmsFloat64Number AdaptationStates[],
-                                      cmsUInt32Number  dwFlags);
-
-
-// Each plug-in defines a single intent number.
-typedef struct {
-    cmsPluginBase     base;
-    cmsUInt32Number   Intent;
-    cmsIntentFn       Link;
-    char              Description[256];
-
-} cmsPluginRenderingIntent;
-
-
-// The default ICC intents (perceptual, saturation, rel.col and abs.col)
-CMSAPI cmsPipeline*  CMSEXPORT _cmsDefaultICCintents(cmsContext       ContextID,
-                                                     cmsUInt32Number  nProfiles,
-                                                     cmsUInt32Number  Intents[],
-                                                     cmsHPROFILE      hProfiles[],
-                                                     cmsBool          BPC[],
-                                                     cmsFloat64Number AdaptationStates[],
-                                                     cmsUInt32Number  dwFlags);
-
-
-//----------------------------------------------------------------------------------------------------------
-
-// Pipelines, Multi Process Elements.
-
-typedef void (* _cmsStageEvalFn)     (const cmsFloat32Number In[], cmsFloat32Number Out[], const cmsStage* mpe);
-typedef void*(* _cmsStageDupElemFn)  (cmsStage* mpe);
-typedef void (* _cmsStageFreeElemFn) (cmsStage* mpe);
-
-
-// This function allocates a generic MPE
-CMSAPI cmsStage* CMSEXPORT _cmsStageAllocPlaceholder(cmsContext ContextID,
-                                cmsStageSignature     Type,
-                                cmsUInt32Number       InputChannels,
-                                cmsUInt32Number       OutputChannels,
-                                _cmsStageEvalFn       EvalPtr,            // Points to fn that evaluates the element (always in floating point)
-                                _cmsStageDupElemFn    DupElemPtr,         // Points to a fn that duplicates the stage
-                                _cmsStageFreeElemFn   FreePtr,            // Points to a fn that sets the element free
-                                void*                 Data);              // A generic pointer to whatever memory needed by the element
-typedef struct {
-      cmsPluginBase     base;
-      cmsTagTypeHandler Handler;
-
-}  cmsPluginMultiProcessElement;
-
-
-// Data kept in "Element" member of cmsStage
-
-// Curves
-typedef struct {
-    cmsUInt32Number nCurves;
-    cmsToneCurve**  TheCurves;
-
-} _cmsStageToneCurvesData;
-
-// Matrix
-typedef struct {
-    cmsFloat64Number*  Double;          // floating point for the matrix
-    cmsFloat64Number*  Offset;          // The offset
-
-} _cmsStageMatrixData;
-
-// CLUT
-typedef struct {
-
-    union {                       // Can have only one of both representations at same time
-        cmsUInt16Number*  T;      // Points to the table 16 bits table
-        cmsFloat32Number* TFloat; // Points to the cmsFloat32Number table
-
-    } Tab;
-
-    cmsInterpParams* Params;
-    cmsUInt32Number  nEntries;
-    cmsBool          HasFloatValues;
-
-} _cmsStageCLutData;
-
-
-//----------------------------------------------------------------------------------------------------------
-// Optimization. Using this plug-in, additional optimization strategies may be implemented.
-// The function should return TRUE if any optimization is done on the LUT, this terminates
-// the optimization  search. Or FALSE if it is unable to optimize and want to give a chance
-// to the rest of optimizers.
-
-typedef void     (* _cmsOPTeval16Fn)(register const cmsUInt16Number In[],
-                                     register cmsUInt16Number Out[],
-                                     register const void* Data);
-
-
-typedef cmsBool  (* _cmsOPToptimizeFn)(cmsPipeline** Lut,
-                                       cmsUInt32Number  Intent,
-                                       cmsUInt32Number* InputFormat,
-                                       cmsUInt32Number* OutputFormat,
-                                       cmsUInt32Number* dwFlags);
-
-// This function may be used to set the optional evaluator and a block of private data. If private data is being used, an optional
-// duplicator and free functions should also be specified in order to duplicate the LUT construct. Use NULL to inhibit such functionality.
-
-CMSAPI void CMSEXPORT _cmsPipelineSetOptimizationParameters(cmsPipeline* Lut,
-                                               _cmsOPTeval16Fn Eval16,
-                                               void* PrivateData,
-                                               _cmsFreeUserDataFn FreePrivateDataFn,
-                                               _cmsDupUserDataFn DupPrivateDataFn);
-
-typedef struct {
-      cmsPluginBase     base;
-
-      // Optimize entry point
-      _cmsOPToptimizeFn  OptimizePtr;
-
-}  cmsPluginOptimization;
-
-//----------------------------------------------------------------------------------------------------------
-// Full xform
-typedef void     (* _cmsTransformFn)(struct _cmstransform_struct *CMMcargo,
-                                     const void* InputBuffer,
-                                     void* OutputBuffer,
-                                     cmsUInt32Number Size,
-                                     cmsUInt32Number Stride);
-
-typedef cmsBool  (* _cmsTransformFactory)(_cmsTransformFn* xform,
-                                         void** UserData,
-                                         _cmsFreeUserDataFn* FreePrivateDataFn,
-                                         cmsPipeline** Lut,
-                                         cmsUInt32Number* InputFormat,
-                                         cmsUInt32Number* OutputFormat,
-                                         cmsUInt32Number* dwFlags);
-
-
-// Retrieve user data as specified by the factory
-CMSAPI void   CMSEXPORT _cmsSetTransformUserData(struct _cmstransform_struct *CMMcargo, void* ptr, _cmsFreeUserDataFn FreePrivateDataFn);
-CMSAPI void * CMSEXPORT _cmsGetTransformUserData(struct _cmstransform_struct *CMMcargo);
-
-
-// Retrieve formatters
-CMSAPI void   CMSEXPORT _cmsGetTransformFormatters16   (struct _cmstransform_struct *CMMcargo, cmsFormatter16* FromInput, cmsFormatter16* ToOutput);
-CMSAPI void   CMSEXPORT _cmsGetTransformFormattersFloat(struct _cmstransform_struct *CMMcargo, cmsFormatterFloat* FromInput, cmsFormatterFloat* ToOutput);
-
-typedef struct {
-      cmsPluginBase     base;
-
-      // Transform entry point
-      _cmsTransformFactory  Factory;
-
-}  cmsPluginTransform;
-
-//----------------------------------------------------------------------------------------------------------
-// Mutex 
-
-typedef void*    (* _cmsCreateMutexFnPtrType)(cmsContext ContextID);
-typedef void     (* _cmsDestroyMutexFnPtrType)(cmsContext ContextID, void* mtx);
-typedef cmsBool  (* _cmsLockMutexFnPtrType)(cmsContext ContextID, void* mtx);
-typedef void     (* _cmsUnlockMutexFnPtrType)(cmsContext ContextID, void* mtx);
-
-typedef struct {
-      cmsPluginBase     base;
-
-     _cmsCreateMutexFnPtrType  CreateMutexPtr;
-     _cmsDestroyMutexFnPtrType DestroyMutexPtr;
-     _cmsLockMutexFnPtrType    LockMutexPtr;
-     _cmsUnlockMutexFnPtrType  UnlockMutexPtr;
-
-}  cmsPluginMutex;
-
-CMSAPI void*   CMSEXPORT _cmsCreateMutex(cmsContext ContextID);
-CMSAPI void    CMSEXPORT _cmsDestroyMutex(cmsContext ContextID, void* mtx);
-CMSAPI cmsBool CMSEXPORT _cmsLockMutex(cmsContext ContextID, void* mtx);
-CMSAPI void    CMSEXPORT _cmsUnlockMutex(cmsContext ContextID, void* mtx);
-
-
-#ifndef CMS_USE_CPP_API
-#   ifdef __cplusplus
-    }
-#   endif
-#endif
-
-#define _lcms_plugin_H
-#endif
diff --git a/core/src/fxcodec/lcms2/lcms2-2.6/src/cmscam02.c b/core/src/fxcodec/lcms2/lcms2-2.6/src/cmscam02.c
deleted file mode 100644 (file)
index 9d874aa..0000000
+++ /dev/null
@@ -1,486 +0,0 @@
-//---------------------------------------------------------------------------------
-//
-//  Little Color Management System
-//  Copyright (c) 1998-2012 Marti Maria Saguer
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the "Software"),
-// to deal in the Software without restriction, including without limitation
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,
-// and/or sell copies of the Software, and to permit persons to whom the Software
-// is furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
-// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-//---------------------------------------------------------------------------------
-//
-
-#include "lcms2_internal.h"
-
-// CIECAM 02 appearance model. Many thanks to Jordi Vilar for the debugging.
-
-// ---------- Implementation --------------------------------------------
-
-typedef struct  {
-
-    cmsFloat64Number XYZ[3];
-    cmsFloat64Number RGB[3];
-    cmsFloat64Number RGBc[3];
-    cmsFloat64Number RGBp[3];
-    cmsFloat64Number RGBpa[3];
-    cmsFloat64Number a, b, h, e, H, A, J, Q, s, t, C, M;
-    cmsFloat64Number abC[2];
-    cmsFloat64Number abs[2];
-    cmsFloat64Number abM[2];
-
-} CAM02COLOR;
-
-typedef struct  {
-
-    CAM02COLOR adoptedWhite;
-    cmsFloat64Number LA, Yb;
-    cmsFloat64Number F, c, Nc;
-    cmsUInt32Number surround;
-    cmsFloat64Number n, Nbb, Ncb, z, FL, D;
-
-    cmsContext ContextID;
-
-} cmsCIECAM02;
-
-
-static
-cmsFloat64Number compute_n(cmsCIECAM02* pMod)
-{
-    return (pMod -> Yb / pMod -> adoptedWhite.XYZ[1]);
-}
-
-static
-cmsFloat64Number compute_z(cmsCIECAM02* pMod)
-{
-    return (1.48 + pow(pMod -> n, 0.5));
-}
-
-static
-cmsFloat64Number computeNbb(cmsCIECAM02* pMod)
-{
-    return (0.725 * pow((1.0 / pMod -> n), 0.2));
-}
-
-static
-cmsFloat64Number computeFL(cmsCIECAM02* pMod)
-{
-    cmsFloat64Number k, FL;
-
-    k = 1.0 / ((5.0 * pMod->LA) + 1.0);
-    FL = 0.2 * pow(k, 4.0) * (5.0 * pMod->LA) + 0.1 *
-        (pow((1.0 - pow(k, 4.0)), 2.0)) *
-        (pow((5.0 * pMod->LA), (1.0 / 3.0)));
-
-    return FL;
-}
-
-static
-cmsFloat64Number computeD(cmsCIECAM02* pMod)
-{
-    cmsFloat64Number D;
-
-    D = pMod->F - (1.0/3.6)*(exp(((-pMod ->LA-42) / 92.0)));
-
-    return D;
-}
-
-
-static
-CAM02COLOR XYZtoCAT02(CAM02COLOR clr)
-{
-    clr.RGB[0] = (clr.XYZ[0] *  0.7328) + (clr.XYZ[1] *  0.4296) + (clr.XYZ[2] * -0.1624);
-    clr.RGB[1] = (clr.XYZ[0] * -0.7036) + (clr.XYZ[1] *  1.6975) + (clr.XYZ[2] *  0.0061);
-    clr.RGB[2] = (clr.XYZ[0] *  0.0030) + (clr.XYZ[1] *  0.0136) + (clr.XYZ[2] *  0.9834);
-
-    return clr;
-}
-
-static
-CAM02COLOR ChromaticAdaptation(CAM02COLOR clr, cmsCIECAM02* pMod)
-{
-    cmsUInt32Number i;
-
-    for (i = 0; i < 3; i++) {
-        clr.RGBc[i] = ((pMod -> adoptedWhite.XYZ[1] *
-            (pMod->D / pMod -> adoptedWhite.RGB[i])) +
-            (1.0 - pMod->D)) * clr.RGB[i];
-    }
-
-    return clr;
-}
-
-
-static
-CAM02COLOR CAT02toHPE(CAM02COLOR clr)
-{
-    cmsFloat64Number M[9];
-
-    M[0] =(( 0.38971 *  1.096124) + (0.68898 * 0.454369) + (-0.07868 * -0.009628));
-    M[1] =(( 0.38971 * -0.278869) + (0.68898 * 0.473533) + (-0.07868 * -0.005698));
-    M[2] =(( 0.38971 *  0.182745) + (0.68898 * 0.072098) + (-0.07868 *  1.015326));
-    M[3] =((-0.22981 *  1.096124) + (1.18340 * 0.454369) + ( 0.04641 * -0.009628));
-    M[4] =((-0.22981 * -0.278869) + (1.18340 * 0.473533) + ( 0.04641 * -0.005698));
-    M[5] =((-0.22981 *  0.182745) + (1.18340 * 0.072098) + ( 0.04641 *  1.015326));
-    M[6] =(-0.009628);
-    M[7] =(-0.005698);
-    M[8] =( 1.015326);
-
-    clr.RGBp[0] = (clr.RGBc[0] * M[0]) +  (clr.RGBc[1] * M[1]) + (clr.RGBc[2] * M[2]);
-    clr.RGBp[1] = (clr.RGBc[0] * M[3]) +  (clr.RGBc[1] * M[4]) + (clr.RGBc[2] * M[5]);
-    clr.RGBp[2] = (clr.RGBc[0] * M[6]) +  (clr.RGBc[1] * M[7]) + (clr.RGBc[2] * M[8]);
-
-    return  clr;
-}
-
-static
-CAM02COLOR NonlinearCompression(CAM02COLOR clr, cmsCIECAM02* pMod)
-{
-    cmsUInt32Number i;
-    cmsFloat64Number temp;
-
-    for (i = 0; i < 3; i++) {
-        if (clr.RGBp[i] < 0) {
-
-            temp = pow((-1.0 * pMod->FL * clr.RGBp[i] / 100.0), 0.42);
-            clr.RGBpa[i] = (-1.0 * 400.0 * temp) / (temp + 27.13) + 0.1;
-        }
-        else {
-            temp = pow((pMod->FL * clr.RGBp[i] / 100.0), 0.42);
-            clr.RGBpa[i] = (400.0 * temp) / (temp + 27.13) + 0.1;
-        }
-    }
-
-    clr.A = (((2.0 * clr.RGBpa[0]) + clr.RGBpa[1] +
-        (clr.RGBpa[2] / 20.0)) - 0.305) * pMod->Nbb;
-
-    return clr;
-}
-
-static
-CAM02COLOR ComputeCorrelates(CAM02COLOR clr, cmsCIECAM02* pMod)
-{
-    cmsFloat64Number a, b, temp, e, t, r2d, d2r;
-
-    a = clr.RGBpa[0] - (12.0 * clr.RGBpa[1] / 11.0) + (clr.RGBpa[2] / 11.0);
-    b = (clr.RGBpa[0] + clr.RGBpa[1] - (2.0 * clr.RGBpa[2])) / 9.0;
-
-    r2d = (180.0 / 3.141592654);
-    if (a == 0) {
-        if (b == 0)     clr.h = 0;
-        else if (b > 0) clr.h = 90;
-        else            clr.h = 270;
-    }
-    else if (a > 0) {
-        temp = b / a;
-        if (b > 0)       clr.h = (r2d * atan(temp));
-        else if (b == 0) clr.h = 0;
-        else             clr.h = (r2d * atan(temp)) + 360;
-    }
-    else {
-        temp = b / a;
-        clr.h = (r2d * atan(temp)) + 180;
-    }
-
-    d2r = (3.141592654 / 180.0);
-    e = ((12500.0 / 13.0) * pMod->Nc * pMod->Ncb) *
-        (cos((clr.h * d2r + 2.0)) + 3.8);
-
-    if (clr.h < 20.14) {
-        temp = ((clr.h + 122.47)/1.2) + ((20.14 - clr.h)/0.8);
-        clr.H = 300 + (100*((clr.h + 122.47)/1.2)) / temp;
-    }
-    else if (clr.h < 90.0) {
-        temp = ((clr.h - 20.14)/0.8) + ((90.00 - clr.h)/0.7);
-        clr.H = (100*((clr.h - 20.14)/0.8)) / temp;
-    }
-    else if (clr.h < 164.25) {
-        temp = ((clr.h - 90.00)/0.7) + ((164.25 - clr.h)/1.0);
-        clr.H = 100 + ((100*((clr.h - 90.00)/0.7)) / temp);
-    }
-    else if (clr.h < 237.53) {
-        temp = ((clr.h - 164.25)/1.0) + ((237.53 - clr.h)/1.2);
-        clr.H = 200 + ((100*((clr.h - 164.25)/1.0)) / temp);
-    }
-    else {
-        temp = ((clr.h - 237.53)/1.2) + ((360 - clr.h + 20.14)/0.8);
-        clr.H = 300 + ((100*((clr.h - 237.53)/1.2)) / temp);
-    }
-
-    clr.J = 100.0 * pow((clr.A / pMod->adoptedWhite.A),
-        (pMod->c * pMod->z));
-
-    clr.Q = (4.0 / pMod->c) * pow((clr.J / 100.0), 0.5) *
-        (pMod->adoptedWhite.A + 4.0) * pow(pMod->FL, 0.25);
-
-    t = (e * pow(((a * a) + (b * b)), 0.5)) /
-        (clr.RGBpa[0] + clr.RGBpa[1] +
-        ((21.0 / 20.0) * clr.RGBpa[2]));
-
-    clr.C = pow(t, 0.9) * pow((clr.J / 100.0), 0.5) *
-        pow((1.64 - pow(0.29, pMod->n)), 0.73);
-
-    clr.M = clr.C * pow(pMod->FL, 0.25);
-    clr.s = 100.0 * pow((clr.M / clr.Q), 0.5);
-
-    return clr;
-}
-
-
-static
-CAM02COLOR InverseCorrelates(CAM02COLOR clr, cmsCIECAM02* pMod)
-{
-
-    cmsFloat64Number t, e, p1, p2, p3, p4, p5, hr, d2r;
-    d2r = 3.141592654 / 180.0;
-
-    t = pow( (clr.C / (pow((clr.J / 100.0), 0.5) *
-        (pow((1.64 - pow(0.29, pMod->n)), 0.73)))),
-        (1.0 / 0.9) );
-    e = ((12500.0 / 13.0) * pMod->Nc * pMod->Ncb) *
-        (cos((clr.h * d2r + 2.0)) + 3.8);
-
-    clr.A = pMod->adoptedWhite.A * pow(
-           (clr.J / 100.0),
-           (1.0 / (pMod->c * pMod->z)));
-
-    p1 = e / t;
-    p2 = (clr.A / pMod->Nbb) + 0.305;
-    p3 = 21.0 / 20.0;
-
-    hr = clr.h * d2r;
-
-    if (fabs(sin(hr)) >= fabs(cos(hr))) {
-        p4 = p1 / sin(hr);
-        clr.b = (p2 * (2.0 + p3) * (460.0 / 1403.0)) /
-            (p4 + (2.0 + p3) * (220.0 / 1403.0) *
-            (cos(hr) / sin(hr)) - (27.0 / 1403.0) +
-            p3 * (6300.0 / 1403.0));
-        clr.a = clr.b * (cos(hr) / sin(hr));
-    }
-    else {
-        p5 = p1 / cos(hr);
-        clr.a = (p2 * (2.0 + p3) * (460.0 / 1403.0)) /
-            (p5 + (2.0 + p3) * (220.0 / 1403.0) -
-            ((27.0 / 1403.0) - p3 * (6300.0 / 1403.0)) *
-            (sin(hr) / cos(hr)));
-        clr.b = clr.a * (sin(hr) / cos(hr));
-    }
-
-    clr.RGBpa[0] = ((460.0 / 1403.0) * p2) +
-              ((451.0 / 1403.0) * clr.a) +
-              ((288.0 / 1403.0) * clr.b);
-    clr.RGBpa[1] = ((460.0 / 1403.0) * p2) -
-              ((891.0 / 1403.0) * clr.a) -
-              ((261.0 / 1403.0) * clr.b);
-    clr.RGBpa[2] = ((460.0 / 1403.0) * p2) -
-              ((220.0 / 1403.0) * clr.a) -
-              ((6300.0 / 1403.0) * clr.b);
-
-    return clr;
-}
-
-static
-CAM02COLOR InverseNonlinearity(CAM02COLOR clr, cmsCIECAM02* pMod)
-{
-    cmsUInt32Number i;
-    cmsFloat64Number c1;
-
-    for (i = 0; i < 3; i++) {
-        if ((clr.RGBpa[i] - 0.1) < 0) c1 = -1;
-        else                               c1 = 1;
-        clr.RGBp[i] = c1 * (100.0 / pMod->FL) *
-            pow(((27.13 * fabs(clr.RGBpa[i] - 0.1)) /
-            (400.0 - fabs(clr.RGBpa[i] - 0.1))),
-            (1.0 / 0.42));
-    }
-
-    return clr;
-}
-
-static
-CAM02COLOR HPEtoCAT02(CAM02COLOR clr)
-{
-    cmsFloat64Number M[9];
-
-    M[0] = (( 0.7328 *  1.910197) + (0.4296 * 0.370950));
-    M[1] = (( 0.7328 * -1.112124) + (0.4296 * 0.629054));
-    M[2] = (( 0.7328 *  0.201908) + (0.4296 * 0.000008) - 0.1624);
-    M[3] = ((-0.7036 *  1.910197) + (1.6975 * 0.370950));
-    M[4] = ((-0.7036 * -1.112124) + (1.6975 * 0.629054));
-    M[5] = ((-0.7036 *  0.201908) + (1.6975 * 0.000008) + 0.0061);
-    M[6] = (( 0.0030 *  1.910197) + (0.0136 * 0.370950));
-    M[7] = (( 0.0030 * -1.112124) + (0.0136 * 0.629054));
-    M[8] = (( 0.0030 *  0.201908) + (0.0136 * 0.000008) + 0.9834);;
-
-    clr.RGBc[0] = (clr.RGBp[0] * M[0]) + (clr.RGBp[1] * M[1]) + (clr.RGBp[2] * M[2]);
-    clr.RGBc[1] = (clr.RGBp[0] * M[3]) + (clr.RGBp[1] * M[4]) + (clr.RGBp[2] * M[5]);
-    clr.RGBc[2] = (clr.RGBp[0] * M[6]) + (clr.RGBp[1] * M[7]) + (clr.RGBp[2] * M[8]);
-    return clr;
-}
-
-
-static
-CAM02COLOR InverseChromaticAdaptation(CAM02COLOR clr,  cmsCIECAM02* pMod)
-{
-    cmsUInt32Number i;
-    for (i = 0; i < 3; i++) {
-        clr.RGB[i] = clr.RGBc[i] /
-            ((pMod->adoptedWhite.XYZ[1] * pMod->D / pMod->adoptedWhite.RGB[i]) + 1.0 - pMod->D);
-    }
-    return clr;
-}
-
-
-static
-CAM02COLOR CAT02toXYZ(CAM02COLOR clr)
-{
-    clr.XYZ[0] = (clr.RGB[0] *  1.096124) + (clr.RGB[1] * -0.278869) + (clr.RGB[2] *  0.182745);
-    clr.XYZ[1] = (clr.RGB[0] *  0.454369) + (clr.RGB[1] *  0.473533) + (clr.RGB[2] *  0.072098);
-    clr.XYZ[2] = (clr.RGB[0] * -0.009628) + (clr.RGB[1] * -0.005698) + (clr.RGB[2] *  1.015326);
-
-    return clr;
-}
-
-
-cmsHANDLE  CMSEXPORT cmsCIECAM02Init(cmsContext ContextID, const cmsViewingConditions* pVC)
-{
-    cmsCIECAM02* lpMod;
-
-    _cmsAssert(pVC != NULL);
-
-    if((lpMod = (cmsCIECAM02*) _cmsMallocZero(ContextID, sizeof(cmsCIECAM02))) == NULL) {
-        return NULL;
-    }
-
-    lpMod ->ContextID = ContextID;
-
-    lpMod ->adoptedWhite.XYZ[0] = pVC ->whitePoint.X;
-    lpMod ->adoptedWhite.XYZ[1] = pVC ->whitePoint.Y;
-    lpMod ->adoptedWhite.XYZ[2] = pVC ->whitePoint.Z;
-
-    lpMod -> LA       = pVC ->La;
-    lpMod -> Yb       = pVC ->Yb;
-    lpMod -> D        = pVC ->D_value;
-    lpMod -> surround = pVC ->surround;
-
-    switch (lpMod -> surround) {
-
-
-    case CUTSHEET_SURROUND:
-        lpMod->F = 0.8;
-        lpMod->c = 0.41;
-        lpMod->Nc = 0.8;
-        break;
-
-    case DARK_SURROUND:
-        lpMod -> F  = 0.8;
-        lpMod -> c  = 0.525;
-        lpMod -> Nc = 0.8;
-        break;
-
-    case DIM_SURROUND:
-        lpMod -> F  = 0.9;
-        lpMod -> c  = 0.59;
-        lpMod -> Nc = 0.95;
-        break;
-
-    default:
-        // Average surround
-        lpMod -> F  = 1.0;
-        lpMod -> c  = 0.69;
-        lpMod -> Nc = 1.0;
-    }
-
-    lpMod -> n   = compute_n(lpMod);
-    lpMod -> z   = compute_z(lpMod);
-    lpMod -> Nbb = computeNbb(lpMod);
-    lpMod -> FL  = computeFL(lpMod);
-
-    if (lpMod -> D == D_CALCULATE) {
-        lpMod -> D   = computeD(lpMod);
-    }
-
-    lpMod -> Ncb = lpMod -> Nbb;
-
-    lpMod -> adoptedWhite = XYZtoCAT02(lpMod -> adoptedWhite);
-    lpMod -> adoptedWhite = ChromaticAdaptation(lpMod -> adoptedWhite, lpMod);
-    lpMod -> adoptedWhite = CAT02toHPE(lpMod -> adoptedWhite);
-    lpMod -> adoptedWhite = NonlinearCompression(lpMod -> adoptedWhite, lpMod);
-
-    return (cmsHANDLE) lpMod;
-
-}
-
-void CMSEXPORT cmsCIECAM02Done(cmsHANDLE hModel)
-{
-    cmsCIECAM02* lpMod = (cmsCIECAM02*) hModel;
-
-    if (lpMod) _cmsFree(lpMod ->ContextID, lpMod);
-}
-
-
-void CMSEXPORT cmsCIECAM02Forward(cmsHANDLE hModel, const cmsCIEXYZ* pIn, cmsJCh* pOut)
-{
-    CAM02COLOR clr;
-    cmsCIECAM02* lpMod = (cmsCIECAM02*) hModel;
-  
-    _cmsAssert(lpMod != NULL);
-    _cmsAssert(pIn != NULL);
-    _cmsAssert(pOut != NULL);
-
-    memset(&clr, 0, sizeof(clr));
-
-    clr.XYZ[0] = pIn ->X;
-    clr.XYZ[1] = pIn ->Y;
-    clr.XYZ[2] = pIn ->Z;
-
-    clr = XYZtoCAT02(clr);
-    clr = ChromaticAdaptation(clr, lpMod);
-    clr = CAT02toHPE(clr);
-    clr = NonlinearCompression(clr, lpMod);
-    clr = ComputeCorrelates(clr, lpMod);
-
-    pOut ->J = clr.J;
-    pOut ->C = clr.C;
-    pOut ->h = clr.h;
-}
-
-void CMSEXPORT cmsCIECAM02Reverse(cmsHANDLE hModel, const cmsJCh* pIn, cmsCIEXYZ* pOut)
-{
-    CAM02COLOR clr;
-    cmsCIECAM02* lpMod = (cmsCIECAM02*) hModel;
-    
-    _cmsAssert(lpMod != NULL);
-    _cmsAssert(pIn != NULL);
-    _cmsAssert(pOut != NULL);
-
-    memset(&clr, 0, sizeof(clr));
-
-    clr.J = pIn -> J;
-    clr.C = pIn -> C;
-    clr.h = pIn -> h;
-
-    clr = InverseCorrelates(clr, lpMod);
-    clr = InverseNonlinearity(clr, lpMod);
-    clr = HPEtoCAT02(clr);
-    clr = InverseChromaticAdaptation(clr, lpMod);
-    clr = CAT02toXYZ(clr);
-
-    pOut ->X = clr.XYZ[0];
-    pOut ->Y = clr.XYZ[1];
-    pOut ->Z = clr.XYZ[2];
-}
diff --git a/core/src/fxcodec/lcms2/lcms2-2.6/src/cmscgats.c b/core/src/fxcodec/lcms2/lcms2-2.6/src/cmscgats.c
deleted file mode 100644 (file)
index 9017435..0000000
+++ /dev/null
@@ -1,2775 +0,0 @@
-//---------------------------------------------------------------------------------
-//
-//  Little Color Management System
-//  Copyright (c) 1998-2012 Marti Maria Saguer
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the "Software"),
-// to deal in the Software without restriction, including without limitation
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,
-// and/or sell copies of the Software, and to permit persons to whom the Software
-// is furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
-// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-//---------------------------------------------------------------------------------
-//
-
-#include "lcms2_internal.h"
-
-
-// IT8.7 / CGATS.17-200x handling -----------------------------------------------------------------------------
-
-
-#define MAXID        128     // Max length of identifier
-#define MAXSTR      1024     // Max length of string
-#define MAXTABLES    255     // Max Number of tables in a single stream
-#define MAXINCLUDE    20     // Max number of nested includes
-
-#define DEFAULT_DBL_FORMAT  "%.10g" // Double formatting
-
-#ifdef CMS_IS_WINDOWS_
-//sunliang.liu modified 2010426 for wince error
-#      ifndef _WIN32_WCE
-#              include <io.h>
-#      endif
-#    define DIR_CHAR    '\\'
-#else
-#    define DIR_CHAR    '/'
-#endif
-
-
-// Symbols
-typedef enum {
-
-        SNONE,
-        SINUM,      // Integer
-        SDNUM,      // Real
-        SIDENT,     // Identifier
-        SSTRING,    // string
-        SCOMMENT,   // comment
-        SEOLN,      // End of line
-        SEOF,       // End of stream
-        SSYNERROR,  // Syntax error found on stream
-
-        // Keywords
-
-        SBEGIN_DATA,
-        SBEGIN_DATA_FORMAT,
-        SEND_DATA,
-        SEND_DATA_FORMAT,
-        SKEYWORD,
-        SDATA_FORMAT_ID,
-        SINCLUDE
-
-    } SYMBOL;
-
-
-// How to write the value
-typedef enum {
-
-        WRITE_UNCOOKED,
-        WRITE_STRINGIFY,
-        WRITE_HEXADECIMAL,
-        WRITE_BINARY,
-        WRITE_PAIR
-
-    } WRITEMODE;
-
-// Linked list of variable names
-typedef struct _KeyVal {
-
-        struct _KeyVal*  Next;
-        char*            Keyword;       // Name of variable
-        struct _KeyVal*  NextSubkey;    // If key is a dictionary, points to the next item
-        char*            Subkey;        // If key is a dictionary, points to the subkey name
-        char*            Value;         // Points to value
-        WRITEMODE        WriteAs;       // How to write the value
-
-   } KEYVALUE;
-
-
-// Linked list of memory chunks (Memory sink)
-typedef struct _OwnedMem {
-
-        struct _OwnedMem* Next;
-        void *            Ptr;          // Point to value
-
-   } OWNEDMEM;
-
-// Suballocator
-typedef struct _SubAllocator {
-
-         cmsUInt8Number* Block;
-         cmsUInt32Number BlockSize;
-         cmsUInt32Number Used;
-
-    } SUBALLOCATOR;
-
-// Table. Each individual table can hold properties and rows & cols
-typedef struct _Table {
-
-        char SheetType[MAXSTR];               // The first row of the IT8 (the type)
-
-        int            nSamples, nPatches;    // Cols, Rows
-        int            SampleID;              // Pos of ID
-
-        KEYVALUE*      HeaderList;            // The properties
-
-        char**         DataFormat;            // The binary stream descriptor
-        char**         Data;                  // The binary stream
-
-    } TABLE;
-
-// File stream being parsed
-typedef struct _FileContext {
-        char           FileName[cmsMAX_PATH];    // File name if being readed from file
-        FILE*          Stream;                   // File stream or NULL if holded in memory
-    } FILECTX;
-
-// This struct hold all information about an open IT8 handler.
-typedef struct {
-
-
-        cmsUInt32Number  TablesCount;                     // How many tables in this stream
-        cmsUInt32Number  nTable;                          // The actual table
-
-        TABLE Tab[MAXTABLES];
-
-        // Memory management
-        OWNEDMEM*      MemorySink;            // The storage backend
-        SUBALLOCATOR   Allocator;             // String suballocator -- just to keep it fast
-
-        // Parser state machine
-        SYMBOL         sy;                    // Current symbol
-        int            ch;                    // Current character
-
-        int            inum;                  // integer value
-        cmsFloat64Number         dnum;                  // real value
-        char           id[MAXID];             // identifier
-        char           str[MAXSTR];           // string
-
-        // Allowed keywords & datasets. They have visibility on whole stream
-        KEYVALUE*     ValidKeywords;
-        KEYVALUE*     ValidSampleID;
-
-        char*          Source;                // Points to loc. being parsed
-        int            lineno;                // line counter for error reporting
-
-        FILECTX*       FileStack[MAXINCLUDE]; // Stack of files being parsed
-        int            IncludeSP;             // Include Stack Pointer
-
-        char*          MemoryBlock;           // The stream if holded in memory
-
-        char           DoubleFormatter[MAXID];// Printf-like 'cmsFloat64Number' formatter
-
-        cmsContext    ContextID;              // The threading context
-
-   } cmsIT8;
-
-
-// The stream for save operations
-typedef struct {
-
-        FILE* stream;   // For save-to-file behaviour
-
-        cmsUInt8Number* Base;
-        cmsUInt8Number* Ptr;        // For save-to-mem behaviour
-        cmsUInt32Number Used;
-        cmsUInt32Number Max;
-
-    } SAVESTREAM;
-
-
-// ------------------------------------------------------ cmsIT8 parsing routines
-
-
-// A keyword
-typedef struct {
-
-        const char *id;
-        SYMBOL sy;
-
-   } KEYWORD;
-
-// The keyword->symbol translation table. Sorting is required.
-static const KEYWORD TabKeys[] = {
-
-        {"$INCLUDE",               SINCLUDE},   // This is an extension!
-        {".INCLUDE",               SINCLUDE},   // This is an extension!
-
-        {"BEGIN_DATA",             SBEGIN_DATA },
-        {"BEGIN_DATA_FORMAT",      SBEGIN_DATA_FORMAT },
-        {"DATA_FORMAT_IDENTIFIER", SDATA_FORMAT_ID},
-        {"END_DATA",               SEND_DATA},
-        {"END_DATA_FORMAT",        SEND_DATA_FORMAT},
-        {"KEYWORD",                SKEYWORD}
-        };
-
-#define NUMKEYS (sizeof(TabKeys)/sizeof(KEYWORD))
-
-// Predefined properties
-
-// A property
-typedef struct {
-        const char *id;    // The identifier
-        WRITEMODE as;      // How is supposed to be written
-    } PROPERTY;
-
-static PROPERTY PredefinedProperties[] = {
-
-        {"NUMBER_OF_FIELDS", WRITE_UNCOOKED},    // Required - NUMBER OF FIELDS
-        {"NUMBER_OF_SETS",   WRITE_UNCOOKED},    // Required - NUMBER OF SETS
-        {"ORIGINATOR",       WRITE_STRINGIFY},   // Required - Identifies the specific system, organization or individual that created the data file.
-        {"FILE_DESCRIPTOR",  WRITE_STRINGIFY},   // Required - Describes the purpose or contents of the data file.
-        {"CREATED",          WRITE_STRINGIFY},   // Required - Indicates date of creation of the data file.
-        {"DESCRIPTOR",       WRITE_STRINGIFY},   // Required  - Describes the purpose or contents of the data file.
-        {"DIFFUSE_GEOMETRY", WRITE_STRINGIFY},   // The diffuse geometry used. Allowed values are "sphere" or "opal".
-        {"MANUFACTURER",     WRITE_STRINGIFY},
-        {"MANUFACTURE",      WRITE_STRINGIFY},   // Some broken Fuji targets does store this value
-        {"PROD_DATE",        WRITE_STRINGIFY},   // Identifies year and month of production of the target in the form yyyy:mm.
-        {"SERIAL",           WRITE_STRINGIFY},   // Uniquely identifies individual physical target.
-
-        {"MATERIAL",         WRITE_STRINGIFY},   // Identifies the material on which the target was produced using a code
-                               // uniquely identifying th e material. This is intend ed to be used for IT8.7
-                               // physical targets only (i.e . IT8.7/1 a nd IT8.7/2).
-
-        {"INSTRUMENTATION",  WRITE_STRINGIFY},   // Used to report the specific instrumentation used (manufacturer and
-                               // model number) to generate the data reported. This data will often
-                               // provide more information about the particular data collected than an
-                               // extensive list of specific details. This is particularly important for
-                               // spectral data or data derived from spectrophotometry.
-
-        {"MEASUREMENT_SOURCE", WRITE_STRINGIFY}, // Illumination used for spectral measurements. This data helps provide
-                               // a guide to the potential for issues of paper fluorescence, etc.
-
-        {"PRINT_CONDITIONS", WRITE_STRINGIFY},   // Used to define the characteristics of the printed sheet being reported.
-                               // Where standard conditions have been defined (e.g., SWOP at nominal)
-                               // named conditions may suffice. Otherwise, detailed information is
-                               // needed.
-
-        {"SAMPLE_BACKING",   WRITE_STRINGIFY},   // Identifies the backing material used behind the sample during
-                               // measurement. Allowed values are “black? “white? or {"na".
-
-        {"CHISQ_DOF",        WRITE_STRINGIFY},   // Degrees of freedom associated with the Chi squared statistic
-
-       // below properties are new in recent specs:
-
-        {"MEASUREMENT_GEOMETRY", WRITE_STRINGIFY}, // The type of measurement, either reflection or transmission, should be indicated
-                               // along with details of the geometry and the aperture size and shape. For example,
-                               // for transmission measurements it is important to identify 0/diffuse, diffuse/0,
-                               // opal or integrating sphere, etc. For reflection it is important to identify 0/45,
-                               // 45/0, sphere (specular included or excluded), etc.
-
-       {"FILTER",            WRITE_STRINGIFY},   // Identifies the use of physical filter(s) during measurement. Typically used to
-                               // denote the use of filters such as none, D65, Red, Green or Blue.
-
-       {"POLARIZATION",      WRITE_STRINGIFY},   // Identifies the use of a physical polarization filter during measurement. Allowed
-                               // values are {"yes? “white? “none?or “na?
-
-       {"WEIGHTING_FUNCTION", WRITE_PAIR},   // Indicates such functions as: the CIE standard observer functions used in the
-                               // calculation of various data parameters (2 degree and 10 degree), CIE standard
-                               // illuminant functions used in the calculation of various data parameters (e.g., D50,
-                               // D65, etc.), density status response, etc. If used there shall be at least one
-                               // name-value pair following the WEIGHTING_FUNCTION tag/keyword. The first attribute
-                               // in the set shall be {"name" and shall identify the particular parameter used.
-                               // The second shall be {"value" and shall provide the value associated with that name.
-                               // For ASCII data, a string containing the Name and Value attribute pairs shall follow
-                               // the weighting function keyword. A semi-colon separates attribute pairs from each
-                               // other and within the attribute the name and value are separated by a comma.
-
-       {"COMPUTATIONAL_PARAMETER", WRITE_PAIR}, // Parameter that is used in computing a value from measured data. Name is the name
-                               // of the calculation, parameter is the name of the parameter used in the calculation
-                               // and value is the value of the parameter.
-
-       {"TARGET_TYPE",        WRITE_STRINGIFY},  // The type of target being measured, e.g. IT8.7/1, IT8.7/3, user defined, etc.
-
-       {"COLORANT",           WRITE_STRINGIFY},  // Identifies the colorant(s) used in creating the target.
-
-       {"TABLE_DESCRIPTOR",   WRITE_STRINGIFY},  // Describes the purpose or contents of a data table.
-
-       {"TABLE_NAME",         WRITE_STRINGIFY}   // Provides a short name for a data table.
-};
-
-#define NUMPREDEFINEDPROPS (sizeof(PredefinedProperties)/sizeof(PROPERTY))
-
-
-// Predefined sample types on dataset
-static const char* PredefinedSampleID[] = {
-        "SAMPLE_ID",      // Identifies sample that data represents
-        "STRING",         // Identifies label, or other non-machine readable value.
-                          // Value must begin and end with a " symbol
-
-        "CMYK_C",         // Cyan component of CMYK data expressed as a percentage
-        "CMYK_M",         // Magenta component of CMYK data expressed as a percentage
-        "CMYK_Y",         // Yellow component of CMYK data expressed as a percentage
-        "CMYK_K",         // Black component of CMYK data expressed as a percentage
-        "D_RED",          // Red filter density
-        "D_GREEN",        // Green filter density
-        "D_BLUE",         // Blue filter density
-        "D_VIS",          // Visual filter density
-        "D_MAJOR_FILTER", // Major filter d ensity
-        "RGB_R",          // Red component of RGB data
-        "RGB_G",          // Green component of RGB data
-        "RGB_B",          // Blue com ponent of RGB data
-        "SPECTRAL_NM",    // Wavelength of measurement expressed in nanometers
-        "SPECTRAL_PCT",   // Percentage reflectance/transmittance
-        "SPECTRAL_DEC",   // Reflectance/transmittance
-        "XYZ_X",          // X component of tristimulus data
-        "XYZ_Y",          // Y component of tristimulus data
-        "XYZ_Z",          // Z component of tristimulus data
-        "XYY_X"           // x component of chromaticity data
-        "XYY_Y",          // y component of chromaticity data
-        "XYY_CAPY",       // Y component of tristimulus data
-        "LAB_L",          // L* component of Lab data
-        "LAB_A",          // a* component of Lab data
-        "LAB_B",          // b* component of Lab data
-        "LAB_C",          // C*ab component of Lab data
-        "LAB_H",          // hab component of Lab data
-        "LAB_DE",         // CIE dE
-        "LAB_DE_94",      // CIE dE using CIE 94
-        "LAB_DE_CMC",     // dE using CMC
-        "LAB_DE_2000",    // CIE dE using CIE DE 2000
-        "MEAN_DE",        // Mean Delta E (LAB_DE) of samples compared to batch average
-                          // (Used for data files for ANSI IT8.7/1 and IT8.7/2 targets)
-        "STDEV_X",        // Standard deviation of X (tristimulus data)
-        "STDEV_Y",        // Standard deviation of Y (tristimulus data)
-        "STDEV_Z",        // Standard deviation of Z (tristimulus data)
-        "STDEV_L",        // Standard deviation of L*
-        "STDEV_A",        // Standard deviation of a*
-        "STDEV_B",        // Standard deviation of b*
-        "STDEV_DE",       // Standard deviation of CIE dE
-        "CHI_SQD_PAR"};   // The average of the standard deviations of L*, a* and b*. It is
-                          // used to derive an estimate of the chi-squared parameter which is
-                          // recommended as the predictor of the variability of dE
-
-#define NUMPREDEFINEDSAMPLEID (sizeof(PredefinedSampleID)/sizeof(char *))
-
-//Forward declaration of some internal functions
-static void* AllocChunk(cmsIT8* it8, cmsUInt32Number size);
-
-// Checks whatever c is a separator
-static
-cmsBool isseparator(int c)
-{
-    return (c == ' ') || (c == '\t') ; 
-}
-
-// Checks whatever c is a valid identifier char
-static
-cmsBool ismiddle(int c)
-{
-   return (!isseparator(c) && (c != '#') && (c !='\"') && (c != '\'') && (c > 32) && (c < 127));
-}
-
-// Checks whatsever c is a valid identifier middle char.
-static
-cmsBool isidchar(int c)
-{
-   return isalnum(c) || ismiddle(c);
-}
-
-// Checks whatsever c is a valid identifier first char.
-static
-cmsBool isfirstidchar(int c)
-{
-     return !isdigit(c) && ismiddle(c);
-}
-
-// Guess whether the supplied path looks like an absolute path
-static
-cmsBool isabsolutepath(const char *path)
-{
-    char ThreeChars[4];
-
-    if(path == NULL)
-        return FALSE;
-    if (path[0] == 0)
-        return FALSE;
-
-    strncpy(ThreeChars, path, 3);
-    ThreeChars[3] = 0;
-
-    if(ThreeChars[0] == DIR_CHAR)
-        return TRUE;
-
-#ifdef  CMS_IS_WINDOWS_
-    if (isalpha((int) ThreeChars[0]) && ThreeChars[1] == ':')
-        return TRUE;
-#endif
-    return FALSE;
-}
-
-
-// Makes a file path based on a given reference path
-// NOTE: this function doesn't check if the path exists or even if it's legal
-static
-cmsBool BuildAbsolutePath(const char *relPath, const char *basePath, char *buffer, cmsUInt32Number MaxLen)
-{
-    char *tail;
-    cmsUInt32Number len;
-
-    // Already absolute?
-    if (isabsolutepath(relPath)) {
-
-        strncpy(buffer, relPath, MaxLen);
-        buffer[MaxLen-1] = 0;
-        return TRUE;
-    }
-
-    // No, search for last
-    strncpy(buffer, basePath, MaxLen);
-    buffer[MaxLen-1] = 0;
-
-    tail = strrchr(buffer, DIR_CHAR);
-    if (tail == NULL) return FALSE;    // Is not absolute and has no separators??
-
-    len = (cmsUInt32Number) (tail - buffer);
-    if (len >= MaxLen) return FALSE;
-
-    // No need to assure zero terminator over here
-    strncpy(tail + 1, relPath, MaxLen - len);
-
-    return TRUE;
-}
-
-
-// Make sure no exploit is being even tried
-static
-const char* NoMeta(const char* str)
-{
-    if (strchr(str, '%') != NULL)
-        return "**** CORRUPTED FORMAT STRING ***";
-
-    return str;
-}
-
-// Syntax error
-static
-cmsBool SynError(cmsIT8* it8, const char *Txt, ...)
-{
-    char Buffer[256], ErrMsg[1024];
-    va_list args;
-
-    va_start(args, Txt);
-    vsnprintf(Buffer, 255, Txt, args);
-    Buffer[255] = 0;
-    va_end(args);
-
-    snprintf(ErrMsg, 1023, "%s: Line %d, %s", it8->FileStack[it8 ->IncludeSP]->FileName, it8->lineno, Buffer);
-    ErrMsg[1023] = 0;
-    it8->sy = SSYNERROR;
-    cmsSignalError(it8 ->ContextID, cmsERROR_CORRUPTION_DETECTED, "%s", ErrMsg);
-    return FALSE;
-}
-
-// Check if current symbol is same as specified. issue an error else.
-static
-cmsBool Check(cmsIT8* it8, SYMBOL sy, const char* Err)
-{
-        if (it8 -> sy != sy)
-                return SynError(it8, NoMeta(Err));
-        return TRUE;
-}
-
-// Read Next character from stream
-static
-void NextCh(cmsIT8* it8)
-{
-    if (it8 -> FileStack[it8 ->IncludeSP]->Stream) {
-
-        it8 ->ch = fgetc(it8 ->FileStack[it8 ->IncludeSP]->Stream);
-
-        if (feof(it8 -> FileStack[it8 ->IncludeSP]->Stream))  {
-
-            if (it8 ->IncludeSP > 0) {
-
-                fclose(it8 ->FileStack[it8->IncludeSP--]->Stream);
-                it8 -> ch = ' ';                            // Whitespace to be ignored
-
-            } else
-                it8 ->ch = 0;   // EOF
-        }
-    }
-    else {
-        it8->ch = *it8->Source;
-        if (it8->ch) it8->Source++;
-    }
-}
-
-
-// Try to see if current identifier is a keyword, if so return the referred symbol
-static
-SYMBOL BinSrchKey(const char *id)
-{
-    int l = 1;
-    int r = NUMKEYS;
-    int x, res;
-
-    while (r >= l)
-    {
-        x = (l+r)/2;
-        res = cmsstrcasecmp(id, TabKeys[x-1].id);
-        if (res == 0) return TabKeys[x-1].sy;
-        if (res < 0) r = x - 1;
-        else l = x + 1;
-    }
-
-    return SNONE;
-}
-
-
-// 10 ^n
-static
-cmsFloat64Number xpow10(int n)
-{
-    return pow(10, (cmsFloat64Number) n);
-}
-
-
-//  Reads a Real number, tries to follow from integer number
-static
-void ReadReal(cmsIT8* it8, int inum)
-{
-    it8->dnum = (cmsFloat64Number) inum;
-
-    while (isdigit(it8->ch)) {
-
-        it8->dnum = it8->dnum * 10.0 + (it8->ch - '0');
-        NextCh(it8);
-    }
-
-    if (it8->ch == '.') {        // Decimal point
-
-        cmsFloat64Number frac = 0.0;      // fraction
-        int prec = 0;                     // precision
-
-        NextCh(it8);               // Eats dec. point
-
-        while (isdigit(it8->ch)) {
-
-            frac = frac * 10.0 + (it8->ch - '0');
-            prec++;
-            NextCh(it8);
-        }
-
-        it8->dnum = it8->dnum + (frac / xpow10(prec));
-    }
-
-    // Exponent, example 34.00E+20
-    if (toupper(it8->ch) == 'E') {
-
-        int e;
-        int sgn;
-
-        NextCh(it8); sgn = 1;
-
-        if (it8->ch == '-') {
-
-            sgn = -1; NextCh(it8);
-        }
-        else
-            if (it8->ch == '+') {
-
-                sgn = +1;
-                NextCh(it8);
-            }
-
-            e = 0;
-            while (isdigit(it8->ch)) {
-
-                if ((cmsFloat64Number) e * 10L < INT_MAX)
-                    e = e * 10 + (it8->ch - '0');
-
-                NextCh(it8);
-            }
-
-            e = sgn*e;
-            it8 -> dnum = it8 -> dnum * xpow10(e);
-    }
-}
-
-// Parses a float number
-// This can not call directly atof because it uses locale dependant
-// parsing, while CCMX files always use . as decimal separator
-static
-cmsFloat64Number ParseFloatNumber(const char *Buffer)
-{
-    cmsFloat64Number dnum = 0.0;
-    int sign = 1;
-
-    // keep safe
-    if (Buffer == NULL) return 0.0;
-
-    if (*Buffer == '-' || *Buffer == '+') {
-
-         sign = (*Buffer == '-') ? -1 : 1;
-         Buffer++;
-    }
-
-
-    while (*Buffer && isdigit((int) *Buffer)) {
-
-        dnum = dnum * 10.0 + (*Buffer - '0');
-        if (*Buffer) Buffer++;
-    }
-
-    if (*Buffer == '.') {
-
-        cmsFloat64Number frac = 0.0;      // fraction
-        int prec = 0;                     // precission
-
-        if (*Buffer) Buffer++;
-
-        while (*Buffer && isdigit((int) *Buffer)) {
-
-            frac = frac * 10.0 + (*Buffer - '0');
-            prec++;
-            if (*Buffer) Buffer++;
-        }
-
-        dnum = dnum + (frac / xpow10(prec));
-    }
-
-    // Exponent, example 34.00E+20
-    if (*Buffer && toupper(*Buffer) == 'E') {
-
-        int e;
-        int sgn;
-
-        if (*Buffer) Buffer++;
-        sgn = 1;
-
-        if (*Buffer == '-') {
-
-            sgn = -1;
-            if (*Buffer) Buffer++;
-        }
-        else
-            if (*Buffer == '+') {
-
-                sgn = +1;
-                if (*Buffer) Buffer++;
-            }
-
-            e = 0;
-            while (*Buffer && isdigit((int) *Buffer)) {
-
-                if ((cmsFloat64Number) e * 10L < INT_MAX)
-                    e = e * 10 + (*Buffer - '0');
-
-                if (*Buffer) Buffer++;
-            }
-
-            e = sgn*e;
-            dnum = dnum * xpow10(e);
-    }
-
-    return sign * dnum;
-}
-
-
-// Reads next symbol
-static
-void InSymbol(cmsIT8* it8)
-{
-    register char *idptr;
-    register int k;
-    SYMBOL key;
-    int sng;
-    
-    do {
-
-        while (isseparator(it8->ch))
-            NextCh(it8);
-
-        if (isfirstidchar(it8->ch)) {          // Identifier
-
-            k = 0;
-            idptr = it8->id;
-
-            do {
-
-                if (++k < MAXID) *idptr++ = (char) it8->ch;
-
-                NextCh(it8);
-
-            } while (isidchar(it8->ch));
-
-            *idptr = '\0';
-
-
-            key = BinSrchKey(it8->id);
-            if (key == SNONE) it8->sy = SIDENT;
-            else it8->sy = key;
-
-        }
-        else                         // Is a number?
-            if (isdigit(it8->ch) || it8->ch == '.' || it8->ch == '-' || it8->ch == '+')
-            {
-                int sign = 1;
-
-                if (it8->ch == '-') {
-                    sign = -1;
-                    NextCh(it8);
-                }
-
-                it8->inum = 0;
-                it8->sy   = SINUM;
-
-                if (it8->ch == '0') {          // 0xnnnn (Hexa) or 0bnnnn (Binary)
-
-                    NextCh(it8);
-                    if (toupper(it8->ch) == 'X') {
-
-                        int j;
-
-                        NextCh(it8);
-                        while (isxdigit(it8->ch))
-                        {
-                            it8->ch = toupper(it8->ch);
-                            if (it8->ch >= 'A' && it8->ch <= 'F')  j = it8->ch -'A'+10;
-                            else j = it8->ch - '0';
-
-                            if ((long) it8->inum * 16L > (long) INT_MAX)
-                            {
-                                SynError(it8, "Invalid hexadecimal number");
-                                return;
-                            }
-
-                            it8->inum = it8->inum * 16 + j;
-                            NextCh(it8);
-                        }
-                        return;
-                    }
-
-                    if (toupper(it8->ch) == 'B') {  // Binary
-
-                        int j;
-
-                        NextCh(it8);
-                        while (it8->ch == '0' || it8->ch == '1')
-                        {
-                            j = it8->ch - '0';
-
-                            if ((long) it8->inum * 2L > (long) INT_MAX)
-                            {
-                                SynError(it8, "Invalid binary number");
-                                return;
-                            }
-
-                            it8->inum = it8->inum * 2 + j;
-                            NextCh(it8);
-                        }
-                        return;
-                    }
-                }
-
-
-                while (isdigit(it8->ch)) {
-
-                    if ((long) it8->inum * 10L > (long) INT_MAX) {
-                        ReadReal(it8, it8->inum);
-                        it8->sy = SDNUM;
-                        it8->dnum *= sign;
-                        return;
-                    }
-
-                    it8->inum = it8->inum * 10 + (it8->ch - '0');
-                    NextCh(it8);
-                }
-
-                if (it8->ch == '.') {
-
-                    ReadReal(it8, it8->inum);
-                    it8->sy = SDNUM;
-                    it8->dnum *= sign;
-                    return;
-                }
-
-                it8 -> inum *= sign;
-
-                // Special case. Numbers followed by letters are taken as identifiers
-
-                if (isidchar(it8 ->ch)) {
-
-                    if (it8 ->sy == SINUM) {
-
-                        sprintf(it8->id, "%d", it8->inum);
-                    }
-                    else {
-
-                        sprintf(it8->id, it8 ->DoubleFormatter, it8->dnum);
-                    }
-
-                    k = (int) strlen(it8 ->id);
-                    idptr = it8 ->id + k;
-                    do {
-
-                        if (++k < MAXID) *idptr++ = (char) it8->ch;
-
-                        NextCh(it8);
-
-                    } while (isidchar(it8->ch));
-
-                    *idptr = '\0';
-                    it8->sy = SIDENT;
-                }
-                return;
-
-            }
-            else
-                switch ((int) it8->ch) {
-
-        // EOF marker -- ignore it
-        case '\x1a':
-            NextCh(it8);
-            break;
-
-        // Eof stream markers
-        case 0:
-        case -1:
-            it8->sy = SEOF;
-            break;
-
-
-        // Next line
-        case '\r':
-            NextCh(it8);
-            if (it8 ->ch == '\n') 
-                NextCh(it8);
-            it8->sy = SEOLN;
-            it8->lineno++;
-            break;
-
-        case '\n':
-            NextCh(it8);
-            it8->sy = SEOLN;
-            it8->lineno++;
-            break;
-
-        // Comment
-        case '#':
-            NextCh(it8);
-            while (it8->ch && it8->ch != '\n' && it8->ch != '\r')
-                NextCh(it8);
-
-            it8->sy = SCOMMENT;
-            break;
-
-        // String.
-        case '\'':
-        case '\"':
-            idptr = it8->str;
-            sng = it8->ch;
-            k = 0;
-            NextCh(it8);
-
-            while (k < MAXSTR && it8->ch != sng) {
-
-                if (it8->ch == '\n'|| it8->ch == '\r') k = MAXSTR+1;
-                else {
-                    *idptr++ = (char) it8->ch;
-                    NextCh(it8);
-                    k++;
-                }
-            }
-
-            it8->sy = SSTRING;
-            *idptr = '\0';
-            NextCh(it8);
-            break;
-
-
-        default:
-            SynError(it8, "Unrecognized character: 0x%x", it8 ->ch);
-            return;
-            }
-
-    } while (it8->sy == SCOMMENT);
-
-    // Handle the include special token
-
-    if (it8 -> sy == SINCLUDE) {
-
-                FILECTX* FileNest;
-
-                if(it8 -> IncludeSP >= (MAXINCLUDE-1)) {
-
-                    SynError(it8, "Too many recursion levels");
-                    return;
-                }
-
-                InSymbol(it8);
-                if (!Check(it8, SSTRING, "Filename expected")) return;
-
-                FileNest = it8 -> FileStack[it8 -> IncludeSP + 1];
-                if(FileNest == NULL) {
-
-                    FileNest = it8 ->FileStack[it8 -> IncludeSP + 1] = (FILECTX*)AllocChunk(it8, sizeof(FILECTX));
-                    //if(FileNest == NULL)
-                    //  TODO: how to manage out-of-memory conditions?
-                }
-
-                if (BuildAbsolutePath(it8->str,
-                                      it8->FileStack[it8->IncludeSP]->FileName,
-                                      FileNest->FileName, cmsMAX_PATH-1) == FALSE) {
-                    SynError(it8, "File path too long");
-                    return;
-                }
-
-                FileNest->Stream = fopen(FileNest->FileName, "rt");
-                if (FileNest->Stream == NULL) {
-
-                        SynError(it8, "File %s not found", FileNest->FileName);
-                        return;
-                }
-                it8->IncludeSP++;
-
-                it8 ->ch = ' ';
-                InSymbol(it8);
-    }
-
-}
-
-// Checks end of line separator
-static
-cmsBool CheckEOLN(cmsIT8* it8)
-{
-        if (!Check(it8, SEOLN, "Expected separator")) return FALSE;
-        while (it8 -> sy == SEOLN)
-                        InSymbol(it8);
-        return TRUE;
-
-}
-
-// Skip a symbol
-
-static
-void Skip(cmsIT8* it8, SYMBOL sy)
-{
-        if (it8->sy == sy && it8->sy != SEOF)
-                        InSymbol(it8);
-}
-
-
-// Skip multiple EOLN
-static
-void SkipEOLN(cmsIT8* it8)
-{
-    while (it8->sy == SEOLN) {
-             InSymbol(it8);
-    }
-}
-
-
-// Returns a string holding current value
-static
-cmsBool GetVal(cmsIT8* it8, char* Buffer, cmsUInt32Number max, const char* ErrorTitle)
-{
-    switch (it8->sy) {
-
-    case SEOLN:   // Empty value
-                  Buffer[0]=0;
-                  break;
-    case SIDENT:  strncpy(Buffer, it8->id, max);
-                  Buffer[max-1]=0;
-                  break;
-    case SINUM:   snprintf(Buffer, max, "%d", it8 -> inum); break;
-    case SDNUM:   snprintf(Buffer, max, it8->DoubleFormatter, it8 -> dnum); break;
-    case SSTRING: strncpy(Buffer, it8->str, max);
-                  Buffer[max-1] = 0;
-                  break;
-
-
-    default:
-         return SynError(it8, "%s", ErrorTitle);
-    }
-
-    Buffer[max] = 0;
-    return TRUE;
-}
-
-// ---------------------------------------------------------- Table
-
-static
-TABLE* GetTable(cmsIT8* it8)
-{
-   if ((it8 -> nTable >= it8 ->TablesCount)) {
-
-           SynError(it8, "Table %d out of sequence", it8 -> nTable);
-           return it8 -> Tab;
-   }
-
-   return it8 ->Tab + it8 ->nTable;
-}
-
-// ---------------------------------------------------------- Memory management
-
-
-// Frees an allocator and owned memory
-void CMSEXPORT cmsIT8Free(cmsHANDLE hIT8)
-{
-   cmsIT8* it8 = (cmsIT8*) hIT8;
-
-    if (it8 == NULL)
-        return;
-
-    if (it8->MemorySink) {
-
-        OWNEDMEM* p;
-        OWNEDMEM* n;
-
-        for (p = it8->MemorySink; p != NULL; p = n) {
-
-            n = p->Next;
-            if (p->Ptr) _cmsFree(it8 ->ContextID, p->Ptr);
-            _cmsFree(it8 ->ContextID, p);
-        }
-    }
-
-    if (it8->MemoryBlock)
-        _cmsFree(it8 ->ContextID, it8->MemoryBlock);
-
-    _cmsFree(it8 ->ContextID, it8);
-}
-
-
-// Allocates a chunk of data, keep linked list
-static
-void* AllocBigBlock(cmsIT8* it8, cmsUInt32Number size)
-{
-    OWNEDMEM* ptr1;
-    void* ptr = _cmsMallocZero(it8->ContextID, size);
-
-    if (ptr != NULL) {
-
-        ptr1 = (OWNEDMEM*) _cmsMallocZero(it8 ->ContextID, sizeof(OWNEDMEM));
-
-        if (ptr1 == NULL) {
-
-            _cmsFree(it8 ->ContextID, ptr);
-            return NULL;
-        }
-
-        ptr1-> Ptr        = ptr;
-        ptr1-> Next       = it8 -> MemorySink;
-        it8 -> MemorySink = ptr1;
-    }
-
-    return ptr;
-}
-
-
-// Suballocator.
-static
-void* AllocChunk(cmsIT8* it8, cmsUInt32Number size)
-{
-    cmsUInt32Number Free = it8 ->Allocator.BlockSize - it8 ->Allocator.Used;
-    cmsUInt8Number* ptr;
-
-    size = _cmsALIGNMEM(size);
-
-    if (size > Free) {
-
-        if (it8 -> Allocator.BlockSize == 0)
-
-                it8 -> Allocator.BlockSize = 20*1024;
-        else
-                it8 ->Allocator.BlockSize *= 2;
-
-        if (it8 ->Allocator.BlockSize < size)
-                it8 ->Allocator.BlockSize = size;
-
-        it8 ->Allocator.Used = 0;
-        it8 ->Allocator.Block = (cmsUInt8Number*)  AllocBigBlock(it8, it8 ->Allocator.BlockSize);
-    }
-
-    ptr = it8 ->Allocator.Block + it8 ->Allocator.Used;
-    it8 ->Allocator.Used += size;
-
-    return (void*) ptr;
-
-}
-
-
-// Allocates a string
-static
-char *AllocString(cmsIT8* it8, const char* str)
-{
-    cmsUInt32Number Size = (cmsUInt32Number) strlen(str)+1;
-    char *ptr;
-
-
-    ptr = (char *) AllocChunk(it8, Size);
-    if (ptr) strncpy (ptr, str, Size-1);
-
-    return ptr;
-}
-
-// Searches through linked list
-
-static
-cmsBool IsAvailableOnList(KEYVALUE* p, const char* Key, const char* Subkey, KEYVALUE** LastPtr)
-{
-    if (LastPtr) *LastPtr = p;
-
-    for (;  p != NULL; p = p->Next) {
-
-        if (LastPtr) *LastPtr = p;
-
-        if (*Key != '#') { // Comments are ignored
-
-            if (cmsstrcasecmp(Key, p->Keyword) == 0)
-                break;
-        }
-    }
-
-    if (p == NULL)
-        return FALSE;
-
-    if (Subkey == 0)
-        return TRUE;
-
-    for (; p != NULL; p = p->NextSubkey) {
-
-        if (p ->Subkey == NULL) continue;
-
-        if (LastPtr) *LastPtr = p;
-
-        if (cmsstrcasecmp(Subkey, p->Subkey) == 0)
-            return TRUE;
-    }
-
-    return FALSE;
-}
-
-
-
-// Add a property into a linked list
-static
-KEYVALUE* AddToList(cmsIT8* it8, KEYVALUE** Head, const char *Key, const char *Subkey, const char* xValue, WRITEMODE WriteAs)
-{
-    KEYVALUE* p;
-    KEYVALUE* last;
-
-
-    // Check if property is already in list
-
-    if (IsAvailableOnList(*Head, Key, Subkey, &p)) {
-
-        // This may work for editing properties
-
-        //     return SynError(it8, "duplicate key <%s>", Key);
-    }
-    else {
-
-        last = p;
-
-        // Allocate the container
-        p = (KEYVALUE*) AllocChunk(it8, sizeof(KEYVALUE));
-        if (p == NULL)
-        {
-            SynError(it8, "AddToList: out of memory");
-            return NULL;
-        }
-
-        // Store name and value
-        p->Keyword = AllocString(it8, Key);
-        p->Subkey = (Subkey == NULL) ? NULL : AllocString(it8, Subkey);
-
-        // Keep the container in our list
-        if (*Head == NULL) {
-            *Head = p;
-        }
-        else
-        {
-            if (Subkey != NULL && last != NULL) {
-
-                last->NextSubkey = p;
-
-                // If Subkey is not null, then last is the last property with the same key,
-                // but not necessarily is the last property in the list, so we need to move
-                // to the actual list end
-                while (last->Next != NULL)
-                         last = last->Next;
-            }
-
-            if (last != NULL) last->Next = p;
-        }
-
-        p->Next    = NULL;
-        p->NextSubkey = NULL;
-    }
-
-    p->WriteAs = WriteAs;
-
-    if (xValue != NULL) {
-
-        p->Value   = AllocString(it8, xValue);
-    }
-    else {
-        p->Value   = NULL;
-    }
-
-    return p;
-}
-
-static
-KEYVALUE* AddAvailableProperty(cmsIT8* it8, const char* Key, WRITEMODE as)
-{
-    return AddToList(it8, &it8->ValidKeywords, Key, NULL, NULL, as);
-}
-
-
-static
-KEYVALUE* AddAvailableSampleID(cmsIT8* it8, const char* Key)
-{
-    return AddToList(it8, &it8->ValidSampleID, Key, NULL, NULL, WRITE_UNCOOKED);
-}
-
-
-static
-void AllocTable(cmsIT8* it8)
-{
-    TABLE* t;
-
-    t = it8 ->Tab + it8 ->TablesCount;
-
-    t->HeaderList = NULL;
-    t->DataFormat = NULL;
-    t->Data       = NULL;
-
-    it8 ->TablesCount++;
-}
-
-
-cmsInt32Number CMSEXPORT cmsIT8SetTable(cmsHANDLE  IT8, cmsUInt32Number nTable)
-{
-     cmsIT8* it8 = (cmsIT8*) IT8;
-
-     if (nTable >= it8 ->TablesCount) {
-
-         if (nTable == it8 ->TablesCount) {
-
-             AllocTable(it8);
-         }
-         else {
-             SynError(it8, "Table %d is out of sequence", nTable);
-             return -1;
-         }
-     }
-
-     it8 ->nTable = nTable;
-
-     return (cmsInt32Number) nTable;
-}
-
-
-
-// Init an empty container
-cmsHANDLE  CMSEXPORT cmsIT8Alloc(cmsContext ContextID)
-{
-    cmsIT8* it8;
-    cmsUInt32Number i;
-
-    it8 = (cmsIT8*) _cmsMallocZero(ContextID, sizeof(cmsIT8));
-    if (it8 == NULL) return NULL;
-
-    AllocTable(it8);
-
-    it8->MemoryBlock = NULL;
-    it8->MemorySink  = NULL;
-
-    it8 ->nTable = 0;
-
-    it8->ContextID = ContextID;
-    it8->Allocator.Used = 0;
-    it8->Allocator.Block = NULL;
-    it8->Allocator.BlockSize = 0;
-
-    it8->ValidKeywords = NULL;
-    it8->ValidSampleID = NULL;
-
-    it8 -> sy = SNONE;
-    it8 -> ch = ' ';
-    it8 -> Source = NULL;
-    it8 -> inum = 0;
-    it8 -> dnum = 0.0;
-
-    it8->FileStack[0] = (FILECTX*)AllocChunk(it8, sizeof(FILECTX));
-    it8->IncludeSP   = 0;
-    it8 -> lineno = 1;
-
-    strcpy(it8->DoubleFormatter, DEFAULT_DBL_FORMAT);
-    cmsIT8SetSheetType((cmsHANDLE) it8, "CGATS.17");
-
-    // Initialize predefined properties & data
-
-    for (i=0; i < NUMPREDEFINEDPROPS; i++)
-            AddAvailableProperty(it8, PredefinedProperties[i].id, PredefinedProperties[i].as);
-
-    for (i=0; i < NUMPREDEFINEDSAMPLEID; i++)
-            AddAvailableSampleID(it8, PredefinedSampleID[i]);
-
-
-   return (cmsHANDLE) it8;
-}
-
-
-const char* CMSEXPORT cmsIT8GetSheetType(cmsHANDLE hIT8)
-{
-        return GetTable((cmsIT8*) hIT8)->SheetType;
-}
-
-cmsBool CMSEXPORT cmsIT8SetSheetType(cmsHANDLE hIT8, const char* Type)
-{
-        TABLE* t = GetTable((cmsIT8*) hIT8);
-
-        strncpy(t ->SheetType, Type, MAXSTR-1);
-        t ->SheetType[MAXSTR-1] = 0;
-        return TRUE;
-}
-
-cmsBool CMSEXPORT cmsIT8SetComment(cmsHANDLE hIT8, const char* Val)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-
-    if (!Val) return FALSE;
-    if (!*Val) return FALSE;
-
-    return AddToList(it8, &GetTable(it8)->HeaderList, "# ", NULL, Val, WRITE_UNCOOKED) != NULL;
-}
-
-// Sets a property
-cmsBool CMSEXPORT cmsIT8SetPropertyStr(cmsHANDLE hIT8, const char* Key, const char *Val)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-
-    if (!Val) return FALSE;
-    if (!*Val) return FALSE;
-
-    return AddToList(it8, &GetTable(it8)->HeaderList, Key, NULL, Val, WRITE_STRINGIFY) != NULL;
-}
-
-cmsBool CMSEXPORT cmsIT8SetPropertyDbl(cmsHANDLE hIT8, const char* cProp, cmsFloat64Number Val)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-    char Buffer[1024];
-
-    sprintf(Buffer, it8->DoubleFormatter, Val);
-
-    return AddToList(it8, &GetTable(it8)->HeaderList, cProp, NULL, Buffer, WRITE_UNCOOKED) != NULL;
-}
-
-cmsBool CMSEXPORT cmsIT8SetPropertyHex(cmsHANDLE hIT8, const char* cProp, cmsUInt32Number Val)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-    char Buffer[1024];
-
-    sprintf(Buffer, "%u", Val);
-
-    return AddToList(it8, &GetTable(it8)->HeaderList, cProp, NULL, Buffer, WRITE_HEXADECIMAL) != NULL;
-}
-
-cmsBool CMSEXPORT cmsIT8SetPropertyUncooked(cmsHANDLE hIT8, const char* Key, const char* Buffer)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-
-    return AddToList(it8, &GetTable(it8)->HeaderList, Key, NULL, Buffer, WRITE_UNCOOKED) != NULL;
-}
-
-cmsBool CMSEXPORT cmsIT8SetPropertyMulti(cmsHANDLE hIT8, const char* Key, const char* SubKey, const char *Buffer)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-
-    return AddToList(it8, &GetTable(it8)->HeaderList, Key, SubKey, Buffer, WRITE_PAIR) != NULL;
-}
-
-// Gets a property
-const char* CMSEXPORT cmsIT8GetProperty(cmsHANDLE hIT8, const char* Key)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-    KEYVALUE* p;
-
-    if (IsAvailableOnList(GetTable(it8) -> HeaderList, Key, NULL, &p))
-    {
-        return p -> Value;
-    }
-    return NULL;
-}
-
-
-cmsFloat64Number CMSEXPORT cmsIT8GetPropertyDbl(cmsHANDLE hIT8, const char* cProp)
-{
-    const char *v = cmsIT8GetProperty(hIT8, cProp);
-
-    if (v == NULL) return 0.0;
-
-    return ParseFloatNumber(v);
-}
-
-const char* CMSEXPORT cmsIT8GetPropertyMulti(cmsHANDLE hIT8, const char* Key, const char *SubKey)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-    KEYVALUE* p;
-
-    if (IsAvailableOnList(GetTable(it8) -> HeaderList, Key, SubKey, &p)) {
-        return p -> Value;
-    }
-    return NULL;
-}
-
-// ----------------------------------------------------------------- Datasets
-
-
-static
-void AllocateDataFormat(cmsIT8* it8)
-{
-    TABLE* t = GetTable(it8);
-
-    if (t -> DataFormat) return;    // Already allocated
-
-    t -> nSamples  = (int) cmsIT8GetPropertyDbl(it8, "NUMBER_OF_FIELDS");
-
-    if (t -> nSamples <= 0) {
-
-        SynError(it8, "AllocateDataFormat: Unknown NUMBER_OF_FIELDS");
-        t -> nSamples = 10;
-        }
-
-    t -> DataFormat = (char**) AllocChunk (it8, ((cmsUInt32Number) t->nSamples + 1) * sizeof(char *));
-    if (t->DataFormat == NULL) {
-
-        SynError(it8, "AllocateDataFormat: Unable to allocate dataFormat array");
-    }
-
-}
-
-static
-const char *GetDataFormat(cmsIT8* it8, int n)
-{
-    TABLE* t = GetTable(it8);
-
-    if (t->DataFormat)
-        return t->DataFormat[n];
-
-    return NULL;
-}
-
-static
-cmsBool SetDataFormat(cmsIT8* it8, int n, const char *label)
-{
-    TABLE* t = GetTable(it8);
-
-    if (!t->DataFormat)
-        AllocateDataFormat(it8);
-
-    if (n > t -> nSamples) {
-        SynError(it8, "More than NUMBER_OF_FIELDS fields.");
-        return FALSE;
-    }
-
-    if (t->DataFormat) {
-        t->DataFormat[n] = AllocString(it8, label);
-    }
-
-    return TRUE;
-}
-
-
-cmsBool CMSEXPORT cmsIT8SetDataFormat(cmsHANDLE  h, int n, const char *Sample)
-{
-        cmsIT8* it8 = (cmsIT8*) h;
-        return SetDataFormat(it8, n, Sample);
-}
-
-static
-void AllocateDataSet(cmsIT8* it8)
-{
-    TABLE* t = GetTable(it8);
-
-    if (t -> Data) return;    // Already allocated
-
-    t-> nSamples   = atoi(cmsIT8GetProperty(it8, "NUMBER_OF_FIELDS"));
-    t-> nPatches   = atoi(cmsIT8GetProperty(it8, "NUMBER_OF_SETS"));
-
-    t-> Data = (char**)AllocChunk (it8, ((cmsUInt32Number) t->nSamples + 1) * ((cmsUInt32Number) t->nPatches + 1) *sizeof (char*));
-    if (t->Data == NULL) {
-
-        SynError(it8, "AllocateDataSet: Unable to allocate data array");
-    }
-
-}
-
-static
-char* GetData(cmsIT8* it8, int nSet, int nField)
-{
-    TABLE* t = GetTable(it8);
-    int  nSamples   = t -> nSamples;
-    int  nPatches   = t -> nPatches;
-
-    if (nSet >= nPatches || nField >= nSamples)
-        return NULL;
-
-    if (!t->Data) return NULL;
-    return t->Data [nSet * nSamples + nField];
-}
-
-static
-cmsBool SetData(cmsIT8* it8, int nSet, int nField, const char *Val)
-{
-    TABLE* t = GetTable(it8);
-
-    if (!t->Data)
-        AllocateDataSet(it8);
-
-    if (!t->Data) return FALSE;
-
-    if (nSet > t -> nPatches || nSet < 0) {
-
-            return SynError(it8, "Patch %d out of range, there are %d patches", nSet, t -> nPatches);
-    }
-
-    if (nField > t ->nSamples || nField < 0) {
-            return SynError(it8, "Sample %d out of range, there are %d samples", nField, t ->nSamples);
-
-    }
-
-    t->Data [nSet * t -> nSamples + nField] = AllocString(it8, Val);
-    return TRUE;
-}
-
-
-// --------------------------------------------------------------- File I/O
-
-
-// Writes a string to file
-static
-void WriteStr(SAVESTREAM* f, const char *str)
-{
-    cmsUInt32Number len;
-
-    if (str == NULL)
-        str = " ";
-
-    // Length to write
-    len = (cmsUInt32Number) strlen(str);
-    f ->Used += len;
-
-
-    if (f ->stream) {   // Should I write it to a file?
-
-        if (fwrite(str, 1, len, f->stream) != len) {
-            cmsSignalError(0, cmsERROR_WRITE, "Write to file error in CGATS parser");
-            return;
-        }
-
-    }
-    else {  // Or to a memory block?
-
-        if (f ->Base) {   // Am I just counting the bytes?
-
-            if (f ->Used > f ->Max) {
-
-                 cmsSignalError(0, cmsERROR_WRITE, "Write to memory overflows in CGATS parser");
-                 return;
-            }
-
-            memmove(f ->Ptr, str, len);
-            f->Ptr += len;
-        }
-
-    }
-}
-
-
-// Write formatted
-
-static
-void Writef(SAVESTREAM* f, const char* frm, ...)
-{
-    char Buffer[4096];
-    va_list args;
-
-    va_start(args, frm);
-    vsnprintf(Buffer, 4095, frm, args);
-    Buffer[4095] = 0;
-    WriteStr(f, Buffer);
-    va_end(args);
-
-}
-
-// Writes full header
-static
-void WriteHeader(cmsIT8* it8, SAVESTREAM* fp)
-{
-    KEYVALUE* p;
-    TABLE* t = GetTable(it8);
-
-    // Writes the type
-    WriteStr(fp, t->SheetType);
-    WriteStr(fp, "\n");
-
-    for (p = t->HeaderList; (p != NULL); p = p->Next)
-    {
-        if (*p ->Keyword == '#') {
-
-            char* Pt;
-
-            WriteStr(fp, "#\n# ");
-            for (Pt = p ->Value; *Pt; Pt++) {
-
-
-                Writef(fp, "%c", *Pt);
-
-                if (*Pt == '\n') {
-                    WriteStr(fp, "# ");
-                }
-            }
-
-            WriteStr(fp, "\n#\n");
-            continue;
-        }
-
-
-        if (!IsAvailableOnList(it8-> ValidKeywords, p->Keyword, NULL, NULL)) {
-
-#ifdef CMS_STRICT_CGATS
-            WriteStr(fp, "KEYWORD\t\"");
-            WriteStr(fp, p->Keyword);
-            WriteStr(fp, "\"\n");
-#endif
-
-            AddAvailableProperty(it8, p->Keyword, WRITE_UNCOOKED);
-        }
-
-        WriteStr(fp, p->Keyword);
-        if (p->Value) {
-
-            switch (p ->WriteAs) {
-
-            case WRITE_UNCOOKED:
-                    Writef(fp, "\t%s", p ->Value);
-                    break;
-
-            case WRITE_STRINGIFY:
-                    Writef(fp, "\t\"%s\"", p->Value );
-                    break;
-
-            case WRITE_HEXADECIMAL:
-                    Writef(fp, "\t0x%X", atoi(p ->Value));
-                    break;
-
-            case WRITE_BINARY:
-                    Writef(fp, "\t0x%B", atoi(p ->Value));
-                    break;
-
-            case WRITE_PAIR:
-                    Writef(fp, "\t\"%s,%s\"", p->Subkey, p->Value);
-                    break;
-
-            default: SynError(it8, "Unknown write mode %d", p ->WriteAs);
-                     return;
-            }
-        }
-
-        WriteStr (fp, "\n");
-    }
-
-}
-
-
-// Writes the data format
-static
-void WriteDataFormat(SAVESTREAM* fp, cmsIT8* it8)
-{
-    int i, nSamples;
-    TABLE* t = GetTable(it8);
-
-    if (!t -> DataFormat) return;
-
-       WriteStr(fp, "BEGIN_DATA_FORMAT\n");
-       WriteStr(fp, " ");
-       nSamples = atoi(cmsIT8GetProperty(it8, "NUMBER_OF_FIELDS"));
-
-       for (i = 0; i < nSamples; i++) {
-
-              WriteStr(fp, t->DataFormat[i]);
-              WriteStr(fp, ((i == (nSamples-1)) ? "\n" : "\t"));
-          }
-
-       WriteStr (fp, "END_DATA_FORMAT\n");
-}
-
-
-// Writes data array
-static
-void WriteData(SAVESTREAM* fp, cmsIT8* it8)
-{
-       int  i, j;
-       TABLE* t = GetTable(it8);
-
-       if (!t->Data) return;
-
-       WriteStr (fp, "BEGIN_DATA\n");
-
-       t->nPatches = atoi(cmsIT8GetProperty(it8, "NUMBER_OF_SETS"));
-
-       for (i = 0; i < t-> nPatches; i++) {
-
-              WriteStr(fp, " ");
-
-              for (j = 0; j < t->nSamples; j++) {
-
-                     char *ptr = t->Data[i*t->nSamples+j];
-
-                     if (ptr == NULL) WriteStr(fp, "\"\"");
-                     else {
-                         // If value contains whitespace, enclose within quote
-
-                         if (strchr(ptr, ' ') != NULL) {
-
-                             WriteStr(fp, "\"");
-                             WriteStr(fp, ptr);
-                             WriteStr(fp, "\"");
-                         }
-                         else
-                            WriteStr(fp, ptr);
-                     }
-
-                     WriteStr(fp, ((j == (t->nSamples-1)) ? "\n" : "\t"));
-              }
-       }
-       WriteStr (fp, "END_DATA\n");
-}
-
-
-
-// Saves whole file
-cmsBool CMSEXPORT cmsIT8SaveToFile(cmsHANDLE hIT8, const char* cFileName)
-{
-    SAVESTREAM sd;
-    cmsUInt32Number i;
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-
-    memset(&sd, 0, sizeof(sd));
-
-    sd.stream = fopen(cFileName, "wt");
-    if (!sd.stream) return FALSE;
-
-    for (i=0; i < it8 ->TablesCount; i++) {
-
-            cmsIT8SetTable(hIT8, i);
-            WriteHeader(it8, &sd);
-            WriteDataFormat(&sd, it8);
-            WriteData(&sd, it8);
-    }
-
-    if (fclose(sd.stream) != 0) return FALSE;
-
-    return TRUE;
-}
-
-
-// Saves to memory
-cmsBool CMSEXPORT cmsIT8SaveToMem(cmsHANDLE hIT8, void *MemPtr, cmsUInt32Number* BytesNeeded)
-{
-    SAVESTREAM sd;
-    cmsUInt32Number i;
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-
-    memset(&sd, 0, sizeof(sd));
-
-    sd.stream = NULL;
-    sd.Base   = (cmsUInt8Number*)  MemPtr;
-    sd.Ptr    = sd.Base;
-
-    sd.Used = 0;
-
-    if (sd.Base)
-        sd.Max  = *BytesNeeded;     // Write to memory?
-    else
-        sd.Max  = 0;                // Just counting the needed bytes
-
-    for (i=0; i < it8 ->TablesCount; i++) {
-
-        cmsIT8SetTable(hIT8, i);
-        WriteHeader(it8, &sd);
-        WriteDataFormat(&sd, it8);
-        WriteData(&sd, it8);
-    }
-
-    sd.Used++;  // The \0 at the very end
-
-    if (sd.Base)
-        *sd.Ptr = 0;
-
-    *BytesNeeded = sd.Used;
-
-    return TRUE;
-}
-
-
-// -------------------------------------------------------------- Higer level parsing
-
-static
-cmsBool DataFormatSection(cmsIT8* it8)
-{
-    int iField = 0;
-    TABLE* t = GetTable(it8);
-
-    InSymbol(it8);   // Eats "BEGIN_DATA_FORMAT"
-    CheckEOLN(it8);
-
-    while (it8->sy != SEND_DATA_FORMAT &&
-        it8->sy != SEOLN &&
-        it8->sy != SEOF &&
-        it8->sy != SSYNERROR)  {
-
-            if (it8->sy != SIDENT) {
-
-                return SynError(it8, "Sample type expected");
-            }
-
-            if (!SetDataFormat(it8, iField, it8->id)) return FALSE;
-            iField++;
-
-            InSymbol(it8);
-            SkipEOLN(it8);
-       }
-
-       SkipEOLN(it8);
-       Skip(it8, SEND_DATA_FORMAT);
-       SkipEOLN(it8);
-
-       if (iField != t ->nSamples) {
-           SynError(it8, "Count mismatch. NUMBER_OF_FIELDS was %d, found %d\n", t ->nSamples, iField);
-
-
-       }
-
-       return TRUE;
-}
-
-
-
-static
-cmsBool DataSection (cmsIT8* it8)
-{
-    int  iField = 0;
-    int  iSet   = 0;
-    char Buffer[256];
-    TABLE* t = GetTable(it8);
-
-    InSymbol(it8);   // Eats "BEGIN_DATA"
-    CheckEOLN(it8);
-
-    if (!t->Data)
-        AllocateDataSet(it8);
-
-    while (it8->sy != SEND_DATA && it8->sy != SEOF)
-    {
-        if (iField >= t -> nSamples) {
-            iField = 0;
-            iSet++;
-
-        }
-
-        if (it8->sy != SEND_DATA && it8->sy != SEOF) {
-
-            if (!GetVal(it8, Buffer, 255, "Sample data expected"))
-                return FALSE;
-
-            if (!SetData(it8, iSet, iField, Buffer))
-                return FALSE;
-
-            iField++;
-
-            InSymbol(it8);
-            SkipEOLN(it8);
-        }
-    }
-
-    SkipEOLN(it8);
-    Skip(it8, SEND_DATA);
-    SkipEOLN(it8);
-
-    // Check for data completion.
-
-    if ((iSet+1) != t -> nPatches)
-        return SynError(it8, "Count mismatch. NUMBER_OF_SETS was %d, found %d\n", t ->nPatches, iSet+1);
-
-    return TRUE;
-}
-
-
-
-
-static
-cmsBool HeaderSection(cmsIT8* it8)
-{
-    char VarName[MAXID];
-    char Buffer[MAXSTR];
-    KEYVALUE* Key;
-
-        while (it8->sy != SEOF &&
-               it8->sy != SSYNERROR &&
-               it8->sy != SBEGIN_DATA_FORMAT &&
-               it8->sy != SBEGIN_DATA) {
-
-
-        switch (it8 -> sy) {
-
-        case SKEYWORD:
-                InSymbol(it8);
-                if (!GetVal(it8, Buffer, MAXSTR-1, "Keyword expected")) return FALSE;
-                if (!AddAvailableProperty(it8, Buffer, WRITE_UNCOOKED)) return FALSE;
-                InSymbol(it8);
-                break;
-
-
-        case SDATA_FORMAT_ID:
-                InSymbol(it8);
-                if (!GetVal(it8, Buffer, MAXSTR-1, "Keyword expected")) return FALSE;
-                if (!AddAvailableSampleID(it8, Buffer)) return FALSE;
-                InSymbol(it8);
-                break;
-
-
-        case SIDENT:
-                strncpy(VarName, it8->id, MAXID-1);
-                VarName[MAXID-1] = 0;
-
-                if (!IsAvailableOnList(it8-> ValidKeywords, VarName, NULL, &Key)) {
-
-#ifdef CMS_STRICT_CGATS
-                 return SynError(it8, "Undefined keyword '%s'", VarName);
-#else
-                    Key = AddAvailableProperty(it8, VarName, WRITE_UNCOOKED);
-                    if (Key == NULL) return FALSE;
-#endif
-                }
-
-                InSymbol(it8);
-                if (!GetVal(it8, Buffer, MAXSTR-1, "Property data expected")) return FALSE;
-
-                if(Key->WriteAs != WRITE_PAIR) {
-                    AddToList(it8, &GetTable(it8)->HeaderList, VarName, NULL, Buffer,
-                                (it8->sy == SSTRING) ? WRITE_STRINGIFY : WRITE_UNCOOKED);
-                }
-                else {
-                    const char *Subkey;
-                    char *Nextkey;
-                    if (it8->sy != SSTRING)
-                        return SynError(it8, "Invalid value '%s' for property '%s'.", Buffer, VarName);
-
-                    // chop the string as a list of "subkey, value" pairs, using ';' as a separator
-                    for (Subkey = Buffer; Subkey != NULL; Subkey = Nextkey)
-                    {
-                        char *Value, *temp;
-
-                        //  identify token pair boundary
-                        Nextkey = (char*) strchr(Subkey, ';');
-                        if(Nextkey)
-                            *Nextkey++ = '\0';
-
-                        // for each pair, split the subkey and the value
-                        Value = (char*) strrchr(Subkey, ',');
-                        if(Value == NULL)
-                            return SynError(it8, "Invalid value for property '%s'.", VarName);
-
-                        // gobble the spaces before the coma, and the coma itself
-                        temp = Value++;
-                        do *temp-- = '\0'; while(temp >= Subkey && *temp == ' ');
-
-                        // gobble any space at the right
-                        temp = Value + strlen(Value) - 1;
-                        while(*temp == ' ') *temp-- = '\0';
-
-                        // trim the strings from the left
-                        Subkey += strspn(Subkey, " ");
-                        Value += strspn(Value, " ");
-
-                        if(Subkey[0] == 0 || Value[0] == 0)
-                            return SynError(it8, "Invalid value for property '%s'.", VarName);
-                        AddToList(it8, &GetTable(it8)->HeaderList, VarName, Subkey, Value, WRITE_PAIR);
-                    }
-                }
-
-                InSymbol(it8);
-                break;
-
-
-        case SEOLN: break;
-
-        default:
-                return SynError(it8, "expected keyword or identifier");
-        }
-
-    SkipEOLN(it8);
-    }
-
-    return TRUE;
-
-}
-
-
-static
-void ReadType(cmsIT8* it8, char* SheetTypePtr)
-{
-    // First line is a very special case.
-
-    while (isseparator(it8->ch))
-            NextCh(it8);
-
-    while (it8->ch != '\r' && it8 ->ch != '\n' && it8->ch != '\t' && it8 -> ch != -1) {
-
-        *SheetTypePtr++= (char) it8 ->ch;
-        NextCh(it8);
-    }
-
-    *SheetTypePtr = 0;
-}
-
-
-static
-cmsBool ParseIT8(cmsIT8* it8, cmsBool nosheet)
-{
-    char* SheetTypePtr = it8 ->Tab[0].SheetType;
-
-    if (nosheet == 0) {
-        ReadType(it8, SheetTypePtr);
-    }
-
-    InSymbol(it8);
-
-    SkipEOLN(it8);
-
-    while (it8-> sy != SEOF &&
-           it8-> sy != SSYNERROR) {
-
-            switch (it8 -> sy) {
-
-            case SBEGIN_DATA_FORMAT:
-                    if (!DataFormatSection(it8)) return FALSE;
-                    break;
-
-            case SBEGIN_DATA:
-
-                    if (!DataSection(it8)) return FALSE;
-
-                    if (it8 -> sy != SEOF) {
-
-                            AllocTable(it8);
-                            it8 ->nTable = it8 ->TablesCount - 1;
-
-                            // Read sheet type if present. We only support identifier and string.
-                            // <ident> <eoln> is a type string
-                            // anything else, is not a type string
-                            if (nosheet == 0) {
-
-                                if (it8 ->sy == SIDENT) {
-
-                                    // May be a type sheet or may be a prop value statement. We cannot use insymbol in
-                                    // this special case...
-                                     while (isseparator(it8->ch))
-                                         NextCh(it8);
-
-                                     // If a newline is found, then this is a type string
-                                    if (it8 ->ch == '\n' || it8->ch == '\r') {
-
-                                         cmsIT8SetSheetType(it8, it8 ->id);
-                                         InSymbol(it8);
-                                    }
-                                    else
-                                    {
-                                        // It is not. Just continue
-                                        cmsIT8SetSheetType(it8, "");
-                                    }
-                                }
-                                else
-                                    // Validate quoted strings
-                                    if (it8 ->sy == SSTRING) {
-                                        cmsIT8SetSheetType(it8, it8 ->str);
-                                        InSymbol(it8);
-                                    }
-                           }
-
-                    }
-                    break;
-
-            case SEOLN:
-                    SkipEOLN(it8);
-                    break;
-
-            default:
-                    if (!HeaderSection(it8)) return FALSE;
-           }
-
-    }
-
-    return (it8 -> sy != SSYNERROR);
-}
-
-
-
-// Init usefull pointers
-
-static
-void CookPointers(cmsIT8* it8)
-{
-    int idField, i;
-    char* Fld;
-    cmsUInt32Number j;
-    cmsUInt32Number nOldTable = it8 ->nTable;
-
-    for (j=0; j < it8 ->TablesCount; j++) {
-
-    TABLE* t = it8 ->Tab + j;
-
-    t -> SampleID = 0;
-    it8 ->nTable = j;
-
-    for (idField = 0; idField < t -> nSamples; idField++)
-    {
-        if (t ->DataFormat == NULL){
-            SynError(it8, "Undefined DATA_FORMAT");
-            return;
-        }
-
-        Fld = t->DataFormat[idField];
-        if (!Fld) continue;
-
-
-        if (cmsstrcasecmp(Fld, "SAMPLE_ID") == 0) {
-
-            t -> SampleID = idField;
-
-            for (i=0; i < t -> nPatches; i++) {
-
-                char *Data = GetData(it8, i, idField);
-                if (Data) {
-                    char Buffer[256];
-
-                    strncpy(Buffer, Data, 255);
-                    Buffer[255] = 0;
-
-                    if (strlen(Buffer) <= strlen(Data))
-                        strcpy(Data, Buffer);
-                    else
-                        SetData(it8, i, idField, Buffer);
-
-                }
-            }
-
-        }
-
-        // "LABEL" is an extension. It keeps references to forward tables
-
-        if ((cmsstrcasecmp(Fld, "LABEL") == 0) || Fld[0] == '$' ) {
-
-                    // Search for table references...
-                    for (i=0; i < t -> nPatches; i++) {
-
-                            char *Label = GetData(it8, i, idField);
-
-                            if (Label) {
-
-                                cmsUInt32Number k;
-
-                                // This is the label, search for a table containing
-                                // this property
-
-                                for (k=0; k < it8 ->TablesCount; k++) {
-
-                                    TABLE* Table = it8 ->Tab + k;
-                                    KEYVALUE* p;
-
-                                    if (IsAvailableOnList(Table->HeaderList, Label, NULL, &p)) {
-
-                                        // Available, keep type and table
-                                        char Buffer[256];
-
-                                        char *Type  = p ->Value;
-                                        int  nTable = (int) k;
-
-                                        snprintf(Buffer, 255, "%s %d %s", Label, nTable, Type );
-
-                                        SetData(it8, i, idField, Buffer);
-                                    }
-                                }
-
-
-                            }
-
-                    }
-
-
-        }
-
-    }
-    }
-
-    it8 ->nTable = nOldTable;
-}
-
-// Try to infere if the file is a CGATS/IT8 file at all. Read first line
-// that should be something like some printable characters plus a \n
-// returns 0 if this is not like a CGATS, or an integer otherwise. This integer is the number of words in first line?
-static
-int IsMyBlock(cmsUInt8Number* Buffer, int n)
-{
-    int words = 1, space = 0, quot = 0;
-    int i;
-
-    if (n < 10) return 0;   // Too small
-
-    if (n > 132)
-        n = 132;
-
-    for (i = 1; i < n; i++) {
-
-        switch(Buffer[i])
-        {
-        case '\n':
-        case '\r':
-            return ((quot == 1) || (words > 2)) ? 0 : words;
-        case '\t':
-        case ' ':
-            if(!quot && !space)
-                space = 1;
-            break;
-        case '\"':
-            quot = !quot;
-            break;
-        default:
-            if (Buffer[i] < 32) return 0;
-            if (Buffer[i] > 127) return 0;
-            words += space;
-            space = 0;
-            break;
-        }
-    }
-
-    return 0;
-}
-
-
-static
-cmsBool IsMyFile(const char* FileName)
-{
-   FILE *fp;
-   cmsUInt32Number Size;
-   cmsUInt8Number Ptr[133];
-
-   fp = fopen(FileName, "rt");
-   if (!fp) {
-       cmsSignalError(0, cmsERROR_FILE, "File '%s' not found", FileName);
-       return FALSE;
-   }
-
-   Size = (cmsUInt32Number) fread(Ptr, 1, 132, fp);
-
-   if (fclose(fp) != 0)
-       return FALSE;
-
-   Ptr[Size] = '\0';
-
-   return IsMyBlock(Ptr, Size);
-}
-
-// ---------------------------------------------------------- Exported routines
-
-
-cmsHANDLE  CMSEXPORT cmsIT8LoadFromMem(cmsContext ContextID, void *Ptr, cmsUInt32Number len)
-{
-    cmsHANDLE hIT8;
-    cmsIT8*  it8;
-    int type;
-
-    _cmsAssert(Ptr != NULL);
-    _cmsAssert(len != 0);
-
-    type = IsMyBlock((cmsUInt8Number*)Ptr, len);
-    if (type == 0) return NULL;
-
-    hIT8 = cmsIT8Alloc(ContextID);
-    if (!hIT8) return NULL;
-
-    it8 = (cmsIT8*) hIT8;
-    it8 ->MemoryBlock = (char*) _cmsMalloc(ContextID, len + 1);
-
-    strncpy(it8 ->MemoryBlock, (const char*) Ptr, len);
-    it8 ->MemoryBlock[len] = 0;
-
-    strncpy(it8->FileStack[0]->FileName, "", cmsMAX_PATH-1);
-    it8-> Source = it8 -> MemoryBlock;
-
-    if (!ParseIT8(it8, type-1)) {
-
-        cmsIT8Free(hIT8);
-        return FALSE;
-    }
-
-    CookPointers(it8);
-    it8 ->nTable = 0;
-
-    _cmsFree(ContextID, it8->MemoryBlock);
-    it8 -> MemoryBlock = NULL;
-
-    return hIT8;
-
-
-}
-
-
-cmsHANDLE  CMSEXPORT cmsIT8LoadFromFile(cmsContext ContextID, const char* cFileName)
-{
-
-     cmsHANDLE hIT8;
-     cmsIT8*  it8;
-     int type;
-
-     _cmsAssert(cFileName != NULL);
-
-     type = IsMyFile(cFileName);
-     if (type == 0) return NULL;
-
-     hIT8 = cmsIT8Alloc(ContextID);
-     it8 = (cmsIT8*) hIT8;
-     if (!hIT8) return NULL;
-
-
-     it8 ->FileStack[0]->Stream = fopen(cFileName, "rt");
-
-     if (!it8 ->FileStack[0]->Stream) {
-         cmsIT8Free(hIT8);
-         return NULL;
-     }
-
-
-    strncpy(it8->FileStack[0]->FileName, cFileName, cmsMAX_PATH-1);
-    it8->FileStack[0]->FileName[cmsMAX_PATH-1] = 0;
-
-    if (!ParseIT8(it8, type-1)) {
-
-            fclose(it8 ->FileStack[0]->Stream);
-            cmsIT8Free(hIT8);
-            return NULL;
-    }
-
-    CookPointers(it8);
-    it8 ->nTable = 0;
-
-    if (fclose(it8 ->FileStack[0]->Stream)!= 0) {
-            cmsIT8Free(hIT8);
-            return NULL;
-    }
-
-    return hIT8;
-
-}
-
-int CMSEXPORT cmsIT8EnumDataFormat(cmsHANDLE hIT8, char ***SampleNames)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-    TABLE* t;
-
-    _cmsAssert(hIT8 != NULL);
-
-    t = GetTable(it8);
-
-    if (SampleNames)
-        *SampleNames = t -> DataFormat;
-    return t -> nSamples;
-}
-
-
-cmsUInt32Number CMSEXPORT cmsIT8EnumProperties(cmsHANDLE hIT8, char ***PropertyNames)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-    KEYVALUE* p;
-    cmsUInt32Number n;
-    char **Props;
-    TABLE* t;
-
-    _cmsAssert(hIT8 != NULL);
-
-    t = GetTable(it8);
-
-    // Pass#1 - count properties
-
-    n = 0;
-    for (p = t -> HeaderList;  p != NULL; p = p->Next) {
-        n++;
-    }
-
-
-    Props = (char **) AllocChunk(it8, sizeof(char *) * n);
-
-    // Pass#2 - Fill pointers
-    n = 0;
-    for (p = t -> HeaderList;  p != NULL; p = p->Next) {
-        Props[n++] = p -> Keyword;
-    }
-
-    *PropertyNames = Props;
-    return n;
-}
-
-cmsUInt32Number CMSEXPORT cmsIT8EnumPropertyMulti(cmsHANDLE hIT8, const char* cProp, const char ***SubpropertyNames)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-    KEYVALUE *p, *tmp;
-    cmsUInt32Number n;
-    const char **Props;
-    TABLE* t;
-
-    _cmsAssert(hIT8 != NULL);
-
-
-    t = GetTable(it8);
-
-    if(!IsAvailableOnList(t->HeaderList, cProp, NULL, &p)) {
-        *SubpropertyNames = 0;
-        return 0;
-    }
-
-    // Pass#1 - count properties
-
-    n = 0;
-    for (tmp = p;  tmp != NULL; tmp = tmp->NextSubkey) {
-        if(tmp->Subkey != NULL)
-            n++;
-    }
-
-
-    Props = (const char **) AllocChunk(it8, sizeof(char *) * n);
-
-    // Pass#2 - Fill pointers
-    n = 0;
-    for (tmp = p;  tmp != NULL; tmp = tmp->NextSubkey) {
-        if(tmp->Subkey != NULL)
-            Props[n++] = p ->Subkey;
-    }
-
-    *SubpropertyNames = Props;
-    return n;
-}
-
-static
-int LocatePatch(cmsIT8* it8, const char* cPatch)
-{
-    int i;
-    const char *data;
-    TABLE* t = GetTable(it8);
-
-    for (i=0; i < t-> nPatches; i++) {
-
-        data = GetData(it8, i, t->SampleID);
-
-        if (data != NULL) {
-
-                if (cmsstrcasecmp(data, cPatch) == 0)
-                        return i;
-                }
-        }
-
-        // SynError(it8, "Couldn't find patch '%s'\n", cPatch);
-        return -1;
-}
-
-
-static
-int LocateEmptyPatch(cmsIT8* it8)
-{
-    int i;
-    const char *data;
-    TABLE* t = GetTable(it8);
-
-    for (i=0; i < t-> nPatches; i++) {
-
-        data = GetData(it8, i, t->SampleID);
-
-        if (data == NULL)
-            return i;
-
-    }
-
-    return -1;
-}
-
-static
-int LocateSample(cmsIT8* it8, const char* cSample)
-{
-    int i;
-    const char *fld;
-    TABLE* t = GetTable(it8);
-
-    for (i=0; i < t->nSamples; i++) {
-
-        fld = GetDataFormat(it8, i);
-        if (cmsstrcasecmp(fld, cSample) == 0)
-            return i;
-    }
-
-    return -1;
-
-}
-
-
-int CMSEXPORT cmsIT8FindDataFormat(cmsHANDLE hIT8, const char* cSample)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-
-    _cmsAssert(hIT8 != NULL);
-
-    return LocateSample(it8, cSample);
-}
-
-
-
-const char* CMSEXPORT cmsIT8GetDataRowCol(cmsHANDLE hIT8, int row, int col)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-
-    _cmsAssert(hIT8 != NULL);
-
-    return GetData(it8, row, col);
-}
-
-
-cmsFloat64Number CMSEXPORT cmsIT8GetDataRowColDbl(cmsHANDLE hIT8, int row, int col)
-{
-    const char* Buffer;
-
-    Buffer = cmsIT8GetDataRowCol(hIT8, row, col);
-
-    if (Buffer == NULL) return 0.0;
-
-    return ParseFloatNumber(Buffer);
-}
-
-
-cmsBool CMSEXPORT cmsIT8SetDataRowCol(cmsHANDLE hIT8, int row, int col, const char* Val)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-
-    _cmsAssert(hIT8 != NULL);
-
-    return SetData(it8, row, col, Val);
-}
-
-
-cmsBool CMSEXPORT cmsIT8SetDataRowColDbl(cmsHANDLE hIT8, int row, int col, cmsFloat64Number Val)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-    char Buff[256];
-
-    _cmsAssert(hIT8 != NULL);
-
-    sprintf(Buff, it8->DoubleFormatter, Val);
-
-    return SetData(it8, row, col, Buff);
-}
-
-
-
-const char* CMSEXPORT cmsIT8GetData(cmsHANDLE hIT8, const char* cPatch, const char* cSample)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-    int iField, iSet;
-
-    _cmsAssert(hIT8 != NULL);
-
-    iField = LocateSample(it8, cSample);
-    if (iField < 0) {
-        return NULL;
-    }
-
-    iSet = LocatePatch(it8, cPatch);
-    if (iSet < 0) {
-            return NULL;
-    }
-
-    return GetData(it8, iSet, iField);
-}
-
-
-cmsFloat64Number CMSEXPORT cmsIT8GetDataDbl(cmsHANDLE  it8, const char* cPatch, const char* cSample)
-{
-    const char* Buffer;
-
-    Buffer = cmsIT8GetData(it8, cPatch, cSample);
-
-    return ParseFloatNumber(Buffer);
-}
-
-
-
-cmsBool CMSEXPORT cmsIT8SetData(cmsHANDLE hIT8, const char* cPatch, const char* cSample, const char *Val)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-    int iField, iSet;
-    TABLE* t;
-
-    _cmsAssert(hIT8 != NULL);
-
-    t = GetTable(it8);
-
-    iField = LocateSample(it8, cSample);
-
-    if (iField < 0)
-        return FALSE;
-
-    if (t-> nPatches == 0) {
-
-        AllocateDataFormat(it8);
-        AllocateDataSet(it8);
-        CookPointers(it8);
-    }
-
-    if (cmsstrcasecmp(cSample, "SAMPLE_ID") == 0) {
-
-        iSet   = LocateEmptyPatch(it8);
-        if (iSet < 0) {
-            return SynError(it8, "Couldn't add more patches '%s'\n", cPatch);
-        }
-
-        iField = t -> SampleID;
-    }
-    else {
-        iSet = LocatePatch(it8, cPatch);
-        if (iSet < 0) {
-            return FALSE;
-        }
-    }
-
-    return SetData(it8, iSet, iField, Val);
-}
-
-
-cmsBool CMSEXPORT cmsIT8SetDataDbl(cmsHANDLE hIT8, const char* cPatch,
-                                   const char* cSample,
-                                   cmsFloat64Number Val)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-    char Buff[256];
-
-    _cmsAssert(hIT8 != NULL);
-
-    snprintf(Buff, 255, it8->DoubleFormatter, Val);
-    return cmsIT8SetData(hIT8, cPatch, cSample, Buff);
-}
-
-// Buffer should get MAXSTR at least
-
-const char* CMSEXPORT cmsIT8GetPatchName(cmsHANDLE hIT8, int nPatch, char* buffer)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-    TABLE* t;
-    char* Data;
-
-    _cmsAssert(hIT8 != NULL);
-
-    t = GetTable(it8);
-    Data = GetData(it8, nPatch, t->SampleID);
-
-    if (!Data) return NULL;
-    if (!buffer) return Data;
-
-    strncpy(buffer, Data, MAXSTR-1);
-    buffer[MAXSTR-1] = 0;
-    return buffer;
-}
-
-int CMSEXPORT cmsIT8GetPatchByName(cmsHANDLE hIT8, const char *cPatch)
-{
-    _cmsAssert(hIT8 != NULL);
-
-    return LocatePatch((cmsIT8*)hIT8, cPatch);
-}
-
-cmsUInt32Number CMSEXPORT cmsIT8TableCount(cmsHANDLE hIT8)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-
-    _cmsAssert(hIT8 != NULL);
-
-    return it8 ->TablesCount;
-}
-
-// This handles the "LABEL" extension.
-// Label, nTable, Type
-
-int CMSEXPORT cmsIT8SetTableByLabel(cmsHANDLE hIT8, const char* cSet, const char* cField, const char* ExpectedType)
-{
-    const char* cLabelFld;
-    char Type[256], Label[256];
-    int nTable;
-
-    _cmsAssert(hIT8 != NULL);
-
-    if (cField != NULL && *cField == 0)
-            cField = "LABEL";
-
-    if (cField == NULL)
-            cField = "LABEL";
-
-    cLabelFld = cmsIT8GetData(hIT8, cSet, cField);
-    if (!cLabelFld) return -1;
-
-    if (sscanf(cLabelFld, "%255s %d %255s", Label, &nTable, Type) != 3)
-            return -1;
-
-    if (ExpectedType != NULL && *ExpectedType == 0)
-        ExpectedType = NULL;
-
-    if (ExpectedType) {
-
-        if (cmsstrcasecmp(Type, ExpectedType) != 0) return -1;
-    }
-
-    return cmsIT8SetTable(hIT8, nTable);
-}
-
-
-cmsBool CMSEXPORT cmsIT8SetIndexColumn(cmsHANDLE hIT8, const char* cSample)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-    int pos;
-
-    _cmsAssert(hIT8 != NULL);
-
-    pos = LocateSample(it8, cSample);
-    if(pos == -1)
-        return FALSE;
-
-    it8->Tab[it8->nTable].SampleID = pos;
-    return TRUE;
-}
-
-
-void CMSEXPORT cmsIT8DefineDblFormat(cmsHANDLE hIT8, const char* Formatter)
-{
-    cmsIT8* it8 = (cmsIT8*) hIT8;
-
-    _cmsAssert(hIT8 != NULL);
-
-    if (Formatter == NULL)
-        strcpy(it8->DoubleFormatter, DEFAULT_DBL_FORMAT);
-    else
-        strncpy(it8->DoubleFormatter, Formatter, sizeof(it8->DoubleFormatter));
-
-    it8 ->DoubleFormatter[sizeof(it8 ->DoubleFormatter)-1] = 0;
-}
diff --git a/core/src/fxcodec/lcms2/lcms2-2.6/src/cmscnvrt.c b/core/src/fxcodec/lcms2/lcms2-2.6/src/cmscnvrt.c
deleted file mode 100644 (file)
index 1a93e83..0000000
+++ /dev/null
@@ -1,1142 +0,0 @@
-//---------------------------------------------------------------------------------
-//
-//  Little Color Management System
-//  Copyright (c) 1998-2012 Marti Maria Saguer
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the "Software"),
-// to deal in the Software without restriction, including without limitation
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,
-// and/or sell copies of the Software, and to permit persons to whom the Software
-// is furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
-// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-//---------------------------------------------------------------------------------
-//
-
-#include "lcms2_internal.h"
-
-
-// Link several profiles to obtain a single LUT modelling the whole color transform. Intents, Black point
-// compensation and Adaptation parameters may vary across profiles. BPC and Adaptation refers to the PCS
-// after the profile. I.e, BPC[0] refers to connexion between profile(0) and profile(1)
-cmsPipeline* _cmsLinkProfiles(cmsContext     ContextID,
-                              cmsUInt32Number nProfiles,
-                              cmsUInt32Number Intents[],
-                              cmsHPROFILE     hProfiles[],
-                              cmsBool         BPC[],
-                              cmsFloat64Number AdaptationStates[],
-                              cmsUInt32Number dwFlags);
-
-//---------------------------------------------------------------------------------
-
-// This is the default routine for ICC-style intents. A user may decide to override it by using a plugin.
-// Supported intents are perceptual, relative colorimetric, saturation and ICC-absolute colorimetric
-static
-cmsPipeline* DefaultICCintents(cmsContext     ContextID,
-                               cmsUInt32Number nProfiles,
-                               cmsUInt32Number Intents[],
-                               cmsHPROFILE     hProfiles[],
-                               cmsBool         BPC[],
-                               cmsFloat64Number AdaptationStates[],
-                               cmsUInt32Number dwFlags);
-
-//---------------------------------------------------------------------------------
-
-// This is the entry for black-preserving K-only intents, which are non-ICC. Last profile have to be a output profile
-// to do the trick (no devicelinks allowed at that position)
-static
-cmsPipeline*  BlackPreservingKOnlyIntents(cmsContext     ContextID,
-                                          cmsUInt32Number nProfiles,
-                                          cmsUInt32Number Intents[],
-                                          cmsHPROFILE     hProfiles[],
-                                          cmsBool         BPC[],
-                                          cmsFloat64Number AdaptationStates[],
-                                          cmsUInt32Number dwFlags);
-
-//---------------------------------------------------------------------------------
-
-// This is the entry for black-plane preserving, which are non-ICC. Again, Last profile have to be a output profile
-// to do the trick (no devicelinks allowed at that position)
-static
-cmsPipeline*  BlackPreservingKPlaneIntents(cmsContext     ContextID,
-                                           cmsUInt32Number nProfiles,
-                                           cmsUInt32Number Intents[],
-                                           cmsHPROFILE     hProfiles[],
-                                           cmsBool         BPC[],
-                                           cmsFloat64Number AdaptationStates[],
-                                           cmsUInt32Number dwFlags);
-
-//---------------------------------------------------------------------------------
-
-
-// This is a structure holding implementations for all supported intents.
-typedef struct _cms_intents_list {
-
-    cmsUInt32Number Intent;
-    char            Description[256];
-    cmsIntentFn     Link;
-    struct _cms_intents_list*  Next;
-
-} cmsIntentsList;
-
-
-// Built-in intents
-static cmsIntentsList DefaultIntents[] = {
-
-    { INTENT_PERCEPTUAL,                            "Perceptual",                                   DefaultICCintents,            &DefaultIntents[1] },
-    { INTENT_RELATIVE_COLORIMETRIC,                 "Relative colorimetric",                        DefaultICCintents,            &DefaultIntents[2] },
-    { INTENT_SATURATION,                            "Saturation",                                   DefaultICCintents,            &DefaultIntents[3] },
-    { INTENT_ABSOLUTE_COLORIMETRIC,                 "Absolute colorimetric",                        DefaultICCintents,            &DefaultIntents[4] },
-    { INTENT_PRESERVE_K_ONLY_PERCEPTUAL,            "Perceptual preserving black ink",              BlackPreservingKOnlyIntents,  &DefaultIntents[5] },
-    { INTENT_PRESERVE_K_ONLY_RELATIVE_COLORIMETRIC, "Relative colorimetric preserving black ink",   BlackPreservingKOnlyIntents,  &DefaultIntents[6] },
-    { INTENT_PRESERVE_K_ONLY_SATURATION,            "Saturation preserving black ink",              BlackPreservingKOnlyIntents,  &DefaultIntents[7] },
-    { INTENT_PRESERVE_K_PLANE_PERCEPTUAL,           "Perceptual preserving black plane",            BlackPreservingKPlaneIntents, &DefaultIntents[8] },
-    { INTENT_PRESERVE_K_PLANE_RELATIVE_COLORIMETRIC,"Relative colorimetric preserving black plane", BlackPreservingKPlaneIntents, &DefaultIntents[9] },
-    { INTENT_PRESERVE_K_PLANE_SATURATION,           "Saturation preserving black plane",            BlackPreservingKPlaneIntents, NULL }
-};
-
-
-// A pointer to the begining of the list
-_cmsIntentsPluginChunkType _cmsIntentsPluginChunk = { NULL };
-
-// Duplicates the zone of memory used by the plug-in in the new context
-static
-void DupPluginIntentsList(struct _cmsContext_struct* ctx, 
-                                               const struct _cmsContext_struct* src)
-{
-   _cmsIntentsPluginChunkType newHead = { NULL };
-   cmsIntentsList*  entry;
-   cmsIntentsList*  Anterior = NULL;
-   _cmsIntentsPluginChunkType* head = (_cmsIntentsPluginChunkType*) src->chunks[IntentPlugin];
-
-    // Walk the list copying all nodes
-   for (entry = head->Intents;
-        entry != NULL;
-        entry = entry ->Next) {
-
-            cmsIntentsList *newEntry = ( cmsIntentsList *) _cmsSubAllocDup(ctx ->MemPool, entry, sizeof(cmsIntentsList));
-   
-            if (newEntry == NULL) 
-                return;
-
-            // We want to keep the linked list order, so this is a little bit tricky
-            newEntry -> Next = NULL;
-            if (Anterior)
-                Anterior -> Next = newEntry;
-     
-            Anterior = newEntry;
-
-            if (newHead.Intents == NULL)
-                newHead.Intents = newEntry;
-    }
-
-  ctx ->chunks[IntentPlugin] = _cmsSubAllocDup(ctx->MemPool, &newHead, sizeof(_cmsIntentsPluginChunkType));
-}
-
-void  _cmsAllocIntentsPluginChunk(struct _cmsContext_struct* ctx, 
-                                         const struct _cmsContext_struct* src)
-{
-    if (src != NULL) {
-
-        // Copy all linked list
-        DupPluginIntentsList(ctx, src);
-    }
-    else {
-        static _cmsIntentsPluginChunkType IntentsPluginChunkType = { NULL };
-        ctx ->chunks[IntentPlugin] = _cmsSubAllocDup(ctx ->MemPool, &IntentsPluginChunkType, sizeof(_cmsIntentsPluginChunkType));
-    }
-}
-
-
-// Search the list for a suitable intent. Returns NULL if not found
-static
-cmsIntentsList* SearchIntent(cmsContext ContextID, cmsUInt32Number Intent)
-{
-    _cmsIntentsPluginChunkType* ctx = ( _cmsIntentsPluginChunkType*) _cmsContextGetClientChunk(ContextID, IntentPlugin);
-    cmsIntentsList* pt;
-
-    for (pt = ctx -> Intents; pt != NULL; pt = pt -> Next)
-        if (pt ->Intent == Intent) return pt;
-
-    for (pt = DefaultIntents; pt != NULL; pt = pt -> Next)
-        if (pt ->Intent == Intent) return pt;
-
-    return NULL;
-}
-
-// Black point compensation. Implemented as a linear scaling in XYZ. Black points
-// should come relative to the white point. Fills an matrix/offset element m
-// which is organized as a 4x4 matrix.
-static
-void ComputeBlackPointCompensation(const cmsCIEXYZ* BlackPointIn,
-                                   const cmsCIEXYZ* BlackPointOut,
-                                   cmsMAT3* m, cmsVEC3* off)
-{
-  cmsFloat64Number ax, ay, az, bx, by, bz, tx, ty, tz;
-
-   // Now we need to compute a matrix plus an offset m and of such of
-   // [m]*bpin + off = bpout
-   // [m]*D50  + off = D50
-   //
-   // This is a linear scaling in the form ax+b, where
-   // a = (bpout - D50) / (bpin - D50)
-   // b = - D50* (bpout - bpin) / (bpin - D50)
-
-   tx = BlackPointIn->X - cmsD50_XYZ()->X;
-   ty = BlackPointIn->Y - cmsD50_XYZ()->Y;
-   tz = BlackPointIn->Z - cmsD50_XYZ()->Z;
-
-   ax = (BlackPointOut->X - cmsD50_XYZ()->X) / tx;
-   ay = (BlackPointOut->Y - cmsD50_XYZ()->Y) / ty;
-   az = (BlackPointOut->Z - cmsD50_XYZ()->Z) / tz;
-
-   bx = - cmsD50_XYZ()-> X * (BlackPointOut->X - BlackPointIn->X) / tx;
-   by = - cmsD50_XYZ()-> Y * (BlackPointOut->Y - BlackPointIn->Y) / ty;
-   bz = - cmsD50_XYZ()-> Z * (BlackPointOut->Z - BlackPointIn->Z) / tz;
-
-   _cmsVEC3init(&m ->v[0], ax, 0,  0);
-   _cmsVEC3init(&m ->v[1], 0, ay,  0);
-   _cmsVEC3init(&m ->v[2], 0,  0,  az);
-   _cmsVEC3init(off, bx, by, bz);
-
-}
-
-
-// Approximate a blackbody illuminant based on CHAD information
-static
-cmsFloat64Number CHAD2Temp(const cmsMAT3* Chad)
-{
-    // Convert D50 across inverse CHAD to get the absolute white point
-    cmsVEC3 d, s;
-    cmsCIEXYZ Dest;
-    cmsCIExyY DestChromaticity;
-    cmsFloat64Number TempK;
-    cmsMAT3 m1, m2;
-
-    m1 = *Chad;
-    if (!_cmsMAT3inverse(&m1, &m2)) return FALSE;
-
-    s.n[VX] = cmsD50_XYZ() -> X;
-    s.n[VY] = cmsD50_XYZ() -> Y;
-    s.n[VZ] = cmsD50_XYZ() -> Z;
-
-    _cmsMAT3eval(&d, &m2, &s);
-
-    Dest.X = d.n[VX];
-    Dest.Y = d.n[VY];
-    Dest.Z = d.n[VZ];
-
-    cmsXYZ2xyY(&DestChromaticity, &Dest);
-
-    if (!cmsTempFromWhitePoint(&TempK, &DestChromaticity))
-        return -1.0;
-
-    return TempK;
-}
-
-// Compute a CHAD based on a given temperature
-static
-    void Temp2CHAD(cmsMAT3* Chad, cmsFloat64Number Temp)
-{
-    cmsCIEXYZ White;
-    cmsCIExyY ChromaticityOfWhite;
-
-    cmsWhitePointFromTemp(&ChromaticityOfWhite, Temp);
-    cmsxyY2XYZ(&White, &ChromaticityOfWhite);
-    _cmsAdaptationMatrix(Chad, NULL, &White, cmsD50_XYZ());
-}
-
-// Join scalings to obtain relative input to absolute and then to relative output.
-// Result is stored in a 3x3 matrix
-static
-cmsBool  ComputeAbsoluteIntent(cmsFloat64Number AdaptationState,
-                               const cmsCIEXYZ* WhitePointIn,
-                               const cmsMAT3* ChromaticAdaptationMatrixIn,
-                               const cmsCIEXYZ* WhitePointOut,
-                               const cmsMAT3* ChromaticAdaptationMatrixOut,
-                               cmsMAT3* m)
-{
-    cmsMAT3 Scale, m1, m2, m3, m4;
-
-    // Adaptation state
-    if (AdaptationState == 1.0) {
-
-        // Observer is fully adapted. Keep chromatic adaptation.
-        // That is the standard V4 behaviour
-        _cmsVEC3init(&m->v[0], WhitePointIn->X / WhitePointOut->X, 0, 0);
-        _cmsVEC3init(&m->v[1], 0, WhitePointIn->Y / WhitePointOut->Y, 0);
-        _cmsVEC3init(&m->v[2], 0, 0, WhitePointIn->Z / WhitePointOut->Z);
-
-    }
-    else  {
-
-        // Incomplete adaptation. This is an advanced feature.
-        _cmsVEC3init(&Scale.v[0], WhitePointIn->X / WhitePointOut->X, 0, 0);
-        _cmsVEC3init(&Scale.v[1], 0,  WhitePointIn->Y / WhitePointOut->Y, 0);
-        _cmsVEC3init(&Scale.v[2], 0, 0,  WhitePointIn->Z / WhitePointOut->Z);
-
-
-        if (AdaptationState == 0.0) {
-
-            m1 = *ChromaticAdaptationMatrixOut;
-            _cmsMAT3per(&m2, &m1, &Scale);
-            // m2 holds CHAD from output white to D50 times abs. col. scaling
-
-            // Observer is not adapted, undo the chromatic adaptation
-            _cmsMAT3per(m, &m2, ChromaticAdaptationMatrixOut);
-
-            m3 = *ChromaticAdaptationMatrixIn;
-            if (!_cmsMAT3inverse(&m3, &m4)) return FALSE;
-            _cmsMAT3per(m, &m2, &m4);
-
-        } else {
-
-            cmsMAT3 MixedCHAD;
-            cmsFloat64Number TempSrc, TempDest, Temp;
-
-            m1 = *ChromaticAdaptationMatrixIn;
-            if (!_cmsMAT3inverse(&m1, &m2)) return FALSE;
-            _cmsMAT3per(&m3, &m2, &Scale);
-            // m3 holds CHAD from input white to D50 times abs. col. scaling
-
-            TempSrc  = CHAD2Temp(ChromaticAdaptationMatrixIn);
-            TempDest = CHAD2Temp(ChromaticAdaptationMatrixOut);
-
-            if (TempSrc < 0.0 || TempDest < 0.0) return FALSE; // Something went wrong
-
-            if (_cmsMAT3isIdentity(&Scale) && fabs(TempSrc - TempDest) < 0.01) {
-
-                _cmsMAT3identity(m);
-                return TRUE;
-            }
-
-            Temp = (1.0 - AdaptationState) * TempDest + AdaptationState * TempSrc;
-
-            // Get a CHAD from whatever output temperature to D50. This replaces output CHAD
-            Temp2CHAD(&MixedCHAD, Temp);
-
-            _cmsMAT3per(m, &m3, &MixedCHAD);
-        }
-
-    }
-    return TRUE;
-
-}
-
-// Just to see if m matrix should be applied
-static
-cmsBool IsEmptyLayer(cmsMAT3* m, cmsVEC3* off)
-{
-    cmsFloat64Number diff = 0;
-    cmsMAT3 Ident;
-    int i;
-
-    if (m == NULL && off == NULL) return TRUE;  // NULL is allowed as an empty layer
-    if (m == NULL && off != NULL) return FALSE; // This is an internal error
-
-    _cmsMAT3identity(&Ident);
-
-    for (i=0; i < 3*3; i++)
-        diff += fabs(((cmsFloat64Number*)m)[i] - ((cmsFloat64Number*)&Ident)[i]);
-
-    for (i=0; i < 3; i++)
-        diff += fabs(((cmsFloat64Number*)off)[i]);
-
-
-    return (diff < 0.002);
-}
-
-
-// Compute the conversion layer
-static
-cmsBool ComputeConversion(int i, cmsHPROFILE hProfiles[],
-                                 cmsUInt32Number Intent,
-                                 cmsBool BPC,
-                                 cmsFloat64Number AdaptationState,
-                                 cmsMAT3* m, cmsVEC3* off)
-{
-
-    int k;
-
-    // m  and off are set to identity and this is detected latter on
-    _cmsMAT3identity(m);
-    _cmsVEC3init(off, 0, 0, 0);
-
-    // If intent is abs. colorimetric,
-    if (Intent == INTENT_ABSOLUTE_COLORIMETRIC) {
-
-        cmsCIEXYZ WhitePointIn, WhitePointOut;
-        cmsMAT3 ChromaticAdaptationMatrixIn, ChromaticAdaptationMatrixOut;
-
-        _cmsReadMediaWhitePoint(&WhitePointIn,  hProfiles[i-1]);
-        _cmsReadCHAD(&ChromaticAdaptationMatrixIn, hProfiles[i-1]);
-
-        _cmsReadMediaWhitePoint(&WhitePointOut,  hProfiles[i]);
-        _cmsReadCHAD(&ChromaticAdaptationMatrixOut, hProfiles[i]);
-
-        if (!ComputeAbsoluteIntent(AdaptationState,
-                                  &WhitePointIn,  &ChromaticAdaptationMatrixIn,
-                                  &WhitePointOut, &ChromaticAdaptationMatrixOut, m)) return FALSE;
-
-    }
-    else {
-        // Rest of intents may apply BPC.
-
-        if (BPC) {
-
-            cmsCIEXYZ BlackPointIn, BlackPointOut;
-
-            cmsDetectBlackPoint(&BlackPointIn,  hProfiles[i-1], Intent, 0);
-            cmsDetectDestinationBlackPoint(&BlackPointOut, hProfiles[i], Intent, 0);
-
-            // If black points are equal, then do nothing
-            if (BlackPointIn.X != BlackPointOut.X ||
-                BlackPointIn.Y != BlackPointOut.Y ||
-                BlackPointIn.Z != BlackPointOut.Z)
-                    ComputeBlackPointCompensation(&BlackPointIn, &BlackPointOut, m, off);
-        }
-    }
-
-    // Offset should be adjusted because the encoding. We encode XYZ normalized to 0..1.0,
-    // to do that, we divide by MAX_ENCODEABLE_XZY. The conversion stage goes XYZ -> XYZ so
-    // we have first to convert from encoded to XYZ and then convert back to encoded.
-    // y = Mx + Off
-    // x = x'c
-    // y = M x'c + Off
-    // y = y'c; y' = y / c
-    // y' = (Mx'c + Off) /c = Mx' + (Off / c)
-
-    for (k=0; k < 3; k++) {
-        off ->n[k] /= MAX_ENCODEABLE_XYZ;
-    }
-
-    return TRUE;
-}
-
-
-// Add a conversion stage if needed. If a matrix/offset m is given, it applies to XYZ space
-static
-cmsBool AddConversion(cmsPipeline* Result, cmsColorSpaceSignature InPCS, cmsColorSpaceSignature OutPCS, cmsMAT3* m, cmsVEC3* off)
-{
-    cmsFloat64Number* m_as_dbl = (cmsFloat64Number*) m;
-    cmsFloat64Number* off_as_dbl = (cmsFloat64Number*) off;
-
-    // Handle PCS mismatches. A specialized stage is added to the LUT in such case
-    switch (InPCS) {
-
-    case cmsSigXYZData: // Input profile operates in XYZ
-
-        switch (OutPCS) {
-
-        case cmsSigXYZData:  // XYZ -> XYZ
-            if (!IsEmptyLayer(m, off) &&
-                !cmsPipelineInsertStage(Result, cmsAT_END, cmsStageAllocMatrix(Result ->ContextID, 3, 3, m_as_dbl, off_as_dbl)))
-                return FALSE;
-            break;
-
-        case cmsSigLabData:  // XYZ -> Lab
-            if (!IsEmptyLayer(m, off) &&
-                !cmsPipelineInsertStage(Result, cmsAT_END, cmsStageAllocMatrix(Result ->ContextID, 3, 3, m_as_dbl, off_as_dbl)))
-                return FALSE;
-            if (!cmsPipelineInsertStage(Result, cmsAT_END, _cmsStageAllocXYZ2Lab(Result ->ContextID)))
-                return FALSE;
-            break;
-
-        default:
-            return FALSE;   // Colorspace mismatch
-        }
-        break;
-
-    case cmsSigLabData: // Input profile operates in Lab
-
-        switch (OutPCS) {
-
-        case cmsSigXYZData:  // Lab -> XYZ
-
-            if (!cmsPipelineInsertStage(Result, cmsAT_END, _cmsStageAllocLab2XYZ(Result ->ContextID)))
-                return FALSE;
-            if (!IsEmptyLayer(m, off) &&
-                !cmsPipelineInsertStage(Result, cmsAT_END, cmsStageAllocMatrix(Result ->ContextID, 3, 3, m_as_dbl, off_as_dbl)))
-                return FALSE;
-            break;
-
-        case cmsSigLabData:  // Lab -> Lab
-
-            if (!IsEmptyLayer(m, off)) {
-                if (!cmsPipelineInsertStage(Result, cmsAT_END, _cmsStageAllocLab2XYZ(Result ->ContextID)) ||
-                    !cmsPipelineInsertStage(Result, cmsAT_END, cmsStageAllocMatrix(Result ->ContextID, 3, 3, m_as_dbl, off_as_dbl)) ||
-                    !cmsPipelineInsertStage(Result, cmsAT_END, _cmsStageAllocXYZ2Lab(Result ->ContextID)))
-                    return FALSE;
-            }
-            break;
-
-        default:
-            return FALSE;  // Mismatch
-        }
-        break;
-
-        // On colorspaces other than PCS, check for same space
-    default:
-        if (InPCS != OutPCS) return FALSE;
-        break;
-    }
-
-    return TRUE;
-}
-
-
-// Is a given space compatible with another?
-static
-cmsBool ColorSpaceIsCompatible(cmsColorSpaceSignature a, cmsColorSpaceSignature b)
-{
-    // If they are same, they are compatible.
-    if (a == b) return TRUE;
-
-    // Check for MCH4 substitution of CMYK
-    if ((a == cmsSig4colorData) && (b == cmsSigCmykData)) return TRUE;
-    if ((a == cmsSigCmykData) && (b == cmsSig4colorData)) return TRUE;
-
-    // Check for XYZ/Lab. Those spaces are interchangeable as they can be computed one from other.
-    if ((a == cmsSigXYZData) && (b == cmsSigLabData)) return TRUE;
-    if ((a == cmsSigLabData) && (b == cmsSigXYZData)) return TRUE;
-
-    return FALSE;
-}
-
-
-// Default handler for ICC-style intents
-static
-cmsPipeline* DefaultICCintents(cmsContext       ContextID,
-                               cmsUInt32Number  nProfiles,
-                               cmsUInt32Number  TheIntents[],
-                               cmsHPROFILE      hProfiles[],
-                               cmsBool          BPC[],
-                               cmsFloat64Number AdaptationStates[],
-                               cmsUInt32Number  dwFlags)
-{
-    cmsPipeline* Lut = NULL;
-    cmsPipeline* Result;
-    cmsHPROFILE hProfile;
-    cmsMAT3 m;
-    cmsVEC3 off;
-    cmsColorSpaceSignature ColorSpaceIn, ColorSpaceOut, CurrentColorSpace;
-    cmsProfileClassSignature ClassSig;
-    cmsUInt32Number  i, Intent;
-
-    // For safety
-    if (nProfiles == 0) return NULL;
-
-    // Allocate an empty LUT for holding the result. 0 as channel count means 'undefined'
-    Result = cmsPipelineAlloc(ContextID, 0, 0);
-    if (Result == NULL) return NULL;
-
-    CurrentColorSpace = cmsGetColorSpace(hProfiles[0]);
-
-    for (i=0; i < nProfiles; i++) {
-
-        cmsBool  lIsDeviceLink, lIsInput;
-
-        hProfile      = hProfiles[i];
-        ClassSig      = cmsGetDeviceClass(hProfile);
-        lIsDeviceLink = (ClassSig == cmsSigLinkClass || ClassSig == cmsSigAbstractClass );
-
-        // First profile is used as input unless devicelink or abstract
-        if ((i == 0) && !lIsDeviceLink) {
-            lIsInput = TRUE;
-        }
-        else {
-          // Else use profile in the input direction if current space is not PCS
-        lIsInput      = (CurrentColorSpace != cmsSigXYZData) &&
-                        (CurrentColorSpace != cmsSigLabData);
-        }
-
-        Intent        = TheIntents[i];
-
-        if (lIsInput || lIsDeviceLink) {
-
-            ColorSpaceIn    = cmsGetColorSpace(hProfile);
-            ColorSpaceOut   = cmsGetPCS(hProfile);
-        }
-        else {
-
-            ColorSpaceIn    = cmsGetPCS(hProfile);
-            ColorSpaceOut   = cmsGetColorSpace(hProfile);
-        }
-
-        if (!ColorSpaceIsCompatible(ColorSpaceIn, CurrentColorSpace)) {
-
-            cmsSignalError(ContextID, cmsERROR_COLORSPACE_CHECK, "ColorSpace mismatch");
-            goto Error;
-        }
-
-        // If devicelink is found, then no custom intent is allowed and we can
-        // read the LUT to be applied. Settings don't apply here.
-        if (lIsDeviceLink || ((ClassSig == cmsSigNamedColorClass) && (nProfiles == 1))) {
-
-            // Get the involved LUT from the profile
-            Lut = _cmsReadDevicelinkLUT(hProfile, Intent);
-            if (Lut == NULL) goto Error;
-
-            // What about abstract profiles?
-             if (ClassSig == cmsSigAbstractClass && i > 0) {
-                if (!ComputeConversion(i, hProfiles, Intent, BPC[i], AdaptationStates[i], &m, &off)) goto Error;
-             }
-             else {
-                _cmsMAT3identity(&m);
-                _cmsVEC3init(&off, 0, 0, 0);
-             }
-
-
-            if (!AddConversion(Result, CurrentColorSpace, ColorSpaceIn, &m, &off)) goto Error;
-
-        }
-        else {
-
-            if (lIsInput) {
-                // Input direction means non-pcs connection, so proceed like devicelinks
-                Lut = _cmsReadInputLUT(hProfile, Intent);
-                if (Lut == NULL) goto Error;
-            }
-            else {
-
-                // Output direction means PCS connection. Intent may apply here
-                Lut = _cmsReadOutputLUT(hProfile, Intent);
-                if (Lut == NULL) goto Error;
-
-
-                if (!ComputeConversion(i, hProfiles, Intent, BPC[i], AdaptationStates[i], &m, &off)) goto Error;
-                if (!AddConversion(Result, CurrentColorSpace, ColorSpaceIn, &m, &off)) goto Error;
-
-            }
-        }
-
-        // Concatenate to the output LUT
-        if (!cmsPipelineCat(Result, Lut))
-            goto Error;
-
-        cmsPipelineFree(Lut);
-        Lut = NULL;
-
-        // Update current space
-        CurrentColorSpace = ColorSpaceOut;
-    }
-
-    return Result;
-
-Error:
-
-    if (Lut != NULL) cmsPipelineFree(Lut);
-    if (Result != NULL) cmsPipelineFree(Result);
-    return NULL;
-
-    cmsUNUSED_PARAMETER(dwFlags);
-}
-
-
-// Wrapper for DLL calling convention
-cmsPipeline*  CMSEXPORT _cmsDefaultICCintents(cmsContext     ContextID,
-                                              cmsUInt32Number nProfiles,
-                                              cmsUInt32Number TheIntents[],
-                                              cmsHPROFILE     hProfiles[],
-                                              cmsBool         BPC[],
-                                              cmsFloat64Number AdaptationStates[],
-                                              cmsUInt32Number dwFlags)
-{
-    return DefaultICCintents(ContextID, nProfiles, TheIntents, hProfiles, BPC, AdaptationStates, dwFlags);
-}
-
-// Black preserving intents ---------------------------------------------------------------------------------------------
-
-// Translate black-preserving intents to ICC ones
-static
-int TranslateNonICCIntents(int Intent)
-{
-    switch (Intent) {
-        case INTENT_PRESERVE_K_ONLY_PERCEPTUAL:
-        case INTENT_PRESERVE_K_PLANE_PERCEPTUAL:
-            return INTENT_PERCEPTUAL;
-
-        case INTENT_PRESERVE_K_ONLY_RELATIVE_COLORIMETRIC:
-        case INTENT_PRESERVE_K_PLANE_RELATIVE_COLORIMETRIC:
-            return INTENT_RELATIVE_COLORIMETRIC;
-
-        case INTENT_PRESERVE_K_ONLY_SATURATION:
-        case INTENT_PRESERVE_K_PLANE_SATURATION:
-            return INTENT_SATURATION;
-
-        default: return Intent;
-    }
-}
-
-// Sampler for Black-only preserving CMYK->CMYK transforms
-
-typedef struct {
-    cmsPipeline*    cmyk2cmyk;      // The original transform
-    cmsToneCurve*   KTone;          // Black-to-black tone curve
-
-} GrayOnlyParams;
-
-
-// Preserve black only if that is the only ink used
-static
-int BlackPreservingGrayOnlySampler(register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void* Cargo)
-{
-    GrayOnlyParams* bp = (GrayOnlyParams*) Cargo;
-
-    // If going across black only, keep black only
-    if (In[0] == 0 && In[1] == 0 && In[2] == 0) {
-
-        // TAC does not apply because it is black ink!
-        Out[0] = Out[1] = Out[2] = 0;
-        Out[3] = cmsEvalToneCurve16(bp->KTone, In[3]);
-        return TRUE;
-    }
-
-    // Keep normal transform for other colors
-    bp ->cmyk2cmyk ->Eval16Fn(In, Out, bp ->cmyk2cmyk->Data);
-    return TRUE;
-}
-
-// This is the entry for black-preserving K-only intents, which are non-ICC
-static
-cmsPipeline*  BlackPreservingKOnlyIntents(cmsContext     ContextID,
-                                          cmsUInt32Number nProfiles,
-                                          cmsUInt32Number TheIntents[],
-                                          cmsHPROFILE     hProfiles[],
-                                          cmsBool         BPC[],
-                                          cmsFloat64Number AdaptationStates[],
-                                          cmsUInt32Number dwFlags)
-{
-    GrayOnlyParams  bp;
-    cmsPipeline*    Result;
-    cmsUInt32Number ICCIntents[256];
-    cmsStage*         CLUT;
-    cmsUInt32Number i, nGridPoints;
-
-
-    // Sanity check
-    if (nProfiles < 1 || nProfiles > 255) return NULL;
-
-    // Translate black-preserving intents to ICC ones
-    for (i=0; i < nProfiles; i++)
-        ICCIntents[i] = TranslateNonICCIntents(TheIntents[i]);
-
-    // Check for non-cmyk profiles
-    if (cmsGetColorSpace(hProfiles[0]) != cmsSigCmykData ||
-        cmsGetColorSpace(hProfiles[nProfiles-1]) != cmsSigCmykData)
-           return DefaultICCintents(ContextID, nProfiles, ICCIntents, hProfiles, BPC, AdaptationStates, dwFlags);
-
-    memset(&bp, 0, sizeof(bp));
-
-    // Allocate an empty LUT for holding the result
-    Result = cmsPipelineAlloc(ContextID, 4, 4);
-    if (Result == NULL) return NULL;
-
-    // Create a LUT holding normal ICC transform
-    bp.cmyk2cmyk = DefaultICCintents(ContextID,
-        nProfiles,
-        ICCIntents,
-        hProfiles,
-        BPC,
-        AdaptationStates,
-        dwFlags);
-
-    if (bp.cmyk2cmyk == NULL) goto Error;
-
-    // Now, compute the tone curve
-    bp.KTone = _cmsBuildKToneCurve(ContextID,
-        4096,
-        nProfiles,
-        ICCIntents,
-        hProfiles,
-        BPC,
-        AdaptationStates,
-        dwFlags);
-
-    if (bp.KTone == NULL) goto Error;
-
-
-    // How many gridpoints are we going to use?
-    nGridPoints = _cmsReasonableGridpointsByColorspace(cmsSigCmykData, dwFlags);
-
-    // Create the CLUT. 16 bits
-    CLUT = cmsStageAllocCLut16bit(ContextID, nGridPoints, 4, 4, NULL);
-    if (CLUT == NULL) goto Error;
-
-    // This is the one and only MPE in this LUT
-    if (!cmsPipelineInsertStage(Result, cmsAT_BEGIN, CLUT))
-        goto Error;
-
-    // Sample it. We cannot afford pre/post linearization this time.
-    if (!cmsStageSampleCLut16bit(CLUT, BlackPreservingGrayOnlySampler, (void*) &bp, 0))
-        goto Error;
-
-    // Get rid of xform and tone curve
-    cmsPipelineFree(bp.cmyk2cmyk);
-    cmsFreeToneCurve(bp.KTone);
-
-    return Result;
-
-Error:
-
-    if (bp.cmyk2cmyk != NULL) cmsPipelineFree(bp.cmyk2cmyk);
-    if (bp.KTone != NULL)  cmsFreeToneCurve(bp.KTone);
-    if (Result != NULL) cmsPipelineFree(Result);
-    return NULL;
-
-}
-
-// K Plane-preserving CMYK to CMYK ------------------------------------------------------------------------------------
-
-typedef struct {
-
-    cmsPipeline*     cmyk2cmyk;     // The original transform
-    cmsHTRANSFORM    hProofOutput;  // Output CMYK to Lab (last profile)
-    cmsHTRANSFORM    cmyk2Lab;      // The input chain
-    cmsToneCurve*    KTone;         // Black-to-black tone curve
-    cmsPipeline*     LabK2cmyk;     // The output profile
-    cmsFloat64Number MaxError;
-
-    cmsHTRANSFORM    hRoundTrip;
-    cmsFloat64Number MaxTAC;
-
-
-} PreserveKPlaneParams;
-
-
-// The CLUT will be stored at 16 bits, but calculations are performed at cmsFloat32Number precision
-static
-int BlackPreservingSampler(register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void* Cargo)
-{
-    int i;
-    cmsFloat32Number Inf[4], Outf[4];
-    cmsFloat32Number LabK[4];
-    cmsFloat64Number SumCMY, SumCMYK, Error, Ratio;
-    cmsCIELab ColorimetricLab, BlackPreservingLab;
-    PreserveKPlaneParams* bp = (PreserveKPlaneParams*) Cargo;
-
-    // Convert from 16 bits to floating point
-    for (i=0; i < 4; i++)
-        Inf[i] = (cmsFloat32Number) (In[i] / 65535.0);
-
-    // Get the K across Tone curve
-    LabK[3] = cmsEvalToneCurveFloat(bp ->KTone, Inf[3]);
-
-    // If going across black only, keep black only
-    if (In[0] == 0 && In[1] == 0 && In[2] == 0) {
-
-        Out[0] = Out[1] = Out[2] = 0;
-        Out[3] = _cmsQuickSaturateWord(LabK[3] * 65535.0);
-        return TRUE;
-    }
-
-    // Try the original transform,
-    cmsPipelineEvalFloat( Inf, Outf, bp ->cmyk2cmyk);
-
-    // Store a copy of the floating point result into 16-bit
-    for (i=0; i < 4; i++)
-            Out[i] = _cmsQuickSaturateWord(Outf[i] * 65535.0);
-
-    // Maybe K is already ok (mostly on K=0)
-    if ( fabs(Outf[3] - LabK[3]) < (3.0 / 65535.0) ) {
-        return TRUE;
-    }
-
-    // K differ, mesure and keep Lab measurement for further usage
-    // this is done in relative colorimetric intent
-    cmsDoTransform(bp->hProofOutput, Out, &ColorimetricLab, 1);
-
-    // Is not black only and the transform doesn't keep black.
-    // Obtain the Lab of output CMYK. After that we have Lab + K
-    cmsDoTransform(bp ->cmyk2Lab, Outf, LabK, 1);
-
-    // Obtain the corresponding CMY using reverse interpolation
-    // (K is fixed in LabK[3])
-    if (!cmsPipelineEvalReverseFloat(LabK, Outf, Outf, bp ->LabK2cmyk)) {
-
-        // Cannot find a suitable value, so use colorimetric xform
-        // which is already stored in Out[]
-        return TRUE;
-    }
-
-    // Make sure to pass thru K (which now is fixed)
-    Outf[3] = LabK[3];
-
-    // Apply TAC if needed
-    SumCMY   = Outf[0]  + Outf[1] + Outf[2];
-    SumCMYK  = SumCMY + Outf[3];
-
-    if (SumCMYK > bp ->MaxTAC) {
-
-        Ratio = 1 - ((SumCMYK - bp->MaxTAC) / SumCMY);
-        if (Ratio < 0)
-            Ratio = 0;
-    }
-    else
-       Ratio = 1.0;
-
-    Out[0] = _cmsQuickSaturateWord(Outf[0] * Ratio * 65535.0);     // C
-    Out[1] = _cmsQuickSaturateWord(Outf[1] * Ratio * 65535.0);     // M
-    Out[2] = _cmsQuickSaturateWord(Outf[2] * Ratio * 65535.0);     // Y
-    Out[3] = _cmsQuickSaturateWord(Outf[3] * 65535.0);
-
-    // Estimate the error (this goes 16 bits to Lab DBL)
-    cmsDoTransform(bp->hProofOutput, Out, &BlackPreservingLab, 1);
-    Error = cmsDeltaE(&ColorimetricLab, &BlackPreservingLab);
-    if (Error > bp -> MaxError)
-        bp->MaxError = Error;
-
-    return TRUE;
-}
-
-// This is the entry for black-plane preserving, which are non-ICC
-static
-cmsPipeline* BlackPreservingKPlaneIntents(cmsContext     ContextID,
-                                          cmsUInt32Number nProfiles,
-                                          cmsUInt32Number TheIntents[],
-                                          cmsHPROFILE     hProfiles[],
-                                          cmsBool         BPC[],
-                                          cmsFloat64Number AdaptationStates[],
-                                          cmsUInt32Number dwFlags)
-{
-    PreserveKPlaneParams bp;
-    cmsPipeline*    Result = NULL;
-    cmsUInt32Number ICCIntents[256];
-    cmsStage*         CLUT;
-    cmsUInt32Number i, nGridPoints;
-    cmsHPROFILE hLab;
-
-    // Sanity check
-    if (nProfiles < 1 || nProfiles > 255) return NULL;
-
-    // Translate black-preserving intents to ICC ones
-    for (i=0; i < nProfiles; i++)
-        ICCIntents[i] = TranslateNonICCIntents(TheIntents[i]);
-
-    // Check for non-cmyk profiles
-    if (cmsGetColorSpace(hProfiles[0]) != cmsSigCmykData ||
-        !(cmsGetColorSpace(hProfiles[nProfiles-1]) == cmsSigCmykData ||
-        cmsGetDeviceClass(hProfiles[nProfiles-1]) == cmsSigOutputClass))
-           return  DefaultICCintents(ContextID, nProfiles, ICCIntents, hProfiles, BPC, AdaptationStates, dwFlags);
-
-    // Allocate an empty LUT for holding the result
-    Result = cmsPipelineAlloc(ContextID, 4, 4);
-    if (Result == NULL) return NULL;
-
-
-    memset(&bp, 0, sizeof(bp));
-
-    // We need the input LUT of the last profile, assuming this one is responsible of
-    // black generation. This LUT will be seached in inverse order.
-    bp.LabK2cmyk = _cmsReadInputLUT(hProfiles[nProfiles-1], INTENT_RELATIVE_COLORIMETRIC);
-    if (bp.LabK2cmyk == NULL) goto Cleanup;
-
-    // Get total area coverage (in 0..1 domain)
-    bp.MaxTAC = cmsDetectTAC(hProfiles[nProfiles-1]) / 100.0;
-    if (bp.MaxTAC <= 0) goto Cleanup;
-
-
-    // Create a LUT holding normal ICC transform
-    bp.cmyk2cmyk = DefaultICCintents(ContextID,
-                                         nProfiles,
-                                         ICCIntents,
-                                         hProfiles,
-                                         BPC,
-                                         AdaptationStates,
-                                         dwFlags);
-    if (bp.cmyk2cmyk == NULL) goto Cleanup;
-
-    // Now the tone curve
-    bp.KTone = _cmsBuildKToneCurve(ContextID, 4096, nProfiles,
-                                   ICCIntents,
-                                   hProfiles,
-                                   BPC,
-                                   AdaptationStates,
-                                   dwFlags);
-    if (bp.KTone == NULL) goto Cleanup;
-
-    // To measure the output, Last profile to Lab
-    hLab = cmsCreateLab4ProfileTHR(ContextID, NULL);
-    bp.hProofOutput = cmsCreateTransformTHR(ContextID, hProfiles[nProfiles-1],
-                                         CHANNELS_SH(4)|BYTES_SH(2), hLab, TYPE_Lab_DBL,
-                                         INTENT_RELATIVE_COLORIMETRIC,
-                                         cmsFLAGS_NOCACHE|cmsFLAGS_NOOPTIMIZE);
-    if ( bp.hProofOutput == NULL) goto Cleanup;
-
-    // Same as anterior, but lab in the 0..1 range
-    bp.cmyk2Lab = cmsCreateTransformTHR(ContextID, hProfiles[nProfiles-1],
-                                         FLOAT_SH(1)|CHANNELS_SH(4)|BYTES_SH(4), hLab,
-                                         FLOAT_SH(1)|CHANNELS_SH(3)|BYTES_SH(4),
-                                         INTENT_RELATIVE_COLORIMETRIC,
-                                         cmsFLAGS_NOCACHE|cmsFLAGS_NOOPTIMIZE);
-    if (bp.cmyk2Lab == NULL) goto Cleanup;
-    cmsCloseProfile(hLab);
-
-    // Error estimation (for debug only)
-    bp.MaxError = 0;
-
-    // How many gridpoints are we going to use?
-    nGridPoints = _cmsReasonableGridpointsByColorspace(cmsSigCmykData, dwFlags);
-
-
-    CLUT = cmsStageAllocCLut16bit(ContextID, nGridPoints, 4, 4, NULL);
-    if (CLUT == NULL) goto Cleanup;
-
-    if (!cmsPipelineInsertStage(Result, cmsAT_BEGIN, CLUT))
-        goto Cleanup;
-
-    cmsStageSampleCLut16bit(CLUT, BlackPreservingSampler, (void*) &bp, 0);
-
-Cleanup:
-
-    if (bp.cmyk2cmyk) cmsPipelineFree(bp.cmyk2cmyk);
-    if (bp.cmyk2Lab) cmsDeleteTransform(bp.cmyk2Lab);
-    if (bp.hProofOutput) cmsDeleteTransform(bp.hProofOutput);
-
-    if (bp.KTone) cmsFreeToneCurve(bp.KTone);
-    if (bp.LabK2cmyk) cmsPipelineFree(bp.LabK2cmyk);
-
-    return Result;
-}
-
-// Link routines ------------------------------------------------------------------------------------------------------
-
-// Chain several profiles into a single LUT. It just checks the parameters and then calls the handler
-// for the first intent in chain. The handler may be user-defined. Is up to the handler to deal with the
-// rest of intents in chain. A maximum of 255 profiles at time are supported, which is pretty reasonable.
-cmsPipeline* _cmsLinkProfiles(cmsContext     ContextID,
-                              cmsUInt32Number nProfiles,
-                              cmsUInt32Number TheIntents[],
-                              cmsHPROFILE     hProfiles[],
-                              cmsBool         BPC[],
-                              cmsFloat64Number AdaptationStates[],
-                              cmsUInt32Number dwFlags)
-{
-    cmsUInt32Number i;
-    cmsIntentsList* Intent;
-
-    // Make sure a reasonable number of profiles is provided
-    if (nProfiles <= 0 || nProfiles > 255) {
-         cmsSignalError(ContextID, cmsERROR_RANGE, "Couldn't link '%d' profiles", nProfiles);
-        return NULL;
-    }
-
-    for (i=0; i < nProfiles; i++) {
-
-        // Check if black point is really needed or allowed. Note that
-        // following Adobe's document:
-        // BPC does not apply to devicelink profiles, nor to abs colorimetric,
-        // and applies always on V4 perceptual and saturation.
-
-        if (TheIntents[i] == INTENT_ABSOLUTE_COLORIMETRIC)
-            BPC[i] = FALSE;
-
-        if (TheIntents[i] == INTENT_PERCEPTUAL || TheIntents[i] == INTENT_SATURATION) {
-
-            // Force BPC for V4 profiles in perceptual and saturation
-            if (cmsGetProfileVersion(hProfiles[i]) >= 4.0)
-                BPC[i] = TRUE;
-        }
-    }
-
-    // Search for a handler. The first intent in the chain defines the handler. That would
-    // prevent using multiple custom intents in a multiintent chain, but the behaviour of
-    // this case would present some issues if the custom intent tries to do things like
-    // preserve primaries. This solution is not perfect, but works well on most cases.
-
-    Intent = SearchIntent(ContextID, TheIntents[0]);
-    if (Intent == NULL) {
-        cmsSignalError(ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unsupported intent '%d'", TheIntents[0]);
-        return NULL;
-    }
-
-    // Call the handler
-    return Intent ->Link(ContextID, nProfiles, TheIntents, hProfiles, BPC, AdaptationStates, dwFlags);
-}
-
-// -------------------------------------------------------------------------------------------------
-
-// Get information about available intents. nMax is the maximum space for the supplied "Codes"
-// and "Descriptions" the function returns the total number of intents, which may be greater
-// than nMax, although the matrices are not populated beyond this level.
-cmsUInt32Number CMSEXPORT cmsGetSupportedIntentsTHR(cmsContext ContextID, cmsUInt32Number nMax, cmsUInt32Number* Codes, char** Descriptions)
-{
-    _cmsIntentsPluginChunkType* ctx = ( _cmsIntentsPluginChunkType*) _cmsContextGetClientChunk(ContextID, IntentPlugin);
-    cmsIntentsList* pt;
-    cmsUInt32Number nIntents;
-
-
-    for (nIntents=0, pt = ctx->Intents; pt != NULL; pt = pt -> Next)
-    {
-        if (nIntents < nMax) {
-            if (Codes != NULL)
-                Codes[nIntents] = pt ->Intent;
-
-            if (Descriptions != NULL)
-                Descriptions[nIntents] = pt ->Description;
-        }
-
-        nIntents++;
-    }
-
-    for (nIntents=0, pt = DefaultIntents; pt != NULL; pt = pt -> Next)
-    {
-        if (nIntents < nMax) {
-            if (Codes != NULL)
-                Codes[nIntents] = pt ->Intent;
-
-            if (Descriptions != NULL)
-                Descriptions[nIntents] = pt ->Description;
-        }
-
-        nIntents++;
-    }
-    return nIntents;
-}
-
-cmsUInt32Number CMSEXPORT cmsGetSupportedIntents(cmsUInt32Number nMax, cmsUInt32Number* Codes, char** Descriptions)
-{
-    return cmsGetSupportedIntentsTHR(NULL, nMax, Codes, Descriptions);
-}
-
-// The plug-in registration. User can add new intents or override default routines
-cmsBool  _cmsRegisterRenderingIntentPlugin(cmsContext id, cmsPluginBase* Data)
-{
-    _cmsIntentsPluginChunkType* ctx = ( _cmsIntentsPluginChunkType*) _cmsContextGetClientChunk(id, IntentPlugin);
-    cmsPluginRenderingIntent* Plugin = (cmsPluginRenderingIntent*) Data;
-    cmsIntentsList* fl;
-
-    // Do we have to reset the custom intents?
-    if (Data == NULL) {
-
-        ctx->Intents = NULL;
-        return TRUE;
-    }
-
-    fl = (cmsIntentsList*) _cmsPluginMalloc(id, sizeof(cmsIntentsList));
-    if (fl == NULL) return FALSE;
-
-
-    fl ->Intent  = Plugin ->Intent;
-    strncpy(fl ->Description, Plugin ->Description, sizeof(fl ->Description)-1);
-    fl ->Description[sizeof(fl ->Description)-1] = 0;
-
-    fl ->Link    = Plugin ->Link;
-
-    fl ->Next = ctx ->Intents;
-    ctx ->Intents = fl;
-
-    return TRUE;
-}
-
diff --git a/core/src/fxcodec/lcms2/lcms2-2.6/src/cmserr.c b/core/src/fxcodec/lcms2/lcms2-2.6/src/cmserr.c
deleted file mode 100644 (file)
index b008b52..0000000
+++ /dev/null
@@ -1,707 +0,0 @@
-//---------------------------------------------------------------------------------
-//
-//  Little Color Management System
-//  Copyright (c) 1998-2012 Marti Maria Saguer
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the "Software"),
-// to deal in the Software without restriction, including without limitation
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,
-// and/or sell copies of the Software, and to permit persons to whom the Software
-// is furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
-// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-//---------------------------------------------------------------------------------
-
-#include "lcms2_internal.h"
-
-// I am so tired about incompatibilities on those functions that here are some replacements
-// that hopefully would be fully portable.
-
-// compare two strings ignoring case
-int CMSEXPORT cmsstrcasecmp(const char* s1, const char* s2)
-{
-    register const unsigned char *us1 = (const unsigned char *)s1,
-                                 *us2 = (const unsigned char *)s2;
-
-    while (toupper(*us1) == toupper(*us2++))
-        if (*us1++ == '\0')
-            return 0;
-
-    return (toupper(*us1) - toupper(*--us2));
-}
-
-// long int because C99 specifies ftell in such way (7.19.9.2)
-long int CMSEXPORT cmsfilelength(FILE* f)
-{
-    long int p , n;
-
-    p = ftell(f); // register current file position
-
-    if (fseek(f, 0, SEEK_END) != 0) {
-        return -1;
-    }
-
-    n = ftell(f);
-    fseek(f, p, SEEK_SET); // file position restored
-
-    return n;
-}
-
-#if 0
-// Memory handling ------------------------------------------------------------------
-//
-// This is the interface to low-level memory management routines. By default a simple
-// wrapping to malloc/free/realloc is provided, although there is a limit on the max
-// amount of memoy that can be reclaimed. This is mostly as a safety feature to prevent 
-// bogus or evil code to allocate huge blocks that otherwise lcms would never need.
-
-#define MAX_MEMORY_FOR_ALLOC  ((cmsUInt32Number)(1024U*1024U*512U))
-
-// User may override this behaviour by using a memory plug-in, which basically replaces
-// the default memory management functions. In this case, no check is performed and it
-// is up to the plug-in writter to keep in the safe side. There are only three functions
-// required to be implemented: malloc, realloc and free, although the user may want to
-// replace the optional mallocZero, calloc and dup as well.
-
-cmsBool   _cmsRegisterMemHandlerPlugin(cmsContext ContextID, cmsPluginBase* Plugin);
-
-// *********************************************************************************
-
-// This is the default memory allocation function. It does a very coarse
-// check of amout of memory, just to prevent exploits
-static
-void* _cmsMallocDefaultFn(cmsContext ContextID, cmsUInt32Number size)
-{
-    if (size > MAX_MEMORY_FOR_ALLOC) return NULL;  // Never allow over maximum
-
-    return (void*) malloc(size);
-
-    cmsUNUSED_PARAMETER(ContextID);
-}
-
-// Generic allocate & zero
-static
-void* _cmsMallocZeroDefaultFn(cmsContext ContextID, cmsUInt32Number size)
-{
-    void *pt = _cmsMalloc(ContextID, size);
-    if (pt == NULL) return NULL;
-
-    memset(pt, 0, size);
-    return pt;
-}
-
-
-// The default free function. The only check proformed is against NULL pointers
-static
-void _cmsFreeDefaultFn(cmsContext ContextID, void *Ptr)
-{
-    // free(NULL) is defined a no-op by C99, therefore it is safe to
-    // avoid the check, but it is here just in case...
-
-    if (Ptr) free(Ptr);
-
-    cmsUNUSED_PARAMETER(ContextID);
-}
-
-// The default realloc function. Again it checks for exploits. If Ptr is NULL,
-// realloc behaves the same way as malloc and allocates a new block of size bytes.
-static
-void* _cmsReallocDefaultFn(cmsContext ContextID, void* Ptr, cmsUInt32Number size)
-{
-
-    if (size > MAX_MEMORY_FOR_ALLOC) return NULL;  // Never realloc over 512Mb
-
-    return realloc(Ptr, size);
-
-    cmsUNUSED_PARAMETER(ContextID);
-}
-
-
-// The default calloc function. Allocates an array of num elements, each one of size bytes
-// all memory is initialized to zero.
-static
-void* _cmsCallocDefaultFn(cmsContext ContextID, cmsUInt32Number num, cmsUInt32Number size)
-{
-    cmsUInt32Number Total = num * size;
-
-    // Preserve calloc behaviour
-    if (Total == 0) return NULL;
-
-    // Safe check for overflow.
-    if (num >= UINT_MAX / size) return NULL;
-
-    // Check for overflow
-    if (Total < num || Total < size) {
-        return NULL;
-    }
-
-    if (Total > MAX_MEMORY_FOR_ALLOC) return NULL;  // Never alloc over 512Mb
-
-    return _cmsMallocZero(ContextID, Total);
-}
-
-// Generic block duplication
-static
-void* _cmsDupDefaultFn(cmsContext ContextID, const void* Org, cmsUInt32Number size)
-{
-    void* mem;
-
-    if (size > MAX_MEMORY_FOR_ALLOC) return NULL;  // Never dup over 512Mb
-
-    mem = _cmsMalloc(ContextID, size);
-
-    if (mem != NULL && Org != NULL)
-        memmove(mem, Org, size);
-
-    return mem;
-}
-
-
-// Pointers to memory manager functions in Context0
-_cmsMemPluginChunkType _cmsMemPluginChunk = { _cmsMallocDefaultFn, _cmsMallocZeroDefaultFn, _cmsFreeDefaultFn, 
-                                              _cmsReallocDefaultFn, _cmsCallocDefaultFn,    _cmsDupDefaultFn
-                                            };
-
-
-// Reset and duplicate memory manager
-void _cmsAllocMemPluginChunk(struct _cmsContext_struct* ctx, const struct _cmsContext_struct* src)
-{
-    _cmsAssert(ctx != NULL);
-
-    if (src != NULL) {    
-
-        // Duplicate
-        ctx ->chunks[MemPlugin] = _cmsSubAllocDup(ctx ->MemPool, src ->chunks[MemPlugin], sizeof(_cmsMemPluginChunkType));  
-    }
-    else {
-
-        // To reset it, we use the default allocators, which cannot be overriden
-        ctx ->chunks[MemPlugin] = &ctx ->DefaultMemoryManager;
-    } 
-}
-
-// Auxiliar to fill memory management functions from plugin (or context 0 defaults)
-void _cmsInstallAllocFunctions(cmsPluginMemHandler* Plugin, _cmsMemPluginChunkType* ptr)
-{
-    if (Plugin == NULL) {
-
-        memcpy(ptr, &_cmsMemPluginChunk, sizeof(_cmsMemPluginChunk));
-    }
-    else {
-
-        ptr ->MallocPtr  = Plugin -> MallocPtr;
-        ptr ->FreePtr    = Plugin -> FreePtr;
-        ptr ->ReallocPtr = Plugin -> ReallocPtr;
-
-        // Make sure we revert to defaults
-        ptr ->MallocZeroPtr= _cmsMallocZeroDefaultFn;
-        ptr ->CallocPtr    = _cmsCallocDefaultFn;
-        ptr ->DupPtr       = _cmsDupDefaultFn;
-      
-        if (Plugin ->MallocZeroPtr != NULL) ptr ->MallocZeroPtr = Plugin -> MallocZeroPtr;
-        if (Plugin ->CallocPtr != NULL)     ptr ->CallocPtr     = Plugin -> CallocPtr;
-        if (Plugin ->DupPtr != NULL)        ptr ->DupPtr        = Plugin -> DupPtr;
-        
-    }
-}
-
-
-// Plug-in replacement entry
-cmsBool  _cmsRegisterMemHandlerPlugin(cmsContext ContextID, cmsPluginBase *Data)
-{
-    cmsPluginMemHandler* Plugin = (cmsPluginMemHandler*) Data;     
-    _cmsMemPluginChunkType* ptr;
-
-    // NULL forces to reset to defaults. In this special case, the defaults are stored in the context structure. 
-    // Remaining plug-ins does NOT have any copy in the context structure, but this is somehow special as the
-    // context internal data should be malloce'd by using those functions. 
-    if (Data == NULL) {
-
-       struct _cmsContext_struct* ctx = ( struct _cmsContext_struct*) ContextID;
-
-       // Return to the default allocators
-        if (ContextID != NULL) {
-            ctx->chunks[MemPlugin] = (void*) &ctx->DefaultMemoryManager;
-        }
-        return TRUE;
-    }
-
-    // Check for required callbacks
-    if (Plugin -> MallocPtr == NULL ||
-        Plugin -> FreePtr == NULL ||
-        Plugin -> ReallocPtr == NULL) return FALSE;
-
-    // Set replacement functions
-    ptr = (_cmsMemPluginChunkType*) _cmsContextGetClientChunk(ContextID, MemPlugin);
-    if (ptr == NULL) 
-        return FALSE;
-
-    _cmsInstallAllocFunctions(Plugin, ptr);
-    return TRUE;
-}
-#else
-#include "../../../../../include/fxcrt/fx_memory.h"
-#include "../../../../../include/fxcrt/fx_system.h"
-
-cmsBool  _cmsRegisterMemHandlerPlugin(cmsContext ContextID, cmsPluginBase* Plugin)
-{
-       return TRUE;
-}
-
-// Generic allocate
-void* CMSEXPORT _cmsMalloc(cmsContext ContextID, cmsUInt32Number size)
-{
-    return FXMEM_DefaultAlloc(size, 1);
-}
-
-// Generic allocate & zero
-void* CMSEXPORT _cmsMallocZero(cmsContext ContextID, cmsUInt32Number size)
-{
-       void* p = FXMEM_DefaultAlloc(size, 1);
-       if (p) FXSYS_memset(p, 0, size);
-       return p;
-}
-
-// Generic calloc
-void* CMSEXPORT _cmsCalloc(cmsContext ContextID, cmsUInt32Number num, cmsUInt32Number size)
-{
-       cmsUInt32Number total = num * size;
-       if (total == 0 || total / size != num || total >= 512 * 1024 * 1024)
-               return NULL;
-
-       return _cmsMallocZero(ContextID, num * size);
-}
-
-// Generic reallocate
-void* CMSEXPORT _cmsRealloc(cmsContext ContextID, void* Ptr, cmsUInt32Number size)
-{
-       return FXMEM_DefaultRealloc(Ptr, size, 1);
-}
-
-// Generic free memory
-void CMSEXPORT _cmsFree(cmsContext ContextID, void* Ptr)
-{
-       if (Ptr != NULL) FXMEM_DefaultFree(Ptr, 0);
-}
-
-// Generic block duplication
-void* CMSEXPORT _cmsDupMem(cmsContext ContextID, const void* Org, cmsUInt32Number size)
-{
-       void* p = FXMEM_DefaultAlloc(size, 1);
-       FXSYS_memmove(p, Org, size);
-       return p;
-}
-
-_cmsMemPluginChunkType _cmsMemPluginChunk = {_cmsMalloc, _cmsMallocZero, _cmsFree, 
-                                                _cmsRealloc, _cmsCalloc,    _cmsDupMem
-                                            };
-
-void _cmsAllocMemPluginChunk(struct _cmsContext_struct* ctx, const struct _cmsContext_struct* src)
-{
-       _cmsAssert(ctx != NULL);
-
-       if (src != NULL) {    
-
-               // Duplicate
-               ctx ->chunks[MemPlugin] = _cmsSubAllocDup(ctx ->MemPool, src ->chunks[MemPlugin], sizeof(_cmsMemPluginChunkType));  
-       }
-       else {
-
-               // To reset it, we use the default allocators, which cannot be overriden
-               ctx ->chunks[MemPlugin] = &ctx ->DefaultMemoryManager;
-       } 
-}
-
-void _cmsInstallAllocFunctions(cmsPluginMemHandler* Plugin, _cmsMemPluginChunkType* ptr)
-{
-       if (Plugin == NULL) {
-
-               memcpy(ptr, &_cmsMemPluginChunk, sizeof(_cmsMemPluginChunk));
-       }
-       else {
-
-               ptr ->MallocPtr  = Plugin -> MallocPtr;
-               ptr ->FreePtr    = Plugin -> FreePtr;
-               ptr ->ReallocPtr = Plugin -> ReallocPtr;
-
-               // Make sure we revert to defaults
-               ptr ->MallocZeroPtr= _cmsMallocZero;
-               ptr ->CallocPtr    = _cmsCalloc;
-               ptr ->DupPtr       = _cmsDupMem;
-
-               if (Plugin ->MallocZeroPtr != NULL) ptr ->MallocZeroPtr = Plugin -> MallocZeroPtr;
-               if (Plugin ->CallocPtr != NULL)     ptr ->CallocPtr     = Plugin -> CallocPtr;
-               if (Plugin ->DupPtr != NULL)        ptr ->DupPtr        = Plugin -> DupPtr;
-
-       }
-}
-#endif
-
-// ********************************************************************************************
-
-// Sub allocation takes care of many pointers of small size. The memory allocated in
-// this way have be freed at once. Next function allocates a single chunk for linked list
-// I prefer this method over realloc due to the big inpact on xput realloc may have if
-// memory is being swapped to disk. This approach is safer (although that may not be true on all platforms)
-static
-_cmsSubAllocator_chunk* _cmsCreateSubAllocChunk(cmsContext ContextID, cmsUInt32Number Initial)
-{
-    _cmsSubAllocator_chunk* chunk;
-
-    // 20K by default
-    if (Initial == 0)
-        Initial = 20*1024;
-
-    // Create the container
-    chunk = (_cmsSubAllocator_chunk*) _cmsMallocZero(ContextID, sizeof(_cmsSubAllocator_chunk));
-    if (chunk == NULL) return NULL;
-
-    // Initialize values
-    chunk ->Block     = (cmsUInt8Number*) _cmsMalloc(ContextID, Initial);
-    if (chunk ->Block == NULL) {
-
-        // Something went wrong
-        _cmsFree(ContextID, chunk);
-        return NULL;
-    }
-
-    chunk ->BlockSize = Initial;
-    chunk ->Used      = 0;
-    chunk ->next      = NULL;
-
-    return chunk;
-}
-
-// The suballocated is nothing but a pointer to the first element in the list. We also keep
-// the thread ID in this structure.
-_cmsSubAllocator* _cmsCreateSubAlloc(cmsContext ContextID, cmsUInt32Number Initial)
-{
-    _cmsSubAllocator* sub;
-
-    // Create the container
-    sub = (_cmsSubAllocator*) _cmsMallocZero(ContextID, sizeof(_cmsSubAllocator));
-    if (sub == NULL) return NULL;
-
-    sub ->ContextID = ContextID;
-
-    sub ->h = _cmsCreateSubAllocChunk(ContextID, Initial);
-    if (sub ->h == NULL) {
-        _cmsFree(ContextID, sub);
-        return NULL;
-    }
-
-    return sub;
-}
-
-
-// Get rid of whole linked list
-void _cmsSubAllocDestroy(_cmsSubAllocator* sub)
-{
-    _cmsSubAllocator_chunk *chunk, *n;
-
-    for (chunk = sub ->h; chunk != NULL; chunk = n) {
-
-        n = chunk->next;
-        if (chunk->Block != NULL) _cmsFree(sub ->ContextID, chunk->Block);
-        _cmsFree(sub ->ContextID, chunk);
-    }
-
-    // Free the header
-    _cmsFree(sub ->ContextID, sub);
-}
-
-
-// Get a pointer to small memory block.
-void*  _cmsSubAlloc(_cmsSubAllocator* sub, cmsUInt32Number size)
-{
-    cmsUInt32Number Free = sub -> h ->BlockSize - sub -> h -> Used;
-    cmsUInt8Number* ptr;
-
-    size = _cmsALIGNMEM(size);
-
-    // Check for memory. If there is no room, allocate a new chunk of double memory size.
-    if (size > Free) {
-
-        _cmsSubAllocator_chunk* chunk;
-        cmsUInt32Number newSize;
-
-        newSize = sub -> h ->BlockSize * 2;
-        if (newSize < size) newSize = size;
-
-        chunk = _cmsCreateSubAllocChunk(sub -> ContextID, newSize);
-        if (chunk == NULL) return NULL;
-
-        // Link list
-        chunk ->next = sub ->h;
-        sub ->h    = chunk;
-
-    }
-
-    ptr =  sub -> h ->Block + sub -> h ->Used;
-    sub -> h -> Used += size;
-
-    return (void*) ptr;
-}
-
-// Duplicate in pool
-void* _cmsSubAllocDup(_cmsSubAllocator* s, const void *ptr, cmsUInt32Number size)
-{
-    void *NewPtr;
-    
-    // Dup of null pointer is also NULL
-    if (ptr == NULL)
-        return NULL;
-
-    NewPtr = _cmsSubAlloc(s, size);
-
-    if (ptr != NULL && NewPtr != NULL) {
-        memcpy(NewPtr, ptr, size);
-    }
-
-    return NewPtr;
-}
-
-
-
-// Error logging ******************************************************************
-
-// There is no error handling at all. When a funtion fails, it returns proper value.
-// For example, all create functions does return NULL on failure. Other return FALSE
-// It may be interesting, for the developer, to know why the function is failing.
-// for that reason, lcms2 does offer a logging function. This function does recive
-// a ENGLISH string with some clues on what is going wrong. You can show this
-// info to the end user, or just create some sort of log.
-// The logging function should NOT terminate the program, as this obviously can leave
-// resources. It is the programmer's responsability to check each function return code
-// to make sure it didn't fail.
-
-// Error messages are limited to MAX_ERROR_MESSAGE_LEN
-
-#define MAX_ERROR_MESSAGE_LEN   1024
-
-// ---------------------------------------------------------------------------------------------------------
-
-// This is our default log error
-static void DefaultLogErrorHandlerFunction(cmsContext ContextID, cmsUInt32Number ErrorCode, const char *Text);
-
-// Context0 storage, which is global
-_cmsLogErrorChunkType _cmsLogErrorChunk = { DefaultLogErrorHandlerFunction };
-
-// Allocates and inits error logger container for a given context. If src is NULL, only initializes the value
-// to the default. Otherwise, it duplicates the value. The interface is standard across all context clients
-void _cmsAllocLogErrorChunk(struct _cmsContext_struct* ctx, 
-                            const struct _cmsContext_struct* src)
-{    
-    static _cmsLogErrorChunkType LogErrorChunk = { DefaultLogErrorHandlerFunction };
-    void* from;
-     
-     if (src != NULL) {
-        from = src ->chunks[Logger];       
-    }
-    else {
-       from = &LogErrorChunk;
-    }
-    
-    ctx ->chunks[Logger] = _cmsSubAllocDup(ctx ->MemPool, from, sizeof(_cmsLogErrorChunkType));   
-}
-
-// The default error logger does nothing.
-static
-void DefaultLogErrorHandlerFunction(cmsContext ContextID, cmsUInt32Number ErrorCode, const char *Text)
-{
-    // fprintf(stderr, "[lcms]: %s\n", Text);
-    // fflush(stderr);
-
-     cmsUNUSED_PARAMETER(ContextID);
-     cmsUNUSED_PARAMETER(ErrorCode);
-     cmsUNUSED_PARAMETER(Text);
-}
-
-// Change log error, context based
-void CMSEXPORT cmsSetLogErrorHandlerTHR(cmsContext ContextID, cmsLogErrorHandlerFunction Fn)
-{
-    _cmsLogErrorChunkType* lhg = (_cmsLogErrorChunkType*) _cmsContextGetClientChunk(ContextID, Logger);
-
-    if (lhg != NULL) {
-
-        if (Fn == NULL)
-            lhg -> LogErrorHandler = DefaultLogErrorHandlerFunction;
-        else
-            lhg -> LogErrorHandler = Fn;
-    }
-}
-
-// Change log error, legacy
-void CMSEXPORT cmsSetLogErrorHandler(cmsLogErrorHandlerFunction Fn)
-{
-    cmsSetLogErrorHandlerTHR(NULL, Fn);    
-}
-
-// Log an error
-// ErrorText is a text holding an english description of error.
-void CMSEXPORT cmsSignalError(cmsContext ContextID, cmsUInt32Number ErrorCode, const char *ErrorText, ...)
-{
-    va_list args;
-    char Buffer[MAX_ERROR_MESSAGE_LEN];
-    _cmsLogErrorChunkType* lhg;
-
-
-    va_start(args, ErrorText);
-    vsnprintf(Buffer, MAX_ERROR_MESSAGE_LEN-1, ErrorText, args);
-    va_end(args);
-
-    // Check for the context, if specified go there. If not, go for the global
-    lhg = (_cmsLogErrorChunkType*) _cmsContextGetClientChunk(ContextID, Logger);
-    if (lhg ->LogErrorHandler) {
-        lhg ->LogErrorHandler(ContextID, ErrorCode, Buffer);
-    }   
-}
-
-// Utility function to print signatures
-void _cmsTagSignature2String(char String[5], cmsTagSignature sig)
-{
-    cmsUInt32Number be;
-
-    // Convert to big endian
-    be = _cmsAdjustEndianess32((cmsUInt32Number) sig);
-
-    // Move chars
-    memmove(String, &be, 4);
-
-    // Make sure of terminator
-    String[4] = 0;
-}
-
-//--------------------------------------------------------------------------------------------------
-
-
-static
-void* defMtxCreate(cmsContext id)
-{
-    _cmsMutex* ptr_mutex = (_cmsMutex*) _cmsMalloc(id, sizeof(_cmsMutex));
-    _cmsInitMutexPrimitive(ptr_mutex);
-    return (void*) ptr_mutex;   
-}
-
-static
-void defMtxDestroy(cmsContext id, void* mtx)
-{
-    _cmsDestroyMutexPrimitive((_cmsMutex *) mtx); 
-    _cmsFree(id, mtx);
-}
-
-static
-cmsBool defMtxLock(cmsContext id, void* mtx)
-{
-    cmsUNUSED_PARAMETER(id);
-    return _cmsLockPrimitive((_cmsMutex *) mtx) == 0;     
-}
-
-static
-void defMtxUnlock(cmsContext id, void* mtx)
-{
-    cmsUNUSED_PARAMETER(id);
-    _cmsUnlockPrimitive((_cmsMutex *) mtx); 
-}
-
-
-
-// Pointers to memory manager functions in Context0
-_cmsMutexPluginChunkType _cmsMutexPluginChunk = { defMtxCreate, defMtxDestroy, defMtxLock, defMtxUnlock };
-
-// Allocate and init mutex container.
-void _cmsAllocMutexPluginChunk(struct _cmsContext_struct* ctx, 
-                                        const struct _cmsContext_struct* src)
-{
-    static _cmsMutexPluginChunkType MutexChunk = {defMtxCreate, defMtxDestroy, defMtxLock, defMtxUnlock };
-    void* from;
-     
-     if (src != NULL) {
-        from = src ->chunks[MutexPlugin];       
-    }
-    else {
-       from = &MutexChunk;
-    }
-    
-    ctx ->chunks[MutexPlugin] = _cmsSubAllocDup(ctx ->MemPool, from, sizeof(_cmsMutexPluginChunkType));   
-}
-
-// Register new ways to transform
-cmsBool  _cmsRegisterMutexPlugin(cmsContext ContextID, cmsPluginBase* Data)
-{
-    cmsPluginMutex* Plugin = (cmsPluginMutex*) Data;
-    _cmsMutexPluginChunkType* ctx = ( _cmsMutexPluginChunkType*) _cmsContextGetClientChunk(ContextID, MutexPlugin);
-
-    if (Data == NULL) {
-
-        // No lock routines
-        ctx->CreateMutexPtr = NULL; 
-        ctx->DestroyMutexPtr = NULL; 
-        ctx->LockMutexPtr = NULL;
-        ctx ->UnlockMutexPtr = NULL;
-        return TRUE;
-    }
-
-    // Factory callback is required
-    if (Plugin ->CreateMutexPtr == NULL || Plugin ->DestroyMutexPtr == NULL || 
-        Plugin ->LockMutexPtr == NULL || Plugin ->UnlockMutexPtr == NULL) return FALSE;
-
-
-    ctx->CreateMutexPtr  = Plugin->CreateMutexPtr;
-    ctx->DestroyMutexPtr = Plugin ->DestroyMutexPtr;
-    ctx ->LockMutexPtr   = Plugin ->LockMutexPtr;
-    ctx ->UnlockMutexPtr = Plugin ->UnlockMutexPtr;
-
-    // All is ok
-    return TRUE;
-}
-
-// Generic Mutex fns
-void* CMSEXPORT _cmsCreateMutex(cmsContext ContextID)
-{
-    _cmsMutexPluginChunkType* ptr = (_cmsMutexPluginChunkType*) _cmsContextGetClientChunk(ContextID, MutexPlugin);
-
-    if (ptr ->CreateMutexPtr == NULL) return NULL;
-
-    return ptr ->CreateMutexPtr(ContextID);
-}
-
-void CMSEXPORT _cmsDestroyMutex(cmsContext ContextID, void* mtx)
-{
-    _cmsMutexPluginChunkType* ptr = (_cmsMutexPluginChunkType*) _cmsContextGetClientChunk(ContextID, MutexPlugin);
-
-    if (ptr ->DestroyMutexPtr != NULL) {
-
-        ptr ->DestroyMutexPtr(ContextID, mtx);
-    }
-}
-
-cmsBool CMSEXPORT _cmsLockMutex(cmsContext ContextID, void* mtx)
-{
-    _cmsMutexPluginChunkType* ptr = (_cmsMutexPluginChunkType*) _cmsContextGetClientChunk(ContextID, MutexPlugin);
-
-    if (ptr ->LockMutexPtr == NULL) return TRUE;
-
-    return ptr ->LockMutexPtr(ContextID, mtx);
-}
-
-void CMSEXPORT _cmsUnlockMutex(cmsContext ContextID, void* mtx)
-{
-    _cmsMutexPluginChunkType* ptr = (_cmsMutexPluginChunkType*) _cmsContextGetClientChunk(ContextID, MutexPlugin);
-
-    if (ptr ->UnlockMutexPtr != NULL) {
-
-        ptr ->UnlockMutexPtr(ContextID, mtx);
-    }
-}
diff --git a/core/src/fxcodec/lcms2/lcms2-2.6/src/cmsgamma.c b/core/src/fxcodec/lcms2/lcms2-2.6/src/cmsgamma.c
deleted file mode 100644 (file)
index 97aeb7c..0000000
+++ /dev/null
@@ -1,1298 +0,0 @@
-//---------------------------------------------------------------------------------
-//
-//  Little Color Management System
-//  Copyright (c) 1998-2013 Marti Maria Saguer
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the "Software"),
-// to deal in the Software without restriction, including without limitation
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,
-// and/or sell copies of the Software, and to permit persons to whom the Software
-// is furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
-// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-//---------------------------------------------------------------------------------
-//
-
-#include "lcms2_internal.h"
-
-// Tone curves are powerful constructs that can contain curves specified in diverse ways.
-// The curve is stored in segments, where each segment can be sampled or specified by parameters.
-// a 16.bit simplification of the *whole* curve is kept for optimization purposes. For float operation,
-// each segment is evaluated separately. Plug-ins may be used to define new parametric schemes,
-// each plug-in may define up to MAX_TYPES_IN_LCMS_PLUGIN functions types. For defining a function,
-// the plug-in should provide the type id, how many parameters each type has, and a pointer to
-// a procedure that evaluates the function. In the case of reverse evaluation, the evaluator will
-// be called with the type id as a negative value, and a sampled version of the reversed curve
-// will be built.
-
-// ----------------------------------------------------------------- Implementation
-// Maxim number of nodes
-#define MAX_NODES_IN_CURVE   4097
-#define MINUS_INF            (-1E22F)
-#define PLUS_INF             (+1E22F)
-
-// The list of supported parametric curves
-typedef struct _cmsParametricCurvesCollection_st {
-
-    int nFunctions;                                     // Number of supported functions in this chunk
-    int FunctionTypes[MAX_TYPES_IN_LCMS_PLUGIN];        // The identification types
-    int ParameterCount[MAX_TYPES_IN_LCMS_PLUGIN];       // Number of parameters for each function
-    cmsParametricCurveEvaluator    Evaluator;           // The evaluator
-
-    struct _cmsParametricCurvesCollection_st* Next; // Next in list
-
-} _cmsParametricCurvesCollection;
-
-// This is the default (built-in) evaluator
-static cmsFloat64Number DefaultEvalParametricFn(cmsInt32Number Type, const cmsFloat64Number Params[], cmsFloat64Number R);
-
-// The built-in list
-static _cmsParametricCurvesCollection DefaultCurves = {
-    9,                                  // # of curve types
-    { 1, 2, 3, 4, 5, 6, 7, 8, 108 },    // Parametric curve ID
-    { 1, 3, 4, 5, 7, 4, 5, 5, 1 },      // Parameters by type
-    DefaultEvalParametricFn,            // Evaluator
-    NULL                                // Next in chain
-};
-
-// Duplicates the zone of memory used by the plug-in in the new context
-static
-void DupPluginCurvesList(struct _cmsContext_struct* ctx, 
-                                               const struct _cmsContext_struct* src)
-{
-   _cmsCurvesPluginChunkType newHead = { NULL };
-   _cmsParametricCurvesCollection*  entry;
-   _cmsParametricCurvesCollection*  Anterior = NULL;
-   _cmsCurvesPluginChunkType* head = (_cmsCurvesPluginChunkType*) src->chunks[CurvesPlugin];
-
-    _cmsAssert(head != NULL);
-
-    // Walk the list copying all nodes
-   for (entry = head->ParametricCurves;
-        entry != NULL;
-        entry = entry ->Next) {
-
-            _cmsParametricCurvesCollection *newEntry = ( _cmsParametricCurvesCollection *) _cmsSubAllocDup(ctx ->MemPool, entry, sizeof(_cmsParametricCurvesCollection));
-   
-            if (newEntry == NULL) 
-                return;
-
-            // We want to keep the linked list order, so this is a little bit tricky
-            newEntry -> Next = NULL;
-            if (Anterior)
-                Anterior -> Next = newEntry;
-     
-            Anterior = newEntry;
-
-            if (newHead.ParametricCurves == NULL)
-                newHead.ParametricCurves = newEntry;
-    }
-
-  ctx ->chunks[CurvesPlugin] = _cmsSubAllocDup(ctx->MemPool, &newHead, sizeof(_cmsCurvesPluginChunkType));
-}
-
-// The allocator have to follow the chain
-void _cmsAllocCurvesPluginChunk(struct _cmsContext_struct* ctx, 
-                                const struct _cmsContext_struct* src)
-{
-    _cmsAssert(ctx != NULL);
-
-    if (src != NULL) {
-
-        // Copy all linked list
-       DupPluginCurvesList(ctx, src);
-    }
-    else {
-        static _cmsCurvesPluginChunkType CurvesPluginChunk = { NULL };
-        ctx ->chunks[CurvesPlugin] = _cmsSubAllocDup(ctx ->MemPool, &CurvesPluginChunk, sizeof(_cmsCurvesPluginChunkType));
-    }
-}
-
-
-// The linked list head
-_cmsCurvesPluginChunkType _cmsCurvesPluginChunk = { NULL };
-
-// As a way to install new parametric curves
-cmsBool _cmsRegisterParametricCurvesPlugin(cmsContext ContextID, cmsPluginBase* Data)
-{
-    _cmsCurvesPluginChunkType* ctx = ( _cmsCurvesPluginChunkType*) _cmsContextGetClientChunk(ContextID, CurvesPlugin);
-    cmsPluginParametricCurves* Plugin = (cmsPluginParametricCurves*) Data;
-    _cmsParametricCurvesCollection* fl;
-
-    if (Data == NULL) {
-
-          ctx -> ParametricCurves =  NULL;
-          return TRUE;
-    }
-
-    fl = (_cmsParametricCurvesCollection*) _cmsPluginMalloc(ContextID, sizeof(_cmsParametricCurvesCollection));
-    if (fl == NULL) return FALSE;
-
-    // Copy the parameters
-    fl ->Evaluator  = Plugin ->Evaluator;
-    fl ->nFunctions = Plugin ->nFunctions;
-
-    // Make sure no mem overwrites
-    if (fl ->nFunctions > MAX_TYPES_IN_LCMS_PLUGIN)
-        fl ->nFunctions = MAX_TYPES_IN_LCMS_PLUGIN;
-
-    // Copy the data
-    memmove(fl->FunctionTypes,  Plugin ->FunctionTypes,   fl->nFunctions * sizeof(cmsUInt32Number));
-    memmove(fl->ParameterCount, Plugin ->ParameterCount,  fl->nFunctions * sizeof(cmsUInt32Number));
-
-    // Keep linked list
-    fl ->Next = ctx->ParametricCurves;
-    ctx->ParametricCurves = fl;
-
-    // All is ok
-    return TRUE;
-}
-
-
-// Search in type list, return position or -1 if not found
-static
-int IsInSet(int Type, _cmsParametricCurvesCollection* c)
-{
-    int i;
-
-    for (i=0; i < c ->nFunctions; i++)
-        if (abs(Type) == c ->FunctionTypes[i]) return i;
-
-    return -1;
-}
-
-
-// Search for the collection which contains a specific type
-static
-_cmsParametricCurvesCollection *GetParametricCurveByType(cmsContext ContextID, int Type, int* index)
-{
-    _cmsParametricCurvesCollection* c;
-    int Position;
-    _cmsCurvesPluginChunkType* ctx = ( _cmsCurvesPluginChunkType*) _cmsContextGetClientChunk(ContextID, CurvesPlugin);
-
-    for (c = ctx->ParametricCurves; c != NULL; c = c ->Next) {
-
-        Position = IsInSet(Type, c);
-
-        if (Position != -1) {
-            if (index != NULL)
-                *index = Position;
-            return c;
-        }
-    }
-    // If none found, revert for defaults
-    for (c = &DefaultCurves; c != NULL; c = c ->Next) {
-
-        Position = IsInSet(Type, c);
-
-        if (Position != -1) {
-            if (index != NULL)
-                *index = Position;
-            return c;
-        }
-    }
-
-    return NULL;
-}
-
-// Low level allocate, which takes care of memory details. nEntries may be zero, and in this case
-// no optimation curve is computed. nSegments may also be zero in the inverse case, where only the
-// optimization curve is given. Both features simultaneously is an error
-static
-cmsToneCurve* AllocateToneCurveStruct(cmsContext ContextID, cmsInt32Number nEntries,
-                                      cmsInt32Number nSegments, const cmsCurveSegment* Segments,
-                                      const cmsUInt16Number* Values)
-{
-    cmsToneCurve* p;
-    int i;
-
-    // We allow huge tables, which are then restricted for smoothing operations
-    if (nEntries > 65530 || nEntries < 0) {
-        cmsSignalError(ContextID, cmsERROR_RANGE, "Couldn't create tone curve of more than 65530 entries");
-        return NULL;
-    }
-
-    if (nEntries <= 0 && nSegments <= 0) {
-        cmsSignalError(ContextID, cmsERROR_RANGE, "Couldn't create tone curve with zero segments and no table");
-        return NULL;
-    }
-
-    // Allocate all required pointers, etc.
-    p = (cmsToneCurve*) _cmsMallocZero(ContextID, sizeof(cmsToneCurve));
-    if (!p) return NULL;
-
-    // In this case, there are no segments
-    if (nSegments <= 0) {
-        p ->Segments = NULL;
-        p ->Evals = NULL;
-    }
-    else {
-        p ->Segments = (cmsCurveSegment*) _cmsCalloc(ContextID, nSegments, sizeof(cmsCurveSegment));
-        if (p ->Segments == NULL) goto Error;
-
-        p ->Evals    = (cmsParametricCurveEvaluator*) _cmsCalloc(ContextID, nSegments, sizeof(cmsParametricCurveEvaluator));
-        if (p ->Evals == NULL) goto Error;
-    }
-
-    p -> nSegments = nSegments;
-
-    // This 16-bit table contains a limited precision representation of the whole curve and is kept for
-    // increasing xput on certain operations.
-    if (nEntries <= 0) {
-        p ->Table16 = NULL;
-    }
-    else {
-       p ->Table16 = (cmsUInt16Number*)  _cmsCalloc(ContextID, nEntries, sizeof(cmsUInt16Number));
-       if (p ->Table16 == NULL) goto Error;
-    }
-
-    p -> nEntries  = nEntries;
-
-    // Initialize members if requested
-    if (Values != NULL && (nEntries > 0)) {
-
-        for (i=0; i < nEntries; i++)
-            p ->Table16[i] = Values[i];
-    }
-
-    // Initialize the segments stuff. The evaluator for each segment is located and a pointer to it
-    // is placed in advance to maximize performance.
-    if (Segments != NULL && (nSegments > 0)) {
-
-        _cmsParametricCurvesCollection *c;
-
-        p ->SegInterp = (cmsInterpParams**) _cmsCalloc(ContextID, nSegments, sizeof(cmsInterpParams*));
-        if (p ->SegInterp == NULL) goto Error;
-
-        for (i=0; i< nSegments; i++) {
-
-            // Type 0 is a special marker for table-based curves
-            if (Segments[i].Type == 0)
-                p ->SegInterp[i] = _cmsComputeInterpParams(ContextID, Segments[i].nGridPoints, 1, 1, NULL, CMS_LERP_FLAGS_FLOAT);
-
-            memmove(&p ->Segments[i], &Segments[i], sizeof(cmsCurveSegment));
-
-            if (Segments[i].Type == 0 && Segments[i].SampledPoints != NULL)
-                p ->Segments[i].SampledPoints = (cmsFloat32Number*) _cmsDupMem(ContextID, Segments[i].SampledPoints, sizeof(cmsFloat32Number) * Segments[i].nGridPoints);
-            else
-                p ->Segments[i].SampledPoints = NULL;
-
-
-            c = GetParametricCurveByType(ContextID, Segments[i].Type, NULL);
-            if (c != NULL)
-                    p ->Evals[i] = c ->Evaluator;
-        }
-    }
-
-    p ->InterpParams = _cmsComputeInterpParams(ContextID, p ->nEntries, 1, 1, p->Table16, CMS_LERP_FLAGS_16BITS);
-    if (p->InterpParams != NULL)
-        return p;
-
-Error:
-    if (p -> Segments) _cmsFree(ContextID, p ->Segments);
-    if (p -> Evals) _cmsFree(ContextID, p -> Evals);
-    if (p ->Table16) _cmsFree(ContextID, p ->Table16);
-    _cmsFree(ContextID, p);
-    return NULL;
-}
-
-
-// Parametric Fn using floating point
-static
-cmsFloat64Number DefaultEvalParametricFn(cmsInt32Number Type, const cmsFloat64Number Params[], cmsFloat64Number R)
-{
-    cmsFloat64Number e, Val, disc;
-
-    switch (Type) {
-
-   // X = Y ^ Gamma
-    case 1:
-        if (R < 0) {
-
-            if (fabs(Params[0] - 1.0) < MATRIX_DET_TOLERANCE)
-                Val = R;
-            else
-                Val = 0;
-        }
-        else
-            Val = pow(R, Params[0]);
-        break;
-
-    // Type 1 Reversed: X = Y ^1/gamma
-    case -1:
-         if (R < 0) {
-
-            if (fabs(Params[0] - 1.0) < MATRIX_DET_TOLERANCE)
-                Val = R;
-            else
-                Val = 0;
-        }
-        else
-            Val = pow(R, 1/Params[0]);
-        break;
-
-    // CIE 122-1966
-    // Y = (aX + b)^Gamma  | X >= -b/a
-    // Y = 0               | else
-    case 2:
-        disc = -Params[2] / Params[1];
-
-        if (R >= disc ) {
-
-            e = Params[1]*R + Params[2];
-
-            if (e > 0)
-                Val = pow(e, Params[0]);
-            else
-                Val = 0;
-        }
-        else
-            Val = 0;
-        break;
-
-     // Type 2 Reversed
-     // X = (Y ^1/g  - b) / a
-     case -2:
-         if (R < 0)
-             Val = 0;
-         else
-             Val = (pow(R, 1.0/Params[0]) - Params[2]) / Params[1];
-
-         if (Val < 0)
-              Val = 0;
-         break;
-
-
-    // IEC 61966-3
-    // Y = (aX + b)^Gamma | X <= -b/a
-    // Y = c              | else
-    case 3:
-        disc = -Params[2] / Params[1];
-        if (disc < 0)
-            disc = 0;
-
-        if (R >= disc) {
-
-            e = Params[1]*R + Params[2];
-
-            if (e > 0)
-                Val = pow(e, Params[0]) + Params[3];
-            else
-                Val = 0;
-        }
-        else
-            Val = Params[3];
-        break;
-
-
-    // Type 3 reversed
-    // X=((Y-c)^1/g - b)/a      | (Y>=c)
-    // X=-b/a                   | (Y<c)
-    case -3:
-        if (R >= Params[3])  {
-
-            e = R - Params[3];
-
-            if (e > 0)
-                Val = (pow(e, 1/Params[0]) - Params[2]) / Params[1];
-            else
-                Val = 0;
-        }
-        else {
-            Val = -Params[2] / Params[1];
-        }
-        break;
-
-
-    // IEC 61966-2.1 (sRGB)
-    // Y = (aX + b)^Gamma | X >= d
-    // Y = cX             | X < d
-    case 4:
-        if (R >= Params[4]) {
-
-            e = Params[1]*R + Params[2];
-
-            if (e > 0)
-                Val = pow(e, Params[0]);
-            else
-                Val = 0;
-        }
-        else
-            Val = R * Params[3];
-        break;
-
-    // Type 4 reversed
-    // X=((Y^1/g-b)/a)    | Y >= (ad+b)^g
-    // X=Y/c              | Y< (ad+b)^g
-    case -4:
-        e = Params[1] * Params[4] + Params[2];
-        if (e < 0)
-            disc = 0;
-        else
-            disc = pow(e, Params[0]);
-
-        if (R >= disc) {
-
-            Val = (pow(R, 1.0/Params[0]) - Params[2]) / Params[1];
-        }
-        else {
-            Val = R / Params[3];
-        }
-        break;
-
-
-    // Y = (aX + b)^Gamma + e | X >= d
-    // Y = cX + f             | X < d
-    case 5:
-        if (R >= Params[4]) {
-
-            e = Params[1]*R + Params[2];
-
-            if (e > 0)
-                Val = pow(e, Params[0]) + Params[5];
-            else
-                Val = Params[5];
-        }
-        else
-            Val = R*Params[3] + Params[6];
-        break;
-
-
-    // Reversed type 5
-    // X=((Y-e)1/g-b)/a   | Y >=(ad+b)^g+e), cd+f
-    // X=(Y-f)/c          | else
-    case -5:
-
-        disc = Params[3] * Params[4] + Params[6];
-        if (R >= disc) {
-
-            e = R - Params[5];
-            if (e < 0)
-                Val = 0;
-            else
-                Val = (pow(e, 1.0/Params[0]) - Params[2]) / Params[1];
-        }
-        else {
-            Val = (R - Params[6]) / Params[3];
-        }
-        break;
-
-
-    // Types 6,7,8 comes from segmented curves as described in ICCSpecRevision_02_11_06_Float.pdf
-    // Type 6 is basically identical to type 5 without d
-
-    // Y = (a * X + b) ^ Gamma + c
-    case 6:
-        e = Params[1]*R + Params[2];
-
-        if (e < 0)
-            Val = Params[3];
-        else
-            Val = pow(e, Params[0]) + Params[3];
-        break;
-
-    // ((Y - c) ^1/Gamma - b) / a
-    case -6:
-        e = R - Params[3];
-        if (e < 0)
-            Val = 0;
-        else
-        Val = (pow(e, 1.0/Params[0]) - Params[2]) / Params[1];
-        break;
-
-
-    // Y = a * log (b * X^Gamma + c) + d
-    case 7:
-
-       e = Params[2] * pow(R, Params[0]) + Params[3];
-       if (e <= 0)
-           Val = Params[4];
-       else
-           Val = Params[1]*log10(e) + Params[4];
-       break;
-
-    // (Y - d) / a = log(b * X ^Gamma + c)
-    // pow(10, (Y-d) / a) = b * X ^Gamma + c
-    // pow((pow(10, (Y-d) / a) - c) / b, 1/g) = X
-    case -7:
-       Val = pow((pow(10.0, (R-Params[4]) / Params[1]) - Params[3]) / Params[2], 1.0 / Params[0]);
-       break;
-
-
-   //Y = a * b^(c*X+d) + e
-   case 8:
-       Val = (Params[0] * pow(Params[1], Params[2] * R + Params[3]) + Params[4]);
-       break;
-
-
-   // Y = (log((y-e) / a) / log(b) - d ) / c
-   // a=0, b=1, c=2, d=3, e=4,
-   case -8:
-
-       disc = R - Params[4];
-       if (disc < 0) Val = 0;
-       else
-           Val = (log(disc / Params[0]) / log(Params[1]) - Params[3]) / Params[2];
-       break;
-
-   // S-Shaped: (1 - (1-x)^1/g)^1/g
-   case 108:
-      Val = pow(1.0 - pow(1 - R, 1/Params[0]), 1/Params[0]);
-      break;
-
-    // y = (1 - (1-x)^1/g)^1/g
-    // y^g = (1 - (1-x)^1/g)
-    // 1 - y^g = (1-x)^1/g
-    // (1 - y^g)^g = 1 - x
-    // 1 - (1 - y^g)^g
-    case -108:
-        Val = 1 - pow(1 - pow(R, Params[0]), Params[0]);
-        break;
-
-    default:
-        // Unsupported parametric curve. Should never reach here
-        return 0;
-    }
-
-    return Val;
-}
-
-// Evaluate a segmented funtion for a single value. Return -1 if no valid segment found .
-// If fn type is 0, perform an interpolation on the table
-static
-cmsFloat64Number EvalSegmentedFn(const cmsToneCurve *g, cmsFloat64Number R)
-{
-    int i;
-
-    for (i = g ->nSegments-1; i >= 0 ; --i) {
-
-        // Check for domain
-        if ((R > g ->Segments[i].x0) && (R <= g ->Segments[i].x1)) {
-
-            // Type == 0 means segment is sampled
-            if (g ->Segments[i].Type == 0) {
-
-                cmsFloat32Number R1 = (cmsFloat32Number) (R - g ->Segments[i].x0) / (g ->Segments[i].x1 - g ->Segments[i].x0);
-                cmsFloat32Number Out;
-
-                // Setup the table (TODO: clean that)
-                g ->SegInterp[i]-> Table = g ->Segments[i].SampledPoints;
-
-                g ->SegInterp[i] -> Interpolation.LerpFloat(&R1, &Out, g ->SegInterp[i]);
-
-                return Out;
-            }
-            else
-                return g ->Evals[i](g->Segments[i].Type, g ->Segments[i].Params, R);
-        }
-    }
-
-    return MINUS_INF;
-}
-
-// Access to estimated low-res table
-cmsUInt32Number CMSEXPORT cmsGetToneCurveEstimatedTableEntries(const cmsToneCurve* t)
-{
-    _cmsAssert(t != NULL);
-    return t ->nEntries;
-}
-
-const cmsUInt16Number* CMSEXPORT cmsGetToneCurveEstimatedTable(const cmsToneCurve* t)
-{
-    _cmsAssert(t != NULL);
-    return t ->Table16;
-}
-
-
-// Create an empty gamma curve, by using tables. This specifies only the limited-precision part, and leaves the
-// floating point description empty.
-cmsToneCurve* CMSEXPORT cmsBuildTabulatedToneCurve16(cmsContext ContextID, cmsInt32Number nEntries, const cmsUInt16Number Values[])
-{
-    return AllocateToneCurveStruct(ContextID, nEntries, 0, NULL, Values);
-}
-
-static
-int EntriesByGamma(cmsFloat64Number Gamma)
-{
-    if (fabs(Gamma - 1.0) < 0.001) return 2;
-    return 4096;
-}
-
-
-// Create a segmented gamma, fill the table
-cmsToneCurve* CMSEXPORT cmsBuildSegmentedToneCurve(cmsContext ContextID,
-                                                   cmsInt32Number nSegments, const cmsCurveSegment Segments[])
-{
-    int i;
-    cmsFloat64Number R, Val;
-    cmsToneCurve* g;
-    int nGridPoints = 4096;
-
-    _cmsAssert(Segments != NULL);
-
-    // Optimizatin for identity curves.
-    if (nSegments == 1 && Segments[0].Type == 1) {
-
-        nGridPoints = EntriesByGamma(Segments[0].Params[0]);
-    }
-
-    g = AllocateToneCurveStruct(ContextID, nGridPoints, nSegments, Segments, NULL);
-    if (g == NULL) return NULL;
-
-    // Once we have the floating point version, we can approximate a 16 bit table of 4096 entries
-    // for performance reasons. This table would normally not be used except on 8/16 bits transforms.
-    for (i=0; i < nGridPoints; i++) {
-
-        R   = (cmsFloat64Number) i / (nGridPoints-1);
-
-        Val = EvalSegmentedFn(g, R);
-
-        // Round and saturate
-        g ->Table16[i] = _cmsQuickSaturateWord(Val * 65535.0);
-    }
-
-    return g;
-}
-
-// Use a segmented curve to store the floating point table
-cmsToneCurve* CMSEXPORT cmsBuildTabulatedToneCurveFloat(cmsContext ContextID, cmsUInt32Number nEntries, const cmsFloat32Number values[])
-{
-    cmsCurveSegment Seg[3];
-
-    // A segmented tone curve should have function segments in the first and last positions
-    // Initialize segmented curve part up to 0 to constant value = samples[0]
-    Seg[0].x0 = MINUS_INF;
-    Seg[0].x1 = 0;
-    Seg[0].Type = 6;
-
-    Seg[0].Params[0] = 1;
-    Seg[0].Params[1] = 0;
-    Seg[0].Params[2] = 0;
-    Seg[0].Params[3] = values[0];
-    Seg[0].Params[4] = 0;
-
-    // From zero to 1
-    Seg[1].x0 = 0;
-    Seg[1].x1 = 1.0;
-    Seg[1].Type = 0;
-
-    Seg[1].nGridPoints = nEntries;
-    Seg[1].SampledPoints = (cmsFloat32Number*) values;
-
-    // Final segment is constant = lastsample
-    Seg[2].x0 = 1.0;
-    Seg[2].x1 = PLUS_INF;
-    Seg[2].Type = 6;
-    
-    Seg[2].Params[0] = 1;
-    Seg[2].Params[1] = 0;
-    Seg[2].Params[2] = 0;
-    Seg[2].Params[3] = values[nEntries-1];
-    Seg[2].Params[4] = 0;
-    
-
-    return cmsBuildSegmentedToneCurve(ContextID, 3, Seg);
-}
-
-// Parametric curves
-//
-// Parameters goes as: Curve, a, b, c, d, e, f
-// Type is the ICC type +1
-// if type is negative, then the curve is analyticaly inverted
-cmsToneCurve* CMSEXPORT cmsBuildParametricToneCurve(cmsContext ContextID, cmsInt32Number Type, const cmsFloat64Number Params[])
-{
-    cmsCurveSegment Seg0;
-    int Pos = 0;
-    cmsUInt32Number size;
-    _cmsParametricCurvesCollection* c = GetParametricCurveByType(ContextID, Type, &Pos);
-
-    _cmsAssert(Params != NULL);
-
-    if (c == NULL) {
-        cmsSignalError(ContextID, cmsERROR_UNKNOWN_EXTENSION, "Invalid parametric curve type %d", Type);
-        return NULL;
-    }
-
-    memset(&Seg0, 0, sizeof(Seg0));
-
-    Seg0.x0   = MINUS_INF;
-    Seg0.x1   = PLUS_INF;
-    Seg0.Type = Type;
-
-    size = c->ParameterCount[Pos] * sizeof(cmsFloat64Number);
-    memmove(Seg0.Params, Params, size);
-
-    return cmsBuildSegmentedToneCurve(ContextID, 1, &Seg0);
-}
-
-
-
-// Build a gamma table based on gamma constant
-cmsToneCurve* CMSEXPORT cmsBuildGamma(cmsContext ContextID, cmsFloat64Number Gamma)
-{
-    return cmsBuildParametricToneCurve(ContextID, 1, &Gamma);
-}
-
-
-// Free all memory taken by the gamma curve
-void CMSEXPORT cmsFreeToneCurve(cmsToneCurve* Curve)
-{
-    cmsContext ContextID;
-
-       // added by Xiaochuan Liu
-       // Curve->InterpParams may be null
-    if (Curve == NULL || Curve->InterpParams == NULL) return;
-
-    ContextID = Curve ->InterpParams->ContextID;
-
-    _cmsFreeInterpParams(Curve ->InterpParams);
-       Curve ->InterpParams = NULL;
-
-    if (Curve -> Table16)
-       {
-        _cmsFree(ContextID, Curve ->Table16);
-               Curve ->Table16 = NULL;
-       }
-
-    if (Curve ->Segments) {
-
-        cmsUInt32Number i;
-
-        for (i=0; i < Curve ->nSegments; i++) {
-
-            if (Curve ->Segments[i].SampledPoints) {
-                _cmsFree(ContextID, Curve ->Segments[i].SampledPoints);
-                               Curve ->Segments[i].SampledPoints = NULL;
-            }
-
-            if (Curve ->SegInterp[i] != 0)
-                       {
-                _cmsFreeInterpParams(Curve->SegInterp[i]);
-                               Curve->SegInterp[i] = NULL;
-                       }
-        }
-
-        _cmsFree(ContextID, Curve ->Segments);
-               Curve ->Segments = NULL;
-        _cmsFree(ContextID, Curve ->SegInterp);
-               Curve ->SegInterp = NULL;
-    }
-
-    if (Curve -> Evals)
-       {
-        _cmsFree(ContextID, Curve -> Evals);
-               Curve -> Evals = NULL;
-       }
-
-    if (Curve)
-       {
-               _cmsFree(ContextID, Curve);
-               Curve = NULL;
-