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

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

Further decoder fixes.

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