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