• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 The libgav1 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 #ifndef LIBGAV1_SRC_UTILS_BLOCK_PARAMETERS_HOLDER_H_
18 #define LIBGAV1_SRC_UTILS_BLOCK_PARAMETERS_HOLDER_H_
19 
20 #include <memory>
21 
22 #include "src/utils/array_2d.h"
23 #include "src/utils/compiler_attributes.h"
24 #include "src/utils/constants.h"
25 #include "src/utils/parameter_tree.h"
26 #include "src/utils/types.h"
27 
28 namespace libgav1 {
29 
30 // Holds a 2D array of |ParameterTree| objects. Each tree stores the parameters
31 // corresponding to a superblock.
32 class BlockParametersHolder {
33  public:
34   BlockParametersHolder() = default;
35 
36   // Not copyable or movable.
37   BlockParametersHolder(const BlockParametersHolder&) = delete;
38   BlockParametersHolder& operator=(const BlockParametersHolder&) = delete;
39 
40   // If |use_128x128_superblock| is true, 128x128 superblocks will be used,
41   // otherwise 64x64 superblocks will be used.
42   LIBGAV1_MUST_USE_RESULT bool Reset(int rows4x4, int columns4x4,
43                                      bool use_128x128_superblock);
44 
45   // Finds the BlockParameters corresponding to |row4x4| and |column4x4|. This
46   // is done as a simple look up of the |block_parameters_cache_| matrix.
47   // Returns nullptr if the BlockParameters cannot be found.
Find(int row4x4,int column4x4)48   BlockParameters* Find(int row4x4, int column4x4) const {
49     return block_parameters_cache_[row4x4][column4x4];
50   }
51 
Address(int row4x4,int column4x4)52   BlockParameters** Address(int row4x4, int column4x4) {
53     return block_parameters_cache_.data() + row4x4 * columns4x4_ + column4x4;
54   }
55 
Address(int row4x4,int column4x4)56   BlockParameters* const* Address(int row4x4, int column4x4) const {
57     return block_parameters_cache_.data() + row4x4 * columns4x4_ + column4x4;
58   }
59 
columns4x4()60   int columns4x4() const { return columns4x4_; }
61 
62   // Returns the ParameterTree corresponding to superblock starting at (|row|,
63   // |column|).
Tree(int row,int column)64   ParameterTree* Tree(int row, int column) { return trees_[row][column].get(); }
65 
66   // Fills the cache matrix for the block starting at |row4x4|, |column4x4| of
67   // size |block_size| with the pointer |bp|.
68   void FillCache(int row4x4, int column4x4, BlockSize block_size,
69                  BlockParameters* bp);
70 
71  private:
72   int rows4x4_ = 0;
73   int columns4x4_ = 0;
74   bool use_128x128_superblock_ = false;
75   Array2D<std::unique_ptr<ParameterTree>> trees_;
76 
77   // This is a 2d array of size |rows4x4_| * |columns4x4_|. This is filled in by
78   // FillCache() and used by Find() to perform look ups using exactly one look
79   // up (instead of traversing the entire tree).
80   Array2D<BlockParameters*> block_parameters_cache_;
81 };
82 
83 }  // namespace libgav1
84 
85 #endif  // LIBGAV1_SRC_UTILS_BLOCK_PARAMETERS_HOLDER_H_
86