43f59e6efca67b8c7c89cfde6d78a57e649f9e77
[reactos.git] / subsystems / win32 / win32k / include / palette.h
1 #pragma once
2
3 #include <include/dc.h>
4
5 #define NO_MAPPING
6
7 #define PALETTE_FIXED 0x0001 /* read-only colormap - have to use XAllocColor (if not virtual) */
8 #define PALETTE_VIRTUAL 0x0002 /* no mapping needed - pixel == pixel color */
9
10 #define PALETTE_PRIVATE 0x1000 /* private colormap, identity mapping */
11 #define PALETTE_WHITESET 0x2000
12
13 // Palette mode flags
14 #ifndef __WINDDI_H // Defined in ddk/winddi.h
15 #define PAL_INDEXED 0x00000001 // Indexed palette
16 #define PAL_BITFIELDS 0x00000002 // Bit fields used for DIB, DIB section
17 #define PAL_RGB 0x00000004 // Red, green, blue
18 #define PAL_BGR 0x00000008 // Blue, green, red
19 #define PAL_CMYK 0x00000010 // Cyan, magenta, yellow, black
20 #endif
21 #define PAL_DC 0x00000100
22 #define PAL_FIXED 0x00000200 // Can't be changed
23 #define PAL_FREE 0x00000400
24 #define PAL_MANAGED 0x00000800
25 #define PAL_NOSTATIC 0x00001000
26 #define PAL_MONOCHROME 0x00002000 // Two colors only
27 #define PAL_BRUSHHACK 0x00004000
28 #define PAL_DIBSECTION 0x00008000 // Used for a DIB section
29 #define PAL_NOSTATIC256 0x00010000
30 #define PAL_HT 0x00100000 // Halftone palette
31 #define PAL_RGB16_555 0x00200000 // 16-bit RGB in 555 format
32 #define PAL_RGB16_565 0x00400000 // 16-bit RGB in 565 format
33 #define PAL_GAMMACORRECTION 0x00800000 // Correct colors
34
35
36 typedef struct _PALETTE
37 {
38 /* Header for all gdi objects in the handle table.
39 Do not (re)move this. */
40 BASEOBJECT BaseObject;
41
42 PALOBJ PalObj;
43 XLATEOBJ *logicalToSystem;
44 HPALETTE Self;
45 ULONG Mode; // PAL_INDEXED, PAL_BITFIELDS, PAL_RGB, PAL_BGR
46 ULONG NumColors;
47 PALETTEENTRY *IndexedColors;
48 ULONG RedMask;
49 ULONG GreenMask;
50 ULONG BlueMask;
51 ULONG ulRedShift;
52 ULONG ulGreenShift;
53 ULONG ulBlueShift;
54 HDEV hPDev;
55 } PALETTE, *PPALETTE;
56
57 extern PALETTE gpalRGB, gpalBGR, gpalMono;
58
59
60 HPALETTE FASTCALL PALETTE_AllocPalette(ULONG Mode,
61 ULONG NumColors,
62 ULONG *Colors,
63 ULONG Red,
64 ULONG Green,
65 ULONG Blue);
66 HPALETTE FASTCALL PALETTE_AllocPaletteIndexedRGB(ULONG NumColors,
67 CONST RGBQUAD *Colors);
68 #define PALETTE_FreePalette(pPalette) GDIOBJ_FreeObj((POBJ)pPalette, GDIObjType_PAL_TYPE)
69 #define PALETTE_FreePaletteByHandle(hPalette) GDIOBJ_FreeObjByHandle((HGDIOBJ)hPalette, GDI_OBJECT_TYPE_PALETTE)
70 #define PALETTE_LockPalette(hPalette) ((PPALETTE)GDIOBJ_LockObj((HGDIOBJ)hPalette, GDI_OBJECT_TYPE_PALETTE))
71 #define PALETTE_UnlockPalette(pPalette) GDIOBJ_UnlockObjByPtr((POBJ)pPalette)
72
73 #define PALETTE_ShareLockPalette(hpal) \
74 ((PPALETTE)GDIOBJ_ShareLockObj((HGDIOBJ)hpal, GDI_OBJECT_TYPE_PALETTE))
75 #define PALETTE_ShareUnlockPalette(ppal) \
76 GDIOBJ_ShareUnlockObjByPtr(&ppal->BaseObject)
77
78 BOOL INTERNAL_CALL PALETTE_Cleanup(PVOID ObjectBody);
79
80 HPALETTE FASTCALL PALETTE_Init (VOID);
81 VOID FASTCALL PALETTE_ValidateFlags (PALETTEENTRY* lpPalE, INT size);
82 #ifndef NO_MAPPING
83 INT APIENTRY PALETTE_SetMapping(PALOBJ* palPtr, UINT uStart, UINT uNum, BOOL mapOnly);
84 #endif
85 INT FASTCALL PALETTE_ToPhysical (PDC dc, COLORREF color);
86
87 INT FASTCALL PALETTE_GetObject(PPALETTE pGdiObject, INT cbCount, LPLOGBRUSH lpBuffer);
88 ULONG NTAPI PALETTE_ulGetNearestPaletteIndex(PALETTE* ppal, ULONG iColor);
89 ULONG NTAPI PALETTE_ulGetNearestIndex(PALETTE* ppal, ULONG iColor);
90 VOID NTAPI PALETTE_vGetBitMasks(PPALETTE ppal, PULONG pulColors);
91
92 PPALETTEENTRY FASTCALL ReturnSystemPalette (VOID);
93 HPALETTE FASTCALL GdiSelectPalette(HDC, HPALETTE, BOOL);
94
95 ULONG
96 FORCEINLINE
97 CalculateShift(ULONG ulMask1, ULONG ulMask2)
98 {
99 ULONG ulShift1, ulShift2;
100 BitScanReverse(&ulShift1, ulMask1);
101 BitScanReverse(&ulShift2, ulMask2);
102 ulShift2 -= ulShift1;
103 if ((INT)ulShift2 < 0) ulShift2 += 32;
104 return ulShift2;
105 }
106
107 FORCEINLINE
108 ULONG
109 PALETTE_ulGetRGBColorFromIndex(PPALETTE ppal, ULONG ulIndex)
110 {
111 return RGB(ppal->IndexedColors[ulIndex].peRed,
112 ppal->IndexedColors[ulIndex].peGreen,
113 ppal->IndexedColors[ulIndex].peBlue);
114 }