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 if ((ret
= GetColorDirectoryW( NULL
, bufferW
, &sizeW
)))
96 *size
= WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
97 len
= WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, buffer
, *size
, NULL
, NULL
);
98 if (!len
) ret
= FALSE
;
100 else *size
= sizeW
/ sizeof(WCHAR
);
102 HeapFree( GetProcessHeap(), 0, bufferW
);
107 /******************************************************************************
108 * GetColorDirectoryW [MSCMS.@]
110 * Get the directory where color profiles are stored.
113 * machine [I] Name of the machine for which to get the color directory.
114 * Must be NULL, which indicates the local machine.
115 * buffer [I] Buffer to receive the path name.
116 * size [I/O] Size of the buffer in bytes. On return the variable holds
117 * the number of bytes actually needed.
119 BOOL WINAPI
GetColorDirectoryW( PCWSTR machine
, PWSTR buffer
, PDWORD size
)
121 WCHAR colordir
[MAX_PATH
];
122 static const WCHAR colorsubdir
[] = { '\\','c','o','l','o','r',0 };
125 TRACE( "( %p, %p )\n", buffer
, size
);
127 if (machine
|| !size
) return FALSE
;
129 GetSystemDirectoryW( colordir
, sizeof(colordir
) / sizeof(WCHAR
) );
130 lstrcatW( colordir
, colorsubdir
);
132 len
= lstrlenW( colordir
) * sizeof(WCHAR
);
134 if (buffer
&& len
<= *size
)
136 lstrcpyW( buffer
, colordir
);
141 SetLastError( ERROR_MORE_DATA
);
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%08x, %d, %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, %d, %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%08x, %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 if ((ret
= GetStandardColorSpaceProfileW( NULL
, id
, profileW
, &sizeW
)))
394 *size
= WideCharToMultiByte( CP_ACP
, 0, profileW
, -1, NULL
, 0, NULL
, NULL
);
395 len
= WideCharToMultiByte( CP_ACP
, 0, profileW
, -1, profile
, *size
, NULL
, NULL
);
396 if (!len
) ret
= FALSE
;
398 else *size
= sizeW
/ sizeof(WCHAR
);
400 HeapFree( GetProcessHeap(), 0, profileW
);
405 /******************************************************************************
406 * GetStandardColorSpaceProfileW [MSCMS.@]
408 * Retrieve the profile filename for a given standard color space id.
411 * machine [I] Name of the machine for which to get the standard color space.
412 * Must be NULL, which indicates the local machine.
413 * id [I] Id of a standard color space.
414 * profile [O] Buffer to receive the profile filename.
415 * size [I/O] Size of the filename buffer in bytes.
421 BOOL WINAPI
GetStandardColorSpaceProfileW( PCWSTR machine
, DWORD id
, PWSTR profile
, PDWORD size
)
423 static const WCHAR rgbprofilefile
[] =
424 { '\\','s','r','g','b',' ','c','o','l','o','r',' ',
425 's','p','a','c','e',' ','p','r','o','f','i','l','e','.','i','c','m',0 };
426 WCHAR rgbprofile
[MAX_PATH
];
427 DWORD len
= sizeof(rgbprofile
);
429 TRACE( "( 0x%08x, %p, %p )\n", id
, profile
, size
);
433 SetLastError( ERROR_NOT_SUPPORTED
);
439 SetLastError( ERROR_INVALID_PARAMETER
);
445 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
449 GetColorDirectoryW( machine
, rgbprofile
, &len
);
453 case SPACE_RGB
: /* 'RGB ' */
454 lstrcatW( rgbprofile
, rgbprofilefile
);
455 len
= lstrlenW( rgbprofile
) * sizeof(WCHAR
);
457 if (*size
< len
|| !profile
)
460 SetLastError( ERROR_MORE_DATA
);
464 lstrcpyW( profile
, rgbprofile
);
468 SetLastError( ERROR_FILE_NOT_FOUND
);
474 static BOOL
MSCMS_header_from_file( LPWSTR file
, PPROFILEHEADER header
)
478 WCHAR path
[MAX_PATH
], slash
[] = {'\\',0};
479 DWORD size
= sizeof(path
);
482 ret
= GetColorDirectoryW( NULL
, path
, &size
);
485 WARN( "Can't retrieve color directory\n" );
488 if (size
+ sizeof(slash
) + sizeof(WCHAR
) * lstrlenW( file
) > sizeof(path
))
490 WARN( "Filename too long\n" );
494 lstrcatW( path
, slash
);
495 lstrcatW( path
, file
);
497 profile
.dwType
= PROFILE_FILENAME
;
498 profile
.pProfileData
= path
;
499 profile
.cbDataSize
= lstrlenW( path
) + 1;
501 handle
= OpenColorProfileW( &profile
, PROFILE_READ
, FILE_SHARE_READ
, OPEN_EXISTING
);
504 WARN( "Can't open color profile\n" );
508 ret
= GetColorProfileHeader( handle
, header
);
510 WARN( "Can't retrieve color profile header\n" );
512 CloseColorProfile( handle
);
516 static BOOL
MSCMS_match_profile( PENUMTYPEW rec
, PPROFILEHEADER hdr
)
518 if (rec
->dwFields
& ET_DEVICENAME
)
520 FIXME( "ET_DEVICENAME: %s\n", debugstr_w(rec
->pDeviceName
) );
522 if (rec
->dwFields
& ET_MEDIATYPE
)
524 FIXME( "ET_MEDIATYPE: 0x%08x\n", rec
->dwMediaType
);
526 if (rec
->dwFields
& ET_DITHERMODE
)
528 FIXME( "ET_DITHERMODE: 0x%08x\n", rec
->dwDitheringMode
);
530 if (rec
->dwFields
& ET_RESOLUTION
)
532 FIXME( "ET_RESOLUTION: 0x%08x, 0x%08x\n",
533 rec
->dwResolution
[0], rec
->dwResolution
[1] );
535 if (rec
->dwFields
& ET_DEVICECLASS
)
537 FIXME( "ET_DEVICECLASS: %s\n", MSCMS_dbgstr_tag(rec
->dwMediaType
) );
539 if (rec
->dwFields
& ET_CMMTYPE
)
541 TRACE( "ET_CMMTYPE: %s\n", MSCMS_dbgstr_tag(rec
->dwCMMType
) );
542 if (rec
->dwCMMType
!= hdr
->phCMMType
) return FALSE
;
544 if (rec
->dwFields
& ET_CLASS
)
546 TRACE( "ET_CLASS: %s\n", MSCMS_dbgstr_tag(rec
->dwClass
) );
547 if (rec
->dwClass
!= hdr
->phClass
) return FALSE
;
549 if (rec
->dwFields
& ET_DATACOLORSPACE
)
551 TRACE( "ET_DATACOLORSPACE: %s\n", MSCMS_dbgstr_tag(rec
->dwDataColorSpace
) );
552 if (rec
->dwDataColorSpace
!= hdr
->phDataColorSpace
) return FALSE
;
554 if (rec
->dwFields
& ET_CONNECTIONSPACE
)
556 TRACE( "ET_CONNECTIONSPACE: %s\n", MSCMS_dbgstr_tag(rec
->dwConnectionSpace
) );
557 if (rec
->dwConnectionSpace
!= hdr
->phConnectionSpace
) return FALSE
;
559 if (rec
->dwFields
& ET_SIGNATURE
)
561 TRACE( "ET_SIGNATURE: %s\n", MSCMS_dbgstr_tag(rec
->dwSignature
) );
562 if (rec
->dwSignature
!= hdr
->phSignature
) return FALSE
;
564 if (rec
->dwFields
& ET_PLATFORM
)
566 TRACE( "ET_PLATFORM: %s\n", MSCMS_dbgstr_tag(rec
->dwPlatform
) );
567 if (rec
->dwPlatform
!= hdr
->phPlatform
) return FALSE
;
569 if (rec
->dwFields
& ET_PROFILEFLAGS
)
571 TRACE( "ET_PROFILEFLAGS: 0x%08x\n", rec
->dwProfileFlags
);
572 if (rec
->dwProfileFlags
!= hdr
->phProfileFlags
) return FALSE
;
574 if (rec
->dwFields
& ET_MANUFACTURER
)
576 TRACE( "ET_MANUFACTURER: %s\n", MSCMS_dbgstr_tag(rec
->dwManufacturer
) );
577 if (rec
->dwManufacturer
!= hdr
->phManufacturer
) return FALSE
;
579 if (rec
->dwFields
& ET_MODEL
)
581 TRACE( "ET_MODEL: %s\n", MSCMS_dbgstr_tag(rec
->dwModel
) );
582 if (rec
->dwModel
!= hdr
->phModel
) return FALSE
;
584 if (rec
->dwFields
& ET_ATTRIBUTES
)
586 TRACE( "ET_ATTRIBUTES: 0x%08x, 0x%08x\n",
587 rec
->dwAttributes
[0], rec
->dwAttributes
[1] );
588 if (rec
->dwAttributes
[0] != hdr
->phAttributes
[0] ||
589 rec
->dwAttributes
[1] != hdr
->phAttributes
[1]) return FALSE
;
591 if (rec
->dwFields
& ET_RENDERINGINTENT
)
593 TRACE( "ET_RENDERINGINTENT: 0x%08x\n", rec
->dwRenderingIntent
);
594 if (rec
->dwRenderingIntent
!= hdr
->phRenderingIntent
) return FALSE
;
596 if (rec
->dwFields
& ET_CREATOR
)
598 TRACE( "ET_CREATOR: %s\n", MSCMS_dbgstr_tag(rec
->dwCreator
) );
599 if (rec
->dwCreator
!= hdr
->phCreator
) return FALSE
;
604 /******************************************************************************
605 * EnumColorProfilesA [MSCMS.@]
607 * See EnumColorProfilesW.
609 BOOL WINAPI
EnumColorProfilesA( PCSTR machine
, PENUMTYPEA record
, PBYTE buffer
,
610 PDWORD size
, PDWORD number
)
612 BOOL match
, ret
= FALSE
;
614 char colordir
[MAX_PATH
], glob
[MAX_PATH
], **profiles
= NULL
;
615 DWORD i
, len
= sizeof(colordir
), count
= 0, totalsize
= 0;
616 PROFILEHEADER header
;
617 WIN32_FIND_DATAA data
;
619 WCHAR
*fileW
= NULL
, *deviceW
= NULL
;
622 TRACE( "( %p, %p, %p, %p, %p )\n", machine
, record
, buffer
, size
, number
);
624 if (machine
|| !record
|| !size
||
625 record
->dwSize
!= sizeof(ENUMTYPEA
) ||
626 record
->dwVersion
!= ENUM_TYPE_VERSION
) return FALSE
;
628 ret
= GetColorDirectoryA( machine
, colordir
, &len
);
629 if (!ret
|| len
+ sizeof(spec
) > MAX_PATH
)
631 WARN( "can't retrieve color directory\n" );
635 lstrcpyA( glob
, colordir
);
636 lstrcatA( glob
, spec
);
638 find
= FindFirstFileA( glob
, &data
);
639 if (find
== INVALID_HANDLE_VALUE
) return FALSE
;
641 profiles
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(char *) + 1 );
642 if (!profiles
) goto exit
;
644 memcpy( &recordW
, record
, sizeof(ENUMTYPEA
) );
645 if (record
->pDeviceName
)
647 deviceW
= MSCMS_strdupW( record
->pDeviceName
);
648 if (!(recordW
.pDeviceName
= deviceW
)) goto exit
;
651 fileW
= MSCMS_strdupW( data
.cFileName
);
652 if (!fileW
) goto exit
;
654 ret
= MSCMS_header_from_file( fileW
, &header
);
657 match
= MSCMS_match_profile( &recordW
, &header
);
660 len
= sizeof(char) * (lstrlenA( data
.cFileName
) + 1);
661 profiles
[count
] = HeapAlloc( GetProcessHeap(), 0, len
);
663 if (!profiles
[count
]) goto exit
;
666 TRACE( "matching profile: %s\n", debugstr_a(data
.cFileName
) );
667 lstrcpyA( profiles
[count
], data
.cFileName
);
673 HeapFree( GetProcessHeap(), 0, fileW
);
676 while (FindNextFileA( find
, &data
))
678 fileW
= MSCMS_strdupW( data
.cFileName
);
679 if (!fileW
) goto exit
;
681 ret
= MSCMS_header_from_file( fileW
, &header
);
684 HeapFree( GetProcessHeap(), 0, fileW
);
688 match
= MSCMS_match_profile( &recordW
, &header
);
691 char **tmp
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
692 profiles
, sizeof(char *) * (count
+ 1) );
696 len
= sizeof(char) * (lstrlenA( data
.cFileName
) + 1);
697 profiles
[count
] = HeapAlloc( GetProcessHeap(), 0, len
);
699 if (!profiles
[count
]) goto exit
;
702 TRACE( "matching profile: %s\n", debugstr_a(data
.cFileName
) );
703 lstrcpyA( profiles
[count
], data
.cFileName
);
708 HeapFree( GetProcessHeap(), 0, fileW
);
713 if (buffer
&& *size
>= totalsize
)
715 char *p
= (char *)buffer
;
717 for (i
= 0; i
< count
; i
++)
719 lstrcpyA( p
, profiles
[i
] );
720 p
+= lstrlenA( profiles
[i
] ) + 1;
728 if (number
) *number
= count
;
731 for (i
= 0; i
< count
; i
++)
732 HeapFree( GetProcessHeap(), 0, profiles
[i
] );
733 HeapFree( GetProcessHeap(), 0, profiles
);
734 HeapFree( GetProcessHeap(), 0, deviceW
);
735 HeapFree( GetProcessHeap(), 0, fileW
);
741 /******************************************************************************
742 * EnumColorProfilesW [MSCMS.@]
744 * Enumerate profiles that match given criteria.
747 * machine [I] Name of the machine for which to enumerate profiles.
748 * Must be NULL, which indicates the local machine.
749 * record [I] Record of criteria that a profile must match.
750 * buffer [O] Buffer to receive a string array of profile filenames.
751 * size [I/O] Size of the filename buffer in bytes.
752 * number [O] Number of filenames copied into buffer.
758 BOOL WINAPI
EnumColorProfilesW( PCWSTR machine
, PENUMTYPEW record
, PBYTE buffer
,
759 PDWORD size
, PDWORD number
)
761 BOOL match
, ret
= FALSE
;
762 WCHAR spec
[] = {'\\','*',0};
763 WCHAR colordir
[MAX_PATH
], glob
[MAX_PATH
], **profiles
= NULL
;
764 DWORD i
, len
= sizeof(colordir
), count
= 0, totalsize
= 0;
765 PROFILEHEADER header
;
766 WIN32_FIND_DATAW data
;
769 TRACE( "( %p, %p, %p, %p, %p )\n", machine
, record
, buffer
, size
, number
);
771 if (machine
|| !record
|| !size
||
772 record
->dwSize
!= sizeof(ENUMTYPEW
) ||
773 record
->dwVersion
!= ENUM_TYPE_VERSION
) return FALSE
;
775 ret
= GetColorDirectoryW( machine
, colordir
, &len
);
776 if (!ret
|| len
+ sizeof(spec
) > MAX_PATH
)
778 WARN( "Can't retrieve color directory\n" );
782 lstrcpyW( glob
, colordir
);
783 lstrcatW( glob
, spec
);
785 find
= FindFirstFileW( glob
, &data
);
786 if (find
== INVALID_HANDLE_VALUE
) return FALSE
;
788 profiles
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WCHAR
*) + 1 );
789 if (!profiles
) goto exit
;
791 ret
= MSCMS_header_from_file( data
.cFileName
, &header
);
794 match
= MSCMS_match_profile( record
, &header
);
797 len
= sizeof(WCHAR
) * (lstrlenW( data
.cFileName
) + 1);
798 profiles
[count
] = HeapAlloc( GetProcessHeap(), 0, len
);
800 if (!profiles
[count
]) goto exit
;
803 TRACE( "matching profile: %s\n", debugstr_w(data
.cFileName
) );
804 lstrcpyW( profiles
[count
], data
.cFileName
);
811 while (FindNextFileW( find
, &data
))
813 ret
= MSCMS_header_from_file( data
.cFileName
, &header
);
816 match
= MSCMS_match_profile( record
, &header
);
819 WCHAR
**tmp
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
820 profiles
, sizeof(WCHAR
*) * (count
+ 1) );
824 len
= sizeof(WCHAR
) * (lstrlenW( data
.cFileName
) + 1);
825 profiles
[count
] = HeapAlloc( GetProcessHeap(), 0, len
);
827 if (!profiles
[count
]) goto exit
;
830 TRACE( "matching profile: %s\n", debugstr_w(data
.cFileName
) );
831 lstrcpyW( profiles
[count
], data
.cFileName
);
839 if (buffer
&& *size
>= totalsize
)
841 WCHAR
*p
= (WCHAR
*)buffer
;
843 for (i
= 0; i
< count
; i
++)
845 lstrcpyW( p
, profiles
[i
] );
846 p
+= lstrlenW( profiles
[i
] ) + 1;
854 if (number
) *number
= count
;
857 for (i
= 0; i
< count
; i
++)
858 HeapFree( GetProcessHeap(), 0, profiles
[i
] );
859 HeapFree( GetProcessHeap(), 0, profiles
);
865 /******************************************************************************
866 * InstallColorProfileA [MSCMS.@]
868 * See InstallColorProfileW.
870 BOOL WINAPI
InstallColorProfileA( PCSTR machine
, PCSTR profile
)
876 TRACE( "( %s )\n", debugstr_a(profile
) );
878 if (machine
|| !profile
) return FALSE
;
880 len
= MultiByteToWideChar( CP_ACP
, 0, profile
, -1, NULL
, 0 );
881 profileW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
885 MultiByteToWideChar( CP_ACP
, 0, profile
, -1, profileW
, len
);
887 ret
= InstallColorProfileW( NULL
, profileW
);
888 HeapFree( GetProcessHeap(), 0, profileW
);
893 /******************************************************************************
894 * InstallColorProfileW [MSCMS.@]
896 * Install a color profile.
899 * machine [I] Name of the machine to install the profile on. Must be NULL,
900 * which indicates the local machine.
901 * profile [I] Full path name of the profile to install.
907 BOOL WINAPI
InstallColorProfileW( PCWSTR machine
, PCWSTR profile
)
909 WCHAR dest
[MAX_PATH
], base
[MAX_PATH
];
910 DWORD size
= sizeof(dest
);
911 static const WCHAR slash
[] = { '\\', 0 };
913 TRACE( "( %s )\n", debugstr_w(profile
) );
915 if (machine
|| !profile
) return FALSE
;
917 if (!GetColorDirectoryW( machine
, dest
, &size
)) return FALSE
;
919 MSCMS_basename( profile
, base
);
921 lstrcatW( dest
, slash
);
922 lstrcatW( dest
, base
);
924 /* Is source equal to destination? */
925 if (!lstrcmpW( profile
, dest
)) return TRUE
;
927 return CopyFileW( profile
, dest
, TRUE
);
930 /******************************************************************************
931 * IsColorProfileTagPresent [MSCMS.@]
933 * Determine if a given ICC tag type is present in a color profile.
936 * profile [I] Color profile handle.
937 * tag [I] ICC tag type.
938 * present [O] Pointer to a BOOL variable. Set to TRUE if tag type is present,
945 BOOL WINAPI
IsColorProfileTagPresent( HPROFILE profile
, TAGTYPE type
, PBOOL present
)
949 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
953 TRACE( "( %p, 0x%08x, %p )\n", profile
, type
, present
);
955 if (!iccprofile
|| !present
) return FALSE
;
957 count
= MSCMS_get_tag_count( iccprofile
);
959 for (i
= 0; i
< count
; i
++)
961 MSCMS_get_tag_by_index( iccprofile
, i
, &tag
);
965 *present
= ret
= TRUE
;
970 #endif /* HAVE_LCMS */
974 /******************************************************************************
975 * IsColorProfileValid [MSCMS.@]
977 * Determine if a given color profile is valid.
980 * profile [I] Color profile handle.
981 * valid [O] Pointer to a BOOL variable. Set to TRUE if profile is valid,
988 BOOL WINAPI
IsColorProfileValid( HPROFILE profile
, PBOOL valid
)
992 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
994 TRACE( "( %p, %p )\n", profile
, valid
);
996 if (!valid
) return FALSE
;
997 if (iccprofile
) return *valid
= TRUE
;
999 #endif /* HAVE_LCMS */
1003 /******************************************************************************
1004 * SetColorProfileElement [MSCMS.@]
1006 * Set data for a specified tag type.
1009 * profile [I] Handle to a color profile.
1010 * type [I] ICC tag type.
1011 * offset [I] Offset in bytes to start copying to.
1012 * size [I/O] Size of the buffer in bytes. On return the variable holds the
1013 * number of bytes actually needed.
1014 * buffer [O] Buffer holding the tag data.
1020 BOOL WINAPI
SetColorProfileElement( HPROFILE profile
, TAGTYPE type
, DWORD offset
, PDWORD size
,
1025 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
1026 DWORD i
, count
, access
= MSCMS_hprofile2access( profile
);
1029 TRACE( "( %p, 0x%08x, %d, %p, %p )\n", profile
, type
, offset
, size
, buffer
);
1031 if (!iccprofile
|| !size
|| !buffer
) return FALSE
;
1032 if (!(access
& PROFILE_READWRITE
)) return FALSE
;
1034 count
= MSCMS_get_tag_count( iccprofile
);
1036 for (i
= 0; i
< count
; i
++)
1038 MSCMS_get_tag_by_index( iccprofile
, i
, &tag
);
1040 if (tag
.sig
== type
)
1042 if (offset
> tag
.size
) return FALSE
;
1044 MSCMS_set_tag_data( iccprofile
, &tag
, offset
, buffer
);
1049 #endif /* HAVE_LCMS */
1053 /******************************************************************************
1054 * SetColorProfileHeader [MSCMS.@]
1056 * Set header data for a given profile.
1059 * profile [I] Handle to a color profile.
1060 * header [I] Buffer holding the header data.
1066 BOOL WINAPI
SetColorProfileHeader( HPROFILE profile
, PPROFILEHEADER header
)
1070 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
1071 DWORD access
= MSCMS_hprofile2access( profile
);
1073 TRACE( "( %p, %p )\n", profile
, header
);
1075 if (!iccprofile
|| !header
) return FALSE
;
1076 if (!(access
& PROFILE_READWRITE
)) return FALSE
;
1078 MSCMS_set_profile_header( iccprofile
, header
);
1081 #endif /* HAVE_LCMS */
1085 /******************************************************************************
1086 * UninstallColorProfileA [MSCMS.@]
1088 * See UninstallColorProfileW.
1090 BOOL WINAPI
UninstallColorProfileA( PCSTR machine
, PCSTR profile
, BOOL
delete )
1096 TRACE( "( %s, %x )\n", debugstr_a(profile
), delete );
1098 if (machine
|| !profile
) return FALSE
;
1100 len
= MultiByteToWideChar( CP_ACP
, 0, profile
, -1, NULL
, 0 );
1101 profileW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1105 MultiByteToWideChar( CP_ACP
, 0, profile
, -1, profileW
, len
);
1107 ret
= UninstallColorProfileW( NULL
, profileW
, delete );
1109 HeapFree( GetProcessHeap(), 0, profileW
);
1114 /******************************************************************************
1115 * UninstallColorProfileW [MSCMS.@]
1117 * Uninstall a color profile.
1120 * machine [I] Name of the machine to uninstall the profile on. Must be NULL,
1121 * which indicates the local machine.
1122 * profile [I] Full path name of the profile to uninstall.
1123 * delete [I] Bool that specifies whether the profile file should be deleted.
1129 BOOL WINAPI
UninstallColorProfileW( PCWSTR machine
, PCWSTR profile
, BOOL
delete )
1131 TRACE( "( %s, %x )\n", debugstr_w(profile
), delete );
1133 if (machine
|| !profile
) return FALSE
;
1135 if (delete) return DeleteFileW( profile
);
1140 /******************************************************************************
1141 * OpenColorProfileA [MSCMS.@]
1143 * See OpenColorProfileW.
1145 HPROFILE WINAPI
OpenColorProfileA( PPROFILE profile
, DWORD access
, DWORD sharing
, DWORD creation
)
1147 HPROFILE handle
= NULL
;
1149 TRACE( "( %p, 0x%08x, 0x%08x, 0x%08x )\n", profile
, access
, sharing
, creation
);
1151 if (!profile
|| !profile
->pProfileData
) return NULL
;
1153 /* No AW conversion needed for memory based profiles */
1154 if (profile
->dwType
& PROFILE_MEMBUFFER
)
1155 return OpenColorProfileW( profile
, access
, sharing
, creation
);
1157 if (profile
->dwType
& PROFILE_FILENAME
)
1162 profileW
.dwType
= profile
->dwType
;
1164 len
= MultiByteToWideChar( CP_ACP
, 0, profile
->pProfileData
, -1, NULL
, 0 );
1165 profileW
.pProfileData
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1167 if (profileW
.pProfileData
)
1169 profileW
.cbDataSize
= len
* sizeof(WCHAR
);
1170 MultiByteToWideChar( CP_ACP
, 0, profile
->pProfileData
, -1, profileW
.pProfileData
, len
);
1172 handle
= OpenColorProfileW( &profileW
, access
, sharing
, creation
);
1173 HeapFree( GetProcessHeap(), 0, profileW
.pProfileData
);
1179 /******************************************************************************
1180 * OpenColorProfileW [MSCMS.@]
1182 * Open a color profile.
1185 * profile [I] Pointer to a color profile structure.
1186 * access [I] Desired access.
1187 * sharing [I] Sharing mode.
1188 * creation [I] Creation mode.
1191 * Success: Handle to the opened profile.
1195 * Values for access: PROFILE_READ or PROFILE_READWRITE.
1196 * Values for sharing: 0 (no sharing), FILE_SHARE_READ and/or FILE_SHARE_WRITE.
1197 * Values for creation: one of CREATE_NEW, CREATE_ALWAYS, OPEN_EXISTING,
1198 * OPEN_ALWAYS, TRUNCATE_EXISTING.
1199 * Sharing and creation flags are ignored for memory based profiles.
1201 HPROFILE WINAPI
OpenColorProfileW( PPROFILE profile
, DWORD access
, DWORD sharing
, DWORD creation
)
1204 cmsHPROFILE cmsprofile
= NULL
;
1205 icProfile
*iccprofile
= NULL
;
1206 HANDLE handle
= NULL
;
1209 TRACE( "( %p, 0x%08x, 0x%08x, 0x%08x )\n", profile
, access
, sharing
, creation
);
1211 if (!profile
|| !profile
->pProfileData
) return NULL
;
1213 if (profile
->dwType
& PROFILE_MEMBUFFER
)
1215 /* FIXME: access flags not implemented for memory based profiles */
1217 iccprofile
= profile
->pProfileData
;
1218 size
= profile
->cbDataSize
;
1220 cmsprofile
= cmsOpenProfileFromMem( iccprofile
, size
);
1223 if (profile
->dwType
& PROFILE_FILENAME
)
1225 DWORD read
, flags
= 0;
1227 TRACE( "profile file: %s\n", debugstr_w( (WCHAR
*)profile
->pProfileData
) );
1229 if (access
& PROFILE_READ
) flags
= GENERIC_READ
;
1230 if (access
& PROFILE_READWRITE
) flags
= GENERIC_READ
|GENERIC_WRITE
;
1232 if (!flags
) return NULL
;
1234 handle
= CreateFileW( profile
->pProfileData
, flags
, sharing
, NULL
, creation
, 0, NULL
);
1235 if (handle
== INVALID_HANDLE_VALUE
)
1237 WARN( "Unable to open color profile\n" );
1241 if ((size
= GetFileSize( handle
, NULL
)) == INVALID_FILE_SIZE
)
1243 ERR( "Unable to retrieve size of color profile\n" );
1244 CloseHandle( handle
);
1248 iccprofile
= HeapAlloc( GetProcessHeap(), 0, size
);
1251 ERR( "Unable to allocate memory for color profile\n" );
1252 CloseHandle( handle
);
1256 if (!ReadFile( handle
, iccprofile
, size
, &read
, NULL
) || read
!= size
)
1258 ERR( "Unable to read color profile\n" );
1260 CloseHandle( handle
);
1261 HeapFree( GetProcessHeap(), 0, iccprofile
);
1265 cmsprofile
= cmsOpenProfileFromMem( iccprofile
, size
);
1269 return MSCMS_create_hprofile_handle( handle
, iccprofile
, cmsprofile
, access
);
1271 #endif /* HAVE_LCMS */
1275 /******************************************************************************
1276 * CloseColorProfile [MSCMS.@]
1278 * Close a color profile.
1281 * profile [I] Handle to the profile.
1287 BOOL WINAPI
CloseColorProfile( HPROFILE profile
)
1291 icProfile
*iccprofile
= MSCMS_hprofile2iccprofile( profile
);
1292 HANDLE file
= MSCMS_hprofile2handle( profile
);
1293 DWORD access
= MSCMS_hprofile2access( profile
);
1295 TRACE( "( %p )\n", profile
);
1297 if (file
&& (access
& PROFILE_READWRITE
))
1299 DWORD written
, size
= MSCMS_get_profile_size( iccprofile
);
1301 if (SetFilePointer( file
, 0, NULL
, FILE_BEGIN
) ||
1302 !WriteFile( file
, iccprofile
, size
, &written
, NULL
) || written
!= size
)
1303 ERR( "Unable to write color profile\n" );
1306 ret
= cmsCloseProfile( MSCMS_hprofile2cmsprofile( profile
) );
1307 HeapFree( GetProcessHeap(), 0, MSCMS_hprofile2iccprofile( profile
) );
1309 CloseHandle( MSCMS_hprofile2handle( profile
) );
1310 MSCMS_destroy_hprofile_handle( profile
);
1312 #endif /* HAVE_LCMS */