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

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

Removed 3D-HEVC related code.

  • Property svn:eol-style set to native
File size: 48.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, 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    piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset;
356    uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
357    uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
358    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
359
360    for(uiY = 0; uiY < uiHeight; uiY++)
361    {
362      for(uiX = 0; uiX < uiWidth; uiX++)
363      {
364        UInt uiSample;
365        m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
366        piPCMSample[uiX] = uiSample;
367      }
368      piPCMSample += uiWidth;
369    }
370
371    piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset;
372    uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
373    uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
374    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
375
376    for(uiY = 0; uiY < uiHeight; uiY++)
377    {
378      for(uiX = 0; uiX < uiWidth; uiX++)
379      {
380        UInt uiSample;
381        m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
382        piPCMSample[uiX] = uiSample;
383      }
384      piPCMSample += uiWidth;
385    }
386
387    m_pcTDecBinIf->start();
388  }
389}
390
391Void TDecSbac::parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
392{
393  UInt uiSymbol;
394  m_pcTDecBinIf->decodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) );
395#if H_MV_ENC_DEC_TRAC
396  DTRACE_CU("cu_transquant_bypass_flag", uiSymbol); 
397#endif
398  pcCU->setCUTransquantBypassSubParts(uiSymbol ? true : false, uiAbsPartIdx, uiDepth);
399}
400
401/** parse skip flag
402 * \param pcCU
403 * \param uiAbsPartIdx
404 * \param uiDepth
405 * \returns Void
406 */
407Void TDecSbac::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
408{
409  if( pcCU->getSlice()->isIntra() )
410  {
411    return;
412  }
413 
414  UInt uiSymbol = 0;
415  UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx );
416  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) );
417#if !H_MV_ENC_DEC_TRAC
418  DTRACE_CABAC_VL( g_nSymbolCounter++ );
419  DTRACE_CABAC_T( "\tSkipFlag" );
420  DTRACE_CABAC_T( "\tuiCtxSkip: ");
421  DTRACE_CABAC_V( uiCtxSkip );
422  DTRACE_CABAC_T( "\tuiSymbol: ");
423  DTRACE_CABAC_V( uiSymbol );
424  DTRACE_CABAC_T( "\n");
425#endif
426 
427  if( uiSymbol )
428  {
429    pcCU->setSkipFlagSubParts( true,        uiAbsPartIdx, uiDepth );
430    pcCU->setPredModeSubParts( MODE_INTER,  uiAbsPartIdx, uiDepth );
431    pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
432    pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
433    pcCU->setMergeFlagSubParts( true , uiAbsPartIdx, 0, uiDepth );
434  }
435#if H_MV_ENC_DEC_TRAC
436  DTRACE_CU("cu_skip_flag", uiSymbol); 
437#endif
438}
439/** parse merge flag
440 * \param pcCU
441 * \param uiAbsPartIdx
442 * \param uiDepth
443 * \param uiPUIdx
444 * \returns Void
445 */
446Void TDecSbac::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
447{
448  UInt uiSymbol;
449  m_pcTDecBinIf->decodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) );
450#if H_MV_ENC_DEC_TRAC
451  DTRACE_PU("merge_flag", uiSymbol)
452#endif
453  pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth );
454
455#if !H_MV_ENC_DEC_TRAC
456  DTRACE_CABAC_VL( g_nSymbolCounter++ );
457  DTRACE_CABAC_T( "\tMergeFlag: " );
458  DTRACE_CABAC_V( uiSymbol );
459  DTRACE_CABAC_T( "\tAddress: " );
460  DTRACE_CABAC_V( pcCU->getAddr() );
461  DTRACE_CABAC_T( "\tuiAbsPartIdx: " );
462  DTRACE_CABAC_V( uiAbsPartIdx );
463  DTRACE_CABAC_T( "\n" );
464#endif
465}
466
467Void TDecSbac::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex )
468{
469  UInt uiUnaryIdx = 0;
470  UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand();
471  if ( uiNumCand > 1 )
472  {
473    for( ; uiUnaryIdx < uiNumCand - 1; ++uiUnaryIdx )
474    {
475      UInt uiSymbol = 0;
476      if ( uiUnaryIdx==0 )
477      {
478        m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) );
479      }
480      else
481      {
482        m_pcTDecBinIf->decodeBinEP( uiSymbol );
483      }
484      if( uiSymbol == 0 )
485      {
486        break;
487      }
488    }
489#if H_MV_ENC_DEC_TRAC
490    DTRACE_PU("merge_idx", uiUnaryIdx)
491#endif
492  }
493  ruiMergeIndex = uiUnaryIdx;
494
495#if !H_MV_ENC_DEC_TRAC
496  DTRACE_CABAC_VL( g_nSymbolCounter++ )
497  DTRACE_CABAC_T( "\tparseMergeIndex()" )
498  DTRACE_CABAC_T( "\tuiMRGIdx= " )
499  DTRACE_CABAC_V( ruiMergeIndex )
500  DTRACE_CABAC_T( "\n" )
501#endif
502}
503
504Void TDecSbac::parseMVPIdx      ( Int& riMVPIdx )
505{
506  UInt uiSymbol;
507  xReadUnaryMaxSymbol(uiSymbol, m_cMVPIdxSCModel.get(0), 1, AMVP_MAX_NUM_CANDS-1);
508  riMVPIdx = uiSymbol;
509}
510
511Void TDecSbac::parseSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
512{
513  if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
514  {
515    pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx );
516    return;
517  }
518
519  UInt uiSymbol;
520    m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSplitFlagSCModel.get( 0, 0, pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ) ) );
521#if H_MV_ENC_DEC_TRAC
522    DTRACE_CU("split_cu_flag", uiSymbol); 
523#else
524    DTRACE_CABAC_VL( g_nSymbolCounter++ )
525    DTRACE_CABAC_T( "\tSplitFlag\n" )
526#endif
527  pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx );
528 
529  return;
530}
531
532/** parse partition size
533 * \param pcCU
534 * \param uiAbsPartIdx
535 * \param uiDepth
536 * \returns Void
537 */
538Void TDecSbac::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
539{
540  UInt uiSymbol, uiMode = 0;
541  PartSize eMode;
542
543
544 
545  if ( pcCU->isIntra( uiAbsPartIdx ) )
546  {
547     uiSymbol = 1;
548      if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
549      {
550        m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 0) );
551#if H_MV_ENC_DEC_TRAC         
552        DTRACE_CU("part_mode", uiSymbol)
553#endif       
554      }
555      eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN;
556    UInt uiTrLevel = 0;   
557    UInt uiWidthInBit  = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2;
558    UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2;
559    uiTrLevel          = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0;
560    if( eMode == SIZE_NxN )
561    {
562      pcCU->setTrIdxSubParts( 1+uiTrLevel, uiAbsPartIdx, uiDepth );
563    }
564    else
565    {
566      pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth );
567    }
568  }
569  else
570  {
571      UInt uiMaxNumBits = 2;
572      if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( (g_uiMaxCUWidth>>uiDepth) == 8 && (g_uiMaxCUHeight>>uiDepth) == 8 ) )
573      {
574        uiMaxNumBits ++;
575      }
576      for ( UInt ui = 0; ui < uiMaxNumBits; ui++ )
577      {
578        m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) );
579        if ( uiSymbol )
580        {
581          break;
582        }
583        uiMode++;
584      }
585      eMode = (PartSize) uiMode;
586      if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) )
587      {
588        if (eMode == SIZE_2NxN)
589        {
590        m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
591          if (uiSymbol == 0)
592          {
593            m_pcTDecBinIf->decodeBinEP(uiSymbol);
594            eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD);
595          }
596        }
597        else if (eMode == SIZE_Nx2N)
598        {
599        m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
600          if (uiSymbol == 0)
601          {
602            m_pcTDecBinIf->decodeBinEP(uiSymbol);
603            eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N);
604          }
605        }
606      }
607#if H_MV_ENC_DEC_TRAC         
608      DTRACE_CU("part_mode", eMode )
609#endif
610  }
611  pcCU->setPartSizeSubParts( eMode, uiAbsPartIdx, uiDepth );
612  pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
613}
614
615/** parse prediction mode
616 * \param pcCU
617 * \param uiAbsPartIdx
618 * \param uiDepth
619 * \returns Void
620 */
621Void TDecSbac::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
622{
623  if( pcCU->getSlice()->isIntra() )
624  {
625    pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth );
626    return;
627  }
628 
629  UInt uiSymbol;
630  Int  iPredMode = MODE_INTER;
631  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPredModeSCModel.get( 0, 0, 0 ) );
632  iPredMode += uiSymbol;
633#if H_MV_ENC_DEC_TRAC         
634  DTRACE_CU("pred_mode_flag", uiSymbol)
635#endif       
636  pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth );
637}
638
639Void TDecSbac::parseIntraDirLumaAng  ( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
640{
641  PartSize mode = pcCU->getPartitionSize( absPartIdx );
642  UInt partNum = mode==SIZE_NxN?4:1;
643  UInt partOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2;
644  UInt mpmPred[4],symbol;
645  Int j,intraPredMode;   
646  if (mode==SIZE_NxN)
647  {
648    depth++;
649  }
650  for (j=0;j<partNum;j++)
651  {
652    m_pcTDecBinIf->decodeBin( symbol, m_cCUIntraPredSCModel.get( 0, 0, 0) );
653    mpmPred[j] = symbol;
654#if H_MV_ENC_DEC_TRAC         
655    DTRACE_CU("prev_intra_luma_pred_flag", symbol)
656#endif
657  }
658  for (j=0;j<partNum;j++)
659  {
660    Int preds[3] = {-1, -1, -1};
661    Int predNum = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds); 
662    if (mpmPred[j])
663    {
664      m_pcTDecBinIf->decodeBinEP( symbol );
665      if (symbol)
666      {
667        m_pcTDecBinIf->decodeBinEP( symbol );
668        symbol++;
669      }
670#if H_MV_ENC_DEC_TRAC         
671      DTRACE_CU("mpm_idx", symbol)
672#endif
673      intraPredMode = preds[symbol];
674    }
675    else
676    {
677      m_pcTDecBinIf->decodeBinsEP( symbol, 5 );
678      intraPredMode = symbol;
679#if H_MV_ENC_DEC_TRAC         
680      DTRACE_CU("rem_intra_luma_pred_mode", symbol)
681#endif       
682      //postponed sorting of MPMs (only in remaining branch)
683      if (preds[0] > preds[1])
684      { 
685        std::swap(preds[0], preds[1]); 
686      }
687      if (preds[0] > preds[2])
688      {
689        std::swap(preds[0], preds[2]);
690      }
691      if (preds[1] > preds[2])
692      {
693        std::swap(preds[1], preds[2]);
694      }
695      for ( Int i = 0; i < predNum; i++ )
696      {
697        intraPredMode += ( intraPredMode >= preds[i] );
698      }
699    }
700    pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, absPartIdx+partOffset*j, depth );
701  }
702}
703
704Void TDecSbac::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
705{
706  UInt uiSymbol;
707
708  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) );
709
710  if( uiSymbol == 0 )
711  {
712#if H_MV_ENC_DEC_TRAC         
713    DTRACE_CU("intra_chroma_pred_mode", uiSymbol )
714#endif       
715    uiSymbol = DM_CHROMA_IDX;
716  } 
717  else 
718  {
719    {
720      UInt uiIPredMode;
721      m_pcTDecBinIf->decodeBinsEP( uiIPredMode, 2 );
722#if H_MV_ENC_DEC_TRAC         
723      DTRACE_CU("intra_chroma_pred_mode", uiIPredMode )
724#endif       
725      UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ];
726      pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir );
727      uiSymbol = uiAllowedChromaDir[ uiIPredMode ];
728    }
729  }
730  pcCU->setChromIntraDirSubParts( uiSymbol, uiAbsPartIdx, uiDepth );
731  return;
732}
733
734
735Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx )
736{
737  UInt uiSymbol;
738  const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx );
739  ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 );
740  uiSymbol = 0;
741  if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 )
742  {
743    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) );
744  }
745
746  if( uiSymbol )
747  {
748    uiSymbol = 2;
749  }
750  else
751  {
752    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + 4 ) );
753    assert(uiSymbol == 0 || uiSymbol == 1);
754  }
755
756  uiSymbol++;
757  ruiInterDir = uiSymbol;
758#if H_MV_ENC_DEC_TRAC
759    DTRACE_PU("inter_pred_idc", ruiInterDir - 1 )   
760#endif
761
762  return;
763}
764
765Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList )
766{
767  UInt uiSymbol;
768  {
769    ContextModel *pCtx = m_cCURefPicSCModel.get( 0 );
770    m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
771
772    if( uiSymbol )
773    {
774      UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2;
775      pCtx++;
776      UInt ui;
777      for( ui = 0; ui < uiRefNum; ++ui )
778      {
779        if( ui == 0 )
780        {
781          m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
782        }
783        else
784        {
785          m_pcTDecBinIf->decodeBinEP( uiSymbol );
786        }
787        if( uiSymbol == 0 )
788        {
789          break;
790        }
791      }
792      uiSymbol = ui + 1;
793    }
794    riRefFrmIdx = uiSymbol;
795  }
796
797#if H_MV_ENC_DEC_TRAC
798#if ENC_DEC_TRACE
799  if ( eRefList == REF_PIC_LIST_0 )
800  {
801    DTRACE_PU("ref_idx_l0", uiSymbol)
802  }
803  else
804  {
805    DTRACE_PU("ref_idx_l1", uiSymbol)
806  }
807#endif
808#endif
809  return;
810}
811
812Void TDecSbac::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList )
813{
814  UInt uiSymbol;
815  UInt uiHorAbs;
816  UInt uiVerAbs;
817  UInt uiHorSign = 0;
818  UInt uiVerSign = 0;
819  ContextModel *pCtx = m_cCUMvdSCModel.get( 0 );
820
821  if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3)
822  {
823    uiHorAbs=0;
824    uiVerAbs=0;
825  }
826  else
827  {
828    m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx );
829    m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx );
830
831    const Bool bHorAbsGr0 = uiHorAbs != 0;
832    const Bool bVerAbsGr0 = uiVerAbs != 0;
833    pCtx++;
834
835    if( bHorAbsGr0 )
836    {
837      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
838      uiHorAbs += uiSymbol;
839    }
840
841    if( bVerAbsGr0 )
842    {
843      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
844      uiVerAbs += uiSymbol;
845    }
846
847    if( bHorAbsGr0 )
848    {
849      if( 2 == uiHorAbs )
850      {
851        xReadEpExGolomb( uiSymbol, 1 );
852        uiHorAbs += uiSymbol;
853      }
854
855      m_pcTDecBinIf->decodeBinEP( uiHorSign );
856    }
857
858    if( bVerAbsGr0 )
859    {
860      if( 2 == uiVerAbs )
861      {
862        xReadEpExGolomb( uiSymbol, 1 );
863        uiVerAbs += uiSymbol;
864      }
865
866      m_pcTDecBinIf->decodeBinEP( uiVerSign );
867    }
868
869  }
870
871  const TComMv cMv( uiHorSign ? -Int( uiHorAbs ): uiHorAbs, uiVerSign ? -Int( uiVerAbs ) : uiVerAbs );
872  pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiDepth, uiPartIdx );
873  return;
874}
875
876
877Void TDecSbac::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize )
878{
879  m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize ) );
880#if !H_MV_ENC_DEC_TRAC
881  DTRACE_CABAC_VL( g_nSymbolCounter++ )
882  DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" )
883  DTRACE_CABAC_T( "\tsymbol=" )
884  DTRACE_CABAC_V( ruiSubdivFlag )
885  DTRACE_CABAC_T( "\tctx=" )
886  DTRACE_CABAC_V( uiLog2TransformBlockSize )
887  DTRACE_CABAC_T( "\n" )
888#endif
889}
890
891Void TDecSbac::parseQtRootCbf( UInt uiAbsPartIdx, UInt& uiQtRootCbf )
892{
893  UInt uiSymbol;
894  const UInt uiCtx = 0;
895  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) );
896#if !H_MV_ENC_DEC_TRAC
897  DTRACE_CABAC_VL( g_nSymbolCounter++ )
898  DTRACE_CABAC_T( "\tparseQtRootCbf()" )
899  DTRACE_CABAC_T( "\tsymbol=" )
900  DTRACE_CABAC_V( uiSymbol )
901  DTRACE_CABAC_T( "\tctx=" )
902  DTRACE_CABAC_V( uiCtx )
903  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
904  DTRACE_CABAC_V( uiAbsPartIdx )
905  DTRACE_CABAC_T( "\n" )
906#else
907  DTRACE_CU( "rqt_root_cbf", uiSymbol )
908#endif
909 
910  uiQtRootCbf = uiSymbol;
911}
912
913Void TDecSbac::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
914{
915  Int qp;
916  UInt uiDQp;
917  Int  iDQp;
918 
919  UInt uiSymbol;
920
921  xReadUnaryMaxSymbol (uiDQp,  &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX);
922
923  if( uiDQp >= CU_DQP_TU_CMAX)
924  {
925    xReadEpExGolomb( uiSymbol, CU_DQP_EG_k );
926    uiDQp+=uiSymbol;
927  }
928
929  if ( uiDQp > 0 )
930  {
931    UInt uiSign;
932    Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
933    m_pcTDecBinIf->decodeBinEP(uiSign);
934    iDQp = uiDQp;
935    if(uiSign)
936    {
937      iDQp = -iDQp;
938    }
939    qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY;
940  }
941  else 
942  {
943    qp = pcCU->getRefQP(uiAbsPartIdx);
944  }
945  pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth); 
946  pcCU->setCodedQP(qp);
947}
948
949Void TDecSbac::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth )
950{
951  UInt uiSymbol;
952  const UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth );
953  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA: eType, uiCtx ) );
954#if !H_MV_ENC_DEC_TRAC 
955  DTRACE_CABAC_VL( g_nSymbolCounter++ )
956  DTRACE_CABAC_T( "\tparseQtCbf()" )
957  DTRACE_CABAC_T( "\tsymbol=" )
958  DTRACE_CABAC_V( uiSymbol )
959  DTRACE_CABAC_T( "\tctx=" )
960  DTRACE_CABAC_V( uiCtx )
961  DTRACE_CABAC_T( "\tetype=" )
962  DTRACE_CABAC_V( eType )
963  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
964  DTRACE_CABAC_V( uiAbsPartIdx )
965  DTRACE_CABAC_T( "\n" )
966#endif
967 
968  pcCU->setCbfSubParts( uiSymbol << uiTrDepth, eType, uiAbsPartIdx, uiDepth );
969}
970
971void TDecSbac::parseTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType)
972{
973  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
974  {
975    return;
976  }
977  if(width != 4 || height != 4)
978  {
979    return;
980  }
981 
982  UInt useTransformSkip;
983  m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) );
984  if(eTType!= TEXT_LUMA)
985  {
986    const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiDepth;
987    if(uiLog2TrafoSize == 2) 
988    { 
989      uiDepth --;
990    }
991  }
992#if !H_MV_ENC_DEC_TRAC
993  DTRACE_CABAC_VL( g_nSymbolCounter++ )
994  DTRACE_CABAC_T("\tparseTransformSkip()");
995  DTRACE_CABAC_T( "\tsymbol=" )
996  DTRACE_CABAC_V( useTransformSkip )
997  DTRACE_CABAC_T( "\tAddr=" )
998  DTRACE_CABAC_V( pcCU->getAddr() )
999  DTRACE_CABAC_T( "\tetype=" )
1000  DTRACE_CABAC_V( eTType )
1001  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1002  DTRACE_CABAC_V( uiAbsPartIdx )
1003  DTRACE_CABAC_T( "\n" )
1004#endif
1005
1006  pcCU->setTransformSkipSubParts( useTransformSkip, eTType, uiAbsPartIdx, uiDepth);
1007}
1008
1009/** Parse (X,Y) position of the last significant coefficient
1010 * \param uiPosLastX reference to X component of last coefficient
1011 * \param uiPosLastY reference to Y component of last coefficient
1012 * \param width  Block width
1013 * \param height Block height
1014 * \param eTType plane type / luminance or chrominance
1015 * \param uiScanIdx scan type (zig-zag, hor, ver)
1016 *
1017 * This method decodes the X and Y component within a block of the last significant coefficient.
1018 */
1019Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, TextType eTType, UInt uiScanIdx )
1020{
1021  UInt uiLast;
1022  ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType );
1023  ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType );
1024
1025  Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY;
1026  blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2));
1027  blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2));
1028  shiftX= eTType ? g_aucConvertToBit[ width  ] :((g_aucConvertToBit[ width  ]+3)>>2);
1029  shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2);
1030  // posX
1031  for( uiPosLastX = 0; uiPosLastX < g_uiGroupIdx[ width - 1 ]; uiPosLastX++ )
1032  {
1033    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + blkSizeOffsetX + (uiPosLastX >>shiftX) ) );
1034    if( !uiLast )
1035    {
1036      break;
1037    }
1038  }
1039
1040  // posY
1041  for( uiPosLastY = 0; uiPosLastY < g_uiGroupIdx[ height - 1 ]; uiPosLastY++ )
1042  {
1043    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + blkSizeOffsetY + (uiPosLastY >>shiftY)) );
1044    if( !uiLast )
1045    {
1046      break;
1047    }
1048  }
1049  if ( uiPosLastX > 3 )
1050  {
1051    UInt uiTemp  = 0;
1052    UInt uiCount = ( uiPosLastX - 2 ) >> 1;
1053    for ( Int i = uiCount - 1; i >= 0; i-- )
1054    {
1055      m_pcTDecBinIf->decodeBinEP( uiLast );
1056      uiTemp += uiLast << i;
1057    }
1058    uiPosLastX = g_uiMinInGroup[ uiPosLastX ] + uiTemp;
1059  }
1060  if ( uiPosLastY > 3 )
1061  {
1062    UInt uiTemp  = 0;
1063    UInt uiCount = ( uiPosLastY - 2 ) >> 1;
1064    for ( Int i = uiCount - 1; i >= 0; i-- )
1065    {
1066      m_pcTDecBinIf->decodeBinEP( uiLast );
1067      uiTemp += uiLast << i;
1068    }
1069    uiPosLastY = g_uiMinInGroup[ uiPosLastY ] + uiTemp;
1070  }
1071 
1072  if( uiScanIdx == SCAN_VER )
1073  {
1074    swap( uiPosLastX, uiPosLastY );
1075  }
1076}
1077
1078Void TDecSbac::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType )
1079{
1080#if !H_MV_ENC_DEC_TRAC
1081  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1082  DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" )
1083  DTRACE_CABAC_V( eTType )
1084  DTRACE_CABAC_T( "\twidth=" )
1085  DTRACE_CABAC_V( uiWidth )
1086  DTRACE_CABAC_T( "\theight=" )
1087  DTRACE_CABAC_V( uiHeight )
1088  DTRACE_CABAC_T( "\tdepth=" )
1089  DTRACE_CABAC_V( uiDepth )
1090  DTRACE_CABAC_T( "\tabspartidx=" )
1091  DTRACE_CABAC_V( uiAbsPartIdx )
1092  DTRACE_CABAC_T( "\ttoCU-X=" )
1093  DTRACE_CABAC_V( pcCU->getCUPelX() )
1094  DTRACE_CABAC_T( "\ttoCU-Y=" )
1095  DTRACE_CABAC_V( pcCU->getCUPelY() )
1096  DTRACE_CABAC_T( "\tCU-addr=" )
1097  DTRACE_CABAC_V(  pcCU->getAddr() )
1098  DTRACE_CABAC_T( "\tinCU-X=" )
1099  DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1100  DTRACE_CABAC_T( "\tinCU-Y=" )
1101  DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1102  DTRACE_CABAC_T( "\tpredmode=" )
1103  DTRACE_CABAC_V(  pcCU->getPredictionMode( uiAbsPartIdx ) )
1104  DTRACE_CABAC_T( "\n" )
1105#endif
1106 
1107  if( uiWidth > pcCU->getSlice()->getSPS()->getMaxTrSize() )
1108  {
1109    uiWidth  = pcCU->getSlice()->getSPS()->getMaxTrSize();
1110    uiHeight = pcCU->getSlice()->getSPS()->getMaxTrSize();
1111  }
1112  if(pcCU->getSlice()->getPPS()->getUseTransformSkip())
1113  {
1114    parseTransformSkipFlags( pcCU, uiAbsPartIdx, uiWidth, uiHeight, uiDepth, eTType);
1115  }
1116
1117  eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA );
1118 
1119  //----- parse significance map -----
1120  const UInt  uiLog2BlockSize   = g_aucConvertToBit[ uiWidth ] + 2;
1121  const UInt  uiMaxNumCoeff     = uiWidth * uiHeight;
1122  const UInt  uiMaxNumCoeffM1   = uiMaxNumCoeff - 1;
1123  UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx));
1124 
1125  //===== decode last significant =====
1126  UInt uiPosLastX, uiPosLastY;
1127  parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, eTType, uiScanIdx );
1128  UInt uiBlkPosLast      = uiPosLastX + (uiPosLastY<<uiLog2BlockSize);
1129  pcCoef[ uiBlkPosLast ] = 1;
1130
1131  //===== decode significance flags =====
1132  UInt uiScanPosLast;
1133  const UInt *scan   = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize-1 ];
1134  for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ )
1135  {
1136    UInt uiBlkPos = scan[ uiScanPosLast ];
1137    if( uiBlkPosLast == uiBlkPos )
1138    {
1139      break;
1140    }
1141  }
1142
1143  ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType );
1144  ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA;
1145
1146  const Int  iLastScanSet      = uiScanPosLast >> LOG2_SCAN_SET_SIZE;
1147  UInt c1 = 1;
1148  UInt uiGoRiceParam           = 0;
1149
1150  Bool beValid; 
1151  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
1152  {
1153    beValid = false;
1154  }
1155  else 
1156  {
1157    beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0;
1158  }
1159  UInt absSum = 0;
1160
1161  UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ];
1162  ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM );
1163  const UInt uiNumBlkSide = uiWidth >> (MLS_CG_SIZE >> 1);
1164  const UInt * scanCG;
1165  {
1166    scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0  ];   
1167    if( uiLog2BlockSize == 3 )
1168    {
1169      scanCG = g_sigLastScan8x8[ uiScanIdx ];
1170    }
1171    else if( uiLog2BlockSize == 5 )
1172    {
1173      scanCG = g_sigLastScanCG32x32;
1174    }
1175  }
1176  Int  iScanPosSig             = (Int) uiScanPosLast;
1177  for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- )
1178  {
1179    Int  iSubPos     = iSubSet << LOG2_SCAN_SET_SIZE;
1180    uiGoRiceParam    = 0;
1181    Int numNonZero = 0;
1182   
1183    Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE;
1184
1185    Int pos[SCAN_SET_SIZE];
1186    if( iScanPosSig == (Int) uiScanPosLast )
1187    {
1188      lastNZPosInCG  = iScanPosSig;
1189      firstNZPosInCG = iScanPosSig;
1190      iScanPosSig--;
1191      pos[ numNonZero ] = uiBlkPosLast;
1192      numNonZero = 1;
1193    }
1194
1195    // decode significant_coeffgroup_flag
1196    Int iCGBlkPos = scanCG[ iSubSet ];
1197    Int iCGPosY   = iCGBlkPos / uiNumBlkSide;
1198    Int iCGPosX   = iCGBlkPos - (iCGPosY * uiNumBlkSide);
1199    if( iSubSet == iLastScanSet || iSubSet == 0)
1200    {
1201      uiSigCoeffGroupFlag[ iCGBlkPos ] = 1;
1202    }
1203    else
1204    {
1205      UInt uiSigCoeffGroup;
1206      UInt uiCtxSig  = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight );
1207      m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] );
1208      uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup;
1209    }
1210
1211    // decode significant_coeff_flag
1212    Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight );
1213    UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig;
1214    for( ; iScanPosSig >= iSubPos; iScanPosSig-- )
1215    {
1216      uiBlkPos  = scan[ iScanPosSig ];
1217      uiPosY    = uiBlkPos >> uiLog2BlockSize;
1218      uiPosX    = uiBlkPos - ( uiPosY << uiLog2BlockSize );
1219      uiSig     = 0;
1220     
1221      if( uiSigCoeffGroupFlag[ iCGBlkPos ] )
1222      {
1223        if( iScanPosSig > iSubPos || iSubSet == 0  || numNonZero )
1224        {
1225          uiCtxSig  = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType );
1226          m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] );
1227        }
1228        else
1229        {
1230          uiSig = 1;
1231        }
1232      }
1233      pcCoef[ uiBlkPos ] = uiSig;
1234      if( uiSig )
1235      {
1236        pos[ numNonZero ] = uiBlkPos;
1237        numNonZero ++;
1238        if( lastNZPosInCG == -1 )
1239        {
1240          lastNZPosInCG = iScanPosSig;
1241        }
1242        firstNZPosInCG = iScanPosSig;
1243      }
1244    }
1245   
1246    if( numNonZero )
1247    {
1248      Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD );
1249      absSum = 0;
1250      UInt uiCtxSet    = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0;
1251      UInt uiBin;
1252      if( c1 == 0 )
1253      {
1254        uiCtxSet++;
1255      }
1256      c1 = 1;
1257      ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet;
1258      Int absCoeff[SCAN_SET_SIZE];
1259
1260      for ( Int i = 0; i < numNonZero; i++) absCoeff[i] = 1;   
1261      Int numC1Flag = min(numNonZero, C1FLAG_NUMBER);
1262      Int firstC2FlagIdx = -1;
1263
1264      for( Int idx = 0; idx < numC1Flag; idx++ )
1265      {
1266        m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] );
1267        if( uiBin == 1 )
1268        {
1269          c1 = 0;
1270          if (firstC2FlagIdx == -1)
1271          {
1272            firstC2FlagIdx = idx;
1273          }
1274        }
1275        else if( (c1 < 3) && (c1 > 0) )
1276        {
1277          c1++;
1278        }
1279        absCoeff[ idx ] = uiBin + 1;
1280      }
1281     
1282      if (c1 == 0)
1283      {
1284        baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet;
1285        if ( firstC2FlagIdx != -1)
1286        {
1287          m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] ); 
1288          absCoeff[ firstC2FlagIdx ] = uiBin + 2;
1289        }
1290      }
1291
1292      UInt coeffSigns;
1293      if ( signHidden && beValid )
1294      {
1295        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 );
1296        coeffSigns <<= 32 - (numNonZero-1);
1297      }
1298      else
1299      {
1300        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero );
1301        coeffSigns <<= 32 - numNonZero;
1302      }
1303     
1304      Int iFirstCoeff2 = 1;   
1305      if (c1 == 0 || numNonZero > C1FLAG_NUMBER)
1306      {
1307        for( Int idx = 0; idx < numNonZero; idx++ )
1308        {
1309          UInt baseLevel  = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2) : 1;
1310
1311          if( absCoeff[ idx ] == baseLevel)
1312          {
1313            UInt uiLevel;
1314            xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam );
1315            absCoeff[ idx ] = uiLevel + baseLevel;
1316            if(absCoeff[idx]>3*(1<<uiGoRiceParam))
1317            {
1318              uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4);
1319            }
1320          }
1321
1322          if(absCoeff[ idx ] >= 2) 
1323          {
1324            iFirstCoeff2 = 0;
1325          }
1326        }
1327      }
1328
1329      for( Int idx = 0; idx < numNonZero; idx++ )
1330      {
1331        Int blkPos = pos[ idx ];
1332        // Signs applied later.
1333        pcCoef[ blkPos ] = absCoeff[ idx ];
1334        absSum += absCoeff[ idx ];
1335
1336        if ( idx == numNonZero-1 && signHidden && beValid )
1337        {
1338          // Infer sign of 1st element.
1339          if (absSum&0x1)
1340          {
1341            pcCoef[ blkPos ] = -pcCoef[ blkPos ];
1342          }
1343        }
1344        else
1345        {
1346          Int sign = static_cast<Int>( coeffSigns ) >> 31;
1347          pcCoef[ blkPos ] = ( pcCoef[ blkPos ] ^ sign ) - sign;
1348          coeffSigns <<= 1;
1349        }
1350      }
1351    }
1352  }
1353 
1354  return;
1355}
1356
1357
1358Void TDecSbac::parseSaoMaxUvlc ( UInt& val, UInt maxSymbol )
1359{
1360  if (maxSymbol == 0)
1361  {
1362    val = 0;
1363    return;
1364  }
1365
1366  UInt code;
1367  Int  i;
1368  m_pcTDecBinIf->decodeBinEP( code );
1369  if ( code == 0 )
1370  {
1371    val = 0;
1372    return;
1373  }
1374
1375  i=1;
1376  while (1)
1377  {
1378    m_pcTDecBinIf->decodeBinEP( code );
1379    if ( code == 0 )
1380    {
1381      break;
1382    }
1383    i++;
1384    if (i == maxSymbol) 
1385    {
1386      break;
1387    }
1388  }
1389
1390  val = i;
1391}
1392Void TDecSbac::parseSaoUflc (UInt uiLength, UInt&  riVal)
1393{
1394  m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength );
1395}
1396Void TDecSbac::parseSaoMerge (UInt&  ruiVal)
1397{
1398  UInt uiCode;
1399  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) );
1400  ruiVal = (Int)uiCode;
1401}
1402Void TDecSbac::parseSaoTypeIdx (UInt&  ruiVal)
1403{
1404  UInt uiCode;
1405  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
1406  if (uiCode == 0) 
1407  {
1408    ruiVal = 0;
1409  }
1410  else
1411  {
1412    m_pcTDecBinIf->decodeBinEP( uiCode ); 
1413    if (uiCode == 0)
1414    {
1415      ruiVal = 1;
1416    }
1417    else
1418    {
1419      ruiVal = 2;
1420    }
1421  }
1422}
1423
1424Void TDecSbac::parseSaoSign(UInt& val)
1425{
1426  m_pcTDecBinIf->decodeBinEP ( val ); 
1427}
1428
1429Void TDecSbac::parseSAOBlkParam (SAOBlkParam& saoBlkParam
1430                                , Bool* sliceEnabled
1431                                , Bool leftMergeAvail
1432                                , Bool aboveMergeAvail
1433                                )
1434{
1435  UInt uiSymbol;
1436
1437  Bool isLeftMerge = false;
1438  Bool isAboveMerge= false;
1439
1440  if(leftMergeAvail)
1441  {
1442    parseSaoMerge(uiSymbol); //sao_merge_left_flag
1443    isLeftMerge = (uiSymbol?true:false);
1444  }
1445
1446  if( aboveMergeAvail && !isLeftMerge)
1447  {
1448    parseSaoMerge(uiSymbol); //sao_merge_up_flag
1449    isAboveMerge = (uiSymbol?true:false);
1450  }
1451
1452  if(isLeftMerge || isAboveMerge) //merge mode
1453      {
1454    saoBlkParam[SAO_Y].modeIdc = saoBlkParam[SAO_Cb].modeIdc = saoBlkParam[SAO_Cr].modeIdc = SAO_MODE_MERGE;
1455    saoBlkParam[SAO_Y].typeIdc = saoBlkParam[SAO_Cb].typeIdc = saoBlkParam[SAO_Cr].typeIdc = (isLeftMerge)?SAO_MERGE_LEFT:SAO_MERGE_ABOVE;
1456      }   
1457  else //new or off mode
1458      {
1459    for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
1460        {
1461      SAOOffset& ctbParam = saoBlkParam[compIdx];
1462
1463      if(!sliceEnabled[compIdx])
1464          {
1465        //off
1466        ctbParam.modeIdc = SAO_MODE_OFF;
1467        continue;
1468        }
1469
1470      //type
1471      if(compIdx == SAO_Y || compIdx == SAO_Cb)
1472    {
1473        parseSaoTypeIdx(uiSymbol); //sao_type_idx_luma or sao_type_idx_chroma
1474
1475        assert(uiSymbol ==0 || uiSymbol ==1 || uiSymbol ==2);
1476
1477        if(uiSymbol ==0) //OFF
1478     {
1479          ctbParam.modeIdc = SAO_MODE_OFF;
1480   }
1481        else if(uiSymbol == 1) //BO
1482        {
1483          ctbParam.modeIdc = SAO_MODE_NEW;
1484          ctbParam.typeIdc = SAO_TYPE_START_BO;
1485  }
1486        else //2, EO
1487  {
1488          ctbParam.modeIdc = SAO_MODE_NEW;
1489          ctbParam.typeIdc = SAO_TYPE_START_EO;
1490        }
1491
1492  }
1493      else //Cr, follow Cb SAO type
1494      {
1495        ctbParam.modeIdc = saoBlkParam[SAO_Cb].modeIdc;
1496        ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc;
1497}
1498
1499      if(ctbParam.modeIdc == SAO_MODE_NEW)
1500{
1501        Int offset[4];
1502        for(Int i=0; i< 4; i++)
1503  {
1504          parseSaoMaxUvlc(uiSymbol,  g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
1505          offset[i] = (Int)uiSymbol;
1506  }
1507
1508        if(ctbParam.typeIdc == SAO_TYPE_START_BO)
1509  {
1510          for(Int i=0; i< 4; i++)
1511    {
1512            if(offset[i] != 0)
1513    {
1514              parseSaoSign(uiSymbol); //sao_offset_sign
1515              if(uiSymbol)
1516      {
1517                offset[i] = -offset[i];
1518      }
1519    }
1520  }
1521          parseSaoUflc(NUM_SAO_BO_CLASSES_LOG2, uiSymbol ); //sao_band_position
1522          ctbParam.typeAuxInfo = uiSymbol;
1523
1524          for(Int i=0; i<4; i++)
1525      {
1526            ctbParam.offset[(ctbParam.typeAuxInfo+i)%MAX_NUM_SAO_CLASSES] = offset[i];
1527      }
1528
1529        }
1530        else //EO
1531        {
1532          ctbParam.typeAuxInfo = 0;
1533
1534          if(compIdx == SAO_Y || compIdx == SAO_Cb)
1535        {
1536            parseSaoUflc(NUM_SAO_EO_TYPES_LOG2, uiSymbol ); //sao_eo_class_luma or sao_eo_class_chroma
1537            ctbParam.typeIdc += uiSymbol;
1538        }
1539        else
1540        {
1541            ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc;
1542        }
1543          ctbParam.offset[SAO_CLASS_EO_FULL_VALLEY] = offset[0];
1544          ctbParam.offset[SAO_CLASS_EO_HALF_VALLEY] = offset[1];
1545          ctbParam.offset[SAO_CLASS_EO_PLAIN      ] = 0;
1546          ctbParam.offset[SAO_CLASS_EO_HALF_PEAK  ] = -offset[2];
1547          ctbParam.offset[SAO_CLASS_EO_FULL_PEAK  ] = -offset[3];
1548      }
1549      }
1550    }
1551  }
1552}
1553
1554/**
1555 - Initialize our contexts from the nominated source.
1556 .
1557 \param pSrc Contexts to be copied.
1558 */
1559Void TDecSbac::xCopyContextsFrom( TDecSbac* pSrc )
1560{
1561  memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0]));
1562}
1563
1564Void TDecSbac::xCopyFrom( TDecSbac* pSrc )
1565{
1566  m_pcTDecBinIf->copyState( pSrc->m_pcTDecBinIf );
1567
1568  m_uiLastQp           = pSrc->m_uiLastQp;
1569  xCopyContextsFrom( pSrc );
1570
1571}
1572
1573Void TDecSbac::load ( TDecSbac* pScr )
1574{
1575  xCopyFrom(pScr);
1576}
1577
1578Void TDecSbac::loadContexts ( TDecSbac* pScr )
1579{
1580  xCopyContextsFrom(pScr);
1581}
1582
1583
1584
1585
1586
1587
1588
1589//! \}
Note: See TracBrowser for help on using the repository browser.