EtcBlock4x4Encoding.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 "EtcColorFloatRGBA.h"
  18. #include "EtcErrorMetric.h"
  19. #include <assert.h>
  20. #include <float.h>
  21. namespace Etc
  22. {
  23. class Block4x4;
  24. // abstract base class for specific encodings
  25. class Block4x4Encoding
  26. {
  27. public:
  28. static const unsigned int ROWS = 4;
  29. static const unsigned int COLUMNS = 4;
  30. static const unsigned int PIXELS = ROWS * COLUMNS;
  31. static const float LUMA_WEIGHT;
  32. static const float CHROMA_BLUE_WEIGHT;
  33. typedef enum
  34. {
  35. MODE_UNKNOWN,
  36. //
  37. MODE_ETC1,
  38. MODE_T,
  39. MODE_H,
  40. MODE_PLANAR,
  41. MODE_R11,
  42. MODE_RG11,
  43. //
  44. MODES
  45. } Mode;
  46. Block4x4Encoding(void);
  47. //virtual ~Block4x4Encoding(void) =0;
  48. virtual ~Block4x4Encoding(void) {}
  49. virtual void InitFromSource(Block4x4 *a_pblockParent,
  50. ColorFloatRGBA *a_pafrgbaSource,
  51. unsigned char *a_paucEncodingBits, ErrorMetric a_errormetric) = 0;
  52. virtual void InitFromEncodingBits(Block4x4 *a_pblockParent,
  53. unsigned char *a_paucEncodingBits,
  54. ColorFloatRGBA *a_pafrgbaSource,
  55. ErrorMetric a_errormetric) = 0;
  56. // perform an iteration of the encoding
  57. // the first iteration must generate a complete, valid (if poor) encoding
  58. virtual void PerformIteration(float a_fEffort) = 0;
  59. void CalcBlockError(void);
  60. inline float GetError(void)
  61. {
  62. assert(m_fError >= 0.0f);
  63. return m_fError;
  64. }
  65. inline ColorFloatRGBA * GetDecodedColors(void)
  66. {
  67. return m_afrgbaDecodedColors;
  68. }
  69. inline float * GetDecodedAlphas(void)
  70. {
  71. return m_afDecodedAlphas;
  72. }
  73. virtual void SetEncodingBits(void) = 0;
  74. virtual bool GetFlip(void) = 0;
  75. virtual bool IsDifferential(void) = 0;
  76. virtual bool HasSeverelyBentDifferentialColors(void) const = 0;
  77. inline Mode GetMode(void)
  78. {
  79. return m_mode;
  80. }
  81. inline bool IsDone(void)
  82. {
  83. return m_boolDone;
  84. }
  85. inline void SetDoneIfPerfect()
  86. {
  87. if (GetError() == 0.0f)
  88. {
  89. m_boolDone = true;
  90. }
  91. }
  92. float CalcPixelError(ColorFloatRGBA a_frgbaDecodedColor, float a_fDecodedAlpha,
  93. ColorFloatRGBA a_frgbaSourcePixel);
  94. protected:
  95. void Init(Block4x4 *a_pblockParent,
  96. ColorFloatRGBA *a_pafrgbaSource,
  97. ErrorMetric a_errormetric);
  98. Block4x4 *m_pblockParent;
  99. ColorFloatRGBA *m_pafrgbaSource;
  100. bool m_boolBorderPixels; // if block has any border pixels
  101. ColorFloatRGBA m_afrgbaDecodedColors[PIXELS]; // decoded RGB components, ignore Alpha
  102. float m_afDecodedAlphas[PIXELS]; // decoded alpha component
  103. float m_fError; // error for RGBA relative to m_pafrgbaSource
  104. // intermediate encoding
  105. Mode m_mode;
  106. unsigned int m_uiEncodingIterations;
  107. bool m_boolDone; // all iterations have been done
  108. ErrorMetric m_errormetric;
  109. private:
  110. };
  111. } // namespace Etc