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.

117 lines
3.3 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // This file contains texture filtering functions.
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997.
  6. //
  7. //-----------------------------------------------------------------------------
  8. #include "rgb_pch.h"
  9. #pragma hdrstop
  10. #include "ctexfilt.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. r00 = r00 + ((iU*(r10 - r00)) >> 16);
  54. g00 = g00 + ((iU*(g10 - g00)) >> 16);
  55. b00 = b00 + ((iU*(b10 - b00)) >> 16);
  56. a00 = a00 + ((iU*(a10 - a00)) >> 16);
  57. r01 = r01 + ((iU*(r11 - r01)) >> 16);
  58. g01 = g01 + ((iU*(g11 - g01)) >> 16);
  59. b01 = b01 + ((iU*(b11 - b01)) >> 16);
  60. a01 = a01 + ((iU*(a11 - a01)) >> 16);
  61. r00 = r00 + ((iV*(r01 - r00)) >> 16);
  62. g00 = g00 + ((iV*(g01 - g00)) >> 16);
  63. b00 = b00 + ((iV*(b01 - b00)) >> 16);
  64. a00 = a00 + ((iV*(a01 - a00)) >> 16);
  65. #else
  66. // another potential implementation
  67. INT32 s1, s2, s3, s4;
  68. s4 = (iU * iV)>>16; // (0.16 * 0.16) >> 16 = 0.16
  69. s3 = iV - s4;
  70. s2 = iU - s4;
  71. s1 = 0x10000 - iV - s2;
  72. INT32 r00, r01, r10, r11;
  73. INT32 g00, g01, g10, g11;
  74. INT32 b00, b01, b10, b11;
  75. INT32 a00, a01, a10, a11;
  76. r00 = RGBA_GETRED(uTex00);
  77. r01 = RGBA_GETRED(uTex01);
  78. r10 = RGBA_GETRED(uTex10);
  79. r11 = RGBA_GETRED(uTex11);
  80. g00 = RGBA_GETGREEN(uTex00);
  81. g01 = RGBA_GETGREEN(uTex01);
  82. g10 = RGBA_GETGREEN(uTex10);
  83. g11 = RGBA_GETGREEN(uTex11);
  84. b00 = RGBA_GETBLUE(uTex00);
  85. b01 = RGBA_GETBLUE(uTex01);
  86. b10 = RGBA_GETBLUE(uTex10);
  87. b11 = RGBA_GETBLUE(uTex11);
  88. a00 = RGBA_GETALPHA(uTex00);
  89. a01 = RGBA_GETALPHA(uTex01);
  90. a10 = RGBA_GETALPHA(uTex10);
  91. a11 = RGBA_GETALPHA(uTex11);
  92. // 8.0 * 0.16 == 8.16 >> 16 == 8.0
  93. r00 = (r00*s1 + r10*s2 + r01*s3 + r11*s4)>>16;
  94. g00 = (g00*s1 + g10*s2 + g01*s3 + g11*s4)>>16;
  95. b00 = (b00*s1 + b10*s2 + b01*s3 + b11*s4)>>16;
  96. a00 = (a00*s1 + a10*s2 + a01*s3 + a11*s4)>>16;
  97. #endif
  98. *pOut = RGBA_MAKE(r00, g00, b00, a00);
  99. }