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.

118 lines
3.4 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // This file contains texture filtering functions.
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997.
  6. //
  7. //-----------------------------------------------------------------------------
  8. #include "pch.cpp"
  9. #pragma hdrstop
  10. #include "mtexfilt.h"
  11. //-----------------------------------------------------------------------------
  12. //
  13. // TexFiltBilinear
  14. //
  15. // Given the basic bilinear equations
  16. //
  17. // A = C00 + U*(C10 - C00)
  18. // B = C01 + U*(C11 - C01)
  19. // C = A + V*(B-A)
  20. //
  21. // This routine is based on the re-arrangement of this equation into
  22. //
  23. // C = C00*(1-U-V+U*V) + C10*(U-U*V) + C10(V-U*V) + C11*(U*V)
  24. // or
  25. // C = C00*s1 + C10*s2 + C10*s3 + C11*s4
  26. //
  27. //-----------------------------------------------------------------------------
  28. void TexFiltBilinear(D3DCOLOR *pOut, INT32 iU, INT32 iV, UINT32 uTex00, UINT32 uTex10,
  29. UINT32 uTex01, UINT32 uTex11)
  30. {
  31. #define SIMPLE_BILINEAR 1
  32. #ifdef SIMPLE_BILINEAR
  33. INT32 r00, r01, r10, r11;
  34. INT32 g00, g01, g10, g11;
  35. INT32 b00, b01, b10, b11;
  36. INT32 a00, a01, a10, a11;
  37. r00 = RGBA_GETRED(uTex00);
  38. r01 = RGBA_GETRED(uTex01);
  39. r10 = RGBA_GETRED(uTex10);
  40. r11 = RGBA_GETRED(uTex11);
  41. g00 = RGBA_GETGREEN(uTex00);
  42. g01 = RGBA_GETGREEN(uTex01);
  43. g10 = RGBA_GETGREEN(uTex10);
  44. g11 = RGBA_GETGREEN(uTex11);
  45. b00 = RGBA_GETBLUE(uTex00);
  46. b01 = RGBA_GETBLUE(uTex01);
  47. b10 = RGBA_GETBLUE(uTex10);
  48. b11 = RGBA_GETBLUE(uTex11);
  49. a00 = RGBA_GETALPHA(uTex00);
  50. a01 = RGBA_GETALPHA(uTex01);
  51. a10 = RGBA_GETALPHA(uTex10);
  52. a11 = RGBA_GETALPHA(uTex11);
  53. // can be MMX_mulhw's
  54. r00 = r00 + ((iU*(r10 - r00)) >> 16);
  55. g00 = g00 + ((iU*(g10 - g00)) >> 16);
  56. b00 = b00 + ((iU*(b10 - b00)) >> 16);
  57. a00 = a00 + ((iU*(a10 - a00)) >> 16);
  58. r01 = r01 + ((iU*(r11 - r01)) >> 16);
  59. g01 = g01 + ((iU*(g11 - g01)) >> 16);
  60. b01 = b01 + ((iU*(b11 - b01)) >> 16);
  61. a01 = a01 + ((iU*(a11 - a01)) >> 16);
  62. r00 = r00 + ((iV*(r01 - r00)) >> 16);
  63. g00 = g00 + ((iV*(g01 - g00)) >> 16);
  64. b00 = b00 + ((iV*(b01 - b00)) >> 16);
  65. a00 = a00 + ((iV*(a01 - a00)) >> 16);
  66. #else
  67. // another potential MMX implementation
  68. INT32 s1, s2, s3, s4;
  69. s4 = (iU * iV)>>16; // (0.16 * 0.16) >> 16 = 0.16
  70. s3 = iV - s4;
  71. s2 = iU - s4;
  72. s1 = 0x10000 - iV - s2;
  73. INT32 r00, r01, r10, r11;
  74. INT32 g00, g01, g10, g11;
  75. INT32 b00, b01, b10, b11;
  76. INT32 a00, a01, a10, a11;
  77. r00 = RGBA_GETRED(uTex00);
  78. r01 = RGBA_GETRED(uTex01);
  79. r10 = RGBA_GETRED(uTex10);
  80. r11 = RGBA_GETRED(uTex11);
  81. g00 = RGBA_GETGREEN(uTex00);
  82. g01 = RGBA_GETGREEN(uTex01);
  83. g10 = RGBA_GETGREEN(uTex10);
  84. g11 = RGBA_GETGREEN(uTex11);
  85. b00 = RGBA_GETBLUE(uTex00);
  86. b01 = RGBA_GETBLUE(uTex01);
  87. b10 = RGBA_GETBLUE(uTex10);
  88. b11 = RGBA_GETBLUE(uTex11);
  89. a00 = RGBA_GETALPHA(uTex00);
  90. a01 = RGBA_GETALPHA(uTex01);
  91. a10 = RGBA_GETALPHA(uTex10);
  92. a11 = RGBA_GETALPHA(uTex11);
  93. // 8.0 * 0.16 == 8.16 >> 16 == 8.0
  94. r00 = (r00*s1 + r10*s2 + r01*s3 + r11*s4)>>16;
  95. g00 = (g00*s1 + g10*s2 + g01*s3 + g11*s4)>>16;
  96. b00 = (b00*s1 + b10*s2 + b01*s3 + b11*s4)>>16;
  97. a00 = (a00*s1 + a10*s2 + a01*s3 + a11*s4)>>16;
  98. #endif
  99. *pOut = RGBA_MAKE(r00, g00, b00, a00);
  100. }