From 4d4c7f838c962e595297b9fdbdeb0fddc39d349f Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Mon, 16 Aug 2010 17:30:42 -0500 Subject: [PATCH 1/2] gdiplus: Move WIC source conversion into a helper function. --- dlls/gdiplus/image.c | 134 +++++++++++++++++++++++++++----------------------- 1 files changed, 73 insertions(+), 61 deletions(-) diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c index d72ae8d..30c433d 100644 --- a/dlls/gdiplus/image.c +++ b/dlls/gdiplus/image.c @@ -2481,95 +2481,107 @@ static const PixelFormat wic_gdip_formats[] = { PixelFormat32bppPARGB, }; -static GpStatus decode_image_wic(IStream* stream, REFCLSID clsid, GpImage **image) +static GpStatus bitmap_from_wicsource(IWICBitmapSource *orig_src, GpImage **image) { - GpStatus status=Ok; - GpBitmap *bitmap; - HRESULT hr; - IWICBitmapDecoder *decoder; - IWICBitmapFrameDecode *frame; IWICBitmapSource *source=NULL; + HRESULT hr; + GpStatus status=Ok; WICPixelFormatGUID wic_format; PixelFormat gdip_format=0; int i; UINT width, height; + GpBitmap *bitmap; BitmapData lockeddata; WICRect wrc; - HRESULT initresult; - - initresult = CoInitialize(NULL); - hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, - &IID_IWICBitmapDecoder, (void**)&decoder); - if (FAILED(hr)) goto end; + hr = IWICBitmapSource_GetPixelFormat(orig_src, &wic_format); - hr = IWICBitmapDecoder_Initialize(decoder, (IStream*)stream, WICDecodeMetadataCacheOnLoad); if (SUCCEEDED(hr)) - hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame); + { + for (i=0; wic_pixel_formats[i]; i++) + { + if (IsEqualGUID(&wic_format, wic_pixel_formats[i])) + { + source = orig_src; + IWICBitmapSource_AddRef(source); + gdip_format = wic_gdip_formats[i]; + break; + } + } + if (!source) + { + /* unknown format; fall back on 32bppARGB */ + hr = WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA, orig_src, &source); + gdip_format = PixelFormat32bppARGB; + } + } - if (SUCCEEDED(hr)) /* got frame */ + if (SUCCEEDED(hr)) /* got source */ { - hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &wic_format); + hr = IWICBitmapSource_GetSize(source, &width, &height); if (SUCCEEDED(hr)) + status = GdipCreateBitmapFromScan0(width, height, 0, gdip_format, + NULL, &bitmap); + + if (SUCCEEDED(hr) && status == Ok) /* created bitmap */ { - for (i=0; wic_pixel_formats[i]; i++) + status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeWrite, + gdip_format, &lockeddata); + if (status == Ok) /* locked bitmap */ { - if (IsEqualGUID(&wic_format, wic_pixel_formats[i])) + wrc.X = 0; + wrc.Width = width; + wrc.Height = 1; + for (i=0; i