Source code of Windows XP (NT5)
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.

296 lines
7.7 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: span_s.h *
  3. * *
  4. * This include file is used to generate various flavors of smooth-shaded *
  5. * spans, or scanlines. The variations cover RGB/Color-indexed operation, *
  6. * dithering, and pixel-depth. Not your typical include file. *
  7. * *
  8. * Created: 24-Feb-1994 *
  9. * Author: Otto Berkes [ottob] *
  10. * *
  11. * Copyright (c) 1994 Microsoft Corporation *
  12. \**************************************************************************/
  13. void
  14. #if RGBMODE
  15. #if DITHER
  16. #if (BPP == 8)
  17. __fastGenRGB8DithSmoothSpan(__GLGENcontext *gengc)
  18. #elif (BPP == 16)
  19. __fastGenRGB16DithSmoothSpan(__GLGENcontext *gengc)
  20. #elif (BPP == 24)
  21. __fastGenRGB24DithSmoothSpan(__GLGENcontext *gengc)
  22. #else
  23. __fastGenRGB32DithSmoothSpan(__GLGENcontext *gengc)
  24. #endif
  25. #else //!DITHER
  26. #if (BPP == 8)
  27. __fastGenRGB8SmoothSpan(__GLGENcontext *gengc)
  28. #elif (BPP == 16)
  29. __fastGenRGB16SmoothSpan(__GLGENcontext *gengc)
  30. #elif (BPP == 24)
  31. __fastGenRGB24SmoothSpan(__GLGENcontext *gengc)
  32. #else
  33. __fastGenRGB32SmoothSpan(__GLGENcontext *gengc)
  34. #endif
  35. #endif //!DITHER
  36. #else //!RGBMODE
  37. #if DITHER
  38. #if (BPP == 8)
  39. __fastGenCI8DithSmoothSpan(__GLGENcontext *gengc)
  40. #elif (BPP == 16)
  41. __fastGenCI16DithSmoothSpan(__GLGENcontext *gengc)
  42. #elif (BPP == 24)
  43. __fastGenCI24DithSmoothSpan(__GLGENcontext *gengc)
  44. #else
  45. __fastGenCI32DithSmoothSpan(__GLGENcontext *gengc)
  46. #endif
  47. #else //!DITHER
  48. #if (BPP == 8)
  49. __fastGenCI8SmoothSpan(__GLGENcontext *gengc)
  50. #elif (BPP == 16)
  51. __fastGenCI16SmoothSpan(__GLGENcontext *gengc)
  52. #elif (BPP == 24)
  53. __fastGenCI24SmoothSpan(__GLGENcontext *gengc)
  54. #else
  55. __fastGenCI32SmoothSpan(__GLGENcontext *gengc)
  56. #endif
  57. #endif //!DITHER
  58. #endif //!RGBMODE
  59. {
  60. ULONG rAccum;
  61. #if RGBMODE
  62. ULONG gAccum;
  63. ULONG bAccum;
  64. #endif
  65. LONG rDelta;
  66. #if RGBMODE
  67. LONG gDelta;
  68. LONG bDelta;
  69. #endif
  70. ULONG rShift;
  71. #if RGBMODE
  72. ULONG gShift;
  73. ULONG bShift;
  74. #endif
  75. GENACCEL *pGenAccel;
  76. __GLcolorBuffer *cfb;
  77. BYTE *pPix;
  78. #if (BPP == 8)
  79. BYTE *pXlat;
  80. #elif (!RGBMODE)
  81. ULONG *pXlat;
  82. #endif
  83. ULONG *pMask;
  84. #if DITHER
  85. ULONG ditherShift;
  86. ULONG ditherRow;
  87. #endif
  88. LONG count;
  89. LONG totalCount;
  90. // get color deltas and accumulators
  91. pGenAccel = (GENACCEL *)(gengc->pPrivateArea);
  92. rDelta = pGenAccel->spanDelta.r;
  93. #if RGBMODE
  94. gDelta = pGenAccel->spanDelta.g;
  95. bDelta = pGenAccel->spanDelta.b;
  96. #endif
  97. // Try to accelerate color-invariant spans
  98. if (!(pGenAccel->flags & HAVE_STIPPLE) &&
  99. (gengc->gc.polygon.shader.length > 3)) {
  100. if (gengc->gc.polygon.shader.length < 16) {
  101. #if RGBMODE
  102. if ((((rDelta & 0xffffff80) == 0) || ((-rDelta & 0xffffff80) == 0)) &&
  103. (((gDelta & 0xffffff80) == 0) || ((-gDelta & 0xffffff80) == 0)) &&
  104. (((bDelta & 0xffffff80) == 0) || ((-bDelta & 0xffffff80) == 0))) {
  105. #else
  106. if (((rDelta & 0xffffff80) == 0) || ((-rDelta & 0xffffff80) == 0)) {
  107. #endif
  108. (*pGenAccel->__fastFlatSpanFuncPtr)(gengc);
  109. return;
  110. }
  111. } else if (gengc->gc.polygon.shader.length < 32) {
  112. #if RGBMODE
  113. if ((((rDelta & 0xffffffc0) == 0) || ((-rDelta & 0xffffffc0) == 0)) &&
  114. (((gDelta & 0xffffffc0) == 0) || ((-gDelta & 0xffffffc0) == 0)) &&
  115. (((bDelta & 0xffffffc0) == 0) || ((-bDelta & 0xffffffc0) == 0))) {
  116. #else
  117. if (((rDelta & 0xffffffc0) == 0) || ((-rDelta & 0xffffffc0) == 0)) {
  118. #endif
  119. (*pGenAccel->__fastFlatSpanFuncPtr)(gengc);
  120. return;
  121. }
  122. } else if (gengc->gc.polygon.shader.length < 64) {
  123. #if RGBMODE
  124. if ((((rDelta & 0xffffffe0) == 0) || ((-rDelta & 0xffffffe0) == 0)) &&
  125. (((gDelta & 0xffffffe0) == 0) || ((-gDelta & 0xffffffe0) == 0)) &&
  126. (((bDelta & 0xffffffe0) == 0) || ((-bDelta & 0xffffffe0) == 0))) {
  127. #else
  128. if (((rDelta & 0xffffffe0) == 0) || ((-rDelta & 0xffffffe0) == 0)) {
  129. #endif
  130. (*pGenAccel->__fastFlatSpanFuncPtr)(gengc);
  131. return;
  132. }
  133. }
  134. }
  135. rAccum = pGenAccel->spanValue.r;
  136. #if RGBMODE
  137. gAccum = pGenAccel->spanValue.g;
  138. bAccum = pGenAccel->spanValue.b;
  139. #endif
  140. cfb = gengc->gc.polygon.shader.cfb;
  141. rShift = cfb->redShift;
  142. #if RGBMODE
  143. gShift = cfb->greenShift;
  144. bShift = cfb->blueShift;
  145. #endif
  146. // get address of destination
  147. if (pGenAccel->flags & SURFACE_TYPE_DIB) {
  148. int xScr;
  149. int yScr;
  150. xScr = gengc->gc.polygon.shader.frag.x -
  151. gengc->gc.constants.viewportXAdjust +
  152. cfb->buf.xOrigin;
  153. yScr = gengc->gc.polygon.shader.frag.y -
  154. gengc->gc.constants.viewportYAdjust +
  155. cfb->buf.yOrigin;
  156. pPix = (BYTE *)cfb->buf.base + (yScr * cfb->buf.outerWidth) +
  157. #if (BPP == 8)
  158. xScr;
  159. #elif (BPP == 16)
  160. (xScr << 1);
  161. #elif (BPP == 24)
  162. xScr + (xScr << 1);
  163. #else
  164. (xScr << 2);
  165. #endif //BPP
  166. } else
  167. pPix = gengc->ColorsBits;
  168. // set up pointer to translation table as needed
  169. #if (BPP == 8)
  170. pXlat = gengc->pajTranslateVector;
  171. #elif (!RGBMODE)
  172. pXlat = (ULONG *)(gengc->pajTranslateVector + sizeof(DWORD));
  173. #endif
  174. #if DITHER
  175. ditherRow = Dither_4x4[gengc->gc.polygon.shader.frag.y & 0x3];
  176. ditherShift = (gengc->gc.polygon.shader.frag.x & 0x3) << 3;
  177. #endif
  178. pMask = gengc->gc.polygon.shader.stipplePat;
  179. if ((totalCount = count = gengc->gc.polygon.shader.length) > 32)
  180. count = 32;
  181. for (; totalCount > 0; totalCount -= 32) {
  182. ULONG mask;
  183. ULONG maskTest;
  184. if ((mask = *pMask++) == 0) {
  185. #if RGBMODE
  186. rAccum += (rDelta << 5);
  187. gAccum += (gDelta << 5);
  188. bAccum += (bDelta << 5);
  189. #else
  190. rAccum += (rDelta << 5);
  191. #endif
  192. pPix += (32 * (BPP / 8));
  193. continue;
  194. }
  195. maskTest = 0x80000000;
  196. if ((count = totalCount) > 32)
  197. count = 32;
  198. for (; count; count--, maskTest >>= 1) {
  199. if (mask & maskTest) {
  200. DWORD color;
  201. #if DITHER
  202. ULONG ditherVal = ((ditherRow >> ditherShift) & 0xff) << 8;
  203. ditherShift = (ditherShift + 8) & 0x18;
  204. #else
  205. #define ditherVal 0x0800
  206. #endif
  207. #if RGBMODE
  208. color = (((rAccum + ditherVal) >> 16) << rShift) |
  209. (((gAccum + ditherVal) >> 16) << gShift) |
  210. (((bAccum + ditherVal) >> 16) << bShift);
  211. #if (BPP == 8)
  212. // XXX the color value should *not* have to be masked!
  213. color = *(pXlat + (color & 0xff));
  214. #endif
  215. #else //!RGBMODE
  216. // XXX nor should color-index values!
  217. #if (BPP == 8)
  218. color = *(pXlat + (((rAccum + ditherVal) >> 16) & 0xff));
  219. #else
  220. color = *(pXlat + (((rAccum + ditherVal) >> 16) & 0xfff));
  221. #endif
  222. #endif //!RGBMODE
  223. #if (BPP == 8)
  224. *pPix = (BYTE)color;
  225. #elif (BPP == 16)
  226. *((WORD *)pPix) = (USHORT)color;
  227. #elif (BPP == 24)
  228. *pPix = (BYTE)color;
  229. *(pPix + 1) = (BYTE)(color >> 8);
  230. *(pPix + 2) = (BYTE)(color >> 16);
  231. #else
  232. *((DWORD *)pPix) = color;
  233. #endif //BPP
  234. }
  235. #if RGBMODE
  236. rAccum += rDelta;
  237. gAccum += gDelta;
  238. bAccum += bDelta;
  239. #else
  240. rAccum += rDelta;
  241. #endif
  242. pPix += (BPP / 8);
  243. }
  244. }
  245. }
  246. #if !DITHER
  247. #undef ditherVal
  248. #endif