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