source: 3DVCSoftware/branches/HTM-11.2-dev3-HiSilicon/source/Lib/TLibDecoder/TDecSbac.cpp @ 994

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

Integration of JCT3V-I0120 Remove "depth_dc_flag" signalling in DMM cases

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