source: 3DVCSoftware/branches/HTM-9.3-dev1-RWTH/source/Lib/TLibDecoder/TDecEntropy.cpp @ 819

Last change on this file since 819 was 819, checked in by rwth, 11 years ago
  • make G0106 and G0148 mutually exclusive
  • Property svn:eol-style set to native
File size: 30.6 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-2013, 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
40//! \ingroup TLibDecoder
41//! \{
42
43Void TDecEntropy::setEntropyDecoder         ( TDecEntropyIf* p )
44{
45  m_pcEntropyDecoderIf = p;
46}
47
48#include "TLibCommon/TComSampleAdaptiveOffset.h"
49
50Void TDecEntropy::decodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
51{
52  m_pcEntropyDecoderIf->parseSkipFlag( pcCU, uiAbsPartIdx, uiDepth );
53}
54
55Void TDecEntropy::decodeCUTransquantBypassFlag(TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
56{
57  m_pcEntropyDecoderIf->parseCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth );
58}
59
60/** decode merge flag
61 * \param pcSubCU
62 * \param uiAbsPartIdx
63 * \param uiDepth
64 * \param uiPUIdx
65 * \returns Void
66 */
67Void TDecEntropy::decodeMergeFlag( TComDataCU* pcSubCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
68{ 
69  // at least one merge candidate exists
70  m_pcEntropyDecoderIf->parseMergeFlag( pcSubCU, uiAbsPartIdx, uiDepth, uiPUIdx );
71}
72
73/** decode merge index
74 * \param pcCU
75 * \param uiPartIdx
76 * \param uiAbsPartIdx
77 * \param puhInterDirNeighbours pointer to list of inter direction from the casual neighbours
78 * \param pcMvFieldNeighbours pointer to list of motion vector field from the casual neighbours
79 * \param uiDepth
80 * \returns Void
81 */
82Void TDecEntropy::decodeMergeIndex( TComDataCU* pcCU, UInt uiPartIdx, UInt uiAbsPartIdx, UInt uiDepth )
83{
84  UInt uiMergeIndex = 0;
85  m_pcEntropyDecoderIf->parseMergeIndex( pcCU, uiMergeIndex );
86  pcCU->setMergeIndexSubParts( uiMergeIndex, uiAbsPartIdx, uiPartIdx, uiDepth );
87}
88
89#if H_3D_ARP
90Void TDecEntropy::decodeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
91{
92  if( !pcCU->getSlice()->getARPStepNum() || pcCU->isIntra( uiAbsPartIdx ) )
93  {
94    return;
95  }
96
97  if( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N )
98  {
99    pcCU->setARPWSubParts( 0 , uiAbsPartIdx, uiDepth );
100  }
101  else
102  {
103    m_pcEntropyDecoderIf->parseARPW( pcCU , uiAbsPartIdx , uiDepth );
104  }
105}
106#endif
107
108#if H_3D_IC
109Void TDecEntropy::decodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
110{
111  pcCU->setICFlagSubParts( false , uiAbsPartIdx, 0, uiDepth );
112
113  if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) || pcCU->getSlice()->getIsDepth() )
114  {
115    return;
116  }
117
118  if( !pcCU->getSlice()->getApplyIC() )
119    return;
120
121  if( pcCU->isICFlagRequired( uiAbsPartIdx ) )
122    m_pcEntropyDecoderIf->parseICFlag( pcCU, uiAbsPartIdx, uiDepth );
123}
124#endif
125
126Void TDecEntropy::decodeSplitFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
127{
128  m_pcEntropyDecoderIf->parseSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
129}
130
131Void TDecEntropy::decodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
132{
133  m_pcEntropyDecoderIf->parsePredMode( pcCU, uiAbsPartIdx, uiDepth );
134}
135
136Void TDecEntropy::decodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
137{
138  m_pcEntropyDecoderIf->parsePartSize( pcCU, uiAbsPartIdx, uiDepth );
139 
140#if H_3D_DBBP
141  if( pcCU->getSlice()->getVPS()->getUseDBBP(pcCU->getSlice()->getLayerIdInVps()) && pcCU->getPartitionSize(uiAbsPartIdx) == RWTH_DBBP_PACK_MODE )
142  {
143    decodeDBBPFlag(pcCU, uiAbsPartIdx, uiDepth);
144   
145    if( pcCU->getDBBPFlag(uiAbsPartIdx) )
146    {
147      AOF( pcCU->getPartitionSize(uiAbsPartIdx) == RWTH_DBBP_PACK_MODE );
148     
149      // get collocated depth block
150      UInt uiDepthStride = 0;
151      Pel* pDepthPels = NULL;
152      pDepthPels = pcCU->getVirtualDepthBlock(uiAbsPartIdx, pcCU->getWidth(uiAbsPartIdx), pcCU->getHeight(uiAbsPartIdx), uiDepthStride);
153     
154      AOF( pDepthPels != NULL );
155      AOF( uiDepthStride != 0 );
156     
157      // derive true partitioning for this CU based on depth
158      // (needs to be done in parsing process as motion vector predictors are also derived during parsing)
159      PartSize eVirtualPartSize = m_pcPrediction->getPartitionSizeFromDepth(pDepthPels, uiDepthStride, pcCU->getWidth(uiAbsPartIdx));
160      AOF( eVirtualPartSize != SIZE_NONE );
161     
162      pcCU->setPartSizeSubParts(eVirtualPartSize, uiAbsPartIdx, uiDepth);
163      AOF( pcCU->getPartitionSize(uiAbsPartIdx) == eVirtualPartSize );
164    }
165  }
166#endif
167}
168
169Void TDecEntropy::decodePredInfo    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
170{
171  if( pcCU->isIntra( uiAbsPartIdx ) )                                 // If it is Intra mode, encode intra prediction mode.
172  {
173    decodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx, uiDepth );
174#if H_3D_DIM_SDC
175    if(!pcCU->getSDCFlag(uiAbsPartIdx))
176#endif
177    decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth );
178  }
179  else                                                                // if it is Inter mode, encode motion vector and reference index
180  {
181    decodePUWise( pcCU, uiAbsPartIdx, uiDepth, pcSubCU );
182  }
183}
184
185/** Parse I_PCM information.
186 * \param pcCU  pointer to CUpointer to CU
187 * \param uiAbsPartIdx CU index
188 * \param uiDepth CU depth
189 * \returns Void
190 */
191Void TDecEntropy::decodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
192{
193  if(!pcCU->getSlice()->getSPS()->getUsePCM()
194    || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize())
195    || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()) )
196  {
197    return;
198  }
199#if H_3D_DIM_SDC
200  if( pcCU->getSDCFlag(uiAbsPartIdx) )
201  {
202    return;
203  }
204#endif
205 
206  m_pcEntropyDecoderIf->parseIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
207}
208
209Void TDecEntropy::decodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
210{
211  m_pcEntropyDecoderIf->parseIntraDirLumaAng( pcCU, uiAbsPartIdx, uiDepth );
212}
213
214Void TDecEntropy::decodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
215{
216  m_pcEntropyDecoderIf->parseIntraDirChroma( pcCU, uiAbsPartIdx, uiDepth );
217}
218
219/** decode motion information for every PU block.
220 * \param pcCU
221 * \param uiAbsPartIdx
222 * \param uiDepth
223 * \param pcSubCU
224 * \returns Void
225 */
226Void TDecEntropy::decodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
227{
228  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
229  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
230  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
231
232#if H_3D_IV_MERGE
233  TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
234  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
235#else
236  TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
237  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
238#endif
239#if H_3D_SPIVMP
240  Bool bSPIVMPFlag[MRG_MAX_NUM_CANDS_MEM];
241  TComMvField*  pcMvFieldSP;
242  UChar* puhInterDirSP;
243  pcMvFieldSP = new TComMvField[pcCU->getPic()->getPicSym()->getNumPartition()*2]; 
244  puhInterDirSP = new UChar[pcCU->getPic()->getPicSym()->getNumPartition()]; 
245#endif
246  for ( UInt ui = 0; ui < pcCU->getSlice()->getMaxNumMergeCand(); ui++ )
247  {
248    uhInterDirNeighbours[ui] = 0;
249  }
250  Int numValidMergeCand = 0;
251  Bool isMerged = false;
252
253  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
254  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 );
255#if H_3D_IV_MERGE
256  pcSubCU->copyDVInfoFrom( pcCU, uiAbsPartIdx);
257#endif
258  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
259  {
260#if H_MV_ENC_DEC_TRAC
261    DTRACE_PU_S("=========== prediction_unit ===========\n")
262    // ToDo:
263    //DTRACE_PU("x0", uiLPelX)
264    //DTRACE_PU("x1", uiTPelY)
265#endif
266    decodeMergeFlag( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
267    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
268    {
269      decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, uiDepth );
270      UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
271#if H_3D_IC
272      decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
273#endif
274#if H_3D_ARP
275      decodeARPW  ( pcCU, uiAbsPartIdx, uiDepth );
276#endif
277#if H_3D_DBBP
278      if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 && pcCU->getDBBPFlag(uiAbsPartIdx) == false )
279#else
280      if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 ) 
281#endif
282      {
283        pcSubCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );
284        if ( !isMerged )
285        {
286#if H_3D_VSP
287          Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
288          memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
289          InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
290#if H_3D_SPIVMP
291          memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM);
292#endif
293          pcSubCU->initAvailableFlags();
294          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand);
295          pcSubCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo
296#if H_3D_SPIVMP
297            , bSPIVMPFlag, pcMvFieldSP, puhInterDirSP
298#endif
299            , numValidMergeCand );
300          pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
301
302          if(vspFlag[uiMergeIndex])
303          {
304            pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiSubPartIdx, uiPartIdx, uiDepth);
305          }
306#else
307#if H_3D
308          pcSubCU->initAvailableFlags();
309          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand);
310          pcSubCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
311
312#else
313          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
314#endif
315#endif
316          isMerged = true;
317        }
318        pcSubCU->setPartSizeSubParts( ePartSize, 0, uiDepth );
319      }
320      else
321      {
322        uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
323#if H_3D_VSP
324        Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
325        memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
326        InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
327#if H_3D_SPIVMP
328        memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM);
329#endif
330        pcSubCU->initAvailableFlags();
331        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
332        pcSubCU->xGetInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo
333#if H_3D_SPIVMP
334          , bSPIVMPFlag, pcMvFieldSP, puhInterDirSP
335#endif
336          ,numValidMergeCand, uiMergeIndex );
337        pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
338        if(vspFlag[uiMergeIndex])
339        {
340          pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiSubPartIdx, uiPartIdx, uiDepth);
341        }
342#else
343#if H_3D
344        pcSubCU->initAvailableFlags();
345        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
346        pcSubCU->xGetInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
347#else
348        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
349#endif
350#endif
351      }
352      pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
353
354#if MTK_DDD_G0063
355      if( uiMergeIndex == pcSubCU->getUseDDDCandIdx() )
356      {
357          assert( pcCU->getSlice()->getViewIndex() != 0 );
358          pcCU->setUseDDD( true, uiSubPartIdx, uiPartIdx, uiDepth );
359          pcCU->setDDDepthSubParts( pcSubCU->getDDTmpDepth(),uiSubPartIdx, uiPartIdx, uiDepth );
360      }
361      else
362      {
363          pcCU->setUseDDD( false, uiSubPartIdx, uiPartIdx, uiDepth );
364      }
365#endif
366
367      TComMv cTmpMv( 0, 0 );
368      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
369      {       
370        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
371        {
372          pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
373          pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
374          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
375          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
376#if NTT_STORE_SPDV_VSP_G0148
377#if H_3D_DBBP
378          if( pcCU->getVSPFlag( uiSubPartIdx ) != 0 && !pcCU->getDBBPFlag( uiAbsPartIdx ) )
379#else
380          if( pcCU->getVSPFlag( uiSubPartIdx ) != 0 )
381#endif
382          {
383            if ( uhInterDirNeighbours[ uiMergeIndex ] & (1<<uiRefListIdx) )
384            {
385              UInt dummy;
386              Int vspSize;
387              Int width, height;
388              pcCU->getPartIndexAndSize( uiPartIdx, dummy, width, height, uiSubPartIdx, pcCU->getTotalNumPart()==256 );
389              pcCU->setMvFieldPUForVSP( pcCU, uiSubPartIdx, width, height, RefPicList( uiRefListIdx ), cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getRefIdx(), vspSize );
390              pcCU->setVSPFlag( uiSubPartIdx, vspSize );
391            }
392          }
393#endif
394        }
395      }
396#if H_3D_SPIVMP
397      pcCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth ); 
398      if (bSPIVMPFlag[uiMergeIndex] != 0)
399      {
400        Int iWidth, iHeight;
401        UInt uiIdx;
402        pcCU->getPartIndexAndSize( uiPartIdx, uiIdx, iWidth, iHeight, uiSubPartIdx, true );
403
404        UInt uiSPAddr;
405
406        Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
407
408        pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
409
410        for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++)
411        {
412          pcCU->getSPAbsPartIdx(uiSubPartIdx, iSPWidth, iSPHeight, iPartitionIdx, iNumSPInOneLine, uiSPAddr);
413          pcCU->setInterDirSP(puhInterDirSP[iPartitionIdx], uiSPAddr, iSPWidth, iSPHeight);
414          pcCU->getCUMvField( REF_PIC_LIST_0 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx], iSPWidth, iSPHeight);
415          pcCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight);
416        }
417      }
418#endif
419    }
420    else
421    {
422      decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
423      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
424      {       
425        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
426        {
427          decodeRefFrmIdxPU( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
428          decodeMvdPU      ( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
429          decodeMVPIdxPU   ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
430        }
431      }
432#if H_3D_IC
433      decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
434#endif
435#if H_3D_ARP
436      decodeARPW  ( pcCU, uiAbsPartIdx, uiDepth );
437#endif
438    }
439#if H_3D_VSP
440#if NTT_STORE_SPDV_VSP_G0148
441    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) && (pcCU->getVSPFlag(uiSubPartIdx) == 0))
442#else
443    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) && (pcCU->getVSPFlag(uiSubPartIdx) == false))
444#endif
445#else
446    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) )
447#endif
448    {
449      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( TComMv(0,0), ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
450      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( -1, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
451      pcCU->setInterDirSubParts( 1, uiSubPartIdx, uiPartIdx, uiDepth);
452    }
453  }
454#if H_3D_SPIVMP
455  delete[] pcMvFieldSP;
456  delete[] puhInterDirSP;
457#endif
458  return;
459}
460
461/** decode inter direction for a PU block
462 * \param pcCU
463 * \param uiAbsPartIdx
464 * \param uiDepth
465 * \param uiPartIdx
466 * \returns Void
467 */
468Void TDecEntropy::decodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx )
469{
470  UInt uiInterDir;
471
472  if ( pcCU->getSlice()->isInterP() )
473  {
474    uiInterDir = 1;
475  }
476  else
477  {
478    m_pcEntropyDecoderIf->parseInterDir( pcCU, uiInterDir, uiAbsPartIdx );
479  }
480
481  pcCU->setInterDirSubParts( uiInterDir, uiAbsPartIdx, uiPartIdx, uiDepth );
482}
483
484Void TDecEntropy::decodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
485{
486  Int iRefFrmIdx = 0;
487  Int iParseRefFrmIdx = pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList );
488
489  if ( pcCU->getSlice()->getNumRefIdx( eRefList ) > 1 && iParseRefFrmIdx )
490  {
491    m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, eRefList );
492  }
493  else if ( !iParseRefFrmIdx )
494  {
495    iRefFrmIdx = NOT_VALID;
496  }
497  else
498  {
499    iRefFrmIdx = 0;
500  }
501
502  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
503  pcCU->getCUMvField( eRefList )->setAllRefIdx( iRefFrmIdx, ePartSize, uiAbsPartIdx, uiDepth, uiPartIdx );
504}
505
506/** decode motion vector difference for a PU block
507 * \param pcCU
508 * \param uiAbsPartIdx
509 * \param uiDepth
510 * \param uiPartIdx
511 * \param eRefList
512 * \returns Void
513 */
514Void TDecEntropy::decodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
515{
516  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
517  {
518    m_pcEntropyDecoderIf->parseMvd( pcCU, uiAbsPartIdx, uiPartIdx, uiDepth, eRefList );
519  }
520}
521
522Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
523{
524  Int iMVPIdx = -1;
525
526  TComMv cZeroMv( 0, 0 );
527  TComMv cMv     = cZeroMv;
528  Int    iRefIdx = -1;
529
530  TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList );
531  AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo();
532
533  iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr);
534  cMv = cZeroMv;
535
536  if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) )
537  {
538    m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx );
539#if H_MV_ENC_DEC_TRAC
540#if ENC_DEC_TRACE
541    if ( eRefList == REF_PIC_LIST_0 )
542    {
543      DTRACE_PU("mvp_l0_flag", iMVPIdx)
544    }
545    else
546    {
547      DTRACE_PU("mvp_l1_flag", iMVPIdx)
548    }
549#endif
550#endif
551  }
552  pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo);
553  pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth);
554  pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth );
555  if ( iRefIdx >= 0 )
556  {
557    m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, cMv);
558    cMv += pcSubCUMvField->getMvd( uiPartAddr );
559  }
560
561  PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr );
562  pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx);
563}
564
565Void TDecEntropy::xDecodeTransform( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP)
566{
567  UInt uiSubdiv;
568  const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
569
570  if(uiTrIdx==0)
571  {
572    m_bakAbsPartIdxCU = uiAbsPartIdx;
573  }
574  if( uiLog2TrafoSize == 2 )
575  {
576    UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
577    if( ( uiAbsPartIdx % partNum ) == 0 )
578    {
579      m_uiBakAbsPartIdx   = uiAbsPartIdx;
580      m_uiBakChromaOffset = offsetChroma;
581    }
582  }
583  if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
584  {
585    uiSubdiv = 1;
586  }
587  else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) )
588  {
589    uiSubdiv = (uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx));
590  }
591  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
592  {
593    uiSubdiv = 1;
594  }
595  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
596  {
597    uiSubdiv = 0;
598  }
599  else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
600  {
601    uiSubdiv = 0;
602  }
603  else
604  {
605    assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
606    m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
607  }
608 
609  const UInt uiTrDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx );
610  {
611    const Bool bFirstCbfOfCU = uiTrDepth == 0;
612    if( bFirstCbfOfCU )
613    {
614      pcCU->setCbfSubParts( 0, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
615      pcCU->setCbfSubParts( 0, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
616    }
617    if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
618    {
619      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) )
620      {
621        m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth, uiDepth );
622      }
623      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) )
624      {
625        m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth, uiDepth );
626      }
627    }
628    else
629    {
630      pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
631      pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
632    }
633  }
634 
635  if( uiSubdiv )
636  {
637    UInt size;
638    width  >>= 1;
639    height >>= 1;
640    size = width*height;
641    uiTrIdx++;
642    ++uiDepth;
643    const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
644    const UInt uiStartAbsPartIdx = uiAbsPartIdx;
645    UInt uiYCbf = 0;
646    UInt uiUCbf = 0;
647    UInt uiVCbf = 0;
648   
649    for( Int i = 0; i < 4; i++ )
650    {
651      xDecodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
652      uiYCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth+1 );
653      uiUCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth+1 );
654      uiVCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth+1 );
655      uiAbsPartIdx += uiQPartNum;
656      offsetLuma += size;  offsetChroma += (size>>2);
657    }
658   
659    for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui )
660    {
661      pcCU->getCbf( TEXT_LUMA     )[uiStartAbsPartIdx + ui] |= uiYCbf << uiTrDepth;
662      pcCU->getCbf( TEXT_CHROMA_U )[uiStartAbsPartIdx + ui] |= uiUCbf << uiTrDepth;
663      pcCU->getCbf( TEXT_CHROMA_V )[uiStartAbsPartIdx + ui] |= uiVCbf << uiTrDepth;
664    }
665  }
666  else
667  {
668    assert( uiDepth >= pcCU->getDepth( uiAbsPartIdx ) );
669    pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiDepth );
670   
671#if !H_MV_ENC_DEC_TRAC
672    {
673      DTRACE_CABAC_VL( g_nSymbolCounter++ );
674      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
675      DTRACE_CABAC_V( uiAbsPartIdx );
676      DTRACE_CABAC_T( "\tdepth=" );
677      DTRACE_CABAC_V( uiDepth );
678      DTRACE_CABAC_T( "\ttrdepth=" );
679      DTRACE_CABAC_V( uiTrDepth );
680      DTRACE_CABAC_T( "\n" );
681    }
682#endif
683   
684    pcCU->setCbfSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiDepth );
685    if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
686    {
687      pcCU->setCbfSubParts( 1 << uiTrDepth, TEXT_LUMA, uiAbsPartIdx, uiDepth );
688    }
689    else
690    {
691      m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrDepth, uiDepth );
692    }
693
694
695    // transform_unit begin
696    UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA    , uiTrIdx );
697    UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
698    UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
699    if( uiLog2TrafoSize == 2 )
700    {
701      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
702      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
703      {
704        cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
705        cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
706      }
707    }
708    if ( cbfY || cbfU || cbfV )
709    {
710      // dQP: only for LCU
711      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
712      {
713        if ( bCodeDQP )
714        {
715          decodeQP( pcCU, m_bakAbsPartIdxCU);
716          bCodeDQP = false;
717        }
718      }
719    }
720    if( cbfY )
721    {
722      Int trWidth = width;
723      Int trHeight = height;
724      m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
725    }
726    if( uiLog2TrafoSize > 2 )
727    {
728      Int trWidth = width >> 1;
729      Int trHeight = height >> 1;
730      if( cbfU )
731      {
732        m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
733      }
734      if( cbfV )
735      {
736        m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
737      }
738    }
739    else
740    {
741      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
742      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
743      {
744        Int trWidth = width;
745        Int trHeight = height;
746        if( cbfU )
747        {
748          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
749        }
750        if( cbfV )
751        {
752          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
753        }
754      }
755    }
756    // transform_unit end
757  }
758}
759
760Void TDecEntropy::decodeQP          ( TComDataCU* pcCU, UInt uiAbsPartIdx )
761{
762  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
763  {
764    m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
765  }
766}
767
768
769/** decode coefficients
770 * \param pcCU
771 * \param uiAbsPartIdx
772 * \param uiDepth
773 * \param uiWidth
774 * \param uiHeight
775 * \returns Void
776 */
777Void TDecEntropy::decodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
778{
779  UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
780  UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
781  UInt uiChromaOffset = uiLumaOffset>>2;
782 
783#if H_3D_DIM_SDC
784  if( pcCU->getSDCFlag( uiAbsPartIdx ) )
785  {
786    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
787    assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 );
788    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 );
789    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
790    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
791    return;
792  }
793#endif
794 
795#if H_3D_INTER_SDC
796  if( pcCU->getInterSDCFlag( uiAbsPartIdx ) )
797  {
798    assert( !pcCU->isSkipped( uiAbsPartIdx ) );
799    assert( !pcCU->isIntra( uiAbsPartIdx) );
800    assert( pcCU->getSlice()->getIsDepth() );
801
802    decodeInterSDCResidualData( pcCU, uiAbsPartIdx, uiDepth );
803    return;
804  }
805#endif
806
807  if( pcCU->isIntra(uiAbsPartIdx) )
808  {
809  }
810  else
811  {
812    UInt uiQtRootCbf = 1;
813    if( !( pcCU->getPartitionSize( uiAbsPartIdx) == SIZE_2Nx2N && pcCU->getMergeFlag( uiAbsPartIdx ) ) )
814    {
815      m_pcEntropyDecoderIf->parseQtRootCbf( uiAbsPartIdx, uiQtRootCbf );
816    }
817    if ( !uiQtRootCbf )
818    {
819      pcCU->setCbfSubParts( 0, 0, 0, uiAbsPartIdx, uiDepth );
820      pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth );
821      return;
822    }
823   
824  }
825  xDecodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP );
826}
827
828#if H_3D_INTER_SDC
829Void TDecEntropy::decodeInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
830{
831  pcCU->setInterSDCFlagSubParts( false, uiAbsPartIdx, 0, uiDepth);
832
833  if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )
834  {
835    return;
836  }
837
838  if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || pcCU->isSkipped( uiAbsPartIdx ) )
839  {
840    return;
841  }
842
843  m_pcEntropyDecoderIf->parseInterSDCFlag( pcCU, uiAbsPartIdx, uiDepth );
844}
845
846Void TDecEntropy::decodeInterSDCResidualData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
847{
848  if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )
849  {
850    return;
851  }
852
853  if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || !pcCU->getInterSDCFlag( uiAbsPartIdx ) )
854  {
855    return;
856  }
857
858  UInt uiNumSegments = ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) ? 1 : ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 4 : 2 );
859
860  // decode residual data for each segment
861  for( UInt uiSeg = 0; uiSeg < uiNumSegments; uiSeg++ )
862  {
863    m_pcEntropyDecoderIf->parseInterSDCResidualData( pcCU, uiAbsPartIdx, uiDepth, uiSeg );
864  }
865}
866#endif
867
868#if H_3D_DBBP
869Void TDecEntropy::decodeDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
870{
871  m_pcEntropyDecoderIf->parseDBBPFlag( pcCU, uiAbsPartIdx, uiDepth );
872}
873#endif
874
875//! \}
Note: See TracBrowser for help on using the repository browser.