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

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