source: 3DVCSoftware/branches/HTM-11.1-dev0/source/Lib/TLibDecoder/TDecSbac.cpp @ 967

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

Cleanup part 1.

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