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

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

integration of JCT3V-G0122 (generalize SDC to all depth intra modes) by Qualcomm.

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