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
31 #include "wincodecs_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
38 const IWICImagingFactoryVtbl *lpIWICImagingFactoryVtbl;
42 static HRESULT WINAPI ImagingFactory_QueryInterface(IWICImagingFactory *iface, REFIID iid,
45 ImagingFactory *This = (ImagingFactory*)iface;
46 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
48 if (!ppv) return E_INVALIDARG;
50 if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IWICImagingFactory, iid))
60 IUnknown_AddRef((IUnknown*)*ppv);
64 static ULONG WINAPI ImagingFactory_AddRef(IWICImagingFactory *iface)
66 ImagingFactory *This = (ImagingFactory*)iface;
67 ULONG ref = InterlockedIncrement(&This->ref);
69 TRACE("(%p) refcount=%u\n", iface, ref);
74 static ULONG WINAPI ImagingFactory_Release(IWICImagingFactory *iface)
76 ImagingFactory *This = (ImagingFactory*)iface;
77 ULONG ref = InterlockedDecrement(&This->ref);
79 TRACE("(%p) refcount=%u\n", iface, ref);
82 HeapFree(GetProcessHeap(), 0, This);
87 static HRESULT WINAPI ImagingFactory_CreateDecoderFromFilename(
88 IWICImagingFactory *iface, LPCWSTR wzFilename, const GUID *pguidVendor,
89 DWORD dwDesiredAccess, WICDecodeOptions metadataOptions,
90 IWICBitmapDecoder **ppIDecoder)
92 FIXME("(%p,%s,%s,%u,%u,%p): stub\n", iface, debugstr_w(wzFilename),
93 debugstr_guid(pguidVendor), dwDesiredAccess, metadataOptions, ppIDecoder);
97 static HRESULT WINAPI ImagingFactory_CreateDecoderFromStream(
98 IWICImagingFactory *iface, IStream *pIStream, const GUID *pguidVendor,
99 WICDecodeOptions metadataOptions, IWICBitmapDecoder **ppIDecoder)
102 IEnumUnknown *enumdecoders;
103 IUnknown *unkdecoderinfo;
104 IWICBitmapDecoderInfo *decoderinfo;
105 IWICBitmapDecoder *decoder=NULL;
110 TRACE("(%p,%p,%s,%u,%p)\n", iface, pIStream, debugstr_guid(pguidVendor),
111 metadataOptions, ppIDecoder);
113 if (pguidVendor && !fixme++)
114 FIXME("ignoring vendor GUID\n");
116 res = CreateComponentEnumerator(WICDecoder, WICComponentEnumerateDefault, &enumdecoders);
117 if (FAILED(res)) return res;
121 res = IEnumUnknown_Next(enumdecoders, 1, &unkdecoderinfo, &num_fetched);
125 res = IUnknown_QueryInterface(unkdecoderinfo, &IID_IWICBitmapDecoderInfo, (void**)&decoderinfo);
129 res = IWICBitmapDecoderInfo_MatchesPattern(decoderinfo, pIStream, &matches);
131 if (SUCCEEDED(res) && matches)
133 res = IWICBitmapDecoderInfo_CreateInstance(decoderinfo, &decoder);
135 /* FIXME: should use QueryCapability to choose a decoder */
139 res = IWICBitmapDecoder_Initialize(decoder, pIStream, metadataOptions);
143 IWICBitmapDecoder_Release(decoder);
149 IWICBitmapDecoderInfo_Release(decoderinfo);
152 IUnknown_Release(unkdecoderinfo);
158 IEnumUnknown_Release(enumdecoders);
162 *ppIDecoder = decoder;
167 if (WARN_ON(wincodecs))
173 WARN("failed to load from a stream\n");
176 res = IStream_Seek(pIStream, seek, STREAM_SEEK_SET, NULL);
178 res = IStream_Read(pIStream, data, 4, &bytesread);
180 WARN("first %i bytes of stream=%x %x %x %x\n", bytesread, data[0], data[1], data[2], data[3]);
183 return WINCODEC_ERR_COMPONENTNOTFOUND;
187 static HRESULT WINAPI ImagingFactory_CreateDecoderFromFileHandle(
188 IWICImagingFactory *iface, ULONG_PTR hFile, const GUID *pguidVendor,
189 WICDecodeOptions metadataOptions, IWICBitmapDecoder **ppIDecoder)
191 FIXME("(%p,%lx,%s,%u,%p): stub\n", iface, hFile, debugstr_guid(pguidVendor),
192 metadataOptions, ppIDecoder);
196 static HRESULT WINAPI ImagingFactory_CreateComponentInfo(IWICImagingFactory *iface,
197 REFCLSID clsidComponent, IWICComponentInfo **ppIInfo)
199 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(clsidComponent), ppIInfo);
200 return CreateComponentInfo(clsidComponent, ppIInfo);
203 static HRESULT WINAPI ImagingFactory_CreateDecoder(IWICImagingFactory *iface,
204 REFGUID guidContainerFormat, const GUID *pguidVendor,
205 IWICBitmapDecoder **ppIDecoder)
207 FIXME("(%p,%s,%s,%p): stub\n", iface, debugstr_guid(guidContainerFormat),
208 debugstr_guid(pguidVendor), ppIDecoder);
212 static HRESULT WINAPI ImagingFactory_CreateEncoder(IWICImagingFactory *iface,
213 REFGUID guidContainerFormat, const GUID *pguidVendor,
214 IWICBitmapEncoder **ppIEncoder)
216 FIXME("(%p,%s,%s,%p): stub\n", iface, debugstr_guid(guidContainerFormat),
217 debugstr_guid(pguidVendor), ppIEncoder);
221 static HRESULT WINAPI ImagingFactory_CreatePalette(IWICImagingFactory *iface,
222 IWICPalette **ppIPalette)
224 TRACE("(%p,%p)\n", iface, ppIPalette);
225 return PaletteImpl_Create(ppIPalette);
228 static HRESULT WINAPI ImagingFactory_CreateFormatConverter(IWICImagingFactory *iface,
229 IWICFormatConverter **ppIFormatConverter)
231 FIXME("(%p,%p): stub\n", iface, ppIFormatConverter);
235 static HRESULT WINAPI ImagingFactory_CreateBitmapScaler(IWICImagingFactory *iface,
236 IWICBitmapScaler **ppIBitmapScaler)
238 FIXME("(%p,%p): stub\n", iface, ppIBitmapScaler);
242 static HRESULT WINAPI ImagingFactory_CreateBitmapClipper(IWICImagingFactory *iface,
243 IWICBitmapClipper **ppIBitmapClipper)
245 FIXME("(%p,%p): stub\n", iface, ppIBitmapClipper);
249 static HRESULT WINAPI ImagingFactory_CreateBitmapFlipRotator(IWICImagingFactory *iface,
250 IWICBitmapFlipRotator **ppIBitmapFlipRotator)
252 FIXME("(%p,%p): stub\n", iface, ppIBitmapFlipRotator);
256 static HRESULT WINAPI ImagingFactory_CreateStream(IWICImagingFactory *iface,
257 IWICStream **ppIWICStream)
259 TRACE("(%p,%p)\n", iface, ppIWICStream);
260 return StreamImpl_Create(ppIWICStream);
263 static HRESULT WINAPI ImagingFactory_CreateColorContext(IWICImagingFactory *iface,
264 IWICColorContext **ppIColorContext)
266 FIXME("(%p,%p): stub\n", iface, ppIColorContext);
270 static HRESULT WINAPI ImagingFactory_CreateColorTransformer(IWICImagingFactory *iface,
271 IWICColorTransform **ppIColorTransform)
273 FIXME("(%p,%p): stub\n", iface, ppIColorTransform);
277 static HRESULT WINAPI ImagingFactory_CreateBitmap(IWICImagingFactory *iface,
278 UINT uiWidth, UINT uiHeight, REFWICPixelFormatGUID pixelFormat,
279 WICBitmapCreateCacheOption option, IWICBitmap **ppIBitmap)
281 FIXME("(%p,%u,%u,%s,%u,%p): stub\n", iface, uiWidth, uiHeight,
282 debugstr_guid(pixelFormat), option, ppIBitmap);
286 static HRESULT WINAPI ImagingFactory_CreateBitmapFromSource(IWICImagingFactory *iface,
287 IWICBitmapSource *piBitmapSource, WICBitmapCreateCacheOption option,
288 IWICBitmap **ppIBitmap)
290 FIXME("(%p,%p,%u,%p): stub\n", iface, piBitmapSource, option, ppIBitmap);
294 static HRESULT WINAPI ImagingFactory_CreateBitmapFromSourceRect(IWICImagingFactory *iface,
295 IWICBitmapSource *piBitmapSource, UINT x, UINT y, UINT width, UINT height,
296 IWICBitmap **ppIBitmap)
298 FIXME("(%p,%p,%u,%u,%u,%u,%p): stub\n", iface, piBitmapSource, x, y, width,
303 static HRESULT WINAPI ImagingFactory_CreateBitmapFromMemory(IWICImagingFactory *iface,
304 UINT uiWidth, UINT uiHeight, REFWICPixelFormatGUID pixelFormat, UINT cbStride,
305 UINT cbBufferSize, BYTE *pbBuffer, IWICBitmap **ppIBitmap)
307 FIXME("(%p,%u,%u,%s,%u,%u,%p,%p): stub\n", iface, uiWidth, uiHeight,
308 debugstr_guid(pixelFormat), cbStride, cbBufferSize, pbBuffer, ppIBitmap);
312 static HRESULT WINAPI ImagingFactory_CreateBitmapFromHBITMAP(IWICImagingFactory *iface,
313 HBITMAP hBitmap, HPALETTE hPalette, WICBitmapAlphaChannelOption options,
314 IWICBitmap **ppIBitmap)
316 FIXME("(%p,%p,%p,%u,%p): stub\n", iface, hBitmap, hPalette, options, ppIBitmap);
320 static HRESULT WINAPI ImagingFactory_CreateBitmapFromHICON(IWICImagingFactory *iface,
321 HICON hIcon, IWICBitmap **ppIBitmap)
323 FIXME("(%p,%p,%p): stub\n", iface, hIcon, ppIBitmap);
327 static HRESULT WINAPI ImagingFactory_CreateComponentEnumerator(IWICImagingFactory *iface,
328 DWORD componentTypes, DWORD options, IEnumUnknown **ppIEnumUnknown)
330 TRACE("(%p,%u,%u,%p)\n", iface, componentTypes, options, ppIEnumUnknown);
331 return CreateComponentEnumerator(componentTypes, options, ppIEnumUnknown);
334 static HRESULT WINAPI ImagingFactory_CreateFastMetadataEncoderFromDecoder(
335 IWICImagingFactory *iface, IWICBitmapDecoder *pIDecoder,
336 IWICFastMetadataEncoder **ppIFastEncoder)
338 FIXME("(%p,%p,%p): stub\n", iface, pIDecoder, ppIFastEncoder);
342 static HRESULT WINAPI ImagingFactory_CreateFastMetadataEncoderFromFrameDecode(
343 IWICImagingFactory *iface, IWICBitmapFrameDecode *pIFrameDecoder,
344 IWICFastMetadataEncoder **ppIFastEncoder)
346 FIXME("(%p,%p,%p): stub\n", iface, pIFrameDecoder, ppIFastEncoder);
350 static HRESULT WINAPI ImagingFactory_CreateQueryWriter(IWICImagingFactory *iface,
351 REFGUID guidMetadataFormat, const GUID *pguidVendor,
352 IWICMetadataQueryWriter **ppIQueryWriter)
354 FIXME("(%p,%s,%s,%p): stub\n", iface, debugstr_guid(guidMetadataFormat),
355 debugstr_guid(pguidVendor), ppIQueryWriter);
359 static HRESULT WINAPI ImagingFactory_CreateQueryWriterFromReader(IWICImagingFactory *iface,
360 IWICMetadataQueryReader *pIQueryReader, const GUID *pguidVendor,
361 IWICMetadataQueryWriter **ppIQueryWriter)
363 FIXME("(%p,%p,%s,%p): stub\n", iface, pIQueryReader, debugstr_guid(pguidVendor),
368 static const IWICImagingFactoryVtbl ImagingFactory_Vtbl = {
369 ImagingFactory_QueryInterface,
370 ImagingFactory_AddRef,
371 ImagingFactory_Release,
372 ImagingFactory_CreateDecoderFromFilename,
373 ImagingFactory_CreateDecoderFromStream,
374 ImagingFactory_CreateDecoderFromFileHandle,
375 ImagingFactory_CreateComponentInfo,
376 ImagingFactory_CreateDecoder,
377 ImagingFactory_CreateEncoder,
378 ImagingFactory_CreatePalette,
379 ImagingFactory_CreateFormatConverter,
380 ImagingFactory_CreateBitmapScaler,
381 ImagingFactory_CreateBitmapClipper,
382 ImagingFactory_CreateBitmapFlipRotator,
383 ImagingFactory_CreateStream,
384 ImagingFactory_CreateColorContext,
385 ImagingFactory_CreateColorTransformer,
386 ImagingFactory_CreateBitmap,
387 ImagingFactory_CreateBitmapFromSource,
388 ImagingFactory_CreateBitmapFromSourceRect,
389 ImagingFactory_CreateBitmapFromMemory,
390 ImagingFactory_CreateBitmapFromHBITMAP,
391 ImagingFactory_CreateBitmapFromHICON,
392 ImagingFactory_CreateComponentEnumerator,
393 ImagingFactory_CreateFastMetadataEncoderFromDecoder,
394 ImagingFactory_CreateFastMetadataEncoderFromFrameDecode,
395 ImagingFactory_CreateQueryWriter,
396 ImagingFactory_CreateQueryWriterFromReader
399 HRESULT ImagingFactory_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv)
401 ImagingFactory *This;
404 TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv);
408 if (pUnkOuter) return CLASS_E_NOAGGREGATION;
410 This = HeapAlloc(GetProcessHeap(), 0, sizeof(ImagingFactory));
411 if (!This) return E_OUTOFMEMORY;
413 This->lpIWICImagingFactoryVtbl = &ImagingFactory_Vtbl;
416 ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv);
417 IUnknown_Release((IUnknown*)This);