This source file includes following definitions.
- DecodeAbTIFF
- CreateStep
- CreateLinear
- SetTextTags
- main
#include "lcms2.h"
#include <stdlib.h>
#include <math.h>
static
double DecodeAbTIFF(double ab)
{
if (ab <= 128.)
ab += 127.;
else
ab -= 127.;
return ab;
}
static
cmsToneCurve* CreateStep(void)
{
cmsToneCurve* Gamma;
cmsUInt16Number* Table;
int i;
double a;
Table = calloc(4096, sizeof(cmsUInt16Number));
if (Table == NULL) return NULL;
for (i=0; i < 4096; i++) {
a = (double) i * 255. / 4095.;
a = DecodeAbTIFF(a);
Table[i] = (cmsUInt16Number) floor(a * 257. + 0.5);
}
Gamma = cmsBuildTabulatedToneCurve16(0, 4096, Table);
free(Table);
return Gamma;
}
static
cmsToneCurve* CreateLinear(void)
{
cmsUInt16Number Linear[2] = { 0, 0xffff };
return cmsBuildTabulatedToneCurve16(0, 2, Linear);
}
static
cmsBool SetTextTags(cmsHPROFILE hProfile)
{
cmsMLU *DescriptionMLU, *CopyrightMLU;
cmsBool rc = FALSE;
DescriptionMLU = cmsMLUalloc(0, 1);
CopyrightMLU = cmsMLUalloc(0, 1);
if (DescriptionMLU == NULL || CopyrightMLU == NULL) goto Error;
if (!cmsMLUsetASCII(DescriptionMLU, "en", "US", "Little cms Tiff8 CIELab")) goto Error;
if (!cmsMLUsetASCII(CopyrightMLU, "en", "US", "Copyright (c) Marti Maria, 2010. All rights reserved.")) goto Error;
if (!cmsWriteTag(hProfile, cmsSigProfileDescriptionTag, DescriptionMLU)) goto Error;
if (!cmsWriteTag(hProfile, cmsSigCopyrightTag, CopyrightMLU)) goto Error;
rc = TRUE;
Error:
if (DescriptionMLU)
cmsMLUfree(DescriptionMLU);
if (CopyrightMLU)
cmsMLUfree(CopyrightMLU);
return rc;
}
int main(int argc, char *argv[])
{
cmsHPROFILE hProfile;
cmsPipeline *AToB0;
cmsToneCurve* PreLinear[3];
cmsToneCurve *Lin, *Step;
fprintf(stderr, "Creating lcmstiff8.icm...");
remove("lcmstiff8.icm");
hProfile = cmsOpenProfileFromFile("lcmstiff8.icm", "w");
Lin = CreateLinear();
Step = CreateStep();
PreLinear[0] = Lin;
PreLinear[1] = Step;
PreLinear[2] = Step;
AToB0 = cmsPipelineAlloc(0, 3, 3);
cmsPipelineInsertStage(AToB0,
cmsAT_BEGIN, cmsStageAllocToneCurves(0, 3, PreLinear));
cmsSetColorSpace(hProfile, cmsSigLabData);
cmsSetPCS(hProfile, cmsSigLabData);
cmsSetDeviceClass(hProfile, cmsSigLinkClass);
cmsSetProfileVersion(hProfile, 4.2);
cmsWriteTag(hProfile, cmsSigAToB0Tag, AToB0);
SetTextTags(hProfile);
cmsCloseProfile(hProfile);
cmsFreeToneCurve(Lin);
cmsFreeToneCurve(Step);
cmsPipelineFree(AToB0);
fprintf(stderr, "Done.\n");
return 0;
}