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.

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