source: 3DVCSoftware/branches/HTM-14.1-update-dev3-ETRI/source/Lib/TLibDecoder/TDecEntropy.cpp @ 1233

Last change on this file since 1233 was 1233, checked in by etri-htm, 9 years ago

Reactive_MLC (the MACRO is "NH_3D_MLC")

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