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
32 #include "mscms_priv.h"
36 static inline void adjust_endianness32( ULONG
*ptr
)
38 #ifndef WORDS_BIGENDIAN
39 *ptr
= RtlUlongByteSwap(*ptr
);
43 void get_profile_header( const struct profile
*profile
, PROFILEHEADER
*header
)
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
)
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
));
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
));
76 adjust_endianness32( &sig
);
80 tag
->offset
= entry
->offset
;
81 tag
->size
= entry
->size
;
82 adjust_endianness32( &tag
->offset
);
83 adjust_endianness32( &tag
->size
);
90 BOOL
get_tag_data( const struct profile
*profile
, TAGTYPE type
, DWORD offset
, void *buffer
, DWORD
*len
)
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
;
103 memcpy( buffer
, profile
->data
+ tag
.offset
+ offset
, tag
.size
- offset
);
104 *len
= tag
.size
- offset
;
108 BOOL
set_tag_data( const struct profile
*profile
, TAGTYPE type
, DWORD offset
, const void *buffer
, DWORD
*len
)
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
);
120 #endif /* HAVE_LCMS2 */