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

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