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

Last change on this file since 521 was 521, checked in by tech, 12 years ago

Integrated following changes:

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