gdiplus: Always provide image data in the format requested by image encoders.

Vincent Povirk madewokherd at gmail.com
Fri Sep 20 14:13:03 CDT 2013


For bug 31557.

I don't know why the code for this was initially removed (tests seem
to work fine), but whatever the reason, we'll need to address it
without writing image data in the wrong format.
-------------- next part --------------
From ca6cb38711264cabcb290d90d75e4eef5dafddf9 Mon Sep 17 00:00:00 2001
From: Vincent Povirk <vincent at codeweavers.com>
Date: Wed, 14 Aug 2013 15:04:13 -0500
Subject: [PATCH 1/3] gdiplus: Always provide image data in the format
 requested by image encoders.

---
 dlls/gdiplus/image.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c
index ada53e8..025172e 100644
--- a/dlls/gdiplus/image.c
+++ b/dlls/gdiplus/image.c
@@ -4043,6 +4043,7 @@ static GpStatus encode_image_WIC(GpImage *image, IStream* stream,
     HRESULT hr;
     UINT width, height;
     PixelFormat gdipformat=0;
+    const WICPixelFormatGUID *desired_wicformat;
     WICPixelFormatGUID wicformat;
     GpRect rc;
     BitmapData lockeddata;
@@ -4095,20 +4096,40 @@ static GpStatus encode_image_WIC(GpImage *image, IStream* stream,
             {
                 if (pixel_formats[i].gdip_format == bitmap->format)
                 {
-                    memcpy(&wicformat, pixel_formats[i].wic_format, sizeof(GUID));
+                    desired_wicformat = pixel_formats[i].wic_format;
                     gdipformat = bitmap->format;
                     break;
                 }
             }
             if (!gdipformat)
             {
-                memcpy(&wicformat, &GUID_WICPixelFormat32bppBGRA, sizeof(GUID));
+                desired_wicformat = &GUID_WICPixelFormat32bppBGRA;
                 gdipformat = PixelFormat32bppARGB;
             }
 
+            memcpy(&wicformat, desired_wicformat, sizeof(GUID));
             hr = IWICBitmapFrameEncode_SetPixelFormat(frameencode, &wicformat);
         }
 
+        if (SUCCEEDED(hr) && !IsEqualGUID(desired_wicformat, &wicformat))
+        {
+            /* Encoder doesn't support this bitmap's format. */
+            gdipformat = 0;
+            for (i=0; pixel_formats[i].wic_format; i++)
+            {
+                if (IsEqualGUID(&wicformat, pixel_formats[i].wic_format))
+                {
+                    gdipformat = bitmap->format;
+                    break;
+                }
+            }
+            if (!gdipformat)
+            {
+                ERR("Cannot support encoder format %s\n", debugstr_guid(&wicformat));
+                hr = E_FAIL;
+            }
+        }
+
         if (SUCCEEDED(hr))
         {
             stat = GdipBitmapLockBits(bitmap, &rc, ImageLockModeRead, gdipformat,
-- 
1.8.1.2


More information about the wine-patches mailing list