// 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 if (cmsGetDeviceClass(hProfile) == cmsSigLinkClass) { return (cmsGetHeaderRenderingIntent(hProfile) == Intent); } switch (UsedDirection) { case LCMS_USED_AS_INPUT: TagTable = Device2PCS16; 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: return cmsIsIntentSupported(hProfile, Intent, LCMS_USED_AS_INPUT) && cmsIsIntentSupported(hProfile, INTENT_RELATIVE_COLORIMETRIC, LCMS_USED_AS_OUTPUT); default: cmsSignalError(cmsGetProfileContextID(hProfile), cmsERROR_RANGE, "Unexpected direction (%d)", UsedDirection); return FALSE; } return cmsIsTag(hProfile, TagTable[Intent]); }
static int BlackPointUsingPerceptualBlack(LPcmsCIEXYZ BlackPoint, cmsHPROFILE hProfile, DWORD dwFlags) { cmsHTRANSFORM hPercLab2CMYK, hRelColCMYK2Lab; cmsHPROFILE hLab; cmsCIELab LabIn, LabOut; WORD CMYK[MAXCHANNELS]; cmsCIEXYZ BlackXYZ, MediaWhite; if (!cmsIsIntentSupported(hProfile, INTENT_PERCEPTUAL, LCMS_USED_AS_INPUT)) { BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0; return 0; } hLab = cmsCreateLabProfile(NULL); hPercLab2CMYK = cmsCreateTransform(hLab, TYPE_Lab_DBL, hProfile, TYPE_CMYK_16, INTENT_PERCEPTUAL, cmsFLAGS_NOTPRECALC); hRelColCMYK2Lab = cmsCreateTransform(hProfile, TYPE_CMYK_16, hLab, TYPE_Lab_DBL, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_NOTPRECALC); LabIn.L = LabIn.a = LabIn.b = 0; cmsDoTransform(hPercLab2CMYK, &LabIn, CMYK, 1); cmsDoTransform(hRelColCMYK2Lab, CMYK, &LabOut, 1); if (LabOut.L > 50) LabOut.L = 50; LabOut.a = LabOut.b = 0; cmsDeleteTransform(hPercLab2CMYK); cmsDeleteTransform(hRelColCMYK2Lab); cmsCloseProfile(hLab); cmsLab2XYZ(NULL, &BlackXYZ, &LabOut); if (!(dwFlags & LCMS_BPFLAGS_D50_ADAPTED)){ cmsTakeMediaWhitePoint(&MediaWhite, hProfile); cmsAdaptToIlluminant(BlackPoint, cmsD50_XYZ(), &MediaWhite, &BlackXYZ); } else *BlackPoint = BlackXYZ; return 1; }
static PyObject * cms_profile_is_intent_supported(CmsProfileObject *self, PyObject *args) { LCMSBOOL result; int intent; int direction; if (!PyArg_ParseTuple(args, "ii:is_intent_supported", &intent, &direction)) return NULL; result = cmsIsIntentSupported(self->profile, intent, direction); /* printf("cmsIsIntentSupported(%p, %d, %d) => %d\n", self->profile, intent, direction, result); */ return PyInt_FromLong(result != 0); }
// Get a black point of output CMYK profile, discounting any ink-limiting embedded // in the profile. For doing that, we use perceptual intent in input direction: // Lab (0, 0, 0) -> [Perceptual] Profile -> CMYK -> [Rel. colorimetric] Profile -> Lab static cmsBool BlackPointUsingPerceptualBlack(cmsCIEXYZ* BlackPoint, cmsHPROFILE hProfile) { cmsHTRANSFORM hRoundTrip; cmsCIELab LabIn, LabOut; cmsCIEXYZ BlackXYZ; // Is the intent supported by the profile? if (!cmsIsIntentSupported(hProfile, INTENT_PERCEPTUAL, LCMS_USED_AS_INPUT)) { BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0; return TRUE; } hRoundTrip = CreateRoundtripXForm(hProfile, INTENT_PERCEPTUAL); if (hRoundTrip == NULL) { BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0; return FALSE; } LabIn.L = LabIn.a = LabIn.b = 0; cmsDoTransform(hRoundTrip, &LabIn, &LabOut, 1); // Clip Lab to reasonable limits if (LabOut.L > 50) LabOut.L = 50; LabOut.a = LabOut.b = 0; cmsDeleteTransform(hRoundTrip); // Convert it to XYZ cmsLab2XYZ(NULL, &BlackXYZ, &LabOut); if (BlackPoint != NULL) *BlackPoint = BlackXYZ; return TRUE; }
static int BlackPointAsDarkerColorant(cmsHPROFILE hInput, int Intent, LPcmsCIEXYZ BlackPoint, DWORD dwFlags) { WORD *Black, *White; cmsHTRANSFORM xform; icColorSpaceSignature Space; int nChannels; DWORD dwFormat; cmsHPROFILE hLab; cmsCIELab Lab; cmsCIEXYZ BlackXYZ, MediaWhite; // If the profile does not support input direction, assume Black point 0 if (!cmsIsIntentSupported(hInput, Intent, LCMS_USED_AS_INPUT)) { BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0; return 0; } // Try to get black by using black colorant Space = cmsGetColorSpace(hInput); if (!_cmsEndPointsBySpace(Space, &White, &Black, &nChannels)) { BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0; return 0; } dwFormat = CHANNELS_SH(nChannels)|BYTES_SH(2); hLab = cmsCreateLabProfile(NULL); xform = cmsCreateTransform(hInput, dwFormat, hLab, TYPE_Lab_DBL, Intent, cmsFLAGS_NOTPRECALC); cmsDoTransform(xform, Black, &Lab, 1); // Force it to be neutral, clip to max. L* of 50 Lab.a = Lab.b = 0; if (Lab.L > 50) Lab.L = 50; cmsCloseProfile(hLab); cmsDeleteTransform(xform); cmsLab2XYZ(NULL, &BlackXYZ, &Lab); if (Intent == INTENT_ABSOLUTE_COLORIMETRIC) { *BlackPoint = BlackXYZ; } else { if (!(dwFlags & LCMS_BPFLAGS_D50_ADAPTED)) { cmsTakeMediaWhitePoint(&MediaWhite, hInput); cmsAdaptToIlluminant(BlackPoint, cmsD50_XYZ(), &MediaWhite, &BlackXYZ); } else *BlackPoint = BlackXYZ; } return 1; }
// Use darker colorants to obtain black point. This works in the relative colorimetric intent and // assumes more ink results in darker colors. No ink limit is assumed. static cmsBool BlackPointAsDarkerColorant(cmsHPROFILE hInput, cmsUInt32Number Intent, cmsCIEXYZ* BlackPoint, cmsUInt32Number dwFlags) { cmsUInt16Number *Black; cmsHTRANSFORM xform; cmsColorSpaceSignature Space; cmsUInt32Number nChannels; cmsUInt32Number dwFormat; cmsHPROFILE hLab; cmsCIELab Lab; cmsCIEXYZ BlackXYZ; cmsContext ContextID = cmsGetProfileContextID(hInput); // If the profile does not support input direction, assume Black point 0 if (!cmsIsIntentSupported(hInput, Intent, LCMS_USED_AS_INPUT)) { BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0; return FALSE; } // Create a formatter which has n channels and floating point dwFormat = cmsFormatterForColorspaceOfProfile(hInput, 2); // Try to get black by using black colorant Space = cmsGetColorSpace(hInput); // This function returns darker colorant in 16 bits for several spaces if (!_cmsEndPointsBySpace(Space, NULL, &Black, &nChannels)) { BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0; return FALSE; } if (nChannels != T_CHANNELS(dwFormat)) { BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0; return FALSE; } // Lab will be used as the output space, but lab2 will avoid recursion hLab = cmsCreateLab2ProfileTHR(ContextID, NULL); if (hLab == NULL) { BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0; return FALSE; } // Create the transform xform = cmsCreateTransformTHR(ContextID, hInput, dwFormat, hLab, TYPE_Lab_DBL, Intent, cmsFLAGS_NOOPTIMIZE|cmsFLAGS_NOCACHE); cmsCloseProfile(hLab); if (xform == NULL) { // Something went wrong. Get rid of open resources and return zero as black BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0; return FALSE; } // Convert black to Lab cmsDoTransform(xform, Black, &Lab, 1); // Force it to be neutral, clip to max. L* of 50 Lab.a = Lab.b = 0; if (Lab.L > 50) Lab.L = 50; // Free the resources cmsDeleteTransform(xform); // Convert from Lab (which is now clipped) to XYZ. cmsLab2XYZ(NULL, &BlackXYZ, &Lab); if (BlackPoint != NULL) *BlackPoint = BlackXYZ; return TRUE; cmsUNUSED_PARAMETER(dwFlags); }
static LPLUT ComputeGamutWithInput(cmsHPROFILE hInput, cmsHPROFILE hProfile, int Intent) { cmsHPROFILE hLab; LPLUT Gamut; DWORD dwFormat; GAMUTCHAIN Chain; int nErrState, nChannels, nGridpoints; LPGAMMATABLE Trans[3]; icColorSpaceSignature ColorSpace; ZeroMemory(&Chain, sizeof(GAMUTCHAIN)); hLab = cmsCreateLabProfile(NULL); // Safeguard against early abortion nErrState = cmsErrorAction(LCMS_ERROR_IGNORE); // The figure of merit. On matrix-shaper profiles, should be almost zero as // the conversion is pretty exact. On LUT based profiles, different resolutions // of input and output CLUT may result in differences. if (!cmsIsIntentSupported(hProfile, Intent, LCMS_USED_AS_INPUT) && !cmsIsIntentSupported(hProfile, Intent, LCMS_USED_AS_OUTPUT)) Chain.Thereshold = 1.0; else Chain.Thereshold = ERR_THERESHOLD; ColorSpace = cmsGetColorSpace(hProfile); // If input profile specified, create a transform from such profile to Lab if (hInput != NULL) { nChannels = _cmsChannelsOf(ColorSpace); nGridpoints = _cmsReasonableGridpointsByColorspace(ColorSpace, cmsFLAGS_HIGHRESPRECALC); dwFormat = (CHANNELS_SH(nChannels)|BYTES_SH(2)); Chain.hInput = cmsCreateTransform(hInput, dwFormat, hLab, TYPE_Lab_16, Intent, cmsFLAGS_NOTPRECALC); } else { // Input transform=NULL (Lab) Used to compute the gamut tag // This table will take 53 points to give some accurancy, // 53 * 53 * 53 * 2 = 291K nChannels = 3; // For Lab nGridpoints = 53; Chain.hInput = NULL; dwFormat = (CHANNELS_SH(_cmsChannelsOf(ColorSpace))|BYTES_SH(2)); } // Does create the forward step Chain.hForward = cmsCreateTransform(hLab, TYPE_Lab_16, hProfile, dwFormat, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_NOTPRECALC); // Does create the backwards step Chain.hReverse = cmsCreateTransform(hProfile, dwFormat, hLab, TYPE_Lab_16, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_NOTPRECALC); // Restores error handler previous state cmsErrorAction(nErrState); // All ok? if (Chain.hForward && Chain.hReverse) { // Go on, try to compute gamut LUT from PCS. // This consist on a single channel containing // dE when doing a transform back and forth on // the colorimetric intent. Gamut = cmsAllocLUT(); Gamut = cmsAlloc3DGrid(Gamut, nGridpoints, nChannels, 1); // If no input, then this is a gamut tag operated by Lab, // so include pertinent prelinearization if (hInput == NULL) { CreateLabPrelinearization(Trans); cmsAllocLinearTable(Gamut, Trans, 1); cmsFreeGammaTriple(Trans); } cmsSample3DGrid(Gamut, GamutSampler, (LPVOID) &Chain, Gamut ->wFlags); } else Gamut = NULL; // Didn't work... // Free all needed stuff. if (Chain.hInput) cmsDeleteTransform(Chain.hInput); if (Chain.hForward) cmsDeleteTransform(Chain.hForward); if (Chain.hReverse) cmsDeleteTransform(Chain.hReverse); cmsCloseProfile(hLab); // And return computed hull return Gamut; }