source: 3DVCSoftware/branches/HTM-9.0-Fix/source/Lib/TLibDecoder/TDecEntropy.cpp @ 728

Last change on this file since 728 was 728, checked in by mediatek-htm, 10 years ago

One added macro is “MTK_F0110_FIX”.
The added macro disabled sub-PU IVMP for depth and fixed some delete problems.

  • Property svn:eol-style set to native
File size: 28.5 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#if MTK_F0110_FIX
405  delete[] pcMvFieldSP;
406  delete[] puhInterDirSP;
407#else
408  delete pcMvFieldSP;
409  delete puhInterDirSP;
410#endif
411#endif
412  return;
413}
414
415/** decode inter direction for a PU block
416 * \param pcCU
417 * \param uiAbsPartIdx
418 * \param uiDepth
419 * \param uiPartIdx
420 * \returns Void
421 */
422Void TDecEntropy::decodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx )
423{
424  UInt uiInterDir;
425
426  if ( pcCU->getSlice()->isInterP() )
427  {
428    uiInterDir = 1;
429  }
430  else
431  {
432    m_pcEntropyDecoderIf->parseInterDir( pcCU, uiInterDir, uiAbsPartIdx );
433  }
434
435  pcCU->setInterDirSubParts( uiInterDir, uiAbsPartIdx, uiPartIdx, uiDepth );
436}
437
438Void TDecEntropy::decodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
439{
440  Int iRefFrmIdx = 0;
441  Int iParseRefFrmIdx = pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList );
442
443  if ( pcCU->getSlice()->getNumRefIdx( eRefList ) > 1 && iParseRefFrmIdx )
444  {
445    m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, eRefList );
446  }
447  else if ( !iParseRefFrmIdx )
448  {
449    iRefFrmIdx = NOT_VALID;
450  }
451  else
452  {
453    iRefFrmIdx = 0;
454  }
455
456  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
457  pcCU->getCUMvField( eRefList )->setAllRefIdx( iRefFrmIdx, ePartSize, uiAbsPartIdx, uiDepth, uiPartIdx );
458}
459
460/** decode motion vector difference for a PU block
461 * \param pcCU
462 * \param uiAbsPartIdx
463 * \param uiDepth
464 * \param uiPartIdx
465 * \param eRefList
466 * \returns Void
467 */
468Void TDecEntropy::decodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
469{
470  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
471  {
472    m_pcEntropyDecoderIf->parseMvd( pcCU, uiAbsPartIdx, uiPartIdx, uiDepth, eRefList );
473  }
474}
475
476Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
477{
478  Int iMVPIdx = -1;
479
480  TComMv cZeroMv( 0, 0 );
481  TComMv cMv     = cZeroMv;
482  Int    iRefIdx = -1;
483
484  TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList );
485  AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo();
486
487  iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr);
488  cMv = cZeroMv;
489
490  if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) )
491  {
492    m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx );
493#if H_MV_ENC_DEC_TRAC
494#if ENC_DEC_TRACE
495    if ( eRefList == REF_PIC_LIST_0 )
496    {
497      DTRACE_PU("mvp_l0_flag", iMVPIdx)
498    }
499    else
500    {
501      DTRACE_PU("mvp_l1_flag", iMVPIdx)
502    }
503#endif
504#endif
505  }
506  pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo);
507  pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth);
508  pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth );
509  if ( iRefIdx >= 0 )
510  {
511    m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, cMv);
512    cMv += pcSubCUMvField->getMvd( uiPartAddr );
513  }
514
515  PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr );
516  pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx);
517}
518
519Void TDecEntropy::xDecodeTransform( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP)
520{
521  UInt uiSubdiv;
522  const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
523
524  if(uiTrIdx==0)
525  {
526    m_bakAbsPartIdxCU = uiAbsPartIdx;
527  }
528  if( uiLog2TrafoSize == 2 )
529  {
530    UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
531    if( ( uiAbsPartIdx % partNum ) == 0 )
532    {
533      m_uiBakAbsPartIdx   = uiAbsPartIdx;
534      m_uiBakChromaOffset = offsetChroma;
535    }
536  }
537  if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
538  {
539    uiSubdiv = 1;
540  }
541  else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) )
542  {
543    uiSubdiv = (uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx));
544  }
545  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
546  {
547    uiSubdiv = 1;
548  }
549  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
550  {
551    uiSubdiv = 0;
552  }
553  else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
554  {
555    uiSubdiv = 0;
556  }
557  else
558  {
559    assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
560    m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
561  }
562 
563  const UInt uiTrDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx );
564  {
565    const Bool bFirstCbfOfCU = uiTrDepth == 0;
566    if( bFirstCbfOfCU )
567    {
568      pcCU->setCbfSubParts( 0, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
569      pcCU->setCbfSubParts( 0, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
570    }
571    if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
572    {
573      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) )
574      {
575        m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth, uiDepth );
576      }
577      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) )
578      {
579        m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth, uiDepth );
580      }
581    }
582    else
583    {
584      pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
585      pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
586    }
587  }
588 
589  if( uiSubdiv )
590  {
591    UInt size;
592    width  >>= 1;
593    height >>= 1;
594    size = width*height;
595    uiTrIdx++;
596    ++uiDepth;
597    const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
598    const UInt uiStartAbsPartIdx = uiAbsPartIdx;
599    UInt uiYCbf = 0;
600    UInt uiUCbf = 0;
601    UInt uiVCbf = 0;
602   
603    for( Int i = 0; i < 4; i++ )
604    {
605      xDecodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
606      uiYCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth+1 );
607      uiUCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth+1 );
608      uiVCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth+1 );
609      uiAbsPartIdx += uiQPartNum;
610      offsetLuma += size;  offsetChroma += (size>>2);
611    }
612   
613    for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui )
614    {
615      pcCU->getCbf( TEXT_LUMA     )[uiStartAbsPartIdx + ui] |= uiYCbf << uiTrDepth;
616      pcCU->getCbf( TEXT_CHROMA_U )[uiStartAbsPartIdx + ui] |= uiUCbf << uiTrDepth;
617      pcCU->getCbf( TEXT_CHROMA_V )[uiStartAbsPartIdx + ui] |= uiVCbf << uiTrDepth;
618    }
619  }
620  else
621  {
622    assert( uiDepth >= pcCU->getDepth( uiAbsPartIdx ) );
623    pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiDepth );
624   
625#if !H_MV_ENC_DEC_TRAC
626    {
627      DTRACE_CABAC_VL( g_nSymbolCounter++ );
628      DTRACE_CABAC_T( "\tTrIdx: abspart=" );
629      DTRACE_CABAC_V( uiAbsPartIdx );
630      DTRACE_CABAC_T( "\tdepth=" );
631      DTRACE_CABAC_V( uiDepth );
632      DTRACE_CABAC_T( "\ttrdepth=" );
633      DTRACE_CABAC_V( uiTrDepth );
634      DTRACE_CABAC_T( "\n" );
635    }
636#endif
637   
638    pcCU->setCbfSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiDepth );
639    if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
640    {
641      pcCU->setCbfSubParts( 1 << uiTrDepth, TEXT_LUMA, uiAbsPartIdx, uiDepth );
642    }
643    else
644    {
645      m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrDepth, uiDepth );
646    }
647
648
649    // transform_unit begin
650    UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA    , uiTrIdx );
651    UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
652    UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
653    if( uiLog2TrafoSize == 2 )
654    {
655      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
656      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
657      {
658        cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
659        cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
660      }
661    }
662    if ( cbfY || cbfU || cbfV )
663    {
664      // dQP: only for LCU
665      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
666      {
667        if ( bCodeDQP )
668        {
669          decodeQP( pcCU, m_bakAbsPartIdxCU);
670          bCodeDQP = false;
671        }
672      }
673    }
674    if( cbfY )
675    {
676      Int trWidth = width;
677      Int trHeight = height;
678      m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
679    }
680    if( uiLog2TrafoSize > 2 )
681    {
682      Int trWidth = width >> 1;
683      Int trHeight = height >> 1;
684      if( cbfU )
685      {
686        m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
687      }
688      if( cbfV )
689      {
690        m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
691      }
692    }
693    else
694    {
695      UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
696      if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
697      {
698        Int trWidth = width;
699        Int trHeight = height;
700        if( cbfU )
701        {
702          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
703        }
704        if( cbfV )
705        {
706          m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
707        }
708      }
709    }
710    // transform_unit end
711  }
712}
713
714Void TDecEntropy::decodeQP          ( TComDataCU* pcCU, UInt uiAbsPartIdx )
715{
716  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
717  {
718    m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
719  }
720}
721
722
723/** decode coefficients
724 * \param pcCU
725 * \param uiAbsPartIdx
726 * \param uiDepth
727 * \param uiWidth
728 * \param uiHeight
729 * \returns Void
730 */
731Void TDecEntropy::decodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
732{
733  UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
734  UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
735  UInt uiChromaOffset = uiLumaOffset>>2;
736 
737#if H_3D_DIM_SDC
738  if( pcCU->getSDCFlag( uiAbsPartIdx ) )
739  {
740    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
741    assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 );
742    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 );
743    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
744    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
745    return;
746  }
747#endif
748 
749#if H_3D_INTER_SDC
750  if( pcCU->getInterSDCFlag( uiAbsPartIdx ) )
751  {
752    assert( !pcCU->isSkipped( uiAbsPartIdx ) );
753    assert( !pcCU->isIntra( uiAbsPartIdx) );
754    assert( pcCU->getSlice()->getIsDepth() );
755
756    decodeInterSDCResidualData( pcCU, uiAbsPartIdx, uiDepth );
757    return;
758  }
759#endif
760
761  if( pcCU->isIntra(uiAbsPartIdx) )
762  {
763  }
764  else
765  {
766    UInt uiQtRootCbf = 1;
767    if( !( pcCU->getPartitionSize( uiAbsPartIdx) == SIZE_2Nx2N && pcCU->getMergeFlag( uiAbsPartIdx ) ) )
768    {
769      m_pcEntropyDecoderIf->parseQtRootCbf( uiAbsPartIdx, uiQtRootCbf );
770    }
771    if ( !uiQtRootCbf )
772    {
773      pcCU->setCbfSubParts( 0, 0, 0, uiAbsPartIdx, uiDepth );
774      pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth );
775      return;
776    }
777   
778  }
779  xDecodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP );
780}
781
782#if H_3D_INTER_SDC
783Void TDecEntropy::decodeInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
784{
785  pcCU->setInterSDCFlagSubParts( false, uiAbsPartIdx, 0, uiDepth);
786
787  if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )
788  {
789    return;
790  }
791
792  if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || pcCU->isSkipped( uiAbsPartIdx ) )
793  {
794    return;
795  }
796
797  m_pcEntropyDecoderIf->parseInterSDCFlag( pcCU, uiAbsPartIdx, uiDepth );
798}
799
800Void TDecEntropy::decodeInterSDCResidualData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
801{
802  if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )
803  {
804    return;
805  }
806
807  if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || !pcCU->getInterSDCFlag( uiAbsPartIdx ) )
808  {
809    return;
810  }
811
812  UInt uiNumSegments = ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) ? 1 : ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 4 : 2 );
813
814  // decode residual data for each segment
815  for( UInt uiSeg = 0; uiSeg < uiNumSegments; uiSeg++ )
816  {
817    m_pcEntropyDecoderIf->parseInterSDCResidualData( pcCU, uiAbsPartIdx, uiDepth, uiSeg );
818  }
819}
820#endif
821
822//! \}
Note: See TracBrowser for help on using the repository browser.