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

Last change on this file since 816 was 816, checked in by rwth, 10 years ago
  • first version of DBBP (requires some cleanup)
  • Property svn:eol-style set to native
File size: 30.5 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( pcCU->getVSPFlag( uiSubPartIdx ) != 0 )
378          {
379            if ( uhInterDirNeighbours[ uiMergeIndex ] & (1<<uiRefListIdx) )
380            {
381              UInt dummy;
382              Int vspSize;
383              Int width, height;
384              pcCU->getPartIndexAndSize( uiPartIdx, dummy, width, height, uiSubPartIdx, pcCU->getTotalNumPart()==256 );
385              pcCU->setMvFieldPUForVSP( pcCU, uiSubPartIdx, width, height, RefPicList( uiRefListIdx ), cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getRefIdx(), vspSize );
386              pcCU->setVSPFlag( uiSubPartIdx, vspSize );
387            }
388          }
389#endif
390        }
391      }
392#if H_3D_SPIVMP
393      pcCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth ); 
394      if (bSPIVMPFlag[uiMergeIndex] != 0)
395      {
396        Int iWidth, iHeight;
397        UInt uiIdx;
398        pcCU->getPartIndexAndSize( uiPartIdx, uiIdx, iWidth, iHeight, uiSubPartIdx, true );
399
400        UInt uiSPAddr;
401
402        Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
403
404        pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
405
406        for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++)
407        {
408          pcCU->getSPAbsPartIdx(uiSubPartIdx, iSPWidth, iSPHeight, iPartitionIdx, iNumSPInOneLine, uiSPAddr);
409          pcCU->setInterDirSP(puhInterDirSP[iPartitionIdx], uiSPAddr, iSPWidth, iSPHeight);
410          pcCU->getCUMvField( REF_PIC_LIST_0 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx], iSPWidth, iSPHeight);
411          pcCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight);
412        }
413      }
414#endif
415    }
416    else
417    {
418      decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
419      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
420      {       
421        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
422        {
423          decodeRefFrmIdxPU( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
424          decodeMvdPU      ( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
425          decodeMVPIdxPU   ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
426        }
427      }
428#if H_3D_IC
429      decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
430#endif
431#if H_3D_ARP
432      decodeARPW  ( pcCU, uiAbsPartIdx, uiDepth );
433#endif
434    }
435#if H_3D_VSP
436#if NTT_STORE_SPDV_VSP_G0148
437    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) && (pcCU->getVSPFlag(uiSubPartIdx) == 0))
438#else
439    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) && (pcCU->getVSPFlag(uiSubPartIdx) == false))
440#endif
441#else
442    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) )
443#endif
444    {
445      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( TComMv(0,0), ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
446      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( -1, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
447      pcCU->setInterDirSubParts( 1, uiSubPartIdx, uiPartIdx, uiDepth);
448    }
449  }
450#if H_3D_SPIVMP
451  delete[] pcMvFieldSP;
452  delete[] puhInterDirSP;
453#endif
454  return;
455}
456
457/** decode inter direction for a PU block
458 * \param pcCU
459 * \param uiAbsPartIdx
460 * \param uiDepth
461 * \param uiPartIdx
462 * \returns Void
463 */
464Void TDecEntropy::decodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx )
465{
466  UInt uiInterDir;
467
468  if ( pcCU->getSlice()->isInterP() )
469  {
470    uiInterDir = 1;
471  }
472  else
473  {
474    m_pcEntropyDecoderIf->parseInterDir( pcCU, uiInterDir, uiAbsPartIdx );
475  }
476
477  pcCU->setInterDirSubParts( uiInterDir, uiAbsPartIdx, uiPartIdx, uiDepth );
478}
479
480Void TDecEntropy::decodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
481{
482  Int iRefFrmIdx = 0;
483  Int iParseRefFrmIdx = pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList );
484
485  if ( pcCU->getSlice()->getNumRefIdx( eRefList ) > 1 && iParseRefFrmIdx )
486  {
487    m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, eRefList );
488  }
489  else if ( !iParseRefFrmIdx )
490  {
491    iRefFrmIdx = NOT_VALID;
492  }
493  else
494  {
495    iRefFrmIdx = 0;
496  }
497
498  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
499  pcCU->getCUMvField( eRefList )->setAllRefIdx( iRefFrmIdx, ePartSize, uiAbsPartIdx, uiDepth, uiPartIdx );
500}
501
502/** decode motion vector difference for a PU block
503 * \param pcCU
504 * \param uiAbsPartIdx
505 * \param uiDepth
506 * \param uiPartIdx
507 * \param eRefList
508 * \returns Void
509 */
510Void TDecEntropy::decodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
511{
512  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
513  {
514    m_pcEntropyDecoderIf->parseMvd( pcCU, uiAbsPartIdx, uiPartIdx, uiDepth, eRefList );
515  }
516}
517
518Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
519{
520  Int iMVPIdx = -1;
521
522  TComMv cZeroMv( 0, 0 );
523  TComMv cMv     = cZeroMv;
524  Int    iRefIdx = -1;
525
526  TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList );
527  AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo();
528
529  iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr);
530  cMv = cZeroMv;
531
532  if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) )
533  {
534    m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx );
535#if H_MV_ENC_DEC_TRAC
536#if ENC_DEC_TRACE
537    if ( eRefList == REF_PIC_LIST_0 )
538    {
539      DTRACE_PU("mvp_l0_flag", iMVPIdx)
540    }
541    else
542    {
543      DTRACE_PU("mvp_l1_flag", iMVPIdx)
544    }
545#endif
546#endif
547  }
548  pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo);
549  pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth);
550  pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth );
551  if ( iRefIdx >= 0 )
552  {
553    m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, cMv);
554    cMv += pcSubCUMvField->getMvd( uiPartAddr );
555  }
556
557  PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr );
558  pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx);
559}
560
561Void TDecEntropy::xDecodeTransform( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP)
562{
563  UInt uiSubdiv;
564  const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
565
566  if(uiTrIdx==0)
567  {
568    m_bakAbsPartIdxCU = uiAbsPartIdx;
569  }
570  if( uiLog2TrafoSize == 2 )
571  {
572    UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
573    if( ( uiAbsPartIdx % partNum ) == 0 )
574    {
575      m_uiBakAbsPartIdx   = uiAbsPartIdx;
576      m_uiBakChromaOffset = offsetChroma;
577    }
578  }
579  if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
580  {
581    uiSubdiv = 1;
582  }
583  else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) )
584  {
585    uiSubdiv = (uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx));
586  }
587  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
588  {
589    uiSubdiv = 1;
590  }
591  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
592  {
593    uiSubdiv = 0;
594  }
595  else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
596  {
597    uiSubdiv = 0;
598  }
599  else
600  {
601    assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
602    m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
603  }
604 
605  const UInt uiTrDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx );
606  {
607    const Bool bFirstCbfOfCU = uiTrDepth == 0;
608    if( bFirstCbfOfCU )
609    {
610      pcCU->setCbfSubParts( 0, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
611      pcCU->setCbfSubParts( 0, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
612    }
613    if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
614    {
615      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) )
616      {
617        m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth, uiDepth );
618      }
619      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) )
620      {
621        m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth, uiDepth );
622      }
623    }
624    else
625    {
626      pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
627      pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
628    }
629  }
630 
631  if( uiSubdiv )
632  {
633    UInt size;
634    width  >>= 1;
635    height >>= 1;
636    size = width*height;
637    uiTrIdx++;
638    ++uiDepth;
639    const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
640    const UInt uiStartAbsPartIdx = uiAbsPartIdx;
641    UInt uiYCbf = 0;
642    UInt uiUCbf = 0;
643    UInt uiVCbf = 0;
644   
645    for( Int i = 0; i < 4; i++ )
646    {
647      xDecodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
648      uiYCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth+1 );
649      uiUCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth+1 );
650      uiVCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth+1 );
651      uiAbsPartIdx += uiQPartNum;
652      offsetLuma += size;  offsetChroma += (size>>2);
653    }
654   
655    for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui )
656    {
657      pcCU->getCbf( TEXT_LUMA     )[uiStartAbsPartIdx + ui] |= uiYCbf << uiTrDepth;
658      pcCU->getCbf( TEXT_CHROMA_U )[uiStartAbsPartIdx + ui] |= uiUCbf << uiTrDepth;
659      pcCU->getCbf( TEXT_CHROMA_V )[uiStartAbsPartIdx + ui] |= uiVCbf << uiTrDepth;
660    }
661  }
662  else
663  {
664    assert( uiDepth >= pcCU->getDepth( uiAbsPartIdx ) );
665    pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiDepth );
666   
667#if !H_MV_ENC_DEC_TRAC
668    {
669      DTRACE_CABAC_VL( g_nSymbolCounter++ );
670      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
671      DTRACE_CABAC_V( uiAbsPartIdx );
672      DTRACE_CABAC_T( "\tdepth=" );
673      DTRACE_CABAC_V( uiDepth );
674      DTRACE_CABAC_T( "\ttrdepth=" );
675      DTRACE_CABAC_V( uiTrDepth );
676      DTRACE_CABAC_T( "\n" );
677    }
678#endif
679   
680    pcCU->setCbfSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiDepth );
681    if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
682    {
683      pcCU->setCbfSubParts( 1 << uiTrDepth, TEXT_LUMA, uiAbsPartIdx, uiDepth );
684    }
685    else
686    {
687      m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrDepth, uiDepth );
688    }
689
690
691    // transform_unit begin
692    UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA    , uiTrIdx );
693    UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
694    UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
695    if( uiLog2TrafoSize == 2 )
696    {
697      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
698      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
699      {
700        cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
701        cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
702      }
703    }
704    if ( cbfY || cbfU || cbfV )
705    {
706      // dQP: only for LCU
707      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
708      {
709        if ( bCodeDQP )
710        {
711          decodeQP( pcCU, m_bakAbsPartIdxCU);
712          bCodeDQP = false;
713        }
714      }
715    }
716    if( cbfY )
717    {
718      Int trWidth = width;
719      Int trHeight = height;
720      m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
721    }
722    if( uiLog2TrafoSize > 2 )
723    {
724      Int trWidth = width >> 1;
725      Int trHeight = height >> 1;
726      if( cbfU )
727      {
728        m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
729      }
730      if( cbfV )
731      {
732        m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
733      }
734    }
735    else
736    {
737      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
738      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
739      {
740        Int trWidth = width;
741        Int trHeight = height;
742        if( cbfU )
743        {
744          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
745        }
746        if( cbfV )
747        {
748          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
749        }
750      }
751    }
752    // transform_unit end
753  }
754}
755
756Void TDecEntropy::decodeQP          ( TComDataCU* pcCU, UInt uiAbsPartIdx )
757{
758  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
759  {
760    m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
761  }
762}
763
764
765/** decode coefficients
766 * \param pcCU
767 * \param uiAbsPartIdx
768 * \param uiDepth
769 * \param uiWidth
770 * \param uiHeight
771 * \returns Void
772 */
773Void TDecEntropy::decodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
774{
775  UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
776  UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
777  UInt uiChromaOffset = uiLumaOffset>>2;
778 
779#if H_3D_DIM_SDC
780  if( pcCU->getSDCFlag( uiAbsPartIdx ) )
781  {
782    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
783    assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 );
784    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 );
785    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
786    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
787    return;
788  }
789#endif
790 
791#if H_3D_INTER_SDC
792  if( pcCU->getInterSDCFlag( uiAbsPartIdx ) )
793  {
794    assert( !pcCU->isSkipped( uiAbsPartIdx ) );
795    assert( !pcCU->isIntra( uiAbsPartIdx) );
796    assert( pcCU->getSlice()->getIsDepth() );
797
798    decodeInterSDCResidualData( pcCU, uiAbsPartIdx, uiDepth );
799    return;
800  }
801#endif
802
803  if( pcCU->isIntra(uiAbsPartIdx) )
804  {
805  }
806  else
807  {
808    UInt uiQtRootCbf = 1;
809    if( !( pcCU->getPartitionSize( uiAbsPartIdx) == SIZE_2Nx2N && pcCU->getMergeFlag( uiAbsPartIdx ) ) )
810    {
811      m_pcEntropyDecoderIf->parseQtRootCbf( uiAbsPartIdx, uiQtRootCbf );
812    }
813    if ( !uiQtRootCbf )
814    {
815      pcCU->setCbfSubParts( 0, 0, 0, uiAbsPartIdx, uiDepth );
816      pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth );
817      return;
818    }
819   
820  }
821  xDecodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP );
822}
823
824#if H_3D_INTER_SDC
825Void TDecEntropy::decodeInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
826{
827  pcCU->setInterSDCFlagSubParts( false, uiAbsPartIdx, 0, uiDepth);
828
829  if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )
830  {
831    return;
832  }
833
834  if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || pcCU->isSkipped( uiAbsPartIdx ) )
835  {
836    return;
837  }
838
839  m_pcEntropyDecoderIf->parseInterSDCFlag( pcCU, uiAbsPartIdx, uiDepth );
840}
841
842Void TDecEntropy::decodeInterSDCResidualData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
843{
844  if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )
845  {
846    return;
847  }
848
849  if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || !pcCU->getInterSDCFlag( uiAbsPartIdx ) )
850  {
851    return;
852  }
853
854  UInt uiNumSegments = ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) ? 1 : ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 4 : 2 );
855
856  // decode residual data for each segment
857  for( UInt uiSeg = 0; uiSeg < uiNumSegments; uiSeg++ )
858  {
859    m_pcEntropyDecoderIf->parseInterSDCResidualData( pcCU, uiAbsPartIdx, uiDepth, uiSeg );
860  }
861}
862#endif
863
864#if H_3D_DBBP
865Void TDecEntropy::decodeDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
866{
867  m_pcEntropyDecoderIf->parseDBBPFlag( pcCU, uiAbsPartIdx, uiDepth );
868}
869#endif
870
871//! \}
Note: See TracBrowser for help on using the repository browser.