Source code of Windows XP (NT5)
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.

136 lines
3.2 KiB

  1. /******************************************************************************
  2. * VqTable.cpp *
  3. *-------------*
  4. *
  5. *------------------------------------------------------------------------------
  6. * Copyright (C) 2000 Microsoft Corporation Date: 03/02/00 - 12/4/00
  7. * All Rights Reserved
  8. *
  9. ********************************************************************* mplumpe was PACOG ***/
  10. #include "VqTable.h"
  11. #include <assert.h>
  12. /*****************************************************************************
  13. * CVqTable::CVqTable *
  14. *--------------------*
  15. * Description:
  16. *
  17. ******************************************************************* mplumpe ***/
  18. CVqTable::CVqTable ()
  19. {
  20. m_pfValue = 0;
  21. m_ppfValue = 0;
  22. m_iDim = 0;
  23. m_fOldWeight = 1.0;
  24. }
  25. /*****************************************************************************
  26. * CVqTable::~CVqTable *
  27. *---------------------*
  28. * Description:
  29. *
  30. ******************************************************************* mplumpe ***/
  31. CVqTable::~CVqTable ()
  32. {
  33. if (m_pfValue)
  34. {
  35. delete[] m_pfValue;
  36. }
  37. if (m_ppfValue)
  38. {
  39. delete[] m_ppfValue;
  40. }
  41. }
  42. /*****************************************************************************
  43. * CVqTable::Element *
  44. *-------------------*
  45. * Description:
  46. * Now located in header
  47. ******************************************************************* mplumpe ***/
  48. /*****************************************************************************
  49. * CVqTable::Dimension *
  50. *---------------------*
  51. * Description:
  52. *
  53. ******************************************************************* PACOG ***/
  54. int CVqTable::Dimension ()
  55. {
  56. return m_iDim;
  57. }
  58. /*****************************************************************************
  59. * CVqTable::Load *
  60. *----------------*
  61. * Description:
  62. *
  63. ******************************************************************* mplumpe ***/
  64. int CVqTable::LoadFromFile (FILE* fin)
  65. {
  66. short aux;
  67. assert (fin);
  68. if (!fread (&aux, sizeof (aux), 1, fin)) {
  69. return 0;
  70. }
  71. m_iDim = aux;
  72. if (!fread (&aux, sizeof(aux), 1, fin)) {
  73. return 0;
  74. }
  75. assert (aux == m_iDim); //Should be the a square matrix
  76. if (m_pfValue)
  77. {
  78. delete[] m_pfValue;
  79. }
  80. if ((m_pfValue = new float[m_iDim * m_iDim]) == 0)
  81. {
  82. return 0;
  83. }
  84. if ((m_ppfValue = new float*[m_iDim]) == 0)
  85. {
  86. return 0;
  87. }
  88. if (!fread (m_pfValue, sizeof (float), m_iDim * m_iDim, fin))
  89. {
  90. return 0;
  91. }
  92. // Make array to lookup in table so we don't have to do a multiply
  93. for (aux=0; aux < m_iDim; aux++)
  94. {
  95. m_ppfValue[aux] = m_pfValue+aux*m_iDim;
  96. }
  97. m_fOldWeight = 1.0;
  98. return 1;
  99. }
  100. /*****************************************************************************
  101. * CVqTable::Scale *
  102. *-----------------*
  103. * Description:
  104. *
  105. ******************************************************************* PACOG ***/
  106. void CVqTable::Scale (double dContWeight)
  107. {
  108. if (m_iDim > 0 )
  109. {
  110. for (int i=0; i<m_iDim; i++)
  111. {
  112. for (int j=0; j<m_iDim; j++)
  113. {
  114. m_pfValue[i * m_iDim + j] *= (float) (dContWeight / m_fOldWeight);
  115. }
  116. }
  117. m_fOldWeight = (float)dContWeight;
  118. }
  119. }