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