xref: /aosp_15_r20/external/libgav1/src/loop_restoration_info.h (revision 095378508e87ed692bf8dfeb34008b65b3735891)
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_LOOP_RESTORATION_INFO_H_
18 #define LIBGAV1_SRC_LOOP_RESTORATION_INFO_H_
19 
20 #include <array>
21 #include <cstdint>
22 
23 #include "src/dsp/common.h"
24 #include "src/symbol_decoder_context.h"
25 #include "src/utils/constants.h"
26 #include "src/utils/dynamic_buffer.h"
27 #include "src/utils/entropy_decoder.h"
28 #include "src/utils/types.h"
29 
30 namespace libgav1 {
31 
32 struct LoopRestorationUnitInfo {
33   int row_start;
34   int row_end;
35   int column_start;
36   int column_end;
37 };
38 
39 class LoopRestorationInfo {
40  public:
41   LoopRestorationInfo() = default;
42 
43   // Non copyable/movable.
44   LoopRestorationInfo(const LoopRestorationInfo&) = delete;
45   LoopRestorationInfo& operator=(const LoopRestorationInfo&) = delete;
46   LoopRestorationInfo(LoopRestorationInfo&&) = delete;
47   LoopRestorationInfo& operator=(LoopRestorationInfo&&) = delete;
48 
49   bool Reset(const LoopRestoration* loop_restoration, uint32_t width,
50              uint32_t height, int8_t subsampling_x, int8_t subsampling_y,
51              bool is_monochrome);
52   // Populates the |unit_info| for the super block at |row4x4|, |column4x4|.
53   // Returns true on success, false otherwise.
54   bool PopulateUnitInfoForSuperBlock(Plane plane, BlockSize block_size,
55                                      bool is_superres_scaled,
56                                      uint8_t superres_scale_denominator,
57                                      int row4x4, int column4x4,
58                                      LoopRestorationUnitInfo* unit_info) const;
59   void ReadUnitCoefficients(EntropyDecoder* reader,
60                             SymbolDecoderContext* symbol_decoder_context,
61                             Plane plane, int unit_id,
62                             std::array<RestorationUnitInfo, kMaxPlanes>*
63                                 reference_unit_info);  // 5.11.58.
64   void ReadWienerInfo(
65       EntropyDecoder* reader, Plane plane, int unit_id,
66       std::array<RestorationUnitInfo, kMaxPlanes>* reference_unit_info);
67   void ReadSgrProjInfo(
68       EntropyDecoder* reader, Plane plane, int unit_id,
69       std::array<RestorationUnitInfo, kMaxPlanes>* reference_unit_info);
70 
71   // Getters.
loop_restoration_info(Plane plane,int unit_id)72   const RestorationUnitInfo* loop_restoration_info(Plane plane,
73                                                    int unit_id) const {
74     return &loop_restoration_info_[plane][unit_id];
75   }
76 
num_horizontal_units(Plane plane)77   int num_horizontal_units(Plane plane) const {
78     return num_horizontal_units_[plane];
79   }
num_vertical_units(Plane plane)80   int num_vertical_units(Plane plane) const {
81     return num_vertical_units_[plane];
82   }
num_units(Plane plane)83   int num_units(Plane plane) const { return num_units_[plane]; }
84 
85  private:
86   // If plane_needs_filtering_[plane] is true, loop_restoration_info_[plane]
87   // points to an array of num_units_[plane] elements.
88   RestorationUnitInfo* loop_restoration_info_[kMaxPlanes];
89   // Owns the memory that loop_restoration_info_[plane] points to.
90   DynamicBuffer<RestorationUnitInfo> loop_restoration_info_buffer_;
91   bool plane_needs_filtering_[kMaxPlanes];
92   const LoopRestoration* loop_restoration_;
93   int8_t subsampling_x_;
94   int8_t subsampling_y_;
95   int num_horizontal_units_[kMaxPlanes];
96   int num_vertical_units_[kMaxPlanes];
97   int num_units_[kMaxPlanes];
98 };
99 
100 }  // namespace libgav1
101 
102 #endif  // LIBGAV1_SRC_LOOP_RESTORATION_INFO_H_
103