3 // Copyright (C) 1998-2010 Marti Maria
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the Software
10 // is furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
17 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 // Creates a devicelink that decodes TIFF8 Lab files
30 double DecodeAbTIFF(double ab)
41 cmsToneCurve* CreateStep(void)
44 cmsUInt16Number* Table;
48 Table = calloc(4096, sizeof(cmsUInt16Number));
49 if (Table == NULL) return NULL;
51 for (i=0; i < 4096; i++) {
53 a = (double) i * 255. / 4095.;
57 Table[i] = (cmsUInt16Number) floor(a * 257. + 0.5);
60 Gamma = cmsBuildTabulatedToneCurve16(0, 4096, Table);
68 cmsToneCurve* CreateLinear(void)
70 cmsUInt16Number Linear[2] = { 0, 0xffff };
72 return cmsBuildTabulatedToneCurve16(0, 2, Linear);
77 // Set the copyright and description
79 cmsBool SetTextTags(cmsHPROFILE hProfile)
81 cmsMLU *DescriptionMLU, *CopyrightMLU;
84 DescriptionMLU = cmsMLUalloc(0, 1);
85 CopyrightMLU = cmsMLUalloc(0, 1);
87 if (DescriptionMLU == NULL || CopyrightMLU == NULL) goto Error;
89 if (!cmsMLUsetASCII(DescriptionMLU, "en", "US", "Little cms Tiff8 CIELab")) goto Error;
90 if (!cmsMLUsetASCII(CopyrightMLU, "en", "US", "Copyright (c) Marti Maria, 2010. All rights reserved.")) goto Error;
92 if (!cmsWriteTag(hProfile, cmsSigProfileDescriptionTag, DescriptionMLU)) goto Error;
93 if (!cmsWriteTag(hProfile, cmsSigCopyrightTag, CopyrightMLU)) goto Error;
100 cmsMLUfree(DescriptionMLU);
102 cmsMLUfree(CopyrightMLU);
107 int main(int argc, char *argv[])
109 cmsHPROFILE hProfile;
111 cmsToneCurve* PreLinear[3];
112 cmsToneCurve *Lin, *Step;
114 fprintf(stderr, "Creating lcmstiff8.icm...");
116 remove("lcmstiff8.icm");
117 hProfile = cmsOpenProfileFromFile("lcmstiff8.icm", "w");
119 // Create linearization
120 Lin = CreateLinear();
127 AToB0 = cmsPipelineAlloc(0, 3, 3);
129 cmsPipelineInsertStage(AToB0,
130 cmsAT_BEGIN, cmsStageAllocToneCurves(0, 3, PreLinear));
132 cmsSetColorSpace(hProfile, cmsSigLabData);
133 cmsSetPCS(hProfile, cmsSigLabData);
134 cmsSetDeviceClass(hProfile, cmsSigLinkClass);
135 cmsSetProfileVersion(hProfile, 4.2);
137 cmsWriteTag(hProfile, cmsSigAToB0Tag, AToB0);
139 SetTextTags(hProfile);
141 cmsCloseProfile(hProfile);
143 cmsFreeToneCurve(Lin);
144 cmsFreeToneCurve(Step);
145 cmsPipelineFree(AToB0);
147 fprintf(stderr, "Done.\n");