source: 3DVCSoftware/branches/HTM-6.2-dev1-LG/source/Lib/TLibDecoder/TDecSbac.cpp @ 425

Last change on this file since 425 was 408, checked in by lg, 12 years ago

D0135->D0092->D0091

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