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.

476 lines
13 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: alphablt.hxx
  3. *
  4. * This contains the prototypes for the alpha blending and gradient fill
  5. *
  6. * Created: 22-Feb-1997
  7. * Author: Mark Enstrom
  8. *
  9. * Copyright (c) 1997-1999 Microsoft Corporation
  10. *
  11. \**************************************************************************/
  12. //
  13. // alpha blending DEBUG messages
  14. //
  15. #if DBG
  16. extern ULONG DbgAlpha;
  17. #define ALPHAMSG(level,s) \
  18. if (DbgAlpha >= level) \
  19. { \
  20. DbgPrint("%s\n",s); \
  21. }
  22. #else
  23. #define ALPHAMSG(level,s)
  24. #endif
  25. //
  26. // 5,6,5 and 5,5,5 bytes to rgb565 and rgb555
  27. //
  28. #define rgb555(r,g,b) (((WORD)(r) << 10) | ((WORD)(g) << 5) | (WORD)(b))
  29. #define rgb565(r,g,b) (((WORD)(r) << 11) | ((WORD)(g) << 5) | (WORD)(b))
  30. #define rgb565_to_r(p) (BYTE)((p & 0xf800) >> 11)
  31. #define rgb565_to_g(p) (BYTE)((p & 0x07e0) >> 5)
  32. #define rgb565_to_b(p) (BYTE)((p & 0x001f))
  33. #define rgb555_to_r(p) (BYTE)((p & 0x7c00) >> 10)
  34. #define rgb555_to_g(p) (BYTE)((p & 0x03e0) >> 5)
  35. #define rgb555_to_b(p) (BYTE)((p & 0x001f))
  36. //
  37. // alpha blending color input/output and conversion
  38. //
  39. VOID vLoadAndConvert1ToBGRA (PULONG,PBYTE,LONG,LONG,XLATEOBJ*);
  40. VOID vLoadAndConvert4ToBGRA (PULONG,PBYTE,LONG,LONG,XLATEOBJ*);
  41. VOID vLoadAndConvert8ToBGRA (PULONG,PBYTE,LONG,LONG,XLATEOBJ*);
  42. VOID vLoadAndConvert16BitfieldsToBGRA(PULONG,PBYTE,LONG,LONG,XLATEOBJ*);
  43. VOID vLoadAndConvertRGB16_555ToBGRA (PULONG,PBYTE,LONG,LONG,XLATEOBJ*);
  44. VOID vLoadAndConvertRGB16_565ToBGRA (PULONG,PBYTE,LONG,LONG,XLATEOBJ*);
  45. VOID vLoadAndConvertRGB24ToBGRA (PULONG,PBYTE,LONG,LONG,XLATEOBJ*);
  46. VOID vLoadAndConvertBGR24ToBGRA (PULONG,PBYTE,LONG,LONG,XLATEOBJ*);
  47. VOID vLoadAndConvert32BitfieldsToBGRA(PULONG,PBYTE,LONG,LONG,XLATEOBJ*);
  48. VOID vLoadAndConvertRGB32ToBGRA (PULONG,PBYTE,LONG,LONG,XLATEOBJ*);
  49. typedef VOID (*PFN_PIXLOAD_AND_CONVERT)(PULONG,PBYTE,LONG,LONG,XLATEOBJ*);
  50. VOID vConvertAndSaveBGRATo1 (PBYTE,PULONG,LONG,LONG,XLATEOBJ *,XEPALOBJ,XEPALOBJ);
  51. VOID vConvertAndSaveBGRATo4 (PBYTE,PULONG,LONG,LONG,XLATEOBJ *,XEPALOBJ,XEPALOBJ);
  52. VOID vConvertAndSaveBGRATo8 (PBYTE,PULONG,LONG,LONG,XLATEOBJ *,XEPALOBJ,XEPALOBJ);
  53. VOID vConvertAndSaveBGRAToRGB16_565 (PBYTE,PULONG,LONG,LONG,XLATEOBJ *,XEPALOBJ,XEPALOBJ);
  54. VOID vConvertAndSaveBGRAToRGB16_555 (PBYTE,PULONG,LONG,LONG,XLATEOBJ *,XEPALOBJ,XEPALOBJ);
  55. VOID vConvertAndSaveBGRAToRGB16Bitfields(PBYTE,PULONG,LONG,LONG,XLATEOBJ *,XEPALOBJ,XEPALOBJ);
  56. VOID vConvertAndSaveBGRAToRGB24 (PBYTE,PULONG,LONG,LONG,XLATEOBJ *,XEPALOBJ,XEPALOBJ);
  57. VOID vConvertAndSaveBGRAToBGR24 (PBYTE,PULONG,LONG,LONG,XLATEOBJ *,XEPALOBJ,XEPALOBJ);
  58. VOID vConvertAndSaveBGRATo32Bitfields (PBYTE,PULONG,LONG,LONG,XLATEOBJ *,XEPALOBJ,XEPALOBJ);
  59. VOID vConvertAndSaveBGRAToRGB32 (PBYTE,PULONG,LONG,LONG,XLATEOBJ *,XEPALOBJ,XEPALOBJ);
  60. typedef VOID(*PFN_PIXCONVERT_AND_STORE)(PBYTE,PULONG,LONG,LONG,XLATEOBJ *,XEPALOBJ,XEPALOBJ);
  61. extern "C"
  62. {
  63. VOID vAlphaPerPixelAndConst(PALPHAPIX,PALPHAPIX,LONG,BLENDFUNCTION);
  64. VOID vAlphaPerPixelOnly(PALPHAPIX,PALPHAPIX,LONG,BLENDFUNCTION);
  65. VOID vAlphaConstOnly(PALPHAPIX,PALPHAPIX,LONG,BLENDFUNCTION);
  66. VOID vAlphaConstOnly16_555(PALPHAPIX,PALPHAPIX,LONG,BLENDFUNCTION);
  67. VOID vAlphaConstOnly16_565(PALPHAPIX,PALPHAPIX,LONG,BLENDFUNCTION);
  68. VOID vAlphaConstOnly24(PALPHAPIX,PALPHAPIX,LONG,BLENDFUNCTION);
  69. }
  70. #if defined (_X86_)
  71. VOID mmxAlphaPerPixelOnly(PALPHAPIX,PALPHAPIX,LONG,BLENDFUNCTION);
  72. VOID mmxAlphaPerPixelAndConst(PALPHAPIX,PALPHAPIX,LONG,BLENDFUNCTION);
  73. VOID mmxAlphaConstOnly24(PALPHAPIX,PALPHAPIX,LONG,BLENDFUNCTION);
  74. VOID mmxAlphaConstOnly16_555(PALPHAPIX,PALPHAPIX,LONG,BLENDFUNCTION);
  75. VOID mmxAlphaConstOnly16_565(PALPHAPIX,PALPHAPIX,LONG,BLENDFUNCTION);
  76. #endif
  77. typedef VOID (* PFN_GENERALBLEND)(PALPHAPIX,PALPHAPIX,LONG,BLENDFUNCTION);
  78. //
  79. // alpha blending call data
  80. //
  81. typedef struct _ALPHA_DISPATCH_FORMAT
  82. {
  83. ULONG ulDstBitsPerPixel;
  84. ULONG ulSrcBitsPerPixel;
  85. PFN_PIXLOAD_AND_CONVERT pfnLoadSrcAndConvert;
  86. PFN_PIXLOAD_AND_CONVERT pfnLoadDstAndConvert;
  87. PFN_PIXCONVERT_AND_STORE pfnConvertAndStore;
  88. PFN_GENERALBLEND pfnGeneralBlend;
  89. BLENDFUNCTION BlendFunction;
  90. BOOL bUseMMX;
  91. }ALPHA_DISPATCH_FORMAT,*PALPHA_DISPATCH_FORMAT;
  92. //
  93. // prototypes
  94. //
  95. PSURFACE
  96. psSetupDstSurface(
  97. PSURFACE pSurfDst,
  98. PRECTL prclDst,
  99. SURFMEM &surfTmpDst,
  100. BOOL bForceDstAlloc,
  101. BOOL bCopyFromDst
  102. );
  103. #define SOURCE_ALPHA 0
  104. #define SOURCE_TRAN 1
  105. PSURFACE
  106. psSetupTransparentSrcSurface(
  107. PSURFACE pSurfSrc,
  108. PSURFACE pSurfDst,
  109. PRECTL prclDst,
  110. XLATEOBJ *pxloSrcTo32,
  111. PRECTL prclSrc,
  112. SURFMEM &surfTmpSrc,
  113. ULONG ulSourceType,
  114. ULONG ulTranColor
  115. );
  116. PSURFACE
  117. psurfCreateDIBSurface(
  118. HDC hdcDest,
  119. LPBYTE pInitBits,
  120. LPBITMAPINFO pInfoHeader,
  121. DWORD iUsage,
  122. UINT cjMaxInfo,
  123. UINT cjMaxBits
  124. );
  125. //
  126. // blend routines
  127. //
  128. BOOL
  129. AlphaScanLineBlend(
  130. PBYTE,
  131. PRECTL,
  132. LONG,
  133. PBYTE,
  134. LONG,
  135. PPOINTL,
  136. XLATEOBJ*,
  137. XLATEOBJ*,
  138. XLATEOBJ*,
  139. XEPALOBJ,
  140. XEPALOBJ,
  141. PALPHA_DISPATCH_FORMAT
  142. );
  143. //
  144. // GradientFill
  145. //
  146. extern LONG DitherMatrix[];
  147. extern BOOL gbMMXProcessor;
  148. BOOL bIsMMXProcessor(VOID);
  149. PSURFACE
  150. psSetupDstSurface(
  151. PSURFACE pSurfDst,
  152. PRECTL prclDst,
  153. SURFMEM &surfTmpDst,
  154. BOOL bForceDstAlloc,
  155. BOOL *bAllocDstSurf
  156. );
  157. #define SOURCE_ALPHA 0
  158. #define SOURCE_TRAN 1
  159. PSURFACE
  160. psSetupTransparentSrcSurface(
  161. PSURFACE pSurfSrc,
  162. PSURFACE pSurfDst,
  163. PRECTL prclDst,
  164. XLATEOBJ *pxloSrcTo32,
  165. PRECTL prclSrc,
  166. SURFMEM &surfTmpSrc,
  167. BOOL *bAllocSrcSurf,
  168. ULONG ulSourceType,
  169. ULONG ulTranColor
  170. );
  171. /**************************************************************************\
  172. * GRADIENTRECTDATA
  173. *
  174. *
  175. * color gradient information for gradient fill rectangles
  176. *
  177. *
  178. * History:
  179. *
  180. * 2/11/1997 Mark Enstrom [marke]
  181. *
  182. \**************************************************************************/
  183. typedef struct _GRADIENTRECTDATA
  184. {
  185. RECTL rclClip;
  186. RECTL rclGradient;
  187. POINTL ptDraw;
  188. SIZEL szDraw;
  189. ULONGLONG llRed;
  190. ULONGLONG llGreen;
  191. ULONGLONG llBlue;
  192. ULONGLONG llAlpha;
  193. LONGLONG lldRdY;
  194. LONGLONG lldGdY;
  195. LONGLONG lldBdY;
  196. LONGLONG lldAdY;
  197. LONGLONG lldRdX;
  198. LONGLONG lldGdX;
  199. LONGLONG lldBdX;
  200. LONGLONG lldAdX;
  201. POINTL ptDitherOrg;
  202. ULONG ulMode;
  203. XLATEOBJ *pxlo;
  204. XEPALOBJ *ppalDstSurf;
  205. LONG xScanAdjust;
  206. LONG yScanAdjust;
  207. }GRADIENTRECTDATA,*PGRADIENTRECTDATA;
  208. /**************************************************************************\
  209. * COLOR_INTERP
  210. *
  211. * Color interpolation is done in fixed point 8.56 (tri) or 8.48 (rect)
  212. * This union makes it faster to get int pixel.
  213. *
  214. \**************************************************************************/
  215. typedef union _COLOR_INTERP
  216. {
  217. ULONGLONG ullColor;
  218. ULONG ul[2];
  219. BYTE b[8];
  220. }COLOR_INTERP,*PCOLOR_INTERP;
  221. /**************************************************************************\
  222. * TRIEDGE
  223. *
  224. * Tirangle gradient fill: record left and right edge of each scan
  225. * line. Also record starting color for left edge of scan line. Color
  226. * gradient is stored in TRIANGLEDATA
  227. *
  228. * History:
  229. *
  230. * 2/20/1997 Mark Enstrom [marke]
  231. *
  232. \**************************************************************************/
  233. typedef struct _TRIEDGE
  234. {
  235. LONG xLeft;
  236. LONG xRight;
  237. LONGLONG llRed;
  238. LONGLONG llGreen;
  239. LONGLONG llBlue;
  240. LONGLONG llAlpha;
  241. }TRIEDGE,*PTRIEDGE;
  242. /**************************************************************************\
  243. * TRIANGLEDATA
  244. *
  245. * Color gradient and scan line information needed to gradient fill
  246. * triangle
  247. *
  248. * History:
  249. *
  250. * 2/20/1997 Mark Enstrom [marke]
  251. *
  252. \**************************************************************************/
  253. typedef struct _TRIANGLEDATA
  254. {
  255. RECTL rcl;
  256. LONGLONG lldRdX;
  257. LONGLONG lldGdX;
  258. LONGLONG lldBdX;
  259. LONGLONG lldAdX;
  260. LONGLONG lldRdY;
  261. LONGLONG lldGdY;
  262. LONGLONG lldBdY;
  263. LONGLONG lldAdY;
  264. LONGLONG llRA;
  265. LONGLONG llGA;
  266. LONGLONG llBA;
  267. LONGLONG llAA;
  268. LONG y0;
  269. LONG y1;
  270. LONGLONG Area;
  271. POINTL ptDitherOrg;
  272. POINTL ptColorCalcOrg;
  273. LONG DrawMode;
  274. XLATEOBJ *pxlo;
  275. XEPALOBJ *ppalDstSurf;
  276. TRIEDGE TriEdge[1];
  277. }TRIANGLEDATA,*PTRIANGLEDATA;
  278. /**************************************************************************\
  279. * TRIANGLEDATA
  280. *
  281. * This structure contains stuff common to all the triangle interpolations
  282. *
  283. *
  284. * x1 -
  285. * x2 -
  286. * y1 -
  287. * y2 -
  288. * m - min(x_i - x_0) + min(y_i - y_0);
  289. * d - determinant
  290. * Q - floor(D/abs(d));
  291. * R - D mod abs(d);
  292. *
  293. * History:
  294. *
  295. * 5/20/1997 Kirko
  296. *
  297. \**************************************************************************/
  298. typedef struct _GRADSTRUCT {
  299. LONG x1;
  300. LONG x2;
  301. LONG y1;
  302. LONG y2;
  303. LONG m;
  304. LONG d;
  305. LONGLONG Q;
  306. LONGLONG R;
  307. } GRADSTRUCT;
  308. //
  309. // constant in triangle color gradient calc
  310. //
  311. #define TWO_TO_THE_48TH 0x0001000000000000
  312. //
  313. // maximum edge of triangle before it must be split
  314. //
  315. // 2^16
  316. //
  317. #define MAX_EDGE_LENGTH 16384
  318. /**************************************************************************\
  319. * TRIDDA - data to run line DDAs for generating triangle endpoints
  320. *
  321. *
  322. * History:
  323. *
  324. * 2/20/1997 Mark Enstrom [marke]
  325. *
  326. \**************************************************************************/
  327. typedef struct _TRIDDA
  328. {
  329. LONG M0; // Initial X Device space
  330. LONG N0; // Initial Y Device spave
  331. LONG dM; // Delta X
  332. LONG dN; // Delta Y
  333. LONGLONG C; // Initial Error Constant
  334. LONG dL; // Interger component of delta X
  335. LONG dR; // Remainder component of delta X
  336. LONG R; // Remainder
  337. LONG Rb; // Remainder used to compare with 0
  338. LONG L; // Temp
  339. LONG j; // Temp
  340. LONG Linc; // X inc (pos or neg)
  341. LONG yIndex; // Current index into line array
  342. LONG NumScanLines; // Number of scan lines to run
  343. LONG t0; // place holder
  344. LONGLONG llRed; // Current Color
  345. LONGLONG llGreen; // Current Color
  346. LONGLONG llBlue; // Current Color
  347. LONGLONG llAlpha; // Current Color
  348. LONGLONG lldxyRed; // Combined integer change for step in x and y
  349. LONGLONG lldxyGreen; // Combined integer change for step in x and y
  350. LONGLONG lldxyBlue; // Combined integer change for step in x and y
  351. LONGLONG lldxyAlpha; // Combined integer change for step in x and y
  352. }TRIDDA,*PTRIDDA;
  353. #define SWAP_VERTEX(pv0,pv1,pvt) \
  354. { \
  355. pvt = pv0; \
  356. pv0 = pv1; \
  357. pv1 = pvt; \
  358. }
  359. VOID vGradientFillGeneric(SURFACE *,PTRIANGLEDATA);
  360. VOID vGradientFill1(SURFACE *,PTRIANGLEDATA);
  361. VOID vGradientFill4(SURFACE *,PTRIANGLEDATA);
  362. VOID vGradientFill8(SURFACE *,PTRIANGLEDATA);
  363. VOID vGradientFill16_565(SURFACE *,PTRIANGLEDATA);
  364. VOID vGradientFill16_555(SURFACE *,PTRIANGLEDATA);
  365. VOID vGradientFill16Bitfields(SURFACE *,PTRIANGLEDATA);
  366. VOID vGradientFill24RGB(SURFACE *,PTRIANGLEDATA);
  367. VOID vGradientFill24BGR(SURFACE *,PTRIANGLEDATA);
  368. VOID vGradientFill24Bitfields(SURFACE *,PTRIANGLEDATA);
  369. VOID vGradientFill32BGRA(SURFACE *,PTRIANGLEDATA);
  370. VOID vGradientFill32RGB(SURFACE *,PTRIANGLEDATA);
  371. VOID vGradientFill32Bitfields(SURFACE *,PTRIANGLEDATA);
  372. typedef VOID (*PFN_GRADIENT)(SURFACE *,PTRIANGLEDATA);
  373. VOID vFillGRectDIB32BGRA(SURFACE *,PGRADIENTRECTDATA);
  374. VOID vFillGRectDIB32RGB(SURFACE *,PGRADIENTRECTDATA);
  375. VOID vFillGRectDIB32Bitfields(SURFACE *,PGRADIENTRECTDATA);
  376. VOID vFillGRectDIB24RGB(SURFACE *,PGRADIENTRECTDATA);
  377. VOID vFillGRectDIB24BGR(SURFACE *,PGRADIENTRECTDATA);
  378. VOID vFillGRectDIB24Bitfields(SURFACE *,PGRADIENTRECTDATA);
  379. VOID vFillGRectDIB16_565(SURFACE *,PGRADIENTRECTDATA);
  380. VOID vFillGRectDIB16_555(SURFACE *,PGRADIENTRECTDATA);
  381. VOID vFillGRectDIB16Bitfields(SURFACE *,PGRADIENTRECTDATA);
  382. VOID vFillGRectDIB8(SURFACE *,PGRADIENTRECTDATA);
  383. VOID vFillGRectDIB4(SURFACE *,PGRADIENTRECTDATA);
  384. VOID vFillGRectDIB1(SURFACE *,PGRADIENTRECTDATA);
  385. typedef VOID (*PFN_GRADRECT)(SURFACE *,PGRADIENTRECTDATA);
  386. BOOL
  387. bDoGradient(
  388. LONGLONG *pA,
  389. LONGLONG *pB,
  390. LONGLONG *pC,
  391. LONG g0,
  392. LONG g1,
  393. LONG g2,
  394. GRADSTRUCT *pg
  395. );
  396. BOOL
  397. bIsSourceBGRA(
  398. PSURFACE pSurf
  399. );