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.

321 lines
6.1 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. xlbmpcvt.h
  5. Abstract:
  6. Bitmap conversion header
  7. Environment:
  8. Windows Whistler
  9. Revision History:
  10. 03/23/00
  11. Created it.
  12. --*/
  13. #ifndef _XLBMPCVT_H_
  14. #define _XLBMPCVT_H_
  15. //
  16. // Macros for getting color components
  17. //
  18. #define RED(x) ((BYTE) ((x) ))
  19. #define GREEN(x) ((BYTE) ((x) >> 8))
  20. #define BLUE(x) ((BYTE) ((x) >> 16))
  21. #define CYAN(x) ((BYTE) ((x) ))
  22. #define MAGENTA(x) ((BYTE) ((x) >> 8))
  23. #define YELLOW(x) ((BYTE) ((x) >> 16))
  24. #define BLACK(x) ((BYTE) ((x) >> 24))
  25. //
  26. // Macro to convert from RGB to grayscale
  27. //
  28. // The formula we're using is: grayscale = 0.3*R + 0.59*G + 0.11*B.
  29. // Scale it up with 256 to avoid a division operation.
  30. //
  31. //
  32. #define RGB2GRAY(r, g, b) ((BYTE) (((r)*77 + (g)*151 + (b)*28) >> 8))
  33. #define GET_COLOR_TABLE(pxlo) \
  34. (pxlo ?\
  35. (((pxlo)->flXlate & XO_TABLE) ?\
  36. ((pxlo)->pulXlate ? (pxlo)->pulXlate : XLATEOBJ_piVector(pxlo)) :\
  37. NULL) :\
  38. NULL)
  39. inline
  40. BYTE DWORD2GRAY(
  41. DWORD dwColor)
  42. /*++
  43. Routine Description:
  44. Converts RGB 24 bit color to 8 bit gray scale.
  45. Arguments:
  46. RGB 24 bit color
  47. Return Value:
  48. 8 bit gray scale.
  49. Note:
  50. --*/
  51. {
  52. return RGB2GRAY(RED(dwColor), GREEN(dwColor), BLUE(dwColor));
  53. }
  54. typedef enum {
  55. e1bpp = BMF_1BPP,
  56. e4bpp = BMF_4BPP,
  57. e8bpp = BMF_8BPP,
  58. e16bpp = BMF_16BPP,
  59. e24bpp = BMF_24BPP,
  60. e32bpp = BMF_32BPP
  61. } BPP;
  62. typedef enum {
  63. eOutputGray,
  64. eOutputPal,
  65. eOutputRGB,
  66. eOutputCMYK
  67. } OutputFormat;
  68. typedef enum {
  69. eOddPixelZero,
  70. eOddPixelOne
  71. } OddPixel;
  72. typedef enum {
  73. eBitZero,
  74. eBitOne,
  75. eBitTwo,
  76. eBitThree,
  77. eBitFour,
  78. eBitFive,
  79. eBitSize,
  80. eBitSeven
  81. } FirstBit;
  82. typedef BOOL (*PFNDIBCONV)(PBYTE, DWORD);
  83. class BMPConv
  84. #if DBG
  85. : public XLDebug
  86. #endif
  87. {
  88. SIGNATURE( 'cpmb' )
  89. public:
  90. BMPConv::
  91. BMPConv( VOID );
  92. BMPConv::
  93. ~BMPConv( VOID );
  94. BOOL
  95. BSetInputBPP(BPP InputBPP);
  96. BOOL
  97. BSetOutputBPP(BPP OutputBPP);
  98. BOOL
  99. BSetOutputBMPFormat(OutputFormat BitmapFormat);
  100. BOOL
  101. BSetXLATEOBJ(XLATEOBJ *pxlo);
  102. DWORD
  103. DwGetDstSize(VOID);
  104. BOOL
  105. BSetCompressionType(CompressMode CMode);
  106. CompressMode
  107. GetCompressionType(VOID);
  108. PBYTE
  109. PubConvertBMP(PBYTE pubSrc, DWORD dwcbSrcSize);
  110. #if DBG
  111. VOID
  112. SetDbgLevel(DWORD dwLevel);
  113. #endif
  114. private:
  115. //
  116. // Attrbutes
  117. //
  118. #define BMPCONV_SET_INPUTBPP 0x00000001
  119. #define BMPCONV_SET_OUTPUTBPP 0x00000002
  120. #define BMPCONV_SET_OUTPUTBMPFORMAT 0x00000004
  121. #define BMPCONV_SET_XLATEOBJ 0x00000008
  122. #define BMPCONV_2COLOR_24BPP 0x00000010
  123. #define BMPCONV_CHECKXLATEOBJ 0x00000f00
  124. #define BMPCONV_XLATE 0x00000100
  125. #define BMPCONV_BGR 0x00000200
  126. #define BMPCONV_32BPP_RGB 0x00000400
  127. #define BMPCONV_32BPP_BGR 0x00000800
  128. DWORD m_flags;
  129. BPP m_InputBPP; // Source bitmap bits per pixel
  130. BPP m_OutputBPP; // Destination bitmap bits per pixel
  131. DWORD m_dwWidth;
  132. OutputFormat m_OutputFormat; // Destination bitmap format
  133. OddPixel m_OddPixelStart; // 0 or 1, whether scanline starts on odd-pixel
  134. FirstBit m_FirstBit; // 0 to 7: starting bit of the scanline's first pixel
  135. XLATEOBJ *m_pxlo;
  136. CompressMode m_CMode;
  137. //
  138. // Destination buffer
  139. //
  140. DWORD m_dwOutputBuffSize;
  141. PBYTE m_pubOutputBuff;
  142. DWORD m_dwRLEOutputBuffSize;
  143. DWORD m_dwRLEOutputDataSize;
  144. PBYTE m_pubRLEOutputBuff;
  145. DWORD m_dwDRCOutputBuffSize;
  146. DWORD m_dwDRCPrevOutputBuffSize;
  147. DWORD m_dwDRCOutputDataSize;
  148. PBYTE m_pubDRCOutputBuff;
  149. PBYTE m_pubDRCPrevOutputBuff;
  150. //
  151. // Internal functions
  152. //
  153. BOOL
  154. BCopy( PBYTE pubSrc,
  155. DWORD dwSrcPixelNum);
  156. BOOL
  157. B4BPPtoCMYK(
  158. PBYTE pubSrc,
  159. DWORD dwSrcPixelNum);
  160. BOOL
  161. B4BPPtoRGB(
  162. PBYTE pubSrc,
  163. DWORD dwSrcPixelNum);
  164. BOOL
  165. B4BPPtoGray(
  166. PBYTE pubSrc,
  167. DWORD dwSrcPixelNum);
  168. BOOL
  169. B8BPPtoGray(
  170. IN PBYTE pubSrc,
  171. IN DWORD dwSrcPixelNum);
  172. BOOL
  173. B8BPPtoRGB(
  174. IN PBYTE pubSrc,
  175. IN DWORD dwSrcPixelNum);
  176. BOOL
  177. B8BPPtoCMYK(
  178. IN PBYTE pubSrc,
  179. IN DWORD dwSrcPixelNum);
  180. BOOL
  181. B16BPPtoGray(
  182. IN PBYTE pubSrc,
  183. IN DWORD dwSrcPixelNum);
  184. BOOL
  185. B16BPPtoRGB(
  186. IN PBYTE pubSrc,
  187. IN DWORD dwSrcPixelNum);
  188. BOOL
  189. B24BPPtoGray(
  190. IN PBYTE pubSrc,
  191. IN DWORD dwSrcPixelNum);
  192. BOOL
  193. B24BPPtoRGB(
  194. IN PBYTE pubSrc,
  195. IN DWORD dwSrcPixelNum);
  196. BOOL
  197. B32BPPtoGray(
  198. IN PBYTE pubSrc,
  199. IN DWORD dwSrcPixelNum);
  200. BOOL
  201. B32BPPtoRGB(
  202. IN PBYTE pubSrc,
  203. IN DWORD dwSrcPixelNum);
  204. BOOL
  205. B32BPPtoCMYK(
  206. IN PBYTE pubSrc,
  207. IN DWORD dwSrcPixelNum);
  208. BOOL
  209. BArbtoGray(
  210. PBYTE pubSrc,
  211. DWORD dwSrcPixelNum);
  212. BOOL
  213. BArbtoRGB(
  214. PBYTE pubSrc,
  215. DWORD dwSrcPixelNum);
  216. #ifdef WINNT_40
  217. BOOL
  218. B24BPPToImageMask(
  219. PBYTE pubSrc,
  220. DWORD dwSrcPixelNum);
  221. #endif // WINNT_40
  222. BOOL
  223. BConversionProc(
  224. PBYTE pubSrc,
  225. DWORD dwSrcPixelNum);
  226. BOOL
  227. BCompressRLE(VOID);
  228. BOOL
  229. BCompressDRC(VOID);
  230. DWORD
  231. DwCheckXlateObj(XLATEOBJ*, BPP);
  232. };
  233. BPP
  234. NumToBPP(
  235. ULONG ulBPP);
  236. ULONG
  237. UlBPPtoNum(
  238. BPP Bpp);
  239. #endif // _XLBMPCVT_H_