source: 3DVCSoftware/branches/HTM-14.1-update-dev1-MediaTek/source/Lib/TLibDecoder/TDecEntropy.cpp @ 1258

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

The reactivation of depth intra skip mode (DIS), the MACRO is "NH_3D_DIS".

by Yi-Wen Chen (yiwen.chen@…)

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