source: 3DVCSoftware/branches/HTM-12.2-dev1-Sharp/source/Lib/TLibDecoder/TDecEntropy.cpp @ 1417

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

Integration of JCT3V-J0060. The MACRO is "MTK_SINGLE_DEPTH_VPS_FLAG_J0060".

By YiWen Chen (yiwen.chen@…)

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