lcms2mt_plugin.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. //---------------------------------------------------------------------------------
  2. //
  3. // Little Color Management System
  4. // Copyright (c) 1998-2023 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 writers 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. #ifndef _lcms2mt_plugin_H
  31. // Deal with Microsoft's attempt at deprecating C standard runtime functions
  32. #ifdef _MSC_VER
  33. # if (_MSC_VER >= 1400)
  34. # ifndef _CRT_SECURE_NO_DEPRECATE
  35. # define _CRT_SECURE_NO_DEPRECATE
  36. # endif
  37. # ifndef _CRT_SECURE_NO_WARNINGS
  38. # define _CRT_SECURE_NO_WARNINGS
  39. # endif
  40. # endif
  41. #endif
  42. #ifndef _lcms2mt_H
  43. #include "lcms2mt.h"
  44. #endif
  45. // We need some standard C functions.
  46. #include <stdlib.h>
  47. #include <math.h>
  48. #include <stdarg.h>
  49. #include <memory.h>
  50. #include <string.h>
  51. #ifndef CMS_USE_CPP_API
  52. # ifdef __cplusplus
  53. extern "C" {
  54. # endif
  55. #endif
  56. // Vector & Matrix operations -----------------------------------------------------------------------
  57. // Axis of the matrix/array. No specific meaning at all.
  58. #define VX 0
  59. #define VY 1
  60. #define VZ 2
  61. // Vectors
  62. typedef struct {
  63. cmsFloat64Number n[3];
  64. } cmsVEC3;
  65. // 3x3 Matrix
  66. typedef struct {
  67. cmsVEC3 v[3];
  68. } cmsMAT3;
  69. CMSAPI void CMSEXPORT _cmsVEC3init(cmsContext ContextID, cmsVEC3* r, cmsFloat64Number x, cmsFloat64Number y, cmsFloat64Number z);
  70. CMSAPI void CMSEXPORT _cmsVEC3minus(cmsContext ContextID, cmsVEC3* r, const cmsVEC3* a, const cmsVEC3* b);
  71. CMSAPI void CMSEXPORT _cmsVEC3cross(cmsContext ContextID, cmsVEC3* r, const cmsVEC3* u, const cmsVEC3* v);
  72. CMSAPI cmsFloat64Number CMSEXPORT _cmsVEC3dot(cmsContext ContextID, const cmsVEC3* u, const cmsVEC3* v);
  73. CMSAPI cmsFloat64Number CMSEXPORT _cmsVEC3length(cmsContext ContextID, const cmsVEC3* a);
  74. CMSAPI cmsFloat64Number CMSEXPORT _cmsVEC3distance(cmsContext ContextID, const cmsVEC3* a, const cmsVEC3* b);
  75. CMSAPI void CMSEXPORT _cmsMAT3identity(cmsContext ContextID, cmsMAT3* a);
  76. CMSAPI cmsBool CMSEXPORT _cmsMAT3isIdentity(cmsContext ContextID, const cmsMAT3* a);
  77. CMSAPI void CMSEXPORT _cmsMAT3per(cmsContext ContextID, cmsMAT3* r, const cmsMAT3* a, const cmsMAT3* b);
  78. CMSAPI cmsBool CMSEXPORT _cmsMAT3inverse(cmsContext ContextID, const cmsMAT3* a, cmsMAT3* b);
  79. CMSAPI cmsBool CMSEXPORT _cmsMAT3solve(cmsContext ContextID, cmsVEC3* x, cmsMAT3* a, cmsVEC3* b);
  80. CMSAPI void CMSEXPORT _cmsMAT3eval(cmsContext ContextID, cmsVEC3* r, const cmsMAT3* a, const cmsVEC3* v);
  81. // MD5 low level -------------------------------------------------------------------------------------
  82. CMSAPI cmsHANDLE CMSEXPORT cmsMD5alloc(cmsContext ContextID);
  83. CMSAPI void CMSEXPORT cmsMD5add(cmsHANDLE Handle, const cmsUInt8Number* buf, cmsUInt32Number len);
  84. CMSAPI void CMSEXPORT cmsMD5finish(cmsContext ContextID, cmsProfileID* ProfileID, cmsHANDLE Handle);
  85. // Error logging -------------------------------------------------------------------------------------
  86. CMSAPI void CMSEXPORT cmsSignalError(cmsContext ContextID, cmsUInt32Number ErrorCode, const char *ErrorText, ...);
  87. // Memory management ----------------------------------------------------------------------------------
  88. CMSAPI void* CMSEXPORT _cmsMalloc(cmsContext ContextID, cmsUInt32Number size);
  89. CMSAPI void* CMSEXPORT _cmsMallocZero(cmsContext ContextID, cmsUInt32Number size);
  90. CMSAPI void* CMSEXPORT _cmsCalloc(cmsContext ContextID, cmsUInt32Number num, cmsUInt32Number size);
  91. CMSAPI void* CMSEXPORT _cmsRealloc(cmsContext ContextID, void* Ptr, cmsUInt32Number NewSize);
  92. CMSAPI void CMSEXPORT _cmsFree(cmsContext ContextID, void* Ptr);
  93. CMSAPI void* CMSEXPORT _cmsDupMem(cmsContext ContextID, const void* Org, cmsUInt32Number size);
  94. // I/O handler ----------------------------------------------------------------------------------
  95. struct _cms_io_handler {
  96. void* stream; // Associated stream, which is implemented differently depending on media.
  97. cmsUInt32Number UsedSpace;
  98. cmsUInt32Number ReportedSize;
  99. char PhysicalFile[cmsMAX_PATH];
  100. cmsUInt32Number (* Read)(cmsContext ContextID, struct _cms_io_handler* iohandler, void *Buffer,
  101. cmsUInt32Number size,
  102. cmsUInt32Number count);
  103. cmsBool (* Seek)(cmsContext ContextID, struct _cms_io_handler* iohandler, cmsUInt32Number offset);
  104. cmsBool (* Close)(cmsContext ContextID, struct _cms_io_handler* iohandler);
  105. cmsUInt32Number (* Tell)(cmsContext ContextID, struct _cms_io_handler* iohandler);
  106. cmsBool (* Write)(cmsContext ContextID, struct _cms_io_handler* iohandler, cmsUInt32Number size,
  107. const void* Buffer);
  108. };
  109. // Endianness adjust functions
  110. CMSAPI cmsUInt16Number CMSEXPORT _cmsAdjustEndianess16(cmsUInt16Number Word);
  111. CMSAPI cmsUInt32Number CMSEXPORT _cmsAdjustEndianess32(cmsUInt32Number Value);
  112. CMSAPI void CMSEXPORT _cmsAdjustEndianess64(cmsUInt64Number* Result, cmsUInt64Number* QWord);
  113. // Helper IO functions
  114. CMSAPI cmsBool CMSEXPORT _cmsReadUInt8Number(cmsContext ContextID, cmsIOHANDLER* io, cmsUInt8Number* n);
  115. CMSAPI cmsBool CMSEXPORT _cmsReadUInt16Number(cmsContext ContextID, cmsIOHANDLER* io, cmsUInt16Number* n);
  116. CMSAPI cmsBool CMSEXPORT _cmsReadUInt32Number(cmsContext ContextID, cmsIOHANDLER* io, cmsUInt32Number* n);
  117. CMSAPI cmsBool CMSEXPORT _cmsReadFloat32Number(cmsContext ContextID, cmsIOHANDLER* io, cmsFloat32Number* n);
  118. CMSAPI cmsBool CMSEXPORT _cmsReadUInt64Number(cmsContext ContextID, cmsIOHANDLER* io, cmsUInt64Number* n);
  119. CMSAPI cmsBool CMSEXPORT _cmsRead15Fixed16Number(cmsContext ContextID, cmsIOHANDLER* io, cmsFloat64Number* n);
  120. CMSAPI cmsBool CMSEXPORT _cmsReadXYZNumber(cmsContext ContextID, cmsIOHANDLER* io, cmsCIEXYZ* XYZ);
  121. CMSAPI cmsBool CMSEXPORT _cmsReadUInt16Array(cmsContext ContextID, cmsIOHANDLER* io, cmsUInt32Number n, cmsUInt16Number* Array);
  122. CMSAPI cmsBool CMSEXPORT _cmsWriteUInt8Number(cmsContext ContextID, cmsIOHANDLER* io, cmsUInt8Number n);
  123. CMSAPI cmsBool CMSEXPORT _cmsWriteUInt16Number(cmsContext ContextID, cmsIOHANDLER* io, cmsUInt16Number n);
  124. CMSAPI cmsBool CMSEXPORT _cmsWriteUInt32Number(cmsContext ContextID, cmsIOHANDLER* io, cmsUInt32Number n);
  125. CMSAPI cmsBool CMSEXPORT _cmsWriteFloat32Number(cmsContext ContextID, cmsIOHANDLER* io, cmsFloat32Number n);
  126. CMSAPI cmsBool CMSEXPORT _cmsWriteUInt64Number(cmsContext ContextID, cmsIOHANDLER* io, cmsUInt64Number* n);
  127. CMSAPI cmsBool CMSEXPORT _cmsWrite15Fixed16Number(cmsContext ContextID, cmsIOHANDLER* io, cmsFloat64Number n);
  128. CMSAPI cmsBool CMSEXPORT _cmsWriteXYZNumber(cmsContext ContextID, cmsIOHANDLER* io, const cmsCIEXYZ* XYZ);
  129. CMSAPI cmsBool CMSEXPORT _cmsWriteUInt16Array(cmsContext ContextID, cmsIOHANDLER* io, cmsUInt32Number n, const cmsUInt16Number* Array);
  130. // ICC base tag
  131. typedef struct {
  132. cmsTagTypeSignature sig;
  133. cmsInt8Number reserved[4];
  134. } _cmsTagBase;
  135. // Type base helper functions
  136. CMSAPI cmsTagTypeSignature CMSEXPORT _cmsReadTypeBase(cmsContext ContextID, cmsIOHANDLER* io);
  137. CMSAPI cmsBool CMSEXPORT _cmsWriteTypeBase(cmsContext ContextID, cmsIOHANDLER* io, cmsTagTypeSignature sig);
  138. // Alignment functions
  139. CMSAPI cmsBool CMSEXPORT _cmsReadAlignment(cmsContext ContextID, cmsIOHANDLER* io);
  140. CMSAPI cmsBool CMSEXPORT _cmsWriteAlignment(cmsContext ContextID, cmsIOHANDLER* io);
  141. // To deal with text streams. 2K at most
  142. CMSAPI cmsBool CMSEXPORT _cmsIOPrintf(cmsContext ContextID, cmsIOHANDLER* io, const char* frm, ...);
  143. // Fixed point helper functions
  144. CMSAPI cmsFloat64Number CMSEXPORT _cms8Fixed8toDouble(cmsContext ContextID, cmsUInt16Number fixed8);
  145. CMSAPI cmsUInt16Number CMSEXPORT _cmsDoubleTo8Fixed8(cmsContext ContextID, cmsFloat64Number val);
  146. CMSAPI cmsFloat64Number CMSEXPORT _cms15Fixed16toDouble(cmsContext ContextID, cmsS15Fixed16Number fix32);
  147. CMSAPI cmsS15Fixed16Number CMSEXPORT _cmsDoubleTo15Fixed16(cmsContext ContextID, cmsFloat64Number v);
  148. // Date/time helper functions
  149. CMSAPI void CMSEXPORT _cmsEncodeDateTimeNumber(cmsContext ContextID, cmsDateTimeNumber *Dest, const struct tm *Source);
  150. CMSAPI void CMSEXPORT _cmsDecodeDateTimeNumber(cmsContext ContextID, const cmsDateTimeNumber *Source, struct tm *Dest);
  151. //----------------------------------------------------------------------------------------------------------
  152. // Shared callbacks for user data
  153. typedef void (* _cmsFreeUserDataFn)(cmsContext ContextID, void* Data);
  154. typedef void* (* _cmsDupUserDataFn)(cmsContext ContextID, const void* Data);
  155. //----------------------------------------------------------------------------------------------------------
  156. // Plug-in foundation
  157. #define cmsPluginMagicNumber 0x61637070 // 'acpp'
  158. #define cmsPluginMemHandlerSig 0x6D656D48 // 'memH'
  159. #define cmsPluginInterpolationSig 0x696E7048 // 'inpH'
  160. #define cmsPluginParametricCurveSig 0x70617248 // 'parH'
  161. #define cmsPluginFormattersSig 0x66726D48 // 'frmH
  162. #define cmsPluginTagTypeSig 0x74797048 // 'typH'
  163. #define cmsPluginTagSig 0x74616748 // 'tagH'
  164. #define cmsPluginRenderingIntentSig 0x696E7448 // 'intH'
  165. #define cmsPluginMultiProcessElementSig 0x6D706548 // 'mpeH'
  166. #define cmsPluginOptimizationSig 0x6F707448 // 'optH'
  167. #define cmsPluginTransformSig 0x7A666D48 // 'xfmH'
  168. #define cmsPluginMutexSig 0x6D747A48 // 'mtxH'
  169. #define cmsPluginParalellizationSig 0x70726C48 // 'prlH
  170. typedef struct _cmsPluginBaseStruct {
  171. cmsUInt32Number Magic; // 'acpp' signature
  172. cmsUInt32Number ExpectedVersion; // Expected version of LittleCMS
  173. cmsUInt32Number Type; // Type of plug-in
  174. struct _cmsPluginBaseStruct* Next; // For multiple plugin definition. NULL for end of list.
  175. } cmsPluginBase;
  176. // Maximum number of types in a plugin array
  177. #define MAX_TYPES_IN_LCMS_PLUGIN 20
  178. //----------------------------------------------------------------------------------------------------------
  179. // Memory handler. Each new plug-in type replaces current behaviour
  180. typedef void* (* _cmsMallocFnPtrType)(cmsContext ContextID, cmsUInt32Number size);
  181. typedef void (* _cmsFreeFnPtrType)(cmsContext ContextID, void *Ptr);
  182. typedef void* (* _cmsReallocFnPtrType)(cmsContext ContextID, void* Ptr, cmsUInt32Number NewSize);
  183. typedef void* (* _cmsMalloZerocFnPtrType)(cmsContext ContextID, cmsUInt32Number size);
  184. typedef void* (* _cmsCallocFnPtrType)(cmsContext ContextID, cmsUInt32Number num, cmsUInt32Number size);
  185. typedef void* (* _cmsDupFnPtrType)(cmsContext ContextID, const void* Org, cmsUInt32Number size);
  186. typedef struct {
  187. cmsPluginBase base;
  188. // Required
  189. _cmsMallocFnPtrType MallocPtr;
  190. _cmsFreeFnPtrType FreePtr;
  191. _cmsReallocFnPtrType ReallocPtr;
  192. // Optional
  193. _cmsMalloZerocFnPtrType MallocZeroPtr;
  194. _cmsCallocFnPtrType CallocPtr;
  195. _cmsDupFnPtrType DupPtr;
  196. } cmsPluginMemHandler;
  197. // ------------------------------------------------------------------------------------------------------------------
  198. // Interpolation. 16 bits and floating point versions.
  199. struct _cms_interp_struc;
  200. // Interpolation callbacks
  201. // 16 bits forward interpolation. This function performs precision-limited linear interpolation
  202. // and is supposed to be quite fast. Implementation may be tetrahedral or trilinear, and plug-ins may
  203. // choose to implement any other interpolation algorithm.
  204. typedef void (* _cmsInterpFn16)(cmsContext ContextID,
  205. CMSREGISTER const cmsUInt16Number Input[],
  206. CMSREGISTER cmsUInt16Number Output[],
  207. CMSREGISTER const struct _cms_interp_struc* p);
  208. // Floating point forward interpolation. Full precision interpolation using floats. This is not a
  209. // time critical function. Implementation may be tetrahedral or trilinear, and plug-ins may
  210. // choose to implement any other interpolation algorithm.
  211. typedef void (* _cmsInterpFnFloat)(cmsContext ContextID, cmsFloat32Number const Input[],
  212. cmsFloat32Number Output[],
  213. const struct _cms_interp_struc* p);
  214. // This type holds a pointer to an interpolator that can be either 16 bits or float
  215. typedef union {
  216. _cmsInterpFn16 Lerp16; // Forward interpolation in 16 bits
  217. _cmsInterpFnFloat LerpFloat; // Forward interpolation in floating point
  218. } cmsInterpFunction;
  219. // Flags for interpolator selection
  220. #define CMS_LERP_FLAGS_16BITS 0x0000 // The default
  221. #define CMS_LERP_FLAGS_FLOAT 0x0001 // Requires different implementation
  222. #define CMS_LERP_FLAGS_TRILINEAR 0x0100 // Hint only
  223. #define MAX_INPUT_DIMENSIONS 15
  224. typedef struct _cms_interp_struc { // Used on all interpolations. Supplied by lcms2 when calling the interpolation function
  225. cmsUInt32Number dwFlags; // Keep original flags
  226. cmsUInt32Number nInputs; // != 1 only in 3D interpolation
  227. cmsUInt32Number nOutputs; // != 1 only in 3D interpolation
  228. cmsUInt32Number nSamples[MAX_INPUT_DIMENSIONS]; // Valid on all kinds of tables
  229. cmsUInt32Number Domain[MAX_INPUT_DIMENSIONS]; // Domain = nSamples - 1
  230. cmsUInt32Number opta[MAX_INPUT_DIMENSIONS]; // Optimization for 3D CLUT. This is the number of nodes premultiplied for each
  231. // dimension. For example, in 7 nodes, 7, 7^2 , 7^3, 7^4, etc. On non-regular
  232. // Samplings may vary according of the number of nodes for each dimension.
  233. const void *Table; // Points to the actual interpolation table
  234. cmsInterpFunction Interpolation; // Points to the function to do the interpolation
  235. } cmsInterpParams;
  236. // Interpolators factory
  237. typedef cmsInterpFunction (* cmsInterpFnFactory)(cmsContext ContextID, cmsUInt32Number nInputChannels, cmsUInt32Number nOutputChannels, cmsUInt32Number dwFlags);
  238. // The plug-in
  239. typedef struct {
  240. cmsPluginBase base;
  241. // Points to a user-supplied function which implements the factory
  242. cmsInterpFnFactory InterpolatorsFactory;
  243. } cmsPluginInterpolation;
  244. //----------------------------------------------------------------------------------------------------------
  245. // Parametric curves. A negative type means same function but analytically inverted. Max. number of params is 10
  246. // Evaluator callback for user-supplied parametric curves. May implement more than one type
  247. typedef cmsFloat64Number (* cmsParametricCurveEvaluator)(cmsContext ContextID, cmsInt32Number Type, const cmsFloat64Number Params[10], cmsFloat64Number R);
  248. // Plug-in may implement an arbitrary number of parametric curves
  249. typedef struct {
  250. cmsPluginBase base;
  251. cmsUInt32Number nFunctions; // Number of supported functions
  252. cmsUInt32Number FunctionTypes[MAX_TYPES_IN_LCMS_PLUGIN]; // The identification types
  253. cmsUInt32Number ParameterCount[MAX_TYPES_IN_LCMS_PLUGIN]; // Number of parameters for each function
  254. cmsParametricCurveEvaluator Evaluator; // The evaluator
  255. } cmsPluginParametricCurves;
  256. //----------------------------------------------------------------------------------------------------------
  257. // Formatters. This plug-in adds new handlers, replacing them if they already exist. Formatters dealing with
  258. // cmsFloat32Number (bps = 4) or double (bps = 0) types are requested via FormatterFloat callback. Others come across
  259. // Formatter16 callback
  260. struct _cmstransform_struct;
  261. typedef cmsUInt8Number* (* cmsFormatter16)(cmsContext ContextID,
  262. CMSREGISTER struct _cmstransform_struct* CMMcargo,
  263. CMSREGISTER cmsUInt16Number Values[],
  264. CMSREGISTER cmsUInt8Number* Buffer,
  265. CMSREGISTER cmsUInt32Number Stride);
  266. typedef cmsUInt8Number* (* cmsFormatterFloat)(cmsContext ContextID, struct _cmstransform_struct* CMMcargo,
  267. cmsFloat32Number Values[],
  268. cmsUInt8Number* Buffer,
  269. cmsUInt32Number Stride);
  270. // This type holds a pointer to a formatter that can be either 16 bits or cmsFloat32Number
  271. typedef union {
  272. cmsFormatter16 Fmt16;
  273. cmsFormatterFloat FmtFloat;
  274. } cmsFormatter;
  275. #define CMS_PACK_FLAGS_16BITS 0x0000
  276. #define CMS_PACK_FLAGS_FLOAT 0x0001
  277. typedef enum { cmsFormatterInput=0, cmsFormatterOutput=1 } cmsFormatterDirection;
  278. typedef cmsFormatter (* cmsFormatterFactory)(cmsContext ContextID, cmsUInt32Number Type, // Specific type, i.e. TYPE_RGB_8
  279. cmsFormatterDirection Dir,
  280. cmsUInt32Number dwFlags); // precision
  281. // Plug-in may implement an arbitrary number of formatters
  282. typedef struct {
  283. cmsPluginBase base;
  284. cmsFormatterFactory FormattersFactory;
  285. } cmsPluginFormatters;
  286. //----------------------------------------------------------------------------------------------------------
  287. // Tag type handler. Each type is free to return anything it wants, and it is up to the caller to
  288. // know in advance what is the type contained in the tag.
  289. typedef struct _cms_typehandler_struct {
  290. cmsTagTypeSignature Signature; // The signature of the type
  291. // Allocates and reads items
  292. void * (* ReadPtr)(cmsContext ContextID, struct _cms_typehandler_struct* self,
  293. cmsIOHANDLER* io,
  294. cmsUInt32Number* nItems,
  295. cmsUInt32Number SizeOfTag);
  296. // Writes n Items
  297. cmsBool (* WritePtr)(cmsContext ContextID, struct _cms_typehandler_struct* self,
  298. cmsIOHANDLER* io,
  299. void* Ptr,
  300. cmsUInt32Number nItems);
  301. // Duplicate an item or array of items
  302. void* (* DupPtr)(cmsContext ContextID, struct _cms_typehandler_struct* self,
  303. const void *Ptr,
  304. cmsUInt32Number n);
  305. // Free all resources
  306. void (* FreePtr)(cmsContext ContextID, struct _cms_typehandler_struct* self,
  307. void *Ptr);
  308. // Additional parameters used by the calling thread
  309. cmsUInt32Number ICCVersion;
  310. } cmsTagTypeHandler;
  311. // Each plug-in implements a single type
  312. typedef struct {
  313. cmsPluginBase base;
  314. cmsTagTypeHandler Handler;
  315. } cmsPluginTagType;
  316. //----------------------------------------------------------------------------------------------------------
  317. // This is the tag plugin, which identifies tags. For writing, a pointer to function is provided.
  318. // This function should return the desired type for this tag, given the version of profile
  319. // and the data being serialized.
  320. typedef struct {
  321. cmsUInt32Number ElemCount; // If this tag needs an array, how many elements should keep
  322. // For reading.
  323. cmsUInt32Number nSupportedTypes; // In how many types this tag can come (MAX_TYPES_IN_LCMS_PLUGIN maximum)
  324. cmsTagTypeSignature SupportedTypes[MAX_TYPES_IN_LCMS_PLUGIN];
  325. // For writing
  326. cmsTagTypeSignature (* DecideType)(cmsContext ContextID, cmsFloat64Number ICCVersion, const void *Data);
  327. } cmsTagDescriptor;
  328. // Plug-in implements a single tag
  329. typedef struct {
  330. cmsPluginBase base;
  331. cmsTagSignature Signature;
  332. cmsTagDescriptor Descriptor;
  333. } cmsPluginTag;
  334. //----------------------------------------------------------------------------------------------------------
  335. // Custom intents. This function should join all profiles specified in the array in
  336. // a single LUT. Any custom intent in the chain redirects to custom function. If more than
  337. // one custom intent is found, the one located first is invoked. Usually users should use only one
  338. // custom intent, so mixing custom intents in same multiprofile transform is not supported.
  339. typedef cmsPipeline* (* cmsIntentFn)( cmsContext ContextID,
  340. cmsUInt32Number nProfiles,
  341. cmsUInt32Number Intents[],
  342. cmsHPROFILE hProfiles[],
  343. cmsBool BPC[],
  344. cmsFloat64Number AdaptationStates[],
  345. cmsUInt32Number dwFlags);
  346. // Each plug-in defines a single intent number.
  347. typedef struct {
  348. cmsPluginBase base;
  349. cmsUInt32Number Intent;
  350. cmsIntentFn Link;
  351. char Description[256];
  352. } cmsPluginRenderingIntent;
  353. // The default ICC intents (perceptual, saturation, rel.col and abs.col)
  354. CMSAPI cmsPipeline* CMSEXPORT _cmsDefaultICCintents(cmsContext ContextID,
  355. cmsUInt32Number nProfiles,
  356. cmsUInt32Number Intents[],
  357. cmsHPROFILE hProfiles[],
  358. cmsBool BPC[],
  359. cmsFloat64Number AdaptationStates[],
  360. cmsUInt32Number dwFlags);
  361. //----------------------------------------------------------------------------------------------------------
  362. // Pipelines, Multi Process Elements.
  363. typedef void (* _cmsStageEvalFn) (cmsContext ContextID, const cmsFloat32Number In[], cmsFloat32Number Out[], const cmsStage* mpe);
  364. typedef void*(* _cmsStageDupElemFn) (cmsContext ContextID, cmsStage* mpe);
  365. typedef void (* _cmsStageFreeElemFn) (cmsContext ContextID, cmsStage* mpe);
  366. // This function allocates a generic MPE
  367. CMSAPI cmsStage* CMSEXPORT _cmsStageAllocPlaceholder(cmsContext ContextID,
  368. cmsStageSignature Type,
  369. cmsUInt32Number InputChannels,
  370. cmsUInt32Number OutputChannels,
  371. _cmsStageEvalFn EvalPtr, // Points to fn that evaluates the element (always in floating point)
  372. _cmsStageDupElemFn DupElemPtr, // Points to a fn that duplicates the stage
  373. _cmsStageFreeElemFn FreePtr, // Points to a fn that sets the element free
  374. void* Data); // A generic pointer to whatever memory needed by the element
  375. typedef struct {
  376. cmsPluginBase base;
  377. cmsTagTypeHandler Handler;
  378. } cmsPluginMultiProcessElement;
  379. // Data kept in "Element" member of cmsStage
  380. // Curves
  381. typedef struct {
  382. cmsUInt32Number nCurves;
  383. cmsToneCurve** TheCurves;
  384. } _cmsStageToneCurvesData;
  385. // Matrix
  386. typedef struct {
  387. cmsFloat64Number* Double; // floating point for the matrix
  388. cmsFloat64Number* Offset; // The offset
  389. } _cmsStageMatrixData;
  390. // CLUT
  391. typedef struct {
  392. union { // Can have only one of both representations at same time
  393. cmsUInt16Number* T; // Points to the table 16 bits table
  394. cmsFloat32Number* TFloat; // Points to the cmsFloat32Number table
  395. } Tab;
  396. cmsInterpParams* Params;
  397. cmsUInt32Number nEntries;
  398. cmsBool HasFloatValues;
  399. } _cmsStageCLutData;
  400. //----------------------------------------------------------------------------------------------------------
  401. // Optimization. Using this plug-in, additional optimization strategies may be implemented.
  402. // The function should return TRUE if any optimization is done on the LUT, this terminates
  403. // the optimization search. Or FALSE if it is unable to optimize and want to give a chance
  404. // to the rest of optimizers.
  405. typedef cmsBool (* _cmsOPToptimizeFn)(cmsContext ContextID,
  406. cmsPipeline** Lut,
  407. cmsUInt32Number Intent,
  408. cmsUInt32Number* InputFormat,
  409. cmsUInt32Number* OutputFormat,
  410. cmsUInt32Number* dwFlags);
  411. // Pipeline Evaluator (in 16 bits)
  412. typedef void (* _cmsPipelineEval16Fn)(cmsContext ContextID,
  413. CMSREGISTER const cmsUInt16Number In[],
  414. CMSREGISTER cmsUInt16Number Out[],
  415. const void* Data);
  416. // Pipeline Evaluator (in floating point)
  417. typedef void (* _cmsPipelineEvalFloatFn)(cmsContext ContextID,
  418. const cmsFloat32Number In[],
  419. cmsFloat32Number Out[],
  420. const void* Data);
  421. // This function may be used to set the optional evaluator and a block of private data. If private data is being used, an optional
  422. // duplicator and free functions should also be specified in order to duplicate the LUT construct. Use NULL to inhibit such functionality.
  423. CMSAPI void CMSEXPORT _cmsPipelineSetOptimizationParameters(
  424. cmsContext ContextID,
  425. cmsPipeline* Lut,
  426. _cmsPipelineEval16Fn Eval16,
  427. void* PrivateData,
  428. _cmsFreeUserDataFn FreePrivateDataFn,
  429. _cmsDupUserDataFn DupPrivateDataFn);
  430. typedef struct {
  431. cmsPluginBase base;
  432. // Optimize entry point
  433. _cmsOPToptimizeFn OptimizePtr;
  434. } cmsPluginOptimization;
  435. //----------------------------------------------------------------------------------------------------------
  436. // Full xform
  437. typedef struct {
  438. cmsUInt32Number BytesPerLineIn;
  439. cmsUInt32Number BytesPerLineOut;
  440. cmsUInt32Number BytesPerPlaneIn;
  441. cmsUInt32Number BytesPerPlaneOut;
  442. } cmsStride;
  443. typedef void (* _cmsTransformFn)(cmsContext ContextID, struct _cmstransform_struct *CMMcargo, // Legacy function, handles just ONE scanline.
  444. const void* InputBuffer,
  445. void* OutputBuffer,
  446. cmsUInt32Number Size,
  447. cmsUInt32Number Stride); // Stride in bytes to the next plane in planar formats
  448. typedef void (*_cmsTransform2Fn)(cmsContext ContextID, struct _cmstransform_struct *CMMcargo,
  449. const void* InputBuffer,
  450. void* OutputBuffer,
  451. cmsUInt32Number PixelsPerLine,
  452. cmsUInt32Number LineCount,
  453. const cmsStride* Stride);
  454. typedef cmsBool (* _cmsTransformFactory)(cmsContext ContextID, _cmsTransformFn* xform,
  455. void** UserData,
  456. _cmsFreeUserDataFn* FreePrivateDataFn,
  457. cmsPipeline** Lut,
  458. cmsUInt32Number* InputFormat,
  459. cmsUInt32Number* OutputFormat,
  460. cmsUInt32Number* dwFlags);
  461. typedef cmsBool (* _cmsTransform2Factory)(cmsContext ContextID, _cmsTransform2Fn* xform,
  462. void** UserData,
  463. _cmsFreeUserDataFn* FreePrivateDataFn,
  464. cmsPipeline** Lut,
  465. cmsUInt32Number* InputFormat,
  466. cmsUInt32Number* OutputFormat,
  467. cmsUInt32Number* dwFlags);
  468. // Retrieve user data as specified by the factory
  469. CMSAPI void CMSEXPORT _cmsSetTransformUserData(struct _cmstransform_struct *CMMcargo, void* ptr, _cmsFreeUserDataFn FreePrivateDataFn);
  470. CMSAPI void * CMSEXPORT _cmsGetTransformUserData(struct _cmstransform_struct *CMMcargo);
  471. // Retrieve formatters
  472. CMSAPI void CMSEXPORT _cmsGetTransformFormatters16 (struct _cmstransform_struct *CMMcargo, cmsFormatter16* FromInput, cmsFormatter16* ToOutput);
  473. CMSAPI void CMSEXPORT _cmsGetTransformFormattersFloat(struct _cmstransform_struct *CMMcargo, cmsFormatterFloat* FromInput, cmsFormatterFloat* ToOutput);
  474. // Retrieve original flags
  475. CMSAPI cmsUInt32Number CMSEXPORT _cmsGetTransformFlags(struct _cmstransform_struct* CMMcargo);
  476. typedef struct {
  477. cmsPluginBase base;
  478. // Transform entry point
  479. union {
  480. _cmsTransformFactory legacy_xform;
  481. _cmsTransform2Factory xform;
  482. } factories;
  483. } cmsPluginTransform;
  484. //----------------------------------------------------------------------------------------------------------
  485. // Mutex
  486. typedef void* (* _cmsCreateMutexFnPtrType)(cmsContext ContextID);
  487. typedef void (* _cmsDestroyMutexFnPtrType)(cmsContext ContextID, void* mtx);
  488. typedef cmsBool (* _cmsLockMutexFnPtrType)(cmsContext ContextID, void* mtx);
  489. typedef void (* _cmsUnlockMutexFnPtrType)(cmsContext ContextID, void* mtx);
  490. typedef struct {
  491. cmsPluginBase base;
  492. _cmsCreateMutexFnPtrType CreateMutexPtr;
  493. _cmsDestroyMutexFnPtrType DestroyMutexPtr;
  494. _cmsLockMutexFnPtrType LockMutexPtr;
  495. _cmsUnlockMutexFnPtrType UnlockMutexPtr;
  496. } cmsPluginMutex;
  497. CMSAPI void* CMSEXPORT _cmsCreateMutex(cmsContext ContextID);
  498. CMSAPI void CMSEXPORT _cmsDestroyMutex(cmsContext ContextID, void* mtx);
  499. CMSAPI cmsBool CMSEXPORT _cmsLockMutex(cmsContext ContextID, void* mtx);
  500. CMSAPI void CMSEXPORT _cmsUnlockMutex(cmsContext ContextID, void* mtx);
  501. //----------------------------------------------------------------------------------------------------------
  502. // Parallelization
  503. CMSAPI _cmsTransform2Fn CMSEXPORT _cmsGetTransformWorker(struct _cmstransform_struct* CMMcargo);
  504. CMSAPI cmsInt32Number CMSEXPORT _cmsGetTransformMaxWorkers(struct _cmstransform_struct* CMMcargo);
  505. CMSAPI cmsUInt32Number CMSEXPORT _cmsGetTransformWorkerFlags(struct _cmstransform_struct* CMMcargo);
  506. // Let's plug-in to guess the best number of workers
  507. #define CMS_GUESS_MAX_WORKERS -1
  508. typedef struct {
  509. cmsPluginBase base;
  510. cmsInt32Number MaxWorkers; // Number of starts to do as maximum
  511. cmsUInt32Number WorkerFlags; // Reserved
  512. _cmsTransform2Fn SchedulerFn; // callback to setup functions
  513. } cmsPluginParalellization;
  514. #ifndef CMS_USE_CPP_API
  515. # ifdef __cplusplus
  516. }
  517. # endif
  518. #endif
  519. #define _lcms2mt_plugin_H
  520. #endif