diff --git a/dlls/winex11.drv/palette.c b/dlls/winex11.drv/palette.c index adff6c1d4e3..a7a6b35c9b6 100644 --- a/dlls/winex11.drv/palette.c +++ b/dlls/winex11.drv/palette.c @@ -873,6 +873,49 @@ static inline BOOL colour_is_brighter(RGBQUAD c1, RGBQUAD c2) (c2.rgbRed * c2.rgbRed + c2.rgbGreen * c2.rgbGreen + c2.rgbBlue * c2.rgbBlue); } +/*********************************************************************** + * X11DRV_PALETTE_GetColor + * + * Resolve PALETTEINDEX/PALETTERGB/DIBINDEX COLORREFs to an RGB COLORREF. + */ +COLORREF X11DRV_PALETTE_GetColor( X11DRV_PDEVICE *physDev, COLORREF color ) +{ + HPALETTE hPal = GetCurrentObject(physDev->hdc, OBJ_PAL ); + unsigned char spec_type = color >> 24; + unsigned idx = color & 0xffff; + PALETTEENTRY entry; + RGBQUAD quad; + + switch(spec_type) + { + case 2: /* PALETTERGB */ + idx = GetNearestPaletteIndex( hPal, color ); + /* fall through to PALETTEINDEX */ + + case 1: /* PALETTEINDEX */ + if (!GetPaletteEntries( hPal, idx, 1, &entry )) + { + WARN("PALETTEINDEX(%x) : idx %d is out of bounds, assuming black\n", color, idx); + return 0; + } + return RGB( entry.peRed, entry.peGreen, entry.peBlue ); + + case 0x10: /* DIBINDEX */ + if( GetDIBColorTable( physDev->hdc, idx, 1, &quad ) != 1 ) { + WARN("DIBINDEX(%x) : idx %d is out of bounds, assuming black\n", color , idx); + return 0; + } + return RGB( quad.rgbRed, quad.rgbGreen, quad.rgbBlue ); + + default: + color &= 0xffffff; + /* fall through to RGB */ + + case 0: /* RGB */ + return color; + } +} + /*********************************************************************** * X11DRV_PALETTE_ToPhysical * @@ -898,16 +941,11 @@ int X11DRV_PALETTE_ToPhysical( X11DRV_PDEVICE *physDev, COLORREF color ) unsigned long red, green, blue; unsigned idx = color & 0xffff; - RGBQUAD quad; switch(spec_type) { case 0x10: /* DIBINDEX */ - if( GetDIBColorTable( physDev->hdc, idx, 1, &quad ) != 1 ) { - WARN("DIBINDEX(%x) : idx %d is out of bounds, assuming black\n", color , idx); - return 0; - } - color = RGB( quad.rgbRed, quad.rgbGreen, quad.rgbBlue ); + color = X11DRV_PALETTE_GetColor( physDev, color ); break; case 1: /* PALETTEINDEX */ diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h index f0c0dc62c5a..4412f3e1308 100644 --- a/dlls/winex11.drv/x11drv.h +++ b/dlls/winex11.drv/x11drv.h @@ -502,6 +502,7 @@ extern BOOL X11DRV_IsSolidColor(COLORREF color); extern COLORREF X11DRV_PALETTE_ToLogical(X11DRV_PDEVICE *physDev, int pixel); extern int X11DRV_PALETTE_ToPhysical(X11DRV_PDEVICE *physDev, COLORREF color); +extern COLORREF X11DRV_PALETTE_GetColor( X11DRV_PDEVICE *physDev, COLORREF color ); extern int X11DRV_PALETTE_LookupPixel(ColorShifts *shifts, COLORREF color); extern void X11DRV_PALETTE_ComputeColorShifts(ColorShifts *shifts, unsigned long redMask, unsigned long greenMask, unsigned long blueMask);