source: 3DVCSoftware/branches/HTM-11.2-dev0/source/Lib/TLibDecoder/TDecSbac.cpp @ 1030

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

Merged 11.2-dev2-Samsung@1026.

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