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

Last change on this file since 691 was 655, checked in by tech, 11 years ago

Merged 8.1-Cleanup@654

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