2004-10-07 21:12:41 +02:00
|
|
|
/*
|
|
|
|
* MSCMS - Color Management System for Wine
|
|
|
|
*
|
2008-03-24 21:33:06 +01:00
|
|
|
* Copyright 2004, 2005, 2008 Hans Leidekker
|
2004-10-07 21:12:41 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-10-07 21:12:41 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2008-03-24 21:33:06 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2004-10-07 21:12:41 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
2004-10-22 21:56:51 +02:00
|
|
|
#include "winuser.h"
|
2004-10-07 21:12:41 +02:00
|
|
|
#include "icm.h"
|
|
|
|
|
|
|
|
#include "mscms_priv.h"
|
|
|
|
|
2005-07-18 17:10:36 +02:00
|
|
|
#ifdef HAVE_LCMS
|
2004-10-07 21:12:41 +02:00
|
|
|
|
|
|
|
static CRITICAL_SECTION MSCMS_handle_cs;
|
|
|
|
static CRITICAL_SECTION_DEBUG MSCMS_handle_cs_debug =
|
|
|
|
{
|
|
|
|
0, 0, &MSCMS_handle_cs,
|
|
|
|
{ &MSCMS_handle_cs_debug.ProcessLocksList,
|
|
|
|
&MSCMS_handle_cs_debug.ProcessLocksList },
|
2005-09-09 12:19:44 +02:00
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": MSCMS_handle_cs") }
|
2004-10-07 21:12:41 +02:00
|
|
|
};
|
|
|
|
static CRITICAL_SECTION MSCMS_handle_cs = { &MSCMS_handle_cs_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
static struct profile *profiletable;
|
|
|
|
static struct transform *transformtable;
|
2004-10-07 21:12:41 +02:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
static unsigned int num_profile_handles;
|
|
|
|
static unsigned int num_transform_handles;
|
2004-10-07 21:12:41 +02:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mscms);
|
2005-02-21 19:38:15 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
void free_handle_tables( void )
|
2004-11-30 22:06:14 +01:00
|
|
|
{
|
2008-03-24 21:33:06 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, profiletable );
|
|
|
|
profiletable = NULL;
|
|
|
|
num_profile_handles = 0;
|
2004-11-30 22:06:14 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, transformtable );
|
|
|
|
transformtable = NULL;
|
|
|
|
num_transform_handles = 0;
|
2011-11-16 16:33:11 +01:00
|
|
|
|
|
|
|
DeleteCriticalSection( &MSCMS_handle_cs );
|
2004-11-30 22:06:14 +01:00
|
|
|
}
|
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
struct profile *grab_profile( HPROFILE handle )
|
2004-11-30 22:06:14 +01:00
|
|
|
{
|
2008-03-24 21:33:06 +01:00
|
|
|
DWORD_PTR index;
|
2004-11-30 22:06:14 +01:00
|
|
|
|
|
|
|
EnterCriticalSection( &MSCMS_handle_cs );
|
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
index = (DWORD_PTR)handle - 1;
|
|
|
|
if (index > num_profile_handles)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &MSCMS_handle_cs );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return &profiletable[index];
|
2004-11-30 22:06:14 +01:00
|
|
|
}
|
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
void release_profile( struct profile *profile )
|
2005-02-14 21:53:59 +01:00
|
|
|
{
|
|
|
|
LeaveCriticalSection( &MSCMS_handle_cs );
|
|
|
|
}
|
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
struct transform *grab_transform( HTRANSFORM handle )
|
2004-10-07 21:12:41 +02:00
|
|
|
{
|
2008-03-24 21:33:06 +01:00
|
|
|
DWORD_PTR index;
|
2004-10-07 21:12:41 +02:00
|
|
|
|
|
|
|
EnterCriticalSection( &MSCMS_handle_cs );
|
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
index = (DWORD_PTR)handle - 1;
|
|
|
|
if (index > num_transform_handles)
|
2004-10-07 21:12:41 +02:00
|
|
|
{
|
2008-03-24 21:33:06 +01:00
|
|
|
LeaveCriticalSection( &MSCMS_handle_cs );
|
|
|
|
return NULL;
|
2004-10-07 21:12:41 +02:00
|
|
|
}
|
2008-03-24 21:33:06 +01:00
|
|
|
return &transformtable[index];
|
2004-10-07 21:12:41 +02:00
|
|
|
}
|
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
void release_transform( struct transform *transform )
|
2004-10-07 21:12:41 +02:00
|
|
|
{
|
|
|
|
LeaveCriticalSection( &MSCMS_handle_cs );
|
|
|
|
}
|
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
static HPROFILE alloc_profile_handle( void )
|
2004-11-30 22:06:14 +01:00
|
|
|
{
|
2008-03-24 21:33:06 +01:00
|
|
|
DWORD_PTR index;
|
|
|
|
struct profile *p;
|
|
|
|
unsigned int count = 128;
|
2004-11-30 22:06:14 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
for (index = 0; index < num_profile_handles; index++)
|
2004-11-30 22:06:14 +01:00
|
|
|
{
|
2008-03-24 21:33:06 +01:00
|
|
|
if (!profiletable[index].iccprofile) return (HPROFILE)(index + 1);
|
2004-11-30 22:06:14 +01:00
|
|
|
}
|
2008-03-24 21:33:06 +01:00
|
|
|
if (!profiletable)
|
|
|
|
{
|
|
|
|
p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, count * sizeof(struct profile) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
count = num_profile_handles * 2;
|
|
|
|
p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, profiletable, count * sizeof(struct profile) );
|
|
|
|
}
|
|
|
|
if (!p) return NULL;
|
2004-11-30 22:06:14 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
profiletable = p;
|
|
|
|
num_profile_handles = count;
|
|
|
|
|
|
|
|
return (HPROFILE)(index + 1);
|
2004-11-30 22:06:14 +01:00
|
|
|
}
|
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
HPROFILE create_profile( struct profile *profile )
|
2004-10-07 21:12:41 +02:00
|
|
|
{
|
2008-03-24 21:33:06 +01:00
|
|
|
HPROFILE handle;
|
2004-10-07 21:12:41 +02:00
|
|
|
|
|
|
|
EnterCriticalSection( &MSCMS_handle_cs );
|
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
if ((handle = alloc_profile_handle()))
|
|
|
|
{
|
|
|
|
DWORD_PTR index = (DWORD_PTR)handle - 1;
|
2013-01-24 15:18:09 +01:00
|
|
|
profiletable[index] = *profile;
|
2008-03-24 21:33:06 +01:00
|
|
|
}
|
2004-10-07 21:12:41 +02:00
|
|
|
LeaveCriticalSection( &MSCMS_handle_cs );
|
2008-03-24 21:33:06 +01:00
|
|
|
return handle;
|
2004-10-07 21:12:41 +02:00
|
|
|
}
|
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
BOOL close_profile( HPROFILE handle )
|
2004-10-07 21:12:41 +02:00
|
|
|
{
|
2008-03-24 21:33:06 +01:00
|
|
|
DWORD_PTR index;
|
|
|
|
struct profile *profile;
|
2004-10-07 21:12:41 +02:00
|
|
|
|
|
|
|
EnterCriticalSection( &MSCMS_handle_cs );
|
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
index = (DWORD_PTR)handle - 1;
|
|
|
|
if (index > num_profile_handles)
|
2004-10-07 21:12:41 +02:00
|
|
|
{
|
2008-03-24 21:33:06 +01:00
|
|
|
LeaveCriticalSection( &MSCMS_handle_cs );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
profile = &profiletable[index];
|
2004-10-07 21:12:41 +02:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
if (profile->file != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
if (profile->access & PROFILE_READWRITE)
|
|
|
|
{
|
|
|
|
DWORD written, size = MSCMS_get_profile_size( profile->iccprofile );
|
|
|
|
|
|
|
|
if (SetFilePointer( profile->file, 0, NULL, FILE_BEGIN ) ||
|
|
|
|
!WriteFile( profile->file, profile->iccprofile, size, &written, NULL ) ||
|
|
|
|
written != size)
|
|
|
|
{
|
|
|
|
ERR( "Unable to write color profile\n" );
|
|
|
|
}
|
2004-10-07 21:12:41 +02:00
|
|
|
}
|
2008-03-24 21:33:06 +01:00
|
|
|
CloseHandle( profile->file );
|
2004-10-07 21:12:41 +02:00
|
|
|
}
|
2008-03-24 21:33:06 +01:00
|
|
|
cmsCloseProfile( profile->cmsprofile );
|
|
|
|
HeapFree( GetProcessHeap(), 0, profile->iccprofile );
|
|
|
|
|
|
|
|
memset( profile, 0, sizeof(struct profile) );
|
2004-10-07 21:12:41 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection( &MSCMS_handle_cs );
|
2008-03-24 21:33:06 +01:00
|
|
|
return TRUE;
|
2004-10-07 21:12:41 +02:00
|
|
|
}
|
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
static HTRANSFORM alloc_transform_handle( void )
|
2004-10-07 21:12:41 +02:00
|
|
|
{
|
2008-03-24 21:33:06 +01:00
|
|
|
DWORD_PTR index;
|
|
|
|
struct transform *p;
|
|
|
|
unsigned int count = 128;
|
2004-10-07 21:12:41 +02:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
for (index = 0; index < num_transform_handles; index++)
|
2004-10-07 21:12:41 +02:00
|
|
|
{
|
2008-03-24 21:33:06 +01:00
|
|
|
if (!transformtable[index].cmstransform) return (HTRANSFORM)(index + 1);
|
2005-02-21 19:38:15 +01:00
|
|
|
}
|
2008-03-24 21:33:06 +01:00
|
|
|
if (!transformtable)
|
|
|
|
{
|
|
|
|
p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, count * sizeof(struct transform) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
count = num_transform_handles * 2;
|
|
|
|
p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, transformtable, count * sizeof(struct transform) );
|
|
|
|
}
|
|
|
|
if (!p) return NULL;
|
2005-02-21 19:38:15 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
transformtable = p;
|
|
|
|
num_transform_handles = count;
|
2005-02-21 19:38:15 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
return (HTRANSFORM)(index + 1);
|
2005-02-21 19:38:15 +01:00
|
|
|
}
|
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
HTRANSFORM create_transform( struct transform *transform )
|
2005-02-21 19:38:15 +01:00
|
|
|
{
|
2008-03-24 21:33:06 +01:00
|
|
|
HTRANSFORM handle;
|
2005-02-21 19:38:15 +01:00
|
|
|
|
|
|
|
EnterCriticalSection( &MSCMS_handle_cs );
|
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
if ((handle = alloc_transform_handle()))
|
2005-02-21 19:38:15 +01:00
|
|
|
{
|
2008-03-24 21:33:06 +01:00
|
|
|
DWORD_PTR index = (DWORD_PTR)handle - 1;
|
2013-01-24 15:18:09 +01:00
|
|
|
transformtable[index] = *transform;
|
2005-02-21 19:38:15 +01:00
|
|
|
}
|
|
|
|
LeaveCriticalSection( &MSCMS_handle_cs );
|
2008-03-24 21:33:06 +01:00
|
|
|
return handle;
|
2005-02-21 19:38:15 +01:00
|
|
|
}
|
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
BOOL close_transform( HTRANSFORM handle )
|
2005-02-21 19:38:15 +01:00
|
|
|
{
|
2008-03-24 21:33:06 +01:00
|
|
|
DWORD_PTR index;
|
|
|
|
struct transform *transform;
|
2005-02-21 19:38:15 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
EnterCriticalSection( &MSCMS_handle_cs );
|
2004-10-07 21:12:41 +02:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
index = (DWORD_PTR)handle - 1;
|
|
|
|
if (index > num_transform_handles)
|
|
|
|
{
|
2004-10-07 21:12:41 +02:00
|
|
|
LeaveCriticalSection( &MSCMS_handle_cs );
|
2008-03-24 21:33:06 +01:00
|
|
|
return FALSE;
|
2004-10-07 21:12:41 +02:00
|
|
|
}
|
2008-03-24 21:33:06 +01:00
|
|
|
transform = &transformtable[index];
|
|
|
|
|
|
|
|
cmsDeleteTransform( transform->cmstransform );
|
|
|
|
memset( transform, 0, sizeof(struct transform) );
|
|
|
|
|
|
|
|
LeaveCriticalSection( &MSCMS_handle_cs );
|
|
|
|
return TRUE;
|
2004-10-07 21:12:41 +02:00
|
|
|
}
|
|
|
|
|
2005-07-18 17:10:36 +02:00
|
|
|
#endif /* HAVE_LCMS */
|