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

Last change on this file since 443 was 443, checked in by tech, 11 years ago
  • Reintegrated branch 6.2-dev0 rev. 442.
  • Changed version number.
  • Added coding results.
  • Property svn:eol-style set to native
File size: 95.1 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#if PKU_QC_DEPTH_INTRA_UNI_D0195
922Void TDecSbac::parseDepthIntraMode  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
923{
924  UInt uiPuIdx = ( pcCU->getWidth(uiAbsPartIdx) == 64 )? 2 : ( ( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && pcCU->getWidth(uiAbsPartIdx) == 8 )? 0 : 1);
925  UInt uiDir = 0;
926  Bool bSDCFlag = 0;
927  UInt uiSymbol = 1;
928  UInt uiCode = 0 ;
929  UInt uiBinNum = 0;
930  UInt uiCtxDepthMode = 0;
931  if ( uiPuIdx ==2 )
932  {
933    while(uiBinNum<2 && uiSymbol)
934    {
935      uiCtxDepthMode = uiPuIdx*3 + uiBinNum;
936      m_pcTDecBinIf->decodeBin(uiSymbol,m_cDepthModeModel.get(0,0,uiCtxDepthMode));
937      uiCode = (uiCode<<1)+uiSymbol;
938      uiBinNum++;
939    }
940    if (uiCode == 0)      { uiDir = PLANAR_IDX; bSDCFlag = 1;}
941    else if (uiCode == 2) { uiDir = 0;          bSDCFlag = 0;}
942    else if (uiCode == 3) { uiDir = DC_IDX;     bSDCFlag = 1;}
943  }
944  else if ( uiPuIdx ==0 )
945  {
946    while(uiBinNum<3 && uiSymbol)
947    {
948      uiCtxDepthMode = uiPuIdx*3 + ( uiBinNum >= 2? 2 : uiBinNum );
949      m_pcTDecBinIf->decodeBin(uiSymbol,m_cDepthModeModel.get(0,0,uiCtxDepthMode));
950      uiCode = (uiCode<<1)+uiSymbol;
951      uiBinNum++;
952    }
953    if (uiCode == 0)      { uiDir = 0;                     bSDCFlag = 0;}
954    else if (uiCode == 2) { uiDir = DMM_WEDGE_FULL_IDX;    bSDCFlag = 0;}
955    else if (uiCode == 6) { uiDir = DMM_WEDGE_PREDTEX_IDX; bSDCFlag = 0;}
956    else if (uiCode == 7) { uiDir = EDGE_INTRA_IDX;        bSDCFlag = 0;}
957  }
958  else
959  {
960    uiCtxDepthMode = uiPuIdx*3 ;
961    m_pcTDecBinIf->decodeBin(uiSymbol,m_cDepthModeModel.get(0,0,uiCtxDepthMode));
962    uiCode = (uiCode<<1)+uiSymbol;
963    if (!uiSymbol)
964    {
965      uiCtxDepthMode = uiPuIdx*3 + 1;
966      m_pcTDecBinIf->decodeBin(uiSymbol,m_cDepthModeModel.get(0,0,uiCtxDepthMode));
967      uiCode = (uiCode<<1)+uiSymbol;
968      if (uiSymbol) 
969      { 
970        uiCtxDepthMode = uiPuIdx*3 + 2;
971        m_pcTDecBinIf->decodeBin(uiSymbol,m_cDepthModeModel.get(0,0,uiCtxDepthMode));
972        uiCode = (uiCode<<1)+uiSymbol;
973      }
974    }
975    else
976    {
977      uiCtxDepthMode = uiPuIdx*3 + 1;
978      m_pcTDecBinIf->decodeBin(uiSymbol,m_cDepthModeModel.get(0,0,uiCtxDepthMode));
979      uiCode = (uiCode<<1)+uiSymbol;
980      if (!uiSymbol) 
981      { 
982        uiCtxDepthMode = uiPuIdx*3 + 2;
983        m_pcTDecBinIf->decodeBin(uiSymbol,m_cDepthModeModel.get(0,0,uiCtxDepthMode));
984        uiCode = (uiCode<<1)+uiSymbol;
985      }
986      else
987      {
988        uiBinNum = 0;
989        while( uiSymbol && uiBinNum<3 )
990        {
991          uiCtxDepthMode = uiPuIdx*3 + 2;
992          m_pcTDecBinIf->decodeBin(uiSymbol,m_cDepthModeModel.get(0,0,uiCtxDepthMode));
993          uiCode = (uiCode<<1)+uiSymbol;
994          uiBinNum++;
995        }
996      }
997    }
998    if (uiCode == 0)       { uiDir = PLANAR_IDX;              bSDCFlag = 1;}
999    else if (uiCode == 2)  { uiDir = 5;                       bSDCFlag = 0;}
1000    else if (uiCode == 3)  { uiDir = DMM_WEDGE_FULL_IDX;      bSDCFlag = 1;}
1001    else if (uiCode == 4)  { uiDir = DMM_WEDGE_FULL_IDX;      bSDCFlag = 0;}
1002    else if (uiCode == 5)  { uiDir = DMM_CONTOUR_PREDTEX_IDX; bSDCFlag = 0;}
1003    else if (uiCode == 6)  { uiDir = DMM_WEDGE_PREDTEX_IDX;   bSDCFlag = 0;}
1004    else if (uiCode == 14) { uiDir = DC_IDX;                  bSDCFlag = 1;}
1005    else if (uiCode == 31) { uiDir = DMM_WEDGE_PREDDIR_IDX;   bSDCFlag = 0;}
1006    else if (uiCode == 30) { uiDir = EDGE_INTRA_IDX;          bSDCFlag = 0;}
1007  }
1008  pcCU->setLumaIntraDirSubParts( (UChar)uiDir, uiAbsPartIdx, uiDepth );
1009  pcCU->setSDCFlagSubParts(bSDCFlag, uiAbsPartIdx, 0, uiDepth); 
1010}
1011Void TDecSbac::parseDepthModelingTable  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1012{
1013  parseDepthIntraMode(pcCU,uiAbsPartIdx,uiDepth);
1014 
1015  UInt uiDir = pcCU->getLumaIntraDir(uiAbsPartIdx);
1016  Bool bSdcFlag =  pcCU->getSDCAvailable(uiAbsPartIdx) && pcCU->getSDCFlag(uiAbsPartIdx);
1017  Bool bDmmFlag = (uiDir >= NUM_INTRA_MODE && uiDir < EDGE_INTRA_IDX &&(!bSdcFlag))? 1:0;
1018  if (uiDir >= NUM_INTRA_MODE && uiDir < EDGE_INTRA_IDX)//DMM modes and SDC DMM1
1019  {
1020    if( uiDir == DMM_WEDGE_FULL_IDX )          { xParseWedgeFullInfo          ( pcCU, uiAbsPartIdx, uiDepth ); }
1021    else if( uiDir == DMM_WEDGE_PREDTEX_IDX )  { xParseWedgePredTexInfo       ( pcCU, uiAbsPartIdx, uiDepth ); }
1022    else if( uiDir == DMM_WEDGE_PREDDIR_IDX )  { xParseWedgePredDirInfo       ( pcCU, uiAbsPartIdx, uiDepth ); }
1023  } 
1024  else if(uiDir >= EDGE_INTRA_IDX)//CCM mode
1025  {
1026    xParseEdgeIntraInfo( pcCU, uiAbsPartIdx, uiDepth );
1027  }
1028 
1029  UInt uiSymbol;
1030  if (bDmmFlag)
1031  {
1032    if (bDmmFlag)
1033    {
1034      m_pcTDecBinIf->decodeBin( uiSymbol , m_cDmmDeltaFlagModel.get(0, 0, 0) );
1035      uiDir += uiSymbol;
1036    }
1037    if (uiSymbol)
1038    {
1039      UInt uiDC;
1040      Int iDC = 0,iDC1 = 0,iDC2 = 0;
1041      for ( Int i = 0; i  <2; i++ )
1042      {
1043        xReadExGolombLevel( uiDC, m_cDmmDataSCModel.get(0, 0, 1) );
1044        iDC = uiDC;
1045        if ( uiDC )
1046        {
1047          UInt uiSign;
1048          m_pcTDecBinIf->decodeBinEP( uiSign );
1049          if ( uiSign )
1050          {
1051            iDC = -iDC;
1052          }
1053        }
1054        if ( i == 0 ) { iDC1 = iDC; }
1055        else          { iDC2 = iDC; }
1056      }
1057
1058      if( uiDir == DMM_WEDGE_FULL_D_IDX )   
1059      { 
1060        pcCU->setWedgeFullDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
1061        pcCU->setWedgeFullDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
1062      }
1063      else if( uiDir == DMM_WEDGE_PREDDIR_D_IDX ) 
1064      { 
1065        pcCU->setWedgePredDirDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
1066        pcCU->setWedgePredDirDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
1067      }
1068      else if( uiDir == DMM_WEDGE_PREDTEX_D_IDX) 
1069      { 
1070        pcCU->setWedgePredTexDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
1071        pcCU->setWedgePredTexDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
1072      }
1073      else if (uiDir== DMM_CONTOUR_PREDTEX_D_IDX )
1074      {
1075        pcCU->setContourPredTexDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
1076        pcCU->setContourPredTexDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
1077      }
1078    }
1079  }
1080  else if (uiDir >= EDGE_INTRA_IDX)
1081  {
1082    m_pcTDecBinIf->decodeBin( uiSymbol, m_cEdgeIntraDeltaDCSCModel.get(0, 0, 0) );
1083    if( uiSymbol )
1084    {
1085      uiDir = EDGE_INTRA_DELTA_IDX;
1086      Int iDeltaDC = 0,iDeltaDC0 = 0,iDeltaDC1 = 0;
1087      for (Int i = 0; i<2; i++)
1088      {
1089        xReadExGolombLevel( (UInt &) iDeltaDC, m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) );
1090        if( iDeltaDC != 0 )
1091        {
1092          UInt uiSign;
1093          m_pcTDecBinIf->decodeBinEP( uiSign );
1094          if ( uiSign )
1095          {
1096            iDeltaDC = -iDeltaDC;
1097          }
1098        }
1099        if ( i == 0 ) { iDeltaDC0 = iDeltaDC; }
1100        else          { iDeltaDC1 = iDeltaDC; }
1101      }
1102
1103      pcCU->setEdgeDeltaDC0( uiAbsPartIdx, iDeltaDC0 );
1104      pcCU->setEdgeDeltaDC1( uiAbsPartIdx, iDeltaDC1 );
1105    }
1106  }
1107  else if(bSdcFlag)//SDC mode
1108  {
1109    assert(pcCU->getPartitionSize(uiAbsPartIdx)!=SIZE_NxN);
1110    pcCU->setTrIdxSubParts(0, uiAbsPartIdx, uiDepth);
1111    pcCU->setCbfSubParts(1, 1, 1, uiAbsPartIdx, uiDepth);
1112
1113    UInt uiNumSegments = ( uiDir == DC_IDX || uiDir == PLANAR_IDX )? 1 : 2;
1114    for (int uiSeg=0; uiSeg<uiNumSegments; uiSeg++)
1115    {
1116      parseSDCResidualData(pcCU, uiAbsPartIdx, uiDepth, uiSeg);
1117    }
1118  }
1119
1120  pcCU->setLumaIntraDirSubParts( (UChar)uiDir, uiAbsPartIdx, uiDepth );
1121}
1122#endif
1123Void TDecSbac::parseIntraDirLumaAng  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1124{
1125  UInt uiSymbol;
1126  Int  intraPredMode;
1127#if PKU_QC_DEPTH_INTRA_UNI_D0195
1128  if (pcCU->getSlice()->getSPS()->isDepth())
1129  {
1130    parseDepthModelingTable(pcCU, uiAbsPartIdx, uiDepth);
1131  }
1132  if (pcCU->getLumaIntraDir(uiAbsPartIdx)<NUM_INTRA_MODE && !pcCU->getSDCFlag(uiAbsPartIdx))
1133  {
1134#else
1135#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
1136  UInt uiFlag = 0;
1137  if( pcCU->getSlice()->getSPS()->getUseDMM() && (g_uiMaxCUWidth>>uiDepth) <= DMM_WEDGEMODEL_MAX_SIZE )
1138  {
1139    m_pcTDecBinIf->decodeBin( uiFlag, m_cDmmFlagSCModel.get(0, 0, 0) );
1140  }
1141  if( uiFlag )
1142  {
1143    UInt uiDMMode;
1144
1145#if HHI_DMM_WEDGE_INTRA && HHI_DMM_PRED_TEX
1146    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmModeSCModel.get(0, 0, 0) ); uiDMMode  = uiSymbol;
1147    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmModeSCModel.get(0, 0, 0) ); uiDMMode |= uiSymbol << 1;
1148    if ( pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN && g_uiMaxCUWidth>>uiDepth > 4 )
1149    {
1150      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmModeSCModel.get(0, 0, 0) ); uiDMMode |= uiSymbol << 2;
1151    }
1152#else
1153    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmModeSCModel.get(0, 0, 0) ); uiDMMode  = uiSymbol;
1154    if ( pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN && g_uiMaxCUWidth>>uiDepth > 4 )
1155    {
1156      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmModeSCModel.get(0, 0, 0) ); uiDMMode |= uiSymbol << 1;
1157    }
1158#endif
1159    intraPredMode = uiDMMode + NUM_INTRA_MODE;
1160
1161#if HHI_DMM_WEDGE_INTRA
1162    if( intraPredMode == DMM_WEDGE_FULL_IDX )          { xParseWedgeFullInfo          ( pcCU, uiAbsPartIdx, uiDepth ); }
1163    if( intraPredMode == DMM_WEDGE_FULL_D_IDX )        { xParseWedgeFullDeltaInfo     ( pcCU, uiAbsPartIdx, uiDepth ); }
1164    if( intraPredMode == DMM_WEDGE_PREDDIR_IDX )       { xParseWedgePredDirInfo       ( pcCU, uiAbsPartIdx, uiDepth ); }
1165    if( intraPredMode == DMM_WEDGE_PREDDIR_D_IDX )     { xParseWedgePredDirDeltaInfo  ( pcCU, uiAbsPartIdx, uiDepth ); }
1166#endif
1167#if HHI_DMM_PRED_TEX
1168    if( intraPredMode == DMM_WEDGE_PREDTEX_D_IDX )     { xParseWedgePredTexDeltaInfo  ( pcCU, uiAbsPartIdx, uiDepth ); }
1169#if LGE_DMM3_SIMP_C0044
1170    if( intraPredMode == DMM_WEDGE_PREDTEX_IDX )       { xParseWedgePredTexInfo       ( pcCU, uiAbsPartIdx, uiDepth ); }
1171#endif
1172    if( intraPredMode == DMM_CONTOUR_PREDTEX_D_IDX )   { xParseContourPredTexDeltaInfo( pcCU, uiAbsPartIdx, uiDepth ); }
1173#endif
1174  }
1175  else
1176  {
1177#endif
1178
1179#if LGE_EDGE_INTRA_A0070
1180    Bool bCodeEdgeIntra = false;
1181    if( pcCU->getSlice()->getSPS()->isDepth() )
1182    {
1183      UInt uiPUWidth = pcCU->getWidth( uiAbsPartIdx ) >> (pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 1 : 0);
1184      if( uiPUWidth <= LGE_EDGE_INTRA_MAX_SIZE && uiPUWidth >= LGE_EDGE_INTRA_MIN_SIZE )
1185        bCodeEdgeIntra = true;
1186    }
1187#endif
1188#endif
1189    Int uiPreds[3] = {-1, -1, -1};
1190    Int uiPredNum = pcCU->getIntraDirLumaPredictor(uiAbsPartIdx, uiPreds); 
1191#if !PKU_QC_DEPTH_INTRA_UNI_D0195
1192#if LGE_EDGE_INTRA_A0070
1193    UInt uiCheckBit = 0;
1194#endif
1195#endif
1196
1197    m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUIntraPredSCModel.get( 0, 0, 0) );
1198
1199    if ( uiSymbol )
1200    {
1201      m_pcTDecBinIf->decodeBinEP( uiSymbol );
1202      if (uiSymbol)
1203      {
1204        m_pcTDecBinIf->decodeBinEP( uiSymbol );
1205        uiSymbol++;
1206      }
1207      intraPredMode = uiPreds[uiSymbol];
1208    }
1209    else
1210    {
1211      intraPredMode = 0;
1212
1213
1214      m_pcTDecBinIf->decodeBinsEP( uiSymbol, 5 );
1215#if !PKU_QC_DEPTH_INTRA_UNI_D0195
1216#if LGE_EDGE_INTRA_A0070
1217      if (bCodeEdgeIntra)
1218      {
1219        if (uiSymbol==31)
1220        {
1221          m_pcTDecBinIf->decodeBinsEP(uiCheckBit,1);
1222          if (uiCheckBit)
1223            uiSymbol = EDGE_INTRA_IDX;
1224        }
1225      }
1226#endif
1227#endif
1228      intraPredMode = uiSymbol;
1229
1230      //postponed sorting of MPMs (only in remaining branch)
1231      if (uiPreds[0] > uiPreds[1])
1232      { 
1233        std::swap(uiPreds[0], uiPreds[1]); 
1234      }
1235      if (uiPreds[0] > uiPreds[2])
1236      {
1237        std::swap(uiPreds[0], uiPreds[2]);
1238      }
1239      if (uiPreds[1] > uiPreds[2])
1240      {
1241        std::swap(uiPreds[1], uiPreds[2]);
1242      }
1243#if !PKU_QC_DEPTH_INTRA_UNI_D0195
1244#if LGE_EDGE_INTRA_A0070
1245      if ( intraPredMode != EDGE_INTRA_IDX)
1246      {
1247#endif
1248#endif
1249        for ( Int i = 0; i < uiPredNum; i++ )
1250        {
1251          intraPredMode += ( intraPredMode >= uiPreds[i] );
1252        }
1253#if !PKU_QC_DEPTH_INTRA_UNI_D0195
1254#if LGE_EDGE_INTRA_A0070
1255      }
1256#endif
1257#endif
1258    }
1259
1260#if !PKU_QC_DEPTH_INTRA_UNI_D0195
1261#if LGE_EDGE_INTRA_A0070
1262    if( intraPredMode == EDGE_INTRA_IDX )
1263    {
1264      xParseEdgeIntraInfo( pcCU, uiAbsPartIdx, uiDepth );
1265#if LGE_EDGE_INTRA_DELTA_DC
1266      m_pcTDecBinIf->decodeBin( uiSymbol, m_cEdgeIntraDeltaDCSCModel.get(0, 0, 0) );
1267      if( uiSymbol )
1268      {
1269        intraPredMode = EDGE_INTRA_DELTA_IDX;
1270        Int iDeltaDC0;
1271        Int iDeltaDC1;
1272
1273        xReadExGolombLevel( (UInt &) iDeltaDC0, m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) );
1274        if( iDeltaDC0 != 0 )
1275        {
1276          UInt uiSign;
1277          m_pcTDecBinIf->decodeBinEP( uiSign );
1278          if ( uiSign )
1279          {
1280            iDeltaDC0 = -iDeltaDC0;
1281          }
1282        }
1283        xReadExGolombLevel( (UInt &) iDeltaDC1, m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) );
1284        if( iDeltaDC1 != 0 )
1285        {
1286          UInt uiSign;
1287          m_pcTDecBinIf->decodeBinEP( uiSign );
1288          if ( uiSign )
1289          {
1290            iDeltaDC1 = -iDeltaDC1;
1291          }
1292        }
1293
1294        pcCU->setEdgeDeltaDC0( uiAbsPartIdx, iDeltaDC0 );
1295        pcCU->setEdgeDeltaDC1( uiAbsPartIdx, iDeltaDC1 );
1296      }
1297#endif
1298    }
1299#endif
1300
1301#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
1302  }
1303#endif
1304  pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, uiAbsPartIdx, uiDepth );
1305#else
1306  pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, uiAbsPartIdx, uiDepth );
1307}
1308#endif
1309}
1310
1311Void TDecSbac::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1312{
1313  UInt uiSymbol;
1314
1315  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) );
1316
1317  if( uiSymbol == 0 )
1318  {
1319    uiSymbol = DM_CHROMA_IDX;
1320  } 
1321  else 
1322  {
1323    if( pcCU->getSlice()->getSPS()->getUseLMChroma() )
1324    {
1325      m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 1 ) );
1326    }
1327    else
1328    {
1329      uiSymbol = 1;
1330    }
1331
1332    if( uiSymbol == 0 )
1333    {
1334      uiSymbol = LM_CHROMA_IDX;
1335    } 
1336    else
1337    {
1338      UInt uiIPredMode;
1339      m_pcTDecBinIf->decodeBinsEP( uiIPredMode, 2 );
1340      UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ];
1341      pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir );
1342      uiSymbol = uiAllowedChromaDir[ uiIPredMode ];
1343    }
1344  }
1345  pcCU->setChromIntraDirSubParts( uiSymbol, uiAbsPartIdx, uiDepth );
1346  return;
1347}
1348
1349Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx, UInt uiDepth )
1350{
1351  UInt uiSymbol;
1352  const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx );
1353  ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 );
1354  m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) );
1355
1356  if( uiSymbol )
1357  {
1358    uiSymbol = 2;
1359  }
1360
1361  uiSymbol++;
1362  ruiInterDir = uiSymbol;
1363  return;
1364}
1365
1366Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList )
1367{
1368  UInt uiSymbol;
1369
1370  if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C ) > 0 && eRefList==REF_PIC_LIST_C)
1371  {
1372    ContextModel *pCtx = m_cCURefPicSCModel.get( 0 );
1373    m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1374
1375    if( uiSymbol )
1376    {
1377      xReadUnaryMaxSymbol( uiSymbol, pCtx + 1, 1, pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C )-2 );
1378      uiSymbol++;
1379    }
1380    riRefFrmIdx = uiSymbol;
1381  }
1382  else
1383  {
1384    ContextModel *pCtx = m_cCURefPicSCModel.get( 0 );
1385    m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1386
1387    if( uiSymbol )
1388    {
1389      xReadUnaryMaxSymbol( uiSymbol, pCtx + 1, 1, pcCU->getSlice()->getNumRefIdx( eRefList )-2 );
1390      uiSymbol++;
1391    }
1392    riRefFrmIdx = uiSymbol;
1393  }
1394
1395  return;
1396}
1397
1398Void TDecSbac::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList )
1399{
1400  UInt uiSymbol;
1401  UInt uiHorAbs;
1402  UInt uiVerAbs;
1403  UInt uiHorSign = 0;
1404  UInt uiVerSign = 0;
1405  ContextModel *pCtx = m_cCUMvdSCModel.get( 0 );
1406
1407  if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3)
1408  {
1409    uiHorAbs=0;
1410    uiVerAbs=0;
1411  }
1412  else
1413  {
1414
1415    m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx );
1416    m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx );
1417
1418    const Bool bHorAbsGr0 = uiHorAbs != 0;
1419    const Bool bVerAbsGr0 = uiVerAbs != 0;
1420    pCtx++;
1421
1422    if( bHorAbsGr0 )
1423    {
1424      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1425      uiHorAbs += uiSymbol;
1426    }
1427
1428    if( bVerAbsGr0 )
1429    {
1430      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1431      uiVerAbs += uiSymbol;
1432    }
1433
1434    if( bHorAbsGr0 )
1435    {
1436      if( 2 == uiHorAbs )
1437      {
1438        xReadEpExGolomb( uiSymbol, 1 );
1439        uiHorAbs += uiSymbol;
1440      }
1441
1442      m_pcTDecBinIf->decodeBinEP( uiHorSign );
1443    }
1444
1445    if( bVerAbsGr0 )
1446    {
1447      if( 2 == uiVerAbs )
1448      {
1449        xReadEpExGolomb( uiSymbol, 1 );
1450        uiVerAbs += uiSymbol;
1451      }
1452
1453      m_pcTDecBinIf->decodeBinEP( uiVerSign );
1454    }
1455
1456  }
1457
1458  const TComMv cMv( uiHorSign ? -Int( uiHorAbs ): uiHorAbs, uiVerSign ? -Int( uiVerAbs ) : uiVerAbs );
1459  pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiDepth, uiPartIdx );
1460  return;
1461}
1462
1463
1464Void TDecSbac::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize )
1465{
1466  m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize ) );
1467  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1468  DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" )
1469  DTRACE_CABAC_T( "\tsymbol=" )
1470  DTRACE_CABAC_V( ruiSubdivFlag )
1471  DTRACE_CABAC_T( "\tctx=" )
1472  DTRACE_CABAC_V( uiLog2TransformBlockSize )
1473  DTRACE_CABAC_T( "\n" )
1474}
1475
1476Void TDecSbac::parseQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& uiQtRootCbf )
1477{
1478  UInt uiSymbol;
1479  const UInt uiCtx = 0;
1480  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) );
1481  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1482  DTRACE_CABAC_T( "\tparseQtRootCbf()" )
1483  DTRACE_CABAC_T( "\tsymbol=" )
1484  DTRACE_CABAC_V( uiSymbol )
1485  DTRACE_CABAC_T( "\tctx=" )
1486  DTRACE_CABAC_V( uiCtx )
1487  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1488  DTRACE_CABAC_V( uiAbsPartIdx )
1489  DTRACE_CABAC_T( "\n" )
1490 
1491  uiQtRootCbf = uiSymbol;
1492}
1493
1494Void TDecSbac::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1495{
1496  Int qp;
1497  UInt uiDQp;
1498  Int  iDQp;
1499 
1500  m_pcTDecBinIf->decodeBin( uiDQp, m_cCUDeltaQpSCModel.get( 0, 0, 0 ) );
1501 
1502  if ( uiDQp == 0 )
1503  {
1504    qp = pcCU->getRefQP(uiAbsPartIdx);
1505  }
1506  else
1507  {
1508    UInt uiSign;
1509    Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
1510    m_pcTDecBinIf->decodeBinEP(uiSign);
1511
1512    UInt uiMaxAbsDQpMinus1 = 24 + (qpBdOffsetY/2) + (uiSign);
1513    UInt uiAbsDQpMinus1;
1514    xReadUnaryMaxSymbol (uiAbsDQpMinus1,  &m_cCUDeltaQpSCModel.get( 0, 0, 1 ), 1, uiMaxAbsDQpMinus1);
1515
1516    iDQp = uiAbsDQpMinus1 + 1;
1517
1518    if(uiSign)
1519    {
1520      iDQp = -iDQp;
1521    }
1522
1523    qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY;
1524  }
1525 
1526  UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>(8-(pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()<<1)))<<(8-(pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()<<1)) ;
1527  UInt uiQpCUDepth =   min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ;
1528  pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth );
1529}
1530
1531Void TDecSbac::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth )
1532{
1533  UInt uiSymbol;
1534  const UInt uiCtx = pcCU->getCtxQtCbf( uiAbsPartIdx, eType, uiTrDepth );
1535  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA: eType, uiCtx ) );
1536 
1537  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1538  DTRACE_CABAC_T( "\tparseQtCbf()" )
1539  DTRACE_CABAC_T( "\tsymbol=" )
1540  DTRACE_CABAC_V( uiSymbol )
1541  DTRACE_CABAC_T( "\tctx=" )
1542  DTRACE_CABAC_V( uiCtx )
1543  DTRACE_CABAC_T( "\tetype=" )
1544  DTRACE_CABAC_V( eType )
1545  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1546  DTRACE_CABAC_V( uiAbsPartIdx )
1547  DTRACE_CABAC_T( "\n" )
1548 
1549  pcCU->setCbfSubParts( uiSymbol << uiTrDepth, eType, uiAbsPartIdx, uiDepth );
1550}
1551
1552/** Parse (X,Y) position of the last significant coefficient
1553 * \param uiPosLastX reference to X component of last coefficient
1554 * \param uiPosLastY reference to Y component of last coefficient
1555 * \param width  Block width
1556 * \param height Block height
1557 * \param eTType plane type / luminance or chrominance
1558 * \param uiScanIdx scan type (zig-zag, hor, ver)
1559 *
1560 * This method decodes the X and Y component within a block of the last significant coefficient.
1561 */
1562Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, TextType eTType, UInt uiScanIdx )
1563{
1564  UInt uiLast;
1565  ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType );
1566  ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType );
1567
1568  // posX
1569  Int widthCtx = eTType ? 4 : width;
1570  const UInt *puiCtxIdxX = g_uiLastCtx + ( g_aucConvertToBit[ widthCtx ] * ( g_aucConvertToBit[ widthCtx ] + 3 ) );
1571  for( uiPosLastX = 0; uiPosLastX < g_uiGroupIdx[ width - 1 ]; uiPosLastX++ )
1572  {
1573    if ( eTType  )
1574    {
1575      m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + (uiPosLastX>>g_aucConvertToBit[ width ])  ) );
1576    }
1577    else
1578    {
1579      m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + puiCtxIdxX[ uiPosLastX ] ) );
1580    }
1581    if( !uiLast )
1582    {
1583      break;
1584    }
1585  }
1586
1587  // posY
1588  Int heightCtx = eTType? 4 : height;
1589  const UInt *puiCtxIdxY = g_uiLastCtx + ( g_aucConvertToBit[ heightCtx ] * ( g_aucConvertToBit[ heightCtx ] + 3 ) );
1590  for( uiPosLastY = 0; uiPosLastY < g_uiGroupIdx[ height - 1 ]; uiPosLastY++ )
1591  {
1592    if (eTType)
1593    {
1594      m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + (uiPosLastY>>g_aucConvertToBit[ height ]) ) );
1595    }
1596    else
1597    {
1598      m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + puiCtxIdxY[ uiPosLastY ] ) );
1599    }
1600    if( !uiLast )
1601    {
1602      break;
1603    }
1604  }
1605  if ( uiPosLastX > 3 )
1606  {
1607    UInt uiTemp  = 0;
1608    UInt uiCount = ( uiPosLastX - 2 ) >> 1;
1609    for ( Int i = uiCount - 1; i >= 0; i-- )
1610    {
1611      m_pcTDecBinIf->decodeBinEP( uiLast );
1612      uiTemp += uiLast << i;
1613    }
1614    uiPosLastX = g_uiMinInGroup[ uiPosLastX ] + uiTemp;
1615  }
1616  if ( uiPosLastY > 3 )
1617  {
1618    UInt uiTemp  = 0;
1619    UInt uiCount = ( uiPosLastY - 2 ) >> 1;
1620    for ( Int i = uiCount - 1; i >= 0; i-- )
1621    {
1622      m_pcTDecBinIf->decodeBinEP( uiLast );
1623      uiTemp += uiLast << i;
1624    }
1625    uiPosLastY = g_uiMinInGroup[ uiPosLastY ] + uiTemp;
1626  }
1627 
1628  if( uiScanIdx == SCAN_VER )
1629  {
1630    swap( uiPosLastX, uiPosLastY );
1631  }
1632}
1633
1634Void TDecSbac::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType )
1635{
1636  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1637  DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" )
1638  DTRACE_CABAC_V( eTType )
1639  DTRACE_CABAC_T( "\twidth=" )
1640  DTRACE_CABAC_V( uiWidth )
1641  DTRACE_CABAC_T( "\theight=" )
1642  DTRACE_CABAC_V( uiHeight )
1643  DTRACE_CABAC_T( "\tdepth=" )
1644  DTRACE_CABAC_V( uiDepth )
1645  DTRACE_CABAC_T( "\tabspartidx=" )
1646  DTRACE_CABAC_V( uiAbsPartIdx )
1647  DTRACE_CABAC_T( "\ttoCU-X=" )
1648  DTRACE_CABAC_V( pcCU->getCUPelX() )
1649  DTRACE_CABAC_T( "\ttoCU-Y=" )
1650  DTRACE_CABAC_V( pcCU->getCUPelY() )
1651  DTRACE_CABAC_T( "\tCU-addr=" )
1652  DTRACE_CABAC_V(  pcCU->getAddr() )
1653  DTRACE_CABAC_T( "\tinCU-X=" )
1654  DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1655  DTRACE_CABAC_T( "\tinCU-Y=" )
1656  DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1657  DTRACE_CABAC_T( "\tpredmode=" )
1658  DTRACE_CABAC_V(  pcCU->getPredictionMode( uiAbsPartIdx ) )
1659  DTRACE_CABAC_T( "\n" )
1660 
1661  if( uiWidth > pcCU->getSlice()->getSPS()->getMaxTrSize() )
1662  {
1663    uiWidth  = pcCU->getSlice()->getSPS()->getMaxTrSize();
1664    uiHeight = pcCU->getSlice()->getSPS()->getMaxTrSize();
1665  }
1666 
1667  eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA );
1668 
1669  //----- parse significance map -----
1670  const UInt  uiLog2BlockSize   = g_aucConvertToBit[ uiWidth ] + 2;
1671  const UInt  uiMaxNumCoeff     = uiWidth * uiHeight;
1672  const UInt  uiMaxNumCoeffM1   = uiMaxNumCoeff - 1;
1673  UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx));
1674  int blockType = uiLog2BlockSize;
1675  if (uiWidth != uiHeight)
1676  {
1677    uiScanIdx = SCAN_DIAG;
1678    blockType = 4;
1679  }
1680 
1681  //===== decode last significant =====
1682  UInt uiPosLastX, uiPosLastY;
1683  parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, eTType, uiScanIdx );
1684  UInt uiBlkPosLast      = uiPosLastX + (uiPosLastY<<uiLog2BlockSize);
1685  pcCoef[ uiBlkPosLast ] = 1;
1686
1687  //===== decode significance flags =====
1688  UInt uiScanPosLast   = uiBlkPosLast;
1689  if (uiScanIdx == SCAN_ZIGZAG)
1690  {
1691    // Map zigzag to diagonal scan
1692    uiScanIdx = SCAN_DIAG;
1693  }
1694  const UInt * scan;
1695  if (uiWidth == uiHeight)
1696  {
1697    scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize-1 ];
1698  }
1699  else
1700  {
1701    scan = g_sigScanNSQT[ uiLog2BlockSize - 2 ];
1702  }
1703  for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ )
1704  {
1705    UInt uiBlkPos = scan[ uiScanPosLast ];
1706    if( uiBlkPosLast == uiBlkPos )
1707    {
1708      break;
1709    }
1710  }
1711
1712  ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType );
1713  ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA;
1714
1715  const Int  iLastScanSet      = uiScanPosLast >> LOG2_SCAN_SET_SIZE;
1716  UInt uiNumOne                = 0;
1717  UInt uiGoRiceParam           = 0;
1718
1719  UInt const tsig = pcCU->getSlice()->getPPS()->getTSIG();
1720#if LOSSLESS_CODING
1721  Bool beValid; 
1722  if (pcCU->isLosslessCoded(uiAbsPartIdx))
1723  {
1724    beValid = false;
1725  }
1726  else 
1727  {
1728    beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0;
1729  }
1730#else
1731  Bool beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0;
1732#endif
1733  UInt absSum = 0;
1734
1735  UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ];
1736  ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM );
1737  const UInt uiNumBlkSide = uiWidth >> (MLS_CG_SIZE >> 1);
1738  const UInt * scanCG;
1739  if (uiWidth == uiHeight)
1740  {
1741    scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0  ];   
1742    if( uiLog2BlockSize == 3 )
1743    {
1744      scanCG = g_sigLastScan8x8[ uiScanIdx ];
1745    }
1746    else if( uiLog2BlockSize == 5 )
1747    {
1748      scanCG = g_sigLastScanCG32x32;
1749    }
1750  }
1751  else
1752  {
1753    scanCG = g_sigCGScanNSQT[ uiLog2BlockSize - 2 ];
1754  }
1755  Int  iScanPosSig             = (Int) uiScanPosLast;
1756  for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- )
1757  {
1758    Int  iSubPos     = iSubSet << LOG2_SCAN_SET_SIZE;
1759    uiGoRiceParam    = 0;
1760    Int numNonZero = 0;
1761   
1762    Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE;
1763
1764    Int pos[SCAN_SET_SIZE];
1765    if( iScanPosSig == (Int) uiScanPosLast )
1766    {
1767      lastNZPosInCG  = iScanPosSig;
1768      firstNZPosInCG = iScanPosSig;
1769      iScanPosSig--;
1770      pos[ numNonZero ] = uiBlkPosLast;
1771      numNonZero = 1;
1772    }
1773
1774      // decode significant_coeffgroup_flag
1775      Int iCGBlkPos = scanCG[ iSubSet ];
1776      Int iCGPosY   = iCGBlkPos / uiNumBlkSide;
1777      Int iCGPosX   = iCGBlkPos - (iCGPosY * uiNumBlkSide);
1778      if( uiWidth == 8 && uiHeight == 8 && (uiScanIdx == SCAN_HOR || uiScanIdx == SCAN_VER) )
1779      {
1780        iCGPosY = (uiScanIdx == SCAN_HOR ? iCGBlkPos : 0);
1781        iCGPosX = (uiScanIdx == SCAN_VER ? iCGBlkPos : 0);
1782      }
1783      if( iSubSet == iLastScanSet || iSubSet == 0)
1784      {
1785        uiSigCoeffGroupFlag[ iCGBlkPos ] = 1;
1786      }
1787      else
1788      {
1789          UInt uiSigCoeffGroup;
1790          UInt uiCtxSig  = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiScanIdx, uiWidth, uiHeight );
1791          m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] );
1792          uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup;
1793      }
1794
1795      // decode significant_coeff_flag
1796      UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig;
1797      for( ; iScanPosSig >= iSubPos; iScanPosSig-- )
1798      {
1799        uiBlkPos  = scan[ iScanPosSig ];
1800        uiPosY    = uiBlkPos >> uiLog2BlockSize;
1801        uiPosX    = uiBlkPos - ( uiPosY << uiLog2BlockSize );
1802        uiSig     = 0;
1803       
1804        if( uiSigCoeffGroupFlag[ iCGBlkPos ] )
1805        {
1806          if( iScanPosSig > iSubPos || iSubSet == 0  || numNonZero )
1807          {
1808            uiCtxSig  = TComTrQuant::getSigCtxInc( pcCoef, uiPosX, uiPosY, blockType, uiWidth, uiHeight, eTType );
1809            m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] );
1810          }
1811          else
1812          {
1813            uiSig = 1;
1814          }
1815        }
1816        pcCoef[ uiBlkPos ] = uiSig;
1817        if( uiSig )
1818        {
1819          pos[ numNonZero ] = uiBlkPos;
1820          numNonZero ++;
1821          if( lastNZPosInCG == -1 )
1822          {
1823            lastNZPosInCG = iScanPosSig;
1824          }
1825          firstNZPosInCG = iScanPosSig;
1826        }
1827      }
1828
1829   
1830    if( numNonZero )
1831    {
1832      Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= (Int)tsig );
1833      absSum = 0;
1834
1835      UInt c1 = 1;
1836      UInt uiCtxSet    = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0;
1837      UInt uiBin;
1838     
1839      if( uiNumOne > 0 )
1840      {
1841        uiCtxSet++;
1842      }
1843     
1844      uiNumOne       >>= 1;
1845      ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet;
1846      Int absCoeff[SCAN_SET_SIZE];
1847
1848      for ( Int i = 0; i < numNonZero; i++) absCoeff[i] = 1;   
1849      Int numC1Flag = min(numNonZero, C1FLAG_NUMBER);
1850      Int firstC2FlagIdx = -1;
1851
1852      for( Int idx = 0; idx < numC1Flag; idx++ )
1853      {
1854        m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] );
1855        if( uiBin == 1 )
1856        {
1857          c1 = 0;
1858          if (firstC2FlagIdx == -1)
1859          {
1860            firstC2FlagIdx = idx;
1861          }
1862        }
1863        else if( (c1 < 3) && (c1 > 0) )
1864        {
1865          c1++;
1866        }
1867        absCoeff[ idx ] = uiBin + 1;
1868      }
1869     
1870      if (c1 == 0)
1871      {
1872        baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet;
1873        if ( firstC2FlagIdx != -1)
1874        {
1875          m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] ); 
1876          absCoeff[ firstC2FlagIdx ] = uiBin + 2;
1877        }
1878      }
1879
1880      UInt coeffSigns;
1881      if ( signHidden && beValid )
1882      {
1883        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 );
1884        coeffSigns <<= 32 - (numNonZero-1);
1885      }
1886      else
1887      {
1888        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero );
1889        coeffSigns <<= 32 - numNonZero;
1890      }
1891     
1892      Int iFirstCoeff2 = 1;   
1893      if (c1 == 0 || numNonZero > C1FLAG_NUMBER)
1894      {
1895        for( Int idx = 0; idx < numNonZero; idx++ )
1896        {
1897          UInt baseLevel  = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2) : 1;
1898
1899          if( absCoeff[ idx ] == baseLevel)
1900          {
1901            UInt uiLevel;
1902            xReadGoRiceExGolomb( uiLevel, uiGoRiceParam );
1903            absCoeff[ idx ] = uiLevel + baseLevel;
1904          }
1905
1906          if(absCoeff[ idx ] >= 2) 
1907          {
1908            iFirstCoeff2 = 0;
1909            uiNumOne++;
1910          }
1911        }
1912      }
1913
1914      for( Int idx = 0; idx < numNonZero; idx++ )
1915      {
1916        Int blkPos = pos[ idx ];
1917        // Signs applied later.
1918        pcCoef[ blkPos ] = absCoeff[ idx ];
1919        absSum += absCoeff[ idx ];
1920
1921        if ( idx == numNonZero-1 && signHidden && beValid )
1922        {
1923          // Infer sign of 1st element.
1924          if (absSum&0x1)
1925            pcCoef[ blkPos ] = -pcCoef[ blkPos ];
1926        }
1927        else
1928        {
1929          Int sign = static_cast<Int>( coeffSigns ) >> 31;
1930          pcCoef[ blkPos ] = ( pcCoef[ blkPos ] ^ sign ) - sign;
1931          coeffSigns <<= 1;
1932        }
1933      }
1934    }
1935    else
1936    {
1937      uiNumOne >>= 1;
1938    }
1939  }
1940 
1941  return;
1942}
1943
1944#if LGE_SAO_MIGRATION_D0091
1945Void TDecSbac::parseSaoMaxUvlc ( UInt& val, UInt maxSymbol )
1946{
1947    if (maxSymbol == 0)
1948    {
1949        val = 0;
1950        return;
1951    }
1952
1953    UInt code;
1954    Int  i;
1955    m_pcTDecBinIf->decodeBinEP( code );
1956    if ( code == 0 )
1957    {
1958        val = 0;
1959        return;
1960    }
1961
1962    i=1;
1963    while (1)
1964    {
1965        m_pcTDecBinIf->decodeBinEP( code );
1966        if ( code == 0 )
1967        {
1968            break;
1969        }
1970        i++;
1971        if (i == maxSymbol)
1972        {
1973            break;
1974        }
1975    }   
1976
1977    val = i;
1978}
1979
1980Void TDecSbac::parseSaoUflc (UInt uiLength, UInt&  riVal)
1981{
1982    m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength );
1983}
1984
1985Void TDecSbac::parseSaoMerge (UInt&  ruiVal)
1986{
1987    UInt uiCode;
1988    m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) );
1989    ruiVal = (Int)uiCode;
1990}
1991
1992Void TDecSbac::parseSaoTypeIdx (UInt&  ruiVal)
1993{
1994    UInt uiCode;
1995    m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
1996    if (uiCode == 0) 
1997    {
1998        ruiVal = 0;
1999    }
2000    else
2001    {
2002        m_pcTDecBinIf->decodeBinEP( uiCode ); 
2003        if (uiCode == 0)
2004        {
2005            ruiVal = 5;
2006        }
2007        else
2008        {
2009            ruiVal = 1;
2010        }
2011    }
2012}
2013
2014inline Void copySaoOneLcuParam(SaoLcuParam* psDst,  SaoLcuParam* psSrc)
2015{
2016    Int i;
2017    psDst->partIdx = psSrc->partIdx;
2018    psDst->typeIdx = psSrc->typeIdx;
2019    if (psDst->typeIdx != -1)
2020    {
2021        psDst->subTypeIdx = psSrc->subTypeIdx ;
2022        psDst->length  = psSrc->length;
2023        for (i=0;i<psDst->length;i++)
2024        {
2025            psDst->offset[i] = psSrc->offset[i];
2026        }
2027    }
2028    else
2029    {
2030        psDst->length  = 0;
2031        for (i=0;i<SAO_BO_LEN;i++)
2032        {
2033            psDst->offset[i] = 0;
2034        }
2035    }
2036}
2037
2038Void TDecSbac::parseSaoOffset(SaoLcuParam* psSaoLcuParam, UInt compIdx)
2039{
2040    UInt uiSymbol;
2041    static Int iTypeLength[MAX_NUM_SAO_TYPE] =
2042    {
2043        SAO_EO_LEN,
2044        SAO_EO_LEN,
2045        SAO_EO_LEN,
2046        SAO_EO_LEN,
2047        SAO_BO_LEN
2048    }; 
2049
2050    if (compIdx==2)
2051    {
2052        uiSymbol = (UInt)( psSaoLcuParam->typeIdx + 1);
2053    }
2054    else
2055    {
2056        parseSaoTypeIdx(uiSymbol);
2057    }
2058    psSaoLcuParam->typeIdx = (Int)uiSymbol - 1;
2059
2060    if (uiSymbol)
2061    {
2062        psSaoLcuParam->length = iTypeLength[psSaoLcuParam->typeIdx];
2063#if FULL_NBIT
2064        Int offsetTh = 1 << ( min((Int)(g_uiBitDepth + (g_uiBitDepth-8)-5),5) );
2065#else
2066        Int offsetTh = 1 << ( min((Int)(g_uiBitDepth + g_uiBitIncrement-5),5) );
2067#endif
2068
2069        if( psSaoLcuParam->typeIdx == SAO_BO )
2070        {
2071            for(Int i=0; i< psSaoLcuParam->length; i++)
2072            {
2073                parseSaoMaxUvlc(uiSymbol, offsetTh -1 );
2074                psSaoLcuParam->offset[i] = uiSymbol;
2075            }   
2076            for(Int i=0; i< psSaoLcuParam->length; i++)
2077            {
2078                if (psSaoLcuParam->offset[i] != 0)
2079                {
2080                    m_pcTDecBinIf->decodeBinEP ( uiSymbol);
2081                    if (uiSymbol)
2082                    {
2083                        psSaoLcuParam->offset[i] = -psSaoLcuParam->offset[i] ;
2084                    }
2085                }
2086            }
2087            parseSaoUflc(5, uiSymbol );
2088            psSaoLcuParam->subTypeIdx = uiSymbol;
2089        }
2090        else if( psSaoLcuParam->typeIdx < 4 )
2091        {
2092            parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[0] = uiSymbol;   
2093            parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[1] = uiSymbol;
2094            parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[2] = -(Int)uiSymbol;
2095            parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[3] = -(Int)uiSymbol;
2096            if (compIdx != 2)
2097            {
2098                parseSaoUflc(2, uiSymbol );
2099                psSaoLcuParam->subTypeIdx = uiSymbol;
2100                psSaoLcuParam->typeIdx += psSaoLcuParam->subTypeIdx;
2101            }
2102        }
2103    }
2104    else
2105    {
2106        psSaoLcuParam->length = 0;
2107    }
2108}
2109
2110Void TDecSbac::parseSaoOneLcuInterleaving(Int rx, Int ry, SAOParam* pSaoParam, TComDataCU* pcCU, Int iCUAddrInSlice, Int iCUAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp)
2111{
2112    Int iAddr = pcCU->getAddr();
2113    UInt uiSymbol;
2114
2115    for (Int iCompIdx=0; iCompIdx<3; iCompIdx++)
2116    {
2117        pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag    = 0;
2118        pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag  = 0;
2119        pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx     = 0;
2120        pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx        =-1;
2121        pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[0]      = 0;
2122        pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[1]      = 0;
2123        pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[2]      = 0;
2124        pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[3]      = 0;
2125    }
2126    if (pSaoParam->bSaoFlag[0] || pSaoParam->bSaoFlag[1] )
2127    {
2128        if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft)
2129        {
2130            parseSaoMerge(uiSymbol); 
2131            pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag = (Bool)uiSymbol; 
2132        }
2133        if (pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag==0)
2134        {
2135            if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp)
2136            {
2137                parseSaoMerge(uiSymbol);
2138                pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag = (Bool)uiSymbol;
2139            }
2140        }
2141    }
2142
2143    for (Int iCompIdx=0; iCompIdx<3; iCompIdx++)
2144    {
2145        if ((iCompIdx == 0  && pSaoParam->bSaoFlag[0]) || (iCompIdx > 0  && pSaoParam->bSaoFlag[1]) )
2146        {
2147            if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft)
2148            {
2149                pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag;
2150            }
2151            else
2152            {
2153                pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = 0;
2154            }
2155
2156            if (pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag==0)
2157            {
2158                if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp)
2159                {
2160                    pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag;
2161                }
2162                else
2163                {
2164                    pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = 0;
2165                }
2166   
2167                if (!pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag)
2168                {
2169                    pSaoParam->saoLcuParam[2][iAddr].typeIdx = pSaoParam->saoLcuParam[1][iAddr].typeIdx;
2170                    parseSaoOffset(&(pSaoParam->saoLcuParam[iCompIdx][iAddr]), iCompIdx);
2171                }
2172                else
2173                {
2174                    copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr], &pSaoParam->saoLcuParam[iCompIdx][iAddr-pSaoParam->numCuInWidth]);
2175                }
2176            }
2177            else
2178            {
2179                copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr],  &pSaoParam->saoLcuParam[iCompIdx][iAddr-1]);
2180            }
2181        }
2182        else
2183        {
2184            pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx    = -1;
2185            pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx = 0;
2186        }
2187    }
2188}
2189#else
2190Void TDecSbac::parseSaoUvlc (UInt& ruiVal)
2191{
2192  UInt uiCode;
2193  Int  i;
2194
2195  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoUvlcSCModel.get( 0, 0, 0 ) );
2196  if ( uiCode == 0 )
2197  {
2198    ruiVal = 0;
2199    return;
2200  }
2201
2202  i=1;
2203  while (1)
2204  {
2205    m_pcTDecBinIf->decodeBin( uiCode, m_cSaoUvlcSCModel.get( 0, 0, 1 ) );
2206    if ( uiCode == 0 ) break;
2207    i++;
2208  }
2209
2210  ruiVal = i;
2211}
2212
2213Void TDecSbac::parseSaoSvlc (Int&  riVal)
2214{
2215  UInt uiCode;
2216  Int  iSign;
2217  Int  i;
2218
2219  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoSvlcSCModel.get( 0, 0, 0 ) );
2220
2221  if ( uiCode == 0 )
2222  {
2223    riVal = 0;
2224    return;
2225  }
2226
2227  // read sign
2228  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoSvlcSCModel.get( 0, 0, 1 ) );
2229
2230  if ( uiCode == 0 )
2231  {
2232    iSign =  1;
2233  }
2234  else
2235  {
2236    iSign = -1;
2237  }
2238
2239  // read magnitude
2240  i=1;
2241  while (1)
2242  {
2243    m_pcTDecBinIf->decodeBin( uiCode, m_cSaoSvlcSCModel.get( 0, 0, 2 ) );
2244    if ( uiCode == 0 ) break;
2245    i++;
2246  }
2247
2248  riVal = i*iSign;
2249}
2250
2251Void TDecSbac::parseSaoUflc (UInt&  riVal)
2252{
2253  UInt uiSymbol;
2254  riVal = 0;
2255  for (Int i=0;i<5;i++)
2256  {
2257    m_pcTDecBinIf->decodeBinEP ( uiSymbol );
2258    if (uiSymbol)
2259    {
2260      riVal |= (1<<i);
2261    }
2262  }
2263}
2264Void TDecSbac::parseSaoMergeLeft (UInt&  ruiVal, UInt uiCompIdx)
2265{
2266  UInt uiCode;
2267  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeLeftSCModel.get( 0, 0, uiCompIdx ) );
2268  ruiVal = (Int)uiCode;
2269}
2270
2271Void TDecSbac::parseSaoMergeUp (UInt&  ruiVal)
2272{
2273  UInt uiCode;
2274  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeUpSCModel.get( 0, 0, 0 ) );
2275  ruiVal = (Int)uiCode;
2276}
2277Void TDecSbac::parseSaoTypeIdx (UInt&  ruiVal)
2278{
2279  UInt uiCode;
2280  Int  i;
2281  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
2282  if ( uiCode == 0 )
2283  {
2284    ruiVal = 0;
2285    return;
2286  }
2287  i=1;
2288  while (1)
2289  {
2290    m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 1 ) );
2291    if ( uiCode == 0 ) break;
2292    i++;
2293  }
2294  ruiVal = i;
2295}
2296
2297inline Void copySaoOneLcuParam(SaoLcuParam* psDst,  SaoLcuParam* psSrc)
2298{
2299  Int i;
2300  psDst->partIdx = psSrc->partIdx;
2301  psDst->typeIdx    = psSrc->typeIdx;
2302  if (psDst->typeIdx != -1)
2303  {
2304    if (psDst->typeIdx == SAO_BO)
2305    {
2306      psDst->bandPosition = psSrc->bandPosition ;
2307    }
2308    else
2309    {
2310      psDst->bandPosition = 0;
2311    }
2312    psDst->length  = psSrc->length;
2313    for (i=0;i<psDst->length;i++)
2314    {
2315      psDst->offset[i] = psSrc->offset[i];
2316    }
2317  }
2318  else
2319  {
2320    psDst->length  = 0;
2321    for (i=0;i<SAO_BO_LEN;i++)
2322    {
2323      psDst->offset[i] = 0;
2324    }
2325  }
2326}
2327Void TDecSbac::parseSaoOffset(SaoLcuParam* psSaoLcuParam)
2328{
2329  UInt uiSymbol;
2330  Int iSymbol;
2331  static Int iTypeLength[MAX_NUM_SAO_TYPE] = {
2332    SAO_EO_LEN,
2333    SAO_EO_LEN,
2334    SAO_EO_LEN,
2335    SAO_EO_LEN,
2336    SAO_BO_LEN
2337  }; 
2338
2339  parseSaoTypeIdx(uiSymbol);
2340  psSaoLcuParam->typeIdx = (Int)uiSymbol - 1;
2341  if (uiSymbol)
2342  {
2343    psSaoLcuParam->length = iTypeLength[psSaoLcuParam->typeIdx];
2344    if( psSaoLcuParam->typeIdx == SAO_BO )
2345    {
2346      // Parse Left Band Index
2347      parseSaoUflc( uiSymbol );
2348      psSaoLcuParam->bandPosition = uiSymbol;
2349      for(Int i=0; i< psSaoLcuParam->length; i++)
2350      {
2351        parseSaoSvlc(iSymbol);
2352        psSaoLcuParam->offset[i] = iSymbol;
2353      }   
2354    }
2355    else if( psSaoLcuParam->typeIdx < 4 )
2356    {
2357      parseSaoUvlc(uiSymbol); psSaoLcuParam->offset[0] = uiSymbol;
2358      parseSaoUvlc(uiSymbol); psSaoLcuParam->offset[1] = uiSymbol;
2359      parseSaoUvlc(uiSymbol); psSaoLcuParam->offset[2] = -(Int)uiSymbol;
2360      parseSaoUvlc(uiSymbol); psSaoLcuParam->offset[3] = -(Int)uiSymbol;
2361    }
2362  }
2363  else
2364  {
2365    psSaoLcuParam->length = 0;
2366  }
2367}
2368
2369Void TDecSbac::parseSaoOneLcuInterleaving(Int rx, Int ry, SAOParam* pSaoParam, TComDataCU* pcCU, Int iCUAddrInSlice, Int iCUAddrUpInSlice, Bool bLFCrossSliceBoundaryFlag)
2370{
2371  Int iAddr = pcCU->getAddr();
2372  UInt uiSymbol;
2373  for (Int iCompIdx=0; iCompIdx<3; iCompIdx++)
2374  {
2375    pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag    = 0;
2376    pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag  = 0;
2377    pSaoParam->saoLcuParam[iCompIdx][iAddr].bandPosition   = 0;
2378    pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx        = -1;
2379    pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[0]     = 0;
2380    pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[1]     = 0;
2381    pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[2]     = 0;
2382    pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[3]     = 0;
2383
2384    if (pSaoParam->bSaoFlag[iCompIdx])
2385    {
2386      if (rx>0 && iCUAddrInSlice!=0)
2387      {
2388        parseSaoMergeLeft(uiSymbol,iCompIdx); pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = (Int)uiSymbol;
2389      }
2390      else
2391      {
2392        pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = 0;
2393      }
2394
2395      if (pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag==0)
2396      {
2397        if ((ry > 0) && (iCUAddrUpInSlice>0||bLFCrossSliceBoundaryFlag))
2398        {
2399          parseSaoMergeUp(uiSymbol);  pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = uiSymbol;
2400        }
2401        else
2402        {
2403          pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = 0;
2404        }
2405        if (!pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag)
2406        {
2407          parseSaoOffset(&(pSaoParam->saoLcuParam[iCompIdx][iAddr]));
2408        }
2409        else
2410        {
2411          copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr], &pSaoParam->saoLcuParam[iCompIdx][iAddr-pSaoParam->numCuInWidth]);
2412        }
2413      }
2414      else
2415      {
2416        copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr],  &pSaoParam->saoLcuParam[iCompIdx][iAddr-1]);
2417      }
2418    }
2419    else
2420    {
2421      pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx = -1;
2422      pSaoParam->saoLcuParam[iCompIdx][iAddr].bandPosition = 0;
2423    }
2424  }
2425}
2426#endif
2427/**
2428 - Initialize our contexts from the nominated source.
2429 .
2430 \param pSrc Contexts to be copied.
2431 */
2432Void TDecSbac::xCopyContextsFrom( TDecSbac* pSrc )
2433{
2434  memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0]));
2435}
2436
2437Void TDecSbac::xCopyFrom( TDecSbac* pSrc )
2438{
2439  m_pcTDecBinIf->copyState( pSrc->m_pcTDecBinIf );
2440
2441  m_uiLastQp           = pSrc->m_uiLastQp;
2442  xCopyContextsFrom( pSrc );
2443
2444}
2445
2446Void TDecSbac::load ( TDecSbac* pScr )
2447{
2448  xCopyFrom(pScr);
2449}
2450
2451Void TDecSbac::loadContexts ( TDecSbac* pScr )
2452{
2453  xCopyContextsFrom(pScr);
2454}
2455
2456Void TDecSbac::decodeFlush ( )
2457{
2458  UInt uiBit;
2459  m_pcTDecBinIf->decodeBinTrm(uiBit);
2460  m_pcTDecBinIf->flush();
2461
2462}
2463
2464#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX || (LGE_EDGE_INTRA_A0070 && LGE_EDGE_INTRA_DELTA_DC)
2465Void TDecSbac::xReadExGolombLevel( UInt& ruiSymbol, ContextModel& rcSCModel  )
2466{
2467  UInt uiSymbol;
2468  UInt uiCount = 0;
2469  do
2470  {
2471    m_pcTDecBinIf->decodeBin( uiSymbol, rcSCModel );
2472    uiCount++;
2473  }
2474  while( uiSymbol && ( uiCount != 13 ) );
2475
2476  ruiSymbol = uiCount - 1;
2477
2478  if( uiSymbol )
2479  {
2480    xReadEpExGolomb( uiSymbol, 0 );
2481    ruiSymbol += uiSymbol + 1;
2482  }
2483
2484  return;
2485}
2486#endif
2487#if HHI_DMM_WEDGE_INTRA
2488Void TDecSbac::xParseWedgeFullInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2489{
2490  Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx);
2491  Int iBits = g_aucWedgeFullBitsListIdx[iIntraIdx];
2492
2493  UInt uiSymbol, uiTabIdx = 0;
2494  for ( Int i = 0; i < iBits; i++ )
2495  {
2496    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmDataSCModel.get(0, 0, 0) );
2497    uiTabIdx += ( uiSymbol && i == 0 ) ? 1 : 0;
2498    uiTabIdx += ( uiSymbol && i == 1 ) ? 2 : 0;
2499    uiTabIdx += ( uiSymbol && i == 2 ) ? 4 : 0;
2500    uiTabIdx += ( uiSymbol && i == 3 ) ? 8 : 0;
2501    uiTabIdx += ( uiSymbol && i == 4 ) ? 16 : 0;
2502    uiTabIdx += ( uiSymbol && i == 5 ) ? 32 : 0;
2503    uiTabIdx += ( uiSymbol && i == 6 ) ? 64 : 0;
2504    uiTabIdx += ( uiSymbol && i == 7 ) ? 128 : 0;
2505    uiTabIdx += ( uiSymbol && i == 8 ) ? 256 : 0;
2506    uiTabIdx += ( uiSymbol && i == 9 ) ? 512 : 0;
2507    uiTabIdx += ( uiSymbol && i == 10 ) ? 1024 : 0;
2508    uiTabIdx += ( uiSymbol && i == 11 ) ? 2048 : 0;
2509    uiTabIdx += ( uiSymbol && i == 12 ) ? 4096 : 0;
2510  }
2511
2512  pcCU->setWedgeFullTabIdxSubParts( uiTabIdx, uiAbsPartIdx, uiDepth );
2513}
2514
2515Void TDecSbac::xParseWedgeFullDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2516{
2517  Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx);
2518  Int iBits = g_aucWedgeFullBitsListIdx[iIntraIdx];
2519
2520  UInt uiSymbol, uiTabIdx = 0;
2521  for ( Int i = 0; i < iBits; i++ )
2522  {
2523    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmDataSCModel.get(0, 0, 0) );
2524    uiTabIdx += ( uiSymbol && i == 0 ) ? 1 : 0;
2525    uiTabIdx += ( uiSymbol && i == 1 ) ? 2 : 0;
2526    uiTabIdx += ( uiSymbol && i == 2 ) ? 4 : 0;
2527    uiTabIdx += ( uiSymbol && i == 3 ) ? 8 : 0;
2528    uiTabIdx += ( uiSymbol && i == 4 ) ? 16 : 0;
2529    uiTabIdx += ( uiSymbol && i == 5 ) ? 32 : 0;
2530    uiTabIdx += ( uiSymbol && i == 6 ) ? 64 : 0;
2531    uiTabIdx += ( uiSymbol && i == 7 ) ? 128 : 0;
2532    uiTabIdx += ( uiSymbol && i == 8 ) ? 256 : 0;
2533    uiTabIdx += ( uiSymbol && i == 9 ) ? 512 : 0;
2534    uiTabIdx += ( uiSymbol && i == 10 ) ? 1024 : 0;
2535    uiTabIdx += ( uiSymbol && i == 11 ) ? 2048 : 0;
2536    uiTabIdx += ( uiSymbol && i == 12 ) ? 4096 : 0;
2537  }
2538
2539  pcCU->setWedgeFullTabIdxSubParts( uiTabIdx, uiAbsPartIdx, uiDepth );
2540
2541  UInt uiDC1, uiDC2;
2542  xReadExGolombLevel( uiDC1, m_cDmmDataSCModel.get(0, 0, 1) );
2543  Int iDC1 = uiDC1;
2544  if ( uiDC1 )
2545  {
2546    UInt uiSign;
2547    m_pcTDecBinIf->decodeBinEP( uiSign );
2548    if ( uiSign )
2549    {
2550      iDC1 = -iDC1;
2551    }
2552  }
2553  xReadExGolombLevel( uiDC2, m_cDmmDataSCModel.get(0, 0, 1) );
2554  Int iDC2 = uiDC2;
2555  if ( uiDC2 )
2556  {
2557    UInt uiSign;
2558    m_pcTDecBinIf->decodeBinEP( uiSign );
2559    if ( uiSign )
2560    {
2561      iDC2 = -iDC2;
2562    }
2563  }
2564
2565  pcCU->setWedgeFullDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
2566  pcCU->setWedgeFullDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
2567}
2568
2569Void TDecSbac::xParseWedgePredDirInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2570{
2571  if( DMM_WEDGE_PREDDIR_DELTAEND_MAX > 0 )
2572  {
2573    UInt uiDeltaEnd = 0;
2574    m_pcTDecBinIf->decodeBin( uiDeltaEnd, m_cDmmDataSCModel.get(0, 0, 2) );
2575
2576    Int iDeltaEnd;
2577    if( uiDeltaEnd != 0 )
2578    {
2579      UInt uiAbsValMinus1;
2580      UInt uiSymbol;
2581      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmDataSCModel.get(0, 0, 2) ); uiAbsValMinus1  = uiSymbol;
2582      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmDataSCModel.get(0, 0, 2) ); uiAbsValMinus1 |= uiSymbol << 1;
2583      uiDeltaEnd = uiAbsValMinus1 + 1;
2584
2585      iDeltaEnd = uiDeltaEnd;
2586      UInt uiSign;
2587      m_pcTDecBinIf->decodeBinEP( uiSign );
2588      if( uiSign )
2589      {
2590        iDeltaEnd = -iDeltaEnd;
2591      }
2592    }
2593    else
2594    {
2595      iDeltaEnd = 0;
2596    }
2597    pcCU->setWedgePredDirDeltaEndSubParts( iDeltaEnd, uiAbsPartIdx, uiDepth );
2598  }
2599}
2600
2601Void TDecSbac::xParseWedgePredDirDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2602{
2603  if( DMM_WEDGE_PREDDIR_DELTAEND_MAX > 0 )
2604  {
2605    UInt uiDeltaEnd = 0;
2606    m_pcTDecBinIf->decodeBin( uiDeltaEnd, m_cDmmDataSCModel.get(0, 0, 2) );
2607
2608    Int iDeltaEnd;
2609    if( uiDeltaEnd != 0 )
2610    {
2611      UInt uiAbsValMinus1;
2612      UInt uiSymbol;
2613      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmDataSCModel.get(0, 0, 2) ); uiAbsValMinus1  = uiSymbol;
2614      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmDataSCModel.get(0, 0, 2) ); uiAbsValMinus1 |= uiSymbol << 1;
2615      uiDeltaEnd = uiAbsValMinus1 + 1;
2616
2617      iDeltaEnd = uiDeltaEnd;
2618      UInt uiSign;
2619      m_pcTDecBinIf->decodeBinEP( uiSign );
2620      if( uiSign )
2621      {
2622        iDeltaEnd = -iDeltaEnd;
2623      }
2624    }
2625    else
2626    {
2627      iDeltaEnd = 0;
2628    }
2629
2630    pcCU->setWedgePredDirDeltaEndSubParts( iDeltaEnd, uiAbsPartIdx, uiDepth );
2631  }
2632
2633  UInt uiDC1, uiDC2;
2634  xReadExGolombLevel( uiDC1, m_cDmmDataSCModel.get(0, 0, 1) );
2635  Int iDC1 = uiDC1;
2636  if ( uiDC1 )
2637  {
2638    UInt uiSign;
2639    m_pcTDecBinIf->decodeBinEP( uiSign );
2640    if ( uiSign )
2641    {
2642      iDC1 = -iDC1;
2643    }
2644  }
2645  xReadExGolombLevel( uiDC2, m_cDmmDataSCModel.get(0, 0, 1) );
2646  Int iDC2 = uiDC2;
2647  if ( uiDC2 )
2648  {
2649    UInt uiSign;
2650    m_pcTDecBinIf->decodeBinEP( uiSign );
2651    if ( uiSign )
2652    {
2653      iDC2 = -iDC2;
2654    }
2655  }
2656
2657  pcCU->setWedgePredDirDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
2658  pcCU->setWedgePredDirDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
2659}
2660#endif
2661#if HHI_DMM_PRED_TEX
2662#if LGE_DMM3_SIMP_C0044
2663Void TDecSbac::xParseWedgePredTexInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2664{
2665  Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx);
2666  Int iBits = g_aucWedgeTexPredBitsListIdx[iIntraIdx];
2667
2668  UInt uiSymbol, uiTabIdx = 0;
2669  for ( Int i = 0; i < iBits; i++ )
2670  {
2671    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmDataSCModel.get(0, 0, 3) );
2672    uiTabIdx += ( uiSymbol && i == 0 ) ? 1 : 0;
2673    uiTabIdx += ( uiSymbol && i == 1 ) ? 2 : 0;
2674    uiTabIdx += ( uiSymbol && i == 2 ) ? 4 : 0;
2675    uiTabIdx += ( uiSymbol && i == 3 ) ? 8 : 0;
2676    uiTabIdx += ( uiSymbol && i == 4 ) ? 16 : 0;
2677    uiTabIdx += ( uiSymbol && i == 5 ) ? 32 : 0;
2678    uiTabIdx += ( uiSymbol && i == 6 ) ? 64 : 0;
2679    uiTabIdx += ( uiSymbol && i == 7 ) ? 128 : 0;
2680    uiTabIdx += ( uiSymbol && i == 8 ) ? 256 : 0;
2681    uiTabIdx += ( uiSymbol && i == 9 ) ? 512 : 0;
2682    uiTabIdx += ( uiSymbol && i == 10 ) ? 1024 : 0;
2683  }
2684
2685  pcCU->setWedgePredTexIntraTabIdxSubParts( uiTabIdx, uiAbsPartIdx, uiDepth );
2686}
2687#endif
2688
2689Void TDecSbac::xParseWedgePredTexDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2690{
2691#if LGE_DMM3_SIMP_C0044
2692  xParseWedgePredTexInfo( pcCU, uiAbsPartIdx, uiDepth );
2693#endif
2694  UInt uiDC1, uiDC2;
2695  xReadExGolombLevel( uiDC1, m_cDmmDataSCModel.get(0, 0, 1) );
2696  Int iDC1 = uiDC1;
2697  if ( uiDC1 )
2698  {
2699    UInt uiSign;
2700    m_pcTDecBinIf->decodeBinEP( uiSign );
2701    if ( uiSign )
2702    {
2703      iDC1 = -iDC1;
2704    }
2705  }
2706  xReadExGolombLevel( uiDC2, m_cDmmDataSCModel.get(0, 0, 1) );
2707  Int iDC2 = uiDC2;
2708  if ( uiDC2 )
2709  {
2710    UInt uiSign;
2711    m_pcTDecBinIf->decodeBinEP( uiSign );
2712    if ( uiSign )
2713    {
2714      iDC2 = -iDC2;
2715    }
2716  }
2717
2718  pcCU->setWedgePredTexDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
2719  pcCU->setWedgePredTexDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
2720}
2721
2722Void TDecSbac::xParseContourPredTexDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2723{
2724  UInt uiDC1, uiDC2;
2725  xReadExGolombLevel( uiDC1, m_cDmmDataSCModel.get(0, 0, 1) );
2726  Int iDC1 = uiDC1;
2727  if ( uiDC1 )
2728  {
2729    UInt uiSign;
2730    m_pcTDecBinIf->decodeBinEP( uiSign );
2731    if ( uiSign )
2732    {
2733      iDC1 = -iDC1;
2734    }
2735  }
2736  xReadExGolombLevel( uiDC2, m_cDmmDataSCModel.get(0, 0, 1) );
2737  Int iDC2 = uiDC2;
2738  if ( uiDC2 )
2739  {
2740    UInt uiSign;
2741    m_pcTDecBinIf->decodeBinEP( uiSign );
2742    if ( uiSign )
2743    {
2744      iDC2 = -iDC2;
2745    }
2746  }
2747
2748  pcCU->setContourPredTexDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
2749  pcCU->setContourPredTexDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
2750}
2751#endif
2752#if QC_ARP_D0177
2753Void TDecSbac::parseARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2754{
2755  UInt nMaxW = pcCU->getSlice()->getARPStepNum() - 1;
2756#if !QC_ARP_WARNING_FIX
2757  assert (nMaxW >= 0);
2758#endif
2759  UInt nW = 0;
2760  if( nMaxW > 0 )
2761  {
2762    UInt nOffset = pcCU->getCTXARPWFlag(uiAbsPartIdx);
2763#if !QC_ARP_WARNING_FIX
2764    assert( 0 <= nOffset && nOffset <= 2 );
2765#endif
2766    UInt uiCode = 0;
2767    m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPW.get( 0, 0, 0 + nOffset ) );
2768    nW = uiCode;
2769    if( nW == 1 )   
2770    {
2771      m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPW.get( 0, 0, 3 ) );
2772      nW += ( uiCode == 1 );
2773    }
2774  }
2775  pcCU->setARPWSubParts( ( UChar )( nW ) , uiAbsPartIdx, uiDepth ); 
2776}
2777#endif
2778#if LGE_EDGE_INTRA_A0070
2779Void TDecSbac::xParseEdgeIntraInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2780{
2781  UInt uiSymbol = 0;
2782
2783  // 1. Top(0) or Left(1)
2784  UChar ucLeft;
2785  m_pcTDecBinIf->decodeBinEP( uiSymbol );
2786  ucLeft = uiSymbol;
2787
2788  // 2. Start position (lowest bit first)
2789  UChar ucStart = 0;
2790  for( UInt ui = 0; ui < 6 - uiDepth; ui++ )
2791  {
2792    m_pcTDecBinIf->decodeBinEP( uiSymbol );
2793    ucStart |= (uiSymbol << ui);
2794  }
2795
2796  // 3. Number of edges
2797  UChar ucMax = 0;
2798  for( UInt ui = 0; ui < 7 - uiDepth; ui++ )
2799  {
2800    m_pcTDecBinIf->decodeBinEP( uiSymbol );
2801    ucMax |= (uiSymbol << ui);
2802  }
2803  ucMax++; // +1
2804
2805  // 4. Edges
2806  UChar* pucSymbolList = (UChar*) xMalloc( UChar, 256 * LGE_EDGE_INTRA_MAX_EDGE_NUM_PER_4x4 );
2807  UInt uiCtxEdgeIntra = pcCU->getCtxEdgeIntra( uiAbsPartIdx );
2808  for( Int iPtr = 0; iPtr < ucMax; iPtr++ )
2809  {
2810    UChar ucEdge = 0;
2811    UInt  uiReorderEdge = 0;
2812    // Left-friendly direction
2813    // 0 (   0deg) => 0
2814    // 1 (  45deg) => 10
2815    // 2 ( -45deg) => 110
2816    // 3 (  90deg) => 1110
2817    // 4 ( -90deg) => 11110
2818    // 5 ( 135deg) => 111110
2819    // 6 (-135deg) => 111111
2820    // Right-friendly direction
2821    // 0 (   0deg) => 0
2822    // 1 ( -45deg) => 10
2823    // 2 (  45deg) => 110
2824    // 3 ( -90deg) => 1110
2825    // 4 (  90deg) => 11110
2826    // 5 (-135deg) => 111110
2827    // 6 ( 135deg) => 111111
2828    // refer to a paper "An efficient chain code with Huffman coding"
2829    for( UInt ui = 0; ui < 6; ui++ )
2830    {
2831      m_pcTDecBinIf->decodeBin( uiSymbol, m_cEdgeIntraSCModel.get( 0, 0, uiCtxEdgeIntra ) );
2832      ucEdge <<= 1;
2833      ucEdge |= uiSymbol;
2834      if( uiSymbol == 0 )
2835        break;
2836    }
2837
2838    switch( ucEdge )
2839    {
2840    case 0 :  // "0"
2841      uiReorderEdge = 0;
2842      break;
2843    case 2 :  // "10"
2844      uiReorderEdge = 1;
2845      break;
2846    case 6 :  // "110"
2847      uiReorderEdge = 2;
2848      break;
2849    case 14 : // "1110"
2850      uiReorderEdge = 3;
2851      break;
2852    case 30 : // "11110"
2853      uiReorderEdge = 4;
2854      break;
2855    case 62 : // "111110"
2856      uiReorderEdge = 5;
2857      break;
2858    case 63 : // "111111"
2859      uiReorderEdge = 6;
2860      break;
2861    default :
2862      printf("parseIntraEdgeChain: error (unknown code %d)\n",ucEdge);
2863      assert(false);
2864      break;
2865    }
2866    pucSymbolList[iPtr] = uiReorderEdge;
2867  }
2868  /////////////////////
2869  // Edge Reconstruction
2870  Bool* pbRegion = pcCU->getEdgePartition( uiAbsPartIdx );
2871  pcCU->reconPartition( uiAbsPartIdx, uiDepth, ucLeft == 1, ucStart, ucMax, pucSymbolList, pbRegion );
2872  xFree( pucSymbolList );
2873}
2874#endif
2875 
2876#if RWTH_SDC_DLT_B0036
2877#if !PKU_QC_DEPTH_INTRA_UNI_D0195
2878Void TDecSbac::parseSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2879{
2880  assert( pcCU->getSlice()->getSPS()->isDepth() );
2881 
2882  UInt uiSymbol = 0;
2883  UInt uiCtxSDCFlag = pcCU->getCtxSDCFlag( uiAbsPartIdx );
2884  m_pcTDecBinIf->decodeBin( uiSymbol, m_cSDCFlagSCModel.get( 0, 0, uiCtxSDCFlag ) );
2885 
2886  if( uiSymbol == 1 )
2887  {
2888    pcCU->setPartSizeSubParts(SIZE_2Nx2N, uiAbsPartIdx, uiDepth);
2889   
2890    pcCU->setSDCFlagSubParts( true, uiAbsPartIdx, 0, uiDepth);
2891    pcCU->setTrIdxSubParts(0, uiAbsPartIdx, uiDepth);
2892    pcCU->setCbfSubParts(1, 1, 1, uiAbsPartIdx, uiDepth);
2893  }
2894}
2895
2896Void TDecSbac::parseSDCPredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2897{
2898  assert( pcCU->getSlice()->getSPS()->isDepth() );
2899  assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
2900 
2901  assert( pcCU->getSDCFlag(uiAbsPartIdx) );
2902 
2903  UInt uiCtx            = 0;
2904 
2905  UInt uiMPModeIdx      = 0;
2906 
2907  for(Int i=0; i<RWTH_SDC_NUM_PRED_MODES-1; i++)
2908  {
2909    UInt uiIsMostProb = 0;
2910#if INTEL_SDC64_D0193
2911    if( !(pcCU->getWidth(uiAbsPartIdx) == 64 && i == 1))
2912#endif
2913    m_pcTDecBinIf->decodeBin( uiIsMostProb, m_cSDCPredModeSCModel.get( 0, i, uiCtx ) );
2914   
2915    if ( uiIsMostProb == 1 )
2916      break;
2917   
2918    // else: get next most probable pred mode
2919    uiMPModeIdx = (uiMPModeIdx+1)%RWTH_SDC_NUM_PRED_MODES;
2920  }
2921 
2922  Int intraPredMode = g_auiSDCPredModes[uiMPModeIdx];
2923 
2924#if HHI_DMM_WEDGE_INTRA
2925  if( intraPredMode == DMM_WEDGE_FULL_IDX )          { xParseWedgeFullInfo          ( pcCU, uiAbsPartIdx, uiDepth ); }
2926  if( intraPredMode == DMM_WEDGE_PREDDIR_IDX )       { xParseWedgePredDirInfo       ( pcCU, uiAbsPartIdx, uiDepth ); }
2927#endif
2928 
2929  pcCU->setLumaIntraDirSubParts((UChar)intraPredMode, uiAbsPartIdx, uiDepth);
2930}
2931#endif
2932
2933Void TDecSbac::parseSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSegment )
2934{
2935  assert( pcCU->getSlice()->getSPS()->isDepth() );
2936  assert( pcCU->getSDCFlag(uiAbsPartIdx) );
2937  assert( uiSegment < 2 );
2938 
2939  UInt uiResidual = 0;
2940  UInt uiBit      = 0;
2941  UInt uiAbsIdx   = 0;
2942  UInt uiSign     = 0;
2943  Int  iIdx       = 0;
2944 
2945  UInt uiMaxResidualBits  = pcCU->getSlice()->getSPS()->getBitsPerDepthValue();
2946  assert( uiMaxResidualBits <= g_uiBitDepth );
2947 
2948#if RWTH_SDC_CTX_SIMPL_D0032
2949  m_pcTDecBinIf->decodeBin(uiResidual, m_cSDCResidualFlagSCModel.get( 0, 0, 0 ) );
2950#else
2951  m_pcTDecBinIf->decodeBin(uiResidual, m_cSDCResidualFlagSCModel.get( 0, uiSegment, 0 ) );
2952#endif
2953 
2954  if (uiResidual)
2955  {
2956    // decode residual sign bit
2957#if RWTH_SDC_CTX_SIMPL_D0032
2958    m_pcTDecBinIf->decodeBinEP(uiSign);
2959#else
2960    m_pcTDecBinIf->decodeBin(uiSign, m_cSDCResidualSignFlagSCModel.get( 0, uiSegment, 0 ) );
2961#endif
2962   
2963    // decode residual magnitude
2964#if LGE_CONCATENATE_D0141
2965    //prefix part
2966    UInt uiCount = 0;
2967    UInt uiNumDepthValues = pcCU->getSlice()->getSPS()->getNumDepthValues();
2968    UInt uiPrefixThreshold = ((uiNumDepthValues * 3) >> 2);
2969    for ( UInt ui = 0; ui < uiPrefixThreshold; ui++)
2970    {
2971        m_pcTDecBinIf->decodeBin( uiBit, m_cSDCResidualSCModel.get(0, 0, 0) );
2972        if ( uiBit == 0 )
2973            break;
2974        else
2975            uiCount++;
2976    }
2977    //suffix part
2978    if ( uiCount == uiPrefixThreshold )
2979    {
2980        for ( UInt ui = 0; ui < ( (UInt)ceil( Log2(uiNumDepthValues - uiPrefixThreshold) ) ); ui++ )
2981        {
2982            m_pcTDecBinIf->decodeBinEP( uiBit );
2983            uiAbsIdx |= uiBit << ui;
2984        }
2985        uiAbsIdx += uiCount;
2986    }
2987    else
2988        uiAbsIdx = uiCount;
2989#else
2990    for (Int i=0; i<uiMaxResidualBits; i++)
2991    {
2992#if RWTH_SDC_CTX_SIMPL_D0032
2993      m_pcTDecBinIf->decodeBin(uiBit, m_cSDCResidualSCModel.get( 0, 0, i ) );
2994#else
2995      m_pcTDecBinIf->decodeBin(uiBit, m_cSDCResidualSCModel.get( 0, uiSegment, i ) );
2996#endif
2997      uiAbsIdx |= uiBit << i;
2998    }
2999#endif
3000   
3001    uiAbsIdx += 1;
3002    iIdx =(Int)(uiSign ? -1 : 1)*uiAbsIdx;
3003  }
3004 
3005  pcCU->setSDCSegmentDCOffset(iIdx, uiSegment, uiAbsPartIdx);
3006}
3007#endif
3008
3009//! \}
Note: See TracBrowser for help on using the repository browser.