Commit 48f083b3 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

gdi32: Don't set the bitfields when the dib section is BI_RGB.

parent bb28917b
......@@ -1216,8 +1216,9 @@ HBITMAP WINAPI CreateDIBSection(HDC hdc, CONST BITMAPINFO *bmi, UINT usage,
if (!(dib = HeapAlloc( GetProcessHeap(), 0, sizeof(*dib) ))) return 0;
TRACE("format (%d,%d), planes %d, bpp %d, size %d, %s\n",
width, height, planes, bpp, sizeImage, usage == DIB_PAL_COLORS? "PAL" : "RGB");
TRACE("format (%d,%d), planes %d, bpp %d, %s, size %d %s\n",
width, height, planes, bpp, compression == BI_BITFIELDS? "BI_BITFIELDS" : "BI_RGB",
sizeImage, usage == DIB_PAL_COLORS? "PAL" : "RGB");
dib->dsBm.bmType = 0;
dib->dsBm.bmWidth = width;
......@@ -1255,24 +1256,24 @@ HBITMAP WINAPI CreateDIBSection(HDC hdc, CONST BITMAPINFO *bmi, UINT usage,
dib->dsBmih.biSizeImage = dib->dsBm.bmWidthBytes * dib->dsBm.bmHeight;
/* set dsBitfields values */
if (usage == DIB_PAL_COLORS || bpp <= 8)
{
dib->dsBitfields[0] = dib->dsBitfields[1] = dib->dsBitfields[2] = 0;
if((bpp == 15 || bpp == 16) && compression == BI_RGB)
{
/* In this case Windows changes biCompression to BI_BITFIELDS,
however for now we won't do this, as there are a lot
of places where BI_BITFIELDS is currently unsupported. */
/* dib->dsBmih.biCompression = compression = BI_BITFIELDS;*/
dib->dsBitfields[0] = 0x7c00;
dib->dsBitfields[1] = 0x03e0;
dib->dsBitfields[2] = 0x001f;
}
else switch( bpp )
else if(compression == BI_BITFIELDS)
{
case 15:
case 16:
dib->dsBitfields[0] = (compression == BI_BITFIELDS) ? *(const DWORD *)bmi->bmiColors : 0x7c00;
dib->dsBitfields[1] = (compression == BI_BITFIELDS) ? *((const DWORD *)bmi->bmiColors + 1) : 0x03e0;
dib->dsBitfields[2] = (compression == BI_BITFIELDS) ? *((const DWORD *)bmi->bmiColors + 2) : 0x001f;
break;
case 24:
case 32:
dib->dsBitfields[0] = (compression == BI_BITFIELDS) ? *(const DWORD *)bmi->bmiColors : 0xff0000;
dib->dsBitfields[1] = (compression == BI_BITFIELDS) ? *((const DWORD *)bmi->bmiColors + 1) : 0x00ff00;
dib->dsBitfields[2] = (compression == BI_BITFIELDS) ? *((const DWORD *)bmi->bmiColors + 2) : 0x0000ff;
break;
dib->dsBitfields[0] = *(const DWORD *)bmi->bmiColors;
dib->dsBitfields[1] = *((const DWORD *)bmi->bmiColors + 1);
dib->dsBitfields[2] = *((const DWORD *)bmi->bmiColors + 2);
}
/* get storage location for DIB bits */
......
......@@ -204,10 +204,14 @@ static void test_simple_graphics(void)
{
char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
BITMAPINFO *bmi = (BITMAPINFO *)bmibuf;
DWORD *bit_fields = (DWORD*)(bmibuf + sizeof(BITMAPINFOHEADER));
HDC mem_dc;
BYTE *bits;
HBITMAP dib, orig_bm;
const char **sha1;
DIBSECTION ds;
mem_dc = CreateCompatibleDC(NULL);
/* a8r8g8b8 */
trace("8888\n");
......@@ -221,7 +225,12 @@ static void test_simple_graphics(void)
dib = CreateDIBSection(0, bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
ok(dib != NULL, "ret NULL\n");
mem_dc = CreateCompatibleDC(NULL);
ok(GetObjectW( dib, sizeof(ds), &ds ), "GetObject failed\n");
ok(ds.dsBitfields[0] == 0, "got %08x\n", ds.dsBitfields[0]);
ok(ds.dsBitfields[1] == 0, "got %08x\n", ds.dsBitfields[1]);
ok(ds.dsBitfields[2] == 0, "got %08x\n", ds.dsBitfields[2]);
ok(ds.dsBmih.biCompression == BI_RGB, "got %x\n", ds.dsBmih.biCompression);
orig_bm = SelectObject(mem_dc, dib);
sha1 = sha1_graphics_a8r8g8b8;
......@@ -229,6 +238,47 @@ static void test_simple_graphics(void)
SelectObject(mem_dc, orig_bm);
DeleteObject(dib);
/* a8r8g8b8 - bitfields. Should be the same as the regular 32 bit case.*/
trace("8888 - bitfields\n");
bmi->bmiHeader.biBitCount = 32;
bmi->bmiHeader.biCompression = BI_BITFIELDS;
bit_fields[0] = 0xff0000;
bit_fields[1] = 0x00ff00;
bit_fields[2] = 0x0000ff;
dib = CreateDIBSection(mem_dc, bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
ok(dib != NULL, "ret NULL\n");
ok(GetObjectW( dib, sizeof(ds), &ds ), "GetObject failed\n");
ok(ds.dsBitfields[0] == 0xff0000, "got %08x\n", ds.dsBitfields[0]);
ok(ds.dsBitfields[1] == 0x00ff00, "got %08x\n", ds.dsBitfields[1]);
ok(ds.dsBitfields[2] == 0x0000ff, "got %08x\n", ds.dsBitfields[2]);
ok(ds.dsBmih.biCompression == BI_BITFIELDS, "got %x\n", ds.dsBmih.biCompression);
orig_bm = SelectObject(mem_dc, dib);
sha1 = sha1_graphics_a8r8g8b8;
draw_graphics(mem_dc, bmi, bits, &sha1);
SelectObject(mem_dc, orig_bm);
DeleteObject(dib);
/* r5g5b5 */
bmi->bmiHeader.biBitCount = 16;
bmi->bmiHeader.biCompression = BI_RGB;
dib = CreateDIBSection(0, bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
ok(dib != NULL, "ret NULL\n");
ok(GetObjectW( dib, sizeof(ds), &ds ), "GetObject failed\n");
ok(ds.dsBitfields[0] == 0x7c00, "got %08x\n", ds.dsBitfields[0]);
ok(ds.dsBitfields[1] == 0x03e0, "got %08x\n", ds.dsBitfields[1]);
ok(ds.dsBitfields[2] == 0x001f, "got %08x\n", ds.dsBitfields[2]);
todo_wine
ok(ds.dsBmih.biCompression == BI_BITFIELDS, "got %x\n", ds.dsBmih.biCompression);
DeleteObject(dib);
DeleteDC(mem_dc);
}
......
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