source: 3DVCSoftware/branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibDecoder/TDecSbac.cpp

Last change on this file was 782, checked in by qualcomm, 10 years ago

integration of JCT3V-G0130 (unify signaling and delta DC coding in intra SDC and inter SDC) by Qualcomm

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