source: 3DVCSoftware/trunk/source/Lib/TLibDecoder/TDecSbac.cpp @ 1179

Last change on this file since 1179 was 1179, checked in by tech, 9 years ago

Merged branch 13.1-dev0@1178.

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