source: 3DVCSoftware/branches/HTM-6.2-dev3-RWTH-Fix/source/Lib/TLibDecoder/TDecSbac.cpp @ 414

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