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.

353 lines
12 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // This file contains the source and destination alpha blend functions.
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997.
  6. //
  7. //-----------------------------------------------------------------------------
  8. #include "rgb_pch.h"
  9. #pragma hdrstop
  10. #include "cbldfncs.h"
  11. //-----------------------------------------------------------------------------
  12. //
  13. // SrcBlendZero
  14. //
  15. // (0, 0, 0, 0) * Src
  16. //
  17. //-----------------------------------------------------------------------------
  18. void C_SrcBlend_Zero(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  19. {
  20. *pR = 0;
  21. *pG = 0;
  22. *pB = 0;
  23. *pA = 0;
  24. }
  25. //-----------------------------------------------------------------------------
  26. //
  27. // SrcBlendOne
  28. //
  29. // (1, 1, 1, 1) * Src
  30. //
  31. //-----------------------------------------------------------------------------
  32. void C_SrcBlend_One(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  33. {
  34. *pR = pCtx->SI.uBR;
  35. *pG = pCtx->SI.uBG;
  36. *pB = pCtx->SI.uBB;
  37. *pA = pCtx->SI.uBA;
  38. }
  39. //-----------------------------------------------------------------------------
  40. //
  41. // SrcBlendSrcColor
  42. //
  43. // (Rs, Gs, Bs, As) * Src
  44. //
  45. //-----------------------------------------------------------------------------
  46. void C_SrcBlend_SrcColor(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  47. {
  48. *pR = (pCtx->SI.uBR>>8)*(pCtx->SI.uBR>>8);
  49. *pG = (pCtx->SI.uBG>>8)*(pCtx->SI.uBG>>8);
  50. *pB = (pCtx->SI.uBB>>8)*(pCtx->SI.uBB>>8);
  51. *pA = (pCtx->SI.uBA>>8)*(pCtx->SI.uBA>>8);
  52. }
  53. //-----------------------------------------------------------------------------
  54. //
  55. // SrcBlendInvSrcColor
  56. //
  57. // (1-Rs, 1-Gs, 1-Bs, 1-As) * Src
  58. //
  59. //-----------------------------------------------------------------------------
  60. void C_SrcBlend_InvSrcColor(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  61. {
  62. *pR = (0xff - (pCtx->SI.uBR>>8))*(pCtx->SI.uBR>>8);
  63. *pG = (0xff - (pCtx->SI.uBG>>8))*(pCtx->SI.uBG>>8);
  64. *pB = (0xff - (pCtx->SI.uBB>>8))*(pCtx->SI.uBB>>8);
  65. *pA = (0xff - (pCtx->SI.uBA>>8))*(pCtx->SI.uBA>>8);
  66. }
  67. //-----------------------------------------------------------------------------
  68. //
  69. // SrcBlendSrcAlpha
  70. //
  71. // (As, As, As, As) * Src
  72. //
  73. //-----------------------------------------------------------------------------
  74. void C_SrcBlend_SrcAlpha(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  75. {
  76. UINT16 f = pCtx->SI.uBA>>8;
  77. *pR = f*(pCtx->SI.uBR>>8);
  78. *pG = f*(pCtx->SI.uBG>>8);
  79. *pB = f*(pCtx->SI.uBB>>8);
  80. *pA = f*(pCtx->SI.uBA>>8);
  81. }
  82. //-----------------------------------------------------------------------------
  83. //
  84. // SrcBlendInvSrcAlpha
  85. //
  86. // (1-As, 1-As, 1-As, 1-As) * Src
  87. //
  88. //-----------------------------------------------------------------------------
  89. void C_SrcBlend_InvSrcAlpha(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  90. {
  91. UINT16 f = 0xff - (pCtx->SI.uBA>>8);
  92. *pR = f*(pCtx->SI.uBR>>8);
  93. *pG = f*(pCtx->SI.uBG>>8);
  94. *pB = f*(pCtx->SI.uBB>>8);
  95. *pA = f*(pCtx->SI.uBA>>8);
  96. }
  97. //-----------------------------------------------------------------------------
  98. //
  99. // SrcBlendDestAlpha
  100. //
  101. // (Ad, Ad, Ad, Ad) * Src
  102. //
  103. //-----------------------------------------------------------------------------
  104. void C_SrcBlend_DestAlpha(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  105. {
  106. UINT16 f = (UINT16)RGBA_GETALPHA(DestC);
  107. *pR = f*(pCtx->SI.uBR>>8);
  108. *pG = f*(pCtx->SI.uBG>>8);
  109. *pB = f*(pCtx->SI.uBB>>8);
  110. *pA = f*(pCtx->SI.uBA>>8);
  111. }
  112. //-----------------------------------------------------------------------------
  113. //
  114. // SrcBlendInvDestAlpha
  115. //
  116. // (1-Ad, 1-Ad, 1-Ad, 1-Ad) * Src
  117. //
  118. //-----------------------------------------------------------------------------
  119. void C_SrcBlend_InvDestAlpha(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  120. {
  121. UINT16 f = 0xff - (UINT16)RGBA_GETALPHA(DestC);
  122. *pR = f*(pCtx->SI.uBR>>8);
  123. *pG = f*(pCtx->SI.uBG>>8);
  124. *pB = f*(pCtx->SI.uBB>>8);
  125. *pA = f*(pCtx->SI.uBA>>8);
  126. }
  127. //-----------------------------------------------------------------------------
  128. //
  129. // SrcBlendDestColor
  130. //
  131. // (Rd, Gd, Bd, Ad) * Src
  132. //
  133. //-----------------------------------------------------------------------------
  134. void C_SrcBlend_DestColor(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  135. {
  136. *pR = (UINT16)RGBA_GETRED(DestC) *(pCtx->SI.uBR>>8);
  137. *pG = (UINT16)RGBA_GETGREEN(DestC)*(pCtx->SI.uBG>>8);
  138. *pB = (UINT16)RGBA_GETBLUE(DestC) *(pCtx->SI.uBB>>8);
  139. *pA = (UINT16)RGBA_GETALPHA(DestC)*(pCtx->SI.uBA>>8);
  140. }
  141. //-----------------------------------------------------------------------------
  142. //
  143. // SrcBlendInvDestColor
  144. //
  145. // (1-Rd, 1-Gd, 1-Bd, 1-Ad) * Src
  146. //
  147. //-----------------------------------------------------------------------------
  148. void C_SrcBlend_InvDestColor(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  149. {
  150. *pR = (0xff - (UINT16)RGBA_GETRED(DestC) )*(pCtx->SI.uBR>>8);
  151. *pG = (0xff - (UINT16)RGBA_GETGREEN(DestC))*(pCtx->SI.uBG>>8);
  152. *pB = (0xff - (UINT16)RGBA_GETBLUE(DestC) )*(pCtx->SI.uBB>>8);
  153. *pA = (0xff - (UINT16)RGBA_GETALPHA(DestC))*(pCtx->SI.uBA>>8);
  154. }
  155. //-----------------------------------------------------------------------------
  156. //
  157. // SrcBlendSrcAlphaSat
  158. //
  159. // f = min(as, 1-Ad); (f, f, f, 1) * Src
  160. //
  161. //-----------------------------------------------------------------------------
  162. void C_SrcBlend_SrcAlphaSat(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  163. {
  164. UINT16 f = min< UINT16>(pCtx->SI.uBA>>8, 0xff - (UINT16)RGBA_GETALPHA(DestC));
  165. *pR = f*(pCtx->SI.uBR>>8);
  166. *pG = f*(pCtx->SI.uBG>>8);
  167. *pB = f*(pCtx->SI.uBB>>8);
  168. *pA = pCtx->SI.uBA;
  169. }
  170. //-----------------------------------------------------------------------------
  171. //
  172. // DestBlendZero
  173. //
  174. // (0, 0, 0, 0) * Dest
  175. //
  176. //-----------------------------------------------------------------------------
  177. void C_DestBlend_Zero(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  178. {
  179. *pR = 0;
  180. *pG = 0;
  181. *pB = 0;
  182. *pA = 0;
  183. }
  184. //-----------------------------------------------------------------------------
  185. //
  186. // DestBlendOne
  187. //
  188. // (1, 1, 1, 1) * Dest
  189. //
  190. //-----------------------------------------------------------------------------
  191. void C_DestBlend_One(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  192. {
  193. *pR = ((UINT16)RGBA_GETRED(DestC) <<8);
  194. *pG = ((UINT16)RGBA_GETGREEN(DestC)<<8);
  195. *pB = ((UINT16)RGBA_GETBLUE(DestC) <<8);
  196. *pA = ((UINT16)RGBA_GETALPHA(DestC)<<8);
  197. }
  198. //-----------------------------------------------------------------------------
  199. //
  200. // DestBlendSrcColor
  201. //
  202. // (Rs, Gs, Bs, As) * Dest
  203. //
  204. //-----------------------------------------------------------------------------
  205. void C_DestBlend_SrcColor(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  206. {
  207. *pR = (pCtx->SI.uBR>>8)*((UINT16)RGBA_GETRED(DestC) );
  208. *pG = (pCtx->SI.uBG>>8)*((UINT16)RGBA_GETGREEN(DestC));
  209. *pB = (pCtx->SI.uBB>>8)*((UINT16)RGBA_GETBLUE(DestC) );
  210. *pA = (pCtx->SI.uBA>>8)*((UINT16)RGBA_GETALPHA(DestC));
  211. }
  212. //-----------------------------------------------------------------------------
  213. //
  214. // DestBlendInvSrcColor
  215. //
  216. // (1-Rs, 1-Gs, 1-Bs, 1-As) * Dest
  217. //
  218. //-----------------------------------------------------------------------------
  219. void C_DestBlend_InvSrcColor(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  220. {
  221. *pR = (0xff - (pCtx->SI.uBR>>8))*((UINT16)RGBA_GETRED(DestC) );
  222. *pG = (0xff - (pCtx->SI.uBG>>8))*((UINT16)RGBA_GETGREEN(DestC));
  223. *pB = (0xff - (pCtx->SI.uBB>>8))*((UINT16)RGBA_GETBLUE(DestC) );
  224. *pA = (0xff - (pCtx->SI.uBA>>8))*((UINT16)RGBA_GETALPHA(DestC));
  225. }
  226. //-----------------------------------------------------------------------------
  227. //
  228. // DestBlendSrcAlpha
  229. //
  230. // (As, As, As, As) * Dest
  231. //
  232. //-----------------------------------------------------------------------------
  233. void C_DestBlend_SrcAlpha(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  234. {
  235. UINT16 f = pCtx->SI.uBA>>8;
  236. *pR = f*((UINT16)RGBA_GETRED(DestC) );
  237. *pG = f*((UINT16)RGBA_GETGREEN(DestC));
  238. *pB = f*((UINT16)RGBA_GETBLUE(DestC) );
  239. *pA = f*((UINT16)RGBA_GETALPHA(DestC));
  240. }
  241. //-----------------------------------------------------------------------------
  242. //
  243. // DestBlendInvSrcAlpha
  244. //
  245. // (1-As, 1-As, 1-As, 1-As) * Dest
  246. //
  247. //-----------------------------------------------------------------------------
  248. void C_DestBlend_InvSrcAlpha(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  249. {
  250. UINT16 f = 0xff - (pCtx->SI.uBA>>8);
  251. *pR = f*((UINT16)RGBA_GETRED(DestC) );
  252. *pG = f*((UINT16)RGBA_GETGREEN(DestC));
  253. *pB = f*((UINT16)RGBA_GETBLUE(DestC) );
  254. *pA = f*((UINT16)RGBA_GETALPHA(DestC));
  255. }
  256. //-----------------------------------------------------------------------------
  257. //
  258. // DestBlendDestAlpha
  259. //
  260. // (Ad, Ad, Ad, Ad) * Dest
  261. //
  262. //-----------------------------------------------------------------------------
  263. void C_DestBlend_DestAlpha(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  264. {
  265. UINT16 f = (UINT16)RGBA_GETALPHA(DestC);
  266. *pR = f*((UINT16)RGBA_GETRED(DestC) );
  267. *pG = f*((UINT16)RGBA_GETGREEN(DestC));
  268. *pB = f*((UINT16)RGBA_GETBLUE(DestC) );
  269. *pA = f*((UINT16)RGBA_GETALPHA(DestC));
  270. }
  271. //-----------------------------------------------------------------------------
  272. //
  273. // DestBlendInvDestAlpha
  274. //
  275. // (1-Ad, 1-Ad, 1-Ad, 1-Ad) * Dest
  276. //
  277. //-----------------------------------------------------------------------------
  278. void C_DestBlend_InvDestAlpha(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  279. {
  280. UINT16 f = 0xff - (UINT16)RGBA_GETALPHA(DestC);
  281. *pR = f*((UINT16)RGBA_GETRED(DestC) );
  282. *pG = f*((UINT16)RGBA_GETGREEN(DestC));
  283. *pB = f*((UINT16)RGBA_GETBLUE(DestC) );
  284. *pA = f*((UINT16)RGBA_GETALPHA(DestC));
  285. }
  286. //-----------------------------------------------------------------------------
  287. //
  288. // DestBlendDestColor
  289. //
  290. // (Rd, Gd, Bd, Ad) * Dest
  291. //
  292. //-----------------------------------------------------------------------------
  293. void C_DestBlend_DestColor(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  294. {
  295. *pR = ((UINT16)RGBA_GETRED(DestC) )*((UINT16)RGBA_GETRED(DestC) );
  296. *pG = ((UINT16)RGBA_GETGREEN(DestC))*((UINT16)RGBA_GETGREEN(DestC));
  297. *pB = ((UINT16)RGBA_GETBLUE(DestC) )*((UINT16)RGBA_GETBLUE(DestC) );
  298. *pA = ((UINT16)RGBA_GETALPHA(DestC))*((UINT16)RGBA_GETALPHA(DestC));
  299. }
  300. //-----------------------------------------------------------------------------
  301. //
  302. // DestBlendInvDestColor
  303. //
  304. // (1-Rd, 1-Gd, 1-Bd, 1-Ad) * Dest
  305. //
  306. //-----------------------------------------------------------------------------
  307. void C_DestBlend_InvDestColor(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  308. {
  309. *pR = (0xff - (UINT16)RGBA_GETRED(DestC) )*((UINT16)RGBA_GETRED(DestC) );
  310. *pG = (0xff - (UINT16)RGBA_GETGREEN(DestC))*((UINT16)RGBA_GETGREEN(DestC));
  311. *pB = (0xff - (UINT16)RGBA_GETBLUE(DestC) )*((UINT16)RGBA_GETBLUE(DestC) );
  312. *pA = (0xff - (UINT16)RGBA_GETALPHA(DestC))*((UINT16)RGBA_GETALPHA(DestC));
  313. }
  314. //-----------------------------------------------------------------------------
  315. //
  316. // DestBlendSrcAlphaSat
  317. //
  318. // f = min(As, 1-Ad); (f, f, f, 1) * Dest
  319. //
  320. //-----------------------------------------------------------------------------
  321. void C_DestBlend_SrcAlphaSat(PUINT16 pR, PUINT16 pG, PUINT16 pB, PUINT16 pA, D3DCOLOR DestC, PD3DI_RASTCTX pCtx)
  322. {
  323. UINT16 f = min< UINT16>(pCtx->SI.uBA>>8, 0xff - (UINT16)RGBA_GETALPHA(DestC));
  324. *pR = f*((UINT16)RGBA_GETRED(DestC) );
  325. *pG = f*((UINT16)RGBA_GETGREEN(DestC));
  326. *pB = f*((UINT16)RGBA_GETBLUE(DestC) );
  327. *pA = (UINT16)RGBA_GETALPHA(DestC)<<8;
  328. }