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