From 3424dac3863f57c5d9724a31744469b9fcd4bd89 Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Sat, 12 Dec 2009 17:13:39 -0600 Subject: [PATCH] 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 | 37 +++++++++++++++++++++++++++---------- dlls/gdiplus/tests/image.c | 13 ++++++++++++- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c index f78b70aa891..aa03712b9f0 100644 --- a/dlls/gdiplus/image.c +++ b/dlls/gdiplus/image.c @@ -2659,7 +2659,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); @@ -2700,16 +2701,32 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBi return InvalidParameter; } - if (bm.bmBits) - bits = (BYTE*)bm.bmBits + (bm.bmHeight - 1) * bm.bmWidthBytes; - else - { - FIXME("can only get image data from DIB sections\n"); - bits = NULL; - } + retval = GdipCreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, 0, + format, NULL, bitmap); - retval = GdipCreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, -bm.bmWidthBytes, - format, bits, bitmap); + if (retval == Ok) + { + retval = GdipBitmapLockBits(*bitmap, NULL, ImageLockModeWrite, + format, &lockeddata); + if (retval == Ok) + { + if (bm.bmBits) + { + for (y=0; y