author | adinn |
Fri, 26 Jan 2018 16:38:21 +0000 | |
changeset 48682 | 34e45260c040 |
parent 47216 | 71c04702a3d5 |
child 49775 | 8fa5bb0cb937 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
3 |
* |
|
4 |
* This code is free software; you can redistribute it and/or modify it |
|
5 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 6 |
* published by the Free Software Foundation. Oracle designates this |
2 | 7 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 8 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 9 |
* |
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
* accompanied this code). |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License version |
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
* |
|
5506 | 20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
21 |
* or visit www.oracle.com if you need additional information or have any |
|
22 |
* questions. |
|
2 | 23 |
*/ |
24 |
||
25 |
// This file is available under and governed by the GNU General Public |
|
26 |
// License version 2 only, as published by the Free Software Foundation. |
|
27 |
// However, the following notice accompanied the original version of this |
|
28 |
// file: |
|
29 |
// |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
30 |
//--------------------------------------------------------------------------------- |
2 | 31 |
// |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
32 |
// Little Color Management System |
40152 | 33 |
// Copyright (c) 1998-2016 Marti Maria Saguer |
2 | 34 |
// |
35 |
// Permission is hereby granted, free of charge, to any person obtaining |
|
36 |
// a copy of this software and associated documentation files (the "Software"), |
|
37 |
// to deal in the Software without restriction, including without limitation |
|
38 |
// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
|
39 |
// and/or sell copies of the Software, and to permit persons to whom the Software |
|
40 |
// is furnished to do so, subject to the following conditions: |
|
41 |
// |
|
42 |
// The above copyright notice and this permission notice shall be included in |
|
43 |
// all copies or substantial portions of the Software. |
|
44 |
// |
|
45 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
46 |
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO |
|
47 |
// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
48 |
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
|
49 |
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
|
50 |
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
|
51 |
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
52 |
// |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
53 |
//--------------------------------------------------------------------------------- |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
54 |
// |
2 | 55 |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
56 |
#include "lcms2_internal.h" |
2 | 57 |
|
2394 | 58 |
// CIECAM 02 appearance model. Many thanks to Jordi Vilar for the debugging. |
2 | 59 |
|
60 |
// ---------- Implementation -------------------------------------------- |
|
61 |
||
62 |
typedef struct { |
|
63 |
||
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
64 |
cmsFloat64Number XYZ[3]; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
65 |
cmsFloat64Number RGB[3]; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
66 |
cmsFloat64Number RGBc[3]; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
67 |
cmsFloat64Number RGBp[3]; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
68 |
cmsFloat64Number RGBpa[3]; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
69 |
cmsFloat64Number a, b, h, e, H, A, J, Q, s, t, C, M; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
70 |
cmsFloat64Number abC[2]; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
71 |
cmsFloat64Number abs[2]; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
72 |
cmsFloat64Number abM[2]; |
2 | 73 |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
74 |
} CAM02COLOR; |
2 | 75 |
|
76 |
typedef struct { |
|
77 |
||
78 |
CAM02COLOR adoptedWhite; |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
79 |
cmsFloat64Number LA, Yb; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
80 |
cmsFloat64Number F, c, Nc; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
81 |
cmsUInt32Number surround; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
82 |
cmsFloat64Number n, Nbb, Ncb, z, FL, D; |
2 | 83 |
|
23906 | 84 |
cmsContext ContextID; |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
85 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
86 |
} cmsCIECAM02; |
2 | 87 |
|
88 |
||
89 |
static |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
90 |
cmsFloat64Number compute_n(cmsCIECAM02* pMod) |
2 | 91 |
{ |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
92 |
return (pMod -> Yb / pMod -> adoptedWhite.XYZ[1]); |
2 | 93 |
} |
94 |
||
95 |
static |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
96 |
cmsFloat64Number compute_z(cmsCIECAM02* pMod) |
2 | 97 |
{ |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
98 |
return (1.48 + pow(pMod -> n, 0.5)); |
2 | 99 |
} |
100 |
||
101 |
static |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
102 |
cmsFloat64Number computeNbb(cmsCIECAM02* pMod) |
2 | 103 |
{ |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
104 |
return (0.725 * pow((1.0 / pMod -> n), 0.2)); |
2 | 105 |
} |
106 |
||
107 |
static |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
108 |
cmsFloat64Number computeFL(cmsCIECAM02* pMod) |
2 | 109 |
{ |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
110 |
cmsFloat64Number k, FL; |
2 | 111 |
|
112 |
k = 1.0 / ((5.0 * pMod->LA) + 1.0); |
|
113 |
FL = 0.2 * pow(k, 4.0) * (5.0 * pMod->LA) + 0.1 * |
|
114 |
(pow((1.0 - pow(k, 4.0)), 2.0)) * |
|
115 |
(pow((5.0 * pMod->LA), (1.0 / 3.0))); |
|
116 |
||
117 |
return FL; |
|
118 |
} |
|
119 |
||
120 |
static |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
121 |
cmsFloat64Number computeD(cmsCIECAM02* pMod) |
2 | 122 |
{ |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
123 |
cmsFloat64Number D; |
2 | 124 |
|
125 |
D = pMod->F - (1.0/3.6)*(exp(((-pMod ->LA-42) / 92.0))); |
|
126 |
||
127 |
return D; |
|
128 |
} |
|
129 |
||
130 |
||
131 |
static |
|
132 |
CAM02COLOR XYZtoCAT02(CAM02COLOR clr) |
|
133 |
{ |
|
134 |
clr.RGB[0] = (clr.XYZ[0] * 0.7328) + (clr.XYZ[1] * 0.4296) + (clr.XYZ[2] * -0.1624); |
|
135 |
clr.RGB[1] = (clr.XYZ[0] * -0.7036) + (clr.XYZ[1] * 1.6975) + (clr.XYZ[2] * 0.0061); |
|
136 |
clr.RGB[2] = (clr.XYZ[0] * 0.0030) + (clr.XYZ[1] * 0.0136) + (clr.XYZ[2] * 0.9834); |
|
137 |
||
138 |
return clr; |
|
139 |
} |
|
140 |
||
141 |
static |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
142 |
CAM02COLOR ChromaticAdaptation(CAM02COLOR clr, cmsCIECAM02* pMod) |
2 | 143 |
{ |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
144 |
cmsUInt32Number i; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
145 |
|
2 | 146 |
for (i = 0; i < 3; i++) { |
147 |
clr.RGBc[i] = ((pMod -> adoptedWhite.XYZ[1] * |
|
148 |
(pMod->D / pMod -> adoptedWhite.RGB[i])) + |
|
149 |
(1.0 - pMod->D)) * clr.RGB[i]; |
|
150 |
} |
|
151 |
||
152 |
return clr; |
|
153 |
} |
|
154 |
||
155 |
||
156 |
static |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
157 |
CAM02COLOR CAT02toHPE(CAM02COLOR clr) |
2 | 158 |
{ |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
159 |
cmsFloat64Number M[9]; |
2 | 160 |
|
161 |
M[0] =(( 0.38971 * 1.096124) + (0.68898 * 0.454369) + (-0.07868 * -0.009628)); |
|
162 |
M[1] =(( 0.38971 * -0.278869) + (0.68898 * 0.473533) + (-0.07868 * -0.005698)); |
|
163 |
M[2] =(( 0.38971 * 0.182745) + (0.68898 * 0.072098) + (-0.07868 * 1.015326)); |
|
164 |
M[3] =((-0.22981 * 1.096124) + (1.18340 * 0.454369) + ( 0.04641 * -0.009628)); |
|
165 |
M[4] =((-0.22981 * -0.278869) + (1.18340 * 0.473533) + ( 0.04641 * -0.005698)); |
|
166 |
M[5] =((-0.22981 * 0.182745) + (1.18340 * 0.072098) + ( 0.04641 * 1.015326)); |
|
167 |
M[6] =(-0.009628); |
|
168 |
M[7] =(-0.005698); |
|
169 |
M[8] =( 1.015326); |
|
170 |
||
171 |
clr.RGBp[0] = (clr.RGBc[0] * M[0]) + (clr.RGBc[1] * M[1]) + (clr.RGBc[2] * M[2]); |
|
172 |
clr.RGBp[1] = (clr.RGBc[0] * M[3]) + (clr.RGBc[1] * M[4]) + (clr.RGBc[2] * M[5]); |
|
173 |
clr.RGBp[2] = (clr.RGBc[0] * M[6]) + (clr.RGBc[1] * M[7]) + (clr.RGBc[2] * M[8]); |
|
174 |
||
175 |
return clr; |
|
176 |
} |
|
177 |
||
178 |
static |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
179 |
CAM02COLOR NonlinearCompression(CAM02COLOR clr, cmsCIECAM02* pMod) |
2 | 180 |
{ |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
181 |
cmsUInt32Number i; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
182 |
cmsFloat64Number temp; |
2 | 183 |
|
184 |
for (i = 0; i < 3; i++) { |
|
185 |
if (clr.RGBp[i] < 0) { |
|
186 |
||
187 |
temp = pow((-1.0 * pMod->FL * clr.RGBp[i] / 100.0), 0.42); |
|
188 |
clr.RGBpa[i] = (-1.0 * 400.0 * temp) / (temp + 27.13) + 0.1; |
|
189 |
} |
|
190 |
else { |
|
191 |
temp = pow((pMod->FL * clr.RGBp[i] / 100.0), 0.42); |
|
192 |
clr.RGBpa[i] = (400.0 * temp) / (temp + 27.13) + 0.1; |
|
193 |
} |
|
194 |
} |
|
2394 | 195 |
|
196 |
clr.A = (((2.0 * clr.RGBpa[0]) + clr.RGBpa[1] + |
|
197 |
(clr.RGBpa[2] / 20.0)) - 0.305) * pMod->Nbb; |
|
198 |
||
2 | 199 |
return clr; |
200 |
} |
|
201 |
||
202 |
static |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
203 |
CAM02COLOR ComputeCorrelates(CAM02COLOR clr, cmsCIECAM02* pMod) |
2 | 204 |
{ |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
205 |
cmsFloat64Number a, b, temp, e, t, r2d, d2r; |
2 | 206 |
|
207 |
a = clr.RGBpa[0] - (12.0 * clr.RGBpa[1] / 11.0) + (clr.RGBpa[2] / 11.0); |
|
208 |
b = (clr.RGBpa[0] + clr.RGBpa[1] - (2.0 * clr.RGBpa[2])) / 9.0; |
|
209 |
||
210 |
r2d = (180.0 / 3.141592654); |
|
211 |
if (a == 0) { |
|
212 |
if (b == 0) clr.h = 0; |
|
213 |
else if (b > 0) clr.h = 90; |
|
214 |
else clr.h = 270; |
|
215 |
} |
|
216 |
else if (a > 0) { |
|
217 |
temp = b / a; |
|
218 |
if (b > 0) clr.h = (r2d * atan(temp)); |
|
219 |
else if (b == 0) clr.h = 0; |
|
220 |
else clr.h = (r2d * atan(temp)) + 360; |
|
221 |
} |
|
222 |
else { |
|
223 |
temp = b / a; |
|
224 |
clr.h = (r2d * atan(temp)) + 180; |
|
225 |
} |
|
226 |
||
227 |
d2r = (3.141592654 / 180.0); |
|
228 |
e = ((12500.0 / 13.0) * pMod->Nc * pMod->Ncb) * |
|
229 |
(cos((clr.h * d2r + 2.0)) + 3.8); |
|
230 |
||
231 |
if (clr.h < 20.14) { |
|
232 |
temp = ((clr.h + 122.47)/1.2) + ((20.14 - clr.h)/0.8); |
|
233 |
clr.H = 300 + (100*((clr.h + 122.47)/1.2)) / temp; |
|
234 |
} |
|
235 |
else if (clr.h < 90.0) { |
|
236 |
temp = ((clr.h - 20.14)/0.8) + ((90.00 - clr.h)/0.7); |
|
237 |
clr.H = (100*((clr.h - 20.14)/0.8)) / temp; |
|
238 |
} |
|
239 |
else if (clr.h < 164.25) { |
|
240 |
temp = ((clr.h - 90.00)/0.7) + ((164.25 - clr.h)/1.0); |
|
241 |
clr.H = 100 + ((100*((clr.h - 90.00)/0.7)) / temp); |
|
242 |
} |
|
243 |
else if (clr.h < 237.53) { |
|
244 |
temp = ((clr.h - 164.25)/1.0) + ((237.53 - clr.h)/1.2); |
|
245 |
clr.H = 200 + ((100*((clr.h - 164.25)/1.0)) / temp); |
|
246 |
} |
|
247 |
else { |
|
248 |
temp = ((clr.h - 237.53)/1.2) + ((360 - clr.h + 20.14)/0.8); |
|
249 |
clr.H = 300 + ((100*((clr.h - 237.53)/1.2)) / temp); |
|
250 |
} |
|
251 |
||
252 |
clr.J = 100.0 * pow((clr.A / pMod->adoptedWhite.A), |
|
253 |
(pMod->c * pMod->z)); |
|
254 |
||
255 |
clr.Q = (4.0 / pMod->c) * pow((clr.J / 100.0), 0.5) * |
|
256 |
(pMod->adoptedWhite.A + 4.0) * pow(pMod->FL, 0.25); |
|
257 |
||
258 |
t = (e * pow(((a * a) + (b * b)), 0.5)) / |
|
259 |
(clr.RGBpa[0] + clr.RGBpa[1] + |
|
260 |
((21.0 / 20.0) * clr.RGBpa[2])); |
|
261 |
||
262 |
clr.C = pow(t, 0.9) * pow((clr.J / 100.0), 0.5) * |
|
263 |
pow((1.64 - pow(0.29, pMod->n)), 0.73); |
|
264 |
||
265 |
clr.M = clr.C * pow(pMod->FL, 0.25); |
|
266 |
clr.s = 100.0 * pow((clr.M / clr.Q), 0.5); |
|
267 |
||
268 |
return clr; |
|
269 |
} |
|
270 |
||
271 |
||
272 |
static |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
273 |
CAM02COLOR InverseCorrelates(CAM02COLOR clr, cmsCIECAM02* pMod) |
2 | 274 |
{ |
275 |
||
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
276 |
cmsFloat64Number t, e, p1, p2, p3, p4, p5, hr, d2r; |
2 | 277 |
d2r = 3.141592654 / 180.0; |
278 |
||
279 |
t = pow( (clr.C / (pow((clr.J / 100.0), 0.5) * |
|
280 |
(pow((1.64 - pow(0.29, pMod->n)), 0.73)))), |
|
281 |
(1.0 / 0.9) ); |
|
282 |
e = ((12500.0 / 13.0) * pMod->Nc * pMod->Ncb) * |
|
283 |
(cos((clr.h * d2r + 2.0)) + 3.8); |
|
284 |
||
285 |
clr.A = pMod->adoptedWhite.A * pow( |
|
286 |
(clr.J / 100.0), |
|
287 |
(1.0 / (pMod->c * pMod->z))); |
|
288 |
||
289 |
p1 = e / t; |
|
290 |
p2 = (clr.A / pMod->Nbb) + 0.305; |
|
291 |
p3 = 21.0 / 20.0; |
|
292 |
||
293 |
hr = clr.h * d2r; |
|
294 |
||
295 |
if (fabs(sin(hr)) >= fabs(cos(hr))) { |
|
296 |
p4 = p1 / sin(hr); |
|
297 |
clr.b = (p2 * (2.0 + p3) * (460.0 / 1403.0)) / |
|
298 |
(p4 + (2.0 + p3) * (220.0 / 1403.0) * |
|
299 |
(cos(hr) / sin(hr)) - (27.0 / 1403.0) + |
|
300 |
p3 * (6300.0 / 1403.0)); |
|
301 |
clr.a = clr.b * (cos(hr) / sin(hr)); |
|
302 |
} |
|
303 |
else { |
|
304 |
p5 = p1 / cos(hr); |
|
305 |
clr.a = (p2 * (2.0 + p3) * (460.0 / 1403.0)) / |
|
306 |
(p5 + (2.0 + p3) * (220.0 / 1403.0) - |
|
307 |
((27.0 / 1403.0) - p3 * (6300.0 / 1403.0)) * |
|
308 |
(sin(hr) / cos(hr))); |
|
309 |
clr.b = clr.a * (sin(hr) / cos(hr)); |
|
310 |
} |
|
311 |
||
312 |
clr.RGBpa[0] = ((460.0 / 1403.0) * p2) + |
|
313 |
((451.0 / 1403.0) * clr.a) + |
|
314 |
((288.0 / 1403.0) * clr.b); |
|
315 |
clr.RGBpa[1] = ((460.0 / 1403.0) * p2) - |
|
316 |
((891.0 / 1403.0) * clr.a) - |
|
317 |
((261.0 / 1403.0) * clr.b); |
|
318 |
clr.RGBpa[2] = ((460.0 / 1403.0) * p2) - |
|
319 |
((220.0 / 1403.0) * clr.a) - |
|
320 |
((6300.0 / 1403.0) * clr.b); |
|
321 |
||
322 |
return clr; |
|
323 |
} |
|
324 |
||
325 |
static |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
326 |
CAM02COLOR InverseNonlinearity(CAM02COLOR clr, cmsCIECAM02* pMod) |
2 | 327 |
{ |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
328 |
cmsUInt32Number i; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
329 |
cmsFloat64Number c1; |
2 | 330 |
|
331 |
for (i = 0; i < 3; i++) { |
|
332 |
if ((clr.RGBpa[i] - 0.1) < 0) c1 = -1; |
|
333 |
else c1 = 1; |
|
334 |
clr.RGBp[i] = c1 * (100.0 / pMod->FL) * |
|
335 |
pow(((27.13 * fabs(clr.RGBpa[i] - 0.1)) / |
|
336 |
(400.0 - fabs(clr.RGBpa[i] - 0.1))), |
|
337 |
(1.0 / 0.42)); |
|
338 |
} |
|
339 |
||
340 |
return clr; |
|
341 |
} |
|
342 |
||
343 |
static |
|
344 |
CAM02COLOR HPEtoCAT02(CAM02COLOR clr) |
|
345 |
{ |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
346 |
cmsFloat64Number M[9]; |
2 | 347 |
|
348 |
M[0] = (( 0.7328 * 1.910197) + (0.4296 * 0.370950)); |
|
349 |
M[1] = (( 0.7328 * -1.112124) + (0.4296 * 0.629054)); |
|
350 |
M[2] = (( 0.7328 * 0.201908) + (0.4296 * 0.000008) - 0.1624); |
|
351 |
M[3] = ((-0.7036 * 1.910197) + (1.6975 * 0.370950)); |
|
352 |
M[4] = ((-0.7036 * -1.112124) + (1.6975 * 0.629054)); |
|
353 |
M[5] = ((-0.7036 * 0.201908) + (1.6975 * 0.000008) + 0.0061); |
|
354 |
M[6] = (( 0.0030 * 1.910197) + (0.0136 * 0.370950)); |
|
355 |
M[7] = (( 0.0030 * -1.112124) + (0.0136 * 0.629054)); |
|
356 |
M[8] = (( 0.0030 * 0.201908) + (0.0136 * 0.000008) + 0.9834);; |
|
357 |
||
358 |
clr.RGBc[0] = (clr.RGBp[0] * M[0]) + (clr.RGBp[1] * M[1]) + (clr.RGBp[2] * M[2]); |
|
359 |
clr.RGBc[1] = (clr.RGBp[0] * M[3]) + (clr.RGBp[1] * M[4]) + (clr.RGBp[2] * M[5]); |
|
360 |
clr.RGBc[2] = (clr.RGBp[0] * M[6]) + (clr.RGBp[1] * M[7]) + (clr.RGBp[2] * M[8]); |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
361 |
return clr; |
2 | 362 |
} |
363 |
||
364 |
||
365 |
static |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
366 |
CAM02COLOR InverseChromaticAdaptation(CAM02COLOR clr, cmsCIECAM02* pMod) |
2 | 367 |
{ |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
368 |
cmsUInt32Number i; |
2 | 369 |
for (i = 0; i < 3; i++) { |
370 |
clr.RGB[i] = clr.RGBc[i] / |
|
371 |
((pMod->adoptedWhite.XYZ[1] * pMod->D / pMod->adoptedWhite.RGB[i]) + 1.0 - pMod->D); |
|
372 |
} |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
373 |
return clr; |
2 | 374 |
} |
375 |
||
376 |
||
377 |
static |
|
378 |
CAM02COLOR CAT02toXYZ(CAM02COLOR clr) |
|
379 |
{ |
|
380 |
clr.XYZ[0] = (clr.RGB[0] * 1.096124) + (clr.RGB[1] * -0.278869) + (clr.RGB[2] * 0.182745); |
|
381 |
clr.XYZ[1] = (clr.RGB[0] * 0.454369) + (clr.RGB[1] * 0.473533) + (clr.RGB[2] * 0.072098); |
|
382 |
clr.XYZ[2] = (clr.RGB[0] * -0.009628) + (clr.RGB[1] * -0.005698) + (clr.RGB[2] * 1.015326); |
|
383 |
||
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
384 |
return clr; |
2 | 385 |
} |
386 |
||
387 |
||
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
388 |
cmsHANDLE CMSEXPORT cmsCIECAM02Init(cmsContext ContextID, const cmsViewingConditions* pVC) |
2 | 389 |
{ |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
390 |
cmsCIECAM02* lpMod; |
2 | 391 |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
392 |
_cmsAssert(pVC != NULL); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
393 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
394 |
if((lpMod = (cmsCIECAM02*) _cmsMallocZero(ContextID, sizeof(cmsCIECAM02))) == NULL) { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
395 |
return NULL; |
2 | 396 |
} |
397 |
||
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
398 |
lpMod ->ContextID = ContextID; |
2 | 399 |
|
400 |
lpMod ->adoptedWhite.XYZ[0] = pVC ->whitePoint.X; |
|
401 |
lpMod ->adoptedWhite.XYZ[1] = pVC ->whitePoint.Y; |
|
402 |
lpMod ->adoptedWhite.XYZ[2] = pVC ->whitePoint.Z; |
|
403 |
||
404 |
lpMod -> LA = pVC ->La; |
|
405 |
lpMod -> Yb = pVC ->Yb; |
|
406 |
lpMod -> D = pVC ->D_value; |
|
407 |
lpMod -> surround = pVC ->surround; |
|
408 |
||
409 |
switch (lpMod -> surround) { |
|
410 |
||
411 |
||
14300 | 412 |
case CUTSHEET_SURROUND: |
413 |
lpMod->F = 0.8; |
|
414 |
lpMod->c = 0.41; |
|
415 |
lpMod->Nc = 0.8; |
|
416 |
break; |
|
2 | 417 |
|
14300 | 418 |
case DARK_SURROUND: |
419 |
lpMod -> F = 0.8; |
|
420 |
lpMod -> c = 0.525; |
|
421 |
lpMod -> Nc = 0.8; |
|
422 |
break; |
|
2 | 423 |
|
14300 | 424 |
case DIM_SURROUND: |
425 |
lpMod -> F = 0.9; |
|
426 |
lpMod -> c = 0.59; |
|
427 |
lpMod -> Nc = 0.95; |
|
428 |
break; |
|
2 | 429 |
|
14300 | 430 |
default: |
431 |
// Average surround |
|
432 |
lpMod -> F = 1.0; |
|
433 |
lpMod -> c = 0.69; |
|
434 |
lpMod -> Nc = 1.0; |
|
2 | 435 |
} |
436 |
||
437 |
lpMod -> n = compute_n(lpMod); |
|
438 |
lpMod -> z = compute_z(lpMod); |
|
439 |
lpMod -> Nbb = computeNbb(lpMod); |
|
440 |
lpMod -> FL = computeFL(lpMod); |
|
2394 | 441 |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
442 |
if (lpMod -> D == D_CALCULATE) { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
443 |
lpMod -> D = computeD(lpMod); |
2394 | 444 |
} |
445 |
||
2 | 446 |
lpMod -> Ncb = lpMod -> Nbb; |
447 |
||
448 |
lpMod -> adoptedWhite = XYZtoCAT02(lpMod -> adoptedWhite); |
|
449 |
lpMod -> adoptedWhite = ChromaticAdaptation(lpMod -> adoptedWhite, lpMod); |
|
450 |
lpMod -> adoptedWhite = CAT02toHPE(lpMod -> adoptedWhite); |
|
451 |
lpMod -> adoptedWhite = NonlinearCompression(lpMod -> adoptedWhite, lpMod); |
|
452 |
||
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
453 |
return (cmsHANDLE) lpMod; |
2 | 454 |
|
455 |
} |
|
456 |
||
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
457 |
void CMSEXPORT cmsCIECAM02Done(cmsHANDLE hModel) |
2 | 458 |
{ |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
459 |
cmsCIECAM02* lpMod = (cmsCIECAM02*) hModel; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
460 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
461 |
if (lpMod) _cmsFree(lpMod ->ContextID, lpMod); |
2 | 462 |
} |
463 |
||
464 |
||
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
465 |
void CMSEXPORT cmsCIECAM02Forward(cmsHANDLE hModel, const cmsCIEXYZ* pIn, cmsJCh* pOut) |
2 | 466 |
{ |
467 |
CAM02COLOR clr; |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
468 |
cmsCIECAM02* lpMod = (cmsCIECAM02*) hModel; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
469 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
470 |
_cmsAssert(lpMod != NULL); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
471 |
_cmsAssert(pIn != NULL); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
472 |
_cmsAssert(pOut != NULL); |
2 | 473 |
|
26609 | 474 |
memset(&clr, 0, sizeof(clr)); |
475 |
||
2 | 476 |
clr.XYZ[0] = pIn ->X; |
477 |
clr.XYZ[1] = pIn ->Y; |
|
478 |
clr.XYZ[2] = pIn ->Z; |
|
479 |
||
480 |
clr = XYZtoCAT02(clr); |
|
481 |
clr = ChromaticAdaptation(clr, lpMod); |
|
482 |
clr = CAT02toHPE(clr); |
|
483 |
clr = NonlinearCompression(clr, lpMod); |
|
484 |
clr = ComputeCorrelates(clr, lpMod); |
|
485 |
||
486 |
pOut ->J = clr.J; |
|
487 |
pOut ->C = clr.C; |
|
488 |
pOut ->h = clr.h; |
|
489 |
} |
|
490 |
||
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
491 |
void CMSEXPORT cmsCIECAM02Reverse(cmsHANDLE hModel, const cmsJCh* pIn, cmsCIEXYZ* pOut) |
2 | 492 |
{ |
493 |
CAM02COLOR clr; |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
494 |
cmsCIECAM02* lpMod = (cmsCIECAM02*) hModel; |
2 | 495 |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
496 |
_cmsAssert(lpMod != NULL); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
497 |
_cmsAssert(pIn != NULL); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
498 |
_cmsAssert(pOut != NULL); |
2 | 499 |
|
26609 | 500 |
memset(&clr, 0, sizeof(clr)); |
501 |
||
2 | 502 |
clr.J = pIn -> J; |
503 |
clr.C = pIn -> C; |
|
504 |
clr.h = pIn -> h; |
|
505 |
||
506 |
clr = InverseCorrelates(clr, lpMod); |
|
507 |
clr = InverseNonlinearity(clr, lpMod); |
|
508 |
clr = HPEtoCAT02(clr); |
|
509 |
clr = InverseChromaticAdaptation(clr, lpMod); |
|
510 |
clr = CAT02toXYZ(clr); |
|
511 |
||
512 |
pOut ->X = clr.XYZ[0]; |
|
513 |
pOut ->Y = clr.XYZ[1]; |
|
514 |
pOut ->Z = clr.XYZ[2]; |
|
515 |
} |