ReactOS 0.4.15-dev-7934-g1dc8d80
icc.c
Go to the documentation of this file.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include "config.h"
22
23#include <stdarg.h>
24
25#include "windef.h"
26#include "winbase.h"
27#include "wingdi.h"
28#include "winuser.h"
29#include "wine/winternl.h"
30#include "icm.h"
31
32#include "mscms_priv.h"
33
34#ifdef HAVE_LCMS2
35
36static inline void adjust_endianness32( ULONG *ptr )
37{
38#ifndef WORDS_BIGENDIAN
40#endif
41}
42
43void get_profile_header( const struct profile *profile, PROFILEHEADER *header )
44{
45 unsigned int i;
46
47 memcpy( header, profile->data, sizeof(PROFILEHEADER) );
48
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 );
52}
53
54void set_profile_header( const struct profile *profile, const PROFILEHEADER *header )
55{
56 unsigned int i;
57
58 memcpy( profile->data, header, sizeof(PROFILEHEADER) );
59
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 );
63}
64
65static BOOL get_adjusted_tag( const struct profile *profile, TAGTYPE type, cmsTagEntry *tag )
66{
67 DWORD i, num_tags = *(DWORD *)(profile->data + sizeof(cmsICCHeader));
68 cmsTagEntry *entry;
69 ULONG sig;
70
71 adjust_endianness32( &num_tags );
72 for (i = 0; i < num_tags; i++)
73 {
74 entry = (cmsTagEntry *)(profile->data + sizeof(cmsICCHeader) + sizeof(DWORD) + i * sizeof(*tag));
75 sig = entry->sig;
76 adjust_endianness32( &sig );
77 if (sig == type)
78 {
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;
85 }
86 }
87 return FALSE;
88}
89
90BOOL get_tag_data( const struct profile *profile, TAGTYPE type, DWORD offset, void *buffer, DWORD *len )
91{
92 cmsTagEntry tag;
93
94 if (!get_adjusted_tag( profile, type, &tag )) return FALSE;
95
96 if (!buffer) offset = 0;
97 if (offset > tag.size) return FALSE;
98 if (*len < tag.size - offset || !buffer)
99 {
100 *len = tag.size - offset;
101 return FALSE;
102 }
103 memcpy( buffer, profile->data + tag.offset + offset, tag.size - offset );
104 *len = tag.size - offset;
105 return TRUE;
106}
107
108BOOL set_tag_data( const struct profile *profile, TAGTYPE type, DWORD offset, const void *buffer, DWORD *len )
109{
110 cmsTagEntry tag;
111
112 if (!get_adjusted_tag( profile, type, &tag )) return FALSE;
113
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;
118}
119
120#endif /* HAVE_LCMS2 */
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define RtlUlongByteSwap(_x)
Definition: compat.h:815
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
GLenum GLsizei len
Definition: glext.h:6722
GLintptr offset
Definition: glext.h:5920
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
DWORD TAGTYPE
Definition: icm.h:30
struct tagPROFILEHEADER PROFILEHEADER
uint32_t entry
Definition: isohybrid.c:63
#define profile
Definition: kernel32.h:12
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static PVOID ptr
Definition: dispmode.c:27
#define min(a, b)
Definition: monoChain.cc:55
#define DWORD
Definition: nt_native.h:44
Definition: ecma_167.h:138
uint32_t ULONG
Definition: typedefs.h:59