source: 3DVCSoftware/branches/HTM-12.2-dev2-Samsung/source/Lib/TLibDecoder/TDecEntropy.cpp @ 1098

Last change on this file since 1098 was 1094, checked in by lg, 10 years ago

Integration of JCT3V-J0042. The MACRO is "LGE_DDD_REMOVAL_J0042_J0030."
Integration of JCT3V-J0046. The MACRO is "LGE_DEFAULT_DV_J0046."
Integration of JCT3V-J0050. The MACRO is "LGE_CHROMA_IC_J0050_J0034."
Integration of JCT3V-J0041. The MACRO is "LGE_SIMP_DISP_AVAIL_J0041."

By Sunmi Yoo (sunmi.yoo@…) and Junghak Nam (junghak.nam@…)

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