[5] | 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 |
---|
[56] | 4 | * granted under this license. |
---|
[5] | 5 | * |
---|
[56] | 6 | * Copyright (c) 2010-2012, ITU/ISO/IEC |
---|
[5] | 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. |
---|
[56] | 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
[5] | 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 | */ |
---|
[2] | 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" |
---|
[56] | 44 | #include "ContextTables.h" |
---|
[2] | 45 | |
---|
[56] | 46 | //! \ingroup TLibCommon |
---|
| 47 | //! \{ |
---|
| 48 | |
---|
[2] | 49 | // ==================================================================================================================== |
---|
| 50 | // Constants |
---|
| 51 | // ==================================================================================================================== |
---|
| 52 | |
---|
| 53 | #define QP_BITS 15 |
---|
| 54 | |
---|
| 55 | // ==================================================================================================================== |
---|
| 56 | // Type definition |
---|
| 57 | // ==================================================================================================================== |
---|
| 58 | |
---|
| 59 | typedef struct |
---|
| 60 | { |
---|
[56] | 61 | Int significantCoeffGroupBits[NUM_SIG_CG_FLAG_CTX][2]; |
---|
| 62 | Int significantBits[NUM_SIG_FLAG_CTX][2]; |
---|
[2] | 63 | Int lastXBits[32]; |
---|
| 64 | Int lastYBits[32]; |
---|
[56] | 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]; |
---|
[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; |
---|
[56] | 90 | |
---|
| 91 | Void setQpParam( Int qpScaled, Bool bLowpass, SliceType eSliceType ) |
---|
[2] | 92 | { |
---|
[56] | 93 | m_iQP = qpScaled; |
---|
| 94 | m_iPer = qpScaled / 6; |
---|
| 95 | m_iRem = qpScaled % 6; |
---|
| 96 | m_iBits = QP_BITS + m_iPer; |
---|
[2] | 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 | |
---|
[56] | 108 | Int per() const { return m_iPer; } |
---|
| 109 | Int rem() const { return m_iRem; } |
---|
| 110 | Int bits() const { return m_iBits; } |
---|
[2] | 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 |
---|
[56] | 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 |
---|
| 124 | #if ADAPTIVE_QP_SELECTION |
---|
| 125 | , Bool bUseAdaptQpSelect = false |
---|
| 126 | #endif |
---|
| 127 | ); |
---|
[2] | 128 | |
---|
| 129 | // transform & inverse transform functions |
---|
[56] | 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 | #if LOSSLESS_CODING |
---|
| 143 | Void invtransformNxN( TComDataCU* pcCU, TextType eText, UInt uiMode,Pel* rpcResidual, UInt uiStride, TCoeff* pcCoeff, UInt uiWidth, UInt uiHeight, Int scalingListType); |
---|
[2] | 144 | #else |
---|
[56] | 145 | Void invtransformNxN( TextType eText, UInt uiMode,Pel*& rpcResidual, UInt uiStride, TCoeff* pcCoeff, UInt uiWidth, UInt uiHeight, Int scalingListType); |
---|
[2] | 146 | #endif |
---|
[56] | 147 | Void invRecurTransformNxN ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eTxt, Pel* rpcResidual, UInt uiAddr, UInt uiStride, UInt uiWidth, UInt uiHeight, |
---|
[2] | 148 | UInt uiMaxTrMode, UInt uiTrMode, TCoeff* rpcCoeff ); |
---|
| 149 | |
---|
| 150 | // Misc functions |
---|
[56] | 151 | Void setQPforQuant( Int qpy, Bool bLowpass, SliceType eSliceType, TextType eTxtType, Int qpBdOffset, Int chromaQPOffset); |
---|
| 152 | |
---|
| 153 | #if RDOQ_CHROMA_LAMBDA |
---|
| 154 | Void setLambda(Double dLambdaLuma, Double dLambdaChroma) { m_dLambdaLuma = dLambdaLuma; m_dLambdaChroma = dLambdaChroma; } |
---|
| 155 | Void selectLambda(TextType eTType) { m_dLambda = (eTType == TEXT_LUMA) ? m_dLambdaLuma : m_dLambdaChroma; } |
---|
| 156 | #else |
---|
[2] | 157 | Void setLambda(Double dLambda) { m_dLambda = dLambda;} |
---|
| 158 | #endif |
---|
[56] | 159 | Void setRDOQOffset( UInt uiRDOQOffset ) { m_uiRDOQOffset = uiRDOQOffset; } |
---|
| 160 | |
---|
[2] | 161 | estBitsSbacStruct* m_pcEstBitsSbac; |
---|
| 162 | |
---|
[56] | 163 | static Int getSigCtxInc ( TCoeff* pcCoeff, |
---|
| 164 | Int posX, |
---|
| 165 | Int posY, |
---|
| 166 | Int blockType, |
---|
| 167 | Int width |
---|
| 168 | ,Int height |
---|
| 169 | ,TextType textureType |
---|
| 170 | ); |
---|
| 171 | static UInt getSigCoeffGroupCtxInc ( const UInt* uiSigCoeffGroupFlag, |
---|
| 172 | const UInt uiCGPosX, |
---|
| 173 | const UInt uiCGPosY, |
---|
| 174 | const UInt scanIdx, |
---|
| 175 | Int width, Int height); |
---|
| 176 | Void initScalingList (); |
---|
| 177 | Void destroyScalingList (); |
---|
| 178 | Void setErrScaleCoeff ( UInt list, UInt size, UInt qp, UInt dir); |
---|
| 179 | double* getErrScaleCoeff ( UInt list, UInt size, UInt qp, UInt dir) {return m_errScale[size][list][qp][dir];}; //!< get Error Scale Coefficent |
---|
| 180 | Int* getQuantCoeff ( UInt list, UInt qp, UInt size, UInt dir) {return m_quantCoef[size][list][qp][dir];}; //!< get Quant Coefficent |
---|
| 181 | Int* getDequantCoeff ( UInt list, UInt qp, UInt size, UInt dir) {return m_dequantCoef[size][list][qp][dir];}; //!< get DeQuant Coefficent |
---|
| 182 | Void setUseScalingList ( Bool bUseScalingList){ m_scalingListEnabledFlag = bUseScalingList; }; |
---|
| 183 | Bool getUseScalingList (){ return m_scalingListEnabledFlag; }; |
---|
| 184 | Void setFlatScalingList (); |
---|
| 185 | Void xsetFlatScalingList ( UInt list, UInt size, UInt qp); |
---|
| 186 | Void xSetScalingListEnc ( TComScalingList *scalingList, UInt list, UInt size, UInt qp); |
---|
| 187 | Void xSetScalingListDec ( TComScalingList *scalingList, UInt list, UInt size, UInt qp); |
---|
| 188 | Void setScalingList ( TComScalingList *scalingList); |
---|
| 189 | Void setScalingListDec ( TComScalingList *scalingList); |
---|
| 190 | Void processScalingListEnc( Int *coeff, Int *quantcoeff, Int quantScales, UInt height, UInt width, UInt ratio, Int sizuNum, UInt dc); |
---|
| 191 | Void processScalingListDec( Int *coeff, Int *dequantcoeff, Int invQuantScales, UInt height, UInt width, UInt ratio, Int sizuNum, UInt dc); |
---|
| 192 | #if ADAPTIVE_QP_SELECTION |
---|
| 193 | Void initSliceQpDelta() ; |
---|
| 194 | Void storeSliceQpNext(TComSlice* pcSlice); |
---|
| 195 | Void clearSliceARLCnt(); |
---|
| 196 | Int getQpDelta(Int qp) { return m_qpDelta[qp]; } |
---|
| 197 | Int* getSliceNSamples(){ return m_sliceNsamples ;} |
---|
| 198 | Double* getSliceSumC() { return m_sliceSumC; } |
---|
| 199 | #endif |
---|
[2] | 200 | protected: |
---|
[56] | 201 | #if ADAPTIVE_QP_SELECTION |
---|
| 202 | Int m_qpDelta[MAX_QP+1]; |
---|
| 203 | Int m_sliceNsamples[LEVEL_RANGE+1]; |
---|
| 204 | Double m_sliceSumC[LEVEL_RANGE+1] ; |
---|
| 205 | #endif |
---|
| 206 | Int* m_plTempCoeff; |
---|
[2] | 207 | |
---|
| 208 | QpParam m_cQP; |
---|
[56] | 209 | #if RDOQ_CHROMA_LAMBDA |
---|
| 210 | Double m_dLambdaLuma; |
---|
| 211 | Double m_dLambdaChroma; |
---|
| 212 | #endif |
---|
[2] | 213 | Double m_dLambda; |
---|
| 214 | UInt m_uiRDOQOffset; |
---|
| 215 | UInt m_uiMaxTrSize; |
---|
| 216 | Bool m_bEnc; |
---|
| 217 | Bool m_bUseRDOQ; |
---|
[56] | 218 | #if ADAPTIVE_QP_SELECTION |
---|
| 219 | Bool m_bUseAdaptQpSelect; |
---|
[2] | 220 | #endif |
---|
[56] | 221 | |
---|
| 222 | Bool m_scalingListEnabledFlag; |
---|
| 223 | Int *m_quantCoef [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM][SCALING_LIST_DIR_NUM]; ///< array of quantization matrix coefficient 4x4 |
---|
| 224 | Int *m_dequantCoef [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM][SCALING_LIST_DIR_NUM]; ///< array of dequantization matrix coefficient 4x4 |
---|
| 225 | double *m_errScale [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM][SCALING_LIST_DIR_NUM]; ///< array of quantization matrix coefficient 4x4 |
---|
[2] | 226 | private: |
---|
| 227 | // forward Transform |
---|
[56] | 228 | Void xT ( UInt uiMode,Pel* pResidual, UInt uiStride, Int* plCoeff, Int iWidth, Int iHeight ); |
---|
| 229 | |
---|
| 230 | Void signBitHidingHDQ( TComDataCU* pcCU, TCoeff* pQCoef, TCoeff* pCoef, UInt const *scan, Int* deltaU, Int width, Int height ); |
---|
| 231 | |
---|
[2] | 232 | // quantization |
---|
[56] | 233 | Void xQuant( TComDataCU* pcCU, |
---|
| 234 | Int* pSrc, |
---|
| 235 | TCoeff* pDes, |
---|
| 236 | #if ADAPTIVE_QP_SELECTION |
---|
| 237 | Int*& pArlDes, |
---|
| 238 | #endif |
---|
| 239 | Int iWidth, |
---|
| 240 | Int iHeight, |
---|
| 241 | UInt& uiAcSum, |
---|
| 242 | TextType eTType, |
---|
| 243 | UInt uiAbsPartIdx ); |
---|
[2] | 244 | |
---|
| 245 | // RDOQ functions |
---|
| 246 | |
---|
| 247 | Void xRateDistOptQuant ( TComDataCU* pcCU, |
---|
[56] | 248 | Int* plSrcCoeff, |
---|
| 249 | TCoeff* piDstCoeff, |
---|
| 250 | #if ADAPTIVE_QP_SELECTION |
---|
| 251 | Int*& piArlDstCoeff, |
---|
| 252 | #endif |
---|
[2] | 253 | UInt uiWidth, |
---|
| 254 | UInt uiHeight, |
---|
| 255 | UInt& uiAbsSum, |
---|
| 256 | TextType eTType, |
---|
| 257 | UInt uiAbsPartIdx ); |
---|
[56] | 258 | __inline UInt xGetCodedLevel ( Double& rd64CodedCost, |
---|
| 259 | Double& rd64CodedCost0, |
---|
| 260 | Double& rd64CodedCostSig, |
---|
| 261 | Int lLevelDouble, |
---|
| 262 | UInt uiMaxAbsLevel, |
---|
| 263 | UShort ui16CtxNumSig, |
---|
| 264 | UShort ui16CtxNumOne, |
---|
| 265 | UShort ui16CtxNumAbs, |
---|
| 266 | UShort ui16AbsGoRice, |
---|
| 267 | UInt c1Idx, |
---|
| 268 | UInt c2Idx, |
---|
| 269 | Int iQBits, |
---|
| 270 | Double dTemp, |
---|
| 271 | Bool bLast ) const; |
---|
| 272 | __inline Double xGetICRateCost ( UInt uiAbsLevel, |
---|
[2] | 273 | UShort ui16CtxNumOne, |
---|
| 274 | UShort ui16CtxNumAbs, |
---|
[56] | 275 | UShort ui16AbsGoRice |
---|
| 276 | , UInt c1Idx, |
---|
| 277 | UInt c2Idx |
---|
| 278 | ) const; |
---|
| 279 | __inline Int xGetICRate ( UInt uiAbsLevel, |
---|
| 280 | UShort ui16CtxNumOne, |
---|
| 281 | UShort ui16CtxNumAbs, |
---|
| 282 | UShort ui16AbsGoRice |
---|
| 283 | , UInt c1Idx, |
---|
| 284 | UInt c2Idx |
---|
| 285 | ) const; |
---|
| 286 | __inline Double xGetRateLast ( const UInt uiPosX, |
---|
| 287 | const UInt uiPosY, |
---|
| 288 | const UInt uiBlkWdth ) const; |
---|
| 289 | __inline Double xGetRateSigCoeffGroup ( UShort uiSignificanceCoeffGroup, |
---|
| 290 | UShort ui16CtxNumSig ) const; |
---|
[2] | 291 | __inline Double xGetRateSigCoef ( UShort uiSignificance, |
---|
| 292 | UShort ui16CtxNumSig ) const; |
---|
| 293 | __inline Double xGetICost ( Double dRate ) const; |
---|
| 294 | __inline Double xGetIEPRate ( ) const; |
---|
| 295 | |
---|
| 296 | |
---|
| 297 | // dequantization |
---|
[56] | 298 | Void xDeQuant( const TCoeff* pSrc, Int* pDes, Int iWidth, Int iHeight, Int scalingListType ); |
---|
[2] | 299 | |
---|
| 300 | // inverse transform |
---|
[56] | 301 | Void xIT ( UInt uiMode, Int* plCoef, Pel* pResidual, UInt uiStride, Int iWidth, Int iHeight ); |
---|
| 302 | |
---|
[2] | 303 | };// END CLASS DEFINITION TComTrQuant |
---|
| 304 | |
---|
[56] | 305 | //! \} |
---|
[2] | 306 | |
---|
| 307 | #endif // __TCOMTRQUANT__ |
---|