2 * PROJECT: ReactOS Framebuffer Display Driver
3 * LICENSE: Microsoft NT4 DDK Sample Code License
4 * FILE: boot/drivers/video/displays/framebuf/palette.c
5 * PURPOSE: Palette Support
6 * PROGRAMMERS: Copyright (c) 1992-1995 Microsoft Corporation
11 // Global Table defining the 20 Window Default Colors. For 256 color
12 // palettes the first 10 must be put at the beginning of the palette
13 // and the last 10 at the end of the palette.
15 const PALETTEENTRY BASEPALETTE
[20] =
18 { 0x80,0, 0, 0 }, // 1
19 { 0, 0x80,0, 0 }, // 2
20 { 0x80,0x80,0, 0 }, // 3
21 { 0, 0, 0x80,0 }, // 4
22 { 0x80,0, 0x80,0 }, // 5
23 { 0, 0x80,0x80,0 }, // 6
24 { 0xC0,0xC0,0xC0,0 }, // 7
25 { 192, 220, 192, 0 }, // 8
26 { 166, 202, 240, 0 }, // 9
27 { 255, 251, 240, 0 }, // 10
28 { 160, 160, 164, 0 }, // 11
29 { 0x80,0x80,0x80,0 }, // 12
30 { 0xFF,0, 0 ,0 }, // 13
31 { 0, 0xFF,0 ,0 }, // 14
32 { 0xFF,0xFF,0 ,0 }, // 15
33 { 0 ,0, 0xFF,0 }, // 16
34 { 0xFF,0, 0xFF,0 }, // 17
35 { 0, 0xFF,0xFF,0 }, // 18
36 { 0xFF,0xFF,0xFF,0 }, // 19
39 BOOL
bInitDefaultPalette(PPDEV ppdev
, DEVINFO
*pDevInfo
);
41 /******************************Public*Routine******************************\
44 * Initializes the palette information for this PDEV.
46 * Called by DrvEnablePDEV.
48 \**************************************************************************/
50 BOOL
bInitPaletteInfo(PPDEV ppdev
, DEVINFO
*pDevInfo
)
52 if (!bInitDefaultPalette(ppdev
, pDevInfo
))
58 /******************************Public*Routine******************************\
61 * Frees resources allocated by bInitPaletteInfo.
63 \**************************************************************************/
65 VOID
vDisablePalette(PPDEV ppdev
)
67 // Delete the default palette if we created one.
69 if (ppdev
->hpalDefault
)
71 EngDeletePalette(ppdev
->hpalDefault
);
72 ppdev
->hpalDefault
= (HPALETTE
) 0;
75 if (ppdev
->pPal
!= (PPALETTEENTRY
)NULL
)
76 EngFreeMem((PVOID
)ppdev
->pPal
);
79 /******************************Public*Routine******************************\
82 * Initializes default palette for PDEV.
84 \**************************************************************************/
86 BOOL
bInitDefaultPalette(PPDEV ppdev
, DEVINFO
*pDevInfo
)
88 if (ppdev
->ulBitCount
== 8)
94 // Allocate our palette
97 ppdev
->pPal
= (PPALETTEENTRY
)EngAllocMem(0, sizeof(PALETTEENTRY
) * 256,
100 if ((ppdev
->pPal
) == NULL
) {
101 RIP("DISP bInitDefaultPalette() failed EngAllocMem\n");
106 // Generate 256 (8*4*4) RGB combinations to fill the palette
109 jRed
= jGre
= jBlu
= 0;
111 for (ulLoop
= 0; ulLoop
< 256; ulLoop
++)
113 ppdev
->pPal
[ulLoop
].peRed
= jRed
;
114 ppdev
->pPal
[ulLoop
].peGreen
= jGre
;
115 ppdev
->pPal
[ulLoop
].peBlue
= jBlu
;
116 ppdev
->pPal
[ulLoop
].peFlags
= (BYTE
)0;
124 // Fill in Windows Reserved Colors from the WIN 3.0 DDK
125 // The Window Manager reserved the first and last 10 colors for
126 // painting windows borders and for non-palette managed applications.
129 for (ulLoop
= 0; ulLoop
< 10; ulLoop
++)
135 ppdev
->pPal
[ulLoop
] = BASEPALETTE
[ulLoop
];
141 ppdev
->pPal
[246 + ulLoop
] = BASEPALETTE
[ulLoop
+10];
145 // Create handle for palette.
149 pDevInfo
->hpalDefault
= EngCreatePalette(PAL_INDEXED
,
151 (PULONG
) ppdev
->pPal
,
154 if (ppdev
->hpalDefault
== (HPALETTE
) 0)
156 RIP("DISP bInitDefaultPalette failed EngCreatePalette\n");
157 EngFreeMem(ppdev
->pPal
);
162 // Initialize the hardware with the initial palette.
170 pDevInfo
->hpalDefault
= EngCreatePalette(PAL_BITFIELDS
,
176 if (ppdev
->hpalDefault
== (HPALETTE
) 0)
178 RIP("DISP bInitDefaultPalette failed EngCreatePalette\n");
186 /******************************Public*Routine******************************\
187 * bInit256ColorPalette
189 * Initialize the hardware's palette registers.
191 \**************************************************************************/
193 BOOL
bInit256ColorPalette(PPDEV ppdev
)
195 BYTE ajClutSpace
[MAX_CLUT_SIZE
];
196 PVIDEO_CLUT pScreenClut
;
197 ULONG ulReturnedDataLength
;
199 PVIDEO_CLUTDATA pScreenClutData
;
201 if (ppdev
->ulBitCount
== 8)
204 // Fill in pScreenClut header info:
207 pScreenClut
= (PVIDEO_CLUT
) ajClutSpace
;
208 pScreenClut
->NumEntries
= 256;
209 pScreenClut
->FirstEntry
= 0;
216 pScreenClutData
= (PVIDEO_CLUTDATA
) (&(pScreenClut
->LookupTable
[0]));
220 pScreenClutData
[cColors
].Red
= ppdev
->pPal
[cColors
].peRed
>>
221 ppdev
->cPaletteShift
;
222 pScreenClutData
[cColors
].Green
= ppdev
->pPal
[cColors
].peGreen
>>
223 ppdev
->cPaletteShift
;
224 pScreenClutData
[cColors
].Blue
= ppdev
->pPal
[cColors
].peBlue
>>
225 ppdev
->cPaletteShift
;
226 pScreenClutData
[cColors
].Unused
= 0;
230 // Set palette registers:
233 if (EngDeviceIoControl(ppdev
->hDriver
,
234 IOCTL_VIDEO_SET_COLOR_REGISTERS
,
239 &ulReturnedDataLength
))
241 DISPDBG((0, "Failed bEnablePalette"));
246 DISPDBG((5, "Passed bEnablePalette"));
251 /******************************Public*Routine******************************\
254 * DDI entry point for manipulating the palette.
256 \**************************************************************************/
265 BYTE ajClutSpace
[MAX_CLUT_SIZE
];
266 PVIDEO_CLUT pScreenClut
;
267 PVIDEO_CLUTDATA pScreenClutData
;
270 UNREFERENCED_PARAMETER(fl
);
272 ppdev
= (PDEV
*) dhpdev
;
275 // Fill in pScreenClut header info:
278 pScreenClut
= (PVIDEO_CLUT
) ajClutSpace
;
279 pScreenClut
->NumEntries
= (USHORT
) cColors
;
280 pScreenClut
->FirstEntry
= (USHORT
) iStart
;
282 pScreenClutData
= (PVIDEO_CLUTDATA
) (&(pScreenClut
->LookupTable
[0]));
284 if (cColors
!= PALOBJ_cGetColors(ppalo
, iStart
, cColors
,
285 (ULONG
*) pScreenClutData
))
287 DISPDBG((0, "DrvSetPalette failed PALOBJ_cGetColors\n"));
292 // Set the high reserved byte in each palette entry to 0.
293 // Do the appropriate palette shifting to fit in the DAC.
296 if (ppdev
->cPaletteShift
)
300 pScreenClutData
[cColors
].Red
>>= ppdev
->cPaletteShift
;
301 pScreenClutData
[cColors
].Green
>>= ppdev
->cPaletteShift
;
302 pScreenClutData
[cColors
].Blue
>>= ppdev
->cPaletteShift
;
303 pScreenClutData
[cColors
].Unused
= 0;
310 pScreenClutData
[cColors
].Unused
= 0;
315 // Set palette registers
318 if (EngDeviceIoControl(ppdev
->hDriver
,
319 IOCTL_VIDEO_SET_COLOR_REGISTERS
,
326 DISPDBG((0, "DrvSetPalette failed EngDeviceIoControl\n"));