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

Last change on this file since 1255 was 1255, checked in by ntt, 9 years ago

Reactivation of VSP

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