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-2011 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 // Error logging  -------------------------------------------------------------------------------------
 127 
 128 CMSAPI void               CMSEXPORT  cmsSignalError(cmsContext ContextID, cmsUInt32Number ErrorCode, const char *ErrorText, ...);
 129 
 130 // Memory management ----------------------------------------------------------------------------------
 131 
 132 CMSAPI void*              CMSEXPORT _cmsMalloc(cmsContext ContextID, cmsUInt32Number size);
 133 CMSAPI void*              CMSEXPORT _cmsMallocZero(cmsContext ContextID, cmsUInt32Number size);
 134 CMSAPI void*              CMSEXPORT _cmsCalloc(cmsContext ContextID, cmsUInt32Number num, cmsUInt32Number size);
 135 CMSAPI void*              CMSEXPORT _cmsRealloc(cmsContext ContextID, void* Ptr, cmsUInt32Number NewSize);
 136 CMSAPI void               CMSEXPORT _cmsFree(cmsContext ContextID, void* Ptr);
 137 CMSAPI void*              CMSEXPORT _cmsDupMem(cmsContext ContextID, const void* Org, cmsUInt32Number size);
 138 
 139 // I/O handler ----------------------------------------------------------------------------------
 140 
 141 struct _cms_io_handler {
 142 
 143     void* stream;   // Associated stream, which is implemented differently depending on media.
 144 
 145     cmsContext        ContextID;
 146     cmsUInt32Number   UsedSpace;
 147     cmsUInt32Number   ReportedSize;
 148     char              PhysicalFile[cmsMAX_PATH];
 149 
 150     cmsUInt32Number   (* Read)(struct _cms_io_handler* iohandler, void *Buffer,
 151                                                                   cmsUInt32Number size,
 152                                                                   cmsUInt32Number count);
 153     cmsBool           (* Seek)(struct _cms_io_handler* iohandler, cmsUInt32Number offset);
 154     cmsBool           (* Close)(struct _cms_io_handler* iohandler);
 155     cmsUInt32Number   (* Tell)(struct _cms_io_handler* iohandler);
 156     cmsBool           (* Write)(struct _cms_io_handler* iohandler, cmsUInt32Number size,
 157                                                                    const void* Buffer);
 158 };
 159 
 160 // Endianess adjust functions
 161 CMSAPI cmsUInt16Number   CMSEXPORT  _cmsAdjustEndianess16(cmsUInt16Number Word);
 162 CMSAPI cmsUInt32Number   CMSEXPORT  _cmsAdjustEndianess32(cmsUInt32Number Value);
 163 CMSAPI void              CMSEXPORT  _cmsAdjustEndianess64(cmsUInt64Number* Result, cmsUInt64Number* QWord);
 164 
 165 // Helper IO functions
 166 CMSAPI cmsBool           CMSEXPORT  _cmsReadUInt8Number(cmsIOHANDLER* io,  cmsUInt8Number* n);
 167 CMSAPI cmsBool           CMSEXPORT  _cmsReadUInt16Number(cmsIOHANDLER* io, cmsUInt16Number* n);
 168 CMSAPI cmsBool           CMSEXPORT  _cmsReadUInt32Number(cmsIOHANDLER* io, cmsUInt32Number* n);
 169 CMSAPI cmsBool           CMSEXPORT  _cmsReadFloat32Number(cmsIOHANDLER* io, cmsFloat32Number* n);
 170 CMSAPI cmsBool           CMSEXPORT  _cmsReadUInt64Number(cmsIOHANDLER* io, cmsUInt64Number* n);
 171 CMSAPI cmsBool           CMSEXPORT  _cmsRead15Fixed16Number(cmsIOHANDLER* io, cmsFloat64Number* n);
 172 CMSAPI cmsBool           CMSEXPORT  _cmsReadXYZNumber(cmsIOHANDLER* io, cmsCIEXYZ* XYZ);
 173 CMSAPI cmsBool           CMSEXPORT  _cmsReadUInt16Array(cmsIOHANDLER* io, cmsUInt32Number n, cmsUInt16Number* Array);
 174 
 175 CMSAPI cmsBool           CMSEXPORT  _cmsWriteUInt8Number(cmsIOHANDLER* io, cmsUInt8Number n);
 176 CMSAPI cmsBool           CMSEXPORT  _cmsWriteUInt16Number(cmsIOHANDLER* io, cmsUInt16Number n);
 177 CMSAPI cmsBool           CMSEXPORT  _cmsWriteUInt32Number(cmsIOHANDLER* io, cmsUInt32Number n);
 178 CMSAPI cmsBool           CMSEXPORT  _cmsWriteFloat32Number(cmsIOHANDLER* io, cmsFloat32Number n);
 179 CMSAPI cmsBool           CMSEXPORT  _cmsWriteUInt64Number(cmsIOHANDLER* io, cmsUInt64Number* n);
 180 CMSAPI cmsBool           CMSEXPORT  _cmsWrite15Fixed16Number(cmsIOHANDLER* io, cmsFloat64Number n);
 181 CMSAPI cmsBool           CMSEXPORT  _cmsWriteXYZNumber(cmsIOHANDLER* io, const cmsCIEXYZ* XYZ);
 182 CMSAPI cmsBool           CMSEXPORT  _cmsWriteUInt16Array(cmsIOHANDLER* io, cmsUInt32Number n, const cmsUInt16Number* Array);
 183 
 184 // ICC base tag
 185 typedef struct {
 186     cmsTagTypeSignature  sig;
 187     cmsInt8Number        reserved[4];
 188 
 189 } _cmsTagBase;
 190 
 191 // Type base helper functions
 192 CMSAPI cmsTagTypeSignature  CMSEXPORT _cmsReadTypeBase(cmsIOHANDLER* io);
 193 CMSAPI cmsBool              CMSEXPORT _cmsWriteTypeBase(cmsIOHANDLER* io, cmsTagTypeSignature sig);
 194 
 195 // Alignment functions
 196 CMSAPI cmsBool             CMSEXPORT _cmsReadAlignment(cmsIOHANDLER* io);
 197 CMSAPI cmsBool             CMSEXPORT _cmsWriteAlignment(cmsIOHANDLER* io);
 198 
 199 // To deal with text streams. 2K at most
 200 CMSAPI cmsBool             CMSEXPORT _cmsIOPrintf(cmsIOHANDLER* io, const char* frm, ...);
 201 
 202 // Fixed point helper functions
 203 CMSAPI cmsFloat64Number    CMSEXPORT _cms8Fixed8toDouble(cmsUInt16Number fixed8);
 204 CMSAPI cmsUInt16Number     CMSEXPORT _cmsDoubleTo8Fixed8(cmsFloat64Number val);
 205 
 206 CMSAPI cmsFloat64Number    CMSEXPORT _cms15Fixed16toDouble(cmsS15Fixed16Number fix32);
 207 CMSAPI cmsS15Fixed16Number CMSEXPORT _cmsDoubleTo15Fixed16(cmsFloat64Number v);
 208 
 209 // Date/time helper functions
 210 CMSAPI void                CMSEXPORT _cmsEncodeDateTimeNumber(cmsDateTimeNumber *Dest, const struct tm *Source);
 211 CMSAPI void                CMSEXPORT _cmsDecodeDateTimeNumber(const cmsDateTimeNumber *Source, struct tm *Dest);
 212 
 213 //----------------------------------------------------------------------------------------------------------
 214 
 215 // Shared callbacks for user data
 216 typedef void     (* _cmsFreeUserDataFn)(cmsContext ContextID, void* Data);
 217 typedef void*    (* _cmsDupUserDataFn)(cmsContext ContextID, const void* Data);
 218 
 219 //----------------------------------------------------------------------------------------------------------
 220 
 221 // Plug-in foundation
 222 #define cmsPluginMagicNumber                 0x61637070     // 'acpp'
 223 
 224 #define cmsPluginMemHandlerSig               0x6D656D48     // 'memH'
 225 #define cmsPluginInterpolationSig            0x696E7048     // 'inpH'
 226 #define cmsPluginParametricCurveSig          0x70617248     // 'parH'
 227 #define cmsPluginFormattersSig               0x66726D48     // 'frmH
 228 #define cmsPluginTagTypeSig                  0x74797048     // 'typH'
 229 #define cmsPluginTagSig                      0x74616748     // 'tagH'
 230 #define cmsPluginRenderingIntentSig          0x696E7448     // 'intH'
 231 #define cmsPluginMultiProcessElementSig      0x6D706548     // 'mpeH'
 232 #define cmsPluginOptimizationSig             0x6F707448     // 'optH'
 233 #define cmsPluginTransformSig                0x7A666D48     // 'xfmH'
 234 
 235 typedef struct _cmsPluginBaseStruct {
 236 
 237         cmsUInt32Number                Magic;               // 'acpp' signature
 238         cmsUInt32Number                ExpectedVersion;     // Expected version of LittleCMS
 239         cmsUInt32Number                Type;                // Type of plug-in
 240         struct _cmsPluginBaseStruct*   Next;                // For multiple plugin definition. NULL for end of list.
 241 
 242 } cmsPluginBase;
 243 
 244 // Maximum number of types in a plugin array
 245 #define MAX_TYPES_IN_LCMS_PLUGIN    20
 246 
 247 //----------------------------------------------------------------------------------------------------------
 248 
 249 // Memory handler. Each new plug-in type replaces current behaviour
 250 typedef struct {
 251 
 252         cmsPluginBase base;
 253 
 254         // Required
 255         void * (* MallocPtr)(cmsContext ContextID, cmsUInt32Number size);
 256         void   (* FreePtr)(cmsContext ContextID, void *Ptr);
 257         void * (* ReallocPtr)(cmsContext ContextID, void* Ptr, cmsUInt32Number NewSize);
 258 
 259         // Optional
 260         void * (* MallocZeroPtr)(cmsContext ContextID, cmsUInt32Number size);
 261         void * (* CallocPtr)(cmsContext ContextID, cmsUInt32Number num, cmsUInt32Number size);
 262         void * (* DupPtr)(cmsContext ContextID, const void* Org, cmsUInt32Number size);
 263 
 264 } cmsPluginMemHandler;
 265 
 266 
 267 // ------------------------------------------------------------------------------------------------------------------
 268 
 269 // Interpolation. 16 bits and floating point versions.
 270 struct _cms_interp_struc;
 271 
 272 // Interpolation callbacks
 273 
 274 // 16 bits forward interpolation. This function performs precision-limited linear interpolation
 275 // and is supposed to be quite fast. Implementation may be tetrahedral or trilinear, and plug-ins may
 276 // choose to implement any other interpolation algorithm.
 277 typedef void (* _cmsInterpFn16)(register const cmsUInt16Number Input[],
 278                                 register cmsUInt16Number Output[],
 279                                 register const struct _cms_interp_struc* p);
 280 
 281 // Floating point forward interpolation. Full precision interpolation using floats. This is not a
 282 // time critical function. Implementation may be tetrahedral or trilinear, and plug-ins may
 283 // choose to implement any other interpolation algorithm.
 284 typedef void (* _cmsInterpFnFloat)(cmsFloat32Number const Input[],
 285                                    cmsFloat32Number Output[],
 286                                    const struct _cms_interp_struc* p);
 287 
 288 
 289 
 290 // This type holds a pointer to an interpolator that can be either 16 bits or float
 291 typedef union {
 292     _cmsInterpFn16       Lerp16;            // Forward interpolation in 16 bits
 293     _cmsInterpFnFloat    LerpFloat;         // Forward interpolation in floating point
 294 } cmsInterpFunction;
 295 
 296 // Flags for interpolator selection
 297 #define CMS_LERP_FLAGS_16BITS             0x0000        // The default
 298 #define CMS_LERP_FLAGS_FLOAT              0x0001        // Requires different implementation
 299 #define CMS_LERP_FLAGS_TRILINEAR          0x0100        // Hint only
 300 
 301 
 302 #define MAX_INPUT_DIMENSIONS 8
 303 
 304 typedef struct _cms_interp_struc {  // Used on all interpolations. Supplied by lcms2 when calling the interpolation function
 305 
 306     cmsContext ContextID;     // The calling thread
 307 
 308     cmsUInt32Number dwFlags;  // Keep original flags
 309     cmsUInt32Number nInputs;  // != 1 only in 3D interpolation
 310     cmsUInt32Number nOutputs; // != 1 only in 3D interpolation
 311 
 312     cmsUInt32Number nSamples[MAX_INPUT_DIMENSIONS];  // Valid on all kinds of tables
 313     cmsUInt32Number Domain[MAX_INPUT_DIMENSIONS];    // Domain = nSamples - 1
 314 
 315     cmsUInt32Number opta[MAX_INPUT_DIMENSIONS];     // Optimization for 3D CLUT. This is the number of nodes premultiplied for each
 316                                                     // dimension. For example, in 7 nodes, 7, 7^2 , 7^3, 7^4, etc. On non-regular
 317                                                     // Samplings may vary according of the number of nodes for each dimension.
 318 
 319     const void *Table;                // Points to the actual interpolation table
 320     cmsInterpFunction Interpolation;  // Points to the function to do the interpolation
 321 
 322  } cmsInterpParams;
 323 
 324 // Interpolators factory
 325 typedef cmsInterpFunction (* cmsInterpFnFactory)(cmsUInt32Number nInputChannels, cmsUInt32Number nOutputChannels, cmsUInt32Number dwFlags);
 326 
 327 // The plug-in
 328 typedef struct {
 329     cmsPluginBase base;
 330 
 331     // Points to a user-supplied function which implements the factory
 332     cmsInterpFnFactory InterpolatorsFactory;
 333 
 334 } cmsPluginInterpolation;
 335 
 336 //----------------------------------------------------------------------------------------------------------
 337 
 338 // Parametric curves. A negative type means same function but analytically inverted. Max. number of params is 10
 339 
 340 // Evaluator callback for user-suplied parametric curves. May implement more than one type
 341 typedef  cmsFloat64Number (* cmsParametricCurveEvaluator)(cmsInt32Number Type, const cmsFloat64Number Params[10], cmsFloat64Number R);
 342 
 343 // Plug-in may implement an arbitrary number of parametric curves
 344 typedef struct {
 345     cmsPluginBase base;
 346 
 347     cmsUInt32Number nFunctions;                                     // Number of supported functions
 348     cmsUInt32Number FunctionTypes[MAX_TYPES_IN_LCMS_PLUGIN];        // The identification types
 349     cmsUInt32Number ParameterCount[MAX_TYPES_IN_LCMS_PLUGIN];       // Number of parameters for each function
 350 
 351     cmsParametricCurveEvaluator    Evaluator;                       // The evaluator
 352 
 353 } cmsPluginParametricCurves;
 354 //----------------------------------------------------------------------------------------------------------
 355 
 356 // Formatters. This plug-in adds new handlers, replacing them if they already exist. Formatters dealing with
 357 // cmsFloat32Number (bps = 4) or double (bps = 0) types are requested via FormatterFloat callback. Others come across
 358 // Formatter16 callback
 359 
 360 struct _cmstransform_struct;
 361 
 362 typedef cmsUInt8Number* (* cmsFormatter16)(register struct _cmstransform_struct* CMMcargo,
 363                                            register cmsUInt16Number Values[],
 364                                            register cmsUInt8Number*  Buffer,
 365                                            register cmsUInt32Number  Stride);
 366 
 367 typedef cmsUInt8Number* (* cmsFormatterFloat)(struct _cmstransform_struct* CMMcargo,
 368                                               cmsFloat32Number Values[],
 369                                               cmsUInt8Number*  Buffer,
 370                                               cmsUInt32Number  Stride);
 371 
 372 // This type holds a pointer to a formatter that can be either 16 bits or cmsFloat32Number
 373 typedef union {
 374     cmsFormatter16    Fmt16;
 375     cmsFormatterFloat FmtFloat;
 376 
 377 } cmsFormatter;
 378 
 379 #define CMS_PACK_FLAGS_16BITS       0x0000
 380 #define CMS_PACK_FLAGS_FLOAT        0x0001
 381 
 382 typedef enum { cmsFormatterInput=0, cmsFormatterOutput=1 } cmsFormatterDirection;
 383 
 384 typedef cmsFormatter (* cmsFormatterFactory)(cmsUInt32Number Type,           // Specific type, i.e. TYPE_RGB_8
 385                                              cmsFormatterDirection Dir,
 386                                              cmsUInt32Number dwFlags);      // precision
 387 
 388 // Plug-in may implement an arbitrary number of formatters
 389 typedef struct {
 390     cmsPluginBase          base;
 391     cmsFormatterFactory    FormattersFactory;
 392 
 393 } cmsPluginFormatters;
 394 
 395 //----------------------------------------------------------------------------------------------------------
 396 
 397 // Tag type handler. Each type is free to return anything it wants, and it is up to the caller to
 398 // know in advance what is the type contained in the tag.
 399 typedef struct _cms_typehandler_struct {
 400 
 401         cmsTagTypeSignature Signature;     // The signature of the type
 402 
 403         // Allocates and reads items
 404         void *   (* ReadPtr)(struct _cms_typehandler_struct* self,
 405                              cmsIOHANDLER*      io,
 406                              cmsUInt32Number*   nItems,
 407                              cmsUInt32Number    SizeOfTag);
 408 
 409         // Writes n Items
 410         cmsBool  (* WritePtr)(struct _cms_typehandler_struct* self,
 411                               cmsIOHANDLER*     io,
 412                               void*             Ptr,
 413                               cmsUInt32Number   nItems);
 414 
 415         // Duplicate an item or array of items
 416         void*   (* DupPtr)(struct _cms_typehandler_struct* self,
 417                            const void *Ptr,
 418                            cmsUInt32Number n);
 419 
 420         // Free all resources
 421         void    (* FreePtr)(struct _cms_typehandler_struct* self,
 422                             void *Ptr);
 423 
 424         // Additional parameters used by the calling thread
 425         cmsContext       ContextID;
 426         cmsUInt32Number  ICCVersion;
 427 
 428 } cmsTagTypeHandler;
 429 
 430 // Each plug-in implements a single type
 431 typedef struct {
 432         cmsPluginBase      base;
 433         cmsTagTypeHandler  Handler;
 434 
 435 } cmsPluginTagType;
 436 
 437 //----------------------------------------------------------------------------------------------------------
 438 
 439 // This is the tag plugin, which identifies tags. For writing, a pointer to function is provided.
 440 // This function should return the desired type for this tag, given the version of profile
 441 // and the data being serialized.
 442 typedef struct {
 443 
 444     cmsUInt32Number     ElemCount;          // If this tag needs an array, how many elements should keep
 445 
 446     // For reading.
 447     cmsUInt32Number     nSupportedTypes;    // In how many types this tag can come (MAX_TYPES_IN_LCMS_PLUGIN maximum)
 448     cmsTagTypeSignature SupportedTypes[MAX_TYPES_IN_LCMS_PLUGIN];
 449 
 450     // For writting
 451     cmsTagTypeSignature (* DecideType)(cmsFloat64Number ICCVersion, const void *Data);
 452 
 453 } cmsTagDescriptor;
 454 
 455 // Plug-in implements a single tag
 456 typedef struct {
 457     cmsPluginBase    base;
 458 
 459     cmsTagSignature  Signature;
 460     cmsTagDescriptor Descriptor;
 461 
 462 } cmsPluginTag;
 463 
 464 //----------------------------------------------------------------------------------------------------------
 465 
 466 // Custom intents. This function should join all profiles specified in the array in
 467 // a single LUT. Any custom intent in the chain redirects to custom function. If more than
 468 // one custom intent is found, the one located first is invoked. Usually users should use only one
 469 // custom intent, so mixing custom intents in same multiprofile transform is not supported.
 470 
 471 typedef cmsPipeline* (* cmsIntentFn)( cmsContext       ContextID,
 472                                       cmsUInt32Number  nProfiles,
 473                                       cmsUInt32Number  Intents[],
 474                                       cmsHPROFILE      hProfiles[],
 475                                       cmsBool          BPC[],
 476                                       cmsFloat64Number AdaptationStates[],
 477                                       cmsUInt32Number  dwFlags);
 478 
 479 
 480 // Each plug-in defines a single intent number.
 481 typedef struct {
 482     cmsPluginBase     base;
 483     cmsUInt32Number   Intent;
 484     cmsIntentFn       Link;
 485     char              Description[256];
 486 
 487 } cmsPluginRenderingIntent;
 488 
 489 
 490 // The default ICC intents (perceptual, saturation, rel.col and abs.col)
 491 CMSAPI cmsPipeline*  CMSEXPORT _cmsDefaultICCintents(cmsContext       ContextID,
 492                                                      cmsUInt32Number  nProfiles,
 493                                                      cmsUInt32Number  Intents[],
 494                                                      cmsHPROFILE      hProfiles[],
 495                                                      cmsBool          BPC[],
 496                                                      cmsFloat64Number AdaptationStates[],
 497                                                      cmsUInt32Number  dwFlags);
 498 
 499 
 500 //----------------------------------------------------------------------------------------------------------
 501 
 502 // Pipelines, Multi Process Elements.
 503 
 504 typedef void (* _cmsStageEvalFn)     (const cmsFloat32Number In[], cmsFloat32Number Out[], const cmsStage* mpe);
 505 typedef void*(* _cmsStageDupElemFn)  (cmsStage* mpe);
 506 typedef void (* _cmsStageFreeElemFn) (cmsStage* mpe);
 507 
 508 
 509 // This function allocates a generic MPE
 510 CMSAPI cmsStage* CMSEXPORT _cmsStageAllocPlaceholder(cmsContext ContextID,
 511                                 cmsStageSignature     Type,
 512                                 cmsUInt32Number       InputChannels,
 513                                 cmsUInt32Number       OutputChannels,
 514                                 _cmsStageEvalFn       EvalPtr,            // Points to fn that evaluates the element (always in floating point)
 515                                 _cmsStageDupElemFn    DupElemPtr,         // Points to a fn that duplicates the stage
 516                                 _cmsStageFreeElemFn   FreePtr,            // Points to a fn that sets the element free
 517                                 void*                 Data);              // A generic pointer to whatever memory needed by the element
 518 typedef struct {
 519       cmsPluginBase     base;
 520       cmsTagTypeHandler Handler;
 521 
 522 }  cmsPluginMultiProcessElement;
 523 
 524 
 525 // Data kept in "Element" member of cmsStage
 526 
 527 // Curves
 528 typedef struct {
 529     cmsUInt32Number nCurves;
 530     cmsToneCurve**  TheCurves;
 531 
 532 } _cmsStageToneCurvesData;
 533 
 534 // Matrix
 535 typedef struct {
 536     cmsFloat64Number*  Double;          // floating point for the matrix
 537     cmsFloat64Number*  Offset;          // The offset
 538 
 539 } _cmsStageMatrixData;
 540 
 541 // CLUT
 542 typedef struct {
 543 
 544     union {                       // Can have only one of both representations at same time
 545         cmsUInt16Number*  T;      // Points to the table 16 bits table
 546         cmsFloat32Number* TFloat; // Points to the cmsFloat32Number table
 547 
 548     } Tab;
 549 
 550     cmsInterpParams* Params;
 551     cmsUInt32Number  nEntries;
 552     cmsBool          HasFloatValues;
 553 
 554 } _cmsStageCLutData;
 555 
 556 
 557 //----------------------------------------------------------------------------------------------------------
 558 // Optimization. Using this plug-in, additional optimization strategies may be implemented.
 559 // The function should return TRUE if any optimization is done on the LUT, this terminates
 560 // the optimization  search. Or FALSE if it is unable to optimize and want to give a chance
 561 // to the rest of optimizers.
 562 
 563 typedef void     (* _cmsOPTeval16Fn)(register const cmsUInt16Number In[],
 564                                      register cmsUInt16Number Out[],
 565                                      register const void* Data);
 566 
 567 
 568 typedef cmsBool  (* _cmsOPToptimizeFn)(cmsPipeline** Lut,
 569                                        cmsUInt32Number  Intent,
 570                                        cmsUInt32Number* InputFormat,
 571                                        cmsUInt32Number* OutputFormat,
 572                                        cmsUInt32Number* dwFlags);
 573 
 574 // This function may be used to set the optional evaluator and a block of private data. If private data is being used, an optional
 575 // duplicator and free functions should also be specified in order to duplicate the LUT construct. Use NULL to inhibit such functionality.
 576 
 577 CMSAPI void CMSEXPORT _cmsPipelineSetOptimizationParameters(cmsPipeline* Lut,
 578                                                _cmsOPTeval16Fn Eval16,
 579                                                void* PrivateData,
 580                                                _cmsFreeUserDataFn FreePrivateDataFn,
 581                                                _cmsDupUserDataFn DupPrivateDataFn);
 582 
 583 typedef struct {
 584       cmsPluginBase     base;
 585 
 586       // Optimize entry point
 587       _cmsOPToptimizeFn  OptimizePtr;
 588 
 589 }  cmsPluginOptimization;
 590 
 591 //----------------------------------------------------------------------------------------------------------
 592 // Full xform
 593 typedef void     (* _cmsTransformFn)(struct _cmstransform_struct *CMMcargo,
 594                                      const void* InputBuffer,
 595                                      void* OutputBuffer,
 596                                      cmsUInt32Number Size,
 597                                      cmsUInt32Number Stride);
 598 
 599 typedef cmsBool  (* _cmsTransformFactory)(_cmsTransformFn* xform,
 600                                          void** UserData,
 601                                          _cmsFreeUserDataFn* FreePrivateDataFn,
 602                                          cmsPipeline** Lut,
 603                                          cmsUInt32Number* InputFormat,
 604                                          cmsUInt32Number* OutputFormat,
 605                                          cmsUInt32Number* dwFlags);
 606 
 607 
 608 // Retrieve user data as specified by the factory
 609 CMSAPI void   CMSEXPORT _cmsSetTransformUserData(struct _cmstransform_struct *CMMcargo, void* ptr, _cmsFreeUserDataFn FreePrivateDataFn);
 610 CMSAPI void * CMSEXPORT _cmsGetTransformUserData(struct _cmstransform_struct *CMMcargo);
 611 
 612 
 613 // Retrieve formatters
 614 CMSAPI void   CMSEXPORT _cmsGetTransformFormatters16   (struct _cmstransform_struct *CMMcargo, cmsFormatter16* FromInput, cmsFormatter16* ToOutput);
 615 CMSAPI void   CMSEXPORT _cmsGetTransformFormattersFloat(struct _cmstransform_struct *CMMcargo, cmsFormatterFloat* FromInput, cmsFormatterFloat* ToOutput);
 616 
 617 typedef struct {
 618       cmsPluginBase     base;
 619 
 620       // Transform entry point
 621       _cmsTransformFactory  Factory;
 622 
 623 }  cmsPluginTransform;
 624 
 625 
 626 #ifndef CMS_USE_CPP_API
 627 #   ifdef __cplusplus
 628     }
 629 #   endif
 630 #endif
 631 
 632 #define _lcms_plugin_H
 633 #endif