source: 3DVCSoftware/branches/HTM-14.0-MV-draft-3/source/Lib/TLibDecoder/TDecSbac.cpp

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

Removed 3D-HEVC.

  • Property svn:eol-style set to native
File size: 48.7 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-2015, 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, m_cCUPartSizeSCModel        ( 1,             1,               NUM_PART_SIZE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
57, m_cCUPredModeSCModel        ( 1,             1,               NUM_PRED_MODE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
58, m_cCUIntraPredSCModel       ( 1,             1,               NUM_ADI_CTX                   , m_contextModels + m_numContextModels, m_numContextModels)
59, m_cCUChromaPredSCModel      ( 1,             1,               NUM_CHROMA_PRED_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
60, m_cCUDeltaQpSCModel         ( 1,             1,               NUM_DELTA_QP_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
61, m_cCUInterDirSCModel        ( 1,             1,               NUM_INTER_DIR_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
62, m_cCURefPicSCModel          ( 1,             1,               NUM_REF_NO_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
63, m_cCUMvdSCModel             ( 1,             1,               NUM_MV_RES_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
64, m_cCUQtCbfSCModel           ( 1,             2,               NUM_QT_CBF_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
65, m_cCUTransSubdivFlagSCModel ( 1,             1,               NUM_TRANS_SUBDIV_FLAG_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
66, m_cCUQtRootCbfSCModel       ( 1,             1,               NUM_QT_ROOT_CBF_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
67, m_cCUSigCoeffGroupSCModel   ( 1,             2,               NUM_SIG_CG_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
68, m_cCUSigSCModel             ( 1,             1,               NUM_SIG_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
69, m_cCuCtxLastX               ( 1,             2,               NUM_CTX_LAST_FLAG_XY          , m_contextModels + m_numContextModels, m_numContextModels)
70, m_cCuCtxLastY               ( 1,             2,               NUM_CTX_LAST_FLAG_XY          , m_contextModels + m_numContextModels, m_numContextModels)
71, m_cCUOneSCModel             ( 1,             1,               NUM_ONE_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
72, m_cCUAbsSCModel             ( 1,             1,               NUM_ABS_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
73, m_cMVPIdxSCModel            ( 1,             1,               NUM_MVP_IDX_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
74, m_cSaoMergeSCModel      ( 1,             1,               NUM_SAO_MERGE_FLAG_CTX   , m_contextModels + m_numContextModels, m_numContextModels)
75, m_cSaoTypeIdxSCModel        ( 1,             1,               NUM_SAO_TYPE_IDX_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
76, m_cTransformSkipSCModel     ( 1,             2,               NUM_TRANSFORMSKIP_FLAG_CTX    , m_contextModels + m_numContextModels, m_numContextModels)
77, m_CUTransquantBypassFlagSCModel( 1,          1,               NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
78{
79  assert( m_numContextModels <= MAX_NUM_CTX_MOD );
80}
81
82TDecSbac::~TDecSbac()
83{
84}
85
86// ====================================================================================================================
87// Public member functions
88// ====================================================================================================================
89
90Void TDecSbac::resetEntropy(TComSlice* pSlice)
91{
92  SliceType sliceType  = pSlice->getSliceType();
93  Int       qp         = pSlice->getSliceQp();
94
95  if (pSlice->getPPS()->getCabacInitPresentFlag() && pSlice->getCabacInitFlag())
96  {
97    switch (sliceType)
98    {
99    case P_SLICE:           // change initialization table to B_SLICE initialization
100      sliceType = B_SLICE; 
101      break;
102    case B_SLICE:           // change initialization table to P_SLICE initialization
103      sliceType = P_SLICE; 
104      break;
105    default     :           // should not occur
106      assert(0);
107    }
108  }
109
110  m_cCUSplitFlagSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_SPLIT_FLAG );
111  m_cCUSkipFlagSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SKIP_FLAG );
112  m_cCUMergeFlagExtSCModel.initBuffer    ( sliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT );
113  m_cCUMergeIdxExtSCModel.initBuffer     ( sliceType, qp, (UChar*)INIT_MERGE_IDX_EXT );
114  m_cCUPartSizeSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_PART_SIZE );
115  m_cCUPredModeSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_PRED_MODE );
116  m_cCUIntraPredSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_INTRA_PRED_MODE );
117  m_cCUChromaPredSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE );
118  m_cCUInterDirSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_INTER_DIR );
119  m_cCUMvdSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_MVD );
120  m_cCURefPicSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_REF_PIC );
121  m_cCUDeltaQpSCModel.initBuffer         ( sliceType, qp, (UChar*)INIT_DQP );
122  m_cCUQtCbfSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_QT_CBF );
123  m_cCUQtRootCbfSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_QT_ROOT_CBF );
124  m_cCUSigCoeffGroupSCModel.initBuffer   ( sliceType, qp, (UChar*)INIT_SIG_CG_FLAG );
125  m_cCUSigSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_SIG_FLAG );
126  m_cCuCtxLastX.initBuffer               ( sliceType, qp, (UChar*)INIT_LAST );
127  m_cCuCtxLastY.initBuffer               ( sliceType, qp, (UChar*)INIT_LAST );
128  m_cCUOneSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_ONE_FLAG );
129  m_cCUAbsSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_ABS_FLAG );
130  m_cMVPIdxSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_MVP_IDX );
131  m_cSaoMergeSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG );
132  m_cSaoTypeIdxSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
133
134  m_cCUTransSubdivFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
135  m_cTransformSkipSCModel.initBuffer     ( sliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
136  m_CUTransquantBypassFlagSCModel.initBuffer( sliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
137  m_uiLastDQpNonZero  = 0;
138 
139  // new structure
140  m_uiLastQp          = qp;
141 
142  m_pcTDecBinIf->start();
143}
144
145/** The function does the following: Read out terminate bit. Flush CABAC. Byte-align for next tile.
146 *  Intialize CABAC states. Start CABAC.
147 */
148Void TDecSbac::updateContextTables( SliceType eSliceType, Int iQp )
149{
150  UInt uiBit;
151  m_pcTDecBinIf->decodeBinTrm(uiBit);
152  assert(uiBit); // end_of_sub_stream_one_bit must be equal to 1
153  m_pcTDecBinIf->finish(); 
154  m_pcBitstream->readOutTrailingBits();
155  m_cCUSplitFlagSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG );
156  m_cCUSkipFlagSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG );
157  m_cCUMergeFlagExtSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT );
158  m_cCUMergeIdxExtSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT );
159  m_cCUPartSizeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PART_SIZE );
160  m_cCUPredModeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PRED_MODE );
161  m_cCUIntraPredSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE );
162  m_cCUChromaPredSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE );
163  m_cCUInterDirSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_INTER_DIR );
164  m_cCUMvdSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_MVD );
165  m_cCURefPicSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_REF_PIC );
166  m_cCUDeltaQpSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_DQP );
167  m_cCUQtCbfSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_QT_CBF );
168  m_cCUQtRootCbfSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF );
169  m_cCUSigCoeffGroupSCModel.initBuffer   ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG );
170  m_cCUSigSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG );
171  m_cCuCtxLastX.initBuffer               ( eSliceType, iQp, (UChar*)INIT_LAST );
172  m_cCuCtxLastY.initBuffer               ( eSliceType, iQp, (UChar*)INIT_LAST );
173  m_cCUOneSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG );
174  m_cCUAbsSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG );
175  m_cMVPIdxSCModel.initBuffer            ( eSliceType, iQp, (UChar*)INIT_MVP_IDX );
176  m_cSaoMergeSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG );
177  m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
178  m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
179  m_cTransformSkipSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
180  m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
181
182  m_pcTDecBinIf->start();
183}
184
185Void TDecSbac::parseTerminatingBit( UInt& ruiBit )
186{
187  m_pcTDecBinIf->decodeBinTrm( ruiBit );
188  if ( ruiBit )
189  {
190    m_pcTDecBinIf->finish();
191  }
192}
193
194
195Void TDecSbac::xReadUnaryMaxSymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol )
196{
197  if (uiMaxSymbol == 0)
198  {
199    ruiSymbol = 0;
200    return;
201  }
202 
203  m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] );
204 
205  if( ruiSymbol == 0 || uiMaxSymbol == 1 )
206  {
207    return;
208  }
209 
210  UInt uiSymbol = 0;
211  UInt uiCont;
212 
213  do
214  {
215    m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] );
216    uiSymbol++;
217  }
218  while( uiCont && ( uiSymbol < uiMaxSymbol - 1 ) );
219 
220  if( uiCont && ( uiSymbol == uiMaxSymbol - 1 ) )
221  {
222    uiSymbol++;
223  }
224 
225  ruiSymbol = uiSymbol;
226}
227
228Void TDecSbac::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount )
229{
230  UInt uiSymbol = 0;
231  UInt uiBit = 1;
232 
233  while( uiBit )
234  {
235    m_pcTDecBinIf->decodeBinEP( uiBit );
236    uiSymbol += uiBit << uiCount++;
237  }
238 
239  if ( --uiCount )
240  {
241    UInt bins;
242    m_pcTDecBinIf->decodeBinsEP( bins, uiCount );
243    uiSymbol += bins;
244  }
245 
246  ruiSymbol = uiSymbol;
247}
248
249Void TDecSbac::xReadUnarySymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset )
250{
251  m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] );
252 
253  if( !ruiSymbol )
254  {
255    return;
256  }
257 
258  UInt uiSymbol = 0;
259  UInt uiCont;
260 
261  do
262  {
263    m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] );
264    uiSymbol++;
265  }
266  while( uiCont );
267 
268  ruiSymbol = uiSymbol;
269}
270
271
272/** Parsing of coeff_abs_level_remaing
273 * \param ruiSymbol reference to coeff_abs_level_remaing
274 * \param ruiParam reference to parameter
275 * \returns Void
276 */
277Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam )
278{
279
280  UInt prefix   = 0;
281  UInt codeWord = 0;
282  do
283  {
284    prefix++;
285    m_pcTDecBinIf->decodeBinEP( codeWord );
286  }
287  while( codeWord);
288  codeWord  = 1 - codeWord;
289  prefix -= codeWord;
290  codeWord=0;
291  if (prefix < COEF_REMAIN_BIN_REDUCTION )
292  {
293    m_pcTDecBinIf->decodeBinsEP(codeWord,rParam);
294    rSymbol = (prefix<<rParam) + codeWord;
295  }
296  else
297  {
298    m_pcTDecBinIf->decodeBinsEP(codeWord,prefix-COEF_REMAIN_BIN_REDUCTION+rParam);
299    rSymbol = (((1<<(prefix-COEF_REMAIN_BIN_REDUCTION))+COEF_REMAIN_BIN_REDUCTION-1)<<rParam)+codeWord;
300  }
301}
302
303/** Parse I_PCM information.
304 * \param pcCU
305 * \param uiAbsPartIdx
306 * \param uiDepth
307 * \returns Void
308 *
309 * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes.
310 */
311Void TDecSbac::parseIPCMInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
312{
313  UInt uiSymbol;
314
315    m_pcTDecBinIf->decodeBinTrm(uiSymbol);
316
317#if H_MV_ENC_DEC_TRAC
318      DTRACE_CU("pcm_flag", uiSymbol)
319#endif
320    if (uiSymbol)
321    {
322    Bool bIpcmFlag = true;
323
324    pcCU->setPartSizeSubParts  ( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
325    pcCU->setSizeSubParts      ( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
326    pcCU->setTrIdxSubParts     ( 0, uiAbsPartIdx, uiDepth );
327    pcCU->setIPCMFlagSubParts  ( bIpcmFlag, uiAbsPartIdx, uiDepth );
328
329    UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
330    UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
331    UInt uiChromaOffset = uiLumaOffset>>2;
332
333    Pel* piPCMSample;
334    UInt uiWidth;
335    UInt uiHeight;
336    UInt uiSampleBits;
337    UInt uiX, uiY;
338
339    piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset;
340    uiWidth = pcCU->getWidth(uiAbsPartIdx);
341    uiHeight = pcCU->getHeight(uiAbsPartIdx);
342    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
343
344    for(uiY = 0; uiY < uiHeight; uiY++)
345    {
346      for(uiX = 0; uiX < uiWidth; uiX++)
347      {
348        UInt uiSample;
349        m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
350        piPCMSample[uiX] = uiSample;
351      }
352      piPCMSample += uiWidth;
353    }
354
355
356    piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset;
357    uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
358    uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
359    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
360
361    for(uiY = 0; uiY < uiHeight; uiY++)
362    {
363      for(uiX = 0; uiX < uiWidth; uiX++)
364      {
365        UInt uiSample;
366        m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
367        piPCMSample[uiX] = uiSample;
368      }
369      piPCMSample += uiWidth;
370    }
371
372    piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset;
373    uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
374    uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
375    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
376
377    for(uiY = 0; uiY < uiHeight; uiY++)
378    {
379      for(uiX = 0; uiX < uiWidth; uiX++)
380      {
381        UInt uiSample;
382        m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
383        piPCMSample[uiX] = uiSample;
384      }
385      piPCMSample += uiWidth;
386    }
387
388
389    m_pcTDecBinIf->start();
390  }
391}
392
393Void TDecSbac::parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
394{
395  UInt uiSymbol;
396  m_pcTDecBinIf->decodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) );
397#if H_MV_ENC_DEC_TRAC
398  DTRACE_CU("cu_transquant_bypass_flag", uiSymbol); 
399#endif
400  pcCU->setCUTransquantBypassSubParts(uiSymbol ? true : false, uiAbsPartIdx, uiDepth);
401}
402
403/** parse skip flag
404 * \param pcCU
405 * \param uiAbsPartIdx
406 * \param uiDepth
407 * \returns Void
408 */
409Void TDecSbac::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
410{
411  if( pcCU->getSlice()->isIntra() )
412  {
413    return;
414  }
415 
416  UInt uiSymbol = 0;
417  UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx );
418  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) );
419#if !H_MV_ENC_DEC_TRAC
420  DTRACE_CABAC_VL( g_nSymbolCounter++ );
421  DTRACE_CABAC_T( "\tSkipFlag" );
422  DTRACE_CABAC_T( "\tuiCtxSkip: ");
423  DTRACE_CABAC_V( uiCtxSkip );
424  DTRACE_CABAC_T( "\tuiSymbol: ");
425  DTRACE_CABAC_V( uiSymbol );
426  DTRACE_CABAC_T( "\n");
427#endif
428 
429  if( uiSymbol )
430  {
431    pcCU->setSkipFlagSubParts( true,        uiAbsPartIdx, uiDepth );
432    pcCU->setPredModeSubParts( MODE_INTER,  uiAbsPartIdx, uiDepth );
433    pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
434    pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
435    pcCU->setMergeFlagSubParts( true , uiAbsPartIdx, 0, uiDepth );
436  }
437#if H_MV_ENC_DEC_TRAC
438  DTRACE_CU("cu_skip_flag", uiSymbol); 
439#endif
440}
441
442
443/** parse merge flag
444 * \param pcCU
445 * \param uiAbsPartIdx
446 * \param uiDepth
447 * \param uiPUIdx
448 * \returns Void
449 */
450Void TDecSbac::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
451{
452  UInt uiSymbol;
453  m_pcTDecBinIf->decodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) );
454#if H_MV_ENC_DEC_TRAC
455  DTRACE_PU("merge_flag", uiSymbol)
456#endif
457  pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth );
458
459#if !H_MV_ENC_DEC_TRAC
460  DTRACE_CABAC_VL( g_nSymbolCounter++ );
461  DTRACE_CABAC_T( "\tMergeFlag: " );
462  DTRACE_CABAC_V( uiSymbol );
463  DTRACE_CABAC_T( "\tAddress: " );
464  DTRACE_CABAC_V( pcCU->getAddr() );
465  DTRACE_CABAC_T( "\tuiAbsPartIdx: " );
466  DTRACE_CABAC_V( uiAbsPartIdx );
467  DTRACE_CABAC_T( "\n" );
468#endif
469}
470
471Void TDecSbac::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex )
472{
473  UInt uiUnaryIdx = 0;
474  UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand();
475  if ( uiNumCand > 1 )
476  {
477    for( ; uiUnaryIdx < uiNumCand - 1; ++uiUnaryIdx )
478    {
479      UInt uiSymbol = 0;
480      if ( uiUnaryIdx==0 )
481      {
482        m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) );
483      }
484      else
485      {
486        m_pcTDecBinIf->decodeBinEP( uiSymbol );
487      }
488      if( uiSymbol == 0 )
489      {
490        break;
491      }
492    }
493#if H_MV_ENC_DEC_TRAC
494    DTRACE_PU("merge_idx", uiUnaryIdx)
495#endif
496  }
497  ruiMergeIndex = uiUnaryIdx;
498
499#if !H_MV_ENC_DEC_TRAC
500  DTRACE_CABAC_VL( g_nSymbolCounter++ )
501  DTRACE_CABAC_T( "\tparseMergeIndex()" )
502  DTRACE_CABAC_T( "\tuiMRGIdx= " )
503  DTRACE_CABAC_V( ruiMergeIndex )
504  DTRACE_CABAC_T( "\n" )
505#endif
506}
507
508Void TDecSbac::parseMVPIdx      ( Int& riMVPIdx )
509{
510  UInt uiSymbol;
511  xReadUnaryMaxSymbol(uiSymbol, m_cMVPIdxSCModel.get(0), 1, AMVP_MAX_NUM_CANDS-1);
512  riMVPIdx = uiSymbol;
513}
514
515Void TDecSbac::parseSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
516{
517  if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
518  {
519    pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx );
520    return;
521  }
522
523  UInt uiSymbol;
524    m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSplitFlagSCModel.get( 0, 0, pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ) ) );
525#if H_MV_ENC_DEC_TRAC
526    DTRACE_CU("split_cu_flag", uiSymbol); 
527#else
528    DTRACE_CABAC_VL( g_nSymbolCounter++ )
529    DTRACE_CABAC_T( "\tSplitFlag\n" )
530#endif
531  pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx );
532 
533  return;
534}
535
536/** parse partition size
537 * \param pcCU
538 * \param uiAbsPartIdx
539 * \param uiDepth
540 * \returns Void
541 */
542Void TDecSbac::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
543{
544  UInt uiSymbol, uiMode = 0;
545  PartSize eMode;
546
547
548 
549  if ( pcCU->isIntra( uiAbsPartIdx ) )
550  {
551     uiSymbol = 1;
552      if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
553      {
554        m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 0) );
555#if H_MV_ENC_DEC_TRAC         
556        DTRACE_CU("part_mode", uiSymbol)
557#endif       
558      }
559      eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN;
560    UInt uiTrLevel = 0;   
561    UInt uiWidthInBit  = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2;
562    UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2;
563    uiTrLevel          = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0;
564    if( eMode == SIZE_NxN )
565    {
566      pcCU->setTrIdxSubParts( 1+uiTrLevel, uiAbsPartIdx, uiDepth );
567    }
568    else
569    {
570      pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth );
571    }
572  }
573  else
574  {
575      UInt uiMaxNumBits = 2;
576      if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( (g_uiMaxCUWidth>>uiDepth) == 8 && (g_uiMaxCUHeight>>uiDepth) == 8 ) )
577      {
578        uiMaxNumBits ++;
579      }
580      for ( UInt ui = 0; ui < uiMaxNumBits; ui++ )
581      {
582        m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) );
583        if ( uiSymbol )
584        {
585          break;
586        }
587        uiMode++;
588      }
589      eMode = (PartSize) uiMode;
590      if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) )
591      {
592        if (eMode == SIZE_2NxN)
593        {
594        m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
595          if (uiSymbol == 0)
596          {
597            m_pcTDecBinIf->decodeBinEP(uiSymbol);
598            eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD);
599          }
600        }
601        else if (eMode == SIZE_Nx2N)
602        {
603        m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
604          if (uiSymbol == 0)
605          {
606            m_pcTDecBinIf->decodeBinEP(uiSymbol);
607            eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N);
608          }
609        }
610      }
611#if H_MV_ENC_DEC_TRAC         
612      DTRACE_CU("part_mode", eMode )
613#endif
614  }
615  pcCU->setPartSizeSubParts( eMode, uiAbsPartIdx, uiDepth );
616  pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
617}
618
619/** parse prediction mode
620 * \param pcCU
621 * \param uiAbsPartIdx
622 * \param uiDepth
623 * \returns Void
624 */
625Void TDecSbac::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
626{
627  if( pcCU->getSlice()->isIntra() )
628  {
629    pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth );
630    return;
631  }
632 
633  UInt uiSymbol;
634  Int  iPredMode = MODE_INTER;
635  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPredModeSCModel.get( 0, 0, 0 ) );
636  iPredMode += uiSymbol;
637#if H_MV_ENC_DEC_TRAC         
638  DTRACE_CU("pred_mode_flag", uiSymbol)
639#endif       
640  pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth );
641}
642
643Void TDecSbac::parseIntraDirLumaAng  ( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
644{
645  PartSize mode = pcCU->getPartitionSize( absPartIdx );
646  UInt partNum = mode==SIZE_NxN?4:1;
647  UInt partOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2;
648  UInt mpmPred[4],symbol;
649  Int j,intraPredMode;   
650  if (mode==SIZE_NxN)
651  {
652    depth++;
653  }
654  for (j=0;j<partNum;j++)
655  {
656    m_pcTDecBinIf->decodeBin( symbol, m_cCUIntraPredSCModel.get( 0, 0, 0) );
657    mpmPred[j] = symbol;
658#if H_MV_ENC_DEC_TRAC         
659    DTRACE_CU("prev_intra_luma_pred_flag", symbol)
660#endif
661  }
662  for (j=0;j<partNum;j++)
663  {
664    Int preds[3] = {-1, -1, -1};
665    Int predNum = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds); 
666    if (mpmPred[j])
667    {
668      m_pcTDecBinIf->decodeBinEP( symbol );
669      if (symbol)
670      {
671        m_pcTDecBinIf->decodeBinEP( symbol );
672        symbol++;
673      }
674#if H_MV_ENC_DEC_TRAC         
675      DTRACE_CU("mpm_idx", symbol)
676#endif
677      intraPredMode = preds[symbol];
678    }
679    else
680    {
681      m_pcTDecBinIf->decodeBinsEP( symbol, 5 );
682      intraPredMode = symbol;
683#if H_MV_ENC_DEC_TRAC         
684      DTRACE_CU("rem_intra_luma_pred_mode", symbol)
685#endif       
686      //postponed sorting of MPMs (only in remaining branch)
687      if (preds[0] > preds[1])
688      { 
689        std::swap(preds[0], preds[1]); 
690      }
691      if (preds[0] > preds[2])
692      {
693        std::swap(preds[0], preds[2]);
694      }
695      if (preds[1] > preds[2])
696      {
697        std::swap(preds[1], preds[2]);
698      }
699      for ( Int i = 0; i < predNum; i++ )
700      {
701        intraPredMode += ( intraPredMode >= preds[i] );
702      }
703    }
704    pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, absPartIdx+partOffset*j, depth );
705  }
706}
707
708Void TDecSbac::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
709{
710  UInt uiSymbol;
711
712  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) );
713
714  if( uiSymbol == 0 )
715  {
716#if H_MV_ENC_DEC_TRAC         
717    DTRACE_CU("intra_chroma_pred_mode", uiSymbol )
718#endif       
719    uiSymbol = DM_CHROMA_IDX;
720  } 
721  else 
722  {
723    {
724      UInt uiIPredMode;
725      m_pcTDecBinIf->decodeBinsEP( uiIPredMode, 2 );
726#if H_MV_ENC_DEC_TRAC         
727      DTRACE_CU("intra_chroma_pred_mode", uiIPredMode )
728#endif       
729      UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ];
730      pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir );
731      uiSymbol = uiAllowedChromaDir[ uiIPredMode ];
732    }
733  }
734  pcCU->setChromIntraDirSubParts( uiSymbol, uiAbsPartIdx, uiDepth );
735  return;
736}
737
738
739Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx )
740{
741  UInt uiSymbol;
742  const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx );
743  ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 );
744  uiSymbol = 0;
745  if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 )
746  {
747    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) );
748  }
749
750  if( uiSymbol )
751  {
752    uiSymbol = 2;
753  }
754  else
755  {
756    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + 4 ) );
757    assert(uiSymbol == 0 || uiSymbol == 1);
758  }
759
760  uiSymbol++;
761  ruiInterDir = uiSymbol;
762#if H_MV_ENC_DEC_TRAC
763    DTRACE_PU("inter_pred_idc", ruiInterDir - 1 )   
764#endif
765
766  return;
767}
768
769Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList )
770{
771  UInt uiSymbol;
772  {
773    ContextModel *pCtx = m_cCURefPicSCModel.get( 0 );
774    m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
775
776    if( uiSymbol )
777    {
778      UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2;
779      pCtx++;
780      UInt ui;
781      for( ui = 0; ui < uiRefNum; ++ui )
782      {
783        if( ui == 0 )
784        {
785          m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
786        }
787        else
788        {
789          m_pcTDecBinIf->decodeBinEP( uiSymbol );
790        }
791        if( uiSymbol == 0 )
792        {
793          break;
794        }
795      }
796      uiSymbol = ui + 1;
797    }
798    riRefFrmIdx = uiSymbol;
799  }
800
801#if H_MV_ENC_DEC_TRAC
802#if ENC_DEC_TRACE
803  if ( eRefList == REF_PIC_LIST_0 )
804  {
805    DTRACE_PU("ref_idx_l0", uiSymbol)
806  }
807  else
808  {
809    DTRACE_PU("ref_idx_l1", uiSymbol)
810  }
811#endif
812#endif
813  return;
814}
815
816Void TDecSbac::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList )
817{
818  UInt uiSymbol;
819  UInt uiHorAbs;
820  UInt uiVerAbs;
821  UInt uiHorSign = 0;
822  UInt uiVerSign = 0;
823  ContextModel *pCtx = m_cCUMvdSCModel.get( 0 );
824
825  if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3)
826  {
827    uiHorAbs=0;
828    uiVerAbs=0;
829  }
830  else
831  {
832    m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx );
833    m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx );
834
835    const Bool bHorAbsGr0 = uiHorAbs != 0;
836    const Bool bVerAbsGr0 = uiVerAbs != 0;
837    pCtx++;
838
839    if( bHorAbsGr0 )
840    {
841      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
842      uiHorAbs += uiSymbol;
843    }
844
845    if( bVerAbsGr0 )
846    {
847      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
848      uiVerAbs += uiSymbol;
849    }
850
851    if( bHorAbsGr0 )
852    {
853      if( 2 == uiHorAbs )
854      {
855        xReadEpExGolomb( uiSymbol, 1 );
856        uiHorAbs += uiSymbol;
857      }
858
859      m_pcTDecBinIf->decodeBinEP( uiHorSign );
860    }
861
862    if( bVerAbsGr0 )
863    {
864      if( 2 == uiVerAbs )
865      {
866        xReadEpExGolomb( uiSymbol, 1 );
867        uiVerAbs += uiSymbol;
868      }
869
870      m_pcTDecBinIf->decodeBinEP( uiVerSign );
871    }
872
873  }
874
875  const TComMv cMv( uiHorSign ? -Int( uiHorAbs ): uiHorAbs, uiVerSign ? -Int( uiVerAbs ) : uiVerAbs );
876  pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiDepth, uiPartIdx );
877  return;
878}
879
880
881Void TDecSbac::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize )
882{
883  m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize ) );
884#if !H_MV_ENC_DEC_TRAC
885  DTRACE_CABAC_VL( g_nSymbolCounter++ )
886  DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" )
887  DTRACE_CABAC_T( "\tsymbol=" )
888  DTRACE_CABAC_V( ruiSubdivFlag )
889  DTRACE_CABAC_T( "\tctx=" )
890  DTRACE_CABAC_V( uiLog2TransformBlockSize )
891  DTRACE_CABAC_T( "\n" )
892#else
893  DTRACE_TU("split_transform_flag", ruiSubdivFlag )
894#endif
895}
896
897Void TDecSbac::parseQtRootCbf( UInt uiAbsPartIdx, UInt& uiQtRootCbf )
898{
899  UInt uiSymbol;
900  const UInt uiCtx = 0;
901  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) );
902#if !H_MV_ENC_DEC_TRAC
903  DTRACE_CABAC_VL( g_nSymbolCounter++ )
904  DTRACE_CABAC_T( "\tparseQtRootCbf()" )
905  DTRACE_CABAC_T( "\tsymbol=" )
906  DTRACE_CABAC_V( uiSymbol )
907  DTRACE_CABAC_T( "\tctx=" )
908  DTRACE_CABAC_V( uiCtx )
909  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
910  DTRACE_CABAC_V( uiAbsPartIdx )
911  DTRACE_CABAC_T( "\n" )
912#else
913  DTRACE_CU( "rqt_root_cbf", uiSymbol )
914#endif
915 
916  uiQtRootCbf = uiSymbol;
917}
918
919Void TDecSbac::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
920{
921  Int qp;
922  UInt uiDQp;
923  Int  iDQp;
924 
925  UInt uiSymbol;
926
927  xReadUnaryMaxSymbol (uiDQp,  &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX);
928
929  if( uiDQp >= CU_DQP_TU_CMAX)
930  {
931    xReadEpExGolomb( uiSymbol, CU_DQP_EG_k );
932    uiDQp+=uiSymbol;
933  }
934
935  if ( uiDQp > 0 )
936  {
937    UInt uiSign;
938    Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
939    m_pcTDecBinIf->decodeBinEP(uiSign);
940    iDQp = uiDQp;
941    if(uiSign)
942    {
943      iDQp = -iDQp;
944    }
945    qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY;
946  }
947  else 
948  {
949    qp = pcCU->getRefQP(uiAbsPartIdx);
950  }
951  pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth); 
952  pcCU->setCodedQP(qp);
953}
954
955Void TDecSbac::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth )
956{
957  UInt uiSymbol;
958  const UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth );
959  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA: eType, uiCtx ) );
960#if !H_MV_ENC_DEC_TRAC 
961  DTRACE_CABAC_VL( g_nSymbolCounter++ )
962  DTRACE_CABAC_T( "\tparseQtCbf()" )
963  DTRACE_CABAC_T( "\tsymbol=" )
964  DTRACE_CABAC_V( uiSymbol )
965  DTRACE_CABAC_T( "\tctx=" )
966  DTRACE_CABAC_V( uiCtx )
967  DTRACE_CABAC_T( "\tetype=" )
968  DTRACE_CABAC_V( eType )
969  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
970  DTRACE_CABAC_V( uiAbsPartIdx )
971  DTRACE_CABAC_T( "\n" )
972#else
973  if ( eType == TEXT_CHROMA_U )
974  {
975    DTRACE_TU("cbf_cb", uiSymbol )
976  }
977  else if ( eType == TEXT_CHROMA_V )
978  {
979    DTRACE_TU("cbf_cr", uiSymbol )
980  }
981  else
982  {
983    DTRACE_TU("cbf_luma", uiSymbol )
984  }
985#endif
986 
987  pcCU->setCbfSubParts( uiSymbol << uiTrDepth, eType, uiAbsPartIdx, uiDepth );
988}
989
990void TDecSbac::parseTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType)
991{
992  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
993  {
994    return;
995  }
996  if(width != 4 || height != 4)
997  {
998    return;
999  }
1000 
1001  UInt useTransformSkip;
1002  m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) );
1003  if(eTType!= TEXT_LUMA)
1004  {
1005    const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiDepth;
1006    if(uiLog2TrafoSize == 2) 
1007    { 
1008      uiDepth --;
1009    }
1010  }
1011#if !H_MV_ENC_DEC_TRAC
1012  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1013  DTRACE_CABAC_T("\tparseTransformSkip()");
1014  DTRACE_CABAC_T( "\tsymbol=" )
1015  DTRACE_CABAC_V( useTransformSkip )
1016  DTRACE_CABAC_T( "\tAddr=" )
1017  DTRACE_CABAC_V( pcCU->getAddr() )
1018  DTRACE_CABAC_T( "\tetype=" )
1019  DTRACE_CABAC_V( eTType )
1020  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1021  DTRACE_CABAC_V( uiAbsPartIdx )
1022  DTRACE_CABAC_T( "\n" )
1023#endif
1024
1025  pcCU->setTransformSkipSubParts( useTransformSkip, eTType, uiAbsPartIdx, uiDepth);
1026}
1027
1028/** Parse (X,Y) position of the last significant coefficient
1029 * \param uiPosLastX reference to X component of last coefficient
1030 * \param uiPosLastY reference to Y component of last coefficient
1031 * \param width  Block width
1032 * \param height Block height
1033 * \param eTType plane type / luminance or chrominance
1034 * \param uiScanIdx scan type (zig-zag, hor, ver)
1035 *
1036 * This method decodes the X and Y component within a block of the last significant coefficient.
1037 */
1038Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, TextType eTType, UInt uiScanIdx )
1039{
1040  UInt uiLast;
1041  ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType );
1042  ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType );
1043
1044  Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY;
1045  blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2));
1046  blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2));
1047  shiftX= eTType ? g_aucConvertToBit[ width  ] :((g_aucConvertToBit[ width  ]+3)>>2);
1048  shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2);
1049  // posX
1050  for( uiPosLastX = 0; uiPosLastX < g_uiGroupIdx[ width - 1 ]; uiPosLastX++ )
1051  {
1052    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + blkSizeOffsetX + (uiPosLastX >>shiftX) ) );
1053    if( !uiLast )
1054    {
1055      break;
1056    }
1057  }
1058
1059  // posY
1060  for( uiPosLastY = 0; uiPosLastY < g_uiGroupIdx[ height - 1 ]; uiPosLastY++ )
1061  {
1062    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + blkSizeOffsetY + (uiPosLastY >>shiftY)) );
1063    if( !uiLast )
1064    {
1065      break;
1066    }
1067  }
1068  if ( uiPosLastX > 3 )
1069  {
1070    UInt uiTemp  = 0;
1071    UInt uiCount = ( uiPosLastX - 2 ) >> 1;
1072    for ( Int i = uiCount - 1; i >= 0; i-- )
1073    {
1074      m_pcTDecBinIf->decodeBinEP( uiLast );
1075      uiTemp += uiLast << i;
1076    }
1077    uiPosLastX = g_uiMinInGroup[ uiPosLastX ] + uiTemp;
1078  }
1079  if ( uiPosLastY > 3 )
1080  {
1081    UInt uiTemp  = 0;
1082    UInt uiCount = ( uiPosLastY - 2 ) >> 1;
1083    for ( Int i = uiCount - 1; i >= 0; i-- )
1084    {
1085      m_pcTDecBinIf->decodeBinEP( uiLast );
1086      uiTemp += uiLast << i;
1087    }
1088    uiPosLastY = g_uiMinInGroup[ uiPosLastY ] + uiTemp;
1089  }
1090 
1091  if( uiScanIdx == SCAN_VER )
1092  {
1093    swap( uiPosLastX, uiPosLastY );
1094  }
1095}
1096
1097Void TDecSbac::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType )
1098{
1099#if !H_MV_ENC_DEC_TRAC
1100  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1101  DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" )
1102  DTRACE_CABAC_V( eTType )
1103  DTRACE_CABAC_T( "\twidth=" )
1104  DTRACE_CABAC_V( uiWidth )
1105  DTRACE_CABAC_T( "\theight=" )
1106  DTRACE_CABAC_V( uiHeight )
1107  DTRACE_CABAC_T( "\tdepth=" )
1108  DTRACE_CABAC_V( uiDepth )
1109  DTRACE_CABAC_T( "\tabspartidx=" )
1110  DTRACE_CABAC_V( uiAbsPartIdx )
1111  DTRACE_CABAC_T( "\ttoCU-X=" )
1112  DTRACE_CABAC_V( pcCU->getCUPelX() )
1113  DTRACE_CABAC_T( "\ttoCU-Y=" )
1114  DTRACE_CABAC_V( pcCU->getCUPelY() )
1115  DTRACE_CABAC_T( "\tCU-addr=" )
1116  DTRACE_CABAC_V(  pcCU->getAddr() )
1117  DTRACE_CABAC_T( "\tinCU-X=" )
1118  DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1119  DTRACE_CABAC_T( "\tinCU-Y=" )
1120  DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1121  DTRACE_CABAC_T( "\tpredmode=" )
1122  DTRACE_CABAC_V(  pcCU->getPredictionMode( uiAbsPartIdx ) )
1123  DTRACE_CABAC_T( "\n" )
1124#endif
1125 
1126  if( uiWidth > pcCU->getSlice()->getSPS()->getMaxTrSize() )
1127  {
1128    uiWidth  = pcCU->getSlice()->getSPS()->getMaxTrSize();
1129    uiHeight = pcCU->getSlice()->getSPS()->getMaxTrSize();
1130  }
1131  if(pcCU->getSlice()->getPPS()->getUseTransformSkip())
1132  {
1133    parseTransformSkipFlags( pcCU, uiAbsPartIdx, uiWidth, uiHeight, uiDepth, eTType);
1134  }
1135
1136  eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA );
1137 
1138  //----- parse significance map -----
1139  const UInt  uiLog2BlockSize   = g_aucConvertToBit[ uiWidth ] + 2;
1140  const UInt  uiMaxNumCoeff     = uiWidth * uiHeight;
1141  const UInt  uiMaxNumCoeffM1   = uiMaxNumCoeff - 1;
1142  UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx));
1143 
1144  //===== decode last significant =====
1145  UInt uiPosLastX, uiPosLastY;
1146  parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, eTType, uiScanIdx );
1147  UInt uiBlkPosLast      = uiPosLastX + (uiPosLastY<<uiLog2BlockSize);
1148  pcCoef[ uiBlkPosLast ] = 1;
1149
1150  //===== decode significance flags =====
1151  UInt uiScanPosLast;
1152  const UInt *scan   = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize-1 ];
1153  for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ )
1154  {
1155    UInt uiBlkPos = scan[ uiScanPosLast ];
1156    if( uiBlkPosLast == uiBlkPos )
1157    {
1158      break;
1159    }
1160  }
1161
1162  ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType );
1163  ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA;
1164
1165  const Int  iLastScanSet      = uiScanPosLast >> LOG2_SCAN_SET_SIZE;
1166  UInt c1 = 1;
1167  UInt uiGoRiceParam           = 0;
1168
1169  Bool beValid; 
1170  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
1171  {
1172    beValid = false;
1173  }
1174  else 
1175  {
1176    beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0;
1177  }
1178  UInt absSum = 0;
1179
1180  UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ];
1181  ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM );
1182  const UInt uiNumBlkSide = uiWidth >> (MLS_CG_SIZE >> 1);
1183  const UInt * scanCG;
1184  {
1185    scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0  ];   
1186    if( uiLog2BlockSize == 3 )
1187    {
1188      scanCG = g_sigLastScan8x8[ uiScanIdx ];
1189    }
1190    else if( uiLog2BlockSize == 5 )
1191    {
1192      scanCG = g_sigLastScanCG32x32;
1193    }
1194  }
1195  Int  iScanPosSig             = (Int) uiScanPosLast;
1196  for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- )
1197  {
1198    Int  iSubPos     = iSubSet << LOG2_SCAN_SET_SIZE;
1199    uiGoRiceParam    = 0;
1200    Int numNonZero = 0;
1201   
1202    Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE;
1203
1204    Int pos[SCAN_SET_SIZE];
1205    if( iScanPosSig == (Int) uiScanPosLast )
1206    {
1207      lastNZPosInCG  = iScanPosSig;
1208      firstNZPosInCG = iScanPosSig;
1209      iScanPosSig--;
1210      pos[ numNonZero ] = uiBlkPosLast;
1211      numNonZero = 1;
1212    }
1213
1214    // decode significant_coeffgroup_flag
1215    Int iCGBlkPos = scanCG[ iSubSet ];
1216    Int iCGPosY   = iCGBlkPos / uiNumBlkSide;
1217    Int iCGPosX   = iCGBlkPos - (iCGPosY * uiNumBlkSide);
1218    if( iSubSet == iLastScanSet || iSubSet == 0)
1219    {
1220      uiSigCoeffGroupFlag[ iCGBlkPos ] = 1;
1221    }
1222    else
1223    {
1224      UInt uiSigCoeffGroup;
1225      UInt uiCtxSig  = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight );
1226      m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] );
1227      uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup;
1228    }
1229
1230    // decode significant_coeff_flag
1231    Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight );
1232    UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig;
1233    for( ; iScanPosSig >= iSubPos; iScanPosSig-- )
1234    {
1235      uiBlkPos  = scan[ iScanPosSig ];
1236      uiPosY    = uiBlkPos >> uiLog2BlockSize;
1237      uiPosX    = uiBlkPos - ( uiPosY << uiLog2BlockSize );
1238      uiSig     = 0;
1239     
1240      if( uiSigCoeffGroupFlag[ iCGBlkPos ] )
1241      {
1242        if( iScanPosSig > iSubPos || iSubSet == 0  || numNonZero )
1243        {
1244          uiCtxSig  = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType );
1245          m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] );
1246        }
1247        else
1248        {
1249          uiSig = 1;
1250        }
1251      }
1252      pcCoef[ uiBlkPos ] = uiSig;
1253      if( uiSig )
1254      {
1255        pos[ numNonZero ] = uiBlkPos;
1256        numNonZero ++;
1257        if( lastNZPosInCG == -1 )
1258        {
1259          lastNZPosInCG = iScanPosSig;
1260        }
1261        firstNZPosInCG = iScanPosSig;
1262      }
1263    }
1264   
1265    if( numNonZero )
1266    {
1267      Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD );
1268      absSum = 0;
1269      UInt uiCtxSet    = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0;
1270      UInt uiBin;
1271      if( c1 == 0 )
1272      {
1273        uiCtxSet++;
1274      }
1275      c1 = 1;
1276      ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet;
1277      Int absCoeff[SCAN_SET_SIZE];
1278
1279      for ( Int i = 0; i < numNonZero; i++) absCoeff[i] = 1;   
1280      Int numC1Flag = min(numNonZero, C1FLAG_NUMBER);
1281      Int firstC2FlagIdx = -1;
1282
1283      for( Int idx = 0; idx < numC1Flag; idx++ )
1284      {
1285        m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] );
1286        if( uiBin == 1 )
1287        {
1288          c1 = 0;
1289          if (firstC2FlagIdx == -1)
1290          {
1291            firstC2FlagIdx = idx;
1292          }
1293        }
1294        else if( (c1 < 3) && (c1 > 0) )
1295        {
1296          c1++;
1297        }
1298        absCoeff[ idx ] = uiBin + 1;
1299      }
1300     
1301      if (c1 == 0)
1302      {
1303        baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet;
1304        if ( firstC2FlagIdx != -1)
1305        {
1306          m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] ); 
1307          absCoeff[ firstC2FlagIdx ] = uiBin + 2;
1308        }
1309      }
1310
1311      UInt coeffSigns;
1312      if ( signHidden && beValid )
1313      {
1314        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 );
1315        coeffSigns <<= 32 - (numNonZero-1);
1316      }
1317      else
1318      {
1319        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero );
1320        coeffSigns <<= 32 - numNonZero;
1321      }
1322     
1323      Int iFirstCoeff2 = 1;   
1324      if (c1 == 0 || numNonZero > C1FLAG_NUMBER)
1325      {
1326        for( Int idx = 0; idx < numNonZero; idx++ )
1327        {
1328          UInt baseLevel  = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2) : 1;
1329
1330          if( absCoeff[ idx ] == baseLevel)
1331          {
1332            UInt uiLevel;
1333            xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam );
1334            absCoeff[ idx ] = uiLevel + baseLevel;
1335            if(absCoeff[idx]>3*(1<<uiGoRiceParam))
1336            {
1337              uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4);
1338            }
1339          }
1340
1341          if(absCoeff[ idx ] >= 2) 
1342          {
1343            iFirstCoeff2 = 0;
1344          }
1345        }
1346      }
1347
1348      for( Int idx = 0; idx < numNonZero; idx++ )
1349      {
1350        Int blkPos = pos[ idx ];
1351        // Signs applied later.
1352        pcCoef[ blkPos ] = absCoeff[ idx ];
1353        absSum += absCoeff[ idx ];
1354
1355        if ( idx == numNonZero-1 && signHidden && beValid )
1356        {
1357          // Infer sign of 1st element.
1358          if (absSum&0x1)
1359          {
1360            pcCoef[ blkPos ] = -pcCoef[ blkPos ];
1361          }
1362        }
1363        else
1364        {
1365          Int sign = static_cast<Int>( coeffSigns ) >> 31;
1366          pcCoef[ blkPos ] = ( pcCoef[ blkPos ] ^ sign ) - sign;
1367          coeffSigns <<= 1;
1368        }
1369      }
1370    }
1371  }
1372 
1373  return;
1374}
1375
1376
1377Void TDecSbac::parseSaoMaxUvlc ( UInt& val, UInt maxSymbol )
1378{
1379  if (maxSymbol == 0)
1380  {
1381    val = 0;
1382    return;
1383  }
1384
1385  UInt code;
1386  Int  i;
1387  m_pcTDecBinIf->decodeBinEP( code );
1388  if ( code == 0 )
1389  {
1390    val = 0;
1391    return;
1392  }
1393
1394  i=1;
1395  while (1)
1396  {
1397    m_pcTDecBinIf->decodeBinEP( code );
1398    if ( code == 0 )
1399    {
1400      break;
1401    }
1402    i++;
1403    if (i == maxSymbol) 
1404    {
1405      break;
1406    }
1407  }
1408
1409  val = i;
1410}
1411Void TDecSbac::parseSaoUflc (UInt uiLength, UInt&  riVal)
1412{
1413  m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength );
1414}
1415Void TDecSbac::parseSaoMerge (UInt&  ruiVal)
1416{
1417  UInt uiCode;
1418  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) );
1419  ruiVal = (Int)uiCode;
1420}
1421Void TDecSbac::parseSaoTypeIdx (UInt&  ruiVal)
1422{
1423  UInt uiCode;
1424  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
1425  if (uiCode == 0) 
1426  {
1427    ruiVal = 0;
1428  }
1429  else
1430  {
1431    m_pcTDecBinIf->decodeBinEP( uiCode ); 
1432    if (uiCode == 0)
1433    {
1434      ruiVal = 1;
1435    }
1436    else
1437    {
1438      ruiVal = 2;
1439    }
1440  }
1441}
1442
1443Void TDecSbac::parseSaoSign(UInt& val)
1444{
1445  m_pcTDecBinIf->decodeBinEP ( val ); 
1446}
1447
1448Void TDecSbac::parseSAOBlkParam (SAOBlkParam& saoBlkParam
1449                                , Bool* sliceEnabled
1450                                , Bool leftMergeAvail
1451                                , Bool aboveMergeAvail
1452                                )
1453{
1454  UInt uiSymbol;
1455
1456  Bool isLeftMerge = false;
1457  Bool isAboveMerge= false;
1458
1459  if(leftMergeAvail)
1460  {
1461    parseSaoMerge(uiSymbol); //sao_merge_left_flag
1462    isLeftMerge = (uiSymbol?true:false);
1463  }
1464
1465  if( aboveMergeAvail && !isLeftMerge)
1466  {
1467    parseSaoMerge(uiSymbol); //sao_merge_up_flag
1468    isAboveMerge = (uiSymbol?true:false);
1469  }
1470
1471  if(isLeftMerge || isAboveMerge) //merge mode
1472      {
1473    saoBlkParam[SAO_Y].modeIdc = saoBlkParam[SAO_Cb].modeIdc = saoBlkParam[SAO_Cr].modeIdc = SAO_MODE_MERGE;
1474    saoBlkParam[SAO_Y].typeIdc = saoBlkParam[SAO_Cb].typeIdc = saoBlkParam[SAO_Cr].typeIdc = (isLeftMerge)?SAO_MERGE_LEFT:SAO_MERGE_ABOVE;
1475      }   
1476  else //new or off mode
1477      {
1478    for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
1479        {
1480      SAOOffset& ctbParam = saoBlkParam[compIdx];
1481
1482      if(!sliceEnabled[compIdx])
1483          {
1484        //off
1485        ctbParam.modeIdc = SAO_MODE_OFF;
1486        continue;
1487        }
1488
1489      //type
1490      if(compIdx == SAO_Y || compIdx == SAO_Cb)
1491    {
1492        parseSaoTypeIdx(uiSymbol); //sao_type_idx_luma or sao_type_idx_chroma
1493
1494        assert(uiSymbol ==0 || uiSymbol ==1 || uiSymbol ==2);
1495
1496        if(uiSymbol ==0) //OFF
1497     {
1498          ctbParam.modeIdc = SAO_MODE_OFF;
1499   }
1500        else if(uiSymbol == 1) //BO
1501        {
1502          ctbParam.modeIdc = SAO_MODE_NEW;
1503          ctbParam.typeIdc = SAO_TYPE_START_BO;
1504  }
1505        else //2, EO
1506  {
1507          ctbParam.modeIdc = SAO_MODE_NEW;
1508          ctbParam.typeIdc = SAO_TYPE_START_EO;
1509        }
1510
1511  }
1512      else //Cr, follow Cb SAO type
1513      {
1514        ctbParam.modeIdc = saoBlkParam[SAO_Cb].modeIdc;
1515        ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc;
1516}
1517
1518      if(ctbParam.modeIdc == SAO_MODE_NEW)
1519{
1520        Int offset[4];
1521        for(Int i=0; i< 4; i++)
1522  {
1523          parseSaoMaxUvlc(uiSymbol,  g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
1524          offset[i] = (Int)uiSymbol;
1525  }
1526
1527        if(ctbParam.typeIdc == SAO_TYPE_START_BO)
1528  {
1529          for(Int i=0; i< 4; i++)
1530    {
1531            if(offset[i] != 0)
1532    {
1533              parseSaoSign(uiSymbol); //sao_offset_sign
1534              if(uiSymbol)
1535      {
1536                offset[i] = -offset[i];
1537      }
1538    }
1539  }
1540          parseSaoUflc(NUM_SAO_BO_CLASSES_LOG2, uiSymbol ); //sao_band_position
1541          ctbParam.typeAuxInfo = uiSymbol;
1542
1543          for(Int i=0; i<4; i++)
1544      {
1545            ctbParam.offset[(ctbParam.typeAuxInfo+i)%MAX_NUM_SAO_CLASSES] = offset[i];
1546      }
1547
1548        }
1549        else //EO
1550        {
1551          ctbParam.typeAuxInfo = 0;
1552
1553          if(compIdx == SAO_Y || compIdx == SAO_Cb)
1554        {
1555            parseSaoUflc(NUM_SAO_EO_TYPES_LOG2, uiSymbol ); //sao_eo_class_luma or sao_eo_class_chroma
1556            ctbParam.typeIdc += uiSymbol;
1557        }
1558        else
1559        {
1560            ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc;
1561        }
1562          ctbParam.offset[SAO_CLASS_EO_FULL_VALLEY] = offset[0];
1563          ctbParam.offset[SAO_CLASS_EO_HALF_VALLEY] = offset[1];
1564          ctbParam.offset[SAO_CLASS_EO_PLAIN      ] = 0;
1565          ctbParam.offset[SAO_CLASS_EO_HALF_PEAK  ] = -offset[2];
1566          ctbParam.offset[SAO_CLASS_EO_FULL_PEAK  ] = -offset[3];
1567      }
1568      }
1569    }
1570  }
1571}
1572
1573/**
1574 - Initialize our contexts from the nominated source.
1575 .
1576 \param pSrc Contexts to be copied.
1577 */
1578Void TDecSbac::xCopyContextsFrom( TDecSbac* pSrc )
1579{
1580  memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0]));
1581}
1582
1583Void TDecSbac::xCopyFrom( TDecSbac* pSrc )
1584{
1585  m_pcTDecBinIf->copyState( pSrc->m_pcTDecBinIf );
1586
1587  m_uiLastQp           = pSrc->m_uiLastQp;
1588  xCopyContextsFrom( pSrc );
1589
1590}
1591
1592Void TDecSbac::load ( TDecSbac* pScr )
1593{
1594  xCopyFrom(pScr);
1595}
1596
1597Void TDecSbac::loadContexts ( TDecSbac* pScr )
1598{
1599  xCopyContextsFrom(pScr);
1600}
1601
1602
1603
1604
1605
1606
1607
1608//! \}
Note: See TracBrowser for help on using the repository browser.