• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <GLcommon/etc.h>
16 
17 #include <gtest/gtest.h>
18 #include <stdio.h>
19 
20 namespace {
21 class Etc2Test : public ::testing::Test {
22 protected:
23     static const int cRgbPatchSize = 48;
24     static const int cRgb8A1PatchSize = 64;
25     static const int cRgbEncodedSize = 8;
26     static const int cAlphaPatchSize = 16;
27     static const int cAlphaEncodedSize = 8;
decodeRgbTest(const etc1_byte * bytesEncoded,const etc1_byte * expectedDecoded)28     void decodeRgbTest(const etc1_byte* bytesEncoded, const etc1_byte* expectedDecoded) {
29         etc1_byte decoded[cRgbPatchSize];
30         etc2_decode_rgb_block(bytesEncoded, false, decoded);
31         for (int i=0; i<cRgbPatchSize; i++) {
32             EXPECT_EQ(expectedDecoded[i], decoded[i]);
33         }
34     }
decodeRgb8A1Test(const etc1_byte * bytesEncoded,const etc1_byte * expectedDecoded)35     void decodeRgb8A1Test(const etc1_byte* bytesEncoded, const etc1_byte* expectedDecoded) {
36         etc1_byte decoded[cRgb8A1PatchSize];
37         etc2_decode_rgb_block(bytesEncoded, true, decoded);
38         for (int i=0; i<cRgb8A1PatchSize; i++) {
39             EXPECT_EQ(expectedDecoded[i], decoded[i]);
40         }
41     }
decodeEacTest(const etc1_byte * bytesEncoded,int decodedElementBytes,bool isSigned,const etc1_byte * expectedDecoded)42     void decodeEacTest(const etc1_byte* bytesEncoded, int decodedElementBytes,
43                        bool isSigned, const etc1_byte* expectedDecoded) {
44         etc1_byte decoded[cAlphaPatchSize * decodedElementBytes];
45         eac_decode_single_channel_block(bytesEncoded, decodedElementBytes, isSigned, decoded);
46         for (int i=0; i<cAlphaPatchSize * decodedElementBytes; i++) {
47             EXPECT_EQ(expectedDecoded[i], decoded[i]);
48         }
49     }
50 };
51 }
52 
53 // ETC2 rgb decoder tests.
54 // The three test cases here cover T, H and planar codec, which are
55 // introduced in ETC2.
56 
TEST_F(Etc2Test,ETC2T)57 TEST_F(Etc2Test, ETC2T) {
58     const unsigned char encoded[cRgbEncodedSize] = {21, 101, 186, 135, 166, 238, 74, 106};
59     const unsigned char expectedDecoded[cRgbPatchSize] = {
60         153, 102, 85,   153, 102, 85,   153, 102, 85,   153, 102, 85,
61         171, 154, 120,  171, 154, 120,  171, 154, 120,  187, 170, 136,
62         187, 170, 136,  171, 154, 120,  187, 170, 136,  203, 186, 152,
63         171, 154, 120,  187, 170, 136,  203, 186, 152,  187, 170, 136};
64     decodeRgbTest((const etc1_byte*)encoded, (const etc1_byte*)expectedDecoded);
65 }
66 
TEST_F(Etc2Test,ETC2H)67 TEST_F(Etc2Test, ETC2H) {
68     const unsigned char encoded[cRgbEncodedSize] = {110, 13, 228, 186, 119, 119, 255, 117};
69     const unsigned char expectedDecoded[cRgbPatchSize] = {
70         198, 147, 113,  198, 147, 113,  198, 147, 113,    198, 147, 113,
71         210, 159, 125,  198, 147, 113,  198, 147, 113,    198, 147, 113,
72         198, 147, 113,  198, 147, 113,  198, 147, 113,    198, 147, 113,
73         227, 210, 193,  227, 210, 193,  215, 198, 181,    215, 198, 181};
74     decodeRgbTest((const etc1_byte*)encoded, (const etc1_byte*)expectedDecoded);
75 }
76 
TEST_F(Etc2Test,ETC2P)77 TEST_F(Etc2Test, ETC2P) {
78     const unsigned char encoded[cRgbEncodedSize] = {89, 138, 250, 79, 120, 181, 146, 29};
79     const unsigned char expectedDecoded[cRgbPatchSize] = {
80         178, 139, 113,  173, 134, 107,  168, 130, 101,  163, 125, 95,
81         178, 141, 114,  173, 136, 108,  168, 131, 102,  163, 126, 96,
82         178, 142, 115,  173, 137, 109,  168, 133, 103,  163, 128, 97,
83         178, 144, 116,  173, 139, 110,  168, 134, 104,  163, 129, 98};
84     decodeRgbTest((const etc1_byte*)encoded, (const etc1_byte*)expectedDecoded);
85 }
86 
87 // EAC alpha decoder tests.
TEST_F(Etc2Test,EAC_Alpha)88 TEST_F(Etc2Test, EAC_Alpha) {
89     const unsigned char encoded[cAlphaEncodedSize]
90                             = {101, 65, 229, 178, 147, 5, 32, 2};
91     const unsigned char expectedDecoded[cAlphaPatchSize] = {
92         149, 73, 89, 89,
93         73, 61, 73, 89,
94         49, 61, 61, 89,
95         49, 49, 61, 61};
96     decodeEacTest((const etc1_byte*)encoded, 1, false,
97                   (const etc1_byte*)expectedDecoded);
98 }
99 
100 // EAC 16bit decoder tests.
TEST_F(Etc2Test,DISABLED_EAC_R11_0)101 TEST_F(Etc2Test, DISABLED_EAC_R11_0) {
102     const int elementBytes = 2;
103     const unsigned char encoded[cAlphaEncodedSize]
104                             = {0, 0, 36, 146, 73, 36, 146, 73};
105     const unsigned char expectedDecoded[cAlphaPatchSize * elementBytes] = {
106         0, 0, 0, 0, 0, 0, 0, 0,
107         0, 0, 0, 0, 0, 0, 0, 0,
108         0, 0, 0, 0, 0, 0, 0, 0,
109         0, 0, 0, 0, 0, 0, 0, 0};
110     decodeEacTest((const etc1_byte*)encoded, elementBytes, false,
111                   (const etc1_byte*)expectedDecoded);
112 }
113 
TEST_F(Etc2Test,DISABLED_EAC_R11_NonZero)114 TEST_F(Etc2Test, DISABLED_EAC_R11_NonZero) {
115     const int elementBytes = 2;
116     const unsigned char encoded[cAlphaEncodedSize]
117                             = {45, 16, 23, 116, 38, 100, 86, 208};
118     const unsigned char expectedDecoded[cAlphaPatchSize * elementBytes] = {
119         133, 42, 132, 36, 131, 30, 131, 30,
120         134, 50, 133, 42, 132, 39, 131, 30,
121         134, 53, 133, 47, 133, 42, 132, 36,
122         135, 59, 134, 53, 134, 50, 133, 42};
123     decodeEacTest((const etc1_byte*)encoded, elementBytes, false,
124                   (const etc1_byte*)expectedDecoded);
125 }
126 
TEST_F(Etc2Test,DISABLED_EAC_SIGNED_R11)127 TEST_F(Etc2Test, DISABLED_EAC_SIGNED_R11) {
128     const int elementBytes = 2;
129     const unsigned char encoded[cAlphaEncodedSize]
130                             = {198, 123, 74, 150, 120, 104, 6, 137};
131     const unsigned char expectedDecoded[cAlphaPatchSize * elementBytes] = {
132         230, 148, 1, 128, 1, 128, 1, 128,
133         230, 148, 233, 162, 230, 148, 230, 148,
134         249, 225, 1, 5, 238, 183, 233, 162,
135         233, 162, 238, 183, 238, 183, 233, 162};
136     decodeEacTest((const etc1_byte*)encoded, elementBytes, true,
137                   (const etc1_byte*)expectedDecoded);
138 }
139 
140 // ETC2 RGB8A1 and sRGB8A1 tests.
TEST_F(Etc2Test,ETC2RGB8A1_All0)141 TEST_F(Etc2Test, ETC2RGB8A1_All0) {
142     const unsigned char encoded[cRgbEncodedSize] = {0, 0, 0, 0, 255, 255, 0, 0};
143     const unsigned char expectedDecoded[cRgb8A1PatchSize] = {
144         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
145         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
146         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
147         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
148     decodeRgb8A1Test((const etc1_byte*)encoded, (const etc1_byte*)expectedDecoded);
149 }
150 
TEST_F(Etc2Test,ETC2RGB8A1_OP1_diff_flipped)151 TEST_F(Etc2Test, ETC2RGB8A1_OP1_diff_flipped) {
152     const unsigned char encoded[cRgbEncodedSize] = {76, 206, 232, 35, 126, 232, 34, 21};
153     unsigned char expectedDecoded[cRgb8A1PatchSize] = {
154         91, 223, 255, 255, 91, 223, 255, 255, 79, 211, 244, 255, 69, 201, 234, 255,
155         79, 211, 244, 255, 69, 201, 234, 255, 57, 189, 222, 255, 57, 189, 222, 255,
156         49, 197, 247, 255, 39, 187, 237, 255, 39, 187, 237, 255, 39, 187, 237, 255,
157         39, 187, 237, 255, 39, 187, 237, 255, 39, 187, 237, 255, 43, 191, 241, 255};
158     decodeRgb8A1Test((const etc1_byte*)encoded, (const etc1_byte*)expectedDecoded);
159 }
160 
TEST_F(Etc2Test,ETC2RGB8A1_OP1_T)161 TEST_F(Etc2Test, ETC2RGB8A1_OP1_T) {
162     const unsigned char encoded[cRgbEncodedSize] = {4, 90, 75, 238, 98, 49, 81, 32};
163     unsigned char expectedDecoded[cRgb8A1PatchSize] = {
164         68, 187, 238, 255, 68, 187, 238, 255, 109, 228, 255, 255, 109, 228, 255, 255,
165         0, 85, 170, 255, 27, 146, 197, 255, 68, 187, 238, 255, 68, 187, 238, 255,
166         0, 85, 170, 255, 0, 85, 170, 255, 0, 85, 170, 255, 27, 146, 197, 255,
167         0, 85, 170, 255, 0, 85, 170, 255, 0, 85, 170, 255, 0, 85, 170, 255};
168     decodeRgb8A1Test((const etc1_byte*)encoded, (const etc1_byte*)expectedDecoded);
169 }
170 
TEST_F(Etc2Test,ETC2RGB8A1_OP1_H)171 TEST_F(Etc2Test, ETC2RGB8A1_OP1_H) {
172     const unsigned char encoded[cRgbEncodedSize] = {54, 251, 38, 114, 55, 126, 64, 133};
173     unsigned char expectedDecoded[cRgb8A1PatchSize] = {
174         96, 215, 232, 255, 74, 210, 244, 255, 74, 210, 244, 255, 74, 210, 244, 255,
175         74, 210, 244, 255, 74, 210, 244, 255, 74, 210, 244, 255, 74, 210, 244, 255,
176         62, 198, 232, 255, 74, 210, 244, 255, 74, 210, 244, 255, 96, 215, 232, 255,
177         74, 210, 244, 255, 96, 215, 232, 255, 108, 227, 244, 255, 108, 227, 244, 255};
178     decodeRgb8A1Test((const etc1_byte*)encoded, (const etc1_byte*)expectedDecoded);
179 }
180 
TEST_F(Etc2Test,ETC2RGB8A1_OP1_Planar)181 TEST_F(Etc2Test, ETC2RGB8A1_OP1_Planar) {
182     const unsigned char encoded[cRgbEncodedSize] = {133, 15, 243, 23, 187, 211, 189, 62};
183     unsigned char expectedDecoded[cRgb8A1PatchSize] = {
184         8, 143, 219, 255, 17, 154, 223, 255, 26, 165, 227, 255, 35, 176, 231, 255,
185         35, 166, 227, 255, 44, 177, 231, 255, 53, 188, 235, 255, 62, 199, 239, 255,
186         63, 188, 235, 255, 72, 199, 239, 255, 81, 210, 243, 255, 90, 221, 247, 255,
187         90, 211, 243, 255, 99, 222, 247, 255, 108, 233, 251, 255, 117, 244, 255, 255};
188     decodeRgb8A1Test((const etc1_byte*)encoded, (const etc1_byte*)expectedDecoded);
189 }
190 
TEST_F(Etc2Test,ETC2RGB8A1_OP0_diff_noflipped)191 TEST_F(Etc2Test, ETC2RGB8A1_OP0_diff_noflipped) {
192     const unsigned char encoded[cRgbEncodedSize] = {118, 223, 240, 4, 193, 19, 210, 0};
193     unsigned char expectedDecoded[cRgb8A1PatchSize] = {
194         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 116, 231, 255, 255,
195         0, 0, 0, 0, 115, 222, 247, 255, 116, 231, 255, 255, 99, 214, 247, 255,
196         115, 222, 247, 255, 115, 222, 247, 255, 99, 214, 247, 255, 82, 197, 230, 255,
197         115, 222, 247, 255, 115, 222, 247, 255, 99, 214, 247, 255, 82, 197, 230, 255};
198     decodeRgb8A1Test((const etc1_byte*)encoded, (const etc1_byte*)expectedDecoded);
199 }
200 
TEST_F(Etc2Test,ETC2RGB8A1_OP0_T)201 TEST_F(Etc2Test, ETC2RGB8A1_OP0_T) {
202     const unsigned char encoded[cRgbEncodedSize] = {6, 173, 5, 168, 230, 102, 76, 128};
203     unsigned char expectedDecoded[cRgb8A1PatchSize] = {
204         34, 170, 221, 255, 34, 170, 221, 255, 34, 170, 221, 255, 34, 170, 221, 255,
205         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
206         0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 147, 255, 0, 62, 147, 255,
207         34, 170, 221, 255, 23, 108, 193, 255, 23, 108, 193, 255, 0, 0, 0, 0};
208     decodeRgb8A1Test((const etc1_byte*)encoded, (const etc1_byte*)expectedDecoded);
209 }
210 
TEST_F(Etc2Test,ETC2RGB8A1_OP0_H)211 TEST_F(Etc2Test, ETC2RGB8A1_OP0_H) {
212     const unsigned char encoded[cRgbEncodedSize] = {149, 14, 131, 89, 19, 55, 117, 81};
213     unsigned char expectedDecoded[cRgb8A1PatchSize] = {
214         0, 86, 171, 255, 0, 86, 171, 255, 0, 86, 171, 255, 0, 86, 171, 255,
215         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 154, 205, 255,
216         0, 0, 0, 0, 18, 154, 205, 255, 18, 154, 205, 255, 18, 154, 205, 255,
217         50, 186, 237, 255, 50, 186, 237, 255, 50, 186, 237, 255, 50, 186, 237, 255};
218     decodeRgb8A1Test((const etc1_byte*)encoded, (const etc1_byte*)expectedDecoded);
219 }
220 
TEST_F(Etc2Test,ETC2RGB8A1_OP0_Planer)221 TEST_F(Etc2Test, ETC2RGB8A1_OP0_Planer) {
222     const unsigned char encoded[cRgbEncodedSize] = {35, 73, 249, 152, 191, 212, 60, 253};
223     unsigned char expectedDecoded[cRgb8A1PatchSize] = {
224         69, 201, 239, 255, 64, 199, 238, 255, 59, 196, 237, 255, 53, 194, 236, 255,
225         85, 209, 241, 255, 80, 206, 240, 255, 75, 204, 239, 255, 70, 201, 238, 255,
226         102, 216, 243, 255, 96, 214, 242, 255, 91, 211, 241, 255, 86, 209, 240, 255,
227         118, 224, 245, 255, 113, 221, 244, 255, 107, 219, 243, 255, 102, 216, 242, 255};
228     decodeRgb8A1Test((const etc1_byte*)encoded, (const etc1_byte*)expectedDecoded);
229 }
230