From 320893cec301d8dfe90d98ad5b49bd861b9ebb63 Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Sat, 12 Dec 2009 17:13:39 -0600 Subject: [PATCH 1/2] gdiplus: Explicitly copy the bits from dib sections to new bitmaps. On Windows, GdipCreateBitmapFromHBITMAP creates a copy of the bitmap, not a reference. Currently, we match this behavior, but this is only because we cannot yet create bitmap objects that reference existing memory. If GdipCreateBitmapFromScan0 were fixed to do this, FromHBITMAP would break. Therefore, we always pass NULL to FromScan0 so that it allocates new memory for the bitmap. --- dlls/gdiplus/image.c | 35 ++++++++++++++++++++++++++--------- dlls/gdiplus/tests/image.c | 13 ++++++++++++- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c index 73a6bd6..2ebe9a2 100644 --- a/dlls/gdiplus/image.c +++ b/dlls/gdiplus/image.c @@ -2555,7 +2555,8 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBi BITMAP bm; GpStatus retval; PixelFormat format; - BYTE* bits; + BitmapData lockeddata; + INT y; TRACE("%p %p %p\n", hbm, hpal, bitmap); @@ -2596,16 +2597,32 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBi return InvalidParameter; } - if (bm.bmBits) - bits = (BYTE*)bm.bmBits + (bm.bmHeight - 1) * bm.bmWidthBytes; - else + retval = GdipCreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, 0, + format, NULL, bitmap); + + if (retval == Ok) { - FIXME("can only get image data from DIB sections\n"); - bits = NULL; - } + retval = GdipBitmapLockBits(*bitmap, NULL, ImageLockModeWrite, + format, &lockeddata); + if (retval == Ok) + { + if (bm.bmBits) + { + for (y=0; y