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 a pointer to an icc profile, an lcms
45 * color profile handle and a Windows file handle. Windows color profile
46 * handles are built from indexes into an array of these structures. If
47 * the profile is memory based the file handle field is NULL.
53 icProfile *iccprofile;
54 cmsHPROFILE cmsprofile;
57 #define CMSMAXHANDLES 0x80
59 static struct handlemap handlemaptable[CMSMAXHANDLES];
61 HPROFILE MSCMS_handle2hprofile( HANDLE file )
63 HPROFILE profile = NULL;
66 if (!file) return NULL;
68 EnterCriticalSection( &MSCMS_handle_cs );
70 for (i = 0; i <= CMSMAXHANDLES; i++)
72 if (handlemaptable[i].file == file)
74 profile = (HPROFILE)(i + 1); goto out;
79 LeaveCriticalSection( &MSCMS_handle_cs );
84 HANDLE MSCMS_hprofile2handle( HPROFILE profile )
89 EnterCriticalSection( &MSCMS_handle_cs );
91 i = (unsigned int)profile - 1;
92 file = handlemaptable[i].file;
94 LeaveCriticalSection( &MSCMS_handle_cs );
99 HPROFILE MSCMS_cmsprofile2hprofile( cmsHPROFILE cmsprofile )
101 HPROFILE profile = NULL;
104 if (!cmsprofile) return NULL;
106 EnterCriticalSection( &MSCMS_handle_cs );
108 for (i = 0; i <= CMSMAXHANDLES; i++)
110 if (handlemaptable[i].cmsprofile == cmsprofile)
112 profile = (HPROFILE)(i + 1); goto out;
117 LeaveCriticalSection( &MSCMS_handle_cs );
122 cmsHPROFILE MSCMS_hprofile2cmsprofile( HPROFILE profile )
124 cmsHPROFILE cmshprofile;
127 EnterCriticalSection( &MSCMS_handle_cs );
129 i = (unsigned int)profile - 1;
130 cmshprofile = handlemaptable[i].cmsprofile;
132 LeaveCriticalSection( &MSCMS_handle_cs );
137 HPROFILE MSCMS_iccprofile2hprofile( icProfile *iccprofile )
139 HPROFILE profile = NULL;
142 if (!iccprofile) return NULL;
144 EnterCriticalSection( &MSCMS_handle_cs );
146 for (i = 0; i <= CMSMAXHANDLES; i++)
148 if (handlemaptable[i].iccprofile == iccprofile)
150 profile = (HPROFILE)(i + 1); goto out;
155 LeaveCriticalSection( &MSCMS_handle_cs );
160 icProfile *MSCMS_hprofile2iccprofile( HPROFILE profile )
162 icProfile *iccprofile;
165 EnterCriticalSection( &MSCMS_handle_cs );
167 i = (unsigned int)profile - 1;
168 iccprofile = handlemaptable[i].iccprofile;
170 LeaveCriticalSection( &MSCMS_handle_cs );
175 HPROFILE MSCMS_create_hprofile_handle( HANDLE file, icProfile *iccprofile, cmsHPROFILE cmsprofile )
177 HPROFILE profile = NULL;
180 if (!cmsprofile || !iccprofile) return NULL;
182 EnterCriticalSection( &MSCMS_handle_cs );
184 for (i = 0; i <= CMSMAXHANDLES; i++)
186 if (handlemaptable[i].iccprofile == 0)
188 handlemaptable[i].file = file;
189 handlemaptable[i].iccprofile = iccprofile;
190 handlemaptable[i].cmsprofile = cmsprofile;
192 profile = (HPROFILE)(i + 1); goto out;
197 LeaveCriticalSection( &MSCMS_handle_cs );
202 void MSCMS_destroy_hprofile_handle( HPROFILE profile )
208 EnterCriticalSection( &MSCMS_handle_cs );
210 i = (unsigned int)profile - 1;
211 memset( &handlemaptable[i], 0, sizeof(struct handlemap) );
213 LeaveCriticalSection( &MSCMS_handle_cs );
217 #endif /* HAVE_LCMS_H */