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