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
30 #include "wincodecs_private.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs
);
36 typedef struct FlipRotator
{
37 IWICBitmapFlipRotator IWICBitmapFlipRotator_iface
;
39 IWICBitmapSource
*source
;
43 CRITICAL_SECTION lock
; /* must be held when initialized */
46 static inline FlipRotator
*impl_from_IWICBitmapFlipRotator(IWICBitmapFlipRotator
*iface
)
48 return CONTAINING_RECORD(iface
, FlipRotator
, IWICBitmapFlipRotator_iface
);
51 static HRESULT WINAPI
FlipRotator_QueryInterface(IWICBitmapFlipRotator
*iface
, REFIID iid
,
54 FlipRotator
*This
= impl_from_IWICBitmapFlipRotator(iface
);
55 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
57 if (!ppv
) return E_INVALIDARG
;
59 if (IsEqualIID(&IID_IUnknown
, iid
) ||
60 IsEqualIID(&IID_IWICBitmapSource
, iid
) ||
61 IsEqualIID(&IID_IWICBitmapFlipRotator
, iid
))
71 IUnknown_AddRef((IUnknown
*)*ppv
);
75 static ULONG WINAPI
FlipRotator_AddRef(IWICBitmapFlipRotator
*iface
)
77 FlipRotator
*This
= impl_from_IWICBitmapFlipRotator(iface
);
78 ULONG ref
= InterlockedIncrement(&This
->ref
);
80 TRACE("(%p) refcount=%u\n", iface
, ref
);
85 static ULONG WINAPI
FlipRotator_Release(IWICBitmapFlipRotator
*iface
)
87 FlipRotator
*This
= impl_from_IWICBitmapFlipRotator(iface
);
88 ULONG ref
= InterlockedDecrement(&This
->ref
);
90 TRACE("(%p) refcount=%u\n", iface
, ref
);
94 This
->lock
.DebugInfo
->Spare
[0] = 0;
95 DeleteCriticalSection(&This
->lock
);
96 if (This
->source
) IWICBitmapSource_Release(This
->source
);
97 HeapFree(GetProcessHeap(), 0, This
);
103 static HRESULT WINAPI
FlipRotator_GetSize(IWICBitmapFlipRotator
*iface
,
104 UINT
*puiWidth
, UINT
*puiHeight
)
106 FlipRotator
*This
= impl_from_IWICBitmapFlipRotator(iface
);
107 TRACE("(%p,%p,%p)\n", iface
, puiWidth
, puiHeight
);
110 return WINCODEC_ERR_WRONGSTATE
;
111 else if (This
->swap_xy
)
112 return IWICBitmapSource_GetSize(This
->source
, puiHeight
, puiWidth
);
114 return IWICBitmapSource_GetSize(This
->source
, puiWidth
, puiHeight
);
117 static HRESULT WINAPI
FlipRotator_GetPixelFormat(IWICBitmapFlipRotator
*iface
,
118 WICPixelFormatGUID
*pPixelFormat
)
120 FIXME("(%p,%p): stub\n", iface
, pPixelFormat
);
125 static HRESULT WINAPI
FlipRotator_GetResolution(IWICBitmapFlipRotator
*iface
,
126 double *pDpiX
, double *pDpiY
)
128 FIXME("(%p,%p,%p): stub\n", iface
, pDpiX
, pDpiY
);
133 static HRESULT WINAPI
FlipRotator_CopyPalette(IWICBitmapFlipRotator
*iface
,
134 IWICPalette
*pIPalette
)
136 FIXME("(%p,%p): stub\n", iface
, pIPalette
);
140 static HRESULT WINAPI
FlipRotator_CopyPixels(IWICBitmapFlipRotator
*iface
,
141 const WICRect
*prc
, UINT cbStride
, UINT cbBufferSize
, BYTE
*pbBuffer
)
143 FlipRotator
*This
= impl_from_IWICBitmapFlipRotator(iface
);
146 UINT srcy
, srcwidth
, srcheight
;
150 TRACE("(%p,%p,%u,%u,%p)\n", iface
, prc
, cbStride
, cbBufferSize
, pbBuffer
);
152 if (!This
->source
) return WINCODEC_ERR_WRONGSTATE
;
154 if (This
->swap_xy
|| This
->flip_x
)
156 /* This requires knowledge of the pixel format. */
157 FIXME("flipping x and rotating are not implemented\n");
161 hr
= IWICBitmapSource_GetSize(This
->source
, &srcwidth
, &srcheight
);
162 if (FAILED(hr
)) return hr
;
167 hr
= IWICBitmapSource_GetSize(iface
, &width
, &height
);
168 if (FAILED(hr
)) return hr
;
172 rect
.Height
= height
;
176 for (y
=prc
->Y
; y
- prc
->Y
< prc
->Height
; y
++)
179 srcy
= srcheight
- 1 - y
;
185 rc
.Width
= prc
->Width
;
188 hr
= IWICBitmapSource_CopyPixels(This
->source
, &rc
, cbStride
, cbStride
,
191 if (FAILED(hr
)) break;
193 pbBuffer
+= cbStride
;
199 static HRESULT WINAPI
FlipRotator_Initialize(IWICBitmapFlipRotator
*iface
,
200 IWICBitmapSource
*pISource
, WICBitmapTransformOptions options
)
202 FlipRotator
*This
= impl_from_IWICBitmapFlipRotator(iface
);
205 TRACE("(%p,%p,%u)\n", iface
, pISource
, options
);
207 EnterCriticalSection(&This
->lock
);
211 hr
= WINCODEC_ERR_WRONGSTATE
;
215 if (options
&WICBitmapTransformRotate90
)
218 This
->flip_x
= !This
->flip_x
;
221 if (options
&WICBitmapTransformRotate180
)
223 This
->flip_x
= !This
->flip_x
;
224 This
->flip_y
= !This
->flip_y
;
227 if (options
&WICBitmapTransformFlipHorizontal
)
228 This
->flip_x
= !This
->flip_x
;
230 if (options
&WICBitmapTransformFlipVertical
)
231 This
->flip_y
= !This
->flip_y
;
233 IWICBitmapSource_AddRef(pISource
);
234 This
->source
= pISource
;
237 LeaveCriticalSection(&This
->lock
);
242 static const IWICBitmapFlipRotatorVtbl FlipRotator_Vtbl
= {
243 FlipRotator_QueryInterface
,
247 FlipRotator_GetPixelFormat
,
248 FlipRotator_GetResolution
,
249 FlipRotator_CopyPalette
,
250 FlipRotator_CopyPixels
,
251 FlipRotator_Initialize
254 HRESULT
FlipRotator_Create(IWICBitmapFlipRotator
**fliprotator
)
258 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(FlipRotator
));
259 if (!This
) return E_OUTOFMEMORY
;
261 This
->IWICBitmapFlipRotator_iface
.lpVtbl
= &FlipRotator_Vtbl
;
267 InitializeCriticalSection(&This
->lock
);
268 This
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": FlipRotator.lock");
270 *fliprotator
= &This
->IWICBitmapFlipRotator_iface
;