[51] | 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-2013, 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 | } estBitsSbacStruct; |
---|
| 71 | |
---|
| 72 | // ==================================================================================================================== |
---|
| 73 | // Class definition |
---|
| 74 | // ==================================================================================================================== |
---|
| 75 | |
---|
| 76 | /// QP class |
---|
| 77 | class QpParam |
---|
| 78 | { |
---|
| 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 |
---|
| 112 | |
---|
| 113 | /// transform and quantization class |
---|
| 114 | class TComTrQuant |
---|
| 115 | { |
---|
| 116 | public: |
---|
| 117 | TComTrQuant(); |
---|
| 118 | ~TComTrQuant(); |
---|
| 119 | |
---|
| 120 | // 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 | |
---|
| 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 | UInt scanIdx, |
---|
| 166 | Int posX, |
---|
| 167 | Int posY, |
---|
| 168 | Int log2BlkSize, |
---|
| 169 | TextType textureType |
---|
| 170 | ); |
---|
| 171 | static UInt getSigCoeffGroupCtxInc ( const UInt* uiSigCoeffGroupFlag, |
---|
| 172 | const UInt uiCGPosX, |
---|
| 173 | const UInt uiCGPosY, |
---|
| 174 | Int width, Int height); |
---|
| 175 | Void initScalingList (); |
---|
| 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 |
---|
| 181 | 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); |
---|
| 189 | 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 | #if ADAPTIVE_QP_SELECTION |
---|
| 192 | Void initSliceQpDelta() ; |
---|
| 193 | Void storeSliceQpNext(TComSlice* pcSlice); |
---|
| 194 | Void clearSliceARLCnt(); |
---|
| 195 | Int getQpDelta(Int qp) { return m_qpDelta[qp]; } |
---|
| 196 | Int* getSliceNSamples(){ return m_sliceNsamples ;} |
---|
| 197 | Double* getSliceSumC() { return m_sliceSumC; } |
---|
| 198 | #endif |
---|
| 199 | protected: |
---|
| 200 | #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; |
---|
| 208 | #if RDOQ_CHROMA_LAMBDA |
---|
| 209 | Double m_dLambdaLuma; |
---|
| 210 | Double m_dLambdaChroma; |
---|
| 211 | #endif |
---|
| 212 | Double m_dLambda; |
---|
| 213 | UInt m_uiRDOQOffset; |
---|
| 214 | UInt m_uiMaxTrSize; |
---|
| 215 | Bool m_bEnc; |
---|
| 216 | Bool m_useRDOQ; |
---|
| 217 | Bool m_useRDOQTS; |
---|
| 218 | #if ADAPTIVE_QP_SELECTION |
---|
| 219 | Bool m_bUseAdaptQpSelect; |
---|
| 220 | #endif |
---|
| 221 | Bool m_useTransformSkipFast; |
---|
| 222 | Bool m_scalingListEnabledFlag; |
---|
| 223 | Int *m_quantCoef [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of quantization matrix coefficient 4x4 |
---|
| 224 | Int *m_dequantCoef [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of dequantization matrix coefficient 4x4 |
---|
| 225 | Double *m_errScale [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of quantization matrix coefficient 4x4 |
---|
| 226 | private: |
---|
| 227 | // forward Transform |
---|
| 228 | Void xT (Int bitDepth, UInt uiMode,Pel* pResidual, UInt uiStride, Int* plCoeff, Int iWidth, Int iHeight ); |
---|
| 229 | |
---|
| 230 | // skipping Transform |
---|
| 231 | Void xTransformSkip (Int bitDepth, Pel* piBlkResi, UInt uiStride, Int* psCoeff, Int width, Int height ); |
---|
| 232 | |
---|
| 233 | Void signBitHidingHDQ( TCoeff* pQCoef, TCoeff* pCoef, UInt const *scan, Int* deltaU, Int width, Int height ); |
---|
| 234 | |
---|
| 235 | // quantization |
---|
| 236 | Void xQuant( TComDataCU* pcCU, |
---|
| 237 | Int* pSrc, |
---|
| 238 | TCoeff* pDes, |
---|
| 239 | #if ADAPTIVE_QP_SELECTION |
---|
| 240 | Int*& pArlDes, |
---|
| 241 | #endif |
---|
| 242 | Int iWidth, |
---|
| 243 | Int iHeight, |
---|
| 244 | UInt& uiAcSum, |
---|
| 245 | TextType eTType, |
---|
| 246 | UInt uiAbsPartIdx ); |
---|
| 247 | |
---|
| 248 | // RDOQ functions |
---|
| 249 | |
---|
| 250 | Void xRateDistOptQuant ( TComDataCU* pcCU, |
---|
| 251 | Int* plSrcCoeff, |
---|
| 252 | TCoeff* piDstCoeff, |
---|
| 253 | #if ADAPTIVE_QP_SELECTION |
---|
| 254 | Int*& piArlDstCoeff, |
---|
| 255 | #endif |
---|
| 256 | UInt uiWidth, |
---|
| 257 | UInt uiHeight, |
---|
| 258 | UInt& uiAbsSum, |
---|
| 259 | TextType eTType, |
---|
| 260 | UInt uiAbsPartIdx ); |
---|
| 261 | __inline UInt xGetCodedLevel ( Double& rd64CodedCost, |
---|
| 262 | Double& rd64CodedCost0, |
---|
| 263 | Double& rd64CodedCostSig, |
---|
| 264 | Int lLevelDouble, |
---|
| 265 | UInt uiMaxAbsLevel, |
---|
| 266 | UShort ui16CtxNumSig, |
---|
| 267 | UShort ui16CtxNumOne, |
---|
| 268 | UShort ui16CtxNumAbs, |
---|
| 269 | UShort ui16AbsGoRice, |
---|
| 270 | UInt c1Idx, |
---|
| 271 | UInt c2Idx, |
---|
| 272 | Int iQBits, |
---|
| 273 | Double dTemp, |
---|
| 274 | Bool bLast ) const; |
---|
| 275 | __inline Double xGetICRateCost ( UInt uiAbsLevel, |
---|
| 276 | UShort ui16CtxNumOne, |
---|
| 277 | UShort ui16CtxNumAbs, |
---|
| 278 | UShort ui16AbsGoRice |
---|
| 279 | , UInt c1Idx, |
---|
| 280 | UInt c2Idx |
---|
| 281 | ) const; |
---|
| 282 | __inline Int xGetICRate ( UInt uiAbsLevel, |
---|
| 283 | UShort ui16CtxNumOne, |
---|
| 284 | UShort ui16CtxNumAbs, |
---|
| 285 | UShort ui16AbsGoRice |
---|
| 286 | , UInt c1Idx, |
---|
| 287 | UInt c2Idx |
---|
| 288 | ) const; |
---|
| 289 | __inline Double xGetRateLast ( const UInt uiPosX, |
---|
| 290 | const UInt uiPosY ) const; |
---|
| 291 | __inline Double xGetRateSigCoeffGroup ( UShort uiSignificanceCoeffGroup, |
---|
| 292 | UShort ui16CtxNumSig ) const; |
---|
| 293 | __inline Double xGetRateSigCoef ( UShort uiSignificance, |
---|
| 294 | UShort ui16CtxNumSig ) const; |
---|
| 295 | __inline Double xGetICost ( Double dRate ) const; |
---|
| 296 | __inline Double xGetIEPRate ( ) const; |
---|
| 297 | |
---|
| 298 | |
---|
| 299 | // dequantization |
---|
| 300 | Void xDeQuant(Int bitDepth, const TCoeff* pSrc, Int* pDes, Int iWidth, Int iHeight, Int scalingListType ); |
---|
| 301 | |
---|
| 302 | // inverse transform |
---|
| 303 | Void xIT (Int bitDepth, UInt uiMode, Int* plCoef, Pel* pResidual, UInt uiStride, Int iWidth, Int iHeight ); |
---|
| 304 | |
---|
| 305 | // inverse skipping transform |
---|
| 306 | Void xITransformSkip (Int bitDepth, Int* plCoef, Pel* pResidual, UInt uiStride, Int width, Int height ); |
---|
| 307 | };// END CLASS DEFINITION TComTrQuant |
---|
| 308 | |
---|
| 309 | //! \} |
---|
| 310 | |
---|
| 311 | #endif // __TCOMTRQUANT__ |
---|