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 FIXME("(%p,%p,%p): stub\n", iface, puiWidth, puiHeight);
110 static HRESULT WINAPI BitmapScaler_GetPixelFormat(IWICBitmapScaler *iface,
111 WICPixelFormatGUID *pPixelFormat)
113 FIXME("(%p,%p): stub\n", iface, pPixelFormat);
118 static HRESULT WINAPI BitmapScaler_GetResolution(IWICBitmapScaler *iface,
119 double *pDpiX, double *pDpiY)
121 FIXME("(%p,%p,%p): stub\n", iface, pDpiX, pDpiY);
126 static HRESULT WINAPI BitmapScaler_CopyPalette(IWICBitmapScaler *iface,
127 IWICPalette *pIPalette)
129 FIXME("(%p,%p): stub\n", iface, pIPalette);
134 static HRESULT WINAPI BitmapScaler_CopyPixels(IWICBitmapScaler *iface,
135 const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
137 FIXME("(%p,%p,%u,%u,%p): stub\n", iface, prc, cbStride, cbBufferSize, pbBuffer);
142 static HRESULT WINAPI BitmapScaler_Initialize(IWICBitmapScaler *iface,
143 IWICBitmapSource *pISource, UINT uiWidth, UINT uiHeight,
144 WICBitmapInterpolationMode mode)
146 BitmapScaler *This = impl_from_IWICBitmapScaler(iface);
149 TRACE("(%p,%p,%u,%u,%u)\n", iface, pISource, uiWidth, uiHeight, mode);
151 EnterCriticalSection(&This->lock);
155 hr = WINCODEC_ERR_WRONGSTATE;
159 IWICBitmapSource_AddRef(pISource);
160 This->source = pISource;
162 This->width = uiWidth;
163 This->height = uiHeight;
167 LeaveCriticalSection(&This->lock);
172 static const IWICBitmapScalerVtbl BitmapScaler_Vtbl = {
173 BitmapScaler_QueryInterface,
175 BitmapScaler_Release,
176 BitmapScaler_GetSize,
177 BitmapScaler_GetPixelFormat,
178 BitmapScaler_GetResolution,
179 BitmapScaler_CopyPalette,
180 BitmapScaler_CopyPixels,
181 BitmapScaler_Initialize
184 HRESULT BitmapScaler_Create(IWICBitmapScaler **scaler)
188 This = HeapAlloc(GetProcessHeap(), 0, sizeof(BitmapScaler));
189 if (!This) return E_OUTOFMEMORY;
191 This->IWICBitmapScaler_iface.lpVtbl = &BitmapScaler_Vtbl;
197 InitializeCriticalSection(&This->lock);
198 This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": BitmapScaler.lock");
200 *scaler = &This->IWICBitmapScaler_iface;