HEVC Test Model (HM)  HM-16.3
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-2015, 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_ADI_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 ChannelType channelType, const class TComCodingStatisticsClassType &whichStat )
302 #else
303 Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const ChannelType channelType )
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 + g_maxTrDynamicRange[channelType])) + 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 + g_maxTrDynamicRange[channelType]));
340 
341  const UInt prefixLength = prefix - COEF_REMAIN_BIN_REDUCTION;
342  const UInt suffixLength = (prefixLength == maximumPrefixLength) ? (g_maxTrDynamicRange[channelType] - 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 
374  pcCU->setPartSizeSubParts ( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
375  pcCU->setSizeSubParts ( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
376  pcCU->setTrIdxSubParts ( 0, uiAbsPartIdx, uiDepth );
377  pcCU->setIPCMFlagSubParts ( bIpcmFlag, uiAbsPartIdx, uiDepth );
378 
379  const UInt minCoeffSizeY = pcCU->getPic()->getMinCUWidth() * pcCU->getPic()->getMinCUHeight();
380  const UInt offsetY = minCoeffSizeY * uiAbsPartIdx;
381  for (UInt ch=0; ch < pcCU->getPic()->getNumberValidComponents(); ch++)
382  {
383  const ComponentID compID = ComponentID(ch);
384  const UInt offset = offsetY >> (pcCU->getPic()->getComponentScaleX(compID) + pcCU->getPic()->getComponentScaleY(compID));
385  Pel * pPCMSample = pcCU->getPCMSample(compID) + offset;
386  const UInt width = pcCU->getWidth (uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleX(compID);
387  const UInt height = pcCU->getHeight(uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleY(compID);
388  const UInt sampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepth(toChannelType(compID));
389  for (UInt y=0; y<height; y++)
390  {
391  for (UInt x=0; x<width; x++)
392  {
393  UInt sample;
394  m_pcTDecBinIf->xReadPCMCode(sampleBits, sample);
395  pPCMSample[x] = sample;
396  }
397  pPCMSample += width;
398  }
399  }
400 
401  m_pcTDecBinIf->start();
402  }
403 }
404 
406 {
407  UInt uiSymbol;
409  pcCU->setCUTransquantBypassSubParts(uiSymbol ? true : false, uiAbsPartIdx, uiDepth);
410 }
411 
418 Void TDecSbac::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
419 {
420  if( pcCU->getSlice()->isIntra() )
421  {
422  return;
423  }
424 
425  UInt uiSymbol = 0;
426  UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx );
429  DTRACE_CABAC_T( "\tSkipFlag" );
430  DTRACE_CABAC_T( "\tuiCtxSkip: ");
431  DTRACE_CABAC_V( uiCtxSkip );
432  DTRACE_CABAC_T( "\tuiSymbol: ");
433  DTRACE_CABAC_V( uiSymbol );
434  DTRACE_CABAC_T( "\n");
435 
436  if( uiSymbol )
437  {
438  pcCU->setSkipFlagSubParts( true, uiAbsPartIdx, uiDepth );
439  pcCU->setPredModeSubParts( MODE_INTER, uiAbsPartIdx, uiDepth );
440  pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
441  pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
442  pcCU->setMergeFlagSubParts( true , uiAbsPartIdx, 0, uiDepth );
443  }
444 }
445 
446 
454 Void TDecSbac::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
455 {
456  UInt uiSymbol;
458  pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth );
459 
461  DTRACE_CABAC_T( "\tMergeFlag: " );
462  DTRACE_CABAC_V( uiSymbol );
463  DTRACE_CABAC_T( "\tAddress: " );
464  DTRACE_CABAC_V( pcCU->getCtuRsAddr() );
465  DTRACE_CABAC_T( "\tuiAbsPartIdx: " );
466  DTRACE_CABAC_V( uiAbsPartIdx );
467  DTRACE_CABAC_T( "\n" );
468 }
469 
471 {
472  UInt uiUnaryIdx = 0;
473  UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand();
474  if ( uiNumCand > 1 )
475  {
476  for( ; uiUnaryIdx < uiNumCand - 1; ++uiUnaryIdx )
477  {
478  UInt uiSymbol = 0;
479  if ( uiUnaryIdx==0 )
480  {
482  }
483  else
484  {
486  }
487  if( uiSymbol == 0 )
488  {
489  break;
490  }
491  }
492  }
493  ruiMergeIndex = uiUnaryIdx;
494 
496  DTRACE_CABAC_T( "\tparseMergeIndex()" )
497  DTRACE_CABAC_T( "\tuiMRGIdx= " )
498  DTRACE_CABAC_V( ruiMergeIndex )
499  DTRACE_CABAC_T( "\n" )
500 }
501 
503 {
504  UInt uiSymbol;
506  riMVPIdx = uiSymbol;
507 }
508 
509 Void TDecSbac::parseSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
510 {
511  if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
512  {
513  pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx );
514  return;
515  }
516 #if RExt__DECODER_DEBUG_BIT_STATISTICS
518 #endif
519 
520  UInt uiSymbol;
521  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_T( "\tSplitFlag\n" )
524  pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx );
525 
526  return;
527 }
528 
535 Void TDecSbac::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
536 {
537  UInt uiSymbol, uiMode = 0;
538  PartSize eMode;
539 
540 #if RExt__DECODER_DEBUG_BIT_STATISTICS
542 #endif
543 
544  if ( pcCU->isIntra( uiAbsPartIdx ) )
545  {
546  uiSymbol = 1;
547  if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
548  {
550  }
551  eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN;
552  UInt uiTrLevel = 0;
553  UInt uiWidthInBit = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2;
554  UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2;
555  uiTrLevel = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0;
556  if( eMode == SIZE_NxN )
557  {
558  pcCU->setTrIdxSubParts( 1+uiTrLevel, uiAbsPartIdx, uiDepth );
559  }
560  else
561  {
562  pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth );
563  }
564  }
565  else
566  {
567  UInt uiMaxNumBits = 2;
568 
569  if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( (g_uiMaxCUWidth>>uiDepth) == 8 && (g_uiMaxCUHeight>>uiDepth) == 8 ) )
570  {
571  uiMaxNumBits ++;
572  }
573 
574  for ( UInt ui = 0; ui < uiMaxNumBits; ui++ )
575  {
577  if ( uiSymbol )
578  {
579  break;
580  }
581  uiMode++;
582  }
583  eMode = (PartSize) uiMode;
584  if ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < g_uiMaxCUDepth-g_uiAddCUDepth )
585  {
586  if (eMode == SIZE_2NxN)
587  {
589  if (uiSymbol == 0)
590  {
592  eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD);
593  }
594  }
595  else if (eMode == SIZE_Nx2N)
596  {
598  if (uiSymbol == 0)
599  {
601  eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N);
602  }
603  }
604  }
605  }
606  pcCU->setPartSizeSubParts( eMode, uiAbsPartIdx, uiDepth );
607  pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
608 }
609 
610 
617 Void TDecSbac::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
618 {
619  if( pcCU->getSlice()->isIntra() )
620  {
621  pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth );
622  return;
623  }
624 
625  UInt uiSymbol;
626  Int iPredMode = MODE_INTER;
628  iPredMode += uiSymbol;
629  pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth );
630 }
631 
632 
634 {
635  PartSize mode = pcCU->getPartitionSize( absPartIdx );
636  UInt partNum = mode==SIZE_NxN?4:1;
637  UInt partOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2;
638  UInt mpmPred[4],symbol;
639  Int j,intraPredMode;
640  if (mode==SIZE_NxN)
641  {
642  depth++;
643  }
644 #if RExt__DECODER_DEBUG_BIT_STATISTICS
646 #endif
647  for (j=0;j<partNum;j++)
648  {
650  mpmPred[j] = symbol;
651  }
652  for (j=0;j<partNum;j++)
653  {
654  Int preds[NUM_MOST_PROBABLE_MODES] = {-1, -1, -1};
655  pcCU->getIntraDirPredictor(absPartIdx+partOffset*j, preds, COMPONENT_Y);
656  if (mpmPred[j])
657  {
659  if (symbol)
660  {
662  symbol++;
663  }
664  intraPredMode = preds[symbol];
665  }
666  else
667  {
669  intraPredMode = symbol;
670 
671  //postponed sorting of MPMs (only in remaining branch)
672  if (preds[0] > preds[1])
673  {
674  std::swap(preds[0], preds[1]);
675  }
676  if (preds[0] > preds[2])
677  {
678  std::swap(preds[0], preds[2]);
679  }
680  if (preds[1] > preds[2])
681  {
682  std::swap(preds[1], preds[2]);
683  }
684  for ( UInt i = 0; i < NUM_MOST_PROBABLE_MODES; i++ )
685  {
686  intraPredMode += ( intraPredMode >= preds[i] );
687  }
688  }
689  pcCU->setIntraDirSubParts(CHANNEL_TYPE_LUMA, (UChar)intraPredMode, absPartIdx+partOffset*j, depth );
690  }
691 }
692 
693 
694 Void TDecSbac::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
695 {
696  UInt uiSymbol;
697 #if RExt__DECODER_DEBUG_BIT_STATISTICS
699 #endif
700 
702  if( uiSymbol == 0 )
703  {
704  uiSymbol = DM_CHROMA_IDX;
705  }
706  else
707  {
708  UInt uiIPredMode;
710  UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ];
711  pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir );
712  uiSymbol = uiAllowedChromaDir[ uiIPredMode ];
713  }
714 
715  pcCU->setIntraDirSubParts( CHANNEL_TYPE_CHROMA, uiSymbol, uiAbsPartIdx, uiDepth );
716 }
717 
718 
719 Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx )
720 {
721  UInt uiSymbol;
722  const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx );
724 
725  uiSymbol = 0;
726  if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 )
727  {
729  }
730 
731  if( uiSymbol )
732  {
733  uiSymbol = 2;
734  }
735  else
736  {
738  assert(uiSymbol == 0 || uiSymbol == 1);
739  }
740 
741  uiSymbol++;
742  ruiInterDir = uiSymbol;
743  return;
744 }
745 
746 Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList )
747 {
748  UInt uiSymbol;
749 
750  ContextModel *pCtx = m_cCURefPicSCModel.get( 0 );
752 
753  if( uiSymbol )
754  {
755  UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2;
756  pCtx++;
757  UInt ui;
758  for( ui = 0; ui < uiRefNum; ++ui )
759  {
760  if( ui == 0 )
761  {
763  }
764  else
765  {
767  }
768  if( uiSymbol == 0 )
769  {
770  break;
771  }
772  }
773  uiSymbol = ui + 1;
774  }
775  riRefFrmIdx = uiSymbol;
776 
777  return;
778 }
779 
780 Void TDecSbac::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList )
781 {
782  UInt uiSymbol;
783  UInt uiHorAbs;
784  UInt uiVerAbs;
785  UInt uiHorSign = 0;
786  UInt uiVerSign = 0;
787  ContextModel *pCtx = m_cCUMvdSCModel.get( 0 );
788 
789  if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3)
790  {
791  uiHorAbs=0;
792  uiVerAbs=0;
793  }
794  else
795  {
798 
799  const Bool bHorAbsGr0 = uiHorAbs != 0;
800  const Bool bVerAbsGr0 = uiVerAbs != 0;
801  pCtx++;
802 
803  if( bHorAbsGr0 )
804  {
806  uiHorAbs += uiSymbol;
807  }
808 
809  if( bVerAbsGr0 )
810  {
812  uiVerAbs += uiSymbol;
813  }
814 
815  if( bHorAbsGr0 )
816  {
817  if( 2 == uiHorAbs )
818  {
820  uiHorAbs += uiSymbol;
821  }
822 
824  }
825 
826  if( bVerAbsGr0 )
827  {
828  if( 2 == uiVerAbs )
829  {
831  uiVerAbs += uiSymbol;
832  }
833 
835  }
836 
837  }
838 
839  const TComMv cMv( uiHorSign ? -Int( uiHorAbs ): uiHorAbs, uiVerSign ? -Int( uiVerAbs ) : uiVerAbs );
840  pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiDepth, uiPartIdx );
841  return;
842 }
843 
845 {
846  TComDataCU *pcCU = rTu.getCU();
847 
848  if( isLuma(compID) || !pcCU->getSlice()->getPPS()->getUseCrossComponentPrediction() )
849  {
850  return;
851  }
852 
853  const UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU();
854 
855  if (!pcCU->isIntra(uiAbsPartIdx) || (pcCU->getIntraDir( CHANNEL_TYPE_CHROMA, uiAbsPartIdx ) == DM_CHROMA_IDX))
856  {
857  Char alpha = 0;
858  UInt symbol = 0;
859 
861  DTRACE_CABAC_T("\tparseCrossComponentPrediction()")
862  DTRACE_CABAC_T( "\tAddr=" )
863  DTRACE_CABAC_V( compID )
864  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
865  DTRACE_CABAC_V( uiAbsPartIdx )
866 #if RExt__DECODER_DEBUG_BIT_STATISTICS
868 #endif
871 
872  if(symbol != 0)
873  {
874  // Cross-component prediction alpha is non-zero.
875  UInt sign = 0;
877 
878  if (symbol != 0)
879  {
880  // alpha is 2 (symbol=1), 4(symbol=2) or 8(symbol=3).
881  // Read up to two more bits
882  xReadUnaryMaxSymbol( symbol, (pCtx + 2), 1, 2 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
883  symbol += 1;
884  }
886 
887  alpha = (sign != 0) ? -(1 << symbol) : (1 << symbol);
888  }
889  DTRACE_CABAC_T( "\tAlpha=" )
890  DTRACE_CABAC_V( alpha )
891  DTRACE_CABAC_T( "\n" )
892 
893  pcCU->setCrossComponentPredictionAlphaPartRange( alpha, compID, uiAbsPartIdx, rTu.GetAbsPartIdxNumParts( compID ) );
894  }
895 }
896 
897 Void TDecSbac::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize )
898 {
899  m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize )
901  );
903  DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" )
904  DTRACE_CABAC_T( "\tsymbol=" )
905  DTRACE_CABAC_V( ruiSubdivFlag )
906  DTRACE_CABAC_T( "\tctx=" )
907  DTRACE_CABAC_V( uiLog2TransformBlockSize )
908  DTRACE_CABAC_T( "\n" )
909 }
910 
911 Void TDecSbac::parseQtRootCbf( UInt uiAbsPartIdx, UInt& uiQtRootCbf )
912 {
913  UInt uiSymbol;
914  const UInt uiCtx = 0;
917  DTRACE_CABAC_T( "\tparseQtRootCbf()" )
918  DTRACE_CABAC_T( "\tsymbol=" )
919  DTRACE_CABAC_V( uiSymbol )
920  DTRACE_CABAC_T( "\tctx=" )
921  DTRACE_CABAC_V( uiCtx )
922  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
923  DTRACE_CABAC_V( uiAbsPartIdx )
924  DTRACE_CABAC_T( "\n" )
925 
926  uiQtRootCbf = uiSymbol;
927 }
928 
929 Void TDecSbac::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
930 {
931  Int qp;
932  UInt uiDQp;
933  Int iDQp;
934 
935  UInt uiSymbol;
936 
938 
939  if( uiDQp >= CU_DQP_TU_CMAX)
940  {
942  uiDQp+=uiSymbol;
943  }
944 
945  if ( uiDQp > 0 )
946  {
947  UInt uiSign;
948  Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA);
950  iDQp = uiDQp;
951  if(uiSign)
952  {
953  iDQp = -iDQp;
954  }
955  qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY;
956  }
957  else
958  {
959  qp = pcCU->getRefQP(uiAbsPartIdx);
960  }
961 
962  pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth);
963  pcCU->setCodedQP(qp);
964 }
965 
970 {
971  UInt symbol;
972 #if RExt__DECODER_DEBUG_BIT_STATISTICS
974 #endif
975 
976  Int tableSize = cu->getSlice()->getPPS()->getChromaQpAdjTableSize();
977 
978  /* cu_chroma_qp_adjustment_flag */
980 
981  if (symbol && tableSize > 1)
982  {
983  /* cu_chroma_qp_adjustment_idc */
985  symbol++;
986  }
987  /* NB, symbol = 0 if outer flag is not set,
988  * 1 if outer flag is set and there is no inner flag
989  * 1+ otherwise */
990  cu->setChromaQpAdjSubParts( symbol, absPartIdx, depth );
991  cu->setCodedChromaQpAdj(symbol);
992 }
993 
994 Void TDecSbac::parseQtCbf( TComTU &rTu, const ComponentID compID, const Bool lowestLevel )
995 {
996  TComDataCU* pcCU = rTu.getCU();
997 
998  const UInt absPartIdx = rTu.GetAbsPartIdxTU(compID);
999  const UInt TUDepth = rTu.GetTransformDepthRel();
1000  const UInt uiCtx = pcCU->getCtxQtCbf( rTu, toChannelType(compID) );
1001  const UInt contextSet = toChannelType(compID);
1002 
1003  const UInt width = rTu.getRect(compID).width;
1004  const UInt height = rTu.getRect(compID).height;
1005  const Bool canQuadSplit = (width >= (MIN_TU_SIZE * 2)) && (height >= (MIN_TU_SIZE * 2));
1006  const UInt coveredPartIdxes = rTu.GetAbsPartIdxNumParts(compID);
1007 
1008  // Since the CBF for chroma is coded at the highest level possible, if sub-TUs are
1009  // to be coded for a 4x8 chroma TU, their CBFs must be coded at the highest 4x8 level
1010  // (i.e. where luma TUs are 8x8 rather than 4x4)
1011  // ___ ___
1012  // | | | <- 4 x (8x8 luma + 4x8 4:2:2 chroma)
1013  // |___|___| each quadrant has its own chroma CBF
1014  // | | | _ _ _ _
1015  // |___|___| |
1016  // <--16---> V
1017  // _ _
1018  // |_|_| <- 4 x 4x4 luma + 1 x 4x8 4:2:2 chroma
1019  // |_|_| no chroma CBF is coded - instead the parent CBF is inherited
1020  // <-8-> if sub-TUs are present, their CBFs had to be coded at the parent level
1021 
1022  const UInt lowestTUDepth = TUDepth + ((!lowestLevel && !canQuadSplit) ? 1 : 0); //unsplittable TUs inherit their parent's CBF
1023  UInt lowestTUCBF = 0;
1024 
1025  if ((width != height) && (lowestLevel || !canQuadSplit)) //if sub-TUs are present
1026  {
1027  const UInt subTUDepth = lowestTUDepth + 1;
1028  const UInt partIdxesPerSubTU = rTu.GetAbsPartIdxNumParts(compID) >> 1;
1029 
1030  UInt combinedSubTUCBF = 0;
1031 
1032  for (UInt subTU = 0; subTU < 2; subTU++)
1033  {
1034  UInt uiCbf = MAX_UINT;
1036 
1037  const UInt subTUAbsPartIdx = absPartIdx + (subTU * partIdxesPerSubTU);
1038  pcCU->setCbfPartRange((uiCbf << subTUDepth), compID, subTUAbsPartIdx, partIdxesPerSubTU);
1039  combinedSubTUCBF |= uiCbf;
1040 
1042  DTRACE_CABAC_T( "\tparseQtCbf()" )
1043  DTRACE_CABAC_T( "\tsub-TU=" )
1044  DTRACE_CABAC_V( subTU )
1045  DTRACE_CABAC_T( "\tsymbol=" )
1046  DTRACE_CABAC_V( uiCbf )
1047  DTRACE_CABAC_T( "\tctx=" )
1048  DTRACE_CABAC_V( uiCtx )
1049  DTRACE_CABAC_T( "\tetype=" )
1050  DTRACE_CABAC_V( compID )
1051  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1052  DTRACE_CABAC_V( subTUAbsPartIdx )
1053  DTRACE_CABAC_T( "\n" )
1054  }
1055 
1056  //propagate the sub-TU CBF up to the lowest TU level
1057  if (combinedSubTUCBF != 0)
1058  {
1059  pcCU->bitwiseOrCbfPartRange((combinedSubTUCBF << lowestTUDepth), compID, absPartIdx, coveredPartIdxes);
1060  lowestTUCBF = combinedSubTUCBF;
1061  }
1062  }
1063  else
1064  {
1065  UInt uiCbf = MAX_UINT;
1067 
1068  pcCU->setCbfSubParts((uiCbf << lowestTUDepth), compID, absPartIdx, rTu.GetTransformDepthTotalAdj(compID));
1069 
1071  DTRACE_CABAC_T( "\tparseQtCbf()" )
1072  DTRACE_CABAC_T( "\tsymbol=" )
1073  DTRACE_CABAC_V( uiCbf )
1074  DTRACE_CABAC_T( "\tctx=" )
1075  DTRACE_CABAC_V( uiCtx )
1076  DTRACE_CABAC_T( "\tetype=" )
1077  DTRACE_CABAC_V( compID )
1078  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1079  DTRACE_CABAC_V( rTu.GetAbsPartIdxTU(compID) )
1080  DTRACE_CABAC_T( "\n" )
1081 
1082  lowestTUCBF = uiCbf;
1083  }
1084 
1085  //propagate the lowest level CBF up to the current level
1086  if (lowestTUCBF != 0)
1087  {
1088  for (UInt depth = TUDepth; depth < lowestTUDepth; depth++)
1089  {
1090  pcCU->bitwiseOrCbfPartRange((lowestTUCBF << depth), compID, absPartIdx, coveredPartIdxes);
1091  }
1092  }
1093 }
1094 
1095 
1097 {
1098  TComDataCU* pcCU=rTu.getCU();
1099  UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(component);
1100 
1101  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
1102  {
1103  return;
1104  }
1105 
1107  {
1108  return;
1109  }
1110 
1111  UInt useTransformSkip;
1112 
1113  m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, toChannelType(component), 0 )
1115  );
1116 
1118  DTRACE_CABAC_T("\tparseTransformSkip()");
1119  DTRACE_CABAC_T( "\tsymbol=" )
1120  DTRACE_CABAC_V( useTransformSkip )
1121  DTRACE_CABAC_T( "\tAddr=" )
1122  DTRACE_CABAC_V( pcCU->getCtuRsAddr() )
1123  DTRACE_CABAC_T( "\tetype=" )
1124  DTRACE_CABAC_V( component )
1125  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1127  DTRACE_CABAC_T( "\n" )
1128 
1129  pcCU->setTransformSkipPartRange( useTransformSkip, component, uiAbsPartIdx, rTu.GetAbsPartIdxNumParts(component));
1130 }
1131 
1132 
1143 Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, ComponentID component, UInt uiScanIdx )
1144 {
1145  UInt uiLast;
1146 
1147  ContextModel *pCtxX = m_cCuCtxLastX.get( 0, toChannelType(component) );
1148  ContextModel *pCtxY = m_cCuCtxLastY.get( 0, toChannelType(component) );
1149 
1150 #if RExt__DECODER_DEBUG_BIT_STATISTICS
1152 #endif
1153 
1154 
1155  if ( uiScanIdx == SCAN_VER )
1156  {
1157  swap( width, height );
1158  }
1159 
1160  Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY;
1161  getLastSignificantContextParameters(component, width, height, blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY);
1162 
1163  //------------------
1164 
1165  // posX
1166 
1167  for( uiPosLastX = 0; uiPosLastX < g_uiGroupIdx[ width - 1 ]; uiPosLastX++ )
1168  {
1169  m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + blkSizeOffsetX + (uiPosLastX >>shiftX) ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
1170 
1171  if( !uiLast )
1172  {
1173  break;
1174  }
1175  }
1176 
1177  // posY
1178 
1179  for( uiPosLastY = 0; uiPosLastY < g_uiGroupIdx[ height - 1 ]; uiPosLastY++ )
1180  {
1181  m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + blkSizeOffsetY + (uiPosLastY >>shiftY)) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
1182 
1183  if( !uiLast )
1184  {
1185  break;
1186  }
1187  }
1188 
1189  // EP-coded part
1190 
1191  if ( uiPosLastX > 3 )
1192  {
1193  UInt uiTemp = 0;
1194  UInt uiCount = ( uiPosLastX - 2 ) >> 1;
1195  for ( Int i = uiCount - 1; i >= 0; i-- )
1196  {
1198  uiTemp += uiLast << i;
1199  }
1200  uiPosLastX = g_uiMinInGroup[ uiPosLastX ] + uiTemp;
1201  }
1202  if ( uiPosLastY > 3 )
1203  {
1204  UInt uiTemp = 0;
1205  UInt uiCount = ( uiPosLastY - 2 ) >> 1;
1206  for ( Int i = uiCount - 1; i >= 0; i-- )
1207  {
1209  uiTemp += uiLast << i;
1210  }
1211  uiPosLastY = g_uiMinInGroup[ uiPosLastY ] + uiTemp;
1212  }
1213 
1214  if( uiScanIdx == SCAN_VER )
1215  {
1216  swap( uiPosLastX, uiPosLastY );
1217  }
1218 }
1219 
1221 {
1222  TComDataCU* pcCU=rTu.getCU();
1223  const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(compID);
1224  const TComRectangle &rRect=rTu.getRect(compID);
1225  const UInt uiWidth=rRect.width;
1226  const UInt uiHeight=rRect.height;
1227  TCoeff* pcCoef=(pcCU->getCoeff(compID)+rTu.getCoefficientOffset(compID));
1228 
1230  DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" )
1231  DTRACE_CABAC_V( compID )
1232  DTRACE_CABAC_T( "\twidth=" )
1233  DTRACE_CABAC_V( uiWidth )
1234  DTRACE_CABAC_T( "\theight=" )
1235  DTRACE_CABAC_V( uiHeight )
1236  DTRACE_CABAC_T( "\tdepth=" )
1237 // DTRACE_CABAC_V( rTu.GetTransformDepthTotalAdj(compID) )
1239  DTRACE_CABAC_T( "\tabspartidx=" )
1240 // DTRACE_CABAC_V( uiAbsPartIdx )
1241  DTRACE_CABAC_V( rTu.GetAbsPartIdxTU(compID) )
1242  DTRACE_CABAC_T( "\ttoCU-X=" )
1243  DTRACE_CABAC_V( pcCU->getCUPelX() )
1244  DTRACE_CABAC_T( "\ttoCU-Y=" )
1245  DTRACE_CABAC_V( pcCU->getCUPelY() )
1246  DTRACE_CABAC_T( "\tCU-addr=" )
1247  DTRACE_CABAC_V( pcCU->getCtuRsAddr() )
1248  DTRACE_CABAC_T( "\tinCU-X=" )
1249 // DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1251  DTRACE_CABAC_T( "\tinCU-Y=" )
1252 // DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1254  DTRACE_CABAC_T( "\tpredmode=" )
1255  DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) )
1256  DTRACE_CABAC_T( "\n" )
1257 
1258  //--------------------------------------------------------------------------------------------------
1259 
1260  if( uiWidth > pcCU->getSlice()->getSPS()->getMaxTrSize() )
1261  {
1262  std::cerr << "ERROR: parseCoeffNxN was passed a TU with dimensions larger than the maximum allowed size" << std::endl;
1263  assert(false);
1264  exit(1);
1265  }
1266 
1267  //--------------------------------------------------------------------------------------------------
1268 
1269  //set parameters
1270 
1271  const ChannelType chType = toChannelType(compID);
1272  const UInt uiLog2BlockWidth = g_aucConvertToBit[ uiWidth ] + 2;
1273  const UInt uiLog2BlockHeight = g_aucConvertToBit[ uiHeight ] + 2;
1274  const UInt uiMaxNumCoeff = uiWidth * uiHeight;
1275  const UInt uiMaxNumCoeffM1 = uiMaxNumCoeff - 1;
1276 
1277  const ChannelType channelType = toChannelType(compID);
1278  const Bool extendedPrecision = pcCU->getSlice()->getSPS()->getUseExtendedPrecision();
1279 
1280  const Bool alignCABACBeforeBypass = pcCU->getSlice()->getSPS()->getAlignCABACBeforeBypass();
1281 
1282 #if RExt__DECODER_DEBUG_BIT_STATISTICS
1283  TComCodingStatisticsClassType ctype_group(STATS__CABAC_BITS__SIG_COEFF_GROUP_FLAG, uiLog2BlockWidth, compID);
1284  TComCodingStatisticsClassType ctype_map(STATS__CABAC_BITS__SIG_COEFF_MAP_FLAG, uiLog2BlockWidth, compID);
1285  TComCodingStatisticsClassType ctype_gt1(STATS__CABAC_BITS__GT1_FLAG, uiLog2BlockWidth, compID);
1286  TComCodingStatisticsClassType ctype_gt2(STATS__CABAC_BITS__GT2_FLAG, uiLog2BlockWidth, compID);
1287 #endif
1288 
1289  Bool beValid;
1290  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
1291  {
1292  beValid = false;
1293  if((!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx))
1294  {
1295  parseExplicitRdpcmMode(rTu, compID);
1296  }
1297  }
1298  else
1299  {
1300  beValid = pcCU->getSlice()->getPPS()->getSignHideFlag();
1301  }
1302 
1303  UInt absSum = 0;
1304 
1305  //--------------------------------------------------------------------------------------------------
1306 
1307  if(pcCU->getSlice()->getPPS()->getUseTransformSkip())
1308  {
1309  parseTransformSkipFlags(rTu, compID);
1310  // This TU has coefficients and is transform skipped. Check whether is inter coded and if yes decode the explicit RDPCM mode
1311  if(pcCU->getTransformSkip(uiAbsPartIdx, compID) && (!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx) )
1312  {
1313  parseExplicitRdpcmMode(rTu, compID);
1314  if(pcCU->getExplicitRdpcmMode(compID, uiAbsPartIdx) != RDPCM_OFF)
1315  {
1316  // Sign data hiding is avoided for horizontal and vertical RDPCM modes
1317  beValid = false;
1318  }
1319  }
1320  }
1321 
1322  Int uiIntraMode = -1;
1323  const Bool bIsLuma = isLuma(compID);
1324  Int isIntra = pcCU->isIntra(uiAbsPartIdx) ? 1 : 0;
1325  if ( isIntra && pcCU->isRDPCMEnabled(uiAbsPartIdx) )
1326  {
1327  uiIntraMode = pcCU->getIntraDir( toChannelType(compID), uiAbsPartIdx );
1328  uiIntraMode = (uiIntraMode==DM_CHROMA_IDX && !bIsLuma) ? pcCU->getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, rTu.GetChromaFormat())) : uiIntraMode;
1329  uiIntraMode = ((rTu.GetChromaFormat() == CHROMA_422) && !bIsLuma) ? g_chroma422IntraAngleMappingTable[uiIntraMode] : uiIntraMode;
1330 
1331  Bool transformSkip = pcCU->getTransformSkip( uiAbsPartIdx,compID);
1332  Bool rdpcm_lossy = ( transformSkip /*&& isIntra*/ && ( (uiIntraMode == HOR_IDX) || (uiIntraMode == VER_IDX) ) );
1333  if ( rdpcm_lossy )
1334  {
1335  beValid = false;
1336  }
1337  }
1338 
1339  //--------------------------------------------------------------------------------------------------
1340 
1341  const Bool bUseGolombRiceParameterAdaptation = pcCU->getSlice()->getSPS()->getUseGolombRiceParameterAdaptation();
1342  UInt &currentGolombRiceStatistic = m_golombRiceAdaptationStatistics[rTu.getGolombRiceStatisticsIndex(compID)];
1343 
1344  //select scans
1345  TUEntropyCodingParameters codingParameters;
1346  getTUEntropyCodingParameters(codingParameters, rTu, compID);
1347 
1348  //===== decode last significant =====
1349  UInt uiPosLastX, uiPosLastY;
1350  parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, compID, codingParameters.scanType );
1351  UInt uiBlkPosLast = uiPosLastX + (uiPosLastY<<uiLog2BlockWidth);
1352  pcCoef[ uiBlkPosLast ] = 1;
1353 
1354  //===== decode significance flags =====
1355  UInt uiScanPosLast;
1356  for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ )
1357  {
1358  UInt uiBlkPos = codingParameters.scan[ uiScanPosLast ];
1359  if( uiBlkPosLast == uiBlkPos )
1360  {
1361  break;
1362  }
1363  }
1364 
1365  ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, isChroma(chType) );
1366  ContextModel * const baseCtx = m_cCUSigSCModel.get( 0, 0 ) + getSignificanceMapContextOffset(compID);
1367 
1368  const Int iLastScanSet = uiScanPosLast >> MLS_CG_SIZE;
1369  UInt c1 = 1;
1370  UInt uiGoRiceParam = 0;
1371 
1372 
1373  UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ];
1374  memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM );
1375 
1376  Int iScanPosSig = (Int) uiScanPosLast;
1377  for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- )
1378  {
1379  Int iSubPos = iSubSet << MLS_CG_SIZE;
1380  uiGoRiceParam = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR;
1381  Bool updateGolombRiceStatistics = bUseGolombRiceParameterAdaptation; //leave the statistics at 0 when not using the adaptation system
1382  Int numNonZero = 0;
1383 
1384  Int lastNZPosInCG = -1;
1385  Int firstNZPosInCG = 1 << MLS_CG_SIZE;
1386 
1387  Bool escapeDataPresentInGroup = false;
1388 
1389  Int pos[1 << MLS_CG_SIZE];
1390 
1391  if( iScanPosSig == (Int) uiScanPosLast )
1392  {
1393  lastNZPosInCG = iScanPosSig;
1394  firstNZPosInCG = iScanPosSig;
1395  iScanPosSig--;
1396  pos[ numNonZero ] = uiBlkPosLast;
1397  numNonZero = 1;
1398  }
1399 
1400  // decode significant_coeffgroup_flag
1401  Int iCGBlkPos = codingParameters.scanCG[ iSubSet ];
1402  Int iCGPosY = iCGBlkPos / codingParameters.widthInGroups;
1403  Int iCGPosX = iCGBlkPos - (iCGPosY * codingParameters.widthInGroups);
1404 
1405  if( iSubSet == iLastScanSet || iSubSet == 0)
1406  {
1407  uiSigCoeffGroupFlag[ iCGBlkPos ] = 1;
1408  }
1409  else
1410  {
1411  UInt uiSigCoeffGroup;
1412  UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups );
1413  m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_group) );
1414  uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup;
1415  }
1416 
1417  // decode significant_coeff_flag
1418  const Int patternSigCtx = TComTrQuant::calcPatternSigCtx(uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups);
1419 
1420  UInt uiBlkPos, uiSig, uiCtxSig;
1421  for( ; iScanPosSig >= iSubPos; iScanPosSig-- )
1422  {
1423  uiBlkPos = codingParameters.scan[ iScanPosSig ];
1424  uiSig = 0;
1425 
1426  if( uiSigCoeffGroupFlag[ iCGBlkPos ] )
1427  {
1428  if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero )
1429  {
1430  uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, codingParameters, iScanPosSig, uiLog2BlockWidth, uiLog2BlockHeight, chType );
1431  m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_map) );
1432  }
1433  else
1434  {
1435  uiSig = 1;
1436  }
1437  }
1438  pcCoef[ uiBlkPos ] = uiSig;
1439  if( uiSig )
1440  {
1441  pos[ numNonZero ] = uiBlkPos;
1442  numNonZero ++;
1443  if( lastNZPosInCG == -1 )
1444  {
1445  lastNZPosInCG = iScanPosSig;
1446  }
1447  firstNZPosInCG = iScanPosSig;
1448  }
1449  }
1450 
1451  if( numNonZero > 0 )
1452  {
1453  Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD );
1454 
1455  absSum = 0;
1456 
1457  const UInt uiCtxSet = getContextSetIndex(compID, iSubSet, (c1 == 0));
1458  c1 = 1;
1459  UInt uiBin;
1460 
1461  ContextModel *baseCtxMod = m_cCUOneSCModel.get( 0, 0 ) + (NUM_ONE_FLAG_CTX_PER_SET * uiCtxSet);
1462 
1463  Int absCoeff[1 << MLS_CG_SIZE];
1464 
1465  for ( Int i = 0; i < numNonZero; i++)
1466  {
1467  absCoeff[i] = 1;
1468  }
1469  Int numC1Flag = min(numNonZero, C1FLAG_NUMBER);
1470  Int firstC2FlagIdx = -1;
1471 
1472  for( Int idx = 0; idx < numC1Flag; idx++ )
1473  {
1474  m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_gt1) );
1475  if( uiBin == 1 )
1476  {
1477  c1 = 0;
1478  if (firstC2FlagIdx == -1)
1479  {
1480  firstC2FlagIdx = idx;
1481  }
1482  else //if a greater-than-one has been encountered already this group
1483  {
1484  escapeDataPresentInGroup = true;
1485  }
1486  }
1487  else if( (c1 < 3) && (c1 > 0) )
1488  {
1489  c1++;
1490  }
1491  absCoeff[ idx ] = uiBin + 1;
1492  }
1493 
1494  if (c1 == 0)
1495  {
1496  baseCtxMod = m_cCUAbsSCModel.get( 0, 0 ) + (NUM_ABS_FLAG_CTX_PER_SET * uiCtxSet);
1497  if ( firstC2FlagIdx != -1)
1498  {
1499  m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_gt2) );
1500  absCoeff[ firstC2FlagIdx ] = uiBin + 2;
1501  if (uiBin != 0)
1502  {
1503  escapeDataPresentInGroup = true;
1504  }
1505  }
1506  }
1507 
1508  escapeDataPresentInGroup = escapeDataPresentInGroup || (numNonZero > C1FLAG_NUMBER);
1509 
1510  const Bool alignGroup = escapeDataPresentInGroup && alignCABACBeforeBypass;
1511 
1512 #if RExt__DECODER_DEBUG_BIT_STATISTICS
1513  TComCodingStatisticsClassType ctype_signs((alignGroup ? STATS__CABAC_BITS__ALIGNED_SIGN_BIT : STATS__CABAC_BITS__SIGN_BIT ), uiLog2BlockWidth, compID);
1514  TComCodingStatisticsClassType ctype_escs ((alignGroup ? STATS__CABAC_BITS__ALIGNED_ESCAPE_BITS : STATS__CABAC_BITS__ESCAPE_BITS), uiLog2BlockWidth, compID);
1515 #endif
1516 
1517  if (alignGroup)
1518  {
1519  m_pcTDecBinIf->align();
1520  }
1521 
1522  UInt coeffSigns;
1523  if ( signHidden && beValid )
1524  {
1525  m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_signs) );
1526  coeffSigns <<= 32 - (numNonZero-1);
1527  }
1528  else
1529  {
1530  m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_signs) );
1531  coeffSigns <<= 32 - numNonZero;
1532  }
1533 
1534  Int iFirstCoeff2 = 1;
1535  if (escapeDataPresentInGroup)
1536  {
1537  for( Int idx = 0; idx < numNonZero; idx++ )
1538  {
1539  UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2) : 1;
1540 
1541  if( absCoeff[ idx ] == baseLevel)
1542  {
1543  UInt uiLevel;
1544  xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam, extendedPrecision, channelType RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_escs) );
1545 
1546  absCoeff[ idx ] = uiLevel + baseLevel;
1547 
1548  if (absCoeff[idx] > (3 << uiGoRiceParam))
1549  {
1550  uiGoRiceParam = bUseGolombRiceParameterAdaptation ? (uiGoRiceParam + 1) : (std::min<UInt>((uiGoRiceParam + 1), 4));
1551  }
1552 
1553  if (updateGolombRiceStatistics)
1554  {
1555  const UInt initialGolombRiceParameter = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR;
1556 
1557  if (uiLevel >= (3 << initialGolombRiceParameter))
1558  {
1559  currentGolombRiceStatistic++;
1560  }
1561  else if (((uiLevel * 2) < (1 << initialGolombRiceParameter)) && (currentGolombRiceStatistic > 0))
1562  {
1563  currentGolombRiceStatistic--;
1564  }
1565 
1566  updateGolombRiceStatistics = false;
1567  }
1568  }
1569 
1570  if(absCoeff[ idx ] >= 2)
1571  {
1572  iFirstCoeff2 = 0;
1573  }
1574  }
1575  }
1576 
1577  for( Int idx = 0; idx < numNonZero; idx++ )
1578  {
1579  Int blkPos = pos[ idx ];
1580  // Signs applied later.
1581  pcCoef[ blkPos ] = absCoeff[ idx ];
1582  absSum += absCoeff[ idx ];
1583 
1584  if ( idx == numNonZero-1 && signHidden && beValid )
1585  {
1586  // Infer sign of 1st element.
1587  if (absSum&0x1)
1588  {
1589  pcCoef[ blkPos ] = -pcCoef[ blkPos ];
1590  }
1591  }
1592  else
1593  {
1594  Int sign = static_cast<Int>( coeffSigns ) >> 31;
1595  pcCoef[ blkPos ] = ( pcCoef[ blkPos ] ^ sign ) - sign;
1596  coeffSigns <<= 1;
1597  }
1598  }
1599  }
1600  }
1601 
1602 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
1603  printSBACCoeffData(uiPosLastX, uiPosLastY, uiWidth, uiHeight, compID, uiAbsPartIdx, codingParameters.scanType, pcCoef);
1604 #endif
1605 
1606  return;
1607 }
1608 
1610 {
1611  if (maxSymbol == 0)
1612  {
1613  val = 0;
1614  return;
1615  }
1616 
1617  UInt code;
1618  Int i;
1620  if ( code == 0 )
1621  {
1622  val = 0;
1623  return;
1624  }
1625 
1626  i=1;
1627  while (1)
1628  {
1630  if ( code == 0 )
1631  {
1632  break;
1633  }
1634  i++;
1635  if (i == maxSymbol)
1636  {
1637  break;
1638  }
1639  }
1640 
1641  val = i;
1642 }
1643 
1645 {
1647 }
1648 
1650 {
1651  UInt uiCode;
1653  ruiVal = (Int)uiCode;
1654 }
1655 
1657 {
1658  UInt uiCode;
1660  if (uiCode == 0)
1661  {
1662  ruiVal = 0;
1663  }
1664  else
1665  {
1667  if (uiCode == 0)
1668  {
1669  ruiVal = 1;
1670  }
1671  else
1672  {
1673  ruiVal = 2;
1674  }
1675  }
1676 }
1677 
1679 {
1681 }
1682 
1684  , Bool* sliceEnabled
1685  , Bool leftMergeAvail
1686  , Bool aboveMergeAvail
1687  )
1688 {
1689  UInt uiSymbol;
1690 
1691  Bool isLeftMerge = false;
1692  Bool isAboveMerge= false;
1693 
1694  if(leftMergeAvail)
1695  {
1696  parseSaoMerge(uiSymbol); //sao_merge_left_flag
1697  isLeftMerge = (uiSymbol?true:false);
1698  }
1699 
1700  if( aboveMergeAvail && !isLeftMerge)
1701  {
1702  parseSaoMerge(uiSymbol); //sao_merge_up_flag
1703  isAboveMerge = (uiSymbol?true:false);
1704  }
1705 
1706  if(isLeftMerge || isAboveMerge) //merge mode
1707  {
1708  for (UInt componentIndex = 0; componentIndex < MAX_NUM_COMPONENT; componentIndex++)
1709  {
1710  saoBlkParam[componentIndex].modeIdc = (sliceEnabled[componentIndex]) ? SAO_MODE_MERGE : SAO_MODE_OFF;
1711  saoBlkParam[componentIndex].typeIdc = (isLeftMerge)?SAO_MERGE_LEFT:SAO_MERGE_ABOVE;
1712  }
1713  }
1714  else //new or off mode
1715  {
1716  for(Int compId=COMPONENT_Y; compId < MAX_NUM_COMPONENT; compId++)
1717  {
1718  const ComponentID compIdx=ComponentID(compId);
1719  const ComponentID firstCompOfChType = getFirstComponentOfChannel(toChannelType(compIdx));
1720  SAOOffset& ctbParam = saoBlkParam[compIdx];
1721 
1722  if(!sliceEnabled[compIdx])
1723  {
1724  //off
1725  ctbParam.modeIdc = SAO_MODE_OFF;
1726  continue;
1727  }
1728 
1729  //type
1730  if(compIdx == firstCompOfChType)
1731  {
1732  parseSaoTypeIdx(uiSymbol); //sao_type_idx_luma or sao_type_idx_chroma
1733 
1734  assert(uiSymbol ==0 || uiSymbol ==1 || uiSymbol ==2);
1735 
1736  if(uiSymbol ==0) //OFF
1737  {
1738  ctbParam.modeIdc = SAO_MODE_OFF;
1739  }
1740  else if(uiSymbol == 1) //BO
1741  {
1742  ctbParam.modeIdc = SAO_MODE_NEW;
1743  ctbParam.typeIdc = SAO_TYPE_START_BO;
1744  }
1745  else //2, EO
1746  {
1747  ctbParam.modeIdc = SAO_MODE_NEW;
1748  ctbParam.typeIdc = SAO_TYPE_START_EO;
1749  }
1750 
1751  }
1752  else //Cr, follow Cb SAO type
1753  {
1754  ctbParam.modeIdc = saoBlkParam[COMPONENT_Cb].modeIdc;
1755  ctbParam.typeIdc = saoBlkParam[COMPONENT_Cb].typeIdc;
1756  }
1757 
1758  if(ctbParam.modeIdc == SAO_MODE_NEW)
1759  {
1760 #if O0043_BEST_EFFORT_DECODING
1761  Int bitDepthOrig = g_bitDepthInStream[toChannelType(compIdx)];
1762  Int forceBitDepthAdjust = bitDepthOrig - g_bitDepth[toChannelType(compIdx)];
1763 #endif
1764  Int offset[4];
1765  for(Int i=0; i< 4; i++)
1766  {
1767 #if O0043_BEST_EFFORT_DECODING
1768  Int saoMaxOffsetQVal = (1<<(min(bitDepthOrig, MAX_SAO_TRUNCATED_BITDEPTH)-5))-1;
1769  parseSaoMaxUvlc(uiSymbol, saoMaxOffsetQVal); //sao_offset_abs
1770 #else
1771  parseSaoMaxUvlc(uiSymbol, g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
1772 #endif
1773  offset[i] = (Int)uiSymbol;
1774  }
1775 
1776  if(ctbParam.typeIdc == SAO_TYPE_START_BO)
1777  {
1778  for(Int i=0; i< 4; i++)
1779  {
1780  if(offset[i] != 0)
1781  {
1782  parseSaoSign(uiSymbol); //sao_offset_sign
1783  if(uiSymbol)
1784  {
1785 #if O0043_BEST_EFFORT_DECODING
1786  offset[i] >>= forceBitDepthAdjust;
1787 #endif
1788  offset[i] = -offset[i];
1789  }
1790  }
1791  }
1792  parseSaoUflc(NUM_SAO_BO_CLASSES_LOG2, uiSymbol ); //sao_band_position
1793  ctbParam.typeAuxInfo = uiSymbol;
1794 
1795  for(Int i=0; i<4; i++)
1796  {
1797  ctbParam.offset[(ctbParam.typeAuxInfo+i)%MAX_NUM_SAO_CLASSES] = offset[i];
1798  }
1799 
1800  }
1801  else //EO
1802  {
1803  ctbParam.typeAuxInfo = 0;
1804 
1805  if(firstCompOfChType == compIdx)
1806  {
1807  parseSaoUflc(NUM_SAO_EO_TYPES_LOG2, uiSymbol ); //sao_eo_class_luma or sao_eo_class_chroma
1808  ctbParam.typeIdc += uiSymbol;
1809  }
1810  else
1811  {
1812  ctbParam.typeIdc = saoBlkParam[firstCompOfChType].typeIdc;
1813  }
1814  ctbParam.offset[SAO_CLASS_EO_FULL_VALLEY] = offset[0];
1815  ctbParam.offset[SAO_CLASS_EO_HALF_VALLEY] = offset[1];
1816  ctbParam.offset[SAO_CLASS_EO_PLAIN ] = 0;
1817  ctbParam.offset[SAO_CLASS_EO_HALF_PEAK ] = -offset[2];
1818  ctbParam.offset[SAO_CLASS_EO_FULL_PEAK ] = -offset[3];
1819  }
1820  }
1821  }
1822  }
1823 }
1824 
1831 {
1834 }
1835 
1837 {
1839  xCopyContextsFrom( pSrc );
1840 }
1841 
1843 {
1844  xCopyFrom(pSrc);
1845 }
1846 
1848 {
1849  xCopyContextsFrom(pSrc);
1850 }
1851 
1857 {
1858  TComDataCU* cu = rTu.getCU();
1859  const UInt absPartIdx=rTu.GetAbsPartIdxTU(compID);
1860  const TComRectangle &rect = rTu.getRect(compID);
1861  const UInt tuHeight = g_aucConvertToBit[rect.height];
1862  const UInt tuWidth = g_aucConvertToBit[rect.width];
1863  UInt code = 0;
1864 
1865  assert(tuHeight == tuWidth);
1866 
1867 #if RExt__DECODER_DEBUG_BIT_STATISTICS
1869 #endif
1870 
1872 
1873  if(code == 0)
1874  {
1875  cu->setExplicitRdpcmModePartRange( RDPCM_OFF, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID));
1876  }
1877  else
1878  {
1880  if(code == 0)
1881  {
1882  cu->setExplicitRdpcmModePartRange( RDPCM_HOR, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID));
1883  }
1884  else
1885  {
1886  cu->setExplicitRdpcmModePartRange( RDPCM_VER, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID));
1887  }
1888  }
1889 }
1890 
1891 
#define NUM_SAO_EO_TYPES_LOG2
Definition: TypeDef.h:599
Bool getUseGolombRiceParameterAdaptation() const
Definition: TComSlice.h:901
#define NUM_SAO_BO_CLASSES_LOG2
Definition: TypeDef.h:611
Void loadContexts(const TDecSbac *pSrc)
Definition: TDecSbac.cpp:1847
UInt g_uiMaxCUDepth
Definition: TComRom.cpp:253
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:343
#define MAX_NUM_SAO_CLASSES
Definition: TypeDef.h:709
#define NUM_ADI_CTX
number of context models for intra prediction
Definition: ContextTables.h:60
SBAC decoder class (header)
Void parseIntraDirChroma(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
Definition: TDecSbac.cpp:694
ContextModel3DBuffer m_cCUMergeFlagExtSCModel
Definition: TDecSbac.h:151
Void parseMVPIdx(Int &riMVPIdx)
Definition: TDecSbac.cpp:502
virtual Void xReadPCMCode(UInt uiLength, UInt &ruiCode)=0
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
Bool getUseExtendedPrecision() const
Definition: TComSlice.h:887
SliceType getSliceType() const
Definition: TComSlice.h:1337
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]
ChannelType
Definition: TypeDef.h:361
Void parseQtRootCbf(UInt uiAbsPartIdx, UInt &uiQtRootCbf)
Definition: TDecSbac.cpp:911
static const UChar INIT_LAST[NUMBER_OF_SLICE_TYPES][2 *15]
Int typeAuxInfo
Definition: TypeDef.h:715
Void parseSaoSign(UInt &val)
Definition: TDecSbac.cpp:1678
ContextModel3DBuffer m_cCUChromaPredSCModel
Definition: TDecSbac.h:156
Void setMergeFlagSubParts(Bool bMergeFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
Void parseChromaQpAdjustment(TComDataCU *cu, UInt absPartIdx, UInt depth)
Definition: TDecSbac.cpp:969
void Void
Definition: TypeDef.h:285
virtual ~TDecSbac()
Definition: TDecSbac.cpp:102
UChar * getExplicitRdpcmMode(ComponentID component)
Definition: TComDataCU.h:283
static const UChar INIT_SIG_FLAG[NUMBER_OF_SLICE_TYPES][(28+16)]
UInt getCtxSplitFlag(UInt uiAbsPartIdx, UInt uiDepth)
#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)
UInt g_auiRasterToPelX[((1<<(6))/4)*((1<<(6))/4)]
Definition: TComRom.cpp:257
ContextModel3DBuffer m_cMVPIdxSCModel
Definition: TDecSbac.h:172
#define NUM_CHROMA_MODE
Definition: TypeDef.h:184
#define NULL
Definition: CommonDef.h:100
Int typeIdc
Definition: TypeDef.h:714
#define NUM_MERGE_FLAG_EXT_CTX
number of context models for merge flag of merge extended
Definition: ContextTables.h:54
#define NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX
Int offset[32]
Definition: TypeDef.h:716
Bool getCabacInitPresentFlag() const
Definition: TComSlice.h:1147
char Char
Definition: TypeDef.h:291
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
Char g_aucConvertToBit[(1<<(6))+1]
Definition: TComRom.cpp:558
unsigned int UInt
Definition: TypeDef.h:297
#define C1FLAG_NUMBER
Definition: TypeDef.h:119
UInt getNumPartitionsInCtu() const
Definition: TComPic.h:119
Bool getMvdL1ZeroFlag() const
Definition: TComSlice.h:1364
Void parseIntraDirLumaAng(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
Definition: TDecSbac.cpp:633
ContextModel3DBuffer m_cCUMergeIdxExtSCModel
Definition: TDecSbac.h:152
Bool isRDPCMEnabled(UInt uiAbsPartIdx)
Definition: TComDataCU.h:287
#define VER_IDX
Definition: TypeDef.h:181
Void parseInterDir(TComDataCU *pcCU, UInt &ruiInterDir, UInt uiAbsPartIdx)
Definition: TDecSbac.cpp:719
#define NUM_CTX_LAST_FLAG_XY
number of context models for last coefficient position
Short Pel
pixel type
Definition: TypeDef.h:692
static UInt getChromasCorrespondingPULumaIdx(const UInt lumaZOrderIdxInCtu, const ChromaFormat chFmt)
#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
symmetric motion partition, 2Nx N
Definition: TypeDef.h:396
Void parseSaoTypeIdx(UInt &ruiVal)
Definition: TDecSbac.cpp:1656
static const UChar INIT_CHROMA_QP_ADJ_FLAG[NUMBER_OF_SLICE_TYPES][1]
ContextModel3DBuffer m_cCUSigCoeffGroupSCModel
Definition: TDecSbac.h:165
UInt g_uiAddCUDepth
Definition: TComRom.cpp:254
#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:129
Void parseSkipFlag(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
Definition: TDecSbac.cpp:418
#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))]
UInt64 g_nSymbolCounter
Definition: TComRom.cpp:566
static const UChar INIT_INTER_DIR[NUMBER_OF_SLICE_TYPES][5]
UChar * getInterDir()
Definition: TComDataCU.h:346
static const UChar INIT_QT_ROOT_CBF[NUMBER_OF_SLICE_TYPES][1]
Int getNumRefIdx(RefPicList e) const
Definition: TComSlice.h:1353
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:122
const UInt g_uiGroupIdx[32]
Definition: TComRom.cpp:584
UInt getCtxQtCbf(TComTU &rTu, const ChannelType chType)
virtual Void align()=0
#define RExt__GOLOMB_RICE_INCREMENT_DIVISOR
Definition: TypeDef.h:248
#define NUM_MV_RES_CTX
number of context models for motion vector difference
Definition: ContextTables.h:64
Void setIntraDirSubParts(const ChannelType channelType, const UInt uiDir, const UInt uiAbsPartIdx, const UInt uiDepth)
UInt getMaxTrSize() const
Definition: TComSlice.h:879
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 setCrossComponentPredictionAlphaPartRange(Char alphaValue, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes)
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:509
UInt GetAbsPartIdxTU() const
Definition: TComTU.h:119
Void xReadUnarySymbol(UInt &ruiSymbol, ContextModel *pcSCModel, Int iOffset)
Definition: TDecSbac.cpp:271
#define AMVP_MAX_NUM_CANDS
max number of final candidates
Definition: CommonDef.h:183
const UInt * scanCG
Definition: TypeDef.h:753
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
Void setCbfPartRange(UInt uiCbf, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes)
ContextModel3DBuffer m_cCUQtRootCbfSCModel
Definition: TDecSbac.h:163
Void setPartSizeSubParts(PartSize eMode, UInt uiAbsPartIdx, UInt uiDepth)
ContextModel3DBuffer m_cCUDeltaQpSCModel
Definition: TDecSbac.h:157
PartSize
supported partition shape
Definition: TypeDef.h:393
Void setTransformSkipPartRange(UInt useTransformSkip, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes)
static const UChar INIT_TRANSFORMSKIP_FLAG[NUMBER_OF_SLICE_TYPES][2 *1]
const UChar g_chroma422IntraAngleMappingTable[36]
Definition: TComRom.cpp:540
static const UChar INIT_SKIP_FLAG[NUMBER_OF_SLICE_TYPES][3]
context model class
Definition: ContextModel.h:57
#define MAX_UINT
max. value of unsigned 32-bit integer
Definition: CommonDef.h:115
#define MAX_SAO_TRUNCATED_BITDEPTH
UChar * getIntraDir(const ChannelType channelType) const
Definition: TComDataCU.h:338
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:780
Void resetEntropy(TComSlice *pSlice)
Definition: TDecSbac.cpp:110
virtual Void decodeBin(UInt &ruiBin, ContextModel &rcCtxModel)=0
Int m_numContextModels
Definition: TDecSbac.h:148
#define DTRACE_CABAC_T(x)
Definition: TComRom.h:197
#define CU_DQP_EG_k
expgolomb order
Definition: TypeDef.h:113
#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:1096
UInt getMaxNumMergeCand() const
Definition: TComSlice.h:1451
ContextModel3DBuffer m_ChromaQpAdjFlagSCModel
Definition: TDecSbac.h:182
Void load(const TDecSbac *pSrc)
Definition: TDecSbac.cpp:1842
symmetric motion partition, 2Nx2N
Definition: TypeDef.h:395
Void parseSAOBlkParam(SAOBlkParam &saoBlkParam, Bool *sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail)
Definition: TDecSbac.cpp:1683
Void parseMergeFlag(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx)
Definition: TDecSbac.cpp:454
Int getQpBDOffset(ChannelType type) const
Definition: TComSlice.h:885
ContextModel3DBuffer m_cCUSigSCModel
Definition: TDecSbac.h:166
bool Bool
Definition: TypeDef.h:286
Bool getUseTransformSkip() const
Definition: TComSlice.h:1118
static const UChar INIT_PRED_MODE[NUMBER_OF_SLICE_TYPES][1]
Bool isIntra(UInt uiPartIdx) const
Definition: TComDataCU.h:443
Void setDepthSubParts(UInt uiDepth, UInt uiAbsPartIdx)
Int g_maxTrDynamicRange[MAX_NUM_CHANNEL_TYPE]
Definition: TComRom.cpp:325
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
Void setCUTransquantBypassSubParts(Bool flag, UInt uiAbsPartIdx, UInt uiDepth)
UInt g_uiMaxCUHeight
Definition: TComRom.cpp:252
UInt g_uiMaxCUWidth
Definition: TComRom.cpp:251
Void parseRefFrmIdx(TComDataCU *pcCU, Int &riRefFrmIdx, RefPicList eRefList)
Definition: TDecSbac.cpp:746
UInt getTransformSkipLog2MaxSize() const
Definition: TComSlice.h:1120
static const UChar INIT_EXPLICIT_RDPCM_FLAG[NUMBER_OF_SLICE_TYPES][2 *1]
Void parseMergeIndex(TComDataCU *pcCU, UInt &ruiMergeIndex)
Definition: TDecSbac.cpp:470
UInt getMinCUHeight() const
Definition: TComPic.h:123
asymmetric motion partition, 2Nx( N/2) + 2Nx(3N/2)
Definition: TypeDef.h:399
ContextModel3DBuffer m_cCUPredModeSCModel
Definition: TDecSbac.h:154
Void xReadCoefRemainExGolomb(UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const ChannelType channelType)
Definition: TDecSbac.cpp:303
Char getRefQP(UInt uiCurrAbsIdxInCtu)
static const UChar INIT_TRANS_SUBDIV_FLAG[NUMBER_OF_SLICE_TYPES][3]
asymmetric motion partition, (3N/2)x2N + ( N/2)x2N
Definition: TypeDef.h:402
UInt getCtxInterDir(UInt uiAbsPartIdx)
ContextModel3DBuffer m_cCuCtxLastX
Definition: TDecSbac.h:167
Void parsePartSize(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
Definition: TDecSbac.cpp:535
#define NUM_REF_NO_CTX
number of context models for reference index
Definition: ContextTables.h:68
#define COEF_REMAIN_BIN_REDUCTION
transitions from Golomb-Rice to TU+EG(k)
Definition: TypeDef.h:109
virtual Void start()=0
#define MIN_TU_SIZE
Definition: TComRom.h:56
UInt & getCtuRsAddr()
Definition: TComDataCU.h:207
Void getAllowedChromaDir(UInt uiAbsPartIdx, UInt *uiModeList)
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)
static const UChar INIT_DQP[NUMBER_OF_SLICE_TYPES][3]
UInt getCUPelY() const
Definition: TComDataCU.h:211
ContextModel3DBuffer m_cCUQtCbfSCModel
Definition: TDecSbac.h:161
static ChannelType toChannelType(const ComponentID id)
Void parseCUTransquantBypassFlag(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
Definition: TDecSbac.cpp:405
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:693
Void setCbfSubParts(const UInt uiCbf[MAX_NUM_COMPONENT], UInt uiAbsPartIdx, UInt uiDepth)
#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
UInt g_auiZscanToRaster[((1<<(6))/4)*((1<<(6))/4)]
Definition: TComRom.cpp:255
SAOMode modeIdc
Definition: TypeDef.h:713
Int getComponentScaleX(const ComponentID id) const
Definition: TComPic.h:126
RefPicList
reference list index
Definition: TypeDef.h:415
UInt getCtxSkipFlag(UInt uiAbsPartIdx)
UInt getCoefficientOffset(const ComponentID compID) const
Definition: TComTU.h:94
static const UChar INIT_SIG_CG_FLAG[NUMBER_OF_SLICE_TYPES][2 *2]
intra-prediction mode
Definition: TypeDef.h:410
unsigned char UChar
Definition: TypeDef.h:293
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
ContextModel3DBuffer m_cCUAbsSCModel
Definition: TDecSbac.h:170
UInt g_auiRasterToPelY[((1<<(6))/4)*((1<<(6))/4)]
Definition: TComRom.cpp:258
UChar * getDepth()
Definition: TComDataCU.h:213
Void setChromaQpAdjSubParts(UChar val, Int absPartIdx, Int depth)
const TComPPS * getPPS() const
Definition: TComSlice.h:1309
#define NUM_QT_CBF_CTX_PER_SET
number of context models for QT CBF
ContextModel3DBuffer m_cCUSplitFlagSCModel
Definition: TDecSbac.h:149
Void parseExplicitRdpcmMode(TComTU &rTu, ComponentID compID)
Definition: TDecSbac.cpp:1856
Int getChromaQpAdjTableSize() const
Definition: TComSlice.h:1081
UInt getCUPelX() const
Definition: TComDataCU.h:210
#define DTRACE_CABAC_V(x)
Definition: TComRom.h:195
static const UChar INIT_MERGE_IDX_EXT[NUMBER_OF_SLICE_TYPES][1]
#define MLS_GRP_NUM
G644 : Max number of coefficient groups, max(16, 64)
Definition: TypeDef.h:143
virtual Void copyState(const TDecBinIf *pcTDecBinIf)=0
static const UChar INIT_MVD[NUMBER_OF_SLICE_TYPES][2]
UChar * getTransformSkip(ComponentID compID)
Definition: TComDataCU.h:278
Void parseSaoUflc(UInt uiLength, UInt &ruiVal)
Definition: TDecSbac.cpp:1644
#define SBH_THRESHOLD
I0156: value of the fixed SBH controlling threshold.
Definition: TypeDef.h:115
Bool isIntra() const
Definition: TComSlice.h:1404
TComDataCU * getCU()
Definition: TComTU.h:126
ContextModel m_contextModels[512]
Definition: TDecSbac.h:147
reference list 1
Definition: TypeDef.h:418
UChar * getHeight()
Definition: TComDataCU.h:249
Bool getAlignCABACBeforeBypass() const
Definition: TComSlice.h:904
Void setSizeSubParts(UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, UInt uiDepth)
#define NUM_CTX_LAST_FLAG_SETS
Void xCopyContextsFrom(const TDecSbac *pSrc)
Definition: TDecSbac.cpp:1830
#define DM_CHROMA_IDX
Definition: TypeDef.h:185
#define HOR_IDX
Definition: TypeDef.h:182
COEFF_SCAN_TYPE scanType
Definition: TypeDef.h:754
Void parseDeltaQP(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
Definition: TDecSbac.cpp:929
Bool * getCUTransquantBypass()
Definition: TComDataCU.h:242
#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:401
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:994
Void xCopyFrom(const TDecSbac *pSrc)
Definition: TDecSbac.cpp:1836
TComPic * getPic()
Definition: TComDataCU.h:203
Int g_bitDepth[MAX_NUM_CHANNEL_TYPE]
Definition: TComRom.cpp:548
Void xReadUnaryMaxSymbol(UInt &ruiSymbol, ContextModel *pcSCModel, Int iOffset, UInt uiMaxSymbol)
Definition: TDecSbac.cpp:210
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
Char * getPartitionSize()
Definition: TComDataCU.h:223
Void getIntraDirPredictor(UInt uiAbsPartIdx, Int uiIntraDirPred[NUM_MOST_PROBABLE_MODES], const ComponentID compID, Int *piMode=0)
Void parseSaoMerge(UInt &ruiVal)
Definition: TDecSbac.cpp:1649
static const UChar INIT_REF_PIC[NUMBER_OF_SLICE_TYPES][2]
#define NUM_TRANSFORMSKIP_FLAG_CTX
number of context models for transform skipping
#define DTRACE_CABAC_VL(x)
Definition: TComRom.h:196
Void parseCrossComponentPrediction(class TComTU &rTu, ComponentID compID)
Definition: TDecSbac.cpp:844
Void setIPCMFlagSubParts(Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth)
Void setQPSubParts(Int qp, UInt uiAbsPartIdx, UInt uiDepth)
Void readByte(UInt &ruiBits)
ContextModel3DBuffer m_cCrossComponentPredictionSCModel
Definition: TDecSbac.h:180
Char * getPredictionMode()
Definition: TComDataCU.h:234
Bool getUseAMP() const
Definition: TComSlice.h:858
ContextModel3DBuffer m_CUTransquantBypassFlagSCModel
Definition: TDecSbac.h:177
ContextModel3DBuffer m_cCUMvdSCModel
Definition: TDecSbac.h:160
TComInputBitstream * m_pcBitstream
Definition: TDecSbac.h:107
static Int calcPatternSigCtx(const UInt *sigCoeffGroupFlag, UInt uiCGPosX, UInt uiCGPosY, UInt widthInGroups, UInt heightInGroups)
Void setCodedChromaQpAdj(Char qp)
Definition: TComDataCU.h:269
static UInt getSignificanceMapContextOffset(const ComponentID component)
Void setTrIdxSubParts(UInt uiTrIdx, UInt uiAbsPartIdx, UInt uiDepth)
TComCUMvField * getCUMvField(RefPicList e)
Definition: TComDataCU.h:294
UChar * getWidth()
Definition: TComDataCU.h:245
TCoeff * getCoeff(ComponentID component)
Definition: TComDataCU.h:296
Void parseRemainingBytes(Bool noTrailingBytesExpected)
Definition: TDecSbac.cpp:186
static const UChar INIT_CU_TRANSQUANT_BYPASS_FLAG[NUMBER_OF_SLICE_TYPES][1]
Void bitwiseOrCbfPartRange(UInt uiCbf, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes)
Void parseTransformSubdivFlag(UInt &ruiSubdivFlag, UInt uiLog2TransformBlockSize)
Definition: TDecSbac.cpp:897
Bool getCabacInitFlag()
get CABAC initial flag
Definition: TComSlice.h:1515
#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:296
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)
UInt getPCMBitDepth(ChannelType type) const
Definition: TComSlice.h:915
Int getComponentScaleY(const ComponentID id) const
Definition: TComPic.h:127
ComponentID
Definition: TypeDef.h:368
PredMode
supported prediction type
Definition: TypeDef.h:407
static const UChar INIT_MVP_IDX[NUMBER_OF_SLICE_TYPES][1]
Int getSliceQp() const
Definition: TComSlice.h:1339
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:207
Bool getSignHideFlag() const
Definition: TComSlice.h:1144
#define MLS_CG_SIZE
G644 : Coefficient group size of 4x4.
Definition: TypeDef.h:146
virtual Void decodeBinEP(UInt &ruiBin)=0
Void setSkipFlagSubParts(Bool skip, UInt absPartIdx, UInt depth)
Bool getUseCrossComponentPrediction() const
Definition: TComSlice.h:1107
asymmetric motion partition, 2Nx(3N/2) + 2Nx( N/2)
Definition: TypeDef.h:400
#define NUM_QT_CBF_CTX_SETS
const UInt g_uiMinInGroup[10]
Definition: TComRom.cpp:583
symmetric motion partition, Nx N
Definition: TypeDef.h:398
inter-prediction mode
Definition: TypeDef.h:409
Pel * getPCMSample(ComponentID component)
Definition: TComDataCU.h:301
#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
Void parseCoeffNxN(class TComTU &rTu, ComponentID compID)
Definition: TDecSbac.cpp:1220
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:525
slice header class
Definition: TComSlice.h:1198
#define CU_DQP_TU_CMAX
max number bins for truncated unary
Definition: TypeDef.h:112
UInt g_saoMaxOffsetQVal[MAX_NUM_COMPONENT]
UInt m_golombRiceAdaptationStatistics[4]
Definition: TDecSbac.h:185
#define RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS
Definition: TypeDef.h:247
Void setCodedQP(Char qp)
Definition: TComDataCU.h:262
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 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:397
Void parseLastSignificantXY(UInt &uiPosLastX, UInt &uiPosLastY, Int width, Int height, ComponentID component, UInt uiScanIdx)
Definition: TDecSbac.cpp:1143
Void initBuffer(SliceType eSliceType, Int iQp, UChar *ctxModel)
initialize 3D buffer by slice type & QP
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
TComSlice * getSlice()
Definition: TComDataCU.h:205
const TComSPS * getSPS() const
Definition: TComSlice.h:1306
Void setPredModeSubParts(PredMode eMode, UInt uiAbsPartIdx, UInt uiDepth)
Void parseSaoMaxUvlc(UInt &val, UInt maxSymbol)
Definition: TDecSbac.cpp:1609
Void parsePredMode(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
Definition: TDecSbac.cpp:617
virtual Void decodeBinsEP(UInt &ruiBins, Int numBins)=0
UInt GetTransformDepthTotalAdj(const ComponentID compID) const
Definition: TComTU.h:106
Void setExplicitRdpcmModePartRange(UInt rdpcmMode, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes)