source: 3DVCSoftware/branches/HTM-14.1-update-dev3/source/Lib/TLibDecoder/TDecSbac.cpp @ 1270

Last change on this file since 1270 was 1270, checked in by tech, 9 years ago

Merged 14.1-update-dev4-Qualcomm@1266

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