mscms: Create a copy of memory based profiles.
[wine.git] / dlls / mscms / profile.c
blob76a8168b6c736afbab519e2c7535d25a287ca449
1 /*
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 #include "config.h"
22 #include "wine/debug.h"
23 #include "wine/unicode.h"
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winnls.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "winreg.h"
33 #include "icm.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 )
49 LPWSTR ret = NULL;
50 if (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 );
56 return ret;
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 )
72 int len;
73 BOOL ret = FALSE;
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 );
81 return FALSE;
83 if (machine)
85 SetLastError( ERROR_NOT_SUPPORTED );
86 return FALSE;
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 );
103 return ret;
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','\\',
113 'I','C','M',0};
114 PROFILEHEADER header;
115 PROFILE profile;
116 HPROFILE handle;
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 );
128 return FALSE;
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 );
145 return TRUE;
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 );
160 return FALSE;
162 if (machine)
164 SetLastError( ERROR_NOT_SUPPORTED );
165 return FALSE;
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 )
176 int len;
177 BOOL ret = FALSE;
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 );
185 return FALSE;
187 if (machine)
189 SetLastError( ERROR_NOT_SUPPORTED );
190 return FALSE;
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 );
207 return ret;
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 );
220 return FALSE;
222 if (machine)
224 SetLastError( ERROR_NOT_SUPPORTED );
225 return FALSE;
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 )
238 INT len;
239 LPWSTR bufferW;
240 BOOL ret = FALSE;
241 DWORD sizeW;
243 TRACE( "( %p, %p )\n", buffer, size );
245 if (machine || !size) return FALSE;
247 if (!buffer)
249 ret = GetColorDirectoryW( NULL, NULL, &sizeW );
250 *size = sizeW / sizeof(WCHAR);
251 return FALSE;
254 sizeW = *size * sizeof(WCHAR);
256 bufferW = HeapAlloc( GetProcessHeap(), 0, sizeW );
258 if (bufferW)
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 );
270 return ret;
273 /******************************************************************************
274 * GetColorDirectoryW [MSCMS.@]
276 * Get the directory where color profiles are stored.
278 * PARAMS
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};
290 DWORD len;
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 );
304 *size = len;
305 return TRUE;
308 SetLastError( ERROR_MORE_DATA );
309 *size = len;
310 return FALSE;
313 /******************************************************************************
314 * GetColorProfileElement [MSCMS.@]
316 * Retrieve data for a specified tag type.
318 * PARAMS
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.
328 * RETURNS
329 * Success: TRUE
330 * Failure: FALSE
332 BOOL WINAPI GetColorProfileElement( HPROFILE profile, TAGTYPE type, DWORD offset, PDWORD size,
333 PVOID buffer, PBOOL ref )
335 BOOL ret = FALSE;
336 #ifdef HAVE_LCMS
337 icProfile *iccprofile = MSCMS_hprofile2iccprofile( profile );
338 DWORD i, count;
339 icTag tag;
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 );
350 if (tag.sig == type)
352 if ((tag.size - offset) > *size || !buffer)
354 *size = (tag.size - offset);
355 return FALSE;
358 MSCMS_get_tag_data( iccprofile, &tag, offset, buffer );
360 *ref = FALSE; /* FIXME: calculate properly */
361 return TRUE;
365 #endif /* HAVE_LCMS */
366 return ret;
369 /******************************************************************************
370 * GetColorProfileElementTag [MSCMS.@]
372 * Get the tag type from a color profile by index.
374 * PARAMS
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.
379 * RETURNS
380 * Success: TRUE
381 * Failure: FALSE
383 * NOTES
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 )
389 BOOL ret = FALSE;
390 #ifdef HAVE_LCMS
391 icProfile *iccprofile = MSCMS_hprofile2iccprofile( profile );
392 DWORD count;
393 icTag tag;
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 );
403 *type = tag.sig;
405 ret = TRUE;
407 #endif /* HAVE_LCMS */
408 return ret;
411 /******************************************************************************
412 * GetColorProfileFromHandle [MSCMS.@]
414 * Retrieve an ICC color profile by handle.
416 * PARAMS
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.
422 * RETURNS
423 * Success: TRUE
424 * Failure: FALSE
426 * NOTES
427 * The profile returned will be in big-endian format.
429 BOOL WINAPI GetColorProfileFromHandle( HPROFILE profile, PBYTE buffer, PDWORD size )
431 BOOL ret = FALSE;
432 #ifdef HAVE_LCMS
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;
444 return FALSE;
447 /* No endian conversion needed */
448 memcpy( buffer, iccprofile, header.phSize );
450 *size = header.phSize;
451 ret = TRUE;
453 #endif /* HAVE_LCMS */
454 return ret;
457 /******************************************************************************
458 * GetColorProfileHeader [MSCMS.@]
460 * Retrieve a color profile header by handle.
462 * PARAMS
463 * profile [I] Handle to a color profile.
464 * header [O] Buffer to receive the ICC profile header.
466 * RETURNS
467 * Success: TRUE
468 * Failure: FALSE
470 * NOTES
471 * The profile header returned will be adjusted for endianess.
473 BOOL WINAPI GetColorProfileHeader( HPROFILE profile, PPROFILEHEADER header )
475 #ifdef HAVE_LCMS
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 );
483 return TRUE;
485 #else
486 return FALSE;
487 #endif /* HAVE_LCMS */
490 /******************************************************************************
491 * GetCountColorProfileElements [MSCMS.@]
493 * Retrieve the number of elements in a color profile.
495 * PARAMS
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.
500 * RETURNS
501 * Success: TRUE
502 * Failure: FALSE
504 BOOL WINAPI GetCountColorProfileElements( HPROFILE profile, PDWORD count )
506 BOOL ret = FALSE;
507 #ifdef HAVE_LCMS
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 );
514 ret = TRUE;
516 #endif /* HAVE_LCMS */
517 return ret;
520 /******************************************************************************
521 * GetStandardColorSpaceProfileA [MSCMS.@]
523 * See GetStandardColorSpaceProfileW.
525 BOOL WINAPI GetStandardColorSpaceProfileA( PCSTR machine, DWORD id, PSTR profile, PDWORD size )
527 INT len;
528 LPWSTR profileW;
529 BOOL ret = FALSE;
530 DWORD sizeW;
532 TRACE( "( 0x%08x, %p, %p )\n", id, profile, size );
534 if (machine)
536 SetLastError( ERROR_NOT_SUPPORTED );
537 return FALSE;
540 if (!size)
542 SetLastError( ERROR_INVALID_PARAMETER );
543 return FALSE;
546 sizeW = *size * sizeof(WCHAR);
548 if (!profile)
550 ret = GetStandardColorSpaceProfileW( NULL, id, NULL, &sizeW );
551 *size = sizeW / sizeof(WCHAR);
552 return FALSE;
555 profileW = HeapAlloc( GetProcessHeap(), 0, sizeW );
557 if (profileW)
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 );
569 return ret;
572 /******************************************************************************
573 * GetStandardColorSpaceProfileW [MSCMS.@]
575 * Retrieve the profile filename for a given standard color space id.
577 * PARAMS
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.
584 * RETURNS
585 * Success: TRUE
586 * Failure: FALSE
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 );
598 if (machine)
600 SetLastError( ERROR_NOT_SUPPORTED );
601 return FALSE;
604 if (!size)
606 SetLastError( ERROR_INVALID_PARAMETER );
607 return FALSE;
610 if (!profile)
612 SetLastError( ERROR_INSUFFICIENT_BUFFER );
613 return FALSE;
616 GetColorDirectoryW( machine, rgbprofile, &len );
618 switch (id)
620 case SPACE_RGB: /* 'RGB ' */
621 lstrcatW( rgbprofile, rgbprofilefile );
622 len = lstrlenW( rgbprofile ) * sizeof(WCHAR);
624 if (*size < len || !profile)
626 *size = len;
627 SetLastError( ERROR_MORE_DATA );
628 return FALSE;
631 lstrcpyW( profile, rgbprofile );
632 break;
634 default:
635 SetLastError( ERROR_FILE_NOT_FOUND );
636 return FALSE;
638 return TRUE;
641 static BOOL MSCMS_header_from_file( LPCWSTR file, PPROFILEHEADER header )
643 BOOL ret;
644 PROFILE profile;
645 WCHAR path[MAX_PATH], slash[] = {'\\',0};
646 DWORD size = sizeof(path);
647 HANDLE handle;
649 ret = GetColorDirectoryW( NULL, path, &size );
650 if (!ret)
652 WARN( "Can't retrieve color directory\n" );
653 return FALSE;
655 if (size + sizeof(slash) + sizeof(WCHAR) * lstrlenW( file ) > sizeof(path))
657 WARN( "Filename too long\n" );
658 return FALSE;
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 );
669 if (!handle)
671 WARN( "Can't open color profile\n" );
672 return FALSE;
675 ret = GetColorProfileHeader( handle, header );
676 if (!ret)
677 WARN( "Can't retrieve color profile header\n" );
679 CloseColorProfile( handle );
680 return ret;
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;
768 return TRUE;
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;
785 ENUMTYPEW recordW;
786 WCHAR *fileW = NULL, *deviceW = NULL;
787 HANDLE find;
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" );
799 return FALSE;
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 );
822 if (ret)
824 match = MSCMS_match_profile( &recordW, &header );
825 if (match)
827 len = sizeof(char) * (lstrlenA( data.cFileName ) + 1);
828 profiles[count] = HeapAlloc( GetProcessHeap(), 0, len );
830 if (!profiles[count]) goto exit;
831 else
833 TRACE( "matching profile: %s\n", debugstr_a(data.cFileName) );
834 lstrcpyA( profiles[count], data.cFileName );
835 totalsize += len;
836 count++;
840 HeapFree( GetProcessHeap(), 0, fileW );
841 fileW = NULL;
843 while (FindNextFileA( find, &data ))
845 fileW = MSCMS_strdupW( data.cFileName );
846 if (!fileW) goto exit;
848 ret = MSCMS_header_from_file( fileW, &header );
849 if (!ret)
851 HeapFree( GetProcessHeap(), 0, fileW );
852 continue;
855 match = MSCMS_match_profile( &recordW, &header );
856 if (match)
858 char **tmp = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
859 profiles, sizeof(char *) * (count + 1) );
860 if (!tmp) goto exit;
861 else profiles = tmp;
863 len = sizeof(char) * (lstrlenA( data.cFileName ) + 1);
864 profiles[count] = HeapAlloc( GetProcessHeap(), 0, len );
866 if (!profiles[count]) goto exit;
867 else
869 TRACE( "matching profile: %s\n", debugstr_a(data.cFileName) );
870 lstrcpyA( profiles[count], data.cFileName );
871 totalsize += len;
872 count++;
875 HeapFree( GetProcessHeap(), 0, fileW );
876 fileW = NULL;
879 totalsize++;
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;
889 *p = 0;
890 ret = TRUE;
892 else ret = FALSE;
894 *size = totalsize;
895 if (number) *number = count;
897 exit:
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 );
903 FindClose( find );
905 return ret;
908 /******************************************************************************
909 * EnumColorProfilesW [MSCMS.@]
911 * Enumerate profiles that match given criteria.
913 * PARAMS
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.
921 * RETURNS
922 * Success: TRUE
923 * Failure: FALSE
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;
934 HANDLE find;
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" );
946 return FALSE;
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 );
959 if (ret)
961 match = MSCMS_match_profile( record, &header );
962 if (match)
964 len = sizeof(WCHAR) * (lstrlenW( data.cFileName ) + 1);
965 profiles[count] = HeapAlloc( GetProcessHeap(), 0, len );
967 if (!profiles[count]) goto exit;
968 else
970 TRACE( "matching profile: %s\n", debugstr_w(data.cFileName) );
971 lstrcpyW( profiles[count], data.cFileName );
972 totalsize += len;
973 count++;
978 while (FindNextFileW( find, &data ))
980 ret = MSCMS_header_from_file( data.cFileName, &header );
981 if (!ret) continue;
983 match = MSCMS_match_profile( record, &header );
984 if (match)
986 WCHAR **tmp = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
987 profiles, sizeof(WCHAR *) * (count + 1) );
988 if (!tmp) goto exit;
989 else profiles = tmp;
991 len = sizeof(WCHAR) * (lstrlenW( data.cFileName ) + 1);
992 profiles[count] = HeapAlloc( GetProcessHeap(), 0, len );
994 if (!profiles[count]) goto exit;
995 else
997 TRACE( "matching profile: %s\n", debugstr_w(data.cFileName) );
998 lstrcpyW( profiles[count], data.cFileName );
999 totalsize += len;
1000 count++;
1005 totalsize++;
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;
1015 *p = 0;
1016 ret = TRUE;
1018 else ret = FALSE;
1020 *size = totalsize;
1021 if (number) *number = count;
1023 exit:
1024 for (i = 0; i < count; i++)
1025 HeapFree( GetProcessHeap(), 0, profiles[i] );
1026 HeapFree( GetProcessHeap(), 0, profiles );
1027 FindClose( find );
1029 return ret;
1032 /******************************************************************************
1033 * InstallColorProfileA [MSCMS.@]
1035 * See InstallColorProfileW.
1037 BOOL WINAPI InstallColorProfileA( PCSTR machine, PCSTR profile )
1039 UINT len;
1040 LPWSTR profileW;
1041 BOOL ret = FALSE;
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) );
1050 if (profileW)
1052 MultiByteToWideChar( CP_ACP, 0, profile, -1, profileW, len );
1054 ret = InstallColorProfileW( NULL, profileW );
1055 HeapFree( GetProcessHeap(), 0, profileW );
1057 return ret;
1060 /******************************************************************************
1061 * InstallColorProfileW [MSCMS.@]
1063 * Install a color profile.
1065 * PARAMS
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.
1070 * RETURNS
1071 * Success: TRUE
1072 * Failure: FALSE
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.
1102 * PARAMS
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,
1106 * FALSE otherwise.
1108 * RETURNS
1109 * Success: TRUE
1110 * Failure: FALSE
1112 BOOL WINAPI IsColorProfileTagPresent( HPROFILE profile, TAGTYPE type, PBOOL present )
1114 BOOL ret = FALSE;
1115 #ifdef HAVE_LCMS
1116 icProfile *iccprofile = MSCMS_hprofile2iccprofile( profile );
1117 DWORD i, count;
1118 icTag tag;
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;
1133 break;
1137 #endif /* HAVE_LCMS */
1138 return ret;
1141 /******************************************************************************
1142 * IsColorProfileValid [MSCMS.@]
1144 * Determine if a given color profile is valid.
1146 * PARAMS
1147 * profile [I] Color profile handle.
1148 * valid [O] Pointer to a BOOL variable. Set to TRUE if profile is valid,
1149 * FALSE otherwise.
1151 * RETURNS
1152 * Success: TRUE
1153 * Failure: FALSE
1155 BOOL WINAPI IsColorProfileValid( HPROFILE profile, PBOOL valid )
1157 BOOL ret = FALSE;
1158 #ifdef HAVE_LCMS
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 */
1167 return ret;
1170 /******************************************************************************
1171 * SetColorProfileElement [MSCMS.@]
1173 * Set data for a specified tag type.
1175 * PARAMS
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.
1183 * RETURNS
1184 * Success: TRUE
1185 * Failure: FALSE
1187 BOOL WINAPI SetColorProfileElement( HPROFILE profile, TAGTYPE type, DWORD offset, PDWORD size,
1188 PVOID buffer )
1190 BOOL ret = FALSE;
1191 #ifdef HAVE_LCMS
1192 icProfile *iccprofile = MSCMS_hprofile2iccprofile( profile );
1193 DWORD i, count, access = MSCMS_hprofile2access( profile );
1194 icTag tag;
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 );
1212 return TRUE;
1216 #endif /* HAVE_LCMS */
1217 return ret;
1220 /******************************************************************************
1221 * SetColorProfileHeader [MSCMS.@]
1223 * Set header data for a given profile.
1225 * PARAMS
1226 * profile [I] Handle to a color profile.
1227 * header [I] Buffer holding the header data.
1229 * RETURNS
1230 * Success: TRUE
1231 * Failure: FALSE
1233 BOOL WINAPI SetColorProfileHeader( HPROFILE profile, PPROFILEHEADER header )
1235 #ifdef HAVE_LCMS
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 );
1245 return TRUE;
1247 #else
1248 return FALSE;
1249 #endif /* HAVE_LCMS */
1252 /******************************************************************************
1253 * UninstallColorProfileA [MSCMS.@]
1255 * See UninstallColorProfileW.
1257 BOOL WINAPI UninstallColorProfileA( PCSTR machine, PCSTR profile, BOOL delete )
1259 UINT len;
1260 LPWSTR profileW;
1261 BOOL ret = FALSE;
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) );
1270 if (profileW)
1272 MultiByteToWideChar( CP_ACP, 0, profile, -1, profileW, len );
1274 ret = UninstallColorProfileW( NULL, profileW , delete );
1276 HeapFree( GetProcessHeap(), 0, profileW );
1278 return ret;
1281 /******************************************************************************
1282 * UninstallColorProfileW [MSCMS.@]
1284 * Uninstall a color profile.
1286 * PARAMS
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.
1292 * RETURNS
1293 * Success: TRUE
1294 * Failure: FALSE
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 );
1304 return TRUE;
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)
1326 UINT len;
1327 PROFILE profileW;
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 );
1343 return handle;
1346 /******************************************************************************
1347 * OpenColorProfileW [MSCMS.@]
1349 * Open a color profile.
1351 * PARAMS
1352 * profile [I] Pointer to a color profile structure.
1353 * access [I] Desired access.
1354 * sharing [I] Sharing mode.
1355 * creation [I] Creation mode.
1357 * RETURNS
1358 * Success: Handle to the opened profile.
1359 * Failure: NULL
1361 * NOTES
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 )
1370 #ifdef HAVE_LCMS
1371 cmsHPROFILE cmsprofile = NULL;
1372 icProfile *iccprofile = NULL;
1373 HANDLE handle = INVALID_HANDLE_VALUE;
1375 TRACE( "( %p, 0x%08x, 0x%08x, 0x%08x )\n", profile, access, sharing, creation );
1377 if (!profile || !profile->pProfileData) return NULL;
1379 if (profile->dwType == PROFILE_MEMBUFFER)
1381 /* FIXME: access flags not implemented for memory based profiles */
1383 if (!(iccprofile = HeapAlloc( GetProcessHeap(), 0, profile->cbDataSize ))) return NULL;
1384 memcpy( iccprofile, profile->pProfileData, profile->cbDataSize );
1386 cmsprofile = cmsOpenProfileFromMem( iccprofile, profile->cbDataSize );
1388 else if (profile->dwType == PROFILE_FILENAME)
1390 DWORD size, read, flags = 0;
1392 TRACE( "profile file: %s\n", debugstr_w( (WCHAR *)profile->pProfileData ) );
1394 if (access & PROFILE_READ) flags = GENERIC_READ;
1395 if (access & PROFILE_READWRITE) flags = GENERIC_READ|GENERIC_WRITE;
1397 if (!flags) return NULL;
1398 if (!sharing) sharing = FILE_SHARE_READ;
1400 handle = CreateFileW( profile->pProfileData, flags, sharing, NULL, creation, 0, NULL );
1401 if (handle == INVALID_HANDLE_VALUE)
1403 WARN( "Unable to open color profile %u\n", GetLastError() );
1404 return NULL;
1407 if ((size = GetFileSize( handle, NULL )) == INVALID_FILE_SIZE)
1409 ERR( "Unable to retrieve size of color profile\n" );
1410 CloseHandle( handle );
1411 return NULL;
1414 iccprofile = HeapAlloc( GetProcessHeap(), 0, size );
1415 if (!iccprofile)
1417 ERR( "Unable to allocate memory for color profile\n" );
1418 CloseHandle( handle );
1419 return NULL;
1422 if (!ReadFile( handle, iccprofile, size, &read, NULL ) || read != size)
1424 ERR( "Unable to read color profile\n" );
1426 CloseHandle( handle );
1427 HeapFree( GetProcessHeap(), 0, iccprofile );
1428 return NULL;
1431 cmsprofile = cmsOpenProfileFromMem( iccprofile, size );
1433 else
1435 ERR( "Invalid profile type %u\n", profile->dwType );
1436 return NULL;
1439 if (cmsprofile)
1440 return MSCMS_create_hprofile_handle( handle, iccprofile, cmsprofile, access );
1442 #endif /* HAVE_LCMS */
1443 return NULL;
1446 /******************************************************************************
1447 * CloseColorProfile [MSCMS.@]
1449 * Close a color profile.
1451 * PARAMS
1452 * profile [I] Handle to the profile.
1454 * RETURNS
1455 * Success: TRUE
1456 * Failure: FALSE
1458 BOOL WINAPI CloseColorProfile( HPROFILE profile )
1460 BOOL ret = FALSE;
1461 #ifdef HAVE_LCMS
1462 icProfile *iccprofile = MSCMS_hprofile2iccprofile( profile );
1463 HANDLE file = MSCMS_hprofile2handle( profile );
1464 DWORD access = MSCMS_hprofile2access( profile );
1466 TRACE( "( %p )\n", profile );
1468 if (file != INVALID_HANDLE_VALUE)
1470 if (access & PROFILE_READWRITE)
1472 DWORD written, size = MSCMS_get_profile_size( iccprofile );
1474 if (SetFilePointer( file, 0, NULL, FILE_BEGIN ) ||
1475 !WriteFile( file, iccprofile, size, &written, NULL ) || written != size)
1477 ERR( "Unable to write color profile\n" );
1480 CloseHandle( file );
1482 ret = cmsCloseProfile( MSCMS_hprofile2cmsprofile( profile ) );
1483 HeapFree( GetProcessHeap(), 0, iccprofile );
1485 MSCMS_destroy_hprofile_handle( profile );
1487 #endif /* HAVE_LCMS */
1488 return ret;