source: 3DVCSoftware/branches/HTM-14.1-update-dev4-RWTH/source/Lib/TLibDecoder/TDecSbac.cpp @ 1229

Last change on this file since 1229 was 1229, checked in by rwth, 9 years ago
  • fixed some compiler warnings
  • Property svn:eol-style set to native
File size: 88.2 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
[1200]4 * granted under this license.
[5]5 *
[1200]6 * Copyright (c) 2010-2015, 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     TDecSbac.cpp
35    \brief    Context-adaptive entropy decoder class
36*/
37
38#include "TDecSbac.h"
[1200]39#include "TLibCommon/TComTU.h"
40#include "TLibCommon/TComTrQuant.h"
[2]41
[1200]42#if RExt__DECODER_DEBUG_BIT_STATISTICS
43#include "TLibCommon/TComCodingStatistics.h"
44//
45#define RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(a) , a
46#else
47#define RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(a)
48#endif
49
[56]50//! \ingroup TLibDecoder
51//! \{
52
[1200]53#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
54#include "../TLibCommon/Debug.h"
55#endif
56
57
[2]58//////////////////////////////////////////////////////////////////////
59// Construction/Destruction
60//////////////////////////////////////////////////////////////////////
61
[1200]62TDecSbac::TDecSbac()
[2]63// new structure here
[1200]64: m_pcBitstream                              ( 0 )
65, m_pcTDecBinIf                              ( NULL )
66, m_numContextModels                         ( 0 )
67, m_cCUSplitFlagSCModel                      ( 1,             1,                      NUM_SPLIT_FLAG_CTX                   , m_contextModels + m_numContextModels, m_numContextModels)
68, m_cCUSkipFlagSCModel                       ( 1,             1,                      NUM_SKIP_FLAG_CTX                    , m_contextModels + m_numContextModels, m_numContextModels)
[1196]69#if H_3D
[1179]70, m_cCUDISFlagSCModel         ( 1,             1,               NUM_DIS_FLAG_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
71, m_cCUDISTypeSCModel         ( 1,             1,               NUM_DIS_TYPE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
[1039]72#endif
[1200]73, m_cCUMergeFlagExtSCModel                   ( 1,             1,                      NUM_MERGE_FLAG_EXT_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
74, m_cCUMergeIdxExtSCModel                    ( 1,             1,                      NUM_MERGE_IDX_EXT_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
[608]75#if H_3D_ARP
76, m_cCUPUARPWSCModel          ( 1,             1,               NUM_ARPW_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
[2]77#endif
[608]78#if H_3D_IC
79, m_cCUICFlagSCModel          ( 1,             1,               NUM_IC_FLAG_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
[443]80#endif
[1200]81, m_cCUPartSizeSCModel                       ( 1,             1,                      NUM_PART_SIZE_CTX                    , m_contextModels + m_numContextModels, m_numContextModels)
82, m_cCUPredModeSCModel                       ( 1,             1,                      NUM_PRED_MODE_CTX                    , m_contextModels + m_numContextModels, m_numContextModels)
83, m_cCUIntraPredSCModel                      ( 1,             1,                      NUM_INTRA_PREDICT_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
84, m_cCUChromaPredSCModel                     ( 1,             1,                      NUM_CHROMA_PRED_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
85, m_cCUDeltaQpSCModel                        ( 1,             1,                      NUM_DELTA_QP_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
86, m_cCUInterDirSCModel                       ( 1,             1,                      NUM_INTER_DIR_CTX                    , m_contextModels + m_numContextModels, m_numContextModels)
87, m_cCURefPicSCModel                         ( 1,             1,                      NUM_REF_NO_CTX                       , m_contextModels + m_numContextModels, m_numContextModels)
88, m_cCUMvdSCModel                            ( 1,             1,                      NUM_MV_RES_CTX                       , m_contextModels + m_numContextModels, m_numContextModels)
89, m_cCUQtCbfSCModel                          ( 1,             NUM_QT_CBF_CTX_SETS,    NUM_QT_CBF_CTX_PER_SET               , m_contextModels + m_numContextModels, m_numContextModels)
90, m_cCUTransSubdivFlagSCModel                ( 1,             1,                      NUM_TRANS_SUBDIV_FLAG_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
91, m_cCUQtRootCbfSCModel                      ( 1,             1,                      NUM_QT_ROOT_CBF_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
92, m_cCUSigCoeffGroupSCModel                  ( 1,             2,                      NUM_SIG_CG_FLAG_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
93, m_cCUSigSCModel                            ( 1,             1,                      NUM_SIG_FLAG_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
94, m_cCuCtxLastX                              ( 1,             NUM_CTX_LAST_FLAG_SETS, NUM_CTX_LAST_FLAG_XY                 , m_contextModels + m_numContextModels, m_numContextModels)
95, m_cCuCtxLastY                              ( 1,             NUM_CTX_LAST_FLAG_SETS, NUM_CTX_LAST_FLAG_XY                 , m_contextModels + m_numContextModels, m_numContextModels)
96, m_cCUOneSCModel                            ( 1,             1,                      NUM_ONE_FLAG_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
97, m_cCUAbsSCModel                            ( 1,             1,                      NUM_ABS_FLAG_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
98, m_cMVPIdxSCModel                           ( 1,             1,                      NUM_MVP_IDX_CTX                      , m_contextModels + m_numContextModels, m_numContextModels)
99, m_cSaoMergeSCModel                         ( 1,             1,                      NUM_SAO_MERGE_FLAG_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
100, m_cSaoTypeIdxSCModel                       ( 1,             1,                      NUM_SAO_TYPE_IDX_CTX                 , m_contextModels + m_numContextModels, m_numContextModels)
101, m_cTransformSkipSCModel                    ( 1,             MAX_NUM_CHANNEL_TYPE,   NUM_TRANSFORMSKIP_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
102, m_CUTransquantBypassFlagSCModel            ( 1,             1,                      NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX    , m_contextModels + m_numContextModels, m_numContextModels)
103, m_explicitRdpcmFlagSCModel                 ( 1,             MAX_NUM_CHANNEL_TYPE,   NUM_EXPLICIT_RDPCM_FLAG_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
104, m_explicitRdpcmDirSCModel                  ( 1,             MAX_NUM_CHANNEL_TYPE,   NUM_EXPLICIT_RDPCM_DIR_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
105, m_cCrossComponentPredictionSCModel         ( 1,             1,                      NUM_CROSS_COMPONENT_PREDICTION_CTX   , m_contextModels + m_numContextModels, m_numContextModels)
106, m_ChromaQpAdjFlagSCModel                   ( 1,             1,                      NUM_CHROMA_QP_ADJ_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
107, m_ChromaQpAdjIdcSCModel                    ( 1,             1,                      NUM_CHROMA_QP_ADJ_IDC_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
[608]108#if H_3D_DIM
109, m_cDepthIntraModeSCModel    ( 1,             1,               NUM_DEPTH_INTRA_MODE_CTX      , m_contextModels + m_numContextModels, m_numContextModels)
110, m_cDdcFlagSCModel           ( 1,             1,               NUM_DDC_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
111, m_cDdcDataSCModel           ( 1,             1,               NUM_DDC_DATA_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
[833]112, m_cAngleFlagSCModel         ( 1,             1,               NUM_ANGLE_FLAG_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
[608]113#if H_3D_DIM_SDC
114, m_cSDCResidualFlagSCModel     ( 1,             1,             SDC_NUM_RESIDUAL_FLAG_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
115, m_cSDCResidualSCModel         ( 1,             1,             SDC_NUM_RESIDUAL_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
[100]116#endif
117#endif
[884]118#if H_3D_DIM_SDC
[833]119, m_cSDCFlagSCModel                  ( 1,             1,  NUM_SDC_FLAG_CTX                 , m_contextModels + m_numContextModels, m_numContextModels)
120#endif
[1222]121#if NH_3D_DBBP
[833]122, m_cDBBPFlagSCModel             ( 1,             1,                 DBBP_NUM_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
123#endif
[1200]124
[2]125{
[56]126  assert( m_numContextModels <= MAX_NUM_CTX_MOD );
[2]127}
128
129TDecSbac::~TDecSbac()
130{
131}
132
133// ====================================================================================================================
134// Public member functions
135// ====================================================================================================================
136
[56]137Void TDecSbac::resetEntropy(TComSlice* pSlice)
[2]138{
[56]139  SliceType sliceType  = pSlice->getSliceType();
140  Int       qp         = pSlice->getSliceQp();
141
142  if (pSlice->getPPS()->getCabacInitPresentFlag() && pSlice->getCabacInitFlag())
143  {
144    switch (sliceType)
145    {
146    case P_SLICE:           // change initialization table to B_SLICE initialization
[1200]147      sliceType = B_SLICE;
[56]148      break;
149    case B_SLICE:           // change initialization table to P_SLICE initialization
[1200]150      sliceType = P_SLICE;
[56]151      break;
152    default     :           // should not occur
153      assert(0);
[1200]154      break;
[56]155    }
156  }
157
[1200]158  m_cCUSplitFlagSCModel.initBuffer                ( sliceType, qp, (UChar*)INIT_SPLIT_FLAG );
159  m_cCUSkipFlagSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_SKIP_FLAG );
[1196]160#if H_3D
[1179]161  m_cCUDISFlagSCModel.initBuffer         ( sliceType, qp, (UChar*)INIT_DIS_FLAG );
162  m_cCUDISTypeSCModel.initBuffer         ( sliceType, qp, (UChar*)INIT_DIS_TYPE );
[1039]163#endif
[1200]164  m_cCUMergeFlagExtSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT );
165  m_cCUMergeIdxExtSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_MERGE_IDX_EXT );
[608]166#if H_3D_ARP
167  m_cCUPUARPWSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_ARPW );
[2]168#endif
[608]169#if H_3D_IC
170  m_cCUICFlagSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_IC_FLAG );
[443]171#endif
[1200]172  m_cCUPartSizeSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_PART_SIZE );
173  m_cCUPredModeSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_PRED_MODE );
174  m_cCUIntraPredSCModel.initBuffer                ( sliceType, qp, (UChar*)INIT_INTRA_PRED_MODE );
175  m_cCUChromaPredSCModel.initBuffer               ( sliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE );
176  m_cCUInterDirSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_INTER_DIR );
177  m_cCUMvdSCModel.initBuffer                      ( sliceType, qp, (UChar*)INIT_MVD );
178  m_cCURefPicSCModel.initBuffer                   ( sliceType, qp, (UChar*)INIT_REF_PIC );
179  m_cCUDeltaQpSCModel.initBuffer                  ( sliceType, qp, (UChar*)INIT_DQP );
180  m_cCUQtCbfSCModel.initBuffer                    ( sliceType, qp, (UChar*)INIT_QT_CBF );
181  m_cCUQtRootCbfSCModel.initBuffer                ( sliceType, qp, (UChar*)INIT_QT_ROOT_CBF );
182  m_cCUSigCoeffGroupSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_SIG_CG_FLAG );
183  m_cCUSigSCModel.initBuffer                      ( sliceType, qp, (UChar*)INIT_SIG_FLAG );
184  m_cCuCtxLastX.initBuffer                        ( sliceType, qp, (UChar*)INIT_LAST );
185  m_cCuCtxLastY.initBuffer                        ( sliceType, qp, (UChar*)INIT_LAST );
186  m_cCUOneSCModel.initBuffer                      ( sliceType, qp, (UChar*)INIT_ONE_FLAG );
187  m_cCUAbsSCModel.initBuffer                      ( sliceType, qp, (UChar*)INIT_ABS_FLAG );
188  m_cMVPIdxSCModel.initBuffer                     ( sliceType, qp, (UChar*)INIT_MVP_IDX );
189  m_cSaoMergeSCModel.initBuffer                   ( sliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG );
190  m_cSaoTypeIdxSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
191  m_cCUTransSubdivFlagSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
192  m_cTransformSkipSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
193  m_CUTransquantBypassFlagSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
194  m_explicitRdpcmFlagSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_EXPLICIT_RDPCM_FLAG);
195  m_explicitRdpcmDirSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_EXPLICIT_RDPCM_DIR);
196  m_cCrossComponentPredictionSCModel.initBuffer   ( sliceType, qp, (UChar*)INIT_CROSS_COMPONENT_PREDICTION );
197  m_ChromaQpAdjFlagSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_FLAG );
198  m_ChromaQpAdjIdcSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_IDC );
[608]199#if H_3D_DIM
200  m_cDepthIntraModeSCModel.initBuffer    ( sliceType, qp, (UChar*)INIT_DEPTH_INTRA_MODE );
201  m_cDdcFlagSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DDC_FLAG );
202  m_cDdcDataSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DDC_DATA );
[833]203  m_cAngleFlagSCModel.initBuffer         ( sliceType, qp, (UChar*)INIT_ANGLE_FLAG );
[608]204#if H_3D_DIM_SDC
205  m_cSDCResidualFlagSCModel.initBuffer    ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
206  m_cSDCResidualSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL );
[2]207#endif
[443]208#endif
[884]209#if H_3D_DIM_SDC
[833]210  m_cSDCFlagSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_SDC_FLAG );
211#endif
[1222]212#if NH_3D_DBBP
[833]213  m_cDBBPFlagSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_DBBP_FLAG );
214#endif
[1200]215
216  for (UInt statisticIndex = 0; statisticIndex < RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS ; statisticIndex++)
217  {
218    m_golombRiceAdaptationStatistics[statisticIndex] = 0;
219  }
220
[2]221  m_pcTDecBinIf->start();
222}
223
[1200]224Void TDecSbac::parseTerminatingBit( UInt& ruiBit )
[56]225{
[1200]226  m_pcTDecBinIf->decodeBinTrm( ruiBit );
227  if ( ruiBit == 1 )
228  {
229    m_pcTDecBinIf->finish();
230
231#if RExt__DECODER_DEBUG_BIT_STATISTICS
232    TComCodingStatistics::IncrementStatisticEP(STATS__TRAILING_BITS, m_pcBitstream->readOutTrailingBits(),0);
233#else
234    m_pcBitstream->readOutTrailingBits();
235#endif
236  }
237}
238
[1196]239#if H_3D
[1179]240  m_cCUDISFlagSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_DIS_FLAG );
241  m_cCUDISTypeSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_DIS_TYPE );
[1039]242#endif
[608]243#if H_3D_ARP
244  m_cCUPUARPWSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_ARPW );
[56]245#endif
[608]246#if H_3D_IC
247  m_cCUICFlagSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_IC_FLAG );
[443]248#endif
[608]249#if H_3D_DIM
250  m_cDepthIntraModeSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE );
251  m_cDdcFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG );
252  m_cDdcDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_DATA );
[833]253  m_cAngleFlagSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_ANGLE_FLAG );
[608]254#if H_3D_DIM_SDC
255  m_cSDCResidualFlagSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
256  m_cSDCResidualSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL );
[443]257#endif
[189]258#endif
[884]259#if H_3D_DIM_SDC
[833]260  m_cSDCFlagSCModel.initBuffer            ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG );
261#endif
[56]262
[1200]263
264Void TDecSbac::parseRemainingBytes( Bool noTrailingBytesExpected )
[56]265{
[1200]266  if (noTrailingBytesExpected)
[56]267  {
[1200]268    const UInt numberOfRemainingSubstreamBytes=m_pcBitstream->getNumBitsLeft();
269    assert (numberOfRemainingSubstreamBytes == 0);
[56]270  }
[1200]271  else
272  {
273    while (m_pcBitstream->getNumBitsLeft())
274    {
275      UInt trailingNullByte=m_pcBitstream->readByte();
276      if (trailingNullByte!=0)
277      {
278        printf("Trailing byte should be 0, but has value %02x\n", trailingNullByte);
279        assert(trailingNullByte==0);
280      }
281    }
282  }
[56]283}
284
[1200]285#if RExt__DECODER_DEBUG_BIT_STATISTICS
286Void TDecSbac::xReadUnaryMaxSymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol, const class TComCodingStatisticsClassType &whichStat )
287#else
[2]288Void TDecSbac::xReadUnaryMaxSymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol )
[1200]289#endif
[2]290{
291  if (uiMaxSymbol == 0)
292  {
293    ruiSymbol = 0;
294    return;
295  }
[1200]296
297  m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
298
[2]299  if( ruiSymbol == 0 || uiMaxSymbol == 1 )
300  {
301    return;
302  }
[1200]303
[2]304  UInt uiSymbol = 0;
305  UInt uiCont;
[1200]306
[2]307  do
308  {
[1200]309    m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
[2]310    uiSymbol++;
[1200]311  } while( uiCont && ( uiSymbol < uiMaxSymbol - 1 ) );
312
[2]313  if( uiCont && ( uiSymbol == uiMaxSymbol - 1 ) )
314  {
315    uiSymbol++;
316  }
[1200]317
[2]318  ruiSymbol = uiSymbol;
319}
320
[1200]321#if RExt__DECODER_DEBUG_BIT_STATISTICS
322Void TDecSbac::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount, const class TComCodingStatisticsClassType &whichStat )
323#else
[2]324Void TDecSbac::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount )
[1200]325#endif
[2]326{
327  UInt uiSymbol = 0;
328  UInt uiBit = 1;
[1200]329
[2]330  while( uiBit )
331  {
[1200]332    m_pcTDecBinIf->decodeBinEP( uiBit RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
[2]333    uiSymbol += uiBit << uiCount++;
334  }
[1200]335
[56]336  if ( --uiCount )
[2]337  {
[56]338    UInt bins;
[1200]339    m_pcTDecBinIf->decodeBinsEP( bins, uiCount RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
[56]340    uiSymbol += bins;
[2]341  }
[1200]342
[2]343  ruiSymbol = uiSymbol;
344}
345
[1200]346#if RExt__DECODER_DEBUG_BIT_STATISTICS
347Void TDecSbac::xReadUnarySymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, const class TComCodingStatisticsClassType &whichStat )
348#else
[2]349Void TDecSbac::xReadUnarySymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset )
[1200]350#endif
[2]351{
[1200]352  m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat));
353
[2]354  if( !ruiSymbol )
355  {
356    return;
357  }
[1200]358
[2]359  UInt uiSymbol = 0;
360  UInt uiCont;
[1200]361
[2]362  do
363  {
[1200]364    m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat));
[2]365    uiSymbol++;
[1200]366  } while( uiCont );
367
[2]368  ruiSymbol = uiSymbol;
369}
370
[608]371
372/** Parsing of coeff_abs_level_remaing
[1200]373 * \param rSymbol                 reference to coeff_abs_level_remaing
374 * \param rParam                  reference to parameter
375 * \param useLimitedPrefixLength
376 * \param maxLog2TrDynamicRange
[2]377 */
[1200]378#if RExt__DECODER_DEBUG_BIT_STATISTICS
379Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const Int maxLog2TrDynamicRange, const class TComCodingStatisticsClassType &whichStat )
380#else
381Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const Int maxLog2TrDynamicRange )
382#endif
[2]383{
[608]384  UInt prefix   = 0;
385  UInt codeWord = 0;
[1200]386
387  if (useLimitedPrefixLength)
[2]388  {
[1200]389    const UInt longestPossiblePrefix = (32 - (COEF_REMAIN_BIN_REDUCTION + maxLog2TrDynamicRange)) + COEF_REMAIN_BIN_REDUCTION;
390
391    do
392    {
393      prefix++;
394      m_pcTDecBinIf->decodeBinEP( codeWord RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
395    } while((codeWord != 0) && (prefix < longestPossiblePrefix));
[2]396  }
[1200]397  else
398  {
399    do
400    {
401      prefix++;
402      m_pcTDecBinIf->decodeBinEP( codeWord RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
403    } while( codeWord);
404  }
405
[608]406  codeWord  = 1 - codeWord;
407  prefix -= codeWord;
408  codeWord=0;
[1200]409
[608]410  if (prefix < COEF_REMAIN_BIN_REDUCTION )
411  {
[1200]412    m_pcTDecBinIf->decodeBinsEP(codeWord,rParam RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat));
[608]413    rSymbol = (prefix<<rParam) + codeWord;
414  }
[1200]415  else if (useLimitedPrefixLength)
416  {
417    const UInt maximumPrefixLength = (32 - (COEF_REMAIN_BIN_REDUCTION + maxLog2TrDynamicRange));
418
419    const UInt prefixLength = prefix - COEF_REMAIN_BIN_REDUCTION;
420    const UInt suffixLength = (prefixLength == maximumPrefixLength) ? (maxLog2TrDynamicRange - rParam) : prefixLength;
421
422    m_pcTDecBinIf->decodeBinsEP(codeWord, (suffixLength + rParam) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat));
423
424    rSymbol = codeWord + ((((1 << prefixLength) - 1) + COEF_REMAIN_BIN_REDUCTION) << rParam);
425  }
[608]426  else
427  {
[1200]428    m_pcTDecBinIf->decodeBinsEP(codeWord,prefix-COEF_REMAIN_BIN_REDUCTION+rParam RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat));
[608]429    rSymbol = (((1<<(prefix-COEF_REMAIN_BIN_REDUCTION))+COEF_REMAIN_BIN_REDUCTION-1)<<rParam)+codeWord;
430  }
431}
[2]432
[608]433#if H_3D_DIM
434Void TDecSbac::xReadExGolombLevel( UInt& ruiSymbol, ContextModel& rcSCModel  )
435{
436  UInt uiSymbol;
437  UInt uiCount = 0;
438  do
439  {
440    m_pcTDecBinIf->decodeBin( uiSymbol, rcSCModel );
441    uiCount++;
442  }
[950]443  while( uiSymbol && ( uiCount != 3 ) );
[608]444  ruiSymbol = uiCount - 1;
445
446  if( uiSymbol )
[2]447  {
[608]448    xReadEpExGolomb( uiSymbol, 0 );
449    ruiSymbol += uiSymbol + 1;
[2]450  }
451
[608]452  return;
453}
[2]454
[724]455Void TDecSbac::xParseDimDeltaDC( Pel& rValDeltaDC, UInt uiNumSeg )
456{
457  UInt absValDeltaDC = 0;
458  xReadExGolombLevel( absValDeltaDC, m_cDdcDataSCModel.get(0, 0, 0) );
459  rValDeltaDC = (Pel)absValDeltaDC + ( uiNumSeg > 1 ? 0 : 1 );
460
461  if( rValDeltaDC != 0 )
462  {
463    UInt uiSign;
464    m_pcTDecBinIf->decodeBinEP( uiSign );
465    if ( uiSign )
466    {
467      rValDeltaDC = -rValDeltaDC;
468    }
469  }
470}
[608]471
[724]472
[608]473#if H_3D_DIM_DMM
474Void TDecSbac::xParseDmm1WedgeIdx( UInt& ruiTabIdx, Int iNumBit )
475{
476  UInt uiSymbol, uiIdx = 0;
477  for( Int i = 0; i < iNumBit; i++ )
478  {
[976]479    m_pcTDecBinIf->decodeBinEP( uiSymbol );
[608]480    uiIdx += uiSymbol << i;
481  }
482  ruiTabIdx = uiIdx;
483}
484#endif
[2]485
[1084]486
[608]487#endif
[1200]488
489
490/** Parse I_PCM information.
[56]491 * \param pcCU
[1200]492 * \param uiAbsPartIdx
[56]493 * \param uiDepth
494 * \returns Void
495 *
[1200]496 * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes.
[56]497 */
498Void TDecSbac::parseIPCMInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
[2]499{
500  UInt uiSymbol;
[56]501
[1196]502  m_pcTDecBinIf->decodeBinTrm(uiSymbol);
[2]503
[608]504#if H_MV_ENC_DEC_TRAC
[1196]505  DTRACE_CU("pcm_flag", uiSymbol)
[608]506#endif
[1200]507
508
509  if (uiSymbol == 1)
[1196]510  {
[56]511    Bool bIpcmFlag = true;
[1200]512    const TComSPS &sps=*(pcCU->getSlice()->getSPS());
[56]513
514    pcCU->setPartSizeSubParts  ( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
[1200]515    pcCU->setSizeSubParts      ( sps.getMaxCUWidth()>>uiDepth, sps.getMaxCUHeight()>>uiDepth, uiAbsPartIdx, uiDepth );
[608]516    pcCU->setTrIdxSubParts     ( 0, uiAbsPartIdx, uiDepth );
[56]517    pcCU->setIPCMFlagSubParts  ( bIpcmFlag, uiAbsPartIdx, uiDepth );
[2]518
[1200]519    const UInt minCoeffSizeY = pcCU->getPic()->getMinCUWidth() * pcCU->getPic()->getMinCUHeight();
520    const UInt offsetY       = minCoeffSizeY * uiAbsPartIdx;
521    for (UInt ch=0; ch < pcCU->getPic()->getNumberValidComponents(); ch++)
[56]522    {
[1200]523      const ComponentID compID = ComponentID(ch);
524      const UInt offset = offsetY >> (pcCU->getPic()->getComponentScaleX(compID) + pcCU->getPic()->getComponentScaleY(compID));
525      Pel * pPCMSample  = pcCU->getPCMSample(compID) + offset;
526      const UInt width  = pcCU->getWidth (uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleX(compID);
527      const UInt height = pcCU->getHeight(uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleY(compID);
528      const UInt sampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepth(toChannelType(compID));
529      for (UInt y=0; y<height; y++)
[56]530      {
[1200]531        for (UInt x=0; x<width; x++)
[1196]532        {
[1200]533          UInt sample;
534          m_pcTDecBinIf->xReadPCMCode(sampleBits, sample);
535          pPCMSample[x] = sample;
[1196]536        }
[1200]537        pPCMSample += width;
[56]538      }
[1179]539    }
[608]540    m_pcTDecBinIf->start();
[2]541  }
542}
543
[608]544Void TDecSbac::parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
545{
546  UInt uiSymbol;
[1200]547  m_pcTDecBinIf->decodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__TQ_BYPASS_FLAG) );
[608]548#if H_MV_ENC_DEC_TRAC
549  DTRACE_CU("cu_transquant_bypass_flag", uiSymbol); 
550#endif
[1200]551
[608]552  pcCU->setCUTransquantBypassSubParts(uiSymbol ? true : false, uiAbsPartIdx, uiDepth);
553}
554
[2]555/** parse skip flag
556 * \param pcCU
[1200]557 * \param uiAbsPartIdx
[2]558 * \param uiDepth
559 * \returns Void
560 */
561Void TDecSbac::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
562{
563  if( pcCU->getSlice()->isIntra() )
564  {
565    return;
566  }
[1200]567
[2]568  UInt uiSymbol = 0;
569  UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx );
[1200]570  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SKIP_FLAG) );
[608]571#if !H_MV_ENC_DEC_TRAC
[56]572  DTRACE_CABAC_VL( g_nSymbolCounter++ );
[2]573  DTRACE_CABAC_T( "\tSkipFlag" );
574  DTRACE_CABAC_T( "\tuiCtxSkip: ");
575  DTRACE_CABAC_V( uiCtxSkip );
576  DTRACE_CABAC_T( "\tuiSymbol: ");
577  DTRACE_CABAC_V( uiSymbol );
578  DTRACE_CABAC_T( "\n");
[608]579#endif
[2]580  if( uiSymbol )
581  {
[608]582    pcCU->setSkipFlagSubParts( true,        uiAbsPartIdx, uiDepth );
583    pcCU->setPredModeSubParts( MODE_INTER,  uiAbsPartIdx, uiDepth );
[2]584    pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
[1200]585    pcCU->setSizeSubParts( pcCU->getSlice()->getSPS()->getMaxCUWidth()>>uiDepth, pcCU->getSlice()->getSPS()->getMaxCUHeight()>>uiDepth, uiAbsPartIdx, uiDepth );
[2]586    pcCU->setMergeFlagSubParts( true , uiAbsPartIdx, 0, uiDepth );
587  }
[608]588#if H_MV_ENC_DEC_TRAC
589  DTRACE_CU("cu_skip_flag", uiSymbol); 
590#endif
[1200]591
[2]592}
[1196]593#if H_3D
[1179]594Void TDecSbac::parseDIS( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
595{
596  pcCU->setDISFlagSubParts( false,        uiAbsPartIdx, uiDepth );
597  UInt uiSymbol = 0;
598  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUDISFlagSCModel.get( 0, 0, 0 ) );
599  if( uiSymbol )
600  {
601    pcCU->setDISFlagSubParts( true,        uiAbsPartIdx, uiDepth );
602    pcCU->setSkipFlagSubParts( false,        uiAbsPartIdx, uiDepth );
603    pcCU->setSDCFlagSubParts( false,        uiAbsPartIdx, uiDepth );
604    pcCU->setPredModeSubParts( MODE_INTRA,  uiAbsPartIdx, uiDepth );
605    pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
606    pcCU->setLumaIntraDirSubParts (DC_IDX, uiAbsPartIdx, uiDepth );
607    pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
608    pcCU->setMergeFlagSubParts( false , uiAbsPartIdx, 0, uiDepth );
609    pcCU->setTrIdxSubParts(0, uiAbsPartIdx, uiDepth);
610    pcCU->setCbfSubParts(0, 1, 1, uiAbsPartIdx, uiDepth);
611
612    UInt uiUnaryIdx = 0;
613    UInt uiNumCand  = 4;
614
615    if ( uiNumCand > 1 )
616    {
617      for( ; uiUnaryIdx < uiNumCand - 1; ++uiUnaryIdx )
618      {
619        UInt uiSymbol2 = 0;
620        if ( uiUnaryIdx==0 )
621        {
622          m_pcTDecBinIf->decodeBin( uiSymbol2, m_cCUDISTypeSCModel.get( 0, 0, 0 ) );
623        }
624        else
625        {
626          m_pcTDecBinIf->decodeBinEP( uiSymbol2);
627        }
628        if( uiSymbol2 == 0 )
629        {
630          break;
631        }
632      }
633    }
634    pcCU->setDISTypeSubParts(uiUnaryIdx, uiAbsPartIdx, 0, uiDepth);
635  }
636}
637#endif
[1200]638
639
[2]640/** parse merge flag
641 * \param pcCU
[1200]642 * \param uiAbsPartIdx
[2]643 * \param uiDepth
644 * \param uiPUIdx
645 * \returns Void
646 */
647Void TDecSbac::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
648{
649  UInt uiSymbol;
[1200]650  m_pcTDecBinIf->decodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MERGE_FLAG) );
[608]651#if H_MV_ENC_DEC_TRAC
652  DTRACE_PU("merge_flag", uiSymbol)
653#endif
[2]654  pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth );
[608]655#if !H_MV_ENC_DEC_TRAC
[56]656  DTRACE_CABAC_VL( g_nSymbolCounter++ );
[2]657  DTRACE_CABAC_T( "\tMergeFlag: " );
658  DTRACE_CABAC_V( uiSymbol );
659  DTRACE_CABAC_T( "\tAddress: " );
[1200]660  DTRACE_CABAC_V( pcCU->getCtuRsAddr() );
[2]661  DTRACE_CABAC_T( "\tuiAbsPartIdx: " );
662  DTRACE_CABAC_V( uiAbsPartIdx );
663  DTRACE_CABAC_T( "\n" );
[608]664#endif
[2]665}
666
[608]667Void TDecSbac::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex )
[2]668{
[56]669  UInt uiUnaryIdx = 0;
[608]670  UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand();
[56]671  if ( uiNumCand > 1 )
[2]672  {
[56]673    for( ; uiUnaryIdx < uiNumCand - 1; ++uiUnaryIdx )
[2]674    {
[56]675      UInt uiSymbol = 0;
676      if ( uiUnaryIdx==0 )
[2]677      {
[1200]678        m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MERGE_INDEX) );
[2]679      }
[56]680      else
681      {
[1200]682        m_pcTDecBinIf->decodeBinEP( uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MERGE_INDEX) );
[56]683      }
684      if( uiSymbol == 0 )
[2]685      {
[56]686        break;
[2]687      }
688    }
[608]689#if H_MV_ENC_DEC_TRAC
690    DTRACE_PU("merge_idx", uiUnaryIdx)
691#endif
[2]692  }
693  ruiMergeIndex = uiUnaryIdx;
694
[608]695#if !H_MV_ENC_DEC_TRAC
[56]696  DTRACE_CABAC_VL( g_nSymbolCounter++ )
697  DTRACE_CABAC_T( "\tparseMergeIndex()" )
698  DTRACE_CABAC_T( "\tuiMRGIdx= " )
699  DTRACE_CABAC_V( ruiMergeIndex )
700  DTRACE_CABAC_T( "\n" )
[2]701#endif
702}
703
[56]704Void TDecSbac::parseMVPIdx      ( Int& riMVPIdx )
705{
706  UInt uiSymbol;
[1200]707  xReadUnaryMaxSymbol(uiSymbol, m_cMVPIdxSCModel.get(0), 1, AMVP_MAX_NUM_CANDS-1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVP_IDX) );
[56]708  riMVPIdx = uiSymbol;
709}
[2]710
711Void TDecSbac::parseSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
712{
[1200]713  if( uiDepth == pcCU->getSlice()->getSPS()->getLog2DiffMaxMinCodingBlockSize() )
[2]714  {
715    pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx );
716    return;
717  }
[1200]718#if RExt__DECODER_DEBUG_BIT_STATISTICS
719  const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__SPLIT_FLAG, g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()>>uiDepth]+2);
720#endif
[608]721
[2]722  UInt uiSymbol;
[608]723#if H_3D_QTLPC
[189]724  Bool bParseSplitFlag    = true;
[1124]725  Bool    bLimQtPredFlag = pcCU->getPic()->getSlice(0)->getQtPredFlag();
[189]726  TComPic *pcTexture      = pcCU->getSlice()->getTexturePic();
727  Bool bDepthMapDetect    = (pcTexture != NULL);
728  Bool bIntraSliceDetect  = (pcCU->getSlice()->getSliceType() == I_SLICE);
729
[608]730  Bool rapPic = (pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA);
731
[1084]732#if H_3D_FCO
[1066]733  if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && bLimQtPredFlag && pcTexture->getReconMark())
734#else
[1039]735  if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && bLimQtPredFlag)
[1066]736#endif
[189]737  {
738    TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr());
739    assert(pcTextureCU->getDepth(uiAbsPartIdx) >= uiDepth);
740    bParseSplitFlag         = (pcTextureCU->getDepth(uiAbsPartIdx) > uiDepth);
741  }
742
743  if(bParseSplitFlag)
744  {
745#endif
[1200]746  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSplitFlagSCModel.get( 0, 0, pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ) ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
[608]747#if H_MV_ENC_DEC_TRAC
748    DTRACE_CU("split_cu_flag", uiSymbol); 
749#else
[1200]750  DTRACE_CABAC_VL( g_nSymbolCounter++ )
751  DTRACE_CABAC_T( "\tSplitFlag\n" )
[608]752#endif
753#if H_3D_QTLPC
[189]754  }
755  else
[608]756  {
[189]757    uiSymbol = 0;
[608]758  }
[189]759#endif
[2]760  pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx );
[1196]761
[2]762  return;
763}
764
765/** parse partition size
766 * \param pcCU
[1200]767 * \param uiAbsPartIdx
[2]768 * \param uiDepth
769 * \returns Void
770 */
771Void TDecSbac::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
772{
773  UInt uiSymbol, uiMode = 0;
774  PartSize eMode;
[1200]775  const UChar cuWidth =UChar(pcCU->getSlice()->getSPS()->getMaxCUWidth()>>uiDepth);
776  const UChar cuHeight=UChar(pcCU->getSlice()->getSPS()->getMaxCUHeight()>>uiDepth);
777  const Int log2DiffMaxMinCodingBlockSize = pcCU->getSlice()->getSPS()->getLog2DiffMaxMinCodingBlockSize();
[189]778
[1200]779#if RExt__DECODER_DEBUG_BIT_STATISTICS
780  const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__PART_SIZE, g_aucConvertToBit[cuWidth]+2);
781#endif
782
783  assert ( pcCU->getSlice()->getSPS()->getLog2DiffMaxMinCodingBlockSize() == log2DiffMaxMinCodingBlockSize);
784
[608]785#if H_3D_QTLPC
[189]786  Bool bParsePartSize    = true;
[1196]787
[1124]788  Bool    bLimQtPredFlag = pcCU->getPic()->getSlice(0)->getQtPredFlag();
[189]789  TComPic *pcTexture     = pcCU->getSlice()->getTexturePic();
790  Bool bDepthMapDetect   = (pcTexture != NULL);
791  Bool bIntraSliceDetect = (pcCU->getSlice()->getSliceType() == I_SLICE);
792
[608]793  Bool rapPic     = (pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA);
794
[833]795  Bool depthDependent = false;
796  UInt uiTexturePart = uiMode;
[1084]797
798#if H_3D_FCO
[1066]799  if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && bLimQtPredFlag && pcTexture->getReconMark())
800#else
[1039]801  if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && bLimQtPredFlag )
[1066]802#endif
[189]803  {
804    TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr());
805    assert(pcTextureCU->getDepth(uiAbsPartIdx) >= uiDepth);
[833]806    if(pcTextureCU->getDepth(uiAbsPartIdx) == uiDepth )
[189]807    {
[833]808      depthDependent = true;
809      uiTexturePart = pcTextureCU->getPartitionSize( uiAbsPartIdx );
810    }
811    if (pcTextureCU->getDepth(uiAbsPartIdx) == uiDepth && pcTextureCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N)
812    {
[189]813      bParsePartSize = false;
814      eMode          = SIZE_2Nx2N;
815    }
816  }
817#endif
[608]818
[2]819  if ( pcCU->isIntra( uiAbsPartIdx ) )
820  {
[608]821#if H_3D_QTLPC
[189]822    if(bParsePartSize)
[2]823    {
[189]824#endif
[1200]825    uiSymbol = 1;
826    if( uiDepth == log2DiffMaxMinCodingBlockSize )
827    {
828      m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
[608]829#if H_MV_ENC_DEC_TRAC         
830        DTRACE_CU("part_mode", uiSymbol)
831#endif       
[1200]832    }
833    eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN;
[608]834#if H_3D_QTLPC
[2]835    }
[189]836#endif
[1200]837    UInt uiTrLevel = 0;
[56]838    UInt uiWidthInBit  = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2;
839    UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2;
840    uiTrLevel          = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0;
841    if( eMode == SIZE_NxN )
842    {
843      pcCU->setTrIdxSubParts( 1+uiTrLevel, uiAbsPartIdx, uiDepth );
844    }
845    else
846    {
847      pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth );
848    }
[2]849  }
850  else
851  {
[608]852#if H_3D_QTLPC
[189]853    if(bParsePartSize)
[2]854    {
[833]855      if (depthDependent==false || uiTexturePart == SIZE_NxN|| uiTexturePart == SIZE_2Nx2N)
856      {
857#endif
[1200]858    UInt uiMaxNumBits = 2;
859
860    if( uiDepth == log2DiffMaxMinCodingBlockSize && !( cuWidth == 8 && cuHeight == 8 ) )
861    {
862      uiMaxNumBits ++;
863    }
864
865    for ( UInt ui = 0; ui < uiMaxNumBits; ui++ )
866    {
867      m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
868      if ( uiSymbol )
869      {
870        break;
871      }
872      uiMode++;
873    }
874    eMode = (PartSize) uiMode;
875    if ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize )
876    {
877      if (eMode == SIZE_2NxN)
878      {
879        m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype));
880        if (uiSymbol == 0)
[189]881        {
[1200]882          m_pcTDecBinIf->decodeBinEP(uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
883          eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD);
[189]884        }
[1200]885      }
886      else if (eMode == SIZE_Nx2N)
887      {
888        m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
889        if (uiSymbol == 0)
[189]890        {
[1200]891          m_pcTDecBinIf->decodeBinEP(uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
892          eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N);
[56]893        }
[1200]894      }
895    }
[884]896#if H_3D_QTLPC
[833]897      }
898      else if(uiTexturePart == SIZE_2NxN || uiTexturePart == SIZE_2NxnU || uiTexturePart == SIZE_2NxnD)
899      {
900        UInt uiMaxNumBits = 1;
901        if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) )
902        {
903          uiMaxNumBits ++;
904        }
905        for ( UInt ui = 0; ui < uiMaxNumBits; ui++ )
906        {
907          m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) );
908          if ( uiSymbol )
909          {
910            break;
911          }
912          uiMode++;
913        }
914        eMode = (PartSize) uiMode;
915        if(uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) && uiSymbol==1 )
916        {
917          eMode = SIZE_2NxN;
918        }
919        else if (uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth )==0  && uiSymbol==0)
920        {
921          eMode = SIZE_2NxN;
922        }
923        else if (uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) && uiSymbol==0)
924        {
925          m_pcTDecBinIf->decodeBinEP(uiSymbol);
926          eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD);
927        }
928      }
929      else if(uiTexturePart == SIZE_Nx2N|| uiTexturePart==SIZE_nLx2N || uiTexturePart==SIZE_nRx2N)
930      {
931        UInt uiMaxNumBits = 1;
932        if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) )
933        {
934          uiMaxNumBits ++;
935        }
936        for ( UInt ui = 0; ui < uiMaxNumBits; ui++ )
937        {
938          m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) );
939          if ( uiSymbol )
940          {
941            break;
942          }
943          uiMode++;
944        }
945        eMode = (PartSize) uiMode;
946        if(uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) && uiSymbol==1 )
947        {
948          eMode = SIZE_Nx2N;
949        }
950        else if (uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth )==0  && uiSymbol==0)
951        {
952          eMode = SIZE_Nx2N;
953        }
954        else if (uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) && uiSymbol==0)
955        {
956          m_pcTDecBinIf->decodeBinEP(uiSymbol);
957          eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N);
958        }
959      }
960      else
[884]961      {
[833]962        assert(0);
[884]963      }
[964]964#endif
[608]965#if H_MV_ENC_DEC_TRAC         
966      DTRACE_CU("part_mode", eMode )
967#endif
[964]968#if H_3D_QTLPC
[2]969    }
[189]970#endif
[2]971  }
972  pcCU->setPartSizeSubParts( eMode, uiAbsPartIdx, uiDepth );
[1200]973  pcCU->setSizeSubParts( cuWidth, cuHeight, uiAbsPartIdx, uiDepth );
[2]974}
975
[1200]976
[2]977/** parse prediction mode
978 * \param pcCU
[1200]979 * \param uiAbsPartIdx
[2]980 * \param uiDepth
981 * \returns Void
982 */
983Void TDecSbac::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
984{
985  if( pcCU->getSlice()->isIntra() )
986  {
987    pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth );
988    return;
989  }
[1200]990
[2]991  UInt uiSymbol;
992  Int  iPredMode = MODE_INTER;
[1200]993  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPredModeSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__PRED_MODE) );
[2]994  iPredMode += uiSymbol;
[608]995#if H_MV_ENC_DEC_TRAC         
996  DTRACE_CU("pred_mode_flag", uiSymbol)
997#endif       
[2]998  pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth );
999}
[608]1000
[1200]1001
[608]1002Void TDecSbac::parseIntraDirLumaAng  ( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
[443]1003{
[608]1004  PartSize mode = pcCU->getPartitionSize( absPartIdx );
1005  UInt partNum = mode==SIZE_NxN?4:1;
[1200]1006  UInt partOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2;
[608]1007  UInt mpmPred[4],symbol;
[1200]1008  Int j,intraPredMode;
[608]1009  if (mode==SIZE_NxN)
[443]1010  {
[608]1011    depth++;
[443]1012  }
[1200]1013#if RExt__DECODER_DEBUG_BIT_STATISTICS
1014  const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__INTRA_DIR_ANG, g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()>>depth]+2, CHANNEL_TYPE_LUMA);
1015#endif
[608]1016  for (j=0;j<partNum;j++)
[443]1017  {
[608]1018#if H_3D_DIM
[1124]1019    if( pcCU->getSlice()->getIntraSdcWedgeFlag() || pcCU->getSlice()->getIntraContourFlag() )
[443]1020    {
[608]1021      parseIntraDepth( pcCU, absPartIdx+partOffset*j, depth );
[443]1022    }
[608]1023    if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
1024    {
1025#endif
[1200]1026    m_pcTDecBinIf->decodeBin( symbol, m_cCUIntraPredSCModel.get( 0, 0, 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
1027    mpmPred[j] = symbol;
[608]1028#if H_MV_ENC_DEC_TRAC         
[1196]1029      DTRACE_CU("prev_intra_luma_pred_flag", symbol)
[608]1030#endif
1031#if H_3D_DIM
1032    }
1033#endif
[443]1034  }
[608]1035  for (j=0;j<partNum;j++)
[443]1036  {
[608]1037#if H_3D_DIM
1038    if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
[443]1039    {
[608]1040#endif
[1200]1041    Int preds[NUM_MOST_PROBABLE_MODES] = {-1, -1, -1};
1042    pcCU->getIntraDirPredictor(absPartIdx+partOffset*j, preds, COMPONENT_Y);
1043    if (mpmPred[j])
1044    {
1045      m_pcTDecBinIf->decodeBinEP( symbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
1046      if (symbol)
[608]1047      {
[1200]1048        m_pcTDecBinIf->decodeBinEP( symbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
1049        symbol++;
1050      }
[608]1051#if H_MV_ENC_DEC_TRAC         
[1196]1052        DTRACE_CU("mpm_idx", symbol)
[608]1053#endif
[1200]1054      intraPredMode = preds[symbol];
1055    }
1056    else
1057    {
1058      m_pcTDecBinIf->decodeBinsEP( symbol, 5 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
1059      intraPredMode = symbol;
[608]1060#if H_MV_ENC_DEC_TRAC         
[1196]1061        DTRACE_CU("rem_intra_luma_pred_mode", symbol)
[608]1062#endif       
[1200]1063
1064      //postponed sorting of MPMs (only in remaining branch)
1065      if (preds[0] > preds[1])
1066      {
1067        std::swap(preds[0], preds[1]);
[443]1068      }
[1200]1069      if (preds[0] > preds[2])
1070      {
1071        std::swap(preds[0], preds[2]);
1072      }
1073      if (preds[1] > preds[2])
1074      {
1075        std::swap(preds[1], preds[2]);
1076      }
1077      for ( UInt i = 0; i < NUM_MOST_PROBABLE_MODES; i++ )
1078      {
1079        intraPredMode += ( intraPredMode >= preds[i] );
1080      }
1081    }
1082    pcCU->setIntraDirSubParts(CHANNEL_TYPE_LUMA, (UChar)intraPredMode, absPartIdx+partOffset*j, depth );
[608]1083#if H_3D_DIM
1084    }
1085#endif
[443]1086  }
1087}
[608]1088
[1200]1089
[608]1090Void TDecSbac::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
[443]1091{
[608]1092  UInt uiSymbol;
[1200]1093#if RExt__DECODER_DEBUG_BIT_STATISTICS
1094  const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__INTRA_DIR_ANG, g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()>>uiDepth]+2, CHANNEL_TYPE_CHROMA);
1095#endif
[608]1096
[1200]1097  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
[608]1098  if( uiSymbol == 0 )
[443]1099  {
[608]1100#if H_MV_ENC_DEC_TRAC         
1101    DTRACE_CU("intra_chroma_pred_mode", uiSymbol )
1102#endif       
[1200]1103    uiSymbol = DM_CHROMA_IDX;
1104  }
1105  else
[443]1106  {
[1200]1107    UInt uiIPredMode;
1108    m_pcTDecBinIf->decodeBinsEP( uiIPredMode, 2 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
[608]1109#if H_MV_ENC_DEC_TRAC         
1110      DTRACE_CU("intra_chroma_pred_mode", uiIPredMode )
1111#endif       
[1200]1112    UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ];
1113    pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir );
1114    uiSymbol = uiAllowedChromaDir[ uiIPredMode ];
[443]1115  }
[1200]1116
1117  pcCU->setIntraDirSubParts( CHANNEL_TYPE_CHROMA, uiSymbol, uiAbsPartIdx, uiDepth );
[608]1118}
1119
1120#if H_3D_DIM
1121Void TDecSbac::parseIntraDepth( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
1122{
1123  parseIntraDepthMode( pcCU, absPartIdx, depth );
1124
1125  UInt dir     = pcCU->getLumaIntraDir( absPartIdx );
1126  UInt dimType = getDimType( dir );
1127
1128  switch( dimType )
[443]1129  {
[608]1130#if H_3D_DIM_DMM
1131  case( DMM1_IDX ):
[443]1132    {
[608]1133      UInt uiTabIdx = 0;
1134      xParseDmm1WedgeIdx( uiTabIdx, g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] );
[1124]1135
1136      assert( uiTabIdx < g_dmmWedgeLists[ g_aucConvertToBit[ pcCU->getDMM1BasePatternWidth( pcCU->getWidth( absPartIdx ) )]].size());
1137
[608]1138      pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, absPartIdx, depth );
1139    } break;
1140  case( DMM4_IDX ): break;
1141#endif
1142  default: break;
1143  }
[443]1144
[608]1145  pcCU->setLumaIntraDirSubParts( (UChar)dir, absPartIdx, depth );
1146}
[443]1147
[608]1148Void TDecSbac::parseIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
[2]1149{
[833]1150  UInt uiSymbol, uiIsDimMode;
1151
1152  if( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() >> pcCU->getDepth( absPartIdx ) ) < 64 ) //DMM and HEVC intra modes are both allowed
1153  {
[950]1154    m_pcTDecBinIf->decodeBin( uiSymbol, m_cAngleFlagSCModel.get( 0, 0, 0 ) );
[833]1155  }
1156  else
1157  {
1158    uiSymbol = 1;
1159  }
1160  uiIsDimMode = uiSymbol ? 0 : 1;
1161  pcCU->setLumaIntraDirSubParts( 0, absPartIdx, depth );
1162
1163  //decode DMM index
1164  if( uiIsDimMode )
1165  {
[1124]1166    if( pcCU->getSlice()->getIntraSdcWedgeFlag() && pcCU->getSlice()->getIntraContourFlag() )
[1039]1167    {
1168      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDepthIntraModeSCModel.get( 0, 0, 0 ) );
1169      if( !uiSymbol )
1170      {
1171        pcCU->setLumaIntraDirSubParts( DIM_OFFSET, absPartIdx, depth );
1172      }
1173      else
1174      {
1175        pcCU->setLumaIntraDirSubParts( ( 1+ DIM_OFFSET ), absPartIdx, depth );
1176      }
1177    }
[1124]1178    else if ( pcCU->getSlice()->getIntraSdcWedgeFlag() )
[1039]1179    {
1180      pcCU->setLumaIntraDirSubParts( DIM_OFFSET, absPartIdx, depth );
1181    }
[1124]1182    else if( pcCU->getSlice()->getIntraContourFlag() )
[1039]1183    {
1184      pcCU->setLumaIntraDirSubParts( ( 1+ DIM_OFFSET ), absPartIdx, depth );
1185    }
[833]1186  }
1187}
[2]1188#endif
1189
[608]1190Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx )
[2]1191{
1192  UInt uiSymbol;
[608]1193  const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx );
1194  ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 );
[1200]1195
[608]1196  uiSymbol = 0;
1197  if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 )
[2]1198  {
[1200]1199    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__INTER_DIR) );
[2]1200  }
1201
[56]1202  if( uiSymbol )
[2]1203  {
1204    uiSymbol = 2;
1205  }
[608]1206  else
1207  {
[1200]1208    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + 4 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__INTER_DIR) );
[608]1209    assert(uiSymbol == 0 || uiSymbol == 1);
1210  }
[56]1211
[2]1212  uiSymbol++;
1213  ruiInterDir = uiSymbol;
[608]1214#if H_MV_ENC_DEC_TRAC
1215    DTRACE_PU("inter_pred_idc", ruiInterDir - 1 )   
1216#endif
1217
[2]1218  return;
1219}
1220
[608]1221Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList )
[2]1222{
1223  UInt uiSymbol;
[1200]1224
1225  ContextModel *pCtx = m_cCURefPicSCModel.get( 0 );
1226  m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__REF_FRM_IDX) );
1227
1228  if( uiSymbol )
[2]1229  {
[1200]1230    UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2;
1231    pCtx++;
1232    UInt ui;
1233    for( ui = 0; ui < uiRefNum; ++ui )
[2]1234    {
[1200]1235      if( ui == 0 )
[608]1236      {
[1200]1237        m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__REF_FRM_IDX) );
[608]1238      }
[1200]1239      else
1240      {
1241        m_pcTDecBinIf->decodeBinEP( uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__REF_FRM_IDX) );
1242      }
1243      if( uiSymbol == 0 )
1244      {
1245        break;
1246      }
[2]1247    }
[1200]1248    uiSymbol = ui + 1;
[2]1249  }
[1200]1250  riRefFrmIdx = uiSymbol;
[608]1251#if H_MV_ENC_DEC_TRAC
1252#if ENC_DEC_TRACE
1253  if ( eRefList == REF_PIC_LIST_0 )
1254  {
1255    DTRACE_PU("ref_idx_l0", uiSymbol)
1256  }
[2]1257  else
1258  {
[608]1259    DTRACE_PU("ref_idx_l1", uiSymbol)
[2]1260  }
[608]1261#endif
1262#endif
[1200]1263
[2]1264  return;
1265}
1266
[56]1267Void TDecSbac::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList )
[2]1268{
1269  UInt uiSymbol;
[56]1270  UInt uiHorAbs;
1271  UInt uiVerAbs;
1272  UInt uiHorSign = 0;
1273  UInt uiVerSign = 0;
1274  ContextModel *pCtx = m_cCUMvdSCModel.get( 0 );
[2]1275
[56]1276  if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3)
1277  {
1278    uiHorAbs=0;
1279    uiVerAbs=0;
1280  }
1281  else
1282  {
[1200]1283    m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) );
1284    m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) );
[2]1285
[56]1286    const Bool bHorAbsGr0 = uiHorAbs != 0;
1287    const Bool bVerAbsGr0 = uiVerAbs != 0;
1288    pCtx++;
1289
1290    if( bHorAbsGr0 )
1291    {
[1200]1292      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) );
[56]1293      uiHorAbs += uiSymbol;
1294    }
1295
1296    if( bVerAbsGr0 )
1297    {
[1200]1298      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) );
[56]1299      uiVerAbs += uiSymbol;
1300    }
1301
1302    if( bHorAbsGr0 )
1303    {
1304      if( 2 == uiHorAbs )
1305      {
[1200]1306        xReadEpExGolomb( uiSymbol, 1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) );
[56]1307        uiHorAbs += uiSymbol;
1308      }
1309
[1200]1310      m_pcTDecBinIf->decodeBinEP( uiHorSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) );
[56]1311    }
1312
1313    if( bVerAbsGr0 )
1314    {
1315      if( 2 == uiVerAbs )
1316      {
[1200]1317        xReadEpExGolomb( uiSymbol, 1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) );
[56]1318        uiVerAbs += uiSymbol;
1319      }
1320
[1200]1321      m_pcTDecBinIf->decodeBinEP( uiVerSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) );
[56]1322    }
1323
1324  }
[2]1325
[56]1326  const TComMv cMv( uiHorSign ? -Int( uiHorAbs ): uiHorAbs, uiVerSign ? -Int( uiVerAbs ) : uiVerAbs );
1327  pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiDepth, uiPartIdx );
[2]1328  return;
1329}
1330
[1200]1331Void TDecSbac::parseCrossComponentPrediction( TComTU &rTu, ComponentID compID )
1332{
1333  TComDataCU *pcCU = rTu.getCU();
[2]1334
[1200]1335  if( isLuma(compID) || !pcCU->getSlice()->getPPS()->getPpsRangeExtension().getCrossComponentPredictionEnabledFlag() )
1336  {
1337    return;
1338  }
1339
1340  const UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU();
1341
1342  if (!pcCU->isIntra(uiAbsPartIdx) || (pcCU->getIntraDir( CHANNEL_TYPE_CHROMA, uiAbsPartIdx ) == DM_CHROMA_IDX))
1343  {
1344    Char alpha  = 0;
1345    UInt symbol = 0;
1346
1347    DTRACE_CABAC_VL( g_nSymbolCounter++ )
1348    DTRACE_CABAC_T("\tparseCrossComponentPrediction()")
1349    DTRACE_CABAC_T( "\tAddr=" )
1350    DTRACE_CABAC_V( compID )
1351    DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1352    DTRACE_CABAC_V( uiAbsPartIdx )
1353#if RExt__DECODER_DEBUG_BIT_STATISTICS
1354    TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__CROSS_COMPONENT_PREDICTION, (g_aucConvertToBit[rTu.getRect(compID).width] + 2), compID);
1355#endif
1356    ContextModel *pCtx = m_cCrossComponentPredictionSCModel.get(0, 0) + ((compID == COMPONENT_Cr) ? (NUM_CROSS_COMPONENT_PREDICTION_CTX >> 1) : 0);
1357    m_pcTDecBinIf->decodeBin( symbol, pCtx[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
1358
1359    if(symbol != 0)
1360    {
1361      // Cross-component prediction alpha is non-zero.
1362      UInt sign = 0;
1363      m_pcTDecBinIf->decodeBin( symbol, pCtx[1] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
1364
1365      if (symbol != 0)
1366      {
1367        // alpha is 2 (symbol=1), 4(symbol=2) or 8(symbol=3).
1368        // Read up to two more bits
1369        xReadUnaryMaxSymbol( symbol, (pCtx + 2), 1, 2 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
1370        symbol += 1;
1371      }
1372      m_pcTDecBinIf->decodeBin( sign, pCtx[4] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
1373
1374      alpha = (sign != 0) ? -(1 << symbol) : (1 << symbol);
1375    }
1376    DTRACE_CABAC_T( "\tAlpha=" )
1377    DTRACE_CABAC_V( alpha )
1378    DTRACE_CABAC_T( "\n" )
1379
1380    pcCU->setCrossComponentPredictionAlphaPartRange( alpha, compID, uiAbsPartIdx, rTu.GetAbsPartIdxNumParts( compID ) );
1381  }
1382}
1383
[2]1384Void TDecSbac::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize )
1385{
[1200]1386  m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize )
1387      RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__TRANSFORM_SUBDIV_FLAG, 5-uiLog2TransformBlockSize))
1388                          );
[608]1389#if !H_MV_ENC_DEC_TRAC
[56]1390  DTRACE_CABAC_VL( g_nSymbolCounter++ )
[2]1391  DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" )
1392  DTRACE_CABAC_T( "\tsymbol=" )
1393  DTRACE_CABAC_V( ruiSubdivFlag )
1394  DTRACE_CABAC_T( "\tctx=" )
1395  DTRACE_CABAC_V( uiLog2TransformBlockSize )
1396  DTRACE_CABAC_T( "\n" )
[1179]1397#else
1398  DTRACE_TU("split_transform_flag", ruiSubdivFlag )
[608]1399#endif
[1200]1400
[2]1401}
1402
[608]1403Void TDecSbac::parseQtRootCbf( UInt uiAbsPartIdx, UInt& uiQtRootCbf )
[2]1404{
1405  UInt uiSymbol;
[56]1406  const UInt uiCtx = 0;
[1200]1407  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__QT_ROOT_CBF) );
[608]1408#if !H_MV_ENC_DEC_TRAC
[56]1409  DTRACE_CABAC_VL( g_nSymbolCounter++ )
[2]1410  DTRACE_CABAC_T( "\tparseQtRootCbf()" )
1411  DTRACE_CABAC_T( "\tsymbol=" )
1412  DTRACE_CABAC_V( uiSymbol )
1413  DTRACE_CABAC_T( "\tctx=" )
1414  DTRACE_CABAC_V( uiCtx )
1415  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1416  DTRACE_CABAC_V( uiAbsPartIdx )
1417  DTRACE_CABAC_T( "\n" )
[608]1418#else
1419  DTRACE_CU( "rqt_root_cbf", uiSymbol )
1420#endif
[1200]1421
[2]1422  uiQtRootCbf = uiSymbol;
1423}
1424
1425Void TDecSbac::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1426{
[56]1427  Int qp;
[2]1428  UInt uiDQp;
1429  Int  iDQp;
[1200]1430
[608]1431  UInt uiSymbol;
1432
[1200]1433  xReadUnaryMaxSymbol (uiDQp,  &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTA_QP_EP) );
[608]1434
1435  if( uiDQp >= CU_DQP_TU_CMAX)
[2]1436  {
[1200]1437    xReadEpExGolomb( uiSymbol, CU_DQP_EG_k RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTA_QP_EP));
[608]1438    uiDQp+=uiSymbol;
[2]1439  }
[608]1440
1441  if ( uiDQp > 0 )
[2]1442  {
[56]1443    UInt uiSign;
[1200]1444    Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA);
1445    m_pcTDecBinIf->decodeBinEP(uiSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTA_QP_EP));
[608]1446    iDQp = uiDQp;
[56]1447    if(uiSign)
[2]1448    {
1449      iDQp = -iDQp;
1450    }
[56]1451    qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY;
[2]1452  }
[1200]1453  else
[608]1454  {
1455    qp = pcCU->getRefQP(uiAbsPartIdx);
1456  }
[1200]1457
1458  pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth);
[608]1459  pcCU->setCodedQP(qp);
[2]1460}
1461
[1200]1462/** parse chroma qp adjustment, converting to the internal table representation.
1463 * \returns Void
1464 */
1465Void TDecSbac::parseChromaQpAdjustment( TComDataCU* cu, UInt absPartIdx, UInt depth )
[2]1466{
[1200]1467  UInt symbol;
1468#if RExt__DECODER_DEBUG_BIT_STATISTICS
1469  const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__CHROMA_QP_ADJUSTMENT, g_aucConvertToBit[cu->getSlice()->getSPS()->getMaxCUWidth()>>depth]+2, CHANNEL_TYPE_CHROMA);
1470#endif
1471
1472  Int chromaQpOffsetListLen = cu->getSlice()->getPPS()->getPpsRangeExtension().getChromaQpOffsetListLen();
1473
1474  // cu_chroma_qp_offset_flag
1475  m_pcTDecBinIf->decodeBin( symbol, m_ChromaQpAdjFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
1476
1477  if (symbol && chromaQpOffsetListLen > 1)
1478  {
1479    // cu_chroma_qp_offset_idx
1480    xReadUnaryMaxSymbol( symbol,  &m_ChromaQpAdjIdcSCModel.get( 0, 0, 0 ), 0, chromaQpOffsetListLen - 1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
1481    symbol++;
1482  }
1483  /* NB, symbol = 0 if outer flag is not set,
1484   *              1 if outer flag is set and there is no inner flag
1485   *              1+ otherwise */
1486  cu->setChromaQpAdjSubParts( symbol, absPartIdx, depth );
1487  cu->setCodedChromaQpAdj(symbol);
1488}
1489
1490Void TDecSbac::parseQtCbf( TComTU &rTu, const ComponentID compID, const Bool lowestLevel )
1491{
1492  TComDataCU* pcCU = rTu.getCU();
1493
1494  const UInt absPartIdx       = rTu.GetAbsPartIdxTU(compID);
1495  const UInt TUDepth          = rTu.GetTransformDepthRel();
1496  const UInt uiCtx            = pcCU->getCtxQtCbf( rTu, toChannelType(compID) );
1497  const UInt contextSet       = toChannelType(compID);
1498
1499  const UInt width            = rTu.getRect(compID).width;
1500  const UInt height           = rTu.getRect(compID).height;
1501  const Bool canQuadSplit     = (width >= (MIN_TU_SIZE * 2)) && (height >= (MIN_TU_SIZE * 2));
1502  const UInt coveredPartIdxes = rTu.GetAbsPartIdxNumParts(compID);
1503
1504  //             Since the CBF for chroma is coded at the highest level possible, if sub-TUs are
1505  //             to be coded for a 4x8 chroma TU, their CBFs must be coded at the highest 4x8 level
1506  //             (i.e. where luma TUs are 8x8 rather than 4x4)
1507  //    ___ ___
1508  //   |   |   | <- 4 x (8x8 luma + 4x8 4:2:2 chroma)
1509  //   |___|___|    each quadrant has its own chroma CBF
1510  //   |   |   | _ _ _ _
1511  //   |___|___|        |
1512  //   <--16--->        V
1513  //                   _ _
1514  //                  |_|_| <- 4 x 4x4 luma + 1 x 4x8 4:2:2 chroma
1515  //                  |_|_|    no chroma CBF is coded - instead the parent CBF is inherited
1516  //                  <-8->    if sub-TUs are present, their CBFs had to be coded at the parent level
1517
1518  const UInt lowestTUDepth = TUDepth + ((!lowestLevel && !canQuadSplit) ? 1 : 0); //unsplittable TUs inherit their parent's CBF
1519        UInt lowestTUCBF   = 0;
1520
1521  if ((width != height) && (lowestLevel || !canQuadSplit)) //if sub-TUs are present
1522  {
1523    const UInt subTUDepth        = lowestTUDepth + 1;
1524    const UInt partIdxesPerSubTU = rTu.GetAbsPartIdxNumParts(compID) >> 1;
1525
1526    UInt combinedSubTUCBF = 0;
1527
1528    for (UInt subTU = 0; subTU < 2; subTU++)
1529    {
1530      UInt uiCbf = MAX_UINT;
1531      m_pcTDecBinIf->decodeBin(uiCbf, m_cCUQtCbfSCModel.get(0, contextSet, uiCtx) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__QT_CBF, g_aucConvertToBit[rTu.getRect(compID).width]+2, compID)));
1532
1533      const UInt subTUAbsPartIdx = absPartIdx + (subTU * partIdxesPerSubTU);
1534      pcCU->setCbfPartRange((uiCbf << subTUDepth), compID, subTUAbsPartIdx, partIdxesPerSubTU);
1535      combinedSubTUCBF |= uiCbf;
[608]1536#if !H_MV_ENC_DEC_TRAC 
[1200]1537      DTRACE_CABAC_VL( g_nSymbolCounter++ )
1538      DTRACE_CABAC_T( "\tparseQtCbf()" )
1539      DTRACE_CABAC_T( "\tsub-TU=" )
1540      DTRACE_CABAC_V( subTU )
1541      DTRACE_CABAC_T( "\tsymbol=" )
1542      DTRACE_CABAC_V( uiCbf )
1543      DTRACE_CABAC_T( "\tctx=" )
1544      DTRACE_CABAC_V( uiCtx )
1545      DTRACE_CABAC_T( "\tetype=" )
1546      DTRACE_CABAC_V( compID )
1547      DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1548      DTRACE_CABAC_V( subTUAbsPartIdx )
1549      DTRACE_CABAC_T( "\n" )
[1179]1550#else
[1200]1551  if ( compID == COMPONENT_Cb )
[1179]1552  {
[1200]1553    DTRACE_TU("cbf_cb", uiCbf )
[1179]1554  }
[1200]1555  else if ( compID == COMPONENT_Cr )
[1179]1556  {
[1200]1557    DTRACE_TU("cbf_cr", uiCbf )
[1179]1558  }
1559  else
1560  {
[1200]1561    DTRACE_TU("cbf_luma", uiCbf )
[1179]1562  }
[608]1563#endif
[1200]1564
1565    }
1566
1567    //propagate the sub-TU CBF up to the lowest TU level
1568    if (combinedSubTUCBF != 0)
1569    {
1570      pcCU->bitwiseOrCbfPartRange((combinedSubTUCBF << lowestTUDepth), compID, absPartIdx, coveredPartIdxes);
1571      lowestTUCBF = combinedSubTUCBF;
1572    }
1573  }
1574  else
1575  {
1576    UInt uiCbf = MAX_UINT;
1577    m_pcTDecBinIf->decodeBin(uiCbf, m_cCUQtCbfSCModel.get(0, contextSet, uiCtx) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__QT_CBF, g_aucConvertToBit[rTu.getRect(compID).width]+2, compID)));
1578
1579    pcCU->setCbfSubParts((uiCbf << lowestTUDepth), compID, absPartIdx, rTu.GetTransformDepthTotalAdj(compID));
1580#if !H_MV_ENC_DEC_TRAC
1581    DTRACE_CABAC_VL( g_nSymbolCounter++ )
1582    DTRACE_CABAC_T( "\tparseQtCbf()" )
1583    DTRACE_CABAC_T( "\tsymbol=" )
1584    DTRACE_CABAC_V( uiCbf )
1585    DTRACE_CABAC_T( "\tctx=" )
1586    DTRACE_CABAC_V( uiCtx )
1587    DTRACE_CABAC_T( "\tetype=" )
1588    DTRACE_CABAC_V( compID )
1589    DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1590    DTRACE_CABAC_V( rTu.GetAbsPartIdxTU(compID) )
1591    DTRACE_CABAC_T( "\n" )
1592#else
1593    if ( compID == COMPONENT_Cb )
1594    {
1595      DTRACE_TU("cbf_cb", uiCbf )
1596    }
1597    else if ( compID == COMPONENT_Cr )
1598    {
1599      DTRACE_TU("cbf_cr", uiCbf )
1600    }
1601    else
1602    {
1603      DTRACE_TU("cbf_luma", uiCbf )
1604    }
1605#endif
1606    lowestTUCBF = uiCbf;
1607  }
1608
1609  //propagate the lowest level CBF up to the current level
1610  if (lowestTUCBF != 0)
1611  {
1612    for (UInt depth = TUDepth; depth < lowestTUDepth; depth++)
1613    {
1614      pcCU->bitwiseOrCbfPartRange((lowestTUCBF << depth), compID, absPartIdx, coveredPartIdxes);
1615    }
1616  }
[2]1617}
1618
[1200]1619
1620Void TDecSbac::parseTransformSkipFlags (TComTU &rTu, ComponentID component)
[608]1621{
[1200]1622  TComDataCU* pcCU=rTu.getCU();
1623  UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(component);
1624
[608]1625  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
1626  {
1627    return;
1628  }
[1200]1629
1630  if (!TUCompRectHasAssociatedTransformSkipFlag(rTu.getRect(component), pcCU->getSlice()->getPPS()->getPpsRangeExtension().getLog2MaxTransformSkipBlockSize()))
[608]1631  {
1632    return;
1633  }
[1200]1634
[608]1635  UInt useTransformSkip;
[1200]1636
1637  m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, toChannelType(component), 0 )
1638      RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__TRANSFORM_SKIP_FLAGS, component))
1639                          );
1640
[608]1641#if !H_MV_ENC_DEC_TRAC
1642  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1643  DTRACE_CABAC_T("\tparseTransformSkip()");
1644  DTRACE_CABAC_T( "\tsymbol=" )
1645  DTRACE_CABAC_V( useTransformSkip )
1646  DTRACE_CABAC_T( "\tAddr=" )
[1200]1647  DTRACE_CABAC_V( pcCU->getCtuRsAddr() )
[608]1648  DTRACE_CABAC_T( "\tetype=" )
[1200]1649  DTRACE_CABAC_V( component )
[608]1650  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
[1200]1651  DTRACE_CABAC_V( rTu.GetAbsPartIdxTU() )
[608]1652  DTRACE_CABAC_T( "\n" )
1653#endif
1654
[1200]1655  pcCU->setTransformSkipPartRange( useTransformSkip, component, uiAbsPartIdx, rTu.GetAbsPartIdxNumParts(component));
[608]1656}
1657
[1200]1658
[2]1659/** Parse (X,Y) position of the last significant coefficient
1660 * \param uiPosLastX reference to X component of last coefficient
1661 * \param uiPosLastY reference to Y component of last coefficient
[56]1662 * \param width  Block width
1663 * \param height Block height
[1200]1664 * \param component chroma compinent ID
[2]1665 * \param uiScanIdx scan type (zig-zag, hor, ver)
[56]1666 *
[2]1667 * This method decodes the X and Y component within a block of the last significant coefficient.
1668 */
[1200]1669Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, ComponentID component, UInt uiScanIdx )
[2]1670{
1671  UInt uiLast;
1672
[1200]1673  ContextModel *pCtxX = m_cCuCtxLastX.get( 0, toChannelType(component) );
1674  ContextModel *pCtxY = m_cCuCtxLastY.get( 0, toChannelType(component) );
1675
1676#if RExt__DECODER_DEBUG_BIT_STATISTICS
1677  TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__LAST_SIG_X_Y, g_aucConvertToBit[width]+2, component);
1678#endif
1679
1680
1681  if ( uiScanIdx == SCAN_VER )
1682  {
1683    swap( width, height );
1684  }
1685
[608]1686  Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY;
[1200]1687  getLastSignificantContextParameters(component, width, height, blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY);
1688
1689  //------------------
1690
[56]1691  // posX
[1200]1692
[56]1693  for( uiPosLastX = 0; uiPosLastX < g_uiGroupIdx[ width - 1 ]; uiPosLastX++ )
[2]1694  {
[1200]1695    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + blkSizeOffsetX + (uiPosLastX >>shiftX) ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
1696
[56]1697    if( !uiLast )
1698    {
[2]1699      break;
1700    }
1701  }
1702
[56]1703  // posY
[1200]1704
[56]1705  for( uiPosLastY = 0; uiPosLastY < g_uiGroupIdx[ height - 1 ]; uiPosLastY++ )
[2]1706  {
[1200]1707    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + blkSizeOffsetY + (uiPosLastY >>shiftY)) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
1708
[56]1709    if( !uiLast )
1710    {
[2]1711      break;
1712    }
1713  }
[1200]1714
1715  // EP-coded part
1716
[56]1717  if ( uiPosLastX > 3 )
1718  {
1719    UInt uiTemp  = 0;
1720    UInt uiCount = ( uiPosLastX - 2 ) >> 1;
1721    for ( Int i = uiCount - 1; i >= 0; i-- )
1722    {
[1200]1723      m_pcTDecBinIf->decodeBinEP( uiLast RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
[56]1724      uiTemp += uiLast << i;
1725    }
1726    uiPosLastX = g_uiMinInGroup[ uiPosLastX ] + uiTemp;
1727  }
1728  if ( uiPosLastY > 3 )
1729  {
1730    UInt uiTemp  = 0;
1731    UInt uiCount = ( uiPosLastY - 2 ) >> 1;
1732    for ( Int i = uiCount - 1; i >= 0; i-- )
1733    {
[1200]1734      m_pcTDecBinIf->decodeBinEP( uiLast RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
[56]1735      uiTemp += uiLast << i;
1736    }
1737    uiPosLastY = g_uiMinInGroup[ uiPosLastY ] + uiTemp;
1738  }
[1200]1739
[2]1740  if( uiScanIdx == SCAN_VER )
1741  {
1742    swap( uiPosLastX, uiPosLastY );
1743  }
1744}
1745
[1200]1746Void TDecSbac::parseCoeffNxN(  TComTU &rTu, ComponentID compID )
[2]1747{
[1200]1748  TComDataCU* pcCU=rTu.getCU();
1749  const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(compID);
1750  const TComRectangle &rRect=rTu.getRect(compID);
1751  const UInt uiWidth=rRect.width;
1752  const UInt uiHeight=rRect.height;
1753  TCoeff* pcCoef=(pcCU->getCoeff(compID)+rTu.getCoefficientOffset(compID));
1754  const TComSPS &sps=*(pcCU->getSlice()->getSPS());
[608]1755#if !H_MV_ENC_DEC_TRAC
[56]1756  DTRACE_CABAC_VL( g_nSymbolCounter++ )
[2]1757  DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" )
[1200]1758  DTRACE_CABAC_V( compID )
[2]1759  DTRACE_CABAC_T( "\twidth=" )
1760  DTRACE_CABAC_V( uiWidth )
1761  DTRACE_CABAC_T( "\theight=" )
1762  DTRACE_CABAC_V( uiHeight )
1763  DTRACE_CABAC_T( "\tdepth=" )
[1200]1764//  DTRACE_CABAC_V( rTu.GetTransformDepthTotalAdj(compID) )
1765  DTRACE_CABAC_V( rTu.GetTransformDepthTotal() )
[2]1766  DTRACE_CABAC_T( "\tabspartidx=" )
[1200]1767//  DTRACE_CABAC_V( uiAbsPartIdx )
1768  DTRACE_CABAC_V( rTu.GetAbsPartIdxTU(compID) )
[2]1769  DTRACE_CABAC_T( "\ttoCU-X=" )
1770  DTRACE_CABAC_V( pcCU->getCUPelX() )
1771  DTRACE_CABAC_T( "\ttoCU-Y=" )
1772  DTRACE_CABAC_V( pcCU->getCUPelY() )
1773  DTRACE_CABAC_T( "\tCU-addr=" )
[1200]1774  DTRACE_CABAC_V(  pcCU->getCtuRsAddr() )
[2]1775  DTRACE_CABAC_T( "\tinCU-X=" )
[1200]1776//  DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1777  DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] )
[2]1778  DTRACE_CABAC_T( "\tinCU-Y=" )
[1200]1779// DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1780  DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] )
[2]1781  DTRACE_CABAC_T( "\tpredmode=" )
1782  DTRACE_CABAC_V(  pcCU->getPredictionMode( uiAbsPartIdx ) )
1783  DTRACE_CABAC_T( "\n" )
[608]1784#endif
[1200]1785
1786  //--------------------------------------------------------------------------------------------------
1787
1788  if( uiWidth > sps.getMaxTrSize() )
[2]1789  {
[1200]1790    std::cerr << "ERROR: parseCoeffNxN was passed a TU with dimensions larger than the maximum allowed size" << std::endl;
1791    assert(false);
1792    exit(1);
[2]1793  }
[1200]1794
1795  //--------------------------------------------------------------------------------------------------
1796
1797  //set parameters
1798
1799  const ChannelType  chType            = toChannelType(compID);
1800  const UInt         uiLog2BlockWidth  = g_aucConvertToBit[ uiWidth  ] + 2;
1801  const UInt         uiLog2BlockHeight = g_aucConvertToBit[ uiHeight ] + 2;
1802  const UInt         uiMaxNumCoeff     = uiWidth * uiHeight;
1803  const UInt         uiMaxNumCoeffM1   = uiMaxNumCoeff - 1;
1804
1805  const ChannelType  channelType       = toChannelType(compID);
1806  const Bool         extendedPrecision = sps.getSpsRangeExtension().getExtendedPrecisionProcessingFlag();
1807
1808  const Bool         alignCABACBeforeBypass = sps.getSpsRangeExtension().getCabacBypassAlignmentEnabledFlag();
1809  const Int          maxLog2TrDynamicRange  = sps.getMaxLog2TrDynamicRange(channelType);
1810
1811#if RExt__DECODER_DEBUG_BIT_STATISTICS
1812  TComCodingStatisticsClassType ctype_group(STATS__CABAC_BITS__SIG_COEFF_GROUP_FLAG, uiLog2BlockWidth, compID);
1813  TComCodingStatisticsClassType ctype_map(STATS__CABAC_BITS__SIG_COEFF_MAP_FLAG, uiLog2BlockWidth, compID);
1814  TComCodingStatisticsClassType ctype_gt1(STATS__CABAC_BITS__GT1_FLAG, uiLog2BlockWidth, compID);
1815  TComCodingStatisticsClassType ctype_gt2(STATS__CABAC_BITS__GT2_FLAG, uiLog2BlockWidth, compID);
1816#endif
1817
1818  Bool beValid;
1819  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
1820  {
1821    beValid = false;
1822    if((!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx))
1823    {
1824      parseExplicitRdpcmMode(rTu, compID);
1825    }
1826  }
1827  else
1828  {
1829    beValid = pcCU->getSlice()->getPPS()->getSignHideFlag();
1830  }
1831
1832  UInt absSum = 0;
1833
1834  //--------------------------------------------------------------------------------------------------
1835
[608]1836  if(pcCU->getSlice()->getPPS()->getUseTransformSkip())
1837  {
[1200]1838    parseTransformSkipFlags(rTu, compID);
1839    //  This TU has coefficients and is transform skipped. Check whether is inter coded and if yes decode the explicit RDPCM mode
1840    if(pcCU->getTransformSkip(uiAbsPartIdx, compID) && (!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx) )
1841    {
1842      parseExplicitRdpcmMode(rTu, compID);
1843      if(pcCU->getExplicitRdpcmMode(compID, uiAbsPartIdx) != RDPCM_OFF)
1844      {
1845        //  Sign data hiding is avoided for horizontal and vertical RDPCM modes
1846        beValid = false;
1847      }
1848    }
[608]1849  }
1850
[1200]1851  Int uiIntraMode = -1;
1852  const Bool       bIsLuma = isLuma(compID);
1853  Int isIntra = pcCU->isIntra(uiAbsPartIdx) ? 1 : 0;
1854  if ( isIntra && pcCU->isRDPCMEnabled(uiAbsPartIdx) )
1855  {
1856    const UInt partsPerMinCU = 1<<(2*(sps.getMaxTotalCUDepth() - sps.getLog2DiffMaxMinCodingBlockSize()));
1857    uiIntraMode = pcCU->getIntraDir( toChannelType(compID), uiAbsPartIdx );
1858    uiIntraMode = (uiIntraMode==DM_CHROMA_IDX && !bIsLuma) ? pcCU->getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, rTu.GetChromaFormat(), partsPerMinCU)) : uiIntraMode;
1859    uiIntraMode = ((rTu.GetChromaFormat() == CHROMA_422) && !bIsLuma) ? g_chroma422IntraAngleMappingTable[uiIntraMode] : uiIntraMode;
1860
1861    Bool transformSkip = pcCU->getTransformSkip( uiAbsPartIdx,compID);
1862    Bool rdpcm_lossy = ( transformSkip /*&& isIntra*/ && ( (uiIntraMode == HOR_IDX) || (uiIntraMode == VER_IDX) ) );
1863    if ( rdpcm_lossy )
1864    {
1865      beValid = false;
1866    }
1867  }
1868
1869  //--------------------------------------------------------------------------------------------------
1870
1871  const Bool  bUseGolombRiceParameterAdaptation = sps.getSpsRangeExtension().getPersistentRiceAdaptationEnabledFlag();
1872        UInt &currentGolombRiceStatistic        = m_golombRiceAdaptationStatistics[rTu.getGolombRiceStatisticsIndex(compID)];
1873
1874  //select scans
1875  TUEntropyCodingParameters codingParameters;
1876  getTUEntropyCodingParameters(codingParameters, rTu, compID);
1877
[56]1878  //===== decode last significant =====
1879  UInt uiPosLastX, uiPosLastY;
[1200]1880  parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, compID, codingParameters.scanType );
1881  UInt uiBlkPosLast      = uiPosLastX + (uiPosLastY<<uiLog2BlockWidth);
[56]1882  pcCoef[ uiBlkPosLast ] = 1;
[2]1883
[56]1884  //===== decode significance flags =====
[608]1885  UInt uiScanPosLast;
[56]1886  for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ )
1887  {
[1200]1888    UInt uiBlkPos = codingParameters.scan[ uiScanPosLast ];
[56]1889    if( uiBlkPosLast == uiBlkPos )
[2]1890    {
[56]1891      break;
[2]1892    }
[56]1893  }
[2]1894
[1200]1895  ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, isChroma(chType) );
1896  ContextModel * const baseCtx = m_cCUSigSCModel.get( 0, 0 ) + getSignificanceMapContextOffset(compID);
[56]1897
[1200]1898  const Int  iLastScanSet  = uiScanPosLast >> MLS_CG_SIZE;
1899  UInt c1                  = 1;
1900  UInt uiGoRiceParam       = 0;
[56]1901
1902
1903  UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ];
[1200]1904  memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM );
1905
[56]1906  Int  iScanPosSig             = (Int) uiScanPosLast;
1907  for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- )
1908  {
[1200]1909    Int  iSubPos   = iSubSet << MLS_CG_SIZE;
1910    uiGoRiceParam  = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR;
1911    Bool updateGolombRiceStatistics = bUseGolombRiceParameterAdaptation; //leave the statistics at 0 when not using the adaptation system
[56]1912    Int numNonZero = 0;
1913
[1200]1914    Int lastNZPosInCG  = -1;
1915    Int firstNZPosInCG = 1 << MLS_CG_SIZE;
1916
1917    Bool escapeDataPresentInGroup = false;
1918
1919    Int pos[1 << MLS_CG_SIZE];
1920
[56]1921    if( iScanPosSig == (Int) uiScanPosLast )
1922    {
1923      lastNZPosInCG  = iScanPosSig;
1924      firstNZPosInCG = iScanPosSig;
1925      iScanPosSig--;
1926      pos[ numNonZero ] = uiBlkPosLast;
1927      numNonZero = 1;
1928    }
[2]1929
[608]1930    // decode significant_coeffgroup_flag
[1200]1931    Int iCGBlkPos = codingParameters.scanCG[ iSubSet ];
1932    Int iCGPosY   = iCGBlkPos / codingParameters.widthInGroups;
1933    Int iCGPosX   = iCGBlkPos - (iCGPosY * codingParameters.widthInGroups);
1934
[608]1935    if( iSubSet == iLastScanSet || iSubSet == 0)
1936    {
1937      uiSigCoeffGroupFlag[ iCGBlkPos ] = 1;
1938    }
1939    else
1940    {
1941      UInt uiSigCoeffGroup;
[1200]1942      UInt uiCtxSig  = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups );
1943      m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_group) );
[608]1944      uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup;
1945    }
[56]1946
[608]1947    // decode significant_coeff_flag
[1200]1948    const Int patternSigCtx = TComTrQuant::calcPatternSigCtx(uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups);
1949
1950    UInt uiBlkPos, uiSig, uiCtxSig;
[608]1951    for( ; iScanPosSig >= iSubPos; iScanPosSig-- )
1952    {
[1200]1953      uiBlkPos  = codingParameters.scan[ iScanPosSig ];
[608]1954      uiSig     = 0;
[1200]1955
[608]1956      if( uiSigCoeffGroupFlag[ iCGBlkPos ] )
[56]1957      {
[608]1958        if( iScanPosSig > iSubPos || iSubSet == 0  || numNonZero )
[2]1959        {
[1200]1960          uiCtxSig  = TComTrQuant::getSigCtxInc( patternSigCtx, codingParameters, iScanPosSig, uiLog2BlockWidth, uiLog2BlockHeight, chType );
1961          m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_map) );
[2]1962        }
[608]1963        else
[2]1964        {
[608]1965          uiSig = 1;
[2]1966        }
[56]1967      }
[608]1968      pcCoef[ uiBlkPos ] = uiSig;
1969      if( uiSig )
1970      {
1971        pos[ numNonZero ] = uiBlkPos;
1972        numNonZero ++;
1973        if( lastNZPosInCG == -1 )
1974        {
1975          lastNZPosInCG = iScanPosSig;
1976        }
1977        firstNZPosInCG = iScanPosSig;
1978      }
1979    }
[1200]1980
1981    if( numNonZero > 0 )
[2]1982    {
[608]1983      Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD );
[1200]1984
[56]1985      absSum = 0;
[1200]1986
1987      const UInt uiCtxSet = getContextSetIndex(compID, iSubSet, (c1 == 0));
1988      c1 = 1;
[56]1989      UInt uiBin;
[1200]1990
1991      ContextModel *baseCtxMod = m_cCUOneSCModel.get( 0, 0 ) + (NUM_ONE_FLAG_CTX_PER_SET * uiCtxSet);
1992
1993      Int absCoeff[1 << MLS_CG_SIZE];
1994
1995      for ( Int i = 0; i < numNonZero; i++)
[2]1996      {
[1200]1997        absCoeff[i] = 1;
[56]1998      }
1999      Int numC1Flag = min(numNonZero, C1FLAG_NUMBER);
2000      Int firstC2FlagIdx = -1;
2001
2002      for( Int idx = 0; idx < numC1Flag; idx++ )
2003      {
[1200]2004        m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_gt1) );
[56]2005        if( uiBin == 1 )
[2]2006        {
[56]2007          c1 = 0;
2008          if (firstC2FlagIdx == -1)
2009          {
2010            firstC2FlagIdx = idx;
2011          }
[1200]2012          else //if a greater-than-one has been encountered already this group
2013          {
2014            escapeDataPresentInGroup = true;
2015          }
[56]2016        }
2017        else if( (c1 < 3) && (c1 > 0) )
2018        {
[2]2019          c1++;
2020        }
[56]2021        absCoeff[ idx ] = uiBin + 1;
2022      }
[1200]2023
[56]2024      if (c1 == 0)
2025      {
[1200]2026        baseCtxMod = m_cCUAbsSCModel.get( 0, 0 ) + (NUM_ABS_FLAG_CTX_PER_SET * uiCtxSet);
[56]2027        if ( firstC2FlagIdx != -1)
[2]2028        {
[1200]2029          m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_gt2) );
[56]2030          absCoeff[ firstC2FlagIdx ] = uiBin + 2;
[1200]2031          if (uiBin != 0)
2032          {
2033            escapeDataPresentInGroup = true;
2034          }
[2]2035        }
2036      }
[56]2037
[1200]2038      escapeDataPresentInGroup = escapeDataPresentInGroup || (numNonZero > C1FLAG_NUMBER);
2039
2040      const Bool alignGroup = escapeDataPresentInGroup && alignCABACBeforeBypass;
2041
2042#if RExt__DECODER_DEBUG_BIT_STATISTICS
2043      TComCodingStatisticsClassType ctype_signs((alignGroup ? STATS__CABAC_BITS__ALIGNED_SIGN_BIT    : STATS__CABAC_BITS__SIGN_BIT   ), uiLog2BlockWidth, compID);
2044      TComCodingStatisticsClassType ctype_escs ((alignGroup ? STATS__CABAC_BITS__ALIGNED_ESCAPE_BITS : STATS__CABAC_BITS__ESCAPE_BITS), uiLog2BlockWidth, compID);
2045#endif
2046
2047      if (alignGroup)
2048      {
2049        m_pcTDecBinIf->align();
2050      }
2051
[56]2052      UInt coeffSigns;
2053      if ( signHidden && beValid )
2054      {
[1200]2055        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_signs) );
[56]2056        coeffSigns <<= 32 - (numNonZero-1);
2057      }
2058      else
2059      {
[1200]2060        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_signs) );
[56]2061        coeffSigns <<= 32 - numNonZero;
2062      }
[1200]2063
2064      Int iFirstCoeff2 = 1;
2065      if (escapeDataPresentInGroup)
[2]2066      {
[56]2067        for( Int idx = 0; idx < numNonZero; idx++ )
[2]2068        {
[56]2069          UInt baseLevel  = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2) : 1;
[2]2070
[56]2071          if( absCoeff[ idx ] == baseLevel)
[2]2072          {
[56]2073            UInt uiLevel;
[1200]2074            xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam, extendedPrecision, maxLog2TrDynamicRange RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_escs) );
2075
[56]2076            absCoeff[ idx ] = uiLevel + baseLevel;
[1200]2077
2078            if (absCoeff[idx] > (3 << uiGoRiceParam))
[608]2079            {
[1200]2080              uiGoRiceParam = bUseGolombRiceParameterAdaptation ? (uiGoRiceParam + 1) : (std::min<UInt>((uiGoRiceParam + 1), 4));
[608]2081            }
[1200]2082
2083            if (updateGolombRiceStatistics)
2084            {
2085              const UInt initialGolombRiceParameter = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR;
2086
2087              if (uiLevel >= (3 << initialGolombRiceParameter))
2088              {
2089                currentGolombRiceStatistic++;
2090              }
2091              else if (((uiLevel * 2) < (1 << initialGolombRiceParameter)) && (currentGolombRiceStatistic > 0))
2092              {
2093                currentGolombRiceStatistic--;
2094              }
2095
2096              updateGolombRiceStatistics = false;
2097            }
[2]2098          }
[56]2099
[1200]2100          if(absCoeff[ idx ] >= 2)
[2]2101          {
[56]2102            iFirstCoeff2 = 0;
[2]2103          }
2104        }
2105      }
[56]2106
2107      for( Int idx = 0; idx < numNonZero; idx++ )
[2]2108      {
[56]2109        Int blkPos = pos[ idx ];
2110        // Signs applied later.
2111        pcCoef[ blkPos ] = absCoeff[ idx ];
2112        absSum += absCoeff[ idx ];
2113
2114        if ( idx == numNonZero-1 && signHidden && beValid )
2115        {
2116          // Infer sign of 1st element.
2117          if (absSum&0x1)
[608]2118          {
[56]2119            pcCoef[ blkPos ] = -pcCoef[ blkPos ];
[608]2120          }
[56]2121        }
2122        else
2123        {
2124          Int sign = static_cast<Int>( coeffSigns ) >> 31;
2125          pcCoef[ blkPos ] = ( pcCoef[ blkPos ] ^ sign ) - sign;
2126          coeffSigns <<= 1;
2127        }
[2]2128      }
2129    }
2130  }
[1200]2131
2132#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
2133  printSBACCoeffData(uiPosLastX, uiPosLastY, uiWidth, uiHeight, compID, uiAbsPartIdx, codingParameters.scanType, pcCoef);
2134#endif
2135
[2]2136  return;
2137}
2138
[443]2139Void TDecSbac::parseSaoMaxUvlc ( UInt& val, UInt maxSymbol )
2140{
[608]2141  if (maxSymbol == 0)
[2]2142  {
[608]2143    val = 0;
[2]2144    return;
2145  }
[56]2146
[608]2147  UInt code;
[2]2148  Int  i;
[1200]2149  m_pcTDecBinIf->decodeBinEP( code RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
[608]2150  if ( code == 0 )
[2]2151  {
[608]2152    val = 0;
[2]2153    return;
2154  }
[56]2155
[2]2156  i=1;
2157  while (1)
2158  {
[1200]2159    m_pcTDecBinIf->decodeBinEP( code RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
[608]2160    if ( code == 0 )
2161    {
2162      break;
2163    }
[2]2164    i++;
[1200]2165    if (i == maxSymbol)
[56]2166    {
[608]2167      break;
[56]2168    }
2169  }
[608]2170
2171  val = i;
[2]2172}
[1200]2173
[608]2174Void TDecSbac::parseSaoUflc (UInt uiLength, UInt&  riVal)
[56]2175{
[1200]2176  m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
[56]2177}
[1200]2178
[608]2179Void TDecSbac::parseSaoMerge (UInt&  ruiVal)
[2]2180{
2181  UInt uiCode;
[1200]2182  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
[56]2183  ruiVal = (Int)uiCode;
2184}
[1200]2185
[56]2186Void TDecSbac::parseSaoTypeIdx (UInt&  ruiVal)
2187{
2188  UInt uiCode;
[1200]2189  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
2190  if (uiCode == 0)
[2]2191  {
2192    ruiVal = 0;
2193  }
[608]2194  else
[2]2195  {
[1200]2196    m_pcTDecBinIf->decodeBinEP( uiCode RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
[608]2197    if (uiCode == 0)
2198    {
[872]2199      ruiVal = 1;
[608]2200    }
2201    else
2202    {
[872]2203      ruiVal = 2;
[608]2204    }
[2]2205  }
2206}
2207
[872]2208Void TDecSbac::parseSaoSign(UInt& val)
[2]2209{
[1200]2210  m_pcTDecBinIf->decodeBinEP ( val RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
[56]2211}
[608]2212
[872]2213Void TDecSbac::parseSAOBlkParam (SAOBlkParam& saoBlkParam
2214                                , Bool* sliceEnabled
2215                                , Bool leftMergeAvail
2216                                , Bool aboveMergeAvail
[1200]2217                                , const BitDepths &bitDepths
[872]2218                                )
[56]2219{
2220  UInt uiSymbol;
[2]2221
[872]2222  Bool isLeftMerge = false;
2223  Bool isAboveMerge= false;
2224
2225  if(leftMergeAvail)
[608]2226  {
[872]2227    parseSaoMerge(uiSymbol); //sao_merge_left_flag
2228    isLeftMerge = (uiSymbol?true:false);
[608]2229  }
[872]2230
2231  if( aboveMergeAvail && !isLeftMerge)
[608]2232  {
[872]2233    parseSaoMerge(uiSymbol); //sao_merge_up_flag
2234    isAboveMerge = (uiSymbol?true:false);
[608]2235  }
2236
[872]2237  if(isLeftMerge || isAboveMerge) //merge mode
[1200]2238  {
2239    for (UInt componentIndex = 0; componentIndex < MAX_NUM_COMPONENT; componentIndex++)
2240    {
2241      saoBlkParam[componentIndex].modeIdc = (sliceEnabled[componentIndex]) ? SAO_MODE_MERGE : SAO_MODE_OFF;
2242      saoBlkParam[componentIndex].typeIdc = (isLeftMerge)?SAO_MERGE_LEFT:SAO_MERGE_ABOVE;
2243    }
2244  }
[872]2245  else //new or off mode
[1200]2246  {
2247    for(Int compId=COMPONENT_Y; compId < MAX_NUM_COMPONENT; compId++)
2248    {
2249      const ComponentID compIdx=ComponentID(compId);
2250      const ComponentID firstCompOfChType = getFirstComponentOfChannel(toChannelType(compIdx));
[872]2251      SAOOffset& ctbParam = saoBlkParam[compIdx];
[1200]2252#if O0043_BEST_EFFORT_DECODING
2253      const Int bitDepthOrig = bitDepths.stream[toChannelType(compIdx)];
2254      const Int forceBitDepthAdjust = bitDepthOrig - bitDepths.recon[toChannelType(compIdx)];
2255#else
2256      const Int bitDepthOrig = bitDepths.recon[toChannelType(compIdx)];
2257#endif
2258      const Int maxOffsetQVal=TComSampleAdaptiveOffset::getMaxOffsetQVal(bitDepthOrig);
[872]2259      if(!sliceEnabled[compIdx])
[1200]2260      {
[872]2261        //off
2262        ctbParam.modeIdc = SAO_MODE_OFF;
2263        continue;
[1200]2264      }
[872]2265
2266      //type
[1200]2267      if(compIdx == firstCompOfChType)
2268      {
[872]2269        parseSaoTypeIdx(uiSymbol); //sao_type_idx_luma or sao_type_idx_chroma
2270
2271        assert(uiSymbol ==0 || uiSymbol ==1 || uiSymbol ==2);
2272
2273        if(uiSymbol ==0) //OFF
[1200]2274        {
[872]2275          ctbParam.modeIdc = SAO_MODE_OFF;
[1200]2276        }
[872]2277        else if(uiSymbol == 1) //BO
2278        {
2279          ctbParam.modeIdc = SAO_MODE_NEW;
2280          ctbParam.typeIdc = SAO_TYPE_START_BO;
[1200]2281        }
[872]2282        else //2, EO
[1200]2283        {
[872]2284          ctbParam.modeIdc = SAO_MODE_NEW;
2285          ctbParam.typeIdc = SAO_TYPE_START_EO;
2286        }
2287
[1200]2288      }
[872]2289      else //Cr, follow Cb SAO type
2290      {
[1200]2291        ctbParam.modeIdc = saoBlkParam[COMPONENT_Cb].modeIdc;
2292        ctbParam.typeIdc = saoBlkParam[COMPONENT_Cb].typeIdc;
2293      }
[2]2294
[872]2295      if(ctbParam.modeIdc == SAO_MODE_NEW)
[1200]2296      {
[872]2297        Int offset[4];
2298        for(Int i=0; i< 4; i++)
[1200]2299        {
2300          parseSaoMaxUvlc(uiSymbol, maxOffsetQVal ); //sao_offset_abs
[872]2301          offset[i] = (Int)uiSymbol;
[1200]2302        }
[56]2303
[872]2304        if(ctbParam.typeIdc == SAO_TYPE_START_BO)
[1200]2305        {
[872]2306          for(Int i=0; i< 4; i++)
[1200]2307          {
[872]2308            if(offset[i] != 0)
[1200]2309            {
[872]2310              parseSaoSign(uiSymbol); //sao_offset_sign
2311              if(uiSymbol)
[1200]2312              {
2313#if O0043_BEST_EFFORT_DECODING
2314                offset[i] >>= forceBitDepthAdjust;
2315#endif
[872]2316                offset[i] = -offset[i];
[1200]2317              }
2318            }
2319          }
[872]2320          parseSaoUflc(NUM_SAO_BO_CLASSES_LOG2, uiSymbol ); //sao_band_position
2321          ctbParam.typeAuxInfo = uiSymbol;
[608]2322
[872]2323          for(Int i=0; i<4; i++)
[1200]2324          {
[872]2325            ctbParam.offset[(ctbParam.typeAuxInfo+i)%MAX_NUM_SAO_CLASSES] = offset[i];
[1200]2326          }
[56]2327
2328        }
[872]2329        else //EO
[56]2330        {
[872]2331          ctbParam.typeAuxInfo = 0;
2332
[1200]2333          if(firstCompOfChType == compIdx)
2334          {
[872]2335            parseSaoUflc(NUM_SAO_EO_TYPES_LOG2, uiSymbol ); //sao_eo_class_luma or sao_eo_class_chroma
2336            ctbParam.typeIdc += uiSymbol;
[1200]2337          }
2338          else
2339          {
2340            ctbParam.typeIdc = saoBlkParam[firstCompOfChType].typeIdc;
2341          }
[872]2342          ctbParam.offset[SAO_CLASS_EO_FULL_VALLEY] = offset[0];
2343          ctbParam.offset[SAO_CLASS_EO_HALF_VALLEY] = offset[1];
2344          ctbParam.offset[SAO_CLASS_EO_PLAIN      ] = 0;
2345          ctbParam.offset[SAO_CLASS_EO_HALF_PEAK  ] = -offset[2];
2346          ctbParam.offset[SAO_CLASS_EO_FULL_PEAK  ] = -offset[3];
[1200]2347        }
[56]2348      }
2349    }
[2]2350  }
[56]2351}
[608]2352
[56]2353/**
2354 - Initialize our contexts from the nominated source.
2355 .
2356 \param pSrc Contexts to be copied.
2357 */
[1200]2358Void TDecSbac::xCopyContextsFrom( const TDecSbac* pSrc )
[56]2359{
2360  memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0]));
[1200]2361  memcpy(m_golombRiceAdaptationStatistics, pSrc->m_golombRiceAdaptationStatistics, (sizeof(UInt) * RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS));
[56]2362}
[2]2363
[1200]2364Void TDecSbac::xCopyFrom( const TDecSbac* pSrc )
[56]2365{
2366  m_pcTDecBinIf->copyState( pSrc->m_pcTDecBinIf );
2367  xCopyContextsFrom( pSrc );
[1200]2368}
[56]2369
[1200]2370Void TDecSbac::load ( const TDecSbac* pSrc )
2371{
2372  xCopyFrom(pSrc);
[56]2373}
2374
[1200]2375Void TDecSbac::loadContexts ( const TDecSbac* pSrc )
[56]2376{
[1200]2377  xCopyContextsFrom(pSrc);
[56]2378}
2379
[1200]2380/** Performs CABAC decoding of the explicit RDPCM mode
2381 * \param rTu current TU data structure
2382 * \param compID component identifier
2383 */
2384Void TDecSbac::parseExplicitRdpcmMode( TComTU &rTu, ComponentID compID )
[56]2385{
[1200]2386  TComDataCU* cu = rTu.getCU();
2387  const UInt absPartIdx=rTu.GetAbsPartIdxTU(compID);
2388  const TComRectangle &rect = rTu.getRect(compID);
2389  const UInt tuHeight = g_aucConvertToBit[rect.height];
2390  const UInt tuWidth  = g_aucConvertToBit[rect.width];
2391  UInt code = 0;
2392
2393  assert(tuHeight == tuWidth);
2394
2395#if RExt__DECODER_DEBUG_BIT_STATISTICS
2396  const TComCodingStatisticsClassType ctype(STATS__EXPLICIT_RDPCM_BITS, g_aucConvertToBit[cu->getSlice()->getSPS()->getMaxCUWidth()>>rTu.GetTransformDepthTotal()]+2);
2397#endif
2398
2399  m_pcTDecBinIf->decodeBin(code, m_explicitRdpcmFlagSCModel.get (0, toChannelType(compID), 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype));
2400
2401  if(code == 0)
2402  {
2403    cu->setExplicitRdpcmModePartRange( RDPCM_OFF, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID));
2404  }
2405  else
2406  {
2407    m_pcTDecBinIf->decodeBin(code, m_explicitRdpcmDirSCModel.get (0, toChannelType(compID), 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype));
2408    if(code == 0)
2409    {
2410      cu->setExplicitRdpcmModePartRange( RDPCM_HOR, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID));
2411    }
2412    else
2413    {
2414      cu->setExplicitRdpcmModePartRange( RDPCM_VER, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID));
2415    }
2416  }
[56]2417}
2418
[608]2419#if H_3D_ARP
2420Void TDecSbac::parseARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
[56]2421{
[608]2422  UInt uiMaxW = pcCU->getSlice()->getARPStepNum() - 1;
2423  UInt uiW = 0;
2424  UInt uiOffset = pcCU->getCTXARPWFlag(uiAbsPartIdx);
2425  UInt uiCode = 0;
[56]2426
[608]2427  assert ( uiMaxW > 0 );
[56]2428
[608]2429  m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPWSCModel.get( 0, 0, 0 + uiOffset ) );
[2]2430
[608]2431  uiW = uiCode;
2432  if( 1 == uiW )   
[56]2433  {
[833]2434    m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPWSCModel.get( 0, 0, 2 ) );
[608]2435    uiW += ( 1 == uiCode ? 1 : 0 );
[56]2436  }
[608]2437#if H_MV_ENC_DEC_TRAC
2438  DTRACE_CU("iv_res_pred_weight_idx", uiW )
2439#endif
2440  pcCU->setARPWSubParts( ( UChar )( uiW ) , uiAbsPartIdx, uiDepth ); 
[2]2441}
2442#endif
[56]2443
[608]2444#if H_3D_IC
2445/** parse illumination compensation flag
2446 * \param pcCU
2447 * \param uiAbsPartIdx
2448 * \param uiDepth
2449 * \returns Void
2450 */
2451Void TDecSbac::parseICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2452{ 
2453  UInt uiSymbol = 0;
[833]2454  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUICFlagSCModel.get( 0, 0, 0 ) );
[608]2455#if !H_MV_ENC_DEC_TRAC
2456  DTRACE_CABAC_VL( g_nSymbolCounter++ );
2457  DTRACE_CABAC_T( "\tICFlag" );
2458  DTRACE_CABAC_T( "\tuiCtxIC: ");
2459  DTRACE_CABAC_V( uiCtxIC );
2460  DTRACE_CABAC_T( "\tuiSymbol: ");
2461  DTRACE_CABAC_V( uiSymbol );
2462  DTRACE_CABAC_T( "\n");
2463#else
2464  DTRACE_CU("ic_flag", uiSymbol)
[56]2465#endif
[608]2466 
2467  pcCU->setICFlagSubParts( uiSymbol ? true : false , uiAbsPartIdx, 0, uiDepth );
[296]2468}
2469#endif
2470
[655]2471#if H_3D_INTER_SDC
[833]2472Void TDecSbac::parseDeltaDC( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
2473{
2474  if( ! ( pcCU->getSDCFlag( absPartIdx ) || ( pcCU->isIntra( absPartIdx ) && getDimType( pcCU->getLumaIntraDir( absPartIdx ) ) < DIM_NUM_TYPE ) ) )
2475  {
2476    assert( 0 );
2477  }
2478
[1039]2479  UInt symbol = 1;
2480  UInt uiNumSegments = isDimMode( pcCU->getLumaIntraDir( absPartIdx ) ) ? 2 : 1;
[833]2481
[1039]2482  if( pcCU->isIntra( absPartIdx ) && pcCU->getSDCFlag( absPartIdx ))
2483  {
[1084]2484
[950]2485    m_pcTDecBinIf->decodeBin( symbol, m_cDdcFlagSCModel.get( 0, 0, 0 ) );
[833]2486      assert( pcCU->getPartitionSize( absPartIdx ) == SIZE_2Nx2N );
2487      pcCU->setTrIdxSubParts( 0, absPartIdx, depth );
2488      pcCU->setCbfSubParts( 1, 1, 1, absPartIdx, depth );
2489    }
2490
2491  for( UInt segment = 0; segment < uiNumSegments; segment++ )
2492  {
2493    Pel valDeltaDC = 0;
2494    if( symbol )
2495    {
2496      xParseDimDeltaDC( valDeltaDC, uiNumSegments );
2497    }
2498
2499    if( pcCU->isIntra( absPartIdx ) )
2500    {
2501      UInt dir     = pcCU->getLumaIntraDir( absPartIdx );
2502
2503      if( pcCU->getSDCFlag( absPartIdx ) )
2504      {
2505        pcCU->setSDCSegmentDCOffset( valDeltaDC, segment, absPartIdx );
2506      }
2507      else
2508      {
2509        pcCU->setDimDeltaDC( getDimType( dir ), segment, absPartIdx, valDeltaDC );
2510      }
2511    }
2512    else
2513    {
2514      pcCU->setSDCSegmentDCOffset( valDeltaDC, segment, absPartIdx );
2515    }
2516  }
2517}
2518
2519Void TDecSbac::parseSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2520{
2521  UInt uiSymbol = 0;
2522  UInt uiCtxSDCFlag = pcCU->getCtxSDCFlag( uiAbsPartIdx );
2523
2524  m_pcTDecBinIf->decodeBin( uiSymbol, m_cSDCFlagSCModel.get( 0, 0, uiCtxSDCFlag ) );
[1179]2525  DTRACE_CU("dc_only_flag", uiSymbol)
[833]2526  if( uiSymbol )
2527  {
2528    pcCU->setSDCFlagSubParts( true, uiAbsPartIdx, uiDepth );
2529    pcCU->setTrIdxSubParts( 0, uiAbsPartIdx, uiDepth );
2530    pcCU->setCbfSubParts( 1, 1, 1, uiAbsPartIdx, uiDepth );
2531  }
2532  else
2533  {
2534    pcCU->setSDCFlagSubParts( false, uiAbsPartIdx, uiDepth );
2535  }
2536}
[100]2537
[189]2538#endif
2539
[1222]2540#if NH_3D_DBBP
[833]2541Void TDecSbac::parseDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2542{
[1124]2543  AOF( pcCU->getSlice()->getDepthBasedBlkPartFlag() );
[833]2544  AOF( !pcCU->getSlice()->getIsDepth() );
2545 
2546  UInt uiSymbol = 0;
2547 
[1229]2548  m_pcTDecBinIf->decodeBin( uiSymbol, m_cDBBPFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MERGE_INDEX) );
[1179]2549  DTRACE_CU("dbbp_flag", uiSymbol)
[1039]2550  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
2551  AOF( ePartSize == SIZE_2NxN || ePartSize == SIZE_Nx2N );
[1222]2552  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxTotalCUDepth() - uiDepth ) << 1 ) ) >> 4;
[1039]2553  pcCU->setDBBPFlagSubParts(uiSymbol, uiAbsPartIdx, 0, uiDepth);
2554  pcCU->setDBBPFlagSubParts(uiSymbol, uiAbsPartIdx+uiPUOffset, 1, uiDepth);
[833]2555}
2556#endif
2557
[872]2558
[56]2559//! \}
Note: See TracBrowser for help on using the repository browser.