Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibCommon/TComTrQuant.h
- Timestamp:
- 13 Aug 2015, 17:38:13 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibCommon/TComTrQuant.h
r1179 r1313 2 2 * License, included below. This software may be subject to other third party 3 3 * and contributor rights, including patent rights, and no such rights are 4 * granted under this license. 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2015, ITU/ISO/IEC6 * Copyright (c) 2010-2015, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 42 42 #include "TComYuv.h" 43 43 #include "TComDataCU.h" 44 #include "TComChromaFormat.h" 44 45 #include "ContextTables.h" 45 46 … … 59 60 typedef struct 60 61 { 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]; 62 Int significantCoeffGroupBits[NUM_SIG_CG_FLAG_CTX][2 /*Flag = [0|1]*/]; 63 Int significantBits[NUM_SIG_FLAG_CTX][2 /*Flag = [0|1]*/]; 64 Int lastXBits[MAX_NUM_CHANNEL_TYPE][LAST_SIGNIFICANT_GROUPS]; 65 Int lastYBits[MAX_NUM_CHANNEL_TYPE][LAST_SIGNIFICANT_GROUPS]; 66 Int m_greaterOneBits[NUM_ONE_FLAG_CTX][2 /*Flag = [0|1]*/]; 67 Int m_levelAbsBits[NUM_ABS_FLAG_CTX][2 /*Flag = [0|1]*/]; 68 69 Int blockCbpBits[NUM_QT_CBF_CTX_SETS * NUM_QT_CBF_CTX_PER_SET][2 /*Flag = [0|1]*/]; 70 Int blockRootCbpBits[4][2 /*Flag = [0|1]*/]; 71 72 Int golombRiceAdaptationStatistics[RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS]; 70 73 } estBitsSbacStruct; 71 74 … … 74 77 // ==================================================================================================================== 75 78 76 /// QP class77 classQpParam79 /// QP struct 80 struct QpParam 78 81 { 79 public: 80 QpParam(); 81 82 Int m_iQP; 83 Int m_iPer; 84 Int m_iRem; 85 86 public: 87 Int m_iBits; 88 89 Void setQpParam( Int qpScaled ) 90 { 91 m_iQP = qpScaled; 92 m_iPer = qpScaled / 6; 93 m_iRem = qpScaled % 6; 94 m_iBits = QP_BITS + m_iPer; 95 } 96 97 Void clear() 98 { 99 m_iQP = 0; 100 m_iPer = 0; 101 m_iRem = 0; 102 m_iBits = 0; 103 } 104 105 106 Int per() const { return m_iPer; } 107 Int rem() const { return m_iRem; } 108 Int bits() const { return m_iBits; } 109 110 Int qp() {return m_iQP;} 111 }; // END CLASS DEFINITION QpParam 82 Int Qp; 83 Int per; 84 Int rem; 85 86 QpParam(const Int qpy, 87 const ChannelType chType, 88 const Int qpBdOffset, 89 const Int chromaQPOffset, 90 const ChromaFormat chFmt ); 91 92 QpParam(const TComDataCU &cu, const ComponentID compID); 93 94 }; // END STRUCT DEFINITION QpParam 95 112 96 113 97 /// transform and quantization class … … 117 101 TComTrQuant(); 118 102 ~TComTrQuant(); 119 103 120 104 // initialize class 121 Void init ( UInt uiMaxTrSize, Bool useRDOQ = false, 122 Bool useRDOQTS = false, 123 Bool bEnc = false, Bool useTransformSkipFast = false 124 #if ADAPTIVE_QP_SELECTION 125 , Bool bUseAdaptQpSelect = false 126 #endif 127 ); 128 105 Void init ( UInt uiMaxTrSize, 106 Bool useRDOQ = false, 107 Bool useRDOQTS = false, 108 #if T0196_SELECTIVE_RDOQ 109 Bool useSelectiveRDOQ = false, 110 #endif 111 Bool bEnc = false, 112 Bool useTransformSkipFast = false 113 #if ADAPTIVE_QP_SELECTION 114 , Bool bUseAdaptQpSelect = false 115 #endif 116 ); 117 129 118 // 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 119 Void transformNxN( TComTU & rTu, 120 const ComponentID compID, 121 Pel * pcResidual, 122 const UInt uiStride, 123 TCoeff * rpcCoeff, 124 #if ADAPTIVE_QP_SELECTION 125 TCoeff * rpcArlCoeff, 126 #endif 127 TCoeff & uiAbsSum, 128 const QpParam & cQP 129 ); 130 131 132 Void invTransformNxN( TComTU & rTu, 133 const ComponentID compID, 134 Pel *pcResidual, 135 const UInt uiStride, 136 TCoeff * pcCoeff, 137 const QpParam & cQP 138 DEBUG_STRING_FN_DECLAREP(psDebug)); 139 140 Void invRecurTransformNxN ( const ComponentID compID, TComYuv *pResidual, TComTU &rTu ); 141 142 Void rdpcmNxN ( TComTU& rTu, const ComponentID compID, Pel* pcResidual, const UInt uiStride, const QpParam& cQP, TCoeff* pcCoeff, TCoeff &uiAbsSum, RDPCMMode& rdpcmMode ); 143 Void invRdpcmNxN( TComTU& rTu, const ComponentID compID, Pel* pcResidual, const UInt uiStride ); 144 145 Void applyForwardRDPCM( TComTU& rTu, const ComponentID compID, Pel* pcResidual, const UInt uiStride, const QpParam& cQP, TCoeff* pcCoeff, TCoeff &uiAbsSum, const RDPCMMode mode ); 146 148 147 // Misc functions 149 Void setQPforQuant( Int qpy, TextType eTxtType, Int qpBdOffset, Int chromaQPOffset); 150 151 #if RDOQ_CHROMA_LAMBDA 152 Void setLambdas ( const Double lambdas[3] ) { for (Int component = 0; component < 3; component++) m_lambdas[component] = lambdas[component]; } 153 Void selectLambda(TextType eTType) { m_dLambda = (eTType == TEXT_LUMA) ? m_lambdas[0] : ((eTType == TEXT_CHROMA_U) ? m_lambdas[1] : m_lambdas[2]); } 148 149 #if RDOQ_CHROMA_LAMBDA 150 Void setLambdas(const Double lambdas[MAX_NUM_COMPONENT]) { for (UInt component = 0; component < MAX_NUM_COMPONENT; component++) m_lambdas[component] = lambdas[component]; } 151 Void selectLambda(const ComponentID compIdx) { m_dLambda = m_lambdas[compIdx]; } 154 152 #else 155 153 Void setLambda(Double dLambda) { m_dLambda = dLambda;} 156 154 #endif 157 155 Void setRDOQOffset( UInt uiRDOQOffset ) { m_uiRDOQOffset = uiRDOQOffset; } 158 156 159 157 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 UInt scanIdx, 166 Int posX, 167 Int posY, 168 Int log2BlkSize, 169 TextType textureType 158 159 static Int calcPatternSigCtx( const UInt* sigCoeffGroupFlag, UInt uiCGPosX, UInt uiCGPosY, UInt widthInGroups, UInt heightInGroups ); 160 161 static Int getSigCtxInc ( Int patternSigCtx, 162 const TUEntropyCodingParameters &codingParameters, 163 const Int scanPosition, 164 const Int log2BlockWidth, 165 const Int log2BlockHeight, 166 const ChannelType chanType 170 167 ); 171 static UInt getSigCoeffGroupCtxInc ( const UInt* uiSigCoeffGroupFlag, 172 const UInt uiCGPosX, 173 const UInt uiCGPosY, 174 Int width, Int height); 168 169 static UInt getSigCoeffGroupCtxInc (const UInt* uiSigCoeffGroupFlag, 170 const UInt uiCGPosX, 171 const UInt uiCGPosY, 172 const UInt widthInGroups, 173 const UInt heightInGroups); 174 175 175 Void initScalingList (); 176 176 Void destroyScalingList (); 177 Void setErrScaleCoeff ( UInt list, UInt size, UInt qp); 178 Double* getErrScaleCoeff ( UInt list, UInt size, UInt qp) {return m_errScale[size][list][qp];}; //!< get Error Scale Coefficent 179 Int* getQuantCoeff ( UInt list, UInt qp, UInt size) {return m_quantCoef[size][list][qp];}; //!< get Quant Coefficent 180 Int* getDequantCoeff ( UInt list, UInt qp, UInt size) {return m_dequantCoef[size][list][qp];}; //!< get DeQuant Coefficent 177 Void setErrScaleCoeff ( UInt list, UInt size, Int qp, const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE], const BitDepths &bitDepths ); 178 Double* getErrScaleCoeff ( UInt list, UInt size, Int qp ) { return m_errScale [size][list][qp]; }; //!< get Error Scale Coefficent 179 Double& getErrScaleCoeffNoScalingList ( UInt list, UInt size, Int qp ) { return m_errScaleNoScalingList[size][list][qp]; }; //!< get Error Scale Coefficent 180 Int* getQuantCoeff ( UInt list, Int qp, UInt size ) { return m_quantCoef [size][list][qp]; }; //!< get Quant Coefficent 181 Int* getDequantCoeff ( UInt list, Int qp, UInt size ) { return m_dequantCoef [size][list][qp]; }; //!< get DeQuant Coefficent 181 182 Void setUseScalingList ( Bool bUseScalingList){ m_scalingListEnabledFlag = bUseScalingList; }; 182 Bool getUseScalingList ( ){ return m_scalingListEnabledFlag; };183 Void setFlatScalingList ( );184 Void xsetFlatScalingList ( UInt list, UInt size, UInt qp);185 Void xSetScalingListEnc ( TComScalingList *scalingList, UInt list, UInt size, UInt qp);186 Void xSetScalingListDec ( TComScalingList *scalingList, UInt list, UInt size, UInt qp);187 Void setScalingList ( TComScalingList *scalingList );188 Void setScalingListDec ( TComScalingList *scalingList);183 Bool getUseScalingList (const UInt width, const UInt height, const Bool isTransformSkip){ return m_scalingListEnabledFlag && (!isTransformSkip || ((width == 4) && (height == 4))); }; 184 Void setFlatScalingList (const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE], const BitDepths &bitDepths); 185 Void xsetFlatScalingList ( UInt list, UInt size, Int qp); 186 Void xSetScalingListEnc ( TComScalingList *scalingList, UInt list, UInt size, Int qp); 187 Void xSetScalingListDec ( const TComScalingList &scalingList, UInt list, UInt size, Int qp); 188 Void setScalingList ( TComScalingList *scalingList, const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE], const BitDepths &bitDepths); 189 Void setScalingListDec ( const TComScalingList &scalingList); 189 190 Void processScalingListEnc( Int *coeff, Int *quantcoeff, Int quantScales, UInt height, UInt width, UInt ratio, Int sizuNum, UInt dc); 190 Void processScalingListDec( Int *coeff, Int *dequantcoeff, Int invQuantScales, UInt height, UInt width, UInt ratio, Int sizuNum, UInt dc);191 Void processScalingListDec( const Int *coeff, Int *dequantcoeff, Int invQuantScales, UInt height, UInt width, UInt ratio, Int sizuNum, UInt dc); 191 192 #if ADAPTIVE_QP_SELECTION 192 193 Void initSliceQpDelta() ; 193 194 Void storeSliceQpNext(TComSlice* pcSlice); 194 195 Void clearSliceARLCnt(); 195 Int getQpDelta(Int qp) { return m_qpDelta[qp]; } 196 Int* getSliceNSamples(){ return m_sliceNsamples ;} 196 Int getQpDelta(Int qp) { return m_qpDelta[qp]; } 197 Int* getSliceNSamples(){ return m_sliceNsamples ;} 197 198 Double* getSliceSumC() { return m_sliceSumC; } 198 199 #endif 200 Void transformSkipQuantOneSample(TComTU &rTu, const ComponentID compID, const TCoeff resiDiff, TCoeff* pcCoeff, const UInt uiPos, const QpParam &cQP, const Bool bUseHalfRoundingPoint); 201 Void invTrSkipDeQuantOneSample(TComTU &rTu, ComponentID compID, TCoeff pcCoeff, Pel &reconSample, const QpParam &cQP, UInt uiPos ); 202 199 203 protected: 200 204 #if ADAPTIVE_QP_SELECTION 201 Int m_qpDelta[MAX_QP+1]; 202 Int m_sliceNsamples[LEVEL_RANGE+1]; 203 Double m_sliceSumC[LEVEL_RANGE+1] ; 204 #endif 205 Int*m_plTempCoeff;206 207 QpParam m_cQP; 205 Int m_qpDelta[MAX_QP+1]; 206 Int m_sliceNsamples[LEVEL_RANGE+1]; 207 Double m_sliceSumC[LEVEL_RANGE+1] ; 208 #endif 209 TCoeff* m_plTempCoeff; 210 211 // QpParam m_cQP; - removed - placed on the stack. 208 212 #if RDOQ_CHROMA_LAMBDA 209 Double m_lambdas[ 3];213 Double m_lambdas[MAX_NUM_COMPONENT]; 210 214 #endif 211 215 Double m_dLambda; … … 215 219 Bool m_useRDOQ; 216 220 Bool m_useRDOQTS; 221 #if T0196_SELECTIVE_RDOQ 222 Bool m_useSelectiveRDOQ; 223 #endif 217 224 #if ADAPTIVE_QP_SELECTION 218 225 Bool m_bUseAdaptQpSelect; 219 226 #endif 220 227 Bool m_useTransformSkipFast; 228 221 229 Bool m_scalingListEnabledFlag; 222 Int *m_quantCoef [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of quantization matrix coefficient 4x4 223 Int *m_dequantCoef [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of dequantization matrix coefficient 4x4 224 Double *m_errScale [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of quantization matrix coefficient 4x4 230 231 Int *m_quantCoef [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of quantization matrix coefficient 4x4 232 Int *m_dequantCoef [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of dequantization matrix coefficient 4x4 233 Double *m_errScale [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of quantization matrix coefficient 4x4 234 Double m_errScaleNoScalingList[SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of quantization matrix coefficient 4x4 235 225 236 private: 226 237 // forward Transform 227 Void xT ( Int bitDepth, UInt uiMode,Pel* pResidual, UInt uiStride, Int* plCoeff, Int iWidth, Int iHeight);228 238 Void xT ( const Int channelBitDepth, Bool useDST, Pel* piBlkResi, UInt uiStride, TCoeff* psCoeff, Int iWidth, Int iHeight, const Int maxLog2TrDynamicRange ); 239 229 240 // skipping Transform 230 Void xTransformSkip ( Int bitDepth, Pel* piBlkResi, UInt uiStride, Int* psCoeff, Int width, Int height );231 232 Void signBitHidingHDQ( TCoeff* pQCoef, TCoeff* pCoef, UInt const *scan, Int* deltaU, Int width, Int height);241 Void xTransformSkip ( Pel* piBlkResi, UInt uiStride, TCoeff* psCoeff, TComTU &rTu, const ComponentID component ); 242 243 Void signBitHidingHDQ( TCoeff* pQCoef, TCoeff* pCoef, TCoeff* deltaU, const TUEntropyCodingParameters &codingParameters, const Int maxLog2TrDynamicRange ); 233 244 234 245 // quantization 235 Void xQuant( TComDataCU* pcCU, 236 Int* pSrc, 237 TCoeff* pDes, 238 #if ADAPTIVE_QP_SELECTION 239 Int*& pArlDes, 240 #endif 241 Int iWidth, 242 Int iHeight, 243 UInt& uiAcSum, 244 TextType eTType, 245 UInt uiAbsPartIdx ); 246 Void xQuant( TComTU &rTu, 247 TCoeff * pSrc, 248 TCoeff * pDes, 249 #if ADAPTIVE_QP_SELECTION 250 TCoeff *pArlDes, 251 #endif 252 TCoeff &uiAbsSum, 253 const ComponentID compID, 254 const QpParam &cQP ); 255 256 #if T0196_SELECTIVE_RDOQ 257 Bool xNeedRDOQ( TComTU &rTu, 258 TCoeff * pSrc, 259 const ComponentID compID, 260 const QpParam &cQP ); 261 #endif 246 262 247 263 // RDOQ functions 248 249 Void xRateDistOptQuant ( TComDataCU* pcCU, 250 Int* plSrcCoeff, 251 TCoeff* piDstCoeff, 252 #if ADAPTIVE_QP_SELECTION 253 Int*& piArlDstCoeff, 254 #endif 255 UInt uiWidth, 256 UInt uiHeight, 257 UInt& uiAbsSum, 258 TextType eTType, 259 UInt uiAbsPartIdx ); 260 __inline UInt xGetCodedLevel ( Double& rd64CodedCost, 261 Double& rd64CodedCost0, 262 Double& rd64CodedCostSig, 263 Int lLevelDouble, 264 UInt uiMaxAbsLevel, 265 UShort ui16CtxNumSig, 266 UShort ui16CtxNumOne, 267 UShort ui16CtxNumAbs, 268 UShort ui16AbsGoRice, 269 UInt c1Idx, 270 UInt c2Idx, 271 Int iQBits, 272 Double dTemp, 273 Bool bLast ) const; 274 __inline Int xGetICRate ( UInt uiAbsLevel, 275 UShort ui16CtxNumOne, 276 UShort ui16CtxNumAbs, 277 UShort ui16AbsGoRice 278 , UInt c1Idx, 279 UInt c2Idx 280 ) const; 281 __inline Double xGetRateLast ( const UInt uiPosX, 282 const UInt uiPosY ) const; 283 __inline Double xGetRateSigCoeffGroup ( UShort uiSignificanceCoeffGroup, 284 UShort ui16CtxNumSig ) const; 285 __inline Double xGetRateSigCoef ( UShort uiSignificance, 286 UShort ui16CtxNumSig ) const; 287 __inline Double xGetICost ( Double dRate ) const; 288 __inline Double xGetIEPRate ( ) const; 289 290 264 265 Void xRateDistOptQuant ( TComTU &rTu, 266 TCoeff * plSrcCoeff, 267 TCoeff * piDstCoeff, 268 #if ADAPTIVE_QP_SELECTION 269 TCoeff *piArlDstCoeff, 270 #endif 271 TCoeff &uiAbsSum, 272 const ComponentID compID, 273 const QpParam &cQP ); 274 275 __inline UInt xGetCodedLevel ( Double& rd64CodedCost, 276 Double& rd64CodedCost0, 277 Double& rd64CodedCostSig, 278 Intermediate_Int lLevelDouble, 279 UInt uiMaxAbsLevel, 280 UShort ui16CtxNumSig, 281 UShort ui16CtxNumOne, 282 UShort ui16CtxNumAbs, 283 UShort ui16AbsGoRice, 284 UInt c1Idx, 285 UInt c2Idx, 286 Int iQBits, 287 Double errorScale, 288 Bool bLast, 289 Bool useLimitedPrefixLength, 290 const Int maxLog2TrDynamicRange 291 ) const; 292 293 294 __inline Int xGetICRate ( const UInt uiAbsLevel, 295 const UShort ui16CtxNumOne, 296 const UShort ui16CtxNumAbs, 297 const UShort ui16AbsGoRice, 298 const UInt c1Idx, 299 const UInt c2Idx, 300 const Bool useLimitedPrefixLength, 301 const Int maxLog2TrDynamicRange 302 ) const; 303 304 __inline Double xGetRateLast ( const UInt uiPosX, const UInt uiPosY, const ComponentID component ) const; 305 __inline Double xGetRateSigCoeffGroup( UShort uiSignificanceCoeffGroup, UShort ui16CtxNumSig ) const; 306 __inline Double xGetRateSigCoef ( UShort uiSignificance, UShort ui16CtxNumSig ) const; 307 __inline Double xGetICost ( Double dRate ) const; 308 __inline Double xGetIEPRate ( ) const; 309 310 291 311 // dequantization 292 Void xDeQuant(Int bitDepth, const TCoeff* pSrc, Int* pDes, Int iWidth, Int iHeight, Int scalingListType ); 293 312 Void xDeQuant( TComTU &rTu, 313 const TCoeff * pSrc, 314 TCoeff * pDes, 315 const ComponentID compID, 316 const QpParam &cQP ); 317 294 318 // inverse transform 295 Void xIT ( Int bitDepth, UInt uiMode, Int* plCoef, Pel* pResidual, UInt uiStride, Int iWidth, Int iHeight);296 319 Void xIT ( const Int channelBitDepth, Bool useDST, TCoeff* plCoef, Pel* pResidual, UInt uiStride, Int iWidth, Int iHeight, const Int maxLog2TrDynamicRange ); 320 297 321 // inverse skipping transform 298 Void xITransformSkip (Int bitDepth, Int* plCoef, Pel* pResidual, UInt uiStride, Int width, Int height ); 322 Void xITransformSkip ( TCoeff* plCoef, Pel* pResidual, UInt uiStride, TComTU &rTu, const ComponentID component ); 323 324 public: 325 static Void crossComponentPrediction( TComTU &rTu, 326 const ComponentID compID, 327 const Pel *piResiL, 328 const Pel *piResiC, 329 Pel *piResiT, 330 const Int width, 331 const Int height, 332 const Int strideL, 333 const Int strideC, 334 const Int strideT, 335 const Bool reverse); 336 299 337 };// END CLASS DEFINITION TComTrQuant 300 338
Note: See TracChangeset for help on using the changeset viewer.