EtcBlock4x4Encoding_R11.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright 2015 The Etc2Comp Authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #include "EtcBlock4x4Encoding_RGB8.h"
  18. namespace Etc
  19. {
  20. class Block4x4EncodingBits_R11;
  21. // ################################################################################
  22. // Block4x4Encoding_R11
  23. // ################################################################################
  24. class Block4x4Encoding_R11 : public Block4x4Encoding_RGB8
  25. {
  26. public:
  27. Block4x4Encoding_R11(void);
  28. virtual ~Block4x4Encoding_R11(void);
  29. virtual void InitFromSource(Block4x4 *a_pblockParent,
  30. ColorFloatRGBA *a_pafrgbaSource,
  31. unsigned char *a_paucEncodingBits, ErrorMetric a_errormetric);
  32. virtual void InitFromEncodingBits(Block4x4 *a_pblockParent,
  33. unsigned char *a_paucEncodingBits,
  34. ColorFloatRGBA *a_pafrgbaSource,
  35. ErrorMetric a_errormetric);
  36. virtual void PerformIteration(float a_fEffort);
  37. virtual void SetEncodingBits(void);
  38. inline float GetRedBase(void) const
  39. {
  40. return m_fRedBase;
  41. }
  42. inline float GetRedMultiplier(void) const
  43. {
  44. return m_fRedMultiplier;
  45. }
  46. inline int GetRedTableIndex(void) const
  47. {
  48. return m_uiRedModifierTableIndex;
  49. }
  50. inline const unsigned int * GetRedSelectors(void) const
  51. {
  52. return m_auiRedSelectors;
  53. }
  54. protected:
  55. static const unsigned int MODIFIER_TABLE_ENTRYS = 16;
  56. static const unsigned int SELECTOR_BITS = 3;
  57. static const unsigned int SELECTORS = 1 << SELECTOR_BITS;
  58. static float s_aafModifierTable[MODIFIER_TABLE_ENTRYS][SELECTORS];
  59. void CalculateR11(unsigned int a_uiSelectorsUsed,
  60. float a_fBaseRadius, float a_fMultiplierRadius);
  61. inline float DecodePixelRed(float a_fBase, float a_fMultiplier,
  62. unsigned int a_uiTableIndex, unsigned int a_uiSelector)
  63. {
  64. float fMultiplier = a_fMultiplier;
  65. if (fMultiplier <= 0.0f)
  66. {
  67. fMultiplier = 1.0f / 8.0f;
  68. }
  69. float fPixelRed = a_fBase * 8 + 4 +
  70. 8 * fMultiplier*s_aafModifierTable[a_uiTableIndex][a_uiSelector]*255;
  71. fPixelRed /= 2047.0f;
  72. if (fPixelRed < 0.0f)
  73. {
  74. fPixelRed = 0.0f;
  75. }
  76. else if (fPixelRed > 1.0f)
  77. {
  78. fPixelRed = 1.0f;
  79. }
  80. return fPixelRed;
  81. }
  82. Block4x4EncodingBits_R11 *m_pencodingbitsR11;
  83. float m_fRedBase;
  84. float m_fRedMultiplier;
  85. float m_fRedBlockError;
  86. unsigned int m_uiRedModifierTableIndex;
  87. unsigned int m_auiRedSelectors[PIXELS];
  88. };
  89. // ----------------------------------------------------------------------------------------------------
  90. //
  91. } // namespace Etc