HEVC Test Model (HM)  HM-16.18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TEncSbac.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 "TEncTop.h"
39 #include "TEncSbac.h"
40 #include "TLibCommon/TComTU.h"
41 
42 #include <map>
43 #include <algorithm>
44 
45 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
46 #include "../TLibCommon/Debug.h"
47 #endif
48 
49 
52 
53 // ====================================================================================================================
54 // Constructor / destructor / create / destroy
55 // ====================================================================================================================
56 
58 // new structure here
59 : m_pcBitIf ( NULL )
60 , m_pcBinIf ( NULL )
61 , m_numContextModels ( 0 )
62 , m_cCUSplitFlagSCModel ( 1, 1, NUM_SPLIT_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels)
63 , m_cCUSkipFlagSCModel ( 1, 1, NUM_SKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels)
64 , m_cCUMergeFlagExtSCModel ( 1, 1, NUM_MERGE_FLAG_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels)
65 , m_cCUMergeIdxExtSCModel ( 1, 1, NUM_MERGE_IDX_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels)
66 , m_cCUPartSizeSCModel ( 1, 1, NUM_PART_SIZE_CTX , m_contextModels + m_numContextModels, m_numContextModels)
67 , m_cCUPredModeSCModel ( 1, 1, NUM_PRED_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels)
68 , m_cCUIntraPredSCModel ( 1, 1, NUM_INTRA_PREDICT_CTX , m_contextModels + m_numContextModels, m_numContextModels)
69 , m_cCUChromaPredSCModel ( 1, 1, NUM_CHROMA_PRED_CTX , m_contextModels + m_numContextModels, m_numContextModels)
70 , m_cCUDeltaQpSCModel ( 1, 1, NUM_DELTA_QP_CTX , m_contextModels + m_numContextModels, m_numContextModels)
71 , m_cCUInterDirSCModel ( 1, 1, NUM_INTER_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels)
72 , m_cCURefPicSCModel ( 1, 1, NUM_REF_NO_CTX , m_contextModels + m_numContextModels, m_numContextModels)
73 , m_cCUMvdSCModel ( 1, 1, NUM_MV_RES_CTX , m_contextModels + m_numContextModels, m_numContextModels)
74 , m_cCUQtCbfSCModel ( 1, NUM_QT_CBF_CTX_SETS, NUM_QT_CBF_CTX_PER_SET , m_contextModels + m_numContextModels, m_numContextModels)
75 , m_cCUTransSubdivFlagSCModel ( 1, 1, NUM_TRANS_SUBDIV_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels)
76 , m_cCUQtRootCbfSCModel ( 1, 1, NUM_QT_ROOT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels)
77 , m_cCUSigCoeffGroupSCModel ( 1, 2, NUM_SIG_CG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels)
78 , m_cCUSigSCModel ( 1, 1, NUM_SIG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels)
79 , m_cCuCtxLastX ( 1, NUM_CTX_LAST_FLAG_SETS, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels)
80 , m_cCuCtxLastY ( 1, NUM_CTX_LAST_FLAG_SETS, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels)
81 , m_cCUOneSCModel ( 1, 1, NUM_ONE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels)
82 , m_cCUAbsSCModel ( 1, 1, NUM_ABS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels)
83 , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels)
84 , m_cSaoMergeSCModel ( 1, 1, NUM_SAO_MERGE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels)
85 , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels)
86 , m_cTransformSkipSCModel ( 1, MAX_NUM_CHANNEL_TYPE, NUM_TRANSFORMSKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels)
87 , m_CUTransquantBypassFlagSCModel ( 1, 1, NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels)
88 , m_explicitRdpcmFlagSCModel ( 1, MAX_NUM_CHANNEL_TYPE, NUM_EXPLICIT_RDPCM_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels)
89 , m_explicitRdpcmDirSCModel ( 1, MAX_NUM_CHANNEL_TYPE, NUM_EXPLICIT_RDPCM_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels)
90 , m_cCrossComponentPredictionSCModel ( 1, 1, NUM_CROSS_COMPONENT_PREDICTION_CTX , m_contextModels + m_numContextModels, m_numContextModels)
91 , m_ChromaQpAdjFlagSCModel ( 1, 1, NUM_CHROMA_QP_ADJ_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels)
92 , m_ChromaQpAdjIdcSCModel ( 1, 1, NUM_CHROMA_QP_ADJ_IDC_CTX , m_contextModels + m_numContextModels, m_numContextModels)
93 {
95 }
96 
98 {
99 }
100 
101 // ====================================================================================================================
102 // Public member functions
103 // ====================================================================================================================
104 
106 {
107  Int iQp = pSlice->getSliceQp();
108  SliceType eSliceType = pSlice->getSliceType();
109 
110  SliceType encCABACTableIdx = pSlice->getEncCABACTableIdx();
111  if (!pSlice->isIntra() && (encCABACTableIdx==B_SLICE || encCABACTableIdx==P_SLICE) && pSlice->getPPS()->getCabacInitPresentFlag())
112  {
113  eSliceType = encCABACTableIdx;
114  }
115 
116  m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG );
117  m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG );
120  m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE );
121  m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE );
124  m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR );
125  m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD );
126  m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC );
127  m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP );
128  m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF );
131  m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG );
132  m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST );
133  m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST );
134  m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG );
135  m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG );
136  m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX );
147 
148  for (UInt statisticIndex = 0; statisticIndex < RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS ; statisticIndex++)
149  {
150  m_golombRiceAdaptationStatistics[statisticIndex] = 0;
151  }
152 
153  m_pcBinIf->start();
154 
155  return;
156 }
157 
163 {
164  Int qp = pSlice->getSliceQp();
165 
166  if (!pSlice->isIntra())
167  {
168  SliceType aSliceTypeChoices[] = {B_SLICE, P_SLICE};
169 
170  UInt bestCost = MAX_UINT;
171  SliceType bestSliceType = aSliceTypeChoices[0];
172  for (UInt idx=0; idx<2; idx++)
173  {
174  UInt curCost = 0;
175  SliceType curSliceType = aSliceTypeChoices[idx];
176 
177  curCost = m_cCUSplitFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SPLIT_FLAG );
178  curCost += m_cCUSkipFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SKIP_FLAG );
179  curCost += m_cCUMergeFlagExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT);
180  curCost += m_cCUMergeIdxExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_IDX_EXT);
181  curCost += m_cCUPartSizeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PART_SIZE );
182  curCost += m_cCUPredModeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PRED_MODE );
183  curCost += m_cCUIntraPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTRA_PRED_MODE );
184  curCost += m_cCUChromaPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE );
185  curCost += m_cCUInterDirSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTER_DIR );
186  curCost += m_cCUMvdSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVD );
187  curCost += m_cCURefPicSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_REF_PIC );
188  curCost += m_cCUDeltaQpSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DQP );
189  curCost += m_cCUQtCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_CBF );
190  curCost += m_cCUQtRootCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_ROOT_CBF );
191  curCost += m_cCUSigCoeffGroupSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_CG_FLAG );
192  curCost += m_cCUSigSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_FLAG );
193  curCost += m_cCuCtxLastX.calcCost ( curSliceType, qp, (UChar*)INIT_LAST );
194  curCost += m_cCuCtxLastY.calcCost ( curSliceType, qp, (UChar*)INIT_LAST );
195  curCost += m_cCUOneSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ONE_FLAG );
196  curCost += m_cCUAbsSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ABS_FLAG );
197  curCost += m_cMVPIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVP_IDX );
198  curCost += m_cCUTransSubdivFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
199  curCost += m_cSaoMergeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG );
200  curCost += m_cSaoTypeIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
201  curCost += m_cTransformSkipSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
203  curCost += m_explicitRdpcmFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_EXPLICIT_RDPCM_FLAG);
204  curCost += m_explicitRdpcmDirSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_EXPLICIT_RDPCM_DIR);
206  curCost += m_ChromaQpAdjFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_FLAG );
207  curCost += m_ChromaQpAdjIdcSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_IDC );
208 
209  if (curCost < bestCost)
210  {
211  bestSliceType = curSliceType;
212  bestCost = curCost;
213  }
214  }
215  return bestSliceType;
216  }
217  else
218  {
219  return I_SLICE;
220  }
221 }
222 
223 Void TEncSbac::codeVPS( const TComVPS* /*pcVPS*/ )
224 {
225  assert (0);
226  return;
227 }
228 
229 Void TEncSbac::codeSPS( const TComSPS* /*pcSPS*/ )
230 {
231  assert (0);
232  return;
233 }
234 
235 Void TEncSbac::codePPS( const TComPPS* /*pcPPS*/ )
236 {
237  assert (0);
238  return;
239 }
240 
242 {
243  assert (0);
244  return;
245 }
246 
248 {
249  assert (0);
250  return;
251 }
252 
254 {
255  m_pcBinIf->encodeBinTrm( uilsLast );
256 }
257 
259 {
260  m_pcBinIf->finish();
261 }
262 
263 Void TEncSbac::xWriteUnarySymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset )
264 {
265  m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[0] );
266 
267  if( 0 == uiSymbol)
268  {
269  return;
270  }
271 
272  while( uiSymbol-- )
273  {
274  m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ iOffset ] );
275  }
276 
277  return;
278 }
279 
280 Void TEncSbac::xWriteUnaryMaxSymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol )
281 {
282  if (uiMaxSymbol == 0)
283  {
284  return;
285  }
286 
287  m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ 0 ] );
288 
289  if ( uiSymbol == 0 )
290  {
291  return;
292  }
293 
294  Bool bCodeLast = ( uiMaxSymbol > uiSymbol );
295 
296  while( --uiSymbol )
297  {
298  m_pcBinIf->encodeBin( 1, pcSCModel[ iOffset ] );
299  }
300  if( bCodeLast )
301  {
302  m_pcBinIf->encodeBin( 0, pcSCModel[ iOffset ] );
303  }
304 
305  return;
306 }
307 
309 {
310  UInt bins = 0;
311  Int numBins = 0;
312 
313  while( uiSymbol >= (UInt)(1<<uiCount) )
314  {
315  bins = 2 * bins + 1;
316  numBins++;
317  uiSymbol -= 1 << uiCount;
318  uiCount ++;
319  }
320  bins = 2 * bins + 0;
321  numBins++;
322 
323  bins = (bins << uiCount) | uiSymbol;
324  numBins += uiCount;
325 
326  assert( numBins <= 32 );
327  m_pcBinIf->encodeBinsEP( bins, numBins );
328 }
329 
330 
337 Void TEncSbac::xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam, const Bool useLimitedPrefixLength, const Int maxLog2TrDynamicRange )
338 {
339  Int codeNumber = (Int)symbol;
340  UInt length;
341 
342  if (codeNumber < (COEF_REMAIN_BIN_REDUCTION << rParam))
343  {
344  length = codeNumber>>rParam;
345  m_pcBinIf->encodeBinsEP( (1<<(length+1))-2 , length+1);
346  m_pcBinIf->encodeBinsEP((codeNumber%(1<<rParam)),rParam);
347  }
348  else if (useLimitedPrefixLength)
349  {
350  const UInt maximumPrefixLength = (32 - (COEF_REMAIN_BIN_REDUCTION + maxLog2TrDynamicRange));
351 
352  UInt prefixLength = 0;
353  UInt suffixLength = MAX_UINT;
354  UInt codeValue = (symbol >> rParam) - COEF_REMAIN_BIN_REDUCTION;
355 
356  if (codeValue >= ((1 << maximumPrefixLength) - 1))
357  {
358  prefixLength = maximumPrefixLength;
359  suffixLength = maxLog2TrDynamicRange - rParam;
360  }
361  else
362  {
363  while (codeValue > ((2 << prefixLength) - 2))
364  {
365  prefixLength++;
366  }
367 
368  suffixLength = prefixLength + 1; //+1 for the separator bit
369  }
370 
371  const UInt suffix = codeValue - ((1 << prefixLength) - 1);
372 
373  const UInt totalPrefixLength = prefixLength + COEF_REMAIN_BIN_REDUCTION;
374  const UInt prefix = (1 << totalPrefixLength) - 1;
375  const UInt rParamBitMask = (1 << rParam) - 1;
376 
377  m_pcBinIf->encodeBinsEP( prefix, totalPrefixLength ); //prefix
378  m_pcBinIf->encodeBinsEP(((suffix << rParam) | (symbol & rParamBitMask)), (suffixLength + rParam)); //separator, suffix, and rParam bits
379  }
380  else
381  {
382  length = rParam;
383  codeNumber = codeNumber - ( COEF_REMAIN_BIN_REDUCTION << rParam);
384 
385  while (codeNumber >= (1<<length))
386  {
387  codeNumber -= (1<<(length++));
388  }
389 
390  m_pcBinIf->encodeBinsEP((1<<(COEF_REMAIN_BIN_REDUCTION+length+1-rParam))-2,COEF_REMAIN_BIN_REDUCTION+length+1-rParam);
391  m_pcBinIf->encodeBinsEP(codeNumber,length);
392  }
393 }
394 
395 // SBAC RD
397 {
398  this->xCopyFrom(pSrc);
399 }
400 
402 {
403  m_pcBinIf->copyState( pSrc->m_pcBinIf );
404  if (isLuma(chType))
405  {
407  }
408  else
409  {
411  }
412 }
413 
414 
416 {
417  pDest->xCopyFrom( this );
418 }
419 
420 
422 {
423  m_pcBinIf->copyState( pSrc->m_pcBinIf );
424  xCopyContextsFrom(pSrc);
425 }
426 
427 Void TEncSbac::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
428 {
429  Int iSymbol = pcCU->getMVPIdx(eRefList, uiAbsPartIdx);
430  Int iNum = AMVP_MAX_NUM_CANDS;
431 
432  xWriteUnaryMaxSymbol(iSymbol, m_cMVPIdxSCModel.get(0), 1, iNum-1);
433 }
434 
435 Void TEncSbac::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
436 {
437  PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx );
438  const UInt log2DiffMaxMinCodingBlockSize = pcCU->getSlice()->getSPS()->getLog2DiffMaxMinCodingBlockSize();
439 
440  if ( pcCU->isIntra( uiAbsPartIdx ) )
441  {
442  if( uiDepth == log2DiffMaxMinCodingBlockSize )
443  {
444  m_pcBinIf->encodeBin( eSize == SIZE_2Nx2N? 1 : 0, m_cCUPartSizeSCModel.get( 0, 0, 0 ) );
445  }
446  return;
447  }
448 
449  switch(eSize)
450  {
451  case SIZE_2Nx2N:
452  {
453  m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) );
454  break;
455  }
456  case SIZE_2NxN:
457  case SIZE_2NxnU:
458  case SIZE_2NxnD:
459  {
460  m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) );
461  m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) );
462  if ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize )
463  {
464  if (eSize == SIZE_2NxN)
465  {
467  }
468  else
469  {
471  m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1));
472  }
473  }
474  break;
475  }
476  case SIZE_Nx2N:
477  case SIZE_nLx2N:
478  case SIZE_nRx2N:
479  {
480  m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) );
481  m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) );
482 
483  if( uiDepth == log2DiffMaxMinCodingBlockSize && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) )
484  {
485  m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 2) );
486  }
487 
488  if ( pcCU->getSlice()->getSPS()->getUseAMP() && uiDepth < log2DiffMaxMinCodingBlockSize )
489  {
490  if (eSize == SIZE_Nx2N)
491  {
493  }
494  else
495  {
497  m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1));
498  }
499  }
500  break;
501  }
502  case SIZE_NxN:
503  {
504  if( uiDepth == log2DiffMaxMinCodingBlockSize && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) )
505  {
506  m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) );
507  m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) );
508  m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 2) );
509  }
510  break;
511  }
512  default:
513  {
514  assert(0);
515  break;
516  }
517  }
518 }
519 
520 
527 {
528  // get context function is here
529  m_pcBinIf->encodeBin( pcCU->isIntra( uiAbsPartIdx ) ? 1 : 0, m_cCUPredModeSCModel.get( 0, 0, 0 ) );
530 }
531 
533 {
534  UInt uiSymbol = pcCU->getCUTransquantBypass(uiAbsPartIdx);
535  m_pcBinIf->encodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) );
536 }
537 
544 {
545  // get context function is here
546  UInt uiSymbol = pcCU->isSkipped( uiAbsPartIdx ) ? 1 : 0;
547  UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ) ;
548  m_pcBinIf->encodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) );
549  DTRACE_CABAC_VL( g_nSymbolCounter++ );
550  DTRACE_CABAC_T( "\tSkipFlag" );
551  DTRACE_CABAC_T( "\tuiCtxSkip: ");
552  DTRACE_CABAC_V( uiCtxSkip );
553  DTRACE_CABAC_T( "\tuiSymbol: ");
554  DTRACE_CABAC_V( uiSymbol );
555  DTRACE_CABAC_T( "\n");
556 }
557 
564 {
565  const UInt uiSymbol = pcCU->getMergeFlag( uiAbsPartIdx ) ? 1 : 0;
566  m_pcBinIf->encodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) );
567 
568  DTRACE_CABAC_VL( g_nSymbolCounter++ );
569  DTRACE_CABAC_T( "\tMergeFlag: " );
570  DTRACE_CABAC_V( uiSymbol );
571  DTRACE_CABAC_T( "\tAddress: " );
572  DTRACE_CABAC_V( pcCU->getCtuRsAddr() );
573  DTRACE_CABAC_T( "\tuiAbsPartIdx: " );
574  DTRACE_CABAC_V( uiAbsPartIdx );
575  DTRACE_CABAC_T( "\n" );
576 }
577 
584 {
585  UInt uiUnaryIdx = pcCU->getMergeIndex( uiAbsPartIdx );
586  UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand();
587  if ( uiNumCand > 1 )
588  {
589  for( UInt ui = 0; ui < uiNumCand - 1; ++ui )
590  {
591  const UInt uiSymbol = ui == uiUnaryIdx ? 0 : 1;
592  if ( ui==0 )
593  {
594  m_pcBinIf->encodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) );
595  }
596  else
597  {
598  m_pcBinIf->encodeBinEP( uiSymbol );
599  }
600  if( uiSymbol == 0 )
601  {
602  break;
603  }
604  }
605  }
606  DTRACE_CABAC_VL( g_nSymbolCounter++ );
607  DTRACE_CABAC_T( "\tparseMergeIndex()" );
608  DTRACE_CABAC_T( "\tuiMRGIdx= " );
609  DTRACE_CABAC_V( pcCU->getMergeIndex( uiAbsPartIdx ) );
610  DTRACE_CABAC_T( "\n" );
611 }
612 
613 Void TEncSbac::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
614 {
615  if( uiDepth == pcCU->getSlice()->getSPS()->getLog2DiffMaxMinCodingBlockSize() )
616  {
617  return;
618  }
619 
620  UInt uiCtx = pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth );
621  UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0;
622 
623  assert( uiCtx < 3 );
624  m_pcBinIf->encodeBin( uiCurrSplitFlag, m_cCUSplitFlagSCModel.get( 0, 0, uiCtx ) );
625  DTRACE_CABAC_VL( g_nSymbolCounter++ )
626  DTRACE_CABAC_T( "\tSplitFlag\n" )
627  return;
628 }
629 
631 {
632  m_pcBinIf->encodeBin( uiSymbol, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiCtx ) );
633  DTRACE_CABAC_VL( g_nSymbolCounter++ )
634  DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" )
635  DTRACE_CABAC_T( "\tsymbol=" )
636  DTRACE_CABAC_V( uiSymbol )
637  DTRACE_CABAC_T( "\tctx=" )
638  DTRACE_CABAC_V( uiCtx )
639  DTRACE_CABAC_T( "\n" )
640 }
641 
642 
643 Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiple)
644 {
645  UInt dir[4],j;
646  Int preds[4][NUM_MOST_PROBABLE_MODES] = {{-1, -1, -1},{-1, -1, -1},{-1, -1, -1},{-1, -1, -1}};
647  Int predIdx[4] ={ -1,-1,-1,-1};
648  PartSize mode = pcCU->getPartitionSize( absPartIdx );
649  UInt partNum = isMultiple?(mode==SIZE_NxN?4:1):1;
650  UInt partOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2;
651  for (j=0;j<partNum;j++)
652  {
653  dir[j] = pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx+partOffset*j );
654  pcCU->getIntraDirPredictor(absPartIdx+partOffset*j, preds[j], COMPONENT_Y);
655  for(UInt i = 0; i < NUM_MOST_PROBABLE_MODES; i++)
656  {
657  if(dir[j] == preds[j][i])
658  {
659  predIdx[j] = i;
660  }
661  }
662  m_pcBinIf->encodeBin((predIdx[j] != -1)? 1 : 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) );
663  }
664  for (j=0;j<partNum;j++)
665  {
666  if(predIdx[j] != -1)
667  {
668  m_pcBinIf->encodeBinEP( predIdx[j] ? 1 : 0 );
669  if (predIdx[j])
670  {
671  m_pcBinIf->encodeBinEP( predIdx[j]-1 );
672  }
673  }
674  else
675  {
676  if (preds[j][0] > preds[j][1])
677  {
678  std::swap(preds[j][0], preds[j][1]);
679  }
680  if (preds[j][0] > preds[j][2])
681  {
682  std::swap(preds[j][0], preds[j][2]);
683  }
684  if (preds[j][1] > preds[j][2])
685  {
686  std::swap(preds[j][1], preds[j][2]);
687  }
688  for(Int i = (Int(NUM_MOST_PROBABLE_MODES) - 1); i >= 0; i--)
689  {
690  dir[j] = dir[j] > preds[j][i] ? dir[j] - 1 : dir[j];
691  }
692  m_pcBinIf->encodeBinsEP( dir[j], 5 );
693  }
694  }
695  return;
696 }
697 
699 {
700  UInt uiIntraDirChroma = pcCU->getIntraDir( CHANNEL_TYPE_CHROMA, uiAbsPartIdx );
701 
702  if( uiIntraDirChroma == DM_CHROMA_IDX )
703  {
704  m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, 0 ) );
705  }
706  else
707  {
708  m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) );
709 
710  UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ];
711  pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir );
712 
713  for( Int i = 0; i < NUM_CHROMA_MODE - 1; i++ )
714  {
715  if( uiIntraDirChroma == uiAllowedChromaDir[i] )
716  {
717  uiIntraDirChroma = i;
718  break;
719  }
720  }
721 
722  m_pcBinIf->encodeBinsEP( uiIntraDirChroma, 2 );
723  }
724 
725  return;
726 }
727 
728 
730 {
731  const UInt uiInterDir = pcCU->getInterDir( uiAbsPartIdx ) - 1;
732  const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx );
734 
735  if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 )
736  {
737  m_pcBinIf->encodeBin( uiInterDir == 2 ? 1 : 0, *( pCtx + uiCtx ) );
738  }
739 
740  if (uiInterDir < 2)
741  {
742  m_pcBinIf->encodeBin( uiInterDir, *( pCtx + 4 ) );
743  }
744 
745  return;
746 }
747 
748 Void TEncSbac::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
749 {
750  Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx );
751  ContextModel *pCtx = m_cCURefPicSCModel.get( 0 );
752  m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), *pCtx );
753 
754  if( iRefFrame > 0 )
755  {
756  UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2;
757  pCtx++;
758  iRefFrame--;
759  for( UInt ui = 0; ui < uiRefNum; ++ui )
760  {
761  const UInt uiSymbol = ui == iRefFrame ? 0 : 1;
762  if( ui == 0 )
763  {
764  m_pcBinIf->encodeBin( uiSymbol, *pCtx );
765  }
766  else
767  {
768  m_pcBinIf->encodeBinEP( uiSymbol );
769  }
770  if( uiSymbol == 0 )
771  {
772  break;
773  }
774  }
775  }
776  return;
777 }
778 
779 Void TEncSbac::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
780 {
781  if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3)
782  {
783  return;
784  }
785 
786  const TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefList );
787  const Int iHor = pcCUMvField->getMvd( uiAbsPartIdx ).getHor();
788  const Int iVer = pcCUMvField->getMvd( uiAbsPartIdx ).getVer();
789  ContextModel* pCtx = m_cCUMvdSCModel.get( 0 );
790 
791  m_pcBinIf->encodeBin( iHor != 0 ? 1 : 0, *pCtx );
792  m_pcBinIf->encodeBin( iVer != 0 ? 1 : 0, *pCtx );
793 
794  const Bool bHorAbsGr0 = iHor != 0;
795  const Bool bVerAbsGr0 = iVer != 0;
796  const UInt uiHorAbs = 0 > iHor ? -iHor : iHor;
797  const UInt uiVerAbs = 0 > iVer ? -iVer : iVer;
798  pCtx++;
799 
800  if( bHorAbsGr0 )
801  {
802  m_pcBinIf->encodeBin( uiHorAbs > 1 ? 1 : 0, *pCtx );
803  }
804 
805  if( bVerAbsGr0 )
806  {
807  m_pcBinIf->encodeBin( uiVerAbs > 1 ? 1 : 0, *pCtx );
808  }
809 
810  if( bHorAbsGr0 )
811  {
812  if( uiHorAbs > 1 )
813  {
814  xWriteEpExGolomb( uiHorAbs-2, 1 );
815  }
816 
817  m_pcBinIf->encodeBinEP( 0 > iHor ? 1 : 0 );
818  }
819 
820  if( bVerAbsGr0 )
821  {
822  if( uiVerAbs > 1 )
823  {
824  xWriteEpExGolomb( uiVerAbs-2, 1 );
825  }
826 
827  m_pcBinIf->encodeBinEP( 0 > iVer ? 1 : 0 );
828  }
829 
830  return;
831 }
832 
834 {
835  TComDataCU *pcCU = rTu.getCU();
836 
838  {
839  return;
840  }
841 
842  const UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU();
843 
844  if (!pcCU->isIntra(uiAbsPartIdx) || (pcCU->getIntraDir( CHANNEL_TYPE_CHROMA, uiAbsPartIdx ) == DM_CHROMA_IDX))
845  {
846  DTRACE_CABAC_VL( g_nSymbolCounter++ )
847  DTRACE_CABAC_T("\tparseCrossComponentPrediction()")
848  DTRACE_CABAC_T( "\tAddr=" )
849  DTRACE_CABAC_V( compID )
850  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
851  DTRACE_CABAC_V( uiAbsPartIdx )
852 
853  Int alpha = pcCU->getCrossComponentPredictionAlpha( uiAbsPartIdx, compID );
855  m_pcBinIf->encodeBin(((alpha != 0) ? 1 : 0), pCtx[0]);
856 
857  if (alpha != 0)
858  {
859  static const Int log2AbsAlphaMinus1Table[8] = { 0, 1, 1, 2, 2, 2, 3, 3 };
860  assert(abs(alpha) <= 8);
861 
862  if (abs(alpha)>1)
863  {
864  m_pcBinIf->encodeBin(1, pCtx[1]);
865  xWriteUnaryMaxSymbol( log2AbsAlphaMinus1Table[abs(alpha) - 1] - 1, (pCtx + 2), 1, 2 );
866  }
867  else
868  {
869  m_pcBinIf->encodeBin(0, pCtx[1]);
870  }
871  m_pcBinIf->encodeBin( ((alpha < 0) ? 1 : 0), pCtx[4] );
872  }
873  DTRACE_CABAC_T( "\tAlpha=" )
874  DTRACE_CABAC_V( pcCU->getCrossComponentPredictionAlpha( uiAbsPartIdx, compID ) )
875  DTRACE_CABAC_T( "\n" )
876  }
877 }
878 
880 {
881  Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx );
882 
883  Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA);
884  iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2);
885 
886  UInt uiAbsDQp = (UInt)((iDQp > 0)? iDQp : (-iDQp));
887  UInt TUValue = min((Int)uiAbsDQp, CU_DQP_TU_CMAX);
888  xWriteUnaryMaxSymbol( TUValue, &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX);
889  if( uiAbsDQp >= CU_DQP_TU_CMAX )
890  {
892  }
893 
894  if ( uiAbsDQp > 0)
895  {
896  UInt uiSign = (iDQp > 0 ? 0 : 1);
897  m_pcBinIf->encodeBinEP(uiSign);
898  }
899 
900  return;
901 }
902 
907 {
908  Int internalIdc = cu->getChromaQpAdj( absPartIdx );
909  Int chromaQpOffsetListLen = cu->getSlice()->getPPS()->getPpsRangeExtension().getChromaQpOffsetListLen();
910  /* internal_idc == 0 => flag = 0
911  * internal_idc > 1 => code idc value (if table size warrents) */
912  m_pcBinIf->encodeBin( internalIdc > 0, m_ChromaQpAdjFlagSCModel.get( 0, 0, 0 ) );
913 
914  if (internalIdc > 0 && chromaQpOffsetListLen > 1)
915  {
916  xWriteUnaryMaxSymbol( internalIdc - 1, &m_ChromaQpAdjIdcSCModel.get( 0, 0, 0 ), 0, chromaQpOffsetListLen - 1 );
917  }
918 }
919 
920 Void TEncSbac::codeQtCbf( TComTU &rTu, const ComponentID compID, const Bool lowestLevel )
921 {
922  TComDataCU* pcCU = rTu.getCU();
923 
924  const UInt absPartIdx = rTu.GetAbsPartIdxTU(compID);
925  const UInt TUDepth = rTu.GetTransformDepthRel();
926  UInt uiCtx = pcCU->getCtxQtCbf( rTu, toChannelType(compID) );
927  const UInt contextSet = toChannelType(compID);
928 
929  const UInt width = rTu.getRect(compID).width;
930  const UInt height = rTu.getRect(compID).height;
931  const Bool canQuadSplit = (width >= (MIN_TU_SIZE * 2)) && (height >= (MIN_TU_SIZE * 2));
932 
933  // Since the CBF for chroma is coded at the highest level possible, if sub-TUs are
934  // to be coded for a 4x8 chroma TU, their CBFs must be coded at the highest 4x8 level
935  // (i.e. where luma TUs are 8x8 rather than 4x4)
936  // ___ ___
937  // | | | <- 4 x (8x8 luma + 4x8 4:2:2 chroma)
938  // |___|___| each quadrant has its own chroma CBF
939  // | | | _ _ _ _
940  // |___|___| |
941  // <--16---> V
942  // _ _
943  // |_|_| <- 4 x 4x4 luma + 1 x 4x8 4:2:2 chroma
944  // |_|_| no chroma CBF is coded - instead the parent CBF is inherited
945  // <-8-> if sub-TUs are present, their CBFs had to be coded at the parent level
946 
947  const UInt lowestTUDepth = TUDepth + ((!lowestLevel && !canQuadSplit) ? 1 : 0); //unsplittable TUs inherit their parent's CBF
948 
949  if ((width != height) && (lowestLevel || !canQuadSplit)) //if sub-TUs are present
950  {
951  const UInt subTUDepth = lowestTUDepth + 1; //if this is the lowest level of the TU-tree, the sub-TUs are directly below. Otherwise, this must be the level above the lowest level (as specified above)
952  const UInt partIdxesPerSubTU = rTu.GetAbsPartIdxNumParts(compID) >> 1;
953 
954  for (UInt subTU = 0; subTU < 2; subTU++)
955  {
956  const UInt subTUAbsPartIdx = absPartIdx + (subTU * partIdxesPerSubTU);
957  const UInt uiCbf = pcCU->getCbf(subTUAbsPartIdx, compID, subTUDepth);
958 
959  m_pcBinIf->encodeBin(uiCbf, m_cCUQtCbfSCModel.get(0, contextSet, uiCtx));
960 
961  DTRACE_CABAC_VL( g_nSymbolCounter++ )
962  DTRACE_CABAC_T( "\tparseQtCbf()" )
963  DTRACE_CABAC_T( "\tsub-TU=" )
964  DTRACE_CABAC_V( subTU )
965  DTRACE_CABAC_T( "\tsymbol=" )
966  DTRACE_CABAC_V( uiCbf )
967  DTRACE_CABAC_T( "\tctx=" )
968  DTRACE_CABAC_V( uiCtx )
969  DTRACE_CABAC_T( "\tetype=" )
970  DTRACE_CABAC_V( compID )
971  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
972  DTRACE_CABAC_V( subTUAbsPartIdx )
973  DTRACE_CABAC_T( "\n" )
974  }
975  }
976  else
977  {
978  const UInt uiCbf = pcCU->getCbf( absPartIdx, compID, lowestTUDepth );
979  m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, contextSet, uiCtx ) );
980 
981 
982  DTRACE_CABAC_VL( g_nSymbolCounter++ )
983  DTRACE_CABAC_T( "\tparseQtCbf()" )
984  DTRACE_CABAC_T( "\tsymbol=" )
985  DTRACE_CABAC_V( uiCbf )
986  DTRACE_CABAC_T( "\tctx=" )
987  DTRACE_CABAC_V( uiCtx )
988  DTRACE_CABAC_T( "\tetype=" )
989  DTRACE_CABAC_V( compID )
990  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
991  DTRACE_CABAC_V( rTu.GetAbsPartIdxTU(compID) )
992  DTRACE_CABAC_T( "\n" )
993  }
994 }
995 
996 
998 {
999  TComDataCU* pcCU=rTu.getCU();
1000  const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU();
1001 
1002  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
1003  {
1004  return;
1005  }
1006 
1008  {
1009  return;
1010  }
1011 
1012  UInt useTransformSkip = pcCU->getTransformSkip( uiAbsPartIdx,component);
1013  m_pcBinIf->encodeBin( useTransformSkip, m_cTransformSkipSCModel.get( 0, toChannelType(component), 0 ) );
1014 
1015  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1016  DTRACE_CABAC_T("\tparseTransformSkip()");
1017  DTRACE_CABAC_T( "\tsymbol=" )
1018  DTRACE_CABAC_V( useTransformSkip )
1019  DTRACE_CABAC_T( "\tAddr=" )
1020  DTRACE_CABAC_V( pcCU->getCtuRsAddr() )
1021  DTRACE_CABAC_T( "\tetype=" )
1022  DTRACE_CABAC_V( component )
1023  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1025  DTRACE_CABAC_T( "\n" )
1026 }
1027 
1028 
1035 {
1036  UInt uiIPCM = (pcCU->getIPCMFlag(uiAbsPartIdx) == true)? 1 : 0;
1037 
1038  Bool writePCMSampleFlag = pcCU->getIPCMFlag(uiAbsPartIdx);
1039 
1040  m_pcBinIf->encodeBinTrm (uiIPCM);
1041 
1042  if (writePCMSampleFlag)
1043  {
1045 
1046  const UInt minCoeffSizeY = pcCU->getPic()->getMinCUWidth() * pcCU->getPic()->getMinCUHeight();
1047  const UInt offsetY = minCoeffSizeY * uiAbsPartIdx;
1048  for (UInt ch=0; ch < pcCU->getPic()->getNumberValidComponents(); ch++)
1049  {
1050  const ComponentID compID = ComponentID(ch);
1051  const UInt offset = offsetY >> (pcCU->getPic()->getComponentScaleX(compID) + pcCU->getPic()->getComponentScaleY(compID));
1052  Pel * pPCMSample = pcCU->getPCMSample(compID) + offset;
1053  const UInt width = pcCU->getWidth (uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleX(compID);
1054  const UInt height = pcCU->getHeight(uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleY(compID);
1055  const UInt sampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepth(toChannelType(compID));
1056  for (UInt y=0; y<height; y++)
1057  {
1058  for (UInt x=0; x<width; x++)
1059  {
1060  UInt sample = pPCMSample[x];
1061  m_pcBinIf->xWritePCMCode(sample, sampleBits);
1062  }
1063  pPCMSample += width;
1064  }
1065  }
1066 
1067  m_pcBinIf->resetBac();
1068  }
1069 }
1070 
1072 {
1073  UInt uiCbf = pcCU->getQtRootCbf( uiAbsPartIdx );
1074  UInt uiCtx = 0;
1075  m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) );
1076  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1077  DTRACE_CABAC_T( "\tparseQtRootCbf()" )
1078  DTRACE_CABAC_T( "\tsymbol=" )
1079  DTRACE_CABAC_V( uiCbf )
1080  DTRACE_CABAC_T( "\tctx=" )
1081  DTRACE_CABAC_V( uiCtx )
1082  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
1083  DTRACE_CABAC_V( uiAbsPartIdx )
1084  DTRACE_CABAC_T( "\n" )
1085 }
1086 
1088 {
1089  // this function is only used to estimate the bits when cbf is 0
1090  // and will never be called when writing the bistream. do not need to write log
1091  UInt uiCbf = 0;
1092  UInt uiCtx = rTu.getCU()->getCtxQtCbf( rTu, chType );
1093 
1094  m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, chType, uiCtx ) );
1095 }
1096 
1098 {
1099  // this function is only used to estimate the bits when cbf is 0
1100  // and will never be called when writing the bistream. do not need to write log
1101  UInt uiCbf = 0;
1102  UInt uiCtx = 0;
1103  m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) );
1104 }
1105 
1115 Void TEncSbac::codeLastSignificantXY( UInt uiPosX, UInt uiPosY, Int width, Int height, ComponentID component, UInt uiScanIdx )
1116 {
1117  // swap
1118  if( uiScanIdx == SCAN_VER )
1119  {
1120  swap( uiPosX, uiPosY );
1121  swap( width, height );
1122  }
1123 
1124  UInt uiCtxLast;
1125  UInt uiGroupIdxX = g_uiGroupIdx[ uiPosX ];
1126  UInt uiGroupIdxY = g_uiGroupIdx[ uiPosY ];
1127 
1128  ContextModel *pCtxX = m_cCuCtxLastX.get( 0, toChannelType(component) );
1129  ContextModel *pCtxY = m_cCuCtxLastY.get( 0, toChannelType(component) );
1130 
1131  Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY;
1132  getLastSignificantContextParameters(component, width, height, blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY);
1133 
1134  //------------------
1135 
1136  // posX
1137 
1138  for( uiCtxLast = 0; uiCtxLast < uiGroupIdxX; uiCtxLast++ )
1139  {
1140  m_pcBinIf->encodeBin( 1, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) );
1141  }
1142  if( uiGroupIdxX < g_uiGroupIdx[ width - 1 ])
1143  {
1144  m_pcBinIf->encodeBin( 0, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) );
1145  }
1146 
1147  // posY
1148 
1149  for( uiCtxLast = 0; uiCtxLast < uiGroupIdxY; uiCtxLast++ )
1150  {
1151  m_pcBinIf->encodeBin( 1, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) );
1152  }
1153  if( uiGroupIdxY < g_uiGroupIdx[ height - 1 ])
1154  {
1155  m_pcBinIf->encodeBin( 0, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) );
1156  }
1157 
1158  // EP-coded part
1159 
1160  if ( uiGroupIdxX > 3 )
1161  {
1162  UInt uiCount = ( uiGroupIdxX - 2 ) >> 1;
1163  uiPosX = uiPosX - g_uiMinInGroup[ uiGroupIdxX ];
1164  for (Int i = uiCount - 1 ; i >= 0; i-- )
1165  {
1166  m_pcBinIf->encodeBinEP( ( uiPosX >> i ) & 1 );
1167  }
1168  }
1169  if ( uiGroupIdxY > 3 )
1170  {
1171  UInt uiCount = ( uiGroupIdxY - 2 ) >> 1;
1172  uiPosY = uiPosY - g_uiMinInGroup[ uiGroupIdxY ];
1173  for ( Int i = uiCount - 1 ; i >= 0; i-- )
1174  {
1175  m_pcBinIf->encodeBinEP( ( uiPosY >> i ) & 1 );
1176  }
1177  }
1178 }
1179 
1180 
1181 Void TEncSbac::codeCoeffNxN( TComTU &rTu, TCoeff* pcCoef, const ComponentID compID )
1182 {
1183  TComDataCU* pcCU=rTu.getCU();
1184  const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(compID);
1185  const TComRectangle &tuRect=rTu.getRect(compID);
1186  const UInt uiWidth=tuRect.width;
1187  const UInt uiHeight=tuRect.height;
1188  const TComSPS &sps=*(pcCU->getSlice()->getSPS());
1189 
1190  DTRACE_CABAC_VL( g_nSymbolCounter++ )
1191  DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" )
1192  DTRACE_CABAC_V( compID )
1193  DTRACE_CABAC_T( "\twidth=" )
1194  DTRACE_CABAC_V( uiWidth )
1195  DTRACE_CABAC_T( "\theight=" )
1196  DTRACE_CABAC_V( uiHeight )
1197  DTRACE_CABAC_T( "\tdepth=" )
1198 // DTRACE_CABAC_V( rTu.GetTransformDepthTotalAdj(compID) )
1200  DTRACE_CABAC_T( "\tabspartidx=" )
1201  DTRACE_CABAC_V( uiAbsPartIdx )
1202  DTRACE_CABAC_T( "\ttoCU-X=" )
1203  DTRACE_CABAC_V( pcCU->getCUPelX() )
1204  DTRACE_CABAC_T( "\ttoCU-Y=" )
1205  DTRACE_CABAC_V( pcCU->getCUPelY() )
1206  DTRACE_CABAC_T( "\tCU-addr=" )
1207  DTRACE_CABAC_V( pcCU->getCtuRsAddr() )
1208  DTRACE_CABAC_T( "\tinCU-X=" )
1209 // DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1211  DTRACE_CABAC_T( "\tinCU-Y=" )
1212 // DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] )
1214  DTRACE_CABAC_T( "\tpredmode=" )
1215  DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) )
1216  DTRACE_CABAC_T( "\n" )
1217 
1218  //--------------------------------------------------------------------------------------------------
1219 
1220  if( uiWidth > sps.getMaxTrSize() )
1221  {
1222  std::cerr << "ERROR: codeCoeffNxN was passed a TU with dimensions larger than the maximum allowed size" << std::endl;
1223  assert(false);
1224  exit(1);
1225  }
1226 
1227  // compute number of significant coefficients
1228  UInt uiNumSig = TEncEntropy::countNonZeroCoeffs(pcCoef, uiWidth * uiHeight);
1229 
1230  if ( uiNumSig == 0 )
1231  {
1232  std::cerr << "ERROR: codeCoeffNxN called for empty TU!" << std::endl;
1233  assert(false);
1234  exit(1);
1235  }
1236 
1237  //--------------------------------------------------------------------------------------------------
1238 
1239  //set parameters
1240 
1241  const ChannelType chType = toChannelType(compID);
1242  const UInt uiLog2BlockWidth = g_aucConvertToBit[ uiWidth ] + 2;
1243  const UInt uiLog2BlockHeight = g_aucConvertToBit[ uiHeight ] + 2;
1244 
1245  const ChannelType channelType = toChannelType(compID);
1246  const Bool extendedPrecision = sps.getSpsRangeExtension().getExtendedPrecisionProcessingFlag();
1247 
1248  const Bool alignCABACBeforeBypass = sps.getSpsRangeExtension().getCabacBypassAlignmentEnabledFlag();
1249  const Int maxLog2TrDynamicRange = sps.getMaxLog2TrDynamicRange(channelType);
1250 
1251  Bool beValid;
1252 
1253  {
1254  Int uiIntraMode = -1;
1255  const Bool bIsLuma = isLuma(compID);
1256  Int isIntra = pcCU->isIntra(uiAbsPartIdx) ? 1 : 0;
1257  if ( isIntra )
1258  {
1259  uiIntraMode = pcCU->getIntraDir( toChannelType(compID), uiAbsPartIdx );
1260 
1261  const UInt partsPerMinCU = 1<<(2*(sps.getMaxTotalCUDepth() - sps.getLog2DiffMaxMinCodingBlockSize()));
1262  uiIntraMode = (uiIntraMode==DM_CHROMA_IDX && !bIsLuma) ? pcCU->getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, rTu.GetChromaFormat(), partsPerMinCU)) : uiIntraMode;
1263  uiIntraMode = ((rTu.GetChromaFormat() == CHROMA_422) && !bIsLuma) ? g_chroma422IntraAngleMappingTable[uiIntraMode] : uiIntraMode;
1264  }
1265 
1266  Int transformSkip = pcCU->getTransformSkip( uiAbsPartIdx,compID) ? 1 : 0;
1267  Bool rdpcm_lossy = ( transformSkip && isIntra && ( (uiIntraMode == HOR_IDX) || (uiIntraMode == VER_IDX) ) ) && pcCU->isRDPCMEnabled(uiAbsPartIdx);
1268 
1269  if ( (pcCU->getCUTransquantBypass(uiAbsPartIdx)) || rdpcm_lossy )
1270  {
1271  beValid = false;
1272  if ( (!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx))
1273  {
1274  codeExplicitRdpcmMode( rTu, compID);
1275  }
1276  }
1277  else
1278  {
1279  beValid = pcCU->getSlice()->getPPS()->getSignDataHidingEnabledFlag();
1280  }
1281  }
1282 
1283  //--------------------------------------------------------------------------------------------------
1284 
1285  if(pcCU->getSlice()->getPPS()->getUseTransformSkip())
1286  {
1287  codeTransformSkipFlags(rTu, compID);
1288  if(pcCU->getTransformSkip(uiAbsPartIdx, compID) && !pcCU->isIntra(uiAbsPartIdx) && pcCU->isRDPCMEnabled(uiAbsPartIdx))
1289  {
1290  // This TU has coefficients and is transform skipped. Check whether is inter coded and if yes encode the explicit RDPCM mode
1291  codeExplicitRdpcmMode( rTu, compID);
1292 
1293  if(pcCU->getExplicitRdpcmMode(compID, uiAbsPartIdx) != RDPCM_OFF)
1294  {
1295  // Sign data hiding is avoided for horizontal and vertical explicit RDPCM modes
1296  beValid = false;
1297  }
1298  }
1299  }
1300 
1301  //--------------------------------------------------------------------------------------------------
1302 
1303  const Bool bUseGolombRiceParameterAdaptation = sps.getSpsRangeExtension().getPersistentRiceAdaptationEnabledFlag();
1304  UInt &currentGolombRiceStatistic = m_golombRiceAdaptationStatistics[rTu.getGolombRiceStatisticsIndex(compID)];
1305 
1306  //select scans
1307  TUEntropyCodingParameters codingParameters;
1308  getTUEntropyCodingParameters(codingParameters, rTu, compID);
1309 
1310  //----- encode significance map -----
1311 
1312  // Find position of last coefficient
1313  Int scanPosLast = -1;
1314  Int posLast;
1315 
1316 
1317  UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ];
1318 
1319  memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM );
1320  do
1321  {
1322  posLast = codingParameters.scan[ ++scanPosLast ];
1323 
1324  if( pcCoef[ posLast ] != 0 )
1325  {
1326  // get L1 sig map
1327  UInt uiPosY = posLast >> uiLog2BlockWidth;
1328  UInt uiPosX = posLast - ( uiPosY << uiLog2BlockWidth );
1329 
1330  UInt uiBlkIdx = (codingParameters.widthInGroups * (uiPosY >> MLS_CG_LOG2_HEIGHT)) + (uiPosX >> MLS_CG_LOG2_WIDTH);
1331  uiSigCoeffGroupFlag[ uiBlkIdx ] = 1;
1332 
1333  uiNumSig--;
1334  }
1335  } while ( uiNumSig > 0 );
1336 
1337  // Code position of last coefficient
1338  Int posLastY = posLast >> uiLog2BlockWidth;
1339  Int posLastX = posLast - ( posLastY << uiLog2BlockWidth );
1340  codeLastSignificantXY(posLastX, posLastY, uiWidth, uiHeight, compID, codingParameters.scanType);
1341 
1342  //===== code significance flag =====
1343  ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, chType );
1344  ContextModel * const baseCtx = m_cCUSigSCModel.get( 0, 0 ) + getSignificanceMapContextOffset(compID);
1345 
1346  const Int iLastScanSet = scanPosLast >> MLS_CG_SIZE;
1347 
1348  UInt c1 = 1;
1349  UInt uiGoRiceParam = 0;
1350  Int iScanPosSig = scanPosLast;
1351 
1352  for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- )
1353  {
1354  Int numNonZero = 0;
1355  Int iSubPos = iSubSet << MLS_CG_SIZE;
1356  uiGoRiceParam = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR;
1357  Bool updateGolombRiceStatistics = bUseGolombRiceParameterAdaptation; //leave the statistics at 0 when not using the adaptation system
1358  UInt coeffSigns = 0;
1359 
1360  Int absCoeff[1 << MLS_CG_SIZE];
1361 
1362  Int lastNZPosInCG = -1;
1363  Int firstNZPosInCG = 1 << MLS_CG_SIZE;
1364 
1365  Bool escapeDataPresentInGroup = false;
1366 
1367  if( iScanPosSig == scanPosLast )
1368  {
1369  absCoeff[ 0 ] = Int(abs( pcCoef[ posLast ] ));
1370  coeffSigns = ( pcCoef[ posLast ] < 0 );
1371  numNonZero = 1;
1372  lastNZPosInCG = iScanPosSig;
1373  firstNZPosInCG = iScanPosSig;
1374  iScanPosSig--;
1375  }
1376 
1377  // encode significant_coeffgroup_flag
1378  Int iCGBlkPos = codingParameters.scanCG[ iSubSet ];
1379  Int iCGPosY = iCGBlkPos / codingParameters.widthInGroups;
1380  Int iCGPosX = iCGBlkPos - (iCGPosY * codingParameters.widthInGroups);
1381 
1382  if( iSubSet == iLastScanSet || iSubSet == 0)
1383  {
1384  uiSigCoeffGroupFlag[ iCGBlkPos ] = 1;
1385  }
1386  else
1387  {
1388  UInt uiSigCoeffGroup = (uiSigCoeffGroupFlag[ iCGBlkPos ] != 0);
1389  UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups );
1390  m_pcBinIf->encodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] );
1391  }
1392 
1393  // encode significant_coeff_flag
1394  if( uiSigCoeffGroupFlag[ iCGBlkPos ] )
1395  {
1396  const Int patternSigCtx = TComTrQuant::calcPatternSigCtx(uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups);
1397 
1398  UInt uiBlkPos, uiSig, uiCtxSig;
1399  for( ; iScanPosSig >= iSubPos; iScanPosSig-- )
1400  {
1401  uiBlkPos = codingParameters.scan[ iScanPosSig ];
1402  uiSig = (pcCoef[ uiBlkPos ] != 0);
1403  if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero )
1404  {
1405  uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, codingParameters, iScanPosSig, uiLog2BlockWidth, uiLog2BlockHeight, chType );
1406  m_pcBinIf->encodeBin( uiSig, baseCtx[ uiCtxSig ] );
1407  }
1408  if( uiSig )
1409  {
1410  absCoeff[ numNonZero ] = Int(abs( pcCoef[ uiBlkPos ] ));
1411  coeffSigns = 2 * coeffSigns + ( pcCoef[ uiBlkPos ] < 0 );
1412  numNonZero++;
1413  if( lastNZPosInCG == -1 )
1414  {
1415  lastNZPosInCG = iScanPosSig;
1416  }
1417  firstNZPosInCG = iScanPosSig;
1418  }
1419  }
1420  }
1421  else
1422  {
1423  iScanPosSig = iSubPos - 1;
1424  }
1425 
1426  if( numNonZero > 0 )
1427  {
1428  Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD );
1429 
1430  const UInt uiCtxSet = getContextSetIndex(compID, iSubSet, (c1 == 0));
1431  c1 = 1;
1432 
1433  ContextModel *baseCtxMod = m_cCUOneSCModel.get( 0, 0 ) + (NUM_ONE_FLAG_CTX_PER_SET * uiCtxSet);
1434 
1435  Int numC1Flag = min(numNonZero, C1FLAG_NUMBER);
1436  Int firstC2FlagIdx = -1;
1437  for( Int idx = 0; idx < numC1Flag; idx++ )
1438  {
1439  UInt uiSymbol = absCoeff[ idx ] > 1;
1440  m_pcBinIf->encodeBin( uiSymbol, baseCtxMod[c1] );
1441  if( uiSymbol )
1442  {
1443  c1 = 0;
1444 
1445  if (firstC2FlagIdx == -1)
1446  {
1447  firstC2FlagIdx = idx;
1448  }
1449  else //if a greater-than-one has been encountered already this group
1450  {
1451  escapeDataPresentInGroup = true;
1452  }
1453  }
1454  else if( (c1 < 3) && (c1 > 0) )
1455  {
1456  c1++;
1457  }
1458  }
1459 
1460  if (c1 == 0)
1461  {
1462  baseCtxMod = m_cCUAbsSCModel.get( 0, 0 ) + (NUM_ABS_FLAG_CTX_PER_SET * uiCtxSet);
1463  if ( firstC2FlagIdx != -1)
1464  {
1465  UInt symbol = absCoeff[ firstC2FlagIdx ] > 2;
1466  m_pcBinIf->encodeBin( symbol, baseCtxMod[0] );
1467  if (symbol != 0)
1468  {
1469  escapeDataPresentInGroup = true;
1470  }
1471  }
1472  }
1473 
1474  escapeDataPresentInGroup = escapeDataPresentInGroup || (numNonZero > C1FLAG_NUMBER);
1475 
1476  if (escapeDataPresentInGroup && alignCABACBeforeBypass)
1477  {
1478  m_pcBinIf->align();
1479  }
1480 
1481  if( beValid && signHidden )
1482  {
1483  m_pcBinIf->encodeBinsEP( (coeffSigns >> 1), numNonZero-1 );
1484  }
1485  else
1486  {
1487  m_pcBinIf->encodeBinsEP( coeffSigns, numNonZero );
1488  }
1489 
1490  Int iFirstCoeff2 = 1;
1491  if (escapeDataPresentInGroup)
1492  {
1493  for ( Int idx = 0; idx < numNonZero; idx++ )
1494  {
1495  UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2 ) : 1;
1496 
1497  if( absCoeff[ idx ] >= baseLevel)
1498  {
1499  const UInt escapeCodeValue = absCoeff[idx] - baseLevel;
1500 
1501  xWriteCoefRemainExGolomb( escapeCodeValue, uiGoRiceParam, extendedPrecision, maxLog2TrDynamicRange );
1502 
1503  if (absCoeff[idx] > (3 << uiGoRiceParam))
1504  {
1505  uiGoRiceParam = bUseGolombRiceParameterAdaptation ? (uiGoRiceParam + 1) : (std::min<UInt>((uiGoRiceParam + 1), 4));
1506  }
1507 
1508  if (updateGolombRiceStatistics)
1509  {
1510  const UInt initialGolombRiceParameter = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR;
1511 
1512  if (escapeCodeValue >= (3 << initialGolombRiceParameter))
1513  {
1514  currentGolombRiceStatistic++;
1515  }
1516  else if (((escapeCodeValue * 2) < (1 << initialGolombRiceParameter)) && (currentGolombRiceStatistic > 0))
1517  {
1518  currentGolombRiceStatistic--;
1519  }
1520 
1521  updateGolombRiceStatistics = false;
1522  }
1523  }
1524 
1525  if(absCoeff[ idx ] >= 2)
1526  {
1527  iFirstCoeff2 = 0;
1528  }
1529  }
1530  }
1531  }
1532  }
1533 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
1534  printSBACCoeffData(posLastX, posLastY, uiWidth, uiHeight, compID, uiAbsPartIdx, codingParameters.scanType, pcCoef, pcCU->getSlice()->getFinalized());
1535 #endif
1536 
1537  return;
1538 }
1539 
1544 {
1545  m_pcBinIf->encodeBinEP( code );
1546 }
1547 
1549 {
1550  if (maxSymbol == 0)
1551  {
1552  return;
1553  }
1554 
1555  Int i;
1556  Bool bCodeLast = ( maxSymbol > code );
1557 
1558  if ( code == 0 )
1559  {
1560  m_pcBinIf->encodeBinEP( 0 );
1561  }
1562  else
1563  {
1564  m_pcBinIf->encodeBinEP( 1 );
1565  for ( i=0; i<code-1; i++ )
1566  {
1567  m_pcBinIf->encodeBinEP( 1 );
1568  }
1569  if( bCodeLast )
1570  {
1571  m_pcBinIf->encodeBinEP( 0 );
1572  }
1573  }
1574 }
1575 
1578 Void TEncSbac::codeSaoUflc ( UInt uiLength, UInt uiCode )
1579 {
1580  m_pcBinIf->encodeBinsEP ( uiCode, uiLength );
1581 }
1582 
1586 {
1587  m_pcBinIf->encodeBin(((uiCode == 0) ? 0 : 1), m_cSaoMergeSCModel.get( 0, 0, 0 ));
1588 }
1589 
1593 {
1594  if (uiCode == 0)
1595  {
1596  m_pcBinIf->encodeBin( 0, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
1597  }
1598  else
1599  {
1600  m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
1601  m_pcBinIf->encodeBinEP( uiCode == 1 ? 0 : 1 );
1602  }
1603 }
1604 
1605 Void TEncSbac::codeSAOOffsetParam(ComponentID compIdx, SAOOffset& ctbParam, Bool sliceEnabled, const Int channelBitDepth)
1606 {
1607  UInt uiSymbol;
1608  if(!sliceEnabled)
1609  {
1610  assert(ctbParam.modeIdc == SAO_MODE_OFF);
1611  return;
1612  }
1613  const Bool bIsFirstCompOfChType = (getFirstComponentOfChannel(toChannelType(compIdx)) == compIdx);
1614 
1615  //type
1616  if(bIsFirstCompOfChType)
1617  {
1618  //sao_type_idx_luma or sao_type_idx_chroma
1619  if(ctbParam.modeIdc == SAO_MODE_OFF)
1620  {
1621  uiSymbol =0;
1622  }
1623  else if(ctbParam.typeIdc == SAO_TYPE_BO) //BO
1624  {
1625  uiSymbol = 1;
1626  }
1627  else
1628  {
1629  assert(ctbParam.typeIdc < SAO_TYPE_START_BO); //EO
1630  uiSymbol = 2;
1631  }
1632  codeSaoTypeIdx(uiSymbol);
1633  }
1634 
1635  if(ctbParam.modeIdc == SAO_MODE_NEW)
1636  {
1637  Int numClasses = (ctbParam.typeIdc == SAO_TYPE_BO)?4:NUM_SAO_EO_CLASSES;
1638  Int offset[4];
1639  Int k=0;
1640  for(Int i=0; i< numClasses; i++)
1641  {
1642  if(ctbParam.typeIdc != SAO_TYPE_BO && i == SAO_CLASS_EO_PLAIN)
1643  {
1644  continue;
1645  }
1646  Int classIdx = (ctbParam.typeIdc == SAO_TYPE_BO)?( (ctbParam.typeAuxInfo+i)% NUM_SAO_BO_CLASSES ):i;
1647  offset[k] = ctbParam.offset[classIdx];
1648  k++;
1649  }
1650 
1651  const Int maxOffsetQVal = TComSampleAdaptiveOffset::getMaxOffsetQVal(channelBitDepth);
1652  for(Int i=0; i< 4; i++)
1653  {
1654  codeSaoMaxUvlc((offset[i]<0)?(-offset[i]):(offset[i]), maxOffsetQVal ); //sao_offset_abs
1655  }
1656 
1657 
1658  if(ctbParam.typeIdc == SAO_TYPE_BO)
1659  {
1660  for(Int i=0; i< 4; i++)
1661  {
1662  if(offset[i] != 0)
1663  {
1664  codeSAOSign((offset[i]< 0)?1:0);
1665  }
1666  }
1667 
1668  codeSaoUflc(NUM_SAO_BO_CLASSES_LOG2, ctbParam.typeAuxInfo ); //sao_band_position
1669  }
1670  else //EO
1671  {
1672  if(bIsFirstCompOfChType)
1673  {
1674  assert(ctbParam.typeIdc - SAO_TYPE_START_EO >=0);
1675  codeSaoUflc(NUM_SAO_EO_TYPES_LOG2, ctbParam.typeIdc - SAO_TYPE_START_EO ); //sao_eo_class_luma or sao_eo_class_chroma
1676  }
1677  }
1678 
1679  }
1680 }
1681 
1682 
1683 Void TEncSbac::codeSAOBlkParam(SAOBlkParam& saoBlkParam, const BitDepths &bitDepths
1684  , Bool* sliceEnabled
1685  , Bool leftMergeAvail
1686  , Bool aboveMergeAvail
1687  , Bool onlyEstMergeInfo // = false
1688  )
1689 {
1690 
1691  Bool isLeftMerge = false;
1692  Bool isAboveMerge= false;
1693 
1694  if(leftMergeAvail)
1695  {
1696  isLeftMerge = ((saoBlkParam[COMPONENT_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[COMPONENT_Y].typeIdc == SAO_MERGE_LEFT));
1697  codeSaoMerge( isLeftMerge?1:0 ); //sao_merge_left_flag
1698  }
1699 
1700  if( aboveMergeAvail && !isLeftMerge)
1701  {
1702  isAboveMerge = ((saoBlkParam[COMPONENT_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[COMPONENT_Y].typeIdc == SAO_MERGE_ABOVE));
1703  codeSaoMerge( isAboveMerge?1:0 ); //sao_merge_left_flag
1704  }
1705 
1706  if(onlyEstMergeInfo)
1707  {
1708  return; //only for RDO
1709  }
1710 
1711  if(!isLeftMerge && !isAboveMerge) //not merge mode
1712  {
1713  for(Int compIdx=0; compIdx < MAX_NUM_COMPONENT; compIdx++)
1714  {
1715  codeSAOOffsetParam(ComponentID(compIdx), saoBlkParam[compIdx], sliceEnabled[compIdx], bitDepths.recon[toChannelType(ComponentID(compIdx))]);
1716  }
1717  }
1718 }
1719 
1726 Void TEncSbac::estBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, ChannelType chType, COEFF_SCAN_TYPE scanType )
1727 {
1728  estCBFBit( pcEstBitsSbac );
1729 
1730  estSignificantCoeffGroupMapBit( pcEstBitsSbac, chType );
1731 
1732  // encode significance map
1733  estSignificantMapBit( pcEstBitsSbac, width, height, chType );
1734 
1735  // encode last significant position
1736  estLastSignificantPositionBit( pcEstBitsSbac, width, height, chType, scanType );
1737 
1738  // encode significant coefficients
1739  estSignificantCoefficientsBit( pcEstBitsSbac, chType );
1740 
1742 }
1743 
1751 {
1752  ContextModel *pCtx = m_cCUQtCbfSCModel.get( 0 );
1753 
1754  for( UInt uiCtxInc = 0; uiCtxInc < (NUM_QT_CBF_CTX_SETS * NUM_QT_CBF_CTX_PER_SET); uiCtxInc++ )
1755  {
1756  pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 );
1757  pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 );
1758  }
1759 
1760  pCtx = m_cCUQtRootCbfSCModel.get( 0 );
1761 
1762  for( UInt uiCtxInc = 0; uiCtxInc < 4; uiCtxInc++ )
1763  {
1764  pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 );
1765  pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 );
1766  }
1767 }
1768 
1769 
1777 {
1778  Int firstCtx = 0, numCtx = NUM_SIG_CG_FLAG_CTX;
1779 
1780  for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ )
1781  {
1782  for( UInt uiBin = 0; uiBin < 2; uiBin++ )
1783  {
1784  pcEstBitsSbac->significantCoeffGroupBits[ ctxIdx ][ uiBin ] = m_cCUSigCoeffGroupSCModel.get( 0, chType, ctxIdx ).getEntropyBits( uiBin );
1785  }
1786  }
1787 }
1788 
1789 
1797 {
1798  //--------------------------------------------------------------------------------------------------
1799 
1800  //set up the number of channels and context variables
1801 
1802  const UInt firstComponent = ((isLuma(chType)) ? (COMPONENT_Y) : (COMPONENT_Cb));
1803  const UInt lastComponent = ((isLuma(chType)) ? (COMPONENT_Y) : (COMPONENT_Cb));
1804 
1805  //----------------------------------------------------------
1806 
1807  Int firstCtx = MAX_INT;
1808  Int numCtx = MAX_INT;
1809 
1810  if ((width == 4) && (height == 4))
1811  {
1814  }
1815  else if ((width == 8) && (height == 8))
1816  {
1819  }
1820  else
1821  {
1824  }
1825 
1826  //--------------------------------------------------------------------------------------------------
1827 
1828  //fill the data for the significace map
1829 
1830  for (UInt component = firstComponent; component <= lastComponent; component++)
1831  {
1832  const UInt contextOffset = getSignificanceMapContextOffset(ComponentID(component));
1833 
1834  if (firstCtx > 0)
1835  {
1836  for( UInt bin = 0; bin < 2; bin++ ) //always get the DC
1837  {
1838  pcEstBitsSbac->significantBits[ contextOffset ][ bin ] = m_cCUSigSCModel.get( 0, 0, contextOffset ).getEntropyBits( bin );
1839  }
1840  }
1841 
1842  // This could be made optional, but would require this function to have knowledge of whether the
1843  // TU is transform-skipped or transquant-bypassed and whether the SPS flag is set
1844  for( UInt bin = 0; bin < 2; bin++ )
1845  {
1846  const Int ctxIdx = significanceMapContextSetStart[chType][CONTEXT_TYPE_SINGLE];
1847  pcEstBitsSbac->significantBits[ contextOffset + ctxIdx ][ bin ] = m_cCUSigSCModel.get( 0, 0, (contextOffset + ctxIdx) ).getEntropyBits( bin );
1848  }
1849 
1850  for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ )
1851  {
1852  for( UInt uiBin = 0; uiBin < 2; uiBin++ )
1853  {
1854  pcEstBitsSbac->significantBits[ contextOffset + ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, (contextOffset + ctxIdx) ).getEntropyBits( uiBin );
1855  }
1856  }
1857  }
1858 
1859  //--------------------------------------------------------------------------------------------------
1860 }
1861 
1862 
1871 {
1872  if (scanType == SCAN_VER)
1873  {
1874  swap(width, height);
1875  }
1876 
1877  //--------------------------------------------------------------------------------------------------.
1878 
1879  //set up the number of channels
1880 
1881  const UInt firstComponent = ((isLuma(chType)) ? (COMPONENT_Y) : (COMPONENT_Cb));
1882  const UInt lastComponent = ((isLuma(chType)) ? (COMPONENT_Y) : (COMPONENT_Cb));
1883 
1884  //--------------------------------------------------------------------------------------------------
1885 
1886  //fill the data for the last-significant-coefficient position
1887 
1888  for (UInt componentIndex = firstComponent; componentIndex <= lastComponent; componentIndex++)
1889  {
1890  const ComponentID component = ComponentID(componentIndex);
1891 
1892  Int iBitsX = 0, iBitsY = 0;
1893 
1894  Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY;
1895  getLastSignificantContextParameters(ComponentID(component), width, height, blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY);
1896 
1897  Int ctx;
1898 
1899  const ChannelType channelType = toChannelType(ComponentID(component));
1900 
1901  ContextModel *const pCtxX = m_cCuCtxLastX.get( 0, channelType );
1902  ContextModel *const pCtxY = m_cCuCtxLastY.get( 0, channelType );
1903  Int *const lastXBitsArray = pcEstBitsSbac->lastXBits[channelType];
1904  Int *const lastYBitsArray = pcEstBitsSbac->lastYBits[channelType];
1905 
1906  //------------------------------------------------
1907 
1908  //X-coordinate
1909 
1910  for (ctx = 0; ctx < g_uiGroupIdx[ width - 1 ]; ctx++)
1911  {
1912  Int ctxOffset = blkSizeOffsetX + (ctx >>shiftX);
1913  lastXBitsArray[ ctx ] = iBitsX + pCtxX[ ctxOffset ].getEntropyBits( 0 );
1914  iBitsX += pCtxX[ ctxOffset ].getEntropyBits( 1 );
1915  }
1916 
1917  lastXBitsArray[ctx] = iBitsX;
1918 
1919  //------------------------------------------------
1920 
1921  //Y-coordinate
1922 
1923  for (ctx = 0; ctx < g_uiGroupIdx[ height - 1 ]; ctx++)
1924  {
1925  Int ctxOffset = blkSizeOffsetY + (ctx >>shiftY);
1926  lastYBitsArray[ ctx ] = iBitsY + pCtxY[ ctxOffset ].getEntropyBits( 0 );
1927  iBitsY += pCtxY[ ctxOffset ].getEntropyBits( 1 );
1928  }
1929 
1930  lastYBitsArray[ctx] = iBitsY;
1931 
1932  } //end of component loop
1933 
1934  //--------------------------------------------------------------------------------------------------
1935 }
1936 
1937 
1945 {
1946  ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0);
1947  ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0);
1948 
1949  const UInt oneStartIndex = ((isLuma(chType)) ? (0) : (NUM_ONE_FLAG_CTX_LUMA));
1950  const UInt oneStopIndex = ((isLuma(chType)) ? (NUM_ONE_FLAG_CTX_LUMA) : (NUM_ONE_FLAG_CTX));
1951  const UInt absStartIndex = ((isLuma(chType)) ? (0) : (NUM_ABS_FLAG_CTX_LUMA));
1952  const UInt absStopIndex = ((isLuma(chType)) ? (NUM_ABS_FLAG_CTX_LUMA) : (NUM_ABS_FLAG_CTX));
1953 
1954  for (Int ctxIdx = oneStartIndex; ctxIdx < oneStopIndex; ctxIdx++)
1955  {
1956  pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 );
1957  pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 );
1958  }
1959 
1960  for (Int ctxIdx = absStartIndex; ctxIdx < absStopIndex; ctxIdx++)
1961  {
1962  pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 );
1963  pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 );
1964  }
1965 }
1966 
1973 {
1976 }
1977 
1979 {
1980  xCopyContextsFrom(pSrc);
1981 }
1982 
1988 {
1989  TComDataCU *cu = rTu.getCU();
1990  const TComRectangle &rect = rTu.getRect(compID);
1991  const UInt absPartIdx = rTu.GetAbsPartIdxTU(compID);
1992  const UInt tuHeight = g_aucConvertToBit[rect.height];
1993  const UInt tuWidth = g_aucConvertToBit[rect.width];
1994 
1995  assert(tuHeight == tuWidth);
1996  assert(tuHeight < 4);
1997 
1998  UInt explicitRdpcmMode = cu->getExplicitRdpcmMode(compID, absPartIdx);
1999 
2000  if( explicitRdpcmMode == RDPCM_OFF )
2001  {
2003  }
2004  else if( explicitRdpcmMode == RDPCM_HOR || explicitRdpcmMode == RDPCM_VER )
2005  {
2007  if(explicitRdpcmMode == RDPCM_HOR)
2008  {
2010  }
2011  else
2012  {
2014  }
2015  }
2016  else
2017  {
2018  assert(0);
2019  }
2020 }
2021 
#define NUM_SAO_EO_TYPES_LOG2
Definition: TypeDef.h:562
SChar g_aucConvertToBit[MAX_CU_SIZE+1]
Definition: TComRom.cpp:572
ContextModel3DBuffer m_cSaoTypeIdxSCModel
Definition: TEncSbac.h:200
Void codeQtCbfZero(TComTU &rTu, const ChannelType chType)
Definition: TEncSbac.cpp:1087
#define NUM_SAO_BO_CLASSES_LOG2
Definition: TypeDef.h:574
Bool getCrossComponentPredictionEnabledFlag() const
Definition: TComSlice.h:1001
Int getEntropyBits(Short val)
Definition: ContextModel.h:79
Void estSignificantMapBit(estBitsSbacStruct *pcEstBitsSbac, Int width, Int height, ChannelType chType)
estimate SAMBAC bit cost for significant coefficient map
Definition: TEncSbac.cpp:1796
ContextModel3DBuffer m_explicitRdpcmFlagSCModel
Definition: TEncSbac.h:203
Void codeSplitFlag(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
Definition: TEncSbac.cpp:613
static Int countNonZeroCoeffs(TCoeff *pcCoef, UInt uiSize)
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
Void codeSPS(const TComSPS *pcSPS)
Definition: TEncSbac.cpp:229
SliceType
supported slice type
Definition: TypeDef.h:283
Int getMVPIdx(RefPicList eRefPicList, UInt uiIdx) const
Definition: TComDataCU.h:378
Bool getPersistentRiceAdaptationEnabledFlag() const
Definition: TComSlice.h:732
Int getRefIdx(Int iIdx) const
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)
SliceType getSliceType() const
Definition: TComSlice.h:1353
ContextModel3DBuffer m_cCUMergeFlagExtSCModel
Definition: TEncSbac.h:176
CU data structure class.
Definition: TComDataCU.h:64
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
virtual Void resetBac()=0
Int lastYBits[MAX_NUM_CHANNEL_TYPE][LAST_SIGNIFICANT_GROUPS]
Definition: TComTrQuant.h:65
Void codeCoeffNxN(TComTU &rTu, TCoeff *pcCoef, const ComponentID compID)
Definition: TEncSbac.cpp:1181
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
Int getHor() const
Definition: TComMv.h:88
Void estSignificantCoefficientsBit(estBitsSbacStruct *pcEstBitsSbac, ChannelType chType)
estimate bit cost of significant coefficient
Definition: TEncSbac.cpp:1944
ContextModel3DBuffer m_cCUPredModeSCModel
Definition: TEncSbac.h:179
ContextModel3DBuffer m_cCURefPicSCModel
Definition: TEncSbac.h:184
Void estCBFBit(estBitsSbacStruct *pcEstBitsSbac)
estimate bit cost for each CBP bit
Definition: TEncSbac.cpp:1750
void Void
Definition: TypeDef.h:203
static const UInt significanceMapContextSetSize[MAX_NUM_CHANNEL_TYPE][CONTEXT_NUMBER_OF_TYPES]
Definition: ContextTables.h:86
Void codeSliceHeader(TComSlice *pcSlice)
Definition: TEncSbac.cpp:241
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
SChar * getCrossComponentPredictionAlpha(ComponentID compID)
Definition: TComDataCU.h:242
#define NUM_INTER_DIR_CTX
number of context models for inter prediction direction
Definition: ContextTables.h:63
#define NUM_ONE_FLAG_CTX_LUMA
number of context models for greater than 1 flag of luma
static ComponentID getFirstComponentOfChannel(const ChannelType id)
Void estSignificantCoeffGroupMapBit(estBitsSbacStruct *pcEstBitsSbac, ChannelType chType)
estimate SAMBAC bit cost for significant coefficient group map
Definition: TEncSbac.cpp:1776
Int lastXBits[MAX_NUM_CHANNEL_TYPE][LAST_SIGNIFICANT_GROUPS]
Definition: TComTrQuant.h:64
Void codeSaoTypeIdx(UInt uiCode)
Definition: TEncSbac.cpp:1592
#define NULL
Definition: CommonDef.h:107
Int typeIdc
Definition: TypeDef.h:762
UChar getQtRootCbf(UInt uiIdx) const
Int blockCbpBits[2 *5][2]
Definition: TComTrQuant.h:69
#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
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
TEncBinIf * m_pcBinIf
Definition: TEncSbac.h:120
SChar * getPredictionMode()
Definition: TComDataCU.h:237
UInt getNumPartitionsInCtu() const
Definition: TComPic.h:130
Bool getMvdL1ZeroFlag() const
Definition: TComSlice.h:1383
ContextModel3DBuffer m_cCUInterDirSCModel
Definition: TEncSbac.h:183
Void codeSkipFlag(TComDataCU *pcCU, UInt uiAbsPartIdx)
Definition: TEncSbac.cpp:543
#define NUM_CTX_LAST_FLAG_XY
number of context models for last coefficient position
Short Pel
pixel type
Definition: TypeDef.h:249
#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
Void codeSAOSign(UInt uiCode)
Definition: TEncSbac.cpp:1543
Int blockRootCbpBits[4][2]
Definition: TComTrQuant.h:70
static const Int MIN_TU_SIZE
Definition: CommonDef.h:223
symmetric motion partition, 2Nx N
Definition: TypeDef.h:351
static const UChar INIT_CHROMA_QP_ADJ_FLAG[NUMBER_OF_SLICE_TYPES][1]
#define NUM_ONE_FLAG_CTX
number of context models for greater than 1 flag
UInt m_golombRiceAdaptationStatistics[RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS]
Definition: TEncSbac.h:210
UInt GetTransformDepthRel() const
Definition: TComTU.h:108
Int getNumberValidComponents() const
Definition: TComPic.h:140
UInt getCtxSkipFlag(UInt uiAbsPartIdx) const
#define NUM_SKIP_FLAG_CTX
number of context models for skip flag
Definition: ContextTables.h:52
ContextModel3DBuffer m_cCUChromaPredSCModel
Definition: TEncSbac.h:181
Void codeSaoMaxUvlc(UInt code, UInt maxSymbol)
Definition: TEncSbac.cpp:1548
ContextModel3DBuffer m_cCuCtxLastX
Definition: TEncSbac.h:192
TComMv const & getMvd(Int iIdx) const
UChar getCbf(UInt uiIdx, ComponentID eType) const
Definition: TComDataCU.h:307
UChar * getMergeIndex()
Definition: TComDataCU.h:330
Void codeLastSignificantXY(UInt uiPosX, UInt uiPosY, Int width, Int height, ComponentID component, UInt uiScanIdx)
Definition: TEncSbac.cpp:1115
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
Void codeVPS(const TComVPS *pcVPS)
Definition: TEncSbac.cpp:223
#define NUM_SAO_MERGE_FLAG_CTX
number of context models for SAO merge flags
virtual Void encodeBinTrm(UInt uiBin)=0
UInt getMinCUWidth() const
Definition: TComPic.h:133
ContextModel3DBuffer m_cCUDeltaQpSCModel
Definition: TEncSbac.h:182
#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)
Int m_greaterOneBits[((4 *4)+(4 *2))][2]
Definition: TComTrQuant.h:66
Void codePPS(const TComPPS *pcPPS)
Definition: TEncSbac.cpp:235
Void getAllowedChromaDir(UInt uiAbsPartIdx, UInt *uiModeList) const
Void codeCrossComponentPrediction(TComTU &rTu, ComponentID compID)
Definition: TEncSbac.cpp:833
UInt GetAbsPartIdxTU() const
Definition: TComTU.h:119
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
class for motion information in one CU
UInt getMaxTotalCUDepth() const
Definition: TComSlice.h:861
virtual ~TEncSbac()
Definition: TEncSbac.cpp:97
Int significantBits[(28+16)][2]
Definition: TComTrQuant.h:63
ContextModel3DBuffer m_cCUAbsSCModel
Definition: TEncSbac.h:195
PartSize
supported partition shape
Definition: TypeDef.h:348
static const UChar INIT_TRANSFORMSKIP_FLAG[NUMBER_OF_SLICE_TYPES][2 *1]
ContextModel3DBuffer m_cCUOneSCModel
Definition: TEncSbac.h:194
Void loadContexts(const TEncSbac *pSrc)
Definition: TEncSbac.cpp:1978
Bool * getIPCMFlag()
Definition: TComDataCU.h:354
Void estLastSignificantPositionBit(estBitsSbacStruct *pcEstBitsSbac, Int width, Int height, ChannelType chType, COEFF_SCAN_TYPE scanType)
estimate bit cost of significant coefficient
Definition: TEncSbac.cpp:1870
Void codeIntraDirChroma(TComDataCU *pcCU, UInt uiAbsPartIdx)
Definition: TEncSbac.cpp:698
static const UChar INIT_SKIP_FLAG[NUMBER_OF_SLICE_TYPES][3]
ContextModel3DBuffer m_cCUQtCbfSCModel
Definition: TEncSbac.h:186
context model class
Definition: ContextModel.h:57
ContextModel3DBuffer m_cCUSigSCModel
Definition: TEncSbac.h:191
UChar * getIntraDir(const ChannelType channelType) const
Definition: TComDataCU.h:342
Void xWriteCoefRemainExGolomb(UInt symbol, UInt &rParam, const Bool useLimitedPrefixLength, const Int maxLog2TrDynamicRange)
Definition: TEncSbac.cpp:337
static const UChar INIT_QT_CBF[NUMBER_OF_SLICE_TYPES][2 *5]
Void codeSAOBlkParam(SAOBlkParam &saoBlkParam, const BitDepths &bitDepths, Bool *sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail, Bool onlyEstMergeInfo=false)
Definition: TEncSbac.cpp:1683
#define NUM_SIG_CG_FLAG_CTX
number of context models for MULTI_LEVEL_SIGNIFICANCE
Definition: ContextTables.h:73
Int golombRiceAdaptationStatistics[RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS]
Definition: TComTrQuant.h:72
UInt getGolombRiceStatisticsIndex(const ComponentID compID)
Definition: TComTU.cpp:245
#define NUM_ABS_FLAG_CTX_LUMA
number of context models for greater than 2 flag of luma
UInt getMaxNumMergeCand() const
Definition: TComSlice.h:1465
ContextModel3DBuffer m_cCUSkipFlagSCModel
Definition: TEncSbac.h:175
#define NUM_SAO_BO_CLASSES
Definition: TypeDef.h:575
ContextModel3DBuffer m_cCUTransSubdivFlagSCModel
Definition: TEncSbac.h:187
symmetric motion partition, 2Nx2N
Definition: TypeDef.h:350
Void codeIPCMInfo(TComDataCU *pcCU, UInt uiAbsPartIdx)
Definition: TEncSbac.cpp:1034
Void codeMergeFlag(TComDataCU *pcCU, UInt uiAbsPartIdx)
Definition: TEncSbac.cpp:563
Int getQpBDOffset(ChannelType type) const
Definition: TComSlice.h:904
static const Int MLS_CG_LOG2_WIDTH
Definition: CommonDef.h:169
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
ContextModel3DBuffer m_cCUPartSizeSCModel
Definition: TEncSbac.h:178
static const UChar INIT_CHROMA_QP_ADJ_IDC[NUMBER_OF_SLICE_TYPES][1]
Void xCopyContextsFrom(const TEncSbac *pSrc)
Definition: TEncSbac.cpp:1972
Void xCopyFrom(const TEncSbac *pSrc)
Definition: TEncSbac.cpp:421
#define NUM_CHROMA_PRED_CTX
number of context models for intra prediction (chroma)
Definition: ContextTables.h:62
virtual Void xWritePCMCode(UInt uiCode, UInt uiLength)=0
static const Int VER_IDX
index for intra VERTICAL mode
Definition: CommonDef.h:184
Void xWriteUnarySymbol(UInt uiSymbol, ContextModel *pcSCModel, Int iOffset)
Definition: TEncSbac.cpp:263
ContextModel3DBuffer m_cCUQtRootCbfSCModel
Definition: TEncSbac.h:188
static const UChar INIT_EXPLICIT_RDPCM_FLAG[NUMBER_OF_SLICE_TYPES][2 *1]
Int m_numContextModels
Definition: TEncSbac.h:173
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 codeSAOOffsetParam(ComponentID compIdx, SAOOffset &ctbParam, Bool sliceEnabled, const Int channelBitDepth)
Definition: TEncSbac.cpp:1605
UInt getMinCUHeight() const
Definition: TComPic.h:134
Bool isRDPCMEnabled(UInt uiAbsPartIdx) const
Definition: TComDataCU.h:290
UInt getCtxSplitFlag(UInt uiAbsPartIdx, UInt uiDepth) const
PPS class.
Definition: TComSlice.h:1034
Void codeQtCbf(TComTU &rTu, const ComponentID compID, const Bool lowestLevel)
Definition: TEncSbac.cpp:920
asymmetric motion partition, 2Nx( N/2) + 2Nx(3N/2)
Definition: TypeDef.h:354
static const UChar INIT_TRANS_SUBDIV_FLAG[NUMBER_OF_SLICE_TYPES][3]
Void codeExplicitRdpcmMode(TComTU &rTu, const ComponentID compID)
Definition: TEncSbac.cpp:1987
asymmetric motion partition, (3N/2)x2N + ( N/2)x2N
Definition: TypeDef.h:357
#define NUM_REF_NO_CTX
number of context models for reference index
Definition: ContextTables.h:68
static const Int MAX_INT
max. value of signed 32-bit integer
Definition: CommonDef.h:115
UInt & getCtuRsAddr()
Definition: TComDataCU.h:204
Void load(const TEncSbac *pSrc)
Definition: TEncSbac.cpp:396
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 calcCost(SliceType sliceType, Int qp, UChar *ctxModel)
determine cost of choosing a probability table based on current probabilities
UInt getCUPelY() const
Definition: TComDataCU.h:208
static ChannelType toChannelType(const ComponentID id)
static const Int CU_DQP_TU_CMAX
max number bins for truncated unary
Definition: CommonDef.h:155
Void loadIntraDirMode(const TEncSbac *pScr, const ChannelType chType)
Definition: TEncSbac.cpp:401
Void codeTransformSubdivFlag(UInt uiSymbol, UInt uiCtx)
Definition: TEncSbac.cpp:630
#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]
Void estBit(estBitsSbacStruct *pcEstBitsSbac, Int width, Int height, ChannelType chType, COEFF_SCAN_TYPE scanType)
estimate bit cost for CBP, significant map and significant coefficients
Definition: TEncSbac.cpp:1726
ContextModel3DBuffer m_ChromaQpAdjFlagSCModel
Definition: TEncSbac.h:207
virtual Void copyState(const TEncBinIf *pcTEncBinIf)=0
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
Int getComponentScaleX(const ComponentID id) const
Definition: TComPic.h:137
RefPicList
reference list index
Definition: TypeDef.h:370
Void xWriteEpExGolomb(UInt uiSymbol, UInt uiCount)
Definition: TEncSbac.cpp:308
Void codeTransformSkipFlags(TComTU &rTu, ComponentID component)
Definition: TEncSbac.cpp:997
Bool getCabacBypassAlignmentEnabledFlag() const
Definition: TComSlice.h:735
virtual Void start()=0
#define DTRACE_CABAC_VL(x)
Definition: TComRom.h:153
static const UChar INIT_SIG_CG_FLAG[NUMBER_OF_SLICE_TYPES][2 *2]
ContextModel3DBuffer m_cMVPIdxSCModel
Definition: TEncSbac.h:197
unsigned char UChar
Definition: TypeDef.h:208
const TComRectangle & getRect(const ComponentID compID) const
Definition: TComTU.h:96
Void codeSaoMerge(UInt uiCode)
Definition: TEncSbac.cpp:1585
ContextModel & get(UInt uiZ, UInt uiY, UInt uiX)
COEFF_SCAN_TYPE
coefficient scanning type used in ACS
Definition: TypeDef.h:473
Int getMaxLog2TrDynamicRange(ChannelType channelType) const
Definition: TComSlice.h:901
UChar * getDepth()
Definition: TComDataCU.h:210
virtual Void align()=0
Void codeMvd(TComDataCU *pcCU, UInt uiAbsPartIdx, RefPicList eRefList)
Definition: TEncSbac.cpp:779
Bool isSkipped(UInt uiPartIdx) const
returns true, if the partiton is skipped
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
static const UInt significanceMapContextSetStart[MAX_NUM_CHANNEL_TYPE][CONTEXT_NUMBER_OF_TYPES]
Definition: ContextTables.h:85
#define NUM_QT_CBF_CTX_PER_SET
number of context models for QT CBF
Void codeTilesWPPEntryPoint(TComSlice *pSlice)
Definition: TEncSbac.cpp:247
UInt getCUPelX() const
Definition: TComDataCU.h:207
static const UChar INIT_MERGE_IDX_EXT[NUMBER_OF_SLICE_TYPES][1]
static const UChar INIT_MVD[NUMBER_OF_SLICE_TYPES][2]
Int getVer() const
Definition: TComMv.h:89
Void codeDeltaQP(TComDataCU *pcCU, UInt uiAbsPartIdx)
Definition: TEncSbac.cpp:879
UChar * getTransformSkip(ComponentID compID)
Definition: TComDataCU.h:281
ContextModel3DBuffer m_cCrossComponentPredictionSCModel
Definition: TEncSbac.h:205
Void codePartSize(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
Definition: TEncSbac.cpp:435
ContextModel3DBuffer m_cCUIntraPredSCModel
Definition: TEncSbac.h:180
Void codeCUTransquantBypassFlag(TComDataCU *pcCU, UInt uiAbsPartIdx)
Definition: TEncSbac.cpp:532
Bool isIntra() const
Definition: TComSlice.h:1423
TComDataCU * getCU()
Definition: TComTU.h:126
ContextModel3DBuffer m_cTransformSkipSCModel
Definition: TEncSbac.h:201
#define DTRACE_CABAC_T(x)
Definition: TComRom.h:154
reference list 1
Definition: TypeDef.h:373
UChar * getHeight()
Definition: TComDataCU.h:252
Void codePredMode(TComDataCU *pcCU, UInt uiAbsPartIdx)
Definition: TEncSbac.cpp:526
#define NUM_CTX_LAST_FLAG_SETS
encoder class (header)
const UInt g_uiMinInGroup[LAST_SIGNIFICANT_GROUPS]
Definition: TComRom.cpp:597
COEFF_SCAN_TYPE scanType
Definition: TypeDef.h:812
Int getLog2DiffMaxMinCodingBlockSize() const
Definition: TComSlice.h:853
virtual Void encodeBinEP(UInt uiBin)=0
Bool * getCUTransquantBypass()
Definition: TComDataCU.h:245
ContextModel m_contextModels[512]
Definition: TEncSbac.h:172
#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
virtual Void encodeBin(UInt uiBin, ContextModel &rcCtxModel)=0
Context-adaptive entropy encoder class (header)
UInt GetAbsPartIdxNumParts() const
Definition: TComTU.h:121
static const UChar INIT_ONE_FLAG[NUMBER_OF_SLICE_TYPES][((4 *4)+(4 *2))]
TComPic * getPic()
Definition: TComDataCU.h:200
static Int getMaxOffsetQVal(const Int channelBitDepth)
ContextModel3DBuffer m_cCUSplitFlagSCModel
Definition: TEncSbac.h:174
ContextModel3DBuffer m_ChromaQpAdjIdcSCModel
Definition: TEncSbac.h:208
Bool getFinalized() const
Definition: TComSlice.h:1500
ContextModel3DBuffer m_cCUSigCoeffGroupSCModel
Definition: TEncSbac.h:190
Definition: TComTU.h:48
#define NUM_TRANS_SUBDIV_FLAG_CTX
number of context models for transform subdivision flags
Definition: ContextTables.h:69
Void codeTerminatingBit(UInt uilsLast)
Definition: TEncSbac.cpp:253
static const UChar INIT_SAO_TYPE_IDX[NUMBER_OF_SLICE_TYPES][1]
#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
Void codeMergeIndex(TComDataCU *pcCU, UInt uiAbsPartIdx)
Definition: TEncSbac.cpp:583
const UInt g_uiGroupIdx[MAX_TU_SIZE]
Definition: TComRom.cpp:598
static const UChar INIT_REF_PIC[NUMBER_OF_SLICE_TYPES][2]
Void resetEntropy(const TComSlice *pSlice)
Definition: TEncSbac.cpp:105
#define NUM_TRANSFORMSKIP_FLAG_CTX
number of context models for transform skipping
SliceType getEncCABACTableIdx() const
Definition: TComSlice.h:1539
Bool getUseAMP() const
Definition: TComSlice.h:870
static Int calcPatternSigCtx(const UInt *sigCoeffGroupFlag, UInt uiCGPosX, UInt uiCGPosY, UInt widthInGroups, UInt heightInGroups)
Int significantCoeffGroupBits[2][2]
Definition: TComTrQuant.h:62
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
virtual Void encodeBinsEP(UInt uiBins, Int numBins)=0
Void store(TEncSbac *pDest) const
Definition: TEncSbac.cpp:415
Void codeSliceFinish()
Definition: TEncSbac.cpp:258
Void codeMVPIdx(TComDataCU *pcCU, UInt uiAbsPartIdx, RefPicList eRefList)
Definition: TEncSbac.cpp:427
ContextModel3DBuffer m_cSaoMergeSCModel
Definition: TEncSbac.h:199
virtual Void encodePCMAlignBits()=0
ContextModel3DBuffer m_explicitRdpcmDirSCModel
Definition: TEncSbac.h:204
TComCUMvField * getCUMvField(RefPicList e)
Definition: TComDataCU.h:297
UChar * getWidth()
Definition: TComDataCU.h:248
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
#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)
static const Int MLS_CG_LOG2_HEIGHT
Definition: CommonDef.h:170
int Int
Definition: TypeDef.h:211
static const UChar INIT_INTRA_PRED_MODE[NUMBER_OF_SLICE_TYPES][1]
Int m_levelAbsBits[((1 *4)+(1 *2))][2]
Definition: TComTrQuant.h:67
static const Int RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS
Definition: CommonDef.h:213
UInt getPCMBitDepth(ChannelType type) const
Definition: TComSlice.h:915
ContextModel3DBuffer m_cCUMvdSCModel
Definition: TEncSbac.h:185
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
Void codeChromaQpAdjustment(TComDataCU *cu, UInt absPartIdx)
Definition: TEncSbac.cpp:906
ComponentID
Definition: TypeDef.h:308
static const UChar INIT_MVP_IDX[NUMBER_OF_SLICE_TYPES][1]
Bool * getMergeFlag()
Definition: TComDataCU.h:325
Int getSliceQp() const
Definition: TComSlice.h:1355
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 finish()=0
TEncSbac()
Definition: TEncSbac.cpp:57
SChar * getQP()
Definition: TComDataCU.h:258
SChar getRefQP(UInt uiCurrAbsIdxInCtu) const
Void codeSaoUflc(UInt uiLength, UInt uiCode)
Definition: TEncSbac.cpp:1578
asymmetric motion partition, 2Nx(3N/2) + 2Nx( N/2)
Definition: TypeDef.h:355
Void codeRefFrmIdx(TComDataCU *pcCU, UInt uiAbsPartIdx, RefPicList eRefList)
Definition: TEncSbac.cpp:748
#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
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
SBAC encoder class.
Definition: TEncSbac.h:66
UInt g_auiRasterToPelX[MAX_NUM_PART_IDXS_IN_CTU_WIDTH *MAX_NUM_PART_IDXS_IN_CTU_WIDTH]
Definition: TComRom.cpp:286
static UInt getContextSetIndex(const ComponentID component, const UInt subsetIndex, const Bool foundACoefficientGreaterThan1)
Void codeInterDir(TComDataCU *pcCU, UInt uiAbsPartIdx)
Definition: TEncSbac.cpp:729
vertical first scan
Definition: TypeDef.h:477
slice header class
Definition: TComSlice.h:1225
Void codeIntraDirLumaAng(TComDataCU *pcCU, UInt absPartIdx, Bool isMultiple)
Definition: TEncSbac.cpp:643
static const UInt NUM_MOST_PROBABLE_MODES
Definition: TComDataCU.h:57
ContextModel3DBuffer m_cCuCtxLastY
Definition: TEncSbac.h:193
#define NUM_MERGE_IDX_EXT_CTX
number of context models for merge index of merge extended
Definition: ContextTables.h:55
Void copyFrom(const ContextModel3DBuffer *src)
UChar * getChromaQpAdj()
array of chroma QP adjustments (indexed). when value = 0, cu_chroma_qp_offset_flag=0; when value&gt;0...
Definition: TComDataCU.h:268
Void codeQtRootCbfZero()
Definition: TEncSbac.cpp:1097
Void xWriteUnaryMaxSymbol(UInt uiSymbol, ContextModel *pcSCModel, Int iOffset, UInt uiMaxSymbol)
Definition: TEncSbac.cpp:280
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
#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
ContextModel3DBuffer m_cCUMergeIdxExtSCModel
Definition: TEncSbac.h:177
symmetric motion partition, Nx2N
Definition: TypeDef.h:352
ContextModel3DBuffer m_CUTransquantBypassFlagSCModel
Definition: TEncSbac.h:202
SliceType determineCabacInitIdx(const TComSlice *pSlice)
Definition: TEncSbac.cpp:162
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
UInt GetTransformDepthTotal() const
Definition: TComTU.h:105
TComSlice * getSlice()
Definition: TComDataCU.h:202
const TComSPS * getSPS() const
Definition: TComSlice.h:1329
SPS class.
Definition: TComSlice.h:740
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
Void codeQtRootCbf(TComDataCU *pcCU, UInt uiAbsPartIdx)
Definition: TEncSbac.cpp:1071