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

Last change on this file since 1039 was 1039, checked in by tech, 11 years ago

Merged 11.2-dev0@1038.

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