/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
// This file is available under and governed by the GNU General Public // License version 2 only, as published by the Free Software Foundation. // However, the following notice accompanied the original version of this // file: // //--------------------------------------------------------------------------------- // // Little Color Management System // Copyright (c) 1998-2022 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)
{ #ifndef CMS_USE_BIG_ENDIAN
// from Fixed point 15.16 to double
cmsFloat64Number CMSEXPORT _cms15Fixed16toDouble(cmsS15Fixed16Number fix32)
{
cmsFloat64Number floater, sign, mid; int Whole, FracPart;
// To deal with text streams. 2K at most
cmsBool CMSEXPORT _cmsIOPrintf(cmsIOHANDLER* io, constchar* frm, ...)
{
va_list args; int len;
cmsUInt8Number Buffer[2048];
cmsBool rc;
cmsUInt8Number* ptr;
_cmsAssert(io != NULL);
_cmsAssert(frm != NULL);
va_start(args, frm);
len = vsnprintf((char*) Buffer, 2047, frm, args); if (len < 0) {
va_end(args); returnFALSE; // Truncated, which is a fatal error for us
}
// setlocale may be active, no commas are needed in PS generator // and PS generator is our only client for (ptr = Buffer; *ptr; ptr++)
{ if (*ptr == ',') *ptr = '.';
}
if (Plugin ->ExpectedVersion > LCMS_VERSION) {
cmsSignalError(id, cmsERROR_UNKNOWN_EXTENSION, "plugin needs Little CMS %d, current version is %d",
Plugin ->ExpectedVersion, LCMS_VERSION); returnFALSE;
}
switch (Plugin -> Type) {
case cmsPluginMemHandlerSig: if (!_cmsRegisterMemHandlerPlugin(id, Plugin)) returnFALSE; break;
case cmsPluginInterpolationSig: if (!_cmsRegisterInterpPlugin(id, Plugin)) returnFALSE; break;
case cmsPluginTagTypeSig: if (!_cmsRegisterTagTypePlugin(id, Plugin)) returnFALSE; break;
case cmsPluginTagSig: if (!_cmsRegisterTagPlugin(id, Plugin)) returnFALSE; break;
case cmsPluginFormattersSig: if (!_cmsRegisterFormattersPlugin(id, Plugin)) returnFALSE; break;
case cmsPluginRenderingIntentSig: if (!_cmsRegisterRenderingIntentPlugin(id, Plugin)) returnFALSE; break;
case cmsPluginParametricCurveSig: if (!_cmsRegisterParametricCurvesPlugin(id, Plugin)) returnFALSE; break;
case cmsPluginMultiProcessElementSig: if (!_cmsRegisterMultiProcessElementPlugin(id, Plugin)) returnFALSE; break;
case cmsPluginOptimizationSig: if (!_cmsRegisterOptimizationPlugin(id, Plugin)) returnFALSE; break;
case cmsPluginTransformSig: if (!_cmsRegisterTransformPlugin(id, Plugin)) returnFALSE; break;
case cmsPluginMutexSig: if (!_cmsRegisterMutexPlugin(id, Plugin)) returnFALSE; break;
case cmsPluginParalellizationSig: if (!_cmsRegisterParallelizationPlugin(id, Plugin)) returnFALSE; break;
// Revert all plug-ins to default void CMSEXPORT cmsUnregisterPlugins(void)
{
cmsUnregisterPluginsTHR(NULL);
}
// The Global storage for system context. This is the one and only global variable // pointers structure. All global vars are referenced here. staticstruct _cmsContext_struct globalContext = {
{ NULL, NULL, NULL, NULL, NULL, NULL } // The default memory allocator is not used for context 0
};
// The context pool (linked list head) static _cmsMutex _cmsContextPoolHeadMutex = CMS_MUTEX_INITIALIZER; staticstruct _cmsContext_struct* _cmsContextPoolHead = NULL;
// Make sure context is initialized (needed on windows) static
cmsBool InitContextMutex(void)
{ // See the comments regarding locking in lcms2_internal.h // for an explanation of why we need the following code. #ifndef CMS_NO_PTHREADS #ifdef CMS_IS_WINDOWS_ #ifndef CMS_RELY_ON_WINDOWS_STATIC_MUTEX_INIT
// 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)
{ struct _cmsContext_struct* ctx; void *ptr;
if ((int) mc < 0 || mc >= MemoryClientMax) {
cmsSignalError(ContextID, cmsERROR_INTERNAL, "Bad context client -- possible corruption");
// This is catastrophic. Should never reach here
_cmsAssert(0);
// Reverts to global context return globalContext.chunks[UserPtr];
}
// A null ptr means no special settings for that context, and this // reverts to Context0 globals return globalContext.chunks[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)
{ struct _cmsContext_struct* ctx = _cmsGetContext(ContextID);
if (ctx->MemPool != NULL)
_cmsSubAllocDestroy(ctx->MemPool);
ctx->MemPool = NULL;
}
// Returns the memory manager plug-in, if any, from the Plug-in bundle static
cmsPluginMemHandler* _cmsFindMemoryPlugin(void* PluginBundle)
{
cmsPluginBase* Plugin;
// 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)
{ struct _cmsContext_struct* ctx; struct _cmsContext_struct fakeContext;
// Now we can allocate the pool by using default memory manager
ctx ->MemPool = _cmsCreateSubAlloc(ctx, 22 * sizeof(void*)); // default size about 22 pointers if (ctx ->MemPool == NULL) {
// Setup the plug-ins if (!cmsPluginTHR(ctx, Plugin)) {
cmsDeleteContext(ctx); return NULL;
}
return (cmsContext) ctx;
}
// 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)
{ int i; struct _cmsContext_struct* ctx; conststruct _cmsContext_struct* src = _cmsGetContext(ContextID);
// 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)
{ if (ContextID != NULL) {
// Get rid of plugins
cmsUnregisterPluginsTHR(ContextID);
// Since all memory is allocated in the private pool, all what we need to do is destroy the pool if (ctx -> MemPool != NULL)
_cmsSubAllocDestroy(ctx ->MemPool);
ctx -> MemPool = NULL;
// Maintain list
_cmsEnterCriticalSectionPrimitive(&_cmsContextPoolHeadMutex); if (_cmsContextPoolHead == ctx) {
_cmsContextPoolHead = ctx->Next;
} else {
// Search for previous for (prev = _cmsContextPoolHead;
prev != NULL;
prev = prev ->Next)
{ if (prev -> Next == ctx) {
prev -> Next = ctx ->Next; break;
}
}
}
_cmsLeaveCriticalSectionPrimitive(&_cmsContextPoolHeadMutex);
// free the memory block itself
_cmsFree(&fakeContext, ctx);
}
}
// 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)
{ return _cmsContextGetClientChunk(ContextID, UserPtr);
}
// Use context mutex to provide thread-safe time
cmsBool _cmsGetTime(struct tm* ptr_time)
{ struct tm* t; #ifdefined(HAVE_GMTIME_R) || defined(HAVE_GMTIME_S) struct tm tm; #endif
time_t now = time(NULL);
#ifdef HAVE_GMTIME_R
t = gmtime_r(&now, &tm); #elifdefined(HAVE_GMTIME_S)
t = gmtime_s(&tm, &now) == 0 ? &tm : NULL; #else if (!InitContextMutex()) returnFALSE;
_cmsEnterCriticalSectionPrimitive(&_cmsContextPoolHeadMutex);
t = gmtime(&now);
_cmsLeaveCriticalSectionPrimitive(&_cmsContextPoolHeadMutex); #endif
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.