windowscodecs: Implement IWICBitmapFlipRotator_Initialize.
[wine/hacks.git] / dlls / windowscodecs / fliprotate.c
blob6db7fea4a6a7e65369e34533e7c26849d51425ff
1 /*
2 * Copyright 2010 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 "objbase.h"
28 #include "wincodec.h"
30 #include "wincodecs_private.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
36 typedef struct FlipRotator {
37 const IWICBitmapFlipRotatorVtbl *lpVtbl;
38 LONG ref;
39 IWICBitmapSource *source;
40 int flip_x;
41 int flip_y;
42 int swap_xy;
43 CRITICAL_SECTION lock; /* must be held when initialized */
44 } FlipRotator;
46 static HRESULT WINAPI FlipRotator_QueryInterface(IWICBitmapFlipRotator *iface, REFIID iid,
47 void **ppv)
49 FlipRotator *This = (FlipRotator*)iface;
50 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
52 if (!ppv) return E_INVALIDARG;
54 if (IsEqualIID(&IID_IUnknown, iid) ||
55 IsEqualIID(&IID_IWICBitmapSource, iid) ||
56 IsEqualIID(&IID_IWICBitmapFlipRotator, iid))
58 *ppv = This;
60 else
62 *ppv = NULL;
63 return E_NOINTERFACE;
66 IUnknown_AddRef((IUnknown*)*ppv);
67 return S_OK;
70 static ULONG WINAPI FlipRotator_AddRef(IWICBitmapFlipRotator *iface)
72 FlipRotator *This = (FlipRotator*)iface;
73 ULONG ref = InterlockedIncrement(&This->ref);
75 TRACE("(%p) refcount=%u\n", iface, ref);
77 return ref;
80 static ULONG WINAPI FlipRotator_Release(IWICBitmapFlipRotator *iface)
82 FlipRotator *This = (FlipRotator*)iface;
83 ULONG ref = InterlockedDecrement(&This->ref);
85 TRACE("(%p) refcount=%u\n", iface, ref);
87 if (ref == 0)
89 This->lock.DebugInfo->Spare[0] = 0;
90 DeleteCriticalSection(&This->lock);
91 if (This->source) IWICBitmapSource_Release(This->source);
92 HeapFree(GetProcessHeap(), 0, This);
95 return ref;
98 static HRESULT WINAPI FlipRotator_GetSize(IWICBitmapFlipRotator *iface,
99 UINT *puiWidth, UINT *puiHeight)
101 FIXME("(%p,%p,%p): stub\n", iface, puiWidth, puiHeight);
103 return E_NOTIMPL;
106 static HRESULT WINAPI FlipRotator_GetPixelFormat(IWICBitmapFlipRotator *iface,
107 WICPixelFormatGUID *pPixelFormat)
109 FIXME("(%p,%p): stub\n", iface, pPixelFormat);
111 return E_NOTIMPL;
114 static HRESULT WINAPI FlipRotator_GetResolution(IWICBitmapFlipRotator *iface,
115 double *pDpiX, double *pDpiY)
117 FIXME("(%p,%p,%p): stub\n", iface, pDpiX, pDpiY);
119 return E_NOTIMPL;
122 static HRESULT WINAPI FlipRotator_CopyPalette(IWICBitmapFlipRotator *iface,
123 IWICPalette *pIPalette)
125 FIXME("(%p,%p): stub\n", iface, pIPalette);
126 return E_NOTIMPL;
129 static HRESULT WINAPI FlipRotator_CopyPixels(IWICBitmapFlipRotator *iface,
130 const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
132 FIXME("(%p,%p,%u,%u,%p): stub\n", iface, prc, cbStride, cbBufferSize, pbBuffer);
134 return E_NOTIMPL;
137 static HRESULT WINAPI FlipRotator_Initialize(IWICBitmapFlipRotator *iface,
138 IWICBitmapSource *pISource, WICBitmapTransformOptions options)
140 FlipRotator *This = (FlipRotator*)iface;
141 HRESULT hr=S_OK;
143 TRACE("(%p,%p,%u)\n", iface, pISource, options);
145 EnterCriticalSection(&This->lock);
147 if (This->source)
149 hr = WINCODEC_ERR_WRONGSTATE;
150 goto end;
153 if (options&WICBitmapTransformRotate90)
155 This->swap_xy = 1;
156 This->flip_x = !This->flip_x;
159 if (options&WICBitmapTransformRotate180)
161 This->flip_x = !This->flip_x;
162 This->flip_y = !This->flip_y;
165 if (options&WICBitmapTransformFlipHorizontal)
166 This->flip_x = !This->flip_x;
168 if (options&WICBitmapTransformFlipVertical)
169 This->flip_y = !This->flip_y;
171 IWICBitmapSource_AddRef(pISource);
172 This->source = pISource;
174 end:
175 LeaveCriticalSection(&This->lock);
177 return hr;
180 static const IWICBitmapFlipRotatorVtbl FlipRotator_Vtbl = {
181 FlipRotator_QueryInterface,
182 FlipRotator_AddRef,
183 FlipRotator_Release,
184 FlipRotator_GetSize,
185 FlipRotator_GetPixelFormat,
186 FlipRotator_GetResolution,
187 FlipRotator_CopyPalette,
188 FlipRotator_CopyPixels,
189 FlipRotator_Initialize
192 HRESULT FlipRotator_Create(IWICBitmapFlipRotator **fliprotator)
194 FlipRotator *This;
196 This = HeapAlloc(GetProcessHeap(), 0, sizeof(FlipRotator));
197 if (!This) return E_OUTOFMEMORY;
199 This->lpVtbl = &FlipRotator_Vtbl;
200 This->ref = 1;
201 This->source = NULL;
202 This->flip_x = 0;
203 This->flip_y = 0;
204 This->swap_xy = 0;
205 InitializeCriticalSection(&This->lock);
206 This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": FlipRotator.lock");
208 *fliprotator = (IWICBitmapFlipRotator*)This;
210 return S_OK;