jdk/src/share/native/sun/java2d/cmm/lcms/lcms2_internal.h
changeset 6482 0f6a4442b29e
child 14300 117dc9b98a7b
equal deleted inserted replaced
6481:78d56f33c3a7 6482:0f6a4442b29e
       
     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-2010 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 
       
    56 #ifndef _lcms_internal_H
       
    57 
       
    58 // Include plug-in foundation
       
    59 #ifndef _lcms_plugin_H
       
    60 #   include "lcms2_plugin.h"
       
    61 #endif
       
    62 
       
    63 // ctype is part of C99 as per 7.1.2
       
    64 #include <ctype.h>
       
    65 
       
    66 // assert macro is part of C99 as per 7.2
       
    67 #include <assert.h>
       
    68 
       
    69 // Some needed constants
       
    70 #ifndef M_PI
       
    71 #       define M_PI        3.14159265358979323846
       
    72 #endif
       
    73 
       
    74 #ifndef M_LOG10E
       
    75 #       define M_LOG10E    0.434294481903251827651
       
    76 #endif
       
    77 
       
    78 // BorlandC 5.5 is broken on that
       
    79 #ifdef __BORLANDC__
       
    80 #define sinf(x) (float)sin((float)x)
       
    81 #define sqrtf(x) (float)sqrt((float)x)
       
    82 #endif
       
    83 
       
    84 
       
    85 // Alignment of ICC file format uses 4 bytes (cmsUInt32Number)
       
    86 #define _cmsSIZEOFLONGMINUS1    (sizeof(cmsUInt32Number)-1)
       
    87 #define _cmsALIGNLONG(x) (((x)+_cmsSIZEOFLONGMINUS1) & ~(_cmsSIZEOFLONGMINUS1))
       
    88 
       
    89 // Maximum encodeable values in floating point
       
    90 #define MAX_ENCODEABLE_XYZ  (1.0 + 32767.0/32768.0)
       
    91 #define MIN_ENCODEABLE_ab2  (-128.0)
       
    92 #define MAX_ENCODEABLE_ab2  ((65535.0/256.0) - 128.0)
       
    93 #define MIN_ENCODEABLE_ab4  (-128.0)
       
    94 #define MAX_ENCODEABLE_ab4  (127.0)
       
    95 
       
    96 // Maximum of channels for internal pipeline evaluation
       
    97 #define MAX_STAGE_CHANNELS      128
       
    98 
       
    99 // Unused parameter warning supression
       
   100 #define cmsUNUSED_PARAMETER(x) ((void)x)
       
   101 
       
   102 // The specification for "inline" is section 6.7.4 of the C99 standard (ISO/IEC 9899:1999).
       
   103 // unfortunately VisualC++ does not conform that
       
   104 #if defined(_MSC_VER) || defined(__BORLANDC__)
       
   105 #   define cmsINLINE __inline
       
   106 #else
       
   107 #   define cmsINLINE static inline
       
   108 #endif
       
   109 
       
   110 // Other replacement functions
       
   111 #ifdef _MSC_VER
       
   112 # ifndef snprintf
       
   113 #       define snprintf  _snprintf
       
   114 # endif
       
   115 # ifndef vsnprintf
       
   116 #       define vsnprintf  _vsnprintf
       
   117 # endif
       
   118 #endif
       
   119 
       
   120 // Pthreads. In windows we use the native WIN32 API instead
       
   121 #ifdef CMS_DONT_USE_PTHREADS
       
   122 typedef int LCMS_RWLOCK_T;
       
   123 #   define LCMS_CREATE_LOCK(x)
       
   124 #   define LCMS_FREE_LOCK(x)
       
   125 #   define LCMS_READ_LOCK(x)
       
   126 #   define LCMS_WRITE_LOCK(x)
       
   127 #   define LCMS_UNLOCK(x)
       
   128 #else
       
   129 #ifdef CMS_IS_WINDOWS_
       
   130 #   ifndef WIN32_LEAN_AND_MEAN
       
   131 #       define WIN32_LEAN_AND_MEAN
       
   132 #   endif
       
   133 #   include <windows.h>
       
   134     typedef CRITICAL_SECTION LCMS_RWLOCK_T;
       
   135 #   define LCMS_CREATE_LOCK(x)       InitializeCriticalSection((x))
       
   136 #   define LCMS_FREE_LOCK(x)         DeleteCriticalSection((x))
       
   137 #   define LCMS_READ_LOCK(x)         EnterCriticalSection((x))
       
   138 #   define LCMS_WRITE_LOCK(x)        EnterCriticalSection((x))
       
   139 #   define LCMS_UNLOCK(x)            LeaveCriticalSection((x))
       
   140 #else
       
   141 #   include <pthread.h>
       
   142     typedef    pthread_rwlock_t      LCMS_RWLOCK_T;
       
   143 #   define LCMS_CREATE_LOCK(x)       pthread_rwlock_init((x), NULL)
       
   144 #   define LCMS_FREE_LOCK(x)         pthread_rwlock_destroy((x))
       
   145 #   define LCMS_READ_LOCK(x)         pthread_rwlock_rdlock((x))
       
   146 #   define LCMS_WRITE_LOCK(x)        pthread_rwlock_wrlock((x))
       
   147 #   define LCMS_UNLOCK(x)            pthread_rwlock_unlock((x))
       
   148 #endif
       
   149 #endif
       
   150 
       
   151 // A fast way to convert from/to 16 <-> 8 bits
       
   152 #define FROM_8_TO_16(rgb) (cmsUInt16Number) ((((cmsUInt16Number) (rgb)) << 8)|(rgb))
       
   153 #define FROM_16_TO_8(rgb) (cmsUInt8Number) ((((rgb) * 65281 + 8388608) >> 24) & 0xFF)
       
   154 
       
   155 // Code analysis is broken on asserts
       
   156 #ifdef _MSC_VER
       
   157 #    if (_MSC_VER >= 1500)
       
   158 #            define _cmsAssert(a)  { assert((a)); __analysis_assume((a)); }
       
   159 #     else
       
   160 #            define _cmsAssert(a)   assert((a))
       
   161 #     endif
       
   162 #else
       
   163 #      define _cmsAssert(a)   assert((a))
       
   164 #endif
       
   165 
       
   166 //---------------------------------------------------------------------------------
       
   167 
       
   168 // Determinant lower than that are assumed zero (used on matrix invert)
       
   169 #define MATRIX_DET_TOLERANCE    0.0001
       
   170 
       
   171 //---------------------------------------------------------------------------------
       
   172 
       
   173 // Fixed point
       
   174 #define FIXED_TO_INT(x)         ((x)>>16)
       
   175 #define FIXED_REST_TO_INT(x)    ((x)&0xFFFFU)
       
   176 #define ROUND_FIXED_TO_INT(x)   (((x)+0x8000)>>16)
       
   177 
       
   178 cmsINLINE cmsS15Fixed16Number _cmsToFixedDomain(int a)                   { return a + ((a + 0x7fff) / 0xffff); }
       
   179 cmsINLINE int                 _cmsFromFixedDomain(cmsS15Fixed16Number a) { return a - ((a + 0x7fff) >> 16); }
       
   180 
       
   181 // -----------------------------------------------------------------------------------------------------------
       
   182 
       
   183 // Fast floor conversion logic. Thanks to Sree Kotay and Stuart Nixon
       
   184 // note than this only works in the range ..-32767...+32767 because
       
   185 // mantissa is interpreted as 15.16 fixed point.
       
   186 // The union is to avoid pointer aliasing overoptimization.
       
   187 cmsINLINE int _cmsQuickFloor(cmsFloat64Number val)
       
   188 {
       
   189 #ifdef CMS_DONT_USE_FAST_FLOOR
       
   190     return (int) floor(val);
       
   191 #else
       
   192     const cmsFloat64Number _lcms_double2fixmagic = 68719476736.0 * 1.5;  // 2^36 * 1.5, (52-16=36) uses limited precision to floor
       
   193     union {
       
   194         cmsFloat64Number val;
       
   195         int halves[2];
       
   196     } temp;
       
   197 
       
   198     temp.val = val + _lcms_double2fixmagic;
       
   199 
       
   200 #ifdef CMS_USE_BIG_ENDIAN
       
   201     return temp.halves[1] >> 16;
       
   202 #else
       
   203     return temp.halves[0] >> 16;
       
   204 #endif
       
   205 #endif
       
   206 }
       
   207 
       
   208 // Fast floor restricted to 0..65535.0
       
   209 cmsINLINE cmsUInt16Number _cmsQuickFloorWord(cmsFloat64Number d)
       
   210 {
       
   211     return (cmsUInt16Number) _cmsQuickFloor(d - 32767.0) + 32767U;
       
   212 }
       
   213 
       
   214 // Floor to word, taking care of saturation
       
   215 cmsINLINE cmsUInt16Number _cmsQuickSaturateWord(cmsFloat64Number d)
       
   216 {
       
   217     d += 0.5;
       
   218     if (d <= 0) return 0;
       
   219     if (d >= 65535.0) return 0xffff;
       
   220 
       
   221     return _cmsQuickFloorWord(d);
       
   222 }
       
   223 
       
   224 // Plug-In registering ---------------------------------------------------------------
       
   225 
       
   226 // Specialized function for plug-in memory management. No pairing free() since whole pool is freed at once.
       
   227 void* _cmsPluginMalloc(cmsUInt32Number size);
       
   228 
       
   229 // Memory management
       
   230 cmsBool   _cmsRegisterMemHandlerPlugin(cmsPluginBase* Plugin);
       
   231 
       
   232 // Interpolation
       
   233 cmsBool  _cmsRegisterInterpPlugin(cmsPluginBase* Plugin);
       
   234 
       
   235 // Parametric curves
       
   236 cmsBool  _cmsRegisterParametricCurvesPlugin(cmsPluginBase* Plugin);
       
   237 
       
   238 // Formatters management
       
   239 cmsBool  _cmsRegisterFormattersPlugin(cmsPluginBase* Plugin);
       
   240 
       
   241 // Tag type management
       
   242 cmsBool  _cmsRegisterTagTypePlugin(cmsPluginBase* Plugin);
       
   243 
       
   244 // Tag management
       
   245 cmsBool  _cmsRegisterTagPlugin(cmsPluginBase* Plugin);
       
   246 
       
   247 // Intent management
       
   248 cmsBool  _cmsRegisterRenderingIntentPlugin(cmsPluginBase* Plugin);
       
   249 
       
   250 // Multi Process elements
       
   251 cmsBool  _cmsRegisterMultiProcessElementPlugin(cmsPluginBase* Plugin);
       
   252 
       
   253 // Optimization
       
   254 cmsBool  _cmsRegisterOptimizationPlugin(cmsPluginBase* Plugin);
       
   255 
       
   256 
       
   257 // ---------------------------------------------------------------------------------------------------------
       
   258 
       
   259 // Suballocators. Those are blocks of memory that is freed at the end on whole block.
       
   260 typedef struct _cmsSubAllocator_chunk_st {
       
   261 
       
   262     cmsUInt8Number* Block;
       
   263     cmsUInt32Number BlockSize;
       
   264     cmsUInt32Number Used;
       
   265 
       
   266     struct _cmsSubAllocator_chunk_st* next;
       
   267 
       
   268 } _cmsSubAllocator_chunk;
       
   269 
       
   270 
       
   271 typedef struct {
       
   272 
       
   273     cmsContext ContextID;
       
   274     _cmsSubAllocator_chunk* h;
       
   275 
       
   276 } _cmsSubAllocator;
       
   277 
       
   278 
       
   279 _cmsSubAllocator* _cmsCreateSubAlloc(cmsContext ContextID, cmsUInt32Number Initial);
       
   280 void              _cmsSubAllocDestroy(_cmsSubAllocator* s);
       
   281 void*             _cmsSubAlloc(_cmsSubAllocator* s, cmsUInt32Number size);
       
   282 
       
   283 // ----------------------------------------------------------------------------------
       
   284 
       
   285 // MLU internal representation
       
   286 typedef struct {
       
   287 
       
   288     cmsUInt16Number Language;
       
   289     cmsUInt16Number Country;
       
   290 
       
   291     cmsUInt32Number StrW;       // Offset to current unicode string
       
   292     cmsUInt32Number Len;        // Lenght in bytes
       
   293 
       
   294 } _cmsMLUentry;
       
   295 
       
   296 struct _cms_MLU_struct {
       
   297 
       
   298     cmsContext ContextID;
       
   299 
       
   300     // The directory
       
   301     int AllocatedEntries;
       
   302     int UsedEntries;
       
   303     _cmsMLUentry* Entries;     // Array of pointers to strings allocated in MemPool
       
   304 
       
   305     // The Pool
       
   306     cmsUInt32Number PoolSize;  // The maximum allocated size
       
   307     cmsUInt32Number PoolUsed;  // The used size
       
   308     void*  MemPool;            // Pointer to begin of memory pool
       
   309 };
       
   310 
       
   311 // Named color list internal representation
       
   312 typedef struct {
       
   313 
       
   314     char Name[cmsMAX_PATH];
       
   315     cmsUInt16Number PCS[3];
       
   316     cmsUInt16Number DeviceColorant[cmsMAXCHANNELS];
       
   317 
       
   318 } _cmsNAMEDCOLOR;
       
   319 
       
   320 struct _cms_NAMEDCOLORLIST_struct {
       
   321 
       
   322     cmsUInt32Number nColors;
       
   323     cmsUInt32Number Allocated;
       
   324     cmsUInt32Number ColorantCount;
       
   325 
       
   326     char Prefix[33];      // Prefix and suffix are defined to be 32 characters at most
       
   327     char Suffix[33];
       
   328 
       
   329     _cmsNAMEDCOLOR* List;
       
   330 
       
   331     cmsContext ContextID;
       
   332 };
       
   333 
       
   334 
       
   335 // ----------------------------------------------------------------------------------
       
   336 
       
   337 // This is the internal struct holding profile details.
       
   338 
       
   339 // Maximum supported tags in a profile
       
   340 #define MAX_TABLE_TAG       100
       
   341 
       
   342 typedef struct _cms_iccprofile_struct {
       
   343 
       
   344     // I/O handler
       
   345     cmsIOHANDLER*            IOhandler;
       
   346 
       
   347     // The thread ID
       
   348     cmsContext               ContextID;
       
   349 
       
   350     // Creation time
       
   351     struct tm                Created;
       
   352 
       
   353     // Only most important items found in ICC profiles
       
   354     cmsUInt32Number          Version;
       
   355     cmsProfileClassSignature DeviceClass;
       
   356     cmsColorSpaceSignature   ColorSpace;
       
   357     cmsColorSpaceSignature   PCS;
       
   358     cmsUInt32Number          RenderingIntent;
       
   359     cmsUInt32Number          flags;
       
   360     cmsUInt32Number          manufacturer, model;
       
   361     cmsUInt64Number          attributes;
       
   362 
       
   363     cmsProfileID             ProfileID;
       
   364 
       
   365     // Dictionary
       
   366     cmsUInt32Number          TagCount;
       
   367     cmsTagSignature          TagNames[MAX_TABLE_TAG];
       
   368     cmsTagSignature          TagLinked[MAX_TABLE_TAG];           // The tag to wich is linked (0=none)
       
   369     cmsUInt32Number          TagSizes[MAX_TABLE_TAG];            // Size on disk
       
   370     cmsUInt32Number          TagOffsets[MAX_TABLE_TAG];
       
   371     cmsBool                  TagSaveAsRaw[MAX_TABLE_TAG];        // True to write uncooked
       
   372     void *                   TagPtrs[MAX_TABLE_TAG];
       
   373     cmsTagTypeHandler*       TagTypeHandlers[MAX_TABLE_TAG];     // Same structure may be serialized on different types
       
   374                                                                  // depending on profile version, so we keep track of the                                                             // type handler for each tag in the list.
       
   375     // Special
       
   376     cmsBool                  IsWrite;
       
   377 
       
   378 } _cmsICCPROFILE;
       
   379 
       
   380 // IO helpers for profiles
       
   381 cmsBool              _cmsReadHeader(_cmsICCPROFILE* Icc);
       
   382 cmsBool              _cmsWriteHeader(_cmsICCPROFILE* Icc, cmsUInt32Number UsedSpace);
       
   383 int                  _cmsSearchTag(_cmsICCPROFILE* Icc, cmsTagSignature sig, cmsBool lFollowLinks);
       
   384 
       
   385 // Tag types
       
   386 cmsTagTypeHandler*   _cmsGetTagTypeHandler(cmsTagTypeSignature sig);
       
   387 cmsTagTypeSignature  _cmsGetTagTrueType(cmsHPROFILE hProfile, cmsTagSignature sig);
       
   388 cmsTagDescriptor*    _cmsGetTagDescriptor(cmsTagSignature sig);
       
   389 
       
   390 // Error logging ---------------------------------------------------------------------------------------------------------
       
   391 
       
   392 void                 _cmsTagSignature2String(char String[5], cmsTagSignature sig);
       
   393 
       
   394 // Interpolation ---------------------------------------------------------------------------------------------------------
       
   395 
       
   396 cmsInterpParams*     _cmsComputeInterpParams(cmsContext ContextID, int nSamples, int InputChan, int OutputChan, const void* Table, cmsUInt32Number dwFlags);
       
   397 cmsInterpParams*     _cmsComputeInterpParamsEx(cmsContext ContextID, const cmsUInt32Number nSamples[], int InputChan, int OutputChan, const void* Table, cmsUInt32Number dwFlags);
       
   398 void                 _cmsFreeInterpParams(cmsInterpParams* p);
       
   399 
       
   400 // Curves ----------------------------------------------------------------------------------------------------------------
       
   401 
       
   402 // This struct holds information about a segment, plus a pointer to the function that implements the evaluation.
       
   403 // In the case of table-based, Eval pointer is set to NULL
       
   404 
       
   405 // The gamma function main structure
       
   406 struct _cms_curve_struct {
       
   407 
       
   408     cmsInterpParams*  InterpParams;  // Private optimizations for interpolation
       
   409 
       
   410     cmsUInt32Number   nSegments;     // Number of segments in the curve. Zero for a 16-bit based tables
       
   411     cmsCurveSegment*  Segments;      // The segments
       
   412     cmsInterpParams** SegInterp;     // Array of private optimizations for interpolation in table-based segments
       
   413 
       
   414     cmsParametricCurveEvaluator* Evals;  // Evaluators (one per segment)
       
   415 
       
   416     // 16 bit Table-based representation follows
       
   417     cmsUInt32Number    nEntries;      // Number of table elements
       
   418     cmsUInt16Number*   Table16;       // The table itself.
       
   419 };
       
   420 
       
   421 
       
   422 //  Pipelines & Stages ---------------------------------------------------------------------------------------------
       
   423 
       
   424 // A single stage
       
   425 struct _cmsStage_struct {
       
   426 
       
   427     cmsContext          ContextID;
       
   428 
       
   429     cmsStageSignature   Type;           // Identifies the stage
       
   430     cmsStageSignature   Implements;     // Identifies the *function* of the stage (for optimizations)
       
   431 
       
   432     cmsUInt32Number     InputChannels;  // Input channels -- for optimization purposes
       
   433     cmsUInt32Number     OutputChannels; // Output channels -- for optimization purposes
       
   434 
       
   435     _cmsStageEvalFn     EvalPtr;        // Points to fn that evaluates the stage (always in floating point)
       
   436     _cmsStageDupElemFn  DupElemPtr;     // Points to a fn that duplicates the *data* of the stage
       
   437     _cmsStageFreeElemFn FreePtr;        // Points to a fn that sets the *data* of the stage free
       
   438 
       
   439     // A generic pointer to whatever memory needed by the stage
       
   440     void*               Data;
       
   441 
       
   442     // Maintains linked list (used internally)
       
   443     struct _cmsStage_struct* Next;
       
   444 };
       
   445 
       
   446 // Data kept in "Element" member of cmsStage
       
   447 
       
   448 // Curves
       
   449 typedef struct {
       
   450     cmsUInt32Number nCurves;
       
   451     cmsToneCurve**  TheCurves;
       
   452 
       
   453 } _cmsStageToneCurvesData;
       
   454 
       
   455 // Matrix
       
   456 typedef struct {
       
   457     cmsFloat64Number*  Double;          // floating point for the matrix
       
   458     cmsFloat64Number*  Offset;          // The offset
       
   459 
       
   460 } _cmsStageMatrixData;
       
   461 
       
   462 // CLUT
       
   463 typedef struct {
       
   464 
       
   465     union {                       // Can have only one of both representations at same time
       
   466         cmsUInt16Number*  T;      // Points to the table 16 bits table
       
   467         cmsFloat32Number* TFloat; // Points to the cmsFloat32Number table
       
   468 
       
   469     } Tab;
       
   470 
       
   471     cmsInterpParams* Params;
       
   472     cmsUInt32Number  nEntries;
       
   473     cmsBool          HasFloatValues;
       
   474 
       
   475 } _cmsStageCLutData;
       
   476 
       
   477 
       
   478 // Special Stages (cannot be saved)
       
   479 cmsStage*        _cmsStageAllocLab2XYZ(cmsContext ContextID);
       
   480 cmsStage*        _cmsStageAllocXYZ2Lab(cmsContext ContextID);
       
   481 cmsStage*        _cmsStageAllocLabPrelin(cmsContext ContextID);
       
   482 cmsStage*        _cmsStageAllocLabV2ToV4(cmsContext ContextID);
       
   483 cmsStage*        _cmsStageAllocLabV2ToV4curves(cmsContext ContextID);
       
   484 cmsStage*        _cmsStageAllocLabV4ToV2(cmsContext ContextID);
       
   485 cmsStage*        _cmsStageAllocNamedColor(cmsNAMEDCOLORLIST* NamedColorList);
       
   486 cmsStage*        _cmsStageAllocIdentityCurves(cmsContext ContextID, int nChannels);
       
   487 cmsStage*        _cmsStageAllocIdentityCLut(cmsContext ContextID, int nChan);
       
   488 
       
   489 // For curve set only
       
   490 cmsToneCurve**     _cmsStageGetPtrToCurveSet(const cmsStage* mpe);
       
   491 
       
   492 
       
   493 // Pipeline Evaluator (in floating point)
       
   494 typedef void (* _cmsPipelineEvalFloatFn)(const cmsFloat32Number In[],
       
   495                                          cmsFloat32Number Out[],
       
   496                                          const void* Data);
       
   497 
       
   498 struct _cmsPipeline_struct {
       
   499 
       
   500     cmsStage* Elements;                                // Points to elements chain
       
   501     cmsUInt32Number InputChannels, OutputChannels;
       
   502 
       
   503     // Data & evaluators
       
   504     void *Data;
       
   505 
       
   506    _cmsOPTeval16Fn         Eval16Fn;
       
   507    _cmsPipelineEvalFloatFn EvalFloatFn;
       
   508    _cmsOPTfreeDataFn       FreeDataFn;
       
   509    _cmsOPTdupDataFn        DupDataFn;
       
   510 
       
   511     cmsContext ContextID;            // Environment
       
   512 
       
   513     cmsBool  SaveAs8Bits;            // Implemntation-specific: save as 8 bits if possible
       
   514 };
       
   515 
       
   516 // LUT reading & creation -------------------------------------------------------------------------------------------
       
   517 
       
   518 // Read tags using low-level function, provide necessary glue code to adapt versions, etc. All those return a brand new copy
       
   519 // of the LUTS, since ownership of original is up to the profile. The user should free allocated resources.
       
   520 
       
   521 cmsPipeline*      _cmsReadInputLUT(cmsHPROFILE hProfile, int Intent);
       
   522 cmsPipeline*      _cmsReadOutputLUT(cmsHPROFILE hProfile, int Intent);
       
   523 cmsPipeline*      _cmsReadDevicelinkLUT(cmsHPROFILE hProfile, int Intent);
       
   524 
       
   525 // Special values
       
   526 cmsBool           _cmsReadMediaWhitePoint(cmsCIEXYZ* Dest, cmsHPROFILE hProfile);
       
   527 cmsBool           _cmsReadCHAD(cmsMAT3* Dest, cmsHPROFILE hProfile);
       
   528 
       
   529 // Profile linker --------------------------------------------------------------------------------------------------
       
   530 
       
   531 cmsPipeline* _cmsLinkProfiles(cmsContext         ContextID,
       
   532                               cmsUInt32Number    nProfiles,
       
   533                               cmsUInt32Number    TheIntents[],
       
   534                               cmsHPROFILE        hProfiles[],
       
   535                               cmsBool            BPC[],
       
   536                               cmsFloat64Number   AdaptationStates[],
       
   537                               cmsUInt32Number    dwFlags);
       
   538 
       
   539 // Sequence --------------------------------------------------------------------------------------------------------
       
   540 
       
   541 cmsSEQ* _cmsReadProfileSequence(cmsHPROFILE hProfile);
       
   542 cmsBool _cmsWriteProfileSequence(cmsHPROFILE hProfile, const cmsSEQ* seq);
       
   543 cmsSEQ* _cmsCompileProfileSequence(cmsContext ContextID, cmsUInt32Number nProfiles, cmsHPROFILE hProfiles[]);
       
   544 
       
   545 
       
   546 // LUT optimization ------------------------------------------------------------------------------------------------
       
   547 
       
   548 cmsUInt16Number  _cmsQuantizeVal(cmsFloat64Number i, int MaxSamples);
       
   549 int              _cmsReasonableGridpointsByColorspace(cmsColorSpaceSignature Colorspace, cmsUInt32Number dwFlags);
       
   550 
       
   551 cmsBool          _cmsEndPointsBySpace(cmsColorSpaceSignature Space,
       
   552                                       cmsUInt16Number **White,
       
   553                                       cmsUInt16Number **Black,
       
   554                                       cmsUInt32Number *nOutputs);
       
   555 
       
   556 cmsBool          _cmsOptimizePipeline(cmsPipeline**    Lut,
       
   557                                       int              Intent,
       
   558                                       cmsUInt32Number* InputFormat,
       
   559                                       cmsUInt32Number* OutputFormat,
       
   560                                       cmsUInt32Number* dwFlags );
       
   561 
       
   562 
       
   563 // Hi level LUT building ----------------------------------------------------------------------------------------------
       
   564 
       
   565 cmsPipeline*     _cmsCreateGamutCheckPipeline(cmsContext ContextID,
       
   566                                               cmsHPROFILE hProfiles[],
       
   567                                               cmsBool  BPC[],
       
   568                                               cmsUInt32Number Intents[],
       
   569                                               cmsFloat64Number AdaptationStates[],
       
   570                                               cmsUInt32Number nGamutPCSposition,
       
   571                                               cmsHPROFILE hGamut);
       
   572 
       
   573 
       
   574 // Formatters ------------------------------------------------------------------------------------------------------------
       
   575 
       
   576 cmsBool         _cmsFormatterIsFloat(cmsUInt32Number Type);
       
   577 cmsBool         _cmsFormatterIs8bit(cmsUInt32Number Type);
       
   578 
       
   579 cmsFormatter    _cmsGetFormatter(cmsUInt32Number Type,          // Specific type, i.e. TYPE_RGB_8
       
   580                                  cmsFormatterDirection Dir,
       
   581                                  cmsUInt32Number dwFlags);
       
   582 
       
   583 
       
   584 // Transform logic ------------------------------------------------------------------------------------------------------
       
   585 
       
   586 struct _cmstransform_struct;
       
   587 
       
   588 // Full xform
       
   589 typedef void (* _cmsTransformFn)(struct _cmstransform_struct *Transform,
       
   590                                  const void* InputBuffer,
       
   591                                  void* OutputBuffer, cmsUInt32Number Size);
       
   592 
       
   593 typedef struct {
       
   594 
       
   595     cmsUInt32Number InputFormat, OutputFormat; // Keep formats for further reference
       
   596     cmsUInt32Number StrideIn, StrideOut;       // Planar support
       
   597 
       
   598 } cmsFormatterInfo;
       
   599 
       
   600 // Transformation
       
   601 typedef struct _cmstransform_struct {
       
   602 
       
   603     cmsUInt32Number InputFormat, OutputFormat; // Keep formats for further reference
       
   604 
       
   605     // Points to transform code
       
   606     _cmsTransformFn xform;
       
   607 
       
   608     // Formatters, cannot be embedded into LUT because cache
       
   609     cmsFormatter16 FromInput;
       
   610     cmsFormatter16 ToOutput;
       
   611 
       
   612     cmsFormatterFloat FromInputFloat;
       
   613     cmsFormatterFloat ToOutputFloat;
       
   614 
       
   615     // 1-pixel cache (16 bits only)
       
   616     cmsUInt16Number CacheIn[cmsMAXCHANNELS];
       
   617     cmsUInt16Number CacheOut[cmsMAXCHANNELS];
       
   618 
       
   619     // Semaphor for cache
       
   620     LCMS_RWLOCK_T rwlock;
       
   621 
       
   622     // A MPE LUT holding the full (optimized) transform
       
   623     cmsPipeline* Lut;
       
   624 
       
   625     // A MPE LUT holding the gamut check. It goes from the input space to bilevel
       
   626     cmsPipeline* GamutCheck;
       
   627 
       
   628     // Colorant tables
       
   629     cmsNAMEDCOLORLIST* InputColorant;       // Input Colorant table
       
   630     cmsNAMEDCOLORLIST* OutputColorant;      // Colorant table (for n chans > CMYK)
       
   631 
       
   632     // Informational only
       
   633     cmsColorSpaceSignature EntryColorSpace;
       
   634     cmsColorSpaceSignature ExitColorSpace;
       
   635 
       
   636     // Profiles used to create the transform
       
   637     cmsSEQ* Sequence;
       
   638 
       
   639     cmsUInt32Number  dwOriginalFlags;
       
   640     cmsFloat64Number AdaptationState;
       
   641 
       
   642     // The intent of this transform. That is usually the last intent in the profilechain, but may differ
       
   643     cmsUInt32Number RenderingIntent;
       
   644 
       
   645     // An id that uniquely identifies the running context. May be null.
       
   646     cmsContext ContextID;
       
   647 
       
   648 } _cmsTRANSFORM;
       
   649 
       
   650 // --------------------------------------------------------------------------------------------------
       
   651 
       
   652 cmsHTRANSFORM _cmsChain2Lab(cmsContext             ContextID,
       
   653                             cmsUInt32Number        nProfiles,
       
   654                             cmsUInt32Number        InputFormat,
       
   655                             cmsUInt32Number        OutputFormat,
       
   656                             const cmsUInt32Number  Intents[],
       
   657                             const cmsHPROFILE      hProfiles[],
       
   658                             const cmsBool          BPC[],
       
   659                             const cmsFloat64Number AdaptationStates[],
       
   660                             cmsUInt32Number        dwFlags);
       
   661 
       
   662 
       
   663 cmsToneCurve* _cmsBuildKToneCurve(cmsContext       ContextID,
       
   664                             cmsUInt32Number        nPoints,
       
   665                             cmsUInt32Number        nProfiles,
       
   666                             const cmsUInt32Number  Intents[],
       
   667                             const cmsHPROFILE      hProfiles[],
       
   668                             const cmsBool          BPC[],
       
   669                             const cmsFloat64Number AdaptationStates[],
       
   670                             cmsUInt32Number        dwFlags);
       
   671 
       
   672 cmsBool   _cmsAdaptationMatrix(cmsMAT3* r, const cmsMAT3* ConeMatrix, const cmsCIEXYZ* FromIll, const cmsCIEXYZ* ToIll);
       
   673 
       
   674 cmsBool   _cmsBuildRGB2XYZtransferMatrix(cmsMAT3* r, const cmsCIExyY* WhitePoint, const cmsCIExyYTRIPLE* Primaries);
       
   675 
       
   676 
       
   677 #define _lcms_internal_H
       
   678 #endif