2004-10-07 21:12:41 +02:00
|
|
|
/*
|
|
|
|
* MSCMS - Color Management System for Wine
|
|
|
|
*
|
2008-02-22 14:24:46 +01:00
|
|
|
* Copyright 2004, 2005, 2006, 2008 Hans Leidekker
|
2004-10-07 21:12:41 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-10-07 21:12:41 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/debug.h"
|
2008-02-22 14:24:46 +01:00
|
|
|
#include "wine/unicode.h"
|
2004-10-07 21:12:41 +02:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#include "wingdi.h"
|
2004-10-22 21:56:51 +02:00
|
|
|
#include "winuser.h"
|
2008-02-22 14:24:46 +01:00
|
|
|
#include "winreg.h"
|
2011-09-20 11:31:13 +02:00
|
|
|
#include "shlwapi.h"
|
2004-10-07 21:12:41 +02:00
|
|
|
#include "icm.h"
|
|
|
|
|
2005-07-15 12:09:43 +02:00
|
|
|
#include "mscms_priv.h"
|
2004-10-07 21:12:41 +02:00
|
|
|
|
2004-11-03 23:14:25 +01:00
|
|
|
#define IS_SEPARATOR(ch) ((ch) == '\\' || (ch) == '/')
|
|
|
|
|
|
|
|
static void MSCMS_basename( LPCWSTR path, LPWSTR name )
|
|
|
|
{
|
|
|
|
INT i = lstrlenW( path );
|
|
|
|
|
|
|
|
while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
|
|
|
|
lstrcpyW( name, &path[i] );
|
|
|
|
}
|
|
|
|
|
2006-03-07 16:50:17 +01:00
|
|
|
static inline LPWSTR MSCMS_strdupW( LPCSTR str )
|
|
|
|
{
|
|
|
|
LPWSTR ret = NULL;
|
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
|
|
|
|
if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-02-24 15:20:15 +01:00
|
|
|
const char *MSCMS_dbgstr_tag( DWORD tag )
|
2006-03-07 16:50:17 +01:00
|
|
|
{
|
|
|
|
return wine_dbg_sprintf( "'%c%c%c%c'",
|
|
|
|
(char)(tag >> 24), (char)(tag >> 16), (char)(tag >> 8), (char)(tag) );
|
|
|
|
}
|
|
|
|
|
2004-10-07 21:12:41 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mscms);
|
|
|
|
|
2008-02-22 14:24:46 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* AssociateColorProfileWithDeviceA [MSCMS.@]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI AssociateColorProfileWithDeviceA( PCSTR machine, PCSTR profile, PCSTR device )
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
WCHAR *profileW, *deviceW;
|
|
|
|
|
|
|
|
TRACE( "( %s, %s, %s )\n", debugstr_a(machine), debugstr_a(profile), debugstr_a(device) );
|
|
|
|
|
|
|
|
if (!profile || !device)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (machine)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_SUPPORTED );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, profile, -1, NULL, 0 );
|
|
|
|
if (!(profileW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return FALSE;
|
|
|
|
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, profile, -1, profileW, len );
|
|
|
|
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, device, -1, NULL, 0 );
|
|
|
|
if ((deviceW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
|
|
|
|
{
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, device, -1, deviceW, len );
|
|
|
|
ret = AssociateColorProfileWithDeviceW( NULL, profileW, deviceW );
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, profileW );
|
|
|
|
HeapFree( GetProcessHeap(), 0, deviceW );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL set_profile_device_key( PCWSTR file, const BYTE *value, DWORD size )
|
|
|
|
{
|
|
|
|
static const WCHAR fmtW[] = {'%','c','%','c','%','c','%','c',0};
|
|
|
|
static const WCHAR icmW[] = {'S','o','f','t','w','a','r','e','\\',
|
|
|
|
'M','i','c','r','o','s','o','f','t','\\',
|
|
|
|
'W','i','n','d','o','w','s',' ','N','T','\\',
|
|
|
|
'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
|
|
|
|
'I','C','M',0};
|
|
|
|
PROFILEHEADER header;
|
|
|
|
PROFILE profile;
|
|
|
|
HPROFILE handle;
|
|
|
|
HKEY icm_key, class_key;
|
|
|
|
WCHAR basenameW[MAX_PATH], classW[5];
|
|
|
|
|
|
|
|
profile.dwType = PROFILE_FILENAME;
|
|
|
|
profile.pProfileData = (PVOID)file;
|
|
|
|
profile.cbDataSize = (lstrlenW( file ) + 1) * sizeof(WCHAR);
|
|
|
|
|
|
|
|
/* FIXME is the profile installed? */
|
|
|
|
if (!(handle = OpenColorProfileW( &profile, PROFILE_READ, 0, OPEN_EXISTING )))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PROFILE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-03-07 12:26:36 +01:00
|
|
|
if (!GetColorProfileHeader( handle, &header ))
|
|
|
|
{
|
|
|
|
CloseColorProfile( handle );
|
|
|
|
SetLastError( ERROR_INVALID_PROFILE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-02-22 14:24:46 +01:00
|
|
|
RegCreateKeyExW( HKEY_LOCAL_MACHINE, icmW, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &icm_key, NULL );
|
|
|
|
|
|
|
|
MSCMS_basename( file, basenameW );
|
|
|
|
sprintfW( classW, fmtW, (header.phClass >> 24) & 0xff, (header.phClass >> 16) & 0xff,
|
|
|
|
(header.phClass >> 8) & 0xff, header.phClass & 0xff );
|
|
|
|
|
|
|
|
RegCreateKeyExW( icm_key, classW, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &class_key, NULL );
|
|
|
|
if (value) RegSetValueExW( class_key, basenameW, 0, REG_BINARY, value, size );
|
|
|
|
else RegDeleteValueW( class_key, basenameW );
|
|
|
|
|
|
|
|
RegCloseKey( class_key );
|
|
|
|
RegCloseKey( icm_key );
|
|
|
|
CloseColorProfile( handle );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* AssociateColorProfileWithDeviceW [MSCMS.@]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI AssociateColorProfileWithDeviceW( PCWSTR machine, PCWSTR profile, PCWSTR device )
|
|
|
|
{
|
|
|
|
static const BYTE dummy_value[12];
|
|
|
|
|
|
|
|
TRACE( "( %s, %s, %s )\n", debugstr_w(machine), debugstr_w(profile), debugstr_w(device) );
|
|
|
|
|
|
|
|
if (!profile || !device)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (machine)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_SUPPORTED );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return set_profile_device_key( profile, dummy_value, sizeof(dummy_value) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* DisassociateColorProfileFromDeviceA [MSCMS.@]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DisassociateColorProfileFromDeviceA( PCSTR machine, PCSTR profile, PCSTR device )
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
WCHAR *profileW, *deviceW;
|
|
|
|
|
|
|
|
TRACE( "( %s, %s, %s )\n", debugstr_a(machine), debugstr_a(profile), debugstr_a(device) );
|
|
|
|
|
|
|
|
if (!profile || !device)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (machine)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_SUPPORTED );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, profile, -1, NULL, 0 );
|
|
|
|
if (!(profileW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return FALSE;
|
|
|
|
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, profile, -1, profileW, len );
|
|
|
|
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, device, -1, NULL, 0 );
|
|
|
|
if ((deviceW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
|
|
|
|
{
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, device, -1, deviceW, len );
|
|
|
|
ret = DisassociateColorProfileFromDeviceW( NULL, profileW, deviceW );
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, profileW );
|
|
|
|
HeapFree( GetProcessHeap(), 0, deviceW );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* DisassociateColorProfileFromDeviceW [MSCMS.@]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DisassociateColorProfileFromDeviceW( PCWSTR machine, PCWSTR profile, PCWSTR device )
|
|
|
|
{
|
|
|
|
TRACE( "( %s, %s, %s )\n", debugstr_w(machine), debugstr_w(profile), debugstr_w(device) );
|
|
|
|
|
|
|
|
if (!profile || !device)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (machine)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_SUPPORTED );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return set_profile_device_key( profile, NULL, 0 );
|
|
|
|
}
|
|
|
|
|
2004-11-19 19:22:20 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* GetColorDirectoryA [MSCMS.@]
|
|
|
|
*
|
|
|
|
* See GetColorDirectoryW.
|
|
|
|
*/
|
2004-10-07 21:12:41 +02:00
|
|
|
BOOL WINAPI GetColorDirectoryA( PCSTR machine, PSTR buffer, PDWORD size )
|
|
|
|
{
|
|
|
|
INT len;
|
|
|
|
LPWSTR bufferW;
|
|
|
|
BOOL ret = FALSE;
|
2004-12-07 15:42:47 +01:00
|
|
|
DWORD sizeW;
|
|
|
|
|
|
|
|
TRACE( "( %p, %p )\n", buffer, size );
|
|
|
|
|
|
|
|
if (machine || !size) return FALSE;
|
2004-10-07 21:12:41 +02:00
|
|
|
|
2004-12-07 15:42:47 +01:00
|
|
|
if (!buffer)
|
|
|
|
{
|
|
|
|
ret = GetColorDirectoryW( NULL, NULL, &sizeW );
|
|
|
|
*size = sizeW / sizeof(WCHAR);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-10-07 21:12:41 +02:00
|
|
|
|
2004-12-07 15:42:47 +01:00
|
|
|
sizeW = *size * sizeof(WCHAR);
|
2004-10-07 21:12:41 +02:00
|
|
|
|
|
|
|
bufferW = HeapAlloc( GetProcessHeap(), 0, sizeW );
|
|
|
|
|
|
|
|
if (bufferW)
|
|
|
|
{
|
2006-11-08 21:46:59 +01:00
|
|
|
if ((ret = GetColorDirectoryW( NULL, bufferW, &sizeW )))
|
2004-10-07 21:12:41 +02:00
|
|
|
{
|
2006-11-08 21:46:59 +01:00
|
|
|
*size = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL );
|
|
|
|
len = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, buffer, *size, NULL, NULL );
|
2004-10-07 21:12:41 +02:00
|
|
|
if (!len) ret = FALSE;
|
|
|
|
}
|
2006-11-08 21:46:59 +01:00
|
|
|
else *size = sizeW / sizeof(WCHAR);
|
2004-10-07 21:12:41 +02:00
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, bufferW );
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-11-19 19:22:20 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* GetColorDirectoryW [MSCMS.@]
|
|
|
|
*
|
|
|
|
* Get the directory where color profiles are stored.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* machine [I] Name of the machine for which to get the color directory.
|
|
|
|
* Must be NULL, which indicates the local machine.
|
2004-12-13 14:23:17 +01:00
|
|
|
* buffer [I] Buffer to receive the path name.
|
2004-11-19 19:22:20 +01:00
|
|
|
* size [I/O] Size of the buffer in bytes. On return the variable holds
|
|
|
|
* the number of bytes actually needed.
|
|
|
|
*/
|
2004-10-07 21:12:41 +02:00
|
|
|
BOOL WINAPI GetColorDirectoryW( PCWSTR machine, PWSTR buffer, PDWORD size )
|
|
|
|
{
|
2005-04-11 20:49:40 +02:00
|
|
|
WCHAR colordir[MAX_PATH];
|
2008-01-24 20:02:53 +01:00
|
|
|
static const WCHAR colorsubdir[] =
|
|
|
|
{'\\','s','p','o','o','l','\\','d','r','i','v','e','r','s','\\','c','o','l','o','r',0};
|
2004-10-07 21:12:41 +02:00
|
|
|
DWORD len;
|
|
|
|
|
2004-12-07 15:42:47 +01:00
|
|
|
TRACE( "( %p, %p )\n", buffer, size );
|
2004-10-07 21:12:41 +02:00
|
|
|
|
2004-12-07 15:42:47 +01:00
|
|
|
if (machine || !size) return FALSE;
|
2004-10-07 21:12:41 +02:00
|
|
|
|
2005-07-05 12:56:52 +02:00
|
|
|
GetSystemDirectoryW( colordir, sizeof(colordir) / sizeof(WCHAR) );
|
2005-04-11 20:49:40 +02:00
|
|
|
lstrcatW( colordir, colorsubdir );
|
|
|
|
|
2004-10-07 21:12:41 +02:00
|
|
|
len = lstrlenW( colordir ) * sizeof(WCHAR);
|
|
|
|
|
2006-11-08 21:46:59 +01:00
|
|
|
if (buffer && len <= *size)
|
2004-10-07 21:12:41 +02:00
|
|
|
{
|
2004-11-03 23:14:25 +01:00
|
|
|
lstrcpyW( buffer, colordir );
|
2004-12-07 15:42:47 +01:00
|
|
|
*size = len;
|
2004-10-07 21:12:41 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-11-08 21:46:59 +01:00
|
|
|
SetLastError( ERROR_MORE_DATA );
|
2004-10-07 21:12:41 +02:00
|
|
|
*size = len;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-12-13 14:23:17 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* GetColorProfileElement [MSCMS.@]
|
|
|
|
*
|
|
|
|
* Retrieve data for a specified tag type.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* profile [I] Handle to a color profile.
|
|
|
|
* type [I] ICC tag type.
|
|
|
|
* offset [I] Offset in bytes to start copying from.
|
|
|
|
* size [I/O] Size of the buffer in bytes. On return the variable holds
|
|
|
|
* the number of bytes actually needed.
|
|
|
|
* buffer [O] Buffer to receive the tag data.
|
|
|
|
* ref [O] Pointer to a BOOL that specifies whether more than one tag
|
|
|
|
* references the data.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
2008-03-24 21:33:06 +01:00
|
|
|
BOOL WINAPI GetColorProfileElement( HPROFILE handle, TAGTYPE type, DWORD offset, PDWORD size,
|
2004-11-30 22:06:14 +01:00
|
|
|
PVOID buffer, PBOOL ref )
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
2005-07-18 17:10:36 +02:00
|
|
|
#ifdef HAVE_LCMS
|
2008-03-24 21:33:06 +01:00
|
|
|
struct profile *profile = grab_profile( handle );
|
2004-11-30 22:06:14 +01:00
|
|
|
DWORD i, count;
|
|
|
|
icTag tag;
|
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
TRACE( "( %p, 0x%08x, %d, %p, %p, %p )\n", handle, type, offset, size, buffer, ref );
|
2004-11-30 22:06:14 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
if (!profile) return FALSE;
|
|
|
|
|
|
|
|
if (!size || !ref)
|
|
|
|
{
|
|
|
|
release_profile( profile );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
count = MSCMS_get_tag_count( profile->iccprofile );
|
2004-11-30 22:06:14 +01:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2008-03-24 21:33:06 +01:00
|
|
|
MSCMS_get_tag_by_index( profile->iccprofile, i, &tag );
|
2004-11-30 22:06:14 +01:00
|
|
|
|
|
|
|
if (tag.sig == type)
|
|
|
|
{
|
|
|
|
if ((tag.size - offset) > *size || !buffer)
|
|
|
|
{
|
|
|
|
*size = (tag.size - offset);
|
2008-03-24 21:33:06 +01:00
|
|
|
release_profile( profile );
|
2004-11-30 22:06:14 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-03-24 21:33:06 +01:00
|
|
|
MSCMS_get_tag_data( profile->iccprofile, &tag, offset, buffer );
|
2004-11-30 22:06:14 +01:00
|
|
|
|
|
|
|
*ref = FALSE; /* FIXME: calculate properly */
|
2008-03-24 21:33:06 +01:00
|
|
|
release_profile( profile );
|
2004-11-30 22:06:14 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2008-03-24 21:33:06 +01:00
|
|
|
release_profile( profile );
|
2004-11-30 22:06:14 +01:00
|
|
|
|
2005-07-18 17:10:36 +02:00
|
|
|
#endif /* HAVE_LCMS */
|
2004-11-30 22:06:14 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-11-21 16:48:18 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* GetColorProfileElementTag [MSCMS.@]
|
|
|
|
*
|
2004-12-13 14:23:17 +01:00
|
|
|
* Get the tag type from a color profile by index.
|
2004-11-21 16:48:18 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* profile [I] Handle to a color profile.
|
|
|
|
* index [I] Index into the tag table of the color profile.
|
2004-12-13 14:23:17 +01:00
|
|
|
* type [O] Pointer to a variable that holds the ICC tag type on return.
|
2004-11-21 16:48:18 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The tag table index starts at 1.
|
|
|
|
* Use GetCountColorProfileElements to retrieve a count of tagged elements.
|
|
|
|
*/
|
2008-03-24 21:33:06 +01:00
|
|
|
BOOL WINAPI GetColorProfileElementTag( HPROFILE handle, DWORD index, PTAGTYPE type )
|
2004-11-21 16:48:18 +01:00
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
2005-07-18 17:10:36 +02:00
|
|
|
#ifdef HAVE_LCMS
|
2008-03-24 21:33:06 +01:00
|
|
|
struct profile *profile = grab_profile( handle );
|
2004-11-30 22:06:14 +01:00
|
|
|
DWORD count;
|
|
|
|
icTag tag;
|
2004-11-21 16:48:18 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
TRACE( "( %p, %d, %p )\n", handle, index, type );
|
2004-11-30 22:06:14 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
if (!profile) return FALSE;
|
2004-11-30 22:06:14 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
if (!type)
|
|
|
|
{
|
|
|
|
release_profile( profile );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
count = MSCMS_get_tag_count( profile->iccprofile );
|
|
|
|
if (index > count || index < 1)
|
|
|
|
{
|
|
|
|
release_profile( profile );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
MSCMS_get_tag_by_index( profile->iccprofile, index - 1, &tag );
|
2004-11-30 22:06:14 +01:00
|
|
|
*type = tag.sig;
|
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
release_profile( profile );
|
2004-11-30 22:06:14 +01:00
|
|
|
ret = TRUE;
|
|
|
|
|
2005-07-18 17:10:36 +02:00
|
|
|
#endif /* HAVE_LCMS */
|
2004-11-30 22:06:14 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-12-13 14:23:17 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* GetColorProfileFromHandle [MSCMS.@]
|
|
|
|
*
|
|
|
|
* Retrieve an ICC color profile by handle.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* profile [I] Handle to a color profile.
|
|
|
|
* buffer [O] Buffer to receive the ICC profile.
|
|
|
|
* size [I/O] Size of the buffer in bytes. On return the variable holds the
|
|
|
|
* number of bytes actually needed.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The profile returned will be in big-endian format.
|
|
|
|
*/
|
2008-03-24 21:33:06 +01:00
|
|
|
BOOL WINAPI GetColorProfileFromHandle( HPROFILE handle, PBYTE buffer, PDWORD size )
|
2004-11-30 22:06:14 +01:00
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
2005-07-18 17:10:36 +02:00
|
|
|
#ifdef HAVE_LCMS
|
2008-03-24 21:33:06 +01:00
|
|
|
struct profile *profile = grab_profile( handle );
|
2004-11-30 22:06:14 +01:00
|
|
|
PROFILEHEADER header;
|
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
TRACE( "( %p, %p, %p )\n", handle, buffer, size );
|
2004-11-30 22:06:14 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
if (!profile) return FALSE;
|
|
|
|
|
|
|
|
if (!size)
|
|
|
|
{
|
|
|
|
release_profile( profile );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
MSCMS_get_profile_header( profile->iccprofile, &header );
|
2004-11-30 22:06:14 +01:00
|
|
|
|
|
|
|
if (!buffer || header.phSize > *size)
|
2004-11-21 16:48:18 +01:00
|
|
|
{
|
2004-11-30 22:06:14 +01:00
|
|
|
*size = header.phSize;
|
2008-03-24 21:33:06 +01:00
|
|
|
release_profile( profile );
|
2004-11-30 22:06:14 +01:00
|
|
|
return FALSE;
|
2004-11-21 16:48:18 +01:00
|
|
|
}
|
|
|
|
|
2004-12-07 15:42:47 +01:00
|
|
|
/* No endian conversion needed */
|
2008-03-24 21:33:06 +01:00
|
|
|
memcpy( buffer, profile->iccprofile, header.phSize );
|
2004-12-20 18:04:11 +01:00
|
|
|
*size = header.phSize;
|
2008-03-24 21:33:06 +01:00
|
|
|
|
|
|
|
release_profile( profile );
|
2004-11-30 22:06:14 +01:00
|
|
|
ret = TRUE;
|
|
|
|
|
2005-07-18 17:10:36 +02:00
|
|
|
#endif /* HAVE_LCMS */
|
2004-11-30 22:06:14 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-12-13 14:23:17 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* GetColorProfileHeader [MSCMS.@]
|
|
|
|
*
|
|
|
|
* Retrieve a color profile header by handle.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* profile [I] Handle to a color profile.
|
|
|
|
* header [O] Buffer to receive the ICC profile header.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*
|
|
|
|
* NOTES
|
2011-08-02 22:20:32 +02:00
|
|
|
* The profile header returned will be adjusted for endianness.
|
2004-12-13 14:23:17 +01:00
|
|
|
*/
|
2008-03-24 21:33:06 +01:00
|
|
|
BOOL WINAPI GetColorProfileHeader( HPROFILE handle, PPROFILEHEADER header )
|
2004-11-30 22:06:14 +01:00
|
|
|
{
|
2005-07-18 17:10:36 +02:00
|
|
|
#ifdef HAVE_LCMS
|
2008-03-24 21:33:06 +01:00
|
|
|
struct profile *profile = grab_profile( handle );
|
|
|
|
|
|
|
|
TRACE( "( %p, %p )\n", handle, header );
|
2004-11-30 22:06:14 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
if (!profile) return FALSE;
|
2004-11-30 22:06:14 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
if (!header)
|
|
|
|
{
|
|
|
|
release_profile( profile );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
MSCMS_get_profile_header( profile->iccprofile, header );
|
2004-11-30 22:06:14 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
release_profile( profile );
|
2004-11-30 22:06:14 +01:00
|
|
|
return TRUE;
|
|
|
|
|
2007-07-24 22:29:05 +02:00
|
|
|
#else
|
|
|
|
return FALSE;
|
2005-07-18 17:10:36 +02:00
|
|
|
#endif /* HAVE_LCMS */
|
2004-11-21 16:48:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* GetCountColorProfileElements [MSCMS.@]
|
|
|
|
*
|
|
|
|
* Retrieve the number of elements in a color profile.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* profile [I] Handle to a color profile.
|
|
|
|
* count [O] Pointer to a variable which is set to the number of elements
|
|
|
|
* in the color profile.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
2008-03-24 21:33:06 +01:00
|
|
|
BOOL WINAPI GetCountColorProfileElements( HPROFILE handle, PDWORD count )
|
2004-11-21 16:48:18 +01:00
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
2005-07-18 17:10:36 +02:00
|
|
|
#ifdef HAVE_LCMS
|
2008-03-24 21:33:06 +01:00
|
|
|
struct profile *profile = grab_profile( handle );
|
2004-11-21 16:48:18 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
TRACE( "( %p, %p )\n", handle, count );
|
2004-11-21 16:48:18 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
if (!profile) return FALSE;
|
|
|
|
|
|
|
|
if (!count)
|
|
|
|
{
|
|
|
|
release_profile( profile );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
*count = MSCMS_get_tag_count( profile->iccprofile );
|
|
|
|
|
|
|
|
release_profile( profile );
|
2004-11-30 22:06:14 +01:00
|
|
|
ret = TRUE;
|
2004-11-21 16:48:18 +01:00
|
|
|
|
2005-07-18 17:10:36 +02:00
|
|
|
#endif /* HAVE_LCMS */
|
2004-11-21 16:48:18 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-03-09 19:42:52 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* GetStandardColorSpaceProfileA [MSCMS.@]
|
|
|
|
*
|
|
|
|
* See GetStandardColorSpaceProfileW.
|
|
|
|
*/
|
2004-11-21 16:48:18 +01:00
|
|
|
BOOL WINAPI GetStandardColorSpaceProfileA( PCSTR machine, DWORD id, PSTR profile, PDWORD size )
|
|
|
|
{
|
|
|
|
INT len;
|
|
|
|
LPWSTR profileW;
|
|
|
|
BOOL ret = FALSE;
|
2004-12-07 15:42:47 +01:00
|
|
|
DWORD sizeW;
|
2004-11-21 16:48:18 +01:00
|
|
|
|
2006-09-30 12:07:13 +02:00
|
|
|
TRACE( "( 0x%08x, %p, %p )\n", id, profile, size );
|
2004-11-21 16:48:18 +01:00
|
|
|
|
2006-01-13 14:09:04 +01:00
|
|
|
if (machine)
|
|
|
|
{
|
2006-02-20 11:13:28 +01:00
|
|
|
SetLastError( ERROR_NOT_SUPPORTED );
|
2006-01-13 14:09:04 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!size)
|
|
|
|
{
|
2006-02-20 11:13:28 +01:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2006-01-13 14:09:04 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-12-07 15:42:47 +01:00
|
|
|
|
|
|
|
sizeW = *size * sizeof(WCHAR);
|
|
|
|
|
|
|
|
if (!profile)
|
|
|
|
{
|
|
|
|
ret = GetStandardColorSpaceProfileW( NULL, id, NULL, &sizeW );
|
|
|
|
*size = sizeW / sizeof(WCHAR);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-11-21 16:48:18 +01:00
|
|
|
|
|
|
|
profileW = HeapAlloc( GetProcessHeap(), 0, sizeW );
|
|
|
|
|
|
|
|
if (profileW)
|
|
|
|
{
|
2006-11-08 21:46:59 +01:00
|
|
|
if ((ret = GetStandardColorSpaceProfileW( NULL, id, profileW, &sizeW )))
|
2004-11-21 16:48:18 +01:00
|
|
|
{
|
2006-11-08 21:46:59 +01:00
|
|
|
*size = WideCharToMultiByte( CP_ACP, 0, profileW, -1, NULL, 0, NULL, NULL );
|
|
|
|
len = WideCharToMultiByte( CP_ACP, 0, profileW, -1, profile, *size, NULL, NULL );
|
2004-11-21 16:48:18 +01:00
|
|
|
if (!len) ret = FALSE;
|
|
|
|
}
|
2006-11-08 21:46:59 +01:00
|
|
|
else *size = sizeW / sizeof(WCHAR);
|
2004-11-21 16:48:18 +01:00
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, profileW );
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-03-09 19:42:52 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* GetStandardColorSpaceProfileW [MSCMS.@]
|
|
|
|
*
|
|
|
|
* Retrieve the profile filename for a given standard color space id.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* machine [I] Name of the machine for which to get the standard color space.
|
|
|
|
* Must be NULL, which indicates the local machine.
|
|
|
|
* id [I] Id of a standard color space.
|
2005-03-23 14:15:18 +01:00
|
|
|
* profile [O] Buffer to receive the profile filename.
|
2005-03-09 19:42:52 +01:00
|
|
|
* size [I/O] Size of the filename buffer in bytes.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
2004-11-21 16:48:18 +01:00
|
|
|
BOOL WINAPI GetStandardColorSpaceProfileW( PCWSTR machine, DWORD id, PWSTR profile, PDWORD size )
|
|
|
|
{
|
2005-07-05 12:56:52 +02:00
|
|
|
static const WCHAR rgbprofilefile[] =
|
|
|
|
{ '\\','s','r','g','b',' ','c','o','l','o','r',' ',
|
|
|
|
's','p','a','c','e',' ','p','r','o','f','i','l','e','.','i','c','m',0 };
|
2005-04-11 20:49:40 +02:00
|
|
|
WCHAR rgbprofile[MAX_PATH];
|
2005-07-05 12:56:52 +02:00
|
|
|
DWORD len = sizeof(rgbprofile);
|
2004-11-21 16:48:18 +01:00
|
|
|
|
2006-09-30 12:07:13 +02:00
|
|
|
TRACE( "( 0x%08x, %p, %p )\n", id, profile, size );
|
2004-12-07 15:42:47 +01:00
|
|
|
|
2006-01-13 14:09:04 +01:00
|
|
|
if (machine)
|
|
|
|
{
|
2006-02-20 11:13:28 +01:00
|
|
|
SetLastError( ERROR_NOT_SUPPORTED );
|
2006-01-13 14:09:04 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!size)
|
|
|
|
{
|
2006-02-20 11:13:28 +01:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2006-01-13 14:09:04 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2006-02-25 09:22:36 +01:00
|
|
|
|
|
|
|
if (!profile)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INSUFFICIENT_BUFFER );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2006-01-13 14:09:04 +01:00
|
|
|
|
2005-07-05 12:56:52 +02:00
|
|
|
GetColorDirectoryW( machine, rgbprofile, &len );
|
2004-12-07 15:42:47 +01:00
|
|
|
|
|
|
|
switch (id)
|
2011-07-31 22:13:08 +02:00
|
|
|
{
|
2009-09-02 11:42:34 +02:00
|
|
|
case LCS_sRGB:
|
|
|
|
case LCS_WINDOWS_COLOR_SPACE: /* FIXME */
|
2005-04-11 20:49:40 +02:00
|
|
|
lstrcatW( rgbprofile, rgbprofilefile );
|
2005-07-05 12:56:52 +02:00
|
|
|
len = lstrlenW( rgbprofile ) * sizeof(WCHAR);
|
2004-12-07 15:42:47 +01:00
|
|
|
|
|
|
|
if (*size < len || !profile)
|
|
|
|
{
|
|
|
|
*size = len;
|
2006-11-08 21:46:59 +01:00
|
|
|
SetLastError( ERROR_MORE_DATA );
|
|
|
|
return FALSE;
|
2004-12-07 15:42:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
lstrcpyW( profile, rgbprofile );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2006-11-08 21:46:59 +01:00
|
|
|
SetLastError( ERROR_FILE_NOT_FOUND );
|
2004-12-07 15:42:47 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2004-11-21 16:48:18 +01:00
|
|
|
}
|
|
|
|
|
2007-05-28 19:11:29 +02:00
|
|
|
static BOOL MSCMS_header_from_file( LPCWSTR file, PPROFILEHEADER header )
|
2006-03-07 16:50:17 +01:00
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
PROFILE profile;
|
|
|
|
WCHAR path[MAX_PATH], slash[] = {'\\',0};
|
|
|
|
DWORD size = sizeof(path);
|
|
|
|
HANDLE handle;
|
|
|
|
|
|
|
|
ret = GetColorDirectoryW( NULL, path, &size );
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
WARN( "Can't retrieve color directory\n" );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (size + sizeof(slash) + sizeof(WCHAR) * lstrlenW( file ) > sizeof(path))
|
|
|
|
{
|
|
|
|
WARN( "Filename too long\n" );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
lstrcatW( path, slash );
|
|
|
|
lstrcatW( path, file );
|
|
|
|
|
|
|
|
profile.dwType = PROFILE_FILENAME;
|
|
|
|
profile.pProfileData = path;
|
|
|
|
profile.cbDataSize = lstrlenW( path ) + 1;
|
|
|
|
|
|
|
|
handle = OpenColorProfileW( &profile, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING );
|
|
|
|
if (!handle)
|
|
|
|
{
|
|
|
|
WARN( "Can't open color profile\n" );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GetColorProfileHeader( handle, header );
|
|
|
|
if (!ret)
|
|
|
|
WARN( "Can't retrieve color profile header\n" );
|
|
|
|
|
|
|
|
CloseColorProfile( handle );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL MSCMS_match_profile( PENUMTYPEW rec, PPROFILEHEADER hdr )
|
|
|
|
{
|
|
|
|
if (rec->dwFields & ET_DEVICENAME)
|
|
|
|
{
|
|
|
|
FIXME( "ET_DEVICENAME: %s\n", debugstr_w(rec->pDeviceName) );
|
|
|
|
}
|
|
|
|
if (rec->dwFields & ET_MEDIATYPE)
|
|
|
|
{
|
2006-09-30 12:07:13 +02:00
|
|
|
FIXME( "ET_MEDIATYPE: 0x%08x\n", rec->dwMediaType );
|
2006-03-07 16:50:17 +01:00
|
|
|
}
|
|
|
|
if (rec->dwFields & ET_DITHERMODE)
|
|
|
|
{
|
2006-09-30 12:07:13 +02:00
|
|
|
FIXME( "ET_DITHERMODE: 0x%08x\n", rec->dwDitheringMode );
|
2006-03-07 16:50:17 +01:00
|
|
|
}
|
|
|
|
if (rec->dwFields & ET_RESOLUTION)
|
|
|
|
{
|
2006-09-30 12:07:13 +02:00
|
|
|
FIXME( "ET_RESOLUTION: 0x%08x, 0x%08x\n",
|
2006-03-07 16:50:17 +01:00
|
|
|
rec->dwResolution[0], rec->dwResolution[1] );
|
|
|
|
}
|
|
|
|
if (rec->dwFields & ET_DEVICECLASS)
|
|
|
|
{
|
|
|
|
FIXME( "ET_DEVICECLASS: %s\n", MSCMS_dbgstr_tag(rec->dwMediaType) );
|
|
|
|
}
|
|
|
|
if (rec->dwFields & ET_CMMTYPE)
|
|
|
|
{
|
|
|
|
TRACE( "ET_CMMTYPE: %s\n", MSCMS_dbgstr_tag(rec->dwCMMType) );
|
|
|
|
if (rec->dwCMMType != hdr->phCMMType) return FALSE;
|
|
|
|
}
|
|
|
|
if (rec->dwFields & ET_CLASS)
|
|
|
|
{
|
|
|
|
TRACE( "ET_CLASS: %s\n", MSCMS_dbgstr_tag(rec->dwClass) );
|
|
|
|
if (rec->dwClass != hdr->phClass) return FALSE;
|
|
|
|
}
|
|
|
|
if (rec->dwFields & ET_DATACOLORSPACE)
|
|
|
|
{
|
|
|
|
TRACE( "ET_DATACOLORSPACE: %s\n", MSCMS_dbgstr_tag(rec->dwDataColorSpace) );
|
|
|
|
if (rec->dwDataColorSpace != hdr->phDataColorSpace) return FALSE;
|
|
|
|
}
|
|
|
|
if (rec->dwFields & ET_CONNECTIONSPACE)
|
|
|
|
{
|
|
|
|
TRACE( "ET_CONNECTIONSPACE: %s\n", MSCMS_dbgstr_tag(rec->dwConnectionSpace) );
|
|
|
|
if (rec->dwConnectionSpace != hdr->phConnectionSpace) return FALSE;
|
|
|
|
}
|
|
|
|
if (rec->dwFields & ET_SIGNATURE)
|
|
|
|
{
|
|
|
|
TRACE( "ET_SIGNATURE: %s\n", MSCMS_dbgstr_tag(rec->dwSignature) );
|
|
|
|
if (rec->dwSignature != hdr->phSignature) return FALSE;
|
|
|
|
}
|
|
|
|
if (rec->dwFields & ET_PLATFORM)
|
|
|
|
{
|
|
|
|
TRACE( "ET_PLATFORM: %s\n", MSCMS_dbgstr_tag(rec->dwPlatform) );
|
|
|
|
if (rec->dwPlatform != hdr->phPlatform) return FALSE;
|
|
|
|
}
|
|
|
|
if (rec->dwFields & ET_PROFILEFLAGS)
|
|
|
|
{
|
2006-09-30 12:07:13 +02:00
|
|
|
TRACE( "ET_PROFILEFLAGS: 0x%08x\n", rec->dwProfileFlags );
|
2006-03-07 16:50:17 +01:00
|
|
|
if (rec->dwProfileFlags != hdr->phProfileFlags) return FALSE;
|
|
|
|
}
|
|
|
|
if (rec->dwFields & ET_MANUFACTURER)
|
|
|
|
{
|
|
|
|
TRACE( "ET_MANUFACTURER: %s\n", MSCMS_dbgstr_tag(rec->dwManufacturer) );
|
|
|
|
if (rec->dwManufacturer != hdr->phManufacturer) return FALSE;
|
|
|
|
}
|
|
|
|
if (rec->dwFields & ET_MODEL)
|
|
|
|
{
|
|
|
|
TRACE( "ET_MODEL: %s\n", MSCMS_dbgstr_tag(rec->dwModel) );
|
|
|
|
if (rec->dwModel != hdr->phModel) return FALSE;
|
|
|
|
}
|
|
|
|
if (rec->dwFields & ET_ATTRIBUTES)
|
|
|
|
{
|
2006-09-30 12:07:13 +02:00
|
|
|
TRACE( "ET_ATTRIBUTES: 0x%08x, 0x%08x\n",
|
2006-03-07 16:50:17 +01:00
|
|
|
rec->dwAttributes[0], rec->dwAttributes[1] );
|
|
|
|
if (rec->dwAttributes[0] != hdr->phAttributes[0] ||
|
|
|
|
rec->dwAttributes[1] != hdr->phAttributes[1]) return FALSE;
|
|
|
|
}
|
|
|
|
if (rec->dwFields & ET_RENDERINGINTENT)
|
|
|
|
{
|
2006-09-30 12:07:13 +02:00
|
|
|
TRACE( "ET_RENDERINGINTENT: 0x%08x\n", rec->dwRenderingIntent );
|
2006-03-07 16:50:17 +01:00
|
|
|
if (rec->dwRenderingIntent != hdr->phRenderingIntent) return FALSE;
|
|
|
|
}
|
|
|
|
if (rec->dwFields & ET_CREATOR)
|
|
|
|
{
|
|
|
|
TRACE( "ET_CREATOR: %s\n", MSCMS_dbgstr_tag(rec->dwCreator) );
|
|
|
|
if (rec->dwCreator != hdr->phCreator) return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* EnumColorProfilesA [MSCMS.@]
|
|
|
|
*
|
|
|
|
* See EnumColorProfilesW.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI EnumColorProfilesA( PCSTR machine, PENUMTYPEA record, PBYTE buffer,
|
|
|
|
PDWORD size, PDWORD number )
|
|
|
|
{
|
|
|
|
BOOL match, ret = FALSE;
|
2008-01-24 20:03:14 +01:00
|
|
|
char spec[] = "\\*.icm";
|
2006-03-07 16:50:17 +01:00
|
|
|
char colordir[MAX_PATH], glob[MAX_PATH], **profiles = NULL;
|
|
|
|
DWORD i, len = sizeof(colordir), count = 0, totalsize = 0;
|
|
|
|
PROFILEHEADER header;
|
|
|
|
WIN32_FIND_DATAA data;
|
|
|
|
ENUMTYPEW recordW;
|
2006-10-05 15:36:13 +02:00
|
|
|
WCHAR *fileW = NULL, *deviceW = NULL;
|
2006-03-07 16:50:17 +01:00
|
|
|
HANDLE find;
|
|
|
|
|
|
|
|
TRACE( "( %p, %p, %p, %p, %p )\n", machine, record, buffer, size, number );
|
|
|
|
|
|
|
|
if (machine || !record || !size ||
|
|
|
|
record->dwSize != sizeof(ENUMTYPEA) ||
|
|
|
|
record->dwVersion != ENUM_TYPE_VERSION) return FALSE;
|
|
|
|
|
|
|
|
ret = GetColorDirectoryA( machine, colordir, &len );
|
|
|
|
if (!ret || len + sizeof(spec) > MAX_PATH)
|
|
|
|
{
|
|
|
|
WARN( "can't retrieve color directory\n" );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
lstrcpyA( glob, colordir );
|
|
|
|
lstrcatA( glob, spec );
|
|
|
|
|
|
|
|
find = FindFirstFileA( glob, &data );
|
|
|
|
if (find == INVALID_HANDLE_VALUE) return FALSE;
|
|
|
|
|
|
|
|
profiles = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(char *) + 1 );
|
|
|
|
if (!profiles) goto exit;
|
|
|
|
|
|
|
|
memcpy( &recordW, record, sizeof(ENUMTYPEA) );
|
|
|
|
if (record->pDeviceName)
|
|
|
|
{
|
2006-10-05 15:36:13 +02:00
|
|
|
deviceW = MSCMS_strdupW( record->pDeviceName );
|
|
|
|
if (!(recordW.pDeviceName = deviceW)) goto exit;
|
2006-03-07 16:50:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fileW = MSCMS_strdupW( data.cFileName );
|
|
|
|
if (!fileW) goto exit;
|
|
|
|
|
|
|
|
ret = MSCMS_header_from_file( fileW, &header );
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
match = MSCMS_match_profile( &recordW, &header );
|
|
|
|
if (match)
|
|
|
|
{
|
|
|
|
len = sizeof(char) * (lstrlenA( data.cFileName ) + 1);
|
|
|
|
profiles[count] = HeapAlloc( GetProcessHeap(), 0, len );
|
|
|
|
|
|
|
|
if (!profiles[count]) goto exit;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE( "matching profile: %s\n", debugstr_a(data.cFileName) );
|
|
|
|
lstrcpyA( profiles[count], data.cFileName );
|
|
|
|
totalsize += len;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HeapFree( GetProcessHeap(), 0, fileW );
|
|
|
|
fileW = NULL;
|
|
|
|
|
|
|
|
while (FindNextFileA( find, &data ))
|
|
|
|
{
|
|
|
|
fileW = MSCMS_strdupW( data.cFileName );
|
|
|
|
if (!fileW) goto exit;
|
|
|
|
|
|
|
|
ret = MSCMS_header_from_file( fileW, &header );
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, fileW );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
match = MSCMS_match_profile( &recordW, &header );
|
|
|
|
if (match)
|
|
|
|
{
|
|
|
|
char **tmp = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
profiles, sizeof(char *) * (count + 1) );
|
|
|
|
if (!tmp) goto exit;
|
|
|
|
else profiles = tmp;
|
|
|
|
|
|
|
|
len = sizeof(char) * (lstrlenA( data.cFileName ) + 1);
|
|
|
|
profiles[count] = HeapAlloc( GetProcessHeap(), 0, len );
|
|
|
|
|
|
|
|
if (!profiles[count]) goto exit;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE( "matching profile: %s\n", debugstr_a(data.cFileName) );
|
|
|
|
lstrcpyA( profiles[count], data.cFileName );
|
|
|
|
totalsize += len;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HeapFree( GetProcessHeap(), 0, fileW );
|
|
|
|
fileW = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
totalsize++;
|
|
|
|
if (buffer && *size >= totalsize)
|
|
|
|
{
|
|
|
|
char *p = (char *)buffer;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
lstrcpyA( p, profiles[i] );
|
|
|
|
p += lstrlenA( profiles[i] ) + 1;
|
|
|
|
}
|
|
|
|
*p = 0;
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
else ret = FALSE;
|
|
|
|
|
|
|
|
*size = totalsize;
|
|
|
|
if (number) *number = count;
|
|
|
|
|
|
|
|
exit:
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
HeapFree( GetProcessHeap(), 0, profiles[i] );
|
|
|
|
HeapFree( GetProcessHeap(), 0, profiles );
|
2006-10-05 15:36:13 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, deviceW );
|
2006-03-07 16:50:17 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, fileW );
|
|
|
|
FindClose( find );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* EnumColorProfilesW [MSCMS.@]
|
|
|
|
*
|
|
|
|
* Enumerate profiles that match given criteria.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* machine [I] Name of the machine for which to enumerate profiles.
|
|
|
|
* Must be NULL, which indicates the local machine.
|
|
|
|
* record [I] Record of criteria that a profile must match.
|
|
|
|
* buffer [O] Buffer to receive a string array of profile filenames.
|
|
|
|
* size [I/O] Size of the filename buffer in bytes.
|
|
|
|
* number [O] Number of filenames copied into buffer.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
|
|
|
BOOL WINAPI EnumColorProfilesW( PCWSTR machine, PENUMTYPEW record, PBYTE buffer,
|
|
|
|
PDWORD size, PDWORD number )
|
|
|
|
{
|
|
|
|
BOOL match, ret = FALSE;
|
2008-01-24 20:03:14 +01:00
|
|
|
WCHAR spec[] = {'\\','*','i','c','m',0};
|
2006-03-07 16:50:17 +01:00
|
|
|
WCHAR colordir[MAX_PATH], glob[MAX_PATH], **profiles = NULL;
|
|
|
|
DWORD i, len = sizeof(colordir), count = 0, totalsize = 0;
|
|
|
|
PROFILEHEADER header;
|
|
|
|
WIN32_FIND_DATAW data;
|
|
|
|
HANDLE find;
|
|
|
|
|
|
|
|
TRACE( "( %p, %p, %p, %p, %p )\n", machine, record, buffer, size, number );
|
|
|
|
|
|
|
|
if (machine || !record || !size ||
|
|
|
|
record->dwSize != sizeof(ENUMTYPEW) ||
|
|
|
|
record->dwVersion != ENUM_TYPE_VERSION) return FALSE;
|
|
|
|
|
|
|
|
ret = GetColorDirectoryW( machine, colordir, &len );
|
|
|
|
if (!ret || len + sizeof(spec) > MAX_PATH)
|
|
|
|
{
|
|
|
|
WARN( "Can't retrieve color directory\n" );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
lstrcpyW( glob, colordir );
|
|
|
|
lstrcatW( glob, spec );
|
|
|
|
|
|
|
|
find = FindFirstFileW( glob, &data );
|
|
|
|
if (find == INVALID_HANDLE_VALUE) return FALSE;
|
|
|
|
|
|
|
|
profiles = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR *) + 1 );
|
|
|
|
if (!profiles) goto exit;
|
|
|
|
|
|
|
|
ret = MSCMS_header_from_file( data.cFileName, &header );
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
match = MSCMS_match_profile( record, &header );
|
|
|
|
if (match)
|
|
|
|
{
|
|
|
|
len = sizeof(WCHAR) * (lstrlenW( data.cFileName ) + 1);
|
|
|
|
profiles[count] = HeapAlloc( GetProcessHeap(), 0, len );
|
|
|
|
|
|
|
|
if (!profiles[count]) goto exit;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE( "matching profile: %s\n", debugstr_w(data.cFileName) );
|
|
|
|
lstrcpyW( profiles[count], data.cFileName );
|
|
|
|
totalsize += len;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (FindNextFileW( find, &data ))
|
|
|
|
{
|
|
|
|
ret = MSCMS_header_from_file( data.cFileName, &header );
|
|
|
|
if (!ret) continue;
|
|
|
|
|
|
|
|
match = MSCMS_match_profile( record, &header );
|
|
|
|
if (match)
|
|
|
|
{
|
|
|
|
WCHAR **tmp = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
profiles, sizeof(WCHAR *) * (count + 1) );
|
|
|
|
if (!tmp) goto exit;
|
|
|
|
else profiles = tmp;
|
|
|
|
|
|
|
|
len = sizeof(WCHAR) * (lstrlenW( data.cFileName ) + 1);
|
|
|
|
profiles[count] = HeapAlloc( GetProcessHeap(), 0, len );
|
|
|
|
|
|
|
|
if (!profiles[count]) goto exit;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE( "matching profile: %s\n", debugstr_w(data.cFileName) );
|
|
|
|
lstrcpyW( profiles[count], data.cFileName );
|
|
|
|
totalsize += len;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
totalsize++;
|
|
|
|
if (buffer && *size >= totalsize)
|
|
|
|
{
|
|
|
|
WCHAR *p = (WCHAR *)buffer;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
lstrcpyW( p, profiles[i] );
|
|
|
|
p += lstrlenW( profiles[i] ) + 1;
|
|
|
|
}
|
|
|
|
*p = 0;
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
else ret = FALSE;
|
|
|
|
|
|
|
|
*size = totalsize;
|
|
|
|
if (number) *number = count;
|
|
|
|
|
|
|
|
exit:
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
HeapFree( GetProcessHeap(), 0, profiles[i] );
|
|
|
|
HeapFree( GetProcessHeap(), 0, profiles );
|
|
|
|
FindClose( find );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-11-19 19:22:20 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* InstallColorProfileA [MSCMS.@]
|
|
|
|
*
|
|
|
|
* See InstallColorProfileW.
|
|
|
|
*/
|
2004-10-07 21:12:41 +02:00
|
|
|
BOOL WINAPI InstallColorProfileA( PCSTR machine, PCSTR profile )
|
|
|
|
{
|
|
|
|
UINT len;
|
|
|
|
LPWSTR profileW;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
TRACE( "( %s )\n", debugstr_a(profile) );
|
|
|
|
|
|
|
|
if (machine || !profile) return FALSE;
|
|
|
|
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, profile, -1, NULL, 0 );
|
|
|
|
profileW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
|
|
|
|
|
|
|
if (profileW)
|
|
|
|
{
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, profile, -1, profileW, len );
|
|
|
|
|
|
|
|
ret = InstallColorProfileW( NULL, profileW );
|
|
|
|
HeapFree( GetProcessHeap(), 0, profileW );
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-11-19 19:22:20 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* InstallColorProfileW [MSCMS.@]
|
|
|
|
*
|
|
|
|
* Install a color profile.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* machine [I] Name of the machine to install the profile on. Must be NULL,
|
|
|
|
* which indicates the local machine.
|
|
|
|
* profile [I] Full path name of the profile to install.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
2004-10-07 21:12:41 +02:00
|
|
|
BOOL WINAPI InstallColorProfileW( PCWSTR machine, PCWSTR profile )
|
|
|
|
{
|
2004-11-03 23:14:25 +01:00
|
|
|
WCHAR dest[MAX_PATH], base[MAX_PATH];
|
|
|
|
DWORD size = sizeof(dest);
|
|
|
|
static const WCHAR slash[] = { '\\', 0 };
|
|
|
|
|
|
|
|
TRACE( "( %s )\n", debugstr_w(profile) );
|
2004-10-07 21:12:41 +02:00
|
|
|
|
|
|
|
if (machine || !profile) return FALSE;
|
|
|
|
|
2004-11-03 23:14:25 +01:00
|
|
|
if (!GetColorDirectoryW( machine, dest, &size )) return FALSE;
|
|
|
|
|
|
|
|
MSCMS_basename( profile, base );
|
|
|
|
|
|
|
|
lstrcatW( dest, slash );
|
|
|
|
lstrcatW( dest, base );
|
|
|
|
|
|
|
|
/* Is source equal to destination? */
|
|
|
|
if (!lstrcmpW( profile, dest )) return TRUE;
|
|
|
|
|
|
|
|
return CopyFileW( profile, dest, TRUE );
|
2004-10-07 21:12:41 +02:00
|
|
|
}
|
|
|
|
|
2004-11-21 16:48:18 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* IsColorProfileTagPresent [MSCMS.@]
|
|
|
|
*
|
2004-12-13 14:23:17 +01:00
|
|
|
* Determine if a given ICC tag type is present in a color profile.
|
2004-11-21 16:48:18 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* profile [I] Color profile handle.
|
2004-12-13 14:23:17 +01:00
|
|
|
* tag [I] ICC tag type.
|
|
|
|
* present [O] Pointer to a BOOL variable. Set to TRUE if tag type is present,
|
2004-11-21 16:48:18 +01:00
|
|
|
* FALSE otherwise.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
2008-03-24 21:33:06 +01:00
|
|
|
BOOL WINAPI IsColorProfileTagPresent( HPROFILE handle, TAGTYPE type, PBOOL present )
|
2004-11-21 16:48:18 +01:00
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
2005-07-18 17:10:36 +02:00
|
|
|
#ifdef HAVE_LCMS
|
2008-03-24 21:33:06 +01:00
|
|
|
struct profile *profile = grab_profile( handle );
|
2005-02-21 19:38:15 +01:00
|
|
|
DWORD i, count;
|
|
|
|
icTag tag;
|
2004-11-21 16:48:18 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
TRACE( "( %p, 0x%08x, %p )\n", handle, type, present );
|
2004-11-21 16:48:18 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
if (!profile) return FALSE;
|
2005-02-21 19:38:15 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
if (!present)
|
|
|
|
{
|
|
|
|
release_profile( profile );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
count = MSCMS_get_tag_count( profile->iccprofile );
|
2005-02-21 19:38:15 +01:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2008-03-24 21:33:06 +01:00
|
|
|
MSCMS_get_tag_by_index( profile->iccprofile, i, &tag );
|
2005-02-21 19:38:15 +01:00
|
|
|
|
|
|
|
if (tag.sig == type)
|
|
|
|
{
|
|
|
|
*present = ret = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-03-24 21:33:06 +01:00
|
|
|
release_profile( profile );
|
2004-11-21 16:48:18 +01:00
|
|
|
|
2005-07-18 17:10:36 +02:00
|
|
|
#endif /* HAVE_LCMS */
|
2005-02-21 19:38:15 +01:00
|
|
|
return ret;
|
2004-11-21 16:48:18 +01:00
|
|
|
}
|
|
|
|
|
2004-11-19 19:22:20 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* IsColorProfileValid [MSCMS.@]
|
|
|
|
*
|
|
|
|
* Determine if a given color profile is valid.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* profile [I] Color profile handle.
|
|
|
|
* valid [O] Pointer to a BOOL variable. Set to TRUE if profile is valid,
|
|
|
|
* FALSE otherwise.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
2008-03-24 21:33:06 +01:00
|
|
|
BOOL WINAPI IsColorProfileValid( HPROFILE handle, PBOOL valid )
|
2004-11-19 19:22:20 +01:00
|
|
|
{
|
2004-11-30 22:06:14 +01:00
|
|
|
BOOL ret = FALSE;
|
2005-07-18 17:10:36 +02:00
|
|
|
#ifdef HAVE_LCMS
|
2008-03-24 21:33:06 +01:00
|
|
|
struct profile *profile = grab_profile( handle );
|
|
|
|
|
|
|
|
TRACE( "( %p, %p )\n", handle, valid );
|
2004-11-30 22:06:14 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
if (!profile) return FALSE;
|
2004-11-19 19:22:20 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
if (!valid)
|
|
|
|
{
|
|
|
|
release_profile( profile );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (profile->iccprofile) ret = *valid = TRUE;
|
|
|
|
release_profile( profile );
|
2004-11-30 22:06:14 +01:00
|
|
|
|
2005-07-18 17:10:36 +02:00
|
|
|
#endif /* HAVE_LCMS */
|
2004-11-30 22:06:14 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-12-13 14:23:17 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* SetColorProfileElement [MSCMS.@]
|
|
|
|
*
|
|
|
|
* Set data for a specified tag type.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* profile [I] Handle to a color profile.
|
|
|
|
* type [I] ICC tag type.
|
|
|
|
* offset [I] Offset in bytes to start copying to.
|
|
|
|
* size [I/O] Size of the buffer in bytes. On return the variable holds the
|
|
|
|
* number of bytes actually needed.
|
|
|
|
* buffer [O] Buffer holding the tag data.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
2008-03-24 21:33:06 +01:00
|
|
|
BOOL WINAPI SetColorProfileElement( HPROFILE handle, TAGTYPE type, DWORD offset, PDWORD size,
|
2004-12-13 14:23:17 +01:00
|
|
|
PVOID buffer )
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
2005-07-18 17:10:36 +02:00
|
|
|
#ifdef HAVE_LCMS
|
2008-03-24 21:33:06 +01:00
|
|
|
struct profile *profile = grab_profile( handle );
|
|
|
|
DWORD i, count;
|
2004-12-13 14:23:17 +01:00
|
|
|
icTag tag;
|
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
TRACE( "( %p, 0x%08x, %d, %p, %p )\n", handle, type, offset, size, buffer );
|
2004-12-13 14:23:17 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
if (!profile) return FALSE;
|
2005-02-14 21:53:59 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
if (!size || !buffer || !(profile->access & PROFILE_READWRITE))
|
|
|
|
{
|
|
|
|
release_profile( profile );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
count = MSCMS_get_tag_count( profile->iccprofile );
|
2004-12-13 14:23:17 +01:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2008-03-24 21:33:06 +01:00
|
|
|
MSCMS_get_tag_by_index( profile->iccprofile, i, &tag );
|
2004-12-13 14:23:17 +01:00
|
|
|
|
|
|
|
if (tag.sig == type)
|
|
|
|
{
|
2008-03-24 21:33:06 +01:00
|
|
|
if (offset > tag.size)
|
|
|
|
{
|
|
|
|
release_profile( profile );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
MSCMS_set_tag_data( profile->iccprofile, &tag, offset, buffer );
|
2004-12-13 14:23:17 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
release_profile( profile );
|
2004-12-13 14:23:17 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2008-03-24 21:33:06 +01:00
|
|
|
release_profile( profile );
|
2004-12-13 14:23:17 +01:00
|
|
|
|
2005-07-18 17:10:36 +02:00
|
|
|
#endif /* HAVE_LCMS */
|
2004-12-13 14:23:17 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-03-09 19:42:52 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* SetColorProfileHeader [MSCMS.@]
|
|
|
|
*
|
|
|
|
* Set header data for a given profile.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* profile [I] Handle to a color profile.
|
|
|
|
* header [I] Buffer holding the header data.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
2008-03-24 21:33:06 +01:00
|
|
|
BOOL WINAPI SetColorProfileHeader( HPROFILE handle, PPROFILEHEADER header )
|
2004-11-30 22:06:14 +01:00
|
|
|
{
|
2005-07-18 17:10:36 +02:00
|
|
|
#ifdef HAVE_LCMS
|
2008-03-24 21:33:06 +01:00
|
|
|
struct profile *profile = grab_profile( handle );
|
2004-11-30 22:06:14 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
TRACE( "( %p, %p )\n", handle, header );
|
2004-11-30 22:06:14 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
if (!profile) return FALSE;
|
2004-11-30 22:06:14 +01:00
|
|
|
|
2008-03-24 21:33:06 +01:00
|
|
|
if (!header || !(profile->access & PROFILE_READWRITE))
|
|
|
|
{
|
|
|
|
release_profile( profile );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
MSCMS_set_profile_header( profile->iccprofile, header );
|
|
|
|
|
|
|
|
release_profile( profile );
|
2004-11-30 22:06:14 +01:00
|
|
|
return TRUE;
|
|
|
|
|
2007-07-24 22:29:05 +02:00
|
|
|
#else
|
|
|
|
return FALSE;
|
2005-07-18 17:10:36 +02:00
|
|
|
#endif /* HAVE_LCMS */
|
2004-11-19 19:22:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* UninstallColorProfileA [MSCMS.@]
|
|
|
|
*
|
|
|
|
* See UninstallColorProfileW.
|
|
|
|
*/
|
2004-10-07 21:12:41 +02:00
|
|
|
BOOL WINAPI UninstallColorProfileA( PCSTR machine, PCSTR profile, BOOL delete )
|
|
|
|
{
|
2004-11-03 23:14:25 +01:00
|
|
|
UINT len;
|
|
|
|
LPWSTR profileW;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
2004-11-19 19:22:20 +01:00
|
|
|
TRACE( "( %s, %x )\n", debugstr_a(profile), delete );
|
2004-11-03 23:14:25 +01:00
|
|
|
|
2004-10-07 21:12:41 +02:00
|
|
|
if (machine || !profile) return FALSE;
|
|
|
|
|
2004-11-03 23:14:25 +01:00
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, profile, -1, NULL, 0 );
|
|
|
|
profileW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
2004-10-07 21:12:41 +02:00
|
|
|
|
2004-11-03 23:14:25 +01:00
|
|
|
if (profileW)
|
|
|
|
{
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, profile, -1, profileW, len );
|
|
|
|
|
|
|
|
ret = UninstallColorProfileW( NULL, profileW , delete );
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, profileW );
|
|
|
|
}
|
|
|
|
return ret;
|
2004-10-07 21:12:41 +02:00
|
|
|
}
|
|
|
|
|
2004-11-19 19:22:20 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* UninstallColorProfileW [MSCMS.@]
|
|
|
|
*
|
|
|
|
* Uninstall a color profile.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* machine [I] Name of the machine to uninstall the profile on. Must be NULL,
|
|
|
|
* which indicates the local machine.
|
|
|
|
* profile [I] Full path name of the profile to uninstall.
|
|
|
|
* delete [I] Bool that specifies whether the profile file should be deleted.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
2004-10-07 21:12:41 +02:00
|
|
|
BOOL WINAPI UninstallColorProfileW( PCWSTR machine, PCWSTR profile, BOOL delete )
|
|
|
|
{
|
2004-11-19 19:22:20 +01:00
|
|
|
TRACE( "( %s, %x )\n", debugstr_w(profile), delete );
|
|
|
|
|
2004-10-07 21:12:41 +02:00
|
|
|
if (machine || !profile) return FALSE;
|
|
|
|
|
2004-11-30 22:06:14 +01:00
|
|
|
if (delete) return DeleteFileW( profile );
|
2004-10-07 21:12:41 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-11-19 19:22:20 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* OpenColorProfileA [MSCMS.@]
|
|
|
|
*
|
|
|
|
* See OpenColorProfileW.
|
|
|
|
*/
|
2004-10-07 21:12:41 +02:00
|
|
|
HPROFILE WINAPI OpenColorProfileA( PPROFILE profile, DWORD access, DWORD sharing, DWORD creation )
|
|
|
|
{
|
|
|
|
HPROFILE handle = NULL;
|
|
|
|
|
2006-09-30 12:07:13 +02:00
|
|
|
TRACE( "( %p, 0x%08x, 0x%08x, 0x%08x )\n", profile, access, sharing, creation );
|
2004-10-07 21:12:41 +02:00
|
|
|
|
|
|
|
if (!profile || !profile->pProfileData) return NULL;
|
|
|
|
|
|
|
|
/* No AW conversion needed for memory based profiles */
|
|
|
|
if (profile->dwType & PROFILE_MEMBUFFER)
|
|
|
|
return OpenColorProfileW( profile, access, sharing, creation );
|
|
|
|
|
|
|
|
if (profile->dwType & PROFILE_FILENAME)
|
|
|
|
{
|
|
|
|
UINT len;
|
|
|
|
PROFILE profileW;
|
|
|
|
|
|
|
|
profileW.dwType = profile->dwType;
|
|
|
|
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, profile->pProfileData, -1, NULL, 0 );
|
|
|
|
profileW.pProfileData = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
|
|
|
|
|
|
|
if (profileW.pProfileData)
|
|
|
|
{
|
|
|
|
profileW.cbDataSize = len * sizeof(WCHAR);
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, profile->pProfileData, -1, profileW.pProfileData, len );
|
|
|
|
|
|
|
|
handle = OpenColorProfileW( &profileW, access, sharing, creation );
|
|
|
|
HeapFree( GetProcessHeap(), 0, profileW.pProfileData );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* OpenColorProfileW [MSCMS.@]
|
|
|
|
*
|
|
|
|
* Open a color profile.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2004-11-19 19:22:20 +01:00
|
|
|
* profile [I] Pointer to a color profile structure.
|
|
|
|
* access [I] Desired access.
|
|
|
|
* sharing [I] Sharing mode.
|
|
|
|
* creation [I] Creation mode.
|
2004-10-07 21:12:41 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2004-11-19 19:22:20 +01:00
|
|
|
* Success: Handle to the opened profile.
|
2004-10-07 21:12:41 +02:00
|
|
|
* Failure: NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
2004-11-19 19:22:20 +01:00
|
|
|
* Values for access: PROFILE_READ or PROFILE_READWRITE.
|
|
|
|
* Values for sharing: 0 (no sharing), FILE_SHARE_READ and/or FILE_SHARE_WRITE.
|
2004-10-07 21:12:41 +02:00
|
|
|
* Values for creation: one of CREATE_NEW, CREATE_ALWAYS, OPEN_EXISTING,
|
|
|
|
* OPEN_ALWAYS, TRUNCATE_EXISTING.
|
2004-11-30 22:06:14 +01:00
|
|
|
* Sharing and creation flags are ignored for memory based profiles.
|
2004-10-07 21:12:41 +02:00
|
|
|
*/
|
|
|
|
HPROFILE WINAPI OpenColorProfileW( PPROFILE profile, DWORD access, DWORD sharing, DWORD creation )
|
|
|
|
{
|
2005-07-18 17:10:36 +02:00
|
|
|
#ifdef HAVE_LCMS
|
2004-10-07 21:12:41 +02:00
|
|
|
cmsHPROFILE cmsprofile = NULL;
|
2004-11-30 22:06:14 +01:00
|
|
|
icProfile *iccprofile = NULL;
|
2008-02-28 11:21:52 +01:00
|
|
|
HANDLE handle = INVALID_HANDLE_VALUE;
|
2004-10-07 21:12:41 +02:00
|
|
|
|
2006-09-30 12:07:13 +02:00
|
|
|
TRACE( "( %p, 0x%08x, 0x%08x, 0x%08x )\n", profile, access, sharing, creation );
|
2004-10-07 21:12:41 +02:00
|
|
|
|
|
|
|
if (!profile || !profile->pProfileData) return NULL;
|
|
|
|
|
2008-02-28 11:21:52 +01:00
|
|
|
if (profile->dwType == PROFILE_MEMBUFFER)
|
2004-10-07 21:12:41 +02:00
|
|
|
{
|
2006-01-06 21:07:55 +01:00
|
|
|
/* FIXME: access flags not implemented for memory based profiles */
|
2004-11-30 22:06:14 +01:00
|
|
|
|
2008-02-29 15:36:04 +01:00
|
|
|
if (!(iccprofile = HeapAlloc( GetProcessHeap(), 0, profile->cbDataSize ))) return NULL;
|
|
|
|
memcpy( iccprofile, profile->pProfileData, profile->cbDataSize );
|
|
|
|
|
|
|
|
cmsprofile = cmsOpenProfileFromMem( iccprofile, profile->cbDataSize );
|
2004-10-07 21:12:41 +02:00
|
|
|
}
|
2008-02-28 11:21:52 +01:00
|
|
|
else if (profile->dwType == PROFILE_FILENAME)
|
2004-10-07 21:12:41 +02:00
|
|
|
{
|
2008-02-29 15:36:04 +01:00
|
|
|
DWORD size, read, flags = 0;
|
2004-10-07 21:12:41 +02:00
|
|
|
|
2009-01-17 22:55:25 +01:00
|
|
|
TRACE( "profile file: %s\n", debugstr_w( profile->pProfileData ) );
|
2004-10-07 21:12:41 +02:00
|
|
|
|
|
|
|
if (access & PROFILE_READ) flags = GENERIC_READ;
|
|
|
|
if (access & PROFILE_READWRITE) flags = GENERIC_READ|GENERIC_WRITE;
|
|
|
|
|
|
|
|
if (!flags) return NULL;
|
2008-02-22 16:19:51 +01:00
|
|
|
if (!sharing) sharing = FILE_SHARE_READ;
|
2004-10-07 21:12:41 +02:00
|
|
|
|
2011-09-20 11:31:13 +02:00
|
|
|
if (!PathIsRelativeW( profile->pProfileData ))
|
|
|
|
handle = CreateFileW( profile->pProfileData, flags, sharing, NULL, creation, 0, NULL );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
WCHAR *path;
|
|
|
|
|
|
|
|
if (!GetColorDirectoryW( NULL, NULL, &size ) && GetLastError() == ERROR_MORE_DATA)
|
|
|
|
{
|
|
|
|
size += (strlenW( profile->pProfileData ) + 2) * sizeof(WCHAR);
|
|
|
|
if (!(path = HeapAlloc( GetProcessHeap(), 0, size ))) return NULL;
|
|
|
|
GetColorDirectoryW( NULL, path, &size );
|
|
|
|
PathAddBackslashW( path );
|
|
|
|
strcatW( path, profile->pProfileData );
|
|
|
|
}
|
|
|
|
else return NULL;
|
|
|
|
handle = CreateFileW( path, flags, sharing, NULL, creation, 0, NULL );
|
|
|
|
HeapFree( GetProcessHeap(), 0, path );
|
|
|
|
}
|
2004-11-30 22:06:14 +01:00
|
|
|
if (handle == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2008-02-22 16:19:51 +01:00
|
|
|
WARN( "Unable to open color profile %u\n", GetLastError() );
|
2004-11-30 22:06:14 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-10-07 21:12:41 +02:00
|
|
|
|
2004-11-30 22:06:14 +01:00
|
|
|
if ((size = GetFileSize( handle, NULL )) == INVALID_FILE_SIZE)
|
|
|
|
{
|
|
|
|
ERR( "Unable to retrieve size of color profile\n" );
|
|
|
|
CloseHandle( handle );
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-10-07 21:12:41 +02:00
|
|
|
|
2005-03-24 22:01:35 +01:00
|
|
|
iccprofile = HeapAlloc( GetProcessHeap(), 0, size );
|
2004-11-30 22:06:14 +01:00
|
|
|
if (!iccprofile)
|
2004-10-07 21:12:41 +02:00
|
|
|
{
|
2004-11-30 22:06:14 +01:00
|
|
|
ERR( "Unable to allocate memory for color profile\n" );
|
|
|
|
CloseHandle( handle );
|
|
|
|
return NULL;
|
2004-10-07 21:12:41 +02:00
|
|
|
}
|
2004-11-30 22:06:14 +01:00
|
|
|
|
|
|
|
if (!ReadFile( handle, iccprofile, size, &read, NULL ) || read != size)
|
|
|
|
{
|
|
|
|
ERR( "Unable to read color profile\n" );
|
|
|
|
|
|
|
|
CloseHandle( handle );
|
2006-06-19 16:17:06 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, iccprofile );
|
2004-11-30 22:06:14 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmsprofile = cmsOpenProfileFromMem( iccprofile, size );
|
2004-10-07 21:12:41 +02:00
|
|
|
}
|
2008-02-28 11:21:52 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR( "Invalid profile type %u\n", profile->dwType );
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-10-07 21:12:41 +02:00
|
|
|
|
2004-11-30 22:06:14 +01:00
|
|
|
if (cmsprofile)
|
2008-03-24 21:33:06 +01:00
|
|
|
{
|
|
|
|
struct profile profile;
|
|
|
|
|
|
|
|
profile.file = handle;
|
|
|
|
profile.access = access;
|
|
|
|
profile.iccprofile = iccprofile;
|
|
|
|
profile.cmsprofile = cmsprofile;
|
|
|
|
|
|
|
|
return create_profile( &profile );
|
|
|
|
}
|
2004-10-07 21:12:41 +02:00
|
|
|
|
2005-07-18 17:10:36 +02:00
|
|
|
#endif /* HAVE_LCMS */
|
2004-10-07 21:12:41 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-10-08 23:02:22 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* CloseColorProfile [MSCMS.@]
|
|
|
|
*
|
|
|
|
* Close a color profile.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2004-11-19 19:22:20 +01:00
|
|
|
* profile [I] Handle to the profile.
|
2004-10-08 23:02:22 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
2004-10-07 21:12:41 +02:00
|
|
|
BOOL WINAPI CloseColorProfile( HPROFILE profile )
|
|
|
|
{
|
2004-11-30 22:06:14 +01:00
|
|
|
BOOL ret = FALSE;
|
2005-07-18 17:10:36 +02:00
|
|
|
#ifdef HAVE_LCMS
|
2004-10-07 21:12:41 +02:00
|
|
|
|
|
|
|
TRACE( "( %p )\n", profile );
|
2008-03-24 21:33:06 +01:00
|
|
|
ret = close_profile( profile );
|
2004-10-07 21:12:41 +02:00
|
|
|
|
2005-07-18 17:10:36 +02:00
|
|
|
#endif /* HAVE_LCMS */
|
2004-11-30 22:06:14 +01:00
|
|
|
return ret;
|
2004-10-07 21:12:41 +02:00
|
|
|
}
|