This source file includes following definitions.
- Forward
- Reverse
- InitCargo
- FreeCargo
- main
#include "lcms.h"
typedef struct {
cmsHPROFILE hLab;
cmsHPROFILE hRGB;
cmsHTRANSFORM Lab2RGB;
cmsHTRANSFORM RGB2Lab;
} CARGO, FAR* LPCARGO;
static
int Forward(register WORD In[], register WORD Out[], register LPVOID Cargo)
{
LPCARGO C = (LPCARGO) Cargo;
WORD RGB[3];
cmsCIELab Lab;
cmsLabEncoded2Float(&Lab, In);
printf("%g %g %g\n", Lab.L, Lab.a, Lab.b);
cmsDoTransform(C ->Lab2RGB, In, &RGB, 1);
Out[0] = 0xFFFF - RGB[0];
Out[1] = 0xFFFF - RGB[1];
Out[2] = 0xFFFF - RGB[2];
return TRUE;
}
static
int Reverse(register WORD In[], register WORD Out[], register LPVOID Cargo)
{
LPCARGO C = (LPCARGO) Cargo;
WORD RGB[3];
RGB[0] = 0xFFFF - In[0];
RGB[1] = 0xFFFF - In[1];
RGB[2] = 0xFFFF - In[2];
cmsDoTransform(C ->RGB2Lab, &RGB, Out, 1);
return TRUE;
}
static
void InitCargo(LPCARGO Cargo)
{
Cargo -> hLab = cmsCreateLabProfile(NULL);
Cargo -> hRGB = cmsCreate_sRGBProfile();
Cargo->Lab2RGB = cmsCreateTransform(Cargo->hLab, TYPE_Lab_16,
Cargo ->hRGB, TYPE_RGB_16,
INTENT_RELATIVE_COLORIMETRIC,
cmsFLAGS_NOTPRECALC);
Cargo->RGB2Lab = cmsCreateTransform(Cargo ->hRGB, TYPE_RGB_16,
Cargo ->hLab, TYPE_Lab_16,
INTENT_RELATIVE_COLORIMETRIC,
cmsFLAGS_NOTPRECALC);
}
static
void FreeCargo(LPCARGO Cargo)
{
cmsDeleteTransform(Cargo ->Lab2RGB);
cmsDeleteTransform(Cargo ->RGB2Lab);
cmsCloseProfile(Cargo ->hLab);
cmsCloseProfile(Cargo ->hRGB);
}
int main(void)
{
LPLUT AToB0, BToA0;
CARGO Cargo;
cmsHPROFILE hProfile;
fprintf(stderr, "Creating lcmscmy.icm...");
InitCargo(&Cargo);
hProfile = cmsCreateLabProfile(NULL);
AToB0 = cmsAllocLUT();
BToA0 = cmsAllocLUT();
cmsAlloc3DGrid(AToB0, 25, 3, 3);
cmsAlloc3DGrid(BToA0, 25, 3, 3);
cmsSample3DGrid(AToB0, Reverse, &Cargo, 0);
cmsSample3DGrid(BToA0, Forward, &Cargo, 0);
cmsAddTag(hProfile, icSigAToB0Tag, AToB0);
cmsAddTag(hProfile, icSigBToA0Tag, BToA0);
cmsSetColorSpace(hProfile, icSigCmyData);
cmsSetDeviceClass(hProfile, icSigOutputClass);
cmsAddTag(hProfile, icSigProfileDescriptionTag, "CMY ");
cmsAddTag(hProfile, icSigCopyrightTag, "Copyright (c) HP, 2007. All rights reserved.");
cmsAddTag(hProfile, icSigDeviceMfgDescTag, "Little cms");
cmsAddTag(hProfile, icSigDeviceModelDescTag, "CMY space");
_cmsSaveProfile(hProfile, "lcmscmy.icm");
cmsFreeLUT(AToB0);
cmsFreeLUT(BToA0);
cmsCloseProfile(hProfile);
FreeCargo(&Cargo);
fprintf(stderr, "Done.\n");
return 0;
}