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