2004-10-07 21:12:41 +02:00
|
|
|
/*
|
|
|
|
* MSCMS - Color Management System for Wine
|
|
|
|
*
|
|
|
|
* Copyright 2004 Hans Leidekker
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#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"
|
|
|
|
|
|
|
|
#ifdef HAVE_LCMS_H
|
|
|
|
|
|
|
|
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 },
|
|
|
|
0, 0, { 0, (DWORD)(__FILE__ ": MSCMS_handle_cs") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION MSCMS_handle_cs = { &MSCMS_handle_cs_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
2004-11-30 22:06:14 +01:00
|
|
|
/* A simple structure to tie together a pointer to an icc profile, an lcms
|
|
|
|
* color profile handle and a Windows file handle. Windows color profile
|
|
|
|
* handles are built from indexes into an array of these structures. If
|
|
|
|
* the profile is memory based the file handle field is NULL.
|
2004-10-07 21:12:41 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct handlemap
|
|
|
|
{
|
|
|
|
HANDLE file;
|
2004-11-30 22:06:14 +01:00
|
|
|
icProfile *iccprofile;
|
2004-10-07 21:12:41 +02:00
|
|
|
cmsHPROFILE cmsprofile;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define CMSMAXHANDLES 0x80
|
|
|
|
|
|
|
|
static struct handlemap handlemaptable[CMSMAXHANDLES];
|
|
|
|
|
2004-11-30 22:06:14 +01:00
|
|
|
HPROFILE MSCMS_handle2hprofile( HANDLE file )
|
|
|
|
{
|
|
|
|
HPROFILE profile = NULL;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (!file) return NULL;
|
|
|
|
|
|
|
|
EnterCriticalSection( &MSCMS_handle_cs );
|
|
|
|
|
|
|
|
for (i = 0; i <= CMSMAXHANDLES; i++)
|
|
|
|
{
|
|
|
|
if (handlemaptable[i].file == file)
|
|
|
|
{
|
|
|
|
profile = (HPROFILE)(i + 1); goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
LeaveCriticalSection( &MSCMS_handle_cs );
|
|
|
|
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE MSCMS_hprofile2handle( HPROFILE profile )
|
|
|
|
{
|
|
|
|
HANDLE file;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
EnterCriticalSection( &MSCMS_handle_cs );
|
|
|
|
|
|
|
|
i = (unsigned int)profile - 1;
|
|
|
|
file = handlemaptable[i].file;
|
|
|
|
|
|
|
|
LeaveCriticalSection( &MSCMS_handle_cs );
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2004-10-07 21:12:41 +02:00
|
|
|
HPROFILE MSCMS_cmsprofile2hprofile( cmsHPROFILE cmsprofile )
|
|
|
|
{
|
2004-11-30 22:06:14 +01:00
|
|
|
HPROFILE profile = NULL;
|
2004-10-07 21:12:41 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
2004-11-30 22:06:14 +01:00
|
|
|
if (!cmsprofile) return NULL;
|
2004-10-07 21:12:41 +02:00
|
|
|
|
|
|
|
EnterCriticalSection( &MSCMS_handle_cs );
|
|
|
|
|
|
|
|
for (i = 0; i <= CMSMAXHANDLES; i++)
|
|
|
|
{
|
|
|
|
if (handlemaptable[i].cmsprofile == cmsprofile)
|
|
|
|
{
|
2004-11-30 22:06:14 +01:00
|
|
|
profile = (HPROFILE)(i + 1); goto out;
|
2004-10-07 21:12:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
LeaveCriticalSection( &MSCMS_handle_cs );
|
|
|
|
|
2004-11-30 22:06:14 +01:00
|
|
|
return profile;
|
2004-10-07 21:12:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cmsHPROFILE MSCMS_hprofile2cmsprofile( HPROFILE profile )
|
|
|
|
{
|
2004-11-30 22:06:14 +01:00
|
|
|
cmsHPROFILE cmshprofile;
|
2004-10-07 21:12:41 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
EnterCriticalSection( &MSCMS_handle_cs );
|
|
|
|
|
|
|
|
i = (unsigned int)profile - 1;
|
2004-11-30 22:06:14 +01:00
|
|
|
cmshprofile = handlemaptable[i].cmsprofile;
|
2004-10-07 21:12:41 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection( &MSCMS_handle_cs );
|
|
|
|
|
2004-11-30 22:06:14 +01:00
|
|
|
return cmshprofile;
|
2004-10-07 21:12:41 +02:00
|
|
|
}
|
|
|
|
|
2004-11-30 22:06:14 +01:00
|
|
|
HPROFILE MSCMS_iccprofile2hprofile( icProfile *iccprofile )
|
|
|
|
{
|
|
|
|
HPROFILE profile = NULL;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (!iccprofile) return NULL;
|
|
|
|
|
|
|
|
EnterCriticalSection( &MSCMS_handle_cs );
|
|
|
|
|
|
|
|
for (i = 0; i <= CMSMAXHANDLES; i++)
|
|
|
|
{
|
|
|
|
if (handlemaptable[i].iccprofile == iccprofile)
|
|
|
|
{
|
|
|
|
profile = (HPROFILE)(i + 1); goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
LeaveCriticalSection( &MSCMS_handle_cs );
|
|
|
|
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
|
|
|
icProfile *MSCMS_hprofile2iccprofile( HPROFILE profile )
|
2004-10-07 21:12:41 +02:00
|
|
|
{
|
2004-11-30 22:06:14 +01:00
|
|
|
icProfile *iccprofile;
|
2004-10-07 21:12:41 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
EnterCriticalSection( &MSCMS_handle_cs );
|
|
|
|
|
|
|
|
i = (unsigned int)profile - 1;
|
2004-11-30 22:06:14 +01:00
|
|
|
iccprofile = handlemaptable[i].iccprofile;
|
2004-10-07 21:12:41 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection( &MSCMS_handle_cs );
|
|
|
|
|
2004-11-30 22:06:14 +01:00
|
|
|
return iccprofile;
|
2004-10-07 21:12:41 +02:00
|
|
|
}
|
|
|
|
|
2004-11-30 22:06:14 +01:00
|
|
|
HPROFILE MSCMS_create_hprofile_handle( HANDLE file, icProfile *iccprofile, cmsHPROFILE cmsprofile )
|
2004-10-07 21:12:41 +02:00
|
|
|
{
|
2004-11-30 22:06:14 +01:00
|
|
|
HPROFILE profile = NULL;
|
2004-10-07 21:12:41 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
2004-11-30 22:06:14 +01:00
|
|
|
if (!cmsprofile || !iccprofile) return NULL;
|
2004-10-07 21:12:41 +02:00
|
|
|
|
|
|
|
EnterCriticalSection( &MSCMS_handle_cs );
|
|
|
|
|
|
|
|
for (i = 0; i <= CMSMAXHANDLES; i++)
|
|
|
|
{
|
2004-11-30 22:06:14 +01:00
|
|
|
if (handlemaptable[i].iccprofile == 0)
|
2004-10-07 21:12:41 +02:00
|
|
|
{
|
|
|
|
handlemaptable[i].file = file;
|
2004-11-30 22:06:14 +01:00
|
|
|
handlemaptable[i].iccprofile = iccprofile;
|
2004-10-07 21:12:41 +02:00
|
|
|
handlemaptable[i].cmsprofile = cmsprofile;
|
|
|
|
|
2004-11-30 22:06:14 +01:00
|
|
|
profile = (HPROFILE)(i + 1); goto out;
|
2004-10-07 21:12:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
LeaveCriticalSection( &MSCMS_handle_cs );
|
|
|
|
|
2004-11-30 22:06:14 +01:00
|
|
|
return profile;
|
2004-10-07 21:12:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MSCMS_destroy_hprofile_handle( HPROFILE profile )
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (profile)
|
|
|
|
{
|
|
|
|
EnterCriticalSection( &MSCMS_handle_cs );
|
|
|
|
|
|
|
|
i = (unsigned int)profile - 1;
|
|
|
|
memset( &handlemaptable[i], 0, sizeof(struct handlemap) );
|
|
|
|
|
|
|
|
LeaveCriticalSection( &MSCMS_handle_cs );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_LCMS_H */
|