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

Last change on this file since 1191 was 1179, checked in by tech, 10 years ago

Merged branch 13.1-dev0@1178.

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