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.

118 lines
3.3 KiB

  1. /***************************************************************************
  2. * palette.c
  3. *
  4. * Common halftone palette used by shell.
  5. *
  6. ***************************************************************************/
  7. #include "priv.h"
  8. #include "palette.h"
  9. BYTE * g_pbWinNTCMAP = NULL;
  10. // This function behaves the same as CreateHalftone palette:
  11. // hdc == NULL always return full palette
  12. // hdc palettized return full palette
  13. // hdc not palettized return default palette (VGA colors)
  14. HPALETTE SHCreateShellPalette(HDC hdc)
  15. {
  16. // We would like to use CreateHalftonePalette() always but they
  17. // differ significantly between NT and Win95. Win95's is very
  18. // close to Netscape's; NT's is significantly different (color
  19. // cube cut differently) and it is not an identity palette.
  20. //
  21. // So, we will use CreateHalftonePalette() on Win95 and on NT
  22. // we will use a custom palette containing the same colors in
  23. // Win95's halftone palette ordered so that the color flash
  24. // will be minimized when switching between NT's halftone palette
  25. // and our palette.
  26. //
  27. // On NT 5 and later the halftone palette matches Win95's so the
  28. // custom palette will only be used on machines running NT 4 or below.
  29. // However, we still need to patch in the system colors on NT 5.
  30. HPALETTE hpalHalftone = CreateHalftonePalette(hdc);
  31. if (hpalHalftone)
  32. {
  33. HDC hdcScreen = hdc;
  34. LOGPAL256 lp;
  35. lp.wCnt = (WORD)GetPaletteEntries(hpalHalftone, 0, 256, lp.ape);
  36. lp.wVer = 0x0300;
  37. DeleteObject(hpalHalftone);
  38. if (hdcScreen == NULL)
  39. hdcScreen = CreateCompatibleDC(NULL);
  40. if (hdcScreen)
  41. {
  42. GetSystemPaletteEntries(hdcScreen, 0, 10, lp.ape);
  43. GetSystemPaletteEntries(hdcScreen, 246, 10, lp.ape + 246);
  44. }
  45. hpalHalftone = CreatePalette((LOGPALETTE *)&lp);
  46. if (hdc == NULL && hdcScreen)
  47. DeleteDC(hdcScreen);
  48. }
  49. return hpalHalftone;
  50. }
  51. // SOMEDAY: (raymondc) Pre-invert the map in the header file so we don't
  52. // have to compute it on the fly.
  53. static const BYTE *GetInverseCMAP()
  54. {
  55. if (g_pbWinNTCMAP == NULL)
  56. {
  57. BYTE * pbMap = LocalAlloc(LPTR, 32768);
  58. if (pbMap)
  59. {
  60. int i;
  61. BYTE * pbDst = pbMap;
  62. const BYTE * pbSrc = g_abWin95CMAP;
  63. for (i = 0; i < 32768; ++i)
  64. {
  65. *pbDst++ = g_abWin95ToNT5[*pbSrc++];
  66. }
  67. if (SHInterlockedCompareExchange((void **)&g_pbWinNTCMAP, pbMap, NULL))
  68. {
  69. LocalFree(pbMap); // race, get rid of dupe copy
  70. }
  71. }
  72. }
  73. return g_pbWinNTCMAP;
  74. }
  75. HRESULT SHGetInverseCMAP(BYTE *pbMap, ULONG cbMap)
  76. {
  77. const BYTE *pbSrc;
  78. if (pbMap == NULL)
  79. return E_POINTER;
  80. if (cbMap != 32768 && cbMap != sizeof(BYTE *))
  81. return E_INVALIDARG;
  82. pbSrc = GetInverseCMAP();
  83. if (pbSrc == NULL)
  84. return E_OUTOFMEMORY;
  85. if (cbMap == sizeof(BYTE *))
  86. {
  87. *(const BYTE **)pbMap = pbSrc;
  88. }
  89. else
  90. {
  91. memcpy(pbMap, pbSrc, 32768);
  92. }
  93. return(S_OK);
  94. }
  95. void TermPalette()
  96. {
  97. if (g_pbWinNTCMAP)
  98. LocalFree(g_pbWinNTCMAP);
  99. }