[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 |
---|
| 4 | * granted under this license. |
---|
| 5 | * |
---|
| 6 | * Copyright (c) 2010-2011, 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 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 | */ |
---|
[2] | 33 | |
---|
| 34 | |
---|
[5] | 35 | |
---|
[2] | 36 | /** \file TComTrQuant.h |
---|
| 37 | \brief transform and quantization class (header) |
---|
| 38 | */ |
---|
| 39 | |
---|
| 40 | #ifndef __TCOMTRQUANT__ |
---|
| 41 | #define __TCOMTRQUANT__ |
---|
| 42 | |
---|
| 43 | #include "CommonDef.h" |
---|
| 44 | #include "TComYuv.h" |
---|
| 45 | #include "TComDataCU.h" |
---|
| 46 | |
---|
| 47 | // ==================================================================================================================== |
---|
| 48 | // Constants |
---|
| 49 | // ==================================================================================================================== |
---|
| 50 | |
---|
| 51 | #define QP_BITS 15 |
---|
| 52 | |
---|
| 53 | // AQO Parameter |
---|
| 54 | #define QOFFSET_BITS 15 |
---|
| 55 | #define QOFFSET_BITS_LTR 9 |
---|
| 56 | |
---|
| 57 | // LTR Butterfly Paramter |
---|
| 58 | #define ECore16Shift 10 |
---|
| 59 | #define DCore16Shift 10 |
---|
| 60 | #define ECore32Shift 10 |
---|
| 61 | #define DCore32Shift 10 |
---|
| 62 | |
---|
| 63 | #define DenShift16 6 |
---|
| 64 | #define DenShift32 8 |
---|
| 65 | |
---|
| 66 | // ==================================================================================================================== |
---|
| 67 | // Type definition |
---|
| 68 | // ==================================================================================================================== |
---|
| 69 | |
---|
| 70 | typedef struct |
---|
| 71 | { |
---|
| 72 | Int significantBits[16][2]; |
---|
| 73 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
| 74 | Int lastXBits[32]; |
---|
| 75 | Int lastYBits[32]; |
---|
| 76 | #else |
---|
| 77 | Int lastBits[16][2]; |
---|
| 78 | #endif |
---|
| 79 | Int greaterOneBits[6][2][5][2]; |
---|
| 80 | Int blockCbpBits[45][2]; |
---|
| 81 | Int blockRootCbpBits[4][2]; |
---|
| 82 | Int scanZigzag[2]; ///< flag for zigzag scan |
---|
| 83 | Int scanNonZigzag[2]; ///< flag for non zigzag scan |
---|
| 84 | } estBitsSbacStruct; |
---|
| 85 | |
---|
| 86 | #if QC_MOD_LCEC_RDOQ |
---|
| 87 | typedef struct |
---|
| 88 | { |
---|
| 89 | Int level[4]; |
---|
| 90 | Int pre_level; |
---|
| 91 | Int coeff_ctr; |
---|
| 92 | Long levelDouble; |
---|
| 93 | Double errLevel[4]; |
---|
| 94 | Int noLevels; |
---|
| 95 | Long levelQ; |
---|
| 96 | Bool lowerInt; |
---|
| 97 | UInt quantInd; |
---|
| 98 | } levelDataStruct; |
---|
| 99 | |
---|
| 100 | typedef struct |
---|
| 101 | { |
---|
| 102 | Int run; |
---|
| 103 | Int maxrun; |
---|
| 104 | Int nextLev; |
---|
| 105 | Int nexLevelVal; |
---|
| 106 | } quantLevelStruct; |
---|
| 107 | #endif |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | class TEncCavlc; |
---|
| 112 | |
---|
| 113 | // ==================================================================================================================== |
---|
| 114 | // Class definition |
---|
| 115 | // ==================================================================================================================== |
---|
| 116 | |
---|
| 117 | /// QP class |
---|
| 118 | class QpParam |
---|
| 119 | { |
---|
| 120 | public: |
---|
| 121 | QpParam(); |
---|
| 122 | |
---|
| 123 | Int m_iQP; |
---|
| 124 | Int m_iPer; |
---|
| 125 | Int m_iRem; |
---|
| 126 | |
---|
| 127 | Int m_iAdd2x2; |
---|
| 128 | Int m_iAdd4x4; |
---|
| 129 | Int m_iAdd8x8; |
---|
| 130 | Int m_iAdd16x16; |
---|
| 131 | Int m_iAdd32x32; |
---|
| 132 | private: |
---|
| 133 | Int m_aiAdd2x2[MAX_QP+1][3]; |
---|
| 134 | Int m_aiAdd4x4[MAX_QP+1][3]; |
---|
| 135 | Int m_aiAdd8x8[MAX_QP+1][3]; |
---|
| 136 | Int m_aiAdd16x16[MAX_QP+1][3]; |
---|
| 137 | Int m_aiAdd32x32[MAX_QP+1][3]; |
---|
| 138 | public: |
---|
| 139 | Int m_iBits; |
---|
| 140 | |
---|
| 141 | Void initOffsetParam(Int iStartQP = MIN_QP, Int iEndQP = MAX_QP ); |
---|
| 142 | Void setQOffset( Int iQP, SliceType eSliceType ) |
---|
| 143 | { |
---|
| 144 | m_iAdd2x2 = m_aiAdd2x2[iQP][eSliceType]; |
---|
| 145 | m_iAdd4x4 = m_aiAdd4x4[iQP][eSliceType]; |
---|
| 146 | m_iAdd8x8 = m_aiAdd8x8[iQP][eSliceType]; |
---|
| 147 | m_iAdd16x16 = m_aiAdd16x16[iQP][eSliceType]; |
---|
| 148 | m_iAdd32x32 = m_aiAdd32x32[iQP][eSliceType]; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | Void setQpParam( Int iQP, Bool bLowpass, SliceType eSliceType, Bool bEnc ) |
---|
| 152 | { |
---|
| 153 | assert ( iQP >= MIN_QP && iQP <= MAX_QP ); |
---|
| 154 | m_iQP = iQP; |
---|
| 155 | |
---|
| 156 | m_iPer = (iQP + 6*g_uiBitIncrement)/6; |
---|
| 157 | #if FULL_NBIT |
---|
| 158 | m_iPer += g_uiBitDepth - 8; |
---|
| 159 | #endif |
---|
| 160 | m_iRem = (iQP + 6*g_uiBitIncrement)%6; |
---|
| 161 | |
---|
| 162 | m_iBits = QP_BITS + m_iPer; |
---|
| 163 | |
---|
| 164 | if ( bEnc ) |
---|
| 165 | { |
---|
| 166 | setQOffset(iQP, eSliceType); |
---|
| 167 | } |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | Void clear() |
---|
| 171 | { |
---|
| 172 | m_iQP = 0; |
---|
| 173 | m_iPer = 0; |
---|
| 174 | m_iRem = 0; |
---|
| 175 | m_iBits = 0; |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | |
---|
| 179 | const Int per() const { return m_iPer; } |
---|
| 180 | const Int rem() const { return m_iRem; } |
---|
| 181 | const Int bits() const { return m_iBits; } |
---|
| 182 | |
---|
| 183 | Int qp() {return m_iQP;} |
---|
| 184 | }; // END CLASS DEFINITION QpParam |
---|
| 185 | |
---|
| 186 | /// transform and quantization class |
---|
| 187 | class TComTrQuant |
---|
| 188 | { |
---|
| 189 | public: |
---|
| 190 | TComTrQuant(); |
---|
| 191 | ~TComTrQuant(); |
---|
| 192 | |
---|
| 193 | // initialize class |
---|
| 194 | #if QC_MOD_LCEC |
---|
| 195 | 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 ); |
---|
| 196 | #else |
---|
| 197 | Void init ( UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxTrSize, Int iSymbolMode = 0, UInt *aTable4 = NULL, UInt *aTable8 = NULL, Bool bUseRDOQ = false, Bool bEnc = false ); |
---|
| 198 | #endif |
---|
| 199 | |
---|
| 200 | // transform & inverse transform functions |
---|
| 201 | Void transformNxN ( TComDataCU* pcCU, Pel* pcResidual, UInt uiStride, TCoeff*& rpcCoeff, UInt uiWidth, UInt uiHeight, |
---|
| 202 | UInt& uiAbsSum, TextType eTType, UInt uiAbsPartIdx ); |
---|
| 203 | #if INTRA_DST_TYPE_7 |
---|
| 204 | Void invtransformNxN (TextType eText, UInt uiMode,Pel*& rpcResidual, UInt uiStride, TCoeff* pcCoeff, UInt uiWidth, UInt uiHeight); |
---|
| 205 | #else |
---|
| 206 | Void invtransformNxN ( Pel*& rpcResidual, UInt uiStride, TCoeff* pcCoeff, UInt uiWidth, UInt uiHeight ); |
---|
| 207 | #endif |
---|
| 208 | Void invRecurTransformNxN ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eTxt, Pel*& rpcResidual, UInt uiAddr, UInt uiStride, UInt uiWidth, UInt uiHeight, |
---|
| 209 | UInt uiMaxTrMode, UInt uiTrMode, TCoeff* rpcCoeff ); |
---|
| 210 | |
---|
| 211 | // Misc functions |
---|
| 212 | Void setQPforQuant( Int iQP, Bool bLowpass, SliceType eSliceType, TextType eTxtType); |
---|
| 213 | Void setLambda(Double dLambda) { m_dLambda = dLambda;} |
---|
| 214 | #if QC_MOD_LCEC_RDOQ |
---|
| 215 | Void setRDOQOffset ( UInt uiRDOQOffset ) { m_uiRDOQOffset = uiRDOQOffset; } |
---|
| 216 | #endif |
---|
| 217 | estBitsSbacStruct* m_pcEstBitsSbac; |
---|
| 218 | |
---|
| 219 | static UInt getSigCtxInc ( TCoeff* pcCoeff, |
---|
| 220 | const UInt uiPosX, |
---|
| 221 | const UInt uiPosY, |
---|
| 222 | const UInt uiLog2BlkSize, |
---|
| 223 | const UInt uiStride ); |
---|
| 224 | #if !PCP_SIGMAP_SIMPLE_LAST |
---|
| 225 | static UInt getLastCtxInc ( const UInt uiPosX, |
---|
| 226 | const UInt uiPosY, |
---|
| 227 | const UInt uiLog2BlkSize ); |
---|
| 228 | #endif |
---|
| 229 | protected: |
---|
| 230 | Long* m_plTempCoeff; |
---|
| 231 | UInt* m_puiQuantMtx; |
---|
| 232 | |
---|
| 233 | QpParam m_cQP; |
---|
| 234 | Double m_dLambda; |
---|
| 235 | #if QC_MOD_LCEC_RDOQ |
---|
| 236 | UInt m_uiRDOQOffset; |
---|
| 237 | #endif |
---|
| 238 | UInt m_uiMaxTrSize; |
---|
| 239 | Bool m_bEnc; |
---|
| 240 | Bool m_bUseRDOQ; |
---|
| 241 | |
---|
| 242 | UInt *m_uiLPTableE8; |
---|
| 243 | UInt *m_uiLPTableE4; |
---|
| 244 | Int m_iSymbolMode; |
---|
| 245 | #if QC_MOD_LCEC |
---|
| 246 | UInt *m_uiLastPosVlcIndex; |
---|
| 247 | #endif |
---|
| 248 | |
---|
| 249 | private: |
---|
| 250 | // forward Transform |
---|
| 251 | #if INTRA_DST_TYPE_7 |
---|
| 252 | Void xT ( UInt uiMode,Pel* pResidual, UInt uiStride, Long* plCoeff, Int iSize ); |
---|
| 253 | #else |
---|
| 254 | Void xT ( Pel* pResidual, UInt uiStride, Long* plCoeff, Int iSize ); |
---|
| 255 | #endif |
---|
| 256 | Void xT2 ( Pel* pResidual, UInt uiStride, Long* plCoeff ); |
---|
| 257 | Void xT4 ( Pel* pResidual, UInt uiStride, Long* plCoeff ); |
---|
| 258 | Void xT8 ( Pel* pResidual, UInt uiStride, Long* plCoeff ); |
---|
| 259 | Void xT16 ( Pel* pResidual, UInt uiStride, Long* plCoeff ); |
---|
| 260 | Void xT32 ( Pel* pResidual, UInt uiStride, Long* plCoeff ); |
---|
| 261 | |
---|
| 262 | // quantization |
---|
| 263 | Void xQuant ( TComDataCU* pcCU, Long* pSrc, TCoeff*& pDes, Int iWidth, Int iHeight, UInt& uiAcSum, TextType eTType, UInt uiAbsPartIdx ); |
---|
| 264 | Void xQuantLTR ( TComDataCU* pcCU, Long* pSrc, TCoeff*& pDes, Int iWidth, Int iHeight, UInt& uiAcSum, TextType eTType, UInt uiAbsPartIdx ); |
---|
| 265 | Void xQuant2x2 ( Long* plSrcCoef, TCoeff*& pDstCoef, UInt& uiAbsSum ); |
---|
| 266 | Void xQuant4x4 ( TComDataCU* pcCU, Long* plSrcCoef, TCoeff*& pDstCoef, UInt& uiAbsSum, TextType eTType, UInt uiAbsPartIdx ); |
---|
| 267 | Void xQuant8x8 ( TComDataCU* pcCU, Long* plSrcCoef, TCoeff*& pDstCoef, UInt& uiAbsSum, TextType eTType, UInt uiAbsPartIdx ); |
---|
| 268 | |
---|
| 269 | |
---|
| 270 | // RDOQ functions |
---|
| 271 | |
---|
| 272 | #if QC_MOD_LCEC_RDOQ |
---|
| 273 | Int xCodeCoeffCountBitsLast(TCoeff* scoeff, levelDataStruct* levelData, Int nTab, UInt uiNoCoeff); |
---|
| 274 | UInt xCountVlcBits(UInt uiTableNumber, UInt uiCodeNumber); |
---|
| 275 | #if CAVLC_COEF_LRG_BLK |
---|
| 276 | Int bitCountRDOQ(Int coeff, Int pos, Int nTab, Int lastCoeffFlag,Int levelMode,Int run, Int maxrun, Int vlc_adaptive, Int N, |
---|
| 277 | UInt uiTr1, Int iSum_big_coef, Int iBlockType, TComDataCU* pcCU, const UInt **pLumaRunTr1); |
---|
| 278 | #else |
---|
| 279 | Int bitCountRDOQ(Int coeff, Int pos, Int nTab, Int lastCoeffFlag,Int levelMode,Int run, Int maxrun, Int vlc_adaptive, Int N, |
---|
| 280 | UInt uiTr1, Int iSum_big_coef, Int iBlockType, TComDataCU* pcCU); |
---|
| 281 | #endif |
---|
| 282 | #else |
---|
| 283 | #if QC_MOD_LCEC |
---|
| 284 | Int bitCount_LCEC(Int k,Int pos,Int nTab, Int lpflag,Int levelMode,Int run, Int maxrun, Int vlc_adaptive, Int N, UInt uiTr1); |
---|
| 285 | #else |
---|
| 286 | Int bitCount_LCEC(Int k,Int pos,Int n,Int lpflag,Int levelMode,Int run,Int maxrun,Int vlc_adaptive,Int N); |
---|
| 287 | #endif |
---|
| 288 | #endif |
---|
| 289 | #if QC_MDCS |
---|
| 290 | UInt getCurrLineNum(UInt uiScanIdx, UInt uiPosX, UInt uiPosY); |
---|
| 291 | #endif |
---|
| 292 | Void xRateDistOptQuant_LCEC ( TComDataCU* pcCU, |
---|
| 293 | Long* plSrcCoeff, |
---|
| 294 | TCoeff*& piDstCoeff, |
---|
| 295 | UInt uiWidth, |
---|
| 296 | UInt uiHeight, |
---|
| 297 | UInt& uiAbsSum, |
---|
| 298 | TextType eTType, |
---|
| 299 | UInt uiAbsPartIdx ); |
---|
| 300 | |
---|
| 301 | Void xRateDistOptQuant ( TComDataCU* pcCU, |
---|
| 302 | Long* plSrcCoeff, |
---|
| 303 | TCoeff*& piDstCoeff, |
---|
| 304 | UInt uiWidth, |
---|
| 305 | UInt uiHeight, |
---|
| 306 | UInt& uiAbsSum, |
---|
| 307 | TextType eTType, |
---|
| 308 | UInt uiAbsPartIdx ); |
---|
| 309 | __inline UInt xGetCodedLevel ( Double& rd64UncodedCost, |
---|
| 310 | Double& rd64CodedCost, |
---|
| 311 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
| 312 | Double& rd64CodedLastCost, |
---|
| 313 | UInt& ruiBestNonZeroLevel, |
---|
| 314 | Long lLevelDouble, |
---|
| 315 | UInt uiMaxAbsLevel, |
---|
| 316 | #else |
---|
| 317 | Long lLevelDouble, |
---|
| 318 | UInt uiMaxAbsLevel, |
---|
| 319 | bool bLastScanPos, |
---|
| 320 | #endif |
---|
| 321 | UShort ui16CtxNumSig, |
---|
| 322 | UShort ui16CtxNumOne, |
---|
| 323 | UShort ui16CtxNumAbs, |
---|
| 324 | #if E253 |
---|
| 325 | UShort ui16AbsGoRice, |
---|
| 326 | #endif |
---|
| 327 | Int iQBits, |
---|
| 328 | Double dTemp, |
---|
| 329 | UShort ui16CtxBase ) const; |
---|
| 330 | __inline Double xGetICRateCost ( UInt uiAbsLevel, |
---|
| 331 | #if !PCP_SIGMAP_SIMPLE_LAST |
---|
| 332 | Bool bLastScanPos, |
---|
| 333 | UShort ui16CtxNumSig, |
---|
| 334 | #endif |
---|
| 335 | UShort ui16CtxNumOne, |
---|
| 336 | UShort ui16CtxNumAbs, |
---|
| 337 | #if E253 |
---|
| 338 | UShort ui16AbsGoRice, |
---|
| 339 | #endif |
---|
| 340 | UShort ui16CtxBase ) const; |
---|
| 341 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
| 342 | __inline Double xGetRateLast ( UInt uiPosX, |
---|
| 343 | UInt uiPosY ) const; |
---|
| 344 | __inline Double xGetRateSigCoef ( UShort uiSignificance, |
---|
| 345 | UShort ui16CtxNumSig ) const; |
---|
| 346 | #endif |
---|
| 347 | __inline Double xGetICost ( Double dRate ) const; |
---|
| 348 | __inline Double xGetIEPRate ( ) const; |
---|
| 349 | |
---|
| 350 | |
---|
| 351 | __inline Int xRound ( Int i ) { return ((i)+(1<<5))>>6; } |
---|
| 352 | __inline static Long xTrRound ( Long i, UInt uiShift ) { return ((i)>>uiShift); } |
---|
| 353 | |
---|
| 354 | // dequantization |
---|
| 355 | Void xDeQuant ( TCoeff* pSrc, Long*& pDes, Int iWidth, Int iHeight ); |
---|
| 356 | Void xDeQuantLTR ( TCoeff* pSrc, Long*& pDes, Int iWidth, Int iHeight ); |
---|
| 357 | Void xDeQuant2x2 ( TCoeff* pSrcCoef, Long*& rplDstCoef ); |
---|
| 358 | Void xDeQuant4x4 ( TCoeff* pSrcCoef, Long*& rplDstCoef ); |
---|
| 359 | Void xDeQuant8x8 ( TCoeff* pSrcCoef, Long*& rplDstCoef ); |
---|
| 360 | |
---|
| 361 | // inverse transform |
---|
| 362 | #if INTRA_DST_TYPE_7 |
---|
| 363 | Void xIT ( UInt uiMode, Long* plCoef, Pel* pResidual, UInt uiStride, Int iSize ); |
---|
| 364 | #else |
---|
| 365 | Void xIT ( Long* plCoef, Pel* pResidual, UInt uiStride, Int iSize ); |
---|
| 366 | #endif |
---|
| 367 | Void xIT2 ( Long* plCoef, Pel* pResidual, UInt uiStride ); |
---|
| 368 | Void xIT4 ( Long* plCoef, Pel* pResidual, UInt uiStride ); |
---|
| 369 | Void xIT8 ( Long* plCoef, Pel* pResidual, UInt uiStride ); |
---|
| 370 | Void xIT16 ( Long* plCoef, Pel* pResidual, UInt uiStride ); |
---|
| 371 | Void xIT32 ( Long* plCoef, Pel* pResidual, UInt uiStride ); |
---|
| 372 | |
---|
| 373 | |
---|
| 374 | };// END CLASS DEFINITION TComTrQuant |
---|
| 375 | |
---|
| 376 | |
---|
| 377 | #endif // __TCOMTRQUANT__ |
---|
| 378 | |
---|