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.  Oracle designates this
   7  * particular file as subject to the "Classpath" exception as provided
   8  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  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 //
  32 //  Little Color Management System
  33 //  Copyright (c) 1998-2020 Marti Maria Saguer
  34 //
  35 // Permission is hereby granted, free of charge, to any person obtaining
  36 // a copy of this software and associated documentation files (the "Software"),
  37 // to deal in the Software without restriction, including without limitation
  38 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  39 // and/or sell copies of the Software, and to permit persons to whom the Software
  40 // is furnished to do so, subject to the following conditions:
  41 //
  42 // The above copyright notice and this permission notice shall be included in
  43 // all copies or substantial portions of the Software.
  44 //
  45 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  46 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  47 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  48 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  49 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  50 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  51 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  52 //
  53 //---------------------------------------------------------------------------------
  54 //
  55 // This is the plug-in header file. Normal LittleCMS clients should not use it.
  56 // It is provided for plug-in writters that may want to access the support
  57 // functions to do low level operations. All plug-in related structures
  58 // are defined here. Including this file forces to include the standard API too.
  59 
  60 #ifndef _lcms_plugin_H
  61 
  62 // Deal with Microsoft's attempt at deprecating C standard runtime functions
  63 #ifdef _MSC_VER
  64 #    if (_MSC_VER >= 1400)
  65 #      ifndef _CRT_SECURE_NO_DEPRECATE
  66 #        define _CRT_SECURE_NO_DEPRECATE
  67 #      endif
  68 #      ifndef _CRT_SECURE_NO_WARNINGS
  69 #        define _CRT_SECURE_NO_WARNINGS
  70 #      endif
  71 #    endif
  72 #endif
  73 
  74 #ifndef _lcms2_H
  75 #include "lcms2.h"
  76 #endif
  77 
  78 // We need some standard C functions.
  79 #include <stdlib.h>
  80 #include <math.h>
  81 #include <stdarg.h>
  82 #include <memory.h>
  83 #include <string.h>
  84 
  85 
  86 #ifndef CMS_USE_CPP_API
  87 #   ifdef __cplusplus
  88 extern "C" {
  89 #   endif
  90 #endif
  91 
  92 // Vector & Matrix operations -----------------------------------------------------------------------
  93 
  94 // Axis of the matrix/array. No specific meaning at all.
  95 #define VX      0
  96 #define VY      1
  97 #define VZ      2
  98 
  99 // Vectors
 100 typedef struct {
 101     cmsFloat64Number n[3];
 102 
 103     } cmsVEC3;
 104 
 105 // 3x3 Matrix
 106 typedef struct {
 107     cmsVEC3 v[3];
 108 
 109     } cmsMAT3;
 110 
 111 CMSAPI void               CMSEXPORT _cmsVEC3init(cmsVEC3* r, cmsFloat64Number x, cmsFloat64Number y, cmsFloat64Number z);
 112 CMSAPI void               CMSEXPORT _cmsVEC3minus(cmsVEC3* r, const cmsVEC3* a, const cmsVEC3* b);
 113 CMSAPI void               CMSEXPORT _cmsVEC3cross(cmsVEC3* r, const cmsVEC3* u, const cmsVEC3* v);
 114 CMSAPI cmsFloat64Number   CMSEXPORT _cmsVEC3dot(const cmsVEC3* u, const cmsVEC3* v);
 115 CMSAPI cmsFloat64Number   CMSEXPORT _cmsVEC3length(const cmsVEC3* a);
 116 CMSAPI cmsFloat64Number   CMSEXPORT _cmsVEC3distance(const cmsVEC3* a, const cmsVEC3* b);
 117 
 118 CMSAPI void               CMSEXPORT _cmsMAT3identity(cmsMAT3* a);
 119 CMSAPI cmsBool            CMSEXPORT _cmsMAT3isIdentity(const cmsMAT3* a);
 120 CMSAPI void               CMSEXPORT _cmsMAT3per(cmsMAT3* r, const cmsMAT3* a, const cmsMAT3* b);
 121 CMSAPI cmsBool            CMSEXPORT _cmsMAT3inverse(const cmsMAT3* a, cmsMAT3* b);
 122 CMSAPI cmsBool            CMSEXPORT _cmsMAT3solve(cmsVEC3* x, cmsMAT3* a, cmsVEC3* b);
 123 CMSAPI void               CMSEXPORT _cmsMAT3eval(cmsVEC3* r, const cmsMAT3* a, const cmsVEC3* v);
 124 
 125 
 126 // MD5 low level  -------------------------------------------------------------------------------------
 127 
 128 CMSAPI cmsHANDLE          CMSEXPORT cmsMD5alloc(cmsContext ContextID);
 129 CMSAPI void               CMSEXPORT cmsMD5add(cmsHANDLE Handle, const cmsUInt8Number* buf, cmsUInt32Number len);
 130 CMSAPI void               CMSEXPORT cmsMD5finish(cmsProfileID* ProfileID, cmsHANDLE Handle);
 131 
 132 // Error logging  -------------------------------------------------------------------------------------
 133 
 134 CMSAPI void               CMSEXPORT  cmsSignalError(cmsContext ContextID, cmsUInt32Number ErrorCode, const char *ErrorText, ...);
 135 
 136 // Memory management ----------------------------------------------------------------------------------
 137 
 138 CMSAPI void*              CMSEXPORT _cmsMalloc(cmsContext ContextID, cmsUInt32Number size);
 139 CMSAPI void*              CMSEXPORT _cmsMallocZero(cmsContext ContextID, cmsUInt32Number size);
 140 CMSAPI void*              CMSEXPORT _cmsCalloc(cmsContext ContextID, cmsUInt32Number num, cmsUInt32Number size);
 141 CMSAPI void*              CMSEXPORT _cmsRealloc(cmsContext ContextID, void* Ptr, cmsUInt32Number NewSize);
 142 CMSAPI void               CMSEXPORT _cmsFree(cmsContext ContextID, void* Ptr);
 143 CMSAPI void*              CMSEXPORT _cmsDupMem(cmsContext ContextID, const void* Org, cmsUInt32Number size);
 144 
 145 // I/O handler ----------------------------------------------------------------------------------
 146 
 147 struct _cms_io_handler {
 148 
 149     void* stream;   // Associated stream, which is implemented differently depending on media.
 150 
 151     cmsContext        ContextID;
 152     cmsUInt32Number   UsedSpace;
 153     cmsUInt32Number   ReportedSize;
 154     char              PhysicalFile[cmsMAX_PATH];
 155 
 156     cmsUInt32Number   (* Read)(struct _cms_io_handler* iohandler, void *Buffer,
 157                                                                   cmsUInt32Number size,
 158                                                                   cmsUInt32Number count);
 159     cmsBool           (* Seek)(struct _cms_io_handler* iohandler, cmsUInt32Number offset);
 160     cmsBool           (* Close)(struct _cms_io_handler* iohandler);
 161     cmsUInt32Number   (* Tell)(struct _cms_io_handler* iohandler);
 162     cmsBool           (* Write)(struct _cms_io_handler* iohandler, cmsUInt32Number size,
 163                                                                    const void* Buffer);
 164 };
 165 
 166 // Endianness adjust functions
 167 CMSAPI cmsUInt16Number   CMSEXPORT  _cmsAdjustEndianess16(cmsUInt16Number Word);
 168 CMSAPI cmsUInt32Number   CMSEXPORT  _cmsAdjustEndianess32(cmsUInt32Number Value);
 169 CMSAPI void              CMSEXPORT  _cmsAdjustEndianess64(cmsUInt64Number* Result, cmsUInt64Number* QWord);
 170 
 171 // Helper IO functions
 172 CMSAPI cmsBool           CMSEXPORT  _cmsReadUInt8Number(cmsIOHANDLER* io,  cmsUInt8Number* n);
 173 CMSAPI cmsBool           CMSEXPORT  _cmsReadUInt16Number(cmsIOHANDLER* io, cmsUInt16Number* n);
 174 CMSAPI cmsBool           CMSEXPORT  _cmsReadUInt32Number(cmsIOHANDLER* io, cmsUInt32Number* n);
 175 CMSAPI cmsBool           CMSEXPORT  _cmsReadFloat32Number(cmsIOHANDLER* io, cmsFloat32Number* n);
 176 CMSAPI cmsBool           CMSEXPORT  _cmsReadUInt64Number(cmsIOHANDLER* io, cmsUInt64Number* n);
 177 CMSAPI cmsBool           CMSEXPORT  _cmsRead15Fixed16Number(cmsIOHANDLER* io, cmsFloat64Number* n);
 178 CMSAPI cmsBool           CMSEXPORT  _cmsReadXYZNumber(cmsIOHANDLER* io, cmsCIEXYZ* XYZ);
 179 CMSAPI cmsBool           CMSEXPORT  _cmsReadUInt16Array(cmsIOHANDLER* io, cmsUInt32Number n, cmsUInt16Number* Array);
 180 
 181 CMSAPI cmsBool           CMSEXPORT  _cmsWriteUInt8Number(cmsIOHANDLER* io, cmsUInt8Number n);
 182 CMSAPI cmsBool           CMSEXPORT  _cmsWriteUInt16Number(cmsIOHANDLER* io, cmsUInt16Number n);
 183 CMSAPI cmsBool           CMSEXPORT  _cmsWriteUInt32Number(cmsIOHANDLER* io, cmsUInt32Number n);
 184 CMSAPI cmsBool           CMSEXPORT  _cmsWriteFloat32Number(cmsIOHANDLER* io, cmsFloat32Number n);
 185 CMSAPI cmsBool           CMSEXPORT  _cmsWriteUInt64Number(cmsIOHANDLER* io, cmsUInt64Number* n);
 186 CMSAPI cmsBool           CMSEXPORT  _cmsWrite15Fixed16Number(cmsIOHANDLER* io, cmsFloat64Number n);
 187 CMSAPI cmsBool           CMSEXPORT  _cmsWriteXYZNumber(cmsIOHANDLER* io, const cmsCIEXYZ* XYZ);
 188 CMSAPI cmsBool           CMSEXPORT  _cmsWriteUInt16Array(cmsIOHANDLER* io, cmsUInt32Number n, const cmsUInt16Number* Array);
 189 
 190 // ICC base tag
 191 typedef struct {
 192     cmsTagTypeSignature  sig;
 193     cmsInt8Number        reserved[4];
 194 
 195 } _cmsTagBase;
 196 
 197 // Type base helper functions
 198 CMSAPI cmsTagTypeSignature  CMSEXPORT _cmsReadTypeBase(cmsIOHANDLER* io);
 199 CMSAPI cmsBool              CMSEXPORT _cmsWriteTypeBase(cmsIOHANDLER* io, cmsTagTypeSignature sig);
 200 
 201 // Alignment functions
 202 CMSAPI cmsBool             CMSEXPORT _cmsReadAlignment(cmsIOHANDLER* io);
 203 CMSAPI cmsBool             CMSEXPORT _cmsWriteAlignment(cmsIOHANDLER* io);
 204 
 205 // To deal with text streams. 2K at most
 206 CMSAPI cmsBool             CMSEXPORT _cmsIOPrintf(cmsIOHANDLER* io, const char* frm, ...);
 207 
 208 // Fixed point helper functions
 209 CMSAPI cmsFloat64Number    CMSEXPORT _cms8Fixed8toDouble(cmsUInt16Number fixed8);
 210 CMSAPI cmsUInt16Number     CMSEXPORT _cmsDoubleTo8Fixed8(cmsFloat64Number val);
 211 
 212 CMSAPI cmsFloat64Number    CMSEXPORT _cms15Fixed16toDouble(cmsS15Fixed16Number fix32);
 213 CMSAPI cmsS15Fixed16Number CMSEXPORT _cmsDoubleTo15Fixed16(cmsFloat64Number v);
 214 
 215 // Date/time helper functions
 216 CMSAPI void                CMSEXPORT _cmsEncodeDateTimeNumber(cmsDateTimeNumber *Dest, const struct tm *Source);
 217 CMSAPI void                CMSEXPORT _cmsDecodeDateTimeNumber(const cmsDateTimeNumber *Source, struct tm *Dest);
 218 
 219 //----------------------------------------------------------------------------------------------------------
 220 
 221 // Shared callbacks for user data
 222 typedef void     (* _cmsFreeUserDataFn)(cmsContext ContextID, void* Data);
 223 typedef void*    (* _cmsDupUserDataFn)(cmsContext ContextID, const void* Data);
 224 
 225 //----------------------------------------------------------------------------------------------------------
 226 
 227 // Plug-in foundation
 228 #define cmsPluginMagicNumber                 0x61637070     // 'acpp'
 229 
 230 #define cmsPluginMemHandlerSig               0x6D656D48     // 'memH'
 231 #define cmsPluginInterpolationSig            0x696E7048     // 'inpH'
 232 #define cmsPluginParametricCurveSig          0x70617248     // 'parH'
 233 #define cmsPluginFormattersSig               0x66726D48     // 'frmH
 234 #define cmsPluginTagTypeSig                  0x74797048     // 'typH'
 235 #define cmsPluginTagSig                      0x74616748     // 'tagH'
 236 #define cmsPluginRenderingIntentSig          0x696E7448     // 'intH'
 237 #define cmsPluginMultiProcessElementSig      0x6D706548     // 'mpeH'
 238 #define cmsPluginOptimizationSig             0x6F707448     // 'optH'
 239 #define cmsPluginTransformSig                0x7A666D48     // 'xfmH'
 240 #define cmsPluginMutexSig                    0x6D747A48     // 'mtxH'
 241 
 242 typedef struct _cmsPluginBaseStruct {
 243 
 244         cmsUInt32Number                Magic;               // 'acpp' signature
 245         cmsUInt32Number                ExpectedVersion;     // Expected version of LittleCMS
 246         cmsUInt32Number                Type;                // Type of plug-in
 247         struct _cmsPluginBaseStruct*   Next;                // For multiple plugin definition. NULL for end of list.
 248 
 249 } cmsPluginBase;
 250 
 251 // Maximum number of types in a plugin array
 252 #define MAX_TYPES_IN_LCMS_PLUGIN    20
 253 
 254 //----------------------------------------------------------------------------------------------------------
 255 
 256 // Memory handler. Each new plug-in type replaces current behaviour
 257 
 258 typedef void* (* _cmsMallocFnPtrType)(cmsContext ContextID, cmsUInt32Number size);
 259 typedef void  (* _cmsFreeFnPtrType)(cmsContext ContextID, void *Ptr);
 260 typedef void* (* _cmsReallocFnPtrType)(cmsContext ContextID, void* Ptr, cmsUInt32Number NewSize);
 261 
 262 typedef void* (* _cmsMalloZerocFnPtrType)(cmsContext ContextID, cmsUInt32Number size);
 263 typedef void* (* _cmsCallocFnPtrType)(cmsContext ContextID, cmsUInt32Number num, cmsUInt32Number size);
 264 typedef void* (* _cmsDupFnPtrType)(cmsContext ContextID, const void* Org, cmsUInt32Number size);
 265 
 266 typedef struct {
 267 
 268         cmsPluginBase base;
 269 
 270         // Required
 271         _cmsMallocFnPtrType  MallocPtr;
 272         _cmsFreeFnPtrType    FreePtr;
 273         _cmsReallocFnPtrType ReallocPtr;
 274 
 275         // Optional
 276        _cmsMalloZerocFnPtrType MallocZeroPtr;
 277        _cmsCallocFnPtrType     CallocPtr;
 278        _cmsDupFnPtrType        DupPtr;
 279 
 280 } cmsPluginMemHandler;
 281 
 282 
 283 // ------------------------------------------------------------------------------------------------------------------
 284 
 285 // Interpolation. 16 bits and floating point versions.
 286 struct _cms_interp_struc;
 287 
 288 // Interpolation callbacks
 289 
 290 // 16 bits forward interpolation. This function performs precision-limited linear interpolation
 291 // and is supposed to be quite fast. Implementation may be tetrahedral or trilinear, and plug-ins may
 292 // choose to implement any other interpolation algorithm.
 293 typedef void (* _cmsInterpFn16)(CMSREGISTER const cmsUInt16Number Input[],
 294                                 CMSREGISTER cmsUInt16Number Output[],
 295                                 CMSREGISTER const struct _cms_interp_struc* p);
 296 
 297 // Floating point forward interpolation. Full precision interpolation using floats. This is not a
 298 // time critical function. Implementation may be tetrahedral or trilinear, and plug-ins may
 299 // choose to implement any other interpolation algorithm.
 300 typedef void (* _cmsInterpFnFloat)(cmsFloat32Number const Input[],
 301                                    cmsFloat32Number Output[],
 302                                    const struct _cms_interp_struc* p);
 303 
 304 
 305 
 306 // This type holds a pointer to an interpolator that can be either 16 bits or float
 307 typedef union {
 308     _cmsInterpFn16       Lerp16;            // Forward interpolation in 16 bits
 309     _cmsInterpFnFloat    LerpFloat;         // Forward interpolation in floating point
 310 } cmsInterpFunction;
 311 
 312 // Flags for interpolator selection
 313 #define CMS_LERP_FLAGS_16BITS             0x0000        // The default
 314 #define CMS_LERP_FLAGS_FLOAT              0x0001        // Requires different implementation
 315 #define CMS_LERP_FLAGS_TRILINEAR          0x0100        // Hint only
 316 
 317 
 318 #define MAX_INPUT_DIMENSIONS 8
 319 
 320 typedef struct _cms_interp_struc {  // Used on all interpolations. Supplied by lcms2 when calling the interpolation function
 321 
 322     cmsContext ContextID;     // The calling thread
 323 
 324     cmsUInt32Number dwFlags;  // Keep original flags
 325     cmsUInt32Number nInputs;  // != 1 only in 3D interpolation
 326     cmsUInt32Number nOutputs; // != 1 only in 3D interpolation
 327 
 328     cmsUInt32Number nSamples[MAX_INPUT_DIMENSIONS];  // Valid on all kinds of tables
 329     cmsUInt32Number Domain[MAX_INPUT_DIMENSIONS];    // Domain = nSamples - 1
 330 
 331     cmsUInt32Number opta[MAX_INPUT_DIMENSIONS];     // Optimization for 3D CLUT. This is the number of nodes premultiplied for each
 332                                                     // dimension. For example, in 7 nodes, 7, 7^2 , 7^3, 7^4, etc. On non-regular
 333                                                     // Samplings may vary according of the number of nodes for each dimension.
 334 
 335     const void *Table;                // Points to the actual interpolation table
 336     cmsInterpFunction Interpolation;  // Points to the function to do the interpolation
 337 
 338  } cmsInterpParams;
 339 
 340 // Interpolators factory
 341 typedef cmsInterpFunction (* cmsInterpFnFactory)(cmsUInt32Number nInputChannels, cmsUInt32Number nOutputChannels, cmsUInt32Number dwFlags);
 342 
 343 // The plug-in
 344 typedef struct {
 345     cmsPluginBase base;
 346 
 347     // Points to a user-supplied function which implements the factory
 348     cmsInterpFnFactory InterpolatorsFactory;
 349 
 350 } cmsPluginInterpolation;
 351 
 352 //----------------------------------------------------------------------------------------------------------
 353 
 354 // Parametric curves. A negative type means same function but analytically inverted. Max. number of params is 10
 355 
 356 // Evaluator callback for user-supplied parametric curves. May implement more than one type
 357 typedef  cmsFloat64Number (* cmsParametricCurveEvaluator)(cmsInt32Number Type, const cmsFloat64Number Params[10], cmsFloat64Number R);
 358 
 359 // Plug-in may implement an arbitrary number of parametric curves
 360 typedef struct {
 361     cmsPluginBase base;
 362 
 363     cmsUInt32Number nFunctions;                                     // Number of supported functions
 364     cmsUInt32Number FunctionTypes[MAX_TYPES_IN_LCMS_PLUGIN];        // The identification types
 365     cmsUInt32Number ParameterCount[MAX_TYPES_IN_LCMS_PLUGIN];       // Number of parameters for each function
 366 
 367     cmsParametricCurveEvaluator    Evaluator;                       // The evaluator
 368 
 369 } cmsPluginParametricCurves;
 370 //----------------------------------------------------------------------------------------------------------
 371 
 372 // Formatters. This plug-in adds new handlers, replacing them if they already exist. Formatters dealing with
 373 // cmsFloat32Number (bps = 4) or double (bps = 0) types are requested via FormatterFloat callback. Others come across
 374 // Formatter16 callback
 375 
 376 struct _cmstransform_struct;
 377 
 378 typedef cmsUInt8Number* (* cmsFormatter16)(CMSREGISTER struct _cmstransform_struct* CMMcargo,
 379                                            CMSREGISTER cmsUInt16Number Values[],
 380                                            CMSREGISTER cmsUInt8Number* Buffer,
 381                                            CMSREGISTER cmsUInt32Number Stride);
 382 
 383 typedef cmsUInt8Number* (* cmsFormatterFloat)(struct _cmstransform_struct* CMMcargo,
 384                                               cmsFloat32Number Values[],
 385                                               cmsUInt8Number*  Buffer,
 386                                               cmsUInt32Number  Stride);
 387 
 388 // This type holds a pointer to a formatter that can be either 16 bits or cmsFloat32Number
 389 typedef union {
 390     cmsFormatter16    Fmt16;
 391     cmsFormatterFloat FmtFloat;
 392 
 393 } cmsFormatter;
 394 
 395 #define CMS_PACK_FLAGS_16BITS       0x0000
 396 #define CMS_PACK_FLAGS_FLOAT        0x0001
 397 
 398 typedef enum { cmsFormatterInput=0, cmsFormatterOutput=1 } cmsFormatterDirection;
 399 
 400 typedef cmsFormatter (* cmsFormatterFactory)(cmsUInt32Number Type,           // Specific type, i.e. TYPE_RGB_8
 401                                              cmsFormatterDirection Dir,
 402                                              cmsUInt32Number dwFlags);      // precision
 403 
 404 // Plug-in may implement an arbitrary number of formatters
 405 typedef struct {
 406     cmsPluginBase          base;
 407     cmsFormatterFactory    FormattersFactory;
 408 
 409 } cmsPluginFormatters;
 410 
 411 //----------------------------------------------------------------------------------------------------------
 412 
 413 // Tag type handler. Each type is free to return anything it wants, and it is up to the caller to
 414 // know in advance what is the type contained in the tag.
 415 typedef struct _cms_typehandler_struct {
 416 
 417         cmsTagTypeSignature Signature;     // The signature of the type
 418 
 419         // Allocates and reads items
 420         void *   (* ReadPtr)(struct _cms_typehandler_struct* self,
 421                              cmsIOHANDLER*      io,
 422                              cmsUInt32Number*   nItems,
 423                              cmsUInt32Number    SizeOfTag);
 424 
 425         // Writes n Items
 426         cmsBool  (* WritePtr)(struct _cms_typehandler_struct* self,
 427                               cmsIOHANDLER*     io,
 428                               void*             Ptr,
 429                               cmsUInt32Number   nItems);
 430 
 431         // Duplicate an item or array of items
 432         void*   (* DupPtr)(struct _cms_typehandler_struct* self,
 433                            const void *Ptr,
 434                            cmsUInt32Number n);
 435 
 436         // Free all resources
 437         void    (* FreePtr)(struct _cms_typehandler_struct* self,
 438                             void *Ptr);
 439 
 440         // Additional parameters used by the calling thread
 441         cmsContext       ContextID;
 442         cmsUInt32Number  ICCVersion;
 443 
 444 } cmsTagTypeHandler;
 445 
 446 // Each plug-in implements a single type
 447 typedef struct {
 448         cmsPluginBase      base;
 449         cmsTagTypeHandler  Handler;
 450 
 451 } cmsPluginTagType;
 452 
 453 //----------------------------------------------------------------------------------------------------------
 454 
 455 // This is the tag plugin, which identifies tags. For writing, a pointer to function is provided.
 456 // This function should return the desired type for this tag, given the version of profile
 457 // and the data being serialized.
 458 typedef struct {
 459 
 460     cmsUInt32Number     ElemCount;          // If this tag needs an array, how many elements should keep
 461 
 462     // For reading.
 463     cmsUInt32Number     nSupportedTypes;    // In how many types this tag can come (MAX_TYPES_IN_LCMS_PLUGIN maximum)
 464     cmsTagTypeSignature SupportedTypes[MAX_TYPES_IN_LCMS_PLUGIN];
 465 
 466     // For writing
 467     cmsTagTypeSignature (* DecideType)(cmsFloat64Number ICCVersion, const void *Data);
 468 
 469 } cmsTagDescriptor;
 470 
 471 // Plug-in implements a single tag
 472 typedef struct {
 473     cmsPluginBase    base;
 474 
 475     cmsTagSignature  Signature;
 476     cmsTagDescriptor Descriptor;
 477 
 478 } cmsPluginTag;
 479 
 480 //----------------------------------------------------------------------------------------------------------
 481 
 482 // Custom intents. This function should join all profiles specified in the array in
 483 // a single LUT. Any custom intent in the chain redirects to custom function. If more than
 484 // one custom intent is found, the one located first is invoked. Usually users should use only one
 485 // custom intent, so mixing custom intents in same multiprofile transform is not supported.
 486 
 487 typedef cmsPipeline* (* cmsIntentFn)( cmsContext       ContextID,
 488                                       cmsUInt32Number  nProfiles,
 489                                       cmsUInt32Number  Intents[],
 490                                       cmsHPROFILE      hProfiles[],
 491                                       cmsBool          BPC[],
 492                                       cmsFloat64Number AdaptationStates[],
 493                                       cmsUInt32Number  dwFlags);
 494 
 495 
 496 // Each plug-in defines a single intent number.
 497 typedef struct {
 498     cmsPluginBase     base;
 499     cmsUInt32Number   Intent;
 500     cmsIntentFn       Link;
 501     char              Description[256];
 502 
 503 } cmsPluginRenderingIntent;
 504 
 505 
 506 // The default ICC intents (perceptual, saturation, rel.col and abs.col)
 507 CMSAPI cmsPipeline*  CMSEXPORT _cmsDefaultICCintents(cmsContext       ContextID,
 508                                                      cmsUInt32Number  nProfiles,
 509                                                      cmsUInt32Number  Intents[],
 510                                                      cmsHPROFILE      hProfiles[],
 511                                                      cmsBool          BPC[],
 512                                                      cmsFloat64Number AdaptationStates[],
 513                                                      cmsUInt32Number  dwFlags);
 514 
 515 
 516 //----------------------------------------------------------------------------------------------------------
 517 
 518 // Pipelines, Multi Process Elements.
 519 
 520 typedef void (* _cmsStageEvalFn)     (const cmsFloat32Number In[], cmsFloat32Number Out[], const cmsStage* mpe);
 521 typedef void*(* _cmsStageDupElemFn)  (cmsStage* mpe);
 522 typedef void (* _cmsStageFreeElemFn) (cmsStage* mpe);
 523 
 524 
 525 // This function allocates a generic MPE
 526 CMSAPI cmsStage* CMSEXPORT _cmsStageAllocPlaceholder(cmsContext ContextID,
 527                                 cmsStageSignature     Type,
 528                                 cmsUInt32Number       InputChannels,
 529                                 cmsUInt32Number       OutputChannels,
 530                                 _cmsStageEvalFn       EvalPtr,            // Points to fn that evaluates the element (always in floating point)
 531                                 _cmsStageDupElemFn    DupElemPtr,         // Points to a fn that duplicates the stage
 532                                 _cmsStageFreeElemFn   FreePtr,            // Points to a fn that sets the element free
 533                                 void*                 Data);              // A generic pointer to whatever memory needed by the element
 534 typedef struct {
 535       cmsPluginBase     base;
 536       cmsTagTypeHandler Handler;
 537 
 538 }  cmsPluginMultiProcessElement;
 539 
 540 
 541 // Data kept in "Element" member of cmsStage
 542 
 543 // Curves
 544 typedef struct {
 545     cmsUInt32Number nCurves;
 546     cmsToneCurve**  TheCurves;
 547 
 548 } _cmsStageToneCurvesData;
 549 
 550 // Matrix
 551 typedef struct {
 552     cmsFloat64Number*  Double;          // floating point for the matrix
 553     cmsFloat64Number*  Offset;          // The offset
 554 
 555 } _cmsStageMatrixData;
 556 
 557 // CLUT
 558 typedef struct {
 559 
 560     union {                       // Can have only one of both representations at same time
 561         cmsUInt16Number*  T;      // Points to the table 16 bits table
 562         cmsFloat32Number* TFloat; // Points to the cmsFloat32Number table
 563 
 564     } Tab;
 565 
 566     cmsInterpParams* Params;
 567     cmsUInt32Number  nEntries;
 568     cmsBool          HasFloatValues;
 569 
 570 } _cmsStageCLutData;
 571 
 572 
 573 //----------------------------------------------------------------------------------------------------------
 574 // Optimization. Using this plug-in, additional optimization strategies may be implemented.
 575 // The function should return TRUE if any optimization is done on the LUT, this terminates
 576 // the optimization  search. Or FALSE if it is unable to optimize and want to give a chance
 577 // to the rest of optimizers.
 578 
 579 typedef void     (* _cmsOPTeval16Fn)(CMSREGISTER const cmsUInt16Number In[],
 580                                      CMSREGISTER cmsUInt16Number Out[],
 581                                      CMSREGISTER const void* Data);
 582 
 583 
 584 typedef cmsBool  (* _cmsOPToptimizeFn)(cmsPipeline** Lut,
 585                                        cmsUInt32Number  Intent,
 586                                        cmsUInt32Number* InputFormat,
 587                                        cmsUInt32Number* OutputFormat,
 588                                        cmsUInt32Number* dwFlags);
 589 
 590 // This function may be used to set the optional evaluator and a block of private data. If private data is being used, an optional
 591 // duplicator and free functions should also be specified in order to duplicate the LUT construct. Use NULL to inhibit such functionality.
 592 
 593 CMSAPI void CMSEXPORT _cmsPipelineSetOptimizationParameters(cmsPipeline* Lut,
 594                                                _cmsOPTeval16Fn Eval16,
 595                                                void* PrivateData,
 596                                                _cmsFreeUserDataFn FreePrivateDataFn,
 597                                                _cmsDupUserDataFn DupPrivateDataFn);
 598 
 599 typedef struct {
 600       cmsPluginBase     base;
 601 
 602       // Optimize entry point
 603       _cmsOPToptimizeFn  OptimizePtr;
 604 
 605 }  cmsPluginOptimization;
 606 
 607 //----------------------------------------------------------------------------------------------------------
 608 // Full xform
 609 
 610 typedef struct {
 611        cmsUInt32Number BytesPerLineIn;
 612        cmsUInt32Number BytesPerLineOut;
 613        cmsUInt32Number BytesPerPlaneIn;
 614        cmsUInt32Number BytesPerPlaneOut;
 615 
 616 } cmsStride;
 617 
 618 typedef void     (* _cmsTransformFn)(struct _cmstransform_struct *CMMcargo,   // Legacy function, handles just ONE scanline.
 619                                      const void* InputBuffer,
 620                                      void* OutputBuffer,
 621                                      cmsUInt32Number Size,
 622                                      cmsUInt32Number Stride);                 // Stride in bytes to the next plana in planar formats
 623 
 624 
 625 typedef void     (*_cmsTransform2Fn)(struct _cmstransform_struct *CMMcargo,
 626                                      const void* InputBuffer,
 627                                      void* OutputBuffer,
 628                                      cmsUInt32Number PixelsPerLine,
 629                                      cmsUInt32Number LineCount,
 630                                      const cmsStride* Stride);
 631 
 632 typedef cmsBool  (* _cmsTransformFactory)(_cmsTransformFn* xform,
 633                                          void** UserData,
 634                                          _cmsFreeUserDataFn* FreePrivateDataFn,
 635                                          cmsPipeline** Lut,
 636                                          cmsUInt32Number* InputFormat,
 637                                          cmsUInt32Number* OutputFormat,
 638                                          cmsUInt32Number* dwFlags);
 639 
 640 typedef cmsBool  (* _cmsTransform2Factory)(_cmsTransform2Fn* xform,
 641                                          void** UserData,
 642                                          _cmsFreeUserDataFn* FreePrivateDataFn,
 643                                          cmsPipeline** Lut,
 644                                          cmsUInt32Number* InputFormat,
 645                                          cmsUInt32Number* OutputFormat,
 646                                          cmsUInt32Number* dwFlags);
 647 
 648 
 649 // Retrieve user data as specified by the factory
 650 CMSAPI void   CMSEXPORT _cmsSetTransformUserData(struct _cmstransform_struct *CMMcargo, void* ptr, _cmsFreeUserDataFn FreePrivateDataFn);
 651 CMSAPI void * CMSEXPORT _cmsGetTransformUserData(struct _cmstransform_struct *CMMcargo);
 652 
 653 
 654 // Retrieve formatters
 655 CMSAPI void   CMSEXPORT _cmsGetTransformFormatters16   (struct _cmstransform_struct *CMMcargo, cmsFormatter16* FromInput, cmsFormatter16* ToOutput);
 656 CMSAPI void   CMSEXPORT _cmsGetTransformFormattersFloat(struct _cmstransform_struct *CMMcargo, cmsFormatterFloat* FromInput, cmsFormatterFloat* ToOutput);
 657 
 658 typedef struct {
 659       cmsPluginBase     base;
 660 
 661       // Transform entry point
 662       union {
 663              _cmsTransformFactory        legacy_xform;
 664              _cmsTransform2Factory       xform;
 665       } factories;
 666 
 667 }  cmsPluginTransform;
 668 
 669 //----------------------------------------------------------------------------------------------------------
 670 // Mutex
 671 
 672 typedef void*    (* _cmsCreateMutexFnPtrType)(cmsContext ContextID);
 673 typedef void     (* _cmsDestroyMutexFnPtrType)(cmsContext ContextID, void* mtx);
 674 typedef cmsBool  (* _cmsLockMutexFnPtrType)(cmsContext ContextID, void* mtx);
 675 typedef void     (* _cmsUnlockMutexFnPtrType)(cmsContext ContextID, void* mtx);
 676 
 677 typedef struct {
 678       cmsPluginBase     base;
 679 
 680      _cmsCreateMutexFnPtrType  CreateMutexPtr;
 681      _cmsDestroyMutexFnPtrType DestroyMutexPtr;
 682      _cmsLockMutexFnPtrType    LockMutexPtr;
 683      _cmsUnlockMutexFnPtrType  UnlockMutexPtr;
 684 
 685 }  cmsPluginMutex;
 686 
 687 CMSAPI void*   CMSEXPORT _cmsCreateMutex(cmsContext ContextID);
 688 CMSAPI void    CMSEXPORT _cmsDestroyMutex(cmsContext ContextID, void* mtx);
 689 CMSAPI cmsBool CMSEXPORT _cmsLockMutex(cmsContext ContextID, void* mtx);
 690 CMSAPI void    CMSEXPORT _cmsUnlockMutex(cmsContext ContextID, void* mtx);
 691 
 692 
 693 #ifndef CMS_USE_CPP_API
 694 #   ifdef __cplusplus
 695     }
 696 #   endif
 697 #endif
 698 
 699 #define _lcms_plugin_H
 700 #endif
--- EOF ---