[2] | 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-2012, 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 TDecEntropy.cpp |
---|
| 35 | \brief entropy decoder class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include "TDecEntropy.h" |
---|
| 39 | |
---|
| 40 | //! \ingroup TLibDecoder |
---|
| 41 | //! \{ |
---|
| 42 | |
---|
| 43 | Void TDecEntropy::setEntropyDecoder ( TDecEntropyIf* p ) |
---|
| 44 | { |
---|
| 45 | m_pcEntropyDecoderIf = p; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | #include "TLibCommon/TComAdaptiveLoopFilter.h" |
---|
| 49 | #include "TLibCommon/TComSampleAdaptiveOffset.h" |
---|
| 50 | |
---|
| 51 | Void TDecEntropy::decodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 52 | { |
---|
| 53 | m_pcEntropyDecoderIf->parseSkipFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | Void TDecEntropy::decodeCUTransquantBypassFlag(TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 57 | { |
---|
| 58 | m_pcEntropyDecoderIf->parseCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | #if INTRA_BL |
---|
| 62 | Void TDecEntropy::decodeIntraBLFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth ) |
---|
| 63 | { |
---|
| 64 | m_pcEntropyDecoderIf->parseIntraBLFlag( pcCU, uiAbsPartIdx, uiPartIdx, uiDepth ); |
---|
| 65 | } |
---|
| 66 | #endif |
---|
| 67 | |
---|
| 68 | /** decode merge flag |
---|
| 69 | * \param pcSubCU |
---|
| 70 | * \param uiAbsPartIdx |
---|
| 71 | * \param uiDepth |
---|
| 72 | * \param uiPUIdx |
---|
| 73 | * \returns Void |
---|
| 74 | */ |
---|
| 75 | Void TDecEntropy::decodeMergeFlag( TComDataCU* pcSubCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx ) |
---|
| 76 | { |
---|
| 77 | // at least one merge candidate exists |
---|
| 78 | m_pcEntropyDecoderIf->parseMergeFlag( pcSubCU, uiAbsPartIdx, uiDepth, uiPUIdx ); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | /** decode merge index |
---|
| 82 | * \param pcCU |
---|
| 83 | * \param uiPartIdx |
---|
| 84 | * \param uiAbsPartIdx |
---|
| 85 | * \param puhInterDirNeighbours pointer to list of inter direction from the casual neighbours |
---|
| 86 | * \param pcMvFieldNeighbours pointer to list of motion vector field from the casual neighbours |
---|
| 87 | * \param uiDepth |
---|
| 88 | * \returns Void |
---|
| 89 | */ |
---|
| 90 | Void TDecEntropy::decodeMergeIndex( TComDataCU* pcCU, UInt uiPartIdx, UInt uiAbsPartIdx, PartSize eCUMode, UChar* puhInterDirNeighbours, TComMvField* pcMvFieldNeighbours, UInt uiDepth ) |
---|
| 91 | { |
---|
| 92 | UInt uiMergeIndex = 0; |
---|
| 93 | m_pcEntropyDecoderIf->parseMergeIndex( pcCU, uiMergeIndex, uiAbsPartIdx, uiDepth ); |
---|
| 94 | pcCU->setMergeIndexSubParts( uiMergeIndex, uiAbsPartIdx, uiPartIdx, uiDepth ); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | Void TDecEntropy::decodeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 98 | { |
---|
| 99 | m_pcEntropyDecoderIf->parseSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | Void TDecEntropy::decodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 103 | { |
---|
| 104 | m_pcEntropyDecoderIf->parsePredMode( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | Void TDecEntropy::decodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 108 | { |
---|
| 109 | m_pcEntropyDecoderIf->parsePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | Void TDecEntropy::decodePredInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU ) |
---|
| 113 | { |
---|
| 114 | #if INTRA_BL |
---|
| 115 | if( pcCU->isIntraBL( uiAbsPartIdx ) ) // Do nothing for Intra BL mode. |
---|
| 116 | { |
---|
| 117 | return; |
---|
| 118 | } |
---|
| 119 | #endif |
---|
| 120 | if( pcCU->isIntra( uiAbsPartIdx ) ) // If it is Intra mode, encode intra prediction mode. |
---|
| 121 | { |
---|
| 122 | decodeIntraDirModeLuma ( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 123 | decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 124 | } |
---|
| 125 | else // if it is Inter mode, encode motion vector and reference index |
---|
| 126 | { |
---|
| 127 | decodePUWise( pcCU, uiAbsPartIdx, uiDepth, pcSubCU ); |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | /** Parse I_PCM information. |
---|
| 132 | * \param pcCU pointer to CUpointer to CU |
---|
| 133 | * \param uiAbsPartIdx CU index |
---|
| 134 | * \param uiDepth CU depth |
---|
| 135 | * \returns Void |
---|
| 136 | */ |
---|
| 137 | Void TDecEntropy::decodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 138 | { |
---|
| 139 | if(!pcCU->getSlice()->getSPS()->getUsePCM() |
---|
| 140 | || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize()) |
---|
| 141 | || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()) ) |
---|
| 142 | { |
---|
| 143 | return; |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | m_pcEntropyDecoderIf->parseIPCMInfo( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | Void TDecEntropy::decodeIntraDirModeLuma ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 150 | { |
---|
| 151 | m_pcEntropyDecoderIf->parseIntraDirLumaAng( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | Void TDecEntropy::decodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 155 | { |
---|
| 156 | m_pcEntropyDecoderIf->parseIntraDirChroma( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | /** decode motion information for every PU block. |
---|
| 160 | * \param pcCU |
---|
| 161 | * \param uiAbsPartIdx |
---|
| 162 | * \param uiDepth |
---|
| 163 | * \param pcSubCU |
---|
| 164 | * \returns Void |
---|
| 165 | */ |
---|
| 166 | Void TDecEntropy::decodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU ) |
---|
| 167 | { |
---|
| 168 | PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
| 169 | UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) ); |
---|
| 170 | UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4; |
---|
| 171 | |
---|
| 172 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists |
---|
| 173 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
| 174 | |
---|
| 175 | for ( UInt ui = 0; ui < pcCU->getSlice()->getMaxNumMergeCand(); ui++ ) |
---|
| 176 | { |
---|
| 177 | uhInterDirNeighbours[ui] = 0; |
---|
| 178 | } |
---|
| 179 | Int numValidMergeCand = 0; |
---|
| 180 | bool isMerged = false; |
---|
| 181 | |
---|
| 182 | pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 ); |
---|
| 183 | pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 ); |
---|
| 184 | for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset ) |
---|
| 185 | { |
---|
| 186 | decodeMergeFlag( pcCU, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
| 187 | if ( pcCU->getMergeFlag( uiSubPartIdx ) ) |
---|
| 188 | { |
---|
| 189 | decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, ePartSize, uhInterDirNeighbours, cMvFieldNeighbours, uiDepth ); |
---|
| 190 | UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx); |
---|
| 191 | #if REF_IDX_FRAMEWORK // HM bug fix |
---|
| 192 | if(uiPartIdx) |
---|
| 193 | { |
---|
| 194 | for(UInt ui=0; ui<uiMergeIndex+1; ui++) |
---|
| 195 | { |
---|
| 196 | cMvFieldNeighbours[(ui<<1)].setMvField(TComMv(), NOT_VALID); |
---|
| 197 | cMvFieldNeighbours[(ui<<1)+1].setMvField(TComMv(), NOT_VALID); |
---|
| 198 | } |
---|
| 199 | } |
---|
| 200 | #endif |
---|
| 201 | if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 ) |
---|
| 202 | { |
---|
| 203 | pcSubCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
| 204 | if ( !isMerged ) |
---|
| 205 | { |
---|
| 206 | pcSubCU->getInterMergeCandidates( 0, 0, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand ); |
---|
| 207 | isMerged = true; |
---|
| 208 | } |
---|
| 209 | pcSubCU->setPartSizeSubParts( ePartSize, 0, uiDepth ); |
---|
| 210 | } |
---|
| 211 | else |
---|
| 212 | { |
---|
| 213 | uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx); |
---|
| 214 | pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex ); |
---|
| 215 | } |
---|
| 216 | pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth ); |
---|
| 217 | |
---|
| 218 | TComMv cTmpMv( 0, 0 ); |
---|
| 219 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
| 220 | { |
---|
| 221 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
| 222 | { |
---|
| 223 | pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth); |
---|
| 224 | pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth); |
---|
| 225 | pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
| 226 | pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], ePartSize, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
| 227 | } |
---|
| 228 | } |
---|
| 229 | } |
---|
| 230 | else |
---|
| 231 | { |
---|
| 232 | decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
| 233 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
| 234 | { |
---|
| 235 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
| 236 | { |
---|
| 237 | decodeRefFrmIdxPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) ); |
---|
| 238 | decodeMvdPU ( pcCU, uiSubPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) ); |
---|
| 239 | decodeMVPIdxPU ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) ); |
---|
| 240 | } |
---|
| 241 | } |
---|
| 242 | } |
---|
| 243 | if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) ) |
---|
| 244 | { |
---|
| 245 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( TComMv(0,0), ePartSize, uiSubPartIdx, uiDepth, uiPartIdx); |
---|
| 246 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( -1, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx); |
---|
| 247 | pcCU->setInterDirSubParts( 1, uiSubPartIdx, uiPartIdx, uiDepth); |
---|
| 248 | } |
---|
| 249 | } |
---|
| 250 | return; |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | /** decode inter direction for a PU block |
---|
| 254 | * \param pcCU |
---|
| 255 | * \param uiAbsPartIdx |
---|
| 256 | * \param uiDepth |
---|
| 257 | * \param uiPartIdx |
---|
| 258 | * \returns Void |
---|
| 259 | */ |
---|
| 260 | Void TDecEntropy::decodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx ) |
---|
| 261 | { |
---|
| 262 | UInt uiInterDir; |
---|
| 263 | |
---|
| 264 | if ( pcCU->getSlice()->isInterP() ) |
---|
| 265 | { |
---|
| 266 | uiInterDir = 1; |
---|
| 267 | } |
---|
| 268 | else |
---|
| 269 | { |
---|
| 270 | m_pcEntropyDecoderIf->parseInterDir( pcCU, uiInterDir, uiAbsPartIdx, uiDepth ); |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | pcCU->setInterDirSubParts( uiInterDir, uiAbsPartIdx, uiPartIdx, uiDepth ); |
---|
| 274 | } |
---|
| 275 | |
---|
| 276 | Void TDecEntropy::decodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList ) |
---|
| 277 | { |
---|
| 278 | Int iRefFrmIdx = 0; |
---|
| 279 | Int iParseRefFrmIdx = pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ); |
---|
| 280 | |
---|
| 281 | if ( pcCU->getSlice()->getNumRefIdx( eRefList ) > 1 && iParseRefFrmIdx ) |
---|
| 282 | { |
---|
| 283 | m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, uiAbsPartIdx, uiDepth, eRefList ); |
---|
| 284 | } |
---|
| 285 | else if ( !iParseRefFrmIdx ) |
---|
| 286 | { |
---|
| 287 | iRefFrmIdx = NOT_VALID; |
---|
| 288 | } |
---|
| 289 | else |
---|
| 290 | { |
---|
| 291 | iRefFrmIdx = 0; |
---|
| 292 | } |
---|
| 293 | |
---|
| 294 | PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
| 295 | pcCU->getCUMvField( eRefList )->setAllRefIdx( iRefFrmIdx, ePartSize, uiAbsPartIdx, uiDepth, uiPartIdx ); |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | /** decode motion vector difference for a PU block |
---|
| 299 | * \param pcCU |
---|
| 300 | * \param uiAbsPartIdx |
---|
| 301 | * \param uiDepth |
---|
| 302 | * \param uiPartIdx |
---|
| 303 | * \param eRefList |
---|
| 304 | * \returns Void |
---|
| 305 | */ |
---|
| 306 | Void TDecEntropy::decodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList ) |
---|
| 307 | { |
---|
| 308 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
| 309 | { |
---|
| 310 | m_pcEntropyDecoderIf->parseMvd( pcCU, uiAbsPartIdx, uiPartIdx, uiDepth, eRefList ); |
---|
| 311 | } |
---|
| 312 | } |
---|
| 313 | |
---|
| 314 | Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList ) |
---|
| 315 | { |
---|
| 316 | Int iMVPIdx = -1; |
---|
| 317 | |
---|
| 318 | TComMv cZeroMv( 0, 0 ); |
---|
| 319 | TComMv cMv = cZeroMv; |
---|
| 320 | Int iRefIdx = -1; |
---|
| 321 | |
---|
| 322 | TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList ); |
---|
| 323 | AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo(); |
---|
| 324 | |
---|
| 325 | iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr); |
---|
| 326 | cMv = cZeroMv; |
---|
| 327 | |
---|
| 328 | #if !SPS_AMVP_CLEANUP |
---|
| 329 | if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) && (pcSubCU->getAMVPMode(uiPartAddr) == AM_EXPL) ) |
---|
| 330 | #else |
---|
| 331 | if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) ) |
---|
| 332 | #endif |
---|
| 333 | { |
---|
| 334 | m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx ); |
---|
| 335 | } |
---|
| 336 | pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo); |
---|
| 337 | pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth); |
---|
| 338 | pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth ); |
---|
| 339 | if ( iRefIdx >= 0 ) |
---|
| 340 | { |
---|
| 341 | m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, iRefIdx, cMv); |
---|
| 342 | cMv += pcSubCUMvField->getMvd( uiPartAddr ); |
---|
| 343 | } |
---|
| 344 | |
---|
| 345 | PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr ); |
---|
| 346 | pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx); |
---|
| 347 | } |
---|
| 348 | |
---|
| 349 | Void TDecEntropy::xDecodeTransform( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt absTUPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, UInt uiInnerQuadIdx, Bool& bCodeDQP) |
---|
| 350 | { |
---|
| 351 | UInt uiSubdiv; |
---|
| 352 | const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth; |
---|
| 353 | |
---|
| 354 | if(uiTrIdx==0) |
---|
| 355 | { |
---|
| 356 | m_bakAbsPartIdxCU = uiAbsPartIdx; |
---|
| 357 | } |
---|
| 358 | if( uiLog2TrafoSize == 2 ) |
---|
| 359 | { |
---|
| 360 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
| 361 | if( ( uiAbsPartIdx % partNum ) == 0 ) |
---|
| 362 | { |
---|
| 363 | m_uiBakAbsPartIdx = uiAbsPartIdx; |
---|
| 364 | m_uiBakChromaOffset = offsetChroma; |
---|
| 365 | } |
---|
| 366 | } |
---|
| 367 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) ) |
---|
| 368 | { |
---|
| 369 | uiSubdiv = 1; |
---|
| 370 | } |
---|
| 371 | else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) ) |
---|
| 372 | { |
---|
| 373 | uiSubdiv = (uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx)); |
---|
| 374 | } |
---|
| 375 | else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
| 376 | { |
---|
| 377 | uiSubdiv = 1; |
---|
| 378 | } |
---|
| 379 | else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
| 380 | { |
---|
| 381 | uiSubdiv = 0; |
---|
| 382 | } |
---|
| 383 | else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
| 384 | { |
---|
| 385 | uiSubdiv = 0; |
---|
| 386 | } |
---|
| 387 | else |
---|
| 388 | { |
---|
| 389 | assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ); |
---|
| 390 | #if TRANS_SPLIT_FLAG_CTX_REDUCTION |
---|
| 391 | m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize ); |
---|
| 392 | #else |
---|
| 393 | m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, uiDepth ); |
---|
| 394 | #endif |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | const UInt uiTrDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx ); |
---|
| 398 | { |
---|
| 399 | const Bool bFirstCbfOfCU = uiTrDepth == 0; |
---|
| 400 | if( bFirstCbfOfCU ) |
---|
| 401 | { |
---|
| 402 | pcCU->setCbfSubParts( 0, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth ); |
---|
| 403 | pcCU->setCbfSubParts( 0, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth ); |
---|
| 404 | } |
---|
| 405 | if( bFirstCbfOfCU || uiLog2TrafoSize > 2 ) |
---|
| 406 | { |
---|
| 407 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) ) |
---|
| 408 | { |
---|
| 409 | m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth, uiDepth ); |
---|
| 410 | } |
---|
| 411 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) ) |
---|
| 412 | { |
---|
| 413 | m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth, uiDepth ); |
---|
| 414 | } |
---|
| 415 | } |
---|
| 416 | else |
---|
| 417 | { |
---|
| 418 | pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth ); |
---|
| 419 | pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth ); |
---|
| 420 | } |
---|
| 421 | } |
---|
| 422 | |
---|
| 423 | if( uiSubdiv ) |
---|
| 424 | { |
---|
| 425 | UInt size; |
---|
| 426 | width >>= 1; |
---|
| 427 | height >>= 1; |
---|
| 428 | size = width*height; |
---|
| 429 | uiTrIdx++; |
---|
| 430 | ++uiDepth; |
---|
| 431 | const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1); |
---|
| 432 | const UInt uiStartAbsPartIdx = uiAbsPartIdx; |
---|
| 433 | UInt uiLumaTrMode, uiChromaTrMode; |
---|
| 434 | pcCU->convertTransIdx( uiStartAbsPartIdx, uiTrDepth+1, uiLumaTrMode, uiChromaTrMode ); |
---|
| 435 | UInt uiYCbf = 0; |
---|
| 436 | UInt uiUCbf = 0; |
---|
| 437 | UInt uiVCbf = 0; |
---|
| 438 | |
---|
| 439 | for( Int i = 0; i < 4; i++ ) |
---|
| 440 | { |
---|
| 441 | #if REMOVE_NSQT |
---|
| 442 | UInt nsAddr = uiAbsPartIdx; |
---|
| 443 | #else |
---|
| 444 | UInt nsAddr = 0; |
---|
| 445 | nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, i, uiTrDepth+1 ); |
---|
| 446 | #endif |
---|
| 447 | xDecodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, nsAddr, uiDepth, width, height, uiTrIdx, i, bCodeDQP ); |
---|
| 448 | uiYCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiLumaTrMode ); |
---|
| 449 | uiUCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiChromaTrMode ); |
---|
| 450 | uiVCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiChromaTrMode ); |
---|
| 451 | uiAbsPartIdx += uiQPartNum; |
---|
| 452 | offsetLuma += size; offsetChroma += (size>>2); |
---|
| 453 | } |
---|
| 454 | |
---|
| 455 | pcCU->convertTransIdx( uiStartAbsPartIdx, uiTrDepth, uiLumaTrMode, uiChromaTrMode ); |
---|
| 456 | for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui ) |
---|
| 457 | { |
---|
| 458 | pcCU->getCbf( TEXT_LUMA )[uiStartAbsPartIdx + ui] |= uiYCbf << uiLumaTrMode; |
---|
| 459 | pcCU->getCbf( TEXT_CHROMA_U )[uiStartAbsPartIdx + ui] |= uiUCbf << uiChromaTrMode; |
---|
| 460 | pcCU->getCbf( TEXT_CHROMA_V )[uiStartAbsPartIdx + ui] |= uiVCbf << uiChromaTrMode; |
---|
| 461 | } |
---|
| 462 | } |
---|
| 463 | else |
---|
| 464 | { |
---|
| 465 | assert( uiDepth >= pcCU->getDepth( uiAbsPartIdx ) ); |
---|
| 466 | pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiDepth ); |
---|
| 467 | |
---|
| 468 | { |
---|
| 469 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 470 | DTRACE_CABAC_T( "\tTrIdx: abspart=" ); |
---|
| 471 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
| 472 | DTRACE_CABAC_T( "\tdepth=" ); |
---|
| 473 | DTRACE_CABAC_V( uiDepth ); |
---|
| 474 | DTRACE_CABAC_T( "\ttrdepth=" ); |
---|
| 475 | DTRACE_CABAC_V( uiTrDepth ); |
---|
| 476 | DTRACE_CABAC_T( "\n" ); |
---|
| 477 | } |
---|
| 478 | |
---|
| 479 | UInt uiLumaTrMode, uiChromaTrMode; |
---|
| 480 | pcCU->convertTransIdx( uiAbsPartIdx, uiTrDepth, uiLumaTrMode, uiChromaTrMode ); |
---|
| 481 | #if !REMOVE_NSQT |
---|
| 482 | if(pcCU->getPredictionMode( uiAbsPartIdx ) == MODE_INTER && pcCU->useNonSquarePU( uiAbsPartIdx ) ) |
---|
| 483 | { |
---|
| 484 | pcCU->setNSQTIdxSubParts( uiLog2TrafoSize, uiAbsPartIdx, absTUPartIdx, uiLumaTrMode ); |
---|
| 485 | } |
---|
| 486 | #endif |
---|
| 487 | pcCU->setCbfSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiDepth ); |
---|
| 488 | #if INTRA_BL |
---|
[17] | 489 | #if NO_RESIDUAL_FLAG_FOR_BLPRED |
---|
| 490 | if( ( !pcCU->isIntra(uiAbsPartIdx) || pcCU->isIntraBL(uiAbsPartIdx)) && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) ) |
---|
| 491 | #else |
---|
[2] | 492 | if( ( !pcCU->isIntra(uiAbsPartIdx) ) && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) ) |
---|
[17] | 493 | #endif |
---|
[2] | 494 | #else |
---|
| 495 | if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) ) |
---|
| 496 | #endif |
---|
| 497 | { |
---|
| 498 | pcCU->setCbfSubParts( 1 << uiLumaTrMode, TEXT_LUMA, uiAbsPartIdx, uiDepth ); |
---|
| 499 | } |
---|
| 500 | else |
---|
| 501 | { |
---|
| 502 | m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiLumaTrMode, uiDepth ); |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | |
---|
| 506 | // transform_unit begin |
---|
| 507 | UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA , uiTrIdx ); |
---|
| 508 | UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
| 509 | UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
| 510 | if( uiLog2TrafoSize == 2 ) |
---|
| 511 | { |
---|
| 512 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
| 513 | if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
---|
| 514 | { |
---|
| 515 | cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
| 516 | cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
| 517 | } |
---|
| 518 | } |
---|
| 519 | if ( cbfY || cbfU || cbfV ) |
---|
| 520 | { |
---|
| 521 | // dQP: only for LCU |
---|
| 522 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
| 523 | { |
---|
| 524 | if ( bCodeDQP ) |
---|
| 525 | { |
---|
| 526 | decodeQP( pcCU, m_bakAbsPartIdxCU); |
---|
| 527 | bCodeDQP = false; |
---|
| 528 | } |
---|
| 529 | } |
---|
| 530 | } |
---|
| 531 | if( cbfY ) |
---|
| 532 | { |
---|
| 533 | Int trWidth = width; |
---|
| 534 | Int trHeight = height; |
---|
| 535 | #if !REMOVE_NSQT |
---|
| 536 | pcCU->getNSQTSize( uiTrIdx, uiAbsPartIdx, trWidth, trHeight ); |
---|
| 537 | #endif |
---|
| 538 | m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); |
---|
| 539 | } |
---|
| 540 | if( uiLog2TrafoSize > 2 ) |
---|
| 541 | { |
---|
| 542 | Int trWidth = width >> 1; |
---|
| 543 | Int trHeight = height >> 1; |
---|
| 544 | #if !REMOVE_NSQT |
---|
| 545 | pcCU->getNSQTSize( uiTrIdx, uiAbsPartIdx, trWidth, trHeight ); |
---|
| 546 | #endif |
---|
| 547 | if( cbfU ) |
---|
| 548 | { |
---|
| 549 | m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
| 550 | } |
---|
| 551 | if( cbfV ) |
---|
| 552 | { |
---|
| 553 | m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
| 554 | } |
---|
| 555 | } |
---|
| 556 | else |
---|
| 557 | { |
---|
| 558 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
| 559 | if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
---|
| 560 | { |
---|
| 561 | Int trWidth = width; |
---|
| 562 | Int trHeight = height; |
---|
| 563 | #if !REMOVE_NSQT |
---|
| 564 | pcCU->getNSQTSize( uiTrIdx - 1, uiAbsPartIdx, trWidth, trHeight ); |
---|
| 565 | #endif |
---|
| 566 | if( cbfU ) |
---|
| 567 | { |
---|
| 568 | m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
| 569 | } |
---|
| 570 | if( cbfV ) |
---|
| 571 | { |
---|
| 572 | m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
| 573 | } |
---|
| 574 | } |
---|
| 575 | } |
---|
| 576 | // transform_unit end |
---|
| 577 | } |
---|
| 578 | } |
---|
| 579 | |
---|
| 580 | Void TDecEntropy::decodeQP ( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 581 | { |
---|
| 582 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
| 583 | { |
---|
| 584 | m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) ); |
---|
| 585 | } |
---|
| 586 | } |
---|
| 587 | |
---|
| 588 | |
---|
| 589 | /** decode coefficients |
---|
| 590 | * \param pcCU |
---|
| 591 | * \param uiAbsPartIdx |
---|
| 592 | * \param uiDepth |
---|
| 593 | * \param uiWidth |
---|
| 594 | * \param uiHeight |
---|
| 595 | * \returns Void |
---|
| 596 | */ |
---|
| 597 | Void TDecEntropy::decodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP ) |
---|
| 598 | { |
---|
| 599 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
| 600 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
| 601 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
| 602 | |
---|
[17] | 603 | #if NO_RESIDUAL_FLAG_FOR_BLPRED |
---|
| 604 | if( pcCU->isIntra(uiAbsPartIdx) && !pcCU->isIntraBL(uiAbsPartIdx) ) |
---|
| 605 | #else |
---|
[2] | 606 | if( pcCU->isIntra(uiAbsPartIdx) ) |
---|
[17] | 607 | #endif |
---|
[2] | 608 | { |
---|
| 609 | } |
---|
| 610 | else |
---|
| 611 | { |
---|
| 612 | UInt uiQtRootCbf = 1; |
---|
| 613 | if( !( pcCU->getPartitionSize( uiAbsPartIdx) == SIZE_2Nx2N && pcCU->getMergeFlag( uiAbsPartIdx ) ) ) |
---|
| 614 | { |
---|
| 615 | m_pcEntropyDecoderIf->parseQtRootCbf( pcCU, uiAbsPartIdx, uiDepth, uiQtRootCbf ); |
---|
| 616 | } |
---|
| 617 | if ( !uiQtRootCbf ) |
---|
| 618 | { |
---|
| 619 | pcCU->setCbfSubParts( 0, 0, 0, uiAbsPartIdx, uiDepth ); |
---|
| 620 | pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth ); |
---|
| 621 | #if !REMOVE_NSQT |
---|
| 622 | pcCU->setNSQTIdxSubParts( uiAbsPartIdx, uiDepth ); |
---|
| 623 | #endif |
---|
| 624 | return; |
---|
| 625 | } |
---|
| 626 | |
---|
| 627 | } |
---|
| 628 | xDecodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, 0, bCodeDQP ); |
---|
| 629 | } |
---|
| 630 | |
---|
| 631 | //! \} |
---|