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