I'm trying to figure out how to apply a 3D color lookup table to a source image 
in 8-bit sRGB space to result in a new image also in 8-bit sRGB space.

After poking around the lcms2.2 codebase (and Google) for some examples to 
follow, here's what I have so far (error handling omitted for brevity):

cmsHPROFILE hProfile = cmsCreateProfilePlaceholder(0);

cmsSetProfileVersion(hProfile, 4.2);
cmsSetDeviceClass(hProfile, cmsSigAbstractClass);
cmsSetColorSpace(hProfile, cmsSigRgbData);
cmsSetPCS(hProfile, cmsSigRgbData);

cmsPipeline* pipe = cmsPipelineAlloc(NULL, 3, 3);
cmsStage* stage = cmsStageAllocCLut16bit(NULL, 33, 3, 3, NULL);
cmsStageSampleCLut16bit(stage, MyTable, 0, 0);

cmsPipelineInsertStage(pipe, cmsAT_END, stage);

/*
cmsPipelineInsertStage(pipe, cmsAT_BEGIN, identityCurves(NULL, 3));
cmsPipelineInsertStage(pipe, cmsAT_END, identityCurves(NULL, 3));
cmsSaveProfileToFile(hProfile, "my.icc");
*/

cmsWriteTag(hProfile, cmsSigAToB0Tag, pipe);

cmsHTRANSFORM hTransform = cmsCreateTransform(
  cmsCreate_sRGBProfile(), TYPE_RGB_8, hProfile, TYPE_RGB_8,
  INTENT_PERCEPTUAL, 0);

// *** cms error 9: ColorSpace mismatch
// *** cms error 13: Couldn't link the profiles

// ------------------------------------------------------------

cmsStage* identityCurves(cmsContext id, int nChannels)
  { return cmsStageAllocToneCurves(id, nChannels, NULL); }

cmsInt32Number
MyTable(const cmsUInt16Number in[], cmsUInt16Number out[], void*) {
    out[0] = in[0], out[1] = in[1], out[2] = in[2];
    return 1;
}

Sadly, when I actually try to run this code, I get a pair of errors from 
cmsCreateTransform:

cms error 9: ColorSpace mismatch
cms error 13: Couldn't link the profiles

Running in gdb, I see "ColorSpace mismatch" comes from 
"ColorSpaceIsCompatible(ColorSpaceIn, CurrentColorSpace)" where my ColorSpaceIn 
== cmsSigRgbData, and CurrentColorSpace == cmsSigXYZData. I believe I 
understand where cmsSigRgbData is coming from (my Profile object, presumably), 
but I don't understand where the cmsSigXYZData value is coming from. Perhaps 
that's the crux of my problem?

I'd also like to save the profile to an ICC file. In order to do that, I 
uncomment the call cmsSaveProfileToFile. For that to work, however, I need the 
identityCurves before and after the CLUT, otherwise it gives me:

cms error 13: LUT is not suitable to be saved as LutAToB
cms error 7: Couldn't write type 'mAB '

With the identity curves in place, it saves a file, but the file doesn't appear 
to be useable as an ICC profile from, say, Photoshop. Saving the ICC file isn't 
crucial for my current needs, but generating a transform is.

I'm sure I'm doing something stupid and obviously wrong, but I'm not at all 
sure what. Can anyone help?

Thanks!
Tim.
------------------------------------------------------------------------------
EMC VNX: the world's simplest storage, starting under $10K
The only unified storage solution that offers unified management 
Up to 160% more powerful than alternatives and 25% more efficient. 
Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev
_______________________________________________
Lcms-user mailing list
Lcms-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lcms-user

Reply via email to