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

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