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