ReactOS  0.4.14-dev-815-ge410a12
palette.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Framebuffer Display Driver
3  * LICENSE: Microsoft NT4 DDK Sample Code License
4  * FILE: win32ss/drivers/displays/framebuf_new/palette.c
5  * PURPOSE: Palette Support
6  * PROGRAMMERS: Copyright (c) 1992-1995 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 
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 NTAPI 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 
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 
66 {
67 // Delete the default palette if we created one.
68 
69  if (ppdev->hpalDefault)
70  {
72  ppdev->hpalDefault = (HPALETTE) 0;
73  }
74 
75  if (ppdev->pPal != (PPALETTEENTRY)NULL)
76  EngFreeMem((PVOID)ppdev->pPal);
77 }
78 
79 /******************************Public*Routine******************************\
80 * bInitDefaultPalette
81 *
82 * Initializes default palette for PDEV.
83 *
84 \**************************************************************************/
85 
87 {
88  if (ppdev->ulBitCount == 8)
89  {
90  ULONG ulLoop;
91  BYTE jRed,jGre,jBlu;
92 
93  //
94  // Allocate our palette
95  //
96 
97  ppdev->pPal = (PPALETTEENTRY)EngAllocMem(0, sizeof(PALETTEENTRY) * 256,
98  ALLOC_TAG);
99 
100  if ((ppdev->pPal) == NULL) {
101  RIP("DISP bInitDefaultPalette() failed EngAllocMem\n");
102  return(FALSE);
103  }
104 
105  //
106  // Generate 256 (8*4*4) RGB combinations to fill the palette
107  //
108 
109  jRed = jGre = jBlu = 0;
110 
111  for (ulLoop = 0; ulLoop < 256; ulLoop++)
112  {
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;
117 
118  if (!(jRed += 32))
119  if (!(jGre += 32))
120  jBlu += 64;
121  }
122 
123  //
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.
127  //
128 
129  for (ulLoop = 0; ulLoop < 10; ulLoop++)
130  {
131  //
132  // First 10
133  //
134 
135  ppdev->pPal[ulLoop] = BASEPALETTE[ulLoop];
136 
137  //
138  // Last 10
139  //
140 
141  ppdev->pPal[246 + ulLoop] = BASEPALETTE[ulLoop+10];
142  }
143 
144  //
145  // Create handle for palette.
146  //
147 
148  ppdev->hpalDefault =
150  256,
151  (PULONG) ppdev->pPal,
152  0,0,0);
153 
154  if (ppdev->hpalDefault == (HPALETTE) 0)
155  {
156  RIP("DISP bInitDefaultPalette failed EngCreatePalette\n");
157  EngFreeMem(ppdev->pPal);
158  return(FALSE);
159  }
160 
161  //
162  // Initialize the hardware with the initial palette.
163  //
164 
165  return(TRUE);
166 
167  } else {
168 
169  ppdev->hpalDefault =
171  0,(PULONG) NULL,
172  ppdev->flRed,
173  ppdev->flGreen,
174  ppdev->flBlue);
175 
176  if (ppdev->hpalDefault == (HPALETTE) 0)
177  {
178  RIP("DISP bInitDefaultPalette failed EngCreatePalette\n");
179  return(FALSE);
180  }
181  }
182 
183  return(TRUE);
184 }
185 
186 /******************************Public*Routine******************************\
187 * bInit256ColorPalette
188 *
189 * Initialize the hardware's palette registers.
190 *
191 \**************************************************************************/
192 
194 {
195  BYTE ajClutSpace[MAX_CLUT_SIZE];
196  PVIDEO_CLUT pScreenClut;
197  ULONG ulReturnedDataLength;
198  ULONG cColors;
199  PVIDEO_CLUTDATA pScreenClutData;
200 
201  if (ppdev->ulBitCount == 8)
202  {
203  //
204  // Fill in pScreenClut header info:
205  //
206 
207  pScreenClut = (PVIDEO_CLUT) ajClutSpace;
208  pScreenClut->NumEntries = 256;
209  pScreenClut->FirstEntry = 0;
210 
211  //
212  // Copy colours in:
213  //
214 
215  cColors = 256;
216  pScreenClutData = (PVIDEO_CLUTDATA) (&(pScreenClut->LookupTable[0]));
217 
218  while(cColors--)
219  {
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;
227  }
228 
229  //
230  // Set palette registers:
231  //
232 
233  if (EngDeviceIoControl(ppdev->hDriver,
235  pScreenClut,
237  NULL,
238  0,
239  &ulReturnedDataLength))
240  {
241  DISPDBG((0, "Failed bEnablePalette"));
242  return(FALSE);
243  }
244  }
245 
246  DISPDBG((5, "Passed bEnablePalette"));
247 
248  return(TRUE);
249 }
250 
251 /******************************Public*Routine******************************\
252 * DrvSetPalette
253 *
254 * DDI entry point for manipulating the palette.
255 *
256 \**************************************************************************/
257 
259 DHPDEV dhpdev,
260 PALOBJ* ppalo,
261 FLONG fl,
262 ULONG iStart,
263 ULONG cColors)
264 {
265  BYTE ajClutSpace[MAX_CLUT_SIZE];
266  PVIDEO_CLUT pScreenClut;
267  PVIDEO_CLUTDATA pScreenClutData;
268  PDEV* ppdev;
269 
271 
272  ppdev = (PDEV*) dhpdev;
273 
274  //
275  // Fill in pScreenClut header info:
276  //
277 
278  pScreenClut = (PVIDEO_CLUT) ajClutSpace;
279  pScreenClut->NumEntries = (USHORT) cColors;
280  pScreenClut->FirstEntry = (USHORT) iStart;
281 
282  pScreenClutData = (PVIDEO_CLUTDATA) (&(pScreenClut->LookupTable[0]));
283 
284  if (cColors != PALOBJ_cGetColors(ppalo, iStart, cColors,
285  (ULONG*) pScreenClutData))
286  {
287  DISPDBG((0, "DrvSetPalette failed PALOBJ_cGetColors\n"));
288  return (FALSE);
289  }
290 
291  //
292  // Set the high reserved byte in each palette entry to 0.
293  // Do the appropriate palette shifting to fit in the DAC.
294  //
295 
296  if (ppdev->cPaletteShift)
297  {
298  while(cColors--)
299  {
300  pScreenClutData[cColors].Red >>= ppdev->cPaletteShift;
301  pScreenClutData[cColors].Green >>= ppdev->cPaletteShift;
302  pScreenClutData[cColors].Blue >>= ppdev->cPaletteShift;
303  pScreenClutData[cColors].Unused = 0;
304  }
305  }
306  else
307  {
308  while(cColors--)
309  {
310  pScreenClutData[cColors].Unused = 0;
311  }
312  }
313 
314  //
315  // Set palette registers
316  //
317 
318  if (EngDeviceIoControl(ppdev->hDriver,
320  pScreenClut,
322  NULL,
323  0,
324  &cColors))
325  {
326  DISPDBG((0, "DrvSetPalette failed EngDeviceIoControl\n"));
327  return (FALSE);
328  }
329 
330  return(TRUE);
331 
332 }
#define TRUE
Definition: types.h:120
BOOL NTAPI bInitDefaultPalette(PPDEV ppdev, DEVINFO *pDevInfo)
Definition: palette.c:86
typedef DHPDEV(APIENTRY FN_DrvEnablePDEV)(_In_ DEVMODEW *pdm
BOOL APIENTRY DrvSetPalette(IN DHPDEV dhpdev, IN PALOBJ *ppalo, IN FLONG fl, IN ULONG iStart, IN ULONG cColors)
Definition: palette.c:170
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define EngFreeMem
Definition: polytest.cpp:56
USHORT FirstEntry
Definition: ntddvdeo.h:520
BOOL NTAPI bInit256ColorPalette(PPDEV ppdev)
Definition: palette.c:193
#define RIP(x)
Definition: debug.h:24
_In_ UINT iStart
Definition: wingdi.h:3619
HPALETTE hpalDefault
Definition: driver.h:27
struct VIDEO_CLUT * PVIDEO_CLUT
ULONG APIENTRY PALOBJ_cGetColors(PALOBJ *PalObj, ULONG Start, ULONG Colors, ULONG *PaletteEntry)
Definition: palette.c:423
#define ALLOC_TAG
Definition: btrfs_drv.h:91
HPALETTE APIENTRY EngCreatePalette(ULONG iMode, ULONG cColors, ULONG *pulColors, ULONG flRed, ULONG flGreen, ULONG flBlue)
Definition: palette.c:375
PALETTEENTRY * pPal
Definition: driver.h:48
FLONG flGreen
Definition: driver.h:37
VOID NTAPI vDisablePalette(PPDEV ppdev)
Definition: palette.c:65
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
_In_ FLONG fl
Definition: winddi.h:1279
unsigned int BOOL
Definition: ntddk_ex.h:94
const PALETTEENTRY BASEPALETTE[20]
Definition: palette.c:28
HANDLE hDriver
Definition: framebuf.h:35
HPALETTE hpalDefault
Definition: winddi.h:398
smooth NULL
Definition: ftsmooth.c:416
BOOL APIENTRY EngDeletePalette(IN HPALETTE hpal)
Definition: palette.c:406
unsigned long FLONG
Definition: ntbasedef.h:373
FLONG flRed
Definition: driver.h:36
ULONG ulBitCount
Definition: driver.h:42
USHORT NumEntries
Definition: ntddvdeo.h:519
#define DISPDBG(arg)
Definition: debug.h:23
_In_ PALOBJ * ppalo
Definition: winddi.h:4012
void * EngAllocMem(int zero, unsigned long size, int tag=0)
Definition: polytest.cpp:70
Definition: framebuf.h:33
unsigned char BYTE
Definition: mem.h:68
ULONG cPaletteShift
Definition: driver.h:39
#define MAX_CLUT_SIZE
Definition: driver.h:64
unsigned short USHORT
Definition: pedump.c:61
unsigned int * PULONG
Definition: retypes.h:1
unsigned int ULONG
Definition: retypes.h:1
struct _VIDEO_CLUTDATA * PVIDEO_CLUTDATA
FLONG flBlue
Definition: driver.h:38
BOOL NTAPI bInitPaletteInfo(PPDEV ppdev, DEVINFO *pDevInfo)
Definition: palette.c:50
struct tagPALETTEENTRY * PPALETTEENTRY
#define IOCTL_VIDEO_SET_COLOR_REGISTERS
Definition: ntddvdeo.h:149
union VIDEO_CLUT::@3062 LookupTable[1]