ReactOS 0.4.16-dev-751-g45ed1a9
colorcontext.c
Go to the documentation of this file.
1/*
2 * Copyright 2012 Hans Leidekker for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19#include <stdarg.h>
20
21#define COBJMACROS
22
23#include "windef.h"
24#include "winbase.h"
25#include "objbase.h"
26
27#include "wincodecs_private.h"
28
29#include "wine/debug.h"
30
32
33typedef struct ColorContext {
41
43{
44 return CONTAINING_RECORD(iface, ColorContext, IWICColorContext_iface);
45}
46
48 void **ppv)
49{
51 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
52
53 if (!ppv) return E_INVALIDARG;
54
55 if (IsEqualIID(&IID_IUnknown, iid) ||
56 IsEqualIID(&IID_IWICColorContext, iid))
57 {
58 *ppv = &This->IWICColorContext_iface;
59 }
60 else
61 {
62 *ppv = NULL;
63 return E_NOINTERFACE;
64 }
65
66 IUnknown_AddRef((IUnknown*)*ppv);
67 return S_OK;
68}
69
71{
74
75 TRACE("(%p) refcount=%lu\n", iface, ref);
76
77 return ref;
78}
79
81{
84
85 TRACE("(%p) refcount=%lu\n", iface, ref);
86
87 if (ref == 0)
88 {
89 free(This->profile);
90 free(This);
91 }
92
93 return ref;
94}
95
97{
101 BOOL ret;
102
103 *len = 0;
104 *profile = NULL;
107
108 if (!(GetFileSizeEx(handle, &size)))
109 {
112 }
113 if (size.u.HighPart)
114 {
115 WARN("file too large\n");
117 return E_FAIL;
118 }
119 if (!(*profile = malloc(size.u.LowPart)))
120 {
122 return E_OUTOFMEMORY;
123 }
124 ret = ReadFile(handle, *profile, size.u.LowPart, &count, NULL);
126 if (!ret) {
127 free(*profile);
128 *profile = NULL;
130 }
131 if (count != size.u.LowPart) {
132 free(*profile);
133 *profile = NULL;
134 return E_FAIL;
135 }
136 *len = count;
137 return S_OK;
138}
139
141 LPCWSTR wzFilename)
142{
144 BYTE *profile;
145 UINT len;
146 HRESULT hr;
147 TRACE("(%p,%s)\n", iface, debugstr_w(wzFilename));
148
151
152 if (!wzFilename) return E_INVALIDARG;
153
154 hr = load_profile(wzFilename, &profile, &len);
155 if (FAILED(hr)) return hr;
156
157 free(This->profile);
158 This->profile = profile;
159 This->profile_len = len;
161
162 return S_OK;
163}
164
166 const BYTE *pbBuffer, UINT cbBufferSize)
167{
169 BYTE *profile;
170 TRACE("(%p,%p,%u)\n", iface, pbBuffer, cbBufferSize);
171
174
175 if (!(profile = malloc(cbBufferSize))) return E_OUTOFMEMORY;
176 memcpy(profile, pbBuffer, cbBufferSize);
177
178 free(This->profile);
179 This->profile = profile;
180 This->profile_len = cbBufferSize;
182
183 return S_OK;
184}
185
187 UINT value)
188{
190 TRACE("(%p,%u)\n", iface, value);
191
194
195 This->exif_color_space = value;
197
198 return S_OK;
199}
200
202 WICColorContextType *pType)
203{
205 TRACE("(%p,%p)\n", iface, pType);
206
207 if (!pType) return E_INVALIDARG;
208
209 *pType = This->type;
210 return S_OK;
211}
212
214 UINT cbBuffer, BYTE *pbBuffer, UINT *pcbActual)
215{
217 TRACE("(%p,%u,%p,%p)\n", iface, cbBuffer, pbBuffer, pcbActual);
218
219 if (This->type != WICColorContextProfile)
221
222 if (!pcbActual) return E_INVALIDARG;
223
224 if (cbBuffer >= This->profile_len && pbBuffer)
225 memcpy(pbBuffer, This->profile, This->profile_len);
226
227 *pcbActual = This->profile_len;
228
229 return S_OK;
230}
231
233 UINT *pValue)
234{
236 TRACE("(%p,%p)\n", iface, pValue);
237
238 if (!pValue) return E_INVALIDARG;
239
240 *pValue = This->exif_color_space;
241 return S_OK;
242}
243
244static const IWICColorContextVtbl ColorContext_Vtbl = {
254};
255
257{
259
260 if (!colorcontext) return E_INVALIDARG;
261
262 This = malloc(sizeof(ColorContext));
263 if (!This) return E_OUTOFMEMORY;
264
265 This->IWICColorContext_iface.lpVtbl = &ColorContext_Vtbl;
266 This->ref = 1;
267 This->type = 0;
268 This->profile = NULL;
269 This->profile_len = 0;
270 This->exif_color_space = ~0u;
271
272 *colorcontext = &This->IWICColorContext_iface;
273
274 return S_OK;
275}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define WARN(fmt,...)
Definition: precomp.h:61
const GUID IID_IUnknown
static HRESULT load_profile(const WCHAR *filename, BYTE **profile, UINT *len)
Definition: colorcontext.c:96
HRESULT ColorContext_Create(IWICColorContext **colorcontext)
Definition: colorcontext.c:256
static HRESULT WINAPI ColorContext_InitializeFromFilename(IWICColorContext *iface, LPCWSTR wzFilename)
Definition: colorcontext.c:140
static HRESULT WINAPI ColorContext_GetType(IWICColorContext *iface, WICColorContextType *pType)
Definition: colorcontext.c:201
static HRESULT WINAPI ColorContext_GetProfileBytes(IWICColorContext *iface, UINT cbBuffer, BYTE *pbBuffer, UINT *pcbActual)
Definition: colorcontext.c:213
static HRESULT WINAPI ColorContext_QueryInterface(IWICColorContext *iface, REFIID iid, void **ppv)
Definition: colorcontext.c:47
static ULONG WINAPI ColorContext_AddRef(IWICColorContext *iface)
Definition: colorcontext.c:70
static ColorContext * impl_from_IWICColorContext(IWICColorContext *iface)
Definition: colorcontext.c:42
static const IWICColorContextVtbl ColorContext_Vtbl
Definition: colorcontext.c:244
static HRESULT WINAPI ColorContext_InitializeFromExifColorSpace(IWICColorContext *iface, UINT value)
Definition: colorcontext.c:186
static ULONG WINAPI ColorContext_Release(IWICColorContext *iface)
Definition: colorcontext.c:80
static HRESULT WINAPI ColorContext_InitializeFromMemory(IWICColorContext *iface, const BYTE *pbBuffer, UINT cbBufferSize)
Definition: colorcontext.c:165
static HRESULT WINAPI ColorContext_GetExifColorSpace(IWICColorContext *iface, UINT *pValue)
Definition: colorcontext.c:232
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_FAIL
Definition: ddrawi.h:102
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define CreateFileW
Definition: compat.h:741
#define GetFileSizeEx
Definition: compat.h:757
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
PWCHAR pValue
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
GLenum GLsizei len
Definition: glext.h:6722
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 * u
Definition: glfuncs.h:240
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
const char * filename
Definition: ioapi.h:137
#define debugstr_guid
Definition: kernel32.h:35
#define profile
Definition: kernel32.h:12
#define debugstr_w
Definition: kernel32.h:32
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned int UINT
Definition: ndis.h:50
long LONG
Definition: pedump.c:60
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define REFIID
Definition: guiddef.h:118
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
UINT profile_len
Definition: colorcontext.c:38
BYTE * profile
Definition: colorcontext.c:37
UINT exif_color_space
Definition: colorcontext.c:39
WICColorContextType type
Definition: colorcontext.c:36
IWICColorContext IWICColorContext_iface
Definition: colorcontext.c:34
Definition: send.c:48
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
Definition: pdh_main.c:94
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
WICColorContextType
Definition: wincodec.idl:119
@ WICColorContextUninitialized
Definition: wincodec.idl:120
@ WICColorContextExifColorSpace
Definition: wincodec.idl:122
@ WICColorContextProfile
Definition: wincodec.idl:121
#define WINAPI
Definition: msvc.h:6
#define WINCODEC_ERR_WRONGSTATE
Definition: winerror.h:3281
#define WINCODEC_ERR_NOTINITIALIZED
Definition: winerror.h:3285
#define E_NOINTERFACE
Definition: winerror.h:2364
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
unsigned char BYTE
Definition: xxhash.c:193