1 | /* The copyright in this software is being made available under the BSD |
---|
2 | * License, included below. This software may be subject to other third party |
---|
3 | * and contributor rights, including patent rights, and no such rights are |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2012, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file TComTrQuant.h |
---|
35 | \brief transform and quantization class (header) |
---|
36 | */ |
---|
37 | |
---|
38 | #ifndef __TCOMTRQUANT__ |
---|
39 | #define __TCOMTRQUANT__ |
---|
40 | |
---|
41 | #include "CommonDef.h" |
---|
42 | #include "TComYuv.h" |
---|
43 | #include "TComDataCU.h" |
---|
44 | #include "ContextTables.h" |
---|
45 | |
---|
46 | //! \ingroup TLibCommon |
---|
47 | //! \{ |
---|
48 | |
---|
49 | // ==================================================================================================================== |
---|
50 | // Constants |
---|
51 | // ==================================================================================================================== |
---|
52 | |
---|
53 | #define QP_BITS 15 |
---|
54 | |
---|
55 | // ==================================================================================================================== |
---|
56 | // Type definition |
---|
57 | // ==================================================================================================================== |
---|
58 | |
---|
59 | typedef struct |
---|
60 | { |
---|
61 | Int significantCoeffGroupBits[NUM_SIG_CG_FLAG_CTX][2]; |
---|
62 | Int significantBits[NUM_SIG_FLAG_CTX][2]; |
---|
63 | Int lastXBits[32]; |
---|
64 | Int lastYBits[32]; |
---|
65 | Int m_greaterOneBits[NUM_ONE_FLAG_CTX][2]; |
---|
66 | Int m_levelAbsBits[NUM_ABS_FLAG_CTX][2]; |
---|
67 | |
---|
68 | Int blockCbpBits[3*NUM_QT_CBF_CTX][2]; |
---|
69 | Int blockRootCbpBits[4][2]; |
---|
70 | Int scanZigzag[2]; ///< flag for zigzag scan |
---|
71 | Int scanNonZigzag[2]; ///< flag for non zigzag scan |
---|
72 | } estBitsSbacStruct; |
---|
73 | |
---|
74 | // ==================================================================================================================== |
---|
75 | // Class definition |
---|
76 | // ==================================================================================================================== |
---|
77 | |
---|
78 | /// QP class |
---|
79 | class QpParam |
---|
80 | { |
---|
81 | public: |
---|
82 | QpParam(); |
---|
83 | |
---|
84 | Int m_iQP; |
---|
85 | Int m_iPer; |
---|
86 | Int m_iRem; |
---|
87 | |
---|
88 | public: |
---|
89 | Int m_iBits; |
---|
90 | |
---|
91 | Void setQpParam( Int qpScaled ) |
---|
92 | { |
---|
93 | m_iQP = qpScaled; |
---|
94 | m_iPer = qpScaled / 6; |
---|
95 | m_iRem = qpScaled % 6; |
---|
96 | m_iBits = QP_BITS + m_iPer; |
---|
97 | } |
---|
98 | |
---|
99 | Void clear() |
---|
100 | { |
---|
101 | m_iQP = 0; |
---|
102 | m_iPer = 0; |
---|
103 | m_iRem = 0; |
---|
104 | m_iBits = 0; |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | Int per() const { return m_iPer; } |
---|
109 | Int rem() const { return m_iRem; } |
---|
110 | Int bits() const { return m_iBits; } |
---|
111 | |
---|
112 | Int qp() {return m_iQP;} |
---|
113 | }; // END CLASS DEFINITION QpParam |
---|
114 | |
---|
115 | /// transform and quantization class |
---|
116 | class TComTrQuant |
---|
117 | { |
---|
118 | public: |
---|
119 | TComTrQuant(); |
---|
120 | ~TComTrQuant(); |
---|
121 | |
---|
122 | // initialize class |
---|
123 | Void init ( UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxTrSize, Int iSymbolMode = 0, UInt *aTable4 = NULL, UInt *aTable8 = NULL, UInt *aTableLastPosVlcIndex=NULL, Bool bUseRDOQ = false, Bool bEnc = false, Bool useTransformSkipFast = false |
---|
124 | #if ADAPTIVE_QP_SELECTION |
---|
125 | , Bool bUseAdaptQpSelect = false |
---|
126 | #endif |
---|
127 | ); |
---|
128 | |
---|
129 | // transform & inverse transform functions |
---|
130 | Void transformNxN( TComDataCU* pcCU, |
---|
131 | Pel* pcResidual, |
---|
132 | UInt uiStride, |
---|
133 | TCoeff* rpcCoeff, |
---|
134 | #if ADAPTIVE_QP_SELECTION |
---|
135 | Int*& rpcArlCoeff, |
---|
136 | #endif |
---|
137 | UInt uiWidth, |
---|
138 | UInt uiHeight, |
---|
139 | UInt& uiAbsSum, |
---|
140 | TextType eTType, |
---|
141 | UInt uiAbsPartIdx, |
---|
142 | Bool useTransformSkip = false ); |
---|
143 | |
---|
144 | Void invtransformNxN( Bool transQuantBypass, TextType eText, UInt uiMode,Pel* rpcResidual, UInt uiStride, TCoeff* pcCoeff, UInt uiWidth, UInt uiHeight, Int scalingListType, Bool useTransformSkip = false ); |
---|
145 | Void invRecurTransformNxN ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eTxt, Pel* rpcResidual, UInt uiAddr, UInt uiStride, UInt uiWidth, UInt uiHeight, |
---|
146 | UInt uiMaxTrMode, UInt uiTrMode, TCoeff* rpcCoeff ); |
---|
147 | |
---|
148 | // Misc functions |
---|
149 | Void setQPforQuant( Int qpy, TextType eTxtType, Int qpBdOffset, Int chromaQPOffset); |
---|
150 | |
---|
151 | #if RDOQ_CHROMA_LAMBDA |
---|
152 | Void setLambda(Double dLambdaLuma, Double dLambdaChroma) { m_dLambdaLuma = dLambdaLuma; m_dLambdaChroma = dLambdaChroma; } |
---|
153 | Void selectLambda(TextType eTType) { m_dLambda = (eTType == TEXT_LUMA) ? m_dLambdaLuma : m_dLambdaChroma; } |
---|
154 | #else |
---|
155 | Void setLambda(Double dLambda) { m_dLambda = dLambda;} |
---|
156 | #endif |
---|
157 | Void setRDOQOffset( UInt uiRDOQOffset ) { m_uiRDOQOffset = uiRDOQOffset; } |
---|
158 | |
---|
159 | estBitsSbacStruct* m_pcEstBitsSbac; |
---|
160 | |
---|
161 | static Int calcPatternSigCtx( const UInt* sigCoeffGroupFlag, UInt posXCG, UInt posYCG, Int width, Int height ); |
---|
162 | |
---|
163 | static Int getSigCtxInc ( |
---|
164 | Int patternSigCtx, |
---|
165 | #if REMOVAL_8x2_2x8_CG |
---|
166 | UInt scanIdx, |
---|
167 | #endif |
---|
168 | Int posX, |
---|
169 | Int posY, |
---|
170 | Int blockType, |
---|
171 | Int width |
---|
172 | ,Int height |
---|
173 | ,TextType textureType |
---|
174 | ); |
---|
175 | static UInt getSigCoeffGroupCtxInc ( const UInt* uiSigCoeffGroupFlag, |
---|
176 | const UInt uiCGPosX, |
---|
177 | const UInt uiCGPosY, |
---|
178 | const UInt scanIdx, |
---|
179 | Int width, Int height); |
---|
180 | Void initScalingList (); |
---|
181 | Void destroyScalingList (); |
---|
182 | Void setErrScaleCoeff ( UInt list, UInt size, UInt qp, UInt dir); |
---|
183 | double* getErrScaleCoeff ( UInt list, UInt size, UInt qp, UInt dir) {return m_errScale[size][list][qp][dir];}; //!< get Error Scale Coefficent |
---|
184 | Int* getQuantCoeff ( UInt list, UInt qp, UInt size, UInt dir) {return m_quantCoef[size][list][qp][dir];}; //!< get Quant Coefficent |
---|
185 | Int* getDequantCoeff ( UInt list, UInt qp, UInt size, UInt dir) {return m_dequantCoef[size][list][qp][dir];}; //!< get DeQuant Coefficent |
---|
186 | Void setUseScalingList ( Bool bUseScalingList){ m_scalingListEnabledFlag = bUseScalingList; }; |
---|
187 | Bool getUseScalingList (){ return m_scalingListEnabledFlag; }; |
---|
188 | Void setFlatScalingList (); |
---|
189 | Void xsetFlatScalingList ( UInt list, UInt size, UInt qp); |
---|
190 | Void xSetScalingListEnc ( TComScalingList *scalingList, UInt list, UInt size, UInt qp); |
---|
191 | Void xSetScalingListDec ( TComScalingList *scalingList, UInt list, UInt size, UInt qp); |
---|
192 | Void setScalingList ( TComScalingList *scalingList); |
---|
193 | Void setScalingListDec ( TComScalingList *scalingList); |
---|
194 | Void processScalingListEnc( Int *coeff, Int *quantcoeff, Int quantScales, UInt height, UInt width, UInt ratio, Int sizuNum, UInt dc); |
---|
195 | Void processScalingListDec( Int *coeff, Int *dequantcoeff, Int invQuantScales, UInt height, UInt width, UInt ratio, Int sizuNum, UInt dc); |
---|
196 | #if ADAPTIVE_QP_SELECTION |
---|
197 | Void initSliceQpDelta() ; |
---|
198 | Void storeSliceQpNext(TComSlice* pcSlice); |
---|
199 | Void clearSliceARLCnt(); |
---|
200 | Int getQpDelta(Int qp) { return m_qpDelta[qp]; } |
---|
201 | Int* getSliceNSamples(){ return m_sliceNsamples ;} |
---|
202 | Double* getSliceSumC() { return m_sliceSumC; } |
---|
203 | #endif |
---|
204 | protected: |
---|
205 | #if ADAPTIVE_QP_SELECTION |
---|
206 | Int m_qpDelta[MAX_QP+1]; |
---|
207 | Int m_sliceNsamples[LEVEL_RANGE+1]; |
---|
208 | Double m_sliceSumC[LEVEL_RANGE+1] ; |
---|
209 | #endif |
---|
210 | Int* m_plTempCoeff; |
---|
211 | |
---|
212 | QpParam m_cQP; |
---|
213 | #if RDOQ_CHROMA_LAMBDA |
---|
214 | Double m_dLambdaLuma; |
---|
215 | Double m_dLambdaChroma; |
---|
216 | #endif |
---|
217 | Double m_dLambda; |
---|
218 | UInt m_uiRDOQOffset; |
---|
219 | UInt m_uiMaxTrSize; |
---|
220 | Bool m_bEnc; |
---|
221 | Bool m_bUseRDOQ; |
---|
222 | #if ADAPTIVE_QP_SELECTION |
---|
223 | Bool m_bUseAdaptQpSelect; |
---|
224 | #endif |
---|
225 | Bool m_useTransformSkipFast; |
---|
226 | Bool m_scalingListEnabledFlag; |
---|
227 | Int *m_quantCoef [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM][SCALING_LIST_DIR_NUM]; ///< array of quantization matrix coefficient 4x4 |
---|
228 | Int *m_dequantCoef [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM][SCALING_LIST_DIR_NUM]; ///< array of dequantization matrix coefficient 4x4 |
---|
229 | double *m_errScale [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM][SCALING_LIST_DIR_NUM]; ///< array of quantization matrix coefficient 4x4 |
---|
230 | private: |
---|
231 | // forward Transform |
---|
232 | Void xT ( UInt uiMode,Pel* pResidual, UInt uiStride, Int* plCoeff, Int iWidth, Int iHeight ); |
---|
233 | |
---|
234 | // skipping Transform |
---|
235 | Void xTransformSkip ( Pel* piBlkResi, UInt uiStride, Int* psCoeff, Int width, Int height ); |
---|
236 | |
---|
237 | Void signBitHidingHDQ( TComDataCU* pcCU, TCoeff* pQCoef, TCoeff* pCoef, UInt const *scan, Int* deltaU, Int width, Int height ); |
---|
238 | |
---|
239 | // quantization |
---|
240 | Void xQuant( TComDataCU* pcCU, |
---|
241 | Int* pSrc, |
---|
242 | TCoeff* pDes, |
---|
243 | #if ADAPTIVE_QP_SELECTION |
---|
244 | Int*& pArlDes, |
---|
245 | #endif |
---|
246 | Int iWidth, |
---|
247 | Int iHeight, |
---|
248 | UInt& uiAcSum, |
---|
249 | TextType eTType, |
---|
250 | UInt uiAbsPartIdx ); |
---|
251 | |
---|
252 | // RDOQ functions |
---|
253 | |
---|
254 | Void xRateDistOptQuant ( TComDataCU* pcCU, |
---|
255 | Int* plSrcCoeff, |
---|
256 | TCoeff* piDstCoeff, |
---|
257 | #if ADAPTIVE_QP_SELECTION |
---|
258 | Int*& piArlDstCoeff, |
---|
259 | #endif |
---|
260 | UInt uiWidth, |
---|
261 | UInt uiHeight, |
---|
262 | UInt& uiAbsSum, |
---|
263 | TextType eTType, |
---|
264 | UInt uiAbsPartIdx ); |
---|
265 | __inline UInt xGetCodedLevel ( Double& rd64CodedCost, |
---|
266 | Double& rd64CodedCost0, |
---|
267 | Double& rd64CodedCostSig, |
---|
268 | Int lLevelDouble, |
---|
269 | UInt uiMaxAbsLevel, |
---|
270 | UShort ui16CtxNumSig, |
---|
271 | UShort ui16CtxNumOne, |
---|
272 | UShort ui16CtxNumAbs, |
---|
273 | UShort ui16AbsGoRice, |
---|
274 | UInt c1Idx, |
---|
275 | UInt c2Idx, |
---|
276 | Int iQBits, |
---|
277 | Double dTemp, |
---|
278 | Bool bLast ) const; |
---|
279 | __inline Double xGetICRateCost ( UInt uiAbsLevel, |
---|
280 | UShort ui16CtxNumOne, |
---|
281 | UShort ui16CtxNumAbs, |
---|
282 | UShort ui16AbsGoRice |
---|
283 | , UInt c1Idx, |
---|
284 | UInt c2Idx |
---|
285 | ) const; |
---|
286 | __inline Int xGetICRate ( UInt uiAbsLevel, |
---|
287 | UShort ui16CtxNumOne, |
---|
288 | UShort ui16CtxNumAbs, |
---|
289 | UShort ui16AbsGoRice |
---|
290 | , UInt c1Idx, |
---|
291 | UInt c2Idx |
---|
292 | ) const; |
---|
293 | __inline Double xGetRateLast ( const UInt uiPosX, |
---|
294 | const UInt uiPosY, |
---|
295 | const UInt uiBlkWdth ) const; |
---|
296 | __inline Double xGetRateSigCoeffGroup ( UShort uiSignificanceCoeffGroup, |
---|
297 | UShort ui16CtxNumSig ) const; |
---|
298 | __inline Double xGetRateSigCoef ( UShort uiSignificance, |
---|
299 | UShort ui16CtxNumSig ) const; |
---|
300 | __inline Double xGetICost ( Double dRate ) const; |
---|
301 | __inline Double xGetIEPRate ( ) const; |
---|
302 | |
---|
303 | |
---|
304 | // dequantization |
---|
305 | Void xDeQuant( const TCoeff* pSrc, Int* pDes, Int iWidth, Int iHeight, Int scalingListType ); |
---|
306 | |
---|
307 | // inverse transform |
---|
308 | Void xIT ( UInt uiMode, Int* plCoef, Pel* pResidual, UInt uiStride, Int iWidth, Int iHeight ); |
---|
309 | |
---|
310 | // inverse skipping transform |
---|
311 | Void xITransformSkip ( Int* plCoef, Pel* pResidual, UInt uiStride, Int width, Int height ); |
---|
312 | };// END CLASS DEFINITION TComTrQuant |
---|
313 | |
---|
314 | //! \} |
---|
315 | |
---|
316 | #endif // __TCOMTRQUANT__ |
---|