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 const IWICImagingFactoryVtbl
*lpIWICImagingFactoryVtbl
;
43 static HRESULT WINAPI
ImagingFactory_QueryInterface(IWICImagingFactory
*iface
, REFIID iid
,
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
))
61 IUnknown_AddRef((IUnknown
*)*ppv
);
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
);
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
);
83 HeapFree(GetProcessHeap(), 0, This
);
88 static HRESULT WINAPI
ImagingFactory_CreateDecoderFromFilename(
89 IWICImagingFactory
*iface
, LPCWSTR wzFilename
, const GUID
*pguidVendor
,
90 DWORD dwDesiredAccess
, WICDecodeOptions metadataOptions
,
91 IWICBitmapDecoder
**ppIDecoder
)
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
);
102 hr
= IWICStream_InitializeFromFilename(stream
, wzFilename
, dwDesiredAccess
);
106 hr
= IWICImagingFactory_CreateDecoderFromStream(iface
, (IStream
*)stream
,
107 pguidVendor
, metadataOptions
, ppIDecoder
);
110 IWICStream_Release(stream
);
116 static HRESULT WINAPI
ImagingFactory_CreateDecoderFromStream(
117 IWICImagingFactory
*iface
, IStream
*pIStream
, const GUID
*pguidVendor
,
118 WICDecodeOptions metadataOptions
, IWICBitmapDecoder
**ppIDecoder
)
121 IEnumUnknown
*enumdecoders
;
122 IUnknown
*unkdecoderinfo
;
123 IWICBitmapDecoderInfo
*decoderinfo
;
124 IWICBitmapDecoder
*decoder
=NULL
;
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
;
140 res
= IEnumUnknown_Next(enumdecoders
, 1, &unkdecoderinfo
, &num_fetched
);
144 res
= IUnknown_QueryInterface(unkdecoderinfo
, &IID_IWICBitmapDecoderInfo
, (void**)&decoderinfo
);
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 */
158 res
= IWICBitmapDecoder_Initialize(decoder
, pIStream
, metadataOptions
);
162 IWICBitmapDecoder_Release(decoder
);
168 IWICBitmapDecoderInfo_Release(decoderinfo
);
171 IUnknown_Release(unkdecoderinfo
);
177 IEnumUnknown_Release(enumdecoders
);
181 *ppIDecoder
= decoder
;
186 if (WARN_ON(wincodecs
))
192 WARN("failed to load from a stream\n");
195 res
= IStream_Seek(pIStream
, seek
, STREAM_SEEK_SET
, NULL
);
197 res
= IStream_Read(pIStream
, data
, 4, &bytesread
);
199 WARN("first %i bytes of stream=%x %x %x %x\n", bytesread
, data
[0], data
[1], data
[2], data
[3]);
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
);
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
);
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
);
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
);
260 static HRESULT WINAPI
ImagingFactory_CreateBitmapClipper(IWICImagingFactory
*iface
,
261 IWICBitmapClipper
**ppIBitmapClipper
)
263 FIXME("(%p,%p): stub\n", iface
, ppIBitmapClipper
);
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
);
288 static HRESULT WINAPI
ImagingFactory_CreateColorTransformer(IWICImagingFactory
*iface
,
289 IWICColorTransform
**ppIColorTransform
)
291 FIXME("(%p,%p): stub\n", iface
, ppIColorTransform
);
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
);
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
);
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
,
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
);
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
);
338 static HRESULT WINAPI
ImagingFactory_CreateBitmapFromHICON(IWICImagingFactory
*iface
,
339 HICON hIcon
, IWICBitmap
**ppIBitmap
)
341 FIXME("(%p,%p,%p): stub\n", iface
, hIcon
, ppIBitmap
);
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
);
360 static HRESULT WINAPI
ImagingFactory_CreateFastMetadataEncoderFromFrameDecode(
361 IWICImagingFactory
*iface
, IWICBitmapFrameDecode
*pIFrameDecoder
,
362 IWICFastMetadataEncoder
**ppIFastEncoder
)
364 FIXME("(%p,%p,%p): stub\n", iface
, pIFrameDecoder
, ppIFastEncoder
);
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
);
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
),
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
;
422 TRACE("(%p,%s,%p)\n", pUnkOuter
, debugstr_guid(iid
), ppv
);
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
;
434 ret
= IUnknown_QueryInterface((IUnknown
*)This
, iid
, ppv
);
435 IUnknown_Release((IUnknown
*)This
);