2 * Copyright 2012 Hans Leidekker for CodeWeavers
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.
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.
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
30 #include "wincodecs_private.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
36 typedef struct ColorContext {
37 IWICColorContext IWICColorContext_iface;
39 WICColorContextType type;
42 UINT exif_color_space;
45 static inline ColorContext *impl_from_IWICColorContext(IWICColorContext *iface)
47 return CONTAINING_RECORD(iface, ColorContext, IWICColorContext_iface);
50 static HRESULT WINAPI ColorContext_QueryInterface(IWICColorContext *iface, REFIID iid,
53 ColorContext *This = impl_from_IWICColorContext(iface);
54 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
56 if (!ppv) return E_INVALIDARG;
58 if (IsEqualIID(&IID_IUnknown, iid) ||
59 IsEqualIID(&IID_IWICColorContext, iid))
61 *ppv = &This->IWICColorContext_iface;
69 IUnknown_AddRef((IUnknown*)*ppv);
73 static ULONG WINAPI ColorContext_AddRef(IWICColorContext *iface)
75 ColorContext *This = impl_from_IWICColorContext(iface);
76 ULONG ref = InterlockedIncrement(&This->ref);
78 TRACE("(%p) refcount=%u\n", iface, ref);
83 static ULONG WINAPI ColorContext_Release(IWICColorContext *iface)
85 ColorContext *This = impl_from_IWICColorContext(iface);
86 ULONG ref = InterlockedDecrement(&This->ref);
88 TRACE("(%p) refcount=%u\n", iface, ref);
92 HeapFree(GetProcessHeap(), 0, This->profile);
93 HeapFree(GetProcessHeap(), 0, This);
99 static HRESULT WINAPI ColorContext_InitializeFromFilename(IWICColorContext *iface,
102 FIXME("(%p,%s)\n", iface, debugstr_w(wzFilename));
106 static HRESULT WINAPI ColorContext_InitializeFromMemory(IWICColorContext *iface,
107 const BYTE *pbBuffer, UINT cbBufferSize)
109 ColorContext *This = impl_from_IWICColorContext(iface);
110 TRACE("(%p,%p,%u)\n", iface, pbBuffer, cbBufferSize);
112 if (This->type != WICColorContextUninitialized)
113 return WINCODEC_ERR_WRONGSTATE;
115 HeapFree(GetProcessHeap(), 0, This->profile);
116 if (!(This->profile = HeapAlloc(GetProcessHeap(), 0, cbBufferSize)))
117 return E_OUTOFMEMORY;
119 memcpy(This->profile, pbBuffer, cbBufferSize);
120 This->profile_len = cbBufferSize;
121 This->type = WICColorContextProfile;
126 static HRESULT WINAPI ColorContext_InitializeFromExifColorSpace(IWICColorContext *iface,
129 ColorContext *This = impl_from_IWICColorContext(iface);
130 TRACE("(%p,%u)\n", iface, value);
132 if (This->type != WICColorContextUninitialized && This->type != WICColorContextExifColorSpace)
133 return WINCODEC_ERR_WRONGSTATE;
135 This->exif_color_space = value;
136 This->type = WICColorContextExifColorSpace;
141 static HRESULT WINAPI ColorContext_GetType(IWICColorContext *iface,
142 WICColorContextType *pType)
144 ColorContext *This = impl_from_IWICColorContext(iface);
145 TRACE("(%p,%p)\n", iface, pType);
147 if (!pType) return E_INVALIDARG;
153 static HRESULT WINAPI ColorContext_GetProfileBytes(IWICColorContext *iface,
154 UINT cbBuffer, BYTE *pbBuffer, UINT *pcbActual)
156 ColorContext *This = impl_from_IWICColorContext(iface);
157 TRACE("(%p,%u,%p,%p)\n", iface, cbBuffer, pbBuffer, pcbActual);
159 if (This->type != WICColorContextProfile)
160 return WINCODEC_ERR_NOTINITIALIZED;
162 if (!pcbActual) return E_INVALIDARG;
164 if (cbBuffer >= This->profile_len && pbBuffer)
165 memcpy(pbBuffer, This->profile, This->profile_len);
167 *pcbActual = This->profile_len;
172 static HRESULT WINAPI ColorContext_GetExifColorSpace(IWICColorContext *iface,
175 ColorContext *This = impl_from_IWICColorContext(iface);
176 TRACE("(%p,%p)\n", iface, pValue);
178 if (!pValue) return E_INVALIDARG;
180 *pValue = This->exif_color_space;
184 static const IWICColorContextVtbl ColorContext_Vtbl = {
185 ColorContext_QueryInterface,
187 ColorContext_Release,
188 ColorContext_InitializeFromFilename,
189 ColorContext_InitializeFromMemory,
190 ColorContext_InitializeFromExifColorSpace,
191 ColorContext_GetType,
192 ColorContext_GetProfileBytes,
193 ColorContext_GetExifColorSpace
196 HRESULT ColorContext_Create(IWICColorContext **colorcontext)
200 if (!colorcontext) return E_INVALIDARG;
202 This = HeapAlloc(GetProcessHeap(), 0, sizeof(ColorContext));
203 if (!This) return E_OUTOFMEMORY;
205 This->IWICColorContext_iface.lpVtbl = &ColorContext_Vtbl;
208 This->profile = NULL;
209 This->profile_len = 0;
210 This->exif_color_space = ~0u;
212 *colorcontext = &This->IWICColorContext_iface;