[313] | 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; }; |
---|
[414] | 183 | |
---|
| 184 | #if IL_SL_SIGNALLING_N0371 |
---|
| 185 | Void setFlatScalingList ( UInt m_layerId ); |
---|
| 186 | #else |
---|
[313] | 187 | Void setFlatScalingList (); |
---|
[414] | 188 | #endif |
---|
| 189 | |
---|
[313] | 190 | Void xsetFlatScalingList ( UInt list, UInt size, UInt qp); |
---|
| 191 | Void xSetScalingListEnc ( TComScalingList *scalingList, UInt list, UInt size, UInt qp); |
---|
| 192 | Void xSetScalingListDec ( TComScalingList *scalingList, UInt list, UInt size, UInt qp); |
---|
| 193 | Void setScalingList ( TComScalingList *scalingList); |
---|
| 194 | Void setScalingListDec ( TComScalingList *scalingList); |
---|
| 195 | Void processScalingListEnc( Int *coeff, Int *quantcoeff, Int quantScales, UInt height, UInt width, UInt ratio, Int sizuNum, UInt dc); |
---|
| 196 | Void processScalingListDec( Int *coeff, Int *dequantcoeff, Int invQuantScales, UInt height, UInt width, UInt ratio, Int sizuNum, UInt dc); |
---|
| 197 | #if ADAPTIVE_QP_SELECTION |
---|
| 198 | Void initSliceQpDelta() ; |
---|
| 199 | Void storeSliceQpNext(TComSlice* pcSlice); |
---|
| 200 | Void clearSliceARLCnt(); |
---|
| 201 | Int getQpDelta(Int qp) { return m_qpDelta[qp]; } |
---|
| 202 | Int* getSliceNSamples(){ return m_sliceNsamples ;} |
---|
| 203 | Double* getSliceSumC() { return m_sliceSumC; } |
---|
| 204 | #endif |
---|
| 205 | protected: |
---|
| 206 | #if ADAPTIVE_QP_SELECTION |
---|
| 207 | Int m_qpDelta[MAX_QP+1]; |
---|
| 208 | Int m_sliceNsamples[LEVEL_RANGE+1]; |
---|
| 209 | Double m_sliceSumC[LEVEL_RANGE+1] ; |
---|
| 210 | #endif |
---|
| 211 | Int* m_plTempCoeff; |
---|
| 212 | |
---|
| 213 | QpParam m_cQP; |
---|
| 214 | #if RDOQ_CHROMA_LAMBDA |
---|
| 215 | Double m_dLambdaLuma; |
---|
| 216 | Double m_dLambdaChroma; |
---|
| 217 | #endif |
---|
| 218 | Double m_dLambda; |
---|
| 219 | UInt m_uiRDOQOffset; |
---|
| 220 | UInt m_uiMaxTrSize; |
---|
| 221 | Bool m_bEnc; |
---|
| 222 | Bool m_useRDOQ; |
---|
| 223 | Bool m_useRDOQTS; |
---|
| 224 | #if ADAPTIVE_QP_SELECTION |
---|
| 225 | Bool m_bUseAdaptQpSelect; |
---|
| 226 | #endif |
---|
| 227 | Bool m_useTransformSkipFast; |
---|
| 228 | Bool m_scalingListEnabledFlag; |
---|
| 229 | Int *m_quantCoef [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of quantization matrix coefficient 4x4 |
---|
| 230 | Int *m_dequantCoef [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of dequantization matrix coefficient 4x4 |
---|
| 231 | Double *m_errScale [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of quantization matrix coefficient 4x4 |
---|
| 232 | private: |
---|
| 233 | // forward Transform |
---|
| 234 | Void xT (Int bitDepth, UInt uiMode,Pel* pResidual, UInt uiStride, Int* plCoeff, Int iWidth, Int iHeight ); |
---|
| 235 | |
---|
| 236 | // skipping Transform |
---|
| 237 | Void xTransformSkip (Int bitDepth, Pel* piBlkResi, UInt uiStride, Int* psCoeff, Int width, Int height ); |
---|
| 238 | |
---|
| 239 | Void signBitHidingHDQ( TCoeff* pQCoef, TCoeff* pCoef, UInt const *scan, Int* deltaU, Int width, Int height ); |
---|
| 240 | |
---|
| 241 | // quantization |
---|
| 242 | Void xQuant( TComDataCU* pcCU, |
---|
| 243 | Int* pSrc, |
---|
| 244 | TCoeff* pDes, |
---|
| 245 | #if ADAPTIVE_QP_SELECTION |
---|
| 246 | Int*& pArlDes, |
---|
| 247 | #endif |
---|
| 248 | Int iWidth, |
---|
| 249 | Int iHeight, |
---|
| 250 | UInt& uiAcSum, |
---|
| 251 | TextType eTType, |
---|
| 252 | UInt uiAbsPartIdx ); |
---|
| 253 | |
---|
| 254 | // RDOQ functions |
---|
| 255 | |
---|
| 256 | Void xRateDistOptQuant ( TComDataCU* pcCU, |
---|
| 257 | Int* plSrcCoeff, |
---|
| 258 | TCoeff* piDstCoeff, |
---|
| 259 | #if ADAPTIVE_QP_SELECTION |
---|
| 260 | Int*& piArlDstCoeff, |
---|
| 261 | #endif |
---|
| 262 | UInt uiWidth, |
---|
| 263 | UInt uiHeight, |
---|
| 264 | UInt& uiAbsSum, |
---|
| 265 | TextType eTType, |
---|
| 266 | UInt uiAbsPartIdx ); |
---|
| 267 | __inline UInt xGetCodedLevel ( Double& rd64CodedCost, |
---|
| 268 | Double& rd64CodedCost0, |
---|
| 269 | Double& rd64CodedCostSig, |
---|
| 270 | Int lLevelDouble, |
---|
| 271 | UInt uiMaxAbsLevel, |
---|
| 272 | UShort ui16CtxNumSig, |
---|
| 273 | UShort ui16CtxNumOne, |
---|
| 274 | UShort ui16CtxNumAbs, |
---|
| 275 | UShort ui16AbsGoRice, |
---|
| 276 | UInt c1Idx, |
---|
| 277 | UInt c2Idx, |
---|
| 278 | Int iQBits, |
---|
| 279 | Double dTemp, |
---|
| 280 | Bool bLast ) const; |
---|
| 281 | __inline Double xGetICRateCost ( UInt uiAbsLevel, |
---|
| 282 | UShort ui16CtxNumOne, |
---|
| 283 | UShort ui16CtxNumAbs, |
---|
| 284 | UShort ui16AbsGoRice |
---|
| 285 | , UInt c1Idx, |
---|
| 286 | UInt c2Idx |
---|
| 287 | ) const; |
---|
| 288 | __inline Int xGetICRate ( UInt uiAbsLevel, |
---|
| 289 | UShort ui16CtxNumOne, |
---|
| 290 | UShort ui16CtxNumAbs, |
---|
| 291 | UShort ui16AbsGoRice |
---|
| 292 | , UInt c1Idx, |
---|
| 293 | UInt c2Idx |
---|
| 294 | ) const; |
---|
| 295 | __inline Double xGetRateLast ( const UInt uiPosX, |
---|
| 296 | const UInt uiPosY ) const; |
---|
| 297 | __inline Double xGetRateSigCoeffGroup ( UShort uiSignificanceCoeffGroup, |
---|
| 298 | UShort ui16CtxNumSig ) const; |
---|
| 299 | __inline Double xGetRateSigCoef ( UShort uiSignificance, |
---|
| 300 | UShort ui16CtxNumSig ) const; |
---|
| 301 | __inline Double xGetICost ( Double dRate ) const; |
---|
| 302 | __inline Double xGetIEPRate ( ) const; |
---|
| 303 | |
---|
| 304 | |
---|
| 305 | // dequantization |
---|
| 306 | Void xDeQuant(Int bitDepth, const TCoeff* pSrc, Int* pDes, Int iWidth, Int iHeight, Int scalingListType ); |
---|
| 307 | |
---|
| 308 | // inverse transform |
---|
| 309 | Void xIT (Int bitDepth, UInt uiMode, Int* plCoef, Pel* pResidual, UInt uiStride, Int iWidth, Int iHeight ); |
---|
| 310 | |
---|
| 311 | // inverse skipping transform |
---|
| 312 | Void xITransformSkip (Int bitDepth, Int* plCoef, Pel* pResidual, UInt uiStride, Int width, Int height ); |
---|
| 313 | };// END CLASS DEFINITION TComTrQuant |
---|
| 314 | |
---|
| 315 | //! \} |
---|
| 316 | |
---|
| 317 | #endif // __TCOMTRQUANT__ |
---|