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
33 #include "wincodecs_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs
);
40 IWICImagingFactory2 IWICImagingFactory2_iface
;
41 IWICComponentFactory IWICComponentFactory_iface
;
45 static inline ImagingFactory
*impl_from_IWICComponentFactory(IWICComponentFactory
*iface
)
47 return CONTAINING_RECORD(iface
, ImagingFactory
, IWICComponentFactory_iface
);
50 static inline ImagingFactory
*impl_from_IWICImagingFactory2(IWICImagingFactory2
*iface
)
52 return CONTAINING_RECORD(iface
, ImagingFactory
, IWICImagingFactory2_iface
);
55 static HRESULT WINAPI
ImagingFactory_QueryInterface(IWICImagingFactory2
*iface
, REFIID iid
,
58 ImagingFactory
*This
= impl_from_IWICImagingFactory2(iface
);
59 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
61 if (!ppv
) return E_INVALIDARG
;
63 if (IsEqualIID(&IID_IUnknown
, iid
) ||
64 IsEqualIID(&IID_IWICImagingFactory
, iid
) ||
65 IsEqualIID(&IID_IWICComponentFactory
, iid
))
67 *ppv
= &This
->IWICComponentFactory_iface
;
69 else if (IsEqualIID(&IID_IWICImagingFactory2
, iid
))
71 *ppv
= &This
->IWICImagingFactory2_iface
;
79 IUnknown_AddRef((IUnknown
*)*ppv
);
83 static ULONG WINAPI
ImagingFactory_AddRef(IWICImagingFactory2
*iface
)
85 ImagingFactory
*This
= impl_from_IWICImagingFactory2(iface
);
86 ULONG ref
= InterlockedIncrement(&This
->ref
);
88 TRACE("(%p) refcount=%u\n", iface
, ref
);
93 static ULONG WINAPI
ImagingFactory_Release(IWICImagingFactory2
*iface
)
95 ImagingFactory
*This
= impl_from_IWICImagingFactory2(iface
);
96 ULONG ref
= InterlockedDecrement(&This
->ref
);
98 TRACE("(%p) refcount=%u\n", iface
, ref
);
101 HeapFree(GetProcessHeap(), 0, This
);
106 static HRESULT WINAPI
ImagingFactory_CreateDecoderFromFilename(
107 IWICImagingFactory2
*iface
, LPCWSTR wzFilename
, const GUID
*pguidVendor
,
108 DWORD dwDesiredAccess
, WICDecodeOptions metadataOptions
,
109 IWICBitmapDecoder
**ppIDecoder
)
114 TRACE("(%p,%s,%s,%u,%u,%p)\n", iface
, debugstr_w(wzFilename
),
115 debugstr_guid(pguidVendor
), dwDesiredAccess
, metadataOptions
, ppIDecoder
);
117 hr
= StreamImpl_Create(&stream
);
120 hr
= IWICStream_InitializeFromFilename(stream
, wzFilename
, dwDesiredAccess
);
124 hr
= IWICImagingFactory2_CreateDecoderFromStream(iface
, (IStream
*)stream
,
125 pguidVendor
, metadataOptions
, ppIDecoder
);
128 IWICStream_Release(stream
);
134 static HRESULT
find_decoder(IStream
*pIStream
, const GUID
*pguidVendor
,
135 WICDecodeOptions metadataOptions
, IWICBitmapDecoder
**decoder
)
137 IEnumUnknown
*enumdecoders
;
138 IUnknown
*unkdecoderinfo
;
139 IWICBitmapDecoderInfo
*decoderinfo
;
147 res
= CreateComponentEnumerator(WICDecoder
, WICComponentEnumerateDefault
, &enumdecoders
);
148 if (FAILED(res
)) return res
;
152 res
= IEnumUnknown_Next(enumdecoders
, 1, &unkdecoderinfo
, &num_fetched
);
156 res
= IUnknown_QueryInterface(unkdecoderinfo
, &IID_IWICBitmapDecoderInfo
, (void**)&decoderinfo
);
162 res
= IWICBitmapDecoderInfo_GetVendorGUID(decoderinfo
, &vendor
);
163 if (FAILED(res
) || !IsEqualIID(&vendor
, pguidVendor
))
165 IWICBitmapDecoderInfo_Release(decoderinfo
);
166 IUnknown_Release(unkdecoderinfo
);
171 res
= IWICBitmapDecoderInfo_MatchesPattern(decoderinfo
, pIStream
, &matches
);
173 if (SUCCEEDED(res
) && matches
)
175 res
= IWICBitmapDecoderInfo_CreateInstance(decoderinfo
, decoder
);
177 /* FIXME: should use QueryCapability to choose a decoder */
181 res
= IWICBitmapDecoder_Initialize(*decoder
, pIStream
, metadataOptions
);
185 IWICBitmapDecoder_Release(*decoder
);
186 IWICBitmapDecoderInfo_Release(decoderinfo
);
187 IUnknown_Release(unkdecoderinfo
);
188 IEnumUnknown_Release(enumdecoders
);
195 IWICBitmapDecoderInfo_Release(decoderinfo
);
198 IUnknown_Release(unkdecoderinfo
);
204 IEnumUnknown_Release(enumdecoders
);
206 return WINCODEC_ERR_COMPONENTNOTFOUND
;
209 static HRESULT WINAPI
ImagingFactory_CreateDecoderFromStream(
210 IWICImagingFactory2
*iface
, IStream
*pIStream
, const GUID
*pguidVendor
,
211 WICDecodeOptions metadataOptions
, IWICBitmapDecoder
**ppIDecoder
)
214 IWICBitmapDecoder
*decoder
= NULL
;
216 TRACE("(%p,%p,%s,%u,%p)\n", iface
, pIStream
, debugstr_guid(pguidVendor
),
217 metadataOptions
, ppIDecoder
);
220 res
= find_decoder(pIStream
, pguidVendor
, metadataOptions
, &decoder
);
222 res
= find_decoder(pIStream
, NULL
, metadataOptions
, &decoder
);
226 *ppIDecoder
= decoder
;
231 if (WARN_ON(wincodecs
))
237 WARN("failed to load from a stream %#x\n", res
);
240 if (IStream_Seek(pIStream
, seek
, STREAM_SEEK_SET
, NULL
) == S_OK
)
242 if (IStream_Read(pIStream
, data
, 4, &bytesread
) == S_OK
)
243 WARN("first %i bytes of stream=%x %x %x %x\n", bytesread
, data
[0], data
[1], data
[2], data
[3]);
251 static HRESULT WINAPI
ImagingFactory_CreateDecoderFromFileHandle(
252 IWICImagingFactory2
*iface
, ULONG_PTR hFile
, const GUID
*pguidVendor
,
253 WICDecodeOptions metadataOptions
, IWICBitmapDecoder
**ppIDecoder
)
258 TRACE("(%p,%lx,%s,%u,%p)\n", iface
, hFile
, debugstr_guid(pguidVendor
),
259 metadataOptions
, ppIDecoder
);
261 hr
= StreamImpl_Create(&stream
);
264 hr
= stream_initialize_from_filehandle(stream
, (HANDLE
)hFile
);
267 hr
= IWICImagingFactory2_CreateDecoderFromStream(iface
, (IStream
*)stream
,
268 pguidVendor
, metadataOptions
, ppIDecoder
);
270 IWICStream_Release(stream
);
275 static HRESULT WINAPI
ImagingFactory_CreateComponentInfo(IWICImagingFactory2
*iface
,
276 REFCLSID clsidComponent
, IWICComponentInfo
**ppIInfo
)
278 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(clsidComponent
), ppIInfo
);
279 return CreateComponentInfo(clsidComponent
, ppIInfo
);
282 static HRESULT WINAPI
ImagingFactory_CreateDecoder(IWICImagingFactory2
*iface
,
283 REFGUID guidContainerFormat
, const GUID
*pguidVendor
,
284 IWICBitmapDecoder
**ppIDecoder
)
286 IEnumUnknown
*enumdecoders
;
287 IUnknown
*unkdecoderinfo
;
288 IWICBitmapDecoderInfo
*decoderinfo
;
289 IWICBitmapDecoder
*decoder
= NULL
, *preferred_decoder
= NULL
;
294 TRACE("(%p,%s,%s,%p)\n", iface
, debugstr_guid(guidContainerFormat
),
295 debugstr_guid(pguidVendor
), ppIDecoder
);
297 if (!guidContainerFormat
|| !ppIDecoder
) return E_INVALIDARG
;
299 res
= CreateComponentEnumerator(WICDecoder
, WICComponentEnumerateDefault
, &enumdecoders
);
300 if (FAILED(res
)) return res
;
302 while (!preferred_decoder
)
304 res
= IEnumUnknown_Next(enumdecoders
, 1, &unkdecoderinfo
, &num_fetched
);
305 if (res
!= S_OK
) break;
307 res
= IUnknown_QueryInterface(unkdecoderinfo
, &IID_IWICBitmapDecoderInfo
, (void **)&decoderinfo
);
312 res
= IWICBitmapDecoderInfo_GetContainerFormat(decoderinfo
, &container_guid
);
313 if (SUCCEEDED(res
) && IsEqualIID(&container_guid
, guidContainerFormat
))
315 IWICBitmapDecoder
*new_decoder
;
317 res
= IWICBitmapDecoderInfo_CreateInstance(decoderinfo
, &new_decoder
);
322 res
= IWICBitmapDecoderInfo_GetVendorGUID(decoderinfo
, &vendor
);
323 if (SUCCEEDED(res
) && IsEqualIID(&vendor
, pguidVendor
))
325 preferred_decoder
= new_decoder
;
330 if (new_decoder
&& !decoder
)
332 decoder
= new_decoder
;
336 if (new_decoder
) IWICBitmapDecoder_Release(new_decoder
);
340 IWICBitmapDecoderInfo_Release(decoderinfo
);
343 IUnknown_Release(unkdecoderinfo
);
346 IEnumUnknown_Release(enumdecoders
);
348 if (preferred_decoder
)
350 *ppIDecoder
= preferred_decoder
;
351 if (decoder
) IWICBitmapDecoder_Release(decoder
);
357 *ppIDecoder
= decoder
;
362 return WINCODEC_ERR_COMPONENTNOTFOUND
;
365 static HRESULT WINAPI
ImagingFactory_CreateEncoder(IWICImagingFactory2
*iface
,
366 REFGUID guidContainerFormat
, const GUID
*pguidVendor
,
367 IWICBitmapEncoder
**ppIEncoder
)
370 IEnumUnknown
*enumencoders
;
371 IUnknown
*unkencoderinfo
;
372 IWICBitmapEncoderInfo
*encoderinfo
;
373 IWICBitmapEncoder
*encoder
=NULL
;
376 GUID actual_containerformat
;
378 TRACE("(%p,%s,%s,%p)\n", iface
, debugstr_guid(guidContainerFormat
),
379 debugstr_guid(pguidVendor
), ppIEncoder
);
381 if (pguidVendor
&& !fixme
++)
382 FIXME("ignoring vendor GUID\n");
384 res
= CreateComponentEnumerator(WICEncoder
, WICComponentEnumerateDefault
, &enumencoders
);
385 if (FAILED(res
)) return res
;
389 res
= IEnumUnknown_Next(enumencoders
, 1, &unkencoderinfo
, &num_fetched
);
393 res
= IUnknown_QueryInterface(unkencoderinfo
, &IID_IWICBitmapEncoderInfo
, (void**)&encoderinfo
);
397 res
= IWICBitmapEncoderInfo_GetContainerFormat(encoderinfo
, &actual_containerformat
);
399 if (SUCCEEDED(res
) && IsEqualGUID(guidContainerFormat
, &actual_containerformat
))
401 res
= IWICBitmapEncoderInfo_CreateInstance(encoderinfo
, &encoder
);
406 IWICBitmapEncoderInfo_Release(encoderinfo
);
409 IUnknown_Release(unkencoderinfo
);
415 IEnumUnknown_Release(enumencoders
);
419 *ppIEncoder
= encoder
;
424 WARN("failed to create encoder\n");
426 return WINCODEC_ERR_COMPONENTNOTFOUND
;
430 static HRESULT WINAPI
ImagingFactory_CreatePalette(IWICImagingFactory2
*iface
,
431 IWICPalette
**ppIPalette
)
433 TRACE("(%p,%p)\n", iface
, ppIPalette
);
434 return PaletteImpl_Create(ppIPalette
);
437 static HRESULT WINAPI
ImagingFactory_CreateFormatConverter(IWICImagingFactory2
*iface
,
438 IWICFormatConverter
**ppIFormatConverter
)
440 return FormatConverter_CreateInstance(&IID_IWICFormatConverter
, (void**)ppIFormatConverter
);
443 static HRESULT WINAPI
ImagingFactory_CreateBitmapScaler(IWICImagingFactory2
*iface
,
444 IWICBitmapScaler
**ppIBitmapScaler
)
446 TRACE("(%p,%p)\n", iface
, ppIBitmapScaler
);
448 return BitmapScaler_Create(ppIBitmapScaler
);
451 static HRESULT WINAPI
ImagingFactory_CreateBitmapClipper(IWICImagingFactory2
*iface
,
452 IWICBitmapClipper
**ppIBitmapClipper
)
454 TRACE("(%p,%p)\n", iface
, ppIBitmapClipper
);
455 return BitmapClipper_Create(ppIBitmapClipper
);
458 static HRESULT WINAPI
ImagingFactory_CreateBitmapFlipRotator(IWICImagingFactory2
*iface
,
459 IWICBitmapFlipRotator
**ppIBitmapFlipRotator
)
461 TRACE("(%p,%p)\n", iface
, ppIBitmapFlipRotator
);
462 return FlipRotator_Create(ppIBitmapFlipRotator
);
465 static HRESULT WINAPI
ImagingFactory_CreateStream(IWICImagingFactory2
*iface
,
466 IWICStream
**ppIWICStream
)
468 TRACE("(%p,%p)\n", iface
, ppIWICStream
);
469 return StreamImpl_Create(ppIWICStream
);
472 static HRESULT WINAPI
ImagingFactory_CreateColorContext(IWICImagingFactory2
*iface
,
473 IWICColorContext
**ppIColorContext
)
475 TRACE("(%p,%p)\n", iface
, ppIColorContext
);
476 return ColorContext_Create(ppIColorContext
);
479 static HRESULT WINAPI
ImagingFactory_CreateColorTransformer(IWICImagingFactory2
*iface
,
480 IWICColorTransform
**ppIColorTransform
)
482 TRACE("(%p,%p)\n", iface
, ppIColorTransform
);
483 return ColorTransform_Create(ppIColorTransform
);
486 static HRESULT WINAPI
ImagingFactory_CreateBitmap(IWICImagingFactory2
*iface
,
487 UINT uiWidth
, UINT uiHeight
, REFWICPixelFormatGUID pixelFormat
,
488 WICBitmapCreateCacheOption option
, IWICBitmap
**ppIBitmap
)
490 TRACE("(%p,%u,%u,%s,%u,%p)\n", iface
, uiWidth
, uiHeight
,
491 debugstr_guid(pixelFormat
), option
, ppIBitmap
);
492 return BitmapImpl_Create(uiWidth
, uiHeight
, 0, 0, NULL
, 0, pixelFormat
, option
, ppIBitmap
);
495 static HRESULT
create_bitmap_from_source_rect(IWICBitmapSource
*piBitmapSource
, const WICRect
*rect
,
496 WICBitmapCreateCacheOption option
, IWICBitmap
**ppIBitmap
)
499 IWICBitmapLock
*lock
;
500 IWICPalette
*palette
;
502 WICPixelFormatGUID pixelformat
= {0};
506 IWICComponentInfo
*info
;
507 IWICPixelFormatInfo2
*formatinfo
;
508 WICPixelFormatNumericRepresentation format_type
;
510 assert(!rect
|| option
== WICBitmapCacheOnLoad
);
512 if (!piBitmapSource
|| !ppIBitmap
)
515 if (option
== WICBitmapNoCache
&& SUCCEEDED(IWICBitmapSource_QueryInterface(piBitmapSource
,
516 &IID_IWICBitmap
, (void **)&result
)))
522 hr
= IWICBitmapSource_GetSize(piBitmapSource
, &width
, &height
);
524 if (SUCCEEDED(hr
) && rect
)
526 if (rect
->X
>= width
|| rect
->Y
>= height
|| rect
->Width
== 0 || rect
->Height
== 0)
529 width
= min(width
- rect
->X
, rect
->Width
);
530 height
= min(height
- rect
->Y
, rect
->Height
);
534 hr
= IWICBitmapSource_GetPixelFormat(piBitmapSource
, &pixelformat
);
537 hr
= CreateComponentInfo(&pixelformat
, &info
);
541 hr
= IWICComponentInfo_QueryInterface(info
, &IID_IWICPixelFormatInfo2
, (void**)&formatinfo
);
545 hr
= IWICPixelFormatInfo2_GetNumericRepresentation(formatinfo
, &format_type
);
547 IWICPixelFormatInfo2_Release(formatinfo
);
550 IWICComponentInfo_Release(info
);
554 hr
= BitmapImpl_Create(width
, height
, 0, 0, NULL
, 0, &pixelformat
, option
, &result
);
558 hr
= IWICBitmap_Lock(result
, NULL
, WICBitmapLockWrite
, &lock
);
561 UINT stride
, buffersize
;
574 hr
= IWICBitmapLock_GetStride(lock
, &stride
);
577 hr
= IWICBitmapLock_GetDataPointer(lock
, &buffersize
, &buffer
);
580 hr
= IWICBitmapSource_CopyPixels(piBitmapSource
, &rc
, stride
,
583 IWICBitmapLock_Release(lock
);
586 if (SUCCEEDED(hr
) && (format_type
== WICPixelFormatNumericRepresentationUnspecified
||
587 format_type
== WICPixelFormatNumericRepresentationIndexed
))
589 hr
= PaletteImpl_Create(&palette
);
593 hr
= IWICBitmapSource_CopyPalette(piBitmapSource
, palette
);
596 hr
= IWICBitmap_SetPalette(result
, palette
);
600 IWICPalette_Release(palette
);
606 hr
= IWICBitmapSource_GetResolution(piBitmapSource
, &dpix
, &dpiy
);
609 hr
= IWICBitmap_SetResolution(result
, dpix
, dpiy
);
617 IWICBitmap_Release(result
);
623 static HRESULT WINAPI
ImagingFactory_CreateBitmapFromSource(IWICImagingFactory2
*iface
,
624 IWICBitmapSource
*piBitmapSource
, WICBitmapCreateCacheOption option
,
625 IWICBitmap
**ppIBitmap
)
627 TRACE("(%p,%p,%u,%p)\n", iface
, piBitmapSource
, option
, ppIBitmap
);
629 return create_bitmap_from_source_rect(piBitmapSource
, NULL
, option
, ppIBitmap
);
632 static HRESULT WINAPI
ImagingFactory_CreateBitmapFromSourceRect(IWICImagingFactory2
*iface
,
633 IWICBitmapSource
*piBitmapSource
, UINT x
, UINT y
, UINT width
, UINT height
,
634 IWICBitmap
**ppIBitmap
)
638 TRACE("(%p,%p,%u,%u,%u,%u,%p)\n", iface
, piBitmapSource
, x
, y
, width
,
644 rect
.Height
= height
;
646 return create_bitmap_from_source_rect(piBitmapSource
, &rect
, WICBitmapCacheOnLoad
, ppIBitmap
);
649 static HRESULT WINAPI
ImagingFactory_CreateBitmapFromMemory(IWICImagingFactory2
*iface
,
650 UINT width
, UINT height
, REFWICPixelFormatGUID format
, UINT stride
,
651 UINT size
, BYTE
*buffer
, IWICBitmap
**bitmap
)
655 TRACE("(%p,%u,%u,%s,%u,%u,%p,%p\n", iface
, width
, height
,
656 debugstr_guid(format
), stride
, size
, buffer
, bitmap
);
658 if (!stride
|| !size
|| !buffer
|| !bitmap
) return E_INVALIDARG
;
660 hr
= BitmapImpl_Create(width
, height
, stride
, size
, NULL
, 0, format
, WICBitmapCacheOnLoad
, bitmap
);
663 IWICBitmapLock
*lock
;
665 hr
= IWICBitmap_Lock(*bitmap
, NULL
, WICBitmapLockWrite
, &lock
);
671 IWICBitmapLock_GetDataPointer(lock
, &buffersize
, &data
);
672 memcpy(data
, buffer
, buffersize
);
674 IWICBitmapLock_Release(lock
);
678 IWICBitmap_Release(*bitmap
);
685 static BOOL
get_16bpp_format(HBITMAP hbm
, WICPixelFormatGUID
*format
)
691 hdc
= CreateCompatibleDC(0);
693 memset(&bmh
, 0, sizeof(bmh
));
694 bmh
.bV4Size
= sizeof(bmh
);
697 bmh
.bV4V4Compression
= BI_BITFIELDS
;
698 bmh
.bV4BitCount
= 16;
700 GetDIBits(hdc
, hbm
, 0, 0, NULL
, (BITMAPINFO
*)&bmh
, DIB_RGB_COLORS
);
702 if (bmh
.bV4RedMask
== 0x7c00 &&
703 bmh
.bV4GreenMask
== 0x3e0 &&
704 bmh
.bV4BlueMask
== 0x1f)
706 *format
= GUID_WICPixelFormat16bppBGR555
;
708 else if (bmh
.bV4RedMask
== 0xf800 &&
709 bmh
.bV4GreenMask
== 0x7e0 &&
710 bmh
.bV4BlueMask
== 0x1f)
712 *format
= GUID_WICPixelFormat16bppBGR565
;
716 FIXME("unrecognized bitfields %x,%x,%x\n", bmh
.bV4RedMask
,
717 bmh
.bV4GreenMask
, bmh
.bV4BlueMask
);
725 static HRESULT WINAPI
ImagingFactory_CreateBitmapFromHBITMAP(IWICImagingFactory2
*iface
,
726 HBITMAP hbm
, HPALETTE hpal
, WICBitmapAlphaChannelOption option
, IWICBitmap
**bitmap
)
730 WICPixelFormatGUID format
;
731 IWICBitmapLock
*lock
;
732 UINT size
, num_palette_entries
= 0;
733 PALETTEENTRY entry
[256];
735 TRACE("(%p,%p,%p,%u,%p)\n", iface
, hbm
, hpal
, option
, bitmap
);
737 if (!bitmap
) return E_INVALIDARG
;
739 if (GetObjectW(hbm
, sizeof(bm
), &bm
) != sizeof(bm
))
740 return WINCODEC_ERR_WIN32ERROR
;
744 num_palette_entries
= GetPaletteEntries(hpal
, 0, 256, entry
);
745 if (!num_palette_entries
)
746 return WINCODEC_ERR_WIN32ERROR
;
749 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
750 switch(bm
.bmBitsPixel
)
753 format
= GUID_WICPixelFormat1bppIndexed
;
756 format
= GUID_WICPixelFormat4bppIndexed
;
759 format
= GUID_WICPixelFormat8bppIndexed
;
762 if (!get_16bpp_format(hbm
, &format
))
766 format
= GUID_WICPixelFormat24bppBGR
;
771 case WICBitmapUseAlpha
:
772 format
= GUID_WICPixelFormat32bppBGRA
;
774 case WICBitmapUsePremultipliedAlpha
:
775 format
= GUID_WICPixelFormat32bppPBGRA
;
777 case WICBitmapIgnoreAlpha
:
778 format
= GUID_WICPixelFormat32bppBGR
;
785 format
= GUID_WICPixelFormat48bppRGB
;
788 FIXME("unsupported %d bpp\n", bm
.bmBitsPixel
);
792 hr
= BitmapImpl_Create(bm
.bmWidth
, bm
.bmHeight
, bm
.bmWidthBytes
, 0, NULL
, 0, &format
,
793 WICBitmapCacheOnLoad
, bitmap
);
794 if (hr
!= S_OK
) return hr
;
796 hr
= IWICBitmap_Lock(*bitmap
, NULL
, WICBitmapLockWrite
, &lock
);
801 char bmibuf
[FIELD_OFFSET(BITMAPINFO
, bmiColors
[256])];
802 BITMAPINFO
*bmi
= (BITMAPINFO
*)bmibuf
;
804 IWICBitmapLock_GetDataPointer(lock
, &size
, &buffer
);
806 hdc
= CreateCompatibleDC(0);
808 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
809 bmi
->bmiHeader
.biBitCount
= 0;
810 GetDIBits(hdc
, hbm
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
811 bmi
->bmiHeader
.biHeight
= -bm
.bmHeight
;
812 GetDIBits(hdc
, hbm
, 0, bm
.bmHeight
, buffer
, bmi
, DIB_RGB_COLORS
);
815 IWICBitmapLock_Release(lock
);
817 if (num_palette_entries
)
819 IWICPalette
*palette
;
820 WICColor colors
[256];
823 hr
= PaletteImpl_Create(&palette
);
826 for (i
= 0; i
< num_palette_entries
; i
++)
827 colors
[i
] = 0xff000000 | entry
[i
].peRed
<< 16 |
828 entry
[i
].peGreen
<< 8 | entry
[i
].peBlue
;
830 hr
= IWICPalette_InitializeCustom(palette
, colors
, num_palette_entries
);
832 hr
= IWICBitmap_SetPalette(*bitmap
, palette
);
834 IWICPalette_Release(palette
);
841 IWICBitmap_Release(*bitmap
);
848 static HRESULT WINAPI
ImagingFactory_CreateBitmapFromHICON(IWICImagingFactory2
*iface
,
849 HICON hicon
, IWICBitmap
**bitmap
)
851 IWICBitmapLock
*lock
;
854 int width
, height
, x
, y
;
863 TRACE("(%p,%p,%p)\n", iface
, hicon
, bitmap
);
865 if (!bitmap
) return E_INVALIDARG
;
867 if (!GetIconInfo(hicon
, &info
))
868 return HRESULT_FROM_WIN32(GetLastError());
870 GetObjectW(info
.hbmColor
? info
.hbmColor
: info
.hbmMask
, sizeof(bm
), &bm
);
873 height
= info
.hbmColor
? abs(bm
.bmHeight
) : abs(bm
.bmHeight
) / 2;
875 size
= stride
* height
;
877 hr
= BitmapImpl_Create(width
, height
, stride
, size
, NULL
, 0,
878 &GUID_WICPixelFormat32bppBGRA
, WICBitmapCacheOnLoad
, bitmap
);
879 if (hr
!= S_OK
) goto failed
;
881 hr
= IWICBitmap_Lock(*bitmap
, NULL
, WICBitmapLockWrite
, &lock
);
884 IWICBitmap_Release(*bitmap
);
887 IWICBitmapLock_GetDataPointer(lock
, &size
, &buffer
);
889 hdc
= CreateCompatibleDC(0);
891 memset(&bi
, 0, sizeof(bi
));
892 bi
.bmiHeader
.biSize
= sizeof(bi
.bmiHeader
);
893 bi
.bmiHeader
.biWidth
= width
;
894 bi
.bmiHeader
.biHeight
= info
.hbmColor
? -height
: -height
* 2;
895 bi
.bmiHeader
.biPlanes
= 1;
896 bi
.bmiHeader
.biBitCount
= 32;
897 bi
.bmiHeader
.biCompression
= BI_RGB
;
903 GetDIBits(hdc
, info
.hbmColor
, 0, height
, buffer
, &bi
, DIB_RGB_COLORS
);
905 if (bm
.bmBitsPixel
== 32)
907 /* If any pixel has a non-zero alpha, ignore hbmMask */
908 bits
= (DWORD
*)buffer
;
909 for (x
= 0; x
< width
&& !has_alpha
; x
++, bits
++)
911 for (y
= 0; y
< height
; y
++)
913 if (*bits
& 0xff000000)
923 GetDIBits(hdc
, info
.hbmMask
, 0, height
, buffer
, &bi
, DIB_RGB_COLORS
);
933 mask
= HeapAlloc(GetProcessHeap(), 0, size
);
936 IWICBitmapLock_Release(lock
);
937 IWICBitmap_Release(*bitmap
);
943 /* read alpha data from the mask */
944 GetDIBits(hdc
, info
.hbmMask
, info
.hbmColor
? 0 : height
, height
, mask
, &bi
, DIB_RGB_COLORS
);
946 for (y
= 0; y
< height
; y
++)
948 rgba
= (DWORD
*)(buffer
+ y
* stride
);
949 bits
= (DWORD
*)(mask
+ y
* stride
);
951 for (x
= 0; x
< width
; x
++, rgba
++, bits
++)
960 HeapFree(GetProcessHeap(), 0, mask
);
964 /* set constant alpha of 255 */
965 for (y
= 0; y
< height
; y
++)
967 rgba
= (DWORD
*)(buffer
+ y
* stride
);
968 for (x
= 0; x
< width
; x
++, rgba
++)
975 IWICBitmapLock_Release(lock
);
979 DeleteObject(info
.hbmColor
);
980 DeleteObject(info
.hbmMask
);
985 static HRESULT WINAPI
ImagingFactory_CreateComponentEnumerator(IWICImagingFactory2
*iface
,
986 DWORD componentTypes
, DWORD options
, IEnumUnknown
**ppIEnumUnknown
)
988 TRACE("(%p,%u,%u,%p)\n", iface
, componentTypes
, options
, ppIEnumUnknown
);
989 return CreateComponentEnumerator(componentTypes
, options
, ppIEnumUnknown
);
992 static HRESULT WINAPI
ImagingFactory_CreateFastMetadataEncoderFromDecoder(
993 IWICImagingFactory2
*iface
, IWICBitmapDecoder
*pIDecoder
,
994 IWICFastMetadataEncoder
**ppIFastEncoder
)
996 FIXME("(%p,%p,%p): stub\n", iface
, pIDecoder
, ppIFastEncoder
);
1000 static HRESULT WINAPI
ImagingFactory_CreateFastMetadataEncoderFromFrameDecode(
1001 IWICImagingFactory2
*iface
, IWICBitmapFrameDecode
*pIFrameDecoder
,
1002 IWICFastMetadataEncoder
**ppIFastEncoder
)
1004 FIXME("(%p,%p,%p): stub\n", iface
, pIFrameDecoder
, ppIFastEncoder
);
1008 static HRESULT WINAPI
ImagingFactory_CreateQueryWriter(IWICImagingFactory2
*iface
,
1009 REFGUID guidMetadataFormat
, const GUID
*pguidVendor
,
1010 IWICMetadataQueryWriter
**ppIQueryWriter
)
1012 FIXME("(%p,%s,%s,%p): stub\n", iface
, debugstr_guid(guidMetadataFormat
),
1013 debugstr_guid(pguidVendor
), ppIQueryWriter
);
1017 static HRESULT WINAPI
ImagingFactory_CreateQueryWriterFromReader(IWICImagingFactory2
*iface
,
1018 IWICMetadataQueryReader
*pIQueryReader
, const GUID
*pguidVendor
,
1019 IWICMetadataQueryWriter
**ppIQueryWriter
)
1021 FIXME("(%p,%p,%s,%p): stub\n", iface
, pIQueryReader
, debugstr_guid(pguidVendor
),
1026 static HRESULT WINAPI
ImagingFactory_CreateImageEncoder(IWICImagingFactory2
*iface
, ID2D1Device
*device
, IWICImageEncoder
**encoder
)
1028 FIXME("%p,%p,%p stub.\n", iface
, device
, encoder
);
1032 static const IWICImagingFactory2Vtbl ImagingFactory_Vtbl
= {
1033 ImagingFactory_QueryInterface
,
1034 ImagingFactory_AddRef
,
1035 ImagingFactory_Release
,
1036 ImagingFactory_CreateDecoderFromFilename
,
1037 ImagingFactory_CreateDecoderFromStream
,
1038 ImagingFactory_CreateDecoderFromFileHandle
,
1039 ImagingFactory_CreateComponentInfo
,
1040 ImagingFactory_CreateDecoder
,
1041 ImagingFactory_CreateEncoder
,
1042 ImagingFactory_CreatePalette
,
1043 ImagingFactory_CreateFormatConverter
,
1044 ImagingFactory_CreateBitmapScaler
,
1045 ImagingFactory_CreateBitmapClipper
,
1046 ImagingFactory_CreateBitmapFlipRotator
,
1047 ImagingFactory_CreateStream
,
1048 ImagingFactory_CreateColorContext
,
1049 ImagingFactory_CreateColorTransformer
,
1050 ImagingFactory_CreateBitmap
,
1051 ImagingFactory_CreateBitmapFromSource
,
1052 ImagingFactory_CreateBitmapFromSourceRect
,
1053 ImagingFactory_CreateBitmapFromMemory
,
1054 ImagingFactory_CreateBitmapFromHBITMAP
,
1055 ImagingFactory_CreateBitmapFromHICON
,
1056 ImagingFactory_CreateComponentEnumerator
,
1057 ImagingFactory_CreateFastMetadataEncoderFromDecoder
,
1058 ImagingFactory_CreateFastMetadataEncoderFromFrameDecode
,
1059 ImagingFactory_CreateQueryWriter
,
1060 ImagingFactory_CreateQueryWriterFromReader
,
1061 ImagingFactory_CreateImageEncoder
,
1064 static HRESULT WINAPI
ComponentFactory_QueryInterface(IWICComponentFactory
*iface
, REFIID iid
, void **ppv
)
1066 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1067 return IWICImagingFactory2_QueryInterface(&This
->IWICImagingFactory2_iface
, iid
, ppv
);
1070 static ULONG WINAPI
ComponentFactory_AddRef(IWICComponentFactory
*iface
)
1072 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1073 return IWICImagingFactory2_AddRef(&This
->IWICImagingFactory2_iface
);
1076 static ULONG WINAPI
ComponentFactory_Release(IWICComponentFactory
*iface
)
1078 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1079 return IWICImagingFactory2_Release(&This
->IWICImagingFactory2_iface
);
1082 static HRESULT WINAPI
ComponentFactory_CreateDecoderFromFilename(IWICComponentFactory
*iface
, LPCWSTR filename
,
1083 const GUID
*vendor
, DWORD desired_access
, WICDecodeOptions options
, IWICBitmapDecoder
**decoder
)
1085 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1086 return IWICImagingFactory2_CreateDecoderFromFilename(&This
->IWICImagingFactory2_iface
, filename
, vendor
,
1087 desired_access
, options
, decoder
);
1090 static HRESULT WINAPI
ComponentFactory_CreateDecoderFromStream(IWICComponentFactory
*iface
, IStream
*stream
,
1091 const GUID
*vendor
, WICDecodeOptions options
, IWICBitmapDecoder
**decoder
)
1093 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1094 return IWICImagingFactory2_CreateDecoderFromStream(&This
->IWICImagingFactory2_iface
, stream
, vendor
,
1098 static HRESULT WINAPI
ComponentFactory_CreateDecoderFromFileHandle(IWICComponentFactory
*iface
, ULONG_PTR hFile
,
1099 const GUID
*vendor
, WICDecodeOptions options
, IWICBitmapDecoder
**decoder
)
1101 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1102 return IWICImagingFactory2_CreateDecoderFromFileHandle(&This
->IWICImagingFactory2_iface
, hFile
, vendor
,
1106 static HRESULT WINAPI
ComponentFactory_CreateComponentInfo(IWICComponentFactory
*iface
, REFCLSID component
,
1107 IWICComponentInfo
**info
)
1109 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1110 return IWICImagingFactory2_CreateComponentInfo(&This
->IWICImagingFactory2_iface
, component
, info
);
1113 static HRESULT WINAPI
ComponentFactory_CreateDecoder(IWICComponentFactory
*iface
, REFGUID format
, const GUID
*vendor
,
1114 IWICBitmapDecoder
**decoder
)
1116 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1117 return IWICImagingFactory2_CreateDecoder(&This
->IWICImagingFactory2_iface
, format
, vendor
, decoder
);
1120 static HRESULT WINAPI
ComponentFactory_CreateEncoder(IWICComponentFactory
*iface
, REFGUID format
, const GUID
*vendor
,
1121 IWICBitmapEncoder
**encoder
)
1123 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1124 return IWICImagingFactory2_CreateEncoder(&This
->IWICImagingFactory2_iface
, format
, vendor
, encoder
);
1127 static HRESULT WINAPI
ComponentFactory_CreatePalette(IWICComponentFactory
*iface
, IWICPalette
**palette
)
1129 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1130 return IWICImagingFactory2_CreatePalette(&This
->IWICImagingFactory2_iface
, palette
);
1133 static HRESULT WINAPI
ComponentFactory_CreateFormatConverter(IWICComponentFactory
*iface
, IWICFormatConverter
**converter
)
1135 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1136 return IWICImagingFactory2_CreateFormatConverter(&This
->IWICImagingFactory2_iface
, converter
);
1139 static HRESULT WINAPI
ComponentFactory_CreateBitmapScaler(IWICComponentFactory
*iface
, IWICBitmapScaler
**scaler
)
1141 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1142 return IWICImagingFactory2_CreateBitmapScaler(&This
->IWICImagingFactory2_iface
, scaler
);
1145 static HRESULT WINAPI
ComponentFactory_CreateBitmapClipper(IWICComponentFactory
*iface
, IWICBitmapClipper
**clipper
)
1147 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1148 return IWICImagingFactory2_CreateBitmapClipper(&This
->IWICImagingFactory2_iface
, clipper
);
1151 static HRESULT WINAPI
ComponentFactory_CreateBitmapFlipRotator(IWICComponentFactory
*iface
, IWICBitmapFlipRotator
**fliprotator
)
1153 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1154 return IWICImagingFactory2_CreateBitmapFlipRotator(&This
->IWICImagingFactory2_iface
, fliprotator
);
1157 static HRESULT WINAPI
ComponentFactory_CreateStream(IWICComponentFactory
*iface
, IWICStream
**stream
)
1159 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1160 return IWICImagingFactory2_CreateStream(&This
->IWICImagingFactory2_iface
, stream
);
1163 static HRESULT WINAPI
ComponentFactory_CreateColorContext(IWICComponentFactory
*iface
, IWICColorContext
**context
)
1165 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1166 return IWICImagingFactory2_CreateColorContext(&This
->IWICImagingFactory2_iface
, context
);
1169 static HRESULT WINAPI
ComponentFactory_CreateColorTransformer(IWICComponentFactory
*iface
, IWICColorTransform
**transformer
)
1171 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1172 return IWICImagingFactory2_CreateColorTransformer(&This
->IWICImagingFactory2_iface
, transformer
);
1175 static HRESULT WINAPI
ComponentFactory_CreateBitmap(IWICComponentFactory
*iface
, UINT width
, UINT height
, REFWICPixelFormatGUID pixel_format
,
1176 WICBitmapCreateCacheOption option
, IWICBitmap
**bitmap
)
1178 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1179 return IWICImagingFactory2_CreateBitmap(&This
->IWICImagingFactory2_iface
, width
, height
, pixel_format
, option
, bitmap
);
1182 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromSource(IWICComponentFactory
*iface
, IWICBitmapSource
*source
,
1183 WICBitmapCreateCacheOption option
, IWICBitmap
**bitmap
)
1185 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1186 return IWICImagingFactory2_CreateBitmapFromSource(&This
->IWICImagingFactory2_iface
, source
, option
, bitmap
);
1189 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromSourceRect(IWICComponentFactory
*iface
, IWICBitmapSource
*source
,
1190 UINT x
, UINT y
, UINT width
, UINT height
, IWICBitmap
**bitmap
)
1192 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1193 return IWICImagingFactory2_CreateBitmapFromSourceRect(&This
->IWICImagingFactory2_iface
, source
, x
, y
, width
, height
, bitmap
);
1196 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromMemory(IWICComponentFactory
*iface
, UINT width
, UINT height
,
1197 REFWICPixelFormatGUID format
, UINT stride
, UINT size
, BYTE
*buffer
, IWICBitmap
**bitmap
)
1199 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1200 return IWICImagingFactory2_CreateBitmapFromMemory(&This
->IWICImagingFactory2_iface
, width
, height
, format
, stride
,
1201 size
, buffer
, bitmap
);
1204 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromHBITMAP(IWICComponentFactory
*iface
, HBITMAP hbm
, HPALETTE hpal
,
1205 WICBitmapAlphaChannelOption option
, IWICBitmap
**bitmap
)
1207 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1208 return IWICImagingFactory2_CreateBitmapFromHBITMAP(&This
->IWICImagingFactory2_iface
, hbm
, hpal
, option
, bitmap
);
1211 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromHICON(IWICComponentFactory
*iface
, HICON hicon
, IWICBitmap
**bitmap
)
1213 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1214 return IWICImagingFactory2_CreateBitmapFromHICON(&This
->IWICImagingFactory2_iface
, hicon
, bitmap
);
1217 static HRESULT WINAPI
ComponentFactory_CreateComponentEnumerator(IWICComponentFactory
*iface
, DWORD component_types
,
1218 DWORD options
, IEnumUnknown
**enumerator
)
1220 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1221 return IWICImagingFactory2_CreateComponentEnumerator(&This
->IWICImagingFactory2_iface
, component_types
,
1222 options
, enumerator
);
1225 static HRESULT WINAPI
ComponentFactory_CreateFastMetadataEncoderFromDecoder(IWICComponentFactory
*iface
, IWICBitmapDecoder
*decoder
,
1226 IWICFastMetadataEncoder
**encoder
)
1228 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1229 return IWICImagingFactory2_CreateFastMetadataEncoderFromDecoder(&This
->IWICImagingFactory2_iface
, decoder
, encoder
);
1232 static HRESULT WINAPI
ComponentFactory_CreateFastMetadataEncoderFromFrameDecode(IWICComponentFactory
*iface
,
1233 IWICBitmapFrameDecode
*frame_decode
, IWICFastMetadataEncoder
**encoder
)
1235 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1236 return IWICImagingFactory2_CreateFastMetadataEncoderFromFrameDecode(&This
->IWICImagingFactory2_iface
, frame_decode
, encoder
);
1239 static HRESULT WINAPI
ComponentFactory_CreateQueryWriter(IWICComponentFactory
*iface
, REFGUID format
, const GUID
*vendor
,
1240 IWICMetadataQueryWriter
**writer
)
1242 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1243 return IWICImagingFactory2_CreateQueryWriter(&This
->IWICImagingFactory2_iface
, format
, vendor
, writer
);
1246 static HRESULT WINAPI
ComponentFactory_CreateQueryWriterFromReader(IWICComponentFactory
*iface
, IWICMetadataQueryReader
*reader
,
1247 const GUID
*vendor
, IWICMetadataQueryWriter
**writer
)
1249 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1250 return IWICImagingFactory2_CreateQueryWriterFromReader(&This
->IWICImagingFactory2_iface
, reader
, vendor
, writer
);
1253 static HRESULT WINAPI
ComponentFactory_CreateMetadataReader(IWICComponentFactory
*iface
,
1254 REFGUID format
, const GUID
*vendor
, DWORD options
, IStream
*stream
, IWICMetadataReader
**reader
)
1256 FIXME("%p,%s,%s,%x,%p,%p: stub\n", iface
, debugstr_guid(format
), debugstr_guid(vendor
),
1257 options
, stream
, reader
);
1261 static HRESULT WINAPI
ComponentFactory_CreateMetadataReaderFromContainer(IWICComponentFactory
*iface
,
1262 REFGUID format
, const GUID
*vendor
, DWORD options
, IStream
*stream
, IWICMetadataReader
**reader
)
1265 IEnumUnknown
*enumreaders
;
1266 IUnknown
*unkreaderinfo
;
1267 IWICMetadataReaderInfo
*readerinfo
;
1268 IWICPersistStream
*wicpersiststream
;
1270 GUID decoder_vendor
;
1274 TRACE("%p,%s,%s,%x,%p,%p\n", iface
, debugstr_guid(format
), debugstr_guid(vendor
),
1275 options
, stream
, reader
);
1277 if (!format
|| !stream
|| !reader
)
1278 return E_INVALIDARG
;
1282 hr
= CreateComponentEnumerator(WICMetadataReader
, WICComponentEnumerateDefault
, &enumreaders
);
1283 if (FAILED(hr
)) return hr
;
1290 hr
= IEnumUnknown_Next(enumreaders
, 1, &unkreaderinfo
, &num_fetched
);
1294 hr
= IUnknown_QueryInterface(unkreaderinfo
, &IID_IWICMetadataReaderInfo
, (void**)&readerinfo
);
1300 hr
= IWICMetadataReaderInfo_GetVendorGUID(readerinfo
, &decoder_vendor
);
1302 if (FAILED(hr
) || !IsEqualIID(vendor
, &decoder_vendor
))
1304 IWICMetadataReaderInfo_Release(readerinfo
);
1305 IUnknown_Release(unkreaderinfo
);
1310 hr
= IWICMetadataReaderInfo_MatchesPattern(readerinfo
, format
, stream
, &matches
);
1312 if (SUCCEEDED(hr
) && matches
)
1314 hr
= IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
1317 hr
= IWICMetadataReaderInfo_CreateInstance(readerinfo
, reader
);
1321 hr
= IWICMetadataReader_QueryInterface(*reader
, &IID_IWICPersistStream
, (void**)&wicpersiststream
);
1325 hr
= IWICPersistStream_LoadEx(wicpersiststream
,
1326 stream
, vendor
, options
& WICPersistOptionMask
);
1328 IWICPersistStream_Release(wicpersiststream
);
1333 IWICMetadataReader_Release(*reader
);
1339 IUnknown_Release(readerinfo
);
1342 IUnknown_Release(unkreaderinfo
);
1348 if (!*reader
&& vendor
)
1351 IEnumUnknown_Reset(enumreaders
);
1355 IEnumUnknown_Release(enumreaders
);
1357 if (!*reader
&& !(options
& WICMetadataCreationFailUnknown
))
1359 hr
= IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
1362 hr
= UnknownMetadataReader_CreateInstance(&IID_IWICMetadataReader
, (void**)reader
);
1366 hr
= IWICMetadataReader_QueryInterface(*reader
, &IID_IWICPersistStream
, (void**)&wicpersiststream
);
1370 hr
= IWICPersistStream_LoadEx(wicpersiststream
, stream
, NULL
, options
& WICPersistOptionMask
);
1372 IWICPersistStream_Release(wicpersiststream
);
1377 IWICMetadataReader_Release(*reader
);
1386 return WINCODEC_ERR_COMPONENTNOTFOUND
;
1389 static HRESULT WINAPI
ComponentFactory_CreateMetadataWriter(IWICComponentFactory
*iface
,
1390 REFGUID format
, const GUID
*vendor
, DWORD options
, IWICMetadataWriter
**writer
)
1392 FIXME("%p,%s,%s,%x,%p: stub\n", iface
, debugstr_guid(format
), debugstr_guid(vendor
), options
, writer
);
1396 static HRESULT WINAPI
ComponentFactory_CreateMetadataWriterFromReader(IWICComponentFactory
*iface
,
1397 IWICMetadataReader
*reader
, const GUID
*vendor
, IWICMetadataWriter
**writer
)
1399 FIXME("%p,%p,%s,%p: stub\n", iface
, reader
, debugstr_guid(vendor
), writer
);
1403 static HRESULT WINAPI
ComponentFactory_CreateQueryReaderFromBlockReader(IWICComponentFactory
*iface
,
1404 IWICMetadataBlockReader
*block_reader
, IWICMetadataQueryReader
**query_reader
)
1406 TRACE("%p,%p,%p\n", iface
, block_reader
, query_reader
);
1408 if (!block_reader
|| !query_reader
)
1409 return E_INVALIDARG
;
1411 return MetadataQueryReader_CreateInstance(block_reader
, NULL
, query_reader
);
1414 static HRESULT WINAPI
ComponentFactory_CreateQueryWriterFromBlockWriter(IWICComponentFactory
*iface
,
1415 IWICMetadataBlockWriter
*block_writer
, IWICMetadataQueryWriter
**query_writer
)
1417 FIXME("%p,%p,%p: stub\n", iface
, block_writer
, query_writer
);
1421 static HRESULT WINAPI
ComponentFactory_CreateEncoderPropertyBag(IWICComponentFactory
*iface
,
1422 PROPBAG2
*options
, UINT count
, IPropertyBag2
**property
)
1424 TRACE("(%p,%p,%u,%p)\n", iface
, options
, count
, property
);
1425 return CreatePropertyBag2(options
, count
, property
);
1428 static const IWICComponentFactoryVtbl ComponentFactory_Vtbl
= {
1429 ComponentFactory_QueryInterface
,
1430 ComponentFactory_AddRef
,
1431 ComponentFactory_Release
,
1432 ComponentFactory_CreateDecoderFromFilename
,
1433 ComponentFactory_CreateDecoderFromStream
,
1434 ComponentFactory_CreateDecoderFromFileHandle
,
1435 ComponentFactory_CreateComponentInfo
,
1436 ComponentFactory_CreateDecoder
,
1437 ComponentFactory_CreateEncoder
,
1438 ComponentFactory_CreatePalette
,
1439 ComponentFactory_CreateFormatConverter
,
1440 ComponentFactory_CreateBitmapScaler
,
1441 ComponentFactory_CreateBitmapClipper
,
1442 ComponentFactory_CreateBitmapFlipRotator
,
1443 ComponentFactory_CreateStream
,
1444 ComponentFactory_CreateColorContext
,
1445 ComponentFactory_CreateColorTransformer
,
1446 ComponentFactory_CreateBitmap
,
1447 ComponentFactory_CreateBitmapFromSource
,
1448 ComponentFactory_CreateBitmapFromSourceRect
,
1449 ComponentFactory_CreateBitmapFromMemory
,
1450 ComponentFactory_CreateBitmapFromHBITMAP
,
1451 ComponentFactory_CreateBitmapFromHICON
,
1452 ComponentFactory_CreateComponentEnumerator
,
1453 ComponentFactory_CreateFastMetadataEncoderFromDecoder
,
1454 ComponentFactory_CreateFastMetadataEncoderFromFrameDecode
,
1455 ComponentFactory_CreateQueryWriter
,
1456 ComponentFactory_CreateQueryWriterFromReader
,
1457 ComponentFactory_CreateMetadataReader
,
1458 ComponentFactory_CreateMetadataReaderFromContainer
,
1459 ComponentFactory_CreateMetadataWriter
,
1460 ComponentFactory_CreateMetadataWriterFromReader
,
1461 ComponentFactory_CreateQueryReaderFromBlockReader
,
1462 ComponentFactory_CreateQueryWriterFromBlockWriter
,
1463 ComponentFactory_CreateEncoderPropertyBag
1466 HRESULT
ImagingFactory_CreateInstance(REFIID iid
, void** ppv
)
1468 ImagingFactory
*This
;
1471 TRACE("(%s,%p)\n", debugstr_guid(iid
), ppv
);
1475 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1476 if (!This
) return E_OUTOFMEMORY
;
1478 This
->IWICImagingFactory2_iface
.lpVtbl
= &ImagingFactory_Vtbl
;
1479 This
->IWICComponentFactory_iface
.lpVtbl
= &ComponentFactory_Vtbl
;
1482 ret
= IWICImagingFactory2_QueryInterface(&This
->IWICImagingFactory2_iface
, iid
, ppv
);
1483 IWICImagingFactory2_Release(&This
->IWICImagingFactory2_iface
);
1488 HRESULT WINAPI
WICCreateBitmapFromSectionEx(UINT width
, UINT height
,
1489 REFWICPixelFormatGUID format
, HANDLE section
, UINT stride
,
1490 UINT offset
, WICSectionAccessLevel wicaccess
, IWICBitmap
**bitmap
)
1492 SYSTEM_INFO sysinfo
;
1493 UINT bpp
, access
, size
, view_offset
, view_size
;
1497 TRACE("%u,%u,%s,%p,%u,%u,%#x,%p\n", width
, height
, debugstr_guid(format
),
1498 section
, stride
, offset
, wicaccess
, bitmap
);
1500 if (!width
|| !height
|| !section
|| !bitmap
) return E_INVALIDARG
;
1502 hr
= get_pixelformat_bpp(format
, &bpp
);
1503 if (FAILED(hr
)) return hr
;
1507 case WICSectionAccessLevelReadWrite
:
1508 access
= FILE_MAP_READ
| FILE_MAP_WRITE
;
1511 case WICSectionAccessLevelRead
:
1512 access
= FILE_MAP_READ
;
1516 FIXME("unsupported access %#x\n", wicaccess
);
1517 return E_INVALIDARG
;
1520 if (!stride
) stride
= (((bpp
* width
) + 31) / 32) * 4;
1521 size
= stride
* height
;
1522 if (size
/ height
!= stride
) return E_INVALIDARG
;
1524 GetSystemInfo(&sysinfo
);
1525 view_offset
= offset
- (offset
% sysinfo
.dwAllocationGranularity
);
1526 view_size
= size
+ (offset
- view_offset
);
1528 view
= MapViewOfFile(section
, access
, 0, view_offset
, view_size
);
1529 if (!view
) return HRESULT_FROM_WIN32(GetLastError());
1531 offset
-= view_offset
;
1532 hr
= BitmapImpl_Create(width
, height
, stride
, 0, view
, offset
, format
, WICBitmapCacheOnLoad
, bitmap
);
1533 if (FAILED(hr
)) UnmapViewOfFile(view
);
1537 HRESULT WINAPI
WICCreateBitmapFromSection(UINT width
, UINT height
,
1538 REFWICPixelFormatGUID format
, HANDLE section
,
1539 UINT stride
, UINT offset
, IWICBitmap
**bitmap
)
1541 TRACE("%u,%u,%s,%p,%u,%u,%p\n", width
, height
, debugstr_guid(format
),
1542 section
, stride
, offset
, bitmap
);
1544 return WICCreateBitmapFromSectionEx(width
, height
, format
, section
,
1545 stride
, offset
, WICSectionAccessLevelRead
, bitmap
);