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