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_QUANTIZER_H_ 18 #define LIBGAV1_SRC_QUANTIZER_H_ 19 20 #include <cstdint> 21 22 #include "src/utils/constants.h" 23 #include "src/utils/segmentation.h" 24 #include "src/utils/types.h" 25 26 namespace libgav1 { 27 28 // Implements the dequantization functions of Section 7.12.2. 29 class Quantizer { 30 public: 31 Quantizer(int bitdepth, const QuantizerParameters* params); 32 33 // Returns the quantizer value for the dc coefficient for the given plane. 34 // The caller should call GetQIndex() with Tile::current_quantizer_index_ as 35 // the |base_qindex| argument, and pass the return value as the |qindex| 36 // argument to this method. 37 int GetDcValue(Plane plane, int qindex) const; 38 39 // Returns the quantizer value for the ac coefficient for the given plane. 40 // The caller should call GetQIndex() with Tile::current_quantizer_index_ as 41 // the |base_qindex| argument, and pass the return value as the |qindex| 42 // argument to this method. 43 int GetAcValue(Plane plane, int qindex) const; 44 45 private: 46 const QuantizerParameters& params_; 47 const int16_t* dc_lookup_; 48 const int16_t* ac_lookup_; 49 }; 50 51 // Get the quantizer index for the |index|th segment. 52 // 53 // This function has two use cases. What should be passed as the |base_qindex| 54 // argument depends on the use case. 55 // 1. While parsing the uncompressed header or transform type, pass 56 // Quantizer::base_index. 57 // Note: In this use case, the caller only cares about whether the return 58 // value is zero. 59 // 2. To generate the |qindex| argument to Quantizer::GetDcQuant() or 60 // Quantizer::GetAcQuant(), pass Tile::current_quantizer_index_. 61 int GetQIndex(const Segmentation& segmentation, int index, int base_qindex); 62 63 } // namespace libgav1 64 65 #endif // LIBGAV1_SRC_QUANTIZER_H_ 66