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 WINE_DEFAULT_DEBUG_CHANNEL(mscms
);
39 BOOL WINAPI
GetColorDirectoryA( PCSTR machine
, PSTR buffer
, PDWORD size
)
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
);
54 ret
= GetColorDirectoryW( NULL
, bufferW
, &sizeW
);
55 *size
= sizeW
/ sizeof(WCHAR
);
59 len
= WideCharToMultiByte( CP_ACP
, 0, bufferW
, *size
, buffer
, *size
, NULL
, NULL
);
60 if (!len
) ret
= FALSE
;
63 HeapFree( GetProcessHeap(), 0, bufferW
);
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 };
78 TRACE( "( %p, %ld )\n", buffer
, *size
);
80 if (machine
|| !buffer
) return FALSE
;
82 len
= lstrlenW( colordir
) * sizeof(WCHAR
);
86 lstrcatW( buffer
, colordir
);
94 BOOL WINAPI
InstallColorProfileA( PCSTR machine
, PCSTR profile
)
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
) );
109 MultiByteToWideChar( CP_ACP
, 0, profile
, -1, profileW
, len
);
111 ret
= InstallColorProfileW( NULL
, profileW
);
112 HeapFree( GetProcessHeap(), 0, profileW
);
118 BOOL WINAPI
InstallColorProfileW( PCWSTR machine
, PCWSTR profile
)
120 FIXME( "( %s ) stub\n", debugstr_w(profile
) );
122 if (machine
|| !profile
) return FALSE
;
127 BOOL WINAPI
UninstallColorProfileA( PCSTR machine
, PCSTR profile
, BOOL
delete )
129 if (machine
|| !profile
) return FALSE
;
132 return DeleteFileA( profile
);
137 BOOL WINAPI
UninstallColorProfileW( PCWSTR machine
, PCWSTR profile
, BOOL
delete )
139 if (machine
|| !profile
) return FALSE
;
142 return DeleteFileW( profile
);
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
)
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
);
182 /******************************************************************************
183 * OpenColorProfileW [MSCMS.@]
185 * Open a color profile.
188 * profile [I] Pointer to a color profile structure
189 * access [I] Desired access
190 * sharing [I] Sharing mode
191 * creation [I] Creation mode
194 * Success: Handle to the opened profile
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
)
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
)
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
);
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 */
249 /******************************************************************************
250 * CloseColorProfile [MSCMS.@]
252 * Close a color profile.
255 * profile [I] Handle to the profile
261 BOOL WINAPI
CloseColorProfile( HPROFILE profile
)
263 BOOL ret1
, ret2
= FALSE
;
265 TRACE( "( %p )\n", profile
);
268 ret1
= cmsCloseProfile( MSCMS_hprofile2cmsprofile( profile
) );
269 ret2
= CloseHandle( MSCMS_hprofile2handle( profile
) );
271 MSCMS_destroy_hprofile_handle( profile
);
273 #endif /* HAVE_LCMS_H */