kernel32: Update Italian translation.
[wine/testsucceed.git] / dlls / windowscodecs / palette.c
blob40ab190958e3e87f39fe7a3ddd8b65f26af07725
1 /*
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
19 #include "config.h"
21 #include <stdarg.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winreg.h"
28 #include "objbase.h"
29 #include "wincodec.h"
31 #include "wincodecs_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
37 typedef struct {
38 const IWICPaletteVtbl *lpIWICPaletteVtbl;
39 LONG ref;
40 UINT count;
41 WICColor *colors;
42 WICBitmapPaletteType type;
43 CRITICAL_SECTION lock; /* must be held when count, colors, or type is accessed */
44 } PaletteImpl;
46 static HRESULT WINAPI PaletteImpl_QueryInterface(IWICPalette *iface, REFIID iid,
47 void **ppv)
49 PaletteImpl *This = (PaletteImpl*)iface;
50 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
52 if (!ppv) return E_INVALIDARG;
54 if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IWICPalette, iid))
56 *ppv = This;
58 else
60 *ppv = NULL;
61 return E_NOINTERFACE;
64 IUnknown_AddRef((IUnknown*)*ppv);
65 return S_OK;
68 static ULONG WINAPI PaletteImpl_AddRef(IWICPalette *iface)
70 PaletteImpl *This = (PaletteImpl*)iface;
71 ULONG ref = InterlockedIncrement(&This->ref);
73 TRACE("(%p) refcount=%u\n", iface, ref);
75 return ref;
78 static ULONG WINAPI PaletteImpl_Release(IWICPalette *iface)
80 PaletteImpl *This = (PaletteImpl*)iface;
81 ULONG ref = InterlockedDecrement(&This->ref);
83 TRACE("(%p) refcount=%u\n", iface, ref);
85 if (ref == 0)
87 This->lock.DebugInfo->Spare[0] = 0;
88 DeleteCriticalSection(&This->lock);
89 HeapFree(GetProcessHeap(), 0, This->colors);
90 HeapFree(GetProcessHeap(), 0, This);
93 return ref;
96 static HRESULT WINAPI PaletteImpl_InitializePredefined(IWICPalette *iface,
97 WICBitmapPaletteType ePaletteType, BOOL fAddTransparentColor)
99 FIXME("(%p,%u,%i): stub\n", iface, ePaletteType, fAddTransparentColor);
100 return E_NOTIMPL;
103 static HRESULT WINAPI PaletteImpl_InitializeCustom(IWICPalette *iface,
104 WICColor *pColors, UINT colorCount)
106 PaletteImpl *This = (PaletteImpl*)iface;
107 WICColor *new_colors;
109 TRACE("(%p,%p,%u)\n", iface, pColors, colorCount);
111 if (colorCount == 0)
113 new_colors = NULL;
115 else
117 if (!pColors) return E_INVALIDARG;
118 new_colors = HeapAlloc(GetProcessHeap(), 0, sizeof(WICColor) * colorCount);
119 if (!new_colors) return E_OUTOFMEMORY;
120 memcpy(new_colors, pColors, sizeof(WICColor) * colorCount);
123 EnterCriticalSection(&This->lock);
124 HeapFree(GetProcessHeap(), 0, This->colors);
125 This->colors = new_colors;
126 This->count = colorCount;
127 This->type = WICBitmapPaletteTypeCustom;
128 LeaveCriticalSection(&This->lock);
130 return S_OK;
133 static HRESULT WINAPI PaletteImpl_InitializeFromBitmap(IWICPalette *iface,
134 IWICBitmapSource *pISurface, UINT colorCount, BOOL fAddTransparentColor)
136 FIXME("(%p,%p,%u,%i): stub\n", iface, pISurface, colorCount, fAddTransparentColor);
137 return E_NOTIMPL;
140 static HRESULT WINAPI PaletteImpl_InitializeFromPalette(IWICPalette *iface,
141 IWICPalette *pIPalette)
143 FIXME("(%p,%p): stub\n", iface, pIPalette);
144 return E_NOTIMPL;
147 static HRESULT WINAPI PaletteImpl_GetType(IWICPalette *iface,
148 WICBitmapPaletteType *pePaletteType)
150 PaletteImpl *This = (PaletteImpl*)iface;
152 TRACE("(%p,%p)\n", iface, pePaletteType);
154 if (!pePaletteType) return E_INVALIDARG;
156 EnterCriticalSection(&This->lock);
157 *pePaletteType = This->type;
158 LeaveCriticalSection(&This->lock);
160 return S_OK;
163 static HRESULT WINAPI PaletteImpl_GetColorCount(IWICPalette *iface, UINT *pcCount)
165 PaletteImpl *This = (PaletteImpl*)iface;
167 TRACE("(%p,%p)\n", iface, pcCount);
169 if (!pcCount) return E_INVALIDARG;
171 EnterCriticalSection(&This->lock);
172 *pcCount = This->count;
173 LeaveCriticalSection(&This->lock);
175 return S_OK;
178 static HRESULT WINAPI PaletteImpl_GetColors(IWICPalette *iface, UINT colorCount,
179 WICColor *pColors, UINT *pcActualColors)
181 PaletteImpl *This = (PaletteImpl*)iface;
183 TRACE("(%p,%i,%p,%p)\n", iface, colorCount, pColors, pcActualColors);
185 if (!pColors || !pcActualColors) return E_INVALIDARG;
187 EnterCriticalSection(&This->lock);
189 if (This->count < colorCount) colorCount = This->count;
191 memcpy(pColors, This->colors, sizeof(WICColor) * colorCount);
193 *pcActualColors = colorCount;
195 LeaveCriticalSection(&This->lock);
197 return S_OK;
200 static HRESULT WINAPI PaletteImpl_IsBlackWhite(IWICPalette *iface, BOOL *pfIsBlackWhite)
202 PaletteImpl *This = (PaletteImpl*)iface;
204 TRACE("(%p,%p)\n", iface, pfIsBlackWhite);
206 if (!pfIsBlackWhite) return E_INVALIDARG;
208 EnterCriticalSection(&This->lock);
209 if (This->type == WICBitmapPaletteTypeFixedBW)
210 *pfIsBlackWhite = TRUE;
211 else
212 *pfIsBlackWhite = FALSE;
213 LeaveCriticalSection(&This->lock);
215 return S_OK;
218 static HRESULT WINAPI PaletteImpl_IsGrayscale(IWICPalette *iface, BOOL *pfIsGrayscale)
220 PaletteImpl *This = (PaletteImpl*)iface;
222 TRACE("(%p,%p)\n", iface, pfIsGrayscale);
224 if (!pfIsGrayscale) return E_INVALIDARG;
226 EnterCriticalSection(&This->lock);
227 switch(This->type)
229 case WICBitmapPaletteTypeFixedBW:
230 case WICBitmapPaletteTypeFixedGray4:
231 case WICBitmapPaletteTypeFixedGray16:
232 case WICBitmapPaletteTypeFixedGray256:
233 *pfIsGrayscale = TRUE;
234 break;
235 default:
236 *pfIsGrayscale = FALSE;
238 LeaveCriticalSection(&This->lock);
240 return S_OK;
243 static HRESULT WINAPI PaletteImpl_HasAlpha(IWICPalette *iface, BOOL *pfHasAlpha)
245 PaletteImpl *This = (PaletteImpl*)iface;
246 int i;
248 TRACE("(%p,%p)\n", iface, pfHasAlpha);
250 if (!pfHasAlpha) return E_INVALIDARG;
252 *pfHasAlpha = FALSE;
254 EnterCriticalSection(&This->lock);
255 for (i=0; i<This->count; i++)
256 if ((This->colors[i]&0xff000000) != 0xff000000)
258 *pfHasAlpha = TRUE;
259 break;
261 LeaveCriticalSection(&This->lock);
263 return S_OK;
266 static const IWICPaletteVtbl PaletteImpl_Vtbl = {
267 PaletteImpl_QueryInterface,
268 PaletteImpl_AddRef,
269 PaletteImpl_Release,
270 PaletteImpl_InitializePredefined,
271 PaletteImpl_InitializeCustom,
272 PaletteImpl_InitializeFromBitmap,
273 PaletteImpl_InitializeFromPalette,
274 PaletteImpl_GetType,
275 PaletteImpl_GetColorCount,
276 PaletteImpl_GetColors,
277 PaletteImpl_IsBlackWhite,
278 PaletteImpl_IsGrayscale,
279 PaletteImpl_HasAlpha
282 HRESULT PaletteImpl_Create(IWICPalette **palette)
284 PaletteImpl *This;
286 This = HeapAlloc(GetProcessHeap(), 0, sizeof(PaletteImpl));
287 if (!This) return E_OUTOFMEMORY;
289 This->lpIWICPaletteVtbl = &PaletteImpl_Vtbl;
290 This->ref = 1;
291 This->count = 0;
292 This->colors = NULL;
293 This->type = WICBitmapPaletteTypeCustom;
294 InitializeCriticalSection(&This->lock);
295 This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": PaletteImpl.lock");
297 *palette = (IWICPalette*)This;
299 return S_OK;