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.

214 lines
7.4 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 "cbufwrt.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 C_BufWrite_B8G8R8X8_NoDither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  22. {
  23. // Must write 0 for the unspecified alpha channel to be compatible with DX5
  24. // for destination color keying
  25. UINT32 uARGB = RGBA_MAKE(pCtx->SI.uBR>>8, pCtx->SI.uBG>>8,
  26. pCtx->SI.uBB>>8, 0x00);
  27. PUINT32 pSurface = (PUINT32)pS->pSurface;
  28. *pSurface = uARGB;
  29. // just returns for C, since we really can't loop with function calls
  30. }
  31. //-----------------------------------------------------------------------------
  32. //
  33. // Write_B8G8R8A8_NoDither
  34. //
  35. // Writes output in BGRA-8888 format.
  36. //
  37. //-----------------------------------------------------------------------------
  38. void C_BufWrite_B8G8R8A8_NoDither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  39. {
  40. UINT32 uARGB = RGBA_MAKE(pCtx->SI.uBR>>8, pCtx->SI.uBG>>8,
  41. pCtx->SI.uBB>>8, pCtx->SI.uBA>>8);
  42. PUINT32 pSurface = (PUINT32)pS->pSurface;
  43. *pSurface = uARGB;
  44. // just returns for C, since we really can't loop with function calls
  45. }
  46. //-----------------------------------------------------------------------------
  47. //
  48. // Write_B5G6R5_NoDither
  49. //
  50. // Writes output in BGR-565 format.
  51. //
  52. //-----------------------------------------------------------------------------
  53. void C_BufWrite_B5G6R5_NoDither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  54. {
  55. *(PUINT16)pS->pSurface =
  56. ((pCtx->SI.uBR >> 0) & 0xf800) |
  57. ((pCtx->SI.uBG >> 5) & 0x07e0) |
  58. ((pCtx->SI.uBB >> 11) & 0x001f);
  59. // just returns for C, since we really can't loop with function calls
  60. }
  61. //-----------------------------------------------------------------------------
  62. //
  63. // Write_B5G6R5_Dither
  64. //
  65. // Writes output in BGR-565 format, dithered.
  66. //
  67. //-----------------------------------------------------------------------------
  68. void C_BufWrite_B5G6R5_Dither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  69. {
  70. UINT16 uDither = g_uDitherTable[pCtx->SI.uDitherOffset];
  71. UINT16 uB = pCtx->SI.uBB >> 3; // 8.8 >> 3 = 8.5
  72. UINT16 uG = pCtx->SI.uBG >> 2;
  73. UINT16 uR = pCtx->SI.uBR >> 3;
  74. uB = min((uB >> 8) + ((uB & 0xff) > uDither), 0x1f);
  75. uG = min((uG >> 8) + ((uG & 0xff) > uDither), 0x3f);
  76. uR = min((uR >> 8) + ((uR & 0xff) > uDither), 0x1f);
  77. *(PUINT16)pS->pSurface = uB | (uG << 5) | (uR << 11);
  78. // just returns for C, since we really can't loop with function calls
  79. }
  80. //-----------------------------------------------------------------------------
  81. //
  82. // Write_B5G5R5_NoDither
  83. //
  84. // Writes output in BGR-555 format.
  85. //
  86. //-----------------------------------------------------------------------------
  87. void C_BufWrite_B5G5R5_NoDither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  88. {
  89. // Must write 0 for the unspecified alpha channel to be compatible with DX5
  90. // for destination color keying
  91. *(PUINT16)pS->pSurface =
  92. ((pCtx->SI.uBR >> 1) & 0x7c00) |
  93. ((pCtx->SI.uBG >> 6) & 0x03e0) |
  94. ((pCtx->SI.uBB >> 11) & 0x001f);
  95. // just returns for C, since we really can't loop with function calls
  96. }
  97. //-----------------------------------------------------------------------------
  98. //
  99. // Write_B5G5R5_Dither
  100. //
  101. // Writes output in BGR-555 format, dithered.
  102. //
  103. //-----------------------------------------------------------------------------
  104. void C_BufWrite_B5G5R5_Dither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  105. {
  106. UINT16 uDither = g_uDitherTable[pCtx->SI.uDitherOffset];
  107. UINT16 uB = pCtx->SI.uBB >> 3; // 8.8 >> 3 = 8.5
  108. UINT16 uG = pCtx->SI.uBG >> 3;
  109. UINT16 uR = pCtx->SI.uBR >> 3;
  110. uB = min((uB >> 8) + ((uB & 0xff) > uDither), 0x1f);
  111. uG = min((uG >> 8) + ((uG & 0xff) > uDither), 0x1f);
  112. uR = min((uR >> 8) + ((uR & 0xff) > uDither), 0x1f);
  113. // Must write 0 for the unspecified alpha channel to be compatible with DX5
  114. // for destination color keying
  115. *(PUINT16)pS->pSurface = uB | (uG << 5) | (uR << 10);
  116. // just returns for C, since we really can't loop with function calls
  117. }
  118. //-----------------------------------------------------------------------------
  119. //
  120. // Write_B5G5R5A1_NoDither
  121. //
  122. // Writes output in BGRA-1555 format.
  123. //
  124. //-----------------------------------------------------------------------------
  125. void C_BufWrite_B5G5R5A1_NoDither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  126. {
  127. *(PUINT16)pS->pSurface =
  128. ((pCtx->SI.uBR >> 1) & 0x7c00) |
  129. ((pCtx->SI.uBG >> 6) & 0x03e0) |
  130. ((pCtx->SI.uBB >> 11) & 0x001f) |
  131. ((pCtx->SI.uBA >> 0) & 0x8000);
  132. // just returns for C, since we really can't loop with function calls
  133. }
  134. //-----------------------------------------------------------------------------
  135. //
  136. // Write_B5G5R5A1_Dither
  137. //
  138. // Writes output in BGRA-1555 format, dithered.
  139. //
  140. //-----------------------------------------------------------------------------
  141. void C_BufWrite_B5G5R5A1_Dither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  142. {
  143. UINT16 uDither = g_uDitherTable[pCtx->SI.uDitherOffset];
  144. UINT16 uB = pCtx->SI.uBB >> 3; // 8.8 >> 3 = 8.5
  145. UINT16 uG = pCtx->SI.uBG >> 3;
  146. UINT16 uR = pCtx->SI.uBR >> 3;
  147. uB = min((uB >> 8) + ((uB & 0xff) > uDither), 0x1f);
  148. uG = min((uG >> 8) + ((uG & 0xff) > uDither), 0x1f);
  149. uR = min((uR >> 8) + ((uR & 0xff) > uDither), 0x1f);
  150. *(PUINT16)pS->pSurface = uB | (uG << 5) | (uR << 10) | (pCtx->SI.uBA & 0x8000);
  151. // just returns for C, since we really can't loop with function calls
  152. }
  153. //-----------------------------------------------------------------------------
  154. //
  155. // Write_B8G8R8_NoDither
  156. //
  157. // Writes output in BGR-888 format.
  158. //
  159. //-----------------------------------------------------------------------------
  160. void C_BufWrite_B8G8R8_NoDither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  161. {
  162. PUINT8 pSurface = (PUINT8)pS->pSurface;
  163. *pSurface++ = pCtx->SI.uBB>>8;
  164. *pSurface++ = pCtx->SI.uBG>>8;
  165. *pSurface++ = pCtx->SI.uBR>>8;
  166. // just returns for C, since we really can't loop with function calls
  167. }
  168. //-----------------------------------------------------------------------------
  169. //
  170. // Write_Palette8_NoDither
  171. //
  172. // Writes output to the RGB8 palette format.
  173. //
  174. //-----------------------------------------------------------------------------
  175. void C_BufWrite_Palette8_NoDither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  176. {
  177. UINT16 uMapIdx = MAKE_RGB8(pCtx->SI.uBR>>8, pCtx->SI.uBG>>8, pCtx->SI.uBB>>8);
  178. *(PUINT8)pS->pSurface = (UINT8)(pCtx->pRampMap[uMapIdx]);
  179. // just returns for C, since we really can't loop with function calls
  180. }