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 "wincodecsdk.h"
34 #include "wincodecs_private.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs
);
41 IWICComponentFactory IWICComponentFactory_iface
;
45 static inline ComponentFactory
*impl_from_IWICComponentFactory(IWICComponentFactory
*iface
)
47 return CONTAINING_RECORD(iface
, ComponentFactory
, IWICComponentFactory_iface
);
50 static HRESULT WINAPI
ComponentFactory_QueryInterface(IWICComponentFactory
*iface
, REFIID iid
,
53 ComponentFactory
*This
= impl_from_IWICComponentFactory(iface
);
54 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
56 if (!ppv
) return E_INVALIDARG
;
58 if (IsEqualIID(&IID_IUnknown
, iid
) ||
59 IsEqualIID(&IID_IWICImagingFactory
, iid
) ||
60 IsEqualIID(&IID_IWICComponentFactory
, iid
))
62 *ppv
= &This
->IWICComponentFactory_iface
;
70 IUnknown_AddRef((IUnknown
*)*ppv
);
74 static ULONG WINAPI
ComponentFactory_AddRef(IWICComponentFactory
*iface
)
76 ComponentFactory
*This
= impl_from_IWICComponentFactory(iface
);
77 ULONG ref
= InterlockedIncrement(&This
->ref
);
79 TRACE("(%p) refcount=%u\n", iface
, ref
);
84 static ULONG WINAPI
ComponentFactory_Release(IWICComponentFactory
*iface
)
86 ComponentFactory
*This
= impl_from_IWICComponentFactory(iface
);
87 ULONG ref
= InterlockedDecrement(&This
->ref
);
89 TRACE("(%p) refcount=%u\n", iface
, ref
);
92 HeapFree(GetProcessHeap(), 0, This
);
97 static HRESULT WINAPI
ComponentFactory_CreateDecoderFromFilename(
98 IWICComponentFactory
*iface
, LPCWSTR wzFilename
, const GUID
*pguidVendor
,
99 DWORD dwDesiredAccess
, WICDecodeOptions metadataOptions
,
100 IWICBitmapDecoder
**ppIDecoder
)
105 TRACE("(%p,%s,%s,%u,%u,%p)\n", iface
, debugstr_w(wzFilename
),
106 debugstr_guid(pguidVendor
), dwDesiredAccess
, metadataOptions
, ppIDecoder
);
108 hr
= StreamImpl_Create(&stream
);
111 hr
= IWICStream_InitializeFromFilename(stream
, wzFilename
, dwDesiredAccess
);
115 hr
= IWICComponentFactory_CreateDecoderFromStream(iface
, (IStream
*)stream
,
116 pguidVendor
, metadataOptions
, ppIDecoder
);
119 IWICStream_Release(stream
);
125 static IWICBitmapDecoder
*find_decoder(IStream
*pIStream
, const GUID
*pguidVendor
,
126 WICDecodeOptions metadataOptions
)
128 IEnumUnknown
*enumdecoders
;
129 IUnknown
*unkdecoderinfo
;
130 IWICBitmapDecoderInfo
*decoderinfo
;
131 IWICBitmapDecoder
*decoder
= NULL
;
137 res
= CreateComponentEnumerator(WICDecoder
, WICComponentEnumerateDefault
, &enumdecoders
);
138 if (FAILED(res
)) return NULL
;
142 res
= IEnumUnknown_Next(enumdecoders
, 1, &unkdecoderinfo
, &num_fetched
);
146 res
= IUnknown_QueryInterface(unkdecoderinfo
, &IID_IWICBitmapDecoderInfo
, (void**)&decoderinfo
);
152 res
= IWICBitmapDecoderInfo_GetVendorGUID(decoderinfo
, &vendor
);
153 if (FAILED(res
) || !IsEqualIID(&vendor
, pguidVendor
))
155 IWICBitmapDecoderInfo_Release(decoderinfo
);
156 IUnknown_Release(unkdecoderinfo
);
161 res
= IWICBitmapDecoderInfo_MatchesPattern(decoderinfo
, pIStream
, &matches
);
163 if (SUCCEEDED(res
) && matches
)
165 res
= IWICBitmapDecoderInfo_CreateInstance(decoderinfo
, &decoder
);
167 /* FIXME: should use QueryCapability to choose a decoder */
171 res
= IWICBitmapDecoder_Initialize(decoder
, pIStream
, metadataOptions
);
175 IWICBitmapDecoder_Release(decoder
);
181 IWICBitmapDecoderInfo_Release(decoderinfo
);
184 IUnknown_Release(unkdecoderinfo
);
190 IEnumUnknown_Release(enumdecoders
);
195 static HRESULT WINAPI
ComponentFactory_CreateDecoderFromStream(
196 IWICComponentFactory
*iface
, IStream
*pIStream
, const GUID
*pguidVendor
,
197 WICDecodeOptions metadataOptions
, IWICBitmapDecoder
**ppIDecoder
)
200 IWICBitmapDecoder
*decoder
= NULL
;
202 TRACE("(%p,%p,%s,%u,%p)\n", iface
, pIStream
, debugstr_guid(pguidVendor
),
203 metadataOptions
, ppIDecoder
);
206 decoder
= find_decoder(pIStream
, pguidVendor
, metadataOptions
);
208 decoder
= find_decoder(pIStream
, NULL
, metadataOptions
);
212 *ppIDecoder
= decoder
;
217 if (WARN_ON(wincodecs
))
223 WARN("failed to load from a stream\n");
226 res
= IStream_Seek(pIStream
, seek
, STREAM_SEEK_SET
, NULL
);
228 res
= IStream_Read(pIStream
, data
, 4, &bytesread
);
230 WARN("first %i bytes of stream=%x %x %x %x\n", bytesread
, data
[0], data
[1], data
[2], data
[3]);
233 return WINCODEC_ERR_COMPONENTNOTFOUND
;
237 static HRESULT WINAPI
ComponentFactory_CreateDecoderFromFileHandle(
238 IWICComponentFactory
*iface
, ULONG_PTR hFile
, const GUID
*pguidVendor
,
239 WICDecodeOptions metadataOptions
, IWICBitmapDecoder
**ppIDecoder
)
244 TRACE("(%p,%lx,%s,%u,%p)\n", iface
, hFile
, debugstr_guid(pguidVendor
),
245 metadataOptions
, ppIDecoder
);
247 hr
= StreamImpl_Create(&stream
);
250 hr
= stream_initialize_from_filehandle(stream
, (HANDLE
)hFile
);
253 hr
= IWICComponentFactory_CreateDecoderFromStream(iface
, (IStream
*)stream
,
254 pguidVendor
, metadataOptions
, ppIDecoder
);
256 IWICStream_Release(stream
);
261 static HRESULT WINAPI
ComponentFactory_CreateComponentInfo(IWICComponentFactory
*iface
,
262 REFCLSID clsidComponent
, IWICComponentInfo
**ppIInfo
)
264 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(clsidComponent
), ppIInfo
);
265 return CreateComponentInfo(clsidComponent
, ppIInfo
);
268 static HRESULT WINAPI
ComponentFactory_CreateDecoder(IWICComponentFactory
*iface
,
269 REFGUID guidContainerFormat
, const GUID
*pguidVendor
,
270 IWICBitmapDecoder
**ppIDecoder
)
272 IEnumUnknown
*enumdecoders
;
273 IUnknown
*unkdecoderinfo
;
274 IWICBitmapDecoderInfo
*decoderinfo
;
275 IWICBitmapDecoder
*decoder
= NULL
, *preferred_decoder
= NULL
;
280 TRACE("(%p,%s,%s,%p)\n", iface
, debugstr_guid(guidContainerFormat
),
281 debugstr_guid(pguidVendor
), ppIDecoder
);
283 if (!guidContainerFormat
|| !ppIDecoder
) return E_INVALIDARG
;
285 res
= CreateComponentEnumerator(WICDecoder
, WICComponentEnumerateDefault
, &enumdecoders
);
286 if (FAILED(res
)) return res
;
288 while (!preferred_decoder
)
290 res
= IEnumUnknown_Next(enumdecoders
, 1, &unkdecoderinfo
, &num_fetched
);
291 if (res
!= S_OK
) break;
293 res
= IUnknown_QueryInterface(unkdecoderinfo
, &IID_IWICBitmapDecoderInfo
, (void **)&decoderinfo
);
298 res
= IWICBitmapDecoderInfo_GetContainerFormat(decoderinfo
, &container_guid
);
299 if (SUCCEEDED(res
) && IsEqualIID(&container_guid
, guidContainerFormat
))
301 IWICBitmapDecoder
*new_decoder
;
303 res
= IWICBitmapDecoderInfo_CreateInstance(decoderinfo
, &new_decoder
);
308 res
= IWICBitmapDecoderInfo_GetVendorGUID(decoderinfo
, &vendor
);
309 if (SUCCEEDED(res
) && IsEqualIID(&vendor
, pguidVendor
))
311 preferred_decoder
= new_decoder
;
316 if (new_decoder
&& !decoder
)
318 decoder
= new_decoder
;
322 if (new_decoder
) IWICBitmapDecoder_Release(new_decoder
);
326 IWICBitmapDecoderInfo_Release(decoderinfo
);
329 IUnknown_Release(unkdecoderinfo
);
332 IEnumUnknown_Release(enumdecoders
);
334 if (preferred_decoder
)
336 *ppIDecoder
= preferred_decoder
;
337 if (decoder
) IWICBitmapDecoder_Release(decoder
);
343 *ppIDecoder
= decoder
;
348 return WINCODEC_ERR_COMPONENTNOTFOUND
;
351 static HRESULT WINAPI
ComponentFactory_CreateEncoder(IWICComponentFactory
*iface
,
352 REFGUID guidContainerFormat
, const GUID
*pguidVendor
,
353 IWICBitmapEncoder
**ppIEncoder
)
356 IEnumUnknown
*enumencoders
;
357 IUnknown
*unkencoderinfo
;
358 IWICBitmapEncoderInfo
*encoderinfo
;
359 IWICBitmapEncoder
*encoder
=NULL
;
362 GUID actual_containerformat
;
364 TRACE("(%p,%s,%s,%p)\n", iface
, debugstr_guid(guidContainerFormat
),
365 debugstr_guid(pguidVendor
), ppIEncoder
);
367 if (pguidVendor
&& !fixme
++)
368 FIXME("ignoring vendor GUID\n");
370 res
= CreateComponentEnumerator(WICEncoder
, WICComponentEnumerateDefault
, &enumencoders
);
371 if (FAILED(res
)) return res
;
375 res
= IEnumUnknown_Next(enumencoders
, 1, &unkencoderinfo
, &num_fetched
);
379 res
= IUnknown_QueryInterface(unkencoderinfo
, &IID_IWICBitmapEncoderInfo
, (void**)&encoderinfo
);
383 res
= IWICBitmapEncoderInfo_GetContainerFormat(encoderinfo
, &actual_containerformat
);
385 if (SUCCEEDED(res
) && IsEqualGUID(guidContainerFormat
, &actual_containerformat
))
387 res
= IWICBitmapEncoderInfo_CreateInstance(encoderinfo
, &encoder
);
392 IWICBitmapEncoderInfo_Release(encoderinfo
);
395 IUnknown_Release(unkencoderinfo
);
401 IEnumUnknown_Release(enumencoders
);
405 *ppIEncoder
= encoder
;
410 WARN("failed to create encoder\n");
412 return WINCODEC_ERR_COMPONENTNOTFOUND
;
416 static HRESULT WINAPI
ComponentFactory_CreatePalette(IWICComponentFactory
*iface
,
417 IWICPalette
**ppIPalette
)
419 TRACE("(%p,%p)\n", iface
, ppIPalette
);
420 return PaletteImpl_Create(ppIPalette
);
423 static HRESULT WINAPI
ComponentFactory_CreateFormatConverter(IWICComponentFactory
*iface
,
424 IWICFormatConverter
**ppIFormatConverter
)
426 return FormatConverter_CreateInstance(&IID_IWICFormatConverter
, (void**)ppIFormatConverter
);
429 static HRESULT WINAPI
ComponentFactory_CreateBitmapScaler(IWICComponentFactory
*iface
,
430 IWICBitmapScaler
**ppIBitmapScaler
)
432 TRACE("(%p,%p)\n", iface
, ppIBitmapScaler
);
434 return BitmapScaler_Create(ppIBitmapScaler
);
437 static HRESULT WINAPI
ComponentFactory_CreateBitmapClipper(IWICComponentFactory
*iface
,
438 IWICBitmapClipper
**ppIBitmapClipper
)
440 TRACE("(%p,%p)\n", iface
, ppIBitmapClipper
);
441 return BitmapClipper_Create(ppIBitmapClipper
);
444 static HRESULT WINAPI
ComponentFactory_CreateBitmapFlipRotator(IWICComponentFactory
*iface
,
445 IWICBitmapFlipRotator
**ppIBitmapFlipRotator
)
447 TRACE("(%p,%p)\n", iface
, ppIBitmapFlipRotator
);
448 return FlipRotator_Create(ppIBitmapFlipRotator
);
451 static HRESULT WINAPI
ComponentFactory_CreateStream(IWICComponentFactory
*iface
,
452 IWICStream
**ppIWICStream
)
454 TRACE("(%p,%p)\n", iface
, ppIWICStream
);
455 return StreamImpl_Create(ppIWICStream
);
458 static HRESULT WINAPI
ComponentFactory_CreateColorContext(IWICComponentFactory
*iface
,
459 IWICColorContext
**ppIColorContext
)
461 TRACE("(%p,%p)\n", iface
, ppIColorContext
);
462 return ColorContext_Create(ppIColorContext
);
465 static HRESULT WINAPI
ComponentFactory_CreateColorTransformer(IWICComponentFactory
*iface
,
466 IWICColorTransform
**ppIColorTransform
)
468 TRACE("(%p,%p)\n", iface
, ppIColorTransform
);
469 return ColorTransform_Create(ppIColorTransform
);
472 static HRESULT WINAPI
ComponentFactory_CreateBitmap(IWICComponentFactory
*iface
,
473 UINT uiWidth
, UINT uiHeight
, REFWICPixelFormatGUID pixelFormat
,
474 WICBitmapCreateCacheOption option
, IWICBitmap
**ppIBitmap
)
476 TRACE("(%p,%u,%u,%s,%u,%p)\n", iface
, uiWidth
, uiHeight
,
477 debugstr_guid(pixelFormat
), option
, ppIBitmap
);
478 return BitmapImpl_Create(uiWidth
, uiHeight
, 0, 0, NULL
, pixelFormat
, option
, ppIBitmap
);
481 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromSource(IWICComponentFactory
*iface
,
482 IWICBitmapSource
*piBitmapSource
, WICBitmapCreateCacheOption option
,
483 IWICBitmap
**ppIBitmap
)
486 IWICBitmapLock
*lock
;
487 IWICPalette
*palette
;
489 WICPixelFormatGUID pixelformat
= {0};
493 IWICComponentInfo
*info
;
494 IWICPixelFormatInfo2
*formatinfo
;
495 WICPixelFormatNumericRepresentation format_type
;
497 TRACE("(%p,%p,%u,%p)\n", iface
, piBitmapSource
, option
, ppIBitmap
);
499 if (!piBitmapSource
|| !ppIBitmap
)
502 hr
= IWICBitmapSource_GetSize(piBitmapSource
, &width
, &height
);
505 hr
= IWICBitmapSource_GetPixelFormat(piBitmapSource
, &pixelformat
);
508 hr
= CreateComponentInfo(&pixelformat
, &info
);
512 hr
= IWICComponentInfo_QueryInterface(info
, &IID_IWICPixelFormatInfo2
, (void**)&formatinfo
);
516 hr
= IWICPixelFormatInfo2_GetNumericRepresentation(formatinfo
, &format_type
);
518 IWICPixelFormatInfo2_Release(formatinfo
);
521 IWICComponentInfo_Release(info
);
525 hr
= BitmapImpl_Create(width
, height
, 0, 0, NULL
, &pixelformat
, option
, &result
);
529 hr
= IWICBitmap_Lock(result
, NULL
, WICBitmapLockWrite
, &lock
);
532 UINT stride
, buffersize
;
538 hr
= IWICBitmapLock_GetStride(lock
, &stride
);
541 hr
= IWICBitmapLock_GetDataPointer(lock
, &buffersize
, &buffer
);
544 hr
= IWICBitmapSource_CopyPixels(piBitmapSource
, &rc
, stride
,
547 IWICBitmapLock_Release(lock
);
550 if (SUCCEEDED(hr
) && (format_type
== WICPixelFormatNumericRepresentationUnspecified
||
551 format_type
== WICPixelFormatNumericRepresentationIndexed
))
553 hr
= PaletteImpl_Create(&palette
);
557 hr
= IWICBitmapSource_CopyPalette(piBitmapSource
, palette
);
560 hr
= IWICBitmap_SetPalette(result
, palette
);
564 IWICPalette_Release(palette
);
570 hr
= IWICBitmapSource_GetResolution(piBitmapSource
, &dpix
, &dpiy
);
573 hr
= IWICBitmap_SetResolution(result
, dpix
, dpiy
);
581 IWICBitmap_Release(result
);
587 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromSourceRect(IWICComponentFactory
*iface
,
588 IWICBitmapSource
*piBitmapSource
, UINT x
, UINT y
, UINT width
, UINT height
,
589 IWICBitmap
**ppIBitmap
)
591 FIXME("(%p,%p,%u,%u,%u,%u,%p): stub\n", iface
, piBitmapSource
, x
, y
, width
,
596 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromMemory(IWICComponentFactory
*iface
,
597 UINT width
, UINT height
, REFWICPixelFormatGUID format
, UINT stride
,
598 UINT size
, BYTE
*buffer
, IWICBitmap
**bitmap
)
600 TRACE("(%p,%u,%u,%s,%u,%u,%p,%p\n", iface
, width
, height
,
601 debugstr_guid(format
), stride
, size
, buffer
, bitmap
);
603 if (!stride
|| !size
|| !buffer
|| !bitmap
) return E_INVALIDARG
;
605 return BitmapImpl_Create(width
, height
, stride
, size
, buffer
, format
, WICBitmapCacheOnLoad
, bitmap
);
608 static BOOL
get_16bpp_format(HBITMAP hbm
, WICPixelFormatGUID
*format
)
614 hdc
= CreateCompatibleDC(0);
616 memset(&bmh
, 0, sizeof(bmh
));
617 bmh
.bV4Size
= sizeof(bmh
);
620 bmh
.bV4V4Compression
= BI_BITFIELDS
;
621 bmh
.bV4BitCount
= 16;
623 GetDIBits(hdc
, hbm
, 0, 0, NULL
, (BITMAPINFO
*)&bmh
, DIB_RGB_COLORS
);
625 if (bmh
.bV4RedMask
== 0x7c00 &&
626 bmh
.bV4GreenMask
== 0x3e0 &&
627 bmh
.bV4BlueMask
== 0x1f)
629 *format
= GUID_WICPixelFormat16bppBGR555
;
631 else if (bmh
.bV4RedMask
== 0xf800 &&
632 bmh
.bV4GreenMask
== 0x7e0 &&
633 bmh
.bV4BlueMask
== 0x1f)
635 *format
= GUID_WICPixelFormat16bppBGR565
;
639 FIXME("unrecognized bitfields %x,%x,%x\n", bmh
.bV4RedMask
,
640 bmh
.bV4GreenMask
, bmh
.bV4BlueMask
);
648 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromHBITMAP(IWICComponentFactory
*iface
,
649 HBITMAP hbm
, HPALETTE hpal
, WICBitmapAlphaChannelOption option
, IWICBitmap
**bitmap
)
653 WICPixelFormatGUID format
;
654 IWICBitmapLock
*lock
;
655 UINT size
, num_palette_entries
= 0;
656 PALETTEENTRY entry
[256];
658 TRACE("(%p,%p,%p,%u,%p)\n", iface
, hbm
, hpal
, option
, bitmap
);
660 if (!bitmap
) return E_INVALIDARG
;
662 if (GetObjectW(hbm
, sizeof(bm
), &bm
) != sizeof(bm
))
663 return WINCODEC_ERR_WIN32ERROR
;
667 num_palette_entries
= GetPaletteEntries(hpal
, 0, 256, entry
);
668 if (!num_palette_entries
)
669 return WINCODEC_ERR_WIN32ERROR
;
672 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
673 switch(bm
.bmBitsPixel
)
676 format
= GUID_WICPixelFormat1bppIndexed
;
679 format
= GUID_WICPixelFormat4bppIndexed
;
682 format
= GUID_WICPixelFormat8bppIndexed
;
685 if (!get_16bpp_format(hbm
, &format
))
689 format
= GUID_WICPixelFormat24bppBGR
;
694 case WICBitmapUseAlpha
:
695 format
= GUID_WICPixelFormat32bppBGRA
;
697 case WICBitmapUsePremultipliedAlpha
:
698 format
= GUID_WICPixelFormat32bppPBGRA
;
700 case WICBitmapIgnoreAlpha
:
701 format
= GUID_WICPixelFormat32bppBGR
;
708 format
= GUID_WICPixelFormat48bppRGB
;
711 FIXME("unsupported %d bpp\n", bm
.bmBitsPixel
);
715 hr
= BitmapImpl_Create(bm
.bmWidth
, bm
.bmHeight
, bm
.bmWidthBytes
, 0, NULL
, &format
, WICBitmapCacheOnLoad
, bitmap
);
716 if (hr
!= S_OK
) return hr
;
718 hr
= IWICBitmap_Lock(*bitmap
, NULL
, WICBitmapLockWrite
, &lock
);
723 char bmibuf
[FIELD_OFFSET(BITMAPINFO
, bmiColors
[256])];
724 BITMAPINFO
*bmi
= (BITMAPINFO
*)bmibuf
;
726 IWICBitmapLock_GetDataPointer(lock
, &size
, &buffer
);
728 hdc
= CreateCompatibleDC(0);
730 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
731 bmi
->bmiHeader
.biBitCount
= 0;
732 GetDIBits(hdc
, hbm
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
733 bmi
->bmiHeader
.biHeight
= -bm
.bmHeight
;
734 GetDIBits(hdc
, hbm
, 0, bm
.bmHeight
, buffer
, bmi
, DIB_RGB_COLORS
);
737 IWICBitmapLock_Release(lock
);
739 if (num_palette_entries
)
741 IWICPalette
*palette
;
742 WICColor colors
[256];
745 hr
= PaletteImpl_Create(&palette
);
748 for (i
= 0; i
< num_palette_entries
; i
++)
749 colors
[i
] = 0xff000000 | entry
[i
].peRed
<< 16 |
750 entry
[i
].peGreen
<< 8 | entry
[i
].peBlue
;
752 hr
= IWICPalette_InitializeCustom(palette
, colors
, num_palette_entries
);
754 hr
= IWICBitmap_SetPalette(*bitmap
, palette
);
756 IWICPalette_Release(palette
);
763 IWICBitmap_Release(*bitmap
);
770 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromHICON(IWICComponentFactory
*iface
,
771 HICON hicon
, IWICBitmap
**bitmap
)
773 IWICBitmapLock
*lock
;
776 int width
, height
, x
, y
;
785 TRACE("(%p,%p,%p)\n", iface
, hicon
, bitmap
);
787 if (!bitmap
) return E_INVALIDARG
;
789 if (!GetIconInfo(hicon
, &info
))
790 return HRESULT_FROM_WIN32(GetLastError());
792 GetObjectW(info
.hbmColor
? info
.hbmColor
: info
.hbmMask
, sizeof(bm
), &bm
);
795 height
= info
.hbmColor
? abs(bm
.bmHeight
) : abs(bm
.bmHeight
) / 2;
797 size
= stride
* height
;
799 hr
= BitmapImpl_Create(width
, height
, stride
, size
, NULL
,
800 &GUID_WICPixelFormat32bppBGRA
, WICBitmapCacheOnLoad
, bitmap
);
801 if (hr
!= S_OK
) goto failed
;
803 hr
= IWICBitmap_Lock(*bitmap
, NULL
, WICBitmapLockWrite
, &lock
);
806 IWICBitmap_Release(*bitmap
);
809 IWICBitmapLock_GetDataPointer(lock
, &size
, &buffer
);
811 hdc
= CreateCompatibleDC(0);
813 memset(&bi
, 0, sizeof(bi
));
814 bi
.bmiHeader
.biSize
= sizeof(bi
.bmiHeader
);
815 bi
.bmiHeader
.biWidth
= width
;
816 bi
.bmiHeader
.biHeight
= info
.hbmColor
? -height
: -height
* 2;
817 bi
.bmiHeader
.biPlanes
= 1;
818 bi
.bmiHeader
.biBitCount
= 32;
819 bi
.bmiHeader
.biCompression
= BI_RGB
;
825 GetDIBits(hdc
, info
.hbmColor
, 0, height
, buffer
, &bi
, DIB_RGB_COLORS
);
827 if (bm
.bmBitsPixel
== 32)
829 /* If any pixel has a non-zero alpha, ignore hbmMask */
830 bits
= (DWORD
*)buffer
;
831 for (x
= 0; x
< width
&& !has_alpha
; x
++, bits
++)
833 for (y
= 0; y
< height
; y
++)
835 if (*bits
& 0xff000000)
845 GetDIBits(hdc
, info
.hbmMask
, 0, height
, buffer
, &bi
, DIB_RGB_COLORS
);
855 mask
= HeapAlloc(GetProcessHeap(), 0, size
);
858 IWICBitmapLock_Release(lock
);
859 IWICBitmap_Release(*bitmap
);
865 /* read alpha data from the mask */
866 GetDIBits(hdc
, info
.hbmMask
, info
.hbmColor
? 0 : height
, height
, mask
, &bi
, DIB_RGB_COLORS
);
868 for (y
= 0; y
< height
; y
++)
870 rgba
= (DWORD
*)(buffer
+ y
* stride
);
871 bits
= (DWORD
*)(mask
+ y
* stride
);
873 for (x
= 0; x
< width
; x
++, rgba
++, bits
++)
882 HeapFree(GetProcessHeap(), 0, mask
);
886 /* set constant alpha of 255 */
887 for (y
= 0; y
< height
; y
++)
889 rgba
= (DWORD
*)(buffer
+ y
* stride
);
890 for (x
= 0; x
< width
; x
++, rgba
++)
897 IWICBitmapLock_Release(lock
);
901 DeleteObject(info
.hbmColor
);
902 DeleteObject(info
.hbmMask
);
907 static HRESULT WINAPI
ComponentFactory_CreateComponentEnumerator(IWICComponentFactory
*iface
,
908 DWORD componentTypes
, DWORD options
, IEnumUnknown
**ppIEnumUnknown
)
910 TRACE("(%p,%u,%u,%p)\n", iface
, componentTypes
, options
, ppIEnumUnknown
);
911 return CreateComponentEnumerator(componentTypes
, options
, ppIEnumUnknown
);
914 static HRESULT WINAPI
ComponentFactory_CreateFastMetadataEncoderFromDecoder(
915 IWICComponentFactory
*iface
, IWICBitmapDecoder
*pIDecoder
,
916 IWICFastMetadataEncoder
**ppIFastEncoder
)
918 FIXME("(%p,%p,%p): stub\n", iface
, pIDecoder
, ppIFastEncoder
);
922 static HRESULT WINAPI
ComponentFactory_CreateFastMetadataEncoderFromFrameDecode(
923 IWICComponentFactory
*iface
, IWICBitmapFrameDecode
*pIFrameDecoder
,
924 IWICFastMetadataEncoder
**ppIFastEncoder
)
926 FIXME("(%p,%p,%p): stub\n", iface
, pIFrameDecoder
, ppIFastEncoder
);
930 static HRESULT WINAPI
ComponentFactory_CreateQueryWriter(IWICComponentFactory
*iface
,
931 REFGUID guidMetadataFormat
, const GUID
*pguidVendor
,
932 IWICMetadataQueryWriter
**ppIQueryWriter
)
934 FIXME("(%p,%s,%s,%p): stub\n", iface
, debugstr_guid(guidMetadataFormat
),
935 debugstr_guid(pguidVendor
), ppIQueryWriter
);
939 static HRESULT WINAPI
ComponentFactory_CreateQueryWriterFromReader(IWICComponentFactory
*iface
,
940 IWICMetadataQueryReader
*pIQueryReader
, const GUID
*pguidVendor
,
941 IWICMetadataQueryWriter
**ppIQueryWriter
)
943 FIXME("(%p,%p,%s,%p): stub\n", iface
, pIQueryReader
, debugstr_guid(pguidVendor
),
948 static HRESULT WINAPI
ComponentFactory_CreateMetadataReader(IWICComponentFactory
*iface
,
949 REFGUID format
, const GUID
*vendor
, DWORD options
, IStream
*stream
, IWICMetadataReader
**reader
)
951 FIXME("%p,%s,%s,%x,%p,%p: stub\n", iface
, debugstr_guid(format
), debugstr_guid(vendor
),
952 options
, stream
, reader
);
956 static HRESULT WINAPI
ComponentFactory_CreateMetadataReaderFromContainer(IWICComponentFactory
*iface
,
957 REFGUID format
, const GUID
*vendor
, DWORD options
, IStream
*stream
, IWICMetadataReader
**reader
)
960 IEnumUnknown
*enumreaders
;
961 IUnknown
*unkreaderinfo
;
962 IWICMetadataReaderInfo
*readerinfo
;
963 IWICPersistStream
*wicpersiststream
;
969 TRACE("%p,%s,%s,%x,%p,%p\n", iface
, debugstr_guid(format
), debugstr_guid(vendor
),
970 options
, stream
, reader
);
972 if (!format
|| !stream
|| !reader
)
977 hr
= CreateComponentEnumerator(WICMetadataReader
, WICComponentEnumerateDefault
, &enumreaders
);
978 if (FAILED(hr
)) return hr
;
985 hr
= IEnumUnknown_Next(enumreaders
, 1, &unkreaderinfo
, &num_fetched
);
989 hr
= IUnknown_QueryInterface(unkreaderinfo
, &IID_IWICMetadataReaderInfo
, (void**)&readerinfo
);
995 hr
= IWICMetadataReaderInfo_GetVendorGUID(readerinfo
, &decoder_vendor
);
997 if (FAILED(hr
) || !IsEqualIID(vendor
, &decoder_vendor
))
999 IWICMetadataReaderInfo_Release(readerinfo
);
1000 IUnknown_Release(unkreaderinfo
);
1005 hr
= IWICMetadataReaderInfo_MatchesPattern(readerinfo
, format
, stream
, &matches
);
1007 if (SUCCEEDED(hr
) && matches
)
1009 hr
= IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
1012 hr
= IWICMetadataReaderInfo_CreateInstance(readerinfo
, reader
);
1016 hr
= IWICMetadataReader_QueryInterface(*reader
, &IID_IWICPersistStream
, (void**)&wicpersiststream
);
1020 hr
= IWICPersistStream_LoadEx(wicpersiststream
,
1021 stream
, vendor
, options
& WICPersistOptionsMask
);
1023 IWICPersistStream_Release(wicpersiststream
);
1028 IWICMetadataReader_Release(*reader
);
1034 IUnknown_Release(readerinfo
);
1037 IUnknown_Release(unkreaderinfo
);
1043 if (!*reader
&& vendor
)
1046 IEnumUnknown_Reset(enumreaders
);
1050 IEnumUnknown_Release(enumreaders
);
1052 if (!*reader
&& !(options
& WICMetadataCreationFailUnknown
))
1054 hr
= IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
1057 hr
= UnknownMetadataReader_CreateInstance(&IID_IWICMetadataReader
, (void**)reader
);
1061 hr
= IWICMetadataReader_QueryInterface(*reader
, &IID_IWICPersistStream
, (void**)&wicpersiststream
);
1065 hr
= IWICPersistStream_LoadEx(wicpersiststream
, stream
, NULL
, options
& WICPersistOptionsMask
);
1067 IWICPersistStream_Release(wicpersiststream
);
1072 IWICMetadataReader_Release(*reader
);
1081 return WINCODEC_ERR_COMPONENTNOTFOUND
;
1084 static HRESULT WINAPI
ComponentFactory_CreateMetadataWriter(IWICComponentFactory
*iface
,
1085 REFGUID format
, const GUID
*vendor
, DWORD options
, IWICMetadataWriter
**writer
)
1087 FIXME("%p,%s,%s,%x,%p: stub\n", iface
, debugstr_guid(format
), debugstr_guid(vendor
), options
, writer
);
1091 static HRESULT WINAPI
ComponentFactory_CreateMetadataWriterFromReader(IWICComponentFactory
*iface
,
1092 IWICMetadataReader
*reader
, const GUID
*vendor
, IWICMetadataWriter
**writer
)
1094 FIXME("%p,%p,%s,%p: stub\n", iface
, reader
, debugstr_guid(vendor
), writer
);
1098 static HRESULT WINAPI
ComponentFactory_CreateQueryReaderFromBlockReader(IWICComponentFactory
*iface
,
1099 IWICMetadataBlockReader
*block_reader
, IWICMetadataQueryReader
**query_reader
)
1101 FIXME("%p,%p,%p: stub\n", iface
, block_reader
, query_reader
);
1105 static HRESULT WINAPI
ComponentFactory_CreateQueryWriterFromBlockWriter(IWICComponentFactory
*iface
,
1106 IWICMetadataBlockWriter
*block_writer
, IWICMetadataQueryWriter
**query_writer
)
1108 FIXME("%p,%p,%p: stub\n", iface
, block_writer
, query_writer
);
1112 static HRESULT WINAPI
ComponentFactory_CreateEncoderPropertyBag(IWICComponentFactory
*iface
,
1113 PROPBAG2
*options
, UINT count
, IPropertyBag2
**property
)
1115 TRACE("(%p,%p,%u,%p)\n", iface
, options
, count
, property
);
1116 return CreatePropertyBag2(options
, count
, property
);
1119 static const IWICComponentFactoryVtbl ComponentFactory_Vtbl
= {
1120 ComponentFactory_QueryInterface
,
1121 ComponentFactory_AddRef
,
1122 ComponentFactory_Release
,
1123 ComponentFactory_CreateDecoderFromFilename
,
1124 ComponentFactory_CreateDecoderFromStream
,
1125 ComponentFactory_CreateDecoderFromFileHandle
,
1126 ComponentFactory_CreateComponentInfo
,
1127 ComponentFactory_CreateDecoder
,
1128 ComponentFactory_CreateEncoder
,
1129 ComponentFactory_CreatePalette
,
1130 ComponentFactory_CreateFormatConverter
,
1131 ComponentFactory_CreateBitmapScaler
,
1132 ComponentFactory_CreateBitmapClipper
,
1133 ComponentFactory_CreateBitmapFlipRotator
,
1134 ComponentFactory_CreateStream
,
1135 ComponentFactory_CreateColorContext
,
1136 ComponentFactory_CreateColorTransformer
,
1137 ComponentFactory_CreateBitmap
,
1138 ComponentFactory_CreateBitmapFromSource
,
1139 ComponentFactory_CreateBitmapFromSourceRect
,
1140 ComponentFactory_CreateBitmapFromMemory
,
1141 ComponentFactory_CreateBitmapFromHBITMAP
,
1142 ComponentFactory_CreateBitmapFromHICON
,
1143 ComponentFactory_CreateComponentEnumerator
,
1144 ComponentFactory_CreateFastMetadataEncoderFromDecoder
,
1145 ComponentFactory_CreateFastMetadataEncoderFromFrameDecode
,
1146 ComponentFactory_CreateQueryWriter
,
1147 ComponentFactory_CreateQueryWriterFromReader
,
1148 ComponentFactory_CreateMetadataReader
,
1149 ComponentFactory_CreateMetadataReaderFromContainer
,
1150 ComponentFactory_CreateMetadataWriter
,
1151 ComponentFactory_CreateMetadataWriterFromReader
,
1152 ComponentFactory_CreateQueryReaderFromBlockReader
,
1153 ComponentFactory_CreateQueryWriterFromBlockWriter
,
1154 ComponentFactory_CreateEncoderPropertyBag
1157 HRESULT
ComponentFactory_CreateInstance(REFIID iid
, void** ppv
)
1159 ComponentFactory
*This
;
1162 TRACE("(%s,%p)\n", debugstr_guid(iid
), ppv
);
1166 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(ComponentFactory
));
1167 if (!This
) return E_OUTOFMEMORY
;
1169 This
->IWICComponentFactory_iface
.lpVtbl
= &ComponentFactory_Vtbl
;
1172 ret
= IWICComponentFactory_QueryInterface(&This
->IWICComponentFactory_iface
, iid
, ppv
);
1173 IWICComponentFactory_Release(&This
->IWICComponentFactory_iface
);