/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
// This file is available under and governed by the GNU General Public // License version 2 only, as published by the Free Software Foundation. // However, the following notice accompanied the original version of this // file: // //--------------------------------------------------------------------------------- // // Little Color Management System // Copyright (c) 1998-2022 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. // //--------------------------------------------------------------------------------- //
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
ISum = 1./(Source -> X + Source -> Y + Source -> Z);
Dest -> x = (Source -> X) * ISum;
Dest -> y = (Source -> Y) * ISum;
Dest -> Y = Source -> Y;
}
void CMSEXPORT cmsxyY2XYZ(cmsCIEXYZ* Dest, const cmsCIExyY* Source)
{
Dest -> X = (Source -> x / Source -> y) * Source -> Y;
Dest -> Y = Source -> Y;
Dest -> Z = ((1 - Source -> x - Source -> y) / Source -> y) * Source -> Y;
}
/* 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.
*/
// Standard XYZ to Lab. it can handle negative XZY numbers in some cases void CMSEXPORT cmsXYZ2Lab(const cmsCIEXYZ* WhitePoint, cmsCIELab* Lab, const cmsCIEXYZ* xyz)
{
cmsFloat64Number fx, fy, fz;
if (WhitePoint == NULL)
WhitePoint = cmsD50_XYZ();
// Standard XYZ to Lab. It can return negative XYZ in some cases void CMSEXPORT cmsLab2XYZ(const cmsCIEXYZ* WhitePoint, cmsCIEXYZ* xyz, const cmsCIELab* Lab)
{
cmsFloat64Number x, y, z;
if (WhitePoint == NULL)
WhitePoint = cmsD50_XYZ();
y = (Lab-> L + 16.0) / 116.0;
x = y + 0.002 * Lab -> a;
z = y - 0.005 * Lab -> b;
xyz -> X = f_1(x) * WhitePoint -> X;
xyz -> Y = f_1(y) * WhitePoint -> Y;
xyz -> Z = f_1(z) * WhitePoint -> Z;
static
cmsFloat64Number Clamp_ab_doubleV2(cmsFloat64Number ab)
{ if (ab < MIN_ENCODEABLE_ab2) ab = MIN_ENCODEABLE_ab2; if (ab > MAX_ENCODEABLE_ab2) ab = MAX_ENCODEABLE_ab2;
static
cmsFloat64Number Clamp_L_doubleV4(cmsFloat64Number L)
{ if (L < 0) L = 0; if (L > 100.0) L = 100.0;
return L;
}
static
cmsFloat64Number Clamp_ab_doubleV4(cmsFloat64Number ab)
{ if (ab < MIN_ENCODEABLE_ab4) ab = MIN_ENCODEABLE_ab4; if (ab > MAX_ENCODEABLE_ab4) ab = MAX_ENCODEABLE_ab4;
// Auxiliary: atan2 but operating in degrees and returning 0 if a==b==0 static
cmsFloat64Number atan2deg(cmsFloat64Number a, cmsFloat64Number b)
{
cmsFloat64Number h;
if (a == 0 && b == 0)
h = 0; else
h = atan2(a, b);
h *= (180. / M_PI);
while (h > 360.)
h -= 360.;
while ( h < 0)
h += 360.;
return h;
}
// Auxiliary: Square static
cmsFloat64Number Sqr(cmsFloat64Number v)
{ return v * v;
} // From cylindrical coordinates. No check is performed, then negative values are allowed void CMSEXPORT cmsLab2LCh(cmsCIELCh* LCh, const cmsCIELab* Lab)
{
LCh -> L = Lab -> L;
LCh -> C = pow(Sqr(Lab ->a) + Sqr(Lab ->b), 0.5);
LCh -> h = atan2deg(Lab ->b, Lab ->a);
}
// To cylindrical coordinates. No check is performed, then negative values are allowed void CMSEXPORT cmsLCh2Lab(cmsCIELab* Lab, const cmsCIELCh* LCh)
{
cmsFloat64Number h = (LCh -> h * M_PI) / 180.0;
Lab -> L = LCh -> L;
Lab -> a = LCh -> C * cos(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);
}
// 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)
{
cmsUInt32Number nChannels;
// HighResPrecalc is maximum resolution if (dwFlags & cmsFLAGS_HIGHRESPRECALC) {
if (nChannels > 4) return 7; // 7 for Hifi
if (nChannels == 4) // 23 for CMYK return 23;
return 49; // 49 for RGB and others
}
// LowResPrecal is lower resolution if (dwFlags & cmsFLAGS_LOWRESPRECALC) {
if (nChannels > 4) return 6; // 6 for more than 4 channels
if (nChannels == 1) return 33; // For monochrome
return 17; // 17 for remaining
}
// Default values if (nChannels > 4) return 7; // 7 for Hifi
if (nChannels == 4) return 17; // 17 for CMYK
return 33; // 33 for RGB
}
cmsBool _cmsEndPointsBySpace(cmsColorSpaceSignature Space,
cmsUInt16Number **White,
cmsUInt16Number **Black,
cmsUInt32Number *nOutputs)
{ // Only most common spaces
case PT_CMY: return cmsSigCmyData; case PT_CMYK: return cmsSigCmykData; case PT_YCbCr:return cmsSigYCbCrData; case PT_YUV: return cmsSigLuvData; case PT_XYZ: return cmsSigXYZData;
case PT_LabV2: case PT_Lab: return cmsSigLabData;
case PT_YUVK: return cmsSigLuvKData; case PT_HSV: return cmsSigHsvData; case PT_HLS: return cmsSigHlsData; case PT_Yxy: return cmsSigYxyData;
case PT_MCH1: return cmsSigMCH1Data; case PT_MCH2: return cmsSigMCH2Data; case PT_MCH3: return cmsSigMCH3Data; case PT_MCH4: return cmsSigMCH4Data; case PT_MCH5: return cmsSigMCH5Data; case PT_MCH6: return cmsSigMCH6Data; case PT_MCH7: return cmsSigMCH7Data; case PT_MCH8: return cmsSigMCH8Data;
case PT_MCH9: return cmsSigMCH9Data; case PT_MCH10: return cmsSigMCHAData; case PT_MCH11: return cmsSigMCHBData; case PT_MCH12: return cmsSigMCHCData; case PT_MCH13: return cmsSigMCHDData; case PT_MCH14: return cmsSigMCHEData; case PT_MCH15: return cmsSigMCHFData;
default: return (cmsColorSpaceSignature) 0;
}
}
int CMSEXPORT _cmsLCMScolorSpace(cmsColorSpaceSignature ProfileSpace)
{ switch (ProfileSpace) {
case cmsSigGrayData: return PT_GRAY; case cmsSigRgbData: return PT_RGB; case cmsSigCmyData: return PT_CMY; case cmsSigCmykData: return PT_CMYK; case cmsSigYCbCrData:return PT_YCbCr; case cmsSigLuvData: return PT_YUV; case cmsSigXYZData: return PT_XYZ; case cmsSigLabData: return PT_Lab; case cmsSigLuvKData: return PT_YUVK; 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;
case cmsSigMCH1Data: case cmsSig1colorData: case cmsSigGrayData: return 1;
case cmsSigMCH2Data: case cmsSig2colorData: return 2;
case cmsSigXYZData: case cmsSigLabData: case cmsSigLuvData: case cmsSigYCbCrData: case cmsSigYxyData: case cmsSigRgbData: case cmsSigHsvData: case cmsSigHlsData: case cmsSigCmyData: case cmsSigMCH3Data: case cmsSig3colorData: return 3;
case cmsSigLuvKData: case cmsSigCmykData: case cmsSigMCH4Data: case cmsSig4colorData: return 4;
case cmsSigMCH5Data: case cmsSig5colorData: return 5;
case cmsSigMCH6Data: case cmsSig6colorData: return 6;
case cmsSigMCH7Data: case cmsSig7colorData: return 7;
case cmsSigMCH8Data: case cmsSig8colorData: return 8;
case cmsSigMCH9Data: case cmsSig9colorData: return 9;
case cmsSigMCHAData: case cmsSig10colorData: return 10;
case cmsSigMCHBData: case cmsSig11colorData: return 11;
case cmsSigMCHCData: case cmsSig12colorData: return 12;
case cmsSigMCHDData: case cmsSig13colorData: return 13;
case cmsSigMCHEData: case cmsSig14colorData: return 14;
case cmsSigMCHFData: case cmsSig15colorData: return 15;
default: return -1;
}
}
/** * DEPRECATED: Provided for compatibility only
*/
cmsUInt32Number CMSEXPORT cmsChannelsOf(cmsColorSpaceSignature ColorSpace)
{ int n = cmsChannelsOfColorSpace(ColorSpace); if (n < 0) return 3; return (cmsUInt32Number)n;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.