diff options
Diffstat (limited to 'lcms2mt/testbed/testcms2.c')
-rw-r--r-- | lcms2mt/testbed/testcms2.c | 172 |
1 files changed, 144 insertions, 28 deletions
diff --git a/lcms2mt/testbed/testcms2.c b/lcms2mt/testbed/testcms2.c index f633f565..87c3d460 100644 --- a/lcms2mt/testbed/testcms2.c +++ b/lcms2mt/testbed/testcms2.c @@ -24,7 +24,6 @@ //--------------------------------------------------------------------------------- // - #include "testcms2.h" // A single check. Returns 1 if success, 0 if failed @@ -463,7 +462,7 @@ cmsFloat64Number Clip(cmsFloat64Number v) } static -cmsInt32Number ForwardSampler(cmsContext ContextID, register const cmsUInt16Number In[], cmsUInt16Number Out[], void* Cargo) +cmsInt32Number ForwardSampler(cmsContext ContextID, CMSREGISTER const cmsUInt16Number In[], cmsUInt16Number Out[], void* Cargo) { FakeCMYKParams* p = (FakeCMYKParams*) Cargo; cmsFloat64Number rgb[3], cmyk[4]; @@ -493,7 +492,7 @@ cmsInt32Number ForwardSampler(cmsContext ContextID, register const cmsUInt16Numb static -cmsInt32Number ReverseSampler(cmsContext ContextID, register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void* Cargo) +cmsInt32Number ReverseSampler(cmsContext ContextID, CMSREGISTER const cmsUInt16Number In[], CMSREGISTER cmsUInt16Number Out[], CMSREGISTER void* Cargo) { FakeCMYKParams* p = (FakeCMYKParams*) Cargo; cmsFloat64Number c, m, y, k, rgb[3]; @@ -1726,9 +1725,10 @@ cmsUInt16Number Fn8D3(cmsUInt16Number a1, cmsUInt16Number a2, cmsUInt16Number a3 static -cmsInt32Number Sampler3D(cmsContext ContextID, register const cmsUInt16Number In[], - register cmsUInt16Number Out[], - register void * Cargo) +cmsInt32Number Sampler3D(cmsContext ContextID, + CMSREGISTER const cmsUInt16Number In[], + CMSREGISTER cmsUInt16Number Out[], + CMSREGISTER void * Cargo) { Out[0] = Fn8D1(In[0], In[1], In[2], 0, 0, 0, 0, 0, 3); @@ -1742,9 +1742,10 @@ cmsInt32Number Sampler3D(cmsContext ContextID, register const cmsUInt16Number In } static -cmsInt32Number Sampler4D(cmsContext ContextID, register const cmsUInt16Number In[], - register cmsUInt16Number Out[], - register void * Cargo) +cmsInt32Number Sampler4D(cmsContext ContextID, + CMSREGISTER const cmsUInt16Number In[], + CMSREGISTER cmsUInt16Number Out[], + CMSREGISTER void * Cargo) { Out[0] = Fn8D1(In[0], In[1], In[2], In[3], 0, 0, 0, 0, 4); @@ -1757,9 +1758,10 @@ cmsInt32Number Sampler4D(cmsContext ContextID, register const cmsUInt16Number In } static -cmsInt32Number Sampler5D(cmsContext ContextID, register const cmsUInt16Number In[], - register cmsUInt16Number Out[], - register void * Cargo) +cmsInt32Number Sampler5D(cmsContext ContextID, + CMSREGISTER const cmsUInt16Number In[], + CMSREGISTER cmsUInt16Number Out[], + CMSREGISTER void * Cargo) { Out[0] = Fn8D1(In[0], In[1], In[2], In[3], In[4], 0, 0, 0, 5); @@ -1772,9 +1774,10 @@ cmsInt32Number Sampler5D(cmsContext ContextID, register const cmsUInt16Number In } static -cmsInt32Number Sampler6D(cmsContext ContextID, register const cmsUInt16Number In[], - register cmsUInt16Number Out[], - register void * Cargo) +cmsInt32Number Sampler6D(cmsContext ContextID, + CMSREGISTER const cmsUInt16Number In[], + CMSREGISTER cmsUInt16Number Out[], + CMSREGISTER void * Cargo) { Out[0] = Fn8D1(In[0], In[1], In[2], In[3], In[4], In[5], 0, 0, 6); @@ -1787,9 +1790,10 @@ cmsInt32Number Sampler6D(cmsContext ContextID, register const cmsUInt16Number In } static -cmsInt32Number Sampler7D(cmsContext ContextID, register const cmsUInt16Number In[], - register cmsUInt16Number Out[], - register void * Cargo) +cmsInt32Number Sampler7D(cmsContext ContextID, + CMSREGISTER const cmsUInt16Number In[], + CMSREGISTER cmsUInt16Number Out[], + CMSREGISTER void * Cargo) { Out[0] = Fn8D1(In[0], In[1], In[2], In[3], In[4], In[5], In[6], 0, 7); @@ -1802,9 +1806,10 @@ cmsInt32Number Sampler7D(cmsContext ContextID, register const cmsUInt16Number In } static -cmsInt32Number Sampler8D(cmsContext ContextID, register const cmsUInt16Number In[], - register cmsUInt16Number Out[], - register void * Cargo) +cmsInt32Number Sampler8D(cmsContext ContextID, + CMSREGISTER const cmsUInt16Number In[], + CMSREGISTER cmsUInt16Number Out[], + CMSREGISTER void * Cargo) { Out[0] = Fn8D1(In[0], In[1], In[2], In[3], In[4], In[5], In[6], In[7], 8); @@ -3759,6 +3764,73 @@ Error: +// For educational purposes ONLY. No error checking is performed! +static +cmsInt32Number CreateNamedColorProfile(cmsContext ContextID) +{ + // Color list database + cmsNAMEDCOLORLIST* colors = cmsAllocNamedColorList(ContextID, 0, 10, 4, "PANTONE", "TCX"); + + // Containers for names + cmsMLU* DescriptionMLU, *CopyrightMLU; + + // Create n empty profile + cmsHPROFILE hProfile = cmsOpenProfileFromFile(ContextID, "named.icc", "w"); + + // Values + cmsCIELab Lab; + cmsUInt16Number PCS[3], Colorant[4]; + + // Set profile class + cmsSetProfileVersion(ContextID, hProfile, 4.3); + cmsSetDeviceClass(ContextID, hProfile, cmsSigNamedColorClass); + cmsSetColorSpace(ContextID, hProfile, cmsSigCmykData); + cmsSetPCS(ContextID, hProfile, cmsSigLabData); + cmsSetHeaderRenderingIntent(ContextID, hProfile, INTENT_PERCEPTUAL); + + // Add description and copyright only in english/US + DescriptionMLU = cmsMLUalloc(ContextID, 1); + CopyrightMLU = cmsMLUalloc(ContextID, 1); + + cmsMLUsetWide(ContextID, DescriptionMLU, "en", "US", L"Profile description"); + cmsMLUsetWide(ContextID, CopyrightMLU, "en", "US", L"Profile copyright"); + + cmsWriteTag(ContextID, hProfile, cmsSigProfileDescriptionTag, DescriptionMLU); + cmsWriteTag(ContextID, hProfile, cmsSigCopyrightTag, CopyrightMLU); + + // Set the media white point + cmsWriteTag(ContextID, hProfile, cmsSigMediaWhitePointTag, cmsD50_XYZ()); + + + // Populate one value, Colorant = CMYK values in 16 bits, PCS[] = Encoded Lab values (in V2 format!!) + Lab.L = 50; Lab.a = 10; Lab.b = -10; + cmsFloat2LabEncodedV2(ContextID, PCS, &Lab); + Colorant[0] = 10 * 257; Colorant[1] = 20 * 257; Colorant[2] = 30 * 257; Colorant[3] = 40 * 257; + cmsAppendNamedColor(ContextID, colors, "Hazelnut 14-1315", PCS, Colorant); + + // Another one. Consider to write a routine for that + Lab.L = 40; Lab.a = -5; Lab.b = 8; + cmsFloat2LabEncodedV2(ContextID, PCS, &Lab); + Colorant[0] = 10 * 257; Colorant[1] = 20 * 257; Colorant[2] = 30 * 257; Colorant[3] = 40 * 257; + cmsAppendNamedColor(ContextID, colors, "Kale 18-0107", PCS, Colorant); + + // Write the colors database + cmsWriteTag(ContextID, hProfile, cmsSigNamedColor2Tag, colors); + + // That will create the file + cmsCloseProfile(ContextID, hProfile); + + // Free resources + cmsFreeNamedColorList(ContextID, colors); + cmsMLUfree(ContextID, DescriptionMLU); + cmsMLUfree(ContextID, CopyrightMLU); + + remove("named.icc"); + + return 1; +} + + // ---------------------------------------------------------------------------------------------------------- // Formatters @@ -4880,7 +4952,7 @@ cmsBool CheckOneStr(cmsContext ContextID, cmsMLU* mlu, cmsInt32Number n) static -void SetOneStr(cmsContext ContextID, cmsMLU** mlu, wchar_t* s1, wchar_t* s2) +void SetOneStr(cmsContext ContextID, cmsMLU** mlu, const wchar_t* s1, const wchar_t* s2) { *mlu = cmsMLUalloc(ContextID, 0); cmsMLUsetWide(ContextID, *mlu, "en", "US", s1); @@ -8145,6 +8217,49 @@ int CheckProofingIntersection(cmsContext ContextID) return 1; } +/** +* In 2.11: When I create a RGB profile, set the copyright data with an empty string, +* then call cmsMD5computeID on said profile, the program crashes. +*/ +static +int CheckEmptyMLUC(cmsContext context) +{ + cmsCIExyY white = { 0.31271, 0.32902, 1.0 }; + cmsCIExyYTRIPLE primaries = + { + .Red = { 0.640, 0.330, 1.0 }, + .Green = { 0.300, 0.600, 1.0 }, + .Blue = { 0.150, 0.060, 1.0 } + }; + + cmsFloat64Number parameters[10] = { 2.6, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + cmsToneCurve* toneCurve = cmsBuildParametricToneCurve(context, 1, parameters); + cmsToneCurve* toneCurves[3] = { toneCurve, toneCurve, toneCurve }; + + cmsHPROFILE profile = cmsCreateRGBProfileTHR(context, &white, &primaries, toneCurves); + + cmsSetLogErrorHandlerTHR(context, FatalErrorQuit); + + cmsFreeToneCurve(toneCurve); + + // Set an empty copyright tag. This should log an error. + cmsMLU* mlu = cmsMLUalloc(context, 1); + + cmsMLUsetASCII(mlu, "en", "AU", ""); + cmsMLUsetWide(mlu, "en", "EN", L""); + cmsWriteTag(profile, cmsSigCopyrightTag, mlu); + cmsMLUfree(mlu); + + // This will cause a crash after setting an empty copyright tag. + cmsMD5computeID(profile); + + // Cleanup + cmsCloseProfile(profile); + DebugMemDontCheckThis(context); + + return 1; +} + // -------------------------------------------------------------------------------------------------- // P E R F O R M A N C E C H E C K S // -------------------------------------------------------------------------------------------------- @@ -8836,10 +8951,6 @@ void PrintSupportedIntents(void) // --------------------------------------------------------------------------------------- -#ifdef LCMS_FAST_EXTENSIONS - void* cmsFast8Bitextensions(void); -#endif - int main(int argc, char* argv[]) { cmsInt32Number Exhaustive = 0; @@ -8868,8 +8979,10 @@ int main(int argc, char* argv[]) } #ifdef LCMS_FAST_EXTENSIONS - printf("Installing fast 8 bit extension ..."); - cmsPlugin(cmsFast8Bitextensions()); + //printf("Installing fast 8 bit extension ..."); + //cmsPlugin(cmsFast8Bitextensions()); + printf("Installing fast float extension ..."); + cmsPlugin(cmsFastFloatExtensions()); printf("done.\n"); #endif @@ -9013,6 +9126,8 @@ int main(int argc, char* argv[]) // Named color Check(ctx, "Named color lists", CheckNamedColorList); + Check(ctx, "Create named color profile", CreateNamedColorProfile); + // Profile I/O (this one is huge!) Check(ctx, "Profile creation", CheckProfileCreation); @@ -9083,6 +9198,7 @@ int main(int argc, char* argv[]) Check(ctx, "Transform line stride RGB", CheckTransformLineStride); Check(ctx, "Forged MPE profile", CheckForgedMPE); Check(ctx, "Proofing intersection", CheckProofingIntersection); + Check(ctx, "Empty MLUC", CheckEmptyMLUC); } if (DoPluginTests) |