From 5265e0f2e5c99d0b218115b5f0cb50fb4bb7aed8 Mon Sep 17 00:00:00 2001 From: Rein Klazes Date: Tue, 28 Apr 2009 14:11:04 +0200 Subject: [PATCH] winex11: GetPixel() on a monochrome bitmap should return black or white, not dark red. --- dlls/gdi32/tests/dc.c | 76 +++++++++++++++++++++++++++++++++++++ dlls/winex11.drv/graphics.c | 7 +++- 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/dlls/gdi32/tests/dc.c b/dlls/gdi32/tests/dc.c index 661246c8df6..1efde38b134 100644 --- a/dlls/gdi32/tests/dc.c +++ b/dlls/gdi32/tests/dc.c @@ -253,10 +253,86 @@ static void test_CreateCompatibleDC(void) ok(hNewDC == NULL, "CreateCompatibleDC returned %p\n", hNewDC); } +static void test_DC_bitmap(void) +{ + HDC hdc, hdcmem; + DWORD bits[64]; + HBITMAP hbmp, oldhbmp; + COLORREF col; + int i, bitspixel; + + /* fill bitmap data with b&w pattern */ + for( i = 0; i < 64; i++) bits[i] = i & 1 ? 0 : 0xffffff; + + hdc = GetDC(0); + ok( hdc != NULL, "CreateDC rets %p\n", hdc); + bitspixel = GetDeviceCaps( hdc, BITSPIXEL); + /* create a memory dc */ + hdcmem = CreateCompatibleDC( hdc); + ok( hdcmem != NULL, "CreateCompatibleDC rets %p\n", hdcmem); + /* tests */ + /* test monochrome bitmap: should always work */ + hbmp = CreateBitmap(32, 32, 1, 1, bits); + ok( hbmp != NULL, "CreateBitmap returns %p\n", hbmp); + oldhbmp = SelectObject( hdcmem, hbmp); + ok( oldhbmp != NULL, "SelectObject returned NULL\n" ); /* a memdc always has a bitmap selected */ + col = GetPixel( hdcmem, 0, 0); + ok( col == 0xffffff, "GetPixel returned %08x, expected 00ffffff\n", col); + col = GetPixel( hdcmem, 1, 1); + ok( col == 0x000000, "GetPixel returned %08x, expected 00000000\n", col); + col = GetPixel( hdcmem, 100, 1); + ok( col == CLR_INVALID, "GetPixel returned %08x, expected ffffffff\n", col); + SelectObject( hdcmem, oldhbmp); + DeleteObject( hbmp); + + /* test with 2 bits color depth, not likely to succeed */ + hbmp = CreateBitmap(16, 16, 1, 2, bits); + ok( hbmp != NULL, "CreateBitmap returns %p\n", hbmp); + oldhbmp = SelectObject( hdcmem, hbmp); + if( bitspixel != 2) + ok( !oldhbmp, "SelectObject of a bitmap with 2 bits/pixel should return NULL\n"); + if( oldhbmp) SelectObject( hdcmem, oldhbmp); + DeleteObject( hbmp); + + /* test with 16 bits color depth, might succeed */ + hbmp = CreateBitmap(6, 6, 1, 16, bits); + ok( hbmp != NULL, "CreateBitmap returns %p\n", hbmp); + oldhbmp = SelectObject( hdcmem, hbmp); + if( bitspixel == 16) { + ok( oldhbmp != NULL, "SelectObject returned NULL\n" ); + col = GetPixel( hdcmem, 0, 0); + ok( col == 0xffffff, + "GetPixel of a bitmap with 16 bits/pixel returned %08x, expected 00ffffff\n", col); + col = GetPixel( hdcmem, 1, 1); + ok( col == 0x000000, + "GetPixel of a bitmap with 16 bits/pixel returned returned %08x, expected 00000000\n", col); + } + if( oldhbmp) SelectObject( hdcmem, oldhbmp); + DeleteObject( hbmp); + + /* test with 32 bits color depth, probably succeed */ + hbmp = CreateBitmap(4, 4, 1, 32, bits); + ok( hbmp != NULL, "CreateBitmap returns %p\n", hbmp); + oldhbmp = SelectObject( hdcmem, hbmp); + if( bitspixel == 32) { + ok( oldhbmp != NULL, "SelectObject returned NULL\n" ); + col = GetPixel( hdcmem, 0, 0); + ok( col == 0xffffff, + "GetPixel of a bitmap with 32 bits/pixel returned %08x, expected 00ffffff\n", col); + col = GetPixel( hdcmem, 1, 1); + ok( col == 0x000000, + "GetPixel of a bitmap with 32 bits/pixel returned returned %08x, expected 00000000\n", col); + } + if( oldhbmp) SelectObject( hdcmem, oldhbmp); + DeleteObject( hbmp); + ReleaseDC( 0, hdc ); +} + START_TEST(dc) { test_savedc(); test_savedc_2(); test_GdiConvertToDevmodeW(); test_CreateCompatibleDC(); + test_DC_bitmap(); } diff --git a/dlls/winex11.drv/graphics.c b/dlls/winex11.drv/graphics.c index a44de115643..8d74c7788e3 100644 --- a/dlls/winex11.drv/graphics.c +++ b/dlls/winex11.drv/graphics.c @@ -1082,8 +1082,13 @@ X11DRV_GetPixel( X11DRV_PDEVICE *physDev, INT x, INT y ) /* Update the DIBSection from the pixmap */ X11DRV_UnlockDIBSection(physDev, FALSE); + if( physDev->depth > 1) + pixel = X11DRV_PALETTE_ToLogical(pixel); + else + /* monochrome bitmaps return black or white */ + if( pixel) pixel = 0xffffff; + return pixel; - return X11DRV_PALETTE_ToLogical(pixel); }