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

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

Version: ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  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 
 65 struct profile *grab_profile( HPROFILE handle )
 66 {
 67     DWORD_PTR index;
 68 
 69     EnterCriticalSection( &MSCMS_handle_cs );
 70 
 71     index = (DWORD_PTR)handle - 1;
 72     if (index > num_profile_handles)
 73     {
 74         LeaveCriticalSection( &MSCMS_handle_cs );
 75         return NULL;
 76     }
 77     return &profiletable[index];
 78 }
 79 
 80 void release_profile( struct profile *profile )
 81 {
 82     LeaveCriticalSection( &MSCMS_handle_cs );
 83 }
 84 
 85 struct transform *grab_transform( HTRANSFORM handle )
 86 {
 87     DWORD_PTR index;
 88 
 89     EnterCriticalSection( &MSCMS_handle_cs );
 90 
 91     index = (DWORD_PTR)handle - 1;
 92     if (index > num_transform_handles)
 93     {
 94         LeaveCriticalSection( &MSCMS_handle_cs );
 95         return NULL;
 96     }
 97     return &transformtable[index];
 98 }
 99 
100 void release_transform( struct transform *transform )
101 {
102     LeaveCriticalSection( &MSCMS_handle_cs );
103 }
104 
105 static HPROFILE alloc_profile_handle( void )
106 {
107     DWORD_PTR index;
108     struct profile *p;
109     unsigned int count = 128;
110 
111     for (index = 0; index < num_profile_handles; index++)
112     {
113         if (!profiletable[index].iccprofile) return (HPROFILE)(index + 1);
114     }
115     if (!profiletable)
116     {
117         p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, count * sizeof(struct profile) );
118     }
119     else
120     {
121         count = num_profile_handles * 2;
122         p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, profiletable, count * sizeof(struct profile) );
123     }
124     if (!p) return NULL;
125 
126     profiletable = p;
127     num_profile_handles = count;
128 
129     return (HPROFILE)(index + 1);
130 }
131 
132 HPROFILE create_profile( struct profile *profile )
133 {
134     HPROFILE handle;
135 
136     EnterCriticalSection( &MSCMS_handle_cs );
137 
138     if ((handle = alloc_profile_handle()))
139     {
140         DWORD_PTR index = (DWORD_PTR)handle - 1;
141         memcpy( &profiletable[index], profile, sizeof(struct profile) );
142     }
143     LeaveCriticalSection( &MSCMS_handle_cs );
144     return handle;
145 }
146 
147 BOOL close_profile( HPROFILE handle )
148 {
149     DWORD_PTR index;
150     struct profile *profile;
151 
152     EnterCriticalSection( &MSCMS_handle_cs );
153 
154     index = (DWORD_PTR)handle - 1;
155     if (index > num_profile_handles)
156     {
157         LeaveCriticalSection( &MSCMS_handle_cs );
158         return FALSE;
159     }
160     profile = &profiletable[index];
161 
162     if (profile->file != INVALID_HANDLE_VALUE)
163     {
164         if (profile->access & PROFILE_READWRITE)
165         {
166             DWORD written, size = MSCMS_get_profile_size( profile->iccprofile );
167 
168             if (SetFilePointer( profile->file, 0, NULL, FILE_BEGIN ) ||
169                 !WriteFile( profile->file, profile->iccprofile, size, &written, NULL ) ||
170                 written != size)
171             {
172                 ERR( "Unable to write color profile\n" );
173             }
174         }
175         CloseHandle( profile->file );
176     }
177     cmsCloseProfile( profile->cmsprofile );
178     HeapFree( GetProcessHeap(), 0, profile->iccprofile );
179 
180     memset( profile, 0, sizeof(struct profile) );
181 
182     LeaveCriticalSection( &MSCMS_handle_cs );
183     return TRUE;
184 }
185 
186 static HTRANSFORM alloc_transform_handle( void )
187 {
188     DWORD_PTR index;
189     struct transform *p;
190     unsigned int count = 128;
191 
192     for (index = 0; index < num_transform_handles; index++)
193     {
194         if (!transformtable[index].cmstransform) return (HTRANSFORM)(index + 1);
195     }
196     if (!transformtable)
197     {
198         p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, count * sizeof(struct transform) );
199     }
200     else
201     {
202         count = num_transform_handles * 2;
203         p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, transformtable, count * sizeof(struct transform) );
204     }
205     if (!p) return NULL;
206 
207     transformtable = p;
208     num_transform_handles = count;
209 
210     return (HTRANSFORM)(index + 1);
211 }
212 
213 HTRANSFORM create_transform( struct transform *transform )
214 {
215     HTRANSFORM handle;
216 
217     EnterCriticalSection( &MSCMS_handle_cs );
218 
219     if ((handle = alloc_transform_handle()))
220     {
221         DWORD_PTR index = (DWORD_PTR)handle - 1;
222         memcpy( &transformtable[index], transform, sizeof(struct transform) );
223     }
224     LeaveCriticalSection( &MSCMS_handle_cs );
225     return handle;
226 }
227 
228 BOOL close_transform( HTRANSFORM handle )
229 {
230     DWORD_PTR index;
231     struct transform *transform;
232 
233     EnterCriticalSection( &MSCMS_handle_cs );
234 
235     index = (DWORD_PTR)handle - 1;
236     if (index > num_transform_handles)
237     {
238         LeaveCriticalSection( &MSCMS_handle_cs );
239         return FALSE;
240     }
241     transform = &transformtable[index];
242 
243     cmsDeleteTransform( transform->cmstransform );
244     memset( transform, 0, sizeof(struct transform) );
245 
246     LeaveCriticalSection( &MSCMS_handle_cs );
247     return TRUE;
248 }
249 
250 #endif /* HAVE_LCMS */
251 

~ [ 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.