source: 3DVCSoftware/branches/HTM-10.2-dev0/source/Lib/TLibDecoder/TDecSbac.cpp @ 939

Last change on this file since 939 was 939, checked in by tech, 10 years ago

Merged 10.2-dev3-HiSilicon@928.

  • Property svn:eol-style set to native
File size: 66.5 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6* Copyright (c) 2010-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#if LGE_SIMP_DIM_NOT_PRESENT_FLAG_CODING_H0119_H0135
1138    m_pcTDecBinIf->decodeBin( uiSymbol, m_cAngleFlagSCModel.get( 0, 0, 0 ) );
1139#else
1140    m_pcTDecBinIf->decodeBin( uiSymbol, m_cAngleFlagSCModel.get( 0, 0, pcCU->getCtxAngleFlag( absPartIdx ) ) );
1141#endif
1142  }
1143  else
1144  {
1145    uiSymbol = 1;
1146  }
1147  uiIsDimMode = uiSymbol ? 0 : 1;
1148  pcCU->setLumaIntraDirSubParts( 0, absPartIdx, depth );
1149
1150  //decode DMM index
1151  if( uiIsDimMode )
1152  {
1153    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDepthIntraModeSCModel.get( 0, 0, 0 ) );
1154    if( !uiSymbol )
1155    {
1156      pcCU->setLumaIntraDirSubParts( ( 2 * DMM1_IDX + DIM_OFFSET ), absPartIdx, depth );
1157    }
1158    else
1159    {
1160      pcCU->setLumaIntraDirSubParts( ( 2 * DMM4_IDX + DIM_OFFSET ), absPartIdx, depth );
1161    }
1162  }
1163}
1164#endif
1165
1166Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx )
1167{
1168  UInt uiSymbol;
1169  const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx );
1170  ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 );
1171  uiSymbol = 0;
1172  if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 )
1173  {
1174    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) );
1175  }
1176
1177  if( uiSymbol )
1178  {
1179    uiSymbol = 2;
1180  }
1181  else
1182  {
1183    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + 4 ) );
1184    assert(uiSymbol == 0 || uiSymbol == 1);
1185  }
1186
1187  uiSymbol++;
1188  ruiInterDir = uiSymbol;
1189#if H_MV_ENC_DEC_TRAC
1190    DTRACE_PU("inter_pred_idc", ruiInterDir - 1 )   
1191#endif
1192
1193  return;
1194}
1195
1196Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList )
1197{
1198  UInt uiSymbol;
1199  {
1200    ContextModel *pCtx = m_cCURefPicSCModel.get( 0 );
1201    m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1202
1203    if( uiSymbol )
1204    {
1205      UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2;
1206      pCtx++;
1207      UInt ui;
1208      for( ui = 0; ui < uiRefNum; ++ui )
1209      {
1210        if( ui == 0 )
1211        {
1212          m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1213        }
1214        else
1215        {
1216          m_pcTDecBinIf->decodeBinEP( uiSymbol );
1217        }
1218        if( uiSymbol == 0 )
1219        {
1220          break;
1221        }
1222      }
1223      uiSymbol = ui + 1;
1224    }
1225    riRefFrmIdx = uiSymbol;
1226  }
1227
1228#if H_MV_ENC_DEC_TRAC
1229#if ENC_DEC_TRACE
1230  if ( eRefList == REF_PIC_LIST_0 )
1231  {
1232    DTRACE_PU("ref_idx_l0", uiSymbol)
1233  }
1234  else
1235  {
1236    DTRACE_PU("ref_idx_l1", uiSymbol)
1237  }
1238#endif
1239#endif
1240  return;
1241}
1242
1243Void TDecSbac::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList )
1244{
1245  UInt uiSymbol;
1246  UInt uiHorAbs;
1247  UInt uiVerAbs;
1248  UInt uiHorSign = 0;
1249  UInt uiVerSign = 0;
1250  ContextModel *pCtx = m_cCUMvdSCModel.get( 0 );
1251
1252  if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3)
1253  {
1254    uiHorAbs=0;
1255    uiVerAbs=0;
1256  }
1257  else
1258  {
1259    m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx );
1260    m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx );
1261
1262    const Bool bHorAbsGr0 = uiHorAbs != 0;
1263    const Bool bVerAbsGr0 = uiVerAbs != 0;
1264    pCtx++;
1265
1266    if( bHorAbsGr0 )
1267    {
1268      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1269      uiHorAbs += uiSymbol;
1270    }
1271
1272    if( bVerAbsGr0 )
1273    {
1274      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1275      uiVerAbs += uiSymbol;
1276    }
1277
1278    if( bHorAbsGr0 )
1279    {
1280      if( 2 == uiHorAbs )
1281      {
1282        xReadEpExGolomb( uiSymbol, 1 );
1283        uiHorAbs += uiSymbol;
1284      }
1285
1286      m_pcTDecBinIf->decodeBinEP( uiHorSign );
1287    }
1288
1289    if( bVerAbsGr0 )
1290    {
1291      if( 2 == uiVerAbs )
1292      {
1293        xReadEpExGolomb( uiSymbol, 1 );
1294        uiVerAbs += uiSymbol;
1295      }
1296
1297      m_pcTDecBinIf->decodeBinEP( uiVerSign );
1298    }
1299
1300  }
1301
1302  const TComMv cMv( uiHorSign ? -Int( uiHorAbs ): uiHorAbs, uiVerSign ? -Int( uiVerAbs ) : uiVerAbs );
1303  pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiDepth, uiPartIdx );
1304  return;
1305}
1306
1307
1308Void TDecSbac::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize )
1309{
1310  m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize ) );
1311#if !H_MV_ENC_DEC_TRAC
1312  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1313  DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" )
1314  DTRACE_CABAC_T( "\tsymbol=" )
1315  DTRACE_CABAC_V( ruiSubdivFlag )
1316  DTRACE_CABAC_T( "\tctx=" )
1317  DTRACE_CABAC_V( uiLog2TransformBlockSize )
1318  DTRACE_CABAC_T( "\n" )
1319#endif
1320}
1321
1322Void TDecSbac::parseQtRootCbf( UInt uiAbsPartIdx, UInt& uiQtRootCbf )
1323{
1324  UInt uiSymbol;
1325  const UInt uiCtx = 0;
1326  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) );
1327#if !H_MV_ENC_DEC_TRAC
1328  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1329  DTRACE_CABAC_T( "\tparseQtRootCbf()" )
1330  DTRACE_CABAC_T( "\tsymbol=" )
1331  DTRACE_CABAC_V( uiSymbol )
1332  DTRACE_CABAC_T( "\tctx=" )
1333  DTRACE_CABAC_V( uiCtx )
1334  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1335  DTRACE_CABAC_V( uiAbsPartIdx )
1336  DTRACE_CABAC_T( "\n" )
1337#else
1338  DTRACE_CU( "rqt_root_cbf", uiSymbol )
1339#endif
1340 
1341  uiQtRootCbf = uiSymbol;
1342}
1343
1344Void TDecSbac::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1345{
1346  Int qp;
1347  UInt uiDQp;
1348  Int  iDQp;
1349 
1350  UInt uiSymbol;
1351
1352  xReadUnaryMaxSymbol (uiDQp,  &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX);
1353
1354  if( uiDQp >= CU_DQP_TU_CMAX)
1355  {
1356    xReadEpExGolomb( uiSymbol, CU_DQP_EG_k );
1357    uiDQp+=uiSymbol;
1358  }
1359
1360  if ( uiDQp > 0 )
1361  {
1362    UInt uiSign;
1363    Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
1364    m_pcTDecBinIf->decodeBinEP(uiSign);
1365    iDQp = uiDQp;
1366    if(uiSign)
1367    {
1368      iDQp = -iDQp;
1369    }
1370    qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY;
1371  }
1372  else 
1373  {
1374    qp = pcCU->getRefQP(uiAbsPartIdx);
1375  }
1376  pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth); 
1377  pcCU->setCodedQP(qp);
1378}
1379
1380Void TDecSbac::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth )
1381{
1382  UInt uiSymbol;
1383  const UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth );
1384  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA: eType, uiCtx ) );
1385#if !H_MV_ENC_DEC_TRAC 
1386  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1387  DTRACE_CABAC_T( "\tparseQtCbf()" )
1388  DTRACE_CABAC_T( "\tsymbol=" )
1389  DTRACE_CABAC_V( uiSymbol )
1390  DTRACE_CABAC_T( "\tctx=" )
1391  DTRACE_CABAC_V( uiCtx )
1392  DTRACE_CABAC_T( "\tetype=" )
1393  DTRACE_CABAC_V( eType )
1394  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1395  DTRACE_CABAC_V( uiAbsPartIdx )
1396  DTRACE_CABAC_T( "\n" )
1397#endif
1398 
1399  pcCU->setCbfSubParts( uiSymbol << uiTrDepth, eType, uiAbsPartIdx, uiDepth );
1400}
1401
1402void TDecSbac::parseTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType)
1403{
1404  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
1405  {
1406    return;
1407  }
1408  if(width != 4 || height != 4)
1409  {
1410    return;
1411  }
1412 
1413  UInt useTransformSkip;
1414  m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) );
1415  if(eTType!= TEXT_LUMA)
1416  {
1417    const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiDepth;
1418    if(uiLog2TrafoSize == 2) 
1419    { 
1420      uiDepth --;
1421    }
1422  }
1423#if !H_MV_ENC_DEC_TRAC
1424  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1425  DTRACE_CABAC_T("\tparseTransformSkip()");
1426  DTRACE_CABAC_T( "\tsymbol=" )
1427  DTRACE_CABAC_V( useTransformSkip )
1428  DTRACE_CABAC_T( "\tAddr=" )
1429  DTRACE_CABAC_V( pcCU->getAddr() )
1430  DTRACE_CABAC_T( "\tetype=" )
1431  DTRACE_CABAC_V( eTType )
1432  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1433  DTRACE_CABAC_V( uiAbsPartIdx )
1434  DTRACE_CABAC_T( "\n" )
1435#endif
1436
1437  pcCU->setTransformSkipSubParts( useTransformSkip, eTType, uiAbsPartIdx, uiDepth);
1438}
1439
1440/** Parse (X,Y) position of the last significant coefficient
1441 * \param uiPosLastX reference to X component of last coefficient
1442 * \param uiPosLastY reference to Y component of last coefficient
1443 * \param width  Block width
1444 * \param height Block height
1445 * \param eTType plane type / luminance or chrominance
1446 * \param uiScanIdx scan type (zig-zag, hor, ver)
1447 *
1448 * This method decodes the X and Y component within a block of the last significant coefficient.
1449 */
1450Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, TextType eTType, UInt uiScanIdx )
1451{
1452  UInt uiLast;
1453  ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType );
1454  ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType );
1455
1456  Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY;
1457  blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2));
1458  blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2));
1459  shiftX= eTType ? g_aucConvertToBit[ width  ] :((g_aucConvertToBit[ width  ]+3)>>2);
1460  shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2);
1461  // posX
1462  for( uiPosLastX = 0; uiPosLastX < g_uiGroupIdx[ width - 1 ]; uiPosLastX++ )
1463  {
1464    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + blkSizeOffsetX + (uiPosLastX >>shiftX) ) );
1465    if( !uiLast )
1466    {
1467      break;
1468    }
1469  }
1470
1471  // posY
1472  for( uiPosLastY = 0; uiPosLastY < g_uiGroupIdx[ height - 1 ]; uiPosLastY++ )
1473  {
1474    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + blkSizeOffsetY + (uiPosLastY >>shiftY)) );
1475    if( !uiLast )
1476    {
1477      break;
1478    }
1479  }
1480  if ( uiPosLastX > 3 )
1481  {
1482    UInt uiTemp  = 0;
1483    UInt uiCount = ( uiPosLastX - 2 ) >> 1;
1484    for ( Int i = uiCount - 1; i >= 0; i-- )
1485    {
1486      m_pcTDecBinIf->decodeBinEP( uiLast );
1487      uiTemp += uiLast << i;
1488    }
1489    uiPosLastX = g_uiMinInGroup[ uiPosLastX ] + uiTemp;
1490  }
1491  if ( uiPosLastY > 3 )
1492  {
1493    UInt uiTemp  = 0;
1494    UInt uiCount = ( uiPosLastY - 2 ) >> 1;
1495    for ( Int i = uiCount - 1; i >= 0; i-- )
1496    {
1497      m_pcTDecBinIf->decodeBinEP( uiLast );
1498      uiTemp += uiLast << i;
1499    }
1500    uiPosLastY = g_uiMinInGroup[ uiPosLastY ] + uiTemp;
1501  }
1502 
1503  if( uiScanIdx == SCAN_VER )
1504  {
1505    swap( uiPosLastX, uiPosLastY );
1506  }
1507}
1508
1509Void TDecSbac::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType )
1510{
1511#if !H_MV_ENC_DEC_TRAC
1512  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1513  DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" )
1514  DTRACE_CABAC_V( eTType )
1515  DTRACE_CABAC_T( "\twidth=" )
1516  DTRACE_CABAC_V( uiWidth )
1517  DTRACE_CABAC_T( "\theight=" )
1518  DTRACE_CABAC_V( uiHeight )
1519  DTRACE_CABAC_T( "\tdepth=" )
1520  DTRACE_CABAC_V( uiDepth )
1521  DTRACE_CABAC_T( "\tabspartidx=" )
1522  DTRACE_CABAC_V( uiAbsPartIdx )
1523  DTRACE_CABAC_T( "\ttoCU-X=" )
1524  DTRACE_CABAC_V( pcCU->getCUPelX() )
1525  DTRACE_CABAC_T( "\ttoCU-Y=" )
1526  DTRACE_CABAC_V( pcCU->getCUPelY() )
1527  DTRACE_CABAC_T( "\tCU-addr=" )
1528  DTRACE_CABAC_V(  pcCU->getAddr() )
1529  DTRACE_CABAC_T( "\tinCU-X=" )
1530  DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1531  DTRACE_CABAC_T( "\tinCU-Y=" )
1532  DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1533  DTRACE_CABAC_T( "\tpredmode=" )
1534  DTRACE_CABAC_V(  pcCU->getPredictionMode( uiAbsPartIdx ) )
1535  DTRACE_CABAC_T( "\n" )
1536#endif
1537 
1538  if( uiWidth > pcCU->getSlice()->getSPS()->getMaxTrSize() )
1539  {
1540    uiWidth  = pcCU->getSlice()->getSPS()->getMaxTrSize();
1541    uiHeight = pcCU->getSlice()->getSPS()->getMaxTrSize();
1542  }
1543  if(pcCU->getSlice()->getPPS()->getUseTransformSkip())
1544  {
1545    parseTransformSkipFlags( pcCU, uiAbsPartIdx, uiWidth, uiHeight, uiDepth, eTType);
1546  }
1547
1548  eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA );
1549 
1550  //----- parse significance map -----
1551  const UInt  uiLog2BlockSize   = g_aucConvertToBit[ uiWidth ] + 2;
1552  const UInt  uiMaxNumCoeff     = uiWidth * uiHeight;
1553  const UInt  uiMaxNumCoeffM1   = uiMaxNumCoeff - 1;
1554  UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx));
1555 
1556  //===== decode last significant =====
1557  UInt uiPosLastX, uiPosLastY;
1558  parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, eTType, uiScanIdx );
1559  UInt uiBlkPosLast      = uiPosLastX + (uiPosLastY<<uiLog2BlockSize);
1560  pcCoef[ uiBlkPosLast ] = 1;
1561
1562  //===== decode significance flags =====
1563  UInt uiScanPosLast;
1564  const UInt *scan   = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize-1 ];
1565  for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ )
1566  {
1567    UInt uiBlkPos = scan[ uiScanPosLast ];
1568    if( uiBlkPosLast == uiBlkPos )
1569    {
1570      break;
1571    }
1572  }
1573
1574  ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType );
1575  ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA;
1576
1577  const Int  iLastScanSet      = uiScanPosLast >> LOG2_SCAN_SET_SIZE;
1578  UInt c1 = 1;
1579  UInt uiGoRiceParam           = 0;
1580
1581  Bool beValid; 
1582  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
1583  {
1584    beValid = false;
1585  }
1586  else 
1587  {
1588    beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0;
1589  }
1590  UInt absSum = 0;
1591
1592  UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ];
1593  ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM );
1594  const UInt uiNumBlkSide = uiWidth >> (MLS_CG_SIZE >> 1);
1595  const UInt * scanCG;
1596  {
1597    scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0  ];   
1598    if( uiLog2BlockSize == 3 )
1599    {
1600      scanCG = g_sigLastScan8x8[ uiScanIdx ];
1601    }
1602    else if( uiLog2BlockSize == 5 )
1603    {
1604      scanCG = g_sigLastScanCG32x32;
1605    }
1606  }
1607  Int  iScanPosSig             = (Int) uiScanPosLast;
1608  for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- )
1609  {
1610    Int  iSubPos     = iSubSet << LOG2_SCAN_SET_SIZE;
1611    uiGoRiceParam    = 0;
1612    Int numNonZero = 0;
1613   
1614    Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE;
1615
1616    Int pos[SCAN_SET_SIZE];
1617    if( iScanPosSig == (Int) uiScanPosLast )
1618    {
1619      lastNZPosInCG  = iScanPosSig;
1620      firstNZPosInCG = iScanPosSig;
1621      iScanPosSig--;
1622      pos[ numNonZero ] = uiBlkPosLast;
1623      numNonZero = 1;
1624    }
1625
1626    // decode significant_coeffgroup_flag
1627    Int iCGBlkPos = scanCG[ iSubSet ];
1628    Int iCGPosY   = iCGBlkPos / uiNumBlkSide;
1629    Int iCGPosX   = iCGBlkPos - (iCGPosY * uiNumBlkSide);
1630    if( iSubSet == iLastScanSet || iSubSet == 0)
1631    {
1632      uiSigCoeffGroupFlag[ iCGBlkPos ] = 1;
1633    }
1634    else
1635    {
1636      UInt uiSigCoeffGroup;
1637      UInt uiCtxSig  = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight );
1638      m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] );
1639      uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup;
1640    }
1641
1642    // decode significant_coeff_flag
1643    Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight );
1644    UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig;
1645    for( ; iScanPosSig >= iSubPos; iScanPosSig-- )
1646    {
1647      uiBlkPos  = scan[ iScanPosSig ];
1648      uiPosY    = uiBlkPos >> uiLog2BlockSize;
1649      uiPosX    = uiBlkPos - ( uiPosY << uiLog2BlockSize );
1650      uiSig     = 0;
1651     
1652      if( uiSigCoeffGroupFlag[ iCGBlkPos ] )
1653      {
1654        if( iScanPosSig > iSubPos || iSubSet == 0  || numNonZero )
1655        {
1656          uiCtxSig  = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType );
1657          m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] );
1658        }
1659        else
1660        {
1661          uiSig = 1;
1662        }
1663      }
1664      pcCoef[ uiBlkPos ] = uiSig;
1665      if( uiSig )
1666      {
1667        pos[ numNonZero ] = uiBlkPos;
1668        numNonZero ++;
1669        if( lastNZPosInCG == -1 )
1670        {
1671          lastNZPosInCG = iScanPosSig;
1672        }
1673        firstNZPosInCG = iScanPosSig;
1674      }
1675    }
1676   
1677    if( numNonZero )
1678    {
1679      Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD );
1680      absSum = 0;
1681      UInt uiCtxSet    = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0;
1682      UInt uiBin;
1683      if( c1 == 0 )
1684      {
1685        uiCtxSet++;
1686      }
1687      c1 = 1;
1688      ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet;
1689      Int absCoeff[SCAN_SET_SIZE];
1690
1691      for ( Int i = 0; i < numNonZero; i++) absCoeff[i] = 1;   
1692      Int numC1Flag = min(numNonZero, C1FLAG_NUMBER);
1693      Int firstC2FlagIdx = -1;
1694
1695      for( Int idx = 0; idx < numC1Flag; idx++ )
1696      {
1697        m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] );
1698        if( uiBin == 1 )
1699        {
1700          c1 = 0;
1701          if (firstC2FlagIdx == -1)
1702          {
1703            firstC2FlagIdx = idx;
1704          }
1705        }
1706        else if( (c1 < 3) && (c1 > 0) )
1707        {
1708          c1++;
1709        }
1710        absCoeff[ idx ] = uiBin + 1;
1711      }
1712     
1713      if (c1 == 0)
1714      {
1715        baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet;
1716        if ( firstC2FlagIdx != -1)
1717        {
1718          m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] ); 
1719          absCoeff[ firstC2FlagIdx ] = uiBin + 2;
1720        }
1721      }
1722
1723      UInt coeffSigns;
1724      if ( signHidden && beValid )
1725      {
1726        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 );
1727        coeffSigns <<= 32 - (numNonZero-1);
1728      }
1729      else
1730      {
1731        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero );
1732        coeffSigns <<= 32 - numNonZero;
1733      }
1734     
1735      Int iFirstCoeff2 = 1;   
1736      if (c1 == 0 || numNonZero > C1FLAG_NUMBER)
1737      {
1738        for( Int idx = 0; idx < numNonZero; idx++ )
1739        {
1740          UInt baseLevel  = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2) : 1;
1741
1742          if( absCoeff[ idx ] == baseLevel)
1743          {
1744            UInt uiLevel;
1745            xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam );
1746            absCoeff[ idx ] = uiLevel + baseLevel;
1747            if(absCoeff[idx]>3*(1<<uiGoRiceParam))
1748            {
1749              uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4);
1750            }
1751          }
1752
1753          if(absCoeff[ idx ] >= 2) 
1754          {
1755            iFirstCoeff2 = 0;
1756          }
1757        }
1758      }
1759
1760      for( Int idx = 0; idx < numNonZero; idx++ )
1761      {
1762        Int blkPos = pos[ idx ];
1763        // Signs applied later.
1764        pcCoef[ blkPos ] = absCoeff[ idx ];
1765        absSum += absCoeff[ idx ];
1766
1767        if ( idx == numNonZero-1 && signHidden && beValid )
1768        {
1769          // Infer sign of 1st element.
1770          if (absSum&0x1)
1771          {
1772            pcCoef[ blkPos ] = -pcCoef[ blkPos ];
1773          }
1774        }
1775        else
1776        {
1777          Int sign = static_cast<Int>( coeffSigns ) >> 31;
1778          pcCoef[ blkPos ] = ( pcCoef[ blkPos ] ^ sign ) - sign;
1779          coeffSigns <<= 1;
1780        }
1781      }
1782    }
1783  }
1784 
1785  return;
1786}
1787
1788
1789Void TDecSbac::parseSaoMaxUvlc ( UInt& val, UInt maxSymbol )
1790{
1791  if (maxSymbol == 0)
1792  {
1793    val = 0;
1794    return;
1795  }
1796
1797  UInt code;
1798  Int  i;
1799  m_pcTDecBinIf->decodeBinEP( code );
1800  if ( code == 0 )
1801  {
1802    val = 0;
1803    return;
1804  }
1805
1806  i=1;
1807  while (1)
1808  {
1809    m_pcTDecBinIf->decodeBinEP( code );
1810    if ( code == 0 )
1811    {
1812      break;
1813    }
1814    i++;
1815    if (i == maxSymbol) 
1816    {
1817      break;
1818    }
1819  }
1820
1821  val = i;
1822}
1823Void TDecSbac::parseSaoUflc (UInt uiLength, UInt&  riVal)
1824{
1825  m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength );
1826}
1827Void TDecSbac::parseSaoMerge (UInt&  ruiVal)
1828{
1829  UInt uiCode;
1830  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) );
1831  ruiVal = (Int)uiCode;
1832}
1833Void TDecSbac::parseSaoTypeIdx (UInt&  ruiVal)
1834{
1835  UInt uiCode;
1836  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
1837  if (uiCode == 0) 
1838  {
1839    ruiVal = 0;
1840  }
1841  else
1842  {
1843    m_pcTDecBinIf->decodeBinEP( uiCode ); 
1844    if (uiCode == 0)
1845    {
1846      ruiVal = 1;
1847    }
1848    else
1849    {
1850      ruiVal = 2;
1851    }
1852  }
1853}
1854
1855Void TDecSbac::parseSaoSign(UInt& val)
1856{
1857  m_pcTDecBinIf->decodeBinEP ( val ); 
1858}
1859
1860Void TDecSbac::parseSAOBlkParam (SAOBlkParam& saoBlkParam
1861                                , Bool* sliceEnabled
1862                                , Bool leftMergeAvail
1863                                , Bool aboveMergeAvail
1864                                )
1865{
1866  UInt uiSymbol;
1867
1868  Bool isLeftMerge = false;
1869  Bool isAboveMerge= false;
1870
1871  if(leftMergeAvail)
1872  {
1873    parseSaoMerge(uiSymbol); //sao_merge_left_flag
1874    isLeftMerge = (uiSymbol?true:false);
1875  }
1876
1877  if( aboveMergeAvail && !isLeftMerge)
1878  {
1879    parseSaoMerge(uiSymbol); //sao_merge_up_flag
1880    isAboveMerge = (uiSymbol?true:false);
1881  }
1882
1883  if(isLeftMerge || isAboveMerge) //merge mode
1884      {
1885    saoBlkParam[SAO_Y].modeIdc = saoBlkParam[SAO_Cb].modeIdc = saoBlkParam[SAO_Cr].modeIdc = SAO_MODE_MERGE;
1886    saoBlkParam[SAO_Y].typeIdc = saoBlkParam[SAO_Cb].typeIdc = saoBlkParam[SAO_Cr].typeIdc = (isLeftMerge)?SAO_MERGE_LEFT:SAO_MERGE_ABOVE;
1887      }   
1888  else //new or off mode
1889      {
1890    for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
1891        {
1892      SAOOffset& ctbParam = saoBlkParam[compIdx];
1893
1894      if(!sliceEnabled[compIdx])
1895          {
1896        //off
1897        ctbParam.modeIdc = SAO_MODE_OFF;
1898        continue;
1899        }
1900
1901      //type
1902      if(compIdx == SAO_Y || compIdx == SAO_Cb)
1903    {
1904        parseSaoTypeIdx(uiSymbol); //sao_type_idx_luma or sao_type_idx_chroma
1905
1906        assert(uiSymbol ==0 || uiSymbol ==1 || uiSymbol ==2);
1907
1908        if(uiSymbol ==0) //OFF
1909     {
1910          ctbParam.modeIdc = SAO_MODE_OFF;
1911   }
1912        else if(uiSymbol == 1) //BO
1913        {
1914          ctbParam.modeIdc = SAO_MODE_NEW;
1915          ctbParam.typeIdc = SAO_TYPE_START_BO;
1916  }
1917        else //2, EO
1918  {
1919          ctbParam.modeIdc = SAO_MODE_NEW;
1920          ctbParam.typeIdc = SAO_TYPE_START_EO;
1921        }
1922
1923  }
1924      else //Cr, follow Cb SAO type
1925      {
1926        ctbParam.modeIdc = saoBlkParam[SAO_Cb].modeIdc;
1927        ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc;
1928}
1929
1930      if(ctbParam.modeIdc == SAO_MODE_NEW)
1931{
1932        Int offset[4];
1933        for(Int i=0; i< 4; i++)
1934  {
1935          parseSaoMaxUvlc(uiSymbol,  g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
1936          offset[i] = (Int)uiSymbol;
1937  }
1938
1939        if(ctbParam.typeIdc == SAO_TYPE_START_BO)
1940  {
1941          for(Int i=0; i< 4; i++)
1942    {
1943            if(offset[i] != 0)
1944    {
1945              parseSaoSign(uiSymbol); //sao_offset_sign
1946              if(uiSymbol)
1947      {
1948                offset[i] = -offset[i];
1949      }
1950    }
1951  }
1952          parseSaoUflc(NUM_SAO_BO_CLASSES_LOG2, uiSymbol ); //sao_band_position
1953          ctbParam.typeAuxInfo = uiSymbol;
1954
1955          for(Int i=0; i<4; i++)
1956      {
1957            ctbParam.offset[(ctbParam.typeAuxInfo+i)%MAX_NUM_SAO_CLASSES] = offset[i];
1958      }
1959
1960        }
1961        else //EO
1962        {
1963          ctbParam.typeAuxInfo = 0;
1964
1965          if(compIdx == SAO_Y || compIdx == SAO_Cb)
1966        {
1967            parseSaoUflc(NUM_SAO_EO_TYPES_LOG2, uiSymbol ); //sao_eo_class_luma or sao_eo_class_chroma
1968            ctbParam.typeIdc += uiSymbol;
1969        }
1970        else
1971        {
1972            ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc;
1973        }
1974          ctbParam.offset[SAO_CLASS_EO_FULL_VALLEY] = offset[0];
1975          ctbParam.offset[SAO_CLASS_EO_HALF_VALLEY] = offset[1];
1976          ctbParam.offset[SAO_CLASS_EO_PLAIN      ] = 0;
1977          ctbParam.offset[SAO_CLASS_EO_HALF_PEAK  ] = -offset[2];
1978          ctbParam.offset[SAO_CLASS_EO_FULL_PEAK  ] = -offset[3];
1979      }
1980      }
1981    }
1982  }
1983}
1984
1985/**
1986 - Initialize our contexts from the nominated source.
1987 .
1988 \param pSrc Contexts to be copied.
1989 */
1990Void TDecSbac::xCopyContextsFrom( TDecSbac* pSrc )
1991{
1992  memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0]));
1993}
1994
1995Void TDecSbac::xCopyFrom( TDecSbac* pSrc )
1996{
1997  m_pcTDecBinIf->copyState( pSrc->m_pcTDecBinIf );
1998
1999  m_uiLastQp           = pSrc->m_uiLastQp;
2000  xCopyContextsFrom( pSrc );
2001
2002}
2003
2004Void TDecSbac::load ( TDecSbac* pScr )
2005{
2006  xCopyFrom(pScr);
2007}
2008
2009Void TDecSbac::loadContexts ( TDecSbac* pScr )
2010{
2011  xCopyContextsFrom(pScr);
2012}
2013
2014#if H_3D_ARP
2015Void TDecSbac::parseARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2016{
2017  UInt uiMaxW = pcCU->getSlice()->getARPStepNum() - 1;
2018  UInt uiW = 0;
2019  UInt uiOffset = pcCU->getCTXARPWFlag(uiAbsPartIdx);
2020  UInt uiCode = 0;
2021
2022  assert ( uiMaxW > 0 );
2023
2024  m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPWSCModel.get( 0, 0, 0 + uiOffset ) );
2025
2026  uiW = uiCode;
2027  if( 1 == uiW )   
2028  {
2029    m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPWSCModel.get( 0, 0, 2 ) );
2030    uiW += ( 1 == uiCode ? 1 : 0 );
2031  }
2032#if H_MV_ENC_DEC_TRAC
2033  DTRACE_CU("iv_res_pred_weight_idx", uiW )
2034#endif
2035  pcCU->setARPWSubParts( ( UChar )( uiW ) , uiAbsPartIdx, uiDepth ); 
2036}
2037#endif
2038
2039#if H_3D_IC
2040/** parse illumination compensation flag
2041 * \param pcCU
2042 * \param uiAbsPartIdx
2043 * \param uiDepth
2044 * \returns Void
2045 */
2046Void TDecSbac::parseICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2047{ 
2048  UInt uiSymbol = 0;
2049  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUICFlagSCModel.get( 0, 0, 0 ) );
2050#if !H_MV_ENC_DEC_TRAC
2051  DTRACE_CABAC_VL( g_nSymbolCounter++ );
2052  DTRACE_CABAC_T( "\tICFlag" );
2053  DTRACE_CABAC_T( "\tuiCtxIC: ");
2054  DTRACE_CABAC_V( uiCtxIC );
2055  DTRACE_CABAC_T( "\tuiSymbol: ");
2056  DTRACE_CABAC_V( uiSymbol );
2057  DTRACE_CABAC_T( "\n");
2058#else
2059  DTRACE_CU("ic_flag", uiSymbol)
2060#endif
2061 
2062  pcCU->setICFlagSubParts( uiSymbol ? true : false , uiAbsPartIdx, 0, uiDepth );
2063}
2064#endif
2065
2066#if H_3D_INTER_SDC
2067Void TDecSbac::parseDeltaDC( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
2068{
2069  if( ! ( pcCU->getSDCFlag( absPartIdx ) || ( pcCU->isIntra( absPartIdx ) && getDimType( pcCU->getLumaIntraDir( absPartIdx ) ) < DIM_NUM_TYPE ) ) )
2070  {
2071    assert( 0 );
2072  }
2073
2074  UInt symbol = 0;
2075  UInt uiNumSegments = 0;
2076
2077  if( pcCU->isIntra( absPartIdx ) )
2078  {
2079    UInt dir     = pcCU->getLumaIntraDir( absPartIdx );
2080    uiNumSegments = isDimMode( dir ) ? 2 : 1;
2081#if MTK_DELTA_DC_FLAG_ONE_CONTEXT_H0084_H0100_H0113
2082    m_pcTDecBinIf->decodeBin( symbol, m_cDdcFlagSCModel.get( 0, 0, 0 ) );
2083#else
2084    m_pcTDecBinIf->decodeBin( symbol, m_cDdcFlagSCModel.get( 0, 0, uiNumSegments-1 ) );
2085#endif
2086    if( pcCU->getSDCFlag( absPartIdx ) )
2087    {
2088      assert( pcCU->getPartitionSize( absPartIdx ) == SIZE_2Nx2N );
2089      pcCU->setTrIdxSubParts( 0, absPartIdx, depth );
2090      pcCU->setCbfSubParts( 1, 1, 1, absPartIdx, depth );
2091    }
2092    else
2093    {
2094      pcCU->setLumaIntraDirSubParts( dir + symbol, absPartIdx, depth );
2095    }
2096  }
2097  else
2098  {
2099    uiNumSegments = 1;
2100    symbol = 1;
2101  }
2102
2103
2104  for( UInt segment = 0; segment < uiNumSegments; segment++ )
2105  {
2106    Pel valDeltaDC = 0;
2107    if( symbol )
2108    {
2109      xParseDimDeltaDC( valDeltaDC, uiNumSegments );
2110    }
2111
2112    if( pcCU->isIntra( absPartIdx ) )
2113    {
2114      UInt dir     = pcCU->getLumaIntraDir( absPartIdx );
2115
2116      if( pcCU->getSDCFlag( absPartIdx ) )
2117      {
2118        pcCU->setSDCSegmentDCOffset( valDeltaDC, segment, absPartIdx );
2119      }
2120      else
2121      {
2122        pcCU->setDimDeltaDC( getDimType( dir ), segment, absPartIdx, valDeltaDC );
2123      }
2124    }
2125    else
2126    {
2127      pcCU->setSDCSegmentDCOffset( valDeltaDC, segment, absPartIdx );
2128    }
2129  }
2130}
2131
2132Void TDecSbac::parseSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2133{
2134  UInt uiSymbol = 0;
2135  UInt uiCtxSDCFlag = pcCU->getCtxSDCFlag( uiAbsPartIdx );
2136
2137  m_pcTDecBinIf->decodeBin( uiSymbol, m_cSDCFlagSCModel.get( 0, 0, uiCtxSDCFlag ) );
2138
2139  if( uiSymbol )
2140  {
2141    pcCU->setSDCFlagSubParts( true, uiAbsPartIdx, uiDepth );
2142    pcCU->setTrIdxSubParts( 0, uiAbsPartIdx, uiDepth );
2143    pcCU->setCbfSubParts( 1, 1, 1, uiAbsPartIdx, uiDepth );
2144  }
2145  else
2146  {
2147    pcCU->setSDCFlagSubParts( false, uiAbsPartIdx, uiDepth );
2148  }
2149}
2150
2151#endif
2152
2153#if H_3D_DBBP
2154Void TDecSbac::parseDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2155{
2156#if !MTK_DBBP_SIGNALING_H0094
2157  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
2158#endif
2159  AOF( pcCU->getSlice()->getVPS()->getUseDBBP(pcCU->getSlice()->getLayerIdInVps()) );
2160  AOF( !pcCU->getSlice()->getIsDepth() );
2161#if !MTK_DBBP_SIGNALING_H0094
2162  AOF( ePartSize == RWTH_DBBP_PACK_MODE );
2163#endif
2164 
2165  UInt uiSymbol = 0;
2166 
2167  m_pcTDecBinIf->decodeBin( uiSymbol, m_cDBBPFlagSCModel.get( 0, 0, 0 ) );
2168 
2169  if( uiSymbol )
2170  {
2171    pcCU->setDBBPFlagSubParts(true, uiAbsPartIdx, 0, uiDepth);
2172#if MTK_DIS_SPBIP8X4_H0205
2173    UInt uiCurrPartNumQ = (pcCU->getPic()->getNumPartInCU() >> (2 * uiDepth)) >> 2;
2174    pcCU->setDBBPFlagSubParts(true, uiAbsPartIdx + 2*uiCurrPartNumQ, 1, uiDepth);
2175#endif
2176  }
2177}
2178#endif
2179
2180
2181
2182//! \}
Note: See TracBrowser for help on using the repository browser.