2004-12-07 15:42:47 +01:00
|
|
|
/*
|
|
|
|
* MSCMS - Color Management System for Wine
|
|
|
|
*
|
2005-02-14 21:53:59 +01:00
|
|
|
* Copyright 2004, 2005 Hans Leidekker
|
2004-12-07 15:42:47 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-12-07 15:42:47 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "winternl.h"
|
|
|
|
#include "icm.h"
|
|
|
|
|
2005-07-15 12:09:43 +02:00
|
|
|
#include "mscms_priv.h"
|
2004-12-07 15:42:47 +01:00
|
|
|
|
2013-07-26 13:02:40 +02:00
|
|
|
#ifdef HAVE_LCMS2
|
2004-12-07 15:42:47 +01:00
|
|
|
|
2013-07-26 13:02:40 +02:00
|
|
|
static inline void adjust_endianness32( ULONG *ptr )
|
2004-12-07 15:42:47 +01:00
|
|
|
{
|
|
|
|
#ifndef WORDS_BIGENDIAN
|
|
|
|
*ptr = RtlUlongByteSwap(*ptr);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-07-26 13:02:40 +02:00
|
|
|
void get_profile_header( const struct profile *profile, PROFILEHEADER *header )
|
2004-12-07 15:42:47 +01:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2013-07-26 13:02:40 +02:00
|
|
|
memcpy( header, profile->data, sizeof(PROFILEHEADER) );
|
2004-12-07 15:42:47 +01:00
|
|
|
|
|
|
|
/* ICC format is big-endian, swap bytes if necessary */
|
|
|
|
for (i = 0; i < sizeof(PROFILEHEADER) / sizeof(ULONG); i++)
|
2013-07-26 13:02:40 +02:00
|
|
|
adjust_endianness32( (ULONG *)header + i );
|
2004-12-07 15:42:47 +01:00
|
|
|
}
|
|
|
|
|
2013-07-26 13:02:40 +02:00
|
|
|
void set_profile_header( const struct profile *profile, const PROFILEHEADER *header )
|
2004-12-07 15:42:47 +01:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2013-07-26 13:02:40 +02:00
|
|
|
memcpy( profile->data, header, sizeof(PROFILEHEADER) );
|
2004-12-07 15:42:47 +01:00
|
|
|
|
|
|
|
/* ICC format is big-endian, swap bytes if necessary */
|
2013-07-26 13:02:40 +02:00
|
|
|
for (i = 0; i < sizeof(PROFILEHEADER) / sizeof(ULONG); i++)
|
|
|
|
adjust_endianness32( (ULONG *)profile->data + i );
|
2004-12-07 15:42:47 +01:00
|
|
|
}
|
|
|
|
|
2013-07-26 13:02:40 +02:00
|
|
|
static BOOL get_adjusted_tag( const struct profile *profile, TAGTYPE type, cmsTagEntry *tag )
|
2004-12-07 15:42:47 +01:00
|
|
|
{
|
2013-07-26 13:02:40 +02:00
|
|
|
DWORD i, num_tags = *(DWORD *)(profile->data + sizeof(cmsICCHeader));
|
|
|
|
cmsTagEntry *entry;
|
|
|
|
ULONG sig;
|
|
|
|
|
|
|
|
adjust_endianness32( &num_tags );
|
|
|
|
for (i = 0; i < num_tags; i++)
|
|
|
|
{
|
|
|
|
entry = (cmsTagEntry *)(profile->data + sizeof(cmsICCHeader) + sizeof(DWORD) + i * sizeof(*tag));
|
|
|
|
sig = entry->sig;
|
|
|
|
adjust_endianness32( &sig );
|
|
|
|
if (sig == type)
|
|
|
|
{
|
|
|
|
tag->sig = sig;
|
|
|
|
tag->offset = entry->offset;
|
|
|
|
tag->size = entry->size;
|
|
|
|
adjust_endianness32( &tag->offset );
|
|
|
|
adjust_endianness32( &tag->size );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
2004-12-07 15:42:47 +01:00
|
|
|
}
|
|
|
|
|
2013-07-26 13:02:40 +02:00
|
|
|
BOOL get_tag_data( const struct profile *profile, TAGTYPE type, DWORD offset, void *buffer, DWORD *len )
|
2004-12-07 15:42:47 +01:00
|
|
|
{
|
2013-07-26 13:02:40 +02:00
|
|
|
cmsTagEntry tag;
|
|
|
|
|
|
|
|
if (!get_adjusted_tag( profile, type, &tag )) return FALSE;
|
|
|
|
|
|
|
|
if (!buffer) offset = 0;
|
|
|
|
if (offset > tag.size) return FALSE;
|
|
|
|
if (*len < tag.size - offset || !buffer)
|
|
|
|
{
|
|
|
|
*len = tag.size - offset;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
memcpy( buffer, profile->data + tag.offset + offset, tag.size - offset );
|
|
|
|
*len = tag.size - offset;
|
|
|
|
return TRUE;
|
2004-12-07 15:42:47 +01:00
|
|
|
}
|
|
|
|
|
2013-07-26 13:02:40 +02:00
|
|
|
BOOL set_tag_data( const struct profile *profile, TAGTYPE type, DWORD offset, const void *buffer, DWORD *len )
|
2004-12-07 15:42:47 +01:00
|
|
|
{
|
2013-07-26 13:02:40 +02:00
|
|
|
cmsTagEntry tag;
|
2004-12-13 14:23:17 +01:00
|
|
|
|
2013-07-26 13:02:40 +02:00
|
|
|
if (!get_adjusted_tag( profile, type, &tag )) return FALSE;
|
2005-02-14 21:53:59 +01:00
|
|
|
|
2013-07-26 13:02:40 +02:00
|
|
|
if (offset > tag.size) return FALSE;
|
|
|
|
*len = min( tag.size - offset, *len );
|
|
|
|
memcpy( profile->data + tag.offset + offset, buffer, *len );
|
|
|
|
return TRUE;
|
2005-02-14 21:53:59 +01:00
|
|
|
}
|
|
|
|
|
2013-07-26 13:02:40 +02:00
|
|
|
#endif /* HAVE_LCMS2 */
|