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 "wincodecsdk.h"
33 #include "wincodecs_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs
);
40 IWICComponentFactory IWICComponentFactory_iface
;
44 static inline ComponentFactory
*impl_from_IWICComponentFactory(IWICComponentFactory
*iface
)
46 return CONTAINING_RECORD(iface
, ComponentFactory
, IWICComponentFactory_iface
);
49 static HRESULT WINAPI
ComponentFactory_QueryInterface(IWICComponentFactory
*iface
, REFIID iid
,
52 ComponentFactory
*This
= impl_from_IWICComponentFactory(iface
);
53 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
55 if (!ppv
) return E_INVALIDARG
;
57 if (IsEqualIID(&IID_IUnknown
, iid
) ||
58 IsEqualIID(&IID_IWICImagingFactory
, iid
) ||
59 IsEqualIID(&IID_IWICComponentFactory
, iid
))
69 IUnknown_AddRef((IUnknown
*)*ppv
);
73 static ULONG WINAPI
ComponentFactory_AddRef(IWICComponentFactory
*iface
)
75 ComponentFactory
*This
= impl_from_IWICComponentFactory(iface
);
76 ULONG ref
= InterlockedIncrement(&This
->ref
);
78 TRACE("(%p) refcount=%u\n", iface
, ref
);
83 static ULONG WINAPI
ComponentFactory_Release(IWICComponentFactory
*iface
)
85 ComponentFactory
*This
= impl_from_IWICComponentFactory(iface
);
86 ULONG ref
= InterlockedDecrement(&This
->ref
);
88 TRACE("(%p) refcount=%u\n", iface
, ref
);
91 HeapFree(GetProcessHeap(), 0, This
);
96 static HRESULT WINAPI
ComponentFactory_CreateDecoderFromFilename(
97 IWICComponentFactory
*iface
, LPCWSTR wzFilename
, const GUID
*pguidVendor
,
98 DWORD dwDesiredAccess
, WICDecodeOptions metadataOptions
,
99 IWICBitmapDecoder
**ppIDecoder
)
104 TRACE("(%p,%s,%s,%u,%u,%p)\n", iface
, debugstr_w(wzFilename
),
105 debugstr_guid(pguidVendor
), dwDesiredAccess
, metadataOptions
, ppIDecoder
);
107 hr
= StreamImpl_Create(&stream
);
110 hr
= IWICStream_InitializeFromFilename(stream
, wzFilename
, dwDesiredAccess
);
114 hr
= IWICComponentFactory_CreateDecoderFromStream(iface
, (IStream
*)stream
,
115 pguidVendor
, metadataOptions
, ppIDecoder
);
118 IWICStream_Release(stream
);
124 static HRESULT WINAPI
ComponentFactory_CreateDecoderFromStream(
125 IWICComponentFactory
*iface
, IStream
*pIStream
, const GUID
*pguidVendor
,
126 WICDecodeOptions metadataOptions
, IWICBitmapDecoder
**ppIDecoder
)
128 IEnumUnknown
*enumdecoders
;
129 IUnknown
*unkdecoderinfo
;
130 IWICBitmapDecoderInfo
*decoderinfo
;
131 IWICBitmapDecoder
*decoder
= NULL
, *preferred_decoder
= NULL
;
137 TRACE("(%p,%p,%s,%u,%p)\n", iface
, pIStream
, debugstr_guid(pguidVendor
),
138 metadataOptions
, ppIDecoder
);
140 res
= CreateComponentEnumerator(WICDecoder
, WICComponentEnumerateDefault
, &enumdecoders
);
141 if (FAILED(res
)) return res
;
143 while (!preferred_decoder
)
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 IWICBitmapDecoder
*new_decoder
;
159 res
= IWICBitmapDecoderInfo_CreateInstance(decoderinfo
, &new_decoder
);
161 /* FIXME: should use QueryCapability to choose a decoder */
165 res
= IWICBitmapDecoder_Initialize(new_decoder
, pIStream
, metadataOptions
);
171 res
= IWICBitmapDecoderInfo_GetVendorGUID(decoderinfo
, &vendor
);
172 if (SUCCEEDED(res
) && IsEqualIID(&vendor
, pguidVendor
))
174 preferred_decoder
= new_decoder
;
179 if (new_decoder
&& !decoder
)
181 decoder
= new_decoder
;
186 if (new_decoder
) IWICBitmapDecoder_Release(new_decoder
);
190 IWICBitmapDecoderInfo_Release(decoderinfo
);
193 IUnknown_Release(unkdecoderinfo
);
199 IEnumUnknown_Release(enumdecoders
);
201 if (preferred_decoder
)
203 *ppIDecoder
= preferred_decoder
;
204 if (decoder
) IWICBitmapDecoder_Release(decoder
);
210 *ppIDecoder
= decoder
;
215 if (WARN_ON(wincodecs
))
221 WARN("failed to load from a stream\n");
224 res
= IStream_Seek(pIStream
, seek
, STREAM_SEEK_SET
, NULL
);
226 res
= IStream_Read(pIStream
, data
, 4, &bytesread
);
228 WARN("first %i bytes of stream=%x %x %x %x\n", bytesread
, data
[0], data
[1], data
[2], data
[3]);
231 return WINCODEC_ERR_COMPONENTNOTFOUND
;
235 static HRESULT WINAPI
ComponentFactory_CreateDecoderFromFileHandle(
236 IWICComponentFactory
*iface
, ULONG_PTR hFile
, const GUID
*pguidVendor
,
237 WICDecodeOptions metadataOptions
, IWICBitmapDecoder
**ppIDecoder
)
239 FIXME("(%p,%lx,%s,%u,%p): stub\n", iface
, hFile
, debugstr_guid(pguidVendor
),
240 metadataOptions
, ppIDecoder
);
244 static HRESULT WINAPI
ComponentFactory_CreateComponentInfo(IWICComponentFactory
*iface
,
245 REFCLSID clsidComponent
, IWICComponentInfo
**ppIInfo
)
247 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(clsidComponent
), ppIInfo
);
248 return CreateComponentInfo(clsidComponent
, ppIInfo
);
251 static HRESULT WINAPI
ComponentFactory_CreateDecoder(IWICComponentFactory
*iface
,
252 REFGUID guidContainerFormat
, const GUID
*pguidVendor
,
253 IWICBitmapDecoder
**ppIDecoder
)
255 IEnumUnknown
*enumdecoders
;
256 IUnknown
*unkdecoderinfo
;
257 IWICBitmapDecoderInfo
*decoderinfo
;
258 IWICBitmapDecoder
*decoder
= NULL
, *preferred_decoder
= NULL
;
263 TRACE("(%p,%s,%s,%p)\n", iface
, debugstr_guid(guidContainerFormat
),
264 debugstr_guid(pguidVendor
), ppIDecoder
);
266 if (!guidContainerFormat
|| !ppIDecoder
) return E_INVALIDARG
;
268 res
= CreateComponentEnumerator(WICDecoder
, WICComponentEnumerateDefault
, &enumdecoders
);
269 if (FAILED(res
)) return res
;
271 while (!preferred_decoder
)
273 res
= IEnumUnknown_Next(enumdecoders
, 1, &unkdecoderinfo
, &num_fetched
);
274 if (res
!= S_OK
) break;
276 res
= IUnknown_QueryInterface(unkdecoderinfo
, &IID_IWICBitmapDecoderInfo
, (void **)&decoderinfo
);
281 res
= IWICBitmapDecoderInfo_GetContainerFormat(decoderinfo
, &container_guid
);
282 if (SUCCEEDED(res
) && IsEqualIID(&container_guid
, guidContainerFormat
))
284 IWICBitmapDecoder
*new_decoder
;
286 res
= IWICBitmapDecoderInfo_CreateInstance(decoderinfo
, &new_decoder
);
291 res
= IWICBitmapDecoderInfo_GetVendorGUID(decoderinfo
, &vendor
);
292 if (SUCCEEDED(res
) && IsEqualIID(&vendor
, pguidVendor
))
294 preferred_decoder
= new_decoder
;
299 if (new_decoder
&& !decoder
)
301 decoder
= new_decoder
;
305 if (new_decoder
) IWICBitmapDecoder_Release(new_decoder
);
309 IWICBitmapDecoderInfo_Release(decoderinfo
);
312 IUnknown_Release(unkdecoderinfo
);
315 IEnumUnknown_Release(enumdecoders
);
317 if (preferred_decoder
)
319 *ppIDecoder
= preferred_decoder
;
320 if (decoder
) IWICBitmapDecoder_Release(decoder
);
326 *ppIDecoder
= decoder
;
331 return WINCODEC_ERR_COMPONENTNOTFOUND
;
334 static HRESULT WINAPI
ComponentFactory_CreateEncoder(IWICComponentFactory
*iface
,
335 REFGUID guidContainerFormat
, const GUID
*pguidVendor
,
336 IWICBitmapEncoder
**ppIEncoder
)
338 FIXME("(%p,%s,%s,%p): stub\n", iface
, debugstr_guid(guidContainerFormat
),
339 debugstr_guid(pguidVendor
), ppIEncoder
);
343 static HRESULT WINAPI
ComponentFactory_CreatePalette(IWICComponentFactory
*iface
,
344 IWICPalette
**ppIPalette
)
346 TRACE("(%p,%p)\n", iface
, ppIPalette
);
347 return PaletteImpl_Create(ppIPalette
);
350 static HRESULT WINAPI
ComponentFactory_CreateFormatConverter(IWICComponentFactory
*iface
,
351 IWICFormatConverter
**ppIFormatConverter
)
353 return FormatConverter_CreateInstance(NULL
, &IID_IWICFormatConverter
, (void**)ppIFormatConverter
);
356 static HRESULT WINAPI
ComponentFactory_CreateBitmapScaler(IWICComponentFactory
*iface
,
357 IWICBitmapScaler
**ppIBitmapScaler
)
359 FIXME("(%p,%p): stub\n", iface
, ppIBitmapScaler
);
363 static HRESULT WINAPI
ComponentFactory_CreateBitmapClipper(IWICComponentFactory
*iface
,
364 IWICBitmapClipper
**ppIBitmapClipper
)
366 FIXME("(%p,%p): stub\n", iface
, ppIBitmapClipper
);
370 static HRESULT WINAPI
ComponentFactory_CreateBitmapFlipRotator(IWICComponentFactory
*iface
,
371 IWICBitmapFlipRotator
**ppIBitmapFlipRotator
)
373 TRACE("(%p,%p)\n", iface
, ppIBitmapFlipRotator
);
374 return FlipRotator_Create(ppIBitmapFlipRotator
);
377 static HRESULT WINAPI
ComponentFactory_CreateStream(IWICComponentFactory
*iface
,
378 IWICStream
**ppIWICStream
)
380 TRACE("(%p,%p)\n", iface
, ppIWICStream
);
381 return StreamImpl_Create(ppIWICStream
);
384 static HRESULT WINAPI
ComponentFactory_CreateColorContext(IWICComponentFactory
*iface
,
385 IWICColorContext
**ppIColorContext
)
387 FIXME("(%p,%p): stub\n", iface
, ppIColorContext
);
391 static HRESULT WINAPI
ComponentFactory_CreateColorTransformer(IWICComponentFactory
*iface
,
392 IWICColorTransform
**ppIColorTransform
)
394 FIXME("(%p,%p): stub\n", iface
, ppIColorTransform
);
398 static HRESULT WINAPI
ComponentFactory_CreateBitmap(IWICComponentFactory
*iface
,
399 UINT uiWidth
, UINT uiHeight
, REFWICPixelFormatGUID pixelFormat
,
400 WICBitmapCreateCacheOption option
, IWICBitmap
**ppIBitmap
)
402 FIXME("(%p,%u,%u,%s,%u,%p): stub\n", iface
, uiWidth
, uiHeight
,
403 debugstr_guid(pixelFormat
), option
, ppIBitmap
);
407 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromSource(IWICComponentFactory
*iface
,
408 IWICBitmapSource
*piBitmapSource
, WICBitmapCreateCacheOption option
,
409 IWICBitmap
**ppIBitmap
)
411 FIXME("(%p,%p,%u,%p): stub\n", iface
, piBitmapSource
, option
, ppIBitmap
);
415 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromSourceRect(IWICComponentFactory
*iface
,
416 IWICBitmapSource
*piBitmapSource
, UINT x
, UINT y
, UINT width
, UINT height
,
417 IWICBitmap
**ppIBitmap
)
419 FIXME("(%p,%p,%u,%u,%u,%u,%p): stub\n", iface
, piBitmapSource
, x
, y
, width
,
424 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromMemory(IWICComponentFactory
*iface
,
425 UINT uiWidth
, UINT uiHeight
, REFWICPixelFormatGUID pixelFormat
, UINT cbStride
,
426 UINT cbBufferSize
, BYTE
*pbBuffer
, IWICBitmap
**ppIBitmap
)
428 FIXME("(%p,%u,%u,%s,%u,%u,%p,%p): stub\n", iface
, uiWidth
, uiHeight
,
429 debugstr_guid(pixelFormat
), cbStride
, cbBufferSize
, pbBuffer
, ppIBitmap
);
433 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromHBITMAP(IWICComponentFactory
*iface
,
434 HBITMAP hBitmap
, HPALETTE hPalette
, WICBitmapAlphaChannelOption options
,
435 IWICBitmap
**ppIBitmap
)
437 FIXME("(%p,%p,%p,%u,%p): stub\n", iface
, hBitmap
, hPalette
, options
, ppIBitmap
);
441 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromHICON(IWICComponentFactory
*iface
,
442 HICON hIcon
, IWICBitmap
**ppIBitmap
)
444 FIXME("(%p,%p,%p): stub\n", iface
, hIcon
, ppIBitmap
);
448 static HRESULT WINAPI
ComponentFactory_CreateComponentEnumerator(IWICComponentFactory
*iface
,
449 DWORD componentTypes
, DWORD options
, IEnumUnknown
**ppIEnumUnknown
)
451 TRACE("(%p,%u,%u,%p)\n", iface
, componentTypes
, options
, ppIEnumUnknown
);
452 return CreateComponentEnumerator(componentTypes
, options
, ppIEnumUnknown
);
455 static HRESULT WINAPI
ComponentFactory_CreateFastMetadataEncoderFromDecoder(
456 IWICComponentFactory
*iface
, IWICBitmapDecoder
*pIDecoder
,
457 IWICFastMetadataEncoder
**ppIFastEncoder
)
459 FIXME("(%p,%p,%p): stub\n", iface
, pIDecoder
, ppIFastEncoder
);
463 static HRESULT WINAPI
ComponentFactory_CreateFastMetadataEncoderFromFrameDecode(
464 IWICComponentFactory
*iface
, IWICBitmapFrameDecode
*pIFrameDecoder
,
465 IWICFastMetadataEncoder
**ppIFastEncoder
)
467 FIXME("(%p,%p,%p): stub\n", iface
, pIFrameDecoder
, ppIFastEncoder
);
471 static HRESULT WINAPI
ComponentFactory_CreateQueryWriter(IWICComponentFactory
*iface
,
472 REFGUID guidMetadataFormat
, const GUID
*pguidVendor
,
473 IWICMetadataQueryWriter
**ppIQueryWriter
)
475 FIXME("(%p,%s,%s,%p): stub\n", iface
, debugstr_guid(guidMetadataFormat
),
476 debugstr_guid(pguidVendor
), ppIQueryWriter
);
480 static HRESULT WINAPI
ComponentFactory_CreateQueryWriterFromReader(IWICComponentFactory
*iface
,
481 IWICMetadataQueryReader
*pIQueryReader
, const GUID
*pguidVendor
,
482 IWICMetadataQueryWriter
**ppIQueryWriter
)
484 FIXME("(%p,%p,%s,%p): stub\n", iface
, pIQueryReader
, debugstr_guid(pguidVendor
),
489 static HRESULT WINAPI
ComponentFactory_CreateMetadataReader(IWICComponentFactory
*iface
,
490 REFGUID format
, const GUID
*vendor
, DWORD options
, IStream
*stream
, IWICMetadataReader
**reader
)
492 FIXME("%p,%s,%s,%x,%p,%p: stub\n", iface
, debugstr_guid(format
), debugstr_guid(vendor
),
493 options
, stream
, reader
);
497 static HRESULT WINAPI
ComponentFactory_CreateMetadataReaderFromContainer(IWICComponentFactory
*iface
,
498 REFGUID format
, const GUID
*vendor
, DWORD options
, IStream
*stream
, IWICMetadataReader
**reader
)
500 FIXME("%p,%s,%s,%x,%p,%p: stub\n", iface
, debugstr_guid(format
), debugstr_guid(vendor
),
501 options
, stream
, reader
);
505 static HRESULT WINAPI
ComponentFactory_CreateMetadataWriter(IWICComponentFactory
*iface
,
506 REFGUID format
, const GUID
*vendor
, DWORD options
, IWICMetadataWriter
**writer
)
508 FIXME("%p,%s,%s,%x,%p: stub\n", iface
, debugstr_guid(format
), debugstr_guid(vendor
), options
, writer
);
512 static HRESULT WINAPI
ComponentFactory_CreateMetadataWriterFromReader(IWICComponentFactory
*iface
,
513 IWICMetadataReader
*reader
, const GUID
*vendor
, IWICMetadataWriter
**writer
)
515 FIXME("%p,%p,%s,%p: stub\n", iface
, reader
, debugstr_guid(vendor
), writer
);
519 static HRESULT WINAPI
ComponentFactory_CreateQueryReaderFromBlockReader(IWICComponentFactory
*iface
,
520 IWICMetadataBlockReader
*block_reader
, IWICMetadataQueryReader
**query_reader
)
522 FIXME("%p,%p,%p: stub\n", iface
, block_reader
, query_reader
);
526 static HRESULT WINAPI
ComponentFactory_CreateQueryWriterFromBlockWriter(IWICComponentFactory
*iface
,
527 IWICMetadataBlockWriter
*block_writer
, IWICMetadataQueryWriter
**query_writer
)
529 FIXME("%p,%p,%p: stub\n", iface
, block_writer
, query_writer
);
533 static HRESULT WINAPI
ComponentFactory_CreateEncoderPropertyBag(IWICComponentFactory
*iface
,
534 PROPBAG2
*options
, UINT count
, IPropertyBag2
**property
)
536 FIXME("%p,%p,%u,%p: stub\n", iface
, options
, count
, property
);
540 static const IWICComponentFactoryVtbl ComponentFactory_Vtbl
= {
541 ComponentFactory_QueryInterface
,
542 ComponentFactory_AddRef
,
543 ComponentFactory_Release
,
544 ComponentFactory_CreateDecoderFromFilename
,
545 ComponentFactory_CreateDecoderFromStream
,
546 ComponentFactory_CreateDecoderFromFileHandle
,
547 ComponentFactory_CreateComponentInfo
,
548 ComponentFactory_CreateDecoder
,
549 ComponentFactory_CreateEncoder
,
550 ComponentFactory_CreatePalette
,
551 ComponentFactory_CreateFormatConverter
,
552 ComponentFactory_CreateBitmapScaler
,
553 ComponentFactory_CreateBitmapClipper
,
554 ComponentFactory_CreateBitmapFlipRotator
,
555 ComponentFactory_CreateStream
,
556 ComponentFactory_CreateColorContext
,
557 ComponentFactory_CreateColorTransformer
,
558 ComponentFactory_CreateBitmap
,
559 ComponentFactory_CreateBitmapFromSource
,
560 ComponentFactory_CreateBitmapFromSourceRect
,
561 ComponentFactory_CreateBitmapFromMemory
,
562 ComponentFactory_CreateBitmapFromHBITMAP
,
563 ComponentFactory_CreateBitmapFromHICON
,
564 ComponentFactory_CreateComponentEnumerator
,
565 ComponentFactory_CreateFastMetadataEncoderFromDecoder
,
566 ComponentFactory_CreateFastMetadataEncoderFromFrameDecode
,
567 ComponentFactory_CreateQueryWriter
,
568 ComponentFactory_CreateQueryWriterFromReader
,
569 ComponentFactory_CreateMetadataReader
,
570 ComponentFactory_CreateMetadataReaderFromContainer
,
571 ComponentFactory_CreateMetadataWriter
,
572 ComponentFactory_CreateMetadataWriterFromReader
,
573 ComponentFactory_CreateQueryReaderFromBlockReader
,
574 ComponentFactory_CreateQueryWriterFromBlockWriter
,
575 ComponentFactory_CreateEncoderPropertyBag
578 HRESULT
ComponentFactory_CreateInstance(IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
580 ComponentFactory
*This
;
583 TRACE("(%p,%s,%p)\n", pUnkOuter
, debugstr_guid(iid
), ppv
);
587 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
589 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(ComponentFactory
));
590 if (!This
) return E_OUTOFMEMORY
;
592 This
->IWICComponentFactory_iface
.lpVtbl
= &ComponentFactory_Vtbl
;
595 ret
= IUnknown_QueryInterface((IUnknown
*)This
, iid
, ppv
);
596 IUnknown_Release((IUnknown
*)This
);