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
);
194 IWICBitmapDecoderInfo_Release(decoderinfo
);
197 IUnknown_Release(unkdecoderinfo
);
203 IEnumUnknown_Release(enumdecoders
);
205 return WINCODEC_ERR_COMPONENTNOTFOUND
;
208 static HRESULT WINAPI
ImagingFactory_CreateDecoderFromStream(
209 IWICImagingFactory2
*iface
, IStream
*pIStream
, const GUID
*pguidVendor
,
210 WICDecodeOptions metadataOptions
, IWICBitmapDecoder
**ppIDecoder
)
213 IWICBitmapDecoder
*decoder
= NULL
;
215 TRACE("(%p,%p,%s,%u,%p)\n", iface
, pIStream
, debugstr_guid(pguidVendor
),
216 metadataOptions
, ppIDecoder
);
219 res
= find_decoder(pIStream
, pguidVendor
, metadataOptions
, &decoder
);
221 res
= find_decoder(pIStream
, NULL
, metadataOptions
, &decoder
);
225 *ppIDecoder
= decoder
;
230 if (WARN_ON(wincodecs
))
236 WARN("failed to load from a stream %#x\n", res
);
239 if (IStream_Seek(pIStream
, seek
, STREAM_SEEK_SET
, NULL
) == S_OK
)
241 if (IStream_Read(pIStream
, data
, 4, &bytesread
) == S_OK
)
242 WARN("first %i bytes of stream=%x %x %x %x\n", bytesread
, data
[0], data
[1], data
[2], data
[3]);
250 static HRESULT WINAPI
ImagingFactory_CreateDecoderFromFileHandle(
251 IWICImagingFactory2
*iface
, ULONG_PTR hFile
, const GUID
*pguidVendor
,
252 WICDecodeOptions metadataOptions
, IWICBitmapDecoder
**ppIDecoder
)
257 TRACE("(%p,%lx,%s,%u,%p)\n", iface
, hFile
, debugstr_guid(pguidVendor
),
258 metadataOptions
, ppIDecoder
);
260 hr
= StreamImpl_Create(&stream
);
263 hr
= stream_initialize_from_filehandle(stream
, (HANDLE
)hFile
);
266 hr
= IWICImagingFactory2_CreateDecoderFromStream(iface
, (IStream
*)stream
,
267 pguidVendor
, metadataOptions
, ppIDecoder
);
269 IWICStream_Release(stream
);
274 static HRESULT WINAPI
ImagingFactory_CreateComponentInfo(IWICImagingFactory2
*iface
,
275 REFCLSID clsidComponent
, IWICComponentInfo
**ppIInfo
)
277 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(clsidComponent
), ppIInfo
);
278 return CreateComponentInfo(clsidComponent
, ppIInfo
);
281 static HRESULT WINAPI
ImagingFactory_CreateDecoder(IWICImagingFactory2
*iface
,
282 REFGUID guidContainerFormat
, const GUID
*pguidVendor
,
283 IWICBitmapDecoder
**ppIDecoder
)
285 IEnumUnknown
*enumdecoders
;
286 IUnknown
*unkdecoderinfo
;
287 IWICBitmapDecoderInfo
*decoderinfo
;
288 IWICBitmapDecoder
*decoder
= NULL
, *preferred_decoder
= NULL
;
293 TRACE("(%p,%s,%s,%p)\n", iface
, debugstr_guid(guidContainerFormat
),
294 debugstr_guid(pguidVendor
), ppIDecoder
);
296 if (!guidContainerFormat
|| !ppIDecoder
) return E_INVALIDARG
;
298 res
= CreateComponentEnumerator(WICDecoder
, WICComponentEnumerateDefault
, &enumdecoders
);
299 if (FAILED(res
)) return res
;
301 while (!preferred_decoder
)
303 res
= IEnumUnknown_Next(enumdecoders
, 1, &unkdecoderinfo
, &num_fetched
);
304 if (res
!= S_OK
) break;
306 res
= IUnknown_QueryInterface(unkdecoderinfo
, &IID_IWICBitmapDecoderInfo
, (void **)&decoderinfo
);
311 res
= IWICBitmapDecoderInfo_GetContainerFormat(decoderinfo
, &container_guid
);
312 if (SUCCEEDED(res
) && IsEqualIID(&container_guid
, guidContainerFormat
))
314 IWICBitmapDecoder
*new_decoder
;
316 res
= IWICBitmapDecoderInfo_CreateInstance(decoderinfo
, &new_decoder
);
321 res
= IWICBitmapDecoderInfo_GetVendorGUID(decoderinfo
, &vendor
);
322 if (SUCCEEDED(res
) && IsEqualIID(&vendor
, pguidVendor
))
324 preferred_decoder
= new_decoder
;
329 if (new_decoder
&& !decoder
)
331 decoder
= new_decoder
;
335 if (new_decoder
) IWICBitmapDecoder_Release(new_decoder
);
339 IWICBitmapDecoderInfo_Release(decoderinfo
);
342 IUnknown_Release(unkdecoderinfo
);
345 IEnumUnknown_Release(enumdecoders
);
347 if (preferred_decoder
)
349 *ppIDecoder
= preferred_decoder
;
350 if (decoder
) IWICBitmapDecoder_Release(decoder
);
356 *ppIDecoder
= decoder
;
361 return WINCODEC_ERR_COMPONENTNOTFOUND
;
364 static HRESULT WINAPI
ImagingFactory_CreateEncoder(IWICImagingFactory2
*iface
,
365 REFGUID guidContainerFormat
, const GUID
*pguidVendor
,
366 IWICBitmapEncoder
**ppIEncoder
)
369 IEnumUnknown
*enumencoders
;
370 IUnknown
*unkencoderinfo
;
371 IWICBitmapEncoderInfo
*encoderinfo
;
372 IWICBitmapEncoder
*encoder
=NULL
;
375 GUID actual_containerformat
;
377 TRACE("(%p,%s,%s,%p)\n", iface
, debugstr_guid(guidContainerFormat
),
378 debugstr_guid(pguidVendor
), ppIEncoder
);
380 if (pguidVendor
&& !fixme
++)
381 FIXME("ignoring vendor GUID\n");
383 res
= CreateComponentEnumerator(WICEncoder
, WICComponentEnumerateDefault
, &enumencoders
);
384 if (FAILED(res
)) return res
;
388 res
= IEnumUnknown_Next(enumencoders
, 1, &unkencoderinfo
, &num_fetched
);
392 res
= IUnknown_QueryInterface(unkencoderinfo
, &IID_IWICBitmapEncoderInfo
, (void**)&encoderinfo
);
396 res
= IWICBitmapEncoderInfo_GetContainerFormat(encoderinfo
, &actual_containerformat
);
398 if (SUCCEEDED(res
) && IsEqualGUID(guidContainerFormat
, &actual_containerformat
))
400 res
= IWICBitmapEncoderInfo_CreateInstance(encoderinfo
, &encoder
);
405 IWICBitmapEncoderInfo_Release(encoderinfo
);
408 IUnknown_Release(unkencoderinfo
);
414 IEnumUnknown_Release(enumencoders
);
418 *ppIEncoder
= encoder
;
423 WARN("failed to create encoder\n");
425 return WINCODEC_ERR_COMPONENTNOTFOUND
;
429 static HRESULT WINAPI
ImagingFactory_CreatePalette(IWICImagingFactory2
*iface
,
430 IWICPalette
**ppIPalette
)
432 TRACE("(%p,%p)\n", iface
, ppIPalette
);
433 return PaletteImpl_Create(ppIPalette
);
436 static HRESULT WINAPI
ImagingFactory_CreateFormatConverter(IWICImagingFactory2
*iface
,
437 IWICFormatConverter
**ppIFormatConverter
)
439 return FormatConverter_CreateInstance(&IID_IWICFormatConverter
, (void**)ppIFormatConverter
);
442 static HRESULT WINAPI
ImagingFactory_CreateBitmapScaler(IWICImagingFactory2
*iface
,
443 IWICBitmapScaler
**ppIBitmapScaler
)
445 TRACE("(%p,%p)\n", iface
, ppIBitmapScaler
);
447 return BitmapScaler_Create(ppIBitmapScaler
);
450 static HRESULT WINAPI
ImagingFactory_CreateBitmapClipper(IWICImagingFactory2
*iface
,
451 IWICBitmapClipper
**ppIBitmapClipper
)
453 TRACE("(%p,%p)\n", iface
, ppIBitmapClipper
);
454 return BitmapClipper_Create(ppIBitmapClipper
);
457 static HRESULT WINAPI
ImagingFactory_CreateBitmapFlipRotator(IWICImagingFactory2
*iface
,
458 IWICBitmapFlipRotator
**ppIBitmapFlipRotator
)
460 TRACE("(%p,%p)\n", iface
, ppIBitmapFlipRotator
);
461 return FlipRotator_Create(ppIBitmapFlipRotator
);
464 static HRESULT WINAPI
ImagingFactory_CreateStream(IWICImagingFactory2
*iface
,
465 IWICStream
**ppIWICStream
)
467 TRACE("(%p,%p)\n", iface
, ppIWICStream
);
468 return StreamImpl_Create(ppIWICStream
);
471 static HRESULT WINAPI
ImagingFactory_CreateColorContext(IWICImagingFactory2
*iface
,
472 IWICColorContext
**ppIColorContext
)
474 TRACE("(%p,%p)\n", iface
, ppIColorContext
);
475 return ColorContext_Create(ppIColorContext
);
478 static HRESULT WINAPI
ImagingFactory_CreateColorTransformer(IWICImagingFactory2
*iface
,
479 IWICColorTransform
**ppIColorTransform
)
481 TRACE("(%p,%p)\n", iface
, ppIColorTransform
);
482 return ColorTransform_Create(ppIColorTransform
);
485 static HRESULT WINAPI
ImagingFactory_CreateBitmap(IWICImagingFactory2
*iface
,
486 UINT uiWidth
, UINT uiHeight
, REFWICPixelFormatGUID pixelFormat
,
487 WICBitmapCreateCacheOption option
, IWICBitmap
**ppIBitmap
)
489 TRACE("(%p,%u,%u,%s,%u,%p)\n", iface
, uiWidth
, uiHeight
,
490 debugstr_guid(pixelFormat
), option
, ppIBitmap
);
491 return BitmapImpl_Create(uiWidth
, uiHeight
, 0, 0, NULL
, 0, pixelFormat
, option
, ppIBitmap
);
494 static HRESULT
create_bitmap_from_source_rect(IWICBitmapSource
*piBitmapSource
, const WICRect
*rect
,
495 WICBitmapCreateCacheOption option
, IWICBitmap
**ppIBitmap
)
498 IWICBitmapLock
*lock
;
499 IWICPalette
*palette
;
501 WICPixelFormatGUID pixelformat
= {0};
505 IWICComponentInfo
*info
;
506 IWICPixelFormatInfo2
*formatinfo
;
507 WICPixelFormatNumericRepresentation format_type
;
509 assert(!rect
|| (rect
&& option
== WICBitmapCacheOnLoad
));
511 if (!piBitmapSource
|| !ppIBitmap
)
514 if (option
== WICBitmapNoCache
&& SUCCEEDED(IWICBitmapSource_QueryInterface(piBitmapSource
,
515 &IID_IWICBitmap
, (void **)&result
)))
521 hr
= IWICBitmapSource_GetSize(piBitmapSource
, &width
, &height
);
523 if (SUCCEEDED(hr
) && rect
)
525 if (rect
->X
>= width
|| rect
->Y
>= height
|| rect
->Width
== 0 || rect
->Height
== 0)
528 width
= min(width
- rect
->X
, rect
->Width
);
529 height
= min(height
- rect
->Y
, rect
->Height
);
533 hr
= IWICBitmapSource_GetPixelFormat(piBitmapSource
, &pixelformat
);
536 hr
= CreateComponentInfo(&pixelformat
, &info
);
540 hr
= IWICComponentInfo_QueryInterface(info
, &IID_IWICPixelFormatInfo2
, (void**)&formatinfo
);
544 hr
= IWICPixelFormatInfo2_GetNumericRepresentation(formatinfo
, &format_type
);
546 IWICPixelFormatInfo2_Release(formatinfo
);
549 IWICComponentInfo_Release(info
);
553 hr
= BitmapImpl_Create(width
, height
, 0, 0, NULL
, 0, &pixelformat
, option
, &result
);
557 hr
= IWICBitmap_Lock(result
, NULL
, WICBitmapLockWrite
, &lock
);
560 UINT stride
, buffersize
;
573 hr
= IWICBitmapLock_GetStride(lock
, &stride
);
576 hr
= IWICBitmapLock_GetDataPointer(lock
, &buffersize
, &buffer
);
579 hr
= IWICBitmapSource_CopyPixels(piBitmapSource
, &rc
, stride
,
582 IWICBitmapLock_Release(lock
);
585 if (SUCCEEDED(hr
) && (format_type
== WICPixelFormatNumericRepresentationUnspecified
||
586 format_type
== WICPixelFormatNumericRepresentationIndexed
))
588 hr
= PaletteImpl_Create(&palette
);
592 hr
= IWICBitmapSource_CopyPalette(piBitmapSource
, palette
);
595 hr
= IWICBitmap_SetPalette(result
, palette
);
599 IWICPalette_Release(palette
);
605 hr
= IWICBitmapSource_GetResolution(piBitmapSource
, &dpix
, &dpiy
);
608 hr
= IWICBitmap_SetResolution(result
, dpix
, dpiy
);
616 IWICBitmap_Release(result
);
622 static HRESULT WINAPI
ImagingFactory_CreateBitmapFromSource(IWICImagingFactory2
*iface
,
623 IWICBitmapSource
*piBitmapSource
, WICBitmapCreateCacheOption option
,
624 IWICBitmap
**ppIBitmap
)
626 TRACE("(%p,%p,%u,%p)\n", iface
, piBitmapSource
, option
, ppIBitmap
);
628 return create_bitmap_from_source_rect(piBitmapSource
, NULL
, option
, ppIBitmap
);
631 static HRESULT WINAPI
ImagingFactory_CreateBitmapFromSourceRect(IWICImagingFactory2
*iface
,
632 IWICBitmapSource
*piBitmapSource
, UINT x
, UINT y
, UINT width
, UINT height
,
633 IWICBitmap
**ppIBitmap
)
637 TRACE("(%p,%p,%u,%u,%u,%u,%p)\n", iface
, piBitmapSource
, x
, y
, width
,
643 rect
.Height
= height
;
645 return create_bitmap_from_source_rect(piBitmapSource
, &rect
, WICBitmapCacheOnLoad
, ppIBitmap
);
648 static HRESULT WINAPI
ImagingFactory_CreateBitmapFromMemory(IWICImagingFactory2
*iface
,
649 UINT width
, UINT height
, REFWICPixelFormatGUID format
, UINT stride
,
650 UINT size
, BYTE
*buffer
, IWICBitmap
**bitmap
)
654 TRACE("(%p,%u,%u,%s,%u,%u,%p,%p\n", iface
, width
, height
,
655 debugstr_guid(format
), stride
, size
, buffer
, bitmap
);
657 if (!stride
|| !size
|| !buffer
|| !bitmap
) return E_INVALIDARG
;
659 hr
= BitmapImpl_Create(width
, height
, stride
, size
, NULL
, 0, format
, WICBitmapCacheOnLoad
, bitmap
);
662 IWICBitmapLock
*lock
;
664 hr
= IWICBitmap_Lock(*bitmap
, NULL
, WICBitmapLockWrite
, &lock
);
670 IWICBitmapLock_GetDataPointer(lock
, &buffersize
, &data
);
671 memcpy(data
, buffer
, buffersize
);
673 IWICBitmapLock_Release(lock
);
677 IWICBitmap_Release(*bitmap
);
684 static BOOL
get_16bpp_format(HBITMAP hbm
, WICPixelFormatGUID
*format
)
690 hdc
= CreateCompatibleDC(0);
692 memset(&bmh
, 0, sizeof(bmh
));
693 bmh
.bV4Size
= sizeof(bmh
);
696 bmh
.bV4V4Compression
= BI_BITFIELDS
;
697 bmh
.bV4BitCount
= 16;
699 GetDIBits(hdc
, hbm
, 0, 0, NULL
, (BITMAPINFO
*)&bmh
, DIB_RGB_COLORS
);
701 if (bmh
.bV4RedMask
== 0x7c00 &&
702 bmh
.bV4GreenMask
== 0x3e0 &&
703 bmh
.bV4BlueMask
== 0x1f)
705 *format
= GUID_WICPixelFormat16bppBGR555
;
707 else if (bmh
.bV4RedMask
== 0xf800 &&
708 bmh
.bV4GreenMask
== 0x7e0 &&
709 bmh
.bV4BlueMask
== 0x1f)
711 *format
= GUID_WICPixelFormat16bppBGR565
;
715 FIXME("unrecognized bitfields %x,%x,%x\n", bmh
.bV4RedMask
,
716 bmh
.bV4GreenMask
, bmh
.bV4BlueMask
);
724 static HRESULT WINAPI
ImagingFactory_CreateBitmapFromHBITMAP(IWICImagingFactory2
*iface
,
725 HBITMAP hbm
, HPALETTE hpal
, WICBitmapAlphaChannelOption option
, IWICBitmap
**bitmap
)
729 WICPixelFormatGUID format
;
730 IWICBitmapLock
*lock
;
731 UINT size
, num_palette_entries
= 0;
732 PALETTEENTRY entry
[256];
734 TRACE("(%p,%p,%p,%u,%p)\n", iface
, hbm
, hpal
, option
, bitmap
);
736 if (!bitmap
) return E_INVALIDARG
;
738 if (GetObjectW(hbm
, sizeof(bm
), &bm
) != sizeof(bm
))
739 return WINCODEC_ERR_WIN32ERROR
;
743 num_palette_entries
= GetPaletteEntries(hpal
, 0, 256, entry
);
744 if (!num_palette_entries
)
745 return WINCODEC_ERR_WIN32ERROR
;
748 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
749 switch(bm
.bmBitsPixel
)
752 format
= GUID_WICPixelFormat1bppIndexed
;
755 format
= GUID_WICPixelFormat4bppIndexed
;
758 format
= GUID_WICPixelFormat8bppIndexed
;
761 if (!get_16bpp_format(hbm
, &format
))
765 format
= GUID_WICPixelFormat24bppBGR
;
770 case WICBitmapUseAlpha
:
771 format
= GUID_WICPixelFormat32bppBGRA
;
773 case WICBitmapUsePremultipliedAlpha
:
774 format
= GUID_WICPixelFormat32bppPBGRA
;
776 case WICBitmapIgnoreAlpha
:
777 format
= GUID_WICPixelFormat32bppBGR
;
784 format
= GUID_WICPixelFormat48bppRGB
;
787 FIXME("unsupported %d bpp\n", bm
.bmBitsPixel
);
791 hr
= BitmapImpl_Create(bm
.bmWidth
, bm
.bmHeight
, bm
.bmWidthBytes
, 0, NULL
, 0, &format
,
792 WICBitmapCacheOnLoad
, bitmap
);
793 if (hr
!= S_OK
) return hr
;
795 hr
= IWICBitmap_Lock(*bitmap
, NULL
, WICBitmapLockWrite
, &lock
);
800 char bmibuf
[FIELD_OFFSET(BITMAPINFO
, bmiColors
[256])];
801 BITMAPINFO
*bmi
= (BITMAPINFO
*)bmibuf
;
803 IWICBitmapLock_GetDataPointer(lock
, &size
, &buffer
);
805 hdc
= CreateCompatibleDC(0);
807 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
808 bmi
->bmiHeader
.biBitCount
= 0;
809 GetDIBits(hdc
, hbm
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
810 bmi
->bmiHeader
.biHeight
= -bm
.bmHeight
;
811 GetDIBits(hdc
, hbm
, 0, bm
.bmHeight
, buffer
, bmi
, DIB_RGB_COLORS
);
814 IWICBitmapLock_Release(lock
);
816 if (num_palette_entries
)
818 IWICPalette
*palette
;
819 WICColor colors
[256];
822 hr
= PaletteImpl_Create(&palette
);
825 for (i
= 0; i
< num_palette_entries
; i
++)
826 colors
[i
] = 0xff000000 | entry
[i
].peRed
<< 16 |
827 entry
[i
].peGreen
<< 8 | entry
[i
].peBlue
;
829 hr
= IWICPalette_InitializeCustom(palette
, colors
, num_palette_entries
);
831 hr
= IWICBitmap_SetPalette(*bitmap
, palette
);
833 IWICPalette_Release(palette
);
840 IWICBitmap_Release(*bitmap
);
847 static HRESULT WINAPI
ImagingFactory_CreateBitmapFromHICON(IWICImagingFactory2
*iface
,
848 HICON hicon
, IWICBitmap
**bitmap
)
850 IWICBitmapLock
*lock
;
853 int width
, height
, x
, y
;
862 TRACE("(%p,%p,%p)\n", iface
, hicon
, bitmap
);
864 if (!bitmap
) return E_INVALIDARG
;
866 if (!GetIconInfo(hicon
, &info
))
867 return HRESULT_FROM_WIN32(GetLastError());
869 GetObjectW(info
.hbmColor
? info
.hbmColor
: info
.hbmMask
, sizeof(bm
), &bm
);
872 height
= info
.hbmColor
? abs(bm
.bmHeight
) : abs(bm
.bmHeight
) / 2;
874 size
= stride
* height
;
876 hr
= BitmapImpl_Create(width
, height
, stride
, size
, NULL
, 0,
877 &GUID_WICPixelFormat32bppBGRA
, WICBitmapCacheOnLoad
, bitmap
);
878 if (hr
!= S_OK
) goto failed
;
880 hr
= IWICBitmap_Lock(*bitmap
, NULL
, WICBitmapLockWrite
, &lock
);
883 IWICBitmap_Release(*bitmap
);
886 IWICBitmapLock_GetDataPointer(lock
, &size
, &buffer
);
888 hdc
= CreateCompatibleDC(0);
890 memset(&bi
, 0, sizeof(bi
));
891 bi
.bmiHeader
.biSize
= sizeof(bi
.bmiHeader
);
892 bi
.bmiHeader
.biWidth
= width
;
893 bi
.bmiHeader
.biHeight
= info
.hbmColor
? -height
: -height
* 2;
894 bi
.bmiHeader
.biPlanes
= 1;
895 bi
.bmiHeader
.biBitCount
= 32;
896 bi
.bmiHeader
.biCompression
= BI_RGB
;
902 GetDIBits(hdc
, info
.hbmColor
, 0, height
, buffer
, &bi
, DIB_RGB_COLORS
);
904 if (bm
.bmBitsPixel
== 32)
906 /* If any pixel has a non-zero alpha, ignore hbmMask */
907 bits
= (DWORD
*)buffer
;
908 for (x
= 0; x
< width
&& !has_alpha
; x
++, bits
++)
910 for (y
= 0; y
< height
; y
++)
912 if (*bits
& 0xff000000)
922 GetDIBits(hdc
, info
.hbmMask
, 0, height
, buffer
, &bi
, DIB_RGB_COLORS
);
932 mask
= HeapAlloc(GetProcessHeap(), 0, size
);
935 IWICBitmapLock_Release(lock
);
936 IWICBitmap_Release(*bitmap
);
942 /* read alpha data from the mask */
943 GetDIBits(hdc
, info
.hbmMask
, info
.hbmColor
? 0 : height
, height
, mask
, &bi
, DIB_RGB_COLORS
);
945 for (y
= 0; y
< height
; y
++)
947 rgba
= (DWORD
*)(buffer
+ y
* stride
);
948 bits
= (DWORD
*)(mask
+ y
* stride
);
950 for (x
= 0; x
< width
; x
++, rgba
++, bits
++)
959 HeapFree(GetProcessHeap(), 0, mask
);
963 /* set constant alpha of 255 */
964 for (y
= 0; y
< height
; y
++)
966 rgba
= (DWORD
*)(buffer
+ y
* stride
);
967 for (x
= 0; x
< width
; x
++, rgba
++)
974 IWICBitmapLock_Release(lock
);
978 DeleteObject(info
.hbmColor
);
979 DeleteObject(info
.hbmMask
);
984 static HRESULT WINAPI
ImagingFactory_CreateComponentEnumerator(IWICImagingFactory2
*iface
,
985 DWORD componentTypes
, DWORD options
, IEnumUnknown
**ppIEnumUnknown
)
987 TRACE("(%p,%u,%u,%p)\n", iface
, componentTypes
, options
, ppIEnumUnknown
);
988 return CreateComponentEnumerator(componentTypes
, options
, ppIEnumUnknown
);
991 static HRESULT WINAPI
ImagingFactory_CreateFastMetadataEncoderFromDecoder(
992 IWICImagingFactory2
*iface
, IWICBitmapDecoder
*pIDecoder
,
993 IWICFastMetadataEncoder
**ppIFastEncoder
)
995 FIXME("(%p,%p,%p): stub\n", iface
, pIDecoder
, ppIFastEncoder
);
999 static HRESULT WINAPI
ImagingFactory_CreateFastMetadataEncoderFromFrameDecode(
1000 IWICImagingFactory2
*iface
, IWICBitmapFrameDecode
*pIFrameDecoder
,
1001 IWICFastMetadataEncoder
**ppIFastEncoder
)
1003 FIXME("(%p,%p,%p): stub\n", iface
, pIFrameDecoder
, ppIFastEncoder
);
1007 static HRESULT WINAPI
ImagingFactory_CreateQueryWriter(IWICImagingFactory2
*iface
,
1008 REFGUID guidMetadataFormat
, const GUID
*pguidVendor
,
1009 IWICMetadataQueryWriter
**ppIQueryWriter
)
1011 FIXME("(%p,%s,%s,%p): stub\n", iface
, debugstr_guid(guidMetadataFormat
),
1012 debugstr_guid(pguidVendor
), ppIQueryWriter
);
1016 static HRESULT WINAPI
ImagingFactory_CreateQueryWriterFromReader(IWICImagingFactory2
*iface
,
1017 IWICMetadataQueryReader
*pIQueryReader
, const GUID
*pguidVendor
,
1018 IWICMetadataQueryWriter
**ppIQueryWriter
)
1020 FIXME("(%p,%p,%s,%p): stub\n", iface
, pIQueryReader
, debugstr_guid(pguidVendor
),
1025 static HRESULT WINAPI
ImagingFactory_CreateImageEncoder(IWICImagingFactory2
*iface
, ID2D1Device
*device
, IWICImageEncoder
**encoder
)
1027 FIXME("%p,%p,%p stub.\n", iface
, device
, encoder
);
1031 static const IWICImagingFactory2Vtbl ImagingFactory_Vtbl
= {
1032 ImagingFactory_QueryInterface
,
1033 ImagingFactory_AddRef
,
1034 ImagingFactory_Release
,
1035 ImagingFactory_CreateDecoderFromFilename
,
1036 ImagingFactory_CreateDecoderFromStream
,
1037 ImagingFactory_CreateDecoderFromFileHandle
,
1038 ImagingFactory_CreateComponentInfo
,
1039 ImagingFactory_CreateDecoder
,
1040 ImagingFactory_CreateEncoder
,
1041 ImagingFactory_CreatePalette
,
1042 ImagingFactory_CreateFormatConverter
,
1043 ImagingFactory_CreateBitmapScaler
,
1044 ImagingFactory_CreateBitmapClipper
,
1045 ImagingFactory_CreateBitmapFlipRotator
,
1046 ImagingFactory_CreateStream
,
1047 ImagingFactory_CreateColorContext
,
1048 ImagingFactory_CreateColorTransformer
,
1049 ImagingFactory_CreateBitmap
,
1050 ImagingFactory_CreateBitmapFromSource
,
1051 ImagingFactory_CreateBitmapFromSourceRect
,
1052 ImagingFactory_CreateBitmapFromMemory
,
1053 ImagingFactory_CreateBitmapFromHBITMAP
,
1054 ImagingFactory_CreateBitmapFromHICON
,
1055 ImagingFactory_CreateComponentEnumerator
,
1056 ImagingFactory_CreateFastMetadataEncoderFromDecoder
,
1057 ImagingFactory_CreateFastMetadataEncoderFromFrameDecode
,
1058 ImagingFactory_CreateQueryWriter
,
1059 ImagingFactory_CreateQueryWriterFromReader
,
1060 ImagingFactory_CreateImageEncoder
,
1063 static HRESULT WINAPI
ComponentFactory_QueryInterface(IWICComponentFactory
*iface
, REFIID iid
, void **ppv
)
1065 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1066 return IWICImagingFactory2_QueryInterface(&This
->IWICImagingFactory2_iface
, iid
, ppv
);
1069 static ULONG WINAPI
ComponentFactory_AddRef(IWICComponentFactory
*iface
)
1071 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1072 return IWICImagingFactory2_AddRef(&This
->IWICImagingFactory2_iface
);
1075 static ULONG WINAPI
ComponentFactory_Release(IWICComponentFactory
*iface
)
1077 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1078 return IWICImagingFactory2_Release(&This
->IWICImagingFactory2_iface
);
1081 static HRESULT WINAPI
ComponentFactory_CreateDecoderFromFilename(IWICComponentFactory
*iface
, LPCWSTR filename
,
1082 const GUID
*vendor
, DWORD desired_access
, WICDecodeOptions options
, IWICBitmapDecoder
**decoder
)
1084 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1085 return IWICImagingFactory2_CreateDecoderFromFilename(&This
->IWICImagingFactory2_iface
, filename
, vendor
,
1086 desired_access
, options
, decoder
);
1089 static HRESULT WINAPI
ComponentFactory_CreateDecoderFromStream(IWICComponentFactory
*iface
, IStream
*stream
,
1090 const GUID
*vendor
, WICDecodeOptions options
, IWICBitmapDecoder
**decoder
)
1092 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1093 return IWICImagingFactory2_CreateDecoderFromStream(&This
->IWICImagingFactory2_iface
, stream
, vendor
,
1097 static HRESULT WINAPI
ComponentFactory_CreateDecoderFromFileHandle(IWICComponentFactory
*iface
, ULONG_PTR hFile
,
1098 const GUID
*vendor
, WICDecodeOptions options
, IWICBitmapDecoder
**decoder
)
1100 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1101 return IWICImagingFactory2_CreateDecoderFromFileHandle(&This
->IWICImagingFactory2_iface
, hFile
, vendor
,
1105 static HRESULT WINAPI
ComponentFactory_CreateComponentInfo(IWICComponentFactory
*iface
, REFCLSID component
,
1106 IWICComponentInfo
**info
)
1108 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1109 return IWICImagingFactory2_CreateComponentInfo(&This
->IWICImagingFactory2_iface
, component
, info
);
1112 static HRESULT WINAPI
ComponentFactory_CreateDecoder(IWICComponentFactory
*iface
, REFGUID format
, const GUID
*vendor
,
1113 IWICBitmapDecoder
**decoder
)
1115 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1116 return IWICImagingFactory2_CreateDecoder(&This
->IWICImagingFactory2_iface
, format
, vendor
, decoder
);
1119 static HRESULT WINAPI
ComponentFactory_CreateEncoder(IWICComponentFactory
*iface
, REFGUID format
, const GUID
*vendor
,
1120 IWICBitmapEncoder
**encoder
)
1122 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1123 return IWICImagingFactory2_CreateEncoder(&This
->IWICImagingFactory2_iface
, format
, vendor
, encoder
);
1126 static HRESULT WINAPI
ComponentFactory_CreatePalette(IWICComponentFactory
*iface
, IWICPalette
**palette
)
1128 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1129 return IWICImagingFactory2_CreatePalette(&This
->IWICImagingFactory2_iface
, palette
);
1132 static HRESULT WINAPI
ComponentFactory_CreateFormatConverter(IWICComponentFactory
*iface
, IWICFormatConverter
**converter
)
1134 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1135 return IWICImagingFactory2_CreateFormatConverter(&This
->IWICImagingFactory2_iface
, converter
);
1138 static HRESULT WINAPI
ComponentFactory_CreateBitmapScaler(IWICComponentFactory
*iface
, IWICBitmapScaler
**scaler
)
1140 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1141 return IWICImagingFactory2_CreateBitmapScaler(&This
->IWICImagingFactory2_iface
, scaler
);
1144 static HRESULT WINAPI
ComponentFactory_CreateBitmapClipper(IWICComponentFactory
*iface
, IWICBitmapClipper
**clipper
)
1146 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1147 return IWICImagingFactory2_CreateBitmapClipper(&This
->IWICImagingFactory2_iface
, clipper
);
1150 static HRESULT WINAPI
ComponentFactory_CreateBitmapFlipRotator(IWICComponentFactory
*iface
, IWICBitmapFlipRotator
**fliprotator
)
1152 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1153 return IWICImagingFactory2_CreateBitmapFlipRotator(&This
->IWICImagingFactory2_iface
, fliprotator
);
1156 static HRESULT WINAPI
ComponentFactory_CreateStream(IWICComponentFactory
*iface
, IWICStream
**stream
)
1158 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1159 return IWICImagingFactory2_CreateStream(&This
->IWICImagingFactory2_iface
, stream
);
1162 static HRESULT WINAPI
ComponentFactory_CreateColorContext(IWICComponentFactory
*iface
, IWICColorContext
**context
)
1164 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1165 return IWICImagingFactory2_CreateColorContext(&This
->IWICImagingFactory2_iface
, context
);
1168 static HRESULT WINAPI
ComponentFactory_CreateColorTransformer(IWICComponentFactory
*iface
, IWICColorTransform
**transformer
)
1170 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1171 return IWICImagingFactory2_CreateColorTransformer(&This
->IWICImagingFactory2_iface
, transformer
);
1174 static HRESULT WINAPI
ComponentFactory_CreateBitmap(IWICComponentFactory
*iface
, UINT width
, UINT height
, REFWICPixelFormatGUID pixel_format
,
1175 WICBitmapCreateCacheOption option
, IWICBitmap
**bitmap
)
1177 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1178 return IWICImagingFactory2_CreateBitmap(&This
->IWICImagingFactory2_iface
, width
, height
, pixel_format
, option
, bitmap
);
1181 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromSource(IWICComponentFactory
*iface
, IWICBitmapSource
*source
,
1182 WICBitmapCreateCacheOption option
, IWICBitmap
**bitmap
)
1184 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1185 return IWICImagingFactory2_CreateBitmapFromSource(&This
->IWICImagingFactory2_iface
, source
, option
, bitmap
);
1188 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromSourceRect(IWICComponentFactory
*iface
, IWICBitmapSource
*source
,
1189 UINT x
, UINT y
, UINT width
, UINT height
, IWICBitmap
**bitmap
)
1191 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1192 return IWICImagingFactory2_CreateBitmapFromSourceRect(&This
->IWICImagingFactory2_iface
, source
, x
, y
, width
, height
, bitmap
);
1195 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromMemory(IWICComponentFactory
*iface
, UINT width
, UINT height
,
1196 REFWICPixelFormatGUID format
, UINT stride
, UINT size
, BYTE
*buffer
, IWICBitmap
**bitmap
)
1198 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1199 return IWICImagingFactory2_CreateBitmapFromMemory(&This
->IWICImagingFactory2_iface
, width
, height
, format
, stride
,
1200 size
, buffer
, bitmap
);
1203 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromHBITMAP(IWICComponentFactory
*iface
, HBITMAP hbm
, HPALETTE hpal
,
1204 WICBitmapAlphaChannelOption option
, IWICBitmap
**bitmap
)
1206 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1207 return IWICImagingFactory2_CreateBitmapFromHBITMAP(&This
->IWICImagingFactory2_iface
, hbm
, hpal
, option
, bitmap
);
1210 static HRESULT WINAPI
ComponentFactory_CreateBitmapFromHICON(IWICComponentFactory
*iface
, HICON hicon
, IWICBitmap
**bitmap
)
1212 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1213 return IWICImagingFactory2_CreateBitmapFromHICON(&This
->IWICImagingFactory2_iface
, hicon
, bitmap
);
1216 static HRESULT WINAPI
ComponentFactory_CreateComponentEnumerator(IWICComponentFactory
*iface
, DWORD component_types
,
1217 DWORD options
, IEnumUnknown
**enumerator
)
1219 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1220 return IWICImagingFactory2_CreateComponentEnumerator(&This
->IWICImagingFactory2_iface
, component_types
,
1221 options
, enumerator
);
1224 static HRESULT WINAPI
ComponentFactory_CreateFastMetadataEncoderFromDecoder(IWICComponentFactory
*iface
, IWICBitmapDecoder
*decoder
,
1225 IWICFastMetadataEncoder
**encoder
)
1227 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1228 return IWICImagingFactory2_CreateFastMetadataEncoderFromDecoder(&This
->IWICImagingFactory2_iface
, decoder
, encoder
);
1231 static HRESULT WINAPI
ComponentFactory_CreateFastMetadataEncoderFromFrameDecode(IWICComponentFactory
*iface
,
1232 IWICBitmapFrameDecode
*frame_decode
, IWICFastMetadataEncoder
**encoder
)
1234 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1235 return IWICImagingFactory2_CreateFastMetadataEncoderFromFrameDecode(&This
->IWICImagingFactory2_iface
, frame_decode
, encoder
);
1238 static HRESULT WINAPI
ComponentFactory_CreateQueryWriter(IWICComponentFactory
*iface
, REFGUID format
, const GUID
*vendor
,
1239 IWICMetadataQueryWriter
**writer
)
1241 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1242 return IWICImagingFactory2_CreateQueryWriter(&This
->IWICImagingFactory2_iface
, format
, vendor
, writer
);
1245 static HRESULT WINAPI
ComponentFactory_CreateQueryWriterFromReader(IWICComponentFactory
*iface
, IWICMetadataQueryReader
*reader
,
1246 const GUID
*vendor
, IWICMetadataQueryWriter
**writer
)
1248 ImagingFactory
*This
= impl_from_IWICComponentFactory(iface
);
1249 return IWICImagingFactory2_CreateQueryWriterFromReader(&This
->IWICImagingFactory2_iface
, reader
, vendor
, writer
);
1252 static HRESULT WINAPI
ComponentFactory_CreateMetadataReader(IWICComponentFactory
*iface
,
1253 REFGUID format
, const GUID
*vendor
, DWORD options
, IStream
*stream
, IWICMetadataReader
**reader
)
1255 FIXME("%p,%s,%s,%x,%p,%p: stub\n", iface
, debugstr_guid(format
), debugstr_guid(vendor
),
1256 options
, stream
, reader
);
1260 static HRESULT WINAPI
ComponentFactory_CreateMetadataReaderFromContainer(IWICComponentFactory
*iface
,
1261 REFGUID format
, const GUID
*vendor
, DWORD options
, IStream
*stream
, IWICMetadataReader
**reader
)
1264 IEnumUnknown
*enumreaders
;
1265 IUnknown
*unkreaderinfo
;
1266 IWICMetadataReaderInfo
*readerinfo
;
1267 IWICPersistStream
*wicpersiststream
;
1269 GUID decoder_vendor
;
1273 TRACE("%p,%s,%s,%x,%p,%p\n", iface
, debugstr_guid(format
), debugstr_guid(vendor
),
1274 options
, stream
, reader
);
1276 if (!format
|| !stream
|| !reader
)
1277 return E_INVALIDARG
;
1281 hr
= CreateComponentEnumerator(WICMetadataReader
, WICComponentEnumerateDefault
, &enumreaders
);
1282 if (FAILED(hr
)) return hr
;
1289 hr
= IEnumUnknown_Next(enumreaders
, 1, &unkreaderinfo
, &num_fetched
);
1293 hr
= IUnknown_QueryInterface(unkreaderinfo
, &IID_IWICMetadataReaderInfo
, (void**)&readerinfo
);
1299 hr
= IWICMetadataReaderInfo_GetVendorGUID(readerinfo
, &decoder_vendor
);
1301 if (FAILED(hr
) || !IsEqualIID(vendor
, &decoder_vendor
))
1303 IWICMetadataReaderInfo_Release(readerinfo
);
1304 IUnknown_Release(unkreaderinfo
);
1309 hr
= IWICMetadataReaderInfo_MatchesPattern(readerinfo
, format
, stream
, &matches
);
1311 if (SUCCEEDED(hr
) && matches
)
1313 hr
= IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
1316 hr
= IWICMetadataReaderInfo_CreateInstance(readerinfo
, reader
);
1320 hr
= IWICMetadataReader_QueryInterface(*reader
, &IID_IWICPersistStream
, (void**)&wicpersiststream
);
1324 hr
= IWICPersistStream_LoadEx(wicpersiststream
,
1325 stream
, vendor
, options
& WICPersistOptionMask
);
1327 IWICPersistStream_Release(wicpersiststream
);
1332 IWICMetadataReader_Release(*reader
);
1338 IUnknown_Release(readerinfo
);
1341 IUnknown_Release(unkreaderinfo
);
1347 if (!*reader
&& vendor
)
1350 IEnumUnknown_Reset(enumreaders
);
1354 IEnumUnknown_Release(enumreaders
);
1356 if (!*reader
&& !(options
& WICMetadataCreationFailUnknown
))
1358 hr
= IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
1361 hr
= UnknownMetadataReader_CreateInstance(&IID_IWICMetadataReader
, (void**)reader
);
1365 hr
= IWICMetadataReader_QueryInterface(*reader
, &IID_IWICPersistStream
, (void**)&wicpersiststream
);
1369 hr
= IWICPersistStream_LoadEx(wicpersiststream
, stream
, NULL
, options
& WICPersistOptionMask
);
1371 IWICPersistStream_Release(wicpersiststream
);
1376 IWICMetadataReader_Release(*reader
);
1385 return WINCODEC_ERR_COMPONENTNOTFOUND
;
1388 static HRESULT WINAPI
ComponentFactory_CreateMetadataWriter(IWICComponentFactory
*iface
,
1389 REFGUID format
, const GUID
*vendor
, DWORD options
, IWICMetadataWriter
**writer
)
1391 FIXME("%p,%s,%s,%x,%p: stub\n", iface
, debugstr_guid(format
), debugstr_guid(vendor
), options
, writer
);
1395 static HRESULT WINAPI
ComponentFactory_CreateMetadataWriterFromReader(IWICComponentFactory
*iface
,
1396 IWICMetadataReader
*reader
, const GUID
*vendor
, IWICMetadataWriter
**writer
)
1398 FIXME("%p,%p,%s,%p: stub\n", iface
, reader
, debugstr_guid(vendor
), writer
);
1402 static HRESULT WINAPI
ComponentFactory_CreateQueryReaderFromBlockReader(IWICComponentFactory
*iface
,
1403 IWICMetadataBlockReader
*block_reader
, IWICMetadataQueryReader
**query_reader
)
1405 TRACE("%p,%p,%p\n", iface
, block_reader
, query_reader
);
1407 if (!block_reader
|| !query_reader
)
1408 return E_INVALIDARG
;
1410 return MetadataQueryReader_CreateInstance(block_reader
, NULL
, query_reader
);
1413 static HRESULT WINAPI
ComponentFactory_CreateQueryWriterFromBlockWriter(IWICComponentFactory
*iface
,
1414 IWICMetadataBlockWriter
*block_writer
, IWICMetadataQueryWriter
**query_writer
)
1416 FIXME("%p,%p,%p: stub\n", iface
, block_writer
, query_writer
);
1420 static HRESULT WINAPI
ComponentFactory_CreateEncoderPropertyBag(IWICComponentFactory
*iface
,
1421 PROPBAG2
*options
, UINT count
, IPropertyBag2
**property
)
1423 TRACE("(%p,%p,%u,%p)\n", iface
, options
, count
, property
);
1424 return CreatePropertyBag2(options
, count
, property
);
1427 static const IWICComponentFactoryVtbl ComponentFactory_Vtbl
= {
1428 ComponentFactory_QueryInterface
,
1429 ComponentFactory_AddRef
,
1430 ComponentFactory_Release
,
1431 ComponentFactory_CreateDecoderFromFilename
,
1432 ComponentFactory_CreateDecoderFromStream
,
1433 ComponentFactory_CreateDecoderFromFileHandle
,
1434 ComponentFactory_CreateComponentInfo
,
1435 ComponentFactory_CreateDecoder
,
1436 ComponentFactory_CreateEncoder
,
1437 ComponentFactory_CreatePalette
,
1438 ComponentFactory_CreateFormatConverter
,
1439 ComponentFactory_CreateBitmapScaler
,
1440 ComponentFactory_CreateBitmapClipper
,
1441 ComponentFactory_CreateBitmapFlipRotator
,
1442 ComponentFactory_CreateStream
,
1443 ComponentFactory_CreateColorContext
,
1444 ComponentFactory_CreateColorTransformer
,
1445 ComponentFactory_CreateBitmap
,
1446 ComponentFactory_CreateBitmapFromSource
,
1447 ComponentFactory_CreateBitmapFromSourceRect
,
1448 ComponentFactory_CreateBitmapFromMemory
,
1449 ComponentFactory_CreateBitmapFromHBITMAP
,
1450 ComponentFactory_CreateBitmapFromHICON
,
1451 ComponentFactory_CreateComponentEnumerator
,
1452 ComponentFactory_CreateFastMetadataEncoderFromDecoder
,
1453 ComponentFactory_CreateFastMetadataEncoderFromFrameDecode
,
1454 ComponentFactory_CreateQueryWriter
,
1455 ComponentFactory_CreateQueryWriterFromReader
,
1456 ComponentFactory_CreateMetadataReader
,
1457 ComponentFactory_CreateMetadataReaderFromContainer
,
1458 ComponentFactory_CreateMetadataWriter
,
1459 ComponentFactory_CreateMetadataWriterFromReader
,
1460 ComponentFactory_CreateQueryReaderFromBlockReader
,
1461 ComponentFactory_CreateQueryWriterFromBlockWriter
,
1462 ComponentFactory_CreateEncoderPropertyBag
1465 HRESULT
ImagingFactory_CreateInstance(REFIID iid
, void** ppv
)
1467 ImagingFactory
*This
;
1470 TRACE("(%s,%p)\n", debugstr_guid(iid
), ppv
);
1474 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1475 if (!This
) return E_OUTOFMEMORY
;
1477 This
->IWICImagingFactory2_iface
.lpVtbl
= &ImagingFactory_Vtbl
;
1478 This
->IWICComponentFactory_iface
.lpVtbl
= &ComponentFactory_Vtbl
;
1481 ret
= IWICImagingFactory2_QueryInterface(&This
->IWICImagingFactory2_iface
, iid
, ppv
);
1482 IWICImagingFactory2_Release(&This
->IWICImagingFactory2_iface
);
1487 HRESULT WINAPI
WICCreateBitmapFromSectionEx(UINT width
, UINT height
,
1488 REFWICPixelFormatGUID format
, HANDLE section
, UINT stride
,
1489 UINT offset
, WICSectionAccessLevel wicaccess
, IWICBitmap
**bitmap
)
1491 SYSTEM_INFO sysinfo
;
1492 UINT bpp
, access
, size
, view_offset
, view_size
;
1496 TRACE("%u,%u,%s,%p,%u,%u,%#x,%p\n", width
, height
, debugstr_guid(format
),
1497 section
, stride
, offset
, wicaccess
, bitmap
);
1499 if (!width
|| !height
|| !section
|| !bitmap
) return E_INVALIDARG
;
1501 hr
= get_pixelformat_bpp(format
, &bpp
);
1502 if (FAILED(hr
)) return hr
;
1506 case WICSectionAccessLevelReadWrite
:
1507 access
= FILE_MAP_READ
| FILE_MAP_WRITE
;
1510 case WICSectionAccessLevelRead
:
1511 access
= FILE_MAP_READ
;
1515 FIXME("unsupported access %#x\n", wicaccess
);
1516 return E_INVALIDARG
;
1519 if (!stride
) stride
= (((bpp
* width
) + 31) / 32) * 4;
1520 size
= stride
* height
;
1521 if (size
/ height
!= stride
) return E_INVALIDARG
;
1523 GetSystemInfo(&sysinfo
);
1524 view_offset
= offset
- (offset
% sysinfo
.dwAllocationGranularity
);
1525 view_size
= size
+ (offset
- view_offset
);
1527 view
= MapViewOfFile(section
, access
, 0, view_offset
, view_size
);
1528 if (!view
) return HRESULT_FROM_WIN32(GetLastError());
1530 offset
-= view_offset
;
1531 hr
= BitmapImpl_Create(width
, height
, stride
, 0, view
, offset
, format
, WICBitmapCacheOnLoad
, bitmap
);
1532 if (FAILED(hr
)) UnmapViewOfFile(view
);
1536 HRESULT WINAPI
WICCreateBitmapFromSection(UINT width
, UINT height
,
1537 REFWICPixelFormatGUID format
, HANDLE section
,
1538 UINT stride
, UINT offset
, IWICBitmap
**bitmap
)
1540 TRACE("%u,%u,%s,%p,%u,%u,%p\n", width
, height
, debugstr_guid(format
),
1541 section
, stride
, offset
, bitmap
);
1543 return WICCreateBitmapFromSectionEx(width
, height
, format
, section
,
1544 stride
, offset
, WICSectionAccessLevelRead
, bitmap
);