From 47b812dde4ac5ba2a344b0ea28fc8b766b3adb1d Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Wed, 28 Apr 2004 18:38:07 +0000 Subject: [PATCH] - Simplified handling of palettes selected into device contexts. Now DC->w.hPalette should always point to palette object and shoudn't be NULL. - Fixed bitfield conversion when creating Color -> Mono XLATEOBJs. Fixes bug #275. svn path=/trunk/; revision=9235 --- reactos/subsys/win32k/eng/xlate.c | 6 ++--- reactos/subsys/win32k/objects/bitmaps.c | 32 +------------------------ reactos/subsys/win32k/objects/color.c | 14 +++++++++-- reactos/subsys/win32k/objects/dc.c | 13 +++++----- 4 files changed, 23 insertions(+), 42 deletions(-) diff --git a/reactos/subsys/win32k/eng/xlate.c b/reactos/subsys/win32k/eng/xlate.c index d9c54c9df8b..c139b944273 100644 --- a/reactos/subsys/win32k/eng/xlate.c +++ b/reactos/subsys/win32k/eng/xlate.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: xlate.c,v 1.32 2004/04/09 20:39:10 navaraf Exp $ +/* $Id: xlate.c,v 1.33 2004/04/28 18:38:07 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -445,9 +445,9 @@ XLATEOBJ * STDCALL IntEngCreateMonoXlate( SourcePalGDI = PALETTE_LockPalette(PaletteSource); BitMasksFromPal(SourcePalType, SourcePalGDI, &XlateGDI->RedMask, &XlateGDI->BlueMask, &XlateGDI->GreenMask); - XlateGDI->RedShift = CalculateShift(0xFF0000) - CalculateShift(XlateGDI->RedMask); + XlateGDI->RedShift = CalculateShift(0xFF) - CalculateShift(XlateGDI->RedMask); XlateGDI->GreenShift = CalculateShift(0xFF00) - CalculateShift(XlateGDI->GreenMask); - XlateGDI->BlueShift = CalculateShift(0xFF) - CalculateShift(XlateGDI->BlueMask); + XlateGDI->BlueShift = CalculateShift(0xFF0000) - CalculateShift(XlateGDI->BlueMask); XlateGDI->BackgroundColor = ShiftAndMask(XlateGDI, BackgroundColor); PALETTE_UnlockPalette(PaletteSource); } diff --git a/reactos/subsys/win32k/objects/bitmaps.c b/reactos/subsys/win32k/objects/bitmaps.c index a1d49b6b695..71fb76aa4ea 100644 --- a/reactos/subsys/win32k/objects/bitmaps.c +++ b/reactos/subsys/win32k/objects/bitmaps.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: bitmaps.c,v 1.70 2004/04/25 11:34:13 weiden Exp $ */ +/* $Id: bitmaps.c,v 1.71 2004/04/28 18:38:07 navaraf Exp $ */ #undef WIN32_LEAN_AND_MEAN #include #include @@ -153,22 +153,10 @@ NtGdiBitBlt( } if (DCDest->w.hPalette != 0) - { DestPalette = DCDest->w.hPalette; - } - else - { - DestPalette = NtGdiGetStockObject(DEFAULT_PALETTE); - } if (UsesSource && DCSrc->w.hPalette != 0) - { SourcePalette = DCSrc->w.hPalette; - } - else - { - SourcePalette = NtGdiGetStockObject(DEFAULT_PALETTE); - } PalSourceGDI = PALETTE_LockPalette(SourcePalette); if (NULL == PalSourceGDI) @@ -319,13 +307,9 @@ NtGdiTransparentBlt( if(DCDest->w.hPalette) DestPalette = DCDest->w.hPalette; - else - DestPalette = NtGdiGetStockObject(DEFAULT_PALETTE); if(DCSrc->w.hPalette) SourcePalette = DCSrc->w.hPalette; - else - SourcePalette = NtGdiGetStockObject(DEFAULT_PALETTE); if(!(PalSourceGDI = PALETTE_LockPalette(SourcePalette))) { @@ -652,8 +636,6 @@ NtGdiGetPixel(HDC hDC, INT XPos, INT YPos) { if ( dc->w.hPalette != 0 ) Pal = dc->w.hPalette; - else - Pal = NtGdiGetStockObject(DEFAULT_PALETTE); PalGDI = PALETTE_LockPalette(Pal); if ( PalGDI ) { @@ -1203,22 +1185,10 @@ NtGdiStretchBlt( } if (DCDest->w.hPalette != 0) - { DestPalette = DCDest->w.hPalette; - } - else - { - DestPalette = NtGdiGetStockObject(DEFAULT_PALETTE); - } if (UsesSource && DCSrc->w.hPalette != 0) - { SourcePalette = DCSrc->w.hPalette; - } - else - { - SourcePalette = NtGdiGetStockObject(DEFAULT_PALETTE); - } PalSourceGDI = PALETTE_LockPalette(SourcePalette); if (NULL == PalSourceGDI) diff --git a/reactos/subsys/win32k/objects/color.c b/reactos/subsys/win32k/objects/color.c index aaa0baa8563..3011243c395 100644 --- a/reactos/subsys/win32k/objects/color.c +++ b/reactos/subsys/win32k/objects/color.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: color.c,v 1.36 2004/04/09 20:03:20 navaraf Exp $ */ +/* $Id: color.c,v 1.37 2004/04/28 18:38:07 navaraf Exp $ */ // FIXME: Use PXLATEOBJ logicalToSystem instead of int *mapping @@ -167,7 +167,7 @@ COLORREF STDCALL NtGdiGetNearestColor(HDC hDC, dc = DC_LockDc(hDC); if (NULL != dc) { - HPALETTE hpal = (dc->w.hPalette) ? dc->w.hPalette : NtGdiGetStockObject(DEFAULT_PALETTE); + HPALETTE hpal = dc->w.hPalette; palGDI = (PPALGDI) PALETTE_LockPalette(hpal); if (!palGDI) { @@ -538,6 +538,15 @@ INT STDCALL COLOR_PaletteLookupPixel(PALETTEENTRY *palPalEntry, INT size, COLORREF STDCALL COLOR_LookupNearestColor( PALETTEENTRY* palPalEntry, int size, COLORREF color ) { +#if 1 + INT index; + + index = COLOR_PaletteLookupPixel(palPalEntry, size, NULL, color, FALSE); + return RGB( + palPalEntry[index].peRed, + palPalEntry[index].peGreen, + palPalEntry[index].peBlue); +#else unsigned char spec_type = color >> 24; int i; PALETTEENTRY *COLOR_sysPal = (PALETTEENTRY*)ReturnSystemPalette(); @@ -559,6 +568,7 @@ COLORREF STDCALL COLOR_LookupNearestColor( PALETTEENTRY* palPalEntry, int size, color &= 0x00ffffff; return (0x00ffffff & *(COLORREF*)(COLOR_sysPal + COLOR_PaletteLookupPixel(COLOR_sysPal, 256, NULL, color, FALSE))); +#endif } int STDCALL COLOR_PaletteLookupExactIndex( PALETTEENTRY* palPalEntry, int size, diff --git a/reactos/subsys/win32k/objects/dc.c b/reactos/subsys/win32k/objects/dc.c index fcbb256d011..9dd8b4bc800 100644 --- a/reactos/subsys/win32k/objects/dc.c +++ b/reactos/subsys/win32k/objects/dc.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: dc.c,v 1.132 2004/04/25 20:05:30 weiden Exp $ +/* $Id: dc.c,v 1.133 2004/04/28 18:38:07 navaraf Exp $ * * DC.C - Device context functions * @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include "../eng/clip.h" @@ -1102,8 +1103,8 @@ NtGdiGetDCState(HDC hDC) newdc->w.hFirstBitmap = dc->w.hFirstBitmap; #if 0 newdc->w.hDevice = dc->w.hDevice; - newdc->w.hPalette = dc->w.hPalette; #endif + newdc->w.hPalette = dc->w.hPalette; newdc->w.totalExtent = dc->w.totalExtent; newdc->w.bitsPerPixel = dc->w.bitsPerPixel; newdc->w.ROPmode = dc->w.ROPmode; @@ -1271,6 +1272,8 @@ NtGdiSetDCState ( HDC hDC, HDC hDCSave ) NtGdiSetBkColor( hDC, dcs->w.backgroundColor); NtGdiSetTextColor( hDC, dcs->w.textColor); + NtGdiSelectPalette( hDC, dcs->w.hPalette, FALSE ); + #if 0 GDISelectPalette16( hDC, dcs->w.hPalette, FALSE ); #endif @@ -2085,6 +2088,8 @@ DC_AllocDC(PUNICODE_STRING Driver) NewDC->w.hFont = NtGdiGetStockObject(SYSTEM_FONT); TextIntRealizeFont(NewDC->w.hFont); + NewDC->w.hPalette = NtGdiGetStockObject(DEFAULT_PALETTE); + DC_UnlockDc(hDC); return hDC; @@ -2294,8 +2299,6 @@ IntGetDCColor(HDC hDC, ULONG Object) if(dc->w.hPalette) Pal = dc->w.hPalette; - else - Pal = NtGdiGetStockObject(DEFAULT_PALETTE); Result = CLR_INVALID; @@ -2432,8 +2435,6 @@ IntSetDCColor(HDC hDC, ULONG Object, COLORREF Color) if(dc->w.hPalette) Pal = dc->w.hPalette; - else - Pal = NtGdiGetStockObject(DEFAULT_PALETTE); Result = CLR_INVALID;