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