winex11.drv: getpixel() on a monochrome bitmap should return black or white, not dark red.

Rein Klazes wijn at online.nl
Tue Apr 28 07:11:04 CDT 2009


Fixes bug #18077
---
 dlls/gdi32/tests/dc.c       |   88 +++++++++++++++++++++++++++++++++++++++++++
 dlls/winex11.drv/graphics.c |    7 +++-
 2 files changed, 94 insertions(+), 1 deletions(-)

diff --git a/dlls/gdi32/tests/dc.c b/dlls/gdi32/tests/dc.c
index 661246c..4227606 100644
--- a/dlls/gdi32/tests/dc.c
+++ b/dlls/gdi32/tests/dc.c
@@ -253,10 +253,98 @@ static void test_CreateCompatibleDC(void)
     ok(hNewDC == NULL, "CreateCompatibleDC returned %p\n", hNewDC);
 }
 
+static void test_DC_bitmap(void)
+{
+    HWND hwnd;
+    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; 
+    hwnd = CreateWindowExA( 0, "static", "", WS_POPUP, 0,0,16,16,
+                           0, 0, 0, NULL);
+    assert( hwnd != 0);
+    ShowWindow( hwnd, SW_SHOW);
+    UpdateWindow( hwnd);
+    /* get the dc for this window */
+    hdc = GetDC(hwnd);
+    ok( hdc != NULL, "CreateDC rets %p\n", hdc);
+    /* change the color values in this DC to somehing no black/white */
+    SetTextColor( hdc, 0x111111);
+    SetBkColor( hdc, 0x222222);
+    SetDCBrushColor( hdc, 0x333333);
+    SetDCPenColor( hdc, 0x44444444);
+    /* get the color depth */
+    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, "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, "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, "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);
+
+}
+
 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 a44de11..8d74c77 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);
 }
 
 
-- 
1.6.2.1




More information about the wine-patches mailing list