/src/vvenc/source/Lib/CommonLib/QuantRDOQ.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 QuantRDOQ.h |
43 | | \brief RDOQ 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 "Quant.h" |
53 | | |
54 | | //! \ingroup CommonLib |
55 | | //! \{ |
56 | | |
57 | | namespace vvenc { |
58 | | |
59 | | // ==================================================================================================================== |
60 | | // Class definition |
61 | | // ==================================================================================================================== |
62 | | |
63 | | /// transform and quantization class |
64 | | class QuantRDOQ : public Quant |
65 | | { |
66 | | public: |
67 | | QuantRDOQ( const Quant* other, bool useScalingLists ); |
68 | | ~QuantRDOQ(); |
69 | | |
70 | | public: |
71 | | void setFlatScalingList ( const int maxLog2TrDynamicRange[MAX_NUM_CH], const BitDepths &bitDepths ); |
72 | | // quantization |
73 | | void quant ( TransformUnit& tu, const ComponentID compID, const CCoeffBuf& pSrc, TCoeff &uiAbsSum, const QpParam& cQP, const Ctx& ctx ); |
74 | | void forwardRDPCM ( TransformUnit& tu, const ComponentID compID, const CCoeffBuf& pSrc, TCoeff &uiAbsSum, const QpParam& cQP, const Ctx &ctx ); |
75 | | void rateDistOptQuantTS ( TransformUnit& tu, const ComponentID compID, const CCoeffBuf& coeffs, TCoeff &absSum, const QpParam& qp, const Ctx &ctx ); |
76 | | |
77 | | private: |
78 | 0 | double* xGetErrScaleCoeffSL ( uint32_t list, uint32_t sizeX, uint32_t sizeY, int qp ) { return m_errScale[sizeX][sizeY][list][qp]; }; //!< get Error Scale Coefficent |
79 | | double xGetErrScaleCoeff ( const bool needsSqrt2, SizeType width, SizeType height, int qp, const int maxLog2TrDynamicRange, const int channelBitDepth, bool bTransformSkip); |
80 | 0 | double& xGetErrScaleCoeffNoScalingList ( uint32_t list, uint32_t sizeX, uint32_t sizeY, int qp ) { return m_errScaleNoScalingList[sizeX][sizeY][list][qp]; }; //!< get Error Scale Coefficent |
81 | | void xInitScalingList ( const QuantRDOQ* other ); |
82 | | void xDestroyScalingList (); |
83 | | void xSetErrScaleCoeff ( uint32_t list, uint32_t sizeX, uint32_t sizeY, int qp, const int maxLog2TrDynamicRange[MAX_NUM_CH], const BitDepths &bitDepths ); |
84 | | void xDequantSample ( TCoeff& pRes, TCoeffSig& coeff, const TrQuantParams& trQuantParams ); |
85 | | // RDOQ functions |
86 | | void xRateDistOptQuant ( TransformUnit& tu, const ComponentID compID, const CCoeffBuf& pSrc, TCoeff &uiAbsSum, const QpParam& cQP, const Ctx &ctx); |
87 | | |
88 | | inline uint32_t xGetCodedLevel( double& rd64CodedCost, |
89 | | double& rd64CodedCost0, |
90 | | double& rd64CodedCostSig, |
91 | | Intermediate_Int lLevelDouble, |
92 | | uint32_t uiMaxAbsLevel, |
93 | | const BinFracBits* fracBitsSig, |
94 | | const BinFracBits& fracBitsPar, |
95 | | const BinFracBits& fracBitsGt1, |
96 | | const BinFracBits& fracBitsGt2, |
97 | | const int remRegBins, |
98 | | unsigned goRiceZero, |
99 | | uint16_t ui16AbsGoRice, |
100 | | int iQBits, |
101 | | double errorScale, |
102 | | bool bLast, |
103 | | const int maxLog2TrDynamicRange ) const; |
104 | | inline int xGetICRate ( const uint32_t uiAbsLevel, |
105 | | const BinFracBits& fracBitsPar, |
106 | | const BinFracBits& fracBitsGt1, |
107 | | const BinFracBits& fracBitsGt2, |
108 | | const int remRegBins, |
109 | | unsigned goRiceZero, |
110 | | const uint16_t ui16AbsGoRice, |
111 | | const int maxLog2TrDynamicRange ) const; |
112 | | inline double xGetRateLast ( const int* lastBitsX, const int* lastBitsY, |
113 | | unsigned PosX, unsigned PosY ) const; |
114 | | |
115 | | inline double xGetRateSigCoeffGroup( const BinFracBits& fracBitsSigCG, unsigned uiSignificanceCoeffGroup ) const; |
116 | | |
117 | | inline double xGetRateSigCoef ( const BinFracBits& fracBitsSig, unsigned uiSignificance ) const; |
118 | | |
119 | | inline double xGetICost ( double dRate ) const; |
120 | | inline double xGetIEPRate ( ) const; |
121 | | |
122 | | inline uint32_t xGetCodedLevelTSPred( double& rd64CodedCost, |
123 | | double& rd64CodedCost0, |
124 | | double& rd64CodedCostSig, |
125 | | Intermediate_Int levelDouble, |
126 | | int qBits, |
127 | | double errorScale, |
128 | | uint32_t coeffLevels[], |
129 | | double coeffLevelError[], |
130 | | const BinFracBits* fracBitsSig, |
131 | | const BinFracBits& fracBitsPar, |
132 | | CoeffCodingContext& cctx, |
133 | | const FracBitsAccess& fracBitsAccess, |
134 | | const BinFracBits& fracBitsSign, |
135 | | const BinFracBits& fracBitsGt1, |
136 | | const uint8_t sign, |
137 | | int rightPixel, |
138 | | int belowPixel, |
139 | | uint16_t ricePar, |
140 | | bool isLast, |
141 | | const int maxLog2TrDynamicRange, |
142 | | int& numUsedCtxBins |
143 | | ) const; |
144 | | |
145 | | inline int xGetICRateTS ( const uint32_t absLevel, |
146 | | const BinFracBits& fracBitsPar, |
147 | | const CoeffCodingContext& cctx, |
148 | | const FracBitsAccess& fracBitsAccess, |
149 | | const BinFracBits& fracBitsSign, |
150 | | const BinFracBits& fracBitsGt1, |
151 | | int& numCtxBins, |
152 | | const uint8_t sign, |
153 | | const uint16_t ricePar, |
154 | | const int maxLog2TrDynamicRange ) const; |
155 | | private: |
156 | | bool m_isErrScaleListOwner; |
157 | | |
158 | | double* m_errScale [SCALING_LIST_SIZE_NUM][SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of quantization matrix coefficient 4x4 |
159 | | double m_errScaleNoScalingList [SCALING_LIST_SIZE_NUM][SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of quantization matrix coefficient 4x4 |
160 | | // temporary buffers for RDOQ |
161 | | double m_pdCostCoeff [MAX_TB_SIZEY * MAX_TB_SIZEY]; |
162 | | double m_pdCostSig [MAX_TB_SIZEY * MAX_TB_SIZEY]; |
163 | | double m_pdCostCoeff0 [MAX_TB_SIZEY * MAX_TB_SIZEY]; |
164 | | double m_pdCostCoeffGroupSig [(MAX_TB_SIZEY * MAX_TB_SIZEY) >> MLS_CG_SIZE]; // even if CG size is 2 (if one of the sides is 2) instead of 4, there should be enough space |
165 | | int m_rateIncUp [MAX_TB_SIZEY * MAX_TB_SIZEY]; |
166 | | int m_rateIncDown [MAX_TB_SIZEY * MAX_TB_SIZEY]; |
167 | | int m_sigRateDelta [MAX_TB_SIZEY * MAX_TB_SIZEY]; |
168 | | TCoeff m_deltaU [MAX_TB_SIZEY * MAX_TB_SIZEY]; |
169 | | TCoeff m_fullCoeff [MAX_TB_SIZEY * MAX_TB_SIZEY]; |
170 | | int m_bdpcm; |
171 | | int m_testedLevels; |
172 | | };// END CLASS DEFINITION QuantRDOQ |
173 | | |
174 | | } // namespace vvenc |
175 | | |
176 | | //! \} |
177 | | |