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

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

Merged HTM-8.2-dev0@723.

  • Property svn:eol-style set to native
File size: 28.4 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6 * Copyright (c) 2010-2013, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TDecEntropy.cpp
35    \brief    entropy decoder class
36*/
37
38#include "TDecEntropy.h"
39
40//! \ingroup TLibDecoder
41//! \{
42
43Void TDecEntropy::setEntropyDecoder         ( TDecEntropyIf* p )
44{
45  m_pcEntropyDecoderIf = p;
46}
47
48#include "TLibCommon/TComSampleAdaptiveOffset.h"
49
50Void TDecEntropy::decodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
51{
52  m_pcEntropyDecoderIf->parseSkipFlag( pcCU, uiAbsPartIdx, uiDepth );
53}
54
55Void TDecEntropy::decodeCUTransquantBypassFlag(TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
56{
57  m_pcEntropyDecoderIf->parseCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth );
58}
59
60/** decode merge flag
61 * \param pcSubCU
62 * \param uiAbsPartIdx
63 * \param uiDepth
64 * \param uiPUIdx
65 * \returns Void
66 */
67Void TDecEntropy::decodeMergeFlag( TComDataCU* pcSubCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
68{ 
69  // at least one merge candidate exists
70  m_pcEntropyDecoderIf->parseMergeFlag( pcSubCU, uiAbsPartIdx, uiDepth, uiPUIdx );
71}
72
73/** decode merge index
74 * \param pcCU
75 * \param uiPartIdx
76 * \param uiAbsPartIdx
77 * \param puhInterDirNeighbours pointer to list of inter direction from the casual neighbours
78 * \param pcMvFieldNeighbours pointer to list of motion vector field from the casual neighbours
79 * \param uiDepth
80 * \returns Void
81 */
82Void TDecEntropy::decodeMergeIndex( TComDataCU* pcCU, UInt uiPartIdx, UInt uiAbsPartIdx, UInt uiDepth )
83{
84  UInt uiMergeIndex = 0;
85  m_pcEntropyDecoderIf->parseMergeIndex( pcCU, uiMergeIndex );
86  pcCU->setMergeIndexSubParts( uiMergeIndex, uiAbsPartIdx, uiPartIdx, uiDepth );
87}
88
89#if H_3D_ARP
90Void TDecEntropy::decodeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
91{
92  if( !pcCU->getSlice()->getARPStepNum() || pcCU->isIntra( uiAbsPartIdx ) )
93  {
94    return;
95  }
96
97  if( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N )
98  {
99    pcCU->setARPWSubParts( 0 , uiAbsPartIdx, uiDepth );
100  }
101  else
102  {
103    m_pcEntropyDecoderIf->parseARPW( pcCU , uiAbsPartIdx , uiDepth );
104  }
105}
106#endif
107
108#if H_3D_IC
109Void TDecEntropy::decodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
110{
111  pcCU->setICFlagSubParts( false , uiAbsPartIdx, 0, uiDepth );
112
113#if SEC_ONLY_TEXTURE_IC_F0151
114  if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) || pcCU->getSlice()->getIsDepth() )
115#else
116  if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) )
117#endif
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
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  {
149    decodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx, uiDepth );
150#if H_3D_DIM_SDC
151    if(!pcCU->getSDCFlag(uiAbsPartIdx))
152#endif
153    decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth );
154  }
155  else                                                                // if it is Inter mode, encode motion vector and reference index
156  {
157    decodePUWise( pcCU, uiAbsPartIdx, uiDepth, pcSubCU );
158  }
159}
160
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;
174  }
175#if H_3D_DIM_SDC
176  if( pcCU->getSDCFlag(uiAbsPartIdx) )
177  {
178    return;
179  }
180#endif
181 
182  m_pcEntropyDecoderIf->parseIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
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
195/** decode motion information for every PU block.
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
208#if H_3D_IV_MERGE
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
215#if MTK_SPIVMP_F0110
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
222  for ( UInt ui = 0; ui < pcCU->getSlice()->getMaxNumMergeCand(); ui++ )
223  {
224    uhInterDirNeighbours[ui] = 0;
225  }
226  Int numValidMergeCand = 0;
227  Bool isMerged = false;
228
229  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
230  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 );
231#if H_3D_IV_MERGE
232  pcSubCU->copyDVInfoFrom( pcCU, uiAbsPartIdx);
233#endif
234  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
235  {
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)
241#endif
242    decodeMergeFlag( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
243    if ( pcCU->getMergeFlag( uiSubPartIdx ) )
244    {
245      decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, uiDepth );
246      UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
247#if LGE_SHARP_VSP_INHERIT_F0104
248#if H_3D_IC
249      decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
250#endif
251#if H_3D_ARP
252      decodeARPW  ( pcCU, uiAbsPartIdx, uiDepth );
253#endif
254#endif
255      if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 ) 
256      {
257        pcSubCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );
258        if ( !isMerged )
259        {
260#if H_3D_VSP
261          Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
262          memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
263          InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
264#if MTK_SPIVMP_F0110
265          memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM);
266#endif
267#if ETRIKHU_MERGE_REUSE_F0093
268          pcSubCU->initAvailableFlags();
269          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand);
270          pcSubCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo
271#if MTK_SPIVMP_F0110
272            , bSPIVMPFlag, pcMvFieldSP, puhInterDirSP
273#endif
274            , numValidMergeCand );
275#else
276          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo, numValidMergeCand );
277#endif
278          pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
279
280          if(vspFlag[uiMergeIndex])
281          {
282            pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiSubPartIdx, uiPartIdx, uiDepth);
283          }
284#else
285#if ETRIKHU_MERGE_REUSE_F0093
286          pcSubCU->initAvailableFlags();
287          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand);
288          pcSubCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
289
290#else
291          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
292#endif
293#endif
294          isMerged = true;
295        }
296        pcSubCU->setPartSizeSubParts( ePartSize, 0, uiDepth );
297      }
298      else
299      {
300        uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
301#if H_3D_VSP
302        Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
303        memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
304        InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
305#if MTK_SPIVMP_F0110
306        memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM);
307#endif
308#if ETRIKHU_MERGE_REUSE_F0093
309        pcSubCU->initAvailableFlags();
310        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
311        pcSubCU->xGetInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo
312#if MTK_SPIVMP_F0110
313          , bSPIVMPFlag, pcMvFieldSP, puhInterDirSP
314#endif
315          ,numValidMergeCand, uiMergeIndex );
316#else
317        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo,numValidMergeCand, uiMergeIndex );
318#endif
319        pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
320        if(vspFlag[uiMergeIndex])
321        {
322          pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiSubPartIdx, uiPartIdx, uiDepth);
323        }
324#else
325#if ETRIKHU_MERGE_REUSE_F0093
326        pcSubCU->initAvailableFlags();
327        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
328        pcSubCU->xGetInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
329#else
330        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
331#endif
332#endif
333      }
334      pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
335
336      TComMv cTmpMv( 0, 0 );
337      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
338      {       
339        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
340        {
341          pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
342          pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
343          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
344          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
345        }
346      }
347#if MTK_SPIVMP_F0110
348      pcCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth ); 
349      if (bSPIVMPFlag[uiMergeIndex] != 0)
350      {
351        Int iWidth, iHeight;
352        UInt uiIdx;
353        pcCU->getPartIndexAndSize( uiPartIdx, uiIdx, iWidth, iHeight, uiSubPartIdx, true );
354
355        UInt uiSPAddr;
356
357        Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
358
359        pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
360
361        for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++)
362        {
363          pcCU->getSPAbsPartIdx(uiSubPartIdx, iSPWidth, iSPHeight, iPartitionIdx, iNumSPInOneLine, uiSPAddr);
364          pcCU->setInterDirSP(puhInterDirSP[iPartitionIdx], uiSPAddr, iSPWidth, iSPHeight);
365          pcCU->getCUMvField( REF_PIC_LIST_0 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx], iSPWidth, iSPHeight);
366          pcCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight);
367        }
368      }
369#endif
370    }
371    else
372    {
373      decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
374      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
375      {       
376        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
377        {
378          decodeRefFrmIdxPU( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
379          decodeMvdPU      ( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
380          decodeMVPIdxPU   ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
381        }
382      }
383#if LGE_SHARP_VSP_INHERIT_F0104
384#if H_3D_IC
385      decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
386#endif
387#if H_3D_ARP
388      decodeARPW  ( pcCU, uiAbsPartIdx, uiDepth );
389#endif
390#endif
391    }
392#if H_3D_VSP
393    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) && (pcCU->getVSPFlag(uiSubPartIdx) == false))
394#else
395    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) )
396#endif
397    {
398      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( TComMv(0,0), ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
399      pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( -1, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
400      pcCU->setInterDirSubParts( 1, uiSubPartIdx, uiPartIdx, uiDepth);
401    }
402  }
403#if MTK_SPIVMP_F0110
404  delete pcMvFieldSP;
405  delete puhInterDirSP;
406#endif
407  return;
408}
409
410/** decode inter direction for a PU block
411 * \param pcCU
412 * \param uiAbsPartIdx
413 * \param uiDepth
414 * \param uiPartIdx
415 * \returns Void
416 */
417Void TDecEntropy::decodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx )
418{
419  UInt uiInterDir;
420
421  if ( pcCU->getSlice()->isInterP() )
422  {
423    uiInterDir = 1;
424  }
425  else
426  {
427    m_pcEntropyDecoderIf->parseInterDir( pcCU, uiInterDir, uiAbsPartIdx );
428  }
429
430  pcCU->setInterDirSubParts( uiInterDir, uiAbsPartIdx, uiPartIdx, uiDepth );
431}
432
433Void TDecEntropy::decodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
434{
435  Int iRefFrmIdx = 0;
436  Int iParseRefFrmIdx = pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList );
437
438  if ( pcCU->getSlice()->getNumRefIdx( eRefList ) > 1 && iParseRefFrmIdx )
439  {
440    m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, eRefList );
441  }
442  else if ( !iParseRefFrmIdx )
443  {
444    iRefFrmIdx = NOT_VALID;
445  }
446  else
447  {
448    iRefFrmIdx = 0;
449  }
450
451  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
452  pcCU->getCUMvField( eRefList )->setAllRefIdx( iRefFrmIdx, ePartSize, uiAbsPartIdx, uiDepth, uiPartIdx );
453}
454
455/** decode motion vector difference for a PU block
456 * \param pcCU
457 * \param uiAbsPartIdx
458 * \param uiDepth
459 * \param uiPartIdx
460 * \param eRefList
461 * \returns Void
462 */
463Void TDecEntropy::decodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
464{
465  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
466  {
467    m_pcEntropyDecoderIf->parseMvd( pcCU, uiAbsPartIdx, uiPartIdx, uiDepth, eRefList );
468  }
469}
470
471Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
472{
473  Int iMVPIdx = -1;
474
475  TComMv cZeroMv( 0, 0 );
476  TComMv cMv     = cZeroMv;
477  Int    iRefIdx = -1;
478
479  TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList );
480  AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo();
481
482  iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr);
483  cMv = cZeroMv;
484
485  if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) )
486  {
487    m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx );
488#if H_MV_ENC_DEC_TRAC
489#if ENC_DEC_TRACE
490    if ( eRefList == REF_PIC_LIST_0 )
491    {
492      DTRACE_PU("mvp_l0_flag", iMVPIdx)
493    }
494    else
495    {
496      DTRACE_PU("mvp_l1_flag", iMVPIdx)
497    }
498#endif
499#endif
500  }
501  pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo);
502  pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth);
503  pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth );
504  if ( iRefIdx >= 0 )
505  {
506    m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, cMv);
507    cMv += pcSubCUMvField->getMvd( uiPartAddr );
508  }
509
510  PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr );
511  pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx);
512}
513
514Void TDecEntropy::xDecodeTransform( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP)
515{
516  UInt uiSubdiv;
517  const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
518
519  if(uiTrIdx==0)
520  {
521    m_bakAbsPartIdxCU = uiAbsPartIdx;
522  }
523  if( uiLog2TrafoSize == 2 )
524  {
525    UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
526    if( ( uiAbsPartIdx % partNum ) == 0 )
527    {
528      m_uiBakAbsPartIdx   = uiAbsPartIdx;
529      m_uiBakChromaOffset = offsetChroma;
530    }
531  }
532  if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
533  {
534    uiSubdiv = 1;
535  }
536  else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) )
537  {
538    uiSubdiv = (uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx));
539  }
540  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
541  {
542    uiSubdiv = 1;
543  }
544  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
545  {
546    uiSubdiv = 0;
547  }
548  else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
549  {
550    uiSubdiv = 0;
551  }
552  else
553  {
554    assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
555    m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
556  }
557 
558  const UInt uiTrDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx );
559  {
560    const Bool bFirstCbfOfCU = uiTrDepth == 0;
561    if( bFirstCbfOfCU )
562    {
563      pcCU->setCbfSubParts( 0, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
564      pcCU->setCbfSubParts( 0, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
565    }
566    if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
567    {
568      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) )
569      {
570        m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth, uiDepth );
571      }
572      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) )
573      {
574        m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth, uiDepth );
575      }
576    }
577    else
578    {
579      pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
580      pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
581    }
582  }
583 
584  if( uiSubdiv )
585  {
586    UInt size;
587    width  >>= 1;
588    height >>= 1;
589    size = width*height;
590    uiTrIdx++;
591    ++uiDepth;
592    const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
593    const UInt uiStartAbsPartIdx = uiAbsPartIdx;
594    UInt uiYCbf = 0;
595    UInt uiUCbf = 0;
596    UInt uiVCbf = 0;
597   
598    for( Int i = 0; i < 4; i++ )
599    {
600      xDecodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
601      uiYCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth+1 );
602      uiUCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth+1 );
603      uiVCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth+1 );
604      uiAbsPartIdx += uiQPartNum;
605      offsetLuma += size;  offsetChroma += (size>>2);
606    }
607   
608    for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui )
609    {
610      pcCU->getCbf( TEXT_LUMA     )[uiStartAbsPartIdx + ui] |= uiYCbf << uiTrDepth;
611      pcCU->getCbf( TEXT_CHROMA_U )[uiStartAbsPartIdx + ui] |= uiUCbf << uiTrDepth;
612      pcCU->getCbf( TEXT_CHROMA_V )[uiStartAbsPartIdx + ui] |= uiVCbf << uiTrDepth;
613    }
614  }
615  else
616  {
617    assert( uiDepth >= pcCU->getDepth( uiAbsPartIdx ) );
618    pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiDepth );
619   
620#if !H_MV_ENC_DEC_TRAC
621    {
622      DTRACE_CABAC_VL( g_nSymbolCounter++ );
623      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
624      DTRACE_CABAC_V( uiAbsPartIdx );
625      DTRACE_CABAC_T( "\tdepth=" );
626      DTRACE_CABAC_V( uiDepth );
627      DTRACE_CABAC_T( "\ttrdepth=" );
628      DTRACE_CABAC_V( uiTrDepth );
629      DTRACE_CABAC_T( "\n" );
630    }
631#endif
632   
633    pcCU->setCbfSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiDepth );
634    if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
635    {
636      pcCU->setCbfSubParts( 1 << uiTrDepth, TEXT_LUMA, uiAbsPartIdx, uiDepth );
637    }
638    else
639    {
640      m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrDepth, uiDepth );
641    }
642
643
644    // transform_unit begin
645    UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA    , uiTrIdx );
646    UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
647    UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
648    if( uiLog2TrafoSize == 2 )
649    {
650      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
651      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
652      {
653        cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
654        cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
655      }
656    }
657    if ( cbfY || cbfU || cbfV )
658    {
659      // dQP: only for LCU
660      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
661      {
662        if ( bCodeDQP )
663        {
664          decodeQP( pcCU, m_bakAbsPartIdxCU);
665          bCodeDQP = false;
666        }
667      }
668    }
669    if( cbfY )
670    {
671      Int trWidth = width;
672      Int trHeight = height;
673      m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
674    }
675    if( uiLog2TrafoSize > 2 )
676    {
677      Int trWidth = width >> 1;
678      Int trHeight = height >> 1;
679      if( cbfU )
680      {
681        m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
682      }
683      if( cbfV )
684      {
685        m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
686      }
687    }
688    else
689    {
690      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
691      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
692      {
693        Int trWidth = width;
694        Int trHeight = height;
695        if( cbfU )
696        {
697          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
698        }
699        if( cbfV )
700        {
701          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
702        }
703      }
704    }
705    // transform_unit end
706  }
707}
708
709Void TDecEntropy::decodeQP          ( TComDataCU* pcCU, UInt uiAbsPartIdx )
710{
711  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
712  {
713    m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
714  }
715}
716
717
718/** decode coefficients
719 * \param pcCU
720 * \param uiAbsPartIdx
721 * \param uiDepth
722 * \param uiWidth
723 * \param uiHeight
724 * \returns Void
725 */
726Void TDecEntropy::decodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
727{
728  UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
729  UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
730  UInt uiChromaOffset = uiLumaOffset>>2;
731 
732#if H_3D_DIM_SDC
733  if( pcCU->getSDCFlag( uiAbsPartIdx ) )
734  {
735    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
736    assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 );
737    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 );
738    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
739    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
740    return;
741  }
742#endif
743 
744#if H_3D_INTER_SDC
745  if( pcCU->getInterSDCFlag( uiAbsPartIdx ) )
746  {
747    assert( !pcCU->isSkipped( uiAbsPartIdx ) );
748    assert( !pcCU->isIntra( uiAbsPartIdx) );
749    assert( pcCU->getSlice()->getIsDepth() );
750
751    decodeInterSDCResidualData( pcCU, uiAbsPartIdx, uiDepth );
752    return;
753  }
754#endif
755
756  if( pcCU->isIntra(uiAbsPartIdx) )
757  {
758  }
759  else
760  {
761    UInt uiQtRootCbf = 1;
762    if( !( pcCU->getPartitionSize( uiAbsPartIdx) == SIZE_2Nx2N && pcCU->getMergeFlag( uiAbsPartIdx ) ) )
763    {
764      m_pcEntropyDecoderIf->parseQtRootCbf( uiAbsPartIdx, uiQtRootCbf );
765    }
766    if ( !uiQtRootCbf )
767    {
768      pcCU->setCbfSubParts( 0, 0, 0, uiAbsPartIdx, uiDepth );
769      pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth );
770      return;
771    }
772   
773  }
774  xDecodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP );
775}
776
777#if H_3D_INTER_SDC
778Void TDecEntropy::decodeInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
779{
780  pcCU->setInterSDCFlagSubParts( false, uiAbsPartIdx, 0, uiDepth);
781
782  if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )
783  {
784    return;
785  }
786
787  if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || pcCU->isSkipped( uiAbsPartIdx ) )
788  {
789    return;
790  }
791
792  m_pcEntropyDecoderIf->parseInterSDCFlag( pcCU, uiAbsPartIdx, uiDepth );
793}
794
795Void TDecEntropy::decodeInterSDCResidualData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
796{
797  if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )
798  {
799    return;
800  }
801
802  if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || !pcCU->getInterSDCFlag( uiAbsPartIdx ) )
803  {
804    return;
805  }
806
807  UInt uiNumSegments = ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) ? 1 : ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 4 : 2 );
808
809  // decode residual data for each segment
810  for( UInt uiSeg = 0; uiSeg < uiNumSegments; uiSeg++ )
811  {
812    m_pcEntropyDecoderIf->parseInterSDCResidualData( pcCU, uiAbsPartIdx, uiDepth, uiSeg );
813  }
814}
815#endif
816
817//! \}
Note: See TracBrowser for help on using the repository browser.