/src/FreeImage/Source/OpenEXR/IlmImf/b44ExpLogTable.cpp

https://bitbucket.org/cabalistic/ogredeps/ · C++ · 136 lines · 62 code · 22 blank · 52 comment · 13 complexity · 38f2c2bc9d3aec05b0bd8c2c858ef1c6 MD5 · raw file

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2006, Industrial Light & Magic, a division of Lucas
  4. // Digital Ltd. LLC
  5. //
  6. // All rights reserved.
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions are
  10. // met:
  11. // * Redistributions of source code must retain the above copyright
  12. // notice, this list of conditions and the following disclaimer.
  13. // * Redistributions in binary form must reproduce the above
  14. // copyright notice, this list of conditions and the following disclaimer
  15. // in the documentation and/or other materials provided with the
  16. // distribution.
  17. // * Neither the name of Industrial Light & Magic nor the names of
  18. // its contributors may be used to endorse or promote products derived
  19. // from this software without specific prior written permission.
  20. //
  21. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. //
  33. ///////////////////////////////////////////////////////////////////////////
  34. //---------------------------------------------------------------------------
  35. //
  36. // b44ExpLogTable
  37. //
  38. // A program to generate lookup tables for
  39. //
  40. // y = exp (x / 8)
  41. //
  42. // and
  43. // x = 8 * log (x);
  44. //
  45. // where x and y are 16-bit floating-point numbers
  46. //
  47. // The tables are used by class B44Compressor.
  48. //
  49. //---------------------------------------------------------------------------
  50. #include <half.h>
  51. #include <math.h>
  52. #include <iostream>
  53. #include <iomanip>
  54. using namespace std;
  55. //---------------------------------------------
  56. // Main - prints the half-to-float lookup table
  57. //---------------------------------------------
  58. int
  59. main ()
  60. {
  61. #ifndef HAVE_IOS_BASE
  62. cout.setf (ios::hex, ios::basefield);
  63. #else
  64. cout.setf (ios_base::hex, ios_base::basefield);
  65. #endif
  66. cout << "//\n"
  67. "// This is an automatically generated file.\n"
  68. "// Do not edit.\n"
  69. "//\n\n";
  70. const int iMax = (1 << 16);
  71. cout << "const unsigned short expTable[] =\n"
  72. "{\n"
  73. " ";
  74. for (int i = 0; i < iMax; i++)
  75. {
  76. half h;
  77. h.setBits (i);
  78. if (!h.isFinite())
  79. h = 0;
  80. else if (h >= 8 * log (HALF_MAX))
  81. h = HALF_MAX;
  82. else
  83. h = exp (h / 8);
  84. cout << "0x" << setfill ('0') << setw (4) << h.bits() << ", ";
  85. if (i % 8 == 7)
  86. {
  87. cout << "\n";
  88. if (i < iMax - 1)
  89. cout << " ";
  90. }
  91. }
  92. cout << "};\n\n";
  93. cout << "const unsigned short logTable[] =\n"
  94. "{\n"
  95. " ";
  96. for (int i = 0; i < iMax; i++)
  97. {
  98. half h;
  99. h.setBits (i);
  100. if (!h.isFinite() || h < 0)
  101. h = 0;
  102. else
  103. h = 8 * log (h);
  104. cout << "0x" << setfill ('0') << setw (4) << h.bits() << ", ";
  105. if (i % 8 == 7)
  106. {
  107. cout << "\n";
  108. if (i < iMax - 1)
  109. cout << " ";
  110. }
  111. }
  112. cout << "};\n";
  113. return 0;
  114. }