Commit b58276af authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

gdiplus: Reimplement GdipCreateHBITMAPFromBitmap so it can work on locked bitmaps.

parent 5673d82b
......@@ -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,19 +1500,23 @@ 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);
image_unlock(&bitmap->image, unlock);
return GenericError;
}
if (stat == Ok)
stat = GdipBitmapUnlockBits(bitmap, &lockeddata);
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);
image_unlock(&bitmap->image, unlock);
return stat;
}
if (stat == Ok && (background & 0xffffff))
if (background & 0xffffff)
{
DWORD *ptr;
UINT i;
......@@ -1520,19 +1526,10 @@ GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap,
*ptr = blend_argb_no_bkgnd_alpha(*ptr, background);
}
}
}
else
stat = GenericError;
if (stat != Ok && result)
{
DeleteObject(result);
result = NULL;
}
*hbmReturn = result;
return stat;
image_unlock(&bitmap->image, unlock);
return Ok;
}
GpStatus WINGDIPAPI GdipCreateBitmapFromGraphics(INT width, INT height,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment