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

Last change on this file since 1273 was 1270, checked in by tech, 10 years ago

Merged 14.1-update-dev4-Qualcomm@1266

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