Imported Upstream version 2.4 upstream/2.4
authorAnas Nashif <anas.nashif@intel.com>
Thu, 21 Feb 2013 03:04:12 +0000 (19:04 -0800)
committerAnas Nashif <anas.nashif@intel.com>
Thu, 21 Feb 2013 03:04:12 +0000 (19:04 -0800)
84 files changed:
AUTHORS
ChangeLog
Makefile.in
Projects/.gitignore [new file with mode: 0644]
Projects/BorlandC_5.5/lcms2.rc
Projects/BorlandC_5.5/lcmsdll.lk
Projects/BorlandC_5.5/lcmsdll.lst
Projects/VC2008/lcms2_DLL/lcms2_DLL.vcproj
Projects/VC2008/lcms2_static/lcms2_static.vcproj
Projects/VC2010/jpegicc/jpegicc.vcxproj
Projects/VC2010/lcms2.sln
Projects/VC2010/lcms2_DLL/lcms2_DLL.vcxproj
Projects/VC2010/lcms2_DLL/lcms2_DLL.vcxproj.filters
Projects/VC2010/lcms2_static/lcms2_static.vcxproj
Projects/VC2010/lcms2_static/lcms2_static.vcxproj.filters
Projects/VC2010/linkicc/linkicc.vcxproj
Projects/VC2010/psicc/psicc.vcxproj
Projects/VC2010/testbed/testbed.vcxproj
Projects/VC2010/tiffdiff/tiffdiff.vcxproj
Projects/VC2010/tifficc/tifficc.vcxproj
Projects/VC2010/transicc/transicc.vcxproj
Projects/mac/._.DS_Store
Projects/mac/LittleCMS/._.DS_Store
Projects/mac/LittleCMS/Info.plist
Projects/mac/LittleCMS/LittleCMS.xcodeproj/mariama.mode1v3
Projects/mac/LittleCMS/LittleCMS.xcodeproj/mariama.pbxuser
Projects/mac/LittleCMS/LittleCMS.xcodeproj/project.pbxproj
aclocal.m4
configure
configure.ac
doc/LittleCMS2.3 API.pdf [deleted file]
doc/LittleCMS2.3 Plugin API.pdf [deleted file]
doc/LittleCMS2.3 tutorial.pdf [deleted file]
doc/LittleCMS2.4 API.pdf [new file with mode: 0755]
doc/LittleCMS2.4 Plugin API.pdf [new file with mode: 0755]
doc/LittleCMS2.4 tutorial.pdf [new file with mode: 0755]
include/Makefile.in
include/lcms2.h
include/lcms2_plugin.h
src/Makefile.am
src/Makefile.in
src/cmscam02.c
src/cmscgats.c
src/cmscnvrt.c
src/cmserr.c
src/cmsgamma.c
src/cmsgmt.c
src/cmshalf.c [new file with mode: 0755]
src/cmsintrp.c
src/cmsio0.c
src/cmsio1.c
src/cmslut.c
src/cmsmd5.c
src/cmsmtrx.c
src/cmsnamed.c
src/cmsopt.c
src/cmspack.c
src/cmspcs.c
src/cmsplugin.c
src/cmsps2.c
src/cmssamp.c
src/cmssm.c
src/cmstypes.c
src/cmsvirt.c
src/cmswtpnt.c
src/cmsxform.c
src/lcms2.def
src/lcms2_internal.h
testbed/Makefile.am
testbed/Makefile.in
testbed/testcms2.c
utils/common/utils.h
utils/common/vprf.c
utils/common/xgetopt.c
utils/delphi/lcms2.dll [deleted file]
utils/delphi/lcms2dll.pas
utils/jpgicc/Makefile.in
utils/jpgicc/jpgicc.c
utils/linkicc/Makefile.in
utils/psicc/Makefile.in
utils/tificc/Makefile.in
utils/tificc/tificc.c
utils/transicc/Makefile.in
utils/transicc/transicc.c

diff --git a/AUTHORS b/AUTHORS
index ffac189..86a771d 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -12,14 +12,20 @@ Stuart Nixon
 Jordi Vilar
 Richard Hughes
 Auke Nauta
-Chris Evans
+Chris Evans (Google)
 Lorenzo Ridolfi 
-Robin Watts
+Robin Watts (Artifex)
 Shawn Pedersen 
 Andrew Brygin 
 Samuli Suominen 
 Florian Höch
 Aurelien Jarno 
+Claudiu Cebuc
+Michael Vhrel (Artifex)
+Michal Cihar 
+Daniel Kaneider 
+Mateusz Jurczyk (Google)
+Paul Miller
 
 Special Thanks 
 --------------
@@ -28,3 +34,5 @@ Jos Vernon (WebSupergoo)
 Harald Schneider (Maxon)
 Christian Albrecht 
 Dimitrios Anastassakis 
+Lemke Software 
+Tim Zaman
\ No newline at end of file
index b71c278..9395d82 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -51,4 +51,38 @@ Fixed encoding for floating point tags in Lab/XYZ
 Fixed Absolute colorimetric intent issues
 Fixed a bug on the range of data in transicc, when colorant tag is specified
 Adding a memory alignment macro for CGATS parser
-Updated to ICC spec 4.3
\ No newline at end of file
+Updated to ICC spec 4.3
+Added compatibilty with Argyll's CGATS parser
+
+2.3 Maintenance release
+-----------------------
+
+Fixed a bug in the named color devicelink generation
+Fixed uint64 to work in systems without long long native type
+Added performance improvements from several contributors, mostly Artifex
+Fixed a bug in black preservation checking
+Added black point detection algorithm from Adobe paper
+Added support for transforms on planar data with different stride
+Added a new plug in entry for full transform
+Exposed internal overview table for tone curves
+gamma 1.0 can now operate in unbounded mode
+Fixed a bug in pipeline duplication
+Added getPipelineContextID
+Added a new plug-in type
+Internal stage structs are now accessible through plug-in API
+Fixed a bug on ending zero when saving a IT8 to memory
+Fixed a bug on IT8 reading of negative numbers.
+Increased security checks, thanks to Mateusz Jurczyk, from Google.
+Added half float support
+Fixed a typo on tificc and jpgicc names, thanks to Elle Stone for reporting.
+Fixed a bug on named color profiles.
+Added a conditional compilatio flag for "half" support
+Fixed a bug in transicc when clot tables are present
+Added formatter resolution after xform optimization plugin
+added half float variants (ABGR and so)
+Fixed a bug in XYZ floating point PCS
+Fixed an unitialized read on PatchLUT
+Added a check for maximum input channels
+
+2.4 Featured release
+--------------------
index 2cab7a5..f8d008d 100644 (file)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.3 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -82,6 +82,12 @@ am__nobase_list = $(am__nobase_strip_setup); \
 am__base_list = \
   sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
   sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__uninstall_files_from_dir = { \
+  test -z "$$files" \
+    || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
+    || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
+         $(am__cd) "$$dir" && rm -f $$files; }; \
+  }
 am__installdirs = "$(DESTDIR)$(pkgconfigdir)"
 DATA = $(pkgconfig_DATA)
 RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive        \
@@ -96,9 +102,11 @@ DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 distdir = $(PACKAGE)-$(VERSION)
 top_distdir = $(distdir)
 am__remove_distdir = \
-  { test ! -d "$(distdir)" \
-    || { find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \
-         && rm -fr "$(distdir)"; }; }
+  if test -d "$(distdir)"; then \
+    find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \
+      && rm -rf "$(distdir)" \
+      || { sleep 5 && rm -rf "$(distdir)"; }; \
+  else :; fi
 am__relativize = \
   dir0=`pwd`; \
   sed_first='s,^\([^/]*\)/.*$$,\1,'; \
@@ -127,6 +135,8 @@ am__relativize = \
 DIST_ARCHIVES = $(distdir).tar.gz $(distdir).zip
 GZIP_ENV = --best
 distuninstallcheck_listfiles = find . -type f -print
+am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \
+  | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$'
 distcleancheck_listfiles = find . -type f -print
 ACLOCAL = @ACLOCAL@
 AMTAR = @AMTAR@
@@ -274,7 +284,7 @@ pkgconfig_DATA = lcms2.pc
 all: all-recursive
 
 .SUFFIXES:
-am--refresh:
+am--refresh: Makefile
        @:
 $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
        @for dep in $?; do \
@@ -336,9 +346,7 @@ uninstall-pkgconfigDATA:
        @$(NORMAL_UNINSTALL)
        @list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \
        files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
-       test -n "$$files" || exit 0; \
-       echo " ( cd '$(DESTDIR)$(pkgconfigdir)' && rm -f" $$files ")"; \
-       cd "$(DESTDIR)$(pkgconfigdir)" && rm -f $$files
+       dir='$(DESTDIR)$(pkgconfigdir)'; $(am__uninstall_files_from_dir)
 
 # This directory's subdirectories are mostly independent; you can cd
 # into them and run `make' without going through this Makefile.
@@ -547,7 +555,11 @@ dist-gzip: distdir
        $(am__remove_distdir)
 
 dist-bzip2: distdir
-       tardir=$(distdir) && $(am__tar) | bzip2 -9 -c >$(distdir).tar.bz2
+       tardir=$(distdir) && $(am__tar) | BZIP2=$${BZIP2--9} bzip2 -c >$(distdir).tar.bz2
+       $(am__remove_distdir)
+
+dist-lzip: distdir
+       tardir=$(distdir) && $(am__tar) | lzip -c $${LZIP_OPT--9} >$(distdir).tar.lz
        $(am__remove_distdir)
 
 dist-lzma: distdir
@@ -555,7 +567,7 @@ dist-lzma: distdir
        $(am__remove_distdir)
 
 dist-xz: distdir
-       tardir=$(distdir) && $(am__tar) | xz -c >$(distdir).tar.xz
+       tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz
        $(am__remove_distdir)
 
 dist-tarZ: distdir
@@ -587,6 +599,8 @@ distcheck: dist
          bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\
        *.tar.lzma*) \
          lzma -dc $(distdir).tar.lzma | $(am__untar) ;;\
+       *.tar.lz*) \
+         lzip -dc $(distdir).tar.lz | $(am__untar) ;;\
        *.tar.xz*) \
          xz -dc $(distdir).tar.xz | $(am__untar) ;;\
        *.tar.Z*) \
@@ -606,6 +620,7 @@ distcheck: dist
          && am__cwd=`pwd` \
          && $(am__cd) $(distdir)/_build \
          && ../configure --srcdir=.. --prefix="$$dc_install_base" \
+           $(AM_DISTCHECK_CONFIGURE_FLAGS) \
            $(DISTCHECK_CONFIGURE_FLAGS) \
          && $(MAKE) $(AM_MAKEFLAGS) \
          && $(MAKE) $(AM_MAKEFLAGS) dvi \
@@ -634,8 +649,16 @@ distcheck: dist
          list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \
          sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x'
 distuninstallcheck:
-       @$(am__cd) '$(distuninstallcheck_dir)' \
-       && test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \
+       @test -n '$(distuninstallcheck_dir)' || { \
+         echo 'ERROR: trying to run $@ with an empty' \
+              '$$(distuninstallcheck_dir)' >&2; \
+         exit 1; \
+       }; \
+       $(am__cd) '$(distuninstallcheck_dir)' || { \
+         echo 'ERROR: cannot chdir into $(distuninstallcheck_dir)' >&2; \
+         exit 1; \
+       }; \
+       test `$(am__distuninstallcheck_listfiles) | wc -l` -eq 0 \
           || { echo "ERROR: files left after uninstall:" ; \
                if test -n "$(DESTDIR)"; then \
                  echo "  (check DESTDIR support)"; \
@@ -669,10 +692,15 @@ install-am: all-am
 
 installcheck: installcheck-recursive
 install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-         install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-         `test -z '$(STRIP)' || \
-           echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
 mostlyclean-generic:
 
 clean-generic:
@@ -760,8 +788,8 @@ uninstall-am: uninstall-pkgconfigDATA
 .PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
        all all-am am--refresh check check-am clean clean-generic \
        clean-libtool clean-local ctags ctags-recursive dist dist-all \
-       dist-bzip2 dist-gzip dist-lzma dist-shar dist-tarZ dist-xz \
-       dist-zip distcheck distclean distclean-generic \
+       dist-bzip2 dist-gzip dist-lzip dist-lzma dist-shar dist-tarZ \
+       dist-xz dist-zip distcheck distclean distclean-generic \
        distclean-libtool distclean-tags distcleancheck distdir \
        distuninstallcheck dvi dvi-am html html-am info info-am \
        install install-am install-data install-data-am install-dvi \
diff --git a/Projects/.gitignore b/Projects/.gitignore
new file mode 100644 (file)
index 0000000..1b81b17
--- /dev/null
@@ -0,0 +1,3 @@
+**.suo
+**.sdf
+**.user
\ No newline at end of file
index c5e9299..18432c2 100644 (file)
@@ -1,8 +1,8 @@
 
 
 1 VERSIONINFO
-FILEVERSION 2, 3, 0, 0
-PRODUCTVERSION 2, 3, 0, 0
+FILEVERSION 2, 4, 0, 0
+PRODUCTVERSION 2, 4, 0, 0
 FILEOS VOS_NT_WINDOWS32
 FILETYPE VFT_DLL
 {
@@ -12,9 +12,9 @@ FILETYPE VFT_DLL
   {
    VALUE "CompanyName", "Marti Maria\000\000"
    VALUE "FileDescription", "lcms color engine\000"
-   VALUE "FileVersion", "2.03\000\000"
+   VALUE "FileVersion", "2.04\000\000"
    VALUE "InternalName", "lcms2\000"
-   VALUE "LegalCopyright", "Copyright Â© Marti Maria 2011\000\000"
+   VALUE "LegalCopyright", "Copyright Â© Marti Maria 2012\000\000"
    VALUE "OriginalFilename", "lcms2.dll\000"
   }
 
index ceb5726..de478f4 100644 (file)
@@ -5,6 +5,7 @@ cmscnvrt.obj+
 cmserr.obj+
 cmsgamma.obj+
 cmsgmt.obj+
+cmshalf.obj+
 cmsintrp.obj+
 cmsio0.obj+
 cmsio1.obj+
index 87ce458..b5bd821 100644 (file)
@@ -25,3 +25,4 @@
 ..\..\src\cmsvirt.c
 ..\..\src\cmswtpnt.c
 ..\..\src\cmsxform.c
+..\..\src\cmshalf.c
index b3f9f25..28cb7e2 100644 (file)
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioProject
-       ProjectType="Visual C++"
-       Version="9.00"
-       Name="lcms2_DLL"
-       ProjectGUID="{8C51BE48-ADB8-4089-A9EC-F6BF993A0548}"
-       RootNamespace="lcms2_DLL"
-       Keyword="Win32Proj"
-       TargetFrameworkVersion="196613"
-       >
-       <Platforms>
-               <Platform
-                       Name="Win32"
-               />
-       </Platforms>
-       <ToolFiles>
-       </ToolFiles>
-       <Configurations>
-               <Configuration
-                       Name="Debug|Win32"
-                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
-                       IntermediateDirectory="$(ConfigurationName)"
-                       ConfigurationType="2"
-                       CharacterSet="1"
-                       >
-                       <Tool
-                               Name="VCPreBuildEventTool"
-                       />
-                       <Tool
-                               Name="VCCustomBuildTool"
-                       />
-                       <Tool
-                               Name="VCXMLDataGeneratorTool"
-                       />
-                       <Tool
-                               Name="VCWebServiceProxyGeneratorTool"
-                       />
-                       <Tool
-                               Name="VCMIDLTool"
-                       />
-                       <Tool
-                               Name="VCCLCompilerTool"
-                               Optimization="0"
-                               AdditionalIncludeDirectories="../../../include"
-                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;CMS_DLL_BUILD;_CRT_SECURE_NO_WARNINGS"
-                               MinimalRebuild="true"
-                               BasicRuntimeChecks="3"
-                               RuntimeLibrary="3"
-                               UsePrecompiledHeader="0"
-                               WarningLevel="3"
-                               DebugInformationFormat="4"
-                       />
-                       <Tool
-                               Name="VCManagedResourceCompilerTool"
-                       />
-                       <Tool
-                               Name="VCResourceCompilerTool"
-                       />
-                       <Tool
-                               Name="VCPreLinkEventTool"
-                       />
-                       <Tool
-                               Name="VCLinkerTool"
-                               OutputFile="../../../bin/lcms2d.dll"
-                               LinkIncremental="2"
-                               ModuleDefinitionFile="..\..\..\src\lcms2.def"
-                               GenerateDebugInformation="true"
-                               SubSystem="2"
-                               TargetMachine="1"
-                       />
-                       <Tool
-                               Name="VCALinkTool"
-                       />
-                       <Tool
-                               Name="VCManifestTool"
-                       />
-                       <Tool
-                               Name="VCXDCMakeTool"
-                       />
-                       <Tool
-                               Name="VCBscMakeTool"
-                       />
-                       <Tool
-                               Name="VCFxCopTool"
-                       />
-                       <Tool
-                               Name="VCAppVerifierTool"
-                       />
-                       <Tool
-                               Name="VCPostBuildEventTool"
-                       />
-               </Configuration>
-               <Configuration
-                       Name="Release|Win32"
-                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
-                       IntermediateDirectory="$(ConfigurationName)"
-                       ConfigurationType="2"
-                       CharacterSet="1"
-                       WholeProgramOptimization="1"
-                       >
-                       <Tool
-                               Name="VCPreBuildEventTool"
-                       />
-                       <Tool
-                               Name="VCCustomBuildTool"
-                       />
-                       <Tool
-                               Name="VCXMLDataGeneratorTool"
-                       />
-                       <Tool
-                               Name="VCWebServiceProxyGeneratorTool"
-                       />
-                       <Tool
-                               Name="VCMIDLTool"
-                       />
-                       <Tool
-                               Name="VCCLCompilerTool"
-                               Optimization="2"
-                               EnableIntrinsicFunctions="true"
-                               FavorSizeOrSpeed="1"
-                               OmitFramePointers="true"
-                               EnableFiberSafeOptimizations="true"
-                               WholeProgramOptimization="true"
-                               AdditionalIncludeDirectories="../../../include"
-                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;CMS_DLL_BUILD;_CRT_SECURE_NO_WARNINGS"
-                               RuntimeLibrary="2"
-                               EnableFunctionLevelLinking="true"
-                               UsePrecompiledHeader="0"
-                               WarningLevel="4"
-                               DebugInformationFormat="3"
-                       />
-                       <Tool
-                               Name="VCManagedResourceCompilerTool"
-                       />
-                       <Tool
-                               Name="VCResourceCompilerTool"
-                       />
-                       <Tool
-                               Name="VCPreLinkEventTool"
-                       />
-                       <Tool
-                               Name="VCLinkerTool"
-                               OutputFile="../../../bin/lcms2.dll"
-                               LinkIncremental="1"
-                               ModuleDefinitionFile="..\..\..\src\lcms2.def"
-                               GenerateDebugInformation="true"
-                               SubSystem="2"
-                               OptimizeReferences="2"
-                               EnableCOMDATFolding="2"
-                               TargetMachine="1"
-                       />
-                       <Tool
-                               Name="VCALinkTool"
-                       />
-                       <Tool
-                               Name="VCManifestTool"
-                       />
-                       <Tool
-                               Name="VCXDCMakeTool"
-                       />
-                       <Tool
-                               Name="VCBscMakeTool"
-                       />
-                       <Tool
-                               Name="VCFxCopTool"
-                       />
-                       <Tool
-                               Name="VCAppVerifierTool"
-                       />
-                       <Tool
-                               Name="VCPostBuildEventTool"
-                       />
-               </Configuration>
-       </Configurations>
-       <References>
-       </References>
-       <Files>
-               <Filter
-                       Name="Source Files"
-                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
-                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
-                       >
-                       <File
-                               RelativePath="..\..\..\src\cmscam02.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmscgats.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmscnvrt.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmserr.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsgamma.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsgmt.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsintrp.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsio0.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsio1.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmslut.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsmd5.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsmtrx.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsnamed.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsopt.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmspack.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmspcs.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsplugin.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsps2.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmssamp.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmssm.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmstypes.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsvirt.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmswtpnt.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsxform.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\lcms2.def"
-                               >
-                               <FileConfiguration
-                                       Name="Release|Win32"
-                                       >
-                                       <Tool
-                                               Name="VCCustomBuildTool"
-                                       />
-                               </FileConfiguration>
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\lcms2_internal.h"
-                               >
-                       </File>
-               </Filter>
-               <Filter
-                       Name="Header Files"
-                       Filter="h;hpp;hxx;hm;inl;inc;xsd"
-                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
-                       >
-                       <File
-                               RelativePath="..\..\..\include\lcms2.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\include\lcms2_plugin.h"
-                               >
-                       </File>
-               </Filter>
-               <Filter
-                       Name="Resource Files"
-                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
-                       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
-                       >
-                       <File
-                               RelativePath="..\lcms2.rc"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\resource.h"
-                               >
-                       </File>
-               </Filter>
-       </Files>
-       <Globals>
-       </Globals>
-</VisualStudioProject>
+<?xml version="1.0" encoding="Windows-1252"?>\r
+<VisualStudioProject\r
+       ProjectType="Visual C++"\r
+       Version="9.00"\r
+       Name="lcms2_DLL"\r
+       ProjectGUID="{8C51BE48-ADB8-4089-A9EC-F6BF993A0548}"\r
+       RootNamespace="lcms2_DLL"\r
+       Keyword="Win32Proj"\r
+       TargetFrameworkVersion="196613"\r
+       >\r
+       <Platforms>\r
+               <Platform\r
+                       Name="Win32"\r
+               />\r
+       </Platforms>\r
+       <ToolFiles>\r
+       </ToolFiles>\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
+                       IntermediateDirectory="$(ConfigurationName)"\r
+                       ConfigurationType="2"\r
+                       CharacterSet="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               AdditionalIncludeDirectories="../../../include"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;CMS_DLL_BUILD;_CRT_SECURE_NO_WARNINGS"\r
+                               MinimalRebuild="true"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="3"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               DebugInformationFormat="4"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               OutputFile="../../../bin/lcms2d.dll"\r
+                               LinkIncremental="2"\r
+                               ModuleDefinitionFile="..\..\..\src\lcms2.def"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="2"\r
+                               TargetMachine="1"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
+                       IntermediateDirectory="$(ConfigurationName)"\r
+                       ConfigurationType="2"\r
+                       CharacterSet="1"\r
+                       WholeProgramOptimization="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="2"\r
+                               EnableIntrinsicFunctions="true"\r
+                               FavorSizeOrSpeed="1"\r
+                               OmitFramePointers="true"\r
+                               EnableFiberSafeOptimizations="true"\r
+                               WholeProgramOptimization="true"\r
+                               AdditionalIncludeDirectories="../../../include"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;CMS_DLL_BUILD;_CRT_SECURE_NO_WARNINGS"\r
+                               RuntimeLibrary="2"\r
+                               EnableFunctionLevelLinking="true"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="4"\r
+                               DebugInformationFormat="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               OutputFile="../../../bin/lcms2.dll"\r
+                               LinkIncremental="1"\r
+                               ModuleDefinitionFile="..\..\..\src\lcms2.def"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="2"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               TargetMachine="1"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+       </Configurations>\r
+       <References>\r
+       </References>\r
+       <Files>\r
+               <Filter\r
+                       Name="Source Files"\r
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"\r
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"\r
+                       >\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmscam02.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmscgats.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmscnvrt.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmserr.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsgamma.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsgmt.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmshalf.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsintrp.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsio0.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsio1.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmslut.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsmd5.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsmtrx.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsnamed.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsopt.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmspack.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmspcs.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsplugin.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsps2.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmssamp.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmssm.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmstypes.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsvirt.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmswtpnt.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsxform.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\lcms2.def"\r
+                               >\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32"\r
+                                       >\r
+                                       <Tool\r
+                                               Name="VCCustomBuildTool"\r
+                                       />\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\lcms2_internal.h"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Header Files"\r
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"\r
+                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"\r
+                       >\r
+                       <File\r
+                               RelativePath="..\..\..\include\lcms2.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\include\lcms2_plugin.h"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Resource Files"\r
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"\r
+                       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"\r
+                       >\r
+                       <File\r
+                               RelativePath="..\lcms2.rc"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\resource.h"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
+       </Files>\r
+       <Globals>\r
+       </Globals>\r
+</VisualStudioProject>\r
index 1f08970..8dba650 100644 (file)
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioProject
-       ProjectType="Visual C++"
-       Version="9.00"
-       Name="lcms2_static"
-       ProjectGUID="{71DEDE59-3F1E-486B-A899-4283000F76B5}"
-       RootNamespace="lcms2_static"
-       Keyword="Win32Proj"
-       TargetFrameworkVersion="196613"
-       >
-       <Platforms>
-               <Platform
-                       Name="Win32"
-               />
-       </Platforms>
-       <ToolFiles>
-       </ToolFiles>
-       <Configurations>
-               <Configuration
-                       Name="Debug|Win32"
-                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
-                       IntermediateDirectory="$(ConfigurationName)"
-                       ConfigurationType="4"
-                       CharacterSet="1"
-                       >
-                       <Tool
-                               Name="VCPreBuildEventTool"
-                       />
-                       <Tool
-                               Name="VCCustomBuildTool"
-                       />
-                       <Tool
-                               Name="VCXMLDataGeneratorTool"
-                       />
-                       <Tool
-                               Name="VCWebServiceProxyGeneratorTool"
-                       />
-                       <Tool
-                               Name="VCMIDLTool"
-                       />
-                       <Tool
-                               Name="VCCLCompilerTool"
-                               Optimization="0"
-                               AdditionalIncludeDirectories="../../../include"
-                               PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
-                               MinimalRebuild="true"
-                               BasicRuntimeChecks="3"
-                               RuntimeLibrary="1"
-                               UsePrecompiledHeader="0"
-                               WarningLevel="4"
-                               DebugInformationFormat="4"
-                       />
-                       <Tool
-                               Name="VCManagedResourceCompilerTool"
-                       />
-                       <Tool
-                               Name="VCResourceCompilerTool"
-                       />
-                       <Tool
-                               Name="VCPreLinkEventTool"
-                       />
-                       <Tool
-                               Name="VCLibrarianTool"
-                       />
-                       <Tool
-                               Name="VCALinkTool"
-                       />
-                       <Tool
-                               Name="VCXDCMakeTool"
-                       />
-                       <Tool
-                               Name="VCBscMakeTool"
-                       />
-                       <Tool
-                               Name="VCFxCopTool"
-                       />
-                       <Tool
-                               Name="VCPostBuildEventTool"
-                       />
-               </Configuration>
-               <Configuration
-                       Name="Release|Win32"
-                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
-                       IntermediateDirectory="$(ConfigurationName)"
-                       ConfigurationType="4"
-                       CharacterSet="1"
-                       WholeProgramOptimization="1"
-                       >
-                       <Tool
-                               Name="VCPreBuildEventTool"
-                       />
-                       <Tool
-                               Name="VCCustomBuildTool"
-                       />
-                       <Tool
-                               Name="VCXMLDataGeneratorTool"
-                       />
-                       <Tool
-                               Name="VCWebServiceProxyGeneratorTool"
-                       />
-                       <Tool
-                               Name="VCMIDLTool"
-                       />
-                       <Tool
-                               Name="VCCLCompilerTool"
-                               Optimization="2"
-                               EnableIntrinsicFunctions="true"
-                               AdditionalIncludeDirectories="../../../include"
-                               PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
-                               RuntimeLibrary="0"
-                               EnableFunctionLevelLinking="true"
-                               UsePrecompiledHeader="0"
-                               WarningLevel="4"
-                               DebugInformationFormat="3"
-                       />
-                       <Tool
-                               Name="VCManagedResourceCompilerTool"
-                       />
-                       <Tool
-                               Name="VCResourceCompilerTool"
-                       />
-                       <Tool
-                               Name="VCPreLinkEventTool"
-                       />
-                       <Tool
-                               Name="VCLibrarianTool"
-                       />
-                       <Tool
-                               Name="VCALinkTool"
-                       />
-                       <Tool
-                               Name="VCXDCMakeTool"
-                       />
-                       <Tool
-                               Name="VCBscMakeTool"
-                       />
-                       <Tool
-                               Name="VCFxCopTool"
-                       />
-                       <Tool
-                               Name="VCPostBuildEventTool"
-                       />
-               </Configuration>
-       </Configurations>
-       <References>
-       </References>
-       <Files>
-               <Filter
-                       Name="Source Files"
-                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
-                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
-                       >
-                       <File
-                               RelativePath="..\..\..\src\cmscam02.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmscgats.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmscnvrt.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmserr.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsgamma.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsgmt.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsintrp.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsio0.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsio1.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmslut.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsmd5.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsmtrx.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsnamed.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsopt.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmspack.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmspcs.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsplugin.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsps2.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmssamp.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmssm.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmstypes.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsvirt.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmswtpnt.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\cmsxform.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\src\lcms2_internal.h"
-                               >
-                       </File>
-               </Filter>
-               <Filter
-                       Name="Header Files"
-                       Filter="h;hpp;hxx;hm;inl;inc;xsd"
-                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
-                       >
-                       <File
-                               RelativePath="..\..\..\include\lcms2.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\..\include\lcms2_plugin.h"
-                               >
-                       </File>
-               </Filter>
-               <Filter
-                       Name="Resource Files"
-                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
-                       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
-                       >
-               </Filter>
-       </Files>
-       <Globals>
-       </Globals>
-</VisualStudioProject>
+<?xml version="1.0" encoding="Windows-1252"?>\r
+<VisualStudioProject\r
+       ProjectType="Visual C++"\r
+       Version="9.00"\r
+       Name="lcms2_static"\r
+       ProjectGUID="{71DEDE59-3F1E-486B-A899-4283000F76B5}"\r
+       RootNamespace="lcms2_static"\r
+       Keyword="Win32Proj"\r
+       TargetFrameworkVersion="196613"\r
+       >\r
+       <Platforms>\r
+               <Platform\r
+                       Name="Win32"\r
+               />\r
+       </Platforms>\r
+       <ToolFiles>\r
+       </ToolFiles>\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
+                       IntermediateDirectory="$(ConfigurationName)"\r
+                       ConfigurationType="4"\r
+                       CharacterSet="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               AdditionalIncludeDirectories="../../../include"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_LIB"\r
+                               MinimalRebuild="true"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="1"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="4"\r
+                               DebugInformationFormat="4"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLibrarianTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
+                       IntermediateDirectory="$(ConfigurationName)"\r
+                       ConfigurationType="4"\r
+                       CharacterSet="1"\r
+                       WholeProgramOptimization="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="2"\r
+                               EnableIntrinsicFunctions="true"\r
+                               AdditionalIncludeDirectories="../../../include"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_LIB"\r
+                               RuntimeLibrary="0"\r
+                               EnableFunctionLevelLinking="true"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="4"\r
+                               DebugInformationFormat="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLibrarianTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+       </Configurations>\r
+       <References>\r
+       </References>\r
+       <Files>\r
+               <Filter\r
+                       Name="Source Files"\r
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"\r
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"\r
+                       >\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmscam02.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmscgats.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmscnvrt.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmserr.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsgamma.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsgmt.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmshalf.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsintrp.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsio0.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsio1.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmslut.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsmd5.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsmtrx.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsnamed.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsopt.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmspack.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmspcs.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsplugin.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsps2.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmssamp.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmssm.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmstypes.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsvirt.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmswtpnt.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\cmsxform.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\src\lcms2_internal.h"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Header Files"\r
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"\r
+                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"\r
+                       >\r
+                       <File\r
+                               RelativePath="..\..\..\include\lcms2.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\include\lcms2_plugin.h"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Resource Files"\r
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"\r
+                       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"\r
+                       >\r
+               </Filter>\r
+       </Files>\r
+       <Globals>\r
+       </Globals>\r
+</VisualStudioProject>\r
index f6d8578..5941e85 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup Label="ProjectConfigurations">
-    <ProjectConfiguration Include="Debug|Win32">
-      <Configuration>Debug</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|Win32">
-      <Configuration>Release</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-  </ItemGroup>
-  <PropertyGroup Label="Globals">
-    <ProjectGuid>{62812507-F926-4968-96A9-17678460AD90}</ProjectGuid>
-    <RootNamespace>jpegicc</RootNamespace>
-    <Keyword>Win32Proj</Keyword>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>Unicode</CharacterSet>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
-  <ImportGroup Label="ExtensionSettings">
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
-  </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <PropertyGroup>
-    <_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>
-    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\bin\</OutDir>
-    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
-    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
-    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\bin\</OutDir>
-    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
-    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
-    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
-    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
-    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
-    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
-    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
-    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
-    <IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IncludePath);;C:\jpeg-8b</IncludePath>
-    <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(LibraryPath);;C:\jpeg-8b</LibraryPath>
-    <IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IncludePath);;C:\jpeg-8b</IncludePath>
-    <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(LibraryPath);;C:\jpeg-8b</LibraryPath>
-  </PropertyGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <MinimalRebuild>true</MinimalRebuild>
-      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
-      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
-      <PrecompiledHeader>
-      </PrecompiledHeader>
-      <WarningLevel>Level4</WarningLevel>
-      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
-    </ClCompile>
-    <Link>
-      <AdditionalDependencies>libjpeg.lib;%(AdditionalDependencies)</AdditionalDependencies>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <SubSystem>Console</SubSystem>
-      <TargetMachine>MachineX86</TargetMachine>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-      <Optimization>Full</Optimization>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <PrecompiledHeader>
-      </PrecompiledHeader>
-      <WarningLevel>Level3</WarningLevel>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
-      <OmitFramePointers>true</OmitFramePointers>
-      <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
-    </ClCompile>
-    <Link>
-      <AdditionalDependencies>libjpeg.lib;%(AdditionalDependencies)</AdditionalDependencies>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <SubSystem>Console</SubSystem>
-      <OptimizeReferences>true</OptimizeReferences>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <TargetMachine>MachineX86</TargetMachine>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemGroup>
-    <ClCompile Include="..\..\..\utils\common\vprf.c" />
-    <ClCompile Include="..\..\..\utils\common\xgetopt.c" />
-    <ClCompile Include="..\..\..\utils\jpgicc\iccjpeg.c" />
-    <ClCompile Include="..\..\..\utils\jpgicc\jpgicc.c" />
-  </ItemGroup>
-  <ItemGroup>
-    <ProjectReference Include="..\lcms2_static\lcms2_static.vcxproj">
-      <Project>{71dede59-3f1e-486b-a899-4283000f76b5}</Project>
-      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
-    </ProjectReference>
-  </ItemGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <ItemGroup Label="ProjectConfigurations">\r
+    <ProjectConfiguration Include="Debug|Win32">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Debug|x64">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|Win32">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|x64">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+  </ItemGroup>\r
+  <PropertyGroup Label="Globals">\r
+    <ProjectGuid>{62812507-F926-4968-96A9-17678460AD90}</ProjectGuid>\r
+    <RootNamespace>jpegicc</RootNamespace>\r
+    <Keyword>Win32Proj</Keyword>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />\r
+  <ImportGroup Label="ExtensionSettings">\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <PropertyGroup Label="UserMacros" />\r
+  <PropertyGroup>\r
+    <_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\bin\</OutDir>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\..\bin\</OutDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Configuration)\</IntDir>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\bin\</OutDir>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\..\bin\</OutDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Configuration)\</IntDir>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />\r
+    <IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IncludePath);;C:\jpeg-8b</IncludePath>\r
+    <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(LibraryPath);;C:\jpeg-8b</LibraryPath>\r
+    <IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(IncludePath);;C:\jpeg-8b</IncludePath>\r
+    <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(LibraryPath);;C:\jpeg-8b</LibraryPath>\r
+  </PropertyGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
+    <ClCompile>\r
+      <Optimization>Disabled</Optimization>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <MinimalRebuild>true</MinimalRebuild>\r
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\r
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <AdditionalDependencies>libjpeg.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <TargetMachine>MachineX86</TargetMachine>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">\r
+    <ClCompile>\r
+      <Optimization>Disabled</Optimization>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\r
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <AdditionalDependencies>libjpeg.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
+    <ClCompile>\r
+      <Optimization>Full</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\r
+      <FunctionLevelLinking>true</FunctionLevelLinking>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level3</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>\r
+      <OmitFramePointers>true</OmitFramePointers>\r
+      <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <AdditionalDependencies>libjpeg.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+      <TargetMachine>MachineX86</TargetMachine>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">\r
+    <ClCompile>\r
+      <Optimization>Full</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\r
+      <FunctionLevelLinking>true</FunctionLevelLinking>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level3</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>\r
+      <OmitFramePointers>true</OmitFramePointers>\r
+      <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <AdditionalDependencies>libjpeg.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemGroup>\r
+    <ClCompile Include="..\..\..\utils\common\vprf.c" />\r
+    <ClCompile Include="..\..\..\utils\common\xgetopt.c" />\r
+    <ClCompile Include="..\..\..\utils\jpgicc\iccjpeg.c" />\r
+    <ClCompile Include="..\..\..\utils\jpgicc\jpgicc.c" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ProjectReference Include="..\lcms2_static\lcms2_static.vcxproj">\r
+      <Project>{71dede59-3f1e-486b-a899-4283000f76b5}</Project>\r
+      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>\r
+    </ProjectReference>\r
+  </ItemGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\r
+  <ImportGroup Label="ExtensionTargets">\r
+  </ImportGroup>\r
 </Project>
\ No newline at end of file
index e851ef0..6b9cd5e 100755 (executable)
Binary files a/Projects/VC2010/lcms2.sln and b/Projects/VC2010/lcms2.sln differ
index ec180ca..45057bf 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup Label="ProjectConfigurations">
-    <ProjectConfiguration Include="Debug|Win32">
-      <Configuration>Debug</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|Win32">
-      <Configuration>Release</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-  </ItemGroup>
-  <PropertyGroup Label="Globals">
-    <ProjectGuid>{8C51BE48-ADB8-4089-A9EC-F6BF993A0548}</ProjectGuid>
-    <RootNamespace>lcms2_DLL</RootNamespace>
-    <Keyword>Win32Proj</Keyword>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <CharacterSet>Unicode</CharacterSet>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
-  <ImportGroup Label="ExtensionSettings">
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
-  </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <PropertyGroup>
-    <_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>
-    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\bin\</OutDir>
-    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
-    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
-    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\bin\</OutDir>
-    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
-    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
-    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
-    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
-    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
-    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
-    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
-    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
-  </PropertyGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>../../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;CMS_DLL_BUILD;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <MinimalRebuild>true</MinimalRebuild>
-      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
-      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
-      <PrecompiledHeader>
-      </PrecompiledHeader>
-      <WarningLevel>Level3</WarningLevel>
-      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
-    </ClCompile>
-    <Link>
-      <ModuleDefinitionFile>..\..\..\src\lcms2.def</ModuleDefinitionFile>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <SubSystem>Windows</SubSystem>
-      <TargetMachine>MachineX86</TargetMachine>
-      <OutputFile>../../../bin/lcms2d.dll</OutputFile>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-      <Optimization>Full</Optimization>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
-      <OmitFramePointers>true</OmitFramePointers>
-      <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
-      <WholeProgramOptimization>true</WholeProgramOptimization>
-      <AdditionalIncludeDirectories>../../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;CMS_DLL_BUILD;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <PrecompiledHeader>
-      </PrecompiledHeader>
-      <WarningLevel>Level4</WarningLevel>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <StringPooling>true</StringPooling>
-      <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
-    </ClCompile>
-    <Link>
-      <ModuleDefinitionFile>..\..\..\src\lcms2.def</ModuleDefinitionFile>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <SubSystem>Windows</SubSystem>
-      <OptimizeReferences>true</OptimizeReferences>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <TargetMachine>MachineX86</TargetMachine>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemGroup>
-    <ClCompile Include="..\..\..\src\cmscam02.c" />
-    <ClCompile Include="..\..\..\src\cmscgats.c" />
-    <ClCompile Include="..\..\..\src\cmscnvrt.c" />
-    <ClCompile Include="..\..\..\src\cmserr.c" />
-    <ClCompile Include="..\..\..\src\cmsgamma.c" />
-    <ClCompile Include="..\..\..\src\cmsgmt.c" />
-    <ClCompile Include="..\..\..\src\cmsintrp.c" />
-    <ClCompile Include="..\..\..\src\cmsio0.c" />
-    <ClCompile Include="..\..\..\src\cmsio1.c" />
-    <ClCompile Include="..\..\..\src\cmslut.c" />
-    <ClCompile Include="..\..\..\src\cmsmd5.c" />
-    <ClCompile Include="..\..\..\src\cmsmtrx.c" />
-    <ClCompile Include="..\..\..\src\cmsnamed.c" />
-    <ClCompile Include="..\..\..\src\cmsopt.c" />
-    <ClCompile Include="..\..\..\src\cmspack.c" />
-    <ClCompile Include="..\..\..\src\cmspcs.c" />
-    <ClCompile Include="..\..\..\src\cmsplugin.c" />
-    <ClCompile Include="..\..\..\src\cmsps2.c" />
-    <ClCompile Include="..\..\..\src\cmssamp.c" />
-    <ClCompile Include="..\..\..\src\cmssm.c" />
-    <ClCompile Include="..\..\..\src\cmstypes.c" />
-    <ClCompile Include="..\..\..\src\cmsvirt.c" />
-    <ClCompile Include="..\..\..\src\cmswtpnt.c" />
-    <ClCompile Include="..\..\..\src\cmsxform.c" />
-  </ItemGroup>
-  <ItemGroup>
-    <CustomBuild Include="..\..\..\src\lcms2.def" />
-  </ItemGroup>
-  <ItemGroup>
-    <ClInclude Include="..\..\..\src\lcms2_internal.h" />
-    <ClInclude Include="..\..\..\include\lcms2.h" />
-    <ClInclude Include="..\..\..\include\lcms2_plugin.h" />
-    <ClInclude Include="..\resource.h" />
-  </ItemGroup>
-  <ItemGroup>
-    <ResourceCompile Include="..\lcms2.rc" />
-  </ItemGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <ItemGroup Label="ProjectConfigurations">\r
+    <ProjectConfiguration Include="Debug|Win32">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Debug|x64">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|Win32">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|x64">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+  </ItemGroup>\r
+  <PropertyGroup Label="Globals">\r
+    <ProjectGuid>{8C51BE48-ADB8-4089-A9EC-F6BF993A0548}</ProjectGuid>\r
+    <RootNamespace>lcms2_DLL</RootNamespace>\r
+    <Keyword>Win32Proj</Keyword>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">\r
+    <ConfigurationType>DynamicLibrary</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">\r
+    <ConfigurationType>DynamicLibrary</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">\r
+    <ConfigurationType>DynamicLibrary</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">\r
+    <ConfigurationType>DynamicLibrary</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />\r
+  <ImportGroup Label="ExtensionSettings">\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <PropertyGroup Label="UserMacros" />\r
+  <PropertyGroup>\r
+    <_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\bin\</OutDir>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\..\bin\</OutDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Configuration)\</IntDir>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\bin\</OutDir>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\..\bin\</OutDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Configuration)\</IntDir>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />\r
+  </PropertyGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
+    <ClCompile>\r
+      <Optimization>Disabled</Optimization>\r
+      <AdditionalIncludeDirectories>../../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;CMS_DLL_BUILD;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <MinimalRebuild>true</MinimalRebuild>\r
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\r
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level3</WarningLevel>\r
+      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <ModuleDefinitionFile>..\..\..\src\lcms2.def</ModuleDefinitionFile>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Windows</SubSystem>\r
+      <TargetMachine>MachineX86</TargetMachine>\r
+      <OutputFile>../../../bin/lcms2d.dll</OutputFile>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">\r
+    <ClCompile>\r
+      <Optimization>Disabled</Optimization>\r
+      <AdditionalIncludeDirectories>../../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;CMS_DLL_BUILD;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\r
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level3</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <ModuleDefinitionFile>..\..\..\src\lcms2.def</ModuleDefinitionFile>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Windows</SubSystem>\r
+      <OutputFile>../../../bin/lcms2d.dll</OutputFile>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
+    <ClCompile>\r
+      <Optimization>Full</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>\r
+      <OmitFramePointers>true</OmitFramePointers>\r
+      <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>\r
+      <WholeProgramOptimization>true</WholeProgramOptimization>\r
+      <AdditionalIncludeDirectories>../../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;CMS_DLL_BUILD;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\r
+      <FunctionLevelLinking>true</FunctionLevelLinking>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <StringPooling>true</StringPooling>\r
+      <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <ModuleDefinitionFile>..\..\..\src\lcms2.def</ModuleDefinitionFile>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Windows</SubSystem>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+      <TargetMachine>MachineX86</TargetMachine>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">\r
+    <ClCompile>\r
+      <Optimization>Full</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>\r
+      <OmitFramePointers>true</OmitFramePointers>\r
+      <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>\r
+      <WholeProgramOptimization>true</WholeProgramOptimization>\r
+      <AdditionalIncludeDirectories>../../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;CMS_DLL_BUILD;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\r
+      <FunctionLevelLinking>true</FunctionLevelLinking>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <StringPooling>true</StringPooling>\r
+      <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <ModuleDefinitionFile>..\..\..\src\lcms2.def</ModuleDefinitionFile>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Windows</SubSystem>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemGroup>\r
+    <ClCompile Include="..\..\..\src\cmscam02.c" />\r
+    <ClCompile Include="..\..\..\src\cmscgats.c" />\r
+    <ClCompile Include="..\..\..\src\cmscnvrt.c" />\r
+    <ClCompile Include="..\..\..\src\cmserr.c" />\r
+    <ClCompile Include="..\..\..\src\cmsgamma.c" />\r
+    <ClCompile Include="..\..\..\src\cmsgmt.c" />\r
+    <ClCompile Include="..\..\..\src\cmshalf.c" />\r
+    <ClCompile Include="..\..\..\src\cmsintrp.c" />\r
+    <ClCompile Include="..\..\..\src\cmsio0.c" />\r
+    <ClCompile Include="..\..\..\src\cmsio1.c" />\r
+    <ClCompile Include="..\..\..\src\cmslut.c" />\r
+    <ClCompile Include="..\..\..\src\cmsmd5.c" />\r
+    <ClCompile Include="..\..\..\src\cmsmtrx.c" />\r
+    <ClCompile Include="..\..\..\src\cmsnamed.c" />\r
+    <ClCompile Include="..\..\..\src\cmsopt.c" />\r
+    <ClCompile Include="..\..\..\src\cmspack.c" />\r
+    <ClCompile Include="..\..\..\src\cmspcs.c" />\r
+    <ClCompile Include="..\..\..\src\cmsplugin.c" />\r
+    <ClCompile Include="..\..\..\src\cmsps2.c" />\r
+    <ClCompile Include="..\..\..\src\cmssamp.c" />\r
+    <ClCompile Include="..\..\..\src\cmssm.c" />\r
+    <ClCompile Include="..\..\..\src\cmstypes.c" />\r
+    <ClCompile Include="..\..\..\src\cmsvirt.c" />\r
+    <ClCompile Include="..\..\..\src\cmswtpnt.c" />\r
+    <ClCompile Include="..\..\..\src\cmsxform.c" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <CustomBuild Include="..\..\..\src\lcms2.def" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ClInclude Include="..\..\..\src\lcms2_internal.h" />\r
+    <ClInclude Include="..\..\..\include\lcms2.h" />\r
+    <ClInclude Include="..\..\..\include\lcms2_plugin.h" />\r
+    <ClInclude Include="..\resource.h" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ResourceCompile Include="..\lcms2.rc" />\r
+  </ItemGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\r
+  <ImportGroup Label="ExtensionTargets">\r
+  </ImportGroup>\r
 </Project>
\ No newline at end of file
index fc64fa4..5ac8610 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup>
-    <Filter Include="Header Files">
-      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
-      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
-    </Filter>
-    <Filter Include="Resource Files">
-      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
-      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
-    </Filter>
-    <Filter Include="Source Files">
-      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
-      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
-    </Filter>
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="..\..\..\src\cmscam02.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmscgats.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmscnvrt.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmserr.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsgamma.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsgmt.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsintrp.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsio0.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsio1.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmslut.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsmd5.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsmtrx.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsnamed.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsopt.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmspack.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmspcs.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsplugin.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsps2.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmssamp.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmssm.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmstypes.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsvirt.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmswtpnt.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsxform.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-  </ItemGroup>
-  <ItemGroup>
-    <ClInclude Include="..\..\..\include\lcms2.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\..\..\include\lcms2_plugin.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\..\..\src\lcms2_internal.h">
-      <Filter>Source Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\resource.h">
-      <Filter>Resource Files</Filter>
-    </ClInclude>
-  </ItemGroup>
-  <ItemGroup>
-    <ResourceCompile Include="..\lcms2.rc">
-      <Filter>Resource Files</Filter>
-    </ResourceCompile>
-  </ItemGroup>
-  <ItemGroup>
-    <CustomBuild Include="..\..\..\src\lcms2.def">
-      <Filter>Source Files</Filter>
-    </CustomBuild>
-  </ItemGroup>
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <ItemGroup>\r
+    <Filter Include="Header Files">\r
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>\r
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>\r
+    </Filter>\r
+    <Filter Include="Resource Files">\r
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>\r
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>\r
+    </Filter>\r
+    <Filter Include="Source Files">\r
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>\r
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>\r
+    </Filter>\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ClCompile Include="..\..\..\src\cmscam02.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmscgats.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmscnvrt.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmserr.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsgamma.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsgmt.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsintrp.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsio0.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsio1.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmslut.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsmd5.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsmtrx.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsnamed.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsopt.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmspack.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmspcs.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsplugin.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsps2.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmssamp.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmssm.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmstypes.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsvirt.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmswtpnt.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsxform.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmshalf.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ClInclude Include="..\..\..\include\lcms2.h">\r
+      <Filter>Header Files</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="..\..\..\include\lcms2_plugin.h">\r
+      <Filter>Header Files</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="..\..\..\src\lcms2_internal.h">\r
+      <Filter>Source Files</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="..\resource.h">\r
+      <Filter>Resource Files</Filter>\r
+    </ClInclude>\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ResourceCompile Include="..\lcms2.rc">\r
+      <Filter>Resource Files</Filter>\r
+    </ResourceCompile>\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <CustomBuild Include="..\..\..\src\lcms2.def">\r
+      <Filter>Source Files</Filter>\r
+    </CustomBuild>\r
+  </ItemGroup>\r
 </Project>
\ No newline at end of file
index c611473..b448e67 100644 (file)
@@ -5,10 +5,18 @@
       <Configuration>Debug</Configuration>\r
       <Platform>Win32</Platform>\r
     </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Debug|x64">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
     <ProjectConfiguration Include="Release|Win32">\r
       <Configuration>Release</Configuration>\r
       <Platform>Win32</Platform>\r
     </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|x64">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
   </ItemGroup>\r
   <PropertyGroup Label="Globals">\r
     <ProjectGuid>{71DEDE59-3F1E-486B-A899-4283000F76B5}</ProjectGuid>\r
     <CharacterSet>Unicode</CharacterSet>\r
     <WholeProgramOptimization>true</WholeProgramOptimization>\r
   </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">\r
+    <ConfigurationType>StaticLibrary</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+  </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">\r
     <ConfigurationType>StaticLibrary</ConfigurationType>\r
     <CharacterSet>Unicode</CharacterSet>\r
   </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">\r
+    <ConfigurationType>StaticLibrary</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+  </PropertyGroup>\r
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />\r
   <ImportGroup Label="ExtensionSettings">\r
   </ImportGroup>\r
   <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">\r
     <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
   </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
   <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">\r
     <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
   </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
   <PropertyGroup Label="UserMacros" />\r
   <PropertyGroup>\r
     <_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>\r
     <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\Lib\MS\</OutDir>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\..\Lib\MS\</OutDir>\r
     <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Configuration)\</IntDir>\r
     <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\Lib\MS\</OutDir>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\..\Lib\MS\</OutDir>\r
     <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Configuration)\</IntDir>\r
     <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet>\r
     <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />\r
     <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />\r
     <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet>\r
     <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />\r
     <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />\r
   </PropertyGroup>\r
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
     <ClCompile>\r
       <DebugInformationFormat>EditAndContinue</DebugInformationFormat>\r
       <FunctionLevelLinking>\r
       </FunctionLevelLinking>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">\r
+    <ClCompile>\r
+      <Optimization>Disabled</Optimization>\r
+      <AdditionalIncludeDirectories>../../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\r
+      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <FunctionLevelLinking>\r
+      </FunctionLevelLinking>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
     </ClCompile>\r
   </ItemDefinitionGroup>\r
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
       <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>\r
       <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>\r
       <ExceptionHandling>false</ExceptionHandling>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">\r
+    <ClCompile>\r
+      <Optimization>Full</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <AdditionalIncludeDirectories>../../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\r
+      <FunctionLevelLinking>true</FunctionLevelLinking>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>\r
+      <OmitFramePointers>true</OmitFramePointers>\r
+      <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>\r
+      <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>\r
+      <ExceptionHandling>false</ExceptionHandling>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
     </ClCompile>\r
   </ItemDefinitionGroup>\r
   <ItemGroup>\r
     <ClCompile Include="..\..\..\src\cmserr.c" />\r
     <ClCompile Include="..\..\..\src\cmsgamma.c" />\r
     <ClCompile Include="..\..\..\src\cmsgmt.c" />\r
+    <ClCompile Include="..\..\..\src\cmshalf.c" />\r
     <ClCompile Include="..\..\..\src\cmsintrp.c" />\r
     <ClCompile Include="..\..\..\src\cmsio0.c" />\r
     <ClCompile Include="..\..\..\src\cmsio1.c" />\r
index a2af6e7..c7e6901 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup>
-    <Filter Include="Header Files">
-      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
-      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
-    </Filter>
-    <Filter Include="Resource Files">
-      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
-      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
-    </Filter>
-    <Filter Include="Source Files">
-      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
-      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
-    </Filter>
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="..\..\..\src\cmscam02.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmscgats.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmscnvrt.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmserr.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsgamma.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsgmt.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsintrp.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsio0.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsio1.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmslut.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsmd5.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsmtrx.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsnamed.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsopt.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmspack.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmspcs.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsplugin.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsps2.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmssamp.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmssm.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmstypes.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsvirt.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmswtpnt.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\src\cmsxform.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-  </ItemGroup>
-  <ItemGroup>
-    <ClInclude Include="..\..\..\include\lcms2.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\..\..\include\lcms2_plugin.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\..\..\src\lcms2_internal.h">
-      <Filter>Source Files</Filter>
-    </ClInclude>
-  </ItemGroup>
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <ItemGroup>\r
+    <Filter Include="Header Files">\r
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>\r
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>\r
+    </Filter>\r
+    <Filter Include="Resource Files">\r
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>\r
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>\r
+    </Filter>\r
+    <Filter Include="Source Files">\r
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>\r
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>\r
+    </Filter>\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ClCompile Include="..\..\..\src\cmscam02.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmscgats.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmscnvrt.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmserr.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsgamma.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsgmt.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsintrp.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsio0.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsio1.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmslut.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsmd5.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsmtrx.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsnamed.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsopt.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmspack.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmspcs.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsplugin.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsps2.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmssamp.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmssm.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmstypes.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsvirt.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmswtpnt.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmsxform.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\src\cmshalf.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ClInclude Include="..\..\..\include\lcms2.h">\r
+      <Filter>Header Files</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="..\..\..\include\lcms2_plugin.h">\r
+      <Filter>Header Files</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="..\..\..\src\lcms2_internal.h">\r
+      <Filter>Source Files</Filter>\r
+    </ClInclude>\r
+  </ItemGroup>\r
 </Project>
\ No newline at end of file
index 6bd9ebc..b8022fe 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup Label="ProjectConfigurations">
-    <ProjectConfiguration Include="Debug|Win32">
-      <Configuration>Debug</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|Win32">
-      <Configuration>Release</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-  </ItemGroup>
-  <PropertyGroup Label="Globals">
-    <ProjectGuid>{FBFBE1DC-DB84-4BA1-9552-B4780F457849}</ProjectGuid>
-    <RootNamespace>linkicc</RootNamespace>
-    <Keyword>Win32Proj</Keyword>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>Unicode</CharacterSet>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
-  <ImportGroup Label="ExtensionSettings">
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
-  </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <PropertyGroup>
-    <_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>
-    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\bin\</OutDir>
-    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
-    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
-    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\bin\</OutDir>
-    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
-    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
-    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
-    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
-    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
-    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
-    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
-    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
-  </PropertyGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <MinimalRebuild>true</MinimalRebuild>
-      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
-      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
-      <PrecompiledHeader>
-      </PrecompiledHeader>
-      <WarningLevel>Level4</WarningLevel>
-      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <SubSystem>Console</SubSystem>
-      <TargetMachine>MachineX86</TargetMachine>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-      <Optimization>MaxSpeed</Optimization>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <PrecompiledHeader>
-      </PrecompiledHeader>
-      <WarningLevel>Level4</WarningLevel>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <SubSystem>Console</SubSystem>
-      <OptimizeReferences>true</OptimizeReferences>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <TargetMachine>MachineX86</TargetMachine>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemGroup>
-    <ClCompile Include="..\..\..\utils\linkicc\linkicc.c" />
-    <ClCompile Include="..\..\..\utils\common\vprf.c" />
-    <ClCompile Include="..\..\..\utils\common\xgetopt.c" />
-  </ItemGroup>
-  <ItemGroup>
-    <ProjectReference Include="..\lcms2_static\lcms2_static.vcxproj">
-      <Project>{71dede59-3f1e-486b-a899-4283000f76b5}</Project>
-      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
-    </ProjectReference>
-  </ItemGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <ItemGroup Label="ProjectConfigurations">\r
+    <ProjectConfiguration Include="Debug|Win32">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Debug|x64">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|Win32">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|x64">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+  </ItemGroup>\r
+  <PropertyGroup Label="Globals">\r
+    <ProjectGuid>{FBFBE1DC-DB84-4BA1-9552-B4780F457849}</ProjectGuid>\r
+    <RootNamespace>linkicc</RootNamespace>\r
+    <Keyword>Win32Proj</Keyword>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />\r
+  <ImportGroup Label="ExtensionSettings">\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <PropertyGroup Label="UserMacros" />\r
+  <PropertyGroup>\r
+    <_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\bin\</OutDir>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\..\bin\</OutDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Configuration)\</IntDir>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\bin\</OutDir>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\..\bin\</OutDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Configuration)\</IntDir>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />\r
+  </PropertyGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
+    <ClCompile>\r
+      <Optimization>Disabled</Optimization>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <MinimalRebuild>true</MinimalRebuild>\r
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\r
+      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <TargetMachine>MachineX86</TargetMachine>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">\r
+    <ClCompile>\r
+      <Optimization>Disabled</Optimization>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\r
+      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
+    <ClCompile>\r
+      <Optimization>MaxSpeed</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\r
+      <FunctionLevelLinking>true</FunctionLevelLinking>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+      <TargetMachine>MachineX86</TargetMachine>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">\r
+    <ClCompile>\r
+      <Optimization>MaxSpeed</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\r
+      <FunctionLevelLinking>true</FunctionLevelLinking>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemGroup>\r
+    <ClCompile Include="..\..\..\utils\linkicc\linkicc.c" />\r
+    <ClCompile Include="..\..\..\utils\common\vprf.c" />\r
+    <ClCompile Include="..\..\..\utils\common\xgetopt.c" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ProjectReference Include="..\lcms2_static\lcms2_static.vcxproj">\r
+      <Project>{71dede59-3f1e-486b-a899-4283000f76b5}</Project>\r
+      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>\r
+    </ProjectReference>\r
+  </ItemGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\r
+  <ImportGroup Label="ExtensionTargets">\r
+  </ImportGroup>\r
 </Project>
\ No newline at end of file
index b200db1..32e87d1 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup Label="ProjectConfigurations">
-    <ProjectConfiguration Include="Debug|Win32">
-      <Configuration>Debug</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|Win32">
-      <Configuration>Release</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-  </ItemGroup>
-  <PropertyGroup Label="Globals">
-    <ProjectGuid>{EF6A8851-65FE-46F5-B9EF-14F0B671F693}</ProjectGuid>
-    <RootNamespace>psicc</RootNamespace>
-    <Keyword>Win32Proj</Keyword>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>Unicode</CharacterSet>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
-  <ImportGroup Label="ExtensionSettings">
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
-  </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <PropertyGroup>
-    <_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>
-    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\bin\</OutDir>
-    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
-    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
-    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\bin\</OutDir>
-    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
-    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
-    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
-    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
-    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
-    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
-    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
-    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
-  </PropertyGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <MinimalRebuild>true</MinimalRebuild>
-      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
-      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
-      <PrecompiledHeader>
-      </PrecompiledHeader>
-      <WarningLevel>Level4</WarningLevel>
-      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <SubSystem>Console</SubSystem>
-      <TargetMachine>MachineX86</TargetMachine>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-      <Optimization>MaxSpeed</Optimization>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <PrecompiledHeader>
-      </PrecompiledHeader>
-      <WarningLevel>Level4</WarningLevel>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <SubSystem>Console</SubSystem>
-      <OptimizeReferences>true</OptimizeReferences>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <TargetMachine>MachineX86</TargetMachine>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemGroup>
-    <ClCompile Include="..\..\..\utils\psicc\psicc.c" />
-    <ClCompile Include="..\..\..\utils\common\vprf.c" />
-    <ClCompile Include="..\..\..\utils\common\xgetopt.c" />
-  </ItemGroup>
-  <ItemGroup>
-    <ProjectReference Include="..\lcms2_static\lcms2_static.vcxproj">
-      <Project>{71dede59-3f1e-486b-a899-4283000f76b5}</Project>
-      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
-    </ProjectReference>
-  </ItemGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <ItemGroup Label="ProjectConfigurations">\r
+    <ProjectConfiguration Include="Debug|Win32">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Debug|x64">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|Win32">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|x64">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+  </ItemGroup>\r
+  <PropertyGroup Label="Globals">\r
+    <ProjectGuid>{EF6A8851-65FE-46F5-B9EF-14F0B671F693}</ProjectGuid>\r
+    <RootNamespace>psicc</RootNamespace>\r
+    <Keyword>Win32Proj</Keyword>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />\r
+  <ImportGroup Label="ExtensionSettings">\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <PropertyGroup Label="UserMacros" />\r
+  <PropertyGroup>\r
+    <_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\bin\</OutDir>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\..\bin\</OutDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Configuration)\</IntDir>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\bin\</OutDir>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\..\bin\</OutDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Configuration)\</IntDir>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />\r
+  </PropertyGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
+    <ClCompile>\r
+      <Optimization>Disabled</Optimization>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <MinimalRebuild>true</MinimalRebuild>\r
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\r
+      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <TargetMachine>MachineX86</TargetMachine>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">\r
+    <ClCompile>\r
+      <Optimization>Disabled</Optimization>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\r
+      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
+    <ClCompile>\r
+      <Optimization>MaxSpeed</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\r
+      <FunctionLevelLinking>true</FunctionLevelLinking>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+      <TargetMachine>MachineX86</TargetMachine>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">\r
+    <ClCompile>\r
+      <Optimization>MaxSpeed</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\r
+      <FunctionLevelLinking>true</FunctionLevelLinking>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemGroup>\r
+    <ClCompile Include="..\..\..\utils\psicc\psicc.c" />\r
+    <ClCompile Include="..\..\..\utils\common\vprf.c" />\r
+    <ClCompile Include="..\..\..\utils\common\xgetopt.c" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ProjectReference Include="..\lcms2_static\lcms2_static.vcxproj">\r
+      <Project>{71dede59-3f1e-486b-a899-4283000f76b5}</Project>\r
+      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>\r
+    </ProjectReference>\r
+  </ItemGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\r
+  <ImportGroup Label="ExtensionTargets">\r
+  </ImportGroup>\r
 </Project>
\ No newline at end of file
index 15988b5..01bebe8 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup Label="ProjectConfigurations">
-    <ProjectConfiguration Include="Debug|Win32">
-      <Configuration>Debug</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|Win32">
-      <Configuration>Release</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-  </ItemGroup>
-  <PropertyGroup Label="Globals">
-    <ProjectGuid>{928A3A2B-46EF-4279-959C-513B3652FF0E}</ProjectGuid>
-    <RootNamespace>testbed</RootNamespace>
-    <Keyword>Win32Proj</Keyword>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>Unicode</CharacterSet>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
-  <ImportGroup Label="ExtensionSettings">
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
-  </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <PropertyGroup>
-    <_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>
-    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
-    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
-    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\testbed\</OutDir>
-    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
-    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
-    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
-    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
-    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
-    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
-    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
-    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
-    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\testbed\</OutDir>
-  </PropertyGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>../../../include;../../../src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <MinimalRebuild>true</MinimalRebuild>
-      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
-      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
-      <PrecompiledHeader>
-      </PrecompiledHeader>
-      <WarningLevel>Level3</WarningLevel>
-      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <SubSystem>Console</SubSystem>
-      <TargetMachine>MachineX86</TargetMachine>
-      <Profile>false</Profile>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-      <Optimization>Full</Optimization>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
-      <OmitFramePointers>true</OmitFramePointers>
-      <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
-      <AdditionalIncludeDirectories>../../../include;../../../src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
-      <BufferSecurityCheck>false</BufferSecurityCheck>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
-      <PrecompiledHeader>
-      </PrecompiledHeader>
-      <WarningLevel>Level3</WarningLevel>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <CallingConvention>Cdecl</CallingConvention>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <SubSystem>Console</SubSystem>
-      <OptimizeReferences>true</OptimizeReferences>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <TargetMachine>MachineX86</TargetMachine>
-      <Profile>false</Profile>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemGroup>
-    <ProjectReference Include="..\lcms2_static\lcms2_static.vcxproj">
-      <Project>{71dede59-3f1e-486b-a899-4283000f76b5}</Project>
-      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
-    </ProjectReference>
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="..\..\..\testbed\testcms2.c" />
-  </ItemGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <ItemGroup Label="ProjectConfigurations">\r
+    <ProjectConfiguration Include="Debug|Win32">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Debug|x64">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|Win32">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|x64">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+  </ItemGroup>\r
+  <PropertyGroup Label="Globals">\r
+    <ProjectGuid>{928A3A2B-46EF-4279-959C-513B3652FF0E}</ProjectGuid>\r
+    <RootNamespace>testbed</RootNamespace>\r
+    <Keyword>Win32Proj</Keyword>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />\r
+  <ImportGroup Label="ExtensionSettings">\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <PropertyGroup Label="UserMacros" />\r
+  <PropertyGroup>\r
+    <_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Configuration)\</IntDir>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\testbed\</OutDir>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\..\testbed\</OutDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Configuration)\</IntDir>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\testbed\</OutDir>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\..\testbed\</OutDir>\r
+  </PropertyGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
+    <ClCompile>\r
+      <Optimization>Disabled</Optimization>\r
+      <AdditionalIncludeDirectories>../../../include;../../../src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <MinimalRebuild>true</MinimalRebuild>\r
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\r
+      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level3</WarningLevel>\r
+      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <TargetMachine>MachineX86</TargetMachine>\r
+      <Profile>false</Profile>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">\r
+    <ClCompile>\r
+      <Optimization>Disabled</Optimization>\r
+      <AdditionalIncludeDirectories>../../../include;../../../src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\r
+      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level3</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <Profile>false</Profile>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
+    <ClCompile>\r
+      <Optimization>Full</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>\r
+      <OmitFramePointers>true</OmitFramePointers>\r
+      <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>\r
+      <AdditionalIncludeDirectories>../../../include;../../../src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\r
+      <BufferSecurityCheck>false</BufferSecurityCheck>\r
+      <FunctionLevelLinking>true</FunctionLevelLinking>\r
+      <EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level3</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <CallingConvention>Cdecl</CallingConvention>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+      <TargetMachine>MachineX86</TargetMachine>\r
+      <Profile>false</Profile>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">\r
+    <ClCompile>\r
+      <Optimization>Full</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>\r
+      <OmitFramePointers>true</OmitFramePointers>\r
+      <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>\r
+      <AdditionalIncludeDirectories>../../../include;../../../src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\r
+      <BufferSecurityCheck>false</BufferSecurityCheck>\r
+      <FunctionLevelLinking>true</FunctionLevelLinking>\r
+      <EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level3</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <CallingConvention>Cdecl</CallingConvention>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+      <Profile>false</Profile>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemGroup>\r
+    <ProjectReference Include="..\lcms2_static\lcms2_static.vcxproj">\r
+      <Project>{71dede59-3f1e-486b-a899-4283000f76b5}</Project>\r
+      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>\r
+    </ProjectReference>\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ClCompile Include="..\..\..\testbed\testcms2.c" />\r
+  </ItemGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\r
+  <ImportGroup Label="ExtensionTargets">\r
+  </ImportGroup>\r
 </Project>
\ No newline at end of file
index 210d812..49da2cd 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup Label="ProjectConfigurations">
-    <ProjectConfiguration Include="Debug|Win32">
-      <Configuration>Debug</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|Win32">
-      <Configuration>Release</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-  </ItemGroup>
-  <PropertyGroup Label="Globals">
-    <ProjectGuid>{75B91835-CCD7-48BE-A606-A9C997D5DBEE}</ProjectGuid>
-    <RootNamespace>tiffdiff</RootNamespace>
-    <Keyword>Win32Proj</Keyword>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>Unicode</CharacterSet>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
-  <ImportGroup Label="ExtensionSettings">
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
-  </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <PropertyGroup>
-    <_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>
-    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\bin\</OutDir>
-    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
-    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
-    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\bin\</OutDir>
-    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
-    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
-    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
-    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
-    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
-    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
-    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
-    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
-    <IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IncludePath);;C:\tiff-3.9.4\libtiff</IncludePath>
-    <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(LibraryPath);;C:\tiff-3.9.4\libtiff</LibraryPath>
-    <IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IncludePath);;C:\tiff-3.9.4\libtiff</IncludePath>
-    <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(LibraryPath);;C:\tiff-3.9.4\libtiff</LibraryPath>
-  </PropertyGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <MinimalRebuild>true</MinimalRebuild>
-      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
-      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
-      <PrecompiledHeader>
-      </PrecompiledHeader>
-      <WarningLevel>Level4</WarningLevel>
-      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
-    </ClCompile>
-    <Link>
-      <AdditionalDependencies>libtiff.lib;%(AdditionalDependencies)</AdditionalDependencies>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <SubSystem>Console</SubSystem>
-      <TargetMachine>MachineX86</TargetMachine>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-      <Optimization>MaxSpeed</Optimization>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <PrecompiledHeader>
-      </PrecompiledHeader>
-      <WarningLevel>Level4</WarningLevel>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-    </ClCompile>
-    <Link>
-      <AdditionalDependencies>libtiff.lib;%(AdditionalDependencies)</AdditionalDependencies>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <SubSystem>Console</SubSystem>
-      <OptimizeReferences>true</OptimizeReferences>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <TargetMachine>MachineX86</TargetMachine>
-      <OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemGroup>
-    <ClCompile Include="..\..\..\utils\common\vprf.c" />
-    <ClCompile Include="..\..\..\utils\common\xgetopt.c" />
-    <ClCompile Include="..\..\..\utils\tificc\tifdiff.c" />
-  </ItemGroup>
-  <ItemGroup>
-    <ProjectReference Include="..\lcms2_static\lcms2_static.vcxproj">
-      <Project>{71dede59-3f1e-486b-a899-4283000f76b5}</Project>
-      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
-    </ProjectReference>
-  </ItemGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <ItemGroup Label="ProjectConfigurations">\r
+    <ProjectConfiguration Include="Debug|Win32">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Debug|x64">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|Win32">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|x64">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+  </ItemGroup>\r
+  <PropertyGroup Label="Globals">\r
+    <ProjectGuid>{75B91835-CCD7-48BE-A606-A9C997D5DBEE}</ProjectGuid>\r
+    <RootNamespace>tiffdiff</RootNamespace>\r
+    <Keyword>Win32Proj</Keyword>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />\r
+  <ImportGroup Label="ExtensionSettings">\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <PropertyGroup Label="UserMacros" />\r
+  <PropertyGroup>\r
+    <_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\bin\</OutDir>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\..\bin\</OutDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Configuration)\</IntDir>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\bin\</OutDir>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\..\bin\</OutDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Configuration)\</IntDir>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />\r
+    <IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IncludePath);;C:\tiff-3.9.4\libtiff</IncludePath>\r
+    <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(LibraryPath);;C:\tiff-3.9.4\libtiff</LibraryPath>\r
+    <IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(IncludePath);;C:\tiff-3.9.4\libtiff</IncludePath>\r
+    <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(LibraryPath);;C:\tiff-3.9.4\libtiff</LibraryPath>\r
+  </PropertyGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
+    <ClCompile>\r
+      <Optimization>Disabled</Optimization>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <MinimalRebuild>true</MinimalRebuild>\r
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\r
+      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <AdditionalDependencies>libtiff.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <TargetMachine>MachineX86</TargetMachine>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">\r
+    <ClCompile>\r
+      <Optimization>Disabled</Optimization>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\r
+      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <AdditionalDependencies>libtiff.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
+    <ClCompile>\r
+      <Optimization>MaxSpeed</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\r
+      <FunctionLevelLinking>true</FunctionLevelLinking>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <AdditionalDependencies>libtiff.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+      <TargetMachine>MachineX86</TargetMachine>\r
+      <OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">\r
+    <ClCompile>\r
+      <Optimization>MaxSpeed</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\r
+      <FunctionLevelLinking>true</FunctionLevelLinking>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <AdditionalDependencies>libtiff.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+      <OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemGroup>\r
+    <ClCompile Include="..\..\..\utils\common\vprf.c" />\r
+    <ClCompile Include="..\..\..\utils\common\xgetopt.c" />\r
+    <ClCompile Include="..\..\..\utils\tificc\tifdiff.c" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ProjectReference Include="..\lcms2_static\lcms2_static.vcxproj">\r
+      <Project>{71dede59-3f1e-486b-a899-4283000f76b5}</Project>\r
+      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>\r
+    </ProjectReference>\r
+  </ItemGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\r
+  <ImportGroup Label="ExtensionTargets">\r
+  </ImportGroup>\r
 </Project>
\ No newline at end of file
index cd63de0..38358f7 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup Label="ProjectConfigurations">
-    <ProjectConfiguration Include="Debug|Win32">
-      <Configuration>Debug</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|Win32">
-      <Configuration>Release</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-  </ItemGroup>
-  <PropertyGroup Label="Globals">
-    <ProjectGuid>{2256DE16-ED92-4A6F-9C54-F65BB61E64A2}</ProjectGuid>
-    <RootNamespace>tifficc</RootNamespace>
-    <Keyword>Win32Proj</Keyword>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>Unicode</CharacterSet>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
-  <ImportGroup Label="ExtensionSettings">
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
-  </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <PropertyGroup>
-    <_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>
-    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\bin\</OutDir>
-    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
-    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
-    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\bin\</OutDir>
-    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
-    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
-    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
-    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
-    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
-    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
-    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
-    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
-    <IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IncludePath);C:\tiff-3.9.4\libtiff</IncludePath>
-    <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(LibraryPath);C:\tiff-3.9.4\libtiff</LibraryPath>
-    <IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IncludePath);C:\tiff-3.9.4\libtiff</IncludePath>
-    <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(LibraryPath);C:\tiff-3.9.4\libtiff</LibraryPath>
-  </PropertyGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <MinimalRebuild>true</MinimalRebuild>
-      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
-      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
-      <PrecompiledHeader>
-      </PrecompiledHeader>
-      <WarningLevel>Level3</WarningLevel>
-      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
-    </ClCompile>
-    <Link>
-      <AdditionalDependencies>libtiff.lib;%(AdditionalDependencies)</AdditionalDependencies>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <SubSystem>Console</SubSystem>
-      <TargetMachine>MachineX86</TargetMachine>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-      <Optimization>MaxSpeed</Optimization>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <PrecompiledHeader>
-      </PrecompiledHeader>
-      <WarningLevel>Level4</WarningLevel>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-    </ClCompile>
-    <Link>
-      <AdditionalDependencies>libtiff.lib;%(AdditionalDependencies)</AdditionalDependencies>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <SubSystem>Console</SubSystem>
-      <OptimizeReferences>true</OptimizeReferences>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <TargetMachine>MachineX86</TargetMachine>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemGroup>
-    <ClCompile Include="..\..\..\utils\common\vprf.c" />
-    <ClCompile Include="..\..\..\utils\common\xgetopt.c" />
-    <ClCompile Include="..\..\..\utils\tificc\tificc.c" />
-  </ItemGroup>
-  <ItemGroup>
-    <ClInclude Include="..\..\..\utils\common\utils.h" />
-  </ItemGroup>
-  <ItemGroup>
-    <ProjectReference Include="..\lcms2_static\lcms2_static.vcxproj">
-      <Project>{71dede59-3f1e-486b-a899-4283000f76b5}</Project>
-      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
-    </ProjectReference>
-  </ItemGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <ItemGroup Label="ProjectConfigurations">\r
+    <ProjectConfiguration Include="Debug|Win32">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Debug|x64">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|Win32">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|x64">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+  </ItemGroup>\r
+  <PropertyGroup Label="Globals">\r
+    <ProjectGuid>{2256DE16-ED92-4A6F-9C54-F65BB61E64A2}</ProjectGuid>\r
+    <RootNamespace>tifficc</RootNamespace>\r
+    <Keyword>Win32Proj</Keyword>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />\r
+  <ImportGroup Label="ExtensionSettings">\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <PropertyGroup Label="UserMacros" />\r
+  <PropertyGroup>\r
+    <_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\bin\</OutDir>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\..\bin\</OutDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Configuration)\</IntDir>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\bin\</OutDir>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\..\bin\</OutDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Configuration)\</IntDir>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />\r
+    <IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IncludePath);C:\tiff-3.9.4\libtiff</IncludePath>\r
+    <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(LibraryPath);C:\tiff-3.9.4\libtiff</LibraryPath>\r
+    <IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(IncludePath);C:\tiff-3.9.4\libtiff</IncludePath>\r
+    <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(LibraryPath);C:\tiff-3.9.4\libtiff</LibraryPath>\r
+  </PropertyGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
+    <ClCompile>\r
+      <Optimization>Disabled</Optimization>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <MinimalRebuild>true</MinimalRebuild>\r
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\r
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level3</WarningLevel>\r
+      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <AdditionalDependencies>libtiff.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <TargetMachine>MachineX86</TargetMachine>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">\r
+    <ClCompile>\r
+      <Optimization>Disabled</Optimization>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\r
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level3</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <AdditionalDependencies>libtiff.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
+    <ClCompile>\r
+      <Optimization>MaxSpeed</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\r
+      <FunctionLevelLinking>true</FunctionLevelLinking>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <AdditionalDependencies>libtiff.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+      <TargetMachine>MachineX86</TargetMachine>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">\r
+    <ClCompile>\r
+      <Optimization>MaxSpeed</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\r
+      <FunctionLevelLinking>true</FunctionLevelLinking>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <AdditionalDependencies>libtiff.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemGroup>\r
+    <ClCompile Include="..\..\..\utils\common\vprf.c" />\r
+    <ClCompile Include="..\..\..\utils\common\xgetopt.c" />\r
+    <ClCompile Include="..\..\..\utils\tificc\tificc.c" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ClInclude Include="..\..\..\utils\common\utils.h" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ProjectReference Include="..\lcms2_static\lcms2_static.vcxproj">\r
+      <Project>{71dede59-3f1e-486b-a899-4283000f76b5}</Project>\r
+      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>\r
+    </ProjectReference>\r
+  </ItemGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\r
+  <ImportGroup Label="ExtensionTargets">\r
+  </ImportGroup>\r
 </Project>
\ No newline at end of file
index e7f66e1..85002e1 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup Label="ProjectConfigurations">
-    <ProjectConfiguration Include="Debug|Win32">
-      <Configuration>Debug</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|Win32">
-      <Configuration>Release</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-  </ItemGroup>
-  <PropertyGroup Label="Globals">
-    <ProjectGuid>{9EE22D66-C849-474C-9ED5-C3E141DAB160}</ProjectGuid>
-    <RootNamespace>transicc</RootNamespace>
-    <Keyword>Win32Proj</Keyword>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>Unicode</CharacterSet>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
-  <ImportGroup Label="ExtensionSettings">
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
-  </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <PropertyGroup>
-    <_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>
-    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\bin\</OutDir>
-    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
-    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
-    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\bin\</OutDir>
-    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
-    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
-    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
-    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
-    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
-    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
-    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
-    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
-  </PropertyGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <MinimalRebuild>true</MinimalRebuild>
-      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
-      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
-      <PrecompiledHeader>
-      </PrecompiledHeader>
-      <WarningLevel>Level4</WarningLevel>
-      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <SubSystem>Console</SubSystem>
-      <TargetMachine>MachineX86</TargetMachine>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-      <Optimization>MaxSpeed</Optimization>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <PrecompiledHeader>
-      </PrecompiledHeader>
-      <WarningLevel>Level4</WarningLevel>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <SubSystem>Console</SubSystem>
-      <OptimizeReferences>true</OptimizeReferences>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <TargetMachine>MachineX86</TargetMachine>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemGroup>
-    <ClCompile Include="..\..\..\utils\transicc\transicc.c" />
-    <ClCompile Include="..\..\..\utils\common\vprf.c" />
-    <ClCompile Include="..\..\..\utils\common\xgetopt.c" />
-  </ItemGroup>
-  <ItemGroup>
-    <ClInclude Include="..\..\..\utils\common\utils.h" />
-  </ItemGroup>
-  <ItemGroup>
-    <ProjectReference Include="..\lcms2_static\lcms2_static.vcxproj">
-      <Project>{71dede59-3f1e-486b-a899-4283000f76b5}</Project>
-      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
-    </ProjectReference>
-  </ItemGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <ItemGroup Label="ProjectConfigurations">\r
+    <ProjectConfiguration Include="Debug|Win32">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Debug|x64">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|Win32">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|x64">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+  </ItemGroup>\r
+  <PropertyGroup Label="Globals">\r
+    <ProjectGuid>{9EE22D66-C849-474C-9ED5-C3E141DAB160}</ProjectGuid>\r
+    <RootNamespace>transicc</RootNamespace>\r
+    <Keyword>Win32Proj</Keyword>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />\r
+  <ImportGroup Label="ExtensionSettings">\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />\r
+  </ImportGroup>\r
+  <PropertyGroup Label="UserMacros" />\r
+  <PropertyGroup>\r
+    <_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\bin\</OutDir>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\..\bin\</OutDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Configuration)\</IntDir>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\bin\</OutDir>\r
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\..\bin\</OutDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>\r
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Configuration)\</IntDir>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>\r
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet>\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />\r
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />\r
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />\r
+  </PropertyGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
+    <ClCompile>\r
+      <Optimization>Disabled</Optimization>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <MinimalRebuild>true</MinimalRebuild>\r
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\r
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <TargetMachine>MachineX86</TargetMachine>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">\r
+    <ClCompile>\r
+      <Optimization>Disabled</Optimization>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\r
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
+    <ClCompile>\r
+      <Optimization>MaxSpeed</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\r
+      <FunctionLevelLinking>true</FunctionLevelLinking>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+      <TargetMachine>MachineX86</TargetMachine>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">\r
+    <ClCompile>\r
+      <Optimization>MaxSpeed</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <AdditionalIncludeDirectories>../../../include;../../../utils/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\r
+      <FunctionLevelLinking>true</FunctionLevelLinking>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level4</WarningLevel>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+    </ClCompile>\r
+    <Link>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <SubSystem>Console</SubSystem>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemGroup>\r
+    <ClCompile Include="..\..\..\utils\transicc\transicc.c" />\r
+    <ClCompile Include="..\..\..\utils\common\vprf.c" />\r
+    <ClCompile Include="..\..\..\utils\common\xgetopt.c" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ClInclude Include="..\..\..\utils\common\utils.h" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ProjectReference Include="..\lcms2_static\lcms2_static.vcxproj">\r
+      <Project>{71dede59-3f1e-486b-a899-4283000f76b5}</Project>\r
+      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>\r
+    </ProjectReference>\r
+  </ItemGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\r
+  <ImportGroup Label="ExtensionTargets">\r
+  </ImportGroup>\r
 </Project>
\ No newline at end of file
index 338bd7b..e69de29 100755 (executable)
Binary files a/Projects/mac/._.DS_Store and b/Projects/mac/._.DS_Store differ
index 338bd7b..e69de29 100755 (executable)
Binary files a/Projects/mac/LittleCMS/._.DS_Store and b/Projects/mac/LittleCMS/._.DS_Store differ
index 875d35e..002d6a9 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
 <dict>
        <key>CFBundleDevelopmentRegion</key>
        <string>6.0</string>
        <key>CFBundlePackageType</key>
        <string>FMWK</string>
+       <key>CFBundleShortVersionString</key>
+       <string>1.01</string>
        <key>CFBundleSignature</key>
-       <string>????</string>
+       <string>lcms</string>
        <key>CFBundleVersion</key>
-       <string>1.0</string>
-        <key>CFBundleShortVersionString</key>
-        <string>1.01</string>
+       <string>2.4</string>
        <key>CSResourcesFileMapped</key>
        <true/>
 </dict>
index aabb78c..6e34d0a 100644 (file)
                        <key>Layout</key>
                        <array>
                                <dict>
+                                       <key>BecomeActive</key>
+                                       <true/>
                                        <key>ContentConfiguration</key>
                                        <dict>
                                                <key>PBXBottomSmartGroupGIDs</key>
                                                <dict>
                                                        <key>PBXSmartGroupTreeModuleOutlineStateExpansionKey</key>
                                                        <array>
+                                                               <string>0867D691FE84028FC02AAC07</string>
+                                                               <string>1C37FBAC04509CD000000102</string>
                                                                <string>1C37FABC05509CD000000102</string>
                                                                <string>E2644B35053B69B200211256</string>
                                                        </array>
                                                        <key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
                                                        <array>
                                                                <array>
-                                                                       <integer>0</integer>
+                                                                       <integer>7</integer>
+                                                                       <integer>6</integer>
                                                                </array>
                                                        </array>
                                                        <key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key>
-                                                       <string>{{0, 0}, {389, 970}}</string>
+                                                       <string>{{0, 0}, {389, 946}}</string>
                                                </dict>
                                                <key>PBXTopSmartGroupGIDs</key>
                                                <array/>
                                        <key>GeometryConfiguration</key>
                                        <dict>
                                                <key>Frame</key>
-                                               <string>{{0, 0}, {406, 988}}</string>
+                                               <string>{{0, 0}, {406, 964}}</string>
                                                <key>GroupTreeTableConfiguration</key>
                                                <array>
                                                        <string>MainColumn</string>
                                                        <real>389</real>
                                                </array>
                                                <key>RubberWindowFrame</key>
-                                               <string>0 149 1600 1029 0 0 1600 1178 </string>
+                                               <string>145 -306 1537 1005 0 0 1600 1178 </string>
                                        </dict>
                                        <key>Module</key>
                                        <string>PBXSmartGroupTreeModule</string>
                                                                <key>PBXProjectModuleGUID</key>
                                                                <string>1CE0B20306471E060097A5F4</string>
                                                                <key>PBXProjectModuleLabel</key>
-                                                               <string>cmsio0.c</string>
+                                                               <string>testcms2.c</string>
                                                                <key>PBXSplitModuleInNavigatorKey</key>
                                                                <dict>
                                                                        <key>Split0</key>
                                                                                <key>PBXProjectModuleGUID</key>
                                                                                <string>1CE0B20406471E060097A5F4</string>
                                                                                <key>PBXProjectModuleLabel</key>
-                                                                               <string>cmsio0.c</string>
+                                                                               <string>testcms2.c</string>
                                                                                <key>_historyCapacity</key>
                                                                                <integer>0</integer>
                                                                                <key>bookmark</key>
-                                                                               <string>546B2A0110AC6C9E0054D33A</string>
+                                                                               <string>54C0D5B915A2072100A94CDC</string>
                                                                                <key>history</key>
                                                                                <array>
                                                                                        <string>546B29DA10AC6B6E0054D33A</string>
-                                                                                       <string>546B29DB10AC6B6E0054D33A</string>
                                                                                        <string>546B29F510AC6C480054D33A</string>
-                                                                                       <string>546B29F710AC6C480054D33A</string>
+                                                                                       <string>54DBD07515A206A100180017</string>
                                                                                </array>
                                                                                <key>prevStack</key>
                                                                                <array>
                                                                                        <string>546B29E010AC6B6E0054D33A</string>
                                                                                        <string>546B29E110AC6B6E0054D33A</string>
-                                                                                       <string>546B29E210AC6B6E0054D33A</string>
-                                                                                       <string>546B29E310AC6B6E0054D33A</string>
                                                                                </array>
                                                                        </dict>
                                                                        <key>SplitCount</key>
                                                        <key>GeometryConfiguration</key>
                                                        <dict>
                                                                <key>Frame</key>
-                                                               <string>{{0, 0}, {1189, 19}}</string>
+                                                               <string>{{0, 0}, {1126, 0}}</string>
                                                                <key>RubberWindowFrame</key>
-                                                               <string>0 149 1600 1029 0 0 1600 1178 </string>
+                                                               <string>145 -306 1537 1005 0 0 1600 1178 </string>
                                                        </dict>
                                                        <key>Module</key>
                                                        <string>PBXNavigatorGroup</string>
                                                        <key>Proportion</key>
-                                                       <string>19pt</string>
+                                                       <string>0pt</string>
                                                </dict>
                                                <dict>
-                                                       <key>BecomeActive</key>
-                                                       <true/>
                                                        <key>ContentConfiguration</key>
                                                        <dict>
                                                                <key>PBXProjectModuleGUID</key>
                                                        <key>GeometryConfiguration</key>
                                                        <dict>
                                                                <key>Frame</key>
-                                                               <string>{{0, 24}, {1189, 964}}</string>
+                                                               <string>{{0, 5}, {1126, 959}}</string>
                                                                <key>RubberWindowFrame</key>
-                                                               <string>0 149 1600 1029 0 0 1600 1178 </string>
+                                                               <string>145 -306 1537 1005 0 0 1600 1178 </string>
                                                        </dict>
                                                        <key>Module</key>
                                                        <string>XCDetailModule</string>
                                                        <key>Proportion</key>
-                                                       <string>964pt</string>
+                                                       <string>959pt</string>
                                                </dict>
                                        </array>
                                        <key>Proportion</key>
-                                       <string>1189pt</string>
+                                       <string>1126pt</string>
                                </dict>
                        </array>
                        <key>Name</key>
                        </array>
                        <key>TableOfContents</key>
                        <array>
-                               <string>546B29FF10AC6C9E0054D33A</string>
+                               <string>54C0D5B315A206F900A94CDC</string>
                                <string>1CE0B1FE06471DED0097A5F4</string>
-                               <string>546B2A0010AC6C9E0054D33A</string>
+                               <string>54C0D5B415A206F900A94CDC</string>
                                <string>1CE0B20306471E060097A5F4</string>
                                <string>1CE0B20506471E060097A5F4</string>
                        </array>
        <key>StatusbarIsVisible</key>
        <true/>
        <key>TimeStamp</key>
-       <real>279735424.79254502</real>
+       <real>362940193.69248402</real>
        <key>ToolbarDisplayMode</key>
        <integer>1</integer>
        <key>ToolbarIsVisible</key>
        <integer>5</integer>
        <key>WindowOrderList</key>
        <array>
-               <string>/Users/mariama/lcms-2.0/Projects/mac/LittleCMS/LittleCMS.xcodeproj</string>
+               <string>546B297610AC61DD0054D33A</string>
+               <string>/Users/mariama/lcms2-2.4/Projects/mac/LittleCMS/LittleCMS.xcodeproj</string>
        </array>
        <key>WindowString</key>
-       <string>0 149 1600 1029 0 0 1600 1178 </string>
+       <string>145 -306 1537 1005 0 0 1600 1178 </string>
        <key>WindowToolsV3</key>
        <array>
                <dict>
                                                                <key>PBXProjectModuleGUID</key>
                                                                <string>1CD0528F0623707200166675</string>
                                                                <key>PBXProjectModuleLabel</key>
-                                                               <string>RunUnitTests</string>
+                                                               <string></string>
                                                                <key>StatusBarVisibility</key>
                                                                <true/>
                                                        </dict>
                                                                <key>Frame</key>
                                                                <string>{{0, 0}, {897, 417}}</string>
                                                                <key>RubberWindowFrame</key>
-                                                               <string>645 150 897 912 0 0 1600 1178 </string>
+                                                               <string>645 215 897 912 0 0 1600 1178 </string>
                                                        </dict>
                                                        <key>Module</key>
                                                        <string>PBXNavigatorGroup</string>
                                                                <key>Frame</key>
                                                                <string>{{0, 422}, {897, 449}}</string>
                                                                <key>RubberWindowFrame</key>
-                                                               <string>645 150 897 912 0 0 1600 1178 </string>
+                                                               <string>645 215 897 912 0 0 1600 1178 </string>
                                                        </dict>
                                                        <key>Module</key>
                                                        <string>PBXBuildResultsModule</string>
                        <key>TableOfContents</key>
                        <array>
                                <string>546B297610AC61DD0054D33A</string>
-                               <string>546B297710AC61DD0054D33A</string>
+                               <string>54C0D5B815A2071B00A94CDC</string>
                                <string>1CD0528F0623707200166675</string>
                                <string>XCMainBuildResultsModuleGUID</string>
                        </array>
                        <key>ToolbarConfiguration</key>
                        <string>xcode.toolbar.config.buildV3</string>
                        <key>WindowString</key>
-                       <string>645 150 897 912 0 0 1600 1178 </string>
+                       <string>645 215 897 912 0 0 1600 1178 </string>
                        <key>WindowToolGUID</key>
                        <string>546B297610AC61DD0054D33A</string>
                        <key>WindowToolIsVisible</key>
index 8991514..71ebaa9 100644 (file)
@@ -60,7 +60,7 @@
                                PBXFileTableDataSourceColumnSortingKey = PBXFileDataSource_Filename_ColumnID;
                                PBXFileTableDataSourceColumnWidthsKey = (
                                        20,
-                                       950,
+                                       887,
                                        20,
                                        48,
                                        43,
                                PBXFileTableDataSourceColumnSortingKey = PBXFileDataSource_Filename_ColumnID;
                                PBXFileTableDataSourceColumnWidthsKey = (
                                        20,
-                                       910,
+                                       847,
                                        60,
                                        20,
                                        48,
                                        PBXFileDataSource_Warnings_ColumnID,
                                );
                        };
-                       PBXPerProjectTemplateStateSaveDate = 279735424;
-                       PBXWorkspaceStateSaveDate = 279735424;
+                       PBXPerProjectTemplateStateSaveDate = 362940143;
+                       PBXWorkspaceStateSaveDate = 362940143;
                };
                perUserProjectItems = {
-                       546B29DA10AC6B6E0054D33A /* PBXTextBookmark */ = 546B29DA10AC6B6E0054D33A /* PBXTextBookmark */;
-                       546B29DB10AC6B6E0054D33A /* PBXTextBookmark */ = 546B29DB10AC6B6E0054D33A /* PBXTextBookmark */;
-                       546B29E010AC6B6E0054D33A /* PBXTextBookmark */ = 546B29E010AC6B6E0054D33A /* PBXTextBookmark */;
-                       546B29E110AC6B6E0054D33A /* PBXTextBookmark */ = 546B29E110AC6B6E0054D33A /* PBXTextBookmark */;
-                       546B29E210AC6B6E0054D33A /* PBXTextBookmark */ = 546B29E210AC6B6E0054D33A /* PBXTextBookmark */;
-                       546B29E310AC6B6E0054D33A /* PBXTextBookmark */ = 546B29E310AC6B6E0054D33A /* PBXTextBookmark */;
-                       546B29F510AC6C480054D33A /* PBXTextBookmark */ = 546B29F510AC6C480054D33A /* PBXTextBookmark */;
-                       546B29F710AC6C480054D33A /* PBXTextBookmark */ = 546B29F710AC6C480054D33A /* PBXTextBookmark */;
-                       546B2A0110AC6C9E0054D33A /* PBXTextBookmark */ = 546B2A0110AC6C9E0054D33A /* PBXTextBookmark */;
+                       546B29DA10AC6B6E0054D33A = 546B29DA10AC6B6E0054D33A /* PBXTextBookmark */;
+                       546B29E010AC6B6E0054D33A = 546B29E010AC6B6E0054D33A /* PBXTextBookmark */;
+                       546B29E110AC6B6E0054D33A = 546B29E110AC6B6E0054D33A /* PBXTextBookmark */;
+                       546B29E210AC6B6E0054D33A = 546B29E210AC6B6E0054D33A /* PBXTextBookmark */;
+                       546B29F510AC6C480054D33A = 546B29F510AC6C480054D33A /* PBXTextBookmark */;
+                       54C0D5B215A206F900A94CDC /* PBXTextBookmark */ = 54C0D5B215A206F900A94CDC /* PBXTextBookmark */;
+                       54C0D5B915A2072100A94CDC /* PBXTextBookmark */ = 54C0D5B915A2072100A94CDC /* PBXTextBookmark */;
+                       54DBD07515A206A100180017 = 54DBD07515A206A100180017 /* PBXTextBookmark */;
                };
                sourceControlManager = 546B292F10AC5E210054D33A /* Source Control */;
                userBuildSettings = {
        };
        546B293810AC5E4A0054D33A /* cmsio0.c */ = {
                uiCtxt = {
-                       sepNavIntBoundsRect = "{{0, 0}, {1128, 23044}}";
+                       sepNavIntBoundsRect = "{{0, 0}, {1065, 24374}}";
                        sepNavSelRange = "{25921, 0}";
                        sepNavVisRange = "{0, 0}";
                };
        };
        546B29AD10AC68410054D33A /* testcms2.c */ = {
                uiCtxt = {
-                       sepNavIntBoundsRect = "{{0, 0}, {710, 93590}}";
+                       sepNavIntBoundsRect = "{{0, 0}, {1065, 110054}}";
                        sepNavSelRange = "{0, 0}";
-                       sepNavVisRange = "{0, 1115}";
+                       sepNavVisRange = "{0, 0}";
                        sepNavWindowFrame = "{{61, 247}, {1099, 884}}";
                };
        };
                vrLen = 172;
                vrLoc = 9140;
        };
-       546B29DB10AC6B6E0054D33A /* PBXTextBookmark */ = {
-               isa = PBXTextBookmark;
-               fRef = 546B29AD10AC68410054D33A /* testcms2.c */;
-               name = "testcms2.c: 1";
-               rLen = 0;
-               rLoc = 0;
-               rType = 0;
-               vrLen = 1115;
-               vrLoc = 0;
-       };
        546B29E010AC6B6E0054D33A /* PBXTextBookmark */ = {
                isa = PBXTextBookmark;
                fRef = 546B299D10AC672A0054D33A /* RunUnitTests */;
                vrLen = 1115;
                vrLoc = 0;
        };
-       546B29E310AC6B6E0054D33A /* PBXTextBookmark */ = {
-               isa = PBXTextBookmark;
-               fRef = 546B293810AC5E4A0054D33A /* cmsio0.c */;
-               name = "cmsio0.c: 845";
-               rLen = 0;
-               rLoc = 25921;
-               rType = 0;
-               vrLen = 982;
-               vrLoc = 25453;
-       };
        546B29F510AC6C480054D33A /* PBXTextBookmark */ = {
                isa = PBXTextBookmark;
                fRef = 546B296B10AC5EAA0054D33A /* TestBed-Info.plist */;
                vrLen = 671;
                vrLoc = 0;
        };
-       546B29F710AC6C480054D33A /* PBXTextBookmark */ = {
+       54C0D5B215A206F900A94CDC /* PBXTextBookmark */ = {
+               isa = PBXTextBookmark;
+               fRef = 546B29AD10AC68410054D33A /* testcms2.c */;
+               name = "testcms2.c: 1";
+               rLen = 0;
+               rLoc = 0;
+               rType = 0;
+               vrLen = 0;
+               vrLoc = 0;
+       };
+       54C0D5B915A2072100A94CDC /* PBXTextBookmark */ = {
                isa = PBXTextBookmark;
-               fRef = 546B293810AC5E4A0054D33A /* cmsio0.c */;
-               name = "cmsio0.c: 845";
+               fRef = 546B29AD10AC68410054D33A /* testcms2.c */;
+               name = "testcms2.c: 1";
                rLen = 0;
-               rLoc = 25921;
+               rLoc = 0;
                rType = 0;
-               vrLen = 1922;
+               vrLen = 0;
                vrLoc = 0;
        };
-       546B2A0110AC6C9E0054D33A /* PBXTextBookmark */ = {
+       54DBD07515A206A100180017 /* PBXTextBookmark */ = {
                isa = PBXTextBookmark;
-               fRef = 546B293810AC5E4A0054D33A /* cmsio0.c */;
-               name = "cmsio0.c: 845";
+               fRef = 546B29AD10AC68410054D33A /* testcms2.c */;
+               name = "testcms2.c: 1";
                rLen = 0;
-               rLoc = 25921;
+               rLoc = 0;
                rType = 0;
                vrLen = 0;
                vrLoc = 0;
index a9fa0a5..44b52b8 100644 (file)
@@ -34,6 +34,8 @@
                546B296310AC5E600054D33A /* lcms2.h in Headers */ = {isa = PBXBuildFile; fileRef = 546B296110AC5E600054D33A /* lcms2.h */; settings = {ATTRIBUTES = (Public, ); }; };
                546B296410AC5E600054D33A /* lcms2_plugin.h in Headers */ = {isa = PBXBuildFile; fileRef = 546B296210AC5E600054D33A /* lcms2_plugin.h */; settings = {ATTRIBUTES = (Public, ); }; };
                546B29AE10AC68410054D33A /* testcms2.c in Sources */ = {isa = PBXBuildFile; fileRef = 546B29AD10AC68410054D33A /* testcms2.c */; };
+               54DBD06115A202B200180017 /* cmshalf.c in Sources */ = {isa = PBXBuildFile; fileRef = 54DBD06015A202B200180017 /* cmshalf.c */; };
+               54DBD06215A202BB00180017 /* cmshalf.c in Sources */ = {isa = PBXBuildFile; fileRef = 54DBD06015A202B200180017 /* cmshalf.c */; };
                8D07F2BE0486CC7A007CD1D0 /* LittleCMS_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = 32BAE0B70371A74B00C91783 /* LittleCMS_Prefix.pch */; settings = {ATTRIBUTES = (Private, ); }; };
                8D07F2C00486CC7A007CD1D0 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C1666FE841158C02AAC07 /* InfoPlist.strings */; };
                8D07F2C40486CC7A007CD1D0 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08FB77AAFE841565C02AAC07 /* Carbon.framework */; };
@@ -83,6 +85,7 @@
                546B29A310AC677E0054D33A /* testbed */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = testbed; sourceTree = BUILT_PRODUCTS_DIR; };
                546B29AC10AC682F0054D33A /* lcms2_internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = lcms2_internal.h; path = ../../../src/lcms2_internal.h; sourceTree = SOURCE_ROOT; };
                546B29AD10AC68410054D33A /* testcms2.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testcms2.c; path = ../../../testbed/testcms2.c; sourceTree = SOURCE_ROOT; };
+               54DBD06015A202B200180017 /* cmshalf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = cmshalf.c; path = ../../../src/cmshalf.c; sourceTree = "<group>"; };
                8D07F2C70486CC7A007CD1D0 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
                8D07F2C80486CC7A007CD1D0 /* LittleCMS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LittleCMS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
 /* End PBXFileReference section */
                08FB77ACFE841707C02AAC07 /* Source */ = {
                        isa = PBXGroup;
                        children = (
+                               54DBD06015A202B200180017 /* cmshalf.c */,
                                546B29AD10AC68410054D33A /* testcms2.c */,
                                546B29AC10AC682F0054D33A /* lcms2_internal.h */,
                                546B296110AC5E600054D33A /* lcms2.h */,
                        buildActionMask = 2147483647;
                        files = (
                                546B29AE10AC68410054D33A /* testcms2.c in Sources */,
+                               54DBD06115A202B200180017 /* cmshalf.c in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                546B295E10AC5E4A0054D33A /* cmsvirt.c in Sources */,
                                546B295F10AC5E4A0054D33A /* cmswtpnt.c in Sources */,
                                546B296010AC5E4A0054D33A /* cmsxform.c in Sources */,
+                               54DBD06215A202BB00180017 /* cmshalf.c in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                DYLIB_COMPATIBILITY_VERSION = 1;
                                DYLIB_CURRENT_VERSION = 1;
                                FRAMEWORK_VERSION = A;
+                               GCC_CHAR_IS_UNSIGNED_CHAR = YES;
                                GCC_DYNAMIC_NO_PIC = NO;
                                GCC_ENABLE_FIX_AND_CONTINUE = YES;
                                GCC_MODEL_TUNING = G5;
                                DYLIB_COMPATIBILITY_VERSION = 1;
                                DYLIB_CURRENT_VERSION = 1;
                                FRAMEWORK_VERSION = A;
+                               GCC_CHAR_IS_UNSIGNED_CHAR = YES;
                                GCC_MODEL_TUNING = G5;
                                GCC_PRECOMPILE_PREFIX_HEADER = YES;
                                GCC_PREFIX_HEADER = LittleCMS_Prefix.pch;
index a9f53ea..a69c418 100644 (file)
@@ -1,7 +1,8 @@
-# generated automatically by aclocal 1.11.1 -*- Autoconf -*-
+# generated automatically by aclocal 1.11.3 -*- Autoconf -*-
 
 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-# 2005, 2006, 2007, 2008, 2009  Free Software Foundation, Inc.
+# 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
+# Inc.
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -8446,12 +8447,15 @@ m4_ifndef([_LT_PROG_F77],               [AC_DEFUN([_LT_PROG_F77])])
 m4_ifndef([_LT_PROG_FC],               [AC_DEFUN([_LT_PROG_FC])])
 m4_ifndef([_LT_PROG_CXX],              [AC_DEFUN([_LT_PROG_CXX])])
 
-# Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008  Free Software Foundation, Inc.
+# Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008, 2011 Free Software
+# Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
+# serial 1
+
 # AM_AUTOMAKE_VERSION(VERSION)
 # ----------------------------
 # Automake X.Y traces this macro to ensure aclocal.m4 has been
@@ -8461,7 +8465,7 @@ AC_DEFUN([AM_AUTOMAKE_VERSION],
 [am__api_version='1.11'
 dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
 dnl require some minimum version.  Point them to the right macro.
-m4_if([$1], [1.11.1], [],
+m4_if([$1], [1.11.3], [],
       [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
 ])
 
@@ -8477,19 +8481,21 @@ m4_define([_AM_AUTOCONF_VERSION], [])
 # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
 # This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
 AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
-[AM_AUTOMAKE_VERSION([1.11.1])dnl
+[AM_AUTOMAKE_VERSION([1.11.3])dnl
 m4_ifndef([AC_AUTOCONF_VERSION],
   [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
 _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
 
 # AM_AUX_DIR_EXPAND                                         -*- Autoconf -*-
 
-# Copyright (C) 2001, 2003, 2005  Free Software Foundation, Inc.
+# Copyright (C) 2001, 2003, 2005, 2011 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
+# serial 1
+
 # For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets
 # $ac_aux_dir to `$srcdir/foo'.  In other projects, it is set to
 # `$srcdir', `$srcdir/..', or `$srcdir/../..'.
@@ -8571,14 +8577,14 @@ AC_CONFIG_COMMANDS_PRE(
 Usually this means the macro was only invoked conditionally.]])
 fi])])
 
-# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009
-# Free Software Foundation, Inc.
+# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009,
+# 2010, 2011 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
-# serial 10
+# serial 12
 
 # There are a few dirty hacks below to avoid letting `AC_PROG_CC' be
 # written in clear, in which case automake, when reading aclocal.m4,
@@ -8618,6 +8624,7 @@ AC_CACHE_CHECK([dependency style of $depcc],
   # instance it was reported that on HP-UX the gcc test will end up
   # making a dummy file named `D' -- because `-MD' means `put the output
   # in D'.
+  rm -rf conftest.dir
   mkdir conftest.dir
   # Copy depcomp to subdir because otherwise we won't find it if we're
   # using a relative directory.
@@ -8682,7 +8689,7 @@ AC_CACHE_CHECK([dependency style of $depcc],
        break
       fi
       ;;
-    msvisualcpp | msvcmsys)
+    msvc7 | msvc7msys | msvisualcpp | msvcmsys)
       # This compiler won't grok `-c -o', but also, the minuso test has
       # not run yet.  These depmodes are late enough in the game, and
       # so weak that their functioning should not be impacted.
@@ -8747,10 +8754,13 @@ AC_DEFUN([AM_DEP_TRACK],
 if test "x$enable_dependency_tracking" != xno; then
   am_depcomp="$ac_aux_dir/depcomp"
   AMDEPBACKSLASH='\'
+  am__nodep='_no'
 fi
 AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno])
 AC_SUBST([AMDEPBACKSLASH])dnl
 _AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl
+AC_SUBST([am__nodep])dnl
+_AM_SUBST_NOTMAKE([am__nodep])dnl
 ])
 
 # Generate code to set up dependency tracking.              -*- Autoconf -*-
@@ -8972,12 +8982,15 @@ for _am_header in $config_headers :; do
 done
 echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
 
-# Copyright (C) 2001, 2003, 2005, 2008  Free Software Foundation, Inc.
+# Copyright (C) 2001, 2003, 2005, 2008, 2011 Free Software Foundation,
+# Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
+# serial 1
+
 # AM_PROG_INSTALL_SH
 # ------------------
 # Define $install_sh.
@@ -9017,8 +9030,8 @@ AC_SUBST([am__leading_dot])])
 # Add --enable-maintainer-mode option to configure.         -*- Autoconf -*-
 # From Jim Meyering
 
-# Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2008
-# Free Software Foundation, Inc.
+# Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2008,
+# 2011 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -9038,7 +9051,7 @@ AC_DEFUN([AM_MAINTAINER_MODE],
        [disable], [m4_define([am_maintainer_other], [enable])],
        [m4_define([am_maintainer_other], [enable])
         m4_warn([syntax], [unexpected argument to AM@&t@_MAINTAINER_MODE: $1])])
-AC_MSG_CHECKING([whether to am_maintainer_other maintainer-specific portions of Makefiles])
+AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles])
   dnl maintainer-mode's default is 'disable' unless 'enable' is passed
   AC_ARG_ENABLE([maintainer-mode],
 [  --][am_maintainer_other][-maintainer-mode  am_maintainer_other make rules and dependencies not useful
@@ -9149,12 +9162,15 @@ else
 fi
 ])
 
-# Copyright (C) 2003, 2004, 2005, 2006  Free Software Foundation, Inc.
+# Copyright (C) 2003, 2004, 2005, 2006, 2011 Free Software Foundation,
+# Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
+# serial 1
+
 # AM_PROG_MKDIR_P
 # ---------------
 # Check for `mkdir -p'.
@@ -9177,13 +9193,14 @@ esac
 
 # Helper functions for option handling.                     -*- Autoconf -*-
 
-# Copyright (C) 2001, 2002, 2003, 2005, 2008  Free Software Foundation, Inc.
+# Copyright (C) 2001, 2002, 2003, 2005, 2008, 2010 Free Software
+# Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
-# serial 4
+# serial 5
 
 # _AM_MANGLE_OPTION(NAME)
 # -----------------------
@@ -9191,13 +9208,13 @@ AC_DEFUN([_AM_MANGLE_OPTION],
 [[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])])
 
 # _AM_SET_OPTION(NAME)
-# ------------------------------
+# --------------------
 # Set option NAME.  Presently that only means defining a flag for this option.
 AC_DEFUN([_AM_SET_OPTION],
 [m4_define(_AM_MANGLE_OPTION([$1]), 1)])
 
 # _AM_SET_OPTIONS(OPTIONS)
-# ----------------------------------
+# ------------------------
 # OPTIONS is a space-separated list of Automake options.
 AC_DEFUN([_AM_SET_OPTIONS],
 [m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])])
@@ -9273,12 +9290,14 @@ Check your system clock])
 fi
 AC_MSG_RESULT(yes)])
 
-# Copyright (C) 2001, 2003, 2005  Free Software Foundation, Inc.
+# Copyright (C) 2001, 2003, 2005, 2011 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
+# serial 1
+
 # AM_PROG_INSTALL_STRIP
 # ---------------------
 # One issue with vendor `install' (even GNU) is that you can't
@@ -9301,13 +9320,13 @@ fi
 INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
 AC_SUBST([INSTALL_STRIP_PROGRAM])])
 
-# Copyright (C) 2006, 2008  Free Software Foundation, Inc.
+# Copyright (C) 2006, 2008, 2010 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
-# serial 2
+# serial 3
 
 # _AM_SUBST_NOTMAKE(VARIABLE)
 # ---------------------------
@@ -9316,13 +9335,13 @@ AC_SUBST([INSTALL_STRIP_PROGRAM])])
 AC_DEFUN([_AM_SUBST_NOTMAKE])
 
 # AM_SUBST_NOTMAKE(VARIABLE)
-# ---------------------------
+# --------------------------
 # Public sister of _AM_SUBST_NOTMAKE.
 AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
 
 # Check how to create a tarball.                            -*- Autoconf -*-
 
-# Copyright (C) 2004, 2005  Free Software Foundation, Inc.
+# Copyright (C) 2004, 2005, 2012 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -9344,10 +9363,11 @@ AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
 # a tarball read from stdin.
 #     $(am__untar) < result.tar
 AC_DEFUN([_AM_PROG_TAR],
-[# Always define AMTAR for backward compatibility.
-AM_MISSING_PROG([AMTAR], [tar])
+[# Always define AMTAR for backward compatibility.  Yes, it's still used
+# in the wild :-(  We should find a proper way to deprecate it ...
+AC_SUBST([AMTAR], ['$${TAR-tar}'])
 m4_if([$1], [v7],
-     [am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'],
+     [am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'],
      [m4_case([$1], [ustar],, [pax],,
               [m4_fatal([Unknown tar format])])
 AC_MSG_CHECKING([how to create a $1 tar archive])
index 7e14486..f2c2e59 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.68 for lcms2 2.3.
+# Generated by GNU Autoconf 2.68 for lcms2 2.4.
 #
 #
 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
@@ -567,8 +567,8 @@ MAKEFLAGS=
 # Identity of this package.
 PACKAGE_NAME='lcms2'
 PACKAGE_TARNAME='lcms2'
-PACKAGE_VERSION='2.3'
-PACKAGE_STRING='lcms2 2.3'
+PACKAGE_VERSION='2.4'
+PACKAGE_STRING='lcms2 2.4'
 PACKAGE_BUGREPORT=''
 PACKAGE_URL=''
 
@@ -663,6 +663,7 @@ CPP
 am__fastdepCC_FALSE
 am__fastdepCC_TRUE
 CCDEPMODE
+am__nodep
 AMDEPBACKSLASH
 AMDEP_FALSE
 AMDEP_TRUE
@@ -1319,7 +1320,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures lcms2 2.3 to adapt to many kinds of systems.
+\`configure' configures lcms2 2.4 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1389,7 +1390,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of lcms2 2.3:";;
+     short | recursive ) echo "Configuration of lcms2 2.4:";;
    esac
   cat <<\_ACEOF
 
@@ -1498,7 +1499,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-lcms2 configure 2.3
+lcms2 configure 2.4
 generated by GNU Autoconf 2.68
 
 Copyright (C) 2010 Free Software Foundation, Inc.
@@ -1984,7 +1985,7 @@ cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by lcms2 $as_me 2.3, which was
+It was created by lcms2 $as_me 2.4, which was
 generated by GNU Autoconf 2.68.  Invocation command line was
 
   $ $0 $@
@@ -2355,7 +2356,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 #     then set age to 0.
 #
 LIBRARY_CURRENT=2
-LIBRARY_REVISION=3
+LIBRARY_REVISION=4
 LIBRARY_AGE=0
 
 
@@ -2899,7 +2900,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE='lcms2'
- VERSION='2.3'
+ VERSION='2.4'
 
 
 # Some tools Automake needs.
@@ -2920,11 +2921,11 @@ MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"}
 
 # We need awk for the "check" target.  The system "awk" is bad on
 # some platforms.
-# Always define AMTAR for backward compatibility.
+# Always define AMTAR for backward compatibility.  Yes, it's still used
+# in the wild :-(  We should find a proper way to deprecate it ...
+AMTAR='$${TAR-tar}'
 
-AMTAR=${AMTAR-"${am_missing_run}tar"}
-
-am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'
+am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'
 
 
 
@@ -3014,6 +3015,7 @@ fi
 if test "x$enable_dependency_tracking" != xno; then
   am_depcomp="$ac_aux_dir/depcomp"
   AMDEPBACKSLASH='\'
+  am__nodep='_no'
 fi
  if test "x$enable_dependency_tracking" != xno; then
   AMDEP_TRUE=
@@ -3827,6 +3829,7 @@ else
   # instance it was reported that on HP-UX the gcc test will end up
   # making a dummy file named `D' -- because `-MD' means `put the output
   # in D'.
+  rm -rf conftest.dir
   mkdir conftest.dir
   # Copy depcomp to subdir because otherwise we won't find it if we're
   # using a relative directory.
@@ -3886,7 +3889,7 @@ else
        break
       fi
       ;;
-    msvisualcpp | msvcmsys)
+    msvc7 | msvc7msys | msvisualcpp | msvcmsys)
       # This compiler won't grok `-c -o', but also, the minuso test has
       # not run yet.  These depmodes are late enough in the game, and
       # so weak that their functioning should not be impacted.
@@ -4641,6 +4644,7 @@ else
   # instance it was reported that on HP-UX the gcc test will end up
   # making a dummy file named `D' -- because `-MD' means `put the output
   # in D'.
+  rm -rf conftest.dir
   mkdir conftest.dir
   # Copy depcomp to subdir because otherwise we won't find it if we're
   # using a relative directory.
@@ -4700,7 +4704,7 @@ else
        break
       fi
       ;;
-    msvisualcpp | msvcmsys)
+    msvc7 | msvc7msys | msvisualcpp | msvcmsys)
       # This compiler won't grok `-c -o', but also, the minuso test has
       # not run yet.  These depmodes are late enough in the game, and
       # so weak that their functioning should not be impacted.
@@ -17248,7 +17252,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by lcms2 $as_me 2.3, which was
+This file was extended by lcms2 $as_me 2.4, which was
 generated by GNU Autoconf 2.68.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -17305,7 +17309,7 @@ _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
-lcms2 config.status 2.3
+lcms2 config.status 2.4
 configured by $0, generated by GNU Autoconf 2.68,
   with options \\"\$ac_cs_config\\"
 
index 8e0b2b8..055d86a 100644 (file)
@@ -7,7 +7,7 @@ AC_PREREQ(2.60)
 #
 # Set the package name and version
 #
-AC_INIT(lcms2,2.3)
+AC_INIT(lcms2,2.4)
 
 #
 # Libtool library revision control info
@@ -31,7 +31,7 @@ AC_INIT(lcms2,2.3)
 #     then set age to 0.
 #
 LIBRARY_CURRENT=2
-LIBRARY_REVISION=3
+LIBRARY_REVISION=4
 LIBRARY_AGE=0
 
 AC_SUBST(LIBRARY_CURRENT)dnl
diff --git a/doc/LittleCMS2.3 API.pdf b/doc/LittleCMS2.3 API.pdf
deleted file mode 100755 (executable)
index ec17957..0000000
Binary files a/doc/LittleCMS2.3 API.pdf and /dev/null differ
diff --git a/doc/LittleCMS2.3 Plugin API.pdf b/doc/LittleCMS2.3 Plugin API.pdf
deleted file mode 100755 (executable)
index 02fecdc..0000000
Binary files a/doc/LittleCMS2.3 Plugin API.pdf and /dev/null differ
diff --git a/doc/LittleCMS2.3 tutorial.pdf b/doc/LittleCMS2.3 tutorial.pdf
deleted file mode 100755 (executable)
index 4ad11b5..0000000
Binary files a/doc/LittleCMS2.3 tutorial.pdf and /dev/null differ
diff --git a/doc/LittleCMS2.4 API.pdf b/doc/LittleCMS2.4 API.pdf
new file mode 100755 (executable)
index 0000000..232ad75
Binary files /dev/null and b/doc/LittleCMS2.4 API.pdf differ
diff --git a/doc/LittleCMS2.4 Plugin API.pdf b/doc/LittleCMS2.4 Plugin API.pdf
new file mode 100755 (executable)
index 0000000..dc73d93
Binary files /dev/null and b/doc/LittleCMS2.4 Plugin API.pdf differ
diff --git a/doc/LittleCMS2.4 tutorial.pdf b/doc/LittleCMS2.4 tutorial.pdf
new file mode 100755 (executable)
index 0000000..ee6830a
Binary files /dev/null and b/doc/LittleCMS2.4 tutorial.pdf differ
index 76fc248..eb20dfc 100644 (file)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.3 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -71,6 +71,12 @@ am__nobase_list = $(am__nobase_strip_setup); \
 am__base_list = \
   sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
   sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__uninstall_files_from_dir = { \
+  test -z "$$files" \
+    || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
+    || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
+         $(am__cd) "$$dir" && rm -f $$files; }; \
+  }
 am__installdirs = "$(DESTDIR)$(includedir)"
 HEADERS = $(include_HEADERS)
 ETAGS = etags
@@ -266,9 +272,7 @@ uninstall-includeHEADERS:
        @$(NORMAL_UNINSTALL)
        @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \
        files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
-       test -n "$$files" || exit 0; \
-       echo " ( cd '$(DESTDIR)$(includedir)' && rm -f" $$files ")"; \
-       cd "$(DESTDIR)$(includedir)" && rm -f $$files
+       dir='$(DESTDIR)$(includedir)'; $(am__uninstall_files_from_dir)
 
 ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
        list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
@@ -369,10 +373,15 @@ install-am: all-am
 
 installcheck: installcheck-am
 install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-         install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-         `test -z '$(STRIP)' || \
-           echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
 mostlyclean-generic:
 
 clean-generic:
index 6ef2815..a0ad4f1 100644 (file)
@@ -23,7 +23,7 @@
 //
 //---------------------------------------------------------------------------------
 //
-// Version 2.3
+// Version 2.4
 //
 
 #ifndef _lcms2_H
@@ -52,6 +52,9 @@
 // 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
+
 // ********** End of configuration toggles ******************************
 
 // Needed for streams
@@ -69,7 +72,7 @@ extern "C" {
 #endif
 
 // Version/release
-#define LCMS_VERSION        2030
+#define LCMS_VERSION        2040
 
 // I will give the chance of redefining basic types for compilers that are not fully C99 compliant
 #ifndef CMS_BASIC_TYPES_ALREADY_DEFINED
@@ -78,9 +81,9 @@ extern "C" {
 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 
+#if CHAR_BIT != 8
 #  error "Unable to find 8 bit type, unsupported compiler"
-#endif 
+#endif
 
 // IEEE float storage numbers
 typedef float                cmsFloat32Number;
@@ -182,8 +185,10 @@ typedef int                  cmsBool;
 #   define CMS_USE_BIG_ENDIAN   1
 #endif
 
-#if TARGET_CPU_PPC
+#ifdef TARGET_CPU_PPC
+# if TARGET_CPU_PPC
 #   define CMS_USE_BIG_ENDIAN   1
+# endif
 #endif
 
 #ifdef macintosh
@@ -274,11 +279,11 @@ typedef enum {
     cmsSigUInt16ArrayType                   = 0x75693136,  // 'ui16'
     cmsSigUInt32ArrayType                   = 0x75693332,  // 'ui32'
     cmsSigUInt64ArrayType                   = 0x75693634,  // 'ui64'
-    cmsSigUInt8ArrayType                    = 0x75693038,  // 'ui08' 
+    cmsSigUInt8ArrayType                    = 0x75693038,  // 'ui08'
     cmsSigVcgtType                          = 0x76636774,  // 'vcgt'
     cmsSigViewingConditionsType             = 0x76696577,  // 'view'
     cmsSigXYZType                           = 0x58595A20   // 'XYZ '
-   
+
 
 } cmsTagTypeSignature;
 
@@ -487,7 +492,13 @@ typedef enum {
     cmsSigLabV4toV2                     = 0x34203220,  // '4 2 '
 
     // Identities
-    cmsSigIdentityElemType              = 0x69646E20   // 'idn '
+    cmsSigIdentityElemType              = 0x69646E20,  // 'idn '
+
+    // Float to floatPCS
+    cmsSigLab2FloatPCS                  = 0x64326C20,  // 'd2l '
+    cmsSigFloatPCS2Lab                  = 0x6C326420,  // 'l2d '
+    cmsSigXYZ2FloatPCS                  = 0x64327820,  // 'd2x '
+    cmsSigFloatPCS2XYZ                  = 0x78326420   // 'x2d '
 
 } cmsStageSignature;
 
@@ -611,7 +622,7 @@ typedef void* cmsHTRANSFORM;
 // 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  
+//                          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
@@ -720,16 +731,19 @@ typedef void* cmsHTRANSFORM;
 #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)|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))
@@ -811,8 +825,8 @@ typedef void* cmsHTRANSFORM;
 #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)|DOSWAP_SH(1))
-#define TYPE_ALabV2_8          (COLORSPACE_SH(PT_LabV2)|CHANNELS_SH(3)|BYTES_SH(1)|EXTRA_SH(1)|DOSWAP_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))
@@ -850,22 +864,40 @@ typedef void* cmsHTRANSFORM;
 
 // Float formatters.
 #define TYPE_XYZ_FLT          (FLOAT_SH(1)|COLORSPACE_SH(PT_XYZ)|CHANNELS_SH(3)|BYTES_SH(4))
-#define TYPE_XYZA_FLT         (FLOAT_SH(1)|COLORSPACE_SH(PT_XYZ)|EXTRA_SH(1)|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.  
+// 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
@@ -1096,6 +1128,10 @@ CMSAPI cmsBool           CMSEXPORT cmsIsToneCurveDescending(const cmsToneCurve*
 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 -------------------------------------------------------------
 
@@ -1108,6 +1144,7 @@ CMSAPI cmsPipeline*      CMSEXPORT cmsPipelineAlloc(cmsContext ContextID, cmsUIn
 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);
 
@@ -1168,10 +1205,9 @@ typedef cmsInt32Number (* cmsSAMPLERFLOAT)(register const cmsFloat32Number In[],
 #define SAMPLER_INSPECT     0x01000000
 
 // For CLUT only
-CMSAPI cmsBool           CMSEXPORT cmsStageSampleCLut16bit(cmsStage* mpe,    cmsSAMPLER16 Sampler,    void* Cargo, cmsUInt32Number dwFlags);
+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);
@@ -1281,6 +1317,7 @@ CMSAPI cmsNAMEDCOLORLIST* CMSEXPORT cmsGetNamedColorList(cmsHTRANSFORM xform);
 // 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;
@@ -1344,9 +1381,9 @@ CMSAPI cmsInt32Number    CMSEXPORT cmsReadRawTag(cmsHPROFILE hProfile, cmsTagSig
 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 cmsEmbeddedProfileFalse    0x00000000
+#define cmsEmbeddedProfileTrue     0x00000001
+#define cmsUseAnywhere             0x00000000
 #define cmsUseWithEmbeddedDataOnly 0x00000002
 
 CMSAPI cmsUInt32Number   CMSEXPORT cmsGetHeaderFlags(cmsHPROFILE hProfile);
@@ -1632,6 +1669,13 @@ CMSAPI void             CMSEXPORT cmsDoTransform(cmsHTRANSFORM Transform,
                                                  void * OutputBuffer,
                                                  cmsUInt32Number Size);
 
+CMSAPI void             CMSEXPORT cmsDoTransformStride(cmsHTRANSFORM Transform,
+                                                 const void * InputBuffer,
+                                                 void * OutputBuffer,
+                                                 cmsUInt32Number Size,
+                                                 cmsUInt32Number Stride);
+
+
 CMSAPI void             CMSEXPORT cmsSetAlarmCodes(cmsUInt16Number NewAlarm[cmsMAXCHANNELS]);
 CMSAPI void             CMSEXPORT cmsGetAlarmCodes(cmsUInt16Number NewAlarm[cmsMAXCHANNELS]);
 
@@ -1646,8 +1690,8 @@ CMSAPI cmsUInt32Number CMSEXPORT cmsGetTransformInputFormat(cmsHTRANSFORM hTrans
 CMSAPI cmsUInt32Number CMSEXPORT cmsGetTransformOutputFormat(cmsHTRANSFORM hTransform);
 
 // For backwards compatibility
-CMSAPI cmsBool          CMSEXPORT cmsChangeBuffersFormat(cmsHTRANSFORM hTransform, 
-                                                         cmsUInt32Number InputFormat, 
+CMSAPI cmsBool          CMSEXPORT cmsChangeBuffersFormat(cmsHTRANSFORM hTransform,
+                                                         cmsUInt32Number InputFormat,
                                                          cmsUInt32Number OutputFormat);
 
 
@@ -1694,12 +1738,15 @@ CMSAPI cmsBool          CMSEXPORT cmsIT8SetComment(cmsHANDLE hIT8, const char* c
 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);
@@ -1729,10 +1776,13 @@ CMSAPI cmsBool          CMSEXPORT cmsIT8SetDataFormat(cmsHANDLE hIT8, int n, con
 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);
 
@@ -1748,6 +1798,7 @@ CMSAPI cmsBool          CMSEXPORT cmsGDBCheckPoint(cmsHANDLE hGBD, const cmsCIEL
 
 // 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);
index 340f27c..10e61cb 100644 (file)
@@ -131,7 +131,7 @@ struct _cms_io_handler {
 // Endianess adjust functions
 CMSAPI cmsUInt16Number   CMSEXPORT  _cmsAdjustEndianess16(cmsUInt16Number Word);
 CMSAPI cmsUInt32Number   CMSEXPORT  _cmsAdjustEndianess32(cmsUInt32Number Value);
-CMSAPI void              CMSEXPORT  _cmsAdjustEndianess64(cmsUInt64Number* Result, cmsUInt64Number QWord);
+CMSAPI void              CMSEXPORT  _cmsAdjustEndianess64(cmsUInt64Number* Result, cmsUInt64Number* QWord);
 
 // Helper IO functions
 CMSAPI cmsBool           CMSEXPORT  _cmsReadUInt8Number(cmsIOHANDLER* io,  cmsUInt8Number* n);
@@ -147,7 +147,7 @@ CMSAPI cmsBool           CMSEXPORT  _cmsWriteUInt8Number(cmsIOHANDLER* io, cmsUI
 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  _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);
@@ -181,6 +181,11 @@ CMSAPI cmsS15Fixed16Number CMSEXPORT _cmsDoubleTo15Fixed16(cmsFloat64Number v);
 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);
 
 //----------------------------------------------------------------------------------------------------------
 
@@ -196,6 +201,7 @@ CMSAPI void                CMSEXPORT _cmsDecodeDateTimeNumber(const cmsDateTimeN
 #define cmsPluginRenderingIntentSig          0x696E7448     // 'intH'
 #define cmsPluginMultiProcessElementSig      0x6D706548     // 'mpeH'
 #define cmsPluginOptimizationSig             0x6F707448     // 'optH'
+#define cmsPluginTransformSig                0x7A666D48     // 'xfmH'
 
 typedef struct _cmsPluginBaseStruct {
 
@@ -387,7 +393,7 @@ typedef struct _cms_typehandler_struct {
                             void *Ptr);
 
         // Additional parameters used by the calling thread
-        cmsContext       ContextID; 
+        cmsContext       ContextID;
         cmsUInt32Number  ICCVersion;
 
 } cmsTagTypeHandler;
@@ -486,6 +492,39 @@ typedef struct {
 
 }  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
@@ -496,9 +535,6 @@ typedef void     (* _cmsOPTeval16Fn)(register const cmsUInt16Number In[],
                                      register cmsUInt16Number Out[],
                                      register const void* Data);
 
-typedef void     (* _cmsOPTfreeDataFn)(cmsContext ContextID, void* Data);
-typedef void*    (* _cmsOPTdupDataFn)(cmsContext ContextID, const void* Data);
-
 
 typedef cmsBool  (* _cmsOPToptimizeFn)(cmsPipeline** Lut,
                                        cmsUInt32Number  Intent,
@@ -512,8 +548,8 @@ typedef cmsBool  (* _cmsOPToptimizeFn)(cmsPipeline** Lut,
 CMSAPI void CMSEXPORT _cmsPipelineSetOptimizationParameters(cmsPipeline* Lut,
                                                _cmsOPTeval16Fn Eval16,
                                                void* PrivateData,
-                                               _cmsOPTfreeDataFn FreePrivateDataFn,
-                                               _cmsOPTdupDataFn DupPrivateDataFn);
+                                               _cmsFreeUserDataFn FreePrivateDataFn,
+                                               _cmsDupUserDataFn DupPrivateDataFn);
 
 typedef struct {
       cmsPluginBase     base;
@@ -524,6 +560,39 @@ typedef struct {
 }  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;
+
 
 #ifndef CMS_USE_CPP_API
 #   ifdef __cplusplus
index 8fca2d9..0e49793 100644 (file)
@@ -27,5 +27,5 @@ liblcms2_la_SOURCES = \
   cmscnvrt.c cmserr.c cmsgamma.c cmsgmt.c cmsintrp.c cmsio0.c cmsio1.c cmslut.c \
   cmsplugin.c cmssm.c cmsmd5.c cmsmtrx.c cmspack.c cmspcs.c cmswtpnt.c cmsxform.c \
   cmssamp.c cmsnamed.c cmscam02.c cmsvirt.c cmstypes.c cmscgats.c cmsps2.c cmsopt.c \
-  lcms2_internal.h
+  cmshalf.c lcms2_internal.h
 
index 9e4ba6a..837a795 100644 (file)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.3 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -68,6 +68,12 @@ am__nobase_list = $(am__nobase_strip_setup); \
 am__base_list = \
   sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
   sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__uninstall_files_from_dir = { \
+  test -z "$$files" \
+    || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
+    || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
+         $(am__cd) "$$dir" && rm -f $$files; }; \
+  }
 am__installdirs = "$(DESTDIR)$(libdir)"
 LTLIBRARIES = $(lib_LTLIBRARIES)
 am__DEPENDENCIES_1 =
@@ -76,7 +82,7 @@ am_liblcms2_la_OBJECTS = cmscnvrt.lo cmserr.lo cmsgamma.lo cmsgmt.lo \
        cmsintrp.lo cmsio0.lo cmsio1.lo cmslut.lo cmsplugin.lo \
        cmssm.lo cmsmd5.lo cmsmtrx.lo cmspack.lo cmspcs.lo cmswtpnt.lo \
        cmsxform.lo cmssamp.lo cmsnamed.lo cmscam02.lo cmsvirt.lo \
-       cmstypes.lo cmscgats.lo cmsps2.lo cmsopt.lo
+       cmstypes.lo cmscgats.lo cmsps2.lo cmsopt.lo cmshalf.lo
 liblcms2_la_OBJECTS = $(am_liblcms2_la_OBJECTS)
 liblcms2_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
        $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
@@ -248,7 +254,7 @@ liblcms2_la_SOURCES = \
   cmscnvrt.c cmserr.c cmsgamma.c cmsgmt.c cmsintrp.c cmsio0.c cmsio1.c cmslut.c \
   cmsplugin.c cmssm.c cmsmd5.c cmsmtrx.c cmspack.c cmspcs.c cmswtpnt.c cmsxform.c \
   cmssamp.c cmsnamed.c cmscam02.c cmsvirt.c cmstypes.c cmscgats.c cmsps2.c cmsopt.c \
-  lcms2_internal.h
+  cmshalf.c lcms2_internal.h
 
 all: all-am
 
@@ -315,7 +321,7 @@ clean-libLTLIBRARIES:
          echo "rm -f \"$${dir}/so_locations\""; \
          rm -f "$${dir}/so_locations"; \
        done
-liblcms2.la: $(liblcms2_la_OBJECTS) $(liblcms2_la_DEPENDENCIES) 
+liblcms2.la: $(liblcms2_la_OBJECTS) $(liblcms2_la_DEPENDENCIES) $(EXTRA_liblcms2_la_DEPENDENCIES) 
        $(liblcms2_la_LINK) -rpath $(libdir) $(liblcms2_la_OBJECTS) $(liblcms2_la_LIBADD) $(LIBS)
 
 mostlyclean-compile:
@@ -330,6 +336,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cmserr.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cmsgamma.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cmsgmt.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cmshalf.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cmsintrp.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cmsio0.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cmsio1.Plo@am__quote@
@@ -475,10 +482,15 @@ install-am: all-am
 
 installcheck: installcheck-am
 install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-         install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-         `test -z '$(STRIP)' || \
-           echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
 mostlyclean-generic:
 
 clean-generic:
index 08eea16..4532c3e 100644 (file)
@@ -1,24 +1,24 @@
 //---------------------------------------------------------------------------------
 //
 //  Little Color Management System
-//  Copyright (c) 1998-2010 Marti Maria Saguer
+//  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 
+// 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 
+// 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 
+// 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.
 //
 //---------------------------------------------------------------------------------
@@ -31,7 +31,7 @@
 // ---------- Implementation --------------------------------------------
 
 typedef struct  {
-    
+
     cmsFloat64Number XYZ[3];
     cmsFloat64Number RGB[3];
     cmsFloat64Number RGBc[3];
@@ -41,55 +41,55 @@ typedef struct  {
     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) 
+cmsFloat64Number compute_n(cmsCIECAM02* pMod)
 {
     return (pMod -> Yb / pMod -> adoptedWhite.XYZ[1]);
 }
 
 static
-cmsFloat64Number compute_z(cmsCIECAM02* pMod) 
+cmsFloat64Number compute_z(cmsCIECAM02* pMod)
 {
     return (1.48 + pow(pMod -> n, 0.5));
 }
 
 static
-cmsFloat64Number computeNbb(cmsCIECAM02* pMod) 
+cmsFloat64Number computeNbb(cmsCIECAM02* pMod)
 {
     return (0.725 * pow((1.0 / pMod -> n), 0.2));
 }
 
 static
-cmsFloat64Number computeFL(cmsCIECAM02* pMod) 
+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) 
+static
+cmsFloat64Number computeD(cmsCIECAM02* pMod)
 {
     cmsFloat64Number D;
 
@@ -100,17 +100,17 @@ cmsFloat64Number computeD(cmsCIECAM02* pMod)
 
 
 static
-CAM02COLOR XYZtoCAT02(CAM02COLOR clr) 
+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) 
+CAM02COLOR ChromaticAdaptation(CAM02COLOR clr, cmsCIECAM02* pMod)
 {
     cmsUInt32Number i;
 
@@ -120,15 +120,15 @@ CAM02COLOR ChromaticAdaptation(CAM02COLOR clr, cmsCIECAM02* pMod)
             (1.0 - pMod->D)) * clr.RGB[i];
     }
 
-    return clr; 
+    return clr;
 }
 
 
 static
-CAM02COLOR CAT02toHPE(CAM02COLOR clr) 
+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));
@@ -138,16 +138,16 @@ CAM02COLOR CAT02toHPE(CAM02COLOR clr)
     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) 
+CAM02COLOR NonlinearCompression(CAM02COLOR clr, cmsCIECAM02* pMod)
 {
     cmsUInt32Number i;
     cmsFloat64Number temp;
@@ -163,21 +163,21 @@ CAM02COLOR NonlinearCompression(CAM02COLOR clr, cmsCIECAM02* pMod)
             clr.RGBpa[i] = (400.0 * temp) / (temp + 27.13) + 0.1;
         }
     }
-    
-    clr.A = (((2.0 * clr.RGBpa[0]) + clr.RGBpa[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) 
+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;
@@ -194,11 +194,11 @@ CAM02COLOR ComputeCorrelates(CAM02COLOR clr, cmsCIECAM02* pMod)
         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); 
-    
+    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;
@@ -219,15 +219,15 @@ CAM02COLOR ComputeCorrelates(CAM02COLOR clr, cmsCIECAM02* pMod)
         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), 
+
+    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] + 
+        (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) *
@@ -235,34 +235,34 @@ CAM02COLOR ComputeCorrelates(CAM02COLOR clr, cmsCIECAM02* pMod)
 
     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) 
+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)))), 
+        (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)) /
@@ -279,17 +279,17 @@ CAM02COLOR InverseCorrelates(CAM02COLOR clr, cmsCIECAM02* pMod)
             (sin(hr) / cos(hr)));
         clr.b = clr.a * (sin(hr) / cos(hr));
     }
-    
-    clr.RGBpa[0] = ((460.0 / 1403.0) * p2) + 
+
+    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) - 
+    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;
 }
 
@@ -298,7 +298,7 @@ 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;
@@ -307,15 +307,15 @@ CAM02COLOR InverseNonlinearity(CAM02COLOR clr, cmsCIECAM02* pMod)
             (400.0 - fabs(clr.RGBpa[i] - 0.1))),
             (1.0 / 0.42));
     }
-    
+
     return clr;
 }
 
 static
-CAM02COLOR HPEtoCAT02(CAM02COLOR clr) 
+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);
@@ -325,7 +325,7 @@ CAM02COLOR HPEtoCAT02(CAM02COLOR clr)
     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]);
@@ -334,10 +334,10 @@ CAM02COLOR HPEtoCAT02(CAM02COLOR clr)
 
 
 static
-CAM02COLOR InverseChromaticAdaptation(CAM02COLOR clr,  cmsCIECAM02* pMod) 
+CAM02COLOR InverseChromaticAdaptation(CAM02COLOR clr,  cmsCIECAM02* pMod)
 {
     cmsUInt32Number i;
-    for (i = 0; i < 3; 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);
     }
@@ -346,12 +346,12 @@ CAM02COLOR InverseChromaticAdaptation(CAM02COLOR clr,  cmsCIECAM02* pMod)
 
 
 static
-CAM02COLOR CAT02toXYZ(CAM02COLOR clr) 
+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;
 }
 
@@ -434,10 +434,10 @@ void CMSEXPORT cmsCIECAM02Done(cmsHANDLE hModel)
 
 
 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);
@@ -445,23 +445,23 @@ void CMSEXPORT cmsCIECAM02Forward(cmsHANDLE hModel, const cmsCIEXYZ* pIn, cmsJCh
     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;         
+    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);
@@ -469,13 +469,13 @@ void CMSEXPORT cmsCIECAM02Reverse(cmsHANDLE hModel, const cmsJCh* pIn, cmsCIEXYZ
     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];
index e4ccfbf..9c08feb 100644 (file)
@@ -1,24 +1,24 @@
 //---------------------------------------------------------------------------------
 //
 //  Little Color Management System
-//  Copyright (c) 1998-2011 Marti Maria Saguer
+//  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 
+// 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 
+// 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 
+// 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.
 //
 //---------------------------------------------------------------------------------
@@ -44,8 +44,9 @@
 #    define DIR_CHAR    '/'
 #endif
 
+
 // Symbols
-typedef enum { 
+typedef enum {
 
         SNONE,
         SINUM,      // Integer
@@ -71,10 +72,10 @@ typedef enum {
 
 
 // How to write the value
-typedef enum { 
+typedef enum {
 
         WRITE_UNCOOKED,
-        WRITE_STRINGIFY,            
+        WRITE_STRINGIFY,
         WRITE_HEXADECIMAL,
         WRITE_BINARY,
         WRITE_PAIR
@@ -108,21 +109,21 @@ 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        
+        char**         Data;                  // The binary stream
 
     } TABLE;
 
@@ -132,10 +133,10 @@ typedef struct _FileContext {
         FILE*          Stream;                   // File stream or NULL if holded in memory
     } FILECTX;
 
-// This struct hold all information about an open IT8 handler. 
+// 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
 
@@ -148,7 +149,7 @@ typedef struct {
         // Parser state machine
         SYMBOL         sy;                    // Current symbol
         int            ch;                    // Current character
-      
+
         int            inum;                  // integer value
         cmsFloat64Number         dnum;                  // real value
         char           id[MAXID];             // identifier
@@ -157,10 +158,10 @@ typedef struct {
         // 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
 
@@ -199,7 +200,7 @@ typedef struct {
 
 // The keyword->symbol translation table. Sorting is required.
 static const KEYWORD TabKeys[] = {
+
         {"$INCLUDE",               SINCLUDE},   // This is an extension!
         {".INCLUDE",               SINCLUDE},   // This is an extension!
 
@@ -260,31 +261,31 @@ static PROPERTY PredefinedProperties[] = {
 
        // 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, 
+        {"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 
+       {"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 
+       {"POLARIZATION",      WRITE_STRINGIFY},   // Identifies the use of a physical polarization filter during measurement. Allowed
                                // values are {"yes\94\93white\94\93none\94 or \93na\94.
 
-       {"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 
+       {"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 
+                               // 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 
+                               // 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 
+       {"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.
@@ -302,7 +303,7 @@ static PROPERTY PredefinedProperties[] = {
 // 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. 
+        "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
@@ -350,7 +351,7 @@ static const char* PredefinedSampleID[] = {
 
 #define NUMPREDEFINEDSAMPLEID (sizeof(PredefinedSampleID)/sizeof(char *))
 
-//Forward declaration of some internal functions        
+//Forward declaration of some internal functions
 static void* AllocChunk(cmsIT8* it8, cmsUInt32Number size);
 
 // Checks if c is a separator
@@ -361,7 +362,7 @@ cmsBool isseparator(int c)
 }
 
 // Checks whatever if c is a valid identifier char
-static 
+static
 cmsBool ismiddle(int c)
 {
    return (!isseparator(c) && (c != '#') && (c !='\"') && (c != '\'') && (c > 32) && (c < 127));
@@ -389,7 +390,7 @@ cmsBool isabsolutepath(const char *path)
 
     if(path == NULL)
         return FALSE;
-    if (path[0] == 0) 
+    if (path[0] == 0)
         return FALSE;
 
     strncpy(ThreeChars, path, 3);
@@ -405,9 +406,11 @@ cmsBool isabsolutepath(const char *path)
     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 
+static
 cmsBool BuildAbsolutePath(const char *relPath, const char *basePath, char *buffer, cmsUInt32Number MaxLen)
 {
     char *tail;
@@ -421,8 +424,8 @@ cmsBool BuildAbsolutePath(const char *relPath, const char *basePath, char *buffe
         return TRUE;
     }
 
-    // No, search for last 
-    strncpy(buffer, basePath, MaxLen);  
+    // No, search for last
+    strncpy(buffer, basePath, MaxLen);
     buffer[MaxLen-1] = 0;
 
     tail = strrchr(buffer, DIR_CHAR);
@@ -432,9 +435,9 @@ cmsBool BuildAbsolutePath(const char *relPath, const char *basePath, char *buffe
     if (len >= MaxLen) return FALSE;
 
     // No need to assure zero terminator over here
-    strncpy(tail + 1, relPath, MaxLen - len);   
+    strncpy(tail + 1, relPath, MaxLen - len);
 
-    return TRUE;    
+    return TRUE;
 }
 
 
@@ -442,7 +445,7 @@ cmsBool BuildAbsolutePath(const char *relPath, const char *basePath, char *buffe
 static
 const char* NoMeta(const char* str)
 {
-    if (strchr(str, '%') != NULL) 
+    if (strchr(str, '%') != NULL)
         return "**** CORRUPTED FORMAT STRING ***";
 
     return str;
@@ -493,7 +496,7 @@ void NextCh(cmsIT8* it8)
 
             } else
                 it8 ->ch = 0;   // EOF
-        }              
+        }
     }
     else {
         it8->ch = *it8->Source;
@@ -546,7 +549,7 @@ void ReadReal(cmsIT8* it8, int inum)
     if (it8->ch == '.') {        // Decimal point
 
         cmsFloat64Number frac = 0.0;      // fraction
-        int prec = 0;           // precision
+        int prec = 0;                     // precision
 
         NextCh(it8);               // Eats dec. point
 
@@ -593,6 +596,81 @@ void ReadReal(cmsIT8* it8, int inum)
     }
 }
 
+// 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;
+
+    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
@@ -603,94 +681,94 @@ void InSymbol(cmsIT8* it8)
     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)) {
 
@@ -700,19 +778,19 @@ void InSymbol(cmsIT8* it8)
                         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
@@ -731,18 +809,18 @@ void InSymbol(cmsIT8* it8)
                     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';                    
+
+                    *idptr = '\0';
                     it8->sy = SIDENT;
                 }
                 return;
-                
+
             }
             else
                 switch ((int) it8->ch) {
@@ -757,24 +835,24 @@ void InSymbol(cmsIT8* it8)
         case -1:
             it8->sy = SEOF;
             break;
-            
-            
-        // Next line            
+
+
+        // Next line
         case '\n':
             NextCh(it8);
             it8->sy = SEOLN;
             it8->lineno++;
             break;
-            
+
         // Comment
         case '#':
             NextCh(it8);
             while (it8->ch && it8->ch != '\n')
                 NextCh(it8);
-            
+
             it8->sy = SCOMMENT;
             break;
-            
+
         // String.
         case '\'':
         case '\"':
@@ -782,28 +860,28 @@ void InSymbol(cmsIT8* it8)
             sng = it8->ch;
             k = 0;
             NextCh(it8);
-            
+
             while (k < MAXSTR && it8->ch != sng) {
-                
+
                 if (it8->ch == '\n'|| it8->ch == '\r') k = MAXSTR+1;
-                else {                                    
+                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;            
+            SynError(it8, "Unrecognized character: 0x%x", it8 ->ch);
+            return;
             }
-            
+
     } while (it8->sy == SCOMMENT);
 
     // Handle the include special token
@@ -829,8 +907,8 @@ void InSymbol(cmsIT8* it8)
                     //  TODO: how to manage out-of-memory conditions?
                 }
 
-                if (BuildAbsolutePath(it8->str, 
-                                      it8->FileStack[it8->IncludeSP]->FileName, 
+                if (BuildAbsolutePath(it8->str,
+                                      it8->FileStack[it8->IncludeSP]->FileName,
                                       FileNest->FileName, cmsMAX_PATH-1) == FALSE) {
                     SynError(it8, "File path too long");
                     return;
@@ -845,9 +923,9 @@ void InSymbol(cmsIT8* it8)
                 it8->IncludeSP++;
 
                 it8 ->ch = ' ';
-                InSymbol(it8);    
+                InSymbol(it8);
     }
-                
+
 }
 
 // Checks end of line separator
@@ -887,12 +965,12 @@ cmsBool GetVal(cmsIT8* it8, char* Buffer, cmsUInt32Number max, const char* Error
 {
     switch (it8->sy) {
 
-    case SIDENT:  strncpy(Buffer, it8->id, max); 
+    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); 
+    case SSTRING: strncpy(Buffer, it8->str, max);
                   Buffer[max-1] = 0;
                   break;
 
@@ -909,12 +987,12 @@ cmsBool GetVal(cmsIT8* it8, char* Buffer, cmsUInt32Number max, const char* Error
 
 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;
 }
@@ -944,7 +1022,7 @@ void CMSEXPORT cmsIT8Free(cmsHANDLE hIT8)
     }
 
     if (it8->MemoryBlock)
-        _cmsFree(it8 ->ContextID, it8->MemoryBlock);    
+        _cmsFree(it8 ->ContextID, it8->MemoryBlock);
 
     _cmsFree(it8 ->ContextID, it8);
 }
@@ -999,12 +1077,12 @@ void* AllocChunk(cmsIT8* it8, cmsUInt32Number 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;
-    
+
 }
 
 
@@ -1020,7 +1098,7 @@ char *AllocString(cmsIT8* it8, const char* str)
     if (ptr) strncpy (ptr, str, Size-1);
 
     return ptr;
-}  
+}
 
 // Searches through linked list
 
@@ -1067,13 +1145,13 @@ KEYVALUE* AddToList(cmsIT8* it8, KEYVALUE** Head, const char *Key, const char *S
     KEYVALUE* last;
 
 
-    // Check if property is already in list 
+    // 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);                                        
+        //     return SynError(it8, "duplicate key <%s>", Key);
     }
     else {
 
@@ -1083,7 +1161,7 @@ KEYVALUE* AddToList(cmsIT8* it8, KEYVALUE** Head, const char *Key, const char *S
         p = (KEYVALUE*) AllocChunk(it8, sizeof(KEYVALUE));
         if (p == NULL)
         {
-            SynError(it8, "AddToList: out of memory");        
+            SynError(it8, "AddToList: out of memory");
             return NULL;
         }
 
@@ -1098,13 +1176,13 @@ KEYVALUE* AddToList(cmsIT8* it8, KEYVALUE** Head, const char *Key, const char *S
         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) 
+                while (last->Next != NULL)
                          last = last->Next;
             }
 
@@ -1152,7 +1230,7 @@ void AllocTable(cmsIT8* it8)
     t->HeaderList = NULL;
     t->DataFormat = NULL;
     t->Data       = NULL;
-   
+
     it8 ->TablesCount++;
 }
 
@@ -1190,16 +1268,16 @@ cmsHANDLE  CMSEXPORT cmsIT8Alloc(cmsContext ContextID)
     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->Allocator.BlockSize = 0;
 
     it8->ValidKeywords = NULL;
     it8->ValidSampleID = NULL;
@@ -1218,7 +1296,7 @@ cmsHANDLE  CMSEXPORT cmsIT8Alloc(cmsContext ContextID)
     cmsIT8SetSheetType((cmsHANDLE) it8, "CGATS.17");
 
     // Initialize predefined properties & data
-    
+
     for (i=0; i < NUMPREDEFINEDPROPS; i++)
             AddAvailableProperty(it8, PredefinedProperties[i].id, PredefinedProperties[i].as);
 
@@ -1231,7 +1309,7 @@ cmsHANDLE  CMSEXPORT cmsIT8Alloc(cmsContext ContextID)
 
 
 const char* CMSEXPORT cmsIT8GetSheetType(cmsHANDLE hIT8)
-{        
+{
         return GetTable((cmsIT8*) hIT8)->SheetType;
 }
 
@@ -1254,8 +1332,6 @@ cmsBool CMSEXPORT cmsIT8SetComment(cmsHANDLE hIT8, const char* Val)
     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)
 {
@@ -1267,31 +1343,30 @@ cmsBool CMSEXPORT cmsIT8SetPropertyStr(cmsHANDLE hIT8, const char* Key, const ch
     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;    
+    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, "%d", Val);
 
-    return AddToList(it8, &GetTable(it8)->HeaderList, cProp, NULL, Buffer, WRITE_HEXADECIMAL) != NULL;    
+    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;    
-    
+    cmsIT8* it8 = (cmsIT8*) hIT8;
+
     return AddToList(it8, &GetTable(it8)->HeaderList, Key, NULL, Buffer, WRITE_UNCOOKED) != NULL;
 }
 
@@ -1320,8 +1395,7 @@ cmsFloat64Number CMSEXPORT cmsIT8GetPropertyDbl(cmsHANDLE hIT8, const char* cPro
 {
     const char *v = cmsIT8GetProperty(hIT8, cProp);
 
-    if (v) return atof(v);
-    else return 0.0;
+    return ParseFloatNumber(v);
 }
 
 const char* CMSEXPORT cmsIT8GetPropertyMulti(cmsHANDLE hIT8, const char* Key, const char *SubKey)
@@ -1384,8 +1458,8 @@ cmsBool SetDataFormat(cmsIT8* it8, int n, const char *label)
         SynError(it8, "More than NUMBER_OF_FIELDS fields.");
         return FALSE;
     }
-    
-    if (t->DataFormat) {                
+
+    if (t->DataFormat) {
         t->DataFormat[n] = AllocString(it8, label);
     }
 
@@ -1423,7 +1497,7 @@ 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;
 
@@ -1443,14 +1517,14 @@ cmsBool SetData(cmsIT8* it8, int nSet, int nField, const char *Val)
 
     if (nSet > t -> nPatches || nSet < 0) {
 
-            return SynError(it8, "Patch %d out of range, there are %d patches", nSet, t -> nPatches);            
+            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;
 }
@@ -1465,37 +1539,37 @@ void WriteStr(SAVESTREAM* f, const char *str)
 {
     cmsUInt32Number len;
 
-    if (str == NULL) 
+    if (str == NULL)
         str = " ";
-    
+
     // Lenghth 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;
         }
-                        
-    }   
+
+    }
 }
 
 
@@ -1531,18 +1605,18 @@ void WriteHeader(cmsIT8* it8, SAVESTREAM* fp)
         if (*p ->Keyword == '#') {
 
             char* Pt;
-            
+
             WriteStr(fp, "#\n# ");
             for (Pt = p ->Value; *Pt; Pt++) {
 
 
-                Writef(fp, "%c", *Pt);                
+                Writef(fp, "%c", *Pt);
 
                 if (*Pt == '\n') {
                     WriteStr(fp, "# ");
                 }
             }
-        
+
             WriteStr(fp, "\n#\n");
             continue;
         }
@@ -1565,7 +1639,7 @@ void WriteHeader(cmsIT8* it8, SAVESTREAM* fp)
             switch (p ->WriteAs) {
 
             case WRITE_UNCOOKED:
-                    Writef(fp, "\t%s", p ->Value);                    
+                    Writef(fp, "\t%s", p ->Value);
                     break;
 
             case WRITE_STRINGIFY:
@@ -1664,7 +1738,7 @@ void WriteData(SAVESTREAM* fp, cmsIT8* it8)
 // Saves whole file
 cmsBool CMSEXPORT cmsIT8SaveToFile(cmsHANDLE hIT8, const char* cFileName)
 {
-    SAVESTREAM sd;  
+    SAVESTREAM sd;
     cmsUInt32Number i;
     cmsIT8* it8 = (cmsIT8*) hIT8;
 
@@ -1672,7 +1746,7 @@ cmsBool CMSEXPORT cmsIT8SaveToFile(cmsHANDLE hIT8, const char* cFileName)
 
     sd.stream = fopen(cFileName, "wt");
     if (!sd.stream) return FALSE;
-    
+
     for (i=0; i < it8 ->TablesCount; i++) {
 
             cmsIT8SetTable(hIT8, i);
@@ -1680,7 +1754,7 @@ cmsBool CMSEXPORT cmsIT8SaveToFile(cmsHANDLE hIT8, const char* cFileName)
             WriteDataFormat(&sd, it8);
             WriteData(&sd, it8);
     }
-    
+
     if (fclose(sd.stream) != 0) return FALSE;
 
     return TRUE;
@@ -1690,7 +1764,7 @@ cmsBool CMSEXPORT cmsIT8SaveToFile(cmsHANDLE hIT8, const char* cFileName)
 // Saves to memory
 cmsBool CMSEXPORT cmsIT8SaveToMem(cmsHANDLE hIT8, void *MemPtr, cmsUInt32Number* BytesNeeded)
 {
-    SAVESTREAM sd;  
+    SAVESTREAM sd;
     cmsUInt32Number i;
     cmsIT8* it8 = (cmsIT8*) hIT8;
 
@@ -1702,23 +1776,23 @@ cmsBool CMSEXPORT cmsIT8SaveToMem(cmsHANDLE hIT8, void *MemPtr, cmsUInt32Number*
 
     sd.Used = 0;
 
-    if (sd.Base) 
+    if (sd.Base)
         sd.Max  = *BytesNeeded;     // Write to memory?
-    else 
+    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);
+        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;
+        *sd.Ptr = 0;
 
     *BytesNeeded = sd.Used;
 
@@ -1731,7 +1805,7 @@ cmsBool CMSEXPORT cmsIT8SaveToMem(cmsHANDLE hIT8, void *MemPtr, cmsUInt32Number*
 static
 cmsBool DataFormatSection(cmsIT8* it8)
 {
-    int iField = 0;    
+    int iField = 0;
     TABLE* t = GetTable(it8);
 
     InSymbol(it8);   // Eats "BEGIN_DATA_FORMAT"
@@ -1741,15 +1815,15 @@ cmsBool DataFormatSection(cmsIT8* it8)
         it8->sy != SEOLN &&
         it8->sy != SEOF &&
         it8->sy != SSYNERROR)  {
-        
+
             if (it8->sy != SIDENT) {
-            
-                return SynError(it8, "Sample type expected");                    
+
+                return SynError(it8, "Sample type expected");
             }
-        
+
             if (!SetDataFormat(it8, iField, it8->id)) return FALSE;
             iField++;
-                
+
             InSymbol(it8);
             SkipEOLN(it8);
        }
@@ -1761,7 +1835,7 @@ cmsBool DataFormatSection(cmsIT8* it8)
        if (iField != t ->nSamples) {
            SynError(it8, "Count mismatch. NUMBER_OF_FIELDS was %d, found %d\n", t ->nSamples, iField);
 
-           
+
        }
 
        return TRUE;
@@ -1788,7 +1862,7 @@ cmsBool DataSection (cmsIT8* it8)
         if (iField >= t -> nSamples) {
             iField = 0;
             iSet++;
-          
+
         }
 
         if (it8->sy != SEND_DATA && it8->sy != SEOF) {
@@ -1800,16 +1874,16 @@ cmsBool DataSection (cmsIT8* it8)
                 return FALSE;
 
             iField++;
-            
+
             InSymbol(it8);
-            SkipEOLN(it8);           
+            SkipEOLN(it8);
         }
     }
 
     SkipEOLN(it8);
     Skip(it8, SEND_DATA);
     SkipEOLN(it8);
+
     // Check for data completion.
 
     if ((iSet+1) != t -> nPatches)
@@ -1838,7 +1912,7 @@ cmsBool HeaderSection(cmsIT8* it8)
 
         case SKEYWORD:
                 InSymbol(it8);
-                if (!GetVal(it8, Buffer, MAXSTR-1, "Keyword expected")) return FALSE;                
+                if (!GetVal(it8, Buffer, MAXSTR-1, "Keyword expected")) return FALSE;
                 if (!AddAvailableProperty(it8, Buffer, WRITE_UNCOOKED)) return FALSE;
                 InSymbol(it8);
                 break;
@@ -1846,7 +1920,7 @@ cmsBool HeaderSection(cmsIT8* it8)
 
         case SDATA_FORMAT_ID:
                 InSymbol(it8);
-                if (!GetVal(it8, Buffer, MAXSTR-1, "Keyword expected")) return FALSE;                
+                if (!GetVal(it8, Buffer, MAXSTR-1, "Keyword expected")) return FALSE;
                 if (!AddAvailableSampleID(it8, Buffer)) return FALSE;
                 InSymbol(it8);
                 break;
@@ -1855,10 +1929,10 @@ cmsBool HeaderSection(cmsIT8* it8)
         case SIDENT:
                 strncpy(VarName, it8->id, MAXID-1);
                 VarName[MAXID-1] = 0;
-                
+
                 if (!IsAvailableOnList(it8-> ValidKeywords, VarName, NULL, &Key)) {
 
-#ifdef CMS_STRICT_CGATS               
+#ifdef CMS_STRICT_CGATS
                  return SynError(it8, "Undefined keyword '%s'", VarName);
 #else
                     Key = AddAvailableProperty(it8, VarName, WRITE_UNCOOKED);
@@ -1870,7 +1944,7 @@ cmsBool HeaderSection(cmsIT8* 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, 
+                    AddToList(it8, &GetTable(it8)->HeaderList, VarName, NULL, Buffer,
                                 (it8->sy == SSTRING) ? WRITE_STRINGIFY : WRITE_UNCOOKED);
                 }
                 else {
@@ -1883,7 +1957,7 @@ cmsBool HeaderSection(cmsIT8* it8)
                     for (Subkey = Buffer; Subkey != NULL; Subkey = Nextkey)
                     {
                         char *Value, *temp;
-                
+
                         //  identify token pair boundary
                         Nextkey = (char*) strchr(Subkey, ';');
                         if(Nextkey)
@@ -1900,7 +1974,7 @@ cmsBool HeaderSection(cmsIT8* it8)
 
                         // gobble any space at the right
                         temp = Value + strlen(Value) - 1;
-                        while(*temp == ' ') *temp-- = '\0'; 
+                        while(*temp == ' ') *temp-- = '\0';
 
                         // trim the strings from the left
                         Subkey += strspn(Subkey, " ");
@@ -1911,11 +1985,11 @@ cmsBool HeaderSection(cmsIT8* it8)
                         AddToList(it8, &GetTable(it8)->HeaderList, VarName, Subkey, Value, WRITE_PAIR);
                     }
                 }
-                
+
                 InSymbol(it8);
                 break;
 
-        
+
         case SEOLN: break;
 
         default:
@@ -1932,12 +2006,12 @@ cmsBool HeaderSection(cmsIT8* it8)
 
 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;
@@ -1954,11 +2028,11 @@ cmsBool ParseIT8(cmsIT8* it8, cmsBool nosheet)
     char* SheetTypePtr = it8 ->Tab[0].SheetType;
 
     if (nosheet == 0) {
-        ReadType(it8, SheetTypePtr);  
+        ReadType(it8, SheetTypePtr);
     }
 
     InSymbol(it8);
-   
+
     SkipEOLN(it8);
 
     while (it8-> sy != SEOF &&
@@ -1973,17 +2047,17 @@ cmsBool ParseIT8(cmsIT8* it8, cmsBool nosheet)
             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
@@ -1996,11 +2070,11 @@ cmsBool ParseIT8(cmsIT8* it8, cmsBool nosheet)
 
                                          cmsIT8SetSheetType(it8, it8 ->id);
                                          InSymbol(it8);
-                                    } 
+                                    }
                                     else
                                     {
                                         // It is not. Just continue
-                                        cmsIT8SetSheetType(it8, "");                                       
+                                        cmsIT8SetSheetType(it8, "");
                                     }
                                 }
                                 else
@@ -2010,7 +2084,7 @@ cmsBool ParseIT8(cmsIT8* it8, cmsBool nosheet)
                                         InSymbol(it8);
                                     }
                            }
-                           
+
                     }
                     break;
 
@@ -2044,7 +2118,7 @@ void CookPointers(cmsIT8* it8)
     TABLE* t = it8 ->Tab + j;
 
     t -> SampleID = 0;
-    it8 ->nTable = j;    
+    it8 ->nTable = j;
 
     for (idField = 0; idField < t -> nSamples; idField++)
     {
@@ -2060,16 +2134,16 @@ void CookPointers(cmsIT8* it8)
         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
@@ -2077,23 +2151,23 @@ void CookPointers(cmsIT8* it8)
 
                 }
                 }
-        
+
         }
 
         // "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) {                                
-                                
+
+                            if (Label) {
+
                                 cmsUInt32Number k;
 
-                                // This is the label, search for a table containing 
+                                // This is the label, search for a table containing
                                 // this property
 
                                 for (k=0; k < it8 ->TablesCount; k++) {
@@ -2107,10 +2181,10 @@ void CookPointers(cmsIT8* it8)
                                         char Buffer[256];
 
                                         char *Type  = p ->Value;
-                                        int  nTable = k;                                        
+                                        int  nTable = k;
 
                                         snprintf(Buffer, 255, "%s %d %s", Label, nTable, Type );
-                                                                                
+
                                         SetData(it8, i, idField, Buffer);
                                     }
                                 }
@@ -2131,11 +2205,11 @@ void CookPointers(cmsIT8* it8)
 
 // 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
+// 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 cols = 1, space = 0, quot = 0;
+    int words = 1, space = 0, quot = 0;
     int i;
 
     if (n < 10) return 0;   // Too small
@@ -2149,7 +2223,7 @@ int IsMyBlock(cmsUInt8Number* Buffer, int n)
         {
         case '\n':
         case '\r':
-            return ((quot == 1) || (cols > 2)) ? 0 : cols;
+            return ((quot == 1) || (words > 2)) ? 0 : words;
         case '\t':
         case ' ':
             if(!quot && !space)
@@ -2161,7 +2235,7 @@ int IsMyBlock(cmsUInt8Number* Buffer, int n)
         default:
             if (Buffer[i] < 32) return 0;
             if (Buffer[i] > 127) return 0;
-            cols += space;
+            words += space;
             space = 0;
             break;
         }
@@ -2186,7 +2260,7 @@ cmsBool IsMyFile(const char* FileName)
 
    Size = (cmsUInt32Number) fread(Ptr, 1, 132, fp);
 
-   if (fclose(fp) != 0) 
+   if (fclose(fp) != 0)
        return FALSE;
 
    Ptr[Size] = '\0';
@@ -2199,7 +2273,7 @@ cmsBool IsMyFile(const char* FileName)
 
 cmsHANDLE  CMSEXPORT cmsIT8LoadFromMem(cmsContext ContextID, void *Ptr, cmsUInt32Number len)
 {
-    cmsHANDLE hIT8; 
+    cmsHANDLE hIT8;
     cmsIT8*  it8;
     int type;
 
@@ -2208,7 +2282,7 @@ cmsHANDLE  CMSEXPORT cmsIT8LoadFromMem(cmsContext ContextID, void *Ptr, cmsUInt3
 
     type = IsMyBlock((cmsUInt8Number*)Ptr, len);
     if (type == 0) return NULL;
-    
+
     hIT8 = cmsIT8Alloc(ContextID);
     if (!hIT8) return NULL;
 
@@ -2221,10 +2295,10 @@ cmsHANDLE  CMSEXPORT cmsIT8LoadFromMem(cmsContext ContextID, void *Ptr, cmsUInt3
     strncpy(it8->FileStack[0]->FileName, "", cmsMAX_PATH-1);
     it8-> Source = it8 -> MemoryBlock;
 
-    if (!ParseIT8(it8, type-1)) { 
-       
-        cmsIT8Free(hIT8); 
-        return FALSE; 
+    if (!ParseIT8(it8, type-1)) {
+
+        cmsIT8Free(hIT8);
+        return FALSE;
     }
 
     CookPointers(it8);
@@ -2242,44 +2316,44 @@ cmsHANDLE  CMSEXPORT cmsIT8LoadFromMem(cmsContext ContextID, void *Ptr, cmsUInt3
 cmsHANDLE  CMSEXPORT cmsIT8LoadFromFile(cmsContext ContextID, const char* cFileName)
 {
 
-     cmsHANDLE hIT8; 
+     cmsHANDLE hIT8;
      cmsIT8*  it8;
      int type;
-     
+
      _cmsAssert(cFileName != NULL);
 
      type = IsMyFile(cFileName);
      if (type == 0) return NULL;
 
      hIT8 = cmsIT8Alloc(ContextID);
-     it8 = (cmsIT8*) hIT8;   
+     it8 = (cmsIT8*) hIT8;
      if (!hIT8) return NULL;
 
 
      it8 ->FileStack[0]->Stream = fopen(cFileName, "rt");
 
-     if (!it8 ->FileStack[0]->Stream) {         
+     if (!it8 ->FileStack[0]->Stream) {
          cmsIT8Free(hIT8);
          return NULL;
      }
-     
 
-    strncpy(it8->FileStack[0]->FileName, cFileName, cmsMAX_PATH-1);    
+
+    strncpy(it8->FileStack[0]->FileName, cFileName, cmsMAX_PATH-1);
     it8->FileStack[0]->FileName[cmsMAX_PATH-1] = 0;
 
-    if (!ParseIT8(it8, type-1)) { 
-    
+    if (!ParseIT8(it8, type-1)) {
+
             fclose(it8 ->FileStack[0]->Stream);
-            cmsIT8Free(hIT8); 
-            return NULL; 
+            cmsIT8Free(hIT8);
+            return NULL;
     }
 
     CookPointers(it8);
     it8 ->nTable = 0;
 
     if (fclose(it8 ->FileStack[0]->Stream)!= 0) {
-            cmsIT8Free(hIT8); 
-            return NULL; 
+            cmsIT8Free(hIT8);
+            return NULL;
     }
 
     return hIT8;
@@ -2295,7 +2369,7 @@ int CMSEXPORT cmsIT8EnumDataFormat(cmsHANDLE hIT8, char ***SampleNames)
 
     t = GetTable(it8);
 
-    if (SampleNames) 
+    if (SampleNames)
         *SampleNames = t -> DataFormat;
     return t -> nSamples;
 }
@@ -2308,7 +2382,7 @@ cmsUInt32Number CMSEXPORT cmsIT8EnumProperties(cmsHANDLE hIT8, char ***PropertyN
     cmsUInt32Number n;
     char **Props;
     TABLE* t;
-    
+
     _cmsAssert(hIT8 != NULL);
 
     t = GetTable(it8);
@@ -2340,7 +2414,7 @@ cmsUInt32Number CMSEXPORT cmsIT8EnumPropertyMulti(cmsHANDLE hIT8, const char* cP
     cmsUInt32Number n;
     const char **Props;
     TABLE* t;
-    
+
     _cmsAssert(hIT8 != NULL);
 
 
@@ -2383,7 +2457,7 @@ int LocatePatch(cmsIT8* it8, const char* cPatch)
     for (i=0; i < t-> nPatches; i++) {
 
         data = GetData(it8, i, t->SampleID);
-        
+
         if (data != NULL) {
 
                 if (cmsstrcasecmp(data, cPatch) == 0)
@@ -2391,7 +2465,7 @@ int LocatePatch(cmsIT8* it8, const char* cPatch)
                 }
         }
 
-        // SynError(it8, "Couldn't find patch '%s'\n", cPatch);                               
+        // SynError(it8, "Couldn't find patch '%s'\n", cPatch);
         return -1;
 }
 
@@ -2407,7 +2481,7 @@ int LocateEmptyPatch(cmsIT8* it8)
 
         data = GetData(it8, i, t->SampleID);
 
-        if (data == NULL) 
+        if (data == NULL)
             return i;
 
     }
@@ -2428,7 +2502,7 @@ int LocateSample(cmsIT8* it8, const char* cSample)
         if (cmsstrcasecmp(fld, cSample) == 0)
             return i;
     }
-   
+
     return -1;
 
 }
@@ -2460,24 +2534,18 @@ cmsFloat64Number CMSEXPORT cmsIT8GetDataRowColDbl(cmsHANDLE hIT8, int row, int c
     const char* Buffer;
 
     Buffer = cmsIT8GetDataRowCol(hIT8, row, col);
-    
-    if (Buffer) {
-
-        return atof(Buffer);
-        
-    } else
-        return 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);        
+    return SetData(it8, row, col, Val);
 }
 
 
@@ -2489,13 +2557,13 @@ cmsBool CMSEXPORT cmsIT8SetDataRowColDbl(cmsHANDLE hIT8, int row, int col, cmsFl
     _cmsAssert(hIT8 != NULL);
 
     sprintf(Buff, it8->DoubleFormatter, Val);
-    
-    return SetData(it8, row, col, Buff);        
+
+    return SetData(it8, row, col, Buff);
 }
 
 
 
-const char* CMSEXPORT cmsIT8GetData(cmsHANDLE hIT8, const char* cPatch, const char* cSample)                        
+const char* CMSEXPORT cmsIT8GetData(cmsHANDLE hIT8, const char* cPatch, const char* cSample)
 {
     cmsIT8* it8 = (cmsIT8*) hIT8;
     int iField, iSet;
@@ -2503,12 +2571,12 @@ const char* CMSEXPORT cmsIT8GetData(cmsHANDLE hIT8, const char* cPatch, const ch
     _cmsAssert(hIT8 != NULL);
 
     iField = LocateSample(it8, cSample);
-    if (iField < 0) {       
+    if (iField < 0) {
         return NULL;
     }
 
     iSet = LocatePatch(it8, cPatch);
-    if (iSet < 0) {          
+    if (iSet < 0) {
             return NULL;
     }
 
@@ -2521,15 +2589,8 @@ cmsFloat64Number CMSEXPORT cmsIT8GetDataDbl(cmsHANDLE  it8, const char* cPatch,
     const char* Buffer;
 
     Buffer = cmsIT8GetData(it8, cPatch, cSample);
-    
-    if (Buffer) {
 
-        return atof(Buffer);
-        
-    } else {
-        
-        return 0;
-    }
+    return ParseFloatNumber(Buffer);
 }
 
 
@@ -2539,14 +2600,14 @@ cmsBool CMSEXPORT cmsIT8SetData(cmsHANDLE hIT8, const char* cPatch, const char*
     cmsIT8* it8 = (cmsIT8*) hIT8;
     int iField, iSet;
     TABLE* t;
-    
+
     _cmsAssert(hIT8 != NULL);
 
     t = GetTable(it8);
 
     iField = LocateSample(it8, cSample);
 
-    if (iField < 0) 
+    if (iField < 0)
         return FALSE;
 
     if (t-> nPatches == 0) {
@@ -2560,7 +2621,7 @@ cmsBool CMSEXPORT cmsIT8SetData(cmsHANDLE hIT8, const char* cPatch, const char*
 
         iSet   = LocateEmptyPatch(it8);
         if (iSet < 0) {
-            return SynError(it8, "Couldn't add more patches '%s'\n", cPatch);                        
+            return SynError(it8, "Couldn't add more patches '%s'\n", cPatch);
         }
 
         iField = t -> SampleID;
@@ -2605,7 +2666,7 @@ const char* CMSEXPORT cmsIT8GetPatchName(cmsHANDLE hIT8, int nPatch, char* buffe
     if (!Data) return NULL;
     if (!buffer) return Data;
 
-    strncpy(buffer, Data, MAXSTR-1);        
+    strncpy(buffer, Data, MAXSTR-1);
     buffer[MAXSTR-1] = 0;
     return buffer;
 }
@@ -2626,7 +2687,7 @@ cmsUInt32Number CMSEXPORT cmsIT8TableCount(cmsHANDLE hIT8)
     return it8 ->TablesCount;
 }
 
-// This handles the "LABEL" extension. 
+// This handles the "LABEL" extension.
 // Label, nTable, Type
 
 int CMSEXPORT cmsIT8SetTableByLabel(cmsHANDLE hIT8, const char* cSet, const char* cField, const char* ExpectedType)
@@ -2634,21 +2695,21 @@ int CMSEXPORT cmsIT8SetTableByLabel(cmsHANDLE hIT8, const char* cSet, const char
     const char* cLabelFld;
     char Type[256], Label[256];
     int nTable;
-   
+
     _cmsAssert(hIT8 != NULL);
 
     if (cField != NULL && *cField == 0)
             cField = "LABEL";
 
-    if (cField == NULL) 
+    if (cField == NULL)
             cField = "LABEL";
 
-    cLabelFld = cmsIT8GetData(hIT8, cSet, cField); 
+    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;
 
@@ -2657,7 +2718,7 @@ int CMSEXPORT cmsIT8SetTableByLabel(cmsHANDLE hIT8, const char* cSet, const char
         if (cmsstrcasecmp(Type, ExpectedType) != 0) return -1;
     }
 
-    return cmsIT8SetTable(hIT8, nTable);    
+    return cmsIT8SetTable(hIT8, nTable);
 }
 
 
index 1a8e6d8..01be555 100644 (file)
@@ -1,24 +1,24 @@
 //---------------------------------------------------------------------------------
 //
 //  Little Color Management System
-//  Copyright (c) 1998-2011 Marti Maria Saguer
+//  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 
+// 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 
+// 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 
+// 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 
+// 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, 
+cmsPipeline* _cmsLinkProfiles(cmsContext     ContextID,
                               cmsUInt32Number nProfiles,
-                              cmsUInt32Number Intents[], 
-                              cmsHPROFILE     hProfiles[], 
+                              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. 
+// 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, 
+static
+cmsPipeline* DefaultICCintents(cmsContext     ContextID,
                                cmsUInt32Number nProfiles,
-                               cmsUInt32Number Intents[], 
-                               cmsHPROFILE     hProfiles[], 
+                               cmsUInt32Number Intents[],
+                               cmsHPROFILE     hProfiles[],
                                cmsBool         BPC[],
                                cmsFloat64Number AdaptationStates[],
                                cmsUInt32Number dwFlags);
@@ -56,10 +56,10 @@ cmsPipeline* DefaultICCintents(cmsContext     ContextID,
 // 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, 
+cmsPipeline*  BlackPreservingKOnlyIntents(cmsContext     ContextID,
                                           cmsUInt32Number nProfiles,
-                                          cmsUInt32Number Intents[], 
-                                          cmsHPROFILE     hProfiles[], 
+                                          cmsUInt32Number Intents[],
+                                          cmsHPROFILE     hProfiles[],
                                           cmsBool         BPC[],
                                           cmsFloat64Number AdaptationStates[],
                                           cmsUInt32Number dwFlags);
@@ -69,10 +69,10 @@ cmsPipeline*  BlackPreservingKOnlyIntents(cmsContext     ContextID,
 // 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, 
+cmsPipeline*  BlackPreservingKPlaneIntents(cmsContext     ContextID,
                                            cmsUInt32Number nProfiles,
-                                           cmsUInt32Number Intents[], 
-                                           cmsHPROFILE     hProfiles[], 
+                                           cmsUInt32Number Intents[],
+                                           cmsHPROFILE     hProfiles[],
                                            cmsBool         BPC[],
                                            cmsFloat64Number AdaptationStates[],
                                            cmsUInt32Number dwFlags);
@@ -92,7 +92,7 @@ typedef struct _cms_intents_list {
 
 
 // Built-in intents
-static cmsIntentsList DefaultIntents[] = { 
+static cmsIntentsList DefaultIntents[] = {
 
     { INTENT_PERCEPTUAL,                            "Perceptual",                                   DefaultICCintents,            &DefaultIntents[1] },
     { INTENT_RELATIVE_COLORIMETRIC,                 "Relative colorimetric",                        DefaultICCintents,            &DefaultIntents[2] },
@@ -103,7 +103,7 @@ static cmsIntentsList DefaultIntents[] = {
     { 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 } 
+    { INTENT_PRESERVE_K_PLANE_SATURATION,           "Saturation preserving black plane",            BlackPreservingKPlaneIntents, NULL }
 };
 
 
@@ -111,7 +111,7 @@ static cmsIntentsList DefaultIntents[] = {
 static cmsIntentsList *Intents = DefaultIntents;
 
 // Search the list for a suitable intent. Returns NULL if not found
-static 
+static
 cmsIntentsList* SearchIntent(cmsUInt32Number Intent)
 {
     cmsIntentsList* pt;
@@ -122,16 +122,16 @@ cmsIntentsList* SearchIntent(cmsUInt32Number Intent)
     return NULL;
 }
 
-// Black point compensation. Implemented as a linear scaling in XYZ. Black points 
+// 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, 
+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
@@ -199,7 +199,7 @@ static
     cmsCIEXYZ White;
     cmsCIExyY ChromaticityOfWhite;
 
-    cmsWhitePointFromTemp(&ChromaticityOfWhite, Temp);  
+    cmsWhitePointFromTemp(&ChromaticityOfWhite, Temp);
     cmsxyY2XYZ(&White, &ChromaticityOfWhite);
     _cmsAdaptationMatrix(Chad, NULL, &White, cmsD50_XYZ());
 }
@@ -208,7 +208,7 @@ static
 // Result is stored in a 3x3 matrix
 static
 cmsBool  ComputeAbsoluteIntent(cmsFloat64Number AdaptationState,
-                               const cmsCIEXYZ* WhitePointIn,    
+                               const cmsCIEXYZ* WhitePointIn,
                                const cmsMAT3* ChromaticAdaptationMatrixIn,
                                const cmsCIEXYZ* WhitePointOut,
                                const cmsMAT3* ChromaticAdaptationMatrixOut,
@@ -219,7 +219,7 @@ cmsBool  ComputeAbsoluteIntent(cmsFloat64Number AdaptationState,
     // Adaptation state
     if (AdaptationState == 1.0) {
 
-        // Observer is fully adapted. Keep chromatic adaptation. 
+        // 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);
@@ -257,8 +257,8 @@ cmsBool  ComputeAbsoluteIntent(cmsFloat64Number AdaptationState,
             _cmsMAT3per(&m3, &m2, &Scale);
             // m3 holds CHAD from input white to D50 times abs. col. scaling
 
-            TempSrc  = CHAD2Temp(ChromaticAdaptationMatrixIn);  
-            TempDest = CHAD2Temp(ChromaticAdaptationMatrixOut); 
+            TempSrc  = CHAD2Temp(ChromaticAdaptationMatrixIn);
+            TempDest = CHAD2Temp(ChromaticAdaptationMatrixOut);
 
             if (TempSrc < 0.0 || TempDest < 0.0) return FALSE; // Something went wrong
 
@@ -288,12 +288,12 @@ 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]);
 
@@ -307,10 +307,10 @@ cmsBool IsEmptyLayer(cmsMAT3* m, cmsVEC3* off)
 
 // Compute the conversion layer
 static
-cmsBool ComputeConversion(int i, cmsHPROFILE hProfiles[], 
-                                 cmsUInt32Number Intent, 
-                                 cmsBool BPC, 
-                                 cmsFloat64Number AdaptationState, 
+cmsBool ComputeConversion(int i, cmsHPROFILE hProfiles[],
+                                 cmsUInt32Number Intent,
+                                 cmsBool BPC,
+                                 cmsFloat64Number AdaptationState,
                                  cmsMAT3* m, cmsVEC3* off)
 {
 
@@ -324,7 +324,7 @@ cmsBool ComputeConversion(int i, cmsHPROFILE hProfiles[],
     if (Intent == INTENT_ABSOLUTE_COLORIMETRIC) {
 
         cmsCIEXYZ WhitePointIn, WhitePointOut;
-        cmsMAT3 ChromaticAdaptationMatrixIn, ChromaticAdaptationMatrixOut;  
+        cmsMAT3 ChromaticAdaptationMatrixIn, ChromaticAdaptationMatrixOut;
 
         _cmsReadMediaWhitePoint(&WhitePointIn,  hProfiles[i-1]);
         _cmsReadCHAD(&ChromaticAdaptationMatrixIn, hProfiles[i-1]);
@@ -332,8 +332,8 @@ cmsBool ComputeConversion(int i, cmsHPROFILE hProfiles[],
         _cmsReadMediaWhitePoint(&WhitePointOut,  hProfiles[i]);
         _cmsReadCHAD(&ChromaticAdaptationMatrixOut, hProfiles[i]);
 
-        if (!ComputeAbsoluteIntent(AdaptationState, 
-                                  &WhitePointIn,  &ChromaticAdaptationMatrixIn, 
+        if (!ComputeAbsoluteIntent(AdaptationState,
+                                  &WhitePointIn,  &ChromaticAdaptationMatrixIn,
                                   &WhitePointOut, &ChromaticAdaptationMatrixOut, m)) return FALSE;
 
     }
@@ -345,24 +345,24 @@ cmsBool ComputeConversion(int i, cmsHPROFILE hProfiles[],
             cmsCIEXYZ BlackPointIn, BlackPointOut;
 
             cmsDetectBlackPoint(&BlackPointIn,  hProfiles[i-1], Intent, 0);
-            cmsDetectBlackPoint(&BlackPointOut, hProfiles[i], 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) 
+                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. 
+    // 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) 
+    // y' = (Mx'c + Off) /c = Mx' + (Off / c)
 
     for (k=0; k < 3; k++) {
         off ->n[k] /= MAX_ENCODEABLE_XYZ;
@@ -372,7 +372,7 @@ cmsBool ComputeConversion(int i, cmsHPROFILE hProfiles[],
 }
 
 
-// Add a conversion stage if needed. If a matrix/offset m is given, it applies to XYZ space 
+// 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)
 {
@@ -416,8 +416,8 @@ cmsBool AddConversion(cmsPipeline* Result, cmsColorSpaceSignature InPCS, cmsColo
 
             case cmsSigLabData:  // Lab -> Lab
 
-                if (!IsEmptyLayer(m, off)) {            
-                    cmsPipelineInsertStage(Result, cmsAT_END, _cmsStageAllocLab2XYZ(Result ->ContextID));        
+                if (!IsEmptyLayer(m, off)) {
+                    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));
                 }
@@ -446,6 +446,10 @@ cmsBool ColorSpaceIsCompatible(cmsColorSpaceSignature a, cmsColorSpaceSignature
     // 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;
@@ -456,10 +460,10 @@ cmsBool ColorSpaceIsCompatible(cmsColorSpaceSignature a, cmsColorSpaceSignature
 
 // Default handler for ICC-style intents
 static
-cmsPipeline* DefaultICCintents(cmsContext       ContextID, 
+cmsPipeline* DefaultICCintents(cmsContext       ContextID,
                                cmsUInt32Number  nProfiles,
-                               cmsUInt32Number  TheIntents[], 
-                               cmsHPROFILE      hProfiles[], 
+                               cmsUInt32Number  TheIntents[],
+                               cmsHPROFILE      hProfiles[],
                                cmsBool          BPC[],
                                cmsFloat64Number AdaptationStates[],
                                cmsUInt32Number  dwFlags)
@@ -468,7 +472,7 @@ cmsPipeline* DefaultICCintents(cmsContext       ContextID,
     cmsHPROFILE hProfile;
     cmsMAT3 m;
     cmsVEC3 off;
-    cmsColorSpaceSignature ColorSpaceIn, ColorSpaceOut, CurrentColorSpace; 
+    cmsColorSpaceSignature ColorSpaceIn, ColorSpaceOut, CurrentColorSpace;
     cmsProfileClassSignature ClassSig;
     cmsUInt32Number  i, Intent;
 
@@ -479,7 +483,7 @@ cmsPipeline* DefaultICCintents(cmsContext       ContextID,
     Result = cmsPipelineAlloc(ContextID, 0, 0);
     if (Result == NULL) return NULL;
 
-    CurrentColorSpace = cmsGetColorSpace(hProfiles[0]);    
+    CurrentColorSpace = cmsGetColorSpace(hProfiles[0]);
 
     for (i=0; i < nProfiles; i++) {
 
@@ -518,8 +522,8 @@ cmsPipeline* DefaultICCintents(cmsContext       ContextID,
             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 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
@@ -534,7 +538,7 @@ cmsPipeline* DefaultICCintents(cmsContext       ContextID,
                 _cmsMAT3identity(&m);
                 _cmsVEC3init(&off, 0, 0, 0);
              }
-        
+
 
             if (!AddConversion(Result, CurrentColorSpace, ColorSpaceIn, &m, &off)) goto Error;
 
@@ -543,13 +547,13 @@ cmsPipeline* DefaultICCintents(cmsContext       ContextID,
 
             if (lIsInput) {
                 // Input direction means non-pcs connection, so proceed like devicelinks
-                Lut = _cmsReadInputLUT(hProfile, Intent);       
+                Lut = _cmsReadInputLUT(hProfile, Intent);
                 if (Lut == NULL) goto Error;
             }
             else {
 
                 // Output direction means PCS connection. Intent may apply here
-                Lut = _cmsReadOutputLUT(hProfile, Intent); 
+                Lut = _cmsReadOutputLUT(hProfile, Intent);
                 if (Lut == NULL) goto Error;
 
 
@@ -561,10 +565,10 @@ cmsPipeline* DefaultICCintents(cmsContext       ContextID,
 
         // Concatenate to the output LUT
         cmsPipelineCat(Result, Lut);
-        cmsPipelineFree(Lut);                            
+        cmsPipelineFree(Lut);
 
         // Update current space
-        CurrentColorSpace = ColorSpaceOut;              
+        CurrentColorSpace = ColorSpaceOut;
     }
 
     return Result;
@@ -579,10 +583,10 @@ Error:
 
 
 // Wrapper for DLL calling convention
-cmsPipeline*  CMSEXPORT _cmsDefaultICCintents(cmsContext     ContextID, 
+cmsPipeline*  CMSEXPORT _cmsDefaultICCintents(cmsContext     ContextID,
                                               cmsUInt32Number nProfiles,
-                                              cmsUInt32Number TheIntents[], 
-                                              cmsHPROFILE     hProfiles[], 
+                                              cmsUInt32Number TheIntents[],
+                                              cmsHPROFILE     hProfiles[],
                                               cmsBool         BPC[],
                                               cmsFloat64Number AdaptationStates[],
                                               cmsUInt32Number dwFlags)
@@ -599,7 +603,7 @@ int TranslateNonICCIntents(int Intent)
     switch (Intent) {
         case INTENT_PRESERVE_K_ONLY_PERCEPTUAL:
         case INTENT_PRESERVE_K_PLANE_PERCEPTUAL:
-            return INTENT_PERCEPTUAL; 
+            return INTENT_PERCEPTUAL;
 
         case INTENT_PRESERVE_K_ONLY_RELATIVE_COLORIMETRIC:
         case INTENT_PRESERVE_K_PLANE_RELATIVE_COLORIMETRIC:
@@ -644,10 +648,10 @@ int BlackPreservingGrayOnlySampler(register const cmsUInt16Number In[], register
 
 // This is the entry for black-preserving K-only intents, which are non-ICC
 static
-cmsPipeline*  BlackPreservingKOnlyIntents(cmsContext     ContextID, 
+cmsPipeline*  BlackPreservingKOnlyIntents(cmsContext     ContextID,
                                           cmsUInt32Number nProfiles,
-                                          cmsUInt32Number TheIntents[], 
-                                          cmsHPROFILE     hProfiles[], 
+                                          cmsUInt32Number TheIntents[],
+                                          cmsHPROFILE     hProfiles[],
                                           cmsBool         BPC[],
                                           cmsFloat64Number AdaptationStates[],
                                           cmsUInt32Number dwFlags)
@@ -663,12 +667,12 @@ cmsPipeline*  BlackPreservingKOnlyIntents(cmsContext     ContextID,
     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]); 
+    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) 
+        cmsGetColorSpace(hProfiles[nProfiles-1]) != cmsSigCmykData)
            return DefaultICCintents(ContextID, nProfiles, ICCIntents, hProfiles, BPC, AdaptationStates, dwFlags);
 
     memset(&bp, 0, sizeof(bp));
@@ -678,32 +682,32 @@ cmsPipeline*  BlackPreservingKOnlyIntents(cmsContext     ContextID,
     if (Result == NULL) return NULL;
 
     // Create a LUT holding normal ICC transform
-    bp.cmyk2cmyk = DefaultICCintents(ContextID, 
+    bp.cmyk2cmyk = DefaultICCintents(ContextID,
         nProfiles,
-        ICCIntents, 
-        hProfiles, 
+        ICCIntents,
+        hProfiles,
         BPC,
         AdaptationStates,
         dwFlags);
 
     if (bp.cmyk2cmyk == NULL) goto Error;
-    
+
     // Now, compute the tone curve
-    bp.KTone = _cmsBuildKToneCurve(ContextID, 
-        4096, 
+    bp.KTone = _cmsBuildKToneCurve(ContextID,
+        4096,
         nProfiles,
-        ICCIntents, 
-        hProfiles, 
+        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;
@@ -712,9 +716,9 @@ cmsPipeline*  BlackPreservingKOnlyIntents(cmsContext     ContextID,
     cmsPipelineInsertStage(Result, cmsAT_BEGIN, CLUT);
 
     // Sample it. We cannot afford pre/post linearization this time.
-    if (!cmsStageSampleCLut16bit(CLUT, BlackPreservingGrayOnlySampler, (void*) &bp, 0)) 
+    if (!cmsStageSampleCLut16bit(CLUT, BlackPreservingGrayOnlySampler, (void*) &bp, 0))
         goto Error;
-    
+
     // Get rid of xform and tone curve
     cmsPipelineFree(bp.cmyk2cmyk);
     cmsFreeToneCurve(bp.KTone);
@@ -741,9 +745,9 @@ typedef struct {
     cmsPipeline*     LabK2cmyk;     // The output profile
     cmsFloat64Number MaxError;
 
-    cmsHTRANSFORM    hRoundTrip;               
+    cmsHTRANSFORM    hRoundTrip;
     cmsFloat64Number MaxTAC;
-    
+
 
 } PreserveKPlaneParams;
 
@@ -754,18 +758,18 @@ int BlackPreservingSampler(register const cmsUInt16Number In[], register cmsUInt
 {
     int i;
     cmsFloat32Number Inf[4], Outf[4];
-    cmsFloat32Number LabK[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++) 
+    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) {
 
@@ -773,28 +777,28 @@ int BlackPreservingSampler(register const cmsUInt16Number In[], register cmsUInt
         Out[3] = _cmsQuickSaturateWord(LabK[3] * 65535.0);
         return TRUE;
     }
-    
-    // Try the original transform, 
-    cmsPipelineEvalFloat( Inf, Outf, bp ->cmyk2cmyk);  
-    
+
+    // 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++) 
+    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 
+    // Obtain the corresponding CMY using reverse interpolation
     // (K is fixed in LabK[3])
     if (!cmsPipelineEvalReverseFloat(LabK, Outf, Outf, bp ->LabK2cmyk)) {
 
@@ -805,10 +809,10 @@ int BlackPreservingSampler(register const cmsUInt16Number In[], register cmsUInt
 
     // Make sure to pass thru K (which now is fixed)
     Outf[3] = LabK[3];
-       
-    // Apply TAC if needed    
+
+    // Apply TAC if needed
     SumCMY   = Outf[0]  + Outf[1] + Outf[2];
-    SumCMYK  = SumCMY + Outf[3];      
+    SumCMYK  = SumCMY + Outf[3];
 
     if (SumCMYK > bp ->MaxTAC) {
 
@@ -825,9 +829,9 @@ int BlackPreservingSampler(register const cmsUInt16Number In[], register cmsUInt
     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) 
+    cmsDoTransform(bp->hProofOutput, Out, &BlackPreservingLab, 1);
+    Error = cmsDeltaE(&ColorimetricLab, &BlackPreservingLab);
+    if (Error > bp -> MaxError)
         bp->MaxError = Error;
 
     return TRUE;
@@ -835,10 +839,10 @@ int BlackPreservingSampler(register const cmsUInt16Number In[], register cmsUInt
 
 // This is the entry for black-plane preserving, which are non-ICC
 static
-cmsPipeline* BlackPreservingKPlaneIntents(cmsContext     ContextID, 
+cmsPipeline* BlackPreservingKPlaneIntents(cmsContext     ContextID,
                                           cmsUInt32Number nProfiles,
-                                          cmsUInt32Number TheIntents[], 
-                                          cmsHPROFILE     hProfiles[], 
+                                          cmsUInt32Number TheIntents[],
+                                          cmsHPROFILE     hProfiles[],
                                           cmsBool         BPC[],
                                           cmsFloat64Number AdaptationStates[],
                                           cmsUInt32Number dwFlags)
@@ -847,27 +851,27 @@ cmsPipeline* BlackPreservingKPlaneIntents(cmsContext     ContextID,
     cmsPipeline*    Result = NULL;
     cmsUInt32Number ICCIntents[256];
     cmsStage*         CLUT;
-    cmsUInt32Number i, nGridPoints;    
+    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]); 
+    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) 
+        !(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
@@ -883,8 +887,8 @@ cmsPipeline* BlackPreservingKPlaneIntents(cmsContext     ContextID,
     // Create a LUT holding normal ICC transform
     bp.cmyk2cmyk = DefaultICCintents(ContextID,
                                          nProfiles,
-                                         ICCIntents, 
-                                         hProfiles, 
+                                         ICCIntents,
+                                         hProfiles,
                                          BPC,
                                          AdaptationStates,
                                          dwFlags);
@@ -892,26 +896,26 @@ cmsPipeline* BlackPreservingKPlaneIntents(cmsContext     ContextID,
 
     // Now the tone curve
     bp.KTone = _cmsBuildKToneCurve(ContextID, 4096, nProfiles,
-                                   ICCIntents, 
-                                   hProfiles, 
-                                   BPC, 
+                                   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, 
+    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, 
+    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);
@@ -922,7 +926,7 @@ cmsPipeline* BlackPreservingKPlaneIntents(cmsContext     ContextID,
     // How many gridpoints are we going to use?
     nGridPoints = _cmsReasonableGridpointsByColorspace(cmsSigCmykData, dwFlags);
 
-    
+
     CLUT = cmsStageAllocCLut16bit(ContextID, nGridPoints, 4, 4, NULL);
     if (CLUT == NULL) goto Cleanup;
 
@@ -933,10 +937,10 @@ cmsPipeline* BlackPreservingKPlaneIntents(cmsContext     ContextID,
 Cleanup:
 
     if (bp.cmyk2cmyk) cmsPipelineFree(bp.cmyk2cmyk);
-    if (bp.cmyk2Lab) cmsDeleteTransform(bp.cmyk2Lab);       
+    if (bp.cmyk2Lab) cmsDeleteTransform(bp.cmyk2Lab);
     if (bp.hProofOutput) cmsDeleteTransform(bp.hProofOutput);
-    
-    if (bp.KTone) cmsFreeToneCurve(bp.KTone);   
+
+    if (bp.KTone) cmsFreeToneCurve(bp.KTone);
     if (bp.LabK2cmyk) cmsPipelineFree(bp.LabK2cmyk);
 
     return Result;
@@ -945,12 +949,12 @@ Cleanup:
 // 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 
+// 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, 
+cmsPipeline* _cmsLinkProfiles(cmsContext     ContextID,
                               cmsUInt32Number nProfiles,
-                              cmsUInt32Number TheIntents[], 
-                              cmsHPROFILE     hProfiles[], 
+                              cmsUInt32Number TheIntents[],
+                              cmsHPROFILE     hProfiles[],
                               cmsBool         BPC[],
                               cmsFloat64Number AdaptationStates[],
                               cmsUInt32Number dwFlags)
@@ -966,9 +970,9 @@ cmsPipeline* _cmsLinkProfiles(cmsContext     ContextID,
 
     for (i=0; i < nProfiles; i++) {
 
-        // Check if black point is really needed or allowed. Note that 
+        // 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, 
+        // 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)
@@ -979,7 +983,7 @@ cmsPipeline* _cmsLinkProfiles(cmsContext     ContextID,
             // 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
@@ -999,8 +1003,8 @@ cmsPipeline* _cmsLinkProfiles(cmsContext     ContextID,
 
 // -------------------------------------------------------------------------------------------------
 
-// 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 
+// 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 cmsGetSupportedIntents(cmsUInt32Number nMax, cmsUInt32Number* Codes, char** Descriptions)
 {
@@ -1010,10 +1014,10 @@ cmsUInt32Number CMSEXPORT cmsGetSupportedIntents(cmsUInt32Number nMax, cmsUInt32
     for (nIntents=0, pt = Intents; pt != NULL; pt = pt -> Next)
     {
         if (nIntents < nMax) {
-            if (Codes != NULL) 
+            if (Codes != NULL)
                 Codes[nIntents] = pt ->Intent;
 
-            if (Descriptions != NULL) 
+            if (Descriptions != NULL)
                 Descriptions[nIntents] = pt ->Description;
         }
 
@@ -1031,7 +1035,7 @@ cmsBool  _cmsRegisterRenderingIntentPlugin(cmsPluginBase* Data)
 
     // Do we have to reset the intents?
     if (Data == NULL) {
-    
+
        Intents = DefaultIntents;
        return TRUE;
     }
index 5f93c16..5756c0d 100644 (file)
@@ -1,24 +1,24 @@
 //---------------------------------------------------------------------------------
 //
 //  Little Color Management System
-//  Copyright (c) 1998-2010 Marti Maria Saguer
+//  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 
+// 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 
+// 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 
+// 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.
 //
 //---------------------------------------------------------------------------------
@@ -43,18 +43,18 @@ int CMSEXPORT cmsstrcasecmp(const char* s1, const char* s2)
 // long int because C99 specifies ftell in such way (7.19.9.2)
 long int CMSEXPORT cmsfilelength(FILE* f)
 {
-    long int p , n; 
+    long int p , n;
 
-    p = ftell(f); // register current file position 
+    p = ftell(f); // register current file position
 
-    if (fseek(f, 0, SEEK_END) != 0) { 
-        return -1; 
-    } 
+    if (fseek(f, 0, SEEK_END) != 0) {
+        return -1;
+    }
 
-    n = ftell(f); 
-    fseek(f, p, SEEK_SET); // file position restored 
+    n = ftell(f);
+    fseek(f, p, SEEK_SET); // file position restored
 
-    return n; 
+    return n;
 }
 
 
@@ -62,23 +62,23 @@ long int CMSEXPORT cmsfilelength(FILE* f)
 //
 // 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 
+// amount of memoy that can be reclaimed. This is mostly as a safety feature to
 // prevent bogus or malintentionated 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 
+// 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(cmsPluginBase* Plugin);
 
 // *********************************************************************************
 
-// This is the default memory allocation function. It does a very coarse 
+// 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)
@@ -109,13 +109,13 @@ 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); 
+    if (Ptr) free(Ptr);
 
     cmsUNUSED_PARAMETER(ContextID);
 }
 
-// The default realloc function. Again it check for exploits. If Ptr is NULL, 
-// realloc behaves the same way as malloc and allocates a new block of size bytes. 
+// The default realloc function. Again it check 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)
 {
@@ -139,13 +139,13 @@ void* _cmsCallocDefaultFn(cmsContext ContextID, cmsUInt32Number num, cmsUInt32Nu
     if (Total == 0) return NULL;
 
     // Safe check for overflow.
-    if (num >= UINT_MAX / size) return NULL; 
+    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);
@@ -156,7 +156,7 @@ 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);
@@ -171,7 +171,7 @@ void* _cmsDupDefaultFn(cmsContext ContextID, const void* Org, cmsUInt32Number si
 static void * (* MallocPtr)(cmsContext ContextID, cmsUInt32Number size)                     = _cmsMallocDefaultFn;
 static void * (* MallocZeroPtr)(cmsContext ContextID, cmsUInt32Number size)                 = _cmsMallocZeroDefaultFn;
 static void   (* FreePtr)(cmsContext ContextID, void *Ptr)                                  = _cmsFreeDefaultFn;
-static void * (* ReallocPtr)(cmsContext ContextID, void *Ptr, cmsUInt32Number NewSize)      = _cmsReallocDefaultFn; 
+static void * (* ReallocPtr)(cmsContext ContextID, void *Ptr, cmsUInt32Number NewSize)      = _cmsReallocDefaultFn;
 static void * (* CallocPtr)(cmsContext ContextID, cmsUInt32Number num, cmsUInt32Number size)= _cmsCallocDefaultFn;
 static void * (* DupPtr)(cmsContext ContextID, const void* Org, cmsUInt32Number size)       = _cmsDupDefaultFn;
 
@@ -186,7 +186,7 @@ cmsBool  _cmsRegisterMemHandlerPlugin(cmsPluginBase *Data)
         MallocPtr    = _cmsMallocDefaultFn;
         MallocZeroPtr= _cmsMallocZeroDefaultFn;
         FreePtr      = _cmsFreeDefaultFn;
-        ReallocPtr   = _cmsReallocDefaultFn; 
+        ReallocPtr   = _cmsReallocDefaultFn;
         CallocPtr    = _cmsCallocDefaultFn;
         DupPtr       = _cmsDupDefaultFn;
         return TRUE;
@@ -249,7 +249,7 @@ void* CMSEXPORT _cmsDupMem(cmsContext ContextID, const void* Org, cmsUInt32Numbe
 
 // 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 
+// 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)
@@ -329,7 +329,7 @@ void*  _cmsSubAlloc(_cmsSubAllocator* sub, cmsUInt32Number size)
 
     size = _cmsALIGNMEM(size);
 
-    // Check for memory. If there is no room, allocate a new chunk of double memory size.   
+    // Check for memory. If there is no room, allocate a new chunk of double memory size.
     if (size > Free) {
 
         _cmsSubAllocator_chunk* chunk;
@@ -346,7 +346,7 @@ void*  _cmsSubAlloc(_cmsSubAllocator* sub, cmsUInt32Number size)
         sub ->h    = chunk;
 
     }
-            
+
     ptr =  sub -> h ->Block + sub -> h ->Used;
     sub -> h -> Used += size;
 
@@ -359,7 +359,7 @@ void*  _cmsSubAlloc(_cmsSubAllocator* sub, cmsUInt32Number size)
 // 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 
+// 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
@@ -383,7 +383,7 @@ void DefaultLogErrorHandlerFunction(cmsContext ContextID, cmsUInt32Number ErrorC
 {
     // fprintf(stderr, "[lcms]: %s\n", Text);
     // fflush(stderr);
-   
+
      cmsUNUSED_PARAMETER(ContextID);
      cmsUNUSED_PARAMETER(ErrorCode);
      cmsUNUSED_PARAMETER(Text);
@@ -392,13 +392,13 @@ void DefaultLogErrorHandlerFunction(cmsContext ContextID, cmsUInt32Number ErrorC
 // Change log error
 void CMSEXPORT cmsSetLogErrorHandler(cmsLogErrorHandlerFunction Fn)
 {
-    if (Fn == NULL) 
+    if (Fn == NULL)
         LogErrorHandler = DefaultLogErrorHandlerFunction;
     else
         LogErrorHandler = Fn;
 }
 
-// Log an error 
+// Log an error
 // ErrorText is a text holding an english description of error.
 void CMSEXPORT cmsSignalError(cmsContext ContextID, cmsUInt32Number ErrorCode, const char *ErrorText, ...)
 {
@@ -407,7 +407,7 @@ void CMSEXPORT cmsSignalError(cmsContext ContextID, cmsUInt32Number ErrorCode, c
 
     va_start(args, ErrorText);
     vsnprintf(Buffer, MAX_ERROR_MESSAGE_LEN-1, ErrorText, args);
-    va_end(args);   
+    va_end(args);
 
     // Call handler
     LogErrorHandler(ContextID, ErrorCode, Buffer);
@@ -421,7 +421,7 @@ void _cmsTagSignature2String(char String[5], cmsTagSignature sig)
     // Convert to big endian
     be = _cmsAdjustEndianess32((cmsUInt32Number) sig);
 
-    // Move chars 
+    // Move chars
     memmove(String, &be, 4);
 
     // Make sure of terminator
index 02dc910..1202359 100644 (file)
@@ -1,42 +1,42 @@
 //---------------------------------------------------------------------------------
 //
 //  Little Color Management System
-//  Copyright (c) 1998-2010 Marti Maria Saguer
+//  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 
+// 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 
+// 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 
+// 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. 
+// 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, 
+// 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 
+// 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 
+// Maxim number of nodes
 #define MAX_NODES_IN_CURVE   4097
 #define MINUS_INF            (-1E22F)
 #define PLUS_INF             (+1E22F)
@@ -54,11 +54,11 @@ typedef struct _cmsParametricCurvesCollection_st {
 } _cmsParametricCurvesCollection;
 
 
-// This is the default (built-in) evaluator 
+// This is the default (built-in) evaluator
 static cmsFloat64Number DefaultEvalParametricFn(cmsInt32Number Type, const cmsFloat64Number Params[], cmsFloat64Number R);
 
 // The built-in list
-static _cmsParametricCurvesCollection DefaultCurves = { 
+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
@@ -74,9 +74,9 @@ cmsBool _cmsRegisterParametricCurvesPlugin(cmsPluginBase* Data)
 {
     cmsPluginParametricCurves* Plugin = (cmsPluginParametricCurves*) Data;
     _cmsParametricCurvesCollection* fl;
-    
+
     if (Data == NULL) {
-    
+
           ParametricCurves =  &DefaultCurves;
           return TRUE;
     }
@@ -130,7 +130,7 @@ _cmsParametricCurvesCollection *GetParametricCurveByType(int Type, int* index)
         Position = IsInSet(Type, c);
 
         if (Position != -1) {
-            if (index != NULL) 
+            if (index != NULL)
                 *index = Position;
             return c;
         }
@@ -139,12 +139,12 @@ _cmsParametricCurvesCollection *GetParametricCurveByType(int Type, int* index)
     return NULL;
 }
 
-// Low level allocate, which takes care of memory details. nEntries may be zero, and in this case 
+// 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, 
+cmsToneCurve* AllocateToneCurveStruct(cmsContext ContextID, cmsInt32Number nEntries,
+                                      cmsInt32Number nSegments, const cmsCurveSegment* Segments,
                                       const cmsUInt16Number* Values)
 {
     cmsToneCurve* p;
@@ -179,7 +179,7 @@ cmsToneCurve* AllocateToneCurveStruct(cmsContext ContextID, cmsInt32Number nEntr
     }
 
     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) {
@@ -189,13 +189,13 @@ cmsToneCurve* AllocateToneCurveStruct(cmsContext ContextID, cmsInt32Number nEntr
        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++) 
+        for (i=0; i < nEntries; i++)
             p ->Table16[i] = Values[i];
     }
 
@@ -227,7 +227,7 @@ cmsToneCurve* AllocateToneCurveStruct(cmsContext ContextID, cmsInt32Number nEntr
                     p ->Evals[i] = c ->Evaluator;
         }
     }
-    
+
     p ->InterpParams = _cmsComputeInterpParams(ContextID, p ->nEntries, 1, 1, p->Table16, CMS_LERP_FLAGS_16BITS);
     return p;
 
@@ -248,18 +248,28 @@ cmsFloat64Number DefaultEvalParametricFn(cmsInt32Number Type, const cmsFloat64Nu
 
     switch (Type) {
 
-    // X = Y ^ Gamma
+   // X = Y ^ Gamma
     case 1:
-        if (R < 0) 
-            Val = 0;
+        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)
-            Val = 0;
+         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;
@@ -285,14 +295,14 @@ cmsFloat64Number DefaultEvalParametricFn(cmsInt32Number Type, const cmsFloat64Nu
 
      // Type 2 Reversed
      // X = (Y ^1/g  - b) / a
-     case -2: 
+     case -2:
          if (R < 0)
              Val = 0;
          else
              Val = (pow(R, 1.0/Params[0]) - Params[2]) / Params[1];
 
          if (Val < 0)
-              Val = 0;                            
+              Val = 0;
          break;
 
 
@@ -306,7 +316,7 @@ cmsFloat64Number DefaultEvalParametricFn(cmsInt32Number Type, const cmsFloat64Nu
 
         if (R >= disc) {
 
-            e = Params[1]*R + Params[2];  
+            e = Params[1]*R + Params[2];
 
             if (e > 0)
                 Val = pow(e, Params[0]) + Params[3];
@@ -320,15 +330,15 @@ cmsFloat64Number DefaultEvalParametricFn(cmsInt32Number Type, const cmsFloat64Nu
 
     // Type 3 reversed
     // X=((Y-c)^1/g - b)/a      | (Y>=c)
-    // X=-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 
+            else
                 Val = 0;
         }
         else {
@@ -385,7 +395,7 @@ cmsFloat64Number DefaultEvalParametricFn(cmsInt32Number Type, const cmsFloat64Nu
                 Val = pow(e, Params[0]) + Params[5];
             else
                 Val = 0;
-        }        
+        }
         else
             Val = R*Params[3] + Params[6];
         break;
@@ -400,7 +410,7 @@ cmsFloat64Number DefaultEvalParametricFn(cmsInt32Number Type, const cmsFloat64Nu
         if (R >= disc) {
 
             e = R - Params[5];
-            if (e < 0) 
+            if (e < 0)
                 Val = 0;
             else
                 Val = (pow(e, 1.0/Params[0]) - Params[2]) / Params[1];
@@ -413,29 +423,29 @@ cmsFloat64Number DefaultEvalParametricFn(cmsInt32Number Type, const cmsFloat64Nu
 
     // 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:    
+    case 6:
         e = Params[1]*R + Params[2];
 
-        if (e < 0) 
+        if (e < 0)
             Val = 0;
-        else 
+        else
             Val = pow(e, Params[0]) + Params[3];
         break;
 
-    // ((Y - c) ^1/Gamma - b) / a                        
+    // ((Y - c) ^1/Gamma - b) / a
     case -6:
         e = R - Params[3];
         if (e < 0)
             Val = 0;
-        else 
+        else
         Val = (pow(e, 1.0/Params[0]) - Params[2]) / Params[1];
         break;
 
 
     // Y = a * log (b * X^Gamma + c) + d
-    case 7:                   
+    case 7:
 
        e = Params[2] * pow(R, Params[0]) + Params[3];
        if (e <= 0)
@@ -446,13 +456,13 @@ cmsFloat64Number DefaultEvalParametricFn(cmsInt32Number Type, const cmsFloat64Nu
 
     // (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 
+    // 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          
+   //Y = a * b^(c*X+d) + e
    case 8:
        Val = (Params[0] * pow(Params[1], Params[2] * R + Params[3]) + Params[4]);
        break;
@@ -461,14 +471,14 @@ cmsFloat64Number DefaultEvalParametricFn(cmsInt32Number Type, const cmsFloat64Nu
    // 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];         
+       else
+           Val = (log(disc / Params[0]) / log(Params[1]) - Params[3]) / Params[2];
        break;
 
-   // S-Shaped: (1 - (1-x)^1/g)^1/g                    
+   // 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;
@@ -491,7 +501,7 @@ cmsFloat64Number DefaultEvalParametricFn(cmsInt32Number Type, const cmsFloat64Nu
 }
 
 // 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 
+// If fn type is 0, perform an interpolation on the table
 static
 cmsFloat64Number EvalSegmentedFn(const cmsToneCurve *g, cmsFloat64Number R)
 {
@@ -509,10 +519,10 @@ cmsFloat64Number EvalSegmentedFn(const cmsToneCurve *g, cmsFloat64Number R)
                 cmsFloat32Number Out;
 
                 // Setup the table (TODO: clean that)
-                g ->SegInterp[i]-> Table = g ->Segments[i].SampledPoints; 
+                g ->SegInterp[i]-> Table = g ->Segments[i].SampledPoints;
 
                 g ->SegInterp[i] -> Interpolation.LerpFloat(&R1, &Out, g ->SegInterp[i]);
-                
+
                 return Out;
             }
             else
@@ -523,6 +533,19 @@ cmsFloat64Number EvalSegmentedFn(const cmsToneCurve *g, cmsFloat64Number 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.
@@ -540,17 +563,17 @@ int EntriesByGamma(cmsFloat64Number Gamma)
 
 
 // Create a segmented gamma, fill the table
-cmsToneCurve* CMSEXPORT cmsBuildSegmentedToneCurve(cmsContext ContextID, 
+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. 
+    // Optimizatin for identity curves.
     if (nSegments == 1 && Segments[0].Type == 1) {
 
         nGridPoints = EntriesByGamma(Segments[0].Params[0]);
@@ -592,7 +615,7 @@ cmsToneCurve* CMSEXPORT cmsBuildTabulatedToneCurveFloat(cmsContext ContextID, cm
 
     // From zero to any
     Seg[1].x0 = 0;
-    Seg[1].x1 = 1.0;   
+    Seg[1].x1 = 1.0;
     Seg[1].Type = 0;
 
     Seg[1].nGridPoints = nEntries;
@@ -616,7 +639,7 @@ cmsToneCurve* CMSEXPORT cmsBuildParametricToneCurve(cmsContext ContextID, cmsInt
     _cmsAssert(Params != NULL);
 
     if (c == NULL) {
-         cmsSignalError(ContextID, cmsERROR_UNKNOWN_EXTENSION, "Invalid parametric curve type %d", Type);     
+         cmsSignalError(ContextID, cmsERROR_UNKNOWN_EXTENSION, "Invalid parametric curve type %d", Type);
         return NULL;
     }
 
@@ -645,27 +668,27 @@ cmsToneCurve* CMSEXPORT cmsBuildGamma(cmsContext ContextID, cmsFloat64Number Gam
 void CMSEXPORT cmsFreeToneCurve(cmsToneCurve* Curve)
 {
     cmsContext ContextID;
-    
+
     if (Curve == NULL) return;
 
     ContextID = Curve ->InterpParams->ContextID;
 
     _cmsFreeInterpParams(Curve ->InterpParams);
-    
+
     if (Curve -> Table16)
         _cmsFree(ContextID, Curve ->Table16);
 
     if (Curve ->Segments) {
 
         cmsUInt32Number i;
-        
+
         for (i=0; i < Curve ->nSegments; i++) {
 
             if (Curve ->Segments[i].SampledPoints) {
                 _cmsFree(ContextID, Curve ->Segments[i].SampledPoints);
             }
 
-            if (Curve ->SegInterp[i] != 0) 
+            if (Curve ->SegInterp[i] != 0)
                 _cmsFreeInterpParams(Curve->SegInterp[i]);
         }
 
@@ -695,18 +718,18 @@ void CMSEXPORT cmsFreeToneCurveTriple(cmsToneCurve* Curve[3])
 
 // Duplicate a gamma table
 cmsToneCurve* CMSEXPORT cmsDupToneCurve(const cmsToneCurve* In)
-{   
+{
     if (In == NULL) return NULL;
 
     return  AllocateToneCurveStruct(In ->InterpParams ->ContextID, In ->nEntries, In ->nSegments, In ->Segments, In ->Table16);
 }
 
 // Joins two curves for X and Y. Curves should be monotonic.
-// We want to get 
+// We want to get
 //
-//      y = Y^-1(X(t)) 
+//      y = Y^-1(X(t))
 //
-cmsToneCurve* CMSEXPORT cmsJoinToneCurve(cmsContext ContextID, 
+cmsToneCurve* CMSEXPORT cmsJoinToneCurve(cmsContext ContextID,
                                       const cmsToneCurve* X,
                                       const cmsToneCurve* Y, cmsUInt32Number nResultingPoints)
 {
@@ -725,7 +748,7 @@ cmsToneCurve* CMSEXPORT cmsJoinToneCurve(cmsContext ContextID,
 
     Res = (cmsFloat32Number*) _cmsCalloc(ContextID, nResultingPoints, sizeof(cmsFloat32Number));
     if (Res == NULL) goto Error;
-    
+
     //Iterate
     for (i=0; i <  nResultingPoints; i++) {
 
@@ -736,7 +759,7 @@ cmsToneCurve* CMSEXPORT cmsJoinToneCurve(cmsContext ContextID,
 
     // Allocate space for output
     out = cmsBuildTabulatedToneCurveFloat(ContextID, nResultingPoints, Res);
-    
+
 Error:
 
     if (Res != NULL) _cmsFree(ContextID, Res);
@@ -747,25 +770,25 @@ Error:
 
 
 
-// Get the surrounding nodes. This is tricky on non-monotonic tables 
+// Get the surrounding nodes. This is tricky on non-monotonic tables
 static
 int GetInterval(cmsFloat64Number In, const cmsUInt16Number LutTable[], const struct _cms_interp_struc* p)
-{   
+{
     int i;
     int y0, y1;
-    
+
     // A 1 point table is not allowed
     if (p -> Domain[0] < 1) return -1;
 
-    // Let's see if ascending or descending. 
+    // Let's see if ascending or descending.
     if (LutTable[0] < LutTable[p ->Domain[0]]) {
 
         // Table is overall ascending
         for (i=p->Domain[0]-1; i >=0; --i) {
 
-            y0 = LutTable[i]; 
+            y0 = LutTable[i];
             y1 = LutTable[i+1];
-            
+
             if (y0 <= y1) { // Increasing
                 if (In >= y0 && In <= y1) return i;
             }
@@ -779,7 +802,7 @@ int GetInterval(cmsFloat64Number In, const cmsUInt16Number LutTable[], const str
         // Table is overall descending
         for (i=0; i < (int) p -> Domain[0]; i++) {
 
-            y0 = LutTable[i]; 
+            y0 = LutTable[i];
             y1 = LutTable[i+1];
 
             if (y0 <= y1) { // Increasing
@@ -802,18 +825,18 @@ cmsToneCurve* CMSEXPORT cmsReverseToneCurveEx(cmsInt32Number nResultSamples, con
     cmsFloat64Number a = 0, b = 0, y, x1, y1, x2, y2;
     int i, j;
     int Ascending;
-    
+
     _cmsAssert(InCurve != NULL);
 
     // Try to reverse it analytically whatever possible
     if (InCurve ->nSegments == 1 && InCurve ->Segments[0].Type > 0 && InCurve -> Segments[0].Type <= 5) {
 
-        return cmsBuildParametricToneCurve(InCurve ->InterpParams->ContextID, 
-                                       -(InCurve -> Segments[0].Type), 
+        return cmsBuildParametricToneCurve(InCurve ->InterpParams->ContextID,
+                                       -(InCurve -> Segments[0].Type),
                                        InCurve -> Segments[0].Params);
     }
 
-    // Nope, reverse the table. 
+    // Nope, reverse the table.
     out = cmsBuildTabulatedToneCurve16(InCurve ->InterpParams->ContextID, nResultSamples, NULL);
     if (out == NULL)
         return NULL;
@@ -826,18 +849,18 @@ cmsToneCurve* CMSEXPORT cmsReverseToneCurveEx(cmsInt32Number nResultSamples, con
 
         y = (cmsFloat64Number) i * 65535.0 / (nResultSamples - 1);
 
-        // Find interval in which y is within. 
+        // Find interval in which y is within.
         j = GetInterval(y, InCurve->Table16, InCurve->InterpParams);
         if (j >= 0) {
 
 
             // Get limits of interval
-            x1 = InCurve ->Table16[j]; 
+            x1 = InCurve ->Table16[j];
             x2 = InCurve ->Table16[j+1];
 
             y1 = (cmsFloat64Number) (j * 65535.0) / (InCurve ->nEntries - 1);
             y2 = (cmsFloat64Number) ((j+1) * 65535.0 ) / (InCurve ->nEntries - 1);
-    
+
             // If collapsed, then use any
             if (x1 == x2) {
 
@@ -846,12 +869,12 @@ cmsToneCurve* CMSEXPORT cmsReverseToneCurveEx(cmsInt32Number nResultSamples, con
 
             } else {
 
-                // Interpolate      
+                // Interpolate
                 a = (y2 - y1) / (x2 - x1);
                 b = y2 - a * x2;
             }
         }
-           
+
         out ->Table16[i] = _cmsQuickSaturateWord(a* y + b);
     }
 
@@ -887,7 +910,7 @@ cmsBool smooth2(cmsContext ContextID, cmsFloat32Number w[], cmsFloat32Number y[]
     c = (cmsFloat32Number*) _cmsCalloc(ContextID, MAX_NODES_IN_CURVE, sizeof(cmsFloat32Number));
     d = (cmsFloat32Number*) _cmsCalloc(ContextID, MAX_NODES_IN_CURVE, sizeof(cmsFloat32Number));
     e = (cmsFloat32Number*) _cmsCalloc(ContextID, MAX_NODES_IN_CURVE, sizeof(cmsFloat32Number));
-    
+
     if (c != NULL && d != NULL && e != NULL) {
 
 
@@ -899,7 +922,7 @@ cmsBool smooth2(cmsContext ContextID, cmsFloat32Number w[], cmsFloat32Number y[]
     c[2] = (-4 * lambda - d[1] * c[1] * e[1]) / d[2];
     e[2] = lambda / d[2];
     z[2] = w[2] * y[2] - c[1] * z[1];
-    
+
     for (i = 3; i < m - 1; i++) {
         i1 = i - 1; i2 = i - 2;
         d[i]= w[i] + 6 * lambda - c[i1] * c[i1] * d[i1] - e[i2] * e[i2] * d[i2];
@@ -907,18 +930,18 @@ cmsBool smooth2(cmsContext ContextID, cmsFloat32Number w[], cmsFloat32Number y[]
         e[i] = lambda / d[i];
         z[i] = w[i] * y[i] - c[i1] * z[i1] - e[i2] * z[i2];
     }
-    
+
     i1 = m - 2; i2 = m - 3;
-    
+
     d[m - 1] = w[m - 1] + 5 * lambda -c[i1] * c[i1] * d[i1] - e[i2] * e[i2] * d[i2];
     c[m - 1] = (-2 * lambda - d[i1] * c[i1] * e[i1]) / d[m - 1];
     z[m - 1] = w[m - 1] * y[m - 1] - c[i1] * z[i1] - e[i2] * z[i2];
     i1 = m - 1; i2 = m - 2;
-    
+
     d[m] = w[m] + lambda - c[i1] * c[i1] * d[i1] - e[i2] * e[i2] * d[i2];
     z[m] = (w[m] * y[m] - c[i1] * z[i1] - e[i2] * z[i2]) / d[m];
     z[m - 1] = z[m - 1] / d[m - 1] - c[m - 1] * z[m];
-    
+
     for (i = m - 2; 1<= i; i--)
         z[i] = z[i] / d[i] - c[i] * z[i + 1] - e[i] * z[i + 2];
 
@@ -933,7 +956,7 @@ cmsBool smooth2(cmsContext ContextID, cmsFloat32Number w[], cmsFloat32Number y[]
     return st;
 }
 
-// Smooths a curve sampled at regular intervals. 
+// Smooths a curve sampled at regular intervals.
 cmsBool  CMSEXPORT cmsSmoothToneCurve(cmsToneCurve* Tab, cmsFloat64Number lambda)
 {
     cmsFloat32Number w[MAX_NODES_IN_CURVE], y[MAX_NODES_IN_CURVE], z[MAX_NODES_IN_CURVE];
@@ -1011,14 +1034,14 @@ cmsBool  CMSEXPORT cmsIsToneCurveMonotonic(const cmsToneCurve* t)
     cmsBool lDescending;
 
     _cmsAssert(t != NULL);
-   
+
     // Degenerated curves are monotonic? Ok, let's pass them
     n = t ->nEntries;
     if (n < 2) return TRUE;
 
     // Curve direction
-    lDescending = cmsIsToneCurveDescending(t);     
-   
+    lDescending = cmsIsToneCurveDescending(t);
+
     if (lDescending) {
 
         last = t ->Table16[0];
@@ -1037,7 +1060,7 @@ cmsBool  CMSEXPORT cmsIsToneCurveMonotonic(const cmsToneCurve* t)
         last = t ->Table16[n-1];
 
         for (i = n-2; i >= 0; --i) {
-          
+
             if (t ->Table16[i] - last > 2)
                 return FALSE;
             else
@@ -1083,10 +1106,10 @@ cmsFloat32Number CMSEXPORT cmsEvalToneCurveFloat(const cmsToneCurve* Curve, cmsF
     if (Curve ->nSegments == 0) {
 
         cmsUInt16Number In, Out;
-        
+
         In = (cmsUInt16Number) _cmsQuickSaturateWord(v * 65535.0);
         Out = cmsEvalToneCurve16(Curve, In);
-        
+
         return (cmsFloat32Number) (Out / 65535.0);
     }
 
@@ -1106,21 +1129,21 @@ cmsUInt16Number CMSEXPORT cmsEvalToneCurve16(const cmsToneCurve* Curve, cmsUInt1
 
 
 // Least squares fitting.
-// A mathematical procedure for finding the best-fitting curve to a given set of points by 
-// minimizing the sum of the squares of the offsets ("the residuals") of the points from the curve. 
-// The sum of the squares of the offsets is used instead of the offset absolute values because 
-// this allows the residuals to be treated as a continuous differentiable quantity. 
+// A mathematical procedure for finding the best-fitting curve to a given set of points by
+// minimizing the sum of the squares of the offsets ("the residuals") of the points from the curve.
+// The sum of the squares of the offsets is used instead of the offset absolute values because
+// this allows the residuals to be treated as a continuous differentiable quantity.
 //
 // y = f(x) = x ^ g
 //
 // R  = (yi - (xi^g))
 // R2 = (yi - (xi^g))2
 // SUM R2 = SUM (yi - (xi^g))2
-// 
-// dR2/dg = -2 SUM x^g log(x)(y - x^g)    
-// solving for dR2/dg = 0 
-// 
-// g = 1/n * SUM(log(y) / log(x)) 
+//
+// dR2/dg = -2 SUM x^g log(x)(y - x^g)
+// solving for dR2/dg = 0
+//
+// g = 1/n * SUM(log(y) / log(x))
 
 cmsFloat64Number CMSEXPORT cmsEstimateGamma(const cmsToneCurve* t, cmsFloat64Number Precision)
 {
@@ -1132,13 +1155,13 @@ cmsFloat64Number CMSEXPORT cmsEstimateGamma(const cmsToneCurve* t, cmsFloat64Num
 
     sum = sum2 = n = 0;
 
-    // Excluding endpoints   
+    // Excluding endpoints
     for (i=1; i < (MAX_NODES_IN_CURVE-1); i++) {
 
         x = (cmsFloat64Number) i / (MAX_NODES_IN_CURVE-1);
         y = (cmsFloat64Number) cmsEvalToneCurveFloat(t, (cmsFloat32Number) x);
 
-        // Avoid 7% on lower part to prevent 
+        // Avoid 7% on lower part to prevent
         // artifacts due to linear ramps
 
         if (y > 0. && y < 1. && x > 0.07) {
index 9fec390..601ec29 100644 (file)
-//---------------------------------------------------------------------------------
-//
-//  Little Color Management System
-//  Copyright (c) 1998-2010 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"
-
-
-// Auxiliar: append a Lab identity after the given sequence of profiles
-// and return the transform. Lab profile is closed, rest of profiles are kept open.
-cmsHTRANSFORM _cmsChain2Lab(cmsContext            ContextID,
-                            cmsUInt32Number        nProfiles,
-                            cmsUInt32Number        InputFormat,
-                            cmsUInt32Number        OutputFormat,
-                            const cmsUInt32Number  Intents[], 
-                            const cmsHPROFILE      hProfiles[], 
-                            const cmsBool          BPC[],
-                            const cmsFloat64Number AdaptationStates[],
-                            cmsUInt32Number        dwFlags)
-{
-    cmsHTRANSFORM xform;
-    cmsHPROFILE   hLab;
-    cmsHPROFILE   ProfileList[256];
-    cmsBool       BPCList[256];
-    cmsFloat64Number AdaptationList[256];
-    cmsUInt32Number IntentList[256];
-    cmsUInt32Number i;
-
-    // This is a rather big number and there is no need of dynamic memory
-    // since we are adding a profile, 254 + 1 = 255 and this is the limit
-    if (nProfiles > 254) return NULL;
-    
-    // The output space
-    hLab = cmsCreateLab4ProfileTHR(ContextID, NULL);
-    if (hLab == NULL) return NULL;
-
-    // Create a copy of parameters
-    for (i=0; i < nProfiles; i++) {
-
-        ProfileList[i]    = hProfiles[i];
-        BPCList[i]        = BPC[i];
-        AdaptationList[i] = AdaptationStates[i];
-        IntentList[i]     = Intents[i];
-    }
-
-    // Place Lab identity at chain's end.
-    ProfileList[nProfiles]    = hLab;
-    BPCList[nProfiles]        = 0;
-    AdaptationList[nProfiles] = 1.0;
-    IntentList[nProfiles]     = INTENT_RELATIVE_COLORIMETRIC;
-   
-    // Create the transform
-    xform = cmsCreateExtendedTransform(ContextID, nProfiles + 1, ProfileList, 
-                                       BPCList, 
-                                       IntentList, 
-                                       AdaptationList, 
-                                       NULL, 0, 
-                                       InputFormat, 
-                                       OutputFormat, 
-                                       dwFlags);
-    
-    cmsCloseProfile(hLab);
-
-    return xform;
-}
-
-
-// Compute K -> L* relationship. Flags may include black point compensation. In this case, 
-// the relationship is assumed from the profile with BPC to a black point zero.
-static
-cmsToneCurve* ComputeKToLstar(cmsContext            ContextID,
-                               cmsUInt32Number       nPoints,
-                               cmsUInt32Number       nProfiles,
-                               const cmsUInt32Number Intents[], 
-                               const cmsHPROFILE     hProfiles[], 
-                               const cmsBool         BPC[],
-                               const cmsFloat64Number AdaptationStates[],
-                               cmsUInt32Number dwFlags)
-{
-    cmsToneCurve* out = NULL;   
-    cmsUInt32Number i;
-    cmsHTRANSFORM xform;
-    cmsCIELab Lab;
-    cmsFloat32Number cmyk[4];
-    cmsFloat32Number* SampledPoints;
-    
-    xform = _cmsChain2Lab(ContextID, nProfiles, TYPE_CMYK_FLT, TYPE_Lab_DBL, Intents, hProfiles, BPC, AdaptationStates, dwFlags);
-    if (xform == NULL) return NULL;
-        
-    SampledPoints = (cmsFloat32Number*) _cmsCalloc(ContextID, nPoints, sizeof(cmsFloat32Number));
-    if (SampledPoints  == NULL) goto Error;
-        
-    for (i=0; i < nPoints; i++) {
-
-        cmyk[0] = 0;
-        cmyk[1] = 0;
-        cmyk[2] = 0;
-        cmyk[3] = (cmsFloat32Number) ((i * 100.0) / (nPoints-1));
-
-        cmsDoTransform(xform, cmyk, &Lab, 1);
-        SampledPoints[i]= (cmsFloat32Number) (1.0 - Lab.L / 100.0); // Negate K for easier operation
-    }
-        
-    out = cmsBuildTabulatedToneCurveFloat(ContextID, nPoints, SampledPoints);
-
-Error:
-
-    cmsDeleteTransform(xform);  
-    if (SampledPoints) _cmsFree(ContextID, SampledPoints);
-
-    return out;
-}
-
-
-// Compute Black tone curve on a CMYK -> CMYK transform. This is done by
-// using the proof direction on both profiles to find K->L* relationship
-// then joining both curves. dwFlags may include black point compensation.
-cmsToneCurve* _cmsBuildKToneCurve(cmsContext        ContextID,
-                                   cmsUInt32Number   nPoints,
-                                   cmsUInt32Number   nProfiles,
-                                   const cmsUInt32Number Intents[], 
-                                   const cmsHPROFILE hProfiles[], 
-                                   const cmsBool     BPC[],
-                                   const cmsFloat64Number AdaptationStates[],
-                                   cmsUInt32Number   dwFlags)
-{
-    cmsToneCurve *in, *out, *KTone;       
-    // Make sure CMYK -> CMYK
-    if (cmsGetColorSpace(hProfiles[0]) != cmsSigCmykData ||
-        cmsGetColorSpace(hProfiles[nProfiles-1])!= cmsSigCmykData) return NULL;
-
-    
-    // Make sure last is an output profile
-    if (cmsGetDeviceClass(hProfiles[nProfiles - 1]) != cmsSigOutputClass) return NULL;
-
-    // Create individual curves. BPC works also as each K to L* is
-    // computed as a BPC to zero black point in case of L*
-    in  = ComputeKToLstar(ContextID, nPoints, nProfiles - 1, Intents, hProfiles, BPC, AdaptationStates, dwFlags);
-    if (in == NULL) return NULL;
-    
-    out = ComputeKToLstar(ContextID, nPoints, 1,             
-                            Intents + (nProfiles - 1), 
-                            hProfiles + (nProfiles - 1), 
-                            BPC + (nProfiles - 1),  
-                            AdaptationStates + (nProfiles - 1), 
-                            dwFlags);
-    if (out == NULL) {
-        cmsFreeToneCurve(in);
-        return NULL;
-    }
-
-    // Build the relationship. This effectively limits the maximum accuracy to 16 bits, but 
-    // since this is used on black-preserving LUTs, we are not loosing  accuracy in any case 
-    KTone = cmsJoinToneCurve(ContextID, in, out, nPoints);
-
-    // Get rid of components
-    cmsFreeToneCurve(in); cmsFreeToneCurve(out);
-
-    // Something went wrong...
-    if (KTone == NULL) return NULL;
-
-    // Make sure it is monotonic    
-    if (!cmsIsToneCurveMonotonic(KTone)) {
-        cmsFreeToneCurve(KTone);
-        return NULL;
-    }
-    
-    return KTone;
-}
-
-
-// Gamut LUT Creation -----------------------------------------------------------------------------------------
-
-// Used by gamut & softproofing
-
-typedef struct {
-
-    cmsHTRANSFORM hInput;               // From whatever input color space. 16 bits to DBL
-    cmsHTRANSFORM hForward, hReverse;   // Transforms going from Lab to colorant and back
-    cmsFloat64Number Thereshold;        // The thereshold after which is considered out of gamut
-    
-    } GAMUTCHAIN;
-
-// This sampler does compute gamut boundaries by comparing original
-// values with a transform going back and forth. Values above ERR_THERESHOLD 
-// of maximum are considered out of gamut.
-
-#define ERR_THERESHOLD      5 
-
-
-static
-int GamutSampler(register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void* Cargo)
-{
-    GAMUTCHAIN*  t = (GAMUTCHAIN* ) Cargo;          
-    cmsCIELab LabIn1, LabOut1;  
-    cmsCIELab LabIn2, LabOut2;      
-    cmsUInt16Number Proof[cmsMAXCHANNELS], Proof2[cmsMAXCHANNELS];
-    cmsFloat64Number dE1, dE2, ErrorRatio;
-
-    // Assume in-gamut by default.
-    dE1 = 0.;
-    dE2 = 0;
-    ErrorRatio = 1.0;
-
-    // Convert input to Lab
-    if (t -> hInput != NULL) 
-        cmsDoTransform(t -> hInput, In, &LabIn1, 1);
-
-    // converts from PCS to colorant. This always
-    // does return in-gamut values, 
-    cmsDoTransform(t -> hForward, &LabIn1, Proof, 1);
-
-    // Now, do the inverse, from colorant to PCS.
-    cmsDoTransform(t -> hReverse, Proof, &LabOut1, 1);
-
-    memmove(&LabIn2, &LabOut1, sizeof(cmsCIELab));
-
-    // Try again, but this time taking Check as input
-    cmsDoTransform(t -> hForward, &LabOut1, Proof2,  1);
-    cmsDoTransform(t -> hReverse, Proof2, &LabOut2, 1);
-    
-    // Take difference of direct value
-    dE1 = cmsDeltaE(&LabIn1, &LabOut1);        
-
-    // Take difference of converted value
-    dE2 = cmsDeltaE(&LabIn2, &LabOut2);                 
-
-
-    // if dE1 is small and dE2 is small, value is likely to be in gamut
-    if (dE1 < t->Thereshold && dE2 < t->Thereshold) 
-        Out[0] = 0;
-    else {
-
-        // if dE1 is small and dE2 is big, undefined. Assume in gamut
-        if (dE1 < t->Thereshold && dE2 > t->Thereshold)
-            Out[0] = 0;
-        else
-            // dE1 is big and dE2 is small, clearly out of gamut
-            if (dE1 > t->Thereshold && dE2 < t->Thereshold)
-                Out[0] = (cmsUInt16Number) _cmsQuickFloor((dE1 - t->Thereshold) + .5);
-            else  {
-
-                // dE1 is big and dE2 is also big, could be due to perceptual mapping
-                // so take error ratio
-                if (dE2 == 0.0)
-                    ErrorRatio = dE1;
-                else
-                    ErrorRatio = dE1 / dE2;
-
-                if (ErrorRatio > t->Thereshold) 
-                    Out[0] = (cmsUInt16Number)  _cmsQuickFloor((ErrorRatio - t->Thereshold) + .5);
-                else
-                    Out[0] = 0;
-            }
-    }
-
-
-    return TRUE;
-}
-
-// Does compute a gamut LUT going back and forth across pcs -> relativ. colorimetric intent -> pcs
-// the dE obtained is then annotated on the LUT. Values truely out of gamut are clipped to dE = 0xFFFE
-// and values changed are supposed to be handled by any gamut remapping, so, are out of gamut as well.
-//
-// **WARNING: This algorithm does assume that gamut remapping algorithms does NOT move in-gamut colors,
-// of course, many perceptual and saturation intents does not work in such way, but relativ. ones should.
-
-cmsPipeline* _cmsCreateGamutCheckPipeline(cmsContext ContextID,
-                                                                                 cmsHPROFILE hProfiles[], 
-                                                                                 cmsBool  BPC[], 
-                                                                                 cmsUInt32Number Intents[], 
-                                                                                 cmsFloat64Number AdaptationStates[],
-                                                                                 cmsUInt32Number nGamutPCSposition, 
-                                                                                 cmsHPROFILE hGamut)
-{
-       cmsHPROFILE hLab;
-       cmsPipeline* Gamut;
-       cmsStage* CLUT;
-       cmsUInt32Number dwFormat;
-       GAMUTCHAIN Chain;
-       int nChannels, nGridpoints;
-       cmsColorSpaceSignature ColorSpace;
-       cmsUInt32Number i;    
-       cmsHPROFILE ProfileList[256];
-       cmsBool     BPCList[256];
-       cmsFloat64Number AdaptationList[256];
-       cmsUInt32Number IntentList[256];
-
-       memset(&Chain, 0, sizeof(GAMUTCHAIN)); 
-
-
-       if (nGamutPCSposition <= 0 || nGamutPCSposition > 255) {
-               cmsSignalError(ContextID, cmsERROR_RANGE, "Wrong position of PCS. 1..255 expected, %d found.", nGamutPCSposition);
-               return NULL;
-       }
-
-       hLab = cmsCreateLab4ProfileTHR(ContextID, NULL);
-       if (hLab == NULL) return NULL;
-
-
-       // The figure of merit. On matrix-shaper profiles, should be almost zero as
-       // the conversion is pretty exact. On LUT based profiles, different resolutions
-       // of input and output CLUT may result in differences. 
-
-       if (cmsIsMatrixShaper(hGamut)) {
-
-               Chain.Thereshold = 1.0;
-       }
-       else {
-               Chain.Thereshold = ERR_THERESHOLD;
-       }
-
-
-       // Create a copy of parameters
-       for (i=0; i < nGamutPCSposition; i++) {
-               ProfileList[i]    = hProfiles[i];
-               BPCList[i]        = BPC[i];
-               AdaptationList[i] = AdaptationStates[i];
-               IntentList[i]     = Intents[i];
-       }
-
-       // Fill Lab identity
-       ProfileList[nGamutPCSposition] = hLab;
-       BPCList[nGamutPCSposition] = 0;
-       AdaptationList[nGamutPCSposition] = 1.0;
-       Intents[nGamutPCSposition] = INTENT_RELATIVE_COLORIMETRIC;
-
-
-       ColorSpace  = cmsGetColorSpace(hGamut);  
-
-       nChannels   = cmsChannelsOf(ColorSpace);     
-       nGridpoints = _cmsReasonableGridpointsByColorspace(ColorSpace, cmsFLAGS_HIGHRESPRECALC);
-       dwFormat    = (CHANNELS_SH(nChannels)|BYTES_SH(2));
-
-       // 16 bits to Lab double
-       Chain.hInput = cmsCreateExtendedTransform(ContextID, 
-               nGamutPCSposition + 1, 
-               ProfileList, 
-               BPCList, 
-               Intents, 
-               AdaptationList, 
-               NULL, 0, 
-               dwFormat, TYPE_Lab_DBL, 
-               cmsFLAGS_NOCACHE);
-
-
-       // Does create the forward step. Lab double to device
-       dwFormat    = (CHANNELS_SH(nChannels)|BYTES_SH(2));
-       Chain.hForward = cmsCreateTransformTHR(ContextID,
-               hLab, TYPE_Lab_DBL, 
-               hGamut, dwFormat, 
-               INTENT_RELATIVE_COLORIMETRIC,
-               cmsFLAGS_NOCACHE);
-
-       // Does create the backwards step
-       Chain.hReverse = cmsCreateTransformTHR(ContextID, hGamut, dwFormat, 
-               hLab, TYPE_Lab_DBL,                                      
-               INTENT_RELATIVE_COLORIMETRIC,
-               cmsFLAGS_NOCACHE);
-
-
-       // All ok?
-       if (Chain.hForward && Chain.hReverse) {
-
-               // Go on, try to compute gamut LUT from PCS. This consist on a single channel containing 
-               // dE when doing a transform back and forth on the colorimetric intent. 
-
-               Gamut = cmsPipelineAlloc(ContextID, 3, 1);
-
-               if (Gamut != NULL) {
-
-                       CLUT = cmsStageAllocCLut16bit(ContextID, nGridpoints, nChannels, 1, NULL);
-                       cmsPipelineInsertStage(Gamut, cmsAT_BEGIN, CLUT);
-
-                       cmsStageSampleCLut16bit(CLUT, GamutSampler, (void*) &Chain, 0);
-               }
-       }
-       else 
-               Gamut = NULL;   // Didn't work...
-
-       // Free all needed stuff.
-       if (Chain.hInput)   cmsDeleteTransform(Chain.hInput);
-       if (Chain.hForward) cmsDeleteTransform(Chain.hForward);
-       if (Chain.hReverse) cmsDeleteTransform(Chain.hReverse);
-       if (hLab) cmsCloseProfile(hLab);
-
-       // And return computed hull
-       return Gamut;
-}
-
-// Total Area Coverage estimation ----------------------------------------------------------------
-
-typedef struct {
-    cmsUInt32Number  nOutputChans;
-    cmsHTRANSFORM    hRoundTrip;               
-    cmsFloat32Number MaxTAC;
-    cmsFloat32Number MaxInput[cmsMAXCHANNELS];
-
-} cmsTACestimator;
-
-
-// This callback just accounts the maximum ink dropped in the given node. It does not populate any
-// memory, as the destination table is NULL. Its only purpose it to know the global maximum.
-static
-int EstimateTAC(register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void * Cargo)
-{
-    cmsTACestimator* bp = (cmsTACestimator*) Cargo;
-    cmsFloat32Number RoundTrip[cmsMAXCHANNELS];
-    cmsUInt32Number i;
-    cmsFloat32Number Sum;
-
-    
-    // Evaluate the xform
-    cmsDoTransform(bp->hRoundTrip, In, RoundTrip, 1);
-    
-    // All all amounts of ink
-    for (Sum=0, i=0; i < bp ->nOutputChans; i++) 
-            Sum += RoundTrip[i];
-
-    // If above maximum, keep track of input values
-    if (Sum > bp ->MaxTAC) {
-
-            bp ->MaxTAC = Sum;
-
-            for (i=0; i < bp ->nOutputChans; i++) {
-                bp ->MaxInput[i] = In[i];
-            }
-    }
-    
-    return TRUE;
-
-    cmsUNUSED_PARAMETER(Out);
-}
-
-
-// Detect Total area coverage of the profile
-cmsFloat64Number CMSEXPORT cmsDetectTAC(cmsHPROFILE hProfile)
-{
-    cmsTACestimator bp;
-    cmsUInt32Number dwFormatter;
-    cmsUInt32Number GridPoints[MAX_INPUT_DIMENSIONS];        
-    cmsHPROFILE hLab;
-    cmsContext ContextID = cmsGetProfileContextID(hProfile);
-
-    // TAC only works on output profiles
-    if (cmsGetDeviceClass(hProfile) != cmsSigOutputClass) {        
-        return 0;       
-    }
-
-    // Create a fake formatter for result
-    dwFormatter = cmsFormatterForColorspaceOfProfile(hProfile, 4, TRUE);
-
-    bp.nOutputChans = T_CHANNELS(dwFormatter);
-    bp.MaxTAC = 0;    // Initial TAC is 0
-
-    //  for safety
-    if (bp.nOutputChans >= cmsMAXCHANNELS) return 0;
-
-    hLab = cmsCreateLab4ProfileTHR(ContextID, NULL);
-    if (hLab == NULL) return 0;
-    // Setup a roundtrip on perceptual intent in output profile for TAC estimation
-    bp.hRoundTrip = cmsCreateTransformTHR(ContextID, hLab, TYPE_Lab_16, 
-                                          hProfile, dwFormatter, INTENT_PERCEPTUAL, cmsFLAGS_NOOPTIMIZE|cmsFLAGS_NOCACHE);
-
-    cmsCloseProfile(hLab);  
-    if (bp.hRoundTrip == NULL) return 0;
-
-    // For L* we only need black and white. For C* we need many points
-    GridPoints[0] = 6;
-    GridPoints[1] = 74;
-    GridPoints[2] = 74; 
-
-    
-       if (!cmsSliceSpace16(3, GridPoints, EstimateTAC, &bp)) {
-               bp.MaxTAC = 0;
-       }
-
-    cmsDeleteTransform(bp.hRoundTrip);
-
-    // Results in %
-    return bp.MaxTAC;
-}
-
-
-// Carefully,  clamp on CIELab space.
-
-cmsBool CMSEXPORT cmsDesaturateLab(cmsCIELab* Lab, 
-                                   double amax, double amin,
-                                   double bmax, double bmin)
-{
-
-    // Whole Luma surface to zero
-
-    if (Lab -> L < 0) {
-
-        Lab-> L = Lab->a = Lab-> b = 0.0;
-        return FALSE;
-    }
-
-    // Clamp white, DISCARD HIGHLIGHTS. This is done
-    // in such way because icc spec doesn't allow the
-    // use of L>100 as a highlight means.
-
-    if (Lab->L > 100)
-        Lab -> L = 100;
-
-    // Check out gamut prism, on a, b faces
-
-    if (Lab -> a < amin || Lab->a > amax||
-        Lab -> b < bmin || Lab->b > bmax) {
-
-            cmsCIELCh LCh;
-            double h, slope;
-
-            // Falls outside a, b limits. Transports to LCh space,
-            // and then do the clipping
-
-
-            if (Lab -> a == 0.0) { // Is hue exactly 90?
-
-                // atan will not work, so clamp here
-                Lab -> b = Lab->b < 0 ? bmin : bmax;
-                return TRUE;
-            }
-
-            cmsLab2LCh(&LCh, Lab);
-
-            slope = Lab -> b / Lab -> a;
-            h = LCh.h;
-
-            // There are 4 zones
-
-            if ((h >= 0. && h < 45.) ||
-                (h >= 315 && h <= 360.)) {
-
-                    // clip by amax
-                    Lab -> a = amax;
-                    Lab -> b = amax * slope;
-            }
-            else
-                if (h >= 45. && h < 135.)
-                {
-                    // clip by bmax
-                    Lab -> b = bmax;
-                    Lab -> a = bmax / slope;
-                }
-                else
-                    if (h >= 135. && h < 225.) {
-                        // clip by amin
-                        Lab -> a = amin;
-                        Lab -> b = amin * slope;
-
-                    }
-                    else
-                        if (h >= 225. && h < 315.) {
-                            // clip by bmin
-                            Lab -> b = bmin;
-                            Lab -> a = bmin / slope;
-                        }
-                        else  {
-                            cmsSignalError(0, cmsERROR_RANGE, "Invalid angle");
-                            return FALSE;
-                        }
-
-    }
-
-    return TRUE;
-}
+//---------------------------------------------------------------------------------\r
+//\r
+//  Little Color Management System\r
+//  Copyright (c) 1998-2012 Marti Maria Saguer\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining\r
+// a copy of this software and associated documentation files (the "Software"),\r
+// to deal in the Software without restriction, including without limitation\r
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+// and/or sell copies of the Software, and to permit persons to whom the Software\r
+// is furnished to do so, subject to the following conditions:\r
+//\r
+// The above copyright notice and this permission notice shall be included in\r
+// all copies or substantial portions of the Software.\r
+//\r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO\r
+// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+//---------------------------------------------------------------------------------\r
+//\r
+\r
+#include "lcms2_internal.h"\r
+\r
+\r
+// Auxiliar: append a Lab identity after the given sequence of profiles\r
+// and return the transform. Lab profile is closed, rest of profiles are kept open.\r
+cmsHTRANSFORM _cmsChain2Lab(cmsContext            ContextID,\r
+                            cmsUInt32Number        nProfiles,\r
+                            cmsUInt32Number        InputFormat,\r
+                            cmsUInt32Number        OutputFormat,\r
+                            const cmsUInt32Number  Intents[],\r
+                            const cmsHPROFILE      hProfiles[],\r
+                            const cmsBool          BPC[],\r
+                            const cmsFloat64Number AdaptationStates[],\r
+                            cmsUInt32Number        dwFlags)\r
+{\r
+    cmsHTRANSFORM xform;\r
+    cmsHPROFILE   hLab;\r
+    cmsHPROFILE   ProfileList[256];\r
+    cmsBool       BPCList[256];\r
+    cmsFloat64Number AdaptationList[256];\r
+    cmsUInt32Number IntentList[256];\r
+    cmsUInt32Number i;\r
+\r
+    // This is a rather big number and there is no need of dynamic memory\r
+    // since we are adding a profile, 254 + 1 = 255 and this is the limit\r
+    if (nProfiles > 254) return NULL;\r
+\r
+    // The output space\r
+    hLab = cmsCreateLab4ProfileTHR(ContextID, NULL);\r
+    if (hLab == NULL) return NULL;\r
+\r
+    // Create a copy of parameters\r
+    for (i=0; i < nProfiles; i++) {\r
+\r
+        ProfileList[i]    = hProfiles[i];\r
+        BPCList[i]        = BPC[i];\r
+        AdaptationList[i] = AdaptationStates[i];\r
+        IntentList[i]     = Intents[i];\r
+    }\r
+\r
+    // Place Lab identity at chain's end.\r
+    ProfileList[nProfiles]    = hLab;\r
+    BPCList[nProfiles]        = 0;\r
+    AdaptationList[nProfiles] = 1.0;\r
+    IntentList[nProfiles]     = INTENT_RELATIVE_COLORIMETRIC;\r
+\r
+    // Create the transform\r
+    xform = cmsCreateExtendedTransform(ContextID, nProfiles + 1, ProfileList,\r
+                                       BPCList,\r
+                                       IntentList,\r
+                                       AdaptationList,\r
+                                       NULL, 0,\r
+                                       InputFormat,\r
+                                       OutputFormat,\r
+                                       dwFlags);\r
+\r
+    cmsCloseProfile(hLab);\r
+\r
+    return xform;\r
+}\r
+\r
+\r
+// Compute K -> L* relationship. Flags may include black point compensation. In this case,\r
+// the relationship is assumed from the profile with BPC to a black point zero.\r
+static\r
+cmsToneCurve* ComputeKToLstar(cmsContext            ContextID,\r
+                               cmsUInt32Number       nPoints,\r
+                               cmsUInt32Number       nProfiles,\r
+                               const cmsUInt32Number Intents[],\r
+                               const cmsHPROFILE     hProfiles[],\r
+                               const cmsBool         BPC[],\r
+                               const cmsFloat64Number AdaptationStates[],\r
+                               cmsUInt32Number dwFlags)\r
+{\r
+    cmsToneCurve* out = NULL;\r
+    cmsUInt32Number i;\r
+    cmsHTRANSFORM xform;\r
+    cmsCIELab Lab;\r
+    cmsFloat32Number cmyk[4];\r
+    cmsFloat32Number* SampledPoints;\r
+\r
+    xform = _cmsChain2Lab(ContextID, nProfiles, TYPE_CMYK_FLT, TYPE_Lab_DBL, Intents, hProfiles, BPC, AdaptationStates, dwFlags);\r
+    if (xform == NULL) return NULL;\r
+\r
+    SampledPoints = (cmsFloat32Number*) _cmsCalloc(ContextID, nPoints, sizeof(cmsFloat32Number));\r
+    if (SampledPoints  == NULL) goto Error;\r
+\r
+    for (i=0; i < nPoints; i++) {\r
+\r
+        cmyk[0] = 0;\r
+        cmyk[1] = 0;\r
+        cmyk[2] = 0;\r
+        cmyk[3] = (cmsFloat32Number) ((i * 100.0) / (nPoints-1));\r
+\r
+        cmsDoTransform(xform, cmyk, &Lab, 1);\r
+        SampledPoints[i]= (cmsFloat32Number) (1.0 - Lab.L / 100.0); // Negate K for easier operation\r
+    }\r
+\r
+    out = cmsBuildTabulatedToneCurveFloat(ContextID, nPoints, SampledPoints);\r
+\r
+Error:\r
+\r
+    cmsDeleteTransform(xform);\r
+    if (SampledPoints) _cmsFree(ContextID, SampledPoints);\r
+\r
+    return out;\r
+}\r
+\r
+\r
+// Compute Black tone curve on a CMYK -> CMYK transform. This is done by\r
+// using the proof direction on both profiles to find K->L* relationship\r
+// then joining both curves. dwFlags may include black point compensation.\r
+cmsToneCurve* _cmsBuildKToneCurve(cmsContext        ContextID,\r
+                                   cmsUInt32Number   nPoints,\r
+                                   cmsUInt32Number   nProfiles,\r
+                                   const cmsUInt32Number Intents[],\r
+                                   const cmsHPROFILE hProfiles[],\r
+                                   const cmsBool     BPC[],\r
+                                   const cmsFloat64Number AdaptationStates[],\r
+                                   cmsUInt32Number   dwFlags)\r
+{\r
+    cmsToneCurve *in, *out, *KTone;\r
+\r
+    // Make sure CMYK -> CMYK\r
+    if (cmsGetColorSpace(hProfiles[0]) != cmsSigCmykData ||\r
+        cmsGetColorSpace(hProfiles[nProfiles-1])!= cmsSigCmykData) return NULL;\r
+\r
+\r
+    // Make sure last is an output profile\r
+    if (cmsGetDeviceClass(hProfiles[nProfiles - 1]) != cmsSigOutputClass) return NULL;\r
+\r
+    // Create individual curves. BPC works also as each K to L* is\r
+    // computed as a BPC to zero black point in case of L*\r
+    in  = ComputeKToLstar(ContextID, nPoints, nProfiles - 1, Intents, hProfiles, BPC, AdaptationStates, dwFlags);\r
+    if (in == NULL) return NULL;\r
+\r
+    out = ComputeKToLstar(ContextID, nPoints, 1,\r
+                            Intents + (nProfiles - 1),\r
+                            hProfiles + (nProfiles - 1),\r
+                            BPC + (nProfiles - 1),\r
+                            AdaptationStates + (nProfiles - 1),\r
+                            dwFlags);\r
+    if (out == NULL) {\r
+        cmsFreeToneCurve(in);\r
+        return NULL;\r
+    }\r
+\r
+    // Build the relationship. This effectively limits the maximum accuracy to 16 bits, but\r
+    // since this is used on black-preserving LUTs, we are not loosing  accuracy in any case\r
+    KTone = cmsJoinToneCurve(ContextID, in, out, nPoints);\r
+\r
+    // Get rid of components\r
+    cmsFreeToneCurve(in); cmsFreeToneCurve(out);\r
+\r
+    // Something went wrong...\r
+    if (KTone == NULL) return NULL;\r
+\r
+    // Make sure it is monotonic\r
+    if (!cmsIsToneCurveMonotonic(KTone)) {\r
+        cmsFreeToneCurve(KTone);\r
+        return NULL;\r
+    }\r
+\r
+    return KTone;\r
+}\r
+\r
+\r
+// Gamut LUT Creation -----------------------------------------------------------------------------------------\r
+\r
+// Used by gamut & softproofing\r
+\r
+typedef struct {\r
+\r
+    cmsHTRANSFORM hInput;               // From whatever input color space. 16 bits to DBL\r
+    cmsHTRANSFORM hForward, hReverse;   // Transforms going from Lab to colorant and back\r
+    cmsFloat64Number Thereshold;        // The thereshold after which is considered out of gamut\r
+\r
+    } GAMUTCHAIN;\r
+\r
+// This sampler does compute gamut boundaries by comparing original\r
+// values with a transform going back and forth. Values above ERR_THERESHOLD\r
+// of maximum are considered out of gamut.\r
+\r
+#define ERR_THERESHOLD      5\r
+\r
+\r
+static\r
+int GamutSampler(register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void* Cargo)\r
+{\r
+    GAMUTCHAIN*  t = (GAMUTCHAIN* ) Cargo;\r
+    cmsCIELab LabIn1, LabOut1;\r
+    cmsCIELab LabIn2, LabOut2;\r
+    cmsUInt16Number Proof[cmsMAXCHANNELS], Proof2[cmsMAXCHANNELS];\r
+    cmsFloat64Number dE1, dE2, ErrorRatio;\r
+\r
+    // Assume in-gamut by default.\r
+    dE1 = 0.;\r
+    dE2 = 0;\r
+    ErrorRatio = 1.0;\r
+\r
+    // Convert input to Lab\r
+    if (t -> hInput != NULL)\r
+        cmsDoTransform(t -> hInput, In, &LabIn1, 1);\r
+\r
+    // converts from PCS to colorant. This always\r
+    // does return in-gamut values,\r
+    cmsDoTransform(t -> hForward, &LabIn1, Proof, 1);\r
+\r
+    // Now, do the inverse, from colorant to PCS.\r
+    cmsDoTransform(t -> hReverse, Proof, &LabOut1, 1);\r
+\r
+    memmove(&LabIn2, &LabOut1, sizeof(cmsCIELab));\r
+\r
+    // Try again, but this time taking Check as input\r
+    cmsDoTransform(t -> hForward, &LabOut1, Proof2,  1);\r
+    cmsDoTransform(t -> hReverse, Proof2, &LabOut2, 1);\r
+\r
+    // Take difference of direct value\r
+    dE1 = cmsDeltaE(&LabIn1, &LabOut1);\r
+\r
+    // Take difference of converted value\r
+    dE2 = cmsDeltaE(&LabIn2, &LabOut2);\r
+\r
+\r
+    // if dE1 is small and dE2 is small, value is likely to be in gamut\r
+    if (dE1 < t->Thereshold && dE2 < t->Thereshold)\r
+        Out[0] = 0;\r
+    else {\r
+\r
+        // if dE1 is small and dE2 is big, undefined. Assume in gamut\r
+        if (dE1 < t->Thereshold && dE2 > t->Thereshold)\r
+            Out[0] = 0;\r
+        else\r
+            // dE1 is big and dE2 is small, clearly out of gamut\r
+            if (dE1 > t->Thereshold && dE2 < t->Thereshold)\r
+                Out[0] = (cmsUInt16Number) _cmsQuickFloor((dE1 - t->Thereshold) + .5);\r
+            else  {\r
+\r
+                // dE1 is big and dE2 is also big, could be due to perceptual mapping\r
+                // so take error ratio\r
+                if (dE2 == 0.0)\r
+                    ErrorRatio = dE1;\r
+                else\r
+                    ErrorRatio = dE1 / dE2;\r
+\r
+                if (ErrorRatio > t->Thereshold)\r
+                    Out[0] = (cmsUInt16Number)  _cmsQuickFloor((ErrorRatio - t->Thereshold) + .5);\r
+                else\r
+                    Out[0] = 0;\r
+            }\r
+    }\r
+\r
+\r
+    return TRUE;\r
+}\r
+\r
+// Does compute a gamut LUT going back and forth across pcs -> relativ. colorimetric intent -> pcs\r
+// the dE obtained is then annotated on the LUT. Values truely out of gamut are clipped to dE = 0xFFFE\r
+// and values changed are supposed to be handled by any gamut remapping, so, are out of gamut as well.\r
+//\r
+// **WARNING: This algorithm does assume that gamut remapping algorithms does NOT move in-gamut colors,\r
+// of course, many perceptual and saturation intents does not work in such way, but relativ. ones should.\r
+\r
+cmsPipeline* _cmsCreateGamutCheckPipeline(cmsContext ContextID,\r
+                                                                                 cmsHPROFILE hProfiles[],\r
+                                                                                 cmsBool  BPC[],\r
+                                                                                 cmsUInt32Number Intents[],\r
+                                                                                 cmsFloat64Number AdaptationStates[],\r
+                                                                                 cmsUInt32Number nGamutPCSposition,\r
+                                                                                 cmsHPROFILE hGamut)\r
+{\r
+       cmsHPROFILE hLab;\r
+       cmsPipeline* Gamut;\r
+       cmsStage* CLUT;\r
+       cmsUInt32Number dwFormat;\r
+       GAMUTCHAIN Chain;\r
+       int nChannels, nGridpoints;\r
+       cmsColorSpaceSignature ColorSpace;\r
+       cmsUInt32Number i;\r
+       cmsHPROFILE ProfileList[256];\r
+       cmsBool     BPCList[256];\r
+       cmsFloat64Number AdaptationList[256];\r
+       cmsUInt32Number IntentList[256];\r
+\r
+       memset(&Chain, 0, sizeof(GAMUTCHAIN));\r
+\r
+\r
+       if (nGamutPCSposition <= 0 || nGamutPCSposition > 255) {\r
+               cmsSignalError(ContextID, cmsERROR_RANGE, "Wrong position of PCS. 1..255 expected, %d found.", nGamutPCSposition);\r
+               return NULL;\r
+       }\r
+\r
+       hLab = cmsCreateLab4ProfileTHR(ContextID, NULL);\r
+       if (hLab == NULL) return NULL;\r
+\r
+\r
+       // The figure of merit. On matrix-shaper profiles, should be almost zero as\r
+       // the conversion is pretty exact. On LUT based profiles, different resolutions\r
+       // of input and output CLUT may result in differences.\r
+\r
+       if (cmsIsMatrixShaper(hGamut)) {\r
+\r
+               Chain.Thereshold = 1.0;\r
+       }\r
+       else {\r
+               Chain.Thereshold = ERR_THERESHOLD;\r
+       }\r
+\r
+\r
+       // Create a copy of parameters\r
+       for (i=0; i < nGamutPCSposition; i++) {\r
+               ProfileList[i]    = hProfiles[i];\r
+               BPCList[i]        = BPC[i];\r
+               AdaptationList[i] = AdaptationStates[i];\r
+               IntentList[i]     = Intents[i];\r
+       }\r
+\r
+       // Fill Lab identity\r
+       ProfileList[nGamutPCSposition] = hLab;\r
+       BPCList[nGamutPCSposition] = 0;\r
+       AdaptationList[nGamutPCSposition] = 1.0;\r
+       Intents[nGamutPCSposition] = INTENT_RELATIVE_COLORIMETRIC;\r
+\r
+\r
+       ColorSpace  = cmsGetColorSpace(hGamut);\r
+\r
+       nChannels   = cmsChannelsOf(ColorSpace);\r
+       nGridpoints = _cmsReasonableGridpointsByColorspace(ColorSpace, cmsFLAGS_HIGHRESPRECALC);\r
+       dwFormat    = (CHANNELS_SH(nChannels)|BYTES_SH(2));\r
+\r
+       // 16 bits to Lab double\r
+       Chain.hInput = cmsCreateExtendedTransform(ContextID,\r
+               nGamutPCSposition + 1,\r
+               ProfileList,\r
+               BPCList,\r
+               Intents,\r
+               AdaptationList,\r
+               NULL, 0,\r
+               dwFormat, TYPE_Lab_DBL,\r
+               cmsFLAGS_NOCACHE);\r
+\r
+\r
+       // Does create the forward step. Lab double to device\r
+       dwFormat    = (CHANNELS_SH(nChannels)|BYTES_SH(2));\r
+       Chain.hForward = cmsCreateTransformTHR(ContextID,\r
+               hLab, TYPE_Lab_DBL,\r
+               hGamut, dwFormat,\r
+               INTENT_RELATIVE_COLORIMETRIC,\r
+               cmsFLAGS_NOCACHE);\r
+\r
+       // Does create the backwards step\r
+       Chain.hReverse = cmsCreateTransformTHR(ContextID, hGamut, dwFormat,\r
+               hLab, TYPE_Lab_DBL,\r
+               INTENT_RELATIVE_COLORIMETRIC,\r
+               cmsFLAGS_NOCACHE);\r
+\r
+\r
+       // All ok?\r
+       if (Chain.hForward && Chain.hReverse) {\r
+\r
+               // Go on, try to compute gamut LUT from PCS. This consist on a single channel containing\r
+               // dE when doing a transform back and forth on the colorimetric intent.\r
+\r
+               Gamut = cmsPipelineAlloc(ContextID, 3, 1);\r
+\r
+               if (Gamut != NULL) {\r
+\r
+                       CLUT = cmsStageAllocCLut16bit(ContextID, nGridpoints, nChannels, 1, NULL);\r
+                       cmsPipelineInsertStage(Gamut, cmsAT_BEGIN, CLUT);\r
+\r
+                       cmsStageSampleCLut16bit(CLUT, GamutSampler, (void*) &Chain, 0);\r
+               }\r
+       }\r
+       else\r
+               Gamut = NULL;   // Didn't work...\r
+\r
+       // Free all needed stuff.\r
+       if (Chain.hInput)   cmsDeleteTransform(Chain.hInput);\r
+       if (Chain.hForward) cmsDeleteTransform(Chain.hForward);\r
+       if (Chain.hReverse) cmsDeleteTransform(Chain.hReverse);\r
+       if (hLab) cmsCloseProfile(hLab);\r
+\r
+       // And return computed hull\r
+       return Gamut;\r
+}\r
+\r
+// Total Area Coverage estimation ----------------------------------------------------------------\r
+\r
+typedef struct {\r
+    cmsUInt32Number  nOutputChans;\r
+    cmsHTRANSFORM    hRoundTrip;\r
+    cmsFloat32Number MaxTAC;\r
+    cmsFloat32Number MaxInput[cmsMAXCHANNELS];\r
+\r
+} cmsTACestimator;\r
+\r
+\r
+// This callback just accounts the maximum ink dropped in the given node. It does not populate any\r
+// memory, as the destination table is NULL. Its only purpose it to know the global maximum.\r
+static\r
+int EstimateTAC(register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void * Cargo)\r
+{\r
+    cmsTACestimator* bp = (cmsTACestimator*) Cargo;\r
+    cmsFloat32Number RoundTrip[cmsMAXCHANNELS];\r
+    cmsUInt32Number i;\r
+    cmsFloat32Number Sum;\r
+\r
+\r
+    // Evaluate the xform\r
+    cmsDoTransform(bp->hRoundTrip, In, RoundTrip, 1);\r
+\r
+    // All all amounts of ink\r
+    for (Sum=0, i=0; i < bp ->nOutputChans; i++)\r
+            Sum += RoundTrip[i];\r
+\r
+    // If above maximum, keep track of input values\r
+    if (Sum > bp ->MaxTAC) {\r
+\r
+            bp ->MaxTAC = Sum;\r
+\r
+            for (i=0; i < bp ->nOutputChans; i++) {\r
+                bp ->MaxInput[i] = In[i];\r
+            }\r
+    }\r
+\r
+    return TRUE;\r
+\r
+    cmsUNUSED_PARAMETER(Out);\r
+}\r
+\r
+\r
+// Detect Total area coverage of the profile\r
+cmsFloat64Number CMSEXPORT cmsDetectTAC(cmsHPROFILE hProfile)\r
+{\r
+    cmsTACestimator bp;\r
+    cmsUInt32Number dwFormatter;\r
+    cmsUInt32Number GridPoints[MAX_INPUT_DIMENSIONS];\r
+    cmsHPROFILE hLab;\r
+    cmsContext ContextID = cmsGetProfileContextID(hProfile);\r
+\r
+    // TAC only works on output profiles\r
+    if (cmsGetDeviceClass(hProfile) != cmsSigOutputClass) {\r
+        return 0;\r
+    }\r
+\r
+    // Create a fake formatter for result\r
+    dwFormatter = cmsFormatterForColorspaceOfProfile(hProfile, 4, TRUE);\r
+\r
+    bp.nOutputChans = T_CHANNELS(dwFormatter);\r
+    bp.MaxTAC = 0;    // Initial TAC is 0\r
+\r
+    //  for safety\r
+    if (bp.nOutputChans >= cmsMAXCHANNELS) return 0;\r
+\r
+    hLab = cmsCreateLab4ProfileTHR(ContextID, NULL);\r
+    if (hLab == NULL) return 0;\r
+    // Setup a roundtrip on perceptual intent in output profile for TAC estimation\r
+    bp.hRoundTrip = cmsCreateTransformTHR(ContextID, hLab, TYPE_Lab_16,\r
+                                          hProfile, dwFormatter, INTENT_PERCEPTUAL, cmsFLAGS_NOOPTIMIZE|cmsFLAGS_NOCACHE);\r
+\r
+    cmsCloseProfile(hLab);\r
+    if (bp.hRoundTrip == NULL) return 0;\r
+\r
+    // For L* we only need black and white. For C* we need many points\r
+    GridPoints[0] = 6;\r
+    GridPoints[1] = 74;\r
+    GridPoints[2] = 74;\r
+\r
+\r
+       if (!cmsSliceSpace16(3, GridPoints, EstimateTAC, &bp)) {\r
+               bp.MaxTAC = 0;\r
+       }\r
+\r
+    cmsDeleteTransform(bp.hRoundTrip);\r
+\r
+    // Results in %\r
+    return bp.MaxTAC;\r
+}\r
+\r
+\r
+// Carefully,  clamp on CIELab space.\r
+\r
+cmsBool CMSEXPORT cmsDesaturateLab(cmsCIELab* Lab,\r
+                                   double amax, double amin,\r
+                                   double bmax, double bmin)\r
+{\r
+\r
+    // Whole Luma surface to zero\r
+\r
+    if (Lab -> L < 0) {\r
+\r
+        Lab-> L = Lab->a = Lab-> b = 0.0;\r
+        return FALSE;\r
+    }\r
+\r
+    // Clamp white, DISCARD HIGHLIGHTS. This is done\r
+    // in such way because icc spec doesn't allow the\r
+    // use of L>100 as a highlight means.\r
+\r
+    if (Lab->L > 100)\r
+        Lab -> L = 100;\r
+\r
+    // Check out gamut prism, on a, b faces\r
+\r
+    if (Lab -> a < amin || Lab->a > amax||\r
+        Lab -> b < bmin || Lab->b > bmax) {\r
+\r
+            cmsCIELCh LCh;\r
+            double h, slope;\r
+\r
+            // Falls outside a, b limits. Transports to LCh space,\r
+            // and then do the clipping\r
+\r
+\r
+            if (Lab -> a == 0.0) { // Is hue exactly 90?\r
+\r
+                // atan will not work, so clamp here\r
+                Lab -> b = Lab->b < 0 ? bmin : bmax;\r
+                return TRUE;\r
+            }\r
+\r
+            cmsLab2LCh(&LCh, Lab);\r
+\r
+            slope = Lab -> b / Lab -> a;\r
+            h = LCh.h;\r
+\r
+            // There are 4 zones\r
+\r
+            if ((h >= 0. && h < 45.) ||\r
+                (h >= 315 && h <= 360.)) {\r
+\r
+                    // clip by amax\r
+                    Lab -> a = amax;\r
+                    Lab -> b = amax * slope;\r
+            }\r
+            else\r
+                if (h >= 45. && h < 135.)\r
+                {\r
+                    // clip by bmax\r
+                    Lab -> b = bmax;\r
+                    Lab -> a = bmax / slope;\r
+                }\r
+                else\r
+                    if (h >= 135. && h < 225.) {\r
+                        // clip by amin\r
+                        Lab -> a = amin;\r
+                        Lab -> b = amin * slope;\r
+\r
+                    }\r
+                    else\r
+                        if (h >= 225. && h < 315.) {\r
+                            // clip by bmin\r
+                            Lab -> b = bmin;\r
+                            Lab -> a = bmin / slope;\r
+                        }\r
+                        else  {\r
+                            cmsSignalError(0, cmsERROR_RANGE, "Invalid angle");\r
+                            return FALSE;\r
+                        }\r
+\r
+    }\r
+\r
+    return TRUE;\r
+}\r
diff --git a/src/cmshalf.c b/src/cmshalf.c
new file mode 100755 (executable)
index 0000000..204dee9
--- /dev/null
@@ -0,0 +1,535 @@
+//---------------------------------------------------------------------------------
+//
+//  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"
+
+#ifndef CMS_NO_HALF_SUPPORT 
+
+// This code is inspired in the paper "Fast Half Float Conversions"
+// by Jeroen van der Zijp
+
+static cmsUInt32Number Mantissa[2048] = {
+
+0x00000000, 0x33800000, 0x34000000, 0x34400000, 0x34800000, 0x34a00000,
+0x34c00000, 0x34e00000, 0x35000000, 0x35100000, 0x35200000, 0x35300000,
+0x35400000, 0x35500000, 0x35600000, 0x35700000, 0x35800000, 0x35880000,
+0x35900000, 0x35980000, 0x35a00000, 0x35a80000, 0x35b00000, 0x35b80000,
+0x35c00000, 0x35c80000, 0x35d00000, 0x35d80000, 0x35e00000, 0x35e80000,
+0x35f00000, 0x35f80000, 0x36000000, 0x36040000, 0x36080000, 0x360c0000,
+0x36100000, 0x36140000, 0x36180000, 0x361c0000, 0x36200000, 0x36240000,
+0x36280000, 0x362c0000, 0x36300000, 0x36340000, 0x36380000, 0x363c0000,
+0x36400000, 0x36440000, 0x36480000, 0x364c0000, 0x36500000, 0x36540000,
+0x36580000, 0x365c0000, 0x36600000, 0x36640000, 0x36680000, 0x366c0000,
+0x36700000, 0x36740000, 0x36780000, 0x367c0000, 0x36800000, 0x36820000,
+0x36840000, 0x36860000, 0x36880000, 0x368a0000, 0x368c0000, 0x368e0000,
+0x36900000, 0x36920000, 0x36940000, 0x36960000, 0x36980000, 0x369a0000,
+0x369c0000, 0x369e0000, 0x36a00000, 0x36a20000, 0x36a40000, 0x36a60000,
+0x36a80000, 0x36aa0000, 0x36ac0000, 0x36ae0000, 0x36b00000, 0x36b20000,
+0x36b40000, 0x36b60000, 0x36b80000, 0x36ba0000, 0x36bc0000, 0x36be0000,
+0x36c00000, 0x36c20000, 0x36c40000, 0x36c60000, 0x36c80000, 0x36ca0000,
+0x36cc0000, 0x36ce0000, 0x36d00000, 0x36d20000, 0x36d40000, 0x36d60000,
+0x36d80000, 0x36da0000, 0x36dc0000, 0x36de0000, 0x36e00000, 0x36e20000,
+0x36e40000, 0x36e60000, 0x36e80000, 0x36ea0000, 0x36ec0000, 0x36ee0000,
+0x36f00000, 0x36f20000, 0x36f40000, 0x36f60000, 0x36f80000, 0x36fa0000,
+0x36fc0000, 0x36fe0000, 0x37000000, 0x37010000, 0x37020000, 0x37030000,
+0x37040000, 0x37050000, 0x37060000, 0x37070000, 0x37080000, 0x37090000,
+0x370a0000, 0x370b0000, 0x370c0000, 0x370d0000, 0x370e0000, 0x370f0000,
+0x37100000, 0x37110000, 0x37120000, 0x37130000, 0x37140000, 0x37150000,
+0x37160000, 0x37170000, 0x37180000, 0x37190000, 0x371a0000, 0x371b0000,
+0x371c0000, 0x371d0000, 0x371e0000, 0x371f0000, 0x37200000, 0x37210000,
+0x37220000, 0x37230000, 0x37240000, 0x37250000, 0x37260000, 0x37270000,
+0x37280000, 0x37290000, 0x372a0000, 0x372b0000, 0x372c0000, 0x372d0000,
+0x372e0000, 0x372f0000, 0x37300000, 0x37310000, 0x37320000, 0x37330000,
+0x37340000, 0x37350000, 0x37360000, 0x37370000, 0x37380000, 0x37390000,
+0x373a0000, 0x373b0000, 0x373c0000, 0x373d0000, 0x373e0000, 0x373f0000,
+0x37400000, 0x37410000, 0x37420000, 0x37430000, 0x37440000, 0x37450000,
+0x37460000, 0x37470000, 0x37480000, 0x37490000, 0x374a0000, 0x374b0000,
+0x374c0000, 0x374d0000, 0x374e0000, 0x374f0000, 0x37500000, 0x37510000,
+0x37520000, 0x37530000, 0x37540000, 0x37550000, 0x37560000, 0x37570000,
+0x37580000, 0x37590000, 0x375a0000, 0x375b0000, 0x375c0000, 0x375d0000,
+0x375e0000, 0x375f0000, 0x37600000, 0x37610000, 0x37620000, 0x37630000,
+0x37640000, 0x37650000, 0x37660000, 0x37670000, 0x37680000, 0x37690000,
+0x376a0000, 0x376b0000, 0x376c0000, 0x376d0000, 0x376e0000, 0x376f0000,
+0x37700000, 0x37710000, 0x37720000, 0x37730000, 0x37740000, 0x37750000,
+0x37760000, 0x37770000, 0x37780000, 0x37790000, 0x377a0000, 0x377b0000,
+0x377c0000, 0x377d0000, 0x377e0000, 0x377f0000, 0x37800000, 0x37808000,
+0x37810000, 0x37818000, 0x37820000, 0x37828000, 0x37830000, 0x37838000,
+0x37840000, 0x37848000, 0x37850000, 0x37858000, 0x37860000, 0x37868000,
+0x37870000, 0x37878000, 0x37880000, 0x37888000, 0x37890000, 0x37898000,
+0x378a0000, 0x378a8000, 0x378b0000, 0x378b8000, 0x378c0000, 0x378c8000,
+0x378d0000, 0x378d8000, 0x378e0000, 0x378e8000, 0x378f0000, 0x378f8000,
+0x37900000, 0x37908000, 0x37910000, 0x37918000, 0x37920000, 0x37928000,
+0x37930000, 0x37938000, 0x37940000, 0x37948000, 0x37950000, 0x37958000,
+0x37960000, 0x37968000, 0x37970000, 0x37978000, 0x37980000, 0x37988000,
+0x37990000, 0x37998000, 0x379a0000, 0x379a8000, 0x379b0000, 0x379b8000,
+0x379c0000, 0x379c8000, 0x379d0000, 0x379d8000, 0x379e0000, 0x379e8000,
+0x379f0000, 0x379f8000, 0x37a00000, 0x37a08000, 0x37a10000, 0x37a18000,
+0x37a20000, 0x37a28000, 0x37a30000, 0x37a38000, 0x37a40000, 0x37a48000,
+0x37a50000, 0x37a58000, 0x37a60000, 0x37a68000, 0x37a70000, 0x37a78000,
+0x37a80000, 0x37a88000, 0x37a90000, 0x37a98000, 0x37aa0000, 0x37aa8000,
+0x37ab0000, 0x37ab8000, 0x37ac0000, 0x37ac8000, 0x37ad0000, 0x37ad8000,
+0x37ae0000, 0x37ae8000, 0x37af0000, 0x37af8000, 0x37b00000, 0x37b08000,
+0x37b10000, 0x37b18000, 0x37b20000, 0x37b28000, 0x37b30000, 0x37b38000,
+0x37b40000, 0x37b48000, 0x37b50000, 0x37b58000, 0x37b60000, 0x37b68000,
+0x37b70000, 0x37b78000, 0x37b80000, 0x37b88000, 0x37b90000, 0x37b98000,
+0x37ba0000, 0x37ba8000, 0x37bb0000, 0x37bb8000, 0x37bc0000, 0x37bc8000,
+0x37bd0000, 0x37bd8000, 0x37be0000, 0x37be8000, 0x37bf0000, 0x37bf8000,
+0x37c00000, 0x37c08000, 0x37c10000, 0x37c18000, 0x37c20000, 0x37c28000,
+0x37c30000, 0x37c38000, 0x37c40000, 0x37c48000, 0x37c50000, 0x37c58000,
+0x37c60000, 0x37c68000, 0x37c70000, 0x37c78000, 0x37c80000, 0x37c88000,
+0x37c90000, 0x37c98000, 0x37ca0000, 0x37ca8000, 0x37cb0000, 0x37cb8000,
+0x37cc0000, 0x37cc8000, 0x37cd0000, 0x37cd8000, 0x37ce0000, 0x37ce8000,
+0x37cf0000, 0x37cf8000, 0x37d00000, 0x37d08000, 0x37d10000, 0x37d18000,
+0x37d20000, 0x37d28000, 0x37d30000, 0x37d38000, 0x37d40000, 0x37d48000,
+0x37d50000, 0x37d58000, 0x37d60000, 0x37d68000, 0x37d70000, 0x37d78000,
+0x37d80000, 0x37d88000, 0x37d90000, 0x37d98000, 0x37da0000, 0x37da8000,
+0x37db0000, 0x37db8000, 0x37dc0000, 0x37dc8000, 0x37dd0000, 0x37dd8000,
+0x37de0000, 0x37de8000, 0x37df0000, 0x37df8000, 0x37e00000, 0x37e08000,
+0x37e10000, 0x37e18000, 0x37e20000, 0x37e28000, 0x37e30000, 0x37e38000,
+0x37e40000, 0x37e48000, 0x37e50000, 0x37e58000, 0x37e60000, 0x37e68000,
+0x37e70000, 0x37e78000, 0x37e80000, 0x37e88000, 0x37e90000, 0x37e98000,
+0x37ea0000, 0x37ea8000, 0x37eb0000, 0x37eb8000, 0x37ec0000, 0x37ec8000,
+0x37ed0000, 0x37ed8000, 0x37ee0000, 0x37ee8000, 0x37ef0000, 0x37ef8000,
+0x37f00000, 0x37f08000, 0x37f10000, 0x37f18000, 0x37f20000, 0x37f28000,
+0x37f30000, 0x37f38000, 0x37f40000, 0x37f48000, 0x37f50000, 0x37f58000,
+0x37f60000, 0x37f68000, 0x37f70000, 0x37f78000, 0x37f80000, 0x37f88000,
+0x37f90000, 0x37f98000, 0x37fa0000, 0x37fa8000, 0x37fb0000, 0x37fb8000,
+0x37fc0000, 0x37fc8000, 0x37fd0000, 0x37fd8000, 0x37fe0000, 0x37fe8000,
+0x37ff0000, 0x37ff8000, 0x38000000, 0x38004000, 0x38008000, 0x3800c000,
+0x38010000, 0x38014000, 0x38018000, 0x3801c000, 0x38020000, 0x38024000,
+0x38028000, 0x3802c000, 0x38030000, 0x38034000, 0x38038000, 0x3803c000,
+0x38040000, 0x38044000, 0x38048000, 0x3804c000, 0x38050000, 0x38054000,
+0x38058000, 0x3805c000, 0x38060000, 0x38064000, 0x38068000, 0x3806c000,
+0x38070000, 0x38074000, 0x38078000, 0x3807c000, 0x38080000, 0x38084000,
+0x38088000, 0x3808c000, 0x38090000, 0x38094000, 0x38098000, 0x3809c000,
+0x380a0000, 0x380a4000, 0x380a8000, 0x380ac000, 0x380b0000, 0x380b4000,
+0x380b8000, 0x380bc000, 0x380c0000, 0x380c4000, 0x380c8000, 0x380cc000,
+0x380d0000, 0x380d4000, 0x380d8000, 0x380dc000, 0x380e0000, 0x380e4000,
+0x380e8000, 0x380ec000, 0x380f0000, 0x380f4000, 0x380f8000, 0x380fc000,
+0x38100000, 0x38104000, 0x38108000, 0x3810c000, 0x38110000, 0x38114000,
+0x38118000, 0x3811c000, 0x38120000, 0x38124000, 0x38128000, 0x3812c000,
+0x38130000, 0x38134000, 0x38138000, 0x3813c000, 0x38140000, 0x38144000,
+0x38148000, 0x3814c000, 0x38150000, 0x38154000, 0x38158000, 0x3815c000,
+0x38160000, 0x38164000, 0x38168000, 0x3816c000, 0x38170000, 0x38174000,
+0x38178000, 0x3817c000, 0x38180000, 0x38184000, 0x38188000, 0x3818c000,
+0x38190000, 0x38194000, 0x38198000, 0x3819c000, 0x381a0000, 0x381a4000,
+0x381a8000, 0x381ac000, 0x381b0000, 0x381b4000, 0x381b8000, 0x381bc000,
+0x381c0000, 0x381c4000, 0x381c8000, 0x381cc000, 0x381d0000, 0x381d4000,
+0x381d8000, 0x381dc000, 0x381e0000, 0x381e4000, 0x381e8000, 0x381ec000,
+0x381f0000, 0x381f4000, 0x381f8000, 0x381fc000, 0x38200000, 0x38204000,
+0x38208000, 0x3820c000, 0x38210000, 0x38214000, 0x38218000, 0x3821c000,
+0x38220000, 0x38224000, 0x38228000, 0x3822c000, 0x38230000, 0x38234000,
+0x38238000, 0x3823c000, 0x38240000, 0x38244000, 0x38248000, 0x3824c000,
+0x38250000, 0x38254000, 0x38258000, 0x3825c000, 0x38260000, 0x38264000,
+0x38268000, 0x3826c000, 0x38270000, 0x38274000, 0x38278000, 0x3827c000,
+0x38280000, 0x38284000, 0x38288000, 0x3828c000, 0x38290000, 0x38294000,
+0x38298000, 0x3829c000, 0x382a0000, 0x382a4000, 0x382a8000, 0x382ac000,
+0x382b0000, 0x382b4000, 0x382b8000, 0x382bc000, 0x382c0000, 0x382c4000,
+0x382c8000, 0x382cc000, 0x382d0000, 0x382d4000, 0x382d8000, 0x382dc000,
+0x382e0000, 0x382e4000, 0x382e8000, 0x382ec000, 0x382f0000, 0x382f4000,
+0x382f8000, 0x382fc000, 0x38300000, 0x38304000, 0x38308000, 0x3830c000,
+0x38310000, 0x38314000, 0x38318000, 0x3831c000, 0x38320000, 0x38324000,
+0x38328000, 0x3832c000, 0x38330000, 0x38334000, 0x38338000, 0x3833c000,
+0x38340000, 0x38344000, 0x38348000, 0x3834c000, 0x38350000, 0x38354000,
+0x38358000, 0x3835c000, 0x38360000, 0x38364000, 0x38368000, 0x3836c000,
+0x38370000, 0x38374000, 0x38378000, 0x3837c000, 0x38380000, 0x38384000,
+0x38388000, 0x3838c000, 0x38390000, 0x38394000, 0x38398000, 0x3839c000,
+0x383a0000, 0x383a4000, 0x383a8000, 0x383ac000, 0x383b0000, 0x383b4000,
+0x383b8000, 0x383bc000, 0x383c0000, 0x383c4000, 0x383c8000, 0x383cc000,
+0x383d0000, 0x383d4000, 0x383d8000, 0x383dc000, 0x383e0000, 0x383e4000,
+0x383e8000, 0x383ec000, 0x383f0000, 0x383f4000, 0x383f8000, 0x383fc000,
+0x38400000, 0x38404000, 0x38408000, 0x3840c000, 0x38410000, 0x38414000,
+0x38418000, 0x3841c000, 0x38420000, 0x38424000, 0x38428000, 0x3842c000,
+0x38430000, 0x38434000, 0x38438000, 0x3843c000, 0x38440000, 0x38444000,
+0x38448000, 0x3844c000, 0x38450000, 0x38454000, 0x38458000, 0x3845c000,
+0x38460000, 0x38464000, 0x38468000, 0x3846c000, 0x38470000, 0x38474000,
+0x38478000, 0x3847c000, 0x38480000, 0x38484000, 0x38488000, 0x3848c000,
+0x38490000, 0x38494000, 0x38498000, 0x3849c000, 0x384a0000, 0x384a4000,
+0x384a8000, 0x384ac000, 0x384b0000, 0x384b4000, 0x384b8000, 0x384bc000,
+0x384c0000, 0x384c4000, 0x384c8000, 0x384cc000, 0x384d0000, 0x384d4000,
+0x384d8000, 0x384dc000, 0x384e0000, 0x384e4000, 0x384e8000, 0x384ec000,
+0x384f0000, 0x384f4000, 0x384f8000, 0x384fc000, 0x38500000, 0x38504000,
+0x38508000, 0x3850c000, 0x38510000, 0x38514000, 0x38518000, 0x3851c000,
+0x38520000, 0x38524000, 0x38528000, 0x3852c000, 0x38530000, 0x38534000,
+0x38538000, 0x3853c000, 0x38540000, 0x38544000, 0x38548000, 0x3854c000,
+0x38550000, 0x38554000, 0x38558000, 0x3855c000, 0x38560000, 0x38564000,
+0x38568000, 0x3856c000, 0x38570000, 0x38574000, 0x38578000, 0x3857c000,
+0x38580000, 0x38584000, 0x38588000, 0x3858c000, 0x38590000, 0x38594000,
+0x38598000, 0x3859c000, 0x385a0000, 0x385a4000, 0x385a8000, 0x385ac000,
+0x385b0000, 0x385b4000, 0x385b8000, 0x385bc000, 0x385c0000, 0x385c4000,
+0x385c8000, 0x385cc000, 0x385d0000, 0x385d4000, 0x385d8000, 0x385dc000,
+0x385e0000, 0x385e4000, 0x385e8000, 0x385ec000, 0x385f0000, 0x385f4000,
+0x385f8000, 0x385fc000, 0x38600000, 0x38604000, 0x38608000, 0x3860c000,
+0x38610000, 0x38614000, 0x38618000, 0x3861c000, 0x38620000, 0x38624000,
+0x38628000, 0x3862c000, 0x38630000, 0x38634000, 0x38638000, 0x3863c000,
+0x38640000, 0x38644000, 0x38648000, 0x3864c000, 0x38650000, 0x38654000,
+0x38658000, 0x3865c000, 0x38660000, 0x38664000, 0x38668000, 0x3866c000,
+0x38670000, 0x38674000, 0x38678000, 0x3867c000, 0x38680000, 0x38684000,
+0x38688000, 0x3868c000, 0x38690000, 0x38694000, 0x38698000, 0x3869c000,
+0x386a0000, 0x386a4000, 0x386a8000, 0x386ac000, 0x386b0000, 0x386b4000,
+0x386b8000, 0x386bc000, 0x386c0000, 0x386c4000, 0x386c8000, 0x386cc000,
+0x386d0000, 0x386d4000, 0x386d8000, 0x386dc000, 0x386e0000, 0x386e4000,
+0x386e8000, 0x386ec000, 0x386f0000, 0x386f4000, 0x386f8000, 0x386fc000,
+0x38700000, 0x38704000, 0x38708000, 0x3870c000, 0x38710000, 0x38714000,
+0x38718000, 0x3871c000, 0x38720000, 0x38724000, 0x38728000, 0x3872c000,
+0x38730000, 0x38734000, 0x38738000, 0x3873c000, 0x38740000, 0x38744000,
+0x38748000, 0x3874c000, 0x38750000, 0x38754000, 0x38758000, 0x3875c000,
+0x38760000, 0x38764000, 0x38768000, 0x3876c000, 0x38770000, 0x38774000,
+0x38778000, 0x3877c000, 0x38780000, 0x38784000, 0x38788000, 0x3878c000,
+0x38790000, 0x38794000, 0x38798000, 0x3879c000, 0x387a0000, 0x387a4000,
+0x387a8000, 0x387ac000, 0x387b0000, 0x387b4000, 0x387b8000, 0x387bc000,
+0x387c0000, 0x387c4000, 0x387c8000, 0x387cc000, 0x387d0000, 0x387d4000,
+0x387d8000, 0x387dc000, 0x387e0000, 0x387e4000, 0x387e8000, 0x387ec000,
+0x387f0000, 0x387f4000, 0x387f8000, 0x387fc000, 0x38000000, 0x38002000,
+0x38004000, 0x38006000, 0x38008000, 0x3800a000, 0x3800c000, 0x3800e000,
+0x38010000, 0x38012000, 0x38014000, 0x38016000, 0x38018000, 0x3801a000,
+0x3801c000, 0x3801e000, 0x38020000, 0x38022000, 0x38024000, 0x38026000,
+0x38028000, 0x3802a000, 0x3802c000, 0x3802e000, 0x38030000, 0x38032000,
+0x38034000, 0x38036000, 0x38038000, 0x3803a000, 0x3803c000, 0x3803e000,
+0x38040000, 0x38042000, 0x38044000, 0x38046000, 0x38048000, 0x3804a000,
+0x3804c000, 0x3804e000, 0x38050000, 0x38052000, 0x38054000, 0x38056000,
+0x38058000, 0x3805a000, 0x3805c000, 0x3805e000, 0x38060000, 0x38062000,
+0x38064000, 0x38066000, 0x38068000, 0x3806a000, 0x3806c000, 0x3806e000,
+0x38070000, 0x38072000, 0x38074000, 0x38076000, 0x38078000, 0x3807a000,
+0x3807c000, 0x3807e000, 0x38080000, 0x38082000, 0x38084000, 0x38086000,
+0x38088000, 0x3808a000, 0x3808c000, 0x3808e000, 0x38090000, 0x38092000,
+0x38094000, 0x38096000, 0x38098000, 0x3809a000, 0x3809c000, 0x3809e000,
+0x380a0000, 0x380a2000, 0x380a4000, 0x380a6000, 0x380a8000, 0x380aa000,
+0x380ac000, 0x380ae000, 0x380b0000, 0x380b2000, 0x380b4000, 0x380b6000,
+0x380b8000, 0x380ba000, 0x380bc000, 0x380be000, 0x380c0000, 0x380c2000,
+0x380c4000, 0x380c6000, 0x380c8000, 0x380ca000, 0x380cc000, 0x380ce000,
+0x380d0000, 0x380d2000, 0x380d4000, 0x380d6000, 0x380d8000, 0x380da000,
+0x380dc000, 0x380de000, 0x380e0000, 0x380e2000, 0x380e4000, 0x380e6000,
+0x380e8000, 0x380ea000, 0x380ec000, 0x380ee000, 0x380f0000, 0x380f2000,
+0x380f4000, 0x380f6000, 0x380f8000, 0x380fa000, 0x380fc000, 0x380fe000,
+0x38100000, 0x38102000, 0x38104000, 0x38106000, 0x38108000, 0x3810a000,
+0x3810c000, 0x3810e000, 0x38110000, 0x38112000, 0x38114000, 0x38116000,
+0x38118000, 0x3811a000, 0x3811c000, 0x3811e000, 0x38120000, 0x38122000,
+0x38124000, 0x38126000, 0x38128000, 0x3812a000, 0x3812c000, 0x3812e000,
+0x38130000, 0x38132000, 0x38134000, 0x38136000, 0x38138000, 0x3813a000,
+0x3813c000, 0x3813e000, 0x38140000, 0x38142000, 0x38144000, 0x38146000,
+0x38148000, 0x3814a000, 0x3814c000, 0x3814e000, 0x38150000, 0x38152000,
+0x38154000, 0x38156000, 0x38158000, 0x3815a000, 0x3815c000, 0x3815e000,
+0x38160000, 0x38162000, 0x38164000, 0x38166000, 0x38168000, 0x3816a000,
+0x3816c000, 0x3816e000, 0x38170000, 0x38172000, 0x38174000, 0x38176000,
+0x38178000, 0x3817a000, 0x3817c000, 0x3817e000, 0x38180000, 0x38182000,
+0x38184000, 0x38186000, 0x38188000, 0x3818a000, 0x3818c000, 0x3818e000,
+0x38190000, 0x38192000, 0x38194000, 0x38196000, 0x38198000, 0x3819a000,
+0x3819c000, 0x3819e000, 0x381a0000, 0x381a2000, 0x381a4000, 0x381a6000,
+0x381a8000, 0x381aa000, 0x381ac000, 0x381ae000, 0x381b0000, 0x381b2000,
+0x381b4000, 0x381b6000, 0x381b8000, 0x381ba000, 0x381bc000, 0x381be000,
+0x381c0000, 0x381c2000, 0x381c4000, 0x381c6000, 0x381c8000, 0x381ca000,
+0x381cc000, 0x381ce000, 0x381d0000, 0x381d2000, 0x381d4000, 0x381d6000,
+0x381d8000, 0x381da000, 0x381dc000, 0x381de000, 0x381e0000, 0x381e2000,
+0x381e4000, 0x381e6000, 0x381e8000, 0x381ea000, 0x381ec000, 0x381ee000,
+0x381f0000, 0x381f2000, 0x381f4000, 0x381f6000, 0x381f8000, 0x381fa000,
+0x381fc000, 0x381fe000, 0x38200000, 0x38202000, 0x38204000, 0x38206000,
+0x38208000, 0x3820a000, 0x3820c000, 0x3820e000, 0x38210000, 0x38212000,
+0x38214000, 0x38216000, 0x38218000, 0x3821a000, 0x3821c000, 0x3821e000,
+0x38220000, 0x38222000, 0x38224000, 0x38226000, 0x38228000, 0x3822a000,
+0x3822c000, 0x3822e000, 0x38230000, 0x38232000, 0x38234000, 0x38236000,
+0x38238000, 0x3823a000, 0x3823c000, 0x3823e000, 0x38240000, 0x38242000,
+0x38244000, 0x38246000, 0x38248000, 0x3824a000, 0x3824c000, 0x3824e000,
+0x38250000, 0x38252000, 0x38254000, 0x38256000, 0x38258000, 0x3825a000,
+0x3825c000, 0x3825e000, 0x38260000, 0x38262000, 0x38264000, 0x38266000,
+0x38268000, 0x3826a000, 0x3826c000, 0x3826e000, 0x38270000, 0x38272000,
+0x38274000, 0x38276000, 0x38278000, 0x3827a000, 0x3827c000, 0x3827e000,
+0x38280000, 0x38282000, 0x38284000, 0x38286000, 0x38288000, 0x3828a000,
+0x3828c000, 0x3828e000, 0x38290000, 0x38292000, 0x38294000, 0x38296000,
+0x38298000, 0x3829a000, 0x3829c000, 0x3829e000, 0x382a0000, 0x382a2000,
+0x382a4000, 0x382a6000, 0x382a8000, 0x382aa000, 0x382ac000, 0x382ae000,
+0x382b0000, 0x382b2000, 0x382b4000, 0x382b6000, 0x382b8000, 0x382ba000,
+0x382bc000, 0x382be000, 0x382c0000, 0x382c2000, 0x382c4000, 0x382c6000,
+0x382c8000, 0x382ca000, 0x382cc000, 0x382ce000, 0x382d0000, 0x382d2000,
+0x382d4000, 0x382d6000, 0x382d8000, 0x382da000, 0x382dc000, 0x382de000,
+0x382e0000, 0x382e2000, 0x382e4000, 0x382e6000, 0x382e8000, 0x382ea000,
+0x382ec000, 0x382ee000, 0x382f0000, 0x382f2000, 0x382f4000, 0x382f6000,
+0x382f8000, 0x382fa000, 0x382fc000, 0x382fe000, 0x38300000, 0x38302000,
+0x38304000, 0x38306000, 0x38308000, 0x3830a000, 0x3830c000, 0x3830e000,
+0x38310000, 0x38312000, 0x38314000, 0x38316000, 0x38318000, 0x3831a000,
+0x3831c000, 0x3831e000, 0x38320000, 0x38322000, 0x38324000, 0x38326000,
+0x38328000, 0x3832a000, 0x3832c000, 0x3832e000, 0x38330000, 0x38332000,
+0x38334000, 0x38336000, 0x38338000, 0x3833a000, 0x3833c000, 0x3833e000,
+0x38340000, 0x38342000, 0x38344000, 0x38346000, 0x38348000, 0x3834a000,
+0x3834c000, 0x3834e000, 0x38350000, 0x38352000, 0x38354000, 0x38356000,
+0x38358000, 0x3835a000, 0x3835c000, 0x3835e000, 0x38360000, 0x38362000,
+0x38364000, 0x38366000, 0x38368000, 0x3836a000, 0x3836c000, 0x3836e000,
+0x38370000, 0x38372000, 0x38374000, 0x38376000, 0x38378000, 0x3837a000,
+0x3837c000, 0x3837e000, 0x38380000, 0x38382000, 0x38384000, 0x38386000,
+0x38388000, 0x3838a000, 0x3838c000, 0x3838e000, 0x38390000, 0x38392000,
+0x38394000, 0x38396000, 0x38398000, 0x3839a000, 0x3839c000, 0x3839e000,
+0x383a0000, 0x383a2000, 0x383a4000, 0x383a6000, 0x383a8000, 0x383aa000,
+0x383ac000, 0x383ae000, 0x383b0000, 0x383b2000, 0x383b4000, 0x383b6000,
+0x383b8000, 0x383ba000, 0x383bc000, 0x383be000, 0x383c0000, 0x383c2000,
+0x383c4000, 0x383c6000, 0x383c8000, 0x383ca000, 0x383cc000, 0x383ce000,
+0x383d0000, 0x383d2000, 0x383d4000, 0x383d6000, 0x383d8000, 0x383da000,
+0x383dc000, 0x383de000, 0x383e0000, 0x383e2000, 0x383e4000, 0x383e6000,
+0x383e8000, 0x383ea000, 0x383ec000, 0x383ee000, 0x383f0000, 0x383f2000,
+0x383f4000, 0x383f6000, 0x383f8000, 0x383fa000, 0x383fc000, 0x383fe000,
+0x38400000, 0x38402000, 0x38404000, 0x38406000, 0x38408000, 0x3840a000,
+0x3840c000, 0x3840e000, 0x38410000, 0x38412000, 0x38414000, 0x38416000,
+0x38418000, 0x3841a000, 0x3841c000, 0x3841e000, 0x38420000, 0x38422000,
+0x38424000, 0x38426000, 0x38428000, 0x3842a000, 0x3842c000, 0x3842e000,
+0x38430000, 0x38432000, 0x38434000, 0x38436000, 0x38438000, 0x3843a000,
+0x3843c000, 0x3843e000, 0x38440000, 0x38442000, 0x38444000, 0x38446000,
+0x38448000, 0x3844a000, 0x3844c000, 0x3844e000, 0x38450000, 0x38452000,
+0x38454000, 0x38456000, 0x38458000, 0x3845a000, 0x3845c000, 0x3845e000,
+0x38460000, 0x38462000, 0x38464000, 0x38466000, 0x38468000, 0x3846a000,
+0x3846c000, 0x3846e000, 0x38470000, 0x38472000, 0x38474000, 0x38476000,
+0x38478000, 0x3847a000, 0x3847c000, 0x3847e000, 0x38480000, 0x38482000,
+0x38484000, 0x38486000, 0x38488000, 0x3848a000, 0x3848c000, 0x3848e000,
+0x38490000, 0x38492000, 0x38494000, 0x38496000, 0x38498000, 0x3849a000,
+0x3849c000, 0x3849e000, 0x384a0000, 0x384a2000, 0x384a4000, 0x384a6000,
+0x384a8000, 0x384aa000, 0x384ac000, 0x384ae000, 0x384b0000, 0x384b2000,
+0x384b4000, 0x384b6000, 0x384b8000, 0x384ba000, 0x384bc000, 0x384be000,
+0x384c0000, 0x384c2000, 0x384c4000, 0x384c6000, 0x384c8000, 0x384ca000,
+0x384cc000, 0x384ce000, 0x384d0000, 0x384d2000, 0x384d4000, 0x384d6000,
+0x384d8000, 0x384da000, 0x384dc000, 0x384de000, 0x384e0000, 0x384e2000,
+0x384e4000, 0x384e6000, 0x384e8000, 0x384ea000, 0x384ec000, 0x384ee000,
+0x384f0000, 0x384f2000, 0x384f4000, 0x384f6000, 0x384f8000, 0x384fa000,
+0x384fc000, 0x384fe000, 0x38500000, 0x38502000, 0x38504000, 0x38506000,
+0x38508000, 0x3850a000, 0x3850c000, 0x3850e000, 0x38510000, 0x38512000,
+0x38514000, 0x38516000, 0x38518000, 0x3851a000, 0x3851c000, 0x3851e000,
+0x38520000, 0x38522000, 0x38524000, 0x38526000, 0x38528000, 0x3852a000,
+0x3852c000, 0x3852e000, 0x38530000, 0x38532000, 0x38534000, 0x38536000,
+0x38538000, 0x3853a000, 0x3853c000, 0x3853e000, 0x38540000, 0x38542000,
+0x38544000, 0x38546000, 0x38548000, 0x3854a000, 0x3854c000, 0x3854e000,
+0x38550000, 0x38552000, 0x38554000, 0x38556000, 0x38558000, 0x3855a000,
+0x3855c000, 0x3855e000, 0x38560000, 0x38562000, 0x38564000, 0x38566000,
+0x38568000, 0x3856a000, 0x3856c000, 0x3856e000, 0x38570000, 0x38572000,
+0x38574000, 0x38576000, 0x38578000, 0x3857a000, 0x3857c000, 0x3857e000,
+0x38580000, 0x38582000, 0x38584000, 0x38586000, 0x38588000, 0x3858a000,
+0x3858c000, 0x3858e000, 0x38590000, 0x38592000, 0x38594000, 0x38596000,
+0x38598000, 0x3859a000, 0x3859c000, 0x3859e000, 0x385a0000, 0x385a2000,
+0x385a4000, 0x385a6000, 0x385a8000, 0x385aa000, 0x385ac000, 0x385ae000,
+0x385b0000, 0x385b2000, 0x385b4000, 0x385b6000, 0x385b8000, 0x385ba000,
+0x385bc000, 0x385be000, 0x385c0000, 0x385c2000, 0x385c4000, 0x385c6000,
+0x385c8000, 0x385ca000, 0x385cc000, 0x385ce000, 0x385d0000, 0x385d2000,
+0x385d4000, 0x385d6000, 0x385d8000, 0x385da000, 0x385dc000, 0x385de000,
+0x385e0000, 0x385e2000, 0x385e4000, 0x385e6000, 0x385e8000, 0x385ea000,
+0x385ec000, 0x385ee000, 0x385f0000, 0x385f2000, 0x385f4000, 0x385f6000,
+0x385f8000, 0x385fa000, 0x385fc000, 0x385fe000, 0x38600000, 0x38602000,
+0x38604000, 0x38606000, 0x38608000, 0x3860a000, 0x3860c000, 0x3860e000,
+0x38610000, 0x38612000, 0x38614000, 0x38616000, 0x38618000, 0x3861a000,
+0x3861c000, 0x3861e000, 0x38620000, 0x38622000, 0x38624000, 0x38626000,
+0x38628000, 0x3862a000, 0x3862c000, 0x3862e000, 0x38630000, 0x38632000,
+0x38634000, 0x38636000, 0x38638000, 0x3863a000, 0x3863c000, 0x3863e000,
+0x38640000, 0x38642000, 0x38644000, 0x38646000, 0x38648000, 0x3864a000,
+0x3864c000, 0x3864e000, 0x38650000, 0x38652000, 0x38654000, 0x38656000,
+0x38658000, 0x3865a000, 0x3865c000, 0x3865e000, 0x38660000, 0x38662000,
+0x38664000, 0x38666000, 0x38668000, 0x3866a000, 0x3866c000, 0x3866e000,
+0x38670000, 0x38672000, 0x38674000, 0x38676000, 0x38678000, 0x3867a000,
+0x3867c000, 0x3867e000, 0x38680000, 0x38682000, 0x38684000, 0x38686000,
+0x38688000, 0x3868a000, 0x3868c000, 0x3868e000, 0x38690000, 0x38692000,
+0x38694000, 0x38696000, 0x38698000, 0x3869a000, 0x3869c000, 0x3869e000,
+0x386a0000, 0x386a2000, 0x386a4000, 0x386a6000, 0x386a8000, 0x386aa000,
+0x386ac000, 0x386ae000, 0x386b0000, 0x386b2000, 0x386b4000, 0x386b6000,
+0x386b8000, 0x386ba000, 0x386bc000, 0x386be000, 0x386c0000, 0x386c2000,
+0x386c4000, 0x386c6000, 0x386c8000, 0x386ca000, 0x386cc000, 0x386ce000,
+0x386d0000, 0x386d2000, 0x386d4000, 0x386d6000, 0x386d8000, 0x386da000,
+0x386dc000, 0x386de000, 0x386e0000, 0x386e2000, 0x386e4000, 0x386e6000,
+0x386e8000, 0x386ea000, 0x386ec000, 0x386ee000, 0x386f0000, 0x386f2000,
+0x386f4000, 0x386f6000, 0x386f8000, 0x386fa000, 0x386fc000, 0x386fe000,
+0x38700000, 0x38702000, 0x38704000, 0x38706000, 0x38708000, 0x3870a000,
+0x3870c000, 0x3870e000, 0x38710000, 0x38712000, 0x38714000, 0x38716000,
+0x38718000, 0x3871a000, 0x3871c000, 0x3871e000, 0x38720000, 0x38722000,
+0x38724000, 0x38726000, 0x38728000, 0x3872a000, 0x3872c000, 0x3872e000,
+0x38730000, 0x38732000, 0x38734000, 0x38736000, 0x38738000, 0x3873a000,
+0x3873c000, 0x3873e000, 0x38740000, 0x38742000, 0x38744000, 0x38746000,
+0x38748000, 0x3874a000, 0x3874c000, 0x3874e000, 0x38750000, 0x38752000,
+0x38754000, 0x38756000, 0x38758000, 0x3875a000, 0x3875c000, 0x3875e000,
+0x38760000, 0x38762000, 0x38764000, 0x38766000, 0x38768000, 0x3876a000,
+0x3876c000, 0x3876e000, 0x38770000, 0x38772000, 0x38774000, 0x38776000,
+0x38778000, 0x3877a000, 0x3877c000, 0x3877e000, 0x38780000, 0x38782000,
+0x38784000, 0x38786000, 0x38788000, 0x3878a000, 0x3878c000, 0x3878e000,
+0x38790000, 0x38792000, 0x38794000, 0x38796000, 0x38798000, 0x3879a000,
+0x3879c000, 0x3879e000, 0x387a0000, 0x387a2000, 0x387a4000, 0x387a6000,
+0x387a8000, 0x387aa000, 0x387ac000, 0x387ae000, 0x387b0000, 0x387b2000,
+0x387b4000, 0x387b6000, 0x387b8000, 0x387ba000, 0x387bc000, 0x387be000,
+0x387c0000, 0x387c2000, 0x387c4000, 0x387c6000, 0x387c8000, 0x387ca000,
+0x387cc000, 0x387ce000, 0x387d0000, 0x387d2000, 0x387d4000, 0x387d6000,
+0x387d8000, 0x387da000, 0x387dc000, 0x387de000, 0x387e0000, 0x387e2000,
+0x387e4000, 0x387e6000, 0x387e8000, 0x387ea000, 0x387ec000, 0x387ee000,
+0x387f0000, 0x387f2000, 0x387f4000, 0x387f6000, 0x387f8000, 0x387fa000,
+0x387fc000, 0x387fe000
+};
+
+static cmsUInt16Number Offset[64] = {
+0x0000, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
+0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
+0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
+0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
+0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
+0x0400, 0x0400, 0x0000, 0x0400, 0x0400, 0x0400,
+0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
+0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
+0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
+0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
+0x0400, 0x0400, 0x0400, 0x0400
+};
+
+static cmsUInt32Number Exponent[64] = {
+0x00000000, 0x00800000, 0x01000000, 0x01800000, 0x02000000, 0x02800000,
+0x03000000, 0x03800000, 0x04000000, 0x04800000, 0x05000000, 0x05800000,
+0x06000000, 0x06800000, 0x07000000, 0x07800000, 0x08000000, 0x08800000,
+0x09000000, 0x09800000, 0x0a000000, 0x0a800000, 0x0b000000, 0x0b800000,
+0x0c000000, 0x0c800000, 0x0d000000, 0x0d800000, 0x0e000000, 0x0e800000,
+0x0f000000, 0x47800000, 0x80000000, 0x80800000, 0x81000000, 0x81800000,
+0x82000000, 0x82800000, 0x83000000, 0x83800000, 0x84000000, 0x84800000,
+0x85000000, 0x85800000, 0x86000000, 0x86800000, 0x87000000, 0x87800000,
+0x88000000, 0x88800000, 0x89000000, 0x89800000, 0x8a000000, 0x8a800000,
+0x8b000000, 0x8b800000, 0x8c000000, 0x8c800000, 0x8d000000, 0x8d800000,
+0x8e000000, 0x8e800000, 0x8f000000, 0xc7800000
+};
+
+static cmsUInt16Number Base[512] = {
+0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+0x0000, 0x0000, 0x0000, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040,
+0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x0c00, 0x1000, 0x1400, 0x1800, 0x1c00,
+0x2000, 0x2400, 0x2800, 0x2c00, 0x3000, 0x3400, 0x3800, 0x3c00, 0x4000, 0x4400,
+0x4800, 0x4c00, 0x5000, 0x5400, 0x5800, 0x5c00, 0x6000, 0x6400, 0x6800, 0x6c00,
+0x7000, 0x7400, 0x7800, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00,
+0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00,
+0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00,
+0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00,
+0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00,
+0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00,
+0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00,
+0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00,
+0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00,
+0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00,
+0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00,
+0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x8000, 0x8000, 0x8000, 0x8000,
+0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
+0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
+0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
+0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
+0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
+0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
+0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
+0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
+0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
+0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8001,
+0x8002, 0x8004, 0x8008, 0x8010, 0x8020, 0x8040, 0x8080, 0x8100, 0x8200, 0x8400,
+0x8800, 0x8c00, 0x9000, 0x9400, 0x9800, 0x9c00, 0xa000, 0xa400, 0xa800, 0xac00,
+0xb000, 0xb400, 0xb800, 0xbc00, 0xc000, 0xc400, 0xc800, 0xcc00, 0xd000, 0xd400,
+0xd800, 0xdc00, 0xe000, 0xe400, 0xe800, 0xec00, 0xf000, 0xf400, 0xf800, 0xfc00,
+0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00,
+0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00,
+0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00,
+0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00,
+0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00,
+0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00,
+0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00,
+0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00,
+0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00,
+0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00,
+0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00,
+0xfc00, 0xfc00
+};
+
+static cmsUInt8Number  Shift[512] = {
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x17,
+0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f, 0x0e, 0x0d, 0x0d, 0x0d, 0x0d,
+0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d,
+0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x0d, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x17, 0x16, 0x15, 0x14, 0x13,
+0x12, 0x11, 0x10, 0x0f, 0x0e, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d,
+0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d,
+0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+0x18, 0x18, 0x18, 0x18, 0x0d
+};
+
+cmsFloat32Number _cmsHalf2Float(cmsUInt16Number h)
+{
+    union {
+        cmsFloat32Number flt;
+        cmsUInt32Number  num;
+    } out;
+
+    int n = h >> 10;
+
+    out.num = Mantissa[  (h & 0x3ff) + Offset[ n ] ] + Exponent[ n ];
+    return out.flt;
+}
+
+cmsUInt16Number _cmsFloat2Half(cmsFloat32Number flt)
+{
+    union {
+        cmsFloat32Number flt;
+        cmsUInt32Number  num;
+    } in;
+
+    cmsUInt32Number n, j;
+
+    in.flt = flt;
+    n = in.num;
+    j = (n >> 23) & 0x1ff;
+
+    return (cmsUInt16Number) ((cmsUInt32Number) Base[ j ] + (( n & 0x007fffff) >> Shift[ j ]));
+}
+
+#endif
index 5b9a09a..7cd7ce9 100644 (file)
-//---------------------------------------------------------------------------------
-//
-//  Little Color Management System
-//  Copyright (c) 1998-2010 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"
-
-// This module incorporates several interpolation routines, for 1 to 8 channels on input and
-// up to 65535 channels on output. The user may change those by using the interpolation plug-in
-
-// Interpolation routines by default
-static cmsInterpFunction DefaultInterpolatorsFactory(cmsUInt32Number nInputChannels, cmsUInt32Number nOutputChannels, cmsUInt32Number dwFlags);
-
-// This is the default factory
-static cmsInterpFnFactory Interpolators = DefaultInterpolatorsFactory;
-
-
-// Main plug-in entry
-cmsBool  _cmsRegisterInterpPlugin(cmsPluginBase* Data)
-{
-    cmsPluginInterpolation* Plugin = (cmsPluginInterpolation*) Data;
-
-    if (Data == NULL) {
-    
-        Interpolators = DefaultInterpolatorsFactory;
-        return TRUE;
-    }
-
-    // Set replacement functions
-    Interpolators = Plugin ->InterpolatorsFactory;  
-    return TRUE;
-}
-
-
-// Set the interpolation method
-
-cmsBool _cmsSetInterpolationRoutine(cmsInterpParams* p)
-{
-    // Invoke factory, possibly in the Plug-in
-    p ->Interpolation = Interpolators(p -> nInputs, p ->nOutputs, p ->dwFlags);
-
-    // If unsupported by the plug-in, go for the LittleCMS default. 
-    // If happens only if an extern plug-in is being used
-    if (p ->Interpolation.Lerp16 == NULL)
-        p ->Interpolation = DefaultInterpolatorsFactory(p ->nInputs, p ->nOutputs, p ->dwFlags);
-
-    // Check for valid interpolator (we just check one member of the union)
-    if (p ->Interpolation.Lerp16 == NULL) {    
-            return FALSE;
-    }
-    return TRUE;
-}
-
-
-// This function precalculates as many parameters as possible to speed up the interpolation.
-cmsInterpParams* _cmsComputeInterpParamsEx(cmsContext ContextID,
-                                           const cmsUInt32Number nSamples[], 
-                                           int InputChan, int OutputChan, 
-                                           const void *Table,
-                                           cmsUInt32Number dwFlags)
-{        
-    cmsInterpParams* p;
-    int i;
-    
-    // Check for maximum inputs
-    if (InputChan > MAX_INPUT_DIMENSIONS) {
-             cmsSignalError(ContextID, cmsERROR_RANGE, "Too many input channels (%d channels, max=%d)", InputChan, MAX_INPUT_DIMENSIONS);            
-            return NULL;
-    }
-
-    // Creates an empty object
-    p = (cmsInterpParams*) _cmsMallocZero(ContextID, sizeof(cmsInterpParams));
-    if (p == NULL) return NULL;
-
-    // Keep original parameters
-    p -> dwFlags  = dwFlags;
-    p -> nInputs  = InputChan;
-    p -> nOutputs = OutputChan;
-    p ->Table     = Table;
-    p ->ContextID  = ContextID;
-
-    // Fill samples per input direction and domain (which is number of nodes minus one)
-    for (i=0; i < InputChan; i++) {
-
-        p -> nSamples[i] = nSamples[i];
-        p -> Domain[i]   = nSamples[i] - 1;     
-    }
-
-    // Compute factors to apply to each component to index the grid array
-    p -> opta[0] = p -> nOutputs;  
-    for (i=1; i < InputChan; i++)
-        p ->opta[i] = p ->opta[i-1] * nSamples[InputChan-i];
-
-
-    if (!_cmsSetInterpolationRoutine(p)) {
-         cmsSignalError(ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unsupported interpolation (%d->%d channels)", InputChan, OutputChan);            
-        _cmsFree(ContextID, p);
-        return NULL;
-    }
-
-    // All seems ok
-    return p;
-}
-
-
-// This one is a wrapper on the anterior, but assuming all directions have same number of nodes
-cmsInterpParams* _cmsComputeInterpParams(cmsContext ContextID, int nSamples, int InputChan, int OutputChan, const void* Table, cmsUInt32Number dwFlags)
-{
-    int i;
-    cmsUInt32Number Samples[MAX_INPUT_DIMENSIONS];
-
-    // Fill the auxiliar array
-    for (i=0; i < MAX_INPUT_DIMENSIONS; i++) 
-        Samples[i] = nSamples;
-
-    // Call the extended function
-    return _cmsComputeInterpParamsEx(ContextID, Samples, InputChan, OutputChan, Table, dwFlags);
-}
-
-
-// Free all associated memory
-void _cmsFreeInterpParams(cmsInterpParams* p)
-{
-    if (p != NULL) _cmsFree(p ->ContextID, p);
-}
-
-
-// Inline fixed point interpolation 
-cmsINLINE cmsUInt16Number LinearInterp(cmsS15Fixed16Number a, cmsS15Fixed16Number l, cmsS15Fixed16Number h)
-{
-    cmsUInt32Number dif = (cmsUInt32Number) (h - l) * a + 0x8000;           
-    dif = (dif >> 16) + l;        
-    return (cmsUInt16Number) (dif);
-}
-
-
-//  Linear interpolation (Fixed-point optimized)
-static
-void LinLerp1D(register const cmsUInt16Number Value[], 
-               register cmsUInt16Number Output[], 
-               register const cmsInterpParams* p)
-{
-    cmsUInt16Number y1, y0; 
-    int cell0, rest;
-    int val3;
-    const cmsUInt16Number* LutTable = (cmsUInt16Number*) p ->Table;
-
-    // if last value... 
-    if (Value[0] == 0xffff) {
-
-        Output[0] = LutTable[p -> Domain[0]];
-        return;
-    }
-
-    val3 = p -> Domain[0] * Value[0];
-    val3 = _cmsToFixedDomain(val3);    // To fixed 15.16
-
-    cell0 = FIXED_TO_INT(val3);             // Cell is 16 MSB bits
-    rest  = FIXED_REST_TO_INT(val3);        // Rest is 16 LSB bits
-
-    y0 = LutTable[cell0];
-    y1 = LutTable[cell0+1];
-
-    
-    Output[0] = LinearInterp(rest, y0, y1);
-}
-
-
-// Floating-point version of 1D interpolation
-static
-void LinLerp1Dfloat(const cmsFloat32Number Value[], 
-                    cmsFloat32Number Output[],  
-                    const cmsInterpParams* p)
-{
-       cmsFloat32Number y1, y0;
-       cmsFloat32Number val2, rest;
-       int cell0, cell1;
-       const cmsFloat32Number* LutTable = (cmsFloat32Number*) p ->Table;
-
-       // if last value...
-       if (Value[0] == 1.0) {
-           Output[0] = LutTable[p -> Domain[0]];
-           return;
-       }
-
-       val2 = p -> Domain[0] * Value[0];
-
-       cell0 = (int) floor(val2);
-       cell1 = (int) ceil(val2);
-
-       // Rest is 16 LSB bits
-       rest = val2 - cell0;
-
-       y0 = LutTable[cell0] ;
-       y1 = LutTable[cell1] ;
-
-       Output[0] = y0 + (y1 - y0) * rest;     
-}
-
-
-
-// Eval gray LUT having only one input channel 
-static
-void Eval1Input(register const cmsUInt16Number Input[], 
-                register cmsUInt16Number Output[], 
-                register const cmsInterpParams* p16)
-{
-       cmsS15Fixed16Number fk;
-       cmsS15Fixed16Number k0, k1, rk, K0, K1;
-       int v;
-       cmsUInt32Number OutChan;
-       const cmsUInt16Number* LutTable = (cmsUInt16Number*) p16 -> Table;
-
-       v = Input[0] * p16 -> Domain[0];
-       fk = _cmsToFixedDomain(v);
-
-       k0 = FIXED_TO_INT(fk);
-       rk = (cmsUInt16Number) FIXED_REST_TO_INT(fk);
-
-       k1 = k0 + (Input[0] != 0xFFFFU ? 1 : 0);
-
-       K0 = p16 -> opta[0] * k0;
-       K1 = p16 -> opta[0] * k1;
-
-       for (OutChan=0; OutChan < p16->nOutputs; OutChan++) {
-
-           Output[OutChan] = LinearInterp(rk, LutTable[K0+OutChan], LutTable[K1+OutChan]);
-       }
-}
-
-
-
-// Eval gray LUT having only one input channel 
-static
-void Eval1InputFloat(const cmsFloat32Number Value[], 
-                     cmsFloat32Number Output[], 
-                     const cmsInterpParams* p)
-{
-    cmsFloat32Number y1, y0;
-    cmsFloat32Number val2, rest;
-    int cell0, cell1;
-    cmsUInt32Number OutChan;
-    const cmsFloat32Number* LutTable = (cmsFloat32Number*) p ->Table; 
-
-        // if last value...
-       if (Value[0] == 1.0) {
-           Output[0] = LutTable[p -> Domain[0]];
-           return;
-       }
-
-       val2 = p -> Domain[0] * Value[0];
-
-       cell0 = (int) floor(val2);
-       cell1 = (int) ceil(val2);
-
-       // Rest is 16 LSB bits
-       rest = val2 - cell0;
-       
-       cell0 *= p -> opta[0];
-       cell1 *= p -> opta[0];
-
-       for (OutChan=0; OutChan < p->nOutputs; OutChan++) {
-
-            y0 = LutTable[cell0 + OutChan] ;
-            y1 = LutTable[cell1 + OutChan] ;
-
-            Output[OutChan] = y0 + (y1 - y0) * rest;              
-       }
-}
-
-// Bilinear interpolation (16 bits) - cmsFloat32Number version
-static
-void BilinearInterpFloat(const cmsFloat32Number Input[], 
-                         cmsFloat32Number Output[],                          
-                         const cmsInterpParams* p)
-
-{
-#   define LERP(a,l,h)    (cmsFloat32Number) ((l)+(((h)-(l))*(a)))
-#   define DENS(i,j)      (LutTable[(i)+(j)+OutChan])
-
-    const cmsFloat32Number* LutTable = (cmsFloat32Number*) p ->Table; 
-    cmsFloat32Number      px, py;
-    int        x0, y0,
-               X0, Y0, X1, Y1;
-    int        TotalOut, OutChan;
-    cmsFloat32Number      fx, fy,
-        d00, d01, d10, d11,
-        dx0, dx1,
-        dxy;
-    
-    TotalOut   = p -> nOutputs;
-    px = Input[0] * p->Domain[0];
-    py = Input[1] * p->Domain[1];
-
-    x0 = (int) _cmsQuickFloor(px); fx = px - (cmsFloat32Number) x0;
-    y0 = (int) _cmsQuickFloor(py); fy = py - (cmsFloat32Number) y0;
-    
-    X0 = p -> opta[1] * x0;
-    X1 = X0 + (Input[0] >= 1.0 ? 0 : p->opta[1]);
-
-    Y0 = p -> opta[0] * y0;
-    Y1 = Y0 + (Input[1] >= 1.0 ? 0 : p->opta[0]);
-   
-    for (OutChan = 0; OutChan < TotalOut; OutChan++) {
-       
-        d00 = DENS(X0, Y0);
-        d01 = DENS(X0, Y1);
-        d10 = DENS(X1, Y0);
-        d11 = DENS(X1, Y1);
-
-        dx0 = LERP(fx, d00, d10);
-        dx1 = LERP(fx, d01, d11);
-
-        dxy = LERP(fy, dx0, dx1);
-
-        Output[OutChan] = dxy;
-    }
-
-
-#   undef LERP
-#   undef DENS
-}
-
-// Bilinear interpolation (16 bits) - optimized version
-static
-void BilinearInterp16(register const cmsUInt16Number Input[], 
-                      register cmsUInt16Number Output[],
-                      register const cmsInterpParams* p)
-
-{
-#define DENS(i,j) (LutTable[(i)+(j)+OutChan])
-#define LERP(a,l,h)     (cmsUInt16Number) (l + ROUND_FIXED_TO_INT(((h-l)*a)))
-
-           const cmsUInt16Number* LutTable = (cmsUInt16Number*) p ->Table; 
-           int        OutChan, TotalOut;
-           cmsS15Fixed16Number    fx, fy;
-  register int        rx, ry;
-           int        x0, y0;
-  register int        X0, X1, Y0, Y1;
-           int        d00, d01, d10, d11,
-                      dx0, dx1,
-                      dxy;
-
-    TotalOut   = p -> nOutputs;
-
-    fx = _cmsToFixedDomain((int) Input[0] * p -> Domain[0]);
-    x0  = FIXED_TO_INT(fx);
-    rx  = FIXED_REST_TO_INT(fx);    // Rest in 0..1.0 domain
-
-
-    fy = _cmsToFixedDomain((int) Input[1] * p -> Domain[1]);
-    y0  = FIXED_TO_INT(fy);
-    ry  = FIXED_REST_TO_INT(fy);
-
-
-    X0 = p -> opta[1] * x0;
-    X1 = X0 + (Input[0] == 0xFFFFU ? 0 : p->opta[1]);
-
-    Y0 = p -> opta[0] * y0;
-    Y1 = Y0 + (Input[1] == 0xFFFFU ? 0 : p->opta[0]);
-   
-    for (OutChan = 0; OutChan < TotalOut; OutChan++) {
-
-        d00 = DENS(X0, Y0);
-        d01 = DENS(X0, Y1);
-        d10 = DENS(X1, Y0);
-        d11 = DENS(X1, Y1);
-
-        dx0 = LERP(rx, d00, d10);
-        dx1 = LERP(rx, d01, d11);
-
-        dxy = LERP(ry, dx0, dx1);
-
-        Output[OutChan] = (cmsUInt16Number) dxy;
-    }
-
-
-#   undef LERP
-#   undef DENS
-}
-
-
-// Trilinear interpolation (16 bits) - cmsFloat32Number version
-static
-void TrilinearInterpFloat(const cmsFloat32Number Input[], 
-                          cmsFloat32Number Output[],                          
-                          const cmsInterpParams* p)
-
-{
-#   define LERP(a,l,h)      (cmsFloat32Number) ((l)+(((h)-(l))*(a)))
-#   define DENS(i,j,k)      (LutTable[(i)+(j)+(k)+OutChan])
-
-    const cmsFloat32Number* LutTable = (cmsFloat32Number*) p ->Table; 
-    cmsFloat32Number      px, py, pz;
-    int        x0, y0, z0,
-               X0, Y0, Z0, X1, Y1, Z1;
-    int        TotalOut, OutChan;
-    cmsFloat32Number      fx, fy, fz,
-        d000, d001, d010, d011,
-        d100, d101, d110, d111,
-        dx00, dx01, dx10, dx11,
-        dxy0, dxy1, dxyz;
-    
-    TotalOut   = p -> nOutputs;
-    
-    // We need some clipping here
-    px = Input[0];
-    py = Input[1];
-    pz = Input[2];
-
-    if (px < 0) px = 0; 
-    if (px > 1) px = 1;
-    if (py < 0) py = 0; 
-    if (py > 1) py = 1;
-    if (pz < 0) pz = 0; 
-    if (pz > 1) pz = 1;
-
-    px *= p->Domain[0];
-    py *= p->Domain[1];
-    pz *= p->Domain[2];
-
-    x0 = (int) _cmsQuickFloor(px); fx = px - (cmsFloat32Number) x0;
-    y0 = (int) _cmsQuickFloor(py); fy = py - (cmsFloat32Number) y0;
-    z0 = (int) _cmsQuickFloor(pz); fz = pz - (cmsFloat32Number) z0;
-    
-    X0 = p -> opta[2] * x0;
-    X1 = X0 + (Input[0] >= 1.0 ? 0 : p->opta[2]);
-
-    Y0 = p -> opta[1] * y0;
-    Y1 = Y0 + (Input[1] >= 1.0 ? 0 : p->opta[1]);
-   
-    Z0 = p -> opta[0] * z0;
-    Z1 = Z0 + (Input[2] >= 1.0 ? 0 : p->opta[0]);
-   
-    for (OutChan = 0; OutChan < TotalOut; OutChan++) {
-
-        d000 = DENS(X0, Y0, Z0);
-        d001 = DENS(X0, Y0, Z1);
-        d010 = DENS(X0, Y1, Z0);
-        d011 = DENS(X0, Y1, Z1);
-
-        d100 = DENS(X1, Y0, Z0);
-        d101 = DENS(X1, Y0, Z1);
-        d110 = DENS(X1, Y1, Z0);
-        d111 = DENS(X1, Y1, Z1);
-
-
-        dx00 = LERP(fx, d000, d100);
-        dx01 = LERP(fx, d001, d101);
-        dx10 = LERP(fx, d010, d110);
-        dx11 = LERP(fx, d011, d111);
-
-        dxy0 = LERP(fy, dx00, dx10);
-        dxy1 = LERP(fy, dx01, dx11);
-
-        dxyz = LERP(fz, dxy0, dxy1);
-
-        Output[OutChan] = dxyz;
-    }
-
-
-#   undef LERP
-#   undef DENS
-}
-
-// Trilinear interpolation (16 bits) - optimized version
-static
-void TrilinearInterp16(register const cmsUInt16Number Input[], 
-                       register cmsUInt16Number Output[],
-                       register const cmsInterpParams* p)
-
-{
-#define DENS(i,j,k) (LutTable[(i)+(j)+(k)+OutChan])
-#define LERP(a,l,h)     (cmsUInt16Number) (l + ROUND_FIXED_TO_INT(((h-l)*a)))
-
-           const cmsUInt16Number* LutTable = (cmsUInt16Number*) p ->Table; 
-           int        OutChan, TotalOut;
-           cmsS15Fixed16Number    fx, fy, fz;
-  register int        rx, ry, rz;
-           int        x0, y0, z0;
-  register int        X0, X1, Y0, Y1, Z0, Z1;
-           int        d000, d001, d010, d011,
-                      d100, d101, d110, d111,
-                      dx00, dx01, dx10, dx11,
-                      dxy0, dxy1, dxyz;
-
-    TotalOut   = p -> nOutputs;
-
-    fx = _cmsToFixedDomain((int) Input[0] * p -> Domain[0]);
-    x0  = FIXED_TO_INT(fx);
-    rx  = FIXED_REST_TO_INT(fx);    // Rest in 0..1.0 domain
-
-
-    fy = _cmsToFixedDomain((int) Input[1] * p -> Domain[1]);
-    y0  = FIXED_TO_INT(fy);
-    ry  = FIXED_REST_TO_INT(fy);
-
-    fz = _cmsToFixedDomain((int) Input[2] * p -> Domain[2]);
-    z0 = FIXED_TO_INT(fz);
-    rz = FIXED_REST_TO_INT(fz);
-
-
-    X0 = p -> opta[2] * x0;
-    X1 = X0 + (Input[0] == 0xFFFFU ? 0 : p->opta[2]);
-
-    Y0 = p -> opta[1] * y0;
-    Y1 = Y0 + (Input[1] == 0xFFFFU ? 0 : p->opta[1]);
-   
-    Z0 = p -> opta[0] * z0;
-    Z1 = Z0 + (Input[2] == 0xFFFFU ? 0 : p->opta[0]);
-
-    for (OutChan = 0; OutChan < TotalOut; OutChan++) {
-
-        d000 = DENS(X0, Y0, Z0);
-        d001 = DENS(X0, Y0, Z1);
-        d010 = DENS(X0, Y1, Z0);
-        d011 = DENS(X0, Y1, Z1);
-
-        d100 = DENS(X1, Y0, Z0);
-        d101 = DENS(X1, Y0, Z1);
-        d110 = DENS(X1, Y1, Z0);
-        d111 = DENS(X1, Y1, Z1);
-
-
-        dx00 = LERP(rx, d000, d100);
-        dx01 = LERP(rx, d001, d101);
-        dx10 = LERP(rx, d010, d110);
-        dx11 = LERP(rx, d011, d111);
-
-        dxy0 = LERP(ry, dx00, dx10);
-        dxy1 = LERP(ry, dx01, dx11);
-
-        dxyz = LERP(rz, dxy0, dxy1);
-
-        Output[OutChan] = (cmsUInt16Number) dxyz;
-    }
-
-
-#   undef LERP
-#   undef DENS
-}
-
-
-// Tetrahedral interpolation, using Sakamoto algorithm. 
-#define DENS(i,j,k) (LutTable[(i)+(j)+(k)+OutChan])
-static
-void TetrahedralInterpFloat(const cmsFloat32Number Input[], 
-                            cmsFloat32Number Output[],                          
-                            const cmsInterpParams* p)
-{
-    const cmsFloat32Number* LutTable = (cmsFloat32Number*) p -> Table; 
-    cmsFloat32Number     px, py, pz;
-    int        x0, y0, z0,
-               X0, Y0, Z0, X1, Y1, Z1;
-    cmsFloat32Number     rx, ry, rz;
-    cmsFloat32Number     c0, c1=0, c2=0, c3=0;
-    int                  OutChan, TotalOut;
-
-    TotalOut   = p -> nOutputs;
-
-    // We need some clipping here
-    px = Input[0];
-    py = Input[1];
-    pz = Input[2];
-
-    if (px < 0) px = 0; 
-    if (px > 1) px = 1;
-    if (py < 0) py = 0; 
-    if (py > 1) py = 1;
-    if (pz < 0) pz = 0; 
-    if (pz > 1) pz = 1;
-
-    px *= p->Domain[0];
-    py *= p->Domain[1];
-    pz *= p->Domain[2];
-
-    x0 = (int) _cmsQuickFloor(px); rx = (px - (cmsFloat32Number) x0);
-    y0 = (int) _cmsQuickFloor(py); ry = (py - (cmsFloat32Number) y0);
-    z0 = (int) _cmsQuickFloor(pz); rz = (pz - (cmsFloat32Number) z0);
-
-
-    X0 = p -> opta[2] * x0;
-    X1 = X0 + (Input[0] >= 1.0 ? 0 : p->opta[2]);
-
-    Y0 = p -> opta[1] * y0;
-    Y1 = Y0 + (Input[1] >= 1.0 ? 0 : p->opta[1]);
-   
-    Z0 = p -> opta[0] * z0;
-    Z1 = Z0 + (Input[2] >= 1.0 ? 0 : p->opta[0]);
-   
-    for (OutChan=0; OutChan < TotalOut; OutChan++) {
-
-       // These are the 6 Tetrahedral
-
-        c0 = DENS(X0, Y0, Z0);
-
-        if (rx >= ry && ry >= rz) {
-
-            c1 = DENS(X1, Y0, Z0) - c0;
-            c2 = DENS(X1, Y1, Z0) - DENS(X1, Y0, Z0);
-            c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);
-
-        }
-        else
-            if (rx >= rz && rz >= ry) {            
-
-                c1 = DENS(X1, Y0, Z0) - c0;
-                c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);
-                c3 = DENS(X1, Y0, Z1) - DENS(X1, Y0, Z0);
-
-            }
-            else
-                if (rz >= rx && rx >= ry) {
-
-                    c1 = DENS(X1, Y0, Z1) - DENS(X0, Y0, Z1);
-                    c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);
-                    c3 = DENS(X0, Y0, Z1) - c0;                            
-
-                }
-                else
-                    if (ry >= rx && rx >= rz) {
-
-                        c1 = DENS(X1, Y1, Z0) - DENS(X0, Y1, Z0);
-                        c2 = DENS(X0, Y1, Z0) - c0;
-                        c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);
-
-                    }
-                    else
-                        if (ry >= rz && rz >= rx) {
-
-                            c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);
-                            c2 = DENS(X0, Y1, Z0) - c0;
-                            c3 = DENS(X0, Y1, Z1) - DENS(X0, Y1, Z0);
-
-                        }
-                        else
-                            if (rz >= ry && ry >= rx) {             
-
-                                c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);
-                                c2 = DENS(X0, Y1, Z1) - DENS(X0, Y0, Z1);
-                                c3 = DENS(X0, Y0, Z1) - c0;
-
-                            }
-                            else  {
-                                c1 = c2 = c3 = 0;                               
-                            }
-
-       Output[OutChan] = c0 + c1 * rx + c2 * ry + c3 * rz;
-       }
-
-}
-
-#undef DENS
-
-
-
-#define DENS(i,j,k) (LutTable[(i)+(j)+(k)+OutChan])
-
-static
-void TetrahedralInterp16(register const cmsUInt16Number Input[],
-                         register cmsUInt16Number Output[],
-                         register const cmsInterpParams* p)
-{
-    const cmsUInt16Number* LutTable = (cmsUInt16Number*) p -> Table;
-    cmsS15Fixed16Number    fx, fy, fz;
-    cmsS15Fixed16Number    rx, ry, rz;
-    int                    x0, y0, z0;
-    cmsS15Fixed16Number    c0, c1, c2, c3, Rest;       
-    cmsUInt32Number        OutChan;
-    cmsS15Fixed16Number    X0, X1, Y0, Y1, Z0, Z1;
-    cmsUInt32Number        TotalOut = p -> nOutputs;
-    
-
-    fx  = _cmsToFixedDomain((int) Input[0] * p -> Domain[0]);
-    fy  = _cmsToFixedDomain((int) Input[1] * p -> Domain[1]);
-    fz  = _cmsToFixedDomain((int) Input[2] * p -> Domain[2]);
-
-    x0  = FIXED_TO_INT(fx);
-    y0  = FIXED_TO_INT(fy); 
-    z0  = FIXED_TO_INT(fz);
-
-    rx  = FIXED_REST_TO_INT(fx);   
-    ry  = FIXED_REST_TO_INT(fy);      
-    rz  = FIXED_REST_TO_INT(fz);
-
-    X0 = p -> opta[2] * x0;
-    X1 = X0 + (Input[0] == 0xFFFFU ? 0 : p->opta[2]);
-
-    Y0 = p -> opta[1] * y0;
-    Y1 = Y0 + (Input[1] == 0xFFFFU ? 0 : p->opta[1]);
-
-    Z0 = p -> opta[0] * z0;
-    Z1 = Z0 + (Input[2] == 0xFFFFU ? 0 : p->opta[0]);
-
-    // These are the 6 Tetrahedral
-    for (OutChan=0; OutChan < TotalOut; OutChan++) {
-
-        c0 = DENS(X0, Y0, Z0);
-
-        if (rx >= ry && ry >= rz) {
-
-            c1 = DENS(X1, Y0, Z0) - c0;
-            c2 = DENS(X1, Y1, Z0) - DENS(X1, Y0, Z0);
-            c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);
-
-        }
-        else
-            if (rx >= rz && rz >= ry) {            
-
-                c1 = DENS(X1, Y0, Z0) - c0;
-                c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);
-                c3 = DENS(X1, Y0, Z1) - DENS(X1, Y0, Z0);
-
-            }
-            else
-                if (rz >= rx && rx >= ry) {
-
-                    c1 = DENS(X1, Y0, Z1) - DENS(X0, Y0, Z1);
-                    c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);
-                    c3 = DENS(X0, Y0, Z1) - c0;                            
-
-                }
-                else
-                    if (ry >= rx && rx >= rz) {
-
-                        c1 = DENS(X1, Y1, Z0) - DENS(X0, Y1, Z0);
-                        c2 = DENS(X0, Y1, Z0) - c0;
-                        c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);
-
-                    }
-                    else
-                        if (ry >= rz && rz >= rx) {
-
-                            c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);
-                            c2 = DENS(X0, Y1, Z0) - c0;
-                            c3 = DENS(X0, Y1, Z1) - DENS(X0, Y1, Z0);
-
-                        }
-                        else
-                            if (rz >= ry && ry >= rx) {             
-
-                                c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);
-                                c2 = DENS(X0, Y1, Z1) - DENS(X0, Y0, Z1);
-                                c3 = DENS(X0, Y0, Z1) - c0;
-
-                            }
-                            else  {
-                                c1 = c2 = c3 = 0;                               
-                            }
-
-                            Rest = c1 * rx + c2 * ry + c3 * rz;                
-
-                            Output[OutChan] = (cmsUInt16Number) c0 + ROUND_FIXED_TO_INT(_cmsToFixedDomain(Rest));
-    }
-
-}
-#undef DENS
-
-
-#define DENS(i,j,k) (LutTable[(i)+(j)+(k)+OutChan])
-static
-void Eval4Inputs(register const cmsUInt16Number Input[], 
-                     register cmsUInt16Number Output[], 
-                     register const cmsInterpParams* p16)
-{                        
-    const cmsUInt16Number* LutTable = (cmsUInt16Number*) p16 -> Table; 
-    cmsS15Fixed16Number fk;
-    cmsS15Fixed16Number k0, rk;
-    int K0, K1;
-    cmsS15Fixed16Number    fx, fy, fz;
-    cmsS15Fixed16Number    rx, ry, rz;
-    int                    x0, y0, z0;
-    cmsS15Fixed16Number    X0, X1, Y0, Y1, Z0, Z1;
-    cmsUInt32Number i;
-    cmsS15Fixed16Number    c0, c1, c2, c3, Rest;       
-    cmsUInt32Number        OutChan;
-    cmsUInt16Number        Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS];
-
-
-    fk  = _cmsToFixedDomain((int) Input[0] * p16 -> Domain[0]);
-    fx  = _cmsToFixedDomain((int) Input[1] * p16 -> Domain[1]);
-    fy  = _cmsToFixedDomain((int) Input[2] * p16 -> Domain[2]);
-    fz  = _cmsToFixedDomain((int) Input[3] * p16 -> Domain[3]);
-
-    k0  = FIXED_TO_INT(fk);     
-    x0  = FIXED_TO_INT(fx);
-    y0  = FIXED_TO_INT(fy); 
-    z0  = FIXED_TO_INT(fz);
-
-    rk  = FIXED_REST_TO_INT(fk);
-    rx  = FIXED_REST_TO_INT(fx);   
-    ry  = FIXED_REST_TO_INT(fy);      
-    rz  = FIXED_REST_TO_INT(fz);
-
-    K0 = p16 -> opta[3] * k0;
-    K1 = K0 + (Input[0] == 0xFFFFU ? 0 : p16->opta[3]);
-
-    X0 = p16 -> opta[2] * x0;
-    X1 = X0 + (Input[1] == 0xFFFFU ? 0 : p16->opta[2]);
-
-    Y0 = p16 -> opta[1] * y0;
-    Y1 = Y0 + (Input[2] == 0xFFFFU ? 0 : p16->opta[1]);
-
-    Z0 = p16 -> opta[0] * z0;
-    Z1 = Z0 + (Input[3] == 0xFFFFU ? 0 : p16->opta[0]);
-
-    LutTable = (cmsUInt16Number*) p16 -> Table;
-    LutTable += K0;
-
-    for (OutChan=0; OutChan < p16 -> nOutputs; OutChan++) {
-
-        c0 = DENS(X0, Y0, Z0);
-
-        if (rx >= ry && ry >= rz) {
-
-            c1 = DENS(X1, Y0, Z0) - c0;
-            c2 = DENS(X1, Y1, Z0) - DENS(X1, Y0, Z0);
-            c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);
-
-        }
-        else
-            if (rx >= rz && rz >= ry) {            
-
-                c1 = DENS(X1, Y0, Z0) - c0;
-                c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);
-                c3 = DENS(X1, Y0, Z1) - DENS(X1, Y0, Z0);
-
-            }
-            else
-                if (rz >= rx && rx >= ry) {
-
-                    c1 = DENS(X1, Y0, Z1) - DENS(X0, Y0, Z1);
-                    c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);
-                    c3 = DENS(X0, Y0, Z1) - c0;                            
-
-                }
-                else
-                    if (ry >= rx && rx >= rz) {
-
-                        c1 = DENS(X1, Y1, Z0) - DENS(X0, Y1, Z0);
-                        c2 = DENS(X0, Y1, Z0) - c0;
-                        c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);
-
-                    }
-                    else
-                        if (ry >= rz && rz >= rx) {
-
-                            c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);
-                            c2 = DENS(X0, Y1, Z0) - c0;
-                            c3 = DENS(X0, Y1, Z1) - DENS(X0, Y1, Z0);
-
-                        }
-                        else
-                            if (rz >= ry && ry >= rx) {             
-
-                                c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);
-                                c2 = DENS(X0, Y1, Z1) - DENS(X0, Y0, Z1);
-                                c3 = DENS(X0, Y0, Z1) - c0;
-
-                            }
-                            else  {
-                                c1 = c2 = c3 = 0;                               
-                            }
-
-                            Rest = c1 * rx + c2 * ry + c3 * rz;                
-
-                            Tmp1[OutChan] = (cmsUInt16Number) c0 + ROUND_FIXED_TO_INT(_cmsToFixedDomain(Rest));
-    }
-
-
-    LutTable = (cmsUInt16Number*) p16 -> Table;
-    LutTable += K1;
-
-    for (OutChan=0; OutChan < p16 -> nOutputs; OutChan++) {
-
-        c0 = DENS(X0, Y0, Z0);
-
-        if (rx >= ry && ry >= rz) {
-
-            c1 = DENS(X1, Y0, Z0) - c0;
-            c2 = DENS(X1, Y1, Z0) - DENS(X1, Y0, Z0);
-            c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);
-
-        }
-        else
-            if (rx >= rz && rz >= ry) {            
-
-                c1 = DENS(X1, Y0, Z0) - c0;
-                c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);
-                c3 = DENS(X1, Y0, Z1) - DENS(X1, Y0, Z0);
-
-            }
-            else
-                if (rz >= rx && rx >= ry) {
-
-                    c1 = DENS(X1, Y0, Z1) - DENS(X0, Y0, Z1);
-                    c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);
-                    c3 = DENS(X0, Y0, Z1) - c0;                            
-
-                }
-                else
-                    if (ry >= rx && rx >= rz) {
-
-                        c1 = DENS(X1, Y1, Z0) - DENS(X0, Y1, Z0);
-                        c2 = DENS(X0, Y1, Z0) - c0;
-                        c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);
-
-                    }
-                    else
-                        if (ry >= rz && rz >= rx) {
-
-                            c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);
-                            c2 = DENS(X0, Y1, Z0) - c0;
-                            c3 = DENS(X0, Y1, Z1) - DENS(X0, Y1, Z0);
-
-                        }
-                        else
-                            if (rz >= ry && ry >= rx) {             
-
-                                c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);
-                                c2 = DENS(X0, Y1, Z1) - DENS(X0, Y0, Z1);
-                                c3 = DENS(X0, Y0, Z1) - c0;
-
-                            }
-                            else  {
-                                c1 = c2 = c3 = 0;                               
-                            }
-
-                            Rest = c1 * rx + c2 * ry + c3 * rz;                
-
-                            Tmp2[OutChan] = (cmsUInt16Number) c0 + ROUND_FIXED_TO_INT(_cmsToFixedDomain(Rest));
-    }
-
-
-
-    for (i=0; i < p16 -> nOutputs; i++) {
-        Output[i] = LinearInterp(rk, Tmp1[i], Tmp2[i]);              
-    }
-}
-#undef DENS
-
-
-// For more that 3 inputs (i.e., CMYK)
-// evaluate two 3-dimensional interpolations and then linearly interpolate between them.
-
-
-static
-void Eval4InputsFloat(const cmsFloat32Number Input[], 
-                      cmsFloat32Number Output[], 
-                      const cmsInterpParams* p)
-{                             
-       const cmsFloat32Number* LutTable = (cmsFloat32Number*) p -> Table; 
-       cmsFloat32Number rest;
-       cmsFloat32Number pk;
-       int k0, K0, K1;
-       const cmsFloat32Number* T;
-       cmsUInt32Number i;
-       cmsFloat32Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS];
-       cmsInterpParams p1;
-
-       
-       pk = Input[0] * p->Domain[0];    
-       k0 = _cmsQuickFloor(pk); 
-       rest = pk - (cmsFloat32Number) k0;
-
-       K0 = p -> opta[3] * k0;
-       K1 = K0 + (Input[0] >= 1.0 ? 0 : p->opta[3]);
-
-       p1 = *p;
-       memmove(&p1.Domain[0], &p ->Domain[1], 3*sizeof(cmsUInt32Number));
-       
-       T = LutTable + K0;
-       p1.Table = T;
-
-       TetrahedralInterpFloat(Input + 1,  Tmp1, &p1);
-
-       T = LutTable + K1;
-       p1.Table = T;
-       TetrahedralInterpFloat(Input + 1,  Tmp2, &p1);
-
-       for (i=0; i < p -> nOutputs; i++)
-       {
-              cmsFloat32Number y0 = Tmp1[i];
-              cmsFloat32Number y1 = Tmp2[i];
-
-              Output[i] = y0 + (y1 - y0) * rest;               
-       }
-}
-
-
-static
-void Eval5Inputs(register const cmsUInt16Number Input[], 
-                 register cmsUInt16Number Output[], 
-
-                 register const cmsInterpParams* p16)
-{       
-       const cmsUInt16Number* LutTable = (cmsUInt16Number*) p16 -> Table;  
-       cmsS15Fixed16Number fk;
-       cmsS15Fixed16Number k0, rk;
-       int K0, K1;
-       const cmsUInt16Number* T;
-       cmsUInt32Number i;
-       cmsUInt16Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS];
-       cmsInterpParams p1;
-
-       
-       fk = _cmsToFixedDomain((cmsS15Fixed16Number) Input[0] * p16 -> Domain[0]);
-       k0 = FIXED_TO_INT(fk);
-       rk = FIXED_REST_TO_INT(fk);
-
-       K0 = p16 -> opta[4] * k0;
-       K1 = p16 -> opta[4] * (k0 + (Input[0] != 0xFFFFU ? 1 : 0));
-
-       p1 = *p16;
-       memmove(&p1.Domain[0], &p16 ->Domain[1], 4*sizeof(cmsUInt32Number));
-
-       T = LutTable + K0;
-       p1.Table = T;
-
-       Eval4Inputs(Input + 1, Tmp1, &p1);
-
-       T = LutTable + K1;
-       p1.Table = T;
-
-       Eval4Inputs(Input + 1, Tmp2, &p1);
-
-       for (i=0; i < p16 -> nOutputs; i++) {
-
-              Output[i] = LinearInterp(rk, Tmp1[i], Tmp2[i]);                         
-       }
-
-}
-
-
-static
-void Eval5InputsFloat(const cmsFloat32Number Input[], 
-                      cmsFloat32Number Output[], 
-                      const cmsInterpParams* p)
-{                             
-       const cmsFloat32Number* LutTable = (cmsFloat32Number*) p -> Table; 
-       cmsFloat32Number rest;
-       cmsFloat32Number pk;
-       int k0, K0, K1;
-       const cmsFloat32Number* T;
-       cmsUInt32Number i;
-       cmsFloat32Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS];
-       cmsInterpParams p1;
-
-       pk = Input[0] * p->Domain[0];    
-       k0 = _cmsQuickFloor(pk); 
-       rest = pk - (cmsFloat32Number) k0;
-
-       K0 = p -> opta[4] * k0;
-       K1 = K0 + (Input[0] >= 1.0 ? 0 : p->opta[4]);
-
-       p1 = *p;
-       memmove(&p1.Domain[0], &p ->Domain[1], 4*sizeof(cmsUInt32Number));
-
-       T = LutTable + K0;
-       p1.Table = T;
-       
-       Eval4InputsFloat(Input + 1,  Tmp1, &p1);
-      
-       T = LutTable + K1;
-       p1.Table = T;
-
-       Eval4InputsFloat(Input + 1,  Tmp2, &p1);
-      
-       for (i=0; i < p -> nOutputs; i++) {
-
-              cmsFloat32Number y0 = Tmp1[i];
-              cmsFloat32Number y1 = Tmp2[i];
-
-              Output[i] = y0 + (y1 - y0) * rest;             
-       }
-}
-
-
-
-static
-void Eval6Inputs(register const cmsUInt16Number Input[], 
-                 register cmsUInt16Number Output[], 
-                 register const cmsInterpParams* p16)
-{       
-       const cmsUInt16Number* LutTable = (cmsUInt16Number*) p16 -> Table; 
-       cmsS15Fixed16Number fk;
-       cmsS15Fixed16Number k0, rk;
-       int K0, K1;
-       const cmsUInt16Number* T;
-       cmsUInt32Number i;
-       cmsUInt16Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS];
-       cmsInterpParams p1;
-       
-       fk = _cmsToFixedDomain((cmsS15Fixed16Number) Input[0] * p16 -> Domain[0]);
-       k0 = FIXED_TO_INT(fk);
-       rk = FIXED_REST_TO_INT(fk);
-
-       K0 = p16 -> opta[5] * k0;
-       K1 = p16 -> opta[5] * (k0 + (Input[0] != 0xFFFFU ? 1 : 0));
-
-       p1 = *p16;
-       memmove(&p1.Domain[0], &p16 ->Domain[1], 5*sizeof(cmsUInt32Number));
-
-       T = LutTable + K0;
-       p1.Table = T;
-
-       Eval5Inputs(Input + 1, Tmp1, &p1);
-
-       T = LutTable + K1;
-       p1.Table = T;
-
-       Eval5Inputs(Input + 1, Tmp2, &p1);
-
-       for (i=0; i < p16 -> nOutputs; i++) {
-
-              Output[i] = LinearInterp(rk, Tmp1[i], Tmp2[i]);
-       }
-
-}
-
-
-static
-void Eval6InputsFloat(const cmsFloat32Number Input[], 
-                      cmsFloat32Number Output[], 
-                      const cmsInterpParams* p)
-{                             
-       const cmsFloat32Number* LutTable = (cmsFloat32Number*) p -> Table; 
-       cmsFloat32Number rest;
-       cmsFloat32Number pk;
-       int k0, K0, K1;
-       const cmsFloat32Number* T;
-       cmsUInt32Number i;
-       cmsFloat32Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS];
-       cmsInterpParams p1;
-
-       pk = Input[0] * p->Domain[0];    
-       k0 = _cmsQuickFloor(pk); 
-       rest = pk - (cmsFloat32Number) k0;
-
-       K0 = p -> opta[5] * k0;
-       K1 = K0 + (Input[0] >= 1.0 ? 0 : p->opta[5]);
-
-       p1 = *p;
-       memmove(&p1.Domain[0], &p ->Domain[1], 5*sizeof(cmsUInt32Number));
-       
-       T = LutTable + K0;
-       p1.Table = T;
-  
-       Eval5InputsFloat(Input + 1,  Tmp1, &p1);
-      
-       T = LutTable + K1;
-       p1.Table = T;
-
-       Eval5InputsFloat(Input + 1,  Tmp2, &p1);
-      
-       for (i=0; i < p -> nOutputs; i++) {
-
-              cmsFloat32Number y0 = Tmp1[i];
-              cmsFloat32Number y1 = Tmp2[i];
-
-              Output[i] = y0 + (y1 - y0) * rest;                   
-       }
-}
-
-
-static
-void Eval7Inputs(register const cmsUInt16Number Input[], 
-                 register cmsUInt16Number Output[], 
-                 register const cmsInterpParams* p16)
-{       
-       const cmsUInt16Number* LutTable = (cmsUInt16Number*) p16 -> Table; 
-       cmsS15Fixed16Number fk;
-       cmsS15Fixed16Number k0, rk;
-       int K0, K1;
-       const cmsUInt16Number* T;
-       cmsUInt32Number i;
-       cmsUInt16Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS];
-       cmsInterpParams p1;
-
-       
-       fk = _cmsToFixedDomain((cmsS15Fixed16Number) Input[0] * p16 -> Domain[0]);
-       k0 = FIXED_TO_INT(fk);
-       rk = FIXED_REST_TO_INT(fk);
-
-       K0 = p16 -> opta[6] * k0;
-       K1 = p16 -> opta[6] * (k0 + (Input[0] != 0xFFFFU ? 1 : 0));
-
-       p1 = *p16;
-       memmove(&p1.Domain[0], &p16 ->Domain[1], 6*sizeof(cmsUInt32Number));
-       
-       T = LutTable + K0;
-       p1.Table = T;
-
-       Eval6Inputs(Input + 1, Tmp1, &p1);
-
-       T = LutTable + K1;
-       p1.Table = T;
-
-       Eval6Inputs(Input + 1, Tmp2, &p1);
-
-       for (i=0; i < p16 -> nOutputs; i++) {
-              Output[i] = LinearInterp(rk, Tmp1[i], Tmp2[i]);
-       }
-}
-
-
-static
-void Eval7InputsFloat(const cmsFloat32Number Input[], 
-                      cmsFloat32Number Output[], 
-                      const cmsInterpParams* p)
-{                             
-       const cmsFloat32Number* LutTable = (cmsFloat32Number*) p -> Table; 
-       cmsFloat32Number rest;
-       cmsFloat32Number pk;
-       int k0, K0, K1;
-       const cmsFloat32Number* T;
-       cmsUInt32Number i;
-       cmsFloat32Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS];
-       cmsInterpParams p1;
-
-       pk = Input[0] * p->Domain[0];    
-       k0 = _cmsQuickFloor(pk); 
-       rest = pk - (cmsFloat32Number) k0;
-
-       K0 = p -> opta[6] * k0;
-       K1 = K0 + (Input[0] >= 1.0 ? 0 : p->opta[6]);
-
-       p1 = *p;
-       memmove(&p1.Domain[0], &p ->Domain[1], 6*sizeof(cmsUInt32Number));
-       
-       T = LutTable + K0;
-       p1.Table = T;
-
-       Eval6InputsFloat(Input + 1,  Tmp1, &p1);
-      
-       T = LutTable + K1;
-       p1.Table = T;
-       
-       Eval6InputsFloat(Input + 1,  Tmp2, &p1);
-      
-       
-       for (i=0; i < p -> nOutputs; i++) {
-
-              cmsFloat32Number y0 = Tmp1[i];
-              cmsFloat32Number y1 = Tmp2[i];
-
-              Output[i] = y0 + (y1 - y0) * rest;     
-              
-       }
-}
-
-static
-void Eval8Inputs(register const cmsUInt16Number Input[], 
-                 register cmsUInt16Number Output[], 
-                 register const cmsInterpParams* p16)
-{       
-       const cmsUInt16Number* LutTable = (cmsUInt16Number*) p16 -> Table; 
-       cmsS15Fixed16Number fk;
-       cmsS15Fixed16Number k0, rk;
-       int K0, K1;
-       const cmsUInt16Number* T;
-       cmsUInt32Number i;
-       cmsUInt16Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS];
-       cmsInterpParams p1;
-       
-       fk = _cmsToFixedDomain((cmsS15Fixed16Number) Input[0] * p16 -> Domain[0]);
-       k0 = FIXED_TO_INT(fk);
-       rk = FIXED_REST_TO_INT(fk);
-
-       K0 = p16 -> opta[7] * k0;
-       K1 = p16 -> opta[7] * (k0 + (Input[0] != 0xFFFFU ? 1 : 0));
-
-       p1 = *p16;
-       memmove(&p1.Domain[0], &p16 ->Domain[1], 7*sizeof(cmsUInt32Number));
-       
-       T = LutTable + K0;
-       p1.Table = T;
-
-       Eval7Inputs(Input + 1, Tmp1, &p1);
-
-       T = LutTable + K1;
-       p1.Table = T;
-       Eval7Inputs(Input + 1, Tmp2, &p1);
-
-       for (i=0; i < p16 -> nOutputs; i++) {
-              Output[i] = LinearInterp(rk, Tmp1[i], Tmp2[i]);
-       }
-}
-
-
-
-static
-void Eval8InputsFloat(const cmsFloat32Number Input[], 
-                      cmsFloat32Number Output[], 
-                      const cmsInterpParams* p)
-{                             
-       const cmsFloat32Number* LutTable = (cmsFloat32Number*) p -> Table; 
-       cmsFloat32Number rest;
-       cmsFloat32Number pk;
-       int k0, K0, K1;
-       const cmsFloat32Number* T;
-       cmsUInt32Number i;
-       cmsFloat32Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS];
-       cmsInterpParams p1;
-       
-       pk = Input[0] * p->Domain[0];    
-       k0 = _cmsQuickFloor(pk); 
-       rest = pk - (cmsFloat32Number) k0;
-
-       K0 = p -> opta[7] * k0;
-       K1 = K0 + (Input[0] >= 1.0 ? 0 : p->opta[7]);
-
-       p1 = *p;
-       memmove(&p1.Domain[0], &p ->Domain[1], 7*sizeof(cmsUInt32Number));
-
-       T = LutTable + K0;
-       p1.Table = T;
-
-       Eval7InputsFloat(Input + 1,  Tmp1, &p1);
-      
-       T = LutTable + K1;
-       p1.Table = T;
-
-       Eval7InputsFloat(Input + 1,  Tmp2, &p1);
-      
-
-       for (i=0; i < p -> nOutputs; i++) {
-
-              cmsFloat32Number y0 = Tmp1[i];
-              cmsFloat32Number y1 = Tmp2[i];
-
-              Output[i] = y0 + (y1 - y0) * rest;                   
-       }
-}
-
-// The default factory
-static 
-cmsInterpFunction DefaultInterpolatorsFactory(cmsUInt32Number nInputChannels, cmsUInt32Number nOutputChannels, cmsUInt32Number dwFlags)
-{
-
-    cmsInterpFunction Interpolation;
-    cmsBool  IsFloat     = (dwFlags & CMS_LERP_FLAGS_FLOAT);
-    cmsBool  IsTrilinear = (dwFlags & CMS_LERP_FLAGS_TRILINEAR);
-
-    memset(&Interpolation, 0, sizeof(Interpolation));
-
-    // Safety check
-    if (nInputChannels >= 4 && nOutputChannels >= MAX_STAGE_CHANNELS) 
-        return Interpolation;
-
-    switch (nInputChannels) {
-
-           case 1: // Gray LUT / linear
-
-               if (nOutputChannels == 1) {
-
-                   if (IsFloat) 
-                       Interpolation.LerpFloat = LinLerp1Dfloat;
-                   else
-                       Interpolation.Lerp16 = LinLerp1D;
-
-               }
-               else {
-
-                   if (IsFloat)
-                       Interpolation.LerpFloat = Eval1InputFloat;               
-                   else
-                       Interpolation.Lerp16 = Eval1Input;               
-               }
-               break;
-
-           case 2: // Duotone
-               if (IsFloat) 
-                      Interpolation.LerpFloat =  BilinearInterpFloat;
-               else
-                      Interpolation.Lerp16    =  BilinearInterp16;
-               break;
-
-           case 3:  // RGB et al   
-
-               if (IsTrilinear) {
-
-                   if (IsFloat) 
-                       Interpolation.LerpFloat = TrilinearInterpFloat;
-                   else
-                       Interpolation.Lerp16 = TrilinearInterp16;
-               }
-               else {
-
-                   if (IsFloat) 
-                       Interpolation.LerpFloat = TetrahedralInterpFloat;
-                   else {
-
-                       Interpolation.Lerp16 = TetrahedralInterp16;
-                   }
-               }
-               break;
-
-           case 4:  // CMYK lut             
-
-               if (IsFloat) 
-                   Interpolation.LerpFloat =  Eval4InputsFloat;
-               else
-                   Interpolation.Lerp16    =  Eval4Inputs;
-               break;
-
-           case 5: // 5 Inks
-               if (IsFloat) 
-                   Interpolation.LerpFloat =  Eval5InputsFloat;
-               else
-                   Interpolation.Lerp16    =  Eval5Inputs;
-               break;              
-
-           case 6: // 6 Inks
-               if (IsFloat) 
-                   Interpolation.LerpFloat =  Eval6InputsFloat;
-               else
-                   Interpolation.Lerp16    =  Eval6Inputs;
-               break;
-
-           case 7: // 7 inks
-               if (IsFloat) 
-                   Interpolation.LerpFloat =  Eval7InputsFloat;
-               else
-                   Interpolation.Lerp16    =  Eval7Inputs;
-               break;
-
-           case 8: // 8 inks
-               if (IsFloat) 
-                   Interpolation.LerpFloat =  Eval8InputsFloat;
-               else
-                   Interpolation.Lerp16    =  Eval8Inputs;
-               break;
-
-               break;
-
-           default:
-               Interpolation.Lerp16 = NULL;
-    }
-
-    return Interpolation;
-}
+//---------------------------------------------------------------------------------\r
+//\r
+//  Little Color Management System\r
+//  Copyright (c) 1998-2012 Marti Maria Saguer\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining\r
+// a copy of this software and associated documentation files (the "Software"),\r
+// to deal in the Software without restriction, including without limitation\r
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+// and/or sell copies of the Software, and to permit persons to whom the Software\r
+// is furnished to do so, subject to the following conditions:\r
+//\r
+// The above copyright notice and this permission notice shall be included in\r
+// all copies or substantial portions of the Software.\r
+//\r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO\r
+// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+//---------------------------------------------------------------------------------\r
+//\r
+\r
+#include "lcms2_internal.h"\r
+\r
+// This module incorporates several interpolation routines, for 1 to 8 channels on input and\r
+// up to 65535 channels on output. The user may change those by using the interpolation plug-in\r
+\r
+// Interpolation routines by default\r
+static cmsInterpFunction DefaultInterpolatorsFactory(cmsUInt32Number nInputChannels, cmsUInt32Number nOutputChannels, cmsUInt32Number dwFlags);\r
+\r
+// This is the default factory\r
+static cmsInterpFnFactory Interpolators = DefaultInterpolatorsFactory;\r
+\r
+\r
+// Main plug-in entry\r
+cmsBool  _cmsRegisterInterpPlugin(cmsPluginBase* Data)\r
+{\r
+    cmsPluginInterpolation* Plugin = (cmsPluginInterpolation*) Data;\r
+\r
+    if (Data == NULL) {\r
+\r
+        Interpolators = DefaultInterpolatorsFactory;\r
+        return TRUE;\r
+    }\r
+\r
+    // Set replacement functions\r
+    Interpolators = Plugin ->InterpolatorsFactory;\r
+    return TRUE;\r
+}\r
+\r
+\r
+// Set the interpolation method\r
+\r
+cmsBool _cmsSetInterpolationRoutine(cmsInterpParams* p)\r
+{\r
+    // Invoke factory, possibly in the Plug-in\r
+    p ->Interpolation = Interpolators(p -> nInputs, p ->nOutputs, p ->dwFlags);\r
+\r
+    // If unsupported by the plug-in, go for the LittleCMS default.\r
+    // If happens only if an extern plug-in is being used\r
+    if (p ->Interpolation.Lerp16 == NULL)\r
+        p ->Interpolation = DefaultInterpolatorsFactory(p ->nInputs, p ->nOutputs, p ->dwFlags);\r
+\r
+    // Check for valid interpolator (we just check one member of the union)\r
+    if (p ->Interpolation.Lerp16 == NULL) {\r
+            return FALSE;\r
+    }\r
+    return TRUE;\r
+}\r
+\r
+\r
+// This function precalculates as many parameters as possible to speed up the interpolation.\r
+cmsInterpParams* _cmsComputeInterpParamsEx(cmsContext ContextID,\r
+                                           const cmsUInt32Number nSamples[],\r
+                                           int InputChan, int OutputChan,\r
+                                           const void *Table,\r
+                                           cmsUInt32Number dwFlags)\r
+{\r
+    cmsInterpParams* p;\r
+    int i;\r
+\r
+    // Check for maximum inputs\r
+    if (InputChan > MAX_INPUT_DIMENSIONS) {\r
+             cmsSignalError(ContextID, cmsERROR_RANGE, "Too many input channels (%d channels, max=%d)", InputChan, MAX_INPUT_DIMENSIONS);\r
+            return NULL;\r
+    }\r
+\r
+    // Creates an empty object\r
+    p = (cmsInterpParams*) _cmsMallocZero(ContextID, sizeof(cmsInterpParams));\r
+    if (p == NULL) return NULL;\r
+\r
+    // Keep original parameters\r
+    p -> dwFlags  = dwFlags;\r
+    p -> nInputs  = InputChan;\r
+    p -> nOutputs = OutputChan;\r
+    p ->Table     = Table;\r
+    p ->ContextID  = ContextID;\r
+\r
+    // Fill samples per input direction and domain (which is number of nodes minus one)\r
+    for (i=0; i < InputChan; i++) {\r
+\r
+        p -> nSamples[i] = nSamples[i];\r
+        p -> Domain[i]   = nSamples[i] - 1;\r
+    }\r
+\r
+    // Compute factors to apply to each component to index the grid array\r
+    p -> opta[0] = p -> nOutputs;\r
+    for (i=1; i < InputChan; i++)\r
+        p ->opta[i] = p ->opta[i-1] * nSamples[InputChan-i];\r
+\r
+\r
+    if (!_cmsSetInterpolationRoutine(p)) {\r
+         cmsSignalError(ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unsupported interpolation (%d->%d channels)", InputChan, OutputChan);\r
+        _cmsFree(ContextID, p);\r
+        return NULL;\r
+    }\r
+\r
+    // All seems ok\r
+    return p;\r
+}\r
+\r
+\r
+// This one is a wrapper on the anterior, but assuming all directions have same number of nodes\r
+cmsInterpParams* _cmsComputeInterpParams(cmsContext ContextID, int nSamples, int InputChan, int OutputChan, const void* Table, cmsUInt32Number dwFlags)\r
+{\r
+    int i;\r
+    cmsUInt32Number Samples[MAX_INPUT_DIMENSIONS];\r
+\r
+    // Fill the auxiliar array\r
+    for (i=0; i < MAX_INPUT_DIMENSIONS; i++)\r
+        Samples[i] = nSamples;\r
+\r
+    // Call the extended function\r
+    return _cmsComputeInterpParamsEx(ContextID, Samples, InputChan, OutputChan, Table, dwFlags);\r
+}\r
+\r
+\r
+// Free all associated memory\r
+void _cmsFreeInterpParams(cmsInterpParams* p)\r
+{\r
+    if (p != NULL) _cmsFree(p ->ContextID, p);\r
+}\r
+\r
+\r
+// Inline fixed point interpolation\r
+cmsINLINE cmsUInt16Number LinearInterp(cmsS15Fixed16Number a, cmsS15Fixed16Number l, cmsS15Fixed16Number h)\r
+{\r
+    cmsUInt32Number dif = (cmsUInt32Number) (h - l) * a + 0x8000;\r
+    dif = (dif >> 16) + l;\r
+    return (cmsUInt16Number) (dif);\r
+}\r
+\r
+\r
+//  Linear interpolation (Fixed-point optimized)\r
+static\r
+void LinLerp1D(register const cmsUInt16Number Value[],\r
+               register cmsUInt16Number Output[],\r
+               register const cmsInterpParams* p)\r
+{\r
+    cmsUInt16Number y1, y0;\r
+    int cell0, rest;\r
+    int val3;\r
+    const cmsUInt16Number* LutTable = (cmsUInt16Number*) p ->Table;\r
+\r
+    // if last value...\r
+    if (Value[0] == 0xffff) {\r
+\r
+        Output[0] = LutTable[p -> Domain[0]];\r
+        return;\r
+    }\r
+\r
+    val3 = p -> Domain[0] * Value[0];\r
+    val3 = _cmsToFixedDomain(val3);    // To fixed 15.16\r
+\r
+    cell0 = FIXED_TO_INT(val3);             // Cell is 16 MSB bits\r
+    rest  = FIXED_REST_TO_INT(val3);        // Rest is 16 LSB bits\r
+\r
+    y0 = LutTable[cell0];\r
+    y1 = LutTable[cell0+1];\r
+\r
+\r
+    Output[0] = LinearInterp(rest, y0, y1);\r
+}\r
+\r
+\r
+// Floating-point version of 1D interpolation\r
+static\r
+void LinLerp1Dfloat(const cmsFloat32Number Value[],\r
+                    cmsFloat32Number Output[],\r
+                    const cmsInterpParams* p)\r
+{\r
+       cmsFloat32Number y1, y0;\r
+       cmsFloat32Number val2, rest;\r
+       int cell0, cell1;\r
+       const cmsFloat32Number* LutTable = (cmsFloat32Number*) p ->Table;\r
+\r
+       // if last value...\r
+       if (Value[0] == 1.0) {\r
+           Output[0] = LutTable[p -> Domain[0]];\r
+           return;\r
+       }\r
+\r
+       val2 = p -> Domain[0] * Value[0];\r
+\r
+       cell0 = (int) floor(val2);\r
+       cell1 = (int) ceil(val2);\r
+\r
+       // Rest is 16 LSB bits\r
+       rest = val2 - cell0;\r
+\r
+       y0 = LutTable[cell0] ;\r
+       y1 = LutTable[cell1] ;\r
+\r
+       Output[0] = y0 + (y1 - y0) * rest;\r
+}\r
+\r
+\r
+\r
+// Eval gray LUT having only one input channel\r
+static\r
+void Eval1Input(register const cmsUInt16Number Input[],\r
+                register cmsUInt16Number Output[],\r
+                register const cmsInterpParams* p16)\r
+{\r
+       cmsS15Fixed16Number fk;\r
+       cmsS15Fixed16Number k0, k1, rk, K0, K1;\r
+       int v;\r
+       cmsUInt32Number OutChan;\r
+       const cmsUInt16Number* LutTable = (cmsUInt16Number*) p16 -> Table;\r
+\r
+       v = Input[0] * p16 -> Domain[0];\r
+       fk = _cmsToFixedDomain(v);\r
+\r
+       k0 = FIXED_TO_INT(fk);\r
+       rk = (cmsUInt16Number) FIXED_REST_TO_INT(fk);\r
+\r
+       k1 = k0 + (Input[0] != 0xFFFFU ? 1 : 0);\r
+\r
+       K0 = p16 -> opta[0] * k0;\r
+       K1 = p16 -> opta[0] * k1;\r
+\r
+       for (OutChan=0; OutChan < p16->nOutputs; OutChan++) {\r
+\r
+           Output[OutChan] = LinearInterp(rk, LutTable[K0+OutChan], LutTable[K1+OutChan]);\r
+       }\r
+}\r
+\r
+\r
+\r
+// Eval gray LUT having only one input channel\r
+static\r
+void Eval1InputFloat(const cmsFloat32Number Value[],\r
+                     cmsFloat32Number Output[],\r
+                     const cmsInterpParams* p)\r
+{\r
+    cmsFloat32Number y1, y0;\r
+    cmsFloat32Number val2, rest;\r
+    int cell0, cell1;\r
+    cmsUInt32Number OutChan;\r
+    const cmsFloat32Number* LutTable = (cmsFloat32Number*) p ->Table;\r
+\r
+        // if last value...\r
+       if (Value[0] == 1.0) {\r
+           Output[0] = LutTable[p -> Domain[0]];\r
+           return;\r
+       }\r
+\r
+       val2 = p -> Domain[0] * Value[0];\r
+\r
+       cell0 = (int) floor(val2);\r
+       cell1 = (int) ceil(val2);\r
+\r
+       // Rest is 16 LSB bits\r
+       rest = val2 - cell0;\r
+\r
+       cell0 *= p -> opta[0];\r
+       cell1 *= p -> opta[0];\r
+\r
+       for (OutChan=0; OutChan < p->nOutputs; OutChan++) {\r
+\r
+            y0 = LutTable[cell0 + OutChan] ;\r
+            y1 = LutTable[cell1 + OutChan] ;\r
+\r
+            Output[OutChan] = y0 + (y1 - y0) * rest;\r
+       }\r
+}\r
+\r
+// Bilinear interpolation (16 bits) - cmsFloat32Number version\r
+static\r
+void BilinearInterpFloat(const cmsFloat32Number Input[],\r
+                         cmsFloat32Number Output[],\r
+                         const cmsInterpParams* p)\r
+\r
+{\r
+#   define LERP(a,l,h)    (cmsFloat32Number) ((l)+(((h)-(l))*(a)))\r
+#   define DENS(i,j)      (LutTable[(i)+(j)+OutChan])\r
+\r
+    const cmsFloat32Number* LutTable = (cmsFloat32Number*) p ->Table;\r
+    cmsFloat32Number      px, py;\r
+    int        x0, y0,\r
+               X0, Y0, X1, Y1;\r
+    int        TotalOut, OutChan;\r
+    cmsFloat32Number      fx, fy,\r
+        d00, d01, d10, d11,\r
+        dx0, dx1,\r
+        dxy;\r
+\r
+    TotalOut   = p -> nOutputs;\r
+    px = Input[0] * p->Domain[0];\r
+    py = Input[1] * p->Domain[1];\r
+\r
+    x0 = (int) _cmsQuickFloor(px); fx = px - (cmsFloat32Number) x0;\r
+    y0 = (int) _cmsQuickFloor(py); fy = py - (cmsFloat32Number) y0;\r
+\r
+    X0 = p -> opta[1] * x0;\r
+    X1 = X0 + (Input[0] >= 1.0 ? 0 : p->opta[1]);\r
+\r
+    Y0 = p -> opta[0] * y0;\r
+    Y1 = Y0 + (Input[1] >= 1.0 ? 0 : p->opta[0]);\r
+\r
+    for (OutChan = 0; OutChan < TotalOut; OutChan++) {\r
+\r
+        d00 = DENS(X0, Y0);\r
+        d01 = DENS(X0, Y1);\r
+        d10 = DENS(X1, Y0);\r
+        d11 = DENS(X1, Y1);\r
+\r
+        dx0 = LERP(fx, d00, d10);\r
+        dx1 = LERP(fx, d01, d11);\r
+\r
+        dxy = LERP(fy, dx0, dx1);\r
+\r
+        Output[OutChan] = dxy;\r
+    }\r
+\r
+\r
+#   undef LERP\r
+#   undef DENS\r
+}\r
+\r
+// Bilinear interpolation (16 bits) - optimized version\r
+static\r
+void BilinearInterp16(register const cmsUInt16Number Input[],\r
+                      register cmsUInt16Number Output[],\r
+                      register const cmsInterpParams* p)\r
+\r
+{\r
+#define DENS(i,j) (LutTable[(i)+(j)+OutChan])\r
+#define LERP(a,l,h)     (cmsUInt16Number) (l + ROUND_FIXED_TO_INT(((h-l)*a)))\r
+\r
+           const cmsUInt16Number* LutTable = (cmsUInt16Number*) p ->Table;\r
+           int        OutChan, TotalOut;\r
+           cmsS15Fixed16Number    fx, fy;\r
+  register int        rx, ry;\r
+           int        x0, y0;\r
+  register int        X0, X1, Y0, Y1;\r
+           int        d00, d01, d10, d11,\r
+                      dx0, dx1,\r
+                      dxy;\r
+\r
+    TotalOut   = p -> nOutputs;\r
+\r
+    fx = _cmsToFixedDomain((int) Input[0] * p -> Domain[0]);\r
+    x0  = FIXED_TO_INT(fx);\r
+    rx  = FIXED_REST_TO_INT(fx);    // Rest in 0..1.0 domain\r
+\r
+\r
+    fy = _cmsToFixedDomain((int) Input[1] * p -> Domain[1]);\r
+    y0  = FIXED_TO_INT(fy);\r
+    ry  = FIXED_REST_TO_INT(fy);\r
+\r
+\r
+    X0 = p -> opta[1] * x0;\r
+    X1 = X0 + (Input[0] == 0xFFFFU ? 0 : p->opta[1]);\r
+\r
+    Y0 = p -> opta[0] * y0;\r
+    Y1 = Y0 + (Input[1] == 0xFFFFU ? 0 : p->opta[0]);\r
+\r
+    for (OutChan = 0; OutChan < TotalOut; OutChan++) {\r
+\r
+        d00 = DENS(X0, Y0);\r
+        d01 = DENS(X0, Y1);\r
+        d10 = DENS(X1, Y0);\r
+        d11 = DENS(X1, Y1);\r
+\r
+        dx0 = LERP(rx, d00, d10);\r
+        dx1 = LERP(rx, d01, d11);\r
+\r
+        dxy = LERP(ry, dx0, dx1);\r
+\r
+        Output[OutChan] = (cmsUInt16Number) dxy;\r
+    }\r
+\r
+\r
+#   undef LERP\r
+#   undef DENS\r
+}\r
+\r
+\r
+// Trilinear interpolation (16 bits) - cmsFloat32Number version\r
+static\r
+void TrilinearInterpFloat(const cmsFloat32Number Input[],\r
+                          cmsFloat32Number Output[],\r
+                          const cmsInterpParams* p)\r
+\r
+{\r
+#   define LERP(a,l,h)      (cmsFloat32Number) ((l)+(((h)-(l))*(a)))\r
+#   define DENS(i,j,k)      (LutTable[(i)+(j)+(k)+OutChan])\r
+\r
+    const cmsFloat32Number* LutTable = (cmsFloat32Number*) p ->Table;\r
+    cmsFloat32Number      px, py, pz;\r
+    int        x0, y0, z0,\r
+               X0, Y0, Z0, X1, Y1, Z1;\r
+    int        TotalOut, OutChan;\r
+    cmsFloat32Number      fx, fy, fz,\r
+        d000, d001, d010, d011,\r
+        d100, d101, d110, d111,\r
+        dx00, dx01, dx10, dx11,\r
+        dxy0, dxy1, dxyz;\r
+\r
+    TotalOut   = p -> nOutputs;\r
+\r
+    // We need some clipping here\r
+    px = Input[0];\r
+    py = Input[1];\r
+    pz = Input[2];\r
+\r
+    if (px < 0) px = 0;\r
+    if (px > 1) px = 1;\r
+    if (py < 0) py = 0;\r
+    if (py > 1) py = 1;\r
+    if (pz < 0) pz = 0;\r
+    if (pz > 1) pz = 1;\r
+\r
+    px *= p->Domain[0];\r
+    py *= p->Domain[1];\r
+    pz *= p->Domain[2];\r
+\r
+    x0 = (int) _cmsQuickFloor(px); fx = px - (cmsFloat32Number) x0;\r
+    y0 = (int) _cmsQuickFloor(py); fy = py - (cmsFloat32Number) y0;\r
+    z0 = (int) _cmsQuickFloor(pz); fz = pz - (cmsFloat32Number) z0;\r
+\r
+    X0 = p -> opta[2] * x0;\r
+    X1 = X0 + (Input[0] >= 1.0 ? 0 : p->opta[2]);\r
+\r
+    Y0 = p -> opta[1] * y0;\r
+    Y1 = Y0 + (Input[1] >= 1.0 ? 0 : p->opta[1]);\r
+\r
+    Z0 = p -> opta[0] * z0;\r
+    Z1 = Z0 + (Input[2] >= 1.0 ? 0 : p->opta[0]);\r
+\r
+    for (OutChan = 0; OutChan < TotalOut; OutChan++) {\r
+\r
+        d000 = DENS(X0, Y0, Z0);\r
+        d001 = DENS(X0, Y0, Z1);\r
+        d010 = DENS(X0, Y1, Z0);\r
+        d011 = DENS(X0, Y1, Z1);\r
+\r
+        d100 = DENS(X1, Y0, Z0);\r
+        d101 = DENS(X1, Y0, Z1);\r
+        d110 = DENS(X1, Y1, Z0);\r
+        d111 = DENS(X1, Y1, Z1);\r
+\r
+\r
+        dx00 = LERP(fx, d000, d100);\r
+        dx01 = LERP(fx, d001, d101);\r
+        dx10 = LERP(fx, d010, d110);\r
+        dx11 = LERP(fx, d011, d111);\r
+\r
+        dxy0 = LERP(fy, dx00, dx10);\r
+        dxy1 = LERP(fy, dx01, dx11);\r
+\r
+        dxyz = LERP(fz, dxy0, dxy1);\r
+\r
+        Output[OutChan] = dxyz;\r
+    }\r
+\r
+\r
+#   undef LERP\r
+#   undef DENS\r
+}\r
+\r
+// Trilinear interpolation (16 bits) - optimized version\r
+static\r
+void TrilinearInterp16(register const cmsUInt16Number Input[],\r
+                       register cmsUInt16Number Output[],\r
+                       register const cmsInterpParams* p)\r
+\r
+{\r
+#define DENS(i,j,k) (LutTable[(i)+(j)+(k)+OutChan])\r
+#define LERP(a,l,h)     (cmsUInt16Number) (l + ROUND_FIXED_TO_INT(((h-l)*a)))\r
+\r
+           const cmsUInt16Number* LutTable = (cmsUInt16Number*) p ->Table;\r
+           int        OutChan, TotalOut;\r
+           cmsS15Fixed16Number    fx, fy, fz;\r
+  register int        rx, ry, rz;\r
+           int        x0, y0, z0;\r
+  register int        X0, X1, Y0, Y1, Z0, Z1;\r
+           int        d000, d001, d010, d011,\r
+                      d100, d101, d110, d111,\r
+                      dx00, dx01, dx10, dx11,\r
+                      dxy0, dxy1, dxyz;\r
+\r
+    TotalOut   = p -> nOutputs;\r
+\r
+    fx = _cmsToFixedDomain((int) Input[0] * p -> Domain[0]);\r
+    x0  = FIXED_TO_INT(fx);\r
+    rx  = FIXED_REST_TO_INT(fx);    // Rest in 0..1.0 domain\r
+\r
+\r
+    fy = _cmsToFixedDomain((int) Input[1] * p -> Domain[1]);\r
+    y0  = FIXED_TO_INT(fy);\r
+    ry  = FIXED_REST_TO_INT(fy);\r
+\r
+    fz = _cmsToFixedDomain((int) Input[2] * p -> Domain[2]);\r
+    z0 = FIXED_TO_INT(fz);\r
+    rz = FIXED_REST_TO_INT(fz);\r
+\r
+\r
+    X0 = p -> opta[2] * x0;\r
+    X1 = X0 + (Input[0] == 0xFFFFU ? 0 : p->opta[2]);\r
+\r
+    Y0 = p -> opta[1] * y0;\r
+    Y1 = Y0 + (Input[1] == 0xFFFFU ? 0 : p->opta[1]);\r
+\r
+    Z0 = p -> opta[0] * z0;\r
+    Z1 = Z0 + (Input[2] == 0xFFFFU ? 0 : p->opta[0]);\r
+\r
+    for (OutChan = 0; OutChan < TotalOut; OutChan++) {\r
+\r
+        d000 = DENS(X0, Y0, Z0);\r
+        d001 = DENS(X0, Y0, Z1);\r
+        d010 = DENS(X0, Y1, Z0);\r
+        d011 = DENS(X0, Y1, Z1);\r
+\r
+        d100 = DENS(X1, Y0, Z0);\r
+        d101 = DENS(X1, Y0, Z1);\r
+        d110 = DENS(X1, Y1, Z0);\r
+        d111 = DENS(X1, Y1, Z1);\r
+\r
+\r
+        dx00 = LERP(rx, d000, d100);\r
+        dx01 = LERP(rx, d001, d101);\r
+        dx10 = LERP(rx, d010, d110);\r
+        dx11 = LERP(rx, d011, d111);\r
+\r
+        dxy0 = LERP(ry, dx00, dx10);\r
+        dxy1 = LERP(ry, dx01, dx11);\r
+\r
+        dxyz = LERP(rz, dxy0, dxy1);\r
+\r
+        Output[OutChan] = (cmsUInt16Number) dxyz;\r
+    }\r
+\r
+\r
+#   undef LERP\r
+#   undef DENS\r
+}\r
+\r
+\r
+// Tetrahedral interpolation, using Sakamoto algorithm.\r
+#define DENS(i,j,k) (LutTable[(i)+(j)+(k)+OutChan])\r
+static\r
+void TetrahedralInterpFloat(const cmsFloat32Number Input[],\r
+                            cmsFloat32Number Output[],\r
+                            const cmsInterpParams* p)\r
+{\r
+    const cmsFloat32Number* LutTable = (cmsFloat32Number*) p -> Table;\r
+    cmsFloat32Number     px, py, pz;\r
+    int        x0, y0, z0,\r
+               X0, Y0, Z0, X1, Y1, Z1;\r
+    cmsFloat32Number     rx, ry, rz;\r
+    cmsFloat32Number     c0, c1=0, c2=0, c3=0;\r
+    int                  OutChan, TotalOut;\r
+\r
+    TotalOut   = p -> nOutputs;\r
+\r
+    // We need some clipping here\r
+    px = Input[0];\r
+    py = Input[1];\r
+    pz = Input[2];\r
+\r
+    if (px < 0) px = 0;\r
+    if (px > 1) px = 1;\r
+    if (py < 0) py = 0;\r
+    if (py > 1) py = 1;\r
+    if (pz < 0) pz = 0;\r
+    if (pz > 1) pz = 1;\r
+\r
+    px *= p->Domain[0];\r
+    py *= p->Domain[1];\r
+    pz *= p->Domain[2];\r
+\r
+    x0 = (int) _cmsQuickFloor(px); rx = (px - (cmsFloat32Number) x0);\r
+    y0 = (int) _cmsQuickFloor(py); ry = (py - (cmsFloat32Number) y0);\r
+    z0 = (int) _cmsQuickFloor(pz); rz = (pz - (cmsFloat32Number) z0);\r
+\r
+\r
+    X0 = p -> opta[2] * x0;\r
+    X1 = X0 + (Input[0] >= 1.0 ? 0 : p->opta[2]);\r
+\r
+    Y0 = p -> opta[1] * y0;\r
+    Y1 = Y0 + (Input[1] >= 1.0 ? 0 : p->opta[1]);\r
+\r
+    Z0 = p -> opta[0] * z0;\r
+    Z1 = Z0 + (Input[2] >= 1.0 ? 0 : p->opta[0]);\r
+\r
+    for (OutChan=0; OutChan < TotalOut; OutChan++) {\r
+\r
+       // These are the 6 Tetrahedral\r
+\r
+        c0 = DENS(X0, Y0, Z0);\r
+\r
+        if (rx >= ry && ry >= rz) {\r
+\r
+            c1 = DENS(X1, Y0, Z0) - c0;\r
+            c2 = DENS(X1, Y1, Z0) - DENS(X1, Y0, Z0);\r
+            c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);\r
+\r
+        }\r
+        else\r
+            if (rx >= rz && rz >= ry) {\r
+\r
+                c1 = DENS(X1, Y0, Z0) - c0;\r
+                c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);\r
+                c3 = DENS(X1, Y0, Z1) - DENS(X1, Y0, Z0);\r
+\r
+            }\r
+            else\r
+                if (rz >= rx && rx >= ry) {\r
+\r
+                    c1 = DENS(X1, Y0, Z1) - DENS(X0, Y0, Z1);\r
+                    c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);\r
+                    c3 = DENS(X0, Y0, Z1) - c0;\r
+\r
+                }\r
+                else\r
+                    if (ry >= rx && rx >= rz) {\r
+\r
+                        c1 = DENS(X1, Y1, Z0) - DENS(X0, Y1, Z0);\r
+                        c2 = DENS(X0, Y1, Z0) - c0;\r
+                        c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);\r
+\r
+                    }\r
+                    else\r
+                        if (ry >= rz && rz >= rx) {\r
+\r
+                            c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);\r
+                            c2 = DENS(X0, Y1, Z0) - c0;\r
+                            c3 = DENS(X0, Y1, Z1) - DENS(X0, Y1, Z0);\r
+\r
+                        }\r
+                        else\r
+                            if (rz >= ry && ry >= rx) {\r
+\r
+                                c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);\r
+                                c2 = DENS(X0, Y1, Z1) - DENS(X0, Y0, Z1);\r
+                                c3 = DENS(X0, Y0, Z1) - c0;\r
+\r
+                            }\r
+                            else  {\r
+                                c1 = c2 = c3 = 0;\r
+                            }\r
+\r
+       Output[OutChan] = c0 + c1 * rx + c2 * ry + c3 * rz;\r
+       }\r
+\r
+}\r
+\r
+#undef DENS\r
+\r
+\r
+\r
+\r
+static\r
+void TetrahedralInterp16(register const cmsUInt16Number Input[],\r
+                         register cmsUInt16Number Output[],\r
+                         register const cmsInterpParams* p)\r
+{\r
+    const cmsUInt16Number* LutTable = (cmsUInt16Number*) p -> Table;\r
+    cmsS15Fixed16Number fx, fy, fz;\r
+    cmsS15Fixed16Number rx, ry, rz;\r
+    int x0, y0, z0;\r
+    cmsS15Fixed16Number c0, c1, c2, c3, Rest;\r
+    cmsS15Fixed16Number X0, X1, Y0, Y1, Z0, Z1;\r
+    cmsUInt32Number TotalOut = p -> nOutputs;\r
+\r
+    fx = _cmsToFixedDomain((int) Input[0] * p -> Domain[0]);\r
+    fy = _cmsToFixedDomain((int) Input[1] * p -> Domain[1]);\r
+    fz = _cmsToFixedDomain((int) Input[2] * p -> Domain[2]);\r
+\r
+    x0 = FIXED_TO_INT(fx);\r
+    y0 = FIXED_TO_INT(fy);\r
+    z0 = FIXED_TO_INT(fz);\r
+\r
+    rx = FIXED_REST_TO_INT(fx);\r
+    ry = FIXED_REST_TO_INT(fy);\r
+    rz = FIXED_REST_TO_INT(fz);\r
+\r
+    X0 = p -> opta[2] * x0;\r
+    X1 = (Input[0] == 0xFFFFU ? 0 : p->opta[2]);\r
+\r
+    Y0 = p -> opta[1] * y0;\r
+    Y1 = (Input[1] == 0xFFFFU ? 0 : p->opta[1]);\r
+\r
+    Z0 = p -> opta[0] * z0;\r
+    Z1 = (Input[2] == 0xFFFFU ? 0 : p->opta[0]);\r
+\r
+    LutTable = &LutTable[X0+Y0+Z0];\r
+\r
+    // Output should be computed as x = ROUND_FIXED_TO_INT(_cmsToFixedDomain(Rest))\r
+    // which expands as: x = (Rest + ((Rest+0x7fff)/0xFFFF) + 0x8000)>>16\r
+    // This can be replaced by: t = Rest+0x8001, x = (t + (t>>16))>>16\r
+    // at the cost of being off by one at 7fff and 17ffe.\r
+\r
+    if (rx >= ry) {\r
+        if (ry >= rz) {\r
+            Y1 += X1;\r
+            Z1 += Y1;\r
+            for (; TotalOut; TotalOut--) {\r
+                c1 = LutTable[X1];\r
+                c2 = LutTable[Y1];\r
+                c3 = LutTable[Z1];\r
+                c0 = *LutTable++;\r
+                c3 -= c2;\r
+                c2 -= c1;\r
+                c1 -= c0;\r
+                Rest = c1 * rx + c2 * ry + c3 * rz + 0x8001;\r
+                *Output++ = (cmsUInt16Number) c0 + ((Rest + (Rest>>16))>>16);\r
+            }\r
+        } else if (rz >= rx) {\r
+            X1 += Z1;\r
+            Y1 += X1;\r
+            for (; TotalOut; TotalOut--) {\r
+                c1 = LutTable[X1];\r
+                c2 = LutTable[Y1];\r
+                c3 = LutTable[Z1];\r
+                c0 = *LutTable++;\r
+                c2 -= c1;\r
+                c1 -= c3;\r
+                c3 -= c0;\r
+                Rest = c1 * rx + c2 * ry + c3 * rz + 0x8001;\r
+                *Output++ = (cmsUInt16Number) c0 + ((Rest + (Rest>>16))>>16);\r
+            }\r
+        } else {\r
+            Z1 += X1;\r
+            Y1 += Z1;\r
+            for (; TotalOut; TotalOut--) {\r
+                c1 = LutTable[X1];\r
+                c2 = LutTable[Y1];\r
+                c3 = LutTable[Z1];\r
+                c0 = *LutTable++;\r
+                c2 -= c3;\r
+                c3 -= c1;\r
+                c1 -= c0;\r
+                Rest = c1 * rx + c2 * ry + c3 * rz + 0x8001;\r
+                *Output++ = (cmsUInt16Number) c0 + ((Rest + (Rest>>16))>>16);\r
+            }\r
+        }\r
+    } else {\r
+        if (rx >= rz) {\r
+            X1 += Y1;\r
+            Z1 += X1;\r
+            for (; TotalOut; TotalOut--) {\r
+                c1 = LutTable[X1];\r
+                c2 = LutTable[Y1];\r
+                c3 = LutTable[Z1];\r
+                c0 = *LutTable++;\r
+                c3 -= c1;\r
+                c1 -= c2;\r
+                c2 -= c0;\r
+                Rest = c1 * rx + c2 * ry + c3 * rz + 0x8001;\r
+                *Output++ = (cmsUInt16Number) c0 + ((Rest + (Rest>>16))>>16);\r
+            }\r
+        } else if (ry >= rz) {\r
+            Z1 += Y1;\r
+            X1 += Z1;\r
+            for (; TotalOut; TotalOut--) {\r
+                c1 = LutTable[X1];\r
+                c2 = LutTable[Y1];\r
+                c3 = LutTable[Z1];\r
+                c0 = *LutTable++;\r
+                c1 -= c3;\r
+                c3 -= c2;\r
+                c2 -= c0;\r
+                Rest = c1 * rx + c2 * ry + c3 * rz + 0x8001;\r
+                *Output++ = (cmsUInt16Number) c0 + ((Rest + (Rest>>16))>>16);\r
+            }\r
+        } else {\r
+            Y1 += Z1;\r
+            X1 += Y1;\r
+            for (; TotalOut; TotalOut--) {\r
+                c1 = LutTable[X1];\r
+                c2 = LutTable[Y1];\r
+                c3 = LutTable[Z1];\r
+                c0 = *LutTable++;\r
+                c1 -= c2;\r
+                c2 -= c3;\r
+                c3 -= c0;\r
+                Rest = c1 * rx + c2 * ry + c3 * rz + 0x8001;\r
+                *Output++ = (cmsUInt16Number) c0 + ((Rest + (Rest>>16))>>16);\r
+            }\r
+        }\r
+    }\r
+}\r
+\r
+\r
+#define DENS(i,j,k) (LutTable[(i)+(j)+(k)+OutChan])\r
+static\r
+void Eval4Inputs(register const cmsUInt16Number Input[],\r
+                     register cmsUInt16Number Output[],\r
+                     register const cmsInterpParams* p16)\r
+{\r
+    const cmsUInt16Number* LutTable = (cmsUInt16Number*) p16 -> Table;\r
+    cmsS15Fixed16Number fk;\r
+    cmsS15Fixed16Number k0, rk;\r
+    int K0, K1;\r
+    cmsS15Fixed16Number    fx, fy, fz;\r
+    cmsS15Fixed16Number    rx, ry, rz;\r
+    int                    x0, y0, z0;\r
+    cmsS15Fixed16Number    X0, X1, Y0, Y1, Z0, Z1;\r
+    cmsUInt32Number i;\r
+    cmsS15Fixed16Number    c0, c1, c2, c3, Rest;\r
+    cmsUInt32Number        OutChan;\r
+    cmsUInt16Number        Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS];\r
+\r
+\r
+    fk  = _cmsToFixedDomain((int) Input[0] * p16 -> Domain[0]);\r
+    fx  = _cmsToFixedDomain((int) Input[1] * p16 -> Domain[1]);\r
+    fy  = _cmsToFixedDomain((int) Input[2] * p16 -> Domain[2]);\r
+    fz  = _cmsToFixedDomain((int) Input[3] * p16 -> Domain[3]);\r
+\r
+    k0  = FIXED_TO_INT(fk);\r
+    x0  = FIXED_TO_INT(fx);\r
+    y0  = FIXED_TO_INT(fy);\r
+    z0  = FIXED_TO_INT(fz);\r
+\r
+    rk  = FIXED_REST_TO_INT(fk);\r
+    rx  = FIXED_REST_TO_INT(fx);\r
+    ry  = FIXED_REST_TO_INT(fy);\r
+    rz  = FIXED_REST_TO_INT(fz);\r
+\r
+    K0 = p16 -> opta[3] * k0;\r
+    K1 = K0 + (Input[0] == 0xFFFFU ? 0 : p16->opta[3]);\r
+\r
+    X0 = p16 -> opta[2] * x0;\r
+    X1 = X0 + (Input[1] == 0xFFFFU ? 0 : p16->opta[2]);\r
+\r
+    Y0 = p16 -> opta[1] * y0;\r
+    Y1 = Y0 + (Input[2] == 0xFFFFU ? 0 : p16->opta[1]);\r
+\r
+    Z0 = p16 -> opta[0] * z0;\r
+    Z1 = Z0 + (Input[3] == 0xFFFFU ? 0 : p16->opta[0]);\r
+\r
+    LutTable = (cmsUInt16Number*) p16 -> Table;\r
+    LutTable += K0;\r
+\r
+    for (OutChan=0; OutChan < p16 -> nOutputs; OutChan++) {\r
+\r
+        c0 = DENS(X0, Y0, Z0);\r
+\r
+        if (rx >= ry && ry >= rz) {\r
+\r
+            c1 = DENS(X1, Y0, Z0) - c0;\r
+            c2 = DENS(X1, Y1, Z0) - DENS(X1, Y0, Z0);\r
+            c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);\r
+\r
+        }\r
+        else\r
+            if (rx >= rz && rz >= ry) {\r
+\r
+                c1 = DENS(X1, Y0, Z0) - c0;\r
+                c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);\r
+                c3 = DENS(X1, Y0, Z1) - DENS(X1, Y0, Z0);\r
+\r
+            }\r
+            else\r
+                if (rz >= rx && rx >= ry) {\r
+\r
+                    c1 = DENS(X1, Y0, Z1) - DENS(X0, Y0, Z1);\r
+                    c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);\r
+                    c3 = DENS(X0, Y0, Z1) - c0;\r
+\r
+                }\r
+                else\r
+                    if (ry >= rx && rx >= rz) {\r
+\r
+                        c1 = DENS(X1, Y1, Z0) - DENS(X0, Y1, Z0);\r
+                        c2 = DENS(X0, Y1, Z0) - c0;\r
+                        c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);\r
+\r
+                    }\r
+                    else\r
+                        if (ry >= rz && rz >= rx) {\r
+\r
+                            c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);\r
+                            c2 = DENS(X0, Y1, Z0) - c0;\r
+                            c3 = DENS(X0, Y1, Z1) - DENS(X0, Y1, Z0);\r
+\r
+                        }\r
+                        else\r
+                            if (rz >= ry && ry >= rx) {\r
+\r
+                                c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);\r
+                                c2 = DENS(X0, Y1, Z1) - DENS(X0, Y0, Z1);\r
+                                c3 = DENS(X0, Y0, Z1) - c0;\r
+\r
+                            }\r
+                            else  {\r
+                                c1 = c2 = c3 = 0;\r
+                            }\r
+\r
+                            Rest = c1 * rx + c2 * ry + c3 * rz;\r
+\r
+                            Tmp1[OutChan] = (cmsUInt16Number) c0 + ROUND_FIXED_TO_INT(_cmsToFixedDomain(Rest));\r
+    }\r
+\r
+\r
+    LutTable = (cmsUInt16Number*) p16 -> Table;\r
+    LutTable += K1;\r
+\r
+    for (OutChan=0; OutChan < p16 -> nOutputs; OutChan++) {\r
+\r
+        c0 = DENS(X0, Y0, Z0);\r
+\r
+        if (rx >= ry && ry >= rz) {\r
+\r
+            c1 = DENS(X1, Y0, Z0) - c0;\r
+            c2 = DENS(X1, Y1, Z0) - DENS(X1, Y0, Z0);\r
+            c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);\r
+\r
+        }\r
+        else\r
+            if (rx >= rz && rz >= ry) {\r
+\r
+                c1 = DENS(X1, Y0, Z0) - c0;\r
+                c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);\r
+                c3 = DENS(X1, Y0, Z1) - DENS(X1, Y0, Z0);\r
+\r
+            }\r
+            else\r
+                if (rz >= rx && rx >= ry) {\r
+\r
+                    c1 = DENS(X1, Y0, Z1) - DENS(X0, Y0, Z1);\r
+                    c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);\r
+                    c3 = DENS(X0, Y0, Z1) - c0;\r
+\r
+                }\r
+                else\r
+                    if (ry >= rx && rx >= rz) {\r
+\r
+                        c1 = DENS(X1, Y1, Z0) - DENS(X0, Y1, Z0);\r
+                        c2 = DENS(X0, Y1, Z0) - c0;\r
+                        c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);\r
+\r
+                    }\r
+                    else\r
+                        if (ry >= rz && rz >= rx) {\r
+\r
+                            c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);\r
+                            c2 = DENS(X0, Y1, Z0) - c0;\r
+                            c3 = DENS(X0, Y1, Z1) - DENS(X0, Y1, Z0);\r
+\r
+                        }\r
+                        else\r
+                            if (rz >= ry && ry >= rx) {\r
+\r
+                                c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);\r
+                                c2 = DENS(X0, Y1, Z1) - DENS(X0, Y0, Z1);\r
+                                c3 = DENS(X0, Y0, Z1) - c0;\r
+\r
+                            }\r
+                            else  {\r
+                                c1 = c2 = c3 = 0;\r
+                            }\r
+\r
+                            Rest = c1 * rx + c2 * ry + c3 * rz;\r
+\r
+                            Tmp2[OutChan] = (cmsUInt16Number) c0 + ROUND_FIXED_TO_INT(_cmsToFixedDomain(Rest));\r
+    }\r
+\r
+\r
+\r
+    for (i=0; i < p16 -> nOutputs; i++) {\r
+        Output[i] = LinearInterp(rk, Tmp1[i], Tmp2[i]);\r
+    }\r
+}\r
+#undef DENS\r
+\r
+\r
+// For more that 3 inputs (i.e., CMYK)\r
+// evaluate two 3-dimensional interpolations and then linearly interpolate between them.\r
+\r
+\r
+static\r
+void Eval4InputsFloat(const cmsFloat32Number Input[],\r
+                      cmsFloat32Number Output[],\r
+                      const cmsInterpParams* p)\r
+{\r
+       const cmsFloat32Number* LutTable = (cmsFloat32Number*) p -> Table;\r
+       cmsFloat32Number rest;\r
+       cmsFloat32Number pk;\r
+       int k0, K0, K1;\r
+       const cmsFloat32Number* T;\r
+       cmsUInt32Number i;\r
+       cmsFloat32Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS];\r
+       cmsInterpParams p1;\r
+\r
+\r
+       pk = Input[0] * p->Domain[0];\r
+       k0 = _cmsQuickFloor(pk);\r
+       rest = pk - (cmsFloat32Number) k0;\r
+\r
+       K0 = p -> opta[3] * k0;\r
+       K1 = K0 + (Input[0] >= 1.0 ? 0 : p->opta[3]);\r
+\r
+       p1 = *p;\r
+       memmove(&p1.Domain[0], &p ->Domain[1], 3*sizeof(cmsUInt32Number));\r
+\r
+       T = LutTable + K0;\r
+       p1.Table = T;\r
+\r
+       TetrahedralInterpFloat(Input + 1,  Tmp1, &p1);\r
+\r
+       T = LutTable + K1;\r
+       p1.Table = T;\r
+       TetrahedralInterpFloat(Input + 1,  Tmp2, &p1);\r
+\r
+       for (i=0; i < p -> nOutputs; i++)\r
+       {\r
+              cmsFloat32Number y0 = Tmp1[i];\r
+              cmsFloat32Number y1 = Tmp2[i];\r
+\r
+              Output[i] = y0 + (y1 - y0) * rest;\r
+       }\r
+}\r
+\r
+\r
+static\r
+void Eval5Inputs(register const cmsUInt16Number Input[],\r
+                 register cmsUInt16Number Output[],\r
+\r
+                 register const cmsInterpParams* p16)\r
+{\r
+       const cmsUInt16Number* LutTable = (cmsUInt16Number*) p16 -> Table;\r
+       cmsS15Fixed16Number fk;\r
+       cmsS15Fixed16Number k0, rk;\r
+       int K0, K1;\r
+       const cmsUInt16Number* T;\r
+       cmsUInt32Number i;\r
+       cmsUInt16Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS];\r
+       cmsInterpParams p1;\r
+\r
+\r
+       fk = _cmsToFixedDomain((cmsS15Fixed16Number) Input[0] * p16 -> Domain[0]);\r
+       k0 = FIXED_TO_INT(fk);\r
+       rk = FIXED_REST_TO_INT(fk);\r
+\r
+       K0 = p16 -> opta[4] * k0;\r
+       K1 = p16 -> opta[4] * (k0 + (Input[0] != 0xFFFFU ? 1 : 0));\r
+\r
+       p1 = *p16;\r
+       memmove(&p1.Domain[0], &p16 ->Domain[1], 4*sizeof(cmsUInt32Number));\r
+\r
+       T = LutTable + K0;\r
+       p1.Table = T;\r
+\r
+       Eval4Inputs(Input + 1, Tmp1, &p1);\r
+\r
+       T = LutTable + K1;\r
+       p1.Table = T;\r
+\r
+       Eval4Inputs(Input + 1, Tmp2, &p1);\r
+\r
+       for (i=0; i < p16 -> nOutputs; i++) {\r
+\r
+              Output[i] = LinearInterp(rk, Tmp1[i], Tmp2[i]);\r
+       }\r
+\r
+}\r
+\r
+\r
+static\r
+void Eval5InputsFloat(const cmsFloat32Number Input[],\r
+                      cmsFloat32Number Output[],\r
+                      const cmsInterpParams* p)\r
+{\r
+       const cmsFloat32Number* LutTable = (cmsFloat32Number*) p -> Table;\r
+       cmsFloat32Number rest;\r
+       cmsFloat32Number pk;\r
+       int k0, K0, K1;\r
+       const cmsFloat32Number* T;\r
+       cmsUInt32Number i;\r
+       cmsFloat32Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS];\r
+       cmsInterpParams p1;\r
+\r
+       pk = Input[0] * p->Domain[0];\r
+       k0 = _cmsQuickFloor(pk);\r
+       rest = pk - (cmsFloat32Number) k0;\r
+\r
+       K0 = p -> opta[4] * k0;\r
+       K1 = K0 + (Input[0] >= 1.0 ? 0 : p->opta[4]);\r
+\r
+       p1 = *p;\r
+       memmove(&p1.Domain[0], &p ->Domain[1], 4*sizeof(cmsUInt32Number));\r
+\r
+       T = LutTable + K0;\r
+       p1.Table = T;\r
+\r
+       Eval4InputsFloat(Input + 1,  Tmp1, &p1);\r
+\r
+       T = LutTable + K1;\r
+       p1.Table = T;\r
+\r
+       Eval4InputsFloat(Input + 1,  Tmp2, &p1);\r
+\r
+       for (i=0; i < p -> nOutputs; i++) {\r
+\r
+              cmsFloat32Number y0 = Tmp1[i];\r
+              cmsFloat32Number y1 = Tmp2[i];\r
+\r
+              Output[i] = y0 + (y1 - y0) * rest;\r
+       }\r
+}\r
+\r
+\r
+\r
+static\r
+void Eval6Inputs(register const cmsUInt16Number Input[],\r
+                 register cmsUInt16Number Output[],\r
+                 register const cmsInterpParams* p16)\r
+{\r
+       const cmsUInt16Number* LutTable = (cmsUInt16Number*) p16 -> Table;\r
+       cmsS15Fixed16Number fk;\r
+       cmsS15Fixed16Number k0, rk;\r
+       int K0, K1;\r
+       const cmsUInt16Number* T;\r
+       cmsUInt32Number i;\r
+       cmsUInt16Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS];\r
+       cmsInterpParams p1;\r
+\r
+       fk = _cmsToFixedDomain((cmsS15Fixed16Number) Input[0] * p16 -> Domain[0]);\r
+       k0 = FIXED_TO_INT(fk);\r
+       rk = FIXED_REST_TO_INT(fk);\r
+\r
+       K0 = p16 -> opta[5] * k0;\r
+       K1 = p16 -> opta[5] * (k0 + (Input[0] != 0xFFFFU ? 1 : 0));\r
+\r
+       p1 = *p16;\r
+       memmove(&p1.Domain[0], &p16 ->Domain[1], 5*sizeof(cmsUInt32Number));\r
+\r
+       T = LutTable + K0;\r
+       p1.Table = T;\r
+\r
+       Eval5Inputs(Input + 1, Tmp1, &p1);\r
+\r
+       T = LutTable + K1;\r
+       p1.Table = T;\r
+\r
+       Eval5Inputs(Input + 1, Tmp2, &p1);\r
+\r
+       for (i=0; i < p16 -> nOutputs; i++) {\r
+\r
+              Output[i] = LinearInterp(rk, Tmp1[i], Tmp2[i]);\r
+       }\r
+\r
+}\r
+\r
+\r
+static\r
+void Eval6InputsFloat(const cmsFloat32Number Input[],\r
+                      cmsFloat32Number Output[],\r
+                      const cmsInterpParams* p)\r
+{\r
+       const cmsFloat32Number* LutTable = (cmsFloat32Number*) p -> Table;\r
+       cmsFloat32Number rest;\r
+       cmsFloat32Number pk;\r
+       int k0, K0, K1;\r
+       const cmsFloat32Number* T;\r
+       cmsUInt32Number i;\r
+       cmsFloat32Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS];\r
+       cmsInterpParams p1;\r
+\r
+       pk = Input[0] * p->Domain[0];\r
+       k0 = _cmsQuickFloor(pk);\r
+       rest = pk - (cmsFloat32Number) k0;\r
+\r
+       K0 = p -> opta[5] * k0;\r
+       K1 = K0 + (Input[0] >= 1.0 ? 0 : p->opta[5]);\r
+\r
+       p1 = *p;\r
+       memmove(&p1.Domain[0], &p ->Domain[1], 5*sizeof(cmsUInt32Number));\r
+\r
+       T = LutTable + K0;\r
+       p1.Table = T;\r
+\r
+       Eval5InputsFloat(Input + 1,  Tmp1, &p1);\r
+\r
+       T = LutTable + K1;\r
+       p1.Table = T;\r
+\r
+       Eval5InputsFloat(Input + 1,  Tmp2, &p1);\r
+\r
+       for (i=0; i < p -> nOutputs; i++) {\r
+\r
+              cmsFloat32Number y0 = Tmp1[i];\r
+              cmsFloat32Number y1 = Tmp2[i];\r
+\r
+              Output[i] = y0 + (y1 - y0) * rest;\r
+       }\r
+}\r
+\r
+\r
+static\r
+void Eval7Inputs(register const cmsUInt16Number Input[],\r
+                 register cmsUInt16Number Output[],\r
+                 register const cmsInterpParams* p16)\r
+{\r
+       const cmsUInt16Number* LutTable = (cmsUInt16Number*) p16 -> Table;\r
+       cmsS15Fixed16Number fk;\r
+       cmsS15Fixed16Number k0, rk;\r
+       int K0, K1;\r
+       const cmsUInt16Number* T;\r
+       cmsUInt32Number i;\r
+       cmsUInt16Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS];\r
+       cmsInterpParams p1;\r
+\r
+\r
+       fk = _cmsToFixedDomain((cmsS15Fixed16Number) Input[0] * p16 -> Domain[0]);\r
+       k0 = FIXED_TO_INT(fk);\r
+       rk = FIXED_REST_TO_INT(fk);\r
+\r
+       K0 = p16 -> opta[6] * k0;\r
+       K1 = p16 -> opta[6] * (k0 + (Input[0] != 0xFFFFU ? 1 : 0));\r
+\r
+       p1 = *p16;\r
+       memmove(&p1.Domain[0], &p16 ->Domain[1], 6*sizeof(cmsUInt32Number));\r
+\r
+       T = LutTable + K0;\r
+       p1.Table = T;\r
+\r
+       Eval6Inputs(Input + 1, Tmp1, &p1);\r
+\r
+       T = LutTable + K1;\r
+       p1.Table = T;\r
+\r
+       Eval6Inputs(Input + 1, Tmp2, &p1);\r
+\r
+       for (i=0; i < p16 -> nOutputs; i++) {\r
+              Output[i] = LinearInterp(rk, Tmp1[i], Tmp2[i]);\r
+       }\r
+}\r
+\r
+\r
+static\r
+void Eval7InputsFloat(const cmsFloat32Number Input[],\r
+                      cmsFloat32Number Output[],\r
+                      const cmsInterpParams* p)\r
+{\r
+       const cmsFloat32Number* LutTable = (cmsFloat32Number*) p -> Table;\r
+       cmsFloat32Number rest;\r
+       cmsFloat32Number pk;\r
+       int k0, K0, K1;\r
+       const cmsFloat32Number* T;\r
+       cmsUInt32Number i;\r
+       cmsFloat32Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS];\r
+       cmsInterpParams p1;\r
+\r
+       pk = Input[0] * p->Domain[0];\r
+       k0 = _cmsQuickFloor(pk);\r
+       rest = pk - (cmsFloat32Number) k0;\r
+\r
+       K0 = p -> opta[6] * k0;\r
+       K1 = K0 + (Input[0] >= 1.0 ? 0 : p->opta[6]);\r
+\r
+       p1 = *p;\r
+       memmove(&p1.Domain[0], &p ->Domain[1], 6*sizeof(cmsUInt32Number));\r
+\r
+       T = LutTable + K0;\r
+       p1.Table = T;\r
+\r
+       Eval6InputsFloat(Input + 1,  Tmp1, &p1);\r
+\r
+       T = LutTable + K1;\r
+       p1.Table = T;\r
+\r
+       Eval6InputsFloat(Input + 1,  Tmp2, &p1);\r
+\r
+\r
+       for (i=0; i < p -> nOutputs; i++) {\r
+\r
+              cmsFloat32Number y0 = Tmp1[i];\r
+              cmsFloat32Number y1 = Tmp2[i];\r
+\r
+              Output[i] = y0 + (y1 - y0) * rest;\r
+\r
+       }\r
+}\r
+\r
+static\r
+void Eval8Inputs(register const cmsUInt16Number Input[],\r
+                 register cmsUInt16Number Output[],\r
+                 register const cmsInterpParams* p16)\r
+{\r
+       const cmsUInt16Number* LutTable = (cmsUInt16Number*) p16 -> Table;\r
+       cmsS15Fixed16Number fk;\r
+       cmsS15Fixed16Number k0, rk;\r
+       int K0, K1;\r
+       const cmsUInt16Number* T;\r
+       cmsUInt32Number i;\r
+       cmsUInt16Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS];\r
+       cmsInterpParams p1;\r
+\r
+       fk = _cmsToFixedDomain((cmsS15Fixed16Number) Input[0] * p16 -> Domain[0]);\r
+       k0 = FIXED_TO_INT(fk);\r
+       rk = FIXED_REST_TO_INT(fk);\r
+\r
+       K0 = p16 -> opta[7] * k0;\r
+       K1 = p16 -> opta[7] * (k0 + (Input[0] != 0xFFFFU ? 1 : 0));\r
+\r
+       p1 = *p16;\r
+       memmove(&p1.Domain[0], &p16 ->Domain[1], 7*sizeof(cmsUInt32Number));\r
+\r
+       T = LutTable + K0;\r
+       p1.Table = T;\r
+\r
+       Eval7Inputs(Input + 1, Tmp1, &p1);\r
+\r
+       T = LutTable + K1;\r
+       p1.Table = T;\r
+       Eval7Inputs(Input + 1, Tmp2, &p1);\r
+\r
+       for (i=0; i < p16 -> nOutputs; i++) {\r
+              Output[i] = LinearInterp(rk, Tmp1[i], Tmp2[i]);\r
+       }\r
+}\r
+\r
+\r
+\r
+static\r
+void Eval8InputsFloat(const cmsFloat32Number Input[],\r
+                      cmsFloat32Number Output[],\r
+                      const cmsInterpParams* p)\r
+{\r
+       const cmsFloat32Number* LutTable = (cmsFloat32Number*) p -> Table;\r
+       cmsFloat32Number rest;\r
+       cmsFloat32Number pk;\r
+       int k0, K0, K1;\r
+       const cmsFloat32Number* T;\r
+       cmsUInt32Number i;\r
+       cmsFloat32Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS];\r
+       cmsInterpParams p1;\r
+\r
+       pk = Input[0] * p->Domain[0];\r
+       k0 = _cmsQuickFloor(pk);\r
+       rest = pk - (cmsFloat32Number) k0;\r
+\r
+       K0 = p -> opta[7] * k0;\r
+       K1 = K0 + (Input[0] >= 1.0 ? 0 : p->opta[7]);\r
+\r
+       p1 = *p;\r
+       memmove(&p1.Domain[0], &p ->Domain[1], 7*sizeof(cmsUInt32Number));\r
+\r
+       T = LutTable + K0;\r
+       p1.Table = T;\r
+\r
+       Eval7InputsFloat(Input + 1,  Tmp1, &p1);\r
+\r
+       T = LutTable + K1;\r
+       p1.Table = T;\r
+\r
+       Eval7InputsFloat(Input + 1,  Tmp2, &p1);\r
+\r
+\r
+       for (i=0; i < p -> nOutputs; i++) {\r
+\r
+              cmsFloat32Number y0 = Tmp1[i];\r
+              cmsFloat32Number y1 = Tmp2[i];\r
+\r
+              Output[i] = y0 + (y1 - y0) * rest;\r
+       }\r
+}\r
+\r
+// The default factory\r
+static\r
+cmsInterpFunction DefaultInterpolatorsFactory(cmsUInt32Number nInputChannels, cmsUInt32Number nOutputChannels, cmsUInt32Number dwFlags)\r
+{\r
+\r
+    cmsInterpFunction Interpolation;\r
+    cmsBool  IsFloat     = (dwFlags & CMS_LERP_FLAGS_FLOAT);\r
+    cmsBool  IsTrilinear = (dwFlags & CMS_LERP_FLAGS_TRILINEAR);\r
+\r
+    memset(&Interpolation, 0, sizeof(Interpolation));\r
+\r
+    // Safety check\r
+    if (nInputChannels >= 4 && nOutputChannels >= MAX_STAGE_CHANNELS)\r
+        return Interpolation;\r
+\r
+    switch (nInputChannels) {\r
+\r
+           case 1: // Gray LUT / linear\r
+\r
+               if (nOutputChannels == 1) {\r
+\r
+                   if (IsFloat)\r
+                       Interpolation.LerpFloat = LinLerp1Dfloat;\r
+                   else\r
+                       Interpolation.Lerp16 = LinLerp1D;\r
+\r
+               }\r
+               else {\r
+\r
+                   if (IsFloat)\r
+                       Interpolation.LerpFloat = Eval1InputFloat;\r
+                   else\r
+                       Interpolation.Lerp16 = Eval1Input;\r
+               }\r
+               break;\r
+\r
+           case 2: // Duotone\r
+               if (IsFloat)\r
+                      Interpolation.LerpFloat =  BilinearInterpFloat;\r
+               else\r
+                      Interpolation.Lerp16    =  BilinearInterp16;\r
+               break;\r
+\r
+           case 3:  // RGB et al\r
+\r
+               if (IsTrilinear) {\r
+\r
+                   if (IsFloat)\r
+                       Interpolation.LerpFloat = TrilinearInterpFloat;\r
+                   else\r
+                       Interpolation.Lerp16 = TrilinearInterp16;\r
+               }\r
+               else {\r
+\r
+                   if (IsFloat)\r
+                       Interpolation.LerpFloat = TetrahedralInterpFloat;\r
+                   else {\r
+\r
+                       Interpolation.Lerp16 = TetrahedralInterp16;\r
+                   }\r
+               }\r
+               break;\r
+\r
+           case 4:  // CMYK lut\r
+\r
+               if (IsFloat)\r
+                   Interpolation.LerpFloat =  Eval4InputsFloat;\r
+               else\r
+                   Interpolation.Lerp16    =  Eval4Inputs;\r
+               break;\r
+\r
+           case 5: // 5 Inks\r
+               if (IsFloat)\r
+                   Interpolation.LerpFloat =  Eval5InputsFloat;\r
+               else\r
+                   Interpolation.Lerp16    =  Eval5Inputs;\r
+               break;\r
+\r
+           case 6: // 6 Inks\r
+               if (IsFloat)\r
+                   Interpolation.LerpFloat =  Eval6InputsFloat;\r
+               else\r
+                   Interpolation.Lerp16    =  Eval6Inputs;\r
+               break;\r
+\r
+           case 7: // 7 inks\r
+               if (IsFloat)\r
+                   Interpolation.LerpFloat =  Eval7InputsFloat;\r
+               else\r
+                   Interpolation.Lerp16    =  Eval7Inputs;\r
+               break;\r
+\r
+           case 8: // 8 inks\r
+               if (IsFloat)\r
+                   Interpolation.LerpFloat =  Eval8InputsFloat;\r
+               else\r
+                   Interpolation.Lerp16    =  Eval8Inputs;\r
+               break;\r
+\r
+               break;\r
+\r
+           default:\r
+               Interpolation.Lerp16 = NULL;\r
+    }\r
+\r
+    return Interpolation;\r
+}\r
index 5fb542e..d70b113 100644 (file)
@@ -1,24 +1,24 @@
 //---------------------------------------------------------------------------------
 //
 //  Little Color Management System
-//  Copyright (c) 1998-2011 Marti Maria Saguer
+//  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 
+// 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 
+// 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 
+// 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.
 //
 //---------------------------------------------------------------------------------
 
 // NULL IOhandler basically does nothing but keep track on how many bytes have been
 // written. This is handy when creating profiles, where the file size is needed in the
-// header. Then, whole profile is serialized across NULL IOhandler and a second pass 
+// header. Then, whole profile is serialized across NULL IOhandler and a second pass
 // writes the bytes to the pertinent IOhandler.
 
-typedef struct {        
+typedef struct {
     cmsUInt32Number Pointer;         // Points to current location
 } FILENULL;
 
 static
 cmsUInt32Number NULLRead(cmsIOHANDLER* iohandler, void *Buffer, cmsUInt32Number size, cmsUInt32Number count)
-{   
+{
     FILENULL* ResData = (FILENULL*) iohandler ->stream;
-    
+
     cmsUInt32Number len = size * count;
     ResData -> Pointer += len;
     return count;
@@ -61,15 +61,15 @@ cmsBool  NULLSeek(cmsIOHANDLER* iohandler, cmsUInt32Number offset)
 {
     FILENULL* ResData = (FILENULL*) iohandler ->stream;
 
-    ResData ->Pointer = offset; 
-    return TRUE; 
+    ResData ->Pointer = offset;
+    return TRUE;
 }
 
 static
 cmsUInt32Number NULLTell(cmsIOHANDLER* iohandler)
 {
     FILENULL* ResData = (FILENULL*) iohandler ->stream;
-    return ResData -> Pointer;     
+    return ResData -> Pointer;
 }
 
 static
@@ -88,9 +88,9 @@ cmsBool  NULLWrite(cmsIOHANDLER* iohandler, cmsUInt32Number size, const void *Pt
 
 static
 cmsBool  NULLClose(cmsIOHANDLER* iohandler)
-{   
+{
     FILENULL* ResData = (FILENULL*) iohandler ->stream;
-    
+
     _cmsFree(iohandler ->ContextID, ResData);
     _cmsFree(iohandler ->ContextID, iohandler);
     return TRUE;
@@ -101,17 +101,17 @@ cmsIOHANDLER*  CMSEXPORT cmsOpenIOhandlerFromNULL(cmsContext ContextID)
 {
     struct _cms_io_handler* iohandler = NULL;
     FILENULL* fm = NULL;
-        
+
     iohandler = (struct _cms_io_handler*) _cmsMallocZero(ContextID, sizeof(struct _cms_io_handler));
     if (iohandler == NULL) return NULL;
 
     fm = (FILENULL*) _cmsMallocZero(ContextID, sizeof(FILENULL));
     if (fm == NULL) goto Error;
-    
+
     fm ->Pointer = 0;
 
     iohandler ->ContextID = ContextID;
-    iohandler ->stream  = (void*) fm;   
+    iohandler ->stream  = (void*) fm;
     iohandler ->UsedSpace = 0;
     iohandler ->ReportedSize = 0;
     iohandler ->PhysicalFile[0] = 0;
@@ -146,7 +146,7 @@ typedef struct {
 
 static
 cmsUInt32Number MemoryRead(struct _cms_io_handler* iohandler, void *Buffer, cmsUInt32Number size, cmsUInt32Number count)
-{   
+{
     FILEMEM* ResData = (FILEMEM*) iohandler ->stream;
     cmsUInt8Number* Ptr;
     cmsUInt32Number len = size * count;
@@ -160,7 +160,7 @@ cmsUInt32Number MemoryRead(struct _cms_io_handler* iohandler, void *Buffer, cmsU
 
     Ptr  = ResData -> Block;
     Ptr += ResData -> Pointer;
-    memmove(Buffer, Ptr, len);        
+    memmove(Buffer, Ptr, len);
     ResData -> Pointer += len;
 
     return count;
@@ -173,12 +173,12 @@ cmsBool  MemorySeek(struct _cms_io_handler* iohandler, cmsUInt32Number offset)
     FILEMEM* ResData = (FILEMEM*) iohandler ->stream;
 
     if (offset > ResData ->Size) {
-        cmsSignalError(iohandler ->ContextID, cmsERROR_SEEK,  "Too few data; probably corrupted profile");        
+        cmsSignalError(iohandler ->ContextID, cmsERROR_SEEK,  "Too few data; probably corrupted profile");
         return FALSE;
     }
 
-    ResData ->Pointer = offset; 
-    return TRUE; 
+    ResData ->Pointer = offset;
+    return TRUE;
 }
 
 // Tell for memory
@@ -188,11 +188,11 @@ cmsUInt32Number MemoryTell(struct _cms_io_handler* iohandler)
     FILEMEM* ResData = (FILEMEM*) iohandler ->stream;
 
        if (ResData == NULL) return 0;
-    return ResData -> Pointer;     
+    return ResData -> Pointer;
 }
 
 
-// Writes data to memory, also keeps used space for further reference. 
+// Writes data to memory, also keeps used space for further reference.
 static
 cmsBool  MemoryWrite(struct _cms_io_handler* iohandler, cmsUInt32Number size, const void *Ptr)
 {
@@ -204,27 +204,25 @@ cmsBool  MemoryWrite(struct _cms_io_handler* iohandler, cmsUInt32Number size, co
 
     memmove(ResData ->Block + ResData ->Pointer, Ptr, size);
     ResData ->Pointer += size;
+    iohandler->UsedSpace += size;
 
     if (ResData ->Pointer > iohandler->UsedSpace)
         iohandler->UsedSpace = ResData ->Pointer;
 
-    
-    iohandler->UsedSpace += size;    
-
     return TRUE;
 }
 
 
 static
 cmsBool  MemoryClose(struct _cms_io_handler* iohandler)
-{   
+{
     FILEMEM* ResData = (FILEMEM*) iohandler ->stream;
 
     if (ResData ->FreeBlockOnClose) {
 
         if (ResData ->Block) _cmsFree(iohandler ->ContextID, ResData ->Block);
     }
-    
+
     _cmsFree(iohandler ->ContextID, ResData);
     _cmsFree(iohandler ->ContextID, iohandler);
 
@@ -232,7 +230,7 @@ cmsBool  MemoryClose(struct _cms_io_handler* iohandler)
 }
 
 // Create a iohandler for memory block. AccessMode=='r' assumes the iohandler is going to read, and makes
-// a copy of the memory block for letting user to free the memory after invoking open profile. In write 
+// a copy of the memory block for letting user to free the memory after invoking open profile. In write
 // mode ("w"), Buffere points to the begin of memory block to be written.
 cmsIOHANDLER* CMSEXPORT cmsOpenIOhandlerFromMem(cmsContext ContextID, void *Buffer, cmsUInt32Number size, const char* AccessMode)
 {
@@ -272,14 +270,14 @@ cmsIOHANDLER* CMSEXPORT cmsOpenIOhandlerFromMem(cmsContext ContextID, void *Buff
         iohandler -> ReportedSize = size;
         break;
 
-    case 'w': 
+    case 'w':
         fm = (FILEMEM*) _cmsMallocZero(ContextID, sizeof(FILEMEM));
         if (fm == NULL) goto Error;
 
         fm ->Block = (cmsUInt8Number*) Buffer;
         fm ->FreeBlockOnClose = FALSE;
         fm ->Size    = size;
-        fm ->Pointer = 0;     
+        fm ->Pointer = 0;
         iohandler -> ReportedSize = 0;
         break;
 
@@ -289,7 +287,7 @@ cmsIOHANDLER* CMSEXPORT cmsOpenIOhandlerFromMem(cmsContext ContextID, void *Buff
     }
 
     iohandler ->ContextID = ContextID;
-    iohandler ->stream  = (void*) fm;   
+    iohandler ->stream  = (void*) fm;
     iohandler ->UsedSpace = 0;
     iohandler ->PhysicalFile[0] = 0;
 
@@ -339,7 +337,7 @@ cmsBool  FileSeek(cmsIOHANDLER* iohandler, cmsUInt32Number offset)
 // Returns file pointer position
 static
 cmsUInt32Number FileTell(cmsIOHANDLER* iohandler)
-{       
+{
     return ftell((FILE*)iohandler ->stream);
 }
 
@@ -356,7 +354,7 @@ cmsBool  FileWrite(cmsIOHANDLER* iohandler, cmsUInt32Number size, const void* Bu
 // Closes the file
 static
 cmsBool  FileClose(cmsIOHANDLER* iohandler)
-{   
+{
     if (fclose((FILE*) iohandler ->stream) != 0) return FALSE;
     _cmsFree(iohandler ->ContextID, iohandler);
     return TRUE;
@@ -420,11 +418,11 @@ cmsIOHANDLER* CMSEXPORT cmsOpenIOhandlerFromFile(cmsContext ContextID, const cha
     return iohandler;
 }
 
-// Create a iohandler for stream based files 
+// Create a iohandler for stream based files
 cmsIOHANDLER* CMSEXPORT cmsOpenIOhandlerFromStream(cmsContext ContextID, FILE* Stream)
 {
     cmsIOHANDLER* iohandler = NULL;
-    
+
     iohandler = (cmsIOHANDLER*) _cmsMallocZero(ContextID, sizeof(cmsIOHANDLER));
     if (iohandler == NULL) return NULL;
 
@@ -433,7 +431,7 @@ cmsIOHANDLER* CMSEXPORT cmsOpenIOhandlerFromStream(cmsContext ContextID, FILE* S
     iohandler -> UsedSpace = 0;
     iohandler -> ReportedSize = cmsfilelength(Stream);
     iohandler -> PhysicalFile[0] = 0;
-    
+
     iohandler ->Read    = FileRead;
     iohandler ->Seek    = FileSeek;
     iohandler ->Close   = FileClose;
@@ -465,7 +463,7 @@ cmsHPROFILE CMSEXPORT cmsCreateProfilePlaceholder(cmsContext ContextID)
     // Set it to empty
     Icc -> TagCount   = 0;
 
-    // Set default version 
+    // Set default version
     Icc ->Version =  0x02100000;
 
     // Set creation date/time
@@ -477,7 +475,7 @@ cmsHPROFILE CMSEXPORT cmsCreateProfilePlaceholder(cmsContext ContextID)
 
 cmsContext CMSEXPORT cmsGetProfileContextID(cmsHPROFILE hProfile)
 {
-     _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;  
+     _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
 
     if (Icc == NULL) return NULL;
     return Icc -> ContextID;
@@ -487,7 +485,7 @@ cmsContext CMSEXPORT cmsGetProfileContextID(cmsHPROFILE hProfile)
 // Return the number of tags
 cmsInt32Number CMSEXPORT cmsGetTagCount(cmsHPROFILE hProfile)
 {
-    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;  
+    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
        if (Icc == NULL) return -1;
 
     return  Icc->TagCount;
@@ -496,9 +494,9 @@ cmsInt32Number CMSEXPORT cmsGetTagCount(cmsHPROFILE hProfile)
 // Return the tag signature of a given tag number
 cmsTagSignature CMSEXPORT cmsGetTagSignature(cmsHPROFILE hProfile, cmsUInt32Number n)
 {
-    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;    
+    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
 
-    if (n > Icc->TagCount) return (cmsTagSignature) 0;  // Mark as not available     
+    if (n > Icc->TagCount) return (cmsTagSignature) 0;  // Mark as not available
     if (n >= MAX_TABLE_TAG) return (cmsTagSignature) 0; // As double check
 
     return Icc ->TagNames[n];
@@ -530,10 +528,10 @@ int _cmsSearchTag(_cmsICCPROFILE* Icc, cmsTagSignature sig, cmsBool lFollowLinks
 
                // Search for given tag in ICC profile directory
                n = SearchOneTag(Icc, sig);
-               if (n < 0) 
+               if (n < 0)
                        return -1;        // Not found
 
-               if (!lFollowLinks) 
+               if (!lFollowLinks)
                        return n;         // Found, don't follow links
 
                // Is this a linked tag?
@@ -568,7 +566,7 @@ cmsBool _cmsNewTag(_cmsICCPROFILE* Icc, cmsTagSignature sig, int* NewPos)
     else  {
 
         // New one
-        
+
         if (Icc -> TagCount >= MAX_TABLE_TAG) {
             cmsSignalError(Icc ->ContextID, cmsERROR_RANGE, "Too many tags (%d)", MAX_TABLE_TAG);
             return FALSE;
@@ -602,14 +600,14 @@ cmsBool _cmsReadHeader(_cmsICCPROFILE* Icc)
 
 
     // Read the header
-    if (io -> Read(io, &Header, sizeof(cmsICCHeader), 1) != 1) {        
-        return FALSE; 
+    if (io -> Read(io, &Header, sizeof(cmsICCHeader), 1) != 1) {
+        return FALSE;
     }
 
     // Validate file as an ICC profile
     if (_cmsAdjustEndianess32(Header.magic) != cmsMagicNumber) {
         cmsSignalError(Icc ->ContextID, cmsERROR_BAD_SIGNATURE, "not an ICC profile, invalid signature");
-        return FALSE; 
+        return FALSE;
     }
 
     // Adjust endianess of the used parameters
@@ -620,7 +618,7 @@ cmsBool _cmsReadHeader(_cmsICCPROFILE* Icc)
     Icc -> flags           = _cmsAdjustEndianess32(Header.flags);
     Icc -> manufacturer    = _cmsAdjustEndianess32(Header.manufacturer);
     Icc -> model           = _cmsAdjustEndianess32(Header.model);
-    _cmsAdjustEndianess64(&Icc -> attributes, Header.attributes);
+    _cmsAdjustEndianess64(&Icc -> attributes, &Header.attributes);
     Icc -> Version         = _cmsAdjustEndianess32(Header.version);
 
     // Get size as reported in header
@@ -630,7 +628,7 @@ cmsBool _cmsReadHeader(_cmsICCPROFILE* Icc)
     if (HeaderSize >= Icc ->IOhandler ->ReportedSize)
             HeaderSize = Icc ->IOhandler ->ReportedSize;
 
-   
+
     // Get creation date/time
     _cmsDecodeDateTimeNumber(&Header.date, &Icc ->Created);
 
@@ -639,7 +637,7 @@ cmsBool _cmsReadHeader(_cmsICCPROFILE* Icc)
 
 
     // Read tag directory
-    if (!_cmsReadUInt32Number(io, &TagCount)) return FALSE;                          
+    if (!_cmsReadUInt32Number(io, &TagCount)) return FALSE;
     if (TagCount > MAX_TABLE_TAG) {
 
         cmsSignalError(Icc ->ContextID, cmsERROR_RANGE, "Too many tags (%d)", TagCount);
@@ -657,7 +655,7 @@ cmsBool _cmsReadHeader(_cmsICCPROFILE* Icc)
 
         // Perform some sanity check. Offset + size should fall inside file.
         if (Tag.offset + Tag.size > HeaderSize ||
-            Tag.offset + Tag.size < Tag.offset)       
+            Tag.offset + Tag.size < Tag.offset)
                   continue;
 
         Icc -> TagNames[Icc ->TagCount]   = Tag.sig;
@@ -670,23 +668,23 @@ cmsBool _cmsReadHeader(_cmsICCPROFILE* Icc)
             if ((Icc ->TagOffsets[j] == Tag.offset) &&
                 (Icc ->TagSizes[j]   == Tag.size)) {
 
-                Icc ->TagLinked[Icc ->TagCount] = Icc ->TagNames[j];   
+                Icc ->TagLinked[Icc ->TagCount] = Icc ->TagNames[j];
             }
 
         }
 
         Icc ->TagCount++;
     }
-  
+
     return TRUE;
 }
 
 // Saves profile header
 cmsBool _cmsWriteHeader(_cmsICCPROFILE* Icc, cmsUInt32Number UsedSpace)
 {
-    cmsICCHeader Header;    
+    cmsICCHeader Header;
     cmsUInt32Number i;
-    cmsTagEntry Tag;       
+    cmsTagEntry Tag;
     cmsInt32Number Count = 0;
 
     Header.size        = _cmsAdjustEndianess32(UsedSpace);
@@ -703,17 +701,17 @@ cmsBool _cmsWriteHeader(_cmsICCPROFILE* Icc, cmsUInt32Number UsedSpace)
     Header.magic       = _cmsAdjustEndianess32(cmsMagicNumber);
 
 #ifdef CMS_IS_WINDOWS_
-    Header.platform    = (cmsPlatformSignature) _cmsAdjustEndianess32(cmsSigMicrosoft);  
+    Header.platform    = (cmsPlatformSignature) _cmsAdjustEndianess32(cmsSigMicrosoft);
 #else
-    Header.platform    = (cmsPlatformSignature) _cmsAdjustEndianess32(cmsSigMacintosh);  
+    Header.platform    = (cmsPlatformSignature) _cmsAdjustEndianess32(cmsSigMacintosh);
 #endif
 
     Header.flags        = _cmsAdjustEndianess32(Icc -> flags);
     Header.manufacturer = _cmsAdjustEndianess32(Icc -> manufacturer);
     Header.model        = _cmsAdjustEndianess32(Icc -> model);
 
-    _cmsAdjustEndianess64(&Header.attributes, Icc -> attributes);              
-    
+    _cmsAdjustEndianess64(&Header.attributes, &Icc -> attributes);
+
     // Rendering intent in the header (for embedded profiles)
     Header.renderingIntent = _cmsAdjustEndianess32(Icc -> RenderingIntent);
 
@@ -727,7 +725,7 @@ cmsBool _cmsWriteHeader(_cmsICCPROFILE* Icc, cmsUInt32Number UsedSpace)
 
     memset(&Header.reserved, 0, sizeof(Header.reserved));
 
-    // Set profile ID. Endianess is always big endian   
+    // Set profile ID. Endianess is always big endian
     memmove(&Header.profileID, &Icc ->ProfileID, 16);
 
     // Dump the header
@@ -742,7 +740,7 @@ cmsBool _cmsWriteHeader(_cmsICCPROFILE* Icc, cmsUInt32Number UsedSpace)
     }
 
     // Store number of tags
-    if (!_cmsWriteUInt32Number(Icc ->IOhandler, Count)) return FALSE;   
+    if (!_cmsWriteUInt32Number(Icc ->IOhandler, Count)) return FALSE;
 
     for (i=0; i < Icc -> TagCount; i++) {
 
@@ -824,8 +822,8 @@ void CMSEXPORT cmsSetHeaderAttributes(cmsHPROFILE hProfile, cmsUInt64Number Flag
 
 void CMSEXPORT cmsGetHeaderProfileID(cmsHPROFILE hProfile, cmsUInt8Number* ProfileID)
 {
-    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;    
-    memmove(ProfileID, Icc ->ProfileID.ID8, 16);    
+    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
+    memmove(ProfileID, Icc ->ProfileID.ID8, 16);
 }
 
 void CMSEXPORT cmsSetHeaderProfileID(cmsHPROFILE hProfile, cmsUInt8Number* ProfileID)
@@ -836,8 +834,8 @@ void CMSEXPORT cmsSetHeaderProfileID(cmsHPROFILE hProfile, cmsUInt8Number* Profi
 
 cmsBool  CMSEXPORT cmsGetHeaderCreationDateTime(cmsHPROFILE hProfile, struct tm *Dest)
 {
-    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;    
-    memmove(Dest, &Icc ->Created, sizeof(struct tm));    
+    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
+    memmove(Dest, &Icc ->Created, sizeof(struct tm));
     return TRUE;
 }
 
@@ -896,9 +894,9 @@ cmsUInt32Number BaseToBase(cmsUInt32Number in, int BaseIn, int BaseOut)
     char Buff[100];
     int i, len;
     cmsUInt32Number out;
-    
+
     for (len=0; in > 0 && len < 100; len++) {
-    
+
         Buff[len] = (char) (in % BaseIn);
         in /= BaseIn;
     }
@@ -940,7 +938,7 @@ cmsHPROFILE CMSEXPORT cmsOpenProfileFromIOhandlerTHR(cmsContext ContextID, cmsIO
     NewIcc = (_cmsICCPROFILE*) hEmpty;
 
     NewIcc ->IOhandler = io;
-    if (!_cmsReadHeader(NewIcc)) goto Error;    
+    if (!_cmsReadHeader(NewIcc)) goto Error;
     return hEmpty;
 
 Error:
@@ -964,7 +962,7 @@ cmsHPROFILE CMSEXPORT cmsOpenProfileFromFileTHR(cmsContext ContextID, const char
     if (*sAccess == 'W' || *sAccess == 'w') {
 
         NewIcc -> IsWrite = TRUE;
-        
+
         return hEmpty;
     }
 
@@ -997,11 +995,11 @@ cmsHPROFILE  CMSEXPORT cmsOpenProfileFromStreamTHR(cmsContext ContextID, FILE* I
 
     if (*sAccess == 'w') {
 
-        NewIcc -> IsWrite = TRUE;       
+        NewIcc -> IsWrite = TRUE;
         return hEmpty;
     }
 
-    if (!_cmsReadHeader(NewIcc)) goto Error;    
+    if (!_cmsReadHeader(NewIcc)) goto Error;
     return hEmpty;
 
 Error:
@@ -1027,7 +1025,7 @@ cmsHPROFILE CMSEXPORT cmsOpenProfileFromMemTHR(cmsContext ContextID, const void*
 
     NewIcc = (_cmsICCPROFILE*) hEmpty;
 
-       // Ok, in this case const void* is casted to void* just because open IO handler 
+       // Ok, in this case const void* is casted to void* just because open IO handler
        // shares read and writting modes. Don't abuse this feature!
     NewIcc ->IOhandler = cmsOpenIOhandlerFromMem(ContextID, (void*) MemPtr, dwSize, "r");
     if (NewIcc ->IOhandler == NULL) goto Error;
@@ -1063,7 +1061,7 @@ cmsBool SaveTags(_cmsICCPROFILE* Icc, _cmsICCPROFILE* FileOrig)
 
     for (i=0; i < Icc -> TagCount; i++) {
 
-       
+
         if (Icc ->TagNames[i] == 0) continue;
 
         // Linked tags are not written
@@ -1075,7 +1073,7 @@ cmsBool SaveTags(_cmsICCPROFILE* Icc, _cmsICCPROFILE* FileOrig)
 
         if (!Data) {
 
-            // Reach here if we are copying a tag from a disk-based ICC profile which has not been modified by user. 
+            // Reach here if we are copying a tag from a disk-based ICC profile which has not been modified by user.
             // In this case a blind copy of the block data is performed
             if (FileOrig != NULL && Icc -> TagOffsets[i]) {
 
@@ -1085,7 +1083,7 @@ cmsBool SaveTags(_cmsICCPROFILE* Icc, _cmsICCPROFILE* FileOrig)
 
                 if (!FileOrig ->IOhandler->Seek(FileOrig ->IOhandler, TagOffset)) return FALSE;
 
-                Mem = _cmsMalloc(Icc ->ContextID, TagSize);                  
+                Mem = _cmsMalloc(Icc ->ContextID, TagSize);
                 if (Mem == NULL) return FALSE;
 
                 if (FileOrig ->IOhandler->Read(FileOrig->IOhandler, Mem, TagSize, 1) != 1) return FALSE;
@@ -1093,11 +1091,11 @@ cmsBool SaveTags(_cmsICCPROFILE* Icc, _cmsICCPROFILE* FileOrig)
                 _cmsFree(Icc ->ContextID, Mem);
 
                 Icc -> TagSizes[i] = (io ->UsedSpace - Begin);
-                
+
 
                 // Align to 32 bit boundary.
-                if (! _cmsWriteAlignment(io)) 
-                    return FALSE;                   
+                if (! _cmsWriteAlignment(io))
+                    return FALSE;
             }
 
             continue;
@@ -1123,7 +1121,7 @@ cmsBool SaveTags(_cmsICCPROFILE* Icc, _cmsICCPROFILE* FileOrig)
             }
 
             TypeBase = TypeHandler ->Signature;
-            if (!_cmsWriteTypeBase(io, TypeBase)) 
+            if (!_cmsWriteTypeBase(io, TypeBase))
                 return FALSE;
 
             TypeHandler ->ContextID  = Icc ->ContextID;
@@ -1134,16 +1132,16 @@ cmsBool SaveTags(_cmsICCPROFILE* Icc, _cmsICCPROFILE* FileOrig)
 
                                 _cmsTagSignature2String(String, (cmsTagSignature) TypeBase);
                 cmsSignalError(Icc ->ContextID, cmsERROR_WRITE, "Couldn't write type '%s'", String);
-                return FALSE;   
+                return FALSE;
             }
         }
 
 
-        Icc -> TagSizes[i] = (io ->UsedSpace - Begin);      
+        Icc -> TagSizes[i] = (io ->UsedSpace - Begin);
 
         // Align to 32 bit boundary.
-        if (! _cmsWriteAlignment(io)) 
-            return FALSE;                   
+        if (! _cmsWriteAlignment(io))
+            return FALSE;
     }
 
 
@@ -1181,7 +1179,7 @@ cmsBool SetLinks( _cmsICCPROFILE* Icc)
 cmsUInt32Number CMSEXPORT cmsSaveProfileToIOhandler(cmsHPROFILE hProfile, cmsIOHANDLER* io)
 {
     _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
-    _cmsICCPROFILE Keep;              
+    _cmsICCPROFILE Keep;
     cmsIOHANDLER* PrevIO;
     cmsUInt32Number UsedSpace;
     cmsContext ContextID;
@@ -1202,7 +1200,7 @@ cmsUInt32Number CMSEXPORT cmsSaveProfileToIOhandler(cmsHPROFILE hProfile, cmsIOH
     // Pass #2 does save to iohandler
 
     if (io != NULL) {
-        Icc ->IOhandler = io;     
+        Icc ->IOhandler = io;
         if (!SetLinks(Icc)) goto CleanUp;
         if (!_cmsWriteHeader(Icc, UsedSpace)) goto CleanUp;
         if (!SaveTags(Icc, &Keep)) goto CleanUp;
@@ -1214,20 +1212,20 @@ cmsUInt32Number CMSEXPORT cmsSaveProfileToIOhandler(cmsHPROFILE hProfile, cmsIOH
     return UsedSpace;
 
 
-CleanUp:     
-    cmsCloseIOhandler(PrevIO);      
+CleanUp:
+    cmsCloseIOhandler(PrevIO);
     memmove(Icc, &Keep, sizeof(_cmsICCPROFILE));
     return 0;
 }
 
 
-// Low-level save to disk. 
+// Low-level save to disk.
 cmsBool  CMSEXPORT cmsSaveProfileToFile(cmsHPROFILE hProfile, const char* FileName)
-{   
+{
     cmsContext ContextID = cmsGetProfileContextID(hProfile);
     cmsIOHANDLER* io = cmsOpenIOhandlerFromFile(ContextID, FileName, "w");
     cmsBool rc;
-    
+
     if (io == NULL) return FALSE;
 
     rc = (cmsSaveProfileToIOhandler(hProfile, io) != 0);
@@ -1245,7 +1243,7 @@ cmsBool CMSEXPORT cmsSaveProfileToStream(cmsHPROFILE hProfile, FILE* Stream)
     cmsBool rc;
     cmsContext ContextID = cmsGetProfileContextID(hProfile);
     cmsIOHANDLER* io = cmsOpenIOhandlerFromStream(ContextID, Stream);
-    
+
     if (io == NULL) return FALSE;
 
     rc = (cmsSaveProfileToIOhandler(hProfile, io) != 0);
@@ -1261,9 +1259,9 @@ cmsBool CMSEXPORT cmsSaveProfileToMem(cmsHPROFILE hProfile, void *MemPtr, cmsUIn
     cmsBool rc;
     cmsIOHANDLER* io;
     cmsContext ContextID = cmsGetProfileContextID(hProfile);
-    
+
     // Should we just calculate the needed space?
-    if (MemPtr == NULL) {   
+    if (MemPtr == NULL) {
 
            *BytesNeeded =  cmsSaveProfileToIOhandler(hProfile, NULL);
             return TRUE;
@@ -1286,15 +1284,15 @@ cmsBool  CMSEXPORT cmsCloseProfile(cmsHPROFILE hProfile)
 {
     _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
     cmsBool  rc = TRUE;
-    cmsUInt32Number i;         
+    cmsUInt32Number i;
 
     if (!Icc) return FALSE;
 
-    // Was open in write mode?   
+    // Was open in write mode?
     if (Icc ->IsWrite) {
 
         Icc ->IsWrite = FALSE;      // Assure no further writting
-        rc &= cmsSaveProfileToFile(hProfile, Icc ->IOhandler->PhysicalFile);        
+        rc &= cmsSaveProfileToFile(hProfile, Icc ->IOhandler->PhysicalFile);
     }
 
     for (i=0; i < Icc -> TagCount; i++) {
@@ -1314,9 +1312,9 @@ cmsBool  CMSEXPORT cmsCloseProfile(cmsHPROFILE hProfile)
         }
     }
 
-    if (Icc ->IOhandler != NULL) {      
-        rc &= cmsCloseIOhandler(Icc->IOhandler);   
-    }       
+    if (Icc ->IOhandler != NULL) {
+        rc &= cmsCloseIOhandler(Icc->IOhandler);
+    }
 
     _cmsFree(Icc ->ContextID, Icc);   // Free placeholder memory
 
@@ -1336,9 +1334,9 @@ cmsBool IsTypeSupported(cmsTagDescriptor* TagDescriptor, cmsTagTypeSignature Typ
     nMaxTypes = TagDescriptor->nSupportedTypes;
     if (nMaxTypes >= MAX_TYPES_IN_LCMS_PLUGIN)
         nMaxTypes = MAX_TYPES_IN_LCMS_PLUGIN;
-    
+
     for (i=0; i < nMaxTypes; i++) {
-        if (Type == TagDescriptor ->SupportedTypes[i]) return TRUE; 
+        if (Type == TagDescriptor ->SupportedTypes[i]) return TRUE;
     }
 
     return FALSE;
@@ -1348,7 +1346,7 @@ cmsBool IsTypeSupported(cmsTagDescriptor* TagDescriptor, cmsTagTypeSignature Typ
 // That's the main read function
 void* CMSEXPORT cmsReadTag(cmsHPROFILE hProfile, cmsTagSignature sig)
 {
-    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile; 
+    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
     cmsIOHANDLER* io = Icc ->IOhandler;
     cmsTagTypeHandler* TypeHandler;
     cmsTagDescriptor*  TagDescriptor;
@@ -1370,15 +1368,15 @@ void* CMSEXPORT cmsReadTag(cmsHPROFILE hProfile, cmsTagSignature sig)
 
        // We need to read it. Get the offset and size to the file
     Offset    = Icc -> TagOffsets[n];
-    TagSize   = Icc -> TagSizes[n]; 
-    
+    TagSize   = Icc -> TagSizes[n];
+
     // Seek to its location
     if (!io -> Seek(io, Offset))
             return NULL;
 
     // Search for support on this tag
     TagDescriptor = _cmsGetTagDescriptor(sig);
-    if (TagDescriptor == NULL) return NULL;     // Unsupported. 
+    if (TagDescriptor == NULL) return NULL;     // Unsupported.
 
     // if supported, get type and check if in list
     BaseType = _cmsReadTypeBase(io);
@@ -1412,17 +1410,17 @@ void* CMSEXPORT cmsReadTag(cmsHPROFILE hProfile, cmsTagSignature sig)
     }
 
     // This is a weird error that may be a symptom of something more serious, the number of
-    // stored item is actually less than the number of required elements. 
+    // stored item is actually less than the number of required elements.
     if (ElemCount < TagDescriptor ->ElemCount) {
 
         char String[5];
 
         _cmsTagSignature2String(String, sig);
-        cmsSignalError(Icc ->ContextID, cmsERROR_CORRUPTION_DETECTED, "'%s' Inconsistent number of items: expected %d, got %d", 
+        cmsSignalError(Icc ->ContextID, cmsERROR_CORRUPTION_DETECTED, "'%s' Inconsistent number of items: expected %d, got %d",
                                                              String, TagDescriptor ->ElemCount, ElemCount);
     }
 
-    
+
     // Return the data
     return Icc -> TagPtrs[n];
 }
@@ -1431,8 +1429,8 @@ void* CMSEXPORT cmsReadTag(cmsHPROFILE hProfile, cmsTagSignature sig)
 // Get true type of data
 cmsTagTypeSignature _cmsGetTagTrueType(cmsHPROFILE hProfile, cmsTagSignature sig)
 {
-       _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile; 
-       cmsTagTypeHandler* TypeHandler; 
+       _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
+       cmsTagTypeHandler* TypeHandler;
        int n;
 
        // Search for given tag in ICC profile directory
@@ -1449,7 +1447,7 @@ cmsTagTypeSignature _cmsGetTagTrueType(cmsHPROFILE hProfile, cmsTagSignature sig
 // in that list, the previous version is deleted.
 cmsBool CMSEXPORT cmsWriteTag(cmsHPROFILE hProfile, cmsTagSignature sig, const void* data)
 {
-    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;  
+    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
     cmsTagTypeHandler* TypeHandler = NULL;
     cmsTagDescriptor* TagDescriptor = NULL;
     cmsTagTypeSignature Type;
@@ -1461,9 +1459,9 @@ cmsBool CMSEXPORT cmsWriteTag(cmsHPROFILE hProfile, cmsTagSignature sig, const v
     if (data == NULL) {
 
          i = _cmsSearchTag(Icc, sig, FALSE);
-         if (i >= 0) 
+         if (i >= 0)
              Icc ->TagNames[i] = (cmsTagSignature) 0;
-         // Unsupported by now, reserved for future ampliations (delete)      
+         // Unsupported by now, reserved for future ampliations (delete)
          return FALSE;
     }
 
@@ -1506,21 +1504,21 @@ cmsBool CMSEXPORT cmsWriteTag(cmsHPROFILE hProfile, cmsTagSignature sig, const v
     // This is not a link
     Icc ->TagLinked[i] = (cmsTagSignature) 0;
 
-    // Get information about the TAG. 
+    // Get information about the TAG.
     TagDescriptor = _cmsGetTagDescriptor(sig);
     if (TagDescriptor == NULL){
          cmsSignalError(Icc ->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unsupported tag '%x'", sig);
         return FALSE;
     }
 
-    
-    // Now we need to know which type to use. It depends on the version. 
+
+    // Now we need to know which type to use. It depends on the version.
     Version = cmsGetProfileVersion(hProfile);
 
     if (TagDescriptor ->DecideType != NULL) {
 
         // Let the tag descriptor to decide the type base on depending on
-        // the data. This is useful for example on parametric curves, where 
+        // the data. This is useful for example on parametric curves, where
         // curves specified by a table cannot be saved as parametric and needs
         // to be revented to single v2-curves, even on v4 profiles.
 
@@ -1534,7 +1532,7 @@ cmsBool CMSEXPORT cmsWriteTag(cmsHPROFILE hProfile, cmsTagSignature sig, const v
 
     // Does the tag support this type?
     if (!IsTypeSupported(TagDescriptor, Type)) {
-               
+
         _cmsTagSignature2String(TypeString, (cmsTagSignature) Type);
         _cmsTagSignature2String(SigString,  sig);
 
@@ -1562,21 +1560,21 @@ cmsBool CMSEXPORT cmsWriteTag(cmsHPROFILE hProfile, cmsTagSignature sig, const v
 
     TypeHandler ->ContextID  = Icc ->ContextID;
     TypeHandler ->ICCVersion = Icc ->Version;
-    Icc ->TagPtrs[i]         = TypeHandler ->DupPtr(TypeHandler, data, TagDescriptor ->ElemCount); 
+    Icc ->TagPtrs[i]         = TypeHandler ->DupPtr(TypeHandler, data, TagDescriptor ->ElemCount);
 
     if (Icc ->TagPtrs[i] == NULL)  {
-        
+
         _cmsTagSignature2String(TypeString, (cmsTagSignature) Type);
         _cmsTagSignature2String(SigString,  sig);
         cmsSignalError(Icc ->ContextID, cmsERROR_CORRUPTION_DETECTED, "Malformed struct in type '%s' for tag '%s'", TypeString, SigString);
-        
+
         return FALSE;
     }
-    
+
     return TRUE;
 }
 
-// Read and write raw data. The only way those function would work and keep consistence with normal read and write 
+// Read and write raw data. The only way those function would work and keep consistence with normal read and write
 // is to do an additional step of serialization. That means, readRaw would issue a normal read and then convert the obtained
 // data to raw bytes by using the "write" serialization logic. And vice-versa. I know this may end in situations where
 // raw data written does not exactly correspond with the raw data proposed to cmsWriteRaw data, but this approach allows
@@ -1584,8 +1582,8 @@ cmsBool CMSEXPORT cmsWriteTag(cmsHPROFILE hProfile, cmsTagSignature sig, const v
 
 cmsInt32Number CMSEXPORT cmsReadRawTag(cmsHPROFILE hProfile, cmsTagSignature sig, void* data, cmsUInt32Number BufferSize)
 {
-    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;  
-    void *Object; 
+    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
+    void *Object;
     int i;
     cmsIOHANDLER* MemIO;
     cmsTagTypeHandler* TypeHandler = NULL;
@@ -1604,7 +1602,7 @@ cmsInt32Number CMSEXPORT cmsReadRawTag(cmsHPROFILE hProfile, cmsTagSignature sig
         Offset   = Icc ->TagOffsets[i];
         TagSize  = Icc ->TagSizes[i];
 
-        
+
         // read the data directly, don't keep copy
                if (data != NULL) {
 
@@ -1621,7 +1619,7 @@ cmsInt32Number CMSEXPORT cmsReadRawTag(cmsHPROFILE hProfile, cmsTagSignature sig
     // The data has been already read, or written. But wait!, maybe the user choosed to save as
     // raw data. In this case, return the raw data directly
     if (Icc ->TagSaveAsRaw[i]) {
-               
+
                if (data != NULL)  {
 
                         TagSize  = Icc ->TagSizes[i];
@@ -1634,7 +1632,7 @@ cmsInt32Number CMSEXPORT cmsReadRawTag(cmsHPROFILE hProfile, cmsTagSignature sig
         return Icc ->TagSizes[i];
     }
 
-    // Already readed, or previously set by cmsWriteTag(). We need to serialize that 
+    // Already readed, or previously set by cmsWriteTag(). We need to serialize that
     // data to raw in order to maintain consistency.
     Object = cmsReadTag(hProfile, sig);
     if (Object == NULL) return 0;
@@ -1652,21 +1650,21 @@ cmsInt32Number CMSEXPORT cmsReadRawTag(cmsHPROFILE hProfile, cmsTagSignature sig
     TypeHandler = Icc ->TagTypeHandlers[i];
     TagDescriptor = _cmsGetTagDescriptor(sig);
     if (TagDescriptor == NULL) {
-         cmsCloseIOhandler(MemIO);      
+         cmsCloseIOhandler(MemIO);
          return 0;
     }
-    
+
     // Serialize
     TypeHandler ->ContextID  = Icc ->ContextID;
     TypeHandler ->ICCVersion = Icc ->Version;
 
     if (!_cmsWriteTypeBase(MemIO, TypeHandler ->Signature)) {
-        cmsCloseIOhandler(MemIO);      
-        return 0;    
+        cmsCloseIOhandler(MemIO);
+        return 0;
     }
 
     if (!TypeHandler ->WritePtr(TypeHandler, MemIO, Object, TagDescriptor ->ElemCount)) {
-        cmsCloseIOhandler(MemIO);      
+        cmsCloseIOhandler(MemIO);
         return 0;
     }
 
@@ -1678,12 +1676,12 @@ cmsInt32Number CMSEXPORT cmsReadRawTag(cmsHPROFILE hProfile, cmsTagSignature sig
 }
 
 // Similar to the anterior. This function allows to write directly to the ICC profile any data, without
-// checking anything. As a rule, mixing Raw with cooked doesn't work, so writting a tag as raw and then reading 
+// checking anything. As a rule, mixing Raw with cooked doesn't work, so writting a tag as raw and then reading
 // it as cooked without serializing does result into an error. If that is wha you want, you will need to dump
 // the profile to memry or disk and then reopen it.
 cmsBool CMSEXPORT cmsWriteRawTag(cmsHPROFILE hProfile, cmsTagSignature sig, const void* data, cmsUInt32Number Size)
 {
-    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;  
+    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
     int i;
 
        if (!_cmsNewTag(Icc, sig, &i)) return FALSE;
@@ -1703,7 +1701,7 @@ cmsBool CMSEXPORT cmsWriteRawTag(cmsHPROFILE hProfile, cmsTagSignature sig, cons
 // Using this function you can collapse several tag entries to the same block in the profile
 cmsBool CMSEXPORT cmsLinkTag(cmsHPROFILE hProfile, cmsTagSignature sig, cmsTagSignature dest)
 {
-     _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;  
+     _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
     int i;
 
        if (!_cmsNewTag(Icc, sig, &i)) return FALSE;
@@ -1712,7 +1710,7 @@ cmsBool CMSEXPORT cmsLinkTag(cmsHPROFILE hProfile, cmsTagSignature sig, cmsTagSi
     Icc ->TagSaveAsRaw[i] = FALSE;
     Icc ->TagNames[i]     = sig;
     Icc ->TagLinked[i]    = dest;
-    
+
     Icc ->TagPtrs[i]    = NULL;
     Icc ->TagSizes[i]   = 0;
     Icc ->TagOffsets[i] = 0;
@@ -1724,7 +1722,7 @@ cmsBool CMSEXPORT cmsLinkTag(cmsHPROFILE hProfile, cmsTagSignature sig, cmsTagSi
 // Returns the tag linked to sig, in the case two tags are sharing same resource
 cmsTagSignature  CMSEXPORT cmsTagLinkedTo(cmsHPROFILE hProfile, cmsTagSignature sig)
 {
-    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;  
+    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
     int i;
 
     // Search for given tag in ICC profile directory
index 0787503..12175ee 100644 (file)
@@ -1,24 +1,24 @@
 //---------------------------------------------------------------------------------
 //
 //  Little Color Management System
-//  Copyright (c) 1998-2011 Marti Maria Saguer
+//  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 
+// 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 
+// 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 
+// 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.
 //
 //---------------------------------------------------------------------------------
@@ -56,9 +56,9 @@ static const cmsTagSignature PCS2DeviceFloat[] = {cmsSigBToD0Tag,     // Percept
 
 // Several resources for gray conversions.
 static const cmsFloat64Number GrayInputMatrix[] = { (InpAdj*cmsD50X),  (InpAdj*cmsD50Y),  (InpAdj*cmsD50Z) };
-static const cmsFloat64Number OneToThreeInputMatrix[] = { 1, 1, 1 };   
-static const cmsFloat64Number PickYMatrix[] = { 0, (OutpAdj*cmsD50Y), 0 };   
-static const cmsFloat64Number PickLstarMatrix[] = { 1, 0, 0 };   
+static const cmsFloat64Number OneToThreeInputMatrix[] = { 1, 1, 1 };
+static const cmsFloat64Number PickYMatrix[] = { 0, (OutpAdj*cmsD50Y), 0 };
+static const cmsFloat64Number PickLstarMatrix[] = { 1, 0, 0 };
 
 // Get a media white point fixing some issues found in certain old profiles
 cmsBool  _cmsReadMediaWhitePoint(cmsCIEXYZ* Dest, cmsHPROFILE hProfile)
@@ -67,7 +67,7 @@ cmsBool  _cmsReadMediaWhitePoint(cmsCIEXYZ* Dest, cmsHPROFILE hProfile)
 
     _cmsAssert(Dest != NULL);
 
-    Tag = (cmsCIEXYZ*) cmsReadTag(hProfile, cmsSigMediaWhitePointTag);   
+    Tag = (cmsCIEXYZ*) cmsReadTag(hProfile, cmsSigMediaWhitePointTag);
 
     // If no wp, take D50
     if (Tag == NULL) {
@@ -80,7 +80,7 @@ cmsBool  _cmsReadMediaWhitePoint(cmsCIEXYZ* Dest, cmsHPROFILE hProfile)
 
         if (cmsGetDeviceClass(hProfile) == cmsSigDisplayClass) {
             *Dest = *cmsD50_XYZ();
-            return TRUE;            
+            return TRUE;
         }
     }
 
@@ -113,7 +113,7 @@ cmsBool  _cmsReadCHAD(cmsMAT3* Dest, cmsHPROFILE hProfile)
 
         if (cmsGetDeviceClass(hProfile) == cmsSigDisplayClass) {
 
-            cmsCIEXYZ* White = (cmsCIEXYZ*) cmsReadTag(hProfile, cmsSigMediaWhitePointTag);   
+            cmsCIEXYZ* White = (cmsCIEXYZ*) cmsReadTag(hProfile, cmsSigMediaWhitePointTag);
 
             if (White == NULL) {
 
@@ -141,7 +141,7 @@ cmsBool ReadICCMatrixRGB2XYZ(cmsMAT3* r, cmsHPROFILE hProfile)
     PtrGreen = (cmsCIEXYZ *) cmsReadTag(hProfile, cmsSigGreenColorantTag);
     PtrBlue  = (cmsCIEXYZ *) cmsReadTag(hProfile, cmsSigBlueColorantTag);
 
-    if (PtrRed == NULL || PtrGreen == NULL || PtrBlue == NULL) 
+    if (PtrRed == NULL || PtrGreen == NULL || PtrBlue == NULL)
         return FALSE;
 
     _cmsVEC3init(&r -> v[0], PtrRed -> X, PtrGreen -> X,  PtrBlue -> X);
@@ -159,7 +159,7 @@ cmsPipeline* BuildGrayInputMatrixPipeline(cmsHPROFILE hProfile)
     cmsToneCurve *GrayTRC;
     cmsPipeline* Lut;
     cmsContext ContextID = cmsGetProfileContextID(hProfile);
-    
+
     GrayTRC = (cmsToneCurve *) cmsReadTag(hProfile, cmsSigGrayTRCTag);
     if (GrayTRC == NULL) return NULL;
 
@@ -172,8 +172,8 @@ cmsPipeline* BuildGrayInputMatrixPipeline(cmsHPROFILE hProfile)
         cmsUInt16Number Zero[2] = { 0x8080, 0x8080 };
         cmsToneCurve* EmptyTab;
         cmsToneCurve* LabCurves[3];
-        
-        EmptyTab = cmsBuildTabulatedToneCurve16(ContextID, 2, Zero); 
+
+        EmptyTab = cmsBuildTabulatedToneCurve16(ContextID, 2, Zero);
 
         if (EmptyTab == NULL) {
 
@@ -187,7 +187,7 @@ cmsPipeline* BuildGrayInputMatrixPipeline(cmsHPROFILE hProfile)
 
         cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3,  1, OneToThreeInputMatrix, NULL));
         cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 3, LabCurves));
-        
+
         cmsFreeToneCurve(EmptyTab);
 
     }
@@ -195,7 +195,7 @@ cmsPipeline* BuildGrayInputMatrixPipeline(cmsHPROFILE hProfile)
        cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 1, &GrayTRC));
        cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3,  1, GrayInputMatrix, NULL));
     }
-  
+
     return Lut;
 }
 
@@ -212,15 +212,15 @@ cmsPipeline* BuildRGBInputMatrixShaper(cmsHPROFILE hProfile)
     if (!ReadICCMatrixRGB2XYZ(&Mat, hProfile)) return NULL;
 
     // XYZ PCS in encoded in 1.15 format, and the matrix output comes in 0..0xffff range, so
-    // we need to adjust the output by a factor of (0x10000/0xffff) to put data in 
+    // we need to adjust the output by a factor of (0x10000/0xffff) to put data in
     // a 1.16 range, and then a >> 1 to obtain 1.15. The total factor is (65536.0)/(65535.0*2)
-    
+
     for (i=0; i < 3; i++)
         for (j=0; j < 3; j++)
             Mat.v[i].n[j] *= InpAdj;
-    
 
-    Shapes[0] = (cmsToneCurve *) cmsReadTag(hProfile, cmsSigRedTRCTag);        
+
+    Shapes[0] = (cmsToneCurve *) cmsReadTag(hProfile, cmsSigRedTRCTag);
     Shapes[1] = (cmsToneCurve *) cmsReadTag(hProfile, cmsSigGreenTRCTag);
     Shapes[2] = (cmsToneCurve *) cmsReadTag(hProfile, cmsSigBlueTRCTag);
 
@@ -229,9 +229,18 @@ cmsPipeline* BuildRGBInputMatrixShaper(cmsHPROFILE hProfile)
 
     Lut = cmsPipelineAlloc(ContextID, 3, 3);
     if (Lut != NULL) {
-
+     
         cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 3, Shapes));
         cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3, 3, (cmsFloat64Number*) &Mat, NULL));
+        
+        // Note that it is certainly possible a single profile would have a LUT based
+        // tag for output working in lab and a matrix-shaper for the fallback cases. 
+        // This is not allowed by the spec, but this code is tolerant to those cases    
+        if (cmsGetPCS(hProfile) == cmsSigLabData) {
+
+             cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocXYZ2Lab(ContextID));
+        }
+
     }
 
     return Lut;
@@ -240,7 +249,7 @@ cmsPipeline* BuildRGBInputMatrixShaper(cmsHPROFILE hProfile)
 
 
 // Read the DToAX tag, adjusting the encoding of Lab or XYZ if neded
-static
+/*static
 cmsPipeline* _cmsReadFloatInputTag(cmsHPROFILE hProfile, cmsTagSignature tagFloat)
 {
     cmsContext ContextID       = cmsGetProfileContextID(hProfile);
@@ -260,6 +269,39 @@ cmsPipeline* _cmsReadFloatInputTag(cmsHPROFILE hProfile, cmsTagSignature tagFloa
         {
             cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID));
         }
+
+    return Lut;
+}
+*/
+static
+cmsPipeline* _cmsReadFloatInputTag(cmsHPROFILE hProfile, cmsTagSignature tagFloat)
+{
+    cmsContext ContextID       = cmsGetProfileContextID(hProfile);
+    cmsPipeline* Lut           = cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat));
+    cmsColorSpaceSignature spc = cmsGetColorSpace(hProfile);
+    cmsColorSpaceSignature PCS = cmsGetPCS(hProfile);
+    
+    if (Lut == NULL) return NULL;
+    
+    // input and output of transform are in lcms 0..1 encoding.  If XYZ or Lab spaces are used, 
+    //  these need to be normalized into the appropriate ranges (Lab = 100,0,0, XYZ=1.0,1.0,1.0)
+    if ( spc == cmsSigLabData)
+    {
+        cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToLabFloat(ContextID));
+    }
+    else if (spc == cmsSigXYZData)
+    {
+        cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToXyzFloat(ContextID));
+    }
+    
+    if ( PCS == cmsSigLabData)
+    {
+        cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromLabFloat(ContextID));
+    }
+    else if( PCS == cmsSigXYZData)
+    {
+        cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID));
+    }
     
     return Lut;
 }
@@ -277,7 +319,7 @@ cmsPipeline* _cmsReadInputLUT(cmsHPROFILE hProfile, int Intent)
     // On named color, take the appropiate tag
     if (cmsGetDeviceClass(hProfile) == cmsSigNamedColorClass) {
 
-        cmsPipeline* Lut; 
+        cmsPipeline* Lut;
         cmsNAMEDCOLORLIST* nc = (cmsNAMEDCOLORLIST*) cmsReadTag(hProfile, cmsSigNamedColor2Tag);
 
         if (nc == NULL) return NULL;
@@ -295,8 +337,8 @@ cmsPipeline* _cmsReadInputLUT(cmsHPROFILE hProfile, int Intent)
 
     if (cmsIsTag(hProfile, tagFloat)) {  // Float tag takes precedence
 
-        // Floating point LUT are always V4, but the encoding range is no 
-        // longer 0..1.0, so we need to add an stage depending on the color space        
+        // Floating point LUT are always V4, but the encoding range is no
+        // longer 0..1.0, so we need to add an stage depending on the color space
          return _cmsReadFloatInputTag(hProfile, tagFloat);
     }
 
@@ -320,7 +362,7 @@ cmsPipeline* _cmsReadInputLUT(cmsHPROFILE hProfile, int Intent)
         Lut = cmsPipelineDup(Lut);
 
         // We need to adjust data only for Lab16 on output
-        if (OriginalType != cmsSigLut16Type || cmsGetPCS(hProfile) != cmsSigLabData) 
+        if (OriginalType != cmsSigLut16Type || cmsGetPCS(hProfile) != cmsSigLabData)
             return Lut;
 
         // If the input is Lab, add also a conversion at the begin
@@ -330,25 +372,25 @@ cmsPipeline* _cmsReadInputLUT(cmsHPROFILE hProfile, int Intent)
         // Add a matrix for conversion V2 to V4 Lab PCS
         cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID));
         return Lut;
-    }   
+    }
 
     // Lut was not found, try to create a matrix-shaper
 
     // Check if this is a grayscale profile.
     if (cmsGetColorSpace(hProfile) == cmsSigGrayData) {
 
-        // if so, build appropiate conversion tables. 
+        // if so, build appropiate conversion tables.
         // The tables are the PCS iluminant, scaled across GrayTRC
-        return BuildGrayInputMatrixPipeline(hProfile);              
+        return BuildGrayInputMatrixPipeline(hProfile);
     }
 
-    // Not gray, create a normal matrix-shaper 
+    // Not gray, create a normal matrix-shaper
     return BuildRGBInputMatrixShaper(hProfile);
 }
 
 // ---------------------------------------------------------------------------------------------------------------
 
-// Gray output pipeline. 
+// Gray output pipeline.
 // XYZ -> Gray or Lab -> Gray. Since we only know the GrayTRC, we need to do some assumptions. Gray component will be
 // given by Y on XYZ PCS and by L* on Lab PCS, Both across inverse TRC curve.
 // The complete pipeline on XYZ is Matrix[3:1] -> Tone curve and in Lab Matrix[3:1] -> Tone Curve as well.
@@ -360,7 +402,7 @@ cmsPipeline* BuildGrayOutputPipeline(cmsHPROFILE hProfile)
     cmsPipeline* Lut;
     cmsContext ContextID = cmsGetProfileContextID(hProfile);
 
-    GrayTRC = (cmsToneCurve *) cmsReadTag(hProfile, cmsSigGrayTRCTag);       
+    GrayTRC = (cmsToneCurve *) cmsReadTag(hProfile, cmsSigGrayTRCTag);
     if (GrayTRC == NULL) return NULL;
 
     RevGrayTRC = cmsReverseToneCurve(GrayTRC);
@@ -405,14 +447,14 @@ cmsPipeline* BuildRGBOutputMatrixShaper(cmsHPROFILE hProfile)
         return NULL;
 
     // XYZ PCS in encoded in 1.15 format, and the matrix input should come in 0..0xffff range, so
-    // we need to adjust the input by a << 1 to obtain a 1.16 fixed and then by a factor of 
+    // we need to adjust the input by a << 1 to obtain a 1.16 fixed and then by a factor of
     // (0xffff/0x10000) to put data in 0..0xffff range. Total factor is (2.0*65535.0)/65536.0;
 
     for (i=0; i < 3; i++)
         for (j=0; j < 3; j++)
             Inv.v[i].n[j] *= OutpAdj;
 
-    Shapes[0] = (cmsToneCurve *) cmsReadTag(hProfile, cmsSigRedTRCTag);        
+    Shapes[0] = (cmsToneCurve *) cmsReadTag(hProfile, cmsSigRedTRCTag);
     Shapes[1] = (cmsToneCurve *) cmsReadTag(hProfile, cmsSigGreenTRCTag);
     Shapes[2] = (cmsToneCurve *) cmsReadTag(hProfile, cmsSigBlueTRCTag);
 
@@ -423,13 +465,21 @@ cmsPipeline* BuildRGBOutputMatrixShaper(cmsHPROFILE hProfile)
     InvShapes[1] = cmsReverseToneCurve(Shapes[1]);
     InvShapes[2] = cmsReverseToneCurve(Shapes[2]);
 
-    if (!InvShapes[0] || !InvShapes[1] || !InvShapes[2]) {      
+    if (!InvShapes[0] || !InvShapes[1] || !InvShapes[2]) {
         return NULL;
     }
 
     Lut = cmsPipelineAlloc(ContextID, 3, 3);
     if (Lut != NULL) {
 
+        // Note that it is certainly possible a single profile would have a LUT based
+        // tag for output working in lab and a matrix-shaper for the fallback cases. 
+        // This is not allowed by the spec, but this code is tolerant to those cases    
+        if (cmsGetPCS(hProfile) == cmsSigLabData) {
+
+             cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLab2XYZ(ContextID));
+        }
+
         cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3, 3, (cmsFloat64Number*) &Inv, NULL));
         cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 3, InvShapes));
     }
@@ -461,7 +511,7 @@ void ChangeInterpolationToTrilinear(cmsPipeline* Lut)
 
 
 // Read the DToAX tag, adjusting the encoding of Lab or XYZ if neded
-static
+/*static
 cmsPipeline* _cmsReadFloatOutputTag(cmsHPROFILE hProfile, cmsTagSignature tagFloat)
 {
     cmsContext ContextID       = cmsGetProfileContextID(hProfile);
@@ -481,6 +531,41 @@ cmsPipeline* _cmsReadFloatOutputTag(cmsHPROFILE hProfile, cmsTagSignature tagFlo
         {
             cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToXyzFloat(ContextID));
         }
+
+    return Lut;
+}*/
+
+static
+cmsPipeline* _cmsReadFloatOutputTag(cmsHPROFILE hProfile, cmsTagSignature tagFloat)
+{
+    cmsContext ContextID       = cmsGetProfileContextID(hProfile);
+    cmsPipeline* Lut           = cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat));
+    cmsColorSpaceSignature PCS = cmsGetPCS(hProfile);
+    cmsColorSpaceSignature dataSpace = cmsGetColorSpace(hProfile);
+    
+    if (Lut == NULL) return NULL;
+    
+    // If PCS is Lab or XYZ, the floating point tag is accepting data in the space encoding,
+    // and since the formatter has already accomodated to 0..1.0, we should undo this change
+    if ( PCS == cmsSigLabData)
+    {
+        cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToLabFloat(ContextID));
+    }
+    else
+        if (PCS == cmsSigXYZData)
+        {
+            cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToXyzFloat(ContextID));
+        }
+    
+    // the output can be Lab or XYZ, in which case normalisation is needed on the end of the pipeline
+    if ( dataSpace == cmsSigLabData)
+    {
+        cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromLabFloat(ContextID));
+    }
+    else if ( dataSpace == cmsSigXYZData)
+    {
+        cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID));
+    }
     
     return Lut;
 }
@@ -519,13 +604,13 @@ cmsPipeline* _cmsReadOutputLUT(cmsHPROFILE hProfile, int Intent)
         Lut = cmsPipelineDup(Lut);
         if (Lut == NULL) return NULL;
 
-        // Now it is time for a controversial stuff. I found that for 3D LUTS using 
-        // Lab used as indexer space,  trilinear interpolation should be used         
+        // Now it is time for a controversial stuff. I found that for 3D LUTS using
+        // Lab used as indexer space,  trilinear interpolation should be used
         if (cmsGetPCS(hProfile) == cmsSigLabData)
-                             ChangeInterpolationToTrilinear(Lut);       
+                             ChangeInterpolationToTrilinear(Lut);
 
         // We need to adjust data only for Lab and Lut16 type
-        if (OriginalType != cmsSigLut16Type || cmsGetPCS(hProfile) != cmsSigLabData) 
+        if (OriginalType != cmsSigLut16Type || cmsGetPCS(hProfile) != cmsSigLabData)
             return Lut;
 
         // Add a matrix for conversion V4 to V2 Lab PCS
@@ -536,19 +621,19 @@ cmsPipeline* _cmsReadOutputLUT(cmsHPROFILE hProfile, int Intent)
             cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID));
 
         return Lut;
-    }   
+    }
 
     // Lut not found, try to create a matrix-shaper
 
     // Check if this is a grayscale profile.
      if (cmsGetColorSpace(hProfile) == cmsSigGrayData) {
 
-              // if so, build appropiate conversion tables. 
+              // if so, build appropiate conversion tables.
               // The tables are the PCS iluminant, scaled across GrayTRC
-              return BuildGrayOutputPipeline(hProfile);              
+              return BuildGrayOutputPipeline(hProfile);
     }
 
-    // Not gray, create a normal matrix-shaper 
+    // Not gray, create a normal matrix-shaper, which only operates in XYZ space  
     return BuildRGBOutputMatrixShaper(hProfile);
 }
 
@@ -588,7 +673,7 @@ cmsPipeline* _cmsReadFloatDevicelinkTag(cmsHPROFILE hProfile, cmsTagSignature ta
             return Lut;
 }
 
-// This one includes abstract profiles as well. Matrix-shaper cannot be obtained on that device class. The 
+// This one includes abstract profiles as well. Matrix-shaper cannot be obtained on that device class. The
 // tag name here may default to AToB0
 cmsPipeline* _cmsReadDevicelinkLUT(cmsHPROFILE hProfile, int Intent)
 {
@@ -601,7 +686,7 @@ cmsPipeline* _cmsReadDevicelinkLUT(cmsHPROFILE hProfile, int Intent)
 
     // On named color, take the appropiate tag
     if (cmsGetDeviceClass(hProfile) == cmsSigNamedColorClass) {
+
         cmsNAMEDCOLORLIST* nc = (cmsNAMEDCOLORLIST*) cmsReadTag(hProfile, cmsSigNamedColor2Tag);
 
         if (nc == NULL) return NULL;
@@ -620,20 +705,20 @@ cmsPipeline* _cmsReadDevicelinkLUT(cmsHPROFILE hProfile, int Intent)
 
     if (cmsIsTag(hProfile, tagFloat)) {  // Float tag takes precedence
 
-        // Floating point LUT are always V        
+        // Floating point LUT are always V
         return _cmsReadFloatDevicelinkTag(hProfile, tagFloat);
     }
 
     tagFloat = Device2PCSFloat[0];
-    if (cmsIsTag(hProfile, tagFloat)) {  
-        
+    if (cmsIsTag(hProfile, tagFloat)) {
+
         return cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat));
     }
 
     if (!cmsIsTag(hProfile, tag16)) {  // Is there any LUT-Based table?
-        
+
         tag16    = Device2PCS16[0];
-        if (!cmsIsTag(hProfile, tag16)) return NULL;        
+        if (!cmsIsTag(hProfile, tag16)) return NULL;
     }
 
     // Check profile version and LUT type. Do the necessary adjustments if needed
@@ -646,17 +731,17 @@ cmsPipeline* _cmsReadDevicelinkLUT(cmsHPROFILE hProfile, int Intent)
     Lut = cmsPipelineDup(Lut);
     if (Lut == NULL) return NULL;
 
-     // Now it is time for a controversial stuff. I found that for 3D LUTS using 
-     // Lab used as indexer space,  trilinear interpolation should be used         
+     // Now it is time for a controversial stuff. I found that for 3D LUTS using
+     // Lab used as indexer space,  trilinear interpolation should be used
     if (cmsGetColorSpace(hProfile) == cmsSigLabData)
-                        ChangeInterpolationToTrilinear(Lut);    
+                        ChangeInterpolationToTrilinear(Lut);
 
     // After reading it, we have info about the original type
     OriginalType =  _cmsGetTagTrueType(hProfile, tag16);
 
     // We need to adjust data for Lab16 on output
     if (OriginalType != cmsSigLut16Type) return Lut;
-        
+
     // Here it is possible to get Lab on both sides
 
     if (cmsGetPCS(hProfile) == cmsSigLabData) {
@@ -676,11 +761,11 @@ cmsPipeline* _cmsReadDevicelinkLUT(cmsHPROFILE hProfile, int Intent)
 
 // Returns TRUE if the profile is implemented as matrix-shaper
 cmsBool  CMSEXPORT cmsIsMatrixShaper(cmsHPROFILE hProfile)
-{    
+{
     switch (cmsGetColorSpace(hProfile)) {
 
     case cmsSigGrayData:
-        
+
         return cmsIsTag(hProfile, cmsSigGrayTRCTag);
 
     case cmsSigRgbData:
@@ -700,7 +785,7 @@ cmsBool  CMSEXPORT cmsIsMatrixShaper(cmsHPROFILE hProfile)
 
 // Returns TRUE if the intent is implemented as CLUT
 cmsBool  CMSEXPORT cmsIsCLUT(cmsHPROFILE hProfile, cmsUInt32Number Intent, cmsUInt32Number UsedDirection)
-{    
+{
     const cmsTagSignature* TagTable;
 
     // For devicelinks, the supported intent is that one stated in the header
@@ -711,10 +796,10 @@ cmsBool  CMSEXPORT cmsIsCLUT(cmsHPROFILE hProfile, cmsUInt32Number Intent, cmsUI
     switch (UsedDirection) {
 
        case LCMS_USED_AS_INPUT: TagTable = Device2PCS16; break;
-       case LCMS_USED_AS_OUTPUT:TagTable = PCS2Device16; break; 
+       case LCMS_USED_AS_OUTPUT:TagTable = PCS2Device16; break;
 
        // For proofing, we need rel. colorimetric in output. Let's do some recursion
-       case LCMS_USED_AS_PROOF: 
+       case LCMS_USED_AS_PROOF:
            return cmsIsIntentSupported(hProfile, Intent, LCMS_USED_AS_INPUT) &&
                   cmsIsIntentSupported(hProfile, INTENT_RELATIVE_COLORIMETRIC, LCMS_USED_AS_OUTPUT);
 
@@ -766,7 +851,7 @@ cmsSEQ* _cmsReadProfileSequence(cmsHPROFILE hProfile)
     if (ProfileSeq == NULL) return cmsDupProfileSequenceDescription(ProfileId);
     if (ProfileId  == NULL) return cmsDupProfileSequenceDescription(ProfileSeq);
 
-    // We have to mix both together. For that they must agree 
+    // We have to mix both together. For that they must agree
     if (ProfileSeq ->n != ProfileId ->n) return cmsDupProfileSequenceDescription(ProfileSeq);
 
     NewSeq = cmsDupProfileSequenceDescription(ProfileSeq);
@@ -819,22 +904,22 @@ cmsSEQ* _cmsCompileProfileSequence(cmsContext ContextID, cmsUInt32Number nProfil
         cmsPSEQDESC* ps = &seq ->seq[i];
         cmsHPROFILE h = hProfiles[i];
         cmsTechnologySignature* techpt;
-        
+
         cmsGetHeaderAttributes(h, &ps ->attributes);
-        cmsGetHeaderProfileID(h, ps ->ProfileID.ID8);       
+        cmsGetHeaderProfileID(h, ps ->ProfileID.ID8);
         ps ->deviceMfg   = cmsGetHeaderManufacturer(h);
         ps ->deviceModel = cmsGetHeaderModel(h);
-        
+
         techpt = (cmsTechnologySignature*) cmsReadTag(h, cmsSigTechnologyTag);
         if (techpt == NULL)
             ps ->technology   =  (cmsTechnologySignature) 0;
         else
             ps ->technology   = *techpt;
-                
+
         ps ->Manufacturer = GetMLUFromProfile(h,  cmsSigDeviceMfgDescTag);
-        ps ->Model        = GetMLUFromProfile(h,  cmsSigDeviceModelDescTag);        
+        ps ->Model        = GetMLUFromProfile(h,  cmsSigDeviceModelDescTag);
         ps ->Description  = GetMLUFromProfile(h, cmsSigProfileDescriptionTag);
-        
+
     }
 
     return seq;
@@ -851,7 +936,7 @@ const cmsMLU* GetInfo(cmsHPROFILE hProfile, cmsInfoType Info)
     switch (Info) {
 
     case cmsInfoDescription:
-        sig = cmsSigProfileDescriptionTag; 
+        sig = cmsSigProfileDescriptionTag;
         break;
 
     case cmsInfoManufacturer:
@@ -875,8 +960,8 @@ const cmsMLU* GetInfo(cmsHPROFILE hProfile, cmsInfoType Info)
 
 
 
-cmsUInt32Number CMSEXPORT cmsGetProfileInfo(cmsHPROFILE hProfile, cmsInfoType Info, 
-                                            const char LanguageCode[3], const char CountryCode[3], 
+cmsUInt32Number CMSEXPORT cmsGetProfileInfo(cmsHPROFILE hProfile, cmsInfoType Info,
+                                            const char LanguageCode[3], const char CountryCode[3],
                                             wchar_t* Buffer, cmsUInt32Number BufferSize)
 {
     const cmsMLU* mlu = GetInfo(hProfile, Info);
@@ -886,8 +971,8 @@ cmsUInt32Number CMSEXPORT cmsGetProfileInfo(cmsHPROFILE hProfile, cmsInfoType In
 }
 
 
-cmsUInt32Number  CMSEXPORT cmsGetProfileInfoASCII(cmsHPROFILE hProfile, cmsInfoType Info, 
-                                                          const char LanguageCode[3], const char CountryCode[3], 
+cmsUInt32Number  CMSEXPORT cmsGetProfileInfoASCII(cmsHPROFILE hProfile, cmsInfoType Info,
+                                                          const char LanguageCode[3], const char CountryCode[3],
                                                           char* Buffer, cmsUInt32Number BufferSize)
 {
     const cmsMLU* mlu = GetInfo(hProfile, Info);
index 52204be..b421456 100644 (file)
@@ -1,24 +1,24 @@
 //---------------------------------------------------------------------------------
 //
 //  Little Color Management System
-//  Copyright (c) 1998-2011 Marti Maria Saguer
+//  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 
+// 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 
+// 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 
+// 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.
 //
 //---------------------------------------------------------------------------------
 
 
 // Allocates an empty multi profile element
-cmsStage* CMSEXPORT _cmsStageAllocPlaceholder(cmsContext ContextID, 
+cmsStage* CMSEXPORT _cmsStageAllocPlaceholder(cmsContext ContextID,
                                 cmsStageSignature Type,
-                                cmsUInt32Number InputChannels, 
+                                cmsUInt32Number InputChannels,
                                 cmsUInt32Number OutputChannels,
-                                _cmsStageEvalFn     EvalPtr,           
-                                _cmsStageDupElemFn  DupElemPtr,        
-                                _cmsStageFreeElemFn FreePtr,           
-                                void*             Data)             
+                                _cmsStageEvalFn     EvalPtr,
+                                _cmsStageDupElemFn  DupElemPtr,
+                                _cmsStageFreeElemFn FreePtr,
+                                void*             Data)
 {
     cmsStage* ph = (cmsStage*) _cmsMallocZero(ContextID, sizeof(cmsStage));
 
     if (ph == NULL) return NULL;
-    
-    
+
+
     ph ->ContextID = ContextID;
 
     ph ->Type       = Type;
@@ -49,18 +49,18 @@ cmsStage* CMSEXPORT _cmsStageAllocPlaceholder(cmsContext ContextID,
 
     ph ->InputChannels  = InputChannels;
     ph ->OutputChannels = OutputChannels;
-    ph ->EvalPtr        = EvalPtr;      
-    ph ->DupElemPtr     = DupElemPtr;   
-    ph ->FreePtr        = FreePtr;               
+    ph ->EvalPtr        = EvalPtr;
+    ph ->DupElemPtr     = DupElemPtr;
+    ph ->FreePtr        = FreePtr;
     ph ->Data           = Data;
 
-    return ph; 
+    return ph;
 }
 
 
 static
-void EvaluateIdentity(const cmsFloat32Number In[], 
-                            cmsFloat32Number Out[], 
+void EvaluateIdentity(const cmsFloat32Number In[],
+                            cmsFloat32Number Out[],
                       const cmsStage *mpe)
 {
     memmove(Out, In, mpe ->InputChannels * sizeof(cmsFloat32Number));
@@ -69,10 +69,10 @@ void EvaluateIdentity(const cmsFloat32Number In[],
 
 cmsStage* CMSEXPORT cmsStageAllocIdentity(cmsContext ContextID, cmsUInt32Number nChannels)
 {
-    return _cmsStageAllocPlaceholder(ContextID, 
-                                   cmsSigIdentityElemType, 
+    return _cmsStageAllocPlaceholder(ContextID,
+                                   cmsSigIdentityElemType,
                                    nChannels, nChannels,
-                                   EvaluateIdentity,                            
+                                   EvaluateIdentity,
                                    NULL,
                                    NULL,
                                    NULL);
@@ -84,8 +84,8 @@ void FromFloatTo16(const cmsFloat32Number In[], cmsUInt16Number Out[], cmsUInt32
 {
     cmsUInt32Number i;
 
-    for (i=0; i < n; i++) {     
-        Out[i] = _cmsQuickSaturateWord(In[i] * 65535.0);        
+    for (i=0; i < n; i++) {
+        Out[i] = _cmsQuickSaturateWord(In[i] * 65535.0);
     }
 }
 
@@ -105,7 +105,7 @@ void From16ToFloat(const cmsUInt16Number In[], cmsFloat32Number Out[], cmsUInt32
 // that conform the LUT. It should be called with the LUT, the number of expected elements and
 // then a list of expected types followed with a list of cmsFloat64Number pointers to MPE elements. If
 // the function founds a match with current pipeline, it fills the pointers and returns TRUE
-// if not, returns FALSE without touching anything. Setting pointers to NULL does bypass 
+// if not, returns FALSE without touching anything. Setting pointers to NULL does bypass
 // the storage process.
 cmsBool  CMSEXPORT cmsPipelineCheckAndRetreiveStages(const cmsPipeline* Lut, cmsUInt32Number n, ...)
 {
@@ -125,11 +125,11 @@ cmsBool  CMSEXPORT cmsPipelineCheckAndRetreiveStages(const cmsPipeline* Lut, cms
     for (i=0; i < n; i++) {
 
         // Get asked type
-        Type  = (cmsStageSignature)va_arg(args, cmsStageSignature);      
+        Type  = (cmsStageSignature)va_arg(args, cmsStageSignature);
         if (mpe ->Type != Type) {
 
             va_end(args);       // Mismatch. We are done.
-            return FALSE;       
+            return FALSE;
         }
         mpe = mpe ->Next;
     }
@@ -138,14 +138,14 @@ cmsBool  CMSEXPORT cmsPipelineCheckAndRetreiveStages(const cmsPipeline* Lut, cms
     mpe = Lut ->Elements;
     for (i=0; i < n; i++) {
 
-        ElemPtr = va_arg(args, void**);     
-        if (ElemPtr != NULL) 
+        ElemPtr = va_arg(args, void**);
+        if (ElemPtr != NULL)
             *ElemPtr = mpe;
 
         mpe = mpe ->Next;
     }
 
-    va_end(args);   
+    va_end(args);
     return TRUE;
 }
 
@@ -164,8 +164,8 @@ cmsToneCurve** _cmsStageGetPtrToCurveSet(const cmsStage* mpe)
 }
 
 static
-void EvaluateCurves(const cmsFloat32Number In[], 
-                    cmsFloat32Number Out[], 
+void EvaluateCurves(const cmsFloat32Number In[],
+                    cmsFloat32Number Out[],
                     const cmsStage *mpe)
 {
     _cmsStageToneCurvesData* Data;
@@ -196,7 +196,7 @@ void CurveSetElemTypeFree(cmsStage* mpe)
 
     if (Data ->TheCurves != NULL) {
         for (i=0; i < Data ->nCurves; i++) {
-            if (Data ->TheCurves[i] != NULL) 
+            if (Data ->TheCurves[i] != NULL)
                 cmsFreeToneCurve(Data ->TheCurves[i]);
         }
     }
@@ -232,7 +232,7 @@ void* CurveSetDup(cmsStage* mpe)
 
 Error:
 
-    if (NewElem ->TheCurves != NULL) { 
+    if (NewElem ->TheCurves != NULL) {
         for (i=0; i < NewElem ->nCurves; i++) {
             if (NewElem ->TheCurves[i])
                 cmsFreeToneCurve(Data ->TheCurves[i]);
@@ -250,24 +250,24 @@ cmsStage* CMSEXPORT cmsStageAllocToneCurves(cmsContext ContextID, cmsUInt32Numbe
     cmsUInt32Number i;
     _cmsStageToneCurvesData* NewElem;
     cmsStage* NewMPE;
-    
-    
+
+
     NewMPE = _cmsStageAllocPlaceholder(ContextID, cmsSigCurveSetElemType, nChannels, nChannels,
                                      EvaluateCurves, CurveSetDup, CurveSetElemTypeFree, NULL );
     if (NewMPE == NULL) return NULL;
 
     NewElem = (_cmsStageToneCurvesData*) _cmsMallocZero(ContextID, sizeof(_cmsStageToneCurvesData));
     if (NewElem == NULL) {
-        cmsStageFree(NewMPE); 
+        cmsStageFree(NewMPE);
         return NULL;
     }
+
     NewMPE ->Data  = (void*) NewElem;
 
     NewElem ->nCurves   = nChannels;
     NewElem ->TheCurves = (cmsToneCurve**) _cmsCalloc(ContextID, nChannels, sizeof(cmsToneCurve*));
     if (NewElem ->TheCurves == NULL) {
-        cmsStageFree(NewMPE); 
+        cmsStageFree(NewMPE);
         return NULL;
     }
 
@@ -281,9 +281,10 @@ cmsStage* CMSEXPORT cmsStageAllocToneCurves(cmsContext ContextID, cmsUInt32Numbe
         }
 
         if (NewElem ->TheCurves[i] == NULL) {
-            cmsStageFree(NewMPE); 
+            cmsStageFree(NewMPE);
             return NULL;
         }
+
     }
 
    return NewMPE;
@@ -294,7 +295,7 @@ cmsStage* CMSEXPORT cmsStageAllocToneCurves(cmsContext ContextID, cmsUInt32Numbe
 cmsStage* _cmsStageAllocIdentityCurves(cmsContext ContextID, int nChannels)
 {
     cmsStage* mpe = cmsStageAllocToneCurves(ContextID, nChannels, NULL);
-    
+
     if (mpe == NULL) return NULL;
     mpe ->Implements = cmsSigIdentityElemType;
     return mpe;
@@ -308,8 +309,8 @@ cmsStage* _cmsStageAllocIdentityCurves(cmsContext ContextID, int nChannels)
 
 // Special care should be taken here because precision loss. A temporary cmsFloat64Number buffer is being used
 static
-void EvaluateMatrix(const cmsFloat32Number In[], 
-                    cmsFloat32Number Out[], 
+void EvaluateMatrix(const cmsFloat32Number In[],
+                    cmsFloat32Number Out[],
                     const cmsStage *mpe)
 {
     cmsUInt32Number i, j;
@@ -324,10 +325,10 @@ void EvaluateMatrix(const cmsFloat32Number In[],
             Tmp += In[j] * Data->Double[i*mpe->InputChannels + j];
         }
 
-        if (Data ->Offset != NULL) 
+        if (Data ->Offset != NULL)
             Tmp += Data->Offset[i];
 
-        Out[i] = (cmsFloat32Number) Tmp;     
+        Out[i] = (cmsFloat32Number) Tmp;
     }
 
 
@@ -342,7 +343,7 @@ void* MatrixElemDup(cmsStage* mpe)
     _cmsStageMatrixData* Data = (_cmsStageMatrixData*) mpe ->Data;
     _cmsStageMatrixData* NewElem;
     cmsUInt32Number sz;
-    
+
     NewElem = (_cmsStageMatrixData*) _cmsMallocZero(mpe ->ContextID, sizeof(_cmsStageMatrixData));
     if (NewElem == NULL) return NULL;
 
@@ -351,7 +352,7 @@ void* MatrixElemDup(cmsStage* mpe)
     NewElem ->Double = (cmsFloat64Number*) _cmsDupMem(mpe ->ContextID, Data ->Double, sz * sizeof(cmsFloat64Number)) ;
 
     if (Data ->Offset)
-        NewElem ->Offset = (cmsFloat64Number*) _cmsDupMem(mpe ->ContextID, 
+        NewElem ->Offset = (cmsFloat64Number*) _cmsDupMem(mpe ->ContextID,
                                                 Data ->Offset, mpe -> OutputChannels * sizeof(cmsFloat64Number)) ;
 
     return (void*) NewElem;
@@ -373,7 +374,7 @@ void MatrixElemTypeFree(cmsStage* mpe)
 
 
 
-cmsStage*  CMSEXPORT cmsStageAllocMatrix(cmsContext ContextID, cmsUInt32Number Rows, cmsUInt32Number Cols, 
+cmsStage*  CMSEXPORT cmsStageAllocMatrix(cmsContext ContextID, cmsUInt32Number Rows, cmsUInt32Number Cols,
                                      const cmsFloat64Number* Matrix, const cmsFloat64Number* Offset)
 {
     cmsUInt32Number i, n;
@@ -392,10 +393,10 @@ cmsStage*  CMSEXPORT cmsStageAllocMatrix(cmsContext ContextID, cmsUInt32Number R
                                      EvaluateMatrix, MatrixElemDup, MatrixElemTypeFree, NULL );
     if (NewMPE == NULL) return NULL;
 
-   
+
     NewElem = (_cmsStageMatrixData*) _cmsMallocZero(ContextID, sizeof(_cmsStageMatrixData));
     if (NewElem == NULL) return NULL;
-  
+
 
     NewElem ->Double = (cmsFloat64Number*) _cmsCalloc(ContextID, n, sizeof(cmsFloat64Number));
 
@@ -410,7 +411,7 @@ cmsStage*  CMSEXPORT cmsStageAllocMatrix(cmsContext ContextID, cmsUInt32Number R
 
 
     if (Offset != NULL) {
-    
+
         NewElem ->Offset = (cmsFloat64Number*) _cmsCalloc(ContextID, Cols, sizeof(cmsFloat64Number));
         if (NewElem->Offset == NULL) {
            MatrixElemTypeFree(NewMPE);
@@ -422,7 +423,7 @@ cmsStage*  CMSEXPORT cmsStageAllocMatrix(cmsContext ContextID, cmsUInt32Number R
         }
 
     }
-    
+
     NewMPE ->Data  = (void*) NewElem;
     return NewMPE;
 }
@@ -437,7 +438,7 @@ cmsStage*  CMSEXPORT cmsStageAllocMatrix(cmsContext ContextID, cmsUInt32Number R
 static
 void EvaluateCLUTfloat(const cmsFloat32Number In[], cmsFloat32Number Out[], const cmsStage *mpe)
 {
-    _cmsStageCLutData* Data = (_cmsStageCLutData*) mpe ->Data;  
+    _cmsStageCLutData* Data = (_cmsStageCLutData*) mpe ->Data;
 
     Data -> Params ->Interpolation.LerpFloat(In, Out, Data->Params);
 }
@@ -449,11 +450,11 @@ void EvaluateCLUTfloatIn16(const cmsFloat32Number In[], cmsFloat32Number Out[],
 {
     _cmsStageCLutData* Data = (_cmsStageCLutData*) mpe ->Data;
     cmsUInt16Number In16[MAX_STAGE_CHANNELS], Out16[MAX_STAGE_CHANNELS];
-    
+
     _cmsAssert(mpe ->InputChannels  <= MAX_STAGE_CHANNELS);
     _cmsAssert(mpe ->OutputChannels <= MAX_STAGE_CHANNELS);
 
-    FromFloatTo16(In, In16, mpe ->InputChannels);   
+    FromFloatTo16(In, In16, mpe ->InputChannels);
     Data -> Params ->Interpolation.Lerp16(In16, Out16, Data->Params);
     From16ToFloat(Out16, Out,  mpe ->OutputChannels);
 }
@@ -486,8 +487,8 @@ void* CLUTElemDup(cmsStage* mpe)
 {
     _cmsStageCLutData* Data = (_cmsStageCLutData*) mpe ->Data;
     _cmsStageCLutData* NewElem;
-    
-    
+
+
     NewElem = (_cmsStageCLutData*) _cmsMallocZero(mpe ->ContextID, sizeof(_cmsStageCLutData));
     if (NewElem == NULL) return NULL;
 
@@ -501,11 +502,11 @@ void* CLUTElemDup(cmsStage* mpe)
         else
             NewElem ->Tab.T = (cmsUInt16Number*) _cmsDupMem(mpe ->ContextID, Data ->Tab.T, Data ->nEntries * sizeof (cmsUInt16Number));
     }
-    
+
     NewElem ->Params   = _cmsComputeInterpParamsEx(mpe ->ContextID,
-                                                   Data ->Params ->nSamples, 
+                                                   Data ->Params ->nSamples,
                                                    Data ->Params ->nInputs,
-                                                   Data ->Params ->nOutputs, 
+                                                   Data ->Params ->nOutputs,
                                                    NewElem ->Tab.T,
                                                    Data ->Params ->dwFlags);
 
@@ -518,7 +519,7 @@ void CLutElemTypeFree(cmsStage* mpe)
 {
 
     _cmsStageCLutData* Data = (_cmsStageCLutData*) mpe ->Data;
-    
+
     // Already empty
     if (Data == NULL) return;
 
@@ -526,23 +527,30 @@ void CLutElemTypeFree(cmsStage* mpe)
     if (Data -> Tab.T)
         _cmsFree(mpe ->ContextID, Data -> Tab.T);
 
-    _cmsFreeInterpParams(Data ->Params);    
+    _cmsFreeInterpParams(Data ->Params);
     _cmsFree(mpe ->ContextID, mpe ->Data);
 }
 
 
 // Allocates a 16-bit multidimensional CLUT. This is evaluated at 16-bit precision. Table may have different
 // granularity on each dimension.
-cmsStage* CMSEXPORT cmsStageAllocCLut16bitGranular(cmsContext ContextID, 
-                                         const cmsUInt32Number clutPoints[], 
-                                         cmsUInt32Number inputChan, 
-                                         cmsUInt32Number outputChan, 
+cmsStage* CMSEXPORT cmsStageAllocCLut16bitGranular(cmsContext ContextID,
+                                         const cmsUInt32Number clutPoints[],
+                                         cmsUInt32Number inputChan,
+                                         cmsUInt32Number outputChan,
                                          const cmsUInt16Number* Table)
 {
     cmsUInt32Number i, n;
     _cmsStageCLutData* NewElem;
     cmsStage* NewMPE;
-    
+
+    _cmsAssert(clutPoints != NULL);
+
+    if (inputChan > MAX_INPUT_DIMENSIONS) {
+        cmsSignalError(ContextID, cmsERROR_RANGE, "Too many input channels (%d channels, max=%d)", inputChan, MAX_INPUT_DIMENSIONS);
+        return NULL;
+    }
+
     NewMPE = _cmsStageAllocPlaceholder(ContextID, cmsSigCLutElemType, inputChan, outputChan,
                                      EvaluateCLUTfloatIn16, CLUTElemDup, CLutElemTypeFree, NULL );
 
@@ -582,14 +590,14 @@ cmsStage* CMSEXPORT cmsStageAllocCLut16bitGranular(cmsContext ContextID,
         cmsStageFree(NewMPE);
         return NULL;
     }
+
     return NewMPE;
 }
 
-cmsStage* CMSEXPORT cmsStageAllocCLut16bit(cmsContext ContextID, 
-                                    cmsUInt32Number nGridPoints, 
-                                    cmsUInt32Number inputChan, 
-                                    cmsUInt32Number outputChan, 
+cmsStage* CMSEXPORT cmsStageAllocCLut16bit(cmsContext ContextID,
+                                    cmsUInt32Number nGridPoints,
+                                    cmsUInt32Number inputChan,
+                                    cmsUInt32Number outputChan,
                                     const cmsUInt16Number* Table)
 {
     cmsUInt32Number Dimensions[MAX_INPUT_DIMENSIONS];
@@ -604,10 +612,10 @@ cmsStage* CMSEXPORT cmsStageAllocCLut16bit(cmsContext ContextID,
 }
 
 
-cmsStage* CMSEXPORT cmsStageAllocCLutFloat(cmsContext ContextID, 
-                                       cmsUInt32Number nGridPoints, 
-                                       cmsUInt32Number inputChan, 
-                                       cmsUInt32Number outputChan, 
+cmsStage* CMSEXPORT cmsStageAllocCLutFloat(cmsContext ContextID,
+                                       cmsUInt32Number nGridPoints,
+                                       cmsUInt32Number inputChan,
+                                       cmsUInt32Number outputChan,
                                        const cmsFloat32Number* Table)
 {
    cmsUInt32Number Dimensions[MAX_INPUT_DIMENSIONS];
@@ -627,14 +635,19 @@ cmsStage* CMSEXPORT cmsStageAllocCLutFloatGranular(cmsContext ContextID, const c
     cmsUInt32Number i, n;
     _cmsStageCLutData* NewElem;
     cmsStage* NewMPE;
-    
+
     _cmsAssert(clutPoints != NULL);
 
+    if (inputChan > MAX_INPUT_DIMENSIONS) {
+        cmsSignalError(ContextID, cmsERROR_RANGE, "Too many input channels (%d channels, max=%d)", inputChan, MAX_INPUT_DIMENSIONS);
+        return NULL;
+    }
+
     NewMPE = _cmsStageAllocPlaceholder(ContextID, cmsSigCLutElemType, inputChan, outputChan,
                                              EvaluateCLUTfloat, CLUTElemDup, CLutElemTypeFree, NULL);
     if (NewMPE == NULL) return NULL;
 
-  
+
     NewElem = (_cmsStageCLutData*) _cmsMallocZero(ContextID, sizeof(_cmsStageCLutData));
     if (NewElem == NULL) {
         cmsStageFree(NewMPE);
@@ -642,7 +655,7 @@ cmsStage* CMSEXPORT cmsStageAllocCLutFloatGranular(cmsContext ContextID, const c
     }
 
     NewMPE ->Data  = (void*) NewElem;
-    
+
     // There is a potential integer overflow on conputing n and nEntries.
     NewElem -> nEntries = n = outputChan * CubeSize(clutPoints, inputChan);
     NewElem -> HasFloatValues = TRUE;
@@ -665,7 +678,6 @@ cmsStage* CMSEXPORT cmsStageAllocCLutFloatGranular(cmsContext ContextID, const c
     }
 
 
-    
     NewElem ->Params = _cmsComputeInterpParamsEx(ContextID, clutPoints,  inputChan, outputChan, NewElem ->Tab.TFloat, CMS_LERP_FLAGS_FLOAT);
     if (NewElem ->Params == NULL) {
         cmsStageFree(NewMPE);
@@ -684,7 +696,7 @@ int IdentitySampler(register const cmsUInt16Number In[], register cmsUInt16Numbe
     int nChan = *(int*) Cargo;
     int i;
 
-    for (i=0; i < nChan; i++) 
+    for (i=0; i < nChan; i++)
         Out[i] = In[i];
 
     return 1;
@@ -696,13 +708,13 @@ cmsStage* _cmsStageAllocIdentityCLut(cmsContext ContextID, int nChan)
     cmsUInt32Number Dimensions[MAX_INPUT_DIMENSIONS];
     cmsStage* mpe ;
     int i;
-        
+
     for (i=0; i < MAX_INPUT_DIMENSIONS; i++)
         Dimensions[i] = 2;
 
     mpe = cmsStageAllocCLut16bitGranular(ContextID, Dimensions, nChan, nChan, NULL);
     if (mpe == NULL) return NULL;
-    
+
     if (!cmsStageSampleCLut16bit(mpe, IdentitySampler, &nChan, 0)) {
         cmsStageFree(mpe);
         return NULL;
@@ -729,17 +741,17 @@ cmsUInt16Number _cmsQuantizeVal(cmsFloat64Number i, int MaxSamples)
 cmsBool CMSEXPORT cmsStageSampleCLut16bit(cmsStage* mpe, cmsSAMPLER16 Sampler, void * Cargo, cmsUInt32Number dwFlags)
 {
     int i, t, nTotalPoints, index, rest;
-    int nInputs, nOutputs;  
+    int nInputs, nOutputs;
     cmsUInt32Number* nSamples;
     cmsUInt16Number In[cmsMAXCHANNELS], Out[MAX_STAGE_CHANNELS];
     _cmsStageCLutData* clut;
-    
+
     if (mpe == NULL) return FALSE;
-    
-    clut = (_cmsStageCLutData*) mpe->Data; 
+
+    clut = (_cmsStageCLutData*) mpe->Data;
 
     if (clut == NULL) return FALSE;
-    
+
     nSamples = clut->Params ->nSamples;
     nInputs  = clut->Params ->nInputs;
     nOutputs = clut->Params ->nOutputs;
@@ -760,7 +772,7 @@ cmsBool CMSEXPORT cmsStageSampleCLut16bit(cmsStage* mpe, cmsSAMPLER16 Sampler, v
 
             rest /= nSamples[t];
 
-            In[t] = _cmsQuantizeVal(Colorant, nSamples[t]);                         
+            In[t] = _cmsQuantizeVal(Colorant, nSamples[t]);
         }
 
         if (clut ->Tab.T != NULL) {
@@ -791,8 +803,8 @@ cmsBool CMSEXPORT cmsStageSampleCLutFloat(cmsStage* mpe, cmsSAMPLERFLOAT Sampler
     int i, t, nTotalPoints, index, rest;
     int nInputs, nOutputs;
     cmsUInt32Number* nSamples;
-    cmsFloat32Number In[cmsMAXCHANNELS], Out[MAX_STAGE_CHANNELS];   
-    _cmsStageCLutData* clut = (_cmsStageCLutData*) mpe->Data; 
+    cmsFloat32Number In[cmsMAXCHANNELS], Out[MAX_STAGE_CHANNELS];
+    _cmsStageCLutData* clut = (_cmsStageCLutData*) mpe->Data;
 
     nSamples = clut->Params ->nSamples;
     nInputs  = clut->Params ->nInputs;
@@ -809,12 +821,12 @@ cmsBool CMSEXPORT cmsStageSampleCLutFloat(cmsStage* mpe, cmsSAMPLERFLOAT Sampler
 
         rest = i;
         for (t = nInputs-1; t >=0; --t) {
-         
+
             cmsUInt32Number  Colorant = rest % nSamples[t];
 
             rest /= nSamples[t];
 
-            In[t] =  (cmsFloat32Number) (_cmsQuantizeVal(Colorant, nSamples[t]) / 65535.0);                         
+            In[t] =  (cmsFloat32Number) (_cmsQuantizeVal(Colorant, nSamples[t]) / 65535.0);
         }
 
         if (clut ->Tab.TFloat != NULL) {
@@ -862,7 +874,7 @@ cmsBool CMSEXPORT cmsSliceSpace16(cmsUInt32Number nInputs, const cmsUInt32Number
             cmsUInt32Number  Colorant = rest % clutPoints[t];
 
             rest /= clutPoints[t];
-            In[t] = _cmsQuantizeVal(Colorant, clutPoints[t]);   
+            In[t] = _cmsQuantizeVal(Colorant, clutPoints[t]);
 
         }
 
@@ -892,7 +904,7 @@ cmsInt32Number CMSEXPORT cmsSliceSpaceFloat(cmsUInt32Number nInputs, const cmsUI
             cmsUInt32Number  Colorant = rest % clutPoints[t];
 
             rest /= clutPoints[t];
-            In[t] =  (cmsFloat32Number) (_cmsQuantizeVal(Colorant, clutPoints[t]) / 65535.0);    
+            In[t] =  (cmsFloat32Number) (_cmsQuantizeVal(Colorant, clutPoints[t]) / 65535.0);
 
         }
 
@@ -909,8 +921,8 @@ cmsInt32Number CMSEXPORT cmsSliceSpaceFloat(cmsUInt32Number nInputs, const cmsUI
 
 
 static
-void EvaluateLab2XYZ(const cmsFloat32Number In[], 
-                     cmsFloat32Number Out[], 
+void EvaluateLab2XYZ(const cmsFloat32Number In[],
+                     cmsFloat32Number Out[],
                      const cmsStage *mpe)
 {
     cmsCIELab Lab;
@@ -918,18 +930,18 @@ void EvaluateLab2XYZ(const cmsFloat32Number In[],
     const cmsFloat64Number XYZadj = MAX_ENCODEABLE_XYZ;
 
     // V4 rules
-    Lab.L = In[0] * 100.0;        
+    Lab.L = In[0] * 100.0;
     Lab.a = In[1] * 255.0 - 128.0;
     Lab.b = In[2] * 255.0 - 128.0;
 
     cmsLab2XYZ(NULL, &XYZ, &Lab);
 
-    // From XYZ, range 0..19997 to 0..1.0, note that 1.99997 comes from 0xffff 
+    // From XYZ, range 0..19997 to 0..1.0, note that 1.99997 comes from 0xffff
     // encoded as 1.15 fixed point, so 1 + (32767.0 / 32768.0)
 
-    Out[0] = (cmsFloat32Number) ((cmsFloat64Number) XYZ.X / XYZadj); 
-    Out[1] = (cmsFloat32Number) ((cmsFloat64Number) XYZ.Y / XYZadj); 
-    Out[2] = (cmsFloat32Number) ((cmsFloat64Number) XYZ.Z / XYZadj); 
+    Out[0] = (cmsFloat32Number) ((cmsFloat64Number) XYZ.X / XYZadj);
+    Out[1] = (cmsFloat32Number) ((cmsFloat64Number) XYZ.Y / XYZadj);
+    Out[2] = (cmsFloat32Number) ((cmsFloat64Number) XYZ.Z / XYZadj);
     return;
 
     cmsUNUSED_PARAMETER(mpe);
@@ -944,9 +956,9 @@ cmsStage* _cmsStageAllocLab2XYZ(cmsContext ContextID)
 
 // ********************************************************************************
 
-// v2 L=100 is supposed to be placed on 0xFF00. There is no reasonable 
+// v2 L=100 is supposed to be placed on 0xFF00. There is no reasonable
 // number of gridpoints that would make exact match. However, a prelinearization
-// of 258 entries, would map 0xFF00 exactly on entry 257, and this is good to avoid scum dot. 
+// of 258 entries, would map 0xFF00 exactly on entry 257, and this is good to avoid scum dot.
 // Almost all what we need but unfortunately, the rest of entries should be scaled by
 // (255*257/256) and this is not exact.
 
@@ -961,13 +973,13 @@ cmsStage* _cmsStageAllocLabV2ToV4curves(cmsContext ContextID)
     LabTable[2] = cmsBuildTabulatedToneCurve16(ContextID, 258, NULL);
 
     for (j=0; j < 3; j++) {
-    
+
         if (LabTable[j] == NULL) {
             cmsFreeToneCurveTriple(LabTable);
             return NULL;
         }
-        
-        // We need to map * (0xffff / 0xff00), thats same as (257 / 256) 
+
+        // We need to map * (0xffff / 0xff00), thats same as (257 / 256)
         // So we can use 258-entry tables to do the trick (i / 257) * (255 * 257) * (257 / 256);
         for (i=0; i < 257; i++)  {
 
@@ -990,8 +1002,8 @@ cmsStage* _cmsStageAllocLabV2ToV4curves(cmsContext ContextID)
 cmsStage* _cmsStageAllocLabV2ToV4(cmsContext ContextID)
 {
     static const cmsFloat64Number V2ToV4[] = { 65535.0/65280.0, 0, 0,
-                                     0, 65535.0/65280.0, 0, 
-                                     0, 0, 65535.0/65280.0 
+                                     0, 65535.0/65280.0, 0,
+                                     0, 0, 65535.0/65280.0
                                      };
 
     cmsStage *mpe = cmsStageAllocMatrix(ContextID, 3, 3, V2ToV4, NULL);
@@ -1006,8 +1018,8 @@ cmsStage* _cmsStageAllocLabV2ToV4(cmsContext ContextID)
 cmsStage* _cmsStageAllocLabV4ToV2(cmsContext ContextID)
 {
     static const cmsFloat64Number V4ToV2[] = { 65280.0/65535.0, 0, 0,
-                                     0, 65280.0/65535.0, 0, 
-                                     0, 0, 65280.0/65535.0 
+                                     0, 65280.0/65535.0, 0,
+                                     0, 0, 65280.0/65535.0
                                      };
 
      cmsStage *mpe = cmsStageAllocMatrix(ContextID, 3, 3, V4ToV2, NULL);
@@ -1025,59 +1037,78 @@ cmsStage* _cmsStageAllocLabV4ToV2(cmsContext ContextID)
 
 cmsStage* _cmsStageNormalizeFromLabFloat(cmsContext ContextID)
 {
-    static const cmsFloat64Number a1[] = { 
+    static const cmsFloat64Number a1[] = {
         1.0/100.0, 0, 0,
-        0, 1.0/255.0, 0, 
-        0, 0, 1.0/255.0 
+        0, 1.0/255.0, 0,
+        0, 0, 1.0/255.0
     };
 
-    static const cmsFloat64Number o1[] = { 
+    static const cmsFloat64Number o1[] = {
         0,
-        128.0/255.0, 
-        128.0/255.0 
+        128.0/255.0,
+        128.0/255.0
     };
 
-    return cmsStageAllocMatrix(ContextID, 3, 3, a1, o1);
+    cmsStage *mpe = cmsStageAllocMatrix(ContextID, 3, 3, a1, o1);
+
+    if (mpe == NULL) return mpe;
+    mpe ->Implements = cmsSigLab2FloatPCS;
+    return mpe;
 }
 
+// Fom XYZ to floating point PCS
 cmsStage* _cmsStageNormalizeFromXyzFloat(cmsContext ContextID)
 {
-    static const cmsFloat64Number a1[] = { 
-        1.0/100.0, 0, 0,
-        0, 1.0/100.0, 0, 
-        0, 0, 1.0/100.0 
+#define n (32768.0/65535.0)
+    static const cmsFloat64Number a1[] = {
+        n, 0, 0,
+        0, n, 0,
+        0, 0, n
     };
+#undef n
 
+    cmsStage *mpe =  cmsStageAllocMatrix(ContextID, 3, 3, a1, NULL);
 
-    return cmsStageAllocMatrix(ContextID, 3, 3, a1, NULL);
+    if (mpe == NULL) return mpe;
+    mpe ->Implements = cmsSigXYZ2FloatPCS;
+    return mpe;
 }
 
 cmsStage* _cmsStageNormalizeToLabFloat(cmsContext ContextID)
 {
-    static const cmsFloat64Number a1[] = { 
+    static const cmsFloat64Number a1[] = {
         100.0, 0, 0,
-        0, 255.0, 0, 
-        0, 0, 255.0 
+        0, 255.0, 0,
+        0, 0, 255.0
     };
 
-    static const cmsFloat64Number o1[] = { 
+    static const cmsFloat64Number o1[] = {
         0,
-        -128.0, 
-        -128.0 
+        -128.0,
+        -128.0
     };
 
-    return cmsStageAllocMatrix(ContextID, 3, 3, a1, o1);
+    cmsStage *mpe =  cmsStageAllocMatrix(ContextID, 3, 3, a1, o1);
+    if (mpe == NULL) return mpe;
+    mpe ->Implements = cmsSigFloatPCS2Lab;
+    return mpe;
 }
 
 cmsStage* _cmsStageNormalizeToXyzFloat(cmsContext ContextID)
 {
-    static const cmsFloat64Number a1[] = { 
-        100.0, 0, 0,
-        0, 100.0, 0, 
-        0, 0, 100.0 
+#define n (65535.0/32768.0)
+
+    static const cmsFloat64Number a1[] = {
+        n, 0, 0,
+        0, n, 0,
+        0, 0, n
     };
+#undef n
 
-    return cmsStageAllocMatrix(ContextID, 3, 3, a1, NULL);
+    cmsStage *mpe = cmsStageAllocMatrix(ContextID, 3, 3, a1, NULL);
+    if (mpe == NULL) return mpe;
+    mpe ->Implements = cmsSigFloatPCS2XYZ;
+    return mpe;
 }
 
 
@@ -1091,20 +1122,20 @@ void EvaluateXYZ2Lab(const cmsFloat32Number In[], cmsFloat32Number Out[], const
 {
     cmsCIELab Lab;
     cmsCIEXYZ XYZ;
-    const cmsFloat64Number XYZadj = MAX_ENCODEABLE_XYZ; 
+    const cmsFloat64Number XYZadj = MAX_ENCODEABLE_XYZ;
 
     // From 0..1.0 to XYZ
 
-    XYZ.X = In[0] * XYZadj; 
-    XYZ.Y = In[1] * XYZadj; 
+    XYZ.X = In[0] * XYZadj;
+    XYZ.Y = In[1] * XYZadj;
     XYZ.Z = In[2] * XYZadj;
 
     cmsXYZ2Lab(NULL, &Lab, &XYZ);
-    
+
     // From V4 Lab to 0..1.0
 
-    Out[0] = (cmsFloat32Number) (Lab.L / 100.0); 
-    Out[1] = (cmsFloat32Number) ((Lab.a + 128.0) / 255.0); 
+    Out[0] = (cmsFloat32Number) (Lab.L / 100.0);
+    Out[1] = (cmsFloat32Number) ((Lab.a + 128.0) / 255.0);
     Out[2] = (cmsFloat32Number) ((Lab.b + 128.0) / 255.0);
     return;
 
@@ -1112,9 +1143,9 @@ void EvaluateXYZ2Lab(const cmsFloat32Number In[], cmsFloat32Number Out[], const
 }
 
 cmsStage* _cmsStageAllocXYZ2Lab(cmsContext ContextID)
-{    
+{
     return _cmsStageAllocPlaceholder(ContextID, cmsSigXYZ2LabElemType, 3, 3, EvaluateXYZ2Lab, NULL, NULL, NULL);
+
 }
 
 // ********************************************************************************
@@ -1134,10 +1165,10 @@ cmsStage* _cmsStageAllocLabPrelin(cmsContext ContextID)
 }
 
 
-// Free a single MPE 
+// Free a single MPE
 void CMSEXPORT cmsStageFree(cmsStage* mpe)
 {
-    if (mpe ->FreePtr) 
+    if (mpe ->FreePtr)
         mpe ->FreePtr(mpe);
 
     _cmsFree(mpe ->ContextID, mpe);
@@ -1174,21 +1205,21 @@ cmsStage*  CMSEXPORT cmsStageNext(const cmsStage* mpe)
 cmsStage* CMSEXPORT cmsStageDup(cmsStage* mpe)
 {
     cmsStage* NewMPE;
-    
+
     if (mpe == NULL) return NULL;
-    NewMPE = _cmsStageAllocPlaceholder(mpe ->ContextID, 
-                                     mpe ->Type, 
-                                     mpe ->InputChannels, 
+    NewMPE = _cmsStageAllocPlaceholder(mpe ->ContextID,
+                                     mpe ->Type,
+                                     mpe ->InputChannels,
                                      mpe ->OutputChannels,
                                      mpe ->EvalPtr,
                                      mpe ->DupElemPtr,
                                      mpe ->FreePtr,
                                      NULL);
     if (NewMPE == NULL) return NULL;
-  
+
     NewMPE ->Implements     = mpe ->Implements;
-    if (mpe ->DupElemPtr) 
+
+    if (mpe ->DupElemPtr)
         NewMPE ->Data       = mpe ->DupElemPtr(mpe);
     else
         NewMPE ->Data       = NULL;
@@ -1204,7 +1235,7 @@ cmsStage* CMSEXPORT cmsStageDup(cmsStage* mpe)
 static
 void BlessLUT(cmsPipeline* lut)
 {
-    // We can set the input/ouput channels only if we have elements. 
+    // We can set the input/ouput channels only if we have elements.
     if (lut ->Elements != NULL) {
 
         cmsStage *First, *Last;
@@ -1218,50 +1249,50 @@ void BlessLUT(cmsPipeline* lut)
 }
 
 
-// Default to evaluate the LUT on 16 bit-basis. Precision is retained. 
+// Default to evaluate the LUT on 16 bit-basis. Precision is retained.
 static
 void _LUTeval16(register const cmsUInt16Number In[], register cmsUInt16Number Out[],  register const void* D)
 {
     cmsPipeline* lut = (cmsPipeline*) D;
-    cmsStage *mpe;   
+    cmsStage *mpe;
     cmsFloat32Number Storage[2][MAX_STAGE_CHANNELS];
     int Phase = 0, NextPhase;
-    
+
     From16ToFloat(In, &Storage[Phase][0], lut ->InputChannels);
 
-    for (mpe = lut ->Elements; 
-         mpe != NULL; 
+    for (mpe = lut ->Elements;
+         mpe != NULL;
          mpe = mpe ->Next) {
 
-             NextPhase = Phase ^ 1;            
+             NextPhase = Phase ^ 1;
              mpe ->EvalPtr(&Storage[Phase][0], &Storage[NextPhase][0], mpe);
              Phase = NextPhase;
     }
-    
+
 
     FromFloatTo16(&Storage[Phase][0], Out, lut ->OutputChannels);
 }
 
 
 
-// Does evaluate the LUT on cmsFloat32Number-basis. 
+// Does evaluate the LUT on cmsFloat32Number-basis.
 static
 void _LUTevalFloat(register const cmsFloat32Number In[], register cmsFloat32Number Out[], const void* D)
 {
     cmsPipeline* lut = (cmsPipeline*) D;
-    cmsStage *mpe;   
+    cmsStage *mpe;
     cmsFloat32Number Storage[2][MAX_STAGE_CHANNELS];
     int Phase = 0, NextPhase;
-    
+
     memmove(&Storage[Phase][0], In, lut ->InputChannels  * sizeof(cmsFloat32Number));
 
-    for (mpe = lut ->Elements; 
-         mpe != NULL; 
+    for (mpe = lut ->Elements;
+         mpe != NULL;
          mpe = mpe ->Next) {
 
               NextPhase = Phase ^ 1;
               mpe ->EvalPtr(&Storage[Phase][0], &Storage[NextPhase][0], mpe);
-              Phase = NextPhase;          
+              Phase = NextPhase;
     }
 
     memmove(Out, &Storage[Phase][0], lut ->OutputChannels * sizeof(cmsFloat32Number));
@@ -1290,7 +1321,7 @@ cmsPipeline* CMSEXPORT cmsPipelineAlloc(cmsContext ContextID, cmsUInt32Number In
        NewLUT ->EvalFloatFn = _LUTevalFloat;
        NewLUT ->DupDataFn   = NULL;
        NewLUT ->FreeDataFn  = NULL;
-       NewLUT ->Data        = NewLUT;     
+       NewLUT ->Data        = NewLUT;
        NewLUT ->ContextID   = ContextID;
 
        BlessLUT(NewLUT);
@@ -1298,30 +1329,37 @@ cmsPipeline* CMSEXPORT cmsPipelineAlloc(cmsContext ContextID, cmsUInt32Number In
        return NewLUT;
 }
 
+cmsContext CMSEXPORT cmsGetPipelineContextID(const cmsPipeline* lut)
+{
+    _cmsAssert(lut != NULL);
+    return lut ->ContextID;
+}
 
 cmsUInt32Number CMSEXPORT cmsPipelineInputChannels(const cmsPipeline* lut)
 {
+    _cmsAssert(lut != NULL);
     return lut ->InputChannels;
 }
 
 cmsUInt32Number CMSEXPORT cmsPipelineOutputChannels(const cmsPipeline* lut)
 {
+    _cmsAssert(lut != NULL);
     return lut ->OutputChannels;
 }
 
 // Free a profile elements LUT
 void CMSEXPORT cmsPipelineFree(cmsPipeline* lut)
 {
-    cmsStage *mpe, *Next;   
+    cmsStage *mpe, *Next;
 
     if (lut == NULL) return;
 
-    for (mpe = lut ->Elements; 
-        mpe != NULL; 
+    for (mpe = lut ->Elements;
+        mpe != NULL;
         mpe = Next) {
 
             Next = mpe ->Next;
-            cmsStageFree(mpe);            
+            cmsStageFree(mpe);
     }
 
     if (lut ->FreeDataFn) lut ->FreeDataFn(lut ->ContextID, lut ->Data);
@@ -1330,16 +1368,18 @@ void CMSEXPORT cmsPipelineFree(cmsPipeline* lut)
 }
 
 
-// Default to evaluate the LUT on 16 bit-basis. 
+// Default to evaluate the LUT on 16 bit-basis.
 void CMSEXPORT cmsPipelineEval16(const cmsUInt16Number In[], cmsUInt16Number Out[],  const cmsPipeline* lut)
 {
+    _cmsAssert(lut != NULL);
     lut ->Eval16Fn(In, Out, lut->Data);
 }
 
 
-// Does evaluate the LUT on cmsFloat32Number-basis. 
+// Does evaluate the LUT on cmsFloat32Number-basis.
 void CMSEXPORT cmsPipelineEvalFloat(const cmsFloat32Number In[], cmsFloat32Number Out[], const cmsPipeline* lut)
 {
+    _cmsAssert(lut != NULL);
     lut ->EvalFloatFn(In, Out, lut);
 }
 
@@ -1349,14 +1389,14 @@ void CMSEXPORT cmsPipelineEvalFloat(const cmsFloat32Number In[], cmsFloat32Numbe
 cmsPipeline* CMSEXPORT cmsPipelineDup(const cmsPipeline* lut)
 {
     cmsPipeline* NewLUT;
-    cmsStage *NewMPE, *Anterior = NULL, *mpe;   
+    cmsStage *NewMPE, *Anterior = NULL, *mpe;
     cmsBool  First = TRUE;
 
     if (lut == NULL) return NULL;
 
-    NewLUT = cmsPipelineAlloc(lut ->ContextID, lut ->InputChannels, lut ->OutputChannels);  
-    for (mpe = lut ->Elements; 
-         mpe != NULL; 
+    NewLUT = cmsPipelineAlloc(lut ->ContextID, lut ->InputChannels, lut ->OutputChannels);
+    for (mpe = lut ->Elements;
+         mpe != NULL;
          mpe = mpe ->Next) {
 
              NewMPE = cmsStageDup(mpe);
@@ -1365,22 +1405,24 @@ cmsPipeline* CMSEXPORT cmsPipelineDup(const cmsPipeline* lut)
                  cmsPipelineFree(NewLUT);
                  return NULL;
              }
-    
+
              if (First) {
                  NewLUT ->Elements = NewMPE;
                  First = FALSE;
              }
              else {
-                Anterior ->Next = NewMPE;               
+                Anterior ->Next = NewMPE;
              }
 
             Anterior = NewMPE;
     }
 
-    NewLUT ->DupDataFn  = lut ->DupDataFn;
-    NewLUT ->FreeDataFn = lut ->FreeDataFn;
+    NewLUT ->Eval16Fn    = lut ->Eval16Fn;
+    NewLUT ->EvalFloatFn = lut ->EvalFloatFn;
+    NewLUT ->DupDataFn   = lut ->DupDataFn;
+    NewLUT ->FreeDataFn  = lut ->FreeDataFn;
 
-    if (NewLUT ->DupDataFn != NULL) 
+    if (NewLUT ->DupDataFn != NULL)
         NewLUT ->Data = NewLUT ->DupDataFn(lut ->ContextID, lut->Data);
 
 
@@ -1407,10 +1449,10 @@ void CMSEXPORT cmsPipelineInsertStage(cmsPipeline* lut, cmsStageLoc loc, cmsStag
 
         case cmsAT_END:
 
-            if (lut ->Elements == NULL) 
+            if (lut ->Elements == NULL)
                 lut ->Elements = mpe;
             else {
-            
+
                 for (pt = lut ->Elements;
                      pt != NULL;
                      pt = pt -> Next) Anterior = pt;
@@ -1431,7 +1473,7 @@ void CMSEXPORT cmsPipelineUnlinkStage(cmsPipeline* lut, cmsStageLoc loc, cmsStag
     cmsStage *Anterior, *pt, *Last;
     cmsStage *Unlinked = NULL;
 
-    
+
     // If empty LUT, there is nothing to remove
     if (lut ->Elements == NULL) {
         if (mpe) *mpe = NULL;
@@ -1441,14 +1483,14 @@ void CMSEXPORT cmsPipelineUnlinkStage(cmsPipeline* lut, cmsStageLoc loc, cmsStag
     // On depending on the strategy...
     switch (loc) {
 
-        case cmsAT_BEGIN: 
+        case cmsAT_BEGIN:
             {
                 cmsStage* elem = lut ->Elements;
-             
+
                 lut ->Elements = elem -> Next;
                 elem ->Next = NULL;
                 Unlinked = elem;
-                           
+
             }
             break;
 
@@ -1458,21 +1500,21 @@ void CMSEXPORT cmsPipelineUnlinkStage(cmsPipeline* lut, cmsStageLoc loc, cmsStag
                 pt != NULL;
                 pt = pt -> Next) {
                     Anterior = Last;
-                    Last = pt;              
+                    Last = pt;
             }
 
             Unlinked = Last;  // Next already points to NULL
 
             // Truncate the chain
-            if (Anterior) 
+            if (Anterior)
                 Anterior ->Next = NULL;
-            else 
+            else
                 lut ->Elements = NULL;
             break;
         default:;
     }
 
-    if (mpe) 
+    if (mpe)
         *mpe = Unlinked;
     else
         cmsStageFree(Unlinked);
@@ -1486,7 +1528,7 @@ cmsBool  CMSEXPORT cmsPipelineCat(cmsPipeline* l1, const cmsPipeline* l2)
 {
     cmsStage* mpe, *NewMPE;
 
-    // If both LUTS does not have elements, we need to inherit 
+    // If both LUTS does not have elements, we need to inherit
     // the number of channels
     if (l1 ->Elements == NULL && l2 ->Elements == NULL) {
         l1 ->InputChannels  = l2 ->InputChannels;
@@ -1494,8 +1536,8 @@ cmsBool  CMSEXPORT cmsPipelineCat(cmsPipeline* l1, const cmsPipeline* l2)
     }
 
     // Cat second
-    for (mpe = l2 ->Elements; 
-         mpe != NULL; 
+    for (mpe = l2 ->Elements;
+         mpe != NULL;
          mpe = mpe ->Next) {
 
             // We have to dup each element
@@ -1504,7 +1546,7 @@ cmsBool  CMSEXPORT cmsPipelineCat(cmsPipeline* l1, const cmsPipeline* l2)
              if (NewMPE == NULL) {
                  return FALSE;
              }
-    
+
              cmsPipelineInsertStage(l1, cmsAT_END, NewMPE);
     }
 
@@ -1550,56 +1592,56 @@ cmsUInt32Number CMSEXPORT cmsPipelineStageCount(const cmsPipeline* lut)
 
 // 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.
-void CMSEXPORT _cmsPipelineSetOptimizationParameters(cmsPipeline* Lut, 
-                                        _cmsOPTeval16Fn Eval16, 
-                                        void* PrivateData, 
-                                        _cmsOPTfreeDataFn FreePrivateDataFn, 
-                                        _cmsOPTdupDataFn DupPrivateDataFn)
+void CMSEXPORT _cmsPipelineSetOptimizationParameters(cmsPipeline* Lut,
+                                        _cmsOPTeval16Fn Eval16,
+                                        void* PrivateData,
+                                        _cmsFreeUserDataFn FreePrivateDataFn,
+                                        _cmsDupUserDataFn  DupPrivateDataFn)
 {
 
     Lut ->Eval16Fn = Eval16;
     Lut ->DupDataFn = DupPrivateDataFn;
-    Lut ->FreeDataFn = FreePrivateDataFn;   
+    Lut ->FreeDataFn = FreePrivateDataFn;
     Lut ->Data = PrivateData;
 }
 
 
 // ----------------------------------------------------------- Reverse interpolation
-// Here's how it goes. The derivative Df(x) of the function f is the linear 
-// transformation that best approximates f near the point x. It can be represented 
-// by a matrix A whose entries are the partial derivatives of the components of f 
+// Here's how it goes. The derivative Df(x) of the function f is the linear
+// transformation that best approximates f near the point x. It can be represented
+// by a matrix A whose entries are the partial derivatives of the components of f
 // with respect to all the coordinates. This is know as the Jacobian
 //
-// The best linear approximation to f is given by the matrix equation: 
-// 
-// y-y0 = A (x-x0) 
-// 
-// So, if x0 is a good "guess" for the zero of f, then solving for the zero of this 
-// linear approximation will give a "better guess" for the zero of f. Thus let y=0, 
-// and since y0=f(x0) one can solve the above equation for x. This leads to the 
-// Newton's method formula: 
+// The best linear approximation to f is given by the matrix equation:
+//
+// y-y0 = A (x-x0)
+//
+// So, if x0 is a good "guess" for the zero of f, then solving for the zero of this
+// linear approximation will give a "better guess" for the zero of f. Thus let y=0,
+// and since y0=f(x0) one can solve the above equation for x. This leads to the
+// Newton's method formula:
 //
-// xn+1 = xn - A-1 f(xn) 
-// 
-// where xn+1 denotes the (n+1)-st guess, obtained from the n-th guess xn in the 
-// fashion described above. Iterating this will give better and better approximations 
-// if you have a "good enough" initial guess. 
+// xn+1 = xn - A-1 f(xn)
+//
+// where xn+1 denotes the (n+1)-st guess, obtained from the n-th guess xn in the
+// fashion described above. Iterating this will give better and better approximations
+// if you have a "good enough" initial guess.
 
 
 #define JACOBIAN_EPSILON            0.001f
 #define INVERSION_MAX_ITERATIONS    30
 
 // Increment with reflexion on boundary
-static 
+static
 void IncDelta(cmsFloat32Number *Val)
 {
-    if (*Val < (1.0 - JACOBIAN_EPSILON)) 
+    if (*Val < (1.0 - JACOBIAN_EPSILON))
 
         *Val += JACOBIAN_EPSILON;
-    
-    else 
+
+    else
         *Val -= JACOBIAN_EPSILON;
-    
+
 }
 
 
@@ -1623,7 +1665,7 @@ cmsFloat32Number EuclideanDistance(cmsFloat32Number a[], cmsFloat32Number b[], i
 // Evaluate a LUT in reverse direction. It only searches on 3->3 LUT. Uses Newton method
 //
 // x1 <- x - [J(x)]^-1 * f(x)
-// 
+//
 // lut: The LUT on where to do the search
 // Target: LabK, 3 values of Lab plus destination K which is fixed
 // Result: The obtained CMYK
@@ -1635,10 +1677,10 @@ cmsBool CMSEXPORT cmsPipelineEvalReverseFloat(cmsFloat32Number Target[],
                                               const cmsPipeline* lut)
 {
     cmsUInt32Number  i, j;
-    cmsFloat64Number  error, LastError = 1E20;    
+    cmsFloat64Number  error, LastError = 1E20;
     cmsFloat32Number  fx[4], x[4], xd[4], fxd[4];
     cmsVEC3 tmp, tmp2;
-    cmsMAT3 Jacobian;    
+    cmsMAT3 Jacobian;
     cmsFloat64Number LastResult[4];
 
 
@@ -1658,10 +1700,10 @@ cmsBool CMSEXPORT cmsPipelineEvalReverseFloat(cmsFloat32Number Target[],
     else {
 
         // Only copy 3 channels from hint...
-        for (j=0; j < 3; j++) 
-            x[j] = Hint[j];         
+        for (j=0; j < 3; j++)
+            x[j] = Hint[j];
     }
-    
+
     // If Lut is 4-dimensions, then grab target[3], which is fixed
     if (lut ->InputChannels == 4) {
         x[3] = Target[3];
@@ -1669,7 +1711,7 @@ cmsBool CMSEXPORT cmsPipelineEvalReverseFloat(cmsFloat32Number Target[],
     else x[3] = 0; // To keep lint happy
 
 
-    // Iterate    
+    // Iterate
     for (i = 0; i < INVERSION_MAX_ITERATIONS; i++) {
 
         // Get beginning fx
@@ -1679,19 +1721,19 @@ cmsBool CMSEXPORT cmsPipelineEvalReverseFloat(cmsFloat32Number Target[],
         error = EuclideanDistance(fx, Target, 3);
 
         // If not convergent, return last safe value
-        if (error >= LastError) 
+        if (error >= LastError)
             break;
 
         // Keep latest values
         LastError     = error;
-        for (j=0; j < lut ->InputChannels; j++) 
-                Result[j] = x[j]; 
+        for (j=0; j < lut ->InputChannels; j++)
+                Result[j] = x[j];
 
         // Found an exact match?
-        if (error <= 0) 
+        if (error <= 0)
             break;
 
-        // Obtain slope (the Jacobian)              
+        // Obtain slope (the Jacobian)
         for (j = 0; j < 3; j++) {
 
             xd[0] = x[0];
@@ -1705,7 +1747,7 @@ cmsBool CMSEXPORT cmsPipelineEvalReverseFloat(cmsFloat32Number Target[],
 
             Jacobian.v[0].n[j] = ((fxd[0] - fx[0]) / JACOBIAN_EPSILON);
             Jacobian.v[1].n[j] = ((fxd[1] - fx[1]) / JACOBIAN_EPSILON);
-            Jacobian.v[2].n[j] = ((fxd[2] - fx[2]) / JACOBIAN_EPSILON);        
+            Jacobian.v[2].n[j] = ((fxd[2] - fx[2]) / JACOBIAN_EPSILON);
         }
 
         // Solve system
@@ -1732,3 +1774,4 @@ cmsBool CMSEXPORT cmsPipelineEvalReverseFloat(cmsFloat32Number Target[],
     return TRUE;
 }
 
+
index ecf3d90..c0fd220 100644 (file)
@@ -1,24 +1,24 @@
 //---------------------------------------------------------------------------------
 //
 //  Little Color Management System
-//  Copyright (c) 1998-2010 Marti Maria Saguer
+//  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 
+// 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 
+// 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 
+// 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.
 //
 //---------------------------------------------------------------------------------
@@ -42,7 +42,7 @@ void byteReverse(cmsUInt8Number * buf, cmsUInt32Number longs)
 }
 
 #else
-#define byteReverse(buf, len)   
+#define byteReverse(buf, len)
 #endif
 
 
@@ -66,7 +66,7 @@ typedef struct {
 
 static
 void MD5_Transform(cmsUInt32Number buf[4], cmsUInt32Number in[16])
-    
+
 {
     register cmsUInt32Number a, b, c, d;
 
@@ -176,14 +176,14 @@ void MD5add(cmsHANDLE Handle, cmsUInt8Number* buf, cmsUInt32Number len)
 {
     _cmsMD5* ctx = (_cmsMD5*) Handle;
     cmsUInt32Number t;
-    
+
     t = ctx->bits[0];
     if ((ctx->bits[0] = t + (len << 3)) < t)
-        ctx->bits[1]++; 
+        ctx->bits[1]++;
 
     ctx->bits[1] += len >> 29;
 
-    t = (t >> 3) & 0x3f;    
+    t = (t >> 3) & 0x3f;
 
     if (t) {
 
@@ -265,7 +265,7 @@ cmsBool CMSEXPORT cmsMD5computeID(cmsHPROFILE hProfile)
     cmsUInt8Number* Mem = NULL;
     cmsHANDLE  MD5 = NULL;
     _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
-    _cmsICCPROFILE Keep;              
+    _cmsICCPROFILE Keep;
 
        _cmsAssert(hProfile != NULL);
 
@@ -273,7 +273,7 @@ cmsBool CMSEXPORT cmsMD5computeID(cmsHPROFILE hProfile)
 
     // Save a copy of the profile header
     memmove(&Keep, Icc, sizeof(_cmsICCPROFILE));
-    
+
     // Set RI, attributes and ID
     memset(&Icc ->attributes, 0, sizeof(Icc ->attributes));
     Icc ->RenderingIntent = 0;
@@ -288,7 +288,7 @@ cmsBool CMSEXPORT cmsMD5computeID(cmsHPROFILE hProfile)
 
     // Save to temporary storage
     if (!cmsSaveProfileToMem(hProfile, Mem, &BytesNeeded)) goto Error;
-     
+
     // Create MD5 object
     MD5 = MD5alloc(ContextID);
     if (MD5 == NULL) goto Error;
@@ -298,7 +298,7 @@ cmsBool CMSEXPORT cmsMD5computeID(cmsHPROFILE hProfile)
 
     // Temp storage is no longer needed
     _cmsFree(ContextID, Mem);
-    
+
     // Restore header
     memmove(Icc, &Keep, sizeof(_cmsICCPROFILE));
 
index 84035c9..6195867 100644 (file)
@@ -1,24 +1,24 @@
 //---------------------------------------------------------------------------------
 //
 //  Little Color Management System
-//  Copyright (c) 1998-2010 Marti Maria Saguer
+//  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 
+// 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 
+// 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 
+// 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.
 //
 //---------------------------------------------------------------------------------
@@ -30,7 +30,7 @@
 #define DSWAP(x, y)     {cmsFloat64Number tmp = (x); (x)=(y); (y)=tmp;}
 
 
-// Initiate a vector 
+// Initiate a vector
 void CMSEXPORT _cmsVEC3init(cmsVEC3* r, cmsFloat64Number x, cmsFloat64Number y, cmsFloat64Number z)
 {
     r -> n[VX] = x;
@@ -60,7 +60,7 @@ cmsFloat64Number CMSEXPORT _cmsVEC3dot(const cmsVEC3* u, const cmsVEC3* v)
     return u->n[VX] * v->n[VX] + u->n[VY] * v->n[VY] + u->n[VZ] * v->n[VZ];
 }
 
-// Euclidean length 
+// Euclidean length
 cmsFloat64Number CMSEXPORT _cmsVEC3length(const cmsVEC3* a)
 {
     return sqrt(a ->n[VX] * a ->n[VX] +
index 28ff45d..84dea7e 100644 (file)
@@ -1,24 +1,24 @@
 //---------------------------------------------------------------------------------
 //
 //  Little Color Management System
-//  Copyright (c) 1998-2010 Marti Maria Saguer
+//  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 
+// 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 
+// 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 
+// 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.
 //
 //---------------------------------------------------------------------------------
@@ -58,7 +58,7 @@ cmsMLU* CMSEXPORT cmsMLUalloc(cmsContext ContextID, cmsUInt32Number nItems)
 }
 
 
-// Grows a mempool table for a MLU. Each time this function is called, mempool size is multiplied times two. 
+// Grows a mempool table for a MLU. Each time this function is called, mempool size is multiplied times two.
 static
 cmsBool GrowMLUpool(cmsMLU* mlu)
 {
@@ -70,7 +70,7 @@ cmsBool GrowMLUpool(cmsMLU* mlu)
 
     if (mlu ->PoolSize == 0)
         size = 256;
-    else 
+    else
         size = mlu ->PoolSize * 2;
 
     // Check for overflow
@@ -88,13 +88,13 @@ cmsBool GrowMLUpool(cmsMLU* mlu)
 }
 
 
-// Grows a ntry table for a MLU. Each time this function is called, table size is multiplied times two. 
+// Grows a entry table for a MLU. Each time this function is called, table size is multiplied times two.
 static
 cmsBool GrowMLUtable(cmsMLU* mlu)
 {
     int AllocatedEntries;
     _cmsMLUentry *NewPtr;
-    
+
     // Sanity check
     if (mlu == NULL) return FALSE;
 
@@ -106,7 +106,7 @@ cmsBool GrowMLUtable(cmsMLU* mlu)
     // Reallocate the memory
     NewPtr = (_cmsMLUentry*)_cmsRealloc(mlu ->ContextID, mlu ->Entries, AllocatedEntries*sizeof(_cmsMLUentry));
     if (NewPtr == NULL) return FALSE;
-    
+
     mlu ->Entries          = NewPtr;
     mlu ->AllocatedEntries = AllocatedEntries;
 
@@ -114,19 +114,19 @@ cmsBool GrowMLUtable(cmsMLU* mlu)
 }
 
 
-// Search for a specific entry in the structure. Language and Country are used. 
+// Search for a specific entry in the structure. Language and Country are used.
 static
 int SearchMLUEntry(cmsMLU* mlu, cmsUInt16Number LanguageCode, cmsUInt16Number CountryCode)
 {
     int i;
-    
+
     // Sanity check
     if (mlu == NULL) return -1;
 
     // Iterate whole table
     for (i=0; i < mlu ->UsedEntries; i++) {
 
-        if (mlu ->Entries[i].Country  == CountryCode && 
+        if (mlu ->Entries[i].Country  == CountryCode &&
             mlu ->Entries[i].Language == LanguageCode) return i;
     }
 
@@ -134,10 +134,10 @@ int SearchMLUEntry(cmsMLU* mlu, cmsUInt16Number LanguageCode, cmsUInt16Number Co
     return -1;
 }
 
-// Add a block of characters to the intended MLU. Language and country are specified. 
+// Add a block of characters to the intended MLU. Language and country are specified.
 // Only one entry for Language/country pair is allowed.
 static
-cmsBool AddMLUBlock(cmsMLU* mlu, cmsUInt32Number size, const wchar_t *Block, 
+cmsBool AddMLUBlock(cmsMLU* mlu, cmsUInt32Number size, const wchar_t *Block,
                      cmsUInt16Number LanguageCode, cmsUInt16Number CountryCode)
 {
     cmsUInt32Number Offset;
@@ -161,14 +161,14 @@ cmsBool AddMLUBlock(cmsMLU* mlu, cmsUInt32Number size, const wchar_t *Block,
     }
 
     Offset = mlu ->PoolUsed;
-    
+
     Ptr = (cmsUInt8Number*) mlu ->MemPool;
     if (Ptr == NULL) return FALSE;
 
     // Set the entry
     memmove(Ptr + Offset, Block, size);
     mlu ->PoolUsed += size;
-    
+
     mlu ->Entries[mlu ->UsedEntries].StrW     = Offset;
     mlu ->Entries[mlu ->UsedEntries].Len      = size;
     mlu ->Entries[mlu ->UsedEntries].Country  = CountryCode;
@@ -179,7 +179,7 @@ cmsBool AddMLUBlock(cmsMLU* mlu, cmsUInt32Number size, const wchar_t *Block,
 }
 
 
-// Add an ASCII entry. 
+// Add an ASCII entry.
 cmsBool CMSEXPORT cmsMLUsetASCII(cmsMLU* mlu, const char LanguageCode[3], const char CountryCode[3], const char* ASCIIString)
 {
     cmsUInt32Number i, len = (cmsUInt32Number) strlen(ASCIIString)+1;
@@ -195,16 +195,16 @@ cmsBool CMSEXPORT cmsMLUsetASCII(cmsMLU* mlu, const char LanguageCode[3], const
 
     for (i=0; i < len; i++)
         WStr[i] = (wchar_t) ASCIIString[i];
-    
+
     rc = AddMLUBlock(mlu, len  * sizeof(wchar_t), WStr, Lang, Cntry);
 
     _cmsFree(mlu ->ContextID, WStr);
     return rc;
-    
+
 }
 
 // We don't need any wcs support library
-static 
+static
 cmsUInt32Number mywcslen(const wchar_t *s)
 {
     const wchar_t *p;
@@ -223,7 +223,7 @@ cmsBool  CMSEXPORT cmsMLUsetWide(cmsMLU* mlu, const char Language[3], const char
     cmsUInt16Number Lang  = _cmsAdjustEndianess16(*(cmsUInt16Number*) Language);
     cmsUInt16Number Cntry = _cmsAdjustEndianess16(*(cmsUInt16Number*) Country);
     cmsUInt32Number len;
-    
+
     if (mlu == NULL) return FALSE;
     if (WideString == NULL) return FALSE;
 
@@ -290,11 +290,11 @@ void CMSEXPORT cmsMLUfree(cmsMLU* mlu)
 }
 
 
-// The algorithm first searches for an exact match of country and language, if not found it uses 
+// The algorithm first searches for an exact match of country and language, if not found it uses
 // the Language. If none is found, first entry is used instead.
 static
-const wchar_t* _cmsMLUgetWide(const cmsMLU* mlu, 
-                              cmsUInt32Number *len, 
+const wchar_t* _cmsMLUgetWide(const cmsMLU* mlu,
+                              cmsUInt32Number *len,
                               cmsUInt16Number LanguageCode, cmsUInt16Number CountryCode,
                               cmsUInt16Number* UsedLanguageCode, cmsUInt16Number* UsedCountryCode)
 {
@@ -321,7 +321,7 @@ const wchar_t* _cmsMLUgetWide(const cmsMLU* mlu,
 
                 if (len != NULL) *len = v ->Len;
 
-                return (wchar_t*) ((cmsUInt8Number*) mlu ->MemPool + v -> StrW);        // Found exact match                       
+                return (wchar_t*) ((cmsUInt8Number*) mlu ->MemPool + v -> StrW);        // Found exact match
             }
         }
     }
@@ -342,8 +342,8 @@ const wchar_t* _cmsMLUgetWide(const cmsMLU* mlu,
 
 
 // Obtain an ASCII representation of the wide string. Setting buffer to NULL returns the len
-cmsUInt32Number CMSEXPORT cmsMLUgetASCII(const cmsMLU* mlu, 
-                                       const char LanguageCode[3], const char CountryCode[3], 
+cmsUInt32Number CMSEXPORT cmsMLUgetASCII(const cmsMLU* mlu,
+                                       const char LanguageCode[3], const char CountryCode[3],
                                        char* Buffer, cmsUInt32Number BufferSize)
 {
     const wchar_t *Wide;
@@ -373,7 +373,7 @@ cmsUInt32Number CMSEXPORT cmsMLUgetASCII(const cmsMLU* mlu,
         ASCIIlen = BufferSize - 1;
 
     // Precess each character
-    for (i=0; i < ASCIIlen; i++) { 
+    for (i=0; i < ASCIIlen; i++) {
 
         if (Wide[i] == 0)
             Buffer[i] = 0;
@@ -386,9 +386,9 @@ cmsUInt32Number CMSEXPORT cmsMLUgetASCII(const cmsMLU* mlu,
     return ASCIIlen + 1;
 }
 
-// Obtain a wide representation of the MLU, on depending on current locale settings 
-cmsUInt32Number CMSEXPORT cmsMLUgetWide(const cmsMLU* mlu, 
-                                      const char LanguageCode[3], const char CountryCode[3], 
+// Obtain a wide representation of the MLU, on depending on current locale settings
+cmsUInt32Number CMSEXPORT cmsMLUgetWide(const cmsMLU* mlu,
+                                      const char LanguageCode[3], const char CountryCode[3],
                                       wchar_t* Buffer, cmsUInt32Number BufferSize)
 {
     const wchar_t *Wide;
@@ -402,7 +402,7 @@ cmsUInt32Number CMSEXPORT cmsMLUgetWide(const cmsMLU* mlu,
 
     Wide = _cmsMLUgetWide(mlu, &StrLen, Lang, Cntry, NULL, NULL);
     if (Wide == NULL) return 0;
-    
+
     // Maybe we want only to know the len?
     if (Buffer == NULL) return StrLen + sizeof(wchar_t);
 
@@ -421,27 +421,27 @@ cmsUInt32Number CMSEXPORT cmsMLUgetWide(const cmsMLU* mlu,
 
 
 // Get also the language and country
-CMSAPI cmsBool CMSEXPORT cmsMLUgetTranslation(const cmsMLU* mlu,   
-                                              const char LanguageCode[3], const char CountryCode[3], 
+CMSAPI cmsBool CMSEXPORT cmsMLUgetTranslation(const cmsMLU* mlu,
+                                              const char LanguageCode[3], const char CountryCode[3],
                                               char ObtainedLanguage[3], char ObtainedCountry[3])
 {
     const wchar_t *Wide;
+
     cmsUInt16Number Lang  = _cmsAdjustEndianess16(*(cmsUInt16Number*) LanguageCode);
     cmsUInt16Number Cntry = _cmsAdjustEndianess16(*(cmsUInt16Number*) CountryCode);
-    cmsUInt16Number ObtLang, ObtCode; 
+    cmsUInt16Number ObtLang, ObtCode;
 
     // Sanitize
     if (mlu == NULL) return FALSE;
 
     Wide = _cmsMLUgetWide(mlu, NULL, Lang, Cntry, &ObtLang, &ObtCode);
     if (Wide == NULL) return FALSE;
-    
+
     // Get used language and code
     *(cmsUInt16Number *)ObtainedLanguage = _cmsAdjustEndianess16(ObtLang);
-    *(cmsUInt16Number *)ObtainedCountry  = _cmsAdjustEndianess16(ObtCode);  
+    *(cmsUInt16Number *)ObtainedCountry  = _cmsAdjustEndianess16(ObtCode);
 
-    ObtainedLanguage[2] = ObtainedCountry[2] = 0;       
+    ObtainedLanguage[2] = ObtainedCountry[2] = 0;
     return TRUE;
 }
 
@@ -451,7 +451,7 @@ CMSAPI cmsBool CMSEXPORT cmsMLUgetTranslation(const cmsMLU* mlu,
 // Grow the list to keep at least NumElements
 static
 cmsBool  GrowNamedColorList(cmsNAMEDCOLORLIST* v)
-{           
+{
     cmsUInt32Number size;
     _cmsNAMEDCOLOR * NewPtr;
 
@@ -466,9 +466,9 @@ cmsBool  GrowNamedColorList(cmsNAMEDCOLORLIST* v)
     if (size > 1024*100) return FALSE;
 
     NewPtr = (_cmsNAMEDCOLOR*) _cmsRealloc(v ->ContextID, v ->List, size * sizeof(_cmsNAMEDCOLOR));
-    if (NewPtr == NULL) 
+    if (NewPtr == NULL)
         return FALSE;
-        
+
     v ->List      = NewPtr;
     v ->Allocated = size;
     return TRUE;
@@ -478,9 +478,9 @@ cmsBool  GrowNamedColorList(cmsNAMEDCOLORLIST* v)
 cmsNAMEDCOLORLIST* CMSEXPORT cmsAllocNamedColorList(cmsContext ContextID, cmsUInt32Number n, cmsUInt32Number ColorantCount, const char* Prefix, const char* Suffix)
 {
     cmsNAMEDCOLORLIST* v = (cmsNAMEDCOLORLIST*) _cmsMallocZero(ContextID, sizeof(cmsNAMEDCOLORLIST));
-   
+
     if (v == NULL) return NULL;
-    
+
     v ->List      = NULL;
     v ->nColors   = 0;
     v ->ContextID  = ContextID;
@@ -499,15 +499,15 @@ cmsNAMEDCOLORLIST* CMSEXPORT cmsAllocNamedColorList(cmsContext ContextID, cmsUIn
 
 // Free a list
 void CMSEXPORT cmsFreeNamedColorList(cmsNAMEDCOLORLIST* v)
-{               
+{
     if (v ->List) _cmsFree(v ->ContextID, v ->List);
     if (v) _cmsFree(v ->ContextID, v);
-}   
+}
 
 cmsNAMEDCOLORLIST* CMSEXPORT cmsDupNamedColorList(const cmsNAMEDCOLORLIST* v)
 {
     cmsNAMEDCOLORLIST* NewNC;
-        
+
     if (v == NULL) return NULL;
 
     NewNC= cmsAllocNamedColorList(v ->ContextID, v -> nColors, v ->ColorantCount, v ->Prefix, v ->Suffix);
@@ -527,10 +527,10 @@ cmsNAMEDCOLORLIST* CMSEXPORT cmsDupNamedColorList(const cmsNAMEDCOLORLIST* v)
 
 
 // Append a color to a list. List pointer may change if reallocated
-cmsBool  CMSEXPORT cmsAppendNamedColor(cmsNAMEDCOLORLIST* NamedColorList, 
-                                       const char* Name, 
+cmsBool  CMSEXPORT cmsAppendNamedColor(cmsNAMEDCOLORLIST* NamedColorList,
+                                       const char* Name,
                                        cmsUInt16Number PCS[3], cmsUInt16Number Colorant[cmsMAXCHANNELS])
-{    
+{
     cmsUInt32Number i;
 
     if (NamedColorList == NULL) return FALSE;
@@ -546,10 +546,10 @@ cmsBool  CMSEXPORT cmsAppendNamedColor(cmsNAMEDCOLORLIST* NamedColorList,
         NamedColorList ->List[NamedColorList ->nColors].PCS[i] = PCS == NULL ? 0 : PCS[i];
 
     if (Name != NULL) {
-        
-        strncpy(NamedColorList ->List[NamedColorList ->nColors].Name, Name, 
+
+        strncpy(NamedColorList ->List[NamedColorList ->nColors].Name, Name,
                     sizeof(NamedColorList ->List[NamedColorList ->nColors].Name));
-        
+
         NamedColorList ->List[NamedColorList ->nColors].Name[cmsMAX_PATH-1] = 0;
 
     }
@@ -561,21 +561,21 @@ cmsBool  CMSEXPORT cmsAppendNamedColor(cmsNAMEDCOLORLIST* NamedColorList,
     return TRUE;
 }
 
-// Returns number of elements 
+// Returns number of elements
 cmsUInt32Number CMSEXPORT cmsNamedColorCount(const cmsNAMEDCOLORLIST* NamedColorList)
-{    
+{
      if (NamedColorList == NULL) return 0;
      return NamedColorList ->nColors;
 }
 
 // Info aboout a given color
-cmsBool  CMSEXPORT cmsNamedColorInfo(const cmsNAMEDCOLORLIST* NamedColorList, cmsUInt32Number nColor, 
-                                     char* Name, 
-                                     char* Prefix, 
+cmsBool  CMSEXPORT cmsNamedColorInfo(const cmsNAMEDCOLORLIST* NamedColorList, cmsUInt32Number nColor,
+                                     char* Name,
+                                     char* Prefix,
                                      char* Suffix,
-                                     cmsUInt16Number* PCS, 
+                                     cmsUInt16Number* PCS,
                                      cmsUInt16Number* Colorant)
-{    
+{
     if (NamedColorList == NULL) return FALSE;
 
     if (nColor >= cmsNamedColorCount(NamedColorList)) return FALSE;
@@ -583,11 +583,11 @@ cmsBool  CMSEXPORT cmsNamedColorInfo(const cmsNAMEDCOLORLIST* NamedColorList, cm
     if (Name) strcpy(Name, NamedColorList->List[nColor].Name);
     if (Prefix) strcpy(Prefix, NamedColorList->Prefix);
     if (Suffix) strcpy(Suffix, NamedColorList->Suffix);
-    if (PCS) 
+    if (PCS)
         memmove(PCS, NamedColorList ->List[nColor].PCS, 3*sizeof(cmsUInt16Number));
 
-    if (Colorant) 
-        memmove(Colorant, NamedColorList ->List[nColor].DeviceColorant, 
+    if (Colorant)
+        memmove(Colorant, NamedColorList ->List[nColor].DeviceColorant,
                                 sizeof(cmsUInt16Number) * NamedColorList ->ColorantCount);
 
 
@@ -596,7 +596,7 @@ cmsBool  CMSEXPORT cmsNamedColorInfo(const cmsNAMEDCOLORLIST* NamedColorList, cm
 
 // Search for a given color name (no prefix or suffix)
 cmsInt32Number CMSEXPORT cmsNamedColorIndex(const cmsNAMEDCOLORLIST* NamedColorList, const char* Name)
-{    
+{
     int i, n;
 
     if (NamedColorList == NULL) return -1;
@@ -635,11 +635,11 @@ void EvalNamedColorPCS(const cmsFloat32Number In[], cmsFloat32Number Out[], cons
         cmsSignalError(NamedColorList ->ContextID, cmsERROR_RANGE, "Color %d out of range; ignored", index);
     }
     else {
-      
+
             // Named color always uses Lab
-            Out[0] = (cmsFloat32Number) (NamedColorList->List[index].PCS[0] / 65535.0);      
-            Out[1] = (cmsFloat32Number) (NamedColorList->List[index].PCS[1] / 65535.0);      
-            Out[2] = (cmsFloat32Number) (NamedColorList->List[index].PCS[2] / 65535.0);      
+            Out[0] = (cmsFloat32Number) (NamedColorList->List[index].PCS[0] / 65535.0);
+            Out[1] = (cmsFloat32Number) (NamedColorList->List[index].PCS[1] / 65535.0);
+            Out[2] = (cmsFloat32Number) (NamedColorList->List[index].PCS[2] / 65535.0);
     }
 }
 
@@ -654,8 +654,8 @@ void EvalNamedColor(const cmsFloat32Number In[], cmsFloat32Number Out[], const c
         cmsSignalError(NamedColorList ->ContextID, cmsERROR_RANGE, "Color %d out of range; ignored", index);
     }
     else {
-        for (j=0; j < NamedColorList ->ColorantCount; j++) 
-            Out[j] = (cmsFloat32Number) (NamedColorList->List[index].DeviceColorant[j] / 65535.0);      
+        for (j=0; j < NamedColorList ->ColorantCount; j++)
+            Out[j] = (cmsFloat32Number) (NamedColorList->List[index].DeviceColorant[j] / 65535.0);
     }
 }
 
@@ -663,14 +663,14 @@ void EvalNamedColor(const cmsFloat32Number In[], cmsFloat32Number Out[], const c
 // Named color lookup element
 cmsStage* _cmsStageAllocNamedColor(cmsNAMEDCOLORLIST* NamedColorList, cmsBool UsePCS)
 {
-    return _cmsStageAllocPlaceholder(NamedColorList ->ContextID, 
-                                   cmsSigNamedColorElemType, 
+    return _cmsStageAllocPlaceholder(NamedColorList ->ContextID,
+                                   cmsSigNamedColorElemType,
                                    1, UsePCS ? 3 : NamedColorList ->ColorantCount,
                                    UsePCS ? EvalNamedColorPCS : EvalNamedColor,
                                    DupNamedColorList,
                                    FreeNamedColorList,
                                    cmsDupNamedColorList(NamedColorList));
-  
+
 }
 
 
@@ -699,19 +699,19 @@ cmsSEQ* CMSEXPORT cmsAllocProfileSequenceDescription(cmsContext ContextID, cmsUI
     if (n > 255) return NULL;
 
     Seq = (cmsSEQ*) _cmsMallocZero(ContextID, sizeof(cmsSEQ));
-    if (Seq == NULL) return NULL;   
-    
+    if (Seq == NULL) return NULL;
+
     Seq -> ContextID = ContextID;
     Seq -> seq      = (cmsPSEQDESC*) _cmsCalloc(ContextID, n, sizeof(cmsPSEQDESC));
     Seq -> n        = n;
 
-    
+
     for (i=0; i < n; i++) {
         Seq -> seq[i].Manufacturer = NULL;
         Seq -> seq[i].Model        = NULL;
         Seq -> seq[i].Description  = NULL;
     }
-    
+
     return Seq;
 }
 
@@ -740,10 +740,10 @@ cmsSEQ* CMSEXPORT cmsDupProfileSequenceDescription(const cmsSEQ* pseq)
     NewSeq = (cmsSEQ*) _cmsMalloc(pseq -> ContextID, sizeof(cmsSEQ));
     if (NewSeq == NULL) return NULL;
 
-    
+
     NewSeq -> seq      = (cmsPSEQDESC*) _cmsCalloc(pseq ->ContextID, pseq ->n, sizeof(cmsPSEQDESC));
     if (NewSeq ->seq == NULL) goto Error;
-    
+
     NewSeq -> ContextID = pseq ->ContextID;
     NewSeq -> n        = pseq ->n;
 
@@ -759,7 +759,7 @@ cmsSEQ* CMSEXPORT cmsDupProfileSequenceDescription(const cmsSEQ* pseq)
         NewSeq ->seq[i].Manufacturer = cmsMLUdup(pseq ->seq[i].Manufacturer);
         NewSeq ->seq[i].Model        = cmsMLUdup(pseq ->seq[i].Model);
         NewSeq ->seq[i].Description  = cmsMLUdup(pseq ->seq[i].Description);
-    
+
     }
 
     return NewSeq;
@@ -784,7 +784,7 @@ typedef struct _cmsDICT_struct {
 // Allocate an empty dictionary
 cmsHANDLE CMSEXPORT cmsDictAlloc(cmsContext ContextID)
 {
-    _cmsDICT* dict = (_cmsDICT*) _cmsMallocZero(ContextID, sizeof(_cmsDICT)); 
+    _cmsDICT* dict = (_cmsDICT*) _cmsMallocZero(ContextID, sizeof(_cmsDICT));
     if (dict == NULL) return NULL;
 
     dict ->ContextID = ContextID;
@@ -879,7 +879,7 @@ cmsHANDLE CMSEXPORT cmsDictDup(cmsHANDLE hDict)
 
         entry = entry -> Next;
     }
-    
+
     return hNew;
 }
 
index 1b0d33e..02c1db2 100644 (file)
@@ -4,22 +4,22 @@
 //  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 
+// 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 
+// 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 
+// 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.
 //
 //---------------------------------------------------------------------------------
@@ -39,7 +39,7 @@ typedef struct {
 
     cmsUInt16Number rx[256], ry[256], rz[256];
     cmsUInt32Number X0[256], Y0[256], Z0[256];  // Precomputed nodes and offsets for 8-bit input data
-    
+
 
 } Prelin8Data;
 
@@ -52,33 +52,33 @@ typedef struct {
     // Number of channels
     int nInputs;
     int nOutputs;
-    
+
     // Since there is no limitation of the output number of channels, this buffer holding the connexion CLUT-shaper
     // has to be dynamically allocated. This is not the case of first step shaper-CLUT, which is limited to max inputs
     cmsUInt16Number* StageDEF;
 
-    _cmsInterpFn16 EvalCurveIn16[MAX_INPUT_DIMENSIONS];       // The maximum number of input channels is known in advance 
-    cmsInterpParams*  ParamsCurveIn16[MAX_INPUT_DIMENSIONS];  
-    
+    _cmsInterpFn16 EvalCurveIn16[MAX_INPUT_DIMENSIONS];       // The maximum number of input channels is known in advance
+    cmsInterpParams*  ParamsCurveIn16[MAX_INPUT_DIMENSIONS];
+
     _cmsInterpFn16 EvalCLUT;            // The evaluator for 3D grid
     const cmsInterpParams* CLUTparams;  // (not-owned pointer)
 
-    
+
     _cmsInterpFn16* EvalCurveOut16;       // Points to an array of curve evaluators in 16 bits (not-owned pointer)
     cmsInterpParams**  ParamsCurveOut16;  // Points to an array of references to interpolation params (not-owned pointer)
-    
+
 
 } Prelin16Data;
 
 
-// Optimization for matrix-shaper in 8 bits. Numbers are operated in n.14 signed, tables are stored in 1.14 fixed 
+// Optimization for matrix-shaper in 8 bits. Numbers are operated in n.14 signed, tables are stored in 1.14 fixed
 
 typedef cmsInt32Number cmsS1Fixed14Number;   // Note that this may hold more than 16 bits!
 
 #define DOUBLE_TO_1FIXED14(x) ((cmsS1Fixed14Number) floor((x) * 16384.0 + 0.5))
 
 typedef struct {
+
     cmsContext ContextID;
 
     cmsS1Fixed14Number Shaper1R[256];  // from 0..255 to 1.14  (0.0...1.0)
@@ -88,7 +88,7 @@ typedef struct {
     cmsS1Fixed14Number Mat[3][3];     // n.14 to n.14 (needs a saturation after that)
     cmsS1Fixed14Number Off[3];
 
-    cmsUInt16Number Shaper2R[16385];    // 1.14 to 0..255 
+    cmsUInt16Number Shaper2R[16385];    // 1.14 to 0..255
     cmsUInt16Number Shaper2G[16385];
     cmsUInt16Number Shaper2B[16385];
 
@@ -119,10 +119,10 @@ void _RemoveElement(cmsStage** head)
     cmsStageFree(mpe);
 }
 
-// Remove all identities in chain. Note that pt actually is a double pointer to the element that holds the pointer. 
+// Remove all identities in chain. Note that pt actually is a double pointer to the element that holds the pointer.
 static
 cmsBool _Remove1Op(cmsPipeline* Lut, cmsStageSignature UnaryOp)
-{   
+{
     cmsStage** pt = &Lut ->Elements;
     cmsBool AnyOpt = FALSE;
 
@@ -132,7 +132,7 @@ cmsBool _Remove1Op(cmsPipeline* Lut, cmsStageSignature UnaryOp)
             _RemoveElement(pt);
             AnyOpt = TRUE;
         }
-        else  
+        else
             pt = &((*pt) -> Next);
     }
 
@@ -142,14 +142,14 @@ cmsBool _Remove1Op(cmsPipeline* Lut, cmsStageSignature UnaryOp)
 // Same, but only if two adjacent elements are found
 static
 cmsBool _Remove2Op(cmsPipeline* Lut, cmsStageSignature Op1, cmsStageSignature Op2)
-{   
+{
     cmsStage** pt1;
     cmsStage** pt2;
     cmsBool AnyOpt = FALSE;
 
     pt1 = &Lut ->Elements;
     if (*pt1 == NULL) return AnyOpt;
-    
+
     while (*pt1 != NULL) {
 
         pt2 = &((*pt1) -> Next);
@@ -160,18 +160,18 @@ cmsBool _Remove2Op(cmsPipeline* Lut, cmsStageSignature Op1, cmsStageSignature Op
             _RemoveElement(pt1);
             AnyOpt = TRUE;
         }
-        else  
-            pt1 = &((*pt1) -> Next);            
+        else
+            pt1 = &((*pt1) -> Next);
     }
 
     return AnyOpt;
 }
 
-// Preoptimize just gets rif of no-ops coming paired. Conversion from v2 to v4 followed 
+// Preoptimize just gets rif of no-ops coming paired. Conversion from v2 to v4 followed
 // by a v4 to v2 and vice-versa. The elements are then discarded.
 static
 cmsBool PreOptimize(cmsPipeline* Lut)
-{    
+{
     cmsBool AnyOpt = FALSE, Opt;
 
     AnyOpt = FALSE;
@@ -195,6 +195,12 @@ cmsBool PreOptimize(cmsPipeline* Lut)
         // Remove V2 to V4 followed by V4 to V2
         Opt |= _Remove2Op(Lut, cmsSigLabV2toV4, cmsSigLabV4toV2);
 
+        // Remove float pcs Lab conversions
+        Opt |= _Remove2Op(Lut, cmsSigLab2FloatPCS, cmsSigFloatPCS2Lab);
+
+        // Remove float pcs Lab conversions
+        Opt |= _Remove2Op(Lut, cmsSigXYZ2FloatPCS, cmsSigFloatPCS2XYZ);
+
         if (Opt) AnyOpt = TRUE;
 
     } while (Opt);
@@ -204,12 +210,12 @@ cmsBool PreOptimize(cmsPipeline* Lut)
 
 static
 void Eval16nop1D(register const cmsUInt16Number Input[],
-                 register cmsUInt16Number Output[],                               
+                 register cmsUInt16Number Output[],
                  register const struct _cms_interp_struc* p)
 {
     Output[0] = Input[0];
 
-    cmsUNUSED_PARAMETER(p);  
+    cmsUNUSED_PARAMETER(p);
 }
 
 static
@@ -222,14 +228,14 @@ void PrelinEval16(register const cmsUInt16Number Input[],
     int i;
 
     for (i=0; i < p16 ->nInputs; i++) {
-    
+
         p16 ->EvalCurveIn16[i](&Input[i], &StageABC[i], p16 ->ParamsCurveIn16[i]);
     }
 
     p16 ->EvalCLUT(StageABC, p16 ->StageDEF, p16 ->CLUTparams);
 
     for (i=0; i < p16 ->nOutputs; i++) {
-    
+
         p16 ->EvalCurveOut16[i](&p16->StageDEF[i], &Output[i], p16 ->ParamsCurveOut16[i]);
     }
 }
@@ -249,13 +255,13 @@ void PrelinOpt16free(cmsContext ContextID, void* ptr)
 
 static
 void* Prelin16dup(cmsContext ContextID, const void* ptr)
-{   
+{
     Prelin16Data* p16 = (Prelin16Data*) ptr;
     Prelin16Data* Duped = _cmsDupMem(ContextID, p16, sizeof(Prelin16Data));
 
     if (Duped == NULL) return NULL;
 
-    Duped ->StageDEF         = _cmsCalloc(ContextID, p16 ->nOutputs, sizeof(cmsUInt16Number)); 
+    Duped ->StageDEF         = _cmsCalloc(ContextID, p16 ->nOutputs, sizeof(cmsUInt16Number));
     Duped ->EvalCurveOut16   = _cmsDupMem(ContextID, p16 ->EvalCurveOut16, p16 ->nOutputs * sizeof(_cmsInterpFn16));
     Duped ->ParamsCurveOut16 = _cmsDupMem(ContextID, p16 ->ParamsCurveOut16, p16 ->nOutputs * sizeof(cmsInterpParams* ));
 
@@ -264,19 +270,19 @@ void* Prelin16dup(cmsContext ContextID, const void* ptr)
 
 
 static
-Prelin16Data* PrelinOpt16alloc(cmsContext ContextID, 
-                               const cmsInterpParams* ColorMap, 
-                               int nInputs, cmsToneCurve** In, 
+Prelin16Data* PrelinOpt16alloc(cmsContext ContextID,
+                               const cmsInterpParams* ColorMap,
+                               int nInputs, cmsToneCurve** In,
                                int nOutputs, cmsToneCurve** Out )
 {
     int i;
-    Prelin16Data* p16 = (Prelin16Data*) _cmsMallocZero(ContextID, sizeof(Prelin16Data));
+    Prelin16Data* p16 = _cmsMallocZero(ContextID, sizeof(Prelin16Data));
     if (p16 == NULL) return NULL;
 
     p16 ->nInputs = nInputs;
     p16 -> nOutputs = nOutputs;
 
-    
+
     for (i=0; i < nInputs; i++) {
 
         if (In == NULL) {
@@ -294,7 +300,7 @@ Prelin16Data* PrelinOpt16alloc(cmsContext ContextID,
     p16 ->EvalCLUT   = ColorMap ->Interpolation.Lerp16;
 
 
-    p16 -> StageDEF = _cmsCalloc(ContextID, p16 ->nOutputs, sizeof(cmsUInt16Number)); 
+    p16 -> StageDEF = _cmsCalloc(ContextID, p16 ->nOutputs, sizeof(cmsUInt16Number));
     p16 -> EvalCurveOut16 = (_cmsInterpFn16*) _cmsCalloc(ContextID, nOutputs, sizeof(_cmsInterpFn16));
     p16 -> ParamsCurveOut16 = (cmsInterpParams**) _cmsCalloc(ContextID, nOutputs, sizeof(cmsInterpParams* ));
 
@@ -320,7 +326,7 @@ Prelin16Data* PrelinOpt16alloc(cmsContext ContextID,
 
 #define PRELINEARIZATION_POINTS 4096
 
-// Sampler implemented by another LUT. This is a clean way to precalculate the devicelink 3D CLUT for 
+// Sampler implemented by another LUT. This is a clean way to precalculate the devicelink 3D CLUT for
 // almost any transform. We use floating point precision and then convert from floating point to 16 bits.
 static
 int XFormSampler16(register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void* Cargo)
@@ -333,14 +339,14 @@ int XFormSampler16(register const cmsUInt16Number In[], register cmsUInt16Number
     _cmsAssert(Lut -> OutputChannels < cmsMAXCHANNELS);
 
     // From 16 bit to floating point
-    for (i=0; i < Lut ->InputChannels; i++) 
+    for (i=0; i < Lut ->InputChannels; i++)
         InFloat[i] = (cmsFloat32Number) (In[i] / 65535.0);
 
     // Evaluate in floating point
     cmsPipelineEvalFloat(InFloat, OutFloat, Lut);
 
     // Back to 16 bits representation
-    for (i=0; i < Lut ->OutputChannels; i++) 
+    for (i=0; i < Lut ->OutputChannels; i++)
         Out[i] = _cmsQuickSaturateWord(OutFloat[i] * 65535.0);
 
     // Always succeed
@@ -351,11 +357,11 @@ int XFormSampler16(register const cmsUInt16Number In[], register cmsUInt16Number
 static
 cmsBool AllCurvesAreLinear(cmsStage* mpe)
 {
-    cmsToneCurve** Curves; 
+    cmsToneCurve** Curves;
     cmsUInt32Number i, n;
 
     Curves = _cmsStageGetPtrToCurveSet(mpe);
-    if (Curves == NULL) return FALSE;  
+    if (Curves == NULL) return FALSE;
 
     n = cmsStageOutputChannels(mpe);
 
@@ -383,17 +389,17 @@ cmsBool  PatchLUT(cmsStage* CLUT, cmsUInt16Number At[], cmsUInt16Number Value[],
         return FALSE;
     }
 
-    px = ((cmsFloat64Number) At[0] * (p16->Domain[0])) / 65535.0;
-    py = ((cmsFloat64Number) At[1] * (p16->Domain[1])) / 65535.0;
-    pz = ((cmsFloat64Number) At[2] * (p16->Domain[2])) / 65535.0;
-    pw = ((cmsFloat64Number) At[3] * (p16->Domain[3])) / 65535.0;
+    if (nChannelsIn == 4) {
 
-    x0 = (int) floor(px);
-    y0 = (int) floor(py);
-    z0 = (int) floor(pz);
-    w0 = (int) floor(pw);
+        px = ((cmsFloat64Number) At[0] * (p16->Domain[0])) / 65535.0;
+        py = ((cmsFloat64Number) At[1] * (p16->Domain[1])) / 65535.0;
+        pz = ((cmsFloat64Number) At[2] * (p16->Domain[2])) / 65535.0;
+        pw = ((cmsFloat64Number) At[3] * (p16->Domain[3])) / 65535.0;
 
-    if (nChannelsIn == 4) {
+        x0 = (int) floor(px);
+        y0 = (int) floor(py);
+        z0 = (int) floor(pz);
+        w0 = (int) floor(pw);
 
         if (((px - x0) != 0) ||
             ((py - y0) != 0) ||
@@ -401,27 +407,39 @@ cmsBool  PatchLUT(cmsStage* CLUT, cmsUInt16Number At[], cmsUInt16Number Value[],
             ((pw - w0) != 0)) return FALSE; // Not on exact node
 
         index = p16 -> opta[3] * x0 +
-            p16 -> opta[2] * y0 +
-            p16 -> opta[1] * z0 +
-            p16 -> opta[0] * w0;
+                p16 -> opta[2] * y0 +
+                p16 -> opta[1] * z0 +
+                p16 -> opta[0] * w0;
     }
-    else 
+    else
         if (nChannelsIn == 3) {
 
+            px = ((cmsFloat64Number) At[0] * (p16->Domain[0])) / 65535.0;
+            py = ((cmsFloat64Number) At[1] * (p16->Domain[1])) / 65535.0;
+            pz = ((cmsFloat64Number) At[2] * (p16->Domain[2])) / 65535.0;
+           
+            x0 = (int) floor(px);
+            y0 = (int) floor(py);
+            z0 = (int) floor(pz);
+           
             if (((px - x0) != 0) ||
                 ((py - y0) != 0) ||
                 ((pz - z0) != 0)) return FALSE;  // Not on exact node
 
             index = p16 -> opta[2] * x0 +
-                p16 -> opta[1] * y0 +
-                p16 -> opta[0] * z0;
+                    p16 -> opta[1] * y0 +
+                    p16 -> opta[0] * z0;
         }
-        else 
+        else
             if (nChannelsIn == 1) {
 
+                px = ((cmsFloat64Number) At[0] * (p16->Domain[0])) / 65535.0;
+                
+                x0 = (int) floor(px);
+                
                 if (((px - x0) != 0)) return FALSE; // Not on exact node
 
-                index = p16 -> opta[0] * x0;    
+                index = p16 -> opta[0] * x0;
             }
             else {
                 cmsSignalError(CLUT->ContextID, cmsERROR_INTERNAL, "(internal) %d Channels are not supported on PatchLUT", nChannelsIn);
@@ -436,7 +454,7 @@ cmsBool  PatchLUT(cmsStage* CLUT, cmsUInt16Number At[], cmsUInt16Number Value[],
 
 // Auxiliar, to see if two values are equal or very different
 static
-cmsBool WhitesAreEqual(int n, cmsUInt16Number White1[], cmsUInt16Number White2[] ) 
+cmsBool WhitesAreEqual(int n, cmsUInt16Number White1[], cmsUInt16Number White2[] )
 {
     int i;
 
@@ -457,7 +475,7 @@ cmsBool FixWhiteMisalignment(cmsPipeline* Lut, cmsColorSpaceSignature EntryColor
     cmsUInt16Number  WhiteIn[cmsMAXCHANNELS], WhiteOut[cmsMAXCHANNELS], ObtainedOut[cmsMAXCHANNELS];
     cmsUInt32Number i, nOuts, nIns;
     cmsStage *PreLin = NULL, *CLUT = NULL, *PostLin = NULL;
-    
+
     if (!_cmsEndPointsBySpace(EntryColorSpace,
         &WhitePointIn, NULL, &nIns)) return FALSE;
 
@@ -465,11 +483,13 @@ cmsBool FixWhiteMisalignment(cmsPipeline* Lut, cmsColorSpaceSignature EntryColor
         &WhitePointOut, NULL, &nOuts)) return FALSE;
 
     // It needs to be fixed?
+    if (Lut ->InputChannels != nIns) return FALSE;
+    if (Lut ->OutputChannels != nOuts) return FALSE;
 
     cmsPipelineEval16(WhitePointIn, ObtainedOut, Lut);
 
-    if (WhitesAreEqual(nOuts, WhitePointOut, ObtainedOut)) return TRUE; // whites already match 
-    
+    if (WhitesAreEqual(nOuts, WhitePointOut, ObtainedOut)) return TRUE; // whites already match
+
     // Check if the LUT comes as Prelin, CLUT or Postlin. We allow all combinations
     if (!cmsPipelineCheckAndRetreiveStages(Lut, 3, cmsSigCurveSetElemType, cmsSigCLutElemType, cmsSigCurveSetElemType, &PreLin, &CLUT, &PostLin))
         if (!cmsPipelineCheckAndRetreiveStages(Lut, 2, cmsSigCurveSetElemType, cmsSigCLutElemType, &PreLin, &CLUT))
@@ -482,31 +502,31 @@ cmsBool FixWhiteMisalignment(cmsPipeline* Lut, cmsColorSpaceSignature EntryColor
 
         cmsToneCurve** Curves = _cmsStageGetPtrToCurveSet(PreLin);
 
-        for (i=0; i < nIns; i++) {    
+        for (i=0; i < nIns; i++) {
             WhiteIn[i] = cmsEvalToneCurve16(Curves[i], WhitePointIn[i]);
         }
     }
     else {
-        for (i=0; i < nIns; i++) 
-            WhiteIn[i] = WhitePointIn[i]; 
+        for (i=0; i < nIns; i++)
+            WhiteIn[i] = WhitePointIn[i];
     }
 
     // If any post-linearization, we need to find how is represented white before the curve, do
     // a reverse interpolation in this case.
     if (PostLin) {
-        
+
         cmsToneCurve** Curves = _cmsStageGetPtrToCurveSet(PostLin);
-        
+
         for (i=0; i < nOuts; i++) {
-        
+
             cmsToneCurve* InversePostLin = cmsReverseToneCurve(Curves[i]);
             WhiteOut[i] = cmsEvalToneCurve16(InversePostLin, WhitePointOut[i]);
             cmsFreeToneCurve(InversePostLin);
         }
     }
     else {
-        for (i=0; i < nOuts; i++) 
-            WhiteOut[i] = WhitePointOut[i]; 
+        for (i=0; i < nOuts; i++)
+            WhiteOut[i] = WhitePointOut[i];
     }
 
     // Ok, proceed with patching. May fail and we don't care if it fails
@@ -516,22 +536,23 @@ cmsBool FixWhiteMisalignment(cmsPipeline* Lut, cmsColorSpaceSignature EntryColor
 }
 
 // -----------------------------------------------------------------------------------------------------------------------------------------------
-// This function creates simple LUT from complex ones. The generated LUT has an optional set of 
-// prelinearization curves, a CLUT of nGridPoints and optional postlinearization tables. 
-// These curves have to exist in the original LUT in order to be used in the simplified output. 
+// This function creates simple LUT from complex ones. The generated LUT has an optional set of
+// prelinearization curves, a CLUT of nGridPoints and optional postlinearization tables.
+// These curves have to exist in the original LUT in order to be used in the simplified output.
 // Caller may also use the flags to allow this feature.
 // LUTS with all curves will be simplified to a single curve. Parametric curves are lost.
 // This function should be used on 16-bits LUTS only, as floating point losses precision when simplified
 // -----------------------------------------------------------------------------------------------------------------------------------------------
 
 static
-cmsBool OptimizeByResampling(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt32Number* InputFormat, cmsUInt32Number* OutputFormat, cmsUInt32Number* dwFlags)                          
+cmsBool OptimizeByResampling(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt32Number* InputFormat, cmsUInt32Number* OutputFormat, cmsUInt32Number* dwFlags)
 {
     cmsPipeline* Src;
-    cmsPipeline* Dest;   
-    cmsStage* CLUT;      
+    cmsPipeline* Dest;
+    cmsStage* mpe;
+    cmsStage* CLUT;
     cmsStage *KeepPreLin = NULL, *KeepPostLin = NULL;
-    int nGridPoints;    
+    int nGridPoints;
     cmsColorSpaceSignature ColorSpace, OutputColorSpace;
     cmsStage *NewPreLin = NULL;
     cmsStage *NewPostLin = NULL;
@@ -554,7 +575,14 @@ cmsBool OptimizeByResampling(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt3
 
     Src = *Lut;
 
-    // Allocate an empty LUT    
+   // Named color pipelines cannot be optimized either
+   for (mpe = cmsPipelineGetPtrToFirstStage(Src);
+         mpe != NULL;
+         mpe = cmsStageNext(mpe)) {
+            if (cmsStageType(mpe) == cmsSigNamedColorElemType) return FALSE;
+    }
+
+    // Allocate an empty LUT
     Dest =  cmsPipelineAlloc(Src ->ContextID, Src ->InputChannels, Src ->OutputChannels);
     if (!Dest) return FALSE;
 
@@ -570,7 +598,7 @@ cmsBool OptimizeByResampling(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt3
             // Maybe this is a linear tram, so we can avoid the whole stuff
             if (!AllCurvesAreLinear(PreLin)) {
 
-                // All seems ok, proceed.    
+                // All seems ok, proceed.
                 NewPreLin = cmsStageDup(PreLin);
                 cmsPipelineInsertStage(Dest, cmsAT_BEGIN, NewPreLin);
 
@@ -600,7 +628,7 @@ cmsBool OptimizeByResampling(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt3
             // Maybe this is a linear tram, so we can avoid the whole stuff
             if (!AllCurvesAreLinear(PostLin)) {
 
-                // All seems ok, proceed.       
+                // All seems ok, proceed.
                 NewPostLin = cmsStageDup(PostLin);
                 cmsPipelineInsertStage(Dest, cmsAT_END, NewPostLin);
 
@@ -610,7 +638,7 @@ cmsBool OptimizeByResampling(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt3
         }
     }
 
-    // Now its time to do the sampling. We have to ignore pre/post linearization 
+    // Now its time to do the sampling. We have to ignore pre/post linearization
     // The source LUT whithout pre/post curves is passed as parameter.
     if (!cmsStageSampleCLut16bit(CLUT, XFormSampler16, (void*) Src, 0)) {
 
@@ -619,9 +647,9 @@ cmsBool OptimizeByResampling(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt3
         if (KeepPostLin != NULL) cmsPipelineInsertStage(Src, cmsAT_END,   KeepPostLin);
         cmsPipelineFree(Dest);
         return FALSE;
-    }      
+    }
 
-    // Done. 
+    // Done.
 
     if (KeepPreLin != NULL) cmsStageFree(KeepPreLin);
     if (KeepPostLin != NULL) cmsStageFree(KeepPostLin);
@@ -642,8 +670,8 @@ cmsBool OptimizeByResampling(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt3
     }
     else {
 
-        p16 = PrelinOpt16alloc(Dest ->ContextID, 
-                               DataCLUT ->Params, 
+        p16 = PrelinOpt16alloc(Dest ->ContextID,
+                               DataCLUT ->Params,
                                Dest ->InputChannels,
                                DataSetIn,
                                Dest ->OutputChannels,
@@ -666,13 +694,13 @@ cmsBool OptimizeByResampling(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt3
     *Lut = Dest;
     return TRUE;
 
-    cmsUNUSED_PARAMETER(Intent);    
+    cmsUNUSED_PARAMETER(Intent);
 }
 
 
 // -----------------------------------------------------------------------------------------------------------------------------------------------
-// Fixes the gamma balancing of transform. This is described in my paper "Prelinearization Stages on 
-// Color-Management Application-Specific Integrated Circuits (ASICs)" presented at NIP24. It only works 
+// Fixes the gamma balancing of transform. This is described in my paper "Prelinearization Stages on
+// Color-Management Application-Specific Integrated Circuits (ASICs)" presented at NIP24. It only works
 // for RGB transforms. See the paper for more details
 // -----------------------------------------------------------------------------------------------------------------------------------------------
 
@@ -708,12 +736,12 @@ void SlopeLimiting(cmsToneCurve* g)
     Slope = (EndVal - Val) / AtBegin;   // AtBegin holds the X interval, which is same in both cases
     beta  = Val - Slope * AtEnd;
 
-    for (i = AtEnd; i < (int) g ->nEntries; i++) 
+    for (i = AtEnd; i < (int) g ->nEntries; i++)
         g ->Table16[i] = _cmsQuickSaturateWord(i * Slope + beta);
 }
 
 
-// Precomputes tables for 8-bit on input devicelink. 
+// Precomputes tables for 8-bit on input devicelink.
 static
 Prelin8Data* PrelinOpt8alloc(cmsContext ContextID, const cmsInterpParams* p, cmsToneCurve* G[3])
 {
@@ -724,8 +752,8 @@ Prelin8Data* PrelinOpt8alloc(cmsContext ContextID, const cmsInterpParams* p, cms
 
     p8 = _cmsMallocZero(ContextID, sizeof(Prelin8Data));
     if (p8 == NULL) return NULL;
-    
-    // Since this only works for 8 bit input, values comes always as x * 257, 
+
+    // Since this only works for 8 bit input, values comes always as x * 257,
     // we can safely take msb byte (x << 8 + x)
 
     for (i=0; i < 256; i++) {
@@ -768,13 +796,13 @@ Prelin8Data* PrelinOpt8alloc(cmsContext ContextID, const cmsInterpParams* p, cms
 
 static
 void Prelin8free(cmsContext ContextID, void* ptr)
-{   
+{
     _cmsFree(ContextID, ptr);
 }
 
 static
 void* Prelin8dup(cmsContext ContextID, const void* ptr)
-{   
+{
     return _cmsDupMem(ContextID, ptr, sizeof(Prelin8Data));
 }
 
@@ -787,17 +815,17 @@ void PrelinEval8(register const cmsUInt16Number Input[],
                   register cmsUInt16Number Output[],
                   register const void* D)
 {
-    
+
     cmsUInt8Number         r, g, b;
-    cmsS15Fixed16Number    rx, ry, rz;            
-    cmsS15Fixed16Number    c0, c1, c2, c3, Rest;       
-    int        OutChan;
-    register   cmsS15Fixed16Number    X0, X1, Y0, Y1, Z0, Z1;
+    cmsS15Fixed16Number    rx, ry, rz;
+    cmsS15Fixed16Number    c0, c1, c2, c3, Rest;
+    int                    OutChan;
+    register cmsS15Fixed16Number    X0, X1, Y0, Y1, Z0, Z1;
     Prelin8Data* p8 = (Prelin8Data*) D;
     register const cmsInterpParams* p = p8 ->p;
     int                    TotalOut = p -> nOutputs;
     const cmsUInt16Number* LutTable = p -> Table;
-    
+
     r = Input[0] >> 8;
     g = Input[1] >> 8;
     b = Input[2] >> 8;
@@ -814,7 +842,7 @@ void PrelinEval8(register const cmsUInt16Number Input[],
     Y1 = Y0 + ((ry == 0) ? 0 : p ->opta[1]);
     Z1 = Z0 + ((rz == 0) ? 0 : p ->opta[0]);
 
-  
+
     // These are the 6 Tetrahedral
     for (OutChan=0; OutChan < TotalOut; OutChan++) {
 
@@ -824,11 +852,11 @@ void PrelinEval8(register const cmsUInt16Number Input[],
         {
             c1 = DENS(X1, Y0, Z0) - c0;
             c2 = DENS(X1, Y1, Z0) - DENS(X1, Y0, Z0);
-            c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);                
+            c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);
         }
         else
             if (rx >= rz && rz >= ry)
-            {            
+            {
                 c1 = DENS(X1, Y0, Z0) - c0;
                 c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);
                 c3 = DENS(X1, Y0, Z1) - DENS(X1, Y0, Z0);
@@ -838,38 +866,37 @@ void PrelinEval8(register const cmsUInt16Number Input[],
                 {
                     c1 = DENS(X1, Y0, Z1) - DENS(X0, Y0, Z1);
                     c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);
-                    c3 = DENS(X0, Y0, Z1) - c0;                            
+                    c3 = DENS(X0, Y0, Z1) - c0;
                 }
                 else
                     if (ry >= rx && rx >= rz)
                     {
                         c1 = DENS(X1, Y1, Z0) - DENS(X0, Y1, Z0);
                         c2 = DENS(X0, Y1, Z0) - c0;
-                        c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);          
+                        c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);
                     }
                     else
                         if (ry >= rz && rz >= rx)
                         {
                             c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);
                             c2 = DENS(X0, Y1, Z0) - c0;
-                            c3 = DENS(X0, Y1, Z1) - DENS(X0, Y1, Z0);                
+                            c3 = DENS(X0, Y1, Z1) - DENS(X0, Y1, Z0);
                         }
                         else
                             if (rz >= ry && ry >= rx)
-                            {             
+                            {
                                 c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);
                                 c2 = DENS(X0, Y1, Z1) - DENS(X0, Y0, Z1);
-                                c3 = DENS(X0, Y0, Z1) - c0;              
+                                c3 = DENS(X0, Y0, Z1) - c0;
                             }
                             else  {
-                                c1 = c2 = c3 = 0;              
+                                c1 = c2 = c3 = 0;
                             }
 
 
-                            Rest = c1 * rx + c2 * ry + c3 * rz;
+                            Rest = c1 * rx + c2 * ry + c3 * rz + 0x8001;
+                            Output[OutChan] = (cmsUInt16Number)c0 + ((Rest + (Rest>>16))>>16);
 
-                            Output[OutChan] = (cmsUInt16Number)c0 + ROUND_FIXED_TO_INT(_cmsToFixedDomain(Rest));
-                            
     }
 }
 
@@ -900,18 +927,19 @@ cmsBool IsDegenerated(const cmsToneCurve* g)
 // We need xput over here
 
 static
-cmsBool OptimizeByComputingLinearization(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt32Number* InputFormat, cmsUInt32Number* OutputFormat, cmsUInt32Number* dwFlags)      
+cmsBool OptimizeByComputingLinearization(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt32Number* InputFormat, cmsUInt32Number* OutputFormat, cmsUInt32Number* dwFlags)
 {
     cmsPipeline* OriginalLut;
     int nGridPoints;
     cmsToneCurve *Trans[cmsMAXCHANNELS], *TransReverse[cmsMAXCHANNELS];
-    cmsUInt32Number t, i;  
+    cmsUInt32Number t, i;
     cmsFloat32Number v, In[cmsMAXCHANNELS], Out[cmsMAXCHANNELS];
     cmsBool lIsSuitable, lIsLinear;
-    cmsPipeline* OptimizedLUT = NULL, *LutPlusCurves = NULL;    
+    cmsPipeline* OptimizedLUT = NULL, *LutPlusCurves = NULL;
     cmsStage* OptimizedCLUTmpe;
     cmsColorSpaceSignature ColorSpace, OutputColorSpace;
     cmsStage* OptimizedPrelinMpe;
+    cmsStage* mpe;
     cmsToneCurve**   OptimizedPrelinCurves;
     _cmsStageCLutData*     OptimizedPrelinCLUT;
 
@@ -930,6 +958,14 @@ cmsBool OptimizeByComputingLinearization(cmsPipeline** Lut, cmsUInt32Number Inte
     }
 
     OriginalLut = *Lut;
+
+   // Named color pipelines cannot be optimized either
+   for (mpe = cmsPipelineGetPtrToFirstStage(OriginalLut);
+         mpe != NULL;
+         mpe = cmsStageNext(mpe)) {
+            if (cmsStageType(mpe) == cmsSigNamedColorElemType) return FALSE;
+    }
+
     ColorSpace       = _cmsICCcolorSpace(T_COLORSPACE(*InputFormat));
     OutputColorSpace = _cmsICCcolorSpace(T_COLORSPACE(*OutputFormat));
     nGridPoints      = _cmsReasonableGridpointsByColorspace(ColorSpace, *dwFlags);
@@ -961,7 +997,7 @@ cmsBool OptimizeByComputingLinearization(cmsPipeline** Lut, cmsUInt32Number Inte
     }
 
     // Slope-limit the obtained curves
-    for (t = 0; t < OriginalLut ->InputChannels; t++) 
+    for (t = 0; t < OriginalLut ->InputChannels; t++)
         SlopeLimiting(Trans[t]);
 
     // Check for validity
@@ -975,7 +1011,7 @@ cmsBool OptimizeByComputingLinearization(cmsPipeline** Lut, cmsUInt32Number Inte
 
         // Exclude if non-monotonic
         if (!cmsIsToneCurveMonotonic(Trans[t]))
-            lIsSuitable = FALSE;         
+            lIsSuitable = FALSE;
 
         if (IsDegenerated(Trans[t]))
             lIsSuitable = FALSE;
@@ -1002,7 +1038,7 @@ cmsBool OptimizeByComputingLinearization(cmsPipeline** Lut, cmsUInt32Number Inte
 
     OptimizedPrelinMpe = cmsStageAllocToneCurves(OriginalLut ->ContextID, OriginalLut ->InputChannels, Trans);
 
-    // Create and insert the curves at the beginning    
+    // Create and insert the curves at the beginning
     cmsPipelineInsertStage(OptimizedLUT, cmsAT_BEGIN, OptimizedPrelinMpe);
 
     // Allocate the CLUT for result
@@ -1030,18 +1066,18 @@ cmsBool OptimizeByComputingLinearization(cmsPipeline** Lut, cmsUInt32Number Inte
     // Set the evaluator if 8-bit
     if (_cmsFormatterIs8bit(*InputFormat)) {
 
-        Prelin8Data* p8 = PrelinOpt8alloc(OptimizedLUT ->ContextID, 
-                                                OptimizedPrelinCLUT ->Params, 
+        Prelin8Data* p8 = PrelinOpt8alloc(OptimizedLUT ->ContextID,
+                                                OptimizedPrelinCLUT ->Params,
                                                 OptimizedPrelinCurves);
         if (p8 == NULL) return FALSE;
 
         _cmsPipelineSetOptimizationParameters(OptimizedLUT, PrelinEval8, (void*) p8, Prelin8free, Prelin8dup);
 
-    } 
+    }
     else
     {
-        Prelin16Data* p16 = PrelinOpt16alloc(OptimizedLUT ->ContextID, 
-            OptimizedPrelinCLUT ->Params, 
+        Prelin16Data* p16 = PrelinOpt16alloc(OptimizedLUT ->ContextID,
+            OptimizedPrelinCLUT ->Params,
             3, OptimizedPrelinCurves, 3, NULL);
         if (p16 == NULL) return FALSE;
 
@@ -1075,10 +1111,10 @@ Error:
         if (TransReverse[t]) cmsFreeToneCurve(TransReverse[t]);
     }
 
-    if (LutPlusCurves != NULL) cmsPipelineFree(LutPlusCurves);   
+    if (LutPlusCurves != NULL) cmsPipelineFree(LutPlusCurves);
     if (OptimizedLUT != NULL) cmsPipelineFree(OptimizedLUT);
 
-    return FALSE;    
+    return FALSE;
 
     cmsUNUSED_PARAMETER(Intent);
 }
@@ -1088,12 +1124,12 @@ Error:
 
 static
 void CurvesFree(cmsContext ContextID, void* ptr)
-{   
+{
      Curves16Data* Data = (Curves16Data*) ptr;
      int i;
 
      for (i=0; i < Data -> nCurves; i++) {
-     
+
          _cmsFree(ContextID, Data ->Curves[i]);
      }
 
@@ -1103,7 +1139,7 @@ void CurvesFree(cmsContext ContextID, void* ptr)
 
 static
 void* CurvesDup(cmsContext ContextID, const void* ptr)
-{   
+{
     Curves16Data* Data = _cmsDupMem(ContextID, ptr, sizeof(Curves16Data));
     int i;
 
@@ -1118,7 +1154,7 @@ void* CurvesDup(cmsContext ContextID, const void* ptr)
     return (void*) Data;
 }
 
-// Precomputes tables for 8-bit on input devicelink. 
+// Precomputes tables for 8-bit on input devicelink.
 static
 Curves16Data* CurvesAlloc(cmsContext ContextID, int nCurves, int nElements, cmsToneCurve** G)
 {
@@ -1142,13 +1178,13 @@ Curves16Data* CurvesAlloc(cmsContext ContextID, int nCurves, int nElements, cmsT
 
             for (j=0; j < nElements; j++) {
 
-                c16 ->Curves[i][j] = cmsEvalToneCurve16(G[i], FROM_8_TO_16(j));             
+                c16 ->Curves[i][j] = cmsEvalToneCurve16(G[i], FROM_8_TO_16(j));
             }
         }
         else {
 
             for (j=0; j < nElements; j++) {
-                c16 ->Curves[i][j] = cmsEvalToneCurve16(G[i], (cmsUInt16Number) j);             
+                c16 ->Curves[i][j] = cmsEvalToneCurve16(G[i], (cmsUInt16Number) j);
             }
         }
     }
@@ -1157,14 +1193,14 @@ Curves16Data* CurvesAlloc(cmsContext ContextID, int nCurves, int nElements, cmsT
 }
 
 static
-void FastEvaluateCurves8(register const cmsUInt16Number In[], 
-                          register cmsUInt16Number Out[], 
+void FastEvaluateCurves8(register const cmsUInt16Number In[],
+                          register cmsUInt16Number Out[],
                           register const void* D)
-{   
+{
     Curves16Data* Data = (Curves16Data*) D;
     cmsUInt8Number x;
     int i;
-    
+
     for (i=0; i < Data ->nCurves; i++) {
 
          x = (In[i] >> 8);
@@ -1172,15 +1208,15 @@ void FastEvaluateCurves8(register const cmsUInt16Number In[],
     }
 }
 
-    
+
 static
-void FastEvaluateCurves16(register const cmsUInt16Number In[], 
-                          register cmsUInt16Number Out[], 
+void FastEvaluateCurves16(register const cmsUInt16Number In[],
+                          register cmsUInt16Number Out[],
                           register const void* D)
-{   
+{
     Curves16Data* Data = (Curves16Data*) D;
     int i;
-    
+
     for (i=0; i < Data ->nCurves; i++) {
          Out[i] = Data -> Curves[i][In[i]];
     }
@@ -1188,15 +1224,15 @@ void FastEvaluateCurves16(register const cmsUInt16Number In[],
 
 
 static
-void FastIdentity16(register const cmsUInt16Number In[], 
-                    register cmsUInt16Number Out[], 
+void FastIdentity16(register const cmsUInt16Number In[],
+                    register cmsUInt16Number Out[],
                     register const void* D)
 {
     cmsPipeline* Lut = (cmsPipeline*) D;
     cmsUInt32Number i;
 
     for (i=0; i < Lut ->InputChannels; i++) {
-         Out[i] = In[i];   
+         Out[i] = In[i];
     }
 }
 
@@ -1206,7 +1242,7 @@ void FastIdentity16(register const cmsUInt16Number In[],
 static
 cmsBool OptimizeByJoiningCurves(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt32Number* InputFormat, cmsUInt32Number* OutputFormat, cmsUInt32Number* dwFlags)
 {
-    cmsToneCurve** GammaTables = NULL; 
+    cmsToneCurve** GammaTables = NULL;
     cmsFloat32Number InFloat[cmsMAXCHANNELS], OutFloat[cmsMAXCHANNELS];
     cmsUInt32Number i, j;
     cmsPipeline* Src = *Lut;
@@ -1225,7 +1261,7 @@ cmsBool OptimizeByJoiningCurves(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUI
             if (cmsStageType(mpe) != cmsSigCurveSetElemType) return FALSE;
     }
 
-    // Allocate an empty LUT 
+    // Allocate an empty LUT
     Dest =  cmsPipelineAlloc(Src ->ContextID, Src ->InputChannels, Src ->OutputChannels);
     if (Dest == NULL) return FALSE;
 
@@ -1241,7 +1277,7 @@ cmsBool OptimizeByJoiningCurves(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUI
     // Compute 16 bit result by using floating point
     for (i=0; i < PRELINEARIZATION_POINTS; i++) {
 
-        for (j=0; j < Src ->InputChannels; j++) 
+        for (j=0; j < Src ->InputChannels; j++)
             InFloat[j] = (cmsFloat32Number) ((cmsFloat64Number) i / (PRELINEARIZATION_POINTS - 1));
 
         cmsPipelineEvalFloat(InFloat, OutFloat, Src);
@@ -1263,7 +1299,7 @@ cmsBool OptimizeByJoiningCurves(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUI
     // Maybe the curves are linear at the end
     if (!AllCurvesAreLinear(ObtainedCurves)) {
 
-        cmsPipelineInsertStage(Dest, cmsAT_BEGIN, ObtainedCurves); 
+        cmsPipelineInsertStage(Dest, cmsAT_BEGIN, ObtainedCurves);
 
         // If the curves are to be applied in 8 bits, we can save memory
         if (_cmsFormatterIs8bit(*InputFormat)) {
@@ -1281,7 +1317,7 @@ cmsBool OptimizeByJoiningCurves(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUI
              Curves16Data* c16 = CurvesAlloc(Dest ->ContextID, Data ->nCurves, 65536, Data ->TheCurves);
 
              *dwFlags |= cmsFLAGS_NOCACHE;
-            _cmsPipelineSetOptimizationParameters(Dest, FastEvaluateCurves16, c16, CurvesFree, CurvesDup);          
+            _cmsPipelineSetOptimizationParameters(Dest, FastEvaluateCurves16, c16, CurvesFree, CurvesDup);
         }
     }
     else {
@@ -1337,44 +1373,44 @@ void* DupMatShaper(cmsContext ContextID, const void* Data)
 }
 
 
-// A fast matrix-shaper evaluator for 8 bits. This is a bit ticky since I'm using 1.14 signed fixed point 
-// to accomplish some performance. Actually it takes 256x3 16 bits tables and 16385 x 3 tables of 8 bits, 
+// A fast matrix-shaper evaluator for 8 bits. This is a bit ticky since I'm using 1.14 signed fixed point
+// to accomplish some performance. Actually it takes 256x3 16 bits tables and 16385 x 3 tables of 8 bits,
 // in total about 50K, and the performance boost is huge!
 static
-void MatShaperEval16(register const cmsUInt16Number In[], 
-                     register cmsUInt16Number Out[], 
+void MatShaperEval16(register const cmsUInt16Number In[],
+                     register cmsUInt16Number Out[],
                      register const void* D)
-{    
+{
     MatShaper8Data* p = (MatShaper8Data*) D;
     cmsS1Fixed14Number l1, l2, l3, r, g, b;
     cmsUInt32Number ri, gi, bi;
 
-    // In this case (and only in this case!) we can use this simplification since 
+    // In this case (and only in this case!) we can use this simplification since
     // In[] is assured to come from a 8 bit number. (a << 8 | a)
     ri = In[0] & 0xFF;
     gi = In[1] & 0xFF;
     bi = In[2] & 0xFF;
-    
+
     // Across first shaper, which also converts to 1.14 fixed point
     r = p->Shaper1R[ri];
     g = p->Shaper1G[gi];
     b = p->Shaper1B[bi];
-        
+
     // Evaluate the matrix in 1.14 fixed point
     l1 =  (p->Mat[0][0] * r + p->Mat[0][1] * g + p->Mat[0][2] * b + p->Off[0] + 0x2000) >> 14;
     l2 =  (p->Mat[1][0] * r + p->Mat[1][1] * g + p->Mat[1][2] * b + p->Off[1] + 0x2000) >> 14;
     l3 =  (p->Mat[2][0] * r + p->Mat[2][1] * g + p->Mat[2][2] * b + p->Off[2] + 0x2000) >> 14;
-    
-    // Now we have to clip to 0..1.0 range 
-    ri = (l1 < 0) ? 0 : ((l1 > 16384) ? 16384 : l1);               
-    gi = (l2 < 0) ? 0 : ((l2 > 16384) ? 16384 : l2);               
-    bi = (l3 < 0) ? 0 : ((l3 > 16384) ? 16384 : l3);               
-         
-    // And across second shaper, 
+
+    // Now we have to clip to 0..1.0 range
+    ri = (l1 < 0) ? 0 : ((l1 > 16384) ? 16384 : l1);
+    gi = (l2 < 0) ? 0 : ((l2 > 16384) ? 16384 : l2);
+    bi = (l3 < 0) ? 0 : ((l3 > 16384) ? 16384 : l3);
+
+    // And across second shaper,
     Out[0] = p->Shaper2R[ri];
     Out[1] = p->Shaper2G[gi];
     Out[2] = p->Shaper2B[bi];
-   
+
 }
 
 // This table converts from 8 bits to 1.14 after applying the curve
@@ -1385,9 +1421,9 @@ void FillFirstShaper(cmsS1Fixed14Number* Table, cmsToneCurve* Curve)
     cmsFloat32Number R, y;
 
     for (i=0; i < 256; i++) {
-        
+
         R   = (cmsFloat32Number) (i / 255.0);
-        y   = cmsEvalToneCurveFloat(Curve, R);        
+        y   = cmsEvalToneCurveFloat(Curve, R);
 
         Table[i] = DOUBLE_TO_1FIXED14(y);
     }
@@ -1404,19 +1440,19 @@ void FillSecondShaper(cmsUInt16Number* Table, cmsToneCurve* Curve, cmsBool Is8Bi
 
         R   = (cmsFloat32Number) (i / 16384.0);
         Val = cmsEvalToneCurveFloat(Curve, R);    // Val comes 0..1.0
-        
+
         if (Is8BitsOutput) {
 
             // If 8 bits output, we can optimize further by computing the / 257 part.
             // first we compute the resulting byte and then we store the byte times
             // 257. This quantization allows to round very quick by doing a >> 8, but
             // since the low byte is always equal to msb, we can do a & 0xff and this works!
-            cmsUInt16Number w = _cmsQuickSaturateWord(Val * 65535.0 + 0.5);        
+            cmsUInt16Number w = _cmsQuickSaturateWord(Val * 65535.0);
             cmsUInt8Number  b = FROM_16_TO_8(w);
 
             Table[i] = FROM_8_TO_16(b);
         }
-        else Table[i]  = _cmsQuickSaturateWord(Val * 65535.0 + 0.5);        
+        else Table[i]  = _cmsQuickSaturateWord(Val * 65535.0);
     }
 }
 
@@ -1445,17 +1481,17 @@ cmsBool SetMatShaper(cmsPipeline* Dest, cmsToneCurve* Curve1[3], cmsMAT3* Mat, c
 
     // Convert matrix to nFixed14. Note that those values may take more than 16 bits as
     for (i=0; i < 3; i++) {
-        for (j=0; j < 3; j++) {         
+        for (j=0; j < 3; j++) {
             p ->Mat[i][j] = DOUBLE_TO_1FIXED14(Mat->v[i].n[j]);
         }
     }
-    
+
     for (i=0; i < 3; i++) {
 
-        if (Off == NULL) {          
+        if (Off == NULL) {
             p ->Off[i] = 0;
         }
-        else {      
+        else {
             p ->Off[i] = DOUBLE_TO_1FIXED14(Off->n[i]);
         }
     }
@@ -1464,7 +1500,7 @@ cmsBool SetMatShaper(cmsPipeline* Dest, cmsToneCurve* Curve1[3], cmsMAT3* Mat, c
     if (Is8Bits)
         *OutputFormat |= OPTIMIZED_SH(1);
 
-    // Fill function pointers    
+    // Fill function pointers
     _cmsPipelineSetOptimizationParameters(Dest, MatShaperEval16, (void*) p, FreeMatShaper, DupMatShaper);
     return TRUE;
 }
@@ -1481,7 +1517,7 @@ cmsBool OptimizeMatrixShaper(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt3
     cmsMAT3 res;
     cmsBool IdentityMat;
     cmsPipeline* Dest, *Src;
-   
+
     // Only works on RGB to RGB
     if (T_CHANNELS(*InputFormat) != 3 || T_CHANNELS(*OutputFormat) != 3) return FALSE;
 
@@ -1492,8 +1528,8 @@ cmsBool OptimizeMatrixShaper(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt3
     Src = *Lut;
 
     // Check for shaper-matrix-matrix-shaper structure, that is what this optimizer stands for
-    if (!cmsPipelineCheckAndRetreiveStages(Src, 4, 
-        cmsSigCurveSetElemType, cmsSigMatrixElemType, cmsSigMatrixElemType, cmsSigCurveSetElemType, 
+    if (!cmsPipelineCheckAndRetreiveStages(Src, 4,
+        cmsSigCurveSetElemType, cmsSigMatrixElemType, cmsSigMatrixElemType, cmsSigCurveSetElemType,
         &Curve1, &Matrix1, &Matrix2, &Curve2)) return FALSE;
 
     // Get both matrices
@@ -1514,26 +1550,26 @@ cmsBool OptimizeMatrixShaper(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt3
         IdentityMat = TRUE;
     }
 
-      // Allocate an empty LUT 
+      // Allocate an empty LUT
     Dest =  cmsPipelineAlloc(Src ->ContextID, Src ->InputChannels, Src ->OutputChannels);
     if (!Dest) return FALSE;
 
     // Assamble the new LUT
     cmsPipelineInsertStage(Dest, cmsAT_BEGIN, cmsStageDup(Curve1));
-    if (!IdentityMat) 
+    if (!IdentityMat)
         cmsPipelineInsertStage(Dest, cmsAT_END, cmsStageAllocMatrix(Dest ->ContextID, 3, 3, (const cmsFloat64Number*) &res, Data2 ->Offset));
     cmsPipelineInsertStage(Dest, cmsAT_END, cmsStageDup(Curve2));
 
     // If identity on matrix, we can further optimize the curves, so call the join curves routine
     if (IdentityMat) {
 
-        OptimizeByJoiningCurves(&Dest, Intent, InputFormat, OutputFormat, dwFlags);     
+        OptimizeByJoiningCurves(&Dest, Intent, InputFormat, OutputFormat, dwFlags);
     }
     else {
         _cmsStageToneCurvesData* mpeC1 = (_cmsStageToneCurvesData*) cmsStageData(Curve1);
         _cmsStageToneCurvesData* mpeC2 = (_cmsStageToneCurvesData*) cmsStageData(Curve2);
-                
-        // In this particular optimization, caché does not help as it takes more time to deal with 
+
+        // In this particular optimization, caché does not help as it takes more time to deal with
         // the caché that with the pixel handling
         *dwFlags |= cmsFLAGS_NOCACHE;
 
@@ -1552,9 +1588,9 @@ cmsBool OptimizeMatrixShaper(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt3
 
 // List of optimizations
 typedef struct _cmsOptimizationCollection_st {
-    
+
     _cmsOPToptimizeFn  OptimizePtr;
-    
+
     struct _cmsOptimizationCollection_st *Next;
 
 } _cmsOptimizationCollection;
@@ -1577,13 +1613,13 @@ cmsBool  _cmsRegisterOptimizationPlugin(cmsPluginBase* Data)
 {
     cmsPluginOptimization* Plugin = (cmsPluginOptimization*) Data;
     _cmsOptimizationCollection* fl;
-    
+
     if (Data == NULL) {
 
-        OptimizationCollection = DefaultOptimization; 
+        OptimizationCollection = DefaultOptimization;
         return TRUE;
     }
-    
+
     // Optimizer callback is required
     if (Plugin ->OptimizePtr == NULL) return FALSE;
 
@@ -1592,7 +1628,7 @@ cmsBool  _cmsRegisterOptimizationPlugin(cmsPluginBase* Data)
 
     // Copy the parameters
     fl ->OptimizePtr = Plugin ->OptimizePtr;
-        
+
     // Keep linked list
     fl ->Next = OptimizationCollection;
     OptimizationCollection = fl;
@@ -1602,18 +1638,18 @@ cmsBool  _cmsRegisterOptimizationPlugin(cmsPluginBase* Data)
 }
 
 // The entry point for LUT optimization
-cmsBool _cmsOptimizePipeline(cmsPipeline**    PtrLut,                                               
+cmsBool _cmsOptimizePipeline(cmsPipeline**    PtrLut,
                              int              Intent,
-                             cmsUInt32Number* InputFormat, 
+                             cmsUInt32Number* InputFormat,
                              cmsUInt32Number* OutputFormat,
                              cmsUInt32Number* dwFlags)
-{    
+{
     _cmsOptimizationCollection* Opts;
     cmsBool AnySuccess = FALSE;
-   
+
     // A CLUT is being asked, so force this specific optimization
     if (*dwFlags & cmsFLAGS_FORCE_CLUT) {
-    
+
         PreOptimize(*PtrLut);
         return OptimizeByResampling(PtrLut, Intent, InputFormat, OutputFormat, dwFlags);
     }
@@ -1621,7 +1657,7 @@ cmsBool _cmsOptimizePipeline(cmsPipeline**    PtrLut,
     // Anything to optimize?
     if ((*PtrLut) ->Elements == NULL) {
         _cmsPipelineSetOptimizationParameters(*PtrLut, FastIdentity16, (void*) *PtrLut, NULL, NULL);
-        return TRUE;        
+        return TRUE;
     }
 
     // Try to get rid of identities and trivial conversions.
@@ -1636,19 +1672,19 @@ cmsBool _cmsOptimizePipeline(cmsPipeline**    PtrLut,
     // Do not optimize, keep all precision
     if (*dwFlags & cmsFLAGS_NOOPTIMIZE)
         return FALSE;
-    
+
     // Try built-in optimizations and plug-in
     for (Opts = OptimizationCollection;
          Opts != NULL;
          Opts = Opts ->Next) {
-            
+
             // If one schema succeeded, we are done
             if (Opts ->OptimizePtr(PtrLut, Intent, InputFormat, OutputFormat, dwFlags)) {
-                
+
                 return TRUE;    // Optimized!
             }
     }
-    
+
     // Only simple optimizations succeeded
     return AnySuccess;
 }
index 63a9bc0..71ffcae 100644 (file)
@@ -3,22 +3,22 @@
 //  Little Color Management System
 //  Copyright (c) 1998-2010 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 
+// 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 
+// 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 
+// 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"
 
-// This module handles all formats supported by lcms. There are two flavors, 16 bits and 
+// This module handles all formats supported by lcms. There are two flavors, 16 bits and
 // floating point. Floating point is supported only in a subset, those formats holding
-// cmsFloat32Number (4 bytes per component) and double (marked as 0 bytes per component as special 
-// case)
+// cmsFloat32Number (4 bytes per component) and double (marked as 0 bytes per component
+// as special case)
 
 // ---------------------------------------------------------------------------
 
 #define REVERSE_FLAVOR_16(x)    ((cmsUInt16Number)(0xffff-(x)))
 
 // * 0xffff / 0xff00 = (255 * 257) / (255 * 256) = 257 / 256
-cmsINLINE cmsUInt16Number FomLabV2ToLabV4(cmsUInt16Number x) 
+cmsINLINE cmsUInt16Number FomLabV2ToLabV4(cmsUInt16Number x)
 {
-    int a;
-
-    a = (x << 8 | x) >> 8;  // * 257 / 256
+    int a = (x << 8 | x) >> 8;  // * 257 / 256
     if ( a > 0xffff) return 0xffff;
     return (cmsUInt16Number) a;
 }
 
 // * 0xf00 / 0xffff = * 256 / 257
-cmsINLINE cmsUInt16Number FomLabV4ToLabV2(cmsUInt16Number x) 
+cmsINLINE cmsUInt16Number FomLabV4ToLabV2(cmsUInt16Number x)
 {
     return (cmsUInt16Number) (((x << 8) + 0x80) / 257);
 }
@@ -61,24 +59,25 @@ cmsINLINE cmsUInt16Number FomLabV4ToLabV2(cmsUInt16Number x)
 typedef struct {
     cmsUInt32Number Type;
     cmsUInt32Number Mask;
-    cmsFormatter16 Frm;
+    cmsFormatter16  Frm;
 
 } cmsFormatters16;
 
 typedef struct {
     cmsUInt32Number    Type;
     cmsUInt32Number    Mask;
-    cmsFormatterFloat Frm;
+    cmsFormatterFloat  Frm;
 
 } cmsFormattersFloat;
 
+
 #define ANYSPACE        COLORSPACE_SH(31)
 #define ANYCHANNELS     CHANNELS_SH(15)
 #define ANYEXTRA        EXTRA_SH(7)
 #define ANYPLANAR       PLANAR_SH(1)
 #define ANYENDIAN       ENDIAN16_SH(1)
 #define ANYSWAP         DOSWAP_SH(1)
-#define ANYSWAPFIRST    SWAPFIRST_SH(1) 
+#define ANYSWAPFIRST    SWAPFIRST_SH(1)
 #define ANYFLAVOR       FLAVOR_SH(1)
 
 
@@ -88,12 +87,13 @@ typedef struct {
 #pragma warning(disable : 4100)
 #endif
 
-// Unpacking routines (16 bits) ---------------------------------------------------------------------------------------- 
+// Unpacking routines (16 bits) ----------------------------------------------------------------------------------------
+
 
 // Does almost everything but is slow
 static
-cmsUInt8Number* UnrollChunkyBytes(register _cmsTRANSFORM* info, 
-                                  register cmsUInt16Number wIn[], 
+cmsUInt8Number* UnrollChunkyBytes(register _cmsTRANSFORM* info,
+                                  register cmsUInt16Number wIn[],
                                   register cmsUInt8Number* accum,
                                   register cmsUInt32Number Stride)
 {
@@ -102,7 +102,7 @@ cmsUInt8Number* UnrollChunkyBytes(register _cmsTRANSFORM* info,
     int Reverse    = T_FLAVOR(info ->InputFormat);
     int SwapFirst  = T_SWAPFIRST(info -> InputFormat);
     int Extra      = T_EXTRA(info -> InputFormat);
-    int ExtraFirst = DoSwap && !SwapFirst;
+    int ExtraFirst = DoSwap SwapFirst;
     cmsUInt16Number v;
     int i;
 
@@ -113,10 +113,10 @@ cmsUInt8Number* UnrollChunkyBytes(register _cmsTRANSFORM* info,
     for (i=0; i < nChan; i++) {
         int index = DoSwap ? (nChan - i - 1) : i;
 
-        v = FROM_8_TO_16(*accum); 
+        v = FROM_8_TO_16(*accum);
         v = Reverse ? REVERSE_FLAVOR_16(v) : v;
         wIn[index] = v;
-        accum++;              
+        accum++;
     }
 
     if (!ExtraFirst) {
@@ -139,25 +139,26 @@ cmsUInt8Number* UnrollChunkyBytes(register _cmsTRANSFORM* info,
 
 // Extra channels are just ignored because come in the next planes
 static
-cmsUInt8Number* UnrollPlanarBytes(register _cmsTRANSFORM* info, 
-                                  register cmsUInt16Number wIn[], 
+cmsUInt8Number* UnrollPlanarBytes(register _cmsTRANSFORM* info,
+                                  register cmsUInt16Number wIn[],
                                   register cmsUInt8Number* accum,
                                   register cmsUInt32Number Stride)
 {
-    int nChan = T_CHANNELS(info -> InputFormat);
-    int DoSwap= T_DOSWAP(info ->InputFormat);
-    int Reverse= T_FLAVOR(info ->InputFormat);
+    int nChan     = T_CHANNELS(info -> InputFormat);
+    int DoSwap    = T_DOSWAP(info ->InputFormat);
+    int SwapFirst = T_SWAPFIRST(info ->InputFormat);
+    int Reverse   = T_FLAVOR(info ->InputFormat);
     int i;
     cmsUInt8Number* Init = accum;
 
-    if (DoSwap) {
+    if (DoSwap ^ SwapFirst) {
         accum += T_EXTRA(info -> InputFormat) * Stride;
     }
 
     for (i=0; i < nChan; i++) {
 
         int index = DoSwap ? (nChan - i - 1) : i;
-        cmsUInt16Number v = FROM_8_TO_16(*accum); 
+        cmsUInt16Number v = FROM_8_TO_16(*accum);
 
         wIn[index] = Reverse ? REVERSE_FLAVOR_16(v) : v;
         accum += Stride;
@@ -168,8 +169,8 @@ cmsUInt8Number* UnrollPlanarBytes(register _cmsTRANSFORM* info,
 
 // Special cases, provided for performance
 static
-cmsUInt8Number* Unroll4Bytes(register _cmsTRANSFORM* info, 
-                             register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll4Bytes(register _cmsTRANSFORM* info,
+                             register cmsUInt16Number wIn[],
                              register cmsUInt8Number* accum,
                              register cmsUInt32Number Stride)
 {
@@ -185,8 +186,8 @@ cmsUInt8Number* Unroll4Bytes(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Unroll4BytesReverse(register _cmsTRANSFORM* info, 
-                                    register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll4BytesReverse(register _cmsTRANSFORM* info,
+                                    register cmsUInt16Number wIn[],
                                     register cmsUInt8Number* accum,
                                     register cmsUInt32Number Stride)
 {
@@ -202,8 +203,8 @@ cmsUInt8Number* Unroll4BytesReverse(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Unroll4BytesSwapFirst(register _cmsTRANSFORM* info, 
-                                      register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll4BytesSwapFirst(register _cmsTRANSFORM* info,
+                                      register cmsUInt16Number wIn[],
                                       register cmsUInt8Number* accum,
                                       register cmsUInt32Number Stride)
 {
@@ -220,8 +221,8 @@ cmsUInt8Number* Unroll4BytesSwapFirst(register _cmsTRANSFORM* info,
 
 // KYMC
 static
-cmsUInt8Number* Unroll4BytesSwap(register _cmsTRANSFORM* info, 
-                                 register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll4BytesSwap(register _cmsTRANSFORM* info,
+                                 register cmsUInt16Number wIn[],
                                  register cmsUInt8Number* accum,
                                  register cmsUInt32Number Stride)
 {
@@ -237,8 +238,8 @@ cmsUInt8Number* Unroll4BytesSwap(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Unroll4BytesSwapSwapFirst(register _cmsTRANSFORM* info, 
-                                          register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll4BytesSwapSwapFirst(register _cmsTRANSFORM* info,
+                                          register cmsUInt16Number wIn[],
                                           register cmsUInt8Number* accum,
                                           register cmsUInt32Number Stride)
 {
@@ -254,8 +255,8 @@ cmsUInt8Number* Unroll4BytesSwapSwapFirst(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Unroll3Bytes(register _cmsTRANSFORM* info, 
-                             register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll3Bytes(register _cmsTRANSFORM* info,
+                             register cmsUInt16Number wIn[],
                              register cmsUInt8Number* accum,
                              register cmsUInt32Number Stride)
 {
@@ -270,8 +271,8 @@ cmsUInt8Number* Unroll3Bytes(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Unroll3BytesSkip1Swap(register _cmsTRANSFORM* info, 
-                                      register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll3BytesSkip1Swap(register _cmsTRANSFORM* info,
+                                      register cmsUInt16Number wIn[],
                                       register cmsUInt8Number* accum,
                                       register cmsUInt32Number Stride)
 {
@@ -287,8 +288,8 @@ cmsUInt8Number* Unroll3BytesSkip1Swap(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Unroll3BytesSkip1SwapFirst(register _cmsTRANSFORM* info, 
-                                           register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll3BytesSkip1SwapFirst(register _cmsTRANSFORM* info,
+                                           register cmsUInt16Number wIn[],
                                            register cmsUInt8Number* accum,
                                            register cmsUInt32Number Stride)
 {
@@ -306,8 +307,8 @@ cmsUInt8Number* Unroll3BytesSkip1SwapFirst(register _cmsTRANSFORM* info,
 
 // BRG
 static
-cmsUInt8Number* Unroll3BytesSwap(register _cmsTRANSFORM* info, 
-                                 register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll3BytesSwap(register _cmsTRANSFORM* info,
+                                 register cmsUInt16Number wIn[],
                                  register cmsUInt8Number* accum,
                                  register cmsUInt32Number Stride)
 {
@@ -322,8 +323,8 @@ cmsUInt8Number* Unroll3BytesSwap(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* UnrollLabV2_8(register _cmsTRANSFORM* info, 
-                              register cmsUInt16Number wIn[], 
+cmsUInt8Number* UnrollLabV2_8(register _cmsTRANSFORM* info,
+                              register cmsUInt16Number wIn[],
                               register cmsUInt8Number* accum,
                               register cmsUInt32Number Stride)
 {
@@ -338,8 +339,8 @@ cmsUInt8Number* UnrollLabV2_8(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* UnrollALabV2_8(register _cmsTRANSFORM* info, 
-                               register cmsUInt16Number wIn[], 
+cmsUInt8Number* UnrollALabV2_8(register _cmsTRANSFORM* info,
+                               register cmsUInt16Number wIn[],
                                register cmsUInt8Number* accum,
                                register cmsUInt32Number Stride)
 {
@@ -355,8 +356,8 @@ cmsUInt8Number* UnrollALabV2_8(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* UnrollLabV2_16(register _cmsTRANSFORM* info, 
-                               register cmsUInt16Number wIn[], 
+cmsUInt8Number* UnrollLabV2_16(register _cmsTRANSFORM* info,
+                               register cmsUInt16Number wIn[],
                                register cmsUInt8Number* accum,
                                register cmsUInt32Number Stride)
 {
@@ -372,8 +373,8 @@ cmsUInt8Number* UnrollLabV2_16(register _cmsTRANSFORM* info,
 
 // for duplex
 static
-cmsUInt8Number* Unroll2Bytes(register _cmsTRANSFORM* info, 
-                                     register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll2Bytes(register _cmsTRANSFORM* info,
+                                     register cmsUInt16Number wIn[],
                                      register cmsUInt8Number* accum,
                                      register cmsUInt32Number Stride)
 {
@@ -391,8 +392,8 @@ cmsUInt8Number* Unroll2Bytes(register _cmsTRANSFORM* info,
 
 // Monochrome duplicates L into RGB for null-transforms
 static
-cmsUInt8Number* Unroll1Byte(register _cmsTRANSFORM* info, 
-                            register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll1Byte(register _cmsTRANSFORM* info,
+                            register cmsUInt16Number wIn[],
                             register cmsUInt8Number* accum,
                             register cmsUInt32Number Stride)
 {
@@ -406,8 +407,8 @@ cmsUInt8Number* Unroll1Byte(register _cmsTRANSFORM* info,
 
 
 static
-cmsUInt8Number* Unroll1ByteSkip1(register _cmsTRANSFORM* info, 
-                                 register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll1ByteSkip1(register _cmsTRANSFORM* info,
+                                 register cmsUInt16Number wIn[],
                                  register cmsUInt8Number* accum,
                                  register cmsUInt32Number Stride)
 {
@@ -421,8 +422,8 @@ cmsUInt8Number* Unroll1ByteSkip1(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Unroll1ByteSkip2(register _cmsTRANSFORM* info, 
-                                 register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll1ByteSkip2(register _cmsTRANSFORM* info,
+                                 register cmsUInt16Number wIn[],
                                  register cmsUInt8Number* accum,
                                  register cmsUInt32Number Stride)
 {
@@ -436,8 +437,8 @@ cmsUInt8Number* Unroll1ByteSkip2(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Unroll1ByteReversed(register _cmsTRANSFORM* info, 
-                                    register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll1ByteReversed(register _cmsTRANSFORM* info,
+                                    register cmsUInt16Number wIn[],
                                     register cmsUInt8Number* accum,
                                     register cmsUInt32Number Stride)
 {
@@ -451,8 +452,8 @@ cmsUInt8Number* Unroll1ByteReversed(register _cmsTRANSFORM* info,
 
 
 static
-cmsUInt8Number* UnrollAnyWords(register _cmsTRANSFORM* info, 
-                               register cmsUInt16Number wIn[], 
+cmsUInt8Number* UnrollAnyWords(register _cmsTRANSFORM* info,
+                               register cmsUInt16Number wIn[],
                                register cmsUInt8Number* accum,
                                register cmsUInt32Number Stride)
 {
@@ -462,7 +463,7 @@ cmsUInt8Number* UnrollAnyWords(register _cmsTRANSFORM* info,
     int Reverse     = T_FLAVOR(info ->InputFormat);
     int SwapFirst   = T_SWAPFIRST(info -> InputFormat);
     int Extra       = T_EXTRA(info -> InputFormat);
-    int ExtraFirst  = DoSwap && !SwapFirst;
+    int ExtraFirst  = DoSwap SwapFirst;
     int i;
 
     if (ExtraFirst) {
@@ -472,14 +473,14 @@ cmsUInt8Number* UnrollAnyWords(register _cmsTRANSFORM* info,
     for (i=0; i < nChan; i++) {
 
         int index = DoSwap ? (nChan - i - 1) : i;
-        cmsUInt16Number v = *(cmsUInt16Number*) accum; 
+        cmsUInt16Number v = *(cmsUInt16Number*) accum;
 
         if (SwapEndian)
             v = CHANGE_ENDIAN(v);
 
         wIn[index] = Reverse ? REVERSE_FLAVOR_16(v) : v;
 
-        accum += sizeof(cmsUInt16Number);              
+        accum += sizeof(cmsUInt16Number);
     }
 
     if (!ExtraFirst) {
@@ -500,8 +501,8 @@ cmsUInt8Number* UnrollAnyWords(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* UnrollPlanarWords(register _cmsTRANSFORM* info, 
-                                  register cmsUInt16Number wIn[], 
+cmsUInt8Number* UnrollPlanarWords(register _cmsTRANSFORM* info,
+                                  register cmsUInt16Number wIn[],
                                   register cmsUInt8Number* accum,
                                   register cmsUInt32Number Stride)
 {
@@ -519,14 +520,14 @@ cmsUInt8Number* UnrollPlanarWords(register _cmsTRANSFORM* info,
     for (i=0; i < nChan; i++) {
 
         int index = DoSwap ? (nChan - i - 1) : i;
-        cmsUInt16Number v = *(cmsUInt16Number*) accum; 
+        cmsUInt16Number v = *(cmsUInt16Number*) accum;
 
         if (SwapEndian)
             v = CHANGE_ENDIAN(v);
 
         wIn[index] = Reverse ? REVERSE_FLAVOR_16(v) : v;
 
-        accum +=  Stride * sizeof(cmsUInt16Number);           
+        accum +=  Stride * sizeof(cmsUInt16Number);
     }
 
     return (Init + sizeof(cmsUInt16Number));
@@ -534,8 +535,8 @@ cmsUInt8Number* UnrollPlanarWords(register _cmsTRANSFORM* info,
 
 
 static
-cmsUInt8Number* Unroll4Words(register _cmsTRANSFORM* info, 
-                             register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll4Words(register _cmsTRANSFORM* info,
+                             register cmsUInt16Number wIn[],
                              register cmsUInt8Number* accum,
                              register cmsUInt32Number Stride)
 {
@@ -551,8 +552,8 @@ cmsUInt8Number* Unroll4Words(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Unroll4WordsReverse(register _cmsTRANSFORM* info, 
-                                    register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll4WordsReverse(register _cmsTRANSFORM* info,
+                                    register cmsUInt16Number wIn[],
                                     register cmsUInt8Number* accum,
                                     register cmsUInt32Number Stride)
 {
@@ -568,8 +569,8 @@ cmsUInt8Number* Unroll4WordsReverse(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Unroll4WordsSwapFirst(register _cmsTRANSFORM* info, 
-                                      register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll4WordsSwapFirst(register _cmsTRANSFORM* info,
+                                      register cmsUInt16Number wIn[],
                                       register cmsUInt8Number* accum,
                                       register cmsUInt32Number Stride)
 {
@@ -586,8 +587,8 @@ cmsUInt8Number* Unroll4WordsSwapFirst(register _cmsTRANSFORM* info,
 
 // KYMC
 static
-cmsUInt8Number* Unroll4WordsSwap(register _cmsTRANSFORM* info, 
-                                 register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll4WordsSwap(register _cmsTRANSFORM* info,
+                                 register cmsUInt16Number wIn[],
                                  register cmsUInt8Number* accum,
                                  register cmsUInt32Number Stride)
 {
@@ -603,8 +604,8 @@ cmsUInt8Number* Unroll4WordsSwap(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Unroll4WordsSwapSwapFirst(register _cmsTRANSFORM* info, 
-                                          register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll4WordsSwapSwapFirst(register _cmsTRANSFORM* info,
+                                          register cmsUInt16Number wIn[],
                                           register cmsUInt8Number* accum,
                                           register cmsUInt32Number Stride)
 {
@@ -620,8 +621,8 @@ cmsUInt8Number* Unroll4WordsSwapSwapFirst(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Unroll3Words(register _cmsTRANSFORM* info, 
-                             register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll3Words(register _cmsTRANSFORM* info,
+                             register cmsUInt16Number wIn[],
                              register cmsUInt8Number* accum,
                              register cmsUInt32Number Stride)
 {
@@ -636,8 +637,8 @@ cmsUInt8Number* Unroll3Words(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Unroll3WordsSwap(register _cmsTRANSFORM* info, 
-                                 register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll3WordsSwap(register _cmsTRANSFORM* info,
+                                 register cmsUInt16Number wIn[],
                                  register cmsUInt8Number* accum,
                                  register cmsUInt32Number Stride)
 {
@@ -652,8 +653,8 @@ cmsUInt8Number* Unroll3WordsSwap(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Unroll3WordsSkip1Swap(register _cmsTRANSFORM* info, 
-                                      register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll3WordsSkip1Swap(register _cmsTRANSFORM* info,
+                                      register cmsUInt16Number wIn[],
                                       register cmsUInt8Number* accum,
                                       register cmsUInt32Number Stride)
 {
@@ -669,8 +670,8 @@ cmsUInt8Number* Unroll3WordsSkip1Swap(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Unroll3WordsSkip1SwapFirst(register _cmsTRANSFORM* info, 
-                                           register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll3WordsSkip1SwapFirst(register _cmsTRANSFORM* info,
+                                           register cmsUInt16Number wIn[],
                                            register cmsUInt8Number* accum,
                                            register cmsUInt32Number Stride)
 {
@@ -686,8 +687,8 @@ cmsUInt8Number* Unroll3WordsSkip1SwapFirst(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Unroll1Word(register _cmsTRANSFORM* info, 
-                            register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll1Word(register _cmsTRANSFORM* info,
+                            register cmsUInt16Number wIn[],
                             register cmsUInt8Number* accum,
                             register cmsUInt32Number Stride)
 {
@@ -700,8 +701,8 @@ cmsUInt8Number* Unroll1Word(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Unroll1WordReversed(register _cmsTRANSFORM* info, 
-                                    register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll1WordReversed(register _cmsTRANSFORM* info,
+                                    register cmsUInt16Number wIn[],
                                     register cmsUInt8Number* accum,
                                     register cmsUInt32Number Stride)
 {
@@ -714,12 +715,12 @@ cmsUInt8Number* Unroll1WordReversed(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Unroll1WordSkip3(register _cmsTRANSFORM* info, 
-                                 register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll1WordSkip3(register _cmsTRANSFORM* info,
+                                 register cmsUInt16Number wIn[],
                                  register cmsUInt8Number* accum,
                                  register cmsUInt32Number Stride)
 {
-    wIn[0] = wIn[1] = wIn[2] = *(cmsUInt16Number*) accum; 
+    wIn[0] = wIn[1] = wIn[2] = *(cmsUInt16Number*) accum;
 
     accum += 8;
 
@@ -730,8 +731,8 @@ cmsUInt8Number* Unroll1WordSkip3(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Unroll2Words(register _cmsTRANSFORM* info, 
-                                     register cmsUInt16Number wIn[], 
+cmsUInt8Number* Unroll2Words(register _cmsTRANSFORM* info,
+                                     register cmsUInt16Number wIn[],
                                      register cmsUInt8Number* accum,
                                      register cmsUInt32Number Stride)
 {
@@ -747,11 +748,11 @@ cmsUInt8Number* Unroll2Words(register _cmsTRANSFORM* info,
 
 // This is a conversion of Lab double to 16 bits
 static
-cmsUInt8Number* UnrollLabDoubleTo16(register _cmsTRANSFORM* info, 
-                                    register cmsUInt16Number wIn[], 
+cmsUInt8Number* UnrollLabDoubleTo16(register _cmsTRANSFORM* info,
+                                    register cmsUInt16Number wIn[],
                                     register cmsUInt8Number* accum,
                                     register cmsUInt32Number  Stride)
-{       
+{
     if (T_PLANAR(info -> InputFormat)) {
 
         cmsFloat64Number* Pt = (cmsFloat64Number*) accum;
@@ -773,13 +774,47 @@ cmsUInt8Number* UnrollLabDoubleTo16(register _cmsTRANSFORM* info,
     }
 }
 
+
+// This is a conversion of Lab float to 16 bits
+static
+cmsUInt8Number* UnrollLabFloatTo16(register _cmsTRANSFORM* info,
+                                    register cmsUInt16Number wIn[],
+                                    register cmsUInt8Number* accum,
+                                    register cmsUInt32Number  Stride)
+{
+    cmsCIELab Lab;
+    
+    if (T_PLANAR(info -> InputFormat)) {
+
+        cmsFloat32Number* Pt = (cmsFloat32Number*) accum;
+
+     
+        Lab.L = Pt[0];
+        Lab.a = Pt[Stride];
+        Lab.b = Pt[Stride*2];
+
+        cmsFloat2LabEncoded(wIn, &Lab);
+        return accum + sizeof(cmsFloat32Number);
+    }
+    else {
+        Lab.L = ((cmsFloat32Number*) accum)[0];
+        Lab.a = ((cmsFloat32Number*) accum)[1];
+        Lab.b = ((cmsFloat32Number*) accum)[2];
+
+        cmsFloat2LabEncoded(wIn, &Lab);
+        accum += (3 + T_EXTRA(info ->InputFormat)) * sizeof(cmsFloat32Number);
+        return accum;
+    }
+}
+
 // This is a conversion of XYZ double to 16 bits
 static
-cmsUInt8Number* UnrollXYZDoubleTo16(register _cmsTRANSFORM* info, 
-                                    register cmsUInt16Number wIn[], 
+cmsUInt8Number* UnrollXYZDoubleTo16(register _cmsTRANSFORM* info,
+                                    register cmsUInt16Number wIn[],
                                     register cmsUInt8Number* accum,
                                     register cmsUInt32Number Stride)
-{   
+{
     if (T_PLANAR(info -> InputFormat)) {
 
         cmsFloat64Number* Pt = (cmsFloat64Number*) accum;
@@ -807,18 +842,18 @@ cmsINLINE cmsBool IsInkSpace(cmsUInt32Number Type)
 {
     switch (T_COLORSPACE(Type)) {
 
-     case PT_CMY:       
-     case PT_CMYK:      
-     case PT_MCH5:      
+     case PT_CMY:
+     case PT_CMYK:
+     case PT_MCH5:
      case PT_MCH6:
-     case PT_MCH7:     
-     case PT_MCH8:     
-     case PT_MCH9:     
-     case PT_MCH10:    
-     case PT_MCH11:    
-     case PT_MCH12:    
-     case PT_MCH13:    
-     case PT_MCH14:    
+     case PT_MCH7:
+     case PT_MCH8:
+     case PT_MCH9:
+     case PT_MCH10:
+     case PT_MCH11:
+     case PT_MCH12:
+     case PT_MCH13:
+     case PT_MCH14:
      case PT_MCH15: return TRUE;
 
      default: return FALSE;
@@ -827,70 +862,122 @@ cmsINLINE cmsBool IsInkSpace(cmsUInt32Number Type)
 
 // Inks does come in percentage, remaining cases are between 0..1.0, again to 16 bits
 static
-cmsUInt8Number* UnrollDoubleTo16(register _cmsTRANSFORM* info, 
-                                 register cmsUInt16Number wIn[], 
-                                 register cmsUInt8Number* accum,
-                                 register cmsUInt32Number Stride)
+cmsUInt8Number* UnrollDoubleTo16(register _cmsTRANSFORM* info,
+                                register cmsUInt16Number wIn[],
+                                register cmsUInt8Number* accum,
+                                register cmsUInt32Number Stride)
 {
-    cmsFloat64Number* Inks = (cmsFloat64Number*) accum;
-    int nChan  = T_CHANNELS(info -> InputFormat);
-    int Planar = T_PLANAR(info -> InputFormat);
-    int i;
+
+    int nChan      = T_CHANNELS(info -> InputFormat);
+    int DoSwap     = T_DOSWAP(info ->InputFormat);
+    int Reverse    = T_FLAVOR(info ->InputFormat);
+    int SwapFirst  = T_SWAPFIRST(info -> InputFormat);
+    int Extra      = T_EXTRA(info -> InputFormat);
+    int ExtraFirst = DoSwap ^ SwapFirst;
+    int Planar     = T_PLANAR(info -> InputFormat);
     cmsFloat64Number v;
-    cmsFloat64Number maximum = IsInkSpace(info ->InputFormat) ? 655.35 : 65535.0;
+    cmsUInt16Number  vi;
+    int i, start = 0;
+   cmsFloat64Number maximum = IsInkSpace(info ->InputFormat) ? 655.35 : 65535.0;
+
+
+    if (ExtraFirst)
+            start = Extra;
 
     for (i=0; i < nChan; i++) {
 
-        if (Planar)
+        int index = DoSwap ? (nChan - i - 1) : i;
 
-            v = Inks[i * Stride];
+        if (Planar)
+            v = (cmsFloat32Number) ((cmsFloat64Number*) accum)[(i + start) * Stride];
         else
-            v = Inks[i];
+            v = (cmsFloat32Number) ((cmsFloat64Number*) accum)[i + start];
+
+        vi = _cmsQuickSaturateWord(v * maximum);
+
+        if (Reverse)
+            vi = REVERSE_FLAVOR_16(vi);
+
+        wIn[index] = vi;
+    }
+
 
-        wIn[i] = _cmsQuickSaturateWord(v * maximum);
+    if (Extra == 0 && SwapFirst) {
+        cmsUInt16Number tmp = wIn[0];
+
+        memmove(&wIn[0], &wIn[1], (nChan-1) * sizeof(cmsUInt16Number));
+        wIn[nChan-1] = tmp;
     }
 
     if (T_PLANAR(info -> InputFormat))
         return accum + sizeof(cmsFloat64Number);
     else
-        return accum + (nChan + T_EXTRA(info ->InputFormat)) * sizeof(cmsFloat64Number);
+        return accum + (nChan + Extra) * sizeof(cmsFloat64Number);
 }
 
+
+
 static
-cmsUInt8Number* UnrollFloatTo16(register _cmsTRANSFORM* info, 
-                                register cmsUInt16Number wIn[], 
+cmsUInt8Number* UnrollFloatTo16(register _cmsTRANSFORM* info,
+                                register cmsUInt16Number wIn[],
                                 register cmsUInt8Number* accum,
                                 register cmsUInt32Number Stride)
 {
-    cmsFloat32Number* Inks = (cmsFloat32Number*) accum;
-    int nChan  = T_CHANNELS(info -> InputFormat);
-    int Planar = T_PLANAR(info -> InputFormat);
-    int i;
+
+    int nChan      = T_CHANNELS(info -> InputFormat);
+    int DoSwap     = T_DOSWAP(info ->InputFormat);
+    int Reverse    = T_FLAVOR(info ->InputFormat);
+    int SwapFirst  = T_SWAPFIRST(info -> InputFormat);
+    int Extra      = T_EXTRA(info -> InputFormat);
+    int ExtraFirst = DoSwap ^ SwapFirst;
+    int Planar     = T_PLANAR(info -> InputFormat);
     cmsFloat32Number v;
-    cmsFloat64Number maximum = IsInkSpace(info ->InputFormat) ? 655.35 : 65535.0;
+    cmsUInt16Number  vi;
+    int i, start = 0;
+   cmsFloat64Number maximum = IsInkSpace(info ->InputFormat) ? 655.35 : 65535.0;
+
+
+    if (ExtraFirst)
+            start = Extra;
 
     for (i=0; i < nChan; i++) {
 
-        if (Planar)
+        int index = DoSwap ? (nChan - i - 1) : i;
 
-            v = Inks[i * Stride];
+        if (Planar)
+            v = (cmsFloat32Number) ((cmsFloat32Number*) accum)[(i + start) * Stride];
         else
-            v = Inks[i];
+            v = (cmsFloat32Number) ((cmsFloat32Number*) accum)[i + start];
+
+        vi = _cmsQuickSaturateWord(v * maximum);
+
+        if (Reverse)
+            vi = REVERSE_FLAVOR_16(vi);
+
+        wIn[index] = vi;
+    }
 
-        wIn[i] = _cmsQuickSaturateWord(v * maximum);
+
+    if (Extra == 0 && SwapFirst) {
+        cmsUInt16Number tmp = wIn[0];
+
+        memmove(&wIn[0], &wIn[1], (nChan-1) * sizeof(cmsUInt16Number));
+        wIn[nChan-1] = tmp;
     }
 
     if (T_PLANAR(info -> InputFormat))
         return accum + sizeof(cmsFloat32Number);
     else
-        return accum + (nChan + T_EXTRA(info ->InputFormat)) * sizeof(cmsFloat32Number);
+        return accum + (nChan + Extra) * sizeof(cmsFloat32Number);
 }
 
 
+
+
 // For 1 channel, we need to duplicate data (it comes in 0..1.0 range)
 static
-cmsUInt8Number* UnrollDouble1Chan(register _cmsTRANSFORM* info, 
-                                  register cmsUInt16Number wIn[], 
+cmsUInt8Number* UnrollDouble1Chan(register _cmsTRANSFORM* info,
+                                  register cmsUInt16Number wIn[],
                                   register cmsUInt8Number* accum,
                                   register cmsUInt32Number Stride)
 {
@@ -898,7 +985,7 @@ cmsUInt8Number* UnrollDouble1Chan(register _cmsTRANSFORM* info,
 
     wIn[0] = wIn[1] = wIn[2] = _cmsQuickSaturateWord(Inks[0] * 65535.0);
 
-    return accum + sizeof(cmsFloat64Number);    
+    return accum + sizeof(cmsFloat64Number);
 
     cmsUNUSED_PARAMETER(info);
     cmsUNUSED_PARAMETER(Stride);
@@ -906,76 +993,123 @@ cmsUInt8Number* UnrollDouble1Chan(register _cmsTRANSFORM* info,
 
 //-------------------------------------------------------------------------------------------------------------------
 
-// True float transformation. 
-
-// For anything going from cmsFloat32Number 
+// For anything going from cmsFloat32Number
 static
-cmsUInt8Number* UnrollFloatsToFloat(_cmsTRANSFORM* info, 
-                                    cmsFloat32Number wIn[], 
+cmsUInt8Number* UnrollFloatsToFloat(_cmsTRANSFORM* info,
+                                    cmsFloat32Number wIn[],
                                     cmsUInt8Number* accum,
                                     cmsUInt32Number Stride)
 {
-    cmsFloat32Number* Inks = (cmsFloat32Number*) accum;
-    int nChan  = T_CHANNELS(info -> InputFormat);
-    int Planar = T_PLANAR(info -> InputFormat);
-    int i;
-    cmsFloat64Number maximum = IsInkSpace(info ->InputFormat) ? 100.0 : 1.0;
 
+    int nChan      = T_CHANNELS(info -> InputFormat);
+    int DoSwap     = T_DOSWAP(info ->InputFormat);
+    int Reverse    = T_FLAVOR(info ->InputFormat);
+    int SwapFirst  = T_SWAPFIRST(info -> InputFormat);
+    int Extra      = T_EXTRA(info -> InputFormat);
+    int ExtraFirst = DoSwap ^ SwapFirst;
+    int Planar     = T_PLANAR(info -> InputFormat);
+    cmsFloat32Number v;
+    int i, start = 0;
+    cmsFloat32Number maximum = IsInkSpace(info ->InputFormat) ? 100.0F : 1.0F;
+
+
+    if (ExtraFirst)
+            start = Extra;
+
+    for (i=0; i < nChan; i++) {
 
-    for (i=0; i <  nChan; i++) {
+        int index = DoSwap ? (nChan - i - 1) : i;
 
         if (Planar)
-            wIn[i] = (cmsFloat32Number) (Inks[i * Stride] / maximum);
+            v = (cmsFloat32Number) ((cmsFloat32Number*) accum)[(i + start) * Stride];
         else
-            wIn[i] = (cmsFloat32Number) (Inks[i] / maximum);                            
+            v = (cmsFloat32Number) ((cmsFloat32Number*) accum)[i + start];
+
+        v /= maximum;
+
+        wIn[index] = Reverse ? 1 - v : v;
+    }
+
+
+    if (Extra == 0 && SwapFirst) {
+        cmsFloat32Number tmp = wIn[0];
+
+        memmove(&wIn[0], &wIn[1], (nChan-1) * sizeof(cmsFloat32Number));
+        wIn[nChan-1] = tmp;
     }
 
     if (T_PLANAR(info -> InputFormat))
         return accum + sizeof(cmsFloat32Number);
     else
-        return accum + (nChan + T_EXTRA(info ->InputFormat)) * sizeof(cmsFloat32Number);
+        return accum + (nChan + Extra) * sizeof(cmsFloat32Number);
 }
 
 // For anything going from double
+
 static
-cmsUInt8Number* UnrollDoublesToFloat(_cmsTRANSFORM* info, 
-                                     cmsFloat32Number wIn[], 
-                                     cmsUInt8Number* accum,
-                                     cmsUInt32Number Stride)
+cmsUInt8Number* UnrollDoublesToFloat(_cmsTRANSFORM* info,
+                                    cmsFloat32Number wIn[],
+                                    cmsUInt8Number* accum,
+                                    cmsUInt32Number Stride)
 {
-    cmsFloat64Number* Inks = (cmsFloat64Number*) accum;
-    int nChan  = T_CHANNELS(info -> InputFormat);
-    int Planar = T_PLANAR(info -> InputFormat);
-    int i;
+
+    int nChan      = T_CHANNELS(info -> InputFormat);
+    int DoSwap     = T_DOSWAP(info ->InputFormat);
+    int Reverse    = T_FLAVOR(info ->InputFormat);
+    int SwapFirst  = T_SWAPFIRST(info -> InputFormat);
+    int Extra      = T_EXTRA(info -> InputFormat);
+    int ExtraFirst = DoSwap ^ SwapFirst;
+    int Planar     = T_PLANAR(info -> InputFormat);
+    cmsFloat64Number v;
+    int i, start = 0;
     cmsFloat64Number maximum = IsInkSpace(info ->InputFormat) ? 100.0 : 1.0;
 
-    for (i=0; i <  nChan; i++) {
+
+    if (ExtraFirst)
+            start = Extra;
+
+    for (i=0; i < nChan; i++) {
+
+        int index = DoSwap ? (nChan - i - 1) : i;
 
         if (Planar)
-            wIn[i] = (cmsFloat32Number) (Inks[i * Stride] / maximum);
+            v = (cmsFloat64Number) ((cmsFloat64Number*) accum)[(i + start)  * Stride];
         else
-            wIn[i] = (cmsFloat32Number) (Inks[i] / maximum);                            
+            v = (cmsFloat64Number) ((cmsFloat64Number*) accum)[i + start];
+
+        v /= maximum;
+
+        wIn[index] = (cmsFloat32Number) (Reverse ? 1.0 - v : v);
+    }
+
+
+    if (Extra == 0 && SwapFirst) {
+        cmsFloat32Number tmp = wIn[0];
+
+        memmove(&wIn[0], &wIn[1], (nChan-1) * sizeof(cmsFloat32Number));
+        wIn[nChan-1] = tmp;
     }
 
     if (T_PLANAR(info -> InputFormat))
         return accum + sizeof(cmsFloat64Number);
     else
-        return accum + (nChan + T_EXTRA(info ->InputFormat)) * sizeof(cmsFloat64Number);
+        return accum + (nChan + Extra) * sizeof(cmsFloat64Number);
 }
 
 
+
 // From Lab double to cmsFloat32Number
 static
-cmsUInt8Number* UnrollLabDoubleToFloat(_cmsTRANSFORM* info,  
-                                       cmsFloat32Number wIn[], 
+cmsUInt8Number* UnrollLabDoubleToFloat(_cmsTRANSFORM* info,
+                                       cmsFloat32Number wIn[],
                                        cmsUInt8Number* accum,
                                        cmsUInt32Number Stride)
-{  
+{
     cmsFloat64Number* Pt = (cmsFloat64Number*) accum;
 
     if (T_PLANAR(info -> InputFormat)) {
 
-        wIn[0] = (cmsFloat32Number) (Pt[0] / 100.0);                            // from 0..100 to 0..1 
+        wIn[0] = (cmsFloat32Number) (Pt[0] / 100.0);                            // from 0..100 to 0..1
         wIn[1] = (cmsFloat32Number) ((Pt[Stride] + 128) / 255.0);    // form -128..+127 to 0..1
         wIn[2] = (cmsFloat32Number) ((Pt[Stride*2] + 128) / 255.0);
 
@@ -983,7 +1117,7 @@ cmsUInt8Number* UnrollLabDoubleToFloat(_cmsTRANSFORM* info,
     }
     else {
 
-        wIn[0] = (cmsFloat32Number) (Pt[0] / 100.0);            // from 0..100 to 0..1 
+        wIn[0] = (cmsFloat32Number) (Pt[0] / 100.0);            // from 0..100 to 0..1
         wIn[1] = (cmsFloat32Number) ((Pt[1] + 128) / 255.0);    // form -128..+127 to 0..1
         wIn[2] = (cmsFloat32Number) ((Pt[2] + 128) / 255.0);
 
@@ -994,16 +1128,16 @@ cmsUInt8Number* UnrollLabDoubleToFloat(_cmsTRANSFORM* info,
 
 // From Lab double to cmsFloat32Number
 static
-cmsUInt8Number* UnrollLabFloatToFloat(_cmsTRANSFORM* info, 
-                                      cmsFloat32Number wIn[], 
+cmsUInt8Number* UnrollLabFloatToFloat(_cmsTRANSFORM* info,
+                                      cmsFloat32Number wIn[],
                                       cmsUInt8Number* accum,
                                       cmsUInt32Number Stride)
-{  
+{
     cmsFloat32Number* Pt = (cmsFloat32Number*) accum;
 
     if (T_PLANAR(info -> InputFormat)) {
 
-        wIn[0] = (cmsFloat32Number) (Pt[0] / 100.0);                 // from 0..100 to 0..1 
+        wIn[0] = (cmsFloat32Number) (Pt[0] / 100.0);                 // from 0..100 to 0..1
         wIn[1] = (cmsFloat32Number) ((Pt[Stride] + 128) / 255.0);    // form -128..+127 to 0..1
         wIn[2] = (cmsFloat32Number) ((Pt[Stride*2] + 128) / 255.0);
 
@@ -1011,7 +1145,7 @@ cmsUInt8Number* UnrollLabFloatToFloat(_cmsTRANSFORM* info,
     }
     else {
 
-        wIn[0] = (cmsFloat32Number) (Pt[0] / 100.0);            // from 0..100 to 0..1 
+        wIn[0] = (cmsFloat32Number) (Pt[0] / 100.0);            // from 0..100 to 0..1
         wIn[1] = (cmsFloat32Number) ((Pt[1] + 128) / 255.0);    // form -128..+127 to 0..1
         wIn[2] = (cmsFloat32Number) ((Pt[2] + 128) / 255.0);
 
@@ -1021,27 +1155,28 @@ cmsUInt8Number* UnrollLabFloatToFloat(_cmsTRANSFORM* info,
 }
 
 
+
 // 1.15 fixed point, that means maximum value is MAX_ENCODEABLE_XYZ (0xFFFF)
 static
-cmsUInt8Number* UnrollXYZDoubleToFloat(_cmsTRANSFORM* info,  
-                                       cmsFloat32Number wIn[], 
+cmsUInt8Number* UnrollXYZDoubleToFloat(_cmsTRANSFORM* info,
+                                       cmsFloat32Number wIn[],
                                        cmsUInt8Number* accum,
                                        cmsUInt32Number Stride)
-{  
+{
     cmsFloat64Number* Pt = (cmsFloat64Number*) accum;
 
     if (T_PLANAR(info -> InputFormat)) {
 
-        wIn[0] = (cmsFloat32Number) (Pt[0] / MAX_ENCODEABLE_XYZ);                   
-        wIn[1] = (cmsFloat32Number) (Pt[Stride] / MAX_ENCODEABLE_XYZ);    
+        wIn[0] = (cmsFloat32Number) (Pt[0] / MAX_ENCODEABLE_XYZ);
+        wIn[1] = (cmsFloat32Number) (Pt[Stride] / MAX_ENCODEABLE_XYZ);
         wIn[2] = (cmsFloat32Number) (Pt[Stride*2] / MAX_ENCODEABLE_XYZ);
 
         return accum + sizeof(cmsFloat64Number);
     }
     else {
 
-        wIn[0] = (cmsFloat32Number) (Pt[0] / MAX_ENCODEABLE_XYZ);            
-        wIn[1] = (cmsFloat32Number) (Pt[1] / MAX_ENCODEABLE_XYZ);    
+        wIn[0] = (cmsFloat32Number) (Pt[0] / MAX_ENCODEABLE_XYZ);
+        wIn[1] = (cmsFloat32Number) (Pt[1] / MAX_ENCODEABLE_XYZ);
         wIn[2] = (cmsFloat32Number) (Pt[2] / MAX_ENCODEABLE_XYZ);
 
         accum += sizeof(cmsFloat64Number)*(3 + T_EXTRA(info ->InputFormat));
@@ -1050,25 +1185,25 @@ cmsUInt8Number* UnrollXYZDoubleToFloat(_cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* UnrollXYZFloatToFloat(_cmsTRANSFORM* info,  
-                                      cmsFloat32Number wIn[], 
+cmsUInt8Number* UnrollXYZFloatToFloat(_cmsTRANSFORM* info,
+                                      cmsFloat32Number wIn[],
                                       cmsUInt8Number* accum,
                                       cmsUInt32Number Stride)
-{  
+{
     cmsFloat32Number* Pt = (cmsFloat32Number*) accum;
 
     if (T_PLANAR(info -> InputFormat)) {
 
-        wIn[0] = (cmsFloat32Number) (Pt[0] / MAX_ENCODEABLE_XYZ);                   
-        wIn[1] = (cmsFloat32Number) (Pt[Stride] / MAX_ENCODEABLE_XYZ);    
+        wIn[0] = (cmsFloat32Number) (Pt[0] / MAX_ENCODEABLE_XYZ);
+        wIn[1] = (cmsFloat32Number) (Pt[Stride] / MAX_ENCODEABLE_XYZ);
         wIn[2] = (cmsFloat32Number) (Pt[Stride*2] / MAX_ENCODEABLE_XYZ);
 
         return accum + sizeof(cmsFloat32Number);
     }
     else {
 
-        wIn[0] = (cmsFloat32Number) (Pt[0] / MAX_ENCODEABLE_XYZ);            
-        wIn[1] = (cmsFloat32Number) (Pt[1] / MAX_ENCODEABLE_XYZ);    
+        wIn[0] = (cmsFloat32Number) (Pt[0] / MAX_ENCODEABLE_XYZ);
+        wIn[1] = (cmsFloat32Number) (Pt[1] / MAX_ENCODEABLE_XYZ);
         wIn[2] = (cmsFloat32Number) (Pt[2] / MAX_ENCODEABLE_XYZ);
 
         accum += sizeof(cmsFloat32Number)*(3 + T_EXTRA(info ->InputFormat));
@@ -1076,14 +1211,16 @@ cmsUInt8Number* UnrollXYZFloatToFloat(_cmsTRANSFORM* info,
     }
 }
 
+
+
 // Packing routines -----------------------------------------------------------------------------------------------------------
 
 
 // Generic chunky for byte
 
 static
-cmsUInt8Number* PackAnyBytes(register _cmsTRANSFORM* info, 
-                             register cmsUInt16Number wOut[], 
+cmsUInt8Number* PackAnyBytes(register _cmsTRANSFORM* info,
+                             register cmsUInt16Number wOut[],
                              register cmsUInt8Number* output,
                              register cmsUInt32Number Stride)
 {
@@ -1092,7 +1229,7 @@ cmsUInt8Number* PackAnyBytes(register _cmsTRANSFORM* info,
     int Reverse    = T_FLAVOR(info ->OutputFormat);
     int Extra      = T_EXTRA(info -> OutputFormat);
     int SwapFirst  = T_SWAPFIRST(info -> OutputFormat);
-    int ExtraFirst = DoSwap && !SwapFirst;
+    int ExtraFirst = DoSwap SwapFirst;
     cmsUInt8Number* swap1;
     cmsUInt8Number v = 0;
     int i;
@@ -1134,8 +1271,8 @@ cmsUInt8Number* PackAnyBytes(register _cmsTRANSFORM* info,
 
 
 static
-cmsUInt8Number* PackAnyWords(register _cmsTRANSFORM* info, 
-                             register cmsUInt16Number wOut[], 
+cmsUInt8Number* PackAnyWords(register _cmsTRANSFORM* info,
+                             register cmsUInt16Number wOut[],
                              register cmsUInt8Number* output,
                              register cmsUInt32Number Stride)
 {
@@ -1145,7 +1282,7 @@ cmsUInt8Number* PackAnyWords(register _cmsTRANSFORM* info,
     int Reverse    = T_FLAVOR(info ->OutputFormat);
     int Extra      = T_EXTRA(info -> OutputFormat);
     int SwapFirst  = T_SWAPFIRST(info -> OutputFormat);
-    int ExtraFirst = DoSwap && !SwapFirst;
+    int ExtraFirst = DoSwap SwapFirst;
     cmsUInt16Number* swap1;
     cmsUInt16Number v = 0;
     int i;
@@ -1191,17 +1328,24 @@ cmsUInt8Number* PackAnyWords(register _cmsTRANSFORM* info,
 
 
 static
-cmsUInt8Number* PackPlanarBytes(register _cmsTRANSFORM* info, 
-                                register cmsUInt16Number wOut[], 
+cmsUInt8Number* PackPlanarBytes(register _cmsTRANSFORM* info,
+                                register cmsUInt16Number wOut[],
                                 register cmsUInt8Number* output,
                                 register cmsUInt32Number Stride)
 {
-    int nChan = T_CHANNELS(info -> OutputFormat);
-    int DoSwap = T_DOSWAP(info ->OutputFormat);
-    int Reverse= T_FLAVOR(info ->OutputFormat);
+    int nChan     = T_CHANNELS(info -> OutputFormat);
+    int DoSwap    = T_DOSWAP(info ->OutputFormat);
+    int SwapFirst = T_SWAPFIRST(info ->OutputFormat);
+    int Reverse   = T_FLAVOR(info ->OutputFormat);
     int i;
     cmsUInt8Number* Init = output;
 
+
+    if (DoSwap ^ SwapFirst) {
+        output += T_EXTRA(info -> OutputFormat) * Stride;
+    }
+
+
     for (i=0; i < nChan; i++) {
 
         int index = DoSwap ? (nChan - i - 1) : i;
@@ -1218,8 +1362,8 @@ cmsUInt8Number* PackPlanarBytes(register _cmsTRANSFORM* info,
 
 
 static
-cmsUInt8Number* PackPlanarWords(register _cmsTRANSFORM* info, 
-                                register cmsUInt16Number wOut[], 
+cmsUInt8Number* PackPlanarWords(register _cmsTRANSFORM* info,
+                                register cmsUInt16Number wOut[],
                                 register cmsUInt8Number* output,
                                 register cmsUInt32Number Stride)
 {
@@ -1244,7 +1388,7 @@ cmsUInt8Number* PackPlanarWords(register _cmsTRANSFORM* info,
         if (SwapEndian)
             v = CHANGE_ENDIAN(v);
 
-        if (Reverse) 
+        if (Reverse)
             v =  REVERSE_FLAVOR_16(v);
 
         *(cmsUInt16Number*) output = v;
@@ -1257,8 +1401,8 @@ cmsUInt8Number* PackPlanarWords(register _cmsTRANSFORM* info,
 // CMYKcm (unrolled for speed)
 
 static
-cmsUInt8Number* Pack6Bytes(register _cmsTRANSFORM* info, 
-                           register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack6Bytes(register _cmsTRANSFORM* info,
+                           register cmsUInt16Number wOut[],
                            register cmsUInt8Number* output,
                            register cmsUInt32Number Stride)
 {
@@ -1278,8 +1422,8 @@ cmsUInt8Number* Pack6Bytes(register _cmsTRANSFORM* info,
 // KCMYcm
 
 static
-cmsUInt8Number* Pack6BytesSwap(register _cmsTRANSFORM* info, 
-                               register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack6BytesSwap(register _cmsTRANSFORM* info,
+                               register cmsUInt16Number wOut[],
                                register cmsUInt8Number* output,
                                register cmsUInt32Number Stride)
 {
@@ -1298,8 +1442,8 @@ cmsUInt8Number* Pack6BytesSwap(register _cmsTRANSFORM* info,
 
 // CMYKcm
 static
-cmsUInt8Number* Pack6Words(register _cmsTRANSFORM* info, 
-                           register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack6Words(register _cmsTRANSFORM* info,
+                           register cmsUInt16Number wOut[],
                            register cmsUInt8Number* output,
                            register cmsUInt32Number Stride)
 {
@@ -1324,8 +1468,8 @@ cmsUInt8Number* Pack6Words(register _cmsTRANSFORM* info,
 
 // KCMYcm
 static
-cmsUInt8Number* Pack6WordsSwap(register _cmsTRANSFORM* info, 
-                               register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack6WordsSwap(register _cmsTRANSFORM* info,
+                               register cmsUInt16Number wOut[],
                                register cmsUInt8Number* output,
                                register cmsUInt32Number Stride)
 {
@@ -1350,8 +1494,8 @@ cmsUInt8Number* Pack6WordsSwap(register _cmsTRANSFORM* info,
 
 
 static
-cmsUInt8Number* Pack4Bytes(register _cmsTRANSFORM* info, 
-                           register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack4Bytes(register _cmsTRANSFORM* info,
+                           register cmsUInt16Number wOut[],
                            register cmsUInt8Number* output,
                            register cmsUInt32Number Stride)
 {
@@ -1367,8 +1511,8 @@ cmsUInt8Number* Pack4Bytes(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Pack4BytesReverse(register _cmsTRANSFORM* info, 
-                                  register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack4BytesReverse(register _cmsTRANSFORM* info,
+                                  register cmsUInt16Number wOut[],
                                   register cmsUInt8Number* output,
                                   register cmsUInt32Number Stride)
 {
@@ -1385,8 +1529,8 @@ cmsUInt8Number* Pack4BytesReverse(register _cmsTRANSFORM* info,
 
 
 static
-cmsUInt8Number* Pack4BytesSwapFirst(register _cmsTRANSFORM* info, 
-                                    register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack4BytesSwapFirst(register _cmsTRANSFORM* info,
+                                    register cmsUInt16Number wOut[],
                                     register cmsUInt8Number* output,
                                     register cmsUInt32Number Stride)
 {
@@ -1403,8 +1547,8 @@ cmsUInt8Number* Pack4BytesSwapFirst(register _cmsTRANSFORM* info,
 
 // ABGR
 static
-cmsUInt8Number* Pack4BytesSwap(register _cmsTRANSFORM* info, 
-                               register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack4BytesSwap(register _cmsTRANSFORM* info,
+                               register cmsUInt16Number wOut[],
                                register cmsUInt8Number* output,
                                register cmsUInt32Number Stride)
 {
@@ -1420,8 +1564,8 @@ cmsUInt8Number* Pack4BytesSwap(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Pack4BytesSwapSwapFirst(register _cmsTRANSFORM* info, 
-                                        register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack4BytesSwapSwapFirst(register _cmsTRANSFORM* info,
+                                        register cmsUInt16Number wOut[],
                                         register cmsUInt8Number* output,
                                         register cmsUInt32Number Stride)
 {
@@ -1437,8 +1581,8 @@ cmsUInt8Number* Pack4BytesSwapSwapFirst(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Pack4Words(register _cmsTRANSFORM* info, 
-                           register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack4Words(register _cmsTRANSFORM* info,
+                           register cmsUInt16Number wOut[],
                            register cmsUInt8Number* output,
                            register cmsUInt32Number Stride)
 {
@@ -1458,8 +1602,8 @@ cmsUInt8Number* Pack4Words(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Pack4WordsReverse(register _cmsTRANSFORM* info, 
-                                  register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack4WordsReverse(register _cmsTRANSFORM* info,
+                                  register cmsUInt16Number wOut[],
                                   register cmsUInt8Number* output,
                                   register cmsUInt32Number Stride)
 {
@@ -1480,8 +1624,8 @@ cmsUInt8Number* Pack4WordsReverse(register _cmsTRANSFORM* info,
 
 // ABGR
 static
-cmsUInt8Number* Pack4WordsSwap(register _cmsTRANSFORM* info, 
-                               register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack4WordsSwap(register _cmsTRANSFORM* info,
+                               register cmsUInt16Number wOut[],
                                register cmsUInt8Number* output,
                                register cmsUInt32Number Stride)
 {
@@ -1502,8 +1646,8 @@ cmsUInt8Number* Pack4WordsSwap(register _cmsTRANSFORM* info,
 
 // CMYK
 static
-cmsUInt8Number* Pack4WordsBigEndian(register _cmsTRANSFORM* info, 
-                                    register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack4WordsBigEndian(register _cmsTRANSFORM* info,
+                                    register cmsUInt16Number wOut[],
                                     register cmsUInt8Number* output,
                                     register cmsUInt32Number Stride)
 {
@@ -1524,8 +1668,8 @@ cmsUInt8Number* Pack4WordsBigEndian(register _cmsTRANSFORM* info,
 
 
 static
-cmsUInt8Number* PackLabV2_8(register _cmsTRANSFORM* info, 
-                            register cmsUInt16Number wOut[], 
+cmsUInt8Number* PackLabV2_8(register _cmsTRANSFORM* info,
+                            register cmsUInt16Number wOut[],
                             register cmsUInt8Number* output,
                             register cmsUInt32Number Stride)
 {
@@ -1540,8 +1684,8 @@ cmsUInt8Number* PackLabV2_8(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* PackALabV2_8(register _cmsTRANSFORM* info, 
-                             register cmsUInt16Number wOut[], 
+cmsUInt8Number* PackALabV2_8(register _cmsTRANSFORM* info,
+                             register cmsUInt16Number wOut[],
                              register cmsUInt8Number* output,
                              register cmsUInt32Number Stride)
 {
@@ -1557,8 +1701,8 @@ cmsUInt8Number* PackALabV2_8(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* PackLabV2_16(register _cmsTRANSFORM* info, 
-                             register cmsUInt16Number wOut[], 
+cmsUInt8Number* PackLabV2_16(register _cmsTRANSFORM* info,
+                             register cmsUInt16Number wOut[],
                              register cmsUInt8Number* output,
                              register cmsUInt32Number Stride)
 {
@@ -1576,8 +1720,8 @@ cmsUInt8Number* PackLabV2_16(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Pack3Bytes(register _cmsTRANSFORM* info, 
-                           register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack3Bytes(register _cmsTRANSFORM* info,
+                           register cmsUInt16Number wOut[],
                            register cmsUInt8Number* output,
                            register cmsUInt32Number Stride)
 {
@@ -1592,8 +1736,8 @@ cmsUInt8Number* Pack3Bytes(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Pack3BytesOptimized(register _cmsTRANSFORM* info, 
-                                    register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack3BytesOptimized(register _cmsTRANSFORM* info,
+                                    register cmsUInt16Number wOut[],
                                     register cmsUInt8Number* output,
                                     register cmsUInt32Number Stride)
 {
@@ -1608,8 +1752,8 @@ cmsUInt8Number* Pack3BytesOptimized(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Pack3BytesSwap(register _cmsTRANSFORM* info, 
-                               register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack3BytesSwap(register _cmsTRANSFORM* info,
+                               register cmsUInt16Number wOut[],
                                register cmsUInt8Number* output,
                                register cmsUInt32Number Stride)
 {
@@ -1624,8 +1768,8 @@ cmsUInt8Number* Pack3BytesSwap(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Pack3BytesSwapOptimized(register _cmsTRANSFORM* info, 
-                                        register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack3BytesSwapOptimized(register _cmsTRANSFORM* info,
+                                        register cmsUInt16Number wOut[],
                                         register cmsUInt8Number* output,
                                         register cmsUInt32Number Stride)
 {
@@ -1641,8 +1785,8 @@ cmsUInt8Number* Pack3BytesSwapOptimized(register _cmsTRANSFORM* info,
 
 
 static
-cmsUInt8Number* Pack3Words(register _cmsTRANSFORM* info, 
-                           register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack3Words(register _cmsTRANSFORM* info,
+                           register cmsUInt16Number wOut[],
                            register cmsUInt8Number* output,
                            register cmsUInt32Number Stride)
 {
@@ -1660,8 +1804,8 @@ cmsUInt8Number* Pack3Words(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Pack3WordsSwap(register _cmsTRANSFORM* info, 
-                               register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack3WordsSwap(register _cmsTRANSFORM* info,
+                               register cmsUInt16Number wOut[],
                                register cmsUInt8Number* output,
                                register cmsUInt32Number Stride)
 {
@@ -1679,8 +1823,8 @@ cmsUInt8Number* Pack3WordsSwap(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Pack3WordsBigEndian(register _cmsTRANSFORM* info, 
-                                    register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack3WordsBigEndian(register _cmsTRANSFORM* info,
+                                    register cmsUInt16Number wOut[],
                                     register cmsUInt8Number* output,
                                     register cmsUInt32Number Stride)
 {
@@ -1698,8 +1842,8 @@ cmsUInt8Number* Pack3WordsBigEndian(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Pack3BytesAndSkip1(register _cmsTRANSFORM* info, 
-                                   register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack3BytesAndSkip1(register _cmsTRANSFORM* info,
+                                   register cmsUInt16Number wOut[],
                                    register cmsUInt8Number* output,
                                    register cmsUInt32Number Stride)
 {
@@ -1715,8 +1859,8 @@ cmsUInt8Number* Pack3BytesAndSkip1(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Pack3BytesAndSkip1Optimized(register _cmsTRANSFORM* info, 
-                                            register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack3BytesAndSkip1Optimized(register _cmsTRANSFORM* info,
+                                            register cmsUInt16Number wOut[],
                                             register cmsUInt8Number* output,
                                             register cmsUInt32Number Stride)
 {
@@ -1733,8 +1877,8 @@ cmsUInt8Number* Pack3BytesAndSkip1Optimized(register _cmsTRANSFORM* info,
 
 
 static
-cmsUInt8Number* Pack3BytesAndSkip1SwapFirst(register _cmsTRANSFORM* info, 
-                                            register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack3BytesAndSkip1SwapFirst(register _cmsTRANSFORM* info,
+                                            register cmsUInt16Number wOut[],
                                             register cmsUInt8Number* output,
                                             register cmsUInt32Number Stride)
 {
@@ -1750,8 +1894,8 @@ cmsUInt8Number* Pack3BytesAndSkip1SwapFirst(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Pack3BytesAndSkip1SwapFirstOptimized(register _cmsTRANSFORM* info, 
-                                                     register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack3BytesAndSkip1SwapFirstOptimized(register _cmsTRANSFORM* info,
+                                                     register cmsUInt16Number wOut[],
                                                      register cmsUInt8Number* output,
                                                      register cmsUInt32Number Stride)
 {
@@ -1767,8 +1911,8 @@ cmsUInt8Number* Pack3BytesAndSkip1SwapFirstOptimized(register _cmsTRANSFORM* inf
 }
 
 static
-cmsUInt8Number* Pack3BytesAndSkip1Swap(register _cmsTRANSFORM* info, 
-                                       register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack3BytesAndSkip1Swap(register _cmsTRANSFORM* info,
+                                       register cmsUInt16Number wOut[],
                                        register cmsUInt8Number* output,
                                        register cmsUInt32Number Stride)
 {
@@ -1784,8 +1928,8 @@ cmsUInt8Number* Pack3BytesAndSkip1Swap(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Pack3BytesAndSkip1SwapOptimized(register _cmsTRANSFORM* info, 
-                                                register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack3BytesAndSkip1SwapOptimized(register _cmsTRANSFORM* info,
+                                                register cmsUInt16Number wOut[],
                                                 register cmsUInt8Number* output,
                                                 register cmsUInt32Number Stride)
 {
@@ -1802,11 +1946,11 @@ cmsUInt8Number* Pack3BytesAndSkip1SwapOptimized(register _cmsTRANSFORM* info,
 
 
 static
-cmsUInt8Number* Pack3BytesAndSkip1SwapSwapFirst(register _cmsTRANSFORM* info, 
-                                                register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack3BytesAndSkip1SwapSwapFirst(register _cmsTRANSFORM* info,
+                                                register cmsUInt16Number wOut[],
                                                 register cmsUInt8Number* output,
                                                 register cmsUInt32Number Stride)
-{       
+{
     *output++ = FROM_16_TO_8(wOut[2]);
     *output++ = FROM_16_TO_8(wOut[1]);
     *output++ = FROM_16_TO_8(wOut[0]);
@@ -1819,11 +1963,11 @@ cmsUInt8Number* Pack3BytesAndSkip1SwapSwapFirst(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Pack3BytesAndSkip1SwapSwapFirstOptimized(register _cmsTRANSFORM* info, 
-                                                         register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack3BytesAndSkip1SwapSwapFirstOptimized(register _cmsTRANSFORM* info,
+                                                         register cmsUInt16Number wOut[],
                                                          register cmsUInt8Number* output,
                                                          register cmsUInt32Number Stride)
-{       
+{
     *output++ = (wOut[2] & 0xFF);
     *output++ = (wOut[1] & 0xFF);
     *output++ = (wOut[0] & 0xFF);
@@ -1836,8 +1980,8 @@ cmsUInt8Number* Pack3BytesAndSkip1SwapSwapFirstOptimized(register _cmsTRANSFORM*
 }
 
 static
-cmsUInt8Number* Pack3WordsAndSkip1(register _cmsTRANSFORM* info, 
-                                   register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack3WordsAndSkip1(register _cmsTRANSFORM* info,
+                                   register cmsUInt16Number wOut[],
                                    register cmsUInt8Number* output,
                                    register cmsUInt32Number Stride)
 {
@@ -1856,8 +2000,8 @@ cmsUInt8Number* Pack3WordsAndSkip1(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Pack3WordsAndSkip1Swap(register _cmsTRANSFORM* info, 
-                                       register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack3WordsAndSkip1Swap(register _cmsTRANSFORM* info,
+                                       register cmsUInt16Number wOut[],
                                        register cmsUInt8Number* output,
                                        register cmsUInt32Number Stride)
 {
@@ -1877,11 +2021,11 @@ cmsUInt8Number* Pack3WordsAndSkip1Swap(register _cmsTRANSFORM* info,
 
 
 static
-cmsUInt8Number* Pack3WordsAndSkip1SwapFirst(register _cmsTRANSFORM* info, 
-                                            register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack3WordsAndSkip1SwapFirst(register _cmsTRANSFORM* info,
+                                            register cmsUInt16Number wOut[],
                                             register cmsUInt8Number* output,
                                             register cmsUInt32Number Stride)
-{   
+{
     output+= 2;
     *(cmsUInt16Number*) output = wOut[0];
     output+= 2;
@@ -1898,11 +2042,11 @@ cmsUInt8Number* Pack3WordsAndSkip1SwapFirst(register _cmsTRANSFORM* info,
 
 
 static
-cmsUInt8Number* Pack3WordsAndSkip1SwapSwapFirst(register _cmsTRANSFORM* info, 
-                                                register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack3WordsAndSkip1SwapSwapFirst(register _cmsTRANSFORM* info,
+                                                register cmsUInt16Number wOut[],
                                                 register cmsUInt8Number* output,
                                                 register cmsUInt32Number Stride)
-{      
+{
     *(cmsUInt16Number*) output = wOut[2];
     output+= 2;
     *(cmsUInt16Number*) output = wOut[1];
@@ -1920,8 +2064,8 @@ cmsUInt8Number* Pack3WordsAndSkip1SwapSwapFirst(register _cmsTRANSFORM* info,
 
 
 static
-cmsUInt8Number* Pack1Byte(register _cmsTRANSFORM* info, 
-                          register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack1Byte(register _cmsTRANSFORM* info,
+                          register cmsUInt16Number wOut[],
                           register cmsUInt8Number* output,
                           register cmsUInt32Number Stride)
 {
@@ -1935,8 +2079,8 @@ cmsUInt8Number* Pack1Byte(register _cmsTRANSFORM* info,
 
 
 static
-cmsUInt8Number* Pack1ByteReversed(register _cmsTRANSFORM* info, 
-                                  register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack1ByteReversed(register _cmsTRANSFORM* info,
+                                  register cmsUInt16Number wOut[],
                                   register cmsUInt8Number* output,
                                   register cmsUInt32Number Stride)
 {
@@ -1950,8 +2094,8 @@ cmsUInt8Number* Pack1ByteReversed(register _cmsTRANSFORM* info,
 
 
 static
-cmsUInt8Number* Pack1ByteSkip1(register _cmsTRANSFORM* info, 
-                               register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack1ByteSkip1(register _cmsTRANSFORM* info,
+                               register cmsUInt16Number wOut[],
                                register cmsUInt8Number* output,
                                register cmsUInt32Number Stride)
 {
@@ -1966,8 +2110,8 @@ cmsUInt8Number* Pack1ByteSkip1(register _cmsTRANSFORM* info,
 
 
 static
-cmsUInt8Number* Pack1ByteSkip1SwapFirst(register _cmsTRANSFORM* info, 
-                                        register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack1ByteSkip1SwapFirst(register _cmsTRANSFORM* info,
+                                        register cmsUInt16Number wOut[],
                                         register cmsUInt8Number* output,
                                         register cmsUInt32Number Stride)
 {
@@ -1981,8 +2125,8 @@ cmsUInt8Number* Pack1ByteSkip1SwapFirst(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Pack1Word(register _cmsTRANSFORM* info, 
-                          register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack1Word(register _cmsTRANSFORM* info,
+                          register cmsUInt16Number wOut[],
                           register cmsUInt8Number* output,
                           register cmsUInt32Number Stride)
 {
@@ -1997,8 +2141,8 @@ cmsUInt8Number* Pack1Word(register _cmsTRANSFORM* info,
 
 
 static
-cmsUInt8Number* Pack1WordReversed(register _cmsTRANSFORM* info, 
-                                  register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack1WordReversed(register _cmsTRANSFORM* info,
+                                  register cmsUInt16Number wOut[],
                                   register cmsUInt8Number* output,
                                   register cmsUInt32Number Stride)
 {
@@ -2012,8 +2156,8 @@ cmsUInt8Number* Pack1WordReversed(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Pack1WordBigEndian(register _cmsTRANSFORM* info, 
-                                   register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack1WordBigEndian(register _cmsTRANSFORM* info,
+                                   register cmsUInt16Number wOut[],
                                    register cmsUInt8Number* output,
                                    register cmsUInt32Number Stride)
 {
@@ -2028,8 +2172,8 @@ cmsUInt8Number* Pack1WordBigEndian(register _cmsTRANSFORM* info,
 
 
 static
-cmsUInt8Number* Pack1WordSkip1(register _cmsTRANSFORM* info, 
-                               register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack1WordSkip1(register _cmsTRANSFORM* info,
+                               register cmsUInt16Number wOut[],
                                register cmsUInt8Number* output,
                                register cmsUInt32Number Stride)
 {
@@ -2043,12 +2187,12 @@ cmsUInt8Number* Pack1WordSkip1(register _cmsTRANSFORM* info,
 }
 
 static
-cmsUInt8Number* Pack1WordSkip1SwapFirst(register _cmsTRANSFORM* info, 
-                                        register cmsUInt16Number wOut[], 
+cmsUInt8Number* Pack1WordSkip1SwapFirst(register _cmsTRANSFORM* info,
+                                        register cmsUInt16Number wOut[],
                                         register cmsUInt8Number* output,
                                         register cmsUInt32Number Stride)
 {
-    output += 2; 
+    output += 2;
     *(cmsUInt16Number*) output = wOut[0];
     output+= 2;
 
@@ -2061,9 +2205,9 @@ cmsUInt8Number* Pack1WordSkip1SwapFirst(register _cmsTRANSFORM* info,
 
 // Unencoded Float values -- don't try optimize speed
 static
-cmsUInt8Number* PackLabDoubleFrom16(register _cmsTRANSFORM* info, 
-                                    register cmsUInt16Number wOut[], 
-                                    register cmsUInt8Number* output, 
+cmsUInt8Number* PackLabDoubleFrom16(register _cmsTRANSFORM* info,
+                                    register cmsUInt16Number wOut[],
+                                    register cmsUInt8Number* output,
                                     register cmsUInt32Number Stride)
 {
 
@@ -2082,177 +2226,197 @@ cmsUInt8Number* PackLabDoubleFrom16(register _cmsTRANSFORM* info,
     else {
 
         cmsLabEncoded2Float((cmsCIELab*) output, wOut);
-        return output + (sizeof(cmsCIELab) + T_EXTRA(info ->OutputFormat) * sizeof(cmsFloat64Number));            
+        return output + (sizeof(cmsCIELab) + T_EXTRA(info ->OutputFormat) * sizeof(cmsFloat64Number));
     }
-
 }
 
+
 static
-cmsUInt8Number* PackXYZDoubleFrom16(register _cmsTRANSFORM* Info, 
-                                    register cmsUInt16Number wOut[], 
+cmsUInt8Number* PackLabFloatFrom16(register _cmsTRANSFORM* info,
+                                    register cmsUInt16Number wOut[],
                                     register cmsUInt8Number* output,
                                     register cmsUInt32Number Stride)
 {
-    if (T_PLANAR(Info -> OutputFormat)) {
-
-        cmsCIEXYZ XYZ;
-        cmsFloat64Number* Out = (cmsFloat64Number*) output;
-        cmsXYZEncoded2Float(&XYZ, wOut);
-
-        Out[0]                  = XYZ.X;
-        Out[Stride]   = XYZ.Y;
-        Out[Stride*2] = XYZ.Z;
+    cmsCIELab  Lab;
+    cmsLabEncoded2Float(&Lab, wOut);
 
-        return output + sizeof(cmsFloat64Number);
+    if (T_PLANAR(info -> OutputFormat)) {
+       
+        cmsFloat32Number* Out = (cmsFloat32Number*) output;
+    
+        Out[0]        = (cmsFloat32Number)Lab.L;
+        Out[Stride]   = (cmsFloat32Number)Lab.a;
+        Out[Stride*2] = (cmsFloat32Number)Lab.b;
 
+        return output + sizeof(cmsFloat32Number);
     }
     else {
 
-        cmsXYZEncoded2Float((cmsCIEXYZ*) output, wOut);
+       ((cmsFloat32Number*) output)[0] = (cmsFloat32Number) Lab.L;
+       ((cmsFloat32Number*) output)[1] = (cmsFloat32Number) Lab.a;
+       ((cmsFloat32Number*) output)[2] = (cmsFloat32Number) Lab.b;
 
-        return output + (sizeof(cmsCIEXYZ) + T_EXTRA(Info ->OutputFormat) * sizeof(cmsFloat64Number));
+        return output + (3 + T_EXTRA(info ->OutputFormat)) * sizeof(cmsFloat32Number);
     }
 }
 
 static
-cmsUInt8Number* PackDoubleFrom16(register _cmsTRANSFORM* Info, 
-                                 register cmsUInt16Number wOut[], 
-                                 register cmsUInt8Number* output,
-                                 register cmsUInt32Number Stride)
+cmsUInt8Number* PackXYZDoubleFrom16(register _cmsTRANSFORM* Info,
+                                    register cmsUInt16Number wOut[],
+                                    register cmsUInt8Number* output,
+                                    register cmsUInt32Number Stride)
 {
-    cmsFloat64Number* Inks = (cmsFloat64Number*) output;
-    int nChan = T_CHANNELS(Info -> OutputFormat);
-    int i;
-    cmsFloat64Number maximum = IsInkSpace(Info ->OutputFormat) ? 655.35 : 65535.0;
-
     if (T_PLANAR(Info -> OutputFormat)) {
 
-        for (i=0; i <  nChan; i++) {
+        cmsCIEXYZ XYZ;
+        cmsFloat64Number* Out = (cmsFloat64Number*) output;
+        cmsXYZEncoded2Float(&XYZ, wOut);
 
-            Inks[i*Stride] = wOut[i] / maximum;
-        }
+        Out[0]        = XYZ.X;
+        Out[Stride]   = XYZ.Y;
+        Out[Stride*2] = XYZ.Z;
 
         return output + sizeof(cmsFloat64Number);
-    } 
-    else {
 
-        for (i=0; i <  nChan; i++) {
-
-            Inks[i] = wOut[i] /  maximum;
-        }
+    }
+    else {
 
+        cmsXYZEncoded2Float((cmsCIEXYZ*) output, wOut);
 
-        return output + (nChan + T_EXTRA(Info ->OutputFormat)) * sizeof(cmsFloat64Number);
+        return output + (sizeof(cmsCIEXYZ) + T_EXTRA(Info ->OutputFormat) * sizeof(cmsFloat64Number));
     }
-
 }
 
 static
-cmsUInt8Number* PackFloatFrom16(register _cmsTRANSFORM* Info, 
-                                register cmsUInt16Number wOut[], 
+cmsUInt8Number* PackDoubleFrom16(register _cmsTRANSFORM* info,
+                                register cmsUInt16Number wOut[],
                                 register cmsUInt8Number* output,
                                 register cmsUInt32Number Stride)
 {
-    cmsFloat32Number* Inks = (cmsFloat32Number*) output;
-    int nChan = T_CHANNELS(Info -> OutputFormat);
-    int i;
-    cmsFloat64Number maximum = IsInkSpace(Info ->OutputFormat) ? 655.35 : 65535.0;
+    int nChan      = T_CHANNELS(info -> OutputFormat);
+    int DoSwap     = T_DOSWAP(info ->OutputFormat);
+    int Reverse    = T_FLAVOR(info ->OutputFormat);
+    int Extra      = T_EXTRA(info -> OutputFormat);
+    int SwapFirst  = T_SWAPFIRST(info -> OutputFormat);
+    int Planar     = T_PLANAR(info -> OutputFormat);
+    int ExtraFirst = DoSwap ^ SwapFirst;
+    cmsFloat64Number maximum = IsInkSpace(info ->OutputFormat) ? 655.35 : 65535.0;
+    cmsFloat64Number v = 0;
+    cmsFloat64Number* swap1 = (cmsFloat64Number*) output;
+    int i, start = 0;
 
-    if (T_PLANAR(Info -> OutputFormat)) {
+    if (ExtraFirst)
+        start = Extra;
 
-        for (i=0; i <  nChan; i++) {
+    for (i=0; i < nChan; i++) {
 
-            Inks[i*Stride] = (cmsFloat32Number) (wOut[i] / maximum);
-        }
+        int index = DoSwap ? (nChan - i - 1) : i;
 
-        return output + sizeof(cmsFloat32Number);
-    } 
-    else {
+        v = (cmsFloat64Number) wOut[index] / maximum;
+
+        if (Reverse)
+            v = maximum - v;
 
-        for (i=0; i <  nChan; i++) {
+        if (Planar)
+            ((cmsFloat64Number*) output)[(i + start)  * Stride]= v;
+        else
+            ((cmsFloat64Number*) output)[i + start] = v;
+    }
 
-            Inks[i] = (cmsFloat32Number) (wOut[i] /  maximum);
-        }
+    if (!ExtraFirst) {
+        output += Extra * sizeof(cmsFloat64Number);
+    }
 
+    if (Extra == 0 && SwapFirst) {
 
-        return output + (nChan + T_EXTRA(Info ->OutputFormat)) * sizeof(cmsFloat32Number);
+         memmove(swap1 + 1, swap1, (nChan-1)* sizeof(cmsFloat64Number));
+        *swap1 = v;
     }
 
-}
+    if (T_PLANAR(info -> OutputFormat))
+        return output + sizeof(cmsFloat64Number);
+    else
+        return output + nChan * sizeof(cmsFloat64Number);
 
+}
 
-// --------------------------------------------------------------------------------------------------------
 
 static
-cmsUInt8Number* PackChunkyFloatsFromFloat(_cmsTRANSFORM* info, 
-                                          cmsFloat32Number wOut[], 
-                                          cmsUInt8Number* output,
-                                          cmsUInt32Number Stride)
+cmsUInt8Number* PackFloatFrom16(register _cmsTRANSFORM* info,
+                                register cmsUInt16Number wOut[],
+                                register cmsUInt8Number* output,
+                                register cmsUInt32Number Stride)
 {
     int nChan      = T_CHANNELS(info -> OutputFormat);
     int DoSwap     = T_DOSWAP(info ->OutputFormat);
     int Reverse    = T_FLAVOR(info ->OutputFormat);
     int Extra      = T_EXTRA(info -> OutputFormat);
     int SwapFirst  = T_SWAPFIRST(info -> OutputFormat);
-    int ExtraFirst = DoSwap && !SwapFirst;
-    cmsFloat64Number maximum = IsInkSpace(info ->OutputFormat) ? 100.0 : 1.0;
-    cmsFloat32Number* swap1;
+    int Planar     = T_PLANAR(info -> OutputFormat);
+    int ExtraFirst = DoSwap ^ SwapFirst;
+    cmsFloat64Number maximum = IsInkSpace(info ->OutputFormat) ? 655.35 : 65535.0;
     cmsFloat64Number v = 0;
-    int i;
-
-    swap1 = (cmsFloat32Number*) output;
+    cmsFloat32Number* swap1 = (cmsFloat32Number*) output;
+    int i, start = 0;
 
-    if (ExtraFirst) {
-        output += Extra * sizeof(cmsFloat32Number);
-    }
+    if (ExtraFirst)
+        start = Extra;
 
     for (i=0; i < nChan; i++) {
 
         int index = DoSwap ? (nChan - i - 1) : i;
 
-        v = wOut[index] * maximum;
+        v = (cmsFloat64Number) wOut[index] / maximum;
 
         if (Reverse)
             v = maximum - v;
 
-        *(cmsFloat32Number*) output = (cmsFloat32Number) v;
-
-        output += sizeof(cmsFloat32Number);
+        if (Planar)
+            ((cmsFloat32Number*) output)[(i + start ) * Stride]= (cmsFloat32Number) v;
+        else
+            ((cmsFloat32Number*) output)[i + start] = (cmsFloat32Number) v;
     }
 
     if (!ExtraFirst) {
         output += Extra * sizeof(cmsFloat32Number);
     }
 
-    if (Extra == 0 && SwapFirst) {
+  if (Extra == 0 && SwapFirst) {
 
-        memmove(swap1 + 1, swap1, (nChan-1)* sizeof(cmsFloat32Number));
+         memmove(swap1 + 1, swap1, (nChan-1)* sizeof(cmsFloat32Number));
         *swap1 = (cmsFloat32Number) v;
     }
 
+    if (T_PLANAR(info -> OutputFormat))
+        return output + sizeof(cmsFloat32Number);
+    else
+        return output + nChan * sizeof(cmsFloat32Number);
+}
 
-    return output;
 
-    cmsUNUSED_PARAMETER(Stride);
-}
+
+// --------------------------------------------------------------------------------------------------------
 
 static
-cmsUInt8Number* PackPlanarFloatsFromFloat(_cmsTRANSFORM* info, 
-                                          cmsFloat32Number wOut[], 
-                                          cmsUInt8Number* output,
-                                          cmsUInt32Number Stride)
+cmsUInt8Number* PackFloatsFromFloat(_cmsTRANSFORM* info,
+                                    cmsFloat32Number wOut[],
+                                    cmsUInt8Number* output,
+                                    cmsUInt32Number Stride)
 {
-    int nChan = T_CHANNELS(info -> OutputFormat);
-    int DoSwap = T_DOSWAP(info ->OutputFormat);
-    int Reverse= T_FLAVOR(info ->OutputFormat);
-    int i;
-    cmsUInt8Number* Init = output;
+    int nChan      = T_CHANNELS(info -> OutputFormat);
+    int DoSwap     = T_DOSWAP(info ->OutputFormat);
+    int Reverse    = T_FLAVOR(info ->OutputFormat);
+    int Extra      = T_EXTRA(info -> OutputFormat);
+    int SwapFirst  = T_SWAPFIRST(info -> OutputFormat);
+    int Planar     = T_PLANAR(info -> OutputFormat);
+    int ExtraFirst = DoSwap ^ SwapFirst;
     cmsFloat64Number maximum = IsInkSpace(info ->OutputFormat) ? 100.0 : 1.0;
-    cmsFloat64Number v;
+    cmsFloat32Number* swap1 = (cmsFloat32Number*) output;
+    cmsFloat64Number v = 0;
+    int i, start = 0;
 
-    if (DoSwap) {
-        output += T_EXTRA(info -> OutputFormat) * Stride * sizeof(cmsFloat32Number);
-    }
+    if (ExtraFirst)
+        start = Extra;
 
     for (i=0; i < nChan; i++) {
 
@@ -2260,114 +2424,95 @@ cmsUInt8Number* PackPlanarFloatsFromFloat(_cmsTRANSFORM* info,
 
         v = wOut[index] * maximum;
 
-        if (Reverse) 
-            v =  maximum - v;
+        if (Reverse)
+            v = maximum - v;
+
+        if (Planar)
+            ((cmsFloat32Number*) output)[(i + start)* Stride]= (cmsFloat32Number) v;
+        else
+            ((cmsFloat32Number*) output)[i + start] = (cmsFloat32Number) v;
+    }
 
-        *(cmsFloat32Number*) output = (cmsFloat32Number) v;
-        output += (Stride * sizeof(cmsFloat32Number));
+    if (!ExtraFirst) {
+        output += Extra * sizeof(cmsFloat32Number);
     }
 
-    return (Init + sizeof(cmsFloat32Number));
+   if (Extra == 0 && SwapFirst) {
 
-}
+         memmove(swap1 + 1, swap1, (nChan-1)* sizeof(cmsFloat32Number));
+        *swap1 = (cmsFloat32Number) v;
+    }
 
+    if (T_PLANAR(info -> OutputFormat))
+        return output + sizeof(cmsFloat32Number);
+    else
+        return output + nChan * sizeof(cmsFloat32Number);
+}
 
 static
-cmsUInt8Number* PackChunkyDoublesFromFloat(_cmsTRANSFORM* info, 
-                                           cmsFloat32Number wOut[], 
-                                           cmsUInt8Number* output,
-                                           cmsUInt32Number Stride)
+cmsUInt8Number* PackDoublesFromFloat(_cmsTRANSFORM* info,
+                                    cmsFloat32Number wOut[],
+                                    cmsUInt8Number* output,
+                                    cmsUInt32Number Stride)
 {
     int nChan      = T_CHANNELS(info -> OutputFormat);
     int DoSwap     = T_DOSWAP(info ->OutputFormat);
     int Reverse    = T_FLAVOR(info ->OutputFormat);
     int Extra      = T_EXTRA(info -> OutputFormat);
     int SwapFirst  = T_SWAPFIRST(info -> OutputFormat);
-    int ExtraFirst = DoSwap && !SwapFirst;
-    cmsFloat64Number* swap1;
+    int Planar     = T_PLANAR(info -> OutputFormat);
+    int ExtraFirst = DoSwap ^ SwapFirst;
     cmsFloat64Number maximum = IsInkSpace(info ->OutputFormat) ? 100.0 : 1.0;
     cmsFloat64Number v = 0;
-    int i;
+    cmsFloat64Number* swap1 = (cmsFloat64Number*) output;
+    int i, start = 0;
 
-    swap1 = (cmsFloat64Number*) output;
-
-    if (ExtraFirst) {
-        output += Extra * sizeof(cmsFloat64Number);
-    }
+    if (ExtraFirst)
+        start = Extra;
 
     for (i=0; i < nChan; i++) {
 
         int index = DoSwap ? (nChan - i - 1) : i;
 
-        v = (cmsFloat64Number) wOut[index] * maximum;
+        v = wOut[index] * maximum;
 
         if (Reverse)
             v = maximum - v;
 
-        *(cmsFloat64Number*) output = v;
-
-        output += sizeof(cmsFloat64Number);
+        if (Planar)
+            ((cmsFloat64Number*) output)[(i + start) * Stride] =  v;
+        else
+            ((cmsFloat64Number*) output)[i + start] =  v;
     }
 
     if (!ExtraFirst) {
         output += Extra * sizeof(cmsFloat64Number);
     }
 
-    if (Extra == 0 && SwapFirst) {
+   if (Extra == 0 && SwapFirst) {
 
-        memmove(swap1 + 1, swap1, (nChan-1)* sizeof(cmsFloat64Number));
+         memmove(swap1 + 1, swap1, (nChan-1)* sizeof(cmsFloat64Number));
         *swap1 = v;
     }
 
 
-    return output;
+    if (T_PLANAR(info -> OutputFormat))
+        return output + sizeof(cmsFloat64Number);
+    else
+        return output + nChan * sizeof(cmsFloat64Number);
 
-    cmsUNUSED_PARAMETER(Stride);
 }
 
-static
-cmsUInt8Number* PackPlanarDoublesFromFloat(_cmsTRANSFORM* info, 
-                                           cmsFloat32Number wOut[], 
-                                           cmsUInt8Number* output,
-                                           cmsUInt32Number Stride)
-{
-    int nChan = T_CHANNELS(info -> OutputFormat);
-    int DoSwap = T_DOSWAP(info ->OutputFormat);
-    int Reverse= T_FLAVOR(info ->OutputFormat);
-    int i;
-    cmsUInt8Number* Init = output;
-    cmsFloat64Number maximum = IsInkSpace(info ->OutputFormat) ? 100.0 : 1.0;
-    cmsFloat64Number v;
-
-    if (DoSwap) {
-        output += T_EXTRA(info -> OutputFormat) * Stride * sizeof(cmsFloat64Number);
-    }
-
-    for (i=0; i < nChan; i++) {
-
-        int index = DoSwap ? (nChan - i - 1) : i;
-
-        v = (cmsFloat64Number) wOut[index] * maximum;
-
-        if (Reverse) 
-            v =  maximum - v;
-
-        *(cmsFloat64Number*) output = v;
-        output += (Stride * sizeof(cmsFloat64Number));
-    }
-
-    return (Init + sizeof(cmsFloat64Number));
-}
 
 
 
 
 static
-cmsUInt8Number* PackLabFloatFromFloat(_cmsTRANSFORM* Info, 
-                                      cmsFloat32Number wOut[], 
+cmsUInt8Number* PackLabFloatFromFloat(_cmsTRANSFORM* Info,
+                                      cmsFloat32Number wOut[],
                                       cmsUInt8Number* output,
                                       cmsUInt32Number Stride)
-{        
+{
     cmsFloat32Number* Out = (cmsFloat32Number*) output;
 
     if (T_PLANAR(Info -> OutputFormat)) {
@@ -2384,17 +2529,18 @@ cmsUInt8Number* PackLabFloatFromFloat(_cmsTRANSFORM* Info,
         Out[1] = (cmsFloat32Number) (wOut[1] * 255.0 - 128.0);
         Out[2] = (cmsFloat32Number) (wOut[2] * 255.0 - 128.0);
 
-        return output + (sizeof(cmsFloat32Number)*3 + T_EXTRA(Info ->OutputFormat) * sizeof(cmsFloat32Number));            
+        return output + (sizeof(cmsFloat32Number)*3 + T_EXTRA(Info ->OutputFormat) * sizeof(cmsFloat32Number));
     }
 
 }
 
+
 static
-cmsUInt8Number* PackLabDoubleFromFloat(_cmsTRANSFORM* Info, 
-                                       cmsFloat32Number wOut[], 
+cmsUInt8Number* PackLabDoubleFromFloat(_cmsTRANSFORM* Info,
+                                       cmsFloat32Number wOut[],
                                        cmsUInt8Number* output,
                                        cmsUInt32Number Stride)
-{        
+{
     cmsFloat64Number* Out = (cmsFloat64Number*) output;
 
     if (T_PLANAR(Info -> OutputFormat)) {
@@ -2411,7 +2557,7 @@ cmsUInt8Number* PackLabDoubleFromFloat(_cmsTRANSFORM* Info,
         Out[1] = (cmsFloat64Number) (wOut[1] * 255.0 - 128.0);
         Out[2] = (cmsFloat64Number) (wOut[2] * 255.0 - 128.0);
 
-        return output + (sizeof(cmsFloat64Number)*3 + T_EXTRA(Info ->OutputFormat) * sizeof(cmsFloat64Number));            
+        return output + (sizeof(cmsFloat64Number)*3 + T_EXTRA(Info ->OutputFormat) * sizeof(cmsFloat64Number));
     }
 
 }
@@ -2419,11 +2565,11 @@ cmsUInt8Number* PackLabDoubleFromFloat(_cmsTRANSFORM* Info,
 
 // From 0..1 range to 0..MAX_ENCODEABLE_XYZ
 static
-cmsUInt8Number* PackXYZFloatFromFloat(_cmsTRANSFORM* Info, 
-                                      cmsFloat32Number wOut[], 
+cmsUInt8Number* PackXYZFloatFromFloat(_cmsTRANSFORM* Info,
+                                      cmsFloat32Number wOut[],
                                       cmsUInt8Number* output,
                                       cmsUInt32Number Stride)
-{        
+{
     cmsFloat32Number* Out = (cmsFloat32Number*) output;
 
     if (T_PLANAR(Info -> OutputFormat)) {
@@ -2440,19 +2586,18 @@ cmsUInt8Number* PackXYZFloatFromFloat(_cmsTRANSFORM* Info,
         Out[1] = (cmsFloat32Number) (wOut[1] * MAX_ENCODEABLE_XYZ);
         Out[2] = (cmsFloat32Number) (wOut[2] * MAX_ENCODEABLE_XYZ);
 
-        return output + (sizeof(cmsFloat32Number)*3 + T_EXTRA(Info ->OutputFormat) * sizeof(cmsFloat32Number));            
+        return output + (sizeof(cmsFloat32Number)*3 + T_EXTRA(Info ->OutputFormat) * sizeof(cmsFloat32Number));
     }
 
 }
 
-
 // Same, but convert to double
 static
-cmsUInt8Number* PackXYZDoubleFromFloat(_cmsTRANSFORM* Info, 
-                                       cmsFloat32Number wOut[], 
+cmsUInt8Number* PackXYZDoubleFromFloat(_cmsTRANSFORM* Info,
+                                       cmsFloat32Number wOut[],
                                        cmsUInt8Number* output,
                                        cmsUInt32Number Stride)
-{        
+{
     cmsFloat64Number* Out = (cmsFloat64Number*) output;
 
     if (T_PLANAR(Info -> OutputFormat)) {
@@ -2469,7 +2614,7 @@ cmsUInt8Number* PackXYZDoubleFromFloat(_cmsTRANSFORM* Info,
         Out[1] = (cmsFloat64Number) (wOut[1] * MAX_ENCODEABLE_XYZ);
         Out[2] = (cmsFloat64Number) (wOut[2] * MAX_ENCODEABLE_XYZ);
 
-        return output + (sizeof(cmsFloat64Number)*3 + T_EXTRA(Info ->OutputFormat) * sizeof(cmsFloat64Number));            
+        return output + (sizeof(cmsFloat64Number)*3 + T_EXTRA(Info ->OutputFormat) * sizeof(cmsFloat64Number));
     }
 
 }
@@ -2477,6 +2622,223 @@ cmsUInt8Number* PackXYZDoubleFromFloat(_cmsTRANSFORM* Info,
 
 // ----------------------------------------------------------------------------------------------------------------
 
+#ifndef CMS_NO_HALF_SUPPORT 
+
+// Decodes an stream of half floats to wIn[] described by input format
+
+static
+cmsUInt8Number* UnrollHalfTo16(register _cmsTRANSFORM* info,
+                                register cmsUInt16Number wIn[],
+                                register cmsUInt8Number* accum,
+                                register cmsUInt32Number Stride)
+{
+
+    int nChan      = T_CHANNELS(info -> InputFormat);
+    int DoSwap     = T_DOSWAP(info ->InputFormat);
+    int Reverse    = T_FLAVOR(info ->InputFormat);
+    int SwapFirst  = T_SWAPFIRST(info -> InputFormat);
+    int Extra      = T_EXTRA(info -> InputFormat);
+    int ExtraFirst = DoSwap ^ SwapFirst;
+    int Planar     = T_PLANAR(info -> InputFormat);
+    cmsFloat32Number v;
+    int i, start = 0;
+    cmsFloat32Number maximum = IsInkSpace(info ->InputFormat) ? 655.35F : 65535.0F;
+
+
+    if (ExtraFirst)
+            start = Extra;
+
+    for (i=0; i < nChan; i++) {
+
+        int index = DoSwap ? (nChan - i - 1) : i;
+
+        if (Planar)
+            v = _cmsHalf2Float ( ((cmsUInt16Number*) accum)[(i + start) * Stride] );
+        else
+            v = _cmsHalf2Float ( ((cmsUInt16Number*) accum)[i + start] ) ;
+
+        if (Reverse) v = maximum - v;
+
+        wIn[index] = _cmsQuickSaturateWord(v * maximum);
+    }
+
+
+    if (Extra == 0 && SwapFirst) {
+        cmsUInt16Number tmp = wIn[0];
+
+        memmove(&wIn[0], &wIn[1], (nChan-1) * sizeof(cmsUInt16Number));
+        wIn[nChan-1] = tmp;
+    }
+
+    if (T_PLANAR(info -> InputFormat))
+        return accum + sizeof(cmsUInt16Number);
+    else
+        return accum + (nChan + Extra) * sizeof(cmsUInt16Number);
+}
+
+// Decodes an stream of half floats to wIn[] described by input format
+
+static
+cmsUInt8Number* UnrollHalfToFloat(_cmsTRANSFORM* info,
+                                    cmsFloat32Number wIn[],
+                                    cmsUInt8Number* accum,
+                                    cmsUInt32Number Stride)
+{
+
+    int nChan      = T_CHANNELS(info -> InputFormat);
+    int DoSwap     = T_DOSWAP(info ->InputFormat);
+    int Reverse    = T_FLAVOR(info ->InputFormat);
+    int SwapFirst  = T_SWAPFIRST(info -> InputFormat);
+    int Extra      = T_EXTRA(info -> InputFormat);
+    int ExtraFirst = DoSwap ^ SwapFirst;
+    int Planar     = T_PLANAR(info -> InputFormat);
+    cmsFloat32Number v;
+    int i, start = 0;
+    cmsFloat32Number maximum = IsInkSpace(info ->InputFormat) ? 100.0F : 1.0F;
+
+
+    if (ExtraFirst)
+            start = Extra;
+
+    for (i=0; i < nChan; i++) {
+
+        int index = DoSwap ? (nChan - i - 1) : i;
+
+        if (Planar)
+            v =  _cmsHalf2Float ( ((cmsUInt16Number*) accum)[(i + start) * Stride] );
+        else
+            v =  _cmsHalf2Float ( ((cmsUInt16Number*) accum)[i + start] ) ;
+
+        v /= maximum;
+
+        wIn[index] = Reverse ? 1 - v : v;
+    }
+
+
+    if (Extra == 0 && SwapFirst) {
+        cmsFloat32Number tmp = wIn[0];
+
+        memmove(&wIn[0], &wIn[1], (nChan-1) * sizeof(cmsFloat32Number));
+        wIn[nChan-1] = tmp;
+    }
+
+    if (T_PLANAR(info -> InputFormat))
+        return accum + sizeof(cmsUInt16Number);
+    else
+        return accum + (nChan + Extra) * sizeof(cmsUInt16Number);
+}
+
+
+static
+cmsUInt8Number* PackHalfFrom16(register _cmsTRANSFORM* info,
+                                register cmsUInt16Number wOut[],
+                                register cmsUInt8Number* output,
+                                register cmsUInt32Number Stride)
+{
+    int nChan      = T_CHANNELS(info -> OutputFormat);
+    int DoSwap     = T_DOSWAP(info ->OutputFormat);
+    int Reverse    = T_FLAVOR(info ->OutputFormat);
+    int Extra      = T_EXTRA(info -> OutputFormat);
+    int SwapFirst  = T_SWAPFIRST(info -> OutputFormat);
+    int Planar     = T_PLANAR(info -> OutputFormat);
+    int ExtraFirst = DoSwap ^ SwapFirst;
+    cmsFloat32Number maximum = IsInkSpace(info ->OutputFormat) ? 655.35F : 65535.0F;
+    cmsFloat32Number v = 0;
+    cmsUInt16Number* swap1 = (cmsUInt16Number*) output;
+    int i, start = 0;
+
+    if (ExtraFirst)
+        start = Extra;
+
+    for (i=0; i < nChan; i++) {
+
+        int index = DoSwap ? (nChan - i - 1) : i;
+
+        v = (cmsFloat32Number) wOut[index] / maximum;
+
+        if (Reverse)
+            v = maximum - v;
+
+        if (Planar)
+            ((cmsUInt16Number*) output)[(i + start ) * Stride]= _cmsFloat2Half(v);
+        else
+            ((cmsUInt16Number*) output)[i + start] =  _cmsFloat2Half(v);
+    }
+
+    if (!ExtraFirst) {
+        output += Extra * sizeof(cmsUInt16Number);
+    }
+
+  if (Extra == 0 && SwapFirst) {
+
+         memmove(swap1 + 1, swap1, (nChan-1)* sizeof(cmsUInt16Number));
+        *swap1 = _cmsFloat2Half(v);
+    }
+
+    if (T_PLANAR(info -> OutputFormat))
+        return output + sizeof(cmsUInt16Number);
+    else
+        return output + nChan * sizeof(cmsUInt16Number);
+}
+
+
+
+static
+cmsUInt8Number* PackHalfFromFloat(_cmsTRANSFORM* info,
+                                    cmsFloat32Number wOut[],
+                                    cmsUInt8Number* output,
+                                    cmsUInt32Number Stride)
+{
+    int nChan      = T_CHANNELS(info -> OutputFormat);
+    int DoSwap     = T_DOSWAP(info ->OutputFormat);
+    int Reverse    = T_FLAVOR(info ->OutputFormat);
+    int Extra      = T_EXTRA(info -> OutputFormat);
+    int SwapFirst  = T_SWAPFIRST(info -> OutputFormat);
+    int Planar     = T_PLANAR(info -> OutputFormat);
+    int ExtraFirst = DoSwap ^ SwapFirst;
+    cmsFloat32Number maximum = IsInkSpace(info ->OutputFormat) ? 100.0F : 1.0F;
+    cmsUInt16Number* swap1 = (cmsUInt16Number*) output;
+    cmsFloat32Number v = 0;
+    int i, start = 0;
+
+    if (ExtraFirst)
+        start = Extra;
+
+    for (i=0; i < nChan; i++) {
+
+        int index = DoSwap ? (nChan - i - 1) : i;
+
+        v = wOut[index] * maximum;
+
+        if (Reverse)
+            v = maximum - v;
+
+        if (Planar)
+            ((cmsUInt16Number*) output)[(i + start)* Stride]= _cmsFloat2Half( v );
+        else
+            ((cmsUInt16Number*) output)[i + start] = _cmsFloat2Half( v );
+    }
+
+    if (!ExtraFirst) {
+        output += Extra * sizeof(cmsUInt16Number);
+    }
+
+   if (Extra == 0 && SwapFirst) {
+
+         memmove(swap1 + 1, swap1, (nChan-1)* sizeof(cmsUInt16Number));
+        *swap1 = (cmsUInt16Number)  _cmsFloat2Half( v );
+    }
+
+    if (T_PLANAR(info -> OutputFormat))
+        return output + sizeof(cmsUInt16Number);
+    else
+        return output + nChan * sizeof(cmsUInt16Number);
+}
+
+#endif
+
+// ----------------------------------------------------------------------------------------------------------------
+
 
 static cmsFormatters16 InputFormatters16[] = {
 
@@ -2484,17 +2846,23 @@ static cmsFormatters16 InputFormatters16[] = {
     //  ----------------------------   ------------------------------------  ----------------------------
     { TYPE_Lab_DBL,                                 ANYPLANAR|ANYEXTRA,   UnrollLabDoubleTo16},
     { TYPE_XYZ_DBL,                                 ANYPLANAR|ANYEXTRA,   UnrollXYZDoubleTo16},
+    { TYPE_Lab_FLT,                                 ANYPLANAR|ANYEXTRA,   UnrollLabFloatTo16},
     { TYPE_GRAY_DBL,                                                 0,   UnrollDouble1Chan},
-    { FLOAT_SH(1)|BYTES_SH(0), ANYCHANNELS|ANYPLANAR|ANYEXTRA|ANYSPACE,   UnrollDoubleTo16},
-    { FLOAT_SH(1)|BYTES_SH(4), ANYCHANNELS|ANYPLANAR|ANYEXTRA|ANYSPACE,   UnrollFloatTo16},
-
+    { FLOAT_SH(1)|BYTES_SH(0), ANYCHANNELS|ANYPLANAR|ANYSWAPFIRST|ANYFLAVOR|
+                                             ANYSWAP|ANYEXTRA|ANYSPACE,   UnrollDoubleTo16},
+    { FLOAT_SH(1)|BYTES_SH(4), ANYCHANNELS|ANYPLANAR|ANYSWAPFIRST|ANYFLAVOR|
+                                             ANYSWAP|ANYEXTRA|ANYSPACE,   UnrollFloatTo16},
+#ifndef CMS_NO_HALF_SUPPORT 
+    { FLOAT_SH(1)|BYTES_SH(2), ANYCHANNELS|ANYPLANAR|ANYSWAPFIRST|ANYFLAVOR|
+                                            ANYEXTRA|ANYSWAP|ANYSPACE,   UnrollHalfTo16},
+#endif
 
-    { CHANNELS_SH(1)|BYTES_SH(1),                              ANYSPACE,  Unroll1Byte}, 
+    { CHANNELS_SH(1)|BYTES_SH(1),                              ANYSPACE,  Unroll1Byte},
     { CHANNELS_SH(1)|BYTES_SH(1)|EXTRA_SH(1),                  ANYSPACE,  Unroll1ByteSkip1},
     { CHANNELS_SH(1)|BYTES_SH(1)|EXTRA_SH(2),                  ANYSPACE,  Unroll1ByteSkip2},
     { CHANNELS_SH(1)|BYTES_SH(1)|FLAVOR_SH(1),                 ANYSPACE,  Unroll1ByteReversed},
     { COLORSPACE_SH(PT_MCH2)|CHANNELS_SH(2)|BYTES_SH(1),              0,  Unroll2Bytes},
-   
+
     { TYPE_LabV2_8,                                                   0,  UnrollLabV2_8 },
     { TYPE_ALabV2_8,                                                  0,  UnrollALabV2_8 },
     { TYPE_LabV2_16,                                                  0,  UnrollLabV2_16 },
@@ -2506,13 +2874,15 @@ static cmsFormatters16 InputFormatters16[] = {
 
     { CHANNELS_SH(4)|BYTES_SH(1),                              ANYSPACE,  Unroll4Bytes},
     { CHANNELS_SH(4)|BYTES_SH(1)|FLAVOR_SH(1),                 ANYSPACE,  Unroll4BytesReverse},
-    { CHANNELS_SH(4)|BYTES_SH(1)|SWAPFIRST_SH(1),              ANYSPACE,  Unroll4BytesSwapFirst}, 
-    { CHANNELS_SH(4)|BYTES_SH(1)|DOSWAP_SH(1),                 ANYSPACE,  Unroll4BytesSwap}, 
-    { CHANNELS_SH(4)|BYTES_SH(1)|DOSWAP_SH(1)|SWAPFIRST_SH(1), ANYSPACE,  Unroll4BytesSwapSwapFirst}, 
+    { CHANNELS_SH(4)|BYTES_SH(1)|SWAPFIRST_SH(1),              ANYSPACE,  Unroll4BytesSwapFirst},
+    { CHANNELS_SH(4)|BYTES_SH(1)|DOSWAP_SH(1),                 ANYSPACE,  Unroll4BytesSwap},
+    { CHANNELS_SH(4)|BYTES_SH(1)|DOSWAP_SH(1)|SWAPFIRST_SH(1), ANYSPACE,  Unroll4BytesSwapSwapFirst},
 
-    { BYTES_SH(1)|PLANAR_SH(1),    ANYFLAVOR|ANYSWAP|ANYEXTRA|ANYCHANNELS|ANYSPACE, UnrollPlanarBytes},
-    { BYTES_SH(1),    ANYFLAVOR|ANYSWAPFIRST|ANYSWAP|ANYEXTRA|ANYCHANNELS|ANYSPACE, UnrollChunkyBytes},     
+    { BYTES_SH(1)|PLANAR_SH(1), ANYFLAVOR|ANYSWAPFIRST|
+                                   ANYSWAP|ANYEXTRA|ANYCHANNELS|ANYSPACE, UnrollPlanarBytes},
 
+    { BYTES_SH(1),    ANYFLAVOR|ANYSWAPFIRST|ANYSWAP|
+                                           ANYEXTRA|ANYCHANNELS|ANYSPACE, UnrollChunkyBytes},
 
     { CHANNELS_SH(1)|BYTES_SH(2),                              ANYSPACE,  Unroll1Word},
     { CHANNELS_SH(1)|BYTES_SH(2)|FLAVOR_SH(1),                 ANYSPACE,  Unroll1WordReversed},
@@ -2526,13 +2896,13 @@ static cmsFormatters16 InputFormatters16[] = {
     { CHANNELS_SH(3)|BYTES_SH(2)|EXTRA_SH(1)|SWAPFIRST_SH(1),  ANYSPACE,  Unroll3WordsSkip1SwapFirst},
     { CHANNELS_SH(3)|BYTES_SH(2)|EXTRA_SH(1)|DOSWAP_SH(1),     ANYSPACE,  Unroll3WordsSkip1Swap},
     { CHANNELS_SH(4)|BYTES_SH(2)|FLAVOR_SH(1),                 ANYSPACE,  Unroll4WordsReverse},
-    { CHANNELS_SH(4)|BYTES_SH(2)|SWAPFIRST_SH(1),              ANYSPACE,  Unroll4WordsSwapFirst}, 
-    { CHANNELS_SH(4)|BYTES_SH(2)|DOSWAP_SH(1),                 ANYSPACE,  Unroll4WordsSwap}, 
-    { CHANNELS_SH(4)|BYTES_SH(2)|DOSWAP_SH(1)|SWAPFIRST_SH(1), ANYSPACE,  Unroll4WordsSwapSwapFirst}, 
+    { CHANNELS_SH(4)|BYTES_SH(2)|SWAPFIRST_SH(1),              ANYSPACE,  Unroll4WordsSwapFirst},
+    { CHANNELS_SH(4)|BYTES_SH(2)|DOSWAP_SH(1),                 ANYSPACE,  Unroll4WordsSwap},
+    { CHANNELS_SH(4)|BYTES_SH(2)|DOSWAP_SH(1)|SWAPFIRST_SH(1), ANYSPACE,  Unroll4WordsSwapSwapFirst},
 
 
-    { BYTES_SH(2)|PLANAR_SH(1),  ANYFLAVOR|ANYSWAP|ANYENDIAN|ANYEXTRA|ANYCHANNELS|ANYSPACE,  UnrollPlanarWords },
-    { BYTES_SH(2),  ANYFLAVOR|ANYSWAPFIRST|ANYSWAP|ANYENDIAN|ANYEXTRA|ANYCHANNELS|ANYSPACE,  UnrollAnyWords}, 
+    { BYTES_SH(2)|PLANAR_SH(1),  ANYFLAVOR|ANYSWAP|ANYENDIAN|ANYEXTRA|ANYCHANNELS|ANYSPACE,  UnrollPlanarWords},
+    { BYTES_SH(2),  ANYFLAVOR|ANYSWAPFIRST|ANYSWAP|ANYENDIAN|ANYEXTRA|ANYCHANNELS|ANYSPACE,  UnrollAnyWords},
 };
 
 
@@ -2543,11 +2913,19 @@ static cmsFormattersFloat InputFormattersFloat[] = {
     //  ----------------------------   ------------------------------------  ----------------------------
     {     TYPE_Lab_DBL,                                ANYPLANAR|ANYEXTRA,   UnrollLabDoubleToFloat},
     {     TYPE_Lab_FLT,                                ANYPLANAR|ANYEXTRA,   UnrollLabFloatToFloat},
+
     {     TYPE_XYZ_DBL,                                ANYPLANAR|ANYEXTRA,   UnrollXYZDoubleToFloat},
     {     TYPE_XYZ_FLT,                                ANYPLANAR|ANYEXTRA,   UnrollXYZFloatToFloat},
 
-    {     FLOAT_SH(1)|BYTES_SH(4), ANYPLANAR|ANYEXTRA|ANYCHANNELS|ANYSPACE,  UnrollFloatsToFloat},
-    {     FLOAT_SH(1)|BYTES_SH(0), ANYPLANAR|ANYEXTRA|ANYCHANNELS|ANYSPACE,  UnrollDoublesToFloat},
+    {     FLOAT_SH(1)|BYTES_SH(4), ANYPLANAR|ANYSWAPFIRST|ANYSWAP|ANYEXTRA|
+                                                      ANYCHANNELS|ANYSPACE,  UnrollFloatsToFloat},
+
+    {     FLOAT_SH(1)|BYTES_SH(0), ANYPLANAR|ANYSWAPFIRST|ANYSWAP|ANYEXTRA|
+                                                        ANYCHANNELS|ANYSPACE,  UnrollDoublesToFloat},
+#ifndef CMS_NO_HALF_SUPPORT 
+    {     FLOAT_SH(1)|BYTES_SH(2), ANYPLANAR|ANYSWAPFIRST|ANYSWAP|ANYEXTRA|
+                                                        ANYCHANNELS|ANYSPACE,  UnrollHalfToFloat},
+#endif
 };
 
 
@@ -2558,9 +2936,9 @@ cmsFormatter _cmsGetStockInputFormatter(cmsUInt32Number dwInput, cmsUInt32Number
     cmsUInt32Number i;
     cmsFormatter fr;
 
+    switch (dwFlags) {
 
-    if (!(dwFlags & CMS_PACK_FLAGS_FLOAT)) {
-
+    case CMS_PACK_FLAGS_16BITS: {
         for (i=0; i < sizeof(InputFormatters16) / sizeof(cmsFormatters16); i++) {
             cmsFormatters16* f = InputFormatters16 + i;
 
@@ -2570,7 +2948,9 @@ cmsFormatter _cmsGetStockInputFormatter(cmsUInt32Number dwInput, cmsUInt32Number
             }
         }
     }
-    else {
+    break;
+
+    case CMS_PACK_FLAGS_FLOAT: {
         for (i=0; i < sizeof(InputFormattersFloat) / sizeof(cmsFormattersFloat); i++) {
             cmsFormattersFloat* f = InputFormattersFloat + i;
 
@@ -2580,6 +2960,11 @@ cmsFormatter _cmsGetStockInputFormatter(cmsUInt32Number dwInput, cmsUInt32Number
             }
         }
     }
+    break;
+
+    default:;
+
+    }
 
     fr.Fmt16 = NULL;
     return fr;
@@ -2591,10 +2976,19 @@ static cmsFormatters16 OutputFormatters16[] = {
 
     { TYPE_Lab_DBL,                                      ANYPLANAR|ANYEXTRA,  PackLabDoubleFrom16},
     { TYPE_XYZ_DBL,                                      ANYPLANAR|ANYEXTRA,  PackXYZDoubleFrom16},
-    { FLOAT_SH(1)|BYTES_SH(0),      ANYCHANNELS|ANYPLANAR|ANYEXTRA|ANYSPACE,  PackDoubleFrom16},
-    { FLOAT_SH(1)|BYTES_SH(4),      ANYCHANNELS|ANYPLANAR|ANYEXTRA|ANYSPACE,  PackFloatFrom16},
 
-    { CHANNELS_SH(1)|BYTES_SH(1),                                  ANYSPACE,  Pack1Byte},   
+    { TYPE_Lab_FLT,                                      ANYPLANAR|ANYEXTRA,  PackLabFloatFrom16},
+    
+    { FLOAT_SH(1)|BYTES_SH(0),      ANYFLAVOR|ANYSWAPFIRST|ANYSWAP|
+                                    ANYCHANNELS|ANYPLANAR|ANYEXTRA|ANYSPACE,  PackDoubleFrom16},
+    { FLOAT_SH(1)|BYTES_SH(4),      ANYFLAVOR|ANYSWAPFIRST|ANYSWAP|
+                                    ANYCHANNELS|ANYPLANAR|ANYEXTRA|ANYSPACE,  PackFloatFrom16},
+#ifndef CMS_NO_HALF_SUPPORT 
+    { FLOAT_SH(1)|BYTES_SH(2),      ANYFLAVOR|ANYSWAPFIRST|ANYSWAP|
+                                    ANYCHANNELS|ANYPLANAR|ANYEXTRA|ANYSPACE,  PackHalfFrom16},
+#endif
+
+    { CHANNELS_SH(1)|BYTES_SH(1),                                  ANYSPACE,  Pack1Byte},
     { CHANNELS_SH(1)|BYTES_SH(1)|EXTRA_SH(1),                      ANYSPACE,  Pack1ByteSkip1},
     { CHANNELS_SH(1)|BYTES_SH(1)|EXTRA_SH(1)|SWAPFIRST_SH(1),      ANYSPACE,  Pack1ByteSkip1SwapFirst},
 
@@ -2608,9 +3002,9 @@ static cmsFormatters16 OutputFormatters16[] = {
     { CHANNELS_SH(3)|BYTES_SH(1)|EXTRA_SH(1)|OPTIMIZED_SH(1),      ANYSPACE,  Pack3BytesAndSkip1Optimized},
     { CHANNELS_SH(3)|BYTES_SH(1)|EXTRA_SH(1)|SWAPFIRST_SH(1)|OPTIMIZED_SH(1),
                                                                    ANYSPACE,  Pack3BytesAndSkip1SwapFirstOptimized},
-    { CHANNELS_SH(3)|BYTES_SH(1)|EXTRA_SH(1)|DOSWAP_SH(1)|SWAPFIRST_SH(1)|OPTIMIZED_SH(1),  
+    { CHANNELS_SH(3)|BYTES_SH(1)|EXTRA_SH(1)|DOSWAP_SH(1)|SWAPFIRST_SH(1)|OPTIMIZED_SH(1),
                                                                    ANYSPACE,  Pack3BytesAndSkip1SwapSwapFirstOptimized},
-    { CHANNELS_SH(3)|BYTES_SH(1)|DOSWAP_SH(1)|EXTRA_SH(1)|OPTIMIZED_SH(1),         
+    { CHANNELS_SH(3)|BYTES_SH(1)|DOSWAP_SH(1)|EXTRA_SH(1)|OPTIMIZED_SH(1),
                                                                    ANYSPACE,  Pack3BytesAndSkip1SwapOptimized},
     { CHANNELS_SH(3)|BYTES_SH(1)|DOSWAP_SH(1)|OPTIMIZED_SH(1),     ANYSPACE,  Pack3BytesSwapOptimized},
 
@@ -2619,7 +3013,7 @@ static cmsFormatters16 OutputFormatters16[] = {
     { CHANNELS_SH(3)|BYTES_SH(1),                                  ANYSPACE,  Pack3Bytes},
     { CHANNELS_SH(3)|BYTES_SH(1)|EXTRA_SH(1),                      ANYSPACE,  Pack3BytesAndSkip1},
     { CHANNELS_SH(3)|BYTES_SH(1)|EXTRA_SH(1)|SWAPFIRST_SH(1),      ANYSPACE,  Pack3BytesAndSkip1SwapFirst},
-    { CHANNELS_SH(3)|BYTES_SH(1)|EXTRA_SH(1)|DOSWAP_SH(1)|SWAPFIRST_SH(1),  
+    { CHANNELS_SH(3)|BYTES_SH(1)|EXTRA_SH(1)|DOSWAP_SH(1)|SWAPFIRST_SH(1),
                                                                    ANYSPACE,  Pack3BytesAndSkip1SwapSwapFirst},
     { CHANNELS_SH(3)|BYTES_SH(1)|DOSWAP_SH(1)|EXTRA_SH(1),         ANYSPACE,  Pack3BytesAndSkip1Swap},
     { CHANNELS_SH(3)|BYTES_SH(1)|DOSWAP_SH(1),                     ANYSPACE,  Pack3BytesSwap},
@@ -2627,12 +3021,12 @@ static cmsFormatters16 OutputFormatters16[] = {
     { CHANNELS_SH(6)|BYTES_SH(1)|DOSWAP_SH(1),                     ANYSPACE,  Pack6BytesSwap},
     { CHANNELS_SH(4)|BYTES_SH(1),                                  ANYSPACE,  Pack4Bytes},
     { CHANNELS_SH(4)|BYTES_SH(1)|FLAVOR_SH(1),                     ANYSPACE,  Pack4BytesReverse},
-    { CHANNELS_SH(4)|BYTES_SH(1)|SWAPFIRST_SH(1),                  ANYSPACE,  Pack4BytesSwapFirst}, 
-    { CHANNELS_SH(4)|BYTES_SH(1)|DOSWAP_SH(1),                     ANYSPACE,  Pack4BytesSwap}, 
-    { CHANNELS_SH(4)|BYTES_SH(1)|DOSWAP_SH(1)|SWAPFIRST_SH(1),     ANYSPACE,  Pack4BytesSwapSwapFirst}, 
+    { CHANNELS_SH(4)|BYTES_SH(1)|SWAPFIRST_SH(1),                  ANYSPACE,  Pack4BytesSwapFirst},
+    { CHANNELS_SH(4)|BYTES_SH(1)|DOSWAP_SH(1),                     ANYSPACE,  Pack4BytesSwap},
+    { CHANNELS_SH(4)|BYTES_SH(1)|DOSWAP_SH(1)|SWAPFIRST_SH(1),     ANYSPACE,  Pack4BytesSwapSwapFirst},
 
-    { BYTES_SH(1),                 ANYFLAVOR|ANYSWAPFIRST|ANYSWAP|ANYEXTRA|ANYCHANNELS|ANYSPACE, PackAnyBytes},     
-    { BYTES_SH(1)|PLANAR_SH(1),    ANYFLAVOR|ANYSWAP|ANYEXTRA|ANYCHANNELS|ANYSPACE, PackPlanarBytes},   
+    { BYTES_SH(1),                 ANYFLAVOR|ANYSWAPFIRST|ANYSWAP|ANYEXTRA|ANYCHANNELS|ANYSPACE, PackAnyBytes},
+    { BYTES_SH(1)|PLANAR_SH(1),    ANYFLAVOR|ANYSWAPFIRST|ANYSWAP|ANYEXTRA|ANYCHANNELS|ANYSPACE, PackPlanarBytes},
 
     { CHANNELS_SH(1)|BYTES_SH(2),                                  ANYSPACE,  Pack1Word},
     { CHANNELS_SH(1)|BYTES_SH(2)|EXTRA_SH(1),                      ANYSPACE,  Pack1WordSkip1},
@@ -2646,18 +3040,18 @@ static cmsFormatters16 OutputFormatters16[] = {
     { CHANNELS_SH(3)|BYTES_SH(2)|EXTRA_SH(1)|DOSWAP_SH(1),         ANYSPACE,  Pack3WordsAndSkip1Swap},
     { CHANNELS_SH(3)|BYTES_SH(2)|EXTRA_SH(1)|SWAPFIRST_SH(1),      ANYSPACE,  Pack3WordsAndSkip1SwapFirst},
 
-    { CHANNELS_SH(3)|BYTES_SH(2)|EXTRA_SH(1)|DOSWAP_SH(1)|SWAPFIRST_SH(1),             
+    { CHANNELS_SH(3)|BYTES_SH(2)|EXTRA_SH(1)|DOSWAP_SH(1)|SWAPFIRST_SH(1),
                                                                    ANYSPACE,  Pack3WordsAndSkip1SwapSwapFirst},
 
     { CHANNELS_SH(4)|BYTES_SH(2),                                  ANYSPACE,  Pack4Words},
     { CHANNELS_SH(4)|BYTES_SH(2)|FLAVOR_SH(1),                     ANYSPACE,  Pack4WordsReverse},
-    { CHANNELS_SH(4)|BYTES_SH(2)|DOSWAP_SH(1),                     ANYSPACE,  Pack4WordsSwap}, 
+    { CHANNELS_SH(4)|BYTES_SH(2)|DOSWAP_SH(1),                     ANYSPACE,  Pack4WordsSwap},
     { CHANNELS_SH(4)|BYTES_SH(2)|ENDIAN16_SH(1),                   ANYSPACE,  Pack4WordsBigEndian},
 
     { CHANNELS_SH(6)|BYTES_SH(2),                                  ANYSPACE,  Pack6Words},
     { CHANNELS_SH(6)|BYTES_SH(2)|DOSWAP_SH(1),                     ANYSPACE,  Pack6WordsSwap},
 
-    { BYTES_SH(2)|PLANAR_SH(1),     ANYFLAVOR|ANYENDIAN|ANYSWAP|ANYEXTRA|ANYCHANNELS|ANYSPACE, PackPlanarWords}, 
+    { BYTES_SH(2)|PLANAR_SH(1),     ANYFLAVOR|ANYENDIAN|ANYSWAP|ANYEXTRA|ANYCHANNELS|ANYSPACE, PackPlanarWords},
     { BYTES_SH(2),                  ANYFLAVOR|ANYSWAPFIRST|ANYSWAP|ANYENDIAN|ANYEXTRA|ANYCHANNELS|ANYSPACE, PackAnyWords}
 
 };
@@ -2668,48 +3062,63 @@ static cmsFormattersFloat OutputFormattersFloat[] = {
     //  ----------------------------   ---------------------------------------------------  ----------------------------
     {     TYPE_Lab_FLT,                                                ANYPLANAR|ANYEXTRA,   PackLabFloatFromFloat},
     {     TYPE_XYZ_FLT,                                                ANYPLANAR|ANYEXTRA,   PackXYZFloatFromFloat},
+
     {     TYPE_Lab_DBL,                                                ANYPLANAR|ANYEXTRA,   PackLabDoubleFromFloat},
     {     TYPE_XYZ_DBL,                                                ANYPLANAR|ANYEXTRA,   PackXYZDoubleFromFloat},
-    {     FLOAT_SH(1)|BYTES_SH(4), 
-                             ANYFLAVOR|ANYSWAPFIRST|ANYSWAP|ANYEXTRA|ANYCHANNELS|ANYSPACE,   PackChunkyFloatsFromFloat }, 
-    {     FLOAT_SH(1)|BYTES_SH(4)|PLANAR_SH(1),             ANYEXTRA|ANYCHANNELS|ANYSPACE,   PackPlanarFloatsFromFloat},
-    {     FLOAT_SH(1)|BYTES_SH(0),
-                             ANYFLAVOR|ANYSWAPFIRST|ANYSWAP|ANYEXTRA|ANYCHANNELS|ANYSPACE,   PackChunkyDoublesFromFloat }, 
-    {     FLOAT_SH(1)|BYTES_SH(0)|PLANAR_SH(1),             ANYEXTRA|ANYCHANNELS|ANYSPACE,   PackPlanarDoublesFromFloat},
+
+    {     FLOAT_SH(1)|BYTES_SH(4), ANYPLANAR|
+                             ANYFLAVOR|ANYSWAPFIRST|ANYSWAP|ANYEXTRA|ANYCHANNELS|ANYSPACE,   PackFloatsFromFloat },
+    {     FLOAT_SH(1)|BYTES_SH(0), ANYPLANAR|
+                             ANYFLAVOR|ANYSWAPFIRST|ANYSWAP|ANYEXTRA|ANYCHANNELS|ANYSPACE,   PackDoublesFromFloat },
+#ifndef CMS_NO_HALF_SUPPORT 
+    {     FLOAT_SH(1)|BYTES_SH(2),                                   
+                             ANYFLAVOR|ANYSWAPFIRST|ANYSWAP|ANYEXTRA|ANYCHANNELS|ANYSPACE,   PackHalfFromFloat },
+#endif
+
 
 
 };
 
 
 // Bit fields set to one in the mask are not compared
+static
 cmsFormatter _cmsGetStockOutputFormatter(cmsUInt32Number dwInput, cmsUInt32Number dwFlags)
 {
     cmsUInt32Number i;
     cmsFormatter fr;
 
 
-    if (dwFlags & CMS_PACK_FLAGS_FLOAT) {
+    switch (dwFlags)
+    {
 
-        for (i=0; i < sizeof(OutputFormattersFloat) / sizeof(cmsFormattersFloat); i++) {
-            cmsFormattersFloat* f = OutputFormattersFloat + i;
+     case CMS_PACK_FLAGS_16BITS: {
+
+        for (i=0; i < sizeof(OutputFormatters16) / sizeof(cmsFormatters16); i++) {
+            cmsFormatters16* f = OutputFormatters16 + i;
 
             if ((dwInput & ~f ->Mask) == f ->Type) {
-                fr.FmtFloat = f ->Frm;
+                fr.Fmt16 = f ->Frm;
                 return fr;
             }
         }
+        }
+        break;
 
-    }
-    else {
+    case CMS_PACK_FLAGS_FLOAT: {
 
-        for (i=0; i < sizeof(OutputFormatters16) / sizeof(cmsFormatters16); i++) {
-            cmsFormatters16* f = OutputFormatters16 + i;
+        for (i=0; i < sizeof(OutputFormattersFloat) / sizeof(cmsFormattersFloat); i++) {
+            cmsFormattersFloat* f = OutputFormattersFloat + i;
 
             if ((dwInput & ~f ->Mask) == f ->Type) {
-                fr.Fmt16 = f ->Frm;
+                fr.FmtFloat = f ->Frm;
                 return fr;
             }
         }
+        }
+        break;
+
+    default:;
+
     }
 
     fr.Fmt16 = NULL;
@@ -2739,7 +3148,7 @@ cmsBool  _cmsRegisterFormattersPlugin(cmsPluginBase* Data)
           FactoryList = NULL;
           return TRUE;
     }
-    
+
     fl = (cmsFormattersFactoryList*) _cmsPluginMalloc(sizeof(cmsFormattersFactoryList));
     if (fl == NULL) return FALSE;
 
@@ -2752,8 +3161,8 @@ cmsBool  _cmsRegisterFormattersPlugin(cmsPluginBase* Data)
 }
 
 cmsFormatter _cmsGetFormatter(cmsUInt32Number Type,         // Specific type, i.e. TYPE_RGB_8
-                             cmsFormatterDirection Dir, 
-                             cmsUInt32Number dwFlags)       // Float or 16 bits
+                             cmsFormatterDirection Dir,
+                             cmsUInt32Number dwFlags)
 {
     cmsFormattersFactoryList* f;
 
@@ -2764,9 +3173,9 @@ cmsFormatter _cmsGetFormatter(cmsUInt32Number Type,         // Specific type, i.
     }
 
     // Revert to default
-    if (Dir == cmsFormatterInput) 
+    if (Dir == cmsFormatterInput)
         return _cmsGetStockInputFormatter(Type, dwFlags);
-    else 
+    else
         return _cmsGetStockOutputFormatter(Type, dwFlags);
 }
 
@@ -2788,7 +3197,7 @@ cmsBool  _cmsFormatterIs8bit(cmsUInt32Number Type)
 // Build a suitable formatter for the colorspace of this profile
 cmsUInt32Number CMSEXPORT cmsFormatterForColorspaceOfProfile(cmsHPROFILE hProfile, cmsUInt32Number nBytes, cmsBool lIsFloat)
 {
+
     cmsColorSpaceSignature ColorSpace      = cmsGetColorSpace(hProfile);
     cmsUInt32Number        ColorSpaceBits  = _cmsLCMScolorSpace(ColorSpace);
     cmsUInt32Number        nOutputChans    = cmsChannelsOf(ColorSpace);
@@ -2801,7 +3210,7 @@ cmsUInt32Number CMSEXPORT cmsFormatterForColorspaceOfProfile(cmsHPROFILE hProfil
 // Build a suitable formatter for the colorspace of this profile
 cmsUInt32Number CMSEXPORT cmsFormatterForPCSOfProfile(cmsHPROFILE hProfile, cmsUInt32Number nBytes, cmsBool lIsFloat)
 {
+
     cmsColorSpaceSignature ColorSpace      = cmsGetPCS(hProfile);
     int                    ColorSpaceBits  = _cmsLCMScolorSpace(ColorSpace);
     cmsUInt32Number        nOutputChans    = cmsChannelsOf(ColorSpace);
index 8dd1c22..3279d71 100644 (file)
@@ -3,22 +3,22 @@
 //  Little Color Management System
 //  Copyright (c) 1998-2010 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 
+// 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 
+// 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 
+// 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.
 //
 //---------------------------------------------------------------------------------
@@ -114,7 +114,7 @@ cmsFloat64Number f(cmsFloat64Number t)
     if (t <= Limit)
         return (841.0/108.0) * t + (16.0/116.0);
     else
-        return pow(t, 1.0/3.0); 
+        return pow(t, 1.0/3.0);
 }
 
 static
@@ -135,7 +135,7 @@ void CMSEXPORT cmsXYZ2Lab(const cmsCIEXYZ* WhitePoint, cmsCIELab* Lab, const cms
 {
     cmsFloat64Number fx, fy, fz;
 
-    if (WhitePoint == NULL) 
+    if (WhitePoint == NULL)
         WhitePoint = cmsD50_XYZ();
 
     fx = f(xyz->X / WhitePoint->X);
@@ -153,7 +153,7 @@ void CMSEXPORT cmsLab2XYZ(const cmsCIEXYZ* WhitePoint, cmsCIEXYZ* xyz,  const cm
 {
     cmsFloat64Number x, y, z;
 
-    if (WhitePoint == NULL) 
+    if (WhitePoint == NULL)
         WhitePoint = cmsD50_XYZ();
 
     y = (Lab-> L + 16.0) / 116.0;
@@ -175,7 +175,7 @@ cmsFloat64Number L2float2(cmsUInt16Number v)
 // the a/b part
 static
 cmsFloat64Number ab2float2(cmsUInt16Number v)
-{   
+{
        return ((cmsFloat64Number) v / 256.0) - 128.0;
 }
 
@@ -249,7 +249,7 @@ void CMSEXPORT cmsFloat2LabEncodedV2(cmsUInt16Number wLab[3], const cmsCIELab* f
     Lab.L = Clamp_L_doubleV2(fLab ->L);
     Lab.a = Clamp_ab_doubleV2(fLab ->a);
     Lab.b = Clamp_ab_doubleV2(fLab ->b);
-                                                
+
     wLab[0] = L2Fix2(Lab.L);
     wLab[1] = ab2Fix2(Lab.a);
     wLab[2] = ab2Fix2(Lab.b);
@@ -274,7 +274,7 @@ cmsFloat64Number Clamp_ab_doubleV4(cmsFloat64Number ab)
     return ab;
 }
 
-static 
+static
 cmsUInt16Number L2Fix4(cmsFloat64Number L)
 {
     return _cmsQuickSaturateWord(L *  655.35);
@@ -289,11 +289,11 @@ cmsUInt16Number ab2Fix4(cmsFloat64Number ab)
 void CMSEXPORT cmsFloat2LabEncoded(cmsUInt16Number wLab[3], const cmsCIELab* fLab)
 {
     cmsCIELab Lab;
-    
+
     Lab.L = Clamp_L_doubleV4(fLab ->L);
     Lab.a = Clamp_ab_doubleV4(fLab ->a);
     Lab.b = Clamp_ab_doubleV4(fLab ->b);
-                                
+
     wLab[0] = L2Fix4(Lab.L);
     wLab[1] = ab2Fix4(Lab.a);
     wLab[2] = ab2Fix4(Lab.b);
@@ -317,15 +317,15 @@ cmsFloat64Number atan2deg(cmsFloat64Number a, cmsFloat64Number b)
             h   = 0;
     else
             h = atan2(a, b);
-   
+
     h *= (180. / M_PI);
-    
-    while (h > 360.)         
+
+    while (h > 360.)
         h -= 360.;
-    
+
     while ( h < 0)
         h += 360.;
-    
+
     return h;
 }
 
@@ -334,7 +334,7 @@ cmsFloat64Number atan2deg(cmsFloat64Number a, cmsFloat64Number b)
 static
 cmsFloat64Number Sqr(cmsFloat64Number v)
 {
-    return v *  v; 
+    return v *  v;
 }
 // From cylindrical coordinates. No check is performed, then negative values are allowed
 void CMSEXPORT cmsLab2LCh(cmsCIELCh* LCh, const cmsCIELab* Lab)
@@ -352,13 +352,13 @@ void CMSEXPORT cmsLCh2Lab(cmsCIELab* Lab, const cmsCIELCh* LCh)
 
     Lab -> L = LCh -> L;
     Lab -> a = LCh -> C * cos(h);
-    Lab -> b = LCh -> C * sin(h);          
+    Lab -> b = LCh -> C * sin(h);
 }
 
 // In XYZ All 3 components are encoded using 1.15 fixed point
 static
 cmsUInt16Number XYZ2Fix(cmsFloat64Number d)
-{     
+{
     return _cmsQuickSaturateWord(d * 32768.0);
 }
 
@@ -370,7 +370,7 @@ void CMSEXPORT cmsFloat2XYZEncoded(cmsUInt16Number XYZ[3], const cmsCIEXYZ* fXYZ
     xyz.Y = fXYZ -> Y;
     xyz.Z = fXYZ -> Z;
 
-    // Clamp to encodeable values.     
+    // Clamp to encodeable values.
     if (xyz.Y <= 0) {
 
         xyz.X = 0;
@@ -378,19 +378,19 @@ void CMSEXPORT cmsFloat2XYZEncoded(cmsUInt16Number XYZ[3], const cmsCIEXYZ* fXYZ
         xyz.Z = 0;
     }
 
-    if (xyz.X > MAX_ENCODEABLE_XYZ)            
+    if (xyz.X > MAX_ENCODEABLE_XYZ)
         xyz.X = MAX_ENCODEABLE_XYZ;
 
     if (xyz.X < 0)
         xyz.X = 0;
 
-    if (xyz.Y > MAX_ENCODEABLE_XYZ)            
+    if (xyz.Y > MAX_ENCODEABLE_XYZ)
         xyz.Y = MAX_ENCODEABLE_XYZ;
 
     if (xyz.Y < 0)
         xyz.Y = 0;
 
-    if (xyz.Z > MAX_ENCODEABLE_XYZ)            
+    if (xyz.Z > MAX_ENCODEABLE_XYZ)
         xyz.Z = MAX_ENCODEABLE_XYZ;
 
     if (xyz.Z < 0)
@@ -399,7 +399,7 @@ void CMSEXPORT cmsFloat2XYZEncoded(cmsUInt16Number XYZ[3], const cmsCIEXYZ* fXYZ
 
     XYZ[0] = XYZ2Fix(xyz.X);
     XYZ[1] = XYZ2Fix(xyz.Y);
-    XYZ[2] = XYZ2Fix(xyz.Z);        
+    XYZ[2] = XYZ2Fix(xyz.Z);
 }
 
 
@@ -422,7 +422,7 @@ void CMSEXPORT cmsXYZEncoded2Float(cmsCIEXYZ* fXYZ, const cmsUInt16Number XYZ[3]
     fXYZ -> X = XYZ2float(XYZ[0]);
     fXYZ -> Y = XYZ2float(XYZ[1]);
     fXYZ -> Z = XYZ2float(XYZ[2]);
-}       
+}
 
 
 // Returns dE on two Lab values
@@ -438,7 +438,7 @@ cmsFloat64Number CMSEXPORT cmsDeltaE(const cmsCIELab* Lab1, const cmsCIELab* Lab
 }
 
 
-// Return the CIE94 Delta E 
+// Return the CIE94 Delta E
 cmsFloat64Number CMSEXPORT cmsCIE94DeltaE(const cmsCIELab* Lab1, const cmsCIELab* Lab2)
 {
     cmsCIELCh LCh1, LCh2;
@@ -452,7 +452,7 @@ cmsFloat64Number CMSEXPORT cmsCIE94DeltaE(const cmsCIELab* Lab1, const cmsCIELab
 
     dC  = fabs(LCh1.C - LCh2.C);
     dE  = cmsDeltaE(Lab1, Lab2);
-    
+
     dhsq = Sqr(dE) - Sqr(dL) - Sqr(dC);
     if (dhsq < 0)
         dh = 0;
@@ -463,7 +463,7 @@ cmsFloat64Number CMSEXPORT cmsCIE94DeltaE(const cmsCIELab* Lab1, const cmsCIELab
 
     sc = 1.0 + (0.048 * c12);
     sh = 1.0 + (0.014 * c12);
-            
+
     return sqrt(Sqr(dL)  + Sqr(dC) / Sqr(sc) + Sqr(dh) / Sqr(sh));
 }
 
@@ -513,7 +513,7 @@ cmsFloat64Number CMSEXPORT cmsBFDdeltaE(const cmsCIELab* Lab1, const cmsCIELab*
 
     dc   = 0.035 * AveC / (1 + 0.00365 * AveC)+0.521;
     g    = sqrt(Sqr(Sqr(AveC))/(Sqr(Sqr(AveC))+14000));
-    t    = 0.627+(0.055*cos((Aveh-254)/(180/M_PI))-       
+    t    = 0.627+(0.055*cos((Aveh-254)/(180/M_PI))-
            0.040*cos((2*Aveh-136)/(180/M_PI))+
            0.070*cos((3*Aveh-31)/(180/M_PI))+
            0.049*cos((4*Aveh+114)/(180/M_PI))-
@@ -546,27 +546,27 @@ cmsFloat64Number CMSEXPORT cmsCMCdeltaE(const cmsCIELab* Lab1, const cmsCIELab*
   cmsLab2LCh(&LCh1, Lab1);
   cmsLab2LCh(&LCh2, Lab2);
 
-  
+
   dL = Lab2->L-Lab1->L;
   dC = LCh2.C-LCh1.C;
 
   dE = cmsDeltaE(Lab1, Lab2);
 
-  if (Sqr(dE)>(Sqr(dL)+Sqr(dC))) 
+  if (Sqr(dE)>(Sqr(dL)+Sqr(dC)))
             dh = sqrt(Sqr(dE)-Sqr(dL)-Sqr(dC));
   else
             dh =0;
 
-  if ((LCh1.h > 164) && (LCh1.h < 345)) 
+  if ((LCh1.h > 164) && (LCh1.h < 345))
       t = 0.56 + fabs(0.2 * cos(((LCh1.h + 168)/(180/M_PI))));
-  else 
+  else
       t = 0.36 + fabs(0.4 * cos(((LCh1.h + 35 )/(180/M_PI))));
 
    sc  = 0.0638   * LCh1.C / (1 + 0.0131  * LCh1.C) + 0.638;
    sl  = 0.040975 * Lab1->L /(1 + 0.01765 * Lab1->L);
-   
+
    if (Lab1->L<16)
-         sl = 0.511; 
+         sl = 0.511;
 
    f   = sqrt((LCh1.C * LCh1.C * LCh1.C * LCh1.C)/((LCh1.C * LCh1.C * LCh1.C * LCh1.C)+1900));
    sh  = sc*(t*f+1-f);
@@ -575,7 +575,7 @@ cmsFloat64Number CMSEXPORT cmsCMCdeltaE(const cmsCIELab* Lab1, const cmsCIELab*
    return cmc;
 }
 
-// dE2000 The weightings KL, KC and KH can be modified to reflect the relative 
+// dE2000 The weightings KL, KC and KH can be modified to reflect the relative
 // importance of lightness, chroma and hue in different industrial applications
 cmsFloat64Number CMSEXPORT cmsCIE2000DeltaE(const cmsCIELab* Lab1, const cmsCIELab* Lab2,
                                   cmsFloat64Number Kl, cmsFloat64Number Kc, cmsFloat64Number Kh)
@@ -595,25 +595,25 @@ cmsFloat64Number CMSEXPORT cmsCIE2000DeltaE(const cmsCIELab* Lab1, const cmsCIEL
     cmsFloat64Number a_p = (1 + G ) * a1;
     cmsFloat64Number b_p = b1;
     cmsFloat64Number C_p = sqrt( Sqr(a_p) + Sqr(b_p));
-    cmsFloat64Number h_p = atan2deg(b_p, a_p); 
-                
+    cmsFloat64Number h_p = atan2deg(b_p, a_p);
+
 
     cmsFloat64Number a_ps = (1 + G) * as;
     cmsFloat64Number b_ps = bs;
     cmsFloat64Number C_ps = sqrt(Sqr(a_ps) + Sqr(b_ps));
     cmsFloat64Number h_ps = atan2deg(b_ps, a_ps);
-              
+
     cmsFloat64Number meanC_p =(C_p + C_ps) / 2;
 
     cmsFloat64Number hps_plus_hp  = h_ps + h_p;
     cmsFloat64Number hps_minus_hp = h_ps - h_p;
 
-    cmsFloat64Number meanh_p = fabs(hps_minus_hp) <= 180.000001 ? (hps_plus_hp)/2 : 
-                            (hps_plus_hp) < 360 ? (hps_plus_hp + 360)/2 : 
+    cmsFloat64Number meanh_p = fabs(hps_minus_hp) <= 180.000001 ? (hps_plus_hp)/2 :
+                            (hps_plus_hp) < 360 ? (hps_plus_hp + 360)/2 :
                                                  (hps_plus_hp - 360)/2;
 
     cmsFloat64Number delta_h = (hps_minus_hp) <= -180.000001 ?  (hps_minus_hp + 360) :
-                            (hps_minus_hp) > 180 ? (hps_minus_hp - 360) : 
+                            (hps_minus_hp) > 180 ? (hps_minus_hp - 360) :
                                                     (hps_minus_hp);
     cmsFloat64Number delta_L = (Ls - L1);
     cmsFloat64Number delta_C = (C_ps - C_p );
@@ -621,9 +621,9 @@ cmsFloat64Number CMSEXPORT cmsCIE2000DeltaE(const cmsCIELab* Lab1, const cmsCIEL
 
     cmsFloat64Number delta_H =2 * sqrt(C_ps*C_p) * sin(RADIANS(delta_h) / 2);
 
-    cmsFloat64Number T = 1 - 0.17 * cos(RADIANS(meanh_p-30)) 
-                 + 0.24 * cos(RADIANS(2*meanh_p))  
-                 + 0.32 * cos(RADIANS(3*meanh_p + 6)) 
+    cmsFloat64Number T = 1 - 0.17 * cos(RADIANS(meanh_p-30))
+                 + 0.24 * cos(RADIANS(2*meanh_p))
+                 + 0.32 * cos(RADIANS(3*meanh_p + 6))
                  - 0.2  * cos(RADIANS(4*meanh_p - 63));
 
     cmsFloat64Number Sl = 1 + (0.015 * Sqr((Ls + L1) /2- 50) )/ sqrt(20 + Sqr( (Ls+L1)/2 - 50) );
@@ -637,9 +637,9 @@ cmsFloat64Number CMSEXPORT cmsCIE2000DeltaE(const cmsCIELab* Lab1, const cmsCIEL
 
     cmsFloat64Number Rt = -sin(2 * RADIANS(delta_ro)) * Rc;
 
-    cmsFloat64Number deltaE00 = sqrt( Sqr(delta_L /(Sl * Kl)) + 
-                            Sqr(delta_C/(Sc * Kc))  + 
-                            Sqr(delta_H/(Sh * Kh))  + 
+    cmsFloat64Number deltaE00 = sqrt( Sqr(delta_L /(Sl * Kl)) +
+                            Sqr(delta_C/(Sc * Kc))  +
+                            Sqr(delta_H/(Sh * Kh))  +
                             Rt*(delta_C/(Sc * Kc)) * (delta_H / (Sh * Kh)));
 
     return deltaE00;
@@ -662,41 +662,41 @@ int _cmsReasonableGridpointsByColorspace(cmsColorSpaceSignature Colorspace, cmsU
     // HighResPrecalc is maximum resolution
     if (dwFlags & cmsFLAGS_HIGHRESPRECALC) {
 
-        if (nChannels > 4) 
+        if (nChannels > 4)
                 return 7;       // 7 for Hifi
 
         if (nChannels == 4)     // 23 for CMYK
                 return 23;
-    
-        return 49;      // 49 for RGB and others        
+
+        return 49;      // 49 for RGB and others
     }
 
 
     // LowResPrecal is lower resolution
     if (dwFlags & cmsFLAGS_LOWRESPRECALC) {
-        
-        if (nChannels > 4) 
+
+        if (nChannels > 4)
                 return 6;       // 6 for more than 4 channels
 
-        if (nChannels == 1) 
+        if (nChannels == 1)
                 return 33;      // For monochrome
 
         return 17;              // 17 for remaining
     }
 
     // Default values
-    if (nChannels > 4) 
+    if (nChannels > 4)
                 return 7;       // 7 for Hifi
 
     if (nChannels == 4)
                 return 17;      // 17 for CMYK
 
-    return 33;                  // 33 for RGB   
+    return 33;                  // 33 for RGB
 }
 
 
-cmsBool  _cmsEndPointsBySpace(cmsColorSpaceSignature Space, 
-                             cmsUInt16Number **White, 
+cmsBool  _cmsEndPointsBySpace(cmsColorSpaceSignature Space,
+                             cmsUInt16Number **White,
                              cmsUInt16Number **Black,
                              cmsUInt32Number *nOutputs)
 {
@@ -719,7 +719,7 @@ cmsBool  _cmsEndPointsBySpace(cmsColorSpaceSignature Space,
                            if (Black)    *Black = Grayblack;
                            if (nOutputs) *nOutputs = 1;
                            return TRUE;
-                        
+
        case cmsSigRgbData:  if (White)    *White = RGBwhite;
                            if (Black)    *Black = RGBblack;
                            if (nOutputs) *nOutputs = 3;
@@ -746,7 +746,7 @@ cmsBool  _cmsEndPointsBySpace(cmsColorSpaceSignature Space,
   return FALSE;
 }
 
-   
+
 
 // Several utilities -------------------------------------------------------
 
@@ -799,9 +799,9 @@ cmsColorSpaceSignature CMSEXPORT _cmsICCcolorSpace(int OurNotation)
 
 
 int CMSEXPORT _cmsLCMScolorSpace(cmsColorSpaceSignature ProfileSpace)
-{    
+{
     switch (ProfileSpace) {
-        
+
     case cmsSigGrayData: return  PT_GRAY;
     case cmsSigRgbData:  return  PT_RGB;
     case cmsSigCmyData:  return  PT_CMY;
@@ -814,52 +814,52 @@ int CMSEXPORT _cmsLCMScolorSpace(cmsColorSpaceSignature ProfileSpace)
     case cmsSigHsvData:  return  PT_HSV;
     case cmsSigHlsData:  return  PT_HLS;
     case cmsSigYxyData:  return  PT_Yxy;
-    
+
     case cmsSig1colorData:
     case cmsSigMCH1Data: return PT_MCH1;
-    
+
     case cmsSig2colorData:
     case cmsSigMCH2Data: return PT_MCH2;
-    
+
     case cmsSig3colorData:
     case cmsSigMCH3Data: return PT_MCH3;
-    
+
     case cmsSig4colorData:
     case cmsSigMCH4Data: return PT_MCH4;
-    
+
     case cmsSig5colorData:
     case cmsSigMCH5Data: return PT_MCH5;
-    
+
     case cmsSig6colorData:
     case cmsSigMCH6Data: return PT_MCH6;
-        
+
     case cmsSigMCH7Data:
     case cmsSig7colorData:return PT_MCH7;
-        
+
     case cmsSigMCH8Data:
     case cmsSig8colorData:return PT_MCH8;
-        
+
     case cmsSigMCH9Data:
     case cmsSig9colorData:return PT_MCH9;
-        
+
     case cmsSigMCHAData:
     case cmsSig10colorData:return PT_MCH10;
-        
+
     case cmsSigMCHBData:
     case cmsSig11colorData:return PT_MCH11;
-        
+
     case cmsSigMCHCData:
     case cmsSig12colorData:return PT_MCH12;
-        
+
     case cmsSigMCHDData:
     case cmsSig13colorData:return PT_MCH13;
-        
+
     case cmsSigMCHEData:
     case cmsSig14colorData:return PT_MCH14;
-        
+
     case cmsSigMCHFData:
     case cmsSig15colorData:return PT_MCH15;
-                
+
     default:  return (cmsColorSpaceSignature) (-1);
     }
 }
@@ -869,31 +869,32 @@ cmsUInt32Number CMSEXPORT cmsChannelsOf(cmsColorSpaceSignature ColorSpace)
 {
     switch (ColorSpace) {
 
+    case cmsSig1colorData:
     case cmsSigGrayData: return 1;
 
     case cmsSig2colorData:  return 2;
-        
+
     case cmsSigXYZData:
     case cmsSigLabData:
     case cmsSigLuvData:
     case cmsSigYCbCrData:
     case cmsSigYxyData:
-    case cmsSigRgbData:   
+    case cmsSigRgbData:
     case cmsSigHsvData:
     case cmsSigHlsData:
-    case cmsSigCmyData: 
+    case cmsSigCmyData:
     case cmsSig3colorData:  return 3;
-                   
+
     case cmsSigLuvKData:
     case cmsSigCmykData:
     case cmsSig4colorData:  return 4;
 
     case cmsSigMCH5Data:
-    case cmsSig5colorData:  return 5;  
+    case cmsSig5colorData:  return 5;
 
-    case cmsSigMCH6Data:   
+    case cmsSigMCH6Data:
     case cmsSig6colorData:  return 6;
-        
+
     case cmsSigMCH7Data:
     case cmsSig7colorData:  return  7;
 
@@ -908,7 +909,7 @@ cmsUInt32Number CMSEXPORT cmsChannelsOf(cmsColorSpaceSignature ColorSpace)
 
     case cmsSigMCHBData:
     case cmsSig11colorData: return 11;
-    
+
     case cmsSigMCHCData:
     case cmsSig12colorData: return 12;
 
index 36925aa..a74e579 100644 (file)
@@ -3,22 +3,22 @@
 //  Little Color Management System
 //  Copyright (c) 1998-2010 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 
+// 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 
+// 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 
+// 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.
 //
 //---------------------------------------------------------------------------------
@@ -44,7 +44,7 @@ cmsUInt16Number CMSEXPORT  _cmsAdjustEndianess16(cmsUInt16Number Word)
     tmp = pByte[0];
     pByte[0] = pByte[1];
     pByte[1] = tmp;
-#endif      
+#endif
 
     return Word;
 }
@@ -76,12 +76,12 @@ cmsUInt32Number CMSEXPORT  _cmsAdjustEndianess32(cmsUInt32Number DWord)
 // 1 2 3 4 5 6 7 8
 // 8 7 6 5 4 3 2 1
 
-void CMSEXPORT  _cmsAdjustEndianess64(cmsUInt64Number* Result, cmsUInt64Number QWord)
+void CMSEXPORT  _cmsAdjustEndianess64(cmsUInt64Number* Result, cmsUInt64Number* QWord)
 {
-    
+
 #ifndef CMS_USE_BIG_ENDIAN
-    
-    cmsUInt8Number* pIn  = (cmsUInt8Number*) &QWord;
+
+    cmsUInt8Number* pIn  = (cmsUInt8Number*) QWord;
     cmsUInt8Number* pOut = (cmsUInt8Number*) Result;
 
     _cmsAssert(Result != NULL);
@@ -91,7 +91,7 @@ void CMSEXPORT  _cmsAdjustEndianess64(cmsUInt64Number* Result, cmsUInt64Number Q
     pOut[5] = pIn[2];
     pOut[4] = pIn[3];
     pOut[3] = pIn[4];
-    pOut[2] = pIn[5];   
+    pOut[2] = pIn[5];
     pOut[1] = pIn[6];
     pOut[0] = pIn[7];
 
@@ -99,7 +99,7 @@ void CMSEXPORT  _cmsAdjustEndianess64(cmsUInt64Number* Result, cmsUInt64Number Q
 
     _cmsAssert(Result != NULL);
 
-    *Result = QWord;
+    *Result = *QWord;
 #endif
 }
 
@@ -110,8 +110,8 @@ cmsBool CMSEXPORT  _cmsReadUInt8Number(cmsIOHANDLER* io, cmsUInt8Number* n)
 
     _cmsAssert(io != NULL);
 
-    if (io -> Read(io, &tmp, sizeof(cmsUInt8Number), 1) != 1) 
-            return FALSE;   
+    if (io -> Read(io, &tmp, sizeof(cmsUInt8Number), 1) != 1)
+            return FALSE;
 
     if (n != NULL) *n = tmp;
     return TRUE;
@@ -123,8 +123,8 @@ cmsBool CMSEXPORT  _cmsReadUInt16Number(cmsIOHANDLER* io, cmsUInt16Number* n)
 
     _cmsAssert(io != NULL);
 
-    if (io -> Read(io, &tmp, sizeof(cmsUInt16Number), 1) != 1) 
-            return FALSE;   
+    if (io -> Read(io, &tmp, sizeof(cmsUInt16Number), 1) != 1)
+            return FALSE;
 
     if (n != NULL) *n = _cmsAdjustEndianess16(tmp);
     return TRUE;
@@ -155,8 +155,8 @@ cmsBool CMSEXPORT  _cmsReadUInt32Number(cmsIOHANDLER* io, cmsUInt32Number* n)
 
     _cmsAssert(io != NULL);
 
-    if (io -> Read(io, &tmp, sizeof(cmsUInt32Number), 1) != 1) 
-            return FALSE;   
+    if (io -> Read(io, &tmp, sizeof(cmsUInt32Number), 1) != 1)
+            return FALSE;
 
     if (n != NULL) *n = _cmsAdjustEndianess32(tmp);
     return TRUE;
@@ -168,8 +168,8 @@ cmsBool CMSEXPORT  _cmsReadFloat32Number(cmsIOHANDLER* io, cmsFloat32Number* n)
 
     _cmsAssert(io != NULL);
 
-    if (io -> Read(io, &tmp, sizeof(cmsFloat32Number), 1) != 1) 
-            return FALSE;   
+    if (io -> Read(io, &tmp, sizeof(cmsFloat32Number), 1) != 1)
+            return FALSE;
 
     if (n != NULL) {
 
@@ -186,10 +186,10 @@ cmsBool CMSEXPORT   _cmsReadUInt64Number(cmsIOHANDLER* io, cmsUInt64Number* n)
 
     _cmsAssert(io != NULL);
 
-    if (io -> Read(io, &tmp, sizeof(cmsUInt64Number), 1) != 1) 
-            return FALSE;   
+    if (io -> Read(io, &tmp, sizeof(cmsUInt64Number), 1) != 1)
+            return FALSE;
 
-    if (n != NULL) _cmsAdjustEndianess64(n, tmp);
+    if (n != NULL) _cmsAdjustEndianess64(n, &tmp);
     return TRUE;
 }
 
@@ -200,8 +200,8 @@ cmsBool CMSEXPORT  _cmsRead15Fixed16Number(cmsIOHANDLER* io, cmsFloat64Number* n
 
     _cmsAssert(io != NULL);
 
-    if (io -> Read(io, &tmp, sizeof(cmsUInt32Number), 1) != 1) 
-            return FALSE;   
+    if (io -> Read(io, &tmp, sizeof(cmsUInt32Number), 1) != 1)
+            return FALSE;
 
     if (n != NULL) {
         *n = _cms15Fixed16toDouble(_cmsAdjustEndianess32(tmp));
@@ -250,9 +250,9 @@ cmsBool CMSEXPORT  _cmsWriteUInt8Number(cmsIOHANDLER* io, cmsUInt8Number n)
 {
     _cmsAssert(io != NULL);
 
-    if (io -> Write(io, sizeof(cmsUInt8Number), &n) != 1) 
-            return FALSE;   
-    
+    if (io -> Write(io, sizeof(cmsUInt8Number), &n) != 1)
+            return FALSE;
+
     return TRUE;
 }
 
@@ -263,9 +263,9 @@ cmsBool CMSEXPORT  _cmsWriteUInt16Number(cmsIOHANDLER* io, cmsUInt16Number n)
     _cmsAssert(io != NULL);
 
     tmp = _cmsAdjustEndianess16(n);
-    if (io -> Write(io, sizeof(cmsUInt16Number), &tmp) != 1) 
-            return FALSE;   
-    
+    if (io -> Write(io, sizeof(cmsUInt16Number), &tmp) != 1)
+            return FALSE;
+
     return TRUE;
 }
 
@@ -290,9 +290,9 @@ cmsBool CMSEXPORT  _cmsWriteUInt32Number(cmsIOHANDLER* io, cmsUInt32Number n)
     _cmsAssert(io != NULL);
 
     tmp = _cmsAdjustEndianess32(n);
-    if (io -> Write(io, sizeof(cmsUInt32Number), &tmp) != 1) 
-            return FALSE;   
-    
+    if (io -> Write(io, sizeof(cmsUInt32Number), &tmp) != 1)
+            return FALSE;
+
     return TRUE;
 }
 
@@ -305,22 +305,22 @@ cmsBool CMSEXPORT  _cmsWriteFloat32Number(cmsIOHANDLER* io, cmsFloat32Number n)
 
     tmp = *(cmsUInt32Number*) &n;
     tmp = _cmsAdjustEndianess32(tmp);
-    if (io -> Write(io, sizeof(cmsUInt32Number), &tmp) != 1) 
-            return FALSE;   
-    
+    if (io -> Write(io, sizeof(cmsUInt32Number), &tmp) != 1)
+            return FALSE;
+
     return TRUE;
 }
 
-cmsBool CMSEXPORT  _cmsWriteUInt64Number(cmsIOHANDLER* io, cmsUInt64Number n)
+cmsBool CMSEXPORT  _cmsWriteUInt64Number(cmsIOHANDLER* io, cmsUInt64Number* n)
 {
     cmsUInt64Number tmp;
 
     _cmsAssert(io != NULL);
 
     _cmsAdjustEndianess64(&tmp, n);
-    if (io -> Write(io, sizeof(cmsUInt64Number), &tmp) != 1) 
-            return FALSE;   
-    
+    if (io -> Write(io, sizeof(cmsUInt64Number), &tmp) != 1)
+            return FALSE;
+
     return TRUE;
 }
 
@@ -331,16 +331,16 @@ cmsBool CMSEXPORT  _cmsWrite15Fixed16Number(cmsIOHANDLER* io, cmsFloat64Number n
     _cmsAssert(io != NULL);
 
     tmp = _cmsAdjustEndianess32(_cmsDoubleTo15Fixed16(n));
-    if (io -> Write(io, sizeof(cmsUInt32Number), &tmp) != 1) 
-            return FALSE;   
-    
+    if (io -> Write(io, sizeof(cmsUInt32Number), &tmp) != 1)
+            return FALSE;
+
     return TRUE;
 }
 
 cmsBool CMSEXPORT  _cmsWriteXYZNumber(cmsIOHANDLER* io, const cmsCIEXYZ* XYZ)
 {
     cmsEncodedXYZNumber xyz;
-  
+
     _cmsAssert(io != NULL);
     _cmsAssert(XYZ != NULL);
 
@@ -365,7 +365,7 @@ cmsFloat64Number CMSEXPORT _cms8Fixed8toDouble(cmsUInt16Number fixed8)
 cmsUInt16Number CMSEXPORT _cmsDoubleTo8Fixed8(cmsFloat64Number val)
 {
     cmsS15Fixed16Number GammaFixed32 = _cmsDoubleTo15Fixed16(val);
-    return  (cmsUInt16Number) ((GammaFixed32 >> 8) & 0xFFFF);       
+    return  (cmsUInt16Number) ((GammaFixed32 >> 8) & 0xFFFF);
 }
 
 // from Fixed point 15.16 to double
@@ -386,13 +386,13 @@ cmsFloat64Number CMSEXPORT _cms15Fixed16toDouble(cmsS15Fixed16Number fix32)
     return sign * floater;
 }
 
-// from double to Fixed point 15.16 
+// from double to Fixed point 15.16
 cmsS15Fixed16Number CMSEXPORT _cmsDoubleTo15Fixed16(cmsFloat64Number v)
 {
     return ((cmsS15Fixed16Number) floor((v)*65536.0 + 0.5));
 }
 
-// Date/Time functions 
+// Date/Time functions
 
 void CMSEXPORT _cmsDecodeDateTimeNumber(const cmsDateTimeNumber *Source, struct tm *Dest)
 {
@@ -431,7 +431,7 @@ cmsTagTypeSignature CMSEXPORT _cmsReadTypeBase(cmsIOHANDLER* io)
 
     _cmsAssert(io != NULL);
 
-    if (io -> Read(io, &Base, sizeof(_cmsTagBase), 1) != 1) 
+    if (io -> Read(io, &Base, sizeof(_cmsTagBase), 1) != 1)
         return (cmsTagTypeSignature) 0;
 
     return (cmsTagTypeSignature) _cmsAdjustEndianess32(Base.sig);
@@ -454,7 +454,7 @@ cmsBool CMSEXPORT _cmsReadAlignment(cmsIOHANDLER* io)
     cmsUInt8Number  Buffer[4];
     cmsUInt32Number NextAligned, At;
     cmsUInt32Number BytesToNextAlignedPos;
-    
+
     _cmsAssert(io != NULL);
 
     At = io -> Tell(io);
@@ -502,7 +502,7 @@ cmsBool CMSEXPORT _cmsIOPrintf(cmsIOHANDLER* io, const char* frm, ...)
     if (len < 0) return FALSE;   // Truncated, which is a fatal error for us
 
     rc = io ->Write(io, len, Buffer);
-    
+
     va_end(args);
 
     return rc;
@@ -528,8 +528,8 @@ cmsBool CMSEXPORT cmsPlugin(void* Plug_in)
 {
     cmsPluginBase* Plugin;
 
-    for (Plugin = (cmsPluginBase*) Plug_in; 
-         Plugin != NULL; 
+    for (Plugin = (cmsPluginBase*) Plug_in;
+         Plugin != NULL;
          Plugin = Plugin -> Next) {
 
             if (Plugin -> Magic != cmsPluginMagicNumber) {
@@ -538,7 +538,7 @@ cmsBool CMSEXPORT cmsPlugin(void* Plug_in)
             }
 
             if (Plugin ->ExpectedVersion > LCMS_VERSION) {
-                cmsSignalError(0, cmsERROR_UNKNOWN_EXTENSION, "plugin needs Little CMS %d, current  version is %d", 
+                cmsSignalError(0, cmsERROR_UNKNOWN_EXTENSION, "plugin needs Little CMS %d, current  version is %d",
                     Plugin ->ExpectedVersion, LCMS_VERSION);
                 return FALSE;
             }
@@ -552,11 +552,11 @@ cmsBool CMSEXPORT cmsPlugin(void* Plug_in)
                 case cmsPluginInterpolationSig:
                     if (!_cmsRegisterInterpPlugin(Plugin)) return FALSE;
                     break;
-                
+
                 case cmsPluginTagTypeSig:
                     if (!_cmsRegisterTagTypePlugin(Plugin)) return FALSE;
                     break;
-            
+
                 case cmsPluginTagSig:
                     if (!_cmsRegisterTagPlugin(Plugin)) return FALSE;
                     break;
@@ -581,10 +581,14 @@ cmsBool CMSEXPORT cmsPlugin(void* Plug_in)
                     if (!_cmsRegisterOptimizationPlugin(Plugin)) return FALSE;
                     break;
 
+                case cmsPluginTransformSig:
+                    if (!_cmsRegisterTransformPlugin(Plugin)) return FALSE;
+                    break;
+
                 default:
                     cmsSignalError(0, cmsERROR_UNKNOWN_EXTENSION, "Unrecognized plugin type '%X'", Plugin -> Type);
                     return FALSE;
-            }            
+            }
     }
 
     // Keep a reference to the plug-in
@@ -604,6 +608,7 @@ void CMSEXPORT cmsUnregisterPlugins(void)
     _cmsRegisterParametricCurvesPlugin(NULL);
     _cmsRegisterMultiProcessElementPlugin(NULL);
     _cmsRegisterOptimizationPlugin(NULL);
+    _cmsRegisterTransformPlugin(NULL);
 
     if (PluginPool != NULL)
         _cmsSubAllocDestroy(PluginPool);
index 6b0a73c..1792129 100644 (file)
@@ -3,22 +3,22 @@
 //  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 
+// 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 
+// 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 
+// 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.
 //
 //---------------------------------------------------------------------------------
@@ -26,7 +26,7 @@
 
 #include "lcms2_internal.h"
 
-// PostScript ColorRenderingDictionary and ColorSpaceArray                                                             
+// PostScript ColorRenderingDictionary and ColorSpaceArray
 
 
 #define MAXPSCOLS   60      // Columns on tables
     Implementation
     --------------
 
-  PostScript does use XYZ as its internal PCS. But since PostScript 
-  interpolation tables are limited to 8 bits, I use Lab as a way to 
-  improve the accuracy, favoring perceptual results. So, for the creation 
-  of each CRD, CSA the profiles are converted to Lab via a device 
+  PostScript does use XYZ as its internal PCS. But since PostScript
+  interpolation tables are limited to 8 bits, I use Lab as a way to
+  improve the accuracy, favoring perceptual results. So, for the creation
+  of each CRD, CSA the profiles are converted to Lab via a device
   link between  profile -> Lab or Lab -> profile. The PS code necessary to
   convert Lab <-> XYZ is also included.
 
 
 
-  Color Space Arrays (CSA) 
+  Color Space Arrays (CSA)
   ==================================================================================
 
   In order to obtain precision, code chooses between three ways to implement
   the device -> XYZ transform. These cases identifies monochrome profiles (often
   implemented as a set of curves), matrix-shaper and Pipeline-based.
 
-  Monochrome 
+  Monochrome
   -----------
 
-  This is implemented as /CIEBasedA CSA. The prelinearization curve is 
+  This is implemented as /CIEBasedA CSA. The prelinearization curve is
   placed into /DecodeA section, and matrix equals to D50. Since here is
   no interpolation tables, I do the conversion directly to XYZ
 
   flag is forced on such profiles.
 
     [ /CIEBasedA
-      <<            
+      <<
             /DecodeA { transfer function } bind
-            /MatrixA [D50]  
+            /MatrixA [D50]
             /RangeLMN [ 0.0 cmsD50X 0.0 cmsD50Y 0.0 cmsD50Z ]
             /WhitePoint [D50]
             /BlackPoint [BP]
             /RenderingIntent (intent)
       >>
-    ] 
+    ]
 
    On simpler profiles, the PCS is already XYZ, so no conversion is required.
 
+
    Matrix-shaper based
    -------------------
 
    This is implemented both with /CIEBasedABC or /CIEBasedDEF on dependig
-   of profile implementation. Since here there are no interpolation tables, I do 
+   of profile implementation. Since here there are no interpolation tables, I do
    the conversion directly to XYZ
 
 
@@ -94,7 +94,7 @@
                 /BlackPoint [BP]
                 /RenderingIntent (intent)
             >>
-    ] 
+    ]
 
 
     CLUT based
             /Table [ p p p [<...>]]
             /RangeABC [ 0 1 0 1 0 1]
             /DecodeABC[ <postlinearization> ]
-            /RangeLMN [ -0.236 1.254 0 1 -0.635 1.640 ] 
-               % -128/500 1+127/500 0 1  -127/200 1+128/200 
+            /RangeLMN [ -0.236 1.254 0 1 -0.635 1.640 ]
+               % -128/500 1+127/500 0 1  -127/200 1+128/200
             /MatrixABC [ 1 1 1 1 0 0 0 0 -1]
             /WhitePoint [D50]
             /BlackPoint [BP]
             /RenderingIntent (intent)
-    ] 
+    ]
 
 
   Color Rendering Dictionaries (CRD)
     /BlackPoint [BP]
     /MatrixPQR [ Bradford ]
     /RangePQR [-0.125 1.375 -0.125 1.375 -0.125 1.375 ]
-    /TransformPQR [            
+    /TransformPQR [
     {4 index 3 get div 2 index 3 get mul exch pop exch pop exch pop exch pop } bind
     {4 index 4 get div 2 index 4 get mul exch pop exch pop exch pop exch pop } bind
     {4 index 5 get div 2 index 5 get mul exch pop exch pop exch pop exch pop } bind
     /EncodeABC <...>
     /RangeABC  <.. used for  XYZ -> Lab>
     /EncodeLMN
-    /RenderTable [ p p p [<...>]]   
-    
+    /RenderTable [ p p p [<...>]]
+
     /RenderingIntent (Perceptual)
-  >> 
+  >>
   /Current exch /ColorRendering defineresource pop
 
 
   The following stages are used to convert from XYZ to Lab
-  --------------------------------------------------------  
+  --------------------------------------------------------
 
   Input is given at LMN stage on X, Y, Z
 
     { 0.824900  div dup 0.008856 le {7.787 mul 16 116 div add}{1 3 div exp} ifelse } bind
 
     ]
-    
-      
+
+
   MatrixABC is used to compute f(Y/Yn), f(X/Xn) - f(Y/Yn), f(Y/Yn) - f(Z/Zn)
 
   | 0  1  0|
     { 116 mul  16 sub 100 div  } bind
     { 500 mul 128 add 255 div  } bind
     { 200 mul 128 add 255 div  } bind
-    ]   
-    
+    ]
+
   The following stages are used to convert Lab to XYZ
   ----------------------------------------------------
 
     /RangeABC [ 0 1 0 1 0 1]
     /DecodeABC [ { 100 mul 16 add 116 div } bind
                  { 255 mul 128 sub 500 div } bind
-                 { 255 mul 128 sub 200 div } bind 
+                 { 255 mul 128 sub 200 div } bind
                ]
-    
+
     /MatrixABC [ 1 1 1 1 0 0 0 0 -1]
     /DecodeLMN [
                 {dup 6 29 div ge {dup dup mul mul} {4 29 div sub 108 841 div mul} ifelse 0.964200 mul} bind
  PostScript algorithms discussion.
  =========================================================================================================
 
-  1D interpolation algorithm 
+  1D interpolation algorithm
 
 
   1D interpolation (float)
   ------------------------
-    
+
     val2 = Domain * Value;
 
     cell0 = (int) floor(val2);
     y = y0 + (y1 - y0) * rest;
 
 
-  
+
   PostScript code                   Stack
   ================================================
 
     exch                            % tab val2 cell0 val2
     ceiling cvi                     % tab val2 cell0 cell1
 
-    3 index                         % tab val2 cell0 cell1 tab  
+    3 index                         % tab val2 cell0 cell1 tab
     exch                            % tab val2 cell0 tab cell1
     get                             % tab val2 cell0 y1
 
     4 -1 roll                       % val2 cell0 y1 tab
-    3 -1 roll                       % val2 y1 tab cell0 
-    get                             % val2 y1 y0 
+    3 -1 roll                       % val2 y1 tab cell0
+    get                             % val2 y1 y0
 
     dup                             % val2 y1 y0 y0
-    3 1 roll                        % val2 y0 y1 y0 
+    3 1 roll                        % val2 y0 y1 y0
 
     sub                             % val2 y0 (y1-y0)
     3 -1 roll                       % y0 (y1-y0) val2
     dup                             % y0 (y1-y0) val2 val2
-    floor cvi                       % y0 (y1-y0) val2 floor(val2) 
+    floor cvi                       % y0 (y1-y0) val2 floor(val2)
     sub                             % y0 (y1-y0) rest
     mul                             % y0 t1
     add                             % y
@@ -271,13 +271,13 @@ typedef struct {
 
     int FirstComponent;
     int SecondComponent;
-    
+
     const char* PreMaj;
     const char* PostMaj;
     const char* PreMin;
     const char* PostMin;
 
-    int  FixWhite;    // Force mapping of pure white 
+    int  FixWhite;    // Force mapping of pure white
 
     cmsColorSpaceSignature  ColorSpace;  // ColorSpace of profile
 
@@ -299,7 +299,7 @@ cmsUInt8Number Word2Byte(cmsUInt16Number w)
 /*
 static
 cmsUInt8Number L2Byte(cmsUInt16Number w)
-{    
+{
     int ww = w + 0x0080;
 
     if (ww > 0xFFFF) return 0xFF;
@@ -313,21 +313,21 @@ cmsUInt8Number L2Byte(cmsUInt16Number w)
 static
 void WriteByte(cmsIOHANDLER* m, cmsUInt8Number b)
 {
-    _cmsIOPrintf(m, "%02x", b); 
+    _cmsIOPrintf(m, "%02x", b);
     _cmsPSActualColumn += 2;
 
     if (_cmsPSActualColumn > MAXPSCOLS) {
 
         _cmsIOPrintf(m, "\n");
         _cmsPSActualColumn = 0;
-    }   
+    }
 }
 
 // ----------------------------------------------------------------- PostScript generation
 
 
 // Removes offending Carriage returns
-static 
+static
 char* RemoveCR(const char* txt)
 {
     static char Buffer[2048];
@@ -348,9 +348,9 @@ void EmitHeader(cmsIOHANDLER* m, const char* Title, cmsHPROFILE hProfile)
     time_t timer;
     cmsMLU *Description, *Copyright;
     char DescASCII[256], CopyrightASCII[256];
-    
+
     time(&timer);
-    
+
     Description = (cmsMLU*) cmsReadTag(hProfile, cmsSigProfileDescriptionTag);
     Copyright   = (cmsMLU*) cmsReadTag(hProfile, cmsSigCopyrightTag);
 
@@ -372,8 +372,8 @@ void EmitHeader(cmsIOHANDLER* m, const char* Title, cmsHPROFILE hProfile)
 }
 
 
-// Emits White & Black point. White point is always D50, Black point is the device 
-// Black point adapted to D50. 
+// Emits White & Black point. White point is always D50, Black point is the device
+// Black point adapted to D50.
 
 static
 void EmitWhiteBlackD50(cmsIOHANDLER* m, cmsCIEXYZ* BlackPoint)
@@ -383,7 +383,7 @@ void EmitWhiteBlackD50(cmsIOHANDLER* m, cmsCIEXYZ* BlackPoint)
                                           BlackPoint -> Y,
                                           BlackPoint -> Z);
 
-    _cmsIOPrintf(m, "/WhitePoint [%f %f %f]\n", cmsD50_XYZ()->X, 
+    _cmsIOPrintf(m, "/WhitePoint [%f %f %f]\n", cmsD50_XYZ()->X,
                                           cmsD50_XYZ()->Y,
                                           cmsD50_XYZ()->Z);
 }
@@ -414,7 +414,7 @@ void EmitIntent(cmsIOHANDLER* m, int RenderingIntent)
         default: intent = "Undefined"; break;
     }
 
-    _cmsIOPrintf(m, "/RenderingIntent (%s)\n", intent );    
+    _cmsIOPrintf(m, "/RenderingIntent (%s)\n", intent );
 }
 
 //
@@ -428,13 +428,13 @@ void EmitIntent(cmsIOHANDLER* m, int RenderingIntent)
 static
 void EmitL2Y(cmsIOHANDLER* m)
 {
-    _cmsIOPrintf(m, 
-            "{ " 
+    _cmsIOPrintf(m,
+            "{ "
                 "100 mul 16 add 116 div "               // (L * 100 + 16) / 116
-                 "dup 6 29 div ge "                     // >= 6 / 29 ?          
+                 "dup 6 29 div ge "                     // >= 6 / 29 ?
                  "{ dup dup mul mul } "                 // yes, ^3 and done
                  "{ 4 29 div sub 108 841 div mul } "    // no, slope limiting
-            "ifelse } bind "); 
+            "ifelse } bind ");
 }
 */
 
@@ -451,7 +451,7 @@ void EmitLab2XYZ(cmsIOHANDLER* m)
     _cmsIOPrintf(m, "{255 mul 128 sub 200 div } bind\n");
     _cmsIOPrintf(m, "]\n");
     _cmsIOPrintf(m, "/MatrixABC [ 1 1 1 1 0 0 0 0 -1]\n");
-    _cmsIOPrintf(m, "/RangeLMN [ -0.236 1.254 0 1 -0.635 1.640 ]\n"); 
+    _cmsIOPrintf(m, "/RangeLMN [ -0.236 1.254 0 1 -0.635 1.640 ]\n");
     _cmsIOPrintf(m, "/DecodeLMN [\n");
     _cmsIOPrintf(m, "{dup 6 29 div ge {dup dup mul mul} {4 29 div sub 108 841 div mul} ifelse 0.964200 mul} bind\n");
     _cmsIOPrintf(m, "{dup 6 29 div ge {dup dup mul mul} {4 29 div sub 108 841 div mul} ifelse } bind\n");
@@ -487,7 +487,7 @@ void Emit1Gamma(cmsIOHANDLER* m, cmsToneCurve* Table)
 
     // Bounds check
     EmitRangeCheck(m);
-    
+
     // Emit intepolation code
 
     // PostScript code                      Stack
@@ -501,7 +501,7 @@ void Emit1Gamma(cmsIOHANDLER* m, cmsToneCurve* Table)
 
     _cmsIOPrintf(m, "] ");                        // v tab
 
-    _cmsIOPrintf(m, "dup ");                      // v tab tab        
+    _cmsIOPrintf(m, "dup ");                      // v tab tab
     _cmsIOPrintf(m, "length 1 sub ");             // v tab dom
     _cmsIOPrintf(m, "3 -1 roll ");                // tab dom v
     _cmsIOPrintf(m, "mul ");                      // tab val2
@@ -510,18 +510,18 @@ void Emit1Gamma(cmsIOHANDLER* m, cmsToneCurve* Table)
     _cmsIOPrintf(m, "floor cvi ");                // tab val2 val2 cell0
     _cmsIOPrintf(m, "exch ");                     // tab val2 cell0 val2
     _cmsIOPrintf(m, "ceiling cvi ");              // tab val2 cell0 cell1
-    _cmsIOPrintf(m, "3 index ");                  // tab val2 cell0 cell1 tab 
+    _cmsIOPrintf(m, "3 index ");                  // tab val2 cell0 cell1 tab
     _cmsIOPrintf(m, "exch ");                     // tab val2 cell0 tab cell1
     _cmsIOPrintf(m, "get ");                      // tab val2 cell0 y1
     _cmsIOPrintf(m, "4 -1 roll ");                // val2 cell0 y1 tab
-    _cmsIOPrintf(m, "3 -1 roll ");                // val2 y1 tab cell0 
-    _cmsIOPrintf(m, "get ");                      // val2 y1 y0 
+    _cmsIOPrintf(m, "3 -1 roll ");                // val2 y1 tab cell0
+    _cmsIOPrintf(m, "get ");                      // val2 y1 y0
     _cmsIOPrintf(m, "dup ");                      // val2 y1 y0 y0
-    _cmsIOPrintf(m, "3 1 roll ");                 // val2 y0 y1 y0 
+    _cmsIOPrintf(m, "3 1 roll ");                 // val2 y0 y1 y0
     _cmsIOPrintf(m, "sub ");                      // val2 y0 (y1-y0)
     _cmsIOPrintf(m, "3 -1 roll ");                // y0 (y1-y0) val2
     _cmsIOPrintf(m, "dup ");                      // y0 (y1-y0) val2 val2
-    _cmsIOPrintf(m, "floor cvi ");                // y0 (y1-y0) val2 floor(val2) 
+    _cmsIOPrintf(m, "floor cvi ");                // y0 (y1-y0) val2 floor(val2)
     _cmsIOPrintf(m, "sub ");                      // y0 (y1-y0) rest
     _cmsIOPrintf(m, "mul ");                      // y0 t1
     _cmsIOPrintf(m, "add ");                      // y
@@ -535,7 +535,7 @@ void Emit1Gamma(cmsIOHANDLER* m, cmsToneCurve* Table)
 
 static
 cmsBool GammaTableEquals(cmsUInt16Number* g1, cmsUInt16Number* g2, int nEntries)
-{    
+{
     return memcmp(g1, g2, nEntries* sizeof(cmsUInt16Number)) == 0;
 }
 
@@ -543,23 +543,23 @@ cmsBool GammaTableEquals(cmsUInt16Number* g1, cmsUInt16Number* g2, int nEntries)
 // Does write a set of gamma curves
 
 static
-void EmitNGamma(cmsIOHANDLER* m, int n, cmsToneCurve* g[])                  
+void EmitNGamma(cmsIOHANDLER* m, int n, cmsToneCurve* g[])
 {
     int i;
-    
+
     for( i=0; i < n; i++ )
-    {     
+    {
         if (g[i] == NULL) return; // Error
 
         if (i > 0 && GammaTableEquals(g[i-1]->Table16, g[i]->Table16, g[i]->nEntries)) {
 
             _cmsIOPrintf(m, "dup ");
         }
-        else {    
+        else {
             Emit1Gamma(m, g[i]);
         }
     }
-    
+
 }
 
 
@@ -567,7 +567,7 @@ void EmitNGamma(cmsIOHANDLER* m, int n, cmsToneCurve* g[])
 
 
 // Following code dumps a LUT onto memory stream
-        
+
 
 // This is the sampler. Intended to work in SAMPLER_INSPECT mode,
 // that is, the callback will be called for each knot with
@@ -577,8 +577,8 @@ void EmitNGamma(cmsIOHANDLER* m, int n, cmsToneCurve* g[])
 //
 //  Returning a value other than 0 does terminate the sampling process
 //
-//  Each row contains Pipeline values for all but first component. So, I 
-//  detect row changing by keeping a copy of last value of first 
+//  Each row contains Pipeline values for all but first component. So, I
+//  detect row changing by keeping a copy of last value of first
 //  component. -1 is used to mark begining of whole block.
 
 static
@@ -606,7 +606,7 @@ int OutputValueSampler(register const cmsUInt16Number In[], register cmsUInt16Nu
                         Out[i] = White[i];
             }
 
-             
+
         }
     }
 
@@ -614,43 +614,43 @@ int OutputValueSampler(register const cmsUInt16Number In[], register cmsUInt16Nu
     // Hadle the parenthesis on rows
 
     if (In[0] != sc ->FirstComponent) {
-            
+
             if (sc ->FirstComponent != -1) {
 
                     _cmsIOPrintf(sc ->m, sc ->PostMin);
                     sc ->SecondComponent = -1;
-                    _cmsIOPrintf(sc ->m, sc ->PostMaj);           
+                    _cmsIOPrintf(sc ->m, sc ->PostMaj);
             }
 
-            // Begin block  
+            // Begin block
             _cmsPSActualColumn = 0;
-                    
-            _cmsIOPrintf(sc ->m, sc ->PreMaj);            
-            sc ->FirstComponent = In[0]; 
+
+            _cmsIOPrintf(sc ->m, sc ->PreMaj);
+            sc ->FirstComponent = In[0];
     }
 
 
       if (In[1] != sc ->SecondComponent) {
-            
+
             if (sc ->SecondComponent != -1) {
 
-                    _cmsIOPrintf(sc ->m, sc ->PostMin);           
+                    _cmsIOPrintf(sc ->m, sc ->PostMin);
             }
-                    
-            _cmsIOPrintf(sc ->m, sc ->PreMin);            
-            sc ->SecondComponent = In[1]; 
+
+            _cmsIOPrintf(sc ->m, sc ->PreMin);
+            sc ->SecondComponent = In[1];
     }
 
-      // Dump table. 
+      // Dump table.
 
       for (i=0; i < sc -> Pipeline ->Params->nOutputs; i++) {
 
           cmsUInt16Number wWordOut = Out[i];
           cmsUInt8Number wByteOut;           // Value as byte
-         
+
 
           // We always deal with Lab4
-          
+
           wByteOut = Word2Byte(wWordOut);
           WriteByte(sc -> m, wByteOut);
       }
@@ -661,10 +661,10 @@ int OutputValueSampler(register const cmsUInt16Number In[], register cmsUInt16Nu
 // Writes a Pipeline on memstream. Could be 8 or 16 bits based
 
 static
-void WriteCLUT(cmsIOHANDLER* m, cmsStage* mpe, const char* PreMaj, 
+void WriteCLUT(cmsIOHANDLER* m, cmsStage* mpe, const char* PreMaj,
                                              const char* PostMaj,
                                              const char* PreMin,
-                                             const char* PostMin,                                             
+                                             const char* PostMin,
                                              int FixWhite,
                                              cmsColorSpaceSignature ColorSpace)
 {
@@ -674,12 +674,12 @@ void WriteCLUT(cmsIOHANDLER* m, cmsStage* mpe, const char* PreMaj,
     sc.FirstComponent = -1;
     sc.SecondComponent = -1;
     sc.Pipeline = (_cmsStageCLutData *) mpe ->Data;
-    sc.m   = m;    
+    sc.m   = m;
     sc.PreMaj = PreMaj;
     sc.PostMaj= PostMaj;
 
     sc.PreMin   = PreMin;
-    sc.PostMin  = PostMin;    
+    sc.PostMin  = PostMin;
     sc.FixWhite = FixWhite;
     sc.ColorSpace = ColorSpace;
 
@@ -691,7 +691,7 @@ void WriteCLUT(cmsIOHANDLER* m, cmsStage* mpe, const char* PreMaj,
     _cmsIOPrintf(m, " [\n");
 
     cmsStageSampleCLut16bit(mpe, OutputValueSampler, (void*) &sc, SAMPLER_INSPECT);
-    
+
     _cmsIOPrintf(m, PostMin);
     _cmsIOPrintf(m, PostMaj);
     _cmsIOPrintf(m, "] ");
@@ -720,7 +720,7 @@ int EmitCIEBasedA(cmsIOHANDLER* m, cmsToneCurve* Curve, cmsCIEXYZ* BlackPoint)
     EmitWhiteBlackD50(m, BlackPoint);
     EmitIntent(m, INTENT_PERCEPTUAL);
 
-    _cmsIOPrintf(m, ">>\n");        
+    _cmsIOPrintf(m, ">>\n");
     _cmsIOPrintf(m, "]\n");
 
     return 1;
@@ -733,7 +733,7 @@ static
 int EmitCIEBasedABC(cmsIOHANDLER* m, cmsFloat64Number* Matrix, cmsToneCurve** CurveSet, cmsCIEXYZ* BlackPoint)
 {
     int i;
-    
+
     _cmsIOPrintf(m, "[ /CIEBasedABC\n");
     _cmsIOPrintf(m, "<<\n");
     _cmsIOPrintf(m, "/DecodeABC [ ");
@@ -748,7 +748,7 @@ int EmitCIEBasedABC(cmsIOHANDLER* m, cmsFloat64Number* Matrix, cmsToneCurve** Cu
 
         _cmsIOPrintf(m, "%.6f %.6f %.6f ", Matrix[i + 3*0],
                                            Matrix[i + 3*1],
-                                           Matrix[i + 3*2]);      
+                                           Matrix[i + 3*2]);
     }
 
 
@@ -782,7 +782,7 @@ int EmitCIEBasedDEF(cmsIOHANDLER* m, cmsPipeline* Pipeline, int Intent, cmsCIEXY
     case 3:
 
             _cmsIOPrintf(m, "[ /CIEBasedDEF\n");
-            PreMaj ="<"; 
+            PreMaj ="<";
             PostMaj= ">\n";
             PreMin = PostMin = "";
             break;
@@ -801,7 +801,7 @@ int EmitCIEBasedDEF(cmsIOHANDLER* m, cmsPipeline* Pipeline, int Intent, cmsCIEXY
     _cmsIOPrintf(m, "<<\n");
 
     if (cmsStageType(mpe) == cmsSigCurveSetElemType) {
-            
+
         _cmsIOPrintf(m, "/DecodeDEF [ ");
         EmitNGamma(m, cmsStageOutputChannels(mpe), _cmsStageGetPtrToCurveSet(mpe));
         _cmsIOPrintf(m, "]\n");
@@ -813,18 +813,18 @@ int EmitCIEBasedDEF(cmsIOHANDLER* m, cmsPipeline* Pipeline, int Intent, cmsCIEXY
 
     if (cmsStageType(mpe) == cmsSigCLutElemType) {
 
-            _cmsIOPrintf(m, "/Table ");    
+            _cmsIOPrintf(m, "/Table ");
             WriteCLUT(m, mpe, PreMaj, PostMaj, PreMin, PostMin, FALSE, (cmsColorSpaceSignature) 0);
             _cmsIOPrintf(m, "]\n");
     }
-       
+
     EmitLab2XYZ(m);
     EmitWhiteBlackD50(m, BlackPoint);
     EmitIntent(m, Intent);
 
-    _cmsIOPrintf(m, "   >>\n");       
+    _cmsIOPrintf(m, "   >>\n");
     _cmsIOPrintf(m, "]\n");
-    
+
 
     return 1;
 }
@@ -872,16 +872,16 @@ int WriteInputLUT(cmsIOHANDLER* m, cmsHPROFILE hProfile, int Intent, cmsUInt32Nu
     cmsHPROFILE Profiles[2];
     cmsCIEXYZ BlackPointAdaptedToD50;
 
-    // Does create a device-link based transform. 
+    // Does create a device-link based transform.
     // The DeviceLink is next dumped as working CSA.
-    
+
     InputFormat = cmsFormatterForColorspaceOfProfile(hProfile, 2, FALSE);
     nChannels   = T_CHANNELS(InputFormat);
 
-    
+
     cmsDetectBlackPoint(&BlackPointAdaptedToD50, hProfile, Intent, 0);
 
-    // Adjust output to Lab4 
+    // Adjust output to Lab4
     hLab = cmsCreateLab4ProfileTHR(m ->ContextID, NULL);
 
     Profiles[0] = hProfile;
@@ -889,25 +889,25 @@ int WriteInputLUT(cmsIOHANDLER* m, cmsHPROFILE hProfile, int Intent, cmsUInt32Nu
 
     xform = cmsCreateMultiprofileTransform(Profiles, 2,  InputFormat, TYPE_Lab_DBL, Intent, 0);
     cmsCloseProfile(hLab);
-    
+
     if (xform == NULL) {
 
         cmsSignalError(m ->ContextID, cmsERROR_COLORSPACE_CHECK, "Cannot create transform Profile -> Lab");
         return 0;
     }
-    
+
     // Only 1, 3 and 4 channels are allowed
 
     switch (nChannels) {
 
-    case 1: {            
+    case 1: {
             cmsToneCurve* Gray2Y = ExtractGray2Y(m ->ContextID, hProfile, Intent);
-            EmitCIEBasedA(m, Gray2Y, &BlackPointAdaptedToD50);            
-            cmsFreeToneCurve(Gray2Y);            
+            EmitCIEBasedA(m, Gray2Y, &BlackPointAdaptedToD50);
+            cmsFreeToneCurve(Gray2Y);
             }
             break;
 
-    case 3: 
+    case 3:
     case 4: {
             cmsUInt32Number OutFrm = TYPE_Lab_16;
             cmsPipeline* DeviceLink;
@@ -918,9 +918,9 @@ int WriteInputLUT(cmsIOHANDLER* m, cmsHPROFILE hProfile, int Intent, cmsUInt32Nu
 
             dwFlags |= cmsFLAGS_FORCE_CLUT;
             _cmsOptimizePipeline(&DeviceLink, Intent, &InputFormat, &OutFrm, &dwFlags);
-            
+
             rc = EmitCIEBasedDEF(m, DeviceLink, Intent, &BlackPointAdaptedToD50);
-            cmsPipelineFree(DeviceLink);            
+            cmsPipelineFree(DeviceLink);
             }
             break;
 
@@ -929,10 +929,10 @@ int WriteInputLUT(cmsIOHANDLER* m, cmsHPROFILE hProfile, int Intent, cmsUInt32Nu
         cmsSignalError(m ->ContextID, cmsERROR_COLORSPACE_CHECK, "Only 3, 4 channels supported for CSA. This profile has %d channels.", nChannels);
         return 0;
     }
-    
+
 
     cmsDeleteTransform(xform);
-    
+
     return 1;
 }
 
@@ -948,9 +948,9 @@ cmsFloat64Number* GetPtrToMatrix(const cmsStage* mpe)
 // Does create CSA based on matrix-shaper. Allowed types are gray and RGB based
 
 static
-    int WriteInputMatrixShaper(cmsIOHANDLER* m, cmsHPROFILE hProfile, cmsStage* Matrix, cmsStage* Shaper)
+int WriteInputMatrixShaper(cmsIOHANDLER* m, cmsHPROFILE hProfile, cmsStage* Matrix, cmsStage* Shaper)
 {
-    cmsColorSpaceSignature ColorSpace;    
+    cmsColorSpaceSignature ColorSpace;
     int rc;
     cmsCIEXYZ BlackPointAdaptedToD50;
 
@@ -976,9 +976,9 @@ static
                 for (j=0; j < 3; j++)
                     Mat.v[i].n[j] *= MAX_ENCODEABLE_XYZ;
 
-            rc = EmitCIEBasedABC(m,  (cmsFloat64Number *) &Mat, 
-                                _cmsStageGetPtrToCurveSet(Shaper), 
-                                 &BlackPointAdaptedToD50);      
+            rc = EmitCIEBasedABC(m,  (cmsFloat64Number *) &Mat,
+                                _cmsStageGetPtrToCurveSet(Shaper),
+                                 &BlackPointAdaptedToD50);
         }
         else  {
 
@@ -991,7 +991,7 @@ static
 
 
 
-// Creates a PostScript color list from a named profile data. 
+// Creates a PostScript color list from a named profile data.
 // This is a HP extension, and it works in Lab instead of XYZ
 
 static
@@ -1019,7 +1019,7 @@ int WriteNamedColorCSA(cmsIOHANDLER* m, cmsHPROFILE hNamedColor, int Intent)
 
 
     for (i=0; i < nColors; i++) {
-        
+
         cmsUInt16Number In[1];
         cmsCIELab Lab;
 
@@ -1028,12 +1028,12 @@ int WriteNamedColorCSA(cmsIOHANDLER* m, cmsHPROFILE hNamedColor, int Intent)
         if (!cmsNamedColorInfo(NamedColorList, i, ColorName, NULL, NULL, NULL, NULL))
                 continue;
 
-        cmsDoTransform(xform, In, &Lab, 1);     
+        cmsDoTransform(xform, In, &Lab, 1);
         _cmsIOPrintf(m, "  (%s) [ %.3f %.3f %.3f ]\n", ColorName, Lab.L, Lab.a, Lab.b);
     }
 
 
-        
+
     _cmsIOPrintf(m, ">>\n");
 
     cmsDeleteTransform(xform);
@@ -1044,12 +1044,12 @@ int WriteNamedColorCSA(cmsIOHANDLER* m, cmsHPROFILE hNamedColor, int Intent)
 
 // Does create a Color Space Array on XYZ colorspace for PostScript usage
 static
-cmsUInt32Number GenerateCSA(cmsContext ContextID, 
-                            cmsHPROFILE hProfile, 
-                            cmsUInt32Number Intent, 
-                            cmsUInt32Number dwFlags, 
+cmsUInt32Number GenerateCSA(cmsContext ContextID,
+                            cmsHPROFILE hProfile,
+                            cmsUInt32Number Intent,
+                            cmsUInt32Number dwFlags,
                             cmsIOHANDLER* mem)
-{   
+{
     cmsUInt32Number dwBytesUsed;
     cmsPipeline* lut = NULL;
     cmsStage* Matrix, *Shaper;
@@ -1104,7 +1104,7 @@ cmsUInt32Number GenerateCSA(cmsContext ContextID,
 
 Error:
     if (lut != NULL) cmsPipelineFree(lut);
-    return 0;   
+    return 0;
 }
 
 // ------------------------------------------------------ Color Rendering Dictionary (CRD)
@@ -1126,13 +1126,13 @@ Error:
   =================================
 
           (WPout - BPout)*X - WPout*(BPin - BPout)
-    out = --------------------------------------- 
+    out = ---------------------------------------
                         WPout - BPin
 
 
   Algorithm discussion
   ====================
-      
+
   TransformPQR(WPin, BPin, WPout, BPout, PQR)
 
   Wpin,etc= { Xws Yws Zws Pws Qws Rws }
@@ -1141,31 +1141,31 @@ Error:
   Algorithm             Stack 0...n
   ===========================================================
                         PQR BPout WPout BPin WPin
-  4 index 3 get         WPin PQR BPout WPout BPin WPin  
-  div                   (PQR/WPin) BPout WPout BPin WPin   
-  2 index 3 get         WPout (PQR/WPin) BPout WPout BPin WPin   
-  mult                  WPout*(PQR/WPin) BPout WPout BPin WPin   
-  
-  2 index 3 get         WPout WPout*(PQR/WPin) BPout WPout BPin WPin   
-  2 index 3 get         BPout WPout WPout*(PQR/WPin) BPout WPout BPin WPin     
-  sub                   (WPout-BPout) WPout*(PQR/WPin) BPout WPout BPin WPin    
-  mult                  (WPout-BPout)* WPout*(PQR/WPin) BPout WPout BPin WPin   
-          
-  2 index 3 get         WPout (BPout-WPout)* WPout*(PQR/WPin) BPout WPout BPin WPin     
-  4 index 3 get         BPin WPout (BPout-WPout)* WPout*(PQR/WPin) BPout WPout BPin WPin     
+  4 index 3 get         WPin PQR BPout WPout BPin WPin
+  div                   (PQR/WPin) BPout WPout BPin WPin
+  2 index 3 get         WPout (PQR/WPin) BPout WPout BPin WPin
+  mult                  WPout*(PQR/WPin) BPout WPout BPin WPin
+
+  2 index 3 get         WPout WPout*(PQR/WPin) BPout WPout BPin WPin
+  2 index 3 get         BPout WPout WPout*(PQR/WPin) BPout WPout BPin WPin
+  sub                   (WPout-BPout) WPout*(PQR/WPin) BPout WPout BPin WPin
+  mult                  (WPout-BPout)* WPout*(PQR/WPin) BPout WPout BPin WPin
+
+  2 index 3 get         WPout (BPout-WPout)* WPout*(PQR/WPin) BPout WPout BPin WPin
+  4 index 3 get         BPin WPout (BPout-WPout)* WPout*(PQR/WPin) BPout WPout BPin WPin
   3 index 3 get         BPout BPin WPout (BPout-WPout)* WPout*(PQR/WPin) BPout WPout BPin WPin
-  
-  sub                   (BPin-BPout) WPout (BPout-WPout)* WPout*(PQR/WPin) BPout WPout BPin WPin     
-  mult                  (BPin-BPout)*WPout (BPout-WPout)* WPout*(PQR/WPin) BPout WPout BPin WPin     
-  sub                   (BPout-WPout)* WPout*(PQR/WPin)-(BPin-BPout)*WPout BPout WPout BPin WPin     
 
-  3 index 3 get         BPin (BPout-WPout)* WPout*(PQR/WPin)-(BPin-BPout)*WPout BPout WPout BPin WPin     
-  3 index 3 get         WPout BPin (BPout-WPout)* WPout*(PQR/WPin)-(BPin-BPout)*WPout BPout WPout BPin WPin     
+  sub                   (BPin-BPout) WPout (BPout-WPout)* WPout*(PQR/WPin) BPout WPout BPin WPin
+  mult                  (BPin-BPout)*WPout (BPout-WPout)* WPout*(PQR/WPin) BPout WPout BPin WPin
+  sub                   (BPout-WPout)* WPout*(PQR/WPin)-(BPin-BPout)*WPout BPout WPout BPin WPin
+
+  3 index 3 get         BPin (BPout-WPout)* WPout*(PQR/WPin)-(BPin-BPout)*WPout BPout WPout BPin WPin
+  3 index 3 get         WPout BPin (BPout-WPout)* WPout*(PQR/WPin)-(BPin-BPout)*WPout BPout WPout BPin WPin
   exch
-  sub                   (WPout-BPin) (BPout-WPout)* WPout*(PQR/WPin)-(BPin-BPout)*WPout BPout WPout BPin WPin       
-  div                
-  
-  exch pop 
+  sub                   (WPout-BPin) (BPout-WPout)* WPout*(PQR/WPin)-(BPin-BPout)*WPout BPout WPout BPin WPin
+  div
+
+  exch pop
   exch pop
   exch pop
   exch pop
@@ -1177,10 +1177,10 @@ static
 void EmitPQRStage(cmsIOHANDLER* m, cmsHPROFILE hProfile, int DoBPC, int lIsAbsolute)
 {
 
-   
+
         if (lIsAbsolute) {
 
-            // For absolute colorimetric intent, encode back to relative 
+            // For absolute colorimetric intent, encode back to relative
             // and generate a relative Pipeline
 
             // Relative encoding is obtained across XYZpcs*(D50/WhitePoint)
@@ -1196,7 +1196,7 @@ void EmitPQRStage(cmsIOHANDLER* m, cmsHPROFILE hProfile, int DoBPC, int lIsAbsol
                       "/TransformPQR [\n"
                       "{0.9642 mul %g div exch pop exch pop exch pop exch pop} bind\n"
                       "{1.0000 mul %g div exch pop exch pop exch pop exch pop} bind\n"
-                      "{0.8249 mul %g div exch pop exch pop exch pop exch pop} bind\n]\n", 
+                      "{0.8249 mul %g div exch pop exch pop exch pop exch pop} bind\n]\n",
                       White.X, White.Y, White.Z);
             return;
         }
@@ -1216,16 +1216,16 @@ void EmitPQRStage(cmsIOHANDLER* m, cmsHPROFILE hProfile, int DoBPC, int lIsAbsol
                       "/TransformPQR [\n"
                       "{exch pop exch 3 get mul exch pop exch 3 get div} bind\n"
                       "{exch pop exch 4 get mul exch pop exch 4 get div} bind\n"
-                      "{exch pop exch 5 get mul exch pop exch 5 get div} bind\n]\n"); 
+                      "{exch pop exch 5 get mul exch pop exch 5 get div} bind\n]\n");
         } else {
 
             // BPC
 
             _cmsIOPrintf(m, "%% VonKries-like transform in Bradford Cone Space plus BPC\n"
                       "/TransformPQR [\n");
-                  
+
             _cmsIOPrintf(m, "{4 index 3 get div 2 index 3 get mul "
-                    "2 index 3 get 2 index 3 get sub mul "                          
+                    "2 index 3 get 2 index 3 get sub mul "
                     "2 index 3 get 4 index 3 get 3 index 3 get sub mul sub "
                     "3 index 3 get 3 index 3 get exch sub div "
                     "exch pop exch pop exch pop exch pop } bind\n");
@@ -1243,15 +1243,15 @@ void EmitPQRStage(cmsIOHANDLER* m, cmsHPROFILE hProfile, int DoBPC, int lIsAbsol
                     "exch pop exch pop exch pop exch pop } bind\n]\n");
 
         }
-          
-        
+
+
 }
 
 
 static
 void EmitXYZ2Lab(cmsIOHANDLER* m)
 {
-    _cmsIOPrintf(m, "/RangeLMN [ -0.635 2.0 0 2 -0.635 2.0 ]\n"); 
+    _cmsIOPrintf(m, "/RangeLMN [ -0.635 2.0 0 2 -0.635 2.0 ]\n");
     _cmsIOPrintf(m, "/EncodeLMN [\n");
     _cmsIOPrintf(m, "{ 0.964200  div dup 0.008856 le {7.787 mul 16 116 div add}{1 3 div exp} ifelse } bind\n");
     _cmsIOPrintf(m, "{ 1.000000  div dup 0.008856 le {7.787 mul 16 116 div add}{1 3 div exp} ifelse } bind\n");
@@ -1259,22 +1259,22 @@ void EmitXYZ2Lab(cmsIOHANDLER* m)
     _cmsIOPrintf(m, "]\n");
     _cmsIOPrintf(m, "/MatrixABC [ 0 1 0 1 -1 1 0 0 -1 ]\n");
     _cmsIOPrintf(m, "/EncodeABC [\n");
-    
-        
+
+
     _cmsIOPrintf(m, "{ 116 mul  16 sub 100 div  } bind\n");
     _cmsIOPrintf(m, "{ 500 mul 128 add 256 div  } bind\n");
     _cmsIOPrintf(m, "{ 200 mul 128 add 256 div  } bind\n");
-    
-    
+
+
     _cmsIOPrintf(m, "]\n");
-    
+
 
 }
 
 // Due to impedance mismatch between XYZ and almost all RGB and CMYK spaces
 // I choose to dump LUTS in Lab instead of XYZ. There is still a lot of wasted
 // space on 3D CLUT, but since space seems not to be a problem here, 33 points
-// would give a reasonable accurancy. Note also that CRD tables must operate in 
+// would give a reasonable accurancy. Note also that CRD tables must operate in
 // 8 bits.
 
 static
@@ -1293,8 +1293,8 @@ int WriteOutputLUT(cmsIOHANDLER* m, cmsHPROFILE hProfile, int Intent, cmsUInt32N
     cmsUInt32Number InFrm = TYPE_Lab_16;
     int RelativeEncodingIntent;
     cmsColorSpaceSignature ColorSpace;
-    
-    
+
+
     hLab = cmsCreateLab4ProfileTHR(m ->ContextID, NULL);
     if (hLab == NULL) return 0;
 
@@ -1314,13 +1314,13 @@ int WriteOutputLUT(cmsIOHANDLER* m, cmsHPROFILE hProfile, int Intent, cmsUInt32N
     Profiles[0] = hLab;
     Profiles[1] = hProfile;
 
-    xform = cmsCreateMultiprofileTransformTHR(m ->ContextID, 
-                                              Profiles, 2, TYPE_Lab_DBL, 
+    xform = cmsCreateMultiprofileTransformTHR(m ->ContextID,
+                                              Profiles, 2, TYPE_Lab_DBL,
                                               OutputFormat, RelativeEncodingIntent, 0);
     cmsCloseProfile(hLab);
 
     if (xform == NULL) {
-                        
+
         cmsSignalError(m ->ContextID, cmsERROR_COLORSPACE_CHECK, "Cannot create transform Lab -> Profile in CRD creation");
         return 0;
     }
@@ -1329,12 +1329,12 @@ int WriteOutputLUT(cmsIOHANDLER* m, cmsHPROFILE hProfile, int Intent, cmsUInt32N
     v = (_cmsTRANSFORM*) xform;
     DeviceLink = cmsPipelineDup(v ->Lut);
     if (DeviceLink == NULL) return 0;
-   
-  
+
+
     // We need a CLUT
     dwFlags |= cmsFLAGS_FORCE_CLUT;
     _cmsOptimizePipeline(&DeviceLink, RelativeEncodingIntent, &InFrm, &OutputFormat, &dwFlags);
-  
+
     _cmsIOPrintf(m, "<<\n");
     _cmsIOPrintf(m, "/ColorRenderingType 1\n");
 
@@ -1345,22 +1345,22 @@ int WriteOutputLUT(cmsIOHANDLER* m, cmsHPROFILE hProfile, int Intent, cmsUInt32N
     EmitWhiteBlackD50(m, &BlackPointAdaptedToD50);
     EmitPQRStage(m, hProfile, lDoBPC, Intent == INTENT_ABSOLUTE_COLORIMETRIC);
     EmitXYZ2Lab(m);
-        
-   
-    // FIXUP: map Lab (100, 0, 0) to perfect white, because the particular encoding for Lab 
-    // does map a=b=0 not falling into any specific node. Since range a,b goes -128..127, 
+
+
+    // FIXUP: map Lab (100, 0, 0) to perfect white, because the particular encoding for Lab
+    // does map a=b=0 not falling into any specific node. Since range a,b goes -128..127,
     // zero is slightly moved towards right, so assure next node (in L=100 slice) is mapped to
     // zero. This would sacrifice a bit of highlights, but failure to do so would cause
     // scum dot. Ouch.
-    
+
     if (Intent == INTENT_ABSOLUTE_COLORIMETRIC)
             lFixWhite = FALSE;
 
     _cmsIOPrintf(m, "/RenderTable ");
-    
-    
+
+
     WriteCLUT(m, cmsPipelineGetPtrToFirstStage(DeviceLink), "<", ">\n", "", "", lFixWhite, ColorSpace);
-    
+
     _cmsIOPrintf(m, " %d {} bind ", nChannels);
 
     for (i=1; i < nChannels; i++)
@@ -1368,7 +1368,7 @@ int WriteOutputLUT(cmsIOHANDLER* m, cmsHPROFILE hProfile, int Intent, cmsUInt32N
 
     _cmsIOPrintf(m, "]\n");
 
-        
+
     EmitIntent(m, Intent);
 
     _cmsIOPrintf(m, ">>\n");
@@ -1380,8 +1380,8 @@ int WriteOutputLUT(cmsIOHANDLER* m, cmsHPROFILE hProfile, int Intent, cmsUInt32N
 
     cmsPipelineFree(DeviceLink);
     cmsDeleteTransform(xform);
-    return 1;   
+
+    return 1;
 }
 
 
@@ -1400,31 +1400,31 @@ void BuildColorantList(char *Colorant, int nColorant, cmsUInt16Number Out[])
 
                 sprintf(Buff, "%.3f", Out[j] / 65535.0);
                 strcat(Colorant, Buff);
-                if (j < nColorant -1) 
+                if (j < nColorant -1)
                         strcat(Colorant, " ");
 
-        }       
+        }
 }
 
 
-// Creates a PostScript color list from a named profile data. 
+// Creates a PostScript color list from a named profile data.
 // This is a HP extension.
 
 static
 int WriteNamedColorCRD(cmsIOHANDLER* m, cmsHPROFILE hNamedColor, int Intent, cmsUInt32Number dwFlags)
 {
-    cmsHTRANSFORM xform;    
+    cmsHTRANSFORM xform;
     int i, nColors, nColorant;
     cmsUInt32Number OutputFormat;
     char ColorName[32];
     char Colorant[128];
     cmsNAMEDCOLORLIST* NamedColorList;
 
-    
+
     OutputFormat = cmsFormatterForColorspaceOfProfile(hNamedColor, 2, FALSE);
     nColorant    = T_CHANNELS(OutputFormat);
 
-    
+
     xform = cmsCreateTransform(hNamedColor, TYPE_NAMED_COLOR_INDEX, NULL, OutputFormat, Intent, dwFlags);
     if (xform == NULL) return 0;
 
@@ -1438,9 +1438,9 @@ int WriteNamedColorCRD(cmsIOHANDLER* m, cmsHPROFILE hNamedColor, int Intent, cms
     _cmsIOPrintf(m, "(Suffix) [ ( CV) ( CVC) ( C) ]\n");
 
     nColors   = cmsNamedColorCount(NamedColorList);
-    
+
     for (i=0; i < nColors; i++) {
-        
+
         cmsUInt16Number In[1];
         cmsUInt16Number Out[cmsMAXCHANNELS];
 
@@ -1449,7 +1449,7 @@ int WriteNamedColorCRD(cmsIOHANDLER* m, cmsHPROFILE hNamedColor, int Intent, cms
         if (!cmsNamedColorInfo(NamedColorList, i, ColorName, NULL, NULL, NULL, NULL))
                 continue;
 
-        cmsDoTransform(xform, In, Out, 1);      
+        cmsDoTransform(xform, In, Out, 1);
         BuildColorantList(Colorant, nColorant, Out);
         _cmsIOPrintf(m, "  (%s) [ %s ]\n", ColorName, Colorant);
     }
@@ -1461,22 +1461,22 @@ int WriteNamedColorCRD(cmsIOHANDLER* m, cmsHPROFILE hNamedColor, int Intent, cms
     _cmsIOPrintf(m, " /Current exch /HPSpotTable defineresource pop\n");
     }
 
-    cmsDeleteTransform(xform);  
+    cmsDeleteTransform(xform);
     return 1;
 }
 
 
 
-// This one does create a Color Rendering Dictionary. 
+// This one does create a Color Rendering Dictionary.
 // CRD are always LUT-Based, no matter if profile is
 // implemented as matrix-shaper.
 
 static
 cmsUInt32Number  GenerateCRD(cmsContext ContextID,
-                             cmsHPROFILE hProfile, 
+                             cmsHPROFILE hProfile,
                              cmsUInt32Number Intent, cmsUInt32Number dwFlags,
                              cmsIOHANDLER* mem)
-{    
+{
     cmsUInt32Number dwBytesUsed;
 
     if (!(dwFlags & cmsFLAGS_NODEFAULTRESOURCEDEF)) {
@@ -1494,7 +1494,7 @@ cmsUInt32Number  GenerateCRD(cmsContext ContextID,
     }
     else {
 
-        // CRD are always implemented as LUT 
+        // CRD are always implemented as LUT
 
         if (!WriteOutputLUT(mem, hProfile, Intent, dwFlags)) {
             return 0;
@@ -1519,14 +1519,14 @@ cmsUInt32Number  GenerateCRD(cmsContext ContextID,
 
 
 
-cmsUInt32Number CMSEXPORT cmsGetPostScriptColorResource(cmsContext ContextID,                                                              
+cmsUInt32Number CMSEXPORT cmsGetPostScriptColorResource(cmsContext ContextID,
                                                                cmsPSResourceType Type,
-                                                               cmsHPROFILE hProfile, 
-                                                               cmsUInt32Number Intent, 
-                                                               cmsUInt32Number dwFlags, 
+                                                               cmsHPROFILE hProfile,
+                                                               cmsUInt32Number Intent,
+                                                               cmsUInt32Number dwFlags,
                                                                cmsIOHANDLER* io)
 {
-    cmsUInt32Number  rc; 
+    cmsUInt32Number  rc;
 
 
     switch (Type) {
@@ -1534,7 +1534,7 @@ cmsUInt32Number CMSEXPORT cmsGetPostScriptColorResource(cmsContext ContextID,
         case cmsPS_RESOURCE_CSA:
             rc = GenerateCSA(ContextID, hProfile, Intent, dwFlags, io);
             break;
-            
+
         default:
         case cmsPS_RESOURCE_CRD:
             rc = GenerateCRD(ContextID, hProfile, Intent, dwFlags, io);
@@ -1547,7 +1547,7 @@ cmsUInt32Number CMSEXPORT cmsGetPostScriptColorResource(cmsContext ContextID,
 
 
 cmsUInt32Number CMSEXPORT cmsGetPostScriptCRD(cmsContext ContextID,
-                              cmsHPROFILE hProfile, 
+                              cmsHPROFILE hProfile,
                               cmsUInt32Number Intent, cmsUInt32Number dwFlags,
                               void* Buffer, cmsUInt32Number dwBufferLen)
 {
@@ -1563,7 +1563,7 @@ cmsUInt32Number CMSEXPORT cmsGetPostScriptCRD(cmsContext ContextID,
     if (!mem) return 0;
 
     dwBytesUsed =  cmsGetPostScriptColorResource(ContextID, cmsPS_RESOURCE_CRD, hProfile, Intent, dwFlags, mem);
-                                                               
+
     // Get rid of memory stream
     cmsCloseIOhandler(mem);
 
@@ -1573,16 +1573,16 @@ cmsUInt32Number CMSEXPORT cmsGetPostScriptCRD(cmsContext ContextID,
 
 
 // Does create a Color Space Array on XYZ colorspace for PostScript usage
-cmsUInt32Number CMSEXPORT cmsGetPostScriptCSA(cmsContext ContextID, 
-                                              cmsHPROFILE hProfile, 
-                                              cmsUInt32Number Intent, 
-                                              cmsUInt32Number dwFlags, 
-                                              void* Buffer, 
-                                              cmsUInt32Number dwBufferLen)  
+cmsUInt32Number CMSEXPORT cmsGetPostScriptCSA(cmsContext ContextID,
+                                              cmsHPROFILE hProfile,
+                                              cmsUInt32Number Intent,
+                                              cmsUInt32Number dwFlags,
+                                              void* Buffer,
+                                              cmsUInt32Number dwBufferLen)
 {
     cmsIOHANDLER* mem;
     cmsUInt32Number dwBytesUsed;
-    
+
     if (Buffer == NULL)
         mem = cmsOpenIOhandlerFromNULL(ContextID);
     else
@@ -1591,7 +1591,7 @@ cmsUInt32Number CMSEXPORT cmsGetPostScriptCSA(cmsContext ContextID,
     if (!mem) return 0;
 
     dwBytesUsed =  cmsGetPostScriptColorResource(ContextID, cmsPS_RESOURCE_CSA, hProfile, Intent, dwFlags, mem);
-                                                               
+
     // Get rid of memory stream
     cmsCloseIOhandler(mem);
 
index 090d96d..b2dd2e8 100644 (file)
@@ -3,22 +3,22 @@
 //  Little Color Management System
 //  Copyright (c) 1998-2010 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 
+// 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 
+// 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 
+// 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 file contains routines for resampling and LUT optimization, black point detection
-// and black preservation. 
+// and black preservation.
 
 // Black point detection -------------------------------------------------------------------------
 
 
-// PCS -> PCS round trip transform, always uses relative intent on the device -> pcs 
+// PCS -> PCS round trip transform, always uses relative intent on the device -> pcs
 static
 cmsHTRANSFORM CreateRoundtripXForm(cmsHPROFILE hProfile, cmsUInt32Number nIntent)
 {
@@ -49,7 +49,7 @@ cmsHTRANSFORM CreateRoundtripXForm(cmsHPROFILE hProfile, cmsUInt32Number nIntent
     hProfiles[0] = hLab; hProfiles[1] = hProfile; hProfiles[2] = hProfile; hProfiles[3] = hLab;
     Intents[0]   = INTENT_RELATIVE_COLORIMETRIC; Intents[1] = nIntent; Intents[2] = INTENT_RELATIVE_COLORIMETRIC; Intents[3] = INTENT_RELATIVE_COLORIMETRIC;
 
-    xform =  cmsCreateExtendedTransform(ContextID, 4, hProfiles, BPC, Intents, 
+    xform =  cmsCreateExtendedTransform(ContextID, 4, hProfiles, BPC, Intents,
         States, NULL, 0, TYPE_Lab_DBL, TYPE_Lab_DBL, cmsFLAGS_NOCACHE|cmsFLAGS_NOOPTIMIZE);
 
     cmsCloseProfile(hLab);
@@ -59,7 +59,7 @@ cmsHTRANSFORM CreateRoundtripXForm(cmsHPROFILE hProfile, cmsUInt32Number nIntent
 // Use darker colorants to obtain black point. This works in the relative colorimetric intent and
 // assumes more ink results in darker colors. No ink limit is assumed.
 static
-cmsBool  BlackPointAsDarkerColorant(cmsHPROFILE    hInput,                               
+cmsBool  BlackPointAsDarkerColorant(cmsHPROFILE    hInput,
                                     cmsUInt32Number Intent,
                                     cmsCIEXYZ* BlackPoint,
                                     cmsUInt32Number dwFlags)
@@ -68,28 +68,28 @@ cmsBool  BlackPointAsDarkerColorant(cmsHPROFILE    hInput,
     cmsHTRANSFORM xform;
     cmsColorSpaceSignature Space;
     cmsUInt32Number nChannels;
-    cmsUInt32Number dwFormat; 
+    cmsUInt32Number dwFormat;
     cmsHPROFILE hLab;
     cmsCIELab  Lab;
-    cmsCIEXYZ  BlackXYZ;        
+    cmsCIEXYZ  BlackXYZ;
     cmsContext ContextID = cmsGetProfileContextID(hInput);
-    
-    // If the profile does not support input direction, assume Black point 0    
+
+    // If the profile does not support input direction, assume Black point 0
     if (!cmsIsIntentSupported(hInput, Intent, LCMS_USED_AS_INPUT)) {
 
         BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0;
         return FALSE;
     }
-    
+
     // Create a formatter which has n channels and floating point
     dwFormat = cmsFormatterForColorspaceOfProfile(hInput, 2, FALSE);
 
-   // Try to get black by using black colorant    
+   // Try to get black by using black colorant
     Space = cmsGetColorSpace(hInput);
 
     // This function returns darker colorant in 16 bits for several spaces
     if (!_cmsEndPointsBySpace(Space, NULL, &Black, &nChannels)) {
-        
+
         BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0;
         return FALSE;
     }
@@ -103,21 +103,21 @@ cmsBool  BlackPointAsDarkerColorant(cmsHPROFILE    hInput,
     hLab = cmsCreateLab2ProfileTHR(ContextID, NULL);
     if (hLab == NULL) {
        BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0;
-       return FALSE;    
+       return FALSE;
     }
 
     // Create the transform
     xform = cmsCreateTransformTHR(ContextID, hInput, dwFormat,
                                 hLab, TYPE_Lab_DBL, Intent, cmsFLAGS_NOOPTIMIZE|cmsFLAGS_NOCACHE);
     cmsCloseProfile(hLab);
-    
+
     if (xform == NULL) {
         // Something went wrong. Get rid of open resources and return zero as black
-        
+
         BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0;
         return FALSE;
     }
-    
+
     // Convert black to Lab
     cmsDoTransform(xform, Black, &Lab, 1);
 
@@ -125,38 +125,38 @@ cmsBool  BlackPointAsDarkerColorant(cmsHPROFILE    hInput,
     Lab.a = Lab.b = 0;
     if (Lab.L > 50) Lab.L = 50;
 
-    // Free the resources    
+    // Free the resources
     cmsDeleteTransform(xform);
-    
+
     // Convert from Lab (which is now clipped) to XYZ.
     cmsLab2XYZ(NULL, &BlackXYZ, &Lab);
-    
+
     if (BlackPoint != NULL)
         *BlackPoint = BlackXYZ;
-      
+
     return TRUE;
 
     cmsUNUSED_PARAMETER(dwFlags);
 }
 
-// Get a black point of output CMYK profile, discounting any ink-limiting embedded 
+// Get a black point of output CMYK profile, discounting any ink-limiting embedded
 // in the profile. For doing that, we use perceptual intent in input direction:
 // Lab (0, 0, 0) -> [Perceptual] Profile -> CMYK -> [Rel. colorimetric] Profile -> Lab
 static
 cmsBool BlackPointUsingPerceptualBlack(cmsCIEXYZ* BlackPoint, cmsHPROFILE hProfile)
-                                   
-{    
-    cmsHTRANSFORM hRoundTrip;    
+
+{
+    cmsHTRANSFORM hRoundTrip;
     cmsCIELab LabIn, LabOut;
-    cmsCIEXYZ  BlackXYZ;        
+    cmsCIEXYZ  BlackXYZ;
+
      // Is the intent supported by the profile?
     if (!cmsIsIntentSupported(hProfile, INTENT_PERCEPTUAL, LCMS_USED_AS_INPUT)) {
 
         BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0;
         return TRUE;
     }
-        
+
     hRoundTrip = CreateRoundtripXForm(hProfile, INTENT_PERCEPTUAL);
     if (hRoundTrip == NULL) {
         BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0;
@@ -171,10 +171,10 @@ cmsBool BlackPointUsingPerceptualBlack(cmsCIEXYZ* BlackPoint, cmsHPROFILE hProfi
     LabOut.a = LabOut.b = 0;
 
     cmsDeleteTransform(hRoundTrip);
-  
+
     // Convert it to XYZ
-    cmsLab2XYZ(NULL, &BlackXYZ, &LabOut);   
-    
+    cmsLab2XYZ(NULL, &BlackXYZ, &LabOut);
+
     if (BlackPoint != NULL)
         *BlackPoint = BlackXYZ;
 
@@ -182,34 +182,33 @@ cmsBool BlackPointUsingPerceptualBlack(cmsCIEXYZ* BlackPoint, cmsHPROFILE hProfi
 }
 
 // This function shouldn't exist at all -- there is such quantity of broken
-// profiles on black point tag, that we must somehow fix chromaticity to 
+// profiles on black point tag, that we must somehow fix chromaticity to
 // avoid huge tint when doing Black point compensation. This function does
-// just that. There is a special flag for using black point tag, but turned 
-// off by default because it is bogus on most profiles. The detection algorithm 
-// involves to turn BP to neutral and to use only L component.  
-
+// just that. There is a special flag for using black point tag, but turned
+// off by default because it is bogus on most profiles. The detection algorithm
+// involves to turn BP to neutral and to use only L component.
 cmsBool CMSEXPORT cmsDetectBlackPoint(cmsCIEXYZ* BlackPoint, cmsHPROFILE hProfile, cmsUInt32Number Intent, cmsUInt32Number dwFlags)
-{    
+{
 
     // Zero for black point
     if (cmsGetDeviceClass(hProfile) == cmsSigLinkClass) {
 
         BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0;
-        return FALSE;       
+        return FALSE;
     }
 
-    // v4 + perceptual & saturation intents does have its own black point, and it is 
+    // v4 + perceptual & saturation intents does have its own black point, and it is
     // well specified enough to use it. Black point tag is deprecated in V4.
 
-    if ((cmsGetEncodedICCversion(hProfile) >= 0x4000000) &&     
+    if ((cmsGetEncodedICCversion(hProfile) >= 0x4000000) &&
         (Intent == INTENT_PERCEPTUAL || Intent == INTENT_SATURATION)) {
 
             // Matrix shaper share MRC & perceptual intents
-            if (cmsIsMatrixShaper(hProfile)) 
+            if (cmsIsMatrixShaper(hProfile))
                 return BlackPointAsDarkerColorant(hProfile, INTENT_RELATIVE_COLORIMETRIC, BlackPoint, 0);
 
             // Get Perceptual black out of v4 profiles. That is fixed for perceptual & saturation intents
-            BlackPoint -> X = cmsPERCEPTUAL_BLACK_X; 
+            BlackPoint -> X = cmsPERCEPTUAL_BLACK_X;
             BlackPoint -> Y = cmsPERCEPTUAL_BLACK_Y;
             BlackPoint -> Z = cmsPERCEPTUAL_BLACK_Z;
 
@@ -220,13 +219,13 @@ cmsBool CMSEXPORT cmsDetectBlackPoint(cmsCIEXYZ* BlackPoint, cmsHPROFILE hProfil
 #ifdef CMS_USE_PROFILE_BLACK_POINT_TAG
 
     // v2, v4 rel/abs colorimetric
-    if (cmsIsTag(hProfile, cmsSigMediaBlackPointTag) && 
+    if (cmsIsTag(hProfile, cmsSigMediaBlackPointTag) &&
         Intent == INTENT_RELATIVE_COLORIMETRIC) {
 
             cmsCIEXYZ *BlackPtr, BlackXYZ, UntrustedBlackPoint, TrustedBlackPoint, MediaWhite;
             cmsCIELab Lab;
 
-            // If black point is specified, then use it, 
+            // If black point is specified, then use it,
 
             BlackPtr = cmsReadTag(hProfile, cmsSigMediaBlackPointTag);
             if (BlackPtr != NULL) {
@@ -245,16 +244,16 @@ cmsBool CMSEXPORT cmsDetectBlackPoint(cmsCIEXYZ* BlackPoint, cmsHPROFILE hProfil
 
                 if (BlackPoint != NULL)
                     *BlackPoint = TrustedBlackPoint;
-                
+
                 return TRUE;
             }
     }
 #endif
 
-    // That is about v2 profiles. 
+    // That is about v2 profiles.
 
     // If output profile, discount ink-limiting and that's all
-    if (Intent == INTENT_RELATIVE_COLORIMETRIC && 
+    if (Intent == INTENT_RELATIVE_COLORIMETRIC &&
         (cmsGetDeviceClass(hProfile) == cmsSigOutputClass) &&
         (cmsGetColorSpace(hProfile)  == cmsSigCmykData))
         return BlackPointUsingPerceptualBlack(BlackPoint, hProfile);
@@ -264,3 +263,306 @@ cmsBool CMSEXPORT cmsDetectBlackPoint(cmsCIEXYZ* BlackPoint, cmsHPROFILE hProfil
 }
 
 
+
+// ---------------------------------------------------------------------------------------------------------
+
+// Least Squares Fit of a Quadratic Curve to Data
+// http://www.personal.psu.edu/jhm/f90/lectures/lsq2.html
+
+static
+cmsFloat64Number RootOfLeastSquaresFitQuadraticCurve(int n, cmsFloat64Number x[], cmsFloat64Number y[])
+{
+    double sum_x = 0, sum_x2 = 0, sum_x3 = 0, sum_x4 = 0;
+    double sum_y = 0, sum_yx = 0, sum_yx2 = 0;
+    double disc;
+    int i;
+    cmsMAT3 m;
+    cmsVEC3 v, res;
+
+    if (n < 4) return 0;
+
+    for (i=0; i < n; i++) {
+
+        double xn = x[i];
+        double yn = y[i];
+
+        sum_x  += xn;
+        sum_x2 += xn*xn;
+        sum_x3 += xn*xn*xn;
+        sum_x4 += xn*xn*xn*xn;
+
+        sum_y += yn;
+        sum_yx += yn*xn;
+        sum_yx2 += yn*xn*xn;
+    }
+
+    _cmsVEC3init(&m.v[0], n,      sum_x,  sum_x2);
+    _cmsVEC3init(&m.v[1], sum_x,  sum_x2, sum_x3);
+    _cmsVEC3init(&m.v[2], sum_x2, sum_x3, sum_x4);
+
+    _cmsVEC3init(&v, sum_y, sum_yx, sum_yx2);
+
+    if (!_cmsMAT3solve(&res, &m, &v)) return 0;
+
+    // y = t x2 + u x + c
+       // x = ( - u + Sqrt( u^2 - 4 t c ) ) / ( 2 t )
+    disc = res.n[1]*res.n[1] - 4.0 * res.n[0] * res.n[2];
+    if (disc < 0) return -1;
+
+    return ( -1.0 * res.n[1] + sqrt( disc )) / (2.0 * res.n[0]);
+}
+
+static
+cmsBool IsMonotonic(int n, const cmsFloat64Number Table[])
+{
+       int i;
+       cmsFloat64Number last;
+
+    last = Table[n-1];
+
+    for (i = n-2; i >= 0; --i) {
+
+        if (Table[i] > last)
+
+            return FALSE;
+        else
+            last = Table[i];
+
+    }
+
+    return TRUE;
+}
+
+// Calculates the black point of a destination profile.
+// This algorithm comes from the Adobe paper disclosing its black point compensation method.
+cmsBool CMSEXPORT cmsDetectDestinationBlackPoint(cmsCIEXYZ* BlackPoint, cmsHPROFILE hProfile, cmsUInt32Number Intent, cmsUInt32Number dwFlags)
+{
+    cmsColorSpaceSignature ColorSpace;
+    cmsHTRANSFORM hRoundTrip = NULL;
+    cmsCIELab InitialLab, destLab, Lab;
+
+    cmsFloat64Number MinL, MaxL;
+    cmsBool NearlyStraightMidRange = FALSE;
+    cmsFloat64Number L;
+    cmsFloat64Number x[101], y[101];
+    cmsFloat64Number lo, hi, NonMonoMin;
+    int n, l, i, NonMonoIndx;
+
+
+    // Make sure intent is adequate
+    if (Intent != INTENT_PERCEPTUAL &&
+        Intent != INTENT_RELATIVE_COLORIMETRIC &&
+               Intent != INTENT_SATURATION) {
+                       BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0;
+                       return FALSE;
+       }
+
+
+    // v4 + perceptual & saturation intents does have its own black point, and it is
+    // well specified enough to use it. Black point tag is deprecated in V4.
+    if ((cmsGetEncodedICCversion(hProfile) >= 0x4000000) &&
+        (Intent == INTENT_PERCEPTUAL || Intent == INTENT_SATURATION)) {
+
+            // Matrix shaper share MRC & perceptual intents
+            if (cmsIsMatrixShaper(hProfile))
+                return BlackPointAsDarkerColorant(hProfile, INTENT_RELATIVE_COLORIMETRIC, BlackPoint, 0);
+
+            // Get Perceptual black out of v4 profiles. That is fixed for perceptual & saturation intents
+            BlackPoint -> X = cmsPERCEPTUAL_BLACK_X;
+            BlackPoint -> Y = cmsPERCEPTUAL_BLACK_Y;
+            BlackPoint -> Z = cmsPERCEPTUAL_BLACK_Z;
+            return TRUE;
+    }
+
+
+    // Check if the profile is lut based and gray, rgb or cmyk (7.2 in Adobe's document)
+    ColorSpace = cmsGetColorSpace(hProfile);
+    if (!cmsIsCLUT(hProfile, Intent, LCMS_USED_AS_OUTPUT ) ||
+        (ColorSpace != cmsSigGrayData &&
+         ColorSpace != cmsSigRgbData  &&
+         ColorSpace != cmsSigCmykData)) {
+
+        // In this case, handle as input case
+        return cmsDetectBlackPoint(BlackPoint, hProfile, Intent, dwFlags);
+    }
+
+    // It is one of the valid cases!, presto chargo hocus pocus, go for the Adobe magic
+
+    // Step 1
+    // ======
+
+    // Set a first guess, that should work on good profiles.
+    if (Intent == INTENT_RELATIVE_COLORIMETRIC) {
+
+        cmsCIEXYZ IniXYZ;
+
+        // calculate initial Lab as source black point
+        if (!cmsDetectBlackPoint(&IniXYZ, hProfile, Intent, dwFlags)) {
+            return FALSE;
+        }
+
+        // convert the XYZ to lab
+        cmsXYZ2Lab(NULL, &InitialLab, &IniXYZ);
+
+    } else {
+
+        // set the initial Lab to zero, that should be the black point for perceptual and saturation
+        InitialLab.L = 0;
+        InitialLab.a = 0;
+        InitialLab.b = 0;
+    }
+
+
+    // Step 2
+    // ======
+
+    // Create a roundtrip. Define a Transform BT for all x in L*a*b*
+    hRoundTrip = CreateRoundtripXForm(hProfile, Intent);
+    if (hRoundTrip == NULL)  return FALSE;
+
+    // Calculate Min L*
+    Lab = InitialLab;
+    Lab.L = 0;
+    cmsDoTransform(hRoundTrip, &Lab, &destLab, 1);
+    MinL = destLab.L;
+
+    // Calculate Max L*
+    Lab = InitialLab;
+    Lab.L = 100;
+    cmsDoTransform(hRoundTrip, &Lab, &destLab, 1);
+    MaxL = destLab.L;
+
+    // Step 3
+    // ======
+
+    // check if quadratic estimation needs to be done.
+    if (Intent == INTENT_RELATIVE_COLORIMETRIC) {
+
+        // Conceptually, this code tests how close the source l and converted L are to one another in the mid-range
+        // of the values. If the converted ramp of L values is close enough to a straight line y=x, then InitialLab
+        // is good enough to be the DestinationBlackPoint,
+        NearlyStraightMidRange = TRUE;
+
+        for (l=0; l <= 100; l++) {
+
+            Lab.L = l;
+            Lab.a = InitialLab.a;
+            Lab.b = InitialLab.b;
+
+            cmsDoTransform(hRoundTrip, &Lab, &destLab, 1);
+
+            L = destLab.L;
+
+            // Check the mid range in 20% after MinL
+            if (L > (MinL + 0.2 * (MaxL - MinL))) {
+
+                // Is close enough?
+                if (fabs(L - l) > 4.0) {
+
+                    // Too far away, profile is buggy!
+                    NearlyStraightMidRange = FALSE;
+                    break;
+                }
+            }
+        }
+    }
+    else {
+        // Check is always performed for perceptual and saturation intents
+        NearlyStraightMidRange = FALSE;
+    }
+
+
+    // If no furter checking is needed, we are done
+    if (NearlyStraightMidRange) {
+
+        cmsLab2XYZ(NULL, BlackPoint, &InitialLab);
+        cmsDeleteTransform(hRoundTrip);
+        return TRUE;
+    }
+
+    // The round-trip curve normally looks like a nearly constant section at the black point,
+    // with a corner and a nearly straight line to the white point.
+
+    // STEP 4
+    // =======
+
+    // find the black point using the least squares error quadratic curve fitting
+
+    if (Intent == INTENT_RELATIVE_COLORIMETRIC) {
+        lo = 0.1;
+        hi = 0.5;
+    }
+    else {
+
+        // Perceptual and saturation
+        lo = 0.03;
+        hi = 0.25;
+    }
+
+    // Capture points for the fitting.
+    n = 0;
+    for (l=0; l <= 100; l++) {
+
+        cmsFloat64Number ff;
+
+        Lab.L = (cmsFloat64Number) l;
+        Lab.a = InitialLab.a;
+        Lab.b = InitialLab.b;
+
+        cmsDoTransform(hRoundTrip, &Lab, &destLab, 1);
+
+        ff = (destLab.L - MinL)/(MaxL - MinL);
+
+        if (ff >= lo && ff < hi) {
+
+            x[n] = Lab.L;
+            y[n] = ff;
+            n++;
+        }
+
+    }
+
+       // This part is not on the Adobe paper, but I found is necessary for getting any result.
+
+       if (IsMonotonic(n, y)) {
+
+               // Monotonic means lower point is stil valid
+        cmsLab2XYZ(NULL, BlackPoint, &InitialLab);
+        cmsDeleteTransform(hRoundTrip);
+        return TRUE;
+       }
+
+    // No suitable points, regret and use safer algorithm
+    if (n == 0) {
+        cmsDeleteTransform(hRoundTrip);
+        return cmsDetectBlackPoint(BlackPoint, hProfile, Intent, dwFlags);
+    }
+
+
+       NonMonoMin = 100;
+       NonMonoIndx = 0;
+       for (i=0; i < n; i++) {
+
+               if (y[i] < NonMonoMin) {
+                       NonMonoIndx = i;
+                       NonMonoMin = y[i];
+               }
+       }
+
+       Lab.L = x[NonMonoIndx];
+
+    // fit and get the vertex of quadratic curve
+    Lab.L = RootOfLeastSquaresFitQuadraticCurve(n, x, y);
+
+    if (Lab.L < 0.0 || Lab.L > 50.0) { // clip to zero L* if the vertex is negative
+        Lab.L = 0;
+    }
+
+    Lab.a = InitialLab.a;
+    Lab.b = InitialLab.b;
+
+    cmsLab2XYZ(NULL, BlackPoint, &Lab);
+
+    cmsDeleteTransform(hRoundTrip);
+    return TRUE;
+}
index 5fdc62e..0eaa9a8 100644 (file)
@@ -3,22 +3,22 @@
 //  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 
+// 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 
+// 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 
+// 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.
 //
 //---------------------------------------------------------------------------------
@@ -36,7 +36,7 @@
 // alpha = Hab
 // theta = L*
 
-#define SECTORS 16      // number of divisions in alpha and theta 
+#define SECTORS 16      // number of divisions in alpha and theta
 
 // Spherical coordinates
 typedef struct {
@@ -47,7 +47,7 @@ typedef struct {
 
 } cmsSpherical;
 
-typedef  enum {          
+typedef  enum {
         GP_EMPTY,
         GP_SPECIFIED,
         GP_MODELED
@@ -101,7 +101,7 @@ static
 cmsFloat64Number _cmsAtan2(cmsFloat64Number y, cmsFloat64Number x)
 {
     cmsFloat64Number a;
-    
+
     // Deal with undefined case
     if (x == 0.0 && y == 0.0) return 0;
 
@@ -120,20 +120,20 @@ void ToSpherical(cmsSpherical* sp, const cmsVEC3* v)
 {
 
     cmsFloat64Number L, a, b;
-    
+
     L = v ->n[VX];
     a = v ->n[VY];
     b = v ->n[VZ];
-    
+
     sp ->r = sqrt( L*L + a*a + b*b );
 
    if (sp ->r == 0) {
         sp ->alpha = sp ->theta = 0;
         return;
     }
-           
-    sp ->alpha = _cmsAtan2(a, b);   
-    sp ->theta = _cmsAtan2(sqrt(a*a + b*b), L);  
+
+    sp ->alpha = _cmsAtan2(a, b);
+    sp ->theta = _cmsAtan2(sqrt(a*a + b*b), L);
 }
 
 
@@ -153,7 +153,7 @@ void ToCartesian(cmsVEC3* v, const cmsSpherical* sp)
     cos_theta = cos((M_PI * sp ->theta) / 180.0);
 
     a = sp ->r * sin_theta * sin_alpha;
-    b = sp ->r * sin_theta * cos_alpha; 
+    b = sp ->r * sin_theta * cos_alpha;
     L = sp ->r * cos_theta;
 
     v ->n[VX] = L;
@@ -166,9 +166,9 @@ void ToCartesian(cmsVEC3* v, const cmsSpherical* sp)
 // The limits are the centers of each sector, so
 static
 void QuantizeToSector(const cmsSpherical* sp, int* alpha, int* theta)
-{   
-    *alpha = (int) floor(((sp->alpha * (SECTORS)) / 360.0) );            
-    *theta = (int) floor(((sp->theta * (SECTORS)) / 180.0) );    
+{
+    *alpha = (int) floor(((sp->alpha * (SECTORS)) / 360.0) );
+    *theta = (int) floor(((sp->theta * (SECTORS)) / 180.0) );
 
        if (*alpha >= SECTORS)
                *alpha = SECTORS-1;
@@ -183,19 +183,19 @@ void LineOf2Points(cmsLine* line, cmsVEC3* a, cmsVEC3* b)
 {
 
     _cmsVEC3init(&line ->a, a ->n[VX], a ->n[VY], a ->n[VZ]);
-    _cmsVEC3init(&line ->u, b ->n[VX] - a ->n[VX], 
-                            b ->n[VY] - a ->n[VY], 
-                            b ->n[VZ] - a ->n[VZ]);     
+    _cmsVEC3init(&line ->u, b ->n[VX] - a ->n[VX],
+                            b ->n[VY] - a ->n[VY],
+                            b ->n[VZ] - a ->n[VZ]);
 }
 
 
-// Evaluate parametric line 
+// Evaluate parametric line
 static
 void GetPointOfLine(cmsVEC3* p, const cmsLine* line, cmsFloat64Number t)
 {
     p ->n[VX] = line ->a.n[VX] + t * line->u.n[VX];
     p ->n[VY] = line ->a.n[VY] + t * line->u.n[VY];
-    p ->n[VZ] = line ->a.n[VZ] + t * line->u.n[VZ];     
+    p ->n[VZ] = line ->a.n[VZ] + t * line->u.n[VZ];
 }
 
 
@@ -217,7 +217,7 @@ static
 cmsBool ClosestLineToLine(cmsVEC3* r, const cmsLine* line1, const cmsLine* line2)
 {
     cmsFloat64Number a, b, c, d, e, D;
-    cmsFloat64Number sc, sN, sD; 
+    cmsFloat64Number sc, sN, sD;
     cmsFloat64Number tc, tN, tD;
     cmsVEC3 w0;
 
@@ -271,9 +271,9 @@ cmsBool ClosestLineToLine(cmsVEC3* r, const cmsLine* line1, const cmsLine* line2
         }
     }
     else if (tN > tD) {      // tc > 1 => the t=1 edge is visible
-        
+
         tN = tD;
-        
+
         // recompute sc for this edge
         if ((-d + b) < 0.0)
             sN = 0;
@@ -302,7 +302,7 @@ cmsHANDLE  CMSEXPORT cmsGBDAlloc(cmsContext ContextID)
 {
     cmsGDB* gbd = (cmsGDB*) _cmsMallocZero(ContextID, sizeof(cmsGDB));
     if (gbd == NULL) return NULL;
-    
+
     gbd -> ContextID = ContextID;
 
     return (cmsHANDLE) gbd;
@@ -310,9 +310,9 @@ cmsHANDLE  CMSEXPORT cmsGBDAlloc(cmsContext ContextID)
 
 
 void CMSEXPORT cmsGBDFree(cmsHANDLE hGBD)
-{   
+{
     cmsGDB* gbd = (cmsGDB*) hGBD;
-    if (hGBD != NULL) 
+    if (hGBD != NULL)
         _cmsFree(gbd->ContextID, (void*) gbd);
 }
 
@@ -321,7 +321,7 @@ void CMSEXPORT cmsGBDFree(cmsHANDLE hGBD)
 static
 cmsGDBPoint* GetPoint(cmsGDB* gbd, const cmsCIELab* Lab, cmsSpherical* sp)
 {
-    cmsVEC3 v;  
+    cmsVEC3 v;
     int alpha, theta;
 
     // Housekeeping
@@ -329,12 +329,12 @@ cmsGDBPoint* GetPoint(cmsGDB* gbd, const cmsCIELab* Lab, cmsSpherical* sp)
        _cmsAssert(Lab != NULL);
        _cmsAssert(sp != NULL);
 
-    // Center L* by substracting half of its domain, that's 50 
+    // Center L* by substracting half of its domain, that's 50
     _cmsVEC3init(&v, Lab ->L - 50.0, Lab ->a, Lab ->b);
-       
+
     // Convert to spherical coordinates
     ToSpherical(sp, &v);
-    
+
     if (sp ->r < 0 || sp ->alpha < 0 || sp->theta < 0) {
          cmsSignalError(gbd ->ContextID, cmsERROR_RANGE, "spherical value out of range");
          return NULL;
@@ -342,7 +342,7 @@ cmsGDBPoint* GetPoint(cmsGDB* gbd, const cmsCIELab* Lab, cmsSpherical* sp)
 
     // On which sector it falls?
     QuantizeToSector(sp, &alpha, &theta);
-       
+
     if (alpha < 0 || theta < 0 || alpha >= SECTORS || theta >= SECTORS) {
          cmsSignalError(gbd ->ContextID, cmsERROR_RANGE, " quadrant out of range");
          return NULL;
@@ -352,7 +352,7 @@ cmsGDBPoint* GetPoint(cmsGDB* gbd, const cmsCIELab* Lab, cmsSpherical* sp)
     return &gbd ->Gamut[theta][alpha];
 }
 
-// Add a point to gamut descriptor. Point to add is in Lab color space. 
+// Add a point to gamut descriptor. Point to add is in Lab color space.
 // GBD is centered on a=b=0 and L*=50
 cmsBool CMSEXPORT cmsGDBAddPoint(cmsHANDLE hGBD, const cmsCIELab* Lab)
 {
@@ -388,7 +388,7 @@ cmsBool CMSEXPORT cmsGDBAddPoint(cmsHANDLE hGBD, const cmsCIELab* Lab)
 // Check if a given point falls inside gamut
 cmsBool CMSEXPORT cmsGDBCheckPoint(cmsHANDLE hGBD, const cmsCIELab* Lab)
 {
-    cmsGDB* gbd = (cmsGDB*) hGBD;   
+    cmsGDB* gbd = (cmsGDB*) hGBD;
     cmsGDBPoint* ptr;
     cmsSpherical sp;
 
@@ -406,7 +406,7 @@ cmsBool CMSEXPORT cmsGDBCheckPoint(cmsHANDLE hGBD, const cmsCIELab* Lab)
 
 // -----------------------------------------------------------------------------------------------------------------------
 
-// Find near sectors. The list of sectors found is returned on Close[]. 
+// Find near sectors. The list of sectors found is returned on Close[].
 // The function returns the number of sectors as well.
 
 // 24   9  10  11  12
@@ -416,21 +416,21 @@ cmsBool CMSEXPORT cmsGDBCheckPoint(cmsHANDLE hGBD, const cmsCIELab* Lab)
 // 20  19  18  17  16
 //
 // Those are the relative movements
-// {-2,-2}, {-1, -2}, {0, -2}, {+1, -2}, {+2,  -2}, 
+// {-2,-2}, {-1, -2}, {0, -2}, {+1, -2}, {+2,  -2},
 // {-2,-1}, {-1, -1}, {0, -1}, {+1, -1}, {+2,  -1},
 // {-2, 0}, {-1,  0}, {0,  0}, {+1,  0}, {+2,   0},
 // {-2,+1}, {-1, +1}, {0, +1}, {+1,  +1}, {+2,  +1},
 // {-2,+2}, {-1, +2}, {0, +2}, {+1,  +2}, {+2,  +2}};
 
 
-static 
-const struct _spiral { 
-    
+static
+const struct _spiral {
+
     int AdvX, AdvY;
-    
-    } Spiral[] = { {0,  -1}, {+1, -1}, {+1,  0}, {+1, +1}, {0,  +1}, {-1, +1}, 
-                   {-1,  0}, {-1, -1}, {-1, -2}, {0,  -2}, {+1, -2}, {+2, -2}, 
-                   {+2, -1}, {+2,  0}, {+2, +1}, {+2, +2}, {+1, +2}, {0,  +2}, 
+
+    } Spiral[] = { {0,  -1}, {+1, -1}, {+1,  0}, {+1, +1}, {0,  +1}, {-1, +1},
+                   {-1,  0}, {-1, -1}, {-1, -2}, {0,  -2}, {+1, -2}, {+2, -2},
+                   {+2, -1}, {+2,  0}, {+2, +1}, {+2, +2}, {+1, +2}, {0,  +2},
                    {-1, +2}, {-2, +2}, {-2, +1}, {-2, 0},  {-2, -1}, {-2, -2} };
 
 #define NSTEPS (sizeof(Spiral) / sizeof(struct _spiral))
@@ -454,14 +454,14 @@ int FindNearSectors(cmsGDB* gbd, int alpha, int theta, cmsGDBPoint* Close[])
 
         // Cycle at the begin
         if (a < 0) a = SECTORS + a;
-        if (t < 0) t = SECTORS + t;   
+        if (t < 0) t = SECTORS + t;
 
         pt = &gbd ->Gamut[t][a];
-        
+
         if (pt -> Type != GP_EMPTY) {
 
             Close[nSectors++] = pt;
-        }                           
+        }
     }
 
     return nSectors;
@@ -471,17 +471,17 @@ int FindNearSectors(cmsGDB* gbd, int alpha, int theta, cmsGDBPoint* Close[])
 // Interpolate a missing sector. Method identifies whatever this is top, bottom or mid
 static
 cmsBool InterpolateMissingSector(cmsGDB* gbd, int alpha, int theta)
-{   
+{
     cmsSpherical sp;
     cmsVEC3 Lab;
     cmsVEC3 Centre;
     cmsLine ray;
     int nCloseSectors;
-    cmsGDBPoint* Close[NSTEPS + 1]; 
+    cmsGDBPoint* Close[NSTEPS + 1];
     cmsSpherical closel, templ;
     cmsLine edge;
     int k, m;
-    
+
     // Is that point already specified?
     if (gbd ->Gamut[theta][alpha].Type != GP_EMPTY) return TRUE;
 
@@ -489,10 +489,10 @@ cmsBool InterpolateMissingSector(cmsGDB* gbd, int alpha, int theta)
     nCloseSectors = FindNearSectors(gbd, alpha, theta, Close);
 
 
-    // Find a central point on the sector 
+    // Find a central point on the sector
     sp.alpha = (cmsFloat64Number) ((alpha + 0.5) * 360.0) / (SECTORS);
     sp.theta = (cmsFloat64Number) ((theta + 0.5) * 180.0) / (SECTORS);
-    sp.r     = 50.0; 
+    sp.r     = 50.0;
 
     // Convert to Cartesian
     ToCartesian(&Lab, &sp);
@@ -511,28 +511,28 @@ cmsBool InterpolateMissingSector(cmsGDB* gbd, int alpha, int theta)
         for(m = k+1; m < nCloseSectors; m++) {
 
             cmsVEC3 temp, a1, a2;
-        
+
             // A line from sector to sector
             ToCartesian(&a1, &Close[k]->p);
             ToCartesian(&a2, &Close[m]->p);
 
             LineOf2Points(&edge, &a1, &a2);
 
-            // Find a line  
+            // Find a line
             ClosestLineToLine(&temp, &ray, &edge);
 
             // Convert to spherical
             ToSpherical(&templ, &temp);
-            
 
-            if ( templ.r > closel.r && 
-                 templ.theta >= (theta*180.0/SECTORS) && 
+
+            if ( templ.r > closel.r &&
+                 templ.theta >= (theta*180.0/SECTORS) &&
                  templ.theta <= ((theta+1)*180.0/SECTORS) &&
                  templ.alpha >= (alpha*360.0/SECTORS) &&
                  templ.alpha <= ((alpha+1)*360.0/SECTORS)) {
 
-                closel = templ;         
-            }       
+                closel = templ;
+            }
         }
     }
 
@@ -601,34 +601,34 @@ cmsBool cmsGBDdumpVRML(cmsHANDLE hGBD, const char* fname)
 
     fprintf (fp, "#VRML V2.0 utf8\n");
 
-    // set the viewing orientation and distance 
+    // set the viewing orientation and distance
     fprintf (fp, "DEF CamTest Group {\n");
-    fprintf (fp, "\tchildren [\n"); 
-    fprintf (fp, "\t\tDEF Cameras Group {\n"); 
-    fprintf (fp, "\t\t\tchildren [\n"); 
-    fprintf (fp, "\t\t\t\tDEF DefaultView Viewpoint {\n"); 
-    fprintf (fp, "\t\t\t\t\tposition 0 0 340\n"); 
-    fprintf (fp, "\t\t\t\t\torientation 0 0 1 0\n"); 
-    fprintf (fp, "\t\t\t\t\tdescription \"default view\"\n"); 
-    fprintf (fp, "\t\t\t\t}\n"); 
-    fprintf (fp, "\t\t\t]\n"); 
-    fprintf (fp, "\t\t},\n"); 
-    fprintf (fp, "\t]\n"); 
-    fprintf (fp, "}\n"); 
-
-    // Output the background stuff 
+    fprintf (fp, "\tchildren [\n");
+    fprintf (fp, "\t\tDEF Cameras Group {\n");
+    fprintf (fp, "\t\t\tchildren [\n");
+    fprintf (fp, "\t\t\t\tDEF DefaultView Viewpoint {\n");
+    fprintf (fp, "\t\t\t\t\tposition 0 0 340\n");
+    fprintf (fp, "\t\t\t\t\torientation 0 0 1 0\n");
+    fprintf (fp, "\t\t\t\t\tdescription \"default view\"\n");
+    fprintf (fp, "\t\t\t\t}\n");
+    fprintf (fp, "\t\t\t]\n");
+    fprintf (fp, "\t\t},\n");
+    fprintf (fp, "\t]\n");
+    fprintf (fp, "}\n");
+
+    // Output the background stuff
     fprintf (fp, "Background {\n");
     fprintf (fp, "\tskyColor [\n");
     fprintf (fp, "\t\t.5 .5 .5\n");
     fprintf (fp, "\t]\n");
     fprintf (fp, "}\n");
 
-    // Output the shape stuff 
+    // Output the shape stuff
     fprintf (fp, "Transform {\n");
     fprintf (fp, "\tscale .3 .3 .3\n");
     fprintf (fp, "\tchildren [\n");
 
-    // Draw the axes as a shape: 
+    // Draw the axes as a shape:
     fprintf (fp, "\t\tShape {\n");
     fprintf (fp, "\t\t\tappearance Appearance {\n");
     fprintf (fp, "\t\t\t\tmaterial Material {\n");
@@ -652,7 +652,7 @@ cmsBool cmsGBDdumpVRML(cmsHANDLE hGBD, const char* fname)
     fprintf (fp, "\t\t\t}\n");
     fprintf (fp, "\t\t}\n");
 
-    
+
     fprintf (fp, "\t\tShape {\n");
     fprintf (fp, "\t\t\tappearance Appearance {\n");
     fprintf (fp, "\t\t\t\tmaterial Material {\n");
@@ -662,8 +662,8 @@ cmsBool cmsGBDdumpVRML(cmsHANDLE hGBD, const char* fname)
     fprintf (fp, "\t\t\t\t}\n");
     fprintf (fp, "\t\t\t}\n");
     fprintf (fp, "\t\t\tgeometry PointSet {\n");
-    
-    // fill in the points here 
+
+    // fill in the points here
     fprintf (fp, "\t\t\t\tcoord Coordinate {\n");
     fprintf (fp, "\t\t\t\t\tpoint [\n");
 
@@ -678,7 +678,7 @@ cmsBool cmsGBDdumpVRML(cmsHANDLE hGBD, const char* fname)
 
             fprintf (fp, "\t\t\t\t\t%g %g %g", v.n[0]+50, v.n[1], v.n[2]);
 
-            if ((j == SECTORS - 1) && (i == SECTORS - 1)) 
+            if ((j == SECTORS - 1) && (i == SECTORS - 1))
                 fprintf (fp, "]\n");
             else
                 fprintf (fp, ",\n");
@@ -689,7 +689,7 @@ cmsBool cmsGBDdumpVRML(cmsHANDLE hGBD, const char* fname)
 
 
 
-    // fill in the face colors 
+    // fill in the face colors
     fprintf (fp, "\t\t\t\tcolor Color {\n");
     fprintf (fp, "\t\t\t\t\tcolor [\n");
 
@@ -697,14 +697,14 @@ cmsBool cmsGBDdumpVRML(cmsHANDLE hGBD, const char* fname)
         for (j=0; j < SECTORS; j++) {
 
            cmsVEC3 v;
-   
+
             pt = &gbd ->Gamut[i][j];
 
-                       
+
             ToCartesian(&v, &pt ->p);
 
 
-        if (pt ->Type == GP_EMPTY) 
+        if (pt ->Type == GP_EMPTY)
             fprintf (fp, "\t\t\t\t\t%g %g %g", 0.0, 0.0, 0.0);
         else
             if (pt ->Type == GP_MODELED)
@@ -714,13 +714,13 @@ cmsBool cmsGBDdumpVRML(cmsHANDLE hGBD, const char* fname)
 
                        }
 
-        if ((j == SECTORS - 1) && (i == SECTORS - 1)) 
+        if ((j == SECTORS - 1) && (i == SECTORS - 1))
                 fprintf (fp, "]\n");
             else
                 fprintf (fp, ",\n");
     }
     fprintf (fp, "\t\t\t}\n");
-    
+
 
     fprintf (fp, "\t\t\t}\n");
     fprintf (fp, "\t\t}\n");
index 4548c32..211df64 100644 (file)
@@ -3,22 +3,22 @@
 //  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 
+// 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 
+// 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 
+// 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"
 
-// Tag Serialization  ----------------------------------------------------------------------------- 
+// Tag Serialization  -----------------------------------------------------------------------------
 // This file implements every single tag and tag type as described in the ICC spec. Some types
 // have been deprecated, like ncl and Data. There is no implementation for those types as there
 // are no profiles holding them. The programmer can also extend this list by defining his own types
 // by using the appropiate plug-in. There are three types of plug ins regarding that. First type
 // allows to define new tags using any existing type. Next plug-in type allows to define new types
 // and the third one is very specific: allows to extend the number of elements in the multiprofile
-// elements special type. 
+// elements special type.
 //--------------------------------------------------------------------------------------------------
 
 // Some broken types
@@ -74,17 +74,17 @@ cmsBool RegisterTypesPlugin(cmsPluginBase* Data, _cmsTagTypeLinkedList* LinkedLi
         return TRUE;
     }
 
-    pt = Anterior = LinkedList; 
+    pt = Anterior = LinkedList;
     while (pt != NULL) {
 
         if (Plugin->Handler.Signature == pt -> Handler.Signature) {
-            pt ->Handler = Plugin ->Handler;    // Replace old behaviour. 
+            pt ->Handler = Plugin ->Handler;    // Replace old behaviour.
             // Note that since no memory is allocated, unregister does not
-            // reset this action. 
+            // reset this action.
             return TRUE;
-        }   
+        }
 
-        Anterior = pt;          
+        Anterior = pt;
         pt = pt ->Next;
     }
 
@@ -92,10 +92,10 @@ cmsBool RegisterTypesPlugin(cmsPluginBase* Data, _cmsTagTypeLinkedList* LinkedLi
     pt = (_cmsTagTypeLinkedList*) _cmsPluginMalloc(sizeof(_cmsTagTypeLinkedList));
     if (pt == NULL) return FALSE;
 
-    pt ->Handler   = Plugin ->Handler;  
+    pt ->Handler   = Plugin ->Handler;
     pt ->Next      = NULL;
 
-    if (Anterior) 
+    if (Anterior)
         Anterior -> Next = pt;
 
     return TRUE;
@@ -107,7 +107,7 @@ cmsTagTypeHandler* GetHandler(cmsTagTypeSignature sig, _cmsTagTypeLinkedList* Li
 {
     _cmsTagTypeLinkedList* pt;
 
-    for (pt = LinkedList; 
+    for (pt = LinkedList;
          pt != NULL;
          pt = pt ->Next) {
 
@@ -125,7 +125,7 @@ cmsBool _cmsWriteWCharArray(cmsIOHANDLER* io, cmsUInt32Number n, const wchar_t*
     cmsUInt32Number i;
 
     _cmsAssert(io != NULL);
-    _cmsAssert(Array != NULL);
+    _cmsAssert(!(Array == NULL && n > 0));
 
     for (i=0; i < n; i++) {
         if (!_cmsWriteUInt16Number(io, (cmsUInt16Number) Array[i])) return FALSE;
@@ -158,20 +158,20 @@ cmsBool _cmsReadWCharArray(cmsIOHANDLER* io, cmsUInt32Number n, wchar_t* Array)
 }
 
 // To deal with position tables
-typedef cmsBool (* PositionTableEntryFn)(struct _cms_typehandler_struct* self, 
+typedef cmsBool (* PositionTableEntryFn)(struct _cms_typehandler_struct* self,
                                              cmsIOHANDLER* io,
                                              void* Cargo,
-                                             cmsUInt32Number n, 
+                                             cmsUInt32Number n,
                                              cmsUInt32Number SizeOfTag);
 
 // Helper function to deal with position tables as decribed in ICC spec 4.3
 // A table of n elements is readed, where first comes n records containing offsets and sizes and
 // then a block containing the data itself. This allows to reuse same data in more than one entry
 static
-cmsBool ReadPositionTable(struct _cms_typehandler_struct* self, 
-                              cmsIOHANDLER* io, 
-                              cmsUInt32Number Count, 
-                              cmsUInt32Number BaseOffset, 
+cmsBool ReadPositionTable(struct _cms_typehandler_struct* self,
+                              cmsIOHANDLER* io,
+                              cmsUInt32Number Count,
+                              cmsUInt32Number BaseOffset,
                               void *Cargo,
                               PositionTableEntryFn ElementFn)
 {
@@ -204,10 +204,10 @@ cmsBool ReadPositionTable(struct _cms_typehandler_struct* self,
 
     // Success
     if (ElementOffsets != NULL) _cmsFree(io ->ContextID, ElementOffsets);
-    if (ElementSizes != NULL) _cmsFree(io ->ContextID, ElementSizes);    
+    if (ElementSizes != NULL) _cmsFree(io ->ContextID, ElementSizes);
     return TRUE;
 
-Error:    
+Error:
     if (ElementOffsets != NULL) _cmsFree(io ->ContextID, ElementOffsets);
     if (ElementSizes != NULL) _cmsFree(io ->ContextID, ElementSizes);
     return FALSE;
@@ -215,11 +215,11 @@ Error:
 
 // Same as anterior, but for write position tables
 static
-cmsBool WritePositionTable(struct _cms_typehandler_struct* self, 
+cmsBool WritePositionTable(struct _cms_typehandler_struct* self,
                                cmsIOHANDLER* io,
                                cmsUInt32Number SizeOfTag,
-                               cmsUInt32Number Count, 
-                               cmsUInt32Number BaseOffset, 
+                               cmsUInt32Number Count,
+                               cmsUInt32Number BaseOffset,
                                void *Cargo,
                                PositionTableEntryFn ElementFn)
 {
@@ -233,14 +233,14 @@ cmsBool WritePositionTable(struct _cms_typehandler_struct* self,
 
     ElementSizes = (cmsUInt32Number *) _cmsCalloc(io ->ContextID, Count, sizeof(cmsUInt32Number *));
     if (ElementSizes == NULL) goto Error;
-  
+
     // Keep starting position of curve offsets
     DirectoryPos = io ->Tell(io);
 
     // Write a fake directory to be filled latter on
     for (i=0; i < Count; i++) {
 
-        if (!_cmsWriteUInt32Number(io, 0)) goto Error;  // Offset 
+        if (!_cmsWriteUInt32Number(io, 0)) goto Error;  // Offset
         if (!_cmsWriteUInt32Number(io, 0)) goto Error;  // size
     }
 
@@ -248,13 +248,13 @@ cmsBool WritePositionTable(struct _cms_typehandler_struct* self,
     for (i=0; i < Count; i++) {
 
         Before = io ->Tell(io);
-        ElementOffsets[i] = Before - BaseOffset;                
+        ElementOffsets[i] = Before - BaseOffset;
 
         // Callback to write...
         if (!ElementFn(self, io, Cargo, i, SizeOfTag)) goto Error;
 
         // Now the size
-        ElementSizes[i] = io ->Tell(io) - Before;       
+        ElementSizes[i] = io ->Tell(io) - Before;
     }
 
     // Write the directory
@@ -262,8 +262,8 @@ cmsBool WritePositionTable(struct _cms_typehandler_struct* self,
     if (!io ->Seek(io, DirectoryPos)) goto Error;
 
     for (i=0; i <  Count; i++) {
-        if (!_cmsWriteUInt32Number(io, ElementOffsets[i])) goto Error;  
-        if (!_cmsWriteUInt32Number(io, ElementSizes[i])) goto Error;  
+        if (!_cmsWriteUInt32Number(io, ElementOffsets[i])) goto Error;
+        if (!_cmsWriteUInt32Number(io, ElementSizes[i])) goto Error;
     }
 
     if (!io ->Seek(io, CurrentPos)) goto Error;
@@ -284,7 +284,7 @@ Error:
 // ********************************************************************************
 
 //The XYZType contains an array of three encoded values for the XYZ tristimulus
-//values. Tristimulus values must be non-negative. The signed encoding allows for 
+//values. Tristimulus values must be non-negative. The signed encoding allows for
 //implementation optimizations by minimizing the number of fixed formats.
 
 
@@ -345,7 +345,7 @@ cmsTagTypeSignature DecideXYZtype(cmsFloat64Number ICCVersion, const void *Data)
 // ********************************************************************************
 // Type chromaticity. Only one value is allowed
 // ********************************************************************************
-// The chromaticity tag type provides basic chromaticity data and type of 
+// The chromaticity tag type provides basic chromaticity data and type of
 // phosphors or colorants of a monitor to applications and utilities.
 
 static
@@ -399,8 +399,8 @@ Error:
 static
 cmsBool  SaveOneChromaticity(cmsFloat64Number x, cmsFloat64Number y, cmsIOHANDLER* io)
 {
-    if (!_cmsWriteUInt32Number(io, _cmsDoubleTo15Fixed16(x))) return FALSE;     
-    if (!_cmsWriteUInt32Number(io, _cmsDoubleTo15Fixed16(y))) return FALSE;     
+    if (!_cmsWriteUInt32Number(io, _cmsDoubleTo15Fixed16(x))) return FALSE;
+    if (!_cmsWriteUInt32Number(io, _cmsDoubleTo15Fixed16(y))) return FALSE;
 
     return TRUE;
 }
@@ -420,7 +420,7 @@ cmsBool  Type_Chromaticity_Write(struct _cms_typehandler_struct* self, cmsIOHAND
     return TRUE;
 
     cmsUNUSED_PARAMETER(nItems);
-    cmsUNUSED_PARAMETER(self);  
+    cmsUNUSED_PARAMETER(self);
 }
 
 static
@@ -441,12 +441,12 @@ void Type_Chromaticity_Free(struct _cms_typehandler_struct* self, void* Ptr)
 // Type cmsSigColorantOrderType
 // ********************************************************************************
 
-// This is an optional tag which specifies the laydown order in which colorants will 
-// be printed on an n-colorant device. The laydown order may be the same as the 
-// channel generation order listed in the colorantTableTag or the channel order of a 
-// colour space such as CMYK, in which case this tag is not needed. When this is not 
-// the case (for example, ink-towers sometimes use the order KCMY), this tag may be 
-// used to specify the laydown order of the colorants. 
+// This is an optional tag which specifies the laydown order in which colorants will
+// be printed on an n-colorant device. The laydown order may be the same as the
+// channel generation order listed in the colorantTableTag or the channel order of a
+// colour space such as CMYK, in which case this tag is not needed. When this is not
+// the case (for example, ink-towers sometimes use the order KCMY), this tag may be
+// used to specify the laydown order of the colorants.
 
 
 static
@@ -480,7 +480,7 @@ void *Type_ColorantOrderType_Read(struct _cms_typehandler_struct* self, cmsIOHAN
 static
 cmsBool Type_ColorantOrderType_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems)
 {
-    cmsUInt8Number*  ColorantOrder = (cmsUInt8Number*) Ptr; 
+    cmsUInt8Number*  ColorantOrder = (cmsUInt8Number*) Ptr;
     cmsUInt32Number i, sz, Count;
 
     // Get the length
@@ -488,10 +488,10 @@ cmsBool Type_ColorantOrderType_Write(struct _cms_typehandler_struct* self, cmsIO
         if (ColorantOrder[i] != 0xFF) Count++;
     }
 
-    if (!_cmsWriteUInt32Number(io, Count)) return FALSE;    
+    if (!_cmsWriteUInt32Number(io, Count)) return FALSE;
 
     sz = Count * sizeof(cmsUInt8Number);
-    if (!io -> Write(io, sz, ColorantOrder)) return FALSE;          
+    if (!io -> Write(io, sz, ColorantOrder)) return FALSE;
 
     return TRUE;
 
@@ -517,7 +517,7 @@ void Type_ColorantOrderType_Free(struct _cms_typehandler_struct* self, void* Ptr
 // ********************************************************************************
 // Type cmsSigS15Fixed16ArrayType
 // ********************************************************************************
-// This type represents an array of generic 4-byte/32-bit fixed point quantity. 
+// This type represents an array of generic 4-byte/32-bit fixed point quantity.
 // The number of values is determined from the size of the tag.
 
 static
@@ -537,7 +537,7 @@ void *Type_S15Fixed16_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* i
 
             _cmsFree(self ->ContextID, array_double);
             return NULL;
-        }       
+        }
     }
 
     *nItems = n;
@@ -552,7 +552,7 @@ cmsBool Type_S15Fixed16_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER
 
     for (i=0; i < nItems; i++) {
 
-        if (!_cmsWrite15Fixed16Number(io, Value[i])) return FALSE;  
+        if (!_cmsWrite15Fixed16Number(io, Value[i])) return FALSE;
     }
 
     return TRUE;
@@ -576,7 +576,7 @@ void Type_S15Fixed16_Free(struct _cms_typehandler_struct* self, void* Ptr)
 // ********************************************************************************
 // Type cmsSigU16Fixed16ArrayType
 // ********************************************************************************
-// This type represents an array of generic 4-byte/32-bit quantity. 
+// This type represents an array of generic 4-byte/32-bit quantity.
 // The number of values is determined from the size of the tag.
 
 
@@ -617,7 +617,7 @@ cmsBool Type_U16Fixed16_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER
 
         cmsUInt32Number v = (cmsUInt32Number) floor(Value[i]*65536.0 + 0.5);
 
-        if (!_cmsWriteUInt32Number(io, v)) return FALSE;    
+        if (!_cmsWriteUInt32Number(io, v)) return FALSE;
     }
 
     return TRUE;
@@ -642,9 +642,9 @@ void Type_U16Fixed16_Free(struct _cms_typehandler_struct* self, void* Ptr)
 // Type cmsSigSignatureType
 // ********************************************************************************
 //
-// The signatureType contains a four-byte sequence, Sequences of less than four 
-// characters are padded at the end with spaces, 20h. 
-// Typically this type is used for registered tags that can be displayed on many 
+// The signatureType contains a four-byte sequence, Sequences of less than four
+// characters are padded at the end with spaces, 20h.
+// Typically this type is used for registered tags that can be displayed on many
 // development systems as a sequence of four characters.
 
 static
@@ -664,8 +664,8 @@ void *Type_Signature_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
 static
 cmsBool  Type_Signature_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems)
 {
-    cmsSignature* SigPtr = (cmsSignature*) Ptr; 
-    
+    cmsSignature* SigPtr = (cmsSignature*) Ptr;
+
     return _cmsWriteUInt32Number(io, *SigPtr);
 
     cmsUNUSED_PARAMETER(nItems);
@@ -689,8 +689,8 @@ void Type_Signature_Free(struct _cms_typehandler_struct* self, void* Ptr)
 // Type cmsSigTextType
 // ********************************************************************************
 //
-// The textType is a simple text structure that contains a 7-bit ASCII text string. 
-// The length of the string is obtained by subtracting 8 from the element size portion 
+// The textType is a simple text structure that contains a 7-bit ASCII text string.
+// The length of the string is obtained by subtracting 8 from the element size portion
 // of the tag itself. This string must be terminated with a 00h byte.
 
 static
@@ -711,12 +711,12 @@ void *Type_Text_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cms
     Text = (char*) _cmsMalloc(self ->ContextID, SizeOfTag + 1);
     if (Text == NULL) goto Error;
 
-    if (io -> Read(io, Text, sizeof(char), SizeOfTag) != SizeOfTag) goto Error;        
+    if (io -> Read(io, Text, sizeof(char), SizeOfTag) != SizeOfTag) goto Error;
 
     // Make sure text is properly ended
     Text[SizeOfTag] = 0;
     *nItems = 1;
-    
+
     // Keep the result
     if (!cmsMLUsetASCII(mlu, cmsNoLanguage, cmsNoCountry, Text)) goto Error;
 
@@ -724,7 +724,7 @@ void *Type_Text_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cms
     return (void*) mlu;
 
 Error:
-    if (mlu != NULL) 
+    if (mlu != NULL)
         cmsMLUfree(mlu);
     if (Text != NULL)
         _cmsFree(self ->ContextID, Text);
@@ -736,11 +736,11 @@ Error:
 static
 cmsBool Type_Text_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems)
 {
-    cmsMLU* mlu = (cmsMLU*) Ptr; 
+    cmsMLU* mlu = (cmsMLU*) Ptr;
     cmsUInt32Number size;
     cmsBool  rc;
     char* Text;
-   
+
     // Get the size of the string. Note there is an extra "\0" at the end
     size = cmsMLUgetASCII(mlu, cmsNoLanguage, cmsNoCountry, NULL, 0);
     if (size == 0) return FALSE;       // Cannot be zero!
@@ -781,11 +781,11 @@ void Type_Text_Free(struct _cms_typehandler_struct* self, void* Ptr)
 static
 cmsTagTypeSignature DecideTextType(cmsFloat64Number ICCVersion, const void *Data)
 {
-    if (ICCVersion >= 4.0) 
+    if (ICCVersion >= 4.0)
         return cmsSigMultiLocalizedUnicodeType;
-        
+
     return cmsSigTextType;
-    
+
     cmsUNUSED_PARAMETER(Data);
 }
 
@@ -802,7 +802,7 @@ void *Type_Data_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cms
     cmsUInt32Number LenOfData;
 
     *nItems = 0;
-    
+
     if (SizeOfTag < sizeof(cmsUInt32Number)) return NULL;
 
     LenOfData = SizeOfTag - sizeof(cmsUInt32Number);
@@ -818,13 +818,13 @@ void *Type_Data_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cms
     }
 
     if (io -> Read(io, BinData ->data, sizeof(cmsUInt8Number), LenOfData) != LenOfData) {
-       
+
         _cmsFree(self ->ContextID, BinData);
         return NULL;
     }
 
     *nItems = 1;
-  
+
     return (void*) BinData;
 }
 
@@ -833,7 +833,7 @@ static
 cmsBool Type_Data_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems)
 {
    cmsICCData* BinData = (cmsICCData*) Ptr;
-    
+
    if (!_cmsWriteUInt32Number(io, BinData ->flag)) return FALSE;
 
    return io ->Write(io, BinData ->len, BinData ->data);
@@ -883,7 +883,7 @@ void *Type_Text_Description_Read(struct _cms_typehandler_struct* self, cmsIOHAND
     SizeOfTag -= sizeof(cmsUInt32Number);
 
     // Check for size
-    if (SizeOfTag < AsciiCount) return NULL; 
+    if (SizeOfTag < AsciiCount) return NULL;
 
     // All seems Ok, allocate the container
     mlu = cmsMLUalloc(self ->ContextID, 1);
@@ -904,11 +904,11 @@ void *Type_Text_Description_Read(struct _cms_typehandler_struct* self, cmsIOHAND
     if (!cmsMLUsetASCII(mlu, cmsNoLanguage, cmsNoCountry, Text)) goto Error;
     _cmsFree(self ->ContextID, (void*) Text);
     Text = NULL;
-    
+
     // Skip Unicode code
     if (SizeOfTag < 2* sizeof(cmsUInt32Number)) goto Done;
-    if (!_cmsReadUInt32Number(io, &UnicodeCode)) goto Done;                      
-    if (!_cmsReadUInt32Number(io, &UnicodeCount)) goto Done;    
+    if (!_cmsReadUInt32Number(io, &UnicodeCode)) goto Done;
+    if (!_cmsReadUInt32Number(io, &UnicodeCount)) goto Done;
     SizeOfTag -= 2* sizeof(cmsUInt32Number);
 
     if (SizeOfTag < UnicodeCount*sizeof(cmsUInt16Number)) goto Done;
@@ -919,13 +919,13 @@ void *Type_Text_Description_Read(struct _cms_typehandler_struct* self, cmsIOHAND
     SizeOfTag -= UnicodeCount*sizeof(cmsUInt16Number);
 
     // Skip ScriptCode code if present. Some buggy profiles does have less
-    // data that stricttly required. We need to skip it as this type may come 
+    // data that stricttly required. We need to skip it as this type may come
     // embedded in other types.
-    
+
     if (SizeOfTag >= sizeof(cmsUInt16Number) + sizeof(cmsUInt8Number) + 67) {
 
         if (!_cmsReadUInt16Number(io, &ScriptCodeCode)) goto Done;
-        if (!_cmsReadUInt8Number(io,  &ScriptCodeCount)) goto Done;                      
+        if (!_cmsReadUInt8Number(io,  &ScriptCodeCount)) goto Done;
 
         // Skip rest of tag
         for (i=0; i < 67; i++) {
@@ -958,17 +958,17 @@ cmsBool  Type_Text_Description_Write(struct _cms_typehandler_struct* self, cmsIO
 
     // Used below for writting zeroes
     memset(Filler, 0, sizeof(Filler));
-    
+
     // Get the len of string
     len = cmsMLUgetASCII(mlu, cmsNoLanguage, cmsNoCountry, NULL, 0);
-    
+
     // From ICC3.4: It has been found that textDescriptionType can contain misaligned data
     //(see clause 4.1 for the definition of \93aligned\94). Because the Unicode language
     // code and Unicode count immediately follow the ASCII description, their
     // alignment is not correct if the ASCII count is not a multiple of four. The
     // ScriptCode code is misaligned when the ASCII count is odd. Profile reading and
     // writing software must be written carefully in order to handle these alignment
-    // problems. 
+    // problems.
 
     // Compute an aligned size
     len_aligned = _cmsALIGNLONG(len);
@@ -988,11 +988,11 @@ cmsBool  Type_Text_Description_Write(struct _cms_typehandler_struct* self, cmsIO
         Wide = (wchar_t*) _cmsCalloc(self ->ContextID, len, sizeof(wchar_t));
         if (Wide == NULL) goto Error;
 
-        // Get both representations. 
+        // Get both representations.
         cmsMLUgetASCII(mlu, cmsNoLanguage, cmsNoCountry,  Text, len * sizeof(char));
         cmsMLUgetWide(mlu,  cmsNoLanguage, cmsNoCountry,  Wide, len * sizeof(wchar_t));
     }
-          
+
   // * cmsUInt32Number       count;          * Description length
   // * cmsInt8Number         desc[count]     * NULL terminated ascii string
   // * cmsUInt32Number       ucLangCode;     * UniCode language code
@@ -1001,26 +1001,26 @@ cmsBool  Type_Text_Description_Write(struct _cms_typehandler_struct* self, cmsIO
   // * cmsUInt16Number       scCode;         * ScriptCode code
   // * cmsUInt8Number        scCount;        * ScriptCode count
   // * cmsInt8Number         scDesc[67];     * ScriptCode Description
-    
-    if (!_cmsWriteUInt32Number(io, len_aligned)) goto Error;        
-    if (!io ->Write(io, len, Text)) goto Error;    
-    if (!io ->Write(io, len_filler_alignment, Filler)) goto Error;    
+
+    if (!_cmsWriteUInt32Number(io, len_aligned)) goto Error;
+    if (!io ->Write(io, len, Text)) goto Error;
+    if (!io ->Write(io, len_filler_alignment, Filler)) goto Error;
 
     if (!_cmsWriteUInt32Number(io, 0)) goto Error;  // ucLanguageCode
-    
+
     // This part is tricky: we need an aligned tag size, and the ScriptCode part
     // takes 70 bytes, so we need 2 extra bytes to do the alignment
 
-    if (!_cmsWriteUInt32Number(io, len_aligned+1)) goto Error;  
+    if (!_cmsWriteUInt32Number(io, len_aligned+1)) goto Error;
 
     // Note that in some compilers sizeof(cmsUInt16Number) != sizeof(wchar_t)
-    if (!_cmsWriteWCharArray(io, len, Wide)) goto Error;            
-    if (!_cmsWriteUInt16Array(io, len_filler_alignment+1, (cmsUInt16Number*) Filler)) goto Error;   
+    if (!_cmsWriteWCharArray(io, len, Wide)) goto Error;
+    if (!_cmsWriteUInt16Array(io, len_filler_alignment+1, (cmsUInt16Number*) Filler)) goto Error;
 
     // ScriptCode Code & count (unused)
-    if (!_cmsWriteUInt16Number(io, 0)) goto Error;  
-    if (!_cmsWriteUInt8Number(io, 0)) goto Error;   
-        
+    if (!_cmsWriteUInt16Number(io, 0)) goto Error;
+    if (!_cmsWriteUInt8Number(io, 0)) goto Error;
+
     if (!io ->Write(io, 67, Filler)) goto Error;
 
     rc = TRUE;
@@ -1059,11 +1059,11 @@ void Type_Text_Description_Free(struct _cms_typehandler_struct* self, void* Ptr)
 static
 cmsTagTypeSignature DecideTextDescType(cmsFloat64Number ICCVersion, const void *Data)
 {
-    if (ICCVersion >= 4.0) 
+    if (ICCVersion >= 4.0)
         return cmsSigMultiLocalizedUnicodeType;
-        
+
     return cmsSigTextDescriptionType;
-    
+
     cmsUNUSED_PARAMETER(Data);
 }
 
@@ -1087,7 +1087,7 @@ void *Type_Curve_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cm
 
            case 0:   // Linear.
 
-               NewGamma = cmsBuildTabulatedToneCurve16(self ->ContextID, 2, Linear);               
+               NewGamma = cmsBuildTabulatedToneCurve16(self ->ContextID, 2, Linear);
                if (!NewGamma) return NULL;
                *nItems = 1;
                return NewGamma;
@@ -1106,10 +1106,13 @@ void *Type_Curve_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cm
 
            default:  // Curve
 
+               if (Count > 0x7FFF)
+                   return NULL; // This is to prevent bad guys for doing bad things
+
                NewGamma = cmsBuildTabulatedToneCurve16(self ->ContextID, Count, NULL);
                if (!NewGamma) return NULL;
 
-               if (!_cmsReadUInt16Array(io, Count, NewGamma -> Table16)) return NULL;         
+               if (!_cmsReadUInt16Array(io, Count, NewGamma -> Table16)) return NULL;
 
                *nItems = 1;
                return NewGamma;
@@ -1129,13 +1132,13 @@ cmsBool  Type_Curve_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
             // Single gamma, preserve number
             cmsUInt16Number SingleGammaFixed = _cmsDoubleTo8Fixed8(Curve ->Segments[0].Params[0]);
 
-            if (!_cmsWriteUInt32Number(io, 1)) return FALSE;    
+            if (!_cmsWriteUInt32Number(io, 1)) return FALSE;
             if (!_cmsWriteUInt16Number(io, SingleGammaFixed)) return FALSE;
             return TRUE;
-        
+
     }
 
-    if (!_cmsWriteUInt32Number(io, Curve ->nEntries)) return FALSE; 
+    if (!_cmsWriteUInt32Number(io, Curve ->nEntries)) return FALSE;
     return _cmsWriteUInt16Array(io, Curve ->nEntries, Curve ->Table16);
 
     cmsUNUSED_PARAMETER(nItems);
@@ -1205,7 +1208,7 @@ void *Type_ParametricCurve_Read(struct _cms_typehandler_struct* self, cmsIOHANDL
 
     for (i=0; i < n; i++) {
 
-        if (!_cmsRead15Fixed16Number(io, &Params[i])) return NULL;      
+        if (!_cmsRead15Fixed16Number(io, &Params[i])) return NULL;
     }
 
     NewGamma = cmsBuildParametricToneCurve(self ->ContextID, Type+1, Params);
@@ -1215,7 +1218,7 @@ void *Type_ParametricCurve_Read(struct _cms_typehandler_struct* self, cmsIOHANDL
 
     cmsUNUSED_PARAMETER(SizeOfTag);
 }
-    
+
 
 static
 cmsBool  Type_ParametricCurve_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems)
@@ -1223,30 +1226,30 @@ cmsBool  Type_ParametricCurve_Write(struct _cms_typehandler_struct* self, cmsIOH
     cmsToneCurve* Curve = (cmsToneCurve*) Ptr;
     int i, nParams, typen;
     static const int ParamsByType[] = { 0, 1, 3, 4, 5, 7 };
-      
+
     typen = Curve -> Segments[0].Type;
 
     if (Curve ->nSegments > 1 || typen < 1) {
 
-        cmsSignalError(self->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Multisegment or Inverted parametric curves cannot be written");          
+        cmsSignalError(self->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Multisegment or Inverted parametric curves cannot be written");
         return FALSE;
     }
 
     if (typen > 5) {
-        cmsSignalError(self->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unsupported parametric curve");          
-        return FALSE;    
+        cmsSignalError(self->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unsupported parametric curve");
+        return FALSE;
     }
 
     nParams = ParamsByType[typen];
-    
+
     if (!_cmsWriteUInt16Number(io, (cmsUInt16Number) (Curve ->Segments[0].Type - 1))) return FALSE;
     if (!_cmsWriteUInt16Number(io, 0)) return FALSE;        // Reserved
 
     for (i=0; i < nParams; i++) {
 
-        if (!_cmsWrite15Fixed16Number(io, Curve -> Segments[0].Params[i])) return FALSE;        
+        if (!_cmsWrite15Fixed16Number(io, Curve -> Segments[0].Params[i])) return FALSE;
     }
-    
+
     return TRUE;
 
     cmsUNUSED_PARAMETER(nItems);
@@ -1277,14 +1280,14 @@ void Type_ParametricCurve_Free(struct _cms_typehandler_struct* self, void* Ptr)
 // Type cmsSigDateTimeType
 // ********************************************************************************
 
-// A 12-byte value representation of the time and date, where the byte usage is assigned 
-// as specified in table 1. The actual values are encoded as 16-bit unsigned integers 
+// A 12-byte value representation of the time and date, where the byte usage is assigned
+// as specified in table 1. The actual values are encoded as 16-bit unsigned integers
 // (uInt16Number - see 5.1.6).
 //
-// All the dateTimeNumber values in a profile shall be in Coordinated Universal Time 
+// All the dateTimeNumber values in a profile shall be in Coordinated Universal Time
 // (UTC, also known as GMT or ZULU Time). Profile writers are required to convert local
-// time to UTC when setting these values. Programmes that display these values may show 
-// the dateTimeNumber as UTC, show the equivalent local time (at current locale), or 
+// time to UTC when setting these values. Programmes that display these values may show
+// the dateTimeNumber as UTC, show the equivalent local time (at current locale), or
 // display both UTC and local versions of the dateTimeNumber.
 
 static
@@ -1298,7 +1301,7 @@ void *Type_DateTime_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io,
     if (NewDateTime == NULL) return NULL;
 
     if (io->Read(io, &timestamp, sizeof(cmsDateTimeNumber), 1) != 1) return NULL;
-            
+
      _cmsDecodeDateTimeNumber(&timestamp, NewDateTime);
 
      *nItems = 1;
@@ -1345,7 +1348,7 @@ void Type_DateTime_Free(struct _cms_typehandler_struct* self, void* Ptr)
 
 /*
 The measurementType information refers only to the internal profile data and is
-meant to provide profile makers an alternative to the default measurement 
+meant to provide profile makers an alternative to the default measurement
 specifications.
 */
 
@@ -1371,7 +1374,7 @@ static
 cmsBool  Type_Measurement_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems)
 {
     cmsICCMeasurementConditions* mc =(cmsICCMeasurementConditions*) Ptr;
-    
+
     if (!_cmsWriteUInt32Number(io, mc->Observer)) return FALSE;
     if (!_cmsWriteXYZNumber(io,    &mc->Backing)) return FALSE;
     if (!_cmsWriteUInt32Number(io, mc->Geometry)) return FALSE;
@@ -1403,7 +1406,7 @@ void Type_Measurement_Free(struct _cms_typehandler_struct* self, void* Ptr)
 // Type cmsSigMultiLocalizedUnicodeType
 // ********************************************************************************
 //
-//   Do NOT trust SizeOfTag as there is an issue on the definition of profileSequenceDescTag. See the TechNote from 
+//   Do NOT trust SizeOfTag as there is an issue on the definition of profileSequenceDescTag. See the TechNote from
 //   Max Derhak and Rohit Patil about this: basically the size of the string table should be guessed and cannot be
 //   taken from the size of tag if this tag is embedded as part of bigger structures (profileSequenceDescTag, for instance)
 //
@@ -1412,7 +1415,7 @@ static
 void *Type_MLU_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsUInt32Number* nItems, cmsUInt32Number SizeOfTag)
 {
     cmsMLU* mlu;
-    cmsUInt32Number Count, RecLen, NumOfWchar;       
+    cmsUInt32Number Count, RecLen, NumOfWchar;
     cmsUInt32Number SizeOfHeader;
     cmsUInt32Number  Len, Offset;
     cmsUInt32Number  i;
@@ -1420,8 +1423,8 @@ void *Type_MLU_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsU
     cmsUInt32Number  BeginOfThisString, EndOfThisString, LargestPosition;
 
     *nItems = 0;
-    if (!_cmsReadUInt32Number(io, &Count)) return NULL;           
-    if (!_cmsReadUInt32Number(io, &RecLen)) return NULL;           
+    if (!_cmsReadUInt32Number(io, &Count)) return NULL;
+    if (!_cmsReadUInt32Number(io, &RecLen)) return NULL;
 
     if (RecLen != 12) {
 
@@ -1439,11 +1442,11 @@ void *Type_MLU_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsU
 
     for (i=0; i < Count; i++) {
 
-        if (!_cmsReadUInt16Number(io, &mlu ->Entries[i].Language)) goto Error;           
-        if (!_cmsReadUInt16Number(io, &mlu ->Entries[i].Country))  goto Error;           
+        if (!_cmsReadUInt16Number(io, &mlu ->Entries[i].Language)) goto Error;
+        if (!_cmsReadUInt16Number(io, &mlu ->Entries[i].Country))  goto Error;
 
         // Now deal with Len and offset.
-        if (!_cmsReadUInt32Number(io, &Len)) goto Error;      
+        if (!_cmsReadUInt32Number(io, &Len)) goto Error;
         if (!_cmsReadUInt32Number(io, &Offset)) goto Error;
 
         // Check for overflow
@@ -1451,9 +1454,9 @@ void *Type_MLU_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsU
 
         // True begin of the string
         BeginOfThisString = Offset - SizeOfHeader - 8;
-        
+
         // Ajust to wchar_t elements
-        mlu ->Entries[i].Len = (Len * sizeof(wchar_t)) / sizeof(cmsUInt16Number);        
+        mlu ->Entries[i].Len = (Len * sizeof(wchar_t)) / sizeof(cmsUInt16Number);
         mlu ->Entries[i].StrW = (BeginOfThisString * sizeof(wchar_t)) / sizeof(cmsUInt16Number);
 
         // To guess maximum size, add offset + len
@@ -1464,13 +1467,19 @@ void *Type_MLU_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsU
 
     // Now read the remaining of tag and fill all strings. Substract the directory
     SizeOfTag   = (LargestPosition * sizeof(wchar_t)) / sizeof(cmsUInt16Number);
+    if (SizeOfTag == 0)
+    {
+        Block = NULL;
+        NumOfWchar = 0;
 
-    Block = (wchar_t*) _cmsMalloc(self ->ContextID, SizeOfTag);
-    if (Block == NULL) goto Error;
-
-    NumOfWchar = SizeOfTag / sizeof(wchar_t);
-
-    if (!_cmsReadWCharArray(io, NumOfWchar, Block)) goto Error;
+    }
+    else
+    {
+        Block = (wchar_t*) _cmsMalloc(self ->ContextID, SizeOfTag);
+        if (Block == NULL) goto Error;
+        NumOfWchar = SizeOfTag / sizeof(wchar_t);
+        if (!_cmsReadWCharArray(io, NumOfWchar, Block)) goto Error;
+    }
 
     mlu ->MemPool  = Block;
     mlu ->PoolSize = SizeOfTag;
@@ -1479,9 +1488,9 @@ void *Type_MLU_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsU
     *nItems = 1;
     return (void*) mlu;
 
-Error:          
+Error:
     if (mlu) cmsMLUfree(mlu);
-    return NULL;                                                
+    return NULL;
 }
 
 static
@@ -1495,28 +1504,28 @@ cmsBool  Type_MLU_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io,
     if (Ptr == NULL) {
 
           // Empty placeholder
-          if (!_cmsWriteUInt32Number(io, 0)) return FALSE;           
-          if (!_cmsWriteUInt32Number(io, 12)) return FALSE;           
+          if (!_cmsWriteUInt32Number(io, 0)) return FALSE;
+          if (!_cmsWriteUInt32Number(io, 12)) return FALSE;
           return TRUE;
     }
-    
-    if (!_cmsWriteUInt32Number(io, mlu ->UsedEntries)) return FALSE;           
-    if (!_cmsWriteUInt32Number(io, 12)) return FALSE;           
-          
+
+    if (!_cmsWriteUInt32Number(io, mlu ->UsedEntries)) return FALSE;
+    if (!_cmsWriteUInt32Number(io, 12)) return FALSE;
+
     HeaderSize = 12 * mlu ->UsedEntries + sizeof(_cmsTagBase);
 
     for (i=0; i < mlu ->UsedEntries; i++) {
 
         Len    =  mlu ->Entries[i].Len;
         Offset =  mlu ->Entries[i].StrW;
-        
+
         Len    = (Len * sizeof(cmsUInt16Number)) / sizeof(wchar_t);
         Offset = (Offset * sizeof(cmsUInt16Number)) / sizeof(wchar_t) + HeaderSize + 8;
 
-        if (!_cmsWriteUInt16Number(io, mlu ->Entries[i].Language)) return FALSE;           
-        if (!_cmsWriteUInt16Number(io, mlu ->Entries[i].Country))  return FALSE;  
+        if (!_cmsWriteUInt16Number(io, mlu ->Entries[i].Language)) return FALSE;
+        if (!_cmsWriteUInt16Number(io, mlu ->Entries[i].Country))  return FALSE;
         if (!_cmsWriteUInt32Number(io, Len)) return FALSE;
-        if (!_cmsWriteUInt32Number(io, Offset)) return FALSE;               
+        if (!_cmsWriteUInt32Number(io, Offset)) return FALSE;
     }
 
     if (!_cmsWriteWCharArray(io, mlu ->PoolUsed / sizeof(wchar_t), (wchar_t*)  mlu ->MemPool)) return FALSE;
@@ -1539,7 +1548,7 @@ void* Type_MLU_Dup(struct _cms_typehandler_struct* self, const void *Ptr, cmsUIn
 
 static
 void Type_MLU_Free(struct _cms_typehandler_struct* self, void* Ptr)
-{    
+{
     cmsMLUfree((cmsMLU*) Ptr);
     return;
 
@@ -1581,10 +1590,10 @@ cmsTagTypeSignature DecideLUTtypeB2A(cmsFloat64Number ICCVersion, const void *Da
 }
 
 /*
-This structure represents a colour transform using tables of 8-bit precision. 
-This type contains four processing elements: a 3 by 3 matrix (which shall be 
-the identity matrix unless the input colour space is XYZ), a set of one dimensional 
-input tables, a multidimensional lookup table, and a set of one dimensional output 
+This structure represents a colour transform using tables of 8-bit precision.
+This type contains four processing elements: a 3 by 3 matrix (which shall be
+the identity matrix unless the input colour space is XYZ), a set of one dimensional
+input tables, a multidimensional lookup table, and a set of one dimensional output
 tables. Data is processed using these elements via the following sequence:
 (matrix) -> (1d input tables)  -> (multidimensional lookup table - CLUT) -> (1d output tables)
 
@@ -1599,7 +1608,7 @@ Byte Position   Field Length (bytes)  Content Encoded as...
 
 
 // Read 8 bit tables as gamma functions
-static 
+static
 cmsBool  Read8bitTables(cmsContext ContextID, cmsIOHANDLER* io, cmsPipeline* lut, int nChannels)
 {
     cmsStage* mpe;
@@ -1609,7 +1618,7 @@ cmsBool  Read8bitTables(cmsContext ContextID, cmsIOHANDLER* io, cmsPipeline* lut
 
     if (nChannels > cmsMAXCHANNELS) return FALSE;
     if (nChannels <= 0) return FALSE;
-        
+
     memset(Tables, 0, sizeof(Tables));
 
     Temp = (cmsUInt8Number*) _cmsMalloc(ContextID, 256);
@@ -1628,7 +1637,7 @@ cmsBool  Read8bitTables(cmsContext ContextID, cmsIOHANDLER* io, cmsPipeline* lut
             Tables[i]->Table16[j] = (cmsUInt16Number) FROM_8_TO_16(Temp[j]);
     }
 
-    _cmsFree(ContextID, Temp); 
+    _cmsFree(ContextID, Temp);
     Temp = NULL;
 
 
@@ -1637,7 +1646,7 @@ cmsBool  Read8bitTables(cmsContext ContextID, cmsIOHANDLER* io, cmsPipeline* lut
 
     cmsPipelineInsertStage(lut, cmsAT_END, mpe);
 
-    for (i=0; i < nChannels; i++) 
+    for (i=0; i < nChannels; i++)
         cmsFreeToneCurve(Tables[i]);
 
     return TRUE;
@@ -1648,7 +1657,7 @@ Error:
     }
 
     if (Temp) _cmsFree(ContextID, Temp);
-    return FALSE;       
+    return FALSE;
 }
 
 
@@ -1686,7 +1695,7 @@ cmsBool Write8bitTables(cmsContext ContextID, cmsIOHANDLER* io, cmsUInt32Number
 
 // Check overflow
 static
-unsigned int uipow(cmsUInt32Number n, cmsUInt32Number a, cmsUInt32Number b) 
+size_t uipow(cmsUInt32Number n, cmsUInt32Number a, cmsUInt32Number b)
 {
     cmsUInt32Number rv = 1, rc;
 
@@ -1694,22 +1703,22 @@ unsigned int uipow(cmsUInt32Number n, cmsUInt32Number a, cmsUInt32Number b)
     if (n == 0) return 0;
 
     for (; b > 0; b--) {
-        
+
         rv *= a;
 
         // Check for overflow
-        if (rv > UINT_MAX / a) return 0;
+        if (rv > UINT_MAX / a) return (size_t) -1;
 
     }
-    
+
     rc = rv * n;
 
-    if (rv != rc / n) return 0;
+    if (rv != rc / n) return (size_t) -1;
     return rc;
 }
 
 
-// That will create a MPE LUT with Matrix, pre tables, CLUT and post tables. 
+// That will create a MPE LUT with Matrix, pre tables, CLUT and post tables.
 // 8 bit lut may be scaled easely to v4 PCS, but we need also to properly adjust
 // PCS on BToAxx tags and AtoB if abstract. We need to fix input direction.
 
@@ -1720,20 +1729,22 @@ void *Type_LUT8_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cms
     cmsUInt8Number* Temp = NULL;
     cmsPipeline* NewLUT = NULL;
     cmsStage *mpemat, *mpeclut;
-    cmsUInt32Number nTabSize, i;    
+    cmsUInt32Number nTabSize, i;
     cmsFloat64Number Matrix[3*3];
 
     *nItems = 0;
+
     if (!_cmsReadUInt8Number(io, &InputChannels)) goto Error;
     if (!_cmsReadUInt8Number(io, &OutputChannels)) goto Error;
     if (!_cmsReadUInt8Number(io, &CLUTpoints)) goto Error;
 
+     if (CLUTpoints == 1) goto Error; // Impossible value, 0 for no CLUT and then 2 at least
+
     // Padding
     if (!_cmsReadUInt8Number(io, NULL)) goto Error;
 
     // Do some checking
-   
+
     if (InputChannels > cmsMAXCHANNELS)  goto Error;
     if (OutputChannels > cmsMAXCHANNELS) goto Error;
 
@@ -1752,7 +1763,7 @@ void *Type_LUT8_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cms
     if (!_cmsRead15Fixed16Number(io,  &Matrix[7])) goto Error;
     if (!_cmsRead15Fixed16Number(io,  &Matrix[8])) goto Error;
 
-  
+
     // Only operates if not identity...
     if ((InputChannels == 3) && !_cmsMAT3isIdentity((cmsMAT3*) Matrix)) {
 
@@ -1760,12 +1771,13 @@ void *Type_LUT8_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cms
         if (mpemat == NULL) goto Error;
         cmsPipelineInsertStage(NewLUT, cmsAT_BEGIN, mpemat);
     }
-    
+
     // Get input tables
     if (!Read8bitTables(self ->ContextID, io,  NewLUT, InputChannels)) goto Error;
-    
+
     // Get 3D CLUT. Check the overflow....
     nTabSize = uipow(OutputChannels, CLUTpoints, InputChannels);
+    if (nTabSize == (size_t) -1) goto Error;
     if (nTabSize > 0) {
 
         cmsUInt16Number *PtrW, *T;
@@ -1776,7 +1788,7 @@ void *Type_LUT8_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cms
         PtrW = T  = (cmsUInt16Number*) _cmsCalloc(self ->ContextID, nTabSize, sizeof(cmsUInt16Number));
         if (T  == NULL) goto Error;
 
-        Temp = (cmsUInt8Number*) _cmsMalloc(self ->ContextID, nTabSize);             
+        Temp = (cmsUInt8Number*) _cmsMalloc(self ->ContextID, nTabSize);
         if (Temp == NULL) goto Error;
 
         if (io ->Read(io, Temp, nTabSize, 1) != 1) goto Error;
@@ -1788,7 +1800,7 @@ void *Type_LUT8_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cms
         _cmsFree(self ->ContextID, Temp);
         Temp = NULL;
 
-        
+
         mpeclut = cmsStageAllocCLut16bit(self ->ContextID, CLUTpoints, InputChannels, OutputChannels, T);
         if (mpeclut == NULL) goto Error;
         cmsPipelineInsertStage(NewLUT, cmsAT_END, mpeclut);
@@ -1798,7 +1810,7 @@ void *Type_LUT8_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cms
 
     // Get output tables
     if (!Read8bitTables(self ->ContextID, io,  NewLUT, OutputChannels)) goto Error;
-    
+
     *nItems = 1;
     return NewLUT;
 
@@ -1893,6 +1905,7 @@ cmsBool  Type_LUT8_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io,
     if (!Write8bitTables(self ->ContextID, io, NewLUT ->InputChannels, PreMPE)) return FALSE;
 
     nTabSize = uipow(NewLUT->OutputChannels, clutPoints, NewLUT ->InputChannels);
+    if (nTabSize == (size_t) -1) return FALSE;
     if (nTabSize > 0) {
 
         // The 3D CLUT.
@@ -1926,7 +1939,7 @@ void* Type_LUT8_Dup(struct _cms_typehandler_struct* self, const void *Ptr, cmsUI
 
 static
 void Type_LUT8_Free(struct _cms_typehandler_struct* self, void* Ptr)
-{    
+{
     cmsPipelineFree((cmsPipeline*) Ptr);
     return;
 
@@ -1938,7 +1951,7 @@ void Type_LUT8_Free(struct _cms_typehandler_struct* self, void* Ptr)
 // ********************************************************************************
 
 // Read 16 bit tables as gamma functions
-static 
+static
 cmsBool  Read16bitTables(cmsContext ContextID, cmsIOHANDLER* io, cmsPipeline* lut, int nChannels, int nEntries)
 {
     cmsStage* mpe;
@@ -1949,8 +1962,9 @@ cmsBool  Read16bitTables(cmsContext ContextID, cmsIOHANDLER* io, cmsPipeline* lu
     if (nEntries <= 0) return TRUE;
 
     // Check for malicious profiles
+    if (nEntries < 2) return FALSE;
     if (nChannels > cmsMAXCHANNELS) return FALSE;
-    
+
     // Init table to zero
     memset(Tables, 0, sizeof(Tables));
 
@@ -1969,7 +1983,7 @@ cmsBool  Read16bitTables(cmsContext ContextID, cmsIOHANDLER* io, cmsPipeline* lu
 
     cmsPipelineInsertStage(lut, cmsAT_END, mpe);
 
-    for (i=0; i < nChannels; i++) 
+    for (i=0; i < nChannels; i++)
         cmsFreeToneCurve(Tables[i]);
 
     return TRUE;
@@ -1979,7 +1993,7 @@ Error:
         if (Tables[i]) cmsFreeToneCurve(Tables[i]);
     }
 
-    return FALSE;       
+    return FALSE;
 }
 
 static
@@ -1991,7 +2005,7 @@ cmsBool Write16bitTables(cmsContext ContextID, cmsIOHANDLER* io, _cmsStageToneCu
     int nEntries = 256;
 
     nEntries = Tables->TheCurves[0]->nEntries;
-    
+
     for (i=0; i < Tables ->nCurves; i++) {
 
         for (j=0; j < nEntries; j++) {
@@ -2018,13 +2032,13 @@ void *Type_LUT16_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cm
     cmsUInt32Number nTabSize;
     cmsFloat64Number Matrix[3*3];
     cmsUInt16Number InputEntries, OutputEntries;
-    
+
     *nItems = 0;
 
     if (!_cmsReadUInt8Number(io, &InputChannels)) return NULL;
     if (!_cmsReadUInt8Number(io, &OutputChannels)) return NULL;
     if (!_cmsReadUInt8Number(io, &CLUTpoints)) return NULL;   // 255 maximum
-    
+
     // Padding
     if (!_cmsReadUInt8Number(io, NULL)) return NULL;
 
@@ -2049,7 +2063,6 @@ void *Type_LUT16_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cm
 
 
     // Only operates on 3 channels
-
     if ((InputChannels == 3) && !_cmsMAT3isIdentity((cmsMAT3*) Matrix)) {
 
         mpemat = cmsStageAllocMatrix(self ->ContextID, 3, 3, Matrix, NULL);
@@ -2057,15 +2070,18 @@ void *Type_LUT16_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cm
         cmsPipelineInsertStage(NewLUT, cmsAT_END, mpemat);
     }
 
-    if (!_cmsReadUInt16Number(io, &InputEntries)) return NULL;
-    if (!_cmsReadUInt16Number(io, &OutputEntries)) return NULL; 
+    if (!_cmsReadUInt16Number(io, &InputEntries)) goto Error;
+    if (!_cmsReadUInt16Number(io, &OutputEntries)) goto Error;
+
+    if (InputEntries > 0x7FFF || OutputEntries > 0x7FFF) goto Error;
+    if (CLUTpoints == 1) goto Error; // Impossible value, 0 for no CLUT and then 2 at least
 
-    
     // Get input tables
     if (!Read16bitTables(self ->ContextID, io,  NewLUT, InputChannels, InputEntries)) goto Error;
 
     // Get 3D CLUT
     nTabSize = uipow(OutputChannels, CLUTpoints, InputChannels);
+    if (nTabSize == (size_t) -1) goto Error;
     if (nTabSize > 0) {
 
         cmsUInt16Number *T;
@@ -2075,9 +2091,9 @@ void *Type_LUT16_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cm
 
         if (!_cmsReadUInt16Array(io, nTabSize, T)) {
             _cmsFree(self ->ContextID, T);
-            goto Error;      
+            goto Error;
         }
-        
+
         mpeclut = cmsStageAllocCLut16bit(self ->ContextID, CLUTpoints, InputChannels, OutputChannels, T);
         if (mpeclut == NULL) {
              _cmsFree(self ->ContextID, T);
@@ -2102,7 +2118,7 @@ Error:
     cmsUNUSED_PARAMETER(SizeOfTag);
 }
 
-// We only allow some specific MPE structures: Matrix plus prelin, plus clut, plus post-lin. 
+// We only allow some specific MPE structures: Matrix plus prelin, plus clut, plus post-lin.
 // Some empty defaults are created for missing parts
 
 static
@@ -2123,18 +2139,18 @@ cmsBool  Type_LUT16_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
         MatMPE = (_cmsStageMatrixData*) mpe ->Data;
         mpe = mpe -> Next;
     }
-    
+
 
     if (mpe != NULL && mpe ->Type == cmsSigCurveSetElemType) {
         PreMPE = (_cmsStageToneCurvesData*) mpe ->Data;
         mpe = mpe -> Next;
     }
-    
+
     if (mpe != NULL && mpe ->Type == cmsSigCLutElemType) {
         clut  = (_cmsStageCLutData*) mpe -> Data;
         mpe = mpe ->Next;
     }
-    
+
     if (mpe != NULL && mpe ->Type == cmsSigCurveSetElemType) {
         PostMPE = (_cmsStageToneCurvesData*) mpe ->Data;
         mpe = mpe -> Next;
@@ -2148,7 +2164,7 @@ cmsBool  Type_LUT16_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
 
     InputChannels  = cmsPipelineInputChannels(NewLUT);
     OutputChannels = cmsPipelineOutputChannels(NewLUT);
-    
+
     if (clut == NULL)
         clutPoints = 0;
     else
@@ -2161,7 +2177,7 @@ cmsBool  Type_LUT16_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
 
 
     if (MatMPE != NULL) {
-    
+
         if (!_cmsWrite15Fixed16Number(io, MatMPE -> Double[0])) return FALSE;
         if (!_cmsWrite15Fixed16Number(io, MatMPE -> Double[1])) return FALSE;
         if (!_cmsWrite15Fixed16Number(io, MatMPE -> Double[2])) return FALSE;
@@ -2196,7 +2212,7 @@ cmsBool  Type_LUT16_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
         if (!_cmsWriteUInt16Number(io, (cmsUInt16Number) PostMPE ->TheCurves[0]->nEntries)) return FALSE;
     } else {
         if (!_cmsWriteUInt16Number(io, 0)) return FALSE;
-    
+
     }
 
     // The prelinearization table
@@ -2206,7 +2222,7 @@ cmsBool  Type_LUT16_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
     }
 
     nTabSize = uipow(OutputChannels, clutPoints, InputChannels);
-
+    if (nTabSize == (size_t) -1) return FALSE;
     if (nTabSize > 0) {
         // The 3D CLUT.
         if (clut != NULL) {
@@ -2236,7 +2252,7 @@ void* Type_LUT16_Dup(struct _cms_typehandler_struct* self, const void *Ptr, cmsU
 
 static
 void Type_LUT16_Free(struct _cms_typehandler_struct* self, void* Ptr)
-{    
+{
     cmsPipelineFree((cmsPipeline*) Ptr);
     return;
 
@@ -2258,7 +2274,7 @@ cmsStage* ReadMatrix(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cms
     cmsFloat64Number dOff[3];
     cmsStage* Mat;
 
-    // Go to address 
+    // Go to address
     if (!io -> Seek(io, Offset)) return NULL;
 
     // Read the Matrix
@@ -2275,7 +2291,7 @@ cmsStage* ReadMatrix(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cms
     if (!_cmsRead15Fixed16Number(io, &dOff[0])) return NULL;
     if (!_cmsRead15Fixed16Number(io, &dOff[1])) return NULL;
     if (!_cmsRead15Fixed16Number(io, &dOff[2])) return NULL;
-    
+
     Mat = cmsStageAllocMatrix(self ->ContextID, 3, 3, dMat, dOff);
 
      return Mat;
@@ -2289,7 +2305,7 @@ cmsStage* ReadMatrix(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cms
 static
 cmsStage* ReadCLUT(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsUInt32Number Offset, int InputChannels, int OutputChannels)
 {
-    cmsUInt8Number  gridPoints8[cmsMAXCHANNELS]; // Number of grid points in each dimension.  
+    cmsUInt8Number  gridPoints8[cmsMAXCHANNELS]; // Number of grid points in each dimension.
     cmsUInt32Number GridPoints[cmsMAXCHANNELS], i;
     cmsUInt8Number  Precision;
     cmsStage* CLUT;
@@ -2298,8 +2314,12 @@ cmsStage* ReadCLUT(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsUI
     if (!io -> Seek(io, Offset)) return NULL;
     if (io -> Read(io, gridPoints8, cmsMAXCHANNELS, 1) != 1) return NULL;
 
-    for (i=0; i < cmsMAXCHANNELS; i++)
+
+    for (i=0; i < cmsMAXCHANNELS; i++) {
+
+        if (gridPoints8[i] == 1) return NULL; // Impossible value, 0 for no CLUT and then 2 at least
         GridPoints[i] = gridPoints8[i];
+    }
 
     if (!_cmsReadUInt8Number(io, &Precision)) return NULL;
 
@@ -2316,25 +2336,25 @@ cmsStage* ReadCLUT(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsUI
     if (Precision == 1) {
 
        cmsUInt8Number  v;
-  
+
         for (i=0; i < Data ->nEntries; i++) {
 
                 if (io ->Read(io, &v, sizeof(cmsUInt8Number), 1) != 1) return NULL;
                 Data ->Tab.T[i] = FROM_8_TO_16(v);
         }
-                
+
     }
-    else  
+    else
         if (Precision == 2) {
-        
+
             if (!_cmsReadUInt16Array(io, Data->nEntries, Data ->Tab.T)) return NULL;
     }
     else {
-        cmsSignalError(self ->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unknown precision of '%d'", Precision); 
+        cmsSignalError(self ->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unknown precision of '%d'", Precision);
         return NULL;
     }
 
-    
+
     return CLUT;
 }
 
@@ -2344,7 +2364,7 @@ cmsToneCurve* ReadEmbeddedCurve(struct _cms_typehandler_struct* self, cmsIOHANDL
     cmsTagTypeSignature  BaseType;
     cmsUInt32Number nItems;
 
-    BaseType = _cmsReadTypeBase(io);       
+    BaseType = _cmsReadTypeBase(io);
     switch (BaseType) {
 
             case cmsSigCurveType:
@@ -2353,7 +2373,7 @@ cmsToneCurve* ReadEmbeddedCurve(struct _cms_typehandler_struct* self, cmsIOHANDL
             case cmsSigParametricCurveType:
                 return (cmsToneCurve*) Type_ParametricCurve_Read(self, io, &nItems, 0);
 
-            default: 
+            default:
                 {
                     char String[5];
 
@@ -2368,7 +2388,7 @@ cmsToneCurve* ReadEmbeddedCurve(struct _cms_typehandler_struct* self, cmsIOHANDL
 // Read a set of curves from specific offset
 static
 cmsStage* ReadSetOfCurves(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsUInt32Number Offset, cmsUInt32Number nCurves)
-{     
+{
     cmsToneCurve* Curves[cmsMAXCHANNELS];
     cmsUInt32Number i;
     cmsStage* Lin = NULL;
@@ -2377,38 +2397,39 @@ cmsStage* ReadSetOfCurves(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
 
     if (!io -> Seek(io, Offset)) return FALSE;
 
-    for (i=0; i < nCurves; i++) 
+    for (i=0; i < nCurves; i++)
         Curves[i] = NULL;
 
     for (i=0; i < nCurves; i++) {
 
-        Curves[i] = ReadEmbeddedCurve(self, io);                     
+        Curves[i] = ReadEmbeddedCurve(self, io);
         if (Curves[i] == NULL) goto Error;
-        if (!_cmsReadAlignment(io)) goto Error;   
+        if (!_cmsReadAlignment(io)) goto Error;
+
     }
 
     Lin = cmsStageAllocToneCurves(self ->ContextID, nCurves, Curves);
 
 Error:
-    for (i=0; i < nCurves; i++) 
+    for (i=0; i < nCurves; i++)
         cmsFreeToneCurve(Curves[i]);
 
     return Lin;
 }
 
 
-// LutAtoB type 
+// LutAtoB type
 
-// This structure represents a colour transform. The type contains up to five processing 
-// elements which are stored in the AtoBTag tag in the following order: a set of one 
-// dimensional curves, a 3 by 3 matrix with offset terms, a set of one dimensional curves, 
+// This structure represents a colour transform. The type contains up to five processing
+// elements which are stored in the AtoBTag tag in the following order: a set of one
+// dimensional curves, a 3 by 3 matrix with offset terms, a set of one dimensional curves,
 // a multidimensional lookup table, and a set of one dimensional output curves.
 // Data are processed using these elements via the following sequence:
 //
 //("A" curves) -> (multidimensional lookup table - CLUT) -> ("M" curves) -> (matrix) -> ("B" curves).
 //
 /*
-It is possible to use any or all of these processing elements. At least one processing element 
+It is possible to use any or all of these processing elements. At least one processing element
 must be included.Only the following combinations are allowed:
 
 B
@@ -2422,12 +2443,12 @@ static
 void* Type_LUTA2B_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsUInt32Number* nItems, cmsUInt32Number SizeOfTag)
 {
     cmsUInt32Number      BaseOffset;
-    cmsUInt8Number       inputChan;      // Number of input channels     
-    cmsUInt8Number       outputChan;     // Number of output channels     
-    cmsUInt32Number      offsetB;        // Offset to first "B" curve    
-    cmsUInt32Number      offsetMat;      // Offset to matrix             
-    cmsUInt32Number      offsetM;        // Offset to first "M" curve    
-    cmsUInt32Number      offsetC;        // Offset to CLUT               
+    cmsUInt8Number       inputChan;      // Number of input channels
+    cmsUInt8Number       outputChan;     // Number of output channels
+    cmsUInt32Number      offsetB;        // Offset to first "B" curve
+    cmsUInt32Number      offsetMat;      // Offset to matrix
+    cmsUInt32Number      offsetM;        // Offset to first "M" curve
+    cmsUInt32Number      offsetC;        // Offset to CLUT
     cmsUInt32Number      offsetA;        // Offset to first "A" curve
     cmsStage* mpe;
     cmsPipeline* NewLUT = NULL;
@@ -2437,9 +2458,9 @@ void* Type_LUTA2B_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, c
 
     if (!_cmsReadUInt8Number(io, &inputChan)) return NULL;
     if (!_cmsReadUInt8Number(io, &outputChan)) return NULL;
-    
+
     if (!_cmsReadUInt16Number(io, NULL)) return NULL;
-    
+
     if (!_cmsReadUInt32Number(io, &offsetB)) return NULL;
     if (!_cmsReadUInt32Number(io, &offsetMat)) return NULL;
     if (!_cmsReadUInt32Number(io, &offsetM)) return NULL;
@@ -2452,29 +2473,34 @@ void* Type_LUTA2B_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, c
 
     if (offsetA!= 0) {
         mpe = ReadSetOfCurves(self, io, BaseOffset + offsetA, inputChan);
+        if (mpe == NULL) { cmsPipelineFree(NewLUT); return NULL; }
         cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe);
     }
 
     if (offsetC != 0) {
         mpe = ReadCLUT(self, io, BaseOffset + offsetC, inputChan, outputChan);
-        if (mpe != NULL) cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe);
+        if (mpe == NULL) { cmsPipelineFree(NewLUT); return NULL; }
+        cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe);
     }
 
     if (offsetM != 0) {
         mpe = ReadSetOfCurves(self, io, BaseOffset + offsetM, outputChan);
-        if (mpe != NULL) cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe);
+        if (mpe == NULL) { cmsPipelineFree(NewLUT); return NULL; }
+        cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe);
     }
 
-    if (offsetMat != 0) {           
+    if (offsetMat != 0) {
         mpe = ReadMatrix(self, io, BaseOffset + offsetMat);
-        if (mpe != NULL) cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe);
+        if (mpe == NULL) { cmsPipelineFree(NewLUT); return NULL; }
+        cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe);
     }
 
-    if (offsetB != 0) {                                        
+    if (offsetB != 0) {
         mpe = ReadSetOfCurves(self, io, BaseOffset + offsetB, outputChan);
-        if (mpe != NULL) cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe);
+        if (mpe == NULL) { cmsPipelineFree(NewLUT); return NULL; }
+        cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe);
     }
-      
+
     *nItems = 1;
     return NewLUT;
 
@@ -2484,7 +2510,7 @@ void* Type_LUTA2B_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, c
 // Write a set of curves
 static
 cmsBool  WriteMatrix(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsStage* mpe)
-{   
+{
     _cmsStageMatrixData* m = (_cmsStageMatrixData*) mpe -> Data;
 
     // Write the Matrix
@@ -2521,7 +2547,7 @@ cmsBool  WriteMatrix(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cms
 // Write a set of curves
 static
 cmsBool WriteSetOfCurves(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsTagTypeSignature Type, cmsStage* mpe)
-{   
+{
     cmsUInt32Number i, n;
     cmsTagTypeSignature CurrentType;
     cmsToneCurve** Curves;
@@ -2535,7 +2561,8 @@ cmsBool WriteSetOfCurves(struct _cms_typehandler_struct* self, cmsIOHANDLER* io,
         // If this is a table-based curve, use curve type even on V4
         CurrentType = Type;
 
-        if ((Curves[i] ->nSegments == 0)||(Curves[i]->nSegments == 2) && (Curves[i] ->Segments[1].Type == 0))
+        if ((Curves[i] ->nSegments == 0)||
+            ((Curves[i]->nSegments == 2) && (Curves[i] ->Segments[1].Type == 0)) )
             CurrentType = cmsSigCurveType;
         else
         if (Curves[i] ->Segments[0].Type < 0)
@@ -2553,13 +2580,13 @@ cmsBool WriteSetOfCurves(struct _cms_typehandler_struct* self, cmsIOHANDLER* io,
                 if (!Type_ParametricCurve_Write(self, io, Curves[i], 1)) return FALSE;
                 break;
 
-            default: 
+            default:
                 {
                     char String[5];
 
                     _cmsTagSignature2String(String, (cmsTagSignature) Type);
                     cmsSignalError(self ->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unknown curve type '%s'", String);
-                }               
+                }
                 return FALSE;
         }
 
@@ -2574,17 +2601,17 @@ cmsBool WriteSetOfCurves(struct _cms_typehandler_struct* self, cmsIOHANDLER* io,
 static
 cmsBool WriteCLUT(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsUInt8Number  Precision, cmsStage* mpe)
 {
-    cmsUInt8Number  gridPoints[cmsMAXCHANNELS]; // Number of grid points in each dimension.  
-    cmsUInt32Number i;    
+    cmsUInt8Number  gridPoints[cmsMAXCHANNELS]; // Number of grid points in each dimension.
+    cmsUInt32Number i;
     _cmsStageCLutData* CLUT = ( _cmsStageCLutData*) mpe -> Data;
 
     if (CLUT ->HasFloatValues) {
-         cmsSignalError(self ->ContextID, cmsERROR_NOT_SUITABLE, "Cannot save floating point data, CLUT are 8 or 16 bit only"); 
+         cmsSignalError(self ->ContextID, cmsERROR_NOT_SUITABLE, "Cannot save floating point data, CLUT are 8 or 16 bit only");
          return FALSE;
     }
 
     memset(gridPoints, 0, sizeof(gridPoints));
-    for (i=0; i < (cmsUInt32Number) CLUT ->Params ->nInputs; i++) 
+    for (i=0; i < (cmsUInt32Number) CLUT ->Params ->nInputs; i++)
         gridPoints[i] = (cmsUInt8Number) CLUT ->Params ->nSamples[i];
 
     if (!io -> Write(io, cmsMAXCHANNELS*sizeof(cmsUInt8Number), gridPoints)) return FALSE;
@@ -2599,16 +2626,16 @@ cmsBool WriteCLUT(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsUIn
 
         for (i=0; i < CLUT->nEntries; i++) {
 
-            if (!_cmsWriteUInt8Number(io, FROM_16_TO_8(CLUT->Tab.T[i]))) return FALSE;                
+            if (!_cmsWriteUInt8Number(io, FROM_16_TO_8(CLUT->Tab.T[i]))) return FALSE;
         }
     }
-    else  
+    else
         if (Precision == 2) {
 
             if (!_cmsWriteUInt16Array(io, CLUT->nEntries, CLUT ->Tab.T)) return FALSE;
         }
         else {
-             cmsSignalError(self ->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unknown precision of '%d'", Precision); 
+             cmsSignalError(self ->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unknown precision of '%d'", Precision);
             return FALSE;
         }
 
@@ -2636,10 +2663,10 @@ cmsBool Type_LUTA2B_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
 
     if (Lut ->Elements != NULL)
         if (!cmsPipelineCheckAndRetreiveStages(Lut, 1, cmsSigCurveSetElemType, &B))
-            if (!cmsPipelineCheckAndRetreiveStages(Lut, 3, cmsSigCurveSetElemType, cmsSigMatrixElemType, cmsSigCurveSetElemType, &M, &Matrix, &B))          
-                if (!cmsPipelineCheckAndRetreiveStages(Lut, 3, cmsSigCurveSetElemType, cmsSigCLutElemType, cmsSigCurveSetElemType, &A, &CLUT, &B))              
-                    if (!cmsPipelineCheckAndRetreiveStages(Lut, 5, cmsSigCurveSetElemType, cmsSigCLutElemType, cmsSigCurveSetElemType, 
-                        cmsSigMatrixElemType, cmsSigCurveSetElemType, &A, &CLUT, &M, &Matrix, &B)) {    
+            if (!cmsPipelineCheckAndRetreiveStages(Lut, 3, cmsSigCurveSetElemType, cmsSigMatrixElemType, cmsSigCurveSetElemType, &M, &Matrix, &B))
+                if (!cmsPipelineCheckAndRetreiveStages(Lut, 3, cmsSigCurveSetElemType, cmsSigCLutElemType, cmsSigCurveSetElemType, &A, &CLUT, &B))
+                    if (!cmsPipelineCheckAndRetreiveStages(Lut, 5, cmsSigCurveSetElemType, cmsSigCLutElemType, cmsSigCurveSetElemType,
+                        cmsSigMatrixElemType, cmsSigCurveSetElemType, &A, &CLUT, &M, &Matrix, &B)) {
 
                             cmsSignalError(self->ContextID, cmsERROR_NOT_SUITABLE, "LUT is not suitable to be saved as LutAToB");
                             return FALSE;
@@ -2669,7 +2696,7 @@ cmsBool Type_LUTA2B_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
         offsetA = io ->Tell(io) - BaseOffset;
         if (!WriteSetOfCurves(self, io, cmsSigParametricCurveType, A)) return FALSE;
     }
-    
+
     if (CLUT != NULL) {
         offsetC = io ->Tell(io) - BaseOffset;
         if (!WriteCLUT(self, io, Lut ->SaveAs8Bits ? 1 : 2, CLUT)) return FALSE;
@@ -2680,7 +2707,7 @@ cmsBool Type_LUTA2B_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
         offsetM = io ->Tell(io) - BaseOffset;
         if (!WriteSetOfCurves(self, io, cmsSigParametricCurveType, M)) return FALSE;
     }
-    
+
     if (Matrix != NULL) {
         offsetMat = io ->Tell(io) - BaseOffset;
         if (!WriteMatrix(self, io, Matrix)) return FALSE;
@@ -2691,7 +2718,7 @@ cmsBool Type_LUTA2B_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
         offsetB = io ->Tell(io) - BaseOffset;
         if (!WriteSetOfCurves(self, io, cmsSigParametricCurveType, B)) return FALSE;
     }
-    
+
     CurrentPos = io ->Tell(io);
 
     if (!io ->Seek(io, DirectoryPos)) return FALSE;
@@ -2703,7 +2730,7 @@ cmsBool Type_LUTA2B_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
     if (!_cmsWriteUInt32Number(io, offsetA)) return FALSE;
 
     if (!io ->Seek(io, CurrentPos)) return FALSE;
-    
+
     return TRUE;
 
     cmsUNUSED_PARAMETER(nItems);
@@ -2721,7 +2748,7 @@ void* Type_LUTA2B_Dup(struct _cms_typehandler_struct* self, const void *Ptr, cms
 
 static
 void Type_LUTA2B_Free(struct _cms_typehandler_struct* self, void* Ptr)
-{    
+{
     cmsPipelineFree((cmsPipeline*) Ptr);
     return;
 
@@ -2729,18 +2756,18 @@ void Type_LUTA2B_Free(struct _cms_typehandler_struct* self, void* Ptr)
 }
 
 
-// LutBToA type 
+// LutBToA type
 
 static
 void* Type_LUTB2A_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsUInt32Number* nItems, cmsUInt32Number SizeOfTag)
 {
-    cmsUInt8Number       inputChan;      // Number of input channels     
-    cmsUInt8Number       outputChan;     // Number of output channels     
+    cmsUInt8Number       inputChan;      // Number of input channels
+    cmsUInt8Number       outputChan;     // Number of output channels
     cmsUInt32Number      BaseOffset;     // Actual position in file
-    cmsUInt32Number      offsetB;        // Offset to first "B" curve    
-    cmsUInt32Number      offsetMat;      // Offset to matrix             
-    cmsUInt32Number      offsetM;        // Offset to first "M" curve    
-    cmsUInt32Number      offsetC;        // Offset to CLUT               
+    cmsUInt32Number      offsetB;        // Offset to first "B" curve
+    cmsUInt32Number      offsetMat;      // Offset to matrix
+    cmsUInt32Number      offsetM;        // Offset to first "M" curve
+    cmsUInt32Number      offsetC;        // Offset to CLUT
     cmsUInt32Number      offsetA;        // Offset to first "A" curve
     cmsStage* mpe;
     cmsPipeline* NewLUT = NULL;
@@ -2753,7 +2780,7 @@ void* Type_LUTB2A_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, c
 
     // Padding
     if (!_cmsReadUInt16Number(io, NULL)) return NULL;
-    
+
     if (!_cmsReadUInt32Number(io, &offsetB)) return NULL;
     if (!_cmsReadUInt32Number(io, &offsetMat)) return NULL;
     if (!_cmsReadUInt32Number(io, &offsetM)) return NULL;
@@ -2763,30 +2790,35 @@ void* Type_LUTB2A_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, c
     // Allocates an empty LUT
     NewLUT = cmsPipelineAlloc(self ->ContextID, inputChan, outputChan);
     if (NewLUT == NULL) return NULL;
-    
-    if (offsetB != 0) {                                        
+
+    if (offsetB != 0) {
         mpe = ReadSetOfCurves(self, io, BaseOffset + offsetB, inputChan);
-        if (mpe != NULL) cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe);
+        if (mpe == NULL) { cmsPipelineFree(NewLUT); return NULL; }
+        cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe);
     }
 
-    if (offsetMat != 0) {           
+    if (offsetMat != 0) {
         mpe = ReadMatrix(self, io, BaseOffset + offsetMat);
-        if (mpe != NULL) cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe);
+        if (mpe == NULL) { cmsPipelineFree(NewLUT); return NULL; }
+        cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe);
     }
 
     if (offsetM != 0) {
         mpe = ReadSetOfCurves(self, io, BaseOffset + offsetM, inputChan);
-        if (mpe != NULL) cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe);
+        if (mpe == NULL) { cmsPipelineFree(NewLUT); return NULL; }
+        cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe);
     }
 
     if (offsetC != 0) {
         mpe = ReadCLUT(self, io, BaseOffset + offsetC, inputChan, outputChan);
-        if (mpe != NULL) cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe);
+        if (mpe == NULL) { cmsPipelineFree(NewLUT); return NULL; }
+        cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe);
     }
 
     if (offsetA!= 0) {
         mpe = ReadSetOfCurves(self, io, BaseOffset + offsetA, outputChan);
-        if (mpe != NULL) cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe);
+        if (mpe == NULL) { cmsPipelineFree(NewLUT); return NULL; }
+        cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe);
     }
 
     *nItems = 1;
@@ -2818,25 +2850,25 @@ cmsBool  Type_LUTB2A_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* i
     BaseOffset = io ->Tell(io) - sizeof(_cmsTagBase);
 
     if (!cmsPipelineCheckAndRetreiveStages(Lut, 1, cmsSigCurveSetElemType, &B))
-        if (!cmsPipelineCheckAndRetreiveStages(Lut, 3, cmsSigCurveSetElemType, cmsSigMatrixElemType, cmsSigCurveSetElemType, &B, &Matrix, &M))          
-            if (!cmsPipelineCheckAndRetreiveStages(Lut, 3, cmsSigCurveSetElemType, cmsSigCLutElemType, cmsSigCurveSetElemType, &B, &CLUT, &A))              
-                if (!cmsPipelineCheckAndRetreiveStages(Lut, 5, cmsSigCurveSetElemType, cmsSigMatrixElemType, cmsSigCurveSetElemType, 
-                    cmsSigCLutElemType, cmsSigCurveSetElemType, &B, &Matrix, &M, &CLUT, &A)) {                 
+        if (!cmsPipelineCheckAndRetreiveStages(Lut, 3, cmsSigCurveSetElemType, cmsSigMatrixElemType, cmsSigCurveSetElemType, &B, &Matrix, &M))
+            if (!cmsPipelineCheckAndRetreiveStages(Lut, 3, cmsSigCurveSetElemType, cmsSigCLutElemType, cmsSigCurveSetElemType, &B, &CLUT, &A))
+                if (!cmsPipelineCheckAndRetreiveStages(Lut, 5, cmsSigCurveSetElemType, cmsSigMatrixElemType, cmsSigCurveSetElemType,
+                    cmsSigCLutElemType, cmsSigCurveSetElemType, &B, &Matrix, &M, &CLUT, &A)) {
                         cmsSignalError(self->ContextID, cmsERROR_NOT_SUITABLE, "LUT is not suitable to be saved as LutBToA");
                         return FALSE;
                 }
 
     inputChan  = cmsPipelineInputChannels(Lut);
     outputChan = cmsPipelineOutputChannels(Lut);
-    
+
     if (!_cmsWriteUInt8Number(io, (cmsUInt8Number) inputChan)) return FALSE;
     if (!_cmsWriteUInt8Number(io, (cmsUInt8Number) outputChan)) return FALSE;
     if (!_cmsWriteUInt16Number(io, 0)) return FALSE;
 
     DirectoryPos = io ->Tell(io);
 
-    if (!_cmsWriteUInt32Number(io, 0)) return FALSE;  
-    if (!_cmsWriteUInt32Number(io, 0)) return FALSE;  
+    if (!_cmsWriteUInt32Number(io, 0)) return FALSE;
+    if (!_cmsWriteUInt32Number(io, 0)) return FALSE;
     if (!_cmsWriteUInt32Number(io, 0)) return FALSE;
     if (!_cmsWriteUInt32Number(io, 0)) return FALSE;
     if (!_cmsWriteUInt32Number(io, 0)) return FALSE;
@@ -2846,7 +2878,7 @@ cmsBool  Type_LUTB2A_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* i
         offsetA = io ->Tell(io) - BaseOffset;
         if (!WriteSetOfCurves(self, io, cmsSigParametricCurveType, A)) return FALSE;
     }
-    
+
     if (CLUT != NULL) {
         offsetC = io ->Tell(io) - BaseOffset;
         if (!WriteCLUT(self, io, Lut ->SaveAs8Bits ? 1 : 2, CLUT)) return FALSE;
@@ -2857,10 +2889,10 @@ cmsBool  Type_LUTB2A_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* i
         offsetM = io ->Tell(io) - BaseOffset;
         if (!WriteSetOfCurves(self, io, cmsSigParametricCurveType, M)) return FALSE;
     }
-    
+
     if (Matrix != NULL) {
         offsetMat = io ->Tell(io) - BaseOffset;
-        if (!WriteMatrix(self, io, Matrix)) return FALSE;    
+        if (!WriteMatrix(self, io, Matrix)) return FALSE;
     }
 
     if (B != NULL) {
@@ -2868,7 +2900,7 @@ cmsBool  Type_LUTB2A_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* i
         offsetB = io ->Tell(io) - BaseOffset;
         if (!WriteSetOfCurves(self, io, cmsSigParametricCurveType, B)) return FALSE;
     }
-    
+
     CurrentPos = io ->Tell(io);
 
     if (!io ->Seek(io, DirectoryPos)) return FALSE;
@@ -2880,7 +2912,7 @@ cmsBool  Type_LUTB2A_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* i
     if (!_cmsWriteUInt32Number(io, offsetA)) return FALSE;
 
     if (!io ->Seek(io, CurrentPos)) return FALSE;
-    
+
     return TRUE;
 
     cmsUNUSED_PARAMETER(nItems);
@@ -2899,7 +2931,7 @@ void* Type_LUTB2A_Dup(struct _cms_typehandler_struct* self, const void *Ptr, cms
 
 static
 void Type_LUTB2A_Free(struct _cms_typehandler_struct* self, void* Ptr)
-{    
+{
     cmsPipelineFree((cmsPipeline*) Ptr);
     return;
 
@@ -2912,8 +2944,8 @@ void Type_LUTB2A_Free(struct _cms_typehandler_struct* self, void* Ptr)
 // Type cmsSigColorantTableType
 // ********************************************************************************
 /*
-The purpose of this tag is to identify the colorants used in the profile by a 
-unique name and set of XYZ or L*a*b* values to give the colorant an unambiguous 
+The purpose of this tag is to identify the colorants used in the profile by a
+unique name and set of XYZ or L*a*b* values to give the colorant an unambiguous
 value. The first colorant listed is the colorant of the first device channel of
 a lut tag. The second colorant listed is the colorant of the second device channel
 of a lut tag, and so on.
@@ -2925,7 +2957,7 @@ void *Type_ColorantTable_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER
     cmsUInt32Number i, Count;
     cmsNAMEDCOLORLIST* List;
     char Name[34];
-    cmsUInt16Number PCS[3]; 
+    cmsUInt16Number PCS[3];
 
 
     if (!_cmsReadUInt32Number(io, &Count)) return NULL;
@@ -2943,8 +2975,8 @@ void *Type_ColorantTable_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER
 
         if (!_cmsReadUInt16Array(io, 3, PCS)) goto Error;
 
-        if (!cmsAppendNamedColor(List, Name, PCS, NULL)) goto Error; 
-                                                            
+        if (!cmsAppendNamedColor(List, Name, PCS, NULL)) goto Error;
+
     }
 
     *nItems = 1;
@@ -2964,7 +2996,7 @@ Error:
 static
 cmsBool  Type_ColorantTable_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems)
 {
-    cmsNAMEDCOLORLIST* NamedColorList = (cmsNAMEDCOLORLIST*) Ptr; 
+    cmsNAMEDCOLORLIST* NamedColorList = (cmsNAMEDCOLORLIST*) Ptr;
     int i, nColors;
 
     nColors = cmsNamedColorCount(NamedColorList);
@@ -2974,7 +3006,7 @@ cmsBool  Type_ColorantTable_Write(struct _cms_typehandler_struct* self, cmsIOHAN
     for (i=0; i < nColors; i++) {
 
         char root[33];
-        cmsUInt16Number PCS[3]; 
+        cmsUInt16Number PCS[3];
 
         if (!cmsNamedColorInfo(NamedColorList, i, root, NULL, NULL, PCS, NULL)) return 0;
         root[32] = 0;
@@ -2994,7 +3026,7 @@ static
 void* Type_ColorantTable_Dup(struct _cms_typehandler_struct* self, const void* Ptr, cmsUInt32Number n)
 {
     cmsNAMEDCOLORLIST* nc = (cmsNAMEDCOLORLIST*) Ptr;
-    return (void*) cmsDupNamedColorList(nc); 
+    return (void*) cmsDupNamedColorList(nc);
 
     cmsUNUSED_PARAMETER(n);
     cmsUNUSED_PARAMETER(self);
@@ -3003,7 +3035,7 @@ void* Type_ColorantTable_Dup(struct _cms_typehandler_struct* self, const void* P
 
 static
 void Type_ColorantTable_Free(struct _cms_typehandler_struct* self, void* Ptr)
-{    
+{
     cmsFreeNamedColorList((cmsNAMEDCOLORLIST*) Ptr);
     return;
 
@@ -3015,26 +3047,26 @@ void Type_ColorantTable_Free(struct _cms_typehandler_struct* self, void* Ptr)
 // Type cmsSigNamedColor2Type
 // ********************************************************************************
 //
-//The namedColor2Type is a count value and array of structures that provide color 
-//coordinates for 7-bit ASCII color names. For each named color, a PCS and optional 
-//device representation of the color are given. Both representations are 16-bit values. 
-//The device representation corresponds to the header\92\93color space of data\94 field. 
+//The namedColor2Type is a count value and array of structures that provide color
+//coordinates for 7-bit ASCII color names. For each named color, a PCS and optional
+//device representation of the color are given. Both representations are 16-bit values.
+//The device representation corresponds to the header\92\93color space of data\94 field.
 //This representation should be consistent with the \93number of device components\94
 //field in the namedColor2Type. If this field is 0, device coordinates are not provided.
-//The PCS representation corresponds to the header\92s PCS field. The PCS representation 
-//is always provided. Color names are fixed-length, 32-byte fields including null 
-//termination. In order to maintain maximum portability, it is strongly recommended 
+//The PCS representation corresponds to the header\92s PCS field. The PCS representation
+//is always provided. Color names are fixed-length, 32-byte fields including null
+//termination. In order to maintain maximum portability, it is strongly recommended
 //that special characters of the 7-bit ASCII set not be used.
 
 static
 void *Type_NamedColor_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsUInt32Number* nItems, cmsUInt32Number SizeOfTag)
 {
 
-    cmsUInt32Number      vendorFlag;     // Bottom 16 bits for ICC use 
-    cmsUInt32Number      count;          // Count of named colors 
-    cmsUInt32Number      nDeviceCoords;  // Num of device coordinates 
-    char                 prefix[32];     // Prefix for each color name 
-    char                 suffix[32];     // Suffix for each color name 
+    cmsUInt32Number      vendorFlag;     // Bottom 16 bits for ICC use
+    cmsUInt32Number      count;          // Count of named colors
+    cmsUInt32Number      nDeviceCoords;  // Num of device coordinates
+    char                 prefix[32];     // Prefix for each color name
+    char                 suffix[32];     // Suffix for each color name
     cmsNAMEDCOLORLIST*  v;
     cmsUInt32Number i;
 
@@ -3089,8 +3121,8 @@ static
 cmsBool Type_NamedColor_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems)
 {
     cmsNAMEDCOLORLIST* NamedColorList = (cmsNAMEDCOLORLIST*) Ptr;
-    char                prefix[32];     // Prefix for each color name 
-    char                suffix[32];     // Suffix for each color name 
+    char                prefix[32];     // Prefix for each color name
+    char                suffix[32];     // Suffix for each color name
     int i, nColors;
 
     nColors = cmsNamedColorCount(NamedColorList);
@@ -3115,7 +3147,7 @@ cmsBool Type_NamedColor_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER
 
         if (!cmsNamedColorInfo(NamedColorList, i, Root, NULL, NULL, PCS, Colorant)) return 0;
         if (!io ->Write(io, 32 , Root)) return FALSE;
-        if (!_cmsWriteUInt16Array(io, 3, PCS)) return FALSE;   
+        if (!_cmsWriteUInt16Array(io, 3, PCS)) return FALSE;
         if (!_cmsWriteUInt16Array(io, NamedColorList ->ColorantCount, Colorant)) return FALSE;
     }
 
@@ -3139,7 +3171,7 @@ void* Type_NamedColor_Dup(struct _cms_typehandler_struct* self, const void* Ptr,
 
 static
 void Type_NamedColor_Free(struct _cms_typehandler_struct* self, void* Ptr)
-{    
+{
     cmsFreeNamedColorList((cmsNAMEDCOLORLIST*) Ptr);
     return;
 
@@ -3151,11 +3183,11 @@ void Type_NamedColor_Free(struct _cms_typehandler_struct* self, void* Ptr)
 // Type cmsSigProfileSequenceDescType
 // ********************************************************************************
 
-// This type is an array of structures, each of which contains information from the 
-// header fields and tags from the original profiles which were combined to create 
-// the final profile. The order of the structures is the order in which the profiles 
-// were combined and includes a structure for the final profile. This provides a 
-// description of the profile sequence from source to destination, 
+// This type is an array of structures, each of which contains information from the
+// header fields and tags from the original profiles which were combined to create
+// the final profile. The order of the structures is the order in which the profiles
+// were combined and includes a structure for the final profile. This provides a
+// description of the profile sequence from source to destination,
 // typically used with the DeviceLink profile.
 
 static
@@ -3164,19 +3196,19 @@ cmsBool ReadEmbeddedText(struct _cms_typehandler_struct* self, cmsIOHANDLER* io,
     cmsTagTypeSignature  BaseType;
     cmsUInt32Number nItems;
 
-    BaseType = _cmsReadTypeBase(io); 
+    BaseType = _cmsReadTypeBase(io);
 
     switch (BaseType) {
 
        case cmsSigTextType:
            if (*mlu) cmsMLUfree(*mlu);
            *mlu = (cmsMLU*)Type_Text_Read(self, io, &nItems, SizeOfTag);
-           return (*mlu != NULL); 
+           return (*mlu != NULL);
 
        case cmsSigTextDescriptionType:
            if (*mlu) cmsMLUfree(*mlu);
            *mlu =  (cmsMLU*) Type_Text_Description_Read(self, io, &nItems, SizeOfTag);
-           return (*mlu != NULL); 
+           return (*mlu != NULL);
 
            /*
            TBD: Size is needed for MLU, and we have no idea on which is the available size
@@ -3197,48 +3229,52 @@ void *Type_ProfileSequenceDesc_Read(struct _cms_typehandler_struct* self, cmsIOH
 {
     cmsSEQ* OutSeq;
     cmsUInt32Number i, Count;
-    
+
     *nItems = 0;
-    
-    if (!_cmsReadUInt32Number(io, &Count)) return NULL;  
+
+    if (!_cmsReadUInt32Number(io, &Count)) return NULL;
 
     if (SizeOfTag < sizeof(cmsUInt32Number)) return NULL;
     SizeOfTag -= sizeof(cmsUInt32Number);
 
-   
+
     OutSeq = cmsAllocProfileSequenceDescription(self ->ContextID, Count);
     if (OutSeq == NULL) return NULL;
 
     OutSeq ->n = Count;
-    
+
     // Get structures as well
 
     for (i=0; i < Count; i++) {
-        
+
         cmsPSEQDESC* sec = &OutSeq -> seq[i];
 
-        if (!_cmsReadUInt32Number(io, &sec ->deviceMfg)) return NULL;
-        if (SizeOfTag < sizeof(cmsUInt32Number)) return NULL;
+        if (!_cmsReadUInt32Number(io, &sec ->deviceMfg)) goto Error;
+        if (SizeOfTag < sizeof(cmsUInt32Number)) goto Error;
         SizeOfTag -= sizeof(cmsUInt32Number);
 
-        if (!_cmsReadUInt32Number(io, &sec ->deviceModel)) return NULL;
-        if (SizeOfTag < sizeof(cmsUInt32Number)) return NULL;
+        if (!_cmsReadUInt32Number(io, &sec ->deviceModel)) goto Error;
+        if (SizeOfTag < sizeof(cmsUInt32Number)) goto Error;
         SizeOfTag -= sizeof(cmsUInt32Number);
 
-        if (!_cmsReadUInt64Number(io, &sec ->attributes)) return NULL;        
-        if (SizeOfTag < sizeof(cmsUInt32Number)) return NULL;
+        if (!_cmsReadUInt64Number(io, &sec ->attributes)) goto Error;
+        if (SizeOfTag < sizeof(cmsUInt32Number)) goto Error;
         SizeOfTag -= sizeof(cmsUInt64Number);
 
-        if (!_cmsReadUInt32Number(io, (cmsUInt32Number *)&sec ->technology)) return NULL;
-        if (SizeOfTag < sizeof(cmsUInt32Number)) return NULL;
+        if (!_cmsReadUInt32Number(io, (cmsUInt32Number *)&sec ->technology)) goto Error;
+        if (SizeOfTag < sizeof(cmsUInt32Number)) goto Error;
         SizeOfTag -= sizeof(cmsUInt32Number);
 
-        if (!ReadEmbeddedText(self, io, &sec ->Manufacturer, SizeOfTag)) return NULL;
-        if (!ReadEmbeddedText(self, io, &sec ->Model, SizeOfTag)) return NULL;
+        if (!ReadEmbeddedText(self, io, &sec ->Manufacturer, SizeOfTag)) goto Error;
+        if (!ReadEmbeddedText(self, io, &sec ->Model, SizeOfTag)) goto Error;
     }
 
     *nItems = 1;
     return OutSeq;
+
+Error:
+    cmsFreeProfileSequenceDescription(OutSeq);
+    return NULL;
 }
 
 
@@ -3247,7 +3283,7 @@ void *Type_ProfileSequenceDesc_Read(struct _cms_typehandler_struct* self, cmsIOH
 static
 cmsBool  SaveDescription(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsMLU* Text)
 {
-    if (self ->ICCVersion < 0x4000000) { 
+    if (self ->ICCVersion < 0x4000000) {
 
         if (!_cmsWriteTypeBase(io, cmsSigTextDescriptionType)) return FALSE;
         return Type_Text_Description_Write(self, io, Text, 1);
@@ -3266,21 +3302,21 @@ cmsBool  Type_ProfileSequenceDesc_Write(struct _cms_typehandler_struct* self, cm
     cmsUInt32Number i;
 
     if (!_cmsWriteUInt32Number(io, Seq->n)) return FALSE;
-    
+
     for (i=0; i < Seq ->n; i++) {
 
         cmsPSEQDESC* sec = &Seq -> seq[i];
 
         if (!_cmsWriteUInt32Number(io, sec ->deviceMfg)) return FALSE;
         if (!_cmsWriteUInt32Number(io, sec ->deviceModel)) return FALSE;
-        if (!_cmsWriteUInt64Number(io, sec ->attributes)) return FALSE;        
+        if (!_cmsWriteUInt64Number(io, &sec ->attributes)) return FALSE;
         if (!_cmsWriteUInt32Number(io, sec ->technology)) return FALSE;
-        
-        if (!SaveDescription(self, io, sec ->Manufacturer)) return FALSE;       
-        if (!SaveDescription(self, io, sec ->Model)) return FALSE;          
+
+        if (!SaveDescription(self, io, sec ->Manufacturer)) return FALSE;
+        if (!SaveDescription(self, io, sec ->Model)) return FALSE;
     }
-    
-     return TRUE;  
+
+     return TRUE;
 
      cmsUNUSED_PARAMETER(nItems);
 }
@@ -3288,7 +3324,7 @@ cmsBool  Type_ProfileSequenceDesc_Write(struct _cms_typehandler_struct* self, cm
 
 static
 void* Type_ProfileSequenceDesc_Dup(struct _cms_typehandler_struct* self, const void* Ptr, cmsUInt32Number n)
-{   
+{
     return (void*) cmsDupProfileSequenceDescription((cmsSEQ*) Ptr);
 
     cmsUNUSED_PARAMETER(n);
@@ -3297,7 +3333,7 @@ void* Type_ProfileSequenceDesc_Dup(struct _cms_typehandler_struct* self, const v
 
 static
 void Type_ProfileSequenceDesc_Free(struct _cms_typehandler_struct* self, void* Ptr)
-{    
+{
     cmsFreeProfileSequenceDescription((cmsSEQ*) Ptr);
     return;
 
@@ -3309,23 +3345,23 @@ void Type_ProfileSequenceDesc_Free(struct _cms_typehandler_struct* self, void* P
 // Type cmsSigProfileSequenceIdType
 // ********************************************************************************
 /*
-In certain workflows using ICC Device Link Profiles, it is necessary to identify the 
+In certain workflows using ICC Device Link Profiles, it is necessary to identify the
 original profiles that were combined to create the Device Link Profile.
-This type is an array of structures, each of which contains information for 
+This type is an array of structures, each of which contains information for
 identification of a profile used in a sequence
 */
 
 
 static
-cmsBool ReadSeqID(struct _cms_typehandler_struct* self, 
+cmsBool ReadSeqID(struct _cms_typehandler_struct* self,
                                              cmsIOHANDLER* io,
                                              void* Cargo,
-                                             cmsUInt32Number n, 
+                                             cmsUInt32Number n,
                                              cmsUInt32Number SizeOfTag)
 {
     cmsSEQ* OutSeq = (cmsSEQ*) Cargo;
     cmsPSEQDESC* seq = &OutSeq ->seq[n];
-    
+
     if (io -> Read(io, seq ->ProfileID.ID8, 16, 1) != 1) return FALSE;
     if (!ReadEmbeddedText(self, io, &seq ->Description, SizeOfTag)) return FALSE;
 
@@ -3347,7 +3383,7 @@ void *Type_ProfileSequenceId_Read(struct _cms_typehandler_struct* self, cmsIOHAN
     BaseOffset = io ->Tell(io) - sizeof(_cmsTagBase);
 
     // Get table count
-    if (!_cmsReadUInt32Number(io, &Count)) return NULL;  
+    if (!_cmsReadUInt32Number(io, &Count)) return NULL;
     SizeOfTag -= sizeof(cmsUInt32Number);
 
     // Allocate an empty structure
@@ -3370,18 +3406,18 @@ void *Type_ProfileSequenceId_Read(struct _cms_typehandler_struct* self, cmsIOHAN
 
 
 static
-cmsBool WriteSeqID(struct _cms_typehandler_struct* self, 
+cmsBool WriteSeqID(struct _cms_typehandler_struct* self,
                                              cmsIOHANDLER* io,
                                              void* Cargo,
-                                             cmsUInt32Number n, 
+                                             cmsUInt32Number n,
                                              cmsUInt32Number SizeOfTag)
 {
     cmsSEQ* Seq = (cmsSEQ*) Cargo;
-    
+
     if (!io ->Write(io, 16, Seq ->seq[n].ProfileID.ID8)) return FALSE;
 
     // Store here the MLU
-    if (!SaveDescription(self, io, Seq ->seq[n].Description)) return FALSE;  
+    if (!SaveDescription(self, io, Seq ->seq[n].Description)) return FALSE;
 
     return TRUE;
 
@@ -3396,13 +3432,13 @@ cmsBool  Type_ProfileSequenceId_Write(struct _cms_typehandler_struct* self, cmsI
 
     // Keep the base offset
     BaseOffset = io ->Tell(io) - sizeof(_cmsTagBase);
-    
+
     // This is the table count
     if (!_cmsWriteUInt32Number(io, Seq ->n)) return FALSE;
 
     // This is the position table and content
     if (!WritePositionTable(self, io, 0, Seq ->n, BaseOffset, Seq, WriteSeqID)) return FALSE;
-          
+
     return TRUE;
 
     cmsUNUSED_PARAMETER(nItems);
@@ -3410,7 +3446,7 @@ cmsBool  Type_ProfileSequenceId_Write(struct _cms_typehandler_struct* self, cmsI
 
 static
 void* Type_ProfileSequenceId_Dup(struct _cms_typehandler_struct* self, const void* Ptr, cmsUInt32Number n)
-{   
+{
     return (void*) cmsDupProfileSequenceDescription((cmsSEQ*) Ptr);
 
     cmsUNUSED_PARAMETER(n);
@@ -3419,7 +3455,7 @@ void* Type_ProfileSequenceId_Dup(struct _cms_typehandler_struct* self, const voi
 
 static
 void Type_ProfileSequenceId_Free(struct _cms_typehandler_struct* self, void* Ptr)
-{    
+{
     cmsFreeProfileSequenceDescription((cmsSEQ*) Ptr);
     return;
 
@@ -3495,7 +3531,7 @@ cmsBool  Type_UcrBg_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
     if (!_cmsWriteUInt32Number(io, Value ->Ucr ->nEntries)) return FALSE;
     if (!_cmsWriteUInt16Array(io, Value ->Ucr ->nEntries, Value ->Ucr ->Table16)) return FALSE;
 
-    // Then black generation    
+    // Then black generation
     if (!_cmsWriteUInt32Number(io, Value ->Bg ->nEntries)) return FALSE;
     if (!_cmsWriteUInt16Array(io, Value ->Bg ->nEntries, Value ->Bg ->Table16)) return FALSE;
 
@@ -3504,7 +3540,7 @@ cmsBool  Type_UcrBg_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
     Text     = (char*) _cmsMalloc(self ->ContextID, TextSize);
     if (cmsMLUgetASCII(Value ->Desc, cmsNoLanguage, cmsNoCountry, Text, TextSize) != TextSize) return FALSE;
 
-    if (!io ->Write(io, TextSize, Text)) return FALSE;      
+    if (!io ->Write(io, TextSize, Text)) return FALSE;
     _cmsFree(self ->ContextID, Text);
 
     return TRUE;
@@ -3533,11 +3569,11 @@ static
 void Type_UcrBg_Free(struct _cms_typehandler_struct* self, void *Ptr)
 {
    cmsUcrBg* Src = (cmsUcrBg*) Ptr;
-   
+
    if (Src ->Ucr) cmsFreeToneCurve(Src ->Ucr);
    if (Src ->Bg)  cmsFreeToneCurve(Src ->Bg);
    if (Src ->Desc) cmsMLUfree(Src ->Desc);
-   
+
    _cmsFree(self ->ContextID, Ptr);
 }
 
@@ -3567,12 +3603,12 @@ cmsBool  ReadCountAndSting(struct _cms_typehandler_struct* self, cmsIOHANDLER* i
     cmsUInt32Number Count;
     char* Text;
 
-    if (*SizeOfTag < sizeof(cmsUInt32Number)) return FALSE; 
-    
+    if (*SizeOfTag < sizeof(cmsUInt32Number)) return FALSE;
+
     if (!_cmsReadUInt32Number(io, &Count)) return FALSE;
 
     if (Count > UINT_MAX - sizeof(cmsUInt32Number)) return FALSE;
-    if (*SizeOfTag < Count + sizeof(cmsUInt32Number)) return FALSE; 
+    if (*SizeOfTag < Count + sizeof(cmsUInt32Number)) return FALSE;
 
     Text     = (char*) _cmsMalloc(self ->ContextID, Count+1);
     if (Text == NULL) return FALSE;
@@ -3583,28 +3619,28 @@ cmsBool  ReadCountAndSting(struct _cms_typehandler_struct* self, cmsIOHANDLER* i
     }
 
     Text[Count] = 0;
-   
+
     cmsMLUsetASCII(mlu, "PS", Section, Text);
     _cmsFree(self ->ContextID, Text);
 
     *SizeOfTag -= (Count + sizeof(cmsUInt32Number));
-    return TRUE;    
+    return TRUE;
 }
 
 static
 cmsBool  WriteCountAndSting(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsMLU* mlu, const char* Section)
 {
  cmsUInt32Number TextSize;
- char* Text;    
-    
+ char* Text;
+
     TextSize = cmsMLUgetASCII(mlu, "PS", Section, NULL, 0);
     Text     = (char*) _cmsMalloc(self ->ContextID, TextSize);
 
-    if (!_cmsWriteUInt32Number(io, TextSize)) return FALSE; 
+    if (!_cmsWriteUInt32Number(io, TextSize)) return FALSE;
 
     if (cmsMLUgetASCII(mlu, "PS", Section, Text, TextSize) == 0) return FALSE;
 
-    if (!io ->Write(io, TextSize, Text)) return FALSE;      
+    if (!io ->Write(io, TextSize, Text)) return FALSE;
     _cmsFree(self ->ContextID, Text);
 
     return TRUE;
@@ -3621,7 +3657,7 @@ void *Type_CrdInfo_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io,
     if (!ReadCountAndSting(self, io, mlu, &SizeOfTag, "#1")) goto Error;
     if (!ReadCountAndSting(self, io, mlu, &SizeOfTag, "#2")) goto Error;
     if (!ReadCountAndSting(self, io, mlu, &SizeOfTag, "#3")) goto Error;
-  
+
     *nItems = 1;
     return (void*) mlu;
 
@@ -3663,7 +3699,7 @@ void* Type_CrdInfo_Dup(struct _cms_typehandler_struct* self, const void *Ptr, cm
 
 static
 void Type_CrdInfo_Free(struct _cms_typehandler_struct* self, void *Ptr)
-{    
+{
     cmsMLUfree((cmsMLU*) Ptr);
     return;
 
@@ -3682,12 +3718,12 @@ void *Type_Screening_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
 {
     cmsScreening* sc = NULL;
     cmsUInt32Number i;
-    
+
     sc = (cmsScreening*) _cmsMallocZero(self ->ContextID, sizeof(cmsScreening));
     if (sc == NULL) return NULL;
 
     *nItems = 0;
-    
+
     if (!_cmsReadUInt32Number(io, &sc ->Flag)) goto Error;
     if (!_cmsReadUInt32Number(io, &sc ->nChannels)) goto Error;
 
@@ -3696,8 +3732,8 @@ void *Type_Screening_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
 
     for (i=0; i < sc ->nChannels; i++) {
 
-        if (!_cmsRead15Fixed16Number(io, &sc ->Channels[i].Frequency)) goto Error;      
-        if (!_cmsRead15Fixed16Number(io, &sc ->Channels[i].ScreenAngle)) goto Error;        
+        if (!_cmsRead15Fixed16Number(io, &sc ->Channels[i].Frequency)) goto Error;
+        if (!_cmsRead15Fixed16Number(io, &sc ->Channels[i].ScreenAngle)) goto Error;
         if (!_cmsReadUInt32Number(io, &sc ->Channels[i].SpotShape)) goto Error;
     }
 
@@ -3707,7 +3743,7 @@ void *Type_Screening_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
     return (void*) sc;
 
 Error:
-    if (sc != NULL) 
+    if (sc != NULL)
         _cmsFree(self ->ContextID, sc);
 
     return NULL;
@@ -3719,9 +3755,9 @@ Error:
 static
 cmsBool Type_Screening_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems)
 {
-    cmsScreening* sc = (cmsScreening* ) Ptr; 
+    cmsScreening* sc = (cmsScreening* ) Ptr;
     cmsUInt32Number i;
-        
+
     if (!_cmsWriteUInt32Number(io, sc ->Flag)) return FALSE;
     if (!_cmsWriteUInt32Number(io, sc ->nChannels)) return FALSE;
 
@@ -3758,20 +3794,20 @@ void Type_Screening_Free(struct _cms_typehandler_struct* self, void* Ptr)
 // Type cmsSigViewingConditionsType
 // ********************************************************************************
 //
-//This type represents a set of viewing condition parameters including: 
-//CIE \92absolute\92 illuminant white point tristimulus values and CIE \92absolute\92 
+//This type represents a set of viewing condition parameters including:
+//CIE \92absolute\92 illuminant white point tristimulus values and CIE \92absolute\92
 //surround tristimulus values.
 
 static
 void *Type_ViewingConditions_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsUInt32Number* nItems, cmsUInt32Number SizeOfTag)
 {
     cmsICCViewingConditions* vc = NULL;
-    
+
     vc = (cmsICCViewingConditions*) _cmsMallocZero(self ->ContextID, sizeof(cmsICCViewingConditions));
     if (vc == NULL) return NULL;
 
     *nItems = 0;
-        
+
     if (!_cmsReadXYZNumber(io, &vc ->IlluminantXYZ)) goto Error;
     if (!_cmsReadXYZNumber(io, &vc ->SurroundXYZ)) goto Error;
     if (!_cmsReadUInt32Number(io, &vc ->IlluminantType)) goto Error;
@@ -3781,7 +3817,7 @@ void *Type_ViewingConditions_Read(struct _cms_typehandler_struct* self, cmsIOHAN
     return (void*) vc;
 
 Error:
-    if (vc != NULL) 
+    if (vc != NULL)
         _cmsFree(self ->ContextID, vc);
 
     return NULL;
@@ -3793,8 +3829,8 @@ Error:
 static
 cmsBool Type_ViewingConditions_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems)
 {
-    cmsICCViewingConditions* sc = (cmsICCViewingConditions* ) Ptr; 
-            
+    cmsICCViewingConditions* sc = (cmsICCViewingConditions* ) Ptr;
+
     if (!_cmsWriteXYZNumber(io, &sc ->IlluminantXYZ)) return FALSE;
     if (!_cmsWriteXYZNumber(io, &sc ->SurroundXYZ)) return FALSE;
     if (!_cmsWriteUInt32Number(io, sc ->IlluminantType)) return FALSE;
@@ -3838,7 +3874,7 @@ void* GenericMPEdup(struct _cms_typehandler_struct* self, const void *Ptr, cmsUI
 
 static
 void GenericMPEfree(struct _cms_typehandler_struct* self, void *Ptr)
-{    
+{
     cmsStageFree((cmsStage*) Ptr);
     return;
 
@@ -3854,16 +3890,16 @@ void GenericMPEfree(struct _cms_typehandler_struct* self, void *Ptr)
 // Read an embedded segmented curve
 static
 cmsToneCurve* ReadSegmentedCurve(struct _cms_typehandler_struct* self, cmsIOHANDLER* io)
-{   
+{
     cmsCurveSegSignature ElementSig;
     cmsUInt32Number i, j;
     cmsUInt16Number nSegments;
     cmsCurveSegment*  Segments;
     cmsToneCurve* Curve;
     cmsFloat32Number PrevBreak = -1E22F;    // - infinite
+
     // Take signature and channels for each element.
-     if (!_cmsReadUInt32Number(io, (cmsUInt32Number*) &ElementSig)) return NULL;    
+     if (!_cmsReadUInt32Number(io, (cmsUInt32Number*) &ElementSig)) return NULL;
 
      // That should be a segmented curve
      if (ElementSig != cmsSigSegmentedCurve) return NULL;
@@ -3892,11 +3928,11 @@ cmsToneCurve* ReadSegmentedCurve(struct _cms_typehandler_struct* self, cmsIOHAND
 
           if (!_cmsReadUInt32Number(io, (cmsUInt32Number*) &ElementSig)) goto Error;
           if (!_cmsReadUInt32Number(io, NULL)) goto Error;
-         
+
            switch (ElementSig) {
 
             case cmsSigFormulaCurveSeg: {
-                                       
+
                 cmsUInt16Number Type;
                 cmsUInt32Number ParamsByType[] = {4, 5, 5 };
 
@@ -3938,7 +3974,7 @@ cmsToneCurve* ReadSegmentedCurve(struct _cms_typehandler_struct* self, cmsIOHAND
                 _cmsTagSignature2String(String, (cmsTagSignature) ElementSig);
                 cmsSignalError(self->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unknown curve element type '%s' found.", String);
                 }
-                return NULL;                
+                return NULL;
 
          }
      }
@@ -3958,10 +3994,10 @@ Error:
 
 
 static
-cmsBool ReadMPECurve(struct _cms_typehandler_struct* self, 
+cmsBool ReadMPECurve(struct _cms_typehandler_struct* self,
                      cmsIOHANDLER* io,
                      void* Cargo,
-                     cmsUInt32Number n, 
+                     cmsUInt32Number n,
                      cmsUInt32Number SizeOfTag)
 {
       cmsToneCurve** GammaTables = ( cmsToneCurve**) Cargo;
@@ -4021,10 +4057,10 @@ cmsBool WriteSegmentedCurve(cmsIOHANDLER* io, cmsToneCurve* g)
     cmsCurveSegment* Segments = g ->Segments;
     cmsUInt32Number nSegments = g ->nSegments;
 
-    if (!_cmsWriteUInt32Number(io, cmsSigSegmentedCurve)) goto Error;    
-    if (!_cmsWriteUInt32Number(io, 0)) goto Error;  
-    if (!_cmsWriteUInt16Number(io, (cmsUInt16Number) nSegments)) goto Error;    
-    if (!_cmsWriteUInt16Number(io, 0)) goto Error;  
+    if (!_cmsWriteUInt32Number(io, cmsSigSegmentedCurve)) goto Error;
+    if (!_cmsWriteUInt32Number(io, 0)) goto Error;
+    if (!_cmsWriteUInt16Number(io, (cmsUInt16Number) nSegments)) goto Error;
+    if (!_cmsWriteUInt16Number(io, 0)) goto Error;
 
     // Write the break-points
     for (i=0; i < nSegments - 1; i++) {
@@ -4066,7 +4102,7 @@ cmsBool WriteSegmentedCurve(cmsIOHANDLER* io, cmsToneCurve* g)
             for (j=0; j < ParamsByType[Type]; j++) {
                 if (!_cmsWriteFloat32Number(io, (cmsFloat32Number) ActualSeg ->Params[j])) goto Error;
             }
-        }         
+        }
 
         // It seems there is no need to align. Code is here, and for safety commented out
         // if (!_cmsWriteAlignment(io)) goto Error;
@@ -4080,10 +4116,10 @@ Error:
 
 
 static
-cmsBool WriteMPECurve(struct _cms_typehandler_struct* self, 
+cmsBool WriteMPECurve(struct _cms_typehandler_struct* self,
                       cmsIOHANDLER* io,
                       void* Cargo,
-                      cmsUInt32Number n, 
+                      cmsUInt32Number n,
                       cmsUInt32Number SizeOfTag)
 {
     _cmsStageToneCurvesData* Curves  = (_cmsStageToneCurvesData*) Cargo;
@@ -4097,7 +4133,7 @@ cmsBool WriteMPECurve(struct _cms_typehandler_struct* self,
 // Write a curve, checking first for validity
 static
 cmsBool  Type_MPEcurve_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems)
-{   
+{
     cmsUInt32Number BaseOffset;
     cmsStage* mpe = (cmsStage*) Ptr;
     _cmsStageToneCurvesData* Curves = (_cmsStageToneCurvesData*) mpe ->Data;
@@ -4107,8 +4143,8 @@ cmsBool  Type_MPEcurve_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER*
     // Write the header. Since those are curves, input and output channels are same
     if (!_cmsWriteUInt16Number(io, (cmsUInt16Number) mpe ->InputChannels)) return FALSE;
     if (!_cmsWriteUInt16Number(io, (cmsUInt16Number) mpe ->InputChannels)) return FALSE;
-    
-    if (!WritePositionTable(self, io, 0, 
+
+    if (!WritePositionTable(self, io, 0,
                                 mpe ->InputChannels, BaseOffset, Curves, WriteMPECurve)) return FALSE;
 
 
@@ -4129,14 +4165,14 @@ void *Type_MPEmatrix_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
 {
     cmsStage* mpe;
     cmsUInt16Number   InputChans, OutputChans;
-    cmsUInt32Number   nElems, i;  
+    cmsUInt32Number   nElems, i;
     cmsFloat64Number* Matrix;
     cmsFloat64Number* Offsets;
 
     if (!_cmsReadUInt16Number(io, &InputChans)) return NULL;
     if (!_cmsReadUInt16Number(io, &OutputChans)) return NULL;
 
-    
+
     nElems = InputChans * OutputChans;
 
     // Input and output chans may be ANY (up to 0xffff)
@@ -4145,7 +4181,7 @@ void *Type_MPEmatrix_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
 
     Offsets = (cmsFloat64Number*) _cmsCalloc(self ->ContextID, OutputChans, sizeof(cmsFloat64Number));
     if (Offsets == NULL) {
-    
+
         _cmsFree(self ->ContextID, Matrix);
         return NULL;
     }
@@ -4154,7 +4190,7 @@ void *Type_MPEmatrix_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
 
         cmsFloat32Number v;
 
-        if (!_cmsReadFloat32Number(io, &v)) return NULL;        
+        if (!_cmsReadFloat32Number(io, &v)) return NULL;
         Matrix[i] = v;
     }
 
@@ -4163,7 +4199,7 @@ void *Type_MPEmatrix_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io
 
         cmsFloat32Number v;
 
-        if (!_cmsReadFloat32Number(io, &v)) return NULL;        
+        if (!_cmsReadFloat32Number(io, &v)) return NULL;
         Offsets[i] = v;
     }
 
@@ -4186,13 +4222,13 @@ cmsBool  Type_MPEmatrix_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER
     cmsStage* mpe = (cmsStage*) Ptr;
     _cmsStageMatrixData* Matrix = (_cmsStageMatrixData*) mpe ->Data;
 
-    if (!_cmsWriteUInt16Number(io, (cmsUInt16Number) mpe ->InputChannels)) return FALSE;    
+    if (!_cmsWriteUInt16Number(io, (cmsUInt16Number) mpe ->InputChannels)) return FALSE;
     if (!_cmsWriteUInt16Number(io, (cmsUInt16Number) mpe ->OutputChannels)) return FALSE;
 
     nElems = mpe ->InputChannels * mpe ->OutputChannels;
 
     for (i=0; i < nElems; i++) {
-        if (!_cmsWriteFloat32Number(io, (cmsFloat32Number) Matrix->Double[i])) return FALSE;        
+        if (!_cmsWriteFloat32Number(io, (cmsFloat32Number) Matrix->Double[i])) return FALSE;
     }
 
 
@@ -4200,10 +4236,10 @@ cmsBool  Type_MPEmatrix_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER
 
         if (Matrix ->Offset == NULL) {
 
-               if (!_cmsWriteFloat32Number(io, 0)) return FALSE;        
+               if (!_cmsWriteFloat32Number(io, 0)) return FALSE;
         }
         else {
-               if (!_cmsWriteFloat32Number(io, (cmsFloat32Number) Matrix->Offset[i])) return FALSE;        
+               if (!_cmsWriteFloat32Number(io, (cmsFloat32Number) Matrix->Offset[i])) return FALSE;
         }
     }
 
@@ -4223,13 +4259,13 @@ void *Type_MPEclut_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io,
     cmsUInt8Number Dimensions8[16];
     cmsUInt32Number i, nMaxGrids, GridPoints[MAX_INPUT_DIMENSIONS];
     _cmsStageCLutData* clut;
-    
+
     if (!_cmsReadUInt16Number(io, &InputChans)) return NULL;
     if (!_cmsReadUInt16Number(io, &OutputChans)) return NULL;
-    
+
     if (io ->Read(io, Dimensions8, sizeof(cmsUInt8Number), 16) != 16)
         goto Error;
-    
+
     // Copy MAX_INPUT_DIMENSIONS at most. Expand to cmsUInt32Number
     nMaxGrids = InputChans > MAX_INPUT_DIMENSIONS ? MAX_INPUT_DIMENSIONS : InputChans;
     for (i=0; i < nMaxGrids; i++) GridPoints[i] = (cmsUInt32Number) Dimensions8[i];
@@ -4241,11 +4277,11 @@ void *Type_MPEclut_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io,
     // Read the data
     clut = (_cmsStageCLutData*) mpe ->Data;
     for (i=0; i < clut ->nEntries; i++) {
-        
+
         if (!_cmsReadFloat32Number(io, &clut ->Tab.TFloat[i])) goto Error;
     }
 
-    *nItems = 1;    
+    *nItems = 1;
     return mpe;
 
 Error:
@@ -4259,7 +4295,7 @@ Error:
 // Write a CLUT in floating point
 static
 cmsBool  Type_MPEclut_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems)
-{   
+{
     cmsUInt8Number Dimensions8[16];
     cmsUInt32Number i;
     cmsStage* mpe = (cmsStage*) Ptr;
@@ -4267,7 +4303,7 @@ cmsBool  Type_MPEclut_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER*
 
     // Check for maximum number of channels
     if (mpe -> InputChannels > 15) return FALSE;
-    
+
     // Only floats are supported in MPE
     if (clut ->HasFloatValues == FALSE) return FALSE;
 
@@ -4276,13 +4312,13 @@ cmsBool  Type_MPEclut_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER*
 
     memset(Dimensions8, 0, sizeof(Dimensions8));
 
-    for (i=0; i < mpe ->InputChannels; i++) 
+    for (i=0; i < mpe ->InputChannels; i++)
         Dimensions8[i] = (cmsUInt8Number) clut ->Params ->nSamples[i];
 
     if (!io ->Write(io, 16, Dimensions8)) return FALSE;
 
     for (i=0; i < clut ->nEntries; i++) {
-        
+
         if (!_cmsWriteFloat32Number(io, clut ->Tab.TFloat[i])) return FALSE;
     }
 
@@ -4308,10 +4344,10 @@ static _cmsTagTypeLinkedList SupportedMPEtypes[] = {
 #define DEFAULT_MPE_TYPE_COUNT  (sizeof(SupportedMPEtypes) / sizeof(_cmsTagTypeLinkedList))
 
 static
-cmsBool ReadMPEElem(struct _cms_typehandler_struct* self, 
+cmsBool ReadMPEElem(struct _cms_typehandler_struct* self,
                     cmsIOHANDLER* io,
                     void* Cargo,
-                    cmsUInt32Number n, 
+                    cmsUInt32Number n,
                     cmsUInt32Number SizeOfTag)
 {
     cmsStageSignature ElementSig;
@@ -4334,7 +4370,7 @@ cmsBool ReadMPEElem(struct _cms_typehandler_struct* self,
 
         _cmsTagSignature2String(String, (cmsTagSignature) ElementSig);
 
-        // An unknown element was found. 
+        // An unknown element was found.
         cmsSignalError(self ->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unknown MPE type '%s' found.", String);
         return FALSE;
     }
@@ -4361,7 +4397,7 @@ cmsBool ReadMPEElem(struct _cms_typehandler_struct* self,
 // This is the main dispatcher for MPE
 static
 void *Type_MPE_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsUInt32Number* nItems, cmsUInt32Number SizeOfTag)
-{   
+{
     cmsUInt16Number InputChans, OutputChans;
     cmsUInt32Number ElementCount;
     cmsPipeline *NewLUT = NULL;
@@ -4372,8 +4408,8 @@ void *Type_MPE_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsU
 
     // Read channels and element count
     if (!_cmsReadUInt16Number(io, &InputChans)) return NULL;
-    if (!_cmsReadUInt16Number(io, &OutputChans)) return NULL; 
-    
+    if (!_cmsReadUInt16Number(io, &OutputChans)) return NULL;
+
     // Allocates an empty LUT
     NewLUT = cmsPipelineAlloc(self ->ContextID, InputChans, OutputChans);
     if (NewLUT == NULL) return NULL;
@@ -4398,7 +4434,7 @@ void *Type_MPE_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsU
 // This one is a liitle bit more complex, so we don't use position tables this time.
 static
 cmsBool Type_MPE_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems)
-{   
+{
     cmsUInt32Number i, BaseOffset, DirectoryPos, CurrentPos;
     int inputChan, outputChan;
     cmsUInt32Number ElemCount;
@@ -4429,7 +4465,7 @@ cmsBool Type_MPE_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, v
 
     // Write a fake directory to be filled latter on
     for (i=0; i < ElemCount; i++) {
-        if (!_cmsWriteUInt32Number(io, 0)) goto Error;  // Offset 
+        if (!_cmsWriteUInt32Number(io, 0)) goto Error;  // Offset
         if (!_cmsWriteUInt32Number(io, 0)) goto Error;  // size
     }
 
@@ -4447,13 +4483,13 @@ cmsBool Type_MPE_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, v
 
                 _cmsTagSignature2String(String, (cmsTagSignature) ElementSig);
 
-                 // An unknow element was found. 
+                 // An unknow element was found.
                  cmsSignalError(self->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Found unknown MPE type '%s'", String);
                  goto Error;
         }
 
-        if (!_cmsWriteUInt32Number(io, ElementSig)) goto Error;  
-        if (!_cmsWriteUInt32Number(io, 0)) goto Error;  
+        if (!_cmsWriteUInt32Number(io, ElementSig)) goto Error;
+        if (!_cmsWriteUInt32Number(io, 0)) goto Error;
         Before = io ->Tell(io);
         if (!TypeHandler ->WritePtr(self, io, Elem, 1)) goto Error;
         if (!_cmsWriteAlignment(io)) goto Error;
@@ -4469,8 +4505,8 @@ cmsBool Type_MPE_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, v
     if (!io ->Seek(io, DirectoryPos)) goto Error;
 
     for (i=0; i < ElemCount; i++) {
-        if (!_cmsWriteUInt32Number(io, ElementOffsets[i])) goto Error;  
-        if (!_cmsWriteUInt32Number(io, ElementSizes[i])) goto Error;  
+        if (!_cmsWriteUInt32Number(io, ElementOffsets[i])) goto Error;
+        if (!_cmsWriteUInt32Number(io, ElementSizes[i])) goto Error;
     }
 
     if (!io ->Seek(io, CurrentPos)) goto Error;
@@ -4499,7 +4535,7 @@ void* Type_MPE_Dup(struct _cms_typehandler_struct* self, const void *Ptr, cmsUIn
 
 static
 void Type_MPE_Free(struct _cms_typehandler_struct* self, void *Ptr)
-{    
+{
     cmsPipelineFree((cmsPipeline*) Ptr);
     return;
 
@@ -4524,9 +4560,9 @@ typedef struct {
 
 
 static
-void *Type_vcgt_Read(struct _cms_typehandler_struct* self, 
-                     cmsIOHANDLER* io, 
-                     cmsUInt32Number* nItems, 
+void *Type_vcgt_Read(struct _cms_typehandler_struct* self,
+                     cmsIOHANDLER* io,
+                     cmsUInt32Number* nItems,
                      cmsUInt32Number SizeOfTag)
 {
     cmsUInt32Number TagType, n, i;
@@ -4536,7 +4572,7 @@ void *Type_vcgt_Read(struct _cms_typehandler_struct* self,
 
     // Read tag type
     if (!_cmsReadUInt32Number(io, &TagType)) return NULL;
+
     // Allocate space for the array
     Curves = ( cmsToneCurve**) _cmsCalloc(self ->ContextID, 3, sizeof(cmsToneCurve*));
     if (Curves == NULL) return NULL;
@@ -4545,7 +4581,7 @@ void *Type_vcgt_Read(struct _cms_typehandler_struct* self,
     switch (TagType) {
 
     // Gamma is stored as a table
-    case cmsVideoCardGammaTableType: 
+    case cmsVideoCardGammaTableType:
     {
        cmsUInt16Number nChannels, nElems, nBytes;
 
@@ -4554,13 +4590,13 @@ void *Type_vcgt_Read(struct _cms_typehandler_struct* self,
 
        if (nChannels != 3) {
            cmsSignalError(self->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unsupported number of channels for VCGT '%d'", nChannels);
-           goto Error;                               
+           goto Error;
        }
 
        // Get Table element count and bytes per element
        if (!_cmsReadUInt16Number(io, &nElems)) goto Error;
        if (!_cmsReadUInt16Number(io, &nBytes)) goto Error;
-       
+
        // Adobe's quirk fixup. Fixing broken profiles...
        if (nElems == 256 && nBytes == 1 && SizeOfTag == 1576)
            nBytes = 2;
@@ -4594,17 +4630,17 @@ void *Type_vcgt_Read(struct _cms_typehandler_struct* self,
           // Unsupported
            default:
               cmsSignalError(self->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unsupported bit depth for VCGT '%d'", nBytes * 8);
-              goto Error;       
+              goto Error;
            }
        } // For all 3 channels
     }
     break;
 
    // In this case, gamma is stored as a formula
-   case cmsVideoCardGammaFormulaType: 
+   case cmsVideoCardGammaFormulaType:
    {
        _cmsVCGTGAMMA Colorant[3];
-       
+
         // Populate tone curves
        for (n=0; n < 3; n++) {
 
@@ -4613,16 +4649,16 @@ void *Type_vcgt_Read(struct _cms_typehandler_struct* self,
            if (!_cmsRead15Fixed16Number(io, &Colorant[n].Gamma)) goto Error;
            if (!_cmsRead15Fixed16Number(io, &Colorant[n].Min)) goto Error;
            if (!_cmsRead15Fixed16Number(io, &Colorant[n].Max)) goto Error;
-           
+
             // Parametric curve type 5 is:
             // Y = (aX + b)^Gamma + e | X >= d
             // Y = cX + f             | X < d
 
             // vcgt formula is:
             // Y = (Max \96 Min) * (X ^ Gamma) + Min
-            
+
             // So, the translation is
-            // a = (Max \96 Min) ^ ( 1 / Gamma) 
+            // a = (Max \96 Min) ^ ( 1 / Gamma)
             // e = Min
             // b=c=d=f=0
 
@@ -4633,7 +4669,7 @@ void *Type_vcgt_Read(struct _cms_typehandler_struct* self,
            Params[4] = 0;
            Params[5] = Colorant[n].Min;
            Params[6] = 0;
-    
+
            Curves[n] = cmsBuildParametricToneCurve(self ->ContextID, 5, Params);
            if (Curves[n] == NULL) goto Error;
        }
@@ -4641,7 +4677,7 @@ void *Type_vcgt_Read(struct _cms_typehandler_struct* self,
    break;
 
    // Unsupported
-   default: 
+   default:
       cmsSignalError(self->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unsupported tag type for VCGT '%d'", TagType);
       goto Error;
    }
@@ -4671,7 +4707,7 @@ cmsBool Type_vcgt_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io,
         cmsGetToneCurveParametricType(Curves[1]) == 5 &&
         cmsGetToneCurveParametricType(Curves[2]) == 5) {
 
-            if (!_cmsWriteUInt32Number(io, cmsVideoCardGammaFormulaType)) return FALSE;  
+            if (!_cmsWriteUInt32Number(io, cmsVideoCardGammaFormulaType)) return FALSE;
 
             // Save parameters
             for (i=0; i < 3; i++) {
@@ -4691,10 +4727,10 @@ cmsBool Type_vcgt_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io,
     else {
 
         // Always store as a table of 256 words
-        if (!_cmsWriteUInt32Number(io, cmsVideoCardGammaTableType)) return FALSE;    
-        if (!_cmsWriteUInt16Number(io, 3)) return FALSE;    
-        if (!_cmsWriteUInt16Number(io, 256)) return FALSE;    
-        if (!_cmsWriteUInt16Number(io, 2)) return FALSE;    
+        if (!_cmsWriteUInt32Number(io, cmsVideoCardGammaTableType)) return FALSE;
+        if (!_cmsWriteUInt16Number(io, 3)) return FALSE;
+        if (!_cmsWriteUInt16Number(io, 256)) return FALSE;
+        if (!_cmsWriteUInt16Number(io, 2)) return FALSE;
 
         for (i=0; i < 3; i++) {
             for (j=0; j < 256; j++) {
@@ -4702,7 +4738,7 @@ cmsBool Type_vcgt_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io,
                 cmsFloat32Number v = cmsEvalToneCurveFloat(Curves[i], (cmsFloat32Number) (j / 255.0));
                 cmsUInt16Number  n = _cmsQuickSaturateWord(v * 65535.0);
 
-                if (!_cmsWriteUInt16Number(io, n)) return FALSE;    
+                if (!_cmsWriteUInt16Number(io, n)) return FALSE;
             }
         }
     }
@@ -4827,7 +4863,7 @@ cmsBool ReadOneElem(cmsIOHANDLER* io,  _cmsDICelem* e, cmsUInt32Number i, cmsUIn
     if (!_cmsReadUInt32Number(io, &e ->Sizes[i])) return FALSE;
 
     // An offset of zero has special meaning and shal be preserved
-    if (e ->Offsets[i] > 0) 
+    if (e ->Offsets[i] > 0)
         e ->Offsets[i] += BaseOffset;
     return TRUE;
 }
@@ -4847,12 +4883,12 @@ cmsBool ReadOffsetArray(cmsIOHANDLER* io,  _cmsDICarray* a, cmsUInt32Number Coun
         if (Length > 16) {
 
             if (!ReadOneElem(io, &a ->DisplayName, i, BaseOffset)) return FALSE;
+
         }
 
         if (Length > 24) {
 
-            if (!ReadOneElem(io, & a -> DisplayValue, i, BaseOffset)) return FALSE; 
+            if (!ReadOneElem(io, & a -> DisplayValue, i, BaseOffset)) return FALSE;
         }
     }
     return TRUE;
@@ -4886,7 +4922,7 @@ cmsBool WriteOffsetArray(cmsIOHANDLER* io,  _cmsDICarray* a, cmsUInt32Number Cou
 
         if (Length > 24) {
 
-            if (!WriteOneElem(io, &a -> DisplayValue, i))  return FALSE; 
+            if (!WriteOneElem(io, &a -> DisplayValue, i))  return FALSE;
         }
     }
 
@@ -4898,20 +4934,20 @@ cmsBool ReadOneWChar(cmsIOHANDLER* io,  _cmsDICelem* e, cmsUInt32Number i, wchar
 {
 
     cmsUInt32Number nChars;
-      // Special case for undefined strings (see ICC Votable 
+
+      // Special case for undefined strings (see ICC Votable
       // Proposal Submission, Dictionary Type and Metadata TAG Definition)
       if (e -> Offsets[i] == 0) {
 
-          *wcstr = NULL; 
+          *wcstr = NULL;
           return TRUE;
       }
 
       if (!io -> Seek(io, e -> Offsets[i])) return FALSE;
 
       nChars = e ->Sizes[i] / sizeof(cmsUInt16Number);
-     
-      
+
+
       *wcstr = (wchar_t*) _cmsMallocZero(e ->ContextID, (nChars + 1) * sizeof(wchar_t));
       if (*wcstr == NULL) return FALSE;
 
@@ -4925,7 +4961,7 @@ cmsBool ReadOneWChar(cmsIOHANDLER* io,  _cmsDICelem* e, cmsUInt32Number i, wchar
       return TRUE;
 }
 
-static 
+static
 cmsUInt32Number mywcslen(const wchar_t *s)
 {
     const wchar_t *p;
@@ -4943,7 +4979,7 @@ cmsBool WriteOneWChar(cmsIOHANDLER* io,  _cmsDICelem* e, cmsUInt32Number i, cons
     cmsUInt32Number Before = io ->Tell(io);
     cmsUInt32Number n;
 
-    e ->Offsets[i] = Before - BaseOffset;   
+    e ->Offsets[i] = Before - BaseOffset;
 
     if (wcstr == NULL) {
         e ->Sizes[i] = 0;
@@ -4954,7 +4990,7 @@ cmsBool WriteOneWChar(cmsIOHANDLER* io,  _cmsDICelem* e, cmsUInt32Number i, cons
     n = mywcslen(wcstr);
     if (!_cmsWriteWCharArray(io,  n, wcstr)) return FALSE;
 
-    e ->Sizes[i] = io ->Tell(io) - Before;       
+    e ->Sizes[i] = io ->Tell(io) - Before;
     return TRUE;
 }
 
@@ -4965,7 +5001,7 @@ cmsBool ReadOneMLUC(struct _cms_typehandler_struct* self, cmsIOHANDLER* io,  _cm
 
     // A way to get null MLUCs
     if (e -> Offsets[i] == 0 || e ->Sizes[i] == 0) {
-    
+
         *mlu = NULL;
         return TRUE;
     }
@@ -4981,7 +5017,7 @@ cmsBool WriteOneMLUC(struct _cms_typehandler_struct* self, cmsIOHANDLER* io,  _c
 {
     cmsUInt32Number Before;
 
-     // Special case for undefined strings (see ICC Votable 
+     // Special case for undefined strings (see ICC Votable
      // Proposal Submission, Dictionary Type and Metadata TAG Definition)
      if (mlu == NULL) {
         e ->Sizes[i] = 0;
@@ -4990,11 +5026,11 @@ cmsBool WriteOneMLUC(struct _cms_typehandler_struct* self, cmsIOHANDLER* io,  _c
     }
 
     Before = io ->Tell(io);
-    e ->Offsets[i] = Before - BaseOffset;  
+    e ->Offsets[i] = Before - BaseOffset;
 
     if (!Type_MLU_Write(self, io, (void*) mlu, 1)) return FALSE;
 
-    e ->Sizes[i] = io ->Tell(io) - Before;       
+    e ->Sizes[i] = io ->Tell(io) - Before;
     return TRUE;
 }
 
@@ -5016,21 +5052,21 @@ void *Type_Dictionary_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* i
     BaseOffset = io ->Tell(io) - sizeof(_cmsTagBase);
 
     // Get name-value record count
-    if (!_cmsReadUInt32Number(io, &Count)) return NULL;  
+    if (!_cmsReadUInt32Number(io, &Count)) return NULL;
     SizeOfTag -= sizeof(cmsUInt32Number);
 
-    // Get rec lenghth 
-    if (!_cmsReadUInt32Number(io, &Length)) return NULL;  
+    // Get rec lenghth
+    if (!_cmsReadUInt32Number(io, &Length)) return NULL;
     SizeOfTag -= sizeof(cmsUInt32Number);
 
-    // Check for valid lengths    
+    // Check for valid lengths
     if (Length != 16 && Length != 24 && Length != 32) {
          cmsSignalError(self->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unknown record length in dictionary '%d'", Length);
          return NULL;
     }
 
     // Creates an empty dictionary
-    hDict = cmsDictAlloc(self -> ContextID); 
+    hDict = cmsDictAlloc(self -> ContextID);
     if (hDict == NULL) return NULL;
 
     // On depending on record size, create column arrays
@@ -5053,7 +5089,7 @@ void *Type_Dictionary_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* i
             if (!ReadOneMLUC(self, io, &a.DisplayValue, i, &DisplayValueMLU)) goto Error;
         }
 
-        rc = cmsDictAddEntry(hDict, NameWCS, ValueWCS, DisplayNameMLU, DisplayValueMLU); 
+        rc = cmsDictAddEntry(hDict, NameWCS, ValueWCS, DisplayNameMLU, DisplayValueMLU);
 
         if (NameWCS != NULL) _cmsFree(self ->ContextID, NameWCS);
         if (ValueWCS != NULL) _cmsFree(self ->ContextID, ValueWCS);
@@ -5063,11 +5099,11 @@ void *Type_Dictionary_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* i
         if (!rc) return FALSE;
     }
 
-   FreeArray(&a);   
+   FreeArray(&a);
    *nItems = 1;
-   return (void*) hDict; 
+   return (void*) hDict;
 
-Error:   
+Error:
    FreeArray(&a);
    cmsDictFree(hDict);
    return NULL;
@@ -5152,8 +5188,8 @@ Error:
 
 static
 void* Type_Dictionary_Dup(struct _cms_typehandler_struct* self, const void *Ptr, cmsUInt32Number n)
-{   
-    return (void*)  cmsDictDup((cmsHANDLE) Ptr); 
+{
+    return (void*)  cmsDictDup((cmsHANDLE) Ptr);
 
     cmsUNUSED_PARAMETER(n);
     cmsUNUSED_PARAMETER(self);
@@ -5163,7 +5199,7 @@ void* Type_Dictionary_Dup(struct _cms_typehandler_struct* self, const void *Ptr,
 static
 void Type_Dictionary_Free(struct _cms_typehandler_struct* self, void* Ptr)
 {
-    cmsDictFree((cmsHANDLE) Ptr); 
+    cmsDictFree((cmsHANDLE) Ptr);
     cmsUNUSED_PARAMETER(self);
 }
 
@@ -5205,12 +5241,12 @@ static _cmsTagTypeLinkedList SupportedTagTypes[] = {
 {TYPE_HANDLER(cmsCorbisBrokenXYZtype,          XYZ),                 &SupportedTagTypes[27] },
 {TYPE_HANDLER(cmsMonacoBrokenCurveType,        Curve),               &SupportedTagTypes[28] },
 {TYPE_HANDLER(cmsSigProfileSequenceIdType,     ProfileSequenceId),   &SupportedTagTypes[29] },
-{TYPE_HANDLER(cmsSigDictType,                  Dictionary),          &SupportedTagTypes[30] }, 
+{TYPE_HANDLER(cmsSigDictType,                  Dictionary),          &SupportedTagTypes[30] },
 {TYPE_HANDLER(cmsSigVcgtType,                  vcgt),                NULL }
 };
 
 #define DEFAULT_TAG_TYPE_COUNT  (sizeof(SupportedTagTypes) / sizeof(_cmsTagTypeLinkedList))
-                                
+
 // Both kind of plug-ins share same structure
 cmsBool  _cmsRegisterTagTypePlugin(cmsPluginBase* Data)
 {
@@ -5228,7 +5264,7 @@ cmsTagTypeHandler* _cmsGetTagTypeHandler(cmsTagTypeSignature sig)
 {
     return GetHandler(sig, SupportedTagTypes);
 }
-    
+
 // ********************************************************************************
 // Tag support main routines
 // ********************************************************************************
@@ -5244,21 +5280,21 @@ typedef struct _cmsTagLinkedList_st {
 // This is the list of built-in tags
 static _cmsTagLinkedList SupportedTags[] = {
 
-    { cmsSigAToB0Tag,               { 1, 3,  { cmsSigLut16Type,  cmsSigLutAtoBType, cmsSigLut8Type}, DecideLUTtypeA2B}, &SupportedTags[1]},   
+    { cmsSigAToB0Tag,               { 1, 3,  { cmsSigLut16Type,  cmsSigLutAtoBType, cmsSigLut8Type}, DecideLUTtypeA2B}, &SupportedTags[1]},
     { cmsSigAToB1Tag,               { 1, 3,  { cmsSigLut16Type,  cmsSigLutAtoBType, cmsSigLut8Type}, DecideLUTtypeA2B}, &SupportedTags[2]},
     { cmsSigAToB2Tag,               { 1, 3,  { cmsSigLut16Type,  cmsSigLutAtoBType, cmsSigLut8Type}, DecideLUTtypeA2B}, &SupportedTags[3]},
     { cmsSigBToA0Tag,               { 1, 3,  { cmsSigLut16Type,  cmsSigLutBtoAType, cmsSigLut8Type}, DecideLUTtypeB2A}, &SupportedTags[4]},
     { cmsSigBToA1Tag,               { 1, 3,  { cmsSigLut16Type,  cmsSigLutBtoAType, cmsSigLut8Type}, DecideLUTtypeB2A}, &SupportedTags[5]},
     { cmsSigBToA2Tag,               { 1, 3,  { cmsSigLut16Type,  cmsSigLutBtoAType, cmsSigLut8Type}, DecideLUTtypeB2A}, &SupportedTags[6]},
-     
+
     // Allow corbis  and its broken XYZ type
     { cmsSigRedColorantTag,         { 1, 2, { cmsSigXYZType, cmsCorbisBrokenXYZtype }, DecideXYZtype}, &SupportedTags[7]},
     { cmsSigGreenColorantTag,       { 1, 2, { cmsSigXYZType, cmsCorbisBrokenXYZtype }, DecideXYZtype}, &SupportedTags[8]},
     { cmsSigBlueColorantTag,        { 1, 2, { cmsSigXYZType, cmsCorbisBrokenXYZtype }, DecideXYZtype}, &SupportedTags[9]},
-                                   
+
     { cmsSigRedTRCTag,              { 1, 3, { cmsSigCurveType, cmsSigParametricCurveType, cmsMonacoBrokenCurveType }, DecideCurveType}, &SupportedTags[10]},
     { cmsSigGreenTRCTag,            { 1, 3, { cmsSigCurveType, cmsSigParametricCurveType, cmsMonacoBrokenCurveType }, DecideCurveType}, &SupportedTags[11]},
-    { cmsSigBlueTRCTag,             { 1, 3, { cmsSigCurveType, cmsSigParametricCurveType, cmsMonacoBrokenCurveType }, DecideCurveType}, &SupportedTags[12]}, 
+    { cmsSigBlueTRCTag,             { 1, 3, { cmsSigCurveType, cmsSigParametricCurveType, cmsMonacoBrokenCurveType }, DecideCurveType}, &SupportedTags[12]},
 
     { cmsSigCalibrationDateTimeTag, { 1, 1, { cmsSigDateTimeType }, NULL}, &SupportedTags[13]},
     { cmsSigCharTargetTag,          { 1, 1, { cmsSigTextType },     NULL}, &SupportedTags[14]},
@@ -5299,45 +5335,45 @@ static _cmsTagLinkedList SupportedTags[] = {
 
     { cmsSigMeasurementTag,         { 1, 1, { cmsSigMeasurementType }, NULL}, &SupportedTags[39]},
 
-    { cmsSigPs2CRD0Tag,             { 1, 1, { cmsSigDataType }, NULL}, &SupportedTags[40]},          
-    { cmsSigPs2CRD1Tag,             { 1, 1, { cmsSigDataType }, NULL}, &SupportedTags[41]},                     
-    { cmsSigPs2CRD2Tag,             { 1, 1, { cmsSigDataType }, NULL}, &SupportedTags[42]},                    
-    { cmsSigPs2CRD3Tag,             { 1, 1, { cmsSigDataType }, NULL}, &SupportedTags[43]},                    
-    { cmsSigPs2CSATag,              { 1, 1, { cmsSigDataType }, NULL}, &SupportedTags[44]},                    
-    { cmsSigPs2RenderingIntentTag,  { 1, 1, { cmsSigDataType }, NULL}, &SupportedTags[45]},     
+    { cmsSigPs2CRD0Tag,             { 1, 1, { cmsSigDataType }, NULL}, &SupportedTags[40]},
+    { cmsSigPs2CRD1Tag,             { 1, 1, { cmsSigDataType }, NULL}, &SupportedTags[41]},
+    { cmsSigPs2CRD2Tag,             { 1, 1, { cmsSigDataType }, NULL}, &SupportedTags[42]},
+    { cmsSigPs2CRD3Tag,             { 1, 1, { cmsSigDataType }, NULL}, &SupportedTags[43]},
+    { cmsSigPs2CSATag,              { 1, 1, { cmsSigDataType }, NULL}, &SupportedTags[44]},
+    { cmsSigPs2RenderingIntentTag,  { 1, 1, { cmsSigDataType }, NULL}, &SupportedTags[45]},
 
     { cmsSigViewingCondDescTag,     { 1, 3, { cmsSigTextDescriptionType, cmsSigMultiLocalizedUnicodeType, cmsSigTextType}, DecideTextDescType}, &SupportedTags[46]},
 
-    { cmsSigUcrBgTag,               { 1, 1, { cmsSigUcrBgType}, NULL},    &SupportedTags[47]}, 
-    { cmsSigCrdInfoTag,             { 1, 1, { cmsSigCrdInfoType}, NULL},  &SupportedTags[48]}, 
-
-    { cmsSigDToB0Tag,               { 1, 1, { cmsSigMultiProcessElementType}, NULL}, &SupportedTags[49]}, 
-    { cmsSigDToB1Tag,               { 1, 1, { cmsSigMultiProcessElementType}, NULL}, &SupportedTags[50]}, 
-    { cmsSigDToB2Tag,               { 1, 1, { cmsSigMultiProcessElementType}, NULL}, &SupportedTags[51]}, 
-    { cmsSigDToB3Tag,               { 1, 1, { cmsSigMultiProcessElementType}, NULL}, &SupportedTags[52]}, 
-    { cmsSigBToD0Tag,               { 1, 1, { cmsSigMultiProcessElementType}, NULL}, &SupportedTags[53]}, 
-    { cmsSigBToD1Tag,               { 1, 1, { cmsSigMultiProcessElementType}, NULL}, &SupportedTags[54]}, 
-    { cmsSigBToD2Tag,               { 1, 1, { cmsSigMultiProcessElementType}, NULL}, &SupportedTags[55]}, 
-    { cmsSigBToD3Tag,               { 1, 1, { cmsSigMultiProcessElementType}, NULL}, &SupportedTags[56]}, 
-        
-    { cmsSigScreeningDescTag,       { 1, 1, { cmsSigTextDescriptionType },    NULL}, &SupportedTags[57]}, 
-    { cmsSigViewingConditionsTag,   { 1, 1, { cmsSigViewingConditionsType },  NULL}, &SupportedTags[58]}, 
-
-    { cmsSigScreeningTag,           { 1, 1, { cmsSigScreeningType},          NULL }, &SupportedTags[59]},  
-    { cmsSigVcgtTag,                { 1, 1, { cmsSigVcgtType},               NULL }, &SupportedTags[60]}, 
+    { cmsSigUcrBgTag,               { 1, 1, { cmsSigUcrBgType}, NULL},    &SupportedTags[47]},
+    { cmsSigCrdInfoTag,             { 1, 1, { cmsSigCrdInfoType}, NULL},  &SupportedTags[48]},
+
+    { cmsSigDToB0Tag,               { 1, 1, { cmsSigMultiProcessElementType}, NULL}, &SupportedTags[49]},
+    { cmsSigDToB1Tag,               { 1, 1, { cmsSigMultiProcessElementType}, NULL}, &SupportedTags[50]},
+    { cmsSigDToB2Tag,               { 1, 1, { cmsSigMultiProcessElementType}, NULL}, &SupportedTags[51]},
+    { cmsSigDToB3Tag,               { 1, 1, { cmsSigMultiProcessElementType}, NULL}, &SupportedTags[52]},
+    { cmsSigBToD0Tag,               { 1, 1, { cmsSigMultiProcessElementType}, NULL}, &SupportedTags[53]},
+    { cmsSigBToD1Tag,               { 1, 1, { cmsSigMultiProcessElementType}, NULL}, &SupportedTags[54]},
+    { cmsSigBToD2Tag,               { 1, 1, { cmsSigMultiProcessElementType}, NULL}, &SupportedTags[55]},
+    { cmsSigBToD3Tag,               { 1, 1, { cmsSigMultiProcessElementType}, NULL}, &SupportedTags[56]},
+
+    { cmsSigScreeningDescTag,       { 1, 1, { cmsSigTextDescriptionType },    NULL}, &SupportedTags[57]},
+    { cmsSigViewingConditionsTag,   { 1, 1, { cmsSigViewingConditionsType },  NULL}, &SupportedTags[58]},
+
+    { cmsSigScreeningTag,           { 1, 1, { cmsSigScreeningType},          NULL }, &SupportedTags[59]},
+    { cmsSigVcgtTag,                { 1, 1, { cmsSigVcgtType},               NULL }, &SupportedTags[60]},
     { cmsSigMetaTag,                { 1, 1, { cmsSigDictType},               NULL }, &SupportedTags[61]},
-    { cmsSigProfileSequenceIdTag,   { 1, 1, { cmsSigProfileSequenceIdType},  NULL},  NULL}  
+    { cmsSigProfileSequenceIdTag,   { 1, 1, { cmsSigProfileSequenceIdType},  NULL},  NULL}
 
 };
 
 /*
     Not supported                 Why
-    =======================       =========================================                
-    cmsSigOutputResponseTag   ==> WARNING, POSSIBLE PATENT ON THIS SUBJECT!                
-    cmsSigNamedColorTag       ==> Deprecated                                 
-    cmsSigDataTag             ==> Ancient, unused             
-    cmsSigDeviceSettingsTag   ==> Deprecated, useless     
-*/               
+    =======================       =========================================
+    cmsSigOutputResponseTag   ==> WARNING, POSSIBLE PATENT ON THIS SUBJECT!
+    cmsSigNamedColorTag       ==> Deprecated
+    cmsSigDataTag             ==> Ancient, unused
+    cmsSigDeviceSettingsTag   ==> Deprecated, useless
+*/
 
 #define DEFAULT_TAG_COUNT  (sizeof(SupportedTags) / sizeof(_cmsTagLinkedList))
 
@@ -5348,20 +5384,20 @@ cmsBool  _cmsRegisterTagPlugin(cmsPluginBase* Data)
 
 
     if (Data == NULL) {
-    
+
         SupportedTags[DEFAULT_TAG_COUNT-1].Next = NULL;
         return TRUE;
     }
 
-    pt = Anterior = SupportedTags; 
+    pt = Anterior = SupportedTags;
     while (pt != NULL) {
 
         if (Plugin->Signature == pt -> Signature) {
             pt ->Descriptor = Plugin ->Descriptor;  // Replace old behaviour
             return TRUE;
-        }   
+        }
 
-        Anterior = pt;          
+        Anterior = pt;
         pt = pt ->Next;
     }
 
@@ -5369,7 +5405,7 @@ cmsBool  _cmsRegisterTagPlugin(cmsPluginBase* Data)
     if (pt == NULL) return FALSE;
 
     pt ->Signature  = Plugin ->Signature;
-    pt ->Descriptor = Plugin ->Descriptor;  
+    pt ->Descriptor = Plugin ->Descriptor;
     pt ->Next       = NULL;
 
     if (Anterior != NULL) Anterior -> Next = pt;
@@ -5382,7 +5418,7 @@ cmsTagDescriptor* _cmsGetTagDescriptor(cmsTagSignature sig)
 {
     _cmsTagLinkedList* pt;
 
-    for (pt = SupportedTags; 
+    for (pt = SupportedTags;
             pt != NULL;
             pt = pt ->Next) {
 
index 9a7e718..28ee0ae 100644 (file)
@@ -3,22 +3,22 @@
 //  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 
+// 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 
+// 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 
+// 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.
 //
 //---------------------------------------------------------------------------------
@@ -35,7 +35,7 @@ cmsBool SetTextTags(cmsHPROFILE hProfile, const wchar_t* Description)
     cmsMLU *DescriptionMLU, *CopyrightMLU;
     cmsBool  rc = FALSE;
     cmsContext ContextID = cmsGetProfileContextID(hProfile);
-    
+
     DescriptionMLU  = cmsMLUalloc(ContextID, 1);
     CopyrightMLU    = cmsMLUalloc(ContextID, 1);
 
@@ -45,8 +45,8 @@ cmsBool SetTextTags(cmsHPROFILE hProfile, const wchar_t* Description)
     if (!cmsMLUsetWide(CopyrightMLU,    "en", "US", L"No copyright, use freely")) goto Error;
 
     if (!cmsWriteTag(hProfile, cmsSigProfileDescriptionTag,  DescriptionMLU)) goto Error;
-    if (!cmsWriteTag(hProfile, cmsSigCopyrightTag,           CopyrightMLU)) goto Error;     
-        
+    if (!cmsWriteTag(hProfile, cmsSigCopyrightTag,           CopyrightMLU)) goto Error;
+
     rc = TRUE;
 
 Error:
@@ -57,7 +57,7 @@ Error:
         cmsMLUfree(CopyrightMLU);
     return rc;
 }
-    
+
 
 static
 cmsBool  SetSeqDescTag(cmsHPROFILE hProfile, const char* Model)
@@ -72,10 +72,10 @@ cmsBool  SetSeqDescTag(cmsHPROFILE hProfile, const char* Model)
     Seq->seq[0].deviceModel = (cmsSignature) 0;
 
 #ifdef CMS_DONT_USE_INT64
-    Seq->seq[0].attributes[0] = 0;  
-    Seq->seq[0].attributes[1] = 0;  
+    Seq->seq[0].attributes[0] = 0;
+    Seq->seq[0].attributes[1] = 0;
 #else
-    Seq->seq[0].attributes = 0; 
+    Seq->seq[0].attributes = 0;
 #endif
 
     Seq->seq[0].technology = (cmsTechnologySignature) 0;
@@ -84,11 +84,11 @@ cmsBool  SetSeqDescTag(cmsHPROFILE hProfile, const char* Model)
     cmsMLUsetASCII( Seq->seq[0].Model,        cmsNoLanguage, cmsNoCountry, Model);
 
     if (!_cmsWriteProfileSequence(hProfile, Seq)) goto Error;
-    
+
     rc = TRUE;
 
 Error:
-    if (Seq) 
+    if (Seq)
         cmsFreeProfileSequenceDescription(Seq);
 
     return rc;
@@ -103,7 +103,7 @@ cmsHPROFILE CMSEXPORT cmsCreateRGBProfileTHR(cmsContext ContextID,
                                           const cmsCIExyYTRIPLE* Primaries,
                                           cmsToneCurve* const TransferFunction[3])
 {
-    cmsHPROFILE hICC;   
+    cmsHPROFILE hICC;
     cmsMAT3 MColorants;
     cmsCIEXYZTRIPLE Colorants;
     cmsCIExyY MaxWhite;
@@ -120,7 +120,7 @@ cmsHPROFILE CMSEXPORT cmsCreateRGBProfileTHR(cmsContext ContextID,
     cmsSetColorSpace(hICC,       cmsSigRgbData);
     cmsSetPCS(hICC,              cmsSigXYZData);
 
-    cmsSetHeaderRenderingIntent(hICC,  INTENT_PERCEPTUAL); 
+    cmsSetHeaderRenderingIntent(hICC,  INTENT_PERCEPTUAL);
 
 
     // Implement profile using following tags:
@@ -137,7 +137,7 @@ cmsHPROFILE CMSEXPORT cmsCreateRGBProfileTHR(cmsContext ContextID,
     // This conforms a standard RGB DisplayProfile as says ICC, and then I add (As per addendum II)
     // 10 cmsSigChromaticityTag
 
-    
+
     if (!SetTextTags(hICC, L"RGB built-in")) goto Error;
 
     if (WhitePoint) {
@@ -145,9 +145,9 @@ cmsHPROFILE CMSEXPORT cmsCreateRGBProfileTHR(cmsContext ContextID,
         if (!cmsWriteTag(hICC, cmsSigMediaWhitePointTag, cmsD50_XYZ())) goto Error;
 
         cmsxyY2XYZ(&WhitePointXYZ, WhitePoint);
-        _cmsAdaptationMatrix(&CHAD, NULL, &WhitePointXYZ, cmsD50_XYZ());     
+        _cmsAdaptationMatrix(&CHAD, NULL, &WhitePointXYZ, cmsD50_XYZ());
 
-        // This is a V4 tag, but many CMM does read and understand it no matter which version       
+        // This is a V4 tag, but many CMM does read and understand it no matter which version
         if (!cmsWriteTag(hICC, cmsSigChromaticAdaptationTag, (void*) &CHAD)) goto Error;
     }
 
@@ -157,8 +157,8 @@ cmsHPROFILE CMSEXPORT cmsCreateRGBProfileTHR(cmsContext ContextID,
         MaxWhite.y =  WhitePoint -> y;
         MaxWhite.Y =  1.0;
 
-        if (!_cmsBuildRGB2XYZtransferMatrix(&MColorants, &MaxWhite, Primaries)) goto Error;         
-        
+        if (!_cmsBuildRGB2XYZtransferMatrix(&MColorants, &MaxWhite, Primaries)) goto Error;
+
         Colorants.Red.X   = MColorants.v[0].n[0];
         Colorants.Red.Y   = MColorants.v[1].n[0];
         Colorants.Red.Z   = MColorants.v[2].n[0];
@@ -178,7 +178,7 @@ cmsHPROFILE CMSEXPORT cmsCreateRGBProfileTHR(cmsContext ContextID,
 
 
     if (TransferFunction) {
-    
+
         if (!cmsWriteTag(hICC, cmsSigRedTRCTag,   (void*) TransferFunction[0])) goto Error;
         if (!cmsWriteTag(hICC, cmsSigGreenTRCTag, (void*) TransferFunction[1])) goto Error;
         if (!cmsWriteTag(hICC, cmsSigBlueTRCTag,  (void*) TransferFunction[2])) goto Error;
@@ -212,7 +212,7 @@ cmsHPROFILE CMSEXPORT cmsCreateGrayProfileTHR(cmsContext ContextID,
                                            const cmsToneCurve* TransferFunction)
 {
     cmsHPROFILE hICC;
-    cmsCIEXYZ tmp;              
+    cmsCIEXYZ tmp;
 
     hICC = cmsCreateProfilePlaceholder(ContextID);
     if (!hICC)                          // can't allocate
@@ -223,7 +223,7 @@ cmsHPROFILE CMSEXPORT cmsCreateGrayProfileTHR(cmsContext ContextID,
     cmsSetDeviceClass(hICC,      cmsSigDisplayClass);
     cmsSetColorSpace(hICC,       cmsSigGrayData);
     cmsSetPCS(hICC,              cmsSigXYZData);
-    cmsSetHeaderRenderingIntent(hICC,  INTENT_PERCEPTUAL); 
+    cmsSetHeaderRenderingIntent(hICC,  INTENT_PERCEPTUAL);
 
 
     // Implement profile using following tags:
@@ -232,7 +232,7 @@ cmsHPROFILE CMSEXPORT cmsCreateGrayProfileTHR(cmsContext ContextID,
     //  2 cmsSigMediaWhitePointTag
     //  3 cmsSigGrayTRCTag
 
-    // This conforms a standard Gray DisplayProfile 
+    // This conforms a standard Gray DisplayProfile
 
     // Fill-in the tags
 
@@ -278,7 +278,7 @@ cmsHPROFILE CMSEXPORT cmsCreateLinearizationDeviceLinkTHR(cmsContext ContextID,
     int nChannels;
 
     hICC = cmsCreateProfilePlaceholder(ContextID);
-    if (!hICC)                          
+    if (!hICC)
         return NULL;
 
     cmsSetProfileVersion(hICC, 4.3);
@@ -287,7 +287,7 @@ cmsHPROFILE CMSEXPORT cmsCreateLinearizationDeviceLinkTHR(cmsContext ContextID,
     cmsSetColorSpace(hICC,       ColorSpace);
     cmsSetPCS(hICC,              ColorSpace);
 
-    cmsSetHeaderRenderingIntent(hICC,  INTENT_PERCEPTUAL); 
+    cmsSetHeaderRenderingIntent(hICC,  INTENT_PERCEPTUAL);
 
     // Set up channels
     nChannels = cmsChannelsOf(ColorSpace);
@@ -303,9 +303,9 @@ cmsHPROFILE CMSEXPORT cmsCreateLinearizationDeviceLinkTHR(cmsContext ContextID,
 
     cmsPipelineInsertStage(Pipeline, cmsAT_BEGIN, Lin);
 
-    // Create tags       
-    if (!SetTextTags(hICC, L"Linearization built-in")) goto Error;    
-    if (!cmsWriteTag(hICC, cmsSigAToB0Tag, (void*) Pipeline)) goto Error;       
+    // Create tags
+    if (!SetTextTags(hICC, L"Linearization built-in")) goto Error;
+    if (!cmsWriteTag(hICC, cmsSigAToB0Tag, (void*) Pipeline)) goto Error;
     if (!SetSeqDescTag(hICC, "Linearization built-in")) goto Error;
 
     // Pipeline is already on virtual profile
@@ -330,13 +330,13 @@ cmsHPROFILE CMSEXPORT cmsCreateLinearizationDeviceLink(cmsColorSpaceSignature Co
 
 // Ink-limiting algorithm
 //
-//  Sum = C + M + Y + K 
-//  If Sum > InkLimit 
+//  Sum = C + M + Y + K
+//  If Sum > InkLimit
 //        Ratio= 1 - (Sum - InkLimit) / (C + M + Y)
-//        if Ratio <0 
+//        if Ratio <0
 //              Ratio=0
-//        endif     
-//     Else 
+//        endif
+//     Else
 //         Ratio=1
 //     endif
 //
@@ -354,7 +354,7 @@ int InkLimitingSampler(register const cmsUInt16Number In[], register cmsUInt16Nu
     InkLimit = (InkLimit * 655.35);
 
     SumCMY   = In[0]  + In[1] + In[2];
-    SumCMYK  = SumCMY + In[3];      
+    SumCMYK  = SumCMY + In[3];
 
     if (SumCMYK > InkLimit) {
 
@@ -375,7 +375,7 @@ int InkLimitingSampler(register const cmsUInt16Number In[], register cmsUInt16Nu
 
 // This is a devicelink operating in CMYK for ink-limiting
 
-cmsHPROFILE CMSEXPORT cmsCreateInkLimitingDeviceLinkTHR(cmsContext ContextID, 
+cmsHPROFILE CMSEXPORT cmsCreateInkLimitingDeviceLinkTHR(cmsContext ContextID,
                                                      cmsColorSpaceSignature ColorSpace,
                                                      cmsFloat64Number Limit)
 {
@@ -383,7 +383,7 @@ cmsHPROFILE CMSEXPORT cmsCreateInkLimitingDeviceLinkTHR(cmsContext ContextID,
     cmsPipeline* LUT;
     cmsStage* CLUT;
     int nChannels;
-    
+
     if (ColorSpace != cmsSigCmykData) {
         cmsSignalError(ContextID, cmsERROR_COLORSPACE_CHECK, "InkLimiting: Only CMYK currently supported");
         return NULL;
@@ -391,7 +391,7 @@ cmsHPROFILE CMSEXPORT cmsCreateInkLimitingDeviceLinkTHR(cmsContext ContextID,
 
     if (Limit < 0.0 || Limit > 400) {
 
-        cmsSignalError(ContextID, cmsERROR_RANGE, "InkLimiting: Limit should be between 0..400");        
+        cmsSignalError(ContextID, cmsERROR_RANGE, "InkLimiting: Limit should be between 0..400");
         if (Limit < 0) Limit = 0;
         if (Limit > 400) Limit = 400;
 
@@ -407,22 +407,22 @@ cmsHPROFILE CMSEXPORT cmsCreateInkLimitingDeviceLinkTHR(cmsContext ContextID,
     cmsSetColorSpace(hICC,       ColorSpace);
     cmsSetPCS(hICC,              ColorSpace);
 
-    cmsSetHeaderRenderingIntent(hICC,  INTENT_PERCEPTUAL); 
+    cmsSetHeaderRenderingIntent(hICC,  INTENT_PERCEPTUAL);
 
 
     // Creates a Pipeline with 3D grid only
     LUT = cmsPipelineAlloc(ContextID, 4, 4);
     if (LUT == NULL) goto Error;
-    
+
 
     nChannels = cmsChannelsOf(ColorSpace);
-    
+
     CLUT = cmsStageAllocCLut16bit(ContextID, 17, nChannels, nChannels, NULL);
     if (CLUT == NULL) goto Error;
 
     if (!cmsStageSampleCLut16bit(CLUT, InkLimitingSampler, (void*) &Limit, 0)) goto Error;
 
-    cmsPipelineInsertStage(LUT, cmsAT_BEGIN, _cmsStageAllocIdentityCurves(ContextID, nChannels));  
+    cmsPipelineInsertStage(LUT, cmsAT_BEGIN, _cmsStageAllocIdentityCurves(ContextID, nChannels));
     cmsPipelineInsertStage(LUT, cmsAT_END, CLUT);
     cmsPipelineInsertStage(LUT, cmsAT_END, _cmsStageAllocIdentityCurves(ContextID, nChannels));
 
@@ -431,7 +431,7 @@ cmsHPROFILE CMSEXPORT cmsCreateInkLimitingDeviceLinkTHR(cmsContext ContextID,
 
     if (!cmsWriteTag(hICC, cmsSigAToB0Tag, (void*) LUT))  goto Error;
     if (!SetSeqDescTag(hICC, "ink-limiting built-in")) goto Error;
-     
+
     // cmsPipeline is already on virtual profile
     cmsPipelineFree(LUT);
 
@@ -457,9 +457,9 @@ cmsHPROFILE CMSEXPORT cmsCreateInkLimitingDeviceLink(cmsColorSpaceSignature Colo
 // Creates a fake Lab identity.
 cmsHPROFILE CMSEXPORT cmsCreateLab2ProfileTHR(cmsContext ContextID, const cmsCIExyY* WhitePoint)
 {
-    cmsHPROFILE hProfile;        
+    cmsHPROFILE hProfile;
     cmsPipeline* LUT = NULL;
-    
+
     hProfile = cmsCreateRGBProfileTHR(ContextID, WhitePoint == NULL ? cmsD50_xyY() : WhitePoint, NULL, NULL);
     if (hProfile == NULL) return NULL;
 
@@ -503,9 +503,9 @@ cmsHPROFILE CMSEXPORT cmsCreateLab2Profile(const cmsCIExyY* WhitePoint)
 // Creates a fake Lab V4 identity.
 cmsHPROFILE CMSEXPORT cmsCreateLab4ProfileTHR(cmsContext ContextID, const cmsCIExyY* WhitePoint)
 {
-    cmsHPROFILE hProfile;        
+    cmsHPROFILE hProfile;
     cmsPipeline* LUT = NULL;
-    
+
     hProfile = cmsCreateRGBProfileTHR(ContextID, WhitePoint == NULL ? cmsD50_xyY() : WhitePoint, NULL, NULL);
     if (hProfile == NULL) return NULL;
 
@@ -548,9 +548,9 @@ cmsHPROFILE CMSEXPORT cmsCreateLab4Profile(const cmsCIExyY* WhitePoint)
 // Creates a fake XYZ identity
 cmsHPROFILE CMSEXPORT cmsCreateXYZProfileTHR(cmsContext ContextID)
 {
-    cmsHPROFILE hProfile;        
+    cmsHPROFILE hProfile;
     cmsPipeline* LUT = NULL;
-    
+
     hProfile = cmsCreateRGBProfileTHR(ContextID, cmsD50_xyY(), NULL, NULL);
     if (hProfile == NULL) return NULL;
 
@@ -615,12 +615,12 @@ cmsToneCurve* Build_sRGBGamma(cmsContext ContextID)
     Parameters[1] = 1. / 1.055;
     Parameters[2] = 0.055 / 1.055;
     Parameters[3] = 1. / 12.92;
-    Parameters[4] = 0.04045;    
+    Parameters[4] = 0.04045;
 
     return cmsBuildParametricToneCurve(ContextID, 4, Parameters);
 }
 
-// Create the ICC virtual profile for sRGB space 
+// Create the ICC virtual profile for sRGB space
 cmsHPROFILE CMSEXPORT cmsCreate_sRGBProfileTHR(cmsContext ContextID)
 {
        cmsCIExyY       D65;
@@ -631,11 +631,11 @@ cmsHPROFILE CMSEXPORT cmsCreate_sRGBProfileTHR(cmsContext ContextID)
                                    };
        cmsToneCurve* Gamma22[3];
        cmsHPROFILE  hsRGB;
+
        cmsWhitePointFromTemp(&D65, 6504);
        Gamma22[0] = Gamma22[1] = Gamma22[2] = Build_sRGBGamma(ContextID);
        if (Gamma22[0] == NULL) return NULL;
-           
+
        hsRGB = cmsCreateRGBProfileTHR(ContextID, &D65, &Rec709Primaries, Gamma22);
        cmsFreeToneCurve(Gamma22[0]);
        if (hsRGB == NULL) return NULL;
@@ -672,31 +672,31 @@ int bchswSampler(register const cmsUInt16Number In[], register cmsUInt16Number O
     cmsCIELCh LChIn, LChOut;
     cmsCIEXYZ XYZ;
     LPBCHSWADJUSTS bchsw = (LPBCHSWADJUSTS) Cargo;
-    
+
 
     cmsLabEncoded2Float(&LabIn, In);
-    
+
 
     cmsLab2LCh(&LChIn, &LabIn);
 
     // Do some adjusts on LCh
-    
+
     LChOut.L = LChIn.L * bchsw ->Contrast + bchsw ->Brightness;
     LChOut.C = LChIn.C + bchsw -> Saturation;
     LChOut.h = LChIn.h + bchsw -> Hue;
-    
-        
+
+
     cmsLCh2Lab(&LabOut, &LChOut);
 
     // Move white point in Lab
 
     cmsLab2XYZ(&bchsw ->WPsrc,  &XYZ, &LabOut);
     cmsXYZ2Lab(&bchsw ->WPdest, &LabOut, &XYZ);
-    
+
     // Back to encoded
 
     cmsFloat2LabEncoded(Out, &LabOut);
-    
+
     return TRUE;
 }
 
@@ -706,11 +706,11 @@ int bchswSampler(register const cmsUInt16Number In[], register cmsUInt16Number O
 
 cmsHPROFILE CMSEXPORT cmsCreateBCHSWabstractProfileTHR(cmsContext ContextID,
                                                      int nLUTPoints,
-                                                     cmsFloat64Number Bright, 
+                                                     cmsFloat64Number Bright,
                                                      cmsFloat64Number Contrast,
                                                      cmsFloat64Number Hue,
                                                      cmsFloat64Number Saturation,
-                                                     int TempSrc, 
+                                                     int TempSrc,
                                                      int TempDest)
 {
      cmsHPROFILE hICC;
@@ -726,25 +726,25 @@ cmsHPROFILE CMSEXPORT cmsCreateBCHSWabstractProfileTHR(cmsContext ContextID,
      bchsw.Contrast   = Contrast;
      bchsw.Hue        = Hue;
      bchsw.Saturation = Saturation;
-     
-     cmsWhitePointFromTemp(&WhitePnt, TempSrc );         
+
+     cmsWhitePointFromTemp(&WhitePnt, TempSrc );
      cmsxyY2XYZ(&bchsw.WPsrc, &WhitePnt);
 
      cmsWhitePointFromTemp(&WhitePnt, TempDest);
      cmsxyY2XYZ(&bchsw.WPdest, &WhitePnt);
-    
+
       hICC = cmsCreateProfilePlaceholder(ContextID);
        if (!hICC)                          // can't allocate
             return NULL;
-              
+
 
        cmsSetDeviceClass(hICC,      cmsSigAbstractClass);
        cmsSetColorSpace(hICC,       cmsSigLabData);
        cmsSetPCS(hICC,              cmsSigLabData);
 
-       cmsSetHeaderRenderingIntent(hICC,  INTENT_PERCEPTUAL); 
+       cmsSetHeaderRenderingIntent(hICC,  INTENT_PERCEPTUAL);
+
 
-      
        // Creates a Pipeline with 3D grid only
        Pipeline = cmsPipelineAlloc(ContextID, 3, 3);
        if (Pipeline == NULL) {
@@ -755,26 +755,26 @@ cmsHPROFILE CMSEXPORT cmsCreateBCHSWabstractProfileTHR(cmsContext ContextID,
        for (i=0; i < MAX_INPUT_DIMENSIONS; i++) Dimensions[i] = nLUTPoints;
        CLUT = cmsStageAllocCLut16bitGranular(ContextID, Dimensions, 3, 3, NULL);
        if (CLUT == NULL) return NULL;
-    
-       
+
+
        if (!cmsStageSampleCLut16bit(CLUT, bchswSampler, (void*) &bchsw, 0)) {
 
                 // Shouldn't reach here
                 cmsPipelineFree(Pipeline);
                 cmsCloseProfile(hICC);
                 return NULL;
-       }    
+       }
 
        cmsPipelineInsertStage(Pipeline, cmsAT_END, CLUT);
 
        // Create tags
-        
-       if (!SetTextTags(hICC, L"BCHS built-in")) return NULL;    
-       
+
+       if (!SetTextTags(hICC, L"BCHS built-in")) return NULL;
+
        cmsWriteTag(hICC, cmsSigMediaWhitePointTag, (void*) cmsD50_XYZ());
 
        cmsWriteTag(hICC, cmsSigAToB0Tag, (void*) Pipeline);
-       
+
        // Pipeline is already on virtual profile
        cmsPipelineFree(Pipeline);
 
@@ -784,22 +784,22 @@ cmsHPROFILE CMSEXPORT cmsCreateBCHSWabstractProfileTHR(cmsContext ContextID,
 
 
 CMSAPI cmsHPROFILE   CMSEXPORT cmsCreateBCHSWabstractProfile(int nLUTPoints,
-                                                             cmsFloat64Number Bright, 
+                                                             cmsFloat64Number Bright,
                                                              cmsFloat64Number Contrast,
                                                              cmsFloat64Number Hue,
                                                              cmsFloat64Number Saturation,
-                                                             int TempSrc, 
+                                                             int TempSrc,
                                                              int TempDest)
 {
     return cmsCreateBCHSWabstractProfileTHR(NULL, nLUTPoints, Bright, Contrast, Hue, Saturation, TempSrc, TempDest);
 }
 
 
-// Creates a fake NULL profile. This profile return 1 channel as always 0. 
+// Creates a fake NULL profile. This profile return 1 channel as always 0.
 // Is useful only for gamut checking tricks
 cmsHPROFILE CMSEXPORT cmsCreateNULLProfileTHR(cmsContext ContextID)
 {
-    cmsHPROFILE hProfile;        
+    cmsHPROFILE hProfile;
     cmsPipeline* LUT = NULL;
     cmsStage* PostLin;
     cmsToneCurve* EmptyTab;
@@ -811,9 +811,9 @@ cmsHPROFILE CMSEXPORT cmsCreateNULLProfileTHR(cmsContext ContextID)
 
     cmsSetProfileVersion(hProfile, 4.3);
 
-    if (!SetTextTags(hProfile, L"NULL profile built-in")) goto Error;    
+    if (!SetTextTags(hProfile, L"NULL profile built-in")) goto Error;
+
 
-    
 
     cmsSetDeviceClass(hProfile, cmsSigOutputClass);
     cmsSetColorSpace(hProfile,  cmsSigGrayData);
@@ -823,7 +823,7 @@ cmsHPROFILE CMSEXPORT cmsCreateNULLProfileTHR(cmsContext ContextID)
     LUT = cmsPipelineAlloc(ContextID, 1, 1);
     if (LUT == NULL) goto Error;
 
-    EmptyTab = cmsBuildTabulatedToneCurve16(ContextID, 2, Zero);       
+    EmptyTab = cmsBuildTabulatedToneCurve16(ContextID, 2, Zero);
     PostLin = cmsStageAllocToneCurves(ContextID, 1, &EmptyTab);
     cmsFreeToneCurve(EmptyTab);
 
@@ -832,7 +832,7 @@ cmsHPROFILE CMSEXPORT cmsCreateNULLProfileTHR(cmsContext ContextID)
     if (!cmsWriteTag(hProfile, cmsSigBToA0Tag, (void*) LUT)) goto Error;
     if (!cmsWriteTag(hProfile, cmsSigMediaWhitePointTag, cmsD50_XYZ())) goto Error;
 
-    cmsPipelineFree(LUT);       
+    cmsPipelineFree(LUT);
     return hProfile;
 
 Error:
@@ -861,14 +861,14 @@ int IsPCS(cmsColorSpaceSignature ColorSpace)
 
 
 static
-void FixColorSpaces(cmsHPROFILE hProfile, 
-                              cmsColorSpaceSignature ColorSpace, 
+void FixColorSpaces(cmsHPROFILE hProfile,
+                              cmsColorSpaceSignature ColorSpace,
                               cmsColorSpaceSignature PCS,
                               cmsUInt32Number dwFlags)
 {
     if (dwFlags & cmsFLAGS_GUESSDEVICECLASS) {
 
-            if (IsPCS(ColorSpace) && IsPCS(PCS)) { 
+            if (IsPCS(ColorSpace) && IsPCS(PCS)) {
 
                     cmsSetDeviceClass(hProfile,      cmsSigAbstractClass);
                     cmsSetColorSpace(hProfile,       ColorSpace);
@@ -880,7 +880,7 @@ void FixColorSpaces(cmsHPROFILE hProfile,
 
                     cmsSetDeviceClass(hProfile, cmsSigOutputClass);
                     cmsSetPCS(hProfile,         ColorSpace);
-                    cmsSetColorSpace(hProfile,  PCS);        
+                    cmsSetColorSpace(hProfile,  PCS);
                     return;
             }
 
@@ -908,7 +908,7 @@ static
 cmsHPROFILE CreateNamedColorDevicelink(cmsHTRANSFORM xform)
 {
     _cmsTRANSFORM* v = (_cmsTRANSFORM*) xform;
-    cmsHPROFILE hICC = NULL;  
+    cmsHPROFILE hICC = NULL;
     int i, nColors;
     cmsNAMEDCOLORLIST *nc2 = NULL, *Original = NULL;
 
@@ -922,7 +922,7 @@ cmsHPROFILE CreateNamedColorDevicelink(cmsHTRANSFORM xform)
     cmsSetPCS(hICC, cmsSigLabData);
 
     // Tag profile with information
-    if (!SetTextTags(hICC, L"Named color devicelink")) goto Error;    
+    if (!SetTextTags(hICC, L"Named color devicelink")) goto Error;
 
     Original = cmsGetNamedColorList(xform);
     if (Original == NULL) goto Error;
@@ -931,9 +931,14 @@ cmsHPROFILE CreateNamedColorDevicelink(cmsHTRANSFORM xform)
     nc2     = cmsDupNamedColorList(Original);
     if (nc2 == NULL) goto Error;
 
-    // Colorant count now depends on the output space 
+    // Colorant count now depends on the output space
     nc2 ->ColorantCount = cmsPipelineOutputChannels(v ->Lut);
 
+    // Make sure we have proper formatters
+    cmsChangeBuffersFormat(xform, TYPE_NAMED_COLOR_INDEX,
+        FLOAT_SH(0) | COLORSPACE_SH(_cmsLCMScolorSpace(v ->ExitColorSpace))
+        | BYTES_SH(2) | CHANNELS_SH(cmsChannelsOf(v ->ExitColorSpace)));
+
     // Apply the transfor to colorants.
     for (i=0; i < nColors; i++) {
         cmsDoTransform(xform, &i, nc2 ->List[i].DeviceColorant, 1);
@@ -987,14 +992,14 @@ cmsBool CheckOne(const cmsAllowedLUT* Tab, const cmsPipeline* Lut)
     for (n=0, mpe = Lut ->Elements; mpe != NULL; mpe = mpe ->Next, n++) {
 
         if (n > Tab ->nTypes) return FALSE;
-        if (cmsStageType(mpe) != Tab ->MpeTypes[n]) return FALSE;             
+        if (cmsStageType(mpe) != Tab ->MpeTypes[n]) return FALSE;
     }
 
     return (n == Tab ->nTypes);
 }
 
 
-static 
+static
 const cmsAllowedLUT* FindCombination(const cmsPipeline* Lut, cmsBool IsV4, cmsTagSignature DestinationTag)
 {
     cmsUInt32Number n;
@@ -1011,7 +1016,7 @@ const cmsAllowedLUT* FindCombination(const cmsPipeline* Lut, cmsBool IsV4, cmsTa
 
     return NULL;
 }
-    
+
 
 // Does convert a transform into a device link profile
 cmsHPROFILE CMSEXPORT cmsTransform2DeviceLink(cmsHTRANSFORM hTransform, cmsFloat64Number Version, cmsUInt32Number dwFlags)
@@ -1027,10 +1032,10 @@ cmsHPROFILE CMSEXPORT cmsTransform2DeviceLink(cmsHTRANSFORM hTransform, cmsFloat
     cmsTagSignature DestinationTag;
 
     _cmsAssert(hTransform != NULL);
-    
+
     // Get the first mpe to check for named color
     mpe = cmsPipelineGetPtrToFirstStage(xform ->Lut);
-    
+
     // Check if is a named color transform
     if (mpe != NULL) {
 
@@ -1046,22 +1051,22 @@ cmsHPROFILE CMSEXPORT cmsTransform2DeviceLink(cmsHTRANSFORM hTransform, cmsFloat
     // Time to fix the Lab2/Lab4 issue.
     if ((xform ->EntryColorSpace == cmsSigLabData) && (Version < 4.0)) {
 
-        cmsPipelineInsertStage(LUT, cmsAT_BEGIN, _cmsStageAllocLabV2ToV4curves(ContextID));        
+        cmsPipelineInsertStage(LUT, cmsAT_BEGIN, _cmsStageAllocLabV2ToV4curves(ContextID));
     }
 
     // On the output side too
     if ((xform ->ExitColorSpace) == cmsSigLabData && (Version < 4.0)) {
 
-        cmsPipelineInsertStage(LUT, cmsAT_END, _cmsStageAllocLabV4ToV2(ContextID));        
+        cmsPipelineInsertStage(LUT, cmsAT_END, _cmsStageAllocLabV4ToV2(ContextID));
     }
-   
+
 
     hProfile = cmsCreateProfilePlaceholder(ContextID);
-    if (!hProfile) goto Error;                    // can't allocate        
-    
+    if (!hProfile) goto Error;                    // can't allocate
+
     cmsSetProfileVersion(hProfile, Version);
 
-    FixColorSpaces(hProfile, xform -> EntryColorSpace, xform -> ExitColorSpace, dwFlags);   
+    FixColorSpaces(hProfile, xform -> EntryColorSpace, xform -> ExitColorSpace, dwFlags);
 
     // Optimize the LUT and precalculate a devicelink
 
@@ -1101,11 +1106,11 @@ cmsHPROFILE CMSEXPORT cmsTransform2DeviceLink(cmsHTRANSFORM hTransform, cmsFloat
         _cmsOptimizePipeline(&LUT, xform ->RenderingIntent, &FrmIn, &FrmOut, &dwFlags);
 
         // Put identity curves if needed
-        if (cmsPipelineStageCount(LUT) == 1) {
+        if (cmsPipelineGetPtrToFirstStage(LUT) ->Type != cmsSigCurveSetElemType)
+             cmsPipelineInsertStage(LUT, cmsAT_BEGIN, _cmsStageAllocIdentityCurves(ContextID, ChansIn));
 
-            cmsPipelineInsertStage(LUT, cmsAT_BEGIN, _cmsStageAllocIdentityCurves(ContextID, ChansIn));    
-            cmsPipelineInsertStage(LUT, cmsAT_END,   _cmsStageAllocIdentityCurves(ContextID, ChansOut));   
-        }
+        if (cmsPipelineGetPtrToLastStage(LUT) ->Type != cmsSigCurveSetElemType)
+             cmsPipelineInsertStage(LUT, cmsAT_END,   _cmsStageAllocIdentityCurves(ContextID, ChansOut));
 
         AllowedLUT = FindCombination(LUT, Version >= 4.0, DestinationTag);
     }
@@ -1115,17 +1120,17 @@ cmsHPROFILE CMSEXPORT cmsTransform2DeviceLink(cmsHTRANSFORM hTransform, cmsFloat
         goto Error;
     }
 
-    if (dwFlags & cmsFLAGS_8BITS_DEVICELINK) 
+
+    if (dwFlags & cmsFLAGS_8BITS_DEVICELINK)
                      cmsPipelineSetSaveAs8bitsFlag(LUT, TRUE);
-        
+
     // Tag profile with information
-    if (!SetTextTags(hProfile, L"devicelink")) goto Error;    
+    if (!SetTextTags(hProfile, L"devicelink")) goto Error;
 
-    // Store result            
+    // Store result
     if (!cmsWriteTag(hProfile, DestinationTag, LUT)) goto Error;
-     
-    
+
+
     if (xform -> InputColorant != NULL) {
            if (!cmsWriteTag(hProfile, cmsSigColorantTableTag, xform->InputColorant)) goto Error;
     }
@@ -1133,16 +1138,16 @@ cmsHPROFILE CMSEXPORT cmsTransform2DeviceLink(cmsHTRANSFORM hTransform, cmsFloat
     if (xform -> OutputColorant != NULL) {
            if (!cmsWriteTag(hProfile, cmsSigColorantTableOutTag, xform->OutputColorant)) goto Error;
     }
-    
+
     if (xform ->Sequence != NULL) {
         if (!_cmsWriteProfileSequence(hProfile, xform ->Sequence)) goto Error;
     }
 
-    cmsPipelineFree(LUT);       
+    cmsPipelineFree(LUT);
     return hProfile;
 
 Error:
-    if (LUT != NULL) cmsPipelineFree(LUT);       
+    if (LUT != NULL) cmsPipelineFree(LUT);
     cmsCloseProfile(hProfile);
     return NULL;
 }
index a52c929..e85df95 100644 (file)
@@ -3,22 +3,22 @@
 //  Little Color Management System
 //  Copyright (c) 1998-2010 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 
+// 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 
+// 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 
+// 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.
 //
 //---------------------------------------------------------------------------------
@@ -95,15 +95,15 @@ cmsBool  CMSEXPORT cmsWhitePointFromTemp(cmsCIExyY* WhitePoint, cmsFloat64Number
 
 typedef struct {
 
-    cmsFloat64Number mirek;  // temp (in microreciprocal kelvin) 
-    cmsFloat64Number ut;     // u coord of intersection w/ blackbody locus  
-    cmsFloat64Number vt;     // v coord of intersection w/ blackbody locus 
-    cmsFloat64Number tt;     // slope of ISOTEMPERATURE. line 
+    cmsFloat64Number mirek;  // temp (in microreciprocal kelvin)
+    cmsFloat64Number ut;     // u coord of intersection w/ blackbody locus
+    cmsFloat64Number vt;     // v coord of intersection w/ blackbody locus
+    cmsFloat64Number tt;     // slope of ISOTEMPERATURE. line
 
     } ISOTEMPERATURE;
 
 static ISOTEMPERATURE isotempdata[] = {
-//  {Mirek, Ut,       Vt,      Tt      } 
+//  {Mirek, Ut,       Vt,      Tt      }
     {0,     0.18006,  0.26352,  -0.24341},
     {10,    0.18066,  0.26589,  -0.25479},
     {20,    0.18133,  0.26846,  -0.26876},
@@ -155,7 +155,7 @@ cmsBool  CMSEXPORT cmsTempFromWhitePoint(cmsFloat64Number* TempK, const cmsCIExy
        xs = WhitePoint -> x;
        ys = WhitePoint -> y;
 
-       // convert (x,y) to CIE 1960 (u,WhitePoint) 
+       // convert (x,y) to CIE 1960 (u,WhitePoint)
 
        us = (2*xs) / (-xs + 6*ys + 1.5);
        vs = (3*ys) / (-xs + 6*ys + 1.5);
@@ -186,7 +186,7 @@ cmsBool  CMSEXPORT cmsTempFromWhitePoint(cmsFloat64Number* TempK, const cmsCIExy
 }
 
 
-// Compute chromatic adaptation matrix using Chad as cone matrix 
+// Compute chromatic adaptation matrix using Chad as cone matrix
 
 static
 cmsBool ComputeChromaticAdaptation(cmsMAT3* Conversion,
@@ -195,7 +195,7 @@ cmsBool ComputeChromaticAdaptation(cmsMAT3* Conversion,
                                 const cmsMAT3* Chad)
 
 {
-      
+
     cmsMAT3 Chad_Inv;
     cmsVEC3 ConeSourceXYZ, ConeSourceRGB;
     cmsVEC3 ConeDestXYZ, ConeDestRGB;
@@ -242,14 +242,14 @@ cmsBool  _cmsAdaptationMatrix(cmsMAT3* r, const cmsMAT3* ConeMatrix, const cmsCI
        if (ConeMatrix == NULL)
                ConeMatrix = &LamRigg;
 
-       return ComputeChromaticAdaptation(r, FromIll, ToIll, ConeMatrix);       
+       return ComputeChromaticAdaptation(r, FromIll, ToIll, ConeMatrix);
 }
 
 // Same as anterior, but assuming D50 destination. White point is given in xyY
 static
 cmsBool _cmsAdaptMatrixToD50(cmsMAT3* r, const cmsCIExyY* SourceWhitePt)
 {
-       cmsCIEXYZ Dn;      
+       cmsCIEXYZ Dn;
        cmsMAT3 Bradford;
        cmsMAT3 Tmp;
 
@@ -317,15 +317,15 @@ cmsBool _cmsBuildRGB2XYZtransferMatrix(cmsMAT3* r, const cmsCIExyY* WhitePt, con
 
 
        return _cmsAdaptMatrixToD50(r, WhitePt);
-       
+
 }
 
 
 // Adapts a color to a given illuminant. Original color is expected to have
-// a SourceWhitePt white point. 
-cmsBool CMSEXPORT cmsAdaptToIlluminant(cmsCIEXYZ* Result, 
-                                                        const cmsCIEXYZ* SourceWhitePt, 
-                                                        const cmsCIEXYZ* Illuminant, 
+// a SourceWhitePt white point.
+cmsBool CMSEXPORT cmsAdaptToIlluminant(cmsCIEXYZ* Result,
+                                                        const cmsCIEXYZ* SourceWhitePt,
+                                                        const cmsCIEXYZ* Illuminant,
                                                         const cmsCIEXYZ* Value)
 {
        cmsMAT3 Bradford;
index 8a76dae..5649801 100644 (file)
@@ -3,22 +3,22 @@
 //  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 
+// 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 
+// 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 
+// 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.
 //
 //---------------------------------------------------------------------------------
@@ -39,10 +39,10 @@ cmsFloat64Number CMSEXPORT cmsSetAdaptationState(cmsFloat64Number d)
 {
     cmsFloat64Number OldVal = GlobalAdaptationState;
 
-    if (d >= 0) 
+    if (d >= 0)
         GlobalAdaptationState = d;
 
-    return OldVal;  
+    return OldVal;
 }
 
 // Alarm codes are always global
@@ -52,7 +52,7 @@ void CMSEXPORT cmsSetAlarmCodes(cmsUInt16Number NewAlarm[cmsMAXCHANNELS])
 
     _cmsAssert(NewAlarm != NULL);
 
-    for (i=0; i < cmsMAXCHANNELS; i++) 
+    for (i=0; i < cmsMAXCHANNELS; i++)
         Alarm[i] = NewAlarm[i];
 }
 
@@ -63,7 +63,7 @@ void CMSEXPORT cmsGetAlarmCodes(cmsUInt16Number OldAlarm[cmsMAXCHANNELS])
 
     _cmsAssert(OldAlarm != NULL);
 
-    for (i=0; i < cmsMAXCHANNELS; i++) 
+    for (i=0; i < cmsMAXCHANNELS; i++)
         OldAlarm[i] = Alarm[i];
 }
 
@@ -89,19 +89,35 @@ void CMSEXPORT cmsDeleteTransform(cmsHTRANSFORM hTransform)
     if (p ->Sequence)
         cmsFreeProfileSequenceDescription(p ->Sequence);
 
+    if (p ->UserData)
+        p ->FreeUserData(p ->ContextID, p ->UserData);
+
     _cmsFree(p ->ContextID, (void *) p);
 }
 
-// Apply transform. 
+// Apply transform.
 void CMSEXPORT cmsDoTransform(cmsHTRANSFORM  Transform,
                               const void* InputBuffer,
-                              void* OutputBuffer, 
+                              void* OutputBuffer,
                               cmsUInt32Number Size)
 
 {
     _cmsTRANSFORM* p = (_cmsTRANSFORM*) Transform;
-    
-    p -> xform(p, InputBuffer, OutputBuffer, Size);
+
+    p -> xform(p, InputBuffer, OutputBuffer, Size, Size);
+}
+
+
+// Apply transform.
+void CMSEXPORT cmsDoTransformStride(cmsHTRANSFORM  Transform,
+                              const void* InputBuffer,
+                              void* OutputBuffer,
+                              cmsUInt32Number Size, cmsUInt32Number Stride)
+
+{
+    _cmsTRANSFORM* p = (_cmsTRANSFORM*) Transform;
+
+    p -> xform(p, InputBuffer, OutputBuffer, Size, Stride);
 }
 
 
@@ -110,9 +126,9 @@ void CMSEXPORT cmsDoTransform(cmsHTRANSFORM  Transform,
 // Float xform converts floats. Since there are no performance issues, one routine does all job, including gamut check.
 // Note that because extended range, we can use a -1.0 value for out of gamut in this case.
 static
-void FloatXFORM(_cmsTRANSFORM* p,               
+void FloatXFORM(_cmsTRANSFORM* p,
                 const void* in,
-                void* out, cmsUInt32Number Size)
+                void* out, cmsUInt32Number Size, cmsUInt32Number Stride)
 {
     cmsUInt8Number* accum;
     cmsUInt8Number* output;
@@ -125,7 +141,7 @@ void FloatXFORM(_cmsTRANSFORM* p,
 
     for (i=0; i < Size; i++) {
 
-        accum = p -> FromInputFloat(p, fIn, accum, Size);         
+        accum = p -> FromInputFloat(p, fIn, accum, Stride);
 
         // Any gamut chack to do?
         if (p ->GamutCheck != NULL) {
@@ -143,17 +159,17 @@ void FloatXFORM(_cmsTRANSFORM* p,
             }
             else {
                 // No, proceed normally
-                cmsPipelineEvalFloat(fIn, fOut, p -> Lut); 
+                cmsPipelineEvalFloat(fIn, fOut, p -> Lut);
             }
         }
         else {
 
             // No gamut check at all
-            cmsPipelineEvalFloat(fIn, fOut, p -> Lut);     
+            cmsPipelineEvalFloat(fIn, fOut, p -> Lut);
         }
 
         // Back to asked representation
-        output = p -> ToOutputFloat(p, fOut, output, Size);
+        output = p -> ToOutputFloat(p, fOut, output, Stride);
     }
 }
 
@@ -163,7 +179,8 @@ void FloatXFORM(_cmsTRANSFORM* p,
 static
 void NullXFORM(_cmsTRANSFORM* p,
                const void* in,
-               void* out, cmsUInt32Number Size)
+               void* out, cmsUInt32Number Size,
+               cmsUInt32Number Stride)
 {
     cmsUInt8Number* accum;
     cmsUInt8Number* output;
@@ -176,8 +193,8 @@ void NullXFORM(_cmsTRANSFORM* p,
 
     for (i=0; i < n; i++) {
 
-        accum  = p -> FromInput(p, wIn, accum, Size);
-        output = p -> ToOutput(p, wIn, output, Size);
+        accum  = p -> FromInput(p, wIn, accum, Stride);
+        output = p -> ToOutput(p, wIn, output, Stride);
     }
 }
 
@@ -186,7 +203,7 @@ void NullXFORM(_cmsTRANSFORM* p,
 static
 void PrecalculatedXFORM(_cmsTRANSFORM* p,
                         const void* in,
-                        void* out, cmsUInt32Number Size)
+                        void* out, cmsUInt32Number Size, cmsUInt32Number Stride)
 {
     register cmsUInt8Number* accum;
     register cmsUInt8Number* output;
@@ -195,42 +212,42 @@ void PrecalculatedXFORM(_cmsTRANSFORM* p,
 
     accum  = (cmsUInt8Number*)  in;
     output = (cmsUInt8Number*)  out;
-    n = Size;                    
+    n = Size;
 
     for (i=0; i < n; i++) {
 
-        accum = p -> FromInput(p, wIn, accum, Size);         
-        p ->Lut ->Eval16Fn(wIn, wOut, p -> Lut->Data);     
-        output = p -> ToOutput(p, wOut, output, Size);
+        accum = p -> FromInput(p, wIn, accum, Stride);
+        p ->Lut ->Eval16Fn(wIn, wOut, p -> Lut->Data);
+        output = p -> ToOutput(p, wOut, output, Stride);
     }
 }
 
 
 // Auxiliar: Handle precalculated gamut check
 static
-void TransformOnePixelWithGamutCheck(_cmsTRANSFORM* p, 
-                                     const cmsUInt16Number wIn[], 
+void TransformOnePixelWithGamutCheck(_cmsTRANSFORM* p,
+                                     const cmsUInt16Number wIn[],
                                      cmsUInt16Number wOut[])
 {
     cmsUInt16Number wOutOfGamut;
 
-    p ->GamutCheck ->Eval16Fn(wIn, &wOutOfGamut, p ->GamutCheck ->Data);   
+    p ->GamutCheck ->Eval16Fn(wIn, &wOutOfGamut, p ->GamutCheck ->Data);
     if (wOutOfGamut >= 1) {
 
         cmsUInt16Number i;
 
         for (i=0; i < p ->Lut->OutputChannels; i++)
-            wOut[i] = Alarm[i];                      
+            wOut[i] = Alarm[i];
     }
     else
-        p ->Lut ->Eval16Fn(wIn, wOut, p -> Lut->Data);   
+        p ->Lut ->Eval16Fn(wIn, wOut, p -> Lut->Data);
 }
 
 // Gamut check, No caché, 16 bits.
 static
 void PrecalculatedXFORMGamutCheck(_cmsTRANSFORM* p,
                                   const void* in,
-                                  void* out, cmsUInt32Number Size)
+                                  void* out, cmsUInt32Number Size, cmsUInt32Number Stride)
 {
     cmsUInt8Number* accum;
     cmsUInt8Number* output;
@@ -243,18 +260,18 @@ void PrecalculatedXFORMGamutCheck(_cmsTRANSFORM* p,
 
     for (i=0; i < n; i++) {
 
-        accum = p -> FromInput(p, wIn, accum, Size);
+        accum = p -> FromInput(p, wIn, accum, Stride);
         TransformOnePixelWithGamutCheck(p, wIn, wOut);
-        output = p -> ToOutput(p, wOut, output, Size);
+        output = p -> ToOutput(p, wOut, output, Stride);
     }
 }
 
 
-// No gamut check, Caché, 16 bits, 
+// No gamut check, Caché, 16 bits,
 static
 void CachedXFORM(_cmsTRANSFORM* p,
                  const void* in,
-                 void* out, cmsUInt32Number Size)
+                 void* out, cmsUInt32Number Size, cmsUInt32Number Stride)
 {
     cmsUInt8Number* accum;
     cmsUInt8Number* output;
@@ -275,23 +292,23 @@ void CachedXFORM(_cmsTRANSFORM* p,
 
     for (i=0; i < n; i++) {
 
-        accum = p -> FromInput(p, wIn, accum, Size);
+        accum = p -> FromInput(p, wIn, accum, Stride);
 
         if (memcmp(wIn, Cache.CacheIn, sizeof(Cache.CacheIn)) == 0) {
 
             memcpy(wOut, Cache.CacheOut, sizeof(Cache.CacheOut));
         }
-        else {   
+        else {
 
-            p ->Lut ->Eval16Fn(wIn, wOut, p -> Lut->Data);  
+            p ->Lut ->Eval16Fn(wIn, wOut, p -> Lut->Data);
 
             memcpy(Cache.CacheIn,  wIn,  sizeof(Cache.CacheIn));
             memcpy(Cache.CacheOut, wOut, sizeof(Cache.CacheOut));
         }
 
-        output = p -> ToOutput(p, wOut, output, Size);            
+        output = p -> ToOutput(p, wOut, output, Stride);
     }
+
 }
 
 
@@ -299,7 +316,7 @@ void CachedXFORM(_cmsTRANSFORM* p,
 static
 void CachedXFORMGamutCheck(_cmsTRANSFORM* p,
                            const void* in,
-                           void* out, cmsUInt32Number Size)
+                           void* out, cmsUInt32Number Size, cmsUInt32Number Stride)
 {
        cmsUInt8Number* accum;
        cmsUInt8Number* output;
@@ -320,43 +337,156 @@ void CachedXFORMGamutCheck(_cmsTRANSFORM* p,
 
        for (i=0; i < n; i++) {
 
-            accum = p -> FromInput(p, wIn, accum, Size);
-     
+            accum = p -> FromInput(p, wIn, accum, Stride);
+
             if (memcmp(wIn, Cache.CacheIn, sizeof(Cache.CacheIn)) == 0) {
                     memcpy(wOut, Cache.CacheOut, sizeof(Cache.CacheOut));
             }
-            else {            
+            else {
                     TransformOnePixelWithGamutCheck(p, wIn, wOut);
                     memcpy(Cache.CacheIn, wIn, sizeof(Cache.CacheIn));
                     memcpy(Cache.CacheOut, wOut, sizeof(Cache.CacheOut));
             }
 
-            output = p -> ToOutput(p, wOut, output, Size);
+            output = p -> ToOutput(p, wOut, output, Stride);
        }
-       
+
+}
+
+// -------------------------------------------------------------------------------------------------------------
+
+// List of used-defined transform factories
+typedef struct _cmsTransformCollection_st {
+
+    _cmsTransformFactory  Factory;
+    struct _cmsTransformCollection_st *Next;
+
+} _cmsTransformCollection;
+
+// The linked list head
+static _cmsTransformCollection* TransformCollection = NULL;
+
+// Register new ways to transform
+cmsBool  _cmsRegisterTransformPlugin(cmsPluginBase* Data)
+{
+    cmsPluginTransform* Plugin = (cmsPluginTransform*) Data;
+    _cmsTransformCollection* fl;
+
+      if (Data == NULL) {
+
+        // Free the chain. Memory is safely freed at exit
+        TransformCollection = NULL;
+        return TRUE;
+    }
+
+    // Factory callback is required
+   if (Plugin ->Factory == NULL) return FALSE;
+
+
+    fl = (_cmsTransformCollection*) _cmsPluginMalloc(sizeof(_cmsTransformCollection));
+    if (fl == NULL) return FALSE;
+
+      // Copy the parameters
+    fl ->Factory = Plugin ->Factory;
+
+    // Keep linked list
+    fl ->Next = TransformCollection;
+    TransformCollection = fl;
+
+    // All is ok
+    return TRUE;
 }
 
 
+void CMSEXPORT _cmsSetTransformUserData(struct _cmstransform_struct *CMMcargo, void* ptr, _cmsFreeUserDataFn FreePrivateDataFn)
+{
+    _cmsAssert(CMMcargo != NULL);
+    CMMcargo ->UserData = ptr;
+    CMMcargo ->FreeUserData = FreePrivateDataFn;
+}
 
+// returns the pointer defined by the plug-in to store private data
+void * CMSEXPORT _cmsGetTransformUserData(struct _cmstransform_struct *CMMcargo)
+{
+    _cmsAssert(CMMcargo != NULL);
+    return CMMcargo ->UserData;
+}
 
-// Allocate transform struct and set it to defaults
+// returns the current formatters
+void CMSEXPORT _cmsGetTransformFormatters16(struct _cmstransform_struct *CMMcargo, cmsFormatter16* FromInput, cmsFormatter16* ToOutput)
+{
+     _cmsAssert(CMMcargo != NULL);
+     if (FromInput) *FromInput = CMMcargo ->FromInput;
+     if (ToOutput)  *ToOutput  = CMMcargo ->ToOutput;
+}
+
+void CMSEXPORT _cmsGetTransformFormattersFloat(struct _cmstransform_struct *CMMcargo, cmsFormatterFloat* FromInput, cmsFormatterFloat* ToOutput)
+{
+     _cmsAssert(CMMcargo != NULL);
+     if (FromInput) *FromInput = CMMcargo ->FromInputFloat;
+     if (ToOutput)  *ToOutput  = CMMcargo ->ToOutputFloat;
+}
+
+
+// Allocate transform struct and set it to defaults. Ask the optimization plug-in about if those formats are proper
+// for separated transforms. If this is the case,
 static
-_cmsTRANSFORM* AllocEmptyTransform(cmsContext ContextID, cmsUInt32Number InputFormat, cmsUInt32Number OutputFormat, cmsUInt32Number dwFlags)
+_cmsTRANSFORM* AllocEmptyTransform(cmsContext ContextID, cmsPipeline* lut,
+                                               cmsUInt32Number Intent, cmsUInt32Number* InputFormat, cmsUInt32Number* OutputFormat, cmsUInt32Number* dwFlags)
 {
+     _cmsTransformCollection* Plugin;
+
     // Allocate needed memory
     _cmsTRANSFORM* p = (_cmsTRANSFORM*) _cmsMallocZero(ContextID, sizeof(_cmsTRANSFORM));
     if (!p) return NULL;
 
+    // Store the proposed pipeline
+    p ->Lut = lut;
+
+    // Let's see if any plug-in want to do the transform by itself
+    for (Plugin = TransformCollection;
+        Plugin != NULL;
+        Plugin = Plugin ->Next) {
+
+            if (Plugin ->Factory(&p->xform, &p->UserData, &p ->FreeUserData, &p ->Lut, InputFormat, OutputFormat, dwFlags)) {
+                
+                // Last plugin in the declaration order takes control. We just keep
+                // the original parameters as a logging. 
+                // Note that cmsFLAGS_CAN_CHANGE_FORMATTER is not set, so by default 
+                // an optimized transform is not reusable. The plug-in can, however, change
+                // the flags and make it suitable.
+
+                p ->ContextID       = ContextID;               
+                p ->InputFormat     = *InputFormat;
+                p ->OutputFormat    = *OutputFormat;
+                p ->dwOriginalFlags = *dwFlags;
+               
+                // Fill the formatters just in case the optimized routine is interested.
+                // No error is thrown if the formatter doesn't exist. It is up to the optimization 
+                // factory to decide what to do in those cases.
+                p ->FromInput      = _cmsGetFormatter(*InputFormat,  cmsFormatterInput, CMS_PACK_FLAGS_16BITS).Fmt16;
+                p ->ToOutput       = _cmsGetFormatter(*OutputFormat, cmsFormatterOutput, CMS_PACK_FLAGS_16BITS).Fmt16;
+                p ->FromInputFloat = _cmsGetFormatter(*InputFormat,  cmsFormatterInput, CMS_PACK_FLAGS_FLOAT).FmtFloat;
+                p ->ToOutputFloat  = _cmsGetFormatter(*OutputFormat, cmsFormatterOutput, CMS_PACK_FLAGS_FLOAT).FmtFloat;
+
+                return p;
+            }
+    }
+
+    // Not suitable for the transform plug-in, let's check  the pipeline plug-in
+    if (p ->Lut != NULL)
+        _cmsOptimizePipeline(&p->Lut, Intent, InputFormat, OutputFormat, dwFlags);
+
     // Check whatever this is a true floating point transform
-    if (_cmsFormatterIsFloat(InputFormat) && _cmsFormatterIsFloat(OutputFormat)) {
+    if (_cmsFormatterIsFloat(*InputFormat) && _cmsFormatterIsFloat(*OutputFormat)) {
 
         // Get formatter function always return a valid union, but the contents of this union may be NULL.
-        p ->FromInputFloat = _cmsGetFormatter(InputFormat,  cmsFormatterInput, CMS_PACK_FLAGS_FLOAT).FmtFloat;
-        p ->ToOutputFloat  = _cmsGetFormatter(OutputFormat, cmsFormatterOutput, CMS_PACK_FLAGS_FLOAT).FmtFloat;
-        dwFlags |= cmsFLAGS_CAN_CHANGE_FORMATTER;
+        p ->FromInputFloat = _cmsGetFormatter(*InputFormat,  cmsFormatterInput, CMS_PACK_FLAGS_FLOAT).FmtFloat;
+        p ->ToOutputFloat  = _cmsGetFormatter(*OutputFormat, cmsFormatterOutput, CMS_PACK_FLAGS_FLOAT).FmtFloat;
+        *dwFlags |= cmsFLAGS_CAN_CHANGE_FORMATTER;
 
         if (p ->FromInputFloat == NULL || p ->ToOutputFloat == NULL) {
-        
+
             cmsSignalError(ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unsupported raster format");
             _cmsFree(ContextID, p);
             return NULL;
@@ -367,16 +497,16 @@ _cmsTRANSFORM* AllocEmptyTransform(cmsContext ContextID, cmsUInt32Number InputFo
     }
     else {
 
-        if (InputFormat == 0 && OutputFormat == 0) {
+        if (*InputFormat == 0 && *OutputFormat == 0) {
             p ->FromInput = p ->ToOutput = NULL;
+            *dwFlags |= cmsFLAGS_CAN_CHANGE_FORMATTER;
         }
         else {
 
             int BytesPerPixelInput;
 
-            p ->FromInput = _cmsGetFormatter(InputFormat,  cmsFormatterInput, CMS_PACK_FLAGS_16BITS).Fmt16;
-            p ->ToOutput  = _cmsGetFormatter(OutputFormat, cmsFormatterOutput, CMS_PACK_FLAGS_16BITS).Fmt16;
-
+            p ->FromInput = _cmsGetFormatter(*InputFormat,  cmsFormatterInput, CMS_PACK_FLAGS_16BITS).Fmt16;
+            p ->ToOutput  = _cmsGetFormatter(*OutputFormat, cmsFormatterOutput, CMS_PACK_FLAGS_16BITS).Fmt16;
 
             if (p ->FromInput == NULL || p ->ToOutput == NULL) {
 
@@ -386,26 +516,26 @@ _cmsTRANSFORM* AllocEmptyTransform(cmsContext ContextID, cmsUInt32Number InputFo
             }
 
             BytesPerPixelInput = T_BYTES(p ->InputFormat);
-            if (BytesPerPixelInput == 0 || BytesPerPixelInput >= 2) 
-                   dwFlags |= cmsFLAGS_CAN_CHANGE_FORMATTER;
+            if (BytesPerPixelInput == 0 || BytesPerPixelInput >= 2)
+                   *dwFlags |= cmsFLAGS_CAN_CHANGE_FORMATTER;
 
         }
 
-        if (dwFlags & cmsFLAGS_NULLTRANSFORM) {
+        if (*dwFlags & cmsFLAGS_NULLTRANSFORM) {
 
             p ->xform = NullXFORM;
         }
         else {
-            if (dwFlags & cmsFLAGS_NOCACHE) {
+            if (*dwFlags & cmsFLAGS_NOCACHE) {
 
-                if (dwFlags & cmsFLAGS_GAMUTCHECK) 
+                if (*dwFlags & cmsFLAGS_GAMUTCHECK)
                     p ->xform = PrecalculatedXFORMGamutCheck;  // Gamut check, no caché
                 else
                     p ->xform = PrecalculatedXFORM;  // No caché, no gamut check
             }
             else {
 
-                if (dwFlags & cmsFLAGS_GAMUTCHECK) 
+                if (*dwFlags & cmsFLAGS_GAMUTCHECK)
                     p ->xform = CachedXFORMGamutCheck;    // Gamut check, caché
                 else
                     p ->xform = CachedXFORM;  // No gamut check, caché
@@ -414,58 +544,60 @@ _cmsTRANSFORM* AllocEmptyTransform(cmsContext ContextID, cmsUInt32Number InputFo
         }
     }
 
-    
-    p ->InputFormat     = InputFormat;
-    p ->OutputFormat    = OutputFormat;
-    p ->dwOriginalFlags = dwFlags;
+    p ->InputFormat     = *InputFormat;
+    p ->OutputFormat    = *OutputFormat;
+    p ->dwOriginalFlags = *dwFlags;
     p ->ContextID       = ContextID;
+    p ->UserData        = NULL;
     return p;
 }
 
 static
-cmsBool GetXFormColorSpaces(int nProfiles, cmsHPROFILE hProfiles[], cmsColorSpaceSignature* Input, cmsColorSpaceSignature* Output) 
-{    
-    cmsColorSpaceSignature ColorSpaceIn, ColorSpaceOut;   
-    cmsColorSpaceSignature PostColorSpace;   
+cmsBool GetXFormColorSpaces(int nProfiles, cmsHPROFILE hProfiles[], cmsColorSpaceSignature* Input, cmsColorSpaceSignature* Output)
+{
+    cmsColorSpaceSignature ColorSpaceIn, ColorSpaceOut;
+    cmsColorSpaceSignature PostColorSpace;
     int i;
 
+    if (nProfiles <= 0) return FALSE;
     if (hProfiles[0] == NULL) return FALSE;
 
     *Input = PostColorSpace = cmsGetColorSpace(hProfiles[0]);
 
-    // Special handling for named color profiles as devicelinks
-    if (nProfiles == 1 && cmsGetDeviceClass(hProfiles[0]) == cmsSigNamedColorClass) {
-            *Input  = cmsSig1colorData;
-            *Output = PostColorSpace;
-            return TRUE;
-    }
-
     for (i=0; i < nProfiles; i++) {
 
+        cmsProfileClassSignature cls;
         cmsHPROFILE hProfile = hProfiles[i];
 
         int lIsInput = (PostColorSpace != cmsSigXYZData) &&
                        (PostColorSpace != cmsSigLabData);
 
-        int lIsDeviceLink;
-               
         if (hProfile == NULL) return FALSE;
 
-        lIsDeviceLink = (cmsGetDeviceClass(hProfile) == cmsSigLinkClass);
+        cls = cmsGetDeviceClass(hProfile);
 
-        if (lIsInput || lIsDeviceLink) {
+        if (cls == cmsSigNamedColorClass) {
+
+            ColorSpaceIn    = cmsSig1colorData;
+            ColorSpaceOut   = (nProfiles > 1) ? cmsGetPCS(hProfile) : cmsGetColorSpace(hProfile);
+        }
+        else
+        if (lIsInput || (cls == cmsSigLinkClass)) {
 
             ColorSpaceIn    = cmsGetColorSpace(hProfile);
             ColorSpaceOut   = cmsGetPCS(hProfile);
         }
-        else {
-
+        else
+        {
             ColorSpaceIn    = cmsGetPCS(hProfile);
             ColorSpaceOut   = cmsGetColorSpace(hProfile);
         }
 
-        PostColorSpace = ColorSpaceOut;     
-    }  
+        if (i==0)
+            *Input = ColorSpaceIn;
+
+        PostColorSpace = ColorSpaceOut;
+    }
 
     *Output = PostColorSpace;
 
@@ -492,12 +624,12 @@ cmsBool  IsProperColorSpace(cmsColorSpaceSignature Check, cmsUInt32Number dwForm
 
 // New to lcms 2.0 -- have all parameters available.
 cmsHTRANSFORM CMSEXPORT cmsCreateExtendedTransform(cmsContext ContextID,
-                                                   cmsUInt32Number nProfiles, cmsHPROFILE hProfiles[], 
-                                                   cmsBool  BPC[], 
-                                                   cmsUInt32Number Intents[], 
+                                                   cmsUInt32Number nProfiles, cmsHPROFILE hProfiles[],
+                                                   cmsBool  BPC[],
+                                                   cmsUInt32Number Intents[],
                                                    cmsFloat64Number AdaptationStates[],
                                                    cmsHPROFILE hGamutProfile,
-                                                   cmsUInt32Number nGamutPCSposition,           
+                                                   cmsUInt32Number nGamutPCSposition,
                                                    cmsUInt32Number InputFormat,
                                                    cmsUInt32Number OutputFormat,
                                                    cmsUInt32Number dwFlags)
@@ -509,12 +641,18 @@ cmsHTRANSFORM CMSEXPORT cmsCreateExtendedTransform(cmsContext ContextID,
     cmsPipeline* Lut;
     cmsUInt32Number LastIntent = Intents[nProfiles-1];
 
+    // If it is a fake transform
+    if (dwFlags & cmsFLAGS_NULLTRANSFORM)
+    {
+        return AllocEmptyTransform(ContextID, NULL, INTENT_PERCEPTUAL, &InputFormat, &OutputFormat, &dwFlags);
+    }
+
     // If gamut check is requested, make sure we have a gamut profile
     if (dwFlags & cmsFLAGS_GAMUTCHECK) {
         if (hGamutProfile == NULL) dwFlags &= ~cmsFLAGS_GAMUTCHECK;
     }
 
-    // On floating point transforms, inhibit optimizations 
+    // On floating point transforms, inhibit optimizations
     FloatTransform = (_cmsFormatterIsFloat(InputFormat) && _cmsFormatterIsFloat(OutputFormat));
 
     if (_cmsFormatterIsFloat(InputFormat) || _cmsFormatterIsFloat(OutputFormat))
@@ -522,36 +660,39 @@ cmsHTRANSFORM CMSEXPORT cmsCreateExtendedTransform(cmsContext ContextID,
 
     // Mark entry/exit spaces
     if (!GetXFormColorSpaces(nProfiles, hProfiles, &EntryColorSpace, &ExitColorSpace)) {
-        cmsSignalError(ContextID, cmsERROR_NULL, "NULL input profiles on transform");        
+        cmsSignalError(ContextID, cmsERROR_NULL, "NULL input profiles on transform");
         return NULL;
     }
 
     // Check if proper colorspaces
-    if (!IsProperColorSpace(EntryColorSpace, InputFormat)) {        
-        cmsSignalError(ContextID, cmsERROR_COLORSPACE_CHECK, "Wrong input color space on transform");        
+    if (!IsProperColorSpace(EntryColorSpace, InputFormat)) {
+        cmsSignalError(ContextID, cmsERROR_COLORSPACE_CHECK, "Wrong input color space on transform");
         return NULL;
     }
 
     if (!IsProperColorSpace(ExitColorSpace, OutputFormat)) {
-        cmsSignalError(ContextID, cmsERROR_COLORSPACE_CHECK, "Wrong output color space on transform");       
+        cmsSignalError(ContextID, cmsERROR_COLORSPACE_CHECK, "Wrong output color space on transform");
         return NULL;
     }
 
     // Create a pipeline with all transformations
     Lut = _cmsLinkProfiles(ContextID, nProfiles, Intents, hProfiles, BPC, AdaptationStates, dwFlags);
     if (Lut == NULL) {
-        cmsSignalError(ContextID, cmsERROR_NOT_SUITABLE, "Couldn't link the profiles");   
+        cmsSignalError(ContextID, cmsERROR_NOT_SUITABLE, "Couldn't link the profiles");
         return NULL;
     }
 
-    // Optimize the LUT if possible
-    _cmsOptimizePipeline(&Lut, LastIntent, &InputFormat, &OutputFormat, &dwFlags);       
+    // Check channel count
+    if ((cmsChannelsOf(EntryColorSpace) != cmsPipelineInputChannels(Lut)) ||
+        (cmsChannelsOf(ExitColorSpace)  != cmsPipelineOutputChannels(Lut))) {
+        cmsSignalError(ContextID, cmsERROR_NOT_SUITABLE, "Channel count doesn't match. Profile is corrupted");
+        return NULL;
+    }
 
 
     // All seems ok
-    xform = AllocEmptyTransform(ContextID, InputFormat, OutputFormat, dwFlags);
+    xform = AllocEmptyTransform(ContextID, Lut, LastIntent, &InputFormat, &OutputFormat, &dwFlags);
     if (xform == NULL) {
-        cmsPipelineFree(Lut);
         return NULL;
     }
 
@@ -559,28 +700,28 @@ cmsHTRANSFORM CMSEXPORT cmsCreateExtendedTransform(cmsContext ContextID,
     xform ->EntryColorSpace = EntryColorSpace;
     xform ->ExitColorSpace  = ExitColorSpace;
     xform ->RenderingIntent = Intents[nProfiles-1];
-    xform ->Lut             = Lut;
-    
+
+
     // Create a gamut check LUT if requested
-    if (hGamutProfile != NULL && (dwFlags & cmsFLAGS_GAMUTCHECK))       
-        xform ->GamutCheck  = _cmsCreateGamutCheckPipeline(ContextID, hProfiles, 
-                                                        BPC, Intents, 
-                                                        AdaptationStates, 
-                                                        nGamutPCSposition, 
+    if (hGamutProfile != NULL && (dwFlags & cmsFLAGS_GAMUTCHECK))
+        xform ->GamutCheck  = _cmsCreateGamutCheckPipeline(ContextID, hProfiles,
+                                                        BPC, Intents,
+                                                        AdaptationStates,
+                                                        nGamutPCSposition,
                                                         hGamutProfile);
 
 
     // Try to read input and output colorant table
     if (cmsIsTag(hProfiles[0], cmsSigColorantTableTag)) {
 
-        // Input table can only come in this way.       
+        // Input table can only come in this way.
         xform ->InputColorant = cmsDupNamedColorList((cmsNAMEDCOLORLIST*) cmsReadTag(hProfiles[0], cmsSigColorantTableTag));
     }
 
-    // Output is a little bit more complex.    
+    // Output is a little bit more complex.
     if (cmsGetDeviceClass(hProfiles[nProfiles-1]) == cmsSigLinkClass) {
 
-        // This tag may exist only on devicelink profiles.        
+        // This tag may exist only on devicelink profiles.
         if (cmsIsTag(hProfiles[nProfiles-1], cmsSigColorantTableOutTag)) {
 
             // It may be NULL if error
@@ -592,14 +733,14 @@ cmsHTRANSFORM CMSEXPORT cmsCreateExtendedTransform(cmsContext ContextID,
         if (cmsIsTag(hProfiles[nProfiles-1], cmsSigColorantTableTag)) {
 
             xform -> OutputColorant = cmsDupNamedColorList((cmsNAMEDCOLORLIST*) cmsReadTag(hProfiles[nProfiles-1], cmsSigColorantTableTag));
-        }     
+        }
     }
 
     // Store the sequence of profiles
     if (dwFlags & cmsFLAGS_KEEP_SEQUENCE) {
         xform ->Sequence = _cmsCompileProfileSequence(ContextID, nProfiles, hProfiles);
     }
-    else 
+    else
         xform ->Sequence = NULL;
 
     // If this is a cached transform, init first value, which is zero (16 bits only)
@@ -612,12 +753,12 @@ cmsHTRANSFORM CMSEXPORT cmsCreateExtendedTransform(cmsContext ContextID,
         }
         else {
 
-            xform ->Lut ->Eval16Fn(xform ->Cache.CacheIn, xform->Cache.CacheOut, xform -> Lut->Data);  
+            xform ->Lut ->Eval16Fn(xform ->Cache.CacheIn, xform->Cache.CacheOut, xform -> Lut->Data);
         }
 
     }
 
-    return (cmsHTRANSFORM) xform; 
+    return (cmsHTRANSFORM) xform;
 }
 
 // Multiprofile transforms: Gamut check is not available here, as it is unclear from which profile the gamut comes.
@@ -683,7 +824,7 @@ cmsHTRANSFORM CMSEXPORT cmsCreateTransformTHR(cmsContext ContextID,
 {
 
     cmsHPROFILE hArray[2];
-    
+
     hArray[0] = Input;
     hArray[1] = Output;
 
@@ -710,7 +851,7 @@ cmsHTRANSFORM CMSEXPORT cmsCreateProofingTransformTHR(cmsContext ContextID,
                                                    cmsUInt32Number nIntent,
                                                    cmsUInt32Number ProofingIntent,
                                                    cmsUInt32Number dwFlags)
-{   
+{
     cmsHPROFILE hArray[4];
     cmsUInt32Number Intents[4];
     cmsBool  BPC[4];
@@ -721,13 +862,13 @@ cmsHTRANSFORM CMSEXPORT cmsCreateProofingTransformTHR(cmsContext ContextID,
     hArray[0]  = InputProfile; hArray[1] = ProofingProfile; hArray[2]  = ProofingProfile;               hArray[3] = OutputProfile;
     Intents[0] = nIntent;      Intents[1] = nIntent;        Intents[2] = INTENT_RELATIVE_COLORIMETRIC;  Intents[3] = ProofingIntent;
     BPC[0]     = DoBPC;        BPC[1] = DoBPC;              BPC[2] = 0;                                 BPC[3] = 0;
-    
+
     Adaptation[0] = Adaptation[1] = Adaptation[2] = Adaptation[3] = GlobalAdaptationState;
 
-    if (!(dwFlags & (cmsFLAGS_SOFTPROOFING|cmsFLAGS_GAMUTCHECK))) 
+    if (!(dwFlags & (cmsFLAGS_SOFTPROOFING|cmsFLAGS_GAMUTCHECK)))
         return cmsCreateTransformTHR(ContextID, InputProfile, InputFormat, OutputProfile, OutputFormat, nIntent, dwFlags);
-  
-    return cmsCreateExtendedTransform(ContextID, 4, hArray, BPC, Intents, Adaptation, 
+
+    return cmsCreateExtendedTransform(ContextID, 4, hArray, BPC, Intents, Adaptation,
                                         ProofingProfile, 1, InputFormat, OutputFormat, dwFlags);
 
 }
@@ -742,7 +883,7 @@ cmsHTRANSFORM CMSEXPORT cmsCreateProofingTransform(cmsHPROFILE InputProfile,
                                                    cmsUInt32Number ProofingIntent,
                                                    cmsUInt32Number dwFlags)
 {
-    return cmsCreateProofingTransformTHR(cmsGetProfileContextID(InputProfile), 
+    return cmsCreateProofingTransformTHR(cmsGetProfileContextID(InputProfile),
                                                    InputProfile,
                                                    InputFormat,
                                                    OutputProfile,
@@ -781,17 +922,16 @@ cmsUInt32Number CMSEXPORT cmsGetTransformOutputFormat(cmsHTRANSFORM hTransform)
 }
 
 // For backwards compatibility
-cmsBool CMSEXPORT cmsChangeBuffersFormat(cmsHTRANSFORM hTransform, 
-                                         cmsUInt32Number InputFormat, 
+cmsBool CMSEXPORT cmsChangeBuffersFormat(cmsHTRANSFORM hTransform,
+                                         cmsUInt32Number InputFormat,
                                          cmsUInt32Number OutputFormat)
 {
 
     _cmsTRANSFORM* xform = (_cmsTRANSFORM*) hTransform;
     cmsFormatter16 FromInput, ToOutput;
-    cmsUInt32Number BytesPerPixelInput;
+
 
     // We only can afford to change formatters if previous transform is at least 16 bits
-    BytesPerPixelInput = T_BYTES(xform ->InputFormat);
     if (!(xform ->dwOriginalFlags & cmsFLAGS_CAN_CHANGE_FORMATTER)) {
 
         cmsSignalError(xform ->ContextID, cmsERROR_NOT_SUITABLE, "cmsChangeBuffersFormat works only on transforms created originally with at least 16 bits of precision");
index b9d2c71..1ba2fcb 100644 (file)
-LIBRARY     LCMS2.DLL
-
-EXPORTS
-
-_cms15Fixed16toDouble                    =   _cms15Fixed16toDouble
-_cms8Fixed8toDouble                      =   _cms8Fixed8toDouble
-cmsAdaptToIlluminant                     =    cmsAdaptToIlluminant
-_cmsAdjustEndianess16                    =   _cmsAdjustEndianess16
-_cmsAdjustEndianess32                    =   _cmsAdjustEndianess32
-_cmsAdjustEndianess64                    =   _cmsAdjustEndianess64
-cmsAllocNamedColorList                   =   cmsAllocNamedColorList
-cmsAllocProfileSequenceDescription       =   cmsAllocProfileSequenceDescription
-cmsAppendNamedColor                      =   cmsAppendNamedColor
-cmsBFDdeltaE                             =   cmsBFDdeltaE
-cmsBuildGamma                            =   cmsBuildGamma
-cmsBuildParametricToneCurve              =   cmsBuildParametricToneCurve
-cmsBuildSegmentedToneCurve               =   cmsBuildSegmentedToneCurve
-cmsBuildTabulatedToneCurve16             =   cmsBuildTabulatedToneCurve16
-cmsBuildTabulatedToneCurveFloat          =   cmsBuildTabulatedToneCurveFloat
-_cmsCalloc                               =   _cmsCalloc
-cmsChannelsOf                            =    cmsChannelsOf
-cmsCIE2000DeltaE                         =    cmsCIE2000DeltaE
-cmsCIE94DeltaE                           =    cmsCIE94DeltaE
-cmsCIECAM02Done                          =    cmsCIECAM02Done
-cmsCIECAM02Forward                       =    cmsCIECAM02Forward
-cmsCIECAM02Init                          =    cmsCIECAM02Init
-cmsCIECAM02Reverse                       =    cmsCIECAM02Reverse
-cmsCloseIOhandler                        =    cmsCloseIOhandler
-cmsCloseProfile                          =    cmsCloseProfile
-cmsCMCdeltaE                             =    cmsCMCdeltaE
-cmsCreate_sRGBProfile                    =    cmsCreate_sRGBProfile
-cmsCreate_sRGBProfileTHR                 =    cmsCreate_sRGBProfileTHR
-cmsCreateBCHSWabstractProfile            =    cmsCreateBCHSWabstractProfile
-cmsCreateBCHSWabstractProfileTHR         =    cmsCreateBCHSWabstractProfileTHR
-cmsCreateExtendedTransform               =    cmsCreateExtendedTransform
-cmsCreateGrayProfile                     =    cmsCreateGrayProfile
-cmsCreateGrayProfileTHR                  =    cmsCreateGrayProfileTHR
-cmsCreateInkLimitingDeviceLink           =    cmsCreateInkLimitingDeviceLink
-cmsCreateInkLimitingDeviceLinkTHR        =    cmsCreateInkLimitingDeviceLinkTHR
-cmsCreateLab2Profile                     =    cmsCreateLab2Profile
-cmsCreateLab2ProfileTHR                  =    cmsCreateLab2ProfileTHR
-cmsCreateLab4Profile                     =    cmsCreateLab4Profile
-cmsCreateLab4ProfileTHR                  =    cmsCreateLab4ProfileTHR
-cmsCreateLinearizationDeviceLink         =    cmsCreateLinearizationDeviceLink
-cmsCreateLinearizationDeviceLinkTHR      =    cmsCreateLinearizationDeviceLinkTHR
-cmsCreateMultiprofileTransform           =    cmsCreateMultiprofileTransform
-cmsCreateMultiprofileTransformTHR        =    cmsCreateMultiprofileTransformTHR
-cmsCreateNULLProfile                     =    cmsCreateNULLProfile
-cmsCreateNULLProfileTHR                  =    cmsCreateNULLProfileTHR
-cmsCreateProfilePlaceholder              =    cmsCreateProfilePlaceholder
-cmsCreateProofingTransform               =    cmsCreateProofingTransform
-cmsCreateProofingTransformTHR            =    cmsCreateProofingTransformTHR
-cmsCreateRGBProfile                      =    cmsCreateRGBProfile
-cmsCreateRGBProfileTHR                   =    cmsCreateRGBProfileTHR
-cmsCreateTransform                       =    cmsCreateTransform
-cmsCreateTransformTHR                    =    cmsCreateTransformTHR
-cmsCreateXYZProfile                      =    cmsCreateXYZProfile
-cmsCreateXYZProfileTHR                   =    cmsCreateXYZProfileTHR
-cmsD50_xyY                               =    cmsD50_xyY
-cmsD50_XYZ                               =    cmsD50_XYZ
-_cmsDecodeDateTimeNumber                 =    _cmsDecodeDateTimeNumber
-_cmsDefaultICCintents                    =    _cmsDefaultICCintents
-cmsDeleteTransform                       =    cmsDeleteTransform
-cmsDeltaE                                =    cmsDeltaE
-cmsDetectBlackPoint                      =    cmsDetectBlackPoint
-cmsDetectTAC                             =    cmsDetectTAC
-cmsDesaturateLab                         =    cmsDesaturateLab
-cmsDoTransform                           =    cmsDoTransform
-_cmsDoubleTo15Fixed16                    =    _cmsDoubleTo15Fixed16
-_cmsDoubleTo8Fixed8                      =    _cmsDoubleTo8Fixed8
-_cmsDupMem                               =    _cmsDupMem
-cmsDupNamedColorList                     =    cmsDupNamedColorList
-cmsDupProfileSequenceDescription         =    cmsDupProfileSequenceDescription
-cmsDupToneCurve                          =    cmsDupToneCurve
-_cmsEncodeDateTimeNumber                 =    _cmsEncodeDateTimeNumber
-cmsEstimateGamma                         =    cmsEstimateGamma
-cmsEvalToneCurve16                       =    cmsEvalToneCurve16
-cmsEvalToneCurveFloat                    =    cmsEvalToneCurveFloat
-cmsfilelength                            =    cmsfilelength
-cmsFloat2LabEncoded                      =    cmsFloat2LabEncoded
-cmsFloat2LabEncodedV2                    =    cmsFloat2LabEncodedV2
-cmsFloat2XYZEncoded                      =    cmsFloat2XYZEncoded
-cmsFormatterForColorspaceOfProfile       =    cmsFormatterForColorspaceOfProfile
-cmsFormatterForPCSOfProfile              =    cmsFormatterForPCSOfProfile
-_cmsFree                                 =    _cmsFree
-cmsFreeNamedColorList                    =    cmsFreeNamedColorList
-cmsFreeProfileSequenceDescription        =    cmsFreeProfileSequenceDescription
-cmsFreeToneCurve                         =    cmsFreeToneCurve
-cmsFreeToneCurveTriple                   =    cmsFreeToneCurveTriple
-cmsGBDAlloc                              =    cmsGBDAlloc
-cmsGBDFree                               =    cmsGBDFree
-cmsGDBAddPoint                           =    cmsGDBAddPoint
-cmsGDBCheckPoint                         =    cmsGDBCheckPoint
-cmsGDBCompute                            =    cmsGDBCompute
-cmsGetAlarmCodes                         =    cmsGetAlarmCodes
-cmsGetColorSpace                         =    cmsGetColorSpace
-cmsGetDeviceClass                        =    cmsGetDeviceClass
-cmsGetEncodedICCversion                  =    cmsGetEncodedICCversion
-cmsGetHeaderAttributes                   =    cmsGetHeaderAttributes
-cmsGetHeaderCreationDateTime             =    cmsGetHeaderCreationDateTime
-cmsGetHeaderFlags                        =    cmsGetHeaderFlags
-cmsGetHeaderManufacturer                 =    cmsGetHeaderManufacturer
-cmsGetHeaderModel                        =    cmsGetHeaderModel
-cmsGetHeaderProfileID                    =    cmsGetHeaderProfileID
-cmsGetHeaderRenderingIntent              =    cmsGetHeaderRenderingIntent
-cmsGetNamedColorList                     =    cmsGetNamedColorList
-cmsGetPCS                                =    cmsGetPCS
-cmsGetPostScriptColorResource            =    cmsGetPostScriptColorResource
-cmsGetPostScriptCRD                      =    cmsGetPostScriptCRD
-cmsGetPostScriptCSA                      =    cmsGetPostScriptCSA
-cmsGetProfileInfo                        =    cmsGetProfileInfo
-cmsGetProfileInfoASCII                   =    cmsGetProfileInfoASCII
-cmsGetProfileContextID                    =    cmsGetProfileContextID
-cmsGetProfileVersion                     =    cmsGetProfileVersion
-cmsGetSupportedIntents                   =    cmsGetSupportedIntents
-cmsGetTagCount                           =    cmsGetTagCount
-cmsGetTagSignature                       =    cmsGetTagSignature
-cmsGetTransformContextID                  =    cmsGetTransformContextID
-_cmsICCcolorSpace                        =    _cmsICCcolorSpace
-_cmsIOPrintf                             =    _cmsIOPrintf
-cmsIsCLUT                                =    cmsIsCLUT
-cmsIsIntentSupported                     =    cmsIsIntentSupported
-cmsIsMatrixShaper                        =    cmsIsMatrixShaper
-cmsIsTag                                 =    cmsIsTag
-cmsIsToneCurveDescending                 =    cmsIsToneCurveDescending
-cmsIsToneCurveLinear                     =    cmsIsToneCurveLinear
-cmsIsToneCurveMonotonic                  =    cmsIsToneCurveMonotonic
-cmsIsToneCurveMultisegment               =    cmsIsToneCurveMultisegment
-cmsGetToneCurveParametricType            =    cmsGetToneCurveParametricType
-cmsIT8Alloc                              =    cmsIT8Alloc
-cmsIT8DefineDblFormat                    =    cmsIT8DefineDblFormat
-cmsIT8EnumDataFormat                     =    cmsIT8EnumDataFormat
-cmsIT8EnumProperties                     =    cmsIT8EnumProperties
-cmsIT8Free                               =    cmsIT8Free
-cmsIT8GetData                            =    cmsIT8GetData
-cmsIT8GetDataDbl                         =    cmsIT8GetDataDbl
-cmsIT8FindDataFormat                      =    cmsIT8FindDataFormat
-cmsIT8GetDataRowCol                      =    cmsIT8GetDataRowCol
-cmsIT8GetDataRowColDbl                   =    cmsIT8GetDataRowColDbl
-cmsIT8GetPatchName                       =    cmsIT8GetPatchName
-cmsIT8GetProperty                        =    cmsIT8GetProperty
-cmsIT8GetPropertyDbl                     =    cmsIT8GetPropertyDbl
-cmsIT8GetSheetType                       =    cmsIT8GetSheetType
-cmsIT8LoadFromFile                       =    cmsIT8LoadFromFile
-cmsIT8LoadFromMem                        =    cmsIT8LoadFromMem
-cmsIT8SaveToFile                         =    cmsIT8SaveToFile
-cmsIT8SaveToMem                          =    cmsIT8SaveToMem
-cmsIT8SetComment                         =    cmsIT8SetComment
-cmsIT8SetData                            =    cmsIT8SetData
-cmsIT8SetDataDbl                         =    cmsIT8SetDataDbl
-cmsIT8SetDataFormat                      =    cmsIT8SetDataFormat
-cmsIT8SetDataRowCol                      =    cmsIT8SetDataRowCol
-cmsIT8SetDataRowColDbl                   =    cmsIT8SetDataRowColDbl
-cmsIT8SetPropertyDbl                     =    cmsIT8SetPropertyDbl
-cmsIT8SetPropertyHex                     =    cmsIT8SetPropertyHex
-cmsIT8SetPropertyStr                     =    cmsIT8SetPropertyStr
-cmsIT8SetPropertyUncooked                =    cmsIT8SetPropertyUncooked
-cmsIT8SetSheetType                       =    cmsIT8SetSheetType
-cmsIT8SetTable                           =    cmsIT8SetTable
-cmsIT8SetTableByLabel                    =    cmsIT8SetTableByLabel
-cmsIT8TableCount                         =    cmsIT8TableCount
-cmsJoinToneCurve                         =    cmsJoinToneCurve
-cmsLab2LCh                               =    cmsLab2LCh
-cmsLab2XYZ                               =    cmsLab2XYZ
-cmsLabEncoded2Float                      =    cmsLabEncoded2Float
-cmsLabEncoded2FloatV2                    =    cmsLabEncoded2FloatV2
-cmsLCh2Lab                               =    cmsLCh2Lab
-_cmsLCMScolorSpace                       =    _cmsLCMScolorSpace
-cmsLinkTag                               =    cmsLinkTag
-cmsTagLinkedTo                           =    cmsTagLinkedTo
-cmsPipelineAlloc                         =    cmsPipelineAlloc
-cmsPipelineCat                           =    cmsPipelineCat
-cmsPipelineCheckAndRetreiveStages        =    cmsPipelineCheckAndRetreiveStages
-cmsPipelineDup                           =    cmsPipelineDup
-cmsPipelineStageCount                    =    cmsPipelineStageCount
-cmsPipelineEval16                        =    cmsPipelineEval16
-cmsPipelineEvalFloat                     =    cmsPipelineEvalFloat
-cmsPipelineEvalReverseFloat              =    cmsPipelineEvalReverseFloat
-cmsPipelineFree                          =    cmsPipelineFree
-cmsPipelineGetPtrToFirstStage            =    cmsPipelineGetPtrToFirstStage
-cmsPipelineGetPtrToLastStage             =    cmsPipelineGetPtrToLastStage
-cmsPipelineInputChannels                 =    cmsPipelineInputChannels
-cmsPipelineInsertStage                   =    cmsPipelineInsertStage
-cmsPipelineOutputChannels                =    cmsPipelineOutputChannels
-cmsPipelineSetSaveAs8bitsFlag            =    cmsPipelineSetSaveAs8bitsFlag
-_cmsPipelineSetOptimizationParameters    =    _cmsPipelineSetOptimizationParameters
-cmsPipelineUnlinkStage                   =    cmsPipelineUnlinkStage
-_cmsMalloc                               =    _cmsMalloc
-_cmsMallocZero                           =    _cmsMallocZero
-_cmsMAT3eval                             =    _cmsMAT3eval
-_cmsMAT3identity                         =    _cmsMAT3identity
-_cmsMAT3inverse                          =    _cmsMAT3inverse
-_cmsMAT3isIdentity                       =    _cmsMAT3isIdentity
-_cmsMAT3per                              =    _cmsMAT3per
-_cmsMAT3solve                            =    _cmsMAT3solve
-cmsMD5computeID                          =    cmsMD5computeID
-cmsMLUalloc                              =    cmsMLUalloc
-cmsMLUdup                                =    cmsMLUdup
-cmsMLUfree                               =    cmsMLUfree
-cmsMLUgetASCII                           =    cmsMLUgetASCII
-cmsMLUgetTranslation                     =    cmsMLUgetTranslation
-cmsMLUgetWide                            =    cmsMLUgetWide
-cmsMLUsetASCII                           =    cmsMLUsetASCII
-cmsMLUsetWide                            =    cmsMLUsetWide
-cmsStageAllocCLut16bit                   =    cmsStageAllocCLut16bit
-cmsStageAllocCLut16bitGranular           =    cmsStageAllocCLut16bitGranular
-cmsStageAllocCLutFloat                   =    cmsStageAllocCLutFloat
-cmsStageAllocCLutFloatGranular           =    cmsStageAllocCLutFloatGranular
-cmsStageAllocToneCurves                  =    cmsStageAllocToneCurves
-cmsStageAllocIdentity                    =    cmsStageAllocIdentity
-cmsStageAllocMatrix                      =    cmsStageAllocMatrix
-_cmsStageAllocPlaceholder                =    _cmsStageAllocPlaceholder
-cmsStageDup                              =    cmsStageDup
-cmsStageFree                             =    cmsStageFree
-cmsStageNext                             =    cmsStageNext
-cmsStageInputChannels                    =    cmsStageInputChannels
-cmsStageOutputChannels                   =    cmsStageOutputChannels
-cmsStageSampleCLut16bit                  =    cmsStageSampleCLut16bit
-cmsStageSampleCLutFloat                  =    cmsStageSampleCLutFloat
-cmsStageType                             =    cmsStageType
-cmsStageData                             =    cmsStageData
-cmsNamedColorCount                       =    cmsNamedColorCount
-cmsNamedColorIndex                       =    cmsNamedColorIndex
-cmsNamedColorInfo                        =    cmsNamedColorInfo
-cmsOpenIOhandlerFromFile                 =    cmsOpenIOhandlerFromFile
-cmsOpenIOhandlerFromMem                  =    cmsOpenIOhandlerFromMem
-cmsOpenIOhandlerFromNULL                 =    cmsOpenIOhandlerFromNULL
-cmsOpenIOhandlerFromStream               =    cmsOpenIOhandlerFromStream
-cmsOpenProfileFromFile                   =    cmsOpenProfileFromFile
-cmsOpenProfileFromFileTHR                =    cmsOpenProfileFromFileTHR
-cmsOpenProfileFromIOhandlerTHR           =    cmsOpenProfileFromIOhandlerTHR
-cmsOpenProfileFromMem                    =    cmsOpenProfileFromMem
-cmsOpenProfileFromMemTHR                 =    cmsOpenProfileFromMemTHR
-cmsOpenProfileFromStream                 =    cmsOpenProfileFromStream
-cmsOpenProfileFromStreamTHR              =    cmsOpenProfileFromStreamTHR
-cmsPlugin                                =    cmsPlugin
-_cmsRead15Fixed16Number                  =    _cmsRead15Fixed16Number
-_cmsReadAlignment                        =    _cmsReadAlignment
-_cmsReadFloat32Number                    =    _cmsReadFloat32Number
-cmsReadRawTag                            =    cmsReadRawTag
-cmsReadTag                               =    cmsReadTag
-_cmsReadTypeBase                         =    _cmsReadTypeBase
-_cmsReadUInt16Array                      =    _cmsReadUInt16Array
-_cmsReadUInt16Number                     =    _cmsReadUInt16Number
-_cmsReadUInt32Number                     =    _cmsReadUInt32Number
-_cmsReadUInt64Number                     =    _cmsReadUInt64Number
-_cmsReadUInt8Number                      =    _cmsReadUInt8Number
-_cmsReadXYZNumber                        =    _cmsReadXYZNumber
-_cmsRealloc                              =    _cmsRealloc
-cmsReverseToneCurve                      =    cmsReverseToneCurve
-cmsReverseToneCurveEx                    =    cmsReverseToneCurveEx
-cmsSaveProfileToFile                     =    cmsSaveProfileToFile
-cmsSaveProfileToIOhandler                =    cmsSaveProfileToIOhandler
-cmsSaveProfileToMem                      =    cmsSaveProfileToMem
-cmsSaveProfileToStream                   =    cmsSaveProfileToStream
-cmsSetAdaptationState                    =    cmsSetAdaptationState
-cmsSetAlarmCodes                         =    cmsSetAlarmCodes
-cmsSetColorSpace                         =    cmsSetColorSpace
-cmsSetDeviceClass                        =    cmsSetDeviceClass
-cmsSetEncodedICCversion                  =    cmsSetEncodedICCversion
-cmsSetHeaderAttributes                   =    cmsSetHeaderAttributes
-cmsSetHeaderFlags                        =    cmsSetHeaderFlags
-cmsSetHeaderManufacturer                 =    cmsSetHeaderManufacturer
-cmsSetHeaderModel                        =    cmsSetHeaderModel
-cmsSetHeaderProfileID                    =    cmsSetHeaderProfileID
-cmsSetHeaderRenderingIntent              =    cmsSetHeaderRenderingIntent
-cmsSetLogErrorHandler                    =    cmsSetLogErrorHandler
-cmsSetPCS                                =    cmsSetPCS
-cmsSetProfileVersion                     =    cmsSetProfileVersion
-cmsSignalError                           =    cmsSignalError
-cmsSmoothToneCurve                       =    cmsSmoothToneCurve
-cmsstrcasecmp                            =    cmsstrcasecmp
-cmsTempFromWhitePoint                    =    cmsTempFromWhitePoint
-cmsTransform2DeviceLink                  =    cmsTransform2DeviceLink
-cmsUnregisterPlugins                     =    cmsUnregisterPlugins
-_cmsVEC3cross                            =    _cmsVEC3cross
-_cmsVEC3distance                         =    _cmsVEC3distance
-_cmsVEC3dot                              =    _cmsVEC3dot
-_cmsVEC3init                             =    _cmsVEC3init
-_cmsVEC3length                           =    _cmsVEC3length
-_cmsVEC3minus                            =    _cmsVEC3minus
-cmsWhitePointFromTemp                    =    cmsWhitePointFromTemp
-_cmsWrite15Fixed16Number                 =    _cmsWrite15Fixed16Number
-_cmsWriteAlignment                       =    _cmsWriteAlignment
-_cmsWriteFloat32Number                   =    _cmsWriteFloat32Number
-cmsWriteRawTag                           =    cmsWriteRawTag
-cmsWriteTag                              =    cmsWriteTag
-_cmsWriteTypeBase                        =    _cmsWriteTypeBase
-_cmsWriteUInt16Array                     =    _cmsWriteUInt16Array
-_cmsWriteUInt16Number                    =    _cmsWriteUInt16Number
-_cmsWriteUInt32Number                    =    _cmsWriteUInt32Number
-_cmsWriteUInt64Number                    =    _cmsWriteUInt64Number
-_cmsWriteUInt8Number                     =    _cmsWriteUInt8Number
-_cmsWriteXYZNumber                       =    _cmsWriteXYZNumber
-cmsxyY2XYZ                               =   cmsxyY2XYZ
-cmsXYZ2Lab                               =   cmsXYZ2Lab
-cmsXYZ2xyY                               =   cmsXYZ2xyY
-cmsXYZEncoded2Float                      =   cmsXYZEncoded2Float
-cmsSliceSpace16                          =   cmsSliceSpace16
-cmsSliceSpaceFloat                       =   cmsSliceSpaceFloat
-cmsChangeBuffersFormat                   =   cmsChangeBuffersFormat
-cmsDictAlloc                             =   cmsDictAlloc 
-cmsDictFree                              =   cmsDictFree
-cmsDictDup                               =   cmsDictDup
-cmsDictAddEntry                          =   cmsDictAddEntry
-cmsDictGetEntryList                      =   cmsDictGetEntryList
-cmsDictNextEntry                         =   cmsDictNextEntry
-                                         
-                                         
\ No newline at end of file
+LIBRARY     LCMS2.DLL\r
+\r
+EXPORTS\r
+\r
+_cms15Fixed16toDouble                    =   _cms15Fixed16toDouble\r
+_cms8Fixed8toDouble                      =   _cms8Fixed8toDouble\r
+cmsAdaptToIlluminant                     =    cmsAdaptToIlluminant\r
+_cmsAdjustEndianess16                    =   _cmsAdjustEndianess16\r
+_cmsAdjustEndianess32                    =   _cmsAdjustEndianess32\r
+_cmsAdjustEndianess64                    =   _cmsAdjustEndianess64\r
+cmsAllocNamedColorList                   =   cmsAllocNamedColorList\r
+cmsAllocProfileSequenceDescription       =   cmsAllocProfileSequenceDescription\r
+cmsAppendNamedColor                      =   cmsAppendNamedColor\r
+cmsBFDdeltaE                             =   cmsBFDdeltaE\r
+cmsBuildGamma                            =   cmsBuildGamma\r
+cmsBuildParametricToneCurve              =   cmsBuildParametricToneCurve\r
+cmsBuildSegmentedToneCurve               =   cmsBuildSegmentedToneCurve\r
+cmsBuildTabulatedToneCurve16             =   cmsBuildTabulatedToneCurve16\r
+cmsBuildTabulatedToneCurveFloat          =   cmsBuildTabulatedToneCurveFloat\r
+_cmsCalloc                               =   _cmsCalloc\r
+cmsChannelsOf                            =    cmsChannelsOf\r
+cmsCIE2000DeltaE                         =    cmsCIE2000DeltaE\r
+cmsCIE94DeltaE                           =    cmsCIE94DeltaE\r
+cmsCIECAM02Done                          =    cmsCIECAM02Done\r
+cmsCIECAM02Forward                       =    cmsCIECAM02Forward\r
+cmsCIECAM02Init                          =    cmsCIECAM02Init\r
+cmsCIECAM02Reverse                       =    cmsCIECAM02Reverse\r
+cmsCloseIOhandler                        =    cmsCloseIOhandler\r
+cmsCloseProfile                          =    cmsCloseProfile\r
+cmsCMCdeltaE                             =    cmsCMCdeltaE\r
+cmsCreate_sRGBProfile                    =    cmsCreate_sRGBProfile\r
+cmsCreate_sRGBProfileTHR                 =    cmsCreate_sRGBProfileTHR\r
+cmsCreateBCHSWabstractProfile            =    cmsCreateBCHSWabstractProfile\r
+cmsCreateBCHSWabstractProfileTHR         =    cmsCreateBCHSWabstractProfileTHR\r
+cmsCreateExtendedTransform               =    cmsCreateExtendedTransform\r
+cmsCreateGrayProfile                     =    cmsCreateGrayProfile\r
+cmsCreateGrayProfileTHR                  =    cmsCreateGrayProfileTHR\r
+cmsCreateInkLimitingDeviceLink           =    cmsCreateInkLimitingDeviceLink\r
+cmsCreateInkLimitingDeviceLinkTHR        =    cmsCreateInkLimitingDeviceLinkTHR\r
+cmsCreateLab2Profile                     =    cmsCreateLab2Profile\r
+cmsCreateLab2ProfileTHR                  =    cmsCreateLab2ProfileTHR\r
+cmsCreateLab4Profile                     =    cmsCreateLab4Profile\r
+cmsCreateLab4ProfileTHR                  =    cmsCreateLab4ProfileTHR\r
+cmsCreateLinearizationDeviceLink         =    cmsCreateLinearizationDeviceLink\r
+cmsCreateLinearizationDeviceLinkTHR      =    cmsCreateLinearizationDeviceLinkTHR\r
+cmsCreateMultiprofileTransform           =    cmsCreateMultiprofileTransform\r
+cmsCreateMultiprofileTransformTHR        =    cmsCreateMultiprofileTransformTHR\r
+cmsCreateNULLProfile                     =    cmsCreateNULLProfile\r
+cmsCreateNULLProfileTHR                  =    cmsCreateNULLProfileTHR\r
+cmsCreateProfilePlaceholder              =    cmsCreateProfilePlaceholder\r
+cmsCreateProofingTransform               =    cmsCreateProofingTransform\r
+cmsCreateProofingTransformTHR            =    cmsCreateProofingTransformTHR\r
+cmsCreateRGBProfile                      =    cmsCreateRGBProfile\r
+cmsCreateRGBProfileTHR                   =    cmsCreateRGBProfileTHR\r
+cmsCreateTransform                       =    cmsCreateTransform\r
+cmsCreateTransformTHR                    =    cmsCreateTransformTHR\r
+cmsCreateXYZProfile                      =    cmsCreateXYZProfile\r
+cmsCreateXYZProfileTHR                   =    cmsCreateXYZProfileTHR\r
+cmsD50_xyY                               =    cmsD50_xyY\r
+cmsD50_XYZ                               =    cmsD50_XYZ\r
+_cmsDecodeDateTimeNumber                 =    _cmsDecodeDateTimeNumber\r
+_cmsDefaultICCintents                    =    _cmsDefaultICCintents\r
+cmsDeleteTransform                       =    cmsDeleteTransform\r
+cmsDeltaE                                =    cmsDeltaE\r
+cmsDetectBlackPoint                      =    cmsDetectBlackPoint\r
+cmsDetectDestinationBlackPoint           =    cmsDetectDestinationBlackPoint\r
+cmsDetectTAC                             =    cmsDetectTAC\r
+cmsDesaturateLab                         =    cmsDesaturateLab\r
+cmsDoTransform                           =    cmsDoTransform\r
+cmsDoTransformStride                     =    cmsDoTransformStride\r
+_cmsDoubleTo15Fixed16                    =    _cmsDoubleTo15Fixed16\r
+_cmsDoubleTo8Fixed8                      =    _cmsDoubleTo8Fixed8\r
+_cmsDupMem                               =    _cmsDupMem\r
+cmsDupNamedColorList                     =    cmsDupNamedColorList\r
+cmsDupProfileSequenceDescription         =    cmsDupProfileSequenceDescription\r
+cmsDupToneCurve                          =    cmsDupToneCurve\r
+_cmsEncodeDateTimeNumber                 =    _cmsEncodeDateTimeNumber\r
+cmsEstimateGamma                         =    cmsEstimateGamma\r
+cmsGetToneCurveEstimatedTableEntries     =    cmsGetToneCurveEstimatedTableEntries\r
+cmsGetToneCurveEstimatedTable            =    cmsGetToneCurveEstimatedTable\r
+cmsEvalToneCurve16                       =    cmsEvalToneCurve16\r
+cmsEvalToneCurveFloat                    =    cmsEvalToneCurveFloat\r
+cmsfilelength                            =    cmsfilelength\r
+cmsFloat2LabEncoded                      =    cmsFloat2LabEncoded\r
+cmsFloat2LabEncodedV2                    =    cmsFloat2LabEncodedV2\r
+cmsFloat2XYZEncoded                      =    cmsFloat2XYZEncoded\r
+cmsFormatterForColorspaceOfProfile       =    cmsFormatterForColorspaceOfProfile\r
+cmsFormatterForPCSOfProfile              =    cmsFormatterForPCSOfProfile\r
+_cmsFree                                 =    _cmsFree\r
+cmsFreeNamedColorList                    =    cmsFreeNamedColorList\r
+cmsFreeProfileSequenceDescription        =    cmsFreeProfileSequenceDescription\r
+cmsFreeToneCurve                         =    cmsFreeToneCurve\r
+cmsFreeToneCurveTriple                   =    cmsFreeToneCurveTriple\r
+cmsGBDAlloc                              =    cmsGBDAlloc\r
+cmsGBDFree                               =    cmsGBDFree\r
+cmsGDBAddPoint                           =    cmsGDBAddPoint\r
+cmsGDBCheckPoint                         =    cmsGDBCheckPoint\r
+cmsGDBCompute                            =    cmsGDBCompute\r
+cmsGetAlarmCodes                         =    cmsGetAlarmCodes\r
+cmsGetColorSpace                         =    cmsGetColorSpace\r
+cmsGetDeviceClass                        =    cmsGetDeviceClass\r
+cmsGetEncodedICCversion                  =    cmsGetEncodedICCversion\r
+cmsGetHeaderAttributes                   =    cmsGetHeaderAttributes\r
+cmsGetHeaderCreationDateTime             =    cmsGetHeaderCreationDateTime\r
+cmsGetHeaderFlags                        =    cmsGetHeaderFlags\r
+cmsGetHeaderManufacturer                 =    cmsGetHeaderManufacturer\r
+cmsGetHeaderModel                        =    cmsGetHeaderModel\r
+cmsGetHeaderProfileID                    =    cmsGetHeaderProfileID\r
+cmsGetHeaderRenderingIntent              =    cmsGetHeaderRenderingIntent\r
+cmsGetNamedColorList                     =    cmsGetNamedColorList\r
+cmsGetPCS                                =    cmsGetPCS\r
+cmsGetPostScriptColorResource            =    cmsGetPostScriptColorResource\r
+cmsGetPostScriptCRD                      =    cmsGetPostScriptCRD\r
+cmsGetPostScriptCSA                      =    cmsGetPostScriptCSA\r
+cmsGetProfileInfo                        =    cmsGetProfileInfo\r
+cmsGetProfileInfoASCII                   =    cmsGetProfileInfoASCII\r
+cmsGetProfileContextID                   =    cmsGetProfileContextID\r
+cmsGetProfileVersion                     =    cmsGetProfileVersion\r
+cmsGetSupportedIntents                   =    cmsGetSupportedIntents\r
+cmsGetTagCount                           =    cmsGetTagCount\r
+cmsGetTagSignature                       =    cmsGetTagSignature\r
+cmsGetTransformContextID                 =    cmsGetTransformContextID\r
+_cmsICCcolorSpace                        =    _cmsICCcolorSpace\r
+_cmsIOPrintf                             =    _cmsIOPrintf\r
+cmsIsCLUT                                =    cmsIsCLUT\r
+cmsIsIntentSupported                     =    cmsIsIntentSupported\r
+cmsIsMatrixShaper                        =    cmsIsMatrixShaper\r
+cmsIsTag                                 =    cmsIsTag\r
+cmsIsToneCurveDescending                 =    cmsIsToneCurveDescending\r
+cmsIsToneCurveLinear                     =    cmsIsToneCurveLinear\r
+cmsIsToneCurveMonotonic                  =    cmsIsToneCurveMonotonic\r
+cmsIsToneCurveMultisegment               =    cmsIsToneCurveMultisegment\r
+cmsGetToneCurveParametricType            =    cmsGetToneCurveParametricType\r
+cmsIT8Alloc                              =    cmsIT8Alloc\r
+cmsIT8DefineDblFormat                    =    cmsIT8DefineDblFormat\r
+cmsIT8EnumDataFormat                     =    cmsIT8EnumDataFormat\r
+cmsIT8EnumProperties                     =    cmsIT8EnumProperties\r
+cmsIT8EnumPropertyMulti                  =    cmsIT8EnumPropertyMulti\r
+cmsIT8Free                               =    cmsIT8Free\r
+cmsIT8GetData                            =    cmsIT8GetData\r
+cmsIT8GetDataDbl                         =    cmsIT8GetDataDbl\r
+cmsIT8FindDataFormat                     =    cmsIT8FindDataFormat\r
+cmsIT8GetDataRowCol                      =    cmsIT8GetDataRowCol\r
+cmsIT8GetDataRowColDbl                   =    cmsIT8GetDataRowColDbl\r
+cmsIT8GetPatchName                       =    cmsIT8GetPatchName\r
+cmsIT8GetPatchByName                     =    cmsIT8GetPatchByName\r
+cmsIT8GetProperty                        =    cmsIT8GetProperty\r
+cmsIT8GetPropertyDbl                     =    cmsIT8GetPropertyDbl\r
+cmsIT8GetPropertyMulti                   =    cmsIT8GetPropertyMulti\r
+cmsIT8GetSheetType                       =    cmsIT8GetSheetType\r
+cmsIT8LoadFromFile                       =    cmsIT8LoadFromFile\r
+cmsIT8LoadFromMem                        =    cmsIT8LoadFromMem\r
+cmsIT8SaveToFile                         =    cmsIT8SaveToFile\r
+cmsIT8SaveToMem                          =    cmsIT8SaveToMem\r
+cmsIT8SetComment                         =    cmsIT8SetComment\r
+cmsIT8SetData                            =    cmsIT8SetData\r
+cmsIT8SetDataDbl                         =    cmsIT8SetDataDbl\r
+cmsIT8SetDataFormat                      =    cmsIT8SetDataFormat\r
+cmsIT8SetDataRowCol                      =    cmsIT8SetDataRowCol\r
+cmsIT8SetDataRowColDbl                   =    cmsIT8SetDataRowColDbl\r
+cmsIT8SetPropertyDbl                     =    cmsIT8SetPropertyDbl\r
+cmsIT8SetPropertyHex                     =    cmsIT8SetPropertyHex\r
+cmsIT8SetPropertyStr                     =    cmsIT8SetPropertyStr\r
+cmsIT8SetPropertyMulti                   =    cmsIT8SetPropertyMulti\r
+cmsIT8SetPropertyUncooked                =    cmsIT8SetPropertyUncooked\r
+cmsIT8SetSheetType                       =    cmsIT8SetSheetType\r
+cmsIT8SetTable                           =    cmsIT8SetTable\r
+cmsIT8SetTableByLabel                    =    cmsIT8SetTableByLabel\r
+cmsIT8SetIndexColumn                     =    cmsIT8SetIndexColumn\r
+cmsIT8TableCount                         =    cmsIT8TableCount\r
+cmsJoinToneCurve                         =    cmsJoinToneCurve\r
+cmsLab2LCh                               =    cmsLab2LCh\r
+cmsLab2XYZ                               =    cmsLab2XYZ\r
+cmsLabEncoded2Float                      =    cmsLabEncoded2Float\r
+cmsLabEncoded2FloatV2                    =    cmsLabEncoded2FloatV2\r
+cmsLCh2Lab                               =    cmsLCh2Lab\r
+_cmsLCMScolorSpace                       =    _cmsLCMScolorSpace\r
+cmsLinkTag                               =    cmsLinkTag\r
+cmsTagLinkedTo                           =    cmsTagLinkedTo\r
+cmsPipelineAlloc                         =    cmsPipelineAlloc\r
+cmsPipelineCat                           =    cmsPipelineCat\r
+cmsPipelineCheckAndRetreiveStages        =    cmsPipelineCheckAndRetreiveStages\r
+cmsPipelineDup                           =    cmsPipelineDup\r
+cmsPipelineStageCount                    =    cmsPipelineStageCount\r
+cmsPipelineEval16                        =    cmsPipelineEval16\r
+cmsPipelineEvalFloat                     =    cmsPipelineEvalFloat\r
+cmsPipelineEvalReverseFloat              =    cmsPipelineEvalReverseFloat\r
+cmsPipelineFree                          =    cmsPipelineFree\r
+cmsPipelineGetPtrToFirstStage            =    cmsPipelineGetPtrToFirstStage\r
+cmsPipelineGetPtrToLastStage             =    cmsPipelineGetPtrToLastStage\r
+cmsPipelineInputChannels                 =    cmsPipelineInputChannels\r
+cmsPipelineInsertStage                   =    cmsPipelineInsertStage\r
+cmsPipelineOutputChannels                =    cmsPipelineOutputChannels\r
+cmsPipelineSetSaveAs8bitsFlag            =    cmsPipelineSetSaveAs8bitsFlag\r
+_cmsPipelineSetOptimizationParameters    =    _cmsPipelineSetOptimizationParameters\r
+cmsPipelineUnlinkStage                   =    cmsPipelineUnlinkStage\r
+_cmsMalloc                               =    _cmsMalloc\r
+_cmsMallocZero                           =    _cmsMallocZero\r
+_cmsMAT3eval                             =    _cmsMAT3eval\r
+_cmsMAT3identity                         =    _cmsMAT3identity\r
+_cmsMAT3inverse                          =    _cmsMAT3inverse\r
+_cmsMAT3isIdentity                       =    _cmsMAT3isIdentity\r
+_cmsMAT3per                              =    _cmsMAT3per\r
+_cmsMAT3solve                            =    _cmsMAT3solve\r
+cmsMD5computeID                          =    cmsMD5computeID\r
+cmsMLUalloc                              =    cmsMLUalloc\r
+cmsMLUdup                                =    cmsMLUdup\r
+cmsMLUfree                               =    cmsMLUfree\r
+cmsMLUgetASCII                           =    cmsMLUgetASCII\r
+cmsMLUgetTranslation                     =    cmsMLUgetTranslation\r
+cmsMLUgetWide                            =    cmsMLUgetWide\r
+cmsMLUsetASCII                           =    cmsMLUsetASCII\r
+cmsMLUsetWide                            =    cmsMLUsetWide\r
+cmsStageAllocCLut16bit                   =    cmsStageAllocCLut16bit\r
+cmsStageAllocCLut16bitGranular           =    cmsStageAllocCLut16bitGranular\r
+cmsStageAllocCLutFloat                   =    cmsStageAllocCLutFloat\r
+cmsStageAllocCLutFloatGranular           =    cmsStageAllocCLutFloatGranular\r
+cmsStageAllocToneCurves                  =    cmsStageAllocToneCurves\r
+cmsStageAllocIdentity                    =    cmsStageAllocIdentity\r
+cmsStageAllocMatrix                      =    cmsStageAllocMatrix\r
+_cmsStageAllocPlaceholder                =    _cmsStageAllocPlaceholder\r
+cmsStageDup                              =    cmsStageDup\r
+cmsStageFree                             =    cmsStageFree\r
+cmsStageNext                             =    cmsStageNext\r
+cmsStageInputChannels                    =    cmsStageInputChannels\r
+cmsStageOutputChannels                   =    cmsStageOutputChannels\r
+cmsStageSampleCLut16bit                  =    cmsStageSampleCLut16bit\r
+cmsStageSampleCLutFloat                  =    cmsStageSampleCLutFloat\r
+cmsStageType                             =    cmsStageType\r
+cmsStageData                             =    cmsStageData\r
+cmsNamedColorCount                       =    cmsNamedColorCount\r
+cmsNamedColorIndex                       =    cmsNamedColorIndex\r
+cmsNamedColorInfo                        =    cmsNamedColorInfo\r
+cmsOpenIOhandlerFromFile                 =    cmsOpenIOhandlerFromFile\r
+cmsOpenIOhandlerFromMem                  =    cmsOpenIOhandlerFromMem\r
+cmsOpenIOhandlerFromNULL                 =    cmsOpenIOhandlerFromNULL\r
+cmsOpenIOhandlerFromStream               =    cmsOpenIOhandlerFromStream\r
+cmsOpenProfileFromFile                   =    cmsOpenProfileFromFile\r
+cmsOpenProfileFromFileTHR                =    cmsOpenProfileFromFileTHR\r
+cmsOpenProfileFromIOhandlerTHR           =    cmsOpenProfileFromIOhandlerTHR\r
+cmsOpenProfileFromMem                    =    cmsOpenProfileFromMem\r
+cmsOpenProfileFromMemTHR                 =    cmsOpenProfileFromMemTHR\r
+cmsOpenProfileFromStream                 =    cmsOpenProfileFromStream\r
+cmsOpenProfileFromStreamTHR              =    cmsOpenProfileFromStreamTHR\r
+cmsPlugin                                =    cmsPlugin\r
+_cmsRead15Fixed16Number                  =    _cmsRead15Fixed16Number\r
+_cmsReadAlignment                        =    _cmsReadAlignment\r
+_cmsReadFloat32Number                    =    _cmsReadFloat32Number\r
+cmsReadRawTag                            =    cmsReadRawTag\r
+cmsReadTag                               =    cmsReadTag\r
+_cmsReadTypeBase                         =    _cmsReadTypeBase\r
+_cmsReadUInt16Array                      =    _cmsReadUInt16Array\r
+_cmsReadUInt16Number                     =    _cmsReadUInt16Number\r
+_cmsReadUInt32Number                     =    _cmsReadUInt32Number\r
+_cmsReadUInt64Number                     =    _cmsReadUInt64Number\r
+_cmsReadUInt8Number                      =    _cmsReadUInt8Number\r
+_cmsReadXYZNumber                        =    _cmsReadXYZNumber\r
+_cmsRealloc                              =    _cmsRealloc\r
+cmsReverseToneCurve                      =    cmsReverseToneCurve\r
+cmsReverseToneCurveEx                    =    cmsReverseToneCurveEx\r
+cmsSaveProfileToFile                     =    cmsSaveProfileToFile\r
+cmsSaveProfileToIOhandler                =    cmsSaveProfileToIOhandler\r
+cmsSaveProfileToMem                      =    cmsSaveProfileToMem\r
+cmsSaveProfileToStream                   =    cmsSaveProfileToStream\r
+cmsSetAdaptationState                    =    cmsSetAdaptationState\r
+cmsSetAlarmCodes                         =    cmsSetAlarmCodes\r
+cmsSetColorSpace                         =    cmsSetColorSpace\r
+cmsSetDeviceClass                        =    cmsSetDeviceClass\r
+cmsSetEncodedICCversion                  =    cmsSetEncodedICCversion\r
+cmsSetHeaderAttributes                   =    cmsSetHeaderAttributes\r
+cmsSetHeaderFlags                        =    cmsSetHeaderFlags\r
+cmsSetHeaderManufacturer                 =    cmsSetHeaderManufacturer\r
+cmsSetHeaderModel                        =    cmsSetHeaderModel\r
+cmsSetHeaderProfileID                    =    cmsSetHeaderProfileID\r
+cmsSetHeaderRenderingIntent              =    cmsSetHeaderRenderingIntent\r
+cmsSetLogErrorHandler                    =    cmsSetLogErrorHandler\r
+cmsSetPCS                                =    cmsSetPCS\r
+cmsSetProfileVersion                     =    cmsSetProfileVersion\r
+cmsSignalError                           =    cmsSignalError\r
+cmsSmoothToneCurve                       =    cmsSmoothToneCurve\r
+cmsstrcasecmp                            =    cmsstrcasecmp\r
+cmsTempFromWhitePoint                    =    cmsTempFromWhitePoint\r
+cmsTransform2DeviceLink                  =    cmsTransform2DeviceLink\r
+cmsUnregisterPlugins                     =    cmsUnregisterPlugins\r
+_cmsVEC3cross                            =    _cmsVEC3cross\r
+_cmsVEC3distance                         =    _cmsVEC3distance\r
+_cmsVEC3dot                              =    _cmsVEC3dot\r
+_cmsVEC3init                             =    _cmsVEC3init\r
+_cmsVEC3length                           =    _cmsVEC3length\r
+_cmsVEC3minus                            =    _cmsVEC3minus\r
+cmsWhitePointFromTemp                    =    cmsWhitePointFromTemp\r
+_cmsWrite15Fixed16Number                 =    _cmsWrite15Fixed16Number\r
+_cmsWriteAlignment                       =    _cmsWriteAlignment\r
+_cmsWriteFloat32Number                   =    _cmsWriteFloat32Number\r
+cmsWriteRawTag                           =    cmsWriteRawTag\r
+cmsWriteTag                              =    cmsWriteTag\r
+_cmsWriteTypeBase                        =    _cmsWriteTypeBase\r
+_cmsWriteUInt16Array                     =    _cmsWriteUInt16Array\r
+_cmsWriteUInt16Number                    =    _cmsWriteUInt16Number\r
+_cmsWriteUInt32Number                    =    _cmsWriteUInt32Number\r
+_cmsWriteUInt64Number                    =    _cmsWriteUInt64Number\r
+_cmsWriteUInt8Number                     =    _cmsWriteUInt8Number\r
+_cmsWriteXYZNumber                       =    _cmsWriteXYZNumber\r
+cmsxyY2XYZ                               =   cmsxyY2XYZ\r
+cmsXYZ2Lab                               =   cmsXYZ2Lab\r
+cmsXYZ2xyY                               =   cmsXYZ2xyY\r
+cmsXYZEncoded2Float                      =   cmsXYZEncoded2Float\r
+cmsSliceSpace16                          =   cmsSliceSpace16\r
+cmsSliceSpaceFloat                       =   cmsSliceSpaceFloat\r
+cmsChangeBuffersFormat                   =   cmsChangeBuffersFormat\r
+cmsDictAlloc                             =   cmsDictAlloc\r
+cmsDictFree                              =   cmsDictFree\r
+cmsDictDup                               =   cmsDictDup\r
+cmsDictAddEntry                          =   cmsDictAddEntry\r
+cmsDictGetEntryList                      =   cmsDictGetEntryList\r
+cmsDictNextEntry                         =   cmsDictNextEntry\r
+_cmsGetTransformUserData                 =   _cmsGetTransformUserData\r
+_cmsSetTransformUserData                 =   _cmsSetTransformUserData\r
+_cmsGetTransformFormatters16             =   _cmsGetTransformFormatters16\r
+_cmsGetTransformFormattersFloat          =   _cmsGetTransformFormattersFloat\r
index 39e38f0..1b47c28 100644 (file)
@@ -3,22 +3,22 @@
 //  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 
+// 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 
+// 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 
+// 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.
 //
 //---------------------------------------------------------------------------------
 #endif
 
 // BorlandC 5.5, VC2003 are broken on that
-#if defined(__BORLANDC__) || (_MSC_VER <= 1400) // 1400 == VC++ 8.0 
+#if defined(__BORLANDC__) || (_MSC_VER < 1400) // 1400 == VC++ 8.0
 #define sinf(x) (float)sin((float)x)
 #define sqrtf(x) (float)sqrt((float)x)
 #endif
 
 
 // Alignment of ICC file format uses 4 bytes (cmsUInt32Number)
-#define _cmsALIGNLONG(x) (((x)+(sizeof(cmsUInt32Number)-1)) & ~(sizeof(cmsUInt32Number)-1))  
+#define _cmsALIGNLONG(x) (((x)+(sizeof(cmsUInt32Number)-1)) & ~(sizeof(cmsUInt32Number)-1))
 
 // Alignment to memory pointer
 #define _cmsALIGNMEM(x)  (((x)+(sizeof(void *) - 1)) & ~(sizeof(void *) - 1))
@@ -70,7 +70,7 @@
 #define MAX_STAGE_CHANNELS  128
 
 // Unused parameter warning supression
-#define cmsUNUSED_PARAMETER(x) ((void)x) 
+#define cmsUNUSED_PARAMETER(x) ((void)x)
 
 // The specification for "inline" is section 6.7.4 of the C99 standard (ISO/IEC 9899:1999).
 // unfortunately VisualC++ does not conform that
@@ -92,7 +92,7 @@
 
 
 // A fast way to convert from/to 16 <-> 8 bits
-#define FROM_8_TO_16(rgb) (cmsUInt16Number) ((((cmsUInt16Number) (rgb)) << 8)|(rgb)) 
+#define FROM_8_TO_16(rgb) (cmsUInt16Number) ((((cmsUInt16Number) (rgb)) << 8)|(rgb))
 #define FROM_16_TO_8(rgb) (cmsUInt8Number) ((((rgb) * 65281 + 8388608) >> 24) & 0xFF)
 
 // Code analysis is broken on asserts
 #define ROUND_FIXED_TO_INT(x)   (((x)+0x8000)>>16)
 
 cmsINLINE cmsS15Fixed16Number _cmsToFixedDomain(int a)                   { return a + ((a + 0x7fff) / 0xffff); }
-cmsINLINE int                 _cmsFromFixedDomain(cmsS15Fixed16Number a) { return a - ((a + 0x7fff) >> 16); }   
+cmsINLINE int                 _cmsFromFixedDomain(cmsS15Fixed16Number a) { return a - ((a + 0x7fff) >> 16); }
 
 // -----------------------------------------------------------------------------------------------------------
 
-// Fast floor conversion logic. Thanks to Sree Kotay and Stuart Nixon 
-// note than this only works in the range ..-32767...+32767 because 
+// Fast floor conversion logic. Thanks to Sree Kotay and Stuart Nixon
+// note than this only works in the range ..-32767...+32767 because
 // mantissa is interpreted as 15.16 fixed point.
 // The union is to avoid pointer aliasing overoptimization.
 cmsINLINE int _cmsQuickFloor(cmsFloat64Number val)
@@ -137,9 +137,9 @@ cmsINLINE int _cmsQuickFloor(cmsFloat64Number val)
         cmsFloat64Number val;
         int halves[2];
     } temp;
-    
+
     temp.val = val + _lcms_double2fixmagic;
-    
+
 #ifdef CMS_USE_BIG_ENDIAN
     return temp.halves[1] >> 16;
 #else
@@ -149,13 +149,13 @@ cmsINLINE int _cmsQuickFloor(cmsFloat64Number val)
 }
 
 // Fast floor restricted to 0..65535.0
-cmsINLINE cmsUInt16Number _cmsQuickFloorWord(cmsFloat64Number d) 
-{ 
-    return (cmsUInt16Number) _cmsQuickFloor(d - 32767.0) + 32767U; 
+cmsINLINE cmsUInt16Number _cmsQuickFloorWord(cmsFloat64Number d)
+{
+    return (cmsUInt16Number) _cmsQuickFloor(d - 32767.0) + 32767U;
 }
 
 // Floor to word, taking care of saturation
-cmsINLINE cmsUInt16Number _cmsQuickSaturateWord(cmsFloat64Number d) 
+cmsINLINE cmsUInt16Number _cmsQuickSaturateWord(cmsFloat64Number d)
 {
     d += 0.5;
     if (d <= 0) return 0;
@@ -196,6 +196,8 @@ cmsBool  _cmsRegisterMultiProcessElementPlugin(cmsPluginBase* Plugin);
 // Optimization
 cmsBool  _cmsRegisterOptimizationPlugin(cmsPluginBase* Plugin);
 
+// Transform
+cmsBool  _cmsRegisterTransformPlugin(cmsPluginBase* Plugin);
 
 // ---------------------------------------------------------------------------------------------------------
 
@@ -229,7 +231,7 @@ void*             _cmsSubAlloc(_cmsSubAllocator* s, cmsUInt32Number size);
 typedef struct {
 
     cmsUInt16Number Language;
-    cmsUInt16Number Country;   
+    cmsUInt16Number Country;
 
     cmsUInt32Number StrW;       // Offset to current unicode string
     cmsUInt32Number Len;        // Lenght in bytes
@@ -237,22 +239,22 @@ typedef struct {
 } _cmsMLUentry;
 
 struct _cms_MLU_struct {
+
     cmsContext ContextID;
 
     // The directory
-    int AllocatedEntries; 
+    int AllocatedEntries;
     int UsedEntries;
     _cmsMLUentry* Entries;     // Array of pointers to strings allocated in MemPool
 
     // The Pool
     cmsUInt32Number PoolSize;  // The maximum allocated size
     cmsUInt32Number PoolUsed;  // The used size
-    void*  MemPool;            // Pointer to begin of memory pool  
+    void*  MemPool;            // Pointer to begin of memory pool
 };
 
 // Named color list internal representation
-typedef struct {    
+typedef struct {
 
     char Name[cmsMAX_PATH];
     cmsUInt16Number PCS[3];
@@ -262,12 +264,12 @@ typedef struct {
 
 struct _cms_NAMEDCOLORLIST_struct {
 
-    cmsUInt32Number nColors;                
+    cmsUInt32Number nColors;
     cmsUInt32Number Allocated;
-    cmsUInt32Number ColorantCount;  
+    cmsUInt32Number ColorantCount;
 
     char Prefix[33];      // Prefix and suffix are defined to be 32 characters at most
-    char Suffix[33];     
+    char Suffix[33];
 
     _cmsNAMEDCOLOR* List;
 
@@ -293,7 +295,7 @@ typedef struct _cms_iccprofile_struct {
     // Creation time
     struct tm                Created;
 
-    // Only most important items found in ICC profiles   
+    // Only most important items found in ICC profiles
     cmsUInt32Number          Version;
     cmsProfileClassSignature DeviceClass;
     cmsColorSpaceSignature   ColorSpace;
@@ -317,7 +319,7 @@ typedef struct _cms_iccprofile_struct {
                                                                  // depending on profile version, so we keep track of the                                                             // type handler for each tag in the list.
     // Special
     cmsBool                  IsWrite;
-    
+
 } _cmsICCPROFILE;
 
 // IO helpers for profiles
@@ -357,19 +359,19 @@ struct _cms_curve_struct {
 
     cmsParametricCurveEvaluator* Evals;  // Evaluators (one per segment)
 
-    // 16 bit Table-based representation follows    
+    // 16 bit Table-based representation follows
     cmsUInt32Number    nEntries;      // Number of table elements
-    cmsUInt16Number*   Table16;       // The table itself. 
-}; 
+    cmsUInt16Number*   Table16;       // The table itself.
+};
 
 
 //  Pipelines & Stages ---------------------------------------------------------------------------------------------
 
 // A single stage
 struct _cmsStage_struct {
-    
+
     cmsContext          ContextID;
-    
+
     cmsStageSignature   Type;           // Identifies the stage
     cmsStageSignature   Implements;     // Identifies the *function* of the stage (for optimizations)
 
@@ -387,37 +389,6 @@ struct _cmsStage_struct {
     struct _cmsStage_struct* Next;
 };
 
-// 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;
-
 
 // Special Stages (cannot be saved)
 cmsStage*        _cmsStageAllocLab2XYZ(cmsContext ContextID);
@@ -434,28 +405,28 @@ cmsStage*        _cmsStageNormalizeFromXyzFloat(cmsContext ContextID);
 cmsStage*        _cmsStageNormalizeToLabFloat(cmsContext ContextID);
 cmsStage*        _cmsStageNormalizeToXyzFloat(cmsContext ContextID);
 
-// For curve set only  
+// For curve set only
 cmsToneCurve**     _cmsStageGetPtrToCurveSet(const cmsStage* mpe);
 
 
 // Pipeline Evaluator (in floating point)
-typedef void (* _cmsPipelineEvalFloatFn)(const cmsFloat32Number In[], 
-                                         cmsFloat32Number Out[], 
-                                         const void* Data); 
+typedef void (* _cmsPipelineEvalFloatFn)(const cmsFloat32Number In[],
+                                         cmsFloat32Number Out[],
+                                         const void* Data);
 
 struct _cmsPipeline_struct {
 
-    cmsStage* Elements;                                // Points to elements chain 
-    cmsUInt32Number InputChannels, OutputChannels;  
-   
+    cmsStage* Elements;                                // Points to elements chain
+    cmsUInt32Number InputChannels, OutputChannels;
+
     // Data & evaluators
     void *Data;
 
    _cmsOPTeval16Fn         Eval16Fn;
    _cmsPipelineEvalFloatFn EvalFloatFn;
-   _cmsOPTfreeDataFn       FreeDataFn;
-   _cmsOPTdupDataFn        DupDataFn;
-    
+   _cmsFreeUserDataFn      FreeDataFn;
+   _cmsDupUserDataFn       DupDataFn;
+
     cmsContext ContextID;            // Environment
 
     cmsBool  SaveAs8Bits;            // Implementation-specific: save as 8 bits if possible
@@ -476,10 +447,10 @@ cmsBool           _cmsReadCHAD(cmsMAT3* Dest, cmsHPROFILE hProfile);
 
 // Profile linker --------------------------------------------------------------------------------------------------
 
-cmsPipeline* _cmsLinkProfiles(cmsContext         ContextID, 
+cmsPipeline* _cmsLinkProfiles(cmsContext         ContextID,
                               cmsUInt32Number    nProfiles,
-                              cmsUInt32Number    TheIntents[], 
-                              cmsHPROFILE        hProfiles[], 
+                              cmsUInt32Number    TheIntents[],
+                              cmsHPROFILE        hProfiles[],
                               cmsBool            BPC[],
                               cmsFloat64Number   AdaptationStates[],
                               cmsUInt32Number    dwFlags);
@@ -496,14 +467,14 @@ cmsSEQ* _cmsCompileProfileSequence(cmsContext ContextID, cmsUInt32Number nProfil
 cmsUInt16Number  _cmsQuantizeVal(cmsFloat64Number i, int MaxSamples);
 int              _cmsReasonableGridpointsByColorspace(cmsColorSpaceSignature Colorspace, cmsUInt32Number dwFlags);
 
-cmsBool          _cmsEndPointsBySpace(cmsColorSpaceSignature Space, 
-                                      cmsUInt16Number **White, 
+cmsBool          _cmsEndPointsBySpace(cmsColorSpaceSignature Space,
+                                      cmsUInt16Number **White,
                                       cmsUInt16Number **Black,
                                       cmsUInt32Number *nOutputs);
 
-cmsBool          _cmsOptimizePipeline(cmsPipeline**    Lut,                                              
+cmsBool          _cmsOptimizePipeline(cmsPipeline**    Lut,
                                       int              Intent,
-                                      cmsUInt32Number* InputFormat, 
+                                      cmsUInt32Number* InputFormat,
                                       cmsUInt32Number* OutputFormat,
                                       cmsUInt32Number* dwFlags );
 
@@ -511,11 +482,11 @@ cmsBool          _cmsOptimizePipeline(cmsPipeline**    Lut,
 // Hi level LUT building ----------------------------------------------------------------------------------------------
 
 cmsPipeline*     _cmsCreateGamutCheckPipeline(cmsContext ContextID,
-                                              cmsHPROFILE hProfiles[], 
-                                              cmsBool  BPC[], 
-                                              cmsUInt32Number Intents[], 
+                                              cmsHPROFILE hProfiles[],
+                                              cmsBool  BPC[],
+                                              cmsUInt32Number Intents[],
                                               cmsFloat64Number AdaptationStates[],
-                                              cmsUInt32Number nGamutPCSposition, 
+                                              cmsUInt32Number nGamutPCSposition,
                                               cmsHPROFILE hGamut);
 
 
@@ -527,10 +498,18 @@ cmsBool         _cmsFormatterIsFloat(cmsUInt32Number Type);
 cmsBool         _cmsFormatterIs8bit(cmsUInt32Number Type);
 
 cmsFormatter    _cmsGetFormatter(cmsUInt32Number Type,          // Specific type, i.e. TYPE_RGB_8
-                                 cmsFormatterDirection Dir, 
+                                 cmsFormatterDirection Dir,
                                  cmsUInt32Number dwFlags);
 
 
+#ifndef CMS_NO_HALF_SUPPORT 
+
+// Half float
+cmsFloat32Number _cmsHalf2Float(cmsUInt16Number h);
+cmsUInt16Number  _cmsFloat2Half(cmsFloat32Number flt);
+
+#endif
+
 // Transform logic ------------------------------------------------------------------------------------------------------
 
 struct _cmstransform_struct;
@@ -544,18 +523,6 @@ typedef struct {
 } _cmsCACHE;
 
 
-// Full xform
-typedef void (* _cmsTransformFn)(struct _cmstransform_struct *Transform,
-                                 const void* InputBuffer,
-                                 void* OutputBuffer, 
-                                 cmsUInt32Number Size);
-
-typedef struct {
-
-    cmsUInt32Number InputFormat, OutputFormat; // Keep formats for further reference
-    cmsUInt32Number StrideIn, StrideOut;       // Planar support
-
-} cmsFormatterInfo;
 
 // Transformation
 typedef struct _cmstransform_struct {
@@ -571,14 +538,14 @@ typedef struct _cmstransform_struct {
 
     cmsFormatterFloat FromInputFloat;
     cmsFormatterFloat ToOutputFloat;
-    
+
     // 1-pixel cache seed for zero as input (16 bits, read only)
     _cmsCACHE Cache;
-    
-    // A MPE LUT holding the full (optimized) transform
+
+    // A Pipeline holding the full (optimized) transform
     cmsPipeline* Lut;
-    
-    // A MPE LUT holding the gamut check. It goes from the input space to bilevel
+
+    // A Pipeline holding the gamut check. It goes from the input space to bilevel
     cmsPipeline* GamutCheck;
 
     // Colorant tables
@@ -588,12 +555,12 @@ typedef struct _cmstransform_struct {
     // Informational only
     cmsColorSpaceSignature EntryColorSpace;
     cmsColorSpaceSignature ExitColorSpace;
-    
+
     // Profiles used to create the transform
     cmsSEQ* Sequence;
 
-    cmsUInt32Number  dwOriginalFlags;      
-    cmsFloat64Number AdaptationState;              
+    cmsUInt32Number  dwOriginalFlags;
+    cmsFloat64Number AdaptationState;
 
     // The intent of this transform. That is usually the last intent in the profilechain, but may differ
     cmsUInt32Number RenderingIntent;
@@ -601,6 +568,10 @@ typedef struct _cmstransform_struct {
     // An id that uniquely identifies the running context. May be null.
     cmsContext ContextID;
 
+    // A user-defined pointer that can be used to store data for transform plug-ins
+    void* UserData;
+    _cmsFreeUserDataFn FreeUserData;
+
 } _cmsTRANSFORM;
 
 // --------------------------------------------------------------------------------------------------
@@ -609,18 +580,18 @@ cmsHTRANSFORM _cmsChain2Lab(cmsContext             ContextID,
                             cmsUInt32Number        nProfiles,
                             cmsUInt32Number        InputFormat,
                             cmsUInt32Number        OutputFormat,
-                            const cmsUInt32Number  Intents[], 
-                            const cmsHPROFILE      hProfiles[], 
+                            const cmsUInt32Number  Intents[],
+                            const cmsHPROFILE      hProfiles[],
                             const cmsBool          BPC[],
                             const cmsFloat64Number AdaptationStates[],
                             cmsUInt32Number        dwFlags);
 
 
-cmsToneCurve* _cmsBuildKToneCurve(cmsContext       ContextID, 
+cmsToneCurve* _cmsBuildKToneCurve(cmsContext       ContextID,
                             cmsUInt32Number        nPoints,
                             cmsUInt32Number        nProfiles,
-                            const cmsUInt32Number  Intents[], 
-                            const cmsHPROFILE      hProfiles[], 
+                            const cmsUInt32Number  Intents[],
+                            const cmsHPROFILE      hProfiles[],
                             const cmsBool          BPC[],
                             const cmsFloat64Number AdaptationStates[],
                             cmsUInt32Number        dwFlags);
index dccb407..7961a42 100644 (file)
@@ -9,7 +9,7 @@ INCLUDES        =  -I$(top_builddir)/include -I$(top_srcdir)/include -I$(top_srcdir)/sr
 
 check_PROGRAMS = testcms
 
-CFLAGS = --pedantic -Wall -std=c99 -O2
+CFLAGS = --pedantic -Wall -std=c99 -O2
 
 testcms_LDADD = $(top_builddir)/src/liblcms2.la 
 testcms_LDFLAGS = @LDFLAGS@
index 89f5c13..db8622c 100644 (file)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.3 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -81,7 +81,7 @@ AUTOMAKE = @AUTOMAKE@
 AWK = @AWK@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
-CFLAGS = --pedantic -Wall -std=c99 -O2
+CFLAGS = @CFLAGS@
 CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
 CXX = @CXX@
@@ -207,6 +207,8 @@ top_srcdir = @top_srcdir@
 # Don't require all the GNU mandated files
 AUTOMAKE_OPTIONS = 1.7 foreign
 INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I$(top_srcdir)/src
+
+# CFLAGS = --pedantic -Wall -std=c99 -O2
 testcms_LDADD = $(top_builddir)/src/liblcms2.la 
 testcms_LDFLAGS = @LDFLAGS@
 testcms_SOURCES = testcms2.c
@@ -257,7 +259,7 @@ clean-checkPROGRAMS:
        list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
        echo " rm -f" $$list; \
        rm -f $$list
-testcms$(EXEEXT): $(testcms_OBJECTS) $(testcms_DEPENDENCIES) 
+testcms$(EXEEXT): $(testcms_OBJECTS) $(testcms_DEPENDENCIES) $(EXTRA_testcms_DEPENDENCIES) 
        @rm -f testcms$(EXEEXT)
        $(testcms_LINK) $(testcms_OBJECTS) $(testcms_LDADD) $(LIBS)
 
@@ -393,10 +395,15 @@ install-am: all-am
 
 installcheck: installcheck-am
 install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-         install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-         `test -z '$(STRIP)' || \
-           echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
 mostlyclean-generic:
 
 clean-generic:
index f070b09..5e0b6b9 100644 (file)
@@ -3,22 +3,22 @@
 //  Little Color Management System
 //  Copyright (c) 1998-2010 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 
+// 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 
+// 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 
+// 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.
 //
 //---------------------------------------------------------------------------------
@@ -72,9 +72,9 @@ static cmsUInt32Number SingleHit, MaxAllocated=0, TotalMemory=0;
 
 // I'm hidding the size before the block. This is a well-known technique and probably the blocks coming from
 // malloc are built in a way similar to that, but I do on my own to be portable.
-typedef struct { 
-    cmsUInt32Number KeepSize;    
-    cmsContext      WhoAllocated; 
+typedef struct {
+    cmsUInt32Number KeepSize;
+    cmsContext      WhoAllocated;
 
     union {
         cmsUInt64Number HiSparc;
@@ -86,12 +86,12 @@ typedef struct {
 
     } alignment;
 
-   
+
 } _cmsMemoryBlock;
 
 #define SIZE_OF_MEM_HEADER (sizeof(_cmsMemoryBlock))
 
-// This is a fake thread descriptor used to check thread integrity. 
+// This is a fake thread descriptor used to check thread integrity.
 // Basically it returns a different threadID each time it is called.
 // Then the memory management replacement functions does check if each
 // free() is being called with same ContextID used on malloc()
@@ -118,7 +118,7 @@ void* DebugMalloc(cmsContext ContextID, cmsUInt32Number size)
     if (TotalMemory > MaxAllocated)
         MaxAllocated = TotalMemory;
 
-    if (size > SingleHit) 
+    if (size > SingleHit)
         SingleHit = size;
 
     blk = (_cmsMemoryBlock*) malloc(size + SIZE_OF_MEM_HEADER);
@@ -135,7 +135,7 @@ static
 void  DebugFree(cmsContext ContextID, void *Ptr)
 {
     _cmsMemoryBlock* blk;
-    
+
     if (Ptr == NULL) {
         Die("NULL free (which is a no-op in C, but may be an clue of something going wrong)");
     }
@@ -165,7 +165,7 @@ void * DebugRealloc(cmsContext ContextID, void* Ptr, cmsUInt32Number NewSize)
     max_sz = blk -> KeepSize > NewSize ? NewSize : blk ->KeepSize;
     memmove(NewPtr, Ptr, max_sz);
     DebugFree(ContextID, Ptr);
-    
+
     return NewPtr;
 }
 
@@ -186,11 +186,15 @@ static cmsPluginMemHandler DebugMemHandler = {{ cmsPluginMagicNumber, 2000, cmsP
 static
 void FatalErrorQuit(cmsContext ContextID, cmsUInt32Number ErrorCode, const char *Text)
 {
-    Die(Text); 
+    Die(Text);
+
+    cmsUNUSED_PARAMETER(ContextID);
+    cmsUNUSED_PARAMETER(ErrorCode);
+
 }
 
 // Print a dot for gauging
-static 
+static
 void Dot(void)
 {
     fprintf(stdout, "."); fflush(stdout);
@@ -263,16 +267,16 @@ void Check(const char* Title, TestFn Fn)
     else {
         printf("FAIL!\n");
 
-        if (SubTestBuffer[0]) 
+        if (SubTestBuffer[0])
             printf("%s: [%s]\n\t%s\n", Title, SubTestBuffer, ReasonToFailBuffer);
         else
             printf("%s:\n\t%s\n", Title, ReasonToFailBuffer);
 
-        if (SimultaneousErrors > 1) 
-               printf("\tMore than one (%d) errors were reported\n", SimultaneousErrors); 
+        if (SimultaneousErrors > 1)
+               printf("\tMore than one (%d) errors were reported\n", SimultaneousErrors);
 
         TotalFail++;
-    }   
+    }
     fflush(stdout);
 }
 
@@ -306,8 +310,8 @@ void DumpToneCurve(cmsToneCurve* gamma, const char* FileName)
 // -------------------------------------------------------------------------------------------------
 
 
-// Used to perform several checks. 
-// The space used is a clone of a well-known commercial 
+// Used to perform several checks.
+// The space used is a clone of a well-known commercial
 // color space which I will name "Above RGB"
 static
 cmsHPROFILE Create_AboveRGB(void)
@@ -318,13 +322,13 @@ cmsHPROFILE Create_AboveRGB(void)
     cmsCIExyYTRIPLE Primaries = {{0.64, 0.33, 1 },
                                  {0.21, 0.71, 1 },
                                  {0.15, 0.06, 1 }};
-    
+
     Curve[0] = Curve[1] = Curve[2] = cmsBuildGamma(DbgThread(), 2.19921875);
 
     cmsWhitePointFromTemp(&D65, 6504);
     hProfile = cmsCreateRGBProfileTHR(DbgThread(), &D65, &Primaries, Curve);
     cmsFreeToneCurve(Curve[0]);
-    
+
     return hProfile;
 }
 
@@ -342,6 +346,20 @@ cmsHPROFILE Create_Gray22(void)
     return hProfile;
 }
 
+// A gamma-3.0 gray space
+static
+cmsHPROFILE Create_Gray30(void)
+{
+    cmsHPROFILE hProfile;
+    cmsToneCurve* Curve = cmsBuildGamma(DbgThread(), 3.0);
+    if (Curve == NULL) return NULL;
+
+    hProfile = cmsCreateGrayProfileTHR(DbgThread(), cmsD50_xyY(), Curve);
+    cmsFreeToneCurve(Curve);
+
+    return hProfile;
+}
+
 
 static
 cmsHPROFILE Create_GrayLab(void)
@@ -369,7 +387,7 @@ cmsHPROFILE Create_CMYK_DeviceLink(void)
     Tab[0] = Curve;
     Tab[1] = Curve;
     Tab[2] = Curve;
-    Tab[3] = Curve;   
+    Tab[3] = Curve;
 
     hProfile = cmsCreateLinearizationDeviceLinkTHR(DbgThread(), cmsSigCmykData, Tab);
     if (hProfile == NULL) return NULL;
@@ -380,7 +398,7 @@ cmsHPROFILE Create_CMYK_DeviceLink(void)
 }
 
 
-// Create a fake CMYK profile, without any other requeriment that being coarse CMYK. 
+// Create a fake CMYK profile, without any other requeriment that being coarse CMYK.
 // DONT USE THIS PROFILE FOR ANYTHING, IT IS USELESS BUT FOR TESTING PURPOSES.
 typedef struct {
 
@@ -403,18 +421,18 @@ static
 cmsInt32Number ForwardSampler(register const cmsUInt16Number In[], cmsUInt16Number Out[], void* Cargo)
 {
     FakeCMYKParams* p = (FakeCMYKParams*) Cargo;
-    cmsFloat64Number rgb[3], cmyk[4];   
+    cmsFloat64Number rgb[3], cmyk[4];
     cmsFloat64Number c, m, y, k;
 
     cmsDoTransform(p ->hLab2sRGB, In, rgb, 1);
-         
+
     c = 1 - rgb[0];
     m = 1 - rgb[1];
     y = 1 - rgb[2];
 
     k = (c < m ? cmsmin(c, y) : cmsmin(m, y));
-   
-    // NONSENSE WARNING!: I'm doing this just because this is a test 
+
+    // NONSENSE WARNING!: I'm doing this just because this is a test
     // profile that may have ink limit up to 400%. There is no UCR here
     // so the profile is basically useless for anything but testing.
 
@@ -433,7 +451,7 @@ static
 cmsInt32Number ReverseSampler(register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void* Cargo)
 {
     FakeCMYKParams* p = (FakeCMYKParams*) Cargo;
-    cmsFloat64Number c, m, y, k, rgb[3];    
+    cmsFloat64Number c, m, y, k, rgb[3];
 
     c = In[0] / 65535.0;
     m = In[1] / 65535.0;
@@ -445,18 +463,18 @@ cmsInt32Number ReverseSampler(register const cmsUInt16Number In[], register cmsU
         rgb[0] = Clip(1 - c);
         rgb[1] = Clip(1 - m);
         rgb[2] = Clip(1 - y);
-    } 
-    else 
+    }
+    else
         if (k == 1) {
 
             rgb[0] = rgb[1] = rgb[2] = 0;
-        } 
+        }
         else {
 
             rgb[0] = Clip((1 - c) * (1 - k));
             rgb[1] = Clip((1 - m) * (1 - k));
-            rgb[2] = Clip((1 - y) * (1 - k));       
-        }   
+            rgb[2] = Clip((1 - y) * (1 - k));
+        }
 
         cmsDoTransform(p ->sRGB2Lab, rgb, Out, 1);
         return 1;
@@ -506,24 +524,24 @@ cmsHPROFILE CreateFakeCMYK(cmsFloat64Number InkLimit, cmsBool lUseAboveRGB)
     CLUT = cmsStageAllocCLut16bit(ContextID, 17, 3, 4, NULL);
     if (CLUT == NULL) return 0;
     if (!cmsStageSampleCLut16bit(CLUT, ForwardSampler, &p, 0)) return 0;
-    
-    cmsPipelineInsertStage(BToA0, cmsAT_BEGIN, _cmsStageAllocIdentityCurves(ContextID, 3)); 
+
+    cmsPipelineInsertStage(BToA0, cmsAT_BEGIN, _cmsStageAllocIdentityCurves(ContextID, 3));
     cmsPipelineInsertStage(BToA0, cmsAT_END, CLUT);
     cmsPipelineInsertStage(BToA0, cmsAT_END, _cmsStageAllocIdentityCurves(ContextID, 4));
-    
+
     if (!cmsWriteTag(hICC, cmsSigBToA0Tag, (void*) BToA0)) return 0;
     cmsPipelineFree(BToA0);
-    
+
     AToB0 = cmsPipelineAlloc(ContextID, 4, 3);
     if (AToB0 == NULL) return 0;
     CLUT = cmsStageAllocCLut16bit(ContextID, 17, 4, 3, NULL);
     if (CLUT == NULL) return 0;
     if (!cmsStageSampleCLut16bit(CLUT, ReverseSampler, &p, 0)) return 0;
 
-    cmsPipelineInsertStage(AToB0, cmsAT_BEGIN, _cmsStageAllocIdentityCurves(ContextID, 4)); 
+    cmsPipelineInsertStage(AToB0, cmsAT_BEGIN, _cmsStageAllocIdentityCurves(ContextID, 4));
     cmsPipelineInsertStage(AToB0, cmsAT_END, CLUT);
     cmsPipelineInsertStage(AToB0, cmsAT_END, _cmsStageAllocIdentityCurves(ContextID, 3));
-    
+
     if (!cmsWriteTag(hICC, cmsSigAToB0Tag, (void*) AToB0)) return 0;
     cmsPipelineFree(AToB0);
 
@@ -536,7 +554,7 @@ cmsHPROFILE CreateFakeCMYK(cmsFloat64Number InkLimit, cmsBool lUseAboveRGB)
     cmsLinkTag(hICC, cmsSigBToA1Tag, cmsSigBToA0Tag);
     cmsLinkTag(hICC, cmsSigBToA2Tag, cmsSigBToA0Tag);
 
-    return hICC;    
+    return hICC;
 }
 
 
@@ -563,7 +581,7 @@ cmsInt32Number OneVirtual(cmsHPROFILE h, const char* SubTestTxt, const char* Fil
 
 
 
-// This test checks the ability of lcms2 to save its built-ins as valid profiles. 
+// This test checks the ability of lcms2 to save its built-ins as valid profiles.
 // It does not check the functionality of such profiles
 static
 cmsInt32Number CreateTestProfiles(void)
@@ -579,15 +597,20 @@ cmsInt32Number CreateTestProfiles(void)
     if (!OneVirtual(h, "aRGB profile", "aRGBlcms2.icc")) return 0;
 
     // ----
-    
+
     h = Create_Gray22();
     if (!OneVirtual(h, "Gray profile", "graylcms2.icc")) return 0;
 
     // ----
 
+    h = Create_Gray30();
+    if (!OneVirtual(h, "Gray 3.0 profile", "gray3lcms2.icc")) return 0;
+
+    // ----
+
     h = Create_GrayLab();
     if (!OneVirtual(h, "Gray Lab profile", "glablcms2.icc")) return 0;
-    
+
     // ----
 
     h = Create_CMYK_DeviceLink();
@@ -637,6 +660,7 @@ void RemoveTestProfiles(void)
     remove("sRGBlcms2.icc");
     remove("aRGBlcms2.icc");
     remove("graylcms2.icc");
+    remove("gray3lcms2.icc");
     remove("linlcms2.icc");
     remove("limitlcms2.icc");
     remove("labv2lcms2.icc");
@@ -646,6 +670,8 @@ void RemoveTestProfiles(void)
     remove("bchslcms2.icc");
     remove("lcms2cmyk.icc");
     remove("glablcms2.icc");
+    remove("lcms2link.icc");
+    remove("lcms2link2.icc");
 }
 
 // -------------------------------------------------------------------------------------------------
@@ -654,6 +680,11 @@ void RemoveTestProfiles(void)
 static
 cmsInt32Number CheckBaseTypes(void)
 {
+    // Ignore warnings about conditional expression
+#ifdef _MSC_VER
+#pragma warning(disable: 4127)
+#endif
+
     if (sizeof(cmsUInt8Number) != 1) return 0;
     if (sizeof(cmsInt8Number) != 1) return 0;
     if (sizeof(cmsUInt16Number) != 2) return 0;
@@ -668,18 +699,18 @@ cmsInt32Number CheckBaseTypes(void)
     if (sizeof(cmsU8Fixed8Number) != 2) return 0;
     if (sizeof(cmsS15Fixed16Number) != 4) return 0;
     if (sizeof(cmsU16Fixed16Number) != 4) return 0;
-    
+
     return 1;
 }
 
 // -------------------------------------------------------------------------------------------------
 
 
-// Are we little or big endian?  From Harbison&Steele.  
+// Are we little or big endian?  From Harbison&Steele.
 static
 cmsInt32Number CheckEndianess(void)
 {
-    cmsInt32Number BigEndian, IsOk;   
+    cmsInt32Number BigEndian, IsOk;
     union {
         long l;
         char c[sizeof (long)];
@@ -742,9 +773,9 @@ cmsInt32Number CheckQuickFloorWord(void)
 
 // -------------------------------------------------------------------------------------------------
 
-// Precision stuff. 
+// Precision stuff.
 
-// On 15.16 fixed point, this is the maximum we can obtain. Remember ICC profiles have storage limits on this number 
+// On 15.16 fixed point, this is the maximum we can obtain. Remember ICC profiles have storage limits on this number
 #define FIXED_PRECISION_15_16 (1.0 / 65535.0)
 
 // On 8.8 fixed point, that is the max we can obtain.
@@ -774,7 +805,7 @@ cmsBool IsGoodVal(const char *title, cmsFloat64Number in, cmsFloat64Number out,
 
 static
 cmsBool  IsGoodFixed15_16(const char *title, cmsFloat64Number in, cmsFloat64Number out)
-{   
+{
     return IsGoodVal(title, in, out, FIXED_PRECISION_15_16);
 }
 
@@ -884,7 +915,7 @@ void BuildTable(cmsInt32Number n, cmsUInt16Number Tab[], cmsBool  Descending)
 // nNodesToCheck = number on nodes to check
 // Down = Create decreasing tables
 // Reverse = Check reverse interpolation
-// max_err = max allowed error 
+// max_err = max allowed error
 
 static
 cmsInt32Number Check1D(cmsInt32Number nNodesToCheck, cmsBool  Down, cmsInt32Number max_err)
@@ -936,7 +967,7 @@ cmsInt32Number Check1DLERP2(void)
 static
 cmsInt32Number Check1DLERP3(void)
 {
-    return Check1D(3, FALSE, 1);    
+    return Check1D(3, FALSE, 1);
 }
 
 
@@ -988,13 +1019,13 @@ static
 cmsInt32Number ExhaustiveCheck1DLERP(void)
 {
     cmsUInt32Number j;
-    
+
     printf("\n");
     for (j=10; j <= 4096; j++) {
 
         if ((j % 10) == 0) printf("%d    \r", j);
 
-        if (!Check1D(j, FALSE, 1)) return 0;    
+        if (!Check1D(j, FALSE, 1)) return 0;
     }
 
     printf("\rResult is ");
@@ -1005,13 +1036,13 @@ static
 cmsInt32Number ExhaustiveCheck1DLERPDown(void)
 {
     cmsUInt32Number j;
-    
+
     printf("\n");
     for (j=10; j <= 4096; j++) {
 
         if ((j % 10) == 0) printf("%d    \r", j);
 
-        if (!Check1D(j, TRUE, 1)) return 0; 
+        if (!Check1D(j, TRUE, 1)) return 0;
     }
 
 
@@ -1121,19 +1152,19 @@ cmsInt32Number Check3DinterpolationTetrahedral16(void)
     cmsInterpParams* p;
     cmsInt32Number i;
     cmsUInt16Number In[3], Out[3];
-    cmsUInt16Number Table[] = { 
+    cmsUInt16Number Table[] = {
 
-        0,    0,   0,     
-        0,    0,   0xffff,    
+        0,    0,   0,
+        0,    0,   0xffff,
 
-        0,    0xffff,    0,   
-        0,    0xffff,    0xffff,  
+        0,    0xffff,    0,
+        0,    0xffff,    0xffff,
 
-        0xffff,    0,    0,    
-        0xffff,    0,    0xffff,   
+        0xffff,    0,    0,
+        0xffff,    0,    0xffff,
 
-        0xffff,    0xffff,   0,    
-        0xffff,    0xffff,   0xffff    
+        0xffff,    0xffff,   0,
+        0xffff,    0xffff,   0xffff
     };
 
     p = _cmsComputeInterpParams(DbgThread(), 2, 3, 3, Table, CMS_LERP_FLAGS_16BITS);
@@ -1165,19 +1196,19 @@ cmsInt32Number Check3DinterpolationTrilinear16(void)
     cmsInterpParams* p;
     cmsInt32Number i;
     cmsUInt16Number In[3], Out[3];
-    cmsUInt16Number Table[] = { 
+    cmsUInt16Number Table[] = {
 
-        0,    0,   0,     
-        0,    0,   0xffff,    
+        0,    0,   0,
+        0,    0,   0xffff,
 
-        0,    0xffff,    0,   
-        0,    0xffff,    0xffff,  
+        0,    0xffff,    0,
+        0,    0xffff,    0xffff,
 
-        0xffff,    0,    0,    
-        0xffff,    0,    0xffff,   
+        0xffff,    0,    0,
+        0xffff,    0,    0xffff,
 
-        0xffff,    0xffff,   0,    
-        0xffff,    0xffff,   0xffff    
+        0xffff,    0xffff,   0,
+        0xffff,    0xffff,   0xffff
     };
 
     p = _cmsComputeInterpParams(DbgThread(), 2, 3, 3, Table, CMS_LERP_FLAGS_TRILINEAR);
@@ -1229,16 +1260,16 @@ cmsInt32Number ExaustiveCheck3DinterpolationFloatTetrahedral(void)
     p = _cmsComputeInterpParams(DbgThread(), 2, 3, 3, FloatTable, CMS_LERP_FLAGS_FLOAT);
 
     MaxErr = 0.0;
-    for (r=0; r < 0xff; r++) 
-        for (g=0; g < 0xff; g++) 
-            for (b=0; b < 0xff; b++) 
+    for (r=0; r < 0xff; r++)
+        for (g=0; g < 0xff; g++)
+            for (b=0; b < 0xff; b++)
         {
 
             In[0] = (cmsFloat32Number) r / 255.0F;
             In[1] = (cmsFloat32Number) g / 255.0F;
             In[2] = (cmsFloat32Number) b / 255.0F;
 
-       
+
         p ->Interpolation.LerpFloat(In, Out, p);
 
        if (!IsGoodFixed15_16("Channel 1", Out[0], In[0])) goto Error;
@@ -1280,9 +1311,9 @@ cmsInt32Number ExaustiveCheck3DinterpolationFloatTrilinear(void)
     p = _cmsComputeInterpParams(DbgThread(), 2, 3, 3, FloatTable, CMS_LERP_FLAGS_FLOAT|CMS_LERP_FLAGS_TRILINEAR);
 
     MaxErr = 0.0;
-    for (r=0; r < 0xff; r++) 
-        for (g=0; g < 0xff; g++) 
-            for (b=0; b < 0xff; b++) 
+    for (r=0; r < 0xff; r++)
+        for (g=0; g < 0xff; g++)
+            for (b=0; b < 0xff; b++)
             {
 
                 In[0] = (cmsFloat32Number) r / 255.0F;
@@ -1313,26 +1344,26 @@ cmsInt32Number ExhaustiveCheck3DinterpolationTetrahedral16(void)
     cmsInterpParams* p;
     cmsInt32Number r, g, b;
     cmsUInt16Number In[3], Out[3];
-    cmsUInt16Number Table[] = { 
+    cmsUInt16Number Table[] = {
 
-        0,    0,   0,     
-        0,    0,   0xffff,    
+        0,    0,   0,
+        0,    0,   0xffff,
 
-        0,    0xffff,    0,   
-        0,    0xffff,    0xffff,  
+        0,    0xffff,    0,
+        0,    0xffff,    0xffff,
 
-        0xffff,    0,    0,    
-        0xffff,    0,    0xffff,   
+        0xffff,    0,    0,
+        0xffff,    0,    0xffff,
 
-        0xffff,    0xffff,   0,    
-        0xffff,    0xffff,   0xffff    
+        0xffff,    0xffff,   0,
+        0xffff,    0xffff,   0xffff
     };
 
     p = _cmsComputeInterpParams(DbgThread(), 2, 3, 3, Table, CMS_LERP_FLAGS_16BITS);
 
-    for (r=0; r < 0xff; r++) 
-        for (g=0; g < 0xff; g++) 
-            for (b=0; b < 0xff; b++) 
+    for (r=0; r < 0xff; r++)
+        for (g=0; g < 0xff; g++)
+            for (b=0; b < 0xff; b++)
         {
             In[0] = (cmsUInt16Number) r ;
             In[1] = (cmsUInt16Number) g ;
@@ -1345,7 +1376,7 @@ cmsInt32Number ExhaustiveCheck3DinterpolationTetrahedral16(void)
        if (!IsGoodWord("Channel 2", Out[1], In[1])) goto Error;
        if (!IsGoodWord("Channel 3", Out[2], In[2])) goto Error;
      }
-    
+
     _cmsFreeInterpParams(p);
     return 1;
 
@@ -1360,26 +1391,26 @@ cmsInt32Number ExhaustiveCheck3DinterpolationTrilinear16(void)
     cmsInterpParams* p;
     cmsInt32Number r, g, b;
     cmsUInt16Number In[3], Out[3];
-    cmsUInt16Number Table[] = { 
+    cmsUInt16Number Table[] = {
 
-        0,    0,   0,     
-        0,    0,   0xffff,    
+        0,    0,   0,
+        0,    0,   0xffff,
 
-        0,    0xffff,    0,   
-        0,    0xffff,    0xffff,  
+        0,    0xffff,    0,
+        0,    0xffff,    0xffff,
 
-        0xffff,    0,    0,    
-        0xffff,    0,    0xffff,   
+        0xffff,    0,    0,
+        0xffff,    0,    0xffff,
 
-        0xffff,    0xffff,   0,    
-        0xffff,    0xffff,   0xffff    
+        0xffff,    0xffff,   0,
+        0xffff,    0xffff,   0xffff
     };
 
     p = _cmsComputeInterpParams(DbgThread(), 2, 3, 3, Table, CMS_LERP_FLAGS_TRILINEAR);
 
-    for (r=0; r < 0xff; r++) 
-        for (g=0; g < 0xff; g++) 
-            for (b=0; b < 0xff; b++) 
+    for (r=0; r < 0xff; r++)
+        for (g=0; g < 0xff; g++)
+            for (b=0; b < 0xff; b++)
         {
             In[0] = (cmsUInt16Number) r ;
             In[1] = (cmsUInt16Number)g ;
@@ -1393,7 +1424,7 @@ cmsInt32Number ExhaustiveCheck3DinterpolationTrilinear16(void)
        if (!IsGoodWord("Channel 3", Out[2], In[2])) goto Error;
      }
 
-    
+
     _cmsFreeInterpParams(p);
     return 1;
 
@@ -1411,29 +1442,29 @@ cmsInt32Number CheckReverseInterpolation3x3(void)
  cmsFloat32Number Target[3], Result[3], Hint[3];
  cmsFloat32Number err, max;
  cmsInt32Number i;
- cmsUInt16Number Table[] = { 
+ cmsUInt16Number Table[] = {
 
-        0,    0,   0,                 // 0 0 0  
-        0,    0,   0xffff,            // 0 0 1  
+        0,    0,   0,                 // 0 0 0
+        0,    0,   0xffff,            // 0 0 1
 
-        0,    0xffff,    0,           // 0 1 0  
-        0,    0xffff,    0xffff,      // 0 1 1  
+        0,    0xffff,    0,           // 0 1 0
+        0,    0xffff,    0xffff,      // 0 1 1
 
-        0xffff,    0,    0,           // 1 0 0  
-        0xffff,    0,    0xffff,      // 1 0 1  
+        0xffff,    0,    0,           // 1 0 0
+        0xffff,    0,    0xffff,      // 1 0 1
 
-        0xffff,    0xffff,   0,       // 1 1 0  
-        0xffff,    0xffff,   0xffff,  // 1 1 1  
+        0xffff,    0xffff,   0,       // 1 1 0
+        0xffff,    0xffff,   0xffff,  // 1 1 1
     };
 
-  
+
 
    Lut = cmsPipelineAlloc(DbgThread(), 3, 3);
 
    clut = cmsStageAllocCLut16bit(DbgThread(), 2, 3, 3, Table);
    cmsPipelineInsertStage(Lut, cmsAT_BEGIN, clut);
-   Target[0] = 0; Target[1] = 0; Target[2] = 0; 
+
+   Target[0] = 0; Target[1] = 0; Target[2] = 0;
    Hint[0] = 0; Hint[1] = 0; Hint[2] = 0;
    cmsPipelineEvalReverseFloat(Target, Result, NULL, Lut);
    if (Result[0] != 0 || Result[1] != 0 || Result[2] != 0){
@@ -1448,7 +1479,7 @@ cmsInt32Number CheckReverseInterpolation3x3(void)
 
        cmsFloat32Number in = i / 100.0F;
 
-       Target[0] = in; Target[1] = 0; Target[2] = 0; 
+       Target[0] = in; Target[1] = 0; Target[2] = 0;
        cmsPipelineEvalReverseFloat(Target, Result, Hint, Lut);
 
        err = fabsf(in - Result[0]);
@@ -1472,39 +1503,39 @@ cmsInt32Number CheckReverseInterpolation4x3(void)
  cmsInt32Number i;
 
  // 4 -> 3, output gets 3 first channels copied
- cmsUInt16Number Table[] = { 
+ cmsUInt16Number Table[] = {
 
         0,         0,         0,          //  0 0 0 0   = ( 0, 0, 0)
         0,         0,         0,          //  0 0 0 1   = ( 0, 0, 0)
-                                        
+
         0,         0,         0xffff,     //  0 0 1 0   = ( 0, 0, 1)
         0,         0,         0xffff,     //  0 0 1 1   = ( 0, 0, 1)
-                                            
+
         0,         0xffff,    0,          //  0 1 0 0   = ( 0, 1, 0)
         0,         0xffff,    0,          //  0 1 0 1   = ( 0, 1, 0)
-                                            
+
         0,         0xffff,    0xffff,     //  0 1 1 0    = ( 0, 1, 1)
         0,         0xffff,    0xffff,     //  0 1 1 1    = ( 0, 1, 1)
 
         0xffff,    0,         0,          //  1 0 0 0    = ( 1, 0, 0)
         0xffff,    0,         0,          //  1 0 0 1    = ( 1, 0, 0)
-                                            
+
         0xffff,    0,         0xffff,     //  1 0 1 0    = ( 1, 0, 1)
         0xffff,    0,         0xffff,     //  1 0 1 1    = ( 1, 0, 1)
-                                            
+
         0xffff,    0xffff,    0,          //  1 1 0 0    = ( 1, 1, 0)
         0xffff,    0xffff,    0,          //  1 1 0 1    = ( 1, 1, 0)
-                                            
+
         0xffff,    0xffff,    0xffff,     //  1 1 1 0    = ( 1, 1, 1)
         0xffff,    0xffff,    0xffff,     //  1 1 1 1    = ( 1, 1, 1)
     };
 
-   
+
    Lut = cmsPipelineAlloc(DbgThread(), 4, 3);
 
    clut = cmsStageAllocCLut16bit(DbgThread(), 2, 4, 3, Table);
    cmsPipelineInsertStage(Lut, cmsAT_BEGIN, clut);
+
    // Check if the LUT is behaving as expected
    SubTest("4->3 feasibility");
    for (i=0; i <= 100; i++) {
@@ -1522,12 +1553,12 @@ cmsInt32Number CheckReverseInterpolation4x3(void)
    }
 
    SubTest("4->3 zero");
-   Target[0] = 0; 
-   Target[1] = 0; 
-   Target[2] = 0; 
+   Target[0] = 0;
+   Target[1] = 0;
+   Target[2] = 0;
 
    // This one holds the fixed K
-   Target[3] = 0; 
+   Target[3] = 0;
 
    // This is our hint (which is a big lie in this case)
    Hint[0] = 0.1F; Hint[1] = 0.1F; Hint[2] = 0.1F;
@@ -1546,7 +1577,7 @@ cmsInt32Number CheckReverseInterpolation4x3(void)
 
        cmsFloat32Number in = i / 100.0F;
 
-       Target[0] = in; Target[1] = 0; Target[2] = 0; 
+       Target[0] = in; Target[1] = 0; Target[2] = 0;
        cmsPipelineEvalReverseFloat(Target, Result, Hint, Lut);
 
        err = fabsf(in - Result[0]);
@@ -1561,7 +1592,7 @@ cmsInt32Number CheckReverseInterpolation4x3(void)
 
 
 
-// Check all interpolation. 
+// Check all interpolation.
 
 static
 cmsUInt16Number Fn8D1(cmsUInt16Number a1, cmsUInt16Number a2, cmsUInt16Number a3, cmsUInt16Number a4,
@@ -1603,6 +1634,9 @@ cmsInt32Number Sampler3D(register const cmsUInt16Number In[],
     Out[2] = Fn8D3(In[0], In[1], In[2], 0, 0, 0, 0, 0, 3);
 
     return 1;
+
+    cmsUNUSED_PARAMETER(Cargo);
+
 }
 
 static
@@ -1616,6 +1650,8 @@ cmsInt32Number Sampler4D(register const cmsUInt16Number In[],
     Out[2] = Fn8D3(In[0], In[1], In[2], In[3], 0, 0, 0, 0, 4);
 
     return 1;
+
+    cmsUNUSED_PARAMETER(Cargo);
 }
 
 static
@@ -1629,6 +1665,8 @@ cmsInt32Number Sampler5D(register const cmsUInt16Number In[],
     Out[2] = Fn8D3(In[0], In[1], In[2], In[3], In[4], 0, 0, 0, 5);
 
     return 1;
+
+    cmsUNUSED_PARAMETER(Cargo);
 }
 
 static
@@ -1642,6 +1680,8 @@ cmsInt32Number Sampler6D(register const cmsUInt16Number In[],
     Out[2] = Fn8D3(In[0], In[1], In[2], In[3], In[4], In[5], 0, 0, 6);
 
     return 1;
+
+    cmsUNUSED_PARAMETER(Cargo);
 }
 
 static
@@ -1655,6 +1695,8 @@ cmsInt32Number Sampler7D(register const cmsUInt16Number In[],
     Out[2] = Fn8D3(In[0], In[1], In[2], In[3], In[4], In[5], In[6], 0, 7);
 
     return 1;
+
+    cmsUNUSED_PARAMETER(Cargo);
 }
 
 static
@@ -1668,14 +1710,16 @@ cmsInt32Number Sampler8D(register const cmsUInt16Number In[],
     Out[2] = Fn8D3(In[0], In[1], In[2], In[3], In[4], In[5], In[6], In[7], 8);
 
     return 1;
+
+    cmsUNUSED_PARAMETER(Cargo);
 }
 
-static 
+static
 cmsBool CheckOne3D(cmsPipeline* lut, cmsUInt16Number a1, cmsUInt16Number a2, cmsUInt16Number a3)
 {
     cmsUInt16Number In[3], Out1[3], Out2[3];
 
-    In[0] = a1; In[1] = a2; In[2] = a3; 
+    In[0] = a1; In[1] = a2; In[2] = a3;
 
     // This is the interpolated value
     cmsPipelineEval16(In, Out1, lut);
@@ -1692,7 +1736,7 @@ cmsBool CheckOne3D(cmsPipeline* lut, cmsUInt16Number a1, cmsUInt16Number a2, cms
     return TRUE;
 }
 
-static 
+static
 cmsBool CheckOne4D(cmsPipeline* lut, cmsUInt16Number a1, cmsUInt16Number a2, cmsUInt16Number a3, cmsUInt16Number a4)
 {
     cmsUInt16Number In[4], Out1[3], Out2[3];
@@ -1714,8 +1758,8 @@ cmsBool CheckOne4D(cmsPipeline* lut, cmsUInt16Number a1, cmsUInt16Number a2, cms
     return TRUE;
 }
 
-static 
-cmsBool CheckOne5D(cmsPipeline* lut, cmsUInt16Number a1, cmsUInt16Number a2, 
+static
+cmsBool CheckOne5D(cmsPipeline* lut, cmsUInt16Number a1, cmsUInt16Number a2,
                                      cmsUInt16Number a3, cmsUInt16Number a4, cmsUInt16Number a5)
 {
     cmsUInt16Number In[5], Out1[3], Out2[3];
@@ -1737,9 +1781,9 @@ cmsBool CheckOne5D(cmsPipeline* lut, cmsUInt16Number a1, cmsUInt16Number a2,
     return TRUE;
 }
 
-static 
-cmsBool CheckOne6D(cmsPipeline* lut, cmsUInt16Number a1, cmsUInt16Number a2, 
-                                     cmsUInt16Number a3, cmsUInt16Number a4, 
+static
+cmsBool CheckOne6D(cmsPipeline* lut, cmsUInt16Number a1, cmsUInt16Number a2,
+                                     cmsUInt16Number a3, cmsUInt16Number a4,
                                      cmsUInt16Number a5, cmsUInt16Number a6)
 {
     cmsUInt16Number In[6], Out1[3], Out2[3];
@@ -1762,9 +1806,9 @@ cmsBool CheckOne6D(cmsPipeline* lut, cmsUInt16Number a1, cmsUInt16Number a2,
 }
 
 
-static 
-cmsBool CheckOne7D(cmsPipeline* lut, cmsUInt16Number a1, cmsUInt16Number a2, 
-                                     cmsUInt16Number a3, cmsUInt16Number a4, 
+static
+cmsBool CheckOne7D(cmsPipeline* lut, cmsUInt16Number a1, cmsUInt16Number a2,
+                                     cmsUInt16Number a3, cmsUInt16Number a4,
                                      cmsUInt16Number a5, cmsUInt16Number a6,
                                      cmsUInt16Number a7)
 {
@@ -1788,9 +1832,9 @@ cmsBool CheckOne7D(cmsPipeline* lut, cmsUInt16Number a1, cmsUInt16Number a2,
 }
 
 
-static 
-cmsBool CheckOne8D(cmsPipeline* lut, cmsUInt16Number a1, cmsUInt16Number a2, 
-                                     cmsUInt16Number a3, cmsUInt16Number a4, 
+static
+cmsBool CheckOne8D(cmsPipeline* lut, cmsUInt16Number a1, cmsUInt16Number a2,
+                                     cmsUInt16Number a3, cmsUInt16Number a4,
                                      cmsUInt16Number a5, cmsUInt16Number a6,
                                      cmsUInt16Number a7, cmsUInt16Number a8)
 {
@@ -1828,14 +1872,14 @@ cmsInt32Number Check3Dinterp(void)
     // Check accuracy
 
     if (!CheckOne3D(lut, 0, 0, 0)) return 0;
-    if (!CheckOne3D(lut, 0xffff, 0xffff, 0xffff)) return 0; 
+    if (!CheckOne3D(lut, 0xffff, 0xffff, 0xffff)) return 0;
 
     if (!CheckOne3D(lut, 0x8080, 0x8080, 0x8080)) return 0;
     if (!CheckOne3D(lut, 0x0000, 0xFE00, 0x80FF)) return 0;
     if (!CheckOne3D(lut, 0x1111, 0x2222, 0x3333)) return 0;
-    if (!CheckOne3D(lut, 0x0000, 0x0012, 0x0013)) return 0; 
-    if (!CheckOne3D(lut, 0x3141, 0x1415, 0x1592)) return 0; 
-    if (!CheckOne3D(lut, 0xFF00, 0xFF01, 0xFF12)) return 0; 
+    if (!CheckOne3D(lut, 0x0000, 0x0012, 0x0013)) return 0;
+    if (!CheckOne3D(lut, 0x3141, 0x1415, 0x1592)) return 0;
+    if (!CheckOne3D(lut, 0xFF00, 0xFF01, 0xFF12)) return 0;
 
     cmsPipelineFree(lut);
 
@@ -1857,14 +1901,14 @@ cmsInt32Number Check3DinterpGranular(void)
     // Check accuracy
 
     if (!CheckOne3D(lut, 0, 0, 0)) return 0;
-    if (!CheckOne3D(lut, 0xffff, 0xffff, 0xffff)) return 0; 
+    if (!CheckOne3D(lut, 0xffff, 0xffff, 0xffff)) return 0;
 
     if (!CheckOne3D(lut, 0x8080, 0x8080, 0x8080)) return 0;
     if (!CheckOne3D(lut, 0x0000, 0xFE00, 0x80FF)) return 0;
     if (!CheckOne3D(lut, 0x1111, 0x2222, 0x3333)) return 0;
-    if (!CheckOne3D(lut, 0x0000, 0x0012, 0x0013)) return 0; 
-    if (!CheckOne3D(lut, 0x3141, 0x1415, 0x1592)) return 0; 
-    if (!CheckOne3D(lut, 0xFF00, 0xFF01, 0xFF12)) return 0; 
+    if (!CheckOne3D(lut, 0x0000, 0x0012, 0x0013)) return 0;
+    if (!CheckOne3D(lut, 0x3141, 0x1415, 0x1592)) return 0;
+    if (!CheckOne3D(lut, 0xFF00, 0xFF01, 0xFF12)) return 0;
 
     cmsPipelineFree(lut);
 
@@ -1886,14 +1930,14 @@ cmsInt32Number Check4Dinterp(void)
     // Check accuracy
 
     if (!CheckOne4D(lut, 0, 0, 0, 0)) return 0;
-    if (!CheckOne4D(lut, 0xffff, 0xffff, 0xffff, 0xffff)) return 0; 
+    if (!CheckOne4D(lut, 0xffff, 0xffff, 0xffff, 0xffff)) return 0;
 
     if (!CheckOne4D(lut, 0x8080, 0x8080, 0x8080, 0x8080)) return 0;
     if (!CheckOne4D(lut, 0x0000, 0xFE00, 0x80FF, 0x8888)) return 0;
     if (!CheckOne4D(lut, 0x1111, 0x2222, 0x3333, 0x4444)) return 0;
-    if (!CheckOne4D(lut, 0x0000, 0x0012, 0x0013, 0x0014)) return 0; 
-    if (!CheckOne4D(lut, 0x3141, 0x1415, 0x1592, 0x9261)) return 0; 
-    if (!CheckOne4D(lut, 0xFF00, 0xFF01, 0xFF12, 0xFF13)) return 0; 
+    if (!CheckOne4D(lut, 0x0000, 0x0012, 0x0013, 0x0014)) return 0;
+    if (!CheckOne4D(lut, 0x3141, 0x1415, 0x1592, 0x9261)) return 0;
+    if (!CheckOne4D(lut, 0xFF00, 0xFF01, 0xFF12, 0xFF13)) return 0;
 
     cmsPipelineFree(lut);
 
@@ -1917,14 +1961,14 @@ cmsInt32Number Check4DinterpGranular(void)
     // Check accuracy
 
     if (!CheckOne4D(lut, 0, 0, 0, 0)) return 0;
-    if (!CheckOne4D(lut, 0xffff, 0xffff, 0xffff, 0xffff)) return 0; 
+    if (!CheckOne4D(lut, 0xffff, 0xffff, 0xffff, 0xffff)) return 0;
 
     if (!CheckOne4D(lut, 0x8080, 0x8080, 0x8080, 0x8080)) return 0;
     if (!CheckOne4D(lut, 0x0000, 0xFE00, 0x80FF, 0x8888)) return 0;
     if (!CheckOne4D(lut, 0x1111, 0x2222, 0x3333, 0x4444)) return 0;
-    if (!CheckOne4D(lut, 0x0000, 0x0012, 0x0013, 0x0014)) return 0; 
-    if (!CheckOne4D(lut, 0x3141, 0x1415, 0x1592, 0x9261)) return 0; 
-    if (!CheckOne4D(lut, 0xFF00, 0xFF01, 0xFF12, 0xFF13)) return 0; 
+    if (!CheckOne4D(lut, 0x0000, 0x0012, 0x0013, 0x0014)) return 0;
+    if (!CheckOne4D(lut, 0x3141, 0x1415, 0x1592, 0x9261)) return 0;
+    if (!CheckOne4D(lut, 0xFF00, 0xFF01, 0xFF12, 0xFF13)) return 0;
 
     cmsPipelineFree(lut);
 
@@ -1947,14 +1991,14 @@ cmsInt32Number Check5DinterpGranular(void)
     // Check accuracy
 
     if (!CheckOne5D(lut, 0, 0, 0, 0, 0)) return 0;
-    if (!CheckOne5D(lut, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff)) return 0; 
+    if (!CheckOne5D(lut, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff)) return 0;
 
     if (!CheckOne5D(lut, 0x8080, 0x8080, 0x8080, 0x8080, 0x1234)) return 0;
     if (!CheckOne5D(lut, 0x0000, 0xFE00, 0x80FF, 0x8888, 0x8078)) return 0;
     if (!CheckOne5D(lut, 0x1111, 0x2222, 0x3333, 0x4444, 0x1455)) return 0;
-    if (!CheckOne5D(lut, 0x0000, 0x0012, 0x0013, 0x0014, 0x2333)) return 0; 
-    if (!CheckOne5D(lut, 0x3141, 0x1415, 0x1592, 0x9261, 0x4567)) return 0; 
-    if (!CheckOne5D(lut, 0xFF00, 0xFF01, 0xFF12, 0xFF13, 0xF344)) return 0; 
+    if (!CheckOne5D(lut, 0x0000, 0x0012, 0x0013, 0x0014, 0x2333)) return 0;
+    if (!CheckOne5D(lut, 0x3141, 0x1415, 0x1592, 0x9261, 0x4567)) return 0;
+    if (!CheckOne5D(lut, 0xFF00, 0xFF01, 0xFF12, 0xFF13, 0xF344)) return 0;
 
     cmsPipelineFree(lut);
 
@@ -1976,14 +2020,14 @@ cmsInt32Number Check6DinterpGranular(void)
     // Check accuracy
 
     if (!CheckOne6D(lut, 0, 0, 0, 0, 0, 0)) return 0;
-    if (!CheckOne6D(lut, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff)) return 0; 
+    if (!CheckOne6D(lut, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff)) return 0;
 
     if (!CheckOne6D(lut, 0x8080, 0x8080, 0x8080, 0x8080, 0x1234, 0x1122)) return 0;
     if (!CheckOne6D(lut, 0x0000, 0xFE00, 0x80FF, 0x8888, 0x8078, 0x2233)) return 0;
     if (!CheckOne6D(lut, 0x1111, 0x2222, 0x3333, 0x4444, 0x1455, 0x3344)) return 0;
-    if (!CheckOne6D(lut, 0x0000, 0x0012, 0x0013, 0x0014, 0x2333, 0x4455)) return 0; 
-    if (!CheckOne6D(lut, 0x3141, 0x1415, 0x1592, 0x9261, 0x4567, 0x5566)) return 0; 
-    if (!CheckOne6D(lut, 0xFF00, 0xFF01, 0xFF12, 0xFF13, 0xF344, 0x6677)) return 0; 
+    if (!CheckOne6D(lut, 0x0000, 0x0012, 0x0013, 0x0014, 0x2333, 0x4455)) return 0;
+    if (!CheckOne6D(lut, 0x3141, 0x1415, 0x1592, 0x9261, 0x4567, 0x5566)) return 0;
+    if (!CheckOne6D(lut, 0xFF00, 0xFF01, 0xFF12, 0xFF13, 0xF344, 0x6677)) return 0;
 
     cmsPipelineFree(lut);
 
@@ -2005,14 +2049,14 @@ cmsInt32Number Check7DinterpGranular(void)
     // Check accuracy
 
     if (!CheckOne7D(lut, 0, 0, 0, 0, 0, 0, 0)) return 0;
-    if (!CheckOne7D(lut, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff)) return 0; 
+    if (!CheckOne7D(lut, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff)) return 0;
 
     if (!CheckOne7D(lut, 0x8080, 0x8080, 0x8080, 0x8080, 0x1234, 0x1122, 0x0056)) return 0;
     if (!CheckOne7D(lut, 0x0000, 0xFE00, 0x80FF, 0x8888, 0x8078, 0x2233, 0x0088)) return 0;
     if (!CheckOne7D(lut, 0x1111, 0x2222, 0x3333, 0x4444, 0x1455, 0x3344, 0x1987)) return 0;
-    if (!CheckOne7D(lut, 0x0000, 0x0012, 0x0013, 0x0014, 0x2333, 0x4455, 0x9988)) return 0; 
-    if (!CheckOne7D(lut, 0x3141, 0x1415, 0x1592, 0x9261, 0x4567, 0x5566, 0xfe56)) return 0; 
-    if (!CheckOne7D(lut, 0xFF00, 0xFF01, 0xFF12, 0xFF13, 0xF344, 0x6677, 0xbabe)) return 0; 
+    if (!CheckOne7D(lut, 0x0000, 0x0012, 0x0013, 0x0014, 0x2333, 0x4455, 0x9988)) return 0;
+    if (!CheckOne7D(lut, 0x3141, 0x1415, 0x1592, 0x9261, 0x4567, 0x5566, 0xfe56)) return 0;
+    if (!CheckOne7D(lut, 0xFF00, 0xFF01, 0xFF12, 0xFF13, 0xF344, 0x6677, 0xbabe)) return 0;
 
     cmsPipelineFree(lut);
 
@@ -2035,14 +2079,14 @@ cmsInt32Number Check8DinterpGranular(void)
     // Check accuracy
 
     if (!CheckOne8D(lut, 0, 0, 0, 0, 0, 0, 0, 0)) return 0;
-    if (!CheckOne8D(lut, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff)) return 0; 
+    if (!CheckOne8D(lut, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff)) return 0;
 
     if (!CheckOne8D(lut, 0x8080, 0x8080, 0x8080, 0x8080, 0x1234, 0x1122, 0x0056, 0x0011)) return 0;
     if (!CheckOne8D(lut, 0x0000, 0xFE00, 0x80FF, 0x8888, 0x8078, 0x2233, 0x0088, 0x2020)) return 0;
     if (!CheckOne8D(lut, 0x1111, 0x2222, 0x3333, 0x4444, 0x1455, 0x3344, 0x1987, 0x4532)) return 0;
-    if (!CheckOne8D(lut, 0x0000, 0x0012, 0x0013, 0x0014, 0x2333, 0x4455, 0x9988, 0x1200)) return 0; 
-    if (!CheckOne8D(lut, 0x3141, 0x1415, 0x1592, 0x9261, 0x4567, 0x5566, 0xfe56, 0x6666)) return 0; 
-    if (!CheckOne8D(lut, 0xFF00, 0xFF01, 0xFF12, 0xFF13, 0xF344, 0x6677, 0xbabe, 0xface)) return 0; 
+    if (!CheckOne8D(lut, 0x0000, 0x0012, 0x0013, 0x0014, 0x2333, 0x4455, 0x9988, 0x1200)) return 0;
+    if (!CheckOne8D(lut, 0x3141, 0x1415, 0x1592, 0x9261, 0x4567, 0x5566, 0xfe56, 0x6666)) return 0;
+    if (!CheckOne8D(lut, 0xFF00, 0xFF01, 0xFF12, 0xFF13, 0xF344, 0x6677, 0xbabe, 0xface)) return 0;
 
     cmsPipelineFree(lut);
 
@@ -2063,7 +2107,7 @@ cmsInt32Number CheckLab2LCh(void)
     for (l=0; l <= 100; l += 10) {
 
         for (a=-128; a <= +128; a += 8) {
-            
+
             for (b=-128; b <= 128; b += 8) {
 
                 Lab.L = l;
@@ -2074,7 +2118,7 @@ cmsInt32Number CheckLab2LCh(void)
                 cmsLCh2Lab(&Lab2, &LCh);
 
                 dist = cmsDeltaE(&Lab, &Lab2);
-                if (dist > Max) Max = dist;                
+                if (dist > Max) Max = dist;
             }
         }
     }
@@ -2158,7 +2202,7 @@ cmsInt32Number CheckLabV2encoding(void)
     cmsCIELab Lab;
 
     n2=0;
-    
+
     for (j=0; j < 65535; j++) {
 
         Inw[0] = Inw[1] = Inw[2] = (cmsUInt16Number) j;
@@ -2186,14 +2230,14 @@ cmsInt32Number CheckLabV4encoding(void)
     cmsCIELab Lab;
 
     n2=0;
-    
+
     for (j=0; j < 65535; j++) {
 
         Inw[0] = Inw[1] = Inw[2] = (cmsUInt16Number) j;
 
         cmsLabEncoded2Float(&Lab, Inw);
         cmsFloat2LabEncoded(aw, &Lab);
-        
+
         for (i=0; i < 3; i++) {
 
         if (aw[i] != j) {
@@ -2215,7 +2259,7 @@ cmsInt32Number CheckTemp2CHRM(void)
     cmsInt32Number j;
     cmsFloat64Number d, v, Max = 0;
     cmsCIExyY White;
-    
+
     for (j=4000; j < 25000; j++) {
 
         cmsWhitePointFromTemp(&White, j);
@@ -2259,7 +2303,7 @@ cmsInt32Number CheckGammaCreation16(void)
             cmsFreeToneCurve(LinGamma);
             return 0;
         }
-    }       
+    }
 
     if (!CheckGammaEstimation(LinGamma, 1.0)) return 0;
 
@@ -2284,7 +2328,7 @@ cmsInt32Number CheckGammaCreationFlt(void)
             cmsFreeToneCurve(LinGamma);
             return 0;
         }
-    }       
+    }
 
     if (!CheckGammaEstimation(LinGamma, 1.0)) return 0;
     cmsFreeToneCurve(LinGamma);
@@ -2309,7 +2353,7 @@ cmsInt32Number CheckGammaFloat(cmsFloat64Number g)
         val = pow((cmsFloat64Number) in, g);
 
         Err = fabs( val - out);
-        if (Err > MaxErr) MaxErr = Err;     
+        if (Err > MaxErr) MaxErr = Err;
     }
 
     if (MaxErr > 0) printf("|Err|<%lf ", MaxErr * 65535.0);
@@ -2320,17 +2364,17 @@ cmsInt32Number CheckGammaFloat(cmsFloat64Number g)
     return 1;
 }
 
-static cmsInt32Number CheckGamma18(void) 
+static cmsInt32Number CheckGamma18(void)
 {
     return CheckGammaFloat(1.8);
 }
 
-static cmsInt32Number CheckGamma22(void) 
+static cmsInt32Number CheckGamma22(void)
 {
     return CheckGammaFloat(2.2);
 }
 
-static cmsInt32Number CheckGamma30(void) 
+static cmsInt32Number CheckGamma30(void)
 {
     return CheckGammaFloat(3.0);
 }
@@ -2341,7 +2385,7 @@ static
 cmsInt32Number CheckGammaFloatTable(cmsFloat64Number g)
 {
     cmsFloat32Number Values[1025];
-    cmsToneCurve* Curve; 
+    cmsToneCurve* Curve;
     cmsInt32Number i;
     cmsFloat32Number in, out;
     cmsFloat64Number val, Err;
@@ -2362,7 +2406,7 @@ cmsInt32Number CheckGammaFloatTable(cmsFloat64Number g)
         val = pow(in, g);
 
         Err = fabs(val - out);
-        if (Err > MaxErr) MaxErr = Err;     
+        if (Err > MaxErr) MaxErr = Err;
     }
 
     if (MaxErr > 0) printf("|Err|<%lf ", MaxErr * 65535.0);
@@ -2374,17 +2418,17 @@ cmsInt32Number CheckGammaFloatTable(cmsFloat64Number g)
 }
 
 
-static cmsInt32Number CheckGamma18Table(void) 
+static cmsInt32Number CheckGamma18Table(void)
 {
     return CheckGammaFloatTable(1.8);
 }
 
-static cmsInt32Number CheckGamma22Table(void) 
+static cmsInt32Number CheckGamma22Table(void)
 {
     return CheckGammaFloatTable(2.2);
 }
 
-static cmsInt32Number CheckGamma30Table(void) 
+static cmsInt32Number CheckGamma30Table(void)
 {
     return CheckGammaFloatTable(3.0);
 }
@@ -2394,7 +2438,7 @@ static
 cmsInt32Number CheckGammaWordTable(cmsFloat64Number g)
 {
     cmsUInt16Number Values[1025];
-    cmsToneCurve* Curve; 
+    cmsToneCurve* Curve;
     cmsInt32Number i;
     cmsFloat32Number in, out;
     cmsFloat64Number val, Err;
@@ -2415,7 +2459,7 @@ cmsInt32Number CheckGammaWordTable(cmsFloat64Number g)
         val = pow(in, g);
 
         Err = fabs(val - out);
-        if (Err > MaxErr) MaxErr = Err;     
+        if (Err > MaxErr) MaxErr = Err;
     }
 
     if (MaxErr > 0) printf("|Err|<%lf ", MaxErr * 65535.0);
@@ -2426,17 +2470,17 @@ cmsInt32Number CheckGammaWordTable(cmsFloat64Number g)
     return 1;
 }
 
-static cmsInt32Number CheckGamma18TableWord(void) 
+static cmsInt32Number CheckGamma18TableWord(void)
 {
     return CheckGammaWordTable(1.8);
 }
 
-static cmsInt32Number CheckGamma22TableWord(void) 
+static cmsInt32Number CheckGamma22TableWord(void)
 {
     return CheckGammaWordTable(2.2);
 }
 
-static cmsInt32Number CheckGamma30TableWord(void) 
+static cmsInt32Number CheckGamma30TableWord(void)
 {
     return CheckGammaWordTable(3.0);
 }
@@ -2455,10 +2499,10 @@ cmsInt32Number CheckJointCurves(void)
 
     Result = cmsJoinToneCurve(DbgThread(), Forward, Reverse, 256);
 
-    cmsFreeToneCurve(Forward); cmsFreeToneCurve(Reverse); 
+    cmsFreeToneCurve(Forward); cmsFreeToneCurve(Reverse);
 
     rc = cmsIsToneCurveLinear(Result);
-    cmsFreeToneCurve(Result); 
+    cmsFreeToneCurve(Result);
 
     if (!rc)
         Fail("Joining same curve twice does not result in a linear ramp");
@@ -2494,7 +2538,7 @@ cmsInt32Number CheckJointCurvesDescending(void)
     cmsToneCurve *Forward, *Reverse, *Result;
     cmsInt32Number i, rc;
 
-     Forward = cmsBuildGamma(DbgThread(), 2.2); 
+     Forward = cmsBuildGamma(DbgThread(), 2.2);
 
     // Fake the curve to be table-based
 
@@ -2502,15 +2546,15 @@ cmsInt32Number CheckJointCurvesDescending(void)
         Forward ->Table16[i] = 0xffff - Forward->Table16[i];
     Forward ->Segments[0].Type = 0;
 
-    Reverse = cmsReverseToneCurve(Forward); 
-    
+    Reverse = cmsReverseToneCurve(Forward);
+
     Result = cmsJoinToneCurve(DbgThread(), Reverse, Reverse, 256);
-    
-    cmsFreeToneCurve(Forward); 
-    cmsFreeToneCurve(Reverse); 
+
+    cmsFreeToneCurve(Forward);
+    cmsFreeToneCurve(Reverse);
 
     rc = cmsIsToneCurveLinear(Result);
-    cmsFreeToneCurve(Result); 
+    cmsFreeToneCurve(Result);
 
     return rc;
 }
@@ -2522,7 +2566,7 @@ cmsInt32Number CheckFToneCurvePoint(cmsToneCurve* c, cmsUInt16Number Point, cmsI
     cmsInt32Number Result;
 
     Result = cmsEvalToneCurve16(c, Point);
-    
+
     return (abs(Value - Result) < 2);
 }
 
@@ -2531,7 +2575,7 @@ cmsInt32Number CheckReverseDegenerated(void)
 {
     cmsToneCurve* p, *g;
     cmsUInt16Number Tab[16];
-    
+
     Tab[0] = 0;
     Tab[1] = 0;
     Tab[2] = 0;
@@ -2551,7 +2595,7 @@ cmsInt32Number CheckReverseDegenerated(void)
 
     p = cmsBuildTabulatedToneCurve16(DbgThread(), 16, Tab);
     g = cmsReverseToneCurve(p);
-    
+
     // Now let's check some points
     if (!CheckFToneCurvePoint(g, 0x5555, 0x5555)) return 0;
     if (!CheckFToneCurvePoint(g, 0x7777, 0x7777)) return 0;
@@ -2617,7 +2661,7 @@ cmsToneCurve* CombineGamma16(cmsToneCurve* g1, cmsToneCurve* g2)
 
         cmsUInt16Number wValIn;
 
-        wValIn = _cmsQuantizeVal(i, 256);     
+        wValIn = _cmsQuantizeVal(i, 256);
         Tab[i] = cmsEvalToneCurve16(g2, cmsEvalToneCurve16(g1, wValIn));
     }
 
@@ -2633,10 +2677,10 @@ cmsInt32Number CheckJointFloatCurves_sRGB(void)
     Forward = Build_sRGBGamma();
     Reverse = cmsReverseToneCurve(Forward);
     Result = CombineGammaFloat(Forward, Reverse);
-    cmsFreeToneCurve(Forward); cmsFreeToneCurve(Reverse); 
+    cmsFreeToneCurve(Forward); cmsFreeToneCurve(Reverse);
 
     rc = cmsIsToneCurveLinear(Result);
-    cmsFreeToneCurve(Result); 
+    cmsFreeToneCurve(Result);
 
     return rc;
 }
@@ -2650,10 +2694,10 @@ cmsInt32Number CheckJoint16Curves_sRGB(void)
     Forward = Build_sRGBGamma();
     Reverse = cmsReverseToneCurve(Forward);
     Result = CombineGamma16(Forward, Reverse);
-    cmsFreeToneCurve(Forward); cmsFreeToneCurve(Reverse); 
+    cmsFreeToneCurve(Forward); cmsFreeToneCurve(Reverse);
 
     rc = cmsIsToneCurveLinear(Result);
-    cmsFreeToneCurve(Result); 
+    cmsFreeToneCurve(Result);
 
     return rc;
 }
@@ -2667,15 +2711,15 @@ cmsInt32Number CheckJointCurvesSShaped(void)
     cmsToneCurve *Forward, *Reverse, *Result;
     cmsInt32Number rc;
 
-    Forward = cmsBuildParametricToneCurve(DbgThread(), 108, &p);    
+    Forward = cmsBuildParametricToneCurve(DbgThread(), 108, &p);
     Reverse = cmsReverseToneCurve(Forward);
     Result = cmsJoinToneCurve(DbgThread(), Forward, Forward, 4096);
 
-    cmsFreeToneCurve(Forward); 
-    cmsFreeToneCurve(Reverse); 
+    cmsFreeToneCurve(Forward);
+    cmsFreeToneCurve(Reverse);
 
     rc = cmsIsToneCurveLinear(Result);
-    cmsFreeToneCurve(Result); 
+    cmsFreeToneCurve(Result);
     return rc;
 }
 
@@ -2717,7 +2761,7 @@ cmsFloat32Number IEC61966_3(cmsFloat32Number x, const cmsFloat64Number Params[])
 
     if (x >= -Params[2] / Params[1]) {
 
-        e = Params[1]*x + Params[2];                    
+        e = Params[1]*x + Params[2];
 
         if (e > 0)
             Val = pow(e, Params[0]) + Params[3];
@@ -2763,7 +2807,7 @@ cmsFloat32Number param_5(cmsFloat32Number x, const cmsFloat64Number Params[])
             Val = pow(e, Params[0]) + Params[5];
         else
             Val = 0;
-    }        
+    }
     else
         Val = x*Params[3] + Params[6];
 
@@ -2774,9 +2818,9 @@ static
 cmsFloat32Number param_6(cmsFloat32Number x, const cmsFloat64Number Params[])
 {
     cmsFloat64Number e, Val;
-    
+
     e = Params[1]*x + Params[2];
-    if (e > 0) 
+    if (e > 0)
         Val = pow(e, Params[0]) + Params[3];
     else
         Val = 0;
@@ -2844,8 +2888,8 @@ cmsBool CheckSingleParametric(const char* Name, dblfnptr fn, cmsInt32Number Type
             goto Error;
 
         sprintf(InverseText, "Inverse %s", Name);
-        if (!IsGoodVal(InverseText, y_fn, y_param2, FIXED_PRECISION_15_16)) 
-            goto Error;       
+        if (!IsGoodVal(InverseText, y_fn, y_param2, FIXED_PRECISION_15_16))
+            goto Error;
     }
 
     cmsFreeToneCurve(tc);
@@ -2865,7 +2909,7 @@ cmsInt32Number CheckParametricToneCurves(void)
     cmsFloat64Number Params[10];
 
      // 1) X = Y ^ Gamma
-     
+
      Params[0] = 2.2;
 
      if (!CheckSingleParametric("Gamma", Gamma, 1, Params)) return 0;
@@ -2888,7 +2932,7 @@ cmsInt32Number CheckParametricToneCurves(void)
      Params[1] = 1.5;
      Params[2] = -0.5;
      Params[3] = 0.3;
-  
+
 
      if (!CheckSingleParametric("IEC 61966-3", IEC61966_3, 3, Params)) return 0;
 
@@ -2900,11 +2944,11 @@ cmsInt32Number CheckParametricToneCurves(void)
      Params[1] = 1. / 1.055;
      Params[2] = 0.055 / 1.055;
      Params[3] = 1. / 12.92;
-     Params[4] = 0.04045;    
+     Params[4] = 0.04045;
 
      if (!CheckSingleParametric("IEC 61966-2.1", IEC61966_21, 4, Params)) return 0;
 
-               
+
      // 5) Y = (aX + b)^Gamma + e | X >= d
      // Y = cX + f             | else
 
@@ -2915,7 +2959,7 @@ cmsInt32Number CheckParametricToneCurves(void)
      Params[4] = 0.1;
      Params[5] = 0.5;
      Params[6] = 0.2;
-     
+
      if (!CheckSingleParametric("param_5", param_5, 5, Params)) return 0;
 
      // 6) Y = (aX + b) ^ Gamma + c
@@ -2924,7 +2968,7 @@ cmsInt32Number CheckParametricToneCurves(void)
      Params[1] = 0.7;
      Params[2] = 0.2;
      Params[3] = 0.3;
-     
+
      if (!CheckSingleParametric("param_6", param_6, 6, Params)) return 0;
 
      // 7) Y = a * log (b * X^Gamma + c) + d
@@ -2937,8 +2981,8 @@ cmsInt32Number CheckParametricToneCurves(void)
 
      if (!CheckSingleParametric("param_7", param_7, 7, Params)) return 0;
 
-     // 8) Y = a * b ^ (c*X+d) + e          
-     
+     // 8) Y = a * b ^ (c*X+d) + e
+
      Params[0] = 0.9;
      Params[1] = 0.9;
      Params[2] = 1.02;
@@ -2965,7 +3009,7 @@ cmsInt32Number CheckLUTcreation(void)
     cmsPipeline* lut;
     cmsPipeline* lut2;
     cmsInt32Number n1, n2;
-    
+
     lut = cmsPipelineAlloc(DbgThread(), 1, 1);
     n1 = cmsPipelineStageCount(lut);
     lut2 = cmsPipelineDup(lut);
@@ -2982,8 +3026,8 @@ static
 void AddIdentityMatrix(cmsPipeline* lut)
 {
     const cmsFloat64Number Identity[] = { 1, 0, 0,
-                          0, 1, 0, 
-                          0, 0, 1, 
+                          0, 1, 0,
+                          0, 0, 1,
                           0, 0, 0 };
 
     cmsPipelineInsertStage(lut, cmsAT_END, cmsStageAllocMatrix(DbgThread(), 3, 3, Identity, NULL));
@@ -2993,18 +3037,18 @@ void AddIdentityMatrix(cmsPipeline* lut)
 static
 void AddIdentityCLUTfloat(cmsPipeline* lut)
 {
-    const cmsFloat32Number  Table[] = { 
+    const cmsFloat32Number  Table[] = {
 
-        0,    0,    0,    
+        0,    0,    0,
         0,    0,    1.0,
 
-        0,    1.0,    0, 
+        0,    1.0,    0,
         0,    1.0,    1.0,
 
-        1.0,    0,    0,    
+        1.0,    0,    0,
         1.0,    0,    1.0,
 
-        1.0,    1.0,    0, 
+        1.0,    1.0,    0,
         1.0,    1.0,    1.0
     };
 
@@ -3015,21 +3059,21 @@ void AddIdentityCLUTfloat(cmsPipeline* lut)
 static
 void AddIdentityCLUT16(cmsPipeline* lut)
 {
-    const cmsUInt16Number Table[] = { 
+    const cmsUInt16Number Table[] = {
 
-        0,    0,    0,    
+        0,    0,    0,
         0,    0,    0xffff,
 
-        0,    0xffff,    0, 
+        0,    0xffff,    0,
         0,    0xffff,    0xffff,
 
-        0xffff,    0,    0,    
+        0xffff,    0,    0,
         0xffff,    0,    0xffff,
 
-        0xffff,    0xffff,    0, 
+        0xffff,    0xffff,    0,
         0xffff,    0xffff,    0xffff
     };
-   
+
 
     cmsPipelineInsertStage(lut, cmsAT_END, cmsStageAllocCLut16bit(DbgThread(), 2, 3, 3, Table));
 }
@@ -3037,7 +3081,7 @@ void AddIdentityCLUT16(cmsPipeline* lut)
 
 // Create a 3 fn identity curves
 
-static 
+static
 void Add3GammaCurves(cmsPipeline* lut, cmsFloat64Number Curve)
 {
     cmsToneCurve* id = cmsBuildGamma(DbgThread(), Curve);
@@ -3048,7 +3092,7 @@ void Add3GammaCurves(cmsPipeline* lut, cmsFloat64Number Curve)
     id3[2] = id;
 
     cmsPipelineInsertStage(lut, cmsAT_END, cmsStageAllocToneCurves(DbgThread(), 3, id3));
-    
+
     cmsFreeToneCurve(id);
 }
 
@@ -3092,7 +3136,7 @@ cmsInt32Number Check16LUT(cmsPipeline* lut)
     cmsUInt16Number Inw[3], Outw[3];
 
     n2=0;
-    
+
     for (j=0; j < 65535; j++) {
 
         cmsInt32Number aw[3];
@@ -3120,13 +3164,13 @@ cmsInt32Number Check16LUT(cmsPipeline* lut)
 static
 cmsInt32Number CheckStagesLUT(cmsPipeline* lut, cmsInt32Number ExpectedStages)
 {
-    
+
     cmsInt32Number nInpChans, nOutpChans, nStages;
 
     nInpChans  = cmsPipelineInputChannels(lut);
     nOutpChans = cmsPipelineOutputChannels(lut);
     nStages    = cmsPipelineStageCount(lut);
-    
+
     return (nInpChans == 3) && (nOutpChans == 3) && (nStages == ExpectedStages);
 }
 
@@ -3238,7 +3282,7 @@ cmsInt32Number Check5StageLUT(void)
     Add3GammaCurves(lut, 1.0);
     AddIdentityMatrix(lut);
     Add3GammaCurves(lut, 1.0);
-    
+
     return CheckFullLUT(lut, 5);
 }
 
@@ -3253,7 +3297,7 @@ cmsInt32Number Check5Stage16LUT(void)
     Add3GammaCurves(lut, 1.0);
     AddIdentityMatrix(lut);
     Add3GammaCurves(lut, 1.0);
-    
+
     return CheckFullLUT(lut, 5);
 }
 
@@ -3268,7 +3312,7 @@ cmsInt32Number Check6StageLUT(void)
     Add3GammaCurves(lut, 1.0);
     AddIdentityMatrix(lut);
     Add3GammaCurves(lut, 1.0);
-    
+
     return CheckFullLUT(lut, 6);
 }
 
@@ -3283,7 +3327,7 @@ cmsInt32Number Check6Stage16LUT(void)
     Add3GammaCurves(lut, 1.0);
     AddIdentityMatrix(lut);
     Add3GammaCurves(lut, 1.0);
-    
+
     return CheckFullLUT(lut, 6);
 }
 
@@ -3394,7 +3438,7 @@ cmsInt32Number CheckNamedColorLUT(void)
 
 // --------------------------------------------------------------------------------------------
 
-// A lightweight test of multilocalized unicode structures. 
+// A lightweight test of multilocalized unicode structures.
 
 static
 cmsInt32Number CheckMLU(void)
@@ -3406,7 +3450,7 @@ cmsInt32Number CheckMLU(void)
     cmsHPROFILE h= NULL;
 
     // Allocate a MLU structure, no preferred size
-    mlu = cmsMLUalloc(DbgThread(), 0);    
+    mlu = cmsMLUalloc(DbgThread(), 0);
 
     // Add some localizations
     cmsMLUsetWide(mlu, "en", "US", L"Hello, world");
@@ -3424,11 +3468,11 @@ cmsInt32Number CheckMLU(void)
     cmsMLUgetASCII(mlu, "es", "ES", Buffer, 256);
     if (strcmp(Buffer, "Hola, mundo") != 0) rc = 0;
 
-  
+
     cmsMLUgetASCII(mlu, "fr", "FR", Buffer, 256);
     if (strcmp(Buffer, "Bonjour, le monde") != 0) rc = 0;
 
-   
+
     cmsMLUgetASCII(mlu, "ca", "CA", Buffer, 256);
     if (strcmp(Buffer, "Hola, mon") != 0) rc = 0;
 
@@ -3439,13 +3483,13 @@ cmsInt32Number CheckMLU(void)
     cmsMLUfree(mlu);
 
     // Now for performance, allocate an empty struct
-    mlu = cmsMLUalloc(DbgThread(), 0);    
+    mlu = cmsMLUalloc(DbgThread(), 0);
 
     // Fill it with several thousands of different lenguages
     for (i=0; i < 4096; i++) {
 
         char Lang[3];
-        
+
         Lang[0] = (char) (i % 255);
         Lang[1] = (char) (i / 255);
         Lang[2] = 0;
@@ -3464,7 +3508,7 @@ cmsInt32Number CheckMLU(void)
     for (i=0; i < 4096; i++) {
 
         char Lang[3];
-        
+
         Lang[0] = (char)(i % 255);
         Lang[1] = (char)(i / 255);
         Lang[2] = 0;
@@ -3475,20 +3519,20 @@ cmsInt32Number CheckMLU(void)
         if (strcmp(Buffer, Buffer2) != 0) { rc = 0; break; }
     }
 
-    if (rc == 0) 
+    if (rc == 0)
         Fail("Unexpected string '%s'", Buffer2);
 
     // Check profile IO
 
     h = cmsOpenProfileFromFileTHR(DbgThread(), "mlucheck.icc", "w");
-        
+
     cmsSetProfileVersion(h, 4.3);
 
     cmsWriteTag(h, cmsSigProfileDescriptionTag, mlu2);
     cmsCloseProfile(h);
     cmsMLUfree(mlu2);
 
-    
+
     h = cmsOpenProfileFromFileTHR(DbgThread(), "mlucheck.icc", "r");
 
     mlu3 = cmsReadTag(h, cmsSigProfileDescriptionTag);
@@ -3498,7 +3542,7 @@ cmsInt32Number CheckMLU(void)
     for (i=0; i < 4096; i++) {
 
         char Lang[3];
-        
+
         Lang[0] = (char) (i % 255);
         Lang[1] = (char) (i / 255);
         Lang[2] = 0;
@@ -3635,16 +3679,16 @@ void CheckSingleFormatter16(cmsUInt32Number Type, const char* Text)
     info.OutputFormat = info.InputFormat = Type;
 
     // Go forth and back
-    f = _cmsGetFormatter(Type,  cmsFormatterInput, 0);
-    b = _cmsGetFormatter(Type,  cmsFormatterOutput, 0);
+    f = _cmsGetFormatter(Type,  cmsFormatterInput, CMS_PACK_FLAGS_16BITS);
+    b = _cmsGetFormatter(Type,  cmsFormatterOutput, CMS_PACK_FLAGS_16BITS);
 
     if (f.Fmt16 == NULL || b.Fmt16 == NULL) {
         Fail("no formatter for %s", Text);
         FormatterFailed = TRUE;
 
         // Useful for debug
-        f = _cmsGetFormatter(Type,  cmsFormatterInput, 0);
-        b = _cmsGetFormatter(Type,  cmsFormatterOutput, 0);
+        f = _cmsGetFormatter(Type,  cmsFormatterInput, CMS_PACK_FLAGS_16BITS);
+        b = _cmsGetFormatter(Type,  cmsFormatterOutput, CMS_PACK_FLAGS_16BITS);
         return;
     }
 
@@ -3653,10 +3697,10 @@ void CheckSingleFormatter16(cmsUInt32Number Type, const char* Text)
 
     for (j=0; j < 5; j++) {
 
-        for (i=0; i < nChannels; i++) { 
+        for (i=0; i < nChannels; i++) {
             Values[i] = (cmsUInt16Number) (i+j);
             // For 8-bit
-            if (bytes == 1) 
+            if (bytes == 1)
                 Values[i] <<= 8;
         }
 
@@ -3665,19 +3709,19 @@ void CheckSingleFormatter16(cmsUInt32Number Type, const char* Text)
     f.Fmt16(&info, Values, Buffer, 1);
 
     for (i=0; i < nChannels; i++) {
-        if (bytes == 1) 
+        if (bytes == 1)
             Values[i] >>= 8;
 
         if (Values[i] != i+j) {
 
-            Fail("%s failed", Text);        
+            Fail("%s failed", Text);
             FormatterFailed = TRUE;
 
             // Useful for debug
-            for (i=0; i < nChannels; i++) { 
+            for (i=0; i < nChannels; i++) {
                 Values[i] = (cmsUInt16Number) (i+j);
                 // For 8-bit
-                if (bytes == 1) 
+                if (bytes == 1)
                     Values[i] <<= 8;
             }
 
@@ -3724,12 +3768,15 @@ cmsInt32Number CheckFormatters16(void)
    C( TYPE_RGBA_16_PLANAR    );
    C( TYPE_RGBA_16_SE        );
    C( TYPE_ARGB_8            );
+   C( TYPE_ARGB_8_PLANAR     );
    C( TYPE_ARGB_16           );
    C( TYPE_ABGR_8            );
+   C( TYPE_ABGR_8_PLANAR     );
    C( TYPE_ABGR_16           );
    C( TYPE_ABGR_16_PLANAR    );
    C( TYPE_ABGR_16_SE        );
    C( TYPE_BGRA_8            );
+   C( TYPE_BGRA_8_PLANAR     );
    C( TYPE_BGRA_16           );
    C( TYPE_BGRA_16_SE        );
    C( TYPE_CMY_8             );
@@ -3827,26 +3874,43 @@ cmsInt32Number CheckFormatters16(void)
    C( TYPE_HSV_16            );
    C( TYPE_HSV_16_PLANAR     );
    C( TYPE_HSV_16_SE         );
-        
+
    C( TYPE_XYZ_FLT  );
    C( TYPE_Lab_FLT  );
    C( TYPE_GRAY_FLT );
    C( TYPE_RGB_FLT  );
+   C( TYPE_BGR_FLT  );
    C( TYPE_CMYK_FLT );
-   C( TYPE_XYZA_FLT );
    C( TYPE_LabA_FLT );
    C( TYPE_RGBA_FLT );
+   C( TYPE_ARGB_FLT );
+   C( TYPE_BGRA_FLT );
+   C( TYPE_ABGR_FLT );
+
 
    C( TYPE_XYZ_DBL  );
    C( TYPE_Lab_DBL  );
    C( TYPE_GRAY_DBL );
    C( TYPE_RGB_DBL  );
+   C( TYPE_BGR_DBL  );
    C( TYPE_CMYK_DBL );
 
    C( TYPE_LabV2_8  );
    C( TYPE_ALabV2_8 );
    C( TYPE_LabV2_16 );
 
+   C( TYPE_GRAY_HALF_FLT );
+   C( TYPE_RGB_HALF_FLT  );
+   C( TYPE_CMYK_HALF_FLT );
+   C( TYPE_RGBA_HALF_FLT );
+
+   C( TYPE_RGBA_HALF_FLT );
+   C( TYPE_ARGB_HALF_FLT );
+   C( TYPE_BGR_HALF_FLT  );
+   C( TYPE_BGRA_HALF_FLT );
+   C( TYPE_ABGR_HALF_FLT );
+
+
    return FormatterFailed == 0 ? 1 : 0;
 }
 #undef C
@@ -3884,7 +3948,7 @@ void CheckSingleFormatterFloat(cmsUInt32Number Type, const char* Text)
 
     for (j=0; j < 5; j++) {
 
-        for (i=0; i < nChannels; i++) { 
+        for (i=0; i < nChannels; i++) {
             Values[i] = (cmsFloat32Number) (i+j);
         }
 
@@ -3898,11 +3962,11 @@ void CheckSingleFormatterFloat(cmsUInt32Number Type, const char* Text)
 
             if (delta > 0.000000001) {
 
-                Fail("%s failed", Text);        
+                Fail("%s failed", Text);
                 FormatterFailed = TRUE;
 
                 // Useful for debug
-                for (i=0; i < nChannels; i++) { 
+                for (i=0; i < nChannels; i++) {
                     Values[i] = (cmsFloat32Number) (i+j);
                 }
 
@@ -3921,30 +3985,75 @@ cmsInt32Number CheckFormattersFloat(void)
 {
     FormatterFailed = FALSE;
 
-    C( TYPE_XYZ_FLT  ); 
+    C( TYPE_XYZ_FLT  );
     C( TYPE_Lab_FLT  );
     C( TYPE_GRAY_FLT );
     C( TYPE_RGB_FLT  );
+    C( TYPE_BGR_FLT  );
     C( TYPE_CMYK_FLT );
 
-    // User
-    C( TYPE_XYZA_FLT );
     C( TYPE_LabA_FLT );
     C( TYPE_RGBA_FLT );
 
+    C( TYPE_ARGB_FLT );
+    C( TYPE_BGRA_FLT );
+    C( TYPE_ABGR_FLT );
+
     C( TYPE_XYZ_DBL  );
     C( TYPE_Lab_DBL  );
     C( TYPE_GRAY_DBL );
     C( TYPE_RGB_DBL  );
+    C( TYPE_BGR_DBL  );
     C( TYPE_CMYK_DBL );
 
+   C( TYPE_GRAY_HALF_FLT );
+   C( TYPE_RGB_HALF_FLT  );
+   C( TYPE_CMYK_HALF_FLT );
+   C( TYPE_RGBA_HALF_FLT );
+
+   C( TYPE_RGBA_HALF_FLT );
+   C( TYPE_ARGB_HALF_FLT );
+   C( TYPE_BGR_HALF_FLT  );
+   C( TYPE_BGRA_HALF_FLT );
+   C( TYPE_ABGR_HALF_FLT );
+
+
     return FormatterFailed == 0 ? 1 : 0;
 }
 #undef C
 
+#ifndef CMS_NO_HALF_SUPPORT 
+
+// Check half float
+#define my_isfinite(x) ((x) != (x))
+static
+cmsInt32Number CheckFormattersHalf(void)
+{
+    int i, j;
+
+
+    for (i=0; i < 0xffff; i++) {
+
+        cmsFloat32Number f = _cmsHalf2Float((cmsUInt16Number) i);
+
+        if (!my_isfinite(f))  {
+
+            j = _cmsFloat2Half(f);
+
+            if (i != j) {
+                Fail("%d != %d in Half float support!\n", i, j);
+                return 0;
+            }
+        }
+    }
+
+    return 1;
+}
+
+#endif
 
 static
-cmsInt32Number CheckOneRGB(cmsHTRANSFORM xform, cmsUInt32Number R, cmsUInt32Number G, cmsUInt32Number B, cmsUInt32Number Ro, cmsUInt32Number Go, cmsUInt32Number Bo)
+cmsInt32Number CheckOneRGB(cmsHTRANSFORM xform, cmsUInt16Number R, cmsUInt16Number G, cmsUInt16Number B, cmsUInt16Number Ro, cmsUInt16Number Go, cmsUInt16Number Bo)
 {
     cmsUInt16Number RGB[3];
     cmsUInt16Number Out[3];
@@ -3990,7 +4099,7 @@ cmsInt32Number CheckChangeBufferFormat(void)
     cmsCloseProfile(hsRGB);
     if (xform == NULL) return 0;
 
-    
+
     if (!CheckOneRGB(xform, 0, 0, 0, 0, 0, 0)) return 0;
     if (!CheckOneRGB(xform, 120, 0, 0, 120, 0, 0)) return 0;
     if (!CheckOneRGB(xform, 0, 222, 255, 0, 222, 255)) return 0;
@@ -4007,7 +4116,7 @@ cmsInt32Number CheckChangeBufferFormat(void)
     if (!CheckOneRGB_double(xform, 0, 0.9, 1, 0, 0.9, 1)) return 0;
 
     cmsDeleteTransform(xform);
-    
+
 return 1;
 }
 
@@ -4019,14 +4128,14 @@ cmsInt32Number CheckXYZ(cmsInt32Number Pass, cmsHPROFILE hProfile, cmsTagSignatu
 {
     cmsCIEXYZ XYZ, *Pt;
 
-    
+
     switch (Pass) {
 
         case 1:
 
             XYZ.X = 1.0; XYZ.Y = 1.1; XYZ.Z = 1.2;
             return cmsWriteTag(hProfile, tag, &XYZ);
-    
+
         case 2:
             Pt = cmsReadTag(hProfile, tag);
             if (Pt == NULL) return 0;
@@ -4054,12 +4163,12 @@ cmsInt32Number CheckGamma(cmsInt32Number Pass, cmsHPROFILE hProfile, cmsTagSigna
             rc = cmsWriteTag(hProfile, tag, g);
             cmsFreeToneCurve(g);
             return rc;
-    
+
         case 2:
             Pt = cmsReadTag(hProfile, tag);
             if (Pt == NULL) return 0;
             return cmsIsToneCurveLinear(Pt);
-            
+
         default:
             return 0;
     }
@@ -4072,7 +4181,7 @@ cmsInt32Number CheckText(cmsInt32Number Pass, cmsHPROFILE hProfile, cmsTagSignat
     cmsInt32Number rc;
     char Buffer[256];
 
-    
+
     switch (Pass) {
 
         case 1:
@@ -4081,13 +4190,13 @@ cmsInt32Number CheckText(cmsInt32Number Pass, cmsHPROFILE hProfile, cmsTagSignat
             rc = cmsWriteTag(hProfile, tag, m);
             cmsMLUfree(m);
             return rc;
-    
+
         case 2:
             Pt = cmsReadTag(hProfile, tag);
             if (Pt == NULL) return 0;
             cmsMLUgetASCII(Pt, cmsNoLanguage, cmsNoCountry, Buffer, 256);
             return strcmp(Buffer, "Test test") == 0;
-            
+
         default:
             return 0;
     }
@@ -4100,13 +4209,13 @@ cmsInt32Number CheckData(cmsInt32Number Pass,  cmsHPROFILE hProfile, cmsTagSigna
     cmsICCData d = { 1, 0, { '?' }};
     cmsInt32Number rc;
 
-    
+
     switch (Pass) {
 
         case 1:
             rc = cmsWriteTag(hProfile, tag, &d);
             return rc;
-    
+
         case 2:
             Pt = cmsReadTag(hProfile, tag);
             if (Pt == NULL) return 0;
@@ -4122,13 +4231,13 @@ static
 cmsInt32Number CheckSignature(cmsInt32Number Pass,  cmsHPROFILE hProfile, cmsTagSignature tag)
 {
     cmsTagSignature *Pt, Holder;
-    
+
     switch (Pass) {
 
         case 1:
             Holder = cmsSigPerceptualReferenceMediumGamut;
             return cmsWriteTag(hProfile, tag, &Holder);
-    
+
         case 2:
             Pt = cmsReadTag(hProfile, tag);
             if (Pt == NULL) return 0;
@@ -4148,7 +4257,7 @@ cmsInt32Number CheckDateTime(cmsInt32Number Pass,  cmsHPROFILE hProfile, cmsTagS
     switch (Pass) {
 
         case 1:
-    
+
             Holder.tm_hour = 1;
             Holder.tm_min = 2;
             Holder.tm_sec = 3;
@@ -4156,13 +4265,13 @@ cmsInt32Number CheckDateTime(cmsInt32Number Pass,  cmsHPROFILE hProfile, cmsTagS
             Holder.tm_mon = 5;
             Holder.tm_year = 2009 - 1900;
             return cmsWriteTag(hProfile, tag, &Holder);
-    
+
         case 2:
             Pt = cmsReadTag(hProfile, tag);
             if (Pt == NULL) return 0;
 
-            return (Pt ->tm_hour == 1 && 
-                Pt ->tm_min == 2 && 
+            return (Pt ->tm_hour == 1 &&
+                Pt ->tm_min == 2 &&
                 Pt ->tm_sec == 3 &&
                 Pt ->tm_mday == 4 &&
                 Pt ->tm_mon == 5 &&
@@ -4261,7 +4370,7 @@ cmsInt32Number CheckLUT(cmsInt32Number Pass,  cmsHPROFILE hProfile, cmsTagSignat
             cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocIdentityCurves(DbgThread(), 3));
             cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocIdentityCLut(DbgThread(), 3));
             cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocIdentityCurves(DbgThread(), 3));
-        
+
             rc =  cmsWriteTag(hProfile, tag, Lut);
             cmsPipelineFree(Lut);
             return rc;
@@ -4287,9 +4396,9 @@ cmsInt32Number CheckCHAD(cmsInt32Number Pass,  cmsHPROFILE hProfile, cmsTagSigna
 
     switch (Pass) {
 
-        case 1:         
+        case 1:
             return cmsWriteTag(hProfile, tag, CHAD);
-            
+
 
         case 2:
             Pt = cmsReadTag(hProfile, tag);
@@ -4313,9 +4422,9 @@ cmsInt32Number CheckChromaticity(cmsInt32Number Pass,  cmsHPROFILE hProfile, cms
 
     switch (Pass) {
 
-        case 1:         
+        case 1:
             return cmsWriteTag(hProfile, tag, &c);
-            
+
 
         case 2:
             Pt = cmsReadTag(hProfile, tag);
@@ -4343,10 +4452,10 @@ cmsInt32Number CheckColorantOrder(cmsInt32Number Pass,  cmsHPROFILE hProfile, cm
 
     switch (Pass) {
 
-        case 1:         
+        case 1:
             for (i=0; i < cmsMAXCHANNELS; i++) c[i] = (cmsUInt8Number) (cmsMAXCHANNELS - i - 1);
             return cmsWriteTag(hProfile, tag, c);
-            
+
 
         case 2:
             Pt = cmsReadTag(hProfile, tag);
@@ -4369,7 +4478,7 @@ cmsInt32Number CheckMeasurement(cmsInt32Number Pass,  cmsHPROFILE hProfile, cmsT
 
     switch (Pass) {
 
-        case 1:         
+        case 1:
             m.Backing.X = 0.1;
             m.Backing.Y = 0.2;
             m.Backing.Z = 0.3;
@@ -4378,7 +4487,7 @@ cmsInt32Number CheckMeasurement(cmsInt32Number Pass,  cmsHPROFILE hProfile, cmsT
             m.IlluminantType = cmsILLUMINANT_TYPE_D50;
             m.Observer = 1;
             return cmsWriteTag(hProfile, tag, &m);
-            
+
 
         case 2:
             Pt = cmsReadTag(hProfile, tag);
@@ -4409,24 +4518,24 @@ cmsInt32Number CheckUcrBg(cmsInt32Number Pass,  cmsHPROFILE hProfile, cmsTagSign
 
     switch (Pass) {
 
-        case 1:         
+        case 1:
             m.Ucr = cmsBuildGamma(DbgThread(), 2.4);
             m.Bg  = cmsBuildGamma(DbgThread(), -2.2);
             m.Desc = cmsMLUalloc(DbgThread(), 1);
-            cmsMLUsetASCII(m.Desc,  cmsNoLanguage, cmsNoCountry, "test UCR/BG");         
+            cmsMLUsetASCII(m.Desc,  cmsNoLanguage, cmsNoCountry, "test UCR/BG");
             rc = cmsWriteTag(hProfile, tag, &m);
             cmsMLUfree(m.Desc);
             cmsFreeToneCurve(m.Bg);
             cmsFreeToneCurve(m.Ucr);
             return rc;
-            
+
 
         case 2:
             Pt = cmsReadTag(hProfile, tag);
             if (Pt == NULL) return 0;
 
             cmsMLUgetASCII(Pt ->Desc, cmsNoLanguage, cmsNoCountry, Buffer, 256);
-            if (strcmp(Buffer, "test UCR/BG") != 0) return 0;       
+            if (strcmp(Buffer, "test UCR/BG") != 0) return 0;
             return 1;
 
         default:
@@ -4444,41 +4553,41 @@ cmsInt32Number CheckCRDinfo(cmsInt32Number Pass,  cmsHPROFILE hProfile, cmsTagSi
 
     switch (Pass) {
 
-        case 1: 
+        case 1:
             mlu = cmsMLUalloc(DbgThread(), 5);
 
             cmsMLUsetWide(mlu,  "PS", "nm", L"test postscript");
             cmsMLUsetWide(mlu,  "PS", "#0", L"perceptual");
             cmsMLUsetWide(mlu,  "PS", "#1", L"relative_colorimetric");
             cmsMLUsetWide(mlu,  "PS", "#2", L"saturation");
-            cmsMLUsetWide(mlu,  "PS", "#3", L"absolute_colorimetric");  
+            cmsMLUsetWide(mlu,  "PS", "#3", L"absolute_colorimetric");
             rc = cmsWriteTag(hProfile, tag, mlu);
             cmsMLUfree(mlu);
             return rc;
-            
+
 
         case 2:
             mlu = (cmsMLU*) cmsReadTag(hProfile, tag);
             if (mlu == NULL) return 0;
 
 
-             
+
              cmsMLUgetASCII(mlu, "PS", "nm", Buffer, 256);
              if (strcmp(Buffer, "test postscript") != 0) return 0;
 
-           
+
              cmsMLUgetASCII(mlu, "PS", "#0", Buffer, 256);
              if (strcmp(Buffer, "perceptual") != 0) return 0;
 
-            
+
              cmsMLUgetASCII(mlu, "PS", "#1", Buffer, 256);
              if (strcmp(Buffer, "relative_colorimetric") != 0) return 0;
 
-             
+
              cmsMLUgetASCII(mlu, "PS", "#2", Buffer, 256);
              if (strcmp(Buffer, "saturation") != 0) return 0;
 
-            
+
              cmsMLUgetASCII(mlu, "PS", "#3", Buffer, 256);
              if (strcmp(Buffer, "absolute_colorimetric") != 0) return 0;
              return 1;
@@ -4513,7 +4622,7 @@ cmsToneCurve *CreateSegmentedCurve(void)
     Seg[2].Params[0] = 1;
     Seg[2].Params[1] = 0;
     Seg[2].Params[2] = 0;
-    Seg[2].Params[3] = 0;               
+    Seg[2].Params[3] = 0;
     Seg[2].x0 = 1;
     Seg[2].x1 = 1E22F;
 
@@ -4530,10 +4639,10 @@ cmsInt32Number CheckMPE(cmsInt32Number Pass,  cmsHPROFILE hProfile, cmsTagSignat
 
     switch (Pass) {
 
-        case 1: 
+        case 1:
 
             Lut = cmsPipelineAlloc(DbgThread(), 3, 3);
-            
+
             cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocLabV2ToV4(DbgThread()));
             cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV4ToV2(DbgThread()));
             AddIdentityCLUTfloat(Lut);
@@ -4541,14 +4650,14 @@ cmsInt32Number CheckMPE(cmsInt32Number Pass,  cmsHPROFILE hProfile, cmsTagSignat
             G[0] = G[1] = G[2] = CreateSegmentedCurve();
             cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocToneCurves(DbgThread(), 3, G));
             cmsFreeToneCurve(G[0]);
-            
+
             rc = cmsWriteTag(hProfile, tag, Lut);
             cmsPipelineFree(Lut);
             return rc;
-            
+
         case 2:
             Pt = cmsReadTag(hProfile, tag);
-            if (Pt == NULL) return 0;           
+            if (Pt == NULL) return 0;
             return CheckFloatLUT(Pt);
 
         default:
@@ -4562,11 +4671,11 @@ cmsInt32Number CheckScreening(cmsInt32Number Pass,  cmsHPROFILE hProfile, cmsTag
 {
     cmsScreening *Pt, sc;
     cmsInt32Number rc;
-    
+
     switch (Pass) {
 
-        case 1:         
-            
+        case 1:
+
             sc.Flag = 0;
             sc.nChannels = 1;
             sc.Channels[0].Frequency = 2.0;
@@ -4575,7 +4684,7 @@ cmsInt32Number CheckScreening(cmsInt32Number Pass,  cmsHPROFILE hProfile, cmsTag
 
             rc = cmsWriteTag(hProfile, tag, &sc);
             return rc;
-            
+
 
         case 2:
             Pt = cmsReadTag(hProfile, tag);
@@ -4599,12 +4708,12 @@ cmsBool CheckOneStr(cmsMLU* mlu, cmsInt32Number n)
 {
     char Buffer[256], Buffer2[256];
 
-    
+
     cmsMLUgetASCII(mlu, "en", "US", Buffer, 255);
     sprintf(Buffer2, "Hello, world %d", n);
     if (strcmp(Buffer, Buffer2) != 0) return FALSE;
 
-  
+
     cmsMLUgetASCII(mlu, "es", "ES", Buffer, 255);
     sprintf(Buffer2, "Hola, mundo %d", n);
     if (strcmp(Buffer, Buffer2) != 0) return FALSE;
@@ -4664,7 +4773,7 @@ cmsInt32Number CheckProfileSequenceTag(cmsInt32Number Pass,  cmsHPROFILE hProfil
         s ->seq[2].attributes = cmsTransparency|cmsGlossy;
 #endif
 
-        if (!cmsWriteTag(hProfile, cmsSigProfileSequenceDescTag, s)) return 0;    
+        if (!cmsWriteTag(hProfile, cmsSigProfileSequenceDescTag, s)) return 0;
         cmsFreeProfileSequenceDescription(s);
         return 1;
 
@@ -4732,7 +4841,7 @@ cmsInt32Number CheckProfileSequenceIDTag(cmsInt32Number Pass,  cmsHPROFILE hProf
         SetOneStr(&s -> seq[1].Description, L"Hello, world 1", L"Hola, mundo 1");
         SetOneStr(&s -> seq[2].Description, L"Hello, world 2", L"Hola, mundo 2");
 
-        if (!cmsWriteTag(hProfile, cmsSigProfileSequenceIdTag, s)) return 0;    
+        if (!cmsWriteTag(hProfile, cmsSigProfileSequenceIdTag, s)) return 0;
         cmsFreeProfileSequenceDescription(s);
         return 1;
 
@@ -4768,7 +4877,7 @@ cmsInt32Number CheckICCViewingConditions(cmsInt32Number Pass,  cmsHPROFILE hProf
 
     switch (Pass) {
 
-        case 1:         
+        case 1:
             s.IlluminantType = 1;
             s.IlluminantXYZ.X = 0.1;
             s.IlluminantXYZ.Y = 0.2;
@@ -4777,7 +4886,7 @@ cmsInt32Number CheckICCViewingConditions(cmsInt32Number Pass,  cmsHPROFILE hProf
             s.SurroundXYZ.Y = 0.5;
             s.SurroundXYZ.Z = 0.6;
 
-            if (!cmsWriteTag(hProfile, cmsSigViewingConditionsTag, &s)) return 0;    
+            if (!cmsWriteTag(hProfile, cmsSigViewingConditionsTag, &s)) return 0;
             return 1;
 
         case 2:
@@ -4807,15 +4916,15 @@ cmsInt32Number CheckVCGT(cmsInt32Number Pass,  cmsHPROFILE hProfile)
 {
     cmsToneCurve* Curves[3];
     cmsToneCurve** PtrCurve;
-    
+
      switch (Pass) {
 
-        case 1:     
+        case 1:
             Curves[0] = cmsBuildGamma(DbgThread(), 1.1);
             Curves[1] = cmsBuildGamma(DbgThread(), 2.2);
             Curves[2] = cmsBuildGamma(DbgThread(), 3.4);
 
-            if (!cmsWriteTag(hProfile, cmsSigVcgtTag, Curves)) return 0;    
+            if (!cmsWriteTag(hProfile, cmsSigVcgtTag, Curves)) return 0;
 
             cmsFreeToneCurveTriple(Curves);
             return 1;
@@ -4845,13 +4954,13 @@ cmsInt32Number CheckDictionary16(cmsInt32Number Pass,  cmsHPROFILE hProfile)
       const cmsDICTentry* e;
       switch (Pass) {
 
-        case 1:     
+        case 1:
             hDict = cmsDictAlloc(DbgThread());
             cmsDictAddEntry(hDict, L"Name0",  NULL, NULL, NULL);
             cmsDictAddEntry(hDict, L"Name1",  L"", NULL, NULL);
             cmsDictAddEntry(hDict, L"Name",  L"String", NULL, NULL);
             cmsDictAddEntry(hDict, L"Name2", L"12",    NULL, NULL);
-            if (!cmsWriteTag(hProfile, cmsSigMetaTag, hDict)) return 0;    
+            if (!cmsWriteTag(hProfile, cmsSigMetaTag, hDict)) return 0;
             cmsDictFree(hDict);
             return 1;
 
@@ -4863,14 +4972,14 @@ cmsInt32Number CheckDictionary16(cmsInt32Number Pass,  cmsHPROFILE hProfile)
              e = cmsDictGetEntryList(hDict);
              if (memcmp(e ->Name, L"Name2", sizeof(wchar_t) * 5) != 0) return 0;
              if (memcmp(e ->Value, L"12",  sizeof(wchar_t) * 2) != 0) return 0;
-             e = cmsDictNextEntry(e);         
+             e = cmsDictNextEntry(e);
              if (memcmp(e ->Name, L"Name", sizeof(wchar_t) * 4) != 0) return 0;
              if (memcmp(e ->Value, L"String",  sizeof(wchar_t) * 5) != 0) return 0;
-             e = cmsDictNextEntry(e);         
+             e = cmsDictNextEntry(e);
              if (memcmp(e ->Name, L"Name1", sizeof(wchar_t) *5) != 0) return 0;
              if (e ->Value == NULL) return 0;
              if (*e->Value != 0) return 0;
-             e = cmsDictNextEntry(e);         
+             e = cmsDictNextEntry(e);
              if (memcmp(e ->Name, L"Name0", sizeof(wchar_t) * 5) != 0) return 0;
              if (e ->Value != NULL) return 0;
              return 1;
@@ -4892,13 +5001,13 @@ cmsInt32Number CheckDictionary24(cmsInt32Number Pass,  cmsHPROFILE hProfile)
     cmsMLU* DisplayName;
     char Buffer[256];
     cmsInt32Number rc = 1;
-    
+
     switch (Pass) {
 
-    case 1:     
+    case 1:
         hDict = cmsDictAlloc(DbgThread());
 
-        DisplayName = cmsMLUalloc(DbgThread(), 0);    
+        DisplayName = cmsMLUalloc(DbgThread(), 0);
 
         cmsMLUsetWide(DisplayName, "en", "US", L"Hello, world");
         cmsMLUsetWide(DisplayName, "es", "ES", L"Hola, mundo");
@@ -4909,9 +5018,9 @@ cmsInt32Number CheckDictionary24(cmsInt32Number Pass,  cmsHPROFILE hProfile)
         cmsMLUfree(DisplayName);
 
         cmsDictAddEntry(hDict, L"Name2", L"12",    NULL, NULL);
-        if (!cmsWriteTag(hProfile, cmsSigMetaTag, hDict)) return 0;    
+        if (!cmsWriteTag(hProfile, cmsSigMetaTag, hDict)) return 0;
         cmsDictFree(hDict);
-        
+
         return 1;
 
 
@@ -4923,9 +5032,9 @@ cmsInt32Number CheckDictionary24(cmsInt32Number Pass,  cmsHPROFILE hProfile)
         e = cmsDictGetEntryList(hDict);
         if (memcmp(e ->Name, L"Name2", sizeof(wchar_t) * 5) != 0) return 0;
         if (memcmp(e ->Value, L"12",  sizeof(wchar_t) * 2) != 0) return 0;
-        e = cmsDictNextEntry(e);         
+        e = cmsDictNextEntry(e);
         if (memcmp(e ->Name, L"Name", sizeof(wchar_t) * 4) != 0) return 0;
-        if (memcmp(e ->Value, L"String",  sizeof(wchar_t) * 5) != 0) return 0;  
+        if (memcmp(e ->Value, L"String",  sizeof(wchar_t) * 5) != 0) return 0;
 
         cmsMLUgetASCII(e->DisplayName, "en", "US", Buffer, 256);
         if (strcmp(Buffer, "Hello, world") != 0) rc = 0;
@@ -4959,7 +5068,7 @@ cmsInt32Number CheckRAWtags(cmsInt32Number Pass,  cmsHPROFILE hProfile)
 
     switch (Pass) {
 
-        case 1:         
+        case 1:
             return cmsWriteRawTag(hProfile, 0x31323334, "data123", 7);
 
         case 2:
@@ -5012,12 +5121,12 @@ cmsInt32Number CheckProfileCreation(void)
         if (!CheckXYZ(Pass, h, cmsSigLuminanceTag)) return 0;
 
         SubTest("Tags holding curves");
-        
+
         if (!CheckGamma(Pass, h, cmsSigBlueTRCTag)) return 0;
         if (!CheckGamma(Pass, h, cmsSigGrayTRCTag)) return 0;
         if (!CheckGamma(Pass, h, cmsSigGreenTRCTag)) return 0;
         if (!CheckGamma(Pass, h, cmsSigRedTRCTag)) return 0;
-        
+
         SubTest("Tags holding text");
 
         if (!CheckText(Pass, h, cmsSigCharTargetTag)) return 0;
@@ -5067,7 +5176,7 @@ cmsInt32Number CheckProfileCreation(void)
         if (!CheckLUT(Pass, h, cmsSigPreview1Tag)) return 0;
         if (!CheckLUT(Pass, h, cmsSigPreview2Tag)) return 0;
         if (!CheckLUT(Pass, h, cmsSigGamutTag)) return 0;
-        
+
         SubTest("Tags holding CHAD");
         if (!CheckCHAD(Pass, h, cmsSigChromaticAdaptationTag)) return 0;
 
@@ -5095,7 +5204,7 @@ cmsInt32Number CheckProfileCreation(void)
         if (!CheckMPE(Pass, h, cmsSigBToD1Tag)) return 0;
         if (!CheckMPE(Pass, h, cmsSigBToD2Tag)) return 0;
         if (!CheckMPE(Pass, h, cmsSigBToD3Tag)) return 0;
-        
+
         SubTest("Tags using screening");
         if (!CheckScreening(Pass, h, cmsSigScreeningTag)) return 0;
 
@@ -5125,15 +5234,15 @@ cmsInt32Number CheckProfileCreation(void)
 
     }
 
-    /*    
+    /*
     Not implemented (by design):
 
-    cmsSigDataTag                           = 0x64617461,  // 'data'  -- Unused   
+    cmsSigDataTag                           = 0x64617461,  // 'data'  -- Unused
     cmsSigDeviceSettingsTag                 = 0x64657673,  // 'devs'  -- Unused
     cmsSigNamedColorTag                     = 0x6E636f6C,  // 'ncol'  -- Don't use this one, deprecated by ICC
-    cmsSigOutputResponseTag                 = 0x72657370,  // 'resp'  -- Possible patent on this 
+    cmsSigOutputResponseTag                 = 0x72657370,  // 'resp'  -- Possible patent on this
     */
-    
+
     cmsCloseProfile(h);
     remove("alltags.icc");
     return 1;
@@ -5148,7 +5257,10 @@ void ErrorReportingFunction(cmsContext ContextID, cmsUInt32Number ErrorCode, con
 {
     TrappedError = TRUE;
     SimultaneousErrors++;
-    strncpy(ReasonToFailBuffer, Text, TEXT_ERROR_BUFFER_SIZE-1);    
+    strncpy(ReasonToFailBuffer, Text, TEXT_ERROR_BUFFER_SIZE-1);
+
+    cmsUNUSED_PARAMETER(ContextID);
+    cmsUNUSED_PARAMETER(ErrorCode);
 }
 
 
@@ -5175,13 +5287,13 @@ cmsInt32Number CheckBadProfiles(void)
         cmsCloseProfile(h);
         return 0;
     }
-    
+
     h = cmsOpenProfileFromFileTHR(DbgThread(), "..", "r");
     if (h != NULL) {
         cmsCloseProfile(h);
         return 0;
     }
-    
+
     h = cmsOpenProfileFromFileTHR(DbgThread(), "IHaveBadAccessMode.icc", "@");
     if (h != NULL) {
         cmsCloseProfile(h);
@@ -5212,8 +5324,8 @@ cmsInt32Number CheckBadProfiles(void)
         return 0;
     }
 
-    if (SimultaneousErrors != 9) return 0;      
-    
+    if (SimultaneousErrors != 9) return 0;
+
     return 1;
 }
 
@@ -5245,7 +5357,7 @@ cmsInt32Number CheckBadTransforms(void)
         return 0;
     }
 
-    
+
 
     x1 = cmsCreateTransform(h1, TYPE_RGB_8, h1, TYPE_RGB_8, 12345, 0);
     if (x1 != NULL) {
@@ -5320,12 +5432,12 @@ cmsInt32Number Check8linearXFORM(cmsHTRANSFORM xform, cmsInt32Number nChan)
     cmsUInt8Number Inw[cmsMAXCHANNELS], Outw[cmsMAXCHANNELS];
 
     n2=0;
-    
+
     for (j=0; j < 0xFF; j++) {
-        
+
         memset(Inw, j, sizeof(Inw));
         cmsDoTransform(xform, Inw, Outw, 1);
-        
+
         for (i=0; i < nChan; i++) {
 
            cmsInt32Number dif = abs(Outw[i] - j);
@@ -5334,13 +5446,13 @@ cmsInt32Number Check8linearXFORM(cmsHTRANSFORM xform, cmsInt32Number nChan)
         }
     }
 
-   // We allow 2 contone of difference on 8 bits 
+   // We allow 2 contone of difference on 8 bits
     if (n2 > 2) {
 
         Fail("Differences too big (%x)", n2);
         return 0;
     }
-    
+
     return 1;
 }
 
@@ -5351,9 +5463,9 @@ cmsInt32Number Compare8bitXFORM(cmsHTRANSFORM xform1, cmsHTRANSFORM xform2, cmsI
     cmsUInt8Number Inw[cmsMAXCHANNELS], Outw1[cmsMAXCHANNELS], Outw2[cmsMAXCHANNELS];;
 
     n2=0;
-    
+
     for (j=0; j < 0xFF; j++) {
-        
+
         memset(Inw, j, sizeof(Inw));
         cmsDoTransform(xform1, Inw, Outw1, 1);
         cmsDoTransform(xform2, Inw, Outw2, 1);
@@ -5366,14 +5478,14 @@ cmsInt32Number Compare8bitXFORM(cmsHTRANSFORM xform1, cmsHTRANSFORM xform2, cmsI
         }
     }
 
-   // We allow 2 contone of difference on 8 bits 
+   // We allow 2 contone of difference on 8 bits
     if (n2 > 2) {
 
         Fail("Differences too big (%x)", n2);
         return 0;
     }
 
-    
+
     return 1;
 }
 
@@ -5385,20 +5497,20 @@ cmsInt32Number Check16linearXFORM(cmsHTRANSFORM xform, cmsInt32Number nChan)
     cmsInt32Number n2, i, j;
     cmsUInt16Number Inw[cmsMAXCHANNELS], Outw[cmsMAXCHANNELS];
 
-    n2=0;    
+    n2=0;
     for (j=0; j < 0xFFFF; j++) {
 
         for (i=0; i < nChan; i++) Inw[i] = (cmsUInt16Number) j;
 
         cmsDoTransform(xform, Inw, Outw, 1);
-        
+
         for (i=0; i < nChan; i++) {
 
            cmsInt32Number dif = abs(Outw[i] - j);
            if (dif > n2) n2 = dif;
 
         }
-    
+
 
    // We allow 2 contone of difference on 16 bits
     if (n2 > 0x200) {
@@ -5407,7 +5519,7 @@ cmsInt32Number Check16linearXFORM(cmsHTRANSFORM xform, cmsInt32Number nChan)
         return 0;
     }
     }
-    
+
     return 1;
 }
 
@@ -5418,9 +5530,9 @@ cmsInt32Number Compare16bitXFORM(cmsHTRANSFORM xform1, cmsHTRANSFORM xform2, cms
     cmsUInt16Number Inw[cmsMAXCHANNELS], Outw1[cmsMAXCHANNELS], Outw2[cmsMAXCHANNELS];;
 
     n2=0;
-    
+
     for (j=0; j < 0xFFFF; j++) {
-        
+
         for (i=0; i < nChan; i++) Inw[i] = (cmsUInt16Number) j;
 
         cmsDoTransform(xform1, Inw, Outw1, 1);
@@ -5434,14 +5546,14 @@ cmsInt32Number Compare16bitXFORM(cmsHTRANSFORM xform1, cmsHTRANSFORM xform2, cms
         }
     }
 
-   // We allow 2 contone of difference on 16 bits 
+   // We allow 2 contone of difference on 16 bits
     if (n2 > 0x200) {
 
         Fail("Differences too big (%x)", n2);
         return 0;
     }
 
-    
+
     return 1;
 }
 
@@ -5454,21 +5566,21 @@ cmsInt32Number CheckFloatlinearXFORM(cmsHTRANSFORM xform, cmsInt32Number nChan)
     cmsFloat32Number In[cmsMAXCHANNELS], Out[cmsMAXCHANNELS];
 
     n2=0;
-    
+
     for (j=0; j < 0xFFFF; j++) {
 
         for (i=0; i < nChan; i++) In[i] = (cmsFloat32Number) (j / 65535.0);;
 
         cmsDoTransform(xform, In, Out, 1);
-        
+
         for (i=0; i < nChan; i++) {
 
            // We allow no difference in floating point
-            if (!IsGoodFixed15_16("linear xform cmsFloat32Number", Out[i], (cmsFloat32Number) (j / 65535.0))) 
+            if (!IsGoodFixed15_16("linear xform cmsFloat32Number", Out[i], (cmsFloat32Number) (j / 65535.0)))
                 return 0;
-        }        
+        }
     }
-    
+
     return 1;
 }
 
@@ -5481,7 +5593,7 @@ cmsInt32Number CompareFloatXFORM(cmsHTRANSFORM xform1, cmsHTRANSFORM xform2, cms
     cmsFloat32Number In[cmsMAXCHANNELS], Out1[cmsMAXCHANNELS], Out2[cmsMAXCHANNELS];
 
     n2=0;
-    
+
     for (j=0; j < 0xFFFF; j++) {
 
         for (i=0; i < nChan; i++) In[i] = (cmsFloat32Number) (j / 65535.0);;
@@ -5492,12 +5604,12 @@ cmsInt32Number CompareFloatXFORM(cmsHTRANSFORM xform1, cmsHTRANSFORM xform2, cms
         for (i=0; i < nChan; i++) {
 
            // We allow no difference in floating point
-            if (!IsGoodFixed15_16("linear xform cmsFloat32Number", Out1[i], Out2[i])) 
+            if (!IsGoodFixed15_16("linear xform cmsFloat32Number", Out1[i], Out2[i]))
                 return 0;
         }
-        
+
     }
-    
+
     return 1;
 }
 
@@ -5516,42 +5628,42 @@ cmsInt32Number CheckCurvesOnlyTransforms(void)
 
     c1 = cmsBuildGamma(DbgThread(), 2.2);
     c2 = cmsBuildGamma(DbgThread(), 1/2.2);
-    c3 = cmsBuildGamma(DbgThread(), 4.84);    
+    c3 = cmsBuildGamma(DbgThread(), 4.84);
 
     h1 = cmsCreateLinearizationDeviceLinkTHR(DbgThread(), cmsSigGrayData, &c1);
     h2 = cmsCreateLinearizationDeviceLinkTHR(DbgThread(), cmsSigGrayData, &c2);
     h3 = cmsCreateLinearizationDeviceLinkTHR(DbgThread(), cmsSigGrayData, &c3);
 
     SubTest("Gray float optimizeable transform");
-    xform1 = cmsCreateTransform(h1, TYPE_GRAY_FLT, h2, TYPE_GRAY_FLT, INTENT_PERCEPTUAL, 0);    
+    xform1 = cmsCreateTransform(h1, TYPE_GRAY_FLT, h2, TYPE_GRAY_FLT, INTENT_PERCEPTUAL, 0);
     rc &= CheckFloatlinearXFORM(xform1, 1);
     cmsDeleteTransform(xform1);
     if (rc == 0) goto Error;
-    
+
     SubTest("Gray 8 optimizeable transform");
-    xform1 = cmsCreateTransform(h1, TYPE_GRAY_8, h2, TYPE_GRAY_8, INTENT_PERCEPTUAL, 0);    
+    xform1 = cmsCreateTransform(h1, TYPE_GRAY_8, h2, TYPE_GRAY_8, INTENT_PERCEPTUAL, 0);
     rc &= Check8linearXFORM(xform1, 1);
     cmsDeleteTransform(xform1);
     if (rc == 0) goto Error;
-    
+
     SubTest("Gray 16 optimizeable transform");
-    xform1 = cmsCreateTransform(h1, TYPE_GRAY_16, h2, TYPE_GRAY_16, INTENT_PERCEPTUAL, 0);  
+    xform1 = cmsCreateTransform(h1, TYPE_GRAY_16, h2, TYPE_GRAY_16, INTENT_PERCEPTUAL, 0);
     rc &= Check16linearXFORM(xform1, 1);
     cmsDeleteTransform(xform1);
     if (rc == 0) goto Error;
 
     SubTest("Gray float non-optimizeable transform");
-    xform1 = cmsCreateTransform(h1, TYPE_GRAY_FLT, h1, TYPE_GRAY_FLT, INTENT_PERCEPTUAL, 0);    
-    xform2 = cmsCreateTransform(h3, TYPE_GRAY_FLT, NULL, TYPE_GRAY_FLT, INTENT_PERCEPTUAL, 0);  
+    xform1 = cmsCreateTransform(h1, TYPE_GRAY_FLT, h1, TYPE_GRAY_FLT, INTENT_PERCEPTUAL, 0);
+    xform2 = cmsCreateTransform(h3, TYPE_GRAY_FLT, NULL, TYPE_GRAY_FLT, INTENT_PERCEPTUAL, 0);
 
     rc &= CompareFloatXFORM(xform1, xform2, 1);
     cmsDeleteTransform(xform1);
     cmsDeleteTransform(xform2);
     if (rc == 0) goto Error;
-    
+
     SubTest("Gray 8 non-optimizeable transform");
-    xform1 = cmsCreateTransform(h1, TYPE_GRAY_8, h1, TYPE_GRAY_8, INTENT_PERCEPTUAL, 0);    
-    xform2 = cmsCreateTransform(h3, TYPE_GRAY_8, NULL, TYPE_GRAY_8, INTENT_PERCEPTUAL, 0);  
+    xform1 = cmsCreateTransform(h1, TYPE_GRAY_8, h1, TYPE_GRAY_8, INTENT_PERCEPTUAL, 0);
+    xform2 = cmsCreateTransform(h3, TYPE_GRAY_8, NULL, TYPE_GRAY_8, INTENT_PERCEPTUAL, 0);
 
     rc &= Compare8bitXFORM(xform1, xform2, 1);
     cmsDeleteTransform(xform1);
@@ -5560,8 +5672,8 @@ cmsInt32Number CheckCurvesOnlyTransforms(void)
 
 
     SubTest("Gray 16 non-optimizeable transform");
-    xform1 = cmsCreateTransform(h1, TYPE_GRAY_16, h1, TYPE_GRAY_16, INTENT_PERCEPTUAL, 0);  
-    xform2 = cmsCreateTransform(h3, TYPE_GRAY_16, NULL, TYPE_GRAY_16, INTENT_PERCEPTUAL, 0);    
+    xform1 = cmsCreateTransform(h1, TYPE_GRAY_16, h1, TYPE_GRAY_16, INTENT_PERCEPTUAL, 0);
+    xform2 = cmsCreateTransform(h3, TYPE_GRAY_16, NULL, TYPE_GRAY_16, INTENT_PERCEPTUAL, 0);
 
     rc &= Compare16bitXFORM(xform1, xform2, 1);
     cmsDeleteTransform(xform1);
@@ -5572,10 +5684,10 @@ Error:
 
     cmsCloseProfile(h1); cmsCloseProfile(h2); cmsCloseProfile(h3);
     cmsFreeToneCurve(c1); cmsFreeToneCurve(c2); cmsFreeToneCurve(c3);
-    
+
     return rc;
 }
-    
+
 
 
 // Lab to Lab trivial transforms ----------------------------------------------------------------------------------------
@@ -5592,7 +5704,7 @@ cmsInt32Number CheckOneLab(cmsHTRANSFORM xform, cmsFloat64Number L, cmsFloat64Nu
     cmsDoTransform(xform, &In, &Out, 1);
 
     dE = cmsDeltaE(&In, &Out);
-    
+
     if (dE > MaxDE) MaxDE = dE;
 
     if (MaxDE >  0.003) {
@@ -5612,13 +5724,13 @@ cmsInt32Number CheckSeveralLab(cmsHTRANSFORM xform)
 
     MaxDE = 0;
     for (L=0; L < 65536; L += 1311) {
-    
+
         for (a = 0; a < 65536; a += 1232) {
 
             for (b = 0; b < 65536; b += 1111) {
 
-                if (!CheckOneLab(xform, (L * 100.0) / 65535.0, 
-                                        (a  / 257.0) - 128, (b / 257.0) - 128)) 
+                if (!CheckOneLab(xform, (L * 100.0) / 65535.0,
+                                        (a  / 257.0) - 128, (b / 257.0) - 128))
                     return 0;
             }
 
@@ -5631,7 +5743,7 @@ cmsInt32Number CheckSeveralLab(cmsHTRANSFORM xform)
 
 static
 cmsInt32Number OneTrivialLab(cmsHPROFILE hLab1, cmsHPROFILE hLab2, const char* txt)
-{   
+{
     cmsHTRANSFORM xform;
     cmsInt32Number rc;
 
@@ -5664,7 +5776,7 @@ cmsInt32Number CheckEncodedLabTransforms(void)
     cmsCIELab White = { 100, 0, 0 };
     cmsHPROFILE hLab1 = cmsCreateLab4ProfileTHR(DbgThread(), NULL);
     cmsHPROFILE hLab2 = cmsCreateLab4ProfileTHR(DbgThread(), NULL);
-  
+
 
     xform = cmsCreateTransformTHR(DbgThread(), hLab1, TYPE_Lab_16, hLab2, TYPE_Lab_DBL, INTENT_RELATIVE_COLORIMETRIC, 0);
     cmsCloseProfile(hLab1); cmsCloseProfile(hLab2);
@@ -5729,7 +5841,7 @@ cmsInt32Number CheckEncodedLabTransforms(void)
         In[2] != 0x8080) return 0;
 
     cmsDeleteTransform(xform);
-   
+
     return 1;
 }
 
@@ -5742,7 +5854,7 @@ cmsInt32Number CheckStoredIdentities(void)
 
     hLab  = cmsCreateLab4ProfileTHR(DbgThread(), NULL);
     xform = cmsCreateTransformTHR(DbgThread(), hLab, TYPE_Lab_8, hLab, TYPE_Lab_8, 0, 0);
-    
+
     hLink = cmsTransform2DeviceLink(xform, 3.4, 0);
     cmsSaveProfileToFile(hLink, "abstractv2.icc");
     cmsCloseProfile(hLink);
@@ -5760,12 +5872,12 @@ cmsInt32Number CheckStoredIdentities(void)
 
     SubTest("V4");
     rc &= CheckSeveralLab(xform);
-    
+
     cmsDeleteTransform(xform);
     cmsCloseProfile(h4);
     if (!rc) goto Error;
 
-    
+
     SubTest("V2");
     h2 = cmsOpenProfileFromFileTHR(DbgThread(), "abstractv2.icc", "r");
 
@@ -5826,13 +5938,13 @@ cmsInt32Number CheckMatrixShaperXFORMFloat(void)
     cmsDeleteTransform(xform);
 
 
-    return rc1 && rc2;  
+    return rc1 && rc2;
 }
 
 // Check a simple xform from a matrix profile to itself. Test 16 bits accuracy.
 static
 cmsInt32Number CheckMatrixShaperXFORM16(void)
-{   
+{
     cmsHPROFILE hAbove, hSRGB;
     cmsHTRANSFORM xform;
     cmsInt32Number rc1, rc2;
@@ -5850,7 +5962,7 @@ cmsInt32Number CheckMatrixShaperXFORM16(void)
     rc2 = Check16linearXFORM(xform, 3);
     cmsDeleteTransform(xform);
 
-    return rc1 && rc2;  
+    return rc1 && rc2;
 
 }
 
@@ -5858,7 +5970,7 @@ cmsInt32Number CheckMatrixShaperXFORM16(void)
 // Check a simple xform from a matrix profile to itself. Test 8 bits accuracy.
 static
 cmsInt32Number CheckMatrixShaperXFORM8(void)
-{   
+{
     cmsHPROFILE hAbove, hSRGB;
     cmsHTRANSFORM xform;
     cmsInt32Number rc1, rc2;
@@ -5876,7 +5988,7 @@ cmsInt32Number CheckMatrixShaperXFORM8(void)
     cmsDeleteTransform(xform);
 
 
-    return rc1 && rc2;  
+    return rc1 && rc2;
 }
 
 
@@ -5931,13 +6043,13 @@ cmsInt32Number Chack_sRGB_Float(void)
 
     MaxErr = 0;
 
-    // Xform 1 goes from 8 bits to XYZ,  
+    // Xform 1 goes from 8 bits to XYZ,
     rc  = CheckOneRGB_f(xform1, 1, 1, 1,        0.0002926, 0.00030352, 0.00025037, 0.0001);
     rc  &= CheckOneRGB_f(xform1, 127, 127, 127, 0.2046329, 0.212230,   0.175069,   0.0001);
     rc  &= CheckOneRGB_f(xform1, 12, 13, 15,    0.0038364, 0.0039928,  0.00385212, 0.0001);
     rc  &= CheckOneRGB_f(xform1, 128, 0, 0,     0.0940846, 0.0480030,  0.00300543, 0.0001);
     rc  &= CheckOneRGB_f(xform1, 190, 25, 210,  0.3203491, 0.1605240,  0.46817115, 0.0001);
-    
+
     // Xform 2 goes from 8 bits to Lab, we allow 0.01 error max
     rc  &= CheckOneRGB_f(xform2, 1, 1, 1,       0.2741748, 0, 0,                  0.01);
     rc  &= CheckOneRGB_f(xform2, 127, 127, 127, 53.192776, 0, 0,                  0.01);
@@ -5946,7 +6058,7 @@ cmsInt32Number Chack_sRGB_Float(void)
 
     cmsDeleteTransform(xform1);
     cmsDeleteTransform(xform2);
-    return rc;  
+    return rc;
 }
 
 
@@ -6004,9 +6116,9 @@ int CheckRGBPrimaries(void)
 
     if (!IsGoodFixed15_16("xRed", tripxyY.Red.x, 0.64) ||
         !IsGoodFixed15_16("yRed", tripxyY.Red.y, 0.33) ||
-        !IsGoodFixed15_16("xGreen", tripxyY.Green.x, 0.30) || 
+        !IsGoodFixed15_16("xGreen", tripxyY.Green.x, 0.30) ||
         !IsGoodFixed15_16("yGreen", tripxyY.Green.y, 0.60) ||
-        !IsGoodFixed15_16("xBlue", tripxyY.Blue.x, 0.15) || 
+        !IsGoodFixed15_16("xBlue", tripxyY.Blue.x, 0.15) ||
         !IsGoodFixed15_16("yBlue", tripxyY.Blue.y, 0.06)) {
             Fail("One or more primaries are wrong.");
             return FALSE;
@@ -6234,7 +6346,7 @@ cmsInt32Number CheckKPlaneBlackPreserving(void)
 
 
     cmsDeleteTransform(xform);
-    
+
     xform = cmsCreateTransformTHR(DbgThread(),  hFOGRA, TYPE_CMYK_FLT, hSWOP, TYPE_CMYK_FLT, INTENT_PRESERVE_K_PLANE_PERCEPTUAL, 0);
 
     for (i=0; i <= 100; i++) {
@@ -6251,16 +6363,16 @@ cmsInt32Number CheckKPlaneBlackPreserving(void)
 
         if (DeltaE > Max) Max = DeltaE;
     }
-    
+
     cmsDeleteTransform(xform);
-    
-    
+
+
 
     cmsCloseProfile(hSWOP);
     cmsCloseProfile(hFOGRA);
     cmsCloseProfile(hLab);
 
-    
+
     cmsDeleteTransform(swop_lab);
     cmsDeleteTransform(fogra_lab);
 
@@ -6279,12 +6391,12 @@ cmsInt32Number CheckProofingXFORMFloat(void)
     cmsInt32Number rc;
 
     hAbove = Create_AboveRGB();
-    xform =  cmsCreateProofingTransformTHR(DbgThread(), hAbove, TYPE_RGB_FLT, hAbove, TYPE_RGB_FLT, hAbove, 
+    xform =  cmsCreateProofingTransformTHR(DbgThread(), hAbove, TYPE_RGB_FLT, hAbove, TYPE_RGB_FLT, hAbove,
                                 INTENT_RELATIVE_COLORIMETRIC, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_SOFTPROOFING);
     cmsCloseProfile(hAbove);
     rc = CheckFloatlinearXFORM(xform, 3);
     cmsDeleteTransform(xform);
-    return rc;  
+    return rc;
 }
 
 static
@@ -6295,12 +6407,12 @@ cmsInt32Number CheckProofingXFORM16(void)
     cmsInt32Number rc;
 
     hAbove = Create_AboveRGB();
-    xform =  cmsCreateProofingTransformTHR(DbgThread(), hAbove, TYPE_RGB_16, hAbove, TYPE_RGB_16, hAbove, 
+    xform =  cmsCreateProofingTransformTHR(DbgThread(), hAbove, TYPE_RGB_16, hAbove, TYPE_RGB_16, hAbove,
                                 INTENT_RELATIVE_COLORIMETRIC, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_SOFTPROOFING|cmsFLAGS_NOCACHE);
     cmsCloseProfile(hAbove);
     rc = Check16linearXFORM(xform, 3);
     cmsDeleteTransform(xform);
-    return rc;  
+    return rc;
 }
 
 
@@ -6324,7 +6436,7 @@ cmsInt32Number CheckGamutCheck(void)
         SubTest("Gamut check on floating point");
 
         // Create a gamut checker in the same space. No value should be out of gamut
-        xform = cmsCreateProofingTransformTHR(DbgThread(), hAbove, TYPE_RGB_FLT, hAbove, TYPE_RGB_FLT, hAbove, 
+        xform = cmsCreateProofingTransformTHR(DbgThread(), hAbove, TYPE_RGB_FLT, hAbove, TYPE_RGB_FLT, hAbove,
                                 INTENT_RELATIVE_COLORIMETRIC, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_GAMUTCHECK);
 
 
@@ -6340,7 +6452,7 @@ cmsInt32Number CheckGamutCheck(void)
 
         SubTest("Gamut check on 16 bits");
 
-        xform = cmsCreateProofingTransformTHR(DbgThread(), hAbove, TYPE_RGB_16, hAbove, TYPE_RGB_16, hAbove, 
+        xform = cmsCreateProofingTransformTHR(DbgThread(), hAbove, TYPE_RGB_16, hAbove, TYPE_RGB_16, hAbove,
                                 INTENT_RELATIVE_COLORIMETRIC, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_GAMUTCHECK);
 
         cmsCloseProfile(hSRGB);
@@ -6364,28 +6476,28 @@ cmsInt32Number CheckBlackPoint(void)
     cmsCIEXYZ Black;
     cmsCIELab Lab;
 
-    hProfile  = cmsOpenProfileFromFileTHR(DbgThread(), "test5.icc", "r");  
-    cmsDetectBlackPoint(&Black, hProfile, INTENT_RELATIVE_COLORIMETRIC, 0);
+    hProfile  = cmsOpenProfileFromFileTHR(DbgThread(), "test5.icc", "r");
+    cmsDetectDestinationBlackPoint(&Black, hProfile, INTENT_RELATIVE_COLORIMETRIC, 0);
     cmsCloseProfile(hProfile);
 
 
     hProfile = cmsOpenProfileFromFileTHR(DbgThread(), "test1.icc", "r");
-    cmsDetectBlackPoint(&Black, hProfile, INTENT_RELATIVE_COLORIMETRIC, 0);
+    cmsDetectDestinationBlackPoint(&Black, hProfile, INTENT_RELATIVE_COLORIMETRIC, 0);
     cmsXYZ2Lab(NULL, &Lab, &Black);
     cmsCloseProfile(hProfile);
 
     hProfile = cmsOpenProfileFromFileTHR(DbgThread(), "lcms2cmyk.icc", "r");
-    cmsDetectBlackPoint(&Black, hProfile, INTENT_RELATIVE_COLORIMETRIC, 0);
+    cmsDetectDestinationBlackPoint(&Black, hProfile, INTENT_RELATIVE_COLORIMETRIC, 0);
     cmsXYZ2Lab(NULL, &Lab, &Black);
     cmsCloseProfile(hProfile);
 
     hProfile = cmsOpenProfileFromFileTHR(DbgThread(), "test2.icc", "r");
-    cmsDetectBlackPoint(&Black, hProfile, INTENT_RELATIVE_COLORIMETRIC, 0);
+    cmsDetectDestinationBlackPoint(&Black, hProfile, INTENT_RELATIVE_COLORIMETRIC, 0);
     cmsXYZ2Lab(NULL, &Lab, &Black);
     cmsCloseProfile(hProfile);
 
     hProfile = cmsOpenProfileFromFileTHR(DbgThread(), "test1.icc", "r");
-    cmsDetectBlackPoint(&Black, hProfile, INTENT_PERCEPTUAL, 0);
+    cmsDetectDestinationBlackPoint(&Black, hProfile, INTENT_PERCEPTUAL, 0);
     cmsXYZ2Lab(NULL, &Lab, &Black);
     cmsCloseProfile(hProfile);
 
@@ -6437,8 +6549,8 @@ cmsInt32Number CheckCGATS(void)
 {
     cmsHANDLE  it8;
     cmsInt32Number i;
-    
 
+    SubTest("IT8 creation");
     it8 = cmsIT8Alloc(DbgThread());
     if (it8 == NULL) return 0;
 
@@ -6458,6 +6570,7 @@ cmsInt32Number CheckCGATS(void)
     cmsIT8SetDataFormat(it8, 2, "RGB_G");
     cmsIT8SetDataFormat(it8, 3, "RGB_B");
 
+    SubTest("Table creation");
     for (i=0; i < NPOINTS_IT8; i++) {
 
           char Patch[20];
@@ -6470,33 +6583,63 @@ cmsInt32Number CheckCGATS(void)
           cmsIT8SetDataRowColDbl(it8, i, 3, i);
     }
 
+    SubTest("Save to file");
     cmsIT8SaveToFile(it8, "TEST.IT8");
     cmsIT8Free(it8);
 
-
+    SubTest("Load from file");
     it8 = cmsIT8LoadFromFile(DbgThread(), "TEST.IT8");
+    if (it8 == NULL) return 0;
+
+    SubTest("Save again file");
     cmsIT8SaveToFile(it8, "TEST.IT8");
     cmsIT8Free(it8);
 
 
-
+    SubTest("Load from file (II)");
     it8 = cmsIT8LoadFromFile(DbgThread(), "TEST.IT8");
+    if (it8 == NULL) return 0;
 
+
+     SubTest("Change prop value");
     if (cmsIT8GetPropertyDbl(it8, "DESCRIPTOR") != 1234) {
-   
+
         return 0;
     }
 
 
     cmsIT8SetPropertyDbl(it8, "DESCRIPTOR", 5678);
-
     if (cmsIT8GetPropertyDbl(it8, "DESCRIPTOR") != 5678) {
-         
+
         return 0;
     }
 
+     SubTest("Positive numbers");
     if (cmsIT8GetDataDbl(it8, "P3", "RGB_G") != 3) {
-   
+
+        return 0;
+    }
+
+
+     SubTest("Positive exponent numbers");
+     cmsIT8SetPropertyDbl(it8, "DBL_PROP", 123E+12);
+     if ((cmsIT8GetPropertyDbl(it8, "DBL_PROP") - 123E+12) > 1 ) {
+
+        return 0;
+    }
+
+    SubTest("Negative exponent numbers");
+    cmsIT8SetPropertyDbl(it8, "DBL_PROP_NEG", 123E-45);
+     if ((cmsIT8GetPropertyDbl(it8, "DBL_PROP_NEG") - 123E-45) > 1E-45 ) {
+
+        return 0;
+    }
+
+
+    SubTest("Negative numbers");
+    cmsIT8SetPropertyDbl(it8, "DBL_NEG_VAL", -123);
+    if ((cmsIT8GetPropertyDbl(it8, "DBL_NEG_VAL")) != -123 ) {
+
         return 0;
     }
 
@@ -6513,16 +6656,16 @@ cmsInt32Number CheckCGATS(void)
 static
 void GenerateCSA(const char* cInProf, const char* FileName)
 {
-    cmsHPROFILE hProfile;   
+    cmsHPROFILE hProfile;
     cmsUInt32Number n;
     char* Buffer;
     cmsContext BuffThread = DbgThread();
     FILE* o;
 
 
-    if (cInProf == NULL) 
+    if (cInProf == NULL)
         hProfile = cmsCreateLab4Profile(NULL);
-    else 
+    else
         hProfile = cmsOpenProfileFromFile(cInProf, "r");
 
     n = cmsGetPostScriptCSA(DbgThread(), hProfile, 0, 0, NULL, 0);
@@ -6554,9 +6697,9 @@ void GenerateCRD(const char* cOutProf, const char* FileName)
     cmsContext BuffThread = DbgThread();
 
 
-    if (cOutProf == NULL) 
+    if (cOutProf == NULL)
         hProfile = cmsCreateLab4Profile(NULL);
-    else 
+    else
         hProfile = cmsOpenProfileFromFile(cOutProf, "r");
 
     n = cmsGetPostScriptCRD(DbgThread(), hProfile, 0, dwFlags, NULL, 0);
@@ -6577,7 +6720,7 @@ void GenerateCRD(const char* cOutProf, const char* FileName)
     remove(FileName);
 }
 
-static 
+static
 cmsInt32Number CheckPostScript(void)
 {
     GenerateCSA("test5.icc", "sRGB_CSA.ps");
@@ -6586,7 +6729,7 @@ cmsInt32Number CheckPostScript(void)
     GenerateCSA("test1.icc", "SWOP_CSA.ps");
     GenerateCSA(NULL, "Lab_CSA.ps");
     GenerateCSA("graylcms2.icc", "gray_CSA.ps");
-    
+
     GenerateCRD("test5.icc", "sRGB_CRD.ps");
     GenerateCRD("aRGBlcms2.icc", "aRGB_CRD.ps");
     GenerateCRD(NULL, "Lab_CRD.ps");
@@ -6620,7 +6763,7 @@ cmsInt32Number CheckInputGray(void)
 
     if (hGray == NULL || hLab == NULL) return 0;
 
-    xform = cmsCreateTransform(hGray, TYPE_GRAY_8, hLab, TYPE_Lab_DBL, INTENT_RELATIVE_COLORIMETRIC, 0); 
+    xform = cmsCreateTransform(hGray, TYPE_GRAY_8, hLab, TYPE_Lab_DBL, INTENT_RELATIVE_COLORIMETRIC, 0);
     cmsCloseProfile(hGray); cmsCloseProfile(hLab);
 
     if (!CheckGray(xform, 0, 0)) return 0;
@@ -6678,15 +6821,15 @@ cmsInt32Number CheckOutputGray(void)
 
     if (hGray == NULL || hLab == NULL) return 0;
 
-    xform = cmsCreateTransform( hLab, TYPE_Lab_DBL, hGray, TYPE_GRAY_8, INTENT_RELATIVE_COLORIMETRIC, 0); 
+    xform = cmsCreateTransform( hLab, TYPE_Lab_DBL, hGray, TYPE_GRAY_8, INTENT_RELATIVE_COLORIMETRIC, 0);
     cmsCloseProfile(hGray); cmsCloseProfile(hLab);
 
     if (!CheckOutGray(xform, 0, 0)) return 0;
     if (!CheckOutGray(xform, 100, 255)) return 0;
-    
+
     if (!CheckOutGray(xform, 20, 52)) return 0;
     if (!CheckOutGray(xform, 50, 118)) return 0;
-    
+
 
     cmsDeleteTransform(xform);
     return 1;
@@ -6717,7 +6860,7 @@ cmsInt32Number CheckLabOutputGray(void)
 
         if (!CheckOutGray(xform, i, g)) return 0;
     }
-    
+
 
     cmsDeleteTransform(xform);
     return 1;
@@ -6734,7 +6877,7 @@ cmsInt32Number CheckV4gamma(void)
     h = cmsOpenProfileFromFileTHR(DbgThread(), "v4gamma.icc", "w");
     if (h == NULL) return 0;
 
-    
+
     cmsSetProfileVersion(h, 4.3);
 
     if (!cmsWriteTag(h, cmsSigGrayTRCTag, g)) return 0;
@@ -6809,11 +6952,11 @@ cmsInt32Number CheckGBD(void)
         for (g1=0; g1 < 256; g1 += 5)
             for (b1=0; b1 < 256; b1 += 5) {
 
-                
-                cmsUInt8Number rgb[3];  
+
+                cmsUInt8Number rgb[3];
 
                 rgb[0] = (cmsUInt8Number) r1;
-                rgb[1] = (cmsUInt8Number) g1; 
+                rgb[1] = (cmsUInt8Number) g1;
                 rgb[2] = (cmsUInt8Number) b1;
 
                 cmsDoTransform(xform, rgb, &Lab, 1);
@@ -6824,11 +6967,11 @@ cmsInt32Number CheckGBD(void)
                     cmsGBDFree(h);
                     return 0;
                 }
-                
+
 
             }
     }
-    
+
 
     if (!cmsGDBCompute(h, 0)) return 0;
     // cmsGBDdumpVRML(h, "c:\\colormaps\\lab.wrl");
@@ -6837,11 +6980,11 @@ cmsInt32Number CheckGBD(void)
         for (g1=10; g1 < 200; g1 += 10)
             for (b1=10; b1 < 200; b1 += 10) {
 
-                
-                cmsUInt8Number rgb[3];  
+
+                cmsUInt8Number rgb[3];
 
                 rgb[0] = (cmsUInt8Number) r1;
-                rgb[1] = (cmsUInt8Number) g1; 
+                rgb[1] = (cmsUInt8Number) g1;
                 rgb[2] = (cmsUInt8Number) b1;
 
                 cmsDoTransform(xform, rgb, &Lab, 1);
@@ -6861,7 +7004,7 @@ cmsInt32Number CheckGBD(void)
     SubTest("checking LCh chroma ring");
     h = cmsGBDAlloc(DbgThread());
 
-    
+
     for (r1=0; r1 < 360; r1++) {
 
         cmsCIELCh LCh;
@@ -6876,7 +7019,7 @@ cmsInt32Number CheckGBD(void)
                     return 0;
                 }
     }
-    
+
 
     if (!cmsGDBCompute(h, 0)) return 0;
 
@@ -6890,29 +7033,263 @@ static
 int CheckMD5(void)
 {
     _cmsICCPROFILE* h;
-    cmsHPROFILE pProfile = cmsOpenProfileFromFile("sRGBlcms2.icc", "r"); 
+    cmsHPROFILE pProfile = cmsOpenProfileFromFile("sRGBlcms2.icc", "r");
     cmsProfileID ProfileID1, ProfileID2, ProfileID3, ProfileID4;
 
     h =(_cmsICCPROFILE*) pProfile;
-    if (cmsMD5computeID(pProfile)) cmsGetHeaderProfileID(pProfile, ProfileID1.ID8); 
-    if (cmsMD5computeID(pProfile)) cmsGetHeaderProfileID(pProfile,ProfileID2.ID8); 
+    if (cmsMD5computeID(pProfile)) cmsGetHeaderProfileID(pProfile, ProfileID1.ID8);
+    if (cmsMD5computeID(pProfile)) cmsGetHeaderProfileID(pProfile,ProfileID2.ID8);
 
     cmsCloseProfile(pProfile);
-    
 
-     pProfile = cmsOpenProfileFromFile("sRGBlcms2.icc", "r");  
+
+     pProfile = cmsOpenProfileFromFile("sRGBlcms2.icc", "r");
 
       h =(_cmsICCPROFILE*) pProfile;
-    if (cmsMD5computeID(pProfile)) cmsGetHeaderProfileID(pProfile, ProfileID3.ID8); 
-    if (cmsMD5computeID(pProfile)) cmsGetHeaderProfileID(pProfile,ProfileID4.ID8); 
+    if (cmsMD5computeID(pProfile)) cmsGetHeaderProfileID(pProfile, ProfileID3.ID8);
+    if (cmsMD5computeID(pProfile)) cmsGetHeaderProfileID(pProfile,ProfileID4.ID8);
 
     cmsCloseProfile(pProfile);
 
-    return ((memcmp(ProfileID1.ID8, ProfileID3.ID8, sizeof(ProfileID1)) == 0) && 
+    return ((memcmp(ProfileID1.ID8, ProfileID3.ID8, sizeof(ProfileID1)) == 0) &&
             (memcmp(ProfileID2.ID8, ProfileID4.ID8, sizeof(ProfileID2)) == 0));
 }
 
 
+
+static
+int CheckLinking(void)
+{
+    cmsHPROFILE h;
+    cmsPipeline * pipeline;
+    cmsStage *stageBegin, *stageEnd;
+
+    // Create a CLUT based profile
+     h = cmsCreateInkLimitingDeviceLinkTHR(DbgThread(), cmsSigCmykData, 150);
+
+     // link a second tag
+     cmsLinkTag(h, cmsSigAToB1Tag, cmsSigAToB0Tag);
+
+     // Save the linked devicelink
+    if (!cmsSaveProfileToFile(h, "lcms2link.icc")) return 0;
+    cmsCloseProfile(h);
+
+    // Now open the profile and read the pipeline
+    h = cmsOpenProfileFromFile("lcms2link.icc", "r");
+    if (h == NULL) return 0;
+
+    pipeline = (cmsPipeline*) cmsReadTag(h, cmsSigAToB1Tag);
+    if (pipeline == NULL)
+    {
+        return 0;
+    }
+
+    pipeline = cmsPipelineDup(pipeline);
+
+    // extract stage from pipe line
+    cmsPipelineUnlinkStage(pipeline, cmsAT_BEGIN, &stageBegin);
+    cmsPipelineUnlinkStage(pipeline, cmsAT_END,   &stageEnd);
+    cmsPipelineInsertStage(pipeline, cmsAT_END,    stageEnd);
+    cmsPipelineInsertStage(pipeline, cmsAT_BEGIN,  stageBegin);
+    
+    if (cmsTagLinkedTo(h, cmsSigAToB1Tag) != cmsSigAToB0Tag) return 0;
+
+    cmsWriteTag(h, cmsSigAToB0Tag, pipeline);
+    cmsPipelineFree(pipeline);
+
+       if (!cmsSaveProfileToFile(h, "lcms2link2.icc")) return 0;
+    cmsCloseProfile(h);
+
+
+    return 1;
+
+}
+
+//  TestMPE
+//
+//  Created by Paul Miller on 30/08/2012.
+//
+static 
+cmsHPROFILE IdentityMatrixProfile( cmsColorSpaceSignature dataSpace)
+{
+    cmsContext ctx = 0;
+    cmsVEC3 zero = {{0,0,0}};
+    cmsMAT3 identity;
+    cmsPipeline* forward;
+    cmsPipeline* reverse;
+    cmsHPROFILE identityProfile = cmsCreateProfilePlaceholder( ctx);
+    
+
+    cmsSetProfileVersion(identityProfile, 4.3);
+    
+    cmsSetDeviceClass( identityProfile,     cmsSigColorSpaceClass);
+    cmsSetColorSpace(identityProfile,       dataSpace);
+    cmsSetPCS(identityProfile,              cmsSigXYZData);
+    
+    cmsSetHeaderRenderingIntent(identityProfile,  INTENT_RELATIVE_COLORIMETRIC);
+    
+    cmsWriteTag(identityProfile, cmsSigMediaWhitePointTag, cmsD50_XYZ());
+    
+   
+    
+    _cmsMAT3identity( &identity);
+    
+    // build forward transform.... (RGB to PCS)
+    forward = cmsPipelineAlloc( 0, 3, 3);
+    cmsPipelineInsertStage( forward, cmsAT_END, cmsStageAllocMatrix( ctx, 3, 3, (cmsFloat64Number*)&identity, (cmsFloat64Number*)&zero));
+    cmsWriteTag( identityProfile, cmsSigDToB1Tag, forward);
+    
+    cmsPipelineFree( forward);
+    
+    reverse = cmsPipelineAlloc( 0, 3, 3);
+    cmsPipelineInsertStage( reverse, cmsAT_END, cmsStageAllocMatrix( ctx, 3, 3, (cmsFloat64Number*)&identity, (cmsFloat64Number*)&zero));
+    cmsWriteTag( identityProfile, cmsSigBToD1Tag, reverse);
+    
+    cmsPipelineFree( reverse);
+    
+    return identityProfile;
+}
+
+static
+cmsInt32Number CheckFloatXYZ(void)
+{
+    cmsHPROFILE input;
+    cmsHPROFILE xyzProfile = cmsCreateXYZProfile();
+    cmsHTRANSFORM xform;
+    cmsFloat32Number in[3];
+    cmsFloat32Number out[3];
+    
+    in[0] = 1.0;
+    in[1] = 1.0;
+    in[2] = 1.0;
+    
+    // RGB to XYZ
+    input = IdentityMatrixProfile( cmsSigRgbData);
+    
+    xform = cmsCreateTransform( input, TYPE_RGB_FLT, xyzProfile, TYPE_XYZ_FLT, INTENT_RELATIVE_COLORIMETRIC, 0);
+    cmsCloseProfile(input);
+    
+    cmsDoTransform( xform, in, out, 1);
+    cmsDeleteTransform( xform);
+    
+    if (!IsGoodVal("Float RGB->XYZ", in[0], out[0], FLOAT_PRECISSION) ||
+        !IsGoodVal("Float RGB->XYZ", in[1], out[1], FLOAT_PRECISSION) ||
+        !IsGoodVal("Float RGB->XYZ", in[2], out[2], FLOAT_PRECISSION))
+           return 0;
+    
+    
+    // XYZ to XYZ
+    input = IdentityMatrixProfile( cmsSigXYZData);
+    
+    xform = cmsCreateTransform( input, TYPE_XYZ_FLT, xyzProfile, TYPE_XYZ_FLT, INTENT_RELATIVE_COLORIMETRIC, 0);
+    cmsCloseProfile(input);
+
+    cmsDoTransform( xform, in, out, 1);
+    
+    
+    cmsDeleteTransform( xform);
+    
+     if (!IsGoodVal("Float XYZ->XYZ", in[0], out[0], FLOAT_PRECISSION) ||
+         !IsGoodVal("Float XYZ->XYZ", in[1], out[1], FLOAT_PRECISSION) ||
+         !IsGoodVal("Float XYZ->XYZ", in[2], out[2], FLOAT_PRECISSION))
+           return 0;
+   
+    
+    // XYZ to RGB
+    input = IdentityMatrixProfile( cmsSigRgbData);
+    
+    xform = cmsCreateTransform( xyzProfile, TYPE_XYZ_FLT, input, TYPE_RGB_FLT, INTENT_RELATIVE_COLORIMETRIC, 0);
+    cmsCloseProfile(input);
+    
+    cmsDoTransform( xform, in, out, 1);
+   
+    cmsDeleteTransform( xform);
+
+       if (!IsGoodVal("Float XYZ->RGB", in[0], out[0], FLOAT_PRECISSION) ||
+           !IsGoodVal("Float XYZ->RGB", in[1], out[1], FLOAT_PRECISSION) ||
+           !IsGoodVal("Float XYZ->RGB", in[2], out[2], FLOAT_PRECISSION))
+           return 0;
+        
+
+    // Now the optimizer should remove a stage
+
+    // XYZ to RGB
+    input = IdentityMatrixProfile( cmsSigRgbData);
+    
+    xform = cmsCreateTransform( input, TYPE_RGB_FLT, input, TYPE_RGB_FLT, INTENT_RELATIVE_COLORIMETRIC, 0);
+    cmsCloseProfile(input);
+    
+    cmsDoTransform( xform, in, out, 1);
+   
+    cmsDeleteTransform( xform);
+
+       if (!IsGoodVal("Float RGB->RGB", in[0], out[0], FLOAT_PRECISSION) ||
+           !IsGoodVal("Float RGB->RGB", in[1], out[1], FLOAT_PRECISSION) ||
+           !IsGoodVal("Float RGB->RGB", in[2], out[2], FLOAT_PRECISSION))
+           return 0;
+    
+    cmsCloseProfile(xyzProfile);
+
+
+    return 1;
+}
+
+
+/*
+Bug reported
+
+        1)
+        sRGB built-in V4.3 -> Lab identity built-in V4.3
+        Flags: "cmsFLAGS_NOCACHE", "cmsFLAGS_NOOPTIMIZE"
+        Input format: TYPE_RGBA_FLT
+        Output format: TYPE_LabA_FLT
+
+        2) and back
+        Lab identity built-in V4.3 -> sRGB built-in V4.3 
+        Flags: "cmsFLAGS_NOCACHE", "cmsFLAGS_NOOPTIMIZE"
+        Input format: TYPE_LabA_FLT
+        Output format: TYPE_RGBA_FLT
+
+*/
+static
+cmsInt32Number ChecksRGB2LabFLT(void)
+{
+    cmsHPROFILE hSRGB = cmsCreate_sRGBProfile();
+    cmsHPROFILE hLab  = cmsCreateLab4Profile(NULL);
+
+    cmsHTRANSFORM xform1 = cmsCreateTransform(hSRGB, TYPE_RGBA_FLT, hLab, TYPE_LabA_FLT, 0, cmsFLAGS_NOCACHE|cmsFLAGS_NOOPTIMIZE);
+    cmsHTRANSFORM xform2 = cmsCreateTransform(hLab, TYPE_LabA_FLT, hSRGB, TYPE_RGBA_FLT, 0, cmsFLAGS_NOCACHE|cmsFLAGS_NOOPTIMIZE);
+
+    cmsFloat32Number RGBA1[4], RGBA2[4], LabA[4];
+    int i;
+
+
+    for (i = 0; i <= 100; i++)
+    {
+        RGBA1[0] = i / 100.0F;
+        RGBA1[1] = i / 100.0F;
+        RGBA1[2] = i / 100.0F;
+        RGBA1[3] = 0;
+
+        cmsDoTransform(xform1, RGBA1, LabA,  1);
+        cmsDoTransform(xform2, LabA, RGBA2, 1);
+
+        if (!IsGoodVal("Float RGB->RGB", RGBA1[0], RGBA2[0], FLOAT_PRECISSION) ||
+            !IsGoodVal("Float RGB->RGB", RGBA1[1], RGBA2[1], FLOAT_PRECISSION) ||
+            !IsGoodVal("Float RGB->RGB", RGBA1[2], RGBA2[2], FLOAT_PRECISSION))
+            return 0;
+    }
+
+
+    cmsDeleteTransform(xform1);
+    cmsDeleteTransform(xform2);
+    cmsCloseProfile(hSRGB);
+    cmsCloseProfile(hLab);
+
+    return 1;
+}
+
+
 // --------------------------------------------------------------------------------------------------
 // P E R F O R M A N C E   C H E C K S
 // --------------------------------------------------------------------------------------------------
@@ -6924,7 +7301,7 @@ typedef struct {cmsUInt8Number r, g, b;}      Scanline_rgb8;
 typedef struct {cmsUInt16Number r, g, b;}     Scanline_rgb0;
 
 
-static 
+static
 void TitlePerformance(const char* Txt)
 {
     printf("%-45s: ", Txt); fflush(stdout);
@@ -6952,10 +7329,10 @@ void SpeedTest16bits(const char * Title, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE
     Scanline_rgb0 *In;
     cmsUInt32Number Mb;
 
-    if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL) 
+    if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
         Die("Unable to open profiles");
 
-    hlcmsxform  = cmsCreateTransformTHR(DbgThread(), hlcmsProfileIn, TYPE_RGB_16, 
+    hlcmsxform  = cmsCreateTransformTHR(DbgThread(), hlcmsProfileIn, TYPE_RGB_16,
                                hlcmsProfileOut, TYPE_RGB_16, Intent, cmsFLAGS_NOCACHE);
     cmsCloseProfile(hlcmsProfileIn);
     cmsCloseProfile(hlcmsProfileOut);
@@ -6984,10 +7361,10 @@ void SpeedTest16bits(const char * Title, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE
 
     diff = clock() - atime;
     free(In);
-        
+
     PrintPerformance(Mb, sizeof(Scanline_rgb0), diff);
     cmsDeleteTransform(hlcmsxform);
-    
+
 }
 
 
@@ -7000,11 +7377,11 @@ void SpeedTest16bitsCMYK(const char * Title, cmsHPROFILE hlcmsProfileIn, cmsHPRO
     cmsHTRANSFORM hlcmsxform;
     Scanline_rgb2 *In;
     cmsUInt32Number Mb;
-     
-    if (hlcmsProfileOut == NULL || hlcmsProfileOut == NULL) 
+
+    if (hlcmsProfileOut == NULL || hlcmsProfileOut == NULL)
         Die("Unable to open profiles");
 
-    hlcmsxform  = cmsCreateTransformTHR(DbgThread(), hlcmsProfileIn, TYPE_CMYK_16, 
+    hlcmsxform  = cmsCreateTransformTHR(DbgThread(), hlcmsProfileIn, TYPE_CMYK_16,
                 hlcmsProfileOut, TYPE_CMYK_16, INTENT_PERCEPTUAL,  cmsFLAGS_NOCACHE);
     cmsCloseProfile(hlcmsProfileIn);
     cmsCloseProfile(hlcmsProfileOut);
@@ -7036,11 +7413,11 @@ void SpeedTest16bitsCMYK(const char * Title, cmsHPROFILE hlcmsProfileIn, cmsHPRO
     diff = clock() - atime;
 
     free(In);
-    
+
     PrintPerformance(Mb, sizeof(Scanline_rgb2), diff);
 
     cmsDeleteTransform(hlcmsxform);
+
 }
 
 
@@ -7053,11 +7430,11 @@ void SpeedTest8bits(const char * Title, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE
     cmsHTRANSFORM hlcmsxform;
     Scanline_rgb8 *In;
     cmsUInt32Number Mb;
-   
-    if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL) 
+
+    if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
         Die("Unable to open profiles");
 
-    hlcmsxform  = cmsCreateTransformTHR(DbgThread(), hlcmsProfileIn, TYPE_RGB_8, 
+    hlcmsxform  = cmsCreateTransformTHR(DbgThread(), hlcmsProfileIn, TYPE_RGB_8,
                             hlcmsProfileOut, TYPE_RGB_8, Intent, cmsFLAGS_NOCACHE);
     cmsCloseProfile(hlcmsProfileIn);
     cmsCloseProfile(hlcmsProfileOut);
@@ -7087,9 +7464,9 @@ void SpeedTest8bits(const char * Title, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE
     diff = clock() - atime;
 
     free(In);
-    
+
     PrintPerformance(Mb, sizeof(Scanline_rgb8), diff);
-    
+
     cmsDeleteTransform(hlcmsxform);
 
 }
@@ -7104,11 +7481,11 @@ void SpeedTest8bitsCMYK(const char * Title, cmsHPROFILE hlcmsProfileIn, cmsHPROF
     cmsHTRANSFORM hlcmsxform;
     Scanline_rgb2 *In;
     cmsUInt32Number Mb;
-    
-    if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL) 
+
+    if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
         Die("Unable to open profiles");
 
-    hlcmsxform  = cmsCreateTransformTHR(DbgThread(), hlcmsProfileIn, TYPE_CMYK_8, 
+    hlcmsxform  = cmsCreateTransformTHR(DbgThread(), hlcmsProfileIn, TYPE_CMYK_8,
                         hlcmsProfileOut, TYPE_CMYK_8, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
     cmsCloseProfile(hlcmsProfileIn);
     cmsCloseProfile(hlcmsProfileOut);
@@ -7139,7 +7516,7 @@ void SpeedTest8bitsCMYK(const char * Title, cmsHPROFILE hlcmsProfileIn, cmsHPROF
     diff = clock() - atime;
 
     free(In);
-    
+
     PrintPerformance(Mb, sizeof(Scanline_rgb2), diff);
 
 
@@ -7157,12 +7534,12 @@ void SpeedTest8bitsGray(const char * Title, cmsHPROFILE hlcmsProfileIn, cmsHPROF
     cmsHTRANSFORM hlcmsxform;
     cmsUInt8Number *In;
     cmsUInt32Number Mb;
-   
-   
-    if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL) 
+
+
+    if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
         Die("Unable to open profiles");
 
-    hlcmsxform  = cmsCreateTransformTHR(DbgThread(), hlcmsProfileIn, 
+    hlcmsxform  = cmsCreateTransformTHR(DbgThread(), hlcmsProfileIn,
                         TYPE_GRAY_8, hlcmsProfileOut, TYPE_GRAY_8, Intent, cmsFLAGS_NOCACHE);
     cmsCloseProfile(hlcmsProfileIn);
     cmsCloseProfile(hlcmsProfileOut);
@@ -7176,7 +7553,7 @@ void SpeedTest8bitsGray(const char * Title, cmsHPROFILE hlcmsProfileIn, cmsHPROF
             for (b=0; b < 256; b++) {
 
         In[j] = (cmsUInt8Number) r;
-        
+
         j++;
     }
 
@@ -7188,7 +7565,7 @@ void SpeedTest8bitsGray(const char * Title, cmsHPROFILE hlcmsProfileIn, cmsHPROF
 
     diff = clock() - atime;
     free(In);
-        
+
     PrintPerformance(Mb, sizeof(cmsUInt8Number), diff);
     cmsDeleteTransform(hlcmsxform);
 }
@@ -7200,7 +7577,7 @@ cmsHPROFILE CreateCurves(void)
     cmsToneCurve* Gamma = cmsBuildGamma(DbgThread(), 1.1);
     cmsToneCurve* Transfer[3];
     cmsHPROFILE h;
-    
+
     Transfer[0] = Transfer[1] = Transfer[2] = Gamma;
     h = cmsCreateLinearizationDeviceLink(cmsSigRgbData, Transfer);
 
@@ -7208,27 +7585,26 @@ cmsHPROFILE CreateCurves(void)
 
     return h;
 }
-    
+
 
 static
 void SpeedTest(void)
 {
-
     printf("\n\nP E R F O R M A N C E   T E S T S\n");
     printf(    "=================================\n\n");
     fflush(stdout);
 
-    SpeedTest16bits("16 bits on CLUT profiles", 
+    SpeedTest16bits("16 bits on CLUT profiles",
         cmsOpenProfileFromFile("test5.icc", "r"),
         cmsOpenProfileFromFile("test3.icc", "r"), INTENT_PERCEPTUAL);
 
-    SpeedTest8bits("8 bits on CLUT profiles", 
+    SpeedTest8bits("8 bits on CLUT profiles",
         cmsOpenProfileFromFile("test5.icc", "r"),
         cmsOpenProfileFromFile("test3.icc", "r"),
         INTENT_PERCEPTUAL);
-    
-    SpeedTest8bits("8 bits on Matrix-Shaper profiles", 
-        cmsOpenProfileFromFile("test5.icc", "r"), 
+
+    SpeedTest8bits("8 bits on Matrix-Shaper profiles",
+        cmsOpenProfileFromFile("test5.icc", "r"),
         cmsOpenProfileFromFile("aRGBlcms2.icc", "r"),
         INTENT_PERCEPTUAL);
 
@@ -7237,50 +7613,54 @@ void SpeedTest(void)
         cmsOpenProfileFromFile("test5.icc", "r"),
         INTENT_PERCEPTUAL);
 
-    SpeedTest8bits("8 bits on Matrix-Shaper profiles (AbsCol)", 
+    SpeedTest8bits("8 bits on Matrix-Shaper profiles (AbsCol)",
        cmsOpenProfileFromFile("test5.icc", "r"),
        cmsOpenProfileFromFile("aRGBlcms2.icc", "r"),
-        INTENT_ABSOLUTE_COLORIMETRIC);  
+        INTENT_ABSOLUTE_COLORIMETRIC);
 
-    SpeedTest16bits("16 bits on Matrix-Shaper profiles", 
+    SpeedTest16bits("16 bits on Matrix-Shaper profiles",
        cmsOpenProfileFromFile("test5.icc", "r"),
         cmsOpenProfileFromFile("aRGBlcms2.icc", "r"),
         INTENT_PERCEPTUAL);
 
-    SpeedTest16bits("16 bits on SAME Matrix-Shaper profiles", 
+    SpeedTest16bits("16 bits on SAME Matrix-Shaper profiles",
         cmsOpenProfileFromFile("aRGBlcms2.icc", "r"),
         cmsOpenProfileFromFile("aRGBlcms2.icc", "r"),
         INTENT_PERCEPTUAL);
 
-    SpeedTest16bits("16 bits on Matrix-Shaper profiles (AbsCol)", 
+    SpeedTest16bits("16 bits on Matrix-Shaper profiles (AbsCol)",
        cmsOpenProfileFromFile("test5.icc", "r"),
        cmsOpenProfileFromFile("aRGBlcms2.icc", "r"),
         INTENT_ABSOLUTE_COLORIMETRIC);
 
-    SpeedTest8bits("8 bits on curves", 
-        CreateCurves(), 
+    SpeedTest8bits("8 bits on curves",
+        CreateCurves(),
         CreateCurves(),
         INTENT_PERCEPTUAL);
 
-    SpeedTest16bits("16 bits on curves", 
-        CreateCurves(), 
+    SpeedTest16bits("16 bits on curves",
+        CreateCurves(),
         CreateCurves(),
         INTENT_PERCEPTUAL);
 
-    SpeedTest8bitsCMYK("8 bits on CMYK profiles", 
+    SpeedTest8bitsCMYK("8 bits on CMYK profiles",
         cmsOpenProfileFromFile("test1.icc", "r"),
         cmsOpenProfileFromFile("test2.icc", "r"));
 
-    SpeedTest16bitsCMYK("16 bits on CMYK profiles", 
+    SpeedTest16bitsCMYK("16 bits on CMYK profiles",
         cmsOpenProfileFromFile("test1.icc", "r"),
         cmsOpenProfileFromFile("test2.icc", "r"));
 
-    SpeedTest8bitsGray("8 bits on gray-to-gray",
-        cmsOpenProfileFromFile("graylcms2.icc", "r"), 
+    SpeedTest8bitsGray("8 bits on gray-to gray",
+        cmsOpenProfileFromFile("gray3lcms2.icc", "r"),
+        cmsOpenProfileFromFile("graylcms2.icc", "r"), INTENT_RELATIVE_COLORIMETRIC);
+
+    SpeedTest8bitsGray("8 bits on gray-to-lab gray",
+        cmsOpenProfileFromFile("graylcms2.icc", "r"),
         cmsOpenProfileFromFile("glablcms2.icc", "r"), INTENT_RELATIVE_COLORIMETRIC);
 
     SpeedTest8bitsGray("8 bits on SAME gray-to-gray",
-        cmsOpenProfileFromFile("graylcms2.icc", "r"), 
+        cmsOpenProfileFromFile("graylcms2.icc", "r"),
         cmsOpenProfileFromFile("graylcms2.icc", "r"), INTENT_PERCEPTUAL);
 }
 
@@ -7371,8 +7751,8 @@ void PrintAllInfos(cmsHPROFILE h)
 {
      PrintInfo(h, cmsInfoDescription);
      PrintInfo(h, cmsInfoManufacturer);
-     PrintInfo(h, cmsInfoModel);       
-     PrintInfo(h, cmsInfoCopyright);   
+     PrintInfo(h, cmsInfoModel);
+     PrintInfo(h, cmsInfoCopyright);
      printf("\n\n");
 }
 
@@ -7381,7 +7761,7 @@ void ReadAllLUTS(cmsHPROFILE h)
 {
     cmsPipeline* a;
     cmsCIEXYZ Black;
-  
+
     a = _cmsReadInputLUT(h, INTENT_PERCEPTUAL);
     if (a) cmsPipelineFree(a);
 
@@ -7421,10 +7801,10 @@ void ReadAllLUTS(cmsHPROFILE h)
     if (a) cmsPipelineFree(a);
 
 
-    cmsDetectBlackPoint(&Black, h, INTENT_PERCEPTUAL, 0);
-    cmsDetectBlackPoint(&Black, h, INTENT_RELATIVE_COLORIMETRIC, 0);
-    cmsDetectBlackPoint(&Black, h, INTENT_SATURATION, 0);
-    cmsDetectBlackPoint(&Black, h, INTENT_ABSOLUTE_COLORIMETRIC, 0);
+    cmsDetectDestinationBlackPoint(&Black, h, INTENT_PERCEPTUAL, 0);
+    cmsDetectDestinationBlackPoint(&Black, h, INTENT_RELATIVE_COLORIMETRIC, 0);
+    cmsDetectDestinationBlackPoint(&Black, h, INTENT_SATURATION, 0);
+    cmsDetectDestinationBlackPoint(&Black, h, INTENT_ABSOLUTE_COLORIMETRIC, 0);
     cmsDetectTAC(h);
 }
 
@@ -7442,11 +7822,11 @@ cmsInt32Number CheckSingleSpecimen(const char* Profile)
 
     h = cmsOpenProfileFromFile(BuffSrc, "r");
     if (h == NULL) return 0;
-    
+
     printf("%s\n", Profile);
-    PrintAllInfos(h);   
-    ReadAllTags(h);  
-    // ReadAllRAWTags(h);   
+    PrintAllInfos(h);
+    ReadAllTags(h);
+    // ReadAllRAWTags(h);
     ReadAllLUTS(h);
 
     cmsSaveProfileToFile(h, BuffDst);
@@ -7454,8 +7834,8 @@ cmsInt32Number CheckSingleSpecimen(const char* Profile)
 
     h = cmsOpenProfileFromFile(BuffDst, "r");
     if (h == NULL) return 0;
-    ReadAllTags(h); 
-    
+    ReadAllTags(h);
+
 
     cmsCloseProfile(h);
 
@@ -7474,15 +7854,15 @@ cmsInt32Number CheckRAWSpecimen(const char* Profile)
 
     h = cmsOpenProfileFromFile(BuffSrc, "r");
     if (h == NULL) return 0;
-    
+
     ReadAllTags(h);
-    ReadAllRAWTags(h);  
+    ReadAllRAWTags(h);
     cmsSaveProfileToFile(h, BuffDst);
     cmsCloseProfile(h);
 
     h = cmsOpenProfileFromFile(BuffDst, "r");
     if (h == NULL) return 0;
-    ReadAllTags(h); 
+    ReadAllTags(h);
     cmsCloseProfile(h);
 
     return 1;
@@ -7531,32 +7911,32 @@ void CheckProfileZOO(void)
 
 
 #if 0
-#define TYPE_709 709 
-static double Rec709Math(int Type, const double Params[], double R) 
-{ double Fun; 
+#define TYPE_709 709
+static double Rec709Math(int Type, const double Params[], double R)
+{ double Fun;
 
-switch (Type) 
-{ 
-case 709: 
+switch (Type)
+{
+case 709:
 
-if (R <= (Params[3]*Params[4])) Fun = R / Params[3]; 
-else Fun = pow(((R - Params[2])/Params[1]), Params[0]); 
-break; 
+if (R <= (Params[3]*Params[4])) Fun = R / Params[3];
+else Fun = pow(((R - Params[2])/Params[1]), Params[0]);
+break;
 
-case -709: 
+case -709:
 
-if (R <= Params[4]) Fun = R * Params[3]; 
-else Fun = Params[1] * pow(R, (1/Params[0])) + Params[2]; 
-break; 
-} 
-return Fun; 
+if (R <= Params[4]) Fun = R * Params[3];
+else Fun = Params[1] * pow(R, (1/Params[0])) + Params[2];
+break;
+}
+return Fun;
 }
 
 
-// Add nonstandard TRC curves -> Rec709 
-cmsPluginParametricCurves NewCurvePlugin = { 
-{ cmsPluginMagicNumber, 2000, cmsPluginParametricCurveSig, NULL }, 
-1, {TYPE_709}, {5}, Rec709Math}; 
+// Add nonstandard TRC curves -> Rec709
+cmsPluginParametricCurves NewCurvePlugin = {
+{ cmsPluginMagicNumber, 2000, cmsPluginParametricCurveSig, NULL },
+1, {TYPE_709}, {5}, Rec709Math};
 #endif
 
 
@@ -7566,12 +7946,13 @@ cmsPluginParametricCurves NewCurvePlugin = {
 
 int main(int argc, char* argv[])
 {
+
     cmsInt32Number Exhaustive = 0;
     cmsInt32Number DoSpeedTests = 1;
-
+    cmsInt32Number DoCheckTests = 1;
 
 #ifdef _MSC_VER
-    _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); 
+    _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
 #endif
 
     printf("LittleCMS %2.2f test bed %s %s\n\n", LCMS_VERSION / 1000.0, __DATE__, __TIME__);
@@ -7582,7 +7963,6 @@ int main(int argc, char* argv[])
         printf("Running exhaustive tests (will take a while...)\n\n");
     }
 
-    
     printf("Installing debug memory plug-in ... ");
     cmsPlugin(&DebugMemHandler);
     printf("done.\n");
@@ -7591,22 +7971,26 @@ int main(int argc, char* argv[])
     cmsSetLogErrorHandler(FatalErrorQuit);
     printf("done.\n");
 
-#ifdef CMS_IS_WINDOWS_     
-     // CheckProfileZOO();
+#ifdef CMS_IS_WINDOWS_
+      // CheckProfileZOO();
 #endif
 
     PrintSupportedIntents();
 
+
+
     // Create utility profiles
-    Check("Creation of test profiles", CreateTestProfiles);    
+    Check("Creation of test profiles", CreateTestProfiles);
 
+    if (DoCheckTests)
+    {
     Check("Base types", CheckBaseTypes);
     Check("endianess", CheckEndianess);
     Check("quick floor", CheckQuickFloor);
     Check("quick floor word", CheckQuickFloorWord);
     Check("Fixed point 15.16 representation", CheckFixedPoint15_16);
     Check("Fixed point 8.8 representation", CheckFixedPoint8_8);
-    
+
     // Forward 1D interpolation
     Check("1D interpolation in 2pt tables", Check1DLERP2);
     Check("1D interpolation in 3pt tables", Check1DLERP3);
@@ -7617,19 +8001,19 @@ int main(int argc, char* argv[])
     Check("1D interpolation in descending 3pt tables", Check1DLERP3Down);
     Check("1D interpolation in descending 6pt tables", Check1DLERP6Down);
     Check("1D interpolation in descending 18pt tables", Check1DLERP18Down);
-    
+
     if (Exhaustive) {
 
         Check("1D interpolation in n tables", ExhaustiveCheck1DLERP);
         Check("1D interpolation in descending tables", ExhaustiveCheck1DLERPDown);
     }
-    
+
     // Forward 3D interpolation
     Check("3D interpolation Tetrahedral (float) ", Check3DinterpolationFloatTetrahedral);
     Check("3D interpolation Trilinear (float) ", Check3DinterpolationFloatTrilinear);
     Check("3D interpolation Tetrahedral (16) ", Check3DinterpolationTetrahedral16);
     Check("3D interpolation Trilinear (16) ", Check3DinterpolationTrilinear16);
-    
+
     if (Exhaustive) {
 
         Check("Exhaustive 3D interpolation Tetrahedral (float) ", ExaustiveCheck3DinterpolationFloatTetrahedral);
@@ -7640,7 +8024,7 @@ int main(int argc, char* argv[])
 
     Check("Reverse interpolation 3 -> 3", CheckReverseInterpolation3x3);
     Check("Reverse interpolation 4 -> 3", CheckReverseInterpolation4x3);
-  
+
 
     // High dimensionality interpolation
 
@@ -7662,7 +8046,7 @@ int main(int argc, char* argv[])
 
     // BlackBody
     Check("Blackbody radiator", CheckTemp2CHRM);
-    
+
     // Tone curves
     Check("Linear gamma curves (16 bits)", CheckGammaCreation16);
     Check("Linear gamma curves (float)", CheckGammaCreationFlt);
@@ -7680,14 +8064,14 @@ int main(int argc, char* argv[])
     Check("Curve 3.0 (word table)", CheckGamma30TableWord);
 
     Check("Parametric curves", CheckParametricToneCurves);
-    
+
     Check("Join curves", CheckJointCurves);
     Check("Join curves descending", CheckJointCurvesDescending);
-    Check("Join curves degenerated", CheckReverseDegenerated);  
+    Check("Join curves degenerated", CheckReverseDegenerated);
     Check("Join curves sRGB (Float)", CheckJointFloatCurves_sRGB);
     Check("Join curves sRGB (16 bits)", CheckJoint16Curves_sRGB);
     Check("Join curves sigmoidal", CheckJointCurvesSShaped);
-        
+
     // LUT basics
     Check("LUT creation & dup", CheckLUTcreation);
     Check("1 Stage LUT ", Check1StageLUT);
@@ -7701,7 +8085,7 @@ int main(int argc, char* argv[])
     Check("5 Stage LUT (16 bits) ", Check5Stage16LUT);
     Check("6 Stage LUT ", Check6StageLUT);
     Check("6 Stage LUT (16 bits) ", Check6Stage16LUT);
-    
+
     // LUT operation
     Check("Lab to Lab LUT (float only) ", CheckLab2LabLUT);
     Check("XYZ to XYZ LUT (float only) ", CheckXYZ2XYZLUT);
@@ -7710,31 +8094,34 @@ int main(int argc, char* argv[])
     Check("Usual formatters", CheckFormatters16);
     Check("Floating point formatters", CheckFormattersFloat);
 
+#ifndef CMS_NO_HALF_SUPPORT 
+    Check("HALF formatters", CheckFormattersHalf);
+#endif
     // ChangeBuffersFormat
     Check("ChangeBuffersFormat", CheckChangeBufferFormat);
-    
-    // MLU    
+
+    // MLU
     Check("Multilocalized Unicode", CheckMLU);
-    
+
     // Named color
     Check("Named color lists", CheckNamedColorList);
-    
+
     // Profile I/O (this one is huge!)
     Check("Profile creation", CheckProfileCreation);
 
-    
+
     // Error reporting
     Check("Error reporting on bad profiles", CheckErrReportingOnBadProfiles);
     Check("Error reporting on bad transforms", CheckErrReportingOnBadTransforms);
-    
+
     // Transforms
     Check("Curves only transforms", CheckCurvesOnlyTransforms);
     Check("Float Lab->Lab transforms", CheckFloatLabTransforms);
-    Check("Encoded Lab->Lab transforms", CheckEncodedLabTransforms);    
+    Check("Encoded Lab->Lab transforms", CheckEncodedLabTransforms);
     Check("Stored identities", CheckStoredIdentities);
 
     Check("Matrix-shaper transform (float)",   CheckMatrixShaperXFORMFloat);
-    Check("Matrix-shaper transform (16 bits)", CheckMatrixShaperXFORM16);   
+    Check("Matrix-shaper transform (16 bits)", CheckMatrixShaperXFORM16);
     Check("Matrix-shaper transform (8 bits)",  CheckMatrixShaperXFORM8);
 
     Check("Primaries of sRGB", CheckRGBPrimaries);
@@ -7748,32 +8135,36 @@ int main(int argc, char* argv[])
 
     Check("Matrix-shaper proofing transform (float)",   CheckProofingXFORMFloat);
     Check("Matrix-shaper proofing transform (16 bits)",  CheckProofingXFORM16);
-    
+
     Check("Gamut check", CheckGamutCheck);
-        
+
     Check("CMYK roundtrip on perceptual transform",   CheckCMYKRoundtrip);
-    
+
     Check("CMYK perceptual transform",   CheckCMYKPerceptual);
     // Check("CMYK rel.col. transform",   CheckCMYKRelCol);
-    
+
     Check("Black ink only preservation", CheckKOnlyBlackPreserving);
     Check("Black plane preservation", CheckKPlaneBlackPreserving);
 
+
     Check("Deciding curve types", CheckV4gamma);
 
     Check("Black point detection", CheckBlackPoint);
-    Check("TAC detection", CheckTAC);    
+    Check("TAC detection", CheckTAC);
 
     Check("CGATS parser", CheckCGATS);
     Check("PostScript generator", CheckPostScript);
     Check("Segment maxima GBD", CheckGBD);
     Check("MD5 digest", CheckMD5);
+    Check("Linking", CheckLinking);
+    Check("floating point tags on XYZ", CheckFloatXYZ);
+    Check("RGB->Lab->RGB with alpha on FLT", ChecksRGB2LabFLT);
+    }
 
 
     if (DoSpeedTests)
         SpeedTest();
-    
+
     DebugMemPrintTotals();
 
     cmsUnregisterPlugins();
@@ -7783,6 +8174,7 @@ int main(int argc, char* argv[])
 
    return TotalFail;
 }
+
+
 
 
index 8f82ea4..db3a0b6 100644 (file)
@@ -4,36 +4,36 @@
 //  Little Color Management System
 //  Copyright (c) 1998-2010 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 
+// 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 
+// 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 
+// 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.
 //
 //---------------------------------------------------------------------------------
 
 #ifndef _lcms_utils_h
 
-// Deal with Microsoft's attempt at deprecating C standard runtime functions 
+// 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 
+#      ifndef _CRT_SECURE_NO_DEPRECATE
+#        define _CRT_SECURE_NO_DEPRECATE
 #      endif
 #      ifndef _CRT_SECURE_NO_WARNINGS
-#        define _CRT_SECURE_NO_WARNINGS  
+#        define _CRT_SECURE_NO_WARNINGS
 #      endif
 #    endif
 #endif
@@ -51,7 +51,7 @@
 
 // Avoid warnings
 
-#define UTILS_UNUSED_PARAMETER(x) ((void)x) 
+#define UTILS_UNUSED_PARAMETER(x) ((void)x)
 
 // Init the utility functions
 
index c166de9..4558927 100644 (file)
-//---------------------------------------------------------------------------------
-//
-//  Little Color Management System
-//  Copyright (c) 1998-2010 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 "utils.h"
-
-
-int Verbose = 0;
-
-static char ProgramName[256] = "";
-
-void FatalError(const char *frm, ...)
-{
-    va_list args;
-
-    va_start(args, frm);
-    fprintf(stderr, "[%s fatal error]: ", ProgramName);
-    vfprintf(stderr, frm, args);
-    fprintf(stderr, "\n");
-    va_end(args);   
-
-    exit(1);
-}
-
-// Show errors to the end user (unless quiet option)
-static
-void MyErrorLogHandler(cmsContext ContextID, cmsUInt32Number ErrorCode, const char *Text)
-{
-    if (Verbose >= 0)
-        fprintf(stderr, "[%s]: %s\n", ProgramName, Text);   
-
-    UTILS_UNUSED_PARAMETER(ErrorCode);
-    UTILS_UNUSED_PARAMETER(ContextID);
-}
-
-
-void InitUtils(const char* PName)
-{
-      strncpy(ProgramName, PName, sizeof(ProgramName));
-      ProgramName[sizeof(ProgramName)-1] = 0;
-
-      cmsSetLogErrorHandler(MyErrorLogHandler);
-}
-
-
-// Virtual profiles are handled here.
-cmsHPROFILE OpenStockProfile(cmsContext ContextID, const char* File)
-{   
-       if (!File) 
-            return cmsCreate_sRGBProfileTHR(ContextID);    
-       
-       if (cmsstrcasecmp(File, "*Lab2") == 0)
-                return cmsCreateLab2ProfileTHR(ContextID, NULL);
-
-       if (cmsstrcasecmp(File, "*Lab4") == 0)
-                return cmsCreateLab4ProfileTHR(ContextID, NULL);
-
-       if (cmsstrcasecmp(File, "*Lab") == 0)
-                return cmsCreateLab4ProfileTHR(ContextID, NULL);
-       
-       if (cmsstrcasecmp(File, "*LabD65") == 0) {
-
-           cmsCIExyY D65xyY;
-           
-           cmsWhitePointFromTemp( &D65xyY, 6504);           
-           return cmsCreateLab4ProfileTHR(ContextID, &D65xyY);
-       }
-
-       if (cmsstrcasecmp(File, "*XYZ") == 0)
-                return cmsCreateXYZProfileTHR(ContextID);
-
-       if (cmsstrcasecmp(File, "*Gray22") == 0) {
-
-           cmsToneCurve* Curve = cmsBuildGamma(ContextID, 2.2);
-           cmsHPROFILE hProfile = cmsCreateGrayProfileTHR(ContextID, cmsD50_xyY(), Curve);
-           cmsFreeToneCurve(Curve);
-           return hProfile;
-       }
-
-        if (cmsstrcasecmp(File, "*Gray30") == 0) {
-
-           cmsToneCurve* Curve = cmsBuildGamma(ContextID, 3.0);
-           cmsHPROFILE hProfile = cmsCreateGrayProfileTHR(ContextID, cmsD50_xyY(), Curve);
-           cmsFreeToneCurve(Curve);
-           return hProfile;
-       }
-
-       if (cmsstrcasecmp(File, "*srgb") == 0)
-                return cmsCreate_sRGBProfileTHR(ContextID);
-
-       if (cmsstrcasecmp(File, "*null") == 0)
-                return cmsCreateNULLProfileTHR(ContextID);
-
-       
-       if (cmsstrcasecmp(File, "*Lin2222") == 0) {
-
-            cmsToneCurve*  Gamma = cmsBuildGamma(0, 2.2);
-            cmsToneCurve*  Gamma4[4];
-            cmsHPROFILE hProfile; 
-
-            Gamma4[0] = Gamma4[1] = Gamma4[2] = Gamma4[3] = Gamma;
-            hProfile = cmsCreateLinearizationDeviceLink(cmsSigCmykData, Gamma4);
-            cmsFreeToneCurve(Gamma);
-            return hProfile;
-       }
-
-           
-        return cmsOpenProfileFromFileTHR(ContextID, File, "r");
-}
-
-// Help on available built-ins
-void PrintBuiltins(void)
-{
-     fprintf(stderr, "\nBuilt-in profiles:\n\n");
-     fprintf(stderr, "\t*Lab2  -- D50-based v2 CIEL*a*b\n"
-                     "\t*Lab4  -- D50-based v4 CIEL*a*b\n"
-                     "\t*Lab   -- D50-based v4 CIEL*a*b\n"
-                     "\t*XYZ   -- CIE XYZ (PCS)\n"
-                     "\t*sRGB  -- sRGB color space\n" 
-                     "\t*Gray22 - Monochrome of Gamma 2.2\n"
-                     "\t*Gray30 - Monochrome of Gamma 3.0\n"
-                     "\t*null   - Monochrome black for all input\n"
-                     "\t*Lin2222- CMYK linearization of gamma 2.2 on each channel\n");
-}
-
-
-// Auxiliar for printing information on profile
-static
-void PrintInfo(cmsHPROFILE h, cmsInfoType Info)
-{
-    char* text;
-    int len;
-
-    len = cmsGetProfileInfoASCII(h, Info, "en", "US", NULL, 0);
-    if (len == 0) return;
-
-    text = malloc(len * sizeof(char));
-    if (text == NULL) return;
-
-    cmsGetProfileInfoASCII(h, Info, "en", "US", text, len);
-
-    if (strlen(text) > 0) 
-        printf("%s\n", text);   
-
-    free(text);
-}
-
-
-
-// Displays the colorant table
-static
-void PrintColorantTable(cmsHPROFILE hInput, cmsTagSignature Sig, const char* Title)
-{
-    cmsNAMEDCOLORLIST* list;
-    int i, n;
-
-    if (cmsIsTag(hInput, Sig)) {
-        
-        printf("%s:\n", Title);
-        
-        list = cmsReadTag(hInput, Sig);
-        if (list == NULL) {
-            printf("(Unavailable)\n");
-            return;
-        }
-
-        n = cmsNamedColorCount(list);
-        for (i=0; i < n; i++) {
-
-            char Name[cmsMAX_PATH];
-
-            cmsNamedColorInfo(list, i, Name, NULL, NULL, NULL, NULL);
-            printf("\t%s\n", Name);
-        }
-            
-        printf("\n");
-    }
-    
-}
-
-
-void PrintProfileInformation(cmsHPROFILE hInput)
-{
-    PrintInfo(hInput, cmsInfoDescription);
-    PrintInfo(hInput, cmsInfoManufacturer);
-    PrintInfo(hInput, cmsInfoModel);       
-    PrintInfo(hInput, cmsInfoCopyright);   
-
-    if (Verbose > 2) {
-        
-        PrintColorantTable(hInput, cmsSigColorantTableTag,    "Input colorant table");
-        PrintColorantTable(hInput, cmsSigColorantTableOutTag, "Input colorant out table");      
-    }
-
-    printf("\n");
-}
-
-// -----------------------------------------------------------------------------
-
-
-void PrintRenderingIntents(void)
-{
-    cmsUInt32Number Codes[200];
-    char* Descriptions[200];
-    cmsUInt32Number n, i;
-
-    fprintf(stderr, "%ct<n> rendering intent:\n\n", SW);
-
-    n = cmsGetSupportedIntents(200, Codes, Descriptions);
-
-    for (i=0; i < n; i++) {
-        fprintf(stderr, "\t%d - %s\n", Codes[i], Descriptions[i]);
-    }
-    fprintf(stderr, "\n");
-}
-
-
-
-// ------------------------------------------------------------------------------
-
-cmsBool SaveMemoryBlock(const cmsUInt8Number* Buffer, cmsUInt32Number dwLen, const char* Filename)
-{
-    FILE* out = fopen(Filename, "wb");
-    if (out == NULL) {
-        FatalError("Cannot create '%s'", Filename);
-        return FALSE;
-    }
-
-    if (fwrite(Buffer, 1, dwLen, out) != dwLen) {
-        FatalError("Cannot write %ld bytes to %s", dwLen, Filename);
-        return FALSE;
-    }
-
-    if (fclose(out) != 0) { 
-        FatalError("Error flushing file '%s'", Filename);
-        return FALSE;
-    }
-
-    return TRUE;
-}
-
-// ------------------------------------------------------------------------------
-
-// Return a pixel type on depending on the number of channels
-int PixelTypeFromChanCount(int ColorChannels)
-{
-    switch (ColorChannels) {
-
-        case 1: return PT_GRAY;
-        case 2: return PT_MCH2;
-        case 3: return PT_MCH3;
-        case 4: return PT_CMYK;
-        case 5: return PT_MCH5;
-        case 6: return PT_MCH6;
-        case 7: return PT_MCH7;
-        case 8: return PT_MCH8;
-        case 9: return PT_MCH9;
-        case 10: return PT_MCH10;
-        case 11: return PT_MCH11;
-        case 12: return PT_MCH12;
-        case 13: return PT_MCH13;
-        case 14: return PT_MCH14;
-        case 15: return PT_MCH15;
-
-        default:
-
-            FatalError("What a weird separation of %d channels?!?!", ColorChannels);                
-            return -1;
-    }
-}
-
-
-// ------------------------------------------------------------------------------
-
-// Return number of channels of pixel type
-int ChanCountFromPixelType(int ColorChannels)
-{
-    switch (ColorChannels) {
-
-      case PT_GRAY: return 1;
-
-      case PT_RGB: 
-      case PT_CMY:
-      case PT_Lab:
-      case PT_YUV:
-      case PT_YCbCr: return 3;
-
-      case PT_CMYK: return 4 ;
-      case PT_MCH2: return 2 ;
-      case PT_MCH3: return 3 ;
-      case PT_MCH4: return 4 ;
-      case PT_MCH5: return 5 ;
-      case PT_MCH6: return 6 ;
-      case PT_MCH7: return 7 ;
-      case PT_MCH8: return 8 ;
-      case PT_MCH9: return 9 ;
-      case PT_MCH10: return 10;
-      case PT_MCH11: return 11;
-      case PT_MCH12: return 12;
-      case PT_MCH13: return 12;
-      case PT_MCH14: return 14;
-      case PT_MCH15: return 15;
-
-      default:
-
-          FatalError("Unsupported color space of %d channels", ColorChannels);          
-          return -1;
-    }
-}
-
-
+//---------------------------------------------------------------------------------\r
+//\r
+//  Little Color Management System\r
+//  Copyright (c) 1998-2010 Marti Maria Saguer\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining\r
+// a copy of this software and associated documentation files (the "Software"),\r
+// to deal in the Software without restriction, including without limitation\r
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+// and/or sell copies of the Software, and to permit persons to whom the Software\r
+// is furnished to do so, subject to the following conditions:\r
+//\r
+// The above copyright notice and this permission notice shall be included in\r
+// all copies or substantial portions of the Software.\r
+//\r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO\r
+// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+//---------------------------------------------------------------------------------\r
+//\r
+\r
+#include "utils.h"\r
+\r
+\r
+int Verbose = 0;\r
+\r
+static char ProgramName[256] = "";\r
+\r
+void FatalError(const char *frm, ...)\r
+{\r
+    va_list args;\r
+\r
+    va_start(args, frm);\r
+    fprintf(stderr, "[%s fatal error]: ", ProgramName);\r
+    vfprintf(stderr, frm, args);\r
+    fprintf(stderr, "\n");\r
+    va_end(args);\r
+\r
+    exit(1);\r
+}\r
+\r
+// Show errors to the end user (unless quiet option)\r
+static\r
+void MyErrorLogHandler(cmsContext ContextID, cmsUInt32Number ErrorCode, const char *Text)\r
+{\r
+    if (Verbose >= 0)\r
+        fprintf(stderr, "[%s]: %s\n", ProgramName, Text);\r
+\r
+    UTILS_UNUSED_PARAMETER(ErrorCode);\r
+    UTILS_UNUSED_PARAMETER(ContextID);\r
+}\r
+\r
+\r
+void InitUtils(const char* PName)\r
+{\r
+      strncpy(ProgramName, PName, sizeof(ProgramName));\r
+      ProgramName[sizeof(ProgramName)-1] = 0;\r
+\r
+      cmsSetLogErrorHandler(MyErrorLogHandler);\r
+}\r
+\r
+\r
+// Virtual profiles are handled here.\r
+cmsHPROFILE OpenStockProfile(cmsContext ContextID, const char* File)\r
+{\r
+       if (!File)\r
+            return cmsCreate_sRGBProfileTHR(ContextID);\r
+\r
+       if (cmsstrcasecmp(File, "*Lab2") == 0)\r
+                return cmsCreateLab2ProfileTHR(ContextID, NULL);\r
+\r
+       if (cmsstrcasecmp(File, "*Lab4") == 0)\r
+                return cmsCreateLab4ProfileTHR(ContextID, NULL);\r
+\r
+       if (cmsstrcasecmp(File, "*Lab") == 0)\r
+                return cmsCreateLab4ProfileTHR(ContextID, NULL);\r
+\r
+       if (cmsstrcasecmp(File, "*LabD65") == 0) {\r
+\r
+           cmsCIExyY D65xyY;\r
+\r
+           cmsWhitePointFromTemp( &D65xyY, 6504);\r
+           return cmsCreateLab4ProfileTHR(ContextID, &D65xyY);\r
+       }\r
+\r
+       if (cmsstrcasecmp(File, "*XYZ") == 0)\r
+                return cmsCreateXYZProfileTHR(ContextID);\r
+\r
+       if (cmsstrcasecmp(File, "*Gray22") == 0) {\r
+\r
+           cmsToneCurve* Curve = cmsBuildGamma(ContextID, 2.2);\r
+           cmsHPROFILE hProfile = cmsCreateGrayProfileTHR(ContextID, cmsD50_xyY(), Curve);\r
+           cmsFreeToneCurve(Curve);\r
+           return hProfile;\r
+       }\r
+\r
+        if (cmsstrcasecmp(File, "*Gray30") == 0) {\r
+\r
+           cmsToneCurve* Curve = cmsBuildGamma(ContextID, 3.0);\r
+           cmsHPROFILE hProfile = cmsCreateGrayProfileTHR(ContextID, cmsD50_xyY(), Curve);\r
+           cmsFreeToneCurve(Curve);\r
+           return hProfile;\r
+       }\r
+\r
+       if (cmsstrcasecmp(File, "*srgb") == 0)\r
+                return cmsCreate_sRGBProfileTHR(ContextID);\r
+\r
+       if (cmsstrcasecmp(File, "*null") == 0)\r
+                return cmsCreateNULLProfileTHR(ContextID);\r
+\r
+\r
+       if (cmsstrcasecmp(File, "*Lin2222") == 0) {\r
+\r
+            cmsToneCurve*  Gamma = cmsBuildGamma(0, 2.2);\r
+            cmsToneCurve*  Gamma4[4];\r
+            cmsHPROFILE hProfile;\r
+\r
+            Gamma4[0] = Gamma4[1] = Gamma4[2] = Gamma4[3] = Gamma;\r
+            hProfile = cmsCreateLinearizationDeviceLink(cmsSigCmykData, Gamma4);\r
+            cmsFreeToneCurve(Gamma);\r
+            return hProfile;\r
+       }\r
+\r
+\r
+        return cmsOpenProfileFromFileTHR(ContextID, File, "r");\r
+}\r
+\r
+// Help on available built-ins\r
+void PrintBuiltins(void)\r
+{\r
+     fprintf(stderr, "\nBuilt-in profiles:\n\n");\r
+     fprintf(stderr, "\t*Lab2  -- D50-based v2 CIEL*a*b\n"\r
+                     "\t*Lab4  -- D50-based v4 CIEL*a*b\n"\r
+                     "\t*Lab   -- D50-based v4 CIEL*a*b\n"\r
+                     "\t*XYZ   -- CIE XYZ (PCS)\n"\r
+                     "\t*sRGB  -- sRGB color space\n"\r
+                     "\t*Gray22 - Monochrome of Gamma 2.2\n"\r
+                     "\t*Gray30 - Monochrome of Gamma 3.0\n"\r
+                     "\t*null   - Monochrome black for all input\n"\r
+                     "\t*Lin2222- CMYK linearization of gamma 2.2 on each channel\n");\r
+}\r
+\r
+\r
+// Auxiliar for printing information on profile\r
+static\r
+void PrintInfo(cmsHPROFILE h, cmsInfoType Info)\r
+{\r
+    char* text;\r
+    int len;\r
+\r
+    len = cmsGetProfileInfoASCII(h, Info, "en", "US", NULL, 0);\r
+    if (len == 0) return;\r
+\r
+    text = malloc(len * sizeof(char));\r
+    if (text == NULL) return;\r
+\r
+    cmsGetProfileInfoASCII(h, Info, "en", "US", text, len);\r
+\r
+    if (strlen(text) > 0)\r
+        printf("%s\n", text);\r
+\r
+    free(text);\r
+}\r
+\r
+\r
+\r
+// Displays the colorant table\r
+static\r
+void PrintColorantTable(cmsHPROFILE hInput, cmsTagSignature Sig, const char* Title)\r
+{\r
+    cmsNAMEDCOLORLIST* list;\r
+    int i, n;\r
+\r
+    if (cmsIsTag(hInput, Sig)) {\r
+\r
+        printf("%s:\n", Title);\r
+\r
+        list = cmsReadTag(hInput, Sig);\r
+        if (list == NULL) {\r
+            printf("(Unavailable)\n");\r
+            return;\r
+        }\r
+\r
+        n = cmsNamedColorCount(list);\r
+        for (i=0; i < n; i++) {\r
+\r
+            char Name[cmsMAX_PATH];\r
+\r
+            cmsNamedColorInfo(list, i, Name, NULL, NULL, NULL, NULL);\r
+            printf("\t%s\n", Name);\r
+        }\r
+\r
+        printf("\n");\r
+    }\r
+\r
+}\r
+\r
+\r
+void PrintProfileInformation(cmsHPROFILE hInput)\r
+{\r
+    PrintInfo(hInput, cmsInfoDescription);\r
+    PrintInfo(hInput, cmsInfoManufacturer);\r
+    PrintInfo(hInput, cmsInfoModel);\r
+    PrintInfo(hInput, cmsInfoCopyright);\r
+\r
+    if (Verbose > 2) {\r
+\r
+        PrintColorantTable(hInput, cmsSigColorantTableTag,    "Input colorant table");\r
+        PrintColorantTable(hInput, cmsSigColorantTableOutTag, "Input colorant out table");\r
+    }\r
+\r
+    printf("\n");\r
+}\r
+\r
+// -----------------------------------------------------------------------------\r
+\r
+\r
+void PrintRenderingIntents(void)\r
+{\r
+    cmsUInt32Number Codes[200];\r
+    char* Descriptions[200];\r
+    cmsUInt32Number n, i;\r
+\r
+    fprintf(stderr, "%ct<n> rendering intent:\n\n", SW);\r
+\r
+    n = cmsGetSupportedIntents(200, Codes, Descriptions);\r
+\r
+    for (i=0; i < n; i++) {\r
+        fprintf(stderr, "\t%d - %s\n", Codes[i], Descriptions[i]);\r
+    }\r
+    fprintf(stderr, "\n");\r
+}\r
+\r
+\r
+\r
+// ------------------------------------------------------------------------------\r
+\r
+cmsBool SaveMemoryBlock(const cmsUInt8Number* Buffer, cmsUInt32Number dwLen, const char* Filename)\r
+{\r
+    FILE* out = fopen(Filename, "wb");\r
+    if (out == NULL) {\r
+        FatalError("Cannot create '%s'", Filename);\r
+        return FALSE;\r
+    }\r
+\r
+    if (fwrite(Buffer, 1, dwLen, out) != dwLen) {\r
+        FatalError("Cannot write %ld bytes to %s", dwLen, Filename);\r
+        return FALSE;\r
+    }\r
+\r
+    if (fclose(out) != 0) {\r
+        FatalError("Error flushing file '%s'", Filename);\r
+        return FALSE;\r
+    }\r
+\r
+    return TRUE;\r
+}\r
+\r
+// ------------------------------------------------------------------------------\r
+\r
+// Return a pixel type on depending on the number of channels\r
+int PixelTypeFromChanCount(int ColorChannels)\r
+{\r
+    switch (ColorChannels) {\r
+\r
+        case 1: return PT_GRAY;\r
+        case 2: return PT_MCH2;\r
+        case 3: return PT_MCH3;\r
+        case 4: return PT_CMYK;\r
+        case 5: return PT_MCH5;\r
+        case 6: return PT_MCH6;\r
+        case 7: return PT_MCH7;\r
+        case 8: return PT_MCH8;\r
+        case 9: return PT_MCH9;\r
+        case 10: return PT_MCH10;\r
+        case 11: return PT_MCH11;\r
+        case 12: return PT_MCH12;\r
+        case 13: return PT_MCH13;\r
+        case 14: return PT_MCH14;\r
+        case 15: return PT_MCH15;\r
+\r
+        default:\r
+\r
+            FatalError("What a weird separation of %d channels?!?!", ColorChannels);\r
+            return -1;\r
+    }\r
+}\r
+\r
+\r
+// ------------------------------------------------------------------------------\r
+\r
+// Return number of channels of pixel type\r
+int ChanCountFromPixelType(int ColorChannels)\r
+{\r
+    switch (ColorChannels) {\r
+\r
+      case PT_GRAY: return 1;\r
+\r
+      case PT_RGB:\r
+      case PT_CMY:\r
+      case PT_Lab:\r
+      case PT_YUV:\r
+      case PT_YCbCr: return 3;\r
+\r
+      case PT_CMYK: return 4 ;\r
+      case PT_MCH2: return 2 ;\r
+      case PT_MCH3: return 3 ;\r
+      case PT_MCH4: return 4 ;\r
+      case PT_MCH5: return 5 ;\r
+      case PT_MCH6: return 6 ;\r
+      case PT_MCH7: return 7 ;\r
+      case PT_MCH8: return 8 ;\r
+      case PT_MCH9: return 9 ;\r
+      case PT_MCH10: return 10;\r
+      case PT_MCH11: return 11;\r
+      case PT_MCH12: return 12;\r
+      case PT_MCH13: return 12;\r
+      case PT_MCH14: return 14;\r
+      case PT_MCH15: return 15;\r
+\r
+      default:\r
+\r
+          FatalError("Unsupported color space of %d channels", ColorChannels);\r
+          return -1;\r
+    }\r
+}\r
+\r
+\r
index 3eb08fe..7f3dc54 100644 (file)
@@ -1,16 +1,16 @@
 /*
-    getopt.c 
+    getopt.c
 
 */
 
 #include <errno.h>
 #include <string.h>
 #include <stdio.h>
+
 int     xoptind = 1;    /* index of which argument is next  */
 char   *xoptarg;        /* pointer to argument of current option */
 int     xopterr = 0;    /* allow error message  */
+
 static  char   *letP = NULL;    /* remember next option char's location */
 char    SW = '-';                              /* DOS switch character, either '-' or '/' */
 
diff --git a/utils/delphi/lcms2.dll b/utils/delphi/lcms2.dll
deleted file mode 100755 (executable)
index 0dd48eb..0000000
Binary files a/utils/delphi/lcms2.dll and /dev/null differ
index e632631..19e3f87 100755 (executable)
@@ -1615,6 +1615,8 @@ FUNCTION  cmsGDBCheckPoint(hGBD: cmsHANDLE; Lab: LPcmsCIELab): cmsBool; StdCall;
 \r
 // Estimate the black point\r
 FUNCTION cmsDetectBlackPoint( BlackPoint: LPcmsCIEXYZ; hProfile: cmsHPROFILE; Intent: cmsUInt32Number; dwFlags: cmsUInt32Number): cmsBool; StdCall;\r
+FUNCTION cmsDetectDestinationBlackPoint( BlackPoint: LPcmsCIEXYZ; hProfile: cmsHPROFILE; Intent: cmsUInt32Number; dwFlags: cmsUInt32Number): cmsBool; StdCall;\r
+\r
 \r
 // Estimate total area coverage\r
 FUNCTION cmsDetectTAC(hProfile: cmsHPROFILE): cmsFloat64Number; StdCall;\r
@@ -2100,6 +2102,7 @@ FUNCTION  cmsGDBCompute(hGDB: cmsHANDLE; dwFlags: cmsUInt32Number): cmsBool; Std
 FUNCTION  cmsGDBCheckPoint(hGBD: cmsHANDLE; Lab: LPcmsCIELab): cmsBool; StdCall; external 'lcms2.dll';\r
 \r
 FUNCTION cmsDetectBlackPoint( BlackPoint: LPcmsCIEXYZ; hProfile: cmsHPROFILE; Intent: cmsUInt32Number; dwFlags: cmsUInt32Number): cmsBool; StdCall; external 'lcms2.dll';\r
+FUNCTION cmsDetectDestinationBlackPoint( BlackPoint: LPcmsCIEXYZ; hProfile: cmsHPROFILE; Intent: cmsUInt32Number; dwFlags: cmsUInt32Number): cmsBool; StdCall; external 'lcms2.dll';\r
 \r
 FUNCTION cmsDetectTAC(hProfile: cmsHPROFILE): cmsFloat64Number; StdCall; external 'lcms2.dll';\r
 \r
index 25f7079..8ac5f75 100644 (file)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.3 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -94,6 +94,12 @@ am__nobase_list = $(am__nobase_strip_setup); \
 am__base_list = \
   sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
   sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__uninstall_files_from_dir = { \
+  test -z "$$files" \
+    || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
+    || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
+         $(am__cd) "$$dir" && rm -f $$files; }; \
+  }
 man1dir = $(mandir)/man1
 NROFF = nroff
 MANS = $(man_MANS)
@@ -320,7 +326,7 @@ clean-binPROGRAMS:
        list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
        echo " rm -f" $$list; \
        rm -f $$list
-jpgicc$(EXEEXT): $(jpgicc_OBJECTS) $(jpgicc_DEPENDENCIES) 
+jpgicc$(EXEEXT): $(jpgicc_OBJECTS) $(jpgicc_DEPENDENCIES) $(EXTRA_jpgicc_DEPENDENCIES) 
        @rm -f jpgicc$(EXEEXT)
        $(jpgicc_LINK) $(jpgicc_OBJECTS) $(jpgicc_LDADD) $(LIBS)
 
@@ -424,9 +430,7 @@ uninstall-man1:
          sed -n '/\.1[a-z]*$$/p'; \
        } | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^1][0-9a-z]*$$,1,;x' \
              -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \
-       test -z "$$files" || { \
-         echo " ( cd '$(DESTDIR)$(man1dir)' && rm -f" $$files ")"; \
-         cd "$(DESTDIR)$(man1dir)" && rm -f $$files; }
+       dir='$(DESTDIR)$(man1dir)'; $(am__uninstall_files_from_dir)
 
 ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
        list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
@@ -540,10 +544,15 @@ install-am: all-am
 
 installcheck: installcheck-am
 install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-         install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-         `test -z '$(STRIP)' || \
-           echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
 mostlyclean-generic:
 
 clean-generic:
index 9b902f6..449c6c8 100644 (file)
-//---------------------------------------------------------------------------------
-//
-//  Little Color Management System
-//  Copyright (c) 1998-2010 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 program does apply profiles to (some) JPEG files
-
-
-#include "utils.h"
-
-#include "jpeglib.h"
-#include "iccjpeg.h"
-
-// Flags
-static cmsBool BlackPointCompensation = FALSE;
-static cmsBool IgnoreEmbedded         = FALSE;
-static cmsBool GamutCheck             = FALSE;
-static cmsBool lIsITUFax              = FALSE;
-static cmsBool lIsPhotoshopApp13      = FALSE;
-static cmsBool lIsEXIF;
-static cmsBool lIsDeviceLink          = FALSE;
-static cmsBool EmbedProfile           = FALSE;
-
-static const char* SaveEmbedded = NULL;
-
-static int Intent                  = INTENT_PERCEPTUAL;
-static int ProofingIntent          = INTENT_PERCEPTUAL;
-static int PrecalcMode             = 1;
-
-static int jpegQuality             = 75;
-
-static cmsFloat64Number ObserverAdaptationState = 0;
-
-
-static char *cInpProf  = NULL;
-static char *cOutProf  = NULL;
-static char *cProofing = NULL;
-
-static FILE * InFile;
-static FILE * OutFile;
-
-static struct jpeg_decompress_struct Decompressor;
-static struct jpeg_compress_struct   Compressor;
-
-
-static struct my_error_mgr {
-
-    struct  jpeg_error_mgr pub;   // "public" fields
-    void*   Cargo;                // "private" fields
-
-} ErrorHandler;
-
-
-cmsUInt16Number Alarm[4] = {128,128,128,0};
-
-// Out of mem
-static
-void OutOfMem(size_t size)
-{
-    FatalError("Out of memory on allocating %d bytes.", size);
-}
-
-
-static
-void my_error_exit (j_common_ptr cinfo)
-{  
-  char buffer[JMSG_LENGTH_MAX];
-  
-  (*cinfo->err->format_message) (cinfo, buffer);
-  FatalError(buffer);
-}
-
-/*
-Definition of the APPn Markers Defined for continuous-tone G3FAX
-
-The application code APP1 initiates identification of the image as 
-a G3FAX application and defines the spatial resolution and subsampling. 
-This marker directly follows the SOI marker. The data format will be as follows:
-
-X'FFE1' (APP1), length, FAX identifier, version, spatial resolution.
-
-The above terms are defined as follows:
-
-Length: (Two octets) Total APP1 field octet count including the octet count itself, but excluding the APP1
-marker.
-
-FAX identifier: (Six octets) X'47', X'33', X'46', X'41', X'58', X'00'. This X'00'-terminated string "G3FAX"
-uniquely identifies this APP1 marker.
-
-Version: (Two octets) X'07CA'. This string specifies the year of approval of the standard, for identification
-in the case of future revision (for example, 1994).
-
-Spatial Resolution: (Two octets) Lightness pixel density in pels/25.4 mm. The basic value is 200. Allowed values are
-100, 200, 300, 400, 600 and 1200 pels/25.4 mm, with square (or equivalent) pels.
-
-NOTE \96 The functional equivalence of inch-based and mm-based resolutions is maintained. For example, the 200 Ã— 200
-*/
-
-static
-cmsBool IsITUFax(jpeg_saved_marker_ptr ptr)
-{
-       while (ptr) 
-       {
-        if (ptr -> marker == (JPEG_APP0 + 1) && ptr -> data_length > 5) {
-            
-                       const char* data = (const char*) ptr -> data;
-
-                       if (strcmp(data, "G3FAX") == 0) return TRUE;                                
-               }
-
-               ptr = ptr -> next;
-       }
-
-       return FALSE;
-}
-
-// Save a ITU T.42/Fax marker with defaults on boundaries. This is the only mode we support right now.
-static
-void SetITUFax(j_compress_ptr cinfo)
-{    
-       unsigned char Marker[] = "G3FAX\x00\0x07\xCA\x00\xC8";
-
-       jpeg_write_marker(cinfo, (JPEG_APP0 + 1), Marker, 10);      
-}
-
-
-// Build a profile for decoding ITU T.42/Fax JPEG streams. 
-// The profile has an additional ability in the input direction of
-// gamut compress values between 85 < a < -85 and -75 < b < 125. This conforms
-// the default range for ITU/T.42 -- See RFC 2301, section 6.2.3 for details
-
-//  L*  =   [0, 100]
-//  a*  =   [\9685, 85]
-//  b*  =   [\9675, 125]
-
-
-// These functions does convert the encoding of ITUFAX to floating point
-// and vice-versa. No gamut mapping is performed yet.
-
-static
-void ITU2Lab(const cmsUInt16Number In[3], cmsCIELab* Lab)
-{
-       Lab -> L = (double) In[0] / 655.35;
-       Lab -> a = (double) 170.* (In[1] - 32768.) / 65535.;
-       Lab -> b = (double) 200.* (In[2] - 24576.) / 65535.;
-}
-
-static
-void Lab2ITU(const cmsCIELab* Lab, cmsUInt16Number Out[3])
-{
-       Out[0] = (cmsUInt16Number) floor((double) (Lab -> L / 100.)* 65535. );
-       Out[1] = (cmsUInt16Number) floor((double) (Lab -> a / 170.)* 65535. + 32768. );
-       Out[2] = (cmsUInt16Number) floor((double) (Lab -> b / 200.)* 65535. + 24576. );
-}
-
-// These are the samplers-- They are passed as callbacks to cmsStageSampleCLut16bit()
-// then, cmsSample3DGrid() will sweel whole Lab gamut calling these functions
-// once for each node. In[] will contain the Lab PCS value to convert to ITUFAX
-// on PCS2ITU, or the ITUFAX value to convert to Lab in ITU2PCS
-// You can change the number of sample points if desired, the algorithm will
-// remain same. 33 points gives good accurancy, but you can reduce to 22 or less
-// is space is critical
-
-#define GRID_POINTS 33
-
-static
-int PCS2ITU(register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void*  Cargo)
-{      
-       cmsCIELab Lab;
-
-       cmsLabEncoded2Float(&Lab, In);    
-       cmsDesaturateLab(&Lab, 85, -85, 125, -75);    // This function does the necessary gamut remapping  
-       Lab2ITU(&Lab, Out);
-       return TRUE;
-
-    UTILS_UNUSED_PARAMETER(Cargo);
-}
-
-
-static
-int ITU2PCS( register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void*  Cargo)
-{   
-       cmsCIELab Lab;
-
-       ITU2Lab(In, &Lab);
-       cmsFloat2LabEncoded(Out, &Lab);    
-       return TRUE;
-
-    UTILS_UNUSED_PARAMETER(Cargo);
-}
-
-// This function does create the virtual input profile, which decodes ITU to the profile connection space
-static
-cmsHPROFILE CreateITU2PCS_ICC(void)
-{      
-       cmsHPROFILE hProfile;
-       cmsPipeline* AToB0;
-       cmsStage* ColorMap;
-       
-       AToB0 = cmsPipelineAlloc(0, 3, 3);
-       if (AToB0 == NULL) return NULL;
-
-       ColorMap = cmsStageAllocCLut16bit(0, GRID_POINTS, 3, 3, NULL);
-       if (ColorMap == NULL) return NULL;
-
-    cmsPipelineInsertStage(AToB0, cmsAT_BEGIN, ColorMap);
-       cmsStageSampleCLut16bit(ColorMap, ITU2PCS, NULL, 0);
-
-       hProfile = cmsCreateProfilePlaceholder(0);
-       if (hProfile == NULL) {
-               cmsPipelineFree(AToB0);
-               return NULL;
-       }
-       
-       cmsWriteTag(hProfile, cmsSigAToB0Tag, AToB0); 
-       cmsSetColorSpace(hProfile, cmsSigLabData);
-       cmsSetPCS(hProfile, cmsSigLabData);
-       cmsSetDeviceClass(hProfile, cmsSigColorSpaceClass);      
-       cmsPipelineFree(AToB0);
-
-       return hProfile;
-}
-
-
-// This function does create the virtual output profile, with the necessary gamut mapping 
-static
-cmsHPROFILE CreatePCS2ITU_ICC(void)
-{
-    cmsHPROFILE hProfile;
-    cmsPipeline* BToA0;
-    cmsStage* ColorMap;
-        
-    BToA0 = cmsPipelineAlloc(0, 3, 3);
-    if (BToA0 == NULL) return NULL;
-
-    ColorMap = cmsStageAllocCLut16bit(0, GRID_POINTS, 3, 3, NULL);
-    if (ColorMap == NULL) return NULL;
-
-    cmsPipelineInsertStage(BToA0, cmsAT_BEGIN, ColorMap);
-    cmsStageSampleCLut16bit(ColorMap, PCS2ITU, NULL, 0);
-
-    hProfile = cmsCreateProfilePlaceholder(0);
-    if (hProfile == NULL) {
-        cmsPipelineFree(BToA0);
-        return NULL;
-    }
-
-    cmsWriteTag(hProfile, cmsSigBToA0Tag, BToA0); 
-    cmsSetColorSpace(hProfile, cmsSigLabData);
-    cmsSetPCS(hProfile, cmsSigLabData);
-    cmsSetDeviceClass(hProfile, cmsSigColorSpaceClass); 
-
-    cmsPipelineFree(BToA0);
-
-    return hProfile;
-}
-
-
-
-#define PS_FIXED_TO_FLOAT(h, l) ((float) (h) + ((float) (l)/(1<<16)))
-
-static
-cmsBool ProcessPhotoshopAPP13(JOCTET FAR *data, int datalen)
-{
-    int i;
-
-    for (i = 14; i < datalen; )
-    {
-        long len;
-        unsigned int type;
-                
-        if (!(GETJOCTET(data[i]  ) == 0x38 &&
-              GETJOCTET(data[i+1]) == 0x42 &&
-              GETJOCTET(data[i+2]) == 0x49 &&
-              GETJOCTET(data[i+3]) == 0x4D)) break; // Not recognized
-                    
-        i += 4; // identifying string 
-        
-        type = (unsigned int) (GETJOCTET(data[i]<<8) + GETJOCTET(data[i+1]));
-
-        i += 2; // resource type 
-        
-        i += GETJOCTET(data[i]) + ((GETJOCTET(data[i]) & 1) ? 1 : 2);   // resource name 
-        
-        len = ((((GETJOCTET(data[i]<<8) + GETJOCTET(data[i+1]))<<8) + 
-                         GETJOCTET(data[i+2]))<<8) + GETJOCTET(data[i+3]);
-
-        i += 4; // Size 
-        
-        if (type == 0x03ED && len >= 16) {
-            
-            Decompressor.X_density = (UINT16) PS_FIXED_TO_FLOAT(GETJOCTET(data[i]<<8) + GETJOCTET(data[i+1]),
-                                                 GETJOCTET(data[i+2]<<8) + GETJOCTET(data[i+3]));
-            Decompressor.Y_density = (UINT16) PS_FIXED_TO_FLOAT(GETJOCTET(data[i+8]<<8) + GETJOCTET(data[i+9]),
-                                                 GETJOCTET(data[i+10]<<8) + GETJOCTET(data[i+11]));
-            
-            // Set the density unit to 1 since the 
-            // Vertical and Horizontal resolutions 
-            // are specified in Pixels per inch 
-
-            Decompressor.density_unit = 0x01;
-            return TRUE;
-            
-        }
-                
-        i += len + ((len & 1) ? 1 : 0);   // Alignment             
-    }
-    return FALSE;
-}
-
-
-static
-cmsBool HandlePhotoshopAPP13(jpeg_saved_marker_ptr ptr)
-{
-    while (ptr) {
-        
-        if (ptr -> marker == (JPEG_APP0 + 13) && ptr -> data_length > 9)
-        {    
-            JOCTET FAR* data = ptr -> data;    
-            
-            if(GETJOCTET(data[0]) == 0x50 &&
-               GETJOCTET(data[1]) == 0x68 &&
-               GETJOCTET(data[2]) == 0x6F &&
-               GETJOCTET(data[3]) == 0x74 &&
-               GETJOCTET(data[4]) == 0x6F &&
-               GETJOCTET(data[5]) == 0x73 &&
-               GETJOCTET(data[6]) == 0x68 &&
-               GETJOCTET(data[7]) == 0x6F &&
-               GETJOCTET(data[8]) == 0x70) {
-             
-                ProcessPhotoshopAPP13(data, ptr -> data_length);
-                return TRUE;
-            }
-        }
-        
-        ptr = ptr -> next;
-    }
-    
-    return FALSE;    
-}
-
-
-typedef unsigned short uint16_t;
-typedef unsigned char uint8_t;
-typedef unsigned int uint32_t;
-
-#define INTEL_BYTE_ORDER 0x4949
-#define XRESOLUTION 0x011a
-#define YRESOLUTION 0x011b
-#define RESOLUTION_UNIT 0x128
-
-// Read a 16-bit word
-static
-uint16_t read16(uint8_t* arr, int pos,  int swapBytes) 
-{ 
-    uint8_t b1 = arr[pos];
-    uint8_t b2 = arr[pos+1];
-    
-    return (swapBytes) ?  ((b2 << 8) | b1) : ((b1 << 8) | b2);
-}
-
-
-// Read a 32-bit word
-static
-uint32_t read32(uint8_t* arr, int pos,  int swapBytes)
-{
-  
-    if(!swapBytes) {
-
-        return (arr[pos]   << 24) | 
-               (arr[pos+1] << 16) | 
-               (arr[pos+2] << 8) | 
-                arr[pos+3];
-    }
-
-    return arr[pos] | 
-           (arr[pos+1] << 8) | 
-           (arr[pos+2] << 16) | 
-           (arr[pos+3] << 24);
-}
-
-
-
-static
-int read_tag(uint8_t* arr, int pos,  int swapBytes, void* dest)
-{
-        // Format should be 5 over here (rational)
-    uint32_t format = read16(arr, pos + 2, swapBytes);
-    // Components should be 1
-    uint32_t components = read32(arr, pos + 4, swapBytes);
-    // Points to the value
-    uint32_t offset;
-    
-    // sanity
-    if (components != 1) return 0;
-
-    if (format == 3) 
-        offset = pos + 8;
-    else
-        offset =  read32(arr, pos + 8, swapBytes);
-
-    switch (format) {
-
-    case 5: // Rational
-          {
-          double num = read32(arr, offset, swapBytes);
-          double den = read32(arr, offset + 4, swapBytes);
-          *(double *) dest = num / den;
-          }
-          break;
-
-    case 3: // uint 16
-        *(int*) dest = read16(arr, offset, swapBytes);
-        break;
-
-    default:  return 0;
-    }
-
-    return 1;
-}
-
-
-
-// Handler for EXIF data
-static
-    cmsBool HandleEXIF(struct jpeg_decompress_struct* cinfo)
-{
-    jpeg_saved_marker_ptr ptr;
-    uint32_t ifd_ofs;
-    int pos = 0, swapBytes = 0;
-    uint32_t i, numEntries;
-    double XRes = -1, YRes = -1;
-    int Unit = 2; // Inches
-
-
-    for (ptr = cinfo ->marker_list; ptr; ptr = ptr ->next) {
-
-        if ((ptr ->marker == JPEG_APP0+1) && ptr ->data_length > 6) {
-            JOCTET FAR* data = ptr -> data;   
-
-            if (memcmp(data, "Exif\0\0", 6) == 0) {
-
-                data += 6; // Skip EXIF marker
-
-                // 8 byte TIFF header
-                // first two determine byte order
-                pos = 0;
-                if (read16(data, pos, 0) == INTEL_BYTE_ORDER) {
-                    swapBytes = 1;
-                }
-
-                pos += 2;
-
-                // next two bytes are always 0x002A (TIFF version)
-                pos += 2;
-
-                // offset to Image File Directory (includes the previous 8 bytes)
-                ifd_ofs = read32(data, pos, swapBytes);
-
-                // Search the directory for resolution tags          
-                numEntries = read16(data, ifd_ofs, swapBytes);
-
-                for (i=0; i < numEntries; i++) {
-
-                    uint32_t entryOffset = ifd_ofs + 2 + (12 * i);
-                    uint32_t tag = read16(data, entryOffset, swapBytes);
-
-                    switch (tag) {
-
-                    case RESOLUTION_UNIT:
-                        if (!read_tag(data, entryOffset, swapBytes, &Unit)) return FALSE;
-                        break;
-
-                    case XRESOLUTION:
-                        if (!read_tag(data, entryOffset, swapBytes, &XRes)) return FALSE;
-                        break;
-
-                    case YRESOLUTION:
-                        if (!read_tag(data, entryOffset, swapBytes, &YRes)) return FALSE;
-                        break;
-
-                    default:;
-                    }
-
-                }
-
-                // Proceed if all found
-
-                if (XRes != -1 && YRes != -1) 
-                {
-
-                    // 1 = None 
-                    // 2 = inches 
-                    // 3 = cm
-
-                    switch (Unit) {
-
-                    case 2:
-                    
-                        cinfo ->X_density = (UINT16) floor(XRes + 0.5);
-                        cinfo ->Y_density = (UINT16) floor(YRes + 0.5);
-                        break;
-
-                    case 1:
-
-                        cinfo ->X_density = (UINT16) floor(XRes * 2.54 + 0.5);
-                        cinfo ->Y_density = (UINT16) floor(YRes * 2.54 + 0.5);
-                        break;
-
-                    default: return FALSE;
-                    }
-
-                    cinfo ->density_unit = 1;  /* 1 for dots/inch, or 2 for dots/cm.*/
-
-                }
-
-
-            }
-        }    
-    }
-    return FALSE;
-}
-
-
-static
-cmsBool OpenInput(const char* FileName)
-{
-       int m;
-
-       lIsITUFax = FALSE;   
-       InFile  = fopen(FileName, "rb");
-       if (InFile == NULL) {
-               FatalError("Cannot open '%s'", FileName);        
-       }
-
-       // Now we can initialize the JPEG decompression object.
-       Decompressor.err                 = jpeg_std_error(&ErrorHandler.pub);
-       ErrorHandler.pub.error_exit      = my_error_exit;
-       ErrorHandler.pub.output_message  = my_error_exit;
-
-       jpeg_create_decompress(&Decompressor);
-       jpeg_stdio_src(&Decompressor, InFile);
-
-       for (m = 0; m < 16; m++)
-               jpeg_save_markers(&Decompressor, JPEG_APP0 + m, 0xFFFF);
-
-       // setup_read_icc_profile(&Decompressor);  
-
-       fseek(InFile, 0, SEEK_SET);
-       jpeg_read_header(&Decompressor, TRUE);
-
-       return TRUE;
-}
-
-
-static
-cmsBool OpenOutput(const char* FileName)
-{
-
-       OutFile = fopen(FileName, "wb");
-       if (OutFile == NULL) {
-               FatalError("Cannot create '%s'", FileName);
-
-       }
-
-       Compressor.err                   = jpeg_std_error(&ErrorHandler.pub);
-       ErrorHandler.pub.error_exit      = my_error_exit;
-       ErrorHandler.pub.output_message  = my_error_exit;
-
-       Compressor.input_components = Compressor.num_components = 4;
-
-       jpeg_create_compress(&Compressor);
-       jpeg_stdio_dest(&Compressor, OutFile);  
-       return TRUE;
-}
-
-static
-cmsBool Done(void)
-{
-       jpeg_destroy_decompress(&Decompressor);
-       jpeg_destroy_compress(&Compressor);
-       return fclose(InFile) + fclose(OutFile);
-
-}
-
-
-// Build up the pixeltype descriptor
-
-static
-cmsUInt32Number GetInputPixelType(void)
-{
-     int space, bps, extra, ColorChannels, Flavor;
-        
-     lIsITUFax         = IsITUFax(Decompressor.marker_list);
-     lIsPhotoshopApp13 = HandlePhotoshopAPP13(Decompressor.marker_list);
-     lIsEXIF           = HandleEXIF(&Decompressor);
-
-     ColorChannels = Decompressor.num_components;
-     extra  = 0;            // Alpha = None
-     bps    = 1;            // 8 bits
-     Flavor = 0;            // Vanilla
-
-     if (lIsITUFax) {
-
-        space = PT_Lab;
-        Decompressor.out_color_space = JCS_YCbCr;  // Fake to don't touch
-     }
-     else
-     switch (Decompressor.jpeg_color_space) {
-
-     case JCS_GRAYSCALE:        // monochrome
-              space = PT_GRAY;
-              Decompressor.out_color_space = JCS_GRAYSCALE;
-              break;
-
-     case JCS_RGB:             // red/green/blue
-              space = PT_RGB;
-              Decompressor.out_color_space = JCS_RGB;
-              break;
-
-     case JCS_YCbCr:               // Y/Cb/Cr (also known as YUV)
-              space = PT_RGB;      // Let IJG code to do the conversion
-              Decompressor.out_color_space = JCS_RGB;   
-              break;
-
-     case JCS_CMYK:            // C/M/Y/K
-              space = PT_CMYK;
-              Decompressor.out_color_space = JCS_CMYK;
-              if (Decompressor.saw_Adobe_marker)            // Adobe keeps CMYK inverted, so change flavor
-                                Flavor = 1;                 // from vanilla to chocolate
-              break;
-
-     case JCS_YCCK:            // Y/Cb/Cr/K              
-              space = PT_CMYK;
-              Decompressor.out_color_space = JCS_CMYK;
-              if (Decompressor.saw_Adobe_marker)            // ditto
-                                Flavor = 1;                 
-              break;
-
-     default:
-              FatalError("Unsupported color space (0x%x)", Decompressor.jpeg_color_space);
-              return 0;
-     }
-
-     return (EXTRA_SH(extra)|CHANNELS_SH(ColorChannels)|BYTES_SH(bps)|COLORSPACE_SH(space)|FLAVOR_SH(Flavor));
-}
-
-
-// Rearrange pixel type to build output descriptor
-static
-cmsUInt32Number ComputeOutputFormatDescriptor(cmsUInt32Number dwInput, int OutColorSpace)
-{
-       int IsPlanar  = T_PLANAR(dwInput);
-       int Channels  = 0;
-       int Flavor    = 0;
-
-       switch (OutColorSpace) {
-
-   case PT_GRAY:
-          Channels = 1;
-          break;
-   case PT_RGB:
-   case PT_CMY:
-   case PT_Lab:
-   case PT_YUV:
-   case PT_YCbCr:
-          Channels = 3;
-          break;
-
-   case PT_CMYK:
-          if (Compressor.write_Adobe_marker)   // Adobe keeps CMYK inverted, so change flavor to chocolate
-                  Flavor = 1;
-          Channels = 4;
-          break;
-   default:
-          FatalError("Unsupported output color space");
-       }
-
-       return (COLORSPACE_SH(OutColorSpace)|PLANAR_SH(IsPlanar)|CHANNELS_SH(Channels)|BYTES_SH(1)|FLAVOR_SH(Flavor));
-}
-
-
-// Equivalence between ICC color spaces and lcms color spaces
-static
-int GetProfileColorSpace(cmsHPROFILE hProfile)
-{
-    cmsColorSpaceSignature ProfileSpace = cmsGetColorSpace(hProfile);
-
-       return _cmsLCMScolorSpace(ProfileSpace);
-}
-
-static
-int GetDevicelinkColorSpace(cmsHPROFILE hProfile)
-{
-    cmsColorSpaceSignature ProfileSpace = cmsGetPCS(hProfile);
-
-       return _cmsLCMScolorSpace(ProfileSpace);
-}
-
-
-// From TRANSUPP
-
-static 
-void jcopy_markers_execute(j_decompress_ptr srcinfo, j_compress_ptr dstinfo)
-{
-  jpeg_saved_marker_ptr marker;
-
-  /* In the current implementation, we don't actually need to examine the
-   * option flag here; we just copy everything that got saved.
-   * But to avoid confusion, we do not output JFIF and Adobe APP14 markers
-   * if the encoder library already wrote one.
-   */
-  for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
-
-    if (dstinfo->write_JFIF_header &&
-        marker->marker == JPEG_APP0 &&
-        marker->data_length >= 5 &&
-        GETJOCTET(marker->data[0]) == 0x4A &&
-        GETJOCTET(marker->data[1]) == 0x46 &&
-        GETJOCTET(marker->data[2]) == 0x49 &&
-        GETJOCTET(marker->data[3]) == 0x46 &&
-        GETJOCTET(marker->data[4]) == 0)
-                          continue;         /* reject duplicate JFIF */
-
-    if (dstinfo->write_Adobe_marker &&
-        marker->marker == JPEG_APP0+14 &&
-        marker->data_length >= 5 &&
-        GETJOCTET(marker->data[0]) == 0x41 &&
-        GETJOCTET(marker->data[1]) == 0x64 &&
-        GETJOCTET(marker->data[2]) == 0x6F &&
-        GETJOCTET(marker->data[3]) == 0x62 &&
-        GETJOCTET(marker->data[4]) == 0x65)
-                         continue;         /* reject duplicate Adobe */
-
-     jpeg_write_marker(dstinfo, marker->marker,
-                       marker->data, marker->data_length);
-  }
-}
-
-static
-void WriteOutputFields(int OutputColorSpace)
-{
-    J_COLOR_SPACE in_space, jpeg_space;
-    int components;
-    
-    switch (OutputColorSpace) {
-        
-    case PT_GRAY: in_space = jpeg_space = JCS_GRAYSCALE; 
-                  components = 1; 
-                  break;
-
-    case PT_RGB:  in_space = JCS_RGB; 
-                  jpeg_space = JCS_YCbCr; 
-                  components = 3; 
-                  break;       // red/green/blue
-
-    case PT_YCbCr: in_space = jpeg_space = JCS_YCbCr; 
-                   components = 3; 
-                   break;               // Y/Cb/Cr (also known as YUV)
-
-    case PT_CMYK: in_space = JCS_CMYK; 
-                  jpeg_space = JCS_YCCK;  
-                  components = 4; 
-                  break;      // C/M/Y/components              
-
-    case PT_Lab:  in_space = jpeg_space = JCS_YCbCr; 
-                  components = 3; 
-                  break;                // Fake to don't touch
-    default:
-                 FatalError("Unsupported output color space");
-                 return;
-    }
-    
-
-    if (jpegQuality >= 100) {
-
-     // avoid destructive conversion when asking for lossless compression 
-        jpeg_space = in_space;
-    }
-
-    Compressor.in_color_space =  in_space;
-    Compressor.jpeg_color_space = jpeg_space;
-    Compressor.input_components = Compressor.num_components = components;
-    jpeg_set_defaults(&Compressor);
-    jpeg_set_colorspace(&Compressor, jpeg_space);
-
-
-    // Make sure to pass resolution through
-    if (OutputColorSpace == PT_CMYK)
-        Compressor.write_JFIF_header = 1;
-
-    // Avoid subsampling on high quality factor
-    jpeg_set_quality(&Compressor, jpegQuality, 1);    
-    if (jpegQuality >= 70) {
-
-      int i;
-      for(i=0; i < Compressor.num_components; i++) {
-
-               Compressor.comp_info[i].h_samp_factor = 1;
-            Compressor.comp_info[i].v_samp_factor = 1;
-      }
-
-    }
-
-}
-
-
-static
-void DoEmbedProfile(const char* ProfileFile)
-{
-    FILE* f;
-    size_t size, EmbedLen;
-    cmsUInt8Number* EmbedBuffer;
-
-        f = fopen(ProfileFile, "rb");
-        if (f == NULL) return;
-
-        size = cmsfilelength(f);
-        EmbedBuffer = (cmsUInt8Number*) malloc(size + 1);
-        EmbedLen = fread(EmbedBuffer, 1, size, f);
-        fclose(f);
-        EmbedBuffer[EmbedLen] = 0;
-
-        write_icc_profile (&Compressor, EmbedBuffer, EmbedLen);                   
-        free(EmbedBuffer);
-}
-
-
-
-static
-int DoTransform(cmsHTRANSFORM hXForm, int OutputColorSpace)
-{       
-    JSAMPROW ScanLineIn;
-    JSAMPROW ScanLineOut;
-
-    
-       //Preserve resolution values from the original
-       // (Thanks to Robert Bergs for finding out this bug)
-       Compressor.density_unit = Decompressor.density_unit;
-       Compressor.X_density    = Decompressor.X_density;
-       Compressor.Y_density    = Decompressor.Y_density;
-
-      //  Compressor.write_JFIF_header = 1;
-     
-       jpeg_start_decompress(&Decompressor);
-       jpeg_start_compress(&Compressor, TRUE);
-
-        if (OutputColorSpace == PT_Lab)
-            SetITUFax(&Compressor);
-
-       // Embed the profile if needed
-       if (EmbedProfile && cOutProf) 
-           DoEmbedProfile(cOutProf);
-
-       ScanLineIn  = (JSAMPROW) malloc(Decompressor.output_width * Decompressor.num_components);
-       ScanLineOut = (JSAMPROW) malloc(Compressor.image_width * Compressor.num_components);
-
-       while (Decompressor.output_scanline <
-                            Decompressor.output_height) {
-
-       jpeg_read_scanlines(&Decompressor, &ScanLineIn, 1);
-
-       cmsDoTransform(hXForm, ScanLineIn, ScanLineOut, Decompressor.output_width);
-
-       jpeg_write_scanlines(&Compressor, &ScanLineOut, 1);
-       }
-
-       free(ScanLineIn); 
-       free(ScanLineOut);
-
-       jpeg_finish_decompress(&Decompressor);
-       jpeg_finish_compress(&Compressor);
-       
-       return TRUE;
-}
-
-
-
-// Transform one image
-
-static
-int TransformImage(char *cDefInpProf, char *cOutProf)
-{
-       cmsHPROFILE hIn, hOut, hProof;
-       cmsHTRANSFORM xform;
-       cmsUInt32Number wInput, wOutput;
-       int OutputColorSpace;
-       cmsUInt32Number dwFlags = 0; 
-       cmsUInt32Number EmbedLen;
-       cmsUInt8Number* EmbedBuffer;
-
-
-       cmsSetAdaptationState(ObserverAdaptationState);
-
-       if (BlackPointCompensation) {
-
-            dwFlags |= cmsFLAGS_BLACKPOINTCOMPENSATION;            
-       }
-
-
-       switch (PrecalcMode) {
-           
-       case 0: dwFlags |= cmsFLAGS_NOOPTIMIZE; break;
-       case 2: dwFlags |= cmsFLAGS_HIGHRESPRECALC; break;
-       case 3: dwFlags |= cmsFLAGS_LOWRESPRECALC; break;
-       default:;
-       }
-        
-
-       if (GamutCheck) {
-            dwFlags |= cmsFLAGS_GAMUTCHECK;
-            cmsSetAlarmCodes(Alarm);
-       }
-        
-       // Take input color space
-       wInput = GetInputPixelType();
-
-        if (lIsDeviceLink) {
-
-            hIn = cmsOpenProfileFromFile(cDefInpProf, "r");
-            hOut = NULL;
-            hProof = NULL;
-       }
-        else {
-
-        if (!IgnoreEmbedded && read_icc_profile(&Decompressor, &EmbedBuffer, &EmbedLen))
-        {
-              hIn = cmsOpenProfileFromMem(EmbedBuffer, EmbedLen);
-
-               if (Verbose) {
-
-                  fprintf(stdout, " (Embedded profile found)\n");
-                                 PrintProfileInformation(hIn);
-                  fflush(stdout);
-              }
-
-               if (hIn != NULL && SaveEmbedded != NULL)
-                          SaveMemoryBlock(EmbedBuffer, EmbedLen, SaveEmbedded);
-
-              free(EmbedBuffer);
-        }
-        else
-        {
-            // Default for ITU/Fax
-            if (cDefInpProf == NULL && T_COLORSPACE(wInput) == PT_Lab)
-                cDefInpProf = "*Lab";
-
-            if (cDefInpProf != NULL && cmsstrcasecmp(cDefInpProf, "*lab") == 0)
-                hIn = CreateITU2PCS_ICC();
-            else
-                hIn = OpenStockProfile(0, cDefInpProf);
-       }
-
-        if (cOutProf != NULL && cmsstrcasecmp(cOutProf, "*lab") == 0)
-            hOut = CreatePCS2ITU_ICC();
-        else
-        hOut = OpenStockProfile(0, cOutProf);
-
-       hProof = NULL;
-       if (cProofing != NULL) {
-
-           hProof = OpenStockProfile(0, cProofing);
-           if (hProof == NULL) {
-            FatalError("Proofing profile couldn't be read.");
-           }
-           dwFlags |= cmsFLAGS_SOFTPROOFING;
-          }
-       }
-
-        if (!hIn)
-            FatalError("Input profile couldn't be read.");
-        if (!hOut)
-            FatalError("Output profile couldn't be read.");
-
-       // Assure both, input profile and input JPEG are on same colorspace       
-       if (cmsGetColorSpace(hIn) != _cmsICCcolorSpace(T_COLORSPACE(wInput)))
-              FatalError("Input profile is not operating in proper color space");
-       
-
-       // Output colorspace is given by output profile
-
-        if (lIsDeviceLink) {
-            OutputColorSpace = GetDevicelinkColorSpace(hIn);
-        }
-        else {
-            OutputColorSpace = GetProfileColorSpace(hOut);
-        }
-
-       jpeg_copy_critical_parameters(&Decompressor, &Compressor);
-       
-       WriteOutputFields(OutputColorSpace);               
-       
-       wOutput      = ComputeOutputFormatDescriptor(wInput, OutputColorSpace);
-       
-      
-       xform = cmsCreateProofingTransform(hIn, wInput, 
-                                          hOut, wOutput, 
-                                          hProof, Intent, 
-                                          ProofingIntent, dwFlags);
-          if (xform == NULL) 
-                 FatalError("Cannot transform by using the profiles");
-  
-       DoTransform(xform, OutputColorSpace);
-
-       
-       jcopy_markers_execute(&Decompressor, &Compressor);
-       
-       cmsDeleteTransform(xform);
-       cmsCloseProfile(hIn);
-       cmsCloseProfile(hOut);
-       if (hProof) cmsCloseProfile(hProof);
-       
-       return 1;
-}
-
-
-// Simply print help
-
-static
-void Help(int level)
-{
-     fprintf(stderr, "little cms ICC profile applier for JPEG - v3.1 [LittleCMS %2.2f]\n\n", LCMS_VERSION / 1000.0);
-
-     switch(level) {
-
-     default:
-     case 0:
-
-     fprintf(stderr, "usage: jpegicc [flags] input.jpg output.jpg\n");
-
-     fprintf(stderr, "\nflags:\n\n");
-     fprintf(stderr, "%cv - Verbose\n", SW);
-     fprintf(stderr, "%ci<profile> - Input profile (defaults to sRGB)\n", SW);
-     fprintf(stderr, "%co<profile> - Output profile (defaults to sRGB)\n", SW);   
-
-        PrintRenderingIntents();
-
-     
-     fprintf(stderr, "%cb - Black point compensation\n", SW);     
-     fprintf(stderr, "%cd<0..1> - Observer adaptation state (abs.col. only)\n", SW);
-     fprintf(stderr, "%cn - Ignore embedded profile\n", SW);
-     fprintf(stderr, "%ce - Embed destination profile\n", SW);
-     fprintf(stderr, "%cs<new profile> - Save embedded profile as <new profile>\n", SW);
-
-     fprintf(stderr, "\n");
-
-     fprintf(stderr, "%cc<0,1,2,3> - Precalculates transform (0=Off, 1=Normal, 2=Hi-res, 3=LoRes) [defaults to 1]\n", SW);     
-     fprintf(stderr, "\n");
-
-     fprintf(stderr, "%cp<profile> - Soft proof profile\n", SW);
-     fprintf(stderr, "%cm<0,1,2,3> - SoftProof intent\n", SW);
-     fprintf(stderr, "%cg - Marks out-of-gamut colors on softproof\n", SW);
-     fprintf(stderr, "%c!<r>,<g>,<b> - Out-of-gamut marker channel values\n", SW);
-
-     fprintf(stderr, "\n");
-     fprintf(stderr, "%cq<0..100> - Output JPEG quality\n", SW);
-
-     fprintf(stderr, "\n");
-     fprintf(stderr, "%ch<0,1,2,3> - More help\n", SW);
-     break;
-
-     case 1:
-
-     fprintf(stderr, "Examples:\n\n"
-                     "To color correct from scanner to sRGB:\n"
-                     "\tjpegicc %ciscanner.icm in.jpg out.jpg\n"
-                     "To convert from monitor1 to monitor2:\n"
-                     "\tjpegicc %cimon1.icm %comon2.icm in.jpg out.jpg\n"
-                     "To make a CMYK separation:\n"
-                     "\tjpegicc %coprinter.icm inrgb.jpg outcmyk.jpg\n"
-                     "To recover sRGB from a CMYK separation:\n"
-                     "\tjpegicc %ciprinter.icm incmyk.jpg outrgb.jpg\n"
-                     "To convert from CIELab ITU/Fax JPEG to sRGB\n"
-                     "\tjpegicc in.jpg out.jpg\n\n", 
-                     SW, SW, SW, SW, SW, SW);
-     break;
-
-     case 2:
-                PrintBuiltins();
-                break;
-
-     case 3:
-
-     fprintf(stderr, "This program is intended to be a demo of the little cms\n"
-                     "engine. Both lcms and this program are freeware. You can\n"
-                     "obtain both in source code at http://www.littlecms.com\n"
-                     "For suggestions, comments, bug reports etc. send mail to\n"
-                     "marti@littlecms.com\n\n");
-     break;
-     }
-
-     exit(0);
-}
-
-
-// The toggles stuff
-
-static
-void HandleSwitches(int argc, char *argv[])
-{
-    int s;
-    
-    while ((s=xgetopt(argc,argv,"bBnNvVGgh:H:i:I:o:O:P:p:t:T:c:C:Q:q:M:m:L:l:eEs:S:!:D:d:")) != EOF) {
-        
-        switch (s)
-        {
-            
-        case 'b':
-        case 'B':
-            BlackPointCompensation = TRUE;
-            break;
-            
-        case 'd':
-        case 'D': ObserverAdaptationState = atof(xoptarg);
-            if (ObserverAdaptationState < 0 || 
-                ObserverAdaptationState > 1.0)
-                FatalError("Adaptation state should be 0..1");
-            break;
-            
-        case 'v':
-        case 'V':
-            Verbose = TRUE;
-            break;
-            
-        case 'i':
-        case 'I':            
-            if (lIsDeviceLink)
-                FatalError("Device-link already specified"); 
-            
-            cInpProf = xoptarg;
-            break;
-            
-        case 'o':
-        case 'O':            
-            if (lIsDeviceLink)
-                FatalError("Device-link already specified"); 
-            
-            cOutProf = xoptarg;
-            break;
-            
-        case 'l':
-        case 'L': 
-                       if (cInpProf != NULL || cOutProf != NULL) 
-                               FatalError("input/output profiles already specified");
-
-            cInpProf = xoptarg;
-            lIsDeviceLink = TRUE;
-            break;
-            
-        case 'p':
-        case 'P':
-            cProofing = xoptarg;
-            break;
-            
-        case 't':
-        case 'T':
-            Intent = atoi(xoptarg);
-            break;
-            
-        case 'N':
-        case 'n':
-            IgnoreEmbedded = TRUE;
-            break;
-            
-        case 'e':
-        case 'E':
-            EmbedProfile = TRUE;
-            break;
-            
-
-        case 'g':
-        case 'G':
-            GamutCheck = TRUE;
-            break;
-            
-        case 'c':
-        case 'C':
-            PrecalcMode = atoi(xoptarg);
-            if (PrecalcMode < 0 || PrecalcMode > 2)
-                FatalError("Unknown precalc mode '%d'", PrecalcMode);
-            break;
-            
-        case 'H':
-        case 'h':  {
-            
-            int a =  atoi(xoptarg);
-            Help(a); 
-                   }
-            break;
-            
-        case 'q':
-        case 'Q':
-            jpegQuality = atoi(xoptarg);
-            if (jpegQuality > 100) jpegQuality = 100;
-            if (jpegQuality < 0)   jpegQuality = 0;
-            break;
-            
-        case 'm':
-        case 'M':
-            ProofingIntent = atoi(xoptarg);
-            break;
-            
-        case 's':
-        case 'S': SaveEmbedded = xoptarg;
-            break;
-            
-        case '!':       
-            if (sscanf(xoptarg, "%hu,%hu,%hu", &Alarm[0], &Alarm[1], &Alarm[2]) == 3) {
-                int i;
-                for (i=0; i < 3; i++) {
-                    Alarm[i] = (Alarm[i] << 8) | Alarm[i];
-                }
-            }
-            break;
-            
-        default:
-            
-            FatalError("Unknown option - run without args to see valid ones");
-        }
-        
-    }
-}
-
-
-int main(int argc, char* argv[])
-{
-       InitUtils("jpegicc");
-
-       HandleSwitches(argc, argv);
-
-       if ((argc - xoptind) != 2) {
-               Help(0);              
-       }
-
-       OpenInput(argv[xoptind]);
-       OpenOutput(argv[xoptind+1]);
-
-       TransformImage(cInpProf, cOutProf);
-
-
-       if (Verbose) { fprintf(stdout, "\n"); fflush(stdout); }
-
-       Done();
-
-       return 0;
-}
-
-
-
+//---------------------------------------------------------------------------------\r
+//\r
+//  Little Color Management System\r
+//  Copyright (c) 1998-2010 Marti Maria Saguer\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining\r
+// a copy of this software and associated documentation files (the "Software"),\r
+// to deal in the Software without restriction, including without limitation\r
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+// and/or sell copies of the Software, and to permit persons to whom the Software\r
+// is furnished to do so, subject to the following conditions:\r
+//\r
+// The above copyright notice and this permission notice shall be included in\r
+// all copies or substantial portions of the Software.\r
+//\r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO\r
+// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+\r
+// This program does apply profiles to (some) JPEG files\r
+\r
+\r
+#include "utils.h"\r
+\r
+#include "jpeglib.h"\r
+#include "iccjpeg.h"\r
+\r
+// Flags\r
+static cmsBool BlackPointCompensation = FALSE;\r
+static cmsBool IgnoreEmbedded         = FALSE;\r
+static cmsBool GamutCheck             = FALSE;\r
+static cmsBool lIsITUFax              = FALSE;\r
+static cmsBool lIsPhotoshopApp13      = FALSE;\r
+static cmsBool lIsEXIF;\r
+static cmsBool lIsDeviceLink          = FALSE;\r
+static cmsBool EmbedProfile           = FALSE;\r
+\r
+static const char* SaveEmbedded = NULL;\r
+\r
+static int Intent                  = INTENT_PERCEPTUAL;\r
+static int ProofingIntent          = INTENT_PERCEPTUAL;\r
+static int PrecalcMode             = 1;\r
+\r
+static int jpegQuality             = 75;\r
+\r
+static cmsFloat64Number ObserverAdaptationState = 0;\r
+\r
+\r
+static char *cInpProf  = NULL;\r
+static char *cOutProf  = NULL;\r
+static char *cProofing = NULL;\r
+\r
+static FILE * InFile;\r
+static FILE * OutFile;\r
+\r
+static struct jpeg_decompress_struct Decompressor;\r
+static struct jpeg_compress_struct   Compressor;\r
+\r
+\r
+static struct my_error_mgr {\r
+\r
+    struct  jpeg_error_mgr pub;   // "public" fields\r
+    void*   Cargo;                // "private" fields\r
+\r
+} ErrorHandler;\r
+\r
+\r
+cmsUInt16Number Alarm[4] = {128,128,128,0};\r
+\r
+// Out of mem\r
+static\r
+void OutOfMem(size_t size)\r
+{\r
+    FatalError("Out of memory on allocating %d bytes.", size);\r
+}\r
+\r
+\r
+static\r
+void my_error_exit (j_common_ptr cinfo)\r
+{\r
+  char buffer[JMSG_LENGTH_MAX];\r
+\r
+  (*cinfo->err->format_message) (cinfo, buffer);\r
+  FatalError(buffer);\r
+}\r
+\r
+/*\r
+Definition of the APPn Markers Defined for continuous-tone G3FAX\r
+\r
+The application code APP1 initiates identification of the image as\r
+a G3FAX application and defines the spatial resolution and subsampling.\r
+This marker directly follows the SOI marker. The data format will be as follows:\r
+\r
+X'FFE1' (APP1), length, FAX identifier, version, spatial resolution.\r
+\r
+The above terms are defined as follows:\r
+\r
+Length: (Two octets) Total APP1 field octet count including the octet count itself, but excluding the APP1\r
+marker.\r
+\r
+FAX identifier: (Six octets) X'47', X'33', X'46', X'41', X'58', X'00'. This X'00'-terminated string "G3FAX"\r
+uniquely identifies this APP1 marker.\r
+\r
+Version: (Two octets) X'07CA'. This string specifies the year of approval of the standard, for identification\r
+in the case of future revision (for example, 1994).\r
+\r
+Spatial Resolution: (Two octets) Lightness pixel density in pels/25.4 mm. The basic value is 200. Allowed values are\r
+100, 200, 300, 400, 600 and 1200 pels/25.4 mm, with square (or equivalent) pels.\r
+\r
+NOTE \96 The functional equivalence of inch-based and mm-based resolutions is maintained. For example, the 200 Ã— 200\r
+*/\r
+\r
+static\r
+cmsBool IsITUFax(jpeg_saved_marker_ptr ptr)\r
+{\r
+       while (ptr)\r
+       {\r
+        if (ptr -> marker == (JPEG_APP0 + 1) && ptr -> data_length > 5) {\r
+\r
+                       const char* data = (const char*) ptr -> data;\r
+\r
+                       if (strcmp(data, "G3FAX") == 0) return TRUE;\r
+               }\r
+\r
+               ptr = ptr -> next;\r
+       }\r
+\r
+       return FALSE;\r
+}\r
+\r
+// Save a ITU T.42/Fax marker with defaults on boundaries. This is the only mode we support right now.\r
+static\r
+void SetITUFax(j_compress_ptr cinfo)\r
+{\r
+       unsigned char Marker[] = "G3FAX\x00\0x07\xCA\x00\xC8";\r
+\r
+       jpeg_write_marker(cinfo, (JPEG_APP0 + 1), Marker, 10);\r
+}\r
+\r
+\r
+// Build a profile for decoding ITU T.42/Fax JPEG streams.\r
+// The profile has an additional ability in the input direction of\r
+// gamut compress values between 85 < a < -85 and -75 < b < 125. This conforms\r
+// the default range for ITU/T.42 -- See RFC 2301, section 6.2.3 for details\r
+\r
+//  L*  =   [0, 100]\r
+//  a*  =   [\9685, 85]\r
+//  b*  =   [\9675, 125]\r
+\r
+\r
+// These functions does convert the encoding of ITUFAX to floating point\r
+// and vice-versa. No gamut mapping is performed yet.\r
+\r
+static\r
+void ITU2Lab(const cmsUInt16Number In[3], cmsCIELab* Lab)\r
+{\r
+       Lab -> L = (double) In[0] / 655.35;\r
+       Lab -> a = (double) 170.* (In[1] - 32768.) / 65535.;\r
+       Lab -> b = (double) 200.* (In[2] - 24576.) / 65535.;\r
+}\r
+\r
+static\r
+void Lab2ITU(const cmsCIELab* Lab, cmsUInt16Number Out[3])\r
+{\r
+       Out[0] = (cmsUInt16Number) floor((double) (Lab -> L / 100.)* 65535. );\r
+       Out[1] = (cmsUInt16Number) floor((double) (Lab -> a / 170.)* 65535. + 32768. );\r
+       Out[2] = (cmsUInt16Number) floor((double) (Lab -> b / 200.)* 65535. + 24576. );\r
+}\r
+\r
+// These are the samplers-- They are passed as callbacks to cmsStageSampleCLut16bit()\r
+// then, cmsSample3DGrid() will sweel whole Lab gamut calling these functions\r
+// once for each node. In[] will contain the Lab PCS value to convert to ITUFAX\r
+// on PCS2ITU, or the ITUFAX value to convert to Lab in ITU2PCS\r
+// You can change the number of sample points if desired, the algorithm will\r
+// remain same. 33 points gives good accurancy, but you can reduce to 22 or less\r
+// is space is critical\r
+\r
+#define GRID_POINTS 33\r
+\r
+static\r
+int PCS2ITU(register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void*  Cargo)\r
+{\r
+       cmsCIELab Lab;\r
+\r
+       cmsLabEncoded2Float(&Lab, In);\r
+       cmsDesaturateLab(&Lab, 85, -85, 125, -75);    // This function does the necessary gamut remapping\r
+       Lab2ITU(&Lab, Out);\r
+       return TRUE;\r
+\r
+    UTILS_UNUSED_PARAMETER(Cargo);\r
+}\r
+\r
+\r
+static\r
+int ITU2PCS( register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void*  Cargo)\r
+{\r
+       cmsCIELab Lab;\r
+\r
+       ITU2Lab(In, &Lab);\r
+       cmsFloat2LabEncoded(Out, &Lab);\r
+       return TRUE;\r
+\r
+    UTILS_UNUSED_PARAMETER(Cargo);\r
+}\r
+\r
+// This function does create the virtual input profile, which decodes ITU to the profile connection space\r
+static\r
+cmsHPROFILE CreateITU2PCS_ICC(void)\r
+{\r
+       cmsHPROFILE hProfile;\r
+       cmsPipeline* AToB0;\r
+       cmsStage* ColorMap;\r
+\r
+       AToB0 = cmsPipelineAlloc(0, 3, 3);\r
+       if (AToB0 == NULL) return NULL;\r
+\r
+       ColorMap = cmsStageAllocCLut16bit(0, GRID_POINTS, 3, 3, NULL);\r
+       if (ColorMap == NULL) return NULL;\r
+\r
+    cmsPipelineInsertStage(AToB0, cmsAT_BEGIN, ColorMap);\r
+       cmsStageSampleCLut16bit(ColorMap, ITU2PCS, NULL, 0);\r
+\r
+       hProfile = cmsCreateProfilePlaceholder(0);\r
+       if (hProfile == NULL) {\r
+               cmsPipelineFree(AToB0);\r
+               return NULL;\r
+       }\r
+\r
+       cmsWriteTag(hProfile, cmsSigAToB0Tag, AToB0);\r
+       cmsSetColorSpace(hProfile, cmsSigLabData);\r
+       cmsSetPCS(hProfile, cmsSigLabData);\r
+       cmsSetDeviceClass(hProfile, cmsSigColorSpaceClass);\r
+       cmsPipelineFree(AToB0);\r
+\r
+       return hProfile;\r
+}\r
+\r
+\r
+// This function does create the virtual output profile, with the necessary gamut mapping\r
+static\r
+cmsHPROFILE CreatePCS2ITU_ICC(void)\r
+{\r
+    cmsHPROFILE hProfile;\r
+    cmsPipeline* BToA0;\r
+    cmsStage* ColorMap;\r
+\r
+    BToA0 = cmsPipelineAlloc(0, 3, 3);\r
+    if (BToA0 == NULL) return NULL;\r
+\r
+    ColorMap = cmsStageAllocCLut16bit(0, GRID_POINTS, 3, 3, NULL);\r
+    if (ColorMap == NULL) return NULL;\r
+\r
+    cmsPipelineInsertStage(BToA0, cmsAT_BEGIN, ColorMap);\r
+    cmsStageSampleCLut16bit(ColorMap, PCS2ITU, NULL, 0);\r
+\r
+    hProfile = cmsCreateProfilePlaceholder(0);\r
+    if (hProfile == NULL) {\r
+        cmsPipelineFree(BToA0);\r
+        return NULL;\r
+    }\r
+\r
+    cmsWriteTag(hProfile, cmsSigBToA0Tag, BToA0);\r
+    cmsSetColorSpace(hProfile, cmsSigLabData);\r
+    cmsSetPCS(hProfile, cmsSigLabData);\r
+    cmsSetDeviceClass(hProfile, cmsSigColorSpaceClass);\r
+\r
+    cmsPipelineFree(BToA0);\r
+\r
+    return hProfile;\r
+}\r
+\r
+\r
+\r
+#define PS_FIXED_TO_FLOAT(h, l) ((float) (h) + ((float) (l)/(1<<16)))\r
+\r
+static\r
+cmsBool ProcessPhotoshopAPP13(JOCTET FAR *data, int datalen)\r
+{\r
+    int i;\r
+\r
+    for (i = 14; i < datalen; )\r
+    {\r
+        long len;\r
+        unsigned int type;\r
+\r
+        if (!(GETJOCTET(data[i]  ) == 0x38 &&\r
+              GETJOCTET(data[i+1]) == 0x42 &&\r
+              GETJOCTET(data[i+2]) == 0x49 &&\r
+              GETJOCTET(data[i+3]) == 0x4D)) break; // Not recognized\r
+\r
+        i += 4; // identifying string\r
+\r
+        type = (unsigned int) (GETJOCTET(data[i]<<8) + GETJOCTET(data[i+1]));\r
+\r
+        i += 2; // resource type\r
+\r
+        i += GETJOCTET(data[i]) + ((GETJOCTET(data[i]) & 1) ? 1 : 2);   // resource name\r
+\r
+        len = ((((GETJOCTET(data[i]<<8) + GETJOCTET(data[i+1]))<<8) +\r
+                         GETJOCTET(data[i+2]))<<8) + GETJOCTET(data[i+3]);\r
+\r
+        i += 4; // Size\r
+\r
+        if (type == 0x03ED && len >= 16) {\r
+\r
+            Decompressor.X_density = (UINT16) PS_FIXED_TO_FLOAT(GETJOCTET(data[i]<<8) + GETJOCTET(data[i+1]),\r
+                                                 GETJOCTET(data[i+2]<<8) + GETJOCTET(data[i+3]));\r
+            Decompressor.Y_density = (UINT16) PS_FIXED_TO_FLOAT(GETJOCTET(data[i+8]<<8) + GETJOCTET(data[i+9]),\r
+                                                 GETJOCTET(data[i+10]<<8) + GETJOCTET(data[i+11]));\r
+\r
+            // Set the density unit to 1 since the\r
+            // Vertical and Horizontal resolutions\r
+            // are specified in Pixels per inch\r
+\r
+            Decompressor.density_unit = 0x01;\r
+            return TRUE;\r
+\r
+        }\r
+\r
+        i += len + ((len & 1) ? 1 : 0);   // Alignment\r
+    }\r
+    return FALSE;\r
+}\r
+\r
+\r
+static\r
+cmsBool HandlePhotoshopAPP13(jpeg_saved_marker_ptr ptr)\r
+{\r
+    while (ptr) {\r
+\r
+        if (ptr -> marker == (JPEG_APP0 + 13) && ptr -> data_length > 9)\r
+        {\r
+            JOCTET FAR* data = ptr -> data;\r
+\r
+            if(GETJOCTET(data[0]) == 0x50 &&\r
+               GETJOCTET(data[1]) == 0x68 &&\r
+               GETJOCTET(data[2]) == 0x6F &&\r
+               GETJOCTET(data[3]) == 0x74 &&\r
+               GETJOCTET(data[4]) == 0x6F &&\r
+               GETJOCTET(data[5]) == 0x73 &&\r
+               GETJOCTET(data[6]) == 0x68 &&\r
+               GETJOCTET(data[7]) == 0x6F &&\r
+               GETJOCTET(data[8]) == 0x70) {\r
+\r
+                ProcessPhotoshopAPP13(data, ptr -> data_length);\r
+                return TRUE;\r
+            }\r
+        }\r
+\r
+        ptr = ptr -> next;\r
+    }\r
+\r
+    return FALSE;\r
+}\r
+\r
+\r
+typedef unsigned short uint16_t;\r
+typedef unsigned char uint8_t;\r
+typedef unsigned int uint32_t;\r
+\r
+#define INTEL_BYTE_ORDER 0x4949\r
+#define XRESOLUTION 0x011a\r
+#define YRESOLUTION 0x011b\r
+#define RESOLUTION_UNIT 0x128\r
+\r
+// Read a 16-bit word\r
+static\r
+uint16_t read16(uint8_t* arr, int pos,  int swapBytes)\r
+{\r
+    uint8_t b1 = arr[pos];\r
+    uint8_t b2 = arr[pos+1];\r
+\r
+    return (swapBytes) ?  ((b2 << 8) | b1) : ((b1 << 8) | b2);\r
+}\r
+\r
+\r
+// Read a 32-bit word\r
+static\r
+uint32_t read32(uint8_t* arr, int pos,  int swapBytes)\r
+{\r
+\r
+    if(!swapBytes) {\r
+\r
+        return (arr[pos]   << 24) |\r
+               (arr[pos+1] << 16) |\r
+               (arr[pos+2] << 8) |\r
+                arr[pos+3];\r
+    }\r
+\r
+    return arr[pos] |\r
+           (arr[pos+1] << 8) |\r
+           (arr[pos+2] << 16) |\r
+           (arr[pos+3] << 24);\r
+}\r
+\r
+\r
+\r
+static\r
+int read_tag(uint8_t* arr, int pos,  int swapBytes, void* dest)\r
+{\r
+        // Format should be 5 over here (rational)\r
+    uint32_t format = read16(arr, pos + 2, swapBytes);\r
+    // Components should be 1\r
+    uint32_t components = read32(arr, pos + 4, swapBytes);\r
+    // Points to the value\r
+    uint32_t offset;\r
+\r
+    // sanity\r
+    if (components != 1) return 0;\r
+\r
+    if (format == 3)\r
+        offset = pos + 8;\r
+    else\r
+        offset =  read32(arr, pos + 8, swapBytes);\r
+\r
+    switch (format) {\r
+\r
+    case 5: // Rational\r
+          {\r
+          double num = read32(arr, offset, swapBytes);\r
+          double den = read32(arr, offset + 4, swapBytes);\r
+          *(double *) dest = num / den;\r
+          }\r
+          break;\r
+\r
+    case 3: // uint 16\r
+        *(int*) dest = read16(arr, offset, swapBytes);\r
+        break;\r
+\r
+    default:  return 0;\r
+    }\r
+\r
+    return 1;\r
+}\r
+\r
+\r
+\r
+// Handler for EXIF data\r
+static\r
+    cmsBool HandleEXIF(struct jpeg_decompress_struct* cinfo)\r
+{\r
+    jpeg_saved_marker_ptr ptr;\r
+    uint32_t ifd_ofs;\r
+    int pos = 0, swapBytes = 0;\r
+    uint32_t i, numEntries;\r
+    double XRes = -1, YRes = -1;\r
+    int Unit = 2; // Inches\r
+\r
+\r
+    for (ptr = cinfo ->marker_list; ptr; ptr = ptr ->next) {\r
+\r
+        if ((ptr ->marker == JPEG_APP0+1) && ptr ->data_length > 6) {\r
+            JOCTET FAR* data = ptr -> data;\r
+\r
+            if (memcmp(data, "Exif\0\0", 6) == 0) {\r
+\r
+                data += 6; // Skip EXIF marker\r
+\r
+                // 8 byte TIFF header\r
+                // first two determine byte order\r
+                pos = 0;\r
+                if (read16(data, pos, 0) == INTEL_BYTE_ORDER) {\r
+                    swapBytes = 1;\r
+                }\r
+\r
+                pos += 2;\r
+\r
+                // next two bytes are always 0x002A (TIFF version)\r
+                pos += 2;\r
+\r
+                // offset to Image File Directory (includes the previous 8 bytes)\r
+                ifd_ofs = read32(data, pos, swapBytes);\r
+\r
+                // Search the directory for resolution tags\r
+                numEntries = read16(data, ifd_ofs, swapBytes);\r
+\r
+                for (i=0; i < numEntries; i++) {\r
+\r
+                    uint32_t entryOffset = ifd_ofs + 2 + (12 * i);\r
+                    uint32_t tag = read16(data, entryOffset, swapBytes);\r
+\r
+                    switch (tag) {\r
+\r
+                    case RESOLUTION_UNIT:\r
+                        if (!read_tag(data, entryOffset, swapBytes, &Unit)) return FALSE;\r
+                        break;\r
+\r
+                    case XRESOLUTION:\r
+                        if (!read_tag(data, entryOffset, swapBytes, &XRes)) return FALSE;\r
+                        break;\r
+\r
+                    case YRESOLUTION:\r
+                        if (!read_tag(data, entryOffset, swapBytes, &YRes)) return FALSE;\r
+                        break;\r
+\r
+                    default:;\r
+                    }\r
+\r
+                }\r
+\r
+                // Proceed if all found\r
+\r
+                if (XRes != -1 && YRes != -1)\r
+                {\r
+\r
+                    // 1 = None\r
+                    // 2 = inches\r
+                    // 3 = cm\r
+\r
+                    switch (Unit) {\r
+\r
+                    case 2:\r
+\r
+                        cinfo ->X_density = (UINT16) floor(XRes + 0.5);\r
+                        cinfo ->Y_density = (UINT16) floor(YRes + 0.5);\r
+                        break;\r
+\r
+                    case 1:\r
+\r
+                        cinfo ->X_density = (UINT16) floor(XRes * 2.54 + 0.5);\r
+                        cinfo ->Y_density = (UINT16) floor(YRes * 2.54 + 0.5);\r
+                        break;\r
+\r
+                    default: return FALSE;\r
+                    }\r
+\r
+                    cinfo ->density_unit = 1;  /* 1 for dots/inch, or 2 for dots/cm.*/\r
+\r
+                }\r
+\r
+\r
+            }\r
+        }\r
+    }\r
+    return FALSE;\r
+}\r
+\r
+\r
+static\r
+cmsBool OpenInput(const char* FileName)\r
+{\r
+       int m;\r
+\r
+       lIsITUFax = FALSE;\r
+       InFile  = fopen(FileName, "rb");\r
+       if (InFile == NULL) {\r
+               FatalError("Cannot open '%s'", FileName);\r
+       }\r
+\r
+       // Now we can initialize the JPEG decompression object.\r
+       Decompressor.err                 = jpeg_std_error(&ErrorHandler.pub);\r
+       ErrorHandler.pub.error_exit      = my_error_exit;\r
+       ErrorHandler.pub.output_message  = my_error_exit;\r
+\r
+       jpeg_create_decompress(&Decompressor);\r
+       jpeg_stdio_src(&Decompressor, InFile);\r
+\r
+       for (m = 0; m < 16; m++)\r
+               jpeg_save_markers(&Decompressor, JPEG_APP0 + m, 0xFFFF);\r
+\r
+       // setup_read_icc_profile(&Decompressor);\r
+\r
+       fseek(InFile, 0, SEEK_SET);\r
+       jpeg_read_header(&Decompressor, TRUE);\r
+\r
+       return TRUE;\r
+}\r
+\r
+\r
+static\r
+cmsBool OpenOutput(const char* FileName)\r
+{\r
+\r
+       OutFile = fopen(FileName, "wb");\r
+       if (OutFile == NULL) {\r
+               FatalError("Cannot create '%s'", FileName);\r
+\r
+       }\r
+\r
+       Compressor.err                   = jpeg_std_error(&ErrorHandler.pub);\r
+       ErrorHandler.pub.error_exit      = my_error_exit;\r
+       ErrorHandler.pub.output_message  = my_error_exit;\r
+\r
+       Compressor.input_components = Compressor.num_components = 4;\r
+\r
+       jpeg_create_compress(&Compressor);\r
+       jpeg_stdio_dest(&Compressor, OutFile);\r
+       return TRUE;\r
+}\r
+\r
+static\r
+cmsBool Done(void)\r
+{\r
+       jpeg_destroy_decompress(&Decompressor);\r
+       jpeg_destroy_compress(&Compressor);\r
+       return fclose(InFile) + fclose(OutFile);\r
+\r
+}\r
+\r
+\r
+// Build up the pixeltype descriptor\r
+\r
+static\r
+cmsUInt32Number GetInputPixelType(void)\r
+{\r
+     int space, bps, extra, ColorChannels, Flavor;\r
+\r
+     lIsITUFax         = IsITUFax(Decompressor.marker_list);\r
+     lIsPhotoshopApp13 = HandlePhotoshopAPP13(Decompressor.marker_list);\r
+     lIsEXIF           = HandleEXIF(&Decompressor);\r
+\r
+     ColorChannels = Decompressor.num_components;\r
+     extra  = 0;            // Alpha = None\r
+     bps    = 1;            // 8 bits\r
+     Flavor = 0;            // Vanilla\r
+\r
+     if (lIsITUFax) {\r
+\r
+        space = PT_Lab;\r
+        Decompressor.out_color_space = JCS_YCbCr;  // Fake to don't touch\r
+     }\r
+     else\r
+     switch (Decompressor.jpeg_color_space) {\r
+\r
+     case JCS_GRAYSCALE:        // monochrome\r
+              space = PT_GRAY;\r
+              Decompressor.out_color_space = JCS_GRAYSCALE;\r
+              break;\r
+\r
+     case JCS_RGB:             // red/green/blue\r
+              space = PT_RGB;\r
+              Decompressor.out_color_space = JCS_RGB;\r
+              break;\r
+\r
+     case JCS_YCbCr:               // Y/Cb/Cr (also known as YUV)\r
+              space = PT_RGB;      // Let IJG code to do the conversion\r
+              Decompressor.out_color_space = JCS_RGB;\r
+              break;\r
+\r
+     case JCS_CMYK:            // C/M/Y/K\r
+              space = PT_CMYK;\r
+              Decompressor.out_color_space = JCS_CMYK;\r
+              if (Decompressor.saw_Adobe_marker)            // Adobe keeps CMYK inverted, so change flavor\r
+                                Flavor = 1;                 // from vanilla to chocolate\r
+              break;\r
+\r
+     case JCS_YCCK:            // Y/Cb/Cr/K\r
+              space = PT_CMYK;\r
+              Decompressor.out_color_space = JCS_CMYK;\r
+              if (Decompressor.saw_Adobe_marker)            // ditto\r
+                                Flavor = 1;\r
+              break;\r
+\r
+     default:\r
+              FatalError("Unsupported color space (0x%x)", Decompressor.jpeg_color_space);\r
+              return 0;\r
+     }\r
+\r
+     return (EXTRA_SH(extra)|CHANNELS_SH(ColorChannels)|BYTES_SH(bps)|COLORSPACE_SH(space)|FLAVOR_SH(Flavor));\r
+}\r
+\r
+\r
+// Rearrange pixel type to build output descriptor\r
+static\r
+cmsUInt32Number ComputeOutputFormatDescriptor(cmsUInt32Number dwInput, int OutColorSpace)\r
+{\r
+       int IsPlanar  = T_PLANAR(dwInput);\r
+       int Channels  = 0;\r
+       int Flavor    = 0;\r
+\r
+       switch (OutColorSpace) {\r
+\r
+   case PT_GRAY:\r
+          Channels = 1;\r
+          break;\r
+   case PT_RGB:\r
+   case PT_CMY:\r
+   case PT_Lab:\r
+   case PT_YUV:\r
+   case PT_YCbCr:\r
+          Channels = 3;\r
+          break;\r
+\r
+   case PT_CMYK:\r
+          if (Compressor.write_Adobe_marker)   // Adobe keeps CMYK inverted, so change flavor to chocolate\r
+                  Flavor = 1;\r
+          Channels = 4;\r
+          break;\r
+   default:\r
+          FatalError("Unsupported output color space");\r
+       }\r
+\r
+       return (COLORSPACE_SH(OutColorSpace)|PLANAR_SH(IsPlanar)|CHANNELS_SH(Channels)|BYTES_SH(1)|FLAVOR_SH(Flavor));\r
+}\r
+\r
+\r
+// Equivalence between ICC color spaces and lcms color spaces\r
+static\r
+int GetProfileColorSpace(cmsHPROFILE hProfile)\r
+{\r
+    cmsColorSpaceSignature ProfileSpace = cmsGetColorSpace(hProfile);\r
+\r
+       return _cmsLCMScolorSpace(ProfileSpace);\r
+}\r
+\r
+static\r
+int GetDevicelinkColorSpace(cmsHPROFILE hProfile)\r
+{\r
+    cmsColorSpaceSignature ProfileSpace = cmsGetPCS(hProfile);\r
+\r
+       return _cmsLCMScolorSpace(ProfileSpace);\r
+}\r
+\r
+\r
+// From TRANSUPP\r
+\r
+static\r
+void jcopy_markers_execute(j_decompress_ptr srcinfo, j_compress_ptr dstinfo)\r
+{\r
+  jpeg_saved_marker_ptr marker;\r
+\r
+  /* In the current implementation, we don't actually need to examine the\r
+   * option flag here; we just copy everything that got saved.\r
+   * But to avoid confusion, we do not output JFIF and Adobe APP14 markers\r
+   * if the encoder library already wrote one.\r
+   */\r
+  for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {\r
+\r
+    if (dstinfo->write_JFIF_header &&\r
+        marker->marker == JPEG_APP0 &&\r
+        marker->data_length >= 5 &&\r
+        GETJOCTET(marker->data[0]) == 0x4A &&\r
+        GETJOCTET(marker->data[1]) == 0x46 &&\r
+        GETJOCTET(marker->data[2]) == 0x49 &&\r
+        GETJOCTET(marker->data[3]) == 0x46 &&\r
+        GETJOCTET(marker->data[4]) == 0)\r
+                          continue;         /* reject duplicate JFIF */\r
+\r
+    if (dstinfo->write_Adobe_marker &&\r
+        marker->marker == JPEG_APP0+14 &&\r
+        marker->data_length >= 5 &&\r
+        GETJOCTET(marker->data[0]) == 0x41 &&\r
+        GETJOCTET(marker->data[1]) == 0x64 &&\r
+        GETJOCTET(marker->data[2]) == 0x6F &&\r
+        GETJOCTET(marker->data[3]) == 0x62 &&\r
+        GETJOCTET(marker->data[4]) == 0x65)\r
+                         continue;         /* reject duplicate Adobe */\r
+\r
+     jpeg_write_marker(dstinfo, marker->marker,\r
+                       marker->data, marker->data_length);\r
+  }\r
+}\r
+\r
+static\r
+void WriteOutputFields(int OutputColorSpace)\r
+{\r
+    J_COLOR_SPACE in_space, jpeg_space;\r
+    int components;\r
+\r
+    switch (OutputColorSpace) {\r
+\r
+    case PT_GRAY: in_space = jpeg_space = JCS_GRAYSCALE;\r
+                  components = 1;\r
+                  break;\r
+\r
+    case PT_RGB:  in_space = JCS_RGB;\r
+                  jpeg_space = JCS_YCbCr;\r
+                  components = 3;\r
+                  break;       // red/green/blue\r
+\r
+    case PT_YCbCr: in_space = jpeg_space = JCS_YCbCr;\r
+                   components = 3;\r
+                   break;               // Y/Cb/Cr (also known as YUV)\r
+\r
+    case PT_CMYK: in_space = JCS_CMYK;\r
+                  jpeg_space = JCS_YCCK;\r
+                  components = 4;\r
+                  break;      // C/M/Y/components\r
+\r
+    case PT_Lab:  in_space = jpeg_space = JCS_YCbCr;\r
+                  components = 3;\r
+                  break;                // Fake to don't touch\r
+    default:\r
+                 FatalError("Unsupported output color space");\r
+                 return;\r
+    }\r
+\r
+\r
+    if (jpegQuality >= 100) {\r
+\r
+     // avoid destructive conversion when asking for lossless compression\r
+        jpeg_space = in_space;\r
+    }\r
+\r
+    Compressor.in_color_space =  in_space;\r
+    Compressor.jpeg_color_space = jpeg_space;\r
+    Compressor.input_components = Compressor.num_components = components;\r
+    jpeg_set_defaults(&Compressor);\r
+    jpeg_set_colorspace(&Compressor, jpeg_space);\r
+\r
+\r
+    // Make sure to pass resolution through\r
+    if (OutputColorSpace == PT_CMYK)\r
+        Compressor.write_JFIF_header = 1;\r
+\r
+    // Avoid subsampling on high quality factor\r
+    jpeg_set_quality(&Compressor, jpegQuality, 1);\r
+    if (jpegQuality >= 70) {\r
+\r
+      int i;\r
+      for(i=0; i < Compressor.num_components; i++) {\r
+\r
+               Compressor.comp_info[i].h_samp_factor = 1;\r
+            Compressor.comp_info[i].v_samp_factor = 1;\r
+      }\r
+\r
+    }\r
+\r
+}\r
+\r
+\r
+static\r
+void DoEmbedProfile(const char* ProfileFile)\r
+{\r
+    FILE* f;\r
+    size_t size, EmbedLen;\r
+    cmsUInt8Number* EmbedBuffer;\r
+\r
+        f = fopen(ProfileFile, "rb");\r
+        if (f == NULL) return;\r
+\r
+        size = cmsfilelength(f);\r
+        EmbedBuffer = (cmsUInt8Number*) malloc(size + 1);\r
+        EmbedLen = fread(EmbedBuffer, 1, size, f);\r
+        fclose(f);\r
+        EmbedBuffer[EmbedLen] = 0;\r
+\r
+        write_icc_profile (&Compressor, EmbedBuffer, EmbedLen);\r
+        free(EmbedBuffer);\r
+}\r
+\r
+\r
+\r
+static\r
+int DoTransform(cmsHTRANSFORM hXForm, int OutputColorSpace)\r
+{\r
+    JSAMPROW ScanLineIn;\r
+    JSAMPROW ScanLineOut;\r
+\r
+\r
+       //Preserve resolution values from the original\r
+       // (Thanks to Robert Bergs for finding out this bug)\r
+       Compressor.density_unit = Decompressor.density_unit;\r
+       Compressor.X_density    = Decompressor.X_density;\r
+       Compressor.Y_density    = Decompressor.Y_density;\r
+\r
+      //  Compressor.write_JFIF_header = 1;\r
+\r
+       jpeg_start_decompress(&Decompressor);\r
+       jpeg_start_compress(&Compressor, TRUE);\r
+\r
+        if (OutputColorSpace == PT_Lab)\r
+            SetITUFax(&Compressor);\r
+\r
+       // Embed the profile if needed\r
+       if (EmbedProfile && cOutProf)\r
+           DoEmbedProfile(cOutProf);\r
+\r
+       ScanLineIn  = (JSAMPROW) malloc(Decompressor.output_width * Decompressor.num_components);\r
+       ScanLineOut = (JSAMPROW) malloc(Compressor.image_width * Compressor.num_components);\r
+\r
+       while (Decompressor.output_scanline <\r
+                            Decompressor.output_height) {\r
+\r
+       jpeg_read_scanlines(&Decompressor, &ScanLineIn, 1);\r
+\r
+       cmsDoTransform(hXForm, ScanLineIn, ScanLineOut, Decompressor.output_width);\r
+\r
+       jpeg_write_scanlines(&Compressor, &ScanLineOut, 1);\r
+       }\r
+\r
+       free(ScanLineIn);\r
+       free(ScanLineOut);\r
+\r
+       jpeg_finish_decompress(&Decompressor);\r
+       jpeg_finish_compress(&Compressor);\r
+\r
+       return TRUE;\r
+}\r
+\r
+\r
+\r
+// Transform one image\r
+\r
+static\r
+int TransformImage(char *cDefInpProf, char *cOutProf)\r
+{\r
+       cmsHPROFILE hIn, hOut, hProof;\r
+       cmsHTRANSFORM xform;\r
+       cmsUInt32Number wInput, wOutput;\r
+       int OutputColorSpace;\r
+       cmsUInt32Number dwFlags = 0;\r
+       cmsUInt32Number EmbedLen;\r
+       cmsUInt8Number* EmbedBuffer;\r
+\r
+\r
+       cmsSetAdaptationState(ObserverAdaptationState);\r
+\r
+       if (BlackPointCompensation) {\r
+\r
+            dwFlags |= cmsFLAGS_BLACKPOINTCOMPENSATION;\r
+       }\r
+\r
+\r
+       switch (PrecalcMode) {\r
+\r
+       case 0: dwFlags |= cmsFLAGS_NOOPTIMIZE; break;\r
+       case 2: dwFlags |= cmsFLAGS_HIGHRESPRECALC; break;\r
+       case 3: dwFlags |= cmsFLAGS_LOWRESPRECALC; break;\r
+       default:;\r
+       }\r
+\r
+\r
+       if (GamutCheck) {\r
+            dwFlags |= cmsFLAGS_GAMUTCHECK;\r
+            cmsSetAlarmCodes(Alarm);\r
+       }\r
+\r
+       // Take input color space\r
+       wInput = GetInputPixelType();\r
+\r
+        if (lIsDeviceLink) {\r
+\r
+            hIn = cmsOpenProfileFromFile(cDefInpProf, "r");\r
+            hOut = NULL;\r
+            hProof = NULL;\r
+       }\r
+        else {\r
+\r
+        if (!IgnoreEmbedded && read_icc_profile(&Decompressor, &EmbedBuffer, &EmbedLen))\r
+        {\r
+              hIn = cmsOpenProfileFromMem(EmbedBuffer, EmbedLen);\r
+\r
+               if (Verbose) {\r
+\r
+                  fprintf(stdout, " (Embedded profile found)\n");\r
+                                 PrintProfileInformation(hIn);\r
+                  fflush(stdout);\r
+              }\r
+\r
+               if (hIn != NULL && SaveEmbedded != NULL)\r
+                          SaveMemoryBlock(EmbedBuffer, EmbedLen, SaveEmbedded);\r
+\r
+              free(EmbedBuffer);\r
+        }\r
+        else\r
+        {\r
+            // Default for ITU/Fax\r
+            if (cDefInpProf == NULL && T_COLORSPACE(wInput) == PT_Lab)\r
+                cDefInpProf = "*Lab";\r
+\r
+            if (cDefInpProf != NULL && cmsstrcasecmp(cDefInpProf, "*lab") == 0)\r
+                hIn = CreateITU2PCS_ICC();\r
+            else\r
+                hIn = OpenStockProfile(0, cDefInpProf);\r
+       }\r
+\r
+        if (cOutProf != NULL && cmsstrcasecmp(cOutProf, "*lab") == 0)\r
+            hOut = CreatePCS2ITU_ICC();\r
+        else\r
+        hOut = OpenStockProfile(0, cOutProf);\r
+\r
+       hProof = NULL;\r
+       if (cProofing != NULL) {\r
+\r
+           hProof = OpenStockProfile(0, cProofing);\r
+           if (hProof == NULL) {\r
+            FatalError("Proofing profile couldn't be read.");\r
+           }\r
+           dwFlags |= cmsFLAGS_SOFTPROOFING;\r
+          }\r
+       }\r
+\r
+        if (!hIn)\r
+            FatalError("Input profile couldn't be read.");\r
+        if (!hOut)\r
+            FatalError("Output profile couldn't be read.");\r
+\r
+       // Assure both, input profile and input JPEG are on same colorspace\r
+       if (cmsGetColorSpace(hIn) != _cmsICCcolorSpace(T_COLORSPACE(wInput)))\r
+              FatalError("Input profile is not operating in proper color space");\r
+\r
+\r
+       // Output colorspace is given by output profile\r
+\r
+        if (lIsDeviceLink) {\r
+            OutputColorSpace = GetDevicelinkColorSpace(hIn);\r
+        }\r
+        else {\r
+            OutputColorSpace = GetProfileColorSpace(hOut);\r
+        }\r
+\r
+       jpeg_copy_critical_parameters(&Decompressor, &Compressor);\r
+\r
+       WriteOutputFields(OutputColorSpace);\r
+\r
+       wOutput      = ComputeOutputFormatDescriptor(wInput, OutputColorSpace);\r
+\r
+\r
+       xform = cmsCreateProofingTransform(hIn, wInput,\r
+                                          hOut, wOutput,\r
+                                          hProof, Intent,\r
+                                          ProofingIntent, dwFlags);\r
+          if (xform == NULL)\r
+                 FatalError("Cannot transform by using the profiles");\r
+\r
+       DoTransform(xform, OutputColorSpace);\r
+\r
+\r
+       jcopy_markers_execute(&Decompressor, &Compressor);\r
+\r
+       cmsDeleteTransform(xform);\r
+       cmsCloseProfile(hIn);\r
+       cmsCloseProfile(hOut);\r
+       if (hProof) cmsCloseProfile(hProof);\r
+\r
+       return 1;\r
+}\r
+\r
+\r
+// Simply print help\r
+\r
+static\r
+void Help(int level)\r
+{\r
+     fprintf(stderr, "little cms ICC profile applier for JPEG - v3.2 [LittleCMS %2.2f]\n\n", LCMS_VERSION / 1000.0);\r
+\r
+     switch(level) {\r
+\r
+     default:\r
+     case 0:\r
+\r
+     fprintf(stderr, "usage: jpgicc [flags] input.jpg output.jpg\n");\r
+\r
+     fprintf(stderr, "\nflags:\n\n");\r
+     fprintf(stderr, "%cv - Verbose\n", SW);\r
+     fprintf(stderr, "%ci<profile> - Input profile (defaults to sRGB)\n", SW);\r
+     fprintf(stderr, "%co<profile> - Output profile (defaults to sRGB)\n", SW);\r
+\r
+        PrintRenderingIntents();\r
+\r
+\r
+     fprintf(stderr, "%cb - Black point compensation\n", SW);\r
+     fprintf(stderr, "%cd<0..1> - Observer adaptation state (abs.col. only)\n", SW);\r
+     fprintf(stderr, "%cn - Ignore embedded profile\n", SW);\r
+     fprintf(stderr, "%ce - Embed destination profile\n", SW);\r
+     fprintf(stderr, "%cs<new profile> - Save embedded profile as <new profile>\n", SW);\r
+\r
+     fprintf(stderr, "\n");\r
+\r
+     fprintf(stderr, "%cc<0,1,2,3> - Precalculates transform (0=Off, 1=Normal, 2=Hi-res, 3=LoRes) [defaults to 1]\n", SW);\r
+     fprintf(stderr, "\n");\r
+\r
+     fprintf(stderr, "%cp<profile> - Soft proof profile\n", SW);\r
+     fprintf(stderr, "%cm<0,1,2,3> - SoftProof intent\n", SW);\r
+     fprintf(stderr, "%cg - Marks out-of-gamut colors on softproof\n", SW);\r
+     fprintf(stderr, "%c!<r>,<g>,<b> - Out-of-gamut marker channel values\n", SW);\r
+\r
+     fprintf(stderr, "\n");\r
+     fprintf(stderr, "%cq<0..100> - Output JPEG quality\n", SW);\r
+\r
+     fprintf(stderr, "\n");\r
+     fprintf(stderr, "%ch<0,1,2,3> - More help\n", SW);\r
+     break;\r
+\r
+     case 1:\r
+\r
+     fprintf(stderr, "Examples:\n\n"\r
+                     "To color correct from scanner to sRGB:\n"\r
+                     "\tjpgicc %ciscanner.icm in.jpg out.jpg\n"\r
+                     "To convert from monitor1 to monitor2:\n"\r
+                     "\tjpgicc %cimon1.icm %comon2.icm in.jpg out.jpg\n"\r
+                     "To make a CMYK separation:\n"\r
+                     "\tjpgicc %coprinter.icm inrgb.jpg outcmyk.jpg\n"\r
+                     "To recover sRGB from a CMYK separation:\n"\r
+                     "\tjpgicc %ciprinter.icm incmyk.jpg outrgb.jpg\n"\r
+                     "To convert from CIELab ITU/Fax JPEG to sRGB\n"\r
+                     "\tjpgicc in.jpg out.jpg\n\n",\r
+                     SW, SW, SW, SW, SW, SW);\r
+     break;\r
+\r
+     case 2:\r
+                PrintBuiltins();\r
+                break;\r
+\r
+     case 3:\r
+\r
+     fprintf(stderr, "This program is intended to be a demo of the little cms\n"\r
+                     "engine. Both lcms and this program are freeware. You can\n"\r
+                     "obtain both in source code at http://www.littlecms.com\n"\r
+                     "For suggestions, comments, bug reports etc. send mail to\n"\r
+                     "marti@littlecms.com\n\n");\r
+     break;\r
+     }\r
+\r
+     exit(0);\r
+}\r
+\r
+\r
+// The toggles stuff\r
+\r
+static\r
+void HandleSwitches(int argc, char *argv[])\r
+{\r
+    int s;\r
+\r
+    while ((s=xgetopt(argc,argv,"bBnNvVGgh:H:i:I:o:O:P:p:t:T:c:C:Q:q:M:m:L:l:eEs:S:!:D:d:")) != EOF) {\r
+\r
+        switch (s)\r
+        {\r
+\r
+        case 'b':\r
+        case 'B':\r
+            BlackPointCompensation = TRUE;\r
+            break;\r
+\r
+        case 'd':\r
+        case 'D': ObserverAdaptationState = atof(xoptarg);\r
+            if (ObserverAdaptationState < 0 ||\r
+                ObserverAdaptationState > 1.0)\r
+                FatalError("Adaptation state should be 0..1");\r
+            break;\r
+\r
+        case 'v':\r
+        case 'V':\r
+            Verbose = TRUE;\r
+            break;\r
+\r
+        case 'i':\r
+        case 'I':\r
+            if (lIsDeviceLink)\r
+                FatalError("Device-link already specified");\r
+\r
+            cInpProf = xoptarg;\r
+            break;\r
+\r
+        case 'o':\r
+        case 'O':\r
+            if (lIsDeviceLink)\r
+                FatalError("Device-link already specified");\r
+\r
+            cOutProf = xoptarg;\r
+            break;\r
+\r
+        case 'l':\r
+        case 'L':\r
+                       if (cInpProf != NULL || cOutProf != NULL)\r
+                               FatalError("input/output profiles already specified");\r
+\r
+            cInpProf = xoptarg;\r
+            lIsDeviceLink = TRUE;\r
+            break;\r
+\r
+        case 'p':\r
+        case 'P':\r
+            cProofing = xoptarg;\r
+            break;\r
+\r
+        case 't':\r
+        case 'T':\r
+            Intent = atoi(xoptarg);\r
+            break;\r
+\r
+        case 'N':\r
+        case 'n':\r
+            IgnoreEmbedded = TRUE;\r
+            break;\r
+\r
+        case 'e':\r
+        case 'E':\r
+            EmbedProfile = TRUE;\r
+            break;\r
+\r
+\r
+        case 'g':\r
+        case 'G':\r
+            GamutCheck = TRUE;\r
+            break;\r
+\r
+        case 'c':\r
+        case 'C':\r
+            PrecalcMode = atoi(xoptarg);\r
+            if (PrecalcMode < 0 || PrecalcMode > 2)\r
+                FatalError("Unknown precalc mode '%d'", PrecalcMode);\r
+            break;\r
+\r
+        case 'H':\r
+        case 'h':  {\r
+\r
+            int a =  atoi(xoptarg);\r
+            Help(a);\r
+                   }\r
+            break;\r
+\r
+        case 'q':\r
+        case 'Q':\r
+            jpegQuality = atoi(xoptarg);\r
+            if (jpegQuality > 100) jpegQuality = 100;\r
+            if (jpegQuality < 0)   jpegQuality = 0;\r
+            break;\r
+\r
+        case 'm':\r
+        case 'M':\r
+            ProofingIntent = atoi(xoptarg);\r
+            break;\r
+\r
+        case 's':\r
+        case 'S': SaveEmbedded = xoptarg;\r
+            break;\r
+\r
+        case '!':\r
+            if (sscanf(xoptarg, "%hu,%hu,%hu", &Alarm[0], &Alarm[1], &Alarm[2]) == 3) {\r
+                int i;\r
+                for (i=0; i < 3; i++) {\r
+                    Alarm[i] = (Alarm[i] << 8) | Alarm[i];\r
+                }\r
+            }\r
+            break;\r
+\r
+        default:\r
+\r
+            FatalError("Unknown option - run without args to see valid ones");\r
+        }\r
+\r
+    }\r
+}\r
+\r
+\r
+int main(int argc, char* argv[])\r
+{\r
+       InitUtils("jpgicc");\r
+\r
+       HandleSwitches(argc, argv);\r
+\r
+       if ((argc - xoptind) != 2) {\r
+               Help(0);\r
+       }\r
+\r
+       OpenInput(argv[xoptind]);\r
+       OpenOutput(argv[xoptind+1]);\r
+\r
+       TransformImage(cInpProf, cOutProf);\r
+\r
+\r
+       if (Verbose) { fprintf(stdout, "\n"); fflush(stdout); }\r
+\r
+       Done();\r
+\r
+       return 0;\r
+}\r
+\r
+\r
+\r
index 0476e51..c2246cc 100644 (file)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.3 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -296,7 +296,7 @@ clean-binPROGRAMS:
        list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
        echo " rm -f" $$list; \
        rm -f $$list
-linkicc$(EXEEXT): $(linkicc_OBJECTS) $(linkicc_DEPENDENCIES) 
+linkicc$(EXEEXT): $(linkicc_OBJECTS) $(linkicc_DEPENDENCIES) $(EXTRA_linkicc_DEPENDENCIES) 
        @rm -f linkicc$(EXEEXT)
        $(linkicc_LINK) $(linkicc_OBJECTS) $(linkicc_LDADD) $(LIBS)
 
@@ -464,10 +464,15 @@ install-am: all-am
 
 installcheck: installcheck-am
 install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-         install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-         `test -z '$(STRIP)' || \
-           echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
 mostlyclean-generic:
 
 clean-generic:
index c933bdc..a90d110 100644 (file)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.3 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -295,7 +295,7 @@ clean-binPROGRAMS:
        list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
        echo " rm -f" $$list; \
        rm -f $$list
-psicc$(EXEEXT): $(psicc_OBJECTS) $(psicc_DEPENDENCIES) 
+psicc$(EXEEXT): $(psicc_OBJECTS) $(psicc_DEPENDENCIES) $(EXTRA_psicc_DEPENDENCIES) 
        @rm -f psicc$(EXEEXT)
        $(psicc_LINK) $(psicc_OBJECTS) $(psicc_LDADD) $(LIBS)
 
@@ -463,10 +463,15 @@ install-am: all-am
 
 installcheck: installcheck-am
 install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-         install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-         `test -z '$(STRIP)' || \
-           echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
 mostlyclean-generic:
 
 clean-generic:
index 15fe863..7db3b56 100644 (file)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.3 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -93,6 +93,12 @@ am__nobase_list = $(am__nobase_strip_setup); \
 am__base_list = \
   sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
   sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__uninstall_files_from_dir = { \
+  test -z "$$files" \
+    || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
+    || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
+         $(am__cd) "$$dir" && rm -f $$files; }; \
+  }
 man1dir = $(mandir)/man1
 NROFF = nroff
 MANS = $(man_MANS)
@@ -319,7 +325,7 @@ clean-binPROGRAMS:
        list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
        echo " rm -f" $$list; \
        rm -f $$list
-tificc$(EXEEXT): $(tificc_OBJECTS) $(tificc_DEPENDENCIES) 
+tificc$(EXEEXT): $(tificc_OBJECTS) $(tificc_DEPENDENCIES) $(EXTRA_tificc_DEPENDENCIES) 
        @rm -f tificc$(EXEEXT)
        $(tificc_LINK) $(tificc_OBJECTS) $(tificc_LDADD) $(LIBS)
 
@@ -422,9 +428,7 @@ uninstall-man1:
          sed -n '/\.1[a-z]*$$/p'; \
        } | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^1][0-9a-z]*$$,1,;x' \
              -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \
-       test -z "$$files" || { \
-         echo " ( cd '$(DESTDIR)$(man1dir)' && rm -f" $$files ")"; \
-         cd "$(DESTDIR)$(man1dir)" && rm -f $$files; }
+       dir='$(DESTDIR)$(man1dir)'; $(am__uninstall_files_from_dir)
 
 ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
        list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
@@ -538,10 +542,15 @@ install-am: all-am
 
 installcheck: installcheck-am
 install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-         install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-         `test -z '$(STRIP)' || \
-           echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
 mostlyclean-generic:
 
 clean-generic:
index 57e0b4d..bb20f87 100644 (file)
@@ -206,7 +206,7 @@ cmsUInt32Number GetInputPixelType(TIFF *Bank)
     TIFFGetFieldDefaulted(Bank,  TIFFTAG_BITSPERSAMPLE, &bps);
 
     if (bps == 1)
-        FatalError("Sorry, bilevel TIFFs has nothig to do with ICC profiles");
+        FatalError("Sorry, bilevel TIFFs has nothing to do with ICC profiles");
 
     if (bps != 8 && bps != 16 && bps != 32)
         FatalError("Sorry, 8, 16 or 32 bits per sample only");
@@ -870,7 +870,7 @@ int TransformImage(TIFF* in, TIFF* out, const char *cDefInpProf)
 static
 void Help(int level)
 {
-    fprintf(stderr, "little cms ICC profile applier for TIFF - v6.1 [LittleCMS %2.2f]\n\n", LCMS_VERSION / 1000.0);
+    fprintf(stderr, "little cms ICC profile applier for TIFF - v6.2 [LittleCMS %2.2f]\n\n", LCMS_VERSION / 1000.0);
     fflush(stderr);
 
     switch(level) {
@@ -878,7 +878,7 @@ void Help(int level)
      default:
      case 0:
 
-         fprintf(stderr, "usage: tifficc [flags] input.tif output.tif\n");
+         fprintf(stderr, "usage: tificc [flags] input.tif output.tif\n");
 
          fprintf(stderr, "\nflags:\n\n");
          fprintf(stderr, "%cv - Verbose\n", SW);
@@ -918,15 +918,15 @@ void Help(int level)
 
          fprintf(stderr, "Examples:\n\n"
              "To color correct from scanner to sRGB:\n"
-             "\ttifficc %ciscanner.icm in.tif out.tif\n"
+             "\ttificc %ciscanner.icm in.tif out.tif\n"
              "To convert from monitor1 to monitor2:\n"
-             "\ttifficc %cimon1.icm %comon2.icm in.tif out.tif\n"
+             "\ttificc %cimon1.icm %comon2.icm in.tif out.tif\n"
              "To make a CMYK separation:\n"
-             "\ttifficc %coprinter.icm inrgb.tif outcmyk.tif\n"
+             "\ttificc %coprinter.icm inrgb.tif outcmyk.tif\n"
              "To recover sRGB from a CMYK separation:\n"
-             "\ttifficc %ciprinter.icm incmyk.tif outrgb.tif\n"
+             "\ttificc %ciprinter.icm incmyk.tif outrgb.tif\n"
              "To convert from CIELab TIFF to sRGB\n"
-             "\ttifficc %ci*Lab in.tif out.tif\n\n", 
+             "\ttificc %ci*Lab in.tif out.tif\n\n", 
              SW, SW, SW, SW, SW, SW);
          break;
 
@@ -1088,7 +1088,7 @@ int main(int argc, char* argv[])
    
     cmsPlugin(&TiffLabPlugin);
 
-    InitUtils("tifficc");
+    InitUtils("tificc");
 
     HandleSwitches(argc, argv);
 
index 477a3c5..ad6b9b0 100644 (file)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.3 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -296,7 +296,7 @@ clean-binPROGRAMS:
        list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
        echo " rm -f" $$list; \
        rm -f $$list
-transicc$(EXEEXT): $(transicc_OBJECTS) $(transicc_DEPENDENCIES) 
+transicc$(EXEEXT): $(transicc_OBJECTS) $(transicc_DEPENDENCIES) $(EXTRA_transicc_DEPENDENCIES) 
        @rm -f transicc$(EXEEXT)
        $(transicc_LINK) $(transicc_OBJECTS) $(transicc_LDADD) $(LIBS)
 
@@ -464,10 +464,15 @@ install-am: all-am
 
 installcheck: installcheck-am
 install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-         install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-         `test -z '$(STRIP)' || \
-           echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
 mostlyclean-generic:
 
 clean-generic:
index 2181359..27b7de9 100644 (file)
@@ -469,8 +469,12 @@ cmsBool OpenTransforms(void)
 
         if (cmsIsTag(hOutput, cmsSigColorantTableTag)){
 
-            List = cmsReadTag(hInput, cmsSigColorantTableTag);
+            List = cmsReadTag(hOutput, cmsSigColorantTableTag);
             OutputColorant = cmsDupNamedColorList(List);
+            if (cmsNamedColorCount(OutputColorant) <= 3) 
+                SetRange(255, FALSE);
+            else
+                SetRange(1, FALSE);  // Inks are already divided by 100 in the formatter
         }
         else OutputColorant = ComponentNames(OutputColorSpace, FALSE);
 
@@ -909,6 +913,36 @@ void TakeCGATSValues(int nPatch, cmsFloat64Number Float[])
         Float[2] = GetIT8Val("CMY_Y", 1.0);
         break;
 
+    case cmsSig1colorData:
+    case cmsSig2colorData:
+    case cmsSig3colorData:
+    case cmsSig4colorData:
+    case cmsSig5colorData:
+    case cmsSig6colorData:
+    case cmsSig7colorData:
+    case cmsSig8colorData:
+    case cmsSig9colorData:
+    case cmsSig10colorData:
+    case cmsSig11colorData:
+    case cmsSig12colorData:
+    case cmsSig13colorData:
+    case cmsSig14colorData:
+    case cmsSig15colorData:
+        {
+            cmsUInt32Number i, n;
+
+            n = cmsChannelsOf(InputColorSpace);
+            for (i=0; i < n; i++) { 
+
+                char Buffer[255];
+
+                sprintf(Buffer, "%dCLR_%d", n, i+1);
+                Float[i] = GetIT8Val(Buffer, 100.0);
+            }
+
+        }
+       break;
+
     default: 
         {
             cmsUInt32Number i, n;
@@ -987,6 +1021,37 @@ void PutCGATSValues(cmsFloat64Number Float[])
         SetCGATSfld("CMY_Y", Float[2]);                 
         break;
 
+    case cmsSig1colorData:
+    case cmsSig2colorData:
+    case cmsSig3colorData:
+    case cmsSig4colorData:
+    case cmsSig5colorData:
+    case cmsSig6colorData:
+    case cmsSig7colorData:
+    case cmsSig8colorData:
+    case cmsSig9colorData:
+    case cmsSig10colorData:
+    case cmsSig11colorData:
+    case cmsSig12colorData:
+    case cmsSig13colorData:
+    case cmsSig14colorData:
+    case cmsSig15colorData:
+        {
+
+            cmsUInt32Number i, n;
+
+            n = cmsChannelsOf(InputColorSpace);
+            for (i=0; i < n; i++) { 
+
+                char Buffer[255];
+
+                sprintf(Buffer, "%dCLR_%d", n, i+1);
+
+                SetCGATSfld(Buffer, Float[i] * 100.0);
+            }
+        }
+       break;
+
     default: 
         {
 
@@ -1074,6 +1139,36 @@ void SetOutputDataFormat(void)
         cmsIT8SetDataFormat(hIT8out, 3, "CMY_Y");                   
         break;
 
+    case cmsSig1colorData:
+    case cmsSig2colorData:
+    case cmsSig3colorData:
+    case cmsSig4colorData:
+    case cmsSig5colorData:
+    case cmsSig6colorData:
+    case cmsSig7colorData:
+    case cmsSig8colorData:
+    case cmsSig9colorData:
+    case cmsSig10colorData:
+    case cmsSig11colorData:
+    case cmsSig12colorData:
+    case cmsSig13colorData:
+    case cmsSig14colorData:
+    case cmsSig15colorData:
+       {
+           int i, n;
+           char Buffer[255];
+
+           n = cmsChannelsOf(OutputColorSpace);
+           cmsIT8SetPropertyDbl(hIT8out, "NUMBER_OF_FIELDS", n+1);
+           cmsIT8SetDataFormat(hIT8out, 0, "SAMPLE_ID");
+
+           for (i=1; i <= n; i++) {
+               sprintf(Buffer, "%dCLR_%d", n, i);
+               cmsIT8SetDataFormat(hIT8out, i, Buffer);
+           }
+       }
+       break;
+
     default: {
 
         int i, n;
@@ -1129,7 +1224,7 @@ int main(int argc, char *argv[])
 
     int nPatch = 0;
 
-    fprintf(stderr, "LittleCMS ColorSpace conversion calculator - 4.1 [LittleCMS %2.2f]\n", LCMS_VERSION / 1000.0);
+    fprintf(stderr, "LittleCMS ColorSpace conversion calculator - 4.2 [LittleCMS %2.2f]\n", LCMS_VERSION / 1000.0);
 
     InitUtils("transicc");