windowscodecs: Add a stub IWICBitmap implementation.
[wine] / dlls / windowscodecs / bitmap.c
1 /*
2  * Copyright 2012 Vincent Povirk for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include "config.h"
20
21 #include <stdarg.h>
22
23 #define COBJMACROS
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "objbase.h"
28 #include "wincodec.h"
29
30 #include "wincodecs_private.h"
31
32 #include "wine/debug.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
35
36 typedef struct BitmapImpl {
37     IWICBitmap IWICBitmap_iface;
38     LONG ref;
39 } BitmapImpl;
40
41 static inline BitmapImpl *impl_from_IWICBitmap(IWICBitmap *iface)
42 {
43     return CONTAINING_RECORD(iface, BitmapImpl, IWICBitmap_iface);
44 }
45
46 static HRESULT WINAPI BitmapImpl_QueryInterface(IWICBitmap *iface, REFIID iid,
47     void **ppv)
48 {
49     BitmapImpl *This = impl_from_IWICBitmap(iface);
50     TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
51
52     if (!ppv) return E_INVALIDARG;
53
54     if (IsEqualIID(&IID_IUnknown, iid) ||
55         IsEqualIID(&IID_IWICBitmapSource, iid) ||
56         IsEqualIID(&IID_IWICBitmap, iid))
57     {
58         *ppv = &This->IWICBitmap_iface;
59     }
60     else
61     {
62         *ppv = NULL;
63         return E_NOINTERFACE;
64     }
65
66     IUnknown_AddRef((IUnknown*)*ppv);
67     return S_OK;
68 }
69
70 static ULONG WINAPI BitmapImpl_AddRef(IWICBitmap *iface)
71 {
72     BitmapImpl *This = impl_from_IWICBitmap(iface);
73     ULONG ref = InterlockedIncrement(&This->ref);
74
75     TRACE("(%p) refcount=%u\n", iface, ref);
76
77     return ref;
78 }
79
80 static ULONG WINAPI BitmapImpl_Release(IWICBitmap *iface)
81 {
82     BitmapImpl *This = impl_from_IWICBitmap(iface);
83     ULONG ref = InterlockedDecrement(&This->ref);
84
85     TRACE("(%p) refcount=%u\n", iface, ref);
86
87     if (ref == 0)
88     {
89         HeapFree(GetProcessHeap(), 0, This);
90     }
91
92     return ref;
93 }
94
95 static HRESULT WINAPI BitmapImpl_GetSize(IWICBitmap *iface,
96     UINT *puiWidth, UINT *puiHeight)
97 {
98     FIXME("(%p,%p,%p)\n", iface, puiWidth, puiHeight);
99
100     return E_NOTIMPL;
101 }
102
103 static HRESULT WINAPI BitmapImpl_GetPixelFormat(IWICBitmap *iface,
104     WICPixelFormatGUID *pPixelFormat)
105 {
106     FIXME("(%p,%p)\n", iface, pPixelFormat);
107
108     return E_NOTIMPL;
109 }
110
111 static HRESULT WINAPI BitmapImpl_GetResolution(IWICBitmap *iface,
112     double *pDpiX, double *pDpiY)
113 {
114     FIXME("(%p,%p,%p)\n", iface, pDpiX, pDpiY);
115
116     return E_NOTIMPL;
117 }
118
119 static HRESULT WINAPI BitmapImpl_CopyPalette(IWICBitmap *iface,
120     IWICPalette *pIPalette)
121 {
122     FIXME("(%p,%p)\n", iface, pIPalette);
123
124     return E_NOTIMPL;
125 }
126
127 static HRESULT WINAPI BitmapImpl_CopyPixels(IWICBitmap *iface,
128     const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
129 {
130     FIXME("(%p,%p,%u,%u,%p)\n", iface, prc, cbStride, cbBufferSize, pbBuffer);
131
132     return E_NOTIMPL;
133 }
134
135 static HRESULT WINAPI BitmapImpl_Lock(IWICBitmap *iface, const WICRect *prcLock,
136     DWORD flags, IWICBitmapLock **ppILock)
137 {
138     FIXME("(%p,%p,%x,%p)\n", iface, prcLock, flags, ppILock);
139
140     return E_NOTIMPL;
141 }
142
143 static HRESULT WINAPI BitmapImpl_SetPalette(IWICBitmap *iface, IWICPalette *pIPalette)
144 {
145     FIXME("(%p,%p)\n", iface, pIPalette);
146
147     return E_NOTIMPL;
148 }
149
150 static HRESULT WINAPI BitmapImpl_SetResolution(IWICBitmap *iface,
151     double dpiX, double dpiY)
152 {
153     FIXME("(%p,%f,%f)\n", iface, dpiX, dpiY);
154
155     return E_NOTIMPL;
156 }
157
158 static const IWICBitmapVtbl BitmapImpl_Vtbl = {
159     BitmapImpl_QueryInterface,
160     BitmapImpl_AddRef,
161     BitmapImpl_Release,
162     BitmapImpl_GetSize,
163     BitmapImpl_GetPixelFormat,
164     BitmapImpl_GetResolution,
165     BitmapImpl_CopyPalette,
166     BitmapImpl_CopyPixels,
167     BitmapImpl_Lock,
168     BitmapImpl_SetPalette,
169     BitmapImpl_SetResolution
170 };
171
172 HRESULT BitmapImpl_Create(UINT uiWidth, UINT uiHeight,
173     REFWICPixelFormatGUID pixelFormat, WICBitmapCreateCacheOption option,
174     IWICBitmap **ppIBitmap)
175 {
176     BitmapImpl *This;
177
178     This = HeapAlloc(GetProcessHeap(), 0, sizeof(BitmapImpl));
179     if (!This) return E_OUTOFMEMORY;
180
181     This->IWICBitmap_iface.lpVtbl = &BitmapImpl_Vtbl;
182     This->ref = 1;
183
184     *ppIBitmap = &This->IWICBitmap_iface;
185
186     return S_OK;
187 }