lcms2_plugin.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. //---------------------------------------------------------------------------------
  2. //
  3. // Little Color Management System
  4. // Copyright (c) 1998-2020 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. #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 WINAPIV 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 WINAPIV _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. 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)(CMSREGISTER const cmsUInt16Number Input[],
  205. CMSREGISTER cmsUInt16Number Output[],
  206. CMSREGISTER const struct _cms_interp_struc* p);
  207. // Floating point forward interpolation. Full precision interpolation using floats. This is not a
  208. // time critical function. Implementation may be tetrahedral or trilinear, and plug-ins may
  209. // choose to implement any other interpolation algorithm.
  210. typedef void (* _cmsInterpFnFloat)(cmsFloat32Number const Input[],
  211. cmsFloat32Number Output[],
  212. const struct _cms_interp_struc* p);
  213. // This type holds a pointer to an interpolator that can be either 16 bits or float
  214. typedef union {
  215. _cmsInterpFn16 Lerp16; // Forward interpolation in 16 bits
  216. _cmsInterpFnFloat LerpFloat; // Forward interpolation in floating point
  217. } cmsInterpFunction;
  218. // Flags for interpolator selection
  219. #define CMS_LERP_FLAGS_16BITS 0x0000 // The default
  220. #define CMS_LERP_FLAGS_FLOAT 0x0001 // Requires different implementation
  221. #define CMS_LERP_FLAGS_TRILINEAR 0x0100 // Hint only
  222. #define MAX_INPUT_DIMENSIONS 15
  223. typedef struct _cms_interp_struc { // Used on all interpolations. Supplied by lcms2 when calling the interpolation function
  224. cmsContext ContextID; // The calling thread
  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)(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)(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)(CMSREGISTER struct _cmstransform_struct* CMMcargo,
  262. CMSREGISTER cmsUInt16Number Values[],
  263. CMSREGISTER cmsUInt8Number* Buffer,
  264. CMSREGISTER cmsUInt32Number Stride);
  265. typedef cmsUInt8Number* (* cmsFormatterFloat)(struct _cmstransform_struct* CMMcargo,
  266. cmsFloat32Number Values[],
  267. cmsUInt8Number* Buffer,
  268. cmsUInt32Number Stride);
  269. // This type holds a pointer to a formatter that can be either 16 bits or cmsFloat32Number
  270. typedef union {
  271. cmsFormatter16 Fmt16;
  272. cmsFormatterFloat FmtFloat;
  273. } cmsFormatter;
  274. #define CMS_PACK_FLAGS_16BITS 0x0000
  275. #define CMS_PACK_FLAGS_FLOAT 0x0001
  276. typedef enum { cmsFormatterInput=0, cmsFormatterOutput=1 } cmsFormatterDirection;
  277. typedef cmsFormatter (* cmsFormatterFactory)(cmsUInt32Number Type, // Specific type, i.e. TYPE_RGB_8
  278. cmsFormatterDirection Dir,
  279. cmsUInt32Number dwFlags); // precision
  280. // Plug-in may implement an arbitrary number of formatters
  281. typedef struct {
  282. cmsPluginBase base;
  283. cmsFormatterFactory FormattersFactory;
  284. } cmsPluginFormatters;
  285. //----------------------------------------------------------------------------------------------------------
  286. // Tag type handler. Each type is free to return anything it wants, and it is up to the caller to
  287. // know in advance what is the type contained in the tag.
  288. typedef struct _cms_typehandler_struct {
  289. cmsTagTypeSignature Signature; // The signature of the type
  290. // Allocates and reads items
  291. void * (* ReadPtr)(struct _cms_typehandler_struct* self,
  292. cmsIOHANDLER* io,
  293. cmsUInt32Number* nItems,
  294. cmsUInt32Number SizeOfTag);
  295. // Writes n Items
  296. cmsBool (* WritePtr)(struct _cms_typehandler_struct* self,
  297. cmsIOHANDLER* io,
  298. void* Ptr,
  299. cmsUInt32Number nItems);
  300. // Duplicate an item or array of items
  301. void* (* DupPtr)(struct _cms_typehandler_struct* self,
  302. const void *Ptr,
  303. cmsUInt32Number n);
  304. // Free all resources
  305. void (* FreePtr)(struct _cms_typehandler_struct* self,
  306. void *Ptr);
  307. // Additional parameters used by the calling thread
  308. cmsContext ContextID;
  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)(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) (const cmsFloat32Number In[], cmsFloat32Number Out[], const cmsStage* mpe);
  364. typedef void*(* _cmsStageDupElemFn) (cmsStage* mpe);
  365. typedef void (* _cmsStageFreeElemFn) (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)(cmsPipeline** Lut,
  406. cmsUInt32Number Intent,
  407. cmsUInt32Number* InputFormat,
  408. cmsUInt32Number* OutputFormat,
  409. cmsUInt32Number* dwFlags);
  410. // Pipeline Evaluator (in 16 bits)
  411. typedef void (* _cmsPipelineEval16Fn)(CMSREGISTER const cmsUInt16Number In[],
  412. CMSREGISTER cmsUInt16Number Out[],
  413. const void* Data);
  414. // Pipeline Evaluator (in floating point)
  415. typedef void (* _cmsPipelineEvalFloatFn)(const cmsFloat32Number In[],
  416. cmsFloat32Number Out[],
  417. const void* Data);
  418. // This function may be used to set the optional evaluator and a block of private data. If private data is being used, an optional
  419. // duplicator and free functions should also be specified in order to duplicate the LUT construct. Use NULL to inhibit such functionality.
  420. CMSAPI void CMSEXPORT _cmsPipelineSetOptimizationParameters(cmsPipeline* Lut,
  421. _cmsPipelineEval16Fn Eval16,
  422. void* PrivateData,
  423. _cmsFreeUserDataFn FreePrivateDataFn,
  424. _cmsDupUserDataFn DupPrivateDataFn);
  425. typedef struct {
  426. cmsPluginBase base;
  427. // Optimize entry point
  428. _cmsOPToptimizeFn OptimizePtr;
  429. } cmsPluginOptimization;
  430. //----------------------------------------------------------------------------------------------------------
  431. // Full xform
  432. typedef struct {
  433. cmsUInt32Number BytesPerLineIn;
  434. cmsUInt32Number BytesPerLineOut;
  435. cmsUInt32Number BytesPerPlaneIn;
  436. cmsUInt32Number BytesPerPlaneOut;
  437. } cmsStride;
  438. typedef void (* _cmsTransformFn)(struct _cmstransform_struct *CMMcargo, // Legacy function, handles just ONE scanline.
  439. const void* InputBuffer,
  440. void* OutputBuffer,
  441. cmsUInt32Number Size,
  442. cmsUInt32Number Stride); // Stride in bytes to the next plana in planar formats
  443. typedef void (*_cmsTransform2Fn)(struct _cmstransform_struct *CMMcargo,
  444. const void* InputBuffer,
  445. void* OutputBuffer,
  446. cmsUInt32Number PixelsPerLine,
  447. cmsUInt32Number LineCount,
  448. const cmsStride* Stride);
  449. typedef cmsBool (* _cmsTransformFactory)(_cmsTransformFn* xform,
  450. void** UserData,
  451. _cmsFreeUserDataFn* FreePrivateDataFn,
  452. cmsPipeline** Lut,
  453. cmsUInt32Number* InputFormat,
  454. cmsUInt32Number* OutputFormat,
  455. cmsUInt32Number* dwFlags);
  456. typedef cmsBool (* _cmsTransform2Factory)(_cmsTransform2Fn* xform,
  457. void** UserData,
  458. _cmsFreeUserDataFn* FreePrivateDataFn,
  459. cmsPipeline** Lut,
  460. cmsUInt32Number* InputFormat,
  461. cmsUInt32Number* OutputFormat,
  462. cmsUInt32Number* dwFlags);
  463. // Retrieve user data as specified by the factory
  464. CMSAPI void CMSEXPORT _cmsSetTransformUserData(struct _cmstransform_struct *CMMcargo, void* ptr, _cmsFreeUserDataFn FreePrivateDataFn);
  465. CMSAPI void * CMSEXPORT _cmsGetTransformUserData(struct _cmstransform_struct *CMMcargo);
  466. // Retrieve formatters
  467. CMSAPI void CMSEXPORT _cmsGetTransformFormatters16 (struct _cmstransform_struct *CMMcargo, cmsFormatter16* FromInput, cmsFormatter16* ToOutput);
  468. CMSAPI void CMSEXPORT _cmsGetTransformFormattersFloat(struct _cmstransform_struct *CMMcargo, cmsFormatterFloat* FromInput, cmsFormatterFloat* ToOutput);
  469. // Retrieve original flags
  470. CMSAPI cmsUInt32Number CMSEXPORT _cmsGetTransformFlags(struct _cmstransform_struct* CMMcargo);
  471. typedef struct {
  472. cmsPluginBase base;
  473. // Transform entry point
  474. union {
  475. _cmsTransformFactory legacy_xform;
  476. _cmsTransform2Factory xform;
  477. } factories;
  478. } cmsPluginTransform;
  479. //----------------------------------------------------------------------------------------------------------
  480. // Mutex
  481. typedef void* (* _cmsCreateMutexFnPtrType)(cmsContext ContextID);
  482. typedef void (* _cmsDestroyMutexFnPtrType)(cmsContext ContextID, void* mtx);
  483. typedef cmsBool (* _cmsLockMutexFnPtrType)(cmsContext ContextID, void* mtx);
  484. typedef void (* _cmsUnlockMutexFnPtrType)(cmsContext ContextID, void* mtx);
  485. typedef struct {
  486. cmsPluginBase base;
  487. _cmsCreateMutexFnPtrType CreateMutexPtr;
  488. _cmsDestroyMutexFnPtrType DestroyMutexPtr;
  489. _cmsLockMutexFnPtrType LockMutexPtr;
  490. _cmsUnlockMutexFnPtrType UnlockMutexPtr;
  491. } cmsPluginMutex;
  492. CMSAPI void* CMSEXPORT _cmsCreateMutex(cmsContext ContextID);
  493. CMSAPI void CMSEXPORT _cmsDestroyMutex(cmsContext ContextID, void* mtx);
  494. CMSAPI cmsBool CMSEXPORT _cmsLockMutex(cmsContext ContextID, void* mtx);
  495. CMSAPI void CMSEXPORT _cmsUnlockMutex(cmsContext ContextID, void* mtx);
  496. #ifndef CMS_USE_CPP_API
  497. # ifdef __cplusplus
  498. }
  499. # endif
  500. #endif
  501. #define _lcms_plugin_H
  502. #endif