EtcBlock4x4Encoding_RGBA8.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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_A8;
  21. // ################################################################################
  22. // Block4x4Encoding_RGBA8
  23. // RGBA8 if not completely opaque or transparent
  24. // ################################################################################
  25. class Block4x4Encoding_RGBA8 : public Block4x4Encoding_RGB8
  26. {
  27. public:
  28. Block4x4Encoding_RGBA8(void);
  29. virtual ~Block4x4Encoding_RGBA8(void);
  30. virtual void InitFromSource(Block4x4 *a_pblockParent,
  31. ColorFloatRGBA *a_pafrgbaSource,
  32. unsigned char *a_paucEncodingBits, ErrorMetric a_errormetric);
  33. virtual void InitFromEncodingBits(Block4x4 *a_pblockParent,
  34. unsigned char *a_paucEncodingBits,
  35. ColorFloatRGBA *a_pafrgbaSource,
  36. ErrorMetric a_errormetric);
  37. virtual void PerformIteration(float a_fEffort);
  38. virtual void SetEncodingBits(void);
  39. protected:
  40. static const unsigned int MODIFIER_TABLE_ENTRYS = 16;
  41. static const unsigned int ALPHA_SELECTOR_BITS = 3;
  42. static const unsigned int ALPHA_SELECTORS = 1 << ALPHA_SELECTOR_BITS;
  43. static float s_aafModifierTable[MODIFIER_TABLE_ENTRYS][ALPHA_SELECTORS];
  44. void CalculateA8(float a_fRadius);
  45. Block4x4EncodingBits_A8 *m_pencodingbitsA8; // A8 portion of Block4x4EncodingBits_RGBA8
  46. float m_fBase;
  47. float m_fMultiplier;
  48. unsigned int m_uiModifierTableIndex;
  49. unsigned int m_auiAlphaSelectors[PIXELS];
  50. private:
  51. inline float DecodePixelAlpha(float a_fBase, float a_fMultiplier,
  52. unsigned int a_uiTableIndex, unsigned int a_uiSelector)
  53. {
  54. float fPixelAlpha = a_fBase +
  55. a_fMultiplier*s_aafModifierTable[a_uiTableIndex][a_uiSelector];
  56. if (fPixelAlpha < 0.0f)
  57. {
  58. fPixelAlpha = 0.0f;
  59. }
  60. else if (fPixelAlpha > 1.0f)
  61. {
  62. fPixelAlpha = 1.0f;
  63. }
  64. return fPixelAlpha;
  65. }
  66. };
  67. // ################################################################################
  68. // Block4x4Encoding_RGBA8_Opaque
  69. // RGBA8 if all pixels have alpha==1
  70. // ################################################################################
  71. class Block4x4Encoding_RGBA8_Opaque : public Block4x4Encoding_RGBA8
  72. {
  73. public:
  74. virtual void PerformIteration(float a_fEffort);
  75. virtual void SetEncodingBits(void);
  76. };
  77. // ################################################################################
  78. // Block4x4Encoding_RGBA8_Transparent
  79. // RGBA8 if all pixels have alpha==0
  80. // ################################################################################
  81. class Block4x4Encoding_RGBA8_Transparent : public Block4x4Encoding_RGBA8
  82. {
  83. public:
  84. virtual void PerformIteration(float a_fEffort);
  85. virtual void SetEncodingBits(void);
  86. };
  87. // ----------------------------------------------------------------------------------------------------
  88. //
  89. } // namespace Etc