EtcBlock4x4.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 "EtcColor.h"
  18. #include "EtcColorFloatRGBA.h"
  19. #include "EtcErrorMetric.h"
  20. #include "EtcImage.h"
  21. #include "EtcBlock4x4Encoding.h"
  22. namespace Etc
  23. {
  24. class Block4x4EncodingBits;
  25. class Block4x4
  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. // the alpha mix for a 4x4 block of pixels
  32. enum class SourceAlphaMix
  33. {
  34. UNKNOWN,
  35. //
  36. OPAQUE, // all 1.0
  37. TRANSPARENT, // all 0.0 or NAN
  38. TRANSLUCENT // not all opaque or transparent
  39. };
  40. typedef void (Block4x4::*EncoderFunctionPtr)(void);
  41. Block4x4(void);
  42. ~Block4x4();
  43. void InitFromSource(Image *a_pimageSource,
  44. unsigned int a_uiSourceH,
  45. unsigned int a_uiSourceV,
  46. unsigned char *a_paucEncodingBits,
  47. ErrorMetric a_errormetric);
  48. void InitFromEtcEncodingBits(Image::Format a_imageformat,
  49. unsigned int a_uiSourceH,
  50. unsigned int a_uiSourceV,
  51. unsigned char *a_paucEncodingBits,
  52. Image *a_pimageSource,
  53. ErrorMetric a_errormetric);
  54. // return true if final iteration was performed
  55. inline void PerformEncodingIteration(float a_fEffort)
  56. {
  57. m_pencoding->PerformIteration(a_fEffort);
  58. }
  59. inline void SetEncodingBitsFromEncoding(void)
  60. {
  61. m_pencoding->SetEncodingBits();
  62. }
  63. inline unsigned int GetSourceH(void)
  64. {
  65. return m_uiSourceH;
  66. }
  67. inline unsigned int GetSourceV(void)
  68. {
  69. return m_uiSourceV;
  70. }
  71. inline float GetError(void)
  72. {
  73. return m_pencoding->GetError();
  74. }
  75. static const unsigned int s_auiPixelOrderHScan[PIXELS];
  76. inline ColorFloatRGBA * GetDecodedColors(void)
  77. {
  78. return m_pencoding->GetDecodedColors();
  79. }
  80. inline float * GetDecodedAlphas(void)
  81. {
  82. return m_pencoding->GetDecodedAlphas();
  83. }
  84. inline Block4x4Encoding::Mode GetEncodingMode(void)
  85. {
  86. return m_pencoding->GetMode();
  87. }
  88. inline bool GetFlip(void)
  89. {
  90. return m_pencoding->GetFlip();
  91. }
  92. inline bool IsDifferential(void)
  93. {
  94. return m_pencoding->IsDifferential();
  95. }
  96. inline ColorFloatRGBA * GetSource()
  97. {
  98. return m_afrgbaSource;
  99. }
  100. inline ErrorMetric GetErrorMetric()
  101. {
  102. return m_errormetric;
  103. }
  104. const char * GetEncodingModeName(void);
  105. inline Block4x4Encoding * GetEncoding(void)
  106. {
  107. return m_pencoding;
  108. }
  109. inline SourceAlphaMix GetSourceAlphaMix(void)
  110. {
  111. return m_sourcealphamix;
  112. }
  113. inline Image * GetImageSource(void)
  114. {
  115. return m_pimageSource;
  116. }
  117. inline bool HasBorderPixels(void)
  118. {
  119. return m_boolBorderPixels;
  120. }
  121. inline bool HasPunchThroughPixels(void)
  122. {
  123. return m_boolPunchThroughPixels;
  124. }
  125. private:
  126. void SetSourcePixels(void);
  127. Image *m_pimageSource;
  128. unsigned int m_uiSourceH;
  129. unsigned int m_uiSourceV;
  130. ErrorMetric m_errormetric;
  131. ColorFloatRGBA m_afrgbaSource[PIXELS]; // vertical scan
  132. SourceAlphaMix m_sourcealphamix;
  133. bool m_boolBorderPixels; // marked as rgba(NAN, NAN, NAN, NAN)
  134. bool m_boolPunchThroughPixels; // RGB8A1 or SRGB8A1 with any pixels with alpha < 0.5
  135. Block4x4Encoding *m_pencoding;
  136. };
  137. } // namespace Etc