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

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

Merged 11.2-dev1-MediaTek@1004.

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