source: 3DVCSoftware/trunk/source/Lib/TLibDecoder/TDecEntropy.cpp @ 884

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

Merged HTM-10.1-dev0@883. (MV-HEVC 7 HLS)

  • Property svn:eol-style set to native
File size: 30.9 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-2014, 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() || pcCU->getARPW( uiAbsPartIdx ) > 0 )
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    }
164  }
165#endif
166}
167
168Void TDecEntropy::decodePredInfo    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
169{
170  if( pcCU->isIntra( uiAbsPartIdx ) )                                 // If it is Intra mode, encode intra prediction mode.
171  {
172    decodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx, uiDepth );
173#if H_3D_DIM_SDC
174    if(!pcCU->getSDCFlag(uiAbsPartIdx))
175#endif
176    decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth );
177  }
178  else                                                                // if it is Inter mode, encode motion vector and reference index
179  {
180    decodePUWise( pcCU, uiAbsPartIdx, uiDepth, pcSubCU );
181  }
182}
183
184/** Parse I_PCM information.
185 * \param pcCU  pointer to CUpointer to CU
186 * \param uiAbsPartIdx CU index
187 * \param uiDepth CU depth
188 * \returns Void
189 */
190Void TDecEntropy::decodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
191{
192  if(!pcCU->getSlice()->getSPS()->getUsePCM()
193    || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize())
194    || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()) )
195  {
196    return;
197  }
198#if H_3D_DIM_SDC
199  if( pcCU->getSDCFlag(uiAbsPartIdx) )
200  {
201    return;
202  }
203#endif
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}
217
218/** decode motion information for every PU block.
219 * \param pcCU
220 * \param uiAbsPartIdx
221 * \param uiDepth
222 * \param pcSubCU
223 * \returns Void
224 */
225Void TDecEntropy::decodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
226{
227  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
228  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
229  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
230
231#if H_3D_IV_MERGE
232  TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
233  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
234#else
235  TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
236  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
237#endif
238#if H_3D_SPIVMP
239  Bool bSPIVMPFlag[MRG_MAX_NUM_CANDS_MEM];
240  TComMvField*  pcMvFieldSP;
241  UChar* puhInterDirSP;
242  pcMvFieldSP = new TComMvField[pcCU->getPic()->getPicSym()->getNumPartition()*2]; 
243  puhInterDirSP = new UChar[pcCU->getPic()->getPicSym()->getNumPartition()]; 
244#endif
245  for ( UInt ui = 0; ui < pcCU->getSlice()->getMaxNumMergeCand(); ui++ )
246  {
247    uhInterDirNeighbours[ui] = 0;
248  }
249  Int numValidMergeCand = 0;
250  Bool isMerged = false;
251
252  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
253  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 );
254#if H_3D_IV_MERGE
255  pcSubCU->copyDVInfoFrom( pcCU, uiAbsPartIdx);
256#endif
257  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
258  {
259#if H_MV_ENC_DEC_TRAC
260    DTRACE_PU_S("=========== prediction_unit ===========\n")
261    // ToDo:
262    //DTRACE_PU("x0", uiLPelX)
263    //DTRACE_PU("x1", uiTPelY)
264#endif
265    decodeMergeFlag( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
266    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
267    {
268      decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, uiDepth );
269      UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
270#if H_3D_ARP
271      decodeARPW  ( pcCU, uiAbsPartIdx, uiDepth );
272#endif
273#if H_3D_IC
274      decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
275#endif
276#if H_3D_DBBP
277      if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 && pcCU->getDBBPFlag(uiAbsPartIdx) == false )
278#else
279      if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 ) 
280#endif
281      {
282        pcSubCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );
283        if ( !isMerged )
284        {
285#if H_3D_VSP
286          Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
287          memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
288          InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
289#if H_3D_SPIVMP
290          memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM);
291#endif
292          pcSubCU->initAvailableFlags();
293          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand);
294          pcSubCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo
295#if H_3D_SPIVMP
296            , bSPIVMPFlag, pcMvFieldSP, puhInterDirSP
297#endif
298            , numValidMergeCand );
299          pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
300
301          if(vspFlag[uiMergeIndex])
302          {
303            pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiSubPartIdx, uiPartIdx, uiDepth);
304          }
305#else
306#if H_3D
307          pcSubCU->initAvailableFlags();
308          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand);
309          pcSubCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
310
311#else
312          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
313#endif
314#endif
315          isMerged = true;
316        }
317        pcSubCU->setPartSizeSubParts( ePartSize, 0, uiDepth );
318      }
319      else
320      {
321        uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
322#if H_3D_VSP
323        Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
324        memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
325        InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
326#if H_3D_SPIVMP
327        memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM);
328#endif
329        pcSubCU->initAvailableFlags();
330        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
331        pcSubCU->xGetInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo
332#if H_3D_SPIVMP
333          , bSPIVMPFlag, pcMvFieldSP, puhInterDirSP
334#endif
335          ,numValidMergeCand, uiMergeIndex );
336        pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
337        if(vspFlag[uiMergeIndex])
338        {
339          pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiSubPartIdx, uiPartIdx, uiDepth);
340        }
341#else
342#if H_3D
343        pcSubCU->initAvailableFlags();
344        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
345        pcSubCU->xGetInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
346#else
347        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
348#endif
349#endif
350      }
351      pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
352
353#if H_3D_DDD
354      if( uiMergeIndex == pcSubCU->getUseDDDCandIdx() )
355      {
356          assert( pcCU->getSlice()->getViewIndex() != 0 );
357          pcCU->setUseDDD( true, uiSubPartIdx, uiPartIdx, uiDepth );
358          pcCU->setDDDepthSubParts( pcSubCU->getDDTmpDepth(),uiSubPartIdx, uiPartIdx, uiDepth );
359      }
360      else
361      {
362          pcCU->setUseDDD( false, uiSubPartIdx, uiPartIdx, uiDepth );
363      }
364#endif
365
366      TComMv cTmpMv( 0, 0 );
367      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
368      {       
369        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
370        {
371          pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
372          pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
373          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
374          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
375#if H_3D_VSP
376#if H_3D_DBBP
377          if( pcCU->getVSPFlag( uiSubPartIdx ) != 0 && !pcCU->getDBBPFlag( uiAbsPartIdx ) )
378#else
379          if( pcCU->getVSPFlag( uiSubPartIdx ) != 0 )
380#endif
381          {
382            if ( uhInterDirNeighbours[ uiMergeIndex ] & (1<<uiRefListIdx) )
383            {
384              UInt dummy;
385              Int vspSize;
386              Int width, height;
387              pcCU->getPartIndexAndSize( uiPartIdx, dummy, width, height, uiSubPartIdx, pcCU->getTotalNumPart()==256 );
388              pcCU->setMvFieldPUForVSP( pcCU, uiSubPartIdx, width, height, RefPicList( uiRefListIdx ), cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getRefIdx(), vspSize );
389              pcCU->setVSPFlag( uiSubPartIdx, vspSize );
390            }
391          }
392#endif
393        }
394      }
395#if H_3D_SPIVMP
396      pcCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth ); 
397      if (bSPIVMPFlag[uiMergeIndex] != 0)
398      {
399        Int iWidth, iHeight;
400        UInt uiIdx;
401        pcCU->getPartIndexAndSize( uiPartIdx, uiIdx, iWidth, iHeight, uiSubPartIdx, true );
402
403        UInt uiSPAddr;
404
405        Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
406
407        pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
408
409        for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++)
410        {
411          pcCU->getSPAbsPartIdx(uiSubPartIdx, iSPWidth, iSPHeight, iPartitionIdx, iNumSPInOneLine, uiSPAddr);
412          pcCU->setInterDirSP(puhInterDirSP[iPartitionIdx], uiSPAddr, iSPWidth, iSPHeight);
413          pcCU->getCUMvField( REF_PIC_LIST_0 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx], iSPWidth, iSPHeight);
414          pcCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight);
415        }
416      }
417#endif
418    }
419    else
420    {
421      decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
422      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
423      {       
424        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
425        {
426          decodeRefFrmIdxPU( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
427          decodeMvdPU      ( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
428          decodeMVPIdxPU   ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
429        }
430      }
431#if H_3D_ARP
432      decodeARPW  ( pcCU, uiAbsPartIdx, uiDepth );
433#endif
434#if H_3D_IC
435      decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
436#endif
437    }
438#if H_3D_VSP
439    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) && (pcCU->getVSPFlag(uiSubPartIdx) == 0))
440#else
441    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) )
442#endif
443    {
444      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( TComMv(0,0), ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
445      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( -1, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
446      pcCU->setInterDirSubParts( 1, uiSubPartIdx, uiPartIdx, uiDepth);
447    }
448  }
449#if H_3D_SPIVMP
450  delete[] pcMvFieldSP;
451  delete[] puhInterDirSP;
452#endif
453  return;
454}
455
456/** decode inter direction for a PU block
457 * \param pcCU
458 * \param uiAbsPartIdx
459 * \param uiDepth
460 * \param uiPartIdx
461 * \returns Void
462 */
463Void TDecEntropy::decodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx )
464{
465  UInt uiInterDir;
466
467  if ( pcCU->getSlice()->isInterP() )
468  {
469    uiInterDir = 1;
470  }
471  else
472  {
473    m_pcEntropyDecoderIf->parseInterDir( pcCU, uiInterDir, uiAbsPartIdx );
474  }
475
476  pcCU->setInterDirSubParts( uiInterDir, uiAbsPartIdx, uiPartIdx, uiDepth );
477}
478
479Void TDecEntropy::decodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
480{
481  Int iRefFrmIdx = 0;
482  Int iParseRefFrmIdx = pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList );
483
484  if ( pcCU->getSlice()->getNumRefIdx( eRefList ) > 1 && iParseRefFrmIdx )
485  {
486    m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, eRefList );
487  }
488  else if ( !iParseRefFrmIdx )
489  {
490    iRefFrmIdx = NOT_VALID;
491  }
492  else
493  {
494    iRefFrmIdx = 0;
495  }
496
497  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
498  pcCU->getCUMvField( eRefList )->setAllRefIdx( iRefFrmIdx, ePartSize, uiAbsPartIdx, uiDepth, uiPartIdx );
499}
500
501/** decode motion vector difference for a PU block
502 * \param pcCU
503 * \param uiAbsPartIdx
504 * \param uiDepth
505 * \param uiPartIdx
506 * \param eRefList
507 * \returns Void
508 */
509Void TDecEntropy::decodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
510{
511  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
512  {
513    m_pcEntropyDecoderIf->parseMvd( pcCU, uiAbsPartIdx, uiPartIdx, uiDepth, eRefList );
514  }
515}
516
517Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
518{
519  Int iMVPIdx = -1;
520
521  TComMv cZeroMv( 0, 0 );
522  TComMv cMv     = cZeroMv;
523  Int    iRefIdx = -1;
524
525  TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList );
526  AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo();
527
528  iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr);
529  cMv = cZeroMv;
530
531  if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) )
532  {
533    m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx );
534#if H_MV_ENC_DEC_TRAC
535#if ENC_DEC_TRACE
536    if ( eRefList == REF_PIC_LIST_0 )
537    {
538      DTRACE_PU("mvp_l0_flag", iMVPIdx)
539    }
540    else
541    {
542      DTRACE_PU("mvp_l1_flag", iMVPIdx)
543    }
544#endif
545#endif
546  }
547  pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo);
548  pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth);
549  pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth );
550  if ( iRefIdx >= 0 )
551  {
552    m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, cMv);
553    cMv += pcSubCUMvField->getMvd( uiPartAddr );
554  }
555
556  PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr );
557  pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx);
558}
559
560Void TDecEntropy::xDecodeTransform( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP, Int quadtreeTULog2MinSizeInCU)
561{
562  UInt uiSubdiv;
563  const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
564
565  if(uiTrIdx==0)
566  {
567    m_bakAbsPartIdxCU = uiAbsPartIdx;
568  }
569  if( uiLog2TrafoSize == 2 )
570  {
571    UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
572    if( ( uiAbsPartIdx % partNum ) == 0 )
573    {
574      m_uiBakAbsPartIdx   = uiAbsPartIdx;
575      m_uiBakChromaOffset = offsetChroma;
576    }
577  }
578  if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
579  {
580    uiSubdiv = 1;
581  }
582  else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) )
583  {
584    uiSubdiv = (uiLog2TrafoSize > quadtreeTULog2MinSizeInCU);
585  }
586  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
587  {
588    uiSubdiv = 1;
589  }
590  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
591  {
592    uiSubdiv = 0;
593  }
594  else if( uiLog2TrafoSize == quadtreeTULog2MinSizeInCU )
595  {
596    uiSubdiv = 0;
597  }
598  else
599  {
600    assert( uiLog2TrafoSize > quadtreeTULog2MinSizeInCU );
601    m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
602  }
603 
604  const UInt uiTrDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx );
605  {
606    const Bool bFirstCbfOfCU = uiTrDepth == 0;
607    if( bFirstCbfOfCU )
608    {
609      pcCU->setCbfSubParts( 0, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
610      pcCU->setCbfSubParts( 0, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
611    }
612    if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
613    {
614      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) )
615      {
616        m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth, uiDepth );
617      }
618      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) )
619      {
620        m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth, uiDepth );
621      }
622    }
623    else
624    {
625      pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
626      pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
627    }
628  }
629 
630  if( uiSubdiv )
631  {
632    UInt size;
633    width  >>= 1;
634    height >>= 1;
635    size = width*height;
636    uiTrIdx++;
637    ++uiDepth;
638    const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
639    const UInt uiStartAbsPartIdx = uiAbsPartIdx;
640    UInt uiYCbf = 0;
641    UInt uiUCbf = 0;
642    UInt uiVCbf = 0;
643   
644    for( Int i = 0; i < 4; i++ )
645    {
646      xDecodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP, quadtreeTULog2MinSizeInCU );
647      uiYCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth+1 );
648      uiUCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth+1 );
649      uiVCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth+1 );
650      uiAbsPartIdx += uiQPartNum;
651      offsetLuma += size;  offsetChroma += (size>>2);
652    }
653   
654    for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui )
655    {
656      pcCU->getCbf( TEXT_LUMA     )[uiStartAbsPartIdx + ui] |= uiYCbf << uiTrDepth;
657      pcCU->getCbf( TEXT_CHROMA_U )[uiStartAbsPartIdx + ui] |= uiUCbf << uiTrDepth;
658      pcCU->getCbf( TEXT_CHROMA_V )[uiStartAbsPartIdx + ui] |= uiVCbf << uiTrDepth;
659    }
660  }
661  else
662  {
663    assert( uiDepth >= pcCU->getDepth( uiAbsPartIdx ) );
664    pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiDepth );
665   
666#if !H_MV_ENC_DEC_TRAC
667    {
668      DTRACE_CABAC_VL( g_nSymbolCounter++ );
669      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
670      DTRACE_CABAC_V( uiAbsPartIdx );
671      DTRACE_CABAC_T( "\tdepth=" );
672      DTRACE_CABAC_V( uiDepth );
673      DTRACE_CABAC_T( "\ttrdepth=" );
674      DTRACE_CABAC_V( uiTrDepth );
675      DTRACE_CABAC_T( "\n" );
676    }
677#endif
678   
679    pcCU->setCbfSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiDepth );
680    if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
681    {
682      pcCU->setCbfSubParts( 1 << uiTrDepth, TEXT_LUMA, uiAbsPartIdx, uiDepth );
683    }
684    else
685    {
686      m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrDepth, uiDepth );
687    }
688
689
690    // transform_unit begin
691    UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA    , uiTrIdx );
692    UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
693    UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
694    if( uiLog2TrafoSize == 2 )
695    {
696      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
697      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
698      {
699        cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
700        cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
701      }
702    }
703    if ( cbfY || cbfU || cbfV )
704    {
705      // dQP: only for LCU
706      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
707      {
708        if ( bCodeDQP )
709        {
710          decodeQP( pcCU, m_bakAbsPartIdxCU);
711          bCodeDQP = false;
712        }
713      }
714    }
715    if( cbfY )
716    {
717      Int trWidth = width;
718      Int trHeight = height;
719      m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
720    }
721    if( uiLog2TrafoSize > 2 )
722    {
723      Int trWidth = width >> 1;
724      Int trHeight = height >> 1;
725      if( cbfU )
726      {
727        m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
728      }
729      if( cbfV )
730      {
731        m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
732      }
733    }
734    else
735    {
736      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
737      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
738      {
739        Int trWidth = width;
740        Int trHeight = height;
741        if( cbfU )
742        {
743          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
744        }
745        if( cbfV )
746        {
747          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
748        }
749      }
750    }
751    // transform_unit end
752  }
753}
754
755Void TDecEntropy::decodeQP          ( TComDataCU* pcCU, UInt uiAbsPartIdx )
756{
757  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
758  {
759    m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
760  }
761}
762
763
764/** decode coefficients
765 * \param pcCU
766 * \param uiAbsPartIdx
767 * \param uiDepth
768 * \param uiWidth
769 * \param uiHeight
770 * \returns Void
771 */
772Void TDecEntropy::decodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
773{
774  UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
775  UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
776  UInt uiChromaOffset = uiLumaOffset>>2;
777#if H_3D_DIM_SDC
778  if( pcCU->getSDCFlag( uiAbsPartIdx ) && pcCU->isIntra( uiAbsPartIdx) )
779  {
780    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
781    assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 );
782    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 );
783    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
784    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
785  }
786
787#if H_3D_INTER_SDC
788  if( pcCU->getSDCFlag( uiAbsPartIdx ) && !pcCU->isIntra( uiAbsPartIdx) )
789  {
790    assert( !pcCU->isSkipped( uiAbsPartIdx ) );
791    assert( !pcCU->isIntra( uiAbsPartIdx) );
792    assert( pcCU->getSlice()->getIsDepth() );
793  }
794#endif
795  if( pcCU->getSlice()->getIsDepth() && ( pcCU->getSDCFlag( uiAbsPartIdx ) || pcCU->isIntra( uiAbsPartIdx ) ) )
796  {
797    Int iPartNum = ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) ? 4 : 1;
798    UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth( uiAbsPartIdx ) << 1 ) ) >> 2;
799 
800    if( !pcCU->getSDCFlag( uiAbsPartIdx ) )
801    {
802      for( Int iPart = 0; iPart < iPartNum; iPart++ )
803      {
804        if( getDimType( pcCU->getLumaIntraDir( uiAbsPartIdx + uiPartOffset*iPart ) ) < DIM_NUM_TYPE ) 
805        {
806          m_pcEntropyDecoderIf->parseDeltaDC( pcCU, uiAbsPartIdx + uiPartOffset*iPart, uiDepth + ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) );
807        }
808      }
809    }
810    else
811    {
812      m_pcEntropyDecoderIf->parseDeltaDC( pcCU, uiAbsPartIdx, uiDepth );
813      return;
814    }
815  }
816#endif
817
818  if( pcCU->isIntra(uiAbsPartIdx) )
819  {
820  }
821  else
822  {
823    UInt uiQtRootCbf = 1;
824    if( !( pcCU->getPartitionSize( uiAbsPartIdx) == SIZE_2Nx2N && pcCU->getMergeFlag( uiAbsPartIdx ) ) )
825    {
826      m_pcEntropyDecoderIf->parseQtRootCbf( uiAbsPartIdx, uiQtRootCbf );
827    }
828    if ( !uiQtRootCbf )
829    {
830      pcCU->setCbfSubParts( 0, 0, 0, uiAbsPartIdx, uiDepth );
831      pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth );
832      return;
833    }
834   
835  }
836
837  Int getQuadtreeTULog2MinSizeInCU = pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx);
838
839  xDecodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP, getQuadtreeTULog2MinSizeInCU );
840}
841
842#if H_3D_INTER_SDC
843Void TDecEntropy::decodeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
844{
845  pcCU->setSDCFlagSubParts( false, uiAbsPartIdx, uiDepth );
846
847  if( ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) ) || 
848    ( pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getVPS()->getVpsDepthModesFlag( pcCU->getSlice()->getLayerIdInVps() ) ) )
849  {
850    return;
851  }
852
853  if( !pcCU->getSlice()->getIsDepth() || pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_2Nx2N || pcCU->isSkipped( uiAbsPartIdx ) )
854  {
855    return;
856  }
857
858  assert( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N || ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->isSkipped( uiAbsPartIdx ) ) );
859  m_pcEntropyDecoderIf->parseSDCFlag( pcCU, uiAbsPartIdx, uiDepth );
860}
861#endif
862#if H_3D_DBBP
863Void TDecEntropy::decodeDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
864{
865  m_pcEntropyDecoderIf->parseDBBPFlag( pcCU, uiAbsPartIdx, uiDepth );
866}
867#endif
868
869//! \}
Note: See TracBrowser for help on using the repository browser.