icc.c 2.98 KB
Newer Older
1 2 3
/*
 * MSCMS - Color Management System for Wine
 *
4
 * Copyright 2004, 2005 Hans Leidekker
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * 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
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
 */

#include "config.h"

#include <stdarg.h>

#include "windef.h"
#include "winbase.h"
#include "winnls.h"
#include "wingdi.h"
#include "winuser.h"
#include "winreg.h"
#include "winternl.h"
#include "icm.h"

34
#include "mscms_priv.h"
35

36
#ifdef HAVE_LCMS
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92

static inline void MSCMS_adjust_endianess32( ULONG *ptr )
{
#ifndef WORDS_BIGENDIAN
    *ptr = RtlUlongByteSwap(*ptr);
#endif
}

void MSCMS_get_profile_header( icProfile *iccprofile, PROFILEHEADER *header )
{
    unsigned int i;

    memcpy( header, iccprofile, sizeof(PROFILEHEADER) );

    /* ICC format is big-endian, swap bytes if necessary */
    for (i = 0; i < sizeof(PROFILEHEADER) / sizeof(ULONG); i++)
        MSCMS_adjust_endianess32( (ULONG *)header + i );
}

void MSCMS_set_profile_header( icProfile *iccprofile, PROFILEHEADER *header )
{
    unsigned int i;
    icHeader *iccheader = (icHeader *)iccprofile;

    memcpy( iccheader, header, sizeof(icHeader) );

    /* ICC format is big-endian, swap bytes if necessary */
    for (i = 0; i < sizeof(icHeader) / sizeof(ULONG); i++)
        MSCMS_adjust_endianess32( (ULONG *)iccheader + i );
}

DWORD MSCMS_get_tag_count( icProfile *iccprofile )
{
    ULONG count = iccprofile->count;

    MSCMS_adjust_endianess32( &count );
    return count;
}

void MSCMS_get_tag_by_index( icProfile *iccprofile, DWORD index, icTag *tag )
{
    icTag *tmp = (icTag *)((char *)&iccprofile->data + index * sizeof(icTag));

    tag->sig = tmp->sig;
    tag->offset = tmp->offset;
    tag->size = tmp->size;

    MSCMS_adjust_endianess32( (ULONG *)&tag->sig );
    MSCMS_adjust_endianess32( (ULONG *)&tag->offset );
    MSCMS_adjust_endianess32( (ULONG *)&tag->size );
}

void MSCMS_get_tag_data( icProfile *iccprofile, icTag *tag, DWORD offset, void *buffer )
{
    memcpy( buffer, (char *)iccprofile + tag->offset + offset, tag->size - offset );
}
93 94 95 96 97 98

void MSCMS_set_tag_data( icProfile *iccprofile, icTag *tag, DWORD offset, void *buffer )
{
    memcpy( (char *)iccprofile + tag->offset + offset, buffer, tag->size - offset );
}

99 100 101 102 103 104 105 106
DWORD MSCMS_get_profile_size( icProfile *iccprofile )
{
    DWORD size = ((icHeader *)iccprofile)->size;

    MSCMS_adjust_endianess32( (ULONG *)&size );
    return size;
}

107
#endif /* HAVE_LCMS */