VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Display/palette.c@ 5952

Last change on this file since 5952 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 KB
Line 
1/******************************Module*Header*******************************\
2*
3* *******************
4* * GDI SAMPLE CODE *
5* *******************
6*
7* Module Name: palette.c
8*
9* Palette support.
10*
11* Copyright (c) 1992-1998 Microsoft Corporation
12\**************************************************************************/
13
14#include "driver.h"
15
16// Global Table defining the 20 Window Default Colors. For 256 color
17// palettes the first 10 must be put at the beginning of the palette
18// and the last 10 at the end of the palette.
19
20const PALETTEENTRY BASEPALETTE[20] =
21{
22 { 0, 0, 0, 0 }, // 0
23 { 0x80,0, 0, 0 }, // 1
24 { 0, 0x80,0, 0 }, // 2
25 { 0x80,0x80,0, 0 }, // 3
26 { 0, 0, 0x80,0 }, // 4
27 { 0x80,0, 0x80,0 }, // 5
28 { 0, 0x80,0x80,0 }, // 6
29 { 0xC0,0xC0,0xC0,0 }, // 7
30 { 192, 220, 192, 0 }, // 8
31 { 166, 202, 240, 0 }, // 9
32 { 255, 251, 240, 0 }, // 10
33 { 160, 160, 164, 0 }, // 11
34 { 0x80,0x80,0x80,0 }, // 12
35 { 0xFF,0, 0 ,0 }, // 13
36 { 0, 0xFF,0 ,0 }, // 14
37 { 0xFF,0xFF,0 ,0 }, // 15
38 { 0 ,0, 0xFF,0 }, // 16
39 { 0xFF,0, 0xFF,0 }, // 17
40 { 0, 0xFF,0xFF,0 }, // 18
41 { 0xFF,0xFF,0xFF,0 }, // 19
42};
43
44BOOL bInitDefaultPalette(PPDEV ppdev, DEVINFO *pDevInfo);
45
46/******************************Public*Routine******************************\
47* bInitPaletteInfo
48*
49* Initializes the palette information for this PDEV.
50*
51* Called by DrvEnablePDEV.
52*
53\**************************************************************************/
54
55BOOL bInitPaletteInfo(PPDEV ppdev, DEVINFO *pDevInfo)
56{
57 if (!bInitDefaultPalette(ppdev, pDevInfo))
58 return(FALSE);
59
60 return(TRUE);
61}
62
63/******************************Public*Routine******************************\
64* vDisablePalette
65*
66* Frees resources allocated by bInitPaletteInfo.
67*
68\**************************************************************************/
69
70VOID vDisablePalette(PPDEV ppdev)
71{
72// Delete the default palette if we created one.
73
74 if (ppdev->hpalDefault)
75 {
76 EngDeletePalette(ppdev->hpalDefault);
77 ppdev->hpalDefault = (HPALETTE) 0;
78 }
79
80 if (ppdev->pPal != (PPALETTEENTRY)NULL)
81 EngFreeMem((PVOID)ppdev->pPal);
82}
83
84/******************************Public*Routine******************************\
85* bInitDefaultPalette
86*
87* Initializes default palette for PDEV.
88*
89\**************************************************************************/
90
91BOOL bInitDefaultPalette(PPDEV ppdev, DEVINFO *pDevInfo)
92{
93 if (ppdev->ulBitCount == 8)
94 {
95 ULONG ulLoop;
96 BYTE jRed,jGre,jBlu;
97
98 //
99 // Allocate our palette
100 //
101
102 ppdev->pPal = (PPALETTEENTRY)EngAllocMem(0, sizeof(PALETTEENTRY) * 256,
103 ALLOC_TAG);
104
105 if ((ppdev->pPal) == NULL) {
106 DISPDBG((0, "DISP bInitDefaultPalette() failed EngAllocMem\n"));
107 return(FALSE);
108 }
109
110 //
111 // Generate 256 (8*4*4) RGB combinations to fill the palette
112 //
113
114 jRed = jGre = jBlu = 0;
115
116 for (ulLoop = 0; ulLoop < 256; ulLoop++)
117 {
118 ppdev->pPal[ulLoop].peRed = jRed;
119 ppdev->pPal[ulLoop].peGreen = jGre;
120 ppdev->pPal[ulLoop].peBlue = jBlu;
121 ppdev->pPal[ulLoop].peFlags = (BYTE)0;
122
123 if (!(jRed += 32))
124 if (!(jGre += 32))
125 jBlu += 64;
126 }
127
128 //
129 // Fill in Windows Reserved Colors from the WIN 3.0 DDK
130 // The Window Manager reserved the first and last 10 colors for
131 // painting windows borders and for non-palette managed applications.
132 //
133
134 for (ulLoop = 0; ulLoop < 10; ulLoop++)
135 {
136 //
137 // First 10
138 //
139
140 ppdev->pPal[ulLoop] = BASEPALETTE[ulLoop];
141
142 //
143 // Last 10
144 //
145
146 ppdev->pPal[246 + ulLoop] = BASEPALETTE[ulLoop+10];
147 }
148
149 //
150 // Create handle for palette.
151 //
152
153 ppdev->hpalDefault =
154 pDevInfo->hpalDefault = EngCreatePalette(PAL_INDEXED,
155 256,
156 (PULONG) ppdev->pPal,
157 0,0,0);
158
159 if (ppdev->hpalDefault == (HPALETTE) 0)
160 {
161 DISPDBG((0, "DISP bInitDefaultPalette failed EngCreatePalette\n"));
162 EngFreeMem(ppdev->pPal);
163 return(FALSE);
164 }
165
166 //
167 // Initialize the hardware with the initial palette.
168 //
169
170 return(TRUE);
171
172 } else {
173
174 ppdev->hpalDefault =
175 pDevInfo->hpalDefault = EngCreatePalette(PAL_BITFIELDS,
176 0,(PULONG) NULL,
177 ppdev->flRed,
178 ppdev->flGreen,
179 ppdev->flBlue);
180
181 if (ppdev->hpalDefault == (HPALETTE) 0)
182 {
183 DISPDBG((0, "DISP bInitDefaultPalette failed EngCreatePalette\n"));
184 return(FALSE);
185 }
186 }
187
188 return(TRUE);
189}
190
191/******************************Public*Routine******************************\
192* bInit256ColorPalette
193*
194* Initialize the hardware's palette registers.
195*
196\**************************************************************************/
197
198BOOL bInit256ColorPalette(PPDEV ppdev)
199{
200 BYTE ajClutSpace[MAX_CLUT_SIZE];
201 PVIDEO_CLUT pScreenClut;
202 ULONG ulReturnedDataLength;
203 ULONG cColors;
204 PVIDEO_CLUTDATA pScreenClutData;
205
206 if (ppdev->ulBitCount == 8)
207 {
208 //
209 // Fill in pScreenClut header info:
210 //
211
212 pScreenClut = (PVIDEO_CLUT) ajClutSpace;
213 pScreenClut->NumEntries = 256;
214 pScreenClut->FirstEntry = 0;
215
216 //
217 // Copy colours in:
218 //
219
220 cColors = 256;
221 pScreenClutData = (PVIDEO_CLUTDATA) (&(pScreenClut->LookupTable[0]));
222
223 while(cColors--)
224 {
225 pScreenClutData[cColors].Red = ppdev->pPal[cColors].peRed >>
226 ppdev->cPaletteShift;
227 pScreenClutData[cColors].Green = ppdev->pPal[cColors].peGreen >>
228 ppdev->cPaletteShift;
229 pScreenClutData[cColors].Blue = ppdev->pPal[cColors].peBlue >>
230 ppdev->cPaletteShift;
231 pScreenClutData[cColors].Unused = 0;
232 }
233
234 //
235 // Set palette registers:
236 //
237
238 if (EngDeviceIoControl(ppdev->hDriver,
239 IOCTL_VIDEO_SET_COLOR_REGISTERS,
240 pScreenClut,
241 MAX_CLUT_SIZE,
242 NULL,
243 0,
244 &ulReturnedDataLength))
245 {
246 DISPDBG((0, "Failed bEnablePalette"));
247 return(FALSE);
248 }
249 }
250
251 DISPDBG((5, "Passed bEnablePalette"));
252
253 return(TRUE);
254}
255
256/******************************Public*Routine******************************\
257* DrvSetPalette
258*
259* DDI entry point for manipulating the palette.
260*
261\**************************************************************************/
262
263BOOL DrvSetPalette(
264DHPDEV dhpdev,
265PALOBJ* ppalo,
266FLONG fl,
267ULONG iStart,
268ULONG cColors)
269{
270 BYTE ajClutSpace[MAX_CLUT_SIZE];
271 PVIDEO_CLUT pScreenClut;
272 PVIDEO_CLUTDATA pScreenClutData;
273 PDEV* ppdev;
274
275 UNREFERENCED_PARAMETER(fl);
276
277 ppdev = (PDEV*) dhpdev;
278
279 //
280 // Fill in pScreenClut header info:
281 //
282
283 pScreenClut = (PVIDEO_CLUT) ajClutSpace;
284 pScreenClut->NumEntries = (USHORT) cColors;
285 pScreenClut->FirstEntry = (USHORT) iStart;
286
287 pScreenClutData = (PVIDEO_CLUTDATA) (&(pScreenClut->LookupTable[0]));
288
289 if (cColors != PALOBJ_cGetColors(ppalo, iStart, cColors,
290 (ULONG*) pScreenClutData))
291 {
292 DISPDBG((0, "DrvSetPalette failed PALOBJ_cGetColors\n"));
293 return (FALSE);
294 }
295
296 //
297 // Set the high reserved byte in each palette entry to 0.
298 // Do the appropriate palette shifting to fit in the DAC.
299 //
300
301 if (ppdev->cPaletteShift)
302 {
303 while(cColors--)
304 {
305 pScreenClutData[cColors].Red >>= ppdev->cPaletteShift;
306 pScreenClutData[cColors].Green >>= ppdev->cPaletteShift;
307 pScreenClutData[cColors].Blue >>= ppdev->cPaletteShift;
308 pScreenClutData[cColors].Unused = 0;
309 }
310 }
311 else
312 {
313 while(cColors--)
314 {
315 pScreenClutData[cColors].Unused = 0;
316 }
317 }
318
319 //
320 // Set palette registers
321 //
322
323 if (EngDeviceIoControl(ppdev->hDriver,
324 IOCTL_VIDEO_SET_COLOR_REGISTERS,
325 pScreenClut,
326 MAX_CLUT_SIZE,
327 NULL,
328 0,
329 &cColors))
330 {
331 DISPDBG((0, "DrvSetPalette failed EngDeviceIoControl\n"));
332 return (FALSE);
333 }
334
335 return(TRUE);
336
337}
338
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette