//--------------------------------------------------------------------------------- // // Little Color Management System // Copyright (c) 1998-2023 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" // inter PCS conversions XYZ <-> CIE L* a* b* /* CIE 15:2004 CIELab is defined as: L* = 116*f(Y/Yn) - 16 0 <= L* <= 100 a* = 500*[f(X/Xn) - f(Y/Yn)] b* = 200*[f(Y/Yn) - f(Z/Zn)] and f(t) = t^(1/3) 1 >= t > (24/116)^3 (841/108)*t + (16/116) 0 <= t <= (24/116)^3 Reverse transform is: X = Xn*[a* / 500 + (L* + 16) / 116] ^ 3 if (X/Xn) > (24/116) = Xn*(a* / 500 + L* / 116) / 7.787 if (X/Xn) <= (24/116) PCS in Lab2 is encoded as: 8 bit Lab PCS: L* 0..100 into a 0..ff byte. a* t + 128 range is -128.0 +127.0 b* 16 bit Lab PCS: L* 0..100 into a 0..ff00 word. a* t + 128 range is -128.0 +127.9961 b* Interchange Space Component Actual Range Encoded Range CIE XYZ X 0 -> 1.99997 0x0000 -> 0xffff CIE XYZ Y 0 -> 1.99997 0x0000 -> 0xffff CIE XYZ Z 0 -> 1.99997 0x0000 -> 0xffff Version 2,3 ----------- CIELAB (16 bit) L* 0 -> 100.0 0x0000 -> 0xff00 CIELAB (16 bit) a* -128.0 -> +127.996 0x0000 -> 0x8000 -> 0xffff CIELAB (16 bit) b* -128.0 -> +127.996 0x0000 -> 0x8000 -> 0xffff Version 4 --------- CIELAB (16 bit) L* 0 -> 100.0 0x0000 -> 0xffff CIELAB (16 bit) a* -128.0 -> +127 0x0000 -> 0x8080 -> 0xffff CIELAB (16 bit) b* -128.0 -> +127 0x0000 -> 0x8080 -> 0xffff */ // Conversions void CMSEXPORT cmsXYZ2xyY(cmsCIExyY* Dest, const cmsCIEXYZ* Source) { … } void CMSEXPORT cmsxyY2XYZ(cmsCIEXYZ* Dest, const cmsCIExyY* Source) { … } /* The break point (24/116)^3 = (6/29)^3 is a very small amount of tristimulus primary (0.008856). Generally, this only happens for nearly ideal blacks and for some orange / amber colors in transmission mode. For example, the Z value of the orange turn indicator lamp lens on an automobile will often be below this value. But the Z does not contribute to the perceived color directly. */ static cmsFloat64Number f(cmsFloat64Number t) { … } static cmsFloat64Number f_1(cmsFloat64Number t) { … } // Standard XYZ to Lab. it can handle negative XZY numbers in some cases void CMSEXPORT cmsXYZ2Lab(const cmsCIEXYZ* WhitePoint, cmsCIELab* Lab, const cmsCIEXYZ* xyz) { … } // Standard XYZ to Lab. It can return negative XYZ in some cases void CMSEXPORT cmsLab2XYZ(const cmsCIEXYZ* WhitePoint, cmsCIEXYZ* xyz, const cmsCIELab* Lab) { … } static cmsFloat64Number L2float2(cmsUInt16Number v) { … } // the a/b part static cmsFloat64Number ab2float2(cmsUInt16Number v) { … } static cmsUInt16Number L2Fix2(cmsFloat64Number L) { … } static cmsUInt16Number ab2Fix2(cmsFloat64Number ab) { … } static cmsFloat64Number L2float4(cmsUInt16Number v) { … } // the a/b part static cmsFloat64Number ab2float4(cmsUInt16Number v) { … } void CMSEXPORT cmsLabEncoded2FloatV2(cmsCIELab* Lab, const cmsUInt16Number wLab[3]) { … } void CMSEXPORT cmsLabEncoded2Float(cmsCIELab* Lab, const cmsUInt16Number wLab[3]) { … } static cmsFloat64Number Clamp_L_doubleV2(cmsFloat64Number L) { … } static cmsFloat64Number Clamp_ab_doubleV2(cmsFloat64Number ab) { … } void CMSEXPORT cmsFloat2LabEncodedV2(cmsUInt16Number wLab[3], const cmsCIELab* fLab) { … } static cmsFloat64Number Clamp_L_doubleV4(cmsFloat64Number L) { … } static cmsFloat64Number Clamp_ab_doubleV4(cmsFloat64Number ab) { … } static cmsUInt16Number L2Fix4(cmsFloat64Number L) { … } static cmsUInt16Number ab2Fix4(cmsFloat64Number ab) { … } void CMSEXPORT cmsFloat2LabEncoded(cmsUInt16Number wLab[3], const cmsCIELab* fLab) { … } // Auxiliary: convert to Radians static cmsFloat64Number RADIANS(cmsFloat64Number deg) { … } // Auxiliary: atan2 but operating in degrees and returning 0 if a==b==0 static cmsFloat64Number atan2deg(cmsFloat64Number a, cmsFloat64Number b) { … } // Auxiliary: Square static cmsFloat64Number Sqr(cmsFloat64Number v) { … } // From cylindrical coordinates. No check is performed, then negative values are allowed void CMSEXPORT cmsLab2LCh(cmsCIELCh* LCh, const cmsCIELab* Lab) { … } // To cylindrical coordinates. No check is performed, then negative values are allowed void CMSEXPORT cmsLCh2Lab(cmsCIELab* Lab, const cmsCIELCh* LCh) { … } // In XYZ All 3 components are encoded using 1.15 fixed point static cmsUInt16Number XYZ2Fix(cmsFloat64Number d) { … } void CMSEXPORT cmsFloat2XYZEncoded(cmsUInt16Number XYZ[3], const cmsCIEXYZ* fXYZ) { … } // To convert from Fixed 1.15 point to cmsFloat64Number static cmsFloat64Number XYZ2float(cmsUInt16Number v) { … } void CMSEXPORT cmsXYZEncoded2Float(cmsCIEXYZ* fXYZ, const cmsUInt16Number XYZ[3]) { … } // Returns dE on two Lab values cmsFloat64Number CMSEXPORT cmsDeltaE(const cmsCIELab* Lab1, const cmsCIELab* Lab2) { … } // Return the CIE94 Delta E cmsFloat64Number CMSEXPORT cmsCIE94DeltaE(const cmsCIELab* Lab1, const cmsCIELab* Lab2) { … } // Auxiliary static cmsFloat64Number ComputeLBFD(const cmsCIELab* Lab) { … } // bfd - gets BFD(1:1) difference between Lab1, Lab2 cmsFloat64Number CMSEXPORT cmsBFDdeltaE(const cmsCIELab* Lab1, const cmsCIELab* Lab2) { … } // cmc - CMC(l:c) difference between Lab1, Lab2 cmsFloat64Number CMSEXPORT cmsCMCdeltaE(const cmsCIELab* Lab1, const cmsCIELab* Lab2, cmsFloat64Number l, cmsFloat64Number c) { … } // 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) { … } // This function returns a number of gridpoints to be used as LUT table. It assumes same number // of gripdpoints in all dimensions. Flags may override the choice. cmsUInt32Number CMSEXPORT _cmsReasonableGridpointsByColorspace(cmsColorSpaceSignature Colorspace, cmsUInt32Number dwFlags) { … } cmsBool _cmsEndPointsBySpace(cmsColorSpaceSignature Space, cmsUInt16Number **White, cmsUInt16Number **Black, cmsUInt32Number *nOutputs) { … } // Several utilities ------------------------------------------------------- // Translate from our colorspace to ICC representation cmsColorSpaceSignature CMSEXPORT _cmsICCcolorSpace(int OurNotation) { … } int CMSEXPORT _cmsLCMScolorSpace(cmsColorSpaceSignature ProfileSpace) { … } cmsInt32Number CMSEXPORT cmsChannelsOfColorSpace(cmsColorSpaceSignature ColorSpace) { … } /** * DEPRECATED: Provided for compatibility only */ cmsUInt32Number CMSEXPORT cmsChannelsOf(cmsColorSpaceSignature ColorSpace) { … }