2 * MSCMS - Color Management System for Wine
4 * Copyright 2004 Hans Leidekker
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "mscms_priv.h"
34 static CRITICAL_SECTION MSCMS_handle_cs;
35 static CRITICAL_SECTION_DEBUG MSCMS_handle_cs_debug =
37 0, 0, &MSCMS_handle_cs,
38 { &MSCMS_handle_cs_debug.ProcessLocksList,
39 &MSCMS_handle_cs_debug.ProcessLocksList },
40 0, 0, { 0, (DWORD)(__FILE__ ": MSCMS_handle_cs") }
42 static CRITICAL_SECTION MSCMS_handle_cs = { &MSCMS_handle_cs_debug, -1, 0, 0, 0, 0 };
44 /* A simple structure to tie together Windows file handles and lcms color
45 * profile handles. Windows color profile handles are built from indexes
46 * into an array of these structures. The 'file' field is set to NULL in
47 * case of a memory based profile
53 cmsHPROFILE cmsprofile;
56 #define CMSMAXHANDLES 0x80
58 static struct handlemap handlemaptable[CMSMAXHANDLES];
60 HPROFILE MSCMS_cmsprofile2hprofile( cmsHPROFILE cmsprofile )
65 if (!cmsprofile) return ret;
67 EnterCriticalSection( &MSCMS_handle_cs );
69 for (i = 0; i <= CMSMAXHANDLES; i++)
71 if (handlemaptable[i].cmsprofile == cmsprofile)
73 ret = (HPROFILE)(i + 1); goto out;
78 LeaveCriticalSection( &MSCMS_handle_cs );
83 cmsHPROFILE MSCMS_hprofile2cmsprofile( HPROFILE profile )
88 EnterCriticalSection( &MSCMS_handle_cs );
90 i = (unsigned int)profile - 1;
91 ret = handlemaptable[i].cmsprofile;
93 LeaveCriticalSection( &MSCMS_handle_cs );
98 HANDLE MSCMS_hprofile2handle( HPROFILE profile )
103 EnterCriticalSection( &MSCMS_handle_cs );
105 i = (unsigned int)profile - 1;
106 ret = handlemaptable[i].file;
108 LeaveCriticalSection( &MSCMS_handle_cs );
113 HPROFILE MSCMS_create_hprofile_handle( HANDLE file, cmsHPROFILE cmsprofile )
118 if (!cmsprofile) return ret;
120 EnterCriticalSection( &MSCMS_handle_cs );
122 for (i = 0; i <= CMSMAXHANDLES; i++)
124 if (handlemaptable[i].cmsprofile == 0)
126 handlemaptable[i].file = file;
127 handlemaptable[i].cmsprofile = cmsprofile;
129 ret = (HPROFILE)(i + 1); goto out;
134 LeaveCriticalSection( &MSCMS_handle_cs );
139 void MSCMS_destroy_hprofile_handle( HPROFILE profile )
145 EnterCriticalSection( &MSCMS_handle_cs );
147 i = (unsigned int)profile - 1;
148 memset( &handlemaptable[i], 0, sizeof(struct handlemap) );
150 LeaveCriticalSection( &MSCMS_handle_cs );
154 #endif /* HAVE_LCMS_H */