source: SHVCSoftware/branches/SHM-dev/source/Lib/TLibDecoder/TDecEntropy.cpp @ 1510

Last change on this file since 1510 was 1410, checked in by seregin, 9 years ago

port rev 4563

  • Property svn:eol-style set to native
File size: 22.3 KB
RevLine 
[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"
44static const Bool bDebugRQT = DebugOptionList::DebugRQT.getInt()!=0;
45static const Bool bDebugPredEnabled = DebugOptionList::DebugPred.getInt()!=0;
46#endif
47
[313]48//! \ingroup TLibDecoder
49//! \{
50
51Void TDecEntropy::setEntropyDecoder         ( TDecEntropyIf* p )
52{
53  m_pcEntropyDecoderIf = p;
54}
55
56#include "TLibCommon/TComSampleAdaptiveOffset.h"
57
58Void TDecEntropy::decodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
59{
60  m_pcEntropyDecoderIf->parseSkipFlag( pcCU, uiAbsPartIdx, uiDepth );
61}
62
[1029]63
[313]64Void TDecEntropy::decodeCUTransquantBypassFlag(TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
65{
66  m_pcEntropyDecoderIf->parseCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth );
67}
68
[1029]69
[313]70/** decode merge flag
71 * \param pcSubCU
[1029]72 * \param uiAbsPartIdx
[313]73 * \param uiDepth
[1029]74 * \param uiPUIdx
[313]75 * \returns Void
76 */
77Void TDecEntropy::decodeMergeFlag( TComDataCU* pcSubCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
[1029]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
[1029]85 * \param uiPartIdx
86 * \param uiAbsPartIdx
[313]87 * \param uiDepth
88 * \returns Void
89 */
90Void TDecEntropy::decodeMergeIndex( TComDataCU* pcCU, UInt uiPartIdx, UInt uiAbsPartIdx, UInt uiDepth )
91{
92  UInt uiMergeIndex = 0;
93  m_pcEntropyDecoderIf->parseMergeIndex( pcCU, uiMergeIndex );
94  pcCU->setMergeIndexSubParts( uiMergeIndex, uiAbsPartIdx, uiPartIdx, uiDepth );
95}
96
97Void TDecEntropy::decodeSplitFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
98{
99  m_pcEntropyDecoderIf->parseSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
100}
101
102Void TDecEntropy::decodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
103{
104  m_pcEntropyDecoderIf->parsePredMode( pcCU, uiAbsPartIdx, uiDepth );
105}
106
107Void TDecEntropy::decodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
108{
109  m_pcEntropyDecoderIf->parsePartSize( pcCU, uiAbsPartIdx, uiDepth );
110}
111
112Void TDecEntropy::decodePredInfo    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
113{
114  if( pcCU->isIntra( uiAbsPartIdx ) )                                 // If it is Intra mode, encode intra prediction mode.
115  {
116    decodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx, uiDepth );
[1029]117    if (pcCU->getPic()->getChromaFormat()!=CHROMA_400)
118    {
119      decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth );
120      if (enable4ChromaPUsInIntraNxNCU(pcCU->getPic()->getChromaFormat()) && pcCU->getPartitionSize( uiAbsPartIdx )==SIZE_NxN)
121      {
122        UInt uiPartOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2;
123        decodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset,   uiDepth+1 );
124        decodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset*2, uiDepth+1 );
125        decodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset*3, uiDepth+1 );
126      }
127    }
[313]128  }
129  else                                                                // if it is Inter mode, encode motion vector and reference index
130  {
131    decodePUWise( pcCU, uiAbsPartIdx, uiDepth, pcSubCU );
132  }
133}
134
[1029]135/** Parse I_PCM information.
[313]136 * \param pcCU  pointer to CUpointer to CU
137 * \param uiAbsPartIdx CU index
138 * \param uiDepth CU depth
139 * \returns Void
140 */
141Void TDecEntropy::decodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
142{
143  if(!pcCU->getSlice()->getSPS()->getUsePCM()
144    || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize())
145    || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()) )
146  {
147    return;
148  }
[1029]149
[313]150  m_pcEntropyDecoderIf->parseIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
151}
152
153Void TDecEntropy::decodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
154{
155  m_pcEntropyDecoderIf->parseIntraDirLumaAng( pcCU, uiAbsPartIdx, uiDepth );
156}
157
158Void TDecEntropy::decodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
159{
160  m_pcEntropyDecoderIf->parseIntraDirChroma( pcCU, uiAbsPartIdx, uiDepth );
[1029]161#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
162  if (bDebugPredEnabled)
163  {
164    UInt cdir=pcCU->getIntraDir(CHANNEL_TYPE_CHROMA, uiAbsPartIdx);
[1246]165    if (cdir==36)
166    {
167      cdir=pcCU->getIntraDir(CHANNEL_TYPE_LUMA, uiAbsPartIdx);
168    }
[1029]169    printf("coding chroma Intra dir: %d, uiAbsPartIdx: %d, luma dir: %d\n", cdir, uiAbsPartIdx, pcCU->getIntraDir(CHANNEL_TYPE_LUMA, uiAbsPartIdx));
170  }
171#endif
[313]172}
173
[1029]174
[313]175/** decode motion information for every PU block.
176 * \param pcCU
[1029]177 * \param uiAbsPartIdx
[313]178 * \param uiDepth
179 * \param pcSubCU
180 * \returns Void
181 */
182Void TDecEntropy::decodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
183{
184  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
185  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
[1290]186  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxTotalCUDepth() - uiDepth ) << 1 ) ) >> 4;
[313]187
188  TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
189  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
190
191  for ( UInt ui = 0; ui < pcCU->getSlice()->getMaxNumMergeCand(); ui++ )
192  {
193    uhInterDirNeighbours[ui] = 0;
194  }
195  Int numValidMergeCand = 0;
[1247]196  Bool hasMergedCandList = false;
[313]197
198  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
199  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 );
200  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
201  {
202    decodeMergeFlag( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
203    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
204    {
205      decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, uiDepth );
[1029]206#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
207      if (bDebugPredEnabled)
208      {
209        std::cout << "Coded merge flag, CU absPartIdx: " << uiAbsPartIdx << " PU(" << uiPartIdx << ") absPartIdx: " << uiSubPartIdx;
210        std::cout << " merge index: " << (UInt)pcCU->getMergeIndex(uiSubPartIdx) << std::endl;
211      }
212#endif
213
[1410]214      const UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
[1029]215      if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 )
[313]216      {
[1247]217        if ( !hasMergedCandList )
[313]218        {
[1247]219          pcSubCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); // temporarily set.
[313]220          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
[1247]221          pcSubCU->setPartSizeSubParts( ePartSize, 0, uiDepth ); // restore.
222          hasMergedCandList = true;
[313]223        }
224      }
225      else
226      {
227        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
228      }
[1029]229
[313]230      pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
231
232      TComMv cTmpMv( 0, 0 );
233      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
[1029]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 );
[1029]241
[313]242        }
243      }
244    }
245    else
246    {
247      decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
248      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
[1029]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 ) );
[1029]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    }
[1029]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
[1029]281 * \param uiAbsPartIdx
[313]282 * \param uiDepth
[1029]283 * \param uiPartIdx
[313]284 * \returns Void
285 */
286Void 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
302Void 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
[1029]326 * \param uiAbsPartIdx
[313]327 * \param uiDepth
328 * \param uiPartIdx
[1029]329 * \param eRefList
[313]330 * \returns Void
331 */
332Void 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
340Void 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
[1029]371Void TDecEntropy::xDecodeTransform        ( Bool& bCodeDQP, Bool& isChromaQpAdjCoded, TComTU &rTu, const Int quadtreeTULog2MinSizeInCU )
[313]372{
[1029]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;
[1029]379  const UInt numValidComponent = pcCU->getPic()->getNumberValidComponents();
380  const Bool bChroma = isChromaEnabled(pcCU->getPic()->getChromaFormat());
[313]381
[1029]382  const UInt uiLog2TrafoSize = rTu.GetLog2LumaTrSize();
383#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
384  if (bDebugRQT)
[313]385  {
[1029]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  }
[1029]390#endif
391
392  if( pcCU->isIntra(uiAbsPartIdx) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
[313]393  {
394    uiSubdiv = 1;
395  }
[1029]396  else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->isInter(uiAbsPartIdx)) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) )
[313]397  {
[1029]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  }
[1029]417
418  for(Int chan=COMPONENT_Cb; chan<numValidComponent; chan++)
[313]419  {
[1029]420    const ComponentID compID=ComponentID(chan);
421    const UInt trDepthTotalAdj=rTu.GetTransformDepthTotalAdj(compID);
422
[313]423    const Bool bFirstCbfOfCU = uiTrDepth == 0;
[1029]424
[313]425    if( bFirstCbfOfCU )
426    {
[1029]427      pcCU->setCbfSubParts( 0, compID, rTu.GetAbsPartIdxTU(compID), trDepthTotalAdj);
[313]428    }
[1029]429    if( bFirstCbfOfCU || rTu.ProcessingAllQuadrants(compID) )
[313]430    {
[1029]431      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, compID, uiTrDepth - 1 ) )
[313]432      {
[1029]433        m_pcEntropyDecoderIf->parseQtCbf( rTu, compID, (uiSubdiv == 0) );
[313]434      }
435    }
436  }
[1029]437
[313]438  if( uiSubdiv )
439  {
[1029]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    {
[1029]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    } while (tuRecurseChild.nextSection(rTu) );
454
455    for(UInt ch=0; ch<numValidComponent; ch++)
[313]456    {
[1029]457      UChar *pBase = pcCU->getCbf( ComponentID(ch) ) + uiAbsPartIdx;
458      const UChar flag = uiYUVCbf[ch] << uiTrDepth;
459
460      for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui )
461      {
462        pBase[ui] |= flag;
463      }
[313]464    }
465  }
466  else
467  {
468    assert( uiDepth >= pcCU->getDepth( uiAbsPartIdx ) );
469    pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiDepth );
[1029]470
[313]471    {
472      DTRACE_CABAC_VL( g_nSymbolCounter++ );
473      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
474      DTRACE_CABAC_V( uiAbsPartIdx );
475      DTRACE_CABAC_T( "\tdepth=" );
476      DTRACE_CABAC_V( uiDepth );
477      DTRACE_CABAC_T( "\ttrdepth=" );
478      DTRACE_CABAC_V( uiTrDepth );
479      DTRACE_CABAC_T( "\n" );
480    }
[1029]481
482    pcCU->setCbfSubParts ( 0, COMPONENT_Y, uiAbsPartIdx, uiDepth );
483
484    if( (!pcCU->isIntra(uiAbsPartIdx)) && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && ((!bChroma) || (!pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cb, 0 ) && !pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cr, 0 )) ))
[313]485    {
[1029]486      pcCU->setCbfSubParts( 1 << uiTrDepth, COMPONENT_Y, uiAbsPartIdx, uiDepth );
[313]487    }
488    else
489    {
[1029]490      m_pcEntropyDecoderIf->parseQtCbf( rTu, COMPONENT_Y, true );
[313]491    }
492
493
494    // transform_unit begin
[1029]495    UInt cbf[MAX_NUM_COMPONENT]={0,0,0};
496    Bool validCbf       = false;
497    Bool validChromaCbf = false;
498    const UInt uiTrIdx = rTu.GetTransformDepthRel();
499
500    for(UInt ch=0; ch<pcCU->getPic()->getNumberValidComponents(); ch++)
[313]501    {
[1029]502      const ComponentID compID = ComponentID(ch);
503
504      cbf[compID] = pcCU->getCbf( uiAbsPartIdx, compID, uiTrIdx );
505
506      if (cbf[compID] != 0)
[313]507      {
[1029]508        validCbf = true;
[1246]509        if (isChroma(compID))
510        {
511          validChromaCbf = true;
512        }
[313]513      }
514    }
[1029]515
516    if ( validCbf )
[313]517    {
[1029]518
519      // dQP: only for CTU
[313]520      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
521      {
522        if ( bCodeDQP )
523        {
[1029]524          const UInt uiAbsPartIdxCU=rTu.GetAbsPartIdxCU();
525          decodeQP( pcCU, uiAbsPartIdxCU);
[313]526          bCodeDQP = false;
527        }
528      }
[1029]529
530      if ( pcCU->getSlice()->getUseChromaQpAdj() )
[313]531      {
[1029]532        if ( validChromaCbf && isChromaQpAdjCoded && !pcCU->getCUTransquantBypass(rTu.GetAbsPartIdxCU()) )
533        {
534          decodeChromaQpAdjustment( pcCU, rTu.GetAbsPartIdxCU() );
535          isChromaQpAdjCoded = false;
536        }
[313]537      }
[1029]538
539      const UInt numValidComp=pcCU->getPic()->getNumberValidComponents();
540
541      for(UInt ch=COMPONENT_Y; ch<numValidComp; ch++)
[313]542      {
[1029]543        const ComponentID compID=ComponentID(ch);
544
545        if( rTu.ProcessComponentSection(compID) )
[313]546        {
[1029]547#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
[1246]548          if (bDebugRQT)
549          {
550            printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, rTu.getRect(compID).width, rTu.getRect(compID).height, 1);
551          }
[1029]552#endif
553
554          if (rTu.getRect(compID).width != rTu.getRect(compID).height)
555          {
556            //code two sub-TUs
557            TComTURecurse subTUIterator(rTu, false, TComTU::VERTICAL_SPLIT, true, compID);
558
559            do
560            {
561              const UInt subTUCBF = pcCU->getCbf(subTUIterator.GetAbsPartIdxTU(), compID, (uiTrIdx + 1));
562
563              if (subTUCBF != 0)
564              {
565#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
[1246]566                if (bDebugRQT)
567                {
568                  printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, subTUIterator.getRect(compID).width, subTUIterator.getRect(compID).height, 1);
569                }
[1029]570#endif
571                m_pcEntropyDecoderIf->parseCoeffNxN( subTUIterator, compID );
572              }
[1246]573            } while (subTUIterator.nextSection(rTu));
[1029]574          }
575          else
576          {
577            if(isChroma(compID) && (cbf[COMPONENT_Y] != 0))
578            {
579              m_pcEntropyDecoderIf->parseCrossComponentPrediction( rTu, compID );
580            }
581
582            if(cbf[compID] != 0)
583            {
584              m_pcEntropyDecoderIf->parseCoeffNxN( rTu, compID );
585            }
586          }
[313]587        }
588      }
589    }
590    // transform_unit end
591  }
592}
593
594Void TDecEntropy::decodeQP          ( TComDataCU* pcCU, UInt uiAbsPartIdx )
595{
596  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
597  {
598    m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
599  }
600}
601
[1029]602Void TDecEntropy::decodeChromaQpAdjustment( TComDataCU* pcCU, UInt uiAbsPartIdx )
603{
604  if ( pcCU->getSlice()->getUseChromaQpAdj() )
605  {
606    m_pcEntropyDecoderIf->parseChromaQpAdjustment( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
607  }
608}
[313]609
[1029]610
[1260]611//! decode coefficients
[1029]612Void 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    {
[1029]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    }
[1029]631
[313]632  }
[1029]633
634  TComTURecurse tuRecurse(pcCU, uiAbsPartIdx, uiDepth);
635
636#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
637  if (bDebugRQT)
[1246]638  {
[1029]639    printf("..codeCoeff: uiAbsPartIdx=%d, PU format=%d, 2Nx2N=%d, NxN=%d\n", uiAbsPartIdx, pcCU->getPartitionSize(uiAbsPartIdx), SIZE_2Nx2N, SIZE_NxN);
[1246]640  }
[1029]641#endif
642
643  Int quadtreeTULog2MinSizeInCU = pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx);
[595]644 
[1029]645  xDecodeTransform( bCodeDQP, isChromaQpAdjCoded, tuRecurse, quadtreeTULog2MinSizeInCU );
[313]646}
647
648//! \}
Note: See TracBrowser for help on using the repository browser.