Author: tkreuzer
Date: Sat May 5 17:29:34 2012
New Revision: 56514
URL:
http://svn.reactos.org/svn/reactos?rev=56514&view=rev
Log:
[WIN32K]
Rename PALETTE_AllocPalette2 to PALETTE_AllocPalette, allocate PALETTE and color array in
one allocation, improve code
Modified:
trunk/reactos/win32ss/gdi/ntgdi/palette.c
trunk/reactos/win32ss/gdi/ntgdi/palette.h
Modified: trunk/reactos/win32ss/gdi/ntgdi/palette.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/ntgdi/palette.…
==============================================================================
--- trunk/reactos/win32ss/gdi/ntgdi/palette.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/gdi/ntgdi/palette.c [iso-8859-1] Sat May 5 17:29:34 2012
@@ -145,62 +145,81 @@
lpPalE[i].peFlags = PC_SYS_USED | (lpPalE[i].peFlags & 0x07);
}
+
PPALETTE
NTAPI
-PALETTE_AllocPalette2(ULONG Mode,
- ULONG NumColors,
- ULONG *Colors,
- ULONG Red,
- ULONG Green,
- ULONG Blue)
-{
- PPALETTE PalGDI;
-
- PalGDI = (PPALETTE)GDIOBJ_AllocateObject(GDIObjType_PAL_TYPE,
- sizeof(PALETTE),
- BASEFLAG_LOOKASIDE);
- if (!PalGDI)
- {
- DPRINT1("Could not allocate a palette.\n");
+PALETTE_AllocPalette(
+ _In_ ULONG iMode,
+ _In_ ULONG cColors,
+ _In_ PULONG pulColors,
+ _In_ FLONG flRed,
+ _In_ FLONG flGreen,
+ _In_ FLONG flBlue)
+{
+ PPALETTE ppal;
+ ULONG fl = 0, cjSize = sizeof(PALETTE);
+
+ /* Check if the palette has entries */
+ if (iMode == PAL_INDEXED)
+ {
+ /* Check color count */
+ if ((cColors == 0) || (cColors > 1024)) return NULL;
+
+ /* Allocate enough space for the palete entries */
+ cjSize += cColors * sizeof(PALETTEENTRY);
+ }
+ else
+ {
+ /* There are no palette entries */
+ cColors = 0;
+
+ /* We can use the lookaside list */
+ fl |= BASEFLAG_LOOKASIDE;
+ }
+
+ /* Allocate the object (without a handle!) */
+ ppal = (PPALETTE)GDIOBJ_AllocateObject(GDIObjType_PAL_TYPE, cjSize, fl);
+ if (!ppal)
+ {
return NULL;
}
- PalGDI->flFlags = Mode;
-
- if (NumColors > 0)
- {
- PalGDI->IndexedColors = ExAllocatePoolWithTag(PagedPool,
- sizeof(PALETTEENTRY) * NumColors,
- TAG_PALETTE);
- if (NULL == PalGDI->IndexedColors)
- {
- GDIOBJ_vDeleteObject(&PalGDI->BaseObject);
- return NULL;
- }
- if (Colors) 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;
-
- if (Red == 0x7c00 && Green == 0x3E0 && Blue == 0x1F)
- PalGDI->flFlags |= PAL_RGB16_555;
- else if (Red == 0xF800 && Green == 0x7E0 && Blue == 0x1F)
- PalGDI->flFlags |= PAL_RGB16_565;
- else if (Red == 0xFF0000 && Green == 0xFF00 && Blue == 0xFF)
- PalGDI->flFlags |= PAL_BGR;
- else if (Red == 0xFF && Green == 0xFF00 && Blue == 0xFF0000)
- PalGDI->flFlags |= PAL_RGB;
- }
-
- return PalGDI;
+ /* Set mode, color count and entry pointer */
+ ppal->flFlags = iMode;
+ ppal->NumColors = cColors;
+ ppal->IndexedColors = ppal->apalColors;
+
+ /* Check what kind of palette this is */
+ if (iMode & PAL_INDEXED)
+ {
+ /* Check if we got a color array */
+ if (pulColors)
+ {
+ /* Copy the entries */
+ RtlCopyMemory(ppal->IndexedColors,
+ pulColors,
+ cColors * sizeof(ULONG));
+ }
+ }
+ else if (iMode & PAL_BITFIELDS)
+ {
+ /* Copy the color masks */
+ ppal->RedMask = flRed;
+ ppal->GreenMask = flGreen;
+ ppal->BlueMask = flBlue;
+
+ /* Check what masks we have and set optimization flags */
+ if ((flRed == 0x7c00) && (flGreen == 0x3E0) && (flBlue == 0x1F))
+ ppal->flFlags |= PAL_RGB16_555;
+ else if ((flRed == 0xF800) && (flGreen == 0x7E0) && (flBlue ==
0x1F))
+ ppal->flFlags |= PAL_RGB16_565;
+ else if ((flRed == 0xFF0000) && (flGreen == 0xFF00) && (flBlue ==
0xFF))
+ ppal->flFlags |= PAL_BGR;
+ else if ((flRed == 0xFF) && (flGreen == 0xFF00) && (flBlue ==
0xFF0000))
+ ppal->flFlags |= PAL_RGB;
+ }
+
+ return ppal;
}
PPALETTE
@@ -216,7 +235,7 @@
PPALETTE ppal;
/* Allocate the palette without a handle */
- ppal = PALETTE_AllocPalette2(iMode, cColors, pulColors, flRed, flGreen, flBlue);
+ ppal = PALETTE_AllocPalette(iMode, cColors, pulColors, flRed, flGreen, flBlue);
if (!ppal) return NULL;
/* Insert the palette into the handle table */
@@ -384,7 +403,7 @@
PPALETTE ppal;
HPALETTE hpal;
- ppal = PALETTE_AllocPalette2(iMode, cColors, pulColors, flRed, flGreen, flBlue);
+ ppal = PALETTE_AllocPalette(iMode, cColors, pulColors, flRed, flGreen, flBlue);
if (!ppal) return NULL;
hpal = GDIOBJ_hInsertObject(&ppal->BaseObject, GDI_OBJ_HMGR_PUBLIC);
Modified: trunk/reactos/win32ss/gdi/ntgdi/palette.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/ntgdi/palette.…
==============================================================================
--- trunk/reactos/win32ss/gdi/ntgdi/palette.h [iso-8859-1] (original)
+++ trunk/reactos/win32ss/gdi/ntgdi/palette.h [iso-8859-1] Sat May 5 17:29:34 2012
@@ -59,7 +59,7 @@
PPALETTE
NTAPI
-PALETTE_AllocPalette2(
+PALETTE_AllocPalette(
_In_ ULONG iMode,
_In_ ULONG cColors,
_In_ PULONG pulColors,
@@ -146,13 +146,3 @@
IN LPLOGPALETTE pLogPal,
IN UINT cEntries);
-////
-
-HPALETTE
-FASTCALL
-PALETTE_AllocPalette(ULONG Mode,
- ULONG NumColors,
- ULONG *Colors,
- ULONG Red,
- ULONG Green,
- ULONG Blue);