windowscodecs: Add wrapper functions for IWICBitmap methods.
[wine/multimedia.git] / dlls / windowscodecs / imgfactory.c
bloba2e8e7f7f1dd9aaf3fd243f8b02d55d7f509ee54
1 /*
2 * Copyright 2009 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 "winreg.h"
28 #include "objbase.h"
29 #include "shellapi.h"
30 #include "wincodec.h"
32 #include "wincodecs_private.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
38 typedef struct {
39 IWICImagingFactory IWICImagingFactory_iface;
40 LONG ref;
41 } ImagingFactory;
43 static inline ImagingFactory *impl_from_IWICImagingFactory(IWICImagingFactory *iface)
45 return CONTAINING_RECORD(iface, ImagingFactory, IWICImagingFactory_iface);
48 static HRESULT WINAPI ImagingFactory_QueryInterface(IWICImagingFactory *iface, REFIID iid,
49 void **ppv)
51 ImagingFactory *This = impl_from_IWICImagingFactory(iface);
52 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
54 if (!ppv) return E_INVALIDARG;
56 if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IWICImagingFactory, 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 ImagingFactory_AddRef(IWICImagingFactory *iface)
72 ImagingFactory *This = impl_from_IWICImagingFactory(iface);
73 ULONG ref = InterlockedIncrement(&This->ref);
75 TRACE("(%p) refcount=%u\n", iface, ref);
77 return ref;
80 static ULONG WINAPI ImagingFactory_Release(IWICImagingFactory *iface)
82 ImagingFactory *This = impl_from_IWICImagingFactory(iface);
83 ULONG ref = InterlockedDecrement(&This->ref);
85 TRACE("(%p) refcount=%u\n", iface, ref);
87 if (ref == 0)
88 HeapFree(GetProcessHeap(), 0, This);
90 return ref;
93 static HRESULT WINAPI ImagingFactory_CreateDecoderFromFilename(
94 IWICImagingFactory *iface, LPCWSTR wzFilename, const GUID *pguidVendor,
95 DWORD dwDesiredAccess, WICDecodeOptions metadataOptions,
96 IWICBitmapDecoder **ppIDecoder)
98 IWICStream *stream;
99 HRESULT hr;
101 TRACE("(%p,%s,%s,%u,%u,%p)\n", iface, debugstr_w(wzFilename),
102 debugstr_guid(pguidVendor), dwDesiredAccess, metadataOptions, ppIDecoder);
104 hr = StreamImpl_Create(&stream);
105 if (SUCCEEDED(hr))
107 hr = IWICStream_InitializeFromFilename(stream, wzFilename, dwDesiredAccess);
109 if (SUCCEEDED(hr))
111 hr = IWICImagingFactory_CreateDecoderFromStream(iface, (IStream*)stream,
112 pguidVendor, metadataOptions, ppIDecoder);
115 IWICStream_Release(stream);
118 return hr;
121 static HRESULT WINAPI ImagingFactory_CreateDecoderFromStream(
122 IWICImagingFactory *iface, IStream *pIStream, const GUID *pguidVendor,
123 WICDecodeOptions metadataOptions, IWICBitmapDecoder **ppIDecoder)
125 static int fixme=0;
126 IEnumUnknown *enumdecoders;
127 IUnknown *unkdecoderinfo;
128 IWICBitmapDecoderInfo *decoderinfo;
129 IWICBitmapDecoder *decoder=NULL;
130 HRESULT res=S_OK;
131 ULONG num_fetched;
132 BOOL matches;
134 TRACE("(%p,%p,%s,%u,%p)\n", iface, pIStream, debugstr_guid(pguidVendor),
135 metadataOptions, ppIDecoder);
137 if (pguidVendor && !fixme++)
138 FIXME("ignoring vendor GUID\n");
140 res = CreateComponentEnumerator(WICDecoder, WICComponentEnumerateDefault, &enumdecoders);
141 if (FAILED(res)) return res;
143 while (!decoder)
145 res = IEnumUnknown_Next(enumdecoders, 1, &unkdecoderinfo, &num_fetched);
147 if (res == S_OK)
149 res = IUnknown_QueryInterface(unkdecoderinfo, &IID_IWICBitmapDecoderInfo, (void**)&decoderinfo);
151 if (SUCCEEDED(res))
153 res = IWICBitmapDecoderInfo_MatchesPattern(decoderinfo, pIStream, &matches);
155 if (SUCCEEDED(res) && matches)
157 res = IWICBitmapDecoderInfo_CreateInstance(decoderinfo, &decoder);
159 /* FIXME: should use QueryCapability to choose a decoder */
161 if (SUCCEEDED(res))
163 res = IWICBitmapDecoder_Initialize(decoder, pIStream, metadataOptions);
165 if (FAILED(res))
167 IWICBitmapDecoder_Release(decoder);
168 decoder = NULL;
173 IWICBitmapDecoderInfo_Release(decoderinfo);
176 IUnknown_Release(unkdecoderinfo);
178 else
179 break;
182 IEnumUnknown_Release(enumdecoders);
184 if (decoder)
186 *ppIDecoder = decoder;
187 return S_OK;
189 else
191 if (WARN_ON(wincodecs))
193 LARGE_INTEGER seek;
194 BYTE data[4];
195 ULONG bytesread;
197 WARN("failed to load from a stream\n");
199 seek.QuadPart = 0;
200 res = IStream_Seek(pIStream, seek, STREAM_SEEK_SET, NULL);
201 if (SUCCEEDED(res))
202 res = IStream_Read(pIStream, data, 4, &bytesread);
203 if (SUCCEEDED(res))
204 WARN("first %i bytes of stream=%x %x %x %x\n", bytesread, data[0], data[1], data[2], data[3]);
206 *ppIDecoder = NULL;
207 return WINCODEC_ERR_COMPONENTNOTFOUND;
211 static HRESULT WINAPI ImagingFactory_CreateDecoderFromFileHandle(
212 IWICImagingFactory *iface, ULONG_PTR hFile, const GUID *pguidVendor,
213 WICDecodeOptions metadataOptions, IWICBitmapDecoder **ppIDecoder)
215 FIXME("(%p,%lx,%s,%u,%p): stub\n", iface, hFile, debugstr_guid(pguidVendor),
216 metadataOptions, ppIDecoder);
217 return E_NOTIMPL;
220 static HRESULT WINAPI ImagingFactory_CreateComponentInfo(IWICImagingFactory *iface,
221 REFCLSID clsidComponent, IWICComponentInfo **ppIInfo)
223 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(clsidComponent), ppIInfo);
224 return CreateComponentInfo(clsidComponent, ppIInfo);
227 static HRESULT WINAPI ImagingFactory_CreateDecoder(IWICImagingFactory *iface,
228 REFGUID guidContainerFormat, const GUID *pguidVendor,
229 IWICBitmapDecoder **ppIDecoder)
231 FIXME("(%p,%s,%s,%p): stub\n", iface, debugstr_guid(guidContainerFormat),
232 debugstr_guid(pguidVendor), ppIDecoder);
233 return E_NOTIMPL;
236 static HRESULT WINAPI ImagingFactory_CreateEncoder(IWICImagingFactory *iface,
237 REFGUID guidContainerFormat, const GUID *pguidVendor,
238 IWICBitmapEncoder **ppIEncoder)
240 FIXME("(%p,%s,%s,%p): stub\n", iface, debugstr_guid(guidContainerFormat),
241 debugstr_guid(pguidVendor), ppIEncoder);
242 return E_NOTIMPL;
245 static HRESULT WINAPI ImagingFactory_CreatePalette(IWICImagingFactory *iface,
246 IWICPalette **ppIPalette)
248 TRACE("(%p,%p)\n", iface, ppIPalette);
249 return PaletteImpl_Create(ppIPalette);
252 static HRESULT WINAPI ImagingFactory_CreateFormatConverter(IWICImagingFactory *iface,
253 IWICFormatConverter **ppIFormatConverter)
255 return FormatConverter_CreateInstance(NULL, &IID_IWICFormatConverter, (void**)ppIFormatConverter);
258 static HRESULT WINAPI ImagingFactory_CreateBitmapScaler(IWICImagingFactory *iface,
259 IWICBitmapScaler **ppIBitmapScaler)
261 FIXME("(%p,%p): stub\n", iface, ppIBitmapScaler);
262 return E_NOTIMPL;
265 static HRESULT WINAPI ImagingFactory_CreateBitmapClipper(IWICImagingFactory *iface,
266 IWICBitmapClipper **ppIBitmapClipper)
268 FIXME("(%p,%p): stub\n", iface, ppIBitmapClipper);
269 return E_NOTIMPL;
272 static HRESULT WINAPI ImagingFactory_CreateBitmapFlipRotator(IWICImagingFactory *iface,
273 IWICBitmapFlipRotator **ppIBitmapFlipRotator)
275 TRACE("(%p,%p)\n", iface, ppIBitmapFlipRotator);
276 return FlipRotator_Create(ppIBitmapFlipRotator);
279 static HRESULT WINAPI ImagingFactory_CreateStream(IWICImagingFactory *iface,
280 IWICStream **ppIWICStream)
282 TRACE("(%p,%p)\n", iface, ppIWICStream);
283 return StreamImpl_Create(ppIWICStream);
286 static HRESULT WINAPI ImagingFactory_CreateColorContext(IWICImagingFactory *iface,
287 IWICColorContext **ppIColorContext)
289 FIXME("(%p,%p): stub\n", iface, ppIColorContext);
290 return E_NOTIMPL;
293 static HRESULT WINAPI ImagingFactory_CreateColorTransformer(IWICImagingFactory *iface,
294 IWICColorTransform **ppIColorTransform)
296 FIXME("(%p,%p): stub\n", iface, ppIColorTransform);
297 return E_NOTIMPL;
300 static HRESULT WINAPI ImagingFactory_CreateBitmap(IWICImagingFactory *iface,
301 UINT uiWidth, UINT uiHeight, REFWICPixelFormatGUID pixelFormat,
302 WICBitmapCreateCacheOption option, IWICBitmap **ppIBitmap)
304 FIXME("(%p,%u,%u,%s,%u,%p): stub\n", iface, uiWidth, uiHeight,
305 debugstr_guid(pixelFormat), option, ppIBitmap);
306 return E_NOTIMPL;
309 static HRESULT WINAPI ImagingFactory_CreateBitmapFromSource(IWICImagingFactory *iface,
310 IWICBitmapSource *piBitmapSource, WICBitmapCreateCacheOption option,
311 IWICBitmap **ppIBitmap)
313 FIXME("(%p,%p,%u,%p): stub\n", iface, piBitmapSource, option, ppIBitmap);
314 return E_NOTIMPL;
317 static HRESULT WINAPI ImagingFactory_CreateBitmapFromSourceRect(IWICImagingFactory *iface,
318 IWICBitmapSource *piBitmapSource, UINT x, UINT y, UINT width, UINT height,
319 IWICBitmap **ppIBitmap)
321 FIXME("(%p,%p,%u,%u,%u,%u,%p): stub\n", iface, piBitmapSource, x, y, width,
322 height, ppIBitmap);
323 return E_NOTIMPL;
326 static HRESULT WINAPI ImagingFactory_CreateBitmapFromMemory(IWICImagingFactory *iface,
327 UINT uiWidth, UINT uiHeight, REFWICPixelFormatGUID pixelFormat, UINT cbStride,
328 UINT cbBufferSize, BYTE *pbBuffer, IWICBitmap **ppIBitmap)
330 FIXME("(%p,%u,%u,%s,%u,%u,%p,%p): stub\n", iface, uiWidth, uiHeight,
331 debugstr_guid(pixelFormat), cbStride, cbBufferSize, pbBuffer, ppIBitmap);
332 return E_NOTIMPL;
335 static HRESULT WINAPI ImagingFactory_CreateBitmapFromHBITMAP(IWICImagingFactory *iface,
336 HBITMAP hBitmap, HPALETTE hPalette, WICBitmapAlphaChannelOption options,
337 IWICBitmap **ppIBitmap)
339 FIXME("(%p,%p,%p,%u,%p): stub\n", iface, hBitmap, hPalette, options, ppIBitmap);
340 return E_NOTIMPL;
343 static HRESULT WINAPI ImagingFactory_CreateBitmapFromHICON(IWICImagingFactory *iface,
344 HICON hIcon, IWICBitmap **ppIBitmap)
346 FIXME("(%p,%p,%p): stub\n", iface, hIcon, ppIBitmap);
347 return E_NOTIMPL;
350 static HRESULT WINAPI ImagingFactory_CreateComponentEnumerator(IWICImagingFactory *iface,
351 DWORD componentTypes, DWORD options, IEnumUnknown **ppIEnumUnknown)
353 TRACE("(%p,%u,%u,%p)\n", iface, componentTypes, options, ppIEnumUnknown);
354 return CreateComponentEnumerator(componentTypes, options, ppIEnumUnknown);
357 static HRESULT WINAPI ImagingFactory_CreateFastMetadataEncoderFromDecoder(
358 IWICImagingFactory *iface, IWICBitmapDecoder *pIDecoder,
359 IWICFastMetadataEncoder **ppIFastEncoder)
361 FIXME("(%p,%p,%p): stub\n", iface, pIDecoder, ppIFastEncoder);
362 return E_NOTIMPL;
365 static HRESULT WINAPI ImagingFactory_CreateFastMetadataEncoderFromFrameDecode(
366 IWICImagingFactory *iface, IWICBitmapFrameDecode *pIFrameDecoder,
367 IWICFastMetadataEncoder **ppIFastEncoder)
369 FIXME("(%p,%p,%p): stub\n", iface, pIFrameDecoder, ppIFastEncoder);
370 return E_NOTIMPL;
373 static HRESULT WINAPI ImagingFactory_CreateQueryWriter(IWICImagingFactory *iface,
374 REFGUID guidMetadataFormat, const GUID *pguidVendor,
375 IWICMetadataQueryWriter **ppIQueryWriter)
377 FIXME("(%p,%s,%s,%p): stub\n", iface, debugstr_guid(guidMetadataFormat),
378 debugstr_guid(pguidVendor), ppIQueryWriter);
379 return E_NOTIMPL;
382 static HRESULT WINAPI ImagingFactory_CreateQueryWriterFromReader(IWICImagingFactory *iface,
383 IWICMetadataQueryReader *pIQueryReader, const GUID *pguidVendor,
384 IWICMetadataQueryWriter **ppIQueryWriter)
386 FIXME("(%p,%p,%s,%p): stub\n", iface, pIQueryReader, debugstr_guid(pguidVendor),
387 ppIQueryWriter);
388 return E_NOTIMPL;
391 static const IWICImagingFactoryVtbl ImagingFactory_Vtbl = {
392 ImagingFactory_QueryInterface,
393 ImagingFactory_AddRef,
394 ImagingFactory_Release,
395 ImagingFactory_CreateDecoderFromFilename,
396 ImagingFactory_CreateDecoderFromStream,
397 ImagingFactory_CreateDecoderFromFileHandle,
398 ImagingFactory_CreateComponentInfo,
399 ImagingFactory_CreateDecoder,
400 ImagingFactory_CreateEncoder,
401 ImagingFactory_CreatePalette,
402 ImagingFactory_CreateFormatConverter,
403 ImagingFactory_CreateBitmapScaler,
404 ImagingFactory_CreateBitmapClipper,
405 ImagingFactory_CreateBitmapFlipRotator,
406 ImagingFactory_CreateStream,
407 ImagingFactory_CreateColorContext,
408 ImagingFactory_CreateColorTransformer,
409 ImagingFactory_CreateBitmap,
410 ImagingFactory_CreateBitmapFromSource,
411 ImagingFactory_CreateBitmapFromSourceRect,
412 ImagingFactory_CreateBitmapFromMemory,
413 ImagingFactory_CreateBitmapFromHBITMAP,
414 ImagingFactory_CreateBitmapFromHICON,
415 ImagingFactory_CreateComponentEnumerator,
416 ImagingFactory_CreateFastMetadataEncoderFromDecoder,
417 ImagingFactory_CreateFastMetadataEncoderFromFrameDecode,
418 ImagingFactory_CreateQueryWriter,
419 ImagingFactory_CreateQueryWriterFromReader
422 HRESULT ImagingFactory_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv)
424 ImagingFactory *This;
425 HRESULT ret;
427 TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv);
429 *ppv = NULL;
431 if (pUnkOuter) return CLASS_E_NOAGGREGATION;
433 This = HeapAlloc(GetProcessHeap(), 0, sizeof(ImagingFactory));
434 if (!This) return E_OUTOFMEMORY;
436 This->IWICImagingFactory_iface.lpVtbl = &ImagingFactory_Vtbl;
437 This->ref = 1;
439 ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv);
440 IUnknown_Release((IUnknown*)This);
442 return ret;