1 //
2 // Little cms
3 // Copyright (C) 1998-2007 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 // Version 1.19
24
25 #ifndef __cms_H
26
27 // ********** Configuration toggles ****************************************
28
29 // Optimization mode.
30 //
31 // Note that USE_ASSEMBLER Is fastest by far, but it is limited to Pentium.
32 // USE_FLOAT are the generic floating-point routines. USE_C should work on
33 // virtually any machine.
34
35 //#define USE_FLOAT 1
36 // #define USE_C 1
37 #define USE_ASSEMBLER 1
38
39 // Define this if you are using this package as a DLL (windows only)
40
41 // #define LCMS_DLL 1
42 // #define LCMS_DLL_BUILD 1
43
44 // Uncomment if you are trying the engine in a non-windows environment
45 // like linux, SGI, VAX, FreeBSD, BeOS, etc.
46 #define NON_WINDOWS 1
47
48 // Uncomment this one if you are using big endian machines (only meaningful
49 // when NON_WINDOWS is used)
50 // #define USE_BIG_ENDIAN 1
51
52 // Uncomment this one if your compiler/machine does support the
53 // "long long" type This will speedup fixed point math. (USE_C only)
54 #define USE_INT64 1
55
56 // Some machines does not have a reliable 'swab' function. Usually
57 // leave commented unless the testbed diagnoses the contrary.
58 // #define USE_CUSTOM_SWAB 1
59
60 // Uncomment this if your compiler supports inline
61 #define USE_INLINE 1
62
63 // Uncomment this if your compiler doesn't work with fast floor function
64 // #define USE_DEFAULT_FLOOR_CONVERSION 1
65
66 // Uncomment this line on multithreading environments
67 // #define USE_PTHREADS 1
68
69 // Uncomment this line if you want lcms to use the black point tag in profile,
70 // if commented, lcms will compute the black point by its own.
71 // It is safer to leve it commented out
72 // #define HONOR_BLACK_POINT_TAG 1
73
74 // ********** End of configuration toggles ******************************
75
76 #define LCMS_VERSION 119
77
78 // Microsoft VisualC++
79
80 // Deal with Microsoft's attempt at deprecating C standard runtime functions
81 #ifdef _MSC_VER
82 # undef NON_WINDOWS
83 # if (_MSC_VER >= 1400)
84 # ifndef _CRT_SECURE_NO_DEPRECATE
85 # define _CRT_SECURE_NO_DEPRECATE 1
86 # endif
87 # endif
88 #endif
89
90 // Borland C
91
92 #ifdef __BORLANDC__
93 # undef NON_WINDOWS
94 #endif
95
96 #include <stdio.h>
97 #include <stdlib.h>
98 #include <math.h>
99 #include <assert.h>
100 #include <stdarg.h>
101 #include <time.h>
102
103 // Metroworks CodeWarrior
104 #ifdef __MWERKS__
105 # define unlink remove
106 # if WIN32
107 # define USE_CUSTOM_SWAB 1
108 # undef NON_WINDOWS
109 # else
110 # define NON_WINDOWS 1
111 # endif
112 #endif
113
114
115 // Here comes the Non-Windows settings
116
117 #ifdef NON_WINDOWS
118
119 // Non windows environments. Also avoid indentation on includes.
120
121 #ifdef USE_PTHREADS
122 # include <pthread.h>
123 typedef pthread_rwlock_t LCMS_RWLOCK_T;
124 # define LCMS_CREATE_LOCK(x) pthread_rwlock_init((x), NULL)
125 # define LCMS_FREE_LOCK(x) pthread_rwlock_destroy((x))
126 # define LCMS_READ_LOCK(x) pthread_rwlock_rdlock((x))
127 # define LCMS_WRITE_LOCK(x) pthread_rwlock_wrlock((x))
128 # define LCMS_UNLOCK(x) pthread_rwlock_unlock((x))
129 #endif
130
131 #undef LCMS_DLL
132
133 #ifdef USE_ASSEMBLER
134 # undef USE_ASSEMBLER
135 # define USE_C 1
136 #endif
137
138 #ifdef _HOST_BIG_ENDIAN
139 # define USE_BIG_ENDIAN 1
140 #endif
141
142 #if defined(__sgi__) || defined(__sgi) || defined(__powerpc__) || defined(sparc) || defined(__ppc__) || defined(__s390__) || defined(__s390x__)
143 # define USE_BIG_ENDIAN 1
144 #endif
145
146 #if TARGET_CPU_PPC
147 # define USE_BIG_ENDIAN 1
148 #endif
149
150 #if macintosh
151 # ifndef __LITTLE_ENDIAN__
152 # define USE_BIG_ENDIAN 1
153 # endif
154 #endif
155
156 #ifdef __BIG_ENDIAN__
157 # define USE_BIG_ENDIAN 1
158 #endif
159
160 #ifdef WORDS_BIGENDIAN
161 # define USE_BIG_ENDIAN 1
162 #endif
163
164 #if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)
165 # include <sys/types.h>
166 # define USE_INT64 1
167 # define LCMSSLONGLONG int64_t
168 # define LCMSULONGLONG u_int64_t
169 #endif
170
171 #ifdef USE_INT64
172 # ifndef LCMSULONGLONG
173 # define LCMSULONGLONG unsigned long long
174 # define LCMSSLONGLONG long long
175 # endif
176 #endif
177
178 #if !defined(__INTEGRITY)
179 # include <memory.h>
180 #endif
181
182 #include <string.h>
183
184 #if defined(__GNUC__) || defined(__FreeBSD__)
185 # include <unistd.h>
186 #endif
187
188 #ifndef LCMS_WIN_TYPES_ALREADY_DEFINED
189
190 typedef unsigned char BYTE, *LPBYTE;
191 typedef unsigned short WORD, *LPWORD;
192 typedef unsigned long DWORD, *LPDWORD;
193 typedef char *LPSTR;
194 typedef void *LPVOID;
195
196 #define ZeroMemory(p,l) memset((p),0,(l))
197 #define CopyMemory(d,s,l) memcpy((d),(s),(l))
198 #define FAR
199
200 #ifndef stricmp
201 # define stricmp strcasecmp
202 #endif
203
204
205 #ifndef FALSE
206 # define FALSE 0
207 #endif
208 #ifndef TRUE
209 # define TRUE 1
210 #endif
211
212 #define LOWORD(l) ((WORD)(l))
213 #define HIWORD(l) ((WORD)((DWORD)(l) >> 16))
214
215 #ifndef MAX_PATH
216 # define MAX_PATH (256)
217 #endif
218
219 #define cdecl
220 #endif
221
222 // The specification for "inline" is section 6.7.4 of the C99 standard (ISO/IEC 9899:1999).
223
224 #define LCMS_INLINE static inline
225
226 #else
227
228 // Win32 stuff
229
230 #ifndef WIN32_LEAN_AND_MEAN
231 # define WIN32_LEAN_AND_MEAN
232 #endif
233
234 #include <windows.h>
235
236 #ifdef _WIN64
237 # ifdef USE_ASSEMBLER
238 # undef USE_ASSEMBLER
239 # define USE_C 1
240 # endif
241 #endif
242
243 #ifdef USE_INT64
244 # ifndef LCMSULONGLONG
245 # define LCMSULONGLONG unsigned __int64
246 # define LCMSSLONGLONG __int64
247 # endif
248 #endif
249
250 // This works for both VC & BorlandC
251 #define LCMS_INLINE __inline
252
253 #ifdef USE_PTHREADS
254 typedef CRITICAL_SECTION LCMS_RWLOCK_T;
255 # define LCMS_CREATE_LOCK(x) InitializeCriticalSection((x))
256 # define LCMS_FREE_LOCK(x) DeleteCriticalSection((x))
257 # define LCMS_READ_LOCK(x) EnterCriticalSection((x))
258 # define LCMS_WRITE_LOCK(x) EnterCriticalSection((x))
259 # define LCMS_UNLOCK(x) LeaveCriticalSection((x))
260 #endif
261
262 #endif
263
264 #ifndef USE_PTHREADS
265 typedef int LCMS_RWLOCK_T;
266 # define LCMS_CREATE_LOCK(x)
267 # define LCMS_FREE_LOCK(x)
268 # define LCMS_READ_LOCK(x)
269 # define LCMS_WRITE_LOCK(x)
270 # define LCMS_UNLOCK(x)
271 #endif
272
273 // Base types
274
275 typedef int LCMSBOOL;
276 typedef void* LCMSHANDLE;
277
278 #include "icc34.h" // ICC header file
279
280
281 // Some tag & type additions
282
283 #define lcmsSignature ((icSignature) 0x6c636d73L)
284
285 #define icSigLuvKData ((icColorSpaceSignature) 0x4C75764BL) // 'LuvK'
286
287 #define icSigHexachromeData ((icColorSpaceSignature) 0x4d434836L) // MCH6
288 #define icSigHeptachromeData ((icColorSpaceSignature) 0x4d434837L) // MCH7
289 #define icSigOctachromeData ((icColorSpaceSignature) 0x4d434838L) // MCH8
290
291 #define icSigMCH5Data ((icColorSpaceSignature) 0x4d434835L) // MCH5
292 #define icSigMCH6Data ((icColorSpaceSignature) 0x4d434836L) // MCH6
293 #define icSigMCH7Data ((icColorSpaceSignature) 0x4d434837L) // MCH7
294 #define icSigMCH8Data ((icColorSpaceSignature) 0x4d434838L) // MCH8
295 #define icSigMCH9Data ((icColorSpaceSignature) 0x4d434839L) // MCH9
296 #define icSigMCHAData ((icColorSpaceSignature) 0x4d434841L) // MCHA
297 #define icSigMCHBData ((icColorSpaceSignature) 0x4d434842L) // MCHB
298 #define icSigMCHCData ((icColorSpaceSignature) 0x4d434843L) // MCHC
299 #define icSigMCHDData ((icColorSpaceSignature) 0x4d434844L) // MCHD
300 #define icSigMCHEData ((icColorSpaceSignature) 0x4d434845L) // MCHE
301 #define icSigMCHFData ((icColorSpaceSignature) 0x4d434846L) // MCHF
302
303 #define icSigChromaticityTag ((icTagSignature) 0x6368726dL) // As per Addendum 2 to Spec. ICC.1:1998-09
304 #define icSigChromaticAdaptationTag ((icTagSignature) 0x63686164L) // 'chad'
305 #define icSigColorantTableTag ((icTagSignature) 0x636c7274L) // 'clrt'
306 #define icSigColorantTableOutTag ((icTagSignature) 0x636c6f74L) // 'clot'
307
308 #define icSigParametricCurveType ((icTagTypeSignature) 0x70617261L) // parametric (ICC 4.0)
309 #define icSigMultiLocalizedUnicodeType ((icTagTypeSignature) 0x6D6C7563L)
310 #define icSigS15Fixed16ArrayType ((icTagTypeSignature) 0x73663332L)
311 #define icSigChromaticityType ((icTagTypeSignature) 0x6368726dL)
312 #define icSiglutAtoBType ((icTagTypeSignature) 0x6d414220L) // mAB
313 #define icSiglutBtoAType ((icTagTypeSignature) 0x6d424120L) // mBA
314 #define icSigColorantTableType ((icTagTypeSignature) 0x636c7274L) // clrt
315
316
317 typedef struct {
318 icUInt8Number gridPoints[16]; // Number of grid points in each dimension.
319 icUInt8Number prec; // Precision of data elements in bytes.
320 icUInt8Number pad1;
321 icUInt8Number pad2;
322 icUInt8Number pad3;
323 /*icUInt8Number data[icAny]; Data follows see spec for size */
324 } icCLutStruct;
325
326 // icLutAtoB
327 typedef struct {
328 icUInt8Number inputChan; // Number of input channels
329 icUInt8Number outputChan; // Number of output channels
330 icUInt8Number pad1;
331 icUInt8Number pad2;
332 icUInt32Number offsetB; // Offset to first "B" curve
333 icUInt32Number offsetMat; // Offset to matrix
334 icUInt32Number offsetM; // Offset to first "M" curve
335 icUInt32Number offsetC; // Offset to CLUT
336 icUInt32Number offsetA; // Offset to first "A" curve
337 /*icUInt8Number data[icAny]; Data follows see spec for size */
338 } icLutAtoB;
339
340 // icLutBtoA
341 typedef struct {
342 icUInt8Number inputChan; // Number of input channels
343 icUInt8Number outputChan; // Number of output channels
344 icUInt8Number pad1;
345 icUInt8Number pad2;
346 icUInt32Number offsetB; // Offset to first "B" curve
347 icUInt32Number offsetMat; // Offset to matrix
348 icUInt32Number offsetM; // Offset to first "M" curve
349 icUInt32Number offsetC; // Offset to CLUT
350 icUInt32Number offsetA; // Offset to first "A" curve
351 /*icUInt8Number data[icAny]; Data follows see spec for size */
352 } icLutBtoA;
353
354
355
356
357
358 #ifdef __cplusplus
359 extern "C" {
360 #endif
361
362 // Calling convention
363
364 #ifdef NON_WINDOWS
365 # define LCMSEXPORT
366 # define LCMSAPI
367 #else
368 # ifdef LCMS_DLL
369 # ifdef __BORLANDC__
370 # define LCMSEXPORT __stdcall _export
371 # define LCMSAPI
372 # else
373 // VC++
374 # define LCMSEXPORT _stdcall
375 # ifdef LCMS_DLL_BUILD
376 # define LCMSAPI __declspec(dllexport)
377 # else
378 # define LCMSAPI __declspec(dllimport)
379 # endif
380 # endif
381 # else
382 # define LCMSEXPORT cdecl
383 # define LCMSAPI
384 # endif
385 #endif
386
387 #ifdef USE_ASSEMBLER
388 #ifdef __BORLANDC__
389
390 # define ASM asm
391 # define RET(v) return(v)
392 #else
393 // VC++
394 # define ASM __asm
395 # define RET(v) return
396 #endif
397 #endif
398
399 #ifdef _MSC_VER
400 #ifndef stricmp
401 # define stricmp _stricmp
402 #endif
403 #ifndef unlink
404 # define unlink _unlink
405 #endif
406 #ifndef swab
407 # define swab _swab
408 #endif
409 #ifndef itoa
410 # define itoa _itoa
411 #endif
412 #ifndef fileno
413 # define fileno _fileno
414 #endif
415 #ifndef strupr
416 # define strupr _strupr
417 #endif
418 #ifndef hypot
419 # define hypot _hypot
420 #endif
421 #ifndef snprintf
422 # define snprintf _snprintf
423 #endif
424 #ifndef vsnprintf
425 # define vsnprintf _vsnprintf
426 #endif
427
428
429 #endif
430
431
432 #ifndef M_PI
433 # define M_PI 3.14159265358979323846
434 #endif
435
436 #ifndef LOGE
437 # define LOGE 0.4342944819
438 #endif
439
440 // ********** Little cms API ***************************************************
441
442 typedef LCMSHANDLE cmsHPROFILE; // Opaque typedefs to hide internals
443 typedef LCMSHANDLE cmsHTRANSFORM;
444
445 #define MAXCHANNELS 16 // Maximum number of channels
446
447 // Format of pixel is defined by one DWORD, using bit fields as follows
448 //
449 // D TTTTT U Y F P X S EEE CCCC BBB
450 //
451 // D: Use dither (8 bits only)
452 // T: Pixeltype
453 // F: Flavor 0=MinIsBlack(Chocolate) 1=MinIsWhite(Vanilla)
454 // P: Planar? 0=Chunky, 1=Planar
455 // X: swap 16 bps endianess?
456 // S: Do swap? ie, BGR, KYMC
457 // E: Extra samples
458 // C: Channels (Samples per pixel)
459 // B: Bytes per sample
460 // Y: Swap first - changes ABGR to BGRA and KCMY to CMYK
461
462
463 #define DITHER_SH(s) ((s) << 22)
464 #define COLORSPACE_SH(s) ((s) << 16)
465 #define SWAPFIRST_SH(s) ((s) << 14)
466 #define FLAVOR_SH(s) ((s) << 13)
467 #define PLANAR_SH(p) ((p) << 12)
468 #define ENDIAN16_SH(e) ((e) << 11)
469 #define DOSWAP_SH(e) ((e) << 10)
470 #define EXTRA_SH(e) ((e) << 7)
471 #define CHANNELS_SH(c) ((c) << 3)
472 #define BYTES_SH(b) (b)
473
474 // Pixel types
475
476 #define PT_ANY 0 // Don't check colorspace
477 // 1 & 2 are reserved
478 #define PT_GRAY 3
479 #define PT_RGB 4
480 #define PT_CMY 5
481 #define PT_CMYK 6
482 #define PT_YCbCr 7
483 #define PT_YUV 8 // Lu'v'
484 #define PT_XYZ 9
485 #define PT_Lab 10
486 #define PT_YUVK 11 // Lu'v'K
487 #define PT_HSV 12
488 #define PT_HLS 13
489 #define PT_Yxy 14
490 #define PT_HiFi 15
491 #define PT_HiFi7 16
492 #define PT_HiFi8 17
493 #define PT_HiFi9 18
494 #define PT_HiFi10 19
495 #define PT_HiFi11 20
496 #define PT_HiFi12 21
497 #define PT_HiFi13 22
498 #define PT_HiFi14 23
499 #define PT_HiFi15 24
500
501 #define NOCOLORSPACECHECK(x) ((x) & 0xFFFF)
502
503 // Some (not all!) representations
504
505 #ifndef TYPE_RGB_8 // TYPE_RGB_8 is a very common identifier, so don't include ours
506 // if user has it already defined.
507
508 #define TYPE_GRAY_8 (COLORSPACE_SH(PT_GRAY)|CHANNELS_SH(1)|BYTES_SH(1))
509 #define TYPE_GRAY_8_REV (COLORSPACE_SH(PT_GRAY)|CHANNELS_SH(1)|BYTES_SH(1)|FLAVOR_SH(1))
510 #define TYPE_GRAY_16 (COLORSPACE_SH(PT_GRAY)|CHANNELS_SH(1)|BYTES_SH(2))
511 #define TYPE_GRAY_16_REV (COLORSPACE_SH(PT_GRAY)|CHANNELS_SH(1)|BYTES_SH(2)|FLAVOR_SH(1))
512 #define TYPE_GRAY_16_SE (COLORSPACE_SH(PT_GRAY)|CHANNELS_SH(1)|BYTES_SH(2)|ENDIAN16_SH(1))
513 #define TYPE_GRAYA_8 (COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|BYTES_SH(1))
514 #define TYPE_GRAYA_16 (COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|BYTES_SH(2))
515 #define TYPE_GRAYA_16_SE (COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|BYTES_SH(2)|ENDIAN16_SH(1))
516 #define TYPE_GRAYA_8_PLANAR (COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|BYTES_SH(1)|PLANAR_SH(1))
517 #define TYPE_GRAYA_16_PLANAR (COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|BYTES_SH(2)|PLANAR_SH(1))
518
519 #define TYPE_RGB_8 (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(1))
520 #define TYPE_RGB_8_PLANAR (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(1)|PLANAR_SH(1))
521 #define TYPE_BGR_8 (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(1)|DOSWAP_SH(1))
522 #define TYPE_BGR_8_PLANAR (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(1)|DOSWAP_SH(1)|PLANAR_SH(1))
523 #define TYPE_RGB_16 (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(2))
524 #define TYPE_RGB_16_PLANAR (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(2)|PLANAR_SH(1))
525 #define TYPE_RGB_16_SE (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(2)|ENDIAN16_SH(1))
526 #define TYPE_BGR_16 (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1))
527 #define TYPE_BGR_16_PLANAR (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1)|PLANAR_SH(1))
528 #define TYPE_BGR_16_SE (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1))
529
530 #define TYPE_RGBA_8 (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(1))
531 #define TYPE_RGBA_8_PLANAR (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(1)|PLANAR_SH(1))
532 #define TYPE_RGBA_16 (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2))
533 #define TYPE_RGBA_16_PLANAR (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|PLANAR_SH(1))
534 #define TYPE_RGBA_16_SE (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|ENDIAN16_SH(1))
535
536 #define TYPE_ARGB_8 (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(1)|SWAPFIRST_SH(1))
537 #define TYPE_ARGB_16 (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|SWAPFIRST_SH(1))
538
539 #define TYPE_ABGR_8 (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(1)|DOSWAP_SH(1))
540 #define TYPE_ABGR_16 (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1))
541 #define TYPE_ABGR_16_PLANAR (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1)|PLANAR_SH(1))
542 #define TYPE_ABGR_16_SE (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1))
543
544 #define TYPE_BGRA_8 (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(1)|DOSWAP_SH(1)|SWAPFIRST_SH(1))
545 #define TYPE_BGRA_16 (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1)|SWAPFIRST_SH(1))
546 #define TYPE_BGRA_16_SE (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|ENDIAN16_SH(1)|SWAPFIRST_SH(1))
547
548 #define TYPE_CMY_8 (COLORSPACE_SH(PT_CMY)|CHANNELS_SH(3)|BYTES_SH(1))
549 #define TYPE_CMY_8_PLANAR (COLORSPACE_SH(PT_CMY)|CHANNELS_SH(3)|BYTES_SH(1)|PLANAR_SH(1))
550 #define TYPE_CMY_16 (COLORSPACE_SH(PT_CMY)|CHANNELS_SH(3)|BYTES_SH(2))
551 #define TYPE_CMY_16_PLANAR (COLORSPACE_SH(PT_CMY)|CHANNELS_SH(3)|BYTES_SH(2)|PLANAR_SH(1))
552 #define TYPE_CMY_16_SE (COLORSPACE_SH(PT_CMY)|CHANNELS_SH(3)|BYTES_SH(2)|ENDIAN16_SH(1))
553
554 #define TYPE_CMYK_8 (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(1))
555 #define TYPE_CMYKA_8 (COLORSPACE_SH(PT_CMYK)|EXTRA_SH(1)|CHANNELS_SH(4)|BYTES_SH(1))
556 #define TYPE_CMYK_8_REV (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(1)|FLAVOR_SH(1))
557 #define TYPE_YUVK_8 TYPE_CMYK_8_REV
558 #define TYPE_CMYK_8_PLANAR (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(1)|PLANAR_SH(1))
559 #define TYPE_CMYK_16 (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2))
560 #define TYPE_CMYK_16_REV (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|FLAVOR_SH(1))
561 #define TYPE_YUVK_16 TYPE_CMYK_16_REV
562 #define TYPE_CMYK_16_PLANAR (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|PLANAR_SH(1))
563 #define TYPE_CMYK_16_SE (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|ENDIAN16_SH(1))
564
565 #define TYPE_KYMC_8 (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(1)|DOSWAP_SH(1))
566 #define TYPE_KYMC_16 (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|DOSWAP_SH(1))
567 #define TYPE_KYMC_16_SE (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1))
568
569 #define TYPE_KCMY_8 (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(1)|SWAPFIRST_SH(1))
570 #define TYPE_KCMY_8_REV (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(1)|FLAVOR_SH(1)|SWAPFIRST_SH(1))
571 #define TYPE_KCMY_16 (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|SWAPFIRST_SH(1))
572 #define TYPE_KCMY_16_REV (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|FLAVOR_SH(1)|SWAPFIRST_SH(1))
573 #define TYPE_KCMY_16_SE (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|ENDIAN16_SH(1)|SWAPFIRST_SH(1))
574
575
576 // HiFi separations, Thanks to Steven Greaves for providing the code,
577 // the colorspace is not checked
578 #define TYPE_CMYK5_8 (CHANNELS_SH(5)|BYTES_SH(1))
579 #define TYPE_CMYK5_16 (CHANNELS_SH(5)|BYTES_SH(2))
580 #define TYPE_CMYK5_16_SE (CHANNELS_SH(5)|BYTES_SH(2)|ENDIAN16_SH(1))
581 #define TYPE_KYMC5_8 (CHANNELS_SH(5)|BYTES_SH(1)|DOSWAP_SH(1))
582 #define TYPE_KYMC5_16 (CHANNELS_SH(5)|BYTES_SH(2)|DOSWAP_SH(1))
583 #define TYPE_KYMC5_16_SE (CHANNELS_SH(5)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1))
584
585 #define TYPE_CMYKcm_8 (CHANNELS_SH(6)|BYTES_SH(1))
586 #define TYPE_CMYKcm_8_PLANAR (CHANNELS_SH(6)|BYTES_SH(1)|PLANAR_SH(1))
587 #define TYPE_CMYKcm_16 (CHANNELS_SH(6)|BYTES_SH(2))
588 #define TYPE_CMYKcm_16_PLANAR (CHANNELS_SH(6)|BYTES_SH(2)|PLANAR_SH(1))
589 #define TYPE_CMYKcm_16_SE (CHANNELS_SH(6)|BYTES_SH(2)|ENDIAN16_SH(1))
590
591 // Separations with more than 6 channels aren't very standarized,
592 // Except most start with CMYK and add other colors, so I just used
593 // then total number of channels after CMYK i.e CMYK8_8
594
595 #define TYPE_CMYK7_8 (CHANNELS_SH(7)|BYTES_SH(1))
596 #define TYPE_CMYK7_16 (CHANNELS_SH(7)|BYTES_SH(2))
597 #define TYPE_CMYK7_16_SE (CHANNELS_SH(7)|BYTES_SH(2)|ENDIAN16_SH(1))
598 #define TYPE_KYMC7_8 (CHANNELS_SH(7)|BYTES_SH(1)|DOSWAP_SH(1))
599 #define TYPE_KYMC7_16 (CHANNELS_SH(7)|BYTES_SH(2)|DOSWAP_SH(1))
600 #define TYPE_KYMC7_16_SE (CHANNELS_SH(7)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1))
601 #define TYPE_CMYK8_8 (CHANNELS_SH(8)|BYTES_SH(1))
602 #define TYPE_CMYK8_16 (CHANNELS_SH(8)|BYTES_SH(2))
603 #define TYPE_CMYK8_16_SE (CHANNELS_SH(8)|BYTES_SH(2)|ENDIAN16_SH(1))
604 #define TYPE_KYMC8_8 (CHANNELS_SH(8)|BYTES_SH(1)|DOSWAP_SH(1))
605 #define TYPE_KYMC8_16 (CHANNELS_SH(8)|BYTES_SH(2)|DOSWAP_SH(1))
606 #define TYPE_KYMC8_16_SE (CHANNELS_SH(8)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1))
607 #define TYPE_CMYK9_8 (CHANNELS_SH(9)|BYTES_SH(1))
608 #define TYPE_CMYK9_16 (CHANNELS_SH(9)|BYTES_SH(2))
609 #define TYPE_CMYK9_16_SE (CHANNELS_SH(9)|BYTES_SH(2)|ENDIAN16_SH(1))
610 #define TYPE_KYMC9_8 (CHANNELS_SH(9)|BYTES_SH(1)|DOSWAP_SH(1))
611 #define TYPE_KYMC9_16 (CHANNELS_SH(9)|BYTES_SH(2)|DOSWAP_SH(1))
612 #define TYPE_KYMC9_16_SE (CHANNELS_SH(9)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1))
613 #define TYPE_CMYK10_8 (CHANNELS_SH(10)|BYTES_SH(1))
614 #define TYPE_CMYK10_16 (CHANNELS_SH(10)|BYTES_SH(2))
615 #define TYPE_CMYK10_16_SE (CHANNELS_SH(10)|BYTES_SH(2)|ENDIAN16_SH(1))
616 #define TYPE_KYMC10_8 (CHANNELS_SH(10)|BYTES_SH(1)|DOSWAP_SH(1))
617 #define TYPE_KYMC10_16 (CHANNELS_SH(10)|BYTES_SH(2)|DOSWAP_SH(1))
618 #define TYPE_KYMC10_16_SE (CHANNELS_SH(10)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1))
619 #define TYPE_CMYK11_8 (CHANNELS_SH(11)|BYTES_SH(1))
620 #define TYPE_CMYK11_16 (CHANNELS_SH(11)|BYTES_SH(2))
621 #define TYPE_CMYK11_16_SE (CHANNELS_SH(11)|BYTES_SH(2)|ENDIAN16_SH(1))
622 #define TYPE_KYMC11_8 (CHANNELS_SH(11)|BYTES_SH(1)|DOSWAP_SH(1))
623 #define TYPE_KYMC11_16 (CHANNELS_SH(11)|BYTES_SH(2)|DOSWAP_SH(1))
624 #define TYPE_KYMC11_16_SE (CHANNELS_SH(11)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1))
625 #define TYPE_CMYK12_8 (CHANNELS_SH(12)|BYTES_SH(1))
626 #define TYPE_CMYK12_16 (CHANNELS_SH(12)|BYTES_SH(2))
627 #define TYPE_CMYK12_16_SE (CHANNELS_SH(12)|BYTES_SH(2)|ENDIAN16_SH(1))
628 #define TYPE_KYMC12_8 (CHANNELS_SH(12)|BYTES_SH(1)|DOSWAP_SH(1))
629 #define TYPE_KYMC12_16 (CHANNELS_SH(12)|BYTES_SH(2)|DOSWAP_SH(1))
630 #define TYPE_KYMC12_16_SE (CHANNELS_SH(12)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1))
631
632 // Colorimetric
633
634 #define TYPE_XYZ_16 (COLORSPACE_SH(PT_XYZ)|CHANNELS_SH(3)|BYTES_SH(2))
635 #define TYPE_Lab_8 (COLORSPACE_SH(PT_Lab)|CHANNELS_SH(3)|BYTES_SH(1))
636 #define TYPE_ALab_8 (COLORSPACE_SH(PT_Lab)|CHANNELS_SH(3)|BYTES_SH(1)|EXTRA_SH(1)|DOSWAP_SH(1))
637 #define TYPE_Lab_16 (COLORSPACE_SH(PT_Lab)|CHANNELS_SH(3)|BYTES_SH(2))
638 #define TYPE_Yxy_16 (COLORSPACE_SH(PT_Yxy)|CHANNELS_SH(3)|BYTES_SH(2))
639
640 // YCbCr
641
642 #define TYPE_YCbCr_8 (COLORSPACE_SH(PT_YCbCr)|CHANNELS_SH(3)|BYTES_SH(1))
643 #define TYPE_YCbCr_8_PLANAR (COLORSPACE_SH(PT_YCbCr)|CHANNELS_SH(3)|BYTES_SH(1)|PLANAR_SH(1))
644 #define TYPE_YCbCr_16 (COLORSPACE_SH(PT_YCbCr)|CHANNELS_SH(3)|BYTES_SH(2))
645 #define TYPE_YCbCr_16_PLANAR (COLORSPACE_SH(PT_YCbCr)|CHANNELS_SH(3)|BYTES_SH(2)|PLANAR_SH(1))
646 #define TYPE_YCbCr_16_SE (COLORSPACE_SH(PT_YCbCr)|CHANNELS_SH(3)|BYTES_SH(2)|ENDIAN16_SH(1))
647
648 // YUV
649
650 #define TYPE_YUV_8 (COLORSPACE_SH(PT_YUV)|CHANNELS_SH(3)|BYTES_SH(1))
651 #define TYPE_YUV_8_PLANAR (COLORSPACE_SH(PT_YUV)|CHANNELS_SH(3)|BYTES_SH(1)|PLANAR_SH(1))
652 #define TYPE_YUV_16 (COLORSPACE_SH(PT_YUV)|CHANNELS_SH(3)|BYTES_SH(2))
653 #define TYPE_YUV_16_PLANAR (COLORSPACE_SH(PT_YUV)|CHANNELS_SH(3)|BYTES_SH(2)|PLANAR_SH(1))
654 #define TYPE_YUV_16_SE (COLORSPACE_SH(PT_YUV)|CHANNELS_SH(3)|BYTES_SH(2)|ENDIAN16_SH(1))
655
656 // HLS
657
658 #define TYPE_HLS_8 (COLORSPACE_SH(PT_HLS)|CHANNELS_SH(3)|BYTES_SH(1))
659 #define TYPE_HLS_8_PLANAR (COLORSPACE_SH(PT_HLS)|CHANNELS_SH(3)|BYTES_SH(1)|PLANAR_SH(1))
660 #define TYPE_HLS_16 (COLORSPACE_SH(PT_HLS)|CHANNELS_SH(3)|BYTES_SH(2))
661 #define TYPE_HLS_16_PLANAR (COLORSPACE_SH(PT_HLS)|CHANNELS_SH(3)|BYTES_SH(2)|PLANAR_SH(1))
662 #define TYPE_HLS_16_SE (COLORSPACE_SH(PT_HLS)|CHANNELS_SH(3)|BYTES_SH(2)|ENDIAN16_SH(1))
663
664
665 // HSV
666
667 #define TYPE_HSV_8 (COLORSPACE_SH(PT_HSV)|CHANNELS_SH(3)|BYTES_SH(1))
668 #define TYPE_HSV_8_PLANAR (COLORSPACE_SH(PT_HSV)|CHANNELS_SH(3)|BYTES_SH(1)|PLANAR_SH(1))
669 #define TYPE_HSV_16 (COLORSPACE_SH(PT_HSV)|CHANNELS_SH(3)|BYTES_SH(2))
670 #define TYPE_HSV_16_PLANAR (COLORSPACE_SH(PT_HSV)|CHANNELS_SH(3)|BYTES_SH(2)|PLANAR_SH(1))
671 #define TYPE_HSV_16_SE (COLORSPACE_SH(PT_HSV)|CHANNELS_SH(3)|BYTES_SH(2)|ENDIAN16_SH(1))
672
673 // Named color index. Only 16 bits allowed (don't check colorspace)
674
675 #define TYPE_NAMED_COLOR_INDEX (CHANNELS_SH(1)|BYTES_SH(2))
676
677 // Double values. Painful slow, but sometimes helpful. NOTE THAT 'BYTES' FIELD IS SET TO ZERO!
678
679 #define TYPE_XYZ_DBL (COLORSPACE_SH(PT_XYZ)|CHANNELS_SH(3)|BYTES_SH(0))
680 #define TYPE_Lab_DBL (COLORSPACE_SH(PT_Lab)|CHANNELS_SH(3)|BYTES_SH(0))
681 #define TYPE_GRAY_DBL (COLORSPACE_SH(PT_GRAY)|CHANNELS_SH(1)|BYTES_SH(0))
682 #define TYPE_RGB_DBL (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(0))
683 #define TYPE_CMYK_DBL (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(0))
684
685 #endif
686
687
688 // Gamma table parameters
689
690 typedef struct {
691
692 unsigned int Crc32; // Has my table been touched?
693
694 // Keep initial parameters for further serialization
695
696 int Type;
697 double Params[10];
698
699 } LCMSGAMMAPARAMS, FAR* LPLCMSGAMMAPARAMS;
700
701 // Gamma tables.
702
703 typedef struct {
704
705 LCMSGAMMAPARAMS Seed; // Parameters used for table creation
706
707 // Table-based representation follows
708
709 int nEntries;
710 WORD GammaTable[1];
711
712 } GAMMATABLE;
713
714 typedef GAMMATABLE FAR* LPGAMMATABLE;
715
716 // Sampled curves (1D)
717 typedef struct {
718
719 int nItems;
720 double* Values;
721
722 } SAMPLEDCURVE;
723
724 typedef SAMPLEDCURVE FAR* LPSAMPLEDCURVE;
725
726 // Vectors
727 typedef struct { // Float Vector
728
729 double n[3];
730
731 } VEC3;
732
733 typedef VEC3 FAR* LPVEC3;
734
735
736 typedef struct { // Matrix
737
738 VEC3 v[3];
739
740 } MAT3;
741
742 typedef MAT3 FAR* LPMAT3;
743
744 // Colorspace values
745 typedef struct {
746
747 double X;
748 double Y;
749 double Z;
750
751 } cmsCIEXYZ;
752
753 typedef cmsCIEXYZ FAR* LPcmsCIEXYZ;
754
755 typedef struct {
756
757 double x;
758 double y;
759 double Y;
760
761 } cmsCIExyY;
762
763 typedef cmsCIExyY FAR* LPcmsCIExyY;
764
765 typedef struct {
766
767 double L;
768 double a;
769 double b;
770
771 } cmsCIELab;
772
773 typedef cmsCIELab FAR* LPcmsCIELab;
774
775 typedef struct {
776
777 double L;
778 double C;
779 double h;
780
781 } cmsCIELCh;
782
783 typedef cmsCIELCh FAR* LPcmsCIELCh;
784
785 typedef struct {
786
787 double J;
788 double C;
789 double h;
790
791 } cmsJCh;
792
793 typedef cmsJCh FAR* LPcmsJCh;
794
795 // Primaries
796 typedef struct {
797
798 cmsCIEXYZ Red;
799 cmsCIEXYZ Green;
800 cmsCIEXYZ Blue;
801
802 } cmsCIEXYZTRIPLE;
803
804 typedef cmsCIEXYZTRIPLE FAR* LPcmsCIEXYZTRIPLE;
805
806
807 typedef struct {
808
809 cmsCIExyY Red;
810 cmsCIExyY Green;
811 cmsCIExyY Blue;
812
813 } cmsCIExyYTRIPLE;
814
815 typedef cmsCIExyYTRIPLE FAR* LPcmsCIExyYTRIPLE;
816
817
818
819 // Following ICC spec
820
821 #define D50X (0.9642)
822 #define D50Y (1.0)
823 #define D50Z (0.8249)
824
825 #define PERCEPTUAL_BLACK_X (0.00336)
826 #define PERCEPTUAL_BLACK_Y (0.0034731)
827 #define PERCEPTUAL_BLACK_Z (0.00287)
828
829 // Does return pointers to constant structs
830
831 LCMSAPI LPcmsCIEXYZ LCMSEXPORT cmsD50_XYZ(void);
832 LCMSAPI LPcmsCIExyY LCMSEXPORT cmsD50_xyY(void);
833
834
835 // Input/Output
836
837 LCMSAPI cmsHPROFILE LCMSEXPORT cmsOpenProfileFromFile(const char *ICCProfile, const char *sAccess);
838 LCMSAPI cmsHPROFILE LCMSEXPORT cmsOpenProfileFromMem(LPVOID MemPtr, DWORD dwSize);
839 LCMSAPI LCMSBOOL LCMSEXPORT cmsCloseProfile(cmsHPROFILE hProfile);
840
841 // Predefined run-time profiles
842
843 LCMSAPI cmsHPROFILE LCMSEXPORT cmsCreateRGBProfile(LPcmsCIExyY WhitePoint,
844 LPcmsCIExyYTRIPLE Primaries,
845 LPGAMMATABLE TransferFunction[3]);
846
847 LCMSAPI cmsHPROFILE LCMSEXPORT cmsCreateGrayProfile(LPcmsCIExyY WhitePoint,
848 LPGAMMATABLE TransferFunction);
849
850 LCMSAPI cmsHPROFILE LCMSEXPORT cmsCreateLinearizationDeviceLink(icColorSpaceSignature ColorSpace,
851 LPGAMMATABLE TransferFunctions[]);
852
853 LCMSAPI cmsHPROFILE LCMSEXPORT cmsCreateInkLimitingDeviceLink(icColorSpaceSignature ColorSpace,
854 double Limit);
855
856
857 LCMSAPI cmsHPROFILE LCMSEXPORT cmsCreateLabProfile(LPcmsCIExyY WhitePoint);
858 LCMSAPI cmsHPROFILE LCMSEXPORT cmsCreateLab4Profile(LPcmsCIExyY WhitePoint);
859
860 LCMSAPI cmsHPROFILE LCMSEXPORT cmsCreateXYZProfile(void);
861 LCMSAPI cmsHPROFILE LCMSEXPORT cmsCreate_sRGBProfile(void);
862
863
864
865 LCMSAPI cmsHPROFILE LCMSEXPORT cmsCreateBCHSWabstractProfile(int nLUTPoints,
866 double Bright,
867 double Contrast,
868 double Hue,
869 double Saturation,
870 int TempSrc,
871 int TempDest);
872
873 LCMSAPI cmsHPROFILE LCMSEXPORT cmsCreateNULLProfile(void);
874
875
876 // Colorimetric space conversions
877
878 LCMSAPI void LCMSEXPORT cmsXYZ2xyY(LPcmsCIExyY Dest, const cmsCIEXYZ* Source);
879 LCMSAPI void LCMSEXPORT cmsxyY2XYZ(LPcmsCIEXYZ Dest, const cmsCIExyY* Source);
880 LCMSAPI void LCMSEXPORT cmsXYZ2Lab(LPcmsCIEXYZ WhitePoint, LPcmsCIELab Lab, const cmsCIEXYZ* xyz);
881 LCMSAPI void LCMSEXPORT cmsLab2XYZ(LPcmsCIEXYZ WhitePoint, LPcmsCIEXYZ xyz, const cmsCIELab* Lab);
882 LCMSAPI void LCMSEXPORT cmsLab2LCh(LPcmsCIELCh LCh, const cmsCIELab* Lab);
883 LCMSAPI void LCMSEXPORT cmsLCh2Lab(LPcmsCIELab Lab, const cmsCIELCh* LCh);
884
885
886 // CIELab handling
887
888 LCMSAPI double LCMSEXPORT cmsDeltaE(LPcmsCIELab Lab1, LPcmsCIELab Lab2);
889 LCMSAPI double LCMSEXPORT cmsCIE94DeltaE(LPcmsCIELab Lab1, LPcmsCIELab Lab2);
890 LCMSAPI double LCMSEXPORT cmsBFDdeltaE(LPcmsCIELab Lab1, LPcmsCIELab Lab2);
891 LCMSAPI double LCMSEXPORT cmsCMCdeltaE(LPcmsCIELab Lab1, LPcmsCIELab Lab2);
892 LCMSAPI double LCMSEXPORT cmsCIE2000DeltaE(LPcmsCIELab Lab1, LPcmsCIELab Lab2, double Kl, double Kc, double Kh);
893
894 LCMSAPI void LCMSEXPORT cmsClampLab(LPcmsCIELab Lab, double amax, double amin, double bmax, double bmin);
895
896 LCMSAPI LCMSBOOL LCMSEXPORT cmsWhitePointFromTemp(int TempK, LPcmsCIExyY WhitePoint);
897
898 LCMSAPI LCMSBOOL LCMSEXPORT cmsAdaptToIlluminant(LPcmsCIEXYZ Result,
899 LPcmsCIEXYZ SourceWhitePt,
900 LPcmsCIEXYZ Illuminant,
901 LPcmsCIEXYZ Value);
902
903 LCMSAPI LCMSBOOL LCMSEXPORT cmsBuildRGB2XYZtransferMatrix(LPMAT3 r,
904 LPcmsCIExyY WhitePoint,
905 LPcmsCIExyYTRIPLE Primaries);
906
907 // Viewing conditions
908
909 #define AVG_SURROUND_4 0
910 #define AVG_SURROUND 1
911 #define DIM_SURROUND 2
912 #define DARK_SURROUND 3
913 #define CUTSHEET_SURROUND 4
914
915 #define D_CALCULATE (-1)
916 #define D_CALCULATE_DISCOUNT (-2)
917
918 typedef struct {
919
920 cmsCIEXYZ whitePoint;
921 double Yb;
922 double La;
923 int surround;
924 double D_value;
925
926 } cmsViewingConditions;
927
928 typedef cmsViewingConditions FAR* LPcmsViewingConditions;
929
930 // CIECAM97s
931
932 LCMSAPI LCMSHANDLE LCMSEXPORT cmsCIECAM97sInit(LPcmsViewingConditions pVC2);
933 LCMSAPI void LCMSEXPORT cmsCIECAM97sDone(LCMSHANDLE hModel);
934 LCMSAPI void LCMSEXPORT cmsCIECAM97sForward(LCMSHANDLE hModel, LPcmsCIEXYZ pIn, LPcmsJCh pOut);
935 LCMSAPI void LCMSEXPORT cmsCIECAM97sReverse(LCMSHANDLE hModel, LPcmsJCh pIn, LPcmsCIEXYZ pOut);
936
937
938 // CIECAM02
939
940 LCMSAPI LCMSHANDLE LCMSEXPORT cmsCIECAM02Init(LPcmsViewingConditions pVC);
941 LCMSAPI void LCMSEXPORT cmsCIECAM02Done(LCMSHANDLE hModel);
942 LCMSAPI void LCMSEXPORT cmsCIECAM02Forward(LCMSHANDLE hModel, LPcmsCIEXYZ pIn, LPcmsJCh pOut);
943 LCMSAPI void LCMSEXPORT cmsCIECAM02Reverse(LCMSHANDLE hModel, LPcmsJCh pIn, LPcmsCIEXYZ pOut);
944
945
946 // Gamma
947
948 LCMSAPI LPGAMMATABLE LCMSEXPORT cmsBuildGamma(int nEntries, double Gamma);
949 LCMSAPI LPGAMMATABLE LCMSEXPORT cmsBuildParametricGamma(int nEntries, int Type, double Params[]);
950 LCMSAPI LPGAMMATABLE LCMSEXPORT cmsAllocGamma(int nEntries);
951 LCMSAPI void LCMSEXPORT cmsFreeGamma(LPGAMMATABLE Gamma);
952 LCMSAPI void LCMSEXPORT cmsFreeGammaTriple(LPGAMMATABLE Gamma[3]);
953 LCMSAPI LPGAMMATABLE LCMSEXPORT cmsDupGamma(LPGAMMATABLE Src);
954 LCMSAPI LPGAMMATABLE LCMSEXPORT cmsReverseGamma(int nResultSamples, LPGAMMATABLE InGamma);
955 LCMSAPI LPGAMMATABLE LCMSEXPORT cmsJoinGamma(LPGAMMATABLE InGamma, LPGAMMATABLE OutGamma);
956 LCMSAPI LPGAMMATABLE LCMSEXPORT cmsJoinGammaEx(LPGAMMATABLE InGamma, LPGAMMATABLE OutGamma, int nPoints);
957 LCMSAPI LCMSBOOL LCMSEXPORT cmsSmoothGamma(LPGAMMATABLE Tab, double lambda);
958 LCMSAPI double LCMSEXPORT cmsEstimateGamma(LPGAMMATABLE t);
959 LCMSAPI double LCMSEXPORT cmsEstimateGammaEx(LPWORD Table, int nEntries, double Thereshold);
960 LCMSAPI LPGAMMATABLE LCMSEXPORT cmsReadICCGamma(cmsHPROFILE hProfile, icTagSignature sig);
961 LCMSAPI LPGAMMATABLE LCMSEXPORT cmsReadICCGammaReversed(cmsHPROFILE hProfile, icTagSignature sig);
962
963 // Access to Profile data.
964
965 LCMSAPI LCMSBOOL LCMSEXPORT cmsTakeMediaWhitePoint(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile);
966 LCMSAPI LCMSBOOL LCMSEXPORT cmsTakeMediaBlackPoint(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile);
967 LCMSAPI LCMSBOOL LCMSEXPORT cmsTakeIluminant(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile);
968 LCMSAPI LCMSBOOL LCMSEXPORT cmsTakeColorants(LPcmsCIEXYZTRIPLE Dest, cmsHPROFILE hProfile);
969 LCMSAPI DWORD LCMSEXPORT cmsTakeHeaderFlags(cmsHPROFILE hProfile);
970 LCMSAPI DWORD LCMSEXPORT cmsTakeHeaderAttributes(cmsHPROFILE hProfile);
971
972 LCMSAPI void LCMSEXPORT cmsSetLanguage(const char LanguageCode[4], const char CountryCode[4]);
973 LCMSAPI const char* LCMSEXPORT cmsTakeProductName(cmsHPROFILE hProfile);
974 LCMSAPI const char* LCMSEXPORT cmsTakeProductDesc(cmsHPROFILE hProfile);
975 LCMSAPI const char* LCMSEXPORT cmsTakeProductInfo(cmsHPROFILE hProfile);
976 LCMSAPI const char* LCMSEXPORT cmsTakeManufacturer(cmsHPROFILE hProfile);
977 LCMSAPI const char* LCMSEXPORT cmsTakeModel(cmsHPROFILE hProfile);
978 LCMSAPI const char* LCMSEXPORT cmsTakeCopyright(cmsHPROFILE hProfile);
979 LCMSAPI const BYTE* LCMSEXPORT cmsTakeProfileID(cmsHPROFILE hProfile);
980
981 LCMSAPI LCMSBOOL LCMSEXPORT cmsTakeCreationDateTime(struct tm *Dest, cmsHPROFILE hProfile);
982 LCMSAPI LCMSBOOL LCMSEXPORT cmsTakeCalibrationDateTime(struct tm *Dest, cmsHPROFILE hProfile);
983
984 LCMSAPI LCMSBOOL LCMSEXPORT cmsIsTag(cmsHPROFILE hProfile, icTagSignature sig);
985 LCMSAPI int LCMSEXPORT cmsTakeRenderingIntent(cmsHPROFILE hProfile);
986
987 LCMSAPI LCMSBOOL LCMSEXPORT cmsTakeCharTargetData(cmsHPROFILE hProfile, char** Data, size_t* len);
988
989 LCMSAPI int LCMSEXPORT cmsReadICCTextEx(cmsHPROFILE hProfile, icTagSignature sig, char *Text, size_t size);
990 LCMSAPI int LCMSEXPORT cmsReadICCText(cmsHPROFILE hProfile, icTagSignature sig, char *Text);
991
992
993 #define LCMS_DESC_MAX 512
994
995 typedef struct {
996
997 icSignature deviceMfg;
998 icSignature deviceModel;
999 icUInt32Number attributes[2];
1000 icTechnologySignature technology;
1001
1002 char Manufacturer[LCMS_DESC_MAX];
1003 char Model[LCMS_DESC_MAX];
1004
1005 } cmsPSEQDESC, FAR *LPcmsPSEQDESC;
1006
1007 typedef struct {
1008
1009 int n;
1010 cmsPSEQDESC seq[1];
1011
1012 } cmsSEQ, FAR *LPcmsSEQ;
1013
1014
1015 LCMSAPI LPcmsSEQ LCMSEXPORT cmsReadProfileSequenceDescription(cmsHPROFILE hProfile);
1016 LCMSAPI void LCMSEXPORT cmsFreeProfileSequenceDescription(LPcmsSEQ pseq);
1017
1018
1019 // Translate form/to our notation to ICC
1020 LCMSAPI icColorSpaceSignature LCMSEXPORT _cmsICCcolorSpace(int OurNotation);
1021 LCMSAPI int LCMSEXPORT _cmsLCMScolorSpace(icColorSpaceSignature ProfileSpace);
1022 LCMSAPI int LCMSEXPORT _cmsChannelsOf(icColorSpaceSignature ColorSpace);
1023 LCMSAPI LCMSBOOL LCMSEXPORT _cmsIsMatrixShaper(cmsHPROFILE hProfile);
1024
1025 // How profiles may be used
1026 #define LCMS_USED_AS_INPUT 0
1027 #define LCMS_USED_AS_OUTPUT 1
1028 #define LCMS_USED_AS_PROOF 2
1029
1030 LCMSAPI LCMSBOOL LCMSEXPORT cmsIsIntentSupported(cmsHPROFILE hProfile, int Intent, int UsedDirection);
1031
1032 LCMSAPI icColorSpaceSignature LCMSEXPORT cmsGetPCS(cmsHPROFILE hProfile);
1033 LCMSAPI icColorSpaceSignature LCMSEXPORT cmsGetColorSpace(cmsHPROFILE hProfile);
1034 LCMSAPI icProfileClassSignature LCMSEXPORT cmsGetDeviceClass(cmsHPROFILE hProfile);
1035 LCMSAPI DWORD LCMSEXPORT cmsGetProfileICCversion(cmsHPROFILE hProfile);
1036 LCMSAPI void LCMSEXPORT cmsSetProfileICCversion(cmsHPROFILE hProfile, DWORD Version);
1037 LCMSAPI icInt32Number LCMSEXPORT cmsGetTagCount(cmsHPROFILE hProfile);
1038 LCMSAPI icTagSignature LCMSEXPORT cmsGetTagSignature(cmsHPROFILE hProfile, icInt32Number n);
1039
1040
1041 LCMSAPI void LCMSEXPORT cmsSetDeviceClass(cmsHPROFILE hProfile, icProfileClassSignature sig);
1042 LCMSAPI void LCMSEXPORT cmsSetColorSpace(cmsHPROFILE hProfile, icColorSpaceSignature sig);
1043 LCMSAPI void LCMSEXPORT cmsSetPCS(cmsHPROFILE hProfile, icColorSpaceSignature pcs);
1044 LCMSAPI void LCMSEXPORT cmsSetRenderingIntent(cmsHPROFILE hProfile, int RenderingIntent);
1045 LCMSAPI void LCMSEXPORT cmsSetHeaderFlags(cmsHPROFILE hProfile, DWORD Flags);
1046 LCMSAPI void LCMSEXPORT cmsSetHeaderAttributes(cmsHPROFILE hProfile, DWORD Flags);
1047 LCMSAPI void LCMSEXPORT cmsSetProfileID(cmsHPROFILE hProfile, LPBYTE ProfileID);
1048
1049 // Intents
1050
1051 #define INTENT_PERCEPTUAL 0
1052 #define INTENT_RELATIVE_COLORIMETRIC 1
1053 #define INTENT_SATURATION 2
1054 #define INTENT_ABSOLUTE_COLORIMETRIC 3
1055
1056 // Flags
1057
1058 #define cmsFLAGS_MATRIXINPUT 0x0001
1059 #define cmsFLAGS_MATRIXOUTPUT 0x0002
1060 #define cmsFLAGS_MATRIXONLY (cmsFLAGS_MATRIXINPUT|cmsFLAGS_MATRIXOUTPUT)
1061
1062 #define cmsFLAGS_NOWHITEONWHITEFIXUP 0x0004 // Don't hot fix scum dot
1063 #define cmsFLAGS_NOPRELINEARIZATION 0x0010 // Don't create prelinearization tables
1064 // on precalculated transforms (internal use)
1065
1066 #define cmsFLAGS_GUESSDEVICECLASS 0x0020 // Guess device class (for transform2devicelink)
1067
1068 #define cmsFLAGS_NOTCACHE 0x0040 // Inhibit 1-pixel cache
1069
1070 #define cmsFLAGS_NOTPRECALC 0x0100
1071 #define cmsFLAGS_NULLTRANSFORM 0x0200 // Don't transform anyway
1072 #define cmsFLAGS_HIGHRESPRECALC 0x0400 // Use more memory to give better accurancy
1073 #define cmsFLAGS_LOWRESPRECALC 0x0800 // Use less memory to minimize resouces
1074
1075
1076 #define cmsFLAGS_WHITEBLACKCOMPENSATION 0x2000
1077 #define cmsFLAGS_BLACKPOINTCOMPENSATION cmsFLAGS_WHITEBLACKCOMPENSATION
1078
1079 // Proofing flags
1080
1081 #define cmsFLAGS_GAMUTCHECK 0x1000 // Out of Gamut alarm
1082 #define cmsFLAGS_SOFTPROOFING 0x4000 // Do softproofing
1083
1084 // Black preservation
1085
1086 #define cmsFLAGS_PRESERVEBLACK 0x8000
1087
1088 // CRD special
1089
1090 #define cmsFLAGS_NODEFAULTRESOURCEDEF 0x01000000
1091
1092 // Gridpoints
1093
1094 #define cmsFLAGS_GRIDPOINTS(n) (((n) & 0xFF) << 16)
1095
1096
1097 // Transforms
1098
1099 LCMSAPI cmsHTRANSFORM LCMSEXPORT cmsCreateTransform(cmsHPROFILE Input,
1100 DWORD InputFormat,
1101 cmsHPROFILE Output,
1102 DWORD OutputFormat,
1103 int Intent,
1104 DWORD dwFlags);
1105
1106 LCMSAPI cmsHTRANSFORM LCMSEXPORT cmsCreateProofingTransform(cmsHPROFILE Input,
1107 DWORD InputFormat,
1108 cmsHPROFILE Output,
1109 DWORD OutputFormat,
1110 cmsHPROFILE Proofing,
1111 int Intent,
1112 int ProofingIntent,
1113 DWORD dwFlags);
1114
1115 LCMSAPI cmsHTRANSFORM LCMSEXPORT cmsCreateMultiprofileTransform(cmsHPROFILE hProfiles[],
1116 int nProfiles,
1117 DWORD InputFormat,
1118 DWORD OutputFormat,
1119 int Intent,
1120 DWORD dwFlags);
1121
1122 LCMSAPI void LCMSEXPORT cmsDeleteTransform(cmsHTRANSFORM hTransform);
1123
1124 LCMSAPI void LCMSEXPORT cmsDoTransform(cmsHTRANSFORM Transform,
1125 LPVOID InputBuffer,
1126 LPVOID OutputBuffer,
1127 unsigned int Size);
1128
1129 LCMSAPI void LCMSEXPORT cmsChangeBuffersFormat(cmsHTRANSFORM hTransform, DWORD InputFormat, DWORD dwOutputFormat);
1130
1131 LCMSAPI void LCMSEXPORT cmsSetAlarmCodes(int r, int g, int b);
1132 LCMSAPI void LCMSEXPORT cmsGetAlarmCodes(int *r, int *g, int *b);
1133
1134
1135 // Adaptation state for absolute colorimetric intent
1136
1137 LCMSAPI double LCMSEXPORT cmsSetAdaptationState(double d);
1138
1139
1140 // Primary preservation strategy
1141
1142 #define LCMS_PRESERVE_PURE_K 0
1143 #define LCMS_PRESERVE_K_PLANE 1
1144
1145 LCMSAPI int LCMSEXPORT cmsSetCMYKPreservationStrategy(int n);
1146
1147 // Named color support
1148 typedef struct {
1149 char Name[MAX_PATH];
1150 WORD PCS[3];
1151 WORD DeviceColorant[MAXCHANNELS];
1152
1153
1154 } cmsNAMEDCOLOR, FAR* LPcmsNAMEDCOLOR;
1155
1156 typedef struct {
1157 int nColors;
1158 int Allocated;
1159 int ColorantCount;
1160 char Prefix[33];
1161 char Suffix[33];
1162
1163 cmsNAMEDCOLOR List[1];
1164
1165 } cmsNAMEDCOLORLIST, FAR* LPcmsNAMEDCOLORLIST;
1166
1167 // Named color support
1168
1169 LCMSAPI int LCMSEXPORT cmsNamedColorCount(cmsHTRANSFORM xform);
1170 LCMSAPI LCMSBOOL LCMSEXPORT cmsNamedColorInfo(cmsHTRANSFORM xform, int nColor, char* Name, char* Prefix, char* Suffix);
1171 LCMSAPI int LCMSEXPORT cmsNamedColorIndex(cmsHTRANSFORM xform, const char* Name);
1172
1173 // Colorant tables
1174
1175 LCMSAPI LPcmsNAMEDCOLORLIST LCMSEXPORT cmsReadColorantTable(cmsHPROFILE hProfile, icTagSignature sig);
1176
1177 // Profile creation
1178
1179 LCMSAPI LCMSBOOL LCMSEXPORT cmsAddTag(cmsHPROFILE hProfile, icTagSignature sig, const void* data);
1180
1181 // Converts a transform to a devicelink profile
1182 LCMSAPI cmsHPROFILE LCMSEXPORT cmsTransform2DeviceLink(cmsHTRANSFORM hTransform, DWORD dwFlags);
1183
1184 // Set the 'save as 8-bit' flag
1185 LCMSAPI void LCMSEXPORT _cmsSetLUTdepth(cmsHPROFILE hProfile, int depth);
1186
1187
1188 // Save profile
1189 LCMSAPI LCMSBOOL LCMSEXPORT _cmsSaveProfile(cmsHPROFILE hProfile, const char* FileName);
1190 LCMSAPI LCMSBOOL LCMSEXPORT _cmsSaveProfileToMem(cmsHPROFILE hProfile, void *MemPtr,
1191 size_t* BytesNeeded);
1192
1193
1194
1195 // PostScript ColorRenderingDictionary and ColorSpaceArray
1196
1197 LCMSAPI DWORD LCMSEXPORT cmsGetPostScriptCSA(cmsHPROFILE hProfile, int Intent, LPVOID Buffer, DWORD dwBufferLen);
1198 LCMSAPI DWORD LCMSEXPORT cmsGetPostScriptCRD(cmsHPROFILE hProfile, int Intent, LPVOID Buffer, DWORD dwBufferLen);
1199 LCMSAPI DWORD LCMSEXPORT cmsGetPostScriptCRDEx(cmsHPROFILE hProfile, int Intent, DWORD dwFlags, LPVOID Buffer, DWORD dwBufferLen);
1200
1201
1202 // Error handling
1203
1204 #define LCMS_ERROR_ABORT 0
1205 #define LCMS_ERROR_SHOW 1
1206 #define LCMS_ERROR_IGNORE 2
1207
1208 LCMSAPI int LCMSEXPORT cmsErrorAction(int nAction);
1209
1210 #define LCMS_ERRC_WARNING 0x1000
1211 #define LCMS_ERRC_RECOVERABLE 0x2000
1212 #define LCMS_ERRC_ABORTED 0x3000
1213
1214 typedef int (* cmsErrorHandlerFunction)(int ErrorCode, const char *ErrorText);
1215
1216 LCMSAPI void LCMSEXPORT cmsSetErrorHandler(cmsErrorHandlerFunction Fn);
1217
1218
1219 // LUT manipulation
1220
1221
1222 typedef struct _lcms_LUT_struc LUT, FAR* LPLUT; // opaque pointer
1223
1224 LCMSAPI LPLUT LCMSEXPORT cmsAllocLUT(void);
1225 LCMSAPI LPLUT LCMSEXPORT cmsAllocLinearTable(LPLUT NewLUT, LPGAMMATABLE Tables[], int nTable);
1226 LCMSAPI LPLUT LCMSEXPORT cmsAlloc3DGrid(LPLUT Lut, int clutPoints, int inputChan, int outputChan);
1227 LCMSAPI LPLUT LCMSEXPORT cmsSetMatrixLUT(LPLUT Lut, LPMAT3 M);
1228 LCMSAPI LPLUT LCMSEXPORT cmsSetMatrixLUT4(LPLUT Lut, LPMAT3 M, LPVEC3 off, DWORD dwFlags);
1229 LCMSAPI void LCMSEXPORT cmsFreeLUT(LPLUT Lut);
1230 LCMSAPI void LCMSEXPORT cmsEvalLUT(LPLUT Lut, WORD In[], WORD Out[]);
1231 LCMSAPI double LCMSEXPORT cmsEvalLUTreverse(LPLUT Lut, WORD Target[], WORD Result[], LPWORD Hint);
1232 LCMSAPI LPLUT LCMSEXPORT cmsReadICCLut(cmsHPROFILE hProfile, icTagSignature sig);
1233 LCMSAPI LPLUT LCMSEXPORT cmsDupLUT(LPLUT Orig);
1234
1235
1236 // LUT Sampling
1237
1238 typedef int (* _cmsSAMPLER)(register WORD In[],
1239 register WORD Out[],
1240 register LPVOID Cargo);
1241
1242 #define SAMPLER_HASTL1 LUT_HASTL1
1243 #define SAMPLER_HASTL2 LUT_HASTL2
1244 #define SAMPLER_INSPECT 0x01000000
1245
1246 LCMSAPI int LCMSEXPORT cmsSample3DGrid(LPLUT Lut, _cmsSAMPLER Sampler, LPVOID Cargo, DWORD dwFlags);
1247
1248 // Formatters
1249
1250 typedef unsigned char* (* cmsFORMATTER)(register void* CMMcargo,
1251 register WORD ToUnroll[],
1252 register LPBYTE Buffer);
1253
1254 LCMSAPI void LCMSEXPORT cmsSetUserFormatters(cmsHTRANSFORM hTransform, DWORD dwInput, cmsFORMATTER Input,
1255 DWORD dwOutput, cmsFORMATTER Output);
1256
1257 LCMSAPI void LCMSEXPORT cmsGetUserFormatters(cmsHTRANSFORM hTransform,
1258 LPDWORD InputFormat, cmsFORMATTER* Input,
1259 LPDWORD OutputFormat, cmsFORMATTER* Output);
1260
1261
1262 // IT8.7 / CGATS.17-200x handling
1263
1264 LCMSAPI LCMSHANDLE LCMSEXPORT cmsIT8Alloc(void);
1265 LCMSAPI void LCMSEXPORT cmsIT8Free(LCMSHANDLE IT8);
1266
1267 // Tables
1268
1269 LCMSAPI int LCMSEXPORT cmsIT8TableCount(LCMSHANDLE IT8);
1270 LCMSAPI int LCMSEXPORT cmsIT8SetTable(LCMSHANDLE IT8, int nTable);
1271
1272 // Persistence
1273 LCMSAPI LCMSHANDLE LCMSEXPORT cmsIT8LoadFromFile(const char* cFileName);
1274 LCMSAPI LCMSHANDLE LCMSEXPORT cmsIT8LoadFromMem(void *Ptr, size_t len);
1275 LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SaveToFile(LCMSHANDLE IT8, const char* cFileName);
1276 LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SaveToMem(LCMSHANDLE hIT8, void *MemPtr, size_t* BytesNeeded);
1277
1278 // Properties
1279 LCMSAPI const char* LCMSEXPORT cmsIT8GetSheetType(LCMSHANDLE hIT8);
1280 LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetSheetType(LCMSHANDLE hIT8, const char* Type);
1281
1282 LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetComment(LCMSHANDLE hIT8, const char* cComment);
1283
1284 LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetPropertyStr(LCMSHANDLE hIT8, const char* cProp, const char *Str);
1285 LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetPropertyDbl(LCMSHANDLE hIT8, const char* cProp, double Val);
1286 LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetPropertyHex(LCMSHANDLE hIT8, const char* cProp, int Val);
1287 LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetPropertyMulti(LCMSHANDLE hIT8, const char* cProp, const char* cSubProp, const char *Val);
1288 LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetPropertyUncooked(LCMSHANDLE hIT8, const char* Key, const char* Buffer);
1289
1290
1291 LCMSAPI const char* LCMSEXPORT cmsIT8GetProperty(LCMSHANDLE hIT8, const char* cProp);
1292 LCMSAPI double LCMSEXPORT cmsIT8GetPropertyDbl(LCMSHANDLE hIT8, const char* cProp);
1293 LCMSAPI const char* LCMSEXPORT cmsIT8GetPropertyMulti(LCMSHANDLE hIT8, const char* cProp, const char *cSubProp);
1294 LCMSAPI int LCMSEXPORT cmsIT8EnumProperties(LCMSHANDLE hIT8, const char ***PropertyNames);
1295 LCMSAPI int LCMSEXPORT cmsIT8EnumPropertyMulti(LCMSHANDLE hIT8, const char* cProp, const char*** SubpropertyNames);
1296
1297 // Datasets
1298
1299 LCMSAPI const char* LCMSEXPORT cmsIT8GetDataRowCol(LCMSHANDLE IT8, int row, int col);
1300 LCMSAPI double LCMSEXPORT cmsIT8GetDataRowColDbl(LCMSHANDLE IT8, int row, int col);
1301
1302 LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetDataRowCol(LCMSHANDLE hIT8, int row, int col,
1303 const char* Val);
1304
1305 LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetDataRowColDbl(LCMSHANDLE hIT8, int row, int col,
1306 double Val);
1307
1308 LCMSAPI const char* LCMSEXPORT cmsIT8GetData(LCMSHANDLE IT8, const char* cPatch, const char* cSample);
1309
1310
1311 LCMSAPI double LCMSEXPORT cmsIT8GetDataDbl(LCMSHANDLE IT8, const char* cPatch, const char* cSample);
1312
1313 LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetData(LCMSHANDLE IT8, const char* cPatch,
1314 const char* cSample,
1315 const char *Val);
1316
1317 LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetDataDbl(LCMSHANDLE hIT8, const char* cPatch,
1318 const char* cSample,
1319 double Val);
1320
1321 LCMSAPI int LCMSEXPORT cmsIT8GetDataFormat(LCMSHANDLE hIT8, const char* cSample);
1322 LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetDataFormat(LCMSHANDLE IT8, int n, const char *Sample);
1323 LCMSAPI int LCMSEXPORT cmsIT8EnumDataFormat(LCMSHANDLE IT8, char ***SampleNames);
1324
1325
1326 LCMSAPI const char* LCMSEXPORT cmsIT8GetPatchName(LCMSHANDLE hIT8, int nPatch, char* buffer);
1327 LCMSAPI int LCMSEXPORT cmsIT8GetPatchByName(LCMSHANDLE hIT8, const char *cSample);
1328
1329 // The LABEL extension
1330
1331 LCMSAPI int LCMSEXPORT cmsIT8SetTableByLabel(LCMSHANDLE hIT8, const char* cSet, const char* cField, const char* ExpectedType);
1332
1333 LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetIndexColumn(LCMSHANDLE hIT8, const char* cSample);
1334
1335 // Formatter for double
1336 LCMSAPI void LCMSEXPORT cmsIT8DefineDblFormat(LCMSHANDLE IT8, const char* Formatter);
1337
1338
1339 // ***************************************************************************
1340 // End of Little cms API From here functions are private
1341 // You can use them only if using static libraries, and at your own risk of
1342 // be stripped or changed at futures releases.
1343
1344 #ifndef LCMS_APIONLY
1345
1346
1347 // Compatibility with anterior versions-- not needed anymore
1348 // -- Morge
1349
1350 LCMSAPI void LCMSEXPORT cmsLabEncoded2Float(LPcmsCIELab Lab, const WORD wLab[3]);
1351 LCMSAPI void LCMSEXPORT cmsLabEncoded2Float4(LPcmsCIELab Lab, const WORD wLab[3]);
1352 LCMSAPI void LCMSEXPORT cmsFloat2LabEncoded(WORD wLab[3], const cmsCIELab* Lab);
1353 LCMSAPI void LCMSEXPORT cmsFloat2LabEncoded4(WORD wLab[3], const cmsCIELab* Lab);
1354 LCMSAPI void LCMSEXPORT cmsXYZEncoded2Float(LPcmsCIEXYZ fxyz, const WORD XYZ[3]);
1355 LCMSAPI void LCMSEXPORT cmsFloat2XYZEncoded(WORD XYZ[3], const cmsCIEXYZ* fXYZ);
1356
1357
1358 // Profiling Extensions --- Would be removed from API in future revisions
1359
1360 LCMSAPI LCMSBOOL LCMSEXPORT _cmsAddTextTag(cmsHPROFILE hProfile, icTagSignature sig, const char* Text);
1361 LCMSAPI LCMSBOOL LCMSEXPORT _cmsAddXYZTag(cmsHPROFILE hProfile, icTagSignature sig, const cmsCIEXYZ* XYZ);
1362 LCMSAPI LCMSBOOL LCMSEXPORT _cmsAddLUTTag(cmsHPROFILE hProfile, icTagSignature sig, const void* lut);
1363 LCMSAPI LCMSBOOL LCMSEXPORT _cmsAddGammaTag(cmsHPROFILE hProfile, icTagSignature sig, LPGAMMATABLE TransferFunction);
1364 LCMSAPI LCMSBOOL LCMSEXPORT _cmsAddChromaticityTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsCIExyYTRIPLE Chrm);
1365 LCMSAPI LCMSBOOL LCMSEXPORT _cmsAddSequenceDescriptionTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsSEQ PSeq);
1366 LCMSAPI LCMSBOOL LCMSEXPORT _cmsAddNamedColorTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsNAMEDCOLORLIST nc);
1367 LCMSAPI LCMSBOOL LCMSEXPORT _cmsAddDateTimeTag(cmsHPROFILE hProfile, icTagSignature sig, struct tm *DateTime);
1368 LCMSAPI LCMSBOOL LCMSEXPORT _cmsAddColorantTableTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsNAMEDCOLORLIST nc);
1369 LCMSAPI LCMSBOOL LCMSEXPORT _cmsAddChromaticAdaptationTag(cmsHPROFILE hProfile, icTagSignature sig, const cmsCIEXYZ* mat);
1370
1371 // --------------------------------------------------------------------------------------------------- Inline functions
1372
1373 // Fast floor conversion logic. Thanks to Sree Kotay and Stuart Nixon
1374 // note than this only works in the range ..-32767...+32767 because
1375 // mantissa is interpreted as 15.16 fixed point.
1376 // The union is to avoid pointer aliasing overoptimization.
1377
_cmsQuickFloor(double val)1378 LCMS_INLINE int _cmsQuickFloor(double val)
1379 {
1380 #ifdef USE_DEFAULT_FLOOR_CONVERSION
1381 return (int) floor(val);
1382 #else
1383 const double _lcms_double2fixmagic = 68719476736.0 * 1.5; // 2^36 * 1.5, (52-16=36) uses limited precision to floor
1384 union {
1385 double val;
1386 int halves[2];
1387 } temp;
1388
1389 temp.val = val + _lcms_double2fixmagic;
1390
1391
1392 #ifdef USE_BIG_ENDIAN
1393 return temp.halves[1] >> 16;
1394 #else
1395 return temp.halves[0] >> 16;
1396 #endif
1397 #endif
1398 }
1399
1400
1401
1402 // Clamp with saturation
1403
_cmsClampWord(int in)1404 LCMS_INLINE WORD _cmsClampWord(int in)
1405 {
1406 if (in < 0) return 0;
1407 if (in > 0xFFFF) return 0xFFFFU; // Including marker
1408 return (WORD) in;
1409 }
1410
1411 #ifndef LCMS_USER_ALLOC
1412
1413 // Low-level alloc hook
1414
_cmsMalloc(size_t size)1415 LCMS_INLINE void* _cmsMalloc(size_t size)
1416 {
1417 if (size > ((size_t) 1024*1024*500)) return NULL; // Never allow over 500Mb
1418 if (size < 0) return NULL; // Prevent signed size_t exploits
1419
1420 return (void*) malloc(size);
1421 }
1422
_cmsCalloc(size_t nmemb,size_t size)1423 LCMS_INLINE void* _cmsCalloc(size_t nmemb, size_t size)
1424 {
1425 size_t alloc = nmemb * size;
1426
1427 if (size == 0) {
1428 return _cmsMalloc(0);
1429 }
1430 if (alloc / size != nmemb) {
1431 return NULL;
1432 }
1433 return _cmsMalloc(alloc);
1434 }
1435
_cmsFree(void * Ptr)1436 LCMS_INLINE void _cmsFree(void *Ptr)
1437 {
1438 if (Ptr) free(Ptr);
1439 }
1440
1441 #endif
1442
1443 // ------------------------------------------------------------------------------------------- end of inline functions
1444
1445 // Signal error from inside lcms code
1446
1447 void cdecl cmsSignalError(int ErrorCode, const char *ErrorText, ...);
1448
1449 // Alignment handling (needed in ReadLUT16 and ReadLUT8)
1450
1451 typedef struct {
1452 icS15Fixed16Number a;
1453 icUInt16Number b;
1454
1455 } _cmsTestAlign16;
1456
1457 #define SIZEOF_UINT16_ALIGNED (sizeof(_cmsTestAlign16) - sizeof(icS15Fixed16Number))
1458
1459 typedef struct {
1460 icS15Fixed16Number a;
1461 icUInt8Number b;
1462
1463 } _cmsTestAlign8;
1464
1465 #define SIZEOF_UINT8_ALIGNED (sizeof(_cmsTestAlign8) - sizeof(icS15Fixed16Number))
1466
1467
1468 // Fixed point
1469
1470
1471 typedef icInt32Number Fixed32; // Fixed 15.16 whith sign
1472
1473 #define INT_TO_FIXED(x) ((x)<<16)
1474 #define DOUBLE_TO_FIXED(x) ((Fixed32) ((x)*65536.0+0.5))
1475 #define FIXED_TO_INT(x) ((x)>>16)
1476 #define FIXED_REST_TO_INT(x) ((x)& 0xFFFFU)
1477 #define FIXED_TO_DOUBLE(x) (((double)x)/65536.0)
1478 #define ROUND_FIXED_TO_INT(x) (((x)+0x8000)>>16)
1479
1480
1481 Fixed32 cdecl FixedMul(Fixed32 a, Fixed32 b);
1482 Fixed32 cdecl FixedSquare(Fixed32 a);
1483
1484
1485 #ifdef USE_INLINE
1486
ToFixedDomain(int a)1487 LCMS_INLINE Fixed32 ToFixedDomain(int a) { return a + ((a + 0x7fff) / 0xffff); }
FromFixedDomain(Fixed32 a)1488 LCMS_INLINE int FromFixedDomain(Fixed32 a) { return a - ((a + 0x7fff) >> 16); }
1489
1490 #else
1491
1492 Fixed32 cdecl ToFixedDomain(int a); // (a * 65536.0 / 65535.0)
1493 int cdecl FromFixedDomain(Fixed32 a); // (a * 65535.0 + .5)
1494
1495 #endif
1496
1497 Fixed32 cdecl FixedLERP(Fixed32 a, Fixed32 l, Fixed32 h);
1498 WORD cdecl FixedScale(WORD a, Fixed32 s);
1499
1500 // Vector & Matrix operations. I'm using the notation frequently found in
1501 // literature. Mostly 'Graphic Gems' samples. Not to be same routines.
1502
1503 // Vector members
1504
1505 #define VX 0
1506 #define VY 1
1507 #define VZ 2
1508
1509 typedef struct { // Fixed 15.16 bits vector
1510 Fixed32 n[3];
1511 } WVEC3, FAR* LPWVEC3;
1512
1513 typedef struct { // Matrix (Fixed 15.16)
1514 WVEC3 v[3];
1515 } WMAT3, FAR* LPWMAT3;
1516
1517
1518
1519 void cdecl VEC3init(LPVEC3 r, double x, double y, double z); // double version
1520 void cdecl VEC3initF(LPWVEC3 r, double x, double y, double z); // Fix32 version
1521 void cdecl VEC3toFix(LPWVEC3 r, LPVEC3 v);
1522 void cdecl VEC3fromFix(LPVEC3 r, LPWVEC3 v);
1523 void cdecl VEC3scaleFix(LPWORD r, LPWVEC3 Scale);
1524 void cdecl VEC3swap(LPVEC3 a, LPVEC3 b);
1525 void cdecl VEC3divK(LPVEC3 r, LPVEC3 v, double d);
1526 void cdecl VEC3perK(LPVEC3 r, LPVEC3 v, double d);
1527 void cdecl VEC3minus(LPVEC3 r, LPVEC3 a, LPVEC3 b);
1528 void cdecl VEC3perComp(LPVEC3 r, LPVEC3 a, LPVEC3 b);
1529 LCMSBOOL cdecl VEC3equal(LPWVEC3 a, LPWVEC3 b, double Tolerance);
1530 LCMSBOOL cdecl VEC3equalF(LPVEC3 a, LPVEC3 b, double Tolerance);
1531 void cdecl VEC3scaleAndCut(LPWVEC3 r, LPVEC3 v, double d);
1532 void cdecl VEC3cross(LPVEC3 r, LPVEC3 u, LPVEC3 v);
1533 void cdecl VEC3saturate(LPVEC3 v);
1534 double cdecl VEC3distance(LPVEC3 a, LPVEC3 b);
1535 double cdecl VEC3length(LPVEC3 a);
1536
1537 void cdecl MAT3identity(LPMAT3 a);
1538 void cdecl MAT3per(LPMAT3 r, LPMAT3 a, LPMAT3 b);
1539 void cdecl MAT3perK(LPMAT3 r, LPMAT3 v, double d);
1540 int cdecl MAT3inverse(LPMAT3 a, LPMAT3 b);
1541 LCMSBOOL cdecl MAT3solve(LPVEC3 x, LPMAT3 a, LPVEC3 b);
1542 double cdecl MAT3det(LPMAT3 m);
1543 void cdecl MAT3eval(LPVEC3 r, LPMAT3 a, LPVEC3 v);
1544 void cdecl MAT3toFix(LPWMAT3 r, LPMAT3 v);
1545 void cdecl MAT3fromFix(LPMAT3 r, LPWMAT3 v);
1546 void cdecl MAT3evalW(LPWVEC3 r, LPWMAT3 a, LPWVEC3 v);
1547 LCMSBOOL cdecl MAT3isIdentity(LPWMAT3 a, double Tolerance);
1548 void cdecl MAT3scaleAndCut(LPWMAT3 r, LPMAT3 v, double d);
1549
1550 // Is a table linear?
1551
1552 int cdecl cmsIsLinear(WORD Table[], int nEntries);
1553
1554 // I hold this structures describing domain
1555 // details mainly for optimization purposes.
1556
1557 struct _lcms_l16params_struc;
1558
1559 typedef void (* _cms3DLERP)(WORD Input[],
1560 WORD Output[],
1561 WORD LutTable[],
1562 struct _lcms_l16params_struc* p);
1563
1564
1565
1566 typedef struct _lcms_l8opt_struc { // Used on 8 bit interpolations
1567
1568 unsigned int X0[256], Y0[256], Z0[256];
1569 WORD rx[256], ry[256], rz[256];
1570
1571 } L8PARAMS, FAR* LPL8PARAMS;
1572
1573 typedef struct _lcms_l16params_struc { // Used on 16 bits interpolations
1574
1575 int nSamples; // Valid on all kinds of tables
1576 int nInputs; // != 1 only in 3D interpolation
1577 int nOutputs; // != 1 only in 3D interpolation
1578
1579 WORD Domain;
1580
1581 int opta1, opta2;
1582 int opta3, opta4; // Optimization for 3D LUT
1583 int opta5, opta6;
1584 int opta7, opta8;
1585
1586 _cms3DLERP Interp3D; // The interpolation routine
1587
1588 LPL8PARAMS p8; // Points to some tables for 8-bit speedup
1589
1590 } L16PARAMS, *LPL16PARAMS;
1591
1592
1593 void cdecl cmsCalcL16Params(int nSamples, LPL16PARAMS p);
1594 void cdecl cmsCalcCLUT16Params(int nSamples, int InputChan, int OutputChan, LPL16PARAMS p);
1595 void cdecl cmsCalcCLUT16ParamsEx(int nSamples, int InputChan, int OutputChan,
1596 LCMSBOOL lUseTetrahedral, LPL16PARAMS p);
1597
1598 WORD cdecl cmsLinearInterpLUT16(WORD Value, WORD LutTable[], LPL16PARAMS p);
1599 Fixed32 cdecl cmsLinearInterpFixed(WORD Value1, WORD LutTable[], LPL16PARAMS p);
1600 WORD cdecl cmsReverseLinearInterpLUT16(WORD Value, WORD LutTable[], LPL16PARAMS p);
1601
1602 void cdecl cmsTrilinearInterp16(WORD Input[],
1603 WORD Output[],
1604 WORD LutTable[],
1605 LPL16PARAMS p);
1606
1607 void cdecl cmsTetrahedralInterp16(WORD Input[],
1608 WORD Output[],
1609 WORD LutTable[], LPL16PARAMS p);
1610
1611 void cdecl cmsTetrahedralInterp8(WORD Input[],
1612 WORD Output[],
1613 WORD LutTable[], LPL16PARAMS p);
1614
1615 // LUT handling
1616
1617 #define LUT_HASMATRIX 0x0001 // Do-op Flags
1618 #define LUT_HASTL1 0x0002
1619 #define LUT_HASTL2 0x0008
1620 #define LUT_HAS3DGRID 0x0010
1621
1622 // New in rev 4.0 of ICC spec
1623
1624 #define LUT_HASMATRIX3 0x0020 // Matrix + offset for LutAToB
1625 #define LUT_HASMATRIX4 0x0040 // Matrix + offset for LutBToA
1626
1627 #define LUT_HASTL3 0x0100 // '3' curves for LutAToB
1628 #define LUT_HASTL4 0x0200 // '4' curves for LutBToA
1629
1630 // V4 emulation
1631
1632 #define LUT_V4_OUTPUT_EMULATE_V2 0x10000 // Is a V4 output LUT, emulating V2
1633 #define LUT_V4_INPUT_EMULATE_V2 0x20000 // Is a V4 input LUT, emulating V2
1634 #define LUT_V2_OUTPUT_EMULATE_V4 0x40000 // Is a V2 output LUT, emulating V4
1635 #define LUT_V2_INPUT_EMULATE_V4 0x80000 // Is a V2 input LUT, emulating V4
1636
1637
1638 struct _lcms_LUT_struc {
1639
1640 DWORD wFlags;
1641 WMAT3 Matrix; // 15fixed16 matrix
1642
1643 unsigned int InputChan;
1644 unsigned int OutputChan;
1645 unsigned int InputEntries;
1646 unsigned int OutputEntries;
1647 unsigned int cLutPoints;
1648
1649
1650 LPWORD L1[MAXCHANNELS]; // First linearization
1651 LPWORD L2[MAXCHANNELS]; // Last linearization
1652
1653 LPWORD T; // 3D CLUT
1654 unsigned int Tsize; // CLUT size in bytes
1655
1656 // Parameters & Optimizations
1657
1658 L16PARAMS In16params;
1659 L16PARAMS Out16params;
1660 L16PARAMS CLut16params;
1661
1662 int Intent; // Accomplished intent
1663
1664 // New for Rev 4.0 of spec (reserved)
1665
1666 WMAT3 Mat3;
1667 WVEC3 Ofs3;
1668 LPWORD L3[MAXCHANNELS];
1669 L16PARAMS L3params;
1670 unsigned int L3Entries;
1671
1672 WMAT3 Mat4;
1673 WVEC3 Ofs4;
1674 LPWORD L4[MAXCHANNELS];
1675 L16PARAMS L4params;
1676 unsigned int L4Entries;
1677
1678 // Gray axes fixup. Only on v2 8-bit Lab LUT
1679
1680 LCMSBOOL FixGrayAxes;
1681
1682
1683 // Parameters used for curve creation
1684
1685 LCMSGAMMAPARAMS LCurvesSeed[4][MAXCHANNELS];
1686
1687
1688 }; // LUT, FAR* LPLUT;
1689
1690
1691 LCMSBOOL cdecl _cmsSmoothEndpoints(LPWORD Table, int nEntries);
1692
1693
1694 // CRC of gamma tables
1695
1696 unsigned int _cmsCrc32OfGammaTable(LPGAMMATABLE Table);
1697
1698 // Sampled curves
1699
1700 LPSAMPLEDCURVE cdecl cmsAllocSampledCurve(int nItems);
1701 void cdecl cmsFreeSampledCurve(LPSAMPLEDCURVE p);
1702 LPSAMPLEDCURVE cdecl cmsDupSampledCurve(LPSAMPLEDCURVE p);
1703
1704 LPSAMPLEDCURVE cdecl cmsConvertGammaToSampledCurve(LPGAMMATABLE Gamma, int nPoints);
1705 LPGAMMATABLE cdecl cmsConvertSampledCurveToGamma(LPSAMPLEDCURVE Sampled, double Max);
1706
1707 void cdecl cmsEndpointsOfSampledCurve(LPSAMPLEDCURVE p, double* Min, double* Max);
1708 void cdecl cmsClampSampledCurve(LPSAMPLEDCURVE p, double Min, double Max);
1709 LCMSBOOL cdecl cmsSmoothSampledCurve(LPSAMPLEDCURVE Tab, double SmoothingLambda);
1710 void cdecl cmsRescaleSampledCurve(LPSAMPLEDCURVE p, double Min, double Max, int nPoints);
1711
1712 LPSAMPLEDCURVE cdecl cmsJoinSampledCurves(LPSAMPLEDCURVE X, LPSAMPLEDCURVE Y, int nResultingPoints);
1713
1714 // Shaper/Matrix handling
1715
1716 #define MATSHAPER_HASMATRIX 0x0001 // Do-ops flags
1717 #define MATSHAPER_HASSHAPER 0x0002
1718 #define MATSHAPER_INPUT 0x0004 // Behaviour
1719 #define MATSHAPER_OUTPUT 0x0008
1720 #define MATSHAPER_HASINPSHAPER 0x0010
1721 #define MATSHAPER_ALLSMELTED (MATSHAPER_INPUT|MATSHAPER_OUTPUT)
1722
1723
1724 typedef struct {
1725 DWORD dwFlags;
1726
1727 WMAT3 Matrix;
1728
1729 L16PARAMS p16; // Primary curve
1730 LPWORD L[3];
1731
1732 L16PARAMS p2_16; // Secondary curve (used as input in smelted ones)
1733 LPWORD L2[3];
1734
1735 } MATSHAPER, FAR* LPMATSHAPER;
1736
1737 LPMATSHAPER cdecl cmsAllocMatShaper(LPMAT3 matrix, LPGAMMATABLE Shaper[], DWORD Behaviour);
1738 LPMATSHAPER cdecl cmsAllocMatShaper2(LPMAT3 matrix, LPGAMMATABLE In[], LPGAMMATABLE Out[], DWORD Behaviour);
1739
1740 void cdecl cmsFreeMatShaper(LPMATSHAPER MatShaper);
1741 void cdecl cmsEvalMatShaper(LPMATSHAPER MatShaper, WORD In[], WORD Out[]);
1742
1743 LCMSBOOL cdecl cmsReadICCMatrixRGB2XYZ(LPMAT3 r, cmsHPROFILE hProfile);
1744
1745 LPMATSHAPER cdecl cmsBuildInputMatrixShaper(cmsHPROFILE InputProfile);
1746 LPMATSHAPER cdecl cmsBuildOutputMatrixShaper(cmsHPROFILE OutputProfile);
1747
1748
1749
1750 // White Point & Primary chromas handling
1751 LCMSBOOL cdecl cmsAdaptationMatrix(LPMAT3 r, LPMAT3 ConeMatrix, LPcmsCIEXYZ FromIll, LPcmsCIEXYZ ToIll);
1752 LCMSBOOL cdecl cmsAdaptMatrixToD50(LPMAT3 r, LPcmsCIExyY SourceWhitePt);
1753 LCMSBOOL cdecl cmsAdaptMatrixFromD50(LPMAT3 r, LPcmsCIExyY DestWhitePt);
1754
1755 LCMSBOOL cdecl cmsReadChromaticAdaptationMatrix(LPMAT3 r, cmsHPROFILE hProfile);
1756
1757 // Inter-PCS conversion routines. They assume D50 as white point.
1758 void cdecl cmsXYZ2LabEncoded(WORD XYZ[3], WORD Lab[3]);
1759 void cdecl cmsLab2XYZEncoded(WORD Lab[3], WORD XYZ[3]);
1760
1761 // Retrieve text representation of WP
1762 void cdecl _cmsIdentifyWhitePoint(char *Buffer, LPcmsCIEXYZ WhitePt);
1763
1764 // Quantize to WORD in a (MaxSamples - 1) domain
1765 WORD cdecl _cmsQuantizeVal(double i, int MaxSamples);
1766
1767 LPcmsNAMEDCOLORLIST cdecl cmsAllocNamedColorList(int n);
1768 int cdecl cmsReadICCnamedColorList(cmsHTRANSFORM xform, cmsHPROFILE hProfile, icTagSignature sig);
1769 void cdecl cmsFreeNamedColorList(LPcmsNAMEDCOLORLIST List);
1770 LCMSBOOL cdecl cmsAppendNamedColor(cmsHTRANSFORM xform, const char* Name, WORD PCS[3], WORD Colorant[MAXCHANNELS]);
1771
1772
1773 // I/O
1774
1775 #define MAX_TABLE_TAG 100
1776
1777 // This is the internal struct holding profile details.
1778
1779 typedef struct _lcms_iccprofile_struct {
1780
1781 void* stream; // Associated stream. If NULL,
1782 // tags are supposed to be in
1783 // memory rather than in a file.
1784
1785 // Only most important items found in ICC profile
1786
1787 icProfileClassSignature DeviceClass;
1788 icColorSpaceSignature ColorSpace;
1789 icColorSpaceSignature PCS;
1790 icRenderingIntent RenderingIntent;
1791 icUInt32Number flags;
1792 icUInt32Number attributes;
1793 cmsCIEXYZ Illuminant;
1794
1795 // Additions for V4 profiles
1796
1797 icUInt32Number Version;
1798 MAT3 ChromaticAdaptation;
1799 cmsCIEXYZ MediaWhitePoint;
1800 cmsCIEXYZ MediaBlackPoint;
1801 BYTE ProfileID[16];
1802
1803
1804 // Dictionary
1805
1806 icInt32Number TagCount;
1807 icTagSignature TagNames[MAX_TABLE_TAG];
1808 size_t TagSizes[MAX_TABLE_TAG];
1809 size_t TagOffsets[MAX_TABLE_TAG];
1810 LPVOID TagPtrs[MAX_TABLE_TAG];
1811
1812 char PhysicalFile[MAX_PATH];
1813
1814 LCMSBOOL IsWrite;
1815 LCMSBOOL SaveAs8Bits;
1816
1817 struct tm Created;
1818
1819 // I/O handlers
1820
1821 size_t (* Read)(void *buffer, size_t size, size_t count, struct _lcms_iccprofile_struct* Icc);
1822
1823 LCMSBOOL (* Seek)(struct _lcms_iccprofile_struct* Icc, size_t offset);
1824 LCMSBOOL (* Close)(struct _lcms_iccprofile_struct* Icc);
1825 size_t (* Tell)(struct _lcms_iccprofile_struct* Icc);
1826
1827 // Writting
1828
1829 LCMSBOOL (* Write)(struct _lcms_iccprofile_struct* Icc, size_t size, LPVOID Ptr);
1830
1831 size_t UsedSpace;
1832
1833
1834 } LCMSICCPROFILE, FAR* LPLCMSICCPROFILE;
1835
1836
1837 // Create an empty template for virtual profiles
1838 cmsHPROFILE cdecl _cmsCreateProfilePlaceholder(void);
1839
1840 // Search into tag dictionary
1841 icInt32Number cdecl _cmsSearchTag(LPLCMSICCPROFILE Profile, icTagSignature sig, LCMSBOOL lSignalError);
1842
1843 // Search for a particular tag, replace if found or add new one else
1844 LPVOID _cmsInitTag(LPLCMSICCPROFILE Icc, icTagSignature sig, size_t size, const void* Init);
1845
1846
1847 LPLCMSICCPROFILE cdecl _cmsCreateProfileFromFilePlaceholder(const char* FileName);
1848 LPLCMSICCPROFILE cdecl _cmsCreateProfileFromMemPlaceholder(LPVOID MemPtr, DWORD dwSize);
1849
1850 void _cmsSetSaveToDisk(LPLCMSICCPROFILE Icc, const char* FileName);
1851 void _cmsSetSaveToMemory(LPLCMSICCPROFILE Icc, LPVOID MemPtr, size_t dwSize);
1852
1853
1854
1855 // These macros unpack format specifiers into integers
1856
1857 #define T_DITHER(s) (((s)>>22)&1)
1858 #define T_COLORSPACE(s) (((s)>>16)&31)
1859 #define T_SWAPFIRST(s) (((s)>>14)&1)
1860 #define T_FLAVOR(s) (((s)>>13)&1)
1861 #define T_PLANAR(p) (((p)>>12)&1)
1862 #define T_ENDIAN16(e) (((e)>>11)&1)
1863 #define T_DOSWAP(e) (((e)>>10)&1)
1864 #define T_EXTRA(e) (((e)>>7)&7)
1865 #define T_CHANNELS(c) (((c)>>3)&15)
1866 #define T_BYTES(b) ((b)&7)
1867
1868
1869
1870 // Internal XFORM struct
1871 struct _cmstransform_struct;
1872
1873 // Full xform
1874 typedef void (* _cmsCOLORCALLBACKFN)(struct _cmstransform_struct *Transform,
1875 LPVOID InputBuffer,
1876 LPVOID OutputBuffer, unsigned int Size);
1877
1878 // intermediate pass, from WORD[] to WORD[]
1879
1880 typedef void (* _cmsADJFN)(WORD In[], WORD Out[], LPWMAT3 m, LPWVEC3 b);
1881
1882 typedef void (* _cmsTRANSFN)(struct _cmstransform_struct *Transform,
1883 WORD In[], WORD Out[]);
1884
1885 typedef void (* _cmsCNVRT)(WORD In[], WORD Out[]);
1886
1887 typedef LPBYTE (* _cmsFIXFN)(register struct _cmstransform_struct *info,
1888 register WORD ToUnroll[],
1889 register LPBYTE Buffer);
1890
1891
1892
1893 // Transformation
1894 typedef struct _cmstransform_struct {
1895
1896 // Keep formats for further reference
1897 DWORD InputFormat, OutputFormat;
1898
1899 DWORD StrideIn, StrideOut; // Planar support
1900
1901 int Intent, ProofIntent;
1902 int DoGamutCheck;
1903
1904
1905 cmsHPROFILE InputProfile;
1906 cmsHPROFILE OutputProfile;
1907 cmsHPROFILE PreviewProfile;
1908
1909 icColorSpaceSignature EntryColorSpace;
1910 icColorSpaceSignature ExitColorSpace;
1911
1912 DWORD dwOriginalFlags; // Flags as specified by user
1913
1914 WMAT3 m1, m2; // Matrix holding inter PCS operation
1915 WVEC3 of1, of2; // Offset terms
1916
1917 _cmsCOLORCALLBACKFN xform;
1918
1919 // Steps in xFORM
1920
1921 _cmsFIXFN FromInput;
1922 _cmsTRANSFN FromDevice;
1923 _cmsADJFN Stage1;
1924 _cmsADJFN Stage2;
1925 _cmsTRANSFN ToDevice;
1926 _cmsFIXFN ToOutput;
1927
1928 // LUTs
1929
1930 LPLUT Device2PCS;
1931 LPLUT PCS2Device;
1932 LPLUT Gamut; // Gamut check
1933 LPLUT Preview; // Preview (Proof)
1934
1935 LPLUT DeviceLink; // Precalculated grid - device link profile
1936 LPLUT GamutCheck; // Precalculated device -> gamut check
1937
1938 // Matrix/Shapers
1939
1940 LPMATSHAPER InMatShaper;
1941 LPMATSHAPER OutMatShaper;
1942 LPMATSHAPER SmeltMatShaper;
1943
1944 // Phase of Lab/XYZ, Abs/Rel
1945
1946 int Phase1, Phase2, Phase3;
1947
1948 // Named color table
1949
1950 LPcmsNAMEDCOLORLIST NamedColorList;
1951
1952 // Flag for transform involving v4 profiles
1953
1954 LCMSBOOL lInputV4Lab, lOutputV4Lab;
1955
1956
1957 // 1-pixel cache
1958
1959 WORD CacheIn[MAXCHANNELS];
1960 WORD CacheOut[MAXCHANNELS];
1961
1962 double AdaptationState; // Figure for v4 incomplete state of adaptation
1963
1964 LCMS_RWLOCK_T rwlock;
1965
1966 } _cmsTRANSFORM,FAR *_LPcmsTRANSFORM;
1967
1968
1969
1970 // Packing & Unpacking
1971
1972 _cmsFIXFN cdecl _cmsIdentifyInputFormat(_LPcmsTRANSFORM xform, DWORD dwInput);
1973 _cmsFIXFN cdecl _cmsIdentifyOutputFormat(_LPcmsTRANSFORM xform, DWORD dwOutput);
1974
1975
1976 // Conversion
1977
1978 #define XYZRel 0
1979 #define LabRel 1
1980
1981
1982 int cdecl cmsChooseCnvrt(int Absolute,
1983 int Phase1, LPcmsCIEXYZ BlackPointIn,
1984 LPcmsCIEXYZ WhitePointIn,
1985 LPcmsCIEXYZ IlluminantIn,
1986 LPMAT3 ChromaticAdaptationMatrixIn,
1987
1988 int Phase2, LPcmsCIEXYZ BlackPointOut,
1989 LPcmsCIEXYZ WhitePointOut,
1990 LPcmsCIEXYZ IlluminantOut,
1991 LPMAT3 ChromaticAdaptationMatrixOut,
1992 int DoBPC,
1993 double AdaptationState,
1994 _cmsADJFN *fn1,
1995 LPWMAT3 wm, LPWVEC3 wof);
1996
1997
1998
1999 // Clamping & Gamut handling
2000
2001 LCMSBOOL cdecl _cmsEndPointsBySpace(icColorSpaceSignature Space,
2002 WORD **White, WORD **Black, int *nOutputs);
2003
2004 WORD * cdecl _cmsWhiteBySpace(icColorSpaceSignature Space);
2005
2006
2007
2008 WORD cdecl Clamp_L(Fixed32 in);
2009 WORD cdecl Clamp_ab(Fixed32 in);
2010
2011 // Detection of black point
2012
2013 #define LCMS_BPFLAGS_D50_ADAPTED 0x0001
2014
2015 int cdecl cmsDetectBlackPoint(LPcmsCIEXYZ BlackPoint, cmsHPROFILE hProfile, int Intent, DWORD dwFlags);
2016
2017 // choose reasonable resolution
2018 int cdecl _cmsReasonableGridpointsByColorspace(icColorSpaceSignature Colorspace, DWORD dwFlags);
2019
2020 // Precalculate device link
2021 LPLUT cdecl _cmsPrecalculateDeviceLink(cmsHTRANSFORM h, DWORD dwFlags);
2022
2023 // Precalculate black preserving device link
2024 LPLUT _cmsPrecalculateBlackPreservingDeviceLink(cmsHTRANSFORM hCMYK2CMYK, DWORD dwFlags);
2025
2026 // Precalculate gamut check
2027 LPLUT cdecl _cmsPrecalculateGamutCheck(cmsHTRANSFORM h);
2028
2029 // Hot fixes bad profiles
2030 LCMSBOOL cdecl _cmsFixWhiteMisalignment(_LPcmsTRANSFORM p);
2031
2032 // Marks LUT as 8 bit on input
2033 LPLUT cdecl _cmsBlessLUT8(LPLUT Lut);
2034
2035 // Compute gamut boundary
2036 LPLUT cdecl _cmsComputeGamutLUT(cmsHPROFILE hProfile, int Intent);
2037
2038 // Compute softproof
2039 LPLUT cdecl _cmsComputeSoftProofLUT(cmsHPROFILE hProfile, int nIntent);
2040
2041 // Find a suitable prelinearization tables, matching the given transform
2042 void cdecl _cmsComputePrelinearizationTablesFromXFORM(cmsHTRANSFORM h[], int nTransforms, LPLUT Grid);
2043
2044
2045 // Build a tone curve for K->K' if possible (only works on CMYK)
2046 LPGAMMATABLE _cmsBuildKToneCurve(cmsHTRANSFORM hCMYK2CMYK, int nPoints);
2047
2048 // Validates a LUT
2049 LCMSBOOL cdecl _cmsValidateLUT(LPLUT NewLUT);
2050
2051
2052 // These are two VITAL macros, from converting between 8 and 16 bit
2053 // representation.
2054
2055 #define RGB_8_TO_16(rgb) (WORD) ((((WORD) (rgb)) << 8)|(rgb))
2056 #define RGB_16_TO_8(rgb) (BYTE) ((((rgb) * 65281 + 8388608) >> 24) & 0xFF)
2057
2058
2059 #endif // LCMS_APIONLY
2060
2061
2062 #define __cms_H
2063
2064 #ifdef __cplusplus
2065 }
2066 #endif
2067
2068 #endif
2069
2070