File indexing completed on 2025-02-23 04:10:58
0001 /* 0002 * SPDX-License-Identifier: GPL-3.0-or-later 0003 */ 0004 0005 #include "TestKoLcmsColorProfile.h" 0006 0007 #include <cmath> 0008 #include <lcms2.h> 0009 0010 #include <KoColor.h> 0011 #include <KoColorProfile.h> 0012 #include <KoColorSpace.h> 0013 #include <KoColorSpaceRegistry.h> 0014 #include <simpletest.h> 0015 0016 qreal testRounding(qreal value) 0017 { 0018 qreal factor; 0019 int temp; 0020 const int numPlaces = 3; 0021 0022 factor = pow(10.0, numPlaces); 0023 temp = (int)(value * factor + 0.5); 0024 return temp / factor; 0025 } 0026 0027 void TestKoLcmsColorProfile::testConversion() 0028 { 0029 const KoColorSpace *sRgb = KoColorSpaceRegistry::instance()->rgb16("sRGB built-in"); 0030 Q_ASSERT(sRgb); 0031 const KoColorSpace *linearRgb = KoColorSpaceRegistry::instance()->rgb16("scRGB (linear)"); 0032 Q_ASSERT(linearRgb); 0033 0034 quint16 src[4]; 0035 src[0] = 257; 0036 src[1] = 257; 0037 src[2] = 257; 0038 src[3] = 65535; 0039 0040 quint16 dst[4]; 0041 memset(&dst, 0, 8); 0042 0043 linearRgb->convertPixelsTo((quint8 *)&src, (quint8 *)&dst, sRgb, 1, KoColorConversionTransformation::IntentRelativeColorimetric, KoColorConversionTransformation::BlackpointCompensation); 0044 0045 quint16 dst2[4]; 0046 memset(&dst2, 0, 8); 0047 0048 cmsHPROFILE sRgbProfile = cmsCreate_sRGBProfile(); 0049 QByteArray rawData = linearRgb->profile()->rawData(); 0050 cmsHPROFILE linearRgbProfile = cmsOpenProfileFromMem((void *)rawData.constData(), rawData.size()); 0051 0052 cmsHTRANSFORM tf = cmsCreateTransform(linearRgbProfile, 0053 TYPE_BGRA_16, 0054 sRgbProfile, 0055 TYPE_BGRA_16, 0056 INTENT_RELATIVE_COLORIMETRIC, 0057 cmsFLAGS_NOOPTIMIZE); 0058 0059 cmsDoTransform(tf, (quint8 *)&src, (quint8 *)&dst2, 1); 0060 0061 Q_ASSERT(dst[0] == dst2[0]); 0062 0063 } 0064 0065 void TestKoLcmsColorProfile::testProofingConversion() 0066 { 0067 const KoColorSpace *sRgb = KoColorSpaceRegistry::instance()->rgb16("sRGB built-in"); 0068 Q_ASSERT(sRgb); 0069 const KoColorSpace *lab = KoColorSpaceRegistry::instance()->lab16();//there's only one lab profile, replace with it's name. 0070 Q_ASSERT(lab); 0071 0072 quint16 src[4];//the following ought to give us a purple only possible in lab. I can't seem to proof this away, somehow... 0073 src[0] = 32896; 0074 src[1] = 65535; 0075 src[2] = 0; 0076 src[3] = 65535; 0077 0078 quint16 dst[4]; 0079 memset(&dst, 0, 8); 0080 0081 cmsHPROFILE sRgbProfile = cmsCreate_sRGBProfile(); 0082 cmsHPROFILE LabProfile = cmsCreateLab4Profile(NULL); 0083 0084 quint16 alarm[cmsMAXCHANNELS]={0}; 0085 alarm[0] = 65535; 0086 alarm[1] = 0; 0087 alarm[2] = 0; 0088 alarm[3] = 65535; 0089 cmsSetAlarmCodes(alarm); 0090 0091 cmsHTRANSFORM tf = cmsCreateProofingTransform(LabProfile, 0092 TYPE_Lab_16, 0093 LabProfile, 0094 TYPE_Lab_16, 0095 sRgbProfile, 0096 INTENT_ABSOLUTE_COLORIMETRIC, 0097 INTENT_ABSOLUTE_COLORIMETRIC, 0098 cmsFLAGS_SOFTPROOFING|cmsFLAGS_GAMUTCHECK); 0099 0100 cmsDoTransform(tf, (quint8 *)&src, (quint8 *)&dst, 1); 0101 0102 qDebug()<<dst[0]<<","<<dst[1]<<","<<dst[2]<<","<<dst[3]; 0103 Q_ASSERT((dst[0] == alarm[0]) && (dst[1] == alarm[1]) && (dst[2] == alarm[2])); 0104 0105 } 0106 SIMPLE_TEST_MAIN(TestKoLcmsColorProfile)