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.

812 lines
33 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: span_f.h *
  3. * *
  4. * This include file is used to generate various flavors of flat-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. #undef STRING1
  14. #undef STRING2
  15. #undef STRING3
  16. #undef STRING4
  17. #if ZBUFFER
  18. #define STRING1 __fastGenMask
  19. #else
  20. #define STRING1 __fastGen
  21. #endif
  22. #if RGBMODE
  23. #define STRING2 RGB
  24. #else
  25. #define STRING2 CI
  26. #endif
  27. #if DITHER
  28. #define STRING3 STRCAT2(BPP, Dith)
  29. #else
  30. #define STRING3 BPP
  31. #endif
  32. #define STRING4 FlatSpan
  33. #undef OLDTEXTURE
  34. #define OLDTEXTURE 0
  35. void FASTCALL STRCAT4(STRING1, STRING2, STRING3, STRING4)
  36. (__GLGENcontext *gengc)
  37. {
  38. ULONG rAccum;
  39. ULONG rShift;
  40. #if RGBMODE
  41. ULONG gAccum;
  42. ULONG bAccum;
  43. ULONG gShift;
  44. ULONG bShift;
  45. #endif
  46. GENACCEL *pGenAccel;
  47. __GLcolorBuffer *cfb;
  48. BYTE *pPix;
  49. #if (BPP == 8)
  50. BYTE *pXlat;
  51. #elif (!RGBMODE)
  52. ULONG *pXlat;
  53. #endif
  54. #if DITHER
  55. ULONG ditherShift;
  56. ULONG ditherRow;
  57. ULONG ditherVal;
  58. #endif
  59. LONG count, cDith;
  60. ULONG color1;
  61. #if DITHER
  62. #if (RGBMODE) || (BPP > 8)
  63. ULONG color2;
  64. ULONG color3;
  65. ULONG color4;
  66. #endif
  67. #elif (BPP == 24)
  68. ULONG color2;
  69. ULONG color3;
  70. #endif
  71. pGenAccel = (GENACCEL *)(gengc->pPrivateArea);
  72. cfb = gengc->gc.polygon.shader.cfb;
  73. // get color deltas and accumulators
  74. rAccum = pGenAccel->spanValue.r;
  75. rShift = cfb->redShift;
  76. #if RGBMODE
  77. gAccum = pGenAccel->spanValue.g;
  78. bAccum = pGenAccel->spanValue.b;
  79. gShift = cfb->greenShift;
  80. bShift = cfb->blueShift;
  81. #endif
  82. // get address of destination
  83. if (pGenAccel->flags & SURFACE_TYPE_DIB) {
  84. pPix = pGenAccel->pPix +
  85. gengc->gc.polygon.shader.frag.x * (BPP / 8);
  86. } else {
  87. pPix = gengc->ColorsBits;
  88. }
  89. // set up pointer to translation table as needed
  90. #if (BPP == 8)
  91. pXlat = gengc->pajTranslateVector;
  92. #elif (!RGBMODE)
  93. pXlat = (ULONG *)(gengc->pajTranslateVector + sizeof(DWORD));
  94. #endif
  95. cDith = (
  96. gengc->gc.polygon.shader.length >= 4
  97. ? 4
  98. : gengc->gc.polygon.shader.length);
  99. #if DITHER
  100. ditherRow = Dither_4x4[gengc->gc.polygon.shader.frag.y & 0x3];
  101. ditherShift = (gengc->gc.polygon.shader.frag.x & 0x3) << 3;
  102. #if RGBMODE
  103. ditherVal = ((ditherRow >> ditherShift) & 0xff) << 8;
  104. color1 = (((rAccum + ditherVal) >> 16) << rShift) |
  105. (((gAccum + ditherVal) >> 16) << gShift) |
  106. (((bAccum + ditherVal) >> 16) << bShift);
  107. #if (BPP == 8)
  108. color1 = *(pXlat + (color1 & 0xff));
  109. #endif
  110. if (--cDith) {
  111. ditherShift = (ditherShift + 8) & 0x18;
  112. ditherVal = ((ditherRow >> ditherShift) & 0xff) << 8;
  113. color2 = (((rAccum + ditherVal) >> 16) << rShift) |
  114. (((gAccum + ditherVal) >> 16) << gShift) |
  115. (((bAccum + ditherVal) >> 16) << bShift);
  116. #if (BPP == 8)
  117. color1 |= (*(pXlat + (color2 & 0xff))) << 8;
  118. #endif
  119. if (--cDith) {
  120. ditherShift = (ditherShift + 8) & 0x18;
  121. ditherVal = ((ditherRow >> ditherShift) & 0xff) << 8;
  122. color3 = (((rAccum + ditherVal) >> 16) << rShift) |
  123. (((gAccum + ditherVal) >> 16) << gShift) |
  124. (((bAccum + ditherVal) >> 16) << bShift);
  125. #if (BPP == 8)
  126. color1 |= (*(pXlat + (color3 & 0xff))) << 16;
  127. #endif
  128. if (--cDith) {
  129. ditherShift = (ditherShift + 8) & 0x18;
  130. ditherVal = ((ditherRow >> ditherShift) & 0xff) << 8;
  131. color4 = (((rAccum + ditherVal) >> 16) << rShift) |
  132. (((gAccum + ditherVal) >> 16) << gShift) |
  133. (((bAccum + ditherVal) >> 16) << bShift);
  134. #if (BPP == 8)
  135. color1 |= (*(pXlat + (color4 & 0xff))) << 24;
  136. #endif
  137. }
  138. }
  139. }
  140. #else //!RGBMODE
  141. ditherVal = ((ditherRow >> ditherShift) & 0xff) << 8;
  142. #if (BPP == 8)
  143. color1 = *(pXlat + (((rAccum + ditherVal) >> 16) & 0xff));
  144. #else
  145. color1 = *(pXlat + (((rAccum + ditherVal) >> 16) & 0xfff));
  146. #endif
  147. if (--cDith) {
  148. ditherShift = (ditherShift + 8) & 0x18;
  149. ditherVal = ((ditherRow >> ditherShift) & 0xff) << 8;
  150. #if (BPP == 8)
  151. color1 |= (*(pXlat + (((rAccum + ditherVal) >> 16) & 0xff)) << 8);
  152. #else
  153. color2 = *(pXlat + (((rAccum + ditherVal) >> 16) & 0xfff));
  154. #endif
  155. if (--cDith) {
  156. ditherShift = (ditherShift + 8) & 0x18;
  157. ditherVal = ((ditherRow >> ditherShift) & 0xff) << 8;
  158. #if (BPP == 8)
  159. color1 |= (*(pXlat + (((rAccum + ditherVal) >> 16) & 0xff)) << 16);
  160. #else
  161. color3= *(pXlat + (((rAccum + ditherVal) >> 16) & 0xfff));
  162. #endif
  163. if (--cDith) {
  164. ditherShift = (ditherShift + 8) & 0x18;
  165. ditherVal = ((ditherRow >> ditherShift) & 0xff) << 8;
  166. #if (BPP == 8)
  167. color1 |= (*(pXlat + (((rAccum + ditherVal) >> 16) & 0xff)) << 24);
  168. #else
  169. color4 = *(pXlat + (((rAccum + ditherVal) >> 16) & 0xfff));
  170. #endif
  171. }
  172. }
  173. }
  174. #endif //!RGBMODE
  175. #else //!DITHER
  176. #if RGBMODE
  177. color1 = (((rAccum + 0x0800) >> 16) << rShift) |
  178. (((gAccum + 0x0800) >> 16) << gShift) |
  179. (((bAccum + 0x0800) >> 16) << bShift);
  180. #if (BPP == 8)
  181. color1 = *(pXlat + (color1 & 0xff));
  182. #endif
  183. #if (BPP == 16)
  184. color1 = color1 | (color1 << 16);
  185. #elif (BPP == 24)
  186. color2 = color1 >> 8;
  187. color3 = color1 >> 16;
  188. #endif
  189. #else //!RGBMODE
  190. #if (BPP == 8)
  191. color1 = *(pXlat + (((rAccum + 0x0800) >> 16) & 0xff));
  192. #else
  193. color1 = *(pXlat + (((rAccum + 0x0800) >> 16) & 0xfff));
  194. #endif
  195. #if (BPP == 16)
  196. color1 = color1 | (color1 << 16);
  197. #elif (BPP == 24)
  198. color2 = color1 >> 8;
  199. color3 = color1 >> 16;
  200. #endif
  201. #endif //!RGBMODE
  202. #endif //!DITHER
  203. #if (ZBUFFER)
  204. if (pGenAccel->flags & GEN_FASTZBUFFER) {
  205. GLuint zAccum = gengc->gc.polygon.shader.frag.z;
  206. GLint zDelta = gengc->gc.polygon.shader.dzdx;
  207. PBYTE zbuf = (PBYTE)gengc->gc.polygon.shader.zbuf;
  208. count = gengc->gc.polygon.shader.length;
  209. if (gengc->gc.modes.depthBits == 16) {
  210. #if DITHER
  211. for (;;) {
  212. if ( ((__GLz16Value)(zAccum >> Z16_SHIFT)) <= *((__GLz16Value*)zbuf) ) {
  213. *((__GLz16Value*)zbuf) = ((__GLz16Value)(zAccum >> Z16_SHIFT));
  214. #if (BPP == 8)
  215. *pPix = (BYTE)color1;
  216. #elif (BPP == 16)
  217. *((WORD *)pPix) = (WORD)color1;
  218. #elif (BPP == 24)
  219. *pPix = (BYTE)color1;
  220. *(pPix + 1) = (BYTE)(color1 >> 8);
  221. *(pPix + 2) = (BYTE)(color1 >> 16);
  222. #else
  223. *((DWORD *)pPix) = color1;
  224. #endif
  225. }
  226. pPix += (BPP / 8);
  227. if (--count <= 0)
  228. break;
  229. zAccum += zDelta;
  230. zbuf += 2;
  231. if ( ((__GLz16Value)(zAccum >> Z16_SHIFT)) <= *((__GLz16Value*)zbuf) ) {
  232. *((__GLz16Value*)zbuf) = ((__GLz16Value)(zAccum >> Z16_SHIFT));
  233. #if (BPP == 8)
  234. *pPix = (BYTE)(color1 >> 8);
  235. #elif (BPP == 16)
  236. *((WORD *)pPix) = (WORD)color2;
  237. #elif (BPP == 24)
  238. *pPix = (BYTE)color2;
  239. *(pPix + 1) = (BYTE)(color2 >> 8);
  240. *(pPix + 2) = (BYTE)(color2 >> 16);
  241. #else
  242. *((DWORD *)pPix) = color2;
  243. #endif
  244. }
  245. pPix += (BPP / 8);
  246. if (--count <= 0)
  247. break;
  248. zAccum += zDelta;
  249. zbuf += 2;
  250. if ( ((__GLz16Value)(zAccum >> Z16_SHIFT)) <= *((__GLz16Value*)zbuf) ) {
  251. *((__GLz16Value*)zbuf) = ((__GLz16Value)(zAccum >> Z16_SHIFT));
  252. #if (BPP == 8)
  253. *pPix = (BYTE)(color1 >> 16);
  254. #elif (BPP == 16)
  255. *((WORD *)pPix) = (WORD)color3;
  256. #elif (BPP == 24)
  257. *pPix = (BYTE)color3;
  258. *(pPix + 1) = (BYTE)(color3 >> 8);
  259. *(pPix + 2) = (BYTE)(color3 >> 16);
  260. #else
  261. *((DWORD *)pPix) = color3;
  262. #endif
  263. }
  264. pPix += (BPP / 8);
  265. if (--count <= 0)
  266. break;
  267. zAccum += zDelta;
  268. zbuf += 2;
  269. if ( ((__GLz16Value)(zAccum >> Z16_SHIFT)) <= *((__GLz16Value*)zbuf) ) {
  270. *((__GLz16Value*)zbuf) = ((__GLz16Value)(zAccum >> Z16_SHIFT));
  271. #if (BPP == 8)
  272. *pPix = (BYTE)(color1 >> 24);
  273. #elif (BPP == 16)
  274. *((WORD *)pPix) = (WORD)color4;
  275. #elif (BPP == 24)
  276. *pPix = (BYTE)color4;
  277. *(pPix + 1) = (BYTE)(color4 >> 8);
  278. *(pPix + 2) = (BYTE)(color4 >> 16);
  279. #else
  280. *((DWORD *)pPix) = color4;
  281. #endif
  282. }
  283. pPix += (BPP / 8);
  284. if (--count <= 0)
  285. break;
  286. zAccum += zDelta;
  287. zbuf += 2;
  288. }
  289. #else //!DITHER
  290. for (; count; count--) {
  291. if ( ((__GLz16Value)(zAccum >> Z16_SHIFT)) <= *((__GLz16Value*)zbuf) ) {
  292. *((__GLz16Value*)zbuf) = ((__GLz16Value)(zAccum >> Z16_SHIFT));
  293. #if (BPP == 8)
  294. *pPix = (BYTE)color1;
  295. #elif (BPP == 16)
  296. *((WORD *)pPix) = (WORD)color1;
  297. #elif (BPP == 24)
  298. *pPix = (BYTE)color1;
  299. *(pPix + 1) = (BYTE)color2;
  300. *(pPix + 2) = (BYTE)color3;
  301. #else
  302. *((DWORD *)pPix) = color1;
  303. #endif //BPP
  304. }
  305. zAccum += zDelta;
  306. zbuf +=2 ;
  307. pPix += (BPP / 8);
  308. }
  309. #endif //!DITHER
  310. } else {
  311. #if DITHER
  312. for (;;) {
  313. if ( zAccum <= *((GLuint*)zbuf) ) {
  314. *((GLuint*)zbuf) = zAccum;
  315. #if (BPP == 8)
  316. *pPix = (BYTE)color1;
  317. #elif (BPP == 16)
  318. *((WORD *)pPix) = (WORD)color1;
  319. #elif (BPP == 24)
  320. *pPix = (BYTE)color1;
  321. *(pPix + 1) = (BYTE)(color1 >> 8);
  322. *(pPix + 2) = (BYTE)(color1 >> 16);
  323. #else
  324. *((DWORD *)pPix) = color1;
  325. #endif
  326. }
  327. pPix += (BPP / 8);
  328. if (--count <= 0)
  329. break;
  330. zbuf+=4;
  331. zAccum += zDelta;
  332. if ( zAccum <= *((GLuint*)zbuf) ) {
  333. *((GLuint*)zbuf) = zAccum;
  334. #if (BPP == 8)
  335. *pPix = (BYTE)(color1 >> 8);
  336. #elif (BPP == 16)
  337. *((WORD *)pPix) = (WORD)color2;
  338. #elif (BPP == 24)
  339. *pPix = (BYTE)color2;
  340. *(pPix + 1) = (BYTE)(color2 >> 8);
  341. *(pPix + 2) = (BYTE)(color2 >> 16);
  342. #else
  343. *((DWORD *)pPix) = color2;
  344. #endif
  345. }
  346. pPix += (BPP / 8);
  347. if (--count <= 0)
  348. break;
  349. zbuf+=4;
  350. zAccum += zDelta;
  351. if ( zAccum <= *((GLuint*)zbuf) ) {
  352. *((GLuint*)zbuf) = zAccum;
  353. #if (BPP == 8)
  354. *pPix = (BYTE)(color1 >> 16);
  355. #elif (BPP == 16)
  356. *((WORD *)pPix) = (WORD)color3;
  357. #elif (BPP == 24)
  358. *pPix = (BYTE)color3;
  359. *(pPix + 1) = (BYTE)(color3 >> 8);
  360. *(pPix + 2) = (BYTE)(color3 >> 16);
  361. #else
  362. *((DWORD *)pPix) = color3;
  363. #endif
  364. }
  365. pPix += (BPP / 8);
  366. if (--count <= 0)
  367. break;
  368. zbuf+=4;
  369. zAccum += zDelta;
  370. if ( zAccum <= *((GLuint*)zbuf) ) {
  371. *((GLuint*)zbuf) = zAccum;
  372. #if (BPP == 8)
  373. *pPix = (BYTE)(color1 >> 24);
  374. #elif (BPP == 16)
  375. *((WORD *)pPix) = (WORD)color4;
  376. #elif (BPP == 24)
  377. *pPix = (BYTE)color4;
  378. *(pPix + 1) = (BYTE)(color4 >> 8);
  379. *(pPix + 2) = (BYTE)(color4 >> 16);
  380. #else
  381. *((DWORD *)pPix) = color4;
  382. #endif
  383. }
  384. pPix += (BPP / 8);
  385. if (--count <= 0)
  386. break;
  387. zAccum += zDelta;
  388. zbuf+=4;
  389. }
  390. #else //!DITHER
  391. for (; count; count--) {
  392. if ( zAccum <= *((GLuint*)zbuf) ) {
  393. *((GLuint*)zbuf) = zAccum;
  394. #if (BPP == 8)
  395. *pPix = (BYTE)color1;
  396. #elif (BPP == 16)
  397. *((WORD *)pPix) = (WORD)color1;
  398. #elif (BPP == 24)
  399. *pPix = (BYTE)color1;
  400. *(pPix + 1) = (BYTE)color2;
  401. *(pPix + 2) = (BYTE)color3;
  402. #else
  403. *((DWORD *)pPix) = color1;
  404. #endif //BPP
  405. }
  406. zbuf+=4;
  407. zAccum += zDelta;
  408. pPix += (BPP / 8);
  409. }
  410. #endif //!DITHER
  411. }
  412. } else { // !FASTZBUFFER
  413. LONG totalCount;
  414. ULONG *pMask = gengc->gc.polygon.shader.stipplePat;
  415. for (totalCount = gengc->gc.polygon.shader.length; totalCount > 0; totalCount -= 32) {
  416. ULONG mask;
  417. ULONG maskTest;
  418. if ((mask = *pMask++) == 0) {
  419. pPix += (32 * (BPP / 8));
  420. continue;
  421. }
  422. maskTest = 0x80000000;
  423. if ((count = totalCount) > 32)
  424. count = 32;
  425. #if DITHER
  426. for (;;) {
  427. if (mask & maskTest) {
  428. #if (BPP == 8)
  429. *pPix = (BYTE)color1;
  430. #elif (BPP == 16)
  431. *((WORD *)pPix) = (WORD)color1;
  432. #elif (BPP == 24)
  433. *pPix = (BYTE)color1;
  434. *(pPix + 1) = (BYTE)(color1 >> 8);
  435. *(pPix + 2) = (BYTE)(color1 >> 16);
  436. #else
  437. *((DWORD *)pPix) = color1;
  438. #endif
  439. }
  440. pPix += (BPP / 8);
  441. if (--count <= 0)
  442. break;
  443. maskTest >>= 1;
  444. if (mask & maskTest) {
  445. #if (BPP == 8)
  446. *pPix = (BYTE)(color1 >> 8);
  447. #elif (BPP == 16)
  448. *((WORD *)pPix) = (WORD)color2;
  449. #elif (BPP == 24)
  450. *pPix = (BYTE)color2;
  451. *(pPix + 1) = (BYTE)(color2 >> 8);
  452. *(pPix + 2) = (BYTE)(color2 >> 16);
  453. #else
  454. *((DWORD *)pPix) = color2;
  455. #endif
  456. }
  457. pPix += (BPP / 8);
  458. if (--count <= 0)
  459. break;
  460. maskTest >>= 1;
  461. if (mask & maskTest) {
  462. #if (BPP == 8)
  463. *pPix = (BYTE)(color1 >> 16);
  464. #elif (BPP == 16)
  465. *((WORD *)pPix) = (WORD)color3;
  466. #elif (BPP == 24)
  467. *pPix = (BYTE)color3;
  468. *(pPix + 1) = (BYTE)(color3 >> 8);
  469. *(pPix + 2) = (BYTE)(color3 >> 16);
  470. #else
  471. *((DWORD *)pPix) = color3;
  472. #endif
  473. }
  474. pPix += (BPP / 8);
  475. if (--count <= 0)
  476. break;
  477. maskTest >>= 1;
  478. if (mask & maskTest) {
  479. #if (BPP == 8)
  480. *pPix = (BYTE)(color1 >> 24);
  481. #elif (BPP == 16)
  482. *((WORD *)pPix) = (WORD)color4;
  483. #elif (BPP == 24)
  484. *pPix = (BYTE)color4;
  485. *(pPix + 1) = (BYTE)(color4 >> 8);
  486. *(pPix + 2) = (BYTE)(color4 >> 16);
  487. #else
  488. *((DWORD *)pPix) = color4;
  489. #endif
  490. }
  491. pPix += (BPP / 8);
  492. if (--count <= 0)
  493. break;
  494. #if ZBUFFER
  495. maskTest >>= 1;
  496. #else
  497. zAccum += zDelta;
  498. zbuf++;
  499. #endif
  500. }
  501. #else //!DITHER
  502. #if (BPP == 8)
  503. if (mask == 0xffffffff) {
  504. RtlFillMemory(pPix, count, color1);
  505. pPix += (32 * (BPP / 8));
  506. continue;
  507. }
  508. #elif (BPP == 16)
  509. if (mask == 0xffffffff) {
  510. LONG ddCount;
  511. if ((ULONG_PTR)pPix & 0x2) { // get odd-start pixel
  512. *((WORD *)pPix)++ = (WORD)color1;
  513. if (--count <= 0)
  514. return;
  515. }
  516. if (ddCount = (count & (~1)) << 1) { // fill DWORDs
  517. RtlFillMemoryUlong(pPix, ddCount, color1);
  518. pPix += ddCount;
  519. }
  520. if (count & 1) // get odd-end pixel
  521. *((WORD *)pPix)++ = (WORD)color1;
  522. continue;
  523. }
  524. #elif (BPP == 24)
  525. if (mask == 0xffffffff) {
  526. ULONG colorShr = color1 >> 8;
  527. LONG i;
  528. for (i = 0; i < count; i++, pPix += 3) {
  529. *pPix = (BYTE)color1;
  530. *(pPix + 1) = (BYTE)color2;
  531. *(pPix + 2) = (BYTE)color3;
  532. }
  533. continue;
  534. }
  535. #elif (BPP == 32)
  536. if (mask == 0xffffffff) {
  537. RtlFillMemoryUlong(pPix, count << 2, color1);
  538. pPix += (32 * (BPP / 8));
  539. continue;
  540. }
  541. #endif //BPP
  542. for (; count; count--) {
  543. if (mask & maskTest) {
  544. #if (BPP == 8)
  545. *pPix = (BYTE)color1;
  546. #elif (BPP == 16)
  547. *((WORD *)pPix) = (WORD)color1;
  548. #elif (BPP == 24)
  549. *pPix = (BYTE)color1;
  550. *(pPix + 1) = (BYTE)color2;
  551. *(pPix + 2) = (BYTE)color3;
  552. #else
  553. *((DWORD *)pPix) = color1;
  554. #endif //BPP
  555. }
  556. maskTest >>= 1;
  557. pPix += (BPP / 8);
  558. }
  559. #endif //!DITHER
  560. }
  561. }
  562. #else // !ZBUFFER
  563. {
  564. LONG totalCount = gengc->gc.polygon.shader.length;
  565. #if DITHER
  566. #if (BPP == 8)
  567. LONG i;
  568. if (totalCount < 7) {
  569. *pPix++ = (BYTE)color1;
  570. if (--totalCount <= 0)
  571. return;
  572. *pPix++ = (BYTE)(color1 >> 8);
  573. if (--totalCount <= 0)
  574. return;
  575. *pPix++ = (BYTE)(color1 >> 16);
  576. if (--totalCount <= 0)
  577. return;
  578. *pPix++ = (BYTE)(color1 >> 24);
  579. if (--totalCount <= 0)
  580. return;
  581. *pPix++ = (BYTE)color1;
  582. if (--totalCount <= 0)
  583. return;
  584. *pPix = (BYTE)(color1 >> 8);
  585. return;
  586. }
  587. if (i = (LONG)((ULONG_PTR)pPix & 0x3)) {
  588. i = ditherShift = (4 - i);
  589. totalCount -= i;
  590. if (i--) {
  591. *pPix++ = (BYTE)color1;
  592. if (i--) {
  593. *pPix++ = (BYTE)(color1 >> 8);
  594. if (i--) {
  595. *pPix++ = (BYTE)(color1 >> 16);
  596. }
  597. }
  598. }
  599. // re-align the dither colors for DWORD boundaries
  600. ditherShift <<= 3;
  601. color1 = (color1 >> ditherShift) |
  602. (color1 << (32 - ditherShift));
  603. }
  604. RtlFillMemoryUlong(pPix, totalCount, color1);
  605. pPix += (totalCount & 0xfffffffc);
  606. i = totalCount & 0x3;
  607. if (i--) {
  608. *pPix++ = (BYTE)color1;
  609. if (i--) {
  610. *pPix++ = (BYTE)(color1 >> 8);
  611. if (i--) {
  612. *pPix++ = (BYTE)(color1 >> 16);
  613. }
  614. }
  615. }
  616. return;
  617. #elif (BPP == 16)
  618. ULONG colorA, colorB;
  619. LONG i;
  620. if (totalCount < 3) {
  621. *((WORD *)pPix)++ = (WORD)color1;
  622. if (--totalCount <= 0)
  623. return;
  624. *((WORD *)pPix)++ = (WORD)color2;
  625. return;
  626. }
  627. if ((ULONG_PTR)pPix & 0x2) {
  628. totalCount--;
  629. *((WORD *)pPix)++ = (WORD)color1;
  630. colorA = color2 | (color3 << 16);
  631. colorB = color4 | (color1 << 16);
  632. } else {
  633. colorA = color1 | (color2 << 16);
  634. colorB = color3 | (color4 << 16);
  635. }
  636. for (i = (totalCount >> 1);;) {
  637. *((DWORD *)pPix)++ = colorA;
  638. if (--i <= 0) {
  639. if (totalCount & 1)
  640. *((WORD *)pPix) = (WORD)colorB;
  641. return;
  642. }
  643. *((DWORD *)pPix)++ = colorB;
  644. if (--i <= 0) {
  645. if (totalCount & 1)
  646. *((WORD *)pPix) = (WORD)colorA;
  647. return;
  648. }
  649. }
  650. #elif (BPP == 24)
  651. for (;;pPix += 12) {
  652. *pPix = (BYTE)color1;
  653. *(pPix + 1) = (BYTE)(color1 >> 8);
  654. *(pPix + 2) = (BYTE)(color1 >> 16);
  655. if (--totalCount <= 0)
  656. return;
  657. *(pPix + 3) = (BYTE)color2;
  658. *(pPix + 4) = (BYTE)(color2 >> 8);
  659. *(pPix + 5) = (BYTE)(color2 >> 16);
  660. if (--totalCount <= 0)
  661. return;
  662. *(pPix + 6) = (BYTE)color3;
  663. *(pPix + 7) = (BYTE)(color3 >> 8);
  664. *(pPix + 8) = (BYTE)(color3 >> 16);
  665. if (--totalCount <= 0)
  666. return;
  667. *(pPix + 9) = (BYTE)color4;
  668. *(pPix + 10) = (BYTE)(color4 >> 8);
  669. *(pPix + 11) = (BYTE)(color4 >> 16);
  670. if (--totalCount <= 0)
  671. return;
  672. }
  673. #elif (BPP == 32)
  674. for (;;pPix += 16) {
  675. *((DWORD *)pPix) = color1;
  676. if (--totalCount <= 0)
  677. return;
  678. *((DWORD *)(pPix + 4)) = color2;
  679. if (--totalCount <= 0)
  680. return;
  681. *((DWORD *)(pPix + 8)) = color3;
  682. if (--totalCount <= 0)
  683. return;
  684. *((DWORD *)(pPix + 12)) = color4;
  685. if (--totalCount <= 0)
  686. return;
  687. }
  688. #endif //BPP
  689. #else //!DITHER
  690. #if (BPP == 8)
  691. RtlFillMemory(pPix, totalCount, color1);
  692. return;
  693. #elif (BPP == 16)
  694. if ((ULONG_PTR)pPix & 0x2) { // get odd-start pixel
  695. *((WORD *)pPix)++ = (WORD)color1;
  696. if (--totalCount <= 0)
  697. return;
  698. }
  699. if (count = (totalCount & (~1)) << 1)
  700. RtlFillMemoryUlong(pPix, count, color1);
  701. if (totalCount & 1) // get odd-end pixel
  702. *((WORD *)(pPix + count)) = (WORD)color1;
  703. return;
  704. #elif (BPP == 24)
  705. LONG i;
  706. for (i = 0; i < totalCount; i++, pPix += 3) {
  707. *pPix = (BYTE)color1;
  708. *(pPix + 1) = (BYTE)(color2);
  709. *(pPix + 2) = (BYTE)(color3);
  710. }
  711. return;
  712. #elif (BPP == 32)
  713. RtlFillMemoryUlong(pPix, totalCount << 2, color1);
  714. return;
  715. #endif //BPP
  716. #endif //!DITHER
  717. }
  718. #endif // !ZBUFFER
  719. }