/src/vvenc/source/Lib/CommonLib/Quant.h
Line | Count | Source |
1 | | /* ----------------------------------------------------------------------------- |
2 | | The copyright in this software is being made available under the Clear BSD |
3 | | License, included below. No patent rights, trademark rights and/or |
4 | | other Intellectual Property Rights other than the copyrights concerning |
5 | | the Software are granted under this license. |
6 | | |
7 | | The Clear BSD License |
8 | | |
9 | | Copyright (c) 2019-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVenC Authors. |
10 | | All rights reserved. |
11 | | |
12 | | Redistribution and use in source and binary forms, with or without modification, |
13 | | are permitted (subject to the limitations in the disclaimer below) provided that |
14 | | the following conditions are met: |
15 | | |
16 | | * Redistributions of source code must retain the above copyright notice, |
17 | | this list of conditions and the following disclaimer. |
18 | | |
19 | | * Redistributions in binary form must reproduce the above copyright |
20 | | notice, this list of conditions and the following disclaimer in the |
21 | | documentation and/or other materials provided with the distribution. |
22 | | |
23 | | * Neither the name of the copyright holder nor the names of its |
24 | | contributors may be used to endorse or promote products derived from this |
25 | | software without specific prior written permission. |
26 | | |
27 | | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY |
28 | | THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
29 | | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
30 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
31 | | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
32 | | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
33 | | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
34 | | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
35 | | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
36 | | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
37 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
38 | | POSSIBILITY OF SUCH DAMAGE. |
39 | | |
40 | | |
41 | | ------------------------------------------------------------------------------------------- */ |
42 | | /** \file Quant.h |
43 | | \brief base quantization class (header) |
44 | | */ |
45 | | |
46 | | #pragma once |
47 | | |
48 | | #include "CommonDef.h" |
49 | | #include "Unit.h" |
50 | | #include "Contexts.h" |
51 | | #include "ContextModelling.h" |
52 | | #include "UnitPartitioner.h" |
53 | | |
54 | | //! \ingroup CommonLib |
55 | | //! \{ |
56 | | |
57 | | namespace vvenc { |
58 | | |
59 | | #if defined(TARGET_SIMD_X86) && ENABLE_SIMD_OPT_QUANT |
60 | | using namespace x86_simd; |
61 | | #endif |
62 | | |
63 | | // ==================================================================================================================== |
64 | | // Constants |
65 | | // ==================================================================================================================== |
66 | | |
67 | | #define QP_BITS 15 |
68 | | |
69 | | static inline int getTransformShift(const int channelBitDepth, const Size size, const int maxLog2TrDynamicRange) |
70 | 0 | { |
71 | 0 | return maxLog2TrDynamicRange - channelBitDepth - ( ( Log2(size.width) + Log2(size.height) ) >> 1 ); |
72 | 0 | } Unexecuted instantiation: vvencimpl.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: InitX86.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: DepQuant_sse41.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: Quant_sse41.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: Trafo_sse41.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: DepQuant_sse42.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: DepQuant_avx2.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: Quant_avx2.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: Trafo_avx2.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: DepQuant.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: Quant.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: QuantRDOQ2.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: EncLib.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: QuantRDOQ.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: EncGOP.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: EncPicture.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: EncSlice.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: InterSearch.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: LoopFilter.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: TrQuant.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: EncCu.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: EncModeCtrl.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: IntraSearch.cpp:vvenc::getTransformShift(int, vvenc::Size, int) Unexecuted instantiation: DecCu.cpp:vvenc::getTransformShift(int, vvenc::Size, int) |
73 | | |
74 | | static inline int getScalingListType(const PredMode predMode, const ComponentID compID) |
75 | 0 | { |
76 | 0 | return ((predMode == MODE_INTRA) ? 0 : MAX_NUM_COMP) + compID; |
77 | 0 | } Unexecuted instantiation: vvencimpl.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: InitX86.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: DepQuant_sse41.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: Quant_sse41.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: Trafo_sse41.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: DepQuant_sse42.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: DepQuant_avx2.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: Quant_avx2.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: Trafo_avx2.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: DepQuant.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: Quant.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: QuantRDOQ2.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: EncLib.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: QuantRDOQ.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: EncGOP.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: EncPicture.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: EncSlice.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: InterSearch.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: LoopFilter.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: TrQuant.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: EncCu.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: EncModeCtrl.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: IntraSearch.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) Unexecuted instantiation: DecCu.cpp:vvenc::getScalingListType(vvenc::PredMode, vvenc::ComponentID) |
78 | | |
79 | | // ==================================================================================================================== |
80 | | // Class definition |
81 | | // ==================================================================================================================== |
82 | | struct TrQuantParams |
83 | | { |
84 | | int rightShift; |
85 | | int qScale; |
86 | | }; |
87 | | |
88 | | /// QP struct |
89 | | class QpParam |
90 | | { |
91 | | public: |
92 | | short Qps[2]; |
93 | | int8_t pers[2]; |
94 | | int8_t rems[2]; |
95 | | |
96 | | public: |
97 | | QpParam(const TransformUnit& tu, const ComponentID &compID, const bool allowACTQpoffset = true); |
98 | | |
99 | 0 | int Qp ( const bool ts ) const { return Qps [ts?1:0]; } |
100 | 0 | int per( const bool ts ) const { return pers[ts?1:0]; } |
101 | 0 | int rem( const bool ts ) const { return rems[ts?1:0]; } |
102 | | }; // END STRUCT DEFINITION QpParam |
103 | | |
104 | | /// transform and quantization class |
105 | | class Quant |
106 | | { |
107 | | public: |
108 | | Quant( const Quant* other, bool useScalingLists ); |
109 | | virtual ~Quant(); |
110 | | |
111 | | // initialize class |
112 | | virtual void init( int rdoq = 0, bool useRDOQTS = false, int thrVal = 8 ); |
113 | | |
114 | | public: |
115 | | |
116 | 0 | void setLambdas ( const double lambdas[MAX_NUM_COMP] ) { for (uint32_t component = 0; component < MAX_NUM_COMP; component++) m_lambdas[component] = lambdas[component]; } |
117 | 0 | void selectLambda ( const ComponentID compId ) { m_dLambda = m_lambdas[ compId ]; } |
118 | 0 | void getLambdas ( double (&lambdas)[MAX_NUM_COMP]) const { for (uint32_t component = 0; component < MAX_NUM_COMP; component++) lambdas[component] = m_lambdas[component]; } |
119 | 0 | void scaleLambda ( const double scale) { m_dLambda *= scale;} |
120 | | |
121 | 0 | int* getQuantCoeff ( uint32_t list, int qp, uint32_t sizeX, uint32_t sizeY ) { return m_quantCoef [sizeX][sizeY][list][qp]; }; //!< get Quant Coefficent |
122 | 0 | int* getDequantCoeff ( uint32_t list, int qp, uint32_t sizeX, uint32_t sizeY ) { return m_dequantCoef [sizeX][sizeY][list][qp]; }; //!< get DeQuant Coefficent |
123 | | |
124 | | bool getUseScalingList ( const uint32_t width, const uint32_t height, const bool isTransformSkip, const bool lfnstApplied ) |
125 | 0 | { |
126 | 0 | return (m_scalingListEnabled && !isTransformSkip && (!lfnstApplied)); |
127 | 0 | }; |
128 | 0 | bool getScalingListEnabled () { return m_scalingListEnabled; } |
129 | | virtual void setFlatScalingList ( const int maxLog2TrDynamicRange[MAX_NUM_CH], const BitDepths &bitDepths ); |
130 | | |
131 | | // quantization |
132 | | virtual void quant ( TransformUnit& tu, const ComponentID compID, const CCoeffBuf& pSrc, TCoeff &uiAbsSum, const QpParam& cQP, const Ctx& ctx ); |
133 | | // de-quantization |
134 | | virtual void dequant ( const TransformUnit& tu, CoeffBuf& dstCoeff, const ComponentID compID, const QpParam& cQP ); |
135 | | |
136 | | protected: |
137 | | bool xNeedRDOQ ( TransformUnit& tu, const ComponentID compID, const CCoeffBuf& pSrc, const QpParam& cQP ); |
138 | | private: |
139 | | void xInitScalingList ( const Quant* other, bool useScalingLists ); |
140 | | void xDestroyScalingList (); |
141 | | void xSetFlatScalingList ( uint32_t list, uint32_t sizeX, uint32_t sizeY, int qp ); |
142 | | void xSignBitHidingHDQ ( TCoeffSig* pQCoef, const TCoeff* pCoef, TCoeff* deltaU, const CoeffCodingContext& cctx, int &lastPos, const int maxLog2TrDynamicRange); |
143 | | void ( *xDeQuant) (const int maxX,const int maxY,const int scale,const TCoeffSig*const piQCoef,const size_t piQCfStride,TCoeff *const piCoef,const int rightShift,const int inputMaximum,const TCoeff transformMaximum); |
144 | | void ( *xQuant ) ( const TransformUnit tu, const ComponentID compID, |
145 | | const CCoeffBuf& piCoef, CoeffSigBuf piQCoef, |
146 | | TCoeff& uiAbsSum, int& lastScanPos, TCoeff* deltaU, |
147 | | const int defaultQuantisationCoefficient, const int iQBits, const int64_t iAdd, |
148 | | const TCoeff entropyCodingMinimum, const TCoeff entropyCodingMaximum, |
149 | | const bool signHiding, |
150 | | const TCoeff m_thrVal ); |
151 | | bool ( *xNeedRdoq ) ( const TCoeff* pCoeff, size_t numCoeff, int quantCoeff, int64_t offset, int shift ); |
152 | | |
153 | | #if defined(TARGET_SIMD_X86) && ENABLE_SIMD_OPT_QUANT |
154 | | void initQuantX86(); |
155 | | template <X86_VEXT vext> |
156 | | void _initQuantX86(); |
157 | | #endif |
158 | | |
159 | | protected: |
160 | | int m_RDOQ; |
161 | | bool m_useRDOQTS; |
162 | | double m_dLambda; |
163 | | TCoeffSig m_tmpBdpcm[1 << ( MAX_TB_LOG2_SIZEY << 1 )]; |
164 | | int m_thrVal; |
165 | | |
166 | | private: |
167 | | double m_lambdas[MAX_NUM_COMP]; |
168 | | bool m_scalingListEnabled; |
169 | | bool m_isScalingListOwner; |
170 | | |
171 | | int *m_quantCoef [SCALING_LIST_SIZE_NUM][SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of quantization matrix coefficient 4x4 |
172 | | int *m_dequantCoef [SCALING_LIST_SIZE_NUM][SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of dequantization matrix coefficient 4x4 |
173 | | };// END CLASS DEFINITION Quant |
174 | | |
175 | | } // namespace vvenc |
176 | | |
177 | | //! \} |
178 | | |