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.

221 lines
6.0 KiB

  1. #if !defined(CTRL__Interpolation_h__INCLUDED)
  2. #define CTRL__Interpolation_h__INCLUDED
  3. #pragma once
  4. #if ENABLE_MSGTABLE_API
  5. /***************************************************************************\
  6. *****************************************************************************
  7. *
  8. * class DuInterpolation
  9. *
  10. *****************************************************************************
  11. \***************************************************************************/
  12. class DuInterpolation :
  13. public InterpolationImpl<DuInterpolation, DUser::SGadget>
  14. {
  15. // Operations
  16. public:
  17. inline DuInterpolation()
  18. {
  19. m_cRef = 1;
  20. }
  21. dapi HRESULT ApiAddRef(Interpolation::AddRefMsg *)
  22. {
  23. m_cRef++;
  24. return S_OK;
  25. }
  26. dapi HRESULT ApiRelease(Interpolation::ReleaseMsg *)
  27. {
  28. if (--m_cRef == 0) {
  29. DeleteHandle(GetHandle());
  30. }
  31. return S_OK;
  32. }
  33. dapi HRESULT ApiCompute(Interpolation::ComputeMsg * pmsg)
  34. {
  35. pmsg->flResult = 0.0f;
  36. return S_OK;
  37. }
  38. // Data
  39. protected:
  40. ULONG m_cRef;
  41. };
  42. /***************************************************************************\
  43. *****************************************************************************
  44. *
  45. * class DuLinearInterpolation
  46. *
  47. *****************************************************************************
  48. \***************************************************************************/
  49. class DuLinearInterpolation :
  50. public LinearInterpolationImpl<DuLinearInterpolation, DuInterpolation>
  51. {
  52. // Operations
  53. public:
  54. dapi HRESULT ApiCompute(Interpolation::ComputeMsg * pmsg)
  55. {
  56. pmsg->flResult = (1.0f - pmsg->flProgress) * pmsg->flStart + pmsg->flProgress * pmsg->flEnd;
  57. return S_OK;
  58. }
  59. };
  60. /***************************************************************************\
  61. *****************************************************************************
  62. *
  63. * class DuLogInterpolation
  64. *
  65. *****************************************************************************
  66. \***************************************************************************/
  67. class DuLogInterpolation :
  68. public LogInterpolationImpl<DuLogInterpolation, DuInterpolation>
  69. {
  70. // Operations
  71. public:
  72. inline DuLogInterpolation()
  73. {
  74. m_flScale = 1.0f;
  75. }
  76. dapi HRESULT ApiCompute(Interpolation::ComputeMsg * pmsg)
  77. {
  78. float flMax = (float) log10(m_flScale * 9.0f + 1.0f);
  79. float flT = (float) log10(pmsg->flProgress * m_flScale * 9.0f + 1.0f) / flMax;
  80. pmsg->flResult = (1.0f - flT) * pmsg->flStart + flT * pmsg->flEnd;
  81. return S_OK;
  82. }
  83. dapi HRESULT ApiSetScale(LogInterpolation::SetScaleMsg * pmsg)
  84. {
  85. m_flScale = pmsg->flScale;
  86. return S_OK;
  87. }
  88. // Data
  89. protected:
  90. float m_flScale;
  91. };
  92. /***************************************************************************\
  93. *****************************************************************************
  94. *
  95. * class DuExpInterpolation
  96. *
  97. *****************************************************************************
  98. \***************************************************************************/
  99. class DuExpInterpolation :
  100. public ExpInterpolationImpl<DuExpInterpolation, DuInterpolation>
  101. {
  102. // Operations
  103. public:
  104. inline DuExpInterpolation()
  105. {
  106. m_flScale = 1.0f;
  107. }
  108. dapi HRESULT ApiCompute(Interpolation::ComputeMsg * pmsg)
  109. {
  110. double dflProgress = pmsg->flProgress;
  111. double dflStart = pmsg->flStart;
  112. double dflEnd = pmsg->flEnd;
  113. double dflScale = m_flScale;
  114. double dflMax = (((10.0 * dflScale) - 1.0) / 9.0);
  115. double dflT = (((pow(10.0 * dflScale, dflProgress) - 1.0) / 9.0) / dflMax);
  116. pmsg->flResult = (float) ((1.0 - dflT) * dflStart + dflT * dflEnd);
  117. return S_OK;
  118. }
  119. dapi HRESULT ApiSetScale(ExpInterpolation::SetScaleMsg * pmsg)
  120. {
  121. m_flScale = pmsg->flScale;
  122. return S_OK;
  123. }
  124. // Data
  125. protected:
  126. float m_flScale;
  127. };
  128. /***************************************************************************\
  129. *****************************************************************************
  130. *
  131. * class DuSCurveInterpolation
  132. *
  133. *****************************************************************************
  134. \***************************************************************************/
  135. class DuSCurveInterpolation :
  136. public SCurveInterpolationImpl<DuSCurveInterpolation, DuInterpolation>
  137. {
  138. // Operations
  139. public:
  140. inline DuSCurveInterpolation()
  141. {
  142. m_flScale = 1.0f;
  143. }
  144. dapi HRESULT ApiCompute(Interpolation::ComputeMsg * pmsg)
  145. {
  146. //
  147. // Slow - fast - slow
  148. //
  149. double dflProgress = pmsg->flProgress;
  150. double dflStart = pmsg->flStart;
  151. double dflEnd = pmsg->flEnd;
  152. double dflScale = m_flScale;
  153. double dflMax;
  154. double dflT;
  155. if (dflProgress < 0.5) {
  156. double dflPartProgress = dflProgress * 2.0;
  157. dflMax = (((10.0 * dflScale) - 1.0) / 9.0) * 2.0;
  158. dflT = ((pow(10.0 * dflScale, dflPartProgress) - 1.0) / 9.0) / dflMax;
  159. } else {
  160. double dflPartProgress = (1.0 - dflProgress) * 2.0;
  161. dflMax = (((10.0 * dflScale) - 1.0) / 9.0) * 2.0;
  162. dflT = 1.0 - ((pow(10.0 * dflScale, dflPartProgress) - 1.0) / 9.0) / dflMax;
  163. }
  164. pmsg->flResult = (float) ((1.0 - dflT) * dflStart + dflT * dflEnd);
  165. return S_OK;
  166. }
  167. dapi HRESULT ApiSetScale(SCurveInterpolation::SetScaleMsg * pmsg)
  168. {
  169. m_flScale = pmsg->flScale;
  170. return S_OK;
  171. }
  172. // Data
  173. protected:
  174. float m_flScale;
  175. };
  176. #endif // ENABLE_MSGTABLE_API
  177. #endif // CTRL__Interpolation_h__INCLUDED