This source file includes following definitions.
- _cmsReadMediaWhitePoint
- _cmsReadCHAD
- ReadICCMatrixRGB2XYZ
- BuildGrayInputMatrixPipeline
- BuildRGBInputMatrixShaper
- _cmsReadFloatInputTag
- _cmsReadInputLUT
- BuildGrayOutputPipeline
- BuildRGBOutputMatrixShaper
- ChangeInterpolationToTrilinear
- _cmsReadFloatOutputTag
- _cmsReadOutputLUT
- _cmsReadFloatDevicelinkTag
- _cmsReadDevicelinkLUT
- cmsIsMatrixShaper
- cmsIsCLUT
- cmsIsIntentSupported
- _cmsReadProfileSequence
- _cmsWriteProfileSequence
- GetMLUFromProfile
- _cmsCompileProfileSequence
- GetInfo
- cmsGetProfileInfo
- cmsGetProfileInfoASCII
#include "lcms2_internal.h"
static const cmsTagSignature Device2PCS16[] = {cmsSigAToB0Tag,
cmsSigAToB1Tag,
cmsSigAToB2Tag,
cmsSigAToB1Tag };
static const cmsTagSignature Device2PCSFloat[] = {cmsSigDToB0Tag,
cmsSigDToB1Tag,
cmsSigDToB2Tag,
cmsSigDToB3Tag };
static const cmsTagSignature PCS2Device16[] = {cmsSigBToA0Tag,
cmsSigBToA1Tag,
cmsSigBToA2Tag,
cmsSigBToA1Tag };
static const cmsTagSignature PCS2DeviceFloat[] = {cmsSigBToD0Tag,
cmsSigBToD1Tag,
cmsSigBToD2Tag,
cmsSigBToD3Tag };
#define InpAdj (1.0/MAX_ENCODEABLE_XYZ)
#define OutpAdj (MAX_ENCODEABLE_XYZ)
static const cmsFloat64Number GrayInputMatrix[] = { (InpAdj*cmsD50X), (InpAdj*cmsD50Y), (InpAdj*cmsD50Z) };
static const cmsFloat64Number OneToThreeInputMatrix[] = { 1, 1, 1 };
static const cmsFloat64Number PickYMatrix[] = { 0, (OutpAdj*cmsD50Y), 0 };
static const cmsFloat64Number PickLstarMatrix[] = { 1, 0, 0 };
cmsBool _cmsReadMediaWhitePoint(cmsCIEXYZ* Dest, cmsHPROFILE hProfile)
{
cmsCIEXYZ* Tag;
_cmsAssert(Dest != NULL);
Tag = (cmsCIEXYZ*) cmsReadTag(hProfile, cmsSigMediaWhitePointTag);
if (Tag == NULL) {
*Dest = *cmsD50_XYZ();
return TRUE;
}
if (cmsGetEncodedICCversion(hProfile) < 0x4000000) {
if (cmsGetDeviceClass(hProfile) == cmsSigDisplayClass) {
*Dest = *cmsD50_XYZ();
return TRUE;
}
}
*Dest = *Tag;
return TRUE;
}
cmsBool _cmsReadCHAD(cmsMAT3* Dest, cmsHPROFILE hProfile)
{
cmsMAT3* Tag;
_cmsAssert(Dest != NULL);
Tag = (cmsMAT3*) cmsReadTag(hProfile, cmsSigChromaticAdaptationTag);
if (Tag != NULL) {
*Dest = *Tag;
return TRUE;
}
_cmsMAT3identity(Dest);
if (cmsGetEncodedICCversion(hProfile) < 0x4000000) {
if (cmsGetDeviceClass(hProfile) == cmsSigDisplayClass) {
cmsCIEXYZ* White = (cmsCIEXYZ*) cmsReadTag(hProfile, cmsSigMediaWhitePointTag);
if (White == NULL) {
_cmsMAT3identity(Dest);
return TRUE;
}
return _cmsAdaptationMatrix(Dest, NULL, White, cmsD50_XYZ());
}
}
return TRUE;
}
static
cmsBool ReadICCMatrixRGB2XYZ(cmsMAT3* r, cmsHPROFILE hProfile)
{
cmsCIEXYZ *PtrRed, *PtrGreen, *PtrBlue;
_cmsAssert(r != NULL);
PtrRed = (cmsCIEXYZ *) cmsReadTag(hProfile, cmsSigRedColorantTag);
PtrGreen = (cmsCIEXYZ *) cmsReadTag(hProfile, cmsSigGreenColorantTag);
PtrBlue = (cmsCIEXYZ *) cmsReadTag(hProfile, cmsSigBlueColorantTag);
if (PtrRed == NULL || PtrGreen == NULL || PtrBlue == NULL)
return FALSE;
_cmsVEC3init(&r -> v[0], PtrRed -> X, PtrGreen -> X, PtrBlue -> X);
_cmsVEC3init(&r -> v[1], PtrRed -> Y, PtrGreen -> Y, PtrBlue -> Y);
_cmsVEC3init(&r -> v[2], PtrRed -> Z, PtrGreen -> Z, PtrBlue -> Z);
return TRUE;
}
static
cmsPipeline* BuildGrayInputMatrixPipeline(cmsHPROFILE hProfile)
{
cmsToneCurve *GrayTRC;
cmsPipeline* Lut;
cmsContext ContextID = cmsGetProfileContextID(hProfile);
GrayTRC = (cmsToneCurve *) cmsReadTag(hProfile, cmsSigGrayTRCTag);
if (GrayTRC == NULL) return NULL;
Lut = cmsPipelineAlloc(ContextID, 1, 3);
if (Lut == NULL)
goto Error;
if (cmsGetPCS(hProfile) == cmsSigLabData) {
cmsUInt16Number Zero[2] = { 0x8080, 0x8080 };
cmsToneCurve* EmptyTab;
cmsToneCurve* LabCurves[3];
EmptyTab = cmsBuildTabulatedToneCurve16(ContextID, 2, Zero);
if (EmptyTab == NULL)
goto Error;
LabCurves[0] = GrayTRC;
LabCurves[1] = EmptyTab;
LabCurves[2] = EmptyTab;
if (!cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3, 1, OneToThreeInputMatrix, NULL)) ||
!cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 3, LabCurves))) {
cmsFreeToneCurve(EmptyTab);
goto Error;
}
cmsFreeToneCurve(EmptyTab);
}
else {
if (!cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 1, &GrayTRC)) ||
!cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3, 1, GrayInputMatrix, NULL)))
goto Error;
}
return Lut;
Error:
cmsFreeToneCurve(GrayTRC);
cmsPipelineFree(Lut);
return NULL;
}
static
cmsPipeline* BuildRGBInputMatrixShaper(cmsHPROFILE hProfile)
{
cmsPipeline* Lut;
cmsMAT3 Mat;
cmsToneCurve *Shapes[3];
cmsContext ContextID = cmsGetProfileContextID(hProfile);
int i, j;
if (!ReadICCMatrixRGB2XYZ(&Mat, hProfile)) return NULL;
for (i=0; i < 3; i++)
for (j=0; j < 3; j++)
Mat.v[i].n[j] *= InpAdj;
Shapes[0] = (cmsToneCurve *) cmsReadTag(hProfile, cmsSigRedTRCTag);
Shapes[1] = (cmsToneCurve *) cmsReadTag(hProfile, cmsSigGreenTRCTag);
Shapes[2] = (cmsToneCurve *) cmsReadTag(hProfile, cmsSigBlueTRCTag);
if (!Shapes[0] || !Shapes[1] || !Shapes[2])
return NULL;
Lut = cmsPipelineAlloc(ContextID, 3, 3);
if (Lut != NULL) {
if (!cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 3, Shapes)) ||
!cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3, 3, (cmsFloat64Number*) &Mat, NULL)))
goto Error;
if (cmsGetPCS(hProfile) == cmsSigLabData) {
if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocXYZ2Lab(ContextID)))
goto Error;
}
}
return Lut;
Error:
cmsPipelineFree(Lut);
return NULL;
}
static
cmsPipeline* _cmsReadFloatInputTag(cmsHPROFILE hProfile, cmsTagSignature tagFloat)
{
cmsContext ContextID = cmsGetProfileContextID(hProfile);
cmsPipeline* Lut = cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat));
cmsColorSpaceSignature spc = cmsGetColorSpace(hProfile);
cmsColorSpaceSignature PCS = cmsGetPCS(hProfile);
if (Lut == NULL) return NULL;
if ( spc == cmsSigLabData)
{
if (!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToLabFloat(ContextID)))
goto Error;
}
else if (spc == cmsSigXYZData)
{
if (!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToXyzFloat(ContextID)))
goto Error;
}
if ( PCS == cmsSigLabData)
{
if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromLabFloat(ContextID)))
goto Error;
}
else if( PCS == cmsSigXYZData)
{
if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID)))
goto Error;
}
return Lut;
Error:
cmsPipelineFree(Lut);
return NULL;
}
cmsPipeline* _cmsReadInputLUT(cmsHPROFILE hProfile, int Intent)
{
cmsTagTypeSignature OriginalType;
cmsTagSignature tag16;
cmsTagSignature tagFloat;
cmsContext ContextID = cmsGetProfileContextID(hProfile);
if (cmsGetDeviceClass(hProfile) == cmsSigNamedColorClass) {
cmsPipeline* Lut;
cmsNAMEDCOLORLIST* nc = (cmsNAMEDCOLORLIST*) cmsReadTag(hProfile, cmsSigNamedColor2Tag);
if (nc == NULL) return NULL;
Lut = cmsPipelineAlloc(ContextID, 0, 0);
if (Lut == NULL) {
cmsFreeNamedColorList(nc);
return NULL;
}
if (!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocNamedColor(nc, TRUE)) ||
!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID))) {
cmsPipelineFree(Lut);
return NULL;
}
return Lut;
}
if (Intent != -1) {
tag16 = Device2PCS16[Intent];
tagFloat = Device2PCSFloat[Intent];
if (cmsIsTag(hProfile, tagFloat)) {
return _cmsReadFloatInputTag(hProfile, tagFloat);
}
if (!cmsIsTag(hProfile, tag16)) {
tag16 = Device2PCS16[0];
}
if (cmsIsTag(hProfile, tag16)) {
cmsPipeline* Lut = (cmsPipeline*) cmsReadTag(hProfile, tag16);
if (Lut == NULL) return NULL;
OriginalType = _cmsGetTagTrueType(hProfile, tag16);
Lut = cmsPipelineDup(Lut);
if (OriginalType != cmsSigLut16Type || cmsGetPCS(hProfile) != cmsSigLabData)
return Lut;
if (cmsGetColorSpace(hProfile) == cmsSigLabData &&
!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocLabV4ToV2(ContextID)))
goto Error;
if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID)))
goto Error;
return Lut;
Error:
cmsPipelineFree(Lut);
return NULL;
}
}
if (cmsGetColorSpace(hProfile) == cmsSigGrayData) {
return BuildGrayInputMatrixPipeline(hProfile);
}
return BuildRGBInputMatrixShaper(hProfile);
}
static
cmsPipeline* BuildGrayOutputPipeline(cmsHPROFILE hProfile)
{
cmsToneCurve *GrayTRC, *RevGrayTRC;
cmsPipeline* Lut;
cmsContext ContextID = cmsGetProfileContextID(hProfile);
GrayTRC = (cmsToneCurve *) cmsReadTag(hProfile, cmsSigGrayTRCTag);
if (GrayTRC == NULL) return NULL;
RevGrayTRC = cmsReverseToneCurve(GrayTRC);
if (RevGrayTRC == NULL) return NULL;
Lut = cmsPipelineAlloc(ContextID, 3, 1);
if (Lut == NULL) {
cmsFreeToneCurve(RevGrayTRC);
return NULL;
}
if (cmsGetPCS(hProfile) == cmsSigLabData) {
if (!cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 1, 3, PickLstarMatrix, NULL)))
goto Error;
}
else {
if (!cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 1, 3, PickYMatrix, NULL)))
goto Error;
}
if (!cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 1, &RevGrayTRC)))
goto Error;
cmsFreeToneCurve(RevGrayTRC);
return Lut;
Error:
cmsFreeToneCurve(RevGrayTRC);
cmsPipelineFree(Lut);
return NULL;
}
static
cmsPipeline* BuildRGBOutputMatrixShaper(cmsHPROFILE hProfile)
{
cmsPipeline* Lut;
cmsToneCurve *Shapes[3], *InvShapes[3];
cmsMAT3 Mat, Inv;
int i, j;
cmsContext ContextID = cmsGetProfileContextID(hProfile);
if (!ReadICCMatrixRGB2XYZ(&Mat, hProfile))
return NULL;
if (!_cmsMAT3inverse(&Mat, &Inv))
return NULL;
for (i=0; i < 3; i++)
for (j=0; j < 3; j++)
Inv.v[i].n[j] *= OutpAdj;
Shapes[0] = (cmsToneCurve *) cmsReadTag(hProfile, cmsSigRedTRCTag);
Shapes[1] = (cmsToneCurve *) cmsReadTag(hProfile, cmsSigGreenTRCTag);
Shapes[2] = (cmsToneCurve *) cmsReadTag(hProfile, cmsSigBlueTRCTag);
if (!Shapes[0] || !Shapes[1] || !Shapes[2])
return NULL;
InvShapes[0] = cmsReverseToneCurve(Shapes[0]);
InvShapes[1] = cmsReverseToneCurve(Shapes[1]);
InvShapes[2] = cmsReverseToneCurve(Shapes[2]);
if (!InvShapes[0] || !InvShapes[1] || !InvShapes[2]) {
return NULL;
}
Lut = cmsPipelineAlloc(ContextID, 3, 3);
if (Lut != NULL) {
if (cmsGetPCS(hProfile) == cmsSigLabData) {
if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLab2XYZ(ContextID)))
goto Error;
}
if (!cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3, 3, (cmsFloat64Number*) &Inv, NULL)) ||
!cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 3, InvShapes)))
goto Error;
}
cmsFreeToneCurveTriple(InvShapes);
return Lut;
Error:
cmsFreeToneCurveTriple(InvShapes);
cmsPipelineFree(Lut);
return NULL;
}
static
void ChangeInterpolationToTrilinear(cmsPipeline* Lut)
{
cmsStage* Stage;
for (Stage = cmsPipelineGetPtrToFirstStage(Lut);
Stage != NULL;
Stage = cmsStageNext(Stage)) {
if (cmsStageType(Stage) == cmsSigCLutElemType) {
_cmsStageCLutData* CLUT = (_cmsStageCLutData*) Stage ->Data;
CLUT ->Params->dwFlags |= CMS_LERP_FLAGS_TRILINEAR;
_cmsSetInterpolationRoutine(Lut->ContextID, CLUT ->Params);
}
}
}
static
cmsPipeline* _cmsReadFloatOutputTag(cmsHPROFILE hProfile, cmsTagSignature tagFloat)
{
cmsContext ContextID = cmsGetProfileContextID(hProfile);
cmsPipeline* Lut = cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat));
cmsColorSpaceSignature PCS = cmsGetPCS(hProfile);
cmsColorSpaceSignature dataSpace = cmsGetColorSpace(hProfile);
if (Lut == NULL) return NULL;
if ( PCS == cmsSigLabData)
{
if (!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToLabFloat(ContextID)))
goto Error;
}
else
if (PCS == cmsSigXYZData)
{
if (!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToXyzFloat(ContextID)))
goto Error;
}
if ( dataSpace == cmsSigLabData)
{
if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromLabFloat(ContextID)))
goto Error;
}
else if (dataSpace == cmsSigXYZData)
{
if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID)))
goto Error;
}
return Lut;
Error:
cmsPipelineFree(Lut);
return NULL;
}
cmsPipeline* _cmsReadOutputLUT(cmsHPROFILE hProfile, int Intent)
{
cmsTagTypeSignature OriginalType;
cmsTagSignature tag16;
cmsTagSignature tagFloat;
cmsContext ContextID = cmsGetProfileContextID(hProfile);
if (Intent != -1) {
tag16 = PCS2Device16[Intent];
tagFloat = PCS2DeviceFloat[Intent];
if (cmsIsTag(hProfile, tagFloat)) {
return _cmsReadFloatOutputTag(hProfile, tagFloat);
}
if (!cmsIsTag(hProfile, tag16)) {
tag16 = PCS2Device16[0];
}
if (cmsIsTag(hProfile, tag16)) {
cmsPipeline* Lut = (cmsPipeline*) cmsReadTag(hProfile, tag16);
if (Lut == NULL) return NULL;
OriginalType = _cmsGetTagTrueType(hProfile, tag16);
Lut = cmsPipelineDup(Lut);
if (Lut == NULL) return NULL;
if (cmsGetPCS(hProfile) == cmsSigLabData)
ChangeInterpolationToTrilinear(Lut);
if (OriginalType != cmsSigLut16Type || cmsGetPCS(hProfile) != cmsSigLabData)
return Lut;
if (!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocLabV4ToV2(ContextID)))
goto Error;
if (cmsGetColorSpace(hProfile) == cmsSigLabData)
if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID)))
goto Error;
return Lut;
Error:
cmsPipelineFree(Lut);
return NULL;
}
}
if (cmsGetColorSpace(hProfile) == cmsSigGrayData) {
return BuildGrayOutputPipeline(hProfile);
}
return BuildRGBOutputMatrixShaper(hProfile);
}
static
cmsPipeline* _cmsReadFloatDevicelinkTag(cmsHPROFILE hProfile, cmsTagSignature tagFloat)
{
cmsContext ContextID = cmsGetProfileContextID(hProfile);
cmsPipeline* Lut = cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat));
cmsColorSpaceSignature PCS = cmsGetPCS(hProfile);
cmsColorSpaceSignature spc = cmsGetColorSpace(hProfile);
if (Lut == NULL) return NULL;
if (spc == cmsSigLabData)
{
if (!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToLabFloat(ContextID)))
goto Error;
}
else
if (spc == cmsSigXYZData)
{
if (!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToXyzFloat(ContextID)))
goto Error;
}
if (PCS == cmsSigLabData)
{
if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromLabFloat(ContextID)))
goto Error;
}
else
if (PCS == cmsSigXYZData)
{
if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID)))
goto Error;
}
return Lut;
Error:
cmsPipelineFree(Lut);
return NULL;
}
cmsPipeline* _cmsReadDevicelinkLUT(cmsHPROFILE hProfile, int Intent)
{
cmsPipeline* Lut;
cmsTagTypeSignature OriginalType;
cmsTagSignature tag16 = Device2PCS16[Intent];
cmsTagSignature tagFloat = Device2PCSFloat[Intent];
cmsContext ContextID = cmsGetProfileContextID(hProfile);
if (cmsGetDeviceClass(hProfile) == cmsSigNamedColorClass) {
cmsNAMEDCOLORLIST* nc = (cmsNAMEDCOLORLIST*) cmsReadTag(hProfile, cmsSigNamedColor2Tag);
if (nc == NULL) return NULL;
Lut = cmsPipelineAlloc(ContextID, 0, 0);
if (Lut == NULL)
goto Error;
if (!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocNamedColor(nc, FALSE)))
goto Error;
if (cmsGetColorSpace(hProfile) == cmsSigLabData)
if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID)))
goto Error;
return Lut;
Error:
cmsPipelineFree(Lut);
cmsFreeNamedColorList(nc);
return NULL;
}
if (cmsIsTag(hProfile, tagFloat)) {
return _cmsReadFloatDevicelinkTag(hProfile, tagFloat);
}
tagFloat = Device2PCSFloat[0];
if (cmsIsTag(hProfile, tagFloat)) {
return cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat));
}
if (!cmsIsTag(hProfile, tag16)) {
tag16 = Device2PCS16[0];
if (!cmsIsTag(hProfile, tag16)) return NULL;
}
Lut = (cmsPipeline*) cmsReadTag(hProfile, tag16);
if (Lut == NULL) return NULL;
Lut = cmsPipelineDup(Lut);
if (Lut == NULL) return NULL;
if (cmsGetPCS(hProfile) == cmsSigLabData)
ChangeInterpolationToTrilinear(Lut);
OriginalType = _cmsGetTagTrueType(hProfile, tag16);
if (OriginalType != cmsSigLut16Type) return Lut;
if (cmsGetColorSpace(hProfile) == cmsSigLabData) {
if(!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocLabV4ToV2(ContextID)))
goto Error2;
}
if (cmsGetPCS(hProfile) == cmsSigLabData) {
if(!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID)))
goto Error2;
}
return Lut;
Error2:
cmsPipelineFree(Lut);
return NULL;
}
cmsBool CMSEXPORT cmsIsMatrixShaper(cmsHPROFILE hProfile)
{
switch (cmsGetColorSpace(hProfile)) {
case cmsSigGrayData:
return cmsIsTag(hProfile, cmsSigGrayTRCTag);
case cmsSigRgbData:
return (cmsIsTag(hProfile, cmsSigRedColorantTag) &&
cmsIsTag(hProfile, cmsSigGreenColorantTag) &&
cmsIsTag(hProfile, cmsSigBlueColorantTag) &&
cmsIsTag(hProfile, cmsSigRedTRCTag) &&
cmsIsTag(hProfile, cmsSigGreenTRCTag) &&
cmsIsTag(hProfile, cmsSigBlueTRCTag));
default:
return FALSE;
}
}
cmsBool CMSEXPORT cmsIsCLUT(cmsHPROFILE hProfile, cmsUInt32Number Intent, cmsUInt32Number UsedDirection)
{
const cmsTagSignature* TagTable;
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;
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]);
}
cmsBool CMSEXPORT cmsIsIntentSupported(cmsHPROFILE hProfile,
cmsUInt32Number Intent, cmsUInt32Number UsedDirection)
{
if (cmsIsCLUT(hProfile, Intent, UsedDirection)) return TRUE;
return cmsIsMatrixShaper(hProfile);
}
cmsSEQ* _cmsReadProfileSequence(cmsHPROFILE hProfile)
{
cmsSEQ* ProfileSeq;
cmsSEQ* ProfileId;
cmsSEQ* NewSeq;
cmsUInt32Number i;
ProfileSeq = (cmsSEQ*) cmsReadTag(hProfile, cmsSigProfileSequenceDescTag);
ProfileId = (cmsSEQ*) cmsReadTag(hProfile, cmsSigProfileSequenceIdTag);
if (ProfileSeq == NULL && ProfileId == NULL) return NULL;
if (ProfileSeq == NULL) return cmsDupProfileSequenceDescription(ProfileId);
if (ProfileId == NULL) return cmsDupProfileSequenceDescription(ProfileSeq);
if (ProfileSeq ->n != ProfileId ->n) return cmsDupProfileSequenceDescription(ProfileSeq);
NewSeq = cmsDupProfileSequenceDescription(ProfileSeq);
if (NewSeq != NULL) {
for (i=0; i < ProfileSeq ->n; i++) {
memmove(&NewSeq ->seq[i].ProfileID, &ProfileId ->seq[i].ProfileID, sizeof(cmsProfileID));
NewSeq ->seq[i].Description = cmsMLUdup(ProfileId ->seq[i].Description);
}
}
return NewSeq;
}
cmsBool _cmsWriteProfileSequence(cmsHPROFILE hProfile, const cmsSEQ* seq)
{
if (!cmsWriteTag(hProfile, cmsSigProfileSequenceDescTag, seq)) return FALSE;
if (cmsGetEncodedICCversion(hProfile) >= 0x4000000) {
if (!cmsWriteTag(hProfile, cmsSigProfileSequenceIdTag, seq)) return FALSE;
}
return TRUE;
}
static
cmsMLU* GetMLUFromProfile(cmsHPROFILE h, cmsTagSignature sig)
{
cmsMLU* mlu = (cmsMLU*) cmsReadTag(h, sig);
if (mlu == NULL) return NULL;
return cmsMLUdup(mlu);
}
cmsSEQ* _cmsCompileProfileSequence(cmsContext ContextID, cmsUInt32Number nProfiles, cmsHPROFILE hProfiles[])
{
cmsUInt32Number i;
cmsSEQ* seq = cmsAllocProfileSequenceDescription(ContextID, nProfiles);
if (seq == NULL) return NULL;
for (i=0; i < nProfiles; i++) {
cmsPSEQDESC* ps = &seq ->seq[i];
cmsHPROFILE h = hProfiles[i];
cmsTechnologySignature* techpt;
cmsGetHeaderAttributes(h, &ps ->attributes);
cmsGetHeaderProfileID(h, ps ->ProfileID.ID8);
ps ->deviceMfg = cmsGetHeaderManufacturer(h);
ps ->deviceModel = cmsGetHeaderModel(h);
techpt = (cmsTechnologySignature*) cmsReadTag(h, cmsSigTechnologyTag);
if (techpt == NULL)
ps ->technology = (cmsTechnologySignature) 0;
else
ps ->technology = *techpt;
ps ->Manufacturer = GetMLUFromProfile(h, cmsSigDeviceMfgDescTag);
ps ->Model = GetMLUFromProfile(h, cmsSigDeviceModelDescTag);
ps ->Description = GetMLUFromProfile(h, cmsSigProfileDescriptionTag);
}
return seq;
}
static
const cmsMLU* GetInfo(cmsHPROFILE hProfile, cmsInfoType Info)
{
cmsTagSignature sig;
switch (Info) {
case cmsInfoDescription:
sig = cmsSigProfileDescriptionTag;
break;
case cmsInfoManufacturer:
sig = cmsSigDeviceMfgDescTag;
break;
case cmsInfoModel:
sig = cmsSigDeviceModelDescTag;
break;
case cmsInfoCopyright:
sig = cmsSigCopyrightTag;
break;
default: return NULL;
}
return (cmsMLU*) cmsReadTag(hProfile, sig);
}
cmsUInt32Number CMSEXPORT cmsGetProfileInfo(cmsHPROFILE hProfile, cmsInfoType Info,
const char LanguageCode[3], const char CountryCode[3],
wchar_t* Buffer, cmsUInt32Number BufferSize)
{
const cmsMLU* mlu = GetInfo(hProfile, Info);
if (mlu == NULL) return 0;
return cmsMLUgetWide(mlu, LanguageCode, CountryCode, Buffer, BufferSize);
}
cmsUInt32Number CMSEXPORT cmsGetProfileInfoASCII(cmsHPROFILE hProfile, cmsInfoType Info,
const char LanguageCode[3], const char CountryCode[3],
char* Buffer, cmsUInt32Number BufferSize)
{
const cmsMLU* mlu = GetInfo(hProfile, Info);
if (mlu == NULL) return 0;
return cmsMLUgetASCII(mlu, LanguageCode, CountryCode, Buffer, BufferSize);
}