reactos/win32ss/gdi/ntgdi/palette.h

166 lines
4 KiB
C
Raw Normal View History

#pragma once
#ifdef _MSC_VER
#pragma warning(disable:4200) // zero-sized array in struct/union
#endif // _MSC_VER
// Palette mode flags
enum _PALFLAGS
{
#ifndef _WINDDI_ // Defined in ddk/winddi.h
PAL_INDEXED = 0x00000001, // Indexed palette
PAL_BITFIELDS = 0x00000002, // Bit fields used for DIB, DIB section
PAL_RGB = 0x00000004, // Red, green, blue
PAL_BGR = 0x00000008, // Blue, green, red
PAL_CMYK = 0x00000010, // Cyan, magenta, yellow, black
#endif
PAL_DC = 0x00000100,
PAL_FIXED = 0x00000200, // Can't be changed
PAL_FREE = 0x00000400,
PAL_MANAGED = 0x00000800,
PAL_NOSTATIC = 0x00001000,
PAL_MONOCHROME = 0x00002000, // Two colors only
PAL_BRUSHHACK = 0x00004000,
PAL_DIBSECTION = 0x00008000, // Used for a DIB section
PAL_NOSTATIC256 = 0x00010000,
PAL_HT = 0x00100000, // Halftone palette
PAL_RGB16_555 = 0x00200000, // 16-bit RGB in 555 format
PAL_RGB16_565 = 0x00400000, // 16-bit RGB in 565 format
PAL_GAMMACORRECTION = 0x00800000, // Correct colors
};
typedef struct _PALETTE
{
/* Header for all gdi objects in the handle table.
Do not (re)move this. */
BASEOBJECT BaseObject;
PALOBJ PalObj;
XLATEOBJ *logicalToSystem;
FLONG flFlags; // PAL_INDEXED, PAL_BITFIELDS, PAL_RGB, PAL_BGR
ULONG NumColors;
PALETTEENTRY *IndexedColors;
ULONG RedMask;
ULONG GreenMask;
ULONG BlueMask;
ULONG ulRedShift;
ULONG ulGreenShift;
ULONG ulBlueShift;
HDEV hPDev;
PALETTEENTRY apalColors[0];
} PALETTE, *PPALETTE;
extern PALETTE gpalRGB, gpalBGR, gpalRGB555, gpalRGB565, *gppalMono, *gppalDefault;
extern PPALETTE appalSurfaceDefault[];
[WIN32K] Rewrite of the GDI handle manager - The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability. - Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also much faster and uses much less memory. - Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs. - Allow allcoating objects without a handle and insert them into the handle table later - Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles. - Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track possible leaks - Make sure that all objects of a process are deleted in cleanup - Make sure all usermode memory allocations are freed, when cleaning up the process pool. - Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture) - Fix some object / reference leaks - Lots of inferface improvements - Use global variables for certain things instead of members in the mapped gdi handle table - Make IntSysCreateRectpRgn create a region without a handle - Fix detection od source and mask use in GreStretchBltMask - Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks - Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always - Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool - Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway, - Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter - Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid - Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
#define PALETTE_UnlockPalette(pPalette) GDIOBJ_vUnlockObject((POBJ)pPalette)
#define PALETTE_ShareLockPalette(hpal) \
((PPALETTE)GDIOBJ_ShareLockObj((HGDIOBJ)hpal, GDI_OBJECT_TYPE_PALETTE))
#define PALETTE_ShareUnlockPalette(ppal) \
[WIN32K] Rewrite of the GDI handle manager - The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability. - Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also much faster and uses much less memory. - Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs. - Allow allcoating objects without a handle and insert them into the handle table later - Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles. - Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track possible leaks - Make sure that all objects of a process are deleted in cleanup - Make sure all usermode memory allocations are freed, when cleaning up the process pool. - Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture) - Fix some object / reference leaks - Lots of inferface improvements - Use global variables for certain things instead of members in the mapped gdi handle table - Make IntSysCreateRectpRgn create a region without a handle - Fix detection od source and mask use in GreStretchBltMask - Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks - Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always - Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool - Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway, - Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter - Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid - Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
GDIOBJ_vDereferenceObject(&ppal->BaseObject)
CODE_SEG("INIT")
NTSTATUS
NTAPI
InitPaletteImpl(VOID);
PPALETTE
NTAPI
PALETTE_AllocPalette(
_In_ ULONG iMode,
_In_ ULONG cColors,
_In_opt_ const PALETTEENTRY* pEntries,
_In_ FLONG flRed,
_In_ FLONG flGreen,
_In_ FLONG flBlue);
PPALETTE
NTAPI
PALETTE_AllocPalWithHandle(
_In_ ULONG iMode,
_In_ ULONG cColors,
_In_opt_ const PALETTEENTRY* pEntries,
_In_ FLONG flRed,
_In_ FLONG flGreen,
_In_ FLONG flBlue);
VOID
FASTCALL
PALETTE_ValidateFlags(
PALETTEENTRY* lpPalE,
INT size);
INT
FASTCALL
PALETTE_GetObject(
PPALETTE pGdiObject,
INT cbCount,
LPLOGBRUSH lpBuffer);
ULONG
NTAPI
PALETTE_ulGetNearestPaletteIndex(
PPALETTE ppal,
ULONG iColor);
ULONG
NTAPI
PALETTE_ulGetNearestIndex(
PPALETTE ppal,
ULONG iColor);
ULONG
NTAPI
PALETTE_ulGetNearestBitFieldsIndex(
PPALETTE ppal,
ULONG ulColor);
VOID
NTAPI
PALETTE_vGetBitMasks(
PPALETTE ppal,
PULONG pulColors);
VOID
NTAPI
PALETTE_vCleanup(PVOID ObjectBody);
XLATEOBJ rewrite. The new XLATEOBJ is not allocated from paged pool anymore, but instead allocated on the stack and Initialized. Only when we habe more than a color table with more than 6 entries, we need to allocate an additional buffer. The new interface: EXLATEOBJ_vInitialize is the main init function. It takes a source and destination palette and back and fore colors for monochome surfaces. EXLATEOBJ_vInitXlateFromDCs takes the source and dest DC and is for color translation between 2 surfaces represented by 2 DCs. EXLATEOBJ_vInitBrushXlate initializes an XLATEOBJ for a pattern brush. Finally EXLATEOBJ_vCleanup needs to be called when the XLATEOBJ is not needed anymore. Implement individual iXlate functions for certain cases and store a function pointer in the EXLATEOBJ structure for quick access. Change the usage of the PALETTE.Mode member to be a flag instead of an enum, add usage of PAL_MONOCHOME, PAL_RGB16_555 and PAL_RGB16_565. Add gpalMono, which *should* be used as palette for 1bpp DDBs. Currently there's a hack in the XLATEOBJ init code, to hack around the fact that this is missing. Fix the Hatch brush patterns, as they were inverted. Implement PALETTE_ulGetNearestBitFieldsIndex and PALETTE_ulGetNearestIndex. Get rid of the XLATEOBJ for the mouse pointer instead realize the pointer before usage. Get rid of logicalToSystem PALETTE member. NtGdiGetDIBitsInternal: Don't create a DIBBrush from the BITMAPINFO, when pvBits is NULL, as the function might be uninitualized. This fixes a crash of gdi_regtest. The whole function is quite ugly and needs to be rewritten (like probably the rest of the DIB code). This fixes the problem of artifacts in the selected desktop icons and some color problems. svn path=/trunk/; revision=42391
2009-08-04 20:37:10 +00:00
FORCEINLINE
ULONG
XLATEOBJ rewrite. The new XLATEOBJ is not allocated from paged pool anymore, but instead allocated on the stack and Initialized. Only when we habe more than a color table with more than 6 entries, we need to allocate an additional buffer. The new interface: EXLATEOBJ_vInitialize is the main init function. It takes a source and destination palette and back and fore colors for monochome surfaces. EXLATEOBJ_vInitXlateFromDCs takes the source and dest DC and is for color translation between 2 surfaces represented by 2 DCs. EXLATEOBJ_vInitBrushXlate initializes an XLATEOBJ for a pattern brush. Finally EXLATEOBJ_vCleanup needs to be called when the XLATEOBJ is not needed anymore. Implement individual iXlate functions for certain cases and store a function pointer in the EXLATEOBJ structure for quick access. Change the usage of the PALETTE.Mode member to be a flag instead of an enum, add usage of PAL_MONOCHOME, PAL_RGB16_555 and PAL_RGB16_565. Add gpalMono, which *should* be used as palette for 1bpp DDBs. Currently there's a hack in the XLATEOBJ init code, to hack around the fact that this is missing. Fix the Hatch brush patterns, as they were inverted. Implement PALETTE_ulGetNearestBitFieldsIndex and PALETTE_ulGetNearestIndex. Get rid of the XLATEOBJ for the mouse pointer instead realize the pointer before usage. Get rid of logicalToSystem PALETTE member. NtGdiGetDIBitsInternal: Don't create a DIBBrush from the BITMAPINFO, when pvBits is NULL, as the function might be uninitualized. This fixes a crash of gdi_regtest. The whole function is quite ugly and needs to be rewritten (like probably the rest of the DIB code). This fixes the problem of artifacts in the selected desktop icons and some color problems. svn path=/trunk/; revision=42391
2009-08-04 20:37:10 +00:00
CalculateShift(ULONG ulMask1, ULONG ulMask2)
{
ULONG ulShift1, ulShift2;
BitScanReverse(&ulShift1, ulMask1);
BitScanReverse(&ulShift2, ulMask2);
ulShift2 -= ulShift1;
if ((INT)ulShift2 < 0) ulShift2 += 32;
return ulShift2;
}
FORCEINLINE
ULONG
PALETTE_ulGetRGBColorFromIndex(PPALETTE ppal, ULONG ulIndex)
{
if (ulIndex >= ppal->NumColors) return 0;
return RGB(ppal->IndexedColors[ulIndex].peRed,
ppal->IndexedColors[ulIndex].peGreen,
ppal->IndexedColors[ulIndex].peBlue);
}
FORCEINLINE
VOID
PALETTE_vSetRGBColorForIndex(PPALETTE ppal, ULONG ulIndex, COLORREF crColor)
{
if (ulIndex >= ppal->NumColors) return;
ppal->IndexedColors[ulIndex].peRed = GetRValue(crColor);
ppal->IndexedColors[ulIndex].peGreen = GetGValue(crColor);
ppal->IndexedColors[ulIndex].peBlue = GetBValue(crColor);
}
HPALETTE
NTAPI
GreCreatePaletteInternal(
IN LPLOGPALETTE pLogPal,
IN UINT cEntries);