source: 3DVCSoftware/branches/HTM-9.3-dev2-MediaTek/source/Lib/TLibDecoder/TDecSbac.cpp @ 790

Last change on this file since 790 was 790, checked in by mediatek-htm, 10 years ago

JCT3V-G0055 Integrated

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