xref: /reactos/win32ss/gdi/ntgdi/palette.h (revision 3adf4508)
1 #pragma once
2 
3 #ifdef _MSC_VER
4 #pragma warning(disable:4200) // zero-sized array in struct/union
5 #endif // _MSC_VER
6 
7 // Palette mode flags
8 enum _PALFLAGS
9 {
10 #ifndef _WINDDI_ // Defined in ddk/winddi.h
11     PAL_INDEXED         = 0x00000001, // Indexed palette
12     PAL_BITFIELDS       = 0x00000002, // Bit fields used for DIB, DIB section
13     PAL_RGB             = 0x00000004, // Red, green, blue
14     PAL_BGR             = 0x00000008, // Blue, green, red
15     PAL_CMYK            = 0x00000010, // Cyan, magenta, yellow, black
16 #endif
17     PAL_DC              = 0x00000100,
18     PAL_FIXED           = 0x00000200, // Can't be changed
19     PAL_FREE            = 0x00000400,
20     PAL_MANAGED         = 0x00000800,
21     PAL_NOSTATIC        = 0x00001000,
22     PAL_MONOCHROME      = 0x00002000, // Two colors only
23     PAL_BRUSHHACK       = 0x00004000,
24     PAL_DIBSECTION      = 0x00008000, // Used for a DIB section
25     PAL_NOSTATIC256     = 0x00010000,
26     PAL_HT              = 0x00100000, // Halftone palette
27     PAL_RGB16_555       = 0x00200000, // 16-bit RGB in 555 format
28     PAL_RGB16_565       = 0x00400000, // 16-bit RGB in 565 format
29     PAL_GAMMACORRECTION = 0x00800000, // Correct colors
30 };
31 
32 typedef struct _PALETTE
33 {
34     /* Header for all gdi objects in the handle table.
35        Do not (re)move this. */
36     BASEOBJECT    BaseObject;
37 
38     PALOBJ PalObj;
39     XLATEOBJ *logicalToSystem;
40     FLONG flFlags; // PAL_INDEXED, PAL_BITFIELDS, PAL_RGB, PAL_BGR
41     ULONG NumColors;
42     PALETTEENTRY *IndexedColors;
43     ULONG RedMask;
44     ULONG GreenMask;
45     ULONG BlueMask;
46     ULONG ulRedShift;
47     ULONG ulGreenShift;
48     ULONG ulBlueShift;
49     HDEV  hPDev;
50     PALETTEENTRY apalColors[0];
51 } PALETTE, *PPALETTE;
52 
53 extern PALETTE gpalRGB, gpalBGR, gpalRGB555, gpalRGB565, *gppalMono, *gppalDefault;
54 extern PPALETTE appalSurfaceDefault[];
55 
56 #define  PALETTE_UnlockPalette(pPalette) GDIOBJ_vUnlockObject((POBJ)pPalette)
57 #define  PALETTE_ShareLockPalette(hpal) \
58   ((PPALETTE)GDIOBJ_ShareLockObj((HGDIOBJ)hpal, GDI_OBJECT_TYPE_PALETTE))
59 #define  PALETTE_ShareUnlockPalette(ppal)  \
60   GDIOBJ_vDereferenceObject(&ppal->BaseObject)
61 
62 CODE_SEG("INIT")
63 NTSTATUS
64 NTAPI
65 InitPaletteImpl(VOID);
66 
67 PPALETTE
68 NTAPI
69 PALETTE_AllocPalette(
70     _In_ ULONG iMode,
71     _In_ ULONG cColors,
72     _In_opt_ const PALETTEENTRY* pEntries,
73     _In_ FLONG flRed,
74     _In_ FLONG flGreen,
75     _In_ FLONG flBlue);
76 
77 PPALETTE
78 NTAPI
79 PALETTE_AllocPalWithHandle(
80     _In_ ULONG iMode,
81     _In_ ULONG cColors,
82     _In_opt_ const PALETTEENTRY* pEntries,
83     _In_ FLONG flRed,
84     _In_ FLONG flGreen,
85     _In_ FLONG flBlue);
86 
87 VOID
88 FASTCALL
89 PALETTE_ValidateFlags(
90     PALETTEENTRY* lpPalE,
91     INT size);
92 
93 INT
94 FASTCALL
95 PALETTE_GetObject(
96     PPALETTE pGdiObject,
97     INT cbCount,
98     LPLOGBRUSH lpBuffer);
99 
100 ULONG
101 NTAPI
102 PALETTE_ulGetNearestPaletteIndex(
103     PPALETTE ppal,
104     ULONG iColor);
105 
106 ULONG
107 NTAPI
108 PALETTE_ulGetNearestIndex(
109     PPALETTE ppal,
110     ULONG iColor);
111 
112 ULONG
113 NTAPI
114 PALETTE_ulGetNearestBitFieldsIndex(
115     PPALETTE ppal,
116     ULONG ulColor);
117 
118 VOID
119 NTAPI
120 PALETTE_vGetBitMasks(
121     PPALETTE ppal,
122     PULONG pulColors);
123 
124 VOID
125 NTAPI
126 PALETTE_vCleanup(PVOID ObjectBody);
127 
128 FORCEINLINE
129 ULONG
CalculateShift(ULONG ulMask1,ULONG ulMask2)130 CalculateShift(ULONG ulMask1, ULONG ulMask2)
131 {
132     ULONG ulShift1, ulShift2;
133     BitScanReverse(&ulShift1, ulMask1);
134     BitScanReverse(&ulShift2, ulMask2);
135     ulShift2 -= ulShift1;
136     if ((INT)ulShift2 < 0) ulShift2 += 32;
137     return ulShift2;
138 }
139 
140 FORCEINLINE
141 ULONG
PALETTE_ulGetRGBColorFromIndex(PPALETTE ppal,ULONG ulIndex)142 PALETTE_ulGetRGBColorFromIndex(PPALETTE ppal, ULONG ulIndex)
143 {
144     if (ulIndex >= ppal->NumColors) return 0;
145     return RGB(ppal->IndexedColors[ulIndex].peRed,
146                ppal->IndexedColors[ulIndex].peGreen,
147                ppal->IndexedColors[ulIndex].peBlue);
148 }
149 
150 FORCEINLINE
151 VOID
PALETTE_vSetRGBColorForIndex(PPALETTE ppal,ULONG ulIndex,COLORREF crColor)152 PALETTE_vSetRGBColorForIndex(PPALETTE ppal, ULONG ulIndex, COLORREF crColor)
153 {
154     if (ulIndex >= ppal->NumColors) return;
155     ppal->IndexedColors[ulIndex].peRed = GetRValue(crColor);
156     ppal->IndexedColors[ulIndex].peGreen = GetGValue(crColor);
157     ppal->IndexedColors[ulIndex].peBlue = GetBValue(crColor);
158 }
159 
160 HPALETTE
161 NTAPI
162 GreCreatePaletteInternal(
163     IN LPLOGPALETTE pLogPal,
164     IN UINT cEntries);
165 
166