source: 3DVCSoftware/branches/HTM-6.2-dev0/source/Lib/TLibDecoder/TDecSbac.cpp @ 433

Last change on this file since 433 was 433, checked in by tech, 12 years ago

Merged HTM-6.2-dev3-RWTH-Fix Rev. 415

  • Property svn:eol-style set to native
File size: 90.7 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6 * Copyright (c) 2010-2012, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TDecSbac.cpp
35    \brief    Context-adaptive entropy decoder class
36*/
37
38#include "TDecSbac.h"
39
40//! \ingroup TLibDecoder
41//! \{
42
43//////////////////////////////////////////////////////////////////////
44// Construction/Destruction
45//////////////////////////////////////////////////////////////////////
46
47TDecSbac::TDecSbac() 
48// new structure here
49: m_pcBitstream               ( 0 )
50, m_pcTDecBinIf               ( NULL )
51, m_numContextModels          ( 0 )
52, m_cCUSplitFlagSCModel       ( 1,             1,               NUM_SPLIT_FLAG_CTX            , m_contextModels + m_numContextModels, m_numContextModels )
53, m_cCUSkipFlagSCModel        ( 1,             1,               NUM_SKIP_FLAG_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
54#if LGE_ILLUCOMP_B0045
55, m_cCUICFlagSCModel          ( 1,             1,               NUM_IC_FLAG_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
56#endif
57, m_cCUMergeFlagExtSCModel    ( 1,             1,               NUM_MERGE_FLAG_EXT_CTX        , m_contextModels + m_numContextModels, m_numContextModels)
58, m_cCUMergeIdxExtSCModel     ( 1,             1,               NUM_MERGE_IDX_EXT_CTX         , m_contextModels + m_numContextModels, m_numContextModels)
59#if H3D_IVRP
60, m_cResPredFlagSCModel       ( 1,             1,               NUM_RES_PRED_FLAG_CTX         , m_contextModels + m_numContextModels, m_numContextModels)
61#endif
62#if QC_ARP_D0177
63, m_cCUPUARPW                 ( 1,             1,               NUM_ARPW_CTX                 , m_contextModels + m_numContextModels, m_numContextModels)
64#endif
65, m_cCUPartSizeSCModel        ( 1,             1,               NUM_PART_SIZE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
66, m_cCUPredModeSCModel        ( 1,             1,               NUM_PRED_MODE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
67, m_cCUAlfCtrlFlagSCModel     ( 1,             1,               NUM_ALF_CTRL_FLAG_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)
84, m_cALFFlagSCModel           ( 1,             1,               NUM_ALF_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
85, m_cALFUvlcSCModel           ( 1,             1,               NUM_ALF_UVLC_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
86, m_cALFSvlcSCModel           ( 1,             1,               NUM_ALF_SVLC_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
87, m_cCUAMPSCModel             ( 1,             1,               NUM_CU_AMP_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
88#if LGE_SAO_MIGRATION_D0091
89, m_cSaoMergeSCModel          ( 1,             1,               NUM_SAO_MERGE_FLAG_CTX        , m_contextModels + m_numContextModels, m_numContextModels)
90, m_cSaoTypeIdxSCModel        ( 1,             1,               NUM_SAO_TYPE_IDX_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
91#else
92, m_cSaoFlagSCModel           ( 1,             1,               NUM_SAO_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
93, m_cSaoUvlcSCModel           ( 1,             1,               NUM_SAO_UVLC_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
94, m_cSaoSvlcSCModel           ( 1,             1,               NUM_SAO_SVLC_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
95, m_cSaoMergeLeftSCModel      ( 1,             1,               NUM_SAO_MERGE_LEFT_FLAG_CTX   , m_contextModels + m_numContextModels, m_numContextModels)
96, m_cSaoMergeUpSCModel        ( 1,             1,               NUM_SAO_MERGE_UP_FLAG_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
97, m_cSaoTypeIdxSCModel        ( 1,             1,               NUM_SAO_TYPE_IDX_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
98#endif
99#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
100#if !PKU_QC_DEPTH_INTRA_UNI_D0195
101, m_cDmmFlagSCModel           ( 1,             1,               NUM_DMM_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
102, m_cDmmModeSCModel           ( 1,             1,               NUM_DMM_MODE_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
103#endif
104, m_cDmmDataSCModel           ( 1,             1,               NUM_DMM_DATA_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
105#endif
106#if LGE_EDGE_INTRA_A0070
107, m_cEdgeIntraSCModel         ( 1,             1,               NUM_EDGE_INTRA_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
108#if LGE_EDGE_INTRA_DELTA_DC
109, m_cEdgeIntraDeltaDCSCModel  ( 1,             1,               NUM_EDGE_INTRA_DELTA_DC_CTX   , m_contextModels + m_numContextModels, m_numContextModels)
110#endif
111#endif
112#if RWTH_SDC_DLT_B0036
113#if !PKU_QC_DEPTH_INTRA_UNI_D0195
114, m_cSDCFlagSCModel             ( 1,             1,                 SDC_NUM_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
115#else
116, m_cDepthModeModel             ( 1,             1,                 DEPTH_MODE_NUM_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
117, m_cDmmDeltaFlagModel             ( 1,             1,                 DMM_DELTA_NUM_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
118#endif
119#if RWTH_SDC_CTX_SIMPL_D0032
120, m_cSDCResidualFlagSCModel     ( 1,             1,  SDC_NUM_RESIDUAL_FLAG_CTX  , m_contextModels + m_numContextModels, m_numContextModels)
121, m_cSDCResidualSCModel         ( 1,             1,  SDC_NUM_RESIDUAL_CTX       , m_contextModels + m_numContextModels, m_numContextModels)
122, m_cSDCPredModeSCModel             ( 1,             3,                 SDC_NUM_PRED_MODE_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
123#else
124, m_cSDCResidualFlagSCModel     ( 1,             2,  SDC_NUM_RESIDUAL_FLAG_CTX  , m_contextModels + m_numContextModels, m_numContextModels)
125, m_cSDCResidualSignFlagSCModel ( 1,             2,  SDC_NUM_SIGN_FLAG_CTX      , m_contextModels + m_numContextModels, m_numContextModels)
126, m_cSDCResidualSCModel         ( 1,             2,  SDC_NUM_RESIDUAL_CTX       , m_contextModels + m_numContextModels, m_numContextModels)
127, m_cSDCPredModeSCModel             ( 1,             3,                 SDC_NUM_PRED_MODE_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
128#endif
129#endif
130{
131  assert( m_numContextModels <= MAX_NUM_CTX_MOD );
132  m_iSliceGranularity = 0;
133}
134
135TDecSbac::~TDecSbac()
136{
137}
138
139// ====================================================================================================================
140// Public member functions
141// ====================================================================================================================
142
143#if CABAC_INIT_FLAG
144Void TDecSbac::resetEntropy(TComSlice* pSlice)
145{
146  SliceType sliceType  = pSlice->getSliceType();
147  Int       qp         = pSlice->getSliceQp();
148
149  if (pSlice->getPPS()->getCabacInitPresentFlag() && pSlice->getCabacInitFlag())
150  {
151    switch (sliceType)
152    {
153    case P_SLICE:           // change initialization table to B_SLICE initialization
154      sliceType = B_SLICE; 
155      break;
156    case B_SLICE:           // change initialization table to P_SLICE initialization
157      sliceType = P_SLICE; 
158      break;
159    default     :           // should not occur
160      assert(0);
161    }
162  }
163
164#else
165Void TDecSbac::resetEntropywithQPandInitIDC (Int  qp, Int iID)
166{
167  SliceType sliceType = (SliceType)iID;
168#endif 
169
170  m_cCUSplitFlagSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_SPLIT_FLAG );
171  m_cCUSkipFlagSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SKIP_FLAG );
172#if LGE_ILLUCOMP_B0045
173  m_cCUICFlagSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_IC_FLAG );
174#endif
175  m_cCUMergeFlagExtSCModel.initBuffer    ( sliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT );
176  m_cCUMergeIdxExtSCModel.initBuffer     ( sliceType, qp, (UChar*)INIT_MERGE_IDX_EXT );
177#if H3D_IVRP
178  m_cResPredFlagSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_RES_PRED_FLAG );
179#endif
180#if QC_ARP_D0177
181  m_cCUPUARPW.initBuffer                ( sliceType, qp, (UChar*)INIT_ARPW );
182#endif
183  m_cCUAlfCtrlFlagSCModel.initBuffer     ( sliceType, qp, (UChar*)INIT_ALF_CTRL_FLAG );
184  m_cCUPartSizeSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_PART_SIZE );
185  m_cCUAMPSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_CU_AMP_POS );
186  m_cCUPredModeSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_PRED_MODE );
187  m_cCUIntraPredSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_INTRA_PRED_MODE );
188  m_cCUChromaPredSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE );
189  m_cCUInterDirSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_INTER_DIR );
190  m_cCUMvdSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_MVD );
191  m_cCURefPicSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_REF_PIC );
192  m_cCUDeltaQpSCModel.initBuffer         ( sliceType, qp, (UChar*)INIT_DQP );
193  m_cCUQtCbfSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_QT_CBF );
194  m_cCUQtRootCbfSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_QT_ROOT_CBF );
195  m_cCUSigCoeffGroupSCModel.initBuffer   ( sliceType, qp, (UChar*)INIT_SIG_CG_FLAG );
196  m_cCUSigSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_SIG_FLAG );
197  m_cCuCtxLastX.initBuffer               ( sliceType, qp, (UChar*)INIT_LAST );
198  m_cCuCtxLastY.initBuffer               ( sliceType, qp, (UChar*)INIT_LAST );
199  m_cCUOneSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_ONE_FLAG );
200  m_cCUAbsSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_ABS_FLAG );
201  m_cMVPIdxSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_MVP_IDX );
202  m_cALFFlagSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_ALF_FLAG );
203  m_cALFUvlcSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_ALF_UVLC );
204  m_cALFSvlcSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_ALF_SVLC );
205#if LGE_SAO_MIGRATION_D0091
206  m_cSaoMergeSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG );
207  m_cSaoTypeIdxSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
208#else
209  m_cSaoFlagSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_SAO_FLAG );
210  m_cSaoUvlcSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_SAO_UVLC );
211  m_cSaoSvlcSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_SAO_SVLC );
212  m_cSaoMergeLeftSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_SAO_MERGE_LEFT_FLAG );
213  m_cSaoMergeUpSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SAO_MERGE_UP_FLAG );
214  m_cSaoTypeIdxSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
215#endif
216
217  m_cCUTransSubdivFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
218#if LGE_EDGE_INTRA_A0070
219  m_cEdgeIntraSCModel.initBuffer         ( sliceType, qp, (UChar*)INIT_EDGE_INTRA );
220#if LGE_EDGE_INTRA_DELTA_DC
221  m_cEdgeIntraDeltaDCSCModel.initBuffer  ( sliceType, qp, (UChar*)INIT_EDGE_INTRA_DELTA_DC );
222#endif
223#endif
224  m_uiLastDQpNonZero  = 0;
225#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
226#if !PKU_QC_DEPTH_INTRA_UNI_D0195
227  m_cDmmFlagSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DMM_FLAG );
228  m_cDmmModeSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DMM_MODE );
229#endif
230  m_cDmmDataSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DMM_DATA );
231#endif
232#if RWTH_SDC_DLT_B0036
233#if !PKU_QC_DEPTH_INTRA_UNI_D0195
234  m_cSDCFlagSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_SDC_FLAG );
235#else
236  m_cDepthModeModel.initBuffer              ( sliceType, qp, (UChar*)INIT_DEPTHMODE_FLAG );
237  m_cDmmDeltaFlagModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DMMDELTA_FLAG );
238#endif
239  m_cSDCResidualFlagSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
240  m_cSDCResidualSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL );
241#if !RWTH_SDC_CTX_SIMPL_D0032
242  m_cSDCResidualSignFlagSCModel.initBuffer  ( sliceType, qp, (UChar*)INIT_SDC_SIGN_FLAG );
243#endif
244  m_cSDCPredModeSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_SDC_PRED_MODE );
245#endif
246 
247  // new structure
248  m_uiLastQp          = qp;
249 
250  m_pcTDecBinIf->start();
251}
252
253/** The function does the following: Read out terminate bit. Flush CABAC. Byte-align for next tile.
254 *  Intialize CABAC states. Start CABAC.
255 */
256Void TDecSbac::updateContextTables( SliceType eSliceType, Int iQp )
257{
258  UInt uiBit;
259  m_pcTDecBinIf->decodeBinTrm(uiBit);
260  m_pcTDecBinIf->finish(); 
261#if !OL_FLUSH_ALIGN
262  // Account for misaligned CABAC.
263  Int iCABACReadAhead = m_pcTDecBinIf->getBitsReadAhead();
264  iCABACReadAhead--;
265  Int iStreamBits = 8-m_pcBitstream->getNumBitsUntilByteAligned();
266  if (iCABACReadAhead >= iStreamBits)
267  {
268    // Misaligned CABAC has read into the 1st byte of the next tile.
269    // Back up a byte prior to alignment.
270    m_pcBitstream->backupByte();
271  }
272#endif
273  m_pcBitstream->readOutTrailingBits();
274  m_cCUSplitFlagSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG );
275  m_cCUSkipFlagSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG );
276#if LGE_ILLUCOMP_B0045
277  m_cCUICFlagSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_IC_FLAG );
278#endif
279  m_cCUMergeFlagExtSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT );
280  m_cCUMergeIdxExtSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT );
281#if H3D_IVRP
282  m_cResPredFlagSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_RES_PRED_FLAG );
283#endif
284#if QC_ARP_D0177
285  m_cCUPUARPW.initBuffer                 ( eSliceType, iQp, (UChar*)INIT_ARPW );
286#endif
287  m_cCUAlfCtrlFlagSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_ALF_CTRL_FLAG );
288  m_cCUPartSizeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PART_SIZE );
289  m_cCUAMPSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS );
290  m_cCUPredModeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PRED_MODE );
291  m_cCUIntraPredSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE );
292  m_cCUChromaPredSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE );
293  m_cCUInterDirSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_INTER_DIR );
294  m_cCUMvdSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_MVD );
295  m_cCURefPicSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_REF_PIC );
296  m_cCUDeltaQpSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_DQP );
297  m_cCUQtCbfSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_QT_CBF );
298  m_cCUQtRootCbfSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF );
299  m_cCUSigCoeffGroupSCModel.initBuffer   ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG );
300  m_cCUSigSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG );
301  m_cCuCtxLastX.initBuffer               ( eSliceType, iQp, (UChar*)INIT_LAST );
302  m_cCuCtxLastY.initBuffer               ( eSliceType, iQp, (UChar*)INIT_LAST );
303  m_cCUOneSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG );
304  m_cCUAbsSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG );
305  m_cMVPIdxSCModel.initBuffer            ( eSliceType, iQp, (UChar*)INIT_MVP_IDX );
306  m_cALFFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_ALF_FLAG );
307  m_cALFUvlcSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_ALF_UVLC );
308  m_cALFSvlcSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_ALF_SVLC );
309#if LGE_SAO_MIGRATION_D0091
310  m_cSaoMergeSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG );
311  m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
312#else
313  m_cSaoFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_SAO_FLAG );
314  m_cSaoUvlcSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_SAO_UVLC );
315  m_cSaoSvlcSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_SAO_SVLC );
316  m_cSaoMergeLeftSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_LEFT_FLAG );
317  m_cSaoMergeUpSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_UP_FLAG );
318  m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
319#endif
320  m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
321#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
322#if !PKU_QC_DEPTH_INTRA_UNI_D0195
323  m_cDmmFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_FLAG );
324  m_cDmmModeSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_MODE );
325#endif
326  m_cDmmDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_DATA );
327#endif
328#if RWTH_SDC_DLT_B0036
329#if !PKU_QC_DEPTH_INTRA_UNI_D0195
330  m_cSDCFlagSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG );
331#else
332  m_cDepthModeModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_DEPTHMODE_FLAG );
333  m_cDmmDeltaFlagModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMMDELTA_FLAG );
334#endif
335  m_cSDCResidualFlagSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
336  m_cSDCResidualSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL );
337#if !RWTH_SDC_CTX_SIMPL_D0032
338  m_cSDCResidualSignFlagSCModel.initBuffer  ( eSliceType, iQp, (UChar*)INIT_SDC_SIGN_FLAG );
339#endif
340  m_cSDCPredModeSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_SDC_PRED_MODE );
341#endif
342
343  m_pcTDecBinIf->start();
344}
345
346Void TDecSbac::readTileMarker( UInt& uiTileIdx, UInt uiBitsUsed )
347{
348  UInt uiSymbol;
349  uiTileIdx = 0;
350  for (Int iShift=uiBitsUsed-1; iShift>=0; iShift--)
351  {
352    m_pcTDecBinIf->decodeBinEP ( uiSymbol );
353    if (uiSymbol)
354    {
355      uiTileIdx |= (1<<iShift);
356    }
357  }
358}
359
360Void TDecSbac::parseTerminatingBit( UInt& ruiBit )
361{
362  m_pcTDecBinIf->decodeBinTrm( ruiBit );
363}
364
365
366Void TDecSbac::xReadUnaryMaxSymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol )
367{
368  if (uiMaxSymbol == 0)
369  {
370    ruiSymbol = 0;
371    return;
372  }
373 
374  m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] );
375 
376  if( ruiSymbol == 0 || uiMaxSymbol == 1 )
377  {
378    return;
379  }
380 
381  UInt uiSymbol = 0;
382  UInt uiCont;
383 
384  do
385  {
386    m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] );
387    uiSymbol++;
388  }
389  while( uiCont && ( uiSymbol < uiMaxSymbol - 1 ) );
390 
391  if( uiCont && ( uiSymbol == uiMaxSymbol - 1 ) )
392  {
393    uiSymbol++;
394  }
395 
396  ruiSymbol = uiSymbol;
397}
398
399Void TDecSbac::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount )
400{
401  UInt uiSymbol = 0;
402  UInt uiBit = 1;
403 
404  while( uiBit )
405  {
406    m_pcTDecBinIf->decodeBinEP( uiBit );
407    uiSymbol += uiBit << uiCount++;
408  }
409 
410  if ( --uiCount )
411  {
412    UInt bins;
413    m_pcTDecBinIf->decodeBinsEP( bins, uiCount );
414    uiSymbol += bins;
415  }
416 
417  ruiSymbol = uiSymbol;
418}
419
420Void TDecSbac::xReadUnarySymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset )
421{
422  m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] );
423 
424  if( !ruiSymbol )
425  {
426    return;
427  }
428 
429  UInt uiSymbol = 0;
430  UInt uiCont;
431 
432  do
433  {
434    m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] );
435    uiSymbol++;
436  }
437  while( uiCont );
438 
439  ruiSymbol = uiSymbol;
440}
441
442/** Parsing of coeff_abs_level_minus3
443 * \param ruiSymbol reference to coeff_abs_level_minus3
444 * \param ruiGoRiceParam reference to Rice parameter
445 * \returns Void
446 */
447Void TDecSbac::xReadGoRiceExGolomb( UInt &ruiSymbol, UInt &ruiGoRiceParam )
448{
449  Bool bExGolomb    = false;
450  UInt uiCodeWord   = 0;
451  UInt uiQuotient   = 0;
452  UInt uiRemainder  = 0;
453  UInt uiMaxVlc     = g_auiGoRiceRange[ ruiGoRiceParam ];
454  UInt uiMaxPreLen  = g_auiGoRicePrefixLen[ ruiGoRiceParam ];
455
456  do
457  {
458    uiQuotient++;
459    m_pcTDecBinIf->decodeBinEP( uiCodeWord );
460  }
461  while( uiCodeWord && uiQuotient < uiMaxPreLen );
462
463  uiCodeWord  = 1 - uiCodeWord;
464  uiQuotient -= uiCodeWord;
465
466  if ( ruiGoRiceParam > 0 )
467  {
468    m_pcTDecBinIf->decodeBinsEP( uiRemainder, ruiGoRiceParam );   
469  }
470
471  ruiSymbol      = uiRemainder + ( uiQuotient << ruiGoRiceParam );
472  bExGolomb      = ruiSymbol == ( uiMaxVlc + 1 );
473
474  if( bExGolomb )
475  {
476    xReadEpExGolomb( uiCodeWord, 0 );
477    ruiSymbol += uiCodeWord;
478  }
479
480  ruiGoRiceParam = g_aauiGoRiceUpdate[ ruiGoRiceParam ][ min<UInt>( ruiSymbol, 23 ) ];
481
482  return;
483}
484
485
486/** Parse I_PCM information.
487 * \param pcCU
488 * \param uiAbsPartIdx
489 * \param uiDepth
490 * \returns Void
491 *
492 * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes.
493 */
494Void TDecSbac::parseIPCMInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
495{
496  UInt uiSymbol;
497  Int numSubseqIPCM = 0;
498  Bool readPCMSampleFlag = false;
499
500  if(pcCU->getNumSucIPCM() > 0) 
501  {
502    readPCMSampleFlag = true;
503  }
504  else
505  {
506    m_pcTDecBinIf->decodeBinTrm(uiSymbol);
507
508    if (uiSymbol)
509    {
510      readPCMSampleFlag = true;
511      m_pcTDecBinIf->decodeNumSubseqIPCM(numSubseqIPCM);
512      pcCU->setNumSucIPCM(numSubseqIPCM + 1);
513      m_pcTDecBinIf->decodePCMAlignBits();
514    }
515  }
516
517  if (readPCMSampleFlag == true)
518  {
519    Bool bIpcmFlag = true;
520
521
522    pcCU->setPartSizeSubParts  ( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
523    pcCU->setSizeSubParts      ( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
524    pcCU->setIPCMFlagSubParts  ( bIpcmFlag, uiAbsPartIdx, uiDepth );
525
526    UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
527    UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
528    UInt uiChromaOffset = uiLumaOffset>>2;
529
530    Pel* piPCMSample;
531    UInt uiWidth;
532    UInt uiHeight;
533    UInt uiSampleBits;
534    UInt uiX, uiY;
535
536    piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset;
537    uiWidth = pcCU->getWidth(uiAbsPartIdx);
538    uiHeight = pcCU->getHeight(uiAbsPartIdx);
539    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
540
541    for(uiY = 0; uiY < uiHeight; uiY++)
542    {
543      for(uiX = 0; uiX < uiWidth; uiX++)
544      {
545        UInt uiSample;
546        m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
547        piPCMSample[uiX] = uiSample;
548      }
549      piPCMSample += uiWidth;
550    }
551
552    piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset;
553    uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
554    uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
555    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
556
557    for(uiY = 0; uiY < uiHeight; uiY++)
558    {
559      for(uiX = 0; uiX < uiWidth; uiX++)
560      {
561        UInt uiSample;
562        m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
563        piPCMSample[uiX] = uiSample;
564      }
565      piPCMSample += uiWidth;
566    }
567
568    piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset;
569    uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
570    uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
571    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
572
573    for(uiY = 0; uiY < uiHeight; uiY++)
574    {
575      for(uiX = 0; uiX < uiWidth; uiX++)
576      {
577        UInt uiSample;
578        m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
579        piPCMSample[uiX] = uiSample;
580      }
581      piPCMSample += uiWidth;
582    }
583
584    pcCU->setNumSucIPCM( pcCU->getNumSucIPCM() - 1);
585    if(pcCU->getNumSucIPCM() == 0)
586    {
587      m_pcTDecBinIf->resetBac();
588    }
589  }
590}
591
592/** parse skip flag
593 * \param pcCU
594 * \param uiAbsPartIdx
595 * \param uiDepth
596 * \returns Void
597 */
598Void TDecSbac::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
599{
600  if( pcCU->getSlice()->isIntra() )
601  {
602    return;
603  }
604 
605  UInt uiSymbol = 0;
606  UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx );
607  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) );
608  DTRACE_CABAC_VL( g_nSymbolCounter++ );
609  DTRACE_CABAC_T( "\tSkipFlag" );
610  DTRACE_CABAC_T( "\tuiCtxSkip: ");
611  DTRACE_CABAC_V( uiCtxSkip );
612  DTRACE_CABAC_T( "\tuiSymbol: ");
613  DTRACE_CABAC_V( uiSymbol );
614  DTRACE_CABAC_T( "\n");
615 
616  if( uiSymbol )
617  {
618    pcCU->setPredModeSubParts( MODE_SKIP,  uiAbsPartIdx, uiDepth );
619    pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
620    pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
621    pcCU->setMergeFlagSubParts( true , uiAbsPartIdx, 0, uiDepth );
622  }
623}
624
625#if LGE_ILLUCOMP_B0045
626/** parse illumination compensation flag
627 * \param pcCU
628 * \param uiAbsPartIdx
629 * \param uiDepth
630 * \returns Void
631 */
632Void TDecSbac::parseICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
633{ 
634  UInt uiSymbol = 0;
635  UInt uiCtxIC = pcCU->getCtxICFlag( uiAbsPartIdx );
636  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUICFlagSCModel.get( 0, 0, uiCtxIC ) );
637  DTRACE_CABAC_VL( g_nSymbolCounter++ );
638  DTRACE_CABAC_T( "\tICFlag" );
639  DTRACE_CABAC_T( "\tuiCtxIC: ");
640  DTRACE_CABAC_V( uiCtxIC );
641  DTRACE_CABAC_T( "\tuiSymbol: ");
642  DTRACE_CABAC_V( uiSymbol );
643  DTRACE_CABAC_T( "\n");
644 
645  pcCU->setICFlagSubParts( uiSymbol ? true : false , uiAbsPartIdx, 0, uiDepth );
646}
647#endif
648
649
650/** parse merge flag
651 * \param pcCU
652 * \param uiAbsPartIdx
653 * \param uiDepth
654 * \param uiPUIdx
655 * \returns Void
656 */
657Void TDecSbac::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
658{
659  UInt uiSymbol;
660  m_pcTDecBinIf->decodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) );
661  pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth );
662
663  DTRACE_CABAC_VL( g_nSymbolCounter++ );
664  DTRACE_CABAC_T( "\tMergeFlag: " );
665  DTRACE_CABAC_V( uiSymbol );
666  DTRACE_CABAC_T( "\tAddress: " );
667  DTRACE_CABAC_V( pcCU->getAddr() );
668  DTRACE_CABAC_T( "\tuiAbsPartIdx: " );
669  DTRACE_CABAC_V( uiAbsPartIdx );
670  DTRACE_CABAC_T( "\n" );
671}
672
673Void TDecSbac::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex, UInt uiAbsPartIdx, UInt uiDepth )
674{
675  UInt uiNumCand = MRG_MAX_NUM_CANDS;
676  UInt uiUnaryIdx = 0;
677  uiNumCand = pcCU->getSlice()->getMaxNumMergeCand();
678#if HHI_MPI
679  const Bool bMVIAvailable = pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE;
680  const UInt uiMviMergePos = bMVIAvailable ? HHI_MPI_MERGE_POS : uiNumCand;
681#endif
682  if ( uiNumCand > 1 )
683  {
684    for( ; uiUnaryIdx < uiNumCand - 1; ++uiUnaryIdx )
685    {
686      UInt uiSymbol = 0;
687      if ( uiUnaryIdx==0 )
688      {
689        m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) );
690      }
691      else
692      {
693        m_pcTDecBinIf->decodeBinEP( uiSymbol );
694      }
695      if( uiSymbol == 0 )
696      {
697        break;
698      }
699    }
700  }
701  ruiMergeIndex = uiUnaryIdx;
702
703  DTRACE_CABAC_VL( g_nSymbolCounter++ )
704  DTRACE_CABAC_T( "\tparseMergeIndex()" )
705  DTRACE_CABAC_T( "\tuiMRGIdx= " )
706  DTRACE_CABAC_V( ruiMergeIndex )
707  DTRACE_CABAC_T( "\n" )
708#if HHI_MPI
709  if( ruiMergeIndex > uiMviMergePos )
710  {
711    assert( bMVIAvailable );
712    ruiMergeIndex--;
713  }
714  else if( ruiMergeIndex == uiMviMergePos )
715  {
716    assert( bMVIAvailable );
717    pcCU->setTextureModeDepthSubParts( uiDepth, uiAbsPartIdx, uiDepth );
718  }
719#endif
720}
721
722#if H3D_IVRP
723Void
724TDecSbac::parseResPredFlag( TComDataCU* pcCU, Bool& rbResPredFlag, UInt uiAbsPartIdx, UInt uiDepth )
725{
726  UInt uiCtx    = pcCU->getCtxResPredFlag( uiAbsPartIdx );
727  UInt uiSymbol = 0;
728  m_pcTDecBinIf->decodeBin( uiSymbol, m_cResPredFlagSCModel.get( 0, 0, uiCtx ) );
729  rbResPredFlag = ( uiSymbol != 0 );
730}
731#endif
732
733#if H3D_IVMP
734Void TDecSbac::parseMVPIdx      ( Int& riMVPIdx, Int iNumAMVPCands )
735{
736  UInt uiSymbol;
737  xReadUnaryMaxSymbol(uiSymbol, m_cMVPIdxSCModel.get(0), 1, iNumAMVPCands-1);
738  riMVPIdx = uiSymbol;
739}
740#else
741Void TDecSbac::parseMVPIdx      ( Int& riMVPIdx )
742{
743  UInt uiSymbol;
744  xReadUnaryMaxSymbol(uiSymbol, m_cMVPIdxSCModel.get(0), 1, AMVP_MAX_NUM_CANDS-1);
745  riMVPIdx = uiSymbol;
746}
747#endif
748
749Void TDecSbac::parseSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
750{
751  if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
752  {
753    pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx );
754    return;
755  }
756 
757  UInt uiSymbol;
758
759#if H3D_QTL
760  Bool bParseSplitFlag    = true;
761
762  TComSPS *sps            = pcCU->getPic()->getSlice(0)->getSPS();
763  TComPic *pcTexture      = pcCU->getSlice()->getTexturePic();
764  Bool bDepthMapDetect    = (pcTexture != NULL);
765  Bool bIntraSliceDetect  = (pcCU->getSlice()->getSliceType() == I_SLICE);
766
767  Bool rapPic     = (pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA);
768  if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTLPC())
769  {
770    TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr());
771    assert(pcTextureCU->getDepth(uiAbsPartIdx) >= uiDepth);
772    bParseSplitFlag         = (pcTextureCU->getDepth(uiAbsPartIdx) > uiDepth);
773  }
774
775  if(bParseSplitFlag)
776  {
777#endif
778    m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSplitFlagSCModel.get( 0, 0, pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ) ) );
779    DTRACE_CABAC_VL( g_nSymbolCounter++ )
780    DTRACE_CABAC_T( "\tSplitFlag\n" )
781#if H3D_QTL
782  }
783  else
784    uiSymbol = 0;
785#endif
786
787  pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx );
788 
789  return;
790}
791
792/** parse partition size
793 * \param pcCU
794 * \param uiAbsPartIdx
795 * \param uiDepth
796 * \returns Void
797 */
798Void TDecSbac::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
799{
800  UInt uiSymbol, uiMode = 0;
801  PartSize eMode;
802
803#if H3D_QTL
804  Bool bParsePartSize    = true;
805  TComSPS *sps           = pcCU->getPic()->getSlice(0)->getSPS();
806  TComPic *pcTexture     = pcCU->getSlice()->getTexturePic();
807  Bool bDepthMapDetect   = (pcTexture != NULL);
808  Bool bIntraSliceDetect = (pcCU->getSlice()->getSliceType() == I_SLICE);
809
810  Bool rapPic     = (pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA);
811  if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTLPC())
812  {
813    TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr());
814    assert(pcTextureCU->getDepth(uiAbsPartIdx) >= uiDepth);
815    if (pcTextureCU->getDepth(uiAbsPartIdx) == uiDepth && pcTextureCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN)
816    {
817      bParsePartSize = false;
818      eMode          = SIZE_2Nx2N;
819    }
820  }
821#endif
822 
823  if ( pcCU->isIntra( uiAbsPartIdx ) )
824  {
825#if H3D_QTL
826    if(bParsePartSize)
827    {
828#endif
829      uiSymbol = 1;
830      if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
831      {
832        m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 0) );
833      }
834      eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN;
835#if H3D_QTL
836    }
837#endif
838    UInt uiTrLevel = 0;   
839    UInt uiWidthInBit  = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2;
840    UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2;
841    uiTrLevel          = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0;
842    if( eMode == SIZE_NxN )
843    {
844      pcCU->setTrIdxSubParts( 1+uiTrLevel, uiAbsPartIdx, uiDepth );
845    }
846    else
847    {
848      pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth );
849    }
850  }
851  else
852  {
853#if H3D_QTL
854    if(bParsePartSize)
855    {
856#endif
857      UInt uiMaxNumBits = 2;
858      if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getSlice()->getSPS()->getDisInter4x4() && (g_uiMaxCUWidth>>uiDepth) == 8 && (g_uiMaxCUHeight>>uiDepth) == 8 ) )
859      {
860        uiMaxNumBits ++;
861      }
862      for ( UInt ui = 0; ui < uiMaxNumBits; ui++ )
863      {
864        m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) );
865        if ( uiSymbol )
866        {
867          break;
868        }
869        uiMode++;
870      }
871      eMode = (PartSize) uiMode;
872      if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) )
873      {
874        if (eMode == SIZE_2NxN)
875        {
876            m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUAMPSCModel.get( 0, 0, 0 ));
877          if (uiSymbol == 0)
878          {
879            m_pcTDecBinIf->decodeBinEP(uiSymbol);
880            eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD);
881          }
882        }
883        else if (eMode == SIZE_Nx2N)
884        {
885          m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUAMPSCModel.get( 0, 0, 0 ));
886          if (uiSymbol == 0)
887          {
888            m_pcTDecBinIf->decodeBinEP(uiSymbol);
889            eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N);
890          }
891        }
892      }
893#if H3D_QTL
894    }
895#endif
896  }
897  pcCU->setPartSizeSubParts( eMode, uiAbsPartIdx, uiDepth );
898  pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
899}
900
901/** parse prediction mode
902 * \param pcCU
903 * \param uiAbsPartIdx
904 * \param uiDepth
905 * \returns Void
906 */
907Void TDecSbac::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
908{
909  if( pcCU->getSlice()->isIntra() )
910  {
911    pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth );
912    return;
913  }
914 
915  UInt uiSymbol;
916  Int  iPredMode = MODE_INTER;
917  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPredModeSCModel.get( 0, 0, 0 ) );
918  iPredMode += uiSymbol;
919  pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth );
920}
921 
922  UInt uiSymbol;
923  if (bDmmFlag)
924  {
925    if (bDmmFlag)
926    {
927      m_pcTDecBinIf->decodeBin( uiSymbol , m_cDmmDeltaFlagModel.get(0, 0, 0) );
928      uiDir += uiSymbol;
929    }
930    if (uiSymbol)
931    {
932      UInt uiDC;
933      Int iDC = 0,iDC1 = 0,iDC2 = 0;
934      for ( Int i = 0; i  <2; i++ )
935      {
936        xReadExGolombLevel( uiDC, m_cDmmDataSCModel.get(0, 0, 1) );
937        iDC = uiDC;
938        if ( uiDC )
939        {
940          UInt uiSign;
941          m_pcTDecBinIf->decodeBinEP( uiSign );
942          if ( uiSign )
943          {
944            iDC = -iDC;
945          }
946        }
947        if ( i == 0 ) { iDC1 = iDC; }
948        else          { iDC2 = iDC; }
949      }
950
951      if( uiDir == DMM_WEDGE_FULL_D_IDX )   
952      { 
953        pcCU->setWedgeFullDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
954        pcCU->setWedgeFullDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
955      }
956      else if( uiDir == DMM_WEDGE_PREDDIR_D_IDX ) 
957      { 
958        pcCU->setWedgePredDirDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
959        pcCU->setWedgePredDirDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
960      }
961      else if( uiDir == DMM_WEDGE_PREDTEX_D_IDX) 
962      { 
963        pcCU->setWedgePredTexDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
964        pcCU->setWedgePredTexDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
965      }
966      else if (uiDir== DMM_CONTOUR_PREDTEX_D_IDX )
967      {
968        pcCU->setContourPredTexDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
969        pcCU->setContourPredTexDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
970      }
971    }
972  }
973  else if (uiDir >= EDGE_INTRA_IDX)
974  {
975    m_pcTDecBinIf->decodeBin( uiSymbol, m_cEdgeIntraDeltaDCSCModel.get(0, 0, 0) );
976    if( uiSymbol )
977    {
978      uiDir = EDGE_INTRA_DELTA_IDX;
979      Int iDeltaDC = 0,iDeltaDC0 = 0,iDeltaDC1 = 0;
980      for (Int i = 0; i<2; i++)
981      {
982        xReadExGolombLevel( (UInt &) iDeltaDC, m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) );
983        if( iDeltaDC != 0 )
984        {
985          UInt uiSign;
986          m_pcTDecBinIf->decodeBinEP( uiSign );
987          if ( uiSign )
988          {
989            iDeltaDC = -iDeltaDC;
990          }
991        }
992        if ( i == 0 ) { iDeltaDC0 = iDeltaDC; }
993        else          { iDeltaDC1 = iDeltaDC; }
994      }
995
996      pcCU->setEdgeDeltaDC0( uiAbsPartIdx, iDeltaDC0 );
997      pcCU->setEdgeDeltaDC1( uiAbsPartIdx, iDeltaDC1 );
998    }
999  }
1000  else if(bSdcFlag)//SDC mode
1001  {
1002    assert(pcCU->getPartitionSize(uiAbsPartIdx)!=SIZE_NxN);
1003    pcCU->setTrIdxSubParts(0, uiAbsPartIdx, uiDepth);
1004    pcCU->setCbfSubParts(1, 1, 1, uiAbsPartIdx, uiDepth);
1005
1006    UInt uiNumSegments = ( uiDir == DC_IDX || uiDir == PLANAR_IDX )? 1 : 2;
1007    for (int uiSeg=0; uiSeg<uiNumSegments; uiSeg++)
1008    {
1009      parseSDCResidualData(pcCU, uiAbsPartIdx, uiDepth, uiSeg);
1010    }
1011  }
1012
1013  pcCU->setLumaIntraDirSubParts( (UChar)uiDir, uiAbsPartIdx, uiDepth );
1014}
1015#endif
1016Void TDecSbac::parseIntraDirLumaAng  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1017{
1018  UInt uiSymbol;
1019  Int  intraPredMode;
1020#if PKU_QC_DEPTH_INTRA_UNI_D0195
1021  if (pcCU->getSlice()->getSPS()->isDepth())
1022  {
1023    parseDepthModelingTable(pcCU, uiAbsPartIdx, uiDepth);
1024  }
1025  if (pcCU->getLumaIntraDir(uiAbsPartIdx)<NUM_INTRA_MODE && !pcCU->getSDCFlag(uiAbsPartIdx))
1026  {
1027#else
1028#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
1029  UInt uiFlag = 0;
1030  if( pcCU->getSlice()->getSPS()->getUseDMM() && (g_uiMaxCUWidth>>uiDepth) <= DMM_WEDGEMODEL_MAX_SIZE )
1031  {
1032    m_pcTDecBinIf->decodeBin( uiFlag, m_cDmmFlagSCModel.get(0, 0, 0) );
1033  }
1034  if( uiFlag )
1035  {
1036    UInt uiDMMode;
1037
1038#if HHI_DMM_WEDGE_INTRA && HHI_DMM_PRED_TEX
1039    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmModeSCModel.get(0, 0, 0) ); uiDMMode  = uiSymbol;
1040    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmModeSCModel.get(0, 0, 0) ); uiDMMode |= uiSymbol << 1;
1041    if ( pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN && g_uiMaxCUWidth>>uiDepth > 4 )
1042    {
1043      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmModeSCModel.get(0, 0, 0) ); uiDMMode |= uiSymbol << 2;
1044    }
1045#else
1046    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmModeSCModel.get(0, 0, 0) ); uiDMMode  = uiSymbol;
1047    if ( pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN && g_uiMaxCUWidth>>uiDepth > 4 )
1048    {
1049      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmModeSCModel.get(0, 0, 0) ); uiDMMode |= uiSymbol << 1;
1050    }
1051#endif
1052    intraPredMode = uiDMMode + NUM_INTRA_MODE;
1053
1054#if HHI_DMM_WEDGE_INTRA
1055    if( intraPredMode == DMM_WEDGE_FULL_IDX )          { xParseWedgeFullInfo          ( pcCU, uiAbsPartIdx, uiDepth ); }
1056    if( intraPredMode == DMM_WEDGE_FULL_D_IDX )        { xParseWedgeFullDeltaInfo     ( pcCU, uiAbsPartIdx, uiDepth ); }
1057    if( intraPredMode == DMM_WEDGE_PREDDIR_IDX )       { xParseWedgePredDirInfo       ( pcCU, uiAbsPartIdx, uiDepth ); }
1058    if( intraPredMode == DMM_WEDGE_PREDDIR_D_IDX )     { xParseWedgePredDirDeltaInfo  ( pcCU, uiAbsPartIdx, uiDepth ); }
1059#endif
1060#if HHI_DMM_PRED_TEX
1061    if( intraPredMode == DMM_WEDGE_PREDTEX_D_IDX )     { xParseWedgePredTexDeltaInfo  ( pcCU, uiAbsPartIdx, uiDepth ); }
1062#if LGE_DMM3_SIMP_C0044
1063    if( intraPredMode == DMM_WEDGE_PREDTEX_IDX )       { xParseWedgePredTexInfo       ( pcCU, uiAbsPartIdx, uiDepth ); }
1064#endif
1065    if( intraPredMode == DMM_CONTOUR_PREDTEX_D_IDX )   { xParseContourPredTexDeltaInfo( pcCU, uiAbsPartIdx, uiDepth ); }
1066#endif
1067  }
1068  else
1069  {
1070#endif
1071
1072#if LGE_EDGE_INTRA_A0070
1073    Bool bCodeEdgeIntra = false;
1074    if( pcCU->getSlice()->getSPS()->isDepth() )
1075    {
1076      UInt uiPUWidth = pcCU->getWidth( uiAbsPartIdx ) >> (pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 1 : 0);
1077      if( uiPUWidth <= LGE_EDGE_INTRA_MAX_SIZE && uiPUWidth >= LGE_EDGE_INTRA_MIN_SIZE )
1078        bCodeEdgeIntra = true;
1079    }
1080#endif
1081    Int uiPreds[3] = {-1, -1, -1};
1082    Int uiPredNum = pcCU->getIntraDirLumaPredictor(uiAbsPartIdx, uiPreds); 
1083#if !PKU_QC_DEPTH_INTRA_UNI_D0195
1084#if LGE_EDGE_INTRA_A0070
1085    UInt uiCheckBit = 0;
1086#endif
1087#endif
1088
1089    m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUIntraPredSCModel.get( 0, 0, 0) );
1090
1091    if ( uiSymbol )
1092    {
1093      m_pcTDecBinIf->decodeBinEP( uiSymbol );
1094      if (uiSymbol)
1095      {
1096        m_pcTDecBinIf->decodeBinEP( uiSymbol );
1097        uiSymbol++;
1098      }
1099      intraPredMode = uiPreds[uiSymbol];
1100    }
1101    else
1102    {
1103      intraPredMode = 0;
1104
1105
1106      m_pcTDecBinIf->decodeBinsEP( uiSymbol, 5 );
1107#if !PKU_QC_DEPTH_INTRA_UNI_D0195
1108#if LGE_EDGE_INTRA_A0070
1109      if (bCodeEdgeIntra)
1110      {
1111        if (uiSymbol==31)
1112        {
1113          m_pcTDecBinIf->decodeBinsEP(uiCheckBit,1);
1114          if (uiCheckBit)
1115            uiSymbol = EDGE_INTRA_IDX;
1116        }
1117      }
1118#endif
1119#endif
1120      intraPredMode = uiSymbol;
1121
1122      //postponed sorting of MPMs (only in remaining branch)
1123      if (uiPreds[0] > uiPreds[1])
1124      { 
1125        std::swap(uiPreds[0], uiPreds[1]); 
1126      }
1127      if (uiPreds[0] > uiPreds[2])
1128      {
1129        std::swap(uiPreds[0], uiPreds[2]);
1130      }
1131      if (uiPreds[1] > uiPreds[2])
1132      {
1133        std::swap(uiPreds[1], uiPreds[2]);
1134      }
1135#if !PKU_QC_DEPTH_INTRA_UNI_D0195
1136#if LGE_EDGE_INTRA_A0070
1137      if ( intraPredMode != EDGE_INTRA_IDX)
1138      {
1139#endif
1140#endif
1141        for ( Int i = 0; i < uiPredNum; i++ )
1142        {
1143          intraPredMode += ( intraPredMode >= uiPreds[i] );
1144        }
1145#if !PKU_QC_DEPTH_INTRA_UNI_D0195
1146#if LGE_EDGE_INTRA_A0070
1147      }
1148#endif
1149#endif
1150    }
1151
1152#if !PKU_QC_DEPTH_INTRA_UNI_D0195
1153#if LGE_EDGE_INTRA_A0070
1154    if( intraPredMode == EDGE_INTRA_IDX )
1155    {
1156      xParseEdgeIntraInfo( pcCU, uiAbsPartIdx, uiDepth );
1157#if LGE_EDGE_INTRA_DELTA_DC
1158      m_pcTDecBinIf->decodeBin( uiSymbol, m_cEdgeIntraDeltaDCSCModel.get(0, 0, 0) );
1159      if( uiSymbol )
1160      {
1161        intraPredMode = EDGE_INTRA_DELTA_IDX;
1162        Int iDeltaDC0;
1163        Int iDeltaDC1;
1164
1165        xReadExGolombLevel( (UInt &) iDeltaDC0, m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) );
1166        if( iDeltaDC0 != 0 )
1167        {
1168          UInt uiSign;
1169          m_pcTDecBinIf->decodeBinEP( uiSign );
1170          if ( uiSign )
1171          {
1172            iDeltaDC0 = -iDeltaDC0;
1173          }
1174        }
1175        xReadExGolombLevel( (UInt &) iDeltaDC1, m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) );
1176        if( iDeltaDC1 != 0 )
1177        {
1178          UInt uiSign;
1179          m_pcTDecBinIf->decodeBinEP( uiSign );
1180          if ( uiSign )
1181          {
1182            iDeltaDC1 = -iDeltaDC1;
1183          }
1184        }
1185
1186        pcCU->setEdgeDeltaDC0( uiAbsPartIdx, iDeltaDC0 );
1187        pcCU->setEdgeDeltaDC1( uiAbsPartIdx, iDeltaDC1 );
1188      }
1189#endif
1190    }
1191#endif
1192
1193#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
1194  }
1195#endif
1196  pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, uiAbsPartIdx, uiDepth );
1197#else
1198  pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, uiAbsPartIdx, uiDepth );
1199}
1200#endif
1201}
1202
1203Void TDecSbac::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1204{
1205  UInt uiSymbol;
1206
1207  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) );
1208
1209  if( uiSymbol == 0 )
1210  {
1211    uiSymbol = DM_CHROMA_IDX;
1212  } 
1213  else 
1214  {
1215    if( pcCU->getSlice()->getSPS()->getUseLMChroma() )
1216    {
1217      m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 1 ) );
1218    }
1219    else
1220    {
1221      uiSymbol = 1;
1222    }
1223
1224    if( uiSymbol == 0 )
1225    {
1226      uiSymbol = LM_CHROMA_IDX;
1227    } 
1228    else
1229    {
1230      UInt uiIPredMode;
1231      m_pcTDecBinIf->decodeBinsEP( uiIPredMode, 2 );
1232      UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ];
1233      pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir );
1234      uiSymbol = uiAllowedChromaDir[ uiIPredMode ];
1235    }
1236  }
1237  pcCU->setChromIntraDirSubParts( uiSymbol, uiAbsPartIdx, uiDepth );
1238  return;
1239}
1240
1241Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx, UInt uiDepth )
1242{
1243  UInt uiSymbol;
1244  const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx );
1245  ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 );
1246  m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) );
1247
1248  if( uiSymbol )
1249  {
1250    uiSymbol = 2;
1251  }
1252
1253  uiSymbol++;
1254  ruiInterDir = uiSymbol;
1255  return;
1256}
1257
1258Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList )
1259{
1260  UInt uiSymbol;
1261
1262  if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C ) > 0 && eRefList==REF_PIC_LIST_C)
1263  {
1264    ContextModel *pCtx = m_cCURefPicSCModel.get( 0 );
1265    m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1266
1267    if( uiSymbol )
1268    {
1269      xReadUnaryMaxSymbol( uiSymbol, pCtx + 1, 1, pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C )-2 );
1270      uiSymbol++;
1271    }
1272    riRefFrmIdx = uiSymbol;
1273  }
1274  else
1275  {
1276    ContextModel *pCtx = m_cCURefPicSCModel.get( 0 );
1277    m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1278
1279    if( uiSymbol )
1280    {
1281      xReadUnaryMaxSymbol( uiSymbol, pCtx + 1, 1, pcCU->getSlice()->getNumRefIdx( eRefList )-2 );
1282      uiSymbol++;
1283    }
1284    riRefFrmIdx = uiSymbol;
1285  }
1286
1287  return;
1288}
1289
1290Void TDecSbac::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList )
1291{
1292  UInt uiSymbol;
1293  UInt uiHorAbs;
1294  UInt uiVerAbs;
1295  UInt uiHorSign = 0;
1296  UInt uiVerSign = 0;
1297  ContextModel *pCtx = m_cCUMvdSCModel.get( 0 );
1298
1299  if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3)
1300  {
1301    uiHorAbs=0;
1302    uiVerAbs=0;
1303  }
1304  else
1305  {
1306
1307    m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx );
1308    m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx );
1309
1310    const Bool bHorAbsGr0 = uiHorAbs != 0;
1311    const Bool bVerAbsGr0 = uiVerAbs != 0;
1312    pCtx++;
1313
1314    if( bHorAbsGr0 )
1315    {
1316      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1317      uiHorAbs += uiSymbol;
1318    }
1319
1320    if( bVerAbsGr0 )
1321    {
1322      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1323      uiVerAbs += uiSymbol;
1324    }
1325
1326    if( bHorAbsGr0 )
1327    {
1328      if( 2 == uiHorAbs )
1329      {
1330        xReadEpExGolomb( uiSymbol, 1 );
1331        uiHorAbs += uiSymbol;
1332      }
1333
1334      m_pcTDecBinIf->decodeBinEP( uiHorSign );
1335    }
1336
1337    if( bVerAbsGr0 )
1338    {
1339      if( 2 == uiVerAbs )
1340      {
1341        xReadEpExGolomb( uiSymbol, 1 );
1342        uiVerAbs += uiSymbol;
1343      }
1344
1345      m_pcTDecBinIf->decodeBinEP( uiVerSign );
1346    }
1347
1348  }
1349
1350  const TComMv cMv( uiHorSign ? -Int( uiHorAbs ): uiHorAbs, uiVerSign ? -Int( uiVerAbs ) : uiVerAbs );
1351  pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiDepth, uiPartIdx );
1352  return;
1353}
1354
1355
1356Void TDecSbac::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize )
1357{
1358  m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize ) );
1359  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1360  DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" )
1361  DTRACE_CABAC_T( "\tsymbol=" )
1362  DTRACE_CABAC_V( ruiSubdivFlag )
1363  DTRACE_CABAC_T( "\tctx=" )
1364  DTRACE_CABAC_V( uiLog2TransformBlockSize )
1365  DTRACE_CABAC_T( "\n" )
1366}
1367
1368Void TDecSbac::parseQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& uiQtRootCbf )
1369{
1370  UInt uiSymbol;
1371  const UInt uiCtx = 0;
1372  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) );
1373  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1374  DTRACE_CABAC_T( "\tparseQtRootCbf()" )
1375  DTRACE_CABAC_T( "\tsymbol=" )
1376  DTRACE_CABAC_V( uiSymbol )
1377  DTRACE_CABAC_T( "\tctx=" )
1378  DTRACE_CABAC_V( uiCtx )
1379  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1380  DTRACE_CABAC_V( uiAbsPartIdx )
1381  DTRACE_CABAC_T( "\n" )
1382 
1383  uiQtRootCbf = uiSymbol;
1384}
1385
1386Void TDecSbac::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1387{
1388  Int qp;
1389  UInt uiDQp;
1390  Int  iDQp;
1391 
1392  m_pcTDecBinIf->decodeBin( uiDQp, m_cCUDeltaQpSCModel.get( 0, 0, 0 ) );
1393 
1394  if ( uiDQp == 0 )
1395  {
1396    qp = pcCU->getRefQP(uiAbsPartIdx);
1397  }
1398  else
1399  {
1400    UInt uiSign;
1401    Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
1402    m_pcTDecBinIf->decodeBinEP(uiSign);
1403
1404    UInt uiMaxAbsDQpMinus1 = 24 + (qpBdOffsetY/2) + (uiSign);
1405    UInt uiAbsDQpMinus1;
1406    xReadUnaryMaxSymbol (uiAbsDQpMinus1,  &m_cCUDeltaQpSCModel.get( 0, 0, 1 ), 1, uiMaxAbsDQpMinus1);
1407
1408    iDQp = uiAbsDQpMinus1 + 1;
1409
1410    if(uiSign)
1411    {
1412      iDQp = -iDQp;
1413    }
1414
1415    qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY;
1416  }
1417 
1418  UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>(8-(pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()<<1)))<<(8-(pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()<<1)) ;
1419  UInt uiQpCUDepth =   min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ;
1420  pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth );
1421}
1422
1423Void TDecSbac::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth )
1424{
1425  UInt uiSymbol;
1426  const UInt uiCtx = pcCU->getCtxQtCbf( uiAbsPartIdx, eType, uiTrDepth );
1427  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA: eType, uiCtx ) );
1428 
1429  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1430  DTRACE_CABAC_T( "\tparseQtCbf()" )
1431  DTRACE_CABAC_T( "\tsymbol=" )
1432  DTRACE_CABAC_V( uiSymbol )
1433  DTRACE_CABAC_T( "\tctx=" )
1434  DTRACE_CABAC_V( uiCtx )
1435  DTRACE_CABAC_T( "\tetype=" )
1436  DTRACE_CABAC_V( eType )
1437  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1438  DTRACE_CABAC_V( uiAbsPartIdx )
1439  DTRACE_CABAC_T( "\n" )
1440 
1441  pcCU->setCbfSubParts( uiSymbol << uiTrDepth, eType, uiAbsPartIdx, uiDepth );
1442}
1443
1444/** Parse (X,Y) position of the last significant coefficient
1445 * \param uiPosLastX reference to X component of last coefficient
1446 * \param uiPosLastY reference to Y component of last coefficient
1447 * \param width  Block width
1448 * \param height Block height
1449 * \param eTType plane type / luminance or chrominance
1450 * \param uiScanIdx scan type (zig-zag, hor, ver)
1451 *
1452 * This method decodes the X and Y component within a block of the last significant coefficient.
1453 */
1454Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, TextType eTType, UInt uiScanIdx )
1455{
1456  UInt uiLast;
1457  ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType );
1458  ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType );
1459
1460  // posX
1461  Int widthCtx = eTType ? 4 : width;
1462  const UInt *puiCtxIdxX = g_uiLastCtx + ( g_aucConvertToBit[ widthCtx ] * ( g_aucConvertToBit[ widthCtx ] + 3 ) );
1463  for( uiPosLastX = 0; uiPosLastX < g_uiGroupIdx[ width - 1 ]; uiPosLastX++ )
1464  {
1465    if ( eTType  )
1466    {
1467      m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + (uiPosLastX>>g_aucConvertToBit[ width ])  ) );
1468    }
1469    else
1470    {
1471      m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + puiCtxIdxX[ uiPosLastX ] ) );
1472    }
1473    if( !uiLast )
1474    {
1475      break;
1476    }
1477  }
1478
1479  // posY
1480  Int heightCtx = eTType? 4 : height;
1481  const UInt *puiCtxIdxY = g_uiLastCtx + ( g_aucConvertToBit[ heightCtx ] * ( g_aucConvertToBit[ heightCtx ] + 3 ) );
1482  for( uiPosLastY = 0; uiPosLastY < g_uiGroupIdx[ height - 1 ]; uiPosLastY++ )
1483  {
1484    if (eTType)
1485    {
1486      m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + (uiPosLastY>>g_aucConvertToBit[ height ]) ) );
1487    }
1488    else
1489    {
1490      m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + puiCtxIdxY[ uiPosLastY ] ) );
1491    }
1492    if( !uiLast )
1493    {
1494      break;
1495    }
1496  }
1497  if ( uiPosLastX > 3 )
1498  {
1499    UInt uiTemp  = 0;
1500    UInt uiCount = ( uiPosLastX - 2 ) >> 1;
1501    for ( Int i = uiCount - 1; i >= 0; i-- )
1502    {
1503      m_pcTDecBinIf->decodeBinEP( uiLast );
1504      uiTemp += uiLast << i;
1505    }
1506    uiPosLastX = g_uiMinInGroup[ uiPosLastX ] + uiTemp;
1507  }
1508  if ( uiPosLastY > 3 )
1509  {
1510    UInt uiTemp  = 0;
1511    UInt uiCount = ( uiPosLastY - 2 ) >> 1;
1512    for ( Int i = uiCount - 1; i >= 0; i-- )
1513    {
1514      m_pcTDecBinIf->decodeBinEP( uiLast );
1515      uiTemp += uiLast << i;
1516    }
1517    uiPosLastY = g_uiMinInGroup[ uiPosLastY ] + uiTemp;
1518  }
1519 
1520  if( uiScanIdx == SCAN_VER )
1521  {
1522    swap( uiPosLastX, uiPosLastY );
1523  }
1524}
1525
1526Void TDecSbac::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType )
1527{
1528  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1529  DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" )
1530  DTRACE_CABAC_V( eTType )
1531  DTRACE_CABAC_T( "\twidth=" )
1532  DTRACE_CABAC_V( uiWidth )
1533  DTRACE_CABAC_T( "\theight=" )
1534  DTRACE_CABAC_V( uiHeight )
1535  DTRACE_CABAC_T( "\tdepth=" )
1536  DTRACE_CABAC_V( uiDepth )
1537  DTRACE_CABAC_T( "\tabspartidx=" )
1538  DTRACE_CABAC_V( uiAbsPartIdx )
1539  DTRACE_CABAC_T( "\ttoCU-X=" )
1540  DTRACE_CABAC_V( pcCU->getCUPelX() )
1541  DTRACE_CABAC_T( "\ttoCU-Y=" )
1542  DTRACE_CABAC_V( pcCU->getCUPelY() )
1543  DTRACE_CABAC_T( "\tCU-addr=" )
1544  DTRACE_CABAC_V(  pcCU->getAddr() )
1545  DTRACE_CABAC_T( "\tinCU-X=" )
1546  DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1547  DTRACE_CABAC_T( "\tinCU-Y=" )
1548  DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1549  DTRACE_CABAC_T( "\tpredmode=" )
1550  DTRACE_CABAC_V(  pcCU->getPredictionMode( uiAbsPartIdx ) )
1551  DTRACE_CABAC_T( "\n" )
1552 
1553  if( uiWidth > pcCU->getSlice()->getSPS()->getMaxTrSize() )
1554  {
1555    uiWidth  = pcCU->getSlice()->getSPS()->getMaxTrSize();
1556    uiHeight = pcCU->getSlice()->getSPS()->getMaxTrSize();
1557  }
1558 
1559  eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA );
1560 
1561  //----- parse significance map -----
1562  const UInt  uiLog2BlockSize   = g_aucConvertToBit[ uiWidth ] + 2;
1563  const UInt  uiMaxNumCoeff     = uiWidth * uiHeight;
1564  const UInt  uiMaxNumCoeffM1   = uiMaxNumCoeff - 1;
1565  UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx));
1566  int blockType = uiLog2BlockSize;
1567  if (uiWidth != uiHeight)
1568  {
1569    uiScanIdx = SCAN_DIAG;
1570    blockType = 4;
1571  }
1572 
1573  //===== decode last significant =====
1574  UInt uiPosLastX, uiPosLastY;
1575  parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, eTType, uiScanIdx );
1576  UInt uiBlkPosLast      = uiPosLastX + (uiPosLastY<<uiLog2BlockSize);
1577  pcCoef[ uiBlkPosLast ] = 1;
1578
1579  //===== decode significance flags =====
1580  UInt uiScanPosLast   = uiBlkPosLast;
1581  if (uiScanIdx == SCAN_ZIGZAG)
1582  {
1583    // Map zigzag to diagonal scan
1584    uiScanIdx = SCAN_DIAG;
1585  }
1586  const UInt * scan;
1587  if (uiWidth == uiHeight)
1588  {
1589    scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize-1 ];
1590  }
1591  else
1592  {
1593    scan = g_sigScanNSQT[ uiLog2BlockSize - 2 ];
1594  }
1595  for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ )
1596  {
1597    UInt uiBlkPos = scan[ uiScanPosLast ];
1598    if( uiBlkPosLast == uiBlkPos )
1599    {
1600      break;
1601    }
1602  }
1603
1604  ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType );
1605  ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA;
1606
1607  const Int  iLastScanSet      = uiScanPosLast >> LOG2_SCAN_SET_SIZE;
1608  UInt uiNumOne                = 0;
1609  UInt uiGoRiceParam           = 0;
1610
1611  UInt const tsig = pcCU->getSlice()->getPPS()->getTSIG();
1612#if LOSSLESS_CODING
1613  Bool beValid; 
1614  if (pcCU->isLosslessCoded(uiAbsPartIdx))
1615  {
1616    beValid = false;
1617  }
1618  else 
1619  {
1620    beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0;
1621  }
1622#else
1623  Bool beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0;
1624#endif
1625  UInt absSum = 0;
1626
1627  UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ];
1628  ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM );
1629  const UInt uiNumBlkSide = uiWidth >> (MLS_CG_SIZE >> 1);
1630  const UInt * scanCG;
1631  if (uiWidth == uiHeight)
1632  {
1633    scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0  ];   
1634    if( uiLog2BlockSize == 3 )
1635    {
1636      scanCG = g_sigLastScan8x8[ uiScanIdx ];
1637    }
1638    else if( uiLog2BlockSize == 5 )
1639    {
1640      scanCG = g_sigLastScanCG32x32;
1641    }
1642  }
1643  else
1644  {
1645    scanCG = g_sigCGScanNSQT[ uiLog2BlockSize - 2 ];
1646  }
1647  Int  iScanPosSig             = (Int) uiScanPosLast;
1648  for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- )
1649  {
1650    Int  iSubPos     = iSubSet << LOG2_SCAN_SET_SIZE;
1651    uiGoRiceParam    = 0;
1652    Int numNonZero = 0;
1653   
1654    Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE;
1655
1656    Int pos[SCAN_SET_SIZE];
1657    if( iScanPosSig == (Int) uiScanPosLast )
1658    {
1659      lastNZPosInCG  = iScanPosSig;
1660      firstNZPosInCG = iScanPosSig;
1661      iScanPosSig--;
1662      pos[ numNonZero ] = uiBlkPosLast;
1663      numNonZero = 1;
1664    }
1665
1666      // decode significant_coeffgroup_flag
1667      Int iCGBlkPos = scanCG[ iSubSet ];
1668      Int iCGPosY   = iCGBlkPos / uiNumBlkSide;
1669      Int iCGPosX   = iCGBlkPos - (iCGPosY * uiNumBlkSide);
1670      if( uiWidth == 8 && uiHeight == 8 && (uiScanIdx == SCAN_HOR || uiScanIdx == SCAN_VER) )
1671      {
1672        iCGPosY = (uiScanIdx == SCAN_HOR ? iCGBlkPos : 0);
1673        iCGPosX = (uiScanIdx == SCAN_VER ? iCGBlkPos : 0);
1674      }
1675      if( iSubSet == iLastScanSet || iSubSet == 0)
1676      {
1677        uiSigCoeffGroupFlag[ iCGBlkPos ] = 1;
1678      }
1679      else
1680      {
1681          UInt uiSigCoeffGroup;
1682          UInt uiCtxSig  = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiScanIdx, uiWidth, uiHeight );
1683          m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] );
1684          uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup;
1685      }
1686
1687      // decode significant_coeff_flag
1688      UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig;
1689      for( ; iScanPosSig >= iSubPos; iScanPosSig-- )
1690      {
1691        uiBlkPos  = scan[ iScanPosSig ];
1692        uiPosY    = uiBlkPos >> uiLog2BlockSize;
1693        uiPosX    = uiBlkPos - ( uiPosY << uiLog2BlockSize );
1694        uiSig     = 0;
1695       
1696        if( uiSigCoeffGroupFlag[ iCGBlkPos ] )
1697        {
1698          if( iScanPosSig > iSubPos || iSubSet == 0  || numNonZero )
1699          {
1700            uiCtxSig  = TComTrQuant::getSigCtxInc( pcCoef, uiPosX, uiPosY, blockType, uiWidth, uiHeight, eTType );
1701            m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] );
1702          }
1703          else
1704          {
1705            uiSig = 1;
1706          }
1707        }
1708        pcCoef[ uiBlkPos ] = uiSig;
1709        if( uiSig )
1710        {
1711          pos[ numNonZero ] = uiBlkPos;
1712          numNonZero ++;
1713          if( lastNZPosInCG == -1 )
1714          {
1715            lastNZPosInCG = iScanPosSig;
1716          }
1717          firstNZPosInCG = iScanPosSig;
1718        }
1719      }
1720
1721   
1722    if( numNonZero )
1723    {
1724      Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= (Int)tsig );
1725      absSum = 0;
1726
1727      UInt c1 = 1;
1728      UInt uiCtxSet    = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0;
1729      UInt uiBin;
1730     
1731      if( uiNumOne > 0 )
1732      {
1733        uiCtxSet++;
1734      }
1735     
1736      uiNumOne       >>= 1;
1737      ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet;
1738      Int absCoeff[SCAN_SET_SIZE];
1739
1740      for ( Int i = 0; i < numNonZero; i++) absCoeff[i] = 1;   
1741      Int numC1Flag = min(numNonZero, C1FLAG_NUMBER);
1742      Int firstC2FlagIdx = -1;
1743
1744      for( Int idx = 0; idx < numC1Flag; idx++ )
1745      {
1746        m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] );
1747        if( uiBin == 1 )
1748        {
1749          c1 = 0;
1750          if (firstC2FlagIdx == -1)
1751          {
1752            firstC2FlagIdx = idx;
1753          }
1754        }
1755        else if( (c1 < 3) && (c1 > 0) )
1756        {
1757          c1++;
1758        }
1759        absCoeff[ idx ] = uiBin + 1;
1760      }
1761     
1762      if (c1 == 0)
1763      {
1764        baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet;
1765        if ( firstC2FlagIdx != -1)
1766        {
1767          m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] ); 
1768          absCoeff[ firstC2FlagIdx ] = uiBin + 2;
1769        }
1770      }
1771
1772      UInt coeffSigns;
1773      if ( signHidden && beValid )
1774      {
1775        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 );
1776        coeffSigns <<= 32 - (numNonZero-1);
1777      }
1778      else
1779      {
1780        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero );
1781        coeffSigns <<= 32 - numNonZero;
1782      }
1783     
1784      Int iFirstCoeff2 = 1;   
1785      if (c1 == 0 || numNonZero > C1FLAG_NUMBER)
1786      {
1787        for( Int idx = 0; idx < numNonZero; idx++ )
1788        {
1789          UInt baseLevel  = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2) : 1;
1790
1791          if( absCoeff[ idx ] == baseLevel)
1792          {
1793            UInt uiLevel;
1794            xReadGoRiceExGolomb( uiLevel, uiGoRiceParam );
1795            absCoeff[ idx ] = uiLevel + baseLevel;
1796          }
1797
1798          if(absCoeff[ idx ] >= 2) 
1799          {
1800            iFirstCoeff2 = 0;
1801            uiNumOne++;
1802          }
1803        }
1804      }
1805
1806      for( Int idx = 0; idx < numNonZero; idx++ )
1807      {
1808        Int blkPos = pos[ idx ];
1809        // Signs applied later.
1810        pcCoef[ blkPos ] = absCoeff[ idx ];
1811        absSum += absCoeff[ idx ];
1812
1813        if ( idx == numNonZero-1 && signHidden && beValid )
1814        {
1815          // Infer sign of 1st element.
1816          if (absSum&0x1)
1817            pcCoef[ blkPos ] = -pcCoef[ blkPos ];
1818        }
1819        else
1820        {
1821          Int sign = static_cast<Int>( coeffSigns ) >> 31;
1822          pcCoef[ blkPos ] = ( pcCoef[ blkPos ] ^ sign ) - sign;
1823          coeffSigns <<= 1;
1824        }
1825      }
1826    }
1827    else
1828    {
1829      uiNumOne >>= 1;
1830    }
1831  }
1832 
1833  return;
1834}
1835
1836#if LGE_SAO_MIGRATION_D0091
1837Void TDecSbac::parseSaoMaxUvlc ( UInt& val, UInt maxSymbol )
1838{
1839    if (maxSymbol == 0)
1840    {
1841        val = 0;
1842        return;
1843    }
1844
1845    UInt code;
1846    Int  i;
1847    m_pcTDecBinIf->decodeBinEP( code );
1848    if ( code == 0 )
1849    {
1850        val = 0;
1851        return;
1852    }
1853
1854    i=1;
1855    while (1)
1856    {
1857        m_pcTDecBinIf->decodeBinEP( code );
1858        if ( code == 0 )
1859        {
1860            break;
1861        }
1862        i++;
1863        if (i == maxSymbol)
1864        {
1865            break;
1866        }
1867    }   
1868
1869    val = i;
1870}
1871
1872Void TDecSbac::parseSaoUflc (UInt uiLength, UInt&  riVal)
1873{
1874    m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength );
1875}
1876
1877Void TDecSbac::parseSaoMerge (UInt&  ruiVal)
1878{
1879    UInt uiCode;
1880    m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) );
1881    ruiVal = (Int)uiCode;
1882}
1883
1884Void TDecSbac::parseSaoTypeIdx (UInt&  ruiVal)
1885{
1886    UInt uiCode;
1887    m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
1888    if (uiCode == 0) 
1889    {
1890        ruiVal = 0;
1891    }
1892    else
1893    {
1894        m_pcTDecBinIf->decodeBinEP( uiCode ); 
1895        if (uiCode == 0)
1896        {
1897            ruiVal = 5;
1898        }
1899        else
1900        {
1901            ruiVal = 1;
1902        }
1903    }
1904}
1905
1906inline Void copySaoOneLcuParam(SaoLcuParam* psDst,  SaoLcuParam* psSrc)
1907{
1908    Int i;
1909    psDst->partIdx = psSrc->partIdx;
1910    psDst->typeIdx = psSrc->typeIdx;
1911    if (psDst->typeIdx != -1)
1912    {
1913        psDst->subTypeIdx = psSrc->subTypeIdx ;
1914        psDst->length  = psSrc->length;
1915        for (i=0;i<psDst->length;i++)
1916        {
1917            psDst->offset[i] = psSrc->offset[i];
1918        }
1919    }
1920    else
1921    {
1922        psDst->length  = 0;
1923        for (i=0;i<SAO_BO_LEN;i++)
1924        {
1925            psDst->offset[i] = 0;
1926        }
1927    }
1928}
1929
1930Void TDecSbac::parseSaoOffset(SaoLcuParam* psSaoLcuParam, UInt compIdx)
1931{
1932    UInt uiSymbol;
1933    static Int iTypeLength[MAX_NUM_SAO_TYPE] =
1934    {
1935        SAO_EO_LEN,
1936        SAO_EO_LEN,
1937        SAO_EO_LEN,
1938        SAO_EO_LEN,
1939        SAO_BO_LEN
1940    }; 
1941
1942    if (compIdx==2)
1943    {
1944        uiSymbol = (UInt)( psSaoLcuParam->typeIdx + 1);
1945    }
1946    else
1947    {
1948        parseSaoTypeIdx(uiSymbol);
1949    }
1950    psSaoLcuParam->typeIdx = (Int)uiSymbol - 1;
1951
1952    if (uiSymbol)
1953    {
1954        psSaoLcuParam->length = iTypeLength[psSaoLcuParam->typeIdx];
1955#if FULL_NBIT
1956        Int offsetTh = 1 << ( min((Int)(g_uiBitDepth + (g_uiBitDepth-8)-5),5) );
1957#else
1958        Int offsetTh = 1 << ( min((Int)(g_uiBitDepth + g_uiBitIncrement-5),5) );
1959#endif
1960
1961        if( psSaoLcuParam->typeIdx == SAO_BO )
1962        {
1963            for(Int i=0; i< psSaoLcuParam->length; i++)
1964            {
1965                parseSaoMaxUvlc(uiSymbol, offsetTh -1 );
1966                psSaoLcuParam->offset[i] = uiSymbol;
1967            }   
1968            for(Int i=0; i< psSaoLcuParam->length; i++)
1969            {
1970                if (psSaoLcuParam->offset[i] != 0)
1971                {
1972                    m_pcTDecBinIf->decodeBinEP ( uiSymbol);
1973                    if (uiSymbol)
1974                    {
1975                        psSaoLcuParam->offset[i] = -psSaoLcuParam->offset[i] ;
1976                    }
1977                }
1978            }
1979            parseSaoUflc(5, uiSymbol );
1980            psSaoLcuParam->subTypeIdx = uiSymbol;
1981        }
1982        else if( psSaoLcuParam->typeIdx < 4 )
1983        {
1984            parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[0] = uiSymbol;   
1985            parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[1] = uiSymbol;
1986            parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[2] = -(Int)uiSymbol;
1987            parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[3] = -(Int)uiSymbol;
1988            if (compIdx != 2)
1989            {
1990                parseSaoUflc(2, uiSymbol );
1991                psSaoLcuParam->subTypeIdx = uiSymbol;
1992                psSaoLcuParam->typeIdx += psSaoLcuParam->subTypeIdx;
1993            }
1994        }
1995    }
1996    else
1997    {
1998        psSaoLcuParam->length = 0;
1999    }
2000}
2001
2002Void TDecSbac::parseSaoOneLcuInterleaving(Int rx, Int ry, SAOParam* pSaoParam, TComDataCU* pcCU, Int iCUAddrInSlice, Int iCUAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp)
2003{
2004    Int iAddr = pcCU->getAddr();
2005    UInt uiSymbol;
2006
2007    for (Int iCompIdx=0; iCompIdx<3; iCompIdx++)
2008    {
2009        pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag    = 0;
2010        pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag  = 0;
2011        pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx     = 0;
2012        pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx        =-1;
2013        pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[0]      = 0;
2014        pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[1]      = 0;
2015        pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[2]      = 0;
2016        pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[3]      = 0;
2017    }
2018    if (pSaoParam->bSaoFlag[0] || pSaoParam->bSaoFlag[1] )
2019    {
2020        if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft)
2021        {
2022            parseSaoMerge(uiSymbol); 
2023            pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag = (Bool)uiSymbol; 
2024        }
2025        if (pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag==0)
2026        {
2027            if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp)
2028            {
2029                parseSaoMerge(uiSymbol);
2030                pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag = (Bool)uiSymbol;
2031            }
2032        }
2033    }
2034
2035    for (Int iCompIdx=0; iCompIdx<3; iCompIdx++)
2036    {
2037        if ((iCompIdx == 0  && pSaoParam->bSaoFlag[0]) || (iCompIdx > 0  && pSaoParam->bSaoFlag[1]) )
2038        {
2039            if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft)
2040            {
2041                pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag;
2042            }
2043            else
2044            {
2045                pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = 0;
2046            }
2047
2048            if (pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag==0)
2049            {
2050                if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp)
2051                {
2052                    pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag;
2053                }
2054                else
2055                {
2056                    pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = 0;
2057                }
2058   
2059                if (!pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag)
2060                {
2061                    pSaoParam->saoLcuParam[2][iAddr].typeIdx = pSaoParam->saoLcuParam[1][iAddr].typeIdx;
2062                    parseSaoOffset(&(pSaoParam->saoLcuParam[iCompIdx][iAddr]), iCompIdx);
2063                }
2064                else
2065                {
2066                    copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr], &pSaoParam->saoLcuParam[iCompIdx][iAddr-pSaoParam->numCuInWidth]);
2067                }
2068            }
2069            else
2070            {
2071                copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr],  &pSaoParam->saoLcuParam[iCompIdx][iAddr-1]);
2072            }
2073        }
2074        else
2075        {
2076            pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx    = -1;
2077            pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx = 0;
2078        }
2079    }
2080}
2081#else
2082Void TDecSbac::parseSaoUvlc (UInt& ruiVal)
2083{
2084  UInt uiCode;
2085  Int  i;
2086
2087  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoUvlcSCModel.get( 0, 0, 0 ) );
2088  if ( uiCode == 0 )
2089  {
2090    ruiVal = 0;
2091    return;
2092  }
2093
2094  i=1;
2095  while (1)
2096  {
2097    m_pcTDecBinIf->decodeBin( uiCode, m_cSaoUvlcSCModel.get( 0, 0, 1 ) );
2098    if ( uiCode == 0 ) break;
2099    i++;
2100  }
2101
2102  ruiVal = i;
2103}
2104
2105Void TDecSbac::parseSaoSvlc (Int&  riVal)
2106{
2107  UInt uiCode;
2108  Int  iSign;
2109  Int  i;
2110
2111  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoSvlcSCModel.get( 0, 0, 0 ) );
2112
2113  if ( uiCode == 0 )
2114  {
2115    riVal = 0;
2116    return;
2117  }
2118
2119  // read sign
2120  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoSvlcSCModel.get( 0, 0, 1 ) );
2121
2122  if ( uiCode == 0 )
2123  {
2124    iSign =  1;
2125  }
2126  else
2127  {
2128    iSign = -1;
2129  }
2130
2131  // read magnitude
2132  i=1;
2133  while (1)
2134  {
2135    m_pcTDecBinIf->decodeBin( uiCode, m_cSaoSvlcSCModel.get( 0, 0, 2 ) );
2136    if ( uiCode == 0 ) break;
2137    i++;
2138  }
2139
2140  riVal = i*iSign;
2141}
2142
2143Void TDecSbac::parseSaoUflc (UInt&  riVal)
2144{
2145  UInt uiSymbol;
2146  riVal = 0;
2147  for (Int i=0;i<5;i++)
2148  {
2149    m_pcTDecBinIf->decodeBinEP ( uiSymbol );
2150    if (uiSymbol)
2151    {
2152      riVal |= (1<<i);
2153    }
2154  }
2155}
2156Void TDecSbac::parseSaoMergeLeft (UInt&  ruiVal, UInt uiCompIdx)
2157{
2158  UInt uiCode;
2159  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeLeftSCModel.get( 0, 0, uiCompIdx ) );
2160  ruiVal = (Int)uiCode;
2161}
2162
2163Void TDecSbac::parseSaoMergeUp (UInt&  ruiVal)
2164{
2165  UInt uiCode;
2166  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeUpSCModel.get( 0, 0, 0 ) );
2167  ruiVal = (Int)uiCode;
2168}
2169Void TDecSbac::parseSaoTypeIdx (UInt&  ruiVal)
2170{
2171  UInt uiCode;
2172  Int  i;
2173  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
2174  if ( uiCode == 0 )
2175  {
2176    ruiVal = 0;
2177    return;
2178  }
2179  i=1;
2180  while (1)
2181  {
2182    m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 1 ) );
2183    if ( uiCode == 0 ) break;
2184    i++;
2185  }
2186  ruiVal = i;
2187}
2188
2189inline Void copySaoOneLcuParam(SaoLcuParam* psDst,  SaoLcuParam* psSrc)
2190{
2191  Int i;
2192  psDst->partIdx = psSrc->partIdx;
2193  psDst->typeIdx    = psSrc->typeIdx;
2194  if (psDst->typeIdx != -1)
2195  {
2196    if (psDst->typeIdx == SAO_BO)
2197    {
2198      psDst->bandPosition = psSrc->bandPosition ;
2199    }
2200    else
2201    {
2202      psDst->bandPosition = 0;
2203    }
2204    psDst->length  = psSrc->length;
2205    for (i=0;i<psDst->length;i++)
2206    {
2207      psDst->offset[i] = psSrc->offset[i];
2208    }
2209  }
2210  else
2211  {
2212    psDst->length  = 0;
2213    for (i=0;i<SAO_BO_LEN;i++)
2214    {
2215      psDst->offset[i] = 0;
2216    }
2217  }
2218}
2219Void TDecSbac::parseSaoOffset(SaoLcuParam* psSaoLcuParam)
2220{
2221  UInt uiSymbol;
2222  Int iSymbol;
2223  static Int iTypeLength[MAX_NUM_SAO_TYPE] = {
2224    SAO_EO_LEN,
2225    SAO_EO_LEN,
2226    SAO_EO_LEN,
2227    SAO_EO_LEN,
2228    SAO_BO_LEN
2229  }; 
2230
2231  parseSaoTypeIdx(uiSymbol);
2232  psSaoLcuParam->typeIdx = (Int)uiSymbol - 1;
2233  if (uiSymbol)
2234  {
2235    psSaoLcuParam->length = iTypeLength[psSaoLcuParam->typeIdx];
2236    if( psSaoLcuParam->typeIdx == SAO_BO )
2237    {
2238      // Parse Left Band Index
2239      parseSaoUflc( uiSymbol );
2240      psSaoLcuParam->bandPosition = uiSymbol;
2241      for(Int i=0; i< psSaoLcuParam->length; i++)
2242      {
2243        parseSaoSvlc(iSymbol);
2244        psSaoLcuParam->offset[i] = iSymbol;
2245      }   
2246    }
2247    else if( psSaoLcuParam->typeIdx < 4 )
2248    {
2249      parseSaoUvlc(uiSymbol); psSaoLcuParam->offset[0] = uiSymbol;
2250      parseSaoUvlc(uiSymbol); psSaoLcuParam->offset[1] = uiSymbol;
2251      parseSaoUvlc(uiSymbol); psSaoLcuParam->offset[2] = -(Int)uiSymbol;
2252      parseSaoUvlc(uiSymbol); psSaoLcuParam->offset[3] = -(Int)uiSymbol;
2253    }
2254  }
2255  else
2256  {
2257    psSaoLcuParam->length = 0;
2258  }
2259}
2260
2261Void TDecSbac::parseSaoOneLcuInterleaving(Int rx, Int ry, SAOParam* pSaoParam, TComDataCU* pcCU, Int iCUAddrInSlice, Int iCUAddrUpInSlice, Bool bLFCrossSliceBoundaryFlag)
2262{
2263  Int iAddr = pcCU->getAddr();
2264  UInt uiSymbol;
2265  for (Int iCompIdx=0; iCompIdx<3; iCompIdx++)
2266  {
2267    pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag    = 0;
2268    pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag  = 0;
2269    pSaoParam->saoLcuParam[iCompIdx][iAddr].bandPosition   = 0;
2270    pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx        = -1;
2271    pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[0]     = 0;
2272    pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[1]     = 0;
2273    pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[2]     = 0;
2274    pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[3]     = 0;
2275
2276    if (pSaoParam->bSaoFlag[iCompIdx])
2277    {
2278      if (rx>0 && iCUAddrInSlice!=0)
2279      {
2280        parseSaoMergeLeft(uiSymbol,iCompIdx); pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = (Int)uiSymbol;
2281      }
2282      else
2283      {
2284        pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = 0;
2285      }
2286
2287      if (pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag==0)
2288      {
2289        if ((ry > 0) && (iCUAddrUpInSlice>0||bLFCrossSliceBoundaryFlag))
2290        {
2291          parseSaoMergeUp(uiSymbol);  pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = uiSymbol;
2292        }
2293        else
2294        {
2295          pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = 0;
2296        }
2297        if (!pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag)
2298        {
2299          parseSaoOffset(&(pSaoParam->saoLcuParam[iCompIdx][iAddr]));
2300        }
2301        else
2302        {
2303          copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr], &pSaoParam->saoLcuParam[iCompIdx][iAddr-pSaoParam->numCuInWidth]);
2304        }
2305      }
2306      else
2307      {
2308        copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr],  &pSaoParam->saoLcuParam[iCompIdx][iAddr-1]);
2309      }
2310    }
2311    else
2312    {
2313      pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx = -1;
2314      pSaoParam->saoLcuParam[iCompIdx][iAddr].bandPosition = 0;
2315    }
2316  }
2317}
2318#endif
2319/**
2320 - Initialize our contexts from the nominated source.
2321 .
2322 \param pSrc Contexts to be copied.
2323 */
2324Void TDecSbac::xCopyContextsFrom( TDecSbac* pSrc )
2325{
2326  memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0]));
2327}
2328
2329Void TDecSbac::xCopyFrom( TDecSbac* pSrc )
2330{
2331  m_pcTDecBinIf->copyState( pSrc->m_pcTDecBinIf );
2332
2333  m_uiLastQp           = pSrc->m_uiLastQp;
2334  xCopyContextsFrom( pSrc );
2335
2336}
2337
2338Void TDecSbac::load ( TDecSbac* pScr )
2339{
2340  xCopyFrom(pScr);
2341}
2342
2343Void TDecSbac::loadContexts ( TDecSbac* pScr )
2344{
2345  xCopyContextsFrom(pScr);
2346}
2347
2348Void TDecSbac::decodeFlush ( )
2349{
2350  UInt uiBit;
2351  m_pcTDecBinIf->decodeBinTrm(uiBit);
2352  m_pcTDecBinIf->flush();
2353
2354}
2355
2356#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX || (LGE_EDGE_INTRA_A0070 && LGE_EDGE_INTRA_DELTA_DC)
2357Void TDecSbac::xReadExGolombLevel( UInt& ruiSymbol, ContextModel& rcSCModel  )
2358{
2359  UInt uiSymbol;
2360  UInt uiCount = 0;
2361  do
2362  {
2363    m_pcTDecBinIf->decodeBin( uiSymbol, rcSCModel );
2364    uiCount++;
2365  }
2366  while( uiSymbol && ( uiCount != 13 ) );
2367
2368  ruiSymbol = uiCount - 1;
2369
2370  if( uiSymbol )
2371  {
2372    xReadEpExGolomb( uiSymbol, 0 );
2373    ruiSymbol += uiSymbol + 1;
2374  }
2375
2376  return;
2377}
2378#endif
2379#if HHI_DMM_WEDGE_INTRA
2380Void TDecSbac::xParseWedgeFullInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2381{
2382  Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx);
2383  Int iBits = g_aucWedgeFullBitsListIdx[iIntraIdx];
2384
2385  UInt uiSymbol, uiTabIdx = 0;
2386  for ( Int i = 0; i < iBits; i++ )
2387  {
2388    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmDataSCModel.get(0, 0, 0) );
2389    uiTabIdx += ( uiSymbol && i == 0 ) ? 1 : 0;
2390    uiTabIdx += ( uiSymbol && i == 1 ) ? 2 : 0;
2391    uiTabIdx += ( uiSymbol && i == 2 ) ? 4 : 0;
2392    uiTabIdx += ( uiSymbol && i == 3 ) ? 8 : 0;
2393    uiTabIdx += ( uiSymbol && i == 4 ) ? 16 : 0;
2394    uiTabIdx += ( uiSymbol && i == 5 ) ? 32 : 0;
2395    uiTabIdx += ( uiSymbol && i == 6 ) ? 64 : 0;
2396    uiTabIdx += ( uiSymbol && i == 7 ) ? 128 : 0;
2397    uiTabIdx += ( uiSymbol && i == 8 ) ? 256 : 0;
2398    uiTabIdx += ( uiSymbol && i == 9 ) ? 512 : 0;
2399    uiTabIdx += ( uiSymbol && i == 10 ) ? 1024 : 0;
2400    uiTabIdx += ( uiSymbol && i == 11 ) ? 2048 : 0;
2401    uiTabIdx += ( uiSymbol && i == 12 ) ? 4096 : 0;
2402  }
2403
2404  pcCU->setWedgeFullTabIdxSubParts( uiTabIdx, uiAbsPartIdx, uiDepth );
2405}
2406
2407Void TDecSbac::xParseWedgeFullDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2408{
2409  Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx);
2410  Int iBits = g_aucWedgeFullBitsListIdx[iIntraIdx];
2411
2412  UInt uiSymbol, uiTabIdx = 0;
2413  for ( Int i = 0; i < iBits; i++ )
2414  {
2415    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmDataSCModel.get(0, 0, 0) );
2416    uiTabIdx += ( uiSymbol && i == 0 ) ? 1 : 0;
2417    uiTabIdx += ( uiSymbol && i == 1 ) ? 2 : 0;
2418    uiTabIdx += ( uiSymbol && i == 2 ) ? 4 : 0;
2419    uiTabIdx += ( uiSymbol && i == 3 ) ? 8 : 0;
2420    uiTabIdx += ( uiSymbol && i == 4 ) ? 16 : 0;
2421    uiTabIdx += ( uiSymbol && i == 5 ) ? 32 : 0;
2422    uiTabIdx += ( uiSymbol && i == 6 ) ? 64 : 0;
2423    uiTabIdx += ( uiSymbol && i == 7 ) ? 128 : 0;
2424    uiTabIdx += ( uiSymbol && i == 8 ) ? 256 : 0;
2425    uiTabIdx += ( uiSymbol && i == 9 ) ? 512 : 0;
2426    uiTabIdx += ( uiSymbol && i == 10 ) ? 1024 : 0;
2427    uiTabIdx += ( uiSymbol && i == 11 ) ? 2048 : 0;
2428    uiTabIdx += ( uiSymbol && i == 12 ) ? 4096 : 0;
2429  }
2430
2431  pcCU->setWedgeFullTabIdxSubParts( uiTabIdx, uiAbsPartIdx, uiDepth );
2432
2433  UInt uiDC1, uiDC2;
2434  xReadExGolombLevel( uiDC1, m_cDmmDataSCModel.get(0, 0, 1) );
2435  Int iDC1 = uiDC1;
2436  if ( uiDC1 )
2437  {
2438    UInt uiSign;
2439    m_pcTDecBinIf->decodeBinEP( uiSign );
2440    if ( uiSign )
2441    {
2442      iDC1 = -iDC1;
2443    }
2444  }
2445  xReadExGolombLevel( uiDC2, m_cDmmDataSCModel.get(0, 0, 1) );
2446  Int iDC2 = uiDC2;
2447  if ( uiDC2 )
2448  {
2449    UInt uiSign;
2450    m_pcTDecBinIf->decodeBinEP( uiSign );
2451    if ( uiSign )
2452    {
2453      iDC2 = -iDC2;
2454    }
2455  }
2456
2457  pcCU->setWedgeFullDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
2458  pcCU->setWedgeFullDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
2459}
2460
2461Void TDecSbac::xParseWedgePredDirInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2462{
2463  if( DMM_WEDGE_PREDDIR_DELTAEND_MAX > 0 )
2464  {
2465    UInt uiDeltaEnd = 0;
2466    m_pcTDecBinIf->decodeBin( uiDeltaEnd, m_cDmmDataSCModel.get(0, 0, 2) );
2467
2468    Int iDeltaEnd;
2469    if( uiDeltaEnd != 0 )
2470    {
2471      UInt uiAbsValMinus1;
2472      UInt uiSymbol;
2473      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmDataSCModel.get(0, 0, 2) ); uiAbsValMinus1  = uiSymbol;
2474      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmDataSCModel.get(0, 0, 2) ); uiAbsValMinus1 |= uiSymbol << 1;
2475      uiDeltaEnd = uiAbsValMinus1 + 1;
2476
2477      iDeltaEnd = uiDeltaEnd;
2478      UInt uiSign;
2479      m_pcTDecBinIf->decodeBinEP( uiSign );
2480      if( uiSign )
2481      {
2482        iDeltaEnd = -iDeltaEnd;
2483      }
2484    }
2485    else
2486    {
2487      iDeltaEnd = 0;
2488    }
2489    pcCU->setWedgePredDirDeltaEndSubParts( iDeltaEnd, uiAbsPartIdx, uiDepth );
2490  }
2491}
2492
2493Void TDecSbac::xParseWedgePredDirDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2494{
2495  if( DMM_WEDGE_PREDDIR_DELTAEND_MAX > 0 )
2496  {
2497    UInt uiDeltaEnd = 0;
2498    m_pcTDecBinIf->decodeBin( uiDeltaEnd, m_cDmmDataSCModel.get(0, 0, 2) );
2499
2500    Int iDeltaEnd;
2501    if( uiDeltaEnd != 0 )
2502    {
2503      UInt uiAbsValMinus1;
2504      UInt uiSymbol;
2505      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmDataSCModel.get(0, 0, 2) ); uiAbsValMinus1  = uiSymbol;
2506      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmDataSCModel.get(0, 0, 2) ); uiAbsValMinus1 |= uiSymbol << 1;
2507      uiDeltaEnd = uiAbsValMinus1 + 1;
2508
2509      iDeltaEnd = uiDeltaEnd;
2510      UInt uiSign;
2511      m_pcTDecBinIf->decodeBinEP( uiSign );
2512      if( uiSign )
2513      {
2514        iDeltaEnd = -iDeltaEnd;
2515      }
2516    }
2517    else
2518    {
2519      iDeltaEnd = 0;
2520    }
2521
2522    pcCU->setWedgePredDirDeltaEndSubParts( iDeltaEnd, uiAbsPartIdx, uiDepth );
2523  }
2524
2525  UInt uiDC1, uiDC2;
2526  xReadExGolombLevel( uiDC1, m_cDmmDataSCModel.get(0, 0, 1) );
2527  Int iDC1 = uiDC1;
2528  if ( uiDC1 )
2529  {
2530    UInt uiSign;
2531    m_pcTDecBinIf->decodeBinEP( uiSign );
2532    if ( uiSign )
2533    {
2534      iDC1 = -iDC1;
2535    }
2536  }
2537  xReadExGolombLevel( uiDC2, m_cDmmDataSCModel.get(0, 0, 1) );
2538  Int iDC2 = uiDC2;
2539  if ( uiDC2 )
2540  {
2541    UInt uiSign;
2542    m_pcTDecBinIf->decodeBinEP( uiSign );
2543    if ( uiSign )
2544    {
2545      iDC2 = -iDC2;
2546    }
2547  }
2548
2549  pcCU->setWedgePredDirDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
2550  pcCU->setWedgePredDirDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
2551}
2552#endif
2553#if HHI_DMM_PRED_TEX
2554#if LGE_DMM3_SIMP_C0044
2555Void TDecSbac::xParseWedgePredTexInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2556{
2557  Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx);
2558  Int iBits = g_aucWedgeTexPredBitsListIdx[iIntraIdx];
2559
2560  UInt uiSymbol, uiTabIdx = 0;
2561  for ( Int i = 0; i < iBits; i++ )
2562  {
2563    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmDataSCModel.get(0, 0, 3) );
2564    uiTabIdx += ( uiSymbol && i == 0 ) ? 1 : 0;
2565    uiTabIdx += ( uiSymbol && i == 1 ) ? 2 : 0;
2566    uiTabIdx += ( uiSymbol && i == 2 ) ? 4 : 0;
2567    uiTabIdx += ( uiSymbol && i == 3 ) ? 8 : 0;
2568    uiTabIdx += ( uiSymbol && i == 4 ) ? 16 : 0;
2569    uiTabIdx += ( uiSymbol && i == 5 ) ? 32 : 0;
2570    uiTabIdx += ( uiSymbol && i == 6 ) ? 64 : 0;
2571    uiTabIdx += ( uiSymbol && i == 7 ) ? 128 : 0;
2572    uiTabIdx += ( uiSymbol && i == 8 ) ? 256 : 0;
2573    uiTabIdx += ( uiSymbol && i == 9 ) ? 512 : 0;
2574    uiTabIdx += ( uiSymbol && i == 10 ) ? 1024 : 0;
2575  }
2576
2577  pcCU->setWedgePredTexIntraTabIdxSubParts( uiTabIdx, uiAbsPartIdx, uiDepth );
2578}
2579#endif
2580
2581Void TDecSbac::xParseWedgePredTexDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2582{
2583#if LGE_DMM3_SIMP_C0044
2584  xParseWedgePredTexInfo( pcCU, uiAbsPartIdx, uiDepth );
2585#endif
2586  UInt uiDC1, uiDC2;
2587  xReadExGolombLevel( uiDC1, m_cDmmDataSCModel.get(0, 0, 1) );
2588  Int iDC1 = uiDC1;
2589  if ( uiDC1 )
2590  {
2591    UInt uiSign;
2592    m_pcTDecBinIf->decodeBinEP( uiSign );
2593    if ( uiSign )
2594    {
2595      iDC1 = -iDC1;
2596    }
2597  }
2598  xReadExGolombLevel( uiDC2, m_cDmmDataSCModel.get(0, 0, 1) );
2599  Int iDC2 = uiDC2;
2600  if ( uiDC2 )
2601  {
2602    UInt uiSign;
2603    m_pcTDecBinIf->decodeBinEP( uiSign );
2604    if ( uiSign )
2605    {
2606      iDC2 = -iDC2;
2607    }
2608  }
2609
2610  pcCU->setWedgePredTexDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
2611  pcCU->setWedgePredTexDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
2612}
2613
2614Void TDecSbac::xParseContourPredTexDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2615{
2616  UInt uiDC1, uiDC2;
2617  xReadExGolombLevel( uiDC1, m_cDmmDataSCModel.get(0, 0, 1) );
2618  Int iDC1 = uiDC1;
2619  if ( uiDC1 )
2620  {
2621    UInt uiSign;
2622    m_pcTDecBinIf->decodeBinEP( uiSign );
2623    if ( uiSign )
2624    {
2625      iDC1 = -iDC1;
2626    }
2627  }
2628  xReadExGolombLevel( uiDC2, m_cDmmDataSCModel.get(0, 0, 1) );
2629  Int iDC2 = uiDC2;
2630  if ( uiDC2 )
2631  {
2632    UInt uiSign;
2633    m_pcTDecBinIf->decodeBinEP( uiSign );
2634    if ( uiSign )
2635    {
2636      iDC2 = -iDC2;
2637    }
2638  }
2639
2640  pcCU->setContourPredTexDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
2641  pcCU->setContourPredTexDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
2642}
2643#endif
2644#if QC_ARP_D0177
2645Void TDecSbac::parseARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2646{
2647  UInt nMaxW = pcCU->getSlice()->getARPStepNum() - 1;
2648#if !QC_ARP_WARNING_FIX
2649  assert (nMaxW >= 0);
2650#endif
2651  UInt nW = 0;
2652  if( nMaxW > 0 )
2653  {
2654    UInt nOffset = pcCU->getCTXARPWFlag(uiAbsPartIdx);
2655#if !QC_ARP_WARNING_FIX
2656    assert( 0 <= nOffset && nOffset <= 2 );
2657#endif
2658    UInt uiCode = 0;
2659    m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPW.get( 0, 0, 0 + nOffset ) );
2660    nW = uiCode;
2661    if( nW == 1 )   
2662    {
2663      m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPW.get( 0, 0, 3 ) );
2664      nW += ( uiCode == 1 );
2665    }
2666  }
2667  pcCU->setARPWSubParts( ( UChar )( nW ) , uiAbsPartIdx, uiDepth ); 
2668}
2669#endif
2670#if LGE_EDGE_INTRA_A0070
2671Void TDecSbac::xParseEdgeIntraInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2672{
2673  UInt uiSymbol = 0;
2674
2675  // 1. Top(0) or Left(1)
2676  UChar ucLeft;
2677  m_pcTDecBinIf->decodeBinEP( uiSymbol );
2678  ucLeft = uiSymbol;
2679
2680  // 2. Start position (lowest bit first)
2681  UChar ucStart = 0;
2682  for( UInt ui = 0; ui < 6 - uiDepth; ui++ )
2683  {
2684    m_pcTDecBinIf->decodeBinEP( uiSymbol );
2685    ucStart |= (uiSymbol << ui);
2686  }
2687
2688  // 3. Number of edges
2689  UChar ucMax = 0;
2690  for( UInt ui = 0; ui < 7 - uiDepth; ui++ )
2691  {
2692    m_pcTDecBinIf->decodeBinEP( uiSymbol );
2693    ucMax |= (uiSymbol << ui);
2694  }
2695  ucMax++; // +1
2696
2697  // 4. Edges
2698  UChar* pucSymbolList = (UChar*) xMalloc( UChar, 256 * LGE_EDGE_INTRA_MAX_EDGE_NUM_PER_4x4 );
2699  UInt uiCtxEdgeIntra = pcCU->getCtxEdgeIntra( uiAbsPartIdx );
2700  for( Int iPtr = 0; iPtr < ucMax; iPtr++ )
2701  {
2702    UChar ucEdge = 0;
2703    UInt  uiReorderEdge = 0;
2704    // Left-friendly direction
2705    // 0 (   0deg) => 0
2706    // 1 (  45deg) => 10
2707    // 2 ( -45deg) => 110
2708    // 3 (  90deg) => 1110
2709    // 4 ( -90deg) => 11110
2710    // 5 ( 135deg) => 111110
2711    // 6 (-135deg) => 111111
2712    // Right-friendly direction
2713    // 0 (   0deg) => 0
2714    // 1 ( -45deg) => 10
2715    // 2 (  45deg) => 110
2716    // 3 ( -90deg) => 1110
2717    // 4 (  90deg) => 11110
2718    // 5 (-135deg) => 111110
2719    // 6 ( 135deg) => 111111
2720    // refer to a paper "An efficient chain code with Huffman coding"
2721    for( UInt ui = 0; ui < 6; ui++ )
2722    {
2723      m_pcTDecBinIf->decodeBin( uiSymbol, m_cEdgeIntraSCModel.get( 0, 0, uiCtxEdgeIntra ) );
2724      ucEdge <<= 1;
2725      ucEdge |= uiSymbol;
2726      if( uiSymbol == 0 )
2727        break;
2728    }
2729
2730    switch( ucEdge )
2731    {
2732    case 0 :  // "0"
2733      uiReorderEdge = 0;
2734      break;
2735    case 2 :  // "10"
2736      uiReorderEdge = 1;
2737      break;
2738    case 6 :  // "110"
2739      uiReorderEdge = 2;
2740      break;
2741    case 14 : // "1110"
2742      uiReorderEdge = 3;
2743      break;
2744    case 30 : // "11110"
2745      uiReorderEdge = 4;
2746      break;
2747    case 62 : // "111110"
2748      uiReorderEdge = 5;
2749      break;
2750    case 63 : // "111111"
2751      uiReorderEdge = 6;
2752      break;
2753    default :
2754      printf("parseIntraEdgeChain: error (unknown code %d)\n",ucEdge);
2755      assert(false);
2756      break;
2757    }
2758    pucSymbolList[iPtr] = uiReorderEdge;
2759  }
2760  /////////////////////
2761  // Edge Reconstruction
2762  Bool* pbRegion = pcCU->getEdgePartition( uiAbsPartIdx );
2763  pcCU->reconPartition( uiAbsPartIdx, uiDepth, ucLeft == 1, ucStart, ucMax, pucSymbolList, pbRegion );
2764  xFree( pucSymbolList );
2765}
2766#endif
2767 
2768#if RWTH_SDC_DLT_B0036
2769#if !PKU_QC_DEPTH_INTRA_UNI_D0195
2770Void TDecSbac::parseSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2771{
2772  assert( pcCU->getSlice()->getSPS()->isDepth() );
2773 
2774  UInt uiSymbol = 0;
2775  UInt uiCtxSDCFlag = pcCU->getCtxSDCFlag( uiAbsPartIdx );
2776  m_pcTDecBinIf->decodeBin( uiSymbol, m_cSDCFlagSCModel.get( 0, 0, uiCtxSDCFlag ) );
2777 
2778  if( uiSymbol == 1 )
2779  {
2780    pcCU->setPartSizeSubParts(SIZE_2Nx2N, uiAbsPartIdx, uiDepth);
2781   
2782    pcCU->setSDCFlagSubParts( true, uiAbsPartIdx, 0, uiDepth);
2783    pcCU->setTrIdxSubParts(0, uiAbsPartIdx, uiDepth);
2784    pcCU->setCbfSubParts(1, 1, 1, uiAbsPartIdx, uiDepth);
2785  }
2786}
2787
2788Void TDecSbac::parseSDCPredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2789{
2790  assert( pcCU->getSlice()->getSPS()->isDepth() );
2791  assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
2792 
2793  assert( pcCU->getSDCFlag(uiAbsPartIdx) );
2794 
2795  UInt uiCtx            = 0;
2796 
2797  UInt uiMPModeIdx      = 0;
2798 
2799  for(Int i=0; i<RWTH_SDC_NUM_PRED_MODES-1; i++)
2800  {
2801    UInt uiIsMostProb = 0;
2802#if INTEL_SDC64_D0193
2803    if( !(pcCU->getWidth(uiAbsPartIdx) == 64 && i == 1))
2804#endif
2805    m_pcTDecBinIf->decodeBin( uiIsMostProb, m_cSDCPredModeSCModel.get( 0, i, uiCtx ) );
2806   
2807    if ( uiIsMostProb == 1 )
2808      break;
2809   
2810    // else: get next most probable pred mode
2811    uiMPModeIdx = (uiMPModeIdx+1)%RWTH_SDC_NUM_PRED_MODES;
2812  }
2813 
2814  Int intraPredMode = g_auiSDCPredModes[uiMPModeIdx];
2815 
2816#if HHI_DMM_WEDGE_INTRA
2817  if( intraPredMode == DMM_WEDGE_FULL_IDX )          { xParseWedgeFullInfo          ( pcCU, uiAbsPartIdx, uiDepth ); }
2818  if( intraPredMode == DMM_WEDGE_PREDDIR_IDX )       { xParseWedgePredDirInfo       ( pcCU, uiAbsPartIdx, uiDepth ); }
2819#endif
2820 
2821  pcCU->setLumaIntraDirSubParts((UChar)intraPredMode, uiAbsPartIdx, uiDepth);
2822}
2823#endif
2824
2825Void TDecSbac::parseSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSegment )
2826{
2827  assert( pcCU->getSlice()->getSPS()->isDepth() );
2828  assert( pcCU->getSDCFlag(uiAbsPartIdx) );
2829  assert( uiSegment < 2 );
2830 
2831  UInt uiResidual = 0;
2832  UInt uiBit      = 0;
2833  UInt uiAbsIdx   = 0;
2834  UInt uiSign     = 0;
2835  Int  iIdx       = 0;
2836 
2837  UInt uiMaxResidualBits  = pcCU->getSlice()->getSPS()->getBitsPerDepthValue();
2838  assert( uiMaxResidualBits <= g_uiBitDepth );
2839 
2840#if RWTH_SDC_CTX_SIMPL_D0032
2841  m_pcTDecBinIf->decodeBin(uiResidual, m_cSDCResidualFlagSCModel.get( 0, 0, 0 ) );
2842#else
2843  m_pcTDecBinIf->decodeBin(uiResidual, m_cSDCResidualFlagSCModel.get( 0, uiSegment, 0 ) );
2844#endif
2845 
2846  if (uiResidual)
2847  {
2848    // decode residual sign bit
2849#if RWTH_SDC_CTX_SIMPL_D0032
2850    m_pcTDecBinIf->decodeBinEP(uiSign);
2851#else
2852    m_pcTDecBinIf->decodeBin(uiSign, m_cSDCResidualSignFlagSCModel.get( 0, uiSegment, 0 ) );
2853#endif
2854   
2855    // decode residual magnitude
2856#if LGE_CONCATENATE_D0141
2857    //prefix part
2858    UInt uiCount = 0;
2859    UInt uiNumDepthValues = pcCU->getSlice()->getSPS()->getNumDepthValues();
2860    UInt uiPrefixThreshold = ((uiNumDepthValues * 3) >> 2);
2861    for ( UInt ui = 0; ui < uiPrefixThreshold; ui++)
2862    {
2863        m_pcTDecBinIf->decodeBin( uiBit, m_cSDCResidualSCModel.get(0, 0, 0) );
2864        if ( uiBit == 0 )
2865            break;
2866        else
2867            uiCount++;
2868    }
2869    //suffix part
2870    if ( uiCount == uiPrefixThreshold )
2871    {
2872        for ( UInt ui = 0; ui < ( (UInt)ceil( Log2(uiNumDepthValues - uiPrefixThreshold) ) ); ui++ )
2873        {
2874            m_pcTDecBinIf->decodeBinEP( uiBit );
2875            uiAbsIdx |= uiBit << ui;
2876        }
2877        uiAbsIdx += uiCount;
2878    }
2879    else
2880        uiAbsIdx = uiCount;
2881#else
2882    for (Int i=0; i<uiMaxResidualBits; i++)
2883    {
2884#if RWTH_SDC_CTX_SIMPL_D0032
2885      m_pcTDecBinIf->decodeBin(uiBit, m_cSDCResidualSCModel.get( 0, 0, i ) );
2886#else
2887      m_pcTDecBinIf->decodeBin(uiBit, m_cSDCResidualSCModel.get( 0, uiSegment, i ) );
2888#endif
2889      uiAbsIdx |= uiBit << i;
2890    }
2891#endif
2892   
2893    uiAbsIdx += 1;
2894    iIdx =(Int)(uiSign ? -1 : 1)*uiAbsIdx;
2895  }
2896 
2897  pcCU->setSDCSegmentDCOffset(iIdx, uiSegment, uiAbsPartIdx);
2898}
2899#endif
2900
2901//! \}
Note: See TracBrowser for help on using the repository browser.