//--------------------------------------------------------------------------------- // // Little Color Management System // Copyright (c) 1998-2023 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the Software // is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // //--------------------------------------------------------------------------------- // #include "lcms2_internal.h" // ---------------------------------------------------------------------------------- // Encoding & Decoding support functions // ---------------------------------------------------------------------------------- // Little-Endian to Big-Endian // Adjust a word value after being read/ before being written from/to an ICC profile cmsUInt16Number CMSEXPORT _cmsAdjustEndianess16(cmsUInt16Number Word) { … } // Transports to properly encoded values - note that icc profiles does use big endian notation. // 1 2 3 4 // 4 3 2 1 cmsUInt32Number CMSEXPORT _cmsAdjustEndianess32(cmsUInt32Number DWord) { … } // 1 2 3 4 5 6 7 8 // 8 7 6 5 4 3 2 1 void CMSEXPORT _cmsAdjustEndianess64(cmsUInt64Number* Result, cmsUInt64Number* QWord) { … } // Auxiliary -- read 8, 16 and 32-bit numbers cmsBool CMSEXPORT _cmsReadUInt8Number(cmsIOHANDLER* io, cmsUInt8Number* n) { … } cmsBool CMSEXPORT _cmsReadUInt16Number(cmsIOHANDLER* io, cmsUInt16Number* n) { … } cmsBool CMSEXPORT _cmsReadUInt16Array(cmsIOHANDLER* io, cmsUInt32Number n, cmsUInt16Number* Array) { … } cmsBool CMSEXPORT _cmsReadUInt32Number(cmsIOHANDLER* io, cmsUInt32Number* n) { … } cmsBool CMSEXPORT _cmsReadFloat32Number(cmsIOHANDLER* io, cmsFloat32Number* n) { … } cmsBool CMSEXPORT _cmsReadUInt64Number(cmsIOHANDLER* io, cmsUInt64Number* n) { … } cmsBool CMSEXPORT _cmsRead15Fixed16Number(cmsIOHANDLER* io, cmsFloat64Number* n) { … } cmsBool CMSEXPORT _cmsReadXYZNumber(cmsIOHANDLER* io, cmsCIEXYZ* XYZ) { … } cmsBool CMSEXPORT _cmsWriteUInt8Number(cmsIOHANDLER* io, cmsUInt8Number n) { … } cmsBool CMSEXPORT _cmsWriteUInt16Number(cmsIOHANDLER* io, cmsUInt16Number n) { … } cmsBool CMSEXPORT _cmsWriteUInt16Array(cmsIOHANDLER* io, cmsUInt32Number n, const cmsUInt16Number* Array) { … } cmsBool CMSEXPORT _cmsWriteUInt32Number(cmsIOHANDLER* io, cmsUInt32Number n) { … } cmsBool CMSEXPORT _cmsWriteFloat32Number(cmsIOHANDLER* io, cmsFloat32Number n) { … } cmsBool CMSEXPORT _cmsWriteUInt64Number(cmsIOHANDLER* io, cmsUInt64Number* n) { … } cmsBool CMSEXPORT _cmsWrite15Fixed16Number(cmsIOHANDLER* io, cmsFloat64Number n) { … } cmsBool CMSEXPORT _cmsWriteXYZNumber(cmsIOHANDLER* io, const cmsCIEXYZ* XYZ) { … } // from Fixed point 8.8 to double cmsFloat64Number CMSEXPORT _cms8Fixed8toDouble(cmsUInt16Number fixed8) { … } cmsUInt16Number CMSEXPORT _cmsDoubleTo8Fixed8(cmsFloat64Number val) { … } // from Fixed point 15.16 to double cmsFloat64Number CMSEXPORT _cms15Fixed16toDouble(cmsS15Fixed16Number fix32) { … } // from double to Fixed point 15.16 cmsS15Fixed16Number CMSEXPORT _cmsDoubleTo15Fixed16(cmsFloat64Number v) { … } // Date/Time functions void CMSEXPORT _cmsDecodeDateTimeNumber(const cmsDateTimeNumber *Source, struct tm *Dest) { … } void CMSEXPORT _cmsEncodeDateTimeNumber(cmsDateTimeNumber *Dest, const struct tm *Source) { … } // Read base and return type base cmsTagTypeSignature CMSEXPORT _cmsReadTypeBase(cmsIOHANDLER* io) { … } // Setup base marker cmsBool CMSEXPORT _cmsWriteTypeBase(cmsIOHANDLER* io, cmsTagTypeSignature sig) { … } cmsBool CMSEXPORT _cmsReadAlignment(cmsIOHANDLER* io) { … } cmsBool CMSEXPORT _cmsWriteAlignment(cmsIOHANDLER* io) { … } // To deal with text streams. 2K at most cmsBool CMSEXPORT _cmsIOPrintf(cmsIOHANDLER* io, const char* frm, ...) { … } // Plugin memory management ------------------------------------------------------------------------------------------------- // Specialized malloc for plug-ins, that is freed upon exit. void* _cmsPluginMalloc(cmsContext ContextID, cmsUInt32Number size) { … } // Main plug-in dispatcher cmsBool CMSEXPORT cmsPlugin(void* Plug_in) { … } cmsBool CMSEXPORT cmsPluginTHR(cmsContext id, void* Plug_in) { … } // Revert all plug-ins to default void CMSEXPORT cmsUnregisterPlugins(void) { … } // The Global storage for system context. This is the one and only global variable // pointers structure. All global vars are referenced here. static struct _cmsContext_struct globalContext = …; // The context pool (linked list head) static _cmsMutex _cmsContextPoolHeadMutex = …; static struct _cmsContext_struct* _cmsContextPoolHead = …; // Make sure context is initialized (needed on windows) static cmsBool InitContextMutex(void) { … } // Internal, get associated pointer, with guessing. Never returns NULL. struct _cmsContext_struct* _cmsGetContext(cmsContext ContextID) { … } // Internal: get the memory area associanted with each context client // Returns the block assigned to the specific zone. Never return NULL. void* _cmsContextGetClientChunk(cmsContext ContextID, _cmsMemoryClient mc) { … } // This function returns the given context its default pristine state, // as no plug-ins were declared. There is no way to unregister a single // plug-in, as a single call to cmsPluginTHR() function may register // many different plug-ins simultaneously, then there is no way to // identify which plug-in to unregister. void CMSEXPORT cmsUnregisterPluginsTHR(cmsContext ContextID) { … } // Returns the memory manager plug-in, if any, from the Plug-in bundle static cmsPluginMemHandler* _cmsFindMemoryPlugin(void* PluginBundle) { … } // Creates a new context with optional associated plug-ins. Caller may also specify an optional pointer to user-defined // data that will be forwarded to plug-ins and logger. cmsContext CMSEXPORT cmsCreateContext(void* Plugin, void* UserData) { … } // Duplicates a context with all associated plug-ins. // Caller may specify an optional pointer to user-defined // data that will be forwarded to plug-ins and logger. cmsContext CMSEXPORT cmsDupContext(cmsContext ContextID, void* NewUserData) { … } // Frees any resources associated with the given context, // and destroys the context placeholder. // The ContextID can no longer be used in any THR operation. void CMSEXPORT cmsDeleteContext(cmsContext ContextID) { … } // Returns the user data associated to the given ContextID, or NULL if no user data was attached on context creation void* CMSEXPORT cmsGetContextUserData(cmsContext ContextID) { … } // Use context mutex to provide thread-safe time cmsBool _cmsGetTime(struct tm* ptr_time) { … }