source: 3DVCSoftware/branches/HTM-11.2-dev2-MediaTek/source/Lib/TLibDecoder/TDecSbac.cpp @ 1007

Last change on this file since 1007 was 1007, checked in by mediatek-htm, 10 years ago

JCT3V-I0099. Changes of sub-PU size signaling and lim_qt_pred_flag signaling in VPS extension 2. Remove use_qtl_flag and use_pc_flag.

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