source: 3DVCSoftware/trunk/source/Lib/TLibDecoder/TDecEntropy.cpp

Last change on this file was 1413, checked in by tech, 6 years ago

Merged HTM-16.2-dev@1412

  • Property svn:eol-style set to native
File size: 38.0 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
6 * Copyright (c) 2010-2017, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TDecEntropy.cpp
35    \brief    entropy decoder class
36*/
37
38#include "TDecEntropy.h"
39#include "TLibCommon/TComTU.h"
40#include "TLibCommon/TComPrediction.h"
41
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
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#if NH_3D
63Void TDecEntropy::decodeDIS( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
64{
65  if( !pcCU->getSlice()->getDepthIntraSkipFlag() )
66  {
67    return;
68  } 
69  m_pcEntropyDecoderIf->parseDIS( pcCU, uiAbsPartIdx, uiDepth );
70}
71#endif
72
73Void TDecEntropy::decodeCUTransquantBypassFlag(TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
74{
75  m_pcEntropyDecoderIf->parseCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth );
76}
77
78
79/** decode merge flag
80 * \param pcSubCU
81 * \param uiAbsPartIdx
82 * \param uiDepth
83 * \param uiPUIdx
84 * \returns Void
85 */
86Void TDecEntropy::decodeMergeFlag( TComDataCU* pcSubCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
87{
88  // at least one merge candidate exists
89  m_pcEntropyDecoderIf->parseMergeFlag( pcSubCU, uiAbsPartIdx, uiDepth, uiPUIdx );
90}
91
92/** decode merge index
93 * \param pcCU
94 * \param uiPartIdx
95 * \param uiAbsPartIdx
96 * \param uiDepth
97 * \returns Void
98 */
99Void TDecEntropy::decodeMergeIndex( TComDataCU* pcCU, UInt uiPartIdx, UInt uiAbsPartIdx, UInt uiDepth )
100{
101  UInt uiMergeIndex = 0;
102  m_pcEntropyDecoderIf->parseMergeIndex( pcCU, uiMergeIndex );
103  pcCU->setMergeIndexSubParts( uiMergeIndex, uiAbsPartIdx, uiPartIdx, uiDepth );
104}
105
106#if NH_3D
107Void TDecEntropy::decodeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
108{
109  if( !pcCU->getSlice()->getARPStepNum() || pcCU->isIntra( uiAbsPartIdx ) )
110  {
111    return;
112  }
113
114  if( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N )
115  {
116    pcCU->setARPWSubParts( 0 , uiAbsPartIdx, uiDepth );
117  }
118  else
119  {
120    m_pcEntropyDecoderIf->parseARPW( pcCU , uiAbsPartIdx , uiDepth );
121  }
122}
123
124Void TDecEntropy::decodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
125{
126  pcCU->setICFlagSubParts( false , uiAbsPartIdx, 0, uiDepth );
127
128  if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) || pcCU->getSlice()->getIsDepth() || pcCU->getARPW( uiAbsPartIdx ) > 0 )
129  {
130    return;
131  }
132
133  if( !pcCU->getSlice()->getApplyIC() )
134    return;
135
136  if( pcCU->isICFlagRequired( uiAbsPartIdx ) )
137    m_pcEntropyDecoderIf->parseICFlag( pcCU, uiAbsPartIdx, uiDepth );
138}
139#endif
140
141Void TDecEntropy::decodeSplitFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
142{
143  m_pcEntropyDecoderIf->parseSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
144}
145
146Void TDecEntropy::decodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
147{
148  m_pcEntropyDecoderIf->parsePredMode( pcCU, uiAbsPartIdx, uiDepth );
149}
150
151Void TDecEntropy::decodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
152{
153  m_pcEntropyDecoderIf->parsePartSize( pcCU, uiAbsPartIdx, uiDepth );
154}
155
156Void TDecEntropy::decodePredInfo    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
157{
158  if( pcCU->isIntra( uiAbsPartIdx ) )                                 // If it is Intra mode, encode intra prediction mode.
159  {
160    decodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx, uiDepth );
161#if NH_3D
162    decodeSDCFlag   ( pcCU, uiAbsPartIdx, uiDepth );
163#endif
164    if (pcCU->getPic()->getChromaFormat()!=CHROMA_400)
165    {
166      decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth );
167      if (enable4ChromaPUsInIntraNxNCU(pcCU->getPic()->getChromaFormat()) && pcCU->getPartitionSize( uiAbsPartIdx )==SIZE_NxN)
168      {
169        UInt uiPartOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2;
170        decodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset,   uiDepth+1 );
171        decodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset*2, uiDepth+1 );
172        decodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset*3, uiDepth+1 );
173      }
174    }
175  }
176  else                                                                // if it is Inter mode, encode motion vector and reference index
177  {
178    decodePUWise( pcCU, uiAbsPartIdx, uiDepth, pcSubCU );
179  }
180}
181
182/** Parse I_PCM information.
183 * \param pcCU  pointer to CUpointer to CU
184 * \param uiAbsPartIdx CU index
185 * \param uiDepth CU depth
186 * \returns Void
187 */
188Void TDecEntropy::decodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
189{
190  if(!pcCU->getSlice()->getSPS()->getUsePCM()
191    || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize())
192    || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()) )
193  {
194    return;
195  }
196
197  m_pcEntropyDecoderIf->parseIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
198}
199
200Void TDecEntropy::decodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
201{
202  m_pcEntropyDecoderIf->parseIntraDirLumaAng( pcCU, uiAbsPartIdx, uiDepth );
203}
204
205Void TDecEntropy::decodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
206{
207  m_pcEntropyDecoderIf->parseIntraDirChroma( pcCU, uiAbsPartIdx, uiDepth );
208#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
209  if (bDebugPredEnabled)
210  {
211    UInt cdir=pcCU->getIntraDir(CHANNEL_TYPE_CHROMA, uiAbsPartIdx);
212    if (cdir==36)
213    {
214      cdir=pcCU->getIntraDir(CHANNEL_TYPE_LUMA, uiAbsPartIdx);
215    }
216    printf("coding chroma Intra dir: %d, uiAbsPartIdx: %d, luma dir: %d\n", cdir, uiAbsPartIdx, pcCU->getIntraDir(CHANNEL_TYPE_LUMA, uiAbsPartIdx));
217  }
218#endif
219}
220
221
222/** decode motion information for every PU block.
223 * \param pcCU
224 * \param uiAbsPartIdx
225 * \param uiDepth
226 * \param pcSubCU
227 * \returns Void
228 */
229Void TDecEntropy::decodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
230{
231  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
232  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
233  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxTotalCUDepth() - uiDepth ) << 1 ) ) >> 4;
234
235#if NH_3D
236  TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
237  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
238#else
239  TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
240  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
241#endif
242#if NH_3D
243  Bool bSPIVMPFlag[MRG_MAX_NUM_CANDS_MEM];     
244  TComMvField*  pcMvFieldSP = new TComMvField[pcCU->getPic()->getPicSym()->getNumPartitionsInCtu()*2]; 
245  UChar* puhInterDirSP = new UChar[pcCU->getPic()->getPicSym()->getNumPartitionsInCtu()]; 
246  pcSubCU->copyDVInfoFrom( pcCU, uiAbsPartIdx);
247#endif
248  for ( UInt ui = 0; ui < pcCU->getSlice()->getMaxNumMergeCand(); ui++ )
249  {
250    uhInterDirNeighbours[ui] = 0;
251  }
252  Int numValidMergeCand = 0;
253  Bool hasMergedCandList = false;
254
255#if MCTS_ENC_CHECK
256  UInt numSpatialMergeCandidates = 0;
257#endif
258  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
259  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 );
260#if NH_3D
261  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
262  {
263#if NH_MV_ENC_DEC_TRAC
264    DTRACE_PU_S("=========== prediction_unit ===========\n")
265    // ToDo:
266    //DTRACE_PU("x0", uiLPelX)
267    //DTRACE_PU("x1", uiTPelY)
268#endif
269
270    ////// Parse PUs syntax
271    decodeMergeFlag( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
272    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
273    {
274      decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, uiDepth );     
275    }
276    else
277    {
278      decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
279      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
280      {       
281        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
282        {
283          decodeRefFrmIdxPU( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
284          decodeMvdPU      ( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
285          decodeMVPIdxPU   ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
286        }
287      }
288    }
289  }
290
291  ////// Parse CUs extension syntax
292  decodeDBBPFlag( pcCU, uiAbsPartIdx, uiDepth ); 
293  decodeSDCFlag ( pcCU, uiAbsPartIdx, uiDepth );
294  decodeARPW    ( pcCU, uiAbsPartIdx, uiDepth );
295  decodeICFlag  ( pcCU, uiAbsPartIdx, uiDepth );
296
297  ////// Decode motion vectors
298  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
299  {
300    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
301    {
302      UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
303#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
304      if (bDebugPredEnabled)
305      {
306        std::cout << "Coded merge flag, CU absPartIdx: " << uiAbsPartIdx << " PU(" << uiPartIdx << ") absPartIdx: " << uiSubPartIdx;
307        std::cout << " merge index: " << (UInt)pcCU->getMergeIndex(uiSubPartIdx) << std::endl;
308      }
309#endif
310
311      if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 && pcCU->getDBBPFlag(uiAbsPartIdx) == false )
312      {
313        if ( !hasMergedCandList )
314        {
315          pcSubCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); // temporarily set.
316          Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
317          memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
318          memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM);
319          pcSubCU->initAvailableFlags();
320#if MCTS_ENC_CHECK
321          numSpatialMergeCandidates = 0;
322          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, numSpatialMergeCandidates );
323#else
324          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
325#endif
326
327          pcSubCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, pcMvFieldSP, puhInterDirSP, numValidMergeCand );
328          pcSubCU->buildMCL( cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, bSPIVMPFlag, numValidMergeCand );
329          pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
330          pcSubCU->setPartSizeSubParts( ePartSize, 0, uiDepth ); // restore.
331          hasMergedCandList = true;
332        }
333      }
334      else
335      {
336        Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
337        memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
338        memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM);
339        pcSubCU->initAvailableFlags();
340#if MCTS_ENC_CHECK
341        numSpatialMergeCandidates = 0;
342        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, numSpatialMergeCandidates, uiMergeIndex );
343#else
344        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
345#endif
346        pcSubCU->xGetInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, pcMvFieldSP, puhInterDirSP ,numValidMergeCand, uiMergeIndex );
347        pcSubCU->buildMCL( cMvFieldNeighbours, uhInterDirNeighbours , vspFlag, bSPIVMPFlag ,numValidMergeCand );
348        pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
349      }
350      pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
351
352      TComMv cTmpMv( 0, 0 );
353      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
354      {
355        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
356        {
357          pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
358          pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
359          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
360          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
361          if( pcCU->getVSPFlag( uiSubPartIdx ) != 0 && !pcCU->getDBBPFlag( uiAbsPartIdx ) )
362          {
363            if ( uhInterDirNeighbours[ uiMergeIndex ] & (1<<uiRefListIdx) )
364            {
365              UInt dummy;
366              Int vspSize;
367              Int width, height;
368              pcCU->getPartIndexAndSize( uiPartIdx, dummy, width, height, uiSubPartIdx, pcCU->getTotalNumPart()==256 );
369              pcCU->setMvFieldPUForVSP( pcCU, uiSubPartIdx, width, height, RefPicList( uiRefListIdx ), cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getRefIdx(), vspSize );
370              pcCU->setVSPFlag( uiSubPartIdx, vspSize );
371            }
372          }
373        }
374      }
375      pcCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth ); 
376      if (bSPIVMPFlag[uiMergeIndex] != 0)
377      {
378        Int iWidth, iHeight;
379        UInt uiIdx;
380        pcCU->getPartIndexAndSize( uiPartIdx, uiIdx, iWidth, iHeight, uiSubPartIdx, true );
381
382        UInt uiSPAddr;
383
384        Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
385
386        pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
387
388        for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++)
389        {
390          pcCU->getSPAbsPartIdx(uiSubPartIdx, iSPWidth, iSPHeight, iPartitionIdx, iNumSPInOneLine, uiSPAddr);
391          pcCU->setInterDirSP(puhInterDirSP[iPartitionIdx], uiSPAddr, iSPWidth, iSPHeight);
392          pcCU->getCUMvField( REF_PIC_LIST_0 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx], iSPWidth, iSPHeight);
393          pcCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight);
394        }
395      }
396    }
397    else
398    {
399      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
400      {       
401        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
402        {
403          decodeMvsAMVP   ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
404#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
405          if (bDebugPredEnabled)
406          {
407            std::cout << "refListIdx: " << uiRefListIdx << std::endl;
408            std::cout << "MVD horizontal: " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getHor() << std::endl;
409            std::cout << "MVD vertical:   " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getVer() << std::endl;
410            std::cout << "MVPIdxPU: " << pcCU->getMVPIdx(RefPicList( uiRefListIdx ), uiSubPartIdx) << std::endl;
411            std::cout << "InterDir: " << (UInt)pcCU->getInterDir(uiSubPartIdx) << std::endl;
412          }
413#endif
414        }
415      }
416    }
417
418    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) )
419    {
420      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( TComMv(0,0), ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
421      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( -1, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
422      pcCU->setInterDirSubParts( 1, uiSubPartIdx, uiPartIdx, uiDepth);
423    }
424  }
425
426  delete[] pcMvFieldSP;
427  delete[] puhInterDirSP;
428
429#else
430  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
431  {
432#if NH_MV_ENC_DEC_TRAC
433    DTRACE_PU_S("=========== prediction_unit ===========\n")
434    // ToDo:
435    //DTRACE_PU("x0", uiLPelX)
436    //DTRACE_PU("x1", uiTPelY)
437#endif
438    decodeMergeFlag( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
439    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
440    {
441      decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, uiDepth );
442#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
443      if (bDebugPredEnabled)
444      {
445        std::cout << "Coded merge flag, CU absPartIdx: " << uiAbsPartIdx << " PU(" << uiPartIdx << ") absPartIdx: " << uiSubPartIdx;
446        std::cout << " merge index: " << (UInt)pcCU->getMergeIndex(uiSubPartIdx) << std::endl;
447      }
448#endif
449      const UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
450      if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 )
451      {
452        if ( !hasMergedCandList )
453        {
454          pcSubCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); // temporarily set.
455
456#if MCTS_ENC_CHECK
457          numSpatialMergeCandidates = 0;
458          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, numSpatialMergeCandidates );
459#else
460          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
461#endif
462          pcSubCU->setPartSizeSubParts( ePartSize, 0, uiDepth ); // restore.
463          hasMergedCandList = true;
464        }
465      }
466      else
467      {
468#if MCTS_ENC_CHECK
469        numSpatialMergeCandidates = 0;
470        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, numSpatialMergeCandidates, uiMergeIndex );
471#else
472
473        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
474#endif
475      }
476#if MCTS_ENC_CHECK
477      if (m_pConformanceCheck->getTMctsCheck() &&  pcSubCU->isLastColumnCTUInTile() && (uiMergeIndex >= numSpatialMergeCandidates) )
478      {
479        m_pConformanceCheck->flagTMctsError("Merge Index using non-spatial merge candidate (Merge)");
480      }
481
482#endif
483      pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
484
485      TComMv cTmpMv( 0, 0 );
486      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
487      {
488        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
489        {
490          pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
491          pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
492          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
493          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
494        }
495      }
496    }
497    else
498    {
499      decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
500      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
501      {
502        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
503        {
504          decodeRefFrmIdxPU( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
505          decodeMvdPU      ( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
506          decodeMVPIdxPU   ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
507#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
508          if (bDebugPredEnabled)
509          {
510            std::cout << "refListIdx: " << uiRefListIdx << std::endl;
511            std::cout << "MVD horizontal: " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getHor() << std::endl;
512            std::cout << "MVD vertical:   " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getVer() << std::endl;
513            std::cout << "MVPIdxPU: " << pcCU->getMVPIdx(RefPicList( uiRefListIdx ), uiSubPartIdx) << std::endl;
514            std::cout << "InterDir: " << (UInt)pcCU->getInterDir(uiSubPartIdx) << std::endl;
515          }
516#endif
517        }
518      } 
519    }
520
521    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) )
522    {
523      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( TComMv(0,0), ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
524      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( -1, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
525      pcCU->setInterDirSubParts( 1, uiSubPartIdx, uiPartIdx, uiDepth);
526    }
527  }
528#endif
529  return;
530}
531
532/** decode inter direction for a PU block
533 * \param pcCU
534 * \param uiAbsPartIdx
535 * \param uiDepth
536 * \param uiPartIdx
537 * \returns Void
538 */
539Void TDecEntropy::decodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx )
540{
541  UInt uiInterDir;
542
543  if ( pcCU->getSlice()->isInterP() )
544  {
545    uiInterDir = 1;
546  }
547  else
548  {
549    m_pcEntropyDecoderIf->parseInterDir( pcCU, uiInterDir, uiAbsPartIdx );
550  }
551
552  pcCU->setInterDirSubParts( uiInterDir, uiAbsPartIdx, uiPartIdx, uiDepth );
553}
554
555Void TDecEntropy::decodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
556{
557  Int iRefFrmIdx = 0;
558  Int iParseRefFrmIdx = pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList );
559
560  if ( pcCU->getSlice()->getNumRefIdx( eRefList ) > 1 && iParseRefFrmIdx )
561  {
562    m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, eRefList );
563  }
564  else if ( !iParseRefFrmIdx )
565  {
566    iRefFrmIdx = NOT_VALID;
567  }
568  else
569  {
570    iRefFrmIdx = 0;
571  }
572
573  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
574  pcCU->getCUMvField( eRefList )->setAllRefIdx( iRefFrmIdx, ePartSize, uiAbsPartIdx, uiDepth, uiPartIdx );
575}
576
577/** decode motion vector difference for a PU block
578 * \param pcCU
579 * \param uiAbsPartIdx
580 * \param uiDepth
581 * \param uiPartIdx
582 * \param eRefList
583 * \returns Void
584 */
585Void TDecEntropy::decodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
586{
587  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
588  {
589    m_pcEntropyDecoderIf->parseMvd( pcCU, uiAbsPartIdx, uiPartIdx, uiDepth, eRefList );
590  }
591}
592
593#if NH_3D
594Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
595{
596  Int iMVPIdx = -1;
597
598  if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) )
599  {
600    m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx );
601#if NH_MV_ENC_DEC_TRAC
602#if ENC_DEC_TRACE
603    if ( eRefList == REF_PIC_LIST_0 )
604    {
605      DTRACE_PU("mvp_l0_flag", iMVPIdx)
606    }
607    else
608    {
609      DTRACE_PU("mvp_l1_flag", iMVPIdx)
610    }
611#endif
612#endif
613  }
614  pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth );
615}
616
617Void TDecEntropy::decodeMvsAMVP( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
618{
619  TComMv cZeroMv( 0, 0 );
620  TComMv cMv     = cZeroMv;
621  Int    iRefIdx = -1;
622
623  TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList );
624  AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo();
625
626  iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr);
627  cMv = cZeroMv;
628
629  pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo);
630  pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth);
631  if ( iRefIdx >= 0 )
632  {
633    m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, cMv);
634    cMv += pcSubCUMvField->getMvd( uiPartAddr );
635  }
636
637  PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr );
638  pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx);
639}
640#else
641Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
642{
643  Int iMVPIdx = -1;
644
645  TComMv cZeroMv( 0, 0 );
646  TComMv cMv     = cZeroMv;
647  Int    iRefIdx = -1;
648
649  TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList );
650  AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo();
651
652  iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr);
653  cMv = cZeroMv;
654
655  if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) )
656  {
657    m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx );
658#if NH_MV_ENC_DEC_TRAC
659#if ENC_DEC_TRACE
660    if ( eRefList == REF_PIC_LIST_0 )
661    {
662      DTRACE_PU("mvp_l0_flag", iMVPIdx)
663    }
664    else
665    {
666      DTRACE_PU("mvp_l1_flag", iMVPIdx)
667    }
668#endif
669#endif
670  }
671  pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo);
672#if MCTS_ENC_CHECK
673  if ((iRefIdx >= 0) && m_pConformanceCheck->getTMctsCheck() && pcSubCU->isLastColumnCTUInTile() && (iMVPIdx == pAMVPInfo->numSpatialMVPCandidates))
674  {
675    m_pConformanceCheck->flagTMctsError("Merge Index using non-spatial merge candidate (AMVP)");
676  }
677#endif
678
679  pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth);
680  pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth );
681  if ( iRefIdx >= 0 )
682  {
683    m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, cMv);
684    cMv += pcSubCUMvField->getMvd( uiPartAddr );
685  }
686
687  PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr );
688  pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx);
689}
690#endif
691
692Void TDecEntropy::xDecodeTransform        ( Bool& bCodeDQP, Bool& isChromaQpAdjCoded, TComTU &rTu, const Int quadtreeTULog2MinSizeInCU )
693{
694
695  TComDataCU *pcCU=rTu.getCU();
696  const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU();
697  const UInt uiDepth=rTu.GetTransformDepthTotal();
698  const UInt uiTrDepth = rTu.GetTransformDepthRel();
699
700#if NH_MV_ENC_DEC_TRAC
701#if ENC_DEC_TRACE
702  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
703  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
704
705  DTRACE_TU_S("=========== transform_tree ===========\n")
706  DTRACE_TU("x0", uiLPelX)
707  DTRACE_TU("x1", uiTPelY)
708 
709  DTRACE_TU("log2TrafoSize", pcCU->getSlice()->getSPS()->getMaxCUWidth()  >> uiDepth )
710  DTRACE_TU("trafoDepth"  , uiDepth)
711#endif
712#endif
713
714  UInt uiSubdiv;
715  const UInt numValidComponent = pcCU->getPic()->getNumberValidComponents();
716  const Bool bChroma = isChromaEnabled(pcCU->getPic()->getChromaFormat());
717
718  const UInt uiLog2TrafoSize = rTu.GetLog2LumaTrSize();
719#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
720  if (bDebugRQT)
721  {
722    printf("x..codeTransform: offsetLuma=%d offsetChroma=%d absPartIdx=%d, uiDepth=%d\n width=%d, height=%d, uiTrIdx=%d, uiInnerQuadIdx=%d\n",
723        rTu.getCoefficientOffset(COMPONENT_Y), rTu.getCoefficientOffset(COMPONENT_Cb), uiAbsPartIdx, uiDepth, rTu.getRect(COMPONENT_Y).width, rTu.getRect(COMPONENT_Y).height, rTu.GetTransformDepthRel(), rTu.GetSectionNumber());
724    fflush(stdout);
725  }
726#endif
727
728  if( pcCU->isIntra(uiAbsPartIdx) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
729  {
730    uiSubdiv = 1;
731  }
732  else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->isInter(uiAbsPartIdx)) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) )
733  {
734    uiSubdiv = (uiLog2TrafoSize >quadtreeTULog2MinSizeInCU);
735  }
736  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
737  {
738    uiSubdiv = 1;
739  }
740  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
741  {
742    uiSubdiv = 0;
743  }
744  else if( uiLog2TrafoSize == quadtreeTULog2MinSizeInCU )
745  {
746    uiSubdiv = 0;
747  }
748  else
749  {
750    assert( uiLog2TrafoSize > quadtreeTULog2MinSizeInCU );
751    m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
752  }
753
754  for(Int chan=COMPONENT_Cb; chan<numValidComponent; chan++)
755  {
756    const ComponentID compID=ComponentID(chan);
757    const UInt trDepthTotalAdj=rTu.GetTransformDepthTotalAdj(compID);
758
759    const Bool bFirstCbfOfCU = uiTrDepth == 0;
760
761    if( bFirstCbfOfCU )
762    {
763      pcCU->setCbfSubParts( 0, compID, rTu.GetAbsPartIdxTU(compID), trDepthTotalAdj);
764    }
765    if( bFirstCbfOfCU || rTu.ProcessingAllQuadrants(compID) )
766    {
767      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, compID, uiTrDepth - 1 ) )
768      {
769        m_pcEntropyDecoderIf->parseQtCbf( rTu, compID, (uiSubdiv == 0) );
770      }
771    }
772  }
773
774  if( uiSubdiv )
775  {
776    const UInt uiQPartNum = pcCU->getPic()->getNumPartitionsInCtu() >> ((uiDepth+1) << 1);
777    UInt uiYUVCbf[MAX_NUM_COMPONENT] = {0,0,0};
778
779    TComTURecurse tuRecurseChild(rTu, true);
780
781    do
782    {
783      xDecodeTransform( bCodeDQP, isChromaQpAdjCoded, tuRecurseChild, quadtreeTULog2MinSizeInCU );
784      UInt childTUAbsPartIdx=tuRecurseChild.GetAbsPartIdxTU();
785      for(UInt ch=0; ch<numValidComponent; ch++)
786      {
787        uiYUVCbf[ch] |= pcCU->getCbf(childTUAbsPartIdx , ComponentID(ch),  uiTrDepth+1 );
788      }
789    } while (tuRecurseChild.nextSection(rTu) );
790
791    for(UInt ch=0; ch<numValidComponent; ch++)
792    {
793      UChar *pBase = pcCU->getCbf( ComponentID(ch) ) + uiAbsPartIdx;
794      const UChar flag = uiYUVCbf[ch] << uiTrDepth;
795
796      for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui )
797      {
798        pBase[ui] |= flag;
799      }
800    }
801  }
802  else
803  {
804    assert( uiDepth >= pcCU->getDepth( uiAbsPartIdx ) );
805    pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiDepth );
806
807#if !NH_MV_ENC_DEC_TRAC
808    {
809      DTRACE_CABAC_VL( g_nSymbolCounter++ );
810      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
811      DTRACE_CABAC_V( uiAbsPartIdx );
812      DTRACE_CABAC_T( "\tdepth=" );
813      DTRACE_CABAC_V( uiDepth );
814      DTRACE_CABAC_T( "\ttrdepth=" );
815      DTRACE_CABAC_V( uiTrDepth );
816      DTRACE_CABAC_T( "\n" );
817    }
818#endif
819
820    pcCU->setCbfSubParts ( 0, COMPONENT_Y, uiAbsPartIdx, uiDepth );
821
822    if( (!pcCU->isIntra(uiAbsPartIdx)) && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && ((!bChroma) || (!pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cb, 0 ) && !pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cr, 0 )) ))
823    {
824      pcCU->setCbfSubParts( 1 << uiTrDepth, COMPONENT_Y, uiAbsPartIdx, uiDepth );
825    }
826    else
827    {
828      m_pcEntropyDecoderIf->parseQtCbf( rTu, COMPONENT_Y, true );
829    }
830
831
832    // transform_unit begin
833    UInt cbf[MAX_NUM_COMPONENT]={0,0,0};
834    Bool validCbf       = false;
835    Bool validChromaCbf = false;
836    const UInt uiTrIdx = rTu.GetTransformDepthRel();
837
838    for(UInt ch=0; ch<pcCU->getPic()->getNumberValidComponents(); ch++)
839    {
840      const ComponentID compID = ComponentID(ch);
841
842      cbf[compID] = pcCU->getCbf( uiAbsPartIdx, compID, uiTrIdx );
843
844      if (cbf[compID] != 0)
845      {
846        validCbf = true;
847        if (isChroma(compID))
848        {
849          validChromaCbf = true;
850        }
851      }
852    }
853
854    if ( validCbf )
855    {
856
857      // dQP: only for CTU
858      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
859      {
860        if ( bCodeDQP )
861        {
862          const UInt uiAbsPartIdxCU=rTu.GetAbsPartIdxCU();
863          decodeQP( pcCU, uiAbsPartIdxCU);
864          bCodeDQP = false;
865        }
866      }
867
868      if ( pcCU->getSlice()->getUseChromaQpAdj() )
869      {
870        if ( validChromaCbf && isChromaQpAdjCoded && !pcCU->getCUTransquantBypass(rTu.GetAbsPartIdxCU()) )
871        {
872          decodeChromaQpAdjustment( pcCU, rTu.GetAbsPartIdxCU() );
873          isChromaQpAdjCoded = false;
874        }
875      }
876
877      const UInt numValidComp=pcCU->getPic()->getNumberValidComponents();
878
879      for(UInt ch=COMPONENT_Y; ch<numValidComp; ch++)
880      {
881        const ComponentID compID=ComponentID(ch);
882
883        if( rTu.ProcessComponentSection(compID) )
884        {
885#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
886          if (bDebugRQT)
887          {
888            printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, rTu.getRect(compID).width, rTu.getRect(compID).height, 1);
889          }
890#endif
891
892          if (rTu.getRect(compID).width != rTu.getRect(compID).height)
893          {
894            //code two sub-TUs
895            TComTURecurse subTUIterator(rTu, false, TComTU::VERTICAL_SPLIT, true, compID);
896
897            do
898            {
899              const UInt subTUCBF = pcCU->getCbf(subTUIterator.GetAbsPartIdxTU(), compID, (uiTrIdx + 1));
900
901              if (subTUCBF != 0)
902              {
903#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
904                if (bDebugRQT)
905                {
906                  printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, subTUIterator.getRect(compID).width, subTUIterator.getRect(compID).height, 1);
907                }
908#endif
909                m_pcEntropyDecoderIf->parseCoeffNxN( subTUIterator, compID );
910              }
911            } while (subTUIterator.nextSection(rTu));
912          }
913          else
914          {
915            if(isChroma(compID) && (cbf[COMPONENT_Y] != 0))
916            {
917              m_pcEntropyDecoderIf->parseCrossComponentPrediction( rTu, compID );
918            }
919
920            if(cbf[compID] != 0)
921            {
922              m_pcEntropyDecoderIf->parseCoeffNxN( rTu, compID );
923            }
924          }
925        }
926      }
927    }
928    // transform_unit end
929  }
930}
931
932Void TDecEntropy::decodeQP          ( TComDataCU* pcCU, UInt uiAbsPartIdx )
933{
934  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
935  {
936    m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
937  }
938}
939
940Void TDecEntropy::decodeChromaQpAdjustment( TComDataCU* pcCU, UInt uiAbsPartIdx )
941{
942  if ( pcCU->getSlice()->getUseChromaQpAdj() )
943  {
944    m_pcEntropyDecoderIf->parseChromaQpAdjustment( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
945  }
946}
947
948
949//! decode coefficients
950Void TDecEntropy::decodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool& bCodeDQP, Bool& isChromaQpAdjCoded )
951{
952#if NH_3D
953  if( pcCU->getSDCFlag( uiAbsPartIdx ) && pcCU->isIntra( uiAbsPartIdx) )
954  {
955    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
956    assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 );
957    assert( pcCU->getCbf(uiAbsPartIdx, COMPONENT_Y) == 1 );
958}
959  if( pcCU->getSDCFlag( uiAbsPartIdx ) && !pcCU->isIntra( uiAbsPartIdx) )
960  {
961    assert( !pcCU->isSkipped( uiAbsPartIdx ) );
962    assert( !pcCU->isIntra( uiAbsPartIdx) );
963    assert( pcCU->getSlice()->getIsDepth() );
964  }
965  if( pcCU->getSlice()->getIsDepth() )
966  {
967    if( pcCU->getSDCFlag( uiAbsPartIdx ) )
968    {
969      m_pcEntropyDecoderIf->parseDeltaDC( pcCU, uiAbsPartIdx, uiDepth );
970      return;
971    }
972    if( pcCU->isIntra( uiAbsPartIdx ) )
973    {
974      Int iPartNum = ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) ? 4 : 1;
975      UInt uiPartOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth( uiAbsPartIdx ) << 1 ) ) >> 2;
976      for( Int iPart = 0; iPart < iPartNum; iPart++ )
977      {
978        if( isDmmMode( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, uiAbsPartIdx + uiPartOffset*iPart ) ) )
979        {
980          m_pcEntropyDecoderIf->parseDeltaDC( pcCU, uiAbsPartIdx + uiPartOffset*iPart, uiDepth + ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) );
981        }
982      }
983    }
984  }
985#endif
986
987  if( pcCU->isIntra(uiAbsPartIdx) )
988  {
989  }
990  else
991  {
992    UInt uiQtRootCbf = 1;
993    if( !( pcCU->getPartitionSize( uiAbsPartIdx) == SIZE_2Nx2N && pcCU->getMergeFlag( uiAbsPartIdx ) ) )
994    {
995      m_pcEntropyDecoderIf->parseQtRootCbf( uiAbsPartIdx, uiQtRootCbf );
996    }
997    if ( !uiQtRootCbf )
998    {
999      static const UInt cbfZero[MAX_NUM_COMPONENT]={0,0,0};
1000      pcCU->setCbfSubParts( cbfZero, uiAbsPartIdx, uiDepth );
1001      pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth );
1002      return;
1003    }
1004
1005  }
1006
1007  TComTURecurse tuRecurse(pcCU, uiAbsPartIdx, uiDepth);
1008
1009#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
1010  if (bDebugRQT)
1011  {
1012    printf("..codeCoeff: uiAbsPartIdx=%d, PU format=%d, 2Nx2N=%d, NxN=%d\n", uiAbsPartIdx, pcCU->getPartitionSize(uiAbsPartIdx), SIZE_2Nx2N, SIZE_NxN);
1013  }
1014#endif
1015
1016  Int quadtreeTULog2MinSizeInCU = pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx);
1017 
1018  xDecodeTransform( bCodeDQP, isChromaQpAdjCoded, tuRecurse, quadtreeTULog2MinSizeInCU );
1019}
1020
1021#if NH_3D
1022Void TDecEntropy::decodeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1023{
1024  pcCU->setSDCFlagSubParts( false, uiAbsPartIdx, uiDepth );
1025  if ( pcCU->isSkipped( uiAbsPartIdx ) )
1026  {
1027    return; 
1028  }
1029
1030
1031  if( ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getInterSdcFlag() ) || 
1032    ( pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getIntraSdcWedgeFlag() ) )
1033  {
1034    return;
1035  }
1036
1037  if( !pcCU->getSlice()->getIsDepth() || pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_2Nx2N || pcCU->isSkipped( uiAbsPartIdx ) )
1038  {
1039    return;
1040  }
1041
1042  assert( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N || ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->isSkipped( uiAbsPartIdx ) ) );
1043  m_pcEntropyDecoderIf->parseSDCFlag( pcCU, uiAbsPartIdx, uiDepth );
1044}
1045
1046Void TDecEntropy::decodeDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1047{
1048  if( pcCU->getSlice()->getDepthBasedBlkPartFlag() && (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2NxN || pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_Nx2N) && pcCU->getWidth(uiAbsPartIdx) > 8 && pcCU->getSlice()->getDefaultRefViewIdxAvailableFlag() )
1049  {
1050    m_pcEntropyDecoderIf->parseDBBPFlag( pcCU, uiAbsPartIdx, uiDepth );
1051  }
1052}
1053#endif
1054
1055
1056
1057//! \}
Note: See TracBrowser for help on using the repository browser.