urlmon: Improve IUri support for mk: URIs.
[wine/multimedia.git] / dlls / windowscodecs / imgfactory.c
blob5c81b9885aed26854ef461d463e3b6d76e94673a
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 const IWICImagingFactoryVtbl *lpIWICImagingFactoryVtbl;
40 LONG ref;
41 } ImagingFactory;
43 static HRESULT WINAPI ImagingFactory_QueryInterface(IWICImagingFactory *iface, REFIID iid,
44 void **ppv)
46 ImagingFactory *This = (ImagingFactory*)iface;
47 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
49 if (!ppv) return E_INVALIDARG;
51 if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IWICImagingFactory, iid))
53 *ppv = This;
55 else
57 *ppv = NULL;
58 return E_NOINTERFACE;
61 IUnknown_AddRef((IUnknown*)*ppv);
62 return S_OK;
65 static ULONG WINAPI ImagingFactory_AddRef(IWICImagingFactory *iface)
67 ImagingFactory *This = (ImagingFactory*)iface;
68 ULONG ref = InterlockedIncrement(&This->ref);
70 TRACE("(%p) refcount=%u\n", iface, ref);
72 return ref;
75 static ULONG WINAPI ImagingFactory_Release(IWICImagingFactory *iface)
77 ImagingFactory *This = (ImagingFactory*)iface;
78 ULONG ref = InterlockedDecrement(&This->ref);
80 TRACE("(%p) refcount=%u\n", iface, ref);
82 if (ref == 0)
83 HeapFree(GetProcessHeap(), 0, This);
85 return ref;
88 static HRESULT WINAPI ImagingFactory_CreateDecoderFromFilename(
89 IWICImagingFactory *iface, LPCWSTR wzFilename, const GUID *pguidVendor,
90 DWORD dwDesiredAccess, WICDecodeOptions metadataOptions,
91 IWICBitmapDecoder **ppIDecoder)
93 IWICStream *stream;
94 HRESULT hr;
96 TRACE("(%p,%s,%s,%u,%u,%p)\n", iface, debugstr_w(wzFilename),
97 debugstr_guid(pguidVendor), dwDesiredAccess, metadataOptions, ppIDecoder);
99 hr = StreamImpl_Create(&stream);
100 if (SUCCEEDED(hr))
102 hr = IWICStream_InitializeFromFilename(stream, wzFilename, dwDesiredAccess);
104 if (SUCCEEDED(hr))
106 hr = IWICImagingFactory_CreateDecoderFromStream(iface, (IStream*)stream,
107 pguidVendor, metadataOptions, ppIDecoder);
110 IWICStream_Release(stream);
113 return hr;
116 static HRESULT WINAPI ImagingFactory_CreateDecoderFromStream(
117 IWICImagingFactory *iface, IStream *pIStream, const GUID *pguidVendor,
118 WICDecodeOptions metadataOptions, IWICBitmapDecoder **ppIDecoder)
120 static int fixme=0;
121 IEnumUnknown *enumdecoders;
122 IUnknown *unkdecoderinfo;
123 IWICBitmapDecoderInfo *decoderinfo;
124 IWICBitmapDecoder *decoder=NULL;
125 HRESULT res=S_OK;
126 ULONG num_fetched;
127 BOOL matches;
129 TRACE("(%p,%p,%s,%u,%p)\n", iface, pIStream, debugstr_guid(pguidVendor),
130 metadataOptions, ppIDecoder);
132 if (pguidVendor && !fixme++)
133 FIXME("ignoring vendor GUID\n");
135 res = CreateComponentEnumerator(WICDecoder, WICComponentEnumerateDefault, &enumdecoders);
136 if (FAILED(res)) return res;
138 while (!decoder)
140 res = IEnumUnknown_Next(enumdecoders, 1, &unkdecoderinfo, &num_fetched);
142 if (res == S_OK)
144 res = IUnknown_QueryInterface(unkdecoderinfo, &IID_IWICBitmapDecoderInfo, (void**)&decoderinfo);
146 if (SUCCEEDED(res))
148 res = IWICBitmapDecoderInfo_MatchesPattern(decoderinfo, pIStream, &matches);
150 if (SUCCEEDED(res) && matches)
152 res = IWICBitmapDecoderInfo_CreateInstance(decoderinfo, &decoder);
154 /* FIXME: should use QueryCapability to choose a decoder */
156 if (SUCCEEDED(res))
158 res = IWICBitmapDecoder_Initialize(decoder, pIStream, metadataOptions);
160 if (FAILED(res))
162 IWICBitmapDecoder_Release(decoder);
163 decoder = NULL;
168 IWICBitmapDecoderInfo_Release(decoderinfo);
171 IUnknown_Release(unkdecoderinfo);
173 else
174 break;
177 IEnumUnknown_Release(enumdecoders);
179 if (decoder)
181 *ppIDecoder = decoder;
182 return S_OK;
184 else
186 if (WARN_ON(wincodecs))
188 LARGE_INTEGER seek;
189 BYTE data[4];
190 ULONG bytesread;
192 WARN("failed to load from a stream\n");
194 seek.QuadPart = 0;
195 res = IStream_Seek(pIStream, seek, STREAM_SEEK_SET, NULL);
196 if (SUCCEEDED(res))
197 res = IStream_Read(pIStream, data, 4, &bytesread);
198 if (SUCCEEDED(res))
199 WARN("first %i bytes of stream=%x %x %x %x\n", bytesread, data[0], data[1], data[2], data[3]);
201 *ppIDecoder = NULL;
202 return WINCODEC_ERR_COMPONENTNOTFOUND;
206 static HRESULT WINAPI ImagingFactory_CreateDecoderFromFileHandle(
207 IWICImagingFactory *iface, ULONG_PTR hFile, const GUID *pguidVendor,
208 WICDecodeOptions metadataOptions, IWICBitmapDecoder **ppIDecoder)
210 FIXME("(%p,%lx,%s,%u,%p): stub\n", iface, hFile, debugstr_guid(pguidVendor),
211 metadataOptions, ppIDecoder);
212 return E_NOTIMPL;
215 static HRESULT WINAPI ImagingFactory_CreateComponentInfo(IWICImagingFactory *iface,
216 REFCLSID clsidComponent, IWICComponentInfo **ppIInfo)
218 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(clsidComponent), ppIInfo);
219 return CreateComponentInfo(clsidComponent, ppIInfo);
222 static HRESULT WINAPI ImagingFactory_CreateDecoder(IWICImagingFactory *iface,
223 REFGUID guidContainerFormat, const GUID *pguidVendor,
224 IWICBitmapDecoder **ppIDecoder)
226 FIXME("(%p,%s,%s,%p): stub\n", iface, debugstr_guid(guidContainerFormat),
227 debugstr_guid(pguidVendor), ppIDecoder);
228 return E_NOTIMPL;
231 static HRESULT WINAPI ImagingFactory_CreateEncoder(IWICImagingFactory *iface,
232 REFGUID guidContainerFormat, const GUID *pguidVendor,
233 IWICBitmapEncoder **ppIEncoder)
235 FIXME("(%p,%s,%s,%p): stub\n", iface, debugstr_guid(guidContainerFormat),
236 debugstr_guid(pguidVendor), ppIEncoder);
237 return E_NOTIMPL;
240 static HRESULT WINAPI ImagingFactory_CreatePalette(IWICImagingFactory *iface,
241 IWICPalette **ppIPalette)
243 TRACE("(%p,%p)\n", iface, ppIPalette);
244 return PaletteImpl_Create(ppIPalette);
247 static HRESULT WINAPI ImagingFactory_CreateFormatConverter(IWICImagingFactory *iface,
248 IWICFormatConverter **ppIFormatConverter)
250 return FormatConverter_CreateInstance(NULL, &IID_IWICFormatConverter, (void**)ppIFormatConverter);
253 static HRESULT WINAPI ImagingFactory_CreateBitmapScaler(IWICImagingFactory *iface,
254 IWICBitmapScaler **ppIBitmapScaler)
256 FIXME("(%p,%p): stub\n", iface, ppIBitmapScaler);
257 return E_NOTIMPL;
260 static HRESULT WINAPI ImagingFactory_CreateBitmapClipper(IWICImagingFactory *iface,
261 IWICBitmapClipper **ppIBitmapClipper)
263 FIXME("(%p,%p): stub\n", iface, ppIBitmapClipper);
264 return E_NOTIMPL;
267 static HRESULT WINAPI ImagingFactory_CreateBitmapFlipRotator(IWICImagingFactory *iface,
268 IWICBitmapFlipRotator **ppIBitmapFlipRotator)
270 TRACE("(%p,%p)\n", iface, ppIBitmapFlipRotator);
271 return FlipRotator_Create(ppIBitmapFlipRotator);
274 static HRESULT WINAPI ImagingFactory_CreateStream(IWICImagingFactory *iface,
275 IWICStream **ppIWICStream)
277 TRACE("(%p,%p)\n", iface, ppIWICStream);
278 return StreamImpl_Create(ppIWICStream);
281 static HRESULT WINAPI ImagingFactory_CreateColorContext(IWICImagingFactory *iface,
282 IWICColorContext **ppIColorContext)
284 FIXME("(%p,%p): stub\n", iface, ppIColorContext);
285 return E_NOTIMPL;
288 static HRESULT WINAPI ImagingFactory_CreateColorTransformer(IWICImagingFactory *iface,
289 IWICColorTransform **ppIColorTransform)
291 FIXME("(%p,%p): stub\n", iface, ppIColorTransform);
292 return E_NOTIMPL;
295 static HRESULT WINAPI ImagingFactory_CreateBitmap(IWICImagingFactory *iface,
296 UINT uiWidth, UINT uiHeight, REFWICPixelFormatGUID pixelFormat,
297 WICBitmapCreateCacheOption option, IWICBitmap **ppIBitmap)
299 FIXME("(%p,%u,%u,%s,%u,%p): stub\n", iface, uiWidth, uiHeight,
300 debugstr_guid(pixelFormat), option, ppIBitmap);
301 return E_NOTIMPL;
304 static HRESULT WINAPI ImagingFactory_CreateBitmapFromSource(IWICImagingFactory *iface,
305 IWICBitmapSource *piBitmapSource, WICBitmapCreateCacheOption option,
306 IWICBitmap **ppIBitmap)
308 FIXME("(%p,%p,%u,%p): stub\n", iface, piBitmapSource, option, ppIBitmap);
309 return E_NOTIMPL;
312 static HRESULT WINAPI ImagingFactory_CreateBitmapFromSourceRect(IWICImagingFactory *iface,
313 IWICBitmapSource *piBitmapSource, UINT x, UINT y, UINT width, UINT height,
314 IWICBitmap **ppIBitmap)
316 FIXME("(%p,%p,%u,%u,%u,%u,%p): stub\n", iface, piBitmapSource, x, y, width,
317 height, ppIBitmap);
318 return E_NOTIMPL;
321 static HRESULT WINAPI ImagingFactory_CreateBitmapFromMemory(IWICImagingFactory *iface,
322 UINT uiWidth, UINT uiHeight, REFWICPixelFormatGUID pixelFormat, UINT cbStride,
323 UINT cbBufferSize, BYTE *pbBuffer, IWICBitmap **ppIBitmap)
325 FIXME("(%p,%u,%u,%s,%u,%u,%p,%p): stub\n", iface, uiWidth, uiHeight,
326 debugstr_guid(pixelFormat), cbStride, cbBufferSize, pbBuffer, ppIBitmap);
327 return E_NOTIMPL;
330 static HRESULT WINAPI ImagingFactory_CreateBitmapFromHBITMAP(IWICImagingFactory *iface,
331 HBITMAP hBitmap, HPALETTE hPalette, WICBitmapAlphaChannelOption options,
332 IWICBitmap **ppIBitmap)
334 FIXME("(%p,%p,%p,%u,%p): stub\n", iface, hBitmap, hPalette, options, ppIBitmap);
335 return E_NOTIMPL;
338 static HRESULT WINAPI ImagingFactory_CreateBitmapFromHICON(IWICImagingFactory *iface,
339 HICON hIcon, IWICBitmap **ppIBitmap)
341 FIXME("(%p,%p,%p): stub\n", iface, hIcon, ppIBitmap);
342 return E_NOTIMPL;
345 static HRESULT WINAPI ImagingFactory_CreateComponentEnumerator(IWICImagingFactory *iface,
346 DWORD componentTypes, DWORD options, IEnumUnknown **ppIEnumUnknown)
348 TRACE("(%p,%u,%u,%p)\n", iface, componentTypes, options, ppIEnumUnknown);
349 return CreateComponentEnumerator(componentTypes, options, ppIEnumUnknown);
352 static HRESULT WINAPI ImagingFactory_CreateFastMetadataEncoderFromDecoder(
353 IWICImagingFactory *iface, IWICBitmapDecoder *pIDecoder,
354 IWICFastMetadataEncoder **ppIFastEncoder)
356 FIXME("(%p,%p,%p): stub\n", iface, pIDecoder, ppIFastEncoder);
357 return E_NOTIMPL;
360 static HRESULT WINAPI ImagingFactory_CreateFastMetadataEncoderFromFrameDecode(
361 IWICImagingFactory *iface, IWICBitmapFrameDecode *pIFrameDecoder,
362 IWICFastMetadataEncoder **ppIFastEncoder)
364 FIXME("(%p,%p,%p): stub\n", iface, pIFrameDecoder, ppIFastEncoder);
365 return E_NOTIMPL;
368 static HRESULT WINAPI ImagingFactory_CreateQueryWriter(IWICImagingFactory *iface,
369 REFGUID guidMetadataFormat, const GUID *pguidVendor,
370 IWICMetadataQueryWriter **ppIQueryWriter)
372 FIXME("(%p,%s,%s,%p): stub\n", iface, debugstr_guid(guidMetadataFormat),
373 debugstr_guid(pguidVendor), ppIQueryWriter);
374 return E_NOTIMPL;
377 static HRESULT WINAPI ImagingFactory_CreateQueryWriterFromReader(IWICImagingFactory *iface,
378 IWICMetadataQueryReader *pIQueryReader, const GUID *pguidVendor,
379 IWICMetadataQueryWriter **ppIQueryWriter)
381 FIXME("(%p,%p,%s,%p): stub\n", iface, pIQueryReader, debugstr_guid(pguidVendor),
382 ppIQueryWriter);
383 return E_NOTIMPL;
386 static const IWICImagingFactoryVtbl ImagingFactory_Vtbl = {
387 ImagingFactory_QueryInterface,
388 ImagingFactory_AddRef,
389 ImagingFactory_Release,
390 ImagingFactory_CreateDecoderFromFilename,
391 ImagingFactory_CreateDecoderFromStream,
392 ImagingFactory_CreateDecoderFromFileHandle,
393 ImagingFactory_CreateComponentInfo,
394 ImagingFactory_CreateDecoder,
395 ImagingFactory_CreateEncoder,
396 ImagingFactory_CreatePalette,
397 ImagingFactory_CreateFormatConverter,
398 ImagingFactory_CreateBitmapScaler,
399 ImagingFactory_CreateBitmapClipper,
400 ImagingFactory_CreateBitmapFlipRotator,
401 ImagingFactory_CreateStream,
402 ImagingFactory_CreateColorContext,
403 ImagingFactory_CreateColorTransformer,
404 ImagingFactory_CreateBitmap,
405 ImagingFactory_CreateBitmapFromSource,
406 ImagingFactory_CreateBitmapFromSourceRect,
407 ImagingFactory_CreateBitmapFromMemory,
408 ImagingFactory_CreateBitmapFromHBITMAP,
409 ImagingFactory_CreateBitmapFromHICON,
410 ImagingFactory_CreateComponentEnumerator,
411 ImagingFactory_CreateFastMetadataEncoderFromDecoder,
412 ImagingFactory_CreateFastMetadataEncoderFromFrameDecode,
413 ImagingFactory_CreateQueryWriter,
414 ImagingFactory_CreateQueryWriterFromReader
417 HRESULT ImagingFactory_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv)
419 ImagingFactory *This;
420 HRESULT ret;
422 TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv);
424 *ppv = NULL;
426 if (pUnkOuter) return CLASS_E_NOAGGREGATION;
428 This = HeapAlloc(GetProcessHeap(), 0, sizeof(ImagingFactory));
429 if (!This) return E_OUTOFMEMORY;
431 This->lpIWICImagingFactoryVtbl = &ImagingFactory_Vtbl;
432 This->ref = 1;
434 ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv);
435 IUnknown_Release((IUnknown*)This);
437 return ret;