Debian Codegraph @

third_party/etc2comp/EtcLib/EtcCodec/EtcBlock4x4Encoding_RGBA8.h

raw
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
17 #pragma once
18
19 #include "EtcBlock4x4Encoding_RGB8.h"
20
21 namespace Etc
22 {
23 class Block4x4EncodingBits_A8;
24
25 // ################################################################################
26 // Block4x4Encoding_RGBA8
27 // RGBA8 if not completely opaque or transparent
28 // ################################################################################
29
30 class Block4x4Encoding_RGBA8 : public Block4x4Encoding_RGB8
31 {
32 public:
33
34 Block4x4Encoding_RGBA8(void);
35 virtual ~Block4x4Encoding_RGBA8(void);
36
37 virtual void InitFromSource(Block4x4 *a_pblockParent,
38 ColorFloatRGBA *a_pafrgbaSource,
39 unsigned char *a_paucEncodingBits, ErrorMetric a_errormetric);
40
41 virtual void InitFromEncodingBits(Block4x4 *a_pblockParent,
42 unsigned char *a_paucEncodingBits,
43 ColorFloatRGBA *a_pafrgbaSource,
44 ErrorMetric a_errormetric);
45
46 virtual void PerformIteration(float a_fEffort);
47
48 virtual void SetEncodingBits(void);
49
50 protected:
51
52 static const unsigned int MODIFIER_TABLE_ENTRYS = 16;
53 static const unsigned int ALPHA_SELECTOR_BITS = 3;
54 static const unsigned int ALPHA_SELECTORS = 1 << ALPHA_SELECTOR_BITS;
55
56 static float s_aafModifierTable[MODIFIER_TABLE_ENTRYS][ALPHA_SELECTORS];
57
58 void CalculateA8(float a_fRadius);
59
60 Block4x4EncodingBits_A8 *m_pencodingbitsA8; // A8 portion of Block4x4EncodingBits_RGBA8
61
62 float m_fBase;
63 float m_fMultiplier;
64 unsigned int m_uiModifierTableIndex;
65 unsigned int m_auiAlphaSelectors[PIXELS];
66
67 private:
68
69 inline float DecodePixelAlpha(float a_fBase, float a_fMultiplier,
70 unsigned int a_uiTableIndex, unsigned int a_uiSelector)
71 {
72 float fPixelAlpha = a_fBase +
73 a_fMultiplier*s_aafModifierTable[a_uiTableIndex][a_uiSelector];
74 if (fPixelAlpha < 0.0f)
75 {
76 fPixelAlpha = 0.0f;
77 }
78 else if (fPixelAlpha > 1.0f)
79 {
80 fPixelAlpha = 1.0f;
81 }
82
83 return fPixelAlpha;
84 }
85
86 };
87
88 // ################################################################################
89 // Block4x4Encoding_RGBA8_Opaque
90 // RGBA8 if all pixels have alpha==1
91 // ################################################################################
92
93 class Block4x4Encoding_RGBA8_Opaque : public Block4x4Encoding_RGBA8
94 {
95 public:
96
97 virtual void PerformIteration(float a_fEffort);
98
99 virtual void SetEncodingBits(void);
100
101 };
102
103 // ################################################################################
104 // Block4x4Encoding_RGBA8_Transparent
105 // RGBA8 if all pixels have alpha==0
106 // ################################################################################
107
108 class Block4x4Encoding_RGBA8_Transparent : public Block4x4Encoding_RGBA8
109 {
110 public:
111
112 virtual void PerformIteration(float a_fEffort);
113
114 virtual void SetEncodingBits(void);
115
116 };
117
118 // ----------------------------------------------------------------------------------------------------
119 //
120
121 } // namespace Etc