source: 3DVCSoftware/branches/HTM-10.2-dev3-Qualcomm/source/Lib/TLibDecoder/TDecSbac.cpp @ 914

Last change on this file since 914 was 914, checked in by qualcomm, 10 years ago

Integration of H0131

  • Property svn:eol-style set to native
File size: 66.1 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-2014, 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
40//! \ingroup TLibDecoder
41//! \{
42
43//////////////////////////////////////////////////////////////////////
44// Construction/Destruction
45//////////////////////////////////////////////////////////////////////
46
47TDecSbac::TDecSbac() 
48// new structure here
49: m_pcBitstream               ( 0 )
50, m_pcTDecBinIf               ( NULL )
51, m_numContextModels          ( 0 )
52, m_cCUSplitFlagSCModel       ( 1,             1,               NUM_SPLIT_FLAG_CTX            , m_contextModels + m_numContextModels, m_numContextModels )
53, m_cCUSkipFlagSCModel        ( 1,             1,               NUM_SKIP_FLAG_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
54, m_cCUMergeFlagExtSCModel    ( 1,             1,               NUM_MERGE_FLAG_EXT_CTX        , m_contextModels + m_numContextModels, m_numContextModels)
55, m_cCUMergeIdxExtSCModel     ( 1,             1,               NUM_MERGE_IDX_EXT_CTX         , m_contextModels + m_numContextModels, m_numContextModels)
56#if H_3D_ARP
57, m_cCUPUARPWSCModel          ( 1,             1,               NUM_ARPW_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
58#endif
59#if H_3D_IC
60, m_cCUICFlagSCModel          ( 1,             1,               NUM_IC_FLAG_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
61#endif
62, m_cCUPartSizeSCModel        ( 1,             1,               NUM_PART_SIZE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
63, m_cCUPredModeSCModel        ( 1,             1,               NUM_PRED_MODE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
64, m_cCUIntraPredSCModel       ( 1,             1,               NUM_ADI_CTX                   , m_contextModels + m_numContextModels, m_numContextModels)
65, m_cCUChromaPredSCModel      ( 1,             1,               NUM_CHROMA_PRED_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
66, m_cCUDeltaQpSCModel         ( 1,             1,               NUM_DELTA_QP_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
67, m_cCUInterDirSCModel        ( 1,             1,               NUM_INTER_DIR_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
68, m_cCURefPicSCModel          ( 1,             1,               NUM_REF_NO_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
69, m_cCUMvdSCModel             ( 1,             1,               NUM_MV_RES_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
70, m_cCUQtCbfSCModel           ( 1,             2,               NUM_QT_CBF_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
71, m_cCUTransSubdivFlagSCModel ( 1,             1,               NUM_TRANS_SUBDIV_FLAG_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
72, m_cCUQtRootCbfSCModel       ( 1,             1,               NUM_QT_ROOT_CBF_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
73, m_cCUSigCoeffGroupSCModel   ( 1,             2,               NUM_SIG_CG_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
74, m_cCUSigSCModel             ( 1,             1,               NUM_SIG_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
75, m_cCuCtxLastX               ( 1,             2,               NUM_CTX_LAST_FLAG_XY          , m_contextModels + m_numContextModels, m_numContextModels)
76, m_cCuCtxLastY               ( 1,             2,               NUM_CTX_LAST_FLAG_XY          , m_contextModels + m_numContextModels, m_numContextModels)
77, m_cCUOneSCModel             ( 1,             1,               NUM_ONE_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
78, m_cCUAbsSCModel             ( 1,             1,               NUM_ABS_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
79, m_cMVPIdxSCModel            ( 1,             1,               NUM_MVP_IDX_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
80, m_cSaoMergeSCModel      ( 1,             1,               NUM_SAO_MERGE_FLAG_CTX   , m_contextModels + m_numContextModels, m_numContextModels)
81, m_cSaoTypeIdxSCModel        ( 1,             1,               NUM_SAO_TYPE_IDX_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
82, m_cTransformSkipSCModel     ( 1,             2,               NUM_TRANSFORMSKIP_FLAG_CTX    , m_contextModels + m_numContextModels, m_numContextModels)
83, m_CUTransquantBypassFlagSCModel( 1,          1,               NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
84#if H_3D_DIM
85, m_cDepthIntraModeSCModel    ( 1,             1,               NUM_DEPTH_INTRA_MODE_CTX      , m_contextModels + m_numContextModels, m_numContextModels)
86, m_cDdcFlagSCModel           ( 1,             1,               NUM_DDC_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
87, m_cDdcDataSCModel           ( 1,             1,               NUM_DDC_DATA_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
88, m_cAngleFlagSCModel         ( 1,             1,               NUM_ANGLE_FLAG_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
89#if H_3D_DIM_DMM && !MTK_DMM_SIMP_CODE_H0092
90, m_cDmm1DataSCModel          ( 1,             1,               NUM_DMM1_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
91#endif
92#if H_3D_DIM_SDC
93, m_cSDCResidualFlagSCModel     ( 1,             1,             SDC_NUM_RESIDUAL_FLAG_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
94, m_cSDCResidualSCModel         ( 1,             1,             SDC_NUM_RESIDUAL_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
95#endif
96#endif
97#if H_3D_DIM_SDC
98, m_cSDCFlagSCModel                  ( 1,             1,  NUM_SDC_FLAG_CTX                 , m_contextModels + m_numContextModels, m_numContextModels)
99#endif
100#if H_3D_DBBP
101, m_cDBBPFlagSCModel             ( 1,             1,                 DBBP_NUM_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
102#endif
103{
104  assert( m_numContextModels <= MAX_NUM_CTX_MOD );
105}
106
107TDecSbac::~TDecSbac()
108{
109}
110
111// ====================================================================================================================
112// Public member functions
113// ====================================================================================================================
114
115Void TDecSbac::resetEntropy(TComSlice* pSlice)
116{
117  SliceType sliceType  = pSlice->getSliceType();
118  Int       qp         = pSlice->getSliceQp();
119
120  if (pSlice->getPPS()->getCabacInitPresentFlag() && pSlice->getCabacInitFlag())
121  {
122    switch (sliceType)
123    {
124    case P_SLICE:           // change initialization table to B_SLICE initialization
125      sliceType = B_SLICE; 
126      break;
127    case B_SLICE:           // change initialization table to P_SLICE initialization
128      sliceType = P_SLICE; 
129      break;
130    default     :           // should not occur
131      assert(0);
132    }
133  }
134
135  m_cCUSplitFlagSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_SPLIT_FLAG );
136  m_cCUSkipFlagSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SKIP_FLAG );
137  m_cCUMergeFlagExtSCModel.initBuffer    ( sliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT );
138  m_cCUMergeIdxExtSCModel.initBuffer     ( sliceType, qp, (UChar*)INIT_MERGE_IDX_EXT );
139#if H_3D_ARP
140  m_cCUPUARPWSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_ARPW );
141#endif
142#if H_3D_IC
143  m_cCUICFlagSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_IC_FLAG );
144#endif
145  m_cCUPartSizeSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_PART_SIZE );
146  m_cCUPredModeSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_PRED_MODE );
147  m_cCUIntraPredSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_INTRA_PRED_MODE );
148  m_cCUChromaPredSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE );
149  m_cCUInterDirSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_INTER_DIR );
150  m_cCUMvdSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_MVD );
151  m_cCURefPicSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_REF_PIC );
152  m_cCUDeltaQpSCModel.initBuffer         ( sliceType, qp, (UChar*)INIT_DQP );
153  m_cCUQtCbfSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_QT_CBF );
154  m_cCUQtRootCbfSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_QT_ROOT_CBF );
155  m_cCUSigCoeffGroupSCModel.initBuffer   ( sliceType, qp, (UChar*)INIT_SIG_CG_FLAG );
156  m_cCUSigSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_SIG_FLAG );
157  m_cCuCtxLastX.initBuffer               ( sliceType, qp, (UChar*)INIT_LAST );
158  m_cCuCtxLastY.initBuffer               ( sliceType, qp, (UChar*)INIT_LAST );
159  m_cCUOneSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_ONE_FLAG );
160  m_cCUAbsSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_ABS_FLAG );
161  m_cMVPIdxSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_MVP_IDX );
162  m_cSaoMergeSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG );
163  m_cSaoTypeIdxSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
164
165  m_cCUTransSubdivFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
166  m_cTransformSkipSCModel.initBuffer     ( sliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
167  m_CUTransquantBypassFlagSCModel.initBuffer( sliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
168#if H_3D_DIM
169  m_cDepthIntraModeSCModel.initBuffer    ( sliceType, qp, (UChar*)INIT_DEPTH_INTRA_MODE );
170  m_cDdcFlagSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DDC_FLAG );
171  m_cDdcDataSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DDC_DATA );
172  m_cAngleFlagSCModel.initBuffer         ( sliceType, qp, (UChar*)INIT_ANGLE_FLAG );
173#if H_3D_DIM_DMM && !MTK_DMM_SIMP_CODE_H0092
174  m_cDmm1DataSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_DMM1_DATA );
175#endif
176#if H_3D_DIM_SDC
177  m_cSDCResidualFlagSCModel.initBuffer    ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
178  m_cSDCResidualSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL );
179#endif
180#endif
181#if H_3D_DIM_SDC
182  m_cSDCFlagSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_SDC_FLAG );
183#endif
184#if H_3D_DBBP
185  m_cDBBPFlagSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_DBBP_FLAG );
186#endif
187  m_uiLastDQpNonZero  = 0;
188 
189  // new structure
190  m_uiLastQp          = qp;
191 
192  m_pcTDecBinIf->start();
193}
194
195/** The function does the following: Read out terminate bit. Flush CABAC. Byte-align for next tile.
196 *  Intialize CABAC states. Start CABAC.
197 */
198Void TDecSbac::updateContextTables( SliceType eSliceType, Int iQp )
199{
200  UInt uiBit;
201  m_pcTDecBinIf->decodeBinTrm(uiBit);
202  assert(uiBit); // end_of_sub_stream_one_bit must be equal to 1
203  m_pcTDecBinIf->finish(); 
204  m_pcBitstream->readOutTrailingBits();
205  m_cCUSplitFlagSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG );
206  m_cCUSkipFlagSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG );
207  m_cCUMergeFlagExtSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT );
208  m_cCUMergeIdxExtSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT );
209#if H_3D_ARP
210  m_cCUPUARPWSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_ARPW );
211#endif
212#if H_3D_IC
213  m_cCUICFlagSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_IC_FLAG );
214#endif
215  m_cCUPartSizeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PART_SIZE );
216  m_cCUPredModeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PRED_MODE );
217  m_cCUIntraPredSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE );
218  m_cCUChromaPredSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE );
219  m_cCUInterDirSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_INTER_DIR );
220  m_cCUMvdSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_MVD );
221  m_cCURefPicSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_REF_PIC );
222  m_cCUDeltaQpSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_DQP );
223  m_cCUQtCbfSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_QT_CBF );
224  m_cCUQtRootCbfSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF );
225  m_cCUSigCoeffGroupSCModel.initBuffer   ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG );
226  m_cCUSigSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG );
227  m_cCuCtxLastX.initBuffer               ( eSliceType, iQp, (UChar*)INIT_LAST );
228  m_cCuCtxLastY.initBuffer               ( eSliceType, iQp, (UChar*)INIT_LAST );
229  m_cCUOneSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG );
230  m_cCUAbsSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG );
231  m_cMVPIdxSCModel.initBuffer            ( eSliceType, iQp, (UChar*)INIT_MVP_IDX );
232  m_cSaoMergeSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG );
233  m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
234  m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
235  m_cTransformSkipSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
236  m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
237
238#if H_3D_DIM
239  m_cDepthIntraModeSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE );
240  m_cDdcFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG );
241  m_cDdcDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_DATA );
242  m_cAngleFlagSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_ANGLE_FLAG );
243#if H_3D_DIM_DMM && !MTK_DMM_SIMP_CODE_H0092
244  m_cDmm1DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA );
245#endif
246#if H_3D_DIM_SDC
247  m_cSDCResidualFlagSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
248  m_cSDCResidualSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL );
249#endif
250#endif
251#if H_3D_DIM_SDC
252  m_cSDCFlagSCModel.initBuffer            ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG );
253#endif
254#if H_3D_DBBP
255  m_cDBBPFlagSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_DBBP_FLAG );
256#endif
257  m_pcTDecBinIf->start();
258}
259
260Void TDecSbac::parseTerminatingBit( UInt& ruiBit )
261{
262  m_pcTDecBinIf->decodeBinTrm( ruiBit );
263  if ( ruiBit )
264  {
265    m_pcTDecBinIf->finish();
266  }
267}
268
269
270Void TDecSbac::xReadUnaryMaxSymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol )
271{
272  if (uiMaxSymbol == 0)
273  {
274    ruiSymbol = 0;
275    return;
276  }
277 
278  m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] );
279 
280  if( ruiSymbol == 0 || uiMaxSymbol == 1 )
281  {
282    return;
283  }
284 
285  UInt uiSymbol = 0;
286  UInt uiCont;
287 
288  do
289  {
290    m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] );
291    uiSymbol++;
292  }
293  while( uiCont && ( uiSymbol < uiMaxSymbol - 1 ) );
294 
295  if( uiCont && ( uiSymbol == uiMaxSymbol - 1 ) )
296  {
297    uiSymbol++;
298  }
299 
300  ruiSymbol = uiSymbol;
301}
302
303Void TDecSbac::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount )
304{
305  UInt uiSymbol = 0;
306  UInt uiBit = 1;
307 
308  while( uiBit )
309  {
310    m_pcTDecBinIf->decodeBinEP( uiBit );
311    uiSymbol += uiBit << uiCount++;
312  }
313 
314  if ( --uiCount )
315  {
316    UInt bins;
317    m_pcTDecBinIf->decodeBinsEP( bins, uiCount );
318    uiSymbol += bins;
319  }
320 
321  ruiSymbol = uiSymbol;
322}
323
324Void TDecSbac::xReadUnarySymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset )
325{
326  m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] );
327 
328  if( !ruiSymbol )
329  {
330    return;
331  }
332 
333  UInt uiSymbol = 0;
334  UInt uiCont;
335 
336  do
337  {
338    m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] );
339    uiSymbol++;
340  }
341  while( uiCont );
342 
343  ruiSymbol = uiSymbol;
344}
345
346
347/** Parsing of coeff_abs_level_remaing
348 * \param ruiSymbol reference to coeff_abs_level_remaing
349 * \param ruiParam reference to parameter
350 * \returns Void
351 */
352Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam )
353{
354
355  UInt prefix   = 0;
356  UInt codeWord = 0;
357  do
358  {
359    prefix++;
360    m_pcTDecBinIf->decodeBinEP( codeWord );
361  }
362  while( codeWord);
363  codeWord  = 1 - codeWord;
364  prefix -= codeWord;
365  codeWord=0;
366  if (prefix < COEF_REMAIN_BIN_REDUCTION )
367  {
368    m_pcTDecBinIf->decodeBinsEP(codeWord,rParam);
369    rSymbol = (prefix<<rParam) + codeWord;
370  }
371  else
372  {
373    m_pcTDecBinIf->decodeBinsEP(codeWord,prefix-COEF_REMAIN_BIN_REDUCTION+rParam);
374    rSymbol = (((1<<(prefix-COEF_REMAIN_BIN_REDUCTION))+COEF_REMAIN_BIN_REDUCTION-1)<<rParam)+codeWord;
375  }
376}
377
378#if H_3D_DIM
379Void TDecSbac::xReadExGolombLevel( UInt& ruiSymbol, ContextModel& rcSCModel  )
380{
381  UInt uiSymbol;
382  UInt uiCount = 0;
383  do
384  {
385    m_pcTDecBinIf->decodeBin( uiSymbol, rcSCModel );
386    uiCount++;
387  }
388#if QC_SIMP_DELTADC_CODING_H0131
389  while( uiSymbol && ( uiCount != 3 ) );
390#else
391  while( uiSymbol && ( uiCount != 13 ) );
392#endif
393  ruiSymbol = uiCount - 1;
394
395  if( uiSymbol )
396  {
397    xReadEpExGolomb( uiSymbol, 0 );
398    ruiSymbol += uiSymbol + 1;
399  }
400
401  return;
402}
403
404Void TDecSbac::xParseDimDeltaDC( Pel& rValDeltaDC, UInt uiNumSeg )
405{
406  UInt absValDeltaDC = 0;
407  xReadExGolombLevel( absValDeltaDC, m_cDdcDataSCModel.get(0, 0, 0) );
408  rValDeltaDC = (Pel)absValDeltaDC + ( uiNumSeg > 1 ? 0 : 1 );
409
410  if( rValDeltaDC != 0 )
411  {
412    UInt uiSign;
413    m_pcTDecBinIf->decodeBinEP( uiSign );
414    if ( uiSign )
415    {
416      rValDeltaDC = -rValDeltaDC;
417    }
418  }
419}
420
421
422#if H_3D_DIM_DMM
423Void TDecSbac::xParseDmm1WedgeIdx( UInt& ruiTabIdx, Int iNumBit )
424{
425  UInt uiSymbol, uiIdx = 0;
426  for( Int i = 0; i < iNumBit; i++ )
427  {
428#if MTK_DMM_SIMP_CODE_H0092
429      m_pcTDecBinIf->decodeBinEP( uiSymbol );
430#else
431      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmm1DataSCModel.get(0, 0, 0) );
432#endif
433    uiIdx += uiSymbol << i;
434  }
435  ruiTabIdx = uiIdx;
436}
437#endif
438
439#if H_3D_DIM_SDC
440Void TDecSbac::xParseSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSegment )
441{
442  assert( pcCU->getSlice()->getIsDepth() );
443  assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
444  assert( pcCU->getSDCFlag(uiAbsPartIdx) );
445  assert( uiSegment < 2 );
446 
447  UInt uiResidual = 0;
448  UInt uiBit      = 0;
449  UInt uiAbsIdx   = 0;
450  UInt uiSign     = 0;
451  Int  iIdx       = 0;
452 
453#if H_3D_DIM_DLT
454  UInt uiMaxResidualBits = pcCU->getSlice()->getPPS()->getDLT()->getBitsPerDepthValue( pcCU->getSlice()->getLayerIdInVps() );
455#else
456  UInt uiMaxResidualBits = g_bitDepthY;
457#endif
458  assert( uiMaxResidualBits <= g_bitDepthY );
459 
460  m_pcTDecBinIf->decodeBin(uiResidual, m_cSDCResidualFlagSCModel.get( 0, 0, 0 ) );
461 
462#if H_MV_ENC_DEC_TRAC
463  DTRACE_CU("sdc_residual_flag[i]", uiResidual)
464#endif
465 
466  if (uiResidual)
467  {
468    // decode residual sign bit
469    m_pcTDecBinIf->decodeBinEP(uiSign);
470#if H_MV_ENC_DEC_TRAC
471    DTRACE_CU("sdc_residual_sign_flag[i]", uiSign)
472#endif
473   
474    // decode residual magnitude
475    // prefix part
476    UInt uiCount = 0;
477#if H_3D_DIM_DLT
478    UInt uiNumDepthValues = pcCU->getSlice()->getPPS()->getDLT()->getNumDepthValues( pcCU->getSlice()->getLayerIdInVps() );
479#else
480    UInt uiNumDepthValues = ((1 << g_bitDepthY)-1);
481#endif
482    UInt uiPrefixThreshold = ((uiNumDepthValues * 3) >> 2);
483    for ( UInt ui = 0; ui < uiPrefixThreshold; ui++)
484    {
485      m_pcTDecBinIf->decodeBin( uiBit, m_cSDCResidualSCModel.get(0, 0, 0) );
486      if ( uiBit == 0 )
487        break;
488      else
489        uiCount++;
490    }
491    // suffix part
492    if ( uiCount == uiPrefixThreshold )
493    {
494      for ( UInt ui = 0; ui < numBitsForValue(uiNumDepthValues - uiPrefixThreshold); ui++ )
495      {
496        m_pcTDecBinIf->decodeBinEP( uiBit );
497        uiAbsIdx |= uiBit << ui;
498      }
499      uiAbsIdx += uiCount;
500    }
501    else
502    {
503      uiAbsIdx = uiCount;
504    }
505 
506#if H_MV_ENC_DEC_TRAC
507    DTRACE_CU("sdc_residual_abs_minus1[i]", uiAbsIdx)
508#endif
509   
510    uiAbsIdx += 1;
511    iIdx =(Int)(uiSign ? -1 : 1)*uiAbsIdx;
512  }
513 
514  pcCU->setSDCSegmentDCOffset(iIdx, uiSegment, uiAbsPartIdx);
515}
516#endif
517#endif
518
519/** Parse I_PCM information.
520 * \param pcCU
521 * \param uiAbsPartIdx
522 * \param uiDepth
523 * \returns Void
524 *
525 * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes.
526 */
527Void TDecSbac::parseIPCMInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
528{
529  UInt uiSymbol;
530
531    m_pcTDecBinIf->decodeBinTrm(uiSymbol);
532
533#if H_MV_ENC_DEC_TRAC
534      DTRACE_CU("pcm_flag", uiSymbol)
535#endif
536    if (uiSymbol)
537    {
538    Bool bIpcmFlag = true;
539
540    pcCU->setPartSizeSubParts  ( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
541    pcCU->setSizeSubParts      ( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
542    pcCU->setTrIdxSubParts     ( 0, uiAbsPartIdx, uiDepth );
543    pcCU->setIPCMFlagSubParts  ( bIpcmFlag, uiAbsPartIdx, uiDepth );
544
545    UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
546    UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
547    UInt uiChromaOffset = uiLumaOffset>>2;
548
549    Pel* piPCMSample;
550    UInt uiWidth;
551    UInt uiHeight;
552    UInt uiSampleBits;
553    UInt uiX, uiY;
554
555    piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset;
556    uiWidth = pcCU->getWidth(uiAbsPartIdx);
557    uiHeight = pcCU->getHeight(uiAbsPartIdx);
558    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
559
560    for(uiY = 0; uiY < uiHeight; uiY++)
561    {
562      for(uiX = 0; uiX < uiWidth; uiX++)
563      {
564        UInt uiSample;
565        m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
566        piPCMSample[uiX] = uiSample;
567      }
568      piPCMSample += uiWidth;
569    }
570
571    piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset;
572    uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
573    uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
574    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
575
576    for(uiY = 0; uiY < uiHeight; uiY++)
577    {
578      for(uiX = 0; uiX < uiWidth; uiX++)
579      {
580        UInt uiSample;
581        m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
582        piPCMSample[uiX] = uiSample;
583      }
584      piPCMSample += uiWidth;
585    }
586
587    piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset;
588    uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
589    uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
590    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
591
592    for(uiY = 0; uiY < uiHeight; uiY++)
593    {
594      for(uiX = 0; uiX < uiWidth; uiX++)
595      {
596        UInt uiSample;
597        m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
598        piPCMSample[uiX] = uiSample;
599      }
600      piPCMSample += uiWidth;
601    }
602
603    m_pcTDecBinIf->start();
604  }
605}
606
607Void TDecSbac::parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
608{
609  UInt uiSymbol;
610  m_pcTDecBinIf->decodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) );
611#if H_MV_ENC_DEC_TRAC
612  DTRACE_CU("cu_transquant_bypass_flag", uiSymbol); 
613#endif
614  pcCU->setCUTransquantBypassSubParts(uiSymbol ? true : false, uiAbsPartIdx, uiDepth);
615}
616
617/** parse skip flag
618 * \param pcCU
619 * \param uiAbsPartIdx
620 * \param uiDepth
621 * \returns Void
622 */
623Void TDecSbac::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
624{
625  if( pcCU->getSlice()->isIntra() )
626  {
627    return;
628  }
629 
630  UInt uiSymbol = 0;
631  UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx );
632  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) );
633#if !H_MV_ENC_DEC_TRAC
634  DTRACE_CABAC_VL( g_nSymbolCounter++ );
635  DTRACE_CABAC_T( "\tSkipFlag" );
636  DTRACE_CABAC_T( "\tuiCtxSkip: ");
637  DTRACE_CABAC_V( uiCtxSkip );
638  DTRACE_CABAC_T( "\tuiSymbol: ");
639  DTRACE_CABAC_V( uiSymbol );
640  DTRACE_CABAC_T( "\n");
641#endif
642 
643  if( uiSymbol )
644  {
645    pcCU->setSkipFlagSubParts( true,        uiAbsPartIdx, uiDepth );
646    pcCU->setPredModeSubParts( MODE_INTER,  uiAbsPartIdx, uiDepth );
647    pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
648    pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
649    pcCU->setMergeFlagSubParts( true , uiAbsPartIdx, 0, uiDepth );
650  }
651#if H_MV_ENC_DEC_TRAC
652  DTRACE_CU("cu_skip_flag", uiSymbol); 
653#endif
654}
655
656/** parse merge flag
657 * \param pcCU
658 * \param uiAbsPartIdx
659 * \param uiDepth
660 * \param uiPUIdx
661 * \returns Void
662 */
663Void TDecSbac::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
664{
665  UInt uiSymbol;
666  m_pcTDecBinIf->decodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) );
667#if H_MV_ENC_DEC_TRAC
668  DTRACE_PU("merge_flag", uiSymbol)
669#endif
670  pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth );
671
672#if !H_MV_ENC_DEC_TRAC
673  DTRACE_CABAC_VL( g_nSymbolCounter++ );
674  DTRACE_CABAC_T( "\tMergeFlag: " );
675  DTRACE_CABAC_V( uiSymbol );
676  DTRACE_CABAC_T( "\tAddress: " );
677  DTRACE_CABAC_V( pcCU->getAddr() );
678  DTRACE_CABAC_T( "\tuiAbsPartIdx: " );
679  DTRACE_CABAC_V( uiAbsPartIdx );
680  DTRACE_CABAC_T( "\n" );
681#endif
682}
683
684Void TDecSbac::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex )
685{
686  UInt uiUnaryIdx = 0;
687  UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand();
688  if ( uiNumCand > 1 )
689  {
690    for( ; uiUnaryIdx < uiNumCand - 1; ++uiUnaryIdx )
691    {
692      UInt uiSymbol = 0;
693      if ( uiUnaryIdx==0 )
694      {
695        m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) );
696      }
697      else
698      {
699        m_pcTDecBinIf->decodeBinEP( uiSymbol );
700      }
701      if( uiSymbol == 0 )
702      {
703        break;
704      }
705    }
706#if H_MV_ENC_DEC_TRAC
707    DTRACE_PU("merge_idx", uiUnaryIdx)
708#endif
709  }
710  ruiMergeIndex = uiUnaryIdx;
711
712#if !H_MV_ENC_DEC_TRAC
713  DTRACE_CABAC_VL( g_nSymbolCounter++ )
714  DTRACE_CABAC_T( "\tparseMergeIndex()" )
715  DTRACE_CABAC_T( "\tuiMRGIdx= " )
716  DTRACE_CABAC_V( ruiMergeIndex )
717  DTRACE_CABAC_T( "\n" )
718#endif
719}
720
721Void TDecSbac::parseMVPIdx      ( Int& riMVPIdx )
722{
723  UInt uiSymbol;
724  xReadUnaryMaxSymbol(uiSymbol, m_cMVPIdxSCModel.get(0), 1, AMVP_MAX_NUM_CANDS-1);
725  riMVPIdx = uiSymbol;
726}
727
728Void TDecSbac::parseSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
729{
730  if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
731  {
732    pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx );
733    return;
734  }
735
736  UInt uiSymbol;
737#if H_3D_QTLPC
738  Bool bParseSplitFlag    = true;
739
740  TComSPS *sps            = pcCU->getPic()->getSlice(0)->getSPS();
741  TComPic *pcTexture      = pcCU->getSlice()->getTexturePic();
742  Bool bDepthMapDetect    = (pcTexture != NULL);
743  Bool bIntraSliceDetect  = (pcCU->getSlice()->getSliceType() == I_SLICE);
744
745  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);
746
747  if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTL() && sps->getUsePC())
748  {
749    TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr());
750    assert(pcTextureCU->getDepth(uiAbsPartIdx) >= uiDepth);
751    bParseSplitFlag         = (pcTextureCU->getDepth(uiAbsPartIdx) > uiDepth);
752  }
753
754  if(bParseSplitFlag)
755  {
756#endif
757    m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSplitFlagSCModel.get( 0, 0, pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ) ) );
758#if H_MV_ENC_DEC_TRAC
759    DTRACE_CU("split_cu_flag", uiSymbol); 
760#else
761    DTRACE_CABAC_VL( g_nSymbolCounter++ )
762    DTRACE_CABAC_T( "\tSplitFlag\n" )
763#endif
764#if H_3D_QTLPC
765  }
766  else
767  {
768    uiSymbol = 0;
769  }
770#endif
771  pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx );
772 
773  return;
774}
775
776/** parse partition size
777 * \param pcCU
778 * \param uiAbsPartIdx
779 * \param uiDepth
780 * \returns Void
781 */
782Void TDecSbac::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
783{
784  UInt uiSymbol, uiMode = 0;
785  PartSize eMode;
786
787#if H_3D_QTLPC
788  Bool bParsePartSize    = true;
789  TComSPS *sps           = pcCU->getPic()->getSlice(0)->getSPS();
790  TComPic *pcTexture     = pcCU->getSlice()->getTexturePic();
791  Bool bDepthMapDetect   = (pcTexture != NULL);
792  Bool bIntraSliceDetect = (pcCU->getSlice()->getSliceType() == I_SLICE);
793
794  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);
795
796  Bool depthDependent = false;
797  UInt uiTexturePart = uiMode;
798  if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTL() && sps->getUsePC())
799  {
800    TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr());
801    assert(pcTextureCU->getDepth(uiAbsPartIdx) >= uiDepth);
802    if(pcTextureCU->getDepth(uiAbsPartIdx) == uiDepth )
803    {
804      depthDependent = true;
805      uiTexturePart = pcTextureCU->getPartitionSize( uiAbsPartIdx );
806    }
807    if (pcTextureCU->getDepth(uiAbsPartIdx) == uiDepth && pcTextureCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N)
808    {
809      bParsePartSize = false;
810      eMode          = SIZE_2Nx2N;
811    }
812  }
813#endif
814
815 
816  if ( pcCU->isIntra( uiAbsPartIdx ) )
817  {
818#if H_3D_QTLPC
819    if(bParsePartSize)
820    {
821#endif
822     uiSymbol = 1;
823      if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
824      {
825        m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 0) );
826#if H_MV_ENC_DEC_TRAC         
827        DTRACE_CU("part_mode", uiSymbol)
828#endif       
829      }
830      eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN;
831#if H_3D_QTLPC
832    }
833#endif
834    UInt uiTrLevel = 0;   
835    UInt uiWidthInBit  = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2;
836    UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2;
837    uiTrLevel          = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0;
838    if( eMode == SIZE_NxN )
839    {
840      pcCU->setTrIdxSubParts( 1+uiTrLevel, uiAbsPartIdx, uiDepth );
841    }
842    else
843    {
844      pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth );
845    }
846  }
847  else
848  {
849#if H_3D_QTLPC
850    if(bParsePartSize)
851    {
852      if (depthDependent==false || uiTexturePart == SIZE_NxN|| uiTexturePart == SIZE_2Nx2N)
853      {
854#endif
855      UInt uiMaxNumBits = 2;
856      if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( (g_uiMaxCUWidth>>uiDepth) == 8 && (g_uiMaxCUHeight>>uiDepth) == 8 ) )
857      {
858        uiMaxNumBits ++;
859      }
860      for ( UInt ui = 0; ui < uiMaxNumBits; ui++ )
861      {
862        m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) );
863        if ( uiSymbol )
864        {
865          break;
866        }
867        uiMode++;
868      }
869      eMode = (PartSize) uiMode;
870      if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) )
871      {
872        if (eMode == SIZE_2NxN)
873        {
874        m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
875          if (uiSymbol == 0)
876          {
877            m_pcTDecBinIf->decodeBinEP(uiSymbol);
878            eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD);
879          }
880        }
881        else if (eMode == SIZE_Nx2N)
882        {
883        m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
884          if (uiSymbol == 0)
885          {
886            m_pcTDecBinIf->decodeBinEP(uiSymbol);
887            eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N);
888          }
889        }
890      }
891#if H_3D_QTLPC
892      }
893      else if(uiTexturePart == SIZE_2NxN || uiTexturePart == SIZE_2NxnU || uiTexturePart == SIZE_2NxnD)
894      {
895        UInt uiMaxNumBits = 1;
896        if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) )
897        {
898          uiMaxNumBits ++;
899        }
900        for ( UInt ui = 0; ui < uiMaxNumBits; ui++ )
901        {
902          m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) );
903          if ( uiSymbol )
904          {
905            break;
906          }
907          uiMode++;
908        }
909        eMode = (PartSize) uiMode;
910        if(uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) && uiSymbol==1 )
911        {
912          eMode = SIZE_2NxN;
913        }
914        else if (uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth )==0  && uiSymbol==0)
915        {
916          eMode = SIZE_2NxN;
917        }
918        else if (uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) && uiSymbol==0)
919        {
920          m_pcTDecBinIf->decodeBinEP(uiSymbol);
921          eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD);
922        }
923      }
924      else if(uiTexturePart == SIZE_Nx2N|| uiTexturePart==SIZE_nLx2N || uiTexturePart==SIZE_nRx2N)
925      {
926        UInt uiMaxNumBits = 1;
927        if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) )
928        {
929          uiMaxNumBits ++;
930        }
931        for ( UInt ui = 0; ui < uiMaxNumBits; ui++ )
932        {
933          m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) );
934          if ( uiSymbol )
935          {
936            break;
937          }
938          uiMode++;
939        }
940        eMode = (PartSize) uiMode;
941        if(uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) && uiSymbol==1 )
942        {
943          eMode = SIZE_Nx2N;
944        }
945        else if (uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth )==0  && uiSymbol==0)
946        {
947          eMode = SIZE_Nx2N;
948        }
949        else if (uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) && uiSymbol==0)
950        {
951          m_pcTDecBinIf->decodeBinEP(uiSymbol);
952          eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N);
953        }
954      }
955      else
956      {
957        assert(0);
958      }
959#if H_MV_ENC_DEC_TRAC         
960      DTRACE_CU("part_mode", eMode )
961#endif
962    }
963#endif
964  }
965  pcCU->setPartSizeSubParts( eMode, uiAbsPartIdx, uiDepth );
966  pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
967}
968
969/** parse prediction mode
970 * \param pcCU
971 * \param uiAbsPartIdx
972 * \param uiDepth
973 * \returns Void
974 */
975Void TDecSbac::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
976{
977  if( pcCU->getSlice()->isIntra() )
978  {
979    pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth );
980    return;
981  }
982 
983  UInt uiSymbol;
984  Int  iPredMode = MODE_INTER;
985  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPredModeSCModel.get( 0, 0, 0 ) );
986  iPredMode += uiSymbol;
987#if H_MV_ENC_DEC_TRAC         
988  DTRACE_CU("pred_mode_flag", uiSymbol)
989#endif       
990  pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth );
991}
992
993Void TDecSbac::parseIntraDirLumaAng  ( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
994{
995  PartSize mode = pcCU->getPartitionSize( absPartIdx );
996  UInt partNum = mode==SIZE_NxN?4:1;
997  UInt partOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2;
998  UInt mpmPred[4],symbol;
999  Int j,intraPredMode;   
1000  if (mode==SIZE_NxN)
1001  {
1002    depth++;
1003  }
1004  for (j=0;j<partNum;j++)
1005  {
1006#if H_3D_DIM
1007    if( pcCU->getSlice()->getVpsDepthModesFlag() )
1008    {
1009      parseIntraDepth( pcCU, absPartIdx+partOffset*j, depth );
1010    }
1011    if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
1012    {
1013#endif
1014    m_pcTDecBinIf->decodeBin( symbol, m_cCUIntraPredSCModel.get( 0, 0, 0) );
1015    mpmPred[j] = symbol;
1016#if H_MV_ENC_DEC_TRAC         
1017    DTRACE_CU("prev_intra_luma_pred_flag", symbol)
1018#endif
1019#if H_3D_DIM
1020    }
1021#endif
1022  }
1023  for (j=0;j<partNum;j++)
1024  {
1025#if H_3D_DIM
1026    if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
1027    {
1028#endif
1029    Int preds[3] = {-1, -1, -1};
1030    Int predNum = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds); 
1031    if (mpmPred[j])
1032    {
1033      m_pcTDecBinIf->decodeBinEP( symbol );
1034      if (symbol)
1035      {
1036        m_pcTDecBinIf->decodeBinEP( symbol );
1037        symbol++;
1038      }
1039#if H_MV_ENC_DEC_TRAC         
1040      DTRACE_CU("mpm_idx", symbol)
1041#endif
1042      intraPredMode = preds[symbol];
1043    }
1044    else
1045    {
1046      m_pcTDecBinIf->decodeBinsEP( symbol, 5 );
1047      intraPredMode = symbol;
1048#if H_MV_ENC_DEC_TRAC         
1049      DTRACE_CU("rem_intra_luma_pred_mode", symbol)
1050#endif       
1051      //postponed sorting of MPMs (only in remaining branch)
1052      if (preds[0] > preds[1])
1053      { 
1054        std::swap(preds[0], preds[1]); 
1055      }
1056      if (preds[0] > preds[2])
1057      {
1058        std::swap(preds[0], preds[2]);
1059      }
1060      if (preds[1] > preds[2])
1061      {
1062        std::swap(preds[1], preds[2]);
1063      }
1064      for ( Int i = 0; i < predNum; i++ )
1065      {
1066        intraPredMode += ( intraPredMode >= preds[i] );
1067      }
1068    }
1069    pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, absPartIdx+partOffset*j, depth );
1070#if H_3D_DIM
1071    }
1072#endif
1073  }
1074}
1075
1076Void TDecSbac::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1077{
1078  UInt uiSymbol;
1079
1080  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) );
1081
1082  if( uiSymbol == 0 )
1083  {
1084#if H_MV_ENC_DEC_TRAC         
1085    DTRACE_CU("intra_chroma_pred_mode", uiSymbol )
1086#endif       
1087    uiSymbol = DM_CHROMA_IDX;
1088  } 
1089  else 
1090  {
1091    {
1092      UInt uiIPredMode;
1093      m_pcTDecBinIf->decodeBinsEP( uiIPredMode, 2 );
1094#if H_MV_ENC_DEC_TRAC         
1095      DTRACE_CU("intra_chroma_pred_mode", uiIPredMode )
1096#endif       
1097      UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ];
1098      pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir );
1099      uiSymbol = uiAllowedChromaDir[ uiIPredMode ];
1100    }
1101  }
1102  pcCU->setChromIntraDirSubParts( uiSymbol, uiAbsPartIdx, uiDepth );
1103  return;
1104}
1105
1106#if H_3D_DIM
1107Void TDecSbac::parseIntraDepth( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
1108{
1109  parseIntraDepthMode( pcCU, absPartIdx, depth );
1110
1111  UInt dir     = pcCU->getLumaIntraDir( absPartIdx );
1112  UInt dimType = getDimType( dir );
1113
1114  switch( dimType )
1115  {
1116#if H_3D_DIM_DMM
1117  case( DMM1_IDX ):
1118    {
1119      UInt uiTabIdx = 0;
1120      xParseDmm1WedgeIdx( uiTabIdx, g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] );
1121      pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, absPartIdx, depth );
1122    } break;
1123  case( DMM4_IDX ): break;
1124#endif
1125  default: break;
1126  }
1127
1128  pcCU->setLumaIntraDirSubParts( (UChar)dir, absPartIdx, depth );
1129}
1130
1131Void TDecSbac::parseIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
1132{
1133  UInt uiSymbol, uiIsDimMode;
1134
1135  if( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() >> pcCU->getDepth( absPartIdx ) ) < 64 ) //DMM and HEVC intra modes are both allowed
1136  {
1137    m_pcTDecBinIf->decodeBin( uiSymbol, m_cAngleFlagSCModel.get( 0, 0, pcCU->getCtxAngleFlag( absPartIdx ) ) );
1138  }
1139  else
1140  {
1141    uiSymbol = 1;
1142  }
1143  uiIsDimMode = uiSymbol ? 0 : 1;
1144  pcCU->setLumaIntraDirSubParts( 0, absPartIdx, depth );
1145
1146  //decode DMM index
1147  if( uiIsDimMode )
1148  {
1149    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDepthIntraModeSCModel.get( 0, 0, 0 ) );
1150    if( !uiSymbol )
1151    {
1152      pcCU->setLumaIntraDirSubParts( ( 2 * DMM1_IDX + DIM_OFFSET ), absPartIdx, depth );
1153    }
1154    else
1155    {
1156      pcCU->setLumaIntraDirSubParts( ( 2 * DMM4_IDX + DIM_OFFSET ), absPartIdx, depth );
1157    }
1158  }
1159}
1160#endif
1161
1162Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx )
1163{
1164  UInt uiSymbol;
1165  const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx );
1166  ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 );
1167  uiSymbol = 0;
1168  if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 )
1169  {
1170    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) );
1171  }
1172
1173  if( uiSymbol )
1174  {
1175    uiSymbol = 2;
1176  }
1177  else
1178  {
1179    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + 4 ) );
1180    assert(uiSymbol == 0 || uiSymbol == 1);
1181  }
1182
1183  uiSymbol++;
1184  ruiInterDir = uiSymbol;
1185#if H_MV_ENC_DEC_TRAC
1186    DTRACE_PU("inter_pred_idc", ruiInterDir - 1 )   
1187#endif
1188
1189  return;
1190}
1191
1192Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList )
1193{
1194  UInt uiSymbol;
1195  {
1196    ContextModel *pCtx = m_cCURefPicSCModel.get( 0 );
1197    m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1198
1199    if( uiSymbol )
1200    {
1201      UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2;
1202      pCtx++;
1203      UInt ui;
1204      for( ui = 0; ui < uiRefNum; ++ui )
1205      {
1206        if( ui == 0 )
1207        {
1208          m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1209        }
1210        else
1211        {
1212          m_pcTDecBinIf->decodeBinEP( uiSymbol );
1213        }
1214        if( uiSymbol == 0 )
1215        {
1216          break;
1217        }
1218      }
1219      uiSymbol = ui + 1;
1220    }
1221    riRefFrmIdx = uiSymbol;
1222  }
1223
1224#if H_MV_ENC_DEC_TRAC
1225#if ENC_DEC_TRACE
1226  if ( eRefList == REF_PIC_LIST_0 )
1227  {
1228    DTRACE_PU("ref_idx_l0", uiSymbol)
1229  }
1230  else
1231  {
1232    DTRACE_PU("ref_idx_l1", uiSymbol)
1233  }
1234#endif
1235#endif
1236  return;
1237}
1238
1239Void TDecSbac::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList )
1240{
1241  UInt uiSymbol;
1242  UInt uiHorAbs;
1243  UInt uiVerAbs;
1244  UInt uiHorSign = 0;
1245  UInt uiVerSign = 0;
1246  ContextModel *pCtx = m_cCUMvdSCModel.get( 0 );
1247
1248  if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3)
1249  {
1250    uiHorAbs=0;
1251    uiVerAbs=0;
1252  }
1253  else
1254  {
1255    m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx );
1256    m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx );
1257
1258    const Bool bHorAbsGr0 = uiHorAbs != 0;
1259    const Bool bVerAbsGr0 = uiVerAbs != 0;
1260    pCtx++;
1261
1262    if( bHorAbsGr0 )
1263    {
1264      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1265      uiHorAbs += uiSymbol;
1266    }
1267
1268    if( bVerAbsGr0 )
1269    {
1270      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1271      uiVerAbs += uiSymbol;
1272    }
1273
1274    if( bHorAbsGr0 )
1275    {
1276      if( 2 == uiHorAbs )
1277      {
1278        xReadEpExGolomb( uiSymbol, 1 );
1279        uiHorAbs += uiSymbol;
1280      }
1281
1282      m_pcTDecBinIf->decodeBinEP( uiHorSign );
1283    }
1284
1285    if( bVerAbsGr0 )
1286    {
1287      if( 2 == uiVerAbs )
1288      {
1289        xReadEpExGolomb( uiSymbol, 1 );
1290        uiVerAbs += uiSymbol;
1291      }
1292
1293      m_pcTDecBinIf->decodeBinEP( uiVerSign );
1294    }
1295
1296  }
1297
1298  const TComMv cMv( uiHorSign ? -Int( uiHorAbs ): uiHorAbs, uiVerSign ? -Int( uiVerAbs ) : uiVerAbs );
1299  pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiDepth, uiPartIdx );
1300  return;
1301}
1302
1303
1304Void TDecSbac::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize )
1305{
1306  m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize ) );
1307#if !H_MV_ENC_DEC_TRAC
1308  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1309  DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" )
1310  DTRACE_CABAC_T( "\tsymbol=" )
1311  DTRACE_CABAC_V( ruiSubdivFlag )
1312  DTRACE_CABAC_T( "\tctx=" )
1313  DTRACE_CABAC_V( uiLog2TransformBlockSize )
1314  DTRACE_CABAC_T( "\n" )
1315#endif
1316}
1317
1318Void TDecSbac::parseQtRootCbf( UInt uiAbsPartIdx, UInt& uiQtRootCbf )
1319{
1320  UInt uiSymbol;
1321  const UInt uiCtx = 0;
1322  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) );
1323#if !H_MV_ENC_DEC_TRAC
1324  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1325  DTRACE_CABAC_T( "\tparseQtRootCbf()" )
1326  DTRACE_CABAC_T( "\tsymbol=" )
1327  DTRACE_CABAC_V( uiSymbol )
1328  DTRACE_CABAC_T( "\tctx=" )
1329  DTRACE_CABAC_V( uiCtx )
1330  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1331  DTRACE_CABAC_V( uiAbsPartIdx )
1332  DTRACE_CABAC_T( "\n" )
1333#else
1334  DTRACE_CU( "rqt_root_cbf", uiSymbol )
1335#endif
1336 
1337  uiQtRootCbf = uiSymbol;
1338}
1339
1340Void TDecSbac::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1341{
1342  Int qp;
1343  UInt uiDQp;
1344  Int  iDQp;
1345 
1346  UInt uiSymbol;
1347
1348  xReadUnaryMaxSymbol (uiDQp,  &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX);
1349
1350  if( uiDQp >= CU_DQP_TU_CMAX)
1351  {
1352    xReadEpExGolomb( uiSymbol, CU_DQP_EG_k );
1353    uiDQp+=uiSymbol;
1354  }
1355
1356  if ( uiDQp > 0 )
1357  {
1358    UInt uiSign;
1359    Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
1360    m_pcTDecBinIf->decodeBinEP(uiSign);
1361    iDQp = uiDQp;
1362    if(uiSign)
1363    {
1364      iDQp = -iDQp;
1365    }
1366    qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY;
1367  }
1368  else 
1369  {
1370    qp = pcCU->getRefQP(uiAbsPartIdx);
1371  }
1372  pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth); 
1373  pcCU->setCodedQP(qp);
1374}
1375
1376Void TDecSbac::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth )
1377{
1378  UInt uiSymbol;
1379  const UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth );
1380  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA: eType, uiCtx ) );
1381#if !H_MV_ENC_DEC_TRAC 
1382  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1383  DTRACE_CABAC_T( "\tparseQtCbf()" )
1384  DTRACE_CABAC_T( "\tsymbol=" )
1385  DTRACE_CABAC_V( uiSymbol )
1386  DTRACE_CABAC_T( "\tctx=" )
1387  DTRACE_CABAC_V( uiCtx )
1388  DTRACE_CABAC_T( "\tetype=" )
1389  DTRACE_CABAC_V( eType )
1390  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1391  DTRACE_CABAC_V( uiAbsPartIdx )
1392  DTRACE_CABAC_T( "\n" )
1393#endif
1394 
1395  pcCU->setCbfSubParts( uiSymbol << uiTrDepth, eType, uiAbsPartIdx, uiDepth );
1396}
1397
1398void TDecSbac::parseTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType)
1399{
1400  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
1401  {
1402    return;
1403  }
1404  if(width != 4 || height != 4)
1405  {
1406    return;
1407  }
1408 
1409  UInt useTransformSkip;
1410  m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) );
1411  if(eTType!= TEXT_LUMA)
1412  {
1413    const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiDepth;
1414    if(uiLog2TrafoSize == 2) 
1415    { 
1416      uiDepth --;
1417    }
1418  }
1419#if !H_MV_ENC_DEC_TRAC
1420  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1421  DTRACE_CABAC_T("\tparseTransformSkip()");
1422  DTRACE_CABAC_T( "\tsymbol=" )
1423  DTRACE_CABAC_V( useTransformSkip )
1424  DTRACE_CABAC_T( "\tAddr=" )
1425  DTRACE_CABAC_V( pcCU->getAddr() )
1426  DTRACE_CABAC_T( "\tetype=" )
1427  DTRACE_CABAC_V( eTType )
1428  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1429  DTRACE_CABAC_V( uiAbsPartIdx )
1430  DTRACE_CABAC_T( "\n" )
1431#endif
1432
1433  pcCU->setTransformSkipSubParts( useTransformSkip, eTType, uiAbsPartIdx, uiDepth);
1434}
1435
1436/** Parse (X,Y) position of the last significant coefficient
1437 * \param uiPosLastX reference to X component of last coefficient
1438 * \param uiPosLastY reference to Y component of last coefficient
1439 * \param width  Block width
1440 * \param height Block height
1441 * \param eTType plane type / luminance or chrominance
1442 * \param uiScanIdx scan type (zig-zag, hor, ver)
1443 *
1444 * This method decodes the X and Y component within a block of the last significant coefficient.
1445 */
1446Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, TextType eTType, UInt uiScanIdx )
1447{
1448  UInt uiLast;
1449  ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType );
1450  ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType );
1451
1452  Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY;
1453  blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2));
1454  blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2));
1455  shiftX= eTType ? g_aucConvertToBit[ width  ] :((g_aucConvertToBit[ width  ]+3)>>2);
1456  shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2);
1457  // posX
1458  for( uiPosLastX = 0; uiPosLastX < g_uiGroupIdx[ width - 1 ]; uiPosLastX++ )
1459  {
1460    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + blkSizeOffsetX + (uiPosLastX >>shiftX) ) );
1461    if( !uiLast )
1462    {
1463      break;
1464    }
1465  }
1466
1467  // posY
1468  for( uiPosLastY = 0; uiPosLastY < g_uiGroupIdx[ height - 1 ]; uiPosLastY++ )
1469  {
1470    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + blkSizeOffsetY + (uiPosLastY >>shiftY)) );
1471    if( !uiLast )
1472    {
1473      break;
1474    }
1475  }
1476  if ( uiPosLastX > 3 )
1477  {
1478    UInt uiTemp  = 0;
1479    UInt uiCount = ( uiPosLastX - 2 ) >> 1;
1480    for ( Int i = uiCount - 1; i >= 0; i-- )
1481    {
1482      m_pcTDecBinIf->decodeBinEP( uiLast );
1483      uiTemp += uiLast << i;
1484    }
1485    uiPosLastX = g_uiMinInGroup[ uiPosLastX ] + uiTemp;
1486  }
1487  if ( uiPosLastY > 3 )
1488  {
1489    UInt uiTemp  = 0;
1490    UInt uiCount = ( uiPosLastY - 2 ) >> 1;
1491    for ( Int i = uiCount - 1; i >= 0; i-- )
1492    {
1493      m_pcTDecBinIf->decodeBinEP( uiLast );
1494      uiTemp += uiLast << i;
1495    }
1496    uiPosLastY = g_uiMinInGroup[ uiPosLastY ] + uiTemp;
1497  }
1498 
1499  if( uiScanIdx == SCAN_VER )
1500  {
1501    swap( uiPosLastX, uiPosLastY );
1502  }
1503}
1504
1505Void TDecSbac::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType )
1506{
1507#if !H_MV_ENC_DEC_TRAC
1508  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1509  DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" )
1510  DTRACE_CABAC_V( eTType )
1511  DTRACE_CABAC_T( "\twidth=" )
1512  DTRACE_CABAC_V( uiWidth )
1513  DTRACE_CABAC_T( "\theight=" )
1514  DTRACE_CABAC_V( uiHeight )
1515  DTRACE_CABAC_T( "\tdepth=" )
1516  DTRACE_CABAC_V( uiDepth )
1517  DTRACE_CABAC_T( "\tabspartidx=" )
1518  DTRACE_CABAC_V( uiAbsPartIdx )
1519  DTRACE_CABAC_T( "\ttoCU-X=" )
1520  DTRACE_CABAC_V( pcCU->getCUPelX() )
1521  DTRACE_CABAC_T( "\ttoCU-Y=" )
1522  DTRACE_CABAC_V( pcCU->getCUPelY() )
1523  DTRACE_CABAC_T( "\tCU-addr=" )
1524  DTRACE_CABAC_V(  pcCU->getAddr() )
1525  DTRACE_CABAC_T( "\tinCU-X=" )
1526  DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1527  DTRACE_CABAC_T( "\tinCU-Y=" )
1528  DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1529  DTRACE_CABAC_T( "\tpredmode=" )
1530  DTRACE_CABAC_V(  pcCU->getPredictionMode( uiAbsPartIdx ) )
1531  DTRACE_CABAC_T( "\n" )
1532#endif
1533 
1534  if( uiWidth > pcCU->getSlice()->getSPS()->getMaxTrSize() )
1535  {
1536    uiWidth  = pcCU->getSlice()->getSPS()->getMaxTrSize();
1537    uiHeight = pcCU->getSlice()->getSPS()->getMaxTrSize();
1538  }
1539  if(pcCU->getSlice()->getPPS()->getUseTransformSkip())
1540  {
1541    parseTransformSkipFlags( pcCU, uiAbsPartIdx, uiWidth, uiHeight, uiDepth, eTType);
1542  }
1543
1544  eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA );
1545 
1546  //----- parse significance map -----
1547  const UInt  uiLog2BlockSize   = g_aucConvertToBit[ uiWidth ] + 2;
1548  const UInt  uiMaxNumCoeff     = uiWidth * uiHeight;
1549  const UInt  uiMaxNumCoeffM1   = uiMaxNumCoeff - 1;
1550  UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx));
1551 
1552  //===== decode last significant =====
1553  UInt uiPosLastX, uiPosLastY;
1554  parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, eTType, uiScanIdx );
1555  UInt uiBlkPosLast      = uiPosLastX + (uiPosLastY<<uiLog2BlockSize);
1556  pcCoef[ uiBlkPosLast ] = 1;
1557
1558  //===== decode significance flags =====
1559  UInt uiScanPosLast;
1560  const UInt *scan   = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize-1 ];
1561  for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ )
1562  {
1563    UInt uiBlkPos = scan[ uiScanPosLast ];
1564    if( uiBlkPosLast == uiBlkPos )
1565    {
1566      break;
1567    }
1568  }
1569
1570  ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType );
1571  ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA;
1572
1573  const Int  iLastScanSet      = uiScanPosLast >> LOG2_SCAN_SET_SIZE;
1574  UInt c1 = 1;
1575  UInt uiGoRiceParam           = 0;
1576
1577  Bool beValid; 
1578  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
1579  {
1580    beValid = false;
1581  }
1582  else 
1583  {
1584    beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0;
1585  }
1586  UInt absSum = 0;
1587
1588  UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ];
1589  ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM );
1590  const UInt uiNumBlkSide = uiWidth >> (MLS_CG_SIZE >> 1);
1591  const UInt * scanCG;
1592  {
1593    scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0  ];   
1594    if( uiLog2BlockSize == 3 )
1595    {
1596      scanCG = g_sigLastScan8x8[ uiScanIdx ];
1597    }
1598    else if( uiLog2BlockSize == 5 )
1599    {
1600      scanCG = g_sigLastScanCG32x32;
1601    }
1602  }
1603  Int  iScanPosSig             = (Int) uiScanPosLast;
1604  for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- )
1605  {
1606    Int  iSubPos     = iSubSet << LOG2_SCAN_SET_SIZE;
1607    uiGoRiceParam    = 0;
1608    Int numNonZero = 0;
1609   
1610    Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE;
1611
1612    Int pos[SCAN_SET_SIZE];
1613    if( iScanPosSig == (Int) uiScanPosLast )
1614    {
1615      lastNZPosInCG  = iScanPosSig;
1616      firstNZPosInCG = iScanPosSig;
1617      iScanPosSig--;
1618      pos[ numNonZero ] = uiBlkPosLast;
1619      numNonZero = 1;
1620    }
1621
1622    // decode significant_coeffgroup_flag
1623    Int iCGBlkPos = scanCG[ iSubSet ];
1624    Int iCGPosY   = iCGBlkPos / uiNumBlkSide;
1625    Int iCGPosX   = iCGBlkPos - (iCGPosY * uiNumBlkSide);
1626    if( iSubSet == iLastScanSet || iSubSet == 0)
1627    {
1628      uiSigCoeffGroupFlag[ iCGBlkPos ] = 1;
1629    }
1630    else
1631    {
1632      UInt uiSigCoeffGroup;
1633      UInt uiCtxSig  = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight );
1634      m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] );
1635      uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup;
1636    }
1637
1638    // decode significant_coeff_flag
1639    Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight );
1640    UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig;
1641    for( ; iScanPosSig >= iSubPos; iScanPosSig-- )
1642    {
1643      uiBlkPos  = scan[ iScanPosSig ];
1644      uiPosY    = uiBlkPos >> uiLog2BlockSize;
1645      uiPosX    = uiBlkPos - ( uiPosY << uiLog2BlockSize );
1646      uiSig     = 0;
1647     
1648      if( uiSigCoeffGroupFlag[ iCGBlkPos ] )
1649      {
1650        if( iScanPosSig > iSubPos || iSubSet == 0  || numNonZero )
1651        {
1652          uiCtxSig  = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType );
1653          m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] );
1654        }
1655        else
1656        {
1657          uiSig = 1;
1658        }
1659      }
1660      pcCoef[ uiBlkPos ] = uiSig;
1661      if( uiSig )
1662      {
1663        pos[ numNonZero ] = uiBlkPos;
1664        numNonZero ++;
1665        if( lastNZPosInCG == -1 )
1666        {
1667          lastNZPosInCG = iScanPosSig;
1668        }
1669        firstNZPosInCG = iScanPosSig;
1670      }
1671    }
1672   
1673    if( numNonZero )
1674    {
1675      Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD );
1676      absSum = 0;
1677      UInt uiCtxSet    = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0;
1678      UInt uiBin;
1679      if( c1 == 0 )
1680      {
1681        uiCtxSet++;
1682      }
1683      c1 = 1;
1684      ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet;
1685      Int absCoeff[SCAN_SET_SIZE];
1686
1687      for ( Int i = 0; i < numNonZero; i++) absCoeff[i] = 1;   
1688      Int numC1Flag = min(numNonZero, C1FLAG_NUMBER);
1689      Int firstC2FlagIdx = -1;
1690
1691      for( Int idx = 0; idx < numC1Flag; idx++ )
1692      {
1693        m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] );
1694        if( uiBin == 1 )
1695        {
1696          c1 = 0;
1697          if (firstC2FlagIdx == -1)
1698          {
1699            firstC2FlagIdx = idx;
1700          }
1701        }
1702        else if( (c1 < 3) && (c1 > 0) )
1703        {
1704          c1++;
1705        }
1706        absCoeff[ idx ] = uiBin + 1;
1707      }
1708     
1709      if (c1 == 0)
1710      {
1711        baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet;
1712        if ( firstC2FlagIdx != -1)
1713        {
1714          m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] ); 
1715          absCoeff[ firstC2FlagIdx ] = uiBin + 2;
1716        }
1717      }
1718
1719      UInt coeffSigns;
1720      if ( signHidden && beValid )
1721      {
1722        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 );
1723        coeffSigns <<= 32 - (numNonZero-1);
1724      }
1725      else
1726      {
1727        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero );
1728        coeffSigns <<= 32 - numNonZero;
1729      }
1730     
1731      Int iFirstCoeff2 = 1;   
1732      if (c1 == 0 || numNonZero > C1FLAG_NUMBER)
1733      {
1734        for( Int idx = 0; idx < numNonZero; idx++ )
1735        {
1736          UInt baseLevel  = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2) : 1;
1737
1738          if( absCoeff[ idx ] == baseLevel)
1739          {
1740            UInt uiLevel;
1741            xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam );
1742            absCoeff[ idx ] = uiLevel + baseLevel;
1743            if(absCoeff[idx]>3*(1<<uiGoRiceParam))
1744            {
1745              uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4);
1746            }
1747          }
1748
1749          if(absCoeff[ idx ] >= 2) 
1750          {
1751            iFirstCoeff2 = 0;
1752          }
1753        }
1754      }
1755
1756      for( Int idx = 0; idx < numNonZero; idx++ )
1757      {
1758        Int blkPos = pos[ idx ];
1759        // Signs applied later.
1760        pcCoef[ blkPos ] = absCoeff[ idx ];
1761        absSum += absCoeff[ idx ];
1762
1763        if ( idx == numNonZero-1 && signHidden && beValid )
1764        {
1765          // Infer sign of 1st element.
1766          if (absSum&0x1)
1767          {
1768            pcCoef[ blkPos ] = -pcCoef[ blkPos ];
1769          }
1770        }
1771        else
1772        {
1773          Int sign = static_cast<Int>( coeffSigns ) >> 31;
1774          pcCoef[ blkPos ] = ( pcCoef[ blkPos ] ^ sign ) - sign;
1775          coeffSigns <<= 1;
1776        }
1777      }
1778    }
1779  }
1780 
1781  return;
1782}
1783
1784
1785Void TDecSbac::parseSaoMaxUvlc ( UInt& val, UInt maxSymbol )
1786{
1787  if (maxSymbol == 0)
1788  {
1789    val = 0;
1790    return;
1791  }
1792
1793  UInt code;
1794  Int  i;
1795  m_pcTDecBinIf->decodeBinEP( code );
1796  if ( code == 0 )
1797  {
1798    val = 0;
1799    return;
1800  }
1801
1802  i=1;
1803  while (1)
1804  {
1805    m_pcTDecBinIf->decodeBinEP( code );
1806    if ( code == 0 )
1807    {
1808      break;
1809    }
1810    i++;
1811    if (i == maxSymbol) 
1812    {
1813      break;
1814    }
1815  }
1816
1817  val = i;
1818}
1819Void TDecSbac::parseSaoUflc (UInt uiLength, UInt&  riVal)
1820{
1821  m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength );
1822}
1823Void TDecSbac::parseSaoMerge (UInt&  ruiVal)
1824{
1825  UInt uiCode;
1826  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) );
1827  ruiVal = (Int)uiCode;
1828}
1829Void TDecSbac::parseSaoTypeIdx (UInt&  ruiVal)
1830{
1831  UInt uiCode;
1832  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
1833  if (uiCode == 0) 
1834  {
1835    ruiVal = 0;
1836  }
1837  else
1838  {
1839    m_pcTDecBinIf->decodeBinEP( uiCode ); 
1840    if (uiCode == 0)
1841    {
1842      ruiVal = 1;
1843    }
1844    else
1845    {
1846      ruiVal = 2;
1847    }
1848  }
1849}
1850
1851Void TDecSbac::parseSaoSign(UInt& val)
1852{
1853  m_pcTDecBinIf->decodeBinEP ( val ); 
1854}
1855
1856Void TDecSbac::parseSAOBlkParam (SAOBlkParam& saoBlkParam
1857                                , Bool* sliceEnabled
1858                                , Bool leftMergeAvail
1859                                , Bool aboveMergeAvail
1860                                )
1861{
1862  UInt uiSymbol;
1863
1864  Bool isLeftMerge = false;
1865  Bool isAboveMerge= false;
1866
1867  if(leftMergeAvail)
1868  {
1869    parseSaoMerge(uiSymbol); //sao_merge_left_flag
1870    isLeftMerge = (uiSymbol?true:false);
1871  }
1872
1873  if( aboveMergeAvail && !isLeftMerge)
1874  {
1875    parseSaoMerge(uiSymbol); //sao_merge_up_flag
1876    isAboveMerge = (uiSymbol?true:false);
1877  }
1878
1879  if(isLeftMerge || isAboveMerge) //merge mode
1880      {
1881    saoBlkParam[SAO_Y].modeIdc = saoBlkParam[SAO_Cb].modeIdc = saoBlkParam[SAO_Cr].modeIdc = SAO_MODE_MERGE;
1882    saoBlkParam[SAO_Y].typeIdc = saoBlkParam[SAO_Cb].typeIdc = saoBlkParam[SAO_Cr].typeIdc = (isLeftMerge)?SAO_MERGE_LEFT:SAO_MERGE_ABOVE;
1883      }   
1884  else //new or off mode
1885      {
1886    for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
1887        {
1888      SAOOffset& ctbParam = saoBlkParam[compIdx];
1889
1890      if(!sliceEnabled[compIdx])
1891          {
1892        //off
1893        ctbParam.modeIdc = SAO_MODE_OFF;
1894        continue;
1895        }
1896
1897      //type
1898      if(compIdx == SAO_Y || compIdx == SAO_Cb)
1899    {
1900        parseSaoTypeIdx(uiSymbol); //sao_type_idx_luma or sao_type_idx_chroma
1901
1902        assert(uiSymbol ==0 || uiSymbol ==1 || uiSymbol ==2);
1903
1904        if(uiSymbol ==0) //OFF
1905     {
1906          ctbParam.modeIdc = SAO_MODE_OFF;
1907   }
1908        else if(uiSymbol == 1) //BO
1909        {
1910          ctbParam.modeIdc = SAO_MODE_NEW;
1911          ctbParam.typeIdc = SAO_TYPE_START_BO;
1912  }
1913        else //2, EO
1914  {
1915          ctbParam.modeIdc = SAO_MODE_NEW;
1916          ctbParam.typeIdc = SAO_TYPE_START_EO;
1917        }
1918
1919  }
1920      else //Cr, follow Cb SAO type
1921      {
1922        ctbParam.modeIdc = saoBlkParam[SAO_Cb].modeIdc;
1923        ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc;
1924}
1925
1926      if(ctbParam.modeIdc == SAO_MODE_NEW)
1927{
1928        Int offset[4];
1929        for(Int i=0; i< 4; i++)
1930  {
1931          parseSaoMaxUvlc(uiSymbol,  g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
1932          offset[i] = (Int)uiSymbol;
1933  }
1934
1935        if(ctbParam.typeIdc == SAO_TYPE_START_BO)
1936  {
1937          for(Int i=0; i< 4; i++)
1938    {
1939            if(offset[i] != 0)
1940    {
1941              parseSaoSign(uiSymbol); //sao_offset_sign
1942              if(uiSymbol)
1943      {
1944                offset[i] = -offset[i];
1945      }
1946    }
1947  }
1948          parseSaoUflc(NUM_SAO_BO_CLASSES_LOG2, uiSymbol ); //sao_band_position
1949          ctbParam.typeAuxInfo = uiSymbol;
1950
1951          for(Int i=0; i<4; i++)
1952      {
1953            ctbParam.offset[(ctbParam.typeAuxInfo+i)%MAX_NUM_SAO_CLASSES] = offset[i];
1954      }
1955
1956        }
1957        else //EO
1958        {
1959          ctbParam.typeAuxInfo = 0;
1960
1961          if(compIdx == SAO_Y || compIdx == SAO_Cb)
1962        {
1963            parseSaoUflc(NUM_SAO_EO_TYPES_LOG2, uiSymbol ); //sao_eo_class_luma or sao_eo_class_chroma
1964            ctbParam.typeIdc += uiSymbol;
1965        }
1966        else
1967        {
1968            ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc;
1969        }
1970          ctbParam.offset[SAO_CLASS_EO_FULL_VALLEY] = offset[0];
1971          ctbParam.offset[SAO_CLASS_EO_HALF_VALLEY] = offset[1];
1972          ctbParam.offset[SAO_CLASS_EO_PLAIN      ] = 0;
1973          ctbParam.offset[SAO_CLASS_EO_HALF_PEAK  ] = -offset[2];
1974          ctbParam.offset[SAO_CLASS_EO_FULL_PEAK  ] = -offset[3];
1975      }
1976      }
1977    }
1978  }
1979}
1980
1981/**
1982 - Initialize our contexts from the nominated source.
1983 .
1984 \param pSrc Contexts to be copied.
1985 */
1986Void TDecSbac::xCopyContextsFrom( TDecSbac* pSrc )
1987{
1988  memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0]));
1989}
1990
1991Void TDecSbac::xCopyFrom( TDecSbac* pSrc )
1992{
1993  m_pcTDecBinIf->copyState( pSrc->m_pcTDecBinIf );
1994
1995  m_uiLastQp           = pSrc->m_uiLastQp;
1996  xCopyContextsFrom( pSrc );
1997
1998}
1999
2000Void TDecSbac::load ( TDecSbac* pScr )
2001{
2002  xCopyFrom(pScr);
2003}
2004
2005Void TDecSbac::loadContexts ( TDecSbac* pScr )
2006{
2007  xCopyContextsFrom(pScr);
2008}
2009
2010#if H_3D_ARP
2011Void TDecSbac::parseARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2012{
2013  UInt uiMaxW = pcCU->getSlice()->getARPStepNum() - 1;
2014  UInt uiW = 0;
2015  UInt uiOffset = pcCU->getCTXARPWFlag(uiAbsPartIdx);
2016  UInt uiCode = 0;
2017
2018  assert ( uiMaxW > 0 );
2019
2020  m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPWSCModel.get( 0, 0, 0 + uiOffset ) );
2021
2022  uiW = uiCode;
2023  if( 1 == uiW )   
2024  {
2025    m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPWSCModel.get( 0, 0, 2 ) );
2026    uiW += ( 1 == uiCode ? 1 : 0 );
2027  }
2028#if H_MV_ENC_DEC_TRAC
2029  DTRACE_CU("iv_res_pred_weight_idx", uiW )
2030#endif
2031  pcCU->setARPWSubParts( ( UChar )( uiW ) , uiAbsPartIdx, uiDepth ); 
2032}
2033#endif
2034
2035#if H_3D_IC
2036/** parse illumination compensation flag
2037 * \param pcCU
2038 * \param uiAbsPartIdx
2039 * \param uiDepth
2040 * \returns Void
2041 */
2042Void TDecSbac::parseICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2043{ 
2044  UInt uiSymbol = 0;
2045  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUICFlagSCModel.get( 0, 0, 0 ) );
2046#if !H_MV_ENC_DEC_TRAC
2047  DTRACE_CABAC_VL( g_nSymbolCounter++ );
2048  DTRACE_CABAC_T( "\tICFlag" );
2049  DTRACE_CABAC_T( "\tuiCtxIC: ");
2050  DTRACE_CABAC_V( uiCtxIC );
2051  DTRACE_CABAC_T( "\tuiSymbol: ");
2052  DTRACE_CABAC_V( uiSymbol );
2053  DTRACE_CABAC_T( "\n");
2054#else
2055  DTRACE_CU("ic_flag", uiSymbol)
2056#endif
2057 
2058  pcCU->setICFlagSubParts( uiSymbol ? true : false , uiAbsPartIdx, 0, uiDepth );
2059}
2060#endif
2061
2062#if H_3D_INTER_SDC
2063Void TDecSbac::parseDeltaDC( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
2064{
2065  if( ! ( pcCU->getSDCFlag( absPartIdx ) || ( pcCU->isIntra( absPartIdx ) && getDimType( pcCU->getLumaIntraDir( absPartIdx ) ) < DIM_NUM_TYPE ) ) )
2066  {
2067    assert( 0 );
2068  }
2069
2070  UInt symbol = 0;
2071  UInt uiNumSegments = 0;
2072
2073  if( pcCU->isIntra( absPartIdx ) )
2074  {
2075    UInt dir     = pcCU->getLumaIntraDir( absPartIdx );
2076    uiNumSegments = isDimMode( dir ) ? 2 : 1;
2077#if MTK_DELTA_DC_FLAG_ONE_CONTEXT_H0084_H0100_H0113
2078    m_pcTDecBinIf->decodeBin( symbol, m_cDdcFlagSCModel.get( 0, 0, 0 ) );
2079#else
2080    m_pcTDecBinIf->decodeBin( symbol, m_cDdcFlagSCModel.get( 0, 0, uiNumSegments-1 ) );
2081#endif
2082    if( pcCU->getSDCFlag( absPartIdx ) )
2083    {
2084      assert( pcCU->getPartitionSize( absPartIdx ) == SIZE_2Nx2N );
2085      pcCU->setTrIdxSubParts( 0, absPartIdx, depth );
2086      pcCU->setCbfSubParts( 1, 1, 1, absPartIdx, depth );
2087    }
2088    else
2089    {
2090      pcCU->setLumaIntraDirSubParts( dir + symbol, absPartIdx, depth );
2091    }
2092  }
2093  else
2094  {
2095    uiNumSegments = 1;
2096    symbol = 1;
2097  }
2098
2099
2100  for( UInt segment = 0; segment < uiNumSegments; segment++ )
2101  {
2102    Pel valDeltaDC = 0;
2103    if( symbol )
2104    {
2105      xParseDimDeltaDC( valDeltaDC, uiNumSegments );
2106    }
2107
2108    if( pcCU->isIntra( absPartIdx ) )
2109    {
2110      UInt dir     = pcCU->getLumaIntraDir( absPartIdx );
2111
2112      if( pcCU->getSDCFlag( absPartIdx ) )
2113      {
2114        pcCU->setSDCSegmentDCOffset( valDeltaDC, segment, absPartIdx );
2115      }
2116      else
2117      {
2118        pcCU->setDimDeltaDC( getDimType( dir ), segment, absPartIdx, valDeltaDC );
2119      }
2120    }
2121    else
2122    {
2123      pcCU->setSDCSegmentDCOffset( valDeltaDC, segment, absPartIdx );
2124    }
2125  }
2126}
2127
2128Void TDecSbac::parseSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2129{
2130  UInt uiSymbol = 0;
2131  UInt uiCtxSDCFlag = pcCU->getCtxSDCFlag( uiAbsPartIdx );
2132
2133  m_pcTDecBinIf->decodeBin( uiSymbol, m_cSDCFlagSCModel.get( 0, 0, uiCtxSDCFlag ) );
2134
2135  if( uiSymbol )
2136  {
2137    pcCU->setSDCFlagSubParts( true, uiAbsPartIdx, uiDepth );
2138    pcCU->setTrIdxSubParts( 0, uiAbsPartIdx, uiDepth );
2139    pcCU->setCbfSubParts( 1, 1, 1, uiAbsPartIdx, uiDepth );
2140  }
2141  else
2142  {
2143    pcCU->setSDCFlagSubParts( false, uiAbsPartIdx, uiDepth );
2144  }
2145}
2146
2147#endif
2148
2149#if H_3D_DBBP
2150Void TDecSbac::parseDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2151{
2152  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
2153  AOF( pcCU->getSlice()->getVPS()->getUseDBBP(pcCU->getSlice()->getLayerIdInVps()) );
2154  AOF( !pcCU->getSlice()->getIsDepth() );
2155  AOF( ePartSize == RWTH_DBBP_PACK_MODE );
2156 
2157  UInt uiSymbol = 0;
2158 
2159  m_pcTDecBinIf->decodeBin( uiSymbol, m_cDBBPFlagSCModel.get( 0, 0, 0 ) );
2160 
2161  if( uiSymbol )
2162  {
2163    pcCU->setDBBPFlagSubParts(true, uiAbsPartIdx, 0, uiDepth);
2164  }
2165}
2166#endif
2167
2168
2169
2170//! \}
Note: See TracBrowser for help on using the repository browser.