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

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

Merged HTM-14.1-update-dev3@1273.

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