• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The libgav1 Authors
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 <algorithm>
16 #include <cstdint>
17 #include <tuple>
18 #include <vector>
19 
20 #include "gmock/gmock.h"
21 #include "gtest/gtest.h"
22 #include "src/utils/common.h"
23 #include "src/utils/constants.h"
24 
25 namespace libgav1 {
26 namespace {
27 
28 // Import all the constants in the anonymous namespace.
29 #include "src/scan_tables.inc"
30 
31 class ScanOrderTest
32     : public testing::TestWithParam<std::tuple<TransformClass, TransformSize>> {
33  public:
34   ScanOrderTest() = default;
35   ScanOrderTest(const ScanOrderTest&) = delete;
36   ScanOrderTest& operator=(const ScanOrderTest&) = delete;
37   ~ScanOrderTest() override = default;
38 
39  protected:
40   TransformClass tx_class_ = std::get<0>(GetParam());
41   TransformSize tx_size_ = std::get<1>(GetParam());
42 };
43 
TEST_P(ScanOrderTest,AllIndicesAreScannedExactlyOnce)44 TEST_P(ScanOrderTest, AllIndicesAreScannedExactlyOnce) {
45   const int tx_width = kTransformWidth[tx_size_];
46   const int tx_height = kTransformHeight[tx_size_];
47   int num_indices;
48   if (tx_class_ == kTransformClass2D || std::max(tx_width, tx_height) == 64) {
49     const int clamped_tx_width = std::min(32, tx_width);
50     const int clamped_tx_height = std::min(32, tx_height);
51     num_indices = clamped_tx_width * clamped_tx_height;
52   } else {
53     num_indices =
54         (std::max(tx_width, tx_height) > 16) ? 64 : tx_width * tx_height;
55   }
56   const uint16_t* const scan = kScan[tx_class_][tx_size_];
57   ASSERT_NE(scan, nullptr);
58   // Ensure that all the indices are scanned exactly once.
59   std::vector<int> scanned;
60   scanned.resize(num_indices);
61   for (int i = 0; i < num_indices; ++i) {
62     scanned[scan[i]]++;
63   }
64   EXPECT_THAT(scanned, testing::Each(1));
65 }
66 
67 constexpr TransformClass kTestTransformClasses[] = {
68     kTransformClass2D, kTransformClassVertical, kTransformClassHorizontal};
69 
70 constexpr TransformSize kTestTransformSizes[] = {
71     kTransformSize4x4,   kTransformSize4x8,   kTransformSize4x16,
72     kTransformSize8x4,   kTransformSize8x8,   kTransformSize8x16,
73     kTransformSize8x32,  kTransformSize16x4,  kTransformSize16x8,
74     kTransformSize16x16, kTransformSize16x32, kTransformSize16x64,
75     kTransformSize32x8,  kTransformSize32x16, kTransformSize32x32,
76     kTransformSize32x64, kTransformSize64x16, kTransformSize64x32,
77     kTransformSize64x64};
78 
79 INSTANTIATE_TEST_SUITE_P(
80     C, ScanOrderTest,
81     testing::Combine(testing::ValuesIn(kTestTransformClasses),
82                      testing::ValuesIn(kTestTransformSizes)));
83 
84 }  // namespace
85 }  // namespace libgav1
86