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.

192 lines
6.4 KiB

  1. /*-----------------------------------------------------------------------------*\
  2. | Routines for dealing with Device independent bitmaps |
  3. | |
  4. | History: |
  5. | 06/23/89 toddla Created |
  6. | 04/25/94 michaele Using in sprite library, removed all dib.c funcs |
  7. | only using the MACRO stuff. |
  8. | |
  9. \*-----------------------------------------------------------------------------*/
  10. #ifndef _INC_DIB_
  11. #define _INC_DIB_
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. typedef LPBITMAPINFOHEADER PDIB;
  16. typedef HANDLE HDIB;
  17. #ifdef WIN32
  18. #define HFILE HANDLE
  19. #endif
  20. PDIB DibOpenFile(LPTSTR szFile);
  21. BOOL DibWriteFile(PDIB pdib, LPTSTR szFile);
  22. PDIB DibReadBitmapInfo(HFILE fh);
  23. HPALETTE DibCreatePalette(PDIB pdib);
  24. BOOL DibSetUsage(PDIB pdib, HPALETTE hpal,UINT wUsage);
  25. BOOL DibDraw(HDC hdc, int x, int y, int dx, int dy, PDIB pdib,
  26. int x0, int y0, int dx0, int dy0, LONG rop, UINT wUsage);
  27. PDIB DibCreate(int bits, int dx, int dy);
  28. PDIB DibCopy(PDIB pdib);
  29. void DibMapToPalette(PDIB pdib, HPALETTE hpal);
  30. PDIB DibConvert(PDIB pdib, int BitCount, DWORD biCompression);
  31. PDIB DibHalftoneDIB(PDIB pdib);
  32. PDIB DibFromBitmap(HBITMAP hbm, DWORD biStyle, UINT biBits,
  33. HPALETTE hpal, UINT wUsage);
  34. HBITMAP BitmapFromDib(PDIB pdib, HPALETTE hpal, UINT wUsage);
  35. void MakeIdentityPalette(HPALETTE hpal);
  36. HPALETTE CopyPalette(HPALETTE hpal);
  37. /****************************************************************************
  38. DIB macros.
  39. ***************************************************************************/
  40. #ifdef WIN32
  41. #define HandleFromDib(lpbi) GlobalHandle(lpbi)
  42. #else
  43. #define HandleFromDib(lpbi) (HANDLE)GlobalHandle(SELECTOROF(lpbi))
  44. #endif
  45. #define DibFromHandle(h) (PDIB)GlobalLock(h)
  46. #define DibFree(pdib) GlobalFreePtr(pdib)
  47. #define WIDTHBYTES(i) ((unsigned)((i+31)&(~31))/8) /* ULONG aligned ! */
  48. #define DibWidth(lpbi) (UINT)(((LPBITMAPINFOHEADER)(lpbi))->biWidth)
  49. #define DibHeight(lpbi) (((LPBITMAPINFOHEADER)(lpbi))->biHeight)
  50. #define DibBitCount(lpbi) (UINT)(((LPBITMAPINFOHEADER)(lpbi))->biBitCount)
  51. #define DibCompression(lpbi) (DWORD)(((LPBITMAPINFOHEADER)(lpbi))->biCompression)
  52. #define DibWidthBytesN(lpbi, n) (UINT)WIDTHBYTES((UINT)(lpbi)->biWidth * (UINT)(n))
  53. #define DibWidthBytes(lpbi) DibWidthBytesN(((LPBITMAPINFOHEADER)lpbi), \
  54. ((LPBITMAPINFOHEADER)lpbi)->biBitCount)
  55. #define DibSizeImage(lpbi) ((lpbi)->biSizeImage == 0 \
  56. ? ((DWORD)(UINT)DibWidthBytes(lpbi) * \
  57. (DWORD)(UINT)(lpbi)->biHeight) \
  58. : (lpbi)->biSizeImage)
  59. #define DibSize(lpbi) ((lpbi)->biSize + (lpbi)->biSizeImage + \
  60. (int)(lpbi)->biClrUsed * sizeof(RGBQUAD))
  61. #define DibPaletteSize(lpbi) (DibNumColors(lpbi) * sizeof(RGBQUAD))
  62. #define DibFlipY(lpbi, y) ((int)(lpbi)->biHeight-1-(y))
  63. //HACK for NT BI_BITFIELDS DIBs
  64. #ifdef WIN32
  65. #define DibPtr(lpbi) ((lpbi)->biCompression == BI_BITFIELDS \
  66. ? (LPVOID)(DibColors(lpbi) + 3) \
  67. : (LPVOID)(DibColors(lpbi) + \
  68. (UINT)(lpbi)->biClrUsed))
  69. #else
  70. #define DibPtr(lpbi) (LPVOID)(DibColors(lpbi) + \
  71. (UINT)(lpbi)->biClrUsed)
  72. #endif
  73. #define DibColors(lpbi) ((RGBQUAD FAR *)((LPBYTE)(lpbi) + \
  74. (int)(lpbi)->biSize))
  75. #define DibNumColors(lpbi) ((lpbi)->biClrUsed == 0 && \
  76. (lpbi)->biBitCount <= 8 \
  77. ? (int)(1 << (int)(lpbi)->biBitCount) \
  78. : (int)(lpbi)->biClrUsed)
  79. #define DibXYN(lpbi,pb,x,y,n) (LPVOID)( \
  80. (BYTE *)(pb) + \
  81. (UINT)((UINT)(x) * (UINT)(n) / 8u) + \
  82. ((DWORD)DibWidthBytesN(lpbi,n) * \
  83. (DWORD)(UINT)(y)))
  84. #define DibXY(lpbi,x,y) DibXYN(lpbi,DibPtr(lpbi),x,y,(lpbi)->biBitCount)
  85. #define FixBitmapInfo(lpbi) if ((lpbi)->biSizeImage == 0) \
  86. (lpbi)->biSizeImage = DibSizeImage(lpbi); \
  87. if ((lpbi)->biClrUsed == 0) \
  88. (lpbi)->biClrUsed = DibNumColors(lpbi); \
  89. if ((lpbi)->biCompression == BI_BITFIELDS && \
  90. (lpbi)->biClrUsed == 0) \
  91. ; // (lpbi)->biClrUsed = 3;
  92. #define DibInfo(pDIB) ((BITMAPINFO FAR *)(pDIB))
  93. /****************************************************************************
  94. ***************************************************************************/
  95. #ifndef BI_BITFIELDS
  96. #define BI_BITFIELDS 3
  97. #endif
  98. #ifndef HALFTONE
  99. #define HALFTONE COLORONCOLOR
  100. #endif
  101. #ifdef __cplusplus
  102. }
  103. #endif
  104. #endif // _INC_DIB_
  105. /*************************************************************************
  106. dibfx.h
  107. Header file for various DIB-to-DIB effects
  108. 02/08/94 Compiled by Jonbl
  109. */
  110. #ifndef _INC_DIBFX_
  111. #define _INC_DIBFX_
  112. #ifdef WIN95
  113. #ifndef _INC_WINDOWS
  114. #include <windows.h>
  115. #include <windowsx.h>
  116. #endif
  117. #endif //WIN95
  118. #ifdef __cplusplus
  119. extern "C" {
  120. #endif
  121. /*************************************************************************
  122. Many of the DIBFX functions use fixed point calculations internally.
  123. These functions are defined in fixed32.asm
  124. */
  125. typedef long Fixed;
  126. Fixed __stdcall FixedMultiply( Fixed Multiplicand, Fixed Multiplier );
  127. Fixed __stdcall FixedDivide( Fixed Dividend, Fixed Divisor );
  128. #define IntToFixed(i) (Fixed)( ((long)(i)) << 16 )
  129. #define FixedToShort(f) (short)( ((long)f) >> 16 )
  130. /*
  131. * DibClear
  132. * Fills a DIB's memory with a given value, effectively clearing
  133. * an 8-bit, 4-bit or 1-bit DIB.
  134. *
  135. * Does not do what you would expect on 16, 24, or 32-bit DIBs,
  136. * but it will work.
  137. *
  138. * Source is in clear.c and clear32.asm
  139. */
  140. BOOL FAR PASCAL DibClear(LPBITMAPINFO lpbiDst, LPVOID lpDst, BYTE value);
  141. #ifdef __cplusplus
  142. }
  143. #endif
  144. #endif // _INC_DIBFX_