Prevent use of MAKEPOINTS in Wine code.
[wine/multimedia.git] / dlls / mscms / handle.c
blobc13c46c00c6d969e3c8c50130b6936202ef4774f
1 /*
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
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_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
50 struct handlemap
52 HANDLE file;
53 cmsHPROFILE cmsprofile;
56 #define CMSMAXHANDLES 0x80
58 static struct handlemap handlemaptable[CMSMAXHANDLES];
60 HPROFILE MSCMS_cmsprofile2hprofile( cmsHPROFILE cmsprofile )
62 HPROFILE ret = NULL;
63 unsigned int i;
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;
77 out:
78 LeaveCriticalSection( &MSCMS_handle_cs );
80 return ret;
83 cmsHPROFILE MSCMS_hprofile2cmsprofile( HPROFILE profile )
85 HANDLE ret;
86 unsigned int i;
88 EnterCriticalSection( &MSCMS_handle_cs );
90 i = (unsigned int)profile - 1;
91 ret = handlemaptable[i].cmsprofile;
93 LeaveCriticalSection( &MSCMS_handle_cs );
95 return ret;
98 HANDLE MSCMS_hprofile2handle( HPROFILE profile )
100 HANDLE ret;
101 unsigned int i;
103 EnterCriticalSection( &MSCMS_handle_cs );
105 i = (unsigned int)profile - 1;
106 ret = handlemaptable[i].file;
108 LeaveCriticalSection( &MSCMS_handle_cs );
110 return ret;
113 HPROFILE MSCMS_create_hprofile_handle( HANDLE file, cmsHPROFILE cmsprofile )
115 HPROFILE ret = NULL;
116 unsigned int i;
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;
133 out:
134 LeaveCriticalSection( &MSCMS_handle_cs );
136 return ret;
139 void MSCMS_destroy_hprofile_handle( HPROFILE profile )
141 unsigned int i;
143 if (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 */