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.

270 lines
10 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: texspan2.h
  3. *
  4. * Calculate the textured pixel, and write the value to the framebuffer.
  5. *
  6. * 22-Nov-1995 ottob Created
  7. *
  8. * Copyright (c) 1995 Microsoft Corporation
  9. \**************************************************************************/
  10. {
  11. DWORD r, g, b;
  12. #if (FLAT_SHADING || SMOOTH_SHADING)
  13. #if (BPP == 8)
  14. ULONG ditherVal = pdither[((ULONG_PTR)pPix) & 0x3];
  15. #elif (BPP == 16)
  16. ULONG ditherVal = pdither[((ULONG_PTR)pPix & 0x6) >> 1];
  17. #endif
  18. #endif
  19. #if PALETTE_ENABLED
  20. if (bPalette) {
  21. texBits = ((BYTE *)TEX_IMAGE +
  22. ((sResult & GENACCEL(gengc).sMask) >> S_SHIFT_PAL) +
  23. ((tResult & TMASK_SUBDIV) >> T_SHIFT_PAL));
  24. texBits = (BYTE *)((ULONG *)TEX_PALETTE + *texBits);
  25. } else {
  26. texBits = ((BYTE *)TEX_IMAGE +
  27. ((sResult & GENACCEL(gengc).sMask) >> S_SHIFT) +
  28. ((tResult & TMASK_SUBDIV) >> T_SHIFT));
  29. }
  30. #elif PALETTE_ONLY
  31. texBits = ((BYTE *)TEX_IMAGE +
  32. ((sResult & GENACCEL(gengc).sMask) >> S_SHIFT_PAL) +
  33. ((tResult & TMASK_SUBDIV) >> T_SHIFT_PAL));
  34. texBits = (BYTE *)((ULONG *)TEX_PALETTE + *texBits);
  35. #else
  36. texBits = ((BYTE *)TEX_IMAGE +
  37. ((sResult & GENACCEL(gengc).sMask) >> S_SHIFT) +
  38. ((tResult & TMASK_SUBDIV) >> T_SHIFT));
  39. #endif
  40. sResult += subDs;
  41. tResult += subDt;
  42. #if (FAST_REPLACE)
  43. {
  44. #if (ALPHA)
  45. if (texBits[3] != 0) {
  46. if (texBits[3] != 0xff) {
  47. texBits = (texBits - GENACCEL(gengc).texImageReplace +
  48. (BYTE *)GENACCEL(gengc).texPalette);
  49. ALPHA_NOMODULATE
  50. ALPHA_READ
  51. #if (BPP == 32)
  52. r = (((gbMulTable[aDisplay | texBits[2]] + rDisplay) << 8) << -RRIGHTSHIFTADJ) & RMASK;
  53. #else
  54. r = (((gbMulTable[aDisplay | texBits[2]] + rDisplay) << 8) >> RRIGHTSHIFTADJ) & RMASK;
  55. #endif
  56. g = (((gbMulTable[aDisplay | texBits[1]] + gDisplay) << 8) >> GRIGHTSHIFTADJ) & GMASK;
  57. b = (((gbMulTable[aDisplay | texBits[0]] + bDisplay) << 8) >> BRIGHTSHIFTADJ) & BMASK;
  58. #if (BPP == 8)
  59. *pPix = gengc->xlatPalette[r | g | b];
  60. #elif (BPP == 16)
  61. *((USHORT *)pPix) = (USHORT)(r | g | b);
  62. #else
  63. *((USHORT UNALIGNED *)pPix) = (USHORT)(g | b);
  64. pPix[2] = (BYTE)(r >> 16);
  65. #endif
  66. } else {
  67. #if (BPP > 16)
  68. ULONG texel = *((ULONG *)texBits);
  69. #endif
  70. #if (BPP == 8)
  71. *pPix = *texBits;
  72. #elif (BPP == 16)
  73. *((USHORT *)pPix) = *((USHORT *)texBits);
  74. #else
  75. *((USHORT UNALIGNED *)pPix) = (USHORT)texel;
  76. pPix[2] = (BYTE)(texel >> 16);
  77. #endif
  78. }
  79. }
  80. #else
  81. {
  82. #if (BPP > 16)
  83. ULONG texel = *((ULONG *)texBits);
  84. #endif
  85. #if (BPP == 8)
  86. *pPix = *texBits;
  87. #elif (BPP == 16)
  88. *((USHORT *)pPix) = *((USHORT *)texBits);
  89. #else
  90. *((USHORT UNALIGNED *)pPix) = (USHORT)texel;
  91. pPix[2] = (BYTE)(texel >> 16);
  92. #endif
  93. }
  94. #endif
  95. }
  96. #elif (REPLACE)
  97. {
  98. #if (ALPHA)
  99. if (texBits[3] != 0) {
  100. if (texBits[3] != 0xff) {
  101. ALPHA_NOMODULATE
  102. ALPHA_READ
  103. #if (BPP == 32)
  104. r = (((gbMulTable[aDisplay | texBits[2]] + rDisplay) << 8) << -RRIGHTSHIFTADJ) & RMASK;
  105. #else
  106. r = (((gbMulTable[aDisplay | texBits[2]] + rDisplay) << 8) >> RRIGHTSHIFTADJ) & RMASK;
  107. #endif
  108. g = (((gbMulTable[aDisplay | texBits[1]] + gDisplay) << 8) >> GRIGHTSHIFTADJ) & GMASK;
  109. b = (((gbMulTable[aDisplay | texBits[0]] + bDisplay) << 8) >> BRIGHTSHIFTADJ) & BMASK;
  110. } else {
  111. #if (BPP == 32)
  112. r = ((texBits[2] << 8) << -RRIGHTSHIFTADJ) & RMASK;
  113. #else
  114. r = ((texBits[2] << 8) >> RRIGHTSHIFTADJ) & RMASK;
  115. #endif
  116. g = ((texBits[1] << 8) >> GRIGHTSHIFTADJ) & GMASK;
  117. b = ((texBits[0] << 8) >> BRIGHTSHIFTADJ) & BMASK;
  118. }
  119. #if (BPP == 8)
  120. *pPix = gengc->xlatPalette[r | g | b];
  121. #elif (BPP == 16)
  122. *((USHORT *)pPix) = (USHORT)(r | g | b);
  123. #else
  124. *((USHORT UNALIGNED *)pPix) = (USHORT)(g | b);
  125. pPix[2] = (BYTE)(r >> 16);
  126. #endif
  127. }
  128. #else
  129. #if (BPP != 32)
  130. r = ((texBits[2] << 8) >> RRIGHTSHIFTADJ) & RMASK;
  131. g = ((texBits[1] << 8) >> GRIGHTSHIFTADJ) & GMASK;
  132. b = ((texBits[0] << 8) >> BRIGHTSHIFTADJ) & BMASK;
  133. #endif
  134. #if (BPP == 8)
  135. *pPix = gengc->xlatPalette[r | g | b];
  136. #elif (BPP == 16)
  137. *((USHORT *)pPix) = (USHORT)(r | g | b);
  138. #else
  139. *((USHORT UNALIGNED *)pPix) = *((USHORT *)texBits);
  140. pPix[2] = (BYTE)texBits[2];
  141. #endif
  142. #endif
  143. }
  144. #elif (FLAT_SHADING)
  145. {
  146. #if (ALPHA)
  147. if (texBits[3] != 0) {
  148. ALPHA_MODULATE;
  149. ALPHA_READ;
  150. #if (BPP == 32)
  151. r = ((((gbMulTable[aDisplay | gbMulTable[rAccum | texBits[2]]] + rDisplay) << (8+RBITS)) + ditherVal) << -RRIGHTSHIFTADJ) & RMASK;
  152. #else
  153. r = ((((gbMulTable[aDisplay | gbMulTable[rAccum | texBits[2]]] + rDisplay) << (8+RBITS)) + ditherVal) >> RRIGHTSHIFTADJ) & RMASK;
  154. #endif
  155. g = ((((gbMulTable[aDisplay | gbMulTable[gAccum | texBits[1]]] + gDisplay) << (8+GBITS)) + ditherVal) >> GRIGHTSHIFTADJ) & GMASK;
  156. b = ((((gbMulTable[aDisplay | gbMulTable[bAccum | texBits[0]]] + bDisplay) << (8+BBITS)) + ditherVal) >> BRIGHTSHIFTADJ) & BMASK;
  157. #if (BPP == 8)
  158. *pPix = gengc->xlatPalette[r | g | b];
  159. #elif (BPP == 16)
  160. *((USHORT *)pPix) = (USHORT)(r | g | b);
  161. #else
  162. *((USHORT UNALIGNED *)pPix) = (USHORT)(g | b);
  163. pPix[2] = (BYTE)(r >> 16);
  164. #endif
  165. }
  166. #else
  167. #if (BPP == 32)
  168. r = (((gbMulTable[rAccum | texBits[2]] << (8+RBITS)) + ditherVal) << -RRIGHTSHIFTADJ) & RMASK;
  169. #else
  170. r = (((gbMulTable[rAccum | texBits[2]] << (8+RBITS)) + ditherVal) >> RRIGHTSHIFTADJ) & RMASK;
  171. #endif
  172. g = (((gbMulTable[gAccum | texBits[1]] << (8+GBITS)) + ditherVal) >> GRIGHTSHIFTADJ) & GMASK;
  173. b = (((gbMulTable[bAccum | texBits[0]] << (8+BBITS)) + ditherVal) >> BRIGHTSHIFTADJ) & BMASK;
  174. #if (BPP == 8)
  175. *pPix = gengc->xlatPalette[r | g | b];
  176. #elif (BPP == 16)
  177. *((USHORT *)pPix) = (USHORT)(r | g | b);
  178. #else
  179. *((USHORT UNALIGNED *)pPix) = (USHORT)(g | b);
  180. pPix[2] = (BYTE)(r >> 16);
  181. #endif
  182. #endif
  183. }
  184. #else // SMOOTH_SHADING
  185. {
  186. #if (ALPHA)
  187. if (texBits[3] != 0) {
  188. ALPHA_MODULATE;
  189. ALPHA_READ;
  190. #if (BPP == 32)
  191. r = ((((gbMulTable[aDisplay | gbMulTable[((rAccum >> RBITS) & 0xff00) | texBits[2]]] + rDisplay) << (8+RBITS)) + ditherVal) << -RRIGHTSHIFTADJ) & RMASK;
  192. #else
  193. r = ((((gbMulTable[aDisplay | gbMulTable[((rAccum >> RBITS) & 0xff00) | texBits[2]]] + rDisplay) << (8+RBITS)) + ditherVal) >> RRIGHTSHIFTADJ) & RMASK;
  194. #endif
  195. g = ((((gbMulTable[aDisplay | gbMulTable[((gAccum >> GBITS) & 0xff00) | texBits[1]]] + gDisplay) << (8+GBITS)) + ditherVal) >> GRIGHTSHIFTADJ) & GMASK;
  196. b = ((((gbMulTable[aDisplay | gbMulTable[((bAccum >> BBITS) & 0xff00) | texBits[0]]] + bDisplay) << (8+BBITS)) + ditherVal) >> BRIGHTSHIFTADJ) & BMASK;
  197. #if (BPP == 8)
  198. *pPix = gengc->xlatPalette[r | g | b];
  199. #elif (BPP == 16)
  200. *((USHORT *)pPix) = (USHORT)(r | g | b);
  201. #else
  202. *((USHORT UNALIGNED *)pPix) = (USHORT)(g | b);
  203. pPix[2] = (BYTE)(r >> 16);
  204. #endif
  205. }
  206. #else
  207. #if (BPP == 32)
  208. r = (((gbMulTable[((rAccum >> RBITS) & 0xff00) | texBits[2]] << (8+RBITS)) + ditherVal) << -RRIGHTSHIFTADJ) & RMASK;
  209. #else
  210. r = (((gbMulTable[((rAccum >> RBITS) & 0xff00) | texBits[2]] << (8+RBITS)) + ditherVal) >> RRIGHTSHIFTADJ) & RMASK;
  211. #endif
  212. g = (((gbMulTable[((gAccum >> GBITS) & 0xff00) | texBits[1]] << (8+GBITS)) + ditherVal) >> GRIGHTSHIFTADJ) & GMASK;
  213. b = (((gbMulTable[((bAccum >> BBITS) & 0xff00) | texBits[0]] << (8+BBITS)) + ditherVal) >> BRIGHTSHIFTADJ) & BMASK;
  214. #if (BPP == 8)
  215. *pPix = gengc->xlatPalette[r | g | b];
  216. #elif (BPP == 16)
  217. *((USHORT *)pPix) = (USHORT)(r | g | b);
  218. #else
  219. *((USHORT UNALIGNED *)pPix) = (USHORT)(g | b);
  220. pPix[2] = (BYTE)(r >> 16);
  221. #endif
  222. #endif
  223. }
  224. #endif
  225. }