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
32 #include "wincodecs_private.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
39 IWICImagingFactory IWICImagingFactory_iface;
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,
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))
66 IUnknown_AddRef((IUnknown*)*ppv);
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);
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);
88 HeapFree(GetProcessHeap(), 0, This);
93 static HRESULT WINAPI ImagingFactory_CreateDecoderFromFilename(
94 IWICImagingFactory *iface, LPCWSTR wzFilename, const GUID *pguidVendor,
95 DWORD dwDesiredAccess, WICDecodeOptions metadataOptions,
96 IWICBitmapDecoder **ppIDecoder)
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);
107 hr = IWICStream_InitializeFromFilename(stream, wzFilename, dwDesiredAccess);
111 hr = IWICImagingFactory_CreateDecoderFromStream(iface, (IStream*)stream,
112 pguidVendor, metadataOptions, ppIDecoder);
115 IWICStream_Release(stream);
121 static HRESULT WINAPI ImagingFactory_CreateDecoderFromStream(
122 IWICImagingFactory *iface, IStream *pIStream, const GUID *pguidVendor,
123 WICDecodeOptions metadataOptions, IWICBitmapDecoder **ppIDecoder)
126 IEnumUnknown *enumdecoders;
127 IUnknown *unkdecoderinfo;
128 IWICBitmapDecoderInfo *decoderinfo;
129 IWICBitmapDecoder *decoder=NULL;
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;
145 res = IEnumUnknown_Next(enumdecoders, 1, &unkdecoderinfo, &num_fetched);
149 res = IUnknown_QueryInterface(unkdecoderinfo, &IID_IWICBitmapDecoderInfo, (void**)&decoderinfo);
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 */
163 res = IWICBitmapDecoder_Initialize(decoder, pIStream, metadataOptions);
167 IWICBitmapDecoder_Release(decoder);
173 IWICBitmapDecoderInfo_Release(decoderinfo);
176 IUnknown_Release(unkdecoderinfo);
182 IEnumUnknown_Release(enumdecoders);
186 *ppIDecoder = decoder;
191 if (WARN_ON(wincodecs))
197 WARN("failed to load from a stream\n");
200 res = IStream_Seek(pIStream, seek, STREAM_SEEK_SET, NULL);
202 res = IStream_Read(pIStream, data, 4, &bytesread);
204 WARN("first %i bytes of stream=%x %x %x %x\n", bytesread, data[0], data[1], data[2], data[3]);
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);
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);
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);
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);
265 static HRESULT WINAPI ImagingFactory_CreateBitmapClipper(IWICImagingFactory *iface,
266 IWICBitmapClipper **ppIBitmapClipper)
268 FIXME("(%p,%p): stub\n", iface, ppIBitmapClipper);
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);
293 static HRESULT WINAPI ImagingFactory_CreateColorTransformer(IWICImagingFactory *iface,
294 IWICColorTransform **ppIColorTransform)
296 FIXME("(%p,%p): stub\n", iface, ppIColorTransform);
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);
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);
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,
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);
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);
343 static HRESULT WINAPI ImagingFactory_CreateBitmapFromHICON(IWICImagingFactory *iface,
344 HICON hIcon, IWICBitmap **ppIBitmap)
346 FIXME("(%p,%p,%p): stub\n", iface, hIcon, ppIBitmap);
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);
365 static HRESULT WINAPI ImagingFactory_CreateFastMetadataEncoderFromFrameDecode(
366 IWICImagingFactory *iface, IWICBitmapFrameDecode *pIFrameDecoder,
367 IWICFastMetadataEncoder **ppIFastEncoder)
369 FIXME("(%p,%p,%p): stub\n", iface, pIFrameDecoder, ppIFastEncoder);
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);
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),
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;
427 TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv);
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;
439 ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv);
440 IUnknown_Release((IUnknown*)This);