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

Last change on this file since 1100 was 1100, checked in by samsung-htm, 9 years ago

Integration of JCT3V-J0037 (Item1 and Item4)

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