source: 3DVCSoftware/branches/HTM-12.2-dev0/source/Lib/TLibDecoder/TDecSbac.cpp @ 1118

Last change on this file since 1118 was 1118, checked in by tech, 9 years ago

Merged 12.2-dev1-Hisilicon@1116.

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