source: 3DVCSoftware/branches/HTM-4.1-dev2-RWTH/source/Lib/TLibDecoder/TDecSbac.cpp @ 184

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