gdiplus: Include an alpha channel in HBITMAPs created from Bitmaps.
This commit is contained in:
parent
42c1b06a13
commit
5f94653159
|
@ -1370,12 +1370,12 @@ GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap,
|
|||
HBITMAP* hbmReturn, ARGB background)
|
||||
{
|
||||
GpStatus stat;
|
||||
HBITMAP result, oldbitmap;
|
||||
HBITMAP result;
|
||||
UINT width, height;
|
||||
HDC hdc;
|
||||
GpGraphics *graphics;
|
||||
BITMAPINFOHEADER bih;
|
||||
void *bits;
|
||||
LPBYTE bits;
|
||||
BitmapData lockeddata;
|
||||
TRACE("(%p,%p,%x)\n", bitmap, hbmReturn, background);
|
||||
|
||||
if (!bitmap || !hbmReturn) return InvalidParameter;
|
||||
|
@ -1398,25 +1398,19 @@ GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap,
|
|||
hdc = CreateCompatibleDC(NULL);
|
||||
if (!hdc) return GenericError;
|
||||
|
||||
result = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS, &bits,
|
||||
result = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS, (void**)&bits,
|
||||
NULL, 0);
|
||||
|
||||
if (result)
|
||||
{
|
||||
oldbitmap = SelectObject(hdc, result);
|
||||
lockeddata.Stride = -width * 4;
|
||||
lockeddata.Scan0 = bits - (lockeddata.Stride * (height - 1));
|
||||
|
||||
stat = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead|ImageLockModeUserInputBuf,
|
||||
PixelFormat32bppPARGB, &lockeddata);
|
||||
|
||||
stat = GdipCreateFromHDC(hdc, &graphics);
|
||||
if (stat == Ok)
|
||||
{
|
||||
stat = GdipGraphicsClear(graphics, background);
|
||||
|
||||
if (stat == Ok)
|
||||
stat = GdipDrawImage(graphics, (GpImage*)bitmap, 0, 0);
|
||||
|
||||
GdipDeleteGraphics(graphics);
|
||||
}
|
||||
|
||||
SelectObject(hdc, oldbitmap);
|
||||
stat = GdipBitmapUnlockBits(bitmap, &lockeddata);
|
||||
}
|
||||
else
|
||||
stat = GenericError;
|
||||
|
|
|
@ -1514,6 +1514,12 @@ static void test_createhbitmap(void)
|
|||
expect(32, bm.bmBitsPixel);
|
||||
ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
|
||||
|
||||
if (bm.bmBits)
|
||||
{
|
||||
DWORD val = *(DWORD*)bm.bmBits;
|
||||
ok(val == 0xff686868, "got %x, expected 0xff686868\n", val);
|
||||
}
|
||||
|
||||
hdc = CreateCompatibleDC(NULL);
|
||||
|
||||
oldhbitmap = SelectObject(hdc, hbitmap);
|
||||
|
@ -1529,6 +1535,49 @@ static void test_createhbitmap(void)
|
|||
|
||||
stat = GdipDisposeImage((GpImage*)bitmap);
|
||||
expect(Ok, stat);
|
||||
|
||||
/* create alpha Bitmap */
|
||||
stat = GdipCreateBitmapFromScan0(8, 20, 32, PixelFormat32bppARGB, bits, &bitmap);
|
||||
expect(Ok, stat);
|
||||
|
||||
/* create HBITMAP */
|
||||
stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
|
||||
expect(Ok, stat);
|
||||
|
||||
if (stat == Ok)
|
||||
{
|
||||
ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
|
||||
expect(sizeof(BITMAP), ret);
|
||||
|
||||
expect(0, bm.bmType);
|
||||
expect(8, bm.bmWidth);
|
||||
expect(20, bm.bmHeight);
|
||||
expect(32, bm.bmWidthBytes);
|
||||
expect(1, bm.bmPlanes);
|
||||
expect(32, bm.bmBitsPixel);
|
||||
ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
|
||||
|
||||
if (bm.bmBits)
|
||||
{
|
||||
DWORD val = *(DWORD*)bm.bmBits;
|
||||
ok(val == 0x682a2a2a, "got %x, expected 0x682a2a2a\n", val);
|
||||
}
|
||||
|
||||
hdc = CreateCompatibleDC(NULL);
|
||||
|
||||
oldhbitmap = SelectObject(hdc, hbitmap);
|
||||
pixel = GetPixel(hdc, 5, 5);
|
||||
SelectObject(hdc, oldhbitmap);
|
||||
|
||||
DeleteDC(hdc);
|
||||
|
||||
expect(0x2a2a2a, pixel);
|
||||
|
||||
DeleteObject(hbitmap);
|
||||
}
|
||||
|
||||
stat = GdipDisposeImage((GpImage*)bitmap);
|
||||
expect(Ok, stat);
|
||||
}
|
||||
|
||||
static void test_getthumbnail(void)
|
||||
|
|
Loading…
Reference in New Issue