VirtualBox

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

最後變更 在這個檔案從16605是 16605,由 vboxsync 提交於 16 年 前

header updates

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

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