source: 3DVCSoftware/branches/HTM-12.1-dev0/source/Lib/TLibDecoder/TDecSbac.cpp @ 1073

Last change on this file since 1073 was 1066, checked in by tech, 11 years ago

Merged 12.0-dev1@1065.

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