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 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
);
130 if (!GetColorProfileHeader( handle
, &header
))
132 CloseColorProfile( handle
);
133 SetLastError( ERROR_INVALID_PROFILE
);
136 RegCreateKeyExW( HKEY_LOCAL_MACHINE
, icmW
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &icm_key
, NULL
);
138 MSCMS_basename( file
, basenameW
);
139 sprintfW( classW
, fmtW
, (header
.phClass
>> 24) & 0xff, (header
.phClass
>> 16) & 0xff,
140 (header
.phClass
>> 8) & 0xff, header
.phClass
& 0xff );
142 RegCreateKeyExW( icm_key
, classW
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &class_key
, NULL
);
143 if (value
) RegSetValueExW( class_key
, basenameW
, 0, REG_BINARY
, value
, size
);
144 else RegDeleteValueW( class_key
, basenameW
);
146 RegCloseKey( class_key
);
147 RegCloseKey( icm_key
);
148 CloseColorProfile( handle
);
152 /******************************************************************************
153 * AssociateColorProfileWithDeviceW [MSCMS.@]
155 BOOL WINAPI
AssociateColorProfileWithDeviceW( PCWSTR machine
, PCWSTR profile
, PCWSTR device
)
157 static const BYTE dummy_value
[12];
159 TRACE( "( %s, %s, %s )\n", debugstr_w(machine
), debugstr_w(profile
), debugstr_w(device
) );
161 if (!profile
|| !device
)
163 SetLastError( ERROR_INVALID_PARAMETER
);
168 SetLastError( ERROR_NOT_SUPPORTED
);
172 return set_profile_device_key( profile
, dummy_value
, sizeof(dummy_value
) );
175 /******************************************************************************
176 * DisassociateColorProfileFromDeviceA [MSCMS.@]
178 BOOL WINAPI
DisassociateColorProfileFromDeviceA( PCSTR machine
, PCSTR profile
, PCSTR device
)
182 WCHAR
*profileW
, *deviceW
;
184 TRACE( "( %s, %s, %s )\n", debugstr_a(machine
), debugstr_a(profile
), debugstr_a(device
) );
186 if (!profile
|| !device
)
188 SetLastError( ERROR_INVALID_PARAMETER
);
193 SetLastError( ERROR_NOT_SUPPORTED
);
197 len
= MultiByteToWideChar( CP_ACP
, 0, profile
, -1, NULL
, 0 );
198 if (!(profileW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return FALSE
;
200 MultiByteToWideChar( CP_ACP
, 0, profile
, -1, profileW
, len
);
202 len
= MultiByteToWideChar( CP_ACP
, 0, device
, -1, NULL
, 0 );
203 if ((deviceW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
205 MultiByteToWideChar( CP_ACP
, 0, device
, -1, deviceW
, len
);
206 ret
= DisassociateColorProfileFromDeviceW( NULL
, profileW
, deviceW
);
209 HeapFree( GetProcessHeap(), 0, profileW
);
210 HeapFree( GetProcessHeap(), 0, deviceW
);
214 /******************************************************************************
215 * DisassociateColorProfileFromDeviceW [MSCMS.@]
217 BOOL WINAPI
DisassociateColorProfileFromDeviceW( PCWSTR machine
, PCWSTR profile
, PCWSTR device
)
219 TRACE( "( %s, %s, %s )\n", debugstr_w(machine
), debugstr_w(profile
), debugstr_w(device
) );
221 if (!profile
|| !device
)
223 SetLastError( ERROR_INVALID_PARAMETER
);
228 SetLastError( ERROR_NOT_SUPPORTED
);
232 return set_profile_device_key( profile
, NULL
, 0 );
235 /******************************************************************************
236 * GetColorDirectoryA [MSCMS.@]
238 * See GetColorDirectoryW.
240 BOOL WINAPI
GetColorDirectoryA( PCSTR machine
, PSTR buffer
, PDWORD size
)
247 TRACE( "( %p, %p )\n", buffer
, size
);
249 if (machine
|| !size
) return FALSE
;
253 ret
= GetColorDirectoryW( NULL
, NULL
, &sizeW
);
254 *size
= sizeW
/ sizeof(WCHAR
);
258 sizeW
= *size
* sizeof(WCHAR
);
260 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 profile
, TAGTYPE type
, DWORD offset
, PDWORD size
,
337 PVOID buffer
, PBOOL ref
)
341 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
345 TRACE( "( %p, 0x%08x, %d, %p, %p, %p )\n", profile
, type
, offset
, size
, buffer
, ref
);
347 if (!iccprofile
|| !size
|| !ref
) return FALSE
;
348 count
= MSCMS_get_tag_count( iccprofile
);
350 for (i
= 0; i
< count
; i
++)
352 MSCMS_get_tag_by_index( iccprofile
, i
, &tag
);
356 if ((tag
.size
- offset
) > *size
|| !buffer
)
358 *size
= (tag
.size
- offset
);
362 MSCMS_get_tag_data( iccprofile
, &tag
, offset
, buffer
);
364 *ref
= FALSE
; /* FIXME: calculate properly */
369 #endif /* HAVE_LCMS */
373 /******************************************************************************
374 * GetColorProfileElementTag [MSCMS.@]
376 * Get the tag type from a color profile by index.
379 * profile [I] Handle to a color profile.
380 * index [I] Index into the tag table of the color profile.
381 * type [O] Pointer to a variable that holds the ICC tag type on return.
388 * The tag table index starts at 1.
389 * Use GetCountColorProfileElements to retrieve a count of tagged elements.
391 BOOL WINAPI
GetColorProfileElementTag( HPROFILE profile
, DWORD index
, PTAGTYPE type
)
395 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
399 TRACE( "( %p, %d, %p )\n", profile
, index
, type
);
401 if (!iccprofile
|| !type
) return FALSE
;
403 count
= MSCMS_get_tag_count( iccprofile
);
404 if (index
> count
|| index
< 1) return FALSE
;
406 MSCMS_get_tag_by_index( iccprofile
, index
- 1, &tag
);
411 #endif /* HAVE_LCMS */
415 /******************************************************************************
416 * GetColorProfileFromHandle [MSCMS.@]
418 * Retrieve an ICC color profile by handle.
421 * profile [I] Handle to a color profile.
422 * buffer [O] Buffer to receive the ICC profile.
423 * size [I/O] Size of the buffer in bytes. On return the variable holds the
424 * number of bytes actually needed.
431 * The profile returned will be in big-endian format.
433 BOOL WINAPI
GetColorProfileFromHandle( HPROFILE profile
, PBYTE buffer
, PDWORD size
)
437 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
438 PROFILEHEADER header
;
440 TRACE( "( %p, %p, %p )\n", profile
, buffer
, size
);
442 if (!iccprofile
|| !size
) return FALSE
;
443 MSCMS_get_profile_header( iccprofile
, &header
);
445 if (!buffer
|| header
.phSize
> *size
)
447 *size
= header
.phSize
;
451 /* No endian conversion needed */
452 memcpy( buffer
, iccprofile
, header
.phSize
);
454 *size
= header
.phSize
;
457 #endif /* HAVE_LCMS */
461 /******************************************************************************
462 * GetColorProfileHeader [MSCMS.@]
464 * Retrieve a color profile header by handle.
467 * profile [I] Handle to a color profile.
468 * header [O] Buffer to receive the ICC profile header.
475 * The profile header returned will be adjusted for endianess.
477 BOOL WINAPI
GetColorProfileHeader( HPROFILE profile
, PPROFILEHEADER header
)
480 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
482 TRACE( "( %p, %p )\n", profile
, header
);
484 if (!iccprofile
|| !header
) return FALSE
;
486 MSCMS_get_profile_header( iccprofile
, header
);
491 #endif /* HAVE_LCMS */
494 /******************************************************************************
495 * GetCountColorProfileElements [MSCMS.@]
497 * Retrieve the number of elements in a color profile.
500 * profile [I] Handle to a color profile.
501 * count [O] Pointer to a variable which is set to the number of elements
502 * in the color profile.
508 BOOL WINAPI
GetCountColorProfileElements( HPROFILE profile
, PDWORD count
)
512 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
514 TRACE( "( %p, %p )\n", profile
, count
);
516 if (!iccprofile
|| !count
) return FALSE
;
517 *count
= MSCMS_get_tag_count( iccprofile
);
520 #endif /* HAVE_LCMS */
524 /******************************************************************************
525 * GetStandardColorSpaceProfileA [MSCMS.@]
527 * See GetStandardColorSpaceProfileW.
529 BOOL WINAPI
GetStandardColorSpaceProfileA( PCSTR machine
, DWORD id
, PSTR profile
, PDWORD size
)
536 TRACE( "( 0x%08x, %p, %p )\n", id
, profile
, size
);
540 SetLastError( ERROR_NOT_SUPPORTED
);
546 SetLastError( ERROR_INVALID_PARAMETER
);
550 sizeW
= *size
* sizeof(WCHAR
);
554 ret
= GetStandardColorSpaceProfileW( NULL
, id
, NULL
, &sizeW
);
555 *size
= sizeW
/ sizeof(WCHAR
);
559 profileW
= HeapAlloc( GetProcessHeap(), 0, sizeW
);
563 if ((ret
= GetStandardColorSpaceProfileW( NULL
, id
, profileW
, &sizeW
)))
565 *size
= WideCharToMultiByte( CP_ACP
, 0, profileW
, -1, NULL
, 0, NULL
, NULL
);
566 len
= WideCharToMultiByte( CP_ACP
, 0, profileW
, -1, profile
, *size
, NULL
, NULL
);
567 if (!len
) ret
= FALSE
;
569 else *size
= sizeW
/ sizeof(WCHAR
);
571 HeapFree( GetProcessHeap(), 0, profileW
);
576 /******************************************************************************
577 * GetStandardColorSpaceProfileW [MSCMS.@]
579 * Retrieve the profile filename for a given standard color space id.
582 * machine [I] Name of the machine for which to get the standard color space.
583 * Must be NULL, which indicates the local machine.
584 * id [I] Id of a standard color space.
585 * profile [O] Buffer to receive the profile filename.
586 * size [I/O] Size of the filename buffer in bytes.
592 BOOL WINAPI
GetStandardColorSpaceProfileW( PCWSTR machine
, DWORD id
, PWSTR profile
, PDWORD size
)
594 static const WCHAR rgbprofilefile
[] =
595 { '\\','s','r','g','b',' ','c','o','l','o','r',' ',
596 's','p','a','c','e',' ','p','r','o','f','i','l','e','.','i','c','m',0 };
597 WCHAR rgbprofile
[MAX_PATH
];
598 DWORD len
= sizeof(rgbprofile
);
600 TRACE( "( 0x%08x, %p, %p )\n", id
, profile
, size
);
604 SetLastError( ERROR_NOT_SUPPORTED
);
610 SetLastError( ERROR_INVALID_PARAMETER
);
616 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
620 GetColorDirectoryW( machine
, rgbprofile
, &len
);
624 case SPACE_RGB
: /* 'RGB ' */
625 lstrcatW( rgbprofile
, rgbprofilefile
);
626 len
= lstrlenW( rgbprofile
) * sizeof(WCHAR
);
628 if (*size
< len
|| !profile
)
631 SetLastError( ERROR_MORE_DATA
);
635 lstrcpyW( profile
, rgbprofile
);
639 SetLastError( ERROR_FILE_NOT_FOUND
);
645 static BOOL
MSCMS_header_from_file( LPCWSTR file
, PPROFILEHEADER header
)
649 WCHAR path
[MAX_PATH
], slash
[] = {'\\',0};
650 DWORD size
= sizeof(path
);
653 ret
= GetColorDirectoryW( NULL
, path
, &size
);
656 WARN( "Can't retrieve color directory\n" );
659 if (size
+ sizeof(slash
) + sizeof(WCHAR
) * lstrlenW( file
) > sizeof(path
))
661 WARN( "Filename too long\n" );
665 lstrcatW( path
, slash
);
666 lstrcatW( path
, file
);
668 profile
.dwType
= PROFILE_FILENAME
;
669 profile
.pProfileData
= path
;
670 profile
.cbDataSize
= lstrlenW( path
) + 1;
672 handle
= OpenColorProfileW( &profile
, PROFILE_READ
, FILE_SHARE_READ
, OPEN_EXISTING
);
675 WARN( "Can't open color profile\n" );
679 ret
= GetColorProfileHeader( handle
, header
);
681 WARN( "Can't retrieve color profile header\n" );
683 CloseColorProfile( handle
);
687 static BOOL
MSCMS_match_profile( PENUMTYPEW rec
, PPROFILEHEADER hdr
)
689 if (rec
->dwFields
& ET_DEVICENAME
)
691 FIXME( "ET_DEVICENAME: %s\n", debugstr_w(rec
->pDeviceName
) );
693 if (rec
->dwFields
& ET_MEDIATYPE
)
695 FIXME( "ET_MEDIATYPE: 0x%08x\n", rec
->dwMediaType
);
697 if (rec
->dwFields
& ET_DITHERMODE
)
699 FIXME( "ET_DITHERMODE: 0x%08x\n", rec
->dwDitheringMode
);
701 if (rec
->dwFields
& ET_RESOLUTION
)
703 FIXME( "ET_RESOLUTION: 0x%08x, 0x%08x\n",
704 rec
->dwResolution
[0], rec
->dwResolution
[1] );
706 if (rec
->dwFields
& ET_DEVICECLASS
)
708 FIXME( "ET_DEVICECLASS: %s\n", MSCMS_dbgstr_tag(rec
->dwMediaType
) );
710 if (rec
->dwFields
& ET_CMMTYPE
)
712 TRACE( "ET_CMMTYPE: %s\n", MSCMS_dbgstr_tag(rec
->dwCMMType
) );
713 if (rec
->dwCMMType
!= hdr
->phCMMType
) return FALSE
;
715 if (rec
->dwFields
& ET_CLASS
)
717 TRACE( "ET_CLASS: %s\n", MSCMS_dbgstr_tag(rec
->dwClass
) );
718 if (rec
->dwClass
!= hdr
->phClass
) return FALSE
;
720 if (rec
->dwFields
& ET_DATACOLORSPACE
)
722 TRACE( "ET_DATACOLORSPACE: %s\n", MSCMS_dbgstr_tag(rec
->dwDataColorSpace
) );
723 if (rec
->dwDataColorSpace
!= hdr
->phDataColorSpace
) return FALSE
;
725 if (rec
->dwFields
& ET_CONNECTIONSPACE
)
727 TRACE( "ET_CONNECTIONSPACE: %s\n", MSCMS_dbgstr_tag(rec
->dwConnectionSpace
) );
728 if (rec
->dwConnectionSpace
!= hdr
->phConnectionSpace
) return FALSE
;
730 if (rec
->dwFields
& ET_SIGNATURE
)
732 TRACE( "ET_SIGNATURE: %s\n", MSCMS_dbgstr_tag(rec
->dwSignature
) );
733 if (rec
->dwSignature
!= hdr
->phSignature
) return FALSE
;
735 if (rec
->dwFields
& ET_PLATFORM
)
737 TRACE( "ET_PLATFORM: %s\n", MSCMS_dbgstr_tag(rec
->dwPlatform
) );
738 if (rec
->dwPlatform
!= hdr
->phPlatform
) return FALSE
;
740 if (rec
->dwFields
& ET_PROFILEFLAGS
)
742 TRACE( "ET_PROFILEFLAGS: 0x%08x\n", rec
->dwProfileFlags
);
743 if (rec
->dwProfileFlags
!= hdr
->phProfileFlags
) return FALSE
;
745 if (rec
->dwFields
& ET_MANUFACTURER
)
747 TRACE( "ET_MANUFACTURER: %s\n", MSCMS_dbgstr_tag(rec
->dwManufacturer
) );
748 if (rec
->dwManufacturer
!= hdr
->phManufacturer
) return FALSE
;
750 if (rec
->dwFields
& ET_MODEL
)
752 TRACE( "ET_MODEL: %s\n", MSCMS_dbgstr_tag(rec
->dwModel
) );
753 if (rec
->dwModel
!= hdr
->phModel
) return FALSE
;
755 if (rec
->dwFields
& ET_ATTRIBUTES
)
757 TRACE( "ET_ATTRIBUTES: 0x%08x, 0x%08x\n",
758 rec
->dwAttributes
[0], rec
->dwAttributes
[1] );
759 if (rec
->dwAttributes
[0] != hdr
->phAttributes
[0] ||
760 rec
->dwAttributes
[1] != hdr
->phAttributes
[1]) return FALSE
;
762 if (rec
->dwFields
& ET_RENDERINGINTENT
)
764 TRACE( "ET_RENDERINGINTENT: 0x%08x\n", rec
->dwRenderingIntent
);
765 if (rec
->dwRenderingIntent
!= hdr
->phRenderingIntent
) return FALSE
;
767 if (rec
->dwFields
& ET_CREATOR
)
769 TRACE( "ET_CREATOR: %s\n", MSCMS_dbgstr_tag(rec
->dwCreator
) );
770 if (rec
->dwCreator
!= hdr
->phCreator
) return FALSE
;
775 /******************************************************************************
776 * EnumColorProfilesA [MSCMS.@]
778 * See EnumColorProfilesW.
780 BOOL WINAPI
EnumColorProfilesA( PCSTR machine
, PENUMTYPEA record
, PBYTE buffer
,
781 PDWORD size
, PDWORD number
)
783 BOOL match
, ret
= FALSE
;
784 char spec
[] = "\\*.icm";
785 char colordir
[MAX_PATH
], glob
[MAX_PATH
], **profiles
= NULL
;
786 DWORD i
, len
= sizeof(colordir
), count
= 0, totalsize
= 0;
787 PROFILEHEADER header
;
788 WIN32_FIND_DATAA data
;
790 WCHAR
*fileW
= NULL
, *deviceW
= NULL
;
793 TRACE( "( %p, %p, %p, %p, %p )\n", machine
, record
, buffer
, size
, number
);
795 if (machine
|| !record
|| !size
||
796 record
->dwSize
!= sizeof(ENUMTYPEA
) ||
797 record
->dwVersion
!= ENUM_TYPE_VERSION
) return FALSE
;
799 ret
= GetColorDirectoryA( machine
, colordir
, &len
);
800 if (!ret
|| len
+ sizeof(spec
) > MAX_PATH
)
802 WARN( "can't retrieve color directory\n" );
806 lstrcpyA( glob
, colordir
);
807 lstrcatA( glob
, spec
);
809 find
= FindFirstFileA( glob
, &data
);
810 if (find
== INVALID_HANDLE_VALUE
) return FALSE
;
812 profiles
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(char *) + 1 );
813 if (!profiles
) goto exit
;
815 memcpy( &recordW
, record
, sizeof(ENUMTYPEA
) );
816 if (record
->pDeviceName
)
818 deviceW
= MSCMS_strdupW( record
->pDeviceName
);
819 if (!(recordW
.pDeviceName
= deviceW
)) goto exit
;
822 fileW
= MSCMS_strdupW( data
.cFileName
);
823 if (!fileW
) goto exit
;
825 ret
= MSCMS_header_from_file( fileW
, &header
);
828 match
= MSCMS_match_profile( &recordW
, &header
);
831 len
= sizeof(char) * (lstrlenA( data
.cFileName
) + 1);
832 profiles
[count
] = HeapAlloc( GetProcessHeap(), 0, len
);
834 if (!profiles
[count
]) goto exit
;
837 TRACE( "matching profile: %s\n", debugstr_a(data
.cFileName
) );
838 lstrcpyA( profiles
[count
], data
.cFileName
);
844 HeapFree( GetProcessHeap(), 0, fileW
);
847 while (FindNextFileA( find
, &data
))
849 fileW
= MSCMS_strdupW( data
.cFileName
);
850 if (!fileW
) goto exit
;
852 ret
= MSCMS_header_from_file( fileW
, &header
);
855 HeapFree( GetProcessHeap(), 0, fileW
);
859 match
= MSCMS_match_profile( &recordW
, &header
);
862 char **tmp
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
863 profiles
, sizeof(char *) * (count
+ 1) );
867 len
= sizeof(char) * (lstrlenA( data
.cFileName
) + 1);
868 profiles
[count
] = HeapAlloc( GetProcessHeap(), 0, len
);
870 if (!profiles
[count
]) goto exit
;
873 TRACE( "matching profile: %s\n", debugstr_a(data
.cFileName
) );
874 lstrcpyA( profiles
[count
], data
.cFileName
);
879 HeapFree( GetProcessHeap(), 0, fileW
);
884 if (buffer
&& *size
>= totalsize
)
886 char *p
= (char *)buffer
;
888 for (i
= 0; i
< count
; i
++)
890 lstrcpyA( p
, profiles
[i
] );
891 p
+= lstrlenA( profiles
[i
] ) + 1;
899 if (number
) *number
= count
;
902 for (i
= 0; i
< count
; i
++)
903 HeapFree( GetProcessHeap(), 0, profiles
[i
] );
904 HeapFree( GetProcessHeap(), 0, profiles
);
905 HeapFree( GetProcessHeap(), 0, deviceW
);
906 HeapFree( GetProcessHeap(), 0, fileW
);
912 /******************************************************************************
913 * EnumColorProfilesW [MSCMS.@]
915 * Enumerate profiles that match given criteria.
918 * machine [I] Name of the machine for which to enumerate profiles.
919 * Must be NULL, which indicates the local machine.
920 * record [I] Record of criteria that a profile must match.
921 * buffer [O] Buffer to receive a string array of profile filenames.
922 * size [I/O] Size of the filename buffer in bytes.
923 * number [O] Number of filenames copied into buffer.
929 BOOL WINAPI
EnumColorProfilesW( PCWSTR machine
, PENUMTYPEW record
, PBYTE buffer
,
930 PDWORD size
, PDWORD number
)
932 BOOL match
, ret
= FALSE
;
933 WCHAR spec
[] = {'\\','*','i','c','m',0};
934 WCHAR colordir
[MAX_PATH
], glob
[MAX_PATH
], **profiles
= NULL
;
935 DWORD i
, len
= sizeof(colordir
), count
= 0, totalsize
= 0;
936 PROFILEHEADER header
;
937 WIN32_FIND_DATAW data
;
940 TRACE( "( %p, %p, %p, %p, %p )\n", machine
, record
, buffer
, size
, number
);
942 if (machine
|| !record
|| !size
||
943 record
->dwSize
!= sizeof(ENUMTYPEW
) ||
944 record
->dwVersion
!= ENUM_TYPE_VERSION
) return FALSE
;
946 ret
= GetColorDirectoryW( machine
, colordir
, &len
);
947 if (!ret
|| len
+ sizeof(spec
) > MAX_PATH
)
949 WARN( "Can't retrieve color directory\n" );
953 lstrcpyW( glob
, colordir
);
954 lstrcatW( glob
, spec
);
956 find
= FindFirstFileW( glob
, &data
);
957 if (find
== INVALID_HANDLE_VALUE
) return FALSE
;
959 profiles
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WCHAR
*) + 1 );
960 if (!profiles
) goto exit
;
962 ret
= MSCMS_header_from_file( data
.cFileName
, &header
);
965 match
= MSCMS_match_profile( record
, &header
);
968 len
= sizeof(WCHAR
) * (lstrlenW( data
.cFileName
) + 1);
969 profiles
[count
] = HeapAlloc( GetProcessHeap(), 0, len
);
971 if (!profiles
[count
]) goto exit
;
974 TRACE( "matching profile: %s\n", debugstr_w(data
.cFileName
) );
975 lstrcpyW( profiles
[count
], data
.cFileName
);
982 while (FindNextFileW( find
, &data
))
984 ret
= MSCMS_header_from_file( data
.cFileName
, &header
);
987 match
= MSCMS_match_profile( record
, &header
);
990 WCHAR
**tmp
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
991 profiles
, sizeof(WCHAR
*) * (count
+ 1) );
995 len
= sizeof(WCHAR
) * (lstrlenW( data
.cFileName
) + 1);
996 profiles
[count
] = HeapAlloc( GetProcessHeap(), 0, len
);
998 if (!profiles
[count
]) goto exit
;
1001 TRACE( "matching profile: %s\n", debugstr_w(data
.cFileName
) );
1002 lstrcpyW( profiles
[count
], data
.cFileName
);
1010 if (buffer
&& *size
>= totalsize
)
1012 WCHAR
*p
= (WCHAR
*)buffer
;
1014 for (i
= 0; i
< count
; i
++)
1016 lstrcpyW( p
, profiles
[i
] );
1017 p
+= lstrlenW( profiles
[i
] ) + 1;
1025 if (number
) *number
= count
;
1028 for (i
= 0; i
< count
; i
++)
1029 HeapFree( GetProcessHeap(), 0, profiles
[i
] );
1030 HeapFree( GetProcessHeap(), 0, profiles
);
1036 /******************************************************************************
1037 * InstallColorProfileA [MSCMS.@]
1039 * See InstallColorProfileW.
1041 BOOL WINAPI
InstallColorProfileA( PCSTR machine
, PCSTR profile
)
1047 TRACE( "( %s )\n", debugstr_a(profile
) );
1049 if (machine
|| !profile
) return FALSE
;
1051 len
= MultiByteToWideChar( CP_ACP
, 0, profile
, -1, NULL
, 0 );
1052 profileW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1056 MultiByteToWideChar( CP_ACP
, 0, profile
, -1, profileW
, len
);
1058 ret
= InstallColorProfileW( NULL
, profileW
);
1059 HeapFree( GetProcessHeap(), 0, profileW
);
1064 /******************************************************************************
1065 * InstallColorProfileW [MSCMS.@]
1067 * Install a color profile.
1070 * machine [I] Name of the machine to install the profile on. Must be NULL,
1071 * which indicates the local machine.
1072 * profile [I] Full path name of the profile to install.
1078 BOOL WINAPI
InstallColorProfileW( PCWSTR machine
, PCWSTR profile
)
1080 WCHAR dest
[MAX_PATH
], base
[MAX_PATH
];
1081 DWORD size
= sizeof(dest
);
1082 static const WCHAR slash
[] = { '\\', 0 };
1084 TRACE( "( %s )\n", debugstr_w(profile
) );
1086 if (machine
|| !profile
) return FALSE
;
1088 if (!GetColorDirectoryW( machine
, dest
, &size
)) return FALSE
;
1090 MSCMS_basename( profile
, base
);
1092 lstrcatW( dest
, slash
);
1093 lstrcatW( dest
, base
);
1095 /* Is source equal to destination? */
1096 if (!lstrcmpW( profile
, dest
)) return TRUE
;
1098 return CopyFileW( profile
, dest
, TRUE
);
1101 /******************************************************************************
1102 * IsColorProfileTagPresent [MSCMS.@]
1104 * Determine if a given ICC tag type is present in a color profile.
1107 * profile [I] Color profile handle.
1108 * tag [I] ICC tag type.
1109 * present [O] Pointer to a BOOL variable. Set to TRUE if tag type is present,
1116 BOOL WINAPI
IsColorProfileTagPresent( HPROFILE profile
, TAGTYPE type
, PBOOL present
)
1120 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
1124 TRACE( "( %p, 0x%08x, %p )\n", profile
, type
, present
);
1126 if (!iccprofile
|| !present
) return FALSE
;
1128 count
= MSCMS_get_tag_count( iccprofile
);
1130 for (i
= 0; i
< count
; i
++)
1132 MSCMS_get_tag_by_index( iccprofile
, i
, &tag
);
1134 if (tag
.sig
== type
)
1136 *present
= ret
= TRUE
;
1141 #endif /* HAVE_LCMS */
1145 /******************************************************************************
1146 * IsColorProfileValid [MSCMS.@]
1148 * Determine if a given color profile is valid.
1151 * profile [I] Color profile handle.
1152 * valid [O] Pointer to a BOOL variable. Set to TRUE if profile is valid,
1159 BOOL WINAPI
IsColorProfileValid( HPROFILE profile
, PBOOL valid
)
1163 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
1165 TRACE( "( %p, %p )\n", profile
, valid
);
1167 if (!valid
) return FALSE
;
1168 if (iccprofile
) return *valid
= TRUE
;
1170 #endif /* HAVE_LCMS */
1174 /******************************************************************************
1175 * SetColorProfileElement [MSCMS.@]
1177 * Set data for a specified tag type.
1180 * profile [I] Handle to a color profile.
1181 * type [I] ICC tag type.
1182 * offset [I] Offset in bytes to start copying to.
1183 * size [I/O] Size of the buffer in bytes. On return the variable holds the
1184 * number of bytes actually needed.
1185 * buffer [O] Buffer holding the tag data.
1191 BOOL WINAPI
SetColorProfileElement( HPROFILE profile
, TAGTYPE type
, DWORD offset
, PDWORD size
,
1196 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
1197 DWORD i
, count
, access
= MSCMS_hprofile2access( profile
);
1200 TRACE( "( %p, 0x%08x, %d, %p, %p )\n", profile
, type
, offset
, size
, buffer
);
1202 if (!iccprofile
|| !size
|| !buffer
) return FALSE
;
1203 if (!(access
& PROFILE_READWRITE
)) return FALSE
;
1205 count
= MSCMS_get_tag_count( iccprofile
);
1207 for (i
= 0; i
< count
; i
++)
1209 MSCMS_get_tag_by_index( iccprofile
, i
, &tag
);
1211 if (tag
.sig
== type
)
1213 if (offset
> tag
.size
) return FALSE
;
1215 MSCMS_set_tag_data( iccprofile
, &tag
, offset
, buffer
);
1220 #endif /* HAVE_LCMS */
1224 /******************************************************************************
1225 * SetColorProfileHeader [MSCMS.@]
1227 * Set header data for a given profile.
1230 * profile [I] Handle to a color profile.
1231 * header [I] Buffer holding the header data.
1237 BOOL WINAPI
SetColorProfileHeader( HPROFILE profile
, PPROFILEHEADER header
)
1240 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
1241 DWORD access
= MSCMS_hprofile2access( profile
);
1243 TRACE( "( %p, %p )\n", profile
, header
);
1245 if (!iccprofile
|| !header
) return FALSE
;
1246 if (!(access
& PROFILE_READWRITE
)) return FALSE
;
1248 MSCMS_set_profile_header( iccprofile
, header
);
1253 #endif /* HAVE_LCMS */
1256 /******************************************************************************
1257 * UninstallColorProfileA [MSCMS.@]
1259 * See UninstallColorProfileW.
1261 BOOL WINAPI
UninstallColorProfileA( PCSTR machine
, PCSTR profile
, BOOL
delete )
1267 TRACE( "( %s, %x )\n", debugstr_a(profile
), delete );
1269 if (machine
|| !profile
) return FALSE
;
1271 len
= MultiByteToWideChar( CP_ACP
, 0, profile
, -1, NULL
, 0 );
1272 profileW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1276 MultiByteToWideChar( CP_ACP
, 0, profile
, -1, profileW
, len
);
1278 ret
= UninstallColorProfileW( NULL
, profileW
, delete );
1280 HeapFree( GetProcessHeap(), 0, profileW
);
1285 /******************************************************************************
1286 * UninstallColorProfileW [MSCMS.@]
1288 * Uninstall a color profile.
1291 * machine [I] Name of the machine to uninstall the profile on. Must be NULL,
1292 * which indicates the local machine.
1293 * profile [I] Full path name of the profile to uninstall.
1294 * delete [I] Bool that specifies whether the profile file should be deleted.
1300 BOOL WINAPI
UninstallColorProfileW( PCWSTR machine
, PCWSTR profile
, BOOL
delete )
1302 TRACE( "( %s, %x )\n", debugstr_w(profile
), delete );
1304 if (machine
|| !profile
) return FALSE
;
1306 if (delete) return DeleteFileW( profile
);
1311 /******************************************************************************
1312 * OpenColorProfileA [MSCMS.@]
1314 * See OpenColorProfileW.
1316 HPROFILE WINAPI
OpenColorProfileA( PPROFILE profile
, DWORD access
, DWORD sharing
, DWORD creation
)
1318 HPROFILE handle
= NULL
;
1320 TRACE( "( %p, 0x%08x, 0x%08x, 0x%08x )\n", profile
, access
, sharing
, creation
);
1322 if (!profile
|| !profile
->pProfileData
) return NULL
;
1324 /* No AW conversion needed for memory based profiles */
1325 if (profile
->dwType
& PROFILE_MEMBUFFER
)
1326 return OpenColorProfileW( profile
, access
, sharing
, creation
);
1328 if (profile
->dwType
& PROFILE_FILENAME
)
1333 profileW
.dwType
= profile
->dwType
;
1335 len
= MultiByteToWideChar( CP_ACP
, 0, profile
->pProfileData
, -1, NULL
, 0 );
1336 profileW
.pProfileData
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1338 if (profileW
.pProfileData
)
1340 profileW
.cbDataSize
= len
* sizeof(WCHAR
);
1341 MultiByteToWideChar( CP_ACP
, 0, profile
->pProfileData
, -1, profileW
.pProfileData
, len
);
1343 handle
= OpenColorProfileW( &profileW
, access
, sharing
, creation
);
1344 HeapFree( GetProcessHeap(), 0, profileW
.pProfileData
);
1350 /******************************************************************************
1351 * OpenColorProfileW [MSCMS.@]
1353 * Open a color profile.
1356 * profile [I] Pointer to a color profile structure.
1357 * access [I] Desired access.
1358 * sharing [I] Sharing mode.
1359 * creation [I] Creation mode.
1362 * Success: Handle to the opened profile.
1366 * Values for access: PROFILE_READ or PROFILE_READWRITE.
1367 * Values for sharing: 0 (no sharing), FILE_SHARE_READ and/or FILE_SHARE_WRITE.
1368 * Values for creation: one of CREATE_NEW, CREATE_ALWAYS, OPEN_EXISTING,
1369 * OPEN_ALWAYS, TRUNCATE_EXISTING.
1370 * Sharing and creation flags are ignored for memory based profiles.
1372 HPROFILE WINAPI
OpenColorProfileW( PPROFILE profile
, DWORD access
, DWORD sharing
, DWORD creation
)
1375 cmsHPROFILE cmsprofile
= NULL
;
1376 icProfile
*iccprofile
= NULL
;
1377 HANDLE handle
= INVALID_HANDLE_VALUE
;
1379 TRACE( "( %p, 0x%08x, 0x%08x, 0x%08x )\n", profile
, access
, sharing
, creation
);
1381 if (!profile
|| !profile
->pProfileData
) return NULL
;
1383 if (profile
->dwType
== PROFILE_MEMBUFFER
)
1385 /* FIXME: access flags not implemented for memory based profiles */
1387 if (!(iccprofile
= HeapAlloc( GetProcessHeap(), 0, profile
->cbDataSize
))) return NULL
;
1388 memcpy( iccprofile
, profile
->pProfileData
, profile
->cbDataSize
);
1390 cmsprofile
= cmsOpenProfileFromMem( iccprofile
, profile
->cbDataSize
);
1392 else if (profile
->dwType
== PROFILE_FILENAME
)
1394 DWORD size
, read
, flags
= 0;
1396 TRACE( "profile file: %s\n", debugstr_w( (WCHAR
*)profile
->pProfileData
) );
1398 if (access
& PROFILE_READ
) flags
= GENERIC_READ
;
1399 if (access
& PROFILE_READWRITE
) flags
= GENERIC_READ
|GENERIC_WRITE
;
1401 if (!flags
) return NULL
;
1402 if (!sharing
) sharing
= FILE_SHARE_READ
;
1404 handle
= CreateFileW( profile
->pProfileData
, flags
, sharing
, NULL
, creation
, 0, NULL
);
1405 if (handle
== INVALID_HANDLE_VALUE
)
1407 WARN( "Unable to open color profile %u\n", GetLastError() );
1411 if ((size
= GetFileSize( handle
, NULL
)) == INVALID_FILE_SIZE
)
1413 ERR( "Unable to retrieve size of color profile\n" );
1414 CloseHandle( handle
);
1418 iccprofile
= HeapAlloc( GetProcessHeap(), 0, size
);
1421 ERR( "Unable to allocate memory for color profile\n" );
1422 CloseHandle( handle
);
1426 if (!ReadFile( handle
, iccprofile
, size
, &read
, NULL
) || read
!= size
)
1428 ERR( "Unable to read color profile\n" );
1430 CloseHandle( handle
);
1431 HeapFree( GetProcessHeap(), 0, iccprofile
);
1435 cmsprofile
= cmsOpenProfileFromMem( iccprofile
, size
);
1439 ERR( "Invalid profile type %u\n", profile
->dwType
);
1444 return MSCMS_create_hprofile_handle( handle
, iccprofile
, cmsprofile
, access
);
1446 #endif /* HAVE_LCMS */
1450 /******************************************************************************
1451 * CloseColorProfile [MSCMS.@]
1453 * Close a color profile.
1456 * profile [I] Handle to the profile.
1462 BOOL WINAPI
CloseColorProfile( HPROFILE profile
)
1466 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
1467 HANDLE file
= MSCMS_hprofile2handle( profile
);
1468 DWORD access
= MSCMS_hprofile2access( profile
);
1470 TRACE( "( %p )\n", profile
);
1472 if (file
!= INVALID_HANDLE_VALUE
)
1474 if (access
& PROFILE_READWRITE
)
1476 DWORD written
, size
= MSCMS_get_profile_size( iccprofile
);
1478 if (SetFilePointer( file
, 0, NULL
, FILE_BEGIN
) ||
1479 !WriteFile( file
, iccprofile
, size
, &written
, NULL
) || written
!= size
)
1481 ERR( "Unable to write color profile\n" );
1484 CloseHandle( file
);
1486 ret
= cmsCloseProfile( MSCMS_hprofile2cmsprofile( profile
) );
1487 HeapFree( GetProcessHeap(), 0, iccprofile
);
1489 MSCMS_destroy_hprofile_handle( profile
);
1491 #endif /* HAVE_LCMS */