1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
//
// Little cms
// Copyright (C) 1998-2010 Marti Maria
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the Software
// is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Creates a devicelink that decodes TIFF8 Lab files
#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);
}
// Set the copyright and description
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");
// Create linearization
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;
}
|