From bc653ce20485c0e76fa16cddbf463c525b878bfa Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Mon, 27 Jun 2011 13:26:42 +0100 Subject: [PATCH] gdi32: Fix the 8 bpp generated colour table. --- dlls/gdi32/dib.c | 25 +++++++--------------- dlls/gdi32/tests/bitmap.c | 45 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/dlls/gdi32/dib.c b/dlls/gdi32/dib.c index 07aa6090b6f..962a1aa0d47 100644 --- a/dlls/gdi32/dib.c +++ b/dlls/gdi32/dib.c @@ -456,7 +456,7 @@ static const RGBQUAD DefLogPaletteQuads[20] = { /* Copy of Default Logical Palet { 0xf0, 0xfb, 0xff, 0x00 }, { 0xa4, 0xa0, 0xa0, 0x00 }, { 0x80, 0x80, 0x80, 0x00 }, - { 0x00, 0x00, 0xf0, 0x00 }, + { 0x00, 0x00, 0xff, 0x00 }, { 0x00, 0xff, 0x00, 0x00 }, { 0x00, 0xff, 0xff, 0x00 }, { 0xff, 0x00, 0x00, 0x00 }, @@ -639,24 +639,15 @@ INT WINAPI GetDIBits( break; case 8: - { - INT r, g, b; - RGBQUAD *color; - memcpy(rgbQuads, DefLogPaletteQuads, 10 * sizeof(RGBQUAD)); memcpy(rgbQuads + 246, DefLogPaletteQuads + 10, 10 * sizeof(RGBQUAD)); - color = rgbQuads + 10; - for(r = 0; r <= 5; r++) /* FIXME */ - for(g = 0; g <= 5; g++) - for(b = 0; b <= 5; b++) { - color->rgbRed = (r * 0xff) / 5; - color->rgbGreen = (g * 0xff) / 5; - color->rgbBlue = (b * 0xff) / 5; - color->rgbReserved = 0; - color++; - } - } - + for (i = 10; i < 246; i++) + { + rgbQuads[i].rgbRed = (i & 0x07) << 5; + rgbQuads[i].rgbGreen = (i & 0x38) << 2; + rgbQuads[i].rgbBlue = i & 0xc0; + rgbQuads[i].rgbReserved = 0; + } } } diff --git a/dlls/gdi32/tests/bitmap.c b/dlls/gdi32/tests/bitmap.c index d21d502df84..e107d7b2457 100644 --- a/dlls/gdi32/tests/bitmap.c +++ b/dlls/gdi32/tests/bitmap.c @@ -1534,6 +1534,7 @@ static void test_GetDIBits(void) BYTE buf[1024]; char bi_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256]; BITMAPINFO *bi = (BITMAPINFO *)bi_buf; + PALETTEENTRY pal_ents[32]; hdc = GetDC(0); @@ -1722,6 +1723,50 @@ todo_wine for (i = 2; i < 256; i++) ok(((WORD*)bi->bmiColors)[i] == 0xAAAA, "Color %d is %d\n", i, ((WORD*)bi->bmiColors)[i]); + /* retrieve 8-bit DIB data */ + memset(bi, 0, sizeof(*bi)); + bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + bi->bmiHeader.biWidth = bm.bmWidth; + bi->bmiHeader.biHeight = bm.bmHeight; + bi->bmiHeader.biPlanes = 1; + bi->bmiHeader.biBitCount = 8; + bi->bmiHeader.biCompression = BI_RGB; + bi->bmiHeader.biSizeImage = 0; + memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256); + memset(buf, 0xAA, sizeof(buf)); + SetLastError(0xdeadbeef); + lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS); + ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n", + lines, bm.bmHeight, GetLastError()); + + GetPaletteEntries( GetStockObject(DEFAULT_PALETTE), 0, 32, pal_ents ); + + for (i = 0; i < 256; i++) + { + RGBQUAD expect; + + if (i < 10 || i >= 246) + { + int entry = i < 10 ? i : i - 236; + expect.rgbRed = pal_ents[entry].peRed; + expect.rgbGreen = pal_ents[entry].peGreen; + expect.rgbBlue = pal_ents[entry].peBlue; + } + else + { + expect.rgbRed = (i & 0x07) << 5; + expect.rgbGreen = (i & 0x38) << 2; + expect.rgbBlue = i & 0xc0; + } + expect.rgbReserved = 0; + + ok(!memcmp(bi->bmiColors + i, &expect, sizeof(expect)), + "expected bmiColors[%d] %x %x %x %x - got %x %x %x %x\n", i, + expect.rgbRed, expect.rgbGreen, expect.rgbBlue, expect.rgbReserved, + bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen, + bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved); + } + /* retrieve 24-bit DIB data */ memset(bi, 0, sizeof(*bi)); bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);