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
22 #include "wine/debug.h"
33 #define LCMS_API_FUNCTION(f) extern typeof(f) * p##f;
35 #undef LCMS_API_FUNCTION
37 #define IS_SEPARATOR(ch) ((ch) == '\\' || (ch) == '/')
39 static void MSCMS_basename( LPCWSTR path, LPWSTR name )
41 INT i = lstrlenW( path );
43 while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
44 lstrcpyW( name, &path[i] );
47 WINE_DEFAULT_DEBUG_CHANNEL(mscms);
49 /******************************************************************************
50 * GetColorDirectoryA [MSCMS.@]
52 * See GetColorDirectoryW.
54 BOOL WINAPI GetColorDirectoryA( PCSTR machine, PSTR buffer, PDWORD size )
59 DWORD sizeW = *size * sizeof(WCHAR);
61 TRACE( "( %p, %ld )\n", buffer, *size );
63 if (machine || !buffer) return FALSE;
65 bufferW = HeapAlloc( GetProcessHeap(), 0, sizeW );
69 ret = GetColorDirectoryW( NULL, bufferW, &sizeW );
70 *size = sizeW / sizeof(WCHAR);
74 len = WideCharToMultiByte( CP_ACP, 0, bufferW, *size, buffer, *size, NULL, NULL );
75 if (!len) ret = FALSE;
78 HeapFree( GetProcessHeap(), 0, bufferW );
83 /******************************************************************************
84 * GetColorDirectoryW [MSCMS.@]
86 * Get the directory where color profiles are stored.
89 * machine [I] Name of the machine for which to get the color directory.
90 * Must be NULL, which indicates the local machine.
91 * buffer [I] Buffer to recieve the path name in.
92 * size [I/O] Size of the buffer in bytes. On return the variable holds
93 * the number of bytes actually needed.
95 BOOL WINAPI GetColorDirectoryW( PCWSTR machine, PWSTR buffer, PDWORD size )
97 /* FIXME: Get this directory from the registry? */
98 static const WCHAR colordir[] =
99 { 'c',':','\\','w','i','n','d','o','w','s','\\', 's','y','s','t','e','m','3','2',
100 '\\','s','p','o','o','l','\\','d','r','i','v','e','r','s','\\','c','o','l','o','r',0 };
104 TRACE( "( %p, %ld )\n", buffer, *size );
106 if (machine || !buffer) return FALSE;
108 len = lstrlenW( colordir ) * sizeof(WCHAR);
112 lstrcpyW( buffer, colordir );
120 /******************************************************************************
121 * InstallColorProfileA [MSCMS.@]
123 * See InstallColorProfileW.
125 BOOL WINAPI InstallColorProfileA( PCSTR machine, PCSTR profile )
131 TRACE( "( %s )\n", debugstr_a(profile) );
133 if (machine || !profile) return FALSE;
135 len = MultiByteToWideChar( CP_ACP, 0, profile, -1, NULL, 0 );
136 profileW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
140 MultiByteToWideChar( CP_ACP, 0, profile, -1, profileW, len );
142 ret = InstallColorProfileW( NULL, profileW );
143 HeapFree( GetProcessHeap(), 0, profileW );
148 /******************************************************************************
149 * InstallColorProfileW [MSCMS.@]
151 * Install a color profile.
154 * machine [I] Name of the machine to install the profile on. Must be NULL,
155 * which indicates the local machine.
156 * profile [I] Full path name of the profile to install.
162 BOOL WINAPI InstallColorProfileW( PCWSTR machine, PCWSTR profile )
164 WCHAR dest[MAX_PATH], base[MAX_PATH];
165 DWORD size = sizeof(dest);
166 static const WCHAR slash[] = { '\\', 0 };
168 TRACE( "( %s )\n", debugstr_w(profile) );
170 if (machine || !profile) return FALSE;
172 if (!GetColorDirectoryW( machine, dest, &size )) return FALSE;
174 MSCMS_basename( profile, base );
176 lstrcatW( dest, slash );
177 lstrcatW( dest, base );
179 /* Is source equal to destination? */
180 if (!lstrcmpW( profile, dest )) return TRUE;
182 return CopyFileW( profile, dest, TRUE );
185 /******************************************************************************
186 * IsColorProfileValid [MSCMS.@]
188 * Determine if a given color profile is valid.
191 * profile [I] Color profile handle.
192 * valid [O] Pointer to a BOOL variable. Set to TRUE if profile is valid,
199 BOOL WINAPI IsColorProfileValid( HPROFILE profile, PBOOL valid )
201 FIXME( "( %p, %p ) stub\n", profile, valid );
203 return *valid = TRUE;
206 /******************************************************************************
207 * UninstallColorProfileA [MSCMS.@]
209 * See UninstallColorProfileW.
211 BOOL WINAPI UninstallColorProfileA( PCSTR machine, PCSTR profile, BOOL delete )
217 TRACE( "( %s, %x )\n", debugstr_a(profile), delete );
219 if (machine || !profile) return FALSE;
221 len = MultiByteToWideChar( CP_ACP, 0, profile, -1, NULL, 0 );
222 profileW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
226 MultiByteToWideChar( CP_ACP, 0, profile, -1, profileW, len );
228 ret = UninstallColorProfileW( NULL, profileW , delete );
230 HeapFree( GetProcessHeap(), 0, profileW );
235 /******************************************************************************
236 * UninstallColorProfileW [MSCMS.@]
238 * Uninstall a color profile.
241 * machine [I] Name of the machine to uninstall the profile on. Must be NULL,
242 * which indicates the local machine.
243 * profile [I] Full path name of the profile to uninstall.
244 * delete [I] Bool that specifies whether the profile file should be deleted.
250 BOOL WINAPI UninstallColorProfileW( PCWSTR machine, PCWSTR profile, BOOL delete )
252 TRACE( "( %s, %x )\n", debugstr_w(profile), delete );
254 if (machine || !profile) return FALSE;
257 return DeleteFileW( profile );
262 /******************************************************************************
263 * OpenColorProfileA [MSCMS.@]
265 * See OpenColorProfileW.
267 HPROFILE WINAPI OpenColorProfileA( PPROFILE profile, DWORD access, DWORD sharing, DWORD creation )
269 HPROFILE handle = NULL;
271 TRACE( "( %p, %lx, %lx, %lx )\n", profile, access, sharing, creation );
273 if (!profile || !profile->pProfileData) return NULL;
275 /* No AW conversion needed for memory based profiles */
276 if (profile->dwType & PROFILE_MEMBUFFER)
277 return OpenColorProfileW( profile, access, sharing, creation );
279 if (profile->dwType & PROFILE_FILENAME)
284 profileW.dwType = profile->dwType;
286 len = MultiByteToWideChar( CP_ACP, 0, profile->pProfileData, -1, NULL, 0 );
287 profileW.pProfileData = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
289 if (profileW.pProfileData)
291 profileW.cbDataSize = len * sizeof(WCHAR);
292 MultiByteToWideChar( CP_ACP, 0, profile->pProfileData, -1, profileW.pProfileData, len );
294 handle = OpenColorProfileW( &profileW, access, sharing, creation );
295 HeapFree( GetProcessHeap(), 0, profileW.pProfileData );
301 /******************************************************************************
302 * OpenColorProfileW [MSCMS.@]
304 * Open a color profile.
307 * profile [I] Pointer to a color profile structure.
308 * access [I] Desired access.
309 * sharing [I] Sharing mode.
310 * creation [I] Creation mode.
313 * Success: Handle to the opened profile.
317 * Values for access: PROFILE_READ or PROFILE_READWRITE.
318 * Values for sharing: 0 (no sharing), FILE_SHARE_READ and/or FILE_SHARE_WRITE.
319 * Values for creation: one of CREATE_NEW, CREATE_ALWAYS, OPEN_EXISTING,
320 * OPEN_ALWAYS, TRUNCATE_EXISTING.
322 HPROFILE WINAPI OpenColorProfileW( PPROFILE profile, DWORD access, DWORD sharing, DWORD creation )
325 cmsHPROFILE cmsprofile = NULL;
326 HANDLE handle = NULL;
328 TRACE( "( %p, %lx, %lx, %lx )\n", profile, access, sharing, creation );
330 if (!profile || !profile->pProfileData) return NULL;
332 if (profile->dwType & PROFILE_MEMBUFFER)
334 FIXME( "Memory based profile not yet supported.\n" ); return NULL;
337 if (profile->dwType & PROFILE_FILENAME)
342 TRACE("profile file: %s\n", debugstr_w( (WCHAR *)profile->pProfileData ));
344 if (access & PROFILE_READ) flags = GENERIC_READ;
345 if (access & PROFILE_READWRITE) flags = GENERIC_READ|GENERIC_WRITE;
347 if (!flags) return NULL;
349 handle = CreateFileW( profile->pProfileData, flags, sharing, NULL, creation, 0, NULL );
350 if (handle == INVALID_HANDLE_VALUE) return NULL;
352 unixname = wine_get_unix_file_name( (WCHAR *)profile->pProfileData );
356 cmsprofile = cmsOpenProfileFromFile( unixname, flags & GENERIC_READ ? "r" : "w" );
357 HeapFree( GetProcessHeap(), 0, unixname );
361 if (cmsprofile) return MSCMS_create_hprofile_handle( handle, cmsprofile );
363 #endif /* HAVE_LCMS_H */
367 /******************************************************************************
368 * CloseColorProfile [MSCMS.@]
370 * Close a color profile.
373 * profile [I] Handle to the profile.
379 BOOL WINAPI CloseColorProfile( HPROFILE profile )
381 BOOL ret1, ret2 = FALSE;
383 TRACE( "( %p )\n", profile );
386 ret1 = cmsCloseProfile( MSCMS_hprofile2cmsprofile( profile ) );
387 ret2 = CloseHandle( MSCMS_hprofile2handle( profile ) );
389 MSCMS_destroy_hprofile_handle( profile );
391 #endif /* HAVE_LCMS_H */