From a3b5f270a89052425d35238710466e668bfe0588 Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Wed, 19 Oct 2011 12:41:52 +0100 Subject: [PATCH] gdi32: Add support for non-rgb colorrefs. --- dlls/gdi32/dibdrv/objects.c | 58 +++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/dlls/gdi32/dibdrv/objects.c b/dlls/gdi32/dibdrv/objects.c index 6b278c8b678..a1f6829b2db 100644 --- a/dlls/gdi32/dibdrv/objects.c +++ b/dlls/gdi32/dibdrv/objects.c @@ -123,6 +123,54 @@ static inline BOOL rgbquad_equal(const RGBQUAD *a, const RGBQUAD *b) return FALSE; } +static COLORREF make_rgb_colorref( dibdrv_physdev *pdev, COLORREF color, + BOOL *got_pixel, DWORD *pixel ) +{ + BYTE type = color >> 24; + WORD index = LOWORD( color ); + HPALETTE pal = GetCurrentObject( pdev->dev.hdc, OBJ_PAL ); + PALETTEENTRY pal_ent; + + *pixel = 0; + *got_pixel = FALSE; + + switch( type ) + { + case 0: break; + + case 0x10: /* DIBINDEX */ + *got_pixel = TRUE; + *pixel = 0; + color = RGB(0, 0, 0); + + if (pdev->dib.bit_count <= 8 && index < (1 << pdev->dib.bit_count)) + { + *pixel = index; + if (index < pdev->dib.color_table_size) + color = RGB( pdev->dib.color_table[index].rgbRed, + pdev->dib.color_table[index].rgbGreen, + pdev->dib.color_table[index].rgbBlue ); + } + break; + + case 2: /* PALETTERGB */ + color &= 0xffffff; + break; + + case 1: /* PALETTEINDEX */ + if (!GetPaletteEntries( pal, index, 1, &pal_ent )) + GetPaletteEntries( pal, 0, 1, &pal_ent ); + color = RGB( pal_ent.peRed, pal_ent.peGreen, pal_ent.peBlue ); + break; + + default: + FIXME("Unhandled color type %08x\n", color); + color &= 0xffffff; + } + + return color; +} + /****************************************************************** * get_pixel_color * @@ -135,11 +183,17 @@ static inline BOOL rgbquad_equal(const RGBQUAD *a, const RGBQUAD *b) DWORD get_pixel_color( dibdrv_physdev *pdev, COLORREF color, BOOL mono_fixup ) { RGBQUAD fg_quad; + BOOL got_pixel; + DWORD pixel; + COLORREF rgb_ref; + + rgb_ref = make_rgb_colorref( pdev, color, &got_pixel, &pixel ); + if (got_pixel) return pixel; if (pdev->dib.bit_count != 1 || !mono_fixup) - return pdev->dib.funcs->colorref_to_pixel( &pdev->dib, color ); + return pdev->dib.funcs->colorref_to_pixel( &pdev->dib, rgb_ref ); - fg_quad = rgbquad_from_colorref( color ); + fg_quad = rgbquad_from_colorref( rgb_ref ); if(rgbquad_equal(&fg_quad, pdev->dib.color_table)) return 0; if(rgbquad_equal(&fg_quad, pdev->dib.color_table + 1))