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