Tizen 2.0 Release
[external/lcms.git] / utils / samples / mkgrayer.c
1 //
2 //  Little cms
3 //  Copyright (C) 1998-2003 Marti Maria
4 //
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:
11 //
12 // The above copyright notice and this permission notice shall be included in 
13 // all copies or substantial portions of the Software.
14 //
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.
22
23
24 #include "lcms.h"
25
26
27
28 static
29 int Forward(register WORD In[], register WORD Out[], register LPVOID Cargo)
30 {       
31     cmsCIELab Lab;
32
33
34     cmsLabEncoded2Float(&Lab, In);
35
36         if (fabs(Lab.a) < 3 && fabs(Lab.b) < 3) {
37                 
38                 double L_01 = Lab.L / 100.0;
39             WORD K;
40
41                 if (L_01 > 1) L_01 = 1;
42                 K = (WORD) floor(L_01* 65535.0 + 0.5);
43
44                 Out[0] = Out[1] = Out[2] = K; 
45         }
46         else {
47                 Out[0] = 0xFFFF; Out[1] = 0; Out[2] = 0; 
48         }
49
50         return TRUE;
51 }
52
53
54
55
56         
57 int main(int argc, char *argv[])
58 {
59         LPLUT BToA0;
60         cmsHPROFILE hProfile;
61
62         fprintf(stderr, "Creating interpol2.icc...");
63
64         unlink("interpol2.icc");
65         hProfile = cmsOpenProfileFromFile("interpol2.icc", "w8");
66
67
68     BToA0 = cmsAllocLUT();
69
70         cmsAlloc3DGrid(BToA0, 17, 3, 3);
71             
72         cmsSample3DGrid(BToA0, Forward, NULL, 0);
73                         
74     cmsAddTag(hProfile, icSigBToA0Tag, BToA0);
75                                         
76         cmsSetColorSpace(hProfile, icSigRgbData);
77     cmsSetPCS(hProfile, icSigLabData);
78     cmsSetDeviceClass(hProfile, icSigOutputClass);
79
80         cmsAddTag(hProfile, icSigProfileDescriptionTag, "Interpolation test");
81     cmsAddTag(hProfile, icSigCopyrightTag,          "Copyright (c) HP 2007. All rights reserved.");
82     cmsAddTag(hProfile, icSigDeviceMfgDescTag,      "Little cms");    
83     cmsAddTag(hProfile, icSigDeviceModelDescTag,    "Interpolation test profile");
84
85         
86         cmsCloseProfile(hProfile);
87     
88         cmsFreeLUT(BToA0);
89         
90         fprintf(stderr, "Done.\n");
91
92         return 0;
93 }