Alexandre Julliard : gdi32: Copy a DIB section as a DIB section in BITMAP_CopyBitmap.

Alexandre Julliard julliard at winehq.org
Wed Sep 29 12:00:12 CDT 2010


Module: wine
Branch: master
Commit: 1914f3ecae2f3197f1ac6ffcc61d041b49ea59d4
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=1914f3ecae2f3197f1ac6ffcc61d041b49ea59d4

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Sep 28 22:44:36 2010 +0200

gdi32: Copy a DIB section as a DIB section in BITMAP_CopyBitmap.

---

 dlls/gdi32/bitmap.c |   40 ++++++++++++++++++++++++++++++++--------
 1 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/dlls/gdi32/bitmap.c b/dlls/gdi32/bitmap.c
index e5a02be..9d05ff5 100644
--- a/dlls/gdi32/bitmap.c
+++ b/dlls/gdi32/bitmap.c
@@ -510,17 +510,41 @@ LONG WINAPI SetBitmapBits(
  */
 HBITMAP BITMAP_CopyBitmap(HBITMAP hbitmap)
 {
-    HBITMAP res = 0;
-    BITMAP bm;
+    HBITMAP res;
+    DIBSECTION dib;
+    DWORD size;
+
+    if (!(size = GetObjectW( hbitmap, sizeof(dib), &dib ))) return 0;
 
-    if (!GetObjectW( hbitmap, sizeof(bm), &bm )) return 0;
-    res = CreateBitmapIndirect(&bm);
+    if (size == sizeof(DIBSECTION))
+    {
+        void *bits;
+        BITMAPINFO *bi;
+        HDC dc = CreateCompatibleDC( NULL );
+
+        if (!dc) return 0;
+        if (!(bi = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ))))
+        {
+            DeleteDC( dc );
+            return 0;
+        }
+        bi->bmiHeader = dib.dsBmih;
+
+        /* Get the color table or the color masks */
+        GetDIBits( dc, hbitmap, 0, 0, NULL, bi, DIB_RGB_COLORS );
+
+        res = CreateDIBSection( dc, bi, DIB_RGB_COLORS, &bits, NULL, 0 );
+        if (res) SetDIBits( dc, res, 0, dib.dsBm.bmHeight, dib.dsBm.bmBits, bi, DIB_RGB_COLORS );
+        HeapFree( GetProcessHeap(), 0, bi );
+        DeleteDC( dc );
+        return res;
+    }
 
+    res = CreateBitmapIndirect( &dib.dsBm );
     if(res) {
-        char *buf = HeapAlloc( GetProcessHeap(), 0, bm.bmWidthBytes *
-			       bm.bmHeight );
-        GetBitmapBits (hbitmap, bm.bmWidthBytes * bm.bmHeight, buf);
-	SetBitmapBits (res, bm.bmWidthBytes * bm.bmHeight, buf);
+        char *buf = HeapAlloc( GetProcessHeap(), 0, dib.dsBm.bmWidthBytes * dib.dsBm.bmHeight );
+        GetBitmapBits (hbitmap, dib.dsBm.bmWidthBytes * dib.dsBm.bmHeight, buf);
+        SetBitmapBits (res, dib.dsBm.bmWidthBytes * dib.dsBm.bmHeight, buf);
 	HeapFree( GetProcessHeap(), 0, buf );
     }
     return res;




More information about the wine-cvs mailing list