Create palette handles as gdiobj handles which can be used by usermode

svn path=/trunk/; revision=5892
This commit is contained in:
Gé van Geldorp 2003-08-28 12:35:59 +00:00
parent 1847e2839e
commit 4ab5d75768
11 changed files with 371 additions and 187 deletions

View file

@ -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: objects.h,v 1.17 2003/08/12 20:08:45 royce Exp $
/* $Id: objects.h,v 1.18 2003/08/28 12:35:59 gvg Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -91,18 +91,6 @@ typedef struct _FONTGDI {
TEXTMETRICW TextMetric;
} FONTGDI, *PFONTGDI;
typedef struct _PALGDI {
ENGOBJ Header;
PALOBJ PalObj;
ULONG Mode; // PAL_INDEXED, PAL_BITFIELDS, PAL_RGB, PAL_BGR
ULONG NumColors;
ULONG *IndexedColors;
ULONG RedMask;
ULONG GreenMask;
ULONG BlueMask;
} PALGDI, *PPALGDI;
typedef struct _PATHGDI {
ENGOBJ Header;
PATHOBJ PathObj;

View file

@ -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: palette.c,v 1.16 2003/07/11 15:59:37 royce Exp $
/* $Id: palette.c,v 1.17 2003/08/28 12:35:59 gvg Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -29,6 +29,7 @@
#include <ddk/winddi.h>
#include <include/object.h>
#include <include/palette.h>
#include "handle.h"
#define NDEBUG
@ -45,36 +46,7 @@ EngCreatePalette(ULONG Mode,
ULONG Green,
ULONG Blue)
{
HPALETTE NewPalette;
PALGDI *PalGDI;
NewPalette = (HPALETTE)CreateGDIHandle(sizeof(PALGDI), sizeof(PALOBJ));
if( !ValidEngHandle( NewPalette ) )
return 0;
PalGDI = (PALGDI*) AccessInternalObject( (ULONG) NewPalette );
ASSERT( PalGDI );
PalGDI->Mode = Mode;
if(Colors != NULL)
{
PalGDI->IndexedColors = ExAllocatePool(NonPagedPool, sizeof(PALETTEENTRY) * NumColors);
RtlCopyMemory(PalGDI->IndexedColors, Colors, sizeof(PALETTEENTRY) * NumColors);
}
if(Mode==PAL_INDEXED)
{
PalGDI->NumColors = NumColors;
} else
if(Mode==PAL_BITFIELDS)
{
PalGDI->RedMask = Red;
PalGDI->GreenMask = Green;
PalGDI->BlueMask = Blue;
}
return NewPalette;
return PALETTE_AllocPalette(Mode, NumColors, Colors, Red, Green, Blue);
}
/*
@ -83,8 +55,7 @@ EngCreatePalette(ULONG Mode,
BOOL STDCALL
EngDeletePalette(IN HPALETTE Palette)
{
FreeGDIHandle((ULONG)Palette);
return TRUE;
return PALETTE_FreePalette(Palette);
}
/*

View file

@ -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: surface.c,v 1.24 2003/08/25 23:24:02 rcampbell Exp $
/* $Id: surface.c,v 1.25 2003/08/28 12:35:59 gvg Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -340,7 +340,9 @@ EngLockSurface(IN HSURF Surface)
* FIXME - don't know if GDIOBJ_LockObj's return value is a SURFOBJ or not...
* also, what is HSURF's correct magic #?
*/
#ifdef TODO
GDIOBJ_LockObj ( Surface, GDI_OBJECT_TYPE_DONTCARE );
#endif
return (SURFOBJ*)AccessUserObject((ULONG)Surface);
}
@ -353,6 +355,8 @@ EngUnlockSurface(IN SURFOBJ *Surface)
/*
* FIXME what is HSURF's correct magic #?
*/
#ifdef TODO
GDIOBJ_UnlockObj ( Surface->hsurf, GDI_OBJECT_TYPE_DONTCARE );
#endif
}
/* EOF */

View file

@ -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.22 2003/08/17 17:32:58 royce Exp $
/* $Id: xlate.c,v 1.23 2003/08/28 12:35:59 gvg Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -34,6 +34,7 @@
#include <ddk/ntddvid.h>
#include <include/object.h>
#include <include/palette.h>
#include "handle.h"
#define NDEBUG
@ -223,11 +224,15 @@ XLATEOBJ * STDCALL IntEngCreateXlate(USHORT DestPalType, USHORT SourcePalType,
if (NULL != PaletteSource)
{
SourcePalGDI = (PALGDI*)AccessInternalObject((ULONG)PaletteSource);
SourcePalGDI = PALETTE_LockPalette(PaletteSource);
}
if (NULL != PaletteDest)
if (PaletteDest == PaletteSource)
{
DestPalGDI = (PALGDI*)AccessInternalObject((ULONG)PaletteDest);
DestPalGDI = SourcePalGDI;
}
else if (NULL != PaletteDest)
{
DestPalGDI = PALETTE_LockPalette(PaletteDest);
}
XlateObj->iSrcType = SourcePalType;
@ -262,6 +267,14 @@ XLATEOBJ * STDCALL IntEngCreateXlate(USHORT DestPalType, USHORT SourcePalType,
((DestPalType == PAL_BGR) && (SourcePalType == PAL_BGR)) )
{
XlateObj->flXlate |= XO_TRIVIAL;
if (NULL != PaletteSource)
{
PALETTE_UnlockPalette(PaletteSource);
}
if (NULL != PaletteDest && PaletteDest != PaletteSource)
{
PALETTE_UnlockPalette(PaletteDest);
}
return XlateObj;
}
@ -276,6 +289,14 @@ XLATEOBJ * STDCALL IntEngCreateXlate(USHORT DestPalType, USHORT SourcePalType,
XlateObj->flXlate |= XO_TRIVIAL;
}
XlateGDI->UseShiftAndMask = TRUE;
if (NULL != PaletteSource)
{
PALETTE_UnlockPalette(PaletteSource);
}
if (NULL != PaletteDest && PaletteDest != PaletteSource)
{
PALETTE_UnlockPalette(PaletteDest);
}
return XlateObj;
}
@ -312,9 +333,13 @@ XLATEOBJ * STDCALL IntEngCreateXlate(USHORT DestPalType, USHORT SourcePalType,
// Converting from indexed to RGB
#ifdef TODO
XLATEOBJ_cGetPalette(XlateObj, XO_SRCPALETTE,
SourcePalGDI->NumColors,
XlateGDI->translationTable);
#else
RtlCopyMemory(XlateGDI->translationTable, SourcePalGDI->IndexedColors, sizeof(ULONG) * SourcePalGDI->NumColors);
#endif
if (PAL_BITFIELDS == XlateObj->iDstType)
{
for (i = 0; i < SourcePalGDI->NumColors; i++)
@ -336,17 +361,30 @@ XLATEOBJ * STDCALL IntEngCreateXlate(USHORT DestPalType, USHORT SourcePalType,
// function anyways if pulXlate is NULL and Dest is PAL_INDEXED
// Converting from RGB to indexed
#ifdef TODO
XLATEOBJ_cGetPalette(XlateObj, XO_DESTPALETTE, DestPalGDI->NumColors, XlateGDI->translationTable);
#else
RtlCopyMemory(XlateGDI->translationTable, DestPalGDI->IndexedColors, sizeof(ULONG) * DestPalGDI->NumColors);
#endif
}
}
// FIXME: Add support for XO_TO_MONO
if (NULL != PaletteSource)
{
PALETTE_UnlockPalette(PaletteSource);
}
if (NULL != PaletteDest && PaletteDest != PaletteSource)
{
PALETTE_UnlockPalette(PaletteDest);
}
return XlateObj;
}
VOID FASTCALL EngDeleteXlate(XLATEOBJ *XlateObj)
{
HPALETTE HXlate = (HPALETTE)AccessHandleFromUserObject(XlateObj);
HANDLE HXlate = (HANDLE)AccessHandleFromUserObject(XlateObj);
XLATEGDI *XlateGDI = (XLATEGDI*)AccessInternalObject((ULONG)HXlate);
if(XlateGDI->translationTable!=NULL)
@ -382,6 +420,7 @@ XLATEOBJ_iXlate(XLATEOBJ *XlateObj,
{
PALGDI *PalGDI;
XLATEGDI *XlateGDI = (XLATEGDI*)AccessInternalObjectFromUserObject(XlateObj);
ULONG Closest;
// Return the original color if there's no color translation object
if(!XlateObj) return Color;
@ -400,10 +439,12 @@ XLATEOBJ_iXlate(XLATEOBJ *XlateObj,
// FIXME: won't work if destination isn't indexed
// Extract the destination palette
PalGDI = (PALGDI*)AccessInternalObject((ULONG)XlateGDI->DestPal);
PalGDI = PALETTE_LockPalette(XlateGDI->DestPal);
// Return closest match for the given color
return ClosestColorMatch(XlateGDI, Color, PalGDI->IndexedColors, PalGDI->NumColors);
Closest = ClosestColorMatch(XlateGDI, Color, PalGDI->IndexedColors, PalGDI->NumColors);
PALETTE_UnlockPalette(XlateGDI->DestPal);
return Closest;
} else
if(XlateObj->iSrcType == PAL_INDEXED)
{
@ -438,9 +479,11 @@ XLATEOBJ_cGetPalette(XLATEOBJ *XlateObj,
HPal = XlateGDI->DestPal;
}
PalGDI = (PALGDI*)AccessInternalObject((ULONG)HPal);
PalGDI = PALETTE_LockPalette(HPal);
RtlCopyMemory(OutPal, PalGDI->IndexedColors, sizeof(ULONG)*cPal);
PALETTE_UnlockPalette(HPal);
return i;
}
/* EOF */

View file

@ -13,6 +13,28 @@ typedef struct {
int max;
} ColorShifts;
typedef struct _PALGDI {
PALOBJ PalObj;
HPALETTE Self;
ULONG Mode; // PAL_INDEXED, PAL_BITFIELDS, PAL_RGB, PAL_BGR
ULONG NumColors;
ULONG *IndexedColors;
ULONG RedMask;
ULONG GreenMask;
ULONG BlueMask;
} PALGDI, *PPALGDI;
HPALETTE FASTCALL PALETTE_AllocPalette(ULONG Mode,
ULONG NumColors,
ULONG *Colors,
ULONG Red,
ULONG Green,
ULONG Blue);
#define PALETTE_FreePalette(hPalette) GDIOBJ_FreeObj((HGDIOBJ)hPalette, GDI_OBJECT_TYPE_PALETTE, GDIOBJFLAG_DEFAULT)
#define PALETTE_LockPalette(hPalette) ((PPALGDI)GDIOBJ_LockObj((HGDIOBJ)hPalette, GDI_OBJECT_TYPE_PALETTE))
#define PALETTE_UnlockPalette(hPalette) GDIOBJ_UnlockObj((HGDIOBJ)hPalette, GDI_OBJECT_TYPE_PALETTE)
HPALETTE FASTCALL PALETTE_Init (VOID);
VOID FASTCALL PALETTE_ValidateFlags (PALETTEENTRY* lpPalE, INT size);
INT STDCALL PALETTE_SetMapping(PPALOBJ palPtr, UINT uStart, UINT uNum, BOOL mapOnly);

View file

@ -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.36 2003/08/25 23:24:02 rcampbell Exp $ */
/* $Id: bitmaps.c,v 1.37 2003/08/28 12:35:59 gvg Exp $ */
#undef WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdlib.h>
@ -27,6 +27,7 @@
#include <include/inteng.h>
#include <include/eng.h>
#include <include/surface.h>
#include <include/palette.h>
#define NDEBUG
#include <win32k/debug1.h>
@ -58,6 +59,7 @@ BOOL STDCALL NtGdiBitBlt(HDC hDCDest,
PPALGDI PalDestGDI, PalSourceGDI;
PXLATEOBJ XlateObj = NULL;
HPALETTE SourcePalette, DestPalette;
ULONG SourceMode, DestMode;
if ( !GDIOBJ_LockMultipleObj(Lock, sizeof(Lock)/sizeof(Lock[0])) )
{
@ -97,30 +99,54 @@ BOOL STDCALL NtGdiBitBlt(HDC hDCDest,
SurfGDISrc = (PSURFGDI)AccessInternalObjectFromUserObject(SurfSrc);
// Retrieve the logical palette of the destination DC
DCLogPal = (PPALOBJ)AccessUserObject((ULONG)DCDest->w.hPalette);
DCLogPal = (PPALOBJ)PALETTE_LockPalette(DCDest->w.hPalette);
if(DCLogPal)
if(DCLogPal->logicalToSystem)
XlateObj = DCLogPal->logicalToSystem;
{
if(DCLogPal->logicalToSystem)
{
XlateObj = DCLogPal->logicalToSystem;
}
PALETTE_UnlockPalette(DCDest->w.hPalette);
}
// If the source and destination formats differ, create an XlateObj [what if we already have one??]
if((BitsPerFormat(SurfDest->iBitmapFormat) != BitsPerFormat(SurfSrc->iBitmapFormat)) && (XlateObj == NULL))
{
if(DCDest->w.hPalette != 0)
DestPalette = DCDest->w.hPalette;
else
DestPalette = NtGdiGetStockObject(DEFAULT_PALETTE);
{
if(DCDest->w.hPalette != 0)
{
DestPalette = DCDest->w.hPalette;
}
else
{
DestPalette = NtGdiGetStockObject(DEFAULT_PALETTE);
}
if(DCSrc->w.hPalette != 0)
SourcePalette = DCSrc->w.hPalette;
else
SourcePalette = NtGdiGetStockObject(DEFAULT_PALETTE);
if(DCSrc->w.hPalette != 0)
{
SourcePalette = DCSrc->w.hPalette;
}
else
{
SourcePalette = NtGdiGetStockObject(DEFAULT_PALETTE);
}
PalDestGDI = (PPALGDI)AccessInternalObject((ULONG)DestPalette);
PalSourceGDI = (PPALGDI)AccessInternalObject((ULONG)SourcePalette);
PalSourceGDI = PALETTE_LockPalette(SourcePalette);
SourceMode = PalSourceGDI->Mode;
PALETTE_UnlockPalette(SourcePalette);
if (DestPalette == SourcePalette)
{
DestMode = SourceMode;
}
else
{
PalDestGDI = PALETTE_LockPalette(DestPalette);
DestMode = PalDestGDI->Mode;
PALETTE_UnlockPalette(DestPalette);
}
XlateObj = (PXLATEOBJ)IntEngCreateXlate(PalDestGDI->Mode, PalSourceGDI->Mode, DestPalette, SourcePalette);
XlateAlloc = TRUE;
XlateObj = (PXLATEOBJ)IntEngCreateXlate(DestMode, SourceMode, DestPalette, SourcePalette);
XlateAlloc = TRUE;
}
// Perform the bitblt operation
@ -131,7 +157,7 @@ BOOL STDCALL NtGdiBitBlt(HDC hDCDest,
if (SurfDestAlloc) ExFreePool(SurfDest);
if (SurfSrcAlloc) ExFreePool(SurfSrc);
GDIOBJ_UnlockMultipleObj(Lock, sizeof(Lock)/sizeof(Lock[0]));
GDIOBJ_UnlockMultipleObj(Lock, sizeof(Lock) / sizeof(Lock[0]));
return Status;
}

View file

@ -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.22 2003/08/24 21:45:40 fireball Exp $ */
/* $Id: color.c,v 1.23 2003/08/28 12:35:59 gvg Exp $ */
// FIXME: Use PXLATEOBJ logicalToSystem instead of int *mapping
@ -167,14 +167,14 @@ HPALETTE STDCALL NtGdiCreatePalette(CONST PLOGPALETTE palette)
{
PPALOBJ PalObj;
HPALETTE NewPalette = (HPALETTE)EngCreatePalette(
HPALETTE NewPalette = PALETTE_AllocPalette(
PAL_INDEXED,
palette->palNumEntries,
(PULONG)palette->palPalEntry,
0, 0, 0);
ULONG size;
PalObj = (PPALOBJ)AccessUserObject ( (ULONG)NewPalette );
PalObj = (PPALOBJ) PALETTE_LockPalette(NewPalette);
size = sizeof(LOGPALETTE) + (palette->palNumEntries * sizeof(PALETTEENTRY));
PalObj->logpalette = ExAllocatePool(NonPagedPool, size);
@ -182,6 +182,8 @@ HPALETTE STDCALL NtGdiCreatePalette(CONST PLOGPALETTE palette)
PALETTE_ValidateFlags(PalObj->logpalette->palPalEntry, PalObj->logpalette->palNumEntries);
PalObj->logicalToSystem = NULL;
PALETTE_UnlockPalette(NewPalette);
return NewPalette;
}
@ -198,21 +200,22 @@ COLORREF STDCALL NtGdiGetNearestColor(HDC hDC,
PDC dc;
PPALOBJ palObj;
if( (dc = DC_LockDc(hDC) ) )
{
HPALETTE hpal = (dc->w.hPalette)? dc->w.hPalette : NtGdiGetStockObject(DEFAULT_PALETTE);
palObj = (PPALOBJ)AccessUserObject((ULONG)hpal);
if (!palObj) {
// GDI_ReleaseObj(hdc);
return nearest;
}
dc = DC_LockDc(hDC);
if (NULL != dc)
{
HPALETTE hpal = (dc->w.hPalette) ? dc->w.hPalette : NtGdiGetStockObject(DEFAULT_PALETTE);
palObj = (PPALOBJ) PALETTE_LockPalette(hpal);
if (!palObj)
{
DC_UnlockDc(hDC);
return nearest;
}
nearest = COLOR_LookupNearestColor(palObj->logpalette->palPalEntry,
palObj->logpalette->palNumEntries, Color);
// FIXME: release hpal!!
// GDI_ReleaseObj( hpal );
DC_UnlockDc( hDC );
}
nearest = COLOR_LookupNearestColor(palObj->logpalette->palPalEntry,
palObj->logpalette->palNumEntries, Color);
PALETTE_UnlockPalette(hpal);
DC_UnlockDc( hDC );
}
return nearest;
}
@ -220,15 +223,15 @@ COLORREF STDCALL NtGdiGetNearestColor(HDC hDC,
UINT STDCALL NtGdiGetNearestPaletteIndex(HPALETTE hpal,
COLORREF Color)
{
PPALOBJ palObj = (PPALOBJ)AccessUserObject((ULONG)hpal);
PPALOBJ palObj = (PPALOBJ) PALETTE_LockPalette(hpal);
UINT index = 0;
if( palObj )
{
// Return closest match for the given RGB color
index = COLOR_PaletteLookupPixel(palObj->logpalette->palPalEntry, palObj->logpalette->palNumEntries, NULL, Color, FALSE);
// GDI_ReleaseObj( hpalette );
}
if (NULL != palObj)
{
/* Return closest match for the given RGB color */
index = COLOR_PaletteLookupPixel(palObj->logpalette->palPalEntry, palObj->logpalette->palNumEntries, NULL, Color, FALSE);
PALETTE_UnlockPalette(hpal);
}
return index;
}
@ -241,25 +244,35 @@ UINT STDCALL NtGdiGetPaletteEntries(HPALETTE hpal,
PPALOBJ palPtr;
UINT numEntries;
palPtr = (PPALOBJ)AccessUserObject((ULONG)hpal);
if (!palPtr) return 0;
numEntries = palPtr->logpalette->palNumEntries;
if (StartIndex + Entries > numEntries) Entries = numEntries - StartIndex;
if (pe)
{
if (StartIndex >= numEntries)
palPtr = (PPALOBJ) PALETTE_LockPalette(hpal);
if (NULL == palPtr)
{
// GDI_ReleaseObj( hpalette );
return 0;
}
memcpy(pe, &palPtr->logpalette->palPalEntry[StartIndex], Entries * sizeof(PALETTEENTRY));
for(numEntries = 0; numEntries < Entries ; numEntries++)
if (pe[numEntries].peFlags & 0xF0)
pe[numEntries].peFlags = 0;
}
// GDI_ReleaseObj( hpalette );
numEntries = palPtr->logpalette->palNumEntries;
if (numEntries < StartIndex + Entries)
{
Entries = numEntries - StartIndex;
}
if (NULL != pe)
{
if (numEntries <= StartIndex)
{
PALETTE_UnlockPalette(hpal);
return 0;
}
memcpy(pe, &palPtr->logpalette->palPalEntry[StartIndex], Entries * sizeof(PALETTEENTRY));
for (numEntries = 0; numEntries < Entries; numEntries++)
{
if (pe[numEntries].peFlags & 0xF0)
{
pe[numEntries].peFlags = 0;
}
}
}
PALETTE_UnlockPalette(hpal);
return Entries;
}
@ -320,7 +333,7 @@ A logical palette is a buffer between color-intensive applications and the syste
the dc palette.
-- If it is an RGB palette, then an XLATEOBJ is created between the RGB values and the dc palette.
*/
UINT STDCALL NtGdiRealizePalette(HDC hDC)
UINT STDCALL NtGdiRealizePalette(HDC hDC)
{
PPALOBJ palPtr, sysPtr;
PPALGDI palGDI, sysGDI;
@ -334,12 +347,12 @@ UINT STDCALL NtGdiRealizePalette(HDC hDC)
if (!dc)
return 0;
palPtr = (PPALOBJ)AccessUserObject((ULONG)dc->w.hPalette);
SurfGDI = (PSURFGDI)AccessInternalObject((ULONG)dc->Surface);
systemPalette = NtGdiGetStockObject((INT)DEFAULT_PALETTE);
sysPtr = (PPALOBJ)AccessUserObject((ULONG)systemPalette);
palGDI = (PPALGDI)AccessInternalObject((ULONG)dc->w.hPalette);
sysGDI = (PPALGDI)AccessInternalObject((ULONG)systemPalette);
palGDI = PALETTE_LockPalette(dc->w.hPalette);
palPtr = (PPALOBJ) palGDI;
sysGDI = PALETTE_LockPalette(systemPalette);
sysPtr = (PPALOBJ) sysGDI;
// Step 1: Create mapping of system palette\DC palette
realized = PALETTE_SetMapping(palPtr, 0, palPtr->logpalette->palNumEntries,
@ -368,7 +381,8 @@ UINT STDCALL NtGdiRealizePalette(HDC hDC)
palPtr->logicalToSystem = IntEngCreateXlate(sysGDI->Mode, palGDI->Mode, systemPalette, dc->w.hPalette);
}
// GDI_ReleaseObj(dc->w.hPalette);
PALETTE_UnlockPalette(systemPalette);
PALETTE_UnlockPalette(dc->w.hPalette);
DC_UnlockDc(hDC);
return realized;
@ -434,14 +448,26 @@ HPALETTE STDCALL NtGdiSelectPalette(HDC hDC,
{
PDC dc;
HPALETTE oldPal;
PPALGDI PalGDI;
// FIXME: mark the palette as a [fore\back]ground pal
dc = DC_LockDc(hDC);
if( dc ){
oldPal = dc->w.hPalette;
dc->w.hPalette = hpal;
DC_UnlockDc( hDC );
}
if (NULL != dc)
{
/* Check if this is a valid palette handle */
PalGDI = PALETTE_LockPalette(hpal);
if (NULL != PalGDI)
{
PALETTE_UnlockPalette(hpal);
oldPal = dc->w.hPalette;
dc->w.hPalette = hpal;
}
else
{
oldPal = NULL;
}
DC_UnlockDc(hDC);
}
return oldPal;
}
@ -460,21 +486,25 @@ UINT STDCALL NtGdiSetPaletteEntries(HPALETTE hpal,
PPALOBJ palPtr;
WORD numEntries;
palPtr = (PPALOBJ)AccessUserObject((ULONG)hpal);
palPtr = (PPALOBJ)PALETTE_LockPalette(hpal);
if (!palPtr) return 0;
numEntries = palPtr->logpalette->palNumEntries;
if (Start >= numEntries)
{
// GDI_ReleaseObj( hpalette );
return 0;
}
if (Start + Entries > numEntries) Entries = numEntries - Start;
{
PALETTE_UnlockPalette(hpal);
return 0;
}
if (numEntries < Start + Entries)
{
Entries = numEntries - Start;
}
memcpy(&palPtr->logpalette->palPalEntry[Start], pe, Entries * sizeof(PALETTEENTRY));
PALETTE_ValidateFlags(palPtr->logpalette->palPalEntry, palPtr->logpalette->palNumEntries);
ExFreePool(palPtr->logicalToSystem);
palPtr->logicalToSystem = NULL;
// GDI_ReleaseObj( hpalette );
PALETTE_UnlockPalette(hpal);
return Entries;
}

View file

@ -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.74 2003/08/25 23:24:02 rcampbell Exp $
/* $Id: dc.c,v 1.75 2003/08/28 12:35:59 gvg Exp $
*
* DC.C - Device context functions
*
@ -43,6 +43,7 @@
#include "../eng/handle.h"
#include <include/inteng.h>
#include <include/eng.h>
#include <include/palette.h>
#define NDEBUG
#include <win32k/debug1.h>
@ -362,6 +363,12 @@ NtGdiCreatePrimarySurface(LPCWSTR Driver,
DPRINT("Enabling PDev\n");
#ifdef TODO
PrimarySurface.DMW.dmBitsPerPel = 16;
PrimarySurface.DMW.dmPelsWidth = 1024;
PrimarySurface.DMW.dmPelsHeight = 768;
PrimarySurface.DMW.dmDisplayFrequency = 60;
#endif
PrimarySurface.PDev =
PrimarySurface.DriverFunctions.EnablePDev(&PrimarySurface.DMW,
L"",
@ -1251,6 +1258,7 @@ NtGdiSelectObject(HDC hDC, HGDIOBJ hGDIObj)
COLORREF *ColorMap;
ULONG NumColors, Index;
HRGN hVisRgn;
USHORT Mode;
if(!hDC || !hGDIObj) return NULL;
@ -1268,11 +1276,13 @@ NtGdiSelectObject(HDC hDC, HGDIOBJ hGDIObj)
objOrg = (HGDIOBJ)dc->w.hPen;
dc->w.hPen = hGDIObj;
// Convert the color of the pen to the format of the DC
PalGDI = (PPALGDI)AccessInternalObject((ULONG) dc->w.hPalette);
if ( PalGDI )
/* Convert the color of the pen to the format of the DC */
PalGDI = PALETTE_LockPalette(dc->w.hPalette);
if (NULL != PalGDI)
{
XlateObj = (PXLATEOBJ)IntEngCreateXlate(PalGDI->Mode, PAL_RGB, dc->w.hPalette, NULL);
Mode = PalGDI->Mode;
PALETTE_UnlockPalette(dc->w.hPalette);
XlateObj = (PXLATEOBJ)IntEngCreateXlate(Mode, PAL_RGB, dc->w.hPalette, NULL);
ASSERT ( XlateObj );
pen = PENOBJ_LockPen(dc->w.hPen);
if( pen )
@ -1288,11 +1298,13 @@ NtGdiSelectObject(HDC hDC, HGDIOBJ hGDIObj)
objOrg = (HGDIOBJ)dc->w.hBrush;
dc->w.hBrush = (HBRUSH) hGDIObj;
// Convert the color of the brush to the format of the DC
PalGDI = (PPALGDI)AccessInternalObject((ULONG) dc->w.hPalette);
if( PalGDI )
/* Convert the color of the brush to the format of the DC */
PalGDI = PALETTE_LockPalette(dc->w.hPalette);
if (NULL != PalGDI)
{
XlateObj = (PXLATEOBJ)IntEngCreateXlate(PalGDI->Mode, PAL_RGB, dc->w.hPalette, NULL);
Mode = PalGDI->Mode;
PALETTE_UnlockPalette(dc->w.hPalette);
XlateObj = (PXLATEOBJ)IntEngCreateXlate(Mode, PAL_RGB, dc->w.hPalette, NULL);
ASSERT(XlateObj);
brush = BRUSHOBJ_LockBrush(dc->w.hBrush);
if( brush )
@ -1342,16 +1354,16 @@ NtGdiSelectObject(HDC hDC, HGDIOBJ hGDIObj)
pb->ColorMap[Index].rgbGreen,
pb->ColorMap[Index].rgbBlue);
}
dc->w.hPalette = EngCreatePalette(PAL_INDEXED, NumColors, (ULONG *) ColorMap, 0, 0, 0);
dc->w.hPalette = PALETTE_AllocPalette(PAL_INDEXED, NumColors, (ULONG *) ColorMap, 0, 0, 0);
ExFreePool(ColorMap);
}
else if ( 16 == pb->dib->dsBmih.biBitCount )
{
dc->w.hPalette = EngCreatePalette(PAL_BITFIELDS, pb->dib->dsBmih.biClrUsed, NULL, 0x7c00, 0x03e0, 0x001f);
dc->w.hPalette = PALETTE_AllocPalette(PAL_BITFIELDS, pb->dib->dsBmih.biClrUsed, NULL, 0x7c00, 0x03e0, 0x001f);
}
else if(pb->dib->dsBmih.biBitCount >= 24)
{
dc->w.hPalette = EngCreatePalette(PAL_RGB, pb->dib->dsBmih.biClrUsed, NULL, 0, 0, 0);
dc->w.hPalette = PALETTE_AllocPalette(PAL_RGB, pb->dib->dsBmih.biClrUsed, NULL, 0, 0, 0);
}
}
else

View file

@ -1,5 +1,5 @@
/*
* $Id: dib.c,v 1.30 2003/08/25 23:24:02 rcampbell Exp $
* $Id: dib.c,v 1.31 2003/08/28 12:35:59 gvg Exp $
*
* ReactOS W32 Subsystem
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
@ -32,6 +32,7 @@
#include <include/dib.h>
#include <internal/safe.h>
#include <include/surface.h>
#include <include/palette.h>
#define NDEBUG
#include <win32k/debug1.h>
@ -48,7 +49,7 @@ UINT STDCALL NtGdiSetDIBColorTable(HDC hDC,
if (!(dc = (PDC)AccessUserObject((ULONG)hDC))) return 0;
if (!(palette = (PPALOBJ)AccessUserObject((ULONG)dc->DevInfo->hpalDefault)))
if (!(palette = (PPALOBJ)PALETTE_LockPalette((ULONG)dc->DevInfo->hpalDefault)))
{
// GDI_ReleaseObj( hdc );
return 0;
@ -77,7 +78,7 @@ UINT STDCALL NtGdiSetDIBColorTable(HDC hDC,
Entries = 0;
}
// GDI_ReleaseObj(dc->DevInfo->hpalDefault);
PALETTE_UnlockPalette(dc->DevInfo->hpalDefault);
// GDI_ReleaseObj(hdc);
return Entries;
@ -156,9 +157,10 @@ NtGdiSetDIBits(
SourceSurf = (PSURFOBJ)AccessUserObject((ULONG)SourceBitmap);
// Destination palette obtained from the hDC
hDCPalette = (PPALGDI)AccessInternalObject((ULONG)dc->DevInfo->hpalDefault);
hDCPalette = PALETTE_LockPalette(dc->DevInfo->hpalDefault);
DDB_Palette_Type = hDCPalette->Mode;
DDB_Palette = dc->DevInfo->hpalDefault;
PALETTE_UnlockPalette(dc->DevInfo->hpalDefault);
// Source palette obtained from the BITMAPINFO
DIB_Palette = BuildDIBPalette ( (PBITMAPINFO)bmi, (PINT)&DIB_Palette_Type );
@ -186,7 +188,7 @@ NtGdiSetDIBits(
// Clean up
EngDeleteXlate(XlateObj);
EngDeletePalette(DIB_Palette);
PALETTE_FreePalette(DIB_Palette);
EngDeleteSurface(SourceBitmap);
EngDeleteSurface(DestBitmap);
@ -354,11 +356,12 @@ INT STDCALL NtGdiGetDIBits(HDC hDC,
BITMAPOBJ_UnlockBitmap(hBitmap);
return 0;
}
PalGdi = (PPALGDI) AccessInternalObject((ULONG) DCObj->w.hPalette);
PalGdi = PALETTE_LockPalette(DCObj->w.hPalette);
BitField = (DWORD *) ((char *) &InfoWithBitFields + InfoWithBitFields.Info.bmiHeader.biSize);
BitField[0] = PalGdi->RedMask;
BitField[1] = PalGdi->GreenMask;
BitField[2] = PalGdi->BlueMask;
PALETTE_UnlockPalette(DCObj->w.hPalette);
InfoSize = InfoWithBitFields.Info.bmiHeader.biSize + 3 * sizeof(DWORD);
DC_UnlockDc(hDC);
}
@ -872,30 +875,33 @@ DIB_MapPaletteColors(PDC dc, CONST BITMAPINFO* lpbmi)
DWORD *lpIndex;
PPALOBJ palObj;
palObj = AccessUserObject ( (ULONG)dc->DevInfo->hpalDefault );
palObj = (PPALOBJ) PALETTE_LockPalette(dc->DevInfo->hpalDefault);
if (palObj == NULL)
{
if (NULL == palObj)
{
// RELEASEDCINFO(hDC);
return NULL;
}
return NULL;
}
nNumColors = 1 << lpbmi->bmiHeader.biBitCount;
if (lpbmi->bmiHeader.biClrUsed)
nNumColors = min(nNumColors, lpbmi->bmiHeader.biClrUsed);
{
nNumColors = min(nNumColors, lpbmi->bmiHeader.biClrUsed);
}
lpRGB = (RGBQUAD *)ExAllocatePool(NonPagedPool, sizeof(RGBQUAD) * nNumColors);
lpIndex = (DWORD *)&lpbmi->bmiColors[0];
for (i=0; i<nNumColors; i++)
{
lpRGB[i].rgbRed = palObj->logpalette->palPalEntry[*lpIndex].peRed;
lpRGB[i].rgbGreen = palObj->logpalette->palPalEntry[*lpIndex].peGreen;
lpRGB[i].rgbBlue = palObj->logpalette->palPalEntry[*lpIndex].peBlue;
lpIndex++;
}
for (i = 0; i < nNumColors; i++)
{
lpRGB[i].rgbRed = palObj->logpalette->palPalEntry[*lpIndex].peRed;
lpRGB[i].rgbGreen = palObj->logpalette->palPalEntry[*lpIndex].peGreen;
lpRGB[i].rgbBlue = palObj->logpalette->palPalEntry[*lpIndex].peBlue;
lpIndex++;
}
// RELEASEDCINFO(hDC);
// RELEASEPALETTEINFO(hPalette);
PALETTE_UnlockPalette(dc->DevInfo->hpalDefault);
return lpRGB;
}
@ -908,14 +914,14 @@ DIBColorTableToPaletteEntries (
{
ULONG i;
for(i=0; i<ColorCount; i++)
{
palEntries->peRed = DIBColorTable->rgbRed;
palEntries->peGreen = DIBColorTable->rgbGreen;
palEntries->peBlue = DIBColorTable->rgbBlue;
palEntries++;
DIBColorTable++;
}
for (i = 0; i < ColorCount; i++)
{
palEntries->peRed = DIBColorTable->rgbRed;
palEntries->peGreen = DIBColorTable->rgbGreen;
palEntries->peBlue = DIBColorTable->rgbBlue;
palEntries++;
DIBColorTable++;
}
return palEntries;
}
@ -932,18 +938,24 @@ BuildDIBPalette (PBITMAPINFO bmi, PINT paletteType)
bits = bmi->bmiHeader.biBitCount;
// Determine paletteType from Bits Per Pixel
if(bits <= 8)
{
*paletteType = PAL_INDEXED;
} else
if(bits < 24)
{
*paletteType = PAL_BITFIELDS;
} else {
*paletteType = PAL_RGB; // Would it be BGR, considering the BGR nature of the DIB color table?
}
if (bits <= 8)
{
*paletteType = PAL_INDEXED;
}
else if(bits < 24)
{
*paletteType = PAL_BITFIELDS;
}
else
{
*paletteType = PAL_RGB; // Would it be BGR, considering the BGR nature of the DIB color table?
}
#ifdef TODO
if (bmi->bmiHeader.biClrUsed == 0)
#else
if (bmi->bmiHeader.biClrUsed == 0 && bmi->bmiHeader.biBitCount <= 8)
#endif
{
ColorCount = 1 << bmi->bmiHeader.biBitCount;
}
@ -954,9 +966,10 @@ BuildDIBPalette (PBITMAPINFO bmi, PINT paletteType)
palEntries = ExAllocatePool(NonPagedPool, sizeof(PALETTEENTRY)*ColorCount);
DIBColorTableToPaletteEntries(palEntries, bmi->bmiColors, ColorCount);
hPal = EngCreatePalette ( *paletteType, ColorCount, (ULONG*)palEntries, 0, 0, 0 );
hPal = PALETTE_AllocPalette( *paletteType, ColorCount, (ULONG*)palEntries, 0, 0, 0 );
ExFreePool(palEntries);
return hPal;
}
/* EOF */

View file

@ -16,13 +16,15 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: palette.c,v 1.10 2003/08/19 11:48:50 weiden Exp $ */
/* $Id: palette.c,v 1.11 2003/08/28 12:35:59 gvg Exp $ */
#undef WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <win32k/debug.h>
#include <win32k/debug1.h>
#include <win32k/bitmaps.h>
#include <win32k/color.h>
#include <win32k/gdiobj.h>
#include <debug.h>
#include <include/palette.h>
#include <include/object.h>
@ -31,6 +33,7 @@
static int PALETTE_firstFree = 0;
static unsigned char PALETTE_freeList[256];
#ifdef TODO
static ColorShifts PALETTE_PRed = {0,0,0};
//static ColorShifts PALETTE_LRed = {0,0,0};
static ColorShifts PALETTE_PGreen = {0,0,0};
@ -39,6 +42,7 @@ static ColorShifts PALETTE_PBlue = {0,0,0};
//static ColorShifts PALETTE_LBlue = {0,0,0};
static int PALETTE_Graymax = 0;
static int palette_size;
#endif
int PALETTE_PaletteFlags = 0;
PALETTEENTRY *COLOR_sysPal = NULL;
@ -52,6 +56,68 @@ PPALETTEENTRY FASTCALL ReturnSystemPalette (VOID)
return COLOR_sysPal;
}
static BOOL FASTCALL
PALETTE_InternalDelete(PPALGDI Palette)
{
if (NULL != Palette->IndexedColors)
{
ExFreePool(Palette->IndexedColors);
}
return TRUE;
}
HPALETTE FASTCALL
PALETTE_AllocPalette(ULONG Mode,
ULONG NumColors,
ULONG *Colors,
ULONG Red,
ULONG Green,
ULONG Blue)
{
HPALETTE NewPalette;
PPALGDI PalGDI;
NewPalette = (HPALETTE) GDIOBJ_AllocObj(sizeof(PALGDI), GDI_OBJECT_TYPE_PALETTE, (GDICLEANUPPROC) PALETTE_InternalDelete);
if (NULL == NewPalette)
{
return NULL;
}
PalGDI = PALETTE_LockPalette(NewPalette);
ASSERT( PalGDI );
PalGDI->Self = NewPalette;
PalGDI->Mode = Mode;
if (NULL != Colors)
{
PalGDI->IndexedColors = ExAllocatePool(NonPagedPool, sizeof(PALETTEENTRY) * NumColors);
if (NULL == PalGDI->IndexedColors)
{
PALETTE_UnlockPalette(NewPalette);
PALETTE_FreePalette(NewPalette);
return NULL;
}
RtlCopyMemory(PalGDI->IndexedColors, Colors, sizeof(PALETTEENTRY) * NumColors);
}
if (PAL_INDEXED == Mode)
{
PalGDI->NumColors = NumColors;
}
else if (PAL_BITFIELDS == Mode)
{
PalGDI->RedMask = Red;
PalGDI->GreenMask = Green;
PalGDI->BlueMask = Blue;
}
PALETTE_UnlockPalette(NewPalette);
return NewPalette;
}
// Create the system palette
HPALETTE FASTCALL PALETTE_Init(VOID)
{
@ -78,7 +144,7 @@ HPALETTE FASTCALL PALETTE_Init(VOID)
hpalette = NtGdiCreatePalette(palPtr);
ExFreePool(palPtr);
palObj = (PPALOBJ)AccessUserObject((ULONG)hpalette);
palObj = (PPALOBJ)PALETTE_LockPalette(hpalette);
if (palObj)
{
if (!(palObj->mapping = ExAllocatePool(NonPagedPool, sizeof(int) * 20)))
@ -86,7 +152,7 @@ HPALETTE FASTCALL PALETTE_Init(VOID)
DbgPrint("Win32k: Can not create palette mapping -- out of memory!");
return FALSE;
}
// GDI_ReleaseObj( hpalette );
PALETTE_UnlockPalette(hpalette);
}
/* palette_size = visual->map_entries; */
@ -114,6 +180,7 @@ static void FASTCALL PALETTE_FormatSystemPalette(void)
PALETTE_freeList[j] = 0;
}
#ifdef TODO
/* Ported from WINE 20020804 (graphics\x11drv\palette.c) */
static int FASTCALL SysPaletteLookupPixel( COLORREF col, BOOL skipReserved )
{
@ -168,6 +235,7 @@ UINT WINAPI GetNearestPaletteIndex(
DPRINT("(%04x,%06lx): returning %d\n", hpalette, color, index );
return index;
}
#endif
VOID FASTCALL PALETTE_ValidateFlags(PALETTEENTRY* lpPalE, INT size)
{
@ -280,6 +348,7 @@ INT STDCALL PALETTE_SetMapping(PPALOBJ palPtr, UINT uStart, UINT uNum, BOOL mapO
return iRemapped;
}
#ifdef TODO
/* Return the physical color closest to 'color'. */
/* Ported from WINE 20020804 (graphics\x11drv\palette.c) */
INT FASTCALL PALETTE_ToPhysical (PDC dc, COLORREF color)
@ -415,4 +484,6 @@ INT FASTCALL PALETTE_ToPhysical (PDC dc, COLORREF color)
// GDI_ReleaseObj( hPal );
return index;
}
#endif
/* EOF */

View file

@ -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: text.c,v 1.44 2003/08/20 07:45:02 gvg Exp $ */
/* $Id: text.c,v 1.45 2003/08/28 12:35:59 gvg Exp $ */
#undef WIN32_LEAN_AND_MEAN
@ -36,6 +36,7 @@
#include <include/inteng.h>
#include <include/text.h>
#include <include/eng.h>
#include <include/palette.h>
#define NDEBUG
#include <win32k/debug1.h>
@ -1056,6 +1057,7 @@ NtGdiTextOut(HDC hDC,
PTEXTOBJ TextObj;
PPALGDI PalDestGDI;
PXLATEOBJ XlateObj;
ULONG Mode;
if( !dc )
return FALSE;
@ -1105,8 +1107,10 @@ NtGdiTextOut(HDC hDC,
}
// Create the brush
PalDestGDI = (PPALGDI)AccessInternalObject((ULONG) dc->w.hPalette);
XlateObj = (PXLATEOBJ)IntEngCreateXlate(PalDestGDI->Mode, PAL_RGB, dc->w.hPalette, NULL);
PalDestGDI = PALETTE_LockPalette(dc->w.hPalette);
Mode = PalDestGDI->Mode;
PALETTE_UnlockPalette(dc->w.hPalette);
XlateObj = (PXLATEOBJ)IntEngCreateXlate(Mode, PAL_RGB, dc->w.hPalette, NULL);
hBrush = NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj, dc->w.textColor));
Brush = BRUSHOBJ_LockBrush(hBrush);
EngDeleteXlate(XlateObj);