Commit 19b7d1db authored by Jeff Smith's avatar Jeff Smith Committed by Alexandre Julliard

gdiplus: Fix GdipCreateBitmapFromICON return status with mask-only icon.

parent a548bef8
......@@ -1635,11 +1635,11 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromHICON(HICON hicon, GpBitmap** bitmap)
TRACE("%p, %p\n", hicon, bitmap);
if(!bitmap || !GetIconInfo(hicon, &iinfo))
if(!bitmap || !GetIconInfo(hicon, &iinfo) || !iinfo.hbmColor || !iinfo.fIcon)
return InvalidParameter;
/* get the size of the icon */
ret = GetObjectA(iinfo.hbmColor ? iinfo.hbmColor : iinfo.hbmMask, sizeof(bm), &bm);
ret = GetObjectA(iinfo.hbmColor, sizeof(bm), &bm);
if (ret == 0) {
DeleteObject(iinfo.hbmColor);
DeleteObject(iinfo.hbmMask);
......@@ -1647,7 +1647,7 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromHICON(HICON hicon, GpBitmap** bitmap)
}
width = bm.bmWidth;
height = iinfo.hbmColor ? abs(bm.bmHeight) : abs(bm.bmHeight) / 2;
height = abs(bm.bmHeight);
stride = width * 4;
stat = GdipCreateBitmapFromScan0(width, height, stride, PixelFormat32bppARGB, NULL, bitmap);
......@@ -1672,7 +1672,7 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromHICON(HICON hicon, GpBitmap** bitmap)
bih.biSize = sizeof(bih);
bih.biWidth = width;
bih.biHeight = iinfo.hbmColor ? -height: -height * 2;
bih.biHeight = -height;
bih.biPlanes = 1;
bih.biBitCount = 32;
bih.biCompression = BI_RGB;
......@@ -1683,71 +1683,45 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromHICON(HICON hicon, GpBitmap** bitmap)
bih.biClrImportant = 0;
screendc = CreateCompatibleDC(0);
if (iinfo.hbmColor)
{
GetDIBits(screendc, iinfo.hbmColor, 0, height, lockeddata.Scan0, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
GetDIBits(screendc, iinfo.hbmColor, 0, height, lockeddata.Scan0, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
if (bm.bmBitsPixel == 32)
{
has_alpha = FALSE;
/* If any pixel has a non-zero alpha, ignore hbmMask */
src = (DWORD*)lockeddata.Scan0;
for (y=0; y<height && !has_alpha; y++)
for (x=0; x<width && !has_alpha; x++)
if ((*src++ & 0xff000000) != 0)
has_alpha = TRUE;
}
else has_alpha = FALSE;
}
else
if (bm.bmBitsPixel == 32)
{
GetDIBits(screendc, iinfo.hbmMask, 0, height, lockeddata.Scan0, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
has_alpha = FALSE;
/* If any pixel has a non-zero alpha, ignore hbmMask */
src = (DWORD*)lockeddata.Scan0;
for (y=0; y<height && !has_alpha; y++)
for (x=0; x<width && !has_alpha; x++)
if ((*src++ & 0xff000000) != 0)
has_alpha = TRUE;
}
else has_alpha = FALSE;
if (!has_alpha)
{
if (iinfo.hbmMask)
{
BYTE *bits = heap_alloc(height * stride);
/* read alpha data from the mask */
if (iinfo.hbmColor)
GetDIBits(screendc, iinfo.hbmMask, 0, height, bits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
else
GetDIBits(screendc, iinfo.hbmMask, height, height, bits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
BYTE *bits = heap_alloc(height * stride);
src = (DWORD*)bits;
dst_row = lockeddata.Scan0;
for (y=0; y<height; y++)
{
dst = (DWORD*)dst_row;
for (x=0; x<width; x++)
{
DWORD src_value = *src++;
if (src_value)
*dst++ = 0;
else
*dst++ |= 0xff000000;
}
dst_row += lockeddata.Stride;
}
/* read alpha data from the mask - the mask can safely be assumed to exist */
GetDIBits(screendc, iinfo.hbmMask, 0, height, bits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
heap_free(bits);
}
else
src = (DWORD*)bits;
dst_row = lockeddata.Scan0;
for (y=0; y<height; y++)
{
/* set constant alpha of 255 */
dst_row = lockeddata.Scan0;
for (y=0; y<height; y++)
dst = (DWORD*)dst_row;
for (x=0; x<width; x++)
{
dst = (DWORD*)dst_row;
for (x=0; x<width; x++)
DWORD src_value = *src++;
if (src_value)
*dst++ = 0;
else
*dst++ |= 0xff000000;
dst_row += lockeddata.Stride;
}
dst_row += lockeddata.Stride;
}
heap_free(bits);
}
DeleteDC(screendc);
......
......@@ -1606,7 +1606,6 @@ static void test_fromhicon(void)
ok(hIcon != 0, "CreateIconIndirect failed\n");
stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
todo_wine
expect(InvalidParameter, stat);
if (stat == Ok)
GdipDisposeImage((GpImage*)bitmap);
......@@ -1619,10 +1618,7 @@ static void test_fromhicon(void)
ok(hIcon != 0, "CreateIconIndirect failed\n");
stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
todo_wine
expect(InvalidParameter, stat);
if (stat == Ok)
GdipDisposeImage((GpImage*)bitmap);
DestroyIcon(hIcon);
DeleteObject(hbmMask);
......
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