2 * Copyright 2009 Vincent Povirk 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
31 #include "wincodecs_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
38 const IWICPaletteVtbl *lpIWICPaletteVtbl;
42 WICBitmapPaletteType type;
45 static HRESULT WINAPI PaletteImpl_QueryInterface(IWICPalette *iface, REFIID iid,
48 PaletteImpl *This = (PaletteImpl*)iface;
49 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
51 if (!ppv) return E_INVALIDARG;
53 if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IWICPalette, iid))
63 IUnknown_AddRef((IUnknown*)*ppv);
67 static ULONG WINAPI PaletteImpl_AddRef(IWICPalette *iface)
69 PaletteImpl *This = (PaletteImpl*)iface;
70 ULONG ref = InterlockedIncrement(&This->ref);
72 TRACE("(%p) refcount=%u\n", iface, ref);
77 static ULONG WINAPI PaletteImpl_Release(IWICPalette *iface)
79 PaletteImpl *This = (PaletteImpl*)iface;
80 ULONG ref = InterlockedDecrement(&This->ref);
82 TRACE("(%p) refcount=%u\n", iface, ref);
86 HeapFree(GetProcessHeap(), 0, This->colors);
87 HeapFree(GetProcessHeap(), 0, This);
93 static HRESULT WINAPI PaletteImpl_InitializePredefined(IWICPalette *iface,
94 WICBitmapPaletteType ePaletteType, BOOL fAddTransparentColor)
96 FIXME("(%p,%u,%i): stub\n", iface, ePaletteType, fAddTransparentColor);
100 static HRESULT WINAPI PaletteImpl_InitializeCustom(IWICPalette *iface,
101 WICColor *pColors, UINT colorCount)
103 PaletteImpl *This = (PaletteImpl*)iface;
104 WICColor *new_colors;
106 TRACE("(%p,%p,%u)\n", iface, pColors, colorCount);
114 if (!pColors) return E_INVALIDARG;
115 new_colors = HeapAlloc(GetProcessHeap(), 0, sizeof(WICColor) * colorCount);
116 if (!new_colors) return E_OUTOFMEMORY;
117 memcpy(new_colors, pColors, sizeof(WICColor) * colorCount);
120 HeapFree(GetProcessHeap(), 0, This->colors);
121 This->colors = new_colors;
122 This->count = colorCount;
123 This->type = WICBitmapPaletteTypeCustom;
128 static HRESULT WINAPI PaletteImpl_InitializeFromBitmap(IWICPalette *iface,
129 IWICBitmapSource *pISurface, UINT colorCount, BOOL fAddTransparentColor)
131 FIXME("(%p,%p,%u,%i): stub\n", iface, pISurface, colorCount, fAddTransparentColor);
135 static HRESULT WINAPI PaletteImpl_InitializeFromPalette(IWICPalette *iface,
136 IWICPalette *pIPalette)
138 FIXME("(%p,%p): stub\n", iface, pIPalette);
142 static HRESULT WINAPI PaletteImpl_GetType(IWICPalette *iface,
143 WICBitmapPaletteType *pePaletteType)
145 PaletteImpl *This = (PaletteImpl*)iface;
147 TRACE("(%p,%p)\n", iface, pePaletteType);
149 if (!pePaletteType) return E_INVALIDARG;
151 *pePaletteType = This->type;
156 static HRESULT WINAPI PaletteImpl_GetColorCount(IWICPalette *iface, UINT *pcCount)
158 PaletteImpl *This = (PaletteImpl*)iface;
160 TRACE("(%p,%p)\n", iface, pcCount);
162 if (!pcCount) return E_INVALIDARG;
164 *pcCount = This->count;
169 static HRESULT WINAPI PaletteImpl_GetColors(IWICPalette *iface, UINT colorCount,
170 WICColor *pColors, UINT *pcActualColors)
172 PaletteImpl *This = (PaletteImpl*)iface;
174 TRACE("(%p,%i,%p,%p)\n", iface, colorCount, pColors, pcActualColors);
176 if (!pColors || !pcActualColors) return E_INVALIDARG;
178 if (This->count < colorCount) colorCount = This->count;
180 memcpy(pColors, This->colors, sizeof(WICColor) * colorCount);
182 *pcActualColors = colorCount;
187 static HRESULT WINAPI PaletteImpl_IsBlackWhite(IWICPalette *iface, BOOL *pfIsBlackWhite)
189 PaletteImpl *This = (PaletteImpl*)iface;
191 TRACE("(%p,%p)\n", iface, pfIsBlackWhite);
193 if (!pfIsBlackWhite) return E_INVALIDARG;
195 if (This->type == WICBitmapPaletteTypeFixedBW)
196 *pfIsBlackWhite = TRUE;
198 *pfIsBlackWhite = FALSE;
203 static HRESULT WINAPI PaletteImpl_IsGrayscale(IWICPalette *iface, BOOL *pfIsGrayscale)
205 PaletteImpl *This = (PaletteImpl*)iface;
207 TRACE("(%p,%p)\n", iface, pfIsGrayscale);
209 if (!pfIsGrayscale) return E_INVALIDARG;
213 case WICBitmapPaletteTypeFixedBW:
214 case WICBitmapPaletteTypeFixedGray4:
215 case WICBitmapPaletteTypeFixedGray16:
216 case WICBitmapPaletteTypeFixedGray256:
217 *pfIsGrayscale = TRUE;
220 *pfIsGrayscale = FALSE;
226 static HRESULT WINAPI PaletteImpl_HasAlpha(IWICPalette *iface, BOOL *pfHasAlpha)
228 PaletteImpl *This = (PaletteImpl*)iface;
231 TRACE("(%p,%p)\n", iface, pfHasAlpha);
233 if (!pfHasAlpha) return E_INVALIDARG;
237 for (i=0; i<This->count; i++)
238 if ((This->colors[i]&0xff000000) != 0xff000000)
247 static const IWICPaletteVtbl PaletteImpl_Vtbl = {
248 PaletteImpl_QueryInterface,
251 PaletteImpl_InitializePredefined,
252 PaletteImpl_InitializeCustom,
253 PaletteImpl_InitializeFromBitmap,
254 PaletteImpl_InitializeFromPalette,
256 PaletteImpl_GetColorCount,
257 PaletteImpl_GetColors,
258 PaletteImpl_IsBlackWhite,
259 PaletteImpl_IsGrayscale,
263 HRESULT PaletteImpl_Create(IWICPalette **palette)
267 This = HeapAlloc(GetProcessHeap(), 0, sizeof(PaletteImpl));
268 if (!This) return E_OUTOFMEMORY;
270 This->lpIWICPaletteVtbl = &PaletteImpl_Vtbl;
274 This->type = WICBitmapPaletteTypeCustom;
276 *palette = (IWICPalette*)This;