mscms: Add tests for EnumColorProfiles{A,W}.
[wine] / dlls / mscms / icc.c
1 /*
2  * MSCMS - Color Management System for Wine
3  *
4  * Copyright 2004, 2005 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22 #include "wine/debug.h"
23
24 #include <stdarg.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winnls.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "winreg.h"
32 #include "winternl.h"
33 #include "icm.h"
34
35 #include "mscms_priv.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(mscms);
38
39 #ifdef HAVE_LCMS
40
41 static inline void MSCMS_adjust_endianess32( ULONG *ptr )
42 {
43 #ifndef WORDS_BIGENDIAN
44     *ptr = RtlUlongByteSwap(*ptr);
45 #endif
46 }
47
48 void MSCMS_get_profile_header( icProfile *iccprofile, PROFILEHEADER *header )
49 {
50     unsigned int i;
51
52     memcpy( header, iccprofile, sizeof(PROFILEHEADER) );
53
54     /* ICC format is big-endian, swap bytes if necessary */
55     for (i = 0; i < sizeof(PROFILEHEADER) / sizeof(ULONG); i++)
56         MSCMS_adjust_endianess32( (ULONG *)header + i );
57 }
58
59 void MSCMS_set_profile_header( icProfile *iccprofile, PROFILEHEADER *header )
60 {
61     unsigned int i;
62     icHeader *iccheader = (icHeader *)iccprofile;
63
64     memcpy( iccheader, header, sizeof(icHeader) );
65
66     /* ICC format is big-endian, swap bytes if necessary */
67     for (i = 0; i < sizeof(icHeader) / sizeof(ULONG); i++)
68         MSCMS_adjust_endianess32( (ULONG *)iccheader + i );
69 }
70
71 DWORD MSCMS_get_tag_count( icProfile *iccprofile )
72 {
73     ULONG count = iccprofile->count;
74
75     MSCMS_adjust_endianess32( &count );
76     return count;
77 }
78
79 void MSCMS_get_tag_by_index( icProfile *iccprofile, DWORD index, icTag *tag )
80 {
81     icTag *tmp = (icTag *)((char *)&iccprofile->data + index * sizeof(icTag));
82
83     tag->sig = tmp->sig;
84     tag->offset = tmp->offset;
85     tag->size = tmp->size;
86
87     MSCMS_adjust_endianess32( (ULONG *)&tag->sig );
88     MSCMS_adjust_endianess32( (ULONG *)&tag->offset );
89     MSCMS_adjust_endianess32( (ULONG *)&tag->size );
90 }
91
92 void MSCMS_get_tag_data( icProfile *iccprofile, icTag *tag, DWORD offset, void *buffer )
93 {
94     memcpy( buffer, (char *)iccprofile + tag->offset + offset, tag->size - offset );
95 }
96
97 void MSCMS_set_tag_data( icProfile *iccprofile, icTag *tag, DWORD offset, void *buffer )
98 {
99     memcpy( (char *)iccprofile + tag->offset + offset, buffer, tag->size - offset );
100 }
101
102 DWORD MSCMS_get_profile_size( icProfile *iccprofile )
103 {
104     DWORD size = ((icHeader *)iccprofile)->size;
105
106     MSCMS_adjust_endianess32( (ULONG *)&size );
107     return size;
108 }
109
110 #endif /* HAVE_LCMS */