source: 3DVCSoftware/branches/HTM-DEV-0.3-dev2a/source/Lib/TLibDecoder/TDecSbac.cpp @ 464

Last change on this file since 464 was 464, checked in by zhang, 12 years ago

Implementation of ARP from QC

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