Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenhandle.c
Go to the documentation of this file.
00001 /* 00002 * MSCMS - Color Management System for Wine 00003 * 00004 * Copyright 2004, 2005, 2008 Hans Leidekker 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00019 */ 00020 00021 #include "config.h" 00022 #include "wine/debug.h" 00023 00024 #include <stdarg.h> 00025 00026 #include "windef.h" 00027 #include "winbase.h" 00028 #include "wingdi.h" 00029 #include "winuser.h" 00030 #include "icm.h" 00031 00032 #include "mscms_priv.h" 00033 00034 #ifdef HAVE_LCMS 00035 00036 static CRITICAL_SECTION MSCMS_handle_cs; 00037 static CRITICAL_SECTION_DEBUG MSCMS_handle_cs_debug = 00038 { 00039 0, 0, &MSCMS_handle_cs, 00040 { &MSCMS_handle_cs_debug.ProcessLocksList, 00041 &MSCMS_handle_cs_debug.ProcessLocksList }, 00042 0, 0, { (DWORD_PTR)(__FILE__ ": MSCMS_handle_cs") } 00043 }; 00044 static CRITICAL_SECTION MSCMS_handle_cs = { &MSCMS_handle_cs_debug, -1, 0, 0, 0, 0 }; 00045 00046 static struct profile *profiletable; 00047 static struct transform *transformtable; 00048 00049 static unsigned int num_profile_handles; 00050 static unsigned int num_transform_handles; 00051 00052 WINE_DEFAULT_DEBUG_CHANNEL(mscms); 00053 00054 void free_handle_tables( void ) 00055 { 00056 HeapFree( GetProcessHeap(), 0, profiletable ); 00057 profiletable = NULL; 00058 num_profile_handles = 0; 00059 00060 HeapFree( GetProcessHeap(), 0, transformtable ); 00061 transformtable = NULL; 00062 num_transform_handles = 0; 00063 00064 DeleteCriticalSection( &MSCMS_handle_cs ); 00065 } 00066 00067 struct profile *grab_profile( HPROFILE handle ) 00068 { 00069 DWORD_PTR index; 00070 00071 EnterCriticalSection( &MSCMS_handle_cs ); 00072 00073 index = (DWORD_PTR)handle - 1; 00074 if (index > num_profile_handles) 00075 { 00076 LeaveCriticalSection( &MSCMS_handle_cs ); 00077 return NULL; 00078 } 00079 return &profiletable[index]; 00080 } 00081 00082 void release_profile( struct profile *profile ) 00083 { 00084 LeaveCriticalSection( &MSCMS_handle_cs ); 00085 } 00086 00087 struct transform *grab_transform( HTRANSFORM handle ) 00088 { 00089 DWORD_PTR index; 00090 00091 EnterCriticalSection( &MSCMS_handle_cs ); 00092 00093 index = (DWORD_PTR)handle - 1; 00094 if (index > num_transform_handles) 00095 { 00096 LeaveCriticalSection( &MSCMS_handle_cs ); 00097 return NULL; 00098 } 00099 return &transformtable[index]; 00100 } 00101 00102 void release_transform( struct transform *transform ) 00103 { 00104 LeaveCriticalSection( &MSCMS_handle_cs ); 00105 } 00106 00107 static HPROFILE alloc_profile_handle( void ) 00108 { 00109 DWORD_PTR index; 00110 struct profile *p; 00111 unsigned int count = 128; 00112 00113 for (index = 0; index < num_profile_handles; index++) 00114 { 00115 if (!profiletable[index].iccprofile) return (HPROFILE)(index + 1); 00116 } 00117 if (!profiletable) 00118 { 00119 p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, count * sizeof(struct profile) ); 00120 } 00121 else 00122 { 00123 count = num_profile_handles * 2; 00124 p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, profiletable, count * sizeof(struct profile) ); 00125 } 00126 if (!p) return NULL; 00127 00128 profiletable = p; 00129 num_profile_handles = count; 00130 00131 return (HPROFILE)(index + 1); 00132 } 00133 00134 HPROFILE create_profile( struct profile *profile ) 00135 { 00136 HPROFILE handle; 00137 00138 EnterCriticalSection( &MSCMS_handle_cs ); 00139 00140 if ((handle = alloc_profile_handle())) 00141 { 00142 DWORD_PTR index = (DWORD_PTR)handle - 1; 00143 memcpy( &profiletable[index], profile, sizeof(struct profile) ); 00144 } 00145 LeaveCriticalSection( &MSCMS_handle_cs ); 00146 return handle; 00147 } 00148 00149 BOOL close_profile( HPROFILE handle ) 00150 { 00151 DWORD_PTR index; 00152 struct profile *profile; 00153 00154 EnterCriticalSection( &MSCMS_handle_cs ); 00155 00156 index = (DWORD_PTR)handle - 1; 00157 if (index > num_profile_handles) 00158 { 00159 LeaveCriticalSection( &MSCMS_handle_cs ); 00160 return FALSE; 00161 } 00162 profile = &profiletable[index]; 00163 00164 if (profile->file != INVALID_HANDLE_VALUE) 00165 { 00166 if (profile->access & PROFILE_READWRITE) 00167 { 00168 DWORD written, size = MSCMS_get_profile_size( profile->iccprofile ); 00169 00170 if (SetFilePointer( profile->file, 0, NULL, FILE_BEGIN ) || 00171 !WriteFile( profile->file, profile->iccprofile, size, &written, NULL ) || 00172 written != size) 00173 { 00174 ERR( "Unable to write color profile\n" ); 00175 } 00176 } 00177 CloseHandle( profile->file ); 00178 } 00179 cmsCloseProfile( profile->cmsprofile ); 00180 HeapFree( GetProcessHeap(), 0, profile->iccprofile ); 00181 00182 memset( profile, 0, sizeof(struct profile) ); 00183 00184 LeaveCriticalSection( &MSCMS_handle_cs ); 00185 return TRUE; 00186 } 00187 00188 static HTRANSFORM alloc_transform_handle( void ) 00189 { 00190 DWORD_PTR index; 00191 struct transform *p; 00192 unsigned int count = 128; 00193 00194 for (index = 0; index < num_transform_handles; index++) 00195 { 00196 if (!transformtable[index].cmstransform) return (HTRANSFORM)(index + 1); 00197 } 00198 if (!transformtable) 00199 { 00200 p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, count * sizeof(struct transform) ); 00201 } 00202 else 00203 { 00204 count = num_transform_handles * 2; 00205 p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, transformtable, count * sizeof(struct transform) ); 00206 } 00207 if (!p) return NULL; 00208 00209 transformtable = p; 00210 num_transform_handles = count; 00211 00212 return (HTRANSFORM)(index + 1); 00213 } 00214 00215 HTRANSFORM create_transform( struct transform *transform ) 00216 { 00217 HTRANSFORM handle; 00218 00219 EnterCriticalSection( &MSCMS_handle_cs ); 00220 00221 if ((handle = alloc_transform_handle())) 00222 { 00223 DWORD_PTR index = (DWORD_PTR)handle - 1; 00224 memcpy( &transformtable[index], transform, sizeof(struct transform) ); 00225 } 00226 LeaveCriticalSection( &MSCMS_handle_cs ); 00227 return handle; 00228 } 00229 00230 BOOL close_transform( HTRANSFORM handle ) 00231 { 00232 DWORD_PTR index; 00233 struct transform *transform; 00234 00235 EnterCriticalSection( &MSCMS_handle_cs ); 00236 00237 index = (DWORD_PTR)handle - 1; 00238 if (index > num_transform_handles) 00239 { 00240 LeaveCriticalSection( &MSCMS_handle_cs ); 00241 return FALSE; 00242 } 00243 transform = &transformtable[index]; 00244 00245 cmsDeleteTransform( transform->cmstransform ); 00246 memset( transform, 0, sizeof(struct transform) ); 00247 00248 LeaveCriticalSection( &MSCMS_handle_cs ); 00249 return TRUE; 00250 } 00251 00252 #endif /* HAVE_LCMS */ Generated on Fri May 25 2012 04:22:20 for ReactOS by
1.7.6.1
|