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 BitmapScaler {
37 IWICBitmapScaler IWICBitmapScaler_iface;
39 IWICBitmapSource *source;
41 WICBitmapInterpolationMode mode;
42 CRITICAL_SECTION lock; /* must be held when initialized */
45 static inline BitmapScaler *impl_from_IWICBitmapScaler(IWICBitmapScaler *iface)
47 return CONTAINING_RECORD(iface, BitmapScaler, IWICBitmapScaler_iface);
50 static HRESULT WINAPI BitmapScaler_QueryInterface(IWICBitmapScaler *iface, REFIID iid,
53 BitmapScaler *This = impl_from_IWICBitmapScaler(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_IWICBitmapSource, iid) ||
60 IsEqualIID(&IID_IWICBitmapScaler, iid))
70 IUnknown_AddRef((IUnknown*)*ppv);
74 static ULONG WINAPI BitmapScaler_AddRef(IWICBitmapScaler *iface)
76 BitmapScaler *This = impl_from_IWICBitmapScaler(iface);
77 ULONG ref = InterlockedIncrement(&This->ref);
79 TRACE("(%p) refcount=%u\n", iface, ref);
84 static ULONG WINAPI BitmapScaler_Release(IWICBitmapScaler *iface)
86 BitmapScaler *This = impl_from_IWICBitmapScaler(iface);
87 ULONG ref = InterlockedDecrement(&This->ref);
89 TRACE("(%p) refcount=%u\n", iface, ref);
93 This->lock.DebugInfo->Spare[0] = 0;
94 DeleteCriticalSection(&This->lock);
95 if (This->source) IWICBitmapSource_Release(This->source);
96 HeapFree(GetProcessHeap(), 0, This);
102 static HRESULT WINAPI BitmapScaler_GetSize(IWICBitmapScaler *iface,
103 UINT *puiWidth, UINT *puiHeight)
105 BitmapScaler *This = impl_from_IWICBitmapScaler(iface);
106 TRACE("(%p,%p,%p)\n", iface, puiWidth, puiHeight);
108 if (!puiWidth || !puiHeight)
112 return WINCODEC_ERR_WRONGSTATE;
114 *puiWidth = This->width;
115 *puiHeight = This->height;
120 static HRESULT WINAPI BitmapScaler_GetPixelFormat(IWICBitmapScaler *iface,
121 WICPixelFormatGUID *pPixelFormat)
123 BitmapScaler *This = impl_from_IWICBitmapScaler(iface);
124 TRACE("(%p,%p)\n", iface, pPixelFormat);
130 return WINCODEC_ERR_WRONGSTATE;
132 return IWICBitmapSource_GetPixelFormat(This->source, pPixelFormat);
135 static HRESULT WINAPI BitmapScaler_GetResolution(IWICBitmapScaler *iface,
136 double *pDpiX, double *pDpiY)
138 FIXME("(%p,%p,%p): stub\n", iface, pDpiX, pDpiY);
143 static HRESULT WINAPI BitmapScaler_CopyPalette(IWICBitmapScaler *iface,
144 IWICPalette *pIPalette)
146 FIXME("(%p,%p): stub\n", iface, pIPalette);
151 static HRESULT WINAPI BitmapScaler_CopyPixels(IWICBitmapScaler *iface,
152 const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
154 FIXME("(%p,%p,%u,%u,%p): stub\n", iface, prc, cbStride, cbBufferSize, pbBuffer);
159 static HRESULT WINAPI BitmapScaler_Initialize(IWICBitmapScaler *iface,
160 IWICBitmapSource *pISource, UINT uiWidth, UINT uiHeight,
161 WICBitmapInterpolationMode mode)
163 BitmapScaler *This = impl_from_IWICBitmapScaler(iface);
166 TRACE("(%p,%p,%u,%u,%u)\n", iface, pISource, uiWidth, uiHeight, mode);
168 EnterCriticalSection(&This->lock);
172 hr = WINCODEC_ERR_WRONGSTATE;
176 IWICBitmapSource_AddRef(pISource);
177 This->source = pISource;
179 This->width = uiWidth;
180 This->height = uiHeight;
184 LeaveCriticalSection(&This->lock);
189 static const IWICBitmapScalerVtbl BitmapScaler_Vtbl = {
190 BitmapScaler_QueryInterface,
192 BitmapScaler_Release,
193 BitmapScaler_GetSize,
194 BitmapScaler_GetPixelFormat,
195 BitmapScaler_GetResolution,
196 BitmapScaler_CopyPalette,
197 BitmapScaler_CopyPixels,
198 BitmapScaler_Initialize
201 HRESULT BitmapScaler_Create(IWICBitmapScaler **scaler)
205 This = HeapAlloc(GetProcessHeap(), 0, sizeof(BitmapScaler));
206 if (!This) return E_OUTOFMEMORY;
208 This->IWICBitmapScaler_iface.lpVtbl = &BitmapScaler_Vtbl;
214 InitializeCriticalSection(&This->lock);
215 This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": BitmapScaler.lock");
217 *scaler = &This->IWICBitmapScaler_iface;