DC: use dc.DcLevel.hPal for the palette instead of using dc.PalIndexed and dc.w.hPalette

NtUserSelectPalette: make code more readable

svn path=/trunk/; revision=33332
This commit is contained in:
Timo Kreuzer 2008-05-06 20:44:25 +00:00
parent 6e7c576b23
commit ad58bfe28a
10 changed files with 92 additions and 104 deletions

View file

@ -344,8 +344,6 @@ typedef struct _WIN_DC_INFO
HBITMAP hFirstBitmap; /* Bitmap selected at creation of the DC */
/* #if 0 */
HPALETTE hPalette;
GdiPath path;
/* #endif */

View file

@ -1078,46 +1078,42 @@ HPALETTE STDCALL NtUserSelectPalette(HDC hDC,
HPALETTE hpal,
BOOL ForceBackground)
{
PDC dc;
HPALETTE oldPal = NULL;
PPALGDI PalGDI;
PDC dc;
HPALETTE oldPal = NULL;
PPALGDI PalGDI;
// FIXME: mark the palette as a [fore\back]ground pal
dc = DC_LockDc(hDC);
if (NULL != dc)
// FIXME: mark the palette as a [fore\back]ground pal
dc = DC_LockDc(hDC);
if (!dc)
{
/* Check if this is a valid palette handle */
PalGDI = PALETTE_LockPalette(hpal);
if (NULL != PalGDI)
{
/* Is this a valid palette for this depth? */
if ((dc->w.bitsPerPixel <= 8 && PAL_INDEXED == PalGDI->Mode)
|| (8 < dc->w.bitsPerPixel && PAL_INDEXED != PalGDI->Mode))
{
PALETTE_UnlockPalette(PalGDI);
oldPal = dc->w.hPalette;
dc->w.hPalette = hpal;
}
else if (8 < dc->w.bitsPerPixel && PAL_INDEXED == PalGDI->Mode)
{
PALETTE_UnlockPalette(PalGDI);
oldPal = dc->PalIndexed;
dc->PalIndexed = hpal;
}
else
{
PALETTE_UnlockPalette(PalGDI);
oldPal = NULL;
}
}
else
{
oldPal = NULL;
}
DC_UnlockDc(dc);
return NULL;
}
return oldPal;
/* Check if this is a valid palette handle */
PalGDI = PALETTE_LockPalette(hpal);
if (!PalGDI)
{
DC_UnlockDc(dc);
return NULL;
}
/* Is this a valid palette for this depth? */
if ((dc->w.bitsPerPixel <= 8 && PalGDI->Mode == PAL_INDEXED) ||
(dc->w.bitsPerPixel > 8 && PalGDI->Mode != PAL_INDEXED))
{
oldPal = dc->DcLevel.hpal;
dc->DcLevel.hpal = hpal;
}
else if (8 < dc->w.bitsPerPixel && PAL_INDEXED == PalGDI->Mode)
{
oldPal = dc->DcLevel.hpal;
dc->DcLevel.hpal = hpal;
}
PALETTE_UnlockPalette(PalGDI);
DC_UnlockDc(dc);
return oldPal;
}

View file

@ -115,10 +115,10 @@ NtGdiAlphaBlend(
BitmapSrc = BITMAPOBJ_LockBitmap(DCSrc->w.hBitmap);
/* Create the XLATEOBJ. */
if (DCDest->w.hPalette != 0)
DestPalette = DCDest->w.hPalette;
if (DCSrc->w.hPalette != 0)
SourcePalette = DCSrc->w.hPalette;
if (DCDest->DcLevel.hpal != 0)
DestPalette = DCDest->DcLevel.hpal;
if (DCSrc->DcLevel.hpal != 0)
SourcePalette = DCSrc->DcLevel.hpal;
/* KB41464 details how to convert between mono and color */
if (DCDest->w.bitsPerPixel == 1 && DCSrc->w.bitsPerPixel == 1)
@ -311,11 +311,11 @@ NtGdiBitBlt(
/* Create the XLATEOBJ. */
if (UsesSource)
{
if (DCDest->w.hPalette != 0)
DestPalette = DCDest->w.hPalette;
if (DCDest->DcLevel.hpal != 0)
DestPalette = DCDest->DcLevel.hpal;
if (DCSrc->w.hPalette != 0)
SourcePalette = DCSrc->w.hPalette;
if (DCSrc->DcLevel.hpal != 0)
SourcePalette = DCSrc->DcLevel.hpal;
/* KB41464 details how to convert between mono and color */
if (DCDest->w.bitsPerPixel == 1 && DCSrc->w.bitsPerPixel == 1)
@ -459,11 +459,11 @@ NtGdiTransparentBlt(
xSrc += DCSrc->w.DCOrgX;
ySrc += DCSrc->w.DCOrgY;
if(DCDest->w.hPalette)
DestPalette = DCDest->w.hPalette;
if(DCDest->DcLevel.hpal)
DestPalette = DCDest->DcLevel.hpal;
if(DCSrc->w.hPalette)
SourcePalette = DCSrc->w.hPalette;
if(DCSrc->DcLevel.hpal)
SourcePalette = DCSrc->DcLevel.hpal;
if(!(PalSourceGDI = PALETTE_LockPalette(SourcePalette)))
{
@ -962,11 +962,11 @@ NtGdiStretchBlt(
/* Create the XLATEOBJ. */
if (UsesSource)
{
if (DCDest->w.hPalette != 0)
DestPalette = DCDest->w.hPalette;
if (DCDest->DcLevel.hpal != 0)
DestPalette = DCDest->DcLevel.hpal;
if (DCSrc->w.hPalette != 0)
SourcePalette = DCSrc->w.hPalette;
if (DCSrc->DcLevel.hpal != 0)
SourcePalette = DCSrc->DcLevel.hpal;
/* FIXME: Use the same logic for create XLATEOBJ as in NtGdiBitBlt. */
XlateObj = (XLATEOBJ*)IntEngCreateXlate(0, 0, DestPalette, SourcePalette);

View file

@ -271,8 +271,8 @@ NtGdiGetPixel(HDC hDC, INT XPos, INT YPos)
SurfaceObject = &BitmapObject->SurfObj;
if ( BitmapObject )
{
if ( dc->w.hPalette != 0 )
Pal = dc->w.hPalette;
if ( dc->DcLevel.hpal != 0 )
Pal = dc->DcLevel.hpal;
/* FIXME: Verify if it shouldn't be PAL_BGR! */
XlateObj = (XLATEOBJ*)IntEngCreateXlate ( PAL_RGB, 0, NULL, Pal );
if ( XlateObj )

View file

@ -127,7 +127,7 @@ IntGdiCreateBrushXlate(PDC Dc, GDIBRUSHOBJ *BrushObj, BOOLEAN *Failed)
}
else if (BrushObj->flAttrs & GDIBRUSH_IS_SOLID)
{
Result = IntEngCreateXlate(0, PAL_RGB, Dc->w.hPalette, NULL);
Result = IntEngCreateXlate(0, PAL_RGB, Dc->DcLevel.hpal, NULL);
*Failed = FALSE;
}
else
@ -143,11 +143,11 @@ IntGdiCreateBrushXlate(PDC Dc, GDIBRUSHOBJ *BrushObj, BOOLEAN *Failed)
if (!Dc_Attr) Dc_Attr = &Dc->Dc_Attr;
if (Dc->w.bitsPerPixel != 1)
Result = IntEngCreateSrcMonoXlate(Dc->w.hPalette, Dc_Attr->crForegroundClr, Dc_Attr->crBackgroundClr);
Result = IntEngCreateSrcMonoXlate(Dc->DcLevel.hpal, Dc_Attr->crForegroundClr, Dc_Attr->crBackgroundClr);
}
else if (BrushObj->flAttrs & GDIBRUSH_IS_DIB)
{
Result = IntEngCreateXlate(0, 0, Dc->w.hPalette, Pattern->hDIBPalette);
Result = IntEngCreateXlate(0, 0, Dc->DcLevel.hpal, Pattern->hDIBPalette);
}
BITMAPOBJ_UnlockBitmap(Pattern);

View file

@ -122,7 +122,7 @@ IntAnimatePalette(HPALETTE hPal,
dc = DC_LockDc(hDC);
if (NULL != dc)
{
if (dc->w.hPalette == hPal)
if (dc->DcLevel.hpal == hPal)
{
DC_UnlockDc(dc);
IntGdiRealizePalette(hDC);
@ -301,7 +301,7 @@ COLORREF STDCALL NtGdiGetNearestColor(HDC hDC, COLORREF Color)
dc = DC_LockDc(hDC);
if (NULL != dc)
{
HPALETTE hpal = dc->w.hPalette;
HPALETTE hpal = dc->DcLevel.hpal;
palGDI = (PPALGDI) PALETTE_LockPalette(hpal);
if (!palGDI)
{
@ -431,7 +431,7 @@ IntGetSystemPaletteEntries(HDC hDC,
return 0;
}
palGDI = PALETTE_LockPalette(dc->w.hPalette);
palGDI = PALETTE_LockPalette(dc->DcLevel.hpal);
if (palGDI != NULL)
{
if (pe != NULL)
@ -505,7 +505,7 @@ UINT FASTCALL IntGdiRealizePalette(HDC hDC)
return 0;
systemPalette = NtGdiGetStockObject((INT)DEFAULT_PALETTE);
palGDI = PALETTE_LockPalette(dc->w.hPalette);
palGDI = PALETTE_LockPalette(dc->DcLevel.hpal);
palPtr = (PALOBJ*) palGDI;
if (palGDI == NULL)
@ -536,8 +536,8 @@ UINT FASTCALL IntGdiRealizePalette(HDC hDC)
// Step 1: Create mapping of system palette\DC palette
#ifndef NO_MAPPING
realized = PALETTE_SetMapping(palPtr, 0, palGDI->NumColors,
(dc->w.hPalette != hPrimaryPalette) ||
(dc->w.hPalette == NtGdiGetStockObject(DEFAULT_PALETTE)));
(dc->DcLevel.hpal != hPrimaryPalette) ||
(dc->DcLevel.hpal == NtGdiGetStockObject(DEFAULT_PALETTE)));
#else
realized = 0;
#endif
@ -574,7 +574,7 @@ UINT FASTCALL IntGdiRealizePalette(HDC hDC)
if(dc->DC_Type != DC_TYPE_MEMORY)
{
// Device managed DC
palGDI->logicalToSystem = IntEngCreateXlate(sysMode, palMode, systemPalette, dc->w.hPalette);
palGDI->logicalToSystem = IntEngCreateXlate(sysMode, palMode, systemPalette, dc->DcLevel.hpal);
}
DC_UnlockDc(dc);

View file

@ -135,8 +135,7 @@ NtGdiCreateCompatibleDC(HDC hDC)
NewDC->w.hFirstBitmap = hBitmap;
NewDC->pPDev = OrigDC->pPDev;
NewDC->PalIndexed = OrigDC->PalIndexed;
NewDC->w.hPalette = OrigDC->w.hPalette;
NewDC->DcLevel.hpal = OrigDC->DcLevel.hpal;
nDc_Attr->lTextAlign = oDc_Attr->lTextAlign;
nDc_Attr->ulForegroundClr = oDc_Attr->ulForegroundClr;
nDc_Attr->ulBackgroundClr = oDc_Attr->ulBackgroundClr;
@ -829,8 +828,7 @@ IntGdiCreateDC(PUNICODE_STRING Driver,
if (!CreateAsIC)
{
NewDC->PalIndexed = NtGdiGetStockObject(DEFAULT_PALETTE);
NewDC->w.hPalette = PrimarySurface.DevInfo.hpalDefault;
NewDC->DcLevel.hpal = PrimarySurface.DevInfo.hpalDefault;
nDc_Attr->jROP2 = R2_COPYPEN;
NewDC->erclWindow.top = NewDC->erclWindow.left = 0;
@ -1130,7 +1128,7 @@ NtGdiGetDCObject(HDC hDC, INT ObjectType)
SelObject = Dc_Attr->hbrush;
break;
case GDI_OBJECT_TYPE_PALETTE:
SelObject = dc->w.hPalette;
SelObject = dc->DcLevel.hpal;
break;
case GDI_OBJECT_TYPE_FONT:
SelObject = Dc_Attr->hlfntNew;
@ -1140,6 +1138,7 @@ NtGdiGetDCObject(HDC hDC, INT ObjectType)
break;
case GDI_OBJECT_TYPE_COLORSPACE:
DPRINT1("FIXME: NtGdiGetCurrentObject() ObjectType OBJ_COLORSPACE not supported yet!\n");
// SelObject = dc->DcLevel.pColorSpace.BaseObject.hHmgr; ?
SelObject = NULL;
break;
default:
@ -1196,18 +1195,18 @@ IntGdiGetDCOrg(PDC pDc, PPOINTL ppt)
*ppt = pDc->ptlDCOrig;
return TRUE;
}
BOOL STDCALL
GdiGetDCOrgEx(HDC hDC, PPOINTL ppt, PRECTL prc)
{
PDC pdc;
pdc = DC_LockDc(hDC);
if (!pdc) return FALSE;
*prc = pdc->erclWindow;
*ppt = pdc->ptlDCOrig;
DC_UnlockDc(pdc);
return TRUE;
}
@ -1217,7 +1216,7 @@ IntGetAspectRatioFilter(PDC pDC,
LPSIZE AspectRatio)
{
PDC_ATTR pDc_Attr;
pDc_Attr = pDC->pDc_Attr;
if ( !pDc_Attr ) pDc_Attr = &pDC->Dc_Attr;
@ -1337,8 +1336,7 @@ IntGdiCopyToSaveState(PDC dc, PDC newdc)
nDc_Attr->hlfntNew = Dc_Attr->hlfntNew;
newdc->w.hBitmap = dc->w.hBitmap;
newdc->w.hFirstBitmap = dc->w.hFirstBitmap;
newdc->PalIndexed = dc->PalIndexed;
newdc->w.hPalette = dc->w.hPalette;
newdc->DcLevel.hpal = dc->DcLevel.hpal;
newdc->w.totalExtent = dc->w.totalExtent;
newdc->w.bitsPerPixel = dc->w.bitsPerPixel;
nDc_Attr->jROP2 = Dc_Attr->jROP2;
@ -1444,7 +1442,6 @@ IntGdiCopyFromSaveState(PDC dc, PDC dcs, HDC hDC)
Dc_Attr->szlWindowExt = sDc_Attr->szlWindowExt;
Dc_Attr->ptlViewportOrg = sDc_Attr->ptlViewportOrg;
Dc_Attr->szlViewportExt = sDc_Attr->szlViewportExt;
dc->PalIndexed = dcs->PalIndexed;
if (dc->DC_Type != DC_TYPE_MEMORY)
{
@ -1488,10 +1485,10 @@ IntGdiCopyFromSaveState(PDC dc, PDC dcs, HDC hDC)
IntGdiSetBkColor( hDC, sDc_Attr->crBackgroundClr);
IntGdiSetTextColor( hDC, sDc_Attr->crForegroundClr);
NtUserSelectPalette( hDC, dcs->w.hPalette, FALSE );
NtUserSelectPalette( hDC, dcs->DcLevel.hpal, FALSE );
#if 0
GDISelectPalette16( hDC, dcs->w.hPalette, FALSE );
GDISelectPalette16( hDC, dcs->DcLevel.hpal, FALSE );
#endif
}
@ -1960,12 +1957,12 @@ NtGdiSelectBitmap(
if(pBmp->dib)
{
pDC->w.bitsPerPixel = pBmp->dib->dsBmih.biBitCount;
pDC->w.hPalette = pBmp->hDIBPalette;
pDC->DcLevel.hpal = pBmp->hDIBPalette;
}
else
{
pDC->w.bitsPerPixel = BitsPerFormat(pBmp->SurfObj.iBitmapFormat);
pDC->w.hPalette = ((GDIDEVICE *)pDC->pPDev)->DevInfo.hpalDefault;
pDC->DcLevel.hpal = ((GDIDEVICE *)pDC->pPDev)->DevInfo.hpalDefault;
}
/* Regenerate the XLATEOBJs. */
@ -2333,7 +2330,7 @@ NtGdiGetAndSetDCDword(
break;
}
SafeResult = Dc_Attr->flFontMapper;
Dc_Attr->flFontMapper = dwIn;
Dc_Attr->flFontMapper = dwIn;
break;
case GdiGetSetMapMode:
SafeResult = IntGdiSetMapMode( dc, dwIn);
@ -2479,7 +2476,7 @@ DC_AllocDC(PUNICODE_STRING Driver)
Dc_Attr->hlfntNew = NtGdiGetStockObject(SYSTEM_FONT);
TextIntRealizeFont(Dc_Attr->hlfntNew);
NewDC->w.hPalette = NtGdiGetStockObject(DEFAULT_PALETTE);
NewDC->DcLevel.hpal = NtGdiGetStockObject(DEFAULT_PALETTE);
DC_UnlockDc(NewDC);
@ -2757,7 +2754,7 @@ IntGdiReferencePdev(PGDIDEVICE pPDev)
}
VOID FASTCALL
IntGdiUnreferencePdev(PGDIDEVICE pPDev, DWORD CleanUpType)
IntGdiUnreferencePdev(PGDIDEVICE pPDev, DWORD CleanUpType)
{
IntGdiAcquireSemaphore(hsemDriverMgmt);
pPDev->cPdevRefs--;

View file

@ -1,4 +1,5 @@
/*
* $Id$
*
* ReactOS W32 Subsystem
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
@ -382,7 +383,7 @@ NtGdiSetDIBitsToDeviceInternal(
SourceSize.cx = bmi->bmiHeader.biWidth;
SourceSize.cy = ScanLines;
DIBWidth = DIB_GetDIBWidthBytes(SourceSize.cx, bmi->bmiHeader.biBitCount);
ProbeForRead(Bits, DIBWidth * abs(bmi->bmiHeader.biHeight), 1);
hSourceBitmap = EngCreateBitmap(SourceSize,
DIBWidth,
@ -403,7 +404,7 @@ NtGdiSetDIBitsToDeviceInternal(
_SEH_LEAVE;
}
/* Obtain destination palette from the DC */
pDCPalette = PALETTE_LockPalette(((GDIDEVICE *)pDC->pPDev)->DevInfo.hpalDefault);
if (!pDCPalette)
@ -415,7 +416,7 @@ NtGdiSetDIBitsToDeviceInternal(
DDBPaletteType = pDCPalette->Mode;
DDBPalette = ((GDIDEVICE *)pDC->pPDev)->DevInfo.hpalDefault;
PALETTE_UnlockPalette(pDCPalette);
DIBPalette = BuildDIBPalette(bmi, (PINT)&DIBPaletteType);
if (!DIBPalette)
{
@ -504,7 +505,7 @@ NtGdiGetDIBitsInternal(HDC hDC,
return 0;
}
/* Source palette obtained from the windows hdc */
hSourcePalette = Dc->w.hPalette;
hSourcePalette = Dc->DcLevel.hpal;
DC_UnlockDc(Dc);
/* don't do anything if we fail this */
@ -909,7 +910,7 @@ IntCreateDIBitmap(PDC Dc,
1,
NULL);
}
if (height < 0)
height = -height;
@ -1258,7 +1259,7 @@ DIB_MapPaletteColors(PDC dc, CONST BITMAPINFO* lpbmi)
USHORT *lpIndex;
PPALGDI palGDI;
palGDI = PALETTE_LockPalette(dc->w.hPalette);
palGDI = PALETTE_LockPalette(dc->DcLevel.hpal);
if (NULL == palGDI)
{
@ -1269,11 +1270,7 @@ DIB_MapPaletteColors(PDC dc, CONST BITMAPINFO* lpbmi)
if (palGDI->Mode != PAL_INDEXED)
{
PALETTE_UnlockPalette(palGDI);
palGDI = PALETTE_LockPalette(dc->PalIndexed);
if (palGDI->Mode != PAL_INDEXED)
{
return NULL;
}
return NULL;
}
nNumColors = 1 << lpbmi->bmiHeader.biBitCount;

View file

@ -64,7 +64,7 @@ IntGdiPolygon(PDC dc,
Dc_Attr = dc->pDc_Attr;
if (!Dc_Attr) Dc_Attr = &dc->Dc_Attr;
BitmapObj = BITMAPOBJ_LockBitmap(dc->w.hBitmap);
/* FIXME - BitmapObj can be NULL!!!! don't assert but handle this case gracefully! */
ASSERT(BitmapObj);
@ -1033,7 +1033,7 @@ IntRectangle(PDC dc,
RECTL DestRect;
MIX Mix;
PDC_ATTR Dc_Attr;
ASSERT ( dc ); // caller's responsibility to set this up
/* FIXME - BitmapObj can be NULL!!! Don't assert but handle this case gracefully! */
ASSERT ( BitmapObj );
@ -1550,13 +1550,13 @@ IntGdiGradientFill(
/* FIXME - BitmapObj can be NULL!!! Don't assert but handle this case gracefully! */
ASSERT(BitmapObj);
PalDestGDI = PALETTE_LockPalette(dc->w.hPalette);
PalDestGDI = PALETTE_LockPalette(dc->DcLevel.hpal);
/* FIXME - PalDestGDI can be NULL!!! Don't assert but handle this case gracefully! */
ASSERT(PalDestGDI);
Mode = PalDestGDI->Mode;
PALETTE_UnlockPalette(PalDestGDI);
XlateObj = (XLATEOBJ*)IntEngCreateXlate(Mode, PAL_RGB, dc->w.hPalette, NULL);
XlateObj = (XLATEOBJ*)IntEngCreateXlate(Mode, PAL_RGB, dc->DcLevel.hpal, NULL);
ASSERT(XlateObj);
Ret = IntEngGradientFill(&BitmapObj->SurfObj,

View file

@ -1629,7 +1629,7 @@ NtGdiExtTextOutW(
YStart = Start.y + dc->w.DCOrgY;
/* Create the brushes */
PalDestGDI = PALETTE_LockPalette(dc->w.hPalette);
PalDestGDI = PALETTE_LockPalette(dc->DcLevel.hpal);
if ( !PalDestGDI )
Mode = PAL_RGB;
else
@ -1637,7 +1637,7 @@ NtGdiExtTextOutW(
Mode = PalDestGDI->Mode;
PALETTE_UnlockPalette(PalDestGDI);
}
XlateObj = (XLATEOBJ*)IntEngCreateXlate(Mode, PAL_RGB, dc->w.hPalette, NULL);
XlateObj = (XLATEOBJ*)IntEngCreateXlate(Mode, PAL_RGB, dc->DcLevel.hpal, NULL);
if ( !XlateObj )
{
goto fail;
@ -1667,7 +1667,7 @@ NtGdiExtTextOutW(
}
IntGdiInitBrushInstance(&BrushBgInst, BrushBg, NULL);
}
XlateObj2 = (XLATEOBJ*)IntEngCreateXlate(PAL_RGB, Mode, NULL, dc->w.hPalette);
XlateObj2 = (XLATEOBJ*)IntEngCreateXlate(PAL_RGB, Mode, NULL, dc->DcLevel.hpal);
if ( !XlateObj2 )
{
goto fail;