lcms2_plugin.h 31 KB

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