Module: wine Branch: master Commit: b58276af4dad993bdac52b979da2d8d9baa1ea8b URL: http://source.winehq.org/git/wine.git/?a=commit;h=b58276af4dad993bdac52b979d...
Author: Piotr Caban piotr@codeweavers.com Date: Tue Feb 14 10:24:47 2017 +0100
gdiplus: Reimplement GdipCreateHBITMAPFromBitmap so it can work on locked bitmaps.
Signed-off-by: Piotr Caban piotr@codeweavers.com Signed-off-by: Vincent Povirk vincent@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/gdiplus/image.c | 53 +++++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 28 deletions(-)
diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c index dd01f77..07609ac 100644 --- a/dlls/gdiplus/image.c +++ b/dlls/gdiplus/image.c @@ -1477,10 +1477,12 @@ GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap, UINT width, height; BITMAPINFOHEADER bih; LPBYTE bits; - BitmapData lockeddata; + BOOL unlock; + TRACE("(%p,%p,%x)\n", bitmap, hbmReturn, background);
if (!bitmap || !hbmReturn) return InvalidParameter; + if (!image_lock(&bitmap->image, &unlock)) return ObjectBusy;
GdipGetImageWidth(&bitmap->image, &width); GdipGetImageHeight(&bitmap->image, &height); @@ -1498,41 +1500,36 @@ GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap, bih.biClrImportant = 0;
result = CreateDIBSection(0, (BITMAPINFO*)&bih, DIB_RGB_COLORS, (void**)&bits, NULL, 0); - - if (result) + if (!result) { - lockeddata.Stride = -width * 4; - lockeddata.Scan0 = bits + (width * 4 * (height - 1)); - - stat = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead|ImageLockModeUserInputBuf, - PixelFormat32bppPARGB, &lockeddata); - - if (stat == Ok) - stat = GdipBitmapUnlockBits(bitmap, &lockeddata); - - if (stat == Ok && (background & 0xffffff)) - { - DWORD *ptr; - UINT i; - for (ptr = (DWORD*)bits, i = 0; i < width * height; ptr++, i++) - { - if ((*ptr & 0xff000000) == 0xff000000) continue; - *ptr = blend_argb_no_bkgnd_alpha(*ptr, background); - } - } + image_unlock(&bitmap->image, unlock); + return GenericError; } - else - stat = GenericError;
- if (stat != Ok && result) + stat = convert_pixels(width, height, -width*4, + bits + (width * 4 * (height - 1)), PixelFormat32bppPARGB, + bitmap->stride, bitmap->bits, bitmap->format, bitmap->image.palette); + if (stat != Ok) { DeleteObject(result); - result = NULL; + image_unlock(&bitmap->image, unlock); + return stat; }
- *hbmReturn = result; + if (background & 0xffffff) + { + DWORD *ptr; + UINT i; + for (ptr = (DWORD*)bits, i = 0; i < width * height; ptr++, i++) + { + if ((*ptr & 0xff000000) == 0xff000000) continue; + *ptr = blend_argb_no_bkgnd_alpha(*ptr, background); + } + }
- return stat; + *hbmReturn = result; + image_unlock(&bitmap->image, unlock); + return Ok; }
GpStatus WINGDIPAPI GdipCreateBitmapFromGraphics(INT width, INT height,