source: 3DVCSoftware/trunk/source/Lib/TLibDecoder/TDecSbac.cpp @ 773

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

Merged branch/9.2-dev0@722.

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