source: 3DVCSoftware/branches/HTM-10.0rc1-dev0/source/Lib/TLibDecoder/TDecSbac.cpp @ 838

Last change on this file since 838 was 838, checked in by tech, 10 years ago

Further fixes.

  • Property svn:eol-style set to native
File size: 67.4 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6* Copyright (c) 2010-2014, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TDecSbac.cpp
35    \brief    Context-adaptive entropy decoder class
36*/
37
38#include "TDecSbac.h"
39
40//! \ingroup TLibDecoder
41//! \{
42
43//////////////////////////////////////////////////////////////////////
44// Construction/Destruction
45//////////////////////////////////////////////////////////////////////
46
47TDecSbac::TDecSbac() 
48// new structure here
49: m_pcBitstream               ( 0 )
50, m_pcTDecBinIf               ( NULL )
51, m_numContextModels          ( 0 )
52, m_cCUSplitFlagSCModel       ( 1,             1,               NUM_SPLIT_FLAG_CTX            , m_contextModels + m_numContextModels, m_numContextModels )
53, m_cCUSkipFlagSCModel        ( 1,             1,               NUM_SKIP_FLAG_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
54, m_cCUMergeFlagExtSCModel    ( 1,             1,               NUM_MERGE_FLAG_EXT_CTX        , m_contextModels + m_numContextModels, m_numContextModels)
55, m_cCUMergeIdxExtSCModel     ( 1,             1,               NUM_MERGE_IDX_EXT_CTX         , m_contextModels + m_numContextModels, m_numContextModels)
56#if H_3D_ARP
57, m_cCUPUARPWSCModel          ( 1,             1,               NUM_ARPW_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
58#endif
59#if H_3D_IC
60, m_cCUICFlagSCModel          ( 1,             1,               NUM_IC_FLAG_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
61#endif
62, m_cCUPartSizeSCModel        ( 1,             1,               NUM_PART_SIZE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
63, m_cCUPredModeSCModel        ( 1,             1,               NUM_PRED_MODE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
64, m_cCUIntraPredSCModel       ( 1,             1,               NUM_ADI_CTX                   , m_contextModels + m_numContextModels, m_numContextModels)
65, m_cCUChromaPredSCModel      ( 1,             1,               NUM_CHROMA_PRED_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
66, m_cCUDeltaQpSCModel         ( 1,             1,               NUM_DELTA_QP_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
67, m_cCUInterDirSCModel        ( 1,             1,               NUM_INTER_DIR_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
68, m_cCURefPicSCModel          ( 1,             1,               NUM_REF_NO_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
69, m_cCUMvdSCModel             ( 1,             1,               NUM_MV_RES_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
70, m_cCUQtCbfSCModel           ( 1,             2,               NUM_QT_CBF_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
71, m_cCUTransSubdivFlagSCModel ( 1,             1,               NUM_TRANS_SUBDIV_FLAG_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
72, m_cCUQtRootCbfSCModel       ( 1,             1,               NUM_QT_ROOT_CBF_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
73, m_cCUSigCoeffGroupSCModel   ( 1,             2,               NUM_SIG_CG_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
74, m_cCUSigSCModel             ( 1,             1,               NUM_SIG_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
75, m_cCuCtxLastX               ( 1,             2,               NUM_CTX_LAST_FLAG_XY          , m_contextModels + m_numContextModels, m_numContextModels)
76, m_cCuCtxLastY               ( 1,             2,               NUM_CTX_LAST_FLAG_XY          , m_contextModels + m_numContextModels, m_numContextModels)
77, m_cCUOneSCModel             ( 1,             1,               NUM_ONE_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
78, m_cCUAbsSCModel             ( 1,             1,               NUM_ABS_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
79, m_cMVPIdxSCModel            ( 1,             1,               NUM_MVP_IDX_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
80, m_cSaoMergeSCModel      ( 1,             1,               NUM_SAO_MERGE_FLAG_CTX   , m_contextModels + m_numContextModels, m_numContextModels)
81, m_cSaoTypeIdxSCModel        ( 1,             1,               NUM_SAO_TYPE_IDX_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
82, m_cTransformSkipSCModel     ( 1,             2,               NUM_TRANSFORMSKIP_FLAG_CTX    , m_contextModels + m_numContextModels, m_numContextModels)
83, m_CUTransquantBypassFlagSCModel( 1,          1,               NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
84#if H_3D_DIM
85, m_cDepthIntraModeSCModel    ( 1,             1,               NUM_DEPTH_INTRA_MODE_CTX      , m_contextModels + m_numContextModels, m_numContextModels)
86, m_cDdcFlagSCModel           ( 1,             1,               NUM_DDC_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
87, m_cDdcDataSCModel           ( 1,             1,               NUM_DDC_DATA_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
88#if QC_GENERIC_SDC_G0122
89, m_cAngleFlagSCModel         ( 1,             1,               NUM_ANGLE_FLAG_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
90#if !QC_SDC_UNIFY_G0130
91, m_cIntraSdcFlagSCModel      ( 1,             1,               NUM_INTRASDC_FLAG_CTX         , m_contextModels + m_numContextModels, m_numContextModels)
92#endif
93#endif
94#if H_3D_DIM_DMM
95, m_cDmm1DataSCModel          ( 1,             1,               NUM_DMM1_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
96#endif
97#if H_3D_DIM_SDC
98, m_cSDCResidualFlagSCModel     ( 1,             1,             SDC_NUM_RESIDUAL_FLAG_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
99, m_cSDCResidualSCModel         ( 1,             1,             SDC_NUM_RESIDUAL_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
100#endif
101#endif
102#if H_3D_INTER_SDC && !QC_SDC_UNIFY_G0130
103, m_cInterSDCFlagSCModel             ( 1,             1,  NUM_INTER_SDC_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
104, m_cInterSDCResidualSCModel         ( 1,             1,  NUM_INTER_SDC_RESIDUAL_CTX       , m_contextModels + m_numContextModels, m_numContextModels)
105, m_cInterSDCResidualSignFlagSCModel ( 1,             1,  NUM_INTER_SDC_SIGN_FLAG_CTX      , m_contextModels + m_numContextModels, m_numContextModels)
106#endif
107#if QC_SDC_UNIFY_G0130
108, m_cSDCFlagSCModel                  ( 1,             1,  NUM_SDC_FLAG_CTX                 , m_contextModels + m_numContextModels, m_numContextModels)
109#endif
110#if H_3D_DBBP
111, m_cDBBPFlagSCModel             ( 1,             1,                 DBBP_NUM_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
112#endif
113{
114  assert( m_numContextModels <= MAX_NUM_CTX_MOD );
115}
116
117TDecSbac::~TDecSbac()
118{
119}
120
121// ====================================================================================================================
122// Public member functions
123// ====================================================================================================================
124
125Void TDecSbac::resetEntropy(TComSlice* pSlice)
126{
127  SliceType sliceType  = pSlice->getSliceType();
128  Int       qp         = pSlice->getSliceQp();
129
130  if (pSlice->getPPS()->getCabacInitPresentFlag() && pSlice->getCabacInitFlag())
131  {
132    switch (sliceType)
133    {
134    case P_SLICE:           // change initialization table to B_SLICE initialization
135      sliceType = B_SLICE; 
136      break;
137    case B_SLICE:           // change initialization table to P_SLICE initialization
138      sliceType = P_SLICE; 
139      break;
140    default     :           // should not occur
141      assert(0);
142    }
143  }
144
145  m_cCUSplitFlagSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_SPLIT_FLAG );
146  m_cCUSkipFlagSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SKIP_FLAG );
147  m_cCUMergeFlagExtSCModel.initBuffer    ( sliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT );
148  m_cCUMergeIdxExtSCModel.initBuffer     ( sliceType, qp, (UChar*)INIT_MERGE_IDX_EXT );
149#if H_3D_ARP
150  m_cCUPUARPWSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_ARPW );
151#endif
152#if H_3D_IC
153  m_cCUICFlagSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_IC_FLAG );
154#endif
155  m_cCUPartSizeSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_PART_SIZE );
156  m_cCUPredModeSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_PRED_MODE );
157  m_cCUIntraPredSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_INTRA_PRED_MODE );
158  m_cCUChromaPredSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE );
159  m_cCUInterDirSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_INTER_DIR );
160  m_cCUMvdSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_MVD );
161  m_cCURefPicSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_REF_PIC );
162  m_cCUDeltaQpSCModel.initBuffer         ( sliceType, qp, (UChar*)INIT_DQP );
163  m_cCUQtCbfSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_QT_CBF );
164  m_cCUQtRootCbfSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_QT_ROOT_CBF );
165  m_cCUSigCoeffGroupSCModel.initBuffer   ( sliceType, qp, (UChar*)INIT_SIG_CG_FLAG );
166  m_cCUSigSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_SIG_FLAG );
167  m_cCuCtxLastX.initBuffer               ( sliceType, qp, (UChar*)INIT_LAST );
168  m_cCuCtxLastY.initBuffer               ( sliceType, qp, (UChar*)INIT_LAST );
169  m_cCUOneSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_ONE_FLAG );
170  m_cCUAbsSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_ABS_FLAG );
171  m_cMVPIdxSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_MVP_IDX );
172  m_cSaoMergeSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG );
173  m_cSaoTypeIdxSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
174
175  m_cCUTransSubdivFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
176  m_cTransformSkipSCModel.initBuffer     ( sliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
177  m_CUTransquantBypassFlagSCModel.initBuffer( sliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
178#if H_3D_DIM
179  m_cDepthIntraModeSCModel.initBuffer    ( sliceType, qp, (UChar*)INIT_DEPTH_INTRA_MODE );
180  m_cDdcFlagSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DDC_FLAG );
181  m_cDdcDataSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DDC_DATA );
182#if QC_GENERIC_SDC_G0122
183  m_cAngleFlagSCModel.initBuffer         ( sliceType, qp, (UChar*)INIT_ANGLE_FLAG );
184#if !QC_SDC_UNIFY_G0130
185  m_cIntraSdcFlagSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_INTRASDC_FLAG );
186#endif
187#endif
188#if H_3D_DIM_DMM
189  m_cDmm1DataSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_DMM1_DATA );
190#endif
191#if H_3D_DIM_SDC
192  m_cSDCResidualFlagSCModel.initBuffer    ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
193  m_cSDCResidualSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL );
194#endif
195#endif
196#if H_3D_INTER_SDC && !QC_SDC_UNIFY_G0130
197  m_cInterSDCFlagSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_INTER_SDC_FLAG );
198  m_cInterSDCResidualSCModel.initBuffer   ( sliceType, qp, (UChar*)INIT_INTER_SDC_RESIDUAL );
199  m_cInterSDCResidualSignFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_INTER_SDC_SIGN_FLAG );
200#endif
201#if QC_SDC_UNIFY_G0130
202  m_cSDCFlagSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_SDC_FLAG );
203#endif
204#if H_3D_DBBP
205  m_cDBBPFlagSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_DBBP_FLAG );
206#endif
207  m_uiLastDQpNonZero  = 0;
208 
209  // new structure
210  m_uiLastQp          = qp;
211 
212  m_pcTDecBinIf->start();
213}
214
215/** The function does the following: Read out terminate bit. Flush CABAC. Byte-align for next tile.
216 *  Intialize CABAC states. Start CABAC.
217 */
218Void TDecSbac::updateContextTables( SliceType eSliceType, Int iQp )
219{
220  UInt uiBit;
221  m_pcTDecBinIf->decodeBinTrm(uiBit);
222  assert(uiBit); // end_of_sub_stream_one_bit must be equal to 1
223  m_pcTDecBinIf->finish(); 
224  m_pcBitstream->readOutTrailingBits();
225  m_cCUSplitFlagSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG );
226  m_cCUSkipFlagSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG );
227  m_cCUMergeFlagExtSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT );
228  m_cCUMergeIdxExtSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT );
229#if H_3D_ARP
230  m_cCUPUARPWSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_ARPW );
231#endif
232#if H_3D_IC
233  m_cCUICFlagSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_IC_FLAG );
234#endif
235  m_cCUPartSizeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PART_SIZE );
236  m_cCUPredModeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PRED_MODE );
237  m_cCUIntraPredSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE );
238  m_cCUChromaPredSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE );
239  m_cCUInterDirSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_INTER_DIR );
240  m_cCUMvdSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_MVD );
241  m_cCURefPicSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_REF_PIC );
242  m_cCUDeltaQpSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_DQP );
243  m_cCUQtCbfSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_QT_CBF );
244  m_cCUQtRootCbfSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF );
245  m_cCUSigCoeffGroupSCModel.initBuffer   ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG );
246  m_cCUSigSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG );
247  m_cCuCtxLastX.initBuffer               ( eSliceType, iQp, (UChar*)INIT_LAST );
248  m_cCuCtxLastY.initBuffer               ( eSliceType, iQp, (UChar*)INIT_LAST );
249  m_cCUOneSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG );
250  m_cCUAbsSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG );
251  m_cMVPIdxSCModel.initBuffer            ( eSliceType, iQp, (UChar*)INIT_MVP_IDX );
252  m_cSaoMergeSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG );
253  m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
254  m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
255  m_cTransformSkipSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
256  m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
257
258#if H_3D_DIM
259  m_cDepthIntraModeSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE );
260  m_cDdcFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG );
261  m_cDdcDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_DATA );
262#if QC_GENERIC_SDC_G0122
263  m_cAngleFlagSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_ANGLE_FLAG );
264#if !QC_SDC_UNIFY_G0130
265  m_cIntraSdcFlagSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_INTRASDC_FLAG );
266#endif
267#endif
268#if H_3D_DIM_DMM
269  m_cDmm1DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA );
270#endif
271#if H_3D_DIM_SDC
272  m_cSDCResidualFlagSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
273  m_cSDCResidualSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL );
274#endif
275#endif
276#if H_3D_INTER_SDC && !QC_SDC_UNIFY_G0130
277  m_cInterSDCFlagSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_INTER_SDC_FLAG );
278  m_cInterSDCResidualSCModel.initBuffer   ( eSliceType, iQp, (UChar*)INIT_INTER_SDC_RESIDUAL );
279  m_cInterSDCResidualSignFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_SDC_SIGN_FLAG );
280#endif
281#if QC_SDC_UNIFY_G0130
282  m_cSDCFlagSCModel.initBuffer            ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG );
283#endif
284#if H_3D_DBBP
285  m_cDBBPFlagSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_DBBP_FLAG );
286#endif
287  m_pcTDecBinIf->start();
288}
289
290Void TDecSbac::parseTerminatingBit( UInt& ruiBit )
291{
292  m_pcTDecBinIf->decodeBinTrm( ruiBit );
293  if ( ruiBit )
294  {
295    m_pcTDecBinIf->finish();
296  }
297}
298
299
300Void TDecSbac::xReadUnaryMaxSymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol )
301{
302  if (uiMaxSymbol == 0)
303  {
304    ruiSymbol = 0;
305    return;
306  }
307 
308  m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] );
309 
310  if( ruiSymbol == 0 || uiMaxSymbol == 1 )
311  {
312    return;
313  }
314 
315  UInt uiSymbol = 0;
316  UInt uiCont;
317 
318  do
319  {
320    m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] );
321    uiSymbol++;
322  }
323  while( uiCont && ( uiSymbol < uiMaxSymbol - 1 ) );
324 
325  if( uiCont && ( uiSymbol == uiMaxSymbol - 1 ) )
326  {
327    uiSymbol++;
328  }
329 
330  ruiSymbol = uiSymbol;
331}
332
333Void TDecSbac::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount )
334{
335  UInt uiSymbol = 0;
336  UInt uiBit = 1;
337 
338  while( uiBit )
339  {
340    m_pcTDecBinIf->decodeBinEP( uiBit );
341    uiSymbol += uiBit << uiCount++;
342  }
343 
344  if ( --uiCount )
345  {
346    UInt bins;
347    m_pcTDecBinIf->decodeBinsEP( bins, uiCount );
348    uiSymbol += bins;
349  }
350 
351  ruiSymbol = uiSymbol;
352}
353
354Void TDecSbac::xReadUnarySymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset )
355{
356  m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] );
357 
358  if( !ruiSymbol )
359  {
360    return;
361  }
362 
363  UInt uiSymbol = 0;
364  UInt uiCont;
365 
366  do
367  {
368    m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] );
369    uiSymbol++;
370  }
371  while( uiCont );
372 
373  ruiSymbol = uiSymbol;
374}
375
376
377/** Parsing of coeff_abs_level_remaing
378 * \param ruiSymbol reference to coeff_abs_level_remaing
379 * \param ruiParam reference to parameter
380 * \returns Void
381 */
382Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam )
383{
384
385  UInt prefix   = 0;
386  UInt codeWord = 0;
387  do
388  {
389    prefix++;
390    m_pcTDecBinIf->decodeBinEP( codeWord );
391  }
392  while( codeWord);
393  codeWord  = 1 - codeWord;
394  prefix -= codeWord;
395  codeWord=0;
396  if (prefix < COEF_REMAIN_BIN_REDUCTION )
397  {
398    m_pcTDecBinIf->decodeBinsEP(codeWord,rParam);
399    rSymbol = (prefix<<rParam) + codeWord;
400  }
401  else
402  {
403    m_pcTDecBinIf->decodeBinsEP(codeWord,prefix-COEF_REMAIN_BIN_REDUCTION+rParam);
404    rSymbol = (((1<<(prefix-COEF_REMAIN_BIN_REDUCTION))+COEF_REMAIN_BIN_REDUCTION-1)<<rParam)+codeWord;
405  }
406}
407
408#if H_3D_DIM
409Void TDecSbac::xReadExGolombLevel( UInt& ruiSymbol, ContextModel& rcSCModel  )
410{
411  UInt uiSymbol;
412  UInt uiCount = 0;
413  do
414  {
415    m_pcTDecBinIf->decodeBin( uiSymbol, rcSCModel );
416    uiCount++;
417  }
418  while( uiSymbol && ( uiCount != 13 ) );
419
420  ruiSymbol = uiCount - 1;
421
422  if( uiSymbol )
423  {
424    xReadEpExGolomb( uiSymbol, 0 );
425    ruiSymbol += uiSymbol + 1;
426  }
427
428  return;
429}
430
431Void TDecSbac::xParseDimDeltaDC( Pel& rValDeltaDC, UInt uiNumSeg )
432{
433  UInt absValDeltaDC = 0;
434  xReadExGolombLevel( absValDeltaDC, m_cDdcDataSCModel.get(0, 0, 0) );
435  rValDeltaDC = (Pel)absValDeltaDC + ( uiNumSeg > 1 ? 0 : 1 );
436
437  if( rValDeltaDC != 0 )
438  {
439    UInt uiSign;
440    m_pcTDecBinIf->decodeBinEP( uiSign );
441    if ( uiSign )
442    {
443      rValDeltaDC = -rValDeltaDC;
444    }
445  }
446}
447
448
449#if H_3D_DIM_DMM
450Void TDecSbac::xParseDmm1WedgeIdx( UInt& ruiTabIdx, Int iNumBit )
451{
452  UInt uiSymbol, uiIdx = 0;
453  for( Int i = 0; i < iNumBit; i++ )
454  {
455    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmm1DataSCModel.get(0, 0, 0) );
456    uiIdx += uiSymbol << i;
457  }
458  ruiTabIdx = uiIdx;
459}
460#endif
461
462#if H_3D_DIM_SDC
463Void TDecSbac::xParseSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSegment )
464{
465  assert( pcCU->getSlice()->getIsDepth() );
466  assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
467  assert( pcCU->getSDCFlag(uiAbsPartIdx) );
468  assert( uiSegment < 2 );
469 
470  UInt uiResidual = 0;
471  UInt uiBit      = 0;
472  UInt uiAbsIdx   = 0;
473  UInt uiSign     = 0;
474  Int  iIdx       = 0;
475 
476#if H_3D_DIM_DLT
477  UInt uiMaxResidualBits = pcCU->getSlice()->getPPS()->getDLT()->getBitsPerDepthValue( pcCU->getSlice()->getLayerIdInVps() );
478#else
479  UInt uiMaxResidualBits = g_bitDepthY;
480#endif
481  assert( uiMaxResidualBits <= g_bitDepthY );
482 
483  m_pcTDecBinIf->decodeBin(uiResidual, m_cSDCResidualFlagSCModel.get( 0, 0, 0 ) );
484 
485#if H_MV_ENC_DEC_TRAC
486  DTRACE_CU("sdc_residual_flag[i]", uiResidual)
487#endif
488 
489  if (uiResidual)
490  {
491    // decode residual sign bit
492    m_pcTDecBinIf->decodeBinEP(uiSign);
493#if H_MV_ENC_DEC_TRAC
494    DTRACE_CU("sdc_residual_sign_flag[i]", uiSign)
495#endif
496   
497    // decode residual magnitude
498    // prefix part
499    UInt uiCount = 0;
500#if H_3D_DIM_DLT
501    UInt uiNumDepthValues = pcCU->getSlice()->getPPS()->getDLT()->getNumDepthValues( pcCU->getSlice()->getLayerIdInVps() );
502#else
503    UInt uiNumDepthValues = ((1 << g_bitDepthY)-1);
504#endif
505    UInt uiPrefixThreshold = ((uiNumDepthValues * 3) >> 2);
506    for ( UInt ui = 0; ui < uiPrefixThreshold; ui++)
507    {
508      m_pcTDecBinIf->decodeBin( uiBit, m_cSDCResidualSCModel.get(0, 0, 0) );
509      if ( uiBit == 0 )
510        break;
511      else
512        uiCount++;
513    }
514    // suffix part
515    if ( uiCount == uiPrefixThreshold )
516    {
517      for ( UInt ui = 0; ui < numBitsForValue(uiNumDepthValues - uiPrefixThreshold); ui++ )
518      {
519        m_pcTDecBinIf->decodeBinEP( uiBit );
520        uiAbsIdx |= uiBit << ui;
521      }
522      uiAbsIdx += uiCount;
523    }
524    else
525    {
526      uiAbsIdx = uiCount;
527    }
528 
529#if H_MV_ENC_DEC_TRAC
530    DTRACE_CU("sdc_residual_abs_minus1[i]", uiAbsIdx)
531#endif
532   
533    uiAbsIdx += 1;
534    iIdx =(Int)(uiSign ? -1 : 1)*uiAbsIdx;
535  }
536 
537  pcCU->setSDCSegmentDCOffset(iIdx, uiSegment, uiAbsPartIdx);
538}
539#endif
540#endif
541
542/** Parse I_PCM information.
543 * \param pcCU
544 * \param uiAbsPartIdx
545 * \param uiDepth
546 * \returns Void
547 *
548 * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes.
549 */
550Void TDecSbac::parseIPCMInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
551{
552  UInt uiSymbol;
553
554    m_pcTDecBinIf->decodeBinTrm(uiSymbol);
555
556#if H_MV_ENC_DEC_TRAC
557      DTRACE_CU("pcm_flag", uiSymbol)
558#endif
559    if (uiSymbol)
560    {
561    Bool bIpcmFlag = true;
562
563    pcCU->setPartSizeSubParts  ( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
564    pcCU->setSizeSubParts      ( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
565    pcCU->setTrIdxSubParts     ( 0, uiAbsPartIdx, uiDepth );
566    pcCU->setIPCMFlagSubParts  ( bIpcmFlag, uiAbsPartIdx, uiDepth );
567
568    UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
569    UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
570    UInt uiChromaOffset = uiLumaOffset>>2;
571
572    Pel* piPCMSample;
573    UInt uiWidth;
574    UInt uiHeight;
575    UInt uiSampleBits;
576    UInt uiX, uiY;
577
578    piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset;
579    uiWidth = pcCU->getWidth(uiAbsPartIdx);
580    uiHeight = pcCU->getHeight(uiAbsPartIdx);
581    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
582
583    for(uiY = 0; uiY < uiHeight; uiY++)
584    {
585      for(uiX = 0; uiX < uiWidth; uiX++)
586      {
587        UInt uiSample;
588        m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
589        piPCMSample[uiX] = uiSample;
590      }
591      piPCMSample += uiWidth;
592    }
593
594    piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset;
595    uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
596    uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
597    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
598
599    for(uiY = 0; uiY < uiHeight; uiY++)
600    {
601      for(uiX = 0; uiX < uiWidth; uiX++)
602      {
603        UInt uiSample;
604        m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
605        piPCMSample[uiX] = uiSample;
606      }
607      piPCMSample += uiWidth;
608    }
609
610    piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset;
611    uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
612    uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
613    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
614
615    for(uiY = 0; uiY < uiHeight; uiY++)
616    {
617      for(uiX = 0; uiX < uiWidth; uiX++)
618      {
619        UInt uiSample;
620        m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
621        piPCMSample[uiX] = uiSample;
622      }
623      piPCMSample += uiWidth;
624    }
625
626    m_pcTDecBinIf->start();
627  }
628}
629
630Void TDecSbac::parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
631{
632  UInt uiSymbol;
633  m_pcTDecBinIf->decodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) );
634#if H_MV_ENC_DEC_TRAC
635  DTRACE_CU("cu_transquant_bypass_flag", uiSymbol); 
636#endif
637  pcCU->setCUTransquantBypassSubParts(uiSymbol ? true : false, uiAbsPartIdx, uiDepth);
638}
639
640/** parse skip flag
641 * \param pcCU
642 * \param uiAbsPartIdx
643 * \param uiDepth
644 * \returns Void
645 */
646Void TDecSbac::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
647{
648  if( pcCU->getSlice()->isIntra() )
649  {
650    return;
651  }
652 
653  UInt uiSymbol = 0;
654  UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx );
655  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) );
656#if !H_MV_ENC_DEC_TRAC
657  DTRACE_CABAC_VL( g_nSymbolCounter++ );
658  DTRACE_CABAC_T( "\tSkipFlag" );
659  DTRACE_CABAC_T( "\tuiCtxSkip: ");
660  DTRACE_CABAC_V( uiCtxSkip );
661  DTRACE_CABAC_T( "\tuiSymbol: ");
662  DTRACE_CABAC_V( uiSymbol );
663  DTRACE_CABAC_T( "\n");
664#endif
665 
666  if( uiSymbol )
667  {
668    pcCU->setSkipFlagSubParts( true,        uiAbsPartIdx, uiDepth );
669    pcCU->setPredModeSubParts( MODE_INTER,  uiAbsPartIdx, uiDepth );
670    pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
671    pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
672    pcCU->setMergeFlagSubParts( true , uiAbsPartIdx, 0, uiDepth );
673  }
674#if H_MV_ENC_DEC_TRAC
675  DTRACE_CU("cu_skip_flag", uiSymbol); 
676#endif
677}
678
679/** parse merge flag
680 * \param pcCU
681 * \param uiAbsPartIdx
682 * \param uiDepth
683 * \param uiPUIdx
684 * \returns Void
685 */
686Void TDecSbac::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
687{
688  UInt uiSymbol;
689  m_pcTDecBinIf->decodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) );
690#if H_MV_ENC_DEC_TRAC
691  DTRACE_PU("merge_flag", uiSymbol)
692#endif
693  pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth );
694
695#if !H_MV_ENC_DEC_TRAC
696  DTRACE_CABAC_VL( g_nSymbolCounter++ );
697  DTRACE_CABAC_T( "\tMergeFlag: " );
698  DTRACE_CABAC_V( uiSymbol );
699  DTRACE_CABAC_T( "\tAddress: " );
700  DTRACE_CABAC_V( pcCU->getAddr() );
701  DTRACE_CABAC_T( "\tuiAbsPartIdx: " );
702  DTRACE_CABAC_V( uiAbsPartIdx );
703  DTRACE_CABAC_T( "\n" );
704#endif
705}
706
707Void TDecSbac::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex )
708{
709  UInt uiUnaryIdx = 0;
710  UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand();
711  if ( uiNumCand > 1 )
712  {
713    for( ; uiUnaryIdx < uiNumCand - 1; ++uiUnaryIdx )
714    {
715      UInt uiSymbol = 0;
716      if ( uiUnaryIdx==0 )
717      {
718        m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) );
719      }
720      else
721      {
722        m_pcTDecBinIf->decodeBinEP( uiSymbol );
723      }
724      if( uiSymbol == 0 )
725      {
726        break;
727      }
728    }
729#if H_MV_ENC_DEC_TRAC
730    DTRACE_PU("merge_idx", uiUnaryIdx)
731#endif
732  }
733  ruiMergeIndex = uiUnaryIdx;
734
735#if !H_MV_ENC_DEC_TRAC
736  DTRACE_CABAC_VL( g_nSymbolCounter++ )
737  DTRACE_CABAC_T( "\tparseMergeIndex()" )
738  DTRACE_CABAC_T( "\tuiMRGIdx= " )
739  DTRACE_CABAC_V( ruiMergeIndex )
740  DTRACE_CABAC_T( "\n" )
741#endif
742}
743
744Void TDecSbac::parseMVPIdx      ( Int& riMVPIdx )
745{
746  UInt uiSymbol;
747  xReadUnaryMaxSymbol(uiSymbol, m_cMVPIdxSCModel.get(0), 1, AMVP_MAX_NUM_CANDS-1);
748  riMVPIdx = uiSymbol;
749}
750
751Void TDecSbac::parseSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
752{
753  if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
754  {
755    pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx );
756    return;
757  }
758
759  UInt uiSymbol;
760#if H_3D_QTLPC
761  Bool bParseSplitFlag    = true;
762
763  TComSPS *sps            = pcCU->getPic()->getSlice(0)->getSPS();
764  TComPic *pcTexture      = pcCU->getSlice()->getTexturePic();
765  Bool bDepthMapDetect    = (pcTexture != NULL);
766  Bool bIntraSliceDetect  = (pcCU->getSlice()->getSliceType() == I_SLICE);
767
768  Bool rapPic = (pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA);
769
770  if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTL() && sps->getUsePC())
771  {
772    TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr());
773    assert(pcTextureCU->getDepth(uiAbsPartIdx) >= uiDepth);
774    bParseSplitFlag         = (pcTextureCU->getDepth(uiAbsPartIdx) > uiDepth);
775  }
776
777  if(bParseSplitFlag)
778  {
779#endif
780    m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSplitFlagSCModel.get( 0, 0, pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ) ) );
781#if H_MV_ENC_DEC_TRAC
782    DTRACE_CU("split_cu_flag", uiSymbol); 
783#else
784    DTRACE_CABAC_VL( g_nSymbolCounter++ )
785    DTRACE_CABAC_T( "\tSplitFlag\n" )
786#endif
787#if H_3D_QTLPC
788  }
789  else
790  {
791    uiSymbol = 0;
792  }
793#endif
794  pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx );
795 
796  return;
797}
798
799/** parse partition size
800 * \param pcCU
801 * \param uiAbsPartIdx
802 * \param uiDepth
803 * \returns Void
804 */
805Void TDecSbac::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
806{
807  UInt uiSymbol, uiMode = 0;
808  PartSize eMode;
809
810#if H_3D_QTLPC
811  Bool bParsePartSize    = true;
812  TComSPS *sps           = pcCU->getPic()->getSlice(0)->getSPS();
813  TComPic *pcTexture     = pcCU->getSlice()->getTexturePic();
814  Bool bDepthMapDetect   = (pcTexture != NULL);
815  Bool bIntraSliceDetect = (pcCU->getSlice()->getSliceType() == I_SLICE);
816
817  Bool rapPic     = (pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA);
818
819#if MTK_TEX_DEP_PAR_G0055
820  Bool depthDependent = false;
821  UInt uiTexturePart = uiMode;
822#endif
823  if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTL() && sps->getUsePC())
824  {
825    TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr());
826    assert(pcTextureCU->getDepth(uiAbsPartIdx) >= uiDepth);
827#if !MTK_TEX_DEP_PAR_G0055
828    if (pcTextureCU->getDepth(uiAbsPartIdx) == uiDepth && pcTextureCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN)
829#else
830    if(pcTextureCU->getDepth(uiAbsPartIdx) == uiDepth )
831    {
832      depthDependent = true;
833      uiTexturePart = pcTextureCU->getPartitionSize( uiAbsPartIdx );
834    }
835    if (pcTextureCU->getDepth(uiAbsPartIdx) == uiDepth && pcTextureCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N)
836#endif
837    {
838      bParsePartSize = false;
839      eMode          = SIZE_2Nx2N;
840    }
841  }
842#endif
843
844 
845  if ( pcCU->isIntra( uiAbsPartIdx ) )
846  {
847#if H_3D_QTLPC
848    if(bParsePartSize)
849    {
850#endif
851     uiSymbol = 1;
852      if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
853      {
854        m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 0) );
855#if H_MV_ENC_DEC_TRAC         
856        DTRACE_CU("part_mode", uiSymbol)
857#endif       
858      }
859      eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN;
860#if H_3D_QTLPC
861    }
862#endif
863    UInt uiTrLevel = 0;   
864    UInt uiWidthInBit  = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2;
865    UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2;
866    uiTrLevel          = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0;
867    if( eMode == SIZE_NxN )
868    {
869      pcCU->setTrIdxSubParts( 1+uiTrLevel, uiAbsPartIdx, uiDepth );
870    }
871    else
872    {
873      pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth );
874    }
875  }
876  else
877  {
878#if H_3D_QTLPC
879    if(bParsePartSize)
880    {
881#endif
882#if MTK_TEX_DEP_PAR_G0055
883      if (depthDependent==false || uiTexturePart == SIZE_NxN|| uiTexturePart == SIZE_2Nx2N)
884      {
885#endif
886      UInt uiMaxNumBits = 2;
887      if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( (g_uiMaxCUWidth>>uiDepth) == 8 && (g_uiMaxCUHeight>>uiDepth) == 8 ) )
888      {
889        uiMaxNumBits ++;
890      }
891      for ( UInt ui = 0; ui < uiMaxNumBits; ui++ )
892      {
893        m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) );
894        if ( uiSymbol )
895        {
896          break;
897        }
898        uiMode++;
899      }
900      eMode = (PartSize) uiMode;
901      if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) )
902      {
903        if (eMode == SIZE_2NxN)
904        {
905        m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
906          if (uiSymbol == 0)
907          {
908            m_pcTDecBinIf->decodeBinEP(uiSymbol);
909            eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD);
910          }
911        }
912        else if (eMode == SIZE_Nx2N)
913        {
914        m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
915          if (uiSymbol == 0)
916          {
917            m_pcTDecBinIf->decodeBinEP(uiSymbol);
918            eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N);
919          }
920        }
921      }
922#if MTK_TEX_DEP_PAR_G0055
923      }
924      else if(uiTexturePart == SIZE_2NxN || uiTexturePart == SIZE_2NxnU || uiTexturePart == SIZE_2NxnD)
925      {
926        UInt uiMaxNumBits = 1;
927        if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) )
928        {
929          uiMaxNumBits ++;
930        }
931        for ( UInt ui = 0; ui < uiMaxNumBits; ui++ )
932        {
933          m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) );
934          if ( uiSymbol )
935          {
936            break;
937          }
938          uiMode++;
939        }
940        eMode = (PartSize) uiMode;
941        if(uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) && uiSymbol==1 )
942        {
943          eMode = SIZE_2NxN;
944        }
945        else if (uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth )==0  && uiSymbol==0)
946        {
947          eMode = SIZE_2NxN;
948        }
949        else if (uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) && uiSymbol==0)
950        {
951          m_pcTDecBinIf->decodeBinEP(uiSymbol);
952          eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD);
953        }
954      }
955      else if(uiTexturePart == SIZE_Nx2N|| uiTexturePart==SIZE_nLx2N || uiTexturePart==SIZE_nRx2N)
956      {
957        UInt uiMaxNumBits = 1;
958        if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) )
959        {
960          uiMaxNumBits ++;
961        }
962        for ( UInt ui = 0; ui < uiMaxNumBits; ui++ )
963        {
964          m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) );
965          if ( uiSymbol )
966          {
967            break;
968          }
969          uiMode++;
970        }
971        eMode = (PartSize) uiMode;
972        if(uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) && uiSymbol==1 )
973        {
974          eMode = SIZE_Nx2N;
975        }
976        else if (uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth )==0  && uiSymbol==0)
977        {
978          eMode = SIZE_Nx2N;
979        }
980        else if (uiMode && pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) && uiSymbol==0)
981        {
982          m_pcTDecBinIf->decodeBinEP(uiSymbol);
983          eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N);
984        }
985      }
986      else
987        assert(0);
988#endif
989#if H_MV_ENC_DEC_TRAC         
990      DTRACE_CU("part_mode", eMode )
991#endif
992#if H_3D_QTLPC
993    }
994#endif
995  }
996  pcCU->setPartSizeSubParts( eMode, uiAbsPartIdx, uiDepth );
997  pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
998}
999
1000/** parse prediction mode
1001 * \param pcCU
1002 * \param uiAbsPartIdx
1003 * \param uiDepth
1004 * \returns Void
1005 */
1006Void TDecSbac::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1007{
1008  if( pcCU->getSlice()->isIntra() )
1009  {
1010    pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth );
1011    return;
1012  }
1013 
1014  UInt uiSymbol;
1015  Int  iPredMode = MODE_INTER;
1016  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPredModeSCModel.get( 0, 0, 0 ) );
1017  iPredMode += uiSymbol;
1018#if H_MV_ENC_DEC_TRAC         
1019  DTRACE_CU("pred_mode_flag", uiSymbol)
1020#endif       
1021  pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth );
1022}
1023
1024Void TDecSbac::parseIntraDirLumaAng  ( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
1025{
1026  PartSize mode = pcCU->getPartitionSize( absPartIdx );
1027  UInt partNum = mode==SIZE_NxN?4:1;
1028  UInt partOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2;
1029  UInt mpmPred[4],symbol;
1030  Int j,intraPredMode;   
1031  if (mode==SIZE_NxN)
1032  {
1033    depth++;
1034  }
1035  for (j=0;j<partNum;j++)
1036  {
1037#if H_3D_DIM
1038    if( pcCU->getSlice()->getVpsDepthModesFlag() )
1039    {
1040      parseIntraDepth( pcCU, absPartIdx+partOffset*j, depth );
1041    }
1042    if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
1043#if H_3D_DIM_SDC
1044#if QC_GENERIC_SDC_G0122
1045      if( 1 ) // This should be cleaned up.
1046#else
1047      if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) )
1048#endif
1049#endif
1050    {
1051#endif
1052    m_pcTDecBinIf->decodeBin( symbol, m_cCUIntraPredSCModel.get( 0, 0, 0) );
1053    mpmPred[j] = symbol;
1054#if H_MV_ENC_DEC_TRAC         
1055    DTRACE_CU("prev_intra_luma_pred_flag", symbol)
1056#endif
1057#if H_3D_DIM
1058    }
1059#endif
1060  }
1061  for (j=0;j<partNum;j++)
1062  {
1063#if H_3D_DIM
1064    if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
1065#if H_3D_DIM_SDC
1066#if QC_GENERIC_SDC_G0122
1067      if( 1 )  // This should be cleaned up.
1068#else
1069      if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) )
1070#endif
1071#endif
1072    {
1073#endif
1074    Int preds[3] = {-1, -1, -1};
1075    Int predNum = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds); 
1076    if (mpmPred[j])
1077    {
1078      m_pcTDecBinIf->decodeBinEP( symbol );
1079      if (symbol)
1080      {
1081        m_pcTDecBinIf->decodeBinEP( symbol );
1082        symbol++;
1083      }
1084#if H_MV_ENC_DEC_TRAC         
1085      DTRACE_CU("mpm_idx", symbol)
1086#endif
1087      intraPredMode = preds[symbol];
1088    }
1089    else
1090    {
1091      m_pcTDecBinIf->decodeBinsEP( symbol, 5 );
1092      intraPredMode = symbol;
1093#if H_MV_ENC_DEC_TRAC         
1094      DTRACE_CU("rem_intra_luma_pred_mode", symbol)
1095#endif       
1096      //postponed sorting of MPMs (only in remaining branch)
1097      if (preds[0] > preds[1])
1098      { 
1099        std::swap(preds[0], preds[1]); 
1100      }
1101      if (preds[0] > preds[2])
1102      {
1103        std::swap(preds[0], preds[2]);
1104      }
1105      if (preds[1] > preds[2])
1106      {
1107        std::swap(preds[1], preds[2]);
1108      }
1109      for ( Int i = 0; i < predNum; i++ )
1110      {
1111        intraPredMode += ( intraPredMode >= preds[i] );
1112      }
1113    }
1114    pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, absPartIdx+partOffset*j, depth );
1115#if H_3D_DIM
1116    }
1117#endif
1118  }
1119}
1120
1121Void TDecSbac::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1122{
1123  UInt uiSymbol;
1124
1125  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) );
1126
1127  if( uiSymbol == 0 )
1128  {
1129#if H_MV_ENC_DEC_TRAC         
1130    DTRACE_CU("intra_chroma_pred_mode", uiSymbol )
1131#endif       
1132    uiSymbol = DM_CHROMA_IDX;
1133  } 
1134  else 
1135  {
1136    {
1137      UInt uiIPredMode;
1138      m_pcTDecBinIf->decodeBinsEP( uiIPredMode, 2 );
1139#if H_MV_ENC_DEC_TRAC         
1140      DTRACE_CU("intra_chroma_pred_mode", uiIPredMode )
1141#endif       
1142      UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ];
1143      pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir );
1144      uiSymbol = uiAllowedChromaDir[ uiIPredMode ];
1145    }
1146  }
1147  pcCU->setChromIntraDirSubParts( uiSymbol, uiAbsPartIdx, uiDepth );
1148  return;
1149}
1150
1151#if H_3D_DIM
1152Void TDecSbac::parseIntraDepth( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
1153{
1154  parseIntraDepthMode( pcCU, absPartIdx, depth );
1155
1156  UInt dir     = pcCU->getLumaIntraDir( absPartIdx );
1157  UInt dimType = getDimType( dir );
1158
1159  switch( dimType )
1160  {
1161#if H_3D_DIM_DMM
1162  case( DMM1_IDX ):
1163    {
1164      UInt uiTabIdx = 0;
1165      xParseDmm1WedgeIdx( uiTabIdx, g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] );
1166      pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, absPartIdx, depth );
1167    } break;
1168  case( DMM4_IDX ): break;
1169#endif
1170  default: break;
1171  }
1172
1173#if !QC_SDC_UNIFY_G0130
1174  if( dimType < DIM_NUM_TYPE || pcCU->getSDCFlag( absPartIdx ) )
1175  {
1176    UInt symbol;
1177#if QC_GENERIC_SDC_G0122
1178    UInt uiNumSegments = isDimMode( dir ) ? 2 : 1;
1179#else
1180    UInt uiNumSegments = ( dir == PLANAR_IDX ) ? 1 : 2;
1181#endif
1182
1183    if( pcCU->getSDCFlag( absPartIdx ) )
1184    {
1185      assert(pcCU->getPartitionSize(absPartIdx)==SIZE_2Nx2N);
1186      pcCU->setTrIdxSubParts(0, absPartIdx, depth);
1187      pcCU->setCbfSubParts(1, 1, 1, absPartIdx, depth);
1188    }
1189
1190    m_pcTDecBinIf->decodeBin( symbol, m_cDdcFlagSCModel.get(0, 0, uiNumSegments-1) );
1191
1192    if( symbol )
1193    {
1194      if( !pcCU->getSDCFlag( absPartIdx ) )
1195      {
1196        dir += symbol;
1197      }
1198    }
1199    for( UInt segment = 0; segment < uiNumSegments; segment++ )
1200    {
1201      Pel valDeltaDC = 0;
1202      if( symbol )
1203      {
1204        xParseDimDeltaDC( valDeltaDC, uiNumSegments );
1205      }
1206
1207      if( pcCU->getSDCFlag( absPartIdx ) )
1208      {
1209        pcCU->setSDCSegmentDCOffset( valDeltaDC, segment, absPartIdx );
1210      }
1211      else
1212      {
1213        pcCU->setDimDeltaDC( dimType, segment, absPartIdx, valDeltaDC );
1214      }
1215    }
1216  }
1217#endif
1218  pcCU->setLumaIntraDirSubParts( (UChar)dir, absPartIdx, depth );
1219}
1220
1221#if QC_GENERIC_SDC_G0122
1222Void TDecSbac::parseIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
1223{
1224  UInt uiSymbol, uiIsDimMode;
1225
1226  if( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() >> pcCU->getDepth( absPartIdx ) ) < 64 ) //DMM and HEVC intra modes are both allowed
1227  {
1228    m_pcTDecBinIf->decodeBin( uiSymbol, m_cAngleFlagSCModel.get( 0, 0, pcCU->getCtxAngleFlag( absPartIdx ) ) );
1229  }
1230  else
1231  {
1232    uiSymbol = 1;
1233  }
1234  uiIsDimMode = uiSymbol ? 0 : 1;
1235  pcCU->setLumaIntraDirSubParts( 0, absPartIdx, depth );
1236#if !QC_SDC_UNIFY_G0130
1237  if( pcCU->getPartitionSize( absPartIdx ) == SIZE_2Nx2N ) //SDC is allowed only in this case
1238  {
1239    m_pcTDecBinIf->decodeBin( uiSymbol, m_cIntraSdcFlagSCModel.get( 0, 0, pcCU->getCtxSDCFlag( absPartIdx ) ) );
1240  }
1241  else
1242  {
1243    uiSymbol = 0;
1244  }
1245
1246  pcCU->setSDCFlagSubParts( uiSymbol, absPartIdx, depth );
1247#endif
1248  //decode DMM index
1249  if( uiIsDimMode )
1250  {
1251    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDepthIntraModeSCModel.get( 0, 0, 0 ) );
1252    if( !uiSymbol )
1253    {
1254      pcCU->setLumaIntraDirSubParts( ( 2 * DMM1_IDX + DIM_OFFSET ), absPartIdx, depth );
1255    }
1256    else
1257    {
1258      pcCU->setLumaIntraDirSubParts( ( 2 * DMM4_IDX + DIM_OFFSET ), absPartIdx, depth );
1259    }
1260  }
1261}
1262#else
1263Void TDecSbac::parseIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
1264{
1265  UInt puIdx = (pcCU->getWidth(absPartIdx) == 64) ? 2 : ( (pcCU->getPartitionSize(absPartIdx) == SIZE_NxN && pcCU->getWidth(absPartIdx) == 8) ? 0 : 1 );
1266  UInt dir = 0;
1267  Bool sdcFlag = 0;
1268  UInt symbol = 1;
1269  UInt modeCode = 0 ;
1270  UInt binNum = 0;
1271  UInt ctxDepthMode = 0;
1272
1273  if( puIdx == 2 )
1274  {
1275    {
1276      ctxDepthMode = puIdx*3 + binNum;
1277      m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
1278      modeCode = (modeCode<<1) + symbol;
1279      binNum++;
1280    }
1281         if( modeCode == 0 ) { dir = PLANAR_IDX; sdcFlag = 1;}
1282    else if( modeCode == 1 ) { dir = 0;          sdcFlag = 0;}
1283  }
1284  else if( puIdx == 0 )
1285  {
1286    while( binNum < 1 && symbol )
1287    {
1288      ctxDepthMode = puIdx*3 + ((binNum >= 2) ? 2 : binNum);
1289      m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
1290      modeCode = (modeCode<<1) + symbol;
1291      binNum++;
1292    }
1293    if( modeCode == 0 ) 
1294    { 
1295      dir = 0;
1296      sdcFlag = 0;
1297    }
1298    else if ( modeCode == 1 ) 
1299    { 
1300      dir = (2*DMM1_IDX+DIM_OFFSET); 
1301      sdcFlag = 0;
1302    }
1303  }
1304  else
1305  {
1306    while( binNum < 4 && symbol )
1307    {
1308      ctxDepthMode = puIdx*3 + ((binNum >= 2) ? 2 : binNum);
1309      m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
1310      modeCode = (modeCode<<1) + symbol;
1311      binNum++;
1312    }
1313    if ( modeCode == 0 )        { dir =  PLANAR_IDX;             sdcFlag = 1;}
1314    else if ( modeCode == 2 )   { dir = 5;                       sdcFlag = 0;}
1315    else if ( modeCode == 6 )   { dir = (2*DMM1_IDX+DIM_OFFSET); sdcFlag = 1;}
1316    else if ( modeCode == 14 )  { dir = (2*DMM1_IDX+DIM_OFFSET); sdcFlag = 0;}
1317    else if ( modeCode == 15 )  { dir = (2*DMM4_IDX+DIM_OFFSET); sdcFlag = 0;}
1318
1319  }
1320  pcCU->setLumaIntraDirSubParts( (UChar)dir, absPartIdx, depth );
1321#if H_3D_DIM_SDC
1322  pcCU->setSDCFlagSubParts( sdcFlag, absPartIdx, depth ); 
1323#endif
1324}
1325#endif
1326#endif
1327
1328Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx )
1329{
1330  UInt uiSymbol;
1331  const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx );
1332  ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 );
1333  uiSymbol = 0;
1334  if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 )
1335  {
1336    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) );
1337  }
1338
1339  if( uiSymbol )
1340  {
1341    uiSymbol = 2;
1342  }
1343  else
1344  {
1345    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + 4 ) );
1346    assert(uiSymbol == 0 || uiSymbol == 1);
1347  }
1348
1349  uiSymbol++;
1350  ruiInterDir = uiSymbol;
1351#if H_MV_ENC_DEC_TRAC
1352    DTRACE_PU("inter_pred_idc", ruiInterDir - 1 )   
1353#endif
1354
1355  return;
1356}
1357
1358Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList )
1359{
1360  UInt uiSymbol;
1361  {
1362    ContextModel *pCtx = m_cCURefPicSCModel.get( 0 );
1363    m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1364
1365    if( uiSymbol )
1366    {
1367      UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2;
1368      pCtx++;
1369      UInt ui;
1370      for( ui = 0; ui < uiRefNum; ++ui )
1371      {
1372        if( ui == 0 )
1373        {
1374          m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1375        }
1376        else
1377        {
1378          m_pcTDecBinIf->decodeBinEP( uiSymbol );
1379        }
1380        if( uiSymbol == 0 )
1381        {
1382          break;
1383        }
1384      }
1385      uiSymbol = ui + 1;
1386    }
1387    riRefFrmIdx = uiSymbol;
1388  }
1389
1390#if H_MV_ENC_DEC_TRAC
1391#if ENC_DEC_TRACE
1392  if ( eRefList == REF_PIC_LIST_0 )
1393  {
1394    DTRACE_PU("ref_idx_l0", uiSymbol)
1395  }
1396  else
1397  {
1398    DTRACE_PU("ref_idx_l1", uiSymbol)
1399  }
1400#endif
1401#endif
1402  return;
1403}
1404
1405Void TDecSbac::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList )
1406{
1407  UInt uiSymbol;
1408  UInt uiHorAbs;
1409  UInt uiVerAbs;
1410  UInt uiHorSign = 0;
1411  UInt uiVerSign = 0;
1412  ContextModel *pCtx = m_cCUMvdSCModel.get( 0 );
1413
1414  if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3)
1415  {
1416    uiHorAbs=0;
1417    uiVerAbs=0;
1418  }
1419  else
1420  {
1421    m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx );
1422    m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx );
1423
1424    const Bool bHorAbsGr0 = uiHorAbs != 0;
1425    const Bool bVerAbsGr0 = uiVerAbs != 0;
1426    pCtx++;
1427
1428    if( bHorAbsGr0 )
1429    {
1430      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1431      uiHorAbs += uiSymbol;
1432    }
1433
1434    if( bVerAbsGr0 )
1435    {
1436      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
1437      uiVerAbs += uiSymbol;
1438    }
1439
1440    if( bHorAbsGr0 )
1441    {
1442      if( 2 == uiHorAbs )
1443      {
1444        xReadEpExGolomb( uiSymbol, 1 );
1445        uiHorAbs += uiSymbol;
1446      }
1447
1448      m_pcTDecBinIf->decodeBinEP( uiHorSign );
1449    }
1450
1451    if( bVerAbsGr0 )
1452    {
1453      if( 2 == uiVerAbs )
1454      {
1455        xReadEpExGolomb( uiSymbol, 1 );
1456        uiVerAbs += uiSymbol;
1457      }
1458
1459      m_pcTDecBinIf->decodeBinEP( uiVerSign );
1460    }
1461
1462  }
1463
1464  const TComMv cMv( uiHorSign ? -Int( uiHorAbs ): uiHorAbs, uiVerSign ? -Int( uiVerAbs ) : uiVerAbs );
1465  pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiDepth, uiPartIdx );
1466  return;
1467}
1468
1469
1470Void TDecSbac::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize )
1471{
1472  m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize ) );
1473#if !H_MV_ENC_DEC_TRAC
1474  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1475  DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" )
1476  DTRACE_CABAC_T( "\tsymbol=" )
1477  DTRACE_CABAC_V( ruiSubdivFlag )
1478  DTRACE_CABAC_T( "\tctx=" )
1479  DTRACE_CABAC_V( uiLog2TransformBlockSize )
1480  DTRACE_CABAC_T( "\n" )
1481#endif
1482}
1483
1484Void TDecSbac::parseQtRootCbf( UInt uiAbsPartIdx, UInt& uiQtRootCbf )
1485{
1486  UInt uiSymbol;
1487  const UInt uiCtx = 0;
1488  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) );
1489#if !H_MV_ENC_DEC_TRAC
1490  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1491  DTRACE_CABAC_T( "\tparseQtRootCbf()" )
1492  DTRACE_CABAC_T( "\tsymbol=" )
1493  DTRACE_CABAC_V( uiSymbol )
1494  DTRACE_CABAC_T( "\tctx=" )
1495  DTRACE_CABAC_V( uiCtx )
1496  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1497  DTRACE_CABAC_V( uiAbsPartIdx )
1498  DTRACE_CABAC_T( "\n" )
1499#else
1500  DTRACE_CU( "rqt_root_cbf", uiSymbol )
1501#endif
1502 
1503  uiQtRootCbf = uiSymbol;
1504}
1505
1506Void TDecSbac::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1507{
1508  Int qp;
1509  UInt uiDQp;
1510  Int  iDQp;
1511 
1512  UInt uiSymbol;
1513
1514  xReadUnaryMaxSymbol (uiDQp,  &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX);
1515
1516  if( uiDQp >= CU_DQP_TU_CMAX)
1517  {
1518    xReadEpExGolomb( uiSymbol, CU_DQP_EG_k );
1519    uiDQp+=uiSymbol;
1520  }
1521
1522  if ( uiDQp > 0 )
1523  {
1524    UInt uiSign;
1525    Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
1526    m_pcTDecBinIf->decodeBinEP(uiSign);
1527    iDQp = uiDQp;
1528    if(uiSign)
1529    {
1530      iDQp = -iDQp;
1531    }
1532    qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY;
1533  }
1534  else 
1535  {
1536    qp = pcCU->getRefQP(uiAbsPartIdx);
1537  }
1538  pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth); 
1539  pcCU->setCodedQP(qp);
1540}
1541
1542Void TDecSbac::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth )
1543{
1544  UInt uiSymbol;
1545  const UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth );
1546  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA: eType, uiCtx ) );
1547#if !H_MV_ENC_DEC_TRAC 
1548  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1549  DTRACE_CABAC_T( "\tparseQtCbf()" )
1550  DTRACE_CABAC_T( "\tsymbol=" )
1551  DTRACE_CABAC_V( uiSymbol )
1552  DTRACE_CABAC_T( "\tctx=" )
1553  DTRACE_CABAC_V( uiCtx )
1554  DTRACE_CABAC_T( "\tetype=" )
1555  DTRACE_CABAC_V( eType )
1556  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1557  DTRACE_CABAC_V( uiAbsPartIdx )
1558  DTRACE_CABAC_T( "\n" )
1559#endif
1560 
1561  pcCU->setCbfSubParts( uiSymbol << uiTrDepth, eType, uiAbsPartIdx, uiDepth );
1562}
1563
1564void TDecSbac::parseTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType)
1565{
1566  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
1567  {
1568    return;
1569  }
1570  if(width != 4 || height != 4)
1571  {
1572    return;
1573  }
1574 
1575  UInt useTransformSkip;
1576  m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) );
1577  if(eTType!= TEXT_LUMA)
1578  {
1579    const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiDepth;
1580    if(uiLog2TrafoSize == 2) 
1581    { 
1582      uiDepth --;
1583    }
1584  }
1585#if !H_MV_ENC_DEC_TRAC
1586  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1587  DTRACE_CABAC_T("\tparseTransformSkip()");
1588  DTRACE_CABAC_T( "\tsymbol=" )
1589  DTRACE_CABAC_V( useTransformSkip )
1590  DTRACE_CABAC_T( "\tAddr=" )
1591  DTRACE_CABAC_V( pcCU->getAddr() )
1592  DTRACE_CABAC_T( "\tetype=" )
1593  DTRACE_CABAC_V( eTType )
1594  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1595  DTRACE_CABAC_V( uiAbsPartIdx )
1596  DTRACE_CABAC_T( "\n" )
1597#endif
1598
1599  pcCU->setTransformSkipSubParts( useTransformSkip, eTType, uiAbsPartIdx, uiDepth);
1600}
1601
1602/** Parse (X,Y) position of the last significant coefficient
1603 * \param uiPosLastX reference to X component of last coefficient
1604 * \param uiPosLastY reference to Y component of last coefficient
1605 * \param width  Block width
1606 * \param height Block height
1607 * \param eTType plane type / luminance or chrominance
1608 * \param uiScanIdx scan type (zig-zag, hor, ver)
1609 *
1610 * This method decodes the X and Y component within a block of the last significant coefficient.
1611 */
1612Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, TextType eTType, UInt uiScanIdx )
1613{
1614  UInt uiLast;
1615  ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType );
1616  ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType );
1617
1618  Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY;
1619  blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2));
1620  blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2));
1621  shiftX= eTType ? g_aucConvertToBit[ width  ] :((g_aucConvertToBit[ width  ]+3)>>2);
1622  shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2);
1623  // posX
1624  for( uiPosLastX = 0; uiPosLastX < g_uiGroupIdx[ width - 1 ]; uiPosLastX++ )
1625  {
1626    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + blkSizeOffsetX + (uiPosLastX >>shiftX) ) );
1627    if( !uiLast )
1628    {
1629      break;
1630    }
1631  }
1632
1633  // posY
1634  for( uiPosLastY = 0; uiPosLastY < g_uiGroupIdx[ height - 1 ]; uiPosLastY++ )
1635  {
1636    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + blkSizeOffsetY + (uiPosLastY >>shiftY)) );
1637    if( !uiLast )
1638    {
1639      break;
1640    }
1641  }
1642  if ( uiPosLastX > 3 )
1643  {
1644    UInt uiTemp  = 0;
1645    UInt uiCount = ( uiPosLastX - 2 ) >> 1;
1646    for ( Int i = uiCount - 1; i >= 0; i-- )
1647    {
1648      m_pcTDecBinIf->decodeBinEP( uiLast );
1649      uiTemp += uiLast << i;
1650    }
1651    uiPosLastX = g_uiMinInGroup[ uiPosLastX ] + uiTemp;
1652  }
1653  if ( uiPosLastY > 3 )
1654  {
1655    UInt uiTemp  = 0;
1656    UInt uiCount = ( uiPosLastY - 2 ) >> 1;
1657    for ( Int i = uiCount - 1; i >= 0; i-- )
1658    {
1659      m_pcTDecBinIf->decodeBinEP( uiLast );
1660      uiTemp += uiLast << i;
1661    }
1662    uiPosLastY = g_uiMinInGroup[ uiPosLastY ] + uiTemp;
1663  }
1664 
1665  if( uiScanIdx == SCAN_VER )
1666  {
1667    swap( uiPosLastX, uiPosLastY );
1668  }
1669}
1670
1671Void TDecSbac::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType )
1672{
1673#if !H_MV_ENC_DEC_TRAC
1674  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1675  DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" )
1676  DTRACE_CABAC_V( eTType )
1677  DTRACE_CABAC_T( "\twidth=" )
1678  DTRACE_CABAC_V( uiWidth )
1679  DTRACE_CABAC_T( "\theight=" )
1680  DTRACE_CABAC_V( uiHeight )
1681  DTRACE_CABAC_T( "\tdepth=" )
1682  DTRACE_CABAC_V( uiDepth )
1683  DTRACE_CABAC_T( "\tabspartidx=" )
1684  DTRACE_CABAC_V( uiAbsPartIdx )
1685  DTRACE_CABAC_T( "\ttoCU-X=" )
1686  DTRACE_CABAC_V( pcCU->getCUPelX() )
1687  DTRACE_CABAC_T( "\ttoCU-Y=" )
1688  DTRACE_CABAC_V( pcCU->getCUPelY() )
1689  DTRACE_CABAC_T( "\tCU-addr=" )
1690  DTRACE_CABAC_V(  pcCU->getAddr() )
1691  DTRACE_CABAC_T( "\tinCU-X=" )
1692  DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1693  DTRACE_CABAC_T( "\tinCU-Y=" )
1694  DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1695  DTRACE_CABAC_T( "\tpredmode=" )
1696  DTRACE_CABAC_V(  pcCU->getPredictionMode( uiAbsPartIdx ) )
1697  DTRACE_CABAC_T( "\n" )
1698#endif
1699 
1700  if( uiWidth > pcCU->getSlice()->getSPS()->getMaxTrSize() )
1701  {
1702    uiWidth  = pcCU->getSlice()->getSPS()->getMaxTrSize();
1703    uiHeight = pcCU->getSlice()->getSPS()->getMaxTrSize();
1704  }
1705  if(pcCU->getSlice()->getPPS()->getUseTransformSkip())
1706  {
1707    parseTransformSkipFlags( pcCU, uiAbsPartIdx, uiWidth, uiHeight, uiDepth, eTType);
1708  }
1709
1710  eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA );
1711 
1712  //----- parse significance map -----
1713  const UInt  uiLog2BlockSize   = g_aucConvertToBit[ uiWidth ] + 2;
1714  const UInt  uiMaxNumCoeff     = uiWidth * uiHeight;
1715  const UInt  uiMaxNumCoeffM1   = uiMaxNumCoeff - 1;
1716  UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx));
1717 
1718  //===== decode last significant =====
1719  UInt uiPosLastX, uiPosLastY;
1720  parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, eTType, uiScanIdx );
1721  UInt uiBlkPosLast      = uiPosLastX + (uiPosLastY<<uiLog2BlockSize);
1722  pcCoef[ uiBlkPosLast ] = 1;
1723
1724  //===== decode significance flags =====
1725  UInt uiScanPosLast;
1726  const UInt *scan   = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize-1 ];
1727  for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ )
1728  {
1729    UInt uiBlkPos = scan[ uiScanPosLast ];
1730    if( uiBlkPosLast == uiBlkPos )
1731    {
1732      break;
1733    }
1734  }
1735
1736  ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType );
1737  ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA;
1738
1739  const Int  iLastScanSet      = uiScanPosLast >> LOG2_SCAN_SET_SIZE;
1740  UInt c1 = 1;
1741  UInt uiGoRiceParam           = 0;
1742
1743  Bool beValid; 
1744  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
1745  {
1746    beValid = false;
1747  }
1748  else 
1749  {
1750    beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0;
1751  }
1752  UInt absSum = 0;
1753
1754  UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ];
1755  ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM );
1756  const UInt uiNumBlkSide = uiWidth >> (MLS_CG_SIZE >> 1);
1757  const UInt * scanCG;
1758  {
1759    scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0  ];   
1760    if( uiLog2BlockSize == 3 )
1761    {
1762      scanCG = g_sigLastScan8x8[ uiScanIdx ];
1763    }
1764    else if( uiLog2BlockSize == 5 )
1765    {
1766      scanCG = g_sigLastScanCG32x32;
1767    }
1768  }
1769  Int  iScanPosSig             = (Int) uiScanPosLast;
1770  for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- )
1771  {
1772    Int  iSubPos     = iSubSet << LOG2_SCAN_SET_SIZE;
1773    uiGoRiceParam    = 0;
1774    Int numNonZero = 0;
1775   
1776    Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE;
1777
1778    Int pos[SCAN_SET_SIZE];
1779    if( iScanPosSig == (Int) uiScanPosLast )
1780    {
1781      lastNZPosInCG  = iScanPosSig;
1782      firstNZPosInCG = iScanPosSig;
1783      iScanPosSig--;
1784      pos[ numNonZero ] = uiBlkPosLast;
1785      numNonZero = 1;
1786    }
1787
1788    // decode significant_coeffgroup_flag
1789    Int iCGBlkPos = scanCG[ iSubSet ];
1790    Int iCGPosY   = iCGBlkPos / uiNumBlkSide;
1791    Int iCGPosX   = iCGBlkPos - (iCGPosY * uiNumBlkSide);
1792    if( iSubSet == iLastScanSet || iSubSet == 0)
1793    {
1794      uiSigCoeffGroupFlag[ iCGBlkPos ] = 1;
1795    }
1796    else
1797    {
1798      UInt uiSigCoeffGroup;
1799      UInt uiCtxSig  = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight );
1800      m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] );
1801      uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup;
1802    }
1803
1804    // decode significant_coeff_flag
1805    Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight );
1806    UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig;
1807    for( ; iScanPosSig >= iSubPos; iScanPosSig-- )
1808    {
1809      uiBlkPos  = scan[ iScanPosSig ];
1810      uiPosY    = uiBlkPos >> uiLog2BlockSize;
1811      uiPosX    = uiBlkPos - ( uiPosY << uiLog2BlockSize );
1812      uiSig     = 0;
1813     
1814      if( uiSigCoeffGroupFlag[ iCGBlkPos ] )
1815      {
1816        if( iScanPosSig > iSubPos || iSubSet == 0  || numNonZero )
1817        {
1818          uiCtxSig  = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType );
1819          m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] );
1820        }
1821        else
1822        {
1823          uiSig = 1;
1824        }
1825      }
1826      pcCoef[ uiBlkPos ] = uiSig;
1827      if( uiSig )
1828      {
1829        pos[ numNonZero ] = uiBlkPos;
1830        numNonZero ++;
1831        if( lastNZPosInCG == -1 )
1832        {
1833          lastNZPosInCG = iScanPosSig;
1834        }
1835        firstNZPosInCG = iScanPosSig;
1836      }
1837    }
1838   
1839    if( numNonZero )
1840    {
1841      Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD );
1842      absSum = 0;
1843      UInt uiCtxSet    = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0;
1844      UInt uiBin;
1845      if( c1 == 0 )
1846      {
1847        uiCtxSet++;
1848      }
1849      c1 = 1;
1850      ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet;
1851      Int absCoeff[SCAN_SET_SIZE];
1852
1853      for ( Int i = 0; i < numNonZero; i++) absCoeff[i] = 1;   
1854      Int numC1Flag = min(numNonZero, C1FLAG_NUMBER);
1855      Int firstC2FlagIdx = -1;
1856
1857      for( Int idx = 0; idx < numC1Flag; idx++ )
1858      {
1859        m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] );
1860        if( uiBin == 1 )
1861        {
1862          c1 = 0;
1863          if (firstC2FlagIdx == -1)
1864          {
1865            firstC2FlagIdx = idx;
1866          }
1867        }
1868        else if( (c1 < 3) && (c1 > 0) )
1869        {
1870          c1++;
1871        }
1872        absCoeff[ idx ] = uiBin + 1;
1873      }
1874     
1875      if (c1 == 0)
1876      {
1877        baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet;
1878        if ( firstC2FlagIdx != -1)
1879        {
1880          m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] ); 
1881          absCoeff[ firstC2FlagIdx ] = uiBin + 2;
1882        }
1883      }
1884
1885      UInt coeffSigns;
1886      if ( signHidden && beValid )
1887      {
1888        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 );
1889        coeffSigns <<= 32 - (numNonZero-1);
1890      }
1891      else
1892      {
1893        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero );
1894        coeffSigns <<= 32 - numNonZero;
1895      }
1896     
1897      Int iFirstCoeff2 = 1;   
1898      if (c1 == 0 || numNonZero > C1FLAG_NUMBER)
1899      {
1900        for( Int idx = 0; idx < numNonZero; idx++ )
1901        {
1902          UInt baseLevel  = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2) : 1;
1903
1904          if( absCoeff[ idx ] == baseLevel)
1905          {
1906            UInt uiLevel;
1907            xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam );
1908            absCoeff[ idx ] = uiLevel + baseLevel;
1909            if(absCoeff[idx]>3*(1<<uiGoRiceParam))
1910            {
1911              uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4);
1912            }
1913          }
1914
1915          if(absCoeff[ idx ] >= 2) 
1916          {
1917            iFirstCoeff2 = 0;
1918          }
1919        }
1920      }
1921
1922      for( Int idx = 0; idx < numNonZero; idx++ )
1923      {
1924        Int blkPos = pos[ idx ];
1925        // Signs applied later.
1926        pcCoef[ blkPos ] = absCoeff[ idx ];
1927        absSum += absCoeff[ idx ];
1928
1929        if ( idx == numNonZero-1 && signHidden && beValid )
1930        {
1931          // Infer sign of 1st element.
1932          if (absSum&0x1)
1933          {
1934            pcCoef[ blkPos ] = -pcCoef[ blkPos ];
1935          }
1936        }
1937        else
1938        {
1939          Int sign = static_cast<Int>( coeffSigns ) >> 31;
1940          pcCoef[ blkPos ] = ( pcCoef[ blkPos ] ^ sign ) - sign;
1941          coeffSigns <<= 1;
1942        }
1943      }
1944    }
1945  }
1946 
1947  return;
1948}
1949
1950
1951Void TDecSbac::parseSaoMaxUvlc ( UInt& val, UInt maxSymbol )
1952{
1953  if (maxSymbol == 0)
1954  {
1955    val = 0;
1956    return;
1957  }
1958
1959  UInt code;
1960  Int  i;
1961  m_pcTDecBinIf->decodeBinEP( code );
1962  if ( code == 0 )
1963  {
1964    val = 0;
1965    return;
1966  }
1967
1968  i=1;
1969  while (1)
1970  {
1971    m_pcTDecBinIf->decodeBinEP( code );
1972    if ( code == 0 )
1973    {
1974      break;
1975    }
1976    i++;
1977    if (i == maxSymbol) 
1978    {
1979      break;
1980    }
1981  }
1982
1983  val = i;
1984}
1985Void TDecSbac::parseSaoUflc (UInt uiLength, UInt&  riVal)
1986{
1987  m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength );
1988}
1989Void TDecSbac::parseSaoMerge (UInt&  ruiVal)
1990{
1991  UInt uiCode;
1992  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) );
1993  ruiVal = (Int)uiCode;
1994}
1995Void TDecSbac::parseSaoTypeIdx (UInt&  ruiVal)
1996{
1997  UInt uiCode;
1998  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
1999  if (uiCode == 0) 
2000  {
2001    ruiVal = 0;
2002  }
2003  else
2004  {
2005    m_pcTDecBinIf->decodeBinEP( uiCode ); 
2006    if (uiCode == 0)
2007    {
2008      ruiVal = 1;
2009    }
2010    else
2011    {
2012      ruiVal = 2;
2013    }
2014  }
2015}
2016
2017Void TDecSbac::parseSaoSign(UInt& val)
2018{
2019  m_pcTDecBinIf->decodeBinEP ( val ); 
2020}
2021
2022Void TDecSbac::parseSAOBlkParam (SAOBlkParam& saoBlkParam
2023                                , Bool* sliceEnabled
2024                                , Bool leftMergeAvail
2025                                , Bool aboveMergeAvail
2026                                )
2027{
2028  UInt uiSymbol;
2029
2030  Bool isLeftMerge = false;
2031  Bool isAboveMerge= false;
2032
2033  if(leftMergeAvail)
2034  {
2035    parseSaoMerge(uiSymbol); //sao_merge_left_flag
2036    isLeftMerge = (uiSymbol?true:false);
2037  }
2038
2039  if( aboveMergeAvail && !isLeftMerge)
2040  {
2041    parseSaoMerge(uiSymbol); //sao_merge_up_flag
2042    isAboveMerge = (uiSymbol?true:false);
2043  }
2044
2045  if(isLeftMerge || isAboveMerge) //merge mode
2046      {
2047    saoBlkParam[SAO_Y].modeIdc = saoBlkParam[SAO_Cb].modeIdc = saoBlkParam[SAO_Cr].modeIdc = SAO_MODE_MERGE;
2048    saoBlkParam[SAO_Y].typeIdc = saoBlkParam[SAO_Cb].typeIdc = saoBlkParam[SAO_Cr].typeIdc = (isLeftMerge)?SAO_MERGE_LEFT:SAO_MERGE_ABOVE;
2049      }   
2050  else //new or off mode
2051      {
2052    for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
2053        {
2054      SAOOffset& ctbParam = saoBlkParam[compIdx];
2055
2056      if(!sliceEnabled[compIdx])
2057          {
2058        //off
2059        ctbParam.modeIdc = SAO_MODE_OFF;
2060        continue;
2061        }
2062
2063      //type
2064      if(compIdx == SAO_Y || compIdx == SAO_Cb)
2065    {
2066        parseSaoTypeIdx(uiSymbol); //sao_type_idx_luma or sao_type_idx_chroma
2067
2068        assert(uiSymbol ==0 || uiSymbol ==1 || uiSymbol ==2);
2069
2070        if(uiSymbol ==0) //OFF
2071     {
2072          ctbParam.modeIdc = SAO_MODE_OFF;
2073   }
2074        else if(uiSymbol == 1) //BO
2075        {
2076          ctbParam.modeIdc = SAO_MODE_NEW;
2077          ctbParam.typeIdc = SAO_TYPE_START_BO;
2078  }
2079        else //2, EO
2080  {
2081          ctbParam.modeIdc = SAO_MODE_NEW;
2082          ctbParam.typeIdc = SAO_TYPE_START_EO;
2083        }
2084
2085  }
2086      else //Cr, follow Cb SAO type
2087      {
2088        ctbParam.modeIdc = saoBlkParam[SAO_Cb].modeIdc;
2089        ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc;
2090}
2091
2092      if(ctbParam.modeIdc == SAO_MODE_NEW)
2093{
2094        Int offset[4];
2095        for(Int i=0; i< 4; i++)
2096  {
2097          parseSaoMaxUvlc(uiSymbol,  g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
2098          offset[i] = (Int)uiSymbol;
2099  }
2100
2101        if(ctbParam.typeIdc == SAO_TYPE_START_BO)
2102  {
2103          for(Int i=0; i< 4; i++)
2104    {
2105            if(offset[i] != 0)
2106    {
2107              parseSaoSign(uiSymbol); //sao_offset_sign
2108              if(uiSymbol)
2109      {
2110                offset[i] = -offset[i];
2111      }
2112    }
2113  }
2114          parseSaoUflc(NUM_SAO_BO_CLASSES_LOG2, uiSymbol ); //sao_band_position
2115          ctbParam.typeAuxInfo = uiSymbol;
2116
2117          for(Int i=0; i<4; i++)
2118      {
2119            ctbParam.offset[(ctbParam.typeAuxInfo+i)%MAX_NUM_SAO_CLASSES] = offset[i];
2120      }
2121
2122        }
2123        else //EO
2124        {
2125          ctbParam.typeAuxInfo = 0;
2126
2127          if(compIdx == SAO_Y || compIdx == SAO_Cb)
2128        {
2129            parseSaoUflc(NUM_SAO_EO_TYPES_LOG2, uiSymbol ); //sao_eo_class_luma or sao_eo_class_chroma
2130            ctbParam.typeIdc += uiSymbol;
2131        }
2132        else
2133        {
2134            ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc;
2135        }
2136          ctbParam.offset[SAO_CLASS_EO_FULL_VALLEY] = offset[0];
2137          ctbParam.offset[SAO_CLASS_EO_HALF_VALLEY] = offset[1];
2138          ctbParam.offset[SAO_CLASS_EO_PLAIN      ] = 0;
2139          ctbParam.offset[SAO_CLASS_EO_HALF_PEAK  ] = -offset[2];
2140          ctbParam.offset[SAO_CLASS_EO_FULL_PEAK  ] = -offset[3];
2141      }
2142      }
2143    }
2144  }
2145}
2146
2147/**
2148 - Initialize our contexts from the nominated source.
2149 .
2150 \param pSrc Contexts to be copied.
2151 */
2152Void TDecSbac::xCopyContextsFrom( TDecSbac* pSrc )
2153{
2154  memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0]));
2155}
2156
2157Void TDecSbac::xCopyFrom( TDecSbac* pSrc )
2158{
2159  m_pcTDecBinIf->copyState( pSrc->m_pcTDecBinIf );
2160
2161  m_uiLastQp           = pSrc->m_uiLastQp;
2162  xCopyContextsFrom( pSrc );
2163
2164}
2165
2166Void TDecSbac::load ( TDecSbac* pScr )
2167{
2168  xCopyFrom(pScr);
2169}
2170
2171Void TDecSbac::loadContexts ( TDecSbac* pScr )
2172{
2173  xCopyContextsFrom(pScr);
2174}
2175//! \}
Note: See TracBrowser for help on using the repository browser.