1 
2 /*
3  * International Color Consortium color transform expanded support
4  *
5  * Author:  Graeme W. Gill
6  * Date:    8/5/2002
7  * Version: 1.00
8  *
9  * Copyright 2002 Graeme W. Gill
10  * All rights reserved.
11  * This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
12  * see the License.txt file for licencing details.
13  *
14  */
15 
16 /*
17  * This is some test code to test the FWA compensation
18  * feature of the spectal to CIE conversion.
19  *
20  */
21 
22 #define FILTERED_D65	/* Use Spectrolino filtered D65 instead of ideal D65 */
23 
24 #define DOPLOT		/* Graphs: Black = target curve */
25 					/*         Red   = uncorrected curve */
26 					/*         Green = corrected curve */
27 
28 #define DATAFILE	/* Write the plot data to a data file */
29 
30 #include <stdio.h>
31 #include <math.h>
32 #include "xspect.h"
33 #include "numlib.h"
34 #ifdef DOPLOT
35 #include "plot.h"
36 #include "ui.h"
37 #endif
38 
39 
40 /* Spectrolino filter "D65" illuminant */
41 static xspect il_sod65 = {
42 	36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
43 	100.0,				/* Scale factor */
44 	{
45 		17.42, 29.51, 36.54, 38.39, 38.15,
46 		39.68, 44.7,  53.6,  64.26, 74.01,
47 		82.39, 89.9, 93.45, 94.05, 91.59,
48 		89.4, 93.69, 100.85, 99.66, 87.12,
49 		78.34, 82.95, 91.31, 98.18, 99.99,
50 		104.38, 120.06, 145.35, 172.8, 190.38,
51 		192.46, 181.28, 163.7, 143.14, 123.57,
52 		104.67
53 	}
54 };
55 
56 /* Material/illuminant record */
57 struct {
58 	char *media;			/* Media/process identifier */
59 	char *illum;			/* Primary illuminant identifier */
60 	icxIllumeType ill;		/* Illuminant used to get reflectance spectrum */
61 	xspect white;			/* Media on its own spectrum */
62 	xspect black;			/* Media with maximum colorant */
63 	struct {
64 		char *pdesc;		/* Description of sample */
65 		xspect s;			/* Spectrum of it */
66 	} patches[6];
67 
68 } matilum[2][2]	= {		/* [Cromalin, Epson 10K] [A, D65] */
69 	{
70 		{
71 			"Cromalin",			/* Paper measured */
72 			"Illuminant A",		/* Illuminant measured under */
73 			icxIT_A,
74 			{	/* White */
75 				36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
76 				1.0,				/* Scale factor */
77 				{
78 					0.0376, 0.0217, 0.0325, 0.1779, 0.5891,
79 					0.9366, 1.0307, 1.0241, 0.9996, 0.9738,
80 					0.9521, 0.9355, 0.9245, 0.9174, 0.9147,
81 					0.9113, 0.9112, 0.9118, 0.9111, 0.9148,
82 					0.9147, 0.9162, 0.9172, 0.9185, 0.9197,
83 					0.9194, 0.9213, 0.9239, 0.9259, 0.9257,
84 					0.9259, 0.9250, 0.9271, 0.9293, 0.9296, 0.9310
85 				}
86 			},
87 			{	/* Black */
88 				36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
89 				1.0,				/* Scale factor */
90 				{
91 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
92 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
93 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
94 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
95 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
96 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
97 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000
98 				}
99 			},
100 			{
101 				{
102 					"30% Y",
103 					{
104 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
105 						1.0,				/* Scale factor */
106 						{
107 							0.0274, 0.0161, 0.0218, 0.1072, 0.3077,
108 							0.4280, 0.4532, 0.4530, 0.4508, 0.4498,
109 							0.4585, 0.5019, 0.6137, 0.7716, 0.8680,
110 							0.8939, 0.9000, 0.8999, 0.9015, 0.9098,
111 							0.9153, 0.9193, 0.9212, 0.9230, 0.9245,
112 							0.9247, 0.9267, 0.9294, 0.9317, 0.9315,
113 							0.9317, 0.9317, 0.9331, 0.9354, 0.9357, 0.9366
114 						}
115 					}
116 				},
117 				{
118 					"60% Y",
119 					{
120 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
121 						1.0,				/* Scale factor */
122 						{
123 							0.0225, 0.0130, 0.0169, 0.0613, 0.1512,
124 							0.1951, 0.2039, 0.2059, 0.2095, 0.2149,
125 							0.2301, 0.2850, 0.4283, 0.6585, 0.8249,
126 							0.8767, 0.8878, 0.8860, 0.8887, 0.9017,
127 							0.9115, 0.9181, 0.9202, 0.9219, 0.9232,
128 							0.9229, 0.9247, 0.9269, 0.9289, 0.9283,
129 							0.9280, 0.9277, 0.9292, 0.9307, 0.9305, 0.9315
130 						}
131 					}
132 				},
133 				{
134 					"90% Y",
135 					{
136 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
137 						1.0,				/* Scale factor */
138 						{
139 							0.0195, 0.0114, 0.0140, 0.0314, 0.0568,
140 							0.0664, 0.0691, 0.0708, 0.0760, 0.0836,
141 							0.1003, 0.1571, 0.3087, 0.5728, 0.7861,
142 							0.8602, 0.8759, 0.8737, 0.8781, 0.8952,
143 							0.9094, 0.9185, 0.9215, 0.9234, 0.9250,
144 							0.9248, 0.9267, 0.9292, 0.9312, 0.9307,
145 							0.9305, 0.9300, 0.9313, 0.9328, 0.9321, 0.9339
146 						}
147 					}
148 				},
149 				{
150 					"30% K",
151 					{
152 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
153 						1.0,				/* Scale factor */
154 						{
155 							0.0163, 0.0117, 0.0181, 0.1018, 0.3029,
156 							0.4324, 0.4585, 0.4539, 0.4437, 0.4330,
157 							0.4247, 0.4180, 0.4140, 0.4113, 0.4108,
158 							0.4095, 0.4097, 0.4101, 0.4100, 0.4117,
159 							0.4119, 0.4126, 0.4133, 0.4141, 0.4152,
160 							0.4156, 0.4169, 0.4187, 0.4200, 0.4206,
161 							0.4211, 0.4214, 0.4224, 0.4240, 0.4243, 0.4256
162 						}
163 					}
164 				},
165 				{
166 					"60% K",
167 					{
168 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
169 						1.0,				/* Scale factor */
170 						{
171 							0.0087, 0.0070, 0.0138, 0.0539, 0.1378,
172 							0.1802, 0.1872, 0.1840, 0.1794, 0.1748,
173 							0.1711, 0.1686, 0.1669, 0.1661, 0.1659,
174 							0.1656, 0.1657, 0.1661, 0.1660, 0.1670,
175 							0.1670, 0.1675, 0.1680, 0.1686, 0.1693,
176 							0.1700, 0.1707, 0.1720, 0.1728, 0.1735,
177 							0.1740, 0.1745, 0.1749, 0.1761, 0.1759, 0.1779
178 						}
179 					}
180 				},
181 				{
182 					"90% K",
183 					{
184 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
185 						1.0,				/* Scale factor */
186 						{
187 							0.0044, 0.0040, 0.0090, 0.0243, 0.0430,
188 							0.0503, 0.0508, 0.0485, 0.0460, 0.0440,
189 							0.0423, 0.0412, 0.0406, 0.0404, 0.0404,
190 							0.0404, 0.0407, 0.0409, 0.0411, 0.0415,
191 							0.0418, 0.0422, 0.0424, 0.0429, 0.0434,
192 							0.0440, 0.0444, 0.0452, 0.0459, 0.0465,
193 							0.0469, 0.0473, 0.0477, 0.0483, 0.0489, 0.0496
194 						}
195 					}
196 				}
197 			}
198 		},
199 		{
200 			"Cromalin",
201 			"Illuminant filtered D65",
202 			icxIT_D65,
203 			{	/* White */
204 				36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
205 				1.0,				/* Scale factor */
206 				{
207 					0.0096, 0.0082, 0.0242, 0.1791, 0.6547,
208 					1.0944, 1.2012, 1.1545, 1.0891, 1.0388,
209 					1.0009, 0.9725, 0.9552, 0.9442, 0.9384,
210 					0.9313, 0.9266, 0.9235, 0.9213, 0.9250,
211 					0.9249, 0.9247, 0.9239, 0.9248, 0.9253,
212 					0.9249, 0.9267, 0.9293, 0.9310, 0.9308,
213 					0.9307, 0.9311, 0.9309, 0.9335, 0.9263, 0.8774
214 				}
215 			},
216 			{	/* Black */
217 				36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
218 				1.0,				/* Scale factor */
219 				{
220 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
221 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
222 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
223 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
224 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
225 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
226 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000
227 				}
228 			},
229 			{
230 				{
231 					"30% Y",
232 					{
233 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
234 						1.0,				/* Scale factor */
235 						{
236 							0.0054, 0.0050, 0.0157, 0.1084, 0.3443,
237 							0.4998, 0.5278, 0.5108, 0.4915, 0.4802,
238 							0.4823, 0.5221, 0.6331, 0.7929, 0.8894,
239 							0.9116, 0.9134, 0.9095, 0.9097, 0.9176,
240 							0.9222, 0.9245, 0.9251, 0.9267, 0.9278,
241 							0.9275, 0.9293, 0.9323, 0.9344, 0.9346,
242 							0.9348, 0.9346, 0.9344, 0.9354, 0.9252, 0.8748
243 						}
244 					}
245 				},
246 				{
247 					"60% Y",
248 					{
249 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
250 						1.0,				/* Scale factor */
251 						{
252 							0.0039, 0.0042, 0.0117, 0.0632, 0.1733,
253 							0.2333, 0.2430, 0.2364, 0.2315, 0.2315,
254 							0.2440, 0.2976, 0.4421, 0.6777, 0.8461,
255 							0.8950, 0.9014, 0.8967, 0.8971, 0.9095,
256 							0.9187, 0.9234, 0.9242, 0.9263, 0.9270,
257 							0.9257, 0.9280, 0.9303, 0.9326, 0.9322,
258 							0.9315, 0.9317, 0.9314, 0.9306, 0.9169, 0.8664
259 						}
260 					}
261 				},
262 				{
263 					"90% Y",
264 					{
265 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
266 						1.0,				/* Scale factor */
267 						{
268 							0.0032, 0.0038, 0.0099, 0.0342, 0.0716,
269 							0.0889, 0.0918, 0.0884, 0.0887, 0.0931,
270 							0.1086, 0.1652, 0.3190, 0.5892, 0.8060,
271 							0.8777, 0.8891, 0.8839, 0.8863, 0.9022,
272 							0.9158, 0.9230, 0.9259, 0.9269, 0.9283,
273 							0.9266, 0.9304, 0.9327, 0.9350, 0.9344,
274 							0.9342, 0.9336, 0.9328, 0.9323, 0.9175, 0.8589
275 						}
276 					}
277 				},
278 				{
279 					"30% K",
280 					{
281 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
282 						1.0,				/* Scale factor */
283 						{
284 							0.0047, 0.0049, 0.0153, 0.1046, 0.3404,
285 							0.5036, 0.5317, 0.5102, 0.4828, 0.4620,
286 							0.4468, 0.4358, 0.4293, 0.4249, 0.4232,
287 							0.4207, 0.4191, 0.4181, 0.4172, 0.4188,
288 							0.4190, 0.4194, 0.4191, 0.4196, 0.4203,
289 							0.4204, 0.4218, 0.4236, 0.4251, 0.4255,
290 							0.4258, 0.4259, 0.4267, 0.4276, 0.4249, 0.4031
291 						}
292 					}
293 				},
294 				{
295 					"60% K",
296 					{
297 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
298 						1.0,				/* Scale factor */
299 						{
300 							0.0042, 0.0047, 0.0126, 0.0586, 0.1584,
301 							0.2146, 0.2206, 0.2101, 0.1978, 0.1885,
302 							0.1820, 0.1774, 0.1748, 0.1730, 0.1726,
303 							0.1714, 0.1710, 0.1703, 0.1704, 0.1712,
304 							0.1709, 0.1717, 0.1713, 0.1724, 0.1730,
305 							0.1732, 0.1738, 0.1753, 0.1759, 0.1768,
306 							0.1766, 0.1778, 0.1774, 0.1775, 0.1774, 0.1707
307 						}
308 					}
309 				},
310 				{
311 					"90% K",
312 					{
313 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
314 						1.0,				/* Scale factor */
315 						{
316 							0.0018, 0.0039, 0.0103, 0.0293, 0.0560,
317 							0.0677, 0.0676, 0.0611, 0.0551, 0.0505,
318 							0.0475, 0.0452, 0.0441, 0.0434, 0.0430,
319 							0.0430, 0.0428, 0.0428, 0.0427, 0.0433,
320 							0.0433, 0.0434, 0.0441, 0.0438, 0.0448,
321 							0.0457, 0.0453, 0.0468, 0.0471, 0.0477,
322 							0.0483, 0.0483, 0.0487, 0.0486, 0.0492, 0.0500
323 						}
324 					}
325 				}
326 			}
327 		}
328 	},
329 	{
330 		{
331 			"Epson10K",
332 			"Illuminant A",
333 			icxIT_A,
334 			{	/* White */
335 				36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
336 				1.0,				/* Scale factor */
337 				{
338 					0.4561, 0.4677, 0.5052, 0.6477, 0.8785,
339 					0.9929, 1.0127, 0.9909, 0.9676, 0.9539,
340 					0.9420, 0.9330, 0.9277, 0.9246, 0.9236,
341 					0.9205, 0.9200, 0.9191, 0.9172, 0.9198,
342 					0.9184, 0.9185, 0.9181, 0.9189, 0.9204,
343 					0.9207, 0.9228, 0.9256, 0.9277, 0.9276,
344 					0.9284, 0.9286, 0.9304, 0.9332, 0.9321, 0.9349
345 				}
346 			},
347 			{	/* Black */
348 				36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
349 				1.0,				/* Scale factor */
350 				{
351 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
352 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
353 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
354 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
355 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
356 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
357 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000
358 				}
359 			},
360 			{
361 				{
362 					"30% Y",
363 					{
364 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
365 						1.0,				/* Scale factor */
366 						{
367 							0.3650, 0.3689, 0.3908, 0.4912, 0.6549,
368 							0.7395, 0.7667, 0.7745, 0.7868, 0.8103,
369 							0.8385, 0.8663, 0.8869, 0.8983, 0.9037,
370 							0.9028, 0.9031, 0.9024, 0.9006, 0.9030,
371 							0.9018, 0.9016, 0.9007, 0.9011, 0.9013,
372 							0.9002, 0.9015, 0.9032, 0.9048, 0.9043,
373 							0.9040, 0.9038, 0.9050, 0.9073, 0.9062, 0.9082
374 						}
375 					}
376 				},
377 				{
378 					"60% Y",
379 					{
380 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
381 						1.0,				/* Scale factor */
382 						{
383 							0.2376, 0.2286, 0.2349, 0.2856, 0.3740,
384 							0.4290, 0.4642, 0.5005, 0.5513, 0.6172,
385 							0.6959, 0.7750, 0.8340, 0.8683, 0.8848,
386 							0.8884, 0.8901, 0.8900, 0.8884, 0.8906,
387 							0.8892, 0.8893, 0.8884, 0.8885, 0.8886,
388 							0.8875, 0.8885, 0.8903, 0.8917, 0.8910,
389 							0.8911, 0.8908, 0.8924, 0.8951, 0.8940, 0.8962
390 						}
391 					}
392 				},
393 				{
394 					"90% Y",
395 					{
396 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
397 						1.0,				/* Scale factor */
398 						{
399 							0.0482, 0.0362, 0.0314, 0.0323, 0.0373,
400 							0.0448, 0.0570, 0.0829, 0.1310, 0.2130,
401 							0.3465, 0.5227, 0.6838, 0.7871, 0.8409,
402 							0.8622, 0.8713, 0.8749, 0.8752, 0.8787,
403 							0.8783, 0.8787, 0.8781, 0.8784, 0.8784,
404 							0.8773, 0.8780, 0.8794, 0.8802, 0.8789,
405 							0.8783, 0.8773, 0.8778, 0.8794, 0.8775, 0.8779
406 						}
407 					}
408 				},
409 				{
410 					"30% K",
411 					{
412 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
413 						1.0,				/* Scale factor */
414 						{
415 							0.3304, 0.3398, 0.3632, 0.4562, 0.6018,
416 							0.6702, 0.6808, 0.6663, 0.6520, 0.6434,
417 							0.6362, 0.6311, 0.6285, 0.6272, 0.6269,
418 							0.6253, 0.6253, 0.6253, 0.6247, 0.6274,
419 							0.6280, 0.6301, 0.6320, 0.6351, 0.6385,
420 							0.6414, 0.6464, 0.6530, 0.6593, 0.6643,
421 							0.6692, 0.6727, 0.6770, 0.6811, 0.6826, 0.6856
422 						}
423 					}
424 				},
425 				{
426 					"60% K",
427 					{
428 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
429 						1.0,				/* Scale factor */
430 						{
431 							0.1735, 0.1784, 0.1886, 0.2295, 0.2936,
432 							0.3232, 0.3279, 0.3227, 0.3177, 0.3152,
433 							0.3133, 0.3126, 0.3126, 0.3131, 0.3141,
434 							0.3142, 0.3151, 0.3160, 0.3169, 0.3195,
435 							0.3217, 0.3251, 0.3287, 0.3335, 0.3386,
436 							0.3439, 0.3511, 0.3599, 0.3692, 0.3775,
437 							0.3853, 0.3919, 0.3982, 0.4036, 0.4068, 0.4109
438 						}
439 					}
440 				},
441 				{
442 					"90% K",
443 					{
444 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
445 						1.0,				/* Scale factor */
446 						{
447 							0.0197, 0.0198, 0.0201, 0.0201, 0.0208,
448 							0.0207, 0.0204, 0.0202, 0.0200, 0.0197,
449 							0.0194, 0.0194, 0.0193, 0.0192, 0.0191,
450 							0.0191, 0.0190, 0.0190, 0.0190, 0.0192,
451 							0.0194, 0.0198, 0.0205, 0.0212, 0.0221,
452 							0.0230, 0.0244, 0.0261, 0.0282, 0.0304,
453 							0.0326, 0.0346, 0.0366, 0.0383, 0.0396, 0.0412
454 						}
455 					}
456 				}
457 			}
458 		},
459 		{
460 			"Epson10K",
461 			"Illuminant filtered D65",
462 			icxIT_D65,
463 			{	/* White */
464 				36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
465 				1.0,				/* Scale factor */
466 				{
467 					0.4452, 0.4631, 0.5041, 0.6692, 0.9582,
468 					1.1083, 1.1289, 1.0717, 1.0191, 0.9929,
469 					0.9721, 0.9560, 0.9483, 0.9439, 0.9419,
470 					0.9374, 0.9357, 0.9337, 0.9313, 0.9340,
471 					0.9330, 0.9329, 0.9320, 0.9328, 0.9341,
472 					0.9339, 0.9366, 0.9387, 0.9406, 0.9405,
473 					0.9404, 0.9405, 0.9414, 0.9455, 0.9369, 0.9289
474 				}
475 			},
476 			{	/* Black */
477 				36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
478 				1.0,				/* Scale factor */
479 				{
480 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
481 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
482 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
483 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
484 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
485 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
486 					0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000
487 				}
488 			},
489 			{
490 				{
491 					"30% Y",
492 					{
493 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
494 						1.0,				/* Scale factor */
495 						{
496 							0.3538, 0.3632, 0.3888, 0.5058, 0.7111,
497 							0.8221, 0.8512, 0.8334, 0.8251, 0.8392,
498 							0.8609, 0.8832, 0.9013, 0.9113, 0.9157,
499 							0.9137, 0.9128, 0.9113, 0.9086, 0.9111,
500 							0.9103, 0.9094, 0.9091, 0.9083, 0.9085,
501 							0.9080, 0.9091, 0.9104, 0.9118, 0.9104,
502 							0.9099, 0.9099, 0.9094, 0.9111, 0.9054, 0.8793
503 						}
504 					}
505 				},
506 				{
507 					"60% Y",
508 					{
509 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
510 						1.0,				/* Scale factor */
511 						{
512 							0.2220, 0.2209, 0.2299, 0.2901, 0.4010,
513 							0.4716, 0.5092, 0.5337, 0.5732, 0.6337,
514 							0.7095, 0.7848, 0.8422, 0.8755, 0.8907,
515 							0.8933, 0.8938, 0.8927, 0.8909, 0.8929,
516 							0.8922, 0.8912, 0.8897, 0.8902, 0.8900,
517 							0.8893, 0.8896, 0.8915, 0.8932, 0.8918,
518 							0.8921, 0.8915, 0.8921, 0.8939, 0.8825, 0.8575
519 						}
520 					}
521 				},
522 				{
523 					"90% Y",
524 					{
525 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
526 						1.0,				/* Scale factor */
527 						{
528 							0.0326, 0.0287, 0.0269, 0.0295, 0.0376,
529 							0.0469, 0.0605, 0.0862, 0.1343, 0.2162,
530 							0.3503, 0.5257, 0.6862, 0.7889, 0.8420,
531 							0.8632, 0.8719, 0.8753, 0.8753, 0.8784,
532 							0.8776, 0.8778, 0.8778, 0.8783, 0.8775,
533 							0.8772, 0.8777, 0.8791, 0.8808, 0.8793,
534 							0.8784, 0.8770, 0.8758, 0.8757, 0.8626, 0.8106
535 						}
536 					}
537 				},
538 				{
539 					"30% K",
540 					{
541 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
542 						1.0,				/* Scale factor */
543 						{
544 							0.3243, 0.3369, 0.3635, 0.4708, 0.6532,
545 							0.7439, 0.7542, 0.7167, 0.6839, 0.6673,
546 							0.6546, 0.6454, 0.6412, 0.6387, 0.6380,
547 							0.6357, 0.6351, 0.6341, 0.6334, 0.6363,
548 							0.6367, 0.6388, 0.6400, 0.6431, 0.6465,
549 							0.6491, 0.6532, 0.6591, 0.6656, 0.6699,
550 							0.6743, 0.6778, 0.6816, 0.6859, 0.6815, 0.6758
551 						}
552 					}
553 				},
554 				{
555 					"60% K",
556 					{
557 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
558 						1.0,				/* Scale factor */
559 						{
560 							0.1707, 0.1772, 0.1895, 0.2374, 0.3174,
561 							0.3566, 0.3616, 0.3464, 0.3329, 0.3272,
562 							0.3228, 0.3201, 0.3196, 0.3198, 0.3208,
563 							0.3203, 0.3207, 0.3217, 0.3221, 0.3249,
564 							0.3269, 0.3295, 0.3339, 0.3375, 0.3427,
565 							0.3483, 0.3545, 0.3635, 0.3726, 0.3808,
566 							0.3881, 0.3949, 0.4003, 0.4053, 0.4052, 0.3962
567 						}
568 					}
569 				},
570 				{
571 					"90% K",
572 					{
573 						36, 380.0, 730.0,	/* 36 bands from 380 to 730 in 10nm steps */
574 						1.0,				/* Scale factor */
575 						{
576 							0.0206, 0.0205, 0.0202, 0.0205, 0.0213,
577 							0.0217, 0.0210, 0.0207, 0.0202, 0.0199,
578 							0.0198, 0.0197, 0.0197, 0.0195, 0.0196,
579 							0.0193, 0.0192, 0.0194, 0.0194, 0.0194,
580 							0.0197, 0.0198, 0.0204, 0.0214, 0.0223,
581 							0.0236, 0.0242, 0.0265, 0.0283, 0.0306,
582 							0.0330, 0.0347, 0.0370, 0.0389, 0.0394, 0.0383
583 						}
584 					}
585 				}
586 			}
587 		}
588 	}
589 };
590 
591 /* ---------------------------------------------------------- */
592 
593 int
main(void)594 main(void) {
595 	int m, ps, ss, pn;
596 #ifdef DATAFILE
597 	FILE *df;
598 #endif
599 
600 	printf("Hi there\n");
601 
602 #ifdef DATAFILE
603 	if ((df = fopen("spectest.dat", "w")) == NULL)
604 		error ("Unable to open data file '%s'","spectest.dat");
605 #endif
606 	/* For each material and illuminant */
607 	for (m = 0; m < 2; m++) {
608 
609 		printf("Material '%s'\n", matilum[m][0].media);
610 
611 		/* For each light source as primary (target/check), other as secondary (instrument) */
612 		for (ps = 0; ps < 2; ps++) {
613 			xsp2cie *pcon, *scon;		/* Conversions */
614 			xspect pill, sill;			/* Illuminants */
615 
616 			ss = 1 - ps;	/* Opposite */
617 
618 #ifdef FILTERED_D65
619 			if (matilum[m][ps].ill == icxIT_D65)
620 				pill = il_sod65;
621 			else
622 #endif
623 				standardIlluminant(&pill, matilum[m][ps].ill, 0);		/* Target/check */
624 
625 #ifdef FILTERED_D65
626 			if (matilum[m][ss].ill == icxIT_D65)
627 				sill = il_sod65;
628 			else
629 #endif
630 				standardIlluminant(&sill, matilum[m][ss].ill, 0);		/* Instrument */
631 
632 			/* Create two conversions for the target/check illuminant */
633 			if ((pcon = new_xsp2cie(icxIT_custom, &pill, icxOT_Shaw_Fairchild_2,
634 			                       NULL, icSigLabData, 1)) == NULL)
635 				error ("Creating conversion failed");
636 
637 			if ((scon = new_xsp2cie(icxIT_custom, &pill, icxOT_Shaw_Fairchild_2,
638 			                       NULL, icSigLabData, 1)) == NULL)
639 				error ("Creating conversion failed");
640 
641 			/* Tell the secondary conversion to allow for instrument illuminant */
642 			if (scon->set_fwa(scon, &sill, NULL, &matilum[m][ss].white))
643 				error ("Setting FWA compensation failed");
644 
645 			printf("Primary (Target/Check) '%s', Secondary (Instrument)'%s'\n",
646 			matilum[m][ps].illum, matilum[m][ss].illum);
647 
648 			/* For each test patch */
649 			for (pn = 0; pn < 6; pn++) {
650 				int i, j;
651 				double plab[3];
652 				double slab[3];
653 				double sclab[3];
654 				xspect psp;			/* Reference spectrum */
655 				xspect ssp;			/* un-compensated spectrum */
656 				xspect scsp;		/* Compensated spectrum */
657 				double de, cde;
658 #ifdef DOPLOT
659 #define	XRES 400
660 				double xx[XRES];
661 				double y1[XRES];
662 				double y2[XRES];
663 				double y3[XRES];
664 #endif /* DOPLOT */
665 
666 
667 				/* Compute reference value for target illuminant */
668 				pcon->sconvert(pcon, &psp, plab, &matilum[m][ps].patches[pn].s);
669 
670 				/* Compute uncompensated value for target illuminant */
671 				pcon->sconvert(pcon, &ssp, slab, &matilum[m][ss].patches[pn].s);
672 
673 				/* Compute compensated value for target illuminant */
674 				scon->sconvert(scon, &scsp, sclab, &matilum[m][ss].patches[pn].s);
675 
676 				de = 0.0;
677 				for (j = 0; j < 3; j++) {
678 					double tt = plab[j] - slab[j];
679 					de += tt * tt;
680 				}
681 				de = sqrt(de);
682 
683 				printf("Patch '%s', Ref %f %f %f,  Other %f %f %f DE %f\n",
684 				matilum[m][ps].patches[pn].pdesc, plab[0], plab[1], plab[2],
685 				slab[0], slab[1], slab[2], de);
686 
687 				cde = 0.0;
688 				for (j = 0; j < 3; j++) {
689 					double tt = plab[j] - sclab[j];
690 					cde += tt * tt;
691 				}
692 				cde = sqrt(cde);
693 
694 				printf("Patch '%s', Ref %f %f %f, COther %f %f %f DE %f\n",
695 				matilum[m][ps].patches[pn].pdesc, plab[0], plab[1], plab[2],
696 				sclab[0], sclab[1], sclab[2], cde);
697 				printf("DE change %f\n",cde - de);
698 				printf("\n");
699 
700 #ifdef DOPLOT
701 				for (i = 0; i < psp.spec_n; i++) {
702 					double ww;
703 
704 					ww = (psp.spec_wl_long - psp.spec_wl_short)
705 					   * ((double)i/(psp.spec_n-1.0)) + psp.spec_wl_short;
706 
707 					xx[i] = ww;
708 					y1[i] = ssp.spec[i];	/* Black - Input */
709 					y2[i] = scsp.spec[i];	/* Red - Estimate */
710 					y3[i] = psp.spec[i];	/* Green - Target */
711 				}
712 				do_plot(xx,y1,y2,y3,i);
713 #endif /* DOPLOT */
714 #ifdef DATAFILE
715 				fprintf(df,"\nPrimary (Target/Check) '%s', Secondary (Instrument)'%s'\n",
716 				        matilum[m][ps].illum, matilum[m][ss].illum);
717 				fprintf(df,"Patch '%s', Ref %f %f %f,  Other %f %f %f DE %f\n",
718 				        matilum[m][ps].patches[pn].pdesc, plab[0], plab[1], plab[2],
719 				        slab[0], slab[1], slab[2], de);
720 				fprintf(df,"Patch '%s', Ref %f %f %f, COther %f %f %f DE %f\n",
721 				        matilum[m][ps].patches[pn].pdesc, plab[0], plab[1], plab[2],
722 				        sclab[0], sclab[1], sclab[2], cde);
723 				fprintf(df,"NM	Ref.	Un-comp.	Comp.\n");
724 				for (i = 0; i < psp.spec_n; i++) {
725 					double ww;
726 
727 					ww = (psp.spec_wl_long - psp.spec_wl_short)
728 					   * ((double)i/(psp.spec_n-1.0)) + psp.spec_wl_short;
729 
730 					fprintf(df,"%d	%f	%f	%f\n",((int)ww), psp.spec[i], ssp.spec[i], scsp.spec[i]);
731 				}
732 #endif /* DATAFILE */
733 			}
734 			pcon->del(pcon);
735 			scon->del(scon);
736 		}
737 	}
738 #ifdef DATAFILE
739 	fclose(df);
740 #endif
741 
742 	return 0;
743 }
744 
745 
746 
747 
748 
749 
750 
751 
752