wine.inf: We should not override existing associations.
[wine/hacks.git] / dlls / mscms / handle.c
blob0ee2c95e6a5677f39fe35d50e8a9dd6d92354456
1 /*
2 * MSCMS - Color Management System for Wine
4 * Copyright 2004, 2005 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "icm.h"
30 #include "mscms_priv.h"
32 #ifdef HAVE_LCMS
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, { (DWORD_PTR)(__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. The 'access'
48 * field records the access parameter supplied to an OpenColorProfile()
49 * call, i.e. PROFILE_READ or PROFILE_READWRITE.
52 struct profile
54 HANDLE file;
55 DWORD access;
56 icProfile *iccprofile;
57 cmsHPROFILE cmsprofile;
60 struct transform
62 cmsHTRANSFORM cmstransform;
65 #define CMSMAXHANDLES 0x80
67 static struct profile profiletable[CMSMAXHANDLES];
68 static struct transform transformtable[CMSMAXHANDLES];
70 HPROFILE MSCMS_handle2hprofile( HANDLE file )
72 HPROFILE profile = NULL;
73 DWORD_PTR i;
75 if (!file) return NULL;
77 EnterCriticalSection( &MSCMS_handle_cs );
79 for (i = 0; i <= CMSMAXHANDLES; i++)
81 if (profiletable[i].file == file)
83 profile = (HPROFILE)(i + 1); goto out;
87 out:
88 LeaveCriticalSection( &MSCMS_handle_cs );
89 return profile;
92 HANDLE MSCMS_hprofile2handle( HPROFILE profile )
94 HANDLE file;
95 DWORD_PTR i;
97 EnterCriticalSection( &MSCMS_handle_cs );
99 i = (DWORD_PTR)profile - 1;
100 file = profiletable[i].file;
102 LeaveCriticalSection( &MSCMS_handle_cs );
103 return file;
106 DWORD MSCMS_hprofile2access( HPROFILE profile )
108 DWORD access;
109 DWORD_PTR i;
111 EnterCriticalSection( &MSCMS_handle_cs );
113 i = (DWORD_PTR)profile - 1;
114 access = profiletable[i].access;
116 LeaveCriticalSection( &MSCMS_handle_cs );
117 return access;
120 HPROFILE MSCMS_cmsprofile2hprofile( cmsHPROFILE cmsprofile )
122 HPROFILE profile = NULL;
123 DWORD_PTR i;
125 if (!cmsprofile) return NULL;
127 EnterCriticalSection( &MSCMS_handle_cs );
129 for (i = 0; i <= CMSMAXHANDLES; i++)
131 if (profiletable[i].cmsprofile == cmsprofile)
133 profile = (HPROFILE)(i + 1); goto out;
137 out:
138 LeaveCriticalSection( &MSCMS_handle_cs );
139 return profile;
142 cmsHPROFILE MSCMS_hprofile2cmsprofile( HPROFILE profile )
144 cmsHPROFILE cmsprofile;
145 DWORD_PTR i;
147 EnterCriticalSection( &MSCMS_handle_cs );
149 i = (DWORD_PTR)profile - 1;
150 cmsprofile = profiletable[i].cmsprofile;
152 LeaveCriticalSection( &MSCMS_handle_cs );
153 return cmsprofile;
156 HPROFILE MSCMS_iccprofile2hprofile( icProfile *iccprofile )
158 HPROFILE profile = NULL;
159 DWORD_PTR i;
161 if (!iccprofile) return NULL;
163 EnterCriticalSection( &MSCMS_handle_cs );
165 for (i = 0; i <= CMSMAXHANDLES; i++)
167 if (profiletable[i].iccprofile == iccprofile)
169 profile = (HPROFILE)(i + 1); goto out;
173 out:
174 LeaveCriticalSection( &MSCMS_handle_cs );
175 return profile;
178 icProfile *MSCMS_hprofile2iccprofile( HPROFILE profile )
180 icProfile *iccprofile;
181 DWORD_PTR i;
183 EnterCriticalSection( &MSCMS_handle_cs );
185 i = (DWORD_PTR)profile - 1;
186 iccprofile = profiletable[i].iccprofile;
188 LeaveCriticalSection( &MSCMS_handle_cs );
189 return iccprofile;
192 HPROFILE MSCMS_create_hprofile_handle( HANDLE file, icProfile *iccprofile,
193 cmsHPROFILE cmsprofile, DWORD access )
195 HPROFILE profile = NULL;
196 DWORD_PTR i;
198 if (!cmsprofile || !iccprofile) return NULL;
200 EnterCriticalSection( &MSCMS_handle_cs );
202 for (i = 0; i <= CMSMAXHANDLES; i++)
204 if (profiletable[i].iccprofile == 0)
206 profiletable[i].file = file;
207 profiletable[i].access = access;
208 profiletable[i].iccprofile = iccprofile;
209 profiletable[i].cmsprofile = cmsprofile;
211 profile = (HPROFILE)(i + 1); goto out;
215 out:
216 LeaveCriticalSection( &MSCMS_handle_cs );
217 return profile;
220 void MSCMS_destroy_hprofile_handle( HPROFILE profile )
222 DWORD_PTR i;
224 if (profile)
226 EnterCriticalSection( &MSCMS_handle_cs );
228 i = (DWORD_PTR)profile - 1;
229 memset( &profiletable[i], 0, sizeof(struct profile) );
231 LeaveCriticalSection( &MSCMS_handle_cs );
235 cmsHTRANSFORM MSCMS_htransform2cmstransform( HTRANSFORM transform )
237 cmsHTRANSFORM cmstransform;
238 DWORD_PTR i;
240 EnterCriticalSection( &MSCMS_handle_cs );
242 i = (DWORD_PTR)transform - 1;
243 cmstransform = transformtable[i].cmstransform;
245 LeaveCriticalSection( &MSCMS_handle_cs );
246 return cmstransform;
249 HTRANSFORM MSCMS_create_htransform_handle( cmsHTRANSFORM cmstransform )
251 HTRANSFORM transform = NULL;
252 DWORD_PTR i;
254 if (!cmstransform) return NULL;
256 EnterCriticalSection( &MSCMS_handle_cs );
258 for (i = 0; i <= CMSMAXHANDLES; i++)
260 if (transformtable[i].cmstransform == 0)
262 transformtable[i].cmstransform = cmstransform;
263 transform = (HTRANSFORM)(i + 1); goto out;
267 out:
268 LeaveCriticalSection( &MSCMS_handle_cs );
269 return transform;
272 void MSCMS_destroy_htransform_handle( HTRANSFORM transform )
274 DWORD_PTR i;
276 if (transform)
278 EnterCriticalSection( &MSCMS_handle_cs );
280 i = (DWORD_PTR)transform - 1;
281 memset( &transformtable[i], 0, sizeof(struct transform) );
283 LeaveCriticalSection( &MSCMS_handle_cs );
287 #endif /* HAVE_LCMS */