source: 3DVCSoftware/branches/HTM-15.0-dev0/source/Lib/TLibDecoder/TDecEntropy.cpp @ 1317

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

Clean-ups. HLS.

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