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.

218 lines
6.6 KiB

  1. #ifndef _DDHelper_h
  2. #define _DDHelper_h
  3. // File: DDHelper.h
  4. // Author: Michael Marr (mikemarr)
  5. //
  6. // Description:
  7. // These are some useful helper functions for sanitizing interactions
  8. // with DirectDraw
  9. //
  10. // History:
  11. // -@- 03/06/97 (mikemarr) created
  12. // -@- 10/07/97 (mikemarr) snarfed from \d2d\mmimage\include
  13. // -@- 10/07/97 (mikemarr) trimmed
  14. // -@- 10/14/97 (mikemarr) added arrays for pixel format mgmt
  15. // -@- 10/28/97 (mikemarr) added PixelOffset macro
  16. // -@- 10/28/97 (mikemarr) added GetColor function
  17. #ifndef __DDRAW_INCLUDED__
  18. #include <ddraw.h>
  19. #endif
  20. #ifndef _PixInfo_h
  21. #include "PixInfo.h"
  22. #endif
  23. #ifndef _Point_h
  24. #include "Point.h"
  25. #endif
  26. typedef enum {
  27. iPF_NULL = 0, iPF_Palette1, iPF_Palette2, iPF_Palette4, iPF_Palette8,
  28. iPF_RGB332, iPF_ARGB4444, iPF_RGB565, iPF_BGR565, iPF_RGB555,
  29. iPF_ARGB5551, iPF_RGB24, iPF_BGR24, iPF_RGB32, iPF_BGR32,
  30. iPF_ARGB, iPF_ABGR, iPF_RGBTRIPLE, iPF_RGBQUAD, iPF_PALETTEENTRY,
  31. iPF_Total
  32. } PixelFormatIndex;
  33. extern const DDPIXELFORMAT g_rgDDPF[iPF_Total];
  34. DWORD GetPixelFormat(const DDPIXELFORMAT &ddpf);
  35. extern const CPixelInfo g_rgPIXI[iPF_Total];
  36. DWORD GetPixelFormat(const CPixelInfo &pixi);
  37. /*
  38. extern const GUID g_rgDDPFGUID[iPF_Total];
  39. DWORD GetPixelFormat(const GUID &guid);
  40. */
  41. extern const PALETTEENTRY g_peZero;
  42. inline BOOL
  43. operator==(const DDPIXELFORMAT &ddpf1, const DDPIXELFORMAT &ddpf2)
  44. {
  45. return (ddpf1.dwRGBBitCount == ddpf2.dwRGBBitCount) &&
  46. (ddpf1.dwRBitMask == ddpf2.dwRBitMask) &&
  47. (ddpf1.dwGBitMask == ddpf2.dwGBitMask) &&
  48. (ddpf1.dwBBitMask == ddpf2.dwBBitMask) &&
  49. (ddpf1.dwRGBAlphaBitMask == ddpf2.dwRGBAlphaBitMask) &&
  50. (ddpf1.dwFlags == ddpf2.dwFlags);
  51. }
  52. #define AllFieldsDefined(dxstruct, flags) (((dxstruct).dwFlags & (flags)) == (flags))
  53. #define AnyFieldsDefined(dxstruct, flags) (((dxstruct).dwFlags & (flags)) != 0)
  54. extern DWORD g_rgdwBPPToPalFlags[9];
  55. extern DWORD g_rgdwBPPToPixFlags[9];
  56. inline DWORD
  57. BPPToPaletteFlags(DWORD nBPP)
  58. {
  59. return (nBPP <= 8 ? g_rgdwBPPToPalFlags[nBPP] : 0);
  60. }
  61. inline DWORD
  62. BPPToPixelFlags(DWORD nBPP)
  63. {
  64. return (nBPP <= 8 ? g_rgdwBPPToPixFlags[nBPP] : 0);
  65. }
  66. DWORD PaletteToPixelFlags(DWORD dwPaletteFlags);
  67. DWORD PixelToPaletteFlags(DWORD dwPaletteFlags);
  68. BYTE PixelFlagsToBPP(DWORD dwFlags);
  69. BYTE PaletteFlagsToBPP(DWORD dwFlags);
  70. HRESULT CreatePlainSurface(IDirectDraw *pDD, DWORD nWidth, DWORD nHeight,
  71. const DDPIXELFORMAT &ddpf, IDirectDrawPalette *pddp,
  72. DWORD dwTransColor, bool bTransparent,
  73. IDirectDrawSurface **ppdds);
  74. inline
  75. HRESULT CreatePlainSurface(IDirectDraw *pDD, DWORD nWidth, DWORD nHeight,
  76. const CPixelInfo &pixiPixFmt, IDirectDrawPalette *pddp,
  77. DWORD dwTransColor, bool bTransparent,
  78. IDirectDrawSurface **ppdds)
  79. {
  80. DDPIXELFORMAT ddpf;
  81. pixiPixFmt.GetDDPF(ddpf);
  82. return CreatePlainSurface(pDD, nWidth, nHeight, ddpf,
  83. pddp, dwTransColor, bTransparent, ppdds);
  84. }
  85. HRESULT CreatePalette(IDirectDraw *pDD, const BYTE *pPalette, DWORD cEntries,
  86. BYTE nBPPTarget, const CPixelInfo &pixiPalFmt,
  87. IDirectDrawPalette **ppddp);
  88. // Notes: luminance ~= (77r + 151g + 28b)/256
  89. #define nREDWEIGHT 77
  90. #define nGREENWEIGHT 151
  91. #define nBLUEWEIGHT 28
  92. #define nMAXPALETTEENTRIES 256
  93. HRESULT ClearToColor(LPRECT prDst, LPDIRECTDRAWSURFACE pdds, DWORD dwColor);
  94. DWORD SimpleFindClosestIndex(const PALETTEENTRY *rgpePalette, DWORD cEntries,
  95. const PALETTEENTRY &peQuery);
  96. HRESULT GetColors(LPDIRECTDRAWSURFACE pdds, const PALETTEENTRY *rgpeQuery, DWORD cEntries,
  97. LPDWORD pdwColors);
  98. HRESULT CreateSurfaceWithText(LPDIRECTDRAW pDD, LPDIRECTDRAWPALETTE pddp,
  99. DWORD iTransp, const char *szText, HFONT hFont, BOOL bShadowed,
  100. SIZE *psiz, LPDIRECTDRAWSURFACE *ppdds);
  101. HRESULT CreatePlainDIBSection(HDC hDC, DWORD nWidth, DWORD nHeight, DWORD nBPP,
  102. const PALETTEENTRY *rgpePalette, HBITMAP *phbm, LPBYTE *ppPixels);
  103. HRESULT GetSurfaceDimensions(LPDIRECTDRAWSURFACE pdds, LPRECT prDimensions);
  104. HRESULT CreatePaletteFromSystem(HDC hDC, IDirectDraw *pDD,
  105. IDirectDrawPalette **ppddp);
  106. // Robust Drawing Routines
  107. HRESULT DrawPoints(LPBYTE pPixels, DWORD nWidth, DWORD nHeight, DWORD nPitch, DWORD nBytesPerPixel,
  108. const Point2 *rgpnt, DWORD cPoints,
  109. DWORD dwColor, DWORD nRadius);
  110. HRESULT DrawBox(LPBYTE pPixels, DWORD nWidth, DWORD nHeight, DWORD nPitch,
  111. DWORD nBytesPerPixel, const RECT &r, DWORD dwColor, DWORD nThickness);
  112. HRESULT DrawFilledBox(LPBYTE pPixels, DWORD nWidth, DWORD nHeight, DWORD nPitch,
  113. DWORD nBytesPerPixel, const RECT &r, DWORD dwColor);
  114. inline HRESULT
  115. DrawPoints(DDSURFACEDESC &ddsd, const Point2 *rgpnt, DWORD cPoints,
  116. DWORD dwColor, DWORD nRadius)
  117. {
  118. return DrawPoints((LPBYTE) ddsd.lpSurface, ddsd.dwWidth, ddsd.dwHeight,
  119. (DWORD) ddsd.lPitch, (ddsd.ddpfPixelFormat.dwRGBBitCount + 7) >> 3,
  120. rgpnt, cPoints, dwColor, nRadius);
  121. }
  122. inline HRESULT
  123. DrawBox(DDSURFACEDESC &ddsd, const RECT &r, DWORD dwColor, DWORD nThickness)
  124. {
  125. return DrawBox((LPBYTE) ddsd.lpSurface, ddsd.dwWidth, ddsd.dwHeight,
  126. (DWORD) ddsd.lPitch, (ddsd.ddpfPixelFormat.dwRGBBitCount + 7) >> 3,
  127. r, dwColor, nThickness);
  128. }
  129. inline HRESULT
  130. DrawFilledBox(DDSURFACEDESC &ddsd, const RECT &r, DWORD dwColor)
  131. {
  132. return DrawFilledBox((LPBYTE) ddsd.lpSurface, ddsd.dwWidth, ddsd.dwHeight,
  133. (DWORD) ddsd.lPitch, (ddsd.ddpfPixelFormat.dwRGBBitCount + 7) >> 3,
  134. r, dwColor);
  135. }
  136. #define PixelOffset(_nX, _nY, _nPitch, _cBytesPerPixel) ((_nPitch * _nY) + (_cBytesPerPixel * _nX))
  137. //
  138. // RECT functions
  139. //
  140. // Function: ClipRect
  141. // Returns TRUE for a non-trivial intersection.
  142. bool ClipRect(const RECT &rTarget, RECT &rSrc);
  143. bool ClipRect(long nWidth, long nHeight, LPRECT prSrc);
  144. // Function: IsInside
  145. // Returns true if the given point is inside the rectangle
  146. inline bool
  147. IsInside(long nX, long nY, const RECT &r)
  148. {
  149. return ((nX >= r.left) && (nX < r.right) && (nY >= r.top) && (nY < r.bottom));
  150. }
  151. inline bool
  152. IsInside(long nX, long nY, const SIZE &siz)
  153. {
  154. return ((nX >= 0) && (nX < siz.cx) && (nY >= 0) && (nY < siz.cy));
  155. }
  156. inline bool
  157. IsFullSize(DWORD nWidth, DWORD nHeight, const RECT &r)
  158. {
  159. return ((r.right == (long) nWidth) && (r.bottom == (long) nHeight) &&
  160. (r.left == 0) && (r.top == 0));
  161. }
  162. inline bool
  163. IsSameSize(DWORD nWidth, DWORD nHeight, const RECT &r)
  164. {
  165. return ((r.right - r.left) == (long) nWidth) &&
  166. ((r.bottom - r.top) == (long) nHeight);
  167. }
  168. inline bool
  169. IsSameSize(const RECT &r1, const RECT &r2)
  170. {
  171. return ((r1.right - r1.left) == (r2.right - r2.left)) &&
  172. ((r1.bottom - r1.top) == (r2.bottom - r2.top));
  173. }
  174. #endif