From 5a5e0e937d979aefcfdffa2ce7b8121a9d77da26 Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Sat, 22 Aug 2009 19:51:08 -0500 Subject: [PATCH] oleaut32: Avoid copying the data when loading an image using WIC. --- dlls/oleaut32/olepicture.c | 66 ++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/dlls/oleaut32/olepicture.c b/dlls/oleaut32/olepicture.c index 83e53494ada..b4def3a1db5 100644 --- a/dlls/oleaut32/olepicture.c +++ b/dlls/oleaut32/olepicture.c @@ -1319,48 +1319,50 @@ end: static HRESULT OLEPictureImpl_LoadWICDecoder(OLEPictureImpl *This, REFCLSID decoder_clsid, BYTE *xbuf, ULONG xread) { HRESULT hr; + IWICImagingFactory *factory; IWICBitmapDecoder *decoder; IWICBitmapFrameDecode *framedecode; HRESULT initresult; - HGLOBAL hdata; - BYTE *data; - IStream *stream; - - hdata = GlobalAlloc(GMEM_MOVEABLE, xread); - if (!hdata) return E_OUTOFMEMORY; - - data = GlobalLock(hdata); - memcpy(data, xbuf, xread); - GlobalUnlock(hdata); - - hr = CreateStreamOnHGlobal(hdata, TRUE, &stream); - if (FAILED(hr)) - { - GlobalFree(hdata); - return hr; - } + IWICStream *stream; initresult = CoInitialize(NULL); - hr = CoCreateInstance(decoder_clsid, NULL, CLSCTX_INPROC_SERVER, - &IID_IWICBitmapDecoder, (void**)&decoder); - if (FAILED(hr)) goto end; - - hr = IWICBitmapDecoder_Initialize(decoder, stream, WICDecodeMetadataCacheOnLoad); - if (SUCCEEDED(hr)) + hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, + &IID_IWICImagingFactory, (void**)&factory); + if (SUCCEEDED(hr)) /* created factory */ { - hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode); - if (SUCCEEDED(hr)) - { - hr = OLEPictureImpl_LoadWICSource(This, (IWICBitmapSource*)framedecode); - IWICBitmapFrameDecode_Release(framedecode); - } + hr = IWICImagingFactory_CreateStream(factory, &stream); + IWICImagingFactory_Release(factory); } - IWICBitmapDecoder_Release(decoder); + if (SUCCEEDED(hr)) /* created stream */ + { + hr = IWICStream_InitializeFromMemory(stream, xbuf, xread); + + if (SUCCEEDED(hr)) /* initialized stream */ + { + hr = CoCreateInstance(decoder_clsid, NULL, CLSCTX_INPROC_SERVER, + &IID_IWICBitmapDecoder, (void**)&decoder); + if (SUCCEEDED(hr)) /* created decoder */ + { + hr = IWICBitmapDecoder_Initialize(decoder, (IStream*)stream, WICDecodeMetadataCacheOnLoad); + + if (SUCCEEDED(hr)) /* initialized decoder */ + hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode); + + IWICBitmapDecoder_Release(decoder); + } + } + + IWICStream_Release(stream); + } + + if (SUCCEEDED(hr)) /* got framedecode */ + { + hr = OLEPictureImpl_LoadWICSource(This, (IWICBitmapSource*)framedecode); + IWICBitmapFrameDecode_Release(framedecode); + } -end: - IStream_Release(stream); if (SUCCEEDED(initresult)) CoUninitialize(); return hr; }