VirtualBox

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

Last change on this file since 35650 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

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