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

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

Merged 14.1-update-dev2@1277.

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