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

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

Removed 3D-HEVC related macros.

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