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.

115 lines
3.8 KiB

  1. #ifndef _PalMap_h
  2. #define _PalMap_h
  3. // File: PalMap.h
  4. // Author: Michael Marr (mikemarr)
  5. //
  6. // Description:
  7. // This class helps perform on-the-fly pixel conversions.
  8. //
  9. // History:
  10. // -@- 11/18/96 (mikemarr) created
  11. // -@- 12/05/96 (mikemarr) modified
  12. // added code for translating all palettes to 8, 16, 24, and 32 bit;
  13. // transparency/alpha stuff is not yet implemented
  14. // -@- 06/24/97 (mikemarr) modified
  15. // removed PixelInfo
  16. // -@- 09/23/97 (mikemarr) copied to DXCConv from d2d\mmimage
  17. //
  18. // Notes:
  19. // REVIEW:
  20. // I probably will never support a 4 bit mode, since 4 bit stuff might
  21. // as well be stored as 8 bit since the space savings is small. However,
  22. // 2 and 1 bit stuff should still be considered, since the space savings
  23. // could be substantial. Further, 1 and 2 bit surfaces represent a large
  24. // class of content - line art, text, FAX, etc. (2 bits buys BGW +
  25. // transparency for example). This type of content tends to be much larger
  26. // in dimension -- so we need an efficient representation.
  27. #ifndef _PixInfo_h
  28. #include "PixInfo.h"
  29. #endif
  30. typedef WORD MapEntry16;
  31. typedef DWORD MapEntry24;
  32. typedef DWORD MapEntry32;
  33. #define flagTRANSPARENT 0x1
  34. #define flagPALETTIZED 0x2
  35. #define nMAXPALETTEENTRIES 256
  36. typedef enum ConvertCode {
  37. cvc4To8 = 0, cvc4To16, cvc4To24, cvc4To32,
  38. cvc8To8, cvc8To16, cvc8To24, cvc8To32,
  39. cvcInvalid, cvcNumCodes
  40. } ConvertCode;
  41. typedef HRESULT (*ConvertFunction)(const BYTE *pSrcPixels, long nSrcPitch,
  42. BYTE *pDstPixels, long nDstPitch,
  43. DWORD nWidth, DWORD nHeight,
  44. const BYTE *pIndexMap);
  45. typedef DWORD (*GetColorFunction)(DWORD dwSrcColor, const BYTE *pIndexMap);
  46. extern ConvertFunction g_rgConvertFunctions[cvcNumCodes];
  47. class CPaletteMap {
  48. public:
  49. CPaletteMap();
  50. ~CPaletteMap();
  51. HRESULT CreateMap(BYTE nBPPSrcPixels, BYTE nBPPSrcPalette, LPPALETTEENTRY rgpeSrc,
  52. const CPixelInfo &pixiDst, LPDIRECTDRAWPALETTE pddpDst);
  53. HRESULT CreateMap(LPDIRECTDRAWPALETTE pddpSrc, const CPixelInfo &pixiDst,
  54. LPDIRECTDRAWPALETTE pddpDst);
  55. // HRESULT CreateSortedMap(BYTE nBPP, const RGB *rgrgbSrc, BYTE nBPPUsed, DWORD iTransColor,
  56. // DWORD dwFlags, LPPALETTEENTRY rgpeDst);
  57. HRESULT BltFast(LPDIRECTDRAWSURFACE pddsSrc, LPRECT prSrc, LPDIRECTDRAWSURFACE pddsDst,
  58. DWORD nXPos, DWORD nYPos, DWORD dwFlags) const;
  59. // REVIEW: this is not "clip-safe"
  60. HRESULT BltFast(const BYTE *pSrcPixels, long nSrcPitch, BYTE *pDstPixels, long nDstPitch,
  61. DWORD nWidth, DWORD nHeight);
  62. DWORD GetIndexMapping(DWORD iSrcColor) const;
  63. DWORD GetSrcBPP() const { return m_cSrcBPP; }
  64. DWORD GetDstBPP() const { return m_cDstBPP; }
  65. BOOL IsIdentity() const { return m_bIdentity; }
  66. private:
  67. HRESULT DoPalTo16BitMap(BYTE nSrcBPP, const CPixelInfo &pixiDst,
  68. const PALETTEENTRY *ppeSrc);
  69. HRESULT DoPalTo24BitMap(BYTE nSrcBPP, const CPixelInfo &pixiDst,
  70. const PALETTEENTRY *ppeSrc);
  71. HRESULT DoPalTo32BitMap(BYTE nSrcBPP, const CPixelInfo &pixiDst,
  72. const PALETTEENTRY *ppeSrc);
  73. HRESULT DoPalToPalMap(BYTE nSrcBPP, BYTE nDstBPP, const PALETTEENTRY *ppeSrc,
  74. const PALETTEENTRY *ppeDst);
  75. static int GetConvertCode(DWORD nSrcBPP, DWORD nDstBPP);
  76. private:
  77. BYTE * m_rgIndexMap;
  78. BYTE m_nConvertCode;
  79. // REVIEW: we don't need to store the src and dst info ==> implicit in ConvertCode
  80. BYTE m_cSrcBPP, m_cDstBPP;
  81. BYTE m_bIdentity;
  82. };
  83. inline HRESULT
  84. CPaletteMap::BltFast(const BYTE *pSrcPixels, long nSrcPitch, BYTE *pDstPixels, long nDstPitch,
  85. DWORD nWidth, DWORD nHeight)
  86. {
  87. ConvertFunction pfnConvertFunction = g_rgConvertFunctions[m_nConvertCode];
  88. if (pfnConvertFunction)
  89. return pfnConvertFunction(pSrcPixels, nSrcPitch, pDstPixels, nDstPitch,
  90. nWidth, nHeight, m_rgIndexMap);
  91. return E_NOTIMPL;
  92. }
  93. #endif