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