[313] | 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 | |
---|
| 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 | |
---|
| 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 | { |
---|
| 113 | #if INTRA_BL |
---|
| 114 | if( pcCU->isIntraBL( uiAbsPartIdx ) ) // Do nothing for Intra BL mode. |
---|
| 115 | { |
---|
| 116 | return; |
---|
| 117 | } |
---|
| 118 | #endif |
---|
| 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); |
---|
| 190 | if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 ) |
---|
| 191 | { |
---|
| 192 | pcSubCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
| 193 | if ( !isMerged ) |
---|
| 194 | { |
---|
| 195 | pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand ); |
---|
| 196 | isMerged = true; |
---|
| 197 | } |
---|
| 198 | pcSubCU->setPartSizeSubParts( ePartSize, 0, uiDepth ); |
---|
| 199 | } |
---|
| 200 | else |
---|
| 201 | { |
---|
| 202 | uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx); |
---|
| 203 | pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex ); |
---|
| 204 | } |
---|
| 205 | pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth ); |
---|
| 206 | |
---|
| 207 | TComMv cTmpMv( 0, 0 ); |
---|
| 208 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
| 209 | { |
---|
| 210 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
| 211 | { |
---|
| 212 | pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth); |
---|
| 213 | pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth); |
---|
| 214 | pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
| 215 | pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], ePartSize, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
| 216 | } |
---|
| 217 | } |
---|
| 218 | } |
---|
| 219 | else |
---|
| 220 | { |
---|
| 221 | decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
| 222 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
| 223 | { |
---|
| 224 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
| 225 | { |
---|
| 226 | decodeRefFrmIdxPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) ); |
---|
| 227 | decodeMvdPU ( pcCU, uiSubPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) ); |
---|
| 228 | decodeMVPIdxPU ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) ); |
---|
| 229 | } |
---|
| 230 | } |
---|
| 231 | } |
---|
| 232 | if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) ) |
---|
| 233 | { |
---|
| 234 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( TComMv(0,0), ePartSize, uiSubPartIdx, uiDepth, uiPartIdx); |
---|
| 235 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( -1, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx); |
---|
| 236 | pcCU->setInterDirSubParts( 1, uiSubPartIdx, uiPartIdx, uiDepth); |
---|
| 237 | } |
---|
| 238 | } |
---|
| 239 | return; |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | /** decode inter direction for a PU block |
---|
| 243 | * \param pcCU |
---|
| 244 | * \param uiAbsPartIdx |
---|
| 245 | * \param uiDepth |
---|
| 246 | * \param uiPartIdx |
---|
| 247 | * \returns Void |
---|
| 248 | */ |
---|
| 249 | Void TDecEntropy::decodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx ) |
---|
| 250 | { |
---|
| 251 | UInt uiInterDir; |
---|
| 252 | |
---|
| 253 | if ( pcCU->getSlice()->isInterP() ) |
---|
| 254 | { |
---|
| 255 | uiInterDir = 1; |
---|
| 256 | } |
---|
| 257 | else |
---|
| 258 | { |
---|
| 259 | m_pcEntropyDecoderIf->parseInterDir( pcCU, uiInterDir, uiAbsPartIdx ); |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | pcCU->setInterDirSubParts( uiInterDir, uiAbsPartIdx, uiPartIdx, uiDepth ); |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | Void TDecEntropy::decodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList ) |
---|
| 266 | { |
---|
| 267 | Int iRefFrmIdx = 0; |
---|
| 268 | Int iParseRefFrmIdx = pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ); |
---|
| 269 | |
---|
| 270 | if ( pcCU->getSlice()->getNumRefIdx( eRefList ) > 1 && iParseRefFrmIdx ) |
---|
| 271 | { |
---|
| 272 | m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, eRefList ); |
---|
| 273 | } |
---|
| 274 | else if ( !iParseRefFrmIdx ) |
---|
| 275 | { |
---|
| 276 | iRefFrmIdx = NOT_VALID; |
---|
| 277 | } |
---|
| 278 | else |
---|
| 279 | { |
---|
| 280 | iRefFrmIdx = 0; |
---|
| 281 | } |
---|
| 282 | |
---|
| 283 | PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
| 284 | pcCU->getCUMvField( eRefList )->setAllRefIdx( iRefFrmIdx, ePartSize, uiAbsPartIdx, uiDepth, uiPartIdx ); |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | /** decode motion vector difference for a PU block |
---|
| 288 | * \param pcCU |
---|
| 289 | * \param uiAbsPartIdx |
---|
| 290 | * \param uiDepth |
---|
| 291 | * \param uiPartIdx |
---|
| 292 | * \param eRefList |
---|
| 293 | * \returns Void |
---|
| 294 | */ |
---|
| 295 | Void TDecEntropy::decodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList ) |
---|
| 296 | { |
---|
| 297 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
| 298 | { |
---|
| 299 | m_pcEntropyDecoderIf->parseMvd( pcCU, uiAbsPartIdx, uiPartIdx, uiDepth, eRefList ); |
---|
| 300 | } |
---|
| 301 | } |
---|
| 302 | |
---|
| 303 | Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList ) |
---|
| 304 | { |
---|
| 305 | Int iMVPIdx = -1; |
---|
| 306 | |
---|
| 307 | TComMv cZeroMv( 0, 0 ); |
---|
| 308 | TComMv cMv = cZeroMv; |
---|
| 309 | Int iRefIdx = -1; |
---|
| 310 | |
---|
| 311 | TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList ); |
---|
| 312 | AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo(); |
---|
| 313 | |
---|
| 314 | iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr); |
---|
| 315 | cMv = cZeroMv; |
---|
| 316 | |
---|
| 317 | if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) ) |
---|
| 318 | { |
---|
| 319 | m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx ); |
---|
| 320 | } |
---|
| 321 | pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo); |
---|
| 322 | pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth); |
---|
| 323 | pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth ); |
---|
| 324 | if ( iRefIdx >= 0 ) |
---|
| 325 | { |
---|
| 326 | m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, cMv); |
---|
| 327 | cMv += pcSubCUMvField->getMvd( uiPartAddr ); |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr ); |
---|
| 331 | pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx); |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | Void TDecEntropy::xDecodeTransform( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP) |
---|
| 335 | { |
---|
| 336 | UInt uiSubdiv; |
---|
| 337 | const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth; |
---|
| 338 | |
---|
| 339 | if(uiTrIdx==0) |
---|
| 340 | { |
---|
| 341 | m_bakAbsPartIdxCU = uiAbsPartIdx; |
---|
| 342 | } |
---|
| 343 | if( uiLog2TrafoSize == 2 ) |
---|
| 344 | { |
---|
| 345 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
| 346 | if( ( uiAbsPartIdx % partNum ) == 0 ) |
---|
| 347 | { |
---|
| 348 | m_uiBakAbsPartIdx = uiAbsPartIdx; |
---|
| 349 | m_uiBakChromaOffset = offsetChroma; |
---|
| 350 | } |
---|
| 351 | } |
---|
| 352 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) ) |
---|
| 353 | { |
---|
| 354 | uiSubdiv = 1; |
---|
| 355 | } |
---|
| 356 | else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) ) |
---|
| 357 | { |
---|
| 358 | uiSubdiv = (uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx)); |
---|
| 359 | } |
---|
| 360 | else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
| 361 | { |
---|
| 362 | uiSubdiv = 1; |
---|
| 363 | } |
---|
| 364 | else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
| 365 | { |
---|
| 366 | uiSubdiv = 0; |
---|
| 367 | } |
---|
| 368 | else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
| 369 | { |
---|
| 370 | uiSubdiv = 0; |
---|
| 371 | } |
---|
| 372 | else |
---|
| 373 | { |
---|
| 374 | assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ); |
---|
| 375 | m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize ); |
---|
| 376 | } |
---|
| 377 | |
---|
| 378 | const UInt uiTrDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx ); |
---|
| 379 | { |
---|
| 380 | const Bool bFirstCbfOfCU = uiTrDepth == 0; |
---|
| 381 | if( bFirstCbfOfCU ) |
---|
| 382 | { |
---|
| 383 | pcCU->setCbfSubParts( 0, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth ); |
---|
| 384 | pcCU->setCbfSubParts( 0, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth ); |
---|
| 385 | } |
---|
| 386 | if( bFirstCbfOfCU || uiLog2TrafoSize > 2 ) |
---|
| 387 | { |
---|
| 388 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) ) |
---|
| 389 | { |
---|
| 390 | m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth, uiDepth ); |
---|
| 391 | } |
---|
| 392 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) ) |
---|
| 393 | { |
---|
| 394 | m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth, uiDepth ); |
---|
| 395 | } |
---|
| 396 | } |
---|
| 397 | else |
---|
| 398 | { |
---|
| 399 | pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth ); |
---|
| 400 | pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth ); |
---|
| 401 | } |
---|
| 402 | } |
---|
| 403 | |
---|
| 404 | if( uiSubdiv ) |
---|
| 405 | { |
---|
| 406 | UInt size; |
---|
| 407 | width >>= 1; |
---|
| 408 | height >>= 1; |
---|
| 409 | size = width*height; |
---|
| 410 | uiTrIdx++; |
---|
| 411 | ++uiDepth; |
---|
| 412 | const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1); |
---|
| 413 | const UInt uiStartAbsPartIdx = uiAbsPartIdx; |
---|
| 414 | UInt uiYCbf = 0; |
---|
| 415 | UInt uiUCbf = 0; |
---|
| 416 | UInt uiVCbf = 0; |
---|
| 417 | |
---|
| 418 | for( Int i = 0; i < 4; i++ ) |
---|
| 419 | { |
---|
| 420 | xDecodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
| 421 | uiYCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth+1 ); |
---|
| 422 | uiUCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth+1 ); |
---|
| 423 | uiVCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth+1 ); |
---|
| 424 | uiAbsPartIdx += uiQPartNum; |
---|
| 425 | offsetLuma += size; offsetChroma += (size>>2); |
---|
| 426 | } |
---|
| 427 | |
---|
| 428 | for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui ) |
---|
| 429 | { |
---|
| 430 | pcCU->getCbf( TEXT_LUMA )[uiStartAbsPartIdx + ui] |= uiYCbf << uiTrDepth; |
---|
| 431 | pcCU->getCbf( TEXT_CHROMA_U )[uiStartAbsPartIdx + ui] |= uiUCbf << uiTrDepth; |
---|
| 432 | pcCU->getCbf( TEXT_CHROMA_V )[uiStartAbsPartIdx + ui] |= uiVCbf << uiTrDepth; |
---|
| 433 | } |
---|
| 434 | } |
---|
| 435 | else |
---|
| 436 | { |
---|
| 437 | assert( uiDepth >= pcCU->getDepth( uiAbsPartIdx ) ); |
---|
| 438 | pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiDepth ); |
---|
| 439 | |
---|
| 440 | { |
---|
| 441 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 442 | DTRACE_CABAC_T( "\tTrIdx: abspart=" ); |
---|
| 443 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
| 444 | DTRACE_CABAC_T( "\tdepth=" ); |
---|
| 445 | DTRACE_CABAC_V( uiDepth ); |
---|
| 446 | DTRACE_CABAC_T( "\ttrdepth=" ); |
---|
| 447 | DTRACE_CABAC_V( uiTrDepth ); |
---|
| 448 | DTRACE_CABAC_T( "\n" ); |
---|
| 449 | } |
---|
| 450 | |
---|
| 451 | pcCU->setCbfSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiDepth ); |
---|
| 452 | #if INTRA_BL |
---|
| 453 | #if NO_RESIDUAL_FLAG_FOR_BLPRED |
---|
| 454 | 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 ) ) |
---|
| 455 | #else |
---|
| 456 | if( ( !pcCU->isIntra(uiAbsPartIdx) ) && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) ) |
---|
| 457 | #endif |
---|
| 458 | #else |
---|
| 459 | if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) ) |
---|
| 460 | #endif |
---|
| 461 | { |
---|
| 462 | pcCU->setCbfSubParts( 1 << uiTrDepth, TEXT_LUMA, uiAbsPartIdx, uiDepth ); |
---|
| 463 | } |
---|
| 464 | else |
---|
| 465 | { |
---|
| 466 | m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrDepth, uiDepth ); |
---|
| 467 | } |
---|
| 468 | |
---|
| 469 | |
---|
| 470 | // transform_unit begin |
---|
| 471 | UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA , uiTrIdx ); |
---|
| 472 | UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
| 473 | UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
| 474 | if( uiLog2TrafoSize == 2 ) |
---|
| 475 | { |
---|
| 476 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
| 477 | if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
---|
| 478 | { |
---|
| 479 | cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
| 480 | cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
| 481 | } |
---|
| 482 | } |
---|
| 483 | if ( cbfY || cbfU || cbfV ) |
---|
| 484 | { |
---|
| 485 | // dQP: only for LCU |
---|
| 486 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
| 487 | { |
---|
| 488 | if ( bCodeDQP ) |
---|
| 489 | { |
---|
| 490 | decodeQP( pcCU, m_bakAbsPartIdxCU); |
---|
| 491 | bCodeDQP = false; |
---|
| 492 | } |
---|
| 493 | } |
---|
| 494 | } |
---|
| 495 | if( cbfY ) |
---|
| 496 | { |
---|
| 497 | Int trWidth = width; |
---|
| 498 | Int trHeight = height; |
---|
| 499 | m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); |
---|
| 500 | } |
---|
| 501 | if( uiLog2TrafoSize > 2 ) |
---|
| 502 | { |
---|
| 503 | Int trWidth = width >> 1; |
---|
| 504 | Int trHeight = height >> 1; |
---|
| 505 | if( cbfU ) |
---|
| 506 | { |
---|
| 507 | m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
| 508 | } |
---|
| 509 | if( cbfV ) |
---|
| 510 | { |
---|
| 511 | m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
| 512 | } |
---|
| 513 | } |
---|
| 514 | else |
---|
| 515 | { |
---|
| 516 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
| 517 | if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
---|
| 518 | { |
---|
| 519 | Int trWidth = width; |
---|
| 520 | Int trHeight = height; |
---|
| 521 | if( cbfU ) |
---|
| 522 | { |
---|
| 523 | m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
| 524 | } |
---|
| 525 | if( cbfV ) |
---|
| 526 | { |
---|
| 527 | m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
| 528 | } |
---|
| 529 | } |
---|
| 530 | } |
---|
| 531 | // transform_unit end |
---|
| 532 | } |
---|
| 533 | } |
---|
| 534 | |
---|
| 535 | Void TDecEntropy::decodeQP ( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 536 | { |
---|
| 537 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
| 538 | { |
---|
| 539 | m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) ); |
---|
| 540 | } |
---|
| 541 | } |
---|
| 542 | |
---|
| 543 | |
---|
| 544 | /** decode coefficients |
---|
| 545 | * \param pcCU |
---|
| 546 | * \param uiAbsPartIdx |
---|
| 547 | * \param uiDepth |
---|
| 548 | * \param uiWidth |
---|
| 549 | * \param uiHeight |
---|
| 550 | * \returns Void |
---|
| 551 | */ |
---|
| 552 | Void TDecEntropy::decodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP ) |
---|
| 553 | { |
---|
| 554 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
| 555 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
| 556 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
| 557 | |
---|
| 558 | #if NO_RESIDUAL_FLAG_FOR_BLPRED |
---|
| 559 | if( pcCU->isIntra(uiAbsPartIdx) && !pcCU->isIntraBL(uiAbsPartIdx) ) |
---|
| 560 | #else |
---|
| 561 | if( pcCU->isIntra(uiAbsPartIdx) ) |
---|
| 562 | #endif |
---|
| 563 | { |
---|
| 564 | } |
---|
| 565 | else |
---|
| 566 | { |
---|
| 567 | UInt uiQtRootCbf = 1; |
---|
| 568 | if( !( pcCU->getPartitionSize( uiAbsPartIdx) == SIZE_2Nx2N && pcCU->getMergeFlag( uiAbsPartIdx ) ) ) |
---|
| 569 | { |
---|
| 570 | m_pcEntropyDecoderIf->parseQtRootCbf( uiAbsPartIdx, uiQtRootCbf ); |
---|
| 571 | } |
---|
| 572 | if ( !uiQtRootCbf ) |
---|
| 573 | { |
---|
| 574 | pcCU->setCbfSubParts( 0, 0, 0, uiAbsPartIdx, uiDepth ); |
---|
| 575 | pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth ); |
---|
| 576 | return; |
---|
| 577 | } |
---|
| 578 | |
---|
| 579 | } |
---|
| 580 | xDecodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP ); |
---|
| 581 | } |
---|
| 582 | |
---|
| 583 | //! \} |
---|