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
22 #include "wine/debug.h"
23 #include "wine/unicode.h"
35 #include "mscms_priv.h"
37 #define IS_SEPARATOR(ch) ((ch) == '\\' || (ch) == '/')
39 static void MSCMS_basename( LPCWSTR path
, LPWSTR name
)
41 INT i
= lstrlenW( path
);
43 while (i
> 0 && !IS_SEPARATOR(path
[i
- 1])) i
--;
44 lstrcpyW( name
, &path
[i
] );
47 static inline LPWSTR
MSCMS_strdupW( LPCSTR str
)
52 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
53 if ((ret
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
54 MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
59 static const char *MSCMS_dbgstr_tag( DWORD tag
)
61 return wine_dbg_sprintf( "'%c%c%c%c'",
62 (char)(tag
>> 24), (char)(tag
>> 16), (char)(tag
>> 8), (char)(tag
) );
65 WINE_DEFAULT_DEBUG_CHANNEL(mscms
);
67 /******************************************************************************
68 * AssociateColorProfileWithDeviceA [MSCMS.@]
70 BOOL WINAPI
AssociateColorProfileWithDeviceA( PCSTR machine
, PCSTR profile
, PCSTR device
)
74 WCHAR
*profileW
, *deviceW
;
76 TRACE( "( %s, %s, %s )\n", debugstr_a(machine
), debugstr_a(profile
), debugstr_a(device
) );
78 if (!profile
|| !device
)
80 SetLastError( ERROR_INVALID_PARAMETER
);
85 SetLastError( ERROR_NOT_SUPPORTED
);
89 len
= MultiByteToWideChar( CP_ACP
, 0, profile
, -1, NULL
, 0 );
90 if (!(profileW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return FALSE
;
92 MultiByteToWideChar( CP_ACP
, 0, profile
, -1, profileW
, len
);
94 len
= MultiByteToWideChar( CP_ACP
, 0, device
, -1, NULL
, 0 );
95 if ((deviceW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
97 MultiByteToWideChar( CP_ACP
, 0, device
, -1, deviceW
, len
);
98 ret
= AssociateColorProfileWithDeviceW( NULL
, profileW
, deviceW
);
101 HeapFree( GetProcessHeap(), 0, profileW
);
102 HeapFree( GetProcessHeap(), 0, deviceW
);
106 static BOOL
set_profile_device_key( PCWSTR file
, const BYTE
*value
, DWORD size
)
108 static const WCHAR fmtW
[] = {'%','c','%','c','%','c','%','c',0};
109 static const WCHAR icmW
[] = {'S','o','f','t','w','a','r','e','\\',
110 'M','i','c','r','o','s','o','f','t','\\',
111 'W','i','n','d','o','w','s',' ','N','T','\\',
112 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
114 PROFILEHEADER header
;
117 HKEY icm_key
, class_key
;
118 WCHAR basenameW
[MAX_PATH
], classW
[5];
120 profile
.dwType
= PROFILE_FILENAME
;
121 profile
.pProfileData
= (PVOID
)file
;
122 profile
.cbDataSize
= (lstrlenW( file
) + 1) * sizeof(WCHAR
);
124 /* FIXME is the profile installed? */
125 if (!(handle
= OpenColorProfileW( &profile
, PROFILE_READ
, 0, OPEN_EXISTING
)))
127 SetLastError( ERROR_INVALID_PROFILE
);
131 RegCreateKeyExW( HKEY_LOCAL_MACHINE
, icmW
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &icm_key
, NULL
);
132 GetColorProfileHeader( handle
, &header
);
134 MSCMS_basename( file
, basenameW
);
135 sprintfW( classW
, fmtW
, (header
.phClass
>> 24) & 0xff, (header
.phClass
>> 16) & 0xff,
136 (header
.phClass
>> 8) & 0xff, header
.phClass
& 0xff );
138 RegCreateKeyExW( icm_key
, classW
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &class_key
, NULL
);
139 if (value
) RegSetValueExW( class_key
, basenameW
, 0, REG_BINARY
, value
, size
);
140 else RegDeleteValueW( class_key
, basenameW
);
142 RegCloseKey( class_key
);
143 RegCloseKey( icm_key
);
144 CloseColorProfile( handle
);
148 /******************************************************************************
149 * AssociateColorProfileWithDeviceW [MSCMS.@]
151 BOOL WINAPI
AssociateColorProfileWithDeviceW( PCWSTR machine
, PCWSTR profile
, PCWSTR device
)
153 static const BYTE dummy_value
[12];
155 TRACE( "( %s, %s, %s )\n", debugstr_w(machine
), debugstr_w(profile
), debugstr_w(device
) );
157 if (!profile
|| !device
)
159 SetLastError( ERROR_INVALID_PARAMETER
);
164 SetLastError( ERROR_NOT_SUPPORTED
);
168 return set_profile_device_key( profile
, dummy_value
, sizeof(dummy_value
) );
171 /******************************************************************************
172 * DisassociateColorProfileFromDeviceA [MSCMS.@]
174 BOOL WINAPI
DisassociateColorProfileFromDeviceA( PCSTR machine
, PCSTR profile
, PCSTR device
)
178 WCHAR
*profileW
, *deviceW
;
180 TRACE( "( %s, %s, %s )\n", debugstr_a(machine
), debugstr_a(profile
), debugstr_a(device
) );
182 if (!profile
|| !device
)
184 SetLastError( ERROR_INVALID_PARAMETER
);
189 SetLastError( ERROR_NOT_SUPPORTED
);
193 len
= MultiByteToWideChar( CP_ACP
, 0, profile
, -1, NULL
, 0 );
194 if (!(profileW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return FALSE
;
196 MultiByteToWideChar( CP_ACP
, 0, profile
, -1, profileW
, len
);
198 len
= MultiByteToWideChar( CP_ACP
, 0, device
, -1, NULL
, 0 );
199 if ((deviceW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
201 MultiByteToWideChar( CP_ACP
, 0, device
, -1, deviceW
, len
);
202 ret
= DisassociateColorProfileFromDeviceW( NULL
, profileW
, deviceW
);
205 HeapFree( GetProcessHeap(), 0, profileW
);
206 HeapFree( GetProcessHeap(), 0, deviceW
);
210 /******************************************************************************
211 * DisassociateColorProfileFromDeviceW [MSCMS.@]
213 BOOL WINAPI
DisassociateColorProfileFromDeviceW( PCWSTR machine
, PCWSTR profile
, PCWSTR device
)
215 TRACE( "( %s, %s, %s )\n", debugstr_w(machine
), debugstr_w(profile
), debugstr_w(device
) );
217 if (!profile
|| !device
)
219 SetLastError( ERROR_INVALID_PARAMETER
);
224 SetLastError( ERROR_NOT_SUPPORTED
);
228 return set_profile_device_key( profile
, NULL
, 0 );
231 /******************************************************************************
232 * GetColorDirectoryA [MSCMS.@]
234 * See GetColorDirectoryW.
236 BOOL WINAPI
GetColorDirectoryA( PCSTR machine
, PSTR buffer
, PDWORD size
)
243 TRACE( "( %p, %p )\n", buffer
, size
);
245 if (machine
|| !size
) return FALSE
;
249 ret
= GetColorDirectoryW( NULL
, NULL
, &sizeW
);
250 *size
= sizeW
/ sizeof(WCHAR
);
254 sizeW
= *size
* sizeof(WCHAR
);
256 bufferW
= HeapAlloc( GetProcessHeap(), 0, sizeW
);
260 if ((ret
= GetColorDirectoryW( NULL
, bufferW
, &sizeW
)))
262 *size
= WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
263 len
= WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, buffer
, *size
, NULL
, NULL
);
264 if (!len
) ret
= FALSE
;
266 else *size
= sizeW
/ sizeof(WCHAR
);
268 HeapFree( GetProcessHeap(), 0, bufferW
);
273 /******************************************************************************
274 * GetColorDirectoryW [MSCMS.@]
276 * Get the directory where color profiles are stored.
279 * machine [I] Name of the machine for which to get the color directory.
280 * Must be NULL, which indicates the local machine.
281 * buffer [I] Buffer to receive the path name.
282 * size [I/O] Size of the buffer in bytes. On return the variable holds
283 * the number of bytes actually needed.
285 BOOL WINAPI
GetColorDirectoryW( PCWSTR machine
, PWSTR buffer
, PDWORD size
)
287 WCHAR colordir
[MAX_PATH
];
288 static const WCHAR colorsubdir
[] =
289 {'\\','s','p','o','o','l','\\','d','r','i','v','e','r','s','\\','c','o','l','o','r',0};
292 TRACE( "( %p, %p )\n", buffer
, size
);
294 if (machine
|| !size
) return FALSE
;
296 GetSystemDirectoryW( colordir
, sizeof(colordir
) / sizeof(WCHAR
) );
297 lstrcatW( colordir
, colorsubdir
);
299 len
= lstrlenW( colordir
) * sizeof(WCHAR
);
301 if (buffer
&& len
<= *size
)
303 lstrcpyW( buffer
, colordir
);
308 SetLastError( ERROR_MORE_DATA
);
313 /******************************************************************************
314 * GetColorProfileElement [MSCMS.@]
316 * Retrieve data for a specified tag type.
319 * profile [I] Handle to a color profile.
320 * type [I] ICC tag type.
321 * offset [I] Offset in bytes to start copying from.
322 * size [I/O] Size of the buffer in bytes. On return the variable holds
323 * the number of bytes actually needed.
324 * buffer [O] Buffer to receive the tag data.
325 * ref [O] Pointer to a BOOL that specifies whether more than one tag
326 * references the data.
332 BOOL WINAPI
GetColorProfileElement( HPROFILE profile
, TAGTYPE type
, DWORD offset
, PDWORD size
,
333 PVOID buffer
, PBOOL ref
)
337 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
341 TRACE( "( %p, 0x%08x, %d, %p, %p, %p )\n", profile
, type
, offset
, size
, buffer
, ref
);
343 if (!iccprofile
|| !size
|| !ref
) return FALSE
;
344 count
= MSCMS_get_tag_count( iccprofile
);
346 for (i
= 0; i
< count
; i
++)
348 MSCMS_get_tag_by_index( iccprofile
, i
, &tag
);
352 if ((tag
.size
- offset
) > *size
|| !buffer
)
354 *size
= (tag
.size
- offset
);
358 MSCMS_get_tag_data( iccprofile
, &tag
, offset
, buffer
);
360 *ref
= FALSE
; /* FIXME: calculate properly */
365 #endif /* HAVE_LCMS */
369 /******************************************************************************
370 * GetColorProfileElementTag [MSCMS.@]
372 * Get the tag type from a color profile by index.
375 * profile [I] Handle to a color profile.
376 * index [I] Index into the tag table of the color profile.
377 * type [O] Pointer to a variable that holds the ICC tag type on return.
384 * The tag table index starts at 1.
385 * Use GetCountColorProfileElements to retrieve a count of tagged elements.
387 BOOL WINAPI
GetColorProfileElementTag( HPROFILE profile
, DWORD index
, PTAGTYPE type
)
391 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
395 TRACE( "( %p, %d, %p )\n", profile
, index
, type
);
397 if (!iccprofile
|| !type
) return FALSE
;
399 count
= MSCMS_get_tag_count( iccprofile
);
400 if (index
> count
|| index
< 1) return FALSE
;
402 MSCMS_get_tag_by_index( iccprofile
, index
- 1, &tag
);
407 #endif /* HAVE_LCMS */
411 /******************************************************************************
412 * GetColorProfileFromHandle [MSCMS.@]
414 * Retrieve an ICC color profile by handle.
417 * profile [I] Handle to a color profile.
418 * buffer [O] Buffer to receive the ICC profile.
419 * size [I/O] Size of the buffer in bytes. On return the variable holds the
420 * number of bytes actually needed.
427 * The profile returned will be in big-endian format.
429 BOOL WINAPI
GetColorProfileFromHandle( HPROFILE profile
, PBYTE buffer
, PDWORD size
)
433 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
434 PROFILEHEADER header
;
436 TRACE( "( %p, %p, %p )\n", profile
, buffer
, size
);
438 if (!iccprofile
|| !size
) return FALSE
;
439 MSCMS_get_profile_header( iccprofile
, &header
);
441 if (!buffer
|| header
.phSize
> *size
)
443 *size
= header
.phSize
;
447 /* No endian conversion needed */
448 memcpy( buffer
, iccprofile
, header
.phSize
);
450 *size
= header
.phSize
;
453 #endif /* HAVE_LCMS */
457 /******************************************************************************
458 * GetColorProfileHeader [MSCMS.@]
460 * Retrieve a color profile header by handle.
463 * profile [I] Handle to a color profile.
464 * header [O] Buffer to receive the ICC profile header.
471 * The profile header returned will be adjusted for endianess.
473 BOOL WINAPI
GetColorProfileHeader( HPROFILE profile
, PPROFILEHEADER header
)
476 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
478 TRACE( "( %p, %p )\n", profile
, header
);
480 if (!iccprofile
|| !header
) return FALSE
;
482 MSCMS_get_profile_header( iccprofile
, header
);
487 #endif /* HAVE_LCMS */
490 /******************************************************************************
491 * GetCountColorProfileElements [MSCMS.@]
493 * Retrieve the number of elements in a color profile.
496 * profile [I] Handle to a color profile.
497 * count [O] Pointer to a variable which is set to the number of elements
498 * in the color profile.
504 BOOL WINAPI
GetCountColorProfileElements( HPROFILE profile
, PDWORD count
)
508 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
510 TRACE( "( %p, %p )\n", profile
, count
);
512 if (!iccprofile
|| !count
) return FALSE
;
513 *count
= MSCMS_get_tag_count( iccprofile
);
516 #endif /* HAVE_LCMS */
520 /******************************************************************************
521 * GetStandardColorSpaceProfileA [MSCMS.@]
523 * See GetStandardColorSpaceProfileW.
525 BOOL WINAPI
GetStandardColorSpaceProfileA( PCSTR machine
, DWORD id
, PSTR profile
, PDWORD size
)
532 TRACE( "( 0x%08x, %p, %p )\n", id
, profile
, size
);
536 SetLastError( ERROR_NOT_SUPPORTED
);
542 SetLastError( ERROR_INVALID_PARAMETER
);
546 sizeW
= *size
* sizeof(WCHAR
);
550 ret
= GetStandardColorSpaceProfileW( NULL
, id
, NULL
, &sizeW
);
551 *size
= sizeW
/ sizeof(WCHAR
);
555 profileW
= HeapAlloc( GetProcessHeap(), 0, sizeW
);
559 if ((ret
= GetStandardColorSpaceProfileW( NULL
, id
, profileW
, &sizeW
)))
561 *size
= WideCharToMultiByte( CP_ACP
, 0, profileW
, -1, NULL
, 0, NULL
, NULL
);
562 len
= WideCharToMultiByte( CP_ACP
, 0, profileW
, -1, profile
, *size
, NULL
, NULL
);
563 if (!len
) ret
= FALSE
;
565 else *size
= sizeW
/ sizeof(WCHAR
);
567 HeapFree( GetProcessHeap(), 0, profileW
);
572 /******************************************************************************
573 * GetStandardColorSpaceProfileW [MSCMS.@]
575 * Retrieve the profile filename for a given standard color space id.
578 * machine [I] Name of the machine for which to get the standard color space.
579 * Must be NULL, which indicates the local machine.
580 * id [I] Id of a standard color space.
581 * profile [O] Buffer to receive the profile filename.
582 * size [I/O] Size of the filename buffer in bytes.
588 BOOL WINAPI
GetStandardColorSpaceProfileW( PCWSTR machine
, DWORD id
, PWSTR profile
, PDWORD size
)
590 static const WCHAR rgbprofilefile
[] =
591 { '\\','s','r','g','b',' ','c','o','l','o','r',' ',
592 's','p','a','c','e',' ','p','r','o','f','i','l','e','.','i','c','m',0 };
593 WCHAR rgbprofile
[MAX_PATH
];
594 DWORD len
= sizeof(rgbprofile
);
596 TRACE( "( 0x%08x, %p, %p )\n", id
, profile
, size
);
600 SetLastError( ERROR_NOT_SUPPORTED
);
606 SetLastError( ERROR_INVALID_PARAMETER
);
612 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
616 GetColorDirectoryW( machine
, rgbprofile
, &len
);
620 case SPACE_RGB
: /* 'RGB ' */
621 lstrcatW( rgbprofile
, rgbprofilefile
);
622 len
= lstrlenW( rgbprofile
) * sizeof(WCHAR
);
624 if (*size
< len
|| !profile
)
627 SetLastError( ERROR_MORE_DATA
);
631 lstrcpyW( profile
, rgbprofile
);
635 SetLastError( ERROR_FILE_NOT_FOUND
);
641 static BOOL
MSCMS_header_from_file( LPCWSTR file
, PPROFILEHEADER header
)
645 WCHAR path
[MAX_PATH
], slash
[] = {'\\',0};
646 DWORD size
= sizeof(path
);
649 ret
= GetColorDirectoryW( NULL
, path
, &size
);
652 WARN( "Can't retrieve color directory\n" );
655 if (size
+ sizeof(slash
) + sizeof(WCHAR
) * lstrlenW( file
) > sizeof(path
))
657 WARN( "Filename too long\n" );
661 lstrcatW( path
, slash
);
662 lstrcatW( path
, file
);
664 profile
.dwType
= PROFILE_FILENAME
;
665 profile
.pProfileData
= path
;
666 profile
.cbDataSize
= lstrlenW( path
) + 1;
668 handle
= OpenColorProfileW( &profile
, PROFILE_READ
, FILE_SHARE_READ
, OPEN_EXISTING
);
671 WARN( "Can't open color profile\n" );
675 ret
= GetColorProfileHeader( handle
, header
);
677 WARN( "Can't retrieve color profile header\n" );
679 CloseColorProfile( handle
);
683 static BOOL
MSCMS_match_profile( PENUMTYPEW rec
, PPROFILEHEADER hdr
)
685 if (rec
->dwFields
& ET_DEVICENAME
)
687 FIXME( "ET_DEVICENAME: %s\n", debugstr_w(rec
->pDeviceName
) );
689 if (rec
->dwFields
& ET_MEDIATYPE
)
691 FIXME( "ET_MEDIATYPE: 0x%08x\n", rec
->dwMediaType
);
693 if (rec
->dwFields
& ET_DITHERMODE
)
695 FIXME( "ET_DITHERMODE: 0x%08x\n", rec
->dwDitheringMode
);
697 if (rec
->dwFields
& ET_RESOLUTION
)
699 FIXME( "ET_RESOLUTION: 0x%08x, 0x%08x\n",
700 rec
->dwResolution
[0], rec
->dwResolution
[1] );
702 if (rec
->dwFields
& ET_DEVICECLASS
)
704 FIXME( "ET_DEVICECLASS: %s\n", MSCMS_dbgstr_tag(rec
->dwMediaType
) );
706 if (rec
->dwFields
& ET_CMMTYPE
)
708 TRACE( "ET_CMMTYPE: %s\n", MSCMS_dbgstr_tag(rec
->dwCMMType
) );
709 if (rec
->dwCMMType
!= hdr
->phCMMType
) return FALSE
;
711 if (rec
->dwFields
& ET_CLASS
)
713 TRACE( "ET_CLASS: %s\n", MSCMS_dbgstr_tag(rec
->dwClass
) );
714 if (rec
->dwClass
!= hdr
->phClass
) return FALSE
;
716 if (rec
->dwFields
& ET_DATACOLORSPACE
)
718 TRACE( "ET_DATACOLORSPACE: %s\n", MSCMS_dbgstr_tag(rec
->dwDataColorSpace
) );
719 if (rec
->dwDataColorSpace
!= hdr
->phDataColorSpace
) return FALSE
;
721 if (rec
->dwFields
& ET_CONNECTIONSPACE
)
723 TRACE( "ET_CONNECTIONSPACE: %s\n", MSCMS_dbgstr_tag(rec
->dwConnectionSpace
) );
724 if (rec
->dwConnectionSpace
!= hdr
->phConnectionSpace
) return FALSE
;
726 if (rec
->dwFields
& ET_SIGNATURE
)
728 TRACE( "ET_SIGNATURE: %s\n", MSCMS_dbgstr_tag(rec
->dwSignature
) );
729 if (rec
->dwSignature
!= hdr
->phSignature
) return FALSE
;
731 if (rec
->dwFields
& ET_PLATFORM
)
733 TRACE( "ET_PLATFORM: %s\n", MSCMS_dbgstr_tag(rec
->dwPlatform
) );
734 if (rec
->dwPlatform
!= hdr
->phPlatform
) return FALSE
;
736 if (rec
->dwFields
& ET_PROFILEFLAGS
)
738 TRACE( "ET_PROFILEFLAGS: 0x%08x\n", rec
->dwProfileFlags
);
739 if (rec
->dwProfileFlags
!= hdr
->phProfileFlags
) return FALSE
;
741 if (rec
->dwFields
& ET_MANUFACTURER
)
743 TRACE( "ET_MANUFACTURER: %s\n", MSCMS_dbgstr_tag(rec
->dwManufacturer
) );
744 if (rec
->dwManufacturer
!= hdr
->phManufacturer
) return FALSE
;
746 if (rec
->dwFields
& ET_MODEL
)
748 TRACE( "ET_MODEL: %s\n", MSCMS_dbgstr_tag(rec
->dwModel
) );
749 if (rec
->dwModel
!= hdr
->phModel
) return FALSE
;
751 if (rec
->dwFields
& ET_ATTRIBUTES
)
753 TRACE( "ET_ATTRIBUTES: 0x%08x, 0x%08x\n",
754 rec
->dwAttributes
[0], rec
->dwAttributes
[1] );
755 if (rec
->dwAttributes
[0] != hdr
->phAttributes
[0] ||
756 rec
->dwAttributes
[1] != hdr
->phAttributes
[1]) return FALSE
;
758 if (rec
->dwFields
& ET_RENDERINGINTENT
)
760 TRACE( "ET_RENDERINGINTENT: 0x%08x\n", rec
->dwRenderingIntent
);
761 if (rec
->dwRenderingIntent
!= hdr
->phRenderingIntent
) return FALSE
;
763 if (rec
->dwFields
& ET_CREATOR
)
765 TRACE( "ET_CREATOR: %s\n", MSCMS_dbgstr_tag(rec
->dwCreator
) );
766 if (rec
->dwCreator
!= hdr
->phCreator
) return FALSE
;
771 /******************************************************************************
772 * EnumColorProfilesA [MSCMS.@]
774 * See EnumColorProfilesW.
776 BOOL WINAPI
EnumColorProfilesA( PCSTR machine
, PENUMTYPEA record
, PBYTE buffer
,
777 PDWORD size
, PDWORD number
)
779 BOOL match
, ret
= FALSE
;
780 char spec
[] = "\\*.icm";
781 char colordir
[MAX_PATH
], glob
[MAX_PATH
], **profiles
= NULL
;
782 DWORD i
, len
= sizeof(colordir
), count
= 0, totalsize
= 0;
783 PROFILEHEADER header
;
784 WIN32_FIND_DATAA data
;
786 WCHAR
*fileW
= NULL
, *deviceW
= NULL
;
789 TRACE( "( %p, %p, %p, %p, %p )\n", machine
, record
, buffer
, size
, number
);
791 if (machine
|| !record
|| !size
||
792 record
->dwSize
!= sizeof(ENUMTYPEA
) ||
793 record
->dwVersion
!= ENUM_TYPE_VERSION
) return FALSE
;
795 ret
= GetColorDirectoryA( machine
, colordir
, &len
);
796 if (!ret
|| len
+ sizeof(spec
) > MAX_PATH
)
798 WARN( "can't retrieve color directory\n" );
802 lstrcpyA( glob
, colordir
);
803 lstrcatA( glob
, spec
);
805 find
= FindFirstFileA( glob
, &data
);
806 if (find
== INVALID_HANDLE_VALUE
) return FALSE
;
808 profiles
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(char *) + 1 );
809 if (!profiles
) goto exit
;
811 memcpy( &recordW
, record
, sizeof(ENUMTYPEA
) );
812 if (record
->pDeviceName
)
814 deviceW
= MSCMS_strdupW( record
->pDeviceName
);
815 if (!(recordW
.pDeviceName
= deviceW
)) goto exit
;
818 fileW
= MSCMS_strdupW( data
.cFileName
);
819 if (!fileW
) goto exit
;
821 ret
= MSCMS_header_from_file( fileW
, &header
);
824 match
= MSCMS_match_profile( &recordW
, &header
);
827 len
= sizeof(char) * (lstrlenA( data
.cFileName
) + 1);
828 profiles
[count
] = HeapAlloc( GetProcessHeap(), 0, len
);
830 if (!profiles
[count
]) goto exit
;
833 TRACE( "matching profile: %s\n", debugstr_a(data
.cFileName
) );
834 lstrcpyA( profiles
[count
], data
.cFileName
);
840 HeapFree( GetProcessHeap(), 0, fileW
);
843 while (FindNextFileA( find
, &data
))
845 fileW
= MSCMS_strdupW( data
.cFileName
);
846 if (!fileW
) goto exit
;
848 ret
= MSCMS_header_from_file( fileW
, &header
);
851 HeapFree( GetProcessHeap(), 0, fileW
);
855 match
= MSCMS_match_profile( &recordW
, &header
);
858 char **tmp
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
859 profiles
, sizeof(char *) * (count
+ 1) );
863 len
= sizeof(char) * (lstrlenA( data
.cFileName
) + 1);
864 profiles
[count
] = HeapAlloc( GetProcessHeap(), 0, len
);
866 if (!profiles
[count
]) goto exit
;
869 TRACE( "matching profile: %s\n", debugstr_a(data
.cFileName
) );
870 lstrcpyA( profiles
[count
], data
.cFileName
);
875 HeapFree( GetProcessHeap(), 0, fileW
);
880 if (buffer
&& *size
>= totalsize
)
882 char *p
= (char *)buffer
;
884 for (i
= 0; i
< count
; i
++)
886 lstrcpyA( p
, profiles
[i
] );
887 p
+= lstrlenA( profiles
[i
] ) + 1;
895 if (number
) *number
= count
;
898 for (i
= 0; i
< count
; i
++)
899 HeapFree( GetProcessHeap(), 0, profiles
[i
] );
900 HeapFree( GetProcessHeap(), 0, profiles
);
901 HeapFree( GetProcessHeap(), 0, deviceW
);
902 HeapFree( GetProcessHeap(), 0, fileW
);
908 /******************************************************************************
909 * EnumColorProfilesW [MSCMS.@]
911 * Enumerate profiles that match given criteria.
914 * machine [I] Name of the machine for which to enumerate profiles.
915 * Must be NULL, which indicates the local machine.
916 * record [I] Record of criteria that a profile must match.
917 * buffer [O] Buffer to receive a string array of profile filenames.
918 * size [I/O] Size of the filename buffer in bytes.
919 * number [O] Number of filenames copied into buffer.
925 BOOL WINAPI
EnumColorProfilesW( PCWSTR machine
, PENUMTYPEW record
, PBYTE buffer
,
926 PDWORD size
, PDWORD number
)
928 BOOL match
, ret
= FALSE
;
929 WCHAR spec
[] = {'\\','*','i','c','m',0};
930 WCHAR colordir
[MAX_PATH
], glob
[MAX_PATH
], **profiles
= NULL
;
931 DWORD i
, len
= sizeof(colordir
), count
= 0, totalsize
= 0;
932 PROFILEHEADER header
;
933 WIN32_FIND_DATAW data
;
936 TRACE( "( %p, %p, %p, %p, %p )\n", machine
, record
, buffer
, size
, number
);
938 if (machine
|| !record
|| !size
||
939 record
->dwSize
!= sizeof(ENUMTYPEW
) ||
940 record
->dwVersion
!= ENUM_TYPE_VERSION
) return FALSE
;
942 ret
= GetColorDirectoryW( machine
, colordir
, &len
);
943 if (!ret
|| len
+ sizeof(spec
) > MAX_PATH
)
945 WARN( "Can't retrieve color directory\n" );
949 lstrcpyW( glob
, colordir
);
950 lstrcatW( glob
, spec
);
952 find
= FindFirstFileW( glob
, &data
);
953 if (find
== INVALID_HANDLE_VALUE
) return FALSE
;
955 profiles
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WCHAR
*) + 1 );
956 if (!profiles
) goto exit
;
958 ret
= MSCMS_header_from_file( data
.cFileName
, &header
);
961 match
= MSCMS_match_profile( record
, &header
);
964 len
= sizeof(WCHAR
) * (lstrlenW( data
.cFileName
) + 1);
965 profiles
[count
] = HeapAlloc( GetProcessHeap(), 0, len
);
967 if (!profiles
[count
]) goto exit
;
970 TRACE( "matching profile: %s\n", debugstr_w(data
.cFileName
) );
971 lstrcpyW( profiles
[count
], data
.cFileName
);
978 while (FindNextFileW( find
, &data
))
980 ret
= MSCMS_header_from_file( data
.cFileName
, &header
);
983 match
= MSCMS_match_profile( record
, &header
);
986 WCHAR
**tmp
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
987 profiles
, sizeof(WCHAR
*) * (count
+ 1) );
991 len
= sizeof(WCHAR
) * (lstrlenW( data
.cFileName
) + 1);
992 profiles
[count
] = HeapAlloc( GetProcessHeap(), 0, len
);
994 if (!profiles
[count
]) goto exit
;
997 TRACE( "matching profile: %s\n", debugstr_w(data
.cFileName
) );
998 lstrcpyW( profiles
[count
], data
.cFileName
);
1006 if (buffer
&& *size
>= totalsize
)
1008 WCHAR
*p
= (WCHAR
*)buffer
;
1010 for (i
= 0; i
< count
; i
++)
1012 lstrcpyW( p
, profiles
[i
] );
1013 p
+= lstrlenW( profiles
[i
] ) + 1;
1021 if (number
) *number
= count
;
1024 for (i
= 0; i
< count
; i
++)
1025 HeapFree( GetProcessHeap(), 0, profiles
[i
] );
1026 HeapFree( GetProcessHeap(), 0, profiles
);
1032 /******************************************************************************
1033 * InstallColorProfileA [MSCMS.@]
1035 * See InstallColorProfileW.
1037 BOOL WINAPI
InstallColorProfileA( PCSTR machine
, PCSTR profile
)
1043 TRACE( "( %s )\n", debugstr_a(profile
) );
1045 if (machine
|| !profile
) return FALSE
;
1047 len
= MultiByteToWideChar( CP_ACP
, 0, profile
, -1, NULL
, 0 );
1048 profileW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1052 MultiByteToWideChar( CP_ACP
, 0, profile
, -1, profileW
, len
);
1054 ret
= InstallColorProfileW( NULL
, profileW
);
1055 HeapFree( GetProcessHeap(), 0, profileW
);
1060 /******************************************************************************
1061 * InstallColorProfileW [MSCMS.@]
1063 * Install a color profile.
1066 * machine [I] Name of the machine to install the profile on. Must be NULL,
1067 * which indicates the local machine.
1068 * profile [I] Full path name of the profile to install.
1074 BOOL WINAPI
InstallColorProfileW( PCWSTR machine
, PCWSTR profile
)
1076 WCHAR dest
[MAX_PATH
], base
[MAX_PATH
];
1077 DWORD size
= sizeof(dest
);
1078 static const WCHAR slash
[] = { '\\', 0 };
1080 TRACE( "( %s )\n", debugstr_w(profile
) );
1082 if (machine
|| !profile
) return FALSE
;
1084 if (!GetColorDirectoryW( machine
, dest
, &size
)) return FALSE
;
1086 MSCMS_basename( profile
, base
);
1088 lstrcatW( dest
, slash
);
1089 lstrcatW( dest
, base
);
1091 /* Is source equal to destination? */
1092 if (!lstrcmpW( profile
, dest
)) return TRUE
;
1094 return CopyFileW( profile
, dest
, TRUE
);
1097 /******************************************************************************
1098 * IsColorProfileTagPresent [MSCMS.@]
1100 * Determine if a given ICC tag type is present in a color profile.
1103 * profile [I] Color profile handle.
1104 * tag [I] ICC tag type.
1105 * present [O] Pointer to a BOOL variable. Set to TRUE if tag type is present,
1112 BOOL WINAPI
IsColorProfileTagPresent( HPROFILE profile
, TAGTYPE type
, PBOOL present
)
1116 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
1120 TRACE( "( %p, 0x%08x, %p )\n", profile
, type
, present
);
1122 if (!iccprofile
|| !present
) return FALSE
;
1124 count
= MSCMS_get_tag_count( iccprofile
);
1126 for (i
= 0; i
< count
; i
++)
1128 MSCMS_get_tag_by_index( iccprofile
, i
, &tag
);
1130 if (tag
.sig
== type
)
1132 *present
= ret
= TRUE
;
1137 #endif /* HAVE_LCMS */
1141 /******************************************************************************
1142 * IsColorProfileValid [MSCMS.@]
1144 * Determine if a given color profile is valid.
1147 * profile [I] Color profile handle.
1148 * valid [O] Pointer to a BOOL variable. Set to TRUE if profile is valid,
1155 BOOL WINAPI
IsColorProfileValid( HPROFILE profile
, PBOOL valid
)
1159 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
1161 TRACE( "( %p, %p )\n", profile
, valid
);
1163 if (!valid
) return FALSE
;
1164 if (iccprofile
) return *valid
= TRUE
;
1166 #endif /* HAVE_LCMS */
1170 /******************************************************************************
1171 * SetColorProfileElement [MSCMS.@]
1173 * Set data for a specified tag type.
1176 * profile [I] Handle to a color profile.
1177 * type [I] ICC tag type.
1178 * offset [I] Offset in bytes to start copying to.
1179 * size [I/O] Size of the buffer in bytes. On return the variable holds the
1180 * number of bytes actually needed.
1181 * buffer [O] Buffer holding the tag data.
1187 BOOL WINAPI
SetColorProfileElement( HPROFILE profile
, TAGTYPE type
, DWORD offset
, PDWORD size
,
1192 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
1193 DWORD i
, count
, access
= MSCMS_hprofile2access( profile
);
1196 TRACE( "( %p, 0x%08x, %d, %p, %p )\n", profile
, type
, offset
, size
, buffer
);
1198 if (!iccprofile
|| !size
|| !buffer
) return FALSE
;
1199 if (!(access
& PROFILE_READWRITE
)) return FALSE
;
1201 count
= MSCMS_get_tag_count( iccprofile
);
1203 for (i
= 0; i
< count
; i
++)
1205 MSCMS_get_tag_by_index( iccprofile
, i
, &tag
);
1207 if (tag
.sig
== type
)
1209 if (offset
> tag
.size
) return FALSE
;
1211 MSCMS_set_tag_data( iccprofile
, &tag
, offset
, buffer
);
1216 #endif /* HAVE_LCMS */
1220 /******************************************************************************
1221 * SetColorProfileHeader [MSCMS.@]
1223 * Set header data for a given profile.
1226 * profile [I] Handle to a color profile.
1227 * header [I] Buffer holding the header data.
1233 BOOL WINAPI
SetColorProfileHeader( HPROFILE profile
, PPROFILEHEADER header
)
1236 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
1237 DWORD access
= MSCMS_hprofile2access( profile
);
1239 TRACE( "( %p, %p )\n", profile
, header
);
1241 if (!iccprofile
|| !header
) return FALSE
;
1242 if (!(access
& PROFILE_READWRITE
)) return FALSE
;
1244 MSCMS_set_profile_header( iccprofile
, header
);
1249 #endif /* HAVE_LCMS */
1252 /******************************************************************************
1253 * UninstallColorProfileA [MSCMS.@]
1255 * See UninstallColorProfileW.
1257 BOOL WINAPI
UninstallColorProfileA( PCSTR machine
, PCSTR profile
, BOOL
delete )
1263 TRACE( "( %s, %x )\n", debugstr_a(profile
), delete );
1265 if (machine
|| !profile
) return FALSE
;
1267 len
= MultiByteToWideChar( CP_ACP
, 0, profile
, -1, NULL
, 0 );
1268 profileW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1272 MultiByteToWideChar( CP_ACP
, 0, profile
, -1, profileW
, len
);
1274 ret
= UninstallColorProfileW( NULL
, profileW
, delete );
1276 HeapFree( GetProcessHeap(), 0, profileW
);
1281 /******************************************************************************
1282 * UninstallColorProfileW [MSCMS.@]
1284 * Uninstall a color profile.
1287 * machine [I] Name of the machine to uninstall the profile on. Must be NULL,
1288 * which indicates the local machine.
1289 * profile [I] Full path name of the profile to uninstall.
1290 * delete [I] Bool that specifies whether the profile file should be deleted.
1296 BOOL WINAPI
UninstallColorProfileW( PCWSTR machine
, PCWSTR profile
, BOOL
delete )
1298 TRACE( "( %s, %x )\n", debugstr_w(profile
), delete );
1300 if (machine
|| !profile
) return FALSE
;
1302 if (delete) return DeleteFileW( profile
);
1307 /******************************************************************************
1308 * OpenColorProfileA [MSCMS.@]
1310 * See OpenColorProfileW.
1312 HPROFILE WINAPI
OpenColorProfileA( PPROFILE profile
, DWORD access
, DWORD sharing
, DWORD creation
)
1314 HPROFILE handle
= NULL
;
1316 TRACE( "( %p, 0x%08x, 0x%08x, 0x%08x )\n", profile
, access
, sharing
, creation
);
1318 if (!profile
|| !profile
->pProfileData
) return NULL
;
1320 /* No AW conversion needed for memory based profiles */
1321 if (profile
->dwType
& PROFILE_MEMBUFFER
)
1322 return OpenColorProfileW( profile
, access
, sharing
, creation
);
1324 if (profile
->dwType
& PROFILE_FILENAME
)
1329 profileW
.dwType
= profile
->dwType
;
1331 len
= MultiByteToWideChar( CP_ACP
, 0, profile
->pProfileData
, -1, NULL
, 0 );
1332 profileW
.pProfileData
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1334 if (profileW
.pProfileData
)
1336 profileW
.cbDataSize
= len
* sizeof(WCHAR
);
1337 MultiByteToWideChar( CP_ACP
, 0, profile
->pProfileData
, -1, profileW
.pProfileData
, len
);
1339 handle
= OpenColorProfileW( &profileW
, access
, sharing
, creation
);
1340 HeapFree( GetProcessHeap(), 0, profileW
.pProfileData
);
1346 /******************************************************************************
1347 * OpenColorProfileW [MSCMS.@]
1349 * Open a color profile.
1352 * profile [I] Pointer to a color profile structure.
1353 * access [I] Desired access.
1354 * sharing [I] Sharing mode.
1355 * creation [I] Creation mode.
1358 * Success: Handle to the opened profile.
1362 * Values for access: PROFILE_READ or PROFILE_READWRITE.
1363 * Values for sharing: 0 (no sharing), FILE_SHARE_READ and/or FILE_SHARE_WRITE.
1364 * Values for creation: one of CREATE_NEW, CREATE_ALWAYS, OPEN_EXISTING,
1365 * OPEN_ALWAYS, TRUNCATE_EXISTING.
1366 * Sharing and creation flags are ignored for memory based profiles.
1368 HPROFILE WINAPI
OpenColorProfileW( PPROFILE profile
, DWORD access
, DWORD sharing
, DWORD creation
)
1371 cmsHPROFILE cmsprofile
= NULL
;
1372 icProfile
*iccprofile
= NULL
;
1373 HANDLE handle
= NULL
;
1376 TRACE( "( %p, 0x%08x, 0x%08x, 0x%08x )\n", profile
, access
, sharing
, creation
);
1378 if (!profile
|| !profile
->pProfileData
) return NULL
;
1380 if (profile
->dwType
& PROFILE_MEMBUFFER
)
1382 /* FIXME: access flags not implemented for memory based profiles */
1384 iccprofile
= profile
->pProfileData
;
1385 size
= profile
->cbDataSize
;
1387 cmsprofile
= cmsOpenProfileFromMem( iccprofile
, size
);
1390 if (profile
->dwType
& PROFILE_FILENAME
)
1392 DWORD read
, flags
= 0;
1394 TRACE( "profile file: %s\n", debugstr_w( (WCHAR
*)profile
->pProfileData
) );
1396 if (access
& PROFILE_READ
) flags
= GENERIC_READ
;
1397 if (access
& PROFILE_READWRITE
) flags
= GENERIC_READ
|GENERIC_WRITE
;
1399 if (!flags
) return NULL
;
1401 handle
= CreateFileW( profile
->pProfileData
, flags
, sharing
, NULL
, creation
, 0, NULL
);
1402 if (handle
== INVALID_HANDLE_VALUE
)
1404 WARN( "Unable to open color profile\n" );
1408 if ((size
= GetFileSize( handle
, NULL
)) == INVALID_FILE_SIZE
)
1410 ERR( "Unable to retrieve size of color profile\n" );
1411 CloseHandle( handle
);
1415 iccprofile
= HeapAlloc( GetProcessHeap(), 0, size
);
1418 ERR( "Unable to allocate memory for color profile\n" );
1419 CloseHandle( handle
);
1423 if (!ReadFile( handle
, iccprofile
, size
, &read
, NULL
) || read
!= size
)
1425 ERR( "Unable to read color profile\n" );
1427 CloseHandle( handle
);
1428 HeapFree( GetProcessHeap(), 0, iccprofile
);
1432 cmsprofile
= cmsOpenProfileFromMem( iccprofile
, size
);
1436 return MSCMS_create_hprofile_handle( handle
, iccprofile
, cmsprofile
, access
);
1438 #endif /* HAVE_LCMS */
1442 /******************************************************************************
1443 * CloseColorProfile [MSCMS.@]
1445 * Close a color profile.
1448 * profile [I] Handle to the profile.
1454 BOOL WINAPI
CloseColorProfile( HPROFILE profile
)
1458 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
1459 HANDLE file
= MSCMS_hprofile2handle( profile
);
1460 DWORD access
= MSCMS_hprofile2access( profile
);
1462 TRACE( "( %p )\n", profile
);
1464 if (file
&& (access
& PROFILE_READWRITE
))
1466 DWORD written
, size
= MSCMS_get_profile_size( iccprofile
);
1468 if (SetFilePointer( file
, 0, NULL
, FILE_BEGIN
) ||
1469 !WriteFile( file
, iccprofile
, size
, &written
, NULL
) || written
!= size
)
1470 ERR( "Unable to write color profile\n" );
1473 ret
= cmsCloseProfile( MSCMS_hprofile2cmsprofile( profile
) );
1474 HeapFree( GetProcessHeap(), 0, MSCMS_hprofile2iccprofile( profile
) );
1476 CloseHandle( MSCMS_hprofile2handle( profile
) );
1477 MSCMS_destroy_hprofile_handle( profile
);
1479 #endif /* HAVE_LCMS */