2 * MSCMS - Color Management System for Wine
4 * Copyright 2004, 2005, 2006 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"
33 #include "mscms_priv.h"
35 #define IS_SEPARATOR(ch) ((ch) == '\\' || (ch) == '/')
37 static void MSCMS_basename( LPCWSTR path
, LPWSTR name
)
39 INT i
= lstrlenW( path
);
41 while (i
> 0 && !IS_SEPARATOR(path
[i
- 1])) i
--;
42 lstrcpyW( name
, &path
[i
] );
45 static inline LPWSTR
MSCMS_strdupW( LPCSTR str
)
50 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
51 if ((ret
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
52 MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
57 static const char *MSCMS_dbgstr_tag( DWORD tag
)
59 return wine_dbg_sprintf( "'%c%c%c%c'",
60 (char)(tag
>> 24), (char)(tag
>> 16), (char)(tag
>> 8), (char)(tag
) );
63 WINE_DEFAULT_DEBUG_CHANNEL(mscms
);
65 /******************************************************************************
66 * GetColorDirectoryA [MSCMS.@]
68 * See GetColorDirectoryW.
70 BOOL WINAPI
GetColorDirectoryA( PCSTR machine
, PSTR buffer
, PDWORD size
)
77 TRACE( "( %p, %p )\n", buffer
, size
);
79 if (machine
|| !size
) return FALSE
;
83 ret
= GetColorDirectoryW( NULL
, NULL
, &sizeW
);
84 *size
= sizeW
/ sizeof(WCHAR
);
88 sizeW
= *size
* sizeof(WCHAR
);
90 bufferW
= HeapAlloc( GetProcessHeap(), 0, sizeW
);
94 ret
= GetColorDirectoryW( NULL
, bufferW
, &sizeW
);
95 *size
= WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
99 len
= WideCharToMultiByte( CP_ACP
, 0, bufferW
, *size
, buffer
, *size
, NULL
, NULL
);
100 if (!len
) ret
= FALSE
;
103 HeapFree( GetProcessHeap(), 0, bufferW
);
108 /******************************************************************************
109 * GetColorDirectoryW [MSCMS.@]
111 * Get the directory where color profiles are stored.
114 * machine [I] Name of the machine for which to get the color directory.
115 * Must be NULL, which indicates the local machine.
116 * buffer [I] Buffer to receive the path name.
117 * size [I/O] Size of the buffer in bytes. On return the variable holds
118 * the number of bytes actually needed.
120 BOOL WINAPI
GetColorDirectoryW( PCWSTR machine
, PWSTR buffer
, PDWORD size
)
122 WCHAR colordir
[MAX_PATH
];
123 static const WCHAR colorsubdir
[] = { '\\','c','o','l','o','r',0 };
126 TRACE( "( %p, %p )\n", buffer
, size
);
128 if (machine
|| !size
) return FALSE
;
130 GetSystemDirectoryW( colordir
, sizeof(colordir
) / sizeof(WCHAR
) );
131 lstrcatW( colordir
, colorsubdir
);
133 len
= lstrlenW( colordir
) * sizeof(WCHAR
);
135 if (len
<= *size
&& buffer
)
137 lstrcpyW( buffer
, colordir
);
146 /******************************************************************************
147 * GetColorProfileElement [MSCMS.@]
149 * Retrieve data for a specified tag type.
152 * profile [I] Handle to a color profile.
153 * type [I] ICC tag type.
154 * offset [I] Offset in bytes to start copying from.
155 * size [I/O] Size of the buffer in bytes. On return the variable holds
156 * the number of bytes actually needed.
157 * buffer [O] Buffer to receive the tag data.
158 * ref [O] Pointer to a BOOL that specifies whether more than one tag
159 * references the data.
165 BOOL WINAPI
GetColorProfileElement( HPROFILE profile
, TAGTYPE type
, DWORD offset
, PDWORD size
,
166 PVOID buffer
, PBOOL ref
)
170 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
174 TRACE( "( %p, 0x%08lx, %ld, %p, %p, %p )\n", profile
, type
, offset
, size
, buffer
, ref
);
176 if (!iccprofile
|| !size
|| !ref
) return FALSE
;
177 count
= MSCMS_get_tag_count( iccprofile
);
179 for (i
= 0; i
< count
; i
++)
181 MSCMS_get_tag_by_index( iccprofile
, i
, &tag
);
185 if ((tag
.size
- offset
) > *size
|| !buffer
)
187 *size
= (tag
.size
- offset
);
191 MSCMS_get_tag_data( iccprofile
, &tag
, offset
, buffer
);
193 *ref
= FALSE
; /* FIXME: calculate properly */
198 #endif /* HAVE_LCMS */
202 /******************************************************************************
203 * GetColorProfileElementTag [MSCMS.@]
205 * Get the tag type from a color profile by index.
208 * profile [I] Handle to a color profile.
209 * index [I] Index into the tag table of the color profile.
210 * type [O] Pointer to a variable that holds the ICC tag type on return.
217 * The tag table index starts at 1.
218 * Use GetCountColorProfileElements to retrieve a count of tagged elements.
220 BOOL WINAPI
GetColorProfileElementTag( HPROFILE profile
, DWORD index
, PTAGTYPE type
)
224 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
228 TRACE( "( %p, %ld, %p )\n", profile
, index
, type
);
230 if (!iccprofile
|| !type
) return FALSE
;
232 count
= MSCMS_get_tag_count( iccprofile
);
233 if (index
> count
|| index
< 1) return FALSE
;
235 MSCMS_get_tag_by_index( iccprofile
, index
- 1, &tag
);
240 #endif /* HAVE_LCMS */
244 /******************************************************************************
245 * GetColorProfileFromHandle [MSCMS.@]
247 * Retrieve an ICC color profile by handle.
250 * profile [I] Handle to a color profile.
251 * buffer [O] Buffer to receive the ICC profile.
252 * size [I/O] Size of the buffer in bytes. On return the variable holds the
253 * number of bytes actually needed.
260 * The profile returned will be in big-endian format.
262 BOOL WINAPI
GetColorProfileFromHandle( HPROFILE profile
, PBYTE buffer
, PDWORD size
)
266 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
267 PROFILEHEADER header
;
269 TRACE( "( %p, %p, %p )\n", profile
, buffer
, size
);
271 if (!iccprofile
|| !size
) return FALSE
;
272 MSCMS_get_profile_header( iccprofile
, &header
);
274 if (!buffer
|| header
.phSize
> *size
)
276 *size
= header
.phSize
;
280 /* No endian conversion needed */
281 memcpy( buffer
, iccprofile
, header
.phSize
);
283 *size
= header
.phSize
;
286 #endif /* HAVE_LCMS */
290 /******************************************************************************
291 * GetColorProfileHeader [MSCMS.@]
293 * Retrieve a color profile header by handle.
296 * profile [I] Handle to a color profile.
297 * header [O] Buffer to receive the ICC profile header.
304 * The profile header returned will be adjusted for endianess.
306 BOOL WINAPI
GetColorProfileHeader( HPROFILE profile
, PPROFILEHEADER header
)
310 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
312 TRACE( "( %p, %p )\n", profile
, header
);
314 if (!iccprofile
|| !header
) return FALSE
;
316 MSCMS_get_profile_header( iccprofile
, header
);
319 #endif /* HAVE_LCMS */
323 /******************************************************************************
324 * GetCountColorProfileElements [MSCMS.@]
326 * Retrieve the number of elements in a color profile.
329 * profile [I] Handle to a color profile.
330 * count [O] Pointer to a variable which is set to the number of elements
331 * in the color profile.
337 BOOL WINAPI
GetCountColorProfileElements( HPROFILE profile
, PDWORD count
)
341 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
343 TRACE( "( %p, %p )\n", profile
, count
);
345 if (!iccprofile
|| !count
) return FALSE
;
346 *count
= MSCMS_get_tag_count( iccprofile
);
349 #endif /* HAVE_LCMS */
353 /******************************************************************************
354 * GetStandardColorSpaceProfileA [MSCMS.@]
356 * See GetStandardColorSpaceProfileW.
358 BOOL WINAPI
GetStandardColorSpaceProfileA( PCSTR machine
, DWORD id
, PSTR profile
, PDWORD size
)
365 TRACE( "( 0x%08lx, %p, %p )\n", id
, profile
, size
);
369 SetLastError( ERROR_NOT_SUPPORTED
);
375 SetLastError( ERROR_INVALID_PARAMETER
);
379 sizeW
= *size
* sizeof(WCHAR
);
383 ret
= GetStandardColorSpaceProfileW( NULL
, id
, NULL
, &sizeW
);
384 *size
= sizeW
/ sizeof(WCHAR
);
388 profileW
= HeapAlloc( GetProcessHeap(), 0, sizeW
);
392 ret
= GetStandardColorSpaceProfileW( NULL
, id
, profileW
, &sizeW
);
393 *size
= WideCharToMultiByte( CP_ACP
, 0, profileW
, -1, NULL
, 0, NULL
, NULL
);
397 len
= WideCharToMultiByte( CP_ACP
, 0, profileW
, *size
, profile
, *size
, NULL
, NULL
);
398 if (!len
) ret
= FALSE
;
401 HeapFree( GetProcessHeap(), 0, profileW
);
406 /******************************************************************************
407 * GetStandardColorSpaceProfileW [MSCMS.@]
409 * Retrieve the profile filename for a given standard color space id.
412 * machine [I] Name of the machine for which to get the standard color space.
413 * Must be NULL, which indicates the local machine.
414 * id [I] Id of a standard color space.
415 * profile [O] Buffer to receive the profile filename.
416 * size [I/O] Size of the filename buffer in bytes.
422 BOOL WINAPI
GetStandardColorSpaceProfileW( PCWSTR machine
, DWORD id
, PWSTR profile
, PDWORD size
)
424 static const WCHAR rgbprofilefile
[] =
425 { '\\','s','r','g','b',' ','c','o','l','o','r',' ',
426 's','p','a','c','e',' ','p','r','o','f','i','l','e','.','i','c','m',0 };
427 WCHAR rgbprofile
[MAX_PATH
];
428 DWORD len
= sizeof(rgbprofile
);
430 TRACE( "( 0x%08lx, %p, %p )\n", id
, profile
, size
);
434 SetLastError( ERROR_NOT_SUPPORTED
);
440 SetLastError( ERROR_INVALID_PARAMETER
);
446 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
450 GetColorDirectoryW( machine
, rgbprofile
, &len
);
454 case 0x52474220: /* 'RGB ' */
455 lstrcatW( rgbprofile
, rgbprofilefile
);
456 len
= lstrlenW( rgbprofile
) * sizeof(WCHAR
);
458 if (*size
< len
|| !profile
)
464 lstrcpyW( profile
, rgbprofile
);
473 static BOOL
MSCMS_header_from_file( LPWSTR file
, PPROFILEHEADER header
)
477 WCHAR path
[MAX_PATH
], slash
[] = {'\\',0};
478 DWORD size
= sizeof(path
);
481 ret
= GetColorDirectoryW( NULL
, path
, &size
);
484 WARN( "Can't retrieve color directory\n" );
487 if (size
+ sizeof(slash
) + sizeof(WCHAR
) * lstrlenW( file
) > sizeof(path
))
489 WARN( "Filename too long\n" );
493 lstrcatW( path
, slash
);
494 lstrcatW( path
, file
);
496 profile
.dwType
= PROFILE_FILENAME
;
497 profile
.pProfileData
= path
;
498 profile
.cbDataSize
= lstrlenW( path
) + 1;
500 handle
= OpenColorProfileW( &profile
, PROFILE_READ
, FILE_SHARE_READ
, OPEN_EXISTING
);
503 WARN( "Can't open color profile\n" );
507 ret
= GetColorProfileHeader( handle
, header
);
509 WARN( "Can't retrieve color profile header\n" );
511 CloseColorProfile( handle
);
515 static BOOL
MSCMS_match_profile( PENUMTYPEW rec
, PPROFILEHEADER hdr
)
517 if (rec
->dwFields
& ET_DEVICENAME
)
519 FIXME( "ET_DEVICENAME: %s\n", debugstr_w(rec
->pDeviceName
) );
521 if (rec
->dwFields
& ET_MEDIATYPE
)
523 FIXME( "ET_MEDIATYPE: 0x%08lx\n", rec
->dwMediaType
);
525 if (rec
->dwFields
& ET_DITHERMODE
)
527 FIXME( "ET_DITHERMODE: 0x%08lx\n", rec
->dwDitheringMode
);
529 if (rec
->dwFields
& ET_RESOLUTION
)
531 FIXME( "ET_RESOLUTION: 0x%08lx, 0x%08lx\n",
532 rec
->dwResolution
[0], rec
->dwResolution
[1] );
534 if (rec
->dwFields
& ET_DEVICECLASS
)
536 FIXME( "ET_DEVICECLASS: %s\n", MSCMS_dbgstr_tag(rec
->dwMediaType
) );
538 if (rec
->dwFields
& ET_CMMTYPE
)
540 TRACE( "ET_CMMTYPE: %s\n", MSCMS_dbgstr_tag(rec
->dwCMMType
) );
541 if (rec
->dwCMMType
!= hdr
->phCMMType
) return FALSE
;
543 if (rec
->dwFields
& ET_CLASS
)
545 TRACE( "ET_CLASS: %s\n", MSCMS_dbgstr_tag(rec
->dwClass
) );
546 if (rec
->dwClass
!= hdr
->phClass
) return FALSE
;
548 if (rec
->dwFields
& ET_DATACOLORSPACE
)
550 TRACE( "ET_DATACOLORSPACE: %s\n", MSCMS_dbgstr_tag(rec
->dwDataColorSpace
) );
551 if (rec
->dwDataColorSpace
!= hdr
->phDataColorSpace
) return FALSE
;
553 if (rec
->dwFields
& ET_CONNECTIONSPACE
)
555 TRACE( "ET_CONNECTIONSPACE: %s\n", MSCMS_dbgstr_tag(rec
->dwConnectionSpace
) );
556 if (rec
->dwConnectionSpace
!= hdr
->phConnectionSpace
) return FALSE
;
558 if (rec
->dwFields
& ET_SIGNATURE
)
560 TRACE( "ET_SIGNATURE: %s\n", MSCMS_dbgstr_tag(rec
->dwSignature
) );
561 if (rec
->dwSignature
!= hdr
->phSignature
) return FALSE
;
563 if (rec
->dwFields
& ET_PLATFORM
)
565 TRACE( "ET_PLATFORM: %s\n", MSCMS_dbgstr_tag(rec
->dwPlatform
) );
566 if (rec
->dwPlatform
!= hdr
->phPlatform
) return FALSE
;
568 if (rec
->dwFields
& ET_PROFILEFLAGS
)
570 TRACE( "ET_PROFILEFLAGS: 0x%08lx\n", rec
->dwProfileFlags
);
571 if (rec
->dwProfileFlags
!= hdr
->phProfileFlags
) return FALSE
;
573 if (rec
->dwFields
& ET_MANUFACTURER
)
575 TRACE( "ET_MANUFACTURER: %s\n", MSCMS_dbgstr_tag(rec
->dwManufacturer
) );
576 if (rec
->dwManufacturer
!= hdr
->phManufacturer
) return FALSE
;
578 if (rec
->dwFields
& ET_MODEL
)
580 TRACE( "ET_MODEL: %s\n", MSCMS_dbgstr_tag(rec
->dwModel
) );
581 if (rec
->dwModel
!= hdr
->phModel
) return FALSE
;
583 if (rec
->dwFields
& ET_ATTRIBUTES
)
585 TRACE( "ET_ATTRIBUTES: 0x%08lx, 0x%08lx\n",
586 rec
->dwAttributes
[0], rec
->dwAttributes
[1] );
587 if (rec
->dwAttributes
[0] != hdr
->phAttributes
[0] ||
588 rec
->dwAttributes
[1] != hdr
->phAttributes
[1]) return FALSE
;
590 if (rec
->dwFields
& ET_RENDERINGINTENT
)
592 TRACE( "ET_RENDERINGINTENT: 0x%08lx\n", rec
->dwRenderingIntent
);
593 if (rec
->dwRenderingIntent
!= hdr
->phRenderingIntent
) return FALSE
;
595 if (rec
->dwFields
& ET_CREATOR
)
597 TRACE( "ET_CREATOR: %s\n", MSCMS_dbgstr_tag(rec
->dwCreator
) );
598 if (rec
->dwCreator
!= hdr
->phCreator
) return FALSE
;
603 /******************************************************************************
604 * EnumColorProfilesA [MSCMS.@]
606 * See EnumColorProfilesW.
608 BOOL WINAPI
EnumColorProfilesA( PCSTR machine
, PENUMTYPEA record
, PBYTE buffer
,
609 PDWORD size
, PDWORD number
)
611 BOOL match
, ret
= FALSE
;
613 char colordir
[MAX_PATH
], glob
[MAX_PATH
], **profiles
= NULL
;
614 DWORD i
, len
= sizeof(colordir
), count
= 0, totalsize
= 0;
615 PROFILEHEADER header
;
616 WIN32_FIND_DATAA data
;
621 TRACE( "( %p, %p, %p, %p, %p )\n", machine
, record
, buffer
, size
, number
);
623 if (machine
|| !record
|| !size
||
624 record
->dwSize
!= sizeof(ENUMTYPEA
) ||
625 record
->dwVersion
!= ENUM_TYPE_VERSION
) return FALSE
;
627 ret
= GetColorDirectoryA( machine
, colordir
, &len
);
628 if (!ret
|| len
+ sizeof(spec
) > MAX_PATH
)
630 WARN( "can't retrieve color directory\n" );
634 lstrcpyA( glob
, colordir
);
635 lstrcatA( glob
, spec
);
637 find
= FindFirstFileA( glob
, &data
);
638 if (find
== INVALID_HANDLE_VALUE
) return FALSE
;
640 profiles
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(char *) + 1 );
641 if (!profiles
) goto exit
;
643 memcpy( &recordW
, record
, sizeof(ENUMTYPEA
) );
644 if (record
->pDeviceName
)
646 recordW
.pDeviceName
= MSCMS_strdupW( record
->pDeviceName
);
647 if (!recordW
.pDeviceName
) goto exit
;
650 fileW
= MSCMS_strdupW( data
.cFileName
);
651 if (!fileW
) goto exit
;
653 ret
= MSCMS_header_from_file( fileW
, &header
);
656 match
= MSCMS_match_profile( &recordW
, &header
);
659 len
= sizeof(char) * (lstrlenA( data
.cFileName
) + 1);
660 profiles
[count
] = HeapAlloc( GetProcessHeap(), 0, len
);
662 if (!profiles
[count
]) goto exit
;
665 TRACE( "matching profile: %s\n", debugstr_a(data
.cFileName
) );
666 lstrcpyA( profiles
[count
], data
.cFileName
);
672 HeapFree( GetProcessHeap(), 0, fileW
);
675 while (FindNextFileA( find
, &data
))
677 fileW
= MSCMS_strdupW( data
.cFileName
);
678 if (!fileW
) goto exit
;
680 ret
= MSCMS_header_from_file( fileW
, &header
);
683 HeapFree( GetProcessHeap(), 0, fileW
);
687 match
= MSCMS_match_profile( &recordW
, &header
);
690 char **tmp
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
691 profiles
, sizeof(char *) * (count
+ 1) );
695 len
= sizeof(char) * (lstrlenA( data
.cFileName
) + 1);
696 profiles
[count
] = HeapAlloc( GetProcessHeap(), 0, len
);
698 if (!profiles
[count
]) goto exit
;
701 TRACE( "matching profile: %s\n", debugstr_a(data
.cFileName
) );
702 lstrcpyA( profiles
[count
], data
.cFileName
);
707 HeapFree( GetProcessHeap(), 0, fileW
);
712 if (buffer
&& *size
>= totalsize
)
714 char *p
= (char *)buffer
;
716 for (i
= 0; i
< count
; i
++)
718 lstrcpyA( p
, profiles
[i
] );
719 p
+= lstrlenA( profiles
[i
] ) + 1;
727 if (number
) *number
= count
;
730 for (i
= 0; i
< count
; i
++)
731 HeapFree( GetProcessHeap(), 0, profiles
[i
] );
732 HeapFree( GetProcessHeap(), 0, profiles
);
733 HeapFree( GetProcessHeap(), 0, (WCHAR
*)recordW
.pDeviceName
);
734 HeapFree( GetProcessHeap(), 0, fileW
);
740 /******************************************************************************
741 * EnumColorProfilesW [MSCMS.@]
743 * Enumerate profiles that match given criteria.
746 * machine [I] Name of the machine for which to enumerate profiles.
747 * Must be NULL, which indicates the local machine.
748 * record [I] Record of criteria that a profile must match.
749 * buffer [O] Buffer to receive a string array of profile filenames.
750 * size [I/O] Size of the filename buffer in bytes.
751 * number [O] Number of filenames copied into buffer.
757 BOOL WINAPI
EnumColorProfilesW( PCWSTR machine
, PENUMTYPEW record
, PBYTE buffer
,
758 PDWORD size
, PDWORD number
)
760 BOOL match
, ret
= FALSE
;
761 WCHAR spec
[] = {'\\','*',0};
762 WCHAR colordir
[MAX_PATH
], glob
[MAX_PATH
], **profiles
= NULL
;
763 DWORD i
, len
= sizeof(colordir
), count
= 0, totalsize
= 0;
764 PROFILEHEADER header
;
765 WIN32_FIND_DATAW data
;
768 TRACE( "( %p, %p, %p, %p, %p )\n", machine
, record
, buffer
, size
, number
);
770 if (machine
|| !record
|| !size
||
771 record
->dwSize
!= sizeof(ENUMTYPEW
) ||
772 record
->dwVersion
!= ENUM_TYPE_VERSION
) return FALSE
;
774 ret
= GetColorDirectoryW( machine
, colordir
, &len
);
775 if (!ret
|| len
+ sizeof(spec
) > MAX_PATH
)
777 WARN( "Can't retrieve color directory\n" );
781 lstrcpyW( glob
, colordir
);
782 lstrcatW( glob
, spec
);
784 find
= FindFirstFileW( glob
, &data
);
785 if (find
== INVALID_HANDLE_VALUE
) return FALSE
;
787 profiles
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WCHAR
*) + 1 );
788 if (!profiles
) goto exit
;
790 ret
= MSCMS_header_from_file( data
.cFileName
, &header
);
793 match
= MSCMS_match_profile( record
, &header
);
796 len
= sizeof(WCHAR
) * (lstrlenW( data
.cFileName
) + 1);
797 profiles
[count
] = HeapAlloc( GetProcessHeap(), 0, len
);
799 if (!profiles
[count
]) goto exit
;
802 TRACE( "matching profile: %s\n", debugstr_w(data
.cFileName
) );
803 lstrcpyW( profiles
[count
], data
.cFileName
);
810 while (FindNextFileW( find
, &data
))
812 ret
= MSCMS_header_from_file( data
.cFileName
, &header
);
815 match
= MSCMS_match_profile( record
, &header
);
818 WCHAR
**tmp
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
819 profiles
, sizeof(WCHAR
*) * (count
+ 1) );
823 len
= sizeof(WCHAR
) * (lstrlenW( data
.cFileName
) + 1);
824 profiles
[count
] = HeapAlloc( GetProcessHeap(), 0, len
);
826 if (!profiles
[count
]) goto exit
;
829 TRACE( "matching profile: %s\n", debugstr_w(data
.cFileName
) );
830 lstrcpyW( profiles
[count
], data
.cFileName
);
838 if (buffer
&& *size
>= totalsize
)
840 WCHAR
*p
= (WCHAR
*)buffer
;
842 for (i
= 0; i
< count
; i
++)
844 lstrcpyW( p
, profiles
[i
] );
845 p
+= lstrlenW( profiles
[i
] ) + 1;
853 if (number
) *number
= count
;
856 for (i
= 0; i
< count
; i
++)
857 HeapFree( GetProcessHeap(), 0, profiles
[i
] );
858 HeapFree( GetProcessHeap(), 0, profiles
);
864 /******************************************************************************
865 * InstallColorProfileA [MSCMS.@]
867 * See InstallColorProfileW.
869 BOOL WINAPI
InstallColorProfileA( PCSTR machine
, PCSTR profile
)
875 TRACE( "( %s )\n", debugstr_a(profile
) );
877 if (machine
|| !profile
) return FALSE
;
879 len
= MultiByteToWideChar( CP_ACP
, 0, profile
, -1, NULL
, 0 );
880 profileW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
884 MultiByteToWideChar( CP_ACP
, 0, profile
, -1, profileW
, len
);
886 ret
= InstallColorProfileW( NULL
, profileW
);
887 HeapFree( GetProcessHeap(), 0, profileW
);
892 /******************************************************************************
893 * InstallColorProfileW [MSCMS.@]
895 * Install a color profile.
898 * machine [I] Name of the machine to install the profile on. Must be NULL,
899 * which indicates the local machine.
900 * profile [I] Full path name of the profile to install.
906 BOOL WINAPI
InstallColorProfileW( PCWSTR machine
, PCWSTR profile
)
908 WCHAR dest
[MAX_PATH
], base
[MAX_PATH
];
909 DWORD size
= sizeof(dest
);
910 static const WCHAR slash
[] = { '\\', 0 };
912 TRACE( "( %s )\n", debugstr_w(profile
) );
914 if (machine
|| !profile
) return FALSE
;
916 if (!GetColorDirectoryW( machine
, dest
, &size
)) return FALSE
;
918 MSCMS_basename( profile
, base
);
920 lstrcatW( dest
, slash
);
921 lstrcatW( dest
, base
);
923 /* Is source equal to destination? */
924 if (!lstrcmpW( profile
, dest
)) return TRUE
;
926 return CopyFileW( profile
, dest
, TRUE
);
929 /******************************************************************************
930 * IsColorProfileTagPresent [MSCMS.@]
932 * Determine if a given ICC tag type is present in a color profile.
935 * profile [I] Color profile handle.
936 * tag [I] ICC tag type.
937 * present [O] Pointer to a BOOL variable. Set to TRUE if tag type is present,
944 BOOL WINAPI
IsColorProfileTagPresent( HPROFILE profile
, TAGTYPE type
, PBOOL present
)
948 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
952 TRACE( "( %p, 0x%08lx, %p )\n", profile
, type
, present
);
954 if (!iccprofile
|| !present
) return FALSE
;
956 count
= MSCMS_get_tag_count( iccprofile
);
958 for (i
= 0; i
< count
; i
++)
960 MSCMS_get_tag_by_index( iccprofile
, i
, &tag
);
964 *present
= ret
= TRUE
;
969 #endif /* HAVE_LCMS */
973 /******************************************************************************
974 * IsColorProfileValid [MSCMS.@]
976 * Determine if a given color profile is valid.
979 * profile [I] Color profile handle.
980 * valid [O] Pointer to a BOOL variable. Set to TRUE if profile is valid,
987 BOOL WINAPI
IsColorProfileValid( HPROFILE profile
, PBOOL valid
)
991 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
993 TRACE( "( %p, %p )\n", profile
, valid
);
995 if (!valid
) return FALSE
;
996 if (iccprofile
) return *valid
= TRUE
;
998 #endif /* HAVE_LCMS */
1002 /******************************************************************************
1003 * SetColorProfileElement [MSCMS.@]
1005 * Set data for a specified tag type.
1008 * profile [I] Handle to a color profile.
1009 * type [I] ICC tag type.
1010 * offset [I] Offset in bytes to start copying to.
1011 * size [I/O] Size of the buffer in bytes. On return the variable holds the
1012 * number of bytes actually needed.
1013 * buffer [O] Buffer holding the tag data.
1019 BOOL WINAPI
SetColorProfileElement( HPROFILE profile
, TAGTYPE type
, DWORD offset
, PDWORD size
,
1024 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
1025 DWORD i
, count
, access
= MSCMS_hprofile2access( profile
);
1028 TRACE( "( %p, 0x%08lx, %ld, %p, %p )\n", profile
, type
, offset
, size
, buffer
);
1030 if (!iccprofile
|| !size
|| !buffer
) return FALSE
;
1031 if (!(access
& PROFILE_READWRITE
)) return FALSE
;
1033 count
= MSCMS_get_tag_count( iccprofile
);
1035 for (i
= 0; i
< count
; i
++)
1037 MSCMS_get_tag_by_index( iccprofile
, i
, &tag
);
1039 if (tag
.sig
== type
)
1041 if (offset
> tag
.size
) return FALSE
;
1043 MSCMS_set_tag_data( iccprofile
, &tag
, offset
, buffer
);
1048 #endif /* HAVE_LCMS */
1052 /******************************************************************************
1053 * SetColorProfileHeader [MSCMS.@]
1055 * Set header data for a given profile.
1058 * profile [I] Handle to a color profile.
1059 * header [I] Buffer holding the header data.
1065 BOOL WINAPI
SetColorProfileHeader( HPROFILE profile
, PPROFILEHEADER header
)
1069 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
1070 DWORD access
= MSCMS_hprofile2access( profile
);
1072 TRACE( "( %p, %p )\n", profile
, header
);
1074 if (!iccprofile
|| !header
) return FALSE
;
1075 if (!(access
& PROFILE_READWRITE
)) return FALSE
;
1077 MSCMS_set_profile_header( iccprofile
, header
);
1080 #endif /* HAVE_LCMS */
1084 /******************************************************************************
1085 * UninstallColorProfileA [MSCMS.@]
1087 * See UninstallColorProfileW.
1089 BOOL WINAPI
UninstallColorProfileA( PCSTR machine
, PCSTR profile
, BOOL
delete )
1095 TRACE( "( %s, %x )\n", debugstr_a(profile
), delete );
1097 if (machine
|| !profile
) return FALSE
;
1099 len
= MultiByteToWideChar( CP_ACP
, 0, profile
, -1, NULL
, 0 );
1100 profileW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1104 MultiByteToWideChar( CP_ACP
, 0, profile
, -1, profileW
, len
);
1106 ret
= UninstallColorProfileW( NULL
, profileW
, delete );
1108 HeapFree( GetProcessHeap(), 0, profileW
);
1113 /******************************************************************************
1114 * UninstallColorProfileW [MSCMS.@]
1116 * Uninstall a color profile.
1119 * machine [I] Name of the machine to uninstall the profile on. Must be NULL,
1120 * which indicates the local machine.
1121 * profile [I] Full path name of the profile to uninstall.
1122 * delete [I] Bool that specifies whether the profile file should be deleted.
1128 BOOL WINAPI
UninstallColorProfileW( PCWSTR machine
, PCWSTR profile
, BOOL
delete )
1130 TRACE( "( %s, %x )\n", debugstr_w(profile
), delete );
1132 if (machine
|| !profile
) return FALSE
;
1134 if (delete) return DeleteFileW( profile
);
1139 /******************************************************************************
1140 * OpenColorProfileA [MSCMS.@]
1142 * See OpenColorProfileW.
1144 HPROFILE WINAPI
OpenColorProfileA( PPROFILE profile
, DWORD access
, DWORD sharing
, DWORD creation
)
1146 HPROFILE handle
= NULL
;
1148 TRACE( "( %p, 0x%08lx, 0x%08lx, 0x%08lx )\n", profile
, access
, sharing
, creation
);
1150 if (!profile
|| !profile
->pProfileData
) return NULL
;
1152 /* No AW conversion needed for memory based profiles */
1153 if (profile
->dwType
& PROFILE_MEMBUFFER
)
1154 return OpenColorProfileW( profile
, access
, sharing
, creation
);
1156 if (profile
->dwType
& PROFILE_FILENAME
)
1161 profileW
.dwType
= profile
->dwType
;
1163 len
= MultiByteToWideChar( CP_ACP
, 0, profile
->pProfileData
, -1, NULL
, 0 );
1164 profileW
.pProfileData
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1166 if (profileW
.pProfileData
)
1168 profileW
.cbDataSize
= len
* sizeof(WCHAR
);
1169 MultiByteToWideChar( CP_ACP
, 0, profile
->pProfileData
, -1, profileW
.pProfileData
, len
);
1171 handle
= OpenColorProfileW( &profileW
, access
, sharing
, creation
);
1172 HeapFree( GetProcessHeap(), 0, profileW
.pProfileData
);
1178 /******************************************************************************
1179 * OpenColorProfileW [MSCMS.@]
1181 * Open a color profile.
1184 * profile [I] Pointer to a color profile structure.
1185 * access [I] Desired access.
1186 * sharing [I] Sharing mode.
1187 * creation [I] Creation mode.
1190 * Success: Handle to the opened profile.
1194 * Values for access: PROFILE_READ or PROFILE_READWRITE.
1195 * Values for sharing: 0 (no sharing), FILE_SHARE_READ and/or FILE_SHARE_WRITE.
1196 * Values for creation: one of CREATE_NEW, CREATE_ALWAYS, OPEN_EXISTING,
1197 * OPEN_ALWAYS, TRUNCATE_EXISTING.
1198 * Sharing and creation flags are ignored for memory based profiles.
1200 HPROFILE WINAPI
OpenColorProfileW( PPROFILE profile
, DWORD access
, DWORD sharing
, DWORD creation
)
1203 cmsHPROFILE cmsprofile
= NULL
;
1204 icProfile
*iccprofile
= NULL
;
1205 HANDLE handle
= NULL
;
1208 TRACE( "( %p, 0x%08lx, 0x%08lx, 0x%08lx )\n", profile
, access
, sharing
, creation
);
1210 if (!profile
|| !profile
->pProfileData
) return NULL
;
1212 if (profile
->dwType
& PROFILE_MEMBUFFER
)
1214 /* FIXME: access flags not implemented for memory based profiles */
1216 iccprofile
= profile
->pProfileData
;
1217 size
= profile
->cbDataSize
;
1219 cmsprofile
= cmsOpenProfileFromMem( iccprofile
, size
);
1222 if (profile
->dwType
& PROFILE_FILENAME
)
1224 DWORD read
, flags
= 0;
1226 TRACE( "profile file: %s\n", debugstr_w( (WCHAR
*)profile
->pProfileData
) );
1228 if (access
& PROFILE_READ
) flags
= GENERIC_READ
;
1229 if (access
& PROFILE_READWRITE
) flags
= GENERIC_READ
|GENERIC_WRITE
;
1231 if (!flags
) return NULL
;
1233 handle
= CreateFileW( profile
->pProfileData
, flags
, sharing
, NULL
, creation
, 0, NULL
);
1234 if (handle
== INVALID_HANDLE_VALUE
)
1236 WARN( "Unable to open color profile\n" );
1240 if ((size
= GetFileSize( handle
, NULL
)) == INVALID_FILE_SIZE
)
1242 ERR( "Unable to retrieve size of color profile\n" );
1243 CloseHandle( handle
);
1247 iccprofile
= HeapAlloc( GetProcessHeap(), 0, size
);
1250 ERR( "Unable to allocate memory for color profile\n" );
1251 CloseHandle( handle
);
1255 if (!ReadFile( handle
, iccprofile
, size
, &read
, NULL
) || read
!= size
)
1257 ERR( "Unable to read color profile\n" );
1259 CloseHandle( handle
);
1260 HeapFree( GetProcessHeap(), 0, iccprofile
);
1264 cmsprofile
= cmsOpenProfileFromMem( iccprofile
, size
);
1268 return MSCMS_create_hprofile_handle( handle
, iccprofile
, cmsprofile
, access
);
1270 #endif /* HAVE_LCMS */
1274 /******************************************************************************
1275 * CloseColorProfile [MSCMS.@]
1277 * Close a color profile.
1280 * profile [I] Handle to the profile.
1286 BOOL WINAPI
CloseColorProfile( HPROFILE profile
)
1290 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
1291 HANDLE file
= MSCMS_hprofile2handle( profile
);
1292 DWORD access
= MSCMS_hprofile2access( profile
);
1294 TRACE( "( %p )\n", profile
);
1296 if (file
&& (access
& PROFILE_READWRITE
))
1298 DWORD written
, size
= MSCMS_get_profile_size( iccprofile
);
1300 if (SetFilePointer( file
, 0, NULL
, FILE_BEGIN
) ||
1301 !WriteFile( file
, iccprofile
, size
, &written
, NULL
) || written
!= size
)
1302 ERR( "Unable to write color profile\n" );
1305 ret
= cmsCloseProfile( MSCMS_hprofile2cmsprofile( profile
) );
1306 HeapFree( GetProcessHeap(), 0, MSCMS_hprofile2iccprofile( profile
) );
1308 CloseHandle( MSCMS_hprofile2handle( profile
) );
1309 MSCMS_destroy_hprofile_handle( profile
);
1311 #endif /* HAVE_LCMS */