lcms2_plugin.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. //---------------------------------------------------------------------------------
  2. //
  3. // Little Color Management System
  4. // Copyright (c) 1998-2017 Marti Maria Saguer
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining
  7. // a copy of this software and associated documentation files (the "Software"),
  8. // to deal in the Software without restriction, including without limitation
  9. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. // and/or sell copies of the Software, and to permit persons to whom the Software
  11. // is furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in
  14. // all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  18. // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. //
  24. //---------------------------------------------------------------------------------
  25. //
  26. // This is the plug-in header file. Normal LittleCMS clients should not use it.
  27. // It is provided for plug-in writters that may want to access the support
  28. // functions to do low level operations. All plug-in related structures
  29. // are defined here. Including this file forces to include the standard API too.
  30. #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. // Error logging -------------------------------------------------------------------------------------
  82. CMSAPI void CMSEXPORT cmsSignalError(cmsContext ContextID, cmsUInt32Number ErrorCode, const char *ErrorText, ...);
  83. // Memory management ----------------------------------------------------------------------------------
  84. CMSAPI void* CMSEXPORT _cmsMalloc(cmsContext ContextID, cmsUInt32Number size);
  85. CMSAPI void* CMSEXPORT _cmsMallocZero(cmsContext ContextID, cmsUInt32Number size);
  86. CMSAPI void* CMSEXPORT _cmsCalloc(cmsContext ContextID, cmsUInt32Number num, cmsUInt32Number size);
  87. CMSAPI void* CMSEXPORT _cmsRealloc(cmsContext ContextID, void* Ptr, cmsUInt32Number NewSize);
  88. CMSAPI void CMSEXPORT _cmsFree(cmsContext ContextID, void* Ptr);
  89. CMSAPI void* CMSEXPORT _cmsDupMem(cmsContext ContextID, const void* Org, cmsUInt32Number size);
  90. // I/O handler ----------------------------------------------------------------------------------
  91. struct _cms_io_handler {
  92. void* stream; // Associated stream, which is implemented differently depending on media.
  93. cmsContext ContextID;
  94. cmsUInt32Number UsedSpace;
  95. cmsUInt32Number ReportedSize;
  96. char PhysicalFile[cmsMAX_PATH];
  97. cmsUInt32Number (* Read)(struct _cms_io_handler* iohandler, void *Buffer,
  98. cmsUInt32Number size,
  99. cmsUInt32Number count);
  100. cmsBool (* Seek)(struct _cms_io_handler* iohandler, cmsUInt32Number offset);
  101. cmsBool (* Close)(struct _cms_io_handler* iohandler);
  102. cmsUInt32Number (* Tell)(struct _cms_io_handler* iohandler);
  103. cmsBool (* Write)(struct _cms_io_handler* iohandler, cmsUInt32Number size,
  104. const void* Buffer);
  105. };
  106. // Endianness adjust functions
  107. CMSAPI cmsUInt16Number CMSEXPORT _cmsAdjustEndianess16(cmsUInt16Number Word);
  108. CMSAPI cmsUInt32Number CMSEXPORT _cmsAdjustEndianess32(cmsUInt32Number Value);
  109. CMSAPI void CMSEXPORT _cmsAdjustEndianess64(cmsUInt64Number* Result, cmsUInt64Number* QWord);
  110. // Helper IO functions
  111. CMSAPI cmsBool CMSEXPORT _cmsReadUInt8Number(cmsIOHANDLER* io, cmsUInt8Number* n);
  112. CMSAPI cmsBool CMSEXPORT _cmsReadUInt16Number(cmsIOHANDLER* io, cmsUInt16Number* n);
  113. CMSAPI cmsBool CMSEXPORT _cmsReadUInt32Number(cmsIOHANDLER* io, cmsUInt32Number* n);
  114. CMSAPI cmsBool CMSEXPORT _cmsReadFloat32Number(cmsIOHANDLER* io, cmsFloat32Number* n);
  115. CMSAPI cmsBool CMSEXPORT _cmsReadUInt64Number(cmsIOHANDLER* io, cmsUInt64Number* n);
  116. CMSAPI cmsBool CMSEXPORT _cmsRead15Fixed16Number(cmsIOHANDLER* io, cmsFloat64Number* n);
  117. CMSAPI cmsBool CMSEXPORT _cmsReadXYZNumber(cmsIOHANDLER* io, cmsCIEXYZ* XYZ);
  118. CMSAPI cmsBool CMSEXPORT _cmsReadUInt16Array(cmsIOHANDLER* io, cmsUInt32Number n, cmsUInt16Number* Array);
  119. CMSAPI cmsBool CMSEXPORT _cmsWriteUInt8Number(cmsIOHANDLER* io, cmsUInt8Number n);
  120. CMSAPI cmsBool CMSEXPORT _cmsWriteUInt16Number(cmsIOHANDLER* io, cmsUInt16Number n);
  121. CMSAPI cmsBool CMSEXPORT _cmsWriteUInt32Number(cmsIOHANDLER* io, cmsUInt32Number n);
  122. CMSAPI cmsBool CMSEXPORT _cmsWriteFloat32Number(cmsIOHANDLER* io, cmsFloat32Number n);
  123. CMSAPI cmsBool CMSEXPORT _cmsWriteUInt64Number(cmsIOHANDLER* io, cmsUInt64Number* n);
  124. CMSAPI cmsBool CMSEXPORT _cmsWrite15Fixed16Number(cmsIOHANDLER* io, cmsFloat64Number n);
  125. CMSAPI cmsBool CMSEXPORT _cmsWriteXYZNumber(cmsIOHANDLER* io, const cmsCIEXYZ* XYZ);
  126. CMSAPI cmsBool CMSEXPORT _cmsWriteUInt16Array(cmsIOHANDLER* io, cmsUInt32Number n, const cmsUInt16Number* Array);
  127. // ICC base tag
  128. typedef struct {
  129. cmsTagTypeSignature sig;
  130. cmsInt8Number reserved[4];
  131. } _cmsTagBase;
  132. // Type base helper functions
  133. CMSAPI cmsTagTypeSignature CMSEXPORT _cmsReadTypeBase(cmsIOHANDLER* io);
  134. CMSAPI cmsBool CMSEXPORT _cmsWriteTypeBase(cmsIOHANDLER* io, cmsTagTypeSignature sig);
  135. // Alignment functions
  136. CMSAPI cmsBool CMSEXPORT _cmsReadAlignment(cmsIOHANDLER* io);
  137. CMSAPI cmsBool CMSEXPORT _cmsWriteAlignment(cmsIOHANDLER* io);
  138. // To deal with text streams. 2K at most
  139. CMSAPI cmsBool CMSEXPORT _cmsIOPrintf(cmsIOHANDLER* io, const char* frm, ...);
  140. // Fixed point helper functions
  141. CMSAPI cmsFloat64Number CMSEXPORT _cms8Fixed8toDouble(cmsUInt16Number fixed8);
  142. CMSAPI cmsUInt16Number CMSEXPORT _cmsDoubleTo8Fixed8(cmsFloat64Number val);
  143. CMSAPI cmsFloat64Number CMSEXPORT _cms15Fixed16toDouble(cmsS15Fixed16Number fix32);
  144. CMSAPI cmsS15Fixed16Number CMSEXPORT _cmsDoubleTo15Fixed16(cmsFloat64Number v);
  145. // Date/time helper functions
  146. CMSAPI void CMSEXPORT _cmsEncodeDateTimeNumber(cmsDateTimeNumber *Dest, const struct tm *Source);
  147. CMSAPI void CMSEXPORT _cmsDecodeDateTimeNumber(const cmsDateTimeNumber *Source, struct tm *Dest);
  148. //----------------------------------------------------------------------------------------------------------
  149. // Shared callbacks for user data
  150. typedef void (* _cmsFreeUserDataFn)(cmsContext ContextID, void* Data);
  151. typedef void* (* _cmsDupUserDataFn)(cmsContext ContextID, const void* Data);
  152. //----------------------------------------------------------------------------------------------------------
  153. // Plug-in foundation
  154. #define cmsPluginMagicNumber 0x61637070 // 'acpp'
  155. #define cmsPluginMemHandlerSig 0x6D656D48 // 'memH'
  156. #define cmsPluginInterpolationSig 0x696E7048 // 'inpH'
  157. #define cmsPluginParametricCurveSig 0x70617248 // 'parH'
  158. #define cmsPluginFormattersSig 0x66726D48 // 'frmH
  159. #define cmsPluginTagTypeSig 0x74797048 // 'typH'
  160. #define cmsPluginTagSig 0x74616748 // 'tagH'
  161. #define cmsPluginRenderingIntentSig 0x696E7448 // 'intH'
  162. #define cmsPluginMultiProcessElementSig 0x6D706548 // 'mpeH'
  163. #define cmsPluginOptimizationSig 0x6F707448 // 'optH'
  164. #define cmsPluginTransformSig 0x7A666D48 // 'xfmH'
  165. #define cmsPluginMutexSig 0x6D747A48 // 'mtxH'
  166. typedef struct _cmsPluginBaseStruct {
  167. cmsUInt32Number Magic; // 'acpp' signature
  168. cmsUInt32Number ExpectedVersion; // Expected version of LittleCMS
  169. cmsUInt32Number Type; // Type of plug-in
  170. struct _cmsPluginBaseStruct* Next; // For multiple plugin definition. NULL for end of list.
  171. } cmsPluginBase;
  172. // Maximum number of types in a plugin array
  173. #define MAX_TYPES_IN_LCMS_PLUGIN 20
  174. //----------------------------------------------------------------------------------------------------------
  175. // Memory handler. Each new plug-in type replaces current behaviour
  176. typedef void* (* _cmsMallocFnPtrType)(cmsContext ContextID, cmsUInt32Number size);
  177. typedef void (* _cmsFreeFnPtrType)(cmsContext ContextID, void *Ptr);
  178. typedef void* (* _cmsReallocFnPtrType)(cmsContext ContextID, void* Ptr, cmsUInt32Number NewSize);
  179. typedef void* (* _cmsMalloZerocFnPtrType)(cmsContext ContextID, cmsUInt32Number size);
  180. typedef void* (* _cmsCallocFnPtrType)(cmsContext ContextID, cmsUInt32Number num, cmsUInt32Number size);
  181. typedef void* (* _cmsDupFnPtrType)(cmsContext ContextID, const void* Org, cmsUInt32Number size);
  182. typedef struct {
  183. cmsPluginBase base;
  184. // Required
  185. _cmsMallocFnPtrType MallocPtr;
  186. _cmsFreeFnPtrType FreePtr;
  187. _cmsReallocFnPtrType ReallocPtr;
  188. // Optional
  189. _cmsMalloZerocFnPtrType MallocZeroPtr;
  190. _cmsCallocFnPtrType CallocPtr;
  191. _cmsDupFnPtrType DupPtr;
  192. } cmsPluginMemHandler;
  193. // ------------------------------------------------------------------------------------------------------------------
  194. // Interpolation. 16 bits and floating point versions.
  195. struct _cms_interp_struc;
  196. // Interpolation callbacks
  197. // 16 bits forward interpolation. This function performs precision-limited linear interpolation
  198. // and is supposed to be quite fast. Implementation may be tetrahedral or trilinear, and plug-ins may
  199. // choose to implement any other interpolation algorithm.
  200. typedef void (* _cmsInterpFn16)(register const cmsUInt16Number Input[],
  201. register cmsUInt16Number Output[],
  202. register const struct _cms_interp_struc* p);
  203. // Floating point forward interpolation. Full precision interpolation using floats. This is not a
  204. // time critical function. Implementation may be tetrahedral or trilinear, and plug-ins may
  205. // choose to implement any other interpolation algorithm.
  206. typedef void (* _cmsInterpFnFloat)(cmsFloat32Number const Input[],
  207. cmsFloat32Number Output[],
  208. const struct _cms_interp_struc* p);
  209. // This type holds a pointer to an interpolator that can be either 16 bits or float
  210. typedef union {
  211. _cmsInterpFn16 Lerp16; // Forward interpolation in 16 bits
  212. _cmsInterpFnFloat LerpFloat; // Forward interpolation in floating point
  213. } cmsInterpFunction;
  214. // Flags for interpolator selection
  215. #define CMS_LERP_FLAGS_16BITS 0x0000 // The default
  216. #define CMS_LERP_FLAGS_FLOAT 0x0001 // Requires different implementation
  217. #define CMS_LERP_FLAGS_TRILINEAR 0x0100 // Hint only
  218. #define MAX_INPUT_DIMENSIONS 8
  219. typedef struct _cms_interp_struc { // Used on all interpolations. Supplied by lcms2 when calling the interpolation function
  220. cmsContext ContextID; // The calling thread
  221. cmsUInt32Number dwFlags; // Keep original flags
  222. cmsUInt32Number nInputs; // != 1 only in 3D interpolation
  223. cmsUInt32Number nOutputs; // != 1 only in 3D interpolation
  224. cmsUInt32Number nSamples[MAX_INPUT_DIMENSIONS]; // Valid on all kinds of tables
  225. cmsUInt32Number Domain[MAX_INPUT_DIMENSIONS]; // Domain = nSamples - 1
  226. cmsUInt32Number opta[MAX_INPUT_DIMENSIONS]; // Optimization for 3D CLUT. This is the number of nodes premultiplied for each
  227. // dimension. For example, in 7 nodes, 7, 7^2 , 7^3, 7^4, etc. On non-regular
  228. // Samplings may vary according of the number of nodes for each dimension.
  229. const void *Table; // Points to the actual interpolation table
  230. cmsInterpFunction Interpolation; // Points to the function to do the interpolation
  231. } cmsInterpParams;
  232. // Interpolators factory
  233. typedef cmsInterpFunction (* cmsInterpFnFactory)(cmsUInt32Number nInputChannels, cmsUInt32Number nOutputChannels, cmsUInt32Number dwFlags);
  234. // The plug-in
  235. typedef struct {
  236. cmsPluginBase base;
  237. // Points to a user-supplied function which implements the factory
  238. cmsInterpFnFactory InterpolatorsFactory;
  239. } cmsPluginInterpolation;
  240. //----------------------------------------------------------------------------------------------------------
  241. // Parametric curves. A negative type means same function but analytically inverted. Max. number of params is 10
  242. // Evaluator callback for user-supplied parametric curves. May implement more than one type
  243. typedef cmsFloat64Number (* cmsParametricCurveEvaluator)(cmsInt32Number Type, const cmsFloat64Number Params[10], cmsFloat64Number R);
  244. // Plug-in may implement an arbitrary number of parametric curves
  245. typedef struct {
  246. cmsPluginBase base;
  247. cmsUInt32Number nFunctions; // Number of supported functions
  248. cmsUInt32Number FunctionTypes[MAX_TYPES_IN_LCMS_PLUGIN]; // The identification types
  249. cmsUInt32Number ParameterCount[MAX_TYPES_IN_LCMS_PLUGIN]; // Number of parameters for each function
  250. cmsParametricCurveEvaluator Evaluator; // The evaluator
  251. } cmsPluginParametricCurves;
  252. //----------------------------------------------------------------------------------------------------------
  253. // Formatters. This plug-in adds new handlers, replacing them if they already exist. Formatters dealing with
  254. // cmsFloat32Number (bps = 4) or double (bps = 0) types are requested via FormatterFloat callback. Others come across
  255. // Formatter16 callback
  256. struct _cmstransform_struct;
  257. typedef cmsUInt8Number* (* cmsFormatter16)(register struct _cmstransform_struct* CMMcargo,
  258. register cmsUInt16Number Values[],
  259. register cmsUInt8Number* Buffer,
  260. register cmsUInt32Number Stride);
  261. typedef cmsUInt8Number* (* cmsFormatterFloat)(struct _cmstransform_struct* CMMcargo,
  262. cmsFloat32Number Values[],
  263. cmsUInt8Number* Buffer,
  264. cmsUInt32Number Stride);
  265. // This type holds a pointer to a formatter that can be either 16 bits or cmsFloat32Number
  266. typedef union {
  267. cmsFormatter16 Fmt16;
  268. cmsFormatterFloat FmtFloat;
  269. } cmsFormatter;
  270. #define CMS_PACK_FLAGS_16BITS 0x0000
  271. #define CMS_PACK_FLAGS_FLOAT 0x0001
  272. typedef enum { cmsFormatterInput=0, cmsFormatterOutput=1 } cmsFormatterDirection;
  273. typedef cmsFormatter (* cmsFormatterFactory)(cmsUInt32Number Type, // Specific type, i.e. TYPE_RGB_8
  274. cmsFormatterDirection Dir,
  275. cmsUInt32Number dwFlags); // precision
  276. // Plug-in may implement an arbitrary number of formatters
  277. typedef struct {
  278. cmsPluginBase base;
  279. cmsFormatterFactory FormattersFactory;
  280. } cmsPluginFormatters;
  281. //----------------------------------------------------------------------------------------------------------
  282. // Tag type handler. Each type is free to return anything it wants, and it is up to the caller to
  283. // know in advance what is the type contained in the tag.
  284. typedef struct _cms_typehandler_struct {
  285. cmsTagTypeSignature Signature; // The signature of the type
  286. // Allocates and reads items
  287. void * (* ReadPtr)(struct _cms_typehandler_struct* self,
  288. cmsIOHANDLER* io,
  289. cmsUInt32Number* nItems,
  290. cmsUInt32Number SizeOfTag);
  291. // Writes n Items
  292. cmsBool (* WritePtr)(struct _cms_typehandler_struct* self,
  293. cmsIOHANDLER* io,
  294. void* Ptr,
  295. cmsUInt32Number nItems);
  296. // Duplicate an item or array of items
  297. void* (* DupPtr)(struct _cms_typehandler_struct* self,
  298. const void *Ptr,
  299. cmsUInt32Number n);
  300. // Free all resources
  301. void (* FreePtr)(struct _cms_typehandler_struct* self,
  302. void *Ptr);
  303. // Additional parameters used by the calling thread
  304. cmsContext ContextID;
  305. cmsUInt32Number ICCVersion;
  306. } cmsTagTypeHandler;
  307. // Each plug-in implements a single type
  308. typedef struct {
  309. cmsPluginBase base;
  310. cmsTagTypeHandler Handler;
  311. } cmsPluginTagType;
  312. //----------------------------------------------------------------------------------------------------------
  313. // This is the tag plugin, which identifies tags. For writing, a pointer to function is provided.
  314. // This function should return the desired type for this tag, given the version of profile
  315. // and the data being serialized.
  316. typedef struct {
  317. cmsUInt32Number ElemCount; // If this tag needs an array, how many elements should keep
  318. // For reading.
  319. cmsUInt32Number nSupportedTypes; // In how many types this tag can come (MAX_TYPES_IN_LCMS_PLUGIN maximum)
  320. cmsTagTypeSignature SupportedTypes[MAX_TYPES_IN_LCMS_PLUGIN];
  321. // For writing
  322. cmsTagTypeSignature (* DecideType)(cmsFloat64Number ICCVersion, const void *Data);
  323. } cmsTagDescriptor;
  324. // Plug-in implements a single tag
  325. typedef struct {
  326. cmsPluginBase base;
  327. cmsTagSignature Signature;
  328. cmsTagDescriptor Descriptor;
  329. } cmsPluginTag;
  330. //----------------------------------------------------------------------------------------------------------
  331. // Custom intents. This function should join all profiles specified in the array in
  332. // a single LUT. Any custom intent in the chain redirects to custom function. If more than
  333. // one custom intent is found, the one located first is invoked. Usually users should use only one
  334. // custom intent, so mixing custom intents in same multiprofile transform is not supported.
  335. typedef cmsPipeline* (* cmsIntentFn)( cmsContext ContextID,
  336. cmsUInt32Number nProfiles,
  337. cmsUInt32Number Intents[],
  338. cmsHPROFILE hProfiles[],
  339. cmsBool BPC[],
  340. cmsFloat64Number AdaptationStates[],
  341. cmsUInt32Number dwFlags);
  342. // Each plug-in defines a single intent number.
  343. typedef struct {
  344. cmsPluginBase base;
  345. cmsUInt32Number Intent;
  346. cmsIntentFn Link;
  347. char Description[256];
  348. } cmsPluginRenderingIntent;
  349. // The default ICC intents (perceptual, saturation, rel.col and abs.col)
  350. CMSAPI cmsPipeline* CMSEXPORT _cmsDefaultICCintents(cmsContext ContextID,
  351. cmsUInt32Number nProfiles,
  352. cmsUInt32Number Intents[],
  353. cmsHPROFILE hProfiles[],
  354. cmsBool BPC[],
  355. cmsFloat64Number AdaptationStates[],
  356. cmsUInt32Number dwFlags);
  357. //----------------------------------------------------------------------------------------------------------
  358. // Pipelines, Multi Process Elements.
  359. typedef void (* _cmsStageEvalFn) (const cmsFloat32Number In[], cmsFloat32Number Out[], const cmsStage* mpe);
  360. typedef void*(* _cmsStageDupElemFn) (cmsStage* mpe);
  361. typedef void (* _cmsStageFreeElemFn) (cmsStage* mpe);
  362. // This function allocates a generic MPE
  363. CMSAPI cmsStage* CMSEXPORT _cmsStageAllocPlaceholder(cmsContext ContextID,
  364. cmsStageSignature Type,
  365. cmsUInt32Number InputChannels,
  366. cmsUInt32Number OutputChannels,
  367. _cmsStageEvalFn EvalPtr, // Points to fn that evaluates the element (always in floating point)
  368. _cmsStageDupElemFn DupElemPtr, // Points to a fn that duplicates the stage
  369. _cmsStageFreeElemFn FreePtr, // Points to a fn that sets the element free
  370. void* Data); // A generic pointer to whatever memory needed by the element
  371. typedef struct {
  372. cmsPluginBase base;
  373. cmsTagTypeHandler Handler;
  374. } cmsPluginMultiProcessElement;
  375. // Data kept in "Element" member of cmsStage
  376. // Curves
  377. typedef struct {
  378. cmsUInt32Number nCurves;
  379. cmsToneCurve** TheCurves;
  380. } _cmsStageToneCurvesData;
  381. // Matrix
  382. typedef struct {
  383. cmsFloat64Number* Double; // floating point for the matrix
  384. cmsFloat64Number* Offset; // The offset
  385. } _cmsStageMatrixData;
  386. // CLUT
  387. typedef struct {
  388. union { // Can have only one of both representations at same time
  389. cmsUInt16Number* T; // Points to the table 16 bits table
  390. cmsFloat32Number* TFloat; // Points to the cmsFloat32Number table
  391. } Tab;
  392. cmsInterpParams* Params;
  393. cmsUInt32Number nEntries;
  394. cmsBool HasFloatValues;
  395. } _cmsStageCLutData;
  396. //----------------------------------------------------------------------------------------------------------
  397. // Optimization. Using this plug-in, additional optimization strategies may be implemented.
  398. // The function should return TRUE if any optimization is done on the LUT, this terminates
  399. // the optimization search. Or FALSE if it is unable to optimize and want to give a chance
  400. // to the rest of optimizers.
  401. typedef void (* _cmsOPTeval16Fn)(register const cmsUInt16Number In[],
  402. register cmsUInt16Number Out[],
  403. register const void* Data);
  404. typedef cmsBool (* _cmsOPToptimizeFn)(cmsPipeline** Lut,
  405. cmsUInt32Number Intent,
  406. cmsUInt32Number* InputFormat,
  407. cmsUInt32Number* OutputFormat,
  408. cmsUInt32Number* dwFlags);
  409. // This function may be used to set the optional evaluator and a block of private data. If private data is being used, an optional
  410. // duplicator and free functions should also be specified in order to duplicate the LUT construct. Use NULL to inhibit such functionality.
  411. CMSAPI void CMSEXPORT _cmsPipelineSetOptimizationParameters(cmsPipeline* Lut,
  412. _cmsOPTeval16Fn Eval16,
  413. void* PrivateData,
  414. _cmsFreeUserDataFn FreePrivateDataFn,
  415. _cmsDupUserDataFn DupPrivateDataFn);
  416. typedef struct {
  417. cmsPluginBase base;
  418. // Optimize entry point
  419. _cmsOPToptimizeFn OptimizePtr;
  420. } cmsPluginOptimization;
  421. //----------------------------------------------------------------------------------------------------------
  422. // Full xform
  423. typedef struct {
  424. cmsUInt32Number BytesPerLineIn;
  425. cmsUInt32Number BytesPerLineOut;
  426. cmsUInt32Number BytesPerPlaneIn;
  427. cmsUInt32Number BytesPerPlaneOut;
  428. } cmsStride;
  429. typedef void (* _cmsTransformFn)(struct _cmstransform_struct *CMMcargo, // Legacy function, handles just ONE scanline.
  430. const void* InputBuffer,
  431. void* OutputBuffer,
  432. cmsUInt32Number Size,
  433. cmsUInt32Number Stride); // Stride in bytes to the next plana in planar formats
  434. typedef void (*_cmsTransform2Fn)(struct _cmstransform_struct *CMMcargo,
  435. const void* InputBuffer,
  436. void* OutputBuffer,
  437. cmsUInt32Number PixelsPerLine,
  438. cmsUInt32Number LineCount,
  439. const cmsStride* Stride);
  440. typedef cmsBool (* _cmsTransformFactory)(_cmsTransformFn* xform,
  441. void** UserData,
  442. _cmsFreeUserDataFn* FreePrivateDataFn,
  443. cmsPipeline** Lut,
  444. cmsUInt32Number* InputFormat,
  445. cmsUInt32Number* OutputFormat,
  446. cmsUInt32Number* dwFlags);
  447. typedef cmsBool (* _cmsTransform2Factory)(_cmsTransform2Fn* xform,
  448. void** UserData,
  449. _cmsFreeUserDataFn* FreePrivateDataFn,
  450. cmsPipeline** Lut,
  451. cmsUInt32Number* InputFormat,
  452. cmsUInt32Number* OutputFormat,
  453. cmsUInt32Number* dwFlags);
  454. // Retrieve user data as specified by the factory
  455. CMSAPI void CMSEXPORT _cmsSetTransformUserData(struct _cmstransform_struct *CMMcargo, void* ptr, _cmsFreeUserDataFn FreePrivateDataFn);
  456. CMSAPI void * CMSEXPORT _cmsGetTransformUserData(struct _cmstransform_struct *CMMcargo);
  457. // Retrieve formatters
  458. CMSAPI void CMSEXPORT _cmsGetTransformFormatters16 (struct _cmstransform_struct *CMMcargo, cmsFormatter16* FromInput, cmsFormatter16* ToOutput);
  459. CMSAPI void CMSEXPORT _cmsGetTransformFormattersFloat(struct _cmstransform_struct *CMMcargo, cmsFormatterFloat* FromInput, cmsFormatterFloat* ToOutput);
  460. typedef struct {
  461. cmsPluginBase base;
  462. // Transform entry point
  463. union {
  464. _cmsTransformFactory legacy_xform;
  465. _cmsTransform2Factory xform;
  466. } factories;
  467. } cmsPluginTransform;
  468. //----------------------------------------------------------------------------------------------------------
  469. // Mutex
  470. typedef void* (* _cmsCreateMutexFnPtrType)(cmsContext ContextID);
  471. typedef void (* _cmsDestroyMutexFnPtrType)(cmsContext ContextID, void* mtx);
  472. typedef cmsBool (* _cmsLockMutexFnPtrType)(cmsContext ContextID, void* mtx);
  473. typedef void (* _cmsUnlockMutexFnPtrType)(cmsContext ContextID, void* mtx);
  474. typedef struct {
  475. cmsPluginBase base;
  476. _cmsCreateMutexFnPtrType CreateMutexPtr;
  477. _cmsDestroyMutexFnPtrType DestroyMutexPtr;
  478. _cmsLockMutexFnPtrType LockMutexPtr;
  479. _cmsUnlockMutexFnPtrType UnlockMutexPtr;
  480. } cmsPluginMutex;
  481. CMSAPI void* CMSEXPORT _cmsCreateMutex(cmsContext ContextID);
  482. CMSAPI void CMSEXPORT _cmsDestroyMutex(cmsContext ContextID, void* mtx);
  483. CMSAPI cmsBool CMSEXPORT _cmsLockMutex(cmsContext ContextID, void* mtx);
  484. CMSAPI void CMSEXPORT _cmsUnlockMutex(cmsContext ContextID, void* mtx);
  485. #ifndef CMS_USE_CPP_API
  486. # ifdef __cplusplus
  487. }
  488. # endif
  489. #endif
  490. #define _lcms_plugin_H
  491. #endif