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
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, { (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.
56 icProfile
*iccprofile
;
57 cmsHPROFILE cmsprofile
;
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
;
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
;
88 LeaveCriticalSection( &MSCMS_handle_cs
);
92 HANDLE
MSCMS_hprofile2handle( HPROFILE profile
)
97 EnterCriticalSection( &MSCMS_handle_cs
);
99 i
= (DWORD_PTR
)profile
- 1;
100 file
= profiletable
[i
].file
;
102 LeaveCriticalSection( &MSCMS_handle_cs
);
106 DWORD
MSCMS_hprofile2access( HPROFILE profile
)
111 EnterCriticalSection( &MSCMS_handle_cs
);
113 i
= (DWORD_PTR
)profile
- 1;
114 access
= profiletable
[i
].access
;
116 LeaveCriticalSection( &MSCMS_handle_cs
);
120 HPROFILE
MSCMS_cmsprofile2hprofile( cmsHPROFILE cmsprofile
)
122 HPROFILE profile
= NULL
;
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
;
138 LeaveCriticalSection( &MSCMS_handle_cs
);
142 cmsHPROFILE
MSCMS_hprofile2cmsprofile( HPROFILE profile
)
144 cmsHPROFILE cmsprofile
;
147 EnterCriticalSection( &MSCMS_handle_cs
);
149 i
= (DWORD_PTR
)profile
- 1;
150 cmsprofile
= profiletable
[i
].cmsprofile
;
152 LeaveCriticalSection( &MSCMS_handle_cs
);
156 HPROFILE
MSCMS_iccprofile2hprofile( icProfile
*iccprofile
)
158 HPROFILE profile
= NULL
;
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
;
174 LeaveCriticalSection( &MSCMS_handle_cs
);
178 icProfile
*MSCMS_hprofile2iccprofile( HPROFILE profile
)
180 icProfile
*iccprofile
;
183 EnterCriticalSection( &MSCMS_handle_cs
);
185 i
= (DWORD_PTR
)profile
- 1;
186 iccprofile
= profiletable
[i
].iccprofile
;
188 LeaveCriticalSection( &MSCMS_handle_cs
);
192 HPROFILE
MSCMS_create_hprofile_handle( HANDLE file
, icProfile
*iccprofile
,
193 cmsHPROFILE cmsprofile
, DWORD access
)
195 HPROFILE profile
= NULL
;
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
;
216 LeaveCriticalSection( &MSCMS_handle_cs
);
220 void MSCMS_destroy_hprofile_handle( HPROFILE 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
;
240 EnterCriticalSection( &MSCMS_handle_cs
);
242 i
= (DWORD_PTR
)transform
- 1;
243 cmstransform
= transformtable
[i
].cmstransform
;
245 LeaveCriticalSection( &MSCMS_handle_cs
);
249 HTRANSFORM
MSCMS_create_htransform_handle( cmsHTRANSFORM cmstransform
)
251 HTRANSFORM transform
= NULL
;
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
;
268 LeaveCriticalSection( &MSCMS_handle_cs
);
272 void MSCMS_destroy_htransform_handle( HTRANSFORM 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 */