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

Last change on this file since 427 was 427, checked in by tech, 11 years ago

Merged HTM-6.2-dev1-LG

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