|
|
1.1 root 1: /******************************Module*Header*******************************\
2: * Module Name: palette.c
3: *
4: * Palette support.
5: *
6: * Copyright (c) 1992 Microsoft Corporation
7: \**************************************************************************/
8:
9: #include "driver.h"
10:
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.
14:
15: const PALETTEENTRY BASEPALETTE[20] =
16: {
17: { 0, 0, 0, 0 }, // 0
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
37: };
38:
39: BOOL bInitDefaultPalette(PPDEV ppdev, DEVINFO *pDevInfo);
40:
41: /******************************Public*Routine******************************\
42: * bInitPaletteInfo
43: *
44: * Initializes the palette information for this PDEV.
45: *
46: * Called by DrvEnablePDEV.
47: *
48: \**************************************************************************/
49:
50: BOOL bInitPaletteInfo(PPDEV ppdev, DEVINFO *pDevInfo)
51: {
52: if (!bInitDefaultPalette(ppdev, pDevInfo))
53: return(FALSE);
54:
55: return(TRUE);
56: }
57:
58: /******************************Public*Routine******************************\
59: * vDisablePalette
60: *
61: * Frees resources allocated by bInitPaletteInfo.
62: *
63: \**************************************************************************/
64:
65: VOID vDisablePalette(PPDEV ppdev)
66: {
67: // Delete the default palette if we created one.
68:
69: if (ppdev->hpalDefault)
70: {
71: EngDeletePalette(ppdev->hpalDefault);
72: ppdev->hpalDefault = (HPALETTE) 0;
73: }
74:
75: if (ppdev->pPal != (PPALETTEENTRY)NULL)
76: LocalFree((PVOID)ppdev->pPal);
77: }
78:
79: /******************************Public*Routine******************************\
80: * bInitDefaultPalette
81: *
82: * Initializes default palette for PDEV.
83: *
84: \**************************************************************************/
85:
86: BOOL bInitDefaultPalette(PPDEV ppdev, DEVINFO *pDevInfo)
87: {
88: if (ppdev->ulBitCount == 8)
89: {
90: ULONG ulLoop;
91: BYTE jRed,jGre,jBlu;
92:
93: // Allocate our palette
94:
95: ppdev->pPal = (PPALETTEENTRY)LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT,
96: (sizeof(PALETTEENTRY) * 256));
97:
98: if ((ppdev->pPal) == NULL) {
99: DISPDBG((0, "DISP bInitDefaultPalette() failed LocalAlloc\n"));
100: return(FALSE);
101: }
102:
103:
104: // Generate 256 (8*4*4) RGB combinations to fill the palette
105:
106: jRed = jGre = jBlu = 0;
107:
108: for (ulLoop = 0; ulLoop < 256; ulLoop++)
109: {
110: ppdev->pPal[ulLoop].peRed = jRed;
111: ppdev->pPal[ulLoop].peGreen = jGre;
112: ppdev->pPal[ulLoop].peBlue = jBlu;
113: ppdev->pPal[ulLoop].peFlags = (BYTE)0;
114:
115: if (!(jRed += 32))
116: if (!(jGre += 32))
117: jBlu += 64;
118: }
119:
120: // Fill in Windows Reserved Colors from the WIN 3.0 DDK
121: // The Window Manager reserved the first and last 10 colors for
122: // painting windows borders and for non-palette managed applications.
123:
124: for (ulLoop = 0; ulLoop < 10; ulLoop++)
125: {
126: // First 10
127:
128: ppdev->pPal[ulLoop] = BASEPALETTE[ulLoop];
129:
130: // Last 10
131:
132: ppdev->pPal[246 + ulLoop] = BASEPALETTE[ulLoop+10];
133: }
134:
135: // Create handle for palette.
136:
137: ppdev->hpalDefault =
138: pDevInfo->hpalDefault = EngCreatePalette(PAL_INDEXED,
139: 256,
140: (PULONG) ppdev->pPal,
141: 0,0,0);
142:
143: if (ppdev->hpalDefault == (HPALETTE) 0)
144: {
145: DISPDBG((0, "DISP bInitDefaultPalette failed EngCreatePalette\n"));
146: LocalFree(ppdev->pPal);
147: return(FALSE);
148: }
149:
150: // Initialize the hardware with the initial palette.
151:
152: return(TRUE);
153: }
154: else if (ppdev->ulBitCount == 16)
155: {
156: ppdev->hpalDefault =
157: pDevInfo->hpalDefault = EngCreatePalette(PAL_BITFIELDS,
158: 0,
159: (PULONG) NULL,
160: ppdev->flRed,
161: ppdev->flGreen,
162: ppdev->flBlue);
163:
164: if (ppdev->hpalDefault == (HPALETTE) 0)
165: {
166: DISPDBG((0, "DISP bInitDefaultPalette failed EngCreatePalette\n"));
167: return(FALSE);
168: }
169: }
170: else
171: {
172: RIP("XGA.DLL: bInitDefaultPalette-wrong BitCount\n");
173:
174: }
175:
176: return(TRUE);
177: }
178:
179: /******************************Public*Routine******************************\
180: * bInit256ColorPalette
181: *
182: * Initialize the hardware's palette registers.
183: *
184: \**************************************************************************/
185:
186: BOOL bInit256ColorPalette(PPDEV ppdev)
187: {
188: BYTE ajClutSpace[MAX_CLUT_SIZE];
189: PVIDEO_CLUT pScreenClut = (PVIDEO_CLUT) ajClutSpace;
190: ULONG ulReturnedDataLength;
191:
192: // Fill in pScreenClut header info
193: pScreenClut->NumEntries = 256;
194: pScreenClut->FirstEntry = 0;
195:
196:
197: // Copy Colors in.
198: memcpy(pScreenClut->LookupTable, ppdev->pPal, sizeof(ULONG) * 256);
199:
200: // Set palette registers
201: if (!DeviceIoControl(ppdev->hDriver,
202: IOCTL_VIDEO_SET_COLOR_REGISTERS,
203: pScreenClut,
204: MAX_CLUT_SIZE,
205: NULL,
206: 0,
207: &ulReturnedDataLength,
208: NULL))
209: {
210: DISPDBG((0, "DISP bInit256ColorPalette failed DeviceIoControl\n"));
211: return(FALSE);
212: }
213:
214: return(TRUE);
215: }
216:
217: /******************************Public*Routine******************************\
218: * DrvSetPalette
219: *
220: * DDI entry point for manipulating the palette.
221: *
222: \**************************************************************************/
223:
224: BOOL DrvSetPalette(
225: DHPDEV dhpdev,
226: PALOBJ *ppalo,
227: FLONG fl,
228: ULONG iStart,
229: ULONG cColors)
230: {
231: BYTE ajClutSpace[MAX_CLUT_SIZE];
232: PVIDEO_CLUT pScreenClut = (PVIDEO_CLUT) ajClutSpace;
233: PPALETTEENTRY pape;
234: ULONG ulTemp = 256;
235:
236: UNREFERENCED_PARAMETER(fl);
237:
238: // Fill in pScreenClut header info
239:
240: pScreenClut->NumEntries = (USHORT) cColors;
241: pScreenClut->FirstEntry = (USHORT) iStart;
242:
243: pape = (PPALETTEENTRY) (pScreenClut->LookupTable);
244:
245: if (cColors != PALOBJ_cGetColors(ppalo, iStart, cColors, (PULONG) pape))
246: {
247: DISPDBG((0, "DISP DrvSetPalette failed PALOBJ_cGetColors\n"));
248: return(FALSE);
249: }
250:
251: // Set the high reserved byte in each palette entry to 0.
252:
253: while(cColors--)
254: pape[cColors].peFlags = 0;
255:
256: // Set palette registers
257:
258: if (!DeviceIoControl(((PPDEV)(dhpdev))->hDriver,
259: IOCTL_VIDEO_SET_COLOR_REGISTERS,
260: pScreenClut,
261: MAX_CLUT_SIZE,
262: NULL,
263: 0,
264: &cColors,
265: NULL))
266: {
267: DISPDBG((0, "DISP DrvSetPalette failed DeviceIoControl\n"));
268: return(FALSE);
269: }
270:
271: return(TRUE);
272: }
273:
274:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.