ReactOS 0.4.15-dev-7953-g1f49173
palette.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Framebuffer Display Driver
3 * LICENSE: Microsoft NT4 DDK Sample Code License
4 * FILE: win32ss/drivers/displays/vga_new/palette.c
5 * PURPOSE: Palette Support
6 * PROGRAMMERS: Copyright (c) 1992-1995 Microsoft Corporation
7 */
8
9#include "driver.h"
10
11// eVb: 4.1 [VGARISC Change] - Add static 16-color VGA palette from VGA NT4 DDK Sample
12
13/******************************Public*Data*Struct*************************\
14* LOGPALETTE
15*
16* This is the palette for the VGA.
17*
18\**************************************************************************/
19
20// Little bit of hacking to get this to compile happily.
21
22typedef struct _VGALOGPALETTE
23{
28
30{
31
320x400, // driver version
3316, // num entries
34{
35 { 0, 0, 0, 0 }, // 0
36 { 0x80,0, 0, 0 }, // 1
37 { 0, 0x80,0, 0 }, // 2
38 { 0x80,0x80,0, 0 }, // 3
39 { 0, 0, 0x80,0 }, // 4
40 { 0x80,0, 0x80,0 }, // 5
41 { 0, 0x80,0x80,0 }, // 6
42 { 0x80,0x80,0x80,0 }, // 7
43
44 { 0xC0,0xC0,0xC0,0 }, // 8
45 { 0xFF,0, 0, 0 }, // 9
46 { 0, 0xFF,0, 0 }, // 10
47 { 0xFF,0xFF,0, 0 }, // 11
48 { 0, 0, 0xFF,0 }, // 12
49 { 0xFF,0, 0xFF,0 }, // 13
50 { 0, 0xFF,0xFF,0 }, // 14
51 { 0xFF,0xFF,0xFF,0 } // 15
52}
53};
54// eVb: 4.1 [END]
55
56BOOL bInitDefaultPalette(PPDEV ppdev, DEVINFO *pDevInfo);
57
58/******************************Public*Routine******************************\
59* bInitPaletteInfo
60*
61* Initializes the palette information for this PDEV.
62*
63* Called by DrvEnablePDEV.
64*
65\**************************************************************************/
66
68{
69 if (!bInitDefaultPalette(ppdev, pDevInfo))
70 return(FALSE);
71
72 return(TRUE);
73}
74
75/******************************Public*Routine******************************\
76* vDisablePalette
77*
78* Frees resources allocated by bInitPaletteInfo.
79*
80\**************************************************************************/
81
83{
84// Delete the default palette if we created one.
85
86 if (ppdev->hpalDefault)
87 {
89 ppdev->hpalDefault = NULL;
90 }
91
92// eVb: 4.2 [VGARISC Change] - VGA Palette is static, no need to free
93#if 0
94 if (ppdev->pPal != NULL)
95 EngFreeMem((PVOID)ppdev->pPal);
96#endif
97// eVb: 4.2 [END]
98}
99
100/******************************Public*Routine******************************\
101* bInitDefaultPalette
102*
103* Initializes default palette for PDEV.
104*
105\**************************************************************************/
106
108{
109// eVb: 4.3 [VGARISC Change] - VGA Palette is static, no need to build
110#if 0
111 if (ppdev->ulBitCount == 8)
112 {
113 ULONG ulLoop;
114 BYTE jRed,jGre,jBlu;
115
116 //
117 // Allocate our palette
118 //
119
120 ppdev->pPal = (PPALETTEENTRY)EngAllocMem(0, sizeof(PALETTEENTRY) * 256,
121 ALLOC_TAG);
122
123 if ((ppdev->pPal) == NULL) {
124 RIP("DISP bInitDefaultPalette() failed EngAllocMem\n");
125 return(FALSE);
126 }
127
128 //
129 // Generate 256 (8*4*4) RGB combinations to fill the palette
130 //
131
132 jRed = jGre = jBlu = 0;
133
134 for (ulLoop = 0; ulLoop < 256; ulLoop++)
135 {
136 ppdev->pPal[ulLoop].peRed = jRed;
137 ppdev->pPal[ulLoop].peGreen = jGre;
138 ppdev->pPal[ulLoop].peBlue = jBlu;
139 ppdev->pPal[ulLoop].peFlags = (BYTE)0;
140
141 if (!(jRed += 32))
142 if (!(jGre += 32))
143 jBlu += 64;
144 }
145
146 //
147 // Fill in Windows Reserved Colors from the WIN 3.0 DDK
148 // The Window Manager reserved the first and last 10 colors for
149 // painting windows borders and for non-palette managed applications.
150 //
151
152 for (ulLoop = 0; ulLoop < 10; ulLoop++)
153 {
154 //
155 // First 10
156 //
157
158 ppdev->pPal[ulLoop] = BASEPALETTE[ulLoop];
159
160 //
161 // Last 10
162 //
163
164 ppdev->pPal[246 + ulLoop] = BASEPALETTE[ulLoop+10];
165 }
166
167#endif
168// eVb: 4.3 [END]
169 //
170 // Create handle for palette.
171 //
172
173 ppdev->hpalDefault =
175// eVb: 4.4 [VGARISC Change] - VGA Palette is 16 colors, not 256, and static
176 16,
178// eVb: 4.4 [END]
179 0,0,0);
180
181 if (ppdev->hpalDefault == NULL)
182 {
183 RIP("DISP bInitDefaultPalette failed EngCreatePalette\n");
184// eVb: 4.5 [VGARISC Change] - VGA Palette is static, no need to free
185 //EngFreeMem(ppdev->pPal);
186// eVb: 4.5 [END]
187 return(FALSE);
188 }
189
190 //
191 // Initialize the hardware with the initial palette.
192 //
193
194 return(TRUE);
195
196// eVb: 4.6 [VGARISC Change] - VGA Palette is static, no bitfield palette needed
197#if 0
198 } else {
199
200 ppdev->hpalDefault =
202 0, NULL,
203 ppdev->flRed,
204 ppdev->flGreen,
205 ppdev->flBlue);
206
207 if (ppdev->hpalDefault == NULL)
208 {
209 RIP("DISP bInitDefaultPalette failed EngCreatePalette\n");
210 return(FALSE);
211 }
212 }
213
214 return(TRUE);
215#endif
216// eVb: 4.6 [END]
217}
218
219/******************************Public*Routine******************************\
220* bInit256ColorPalette
221*
222* Initialize the hardware's palette registers.
223*
224\**************************************************************************/
225
227{
228 BYTE ajClutSpace[MAX_CLUT_SIZE];
229 PVIDEO_CLUT pScreenClut;
230 ULONG ulReturnedDataLength;
231 ULONG cColors;
232 PVIDEO_CLUTDATA pScreenClutData;
233
234 if (ppdev->ulBitCount == 8)
235 {
236 //
237 // Fill in pScreenClut header info:
238 //
239
240 pScreenClut = (PVIDEO_CLUT) ajClutSpace;
241 pScreenClut->NumEntries = 256;
242 pScreenClut->FirstEntry = 0;
243
244 //
245 // Copy colours in:
246 //
247
248 cColors = 256;
249 pScreenClutData = (PVIDEO_CLUTDATA) (&(pScreenClut->LookupTable[0]));
250
251 while(cColors--)
252 {
253 pScreenClutData[cColors].Red = ppdev->pPal[cColors].peRed >>
254 ppdev->cPaletteShift;
255 pScreenClutData[cColors].Green = ppdev->pPal[cColors].peGreen >>
256 ppdev->cPaletteShift;
257 pScreenClutData[cColors].Blue = ppdev->pPal[cColors].peBlue >>
258 ppdev->cPaletteShift;
259 pScreenClutData[cColors].Unused = 0;
260 }
261
262 //
263 // Set palette registers:
264 //
265
266 if (EngDeviceIoControl(ppdev->hDriver,
268 pScreenClut,
270 NULL,
271 0,
272 &ulReturnedDataLength))
273 {
274 DISPDBG((0, "Failed bEnablePalette"));
275 return(FALSE);
276 }
277 }
278
279 DISPDBG((5, "Passed bEnablePalette"));
280
281 return(TRUE);
282}
283
284/******************************Public*Routine******************************\
285* DrvSetPalette
286*
287* DDI entry point for manipulating the palette.
288*
289\**************************************************************************/
290
292DHPDEV dhpdev,
294FLONG fl,
296ULONG cColors)
297{
298 BYTE ajClutSpace[MAX_CLUT_SIZE];
299 PVIDEO_CLUT pScreenClut;
300 PVIDEO_CLUTDATA pScreenClutData;
301 PDEV* ppdev;
302
304
305 ppdev = (PDEV*) dhpdev;
306
307 //
308 // Fill in pScreenClut header info:
309 //
310
311 pScreenClut = (PVIDEO_CLUT) ajClutSpace;
312 pScreenClut->NumEntries = (USHORT) cColors;
313 pScreenClut->FirstEntry = (USHORT) iStart;
314
315 pScreenClutData = (PVIDEO_CLUTDATA) (&(pScreenClut->LookupTable[0]));
316
317 if (cColors != PALOBJ_cGetColors(ppalo, iStart, cColors,
318 (ULONG*) pScreenClutData))
319 {
320 DISPDBG((0, "DrvSetPalette failed PALOBJ_cGetColors\n"));
321 return (FALSE);
322 }
323
324 //
325 // Set the high reserved byte in each palette entry to 0.
326 // Do the appropriate palette shifting to fit in the DAC.
327 //
328
329 if (ppdev->cPaletteShift)
330 {
331 while(cColors--)
332 {
333 pScreenClutData[cColors].Red >>= ppdev->cPaletteShift;
334 pScreenClutData[cColors].Green >>= ppdev->cPaletteShift;
335 pScreenClutData[cColors].Blue >>= ppdev->cPaletteShift;
336 pScreenClutData[cColors].Unused = 0;
337 }
338 }
339 else
340 {
341 while(cColors--)
342 {
343 pScreenClutData[cColors].Unused = 0;
344 }
345 }
346
347 //
348 // Set palette registers
349 //
350
351 if (EngDeviceIoControl(ppdev->hDriver,
353 pScreenClut,
355 NULL,
356 0,
357 &cColors))
358 {
359 DISPDBG((0, "DrvSetPalette failed EngDeviceIoControl\n"));
360 return (FALSE);
361 }
362
363 return(TRUE);
364
365}
#define ALLOC_TAG
Definition: btrfs_drv.h:87
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define APIENTRY
Definition: api.h:79
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long FLONG
Definition: ntbasedef.h:366
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define IOCTL_VIDEO_SET_COLOR_REGISTERS
Definition: ntddvdeo.h:218
struct VIDEO_CLUT * PVIDEO_CLUT
struct _VIDEO_CLUTDATA * PVIDEO_CLUTDATA
unsigned short USHORT
Definition: pedump.c:61
#define EngFreeMem
Definition: polytest.cpp:56
void * EngAllocMem(int zero, unsigned long size, int tag=0)
Definition: polytest.cpp:70
USHORT FirstEntry
Definition: ntddvdeo.h:590
union VIDEO_CLUT::@3181 LookupTable[1]
USHORT NumEntries
Definition: ntddvdeo.h:589
HPALETTE hpalDefault
Definition: winddi.h:398
Definition: framebuf.h:34
ULONG cPaletteShift
Definition: driver.h:37
FLONG flRed
Definition: driver.h:34
ULONG ulBitCount
Definition: driver.h:40
FLONG flGreen
Definition: driver.h:35
PALETTEENTRY * pPal
Definition: driver.h:46
HANDLE hDriver
Definition: framebuf.h:35
FLONG flBlue
Definition: driver.h:36
HPALETTE hpalDefault
Definition: driver.h:25
PALETTEENTRY palPalEntry[16]
Definition: palette.c:26
USHORT NumEntries
Definition: enable.c:136
USHORT ident
Definition: enable.c:135
uint32_t * PULONG
Definition: typedefs.h:59
uint32_t ULONG
Definition: typedefs.h:59
const PALETTEENTRY BASEPALETTE[20]
Definition: palette.c:28
#define RIP(x)
Definition: debug.h:24
#define DISPDBG(arg)
Definition: debug.h:23
#define MAX_CLUT_SIZE
Definition: driver.h:66
VOID vDisablePalette(PPDEV ppdev)
Definition: palette.c:82
BOOL bInitDefaultPalette(PPDEV ppdev, DEVINFO *pDevInfo)
Definition: palette.c:107
struct _VGALOGPALETTE VGALOGPALETTE
BOOL bInit256ColorPalette(PPDEV ppdev)
Definition: palette.c:226
BOOL bInitPaletteInfo(PPDEV ppdev, DEVINFO *pDevInfo)
Definition: palette.c:67
const VGALOGPALETTE logPalVGA
Definition: palette.c:29
_In_ PALOBJ * ppalo
Definition: winddi.h:4012
typedef DHPDEV(APIENTRY FN_DrvEnablePDEV)(_In_ DEVMODEW *pdm
FN_DrvSetPalette DrvSetPalette
_In_ FLONG fl
Definition: winddi.h:1279
#define PAL_BITFIELDS
Definition: winddi.h:1562
ENGAPI BOOL APIENTRY EngDeletePalette(_In_ _Post_ptr_invalid_ HPALETTE hpal)
ENGAPI ULONG APIENTRY PALOBJ_cGetColors(_In_ PALOBJ *ppalo, _In_ ULONG iStart, _In_ ULONG cColors, _Out_writes_(cColors) ULONG *pulColors)
#define PAL_INDEXED
Definition: winddi.h:1561
_Must_inspect_result_ ENGAPI HPALETTE APIENTRY EngCreatePalette(_In_ ULONG iMode, _In_ ULONG cColors, _In_ ULONG *pulColors, _In_ FLONG flRed, _In_ FLONG flGreen, _In_ FLONG flBlue)
struct tagPALETTEENTRY * PPALETTEENTRY
_In_ UINT iStart
Definition: wingdi.h:3620
unsigned char BYTE
Definition: xxhash.c:193