1 // Copyright 2018 Google LLC
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 // https://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 "src/decoder/weight_infill.h"
16 #include "src/decoder/footprint.h"
17
18 #include <gtest/gtest.h>
19
20 #include <vector>
21
22 namespace astc_codec {
23
24 namespace {
25
26 // Make sure that the physical size of the bit representations for certain
27 // dimensions of weight grids matches our expectations
TEST(ASTCWeightInfillTest,TestGetBitCount)28 TEST(ASTCWeightInfillTest, TestGetBitCount) {
29 // Bit encodings
30 EXPECT_EQ(32, CountBitsForWeights(4, 4, 3));
31 EXPECT_EQ(48, CountBitsForWeights(4, 4, 7));
32 EXPECT_EQ(24, CountBitsForWeights(2, 4, 7));
33 EXPECT_EQ(8, CountBitsForWeights(2, 4, 1));
34
35 // Trit encodings
36 EXPECT_EQ(32, CountBitsForWeights(4, 5, 2));
37 EXPECT_EQ(26, CountBitsForWeights(4, 4, 2));
38 EXPECT_EQ(52, CountBitsForWeights(4, 5, 5));
39 EXPECT_EQ(42, CountBitsForWeights(4, 4, 5));
40
41 // Quint encodings
42 EXPECT_EQ(21, CountBitsForWeights(3, 3, 4));
43 EXPECT_EQ(38, CountBitsForWeights(4, 4, 4));
44 EXPECT_EQ(49, CountBitsForWeights(3, 7, 4));
45 EXPECT_EQ(52, CountBitsForWeights(4, 3, 19));
46 EXPECT_EQ(70, CountBitsForWeights(4, 4, 19));
47 }
48
49 // Make sure that we bilerp our weights properly
TEST(ASTCWeightInfillTest,TestInfillBilerp)50 TEST(ASTCWeightInfillTest, TestInfillBilerp) {
51 std::vector<int> weights = InfillWeights(
52 {{ 1, 3, 5, 3, 5, 7, 5, 7, 9 }}, Footprint::Get5x5(), 3, 3);
53
54 std::vector<int> expected_weights = {
55 1, 2, 3, 4, 5,
56 2, 3, 4, 5, 6,
57 3, 4, 5, 6, 7,
58 4, 5, 6, 7, 8,
59 5, 6, 7, 8, 9 };
60
61 ASSERT_EQ(weights.size(), expected_weights.size());
62 for (int i = 0; i < weights.size(); ++i) {
63 EXPECT_EQ(weights[i], expected_weights[i]);
64 }
65 }
66
67 } // namespace
68
69 } // namespace astc_codec
70