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.

208 lines
7.1 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // This file contains the output buffer color writing routines.
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997.
  6. //
  7. //-----------------------------------------------------------------------------
  8. #include "pch.cpp"
  9. #pragma hdrstop
  10. #include "mbufwrt.h"
  11. // Names are read LSB to MSB, so B5G6R5 means five bits of blue starting
  12. // at the LSB, then six bits of green, then five bits of red.
  13. extern UINT16 g_uDitherTable[16];
  14. //-----------------------------------------------------------------------------
  15. //
  16. // Write_B8G8R8X8_NoDither
  17. //
  18. // Writes output in BGR-888 format, aligned to 32 bits.
  19. //
  20. //-----------------------------------------------------------------------------
  21. void CMMX_BufWrite_B8G8R8X8_NoDither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  22. {
  23. UINT32 uARGB = RGBA_MAKE(pCtx->SI.uBR>>8, pCtx->SI.uBG>>8,
  24. pCtx->SI.uBB>>8, 0xff);
  25. PUINT32 pSurface = (PUINT32)pS->pSurface;
  26. *pSurface = uARGB;
  27. // just returns for C, since we really can't loop with function calls
  28. }
  29. //-----------------------------------------------------------------------------
  30. //
  31. // Write_B8G8R8A8_NoDither
  32. //
  33. // Writes output in BGRA-8888 format.
  34. //
  35. //-----------------------------------------------------------------------------
  36. void CMMX_BufWrite_B8G8R8A8_NoDither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  37. {
  38. UINT32 uARGB = RGBA_MAKE(pCtx->SI.uBR>>8, pCtx->SI.uBG>>8,
  39. pCtx->SI.uBB>>8, pCtx->SI.uBA>>8);
  40. PUINT32 pSurface = (PUINT32)pS->pSurface;
  41. *pSurface = uARGB;
  42. // just returns for C, since we really can't loop with function calls
  43. }
  44. //-----------------------------------------------------------------------------
  45. //
  46. // Write_B5G6R5_NoDither
  47. //
  48. // Writes output in BGR-565 format.
  49. //
  50. //-----------------------------------------------------------------------------
  51. void CMMX_BufWrite_B5G6R5_NoDither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  52. {
  53. *(PUINT16)pS->pSurface =
  54. ((pCtx->SI.uBR >> 0) & 0xf800) |
  55. ((pCtx->SI.uBG >> 5) & 0x07e0) |
  56. ((pCtx->SI.uBB >> 11) & 0x001f);
  57. // just returns for C, since we really can't loop with function calls
  58. }
  59. //-----------------------------------------------------------------------------
  60. //
  61. // Write_B5G6R5_Dither
  62. //
  63. // Writes output in BGR-565 format, dithered.
  64. //
  65. //-----------------------------------------------------------------------------
  66. void CMMX_BufWrite_B5G6R5_Dither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  67. {
  68. UINT16 uDither = g_uDitherTable[pCtx->SI.uDitherOffset];
  69. UINT16 uB = pCtx->SI.uBB >> 3; // 8.8 >> 3 = 8.5
  70. UINT16 uG = pCtx->SI.uBG >> 2;
  71. UINT16 uR = pCtx->SI.uBR >> 3;
  72. uB = min((uB >> 8) + ((uB & 0xff) > uDither), 0x1f);
  73. uG = min((uG >> 8) + ((uG & 0xff) > uDither), 0x3f);
  74. uR = min((uR >> 8) + ((uR & 0xff) > uDither), 0x1f);
  75. *(PUINT16)pS->pSurface = uB | (uG << 5) | (uR << 11);
  76. // just returns for C, since we really can't loop with function calls
  77. }
  78. //-----------------------------------------------------------------------------
  79. //
  80. // Write_B5G5R5_NoDither
  81. //
  82. // Writes output in BGR-555 format.
  83. //
  84. //-----------------------------------------------------------------------------
  85. void CMMX_BufWrite_B5G5R5_NoDither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  86. {
  87. *(PUINT16)pS->pSurface =
  88. ((pCtx->SI.uBR >> 1) & 0x7c00) |
  89. ((pCtx->SI.uBG >> 6) & 0x03e0) |
  90. ((pCtx->SI.uBB >> 11) & 0x001f) |
  91. 0x8000;
  92. // just returns for C, since we really can't loop with function calls
  93. }
  94. //-----------------------------------------------------------------------------
  95. //
  96. // Write_B5G5R5_Dither
  97. //
  98. // Writes output in BGR-555 format, dithered.
  99. //
  100. //-----------------------------------------------------------------------------
  101. void CMMX_BufWrite_B5G5R5_Dither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  102. {
  103. UINT16 uDither = g_uDitherTable[pCtx->SI.uDitherOffset];
  104. UINT16 uB = pCtx->SI.uBB >> 3; // 8.8 >> 3 = 8.5
  105. UINT16 uG = pCtx->SI.uBG >> 3;
  106. UINT16 uR = pCtx->SI.uBR >> 3;
  107. uB = min((uB >> 8) + ((uB & 0xff) > uDither), 0x1f);
  108. uG = min((uG >> 8) + ((uG & 0xff) > uDither), 0x1f);
  109. uR = min((uR >> 8) + ((uR & 0xff) > uDither), 0x1f);
  110. *(PUINT16)pS->pSurface = uB | (uG << 5) | (uR << 10) | 0x8000;
  111. // just returns for C, since we really can't loop with function calls
  112. }
  113. //-----------------------------------------------------------------------------
  114. //
  115. // Write_B5G5R5A1_NoDither
  116. //
  117. // Writes output in BGRA-1555 format.
  118. //
  119. //-----------------------------------------------------------------------------
  120. void CMMX_BufWrite_B5G5R5A1_NoDither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  121. {
  122. *(PUINT16)pS->pSurface =
  123. ((pCtx->SI.uBR >> 1) & 0x7c00) |
  124. ((pCtx->SI.uBG >> 6) & 0x03e0) |
  125. ((pCtx->SI.uBB >> 11) & 0x001f) |
  126. ((pCtx->SI.uBA >> 0) & 0x8000);
  127. // just returns for C, since we really can't loop with function calls
  128. }
  129. //-----------------------------------------------------------------------------
  130. //
  131. // Write_B5G5R5A1_Dither
  132. //
  133. // Writes output in BGRA-1555 format, dithered.
  134. //
  135. //-----------------------------------------------------------------------------
  136. void CMMX_BufWrite_B5G5R5A1_Dither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  137. {
  138. UINT16 uDither = g_uDitherTable[pCtx->SI.uDitherOffset];
  139. UINT16 uB = pCtx->SI.uBB >> 3; // 8.8 >> 3 = 8.5
  140. UINT16 uG = pCtx->SI.uBG >> 3;
  141. UINT16 uR = pCtx->SI.uBR >> 3;
  142. uB = min((uB >> 8) + ((uB & 0xff) > uDither), 0x1f);
  143. uG = min((uG >> 8) + ((uG & 0xff) > uDither), 0x1f);
  144. uR = min((uR >> 8) + ((uR & 0xff) > uDither), 0x1f);
  145. *(PUINT16)pS->pSurface = uB | (uG << 5) | (uR << 10) | (pCtx->SI.uBA & 0x8000);
  146. // just returns for C, since we really can't loop with function calls
  147. }
  148. //-----------------------------------------------------------------------------
  149. //
  150. // Write_B8G8R8_NoDither
  151. //
  152. // Writes output in BGR-888 format.
  153. //
  154. //-----------------------------------------------------------------------------
  155. void CMMX_BufWrite_B8G8R8_NoDither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  156. {
  157. PUINT8 pSurface = (PUINT8)pS->pSurface;
  158. *pSurface++ = pCtx->SI.uBB>>8;
  159. *pSurface++ = pCtx->SI.uBG>>8;
  160. *pSurface++ = pCtx->SI.uBR>>8;
  161. // just returns for C, since we really can't loop with function calls
  162. }
  163. //-----------------------------------------------------------------------------
  164. //
  165. // Write_Palette8_NoDither
  166. //
  167. // Writes output to the RGB8 palette format.
  168. //
  169. //-----------------------------------------------------------------------------
  170. void CMMX_BufWrite_Palette8_NoDither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  171. {
  172. UINT16 uMapIdx = MAKE_RGB8(pCtx->SI.uBR>>8, pCtx->SI.uBG>>8, pCtx->SI.uBB>>8);
  173. *(PUINT8)pS->pSurface = (UINT8)(pCtx->pRampMap[uMapIdx]);
  174. // just returns for C, since we really can't loop with function calls
  175. }