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