source: 3DVCSoftware/branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecSbac.cpp @ 537

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

Update to HM 11.0.

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