From 376a7308554aa3c73f3760622317c8fad8e7955a Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Sun, 7 Nov 2010 05:15:13 +0200 Subject: winex11: Add X11DRV_PALETTE_GetColor function to resolve any COLORREF to an RGB --- dlls/winex11.drv/palette.c | 50 ++++++++++++++++++++++++++++++++++++++----- dlls/winex11.drv/x11drv.h | 1 + 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/dlls/winex11.drv/palette.c b/dlls/winex11.drv/palette.c index adff6c1..a7a6b35 100644 --- a/dlls/winex11.drv/palette.c +++ b/dlls/winex11.drv/palette.c @@ -874,6 +874,49 @@ static inline BOOL colour_is_brighter(RGBQUAD c1, RGBQUAD c2) } /*********************************************************************** + * 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 * * Return the physical color closest to 'color'. @@ -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 f0c0dc6..4412f3e 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); -- 1.7.1