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