Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

317 lines
9.3 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: palette.c
  3. *
  4. * Palette support.
  5. *
  6. * Copyright (c) 1992 Microsoft Corporation
  7. \**************************************************************************/
  8. #include "precomp.h"
  9. // Global Table defining the 20 Window Default Colors. For 256 color
  10. // palettes the first 10 must be put at the beginning of the palette
  11. // and the last 10 at the end of the palette.
  12. const PALETTEENTRY BASEPALETTE[20] =
  13. {
  14. { 0, 0, 0, 0 }, // 0
  15. { 0x80,0, 0, 0 }, // 1
  16. { 0, 0x80,0, 0 }, // 2
  17. { 0x80,0x80,0, 0 }, // 3
  18. { 0, 0, 0x80,0 }, // 4
  19. { 0x80,0, 0x80,0 }, // 5
  20. { 0, 0x80,0x80,0 }, // 6
  21. { 0xC0,0xC0,0xC0,0 }, // 7
  22. { 192, 220, 192, 0 }, // 8
  23. { 166, 202, 240, 0 }, // 9
  24. { 255, 251, 240, 0 }, // 10
  25. { 160, 160, 164, 0 }, // 11
  26. { 0x80,0x80,0x80,0 }, // 12
  27. { 0xFF,0, 0 ,0 }, // 13
  28. { 0, 0xFF,0 ,0 }, // 14
  29. { 0xFF,0xFF,0 ,0 }, // 15
  30. { 0 ,0, 0xFF,0 }, // 16
  31. { 0xFF,0, 0xFF,0 }, // 17
  32. { 0, 0xFF,0xFF,0 }, // 18
  33. { 0xFF,0xFF,0xFF,0 }, // 19
  34. };
  35. BOOL bInitDefaultPalette(PPDEV ppdev, DEVINFO *pDevInfo);
  36. /******************************Public*Routine******************************\
  37. * bInitPaletteInfo
  38. *
  39. * Initializes the palette information for this PDEV.
  40. *
  41. * Called by DrvEnablePDEV.
  42. *
  43. \**************************************************************************/
  44. BOOL bInitPaletteInfo(PPDEV ppdev, DEVINFO *pDevInfo)
  45. {
  46. if (!bInitDefaultPalette(ppdev, pDevInfo))
  47. return(FALSE);
  48. return(TRUE);
  49. }
  50. /******************************Public*Routine******************************\
  51. * vDisablePalette
  52. *
  53. * Frees resources allocated by bInitPaletteInfo.
  54. *
  55. \**************************************************************************/
  56. VOID vDisablePalette(PPDEV ppdev)
  57. {
  58. // Delete the default palette if we created one.
  59. if (ppdev->hpalDefault)
  60. {
  61. EngDeletePalette(ppdev->hpalDefault);
  62. ppdev->hpalDefault = (HPALETTE) 0;
  63. }
  64. if (ppdev->pPal != (PPALETTEENTRY)NULL)
  65. MEMORY_FREE((PVOID)ppdev->pPal);
  66. }
  67. /******************************Public*Routine******************************\
  68. * bInitDefaultPalette
  69. *
  70. * Initializes default palette for PDEV.
  71. *
  72. \**************************************************************************/
  73. BOOL bInitDefaultPalette(PPDEV ppdev, DEVINFO *pDevInfo)
  74. {
  75. if (ppdev->ulBitCount == 8)
  76. {
  77. ULONG ulLoop;
  78. BYTE jRed,jGre,jBlu;
  79. // Allocate our palette
  80. #ifdef WINNT_VER40
  81. ppdev->pPal = (PPALETTEENTRY)MEM_ALLOC(FL_ZERO_MEMORY,
  82. (sizeof(PALETTEENTRY) * 256), ALLOC_TAG);
  83. #else
  84. ppdev->pPal = (PPALETTEENTRY)MEM_ALLOC(LMEM_FIXED | LMEM_ZEROINIT,
  85. (sizeof(PALETTEENTRY) * 256));
  86. #endif
  87. if ((ppdev->pPal) == NULL) {
  88. RIP("DISP bInitDefaultPalette() failed MEM_ALLOC\n");
  89. return(FALSE);
  90. }
  91. // Generate 256 (8*4*4) RGB combinations to fill the palette
  92. jRed = jGre = jBlu = 0;
  93. for (ulLoop = 0; ulLoop < 256; ulLoop++)
  94. {
  95. ppdev->pPal[ulLoop].peRed = jRed;
  96. ppdev->pPal[ulLoop].peGreen = jGre;
  97. ppdev->pPal[ulLoop].peBlue = jBlu;
  98. ppdev->pPal[ulLoop].peFlags = (BYTE)0;
  99. if (!(jRed += 32))
  100. if (!(jGre += 32))
  101. jBlu += 64;
  102. }
  103. // Fill in Windows Reserved Colors from the WIN 3.0 DDK
  104. // The Window Manager reserved the first and last 10 colors for
  105. // painting windows borders and for non-palette managed applications.
  106. for (ulLoop = 0; ulLoop < 10; ulLoop++)
  107. {
  108. // First 10
  109. ppdev->pPal[ulLoop] = BASEPALETTE[ulLoop];
  110. // Last 10
  111. ppdev->pPal[246 + ulLoop] = BASEPALETTE[ulLoop+10];
  112. }
  113. // Create handle for palette.
  114. ppdev->hpalDefault =
  115. pDevInfo->hpalDefault = EngCreatePalette(PAL_INDEXED,
  116. 256,
  117. (PULONG) ppdev->pPal,
  118. 0,0,0);
  119. if (ppdev->hpalDefault == (HPALETTE) 0)
  120. {
  121. RIP("DISP bInitDefaultPalette failed EngCreatePalette\n");
  122. MEMORY_FREE(ppdev->pPal);
  123. return(FALSE);
  124. }
  125. // Initialize the hardware with the initial palette.
  126. return(TRUE);
  127. } else {
  128. ppdev->hpalDefault =
  129. pDevInfo->hpalDefault = EngCreatePalette(PAL_BITFIELDS,
  130. 0,(PULONG) NULL,
  131. ppdev->flRed,
  132. ppdev->flGreen,
  133. ppdev->flBlue);
  134. if (ppdev->hpalDefault == (HPALETTE) 0)
  135. {
  136. RIP("DISP bInitDefaultPalette failed EngCreatePalette\n");
  137. return(FALSE);
  138. }
  139. }
  140. return(TRUE);
  141. }
  142. /******************************Public*Routine******************************\
  143. * bInit256ColorPalette
  144. *
  145. * Initialize the hardware's palette registers.
  146. *
  147. \**************************************************************************/
  148. BOOL bInit256ColorPalette(PPDEV ppdev)
  149. {
  150. BYTE ajClutSpace[MAX_CLUT_SIZE];
  151. PVIDEO_CLUT pScreenClut;
  152. ULONG ulReturnedDataLength;
  153. ULONG cColors;
  154. PVIDEO_CLUTDATA pScreenClutData;
  155. if (ppdev->ulBitCount == 8)
  156. {
  157. // Fill in pScreenClut header info:
  158. pScreenClut = (PVIDEO_CLUT) ajClutSpace;
  159. pScreenClut->NumEntries = 256;
  160. pScreenClut->FirstEntry = 0;
  161. // Copy colours in:
  162. cColors = 256;
  163. pScreenClutData = (PVIDEO_CLUTDATA) (&(pScreenClut->LookupTable[0]));
  164. while(cColors--)
  165. {
  166. pScreenClutData[cColors].Red = ppdev->pPal[cColors].peRed >>
  167. ppdev->cPaletteShift;
  168. pScreenClutData[cColors].Green = ppdev->pPal[cColors].peGreen >>
  169. ppdev->cPaletteShift;
  170. pScreenClutData[cColors].Blue = ppdev->pPal[cColors].peBlue >>
  171. ppdev->cPaletteShift;
  172. pScreenClutData[cColors].Unused = 0;
  173. }
  174. // Set palette registers:
  175. if (!DEVICE_IO_CTRL(ppdev->hDriver,
  176. IOCTL_VIDEO_SET_COLOR_REGISTERS,
  177. pScreenClut,
  178. MAX_CLUT_SIZE,
  179. NULL,
  180. 0,
  181. &ulReturnedDataLength,
  182. NULL))
  183. {
  184. DISPDBG((1, "Failed bEnablePalette"));
  185. return(FALSE);
  186. }
  187. }
  188. DISPDBG((5, "Passed bEnablePalette"));
  189. return(TRUE);
  190. }
  191. /******************************Public*Routine******************************\
  192. * DrvSetPalette
  193. *
  194. * DDI entry point for manipulating the palette.
  195. *
  196. \**************************************************************************/
  197. BOOL DrvSetPalette(
  198. DHPDEV dhpdev,
  199. PALOBJ* ppalo,
  200. FLONG fl,
  201. ULONG iStart,
  202. ULONG cColors)
  203. {
  204. BYTE ajClutSpace[MAX_CLUT_SIZE];
  205. PVIDEO_CLUT pScreenClut;
  206. PVIDEO_CLUTDATA pScreenClutData;
  207. PDEV* ppdev;
  208. UNREFERENCED_PARAMETER(fl);
  209. DISPDBG((1, "DISP DrvSetPalette: Entry.\n"));
  210. ppdev = (PDEV*) dhpdev;
  211. // Fill in pScreenClut header info:
  212. pScreenClut = (PVIDEO_CLUT) ajClutSpace;
  213. pScreenClut->NumEntries = (USHORT) cColors;
  214. pScreenClut->FirstEntry = (USHORT) iStart;
  215. pScreenClutData = (PVIDEO_CLUTDATA) (&(pScreenClut->LookupTable[0]));
  216. if (cColors != PALOBJ_cGetColors(ppalo, iStart, cColors,
  217. (ULONG*) pScreenClutData))
  218. {
  219. DISPDBG((1, "DrvSetPalette failed PALOBJ_cGetColors\n"));
  220. return (FALSE);
  221. }
  222. // Set the high reserved byte in each palette entry to 0.
  223. // Do the appropriate palette shifting to fit in the DAC.
  224. if (ppdev->cPaletteShift)
  225. {
  226. while(cColors--)
  227. {
  228. pScreenClutData[cColors].Red >>= ppdev->cPaletteShift;
  229. pScreenClutData[cColors].Green >>= ppdev->cPaletteShift;
  230. pScreenClutData[cColors].Blue >>= ppdev->cPaletteShift;
  231. pScreenClutData[cColors].Unused = 0;
  232. }
  233. }
  234. else
  235. {
  236. while(cColors--)
  237. {
  238. pScreenClutData[cColors].Unused = 0;
  239. }
  240. }
  241. // Set palette registers
  242. if (!DEVICE_IO_CTRL(ppdev->hDriver,
  243. IOCTL_VIDEO_SET_COLOR_REGISTERS,
  244. pScreenClut,
  245. MAX_CLUT_SIZE,
  246. NULL,
  247. 0,
  248. &cColors,
  249. NULL))
  250. {
  251. DISPDBG((1, "DrvSetPalette failed DEVICE_IO_CTRL\n"));
  252. return (FALSE);
  253. }
  254. DISPDBG((1, "DISP DrvSetPalette: Exit.\n"));
  255. return(TRUE);
  256. }
  257.