source: trunk/src/mscms/profile.c@ 21311

Last change on this file since 21311 was 21311, checked in by vladest, 16 years ago

Added CRYPT32 and MSCMS APIs support

File size: 43.3 KB
Line 
1/*
2 * MSCMS - Color Management System for Wine
3 *
4 * Copyright 2004, 2005, 2006, 2008 Hans Leidekker
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include "config.h"
22#include "wine/debug.h"
23#include "wine/unicode.h"
24
25#include <stdarg.h>
26
27#include "windef.h"
28#include "winbase.h"
29#include "winerror.h"
30#include "winnls.h"
31#include "wingdi.h"
32#include "winuser.h"
33#include "winreg.h"
34#include "icm.h"
35
36#include "mscms_priv.h"
37
38#define IS_SEPARATOR(ch) ((ch) == '\\' || (ch) == '/')
39
40static void MSCMS_basename( LPCWSTR path, LPWSTR name )
41{
42 INT i = lstrlenW( path );
43
44 while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
45 lstrcpyW( name, &path[i] );
46}
47
48static inline LPWSTR MSCMS_strdupW( LPCSTR str )
49{
50 LPWSTR ret = NULL;
51 if (str)
52 {
53 DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
54 if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
55 MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
56 }
57 return ret;
58}
59
60const char *MSCMS_dbgstr_tag( DWORD tag )
61{
62 return sprintf( "'%c%c%c%c'",
63 (char)(tag >> 24), (char)(tag >> 16), (char)(tag >> 8), (char)(tag) );
64}
65
66WINE_DEFAULT_DEBUG_CHANNEL(mscms);
67
68/******************************************************************************
69 * AssociateColorProfileWithDeviceA [MSCMS.@]
70 */
71BOOL WINAPI AssociateColorProfileWithDeviceA( PCSTR machine, PCSTR profile, PCSTR device )
72{
73 int len;
74 BOOL ret = FALSE;
75 WCHAR *profileW, *deviceW;
76
77 TRACE( "( %s, %s, %s )\n", debugstr_a(machine), debugstr_a(profile), debugstr_a(device) );
78
79 if (!profile || !device)
80 {
81 SetLastError( ERROR_INVALID_PARAMETER );
82 return FALSE;
83 }
84 if (machine)
85 {
86 SetLastError( ERROR_NOT_SUPPORTED );
87 return FALSE;
88 }
89
90 len = MultiByteToWideChar( CP_ACP, 0, profile, -1, NULL, 0 );
91 if (!(profileW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return FALSE;
92
93 MultiByteToWideChar( CP_ACP, 0, profile, -1, profileW, len );
94
95 len = MultiByteToWideChar( CP_ACP, 0, device, -1, NULL, 0 );
96 if ((deviceW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
97 {
98 MultiByteToWideChar( CP_ACP, 0, device, -1, deviceW, len );
99 ret = AssociateColorProfileWithDeviceW( NULL, profileW, deviceW );
100 }
101
102 HeapFree( GetProcessHeap(), 0, profileW );
103 HeapFree( GetProcessHeap(), 0, deviceW );
104 return ret;
105}
106
107static BOOL set_profile_device_key( PCWSTR file, const BYTE *value, DWORD size )
108{
109 static const WCHAR fmtW[] = {'%','c','%','c','%','c','%','c',0};
110 static const WCHAR icmW[] = {'S','o','f','t','w','a','r','e','\\',
111 'M','i','c','r','o','s','o','f','t','\\',
112 'W','i','n','d','o','w','s',' ','N','T','\\',
113 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
114 'I','C','M',0};
115 PROFILEHEADER header;
116 PROFILE profile;
117 HPROFILE handle;
118 HKEY icm_key, class_key;
119 WCHAR basenameW[MAX_PATH], classW[5];
120
121 profile.dwType = PROFILE_FILENAME;
122 profile.pProfileData = (PVOID)file;
123 profile.cbDataSize = (lstrlenW( file ) + 1) * sizeof(WCHAR);
124
125 /* FIXME is the profile installed? */
126 if (!(handle = OpenColorProfileW( &profile, PROFILE_READ, 0, OPEN_EXISTING )))
127 {
128 SetLastError( ERROR_INVALID_PROFILE );
129 return FALSE;
130 }
131 if (!GetColorProfileHeader( handle, &header ))
132 {
133 CloseColorProfile( handle );
134 SetLastError( ERROR_INVALID_PROFILE );
135 return FALSE;
136 }
137 RegCreateKeyExW( HKEY_LOCAL_MACHINE, icmW, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &icm_key, NULL );
138
139 MSCMS_basename( file, basenameW );
140 sprintfW( classW, fmtW, (header.phClass >> 24) & 0xff, (header.phClass >> 16) & 0xff,
141 (header.phClass >> 8) & 0xff, header.phClass & 0xff );
142
143 RegCreateKeyExW( icm_key, classW, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &class_key, NULL );
144 if (value) RegSetValueExW( class_key, basenameW, 0, REG_BINARY, value, size );
145 else RegDeleteValueW( class_key, basenameW );
146
147 RegCloseKey( class_key );
148 RegCloseKey( icm_key );
149 CloseColorProfile( handle );
150 return TRUE;
151}
152
153/******************************************************************************
154 * AssociateColorProfileWithDeviceW [MSCMS.@]
155 */
156BOOL WINAPI AssociateColorProfileWithDeviceW( PCWSTR machine, PCWSTR profile, PCWSTR device )
157{
158 static const BYTE dummy_value[12];
159
160 TRACE( "( %s, %s, %s )\n", debugstr_w(machine), debugstr_w(profile), debugstr_w(device) );
161
162 if (!profile || !device)
163 {
164 SetLastError( ERROR_INVALID_PARAMETER );
165 return FALSE;
166 }
167 if (machine)
168 {
169 SetLastError( ERROR_NOT_SUPPORTED );
170 return FALSE;
171 }
172
173 return set_profile_device_key( profile, dummy_value, sizeof(dummy_value) );
174}
175
176/******************************************************************************
177 * DisassociateColorProfileFromDeviceA [MSCMS.@]
178 */
179BOOL WINAPI DisassociateColorProfileFromDeviceA( PCSTR machine, PCSTR profile, PCSTR device )
180{
181 int len;
182 BOOL ret = FALSE;
183 WCHAR *profileW, *deviceW;
184
185 TRACE( "( %s, %s, %s )\n", debugstr_a(machine), debugstr_a(profile), debugstr_a(device) );
186
187 if (!profile || !device)
188 {
189 SetLastError( ERROR_INVALID_PARAMETER );
190 return FALSE;
191 }
192 if (machine)
193 {
194 SetLastError( ERROR_NOT_SUPPORTED );
195 return FALSE;
196 }
197
198 len = MultiByteToWideChar( CP_ACP, 0, profile, -1, NULL, 0 );
199 if (!(profileW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return FALSE;
200
201 MultiByteToWideChar( CP_ACP, 0, profile, -1, profileW, len );
202
203 len = MultiByteToWideChar( CP_ACP, 0, device, -1, NULL, 0 );
204 if ((deviceW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
205 {
206 MultiByteToWideChar( CP_ACP, 0, device, -1, deviceW, len );
207 ret = DisassociateColorProfileFromDeviceW( NULL, profileW, deviceW );
208 }
209
210 HeapFree( GetProcessHeap(), 0, profileW );
211 HeapFree( GetProcessHeap(), 0, deviceW );
212 return ret;
213}
214
215/******************************************************************************
216 * DisassociateColorProfileFromDeviceW [MSCMS.@]
217 */
218BOOL WINAPI DisassociateColorProfileFromDeviceW( PCWSTR machine, PCWSTR profile, PCWSTR device )
219{
220 TRACE( "( %s, %s, %s )\n", debugstr_w(machine), debugstr_w(profile), debugstr_w(device) );
221
222 if (!profile || !device)
223 {
224 SetLastError( ERROR_INVALID_PARAMETER );
225 return FALSE;
226 }
227 if (machine)
228 {
229 SetLastError( ERROR_NOT_SUPPORTED );
230 return FALSE;
231 }
232
233 return set_profile_device_key( profile, NULL, 0 );
234}
235
236/******************************************************************************
237 * GetColorDirectoryA [MSCMS.@]
238 *
239 * See GetColorDirectoryW.
240 */
241BOOL WINAPI GetColorDirectoryA( PCSTR machine, PSTR buffer, PDWORD size )
242{
243 INT len;
244 LPWSTR bufferW;
245 BOOL ret = FALSE;
246 DWORD sizeW;
247
248 TRACE( "( %p, %p )\n", buffer, size );
249
250 if (machine || !size) return FALSE;
251
252 if (!buffer)
253 {
254 ret = GetColorDirectoryW( NULL, NULL, &sizeW );
255 *size = sizeW / sizeof(WCHAR);
256 return FALSE;
257 }
258
259 sizeW = *size * sizeof(WCHAR);
260
261 bufferW = HeapAlloc( GetProcessHeap(), 0, sizeW );
262
263 if (bufferW)
264 {
265 if ((ret = GetColorDirectoryW( NULL, bufferW, &sizeW )))
266 {
267 *size = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL );
268 len = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, buffer, *size, NULL, NULL );
269 if (!len) ret = FALSE;
270 }
271 else *size = sizeW / sizeof(WCHAR);
272
273 HeapFree( GetProcessHeap(), 0, bufferW );
274 }
275 return ret;
276}
277
278/******************************************************************************
279 * GetColorDirectoryW [MSCMS.@]
280 *
281 * Get the directory where color profiles are stored.
282 *
283 * PARAMS
284 * machine [I] Name of the machine for which to get the color directory.
285 * Must be NULL, which indicates the local machine.
286 * buffer [I] Buffer to receive the path name.
287 * size [I/O] Size of the buffer in bytes. On return the variable holds
288 * the number of bytes actually needed.
289 */
290BOOL WINAPI GetColorDirectoryW( PCWSTR machine, PWSTR buffer, PDWORD size )
291{
292 WCHAR colordir[MAX_PATH];
293 static const WCHAR colorsubdir[] =
294 {'\\','s','p','o','o','l','\\','d','r','i','v','e','r','s','\\','c','o','l','o','r',0};
295 DWORD len;
296
297 TRACE( "( %p, %p )\n", buffer, size );
298
299 if (machine || !size) return FALSE;
300
301 GetSystemDirectoryW( colordir, sizeof(colordir) / sizeof(WCHAR) );
302 lstrcatW( colordir, colorsubdir );
303
304 len = lstrlenW( colordir ) * sizeof(WCHAR);
305
306 if (buffer && len <= *size)
307 {
308 lstrcpyW( buffer, colordir );
309 *size = len;
310 return TRUE;
311 }
312
313 SetLastError( ERROR_MORE_DATA );
314 *size = len;
315 return FALSE;
316}
317
318/******************************************************************************
319 * GetColorProfileElement [MSCMS.@]
320 *
321 * Retrieve data for a specified tag type.
322 *
323 * PARAMS
324 * profile [I] Handle to a color profile.
325 * type [I] ICC tag type.
326 * offset [I] Offset in bytes to start copying from.
327 * size [I/O] Size of the buffer in bytes. On return the variable holds
328 * the number of bytes actually needed.
329 * buffer [O] Buffer to receive the tag data.
330 * ref [O] Pointer to a BOOL that specifies whether more than one tag
331 * references the data.
332 *
333 * RETURNS
334 * Success: TRUE
335 * Failure: FALSE
336 */
337BOOL WINAPI GetColorProfileElement( HPROFILE handle, TAGTYPE type, DWORD offset, PDWORD size,
338 PVOID buffer, PBOOL ref )
339{
340 BOOL ret = FALSE;
341#ifdef HAVE_LCMS
342 struct profile *profile = grab_profile( handle );
343 DWORD i, count;
344 icTag tag;
345
346 TRACE( "( %p, 0x%08x, %d, %p, %p, %p )\n", handle, type, offset, size, buffer, ref );
347
348 if (!profile) return FALSE;
349
350 if (!size || !ref)
351 {
352 release_profile( profile );
353 return FALSE;
354 }
355 count = MSCMS_get_tag_count( profile->iccprofile );
356
357 for (i = 0; i < count; i++)
358 {
359 MSCMS_get_tag_by_index( profile->iccprofile, i, &tag );
360
361 if (tag.sig == type)
362 {
363 if ((tag.size - offset) > *size || !buffer)
364 {
365 *size = (tag.size - offset);
366 release_profile( profile );
367 return FALSE;
368 }
369 MSCMS_get_tag_data( profile->iccprofile, &tag, offset, buffer );
370
371 *ref = FALSE; /* FIXME: calculate properly */
372 release_profile( profile );
373 return TRUE;
374 }
375 }
376 release_profile( profile );
377
378#endif /* HAVE_LCMS */
379 return ret;
380}
381
382/******************************************************************************
383 * GetColorProfileElementTag [MSCMS.@]
384 *
385 * Get the tag type from a color profile by index.
386 *
387 * PARAMS
388 * profile [I] Handle to a color profile.
389 * index [I] Index into the tag table of the color profile.
390 * type [O] Pointer to a variable that holds the ICC tag type on return.
391 *
392 * RETURNS
393 * Success: TRUE
394 * Failure: FALSE
395 *
396 * NOTES
397 * The tag table index starts at 1.
398 * Use GetCountColorProfileElements to retrieve a count of tagged elements.
399 */
400BOOL WINAPI GetColorProfileElementTag( HPROFILE handle, DWORD index, PTAGTYPE type )
401{
402 BOOL ret = FALSE;
403#ifdef HAVE_LCMS
404 struct profile *profile = grab_profile( handle );
405 DWORD count;
406 icTag tag;
407
408 TRACE( "( %p, %d, %p )\n", handle, index, type );
409
410 if (!profile) return FALSE;
411
412 if (!type)
413 {
414 release_profile( profile );
415 return FALSE;
416 }
417 count = MSCMS_get_tag_count( profile->iccprofile );
418 if (index > count || index < 1)
419 {
420 release_profile( profile );
421 return FALSE;
422 }
423 MSCMS_get_tag_by_index( profile->iccprofile, index - 1, &tag );
424 *type = tag.sig;
425
426 release_profile( profile );
427 ret = TRUE;
428
429#endif /* HAVE_LCMS */
430 return ret;
431}
432
433/******************************************************************************
434 * GetColorProfileFromHandle [MSCMS.@]
435 *
436 * Retrieve an ICC color profile by handle.
437 *
438 * PARAMS
439 * profile [I] Handle to a color profile.
440 * buffer [O] Buffer to receive the ICC profile.
441 * size [I/O] Size of the buffer in bytes. On return the variable holds the
442 * number of bytes actually needed.
443 *
444 * RETURNS
445 * Success: TRUE
446 * Failure: FALSE
447 *
448 * NOTES
449 * The profile returned will be in big-endian format.
450 */
451BOOL WINAPI GetColorProfileFromHandle( HPROFILE handle, PBYTE buffer, PDWORD size )
452{
453 BOOL ret = FALSE;
454#ifdef HAVE_LCMS
455 struct profile *profile = grab_profile( handle );
456 PROFILEHEADER header;
457
458 TRACE( "( %p, %p, %p )\n", handle, buffer, size );
459
460 if (!profile) return FALSE;
461
462 if (!size)
463 {
464 release_profile( profile );
465 return FALSE;
466 }
467 MSCMS_get_profile_header( profile->iccprofile, &header );
468
469 if (!buffer || header.phSize > *size)
470 {
471 *size = header.phSize;
472 release_profile( profile );
473 return FALSE;
474 }
475
476 /* No endian conversion needed */
477 memcpy( buffer, profile->iccprofile, header.phSize );
478 *size = header.phSize;
479
480 release_profile( profile );
481 ret = TRUE;
482
483#endif /* HAVE_LCMS */
484 return ret;
485}
486
487/******************************************************************************
488 * GetColorProfileHeader [MSCMS.@]
489 *
490 * Retrieve a color profile header by handle.
491 *
492 * PARAMS
493 * profile [I] Handle to a color profile.
494 * header [O] Buffer to receive the ICC profile header.
495 *
496 * RETURNS
497 * Success: TRUE
498 * Failure: FALSE
499 *
500 * NOTES
501 * The profile header returned will be adjusted for endianess.
502 */
503BOOL WINAPI GetColorProfileHeader( HPROFILE handle, PPROFILEHEADER header )
504{
505#ifdef HAVE_LCMS
506 struct profile *profile = grab_profile( handle );
507
508 TRACE( "( %p, %p )\n", handle, header );
509
510 if (!profile) return FALSE;
511
512 if (!header)
513 {
514 release_profile( profile );
515 return FALSE;
516 }
517 MSCMS_get_profile_header( profile->iccprofile, header );
518
519 release_profile( profile );
520 return TRUE;
521
522#else
523 return FALSE;
524#endif /* HAVE_LCMS */
525}
526
527/******************************************************************************
528 * GetCountColorProfileElements [MSCMS.@]
529 *
530 * Retrieve the number of elements in a color profile.
531 *
532 * PARAMS
533 * profile [I] Handle to a color profile.
534 * count [O] Pointer to a variable which is set to the number of elements
535 * in the color profile.
536 *
537 * RETURNS
538 * Success: TRUE
539 * Failure: FALSE
540 */
541BOOL WINAPI GetCountColorProfileElements( HPROFILE handle, PDWORD count )
542{
543 BOOL ret = FALSE;
544#ifdef HAVE_LCMS
545 struct profile *profile = grab_profile( handle );
546
547 TRACE( "( %p, %p )\n", handle, count );
548
549 if (!profile) return FALSE;
550
551 if (!count)
552 {
553 release_profile( profile );
554 return FALSE;
555 }
556 *count = MSCMS_get_tag_count( profile->iccprofile );
557
558 release_profile( profile );
559 ret = TRUE;
560
561#endif /* HAVE_LCMS */
562 return ret;
563}
564
565/******************************************************************************
566 * GetStandardColorSpaceProfileA [MSCMS.@]
567 *
568 * See GetStandardColorSpaceProfileW.
569 */
570BOOL WINAPI GetStandardColorSpaceProfileA( PCSTR machine, DWORD id, PSTR profile, PDWORD size )
571{
572 INT len;
573 LPWSTR profileW;
574 BOOL ret = FALSE;
575 DWORD sizeW;
576
577 TRACE( "( 0x%08x, %p, %p )\n", id, profile, size );
578
579 if (machine)
580 {
581 SetLastError( ERROR_NOT_SUPPORTED );
582 return FALSE;
583 }
584
585 if (!size)
586 {
587 SetLastError( ERROR_INVALID_PARAMETER );
588 return FALSE;
589 }
590
591 sizeW = *size * sizeof(WCHAR);
592
593 if (!profile)
594 {
595 ret = GetStandardColorSpaceProfileW( NULL, id, NULL, &sizeW );
596 *size = sizeW / sizeof(WCHAR);
597 return FALSE;
598 }
599
600 profileW = HeapAlloc( GetProcessHeap(), 0, sizeW );
601
602 if (profileW)
603 {
604 if ((ret = GetStandardColorSpaceProfileW( NULL, id, profileW, &sizeW )))
605 {
606 *size = WideCharToMultiByte( CP_ACP, 0, profileW, -1, NULL, 0, NULL, NULL );
607 len = WideCharToMultiByte( CP_ACP, 0, profileW, -1, profile, *size, NULL, NULL );
608 if (!len) ret = FALSE;
609 }
610 else *size = sizeW / sizeof(WCHAR);
611
612 HeapFree( GetProcessHeap(), 0, profileW );
613 }
614 return ret;
615}
616
617/******************************************************************************
618 * GetStandardColorSpaceProfileW [MSCMS.@]
619 *
620 * Retrieve the profile filename for a given standard color space id.
621 *
622 * PARAMS
623 * machine [I] Name of the machine for which to get the standard color space.
624 * Must be NULL, which indicates the local machine.
625 * id [I] Id of a standard color space.
626 * profile [O] Buffer to receive the profile filename.
627 * size [I/O] Size of the filename buffer in bytes.
628 *
629 * RETURNS
630 * Success: TRUE
631 * Failure: FALSE
632 */
633BOOL WINAPI GetStandardColorSpaceProfileW( PCWSTR machine, DWORD id, PWSTR profile, PDWORD size )
634{
635 static const WCHAR rgbprofilefile[] =
636 { '\\','s','r','g','b',' ','c','o','l','o','r',' ',
637 's','p','a','c','e',' ','p','r','o','f','i','l','e','.','i','c','m',0 };
638 WCHAR rgbprofile[MAX_PATH];
639 DWORD len = sizeof(rgbprofile);
640
641 TRACE( "( 0x%08x, %p, %p )\n", id, profile, size );
642
643 if (machine)
644 {
645 SetLastError( ERROR_NOT_SUPPORTED );
646 return FALSE;
647 }
648
649 if (!size)
650 {
651 SetLastError( ERROR_INVALID_PARAMETER );
652 return FALSE;
653 }
654
655 if (!profile)
656 {
657 SetLastError( ERROR_INSUFFICIENT_BUFFER );
658 return FALSE;
659 }
660
661 GetColorDirectoryW( machine, rgbprofile, &len );
662
663 switch (id)
664 {
665 case SPACE_RGB: /* 'RGB ' */
666 lstrcatW( rgbprofile, rgbprofilefile );
667 len = lstrlenW( rgbprofile ) * sizeof(WCHAR);
668
669 if (*size < len || !profile)
670 {
671 *size = len;
672 SetLastError( ERROR_MORE_DATA );
673 return FALSE;
674 }
675
676 lstrcpyW( profile, rgbprofile );
677 break;
678
679 default:
680 SetLastError( ERROR_FILE_NOT_FOUND );
681 return FALSE;
682 }
683 return TRUE;
684}
685
686static BOOL MSCMS_header_from_file( LPCWSTR file, PPROFILEHEADER header )
687{
688 BOOL ret;
689 PROFILE profile;
690 WCHAR path[MAX_PATH], slash[] = {'\\',0};
691 DWORD size = sizeof(path);
692 HANDLE handle;
693
694 ret = GetColorDirectoryW( NULL, path, &size );
695 if (!ret)
696 {
697 WARN( "Can't retrieve color directory\n" );
698 return FALSE;
699 }
700 if (size + sizeof(slash) + sizeof(WCHAR) * lstrlenW( file ) > sizeof(path))
701 {
702 WARN( "Filename too long\n" );
703 return FALSE;
704 }
705
706 lstrcatW( path, slash );
707 lstrcatW( path, file );
708
709 profile.dwType = PROFILE_FILENAME;
710 profile.pProfileData = path;
711 profile.cbDataSize = lstrlenW( path ) + 1;
712
713 handle = OpenColorProfileW( &profile, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING );
714 if (!handle)
715 {
716 WARN( "Can't open color profile\n" );
717 return FALSE;
718 }
719
720 ret = GetColorProfileHeader( handle, header );
721 if (!ret)
722 WARN( "Can't retrieve color profile header\n" );
723
724 CloseColorProfile( handle );
725 return ret;
726}
727
728static BOOL MSCMS_match_profile( PENUMTYPEW rec, PPROFILEHEADER hdr )
729{
730 if (rec->dwFields & ET_DEVICENAME)
731 {
732 FIXME( "ET_DEVICENAME: %s\n", debugstr_w(rec->pDeviceName) );
733 }
734 if (rec->dwFields & ET_MEDIATYPE)
735 {
736 FIXME( "ET_MEDIATYPE: 0x%08x\n", rec->dwMediaType );
737 }
738 if (rec->dwFields & ET_DITHERMODE)
739 {
740 FIXME( "ET_DITHERMODE: 0x%08x\n", rec->dwDitheringMode );
741 }
742 if (rec->dwFields & ET_RESOLUTION)
743 {
744 FIXME( "ET_RESOLUTION: 0x%08x, 0x%08x\n",
745 rec->dwResolution[0], rec->dwResolution[1] );
746 }
747 if (rec->dwFields & ET_DEVICECLASS)
748 {
749 FIXME( "ET_DEVICECLASS: %s\n", MSCMS_dbgstr_tag(rec->dwMediaType) );
750 }
751 if (rec->dwFields & ET_CMMTYPE)
752 {
753 TRACE( "ET_CMMTYPE: %s\n", MSCMS_dbgstr_tag(rec->dwCMMType) );
754 if (rec->dwCMMType != hdr->phCMMType) return FALSE;
755 }
756 if (rec->dwFields & ET_CLASS)
757 {
758 TRACE( "ET_CLASS: %s\n", MSCMS_dbgstr_tag(rec->dwClass) );
759 if (rec->dwClass != hdr->phClass) return FALSE;
760 }
761 if (rec->dwFields & ET_DATACOLORSPACE)
762 {
763 TRACE( "ET_DATACOLORSPACE: %s\n", MSCMS_dbgstr_tag(rec->dwDataColorSpace) );
764 if (rec->dwDataColorSpace != hdr->phDataColorSpace) return FALSE;
765 }
766 if (rec->dwFields & ET_CONNECTIONSPACE)
767 {
768 TRACE( "ET_CONNECTIONSPACE: %s\n", MSCMS_dbgstr_tag(rec->dwConnectionSpace) );
769 if (rec->dwConnectionSpace != hdr->phConnectionSpace) return FALSE;
770 }
771 if (rec->dwFields & ET_SIGNATURE)
772 {
773 TRACE( "ET_SIGNATURE: %s\n", MSCMS_dbgstr_tag(rec->dwSignature) );
774 if (rec->dwSignature != hdr->phSignature) return FALSE;
775 }
776 if (rec->dwFields & ET_PLATFORM)
777 {
778 TRACE( "ET_PLATFORM: %s\n", MSCMS_dbgstr_tag(rec->dwPlatform) );
779 if (rec->dwPlatform != hdr->phPlatform) return FALSE;
780 }
781 if (rec->dwFields & ET_PROFILEFLAGS)
782 {
783 TRACE( "ET_PROFILEFLAGS: 0x%08x\n", rec->dwProfileFlags );
784 if (rec->dwProfileFlags != hdr->phProfileFlags) return FALSE;
785 }
786 if (rec->dwFields & ET_MANUFACTURER)
787 {
788 TRACE( "ET_MANUFACTURER: %s\n", MSCMS_dbgstr_tag(rec->dwManufacturer) );
789 if (rec->dwManufacturer != hdr->phManufacturer) return FALSE;
790 }
791 if (rec->dwFields & ET_MODEL)
792 {
793 TRACE( "ET_MODEL: %s\n", MSCMS_dbgstr_tag(rec->dwModel) );
794 if (rec->dwModel != hdr->phModel) return FALSE;
795 }
796 if (rec->dwFields & ET_ATTRIBUTES)
797 {
798 TRACE( "ET_ATTRIBUTES: 0x%08x, 0x%08x\n",
799 rec->dwAttributes[0], rec->dwAttributes[1] );
800 if (rec->dwAttributes[0] != hdr->phAttributes[0] ||
801 rec->dwAttributes[1] != hdr->phAttributes[1]) return FALSE;
802 }
803 if (rec->dwFields & ET_RENDERINGINTENT)
804 {
805 TRACE( "ET_RENDERINGINTENT: 0x%08x\n", rec->dwRenderingIntent );
806 if (rec->dwRenderingIntent != hdr->phRenderingIntent) return FALSE;
807 }
808 if (rec->dwFields & ET_CREATOR)
809 {
810 TRACE( "ET_CREATOR: %s\n", MSCMS_dbgstr_tag(rec->dwCreator) );
811 if (rec->dwCreator != hdr->phCreator) return FALSE;
812 }
813 return TRUE;
814}
815
816/******************************************************************************
817 * EnumColorProfilesA [MSCMS.@]
818 *
819 * See EnumColorProfilesW.
820 */
821BOOL WINAPI EnumColorProfilesA( PCSTR machine, PENUMTYPEA record, PBYTE buffer,
822 PDWORD size, PDWORD number )
823{
824 BOOL match, ret = FALSE;
825 char spec[] = "\\*.icm";
826 char colordir[MAX_PATH], glob[MAX_PATH], **profiles = NULL;
827 DWORD i, len = sizeof(colordir), count = 0, totalsize = 0;
828 PROFILEHEADER header;
829 WIN32_FIND_DATAA data;
830 ENUMTYPEW recordW;
831 WCHAR *fileW = NULL, *deviceW = NULL;
832 HANDLE find;
833
834 TRACE( "( %p, %p, %p, %p, %p )\n", machine, record, buffer, size, number );
835
836 if (machine || !record || !size ||
837 record->dwSize != sizeof(ENUMTYPEA) ||
838 record->dwVersion != ENUM_TYPE_VERSION) return FALSE;
839
840 ret = GetColorDirectoryA( machine, colordir, &len );
841 if (!ret || len + sizeof(spec) > MAX_PATH)
842 {
843 WARN( "can't retrieve color directory\n" );
844 return FALSE;
845 }
846
847 lstrcpyA( glob, colordir );
848 lstrcatA( glob, spec );
849
850 find = FindFirstFileA( glob, &data );
851 if (find == INVALID_HANDLE_VALUE) return FALSE;
852
853 profiles = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(char *) + 1 );
854 if (!profiles) goto exit;
855
856 memcpy( &recordW, record, sizeof(ENUMTYPEA) );
857 if (record->pDeviceName)
858 {
859 deviceW = MSCMS_strdupW( record->pDeviceName );
860 if (!(recordW.pDeviceName = deviceW)) goto exit;
861 }
862
863 fileW = MSCMS_strdupW( data.cFileName );
864 if (!fileW) goto exit;
865
866 ret = MSCMS_header_from_file( fileW, &header );
867 if (ret)
868 {
869 match = MSCMS_match_profile( &recordW, &header );
870 if (match)
871 {
872 len = sizeof(char) * (lstrlenA( data.cFileName ) + 1);
873 profiles[count] = HeapAlloc( GetProcessHeap(), 0, len );
874
875 if (!profiles[count]) goto exit;
876 else
877 {
878 TRACE( "matching profile: %s\n", debugstr_a(data.cFileName) );
879 lstrcpyA( profiles[count], data.cFileName );
880 totalsize += len;
881 count++;
882 }
883 }
884 }
885 HeapFree( GetProcessHeap(), 0, fileW );
886 fileW = NULL;
887
888 while (FindNextFileA( find, &data ))
889 {
890 fileW = MSCMS_strdupW( data.cFileName );
891 if (!fileW) goto exit;
892
893 ret = MSCMS_header_from_file( fileW, &header );
894 if (!ret)
895 {
896 HeapFree( GetProcessHeap(), 0, fileW );
897 continue;
898 }
899
900 match = MSCMS_match_profile( &recordW, &header );
901 if (match)
902 {
903 char **tmp = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
904 profiles, sizeof(char *) * (count + 1) );
905 if (!tmp) goto exit;
906 else profiles = tmp;
907
908 len = sizeof(char) * (lstrlenA( data.cFileName ) + 1);
909 profiles[count] = HeapAlloc( GetProcessHeap(), 0, len );
910
911 if (!profiles[count]) goto exit;
912 else
913 {
914 TRACE( "matching profile: %s\n", debugstr_a(data.cFileName) );
915 lstrcpyA( profiles[count], data.cFileName );
916 totalsize += len;
917 count++;
918 }
919 }
920 HeapFree( GetProcessHeap(), 0, fileW );
921 fileW = NULL;
922 }
923
924 totalsize++;
925 if (buffer && *size >= totalsize)
926 {
927 char *p = (char *)buffer;
928
929 for (i = 0; i < count; i++)
930 {
931 lstrcpyA( p, profiles[i] );
932 p += lstrlenA( profiles[i] ) + 1;
933 }
934 *p = 0;
935 ret = TRUE;
936 }
937 else ret = FALSE;
938
939 *size = totalsize;
940 if (number) *number = count;
941
942exit:
943 for (i = 0; i < count; i++)
944 HeapFree( GetProcessHeap(), 0, profiles[i] );
945 HeapFree( GetProcessHeap(), 0, profiles );
946 HeapFree( GetProcessHeap(), 0, deviceW );
947 HeapFree( GetProcessHeap(), 0, fileW );
948 FindClose( find );
949
950 return ret;
951}
952
953/******************************************************************************
954 * EnumColorProfilesW [MSCMS.@]
955 *
956 * Enumerate profiles that match given criteria.
957 *
958 * PARAMS
959 * machine [I] Name of the machine for which to enumerate profiles.
960 * Must be NULL, which indicates the local machine.
961 * record [I] Record of criteria that a profile must match.
962 * buffer [O] Buffer to receive a string array of profile filenames.
963 * size [I/O] Size of the filename buffer in bytes.
964 * number [O] Number of filenames copied into buffer.
965 *
966 * RETURNS
967 * Success: TRUE
968 * Failure: FALSE
969 */
970BOOL WINAPI EnumColorProfilesW( PCWSTR machine, PENUMTYPEW record, PBYTE buffer,
971 PDWORD size, PDWORD number )
972{
973 BOOL match, ret = FALSE;
974 WCHAR spec[] = {'\\','*','i','c','m',0};
975 WCHAR colordir[MAX_PATH], glob[MAX_PATH], **profiles = NULL;
976 DWORD i, len = sizeof(colordir), count = 0, totalsize = 0;
977 PROFILEHEADER header;
978 WIN32_FIND_DATAW data;
979 HANDLE find;
980
981 TRACE( "( %p, %p, %p, %p, %p )\n", machine, record, buffer, size, number );
982
983 if (machine || !record || !size ||
984 record->dwSize != sizeof(ENUMTYPEW) ||
985 record->dwVersion != ENUM_TYPE_VERSION) return FALSE;
986
987 ret = GetColorDirectoryW( machine, colordir, &len );
988 if (!ret || len + sizeof(spec) > MAX_PATH)
989 {
990 WARN( "Can't retrieve color directory\n" );
991 return FALSE;
992 }
993
994 lstrcpyW( glob, colordir );
995 lstrcatW( glob, spec );
996
997 find = FindFirstFileW( glob, &data );
998 if (find == INVALID_HANDLE_VALUE) return FALSE;
999
1000 profiles = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR *) + 1 );
1001 if (!profiles) goto exit;
1002
1003 ret = MSCMS_header_from_file( data.cFileName, &header );
1004 if (ret)
1005 {
1006 match = MSCMS_match_profile( record, &header );
1007 if (match)
1008 {
1009 len = sizeof(WCHAR) * (lstrlenW( data.cFileName ) + 1);
1010 profiles[count] = HeapAlloc( GetProcessHeap(), 0, len );
1011
1012 if (!profiles[count]) goto exit;
1013 else
1014 {
1015 TRACE( "matching profile: %s\n", debugstr_w(data.cFileName) );
1016 lstrcpyW( profiles[count], data.cFileName );
1017 totalsize += len;
1018 count++;
1019 }
1020 }
1021 }
1022
1023 while (FindNextFileW( find, &data ))
1024 {
1025 ret = MSCMS_header_from_file( data.cFileName, &header );
1026 if (!ret) continue;
1027
1028 match = MSCMS_match_profile( record, &header );
1029 if (match)
1030 {
1031 WCHAR **tmp = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
1032 profiles, sizeof(WCHAR *) * (count + 1) );
1033 if (!tmp) goto exit;
1034 else profiles = tmp;
1035
1036 len = sizeof(WCHAR) * (lstrlenW( data.cFileName ) + 1);
1037 profiles[count] = HeapAlloc( GetProcessHeap(), 0, len );
1038
1039 if (!profiles[count]) goto exit;
1040 else
1041 {
1042 TRACE( "matching profile: %s\n", debugstr_w(data.cFileName) );
1043 lstrcpyW( profiles[count], data.cFileName );
1044 totalsize += len;
1045 count++;
1046 }
1047 }
1048 }
1049
1050 totalsize++;
1051 if (buffer && *size >= totalsize)
1052 {
1053 WCHAR *p = (WCHAR *)buffer;
1054
1055 for (i = 0; i < count; i++)
1056 {
1057 lstrcpyW( p, profiles[i] );
1058 p += lstrlenW( profiles[i] ) + 1;
1059 }
1060 *p = 0;
1061 ret = TRUE;
1062 }
1063 else ret = FALSE;
1064
1065 *size = totalsize;
1066 if (number) *number = count;
1067
1068exit:
1069 for (i = 0; i < count; i++)
1070 HeapFree( GetProcessHeap(), 0, profiles[i] );
1071 HeapFree( GetProcessHeap(), 0, profiles );
1072 FindClose( find );
1073
1074 return ret;
1075}
1076
1077/******************************************************************************
1078 * InstallColorProfileA [MSCMS.@]
1079 *
1080 * See InstallColorProfileW.
1081 */
1082BOOL WINAPI InstallColorProfileA( PCSTR machine, PCSTR profile )
1083{
1084 UINT len;
1085 LPWSTR profileW;
1086 BOOL ret = FALSE;
1087
1088 TRACE( "( %s )\n", debugstr_a(profile) );
1089
1090 if (machine || !profile) return FALSE;
1091
1092 len = MultiByteToWideChar( CP_ACP, 0, profile, -1, NULL, 0 );
1093 profileW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1094
1095 if (profileW)
1096 {
1097 MultiByteToWideChar( CP_ACP, 0, profile, -1, profileW, len );
1098
1099 ret = InstallColorProfileW( NULL, profileW );
1100 HeapFree( GetProcessHeap(), 0, profileW );
1101 }
1102 return ret;
1103}
1104
1105/******************************************************************************
1106 * InstallColorProfileW [MSCMS.@]
1107 *
1108 * Install a color profile.
1109 *
1110 * PARAMS
1111 * machine [I] Name of the machine to install the profile on. Must be NULL,
1112 * which indicates the local machine.
1113 * profile [I] Full path name of the profile to install.
1114 *
1115 * RETURNS
1116 * Success: TRUE
1117 * Failure: FALSE
1118 */
1119BOOL WINAPI InstallColorProfileW( PCWSTR machine, PCWSTR profile )
1120{
1121 WCHAR dest[MAX_PATH], base[MAX_PATH];
1122 DWORD size = sizeof(dest);
1123 static const WCHAR slash[] = { '\\', 0 };
1124
1125 TRACE( "( %s )\n", debugstr_w(profile) );
1126
1127 if (machine || !profile) return FALSE;
1128
1129 if (!GetColorDirectoryW( machine, dest, &size )) return FALSE;
1130
1131 MSCMS_basename( profile, base );
1132
1133 lstrcatW( dest, slash );
1134 lstrcatW( dest, base );
1135
1136 /* Is source equal to destination? */
1137 if (!lstrcmpW( profile, dest )) return TRUE;
1138
1139 return CopyFileW( profile, dest, TRUE );
1140}
1141
1142/******************************************************************************
1143 * IsColorProfileTagPresent [MSCMS.@]
1144 *
1145 * Determine if a given ICC tag type is present in a color profile.
1146 *
1147 * PARAMS
1148 * profile [I] Color profile handle.
1149 * tag [I] ICC tag type.
1150 * present [O] Pointer to a BOOL variable. Set to TRUE if tag type is present,
1151 * FALSE otherwise.
1152 *
1153 * RETURNS
1154 * Success: TRUE
1155 * Failure: FALSE
1156 */
1157BOOL WINAPI IsColorProfileTagPresent( HPROFILE handle, TAGTYPE type, PBOOL present )
1158{
1159 BOOL ret = FALSE;
1160#ifdef HAVE_LCMS
1161 struct profile *profile = grab_profile( handle );
1162 DWORD i, count;
1163 icTag tag;
1164
1165 TRACE( "( %p, 0x%08x, %p )\n", handle, type, present );
1166
1167 if (!profile) return FALSE;
1168
1169 if (!present)
1170 {
1171 release_profile( profile );
1172 return FALSE;
1173 }
1174 count = MSCMS_get_tag_count( profile->iccprofile );
1175
1176 for (i = 0; i < count; i++)
1177 {
1178 MSCMS_get_tag_by_index( profile->iccprofile, i, &tag );
1179
1180 if (tag.sig == type)
1181 {
1182 *present = ret = TRUE;
1183 break;
1184 }
1185 }
1186 release_profile( profile );
1187
1188#endif /* HAVE_LCMS */
1189 return ret;
1190}
1191
1192/******************************************************************************
1193 * IsColorProfileValid [MSCMS.@]
1194 *
1195 * Determine if a given color profile is valid.
1196 *
1197 * PARAMS
1198 * profile [I] Color profile handle.
1199 * valid [O] Pointer to a BOOL variable. Set to TRUE if profile is valid,
1200 * FALSE otherwise.
1201 *
1202 * RETURNS
1203 * Success: TRUE
1204 * Failure: FALSE
1205 */
1206BOOL WINAPI IsColorProfileValid( HPROFILE handle, PBOOL valid )
1207{
1208 BOOL ret = FALSE;
1209#ifdef HAVE_LCMS
1210 struct profile *profile = grab_profile( handle );
1211
1212 TRACE( "( %p, %p )\n", handle, valid );
1213
1214 if (!profile) return FALSE;
1215
1216 if (!valid)
1217 {
1218 release_profile( profile );
1219 return FALSE;
1220 }
1221 if (profile->iccprofile) ret = *valid = TRUE;
1222 release_profile( profile );
1223
1224#endif /* HAVE_LCMS */
1225 return ret;
1226}
1227
1228/******************************************************************************
1229 * SetColorProfileElement [MSCMS.@]
1230 *
1231 * Set data for a specified tag type.
1232 *
1233 * PARAMS
1234 * profile [I] Handle to a color profile.
1235 * type [I] ICC tag type.
1236 * offset [I] Offset in bytes to start copying to.
1237 * size [I/O] Size of the buffer in bytes. On return the variable holds the
1238 * number of bytes actually needed.
1239 * buffer [O] Buffer holding the tag data.
1240 *
1241 * RETURNS
1242 * Success: TRUE
1243 * Failure: FALSE
1244 */
1245BOOL WINAPI SetColorProfileElement( HPROFILE handle, TAGTYPE type, DWORD offset, PDWORD size,
1246 PVOID buffer )
1247{
1248 BOOL ret = FALSE;
1249#ifdef HAVE_LCMS
1250 struct profile *profile = grab_profile( handle );
1251 DWORD i, count;
1252 icTag tag;
1253
1254 TRACE( "( %p, 0x%08x, %d, %p, %p )\n", handle, type, offset, size, buffer );
1255
1256 if (!profile) return FALSE;
1257
1258 if (!size || !buffer || !(profile->access & PROFILE_READWRITE))
1259 {
1260 release_profile( profile );
1261 return FALSE;
1262 }
1263 count = MSCMS_get_tag_count( profile->iccprofile );
1264
1265 for (i = 0; i < count; i++)
1266 {
1267 MSCMS_get_tag_by_index( profile->iccprofile, i, &tag );
1268
1269 if (tag.sig == type)
1270 {
1271 if (offset > tag.size)
1272 {
1273 release_profile( profile );
1274 return FALSE;
1275 }
1276 MSCMS_set_tag_data( profile->iccprofile, &tag, offset, buffer );
1277
1278 release_profile( profile );
1279 return TRUE;
1280 }
1281 }
1282 release_profile( profile );
1283
1284#endif /* HAVE_LCMS */
1285 return ret;
1286}
1287
1288/******************************************************************************
1289 * SetColorProfileHeader [MSCMS.@]
1290 *
1291 * Set header data for a given profile.
1292 *
1293 * PARAMS
1294 * profile [I] Handle to a color profile.
1295 * header [I] Buffer holding the header data.
1296 *
1297 * RETURNS
1298 * Success: TRUE
1299 * Failure: FALSE
1300 */
1301BOOL WINAPI SetColorProfileHeader( HPROFILE handle, PPROFILEHEADER header )
1302{
1303#ifdef HAVE_LCMS
1304 struct profile *profile = grab_profile( handle );
1305
1306 TRACE( "( %p, %p )\n", handle, header );
1307
1308 if (!profile) return FALSE;
1309
1310 if (!header || !(profile->access & PROFILE_READWRITE))
1311 {
1312 release_profile( profile );
1313 return FALSE;
1314 }
1315 MSCMS_set_profile_header( profile->iccprofile, header );
1316
1317 release_profile( profile );
1318 return TRUE;
1319
1320#else
1321 return FALSE;
1322#endif /* HAVE_LCMS */
1323}
1324
1325/******************************************************************************
1326 * UninstallColorProfileA [MSCMS.@]
1327 *
1328 * See UninstallColorProfileW.
1329 */
1330BOOL WINAPI UninstallColorProfileA( PCSTR machine, PCSTR profile, BOOL delete )
1331{
1332 UINT len;
1333 LPWSTR profileW;
1334 BOOL ret = FALSE;
1335
1336 TRACE( "( %s, %x )\n", debugstr_a(profile), delete );
1337
1338 if (machine || !profile) return FALSE;
1339
1340 len = MultiByteToWideChar( CP_ACP, 0, profile, -1, NULL, 0 );
1341 profileW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1342
1343 if (profileW)
1344 {
1345 MultiByteToWideChar( CP_ACP, 0, profile, -1, profileW, len );
1346
1347 ret = UninstallColorProfileW( NULL, profileW , delete );
1348
1349 HeapFree( GetProcessHeap(), 0, profileW );
1350 }
1351 return ret;
1352}
1353
1354/******************************************************************************
1355 * UninstallColorProfileW [MSCMS.@]
1356 *
1357 * Uninstall a color profile.
1358 *
1359 * PARAMS
1360 * machine [I] Name of the machine to uninstall the profile on. Must be NULL,
1361 * which indicates the local machine.
1362 * profile [I] Full path name of the profile to uninstall.
1363 * delete [I] Bool that specifies whether the profile file should be deleted.
1364 *
1365 * RETURNS
1366 * Success: TRUE
1367 * Failure: FALSE
1368 */
1369BOOL WINAPI UninstallColorProfileW( PCWSTR machine, PCWSTR profile, BOOL delete )
1370{
1371 TRACE( "( %s, %x )\n", debugstr_w(profile), delete );
1372
1373 if (machine || !profile) return FALSE;
1374
1375 if (delete) return DeleteFileW( profile );
1376
1377 return TRUE;
1378}
1379
1380/******************************************************************************
1381 * OpenColorProfileA [MSCMS.@]
1382 *
1383 * See OpenColorProfileW.
1384 */
1385HPROFILE WINAPI OpenColorProfileA( PPROFILE profile, DWORD access, DWORD sharing, DWORD creation )
1386{
1387 HPROFILE handle = NULL;
1388
1389 TRACE( "( %p, 0x%08x, 0x%08x, 0x%08x )\n", profile, access, sharing, creation );
1390
1391 if (!profile || !profile->pProfileData) return NULL;
1392
1393 /* No AW conversion needed for memory based profiles */
1394 if (profile->dwType & PROFILE_MEMBUFFER)
1395 return OpenColorProfileW( profile, access, sharing, creation );
1396
1397 if (profile->dwType & PROFILE_FILENAME)
1398 {
1399 UINT len;
1400 PROFILE profileW;
1401
1402 profileW.dwType = profile->dwType;
1403
1404 len = MultiByteToWideChar( CP_ACP, 0, profile->pProfileData, -1, NULL, 0 );
1405 profileW.pProfileData = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1406
1407 if (profileW.pProfileData)
1408 {
1409 profileW.cbDataSize = len * sizeof(WCHAR);
1410 MultiByteToWideChar( CP_ACP, 0, profile->pProfileData, -1, profileW.pProfileData, len );
1411
1412 handle = OpenColorProfileW( &profileW, access, sharing, creation );
1413 HeapFree( GetProcessHeap(), 0, profileW.pProfileData );
1414 }
1415 }
1416 return handle;
1417}
1418
1419/******************************************************************************
1420 * OpenColorProfileW [MSCMS.@]
1421 *
1422 * Open a color profile.
1423 *
1424 * PARAMS
1425 * profile [I] Pointer to a color profile structure.
1426 * access [I] Desired access.
1427 * sharing [I] Sharing mode.
1428 * creation [I] Creation mode.
1429 *
1430 * RETURNS
1431 * Success: Handle to the opened profile.
1432 * Failure: NULL
1433 *
1434 * NOTES
1435 * Values for access: PROFILE_READ or PROFILE_READWRITE.
1436 * Values for sharing: 0 (no sharing), FILE_SHARE_READ and/or FILE_SHARE_WRITE.
1437 * Values for creation: one of CREATE_NEW, CREATE_ALWAYS, OPEN_EXISTING,
1438 * OPEN_ALWAYS, TRUNCATE_EXISTING.
1439 * Sharing and creation flags are ignored for memory based profiles.
1440 */
1441HPROFILE WINAPI OpenColorProfileW( PPROFILE profile, DWORD access, DWORD sharing, DWORD creation )
1442{
1443#ifdef HAVE_LCMS
1444 cmsHPROFILE cmsprofile = NULL;
1445 icProfile *iccprofile = NULL;
1446 HANDLE handle = INVALID_HANDLE_VALUE;
1447
1448 TRACE( "( %p, 0x%08x, 0x%08x, 0x%08x )\n", profile, access, sharing, creation );
1449
1450 if (!profile || !profile->pProfileData) return NULL;
1451
1452 if (profile->dwType == PROFILE_MEMBUFFER)
1453 {
1454 /* FIXME: access flags not implemented for memory based profiles */
1455
1456 if (!(iccprofile = HeapAlloc( GetProcessHeap(), 0, profile->cbDataSize ))) return NULL;
1457 memcpy( iccprofile, profile->pProfileData, profile->cbDataSize );
1458
1459 cmsprofile = cmsOpenProfileFromMem( iccprofile, profile->cbDataSize );
1460 }
1461 else if (profile->dwType == PROFILE_FILENAME)
1462 {
1463 DWORD size, read, flags = 0;
1464
1465 TRACE( "profile file: %s\n", debugstr_w( (WCHAR *)profile->pProfileData ) );
1466
1467 if (access & PROFILE_READ) flags = GENERIC_READ;
1468 if (access & PROFILE_READWRITE) flags = GENERIC_READ|GENERIC_WRITE;
1469
1470 if (!flags) return NULL;
1471 if (!sharing) sharing = FILE_SHARE_READ;
1472
1473 handle = CreateFileW( profile->pProfileData, flags, sharing, NULL, creation, 0, NULL );
1474 if (handle == INVALID_HANDLE_VALUE)
1475 {
1476 WARN( "Unable to open color profile %u\n", GetLastError() );
1477 return NULL;
1478 }
1479
1480 if ((size = GetFileSize( handle, NULL )) == INVALID_FILE_SIZE)
1481 {
1482 ERR( "Unable to retrieve size of color profile\n" );
1483 CloseHandle( handle );
1484 return NULL;
1485 }
1486
1487 iccprofile = HeapAlloc( GetProcessHeap(), 0, size );
1488 if (!iccprofile)
1489 {
1490 ERR( "Unable to allocate memory for color profile\n" );
1491 CloseHandle( handle );
1492 return NULL;
1493 }
1494
1495 if (!ReadFile( handle, iccprofile, size, &read, NULL ) || read != size)
1496 {
1497 ERR( "Unable to read color profile\n" );
1498
1499 CloseHandle( handle );
1500 HeapFree( GetProcessHeap(), 0, iccprofile );
1501 return NULL;
1502 }
1503
1504 cmsprofile = cmsOpenProfileFromMem( iccprofile, size );
1505 }
1506 else
1507 {
1508 ERR( "Invalid profile type %u\n", profile->dwType );
1509 return NULL;
1510 }
1511
1512 if (cmsprofile)
1513 {
1514 struct profile profile;
1515
1516 profile.file = handle;
1517 profile.access = access;
1518 profile.iccprofile = iccprofile;
1519 profile.cmsprofile = cmsprofile;
1520
1521 return create_profile( &profile );
1522 }
1523
1524#endif /* HAVE_LCMS */
1525 return NULL;
1526}
1527
1528/******************************************************************************
1529 * CloseColorProfile [MSCMS.@]
1530 *
1531 * Close a color profile.
1532 *
1533 * PARAMS
1534 * profile [I] Handle to the profile.
1535 *
1536 * RETURNS
1537 * Success: TRUE
1538 * Failure: FALSE
1539 */
1540BOOL WINAPI CloseColorProfile( HPROFILE profile )
1541{
1542 BOOL ret = FALSE;
1543#ifdef HAVE_LCMS
1544
1545 TRACE( "( %p )\n", profile );
1546 ret = close_profile( profile );
1547
1548#endif /* HAVE_LCMS */
1549 return ret;
1550}
Note: See TracBrowser for help on using the repository browser.