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
31 #include "wincodecs_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs
);
38 IWICImagingFactory2 IWICImagingFactory2_iface
;
39 IWICComponentFactory IWICComponentFactory_iface
;
43 static inline ImagingFactory
*impl_from_IWICComponentFactory(IWICComponentFactory
*iface
)
45 return CONTAINING_RECORD(iface
, ImagingFactory
, IWICComponentFactory_iface
);
48 static inline ImagingFactory
*impl_from_IWICImagingFactory2(IWICImagingFactory2
*iface
)
50 return CONTAINING_RECORD(iface
, ImagingFactory
, IWICImagingFactory2_iface
);
53 static HRESULT WINAPI
ImagingFactory_QueryInterface(IWICImagingFactory2
*iface
, REFIID iid
,
56 ImagingFactory
*This
= impl_from_IWICImagingFactory2(iface
);
57 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
59 if (!ppv
) return E_INVALIDARG
;
61 if (IsEqualIID(&IID_IUnknown
, iid
) ||
62 IsEqualIID(&IID_IWICImagingFactory
, iid
) ||
63 IsEqualIID(&IID_IWICComponentFactory
, iid
))
65 *ppv
= &This
->IWICComponentFactory_iface
;
67 else if (IsEqualIID(&IID_IWICImagingFactory2
, iid
))
69 *ppv
= &This
->IWICImagingFactory2_iface
;
77 IUnknown_AddRef((IUnknown
*)*ppv
);
81 static ULONG WINAPI
ImagingFactory_AddRef(IWICImagingFactory2
*iface
)
83 ImagingFactory
*This
= impl_from_IWICImagingFactory2(iface
);
84 ULONG ref
= InterlockedIncrement(&This
->ref
);
86 TRACE("(%p) refcount=%lu\n", iface
, ref
);
91 static ULONG WINAPI
ImagingFactory_Release(IWICImagingFactory2
*iface
)
93 ImagingFactory
*This
= impl_from_IWICImagingFactory2(iface
);
94 ULONG ref
= InterlockedDecrement(&This
->ref
);
96 TRACE("(%p) refcount=%lu\n", iface
, ref
);
99 HeapFree(GetProcessHeap(), 0, This
);
104 static HRESULT WINAPI
ImagingFactory_CreateDecoderFromFilename(
105 IWICImagingFactory2
*iface
, LPCWSTR wzFilename
, const GUID
*pguidVendor
,
106 DWORD dwDesiredAccess
, WICDecodeOptions metadataOptions
,
107 IWICBitmapDecoder
**ppIDecoder
)
112 TRACE("(%p,%s,%s,%lu,%u,%p)\n", iface
, debugstr_w(wzFilename
),
113 debugstr_guid(pguidVendor
), dwDesiredAccess
, metadataOptions
, ppIDecoder
);
115 hr
= StreamImpl_Create(&stream
);
118 hr
= IWICStream_InitializeFromFilename(stream
, wzFilename
, dwDesiredAccess
);
122 hr
= IWICImagingFactory2_CreateDecoderFromStream(iface
, (IStream
*)stream
,
123 pguidVendor
, metadataOptions
, ppIDecoder
);
126 IWICStream_Release(stream
);
132 static HRESULT
find_decoder(IStream
*pIStream
, const GUID
*pguidVendor
,
133 WICDecodeOptions metadataOptions
, IWICBitmapDecoder
**decoder
)
135 IEnumUnknown
*enumdecoders
= NULL
;
136 IUnknown
*unkdecoderinfo
= NULL
;
138 HRESULT res
, res_wine
;
144 res
= CreateComponentEnumerator(WICDecoder
, WICComponentEnumerateDefault
, &enumdecoders
);
145 if (FAILED(res
)) return res
;
148 while (IEnumUnknown_Next(enumdecoders
, 1, &unkdecoderinfo
, &num_fetched
) == S_OK
)
150 IWICBitmapDecoderInfo
*decoderinfo
= NULL
;
151 IWICWineDecoder
*wine_decoder
= NULL
;
153 res
= IUnknown_QueryInterface(unkdecoderinfo
, &IID_IWICBitmapDecoderInfo
, (void**)&decoderinfo
);
154 if (FAILED(res
)) goto next
;
158 res
= IWICBitmapDecoderInfo_GetVendorGUID(decoderinfo
, &vendor
);
159 if (FAILED(res
) || !IsEqualIID(&vendor
, pguidVendor
)) goto next
;
162 res
= IWICBitmapDecoderInfo_MatchesPattern(decoderinfo
, pIStream
, &matches
);
163 if (FAILED(res
) || !matches
) goto next
;
165 res
= IWICBitmapDecoderInfo_CreateInstance(decoderinfo
, decoder
);
166 if (FAILED(res
)) goto next
;
168 /* FIXME: should use QueryCapability to choose a decoder */
171 res
= IWICBitmapDecoder_Initialize(*decoder
, pIStream
, metadataOptions
);
174 res_wine
= IWICBitmapDecoder_QueryInterface(*decoder
, &IID_IWICWineDecoder
, (void **)&wine_decoder
);
175 if (FAILED(res_wine
))
177 IWICBitmapDecoder_Release(*decoder
);
182 res_wine
= IWICWineDecoder_Initialize(wine_decoder
, pIStream
, metadataOptions
);
183 if (FAILED(res_wine
))
185 IWICBitmapDecoder_Release(*decoder
);
194 if (wine_decoder
) IWICWineDecoder_Release(wine_decoder
);
195 if (decoderinfo
) IWICBitmapDecoderInfo_Release(decoderinfo
);
196 IUnknown_Release(unkdecoderinfo
);
200 IEnumUnknown_Release(enumdecoders
);
201 if (!found
) res
= WINCODEC_ERR_COMPONENTNOTFOUND
;
205 static HRESULT WINAPI
ImagingFactory_CreateDecoderFromStream(
206 IWICImagingFactory2
*iface
, IStream
*pIStream
, const GUID
*pguidVendor
,
207 WICDecodeOptions metadataOptions
, IWICBitmapDecoder
**ppIDecoder
)
210 IWICBitmapDecoder
*decoder
= NULL
;
212 TRACE("(%p,%p,%s,%u,%p)\n", iface
, pIStream
, debugstr_guid(pguidVendor
),
213 metadataOptions
, ppIDecoder
);
216 res
= find_decoder(pIStream
, pguidVendor
, metadataOptions
, &decoder
);
218 res
= find_decoder(pIStream
, NULL
, metadataOptions
, &decoder
);
222 *ppIDecoder
= decoder
;
227 if (WARN_ON(wincodecs
))
233 WARN("failed to load from a stream %#lx\n", res
);
236 if (IStream_Seek(pIStream
, seek
, STREAM_SEEK_SET
, NULL
) == S_OK
)
238 if (IStream_Read(pIStream
, data
, 4, &bytesread
) == S_OK
)
239 WARN("first %li bytes of stream=%x %x %x %x\n", bytesread
, data
[0], data
[1], data
[2], data
[3]);
247 static HRESULT WINAPI
ImagingFactory_CreateDecoderFromFileHandle(
248 IWICImagingFactory2
*iface
, ULONG_PTR hFile
, const GUID
*pguidVendor
,
249 WICDecodeOptions metadataOptions
, IWICBitmapDecoder
**ppIDecoder
)
254 TRACE("(%p,%Ix,%s,%u,%p)\n", iface
, hFile
, debugstr_guid(pguidVendor
),
255 metadataOptions
, ppIDecoder
);
257 hr
= StreamImpl_Create(&stream
);
260 hr
= stream_initialize_from_filehandle(stream
, (HANDLE
)hFile
);
263 hr
= IWICImagingFactory2_CreateDecoderFromStream(iface
, (IStream
*)stream
,
264 pguidVendor
, metadataOptions
, ppIDecoder
);
266 IWICStream_Release(stream
);
271 static HRESULT WINAPI
ImagingFactory_CreateComponentInfo(IWICImagingFactory2
*iface
,
272 REFCLSID clsidComponent
, IWICComponentInfo
**ppIInfo
)
274 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(clsidComponent
), ppIInfo
);
275 return CreateComponentInfo(clsidComponent
, ppIInfo
);
278 static HRESULT WINAPI
ImagingFactory_CreateDecoder(IWICImagingFactory2
*iface
,
279 REFGUID guidContainerFormat
, const GUID
*pguidVendor
,
280 IWICBitmapDecoder
**ppIDecoder
)
282 IEnumUnknown
*enumdecoders
;
283 IUnknown
*unkdecoderinfo
;
284 IWICBitmapDecoderInfo
*decoderinfo
;
285 IWICBitmapDecoder
*decoder
= NULL
, *preferred_decoder
= NULL
;
290 TRACE("(%p,%s,%s,%p)\n", iface
, debugstr_guid(guidContainerFormat
),
291 debugstr_guid(pguidVendor
), ppIDecoder
);
293 if (!guidContainerFormat
|| !ppIDecoder
) return E_INVALIDARG
;
295 res
= CreateComponentEnumerator(WICDecoder
, WICComponentEnumerateDefault
, &enumdecoders
);
296 if (FAILED(res
)) return res
;
298 while (!preferred_decoder
)
300 res
= IEnumUnknown_Next(enumdecoders
, 1, &unkdecoderinfo
, &num_fetched
);
301 if (res
!= S_OK
) break;
303 res
= IUnknown_QueryInterface(unkdecoderinfo
, &IID_IWICBitmapDecoderInfo
, (void **)&decoderinfo
);
308 res
= IWICBitmapDecoderInfo_GetContainerFormat(decoderinfo
, &container_guid
);
309 if (SUCCEEDED(res
) && IsEqualIID(&container_guid
, guidContainerFormat
))
311 IWICBitmapDecoder
*new_decoder
;
313 res
= IWICBitmapDecoderInfo_CreateInstance(decoderinfo
, &new_decoder
);
318 res
= IWICBitmapDecoderInfo_GetVendorGUID(decoderinfo
, &vendor
);
319 if (SUCCEEDED(res
) && IsEqualIID(&vendor
, pguidVendor
))
321 preferred_decoder
= new_decoder
;
326 if (new_decoder
&& !decoder
)
328 decoder
= new_decoder
;
332 if (new_decoder
) IWICBitmapDecoder_Release(new_decoder
);
336 IWICBitmapDecoderInfo_Release(decoderinfo
);
339 IUnknown_Release(unkdecoderinfo
);
342 IEnumUnknown_Release(enumdecoders
);
344 if (preferred_decoder
)
346 *ppIDecoder
= preferred_decoder
;
347 if (decoder
) IWICBitmapDecoder_Release(decoder
);
353 *ppIDecoder
= decoder
;
358 return WINCODEC_ERR_COMPONENTNOTFOUND
;
361 static HRESULT WINAPI
ImagingFactory_CreateEncoder(IWICImagingFactory2
*iface
,
362 REFGUID guidContainerFormat
, const GUID
*pguidVendor
,
363 IWICBitmapEncoder
**ppIEncoder
)
366 IEnumUnknown
*enumencoders
;
367 IUnknown
*unkencoderinfo
;
368 IWICBitmapEncoderInfo
*encoderinfo
;
369 IWICBitmapEncoder
*encoder
=NULL
;
372 GUID actual_containerformat
;
374 TRACE("(%p,%s,%s,%p)\n", iface
, debugstr_guid(guidContainerFormat
),
375 debugstr_guid(pguidVendor
), ppIEncoder
);
377 if (pguidVendor
&& !fixme
++)
378 FIXME("ignoring vendor GUID\n");
380 res
= CreateComponentEnumerator(WICEncoder
, WICComponentEnumerateDefault
, &enumencoders
);
381 if (FAILED(res
)) return res
;
385 res
= IEnumUnknown_Next(enumencoders
, 1, &unkencoderinfo
, &num_fetched
);
389 res
= IUnknown_QueryInterface(unkencoderinfo
, &IID_IWICBitmapEncoderInfo
, (void**)&encoderinfo
);
393 res
= IWICBitmapEncoderInfo_GetContainerFormat(encoderinfo
, &actual_containerformat
);
395 if (SUCCEEDED(res
) && IsEqualGUID(guidContainerFormat
, &actual_containerformat
))
397 res
= IWICBitmapEncoderInfo_CreateInstance(encoderinfo
, &encoder
);
402 IWICBitmapEncoderInfo_Release(encoderinfo
);
405 IUnknown_Release(unkencoderinfo
);
411 IEnumUnknown_Release(enumencoders
);
415 *ppIEncoder
= encoder
;
420 WARN("failed to create encoder\n");
422 return WINCODEC_ERR_COMPONENTNOTFOUND
;
426 static HRESULT WINAPI
ImagingFactory_CreatePalette(IWICImagingFactory2
*iface
,
427 IWICPalette
**ppIPalette
)
429 TRACE("(%p,%p)\n", iface
, ppIPalette
);
430 return PaletteImpl_Create(ppIPalette
);
433 static HRESULT WINAPI
ImagingFactory_CreateFormatConverter(IWICImagingFactory2
*iface
,
434 IWICFormatConverter
**ppIFormatConverter
)
436 return FormatConverter_CreateInstance(&IID_IWICFormatConverter
, (void**)ppIFormatConverter
);
439 static HRESULT WINAPI
ImagingFactory_CreateBitmapScaler(IWICImagingFactory2
*iface
,
440 IWICBitmapScaler
**ppIBitmapScaler
)
442 TRACE("(%p,%p)\n", iface
, ppIBitmapScaler
);
444 return BitmapScaler_Create(ppIBitmapScaler
);
447 static HRESULT WINAPI
ImagingFactory_CreateBitmapClipper(IWICImagingFactory2
*iface
,
448 IWICBitmapClipper
**ppIBitmapClipper
)
450 TRACE("(%p,%p)\n", iface
, ppIBitmapClipper
);
451 return BitmapClipper_Create(ppIBitmapClipper
);
454 static HRESULT WINAPI
ImagingFactory_CreateBitmapFlipRotator(IWICImagingFactory2
*iface
,
455 IWICBitmapFlipRotator
**ppIBitmapFlipRotator
)
457 TRACE("(%p,%p)\n", iface
, ppIBitmapFlipRotator
);
458 return FlipRotator_Create(ppIBitmapFlipRotator
);
461 static HRESULT WINAPI
ImagingFactory_CreateStream(IWICImagingFactory2
*iface
,
462 IWICStream
**ppIWICStream
)
464 TRACE("(%p,%p)\n", iface
, ppIWICStream
);
465 return StreamImpl_Create(ppIWICStream
);
468 static HRESULT WINAPI
ImagingFactory_CreateColorContext(IWICImagingFactory2
*iface
,
469 IWICColorContext
**ppIColorContext
)
471 TRACE("(%p,%p)\n", iface
, ppIColorContext
);
472 return ColorContext_Create(ppIColorContext
);
475 static HRESULT WINAPI
ImagingFactory_CreateColorTransformer(IWICImagingFactory2
*iface
,
476 IWICColorTransform
**ppIColorTransform
)
478 TRACE("(%p,%p)\n", iface
, ppIColorTransform
);
479 return ColorTransform_Create(ppIColorTransform
);
482 static HRESULT WINAPI
ImagingFactory_CreateBitmap(IWICImagingFactory2
*iface
,
483 UINT uiWidth
, UINT uiHeight
, REFWICPixelFormatGUID pixelFormat
,
484 WICBitmapCreateCacheOption option
, IWICBitmap
**ppIBitmap
)
486 TRACE("(%p,%u,%u,%s,%u,%p)\n", iface
, uiWidth
, uiHeight
,
487 debugstr_guid(pixelFormat
), option
, ppIBitmap
);
488 return BitmapImpl_Create(uiWidth
, uiHeight
, 0, 0, NULL
, 0, pixelFormat
, option
, ppIBitmap
);
491 static HRESULT
create_bitmap_from_source_rect(IWICBitmapSource
*piBitmapSource
, const WICRect
*rect
,
492 WICBitmapCreateCacheOption option
, IWICBitmap
**ppIBitmap
)
495 IWICBitmapLock
*lock
;
496 IWICPalette
*palette
;
498 WICPixelFormatGUID pixelformat
= {0};
502 IWICComponentInfo
*info
;
503 IWICPixelFormatInfo2
*formatinfo
;
504 WICPixelFormatNumericRepresentation format_type
;
506 assert(!rect
|| option
== WICBitmapCacheOnLoad
);
508 if (!piBitmapSource
|| !ppIBitmap
)
511 if (option
== WICBitmapNoCache
&& SUCCEEDED(IWICBitmapSource_QueryInterface(piBitmapSource
,
512 &IID_IWICBitmap
, (void **)&result
)))
518 hr
= IWICBitmapSource_GetSize(piBitmapSource
, &width
, &height
);
520 if (SUCCEEDED(hr
) && rect
)
522 if (rect
->X
>= width
|| rect
->Y
>= height
|| rect
->Width
== 0 || rect
->Height
== 0)
525 width
= min(width
- rect
->X
, rect
->Width
);
526 height
= min(height
- rect
->Y
, rect
->Height
);
530 hr
= IWICBitmapSource_GetPixelFormat(piBitmapSource
, &pixelformat
);
533 hr
= CreateComponentInfo(&pixelformat
, &info
);
537 hr
= IWICComponentInfo_QueryInterface(info
, &IID_IWICPixelFormatInfo2
, (void**)&formatinfo
);
541 hr
= IWICPixelFormatInfo2_GetNumericRepresentation(formatinfo
, &format_type
);
543 IWICPixelFormatInfo2_Release(formatinfo
);
546 IWICComponentInfo_Release(info
);
550 hr
= BitmapImpl_Create(width
, height
, 0, 0, NULL
, 0, &pixelformat
, option
, &result
);
554 hr
= IWICBitmap_Lock(result
, NULL
, WICBitmapLockWrite
, &lock
);
557 UINT stride
, buffersize
;
570 hr
= IWICBitmapLock_GetStride(lock
, &stride
);
573 hr
= IWICBitmapLock_GetDataPointer(lock
, &buffersize
, &buffer
);
576 hr
= IWICBitmapSource_CopyPixels(piBitmapSource
, &rc
, stride
,
579 IWICBitmapLock_Release(lock
);
582 if (SUCCEEDED(hr
) && (format_type
== WICPixelFormatNumericRepresentationUnspecified
||
583 format_type
== WICPixelFormatNumericRepresentationIndexed
))
585 hr
= PaletteImpl_Create(&palette
);
589 hr
= IWICBitmapSource_CopyPalette(piBitmapSource
, palette
);
592 hr
= IWICBitmap_SetPalette(result
, palette
);
596 IWICPalette_Release(palette
);
602 hr
= IWICBitmapSource_GetResolution(piBitmapSource
, &dpix
, &dpiy
);
605 hr
= IWICBitmap_SetResolution(result
, dpix
, dpiy
);
613 IWICBitmap_Release(result
);
619 static HRESULT WINAPI
ImagingFactory_CreateBitmapFromSource(IWICImagingFactory2
*iface
,
620 IWICBitmapSource
*piBitmapSource
, WICBitmapCreateCacheOption option
,
621 IWICBitmap
**ppIBitmap
)
623 TRACE("(%p,%p,%u,%p)\n", iface
, piBitmapSource
, option
, ppIBitmap
);
625 return create_bitmap_from_source_rect(piBitmapSource
, NULL
, option
, ppIBitmap
);
628 static HRESULT WINAPI
ImagingFactory_CreateBitmapFromSourceRect(IWICImagingFactory2
*iface
,
629 IWICBitmapSource
*piBitmapSource
, UINT x
, UINT y
, UINT width
, UINT height
,
630 IWICBitmap
**ppIBitmap
)
634 TRACE("(%p,%p,%u,%u,%u,%u,%p)\n", iface
, piBitmapSource
, x
, y
, width
,
640 rect
.Height
= height
;
642 return create_bitmap_from_source_rect(piBitmapSource
, &rect
, WICBitmapCacheOnLoad
, ppIBitmap
);
645 static HRESULT WINAPI
ImagingFactory_CreateBitmapFromMemory(IWICImagingFactory2
*iface
,
646 UINT width
, UINT height
, REFWICPixelFormatGUID format
, UINT stride
,
647 UINT size
, BYTE
*buffer
, IWICBitmap
**bitmap
)
651 TRACE("(%p,%u,%u,%s,%u,%u,%p,%p\n", iface
, width
, height
,
652 debugstr_guid(format
), stride
, size
, buffer
, bitmap
);
654 if (!stride
|| !size
|| !buffer
|| !bitmap
) return E_INVALIDARG
;
656 hr
= BitmapImpl_Create(width
, height
, stride
, size
, NULL
, 0, format
, WICBitmapCacheOnLoad
, bitmap
);
659 IWICBitmapLock
*lock
;
661 hr
= IWICBitmap_Lock(*bitmap
, NULL
, WICBitmapLockWrite
, &lock
);
667 IWICBitmapLock_GetDataPointer(lock
, &buffersize
, &data
);
668 memcpy(data
, buffer
, buffersize
);
670 IWICBitmapLock_Release(lock
);
674 IWICBitmap_Release(*bitmap
);
681 static BOOL
get_16bpp_format(HBITMAP hbm
, WICPixelFormatGUID
*format
)
687 hdc
= CreateCompatibleDC(0);
689 memset(&bmh
, 0, sizeof(bmh
));
690 bmh
.bV4Size
= sizeof(bmh
);
693 bmh
.bV4V4Compression
= BI_BITFIELDS
;
694 bmh
.bV4BitCount
= 16;
696 GetDIBits(hdc
, hbm
, 0, 0, NULL
, (BITMAPINFO
*)&bmh
, DIB_RGB_COLORS
);
698 if (bmh
.bV4RedMask
== 0x7c00 &&
699 bmh
.bV4GreenMask
== 0x3e0 &&
700 bmh
.bV4BlueMask
== 0x1f)
702 *format
= GUID_WICPixelFormat16bppBGR555
;
704 else if (bmh
.bV4RedMask
== 0xf800 &&
705 bmh
.bV4GreenMask
== 0x7e0 &&
706 bmh
.bV4BlueMask
== 0x1f)
708 *format
= GUID_WICPixelFormat16bppBGR565
;
712 FIXME("unrecognized bitfields %lx,%lx,%lx\n", bmh
.bV4RedMask
,
713 bmh
.bV4GreenMask
, bmh
.bV4BlueMask
);
721 static HRESULT WINAPI
ImagingFactory_CreateBitmapFromHBITMAP(IWICImagingFactory2
*iface
,
722 HBITMAP hbm
, HPALETTE hpal
, WICBitmapAlphaChannelOption option
, IWICBitmap
**bitmap
)
726 WICPixelFormatGUID format
;
727 IWICBitmapLock
*lock
;
728 UINT size
, num_palette_entries
= 0;
729 PALETTEENTRY entry
[256];
731 TRACE("(%p,%p,%p,%u,%p)\n", iface
, hbm
, hpal
, option
, bitmap
);
733 if (!bitmap
) return E_INVALIDARG
;
735 if (GetObjectW(hbm
, sizeof(bm
), &bm
) != sizeof(bm
))
736 return WINCODEC_ERR_WIN32ERROR
;
740 num_palette_entries
= GetPaletteEntries(hpal
, 0, 256, entry
);
741 if (!num_palette_entries
)
742 return WINCODEC_ERR_WIN32ERROR
;
745 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
746 switch(bm
.bmBitsPixel
)
749 format
= GUID_WICPixelFormat1bppIndexed
;
752 format
= GUID_WICPixelFormat4bppIndexed
;
755 format
= GUID_WICPixelFormat8bppIndexed
;
758 if (!get_16bpp_format(hbm
, &format
))
762 format
= GUID_WICPixelFormat24bppBGR
;
767 case WICBitmapUseAlpha
:
768 format
= GUID_WICPixelFormat32bppBGRA
;
770 case WICBitmapUsePremultipliedAlpha
:
771 format
= GUID_WICPixelFormat32bppPBGRA
;
773 case WICBitmapIgnoreAlpha
:
774 format
= GUID_WICPixelFormat32bppBGR
;
781 format
= GUID_WICPixelFormat48bppRGB
;
784 FIXME("unsupported %d bpp\n", bm
.bmBitsPixel
);
788 hr
= BitmapImpl_Create(bm
.bmWidth
, bm
.bmHeight
, bm
.bmWidthBytes
, 0, NULL
, 0, &format
,
789 WICBitmapCacheOnLoad
, bitmap
);
790 if (hr
!= S_OK
) return hr
;
792 hr
= IWICBitmap_Lock(*bitmap
, NULL
, WICBitmapLockWrite
, &lock
);
797 char bmibuf
[FIELD_OFFSET(BITMAPINFO
, bmiColors
[256])];
798 BITMAPINFO
*bmi
= (BITMAPINFO
*)bmibuf
;
800 IWICBitmapLock_GetDataPointer(lock
, &size
, &buffer
);
802 hdc
= CreateCompatibleDC(0);
804 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
805 bmi
->bmiHeader
.biBitCount
= 0;
806 GetDIBits(hdc
, hbm
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
807 bmi
->bmiHeader
.biHeight
= -bm
.bmHeight
;
808 GetDIBits(hdc
, hbm
, 0, bm
.bmHeight
, buffer
, bmi
, DIB_RGB_COLORS
);
811 IWICBitmapLock_Release(lock
);
813 if (num_palette_entries
)
815 IWICPalette
*palette
;
816 WICColor colors
[256];
819 hr
= PaletteImpl_Create(&palette
);
822 for (i
= 0; i
< num_palette_entries
; i
++)
823 colors
[i
] = 0xff000000 | entry
[i
].peRed
<< 16 |
824 entry
[i
].peGreen
<< 8 | entry
[i
].peBlue
;
826 hr
= IWICPalette_InitializeCustom(palette
, colors
, num_palette_entries
);
828 hr
= IWICBitmap_SetPalette(*bitmap
, palette
);
830 IWICPalette_Release(palette
);
837 IWICBitmap_Release(*bitmap
);
844 static HRESULT WINAPI
ImagingFactory_CreateBitmapFromHICON(IWICImagingFactory2
*iface
,
845 HICON hicon
, IWICBitmap
**bitmap
)
847 IWICBitmapLock
*lock
;
850 int width
, height
, x
, y
;
859 TRACE("(%p,%p,%p)\n", iface
, hicon
, bitmap
);
861 if (!bitmap
) return E_INVALIDARG
;
863 if (!GetIconInfo(hicon
, &info
))
864 return HRESULT_FROM_WIN32(GetLastError());
866 GetObjectW(info
.hbmColor
? info
.hbmColor
: info
.hbmMask
, sizeof(bm
), &bm
);
869 height
= info
.hbmColor
? abs(bm
.bmHeight
) : abs(bm
.bmHeight
) / 2;
871 size
= stride
* height
;
873 hr
= BitmapImpl_Create(width
, height
, stride
, size
, NULL
, 0,
874 &GUID_WICPixelFormat32bppBGRA
, WICBitmapCacheOnLoad
, bitmap
);
875 if (hr
!= S_OK
) goto failed
;
877 hr
= IWICBitmap_Lock(*bitmap
, NULL
, WICBitmapLockWrite
, &lock
);
880 IWICBitmap_Release(*bitmap
);
883 IWICBitmapLock_GetDataPointer(lock
, &size
, &buffer
);
885 hdc
= CreateCompatibleDC(0);
887 memset(&bi
, 0, sizeof(bi
));
888 bi
.bmiHeader
.biSize
= sizeof(bi
.bmiHeader
);
889 bi
.bmiHeader
.biWidth
= width
;
890 bi
.bmiHeader
.biHeight
= info
.hbmColor
? -height
: -height
* 2;
891 bi
.bmiHeader
.biPlanes
= 1;
892 bi
.bmiHeader
.biBitCount
= 32;
893 bi
.bmiHeader
.biCompression
= BI_RGB
;
899 GetDIBits(hdc
, info
.hbmColor
, 0, height
, buffer
, &bi
, DIB_RGB_COLORS
);
901 if (bm
.bmBitsPixel
== 32)
903 /* If any pixel has a non-zero alpha, ignore hbmMask */
904 DWORD
*ptr
= (DWORD
*)buffer
;
905 DWORD
*end
= ptr
+ width
* height
;
908 if (*ptr
++ & 0xff000000)
917 GetDIBits(hdc
, info
.hbmMask
, 0, height
, buffer
, &bi
, DIB_RGB_COLORS
);
927 mask
= HeapAlloc(GetProcessHeap(), 0, size
);
930 IWICBitmapLock_Release(lock
);
931 IWICBitmap_Release(*bitmap
);
937 /* read alpha data from the mask */
938 GetDIBits(hdc
, info
.hbmMask
, info
.hbmColor
? 0 : height
, height
, mask
, &bi
, DIB_RGB_COLORS
);
940 for (y
= 0; y
< height
; y
++)
942 rgba
= (DWORD
*)(buffer
+ y
* stride
);
943 bits
= (DWORD
*)(mask
+ y
* stride
);
945 for (x
= 0; x
< width
; x
++, rgba
++, bits
++)
954 HeapFree(GetProcessHeap(), 0, mask
);
958 /* set constant alpha of 255 */
959 for (y
= 0; y
< height
; y
++)
961 rgba
= (DWORD
*)(buffer
+ y
* stride
);
962 for (x
= 0; x
< width
; x
++, rgba
++)
969 IWICBitmapLock_Release(lock
);
973 DeleteObject(info
.hbmColor
);
974 DeleteObject(info
.hbmMask
);
979 static HRESULT WINAPI
ImagingFactory_CreateComponentEnumerator(IWICImagingFactory2
*iface
,
980 DWORD componentTypes
, DWORD options
, IEnumUnknown
**ppIEnumUnknown
)
982 TRACE("(%p,%lu,%lu,%p)\n", iface
, componentTypes
, options
, ppIEnumUnknown
);
983 return CreateComponentEnumerator(componentTypes
, options
, ppIEnumUnknown
);
986 static HRESULT WINAPI
ImagingFactory_CreateFastMetadataEncoderFromDecoder(
987 IWICImagingFactory2
*iface
, IWICBitmapDecoder
*pIDecoder
,
988 IWICFastMetadataEncoder
**ppIFastEncoder
)
990 FIXME("(%p,%p,%p): stub\n", iface
, pIDecoder
, ppIFastEncoder
);
994 static HRESULT WINAPI
ImagingFactory_CreateFastMetadataEncoderFromFrameDecode(
995 IWICImagingFactory2
*iface
, IWICBitmapFrameDecode
*pIFrameDecoder
,
996 IWICFastMetadataEncoder
**ppIFastEncoder
)
998 FIXME("(%p,%p,%p): stub\n", iface
, pIFrameDecoder
, ppIFastEncoder
);
1002 static HRESULT WINAPI
ImagingFactory_CreateQueryWriter(IWICImagingFactory2
*iface
,
1003 REFGUID guidMetadataFormat
, const GUID
*pguidVendor
,
1004 IWICMetadataQueryWriter
**ppIQueryWriter
)
1006 FIXME("(%p,%s,%s,%p): stub\n", iface
, debugstr_guid(guidMetadataFormat
),
1007 debugstr_guid(pguidVendor
), ppIQueryWriter
);
1011 static HRESULT WINAPI
ImagingFactory_CreateQueryWriterFromReader(IWICImagingFactory2
*iface
,
1012 IWICMetadataQueryReader
*pIQueryReader
, const GUID
*pguidVendor
,
1013 IWICMetadataQueryWriter
**ppIQueryWriter
)
1015 FIXME("(%p,%p,%s,%p): stub\n", iface
, pIQueryReader
, debugstr_guid(pguidVendor
),
1020 static HRESULT WINAPI
ImagingFactory_CreateImageEncoder(IWICImagingFactory2
*iface
, ID2D1Device
*device
, IWICImageEncoder
**encoder
)
1022 FIXME("%p,%p,%p stub.\n", iface
, device
, encoder
);
1026 static const IWICImagingFactory2Vtbl ImagingFactory_Vtbl
= {
1027 ImagingFactory_QueryInterface
,
1028 ImagingFactory_AddRef
,
1029 ImagingFactory_Release
,
1030 ImagingFactory_CreateDecoderFromFilename
,
1031 ImagingFactory_CreateDecoderFromStream
,
1032 ImagingFactory_CreateDecoderFromFileHandle
,
1033 ImagingFactory_CreateComponentInfo
,
1034 ImagingFactory_CreateDecoder
,
1035 ImagingFactory_CreateEncoder
,
1036 ImagingFactory_CreatePalette
,
1037 ImagingFactory_CreateFormatConverter
,
1038 ImagingFactory_CreateBitmapScaler
,
1039 ImagingFactory_CreateBitmapClipper
,
1040 ImagingFactory_CreateBitmapFlipRotator
,
1041 ImagingFactory_CreateStream
,
1042 ImagingFactory_CreateColorContext
,
1043 ImagingFactory_CreateColorTransformer
,
1044 ImagingFactory_CreateBitmap
,
1045 ImagingFactory_CreateBitmapFromSource
,
1046 ImagingFactory_CreateBitmapFromSourceRect
,
1047 ImagingFactory_CreateBitmapFromMemory
,
1048 ImagingFactory_CreateBitmapFromHBITMAP
,
1049 ImagingFactory_CreateBitmapFromHICON
,
1050 ImagingFactory_CreateComponentEnumerator
,
1051 ImagingFactory_CreateFastMetadataEncoderFromDecoder
,
1052 ImagingFactory_CreateFastMetadataEncoderFromFrameDecode
,
1053 ImagingFactory_CreateQueryWriter
,
1054 ImagingFactory_CreateQueryWriterFromReader
,
1055 ImagingFactory_CreateImageEncoder
,
1058 static HRESULT WINAPI
ComponentFactory_QueryInterface(IWICComponentFactory
*iface
, REFIID iid
, void **ppv
)
1060 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1061 return IWICImagingFactory2_QueryInterface(&This
->IWICImagingFactory2_iface
, iid
, ppv
);
1064 static ULONG WINAPI
ComponentFactory_AddRef(IWICComponentFactory
*iface
)
1066 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1067 return IWICImagingFactory2_AddRef(&This
->IWICImagingFactory2_iface
);
1070 static ULONG WINAPI
ComponentFactory_Release(IWICComponentFactory
*iface
)
1072 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1073 return IWICImagingFactory2_Release(&This
->IWICImagingFactory2_iface
);
1076 static HRESULT WINAPI
ComponentFactory_CreateDecoderFromFilename(IWICComponentFactory
*iface
, LPCWSTR filename
,
1077 const GUID
*vendor
, DWORD desired_access
, WICDecodeOptions options
, IWICBitmapDecoder
**decoder
)
1079 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1080 return IWICImagingFactory2_CreateDecoderFromFilename(&This
->IWICImagingFactory2_iface
, filename
, vendor
,
1081 desired_access
, options
, decoder
);
1084 static HRESULT WINAPI
ComponentFactory_CreateDecoderFromStream(IWICComponentFactory
*iface
, IStream
*stream
,
1085 const GUID
*vendor
, WICDecodeOptions options
, IWICBitmapDecoder
**decoder
)
1087 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1088 return IWICImagingFactory2_CreateDecoderFromStream(&This
->IWICImagingFactory2_iface
, stream
, vendor
,
1092 static HRESULT WINAPI
ComponentFactory_CreateDecoderFromFileHandle(IWICComponentFactory
*iface
, ULONG_PTR hFile
,
1093 const GUID
*vendor
, WICDecodeOptions options
, IWICBitmapDecoder
**decoder
)
1095 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1096 return IWICImagingFactory2_CreateDecoderFromFileHandle(&This
->IWICImagingFactory2_iface
, hFile
, vendor
,
1100 static HRESULT WINAPI
ComponentFactory_CreateComponentInfo(IWICComponentFactory
*iface
, REFCLSID component
,
1101 IWICComponentInfo
**info
)
1103 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1104 return IWICImagingFactory2_CreateComponentInfo(&This
->IWICImagingFactory2_iface
, component
, info
);
1107 static HRESULT WINAPI
ComponentFactory_CreateDecoder(IWICComponentFactory
*iface
, REFGUID format
, const GUID
*vendor
,
1108 IWICBitmapDecoder
**decoder
)
1110 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1111 return IWICImagingFactory2_CreateDecoder(&This
->IWICImagingFactory2_iface
, format
, vendor
, decoder
);
1114 static HRESULT WINAPI
ComponentFactory_CreateEncoder(IWICComponentFactory
*iface
, REFGUID format
, const GUID
*vendor
,
1115 IWICBitmapEncoder
**encoder
)
1117 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1118 return IWICImagingFactory2_CreateEncoder(&This
->IWICImagingFactory2_iface
, format
, vendor
, encoder
);
1121 static HRESULT WINAPI
ComponentFactory_CreatePalette(IWICComponentFactory
*iface
, IWICPalette
**palette
)
1123 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1124 return IWICImagingFactory2_CreatePalette(&This
->IWICImagingFactory2_iface
, palette
);
1127 static HRESULT WINAPI
ComponentFactory_CreateFormatConverter(IWICComponentFactory
*iface
, IWICFormatConverter
**converter
)
1129 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1130 return IWICImagingFactory2_CreateFormatConverter(&This
->IWICImagingFactory2_iface
, converter
);
1133 static HRESULT WINAPI
ComponentFactory_CreateBitmapScaler(IWICComponentFactory
*iface
, IWICBitmapScaler
**scaler
)
1135 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1136 return IWICImagingFactory2_CreateBitmapScaler(&This
->IWICImagingFactory2_iface
, scaler
);
1139 static HRESULT WINAPI
ComponentFactory_CreateBitmapClipper(IWICComponentFactory
*iface
, IWICBitmapClipper
**clipper
)
1141 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1142 return IWICImagingFactory2_CreateBitmapClipper(&This
->IWICImagingFactory2_iface
, clipper
);
1145 static HRESULT WINAPI
ComponentFactory_CreateBitmapFlipRotator(IWICComponentFactory
*iface
, IWICBitmapFlipRotator
**fliprotator
)
1147 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1148 return IWICImagingFactory2_CreateBitmapFlipRotator(&This
->IWICImagingFactory2_iface
, fliprotator
);
1151 static HRESULT WINAPI
ComponentFactory_CreateStream(IWICComponentFactory
*iface
, IWICStream
**stream
)
1153 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1154 return IWICImagingFactory2_CreateStream(&This
->IWICImagingFactory2_iface
, stream
);
1157 static HRESULT WINAPI
ComponentFactory_CreateColorContext(IWICComponentFactory
*iface
, IWICColorContext
**context
)
1159 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1160 return IWICImagingFactory2_CreateColorContext(&This
->IWICImagingFactory2_iface
, context
);
1163 static HRESULT WINAPI
ComponentFactory_CreateColorTransformer(IWICComponentFactory
*iface
, IWICColorTransform
**transformer
)
1165 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1166 return IWICImagingFactory2_CreateColorTransformer(&This
->IWICImagingFactory2_iface
, transformer
);
1169 static HRESULT WINAPI
ComponentFactory_CreateBitmap(IWICComponentFactory
*iface
, UINT width
, UINT height
, REFWICPixelFormatGUID pixel_format
,
1170 WICBitmapCreateCacheOption option
, IWICBitmap
**bitmap
)
1172 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1173 return IWICImagingFactory2_CreateBitmap(&This
->IWICImagingFactory2_iface
, width
, height
, pixel_format
, option
, bitmap
);
1176 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromSource(IWICComponentFactory
*iface
, IWICBitmapSource
*source
,
1177 WICBitmapCreateCacheOption option
, IWICBitmap
**bitmap
)
1179 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1180 return IWICImagingFactory2_CreateBitmapFromSource(&This
->IWICImagingFactory2_iface
, source
, option
, bitmap
);
1183 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromSourceRect(IWICComponentFactory
*iface
, IWICBitmapSource
*source
,
1184 UINT x
, UINT y
, UINT width
, UINT height
, IWICBitmap
**bitmap
)
1186 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1187 return IWICImagingFactory2_CreateBitmapFromSourceRect(&This
->IWICImagingFactory2_iface
, source
, x
, y
, width
, height
, bitmap
);
1190 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromMemory(IWICComponentFactory
*iface
, UINT width
, UINT height
,
1191 REFWICPixelFormatGUID format
, UINT stride
, UINT size
, BYTE
*buffer
, IWICBitmap
**bitmap
)
1193 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1194 return IWICImagingFactory2_CreateBitmapFromMemory(&This
->IWICImagingFactory2_iface
, width
, height
, format
, stride
,
1195 size
, buffer
, bitmap
);
1198 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromHBITMAP(IWICComponentFactory
*iface
, HBITMAP hbm
, HPALETTE hpal
,
1199 WICBitmapAlphaChannelOption option
, IWICBitmap
**bitmap
)
1201 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1202 return IWICImagingFactory2_CreateBitmapFromHBITMAP(&This
->IWICImagingFactory2_iface
, hbm
, hpal
, option
, bitmap
);
1205 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromHICON(IWICComponentFactory
*iface
, HICON hicon
, IWICBitmap
**bitmap
)
1207 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1208 return IWICImagingFactory2_CreateBitmapFromHICON(&This
->IWICImagingFactory2_iface
, hicon
, bitmap
);
1211 static HRESULT WINAPI
ComponentFactory_CreateComponentEnumerator(IWICComponentFactory
*iface
, DWORD component_types
,
1212 DWORD options
, IEnumUnknown
**enumerator
)
1214 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1215 return IWICImagingFactory2_CreateComponentEnumerator(&This
->IWICImagingFactory2_iface
, component_types
,
1216 options
, enumerator
);
1219 static HRESULT WINAPI
ComponentFactory_CreateFastMetadataEncoderFromDecoder(IWICComponentFactory
*iface
, IWICBitmapDecoder
*decoder
,
1220 IWICFastMetadataEncoder
**encoder
)
1222 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1223 return IWICImagingFactory2_CreateFastMetadataEncoderFromDecoder(&This
->IWICImagingFactory2_iface
, decoder
, encoder
);
1226 static HRESULT WINAPI
ComponentFactory_CreateFastMetadataEncoderFromFrameDecode(IWICComponentFactory
*iface
,
1227 IWICBitmapFrameDecode
*frame_decode
, IWICFastMetadataEncoder
**encoder
)
1229 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1230 return IWICImagingFactory2_CreateFastMetadataEncoderFromFrameDecode(&This
->IWICImagingFactory2_iface
, frame_decode
, encoder
);
1233 static HRESULT WINAPI
ComponentFactory_CreateQueryWriter(IWICComponentFactory
*iface
, REFGUID format
, const GUID
*vendor
,
1234 IWICMetadataQueryWriter
**writer
)
1236 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1237 return IWICImagingFactory2_CreateQueryWriter(&This
->IWICImagingFactory2_iface
, format
, vendor
, writer
);
1240 static HRESULT WINAPI
ComponentFactory_CreateQueryWriterFromReader(IWICComponentFactory
*iface
, IWICMetadataQueryReader
*reader
,
1241 const GUID
*vendor
, IWICMetadataQueryWriter
**writer
)
1243 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1244 return IWICImagingFactory2_CreateQueryWriterFromReader(&This
->IWICImagingFactory2_iface
, reader
, vendor
, writer
);
1247 static HRESULT WINAPI
ComponentFactory_CreateMetadataReader(IWICComponentFactory
*iface
,
1248 REFGUID format
, const GUID
*vendor
, DWORD options
, IStream
*stream
, IWICMetadataReader
**reader
)
1250 FIXME("%p,%s,%s,%lx,%p,%p: stub\n", iface
, debugstr_guid(format
), debugstr_guid(vendor
),
1251 options
, stream
, reader
);
1255 static HRESULT WINAPI
ComponentFactory_CreateMetadataReaderFromContainer(IWICComponentFactory
*iface
,
1256 REFGUID format
, const GUID
*vendor
, DWORD options
, IStream
*stream
, IWICMetadataReader
**reader
)
1259 IEnumUnknown
*enumreaders
;
1260 IUnknown
*unkreaderinfo
;
1261 IWICMetadataReaderInfo
*readerinfo
;
1262 IWICPersistStream
*wicpersiststream
;
1264 GUID decoder_vendor
;
1268 TRACE("%p,%s,%s,%lx,%p,%p\n", iface
, debugstr_guid(format
), debugstr_guid(vendor
),
1269 options
, stream
, reader
);
1271 if (!format
|| !stream
|| !reader
)
1272 return E_INVALIDARG
;
1276 hr
= CreateComponentEnumerator(WICMetadataReader
, WICComponentEnumerateDefault
, &enumreaders
);
1277 if (FAILED(hr
)) return hr
;
1284 hr
= IEnumUnknown_Next(enumreaders
, 1, &unkreaderinfo
, &num_fetched
);
1288 hr
= IUnknown_QueryInterface(unkreaderinfo
, &IID_IWICMetadataReaderInfo
, (void**)&readerinfo
);
1294 hr
= IWICMetadataReaderInfo_GetVendorGUID(readerinfo
, &decoder_vendor
);
1296 if (FAILED(hr
) || !IsEqualIID(vendor
, &decoder_vendor
))
1298 IWICMetadataReaderInfo_Release(readerinfo
);
1299 IUnknown_Release(unkreaderinfo
);
1304 hr
= IWICMetadataReaderInfo_MatchesPattern(readerinfo
, format
, stream
, &matches
);
1306 if (SUCCEEDED(hr
) && matches
)
1308 hr
= IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
1311 hr
= IWICMetadataReaderInfo_CreateInstance(readerinfo
, reader
);
1315 hr
= IWICMetadataReader_QueryInterface(*reader
, &IID_IWICPersistStream
, (void**)&wicpersiststream
);
1319 hr
= IWICPersistStream_LoadEx(wicpersiststream
,
1320 stream
, vendor
, options
& WICPersistOptionMask
);
1322 IWICPersistStream_Release(wicpersiststream
);
1327 IWICMetadataReader_Release(*reader
);
1333 IUnknown_Release(readerinfo
);
1336 IUnknown_Release(unkreaderinfo
);
1342 if (!*reader
&& vendor
)
1345 IEnumUnknown_Reset(enumreaders
);
1349 IEnumUnknown_Release(enumreaders
);
1351 if (!*reader
&& !(options
& WICMetadataCreationFailUnknown
))
1353 hr
= IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
1356 hr
= UnknownMetadataReader_CreateInstance(&IID_IWICMetadataReader
, (void**)reader
);
1360 hr
= IWICMetadataReader_QueryInterface(*reader
, &IID_IWICPersistStream
, (void**)&wicpersiststream
);
1364 hr
= IWICPersistStream_LoadEx(wicpersiststream
, stream
, NULL
, options
& WICPersistOptionMask
);
1366 IWICPersistStream_Release(wicpersiststream
);
1371 IWICMetadataReader_Release(*reader
);
1380 return WINCODEC_ERR_COMPONENTNOTFOUND
;
1383 static HRESULT WINAPI
ComponentFactory_CreateMetadataWriter(IWICComponentFactory
*iface
,
1384 REFGUID format
, const GUID
*vendor
, DWORD options
, IWICMetadataWriter
**writer
)
1386 FIXME("%p,%s,%s,%lx,%p: stub\n", iface
, debugstr_guid(format
), debugstr_guid(vendor
), options
, writer
);
1390 static HRESULT WINAPI
ComponentFactory_CreateMetadataWriterFromReader(IWICComponentFactory
*iface
,
1391 IWICMetadataReader
*reader
, const GUID
*vendor
, IWICMetadataWriter
**writer
)
1393 FIXME("%p,%p,%s,%p: stub\n", iface
, reader
, debugstr_guid(vendor
), writer
);
1397 static HRESULT WINAPI
ComponentFactory_CreateQueryReaderFromBlockReader(IWICComponentFactory
*iface
,
1398 IWICMetadataBlockReader
*block_reader
, IWICMetadataQueryReader
**query_reader
)
1400 TRACE("%p,%p,%p\n", iface
, block_reader
, query_reader
);
1402 if (!block_reader
|| !query_reader
)
1403 return E_INVALIDARG
;
1405 return MetadataQueryReader_CreateInstance(block_reader
, NULL
, query_reader
);
1408 static HRESULT WINAPI
ComponentFactory_CreateQueryWriterFromBlockWriter(IWICComponentFactory
*iface
,
1409 IWICMetadataBlockWriter
*block_writer
, IWICMetadataQueryWriter
**query_writer
)
1411 TRACE("%p,%p,%p\n", iface
, block_writer
, query_writer
);
1413 if (!block_writer
|| !query_writer
)
1414 return E_INVALIDARG
;
1416 return MetadataQueryWriter_CreateInstance(block_writer
, NULL
, query_writer
);
1419 static HRESULT WINAPI
ComponentFactory_CreateEncoderPropertyBag(IWICComponentFactory
*iface
,
1420 PROPBAG2
*options
, UINT count
, IPropertyBag2
**property
)
1422 TRACE("(%p,%p,%u,%p)\n", iface
, options
, count
, property
);
1423 return CreatePropertyBag2(options
, count
, property
);
1426 static const IWICComponentFactoryVtbl ComponentFactory_Vtbl
= {
1427 ComponentFactory_QueryInterface
,
1428 ComponentFactory_AddRef
,
1429 ComponentFactory_Release
,
1430 ComponentFactory_CreateDecoderFromFilename
,
1431 ComponentFactory_CreateDecoderFromStream
,
1432 ComponentFactory_CreateDecoderFromFileHandle
,
1433 ComponentFactory_CreateComponentInfo
,
1434 ComponentFactory_CreateDecoder
,
1435 ComponentFactory_CreateEncoder
,
1436 ComponentFactory_CreatePalette
,
1437 ComponentFactory_CreateFormatConverter
,
1438 ComponentFactory_CreateBitmapScaler
,
1439 ComponentFactory_CreateBitmapClipper
,
1440 ComponentFactory_CreateBitmapFlipRotator
,
1441 ComponentFactory_CreateStream
,
1442 ComponentFactory_CreateColorContext
,
1443 ComponentFactory_CreateColorTransformer
,
1444 ComponentFactory_CreateBitmap
,
1445 ComponentFactory_CreateBitmapFromSource
,
1446 ComponentFactory_CreateBitmapFromSourceRect
,
1447 ComponentFactory_CreateBitmapFromMemory
,
1448 ComponentFactory_CreateBitmapFromHBITMAP
,
1449 ComponentFactory_CreateBitmapFromHICON
,
1450 ComponentFactory_CreateComponentEnumerator
,
1451 ComponentFactory_CreateFastMetadataEncoderFromDecoder
,
1452 ComponentFactory_CreateFastMetadataEncoderFromFrameDecode
,
1453 ComponentFactory_CreateQueryWriter
,
1454 ComponentFactory_CreateQueryWriterFromReader
,
1455 ComponentFactory_CreateMetadataReader
,
1456 ComponentFactory_CreateMetadataReaderFromContainer
,
1457 ComponentFactory_CreateMetadataWriter
,
1458 ComponentFactory_CreateMetadataWriterFromReader
,
1459 ComponentFactory_CreateQueryReaderFromBlockReader
,
1460 ComponentFactory_CreateQueryWriterFromBlockWriter
,
1461 ComponentFactory_CreateEncoderPropertyBag
1464 HRESULT
ImagingFactory_CreateInstance(REFIID iid
, void** ppv
)
1466 ImagingFactory
*This
;
1469 TRACE("(%s,%p)\n", debugstr_guid(iid
), ppv
);
1473 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1474 if (!This
) return E_OUTOFMEMORY
;
1476 This
->IWICImagingFactory2_iface
.lpVtbl
= &ImagingFactory_Vtbl
;
1477 This
->IWICComponentFactory_iface
.lpVtbl
= &ComponentFactory_Vtbl
;
1480 ret
= IWICImagingFactory2_QueryInterface(&This
->IWICImagingFactory2_iface
, iid
, ppv
);
1481 IWICImagingFactory2_Release(&This
->IWICImagingFactory2_iface
);
1486 HRESULT WINAPI
WICCreateBitmapFromSectionEx(UINT width
, UINT height
,
1487 REFWICPixelFormatGUID format
, HANDLE section
, UINT stride
,
1488 UINT offset
, WICSectionAccessLevel wicaccess
, IWICBitmap
**bitmap
)
1490 SYSTEM_INFO sysinfo
;
1491 UINT bpp
, access
, size
, view_offset
, view_size
;
1495 TRACE("%u,%u,%s,%p,%u,%u,%#x,%p\n", width
, height
, debugstr_guid(format
),
1496 section
, stride
, offset
, wicaccess
, bitmap
);
1498 if (!width
|| !height
|| !section
|| !bitmap
) return E_INVALIDARG
;
1500 hr
= get_pixelformat_bpp(format
, &bpp
);
1501 if (FAILED(hr
)) return hr
;
1505 case WICSectionAccessLevelReadWrite
:
1506 access
= FILE_MAP_READ
| FILE_MAP_WRITE
;
1509 case WICSectionAccessLevelRead
:
1510 access
= FILE_MAP_READ
;
1514 FIXME("unsupported access %#x\n", wicaccess
);
1515 return E_INVALIDARG
;
1518 if (!stride
) stride
= (((bpp
* width
) + 31) / 32) * 4;
1519 size
= stride
* height
;
1520 if (size
/ height
!= stride
) return E_INVALIDARG
;
1522 GetSystemInfo(&sysinfo
);
1523 view_offset
= offset
- (offset
% sysinfo
.dwAllocationGranularity
);
1524 view_size
= size
+ (offset
- view_offset
);
1526 view
= MapViewOfFile(section
, access
, 0, view_offset
, view_size
);
1527 if (!view
) return HRESULT_FROM_WIN32(GetLastError());
1529 offset
-= view_offset
;
1530 hr
= BitmapImpl_Create(width
, height
, stride
, 0, view
, offset
, format
, WICBitmapCacheOnLoad
, bitmap
);
1531 if (FAILED(hr
)) UnmapViewOfFile(view
);
1535 HRESULT WINAPI
WICCreateBitmapFromSection(UINT width
, UINT height
,
1536 REFWICPixelFormatGUID format
, HANDLE section
,
1537 UINT stride
, UINT offset
, IWICBitmap
**bitmap
)
1539 TRACE("%u,%u,%s,%p,%u,%u,%p\n", width
, height
, debugstr_guid(format
),
1540 section
, stride
, offset
, bitmap
);
1542 return WICCreateBitmapFromSectionEx(width
, height
, format
, section
,
1543 stride
, offset
, WICSectionAccessLevelRead
, bitmap
);