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