2 * MSCMS - Color Management System for Wine
4 * Copyright 2004, 2005, 2006, 2008 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define WIN32_NO_STATUS
24 #include <wine/debug.h>
25 #include <wine/unicode.h>
30 //#include "winbase.h"
35 //#include "shlwapi.h"
38 //#include "mscms_priv.h"
40 static void basename( LPCWSTR path
, LPWSTR name
)
42 INT i
= lstrlenW( path
);
44 while (i
> 0 && path
[i
- 1] != '\\' && path
[i
- 1] != '/') i
--;
45 lstrcpyW( name
, &path
[i
] );
48 static inline LPWSTR
strdupW( LPCSTR str
)
53 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
54 if ((ret
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
55 MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
60 const char *dbgstr_tag( DWORD tag
)
62 return wine_dbg_sprintf( "'%c%c%c%c'",
63 (char)(tag
>> 24), (char)(tag
>> 16), (char)(tag
>> 8), (char)(tag
) );
66 WINE_DEFAULT_DEBUG_CHANNEL(mscms
);
68 /******************************************************************************
69 * AssociateColorProfileWithDeviceA [MSCMS.@]
71 BOOL WINAPI
AssociateColorProfileWithDeviceA( PCSTR machine
, PCSTR profile
, PCSTR device
)
75 WCHAR
*profileW
, *deviceW
;
77 TRACE( "( %s, %s, %s )\n", debugstr_a(machine
), debugstr_a(profile
), debugstr_a(device
) );
79 if (!profile
|| !device
)
81 SetLastError( ERROR_INVALID_PARAMETER
);
86 SetLastError( ERROR_NOT_SUPPORTED
);
90 len
= MultiByteToWideChar( CP_ACP
, 0, profile
, -1, NULL
, 0 );
91 if (!(profileW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return FALSE
;
93 MultiByteToWideChar( CP_ACP
, 0, profile
, -1, profileW
, len
);
95 len
= MultiByteToWideChar( CP_ACP
, 0, device
, -1, NULL
, 0 );
96 if ((deviceW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
98 MultiByteToWideChar( CP_ACP
, 0, device
, -1, deviceW
, len
);
99 ret
= AssociateColorProfileWithDeviceW( NULL
, profileW
, deviceW
);
102 HeapFree( GetProcessHeap(), 0, profileW
);
103 HeapFree( GetProcessHeap(), 0, deviceW
);
107 static BOOL
set_profile_device_key( PCWSTR file
, const BYTE
*value
, DWORD size
)
109 static const WCHAR fmtW
[] = {'%','c','%','c','%','c','%','c',0};
110 static const WCHAR icmW
[] = {'S','o','f','t','w','a','r','e','\\',
111 'M','i','c','r','o','s','o','f','t','\\',
112 'W','i','n','d','o','w','s',' ','N','T','\\',
113 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
115 PROFILEHEADER header
;
118 HKEY icm_key
, class_key
;
119 WCHAR basenameW
[MAX_PATH
], classW
[5];
121 profile
.dwType
= PROFILE_FILENAME
;
122 profile
.pProfileData
= (PVOID
)file
;
123 profile
.cbDataSize
= (lstrlenW( file
) + 1) * sizeof(WCHAR
);
125 /* FIXME is the profile installed? */
126 if (!(handle
= OpenColorProfileW( &profile
, PROFILE_READ
, 0, OPEN_EXISTING
)))
128 SetLastError( ERROR_INVALID_PROFILE
);
131 if (!GetColorProfileHeader( handle
, &header
))
133 CloseColorProfile( handle
);
134 SetLastError( ERROR_INVALID_PROFILE
);
137 RegCreateKeyExW( HKEY_LOCAL_MACHINE
, icmW
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &icm_key
, NULL
);
139 basename( file
, basenameW
);
140 sprintfW( classW
, fmtW
, (header
.phClass
>> 24) & 0xff, (header
.phClass
>> 16) & 0xff,
141 (header
.phClass
>> 8) & 0xff, header
.phClass
& 0xff );
143 RegCreateKeyExW( icm_key
, classW
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &class_key
, NULL
);
144 if (value
) RegSetValueExW( class_key
, basenameW
, 0, REG_BINARY
, value
, size
);
145 else RegDeleteValueW( class_key
, basenameW
);
147 RegCloseKey( class_key
);
148 RegCloseKey( icm_key
);
149 CloseColorProfile( handle
);
153 /******************************************************************************
154 * AssociateColorProfileWithDeviceW [MSCMS.@]
156 BOOL WINAPI
AssociateColorProfileWithDeviceW( PCWSTR machine
, PCWSTR profile
, PCWSTR device
)
158 static const BYTE dummy_value
[12];
160 TRACE( "( %s, %s, %s )\n", debugstr_w(machine
), debugstr_w(profile
), debugstr_w(device
) );
162 if (!profile
|| !device
)
164 SetLastError( ERROR_INVALID_PARAMETER
);
169 SetLastError( ERROR_NOT_SUPPORTED
);
173 return set_profile_device_key( profile
, dummy_value
, sizeof(dummy_value
) );
176 /******************************************************************************
177 * DisassociateColorProfileFromDeviceA [MSCMS.@]
179 BOOL WINAPI
DisassociateColorProfileFromDeviceA( PCSTR machine
, PCSTR profile
, PCSTR device
)
183 WCHAR
*profileW
, *deviceW
;
185 TRACE( "( %s, %s, %s )\n", debugstr_a(machine
), debugstr_a(profile
), debugstr_a(device
) );
187 if (!profile
|| !device
)
189 SetLastError( ERROR_INVALID_PARAMETER
);
194 SetLastError( ERROR_NOT_SUPPORTED
);
198 len
= MultiByteToWideChar( CP_ACP
, 0, profile
, -1, NULL
, 0 );
199 if (!(profileW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return FALSE
;
201 MultiByteToWideChar( CP_ACP
, 0, profile
, -1, profileW
, len
);
203 len
= MultiByteToWideChar( CP_ACP
, 0, device
, -1, NULL
, 0 );
204 if ((deviceW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
206 MultiByteToWideChar( CP_ACP
, 0, device
, -1, deviceW
, len
);
207 ret
= DisassociateColorProfileFromDeviceW( NULL
, profileW
, deviceW
);
210 HeapFree( GetProcessHeap(), 0, profileW
);
211 HeapFree( GetProcessHeap(), 0, deviceW
);
215 /******************************************************************************
216 * DisassociateColorProfileFromDeviceW [MSCMS.@]
218 BOOL WINAPI
DisassociateColorProfileFromDeviceW( PCWSTR machine
, PCWSTR profile
, PCWSTR device
)
220 TRACE( "( %s, %s, %s )\n", debugstr_w(machine
), debugstr_w(profile
), debugstr_w(device
) );
222 if (!profile
|| !device
)
224 SetLastError( ERROR_INVALID_PARAMETER
);
229 SetLastError( ERROR_NOT_SUPPORTED
);
233 return set_profile_device_key( profile
, NULL
, 0 );
236 /******************************************************************************
237 * GetColorDirectoryA [MSCMS.@]
239 * See GetColorDirectoryW.
241 BOOL WINAPI
GetColorDirectoryA( PCSTR machine
, PSTR buffer
, PDWORD size
)
248 TRACE( "( %p, %p )\n", buffer
, size
);
250 if (machine
|| !size
) return FALSE
;
254 ret
= GetColorDirectoryW( NULL
, NULL
, &sizeW
);
255 *size
= sizeW
/ sizeof(WCHAR
);
259 sizeW
= *size
* sizeof(WCHAR
);
261 bufferW
= HeapAlloc( GetProcessHeap(), 0, sizeW
);
264 if ((ret
= GetColorDirectoryW( NULL
, bufferW
, &sizeW
)))
266 *size
= WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
267 len
= WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, buffer
, *size
, NULL
, NULL
);
268 if (!len
) ret
= FALSE
;
270 else *size
= sizeW
/ sizeof(WCHAR
);
272 HeapFree( GetProcessHeap(), 0, bufferW
);
277 /******************************************************************************
278 * GetColorDirectoryW [MSCMS.@]
280 * Get the directory where color profiles are stored.
283 * machine [I] Name of the machine for which to get the color directory.
284 * Must be NULL, which indicates the local machine.
285 * buffer [I] Buffer to receive the path name.
286 * size [I/O] Size of the buffer in bytes. On return the variable holds
287 * the number of bytes actually needed.
289 BOOL WINAPI
GetColorDirectoryW( PCWSTR machine
, PWSTR buffer
, PDWORD size
)
291 WCHAR colordir
[MAX_PATH
];
292 static const WCHAR colorsubdir
[] =
293 {'\\','s','p','o','o','l','\\','d','r','i','v','e','r','s','\\','c','o','l','o','r',0};
296 TRACE( "( %p, %p )\n", buffer
, size
);
298 if (machine
|| !size
) return FALSE
;
300 GetSystemDirectoryW( colordir
, sizeof(colordir
) / sizeof(WCHAR
) );
301 lstrcatW( colordir
, colorsubdir
);
303 len
= lstrlenW( colordir
) * sizeof(WCHAR
);
305 if (buffer
&& len
<= *size
)
307 lstrcpyW( buffer
, colordir
);
312 SetLastError( ERROR_MORE_DATA
);
317 /******************************************************************************
318 * GetColorProfileElement [MSCMS.@]
320 * Retrieve data for a specified tag type.
323 * profile [I] Handle to a color profile.
324 * type [I] ICC tag type.
325 * offset [I] Offset in bytes to start copying from.
326 * size [I/O] Size of the buffer in bytes. On return the variable holds
327 * the number of bytes actually needed.
328 * buffer [O] Buffer to receive the tag data.
329 * ref [O] Pointer to a BOOL that specifies whether more than one tag
330 * references the data.
336 BOOL WINAPI
GetColorProfileElement( HPROFILE handle
, TAGTYPE type
, DWORD offset
, PDWORD size
,
337 PVOID buffer
, PBOOL ref
)
341 struct profile
*profile
= grab_profile( handle
);
343 TRACE( "( %p, 0x%08x, %d, %p, %p, %p )\n", handle
, type
, offset
, size
, buffer
, ref
);
345 if (!profile
) return FALSE
;
349 release_profile( profile
);
352 if (!get_tag_data( profile
, type
, offset
, buffer
, size
))
354 release_profile( profile
);
357 ret
= get_tag_data( profile
, type
, offset
, buffer
, size
);
358 *ref
= cmsTagLinkedTo( profile
->cmsprofile
, type
) != 0;
359 release_profile( profile
);
362 #endif /* HAVE_LCMS2 */
366 /******************************************************************************
367 * GetColorProfileElementTag [MSCMS.@]
369 * Get the tag type from a color profile by index.
372 * profile [I] Handle to a color profile.
373 * index [I] Index into the tag table of the color profile.
374 * type [O] Pointer to a variable that holds the ICC tag type on return.
381 * The tag table index starts at 1.
382 * Use GetCountColorProfileElements to retrieve a count of tagged elements.
384 BOOL WINAPI
GetColorProfileElementTag( HPROFILE handle
, DWORD index
, PTAGTYPE type
)
388 struct profile
*profile
= grab_profile( handle
);
389 cmsInt32Number num_tags
;
392 TRACE( "( %p, %d, %p )\n", handle
, index
, type
);
394 if (!profile
) return FALSE
;
398 release_profile( profile
);
401 num_tags
= cmsGetTagCount( profile
->cmsprofile
);
402 if (num_tags
< 0 || index
> num_tags
|| index
< 1)
404 release_profile( profile
);
407 if ((sig
= cmsGetTagSignature( profile
->cmsprofile
, index
- 1 )))
412 release_profile( profile
);
414 #endif /* HAVE_LCMS2 */
418 /******************************************************************************
419 * GetColorProfileFromHandle [MSCMS.@]
421 * Retrieve an ICC color profile by handle.
424 * profile [I] Handle to a color profile.
425 * buffer [O] Buffer to receive the ICC profile.
426 * size [I/O] Size of the buffer in bytes. On return the variable holds the
427 * number of bytes actually needed.
434 * The profile returned will be in big-endian format.
436 BOOL WINAPI
GetColorProfileFromHandle( HPROFILE handle
, PBYTE buffer
, PDWORD size
)
440 struct profile
*profile
= grab_profile( handle
);
441 PROFILEHEADER header
;
443 TRACE( "( %p, %p, %p )\n", handle
, buffer
, size
);
445 if (!profile
) return FALSE
;
449 release_profile( profile
);
452 get_profile_header( profile
, &header
);
454 if (!buffer
|| header
.phSize
> *size
)
456 *size
= header
.phSize
;
457 release_profile( profile
);
461 /* No endian conversion needed */
462 memcpy( buffer
, profile
->data
, profile
->size
);
463 *size
= profile
->size
;
465 release_profile( profile
);
468 #endif /* HAVE_LCMS2 */
472 /******************************************************************************
473 * GetColorProfileHeader [MSCMS.@]
475 * Retrieve a color profile header by handle.
478 * profile [I] Handle to a color profile.
479 * header [O] Buffer to receive the ICC profile header.
486 * The profile header returned will be adjusted for endianness.
488 BOOL WINAPI
GetColorProfileHeader( HPROFILE handle
, PPROFILEHEADER header
)
491 struct profile
*profile
= grab_profile( handle
);
493 TRACE( "( %p, %p )\n", handle
, header
);
495 if (!profile
) return FALSE
;
499 release_profile( profile
);
502 get_profile_header( profile
, header
);
503 release_profile( profile
);
508 #endif /* HAVE_LCMS2 */
511 /******************************************************************************
512 * GetCountColorProfileElements [MSCMS.@]
514 * Retrieve the number of elements in a color profile.
517 * profile [I] Handle to a color profile.
518 * count [O] Pointer to a variable which is set to the number of elements
519 * in the color profile.
525 BOOL WINAPI
GetCountColorProfileElements( HPROFILE handle
, PDWORD count
)
529 struct profile
*profile
= grab_profile( handle
);
530 cmsInt32Number num_tags
;
532 TRACE( "( %p, %p )\n", handle
, count
);
534 if (!profile
) return FALSE
;
538 release_profile( profile
);
541 if ((num_tags
= cmsGetTagCount( profile
->cmsprofile
)) >= 0)
546 release_profile( profile
);
548 #endif /* HAVE_LCMS2 */
552 /******************************************************************************
553 * GetStandardColorSpaceProfileA [MSCMS.@]
555 * See GetStandardColorSpaceProfileW.
557 BOOL WINAPI
GetStandardColorSpaceProfileA( PCSTR machine
, DWORD id
, PSTR profile
, PDWORD size
)
564 TRACE( "( 0x%08x, %p, %p )\n", id
, profile
, size
);
568 SetLastError( ERROR_NOT_SUPPORTED
);
574 SetLastError( ERROR_INVALID_PARAMETER
);
578 sizeW
= *size
* sizeof(WCHAR
);
582 ret
= GetStandardColorSpaceProfileW( NULL
, id
, NULL
, &sizeW
);
583 *size
= sizeW
/ sizeof(WCHAR
);
587 profileW
= HeapAlloc( GetProcessHeap(), 0, sizeW
);
590 if ((ret
= GetStandardColorSpaceProfileW( NULL
, id
, profileW
, &sizeW
)))
592 *size
= WideCharToMultiByte( CP_ACP
, 0, profileW
, -1, NULL
, 0, NULL
, NULL
);
593 len
= WideCharToMultiByte( CP_ACP
, 0, profileW
, -1, profile
, *size
, NULL
, NULL
);
594 if (!len
) ret
= FALSE
;
596 else *size
= sizeW
/ sizeof(WCHAR
);
598 HeapFree( GetProcessHeap(), 0, profileW
);
603 /******************************************************************************
604 * GetStandardColorSpaceProfileW [MSCMS.@]
606 * Retrieve the profile filename for a given standard color space id.
609 * machine [I] Name of the machine for which to get the standard color space.
610 * Must be NULL, which indicates the local machine.
611 * id [I] Id of a standard color space.
612 * profile [O] Buffer to receive the profile filename.
613 * size [I/O] Size of the filename buffer in bytes.
619 BOOL WINAPI
GetStandardColorSpaceProfileW( PCWSTR machine
, DWORD id
, PWSTR profile
, PDWORD size
)
621 static const WCHAR rgbprofilefile
[] =
622 { '\\','s','r','g','b',' ','c','o','l','o','r',' ',
623 's','p','a','c','e',' ','p','r','o','f','i','l','e','.','i','c','m',0 };
624 WCHAR rgbprofile
[MAX_PATH
];
625 DWORD len
= sizeof(rgbprofile
);
627 TRACE( "( 0x%08x, %p, %p )\n", id
, profile
, size
);
631 SetLastError( ERROR_NOT_SUPPORTED
);
637 SetLastError( ERROR_INVALID_PARAMETER
);
643 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
647 GetColorDirectoryW( machine
, rgbprofile
, &len
);
652 case LCS_WINDOWS_COLOR_SPACE
: /* FIXME */
653 lstrcatW( rgbprofile
, rgbprofilefile
);
654 len
= lstrlenW( rgbprofile
) * sizeof(WCHAR
);
656 if (*size
< len
|| !profile
)
659 SetLastError( ERROR_MORE_DATA
);
663 lstrcpyW( profile
, rgbprofile
);
667 SetLastError( ERROR_FILE_NOT_FOUND
);
673 static BOOL
header_from_file( LPCWSTR file
, PPROFILEHEADER header
)
677 WCHAR path
[MAX_PATH
], slash
[] = {'\\',0};
678 DWORD size
= sizeof(path
);
681 ret
= GetColorDirectoryW( NULL
, path
, &size
);
684 WARN( "Can't retrieve color directory\n" );
687 if (size
+ sizeof(slash
) + sizeof(WCHAR
) * lstrlenW( file
) > sizeof(path
))
689 WARN( "Filename too long\n" );
693 lstrcatW( path
, slash
);
694 lstrcatW( path
, file
);
696 profile
.dwType
= PROFILE_FILENAME
;
697 profile
.pProfileData
= path
;
698 profile
.cbDataSize
= lstrlenW( path
) + 1;
700 handle
= OpenColorProfileW( &profile
, PROFILE_READ
, FILE_SHARE_READ
, OPEN_EXISTING
);
703 WARN( "Can't open color profile\n" );
707 ret
= GetColorProfileHeader( handle
, header
);
709 WARN( "Can't retrieve color profile header\n" );
711 CloseColorProfile( handle
);
715 static BOOL
match_profile( PENUMTYPEW rec
, PPROFILEHEADER hdr
)
717 if (rec
->dwFields
& ET_DEVICENAME
)
719 FIXME( "ET_DEVICENAME: %s\n", debugstr_w(rec
->pDeviceName
) );
721 if (rec
->dwFields
& ET_MEDIATYPE
)
723 FIXME( "ET_MEDIATYPE: 0x%08x\n", rec
->dwMediaType
);
725 if (rec
->dwFields
& ET_DITHERMODE
)
727 FIXME( "ET_DITHERMODE: 0x%08x\n", rec
->dwDitheringMode
);
729 if (rec
->dwFields
& ET_RESOLUTION
)
731 FIXME( "ET_RESOLUTION: 0x%08x, 0x%08x\n",
732 rec
->dwResolution
[0], rec
->dwResolution
[1] );
734 if (rec
->dwFields
& ET_DEVICECLASS
)
736 FIXME( "ET_DEVICECLASS: %s\n", dbgstr_tag(rec
->dwMediaType
) );
738 if (rec
->dwFields
& ET_CMMTYPE
)
740 TRACE( "ET_CMMTYPE: %s\n", dbgstr_tag(rec
->dwCMMType
) );
741 if (rec
->dwCMMType
!= hdr
->phCMMType
) return FALSE
;
743 if (rec
->dwFields
& ET_CLASS
)
745 TRACE( "ET_CLASS: %s\n", dbgstr_tag(rec
->dwClass
) );
746 if (rec
->dwClass
!= hdr
->phClass
) return FALSE
;
748 if (rec
->dwFields
& ET_DATACOLORSPACE
)
750 TRACE( "ET_DATACOLORSPACE: %s\n", dbgstr_tag(rec
->dwDataColorSpace
) );
751 if (rec
->dwDataColorSpace
!= hdr
->phDataColorSpace
) return FALSE
;
753 if (rec
->dwFields
& ET_CONNECTIONSPACE
)
755 TRACE( "ET_CONNECTIONSPACE: %s\n", dbgstr_tag(rec
->dwConnectionSpace
) );
756 if (rec
->dwConnectionSpace
!= hdr
->phConnectionSpace
) return FALSE
;
758 if (rec
->dwFields
& ET_SIGNATURE
)
760 TRACE( "ET_SIGNATURE: %s\n", dbgstr_tag(rec
->dwSignature
) );
761 if (rec
->dwSignature
!= hdr
->phSignature
) return FALSE
;
763 if (rec
->dwFields
& ET_PLATFORM
)
765 TRACE( "ET_PLATFORM: %s\n", dbgstr_tag(rec
->dwPlatform
) );
766 if (rec
->dwPlatform
!= hdr
->phPlatform
) return FALSE
;
768 if (rec
->dwFields
& ET_PROFILEFLAGS
)
770 TRACE( "ET_PROFILEFLAGS: 0x%08x\n", rec
->dwProfileFlags
);
771 if (rec
->dwProfileFlags
!= hdr
->phProfileFlags
) return FALSE
;
773 if (rec
->dwFields
& ET_MANUFACTURER
)
775 TRACE( "ET_MANUFACTURER: %s\n", dbgstr_tag(rec
->dwManufacturer
) );
776 if (rec
->dwManufacturer
!= hdr
->phManufacturer
) return FALSE
;
778 if (rec
->dwFields
& ET_MODEL
)
780 TRACE( "ET_MODEL: %s\n", dbgstr_tag(rec
->dwModel
) );
781 if (rec
->dwModel
!= hdr
->phModel
) return FALSE
;
783 if (rec
->dwFields
& ET_ATTRIBUTES
)
785 TRACE( "ET_ATTRIBUTES: 0x%08x, 0x%08x\n",
786 rec
->dwAttributes
[0], rec
->dwAttributes
[1] );
787 if (rec
->dwAttributes
[0] != hdr
->phAttributes
[0] ||
788 rec
->dwAttributes
[1] != hdr
->phAttributes
[1]) return FALSE
;
790 if (rec
->dwFields
& ET_RENDERINGINTENT
)
792 TRACE( "ET_RENDERINGINTENT: 0x%08x\n", rec
->dwRenderingIntent
);
793 if (rec
->dwRenderingIntent
!= hdr
->phRenderingIntent
) return FALSE
;
795 if (rec
->dwFields
& ET_CREATOR
)
797 TRACE( "ET_CREATOR: %s\n", dbgstr_tag(rec
->dwCreator
) );
798 if (rec
->dwCreator
!= hdr
->phCreator
) return FALSE
;
803 /******************************************************************************
804 * EnumColorProfilesA [MSCMS.@]
806 * See EnumColorProfilesW.
808 BOOL WINAPI
EnumColorProfilesA( PCSTR machine
, PENUMTYPEA record
, PBYTE buffer
,
809 PDWORD size
, PDWORD number
)
811 BOOL match
, ret
= FALSE
;
812 char spec
[] = "\\*.icm";
813 char colordir
[MAX_PATH
], glob
[MAX_PATH
], **profiles
= NULL
;
814 DWORD i
, len
= sizeof(colordir
), count
= 0, totalsize
= 0;
815 PROFILEHEADER header
;
816 WIN32_FIND_DATAA data
;
818 WCHAR
*fileW
= NULL
, *deviceW
= NULL
;
821 TRACE( "( %p, %p, %p, %p, %p )\n", machine
, record
, buffer
, size
, number
);
823 if (machine
|| !record
|| !size
||
824 record
->dwSize
!= sizeof(ENUMTYPEA
) ||
825 record
->dwVersion
!= ENUM_TYPE_VERSION
) return FALSE
;
827 ret
= GetColorDirectoryA( machine
, colordir
, &len
);
828 if (!ret
|| len
+ sizeof(spec
) > MAX_PATH
)
830 WARN( "can't retrieve color directory\n" );
834 lstrcpyA( glob
, colordir
);
835 lstrcatA( glob
, spec
);
837 find
= FindFirstFileA( glob
, &data
);
838 if (find
== INVALID_HANDLE_VALUE
) return FALSE
;
840 profiles
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(char *) + 1 );
841 if (!profiles
) goto exit
;
843 memcpy( &recordW
, record
, sizeof(ENUMTYPEA
) );
844 if (record
->pDeviceName
)
846 deviceW
= strdupW( record
->pDeviceName
);
847 if (!(recordW
.pDeviceName
= deviceW
)) goto exit
;
850 fileW
= strdupW( data
.cFileName
);
851 if (!fileW
) goto exit
;
853 ret
= header_from_file( fileW
, &header
);
856 match
= match_profile( &recordW
, &header
);
859 len
= sizeof(char) * (lstrlenA( data
.cFileName
) + 1);
860 profiles
[count
] = HeapAlloc( GetProcessHeap(), 0, len
);
862 if (!profiles
[count
]) goto exit
;
865 TRACE( "matching profile: %s\n", debugstr_a(data
.cFileName
) );
866 lstrcpyA( profiles
[count
], data
.cFileName
);
872 HeapFree( GetProcessHeap(), 0, fileW
);
875 while (FindNextFileA( find
, &data
))
877 fileW
= strdupW( data
.cFileName
);
878 if (!fileW
) goto exit
;
880 ret
= header_from_file( fileW
, &header
);
883 HeapFree( GetProcessHeap(), 0, fileW
);
887 match
= match_profile( &recordW
, &header
);
890 char **tmp
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
891 profiles
, sizeof(char *) * (count
+ 1) );
895 len
= sizeof(char) * (lstrlenA( data
.cFileName
) + 1);
896 profiles
[count
] = HeapAlloc( GetProcessHeap(), 0, len
);
898 if (!profiles
[count
]) goto exit
;
901 TRACE( "matching profile: %s\n", debugstr_a(data
.cFileName
) );
902 lstrcpyA( profiles
[count
], data
.cFileName
);
907 HeapFree( GetProcessHeap(), 0, fileW
);
912 if (buffer
&& *size
>= totalsize
)
914 char *p
= (char *)buffer
;
916 for (i
= 0; i
< count
; i
++)
918 lstrcpyA( p
, profiles
[i
] );
919 p
+= lstrlenA( profiles
[i
] ) + 1;
927 if (number
) *number
= count
;
930 for (i
= 0; i
< count
; i
++)
931 HeapFree( GetProcessHeap(), 0, profiles
[i
] );
932 HeapFree( GetProcessHeap(), 0, profiles
);
933 HeapFree( GetProcessHeap(), 0, deviceW
);
934 HeapFree( GetProcessHeap(), 0, fileW
);
940 /******************************************************************************
941 * EnumColorProfilesW [MSCMS.@]
943 * Enumerate profiles that match given criteria.
946 * machine [I] Name of the machine for which to enumerate profiles.
947 * Must be NULL, which indicates the local machine.
948 * record [I] Record of criteria that a profile must match.
949 * buffer [O] Buffer to receive a string array of profile filenames.
950 * size [I/O] Size of the filename buffer in bytes.
951 * number [O] Number of filenames copied into buffer.
957 BOOL WINAPI
EnumColorProfilesW( PCWSTR machine
, PENUMTYPEW record
, PBYTE buffer
,
958 PDWORD size
, PDWORD number
)
960 BOOL match
, ret
= FALSE
;
961 WCHAR spec
[] = {'\\','*','i','c','m',0};
962 WCHAR colordir
[MAX_PATH
], glob
[MAX_PATH
], **profiles
= NULL
;
963 DWORD i
, len
= sizeof(colordir
), count
= 0, totalsize
= 0;
964 PROFILEHEADER header
;
965 WIN32_FIND_DATAW data
;
968 TRACE( "( %p, %p, %p, %p, %p )\n", machine
, record
, buffer
, size
, number
);
970 if (machine
|| !record
|| !size
||
971 record
->dwSize
!= sizeof(ENUMTYPEW
) ||
972 record
->dwVersion
!= ENUM_TYPE_VERSION
) return FALSE
;
974 ret
= GetColorDirectoryW( machine
, colordir
, &len
);
975 if (!ret
|| len
+ sizeof(spec
) > MAX_PATH
)
977 WARN( "Can't retrieve color directory\n" );
981 lstrcpyW( glob
, colordir
);
982 lstrcatW( glob
, spec
);
984 find
= FindFirstFileW( glob
, &data
);
985 if (find
== INVALID_HANDLE_VALUE
) return FALSE
;
987 profiles
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WCHAR
*) + 1 );
988 if (!profiles
) goto exit
;
990 ret
= header_from_file( data
.cFileName
, &header
);
993 match
= match_profile( record
, &header
);
996 len
= sizeof(WCHAR
) * (lstrlenW( data
.cFileName
) + 1);
997 profiles
[count
] = HeapAlloc( GetProcessHeap(), 0, len
);
999 if (!profiles
[count
]) goto exit
;
1002 TRACE( "matching profile: %s\n", debugstr_w(data
.cFileName
) );
1003 lstrcpyW( profiles
[count
], data
.cFileName
);
1010 while (FindNextFileW( find
, &data
))
1012 ret
= header_from_file( data
.cFileName
, &header
);
1015 match
= match_profile( record
, &header
);
1018 WCHAR
**tmp
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
1019 profiles
, sizeof(WCHAR
*) * (count
+ 1) );
1020 if (!tmp
) goto exit
;
1021 else profiles
= tmp
;
1023 len
= sizeof(WCHAR
) * (lstrlenW( data
.cFileName
) + 1);
1024 profiles
[count
] = HeapAlloc( GetProcessHeap(), 0, len
);
1026 if (!profiles
[count
]) goto exit
;
1029 TRACE( "matching profile: %s\n", debugstr_w(data
.cFileName
) );
1030 lstrcpyW( profiles
[count
], data
.cFileName
);
1038 if (buffer
&& *size
>= totalsize
)
1040 WCHAR
*p
= (WCHAR
*)buffer
;
1042 for (i
= 0; i
< count
; i
++)
1044 lstrcpyW( p
, profiles
[i
] );
1045 p
+= lstrlenW( profiles
[i
] ) + 1;
1053 if (number
) *number
= count
;
1056 for (i
= 0; i
< count
; i
++)
1057 HeapFree( GetProcessHeap(), 0, profiles
[i
] );
1058 HeapFree( GetProcessHeap(), 0, profiles
);
1064 /******************************************************************************
1065 * InstallColorProfileA [MSCMS.@]
1067 * See InstallColorProfileW.
1069 BOOL WINAPI
InstallColorProfileA( PCSTR machine
, PCSTR profile
)
1075 TRACE( "( %s )\n", debugstr_a(profile
) );
1077 if (machine
|| !profile
) return FALSE
;
1079 len
= MultiByteToWideChar( CP_ACP
, 0, profile
, -1, NULL
, 0 );
1080 profileW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1084 MultiByteToWideChar( CP_ACP
, 0, profile
, -1, profileW
, len
);
1086 ret
= InstallColorProfileW( NULL
, profileW
);
1087 HeapFree( GetProcessHeap(), 0, profileW
);
1092 /******************************************************************************
1093 * InstallColorProfileW [MSCMS.@]
1095 * Install a color profile.
1098 * machine [I] Name of the machine to install the profile on. Must be NULL,
1099 * which indicates the local machine.
1100 * profile [I] Full path name of the profile to install.
1106 BOOL WINAPI
InstallColorProfileW( PCWSTR machine
, PCWSTR profile
)
1108 WCHAR dest
[MAX_PATH
], base
[MAX_PATH
];
1109 DWORD size
= sizeof(dest
);
1110 static const WCHAR slash
[] = { '\\', 0 };
1112 TRACE( "( %s )\n", debugstr_w(profile
) );
1114 if (machine
|| !profile
) return FALSE
;
1116 if (!GetColorDirectoryW( machine
, dest
, &size
)) return FALSE
;
1118 basename( profile
, base
);
1120 lstrcatW( dest
, slash
);
1121 lstrcatW( dest
, base
);
1123 /* Is source equal to destination? */
1124 if (!lstrcmpW( profile
, dest
)) return TRUE
;
1126 return CopyFileW( profile
, dest
, TRUE
);
1129 /******************************************************************************
1130 * IsColorProfileTagPresent [MSCMS.@]
1132 * Determine if a given ICC tag type is present in a color profile.
1135 * profile [I] Color profile handle.
1136 * tag [I] ICC tag type.
1137 * present [O] Pointer to a BOOL variable. Set to TRUE if tag type is present,
1144 BOOL WINAPI
IsColorProfileTagPresent( HPROFILE handle
, TAGTYPE type
, PBOOL present
)
1148 struct profile
*profile
= grab_profile( handle
);
1150 TRACE( "( %p, 0x%08x, %p )\n", handle
, type
, present
);
1152 if (!profile
) return FALSE
;
1156 release_profile( profile
);
1159 *present
= cmsIsTag( profile
->cmsprofile
, type
);
1160 release_profile( profile
);
1163 #endif /* HAVE_LCMS2 */
1167 /******************************************************************************
1168 * IsColorProfileValid [MSCMS.@]
1170 * Determine if a given color profile is valid.
1173 * profile [I] Color profile handle.
1174 * valid [O] Pointer to a BOOL variable. Set to TRUE if profile is valid,
1181 BOOL WINAPI
IsColorProfileValid( HPROFILE handle
, PBOOL valid
)
1185 struct profile
*profile
= grab_profile( handle
);
1187 TRACE( "( %p, %p )\n", handle
, valid
);
1189 if (!profile
) return FALSE
;
1193 release_profile( profile
);
1196 if (profile
->data
) ret
= *valid
= TRUE
;
1197 release_profile( profile
);
1199 #endif /* HAVE_LCMS2 */
1203 /******************************************************************************
1204 * SetColorProfileElement [MSCMS.@]
1206 * Set data for a specified tag type.
1209 * profile [I] Handle to a color profile.
1210 * type [I] ICC tag type.
1211 * offset [I] Offset in bytes to start copying to.
1212 * size [I/O] Size of the buffer in bytes. On return the variable holds the
1213 * number of bytes actually needed.
1214 * buffer [O] Buffer holding the tag data.
1220 BOOL WINAPI
SetColorProfileElement( HPROFILE handle
, TAGTYPE type
, DWORD offset
, PDWORD size
,
1225 struct profile
*profile
= grab_profile( handle
);
1227 TRACE( "( %p, 0x%08x, %d, %p, %p )\n", handle
, type
, offset
, size
, buffer
);
1229 if (!profile
) return FALSE
;
1231 if (!size
|| !buffer
|| !(profile
->access
& PROFILE_READWRITE
))
1233 release_profile( profile
);
1236 ret
= set_tag_data( profile
, type
, offset
, buffer
, size
);
1237 release_profile( profile
);
1240 #endif /* HAVE_LCMS2 */
1244 /******************************************************************************
1245 * SetColorProfileHeader [MSCMS.@]
1247 * Set header data for a given profile.
1250 * profile [I] Handle to a color profile.
1251 * header [I] Buffer holding the header data.
1257 BOOL WINAPI
SetColorProfileHeader( HPROFILE handle
, PPROFILEHEADER header
)
1260 struct profile
*profile
= grab_profile( handle
);
1262 TRACE( "( %p, %p )\n", handle
, header
);
1264 if (!profile
) return FALSE
;
1266 if (!header
|| !(profile
->access
& PROFILE_READWRITE
))
1268 release_profile( profile
);
1271 set_profile_header( profile
, header
);
1272 release_profile( profile
);
1277 #endif /* HAVE_LCMS2 */
1280 /******************************************************************************
1281 * UninstallColorProfileA [MSCMS.@]
1283 * See UninstallColorProfileW.
1285 BOOL WINAPI
UninstallColorProfileA( PCSTR machine
, PCSTR profile
, BOOL
delete )
1291 TRACE( "( %s, %x )\n", debugstr_a(profile
), delete );
1293 if (machine
|| !profile
) return FALSE
;
1295 len
= MultiByteToWideChar( CP_ACP
, 0, profile
, -1, NULL
, 0 );
1296 profileW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1300 MultiByteToWideChar( CP_ACP
, 0, profile
, -1, profileW
, len
);
1302 ret
= UninstallColorProfileW( NULL
, profileW
, delete );
1304 HeapFree( GetProcessHeap(), 0, profileW
);
1309 /******************************************************************************
1310 * UninstallColorProfileW [MSCMS.@]
1312 * Uninstall a color profile.
1315 * machine [I] Name of the machine to uninstall the profile on. Must be NULL,
1316 * which indicates the local machine.
1317 * profile [I] Full path name of the profile to uninstall.
1318 * delete [I] Bool that specifies whether the profile file should be deleted.
1324 BOOL WINAPI
UninstallColorProfileW( PCWSTR machine
, PCWSTR profile
, BOOL
delete )
1326 TRACE( "( %s, %x )\n", debugstr_w(profile
), delete );
1328 if (machine
|| !profile
) return FALSE
;
1330 if (delete) return DeleteFileW( profile
);
1335 /******************************************************************************
1336 * OpenColorProfileA [MSCMS.@]
1338 * See OpenColorProfileW.
1340 HPROFILE WINAPI
OpenColorProfileA( PPROFILE profile
, DWORD access
, DWORD sharing
, DWORD creation
)
1342 HPROFILE handle
= NULL
;
1344 TRACE( "( %p, 0x%08x, 0x%08x, 0x%08x )\n", profile
, access
, sharing
, creation
);
1346 if (!profile
|| !profile
->pProfileData
) return NULL
;
1348 /* No AW conversion needed for memory based profiles */
1349 if (profile
->dwType
& PROFILE_MEMBUFFER
)
1350 return OpenColorProfileW( profile
, access
, sharing
, creation
);
1352 if (profile
->dwType
& PROFILE_FILENAME
)
1357 profileW
.dwType
= profile
->dwType
;
1359 len
= MultiByteToWideChar( CP_ACP
, 0, profile
->pProfileData
, -1, NULL
, 0 );
1360 profileW
.pProfileData
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1362 if (profileW
.pProfileData
)
1364 profileW
.cbDataSize
= len
* sizeof(WCHAR
);
1365 MultiByteToWideChar( CP_ACP
, 0, profile
->pProfileData
, -1, profileW
.pProfileData
, len
);
1367 handle
= OpenColorProfileW( &profileW
, access
, sharing
, creation
);
1368 HeapFree( GetProcessHeap(), 0, profileW
.pProfileData
);
1374 /******************************************************************************
1375 * OpenColorProfileW [MSCMS.@]
1377 * Open a color profile.
1380 * profile [I] Pointer to a color profile structure.
1381 * access [I] Desired access.
1382 * sharing [I] Sharing mode.
1383 * creation [I] Creation mode.
1386 * Success: Handle to the opened profile.
1390 * Values for access: PROFILE_READ or PROFILE_READWRITE.
1391 * Values for sharing: 0 (no sharing), FILE_SHARE_READ and/or FILE_SHARE_WRITE.
1392 * Values for creation: one of CREATE_NEW, CREATE_ALWAYS, OPEN_EXISTING,
1393 * OPEN_ALWAYS, TRUNCATE_EXISTING.
1394 * Sharing and creation flags are ignored for memory based profiles.
1396 HPROFILE WINAPI
OpenColorProfileW( PPROFILE profile
, DWORD access
, DWORD sharing
, DWORD creation
)
1399 cmsHPROFILE cmsprofile
= NULL
;
1401 HANDLE handle
= INVALID_HANDLE_VALUE
;
1404 TRACE( "( %p, 0x%08x, 0x%08x, 0x%08x )\n", profile
, access
, sharing
, creation
);
1406 if (!profile
|| !profile
->pProfileData
) return NULL
;
1408 if (profile
->dwType
== PROFILE_MEMBUFFER
)
1410 /* FIXME: access flags not implemented for memory based profiles */
1412 if (!(data
= HeapAlloc( GetProcessHeap(), 0, profile
->cbDataSize
))) return NULL
;
1413 memcpy( data
, profile
->pProfileData
, profile
->cbDataSize
);
1415 cmsprofile
= cmsOpenProfileFromMem( data
, profile
->cbDataSize
);
1416 size
= profile
->cbDataSize
;
1418 else if (profile
->dwType
== PROFILE_FILENAME
)
1420 DWORD read
, flags
= 0;
1422 TRACE( "profile file: %s\n", debugstr_w( profile
->pProfileData
) );
1424 if (access
& PROFILE_READ
) flags
= GENERIC_READ
;
1425 if (access
& PROFILE_READWRITE
) flags
= GENERIC_READ
|GENERIC_WRITE
;
1427 if (!flags
) return NULL
;
1428 if (!sharing
) sharing
= FILE_SHARE_READ
;
1430 if (!PathIsRelativeW( profile
->pProfileData
))
1431 handle
= CreateFileW( profile
->pProfileData
, flags
, sharing
, NULL
, creation
, 0, NULL
);
1436 if (!GetColorDirectoryW( NULL
, NULL
, &size
) && GetLastError() == ERROR_MORE_DATA
)
1438 size
+= (strlenW( profile
->pProfileData
) + 2) * sizeof(WCHAR
);
1439 if (!(path
= HeapAlloc( GetProcessHeap(), 0, size
))) return NULL
;
1440 GetColorDirectoryW( NULL
, path
, &size
);
1441 PathAddBackslashW( path
);
1442 strcatW( path
, profile
->pProfileData
);
1445 handle
= CreateFileW( path
, flags
, sharing
, NULL
, creation
, 0, NULL
);
1446 HeapFree( GetProcessHeap(), 0, path
);
1448 if (handle
== INVALID_HANDLE_VALUE
)
1450 WARN( "Unable to open color profile %u\n", GetLastError() );
1453 if ((size
= GetFileSize( handle
, NULL
)) == INVALID_FILE_SIZE
)
1455 ERR( "Unable to retrieve size of color profile\n" );
1456 CloseHandle( handle
);
1459 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
)))
1461 ERR( "Unable to allocate memory for color profile\n" );
1462 CloseHandle( handle
);
1465 if (!ReadFile( handle
, data
, size
, &read
, NULL
) || read
!= size
)
1467 ERR( "Unable to read color profile\n" );
1469 CloseHandle( handle
);
1470 HeapFree( GetProcessHeap(), 0, data
);
1473 cmsprofile
= cmsOpenProfileFromMem( data
, size
);
1477 ERR( "Invalid profile type %u\n", profile
->dwType
);
1483 struct profile profile
;
1486 profile
.file
= handle
;
1487 profile
.access
= access
;
1488 profile
.data
= data
;
1489 profile
.size
= size
;
1490 profile
.cmsprofile
= cmsprofile
;
1492 if ((hprof
= create_profile( &profile
))) return hprof
;
1493 HeapFree( GetProcessHeap(), 0, data
);
1494 cmsCloseProfile( cmsprofile
);
1496 CloseHandle( handle
);
1498 #endif /* HAVE_LCMS2 */
1502 /******************************************************************************
1503 * CloseColorProfile [MSCMS.@]
1505 * Close a color profile.
1508 * profile [I] Handle to the profile.
1514 BOOL WINAPI
CloseColorProfile( HPROFILE profile
)
1519 TRACE( "( %p )\n", profile
);
1520 ret
= close_profile( profile
);
1522 #endif /* HAVE_LCMS2 */