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.

230 lines
6.8 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // This file contains texture read functions.
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997.
  6. //
  7. //-----------------------------------------------------------------------------
  8. include(`m4hdr.mh')dnl
  9. #include "pch.cpp"
  10. #pragma hdrstop
  11. #include "ctxrd_mh.h"
  12. // Names are read LSB to MSB, so B5G6R5 means five bits of blue starting
  13. // at the LSB, then six bits of green, then five bits of red.
  14. dnl
  15. dnl d_DoTex
  16. dnl
  17. dnl Calls the macro in $1 with all options to generate differentiated texture
  18. dnl read functions
  19. dnl
  20. define(`d_DoTex', `d_Null($1(NoBorder, NoColorKey))
  21. d_Null($1(NoBorder, ColorKey))
  22. d_Null($1(Border, NoColorKey))
  23. d_Null($1(Border, ColorKey))')dnl
  24. dnl
  25. dnl d_DoBorder
  26. dnl
  27. dnl Inserts conditional border code
  28. dnl
  29. define(`d_DoBorder', `ifelse(`$1', `NoBorder', `', `
  30. if ((iU < 0) || (iV < 0))
  31. {
  32. return pTex->BorderColor;
  33. }')')dnl
  34. dnl
  35. dnl d_DoColorKey
  36. dnl
  37. dnl Inserts conditional color key code
  38. dnl $1 the function type, $2 is the thing to test against the Transparent color,
  39. dnl and $3 is its type.
  40. dnl
  41. define(`d_DoColorKey', `ifelse(`$1', `NoColorKey', `', `
  42. if ($2 == $3pTex->TransparentColor)
  43. {
  44. Color &= 0xffffff;
  45. }')')dnl
  46. dnl
  47. define(`d_B8G8R8', `
  48. D3DCOLOR C_TexRead_B8G8R8_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  49. {
  50. d_DoBorder(`$1')
  51. UINT32 uTexel = ((UINT32*)pBits)[iU | (iV << iShiftU)];
  52. D3DCOLOR Color = uTexel | 0xff000000;
  53. d_DoColorKey(`$2', uTexel)
  54. return Color;
  55. }')dnl
  56. d_DoTex(`d_B8G8R8')
  57. dnl
  58. define(`d_B8G8R8A8', `
  59. D3DCOLOR C_TexRead_B8G8R8A8_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  60. {
  61. d_DoBorder(`$1')
  62. D3DCOLOR Color = ((D3DCOLOR*)pBits)[iU | (iV << iShiftU)];
  63. d_DoColorKey(`$2', Color)
  64. return Color;
  65. }')dnl
  66. d_DoTex(`d_B8G8R8A8')
  67. dnl
  68. define(`d_B5G6R5', `
  69. D3DCOLOR C_TexRead_B5G6R5_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  70. {
  71. d_DoBorder(`$1')
  72. UINT16 uTexel = ((UINT16*)pBits)[iU | (iV << iShiftU)];
  73. D3DCOLOR Color = RGBA_MAKE(( uTexel >> 8 ) & 0xf8,
  74. (( uTexel >> 3) & 0xfc ),
  75. (( uTexel << 3) & 0xf8 ),
  76. 0xff);
  77. d_DoColorKey(`$2', uTexel, `(UINT16)')
  78. return Color;
  79. }')dnl
  80. d_DoTex(`d_B5G6R5')
  81. dnl
  82. define(`d_B5G5R5', `
  83. D3DCOLOR C_TexRead_B5G5R5_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  84. {
  85. d_DoBorder(`$1')
  86. UINT16 uTexel = ((UINT16*)pBits)[iU | (iV << iShiftU)];
  87. D3DCOLOR Color = RGBA_MAKE(( uTexel >> 7 ) & 0xf8,
  88. (( uTexel >> 2) & 0xf8 ),
  89. (( uTexel << 3) & 0xf8 ),
  90. 0xff);
  91. d_DoColorKey(`$2', uTexel, `(UINT16)')
  92. return Color;
  93. }')dnl
  94. d_DoTex(`d_B5G5R5')
  95. dnl
  96. define(`d_B5G5R5A1', `
  97. D3DCOLOR C_TexRead_B5G5R5A1_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  98. {
  99. d_DoBorder(`$1')
  100. INT16 iTexel = ((INT16*)pBits)[iU | (iV << iShiftU)];
  101. D3DCOLOR Color = RGBA_MAKE(( iTexel >> 7 ) & 0xf8,
  102. (( iTexel >> 2) & 0xf8 ),
  103. (( iTexel << 3) & 0xf8 ),
  104. (iTexel >> 15) & 0xff);
  105. d_DoColorKey(`$2', iTexel, `(INT16)')
  106. return Color;
  107. }')dnl
  108. d_DoTex(`d_B5G5R5A1')
  109. dnl
  110. // An alpha of 0xf becomes 0xff, 0x0 becomes 0x0, and it is monotonic.
  111. // May want to apply this operation to all color channels
  112. define(`d_B4G4R4A4', `
  113. D3DCOLOR C_TexRead_B4G4R4A4_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  114. {
  115. d_DoBorder(`$1')
  116. INT16 iTexel = ((INT16*)pBits)[iU | (iV << iShiftU)];
  117. INT16 iAlpha = ( iTexel >> 12 ) & 0xf;
  118. D3DCOLOR Color = RGBA_MAKE((( iTexel >> 4 ) & 0xf0),
  119. (( iTexel >> 0) & 0xf0 ),
  120. (( iTexel << 4) & 0xf0 ),
  121. (iAlpha << 4) | iAlpha );
  122. d_DoColorKey(`$2', iTexel, `(INT16)')
  123. return Color;
  124. }')dnl
  125. d_DoTex(`d_B4G4R4A4')
  126. dnl
  127. define(`d_L8', `
  128. D3DCOLOR C_TexRead_L8_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  129. {
  130. d_DoBorder(`$1')
  131. UINT8 uTexel = ((UINT8*)pBits)[iU | (iV << iShiftU)];
  132. D3DCOLOR Color = RGBA_MAKE(uTexel,
  133. uTexel,
  134. uTexel,
  135. 0xff );
  136. d_DoColorKey(`$2', uTexel, `(UINT8)')
  137. return Color;
  138. }')dnl
  139. d_DoTex(`d_L8')
  140. dnl
  141. define(`d_L8A8', `
  142. D3DCOLOR C_TexRead_L8A8_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  143. {
  144. d_DoBorder(`$1')
  145. UINT16 uTexel = ((UINT16*)pBits)[iU | (iV << iShiftU)];
  146. UINT16 uAlpha = ( uTexel >> 8 ) & 0xff;
  147. UINT16 uTexel8 = uTexel & 0xff;
  148. D3DCOLOR Color = RGBA_MAKE(uTexel8,
  149. uTexel8,
  150. uTexel8,
  151. uAlpha );
  152. d_DoColorKey(`$2', uTexel, `(UINT16)')
  153. return Color;
  154. }')dnl
  155. d_DoTex(`d_L8A8')
  156. dnl
  157. dnl
  158. dnl
  159. dnl d_CheckPalette4
  160. dnl
  161. dnl Index computation for palette4, otherwise just retrieve iTexel for palette8
  162. dnl $1 the function type,
  163. dnl
  164. define(`d_CheckPalette4', `ifelse(eval(d_index(`$1', `Palette4') >= 0), `1', `
  165. INT32 iTexel = pBits[iIndex>>1];
  166. if ((iIndex & 1) == 0)
  167. {
  168. iTexel &= 0xf;
  169. }
  170. else
  171. {
  172. iTexel >>= 4;
  173. }', `
  174. INT32 iTexel = pBits[iIndex];')')dnl
  175. dnl
  176. dnl
  177. dnl
  178. dnl d_DoPaletteAlpha
  179. dnl
  180. dnl Check if palette has alpha
  181. dnl $1 the function type,
  182. dnl
  183. define(`d_DoPaletteAlpha', `ifelse(eval(d_index(`$1', `A') >= 0), `1', `
  184. Color = RGBA_MAKE((Color & 0xff),
  185. (Color >> 8) & 0xff,
  186. (Color >> 16) & 0xff,
  187. (Color >> 24) & 0xff);', `
  188. Color = RGBA_MAKE((Color & 0xff),
  189. (Color >> 8) & 0xff,
  190. (Color >> 16) & 0xff,
  191. 0xff);')')dnl
  192. dnl
  193. define(`d_Palette', `
  194. d_DoBorder(`$1')
  195. INT32 iIndex = iU | (iV << iShiftU);
  196. d_CheckPalette4(`$3')
  197. D3DCOLOR Color = pTex->pPalette[iTexel];
  198. // RL palette is BGR - flip the channels into RGB
  199. d_DoPaletteAlpha(`$3')
  200. d_DoColorKey(`$2', iTexel, `(INT32)')
  201. return Color;
  202. ')dnl
  203. dnl
  204. define(`d_Palette8', `
  205. D3DCOLOR C_TexRead_Palette8_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  206. {
  207. d_Palette($1, $2, Palette8)
  208. }')dnl
  209. d_DoTex(`d_Palette8')
  210. define(`d_Palette4', `
  211. D3DCOLOR C_TexRead_Palette4_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  212. {
  213. d_Palette($1, $2, Palette4)
  214. }')dnl
  215. d_DoTex(`d_Palette4')
  216. dnl
  217. define(`d_Palette8A', `
  218. D3DCOLOR C_TexRead_Palette8A_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  219. {
  220. d_Palette($1, $2, Palette8A)
  221. }')dnl
  222. d_DoTex(`d_Palette8A')
  223. define(`d_Palette4A', `
  224. D3DCOLOR C_TexRead_Palette4A_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  225. {
  226. d_Palette($1, $2, Palette4A)
  227. }')dnl
  228. d_DoTex(`d_Palette4A')