source: 3DVCSoftware/branches/HTM-14.1-update-dev3-MediaTek-Qualcomm/source/Lib/TLibDecoder/TDecEntropy.cpp @ 1259

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

Reactive IVMV by Mediatek

  • Property svn:eol-style set to native
File size: 40.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 NH_3D_SPIVMP
247  Bool bSPIVMPFlag[MRG_MAX_NUM_CANDS_MEM];     
248  TComMvField*  pcMvFieldSP = new TComMvField[pcCU->getPic()->getPicSym()->getNumPartitionsInCtu()*2]; 
249  UChar* puhInterDirSP = new UChar[pcCU->getPic()->getPicSym()->getNumPartitionsInCtu()]; 
250#endif
251#if NH_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 NH_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 NH_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 NH_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 NH_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 NH_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 NH_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#if NH_3D_SPIVMP
582      pcCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth ); 
583      if (bSPIVMPFlag[uiMergeIndex] != 0)
584      {
585        Int iWidth, iHeight;
586        UInt uiIdx;
587        pcCU->getPartIndexAndSize( uiPartIdx, uiIdx, iWidth, iHeight, uiSubPartIdx, true );
588
589        UInt uiSPAddr;
590
591        Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
592
593        pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
594
595        for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++)
596        {
597          pcCU->getSPAbsPartIdx(uiSubPartIdx, iSPWidth, iSPHeight, iPartitionIdx, iNumSPInOneLine, uiSPAddr);
598          pcCU->setInterDirSP(puhInterDirSP[iPartitionIdx], uiSPAddr, iSPWidth, iSPHeight);
599          pcCU->getCUMvField( REF_PIC_LIST_0 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx], iSPWidth, iSPHeight);
600          pcCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight);
601        }
602      }
603#endif
604    }
605    else
606    {
607      decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
608      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
609      {
610        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
611        {
612          decodeRefFrmIdxPU( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
613          decodeMvdPU      ( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
614          decodeMVPIdxPU   ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
615#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
616          if (bDebugPredEnabled)
617          {
618            std::cout << "refListIdx: " << uiRefListIdx << std::endl;
619            std::cout << "MVD horizontal: " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getHor() << std::endl;
620            std::cout << "MVD vertical:   " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getVer() << std::endl;
621            std::cout << "MVPIdxPU: " << pcCU->getMVPIdx(RefPicList( uiRefListIdx ), uiSubPartIdx) << std::endl;
622            std::cout << "InterDir: " << (UInt)pcCU->getInterDir(uiSubPartIdx) << std::endl;
623          }
624#endif
625        }
626      }
627    }
628
629    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) )
630    {
631      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( TComMv(0,0), ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
632      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( -1, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
633      pcCU->setInterDirSubParts( 1, uiSubPartIdx, uiPartIdx, uiDepth);
634    }
635  }
636#endif
637#if NH_3D_SPIVMP
638  delete[] pcMvFieldSP;
639  delete[] puhInterDirSP;
640#endif
641  return;
642}
643
644/** decode inter direction for a PU block
645 * \param pcCU
646 * \param uiAbsPartIdx
647 * \param uiDepth
648 * \param uiPartIdx
649 * \returns Void
650 */
651Void TDecEntropy::decodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx )
652{
653  UInt uiInterDir;
654
655  if ( pcCU->getSlice()->isInterP() )
656  {
657    uiInterDir = 1;
658  }
659  else
660  {
661    m_pcEntropyDecoderIf->parseInterDir( pcCU, uiInterDir, uiAbsPartIdx );
662  }
663
664  pcCU->setInterDirSubParts( uiInterDir, uiAbsPartIdx, uiPartIdx, uiDepth );
665}
666
667Void TDecEntropy::decodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
668{
669  Int iRefFrmIdx = 0;
670  Int iParseRefFrmIdx = pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList );
671
672  if ( pcCU->getSlice()->getNumRefIdx( eRefList ) > 1 && iParseRefFrmIdx )
673  {
674    m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, eRefList );
675  }
676  else if ( !iParseRefFrmIdx )
677  {
678    iRefFrmIdx = NOT_VALID;
679  }
680  else
681  {
682    iRefFrmIdx = 0;
683  }
684
685  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
686  pcCU->getCUMvField( eRefList )->setAllRefIdx( iRefFrmIdx, ePartSize, uiAbsPartIdx, uiDepth, uiPartIdx );
687}
688
689/** decode motion vector difference for a PU block
690 * \param pcCU
691 * \param uiAbsPartIdx
692 * \param uiDepth
693 * \param uiPartIdx
694 * \param eRefList
695 * \returns Void
696 */
697Void TDecEntropy::decodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
698{
699  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
700  {
701    m_pcEntropyDecoderIf->parseMvd( pcCU, uiAbsPartIdx, uiPartIdx, uiDepth, eRefList );
702  }
703}
704
705#if H_3D
706Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
707{
708  Int iMVPIdx = -1;
709
710  if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) )
711  {
712    m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx );
713#if H_MV_ENC_DEC_TRAC
714#if ENC_DEC_TRACE
715    if ( eRefList == REF_PIC_LIST_0 )
716    {
717      DTRACE_PU("mvp_l0_flag", iMVPIdx)
718    }
719    else
720    {
721      DTRACE_PU("mvp_l1_flag", iMVPIdx)
722    }
723#endif
724#endif
725  }
726  pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth );
727}
728
729Void TDecEntropy::decodeMvsAMVP( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
730{
731  TComMv cZeroMv( 0, 0 );
732  TComMv cMv     = cZeroMv;
733  Int    iRefIdx = -1;
734
735  TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList );
736  AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo();
737
738  iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr);
739  cMv = cZeroMv;
740
741  pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo);
742  pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth);
743  if ( iRefIdx >= 0 )
744  {
745    m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, cMv);
746    cMv += pcSubCUMvField->getMvd( uiPartAddr );
747  }
748
749  PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr );
750  pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx);
751}
752#else
753Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
754{
755  Int iMVPIdx = -1;
756
757  TComMv cZeroMv( 0, 0 );
758  TComMv cMv     = cZeroMv;
759  Int    iRefIdx = -1;
760
761  TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList );
762  AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo();
763
764  iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr);
765  cMv = cZeroMv;
766
767  if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) )
768  {
769    m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx );
770#if H_MV_ENC_DEC_TRAC
771#if ENC_DEC_TRACE
772    if ( eRefList == REF_PIC_LIST_0 )
773    {
774      DTRACE_PU("mvp_l0_flag", iMVPIdx)
775    }
776    else
777    {
778      DTRACE_PU("mvp_l1_flag", iMVPIdx)
779    }
780#endif
781#endif
782  }
783  pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo);
784  pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth);
785  pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth );
786  if ( iRefIdx >= 0 )
787  {
788    m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, cMv);
789    cMv += pcSubCUMvField->getMvd( uiPartAddr );
790  }
791
792  PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr );
793  pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx);
794}
795#endif
796
797Void TDecEntropy::xDecodeTransform        ( Bool& bCodeDQP, Bool& isChromaQpAdjCoded, TComTU &rTu, const Int quadtreeTULog2MinSizeInCU )
798{
799
800  TComDataCU *pcCU=rTu.getCU();
801  const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU();
802  const UInt uiDepth=rTu.GetTransformDepthTotal();
803  const UInt uiTrDepth = rTu.GetTransformDepthRel();
804
805#if H_MV_ENC_DEC_TRAC
806#if ENC_DEC_TRACE
807  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
808  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
809
810  DTRACE_TU_S("=========== transform_tree ===========\n")
811  DTRACE_TU("x0", uiLPelX)
812  DTRACE_TU("x1", uiTPelY)
813 
814  DTRACE_TU("log2TrafoSize", pcCU->getSlice()->getSPS()->getMaxCUWidth()  >> uiDepth )
815  DTRACE_TU("trafoDepth"  , uiDepth)
816#endif
817#endif
818
819  UInt uiSubdiv;
820  const UInt numValidComponent = pcCU->getPic()->getNumberValidComponents();
821  const Bool bChroma = isChromaEnabled(pcCU->getPic()->getChromaFormat());
822
823  const UInt uiLog2TrafoSize = rTu.GetLog2LumaTrSize();
824#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
825  if (bDebugRQT)
826  {
827    printf("x..codeTransform: offsetLuma=%d offsetChroma=%d absPartIdx=%d, uiDepth=%d\n width=%d, height=%d, uiTrIdx=%d, uiInnerQuadIdx=%d\n",
828        rTu.getCoefficientOffset(COMPONENT_Y), rTu.getCoefficientOffset(COMPONENT_Cb), uiAbsPartIdx, uiDepth, rTu.getRect(COMPONENT_Y).width, rTu.getRect(COMPONENT_Y).height, rTu.GetTransformDepthRel(), rTu.GetSectionNumber());
829    fflush(stdout);
830  }
831#endif
832
833  if( pcCU->isIntra(uiAbsPartIdx) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
834  {
835    uiSubdiv = 1;
836  }
837  else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->isInter(uiAbsPartIdx)) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) )
838  {
839    uiSubdiv = (uiLog2TrafoSize >quadtreeTULog2MinSizeInCU);
840  }
841  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
842  {
843    uiSubdiv = 1;
844  }
845  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
846  {
847    uiSubdiv = 0;
848  }
849  else if( uiLog2TrafoSize == quadtreeTULog2MinSizeInCU )
850  {
851    uiSubdiv = 0;
852  }
853  else
854  {
855    assert( uiLog2TrafoSize > quadtreeTULog2MinSizeInCU );
856    m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
857  }
858
859  for(Int chan=COMPONENT_Cb; chan<numValidComponent; chan++)
860  {
861    const ComponentID compID=ComponentID(chan);
862    const UInt trDepthTotalAdj=rTu.GetTransformDepthTotalAdj(compID);
863
864    const Bool bFirstCbfOfCU = uiTrDepth == 0;
865
866    if( bFirstCbfOfCU )
867    {
868      pcCU->setCbfSubParts( 0, compID, rTu.GetAbsPartIdxTU(compID), trDepthTotalAdj);
869    }
870    if( bFirstCbfOfCU || rTu.ProcessingAllQuadrants(compID) )
871    {
872      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, compID, uiTrDepth - 1 ) )
873      {
874        m_pcEntropyDecoderIf->parseQtCbf( rTu, compID, (uiSubdiv == 0) );
875      }
876    }
877  }
878
879  if( uiSubdiv )
880  {
881    const UInt uiQPartNum = pcCU->getPic()->getNumPartitionsInCtu() >> ((uiDepth+1) << 1);
882    UInt uiYUVCbf[MAX_NUM_COMPONENT] = {0,0,0};
883
884    TComTURecurse tuRecurseChild(rTu, true);
885
886    do
887    {
888      xDecodeTransform( bCodeDQP, isChromaQpAdjCoded, tuRecurseChild, quadtreeTULog2MinSizeInCU );
889      UInt childTUAbsPartIdx=tuRecurseChild.GetAbsPartIdxTU();
890      for(UInt ch=0; ch<numValidComponent; ch++)
891      {
892        uiYUVCbf[ch] |= pcCU->getCbf(childTUAbsPartIdx , ComponentID(ch),  uiTrDepth+1 );
893      }
894    } while (tuRecurseChild.nextSection(rTu) );
895
896    for(UInt ch=0; ch<numValidComponent; ch++)
897    {
898      UChar *pBase = pcCU->getCbf( ComponentID(ch) ) + uiAbsPartIdx;
899      const UChar flag = uiYUVCbf[ch] << uiTrDepth;
900
901      for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui )
902      {
903        pBase[ui] |= flag;
904      }
905    }
906  }
907  else
908  {
909    assert( uiDepth >= pcCU->getDepth( uiAbsPartIdx ) );
910    pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiDepth );
911
912#if !H_MV_ENC_DEC_TRAC
913    {
914      DTRACE_CABAC_VL( g_nSymbolCounter++ );
915      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
916      DTRACE_CABAC_V( uiAbsPartIdx );
917      DTRACE_CABAC_T( "\tdepth=" );
918      DTRACE_CABAC_V( uiDepth );
919      DTRACE_CABAC_T( "\ttrdepth=" );
920      DTRACE_CABAC_V( uiTrDepth );
921      DTRACE_CABAC_T( "\n" );
922    }
923#endif
924
925    pcCU->setCbfSubParts ( 0, COMPONENT_Y, uiAbsPartIdx, uiDepth );
926
927    if( (!pcCU->isIntra(uiAbsPartIdx)) && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && ((!bChroma) || (!pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cb, 0 ) && !pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cr, 0 )) ))
928    {
929      pcCU->setCbfSubParts( 1 << uiTrDepth, COMPONENT_Y, uiAbsPartIdx, uiDepth );
930    }
931    else
932    {
933      m_pcEntropyDecoderIf->parseQtCbf( rTu, COMPONENT_Y, true );
934    }
935
936
937    // transform_unit begin
938    UInt cbf[MAX_NUM_COMPONENT]={0,0,0};
939    Bool validCbf       = false;
940    Bool validChromaCbf = false;
941    const UInt uiTrIdx = rTu.GetTransformDepthRel();
942
943    for(UInt ch=0; ch<pcCU->getPic()->getNumberValidComponents(); ch++)
944    {
945      const ComponentID compID = ComponentID(ch);
946
947      cbf[compID] = pcCU->getCbf( uiAbsPartIdx, compID, uiTrIdx );
948
949      if (cbf[compID] != 0)
950      {
951        validCbf = true;
952        if (isChroma(compID))
953        {
954          validChromaCbf = true;
955        }
956      }
957    }
958
959    if ( validCbf )
960    {
961
962      // dQP: only for CTU
963      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
964      {
965        if ( bCodeDQP )
966        {
967          const UInt uiAbsPartIdxCU=rTu.GetAbsPartIdxCU();
968          decodeQP( pcCU, uiAbsPartIdxCU);
969          bCodeDQP = false;
970        }
971      }
972
973      if ( pcCU->getSlice()->getUseChromaQpAdj() )
974      {
975        if ( validChromaCbf && isChromaQpAdjCoded && !pcCU->getCUTransquantBypass(rTu.GetAbsPartIdxCU()) )
976        {
977          decodeChromaQpAdjustment( pcCU, rTu.GetAbsPartIdxCU() );
978          isChromaQpAdjCoded = false;
979        }
980      }
981
982      const UInt numValidComp=pcCU->getPic()->getNumberValidComponents();
983
984      for(UInt ch=COMPONENT_Y; ch<numValidComp; ch++)
985      {
986        const ComponentID compID=ComponentID(ch);
987
988        if( rTu.ProcessComponentSection(compID) )
989        {
990#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
991          if (bDebugRQT)
992          {
993            printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, rTu.getRect(compID).width, rTu.getRect(compID).height, 1);
994          }
995#endif
996
997          if (rTu.getRect(compID).width != rTu.getRect(compID).height)
998          {
999            //code two sub-TUs
1000            TComTURecurse subTUIterator(rTu, false, TComTU::VERTICAL_SPLIT, true, compID);
1001
1002            do
1003            {
1004              const UInt subTUCBF = pcCU->getCbf(subTUIterator.GetAbsPartIdxTU(), compID, (uiTrIdx + 1));
1005
1006              if (subTUCBF != 0)
1007              {
1008#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
1009                if (bDebugRQT)
1010                {
1011                  printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, subTUIterator.getRect(compID).width, subTUIterator.getRect(compID).height, 1);
1012                }
1013#endif
1014                m_pcEntropyDecoderIf->parseCoeffNxN( subTUIterator, compID );
1015              }
1016            } while (subTUIterator.nextSection(rTu));
1017          }
1018          else
1019          {
1020            if(isChroma(compID) && (cbf[COMPONENT_Y] != 0))
1021            {
1022              m_pcEntropyDecoderIf->parseCrossComponentPrediction( rTu, compID );
1023            }
1024
1025            if(cbf[compID] != 0)
1026            {
1027              m_pcEntropyDecoderIf->parseCoeffNxN( rTu, compID );
1028            }
1029          }
1030        }
1031      }
1032    }
1033    // transform_unit end
1034  }
1035}
1036
1037Void TDecEntropy::decodeQP          ( TComDataCU* pcCU, UInt uiAbsPartIdx )
1038{
1039  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
1040  {
1041    m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
1042  }
1043}
1044
1045Void TDecEntropy::decodeChromaQpAdjustment( TComDataCU* pcCU, UInt uiAbsPartIdx )
1046{
1047  if ( pcCU->getSlice()->getUseChromaQpAdj() )
1048  {
1049    m_pcEntropyDecoderIf->parseChromaQpAdjustment( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
1050  }
1051}
1052
1053
1054//! decode coefficients
1055Void TDecEntropy::decodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool& bCodeDQP, Bool& isChromaQpAdjCoded )
1056{
1057#if H_3D_DIM_SDC
1058  if( pcCU->getSDCFlag( uiAbsPartIdx ) && pcCU->isIntra( uiAbsPartIdx) )
1059  {
1060    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
1061    assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 );
1062    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 );
1063    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
1064    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
1065}
1066#if H_3D_INTER_SDC
1067  if( pcCU->getSDCFlag( uiAbsPartIdx ) && !pcCU->isIntra( uiAbsPartIdx) )
1068  {
1069    assert( !pcCU->isSkipped( uiAbsPartIdx ) );
1070    assert( !pcCU->isIntra( uiAbsPartIdx) );
1071    assert( pcCU->getSlice()->getIsDepth() );
1072  }
1073#endif
1074  if( pcCU->getSlice()->getIsDepth() && ( pcCU->getSDCFlag( uiAbsPartIdx ) || pcCU->isIntra( uiAbsPartIdx ) ) )
1075  {
1076    Int iPartNum = ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) ? 4 : 1;
1077    UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth( uiAbsPartIdx ) << 1 ) ) >> 2;
1078 
1079    if( !pcCU->getSDCFlag( uiAbsPartIdx ) )
1080    {
1081      for( Int iPart = 0; iPart < iPartNum; iPart++ )
1082      {
1083        if( getDimType( pcCU->getLumaIntraDir( uiAbsPartIdx + uiPartOffset*iPart ) ) < DIM_NUM_TYPE ) 
1084        {
1085          m_pcEntropyDecoderIf->parseDeltaDC( pcCU, uiAbsPartIdx + uiPartOffset*iPart, uiDepth + ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) );
1086        }
1087      }
1088    }
1089    else
1090    {
1091      m_pcEntropyDecoderIf->parseDeltaDC( pcCU, uiAbsPartIdx, uiDepth );
1092      return;
1093    }
1094  }
1095#endif
1096
1097  if( pcCU->isIntra(uiAbsPartIdx) )
1098  {
1099  }
1100  else
1101  {
1102    UInt uiQtRootCbf = 1;
1103    if( !( pcCU->getPartitionSize( uiAbsPartIdx) == SIZE_2Nx2N && pcCU->getMergeFlag( uiAbsPartIdx ) ) )
1104    {
1105      m_pcEntropyDecoderIf->parseQtRootCbf( uiAbsPartIdx, uiQtRootCbf );
1106    }
1107    if ( !uiQtRootCbf )
1108    {
1109      static const UInt cbfZero[MAX_NUM_COMPONENT]={0,0,0};
1110      pcCU->setCbfSubParts( cbfZero, uiAbsPartIdx, uiDepth );
1111      pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth );
1112      return;
1113    }
1114
1115  }
1116
1117  TComTURecurse tuRecurse(pcCU, uiAbsPartIdx, uiDepth);
1118
1119#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
1120  if (bDebugRQT)
1121  {
1122    printf("..codeCoeff: uiAbsPartIdx=%d, PU format=%d, 2Nx2N=%d, NxN=%d\n", uiAbsPartIdx, pcCU->getPartitionSize(uiAbsPartIdx), SIZE_2Nx2N, SIZE_NxN);
1123  }
1124#endif
1125
1126  Int quadtreeTULog2MinSizeInCU = pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx);
1127 
1128  xDecodeTransform( bCodeDQP, isChromaQpAdjCoded, tuRecurse, quadtreeTULog2MinSizeInCU );
1129}
1130
1131#if H_3D_INTER_SDC
1132Void TDecEntropy::decodeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1133{
1134  pcCU->setSDCFlagSubParts( false, uiAbsPartIdx, uiDepth );
1135  if ( pcCU->isSkipped( uiAbsPartIdx ) )
1136  {
1137    return; 
1138  }
1139
1140
1141  if( ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getInterSdcFlag() ) || 
1142    ( pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getIntraSdcWedgeFlag() ) )
1143  {
1144    return;
1145  }
1146
1147  if( !pcCU->getSlice()->getIsDepth() || pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_2Nx2N || pcCU->isSkipped( uiAbsPartIdx ) )
1148  {
1149    return;
1150  }
1151
1152  assert( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N || ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->isSkipped( uiAbsPartIdx ) ) );
1153  m_pcEntropyDecoderIf->parseSDCFlag( pcCU, uiAbsPartIdx, uiDepth );
1154}
1155#endif
1156#if H_3D_DBBP
1157Void TDecEntropy::decodeDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1158{
1159  if( pcCU->getSlice()->getDepthBasedBlkPartFlag() && (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2NxN || pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_Nx2N) && pcCU->getWidth(uiAbsPartIdx) > 8 && pcCU->getSlice()->getDefaultRefViewIdxAvailableFlag() )
1160  {
1161    m_pcEntropyDecoderIf->parseDBBPFlag( pcCU, uiAbsPartIdx, uiDepth );
1162  }
1163}
1164#endif
1165
1166
1167
1168//! \}
Note: See TracBrowser for help on using the repository browser.