source: 3DVCSoftware/branches/HTM-9.2-dev0/source/Lib/TLibDecoder/TDecSbac.cpp @ 764

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

Cleanup part 1

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