Implement color profile handles.
[wine.git] / dlls / mscms / profile.c
blobb95fd1b6a75ab741e4d5b5b3a4844c70bf5ae50c
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 "wine/debug.h"
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winnls.h"
30 #include "wingdi.h"
31 #include "icm.h"
33 #define LCMS_API_FUNCTION(f) extern typeof(f) * p##f;
34 #include "lcms_api.h"
35 #undef LCMS_API_FUNCTION
37 WINE_DEFAULT_DEBUG_CHANNEL(mscms);
39 BOOL WINAPI GetColorDirectoryA( PCSTR machine, PSTR buffer, PDWORD size )
41 INT len;
42 LPWSTR bufferW;
43 BOOL ret = FALSE;
44 DWORD sizeW = *size * sizeof(WCHAR);
46 TRACE( "( %p, %ld )\n", buffer, *size );
48 if (machine || !buffer) return FALSE;
50 bufferW = HeapAlloc( GetProcessHeap(), 0, sizeW );
52 if (bufferW)
54 ret = GetColorDirectoryW( NULL, bufferW, &sizeW );
55 *size = sizeW / sizeof(WCHAR);
57 if (ret)
59 len = WideCharToMultiByte( CP_ACP, 0, bufferW, *size, buffer, *size, NULL, NULL );
60 if (!len) ret = FALSE;
63 HeapFree( GetProcessHeap(), 0, bufferW );
66 return ret;
69 BOOL WINAPI GetColorDirectoryW( PCWSTR machine, PWSTR buffer, PDWORD size )
71 /* FIXME: Get this directory from the registry? */
72 static const WCHAR colordir[] =
73 { 'c',':','\\','w','i','n','d','o','w','s','\\', 's','y','s','t','e','m','3','2',
74 '\\','s','p','o','o','l','\\','d','r','i','v','e','r','s','\\','c','o','l','o','r',0 };
76 DWORD len;
78 TRACE( "( %p, %ld )\n", buffer, *size );
80 if (machine || !buffer) return FALSE;
82 len = lstrlenW( colordir ) * sizeof(WCHAR);
84 if (len <= *size)
86 lstrcatW( buffer, colordir );
87 return TRUE;
90 *size = len;
91 return FALSE;
94 BOOL WINAPI InstallColorProfileA( PCSTR machine, PCSTR profile )
96 UINT len;
97 LPWSTR profileW;
98 BOOL ret = FALSE;
100 TRACE( "( %s )\n", debugstr_a(profile) );
102 if (machine || !profile) return FALSE;
104 len = MultiByteToWideChar( CP_ACP, 0, profile, -1, NULL, 0 );
105 profileW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
107 if (profileW)
109 MultiByteToWideChar( CP_ACP, 0, profile, -1, profileW, len );
111 ret = InstallColorProfileW( NULL, profileW );
112 HeapFree( GetProcessHeap(), 0, profileW );
115 return ret;
118 BOOL WINAPI InstallColorProfileW( PCWSTR machine, PCWSTR profile )
120 FIXME( "( %s ) stub\n", debugstr_w(profile) );
122 if (machine || !profile) return FALSE;
124 return FALSE;
127 BOOL WINAPI UninstallColorProfileA( PCSTR machine, PCSTR profile, BOOL delete )
129 if (machine || !profile) return FALSE;
131 if (delete)
132 return DeleteFileA( profile );
134 return TRUE;
137 BOOL WINAPI UninstallColorProfileW( PCWSTR machine, PCWSTR profile, BOOL delete )
139 if (machine || !profile) return FALSE;
141 if (delete)
142 return DeleteFileW( profile );
144 return TRUE;
147 HPROFILE WINAPI OpenColorProfileA( PPROFILE profile, DWORD access, DWORD sharing, DWORD creation )
149 HPROFILE handle = NULL;
151 TRACE( "( %p, %lx, %lx, %lx )\n", profile, access, sharing, creation );
153 if (!profile || !profile->pProfileData) return NULL;
155 /* No AW conversion needed for memory based profiles */
156 if (profile->dwType & PROFILE_MEMBUFFER)
157 return OpenColorProfileW( profile, access, sharing, creation );
159 if (profile->dwType & PROFILE_FILENAME)
161 UINT len;
162 PROFILE profileW;
164 profileW.dwType = profile->dwType;
166 len = MultiByteToWideChar( CP_ACP, 0, profile->pProfileData, -1, NULL, 0 );
167 profileW.pProfileData = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
169 if (profileW.pProfileData)
171 profileW.cbDataSize = len * sizeof(WCHAR);
172 MultiByteToWideChar( CP_ACP, 0, profile->pProfileData, -1, profileW.pProfileData, len );
174 handle = OpenColorProfileW( &profileW, access, sharing, creation );
175 HeapFree( GetProcessHeap(), 0, profileW.pProfileData );
179 return handle;
182 /******************************************************************************
183 * OpenColorProfileW [MSCMS.@]
185 * Open a color profile.
187 * PARAMS
188 * profile [I] Pointer to a color profile structure
189 * access [I] Desired access
190 * sharing [I] Sharing mode
191 * creation [I] Creation mode
193 * RETURNS
194 * Success: Handle to the opened profile
195 * Failure: NULL
197 * NOTES
198 * Values for access: PROFILE_READ or PROFILE_READWRITE
199 * Values for sharing: 0 (no sharing), FILE_SHARE_READ and/or FILE_SHARE_WRITE
200 * Values for creation: one of CREATE_NEW, CREATE_ALWAYS, OPEN_EXISTING,
201 * OPEN_ALWAYS, TRUNCATE_EXISTING.
204 HPROFILE WINAPI OpenColorProfileW( PPROFILE profile, DWORD access, DWORD sharing, DWORD creation )
206 #ifdef HAVE_LCMS_H
207 cmsHPROFILE cmsprofile = NULL;
208 HANDLE handle = NULL;
210 TRACE( "( %p, %lx, %lx, %lx )\n", profile, access, sharing, creation );
212 if (!profile || !profile->pProfileData) return NULL;
214 if (profile->dwType & PROFILE_MEMBUFFER)
216 FIXME( "Memory based profile not yet supported.\n" ); return NULL;
219 if (profile->dwType & PROFILE_FILENAME)
221 char *unixname;
222 DWORD flags = 0;
224 TRACE("profile file: %s\n", debugstr_w( (WCHAR *)profile->pProfileData ));
226 if (access & PROFILE_READ) flags = GENERIC_READ;
227 if (access & PROFILE_READWRITE) flags = GENERIC_READ|GENERIC_WRITE;
229 if (!flags) return NULL;
231 handle = CreateFileW( profile->pProfileData, flags, sharing, NULL, creation, 0, NULL );
232 if (handle == INVALID_HANDLE_VALUE) return NULL;
234 unixname = wine_get_unix_file_name( (WCHAR *)profile->pProfileData );
236 if (unixname)
238 cmsprofile = cmsOpenProfileFromFile( unixname, flags & GENERIC_READ ? "r" : "w" );
239 HeapFree( GetProcessHeap(), 0, unixname );
243 if (cmsprofile) return MSCMS_create_hprofile_handle( handle, cmsprofile );
245 #endif /* HAVE_LCMS_H */
246 return NULL;
249 BOOL WINAPI CloseColorProfile( HPROFILE profile )
251 BOOL ret1, ret2 = FALSE;
253 TRACE( "( %p )\n", profile );
255 #ifdef HAVE_LCMS_H
256 ret1 = cmsCloseProfile( MSCMS_hprofile2cmsprofile( profile ) );
257 ret2 = CloseHandle( MSCMS_hprofile2handle( profile ) );
259 MSCMS_destroy_hprofile_handle( profile );
261 #endif /* HAVE_LCMS_H */
262 return ret1 && ret2;