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_R11;
24 
25 	// ################################################################################
26 	// Block4x4Encoding_R11
27 	// ################################################################################
28 
29 	class Block4x4Encoding_R11 : public Block4x4Encoding_RGB8
30 	{
31 	public:
32 
33 		Block4x4Encoding_R11(void);
34 		virtual ~Block4x4Encoding_R11(void);
35 
36 		virtual void InitFromSource(Block4x4 *a_pblockParent,
37 			ColorFloatRGBA *a_pafrgbaSource,
38 			unsigned char *a_paucEncodingBits, ErrorMetric a_errormetric);
39 
40 		virtual void InitFromEncodingBits(Block4x4 *a_pblockParent,
41 			unsigned char *a_paucEncodingBits,
42 			ColorFloatRGBA *a_pafrgbaSource,
43 			ErrorMetric a_errormetric);
44 
45 		virtual void PerformIteration(float a_fEffort);
46 
47 		virtual void SetEncodingBits(void);
48 
GetRedBase(void)49 		inline float GetRedBase(void) const
50 		{
51 			return m_fRedBase;
52 		}
53 
GetRedMultiplier(void)54 		inline float GetRedMultiplier(void) const
55 		{
56 			return m_fRedMultiplier;
57 		}
58 
GetRedTableIndex(void)59 		inline int GetRedTableIndex(void) const
60 		{
61 			return m_uiRedModifierTableIndex;
62 		}
63 
GetRedSelectors(void)64 		inline const unsigned int * GetRedSelectors(void) const
65 		{
66 			return m_auiRedSelectors;
67 		}
68 
69 	protected:
70 
71 		static const unsigned int MODIFIER_TABLE_ENTRYS = 16;
72 		static const unsigned int SELECTOR_BITS = 3;
73 		static const unsigned int SELECTORS = 1 << SELECTOR_BITS;
74 
75 		static float s_aafModifierTable[MODIFIER_TABLE_ENTRYS][SELECTORS];
76 
77 		void CalculateR11(unsigned int a_uiSelectorsUsed,
78 							float a_fBaseRadius, float a_fMultiplierRadius);
79 
80 
81 
82 
DecodePixelRed(float a_fBase,float a_fMultiplier,unsigned int a_uiTableIndex,unsigned int a_uiSelector)83 		inline float DecodePixelRed(float a_fBase, float a_fMultiplier,
84 			unsigned int a_uiTableIndex, unsigned int a_uiSelector)
85 		{
86 			float fMultiplier = a_fMultiplier;
87 			if (fMultiplier <= 0.0f)
88 			{
89 				fMultiplier = 1.0f / 8.0f;
90 			}
91 
92 			float fPixelRed = a_fBase * 8 + 4 +
93 				8 * fMultiplier*s_aafModifierTable[a_uiTableIndex][a_uiSelector]*255;
94 			fPixelRed /= 2047.0f;
95 
96 			if (fPixelRed < 0.0f)
97 			{
98 				fPixelRed = 0.0f;
99 			}
100 			else if (fPixelRed > 1.0f)
101 			{
102 				fPixelRed = 1.0f;
103 			}
104 
105 			return fPixelRed;
106 		}
107 
108 		Block4x4EncodingBits_R11 *m_pencodingbitsR11;
109 
110 		float m_fRedBase;
111 		float m_fRedMultiplier;
112 		float m_fRedBlockError;
113 		unsigned int m_uiRedModifierTableIndex;
114 		unsigned int m_auiRedSelectors[PIXELS];
115 
116 
117 	};
118 
119 	// ----------------------------------------------------------------------------------------------------
120 	//
121 
122 } // namespace Etc
123