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

Last change on this file since 789 was 785, checked in by samsung-htm, 11 years ago

Integration of JCT3V-G0072: IC and ARP Flags Signaling

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