source: 3DVCSoftware/branches/HTM-12.2-dev1-Sharp/source/Lib/TLibDecoder/TDecSbac.cpp @ 1417

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

J0033: Assertion at decoder

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