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

Last change on this file since 531 was 531, checked in by tech, 12 years ago

Merged HTM-DEV-0.3-dev1 Rev. 520.

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