source: 3DVCSoftware/branches/HTM-13.1-dev1-Qualcomm/source/Lib/TLibDecoder/TDecSbac.cpp

Last change on this file was 1145, checked in by samsung-htm, 10 years ago

Integration of K0033: Depth intra skip (DIS) mode

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