source: 3DVCSoftware/branches/HTM-11.2-dev3-MediaTek/source/Lib/TLibDecoder/TDecSbac.cpp @ 983

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

Integration of Single Depth Mode proposed in JCT3V-I0095.
The MACRO is "MTK_SINGLE_DEPTH_MODE_I0095".

By Yi-Wen Chen (yiwen.chen@…)

  • Property svn:eol-style set to native
File size: 67.8 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( pcCU->getSlice()->getVpsDepthModesFlag() )
1052    {
1053      parseIntraDepth( pcCU, absPartIdx+partOffset*j, depth );
1054    }
1055    if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
1056    {
1057#endif
1058    m_pcTDecBinIf->decodeBin( symbol, m_cCUIntraPredSCModel.get( 0, 0, 0) );
1059    mpmPred[j] = symbol;
1060#if H_MV_ENC_DEC_TRAC         
1061    DTRACE_CU("prev_intra_luma_pred_flag", symbol)
1062#endif
1063#if H_3D_DIM
1064    }
1065#endif
1066  }
1067  for (j=0;j<partNum;j++)
1068  {
1069#if H_3D_DIM
1070    if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
1071    {
1072#endif
1073    Int preds[3] = {-1, -1, -1};
1074    Int predNum = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds); 
1075    if (mpmPred[j])
1076    {
1077      m_pcTDecBinIf->decodeBinEP( symbol );
1078      if (symbol)
1079      {
1080        m_pcTDecBinIf->decodeBinEP( symbol );
1081        symbol++;
1082      }
1083#if H_MV_ENC_DEC_TRAC         
1084      DTRACE_CU("mpm_idx", symbol)
1085#endif
1086      intraPredMode = preds[symbol];
1087    }
1088    else
1089    {
1090      m_pcTDecBinIf->decodeBinsEP( symbol, 5 );
1091      intraPredMode = symbol;
1092#if H_MV_ENC_DEC_TRAC         
1093      DTRACE_CU("rem_intra_luma_pred_mode", symbol)
1094#endif       
1095      //postponed sorting of MPMs (only in remaining branch)
1096      if (preds[0] > preds[1])
1097      { 
1098        std::swap(preds[0], preds[1]); 
1099      }
1100      if (preds[0] > preds[2])
1101      {
1102        std::swap(preds[0], preds[2]);
1103      }
1104      if (preds[1] > preds[2])
1105      {
1106        std::swap(preds[1], preds[2]);
1107      }
1108      for ( Int i = 0; i < predNum; i++ )
1109      {
1110        intraPredMode += ( intraPredMode >= preds[i] );
1111      }
1112    }
1113    pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, absPartIdx+partOffset*j, depth );
1114#if H_3D_DIM
1115    }
1116#endif
1117  }
1118}
1119
1120Void TDecSbac::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1121{
1122  UInt uiSymbol;
1123
1124  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) );
1125
1126  if( uiSymbol == 0 )
1127  {
1128#if H_MV_ENC_DEC_TRAC         
1129    DTRACE_CU("intra_chroma_pred_mode", uiSymbol )
1130#endif       
1131    uiSymbol = DM_CHROMA_IDX;
1132  } 
1133  else 
1134  {
1135    {
1136      UInt uiIPredMode;
1137      m_pcTDecBinIf->decodeBinsEP( uiIPredMode, 2 );
1138#if H_MV_ENC_DEC_TRAC         
1139      DTRACE_CU("intra_chroma_pred_mode", uiIPredMode )
1140#endif       
1141      UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ];
1142      pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir );
1143      uiSymbol = uiAllowedChromaDir[ uiIPredMode ];
1144    }
1145  }
1146  pcCU->setChromIntraDirSubParts( uiSymbol, uiAbsPartIdx, uiDepth );
1147  return;
1148}
1149
1150#if H_3D_DIM
1151Void TDecSbac::parseIntraDepth( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
1152{
1153  parseIntraDepthMode( pcCU, absPartIdx, depth );
1154
1155  UInt dir     = pcCU->getLumaIntraDir( absPartIdx );
1156  UInt dimType = getDimType( dir );
1157
1158  switch( dimType )
1159  {
1160#if H_3D_DIM_DMM
1161  case( DMM1_IDX ):
1162    {
1163      UInt uiTabIdx = 0;
1164      xParseDmm1WedgeIdx( uiTabIdx, g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] );
1165      pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, absPartIdx, depth );
1166    } break;
1167  case( DMM4_IDX ): break;
1168#endif
1169  default: break;
1170  }
1171
1172  pcCU->setLumaIntraDirSubParts( (UChar)dir, absPartIdx, depth );
1173}
1174
1175Void TDecSbac::parseIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
1176{
1177  UInt uiSymbol, uiIsDimMode;
1178
1179  if( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() >> pcCU->getDepth( absPartIdx ) ) < 64 ) //DMM and HEVC intra modes are both allowed
1180  {
1181    m_pcTDecBinIf->decodeBin( uiSymbol, m_cAngleFlagSCModel.get( 0, 0, 0 ) );
1182  }
1183  else
1184  {
1185    uiSymbol = 1;
1186  }
1187  uiIsDimMode = uiSymbol ? 0 : 1;
1188  pcCU->setLumaIntraDirSubParts( 0, absPartIdx, depth );
1189
1190  //decode DMM index
1191  if( uiIsDimMode )
1192  {
1193    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDepthIntraModeSCModel.get( 0, 0, 0 ) );
1194    if( !uiSymbol )
1195    {
1196      pcCU->setLumaIntraDirSubParts( ( 2 * DMM1_IDX + DIM_OFFSET ), absPartIdx, depth );
1197    }
1198    else
1199    {
1200      pcCU->setLumaIntraDirSubParts( ( 2 * DMM4_IDX + DIM_OFFSET ), absPartIdx, depth );
1201    }
1202  }
1203}
1204#endif
1205
1206Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx )
1207{
1208  UInt uiSymbol;
1209  const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx );
1210  ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 );
1211  uiSymbol = 0;
1212  if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 )
1213  {
1214    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) );
1215  }
1216
1217  if( uiSymbol )
1218  {
1219    uiSymbol = 2;
1220  }
1221  else
1222  {
1223    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + 4 ) );
1224    assert(uiSymbol == 0 || uiSymbol == 1);
1225  }
1226
1227  uiSymbol++;
1228  ruiInterDir = uiSymbol;
1229#if H_MV_ENC_DEC_TRAC
1230    DTRACE_PU("inter_pred_idc", ruiInterDir - 1 )   
1231#endif
1232
1233  return;
1234}
1235
1236Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList )
1237{
1238  UInt uiSymbol;
1239  {
1240    ContextModel *pCtx = m_cCURefPicSCModel.get( 0 );
1241    m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1242
1243    if( uiSymbol )
1244    {
1245      UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2;
1246      pCtx++;
1247      UInt ui;
1248      for( ui = 0; ui < uiRefNum; ++ui )
1249      {
1250        if( ui == 0 )
1251        {
1252          m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1253        }
1254        else
1255        {
1256          m_pcTDecBinIf->decodeBinEP( uiSymbol );
1257        }
1258        if( uiSymbol == 0 )
1259        {
1260          break;
1261        }
1262      }
1263      uiSymbol = ui + 1;
1264    }
1265    riRefFrmIdx = uiSymbol;
1266  }
1267
1268#if H_MV_ENC_DEC_TRAC
1269#if ENC_DEC_TRACE
1270  if ( eRefList == REF_PIC_LIST_0 )
1271  {
1272    DTRACE_PU("ref_idx_l0", uiSymbol)
1273  }
1274  else
1275  {
1276    DTRACE_PU("ref_idx_l1", uiSymbol)
1277  }
1278#endif
1279#endif
1280  return;
1281}
1282
1283Void TDecSbac::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList )
1284{
1285  UInt uiSymbol;
1286  UInt uiHorAbs;
1287  UInt uiVerAbs;
1288  UInt uiHorSign = 0;
1289  UInt uiVerSign = 0;
1290  ContextModel *pCtx = m_cCUMvdSCModel.get( 0 );
1291
1292  if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3)
1293  {
1294    uiHorAbs=0;
1295    uiVerAbs=0;
1296  }
1297  else
1298  {
1299    m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx );
1300    m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx );
1301
1302    const Bool bHorAbsGr0 = uiHorAbs != 0;
1303    const Bool bVerAbsGr0 = uiVerAbs != 0;
1304    pCtx++;
1305
1306    if( bHorAbsGr0 )
1307    {
1308      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1309      uiHorAbs += uiSymbol;
1310    }
1311
1312    if( bVerAbsGr0 )
1313    {
1314      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1315      uiVerAbs += uiSymbol;
1316    }
1317
1318    if( bHorAbsGr0 )
1319    {
1320      if( 2 == uiHorAbs )
1321      {
1322        xReadEpExGolomb( uiSymbol, 1 );
1323        uiHorAbs += uiSymbol;
1324      }
1325
1326      m_pcTDecBinIf->decodeBinEP( uiHorSign );
1327    }
1328
1329    if( bVerAbsGr0 )
1330    {
1331      if( 2 == uiVerAbs )
1332      {
1333        xReadEpExGolomb( uiSymbol, 1 );
1334        uiVerAbs += uiSymbol;
1335      }
1336
1337      m_pcTDecBinIf->decodeBinEP( uiVerSign );
1338    }
1339
1340  }
1341
1342  const TComMv cMv( uiHorSign ? -Int( uiHorAbs ): uiHorAbs, uiVerSign ? -Int( uiVerAbs ) : uiVerAbs );
1343  pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiDepth, uiPartIdx );
1344  return;
1345}
1346
1347
1348Void TDecSbac::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize )
1349{
1350  m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize ) );
1351#if !H_MV_ENC_DEC_TRAC
1352  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1353  DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" )
1354  DTRACE_CABAC_T( "\tsymbol=" )
1355  DTRACE_CABAC_V( ruiSubdivFlag )
1356  DTRACE_CABAC_T( "\tctx=" )
1357  DTRACE_CABAC_V( uiLog2TransformBlockSize )
1358  DTRACE_CABAC_T( "\n" )
1359#endif
1360}
1361
1362Void TDecSbac::parseQtRootCbf( UInt uiAbsPartIdx, UInt& uiQtRootCbf )
1363{
1364  UInt uiSymbol;
1365  const UInt uiCtx = 0;
1366  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) );
1367#if !H_MV_ENC_DEC_TRAC
1368  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1369  DTRACE_CABAC_T( "\tparseQtRootCbf()" )
1370  DTRACE_CABAC_T( "\tsymbol=" )
1371  DTRACE_CABAC_V( uiSymbol )
1372  DTRACE_CABAC_T( "\tctx=" )
1373  DTRACE_CABAC_V( uiCtx )
1374  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1375  DTRACE_CABAC_V( uiAbsPartIdx )
1376  DTRACE_CABAC_T( "\n" )
1377#else
1378  DTRACE_CU( "rqt_root_cbf", uiSymbol )
1379#endif
1380 
1381  uiQtRootCbf = uiSymbol;
1382}
1383
1384Void TDecSbac::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1385{
1386  Int qp;
1387  UInt uiDQp;
1388  Int  iDQp;
1389 
1390  UInt uiSymbol;
1391
1392  xReadUnaryMaxSymbol (uiDQp,  &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX);
1393
1394  if( uiDQp >= CU_DQP_TU_CMAX)
1395  {
1396    xReadEpExGolomb( uiSymbol, CU_DQP_EG_k );
1397    uiDQp+=uiSymbol;
1398  }
1399
1400  if ( uiDQp > 0 )
1401  {
1402    UInt uiSign;
1403    Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
1404    m_pcTDecBinIf->decodeBinEP(uiSign);
1405    iDQp = uiDQp;
1406    if(uiSign)
1407    {
1408      iDQp = -iDQp;
1409    }
1410    qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY;
1411  }
1412  else 
1413  {
1414    qp = pcCU->getRefQP(uiAbsPartIdx);
1415  }
1416  pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth); 
1417  pcCU->setCodedQP(qp);
1418}
1419
1420Void TDecSbac::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth )
1421{
1422  UInt uiSymbol;
1423  const UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth );
1424  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA: eType, uiCtx ) );
1425#if !H_MV_ENC_DEC_TRAC 
1426  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1427  DTRACE_CABAC_T( "\tparseQtCbf()" )
1428  DTRACE_CABAC_T( "\tsymbol=" )
1429  DTRACE_CABAC_V( uiSymbol )
1430  DTRACE_CABAC_T( "\tctx=" )
1431  DTRACE_CABAC_V( uiCtx )
1432  DTRACE_CABAC_T( "\tetype=" )
1433  DTRACE_CABAC_V( eType )
1434  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1435  DTRACE_CABAC_V( uiAbsPartIdx )
1436  DTRACE_CABAC_T( "\n" )
1437#endif
1438 
1439  pcCU->setCbfSubParts( uiSymbol << uiTrDepth, eType, uiAbsPartIdx, uiDepth );
1440}
1441
1442void TDecSbac::parseTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType)
1443{
1444  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
1445  {
1446    return;
1447  }
1448  if(width != 4 || height != 4)
1449  {
1450    return;
1451  }
1452 
1453  UInt useTransformSkip;
1454  m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) );
1455  if(eTType!= TEXT_LUMA)
1456  {
1457    const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiDepth;
1458    if(uiLog2TrafoSize == 2) 
1459    { 
1460      uiDepth --;
1461    }
1462  }
1463#if !H_MV_ENC_DEC_TRAC
1464  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1465  DTRACE_CABAC_T("\tparseTransformSkip()");
1466  DTRACE_CABAC_T( "\tsymbol=" )
1467  DTRACE_CABAC_V( useTransformSkip )
1468  DTRACE_CABAC_T( "\tAddr=" )
1469  DTRACE_CABAC_V( pcCU->getAddr() )
1470  DTRACE_CABAC_T( "\tetype=" )
1471  DTRACE_CABAC_V( eTType )
1472  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1473  DTRACE_CABAC_V( uiAbsPartIdx )
1474  DTRACE_CABAC_T( "\n" )
1475#endif
1476
1477  pcCU->setTransformSkipSubParts( useTransformSkip, eTType, uiAbsPartIdx, uiDepth);
1478}
1479
1480/** Parse (X,Y) position of the last significant coefficient
1481 * \param uiPosLastX reference to X component of last coefficient
1482 * \param uiPosLastY reference to Y component of last coefficient
1483 * \param width  Block width
1484 * \param height Block height
1485 * \param eTType plane type / luminance or chrominance
1486 * \param uiScanIdx scan type (zig-zag, hor, ver)
1487 *
1488 * This method decodes the X and Y component within a block of the last significant coefficient.
1489 */
1490Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, TextType eTType, UInt uiScanIdx )
1491{
1492  UInt uiLast;
1493  ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType );
1494  ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType );
1495
1496  Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY;
1497  blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2));
1498  blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2));
1499  shiftX= eTType ? g_aucConvertToBit[ width  ] :((g_aucConvertToBit[ width  ]+3)>>2);
1500  shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2);
1501  // posX
1502  for( uiPosLastX = 0; uiPosLastX < g_uiGroupIdx[ width - 1 ]; uiPosLastX++ )
1503  {
1504    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + blkSizeOffsetX + (uiPosLastX >>shiftX) ) );
1505    if( !uiLast )
1506    {
1507      break;
1508    }
1509  }
1510
1511  // posY
1512  for( uiPosLastY = 0; uiPosLastY < g_uiGroupIdx[ height - 1 ]; uiPosLastY++ )
1513  {
1514    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + blkSizeOffsetY + (uiPosLastY >>shiftY)) );
1515    if( !uiLast )
1516    {
1517      break;
1518    }
1519  }
1520  if ( uiPosLastX > 3 )
1521  {
1522    UInt uiTemp  = 0;
1523    UInt uiCount = ( uiPosLastX - 2 ) >> 1;
1524    for ( Int i = uiCount - 1; i >= 0; i-- )
1525    {
1526      m_pcTDecBinIf->decodeBinEP( uiLast );
1527      uiTemp += uiLast << i;
1528    }
1529    uiPosLastX = g_uiMinInGroup[ uiPosLastX ] + uiTemp;
1530  }
1531  if ( uiPosLastY > 3 )
1532  {
1533    UInt uiTemp  = 0;
1534    UInt uiCount = ( uiPosLastY - 2 ) >> 1;
1535    for ( Int i = uiCount - 1; i >= 0; i-- )
1536    {
1537      m_pcTDecBinIf->decodeBinEP( uiLast );
1538      uiTemp += uiLast << i;
1539    }
1540    uiPosLastY = g_uiMinInGroup[ uiPosLastY ] + uiTemp;
1541  }
1542 
1543  if( uiScanIdx == SCAN_VER )
1544  {
1545    swap( uiPosLastX, uiPosLastY );
1546  }
1547}
1548
1549Void TDecSbac::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType )
1550{
1551#if !H_MV_ENC_DEC_TRAC
1552  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1553  DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" )
1554  DTRACE_CABAC_V( eTType )
1555  DTRACE_CABAC_T( "\twidth=" )
1556  DTRACE_CABAC_V( uiWidth )
1557  DTRACE_CABAC_T( "\theight=" )
1558  DTRACE_CABAC_V( uiHeight )
1559  DTRACE_CABAC_T( "\tdepth=" )
1560  DTRACE_CABAC_V( uiDepth )
1561  DTRACE_CABAC_T( "\tabspartidx=" )
1562  DTRACE_CABAC_V( uiAbsPartIdx )
1563  DTRACE_CABAC_T( "\ttoCU-X=" )
1564  DTRACE_CABAC_V( pcCU->getCUPelX() )
1565  DTRACE_CABAC_T( "\ttoCU-Y=" )
1566  DTRACE_CABAC_V( pcCU->getCUPelY() )
1567  DTRACE_CABAC_T( "\tCU-addr=" )
1568  DTRACE_CABAC_V(  pcCU->getAddr() )
1569  DTRACE_CABAC_T( "\tinCU-X=" )
1570  DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1571  DTRACE_CABAC_T( "\tinCU-Y=" )
1572  DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1573  DTRACE_CABAC_T( "\tpredmode=" )
1574  DTRACE_CABAC_V(  pcCU->getPredictionMode( uiAbsPartIdx ) )
1575  DTRACE_CABAC_T( "\n" )
1576#endif
1577 
1578  if( uiWidth > pcCU->getSlice()->getSPS()->getMaxTrSize() )
1579  {
1580    uiWidth  = pcCU->getSlice()->getSPS()->getMaxTrSize();
1581    uiHeight = pcCU->getSlice()->getSPS()->getMaxTrSize();
1582  }
1583  if(pcCU->getSlice()->getPPS()->getUseTransformSkip())
1584  {
1585    parseTransformSkipFlags( pcCU, uiAbsPartIdx, uiWidth, uiHeight, uiDepth, eTType);
1586  }
1587
1588  eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA );
1589 
1590  //----- parse significance map -----
1591  const UInt  uiLog2BlockSize   = g_aucConvertToBit[ uiWidth ] + 2;
1592  const UInt  uiMaxNumCoeff     = uiWidth * uiHeight;
1593  const UInt  uiMaxNumCoeffM1   = uiMaxNumCoeff - 1;
1594  UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx));
1595 
1596  //===== decode last significant =====
1597  UInt uiPosLastX, uiPosLastY;
1598  parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, eTType, uiScanIdx );
1599  UInt uiBlkPosLast      = uiPosLastX + (uiPosLastY<<uiLog2BlockSize);
1600  pcCoef[ uiBlkPosLast ] = 1;
1601
1602  //===== decode significance flags =====
1603  UInt uiScanPosLast;
1604  const UInt *scan   = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize-1 ];
1605  for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ )
1606  {
1607    UInt uiBlkPos = scan[ uiScanPosLast ];
1608    if( uiBlkPosLast == uiBlkPos )
1609    {
1610      break;
1611    }
1612  }
1613
1614  ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType );
1615  ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA;
1616
1617  const Int  iLastScanSet      = uiScanPosLast >> LOG2_SCAN_SET_SIZE;
1618  UInt c1 = 1;
1619  UInt uiGoRiceParam           = 0;
1620
1621  Bool beValid; 
1622  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
1623  {
1624    beValid = false;
1625  }
1626  else 
1627  {
1628    beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0;
1629  }
1630  UInt absSum = 0;
1631
1632  UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ];
1633  ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM );
1634  const UInt uiNumBlkSide = uiWidth >> (MLS_CG_SIZE >> 1);
1635  const UInt * scanCG;
1636  {
1637    scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0  ];   
1638    if( uiLog2BlockSize == 3 )
1639    {
1640      scanCG = g_sigLastScan8x8[ uiScanIdx ];
1641    }
1642    else if( uiLog2BlockSize == 5 )
1643    {
1644      scanCG = g_sigLastScanCG32x32;
1645    }
1646  }
1647  Int  iScanPosSig             = (Int) uiScanPosLast;
1648  for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- )
1649  {
1650    Int  iSubPos     = iSubSet << LOG2_SCAN_SET_SIZE;
1651    uiGoRiceParam    = 0;
1652    Int numNonZero = 0;
1653   
1654    Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE;
1655
1656    Int pos[SCAN_SET_SIZE];
1657    if( iScanPosSig == (Int) uiScanPosLast )
1658    {
1659      lastNZPosInCG  = iScanPosSig;
1660      firstNZPosInCG = iScanPosSig;
1661      iScanPosSig--;
1662      pos[ numNonZero ] = uiBlkPosLast;
1663      numNonZero = 1;
1664    }
1665
1666    // decode significant_coeffgroup_flag
1667    Int iCGBlkPos = scanCG[ iSubSet ];
1668    Int iCGPosY   = iCGBlkPos / uiNumBlkSide;
1669    Int iCGPosX   = iCGBlkPos - (iCGPosY * uiNumBlkSide);
1670    if( iSubSet == iLastScanSet || iSubSet == 0)
1671    {
1672      uiSigCoeffGroupFlag[ iCGBlkPos ] = 1;
1673    }
1674    else
1675    {
1676      UInt uiSigCoeffGroup;
1677      UInt uiCtxSig  = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight );
1678      m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] );
1679      uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup;
1680    }
1681
1682    // decode significant_coeff_flag
1683    Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight );
1684    UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig;
1685    for( ; iScanPosSig >= iSubPos; iScanPosSig-- )
1686    {
1687      uiBlkPos  = scan[ iScanPosSig ];
1688      uiPosY    = uiBlkPos >> uiLog2BlockSize;
1689      uiPosX    = uiBlkPos - ( uiPosY << uiLog2BlockSize );
1690      uiSig     = 0;
1691     
1692      if( uiSigCoeffGroupFlag[ iCGBlkPos ] )
1693      {
1694        if( iScanPosSig > iSubPos || iSubSet == 0  || numNonZero )
1695        {
1696          uiCtxSig  = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType );
1697          m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] );
1698        }
1699        else
1700        {
1701          uiSig = 1;
1702        }
1703      }
1704      pcCoef[ uiBlkPos ] = uiSig;
1705      if( uiSig )
1706      {
1707        pos[ numNonZero ] = uiBlkPos;
1708        numNonZero ++;
1709        if( lastNZPosInCG == -1 )
1710        {
1711          lastNZPosInCG = iScanPosSig;
1712        }
1713        firstNZPosInCG = iScanPosSig;
1714      }
1715    }
1716   
1717    if( numNonZero )
1718    {
1719      Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD );
1720      absSum = 0;
1721      UInt uiCtxSet    = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0;
1722      UInt uiBin;
1723      if( c1 == 0 )
1724      {
1725        uiCtxSet++;
1726      }
1727      c1 = 1;
1728      ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet;
1729      Int absCoeff[SCAN_SET_SIZE];
1730
1731      for ( Int i = 0; i < numNonZero; i++) absCoeff[i] = 1;   
1732      Int numC1Flag = min(numNonZero, C1FLAG_NUMBER);
1733      Int firstC2FlagIdx = -1;
1734
1735      for( Int idx = 0; idx < numC1Flag; idx++ )
1736      {
1737        m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] );
1738        if( uiBin == 1 )
1739        {
1740          c1 = 0;
1741          if (firstC2FlagIdx == -1)
1742          {
1743            firstC2FlagIdx = idx;
1744          }
1745        }
1746        else if( (c1 < 3) && (c1 > 0) )
1747        {
1748          c1++;
1749        }
1750        absCoeff[ idx ] = uiBin + 1;
1751      }
1752     
1753      if (c1 == 0)
1754      {
1755        baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet;
1756        if ( firstC2FlagIdx != -1)
1757        {
1758          m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] ); 
1759          absCoeff[ firstC2FlagIdx ] = uiBin + 2;
1760        }
1761      }
1762
1763      UInt coeffSigns;
1764      if ( signHidden && beValid )
1765      {
1766        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 );
1767        coeffSigns <<= 32 - (numNonZero-1);
1768      }
1769      else
1770      {
1771        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero );
1772        coeffSigns <<= 32 - numNonZero;
1773      }
1774     
1775      Int iFirstCoeff2 = 1;   
1776      if (c1 == 0 || numNonZero > C1FLAG_NUMBER)
1777      {
1778        for( Int idx = 0; idx < numNonZero; idx++ )
1779        {
1780          UInt baseLevel  = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2) : 1;
1781
1782          if( absCoeff[ idx ] == baseLevel)
1783          {
1784            UInt uiLevel;
1785            xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam );
1786            absCoeff[ idx ] = uiLevel + baseLevel;
1787            if(absCoeff[idx]>3*(1<<uiGoRiceParam))
1788            {
1789              uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4);
1790            }
1791          }
1792
1793          if(absCoeff[ idx ] >= 2) 
1794          {
1795            iFirstCoeff2 = 0;
1796          }
1797        }
1798      }
1799
1800      for( Int idx = 0; idx < numNonZero; idx++ )
1801      {
1802        Int blkPos = pos[ idx ];
1803        // Signs applied later.
1804        pcCoef[ blkPos ] = absCoeff[ idx ];
1805        absSum += absCoeff[ idx ];
1806
1807        if ( idx == numNonZero-1 && signHidden && beValid )
1808        {
1809          // Infer sign of 1st element.
1810          if (absSum&0x1)
1811          {
1812            pcCoef[ blkPos ] = -pcCoef[ blkPos ];
1813          }
1814        }
1815        else
1816        {
1817          Int sign = static_cast<Int>( coeffSigns ) >> 31;
1818          pcCoef[ blkPos ] = ( pcCoef[ blkPos ] ^ sign ) - sign;
1819          coeffSigns <<= 1;
1820        }
1821      }
1822    }
1823  }
1824 
1825  return;
1826}
1827
1828
1829Void TDecSbac::parseSaoMaxUvlc ( UInt& val, UInt maxSymbol )
1830{
1831  if (maxSymbol == 0)
1832  {
1833    val = 0;
1834    return;
1835  }
1836
1837  UInt code;
1838  Int  i;
1839  m_pcTDecBinIf->decodeBinEP( code );
1840  if ( code == 0 )
1841  {
1842    val = 0;
1843    return;
1844  }
1845
1846  i=1;
1847  while (1)
1848  {
1849    m_pcTDecBinIf->decodeBinEP( code );
1850    if ( code == 0 )
1851    {
1852      break;
1853    }
1854    i++;
1855    if (i == maxSymbol) 
1856    {
1857      break;
1858    }
1859  }
1860
1861  val = i;
1862}
1863Void TDecSbac::parseSaoUflc (UInt uiLength, UInt&  riVal)
1864{
1865  m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength );
1866}
1867Void TDecSbac::parseSaoMerge (UInt&  ruiVal)
1868{
1869  UInt uiCode;
1870  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) );
1871  ruiVal = (Int)uiCode;
1872}
1873Void TDecSbac::parseSaoTypeIdx (UInt&  ruiVal)
1874{
1875  UInt uiCode;
1876  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
1877  if (uiCode == 0) 
1878  {
1879    ruiVal = 0;
1880  }
1881  else
1882  {
1883    m_pcTDecBinIf->decodeBinEP( uiCode ); 
1884    if (uiCode == 0)
1885    {
1886      ruiVal = 1;
1887    }
1888    else
1889    {
1890      ruiVal = 2;
1891    }
1892  }
1893}
1894
1895Void TDecSbac::parseSaoSign(UInt& val)
1896{
1897  m_pcTDecBinIf->decodeBinEP ( val ); 
1898}
1899
1900Void TDecSbac::parseSAOBlkParam (SAOBlkParam& saoBlkParam
1901                                , Bool* sliceEnabled
1902                                , Bool leftMergeAvail
1903                                , Bool aboveMergeAvail
1904                                )
1905{
1906  UInt uiSymbol;
1907
1908  Bool isLeftMerge = false;
1909  Bool isAboveMerge= false;
1910
1911  if(leftMergeAvail)
1912  {
1913    parseSaoMerge(uiSymbol); //sao_merge_left_flag
1914    isLeftMerge = (uiSymbol?true:false);
1915  }
1916
1917  if( aboveMergeAvail && !isLeftMerge)
1918  {
1919    parseSaoMerge(uiSymbol); //sao_merge_up_flag
1920    isAboveMerge = (uiSymbol?true:false);
1921  }
1922
1923  if(isLeftMerge || isAboveMerge) //merge mode
1924      {
1925    saoBlkParam[SAO_Y].modeIdc = saoBlkParam[SAO_Cb].modeIdc = saoBlkParam[SAO_Cr].modeIdc = SAO_MODE_MERGE;
1926    saoBlkParam[SAO_Y].typeIdc = saoBlkParam[SAO_Cb].typeIdc = saoBlkParam[SAO_Cr].typeIdc = (isLeftMerge)?SAO_MERGE_LEFT:SAO_MERGE_ABOVE;
1927      }   
1928  else //new or off mode
1929      {
1930    for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
1931        {
1932      SAOOffset& ctbParam = saoBlkParam[compIdx];
1933
1934      if(!sliceEnabled[compIdx])
1935          {
1936        //off
1937        ctbParam.modeIdc = SAO_MODE_OFF;
1938        continue;
1939        }
1940
1941      //type
1942      if(compIdx == SAO_Y || compIdx == SAO_Cb)
1943    {
1944        parseSaoTypeIdx(uiSymbol); //sao_type_idx_luma or sao_type_idx_chroma
1945
1946        assert(uiSymbol ==0 || uiSymbol ==1 || uiSymbol ==2);
1947
1948        if(uiSymbol ==0) //OFF
1949     {
1950          ctbParam.modeIdc = SAO_MODE_OFF;
1951   }
1952        else if(uiSymbol == 1) //BO
1953        {
1954          ctbParam.modeIdc = SAO_MODE_NEW;
1955          ctbParam.typeIdc = SAO_TYPE_START_BO;
1956  }
1957        else //2, EO
1958  {
1959          ctbParam.modeIdc = SAO_MODE_NEW;
1960          ctbParam.typeIdc = SAO_TYPE_START_EO;
1961        }
1962
1963  }
1964      else //Cr, follow Cb SAO type
1965      {
1966        ctbParam.modeIdc = saoBlkParam[SAO_Cb].modeIdc;
1967        ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc;
1968}
1969
1970      if(ctbParam.modeIdc == SAO_MODE_NEW)
1971{
1972        Int offset[4];
1973        for(Int i=0; i< 4; i++)
1974  {
1975          parseSaoMaxUvlc(uiSymbol,  g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
1976          offset[i] = (Int)uiSymbol;
1977  }
1978
1979        if(ctbParam.typeIdc == SAO_TYPE_START_BO)
1980  {
1981          for(Int i=0; i< 4; i++)
1982    {
1983            if(offset[i] != 0)
1984    {
1985              parseSaoSign(uiSymbol); //sao_offset_sign
1986              if(uiSymbol)
1987      {
1988                offset[i] = -offset[i];
1989      }
1990    }
1991  }
1992          parseSaoUflc(NUM_SAO_BO_CLASSES_LOG2, uiSymbol ); //sao_band_position
1993          ctbParam.typeAuxInfo = uiSymbol;
1994
1995          for(Int i=0; i<4; i++)
1996      {
1997            ctbParam.offset[(ctbParam.typeAuxInfo+i)%MAX_NUM_SAO_CLASSES] = offset[i];
1998      }
1999
2000        }
2001        else //EO
2002        {
2003          ctbParam.typeAuxInfo = 0;
2004
2005          if(compIdx == SAO_Y || compIdx == SAO_Cb)
2006        {
2007            parseSaoUflc(NUM_SAO_EO_TYPES_LOG2, uiSymbol ); //sao_eo_class_luma or sao_eo_class_chroma
2008            ctbParam.typeIdc += uiSymbol;
2009        }
2010        else
2011        {
2012            ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc;
2013        }
2014          ctbParam.offset[SAO_CLASS_EO_FULL_VALLEY] = offset[0];
2015          ctbParam.offset[SAO_CLASS_EO_HALF_VALLEY] = offset[1];
2016          ctbParam.offset[SAO_CLASS_EO_PLAIN      ] = 0;
2017          ctbParam.offset[SAO_CLASS_EO_HALF_PEAK  ] = -offset[2];
2018          ctbParam.offset[SAO_CLASS_EO_FULL_PEAK  ] = -offset[3];
2019      }
2020      }
2021    }
2022  }
2023}
2024
2025/**
2026 - Initialize our contexts from the nominated source.
2027 .
2028 \param pSrc Contexts to be copied.
2029 */
2030Void TDecSbac::xCopyContextsFrom( TDecSbac* pSrc )
2031{
2032  memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0]));
2033}
2034
2035Void TDecSbac::xCopyFrom( TDecSbac* pSrc )
2036{
2037  m_pcTDecBinIf->copyState( pSrc->m_pcTDecBinIf );
2038
2039  m_uiLastQp           = pSrc->m_uiLastQp;
2040  xCopyContextsFrom( pSrc );
2041
2042}
2043
2044Void TDecSbac::load ( TDecSbac* pScr )
2045{
2046  xCopyFrom(pScr);
2047}
2048
2049Void TDecSbac::loadContexts ( TDecSbac* pScr )
2050{
2051  xCopyContextsFrom(pScr);
2052}
2053
2054#if H_3D_ARP
2055Void TDecSbac::parseARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2056{
2057  UInt uiMaxW = pcCU->getSlice()->getARPStepNum() - 1;
2058  UInt uiW = 0;
2059  UInt uiOffset = pcCU->getCTXARPWFlag(uiAbsPartIdx);
2060  UInt uiCode = 0;
2061
2062  assert ( uiMaxW > 0 );
2063
2064  m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPWSCModel.get( 0, 0, 0 + uiOffset ) );
2065
2066  uiW = uiCode;
2067  if( 1 == uiW )   
2068  {
2069    m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPWSCModel.get( 0, 0, 2 ) );
2070    uiW += ( 1 == uiCode ? 1 : 0 );
2071  }
2072#if H_MV_ENC_DEC_TRAC
2073  DTRACE_CU("iv_res_pred_weight_idx", uiW )
2074#endif
2075  pcCU->setARPWSubParts( ( UChar )( uiW ) , uiAbsPartIdx, uiDepth ); 
2076}
2077#endif
2078
2079#if H_3D_IC
2080/** parse illumination compensation flag
2081 * \param pcCU
2082 * \param uiAbsPartIdx
2083 * \param uiDepth
2084 * \returns Void
2085 */
2086Void TDecSbac::parseICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2087{ 
2088  UInt uiSymbol = 0;
2089  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUICFlagSCModel.get( 0, 0, 0 ) );
2090#if !H_MV_ENC_DEC_TRAC
2091  DTRACE_CABAC_VL( g_nSymbolCounter++ );
2092  DTRACE_CABAC_T( "\tICFlag" );
2093  DTRACE_CABAC_T( "\tuiCtxIC: ");
2094  DTRACE_CABAC_V( uiCtxIC );
2095  DTRACE_CABAC_T( "\tuiSymbol: ");
2096  DTRACE_CABAC_V( uiSymbol );
2097  DTRACE_CABAC_T( "\n");
2098#else
2099  DTRACE_CU("ic_flag", uiSymbol)
2100#endif
2101 
2102  pcCU->setICFlagSubParts( uiSymbol ? true : false , uiAbsPartIdx, 0, uiDepth );
2103}
2104#endif
2105
2106#if H_3D_INTER_SDC
2107Void TDecSbac::parseDeltaDC( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
2108{
2109  if( ! ( pcCU->getSDCFlag( absPartIdx ) || ( pcCU->isIntra( absPartIdx ) && getDimType( pcCU->getLumaIntraDir( absPartIdx ) ) < DIM_NUM_TYPE ) ) )
2110  {
2111    assert( 0 );
2112  }
2113
2114  UInt symbol = 0;
2115  UInt uiNumSegments = 0;
2116
2117  if( pcCU->isIntra( absPartIdx ) )
2118  {
2119    UInt dir     = pcCU->getLumaIntraDir( absPartIdx );
2120    uiNumSegments = isDimMode( dir ) ? 2 : 1;
2121    m_pcTDecBinIf->decodeBin( symbol, m_cDdcFlagSCModel.get( 0, 0, 0 ) );
2122    if( pcCU->getSDCFlag( absPartIdx ) )
2123    {
2124      assert( pcCU->getPartitionSize( absPartIdx ) == SIZE_2Nx2N );
2125      pcCU->setTrIdxSubParts( 0, absPartIdx, depth );
2126      pcCU->setCbfSubParts( 1, 1, 1, absPartIdx, depth );
2127    }
2128    else
2129    {
2130      pcCU->setLumaIntraDirSubParts( dir + symbol, absPartIdx, depth );
2131    }
2132  }
2133  else
2134  {
2135    uiNumSegments = 1;
2136    symbol = 1;
2137  }
2138
2139
2140  for( UInt segment = 0; segment < uiNumSegments; segment++ )
2141  {
2142    Pel valDeltaDC = 0;
2143    if( symbol )
2144    {
2145      xParseDimDeltaDC( valDeltaDC, uiNumSegments );
2146    }
2147
2148    if( pcCU->isIntra( absPartIdx ) )
2149    {
2150      UInt dir     = pcCU->getLumaIntraDir( absPartIdx );
2151
2152      if( pcCU->getSDCFlag( absPartIdx ) )
2153      {
2154        pcCU->setSDCSegmentDCOffset( valDeltaDC, segment, absPartIdx );
2155      }
2156      else
2157      {
2158        pcCU->setDimDeltaDC( getDimType( dir ), segment, absPartIdx, valDeltaDC );
2159      }
2160    }
2161    else
2162    {
2163      pcCU->setSDCSegmentDCOffset( valDeltaDC, segment, absPartIdx );
2164    }
2165  }
2166}
2167
2168Void TDecSbac::parseSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2169{
2170  UInt uiSymbol = 0;
2171  UInt uiCtxSDCFlag = pcCU->getCtxSDCFlag( uiAbsPartIdx );
2172
2173  m_pcTDecBinIf->decodeBin( uiSymbol, m_cSDCFlagSCModel.get( 0, 0, uiCtxSDCFlag ) );
2174
2175  if( uiSymbol )
2176  {
2177    pcCU->setSDCFlagSubParts( true, uiAbsPartIdx, uiDepth );
2178    pcCU->setTrIdxSubParts( 0, uiAbsPartIdx, uiDepth );
2179    pcCU->setCbfSubParts( 1, 1, 1, uiAbsPartIdx, uiDepth );
2180  }
2181  else
2182  {
2183    pcCU->setSDCFlagSubParts( false, uiAbsPartIdx, uiDepth );
2184  }
2185}
2186
2187#endif
2188
2189#if H_3D_DBBP
2190Void TDecSbac::parseDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2191{
2192  AOF( pcCU->getSlice()->getVPS()->getUseDBBP(pcCU->getSlice()->getLayerIdInVps()) );
2193  AOF( !pcCU->getSlice()->getIsDepth() );
2194 
2195  UInt uiSymbol = 0;
2196 
2197  m_pcTDecBinIf->decodeBin( uiSymbol, m_cDBBPFlagSCModel.get( 0, 0, 0 ) );
2198 
2199  if( uiSymbol )
2200  {
2201    pcCU->setDBBPFlagSubParts(true, uiAbsPartIdx, 0, uiDepth);
2202    UInt uiCurrPartNumQ = (pcCU->getPic()->getNumPartInCU() >> (2 * uiDepth)) >> 2;
2203    pcCU->setDBBPFlagSubParts(true, uiAbsPartIdx + 2*uiCurrPartNumQ, 1, uiDepth);
2204  }
2205}
2206#endif
2207
2208
2209
2210//! \}
Note: See TracBrowser for help on using the repository browser.