/work/vvenc/source/Lib/CommonLib/QuantRDOQ2.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 QuantRDOQ2.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 "QuantRDOQ.h" |
53 | | |
54 | | //! \ingroup CommonLib |
55 | | //! \{ |
56 | | |
57 | | namespace vvenc { |
58 | | |
59 | | typedef int64_t cost_t ; |
60 | | |
61 | | |
62 | | // ==================================================================================================================== |
63 | | // Class definition |
64 | | // ==================================================================================================================== |
65 | | |
66 | | /// transform and quantization class |
67 | | class QuantRDOQ2 : public QuantRDOQ |
68 | | { |
69 | | public: |
70 | | QuantRDOQ2( const Quant* other, bool useScalingLists, bool enableOpt ); |
71 | | ~QuantRDOQ2(); |
72 | | |
73 | | public: |
74 | | virtual void setFlatScalingList ( const int maxLog2TrDynamicRange[MAX_NUM_CH], const BitDepths &bitDepths ); |
75 | | virtual void quant ( TransformUnit &tu, const ComponentID compID, const CCoeffBuf &pSrc, TCoeff &uiAbsSum, const QpParam &cQP, const Ctx& ctx ); |
76 | | |
77 | | private: |
78 | 0 | int* xGetErrScaleCoeffSL ( unsigned list, unsigned sizeX, unsigned sizeY, int qp ) { return m_errScale[sizeX][sizeY][list][qp]; }; //!< get Error Scale Coefficent |
79 | | int xGetErrScaleCoeff ( const bool needsSqrt2, SizeType width, SizeType height, int qp, const int maxLog2TrDynamicRange, const int channelBitDepth); |
80 | 10.1M | int& xGetErrScaleCoeffNoScalingList ( unsigned list, unsigned sizeX, unsigned sizeY, int qp ) { return m_errScaleNoScalingList[sizeX][sizeY][list][qp]; }; //!< get Error Scale Coefficent |
81 | | |
82 | | void xInitScalingList ( const QuantRDOQ2* other ); |
83 | | void xDestroyScalingList (); |
84 | | void xSetErrScaleCoeff ( unsigned list, unsigned sizeX, unsigned sizeY, int qp, const int maxLog2TrDynamicRange[MAX_NUM_CH], const BitDepths &bitDepths ); |
85 | | void xSetErrScaleCoeffNoScalingList ( unsigned list, unsigned wIdx, unsigned hIdx, int qp, const int maxLog2TrDynamicRange[MAX_NUM_CH], const BitDepths &bitDepths ); |
86 | | void xInitLastPosBitsTab ( const CoeffCodingContext& cctx, const unsigned uiWidth, const unsigned uiHeight, const ChannelType chType, const FracBitsAccess& fracBits ); |
87 | | |
88 | | inline cost_t xiGetICost ( int iRate ) const; |
89 | | inline cost_t xGetIEPRate () const; |
90 | | inline cost_t xRateCostLevel ( const FracBitsAccess& fracBits, const CtxSet& parSet, const CtxSet& gt1Set, const CtxSet& gt2Set, const int ctxOffset, const uint32_t absLevel, const int remRegBins, const unsigned goRiceZero, const uint16_t goRiceParam ) const; |
91 | | NO_INLINE cost_t xRateCostLevelRare ( const FracBitsAccess& fracBits, const CtxSet& parSet, const CtxSet& gt1Set, const CtxSet& gt2Set, const int ctxOffset, const uint32_t absLevel, const int remRegBins, const unsigned goRiceZero, const uint16_t goRiceParam ) const; |
92 | | inline cost_t xiGetCostLast ( const unsigned uiPosX, const unsigned uiPosY, const ChannelType chType ) const; |
93 | | |
94 | | template< bool bSBH, bool bUseScalingList > |
95 | | int xRateDistOptQuantFast( TransformUnit &tu, const ComponentID &compID, const CCoeffBuf &pSrc, TCoeff &uiAbsSum, const QpParam &cQP, const Ctx &ctx ); |
96 | | int xRateDistOptQuant ( TransformUnit &tu, const ComponentID &compID, const CCoeffBuf &pSrc, TCoeff &uiAbsSum, const QpParam &cQP, const Ctx &ctx, bool bUseScalingList ); |
97 | | |
98 | | |
99 | | private: |
100 | | bool m_isErrScaleListOwner; |
101 | | // fractional bits of the integer lambda m_iLambda: the precision of lambda itself, not the rate unit (the rates are in |
102 | | // 1 / 2^SCALE_BITS bits and keep that unit; xiGetICost shifts these bits out again). 16: the smallest lambdas (about |
103 | | // 0.04 at QP 0) are still resolved to about 2e-4 |
104 | | static constexpr int LAMBDA_FRAC_BITS = 16; |
105 | | int64_t m_iLambda; ///< m_dLambda in 1 / 2^LAMBDA_FRAC_BITS (xiGetICost), set per call |
106 | | |
107 | | //QuantErrScale m_quantErrScale; |
108 | | int m_lastBitsX [MAX_NUM_CH][LAST_SIGNIFICANT_GROUPS]; |
109 | | int m_lastBitsY [MAX_NUM_CH][LAST_SIGNIFICANT_GROUPS]; |
110 | | bool m_lastBitsBuilt [MAX_NUM_CH]; ///< true if the channel type's latest call built m_lastBitsX / Y |
111 | | int* m_errScale [SCALING_LIST_SIZE_NUM][SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of quantization matrix coefficient 4x4 |
112 | | int m_errScaleNoScalingList [SCALING_LIST_SIZE_NUM][SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of quantization matrix coefficient 4x4 |
113 | | CtxTpl m_tplBuf [CTX_TPL_BUF_SIZE]; |
114 | | };// END CLASS DEFINITION QuantRDOQ2 |
115 | | |
116 | | } // namespace vvenc |
117 | | //! \} |
118 | | |