[1/4] gdiplus: Avoid accessing dib bits directly in GdipCreateBitmapFromHBITMAP.

Vincent Povirk madewokherd at gmail.com
Wed Dec 5 14:18:08 CST 2012


-------------- next part --------------
From cbbd95fbb4801b275a8d0f859c5a7feeda2a24d6 Mon Sep 17 00:00:00 2001
From: Vincent Povirk <vincent at codeweavers.com>
Date: Wed, 5 Dec 2012 10:36:40 -0600
Subject: [PATCH 1/4] gdiplus: Avoid accessing dib bits directly in
 GdipCreateBitmapFromHBITMAP.

---
 dlls/gdiplus/image.c |   80 +++++++++++++++++++++-----------------------------
 1 file changed, 34 insertions(+), 46 deletions(-)

diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c
index 73f08b9..a8f43e3 100644
--- a/dlls/gdiplus/image.c
+++ b/dlls/gdiplus/image.c
@@ -4694,62 +4694,50 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBi
             format, &lockeddata);
         if (retval == Ok)
         {
-            if (bm.bmBits)
-            {
-                for (y=0; y<bm.bmHeight; y++)
-                {
-                    memcpy((BYTE*)lockeddata.Scan0+lockeddata.Stride*y,
-                           (BYTE*)bm.bmBits+bm.bmWidthBytes*(bm.bmHeight-1-y),
-                           bm.bmWidthBytes);
-                }
-            }
-            else
-            {
-                HDC hdc;
-                HBITMAP oldhbm;
-                BITMAPINFO *pbmi;
-                INT src_height, dst_stride;
-                BYTE *dst_bits;
+            HDC hdc;
+            HBITMAP oldhbm;
+            BITMAPINFO *pbmi;
+            INT src_height, dst_stride;
+            BYTE *dst_bits;
 
-                hdc = CreateCompatibleDC(NULL);
-                oldhbm = SelectObject(hdc, hbm);
+            hdc = CreateCompatibleDC(NULL);
+            oldhbm = SelectObject(hdc, hbm);
 
-                pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
+            pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
 
-                if (pbmi)
-                {
-                    pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-                    pbmi->bmiHeader.biBitCount = 0;
-
-                    GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
-
-                    src_height = abs(pbmi->bmiHeader.biHeight);
+            if (pbmi)
+            {
+                pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+                pbmi->bmiHeader.biBitCount = 0;
 
-                    if (pbmi->bmiHeader.biHeight > 0)
-                    {
-                        dst_bits = (BYTE*)lockeddata.Scan0+lockeddata.Stride*(src_height-1);
-                        dst_stride = -lockeddata.Stride;
-                    }
-                    else
-                    {
-                        dst_bits = lockeddata.Scan0;
-                        dst_stride = lockeddata.Stride;
-                    }
+                GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
 
-                    for (y=0; y<src_height; y++)
-                    {
-                        GetDIBits(hdc, hbm, y, 1, dst_bits+dst_stride*y,
-                            pbmi, DIB_RGB_COLORS);
-                    }
+                src_height = abs(pbmi->bmiHeader.biHeight);
 
-                    GdipFree(pbmi);
+                if (pbmi->bmiHeader.biHeight > 0)
+                {
+                    dst_bits = (BYTE*)lockeddata.Scan0+lockeddata.Stride*(src_height-1);
+                    dst_stride = -lockeddata.Stride;
                 }
                 else
-                    retval = OutOfMemory;
+                {
+                    dst_bits = lockeddata.Scan0;
+                    dst_stride = lockeddata.Stride;
+                }
+
+                for (y=0; y<src_height; y++)
+                {
+                    GetDIBits(hdc, hbm, y, 1, dst_bits+dst_stride*y,
+                        pbmi, DIB_RGB_COLORS);
+                }
 
-                SelectObject(hdc, oldhbm);
-                DeleteDC(hdc);
+                GdipFree(pbmi);
             }
+            else
+                retval = OutOfMemory;
+
+            SelectObject(hdc, oldhbm);
+            DeleteDC(hdc);
 
             GdipBitmapUnlockBits(*bitmap, &lockeddata);
         }
-- 
1.7.10.4


More information about the wine-patches mailing list