source: 3DVCSoftware/branches/HTM-16.0-MV-draft-5/source/Lib/TLibDecoder/TDecSbac.cpp @ 1417

Last change on this file since 1417 was 1390, checked in by tech, 9 years ago

Removed 3D.

  • Property svn:eol-style set to native
File size: 70.6 KB
RevLine 
[5]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
[1313]4 * granted under this license.
[5]5 *
[1313]6 * Copyright (c) 2010-2015, ITU/ISO/IEC
[5]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.
[56]17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
[5]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 */
[2]33
34/** \file     TDecSbac.cpp
35    \brief    Context-adaptive entropy decoder class
36*/
37
38#include "TDecSbac.h"
[1313]39#include "TLibCommon/TComTU.h"
40#include "TLibCommon/TComTrQuant.h"
[2]41
[1313]42#if RExt__DECODER_DEBUG_BIT_STATISTICS
43#include "TLibCommon/TComCodingStatistics.h"
44//
45#define RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(a) , a
46#else
47#define RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(a)
48#endif
49
[56]50//! \ingroup TLibDecoder
51//! \{
52
[1313]53#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
54#include "../TLibCommon/Debug.h"
55#endif
56
57
[2]58//////////////////////////////////////////////////////////////////////
59// Construction/Destruction
60//////////////////////////////////////////////////////////////////////
61
[1313]62TDecSbac::TDecSbac()
[2]63// new structure here
[1313]64: m_pcBitstream                              ( 0 )
65, m_pcTDecBinIf                              ( NULL )
66, m_numContextModels                         ( 0 )
67, m_cCUSplitFlagSCModel                      ( 1,             1,                      NUM_SPLIT_FLAG_CTX                   , m_contextModels + m_numContextModels, m_numContextModels)
68, m_cCUSkipFlagSCModel                       ( 1,             1,                      NUM_SKIP_FLAG_CTX                    , m_contextModels + m_numContextModels, m_numContextModels)
69, m_cCUMergeFlagExtSCModel                   ( 1,             1,                      NUM_MERGE_FLAG_EXT_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
70, m_cCUMergeIdxExtSCModel                    ( 1,             1,                      NUM_MERGE_IDX_EXT_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
71, m_cCUPartSizeSCModel                       ( 1,             1,                      NUM_PART_SIZE_CTX                    , m_contextModels + m_numContextModels, m_numContextModels)
72, m_cCUPredModeSCModel                       ( 1,             1,                      NUM_PRED_MODE_CTX                    , m_contextModels + m_numContextModels, m_numContextModels)
73, m_cCUIntraPredSCModel                      ( 1,             1,                      NUM_INTRA_PREDICT_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
74, m_cCUChromaPredSCModel                     ( 1,             1,                      NUM_CHROMA_PRED_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
75, m_cCUDeltaQpSCModel                        ( 1,             1,                      NUM_DELTA_QP_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
76, m_cCUInterDirSCModel                       ( 1,             1,                      NUM_INTER_DIR_CTX                    , m_contextModels + m_numContextModels, m_numContextModels)
77, m_cCURefPicSCModel                         ( 1,             1,                      NUM_REF_NO_CTX                       , m_contextModels + m_numContextModels, m_numContextModels)
78, m_cCUMvdSCModel                            ( 1,             1,                      NUM_MV_RES_CTX                       , m_contextModels + m_numContextModels, m_numContextModels)
79, m_cCUQtCbfSCModel                          ( 1,             NUM_QT_CBF_CTX_SETS,    NUM_QT_CBF_CTX_PER_SET               , m_contextModels + m_numContextModels, m_numContextModels)
80, m_cCUTransSubdivFlagSCModel                ( 1,             1,                      NUM_TRANS_SUBDIV_FLAG_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
81, m_cCUQtRootCbfSCModel                      ( 1,             1,                      NUM_QT_ROOT_CBF_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
82, m_cCUSigCoeffGroupSCModel                  ( 1,             2,                      NUM_SIG_CG_FLAG_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
83, m_cCUSigSCModel                            ( 1,             1,                      NUM_SIG_FLAG_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
84, m_cCuCtxLastX                              ( 1,             NUM_CTX_LAST_FLAG_SETS, NUM_CTX_LAST_FLAG_XY                 , m_contextModels + m_numContextModels, m_numContextModels)
85, m_cCuCtxLastY                              ( 1,             NUM_CTX_LAST_FLAG_SETS, NUM_CTX_LAST_FLAG_XY                 , m_contextModels + m_numContextModels, m_numContextModels)
86, m_cCUOneSCModel                            ( 1,             1,                      NUM_ONE_FLAG_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
87, m_cCUAbsSCModel                            ( 1,             1,                      NUM_ABS_FLAG_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
88, m_cMVPIdxSCModel                           ( 1,             1,                      NUM_MVP_IDX_CTX                      , m_contextModels + m_numContextModels, m_numContextModels)
89, m_cSaoMergeSCModel                         ( 1,             1,                      NUM_SAO_MERGE_FLAG_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
90, m_cSaoTypeIdxSCModel                       ( 1,             1,                      NUM_SAO_TYPE_IDX_CTX                 , m_contextModels + m_numContextModels, m_numContextModels)
91, m_cTransformSkipSCModel                    ( 1,             MAX_NUM_CHANNEL_TYPE,   NUM_TRANSFORMSKIP_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
92, m_CUTransquantBypassFlagSCModel            ( 1,             1,                      NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX    , m_contextModels + m_numContextModels, m_numContextModels)
93, m_explicitRdpcmFlagSCModel                 ( 1,             MAX_NUM_CHANNEL_TYPE,   NUM_EXPLICIT_RDPCM_FLAG_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
94, m_explicitRdpcmDirSCModel                  ( 1,             MAX_NUM_CHANNEL_TYPE,   NUM_EXPLICIT_RDPCM_DIR_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
95, m_cCrossComponentPredictionSCModel         ( 1,             1,                      NUM_CROSS_COMPONENT_PREDICTION_CTX   , m_contextModels + m_numContextModels, m_numContextModels)
96, m_ChromaQpAdjFlagSCModel                   ( 1,             1,                      NUM_CHROMA_QP_ADJ_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
97, m_ChromaQpAdjIdcSCModel                    ( 1,             1,                      NUM_CHROMA_QP_ADJ_IDC_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
98
99
[2]100{
[56]101  assert( m_numContextModels <= MAX_NUM_CTX_MOD );
[2]102}
103
104TDecSbac::~TDecSbac()
105{
106}
107
108// ====================================================================================================================
109// Public member functions
110// ====================================================================================================================
111
[56]112Void TDecSbac::resetEntropy(TComSlice* pSlice)
[2]113{
[56]114  SliceType sliceType  = pSlice->getSliceType();
115  Int       qp         = pSlice->getSliceQp();
116
117  if (pSlice->getPPS()->getCabacInitPresentFlag() && pSlice->getCabacInitFlag())
118  {
119    switch (sliceType)
120    {
121    case P_SLICE:           // change initialization table to B_SLICE initialization
[1313]122      sliceType = B_SLICE;
[56]123      break;
124    case B_SLICE:           // change initialization table to P_SLICE initialization
[1313]125      sliceType = P_SLICE;
[56]126      break;
127    default     :           // should not occur
128      assert(0);
[1313]129      break;
[56]130    }
131  }
132
[1313]133  m_cCUSplitFlagSCModel.initBuffer                ( sliceType, qp, (UChar*)INIT_SPLIT_FLAG );
134  m_cCUSkipFlagSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_SKIP_FLAG );
135  m_cCUMergeFlagExtSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT );
136  m_cCUMergeIdxExtSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_MERGE_IDX_EXT );
137  m_cCUPartSizeSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_PART_SIZE );
138  m_cCUPredModeSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_PRED_MODE );
139  m_cCUIntraPredSCModel.initBuffer                ( sliceType, qp, (UChar*)INIT_INTRA_PRED_MODE );
140  m_cCUChromaPredSCModel.initBuffer               ( sliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE );
141  m_cCUInterDirSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_INTER_DIR );
142  m_cCUMvdSCModel.initBuffer                      ( sliceType, qp, (UChar*)INIT_MVD );
143  m_cCURefPicSCModel.initBuffer                   ( sliceType, qp, (UChar*)INIT_REF_PIC );
144  m_cCUDeltaQpSCModel.initBuffer                  ( sliceType, qp, (UChar*)INIT_DQP );
145  m_cCUQtCbfSCModel.initBuffer                    ( sliceType, qp, (UChar*)INIT_QT_CBF );
146  m_cCUQtRootCbfSCModel.initBuffer                ( sliceType, qp, (UChar*)INIT_QT_ROOT_CBF );
147  m_cCUSigCoeffGroupSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_SIG_CG_FLAG );
148  m_cCUSigSCModel.initBuffer                      ( sliceType, qp, (UChar*)INIT_SIG_FLAG );
149  m_cCuCtxLastX.initBuffer                        ( sliceType, qp, (UChar*)INIT_LAST );
150  m_cCuCtxLastY.initBuffer                        ( sliceType, qp, (UChar*)INIT_LAST );
151  m_cCUOneSCModel.initBuffer                      ( sliceType, qp, (UChar*)INIT_ONE_FLAG );
152  m_cCUAbsSCModel.initBuffer                      ( sliceType, qp, (UChar*)INIT_ABS_FLAG );
153  m_cMVPIdxSCModel.initBuffer                     ( sliceType, qp, (UChar*)INIT_MVP_IDX );
154  m_cSaoMergeSCModel.initBuffer                   ( sliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG );
155  m_cSaoTypeIdxSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
156  m_cCUTransSubdivFlagSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
157  m_cTransformSkipSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
158  m_CUTransquantBypassFlagSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
159  m_explicitRdpcmFlagSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_EXPLICIT_RDPCM_FLAG);
160  m_explicitRdpcmDirSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_EXPLICIT_RDPCM_DIR);
161  m_cCrossComponentPredictionSCModel.initBuffer   ( sliceType, qp, (UChar*)INIT_CROSS_COMPONENT_PREDICTION );
162  m_ChromaQpAdjFlagSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_FLAG );
163  m_ChromaQpAdjIdcSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_IDC );
[2]164
[1313]165  for (UInt statisticIndex = 0; statisticIndex < RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS ; statisticIndex++)
166  {
167    m_golombRiceAdaptationStatistics[statisticIndex] = 0;
168  }
[608]169
[56]170  m_pcTDecBinIf->start();
171}
172
[608]173Void TDecSbac::parseTerminatingBit( UInt& ruiBit )
[56]174{
[608]175  m_pcTDecBinIf->decodeBinTrm( ruiBit );
[1313]176  if ( ruiBit == 1 )
[56]177  {
[608]178    m_pcTDecBinIf->finish();
[1313]179
180#if RExt__DECODER_DEBUG_BIT_STATISTICS
181    TComCodingStatistics::IncrementStatisticEP(STATS__TRAILING_BITS, m_pcBitstream->readOutTrailingBits(),0);
182#else
183    m_pcBitstream->readOutTrailingBits();
184#endif
[56]185  }
186}
187
[2]188
[1313]189
190Void TDecSbac::parseRemainingBytes( Bool noTrailingBytesExpected )
191{
192  if (noTrailingBytesExpected)
193  {
194    const UInt numberOfRemainingSubstreamBytes=m_pcBitstream->getNumBitsLeft();
195    assert (numberOfRemainingSubstreamBytes == 0);
196  }
197  else
198  {
199    while (m_pcBitstream->getNumBitsLeft())
200    {
201      UInt trailingNullByte=m_pcBitstream->readByte();
202      if (trailingNullByte!=0)
203      {
204        printf("Trailing byte should be 0, but has value %02x\n", trailingNullByte);
205        assert(trailingNullByte==0);
206      }
207    }
208  }
209}
210
211#if RExt__DECODER_DEBUG_BIT_STATISTICS
212Void TDecSbac::xReadUnaryMaxSymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol, const class TComCodingStatisticsClassType &whichStat )
213#else
[2]214Void TDecSbac::xReadUnaryMaxSymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol )
[1313]215#endif
[2]216{
217  if (uiMaxSymbol == 0)
218  {
219    ruiSymbol = 0;
220    return;
221  }
[1313]222
223  m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
224
[2]225  if( ruiSymbol == 0 || uiMaxSymbol == 1 )
226  {
227    return;
228  }
[1313]229
[2]230  UInt uiSymbol = 0;
231  UInt uiCont;
[1313]232
[2]233  do
234  {
[1313]235    m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
[2]236    uiSymbol++;
[1313]237  } while( uiCont && ( uiSymbol < uiMaxSymbol - 1 ) );
238
[2]239  if( uiCont && ( uiSymbol == uiMaxSymbol - 1 ) )
240  {
241    uiSymbol++;
242  }
[1313]243
[2]244  ruiSymbol = uiSymbol;
245}
246
[1313]247#if RExt__DECODER_DEBUG_BIT_STATISTICS
248Void TDecSbac::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount, const class TComCodingStatisticsClassType &whichStat )
249#else
[2]250Void TDecSbac::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount )
[1313]251#endif
[2]252{
253  UInt uiSymbol = 0;
254  UInt uiBit = 1;
[1313]255
[2]256  while( uiBit )
257  {
[1313]258    m_pcTDecBinIf->decodeBinEP( uiBit RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
[2]259    uiSymbol += uiBit << uiCount++;
260  }
[1313]261
[56]262  if ( --uiCount )
[2]263  {
[56]264    UInt bins;
[1313]265    m_pcTDecBinIf->decodeBinsEP( bins, uiCount RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
[56]266    uiSymbol += bins;
[2]267  }
[1313]268
[2]269  ruiSymbol = uiSymbol;
270}
271
[1313]272#if RExt__DECODER_DEBUG_BIT_STATISTICS
273Void TDecSbac::xReadUnarySymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, const class TComCodingStatisticsClassType &whichStat )
274#else
[2]275Void TDecSbac::xReadUnarySymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset )
[1313]276#endif
[2]277{
[1313]278  m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat));
279
[2]280  if( !ruiSymbol )
281  {
282    return;
283  }
[1313]284
[2]285  UInt uiSymbol = 0;
286  UInt uiCont;
[1313]287
[2]288  do
289  {
[1313]290    m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat));
[2]291    uiSymbol++;
[1313]292  } while( uiCont );
293
[2]294  ruiSymbol = uiSymbol;
295}
296
[608]297
298/** Parsing of coeff_abs_level_remaing
[1313]299 * \param rSymbol                 reference to coeff_abs_level_remaing
300 * \param rParam                  reference to parameter
301 * \param useLimitedPrefixLength
302 * \param maxLog2TrDynamicRange
[2]303 */
[1313]304#if RExt__DECODER_DEBUG_BIT_STATISTICS
305Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const Int maxLog2TrDynamicRange, const class TComCodingStatisticsClassType &whichStat )
306#else
307Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const Int maxLog2TrDynamicRange )
308#endif
[2]309{
[608]310  UInt prefix   = 0;
311  UInt codeWord = 0;
[1313]312
313  if (useLimitedPrefixLength)
[2]314  {
[1313]315    const UInt longestPossiblePrefix = (32 - (COEF_REMAIN_BIN_REDUCTION + maxLog2TrDynamicRange)) + COEF_REMAIN_BIN_REDUCTION;
316
317    do
318    {
319      prefix++;
320      m_pcTDecBinIf->decodeBinEP( codeWord RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
321    } while((codeWord != 0) && (prefix < longestPossiblePrefix));
[2]322  }
[1313]323  else
324  {
325    do
326    {
327      prefix++;
328      m_pcTDecBinIf->decodeBinEP( codeWord RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
329    } while( codeWord);
330  }
331
[608]332  codeWord  = 1 - codeWord;
333  prefix -= codeWord;
334  codeWord=0;
[1313]335
[608]336  if (prefix < COEF_REMAIN_BIN_REDUCTION )
337  {
[1313]338    m_pcTDecBinIf->decodeBinsEP(codeWord,rParam RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat));
[608]339    rSymbol = (prefix<<rParam) + codeWord;
340  }
[1313]341  else if (useLimitedPrefixLength)
[608]342  {
[1313]343    const UInt maximumPrefixLength = (32 - (COEF_REMAIN_BIN_REDUCTION + maxLog2TrDynamicRange));
[2]344
[1313]345    const UInt prefixLength = prefix - COEF_REMAIN_BIN_REDUCTION;
346    const UInt suffixLength = (prefixLength == maximumPrefixLength) ? (maxLog2TrDynamicRange - rParam) : prefixLength;
[608]347
[1313]348    m_pcTDecBinIf->decodeBinsEP(codeWord, (suffixLength + rParam) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat));
[2]349
[1313]350    rSymbol = codeWord + ((((1 << prefixLength) - 1) + COEF_REMAIN_BIN_REDUCTION) << rParam);
[724]351  }
[1313]352  else
[608]353  {
[1313]354    m_pcTDecBinIf->decodeBinsEP(codeWord,prefix-COEF_REMAIN_BIN_REDUCTION+rParam RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat));
355    rSymbol = (((1<<(prefix-COEF_REMAIN_BIN_REDUCTION))+COEF_REMAIN_BIN_REDUCTION-1)<<rParam)+codeWord;
[608]356  }
357}
[2]358
[1313]359/** Parse I_PCM information.
[56]360 * \param pcCU
[1313]361 * \param uiAbsPartIdx
[56]362 * \param uiDepth
363 * \returns Void
364 *
[1313]365 * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes.
[56]366 */
367Void TDecSbac::parseIPCMInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
[2]368{
369  UInt uiSymbol;
[56]370
[1196]371  m_pcTDecBinIf->decodeBinTrm(uiSymbol);
[2]372
[1386]373#if NH_MV_ENC_DEC_TRAC
[1196]374  DTRACE_CU("pcm_flag", uiSymbol)
[608]375#endif
[1313]376
377
378  if (uiSymbol == 1)
[1196]379  {
[56]380    Bool bIpcmFlag = true;
[1313]381    const TComSPS &sps=*(pcCU->getSlice()->getSPS());
[56]382
383    pcCU->setPartSizeSubParts  ( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
[1313]384    pcCU->setSizeSubParts      ( sps.getMaxCUWidth()>>uiDepth, sps.getMaxCUHeight()>>uiDepth, uiAbsPartIdx, uiDepth );
[608]385    pcCU->setTrIdxSubParts     ( 0, uiAbsPartIdx, uiDepth );
[56]386    pcCU->setIPCMFlagSubParts  ( bIpcmFlag, uiAbsPartIdx, uiDepth );
[2]387
[1313]388    const UInt minCoeffSizeY = pcCU->getPic()->getMinCUWidth() * pcCU->getPic()->getMinCUHeight();
389    const UInt offsetY       = minCoeffSizeY * uiAbsPartIdx;
390    for (UInt ch=0; ch < pcCU->getPic()->getNumberValidComponents(); ch++)
[56]391    {
[1313]392      const ComponentID compID = ComponentID(ch);
393      const UInt offset = offsetY >> (pcCU->getPic()->getComponentScaleX(compID) + pcCU->getPic()->getComponentScaleY(compID));
394      Pel * pPCMSample  = pcCU->getPCMSample(compID) + offset;
395      const UInt width  = pcCU->getWidth (uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleX(compID);
396      const UInt height = pcCU->getHeight(uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleY(compID);
397      const UInt sampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepth(toChannelType(compID));
398      for (UInt y=0; y<height; y++)
[56]399      {
[1313]400        for (UInt x=0; x<width; x++)
[1196]401        {
[1313]402          UInt sample;
403          m_pcTDecBinIf->xReadPCMCode(sampleBits, sample);
404          pPCMSample[x] = sample;
[1196]405        }
[1313]406        pPCMSample += width;
[56]407      }
[1179]408    }
[608]409    m_pcTDecBinIf->start();
[2]410  }
411}
412
[608]413Void TDecSbac::parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
414{
415  UInt uiSymbol;
[1313]416  m_pcTDecBinIf->decodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__TQ_BYPASS_FLAG) );
[1386]417#if NH_MV_ENC_DEC_TRAC
[608]418  DTRACE_CU("cu_transquant_bypass_flag", uiSymbol); 
419#endif
[1313]420
[608]421  pcCU->setCUTransquantBypassSubParts(uiSymbol ? true : false, uiAbsPartIdx, uiDepth);
422}
423
[2]424/** parse skip flag
425 * \param pcCU
[1313]426 * \param uiAbsPartIdx
[2]427 * \param uiDepth
428 * \returns Void
429 */
430Void TDecSbac::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
431{
432  if( pcCU->getSlice()->isIntra() )
433  {
434    return;
435  }
[1313]436
[2]437  UInt uiSymbol = 0;
438  UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx );
[1313]439  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SKIP_FLAG) );
[1386]440#if !NH_MV_ENC_DEC_TRAC
[56]441  DTRACE_CABAC_VL( g_nSymbolCounter++ );
[2]442  DTRACE_CABAC_T( "\tSkipFlag" );
443  DTRACE_CABAC_T( "\tuiCtxSkip: ");
444  DTRACE_CABAC_V( uiCtxSkip );
445  DTRACE_CABAC_T( "\tuiSymbol: ");
446  DTRACE_CABAC_V( uiSymbol );
447  DTRACE_CABAC_T( "\n");
[608]448#endif
[2]449  if( uiSymbol )
450  {
[608]451    pcCU->setSkipFlagSubParts( true,        uiAbsPartIdx, uiDepth );
452    pcCU->setPredModeSubParts( MODE_INTER,  uiAbsPartIdx, uiDepth );
[2]453    pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
[1313]454    pcCU->setSizeSubParts( pcCU->getSlice()->getSPS()->getMaxCUWidth()>>uiDepth, pcCU->getSlice()->getSPS()->getMaxCUHeight()>>uiDepth, uiAbsPartIdx, uiDepth );
[2]455    pcCU->setMergeFlagSubParts( true , uiAbsPartIdx, 0, uiDepth );
456  }
[1386]457#if NH_MV_ENC_DEC_TRAC
[608]458  DTRACE_CU("cu_skip_flag", uiSymbol); 
459#endif
[1313]460
[2]461}
[1179]462
463
[2]464/** parse merge flag
465 * \param pcCU
[1313]466 * \param uiAbsPartIdx
[2]467 * \param uiDepth
468 * \param uiPUIdx
469 * \returns Void
470 */
471Void TDecSbac::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
472{
473  UInt uiSymbol;
[1313]474  m_pcTDecBinIf->decodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MERGE_FLAG) );
[1386]475#if NH_MV_ENC_DEC_TRAC
[608]476  DTRACE_PU("merge_flag", uiSymbol)
477#endif
[2]478  pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth );
[1386]479#if !NH_MV_ENC_DEC_TRAC
[56]480  DTRACE_CABAC_VL( g_nSymbolCounter++ );
[2]481  DTRACE_CABAC_T( "\tMergeFlag: " );
482  DTRACE_CABAC_V( uiSymbol );
483  DTRACE_CABAC_T( "\tAddress: " );
[1313]484  DTRACE_CABAC_V( pcCU->getCtuRsAddr() );
[2]485  DTRACE_CABAC_T( "\tuiAbsPartIdx: " );
486  DTRACE_CABAC_V( uiAbsPartIdx );
487  DTRACE_CABAC_T( "\n" );
[608]488#endif
[2]489}
490
[608]491Void TDecSbac::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex )
[2]492{
[56]493  UInt uiUnaryIdx = 0;
[608]494  UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand();
[56]495  if ( uiNumCand > 1 )
[2]496  {
[56]497    for( ; uiUnaryIdx < uiNumCand - 1; ++uiUnaryIdx )
[2]498    {
[56]499      UInt uiSymbol = 0;
500      if ( uiUnaryIdx==0 )
[2]501      {
[1313]502        m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MERGE_INDEX) );
[2]503      }
[56]504      else
505      {
[1313]506        m_pcTDecBinIf->decodeBinEP( uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MERGE_INDEX) );
[56]507      }
508      if( uiSymbol == 0 )
[2]509      {
[56]510        break;
[2]511      }
512    }
[1386]513#if NH_MV_ENC_DEC_TRAC
[608]514    DTRACE_PU("merge_idx", uiUnaryIdx)
515#endif
[2]516  }
517  ruiMergeIndex = uiUnaryIdx;
518
[1386]519#if !NH_MV_ENC_DEC_TRAC
[56]520  DTRACE_CABAC_VL( g_nSymbolCounter++ )
521  DTRACE_CABAC_T( "\tparseMergeIndex()" )
522  DTRACE_CABAC_T( "\tuiMRGIdx= " )
523  DTRACE_CABAC_V( ruiMergeIndex )
524  DTRACE_CABAC_T( "\n" )
[2]525#endif
526}
527
[56]528Void TDecSbac::parseMVPIdx      ( Int& riMVPIdx )
529{
530  UInt uiSymbol;
[1313]531  xReadUnaryMaxSymbol(uiSymbol, m_cMVPIdxSCModel.get(0), 1, AMVP_MAX_NUM_CANDS-1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVP_IDX) );
[56]532  riMVPIdx = uiSymbol;
533}
[2]534
535Void TDecSbac::parseSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
536{
[1313]537  if( uiDepth == pcCU->getSlice()->getSPS()->getLog2DiffMaxMinCodingBlockSize() )
[2]538  {
539    pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx );
540    return;
541  }
[1313]542#if RExt__DECODER_DEBUG_BIT_STATISTICS
543  const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__SPLIT_FLAG, g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()>>uiDepth]+2);
544#endif
[608]545
[2]546  UInt uiSymbol;
[1313]547  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSplitFlagSCModel.get( 0, 0, pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ) ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
[1386]548#if NH_MV_ENC_DEC_TRAC
[608]549    DTRACE_CU("split_cu_flag", uiSymbol); 
550#else
[1313]551  DTRACE_CABAC_VL( g_nSymbolCounter++ )
552  DTRACE_CABAC_T( "\tSplitFlag\n" )
[608]553#endif
[2]554  pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx );
[1196]555
[2]556  return;
557}
558
559/** parse partition size
560 * \param pcCU
[1313]561 * \param uiAbsPartIdx
[2]562 * \param uiDepth
563 * \returns Void
564 */
565Void TDecSbac::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
566{
567  UInt uiSymbol, uiMode = 0;
568  PartSize eMode;
[1313]569  const UChar cuWidth =UChar(pcCU->getSlice()->getSPS()->getMaxCUWidth()>>uiDepth);
570  const UChar cuHeight=UChar(pcCU->getSlice()->getSPS()->getMaxCUHeight()>>uiDepth);
571  const Int log2DiffMaxMinCodingBlockSize = pcCU->getSlice()->getSPS()->getLog2DiffMaxMinCodingBlockSize();
[189]572
[1313]573#if RExt__DECODER_DEBUG_BIT_STATISTICS
574  const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__PART_SIZE, g_aucConvertToBit[cuWidth]+2);
575#endif
576
577  assert ( pcCU->getSlice()->getSPS()->getLog2DiffMaxMinCodingBlockSize() == log2DiffMaxMinCodingBlockSize);
578
[1196]579
[2]580  if ( pcCU->isIntra( uiAbsPartIdx ) )
581  {
[1313]582    uiSymbol = 1;
583    if( uiDepth == log2DiffMaxMinCodingBlockSize )
584    {
585      m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
[1386]586#if NH_MV_ENC_DEC_TRAC         
[608]587        DTRACE_CU("part_mode", uiSymbol)
588#endif       
[2]589    }
[1313]590    eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN;
591    UInt uiTrLevel = 0;
[56]592    UInt uiWidthInBit  = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2;
593    UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2;
594    uiTrLevel          = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0;
595    if( eMode == SIZE_NxN )
596    {
597      pcCU->setTrIdxSubParts( 1+uiTrLevel, uiAbsPartIdx, uiDepth );
598    }
599    else
600    {
601      pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth );
602    }
[2]603  }
604  else
605  {
[1313]606    UInt uiMaxNumBits = 2;
607
608    if( uiDepth == log2DiffMaxMinCodingBlockSize && !( cuWidth == 8 && cuHeight == 8 ) )
609    {
610      uiMaxNumBits ++;
611    }
612
613    for ( UInt ui = 0; ui < uiMaxNumBits; ui++ )
614    {
615      m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
616      if ( uiSymbol )
617      {
618        break;
619      }
620      uiMode++;
621    }
622    eMode = (PartSize) uiMode;
623    if ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize )
624    {
625      if (eMode == SIZE_2NxN)
626      {
627        m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype));
628        if (uiSymbol == 0)
[189]629        {
[1313]630          m_pcTDecBinIf->decodeBinEP(uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
631          eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD);
[189]632        }
[1313]633      }
634      else if (eMode == SIZE_Nx2N)
635      {
636        m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
637        if (uiSymbol == 0)
[189]638        {
[1313]639          m_pcTDecBinIf->decodeBinEP(uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
640          eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N);
[56]641        }
[833]642      }
[1313]643    }
[1386]644#if NH_MV_ENC_DEC_TRAC         
[608]645      DTRACE_CU("part_mode", eMode )
646#endif
[2]647  }
648  pcCU->setPartSizeSubParts( eMode, uiAbsPartIdx, uiDepth );
[1313]649  pcCU->setSizeSubParts( cuWidth, cuHeight, uiAbsPartIdx, uiDepth );
[2]650}
651
[1313]652
[2]653/** parse prediction mode
654 * \param pcCU
[1313]655 * \param uiAbsPartIdx
[2]656 * \param uiDepth
657 * \returns Void
658 */
659Void TDecSbac::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
660{
661  if( pcCU->getSlice()->isIntra() )
662  {
663    pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth );
664    return;
665  }
[1313]666
[2]667  UInt uiSymbol;
668  Int  iPredMode = MODE_INTER;
[1313]669  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPredModeSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__PRED_MODE) );
[2]670  iPredMode += uiSymbol;
[1386]671#if NH_MV_ENC_DEC_TRAC         
[608]672  DTRACE_CU("pred_mode_flag", uiSymbol)
673#endif       
[2]674  pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth );
675}
[608]676
[1313]677
[608]678Void TDecSbac::parseIntraDirLumaAng  ( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
[443]679{
[608]680  PartSize mode = pcCU->getPartitionSize( absPartIdx );
681  UInt partNum = mode==SIZE_NxN?4:1;
[1313]682  UInt partOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2;
[608]683  UInt mpmPred[4],symbol;
[1313]684  Int j,intraPredMode;
[608]685  if (mode==SIZE_NxN)
[443]686  {
[608]687    depth++;
[443]688  }
[1313]689#if RExt__DECODER_DEBUG_BIT_STATISTICS
690  const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__INTRA_DIR_ANG, g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()>>depth]+2, CHANNEL_TYPE_LUMA);
691#endif
[608]692  for (j=0;j<partNum;j++)
[443]693  {
[1313]694    m_pcTDecBinIf->decodeBin( symbol, m_cCUIntraPredSCModel.get( 0, 0, 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
695    mpmPred[j] = symbol;
[1386]696#if NH_MV_ENC_DEC_TRAC         
[1196]697      DTRACE_CU("prev_intra_luma_pred_flag", symbol)
[608]698#endif
[443]699  }
[608]700  for (j=0;j<partNum;j++)
[443]701  {
[1313]702    Int preds[NUM_MOST_PROBABLE_MODES] = {-1, -1, -1};
703    pcCU->getIntraDirPredictor(absPartIdx+partOffset*j, preds, COMPONENT_Y);
704    if (mpmPred[j])
705    {
706      m_pcTDecBinIf->decodeBinEP( symbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
707      if (symbol)
[608]708      {
[1313]709        m_pcTDecBinIf->decodeBinEP( symbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
710        symbol++;
711      }
[1386]712#if NH_MV_ENC_DEC_TRAC         
[1196]713        DTRACE_CU("mpm_idx", symbol)
[608]714#endif
[1313]715      intraPredMode = preds[symbol];
716    }
717    else
718    {
719      m_pcTDecBinIf->decodeBinsEP( symbol, 5 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
720      intraPredMode = symbol;
[1386]721#if NH_MV_ENC_DEC_TRAC         
[1196]722        DTRACE_CU("rem_intra_luma_pred_mode", symbol)
[608]723#endif       
[1313]724
725      //postponed sorting of MPMs (only in remaining branch)
726      if (preds[0] > preds[1])
727      {
728        std::swap(preds[0], preds[1]);
[443]729      }
[1313]730      if (preds[0] > preds[2])
731      {
732        std::swap(preds[0], preds[2]);
733      }
734      if (preds[1] > preds[2])
735      {
736        std::swap(preds[1], preds[2]);
737      }
738      for ( UInt i = 0; i < NUM_MOST_PROBABLE_MODES; i++ )
739      {
740        intraPredMode += ( intraPredMode >= preds[i] );
741      }
[608]742    }
[1313]743    pcCU->setIntraDirSubParts(CHANNEL_TYPE_LUMA, (UChar)intraPredMode, absPartIdx+partOffset*j, depth );
[443]744  }
745}
[608]746
[1313]747
[608]748Void TDecSbac::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
[443]749{
[608]750  UInt uiSymbol;
[1313]751#if RExt__DECODER_DEBUG_BIT_STATISTICS
752  const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__INTRA_DIR_ANG, g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()>>uiDepth]+2, CHANNEL_TYPE_CHROMA);
753#endif
[608]754
[1313]755  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
[608]756  if( uiSymbol == 0 )
[443]757  {
[1386]758#if NH_MV_ENC_DEC_TRAC         
[608]759    DTRACE_CU("intra_chroma_pred_mode", uiSymbol )
760#endif       
[1313]761    uiSymbol = DM_CHROMA_IDX;
762  }
763  else
[443]764  {
[1313]765    UInt uiIPredMode;
766    m_pcTDecBinIf->decodeBinsEP( uiIPredMode, 2 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
[1386]767#if NH_MV_ENC_DEC_TRAC         
[608]768      DTRACE_CU("intra_chroma_pred_mode", uiIPredMode )
769#endif       
[1313]770    UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ];
771    pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir );
772    uiSymbol = uiAllowedChromaDir[ uiIPredMode ];
[443]773  }
[608]774
[1313]775  pcCU->setIntraDirSubParts( CHANNEL_TYPE_CHROMA, uiSymbol, uiAbsPartIdx, uiDepth );
[608]776}
[443]777
[608]778Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx )
[2]779{
780  UInt uiSymbol;
[608]781  const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx );
782  ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 );
[1313]783
[608]784  uiSymbol = 0;
785  if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 )
[2]786  {
[1313]787    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__INTER_DIR) );
[2]788  }
789
[56]790  if( uiSymbol )
[2]791  {
792    uiSymbol = 2;
793  }
[608]794  else
795  {
[1313]796    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + 4 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__INTER_DIR) );
[608]797    assert(uiSymbol == 0 || uiSymbol == 1);
798  }
[56]799
[2]800  uiSymbol++;
801  ruiInterDir = uiSymbol;
[1386]802#if NH_MV_ENC_DEC_TRAC
[608]803    DTRACE_PU("inter_pred_idc", ruiInterDir - 1 )   
804#endif
805
[2]806  return;
807}
808
[608]809Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList )
[2]810{
811  UInt uiSymbol;
[1313]812
813  ContextModel *pCtx = m_cCURefPicSCModel.get( 0 );
814  m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__REF_FRM_IDX) );
815
816  if( uiSymbol )
[2]817  {
[1313]818    UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2;
819    pCtx++;
820    UInt ui;
821    for( ui = 0; ui < uiRefNum; ++ui )
[2]822    {
[1313]823      if( ui == 0 )
[608]824      {
[1313]825        m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__REF_FRM_IDX) );
[608]826      }
[1313]827      else
828      {
829        m_pcTDecBinIf->decodeBinEP( uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__REF_FRM_IDX) );
830      }
831      if( uiSymbol == 0 )
832      {
833        break;
834      }
[2]835    }
[1313]836    uiSymbol = ui + 1;
[2]837  }
[1313]838  riRefFrmIdx = uiSymbol;
[1386]839#if NH_MV_ENC_DEC_TRAC
[608]840#if ENC_DEC_TRACE
841  if ( eRefList == REF_PIC_LIST_0 )
842  {
843    DTRACE_PU("ref_idx_l0", uiSymbol)
844  }
[2]845  else
846  {
[608]847    DTRACE_PU("ref_idx_l1", uiSymbol)
[2]848  }
[608]849#endif
850#endif
[1313]851
[2]852  return;
853}
854
[56]855Void TDecSbac::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList )
[2]856{
857  UInt uiSymbol;
[56]858  UInt uiHorAbs;
859  UInt uiVerAbs;
860  UInt uiHorSign = 0;
861  UInt uiVerSign = 0;
862  ContextModel *pCtx = m_cCUMvdSCModel.get( 0 );
[2]863
[56]864  if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3)
865  {
866    uiHorAbs=0;
867    uiVerAbs=0;
868  }
869  else
870  {
[1313]871    m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) );
872    m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) );
[2]873
[56]874    const Bool bHorAbsGr0 = uiHorAbs != 0;
875    const Bool bVerAbsGr0 = uiVerAbs != 0;
876    pCtx++;
877
878    if( bHorAbsGr0 )
879    {
[1313]880      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) );
[56]881      uiHorAbs += uiSymbol;
882    }
883
884    if( bVerAbsGr0 )
885    {
[1313]886      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) );
[56]887      uiVerAbs += uiSymbol;
888    }
889
890    if( bHorAbsGr0 )
891    {
892      if( 2 == uiHorAbs )
893      {
[1313]894        xReadEpExGolomb( uiSymbol, 1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) );
[56]895        uiHorAbs += uiSymbol;
896      }
897
[1313]898      m_pcTDecBinIf->decodeBinEP( uiHorSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) );
[56]899    }
900
901    if( bVerAbsGr0 )
902    {
903      if( 2 == uiVerAbs )
904      {
[1313]905        xReadEpExGolomb( uiSymbol, 1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) );
[56]906        uiVerAbs += uiSymbol;
907      }
908
[1313]909      m_pcTDecBinIf->decodeBinEP( uiVerSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) );
[56]910    }
911
912  }
[2]913
[56]914  const TComMv cMv( uiHorSign ? -Int( uiHorAbs ): uiHorAbs, uiVerSign ? -Int( uiVerAbs ) : uiVerAbs );
915  pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiDepth, uiPartIdx );
[2]916  return;
917}
918
[1313]919Void TDecSbac::parseCrossComponentPrediction( TComTU &rTu, ComponentID compID )
920{
921  TComDataCU *pcCU = rTu.getCU();
[2]922
[1313]923  if( isLuma(compID) || !pcCU->getSlice()->getPPS()->getPpsRangeExtension().getCrossComponentPredictionEnabledFlag() )
924  {
925    return;
926  }
927
928  const UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU();
929
930  if (!pcCU->isIntra(uiAbsPartIdx) || (pcCU->getIntraDir( CHANNEL_TYPE_CHROMA, uiAbsPartIdx ) == DM_CHROMA_IDX))
931  {
[1386]932    SChar alpha = 0;
[1313]933    UInt symbol = 0;
934
935    DTRACE_CABAC_VL( g_nSymbolCounter++ )
936    DTRACE_CABAC_T("\tparseCrossComponentPrediction()")
937    DTRACE_CABAC_T( "\tAddr=" )
938    DTRACE_CABAC_V( compID )
939    DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
940    DTRACE_CABAC_V( uiAbsPartIdx )
941#if RExt__DECODER_DEBUG_BIT_STATISTICS
942    TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__CROSS_COMPONENT_PREDICTION, (g_aucConvertToBit[rTu.getRect(compID).width] + 2), compID);
943#endif
944    ContextModel *pCtx = m_cCrossComponentPredictionSCModel.get(0, 0) + ((compID == COMPONENT_Cr) ? (NUM_CROSS_COMPONENT_PREDICTION_CTX >> 1) : 0);
945    m_pcTDecBinIf->decodeBin( symbol, pCtx[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
946
947    if(symbol != 0)
948    {
949      // Cross-component prediction alpha is non-zero.
950      UInt sign = 0;
951      m_pcTDecBinIf->decodeBin( symbol, pCtx[1] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
952
953      if (symbol != 0)
954      {
955        // alpha is 2 (symbol=1), 4(symbol=2) or 8(symbol=3).
956        // Read up to two more bits
957        xReadUnaryMaxSymbol( symbol, (pCtx + 2), 1, 2 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
958        symbol += 1;
959      }
960      m_pcTDecBinIf->decodeBin( sign, pCtx[4] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
961
962      alpha = (sign != 0) ? -(1 << symbol) : (1 << symbol);
963    }
964    DTRACE_CABAC_T( "\tAlpha=" )
965    DTRACE_CABAC_V( alpha )
966    DTRACE_CABAC_T( "\n" )
967
968    pcCU->setCrossComponentPredictionAlphaPartRange( alpha, compID, uiAbsPartIdx, rTu.GetAbsPartIdxNumParts( compID ) );
969  }
970}
971
[2]972Void TDecSbac::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize )
973{
[1313]974  m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize )
975      RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__TRANSFORM_SUBDIV_FLAG, 5-uiLog2TransformBlockSize))
976                          );
[1386]977#if !NH_MV_ENC_DEC_TRAC
[56]978  DTRACE_CABAC_VL( g_nSymbolCounter++ )
[2]979  DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" )
980  DTRACE_CABAC_T( "\tsymbol=" )
981  DTRACE_CABAC_V( ruiSubdivFlag )
982  DTRACE_CABAC_T( "\tctx=" )
983  DTRACE_CABAC_V( uiLog2TransformBlockSize )
984  DTRACE_CABAC_T( "\n" )
[1179]985#else
986  DTRACE_TU("split_transform_flag", ruiSubdivFlag )
[608]987#endif
[1313]988
[2]989}
990
[608]991Void TDecSbac::parseQtRootCbf( UInt uiAbsPartIdx, UInt& uiQtRootCbf )
[2]992{
993  UInt uiSymbol;
[56]994  const UInt uiCtx = 0;
[1313]995  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__QT_ROOT_CBF) );
[1386]996#if !NH_MV_ENC_DEC_TRAC
[56]997  DTRACE_CABAC_VL( g_nSymbolCounter++ )
[2]998  DTRACE_CABAC_T( "\tparseQtRootCbf()" )
999  DTRACE_CABAC_T( "\tsymbol=" )
1000  DTRACE_CABAC_V( uiSymbol )
1001  DTRACE_CABAC_T( "\tctx=" )
1002  DTRACE_CABAC_V( uiCtx )
1003  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1004  DTRACE_CABAC_V( uiAbsPartIdx )
1005  DTRACE_CABAC_T( "\n" )
[608]1006#else
1007  DTRACE_CU( "rqt_root_cbf", uiSymbol )
1008#endif
[1313]1009
[2]1010  uiQtRootCbf = uiSymbol;
1011}
1012
1013Void TDecSbac::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1014{
[56]1015  Int qp;
[2]1016  UInt uiDQp;
1017  Int  iDQp;
[1313]1018
[608]1019  UInt uiSymbol;
1020
[1313]1021  xReadUnaryMaxSymbol (uiDQp,  &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTA_QP_EP) );
[608]1022
1023  if( uiDQp >= CU_DQP_TU_CMAX)
[2]1024  {
[1313]1025    xReadEpExGolomb( uiSymbol, CU_DQP_EG_k RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTA_QP_EP));
[608]1026    uiDQp+=uiSymbol;
[2]1027  }
[608]1028
1029  if ( uiDQp > 0 )
[2]1030  {
[56]1031    UInt uiSign;
[1313]1032    Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA);
1033    m_pcTDecBinIf->decodeBinEP(uiSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTA_QP_EP));
[608]1034    iDQp = uiDQp;
[56]1035    if(uiSign)
[2]1036    {
1037      iDQp = -iDQp;
1038    }
[56]1039    qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY;
[2]1040  }
[1313]1041  else
[608]1042  {
1043    qp = pcCU->getRefQP(uiAbsPartIdx);
1044  }
[1313]1045
1046  pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth);
[608]1047  pcCU->setCodedQP(qp);
[2]1048}
1049
[1313]1050/** parse chroma qp adjustment, converting to the internal table representation.
1051 * \returns Void
1052 */
1053Void TDecSbac::parseChromaQpAdjustment( TComDataCU* cu, UInt absPartIdx, UInt depth )
[2]1054{
[1313]1055  UInt symbol;
1056#if RExt__DECODER_DEBUG_BIT_STATISTICS
1057  const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__CHROMA_QP_ADJUSTMENT, g_aucConvertToBit[cu->getSlice()->getSPS()->getMaxCUWidth()>>depth]+2, CHANNEL_TYPE_CHROMA);
1058#endif
1059
1060  Int chromaQpOffsetListLen = cu->getSlice()->getPPS()->getPpsRangeExtension().getChromaQpOffsetListLen();
1061
1062  // cu_chroma_qp_offset_flag
1063  m_pcTDecBinIf->decodeBin( symbol, m_ChromaQpAdjFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
1064
1065  if (symbol && chromaQpOffsetListLen > 1)
1066  {
1067    // cu_chroma_qp_offset_idx
1068    xReadUnaryMaxSymbol( symbol,  &m_ChromaQpAdjIdcSCModel.get( 0, 0, 0 ), 0, chromaQpOffsetListLen - 1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
1069    symbol++;
1070  }
1071  /* NB, symbol = 0 if outer flag is not set,
1072   *              1 if outer flag is set and there is no inner flag
1073   *              1+ otherwise */
1074  cu->setChromaQpAdjSubParts( symbol, absPartIdx, depth );
1075  cu->setCodedChromaQpAdj(symbol);
1076}
1077
1078Void TDecSbac::parseQtCbf( TComTU &rTu, const ComponentID compID, const Bool lowestLevel )
1079{
1080  TComDataCU* pcCU = rTu.getCU();
1081
1082  const UInt absPartIdx       = rTu.GetAbsPartIdxTU(compID);
1083  const UInt TUDepth          = rTu.GetTransformDepthRel();
1084  const UInt uiCtx            = pcCU->getCtxQtCbf( rTu, toChannelType(compID) );
1085  const UInt contextSet       = toChannelType(compID);
1086
1087  const UInt width            = rTu.getRect(compID).width;
1088  const UInt height           = rTu.getRect(compID).height;
1089  const Bool canQuadSplit     = (width >= (MIN_TU_SIZE * 2)) && (height >= (MIN_TU_SIZE * 2));
1090  const UInt coveredPartIdxes = rTu.GetAbsPartIdxNumParts(compID);
1091
1092  //             Since the CBF for chroma is coded at the highest level possible, if sub-TUs are
1093  //             to be coded for a 4x8 chroma TU, their CBFs must be coded at the highest 4x8 level
1094  //             (i.e. where luma TUs are 8x8 rather than 4x4)
1095  //    ___ ___
1096  //   |   |   | <- 4 x (8x8 luma + 4x8 4:2:2 chroma)
1097  //   |___|___|    each quadrant has its own chroma CBF
1098  //   |   |   | _ _ _ _
1099  //   |___|___|        |
1100  //   <--16--->        V
1101  //                   _ _
1102  //                  |_|_| <- 4 x 4x4 luma + 1 x 4x8 4:2:2 chroma
1103  //                  |_|_|    no chroma CBF is coded - instead the parent CBF is inherited
1104  //                  <-8->    if sub-TUs are present, their CBFs had to be coded at the parent level
1105
1106  const UInt lowestTUDepth = TUDepth + ((!lowestLevel && !canQuadSplit) ? 1 : 0); //unsplittable TUs inherit their parent's CBF
1107        UInt lowestTUCBF   = 0;
1108
1109  if ((width != height) && (lowestLevel || !canQuadSplit)) //if sub-TUs are present
1110  {
1111    const UInt subTUDepth        = lowestTUDepth + 1;
1112    const UInt partIdxesPerSubTU = rTu.GetAbsPartIdxNumParts(compID) >> 1;
1113
1114    UInt combinedSubTUCBF = 0;
1115
1116    for (UInt subTU = 0; subTU < 2; subTU++)
1117    {
1118      UInt uiCbf = MAX_UINT;
1119      m_pcTDecBinIf->decodeBin(uiCbf, m_cCUQtCbfSCModel.get(0, contextSet, uiCtx) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__QT_CBF, g_aucConvertToBit[rTu.getRect(compID).width]+2, compID)));
1120
1121      const UInt subTUAbsPartIdx = absPartIdx + (subTU * partIdxesPerSubTU);
1122      pcCU->setCbfPartRange((uiCbf << subTUDepth), compID, subTUAbsPartIdx, partIdxesPerSubTU);
1123      combinedSubTUCBF |= uiCbf;
[1386]1124#if !NH_MV_ENC_DEC_TRAC 
[1313]1125      DTRACE_CABAC_VL( g_nSymbolCounter++ )
1126      DTRACE_CABAC_T( "\tparseQtCbf()" )
1127      DTRACE_CABAC_T( "\tsub-TU=" )
1128      DTRACE_CABAC_V( subTU )
1129      DTRACE_CABAC_T( "\tsymbol=" )
1130      DTRACE_CABAC_V( uiCbf )
1131      DTRACE_CABAC_T( "\tctx=" )
1132      DTRACE_CABAC_V( uiCtx )
1133      DTRACE_CABAC_T( "\tetype=" )
1134      DTRACE_CABAC_V( compID )
1135      DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1136      DTRACE_CABAC_V( subTUAbsPartIdx )
1137      DTRACE_CABAC_T( "\n" )
[1179]1138#else
[1313]1139  if ( compID == COMPONENT_Cb )
[1179]1140  {
[1313]1141    DTRACE_TU("cbf_cb", uiCbf )
[1179]1142  }
[1313]1143  else if ( compID == COMPONENT_Cr )
[1179]1144  {
[1313]1145    DTRACE_TU("cbf_cr", uiCbf )
[1179]1146  }
1147  else
1148  {
[1313]1149    DTRACE_TU("cbf_luma", uiCbf )
[1179]1150  }
[608]1151#endif
[1313]1152
1153    }
1154
1155    //propagate the sub-TU CBF up to the lowest TU level
1156    if (combinedSubTUCBF != 0)
1157    {
1158      pcCU->bitwiseOrCbfPartRange((combinedSubTUCBF << lowestTUDepth), compID, absPartIdx, coveredPartIdxes);
1159      lowestTUCBF = combinedSubTUCBF;
1160    }
1161  }
1162  else
1163  {
1164    UInt uiCbf = MAX_UINT;
1165    m_pcTDecBinIf->decodeBin(uiCbf, m_cCUQtCbfSCModel.get(0, contextSet, uiCtx) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__QT_CBF, g_aucConvertToBit[rTu.getRect(compID).width]+2, compID)));
1166
1167    pcCU->setCbfSubParts((uiCbf << lowestTUDepth), compID, absPartIdx, rTu.GetTransformDepthTotalAdj(compID));
[1386]1168#if !NH_MV_ENC_DEC_TRAC
[1313]1169    DTRACE_CABAC_VL( g_nSymbolCounter++ )
1170    DTRACE_CABAC_T( "\tparseQtCbf()" )
1171    DTRACE_CABAC_T( "\tsymbol=" )
1172    DTRACE_CABAC_V( uiCbf )
1173    DTRACE_CABAC_T( "\tctx=" )
1174    DTRACE_CABAC_V( uiCtx )
1175    DTRACE_CABAC_T( "\tetype=" )
1176    DTRACE_CABAC_V( compID )
1177    DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1178    DTRACE_CABAC_V( rTu.GetAbsPartIdxTU(compID) )
1179    DTRACE_CABAC_T( "\n" )
1180#else
1181    if ( compID == COMPONENT_Cb )
1182    {
1183      DTRACE_TU("cbf_cb", uiCbf )
1184    }
1185    else if ( compID == COMPONENT_Cr )
1186    {
1187      DTRACE_TU("cbf_cr", uiCbf )
1188    }
1189    else
1190    {
1191      DTRACE_TU("cbf_luma", uiCbf )
1192    }
1193#endif
1194    lowestTUCBF = uiCbf;
1195  }
1196
1197  //propagate the lowest level CBF up to the current level
1198  if (lowestTUCBF != 0)
1199  {
1200    for (UInt depth = TUDepth; depth < lowestTUDepth; depth++)
1201    {
1202      pcCU->bitwiseOrCbfPartRange((lowestTUCBF << depth), compID, absPartIdx, coveredPartIdxes);
1203    }
1204  }
[2]1205}
1206
[1313]1207
1208Void TDecSbac::parseTransformSkipFlags (TComTU &rTu, ComponentID component)
[608]1209{
[1313]1210  TComDataCU* pcCU=rTu.getCU();
1211  UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(component);
1212
[608]1213  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
1214  {
1215    return;
1216  }
[1313]1217
1218  if (!TUCompRectHasAssociatedTransformSkipFlag(rTu.getRect(component), pcCU->getSlice()->getPPS()->getPpsRangeExtension().getLog2MaxTransformSkipBlockSize()))
[608]1219  {
1220    return;
1221  }
[1313]1222
[608]1223  UInt useTransformSkip;
[1313]1224
1225  m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, toChannelType(component), 0 )
1226      RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__TRANSFORM_SKIP_FLAGS, component))
1227                          );
1228
[1386]1229#if !NH_MV_ENC_DEC_TRAC
[608]1230  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1231  DTRACE_CABAC_T("\tparseTransformSkip()");
1232  DTRACE_CABAC_T( "\tsymbol=" )
1233  DTRACE_CABAC_V( useTransformSkip )
1234  DTRACE_CABAC_T( "\tAddr=" )
[1313]1235  DTRACE_CABAC_V( pcCU->getCtuRsAddr() )
[608]1236  DTRACE_CABAC_T( "\tetype=" )
[1313]1237  DTRACE_CABAC_V( component )
[608]1238  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
[1313]1239  DTRACE_CABAC_V( rTu.GetAbsPartIdxTU() )
[608]1240  DTRACE_CABAC_T( "\n" )
1241#endif
1242
[1313]1243  pcCU->setTransformSkipPartRange( useTransformSkip, component, uiAbsPartIdx, rTu.GetAbsPartIdxNumParts(component));
[608]1244}
1245
[1313]1246
[2]1247/** Parse (X,Y) position of the last significant coefficient
1248 * \param uiPosLastX reference to X component of last coefficient
1249 * \param uiPosLastY reference to Y component of last coefficient
[56]1250 * \param width  Block width
1251 * \param height Block height
[1313]1252 * \param component chroma compinent ID
[2]1253 * \param uiScanIdx scan type (zig-zag, hor, ver)
[56]1254 *
[2]1255 * This method decodes the X and Y component within a block of the last significant coefficient.
1256 */
[1313]1257Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, ComponentID component, UInt uiScanIdx )
[2]1258{
1259  UInt uiLast;
1260
[1313]1261  ContextModel *pCtxX = m_cCuCtxLastX.get( 0, toChannelType(component) );
1262  ContextModel *pCtxY = m_cCuCtxLastY.get( 0, toChannelType(component) );
1263
1264#if RExt__DECODER_DEBUG_BIT_STATISTICS
1265  TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__LAST_SIG_X_Y, g_aucConvertToBit[width]+2, component);
1266#endif
1267
1268
1269  if ( uiScanIdx == SCAN_VER )
1270  {
1271    swap( width, height );
1272  }
1273
[608]1274  Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY;
[1313]1275  getLastSignificantContextParameters(component, width, height, blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY);
1276
1277  //------------------
1278
[56]1279  // posX
[1313]1280
[56]1281  for( uiPosLastX = 0; uiPosLastX < g_uiGroupIdx[ width - 1 ]; uiPosLastX++ )
[2]1282  {
[1313]1283    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + blkSizeOffsetX + (uiPosLastX >>shiftX) ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
1284
[56]1285    if( !uiLast )
1286    {
[2]1287      break;
1288    }
1289  }
1290
[56]1291  // posY
[1313]1292
[56]1293  for( uiPosLastY = 0; uiPosLastY < g_uiGroupIdx[ height - 1 ]; uiPosLastY++ )
[2]1294  {
[1313]1295    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + blkSizeOffsetY + (uiPosLastY >>shiftY)) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
1296
[56]1297    if( !uiLast )
1298    {
[2]1299      break;
1300    }
1301  }
[1313]1302
1303  // EP-coded part
1304
[56]1305  if ( uiPosLastX > 3 )
1306  {
1307    UInt uiTemp  = 0;
1308    UInt uiCount = ( uiPosLastX - 2 ) >> 1;
1309    for ( Int i = uiCount - 1; i >= 0; i-- )
1310    {
[1313]1311      m_pcTDecBinIf->decodeBinEP( uiLast RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
[56]1312      uiTemp += uiLast << i;
1313    }
1314    uiPosLastX = g_uiMinInGroup[ uiPosLastX ] + uiTemp;
1315  }
1316  if ( uiPosLastY > 3 )
1317  {
1318    UInt uiTemp  = 0;
1319    UInt uiCount = ( uiPosLastY - 2 ) >> 1;
1320    for ( Int i = uiCount - 1; i >= 0; i-- )
1321    {
[1313]1322      m_pcTDecBinIf->decodeBinEP( uiLast RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
[56]1323      uiTemp += uiLast << i;
1324    }
1325    uiPosLastY = g_uiMinInGroup[ uiPosLastY ] + uiTemp;
1326  }
[1313]1327
[2]1328  if( uiScanIdx == SCAN_VER )
1329  {
1330    swap( uiPosLastX, uiPosLastY );
1331  }
1332}
1333
[1313]1334Void TDecSbac::parseCoeffNxN(  TComTU &rTu, ComponentID compID )
[2]1335{
[1313]1336  TComDataCU* pcCU=rTu.getCU();
1337  const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(compID);
1338  const TComRectangle &rRect=rTu.getRect(compID);
1339  const UInt uiWidth=rRect.width;
1340  const UInt uiHeight=rRect.height;
1341  TCoeff* pcCoef=(pcCU->getCoeff(compID)+rTu.getCoefficientOffset(compID));
1342  const TComSPS &sps=*(pcCU->getSlice()->getSPS());
[1386]1343#if !NH_MV_ENC_DEC_TRAC
[56]1344  DTRACE_CABAC_VL( g_nSymbolCounter++ )
[2]1345  DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" )
[1313]1346  DTRACE_CABAC_V( compID )
[2]1347  DTRACE_CABAC_T( "\twidth=" )
1348  DTRACE_CABAC_V( uiWidth )
1349  DTRACE_CABAC_T( "\theight=" )
1350  DTRACE_CABAC_V( uiHeight )
1351  DTRACE_CABAC_T( "\tdepth=" )
[1313]1352//  DTRACE_CABAC_V( rTu.GetTransformDepthTotalAdj(compID) )
1353  DTRACE_CABAC_V( rTu.GetTransformDepthTotal() )
[2]1354  DTRACE_CABAC_T( "\tabspartidx=" )
[1313]1355//  DTRACE_CABAC_V( uiAbsPartIdx )
1356  DTRACE_CABAC_V( rTu.GetAbsPartIdxTU(compID) )
[2]1357  DTRACE_CABAC_T( "\ttoCU-X=" )
1358  DTRACE_CABAC_V( pcCU->getCUPelX() )
1359  DTRACE_CABAC_T( "\ttoCU-Y=" )
1360  DTRACE_CABAC_V( pcCU->getCUPelY() )
1361  DTRACE_CABAC_T( "\tCU-addr=" )
[1313]1362  DTRACE_CABAC_V(  pcCU->getCtuRsAddr() )
[2]1363  DTRACE_CABAC_T( "\tinCU-X=" )
[1313]1364//  DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1365  DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] )
[2]1366  DTRACE_CABAC_T( "\tinCU-Y=" )
[1313]1367// DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1368  DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] )
[2]1369  DTRACE_CABAC_T( "\tpredmode=" )
1370  DTRACE_CABAC_V(  pcCU->getPredictionMode( uiAbsPartIdx ) )
1371  DTRACE_CABAC_T( "\n" )
[608]1372#endif
[1313]1373
1374  //--------------------------------------------------------------------------------------------------
1375
1376  if( uiWidth > sps.getMaxTrSize() )
[2]1377  {
[1313]1378    std::cerr << "ERROR: parseCoeffNxN was passed a TU with dimensions larger than the maximum allowed size" << std::endl;
1379    assert(false);
1380    exit(1);
[2]1381  }
[1313]1382
1383  //--------------------------------------------------------------------------------------------------
1384
1385  //set parameters
1386
1387  const ChannelType  chType            = toChannelType(compID);
1388  const UInt         uiLog2BlockWidth  = g_aucConvertToBit[ uiWidth  ] + 2;
1389  const UInt         uiLog2BlockHeight = g_aucConvertToBit[ uiHeight ] + 2;
1390  const UInt         uiMaxNumCoeff     = uiWidth * uiHeight;
1391  const UInt         uiMaxNumCoeffM1   = uiMaxNumCoeff - 1;
1392
1393  const ChannelType  channelType       = toChannelType(compID);
1394  const Bool         extendedPrecision = sps.getSpsRangeExtension().getExtendedPrecisionProcessingFlag();
1395
1396  const Bool         alignCABACBeforeBypass = sps.getSpsRangeExtension().getCabacBypassAlignmentEnabledFlag();
1397  const Int          maxLog2TrDynamicRange  = sps.getMaxLog2TrDynamicRange(channelType);
1398
1399#if RExt__DECODER_DEBUG_BIT_STATISTICS
1400  TComCodingStatisticsClassType ctype_group(STATS__CABAC_BITS__SIG_COEFF_GROUP_FLAG, uiLog2BlockWidth, compID);
1401  TComCodingStatisticsClassType ctype_map(STATS__CABAC_BITS__SIG_COEFF_MAP_FLAG, uiLog2BlockWidth, compID);
1402  TComCodingStatisticsClassType ctype_gt1(STATS__CABAC_BITS__GT1_FLAG, uiLog2BlockWidth, compID);
1403  TComCodingStatisticsClassType ctype_gt2(STATS__CABAC_BITS__GT2_FLAG, uiLog2BlockWidth, compID);
1404#endif
1405
1406  Bool beValid;
1407  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
1408  {
1409    beValid = false;
1410    if((!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx))
1411    {
1412      parseExplicitRdpcmMode(rTu, compID);
1413    }
1414  }
1415  else
1416  {
1417    beValid = pcCU->getSlice()->getPPS()->getSignHideFlag();
1418  }
1419
1420  UInt absSum = 0;
1421
1422  //--------------------------------------------------------------------------------------------------
1423
[608]1424  if(pcCU->getSlice()->getPPS()->getUseTransformSkip())
1425  {
[1313]1426    parseTransformSkipFlags(rTu, compID);
1427    //  This TU has coefficients and is transform skipped. Check whether is inter coded and if yes decode the explicit RDPCM mode
1428    if(pcCU->getTransformSkip(uiAbsPartIdx, compID) && (!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx) )
1429    {
1430      parseExplicitRdpcmMode(rTu, compID);
1431      if(pcCU->getExplicitRdpcmMode(compID, uiAbsPartIdx) != RDPCM_OFF)
1432      {
1433        //  Sign data hiding is avoided for horizontal and vertical RDPCM modes
1434        beValid = false;
1435      }
1436    }
[608]1437  }
1438
[1313]1439  Int uiIntraMode = -1;
1440  const Bool       bIsLuma = isLuma(compID);
1441  Int isIntra = pcCU->isIntra(uiAbsPartIdx) ? 1 : 0;
1442  if ( isIntra && pcCU->isRDPCMEnabled(uiAbsPartIdx) )
1443  {
1444    const UInt partsPerMinCU = 1<<(2*(sps.getMaxTotalCUDepth() - sps.getLog2DiffMaxMinCodingBlockSize()));
1445    uiIntraMode = pcCU->getIntraDir( toChannelType(compID), uiAbsPartIdx );
1446    uiIntraMode = (uiIntraMode==DM_CHROMA_IDX && !bIsLuma) ? pcCU->getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, rTu.GetChromaFormat(), partsPerMinCU)) : uiIntraMode;
1447    uiIntraMode = ((rTu.GetChromaFormat() == CHROMA_422) && !bIsLuma) ? g_chroma422IntraAngleMappingTable[uiIntraMode] : uiIntraMode;
1448
1449    Bool transformSkip = pcCU->getTransformSkip( uiAbsPartIdx,compID);
1450    Bool rdpcm_lossy = ( transformSkip /*&& isIntra*/ && ( (uiIntraMode == HOR_IDX) || (uiIntraMode == VER_IDX) ) );
1451    if ( rdpcm_lossy )
1452    {
1453      beValid = false;
1454    }
1455  }
1456
1457  //--------------------------------------------------------------------------------------------------
1458
1459  const Bool  bUseGolombRiceParameterAdaptation = sps.getSpsRangeExtension().getPersistentRiceAdaptationEnabledFlag();
1460        UInt &currentGolombRiceStatistic        = m_golombRiceAdaptationStatistics[rTu.getGolombRiceStatisticsIndex(compID)];
1461
1462  //select scans
1463  TUEntropyCodingParameters codingParameters;
1464  getTUEntropyCodingParameters(codingParameters, rTu, compID);
1465
[56]1466  //===== decode last significant =====
1467  UInt uiPosLastX, uiPosLastY;
[1313]1468  parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, compID, codingParameters.scanType );
1469  UInt uiBlkPosLast      = uiPosLastX + (uiPosLastY<<uiLog2BlockWidth);
[56]1470  pcCoef[ uiBlkPosLast ] = 1;
[2]1471
[56]1472  //===== decode significance flags =====
[608]1473  UInt uiScanPosLast;
[56]1474  for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ )
1475  {
[1313]1476    UInt uiBlkPos = codingParameters.scan[ uiScanPosLast ];
[56]1477    if( uiBlkPosLast == uiBlkPos )
[2]1478    {
[56]1479      break;
[2]1480    }
[56]1481  }
[2]1482
[1313]1483  ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, isChroma(chType) );
1484  ContextModel * const baseCtx = m_cCUSigSCModel.get( 0, 0 ) + getSignificanceMapContextOffset(compID);
[56]1485
[1313]1486  const Int  iLastScanSet  = uiScanPosLast >> MLS_CG_SIZE;
1487  UInt c1                  = 1;
1488  UInt uiGoRiceParam       = 0;
[56]1489
1490
1491  UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ];
[1313]1492  memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM );
1493
[56]1494  Int  iScanPosSig             = (Int) uiScanPosLast;
1495  for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- )
1496  {
[1313]1497    Int  iSubPos   = iSubSet << MLS_CG_SIZE;
1498    uiGoRiceParam  = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR;
1499    Bool updateGolombRiceStatistics = bUseGolombRiceParameterAdaptation; //leave the statistics at 0 when not using the adaptation system
[56]1500    Int numNonZero = 0;
1501
[1313]1502    Int lastNZPosInCG  = -1;
1503    Int firstNZPosInCG = 1 << MLS_CG_SIZE;
1504
1505    Bool escapeDataPresentInGroup = false;
1506
1507    Int pos[1 << MLS_CG_SIZE];
1508
[56]1509    if( iScanPosSig == (Int) uiScanPosLast )
1510    {
1511      lastNZPosInCG  = iScanPosSig;
1512      firstNZPosInCG = iScanPosSig;
1513      iScanPosSig--;
1514      pos[ numNonZero ] = uiBlkPosLast;
1515      numNonZero = 1;
1516    }
[2]1517
[608]1518    // decode significant_coeffgroup_flag
[1313]1519    Int iCGBlkPos = codingParameters.scanCG[ iSubSet ];
1520    Int iCGPosY   = iCGBlkPos / codingParameters.widthInGroups;
1521    Int iCGPosX   = iCGBlkPos - (iCGPosY * codingParameters.widthInGroups);
1522
[608]1523    if( iSubSet == iLastScanSet || iSubSet == 0)
1524    {
1525      uiSigCoeffGroupFlag[ iCGBlkPos ] = 1;
1526    }
1527    else
1528    {
1529      UInt uiSigCoeffGroup;
[1313]1530      UInt uiCtxSig  = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups );
1531      m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_group) );
[608]1532      uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup;
1533    }
[56]1534
[608]1535    // decode significant_coeff_flag
[1313]1536    const Int patternSigCtx = TComTrQuant::calcPatternSigCtx(uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups);
1537
1538    UInt uiBlkPos, uiSig, uiCtxSig;
[608]1539    for( ; iScanPosSig >= iSubPos; iScanPosSig-- )
1540    {
[1313]1541      uiBlkPos  = codingParameters.scan[ iScanPosSig ];
[608]1542      uiSig     = 0;
[1313]1543
[608]1544      if( uiSigCoeffGroupFlag[ iCGBlkPos ] )
[56]1545      {
[608]1546        if( iScanPosSig > iSubPos || iSubSet == 0  || numNonZero )
[2]1547        {
[1313]1548          uiCtxSig  = TComTrQuant::getSigCtxInc( patternSigCtx, codingParameters, iScanPosSig, uiLog2BlockWidth, uiLog2BlockHeight, chType );
1549          m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_map) );
[2]1550        }
[608]1551        else
[2]1552        {
[608]1553          uiSig = 1;
[2]1554        }
[56]1555      }
[608]1556      pcCoef[ uiBlkPos ] = uiSig;
1557      if( uiSig )
1558      {
1559        pos[ numNonZero ] = uiBlkPos;
1560        numNonZero ++;
1561        if( lastNZPosInCG == -1 )
1562        {
1563          lastNZPosInCG = iScanPosSig;
1564        }
1565        firstNZPosInCG = iScanPosSig;
1566      }
1567    }
[1313]1568
1569    if( numNonZero > 0 )
[2]1570    {
[608]1571      Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD );
[1313]1572
[56]1573      absSum = 0;
[1313]1574
1575      const UInt uiCtxSet = getContextSetIndex(compID, iSubSet, (c1 == 0));
1576      c1 = 1;
[56]1577      UInt uiBin;
[1313]1578
1579      ContextModel *baseCtxMod = m_cCUOneSCModel.get( 0, 0 ) + (NUM_ONE_FLAG_CTX_PER_SET * uiCtxSet);
1580
1581      Int absCoeff[1 << MLS_CG_SIZE];
1582
1583      for ( Int i = 0; i < numNonZero; i++)
[2]1584      {
[1313]1585        absCoeff[i] = 1;
[56]1586      }
1587      Int numC1Flag = min(numNonZero, C1FLAG_NUMBER);
1588      Int firstC2FlagIdx = -1;
1589
1590      for( Int idx = 0; idx < numC1Flag; idx++ )
1591      {
[1313]1592        m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_gt1) );
[56]1593        if( uiBin == 1 )
[2]1594        {
[56]1595          c1 = 0;
1596          if (firstC2FlagIdx == -1)
1597          {
1598            firstC2FlagIdx = idx;
1599          }
[1313]1600          else //if a greater-than-one has been encountered already this group
1601          {
1602            escapeDataPresentInGroup = true;
1603          }
[56]1604        }
1605        else if( (c1 < 3) && (c1 > 0) )
1606        {
[2]1607          c1++;
1608        }
[56]1609        absCoeff[ idx ] = uiBin + 1;
1610      }
[1313]1611
[56]1612      if (c1 == 0)
1613      {
[1313]1614        baseCtxMod = m_cCUAbsSCModel.get( 0, 0 ) + (NUM_ABS_FLAG_CTX_PER_SET * uiCtxSet);
[56]1615        if ( firstC2FlagIdx != -1)
[2]1616        {
[1313]1617          m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_gt2) );
[56]1618          absCoeff[ firstC2FlagIdx ] = uiBin + 2;
[1313]1619          if (uiBin != 0)
1620          {
1621            escapeDataPresentInGroup = true;
1622          }
[2]1623        }
1624      }
[56]1625
[1313]1626      escapeDataPresentInGroup = escapeDataPresentInGroup || (numNonZero > C1FLAG_NUMBER);
1627
1628      const Bool alignGroup = escapeDataPresentInGroup && alignCABACBeforeBypass;
1629
1630#if RExt__DECODER_DEBUG_BIT_STATISTICS
1631      TComCodingStatisticsClassType ctype_signs((alignGroup ? STATS__CABAC_BITS__ALIGNED_SIGN_BIT    : STATS__CABAC_BITS__SIGN_BIT   ), uiLog2BlockWidth, compID);
1632      TComCodingStatisticsClassType ctype_escs ((alignGroup ? STATS__CABAC_BITS__ALIGNED_ESCAPE_BITS : STATS__CABAC_BITS__ESCAPE_BITS), uiLog2BlockWidth, compID);
1633#endif
1634
1635      if (alignGroup)
1636      {
1637        m_pcTDecBinIf->align();
1638      }
1639
[56]1640      UInt coeffSigns;
1641      if ( signHidden && beValid )
1642      {
[1313]1643        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_signs) );
[56]1644        coeffSigns <<= 32 - (numNonZero-1);
1645      }
1646      else
1647      {
[1313]1648        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_signs) );
[56]1649        coeffSigns <<= 32 - numNonZero;
1650      }
[1313]1651
1652      Int iFirstCoeff2 = 1;
1653      if (escapeDataPresentInGroup)
[2]1654      {
[56]1655        for( Int idx = 0; idx < numNonZero; idx++ )
[2]1656        {
[56]1657          UInt baseLevel  = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2) : 1;
[2]1658
[56]1659          if( absCoeff[ idx ] == baseLevel)
[2]1660          {
[56]1661            UInt uiLevel;
[1313]1662            xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam, extendedPrecision, maxLog2TrDynamicRange RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_escs) );
1663
[56]1664            absCoeff[ idx ] = uiLevel + baseLevel;
[1313]1665
1666            if (absCoeff[idx] > (3 << uiGoRiceParam))
[608]1667            {
[1313]1668              uiGoRiceParam = bUseGolombRiceParameterAdaptation ? (uiGoRiceParam + 1) : (std::min<UInt>((uiGoRiceParam + 1), 4));
[608]1669            }
[1313]1670
1671            if (updateGolombRiceStatistics)
1672            {
1673              const UInt initialGolombRiceParameter = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR;
1674
1675              if (uiLevel >= (3 << initialGolombRiceParameter))
1676              {
1677                currentGolombRiceStatistic++;
1678              }
1679              else if (((uiLevel * 2) < (1 << initialGolombRiceParameter)) && (currentGolombRiceStatistic > 0))
1680              {
1681                currentGolombRiceStatistic--;
1682              }
1683
1684              updateGolombRiceStatistics = false;
1685            }
[2]1686          }
[56]1687
[1313]1688          if(absCoeff[ idx ] >= 2)
[2]1689          {
[56]1690            iFirstCoeff2 = 0;
[2]1691          }
1692        }
1693      }
[56]1694
1695      for( Int idx = 0; idx < numNonZero; idx++ )
[2]1696      {
[56]1697        Int blkPos = pos[ idx ];
1698        // Signs applied later.
1699        pcCoef[ blkPos ] = absCoeff[ idx ];
1700        absSum += absCoeff[ idx ];
1701
1702        if ( idx == numNonZero-1 && signHidden && beValid )
1703        {
1704          // Infer sign of 1st element.
1705          if (absSum&0x1)
[608]1706          {
[56]1707            pcCoef[ blkPos ] = -pcCoef[ blkPos ];
[608]1708          }
[56]1709        }
1710        else
1711        {
1712          Int sign = static_cast<Int>( coeffSigns ) >> 31;
1713          pcCoef[ blkPos ] = ( pcCoef[ blkPos ] ^ sign ) - sign;
1714          coeffSigns <<= 1;
1715        }
[2]1716      }
1717    }
1718  }
[1313]1719
1720#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
1721  printSBACCoeffData(uiPosLastX, uiPosLastY, uiWidth, uiHeight, compID, uiAbsPartIdx, codingParameters.scanType, pcCoef);
1722#endif
1723
[2]1724  return;
1725}
1726
[443]1727Void TDecSbac::parseSaoMaxUvlc ( UInt& val, UInt maxSymbol )
1728{
[608]1729  if (maxSymbol == 0)
[2]1730  {
[608]1731    val = 0;
[2]1732    return;
1733  }
[56]1734
[608]1735  UInt code;
[2]1736  Int  i;
[1313]1737  m_pcTDecBinIf->decodeBinEP( code RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
[608]1738  if ( code == 0 )
[2]1739  {
[608]1740    val = 0;
[2]1741    return;
1742  }
[56]1743
[2]1744  i=1;
1745  while (1)
1746  {
[1313]1747    m_pcTDecBinIf->decodeBinEP( code RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
[608]1748    if ( code == 0 )
1749    {
1750      break;
1751    }
[2]1752    i++;
[1313]1753    if (i == maxSymbol)
[56]1754    {
[608]1755      break;
[56]1756    }
1757  }
[608]1758
1759  val = i;
[2]1760}
[1313]1761
[608]1762Void TDecSbac::parseSaoUflc (UInt uiLength, UInt&  riVal)
[56]1763{
[1313]1764  m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
[56]1765}
[1313]1766
[608]1767Void TDecSbac::parseSaoMerge (UInt&  ruiVal)
[2]1768{
1769  UInt uiCode;
[1313]1770  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
[56]1771  ruiVal = (Int)uiCode;
1772}
[1313]1773
[56]1774Void TDecSbac::parseSaoTypeIdx (UInt&  ruiVal)
1775{
1776  UInt uiCode;
[1313]1777  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
1778  if (uiCode == 0)
[2]1779  {
1780    ruiVal = 0;
1781  }
[608]1782  else
[2]1783  {
[1313]1784    m_pcTDecBinIf->decodeBinEP( uiCode RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
[608]1785    if (uiCode == 0)
1786    {
[872]1787      ruiVal = 1;
[608]1788    }
1789    else
1790    {
[872]1791      ruiVal = 2;
[608]1792    }
[2]1793  }
1794}
1795
[872]1796Void TDecSbac::parseSaoSign(UInt& val)
[2]1797{
[1313]1798  m_pcTDecBinIf->decodeBinEP ( val RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
[56]1799}
[608]1800
[872]1801Void TDecSbac::parseSAOBlkParam (SAOBlkParam& saoBlkParam
1802                                , Bool* sliceEnabled
1803                                , Bool leftMergeAvail
1804                                , Bool aboveMergeAvail
[1313]1805                                , const BitDepths &bitDepths
[872]1806                                )
[56]1807{
1808  UInt uiSymbol;
[2]1809
[872]1810  Bool isLeftMerge = false;
1811  Bool isAboveMerge= false;
1812
1813  if(leftMergeAvail)
[608]1814  {
[872]1815    parseSaoMerge(uiSymbol); //sao_merge_left_flag
1816    isLeftMerge = (uiSymbol?true:false);
[608]1817  }
[872]1818
1819  if( aboveMergeAvail && !isLeftMerge)
[608]1820  {
[872]1821    parseSaoMerge(uiSymbol); //sao_merge_up_flag
1822    isAboveMerge = (uiSymbol?true:false);
[608]1823  }
1824
[872]1825  if(isLeftMerge || isAboveMerge) //merge mode
[1313]1826  {
1827    for (UInt componentIndex = 0; componentIndex < MAX_NUM_COMPONENT; componentIndex++)
1828    {
1829      saoBlkParam[componentIndex].modeIdc = (sliceEnabled[componentIndex]) ? SAO_MODE_MERGE : SAO_MODE_OFF;
1830      saoBlkParam[componentIndex].typeIdc = (isLeftMerge)?SAO_MERGE_LEFT:SAO_MERGE_ABOVE;
1831    }
1832  }
[872]1833  else //new or off mode
[1313]1834  {
1835    for(Int compId=COMPONENT_Y; compId < MAX_NUM_COMPONENT; compId++)
1836    {
1837      const ComponentID compIdx=ComponentID(compId);
1838      const ComponentID firstCompOfChType = getFirstComponentOfChannel(toChannelType(compIdx));
[872]1839      SAOOffset& ctbParam = saoBlkParam[compIdx];
[1313]1840#if O0043_BEST_EFFORT_DECODING
1841      const Int bitDepthOrig = bitDepths.stream[toChannelType(compIdx)];
1842      const Int forceBitDepthAdjust = bitDepthOrig - bitDepths.recon[toChannelType(compIdx)];
1843#else
1844      const Int bitDepthOrig = bitDepths.recon[toChannelType(compIdx)];
1845#endif
1846      const Int maxOffsetQVal=TComSampleAdaptiveOffset::getMaxOffsetQVal(bitDepthOrig);
[872]1847      if(!sliceEnabled[compIdx])
[1313]1848      {
[872]1849        //off
1850        ctbParam.modeIdc = SAO_MODE_OFF;
1851        continue;
[1313]1852      }
[872]1853
1854      //type
[1313]1855      if(compIdx == firstCompOfChType)
1856      {
[872]1857        parseSaoTypeIdx(uiSymbol); //sao_type_idx_luma or sao_type_idx_chroma
1858
1859        assert(uiSymbol ==0 || uiSymbol ==1 || uiSymbol ==2);
1860
1861        if(uiSymbol ==0) //OFF
[1313]1862        {
[872]1863          ctbParam.modeIdc = SAO_MODE_OFF;
[1313]1864        }
[872]1865        else if(uiSymbol == 1) //BO
1866        {
1867          ctbParam.modeIdc = SAO_MODE_NEW;
1868          ctbParam.typeIdc = SAO_TYPE_START_BO;
[1313]1869        }
[872]1870        else //2, EO
[1313]1871        {
[872]1872          ctbParam.modeIdc = SAO_MODE_NEW;
1873          ctbParam.typeIdc = SAO_TYPE_START_EO;
1874        }
1875
[1313]1876      }
[872]1877      else //Cr, follow Cb SAO type
1878      {
[1313]1879        ctbParam.modeIdc = saoBlkParam[COMPONENT_Cb].modeIdc;
1880        ctbParam.typeIdc = saoBlkParam[COMPONENT_Cb].typeIdc;
1881      }
[2]1882
[872]1883      if(ctbParam.modeIdc == SAO_MODE_NEW)
[1313]1884      {
[872]1885        Int offset[4];
1886        for(Int i=0; i< 4; i++)
[1313]1887        {
1888          parseSaoMaxUvlc(uiSymbol, maxOffsetQVal ); //sao_offset_abs
[872]1889          offset[i] = (Int)uiSymbol;
[1313]1890        }
[56]1891
[872]1892        if(ctbParam.typeIdc == SAO_TYPE_START_BO)
[1313]1893        {
[872]1894          for(Int i=0; i< 4; i++)
[1313]1895          {
[872]1896            if(offset[i] != 0)
[1313]1897            {
[872]1898              parseSaoSign(uiSymbol); //sao_offset_sign
1899              if(uiSymbol)
[1313]1900              {
1901#if O0043_BEST_EFFORT_DECODING
1902                offset[i] >>= forceBitDepthAdjust;
1903#endif
[872]1904                offset[i] = -offset[i];
[1313]1905              }
1906            }
1907          }
[872]1908          parseSaoUflc(NUM_SAO_BO_CLASSES_LOG2, uiSymbol ); //sao_band_position
1909          ctbParam.typeAuxInfo = uiSymbol;
[608]1910
[872]1911          for(Int i=0; i<4; i++)
[1313]1912          {
[872]1913            ctbParam.offset[(ctbParam.typeAuxInfo+i)%MAX_NUM_SAO_CLASSES] = offset[i];
[1313]1914          }
[56]1915
1916        }
[872]1917        else //EO
[56]1918        {
[872]1919          ctbParam.typeAuxInfo = 0;
1920
[1313]1921          if(firstCompOfChType == compIdx)
1922          {
[872]1923            parseSaoUflc(NUM_SAO_EO_TYPES_LOG2, uiSymbol ); //sao_eo_class_luma or sao_eo_class_chroma
1924            ctbParam.typeIdc += uiSymbol;
[1313]1925          }
1926          else
1927          {
1928            ctbParam.typeIdc = saoBlkParam[firstCompOfChType].typeIdc;
1929          }
[872]1930          ctbParam.offset[SAO_CLASS_EO_FULL_VALLEY] = offset[0];
1931          ctbParam.offset[SAO_CLASS_EO_HALF_VALLEY] = offset[1];
1932          ctbParam.offset[SAO_CLASS_EO_PLAIN      ] = 0;
1933          ctbParam.offset[SAO_CLASS_EO_HALF_PEAK  ] = -offset[2];
1934          ctbParam.offset[SAO_CLASS_EO_FULL_PEAK  ] = -offset[3];
[1313]1935        }
[56]1936      }
1937    }
[2]1938  }
[56]1939}
[608]1940
[56]1941/**
1942 - Initialize our contexts from the nominated source.
1943 .
1944 \param pSrc Contexts to be copied.
1945 */
[1313]1946Void TDecSbac::xCopyContextsFrom( const TDecSbac* pSrc )
[56]1947{
1948  memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0]));
[1313]1949  memcpy(m_golombRiceAdaptationStatistics, pSrc->m_golombRiceAdaptationStatistics, (sizeof(UInt) * RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS));
[56]1950}
[2]1951
[1313]1952Void TDecSbac::xCopyFrom( const TDecSbac* pSrc )
[56]1953{
1954  m_pcTDecBinIf->copyState( pSrc->m_pcTDecBinIf );
1955  xCopyContextsFrom( pSrc );
[1313]1956}
[56]1957
[1313]1958Void TDecSbac::load ( const TDecSbac* pSrc )
1959{
1960  xCopyFrom(pSrc);
[56]1961}
1962
[1313]1963Void TDecSbac::loadContexts ( const TDecSbac* pSrc )
[56]1964{
[1313]1965  xCopyContextsFrom(pSrc);
[56]1966}
1967
[1313]1968/** Performs CABAC decoding of the explicit RDPCM mode
1969 * \param rTu current TU data structure
1970 * \param compID component identifier
1971 */
1972Void TDecSbac::parseExplicitRdpcmMode( TComTU &rTu, ComponentID compID )
[56]1973{
[1313]1974  TComDataCU* cu = rTu.getCU();
1975  const UInt absPartIdx=rTu.GetAbsPartIdxTU(compID);
1976  const TComRectangle &rect = rTu.getRect(compID);
1977  const UInt tuHeight = g_aucConvertToBit[rect.height];
1978  const UInt tuWidth  = g_aucConvertToBit[rect.width];
1979  UInt code = 0;
1980
1981  assert(tuHeight == tuWidth);
1982
1983#if RExt__DECODER_DEBUG_BIT_STATISTICS
1984  const TComCodingStatisticsClassType ctype(STATS__EXPLICIT_RDPCM_BITS, g_aucConvertToBit[cu->getSlice()->getSPS()->getMaxCUWidth()>>rTu.GetTransformDepthTotal()]+2);
1985#endif
1986
1987  m_pcTDecBinIf->decodeBin(code, m_explicitRdpcmFlagSCModel.get (0, toChannelType(compID), 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype));
1988
1989  if(code == 0)
1990  {
1991    cu->setExplicitRdpcmModePartRange( RDPCM_OFF, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID));
1992  }
1993  else
1994  {
1995    m_pcTDecBinIf->decodeBin(code, m_explicitRdpcmDirSCModel.get (0, toChannelType(compID), 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype));
1996    if(code == 0)
1997    {
1998      cu->setExplicitRdpcmModePartRange( RDPCM_HOR, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID));
1999    }
2000    else
2001    {
2002      cu->setExplicitRdpcmModePartRange( RDPCM_VER, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID));
2003    }
2004  }
[56]2005}
2006
2007
2008
2009
[1313]2010
[296]2011
[56]2012//! \}
Note: See TracBrowser for help on using the repository browser.