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

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

Merged branches/HTM-12.1-dev0@1083.

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