d3d8: Get rid of the format switching code in d3d8_device_CopyRects().
[wine.git] / dlls / mscms / icc.c
blob3b1c718b1740055c187034fb94f608c99bd1f528
1 /*
2 * MSCMS - Color Management System for Wine
4 * Copyright 2004, 2005 Hans Leidekker
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "winternl.h"
30 #include "icm.h"
32 #include "mscms_priv.h"
34 #ifdef HAVE_LCMS2
36 static inline void adjust_endianness32( ULONG *ptr )
38 #ifndef WORDS_BIGENDIAN
39 *ptr = RtlUlongByteSwap(*ptr);
40 #endif
43 void get_profile_header( const struct profile *profile, PROFILEHEADER *header )
45 unsigned int i;
47 memcpy( header, profile->data, sizeof(PROFILEHEADER) );
49 /* ICC format is big-endian, swap bytes if necessary */
50 for (i = 0; i < sizeof(PROFILEHEADER) / sizeof(ULONG); i++)
51 adjust_endianness32( (ULONG *)header + i );
54 void set_profile_header( const struct profile *profile, const PROFILEHEADER *header )
56 unsigned int i;
58 memcpy( profile->data, header, sizeof(PROFILEHEADER) );
60 /* ICC format is big-endian, swap bytes if necessary */
61 for (i = 0; i < sizeof(PROFILEHEADER) / sizeof(ULONG); i++)
62 adjust_endianness32( (ULONG *)profile->data + i );
65 static BOOL get_adjusted_tag( const struct profile *profile, TAGTYPE type, cmsTagEntry *tag )
67 DWORD i, num_tags = *(DWORD *)(profile->data + sizeof(cmsICCHeader));
68 cmsTagEntry *entry;
69 ULONG sig;
71 adjust_endianness32( &num_tags );
72 for (i = 0; i < num_tags; i++)
74 entry = (cmsTagEntry *)(profile->data + sizeof(cmsICCHeader) + sizeof(DWORD) + i * sizeof(*tag));
75 sig = entry->sig;
76 adjust_endianness32( &sig );
77 if (sig == type)
79 tag->sig = sig;
80 tag->offset = entry->offset;
81 tag->size = entry->size;
82 adjust_endianness32( &tag->offset );
83 adjust_endianness32( &tag->size );
84 return TRUE;
87 return FALSE;
90 BOOL get_tag_data( const struct profile *profile, TAGTYPE type, DWORD offset, void *buffer, DWORD *len )
92 cmsTagEntry tag;
94 if (!get_adjusted_tag( profile, type, &tag )) return FALSE;
96 if (!buffer) offset = 0;
97 if (offset > tag.size) return FALSE;
98 if (*len < tag.size - offset || !buffer)
100 *len = tag.size - offset;
101 return FALSE;
103 memcpy( buffer, profile->data + tag.offset + offset, tag.size - offset );
104 *len = tag.size - offset;
105 return TRUE;
108 BOOL set_tag_data( const struct profile *profile, TAGTYPE type, DWORD offset, const void *buffer, DWORD *len )
110 cmsTagEntry tag;
112 if (!get_adjusted_tag( profile, type, &tag )) return FALSE;
114 if (offset > tag.size) return FALSE;
115 *len = min( tag.size - offset, *len );
116 memcpy( profile->data + tag.offset + offset, buffer, *len );
117 return TRUE;
120 #endif /* HAVE_LCMS2 */