~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/mscms/handle.c

Version: ~ [ wine-1.5.30 ] ~ [ wine-1.5.29 ] ~ [ wine-1.5.28 ] ~ [ wine-1.5.27 ] ~ [ wine-1.5.26 ] ~ [ wine-1.5.25 ] ~ [ wine-1.5.24 ] ~ [ wine-1.5.23 ] ~ [ wine-1.5.22 ] ~ [ wine-1.5.21 ] ~ [ wine-1.5.20 ] ~ [ wine-1.5.19 ] ~ [ wine-1.5.18 ] ~ [ wine-1.5.17 ] ~ [ wine-1.5.16 ] ~ [ wine-1.5.15 ] ~ [ wine-1.5.14 ] ~ [ wine-1.5.13 ] ~ [ wine-1.5.12 ] ~ [ wine-1.5.11 ] ~ [ wine-1.5.10 ] ~ [ wine-1.5.9 ] ~ [ wine-1.5.8 ] ~ [ wine-1.5.7 ] ~ [ wine-1.4.1 ] ~ [ wine-1.5.6 ] ~ [ wine-1.5.5 ] ~ [ wine-1.5.4 ] ~ [ wine-1.5.3 ] ~ [ wine-1.5.2 ] ~ [ wine-1.5.1 ] ~ [ wine-1.5.0 ] ~ [ wine-1.4 ] ~ [ wine-1.4-rc6 ] ~ [ wine-1.4-rc5 ] ~ [ wine-1.4-rc4 ] ~ [ wine-1.4-rc3 ] ~ [ wine-1.4-rc2 ] ~ [ wine-1.4-rc1 ] ~ [ wine-1.3.37 ] ~ [ wine-1.3.36 ] ~ [ wine-1.3.35 ] ~ [ wine-1.3.34 ] ~ [ wine-1.3.33 ] ~ [ wine-1.3.32 ] ~ [ wine-1.3.31 ] ~ [ wine-1.3.30 ] ~ [ wine-1.3.29 ] ~ [ wine-1.3.28 ] ~ [ wine-1.3.27 ] ~ [ wine-1.3.26 ] ~ [ wine-1.3.25 ] ~ [ wine-1.3.24 ] ~ [ wine-1.3.23 ] ~ [ wine-1.3.22 ] ~ [ wine-1.3.21 ] ~ [ wine-1.3.20 ] ~ [ wine-1.3.19 ] ~ [ wine-1.3.18 ] ~ [ wine-1.2.3 ] ~ [ wine-1.3.17 ] ~ [ wine-1.3.16 ] ~ [ wine-1.3.15 ] ~ [ wine-1.3.14 ] ~ [ wine-1.3.13 ] ~ [ wine-1.3.12 ] ~ [ wine-1.3.11 ] ~ [ wine-1.3.10 ] ~ [ wine-1.3.9 ] ~ [ wine-1.2.2 ] ~ [ wine-1.3.8 ] ~ [ wine-1.3.7 ] ~ [ wine-1.3.6 ] ~ [ wine-1.3.5 ] ~ [ wine-1.2.1 ] ~ [ wine-1.3.4 ] ~ [ wine-1.3.3 ] ~ [ wine-1.3.2 ] ~ [ wine-1.3.1 ] ~ [ wine-1.3.0 ] ~ [ wine-1.2 ] ~ [ wine-1.2-rc7 ] ~ [ wine-1.2-rc6 ] ~ [ wine-1.2-rc5 ] ~ [ wine-1.2-rc4 ] ~ [ wine-1.2-rc3 ] ~ [ wine-1.2-rc2 ] ~ [ wine-1.2-rc1 ] ~ [ wine-1.1.44 ] ~ [ wine-1.1.43 ] ~ [ wine-1.1.42 ] ~ [ wine-1.1.41 ] ~ [ wine-1.1.40 ] ~ [ wine-1.1.39 ] ~ [ wine-1.1.38 ] ~ [ wine-1.1.37 ] ~ [ wine-1.1.36 ] ~ [ wine-1.1.35 ] ~ [ wine-1.1.34 ] ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * MSCMS - Color Management System for Wine
  3  *
  4  * Copyright 2004, 2005, 2008 Hans Leidekker
  5  *
  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.
 10  *
 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.
 15  *
 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
 19  */
 20 
 21 #include "config.h"
 22 #include "wine/debug.h"
 23 
 24 #include <stdarg.h>
 25 
 26 #include "windef.h"
 27 #include "winbase.h"
 28 #include "wingdi.h"
 29 #include "winuser.h"
 30 #include "icm.h"
 31 
 32 #include "mscms_priv.h"
 33 
 34 #ifdef HAVE_LCMS
 35 
 36 static CRITICAL_SECTION MSCMS_handle_cs;
 37 static CRITICAL_SECTION_DEBUG MSCMS_handle_cs_debug =
 38 {
 39     0, 0, &MSCMS_handle_cs,
 40     { &MSCMS_handle_cs_debug.ProcessLocksList,
 41       &MSCMS_handle_cs_debug.ProcessLocksList },
 42       0, 0, { (DWORD_PTR)(__FILE__ ": MSCMS_handle_cs") }
 43 };
 44 static CRITICAL_SECTION MSCMS_handle_cs = { &MSCMS_handle_cs_debug, -1, 0, 0, 0, 0 };
 45 
 46 static struct profile *profiletable;
 47 static struct transform *transformtable;
 48 
 49 static unsigned int num_profile_handles;
 50 static unsigned int num_transform_handles;
 51 
 52 WINE_DEFAULT_DEBUG_CHANNEL(mscms);
 53 
 54 void free_handle_tables( void )
 55 {
 56     HeapFree( GetProcessHeap(), 0, profiletable );
 57     profiletable = NULL;
 58     num_profile_handles = 0;
 59 
 60     HeapFree( GetProcessHeap(), 0, transformtable );
 61     transformtable = NULL;
 62     num_transform_handles = 0;
 63 
 64     DeleteCriticalSection( &MSCMS_handle_cs );
 65 }
 66 
 67 struct profile *grab_profile( HPROFILE handle )
 68 {
 69     DWORD_PTR index;
 70 
 71     EnterCriticalSection( &MSCMS_handle_cs );
 72 
 73     index = (DWORD_PTR)handle - 1;
 74     if (index > num_profile_handles)
 75     {
 76         LeaveCriticalSection( &MSCMS_handle_cs );
 77         return NULL;
 78     }
 79     return &profiletable[index];
 80 }
 81 
 82 void release_profile( struct profile *profile )
 83 {
 84     LeaveCriticalSection( &MSCMS_handle_cs );
 85 }
 86 
 87 struct transform *grab_transform( HTRANSFORM handle )
 88 {
 89     DWORD_PTR index;
 90 
 91     EnterCriticalSection( &MSCMS_handle_cs );
 92 
 93     index = (DWORD_PTR)handle - 1;
 94     if (index > num_transform_handles)
 95     {
 96         LeaveCriticalSection( &MSCMS_handle_cs );
 97         return NULL;
 98     }
 99     return &transformtable[index];
100 }
101 
102 void release_transform( struct transform *transform )
103 {
104     LeaveCriticalSection( &MSCMS_handle_cs );
105 }
106 
107 static HPROFILE alloc_profile_handle( void )
108 {
109     DWORD_PTR index;
110     struct profile *p;
111     unsigned int count = 128;
112 
113     for (index = 0; index < num_profile_handles; index++)
114     {
115         if (!profiletable[index].iccprofile) return (HPROFILE)(index + 1);
116     }
117     if (!profiletable)
118     {
119         p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, count * sizeof(struct profile) );
120     }
121     else
122     {
123         count = num_profile_handles * 2;
124         p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, profiletable, count * sizeof(struct profile) );
125     }
126     if (!p) return NULL;
127 
128     profiletable = p;
129     num_profile_handles = count;
130 
131     return (HPROFILE)(index + 1);
132 }
133 
134 HPROFILE create_profile( struct profile *profile )
135 {
136     HPROFILE handle;
137 
138     EnterCriticalSection( &MSCMS_handle_cs );
139 
140     if ((handle = alloc_profile_handle()))
141     {
142         DWORD_PTR index = (DWORD_PTR)handle - 1;
143         memcpy( &profiletable[index], profile, sizeof(struct profile) );
144     }
145     LeaveCriticalSection( &MSCMS_handle_cs );
146     return handle;
147 }
148 
149 BOOL close_profile( HPROFILE handle )
150 {
151     DWORD_PTR index;
152     struct profile *profile;
153 
154     EnterCriticalSection( &MSCMS_handle_cs );
155 
156     index = (DWORD_PTR)handle - 1;
157     if (index > num_profile_handles)
158     {
159         LeaveCriticalSection( &MSCMS_handle_cs );
160         return FALSE;
161     }
162     profile = &profiletable[index];
163 
164     if (profile->file != INVALID_HANDLE_VALUE)
165     {
166         if (profile->access & PROFILE_READWRITE)
167         {
168             DWORD written, size = MSCMS_get_profile_size( profile->iccprofile );
169 
170             if (SetFilePointer( profile->file, 0, NULL, FILE_BEGIN ) ||
171                 !WriteFile( profile->file, profile->iccprofile, size, &written, NULL ) ||
172                 written != size)
173             {
174                 ERR( "Unable to write color profile\n" );
175             }
176         }
177         CloseHandle( profile->file );
178     }
179     cmsCloseProfile( profile->cmsprofile );
180     HeapFree( GetProcessHeap(), 0, profile->iccprofile );
181 
182     memset( profile, 0, sizeof(struct profile) );
183 
184     LeaveCriticalSection( &MSCMS_handle_cs );
185     return TRUE;
186 }
187 
188 static HTRANSFORM alloc_transform_handle( void )
189 {
190     DWORD_PTR index;
191     struct transform *p;
192     unsigned int count = 128;
193 
194     for (index = 0; index < num_transform_handles; index++)
195     {
196         if (!transformtable[index].cmstransform) return (HTRANSFORM)(index + 1);
197     }
198     if (!transformtable)
199     {
200         p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, count * sizeof(struct transform) );
201     }
202     else
203     {
204         count = num_transform_handles * 2;
205         p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, transformtable, count * sizeof(struct transform) );
206     }
207     if (!p) return NULL;
208 
209     transformtable = p;
210     num_transform_handles = count;
211 
212     return (HTRANSFORM)(index + 1);
213 }
214 
215 HTRANSFORM create_transform( struct transform *transform )
216 {
217     HTRANSFORM handle;
218 
219     EnterCriticalSection( &MSCMS_handle_cs );
220 
221     if ((handle = alloc_transform_handle()))
222     {
223         DWORD_PTR index = (DWORD_PTR)handle - 1;
224         memcpy( &transformtable[index], transform, sizeof(struct transform) );
225     }
226     LeaveCriticalSection( &MSCMS_handle_cs );
227     return handle;
228 }
229 
230 BOOL close_transform( HTRANSFORM handle )
231 {
232     DWORD_PTR index;
233     struct transform *transform;
234 
235     EnterCriticalSection( &MSCMS_handle_cs );
236 
237     index = (DWORD_PTR)handle - 1;
238     if (index > num_transform_handles)
239     {
240         LeaveCriticalSection( &MSCMS_handle_cs );
241         return FALSE;
242     }
243     transform = &transformtable[index];
244 
245     cmsDeleteTransform( transform->cmstransform );
246     memset( transform, 0, sizeof(struct transform) );
247 
248     LeaveCriticalSection( &MSCMS_handle_cs );
249     return TRUE;
250 }
251 
252 #endif /* HAVE_LCMS */
253 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.