Imported Upstream version 2.4
[platform/upstream/lcms2.git] / src / cmsio1.c
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);