source: 3DVCSoftware/trunk/source/Lib/TLibDecoder/TDecEntropy.cpp @ 1313

Last change on this file since 1313 was 1313, checked in by tech, 9 years ago

Merged 14.1-update-dev1@1312.

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