encoderlist.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. //
  19. // Filename: encoderlist.h
  20. // Project: wwbitpack.lib
  21. // Author: Tom Spencer-Smith
  22. // Date: June 1998
  23. // Description:
  24. //
  25. #ifndef ENCODERLIST_H
  26. #define ENCODERLIST_H
  27. #include "encodertypeentry.h"
  28. #include "miscutil.h"
  29. #include "wwdebug.h"
  30. const int MAX_ENCODERTYPES = 100;
  31. class cEncoderList
  32. {
  33. public:
  34. static void Clear_Entries();
  35. static void Set_Compression_Enabled(bool flag) {IsCompressionEnabled = flag;}
  36. static bool Is_Compression_Enabled() {return IsCompressionEnabled;}
  37. static cEncoderTypeEntry & Get_Encoder_Type_Entry(int index);
  38. #pragma auto_inline(off)
  39. //------------------------------------------------------------------------------------
  40. template<class T> static T Set_Precision(int type, T min, T max,
  41. T resolution = 1)
  42. {
  43. WWASSERT(type >= 0 && type < MAX_ENCODERTYPES);
  44. WWASSERT(max - min > -MISCUTIL_EPSILON);
  45. WWASSERT(resolution > MISCUTIL_EPSILON);
  46. EncoderTypes[type].Init(
  47. static_cast<double>(min),
  48. static_cast<double>(max),
  49. static_cast<double>(resolution));
  50. WWDEBUG_SAY(("cEncoderList::Set_Precision for type %d: %d -> %d bits\n",
  51. type, sizeof(T) * 8, EncoderTypes[type].Get_Bit_Precision()));
  52. //
  53. // Return maximum representation error
  54. //
  55. return static_cast<T>(resolution / 2.0f + MISCUTIL_EPSILON);
  56. /*
  57. double max_error = EncoderTypes[type].Get_Resolution() / 2.0f + MISCUTIL_EPSILON;
  58. if (::fabs(max_error - static_cast<T>(max_error)) < MISCUTIL_EPSILON) {
  59. //return static_cast<T>(max_error);
  60. return static_cast<T>(max_error);
  61. } else {
  62. return static_cast<T>(ceil(max_error));
  63. }
  64. /**/
  65. }
  66. //------------------------------------------------------------------------------------
  67. static void Set_Precision(int type, int num_bits)
  68. {
  69. WWASSERT(type >= 0 && type < MAX_ENCODERTYPES);
  70. WWASSERT(num_bits > 0 && num_bits <= 32);
  71. EncoderTypes[type].Init(num_bits);
  72. WWDEBUG_SAY(("cEncoderList::Set_Precision for type %d: %d bits\n",
  73. type, num_bits));
  74. }
  75. //------------------------------------------------------------------------------------
  76. #pragma auto_inline(on)
  77. private:
  78. static cEncoderTypeEntry EncoderTypes[MAX_ENCODERTYPES];
  79. static bool IsCompressionEnabled;
  80. };
  81. #endif // ENCODERLIST_H