Debian Codegraph @

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