2 * Copyright 2009 Vincent Povirk for CodeWeavers
3 * Copyright 2012 Dmitry Timoshkov
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * 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 IWICComponentFactory IWICComponentFactory_iface
;
43 static inline ComponentFactory
*impl_from_IWICComponentFactory(IWICComponentFactory
*iface
)
45 return CONTAINING_RECORD(iface
, ComponentFactory
, IWICComponentFactory_iface
);
48 static HRESULT WINAPI
ComponentFactory_QueryInterface(IWICComponentFactory
*iface
, REFIID iid
,
51 ComponentFactory
*This
= impl_from_IWICComponentFactory(iface
);
52 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
54 if (!ppv
) return E_INVALIDARG
;
56 if (IsEqualIID(&IID_IUnknown
, iid
) ||
57 IsEqualIID(&IID_IWICImagingFactory
, iid
) ||
58 IsEqualIID(&IID_IWICComponentFactory
, iid
))
60 *ppv
= &This
->IWICComponentFactory_iface
;
68 IUnknown_AddRef((IUnknown
*)*ppv
);
72 static ULONG WINAPI
ComponentFactory_AddRef(IWICComponentFactory
*iface
)
74 ComponentFactory
*This
= impl_from_IWICComponentFactory(iface
);
75 ULONG ref
= InterlockedIncrement(&This
->ref
);
77 TRACE("(%p) refcount=%u\n", iface
, ref
);
82 static ULONG WINAPI
ComponentFactory_Release(IWICComponentFactory
*iface
)
84 ComponentFactory
*This
= impl_from_IWICComponentFactory(iface
);
85 ULONG ref
= InterlockedDecrement(&This
->ref
);
87 TRACE("(%p) refcount=%u\n", iface
, ref
);
90 HeapFree(GetProcessHeap(), 0, This
);
95 static HRESULT WINAPI
ComponentFactory_CreateDecoderFromFilename(
96 IWICComponentFactory
*iface
, LPCWSTR wzFilename
, const GUID
*pguidVendor
,
97 DWORD dwDesiredAccess
, WICDecodeOptions metadataOptions
,
98 IWICBitmapDecoder
**ppIDecoder
)
103 TRACE("(%p,%s,%s,%u,%u,%p)\n", iface
, debugstr_w(wzFilename
),
104 debugstr_guid(pguidVendor
), dwDesiredAccess
, metadataOptions
, ppIDecoder
);
106 hr
= StreamImpl_Create(&stream
);
109 hr
= IWICStream_InitializeFromFilename(stream
, wzFilename
, dwDesiredAccess
);
113 hr
= IWICComponentFactory_CreateDecoderFromStream(iface
, (IStream
*)stream
,
114 pguidVendor
, metadataOptions
, ppIDecoder
);
117 IWICStream_Release(stream
);
123 static IWICBitmapDecoder
*find_decoder(IStream
*pIStream
, const GUID
*pguidVendor
,
124 WICDecodeOptions metadataOptions
)
126 IEnumUnknown
*enumdecoders
;
127 IUnknown
*unkdecoderinfo
;
128 IWICBitmapDecoderInfo
*decoderinfo
;
129 IWICBitmapDecoder
*decoder
= NULL
;
135 res
= CreateComponentEnumerator(WICDecoder
, WICComponentEnumerateDefault
, &enumdecoders
);
136 if (FAILED(res
)) return NULL
;
140 res
= IEnumUnknown_Next(enumdecoders
, 1, &unkdecoderinfo
, &num_fetched
);
144 res
= IUnknown_QueryInterface(unkdecoderinfo
, &IID_IWICBitmapDecoderInfo
, (void**)&decoderinfo
);
150 res
= IWICBitmapDecoderInfo_GetVendorGUID(decoderinfo
, &vendor
);
151 if (FAILED(res
) || !IsEqualIID(&vendor
, pguidVendor
))
153 IWICBitmapDecoderInfo_Release(decoderinfo
);
154 IUnknown_Release(unkdecoderinfo
);
159 res
= IWICBitmapDecoderInfo_MatchesPattern(decoderinfo
, pIStream
, &matches
);
161 if (SUCCEEDED(res
) && matches
)
163 res
= IWICBitmapDecoderInfo_CreateInstance(decoderinfo
, &decoder
);
165 /* FIXME: should use QueryCapability to choose a decoder */
169 res
= IWICBitmapDecoder_Initialize(decoder
, pIStream
, metadataOptions
);
173 IWICBitmapDecoder_Release(decoder
);
179 IWICBitmapDecoderInfo_Release(decoderinfo
);
182 IUnknown_Release(unkdecoderinfo
);
188 IEnumUnknown_Release(enumdecoders
);
193 static HRESULT WINAPI
ComponentFactory_CreateDecoderFromStream(
194 IWICComponentFactory
*iface
, IStream
*pIStream
, const GUID
*pguidVendor
,
195 WICDecodeOptions metadataOptions
, IWICBitmapDecoder
**ppIDecoder
)
198 IWICBitmapDecoder
*decoder
= NULL
;
200 TRACE("(%p,%p,%s,%u,%p)\n", iface
, pIStream
, debugstr_guid(pguidVendor
),
201 metadataOptions
, ppIDecoder
);
204 decoder
= find_decoder(pIStream
, pguidVendor
, metadataOptions
);
206 decoder
= find_decoder(pIStream
, NULL
, metadataOptions
);
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
)
242 TRACE("(%p,%lx,%s,%u,%p)\n", iface
, hFile
, debugstr_guid(pguidVendor
),
243 metadataOptions
, ppIDecoder
);
245 hr
= StreamImpl_Create(&stream
);
248 hr
= stream_initialize_from_filehandle(stream
, (HANDLE
)hFile
);
251 hr
= IWICComponentFactory_CreateDecoderFromStream(iface
, (IStream
*)stream
,
252 pguidVendor
, metadataOptions
, ppIDecoder
);
254 IWICStream_Release(stream
);
259 static HRESULT WINAPI
ComponentFactory_CreateComponentInfo(IWICComponentFactory
*iface
,
260 REFCLSID clsidComponent
, IWICComponentInfo
**ppIInfo
)
262 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(clsidComponent
), ppIInfo
);
263 return CreateComponentInfo(clsidComponent
, ppIInfo
);
266 static HRESULT WINAPI
ComponentFactory_CreateDecoder(IWICComponentFactory
*iface
,
267 REFGUID guidContainerFormat
, const GUID
*pguidVendor
,
268 IWICBitmapDecoder
**ppIDecoder
)
270 IEnumUnknown
*enumdecoders
;
271 IUnknown
*unkdecoderinfo
;
272 IWICBitmapDecoderInfo
*decoderinfo
;
273 IWICBitmapDecoder
*decoder
= NULL
, *preferred_decoder
= NULL
;
278 TRACE("(%p,%s,%s,%p)\n", iface
, debugstr_guid(guidContainerFormat
),
279 debugstr_guid(pguidVendor
), ppIDecoder
);
281 if (!guidContainerFormat
|| !ppIDecoder
) return E_INVALIDARG
;
283 res
= CreateComponentEnumerator(WICDecoder
, WICComponentEnumerateDefault
, &enumdecoders
);
284 if (FAILED(res
)) return res
;
286 while (!preferred_decoder
)
288 res
= IEnumUnknown_Next(enumdecoders
, 1, &unkdecoderinfo
, &num_fetched
);
289 if (res
!= S_OK
) break;
291 res
= IUnknown_QueryInterface(unkdecoderinfo
, &IID_IWICBitmapDecoderInfo
, (void **)&decoderinfo
);
296 res
= IWICBitmapDecoderInfo_GetContainerFormat(decoderinfo
, &container_guid
);
297 if (SUCCEEDED(res
) && IsEqualIID(&container_guid
, guidContainerFormat
))
299 IWICBitmapDecoder
*new_decoder
;
301 res
= IWICBitmapDecoderInfo_CreateInstance(decoderinfo
, &new_decoder
);
306 res
= IWICBitmapDecoderInfo_GetVendorGUID(decoderinfo
, &vendor
);
307 if (SUCCEEDED(res
) && IsEqualIID(&vendor
, pguidVendor
))
309 preferred_decoder
= new_decoder
;
314 if (new_decoder
&& !decoder
)
316 decoder
= new_decoder
;
320 if (new_decoder
) IWICBitmapDecoder_Release(new_decoder
);
324 IWICBitmapDecoderInfo_Release(decoderinfo
);
327 IUnknown_Release(unkdecoderinfo
);
330 IEnumUnknown_Release(enumdecoders
);
332 if (preferred_decoder
)
334 *ppIDecoder
= preferred_decoder
;
335 if (decoder
) IWICBitmapDecoder_Release(decoder
);
341 *ppIDecoder
= decoder
;
346 return WINCODEC_ERR_COMPONENTNOTFOUND
;
349 static HRESULT WINAPI
ComponentFactory_CreateEncoder(IWICComponentFactory
*iface
,
350 REFGUID guidContainerFormat
, const GUID
*pguidVendor
,
351 IWICBitmapEncoder
**ppIEncoder
)
354 IEnumUnknown
*enumencoders
;
355 IUnknown
*unkencoderinfo
;
356 IWICBitmapEncoderInfo
*encoderinfo
;
357 IWICBitmapEncoder
*encoder
=NULL
;
360 GUID actual_containerformat
;
362 TRACE("(%p,%s,%s,%p)\n", iface
, debugstr_guid(guidContainerFormat
),
363 debugstr_guid(pguidVendor
), ppIEncoder
);
365 if (pguidVendor
&& !fixme
++)
366 FIXME("ignoring vendor GUID\n");
368 res
= CreateComponentEnumerator(WICEncoder
, WICComponentEnumerateDefault
, &enumencoders
);
369 if (FAILED(res
)) return res
;
373 res
= IEnumUnknown_Next(enumencoders
, 1, &unkencoderinfo
, &num_fetched
);
377 res
= IUnknown_QueryInterface(unkencoderinfo
, &IID_IWICBitmapEncoderInfo
, (void**)&encoderinfo
);
381 res
= IWICBitmapEncoderInfo_GetContainerFormat(encoderinfo
, &actual_containerformat
);
383 if (SUCCEEDED(res
) && IsEqualGUID(guidContainerFormat
, &actual_containerformat
))
385 res
= IWICBitmapEncoderInfo_CreateInstance(encoderinfo
, &encoder
);
390 IWICBitmapEncoderInfo_Release(encoderinfo
);
393 IUnknown_Release(unkencoderinfo
);
399 IEnumUnknown_Release(enumencoders
);
403 *ppIEncoder
= encoder
;
408 WARN("failed to create encoder\n");
410 return WINCODEC_ERR_COMPONENTNOTFOUND
;
414 static HRESULT WINAPI
ComponentFactory_CreatePalette(IWICComponentFactory
*iface
,
415 IWICPalette
**ppIPalette
)
417 TRACE("(%p,%p)\n", iface
, ppIPalette
);
418 return PaletteImpl_Create(ppIPalette
);
421 static HRESULT WINAPI
ComponentFactory_CreateFormatConverter(IWICComponentFactory
*iface
,
422 IWICFormatConverter
**ppIFormatConverter
)
424 return FormatConverter_CreateInstance(&IID_IWICFormatConverter
, (void**)ppIFormatConverter
);
427 static HRESULT WINAPI
ComponentFactory_CreateBitmapScaler(IWICComponentFactory
*iface
,
428 IWICBitmapScaler
**ppIBitmapScaler
)
430 TRACE("(%p,%p)\n", iface
, ppIBitmapScaler
);
432 return BitmapScaler_Create(ppIBitmapScaler
);
435 static HRESULT WINAPI
ComponentFactory_CreateBitmapClipper(IWICComponentFactory
*iface
,
436 IWICBitmapClipper
**ppIBitmapClipper
)
438 TRACE("(%p,%p)\n", iface
, ppIBitmapClipper
);
439 return BitmapClipper_Create(ppIBitmapClipper
);
442 static HRESULT WINAPI
ComponentFactory_CreateBitmapFlipRotator(IWICComponentFactory
*iface
,
443 IWICBitmapFlipRotator
**ppIBitmapFlipRotator
)
445 TRACE("(%p,%p)\n", iface
, ppIBitmapFlipRotator
);
446 return FlipRotator_Create(ppIBitmapFlipRotator
);
449 static HRESULT WINAPI
ComponentFactory_CreateStream(IWICComponentFactory
*iface
,
450 IWICStream
**ppIWICStream
)
452 TRACE("(%p,%p)\n", iface
, ppIWICStream
);
453 return StreamImpl_Create(ppIWICStream
);
456 static HRESULT WINAPI
ComponentFactory_CreateColorContext(IWICComponentFactory
*iface
,
457 IWICColorContext
**ppIColorContext
)
459 TRACE("(%p,%p)\n", iface
, ppIColorContext
);
460 return ColorContext_Create(ppIColorContext
);
463 static HRESULT WINAPI
ComponentFactory_CreateColorTransformer(IWICComponentFactory
*iface
,
464 IWICColorTransform
**ppIColorTransform
)
466 TRACE("(%p,%p)\n", iface
, ppIColorTransform
);
467 return ColorTransform_Create(ppIColorTransform
);
470 static HRESULT WINAPI
ComponentFactory_CreateBitmap(IWICComponentFactory
*iface
,
471 UINT uiWidth
, UINT uiHeight
, REFWICPixelFormatGUID pixelFormat
,
472 WICBitmapCreateCacheOption option
, IWICBitmap
**ppIBitmap
)
474 TRACE("(%p,%u,%u,%s,%u,%p)\n", iface
, uiWidth
, uiHeight
,
475 debugstr_guid(pixelFormat
), option
, ppIBitmap
);
476 return BitmapImpl_Create(uiWidth
, uiHeight
, 0, 0, NULL
, pixelFormat
, option
, ppIBitmap
);
479 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromSource(IWICComponentFactory
*iface
,
480 IWICBitmapSource
*piBitmapSource
, WICBitmapCreateCacheOption option
,
481 IWICBitmap
**ppIBitmap
)
484 IWICBitmapLock
*lock
;
485 IWICPalette
*palette
;
487 WICPixelFormatGUID pixelformat
= {0};
491 IWICComponentInfo
*info
;
492 IWICPixelFormatInfo2
*formatinfo
;
493 WICPixelFormatNumericRepresentation format_type
;
495 TRACE("(%p,%p,%u,%p)\n", iface
, piBitmapSource
, option
, ppIBitmap
);
497 if (!piBitmapSource
|| !ppIBitmap
)
500 hr
= IWICBitmapSource_GetSize(piBitmapSource
, &width
, &height
);
503 hr
= IWICBitmapSource_GetPixelFormat(piBitmapSource
, &pixelformat
);
506 hr
= CreateComponentInfo(&pixelformat
, &info
);
510 hr
= IWICComponentInfo_QueryInterface(info
, &IID_IWICPixelFormatInfo2
, (void**)&formatinfo
);
514 hr
= IWICPixelFormatInfo2_GetNumericRepresentation(formatinfo
, &format_type
);
516 IWICPixelFormatInfo2_Release(formatinfo
);
519 IWICComponentInfo_Release(info
);
523 hr
= BitmapImpl_Create(width
, height
, 0, 0, NULL
, &pixelformat
, option
, &result
);
527 hr
= IWICBitmap_Lock(result
, NULL
, WICBitmapLockWrite
, &lock
);
530 UINT stride
, buffersize
;
536 hr
= IWICBitmapLock_GetStride(lock
, &stride
);
539 hr
= IWICBitmapLock_GetDataPointer(lock
, &buffersize
, &buffer
);
542 hr
= IWICBitmapSource_CopyPixels(piBitmapSource
, &rc
, stride
,
545 IWICBitmapLock_Release(lock
);
548 if (SUCCEEDED(hr
) && (format_type
== WICPixelFormatNumericRepresentationUnspecified
||
549 format_type
== WICPixelFormatNumericRepresentationIndexed
))
551 hr
= PaletteImpl_Create(&palette
);
555 hr
= IWICBitmapSource_CopyPalette(piBitmapSource
, palette
);
558 hr
= IWICBitmap_SetPalette(result
, palette
);
562 IWICPalette_Release(palette
);
568 hr
= IWICBitmapSource_GetResolution(piBitmapSource
, &dpix
, &dpiy
);
571 hr
= IWICBitmap_SetResolution(result
, dpix
, dpiy
);
579 IWICBitmap_Release(result
);
585 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromSourceRect(IWICComponentFactory
*iface
,
586 IWICBitmapSource
*piBitmapSource
, UINT x
, UINT y
, UINT width
, UINT height
,
587 IWICBitmap
**ppIBitmap
)
589 FIXME("(%p,%p,%u,%u,%u,%u,%p): stub\n", iface
, piBitmapSource
, x
, y
, width
,
594 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromMemory(IWICComponentFactory
*iface
,
595 UINT width
, UINT height
, REFWICPixelFormatGUID format
, UINT stride
,
596 UINT size
, BYTE
*buffer
, IWICBitmap
**bitmap
)
598 TRACE("(%p,%u,%u,%s,%u,%u,%p,%p\n", iface
, width
, height
,
599 debugstr_guid(format
), stride
, size
, buffer
, bitmap
);
601 if (!stride
|| !size
|| !buffer
|| !bitmap
) return E_INVALIDARG
;
603 return BitmapImpl_Create(width
, height
, stride
, size
, buffer
, format
, WICBitmapCacheOnLoad
, bitmap
);
606 static BOOL
get_16bpp_format(HBITMAP hbm
, WICPixelFormatGUID
*format
)
612 hdc
= CreateCompatibleDC(0);
614 memset(&bmh
, 0, sizeof(bmh
));
615 bmh
.bV4Size
= sizeof(bmh
);
618 bmh
.bV4V4Compression
= BI_BITFIELDS
;
619 bmh
.bV4BitCount
= 16;
621 GetDIBits(hdc
, hbm
, 0, 0, NULL
, (BITMAPINFO
*)&bmh
, DIB_RGB_COLORS
);
623 if (bmh
.bV4RedMask
== 0x7c00 &&
624 bmh
.bV4GreenMask
== 0x3e0 &&
625 bmh
.bV4BlueMask
== 0x1f)
627 *format
= GUID_WICPixelFormat16bppBGR555
;
629 else if (bmh
.bV4RedMask
== 0xf800 &&
630 bmh
.bV4GreenMask
== 0x7e0 &&
631 bmh
.bV4BlueMask
== 0x1f)
633 *format
= GUID_WICPixelFormat16bppBGR565
;
637 FIXME("unrecognized bitfields %x,%x,%x\n", bmh
.bV4RedMask
,
638 bmh
.bV4GreenMask
, bmh
.bV4BlueMask
);
646 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromHBITMAP(IWICComponentFactory
*iface
,
647 HBITMAP hbm
, HPALETTE hpal
, WICBitmapAlphaChannelOption option
, IWICBitmap
**bitmap
)
651 WICPixelFormatGUID format
;
652 IWICBitmapLock
*lock
;
653 UINT size
, num_palette_entries
= 0;
654 PALETTEENTRY entry
[256];
656 TRACE("(%p,%p,%p,%u,%p)\n", iface
, hbm
, hpal
, option
, bitmap
);
658 if (!bitmap
) return E_INVALIDARG
;
660 if (GetObjectW(hbm
, sizeof(bm
), &bm
) != sizeof(bm
))
661 return WINCODEC_ERR_WIN32ERROR
;
665 num_palette_entries
= GetPaletteEntries(hpal
, 0, 256, entry
);
666 if (!num_palette_entries
)
667 return WINCODEC_ERR_WIN32ERROR
;
670 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
671 switch(bm
.bmBitsPixel
)
674 format
= GUID_WICPixelFormat1bppIndexed
;
677 format
= GUID_WICPixelFormat4bppIndexed
;
680 format
= GUID_WICPixelFormat8bppIndexed
;
683 if (!get_16bpp_format(hbm
, &format
))
687 format
= GUID_WICPixelFormat24bppBGR
;
692 case WICBitmapUseAlpha
:
693 format
= GUID_WICPixelFormat32bppBGRA
;
695 case WICBitmapUsePremultipliedAlpha
:
696 format
= GUID_WICPixelFormat32bppPBGRA
;
698 case WICBitmapIgnoreAlpha
:
699 format
= GUID_WICPixelFormat32bppBGR
;
706 format
= GUID_WICPixelFormat48bppRGB
;
709 FIXME("unsupported %d bpp\n", bm
.bmBitsPixel
);
713 hr
= BitmapImpl_Create(bm
.bmWidth
, bm
.bmHeight
, bm
.bmWidthBytes
, 0, NULL
, &format
, WICBitmapCacheOnLoad
, bitmap
);
714 if (hr
!= S_OK
) return hr
;
716 hr
= IWICBitmap_Lock(*bitmap
, NULL
, WICBitmapLockWrite
, &lock
);
721 char bmibuf
[FIELD_OFFSET(BITMAPINFO
, bmiColors
[256])];
722 BITMAPINFO
*bmi
= (BITMAPINFO
*)bmibuf
;
724 IWICBitmapLock_GetDataPointer(lock
, &size
, &buffer
);
726 hdc
= CreateCompatibleDC(0);
728 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
729 bmi
->bmiHeader
.biBitCount
= 0;
730 GetDIBits(hdc
, hbm
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
731 bmi
->bmiHeader
.biHeight
= -bm
.bmHeight
;
732 GetDIBits(hdc
, hbm
, 0, bm
.bmHeight
, buffer
, bmi
, DIB_RGB_COLORS
);
735 IWICBitmapLock_Release(lock
);
737 if (num_palette_entries
)
739 IWICPalette
*palette
;
740 WICColor colors
[256];
743 hr
= PaletteImpl_Create(&palette
);
746 for (i
= 0; i
< num_palette_entries
; i
++)
747 colors
[i
] = 0xff000000 | entry
[i
].peRed
<< 16 |
748 entry
[i
].peGreen
<< 8 | entry
[i
].peBlue
;
750 hr
= IWICPalette_InitializeCustom(palette
, colors
, num_palette_entries
);
752 hr
= IWICBitmap_SetPalette(*bitmap
, palette
);
754 IWICPalette_Release(palette
);
761 IWICBitmap_Release(*bitmap
);
768 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromHICON(IWICComponentFactory
*iface
,
769 HICON hicon
, IWICBitmap
**bitmap
)
771 IWICBitmapLock
*lock
;
774 int width
, height
, x
, y
;
783 TRACE("(%p,%p,%p)\n", iface
, hicon
, bitmap
);
785 if (!bitmap
) return E_INVALIDARG
;
787 if (!GetIconInfo(hicon
, &info
))
788 return HRESULT_FROM_WIN32(GetLastError());
790 GetObjectW(info
.hbmColor
? info
.hbmColor
: info
.hbmMask
, sizeof(bm
), &bm
);
793 height
= info
.hbmColor
? abs(bm
.bmHeight
) : abs(bm
.bmHeight
) / 2;
795 size
= stride
* height
;
797 hr
= BitmapImpl_Create(width
, height
, stride
, size
, NULL
,
798 &GUID_WICPixelFormat32bppBGRA
, WICBitmapCacheOnLoad
, bitmap
);
799 if (hr
!= S_OK
) goto failed
;
801 hr
= IWICBitmap_Lock(*bitmap
, NULL
, WICBitmapLockWrite
, &lock
);
804 IWICBitmap_Release(*bitmap
);
807 IWICBitmapLock_GetDataPointer(lock
, &size
, &buffer
);
809 hdc
= CreateCompatibleDC(0);
811 memset(&bi
, 0, sizeof(bi
));
812 bi
.bmiHeader
.biSize
= sizeof(bi
.bmiHeader
);
813 bi
.bmiHeader
.biWidth
= width
;
814 bi
.bmiHeader
.biHeight
= info
.hbmColor
? -height
: -height
* 2;
815 bi
.bmiHeader
.biPlanes
= 1;
816 bi
.bmiHeader
.biBitCount
= 32;
817 bi
.bmiHeader
.biCompression
= BI_RGB
;
823 GetDIBits(hdc
, info
.hbmColor
, 0, height
, buffer
, &bi
, DIB_RGB_COLORS
);
825 if (bm
.bmBitsPixel
== 32)
827 /* If any pixel has a non-zero alpha, ignore hbmMask */
828 bits
= (DWORD
*)buffer
;
829 for (x
= 0; x
< width
&& !has_alpha
; x
++, bits
++)
831 for (y
= 0; y
< height
; y
++)
833 if (*bits
& 0xff000000)
843 GetDIBits(hdc
, info
.hbmMask
, 0, height
, buffer
, &bi
, DIB_RGB_COLORS
);
853 mask
= HeapAlloc(GetProcessHeap(), 0, size
);
856 IWICBitmapLock_Release(lock
);
857 IWICBitmap_Release(*bitmap
);
863 /* read alpha data from the mask */
864 GetDIBits(hdc
, info
.hbmMask
, info
.hbmColor
? 0 : height
, height
, mask
, &bi
, DIB_RGB_COLORS
);
866 for (y
= 0; y
< height
; y
++)
868 rgba
= (DWORD
*)(buffer
+ y
* stride
);
869 bits
= (DWORD
*)(mask
+ y
* stride
);
871 for (x
= 0; x
< width
; x
++, rgba
++, bits
++)
880 HeapFree(GetProcessHeap(), 0, mask
);
884 /* set constant alpha of 255 */
885 for (y
= 0; y
< height
; y
++)
887 rgba
= (DWORD
*)(buffer
+ y
* stride
);
888 for (x
= 0; x
< width
; x
++, rgba
++)
895 IWICBitmapLock_Release(lock
);
899 DeleteObject(info
.hbmColor
);
900 DeleteObject(info
.hbmMask
);
905 static HRESULT WINAPI
ComponentFactory_CreateComponentEnumerator(IWICComponentFactory
*iface
,
906 DWORD componentTypes
, DWORD options
, IEnumUnknown
**ppIEnumUnknown
)
908 TRACE("(%p,%u,%u,%p)\n", iface
, componentTypes
, options
, ppIEnumUnknown
);
909 return CreateComponentEnumerator(componentTypes
, options
, ppIEnumUnknown
);
912 static HRESULT WINAPI
ComponentFactory_CreateFastMetadataEncoderFromDecoder(
913 IWICComponentFactory
*iface
, IWICBitmapDecoder
*pIDecoder
,
914 IWICFastMetadataEncoder
**ppIFastEncoder
)
916 FIXME("(%p,%p,%p): stub\n", iface
, pIDecoder
, ppIFastEncoder
);
920 static HRESULT WINAPI
ComponentFactory_CreateFastMetadataEncoderFromFrameDecode(
921 IWICComponentFactory
*iface
, IWICBitmapFrameDecode
*pIFrameDecoder
,
922 IWICFastMetadataEncoder
**ppIFastEncoder
)
924 FIXME("(%p,%p,%p): stub\n", iface
, pIFrameDecoder
, ppIFastEncoder
);
928 static HRESULT WINAPI
ComponentFactory_CreateQueryWriter(IWICComponentFactory
*iface
,
929 REFGUID guidMetadataFormat
, const GUID
*pguidVendor
,
930 IWICMetadataQueryWriter
**ppIQueryWriter
)
932 FIXME("(%p,%s,%s,%p): stub\n", iface
, debugstr_guid(guidMetadataFormat
),
933 debugstr_guid(pguidVendor
), ppIQueryWriter
);
937 static HRESULT WINAPI
ComponentFactory_CreateQueryWriterFromReader(IWICComponentFactory
*iface
,
938 IWICMetadataQueryReader
*pIQueryReader
, const GUID
*pguidVendor
,
939 IWICMetadataQueryWriter
**ppIQueryWriter
)
941 FIXME("(%p,%p,%s,%p): stub\n", iface
, pIQueryReader
, debugstr_guid(pguidVendor
),
946 static HRESULT WINAPI
ComponentFactory_CreateMetadataReader(IWICComponentFactory
*iface
,
947 REFGUID format
, const GUID
*vendor
, DWORD options
, IStream
*stream
, IWICMetadataReader
**reader
)
949 FIXME("%p,%s,%s,%x,%p,%p: stub\n", iface
, debugstr_guid(format
), debugstr_guid(vendor
),
950 options
, stream
, reader
);
954 static HRESULT WINAPI
ComponentFactory_CreateMetadataReaderFromContainer(IWICComponentFactory
*iface
,
955 REFGUID format
, const GUID
*vendor
, DWORD options
, IStream
*stream
, IWICMetadataReader
**reader
)
958 IEnumUnknown
*enumreaders
;
959 IUnknown
*unkreaderinfo
;
960 IWICMetadataReaderInfo
*readerinfo
;
961 IWICPersistStream
*wicpersiststream
;
967 TRACE("%p,%s,%s,%x,%p,%p\n", iface
, debugstr_guid(format
), debugstr_guid(vendor
),
968 options
, stream
, reader
);
970 if (!format
|| !stream
|| !reader
)
975 hr
= CreateComponentEnumerator(WICMetadataReader
, WICComponentEnumerateDefault
, &enumreaders
);
976 if (FAILED(hr
)) return hr
;
983 hr
= IEnumUnknown_Next(enumreaders
, 1, &unkreaderinfo
, &num_fetched
);
987 hr
= IUnknown_QueryInterface(unkreaderinfo
, &IID_IWICMetadataReaderInfo
, (void**)&readerinfo
);
993 hr
= IWICMetadataReaderInfo_GetVendorGUID(readerinfo
, &decoder_vendor
);
995 if (FAILED(hr
) || !IsEqualIID(vendor
, &decoder_vendor
))
997 IWICMetadataReaderInfo_Release(readerinfo
);
998 IUnknown_Release(unkreaderinfo
);
1003 hr
= IWICMetadataReaderInfo_MatchesPattern(readerinfo
, format
, stream
, &matches
);
1005 if (SUCCEEDED(hr
) && matches
)
1007 hr
= IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
1010 hr
= IWICMetadataReaderInfo_CreateInstance(readerinfo
, reader
);
1014 hr
= IWICMetadataReader_QueryInterface(*reader
, &IID_IWICPersistStream
, (void**)&wicpersiststream
);
1018 hr
= IWICPersistStream_LoadEx(wicpersiststream
,
1019 stream
, vendor
, options
& WICPersistOptionMask
);
1021 IWICPersistStream_Release(wicpersiststream
);
1026 IWICMetadataReader_Release(*reader
);
1032 IUnknown_Release(readerinfo
);
1035 IUnknown_Release(unkreaderinfo
);
1041 if (!*reader
&& vendor
)
1044 IEnumUnknown_Reset(enumreaders
);
1048 IEnumUnknown_Release(enumreaders
);
1050 if (!*reader
&& !(options
& WICMetadataCreationFailUnknown
))
1052 hr
= IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
1055 hr
= UnknownMetadataReader_CreateInstance(&IID_IWICMetadataReader
, (void**)reader
);
1059 hr
= IWICMetadataReader_QueryInterface(*reader
, &IID_IWICPersistStream
, (void**)&wicpersiststream
);
1063 hr
= IWICPersistStream_LoadEx(wicpersiststream
, stream
, NULL
, options
& WICPersistOptionMask
);
1065 IWICPersistStream_Release(wicpersiststream
);
1070 IWICMetadataReader_Release(*reader
);
1079 return WINCODEC_ERR_COMPONENTNOTFOUND
;
1082 static HRESULT WINAPI
ComponentFactory_CreateMetadataWriter(IWICComponentFactory
*iface
,
1083 REFGUID format
, const GUID
*vendor
, DWORD options
, IWICMetadataWriter
**writer
)
1085 FIXME("%p,%s,%s,%x,%p: stub\n", iface
, debugstr_guid(format
), debugstr_guid(vendor
), options
, writer
);
1089 static HRESULT WINAPI
ComponentFactory_CreateMetadataWriterFromReader(IWICComponentFactory
*iface
,
1090 IWICMetadataReader
*reader
, const GUID
*vendor
, IWICMetadataWriter
**writer
)
1092 FIXME("%p,%p,%s,%p: stub\n", iface
, reader
, debugstr_guid(vendor
), writer
);
1096 static HRESULT WINAPI
ComponentFactory_CreateQueryReaderFromBlockReader(IWICComponentFactory
*iface
,
1097 IWICMetadataBlockReader
*block_reader
, IWICMetadataQueryReader
**query_reader
)
1099 TRACE("%p,%p,%p\n", iface
, block_reader
, query_reader
);
1101 if (!block_reader
|| !query_reader
)
1102 return E_INVALIDARG
;
1104 return MetadataQueryReader_CreateInstance(block_reader
, query_reader
);
1107 static HRESULT WINAPI
ComponentFactory_CreateQueryWriterFromBlockWriter(IWICComponentFactory
*iface
,
1108 IWICMetadataBlockWriter
*block_writer
, IWICMetadataQueryWriter
**query_writer
)
1110 FIXME("%p,%p,%p: stub\n", iface
, block_writer
, query_writer
);
1114 static HRESULT WINAPI
ComponentFactory_CreateEncoderPropertyBag(IWICComponentFactory
*iface
,
1115 PROPBAG2
*options
, UINT count
, IPropertyBag2
**property
)
1117 TRACE("(%p,%p,%u,%p)\n", iface
, options
, count
, property
);
1118 return CreatePropertyBag2(options
, count
, property
);
1121 static const IWICComponentFactoryVtbl ComponentFactory_Vtbl
= {
1122 ComponentFactory_QueryInterface
,
1123 ComponentFactory_AddRef
,
1124 ComponentFactory_Release
,
1125 ComponentFactory_CreateDecoderFromFilename
,
1126 ComponentFactory_CreateDecoderFromStream
,
1127 ComponentFactory_CreateDecoderFromFileHandle
,
1128 ComponentFactory_CreateComponentInfo
,
1129 ComponentFactory_CreateDecoder
,
1130 ComponentFactory_CreateEncoder
,
1131 ComponentFactory_CreatePalette
,
1132 ComponentFactory_CreateFormatConverter
,
1133 ComponentFactory_CreateBitmapScaler
,
1134 ComponentFactory_CreateBitmapClipper
,
1135 ComponentFactory_CreateBitmapFlipRotator
,
1136 ComponentFactory_CreateStream
,
1137 ComponentFactory_CreateColorContext
,
1138 ComponentFactory_CreateColorTransformer
,
1139 ComponentFactory_CreateBitmap
,
1140 ComponentFactory_CreateBitmapFromSource
,
1141 ComponentFactory_CreateBitmapFromSourceRect
,
1142 ComponentFactory_CreateBitmapFromMemory
,
1143 ComponentFactory_CreateBitmapFromHBITMAP
,
1144 ComponentFactory_CreateBitmapFromHICON
,
1145 ComponentFactory_CreateComponentEnumerator
,
1146 ComponentFactory_CreateFastMetadataEncoderFromDecoder
,
1147 ComponentFactory_CreateFastMetadataEncoderFromFrameDecode
,
1148 ComponentFactory_CreateQueryWriter
,
1149 ComponentFactory_CreateQueryWriterFromReader
,
1150 ComponentFactory_CreateMetadataReader
,
1151 ComponentFactory_CreateMetadataReaderFromContainer
,
1152 ComponentFactory_CreateMetadataWriter
,
1153 ComponentFactory_CreateMetadataWriterFromReader
,
1154 ComponentFactory_CreateQueryReaderFromBlockReader
,
1155 ComponentFactory_CreateQueryWriterFromBlockWriter
,
1156 ComponentFactory_CreateEncoderPropertyBag
1159 HRESULT
ComponentFactory_CreateInstance(REFIID iid
, void** ppv
)
1161 ComponentFactory
*This
;
1164 TRACE("(%s,%p)\n", debugstr_guid(iid
), ppv
);
1168 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(ComponentFactory
));
1169 if (!This
) return E_OUTOFMEMORY
;
1171 This
->IWICComponentFactory_iface
.lpVtbl
= &ComponentFactory_Vtbl
;
1174 ret
= IWICComponentFactory_QueryInterface(&This
->IWICComponentFactory_iface
, iid
, ppv
);
1175 IWICComponentFactory_Release(&This
->IWICComponentFactory_iface
);