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.

244 lines
7.3 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. define(`d_B4G4R4', `
  111. D3DCOLOR C_TexRead_B4G4R4_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  112. {
  113. d_DoBorder(`$1')
  114. INT16 iTexel = ((INT16*)pBits)[iU | (iV << iShiftU)];
  115. D3DCOLOR Color = RGBA_MAKE((( iTexel >> 4 ) & 0xf0),
  116. (( iTexel >> 0) & 0xf0 ),
  117. (( iTexel << 4) & 0xf0 ),
  118. 0xff);
  119. d_DoColorKey(`$2', iTexel, `(INT16)')
  120. return Color;
  121. }')dnl
  122. d_DoTex(`d_B4G4R4')
  123. dnl
  124. // An alpha of 0xf becomes 0xff, 0x0 becomes 0x0, and it is monotonic.
  125. // May want to apply this operation to all color channels
  126. define(`d_B4G4R4A4', `
  127. D3DCOLOR C_TexRead_B4G4R4A4_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  128. {
  129. d_DoBorder(`$1')
  130. INT16 iTexel = ((INT16*)pBits)[iU | (iV << iShiftU)];
  131. INT16 iAlpha = ( iTexel >> 12 ) & 0xf;
  132. D3DCOLOR Color = RGBA_MAKE((( iTexel >> 4 ) & 0xf0),
  133. (( iTexel >> 0) & 0xf0 ),
  134. (( iTexel << 4) & 0xf0 ),
  135. (iAlpha << 4) | iAlpha );
  136. d_DoColorKey(`$2', iTexel, `(INT16)')
  137. return Color;
  138. }')dnl
  139. d_DoTex(`d_B4G4R4A4')
  140. dnl
  141. define(`d_L8', `
  142. D3DCOLOR C_TexRead_L8_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  143. {
  144. d_DoBorder(`$1')
  145. UINT8 iTexel = pBits[iU | (iV << iShiftU)];
  146. D3DCOLOR Color = RGBA_MAKE(iTexel,
  147. iTexel,
  148. iTexel,
  149. 0xff );
  150. d_DoColorKey(`$2', iTexel, `(INT8)')
  151. return Color;
  152. }')dnl
  153. d_DoTex(`d_L8')
  154. dnl
  155. define(`d_L8A8', `
  156. D3DCOLOR C_TexRead_L8A8_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  157. {
  158. d_DoBorder(`$1')
  159. INT16 iTexel = ((INT16*)pBits)[iU | (iV << iShiftU)];
  160. INT16 iAlpha = ( iTexel >> 8 ) & 0xff;
  161. iTexel &= 0xff;
  162. D3DCOLOR Color = RGBA_MAKE(iTexel,
  163. iTexel,
  164. iTexel,
  165. iAlpha );
  166. d_DoColorKey(`$2', iTexel, `(INT16)')
  167. return Color;
  168. }')dnl
  169. d_DoTex(`d_L8A8')
  170. dnl
  171. dnl
  172. dnl
  173. dnl d_CheckPalette4
  174. dnl
  175. dnl Index computation for palette4, otherwise just retrieve iTexel for palette8
  176. dnl $1 the function type,
  177. dnl
  178. define(`d_CheckPalette4', `ifelse(eval(d_index(`$1', `Palette4') >= 0), `1', `
  179. INT32 iTexel = pBits[iIndex>>1];
  180. if ((iIndex & 1) == 0)
  181. {
  182. iTexel &= 0xf;
  183. }
  184. else
  185. {
  186. iTexel >>= 4;
  187. }', `
  188. INT32 iTexel = pBits[iIndex];')')dnl
  189. dnl
  190. dnl
  191. dnl
  192. dnl d_DoPaletteAlpha
  193. dnl
  194. dnl Check if palette has alpha
  195. dnl $1 the function type,
  196. dnl
  197. define(`d_DoPaletteAlpha', `ifelse(eval(d_index(`$1', `A') >= 0), `1', `
  198. Color = RGBA_MAKE((Color & 0xff),
  199. (Color >> 8) & 0xff,
  200. (Color >> 16) & 0xff,
  201. (Color >> 24) & 0xff);', `
  202. Color = RGBA_MAKE((Color & 0xff),
  203. (Color >> 8) & 0xff,
  204. (Color >> 16) & 0xff,
  205. 0xff);')')dnl
  206. dnl
  207. define(`d_Palette', `
  208. d_DoBorder(`$1')
  209. INT32 iIndex = iU | (iV << iShiftU);
  210. d_CheckPalette4(`$3')
  211. D3DCOLOR Color = pTex->pPalette[iTexel];
  212. // RL palette is BGR - flip the channels into RGB
  213. d_DoPaletteAlpha(`$3')
  214. d_DoColorKey(`$2', iTexel, `(INT32)')
  215. return Color;
  216. ')dnl
  217. dnl
  218. define(`d_Palette8', `
  219. D3DCOLOR C_TexRead_Palette8_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  220. {
  221. d_Palette($1, $2, Palette8)
  222. }')dnl
  223. d_DoTex(`d_Palette8')
  224. define(`d_Palette4', `
  225. D3DCOLOR C_TexRead_Palette4_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  226. {
  227. d_Palette($1, $2, Palette4)
  228. }')dnl
  229. d_DoTex(`d_Palette4')
  230. dnl
  231. define(`d_Palette8A', `
  232. D3DCOLOR C_TexRead_Palette8A_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  233. {
  234. d_Palette($1, $2, Palette8A)
  235. }')dnl
  236. d_DoTex(`d_Palette8A')
  237. define(`d_Palette4A', `
  238. D3DCOLOR C_TexRead_Palette4A_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  239. {
  240. d_Palette($1, $2, Palette4A)
  241. }')dnl
  242. d_DoTex(`d_Palette4A')