HEVC Test Model (HM)  HM-16.18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TEncEntropy.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 "TEncEntropy.h"
39 #include "TLibCommon/CommonDef.h"
41 #include "TLibCommon/TComTU.h"
42 
43 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
44 #include "../TLibCommon/Debug.h"
45 static const Bool bDebugPredEnabled = DebugOptionList::DebugPred.getInt()!=0;
46 #endif
47 
50 
52 {
54 }
55 
57 {
59  return;
60 }
61 
63 {
65 }
66 
68 {
70 
71  return;
72 }
73 
75 {
77 }
78 
80 {
81  m_pcEntropyCoderIf->codePPS( pcPPS );
82  return;
83 }
84 
86 {
87  m_pcEntropyCoderIf->codeSPS( pcSPS );
88  return;
89 }
90 
92 {
93  if( bRD )
94  {
95  uiAbsPartIdx = 0;
96  }
97  m_pcEntropyCoderIf->codeCUTransquantBypassFlag( pcCU, uiAbsPartIdx );
98 }
99 
101 {
102  m_pcEntropyCoderIf->codeVPS( pcVPS );
103  return;
104 }
105 
107 {
108  if ( pcCU->getSlice()->isIntra() )
109  {
110  return;
111  }
112  if( bRD )
113  {
114  uiAbsPartIdx = 0;
115  }
116  m_pcEntropyCoderIf->codeSkipFlag( pcCU, uiAbsPartIdx );
117 }
118 
121 {
122  // at least one merge candidate exists
123  m_pcEntropyCoderIf->codeMergeFlag( pcCU, uiAbsPartIdx );
124 }
125 
128 {
129  if( bRD )
130  {
131  uiAbsPartIdx = 0;
132  assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
133  }
134  m_pcEntropyCoderIf->codeMergeIndex( pcCU, uiAbsPartIdx );
135 }
136 
137 
140 {
141  if( bRD )
142  {
143  uiAbsPartIdx = 0;
144  }
145 
146  if ( pcCU->getSlice()->isIntra() )
147  {
148  return;
149  }
150 
151  m_pcEntropyCoderIf->codePredMode( pcCU, uiAbsPartIdx );
152 }
153 
155 Void TEncEntropy::encodeSplitFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD )
156 {
157  if( bRD )
158  {
159  uiAbsPartIdx = 0;
160  }
161 
162  m_pcEntropyCoderIf->codeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
163 }
164 
166 Void TEncEntropy::encodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD )
167 {
168  if( bRD )
169  {
170  uiAbsPartIdx = 0;
171  }
172 
173  m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth );
174 }
175 
176 
183 {
184  if(!pcCU->getSlice()->getSPS()->getUsePCM()
185  || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize())
186  || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()))
187  {
188  return;
189  }
190 
191  if( bRD )
192  {
193  uiAbsPartIdx = 0;
194  }
195 
196  m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx );
197 
198 }
199 
200 Void TEncEntropy::xEncodeTransform( Bool& bCodeDQP, Bool& codeChromaQpAdj, TComTU &rTu )
201 {
202 //pcCU, absPartIdxCU, uiAbsPartIdx, uiDepth+1, uiTrIdx+1, quadrant,
203  TComDataCU *pcCU=rTu.getCU();
204  const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU();
205  const UInt numValidComponent = pcCU->getPic()->getNumberValidComponents();
206  const Bool bChroma = isChromaEnabled(pcCU->getPic()->getChromaFormat());
207  const UInt uiTrIdx = rTu.GetTransformDepthRel();
208  const UInt uiDepth = rTu.GetTransformDepthTotal();
209 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
210  const Bool bDebugRQT=pcCU->getSlice()->getFinalized() && DebugOptionList::DebugRQT.getInt()!=0;
211  if (bDebugRQT)
212  {
213  printf("x..codeTransform: offsetLuma=%d offsetChroma=%d absPartIdx=%d, uiDepth=%d\n width=%d, height=%d, uiTrIdx=%d, uiInnerQuadIdx=%d\n",
215  }
216 #endif
217  const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) > uiTrIdx;// + pcCU->getDepth( uiAbsPartIdx ) > uiDepth;
218  const UInt uiLog2TrafoSize = rTu.GetLog2LumaTrSize();
219 
220 
221  UInt cbf[MAX_NUM_COMPONENT] = {0,0,0};
222  Bool bHaveACodedBlock = false;
223  Bool bHaveACodedChromaBlock = false;
224 
225  for(UInt ch=0; ch<numValidComponent; ch++)
226  {
227  const ComponentID compID = ComponentID(ch);
228 
229  cbf[compID] = pcCU->getCbf( uiAbsPartIdx, compID , uiTrIdx );
230 
231  if (cbf[ch] != 0)
232  {
233  bHaveACodedBlock = true;
234  if (isChroma(compID))
235  {
236  bHaveACodedChromaBlock = true;
237  }
238  }
239  }
240 
241  if( pcCU->isIntra(uiAbsPartIdx) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
242  {
243  assert( uiSubdiv );
244  }
245  else if( pcCU->isInter(uiAbsPartIdx) && (pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N) && uiDepth == pcCU->getDepth(uiAbsPartIdx) && (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) )
246  {
247  if ( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
248  {
249  assert( uiSubdiv );
250  }
251  else
252  {
253  assert(!uiSubdiv );
254  }
255  }
256  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
257  {
258  assert( uiSubdiv );
259  }
260  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
261  {
262  assert( !uiSubdiv );
263  }
264  else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
265  {
266  assert( !uiSubdiv );
267  }
268  else
269  {
270  assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
271  m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
272  }
273 
274  const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx );
275  const Bool bFirstCbfOfCU = uiTrDepthCurr == 0;
276 
277  for(UInt ch=COMPONENT_Cb; ch<numValidComponent; ch++)
278  {
279  const ComponentID compID=ComponentID(ch);
280  if( bFirstCbfOfCU || rTu.ProcessingAllQuadrants(compID) )
281  {
282  if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, compID, uiTrDepthCurr - 1 ) )
283  {
284  m_pcEntropyCoderIf->codeQtCbf( rTu, compID, (uiSubdiv == 0) );
285  }
286  }
287  else
288  {
289  assert( pcCU->getCbf( uiAbsPartIdx, compID, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, compID, uiTrDepthCurr - 1 ) );
290  }
291  }
292 
293  if( uiSubdiv )
294  {
295  TComTURecurse tuRecurseChild(rTu, true);
296  do
297  {
298  xEncodeTransform( bCodeDQP, codeChromaQpAdj, tuRecurseChild );
299  } while (tuRecurseChild.nextSection(rTu));
300  }
301  else
302  {
303  {
304  DTRACE_CABAC_VL( g_nSymbolCounter++ );
305  DTRACE_CABAC_T( "\tTrIdx: abspart=" );
306  DTRACE_CABAC_V( uiAbsPartIdx );
307  DTRACE_CABAC_T( "\tdepth=" );
308  DTRACE_CABAC_V( uiDepth );
309  DTRACE_CABAC_T( "\ttrdepth=" );
310  DTRACE_CABAC_V( pcCU->getTransformIdx( uiAbsPartIdx ) );
311  DTRACE_CABAC_T( "\n" );
312  }
313 
314  if( !pcCU->isIntra(uiAbsPartIdx) && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && (!bChroma || (!pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cb, 0 ) && !pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cr, 0 ) ) ) )
315  {
316  assert( pcCU->getCbf( uiAbsPartIdx, COMPONENT_Y, 0 ) );
317  // printf( "saved one bin! " );
318  }
319  else
320  {
321  m_pcEntropyCoderIf->codeQtCbf( rTu, COMPONENT_Y, true ); //luma CBF is always at the lowest level
322  }
323 
324  if ( bHaveACodedBlock )
325  {
326  // dQP: only for CTU once
327  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
328  {
329  if ( bCodeDQP )
330  {
331  encodeQP( pcCU, rTu.GetAbsPartIdxCU() );
332  bCodeDQP = false;
333  }
334  }
335 
336  if ( pcCU->getSlice()->getUseChromaQpAdj() )
337  {
338  if ( bHaveACodedChromaBlock && codeChromaQpAdj && !pcCU->getCUTransquantBypass(rTu.GetAbsPartIdxCU()) )
339  {
341  codeChromaQpAdj = false;
342  }
343  }
344 
345  const UInt numValidComp=pcCU->getPic()->getNumberValidComponents();
346 
347  for(UInt ch=COMPONENT_Y; ch<numValidComp; ch++)
348  {
349  const ComponentID compID=ComponentID(ch);
350 
351  if (rTu.ProcessComponentSection(compID))
352  {
353 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
354  if (bDebugRQT)
355  {
356  printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, rTu.getRect(compID).width, rTu.getRect(compID).height, 1);
357  }
358 #endif
359 
360  if (rTu.getRect(compID).width != rTu.getRect(compID).height)
361  {
362  //code two sub-TUs
363  TComTURecurse subTUIterator(rTu, false, TComTU::VERTICAL_SPLIT, true, compID);
364 
365  do
366  {
367  const UChar subTUCBF = pcCU->getCbf(subTUIterator.GetAbsPartIdxTU(compID), compID, (uiTrIdx + 1));
368 
369  if (subTUCBF != 0)
370  {
371 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
372  if (bDebugRQT)
373  {
374  printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, subTUIterator.getRect(compID).width, subTUIterator.getRect(compID).height, 1);
375  }
376 #endif
377  m_pcEntropyCoderIf->codeCoeffNxN( subTUIterator, (pcCU->getCoeff(compID) + subTUIterator.getCoefficientOffset(compID)), compID );
378  }
379  }
380  while (subTUIterator.nextSection(rTu));
381  }
382  else
383  {
384  if (isChroma(compID) && (cbf[COMPONENT_Y] != 0))
385  {
387  }
388 
389  if (cbf[compID] != 0)
390  {
391  m_pcEntropyCoderIf->codeCoeffNxN( rTu, (pcCU->getCoeff(compID) + rTu.getCoefficientOffset(compID)), compID );
392  }
393  }
394  }
395  }
396  }
397  }
398 }
399 
400 
402 Void TEncEntropy::encodeIntraDirModeLuma ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiplePU )
403 {
404  m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, absPartIdx , isMultiplePU);
405 }
406 
407 
410 {
411  m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx );
412 
413 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
414  if (bDebugPredEnabled && pcCU->getSlice()->getFinalized())
415  {
416  UInt cdir=pcCU->getIntraDir(CHANNEL_TYPE_CHROMA, uiAbsPartIdx);
417  if (cdir==36)
418  {
419  cdir=pcCU->getIntraDir(CHANNEL_TYPE_LUMA, uiAbsPartIdx);
420  }
421  printf("coding chroma Intra dir: %d, uiAbsPartIdx: %d, luma dir: %d\n", cdir, uiAbsPartIdx, pcCU->getIntraDir(CHANNEL_TYPE_LUMA, uiAbsPartIdx));
422  }
423 #endif
424 }
425 
426 
428 {
429  if( pcCU->isIntra( uiAbsPartIdx ) ) // If it is Intra mode, encode intra prediction mode.
430  {
431  encodeIntraDirModeLuma ( pcCU, uiAbsPartIdx,true );
432  if (pcCU->getPic()->getChromaFormat()!=CHROMA_400)
433  {
434  encodeIntraDirModeChroma( pcCU, uiAbsPartIdx );
435 
436  if (enable4ChromaPUsInIntraNxNCU(pcCU->getPic()->getChromaFormat()) && pcCU->getPartitionSize( uiAbsPartIdx )==SIZE_NxN)
437  {
438  UInt uiPartOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2;
439  encodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset );
440  encodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset*2 );
441  encodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset*3 );
442  }
443  }
444  }
445  else // if it is Inter mode, encode motion vector and reference index
446  {
447  encodePUWise( pcCU, uiAbsPartIdx );
448  }
449 }
450 
452 {
454 }
455 
458 {
459 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
460  const Bool bDebugPred = bDebugPredEnabled && pcCU->getSlice()->getFinalized();
461 #endif
462 
463  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
464  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
465  UInt uiDepth = pcCU->getDepth( uiAbsPartIdx );
466  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxTotalCUDepth() - uiDepth ) << 1 ) ) >> 4;
467 
468  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
469  {
470  encodeMergeFlag( pcCU, uiSubPartIdx );
471  if ( pcCU->getMergeFlag( uiSubPartIdx ) )
472  {
473  encodeMergeIndex( pcCU, uiSubPartIdx );
474 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
475  if (bDebugPred)
476  {
477  std::cout << "Coded merge flag, CU absPartIdx: " << uiAbsPartIdx << " PU(" << uiPartIdx << ") absPartIdx: " << uiSubPartIdx;
478  std::cout << " merge index: " << (UInt)pcCU->getMergeIndex(uiSubPartIdx) << std::endl;
479  }
480 #endif
481  }
482  else
483  {
484  encodeInterDirPU( pcCU, uiSubPartIdx );
485  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
486  {
487  if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
488  {
489  encodeRefFrmIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
490  encodeMvdPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
491  encodeMVPIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
492 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
493  if (bDebugPred)
494  {
495  std::cout << "refListIdx: " << uiRefListIdx << std::endl;
496  std::cout << "MVD horizontal: " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getHor() << std::endl;
497  std::cout << "MVD vertical: " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getVer() << std::endl;
498  std::cout << "MVPIdxPU: " << pcCU->getMVPIdx(RefPicList( uiRefListIdx ), uiSubPartIdx) << std::endl;
499  std::cout << "InterDir: " << (UInt)pcCU->getInterDir(uiSubPartIdx) << std::endl;
500  }
501 #endif
502  }
503  }
504  }
505  }
506 
507  return;
508 }
509 
511 {
512  if ( !pcCU->getSlice()->isInterB() )
513  {
514  return;
515  }
516 
517  m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx );
518 
519  return;
520 }
521 
524 {
525  assert( pcCU->isInter( uiAbsPartIdx ) );
526 
527  if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) )
528  {
529  return;
530  }
531 
532  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
533  {
534  m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
535  }
536 
537  return;
538 }
539 
541 Void TEncEntropy::encodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
542 {
543  assert( pcCU->isInter( uiAbsPartIdx ) );
544 
545  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
546  {
547  m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList );
548  }
549  return;
550 }
551 
553 {
554  if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) )
555  {
556  m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList );
557  }
558 
559  return;
560 }
561 
562 Void TEncEntropy::encodeQtCbf( TComTU &rTu, const ComponentID compID, const Bool lowestLevel )
563 {
564  m_pcEntropyCoderIf->codeQtCbf( rTu, compID, lowestLevel );
565 }
566 
568 {
569  m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSymbol, uiCtx );
570 }
571 
573 {
574  m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
575 }
576 
578 {
579  m_pcEntropyCoderIf->codeQtCbfZero( rTu, chType );
580 }
581 
583 {
585 }
586 
587 // dQP
588 Void TEncEntropy::encodeQP( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
589 {
590  if( bRD )
591  {
592  uiAbsPartIdx = 0;
593  }
594 
595  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
596  {
597  m_pcEntropyCoderIf->codeDeltaQP( pcCU, uiAbsPartIdx );
598  }
599 }
600 
603 {
604  if( inRd )
605  {
606  absPartIdx = 0;
607  }
608 
609  m_pcEntropyCoderIf->codeChromaQpAdjustment( cu, absPartIdx );
610 }
611 
612 // texture
613 
615 Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool& bCodeDQP, Bool& codeChromaQpAdj )
616 {
617 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
618  const Bool bDebugRQT=pcCU->getSlice()->getFinalized() && DebugOptionList::DebugRQT.getInt()!=0;
619 #endif
620 
621  if( pcCU->isIntra(uiAbsPartIdx) )
622  {
623  if (false)
624  {
625  DTRACE_CABAC_VL( g_nSymbolCounter++ )
626  DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" )
627  DTRACE_CABAC_V( uiDepth )
628  DTRACE_CABAC_T( "\n" )
629  }
630  }
631  else
632  {
633  if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) )
634  {
635  m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
636  }
637  if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) )
638  {
639  return;
640  }
641  }
642 
643  TComTURecurse tuRecurse(pcCU, uiAbsPartIdx, uiDepth);
644 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
645  if (bDebugRQT)
646  {
647  printf("..codeCoeff: uiAbsPartIdx=%d, PU format=%d, 2Nx2N=%d, NxN=%d\n", uiAbsPartIdx, pcCU->getPartitionSize(uiAbsPartIdx), SIZE_2Nx2N, SIZE_NxN);
648  }
649 #endif
650 
651  xEncodeTransform( bCodeDQP, codeChromaQpAdj, tuRecurse );
652 }
653 
655 {
656  TComDataCU *pcCU = rTu.getCU();
657 
658  if (pcCU->getCbf(rTu.GetAbsPartIdxTU(), compID, rTu.GetTransformDepthRel()) != 0)
659  {
660  if (rTu.getRect(compID).width != rTu.getRect(compID).height)
661  {
662  //code two sub-TUs
663  TComTURecurse subTUIterator(rTu, false, TComTU::VERTICAL_SPLIT, true, compID);
664 
665  const UInt subTUSize = subTUIterator.getRect(compID).width * subTUIterator.getRect(compID).height;
666 
667  do
668  {
669  const UChar subTUCBF = pcCU->getCbf(subTUIterator.GetAbsPartIdxTU(compID), compID, (subTUIterator.GetTransformDepthRel() + 1));
670 
671  if (subTUCBF != 0)
672  {
673  m_pcEntropyCoderIf->codeCoeffNxN( subTUIterator, (pcCoef + (subTUIterator.GetSectionNumber() * subTUSize)), compID);
674  }
675  }
676  while (subTUIterator.nextSection(rTu));
677  }
678  else
679  {
680  m_pcEntropyCoderIf->codeCoeffNxN(rTu, pcCoef, compID);
681  }
682  }
683 }
684 
685 Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, const ChannelType chType, COEFF_SCAN_TYPE scanType )
686 {
687  const UInt heightAtEntropyCoding = (width != height) ? (height >> 1) : height;
688 
689  m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, width, heightAtEntropyCoding, chType, scanType );
690 }
691 
693 {
694  Int count = 0;
695 
696  for ( Int i = 0; i < uiSize; i++ )
697  {
698  count += pcCoef[i] != 0;
699  }
700 
701  return count;
702 }
703 
virtual Void codeMVPIdx(TComDataCU *pcCU, UInt uiAbsPartIdx, RefPicList eRefList)=0
UInt getQuadtreeTULog2MinSizeInCU(UInt uiIdx) const
static Bool isChromaEnabled(const ChromaFormat fmt)
Void encodeMergeFlag(TComDataCU *pcCU, UInt uiAbsPartIdx)
encode merge flag
sample adaptive offset class (header)
entropy encoder class (header)
Void encodeSPS(const TComSPS *pcSPS)
Definition: TEncEntropy.cpp:85
static Int countNonZeroCoeffs(TCoeff *pcCoef, UInt uiSize)
Int getMVPIdx(RefPicList eRefPicList, UInt uiIdx) const
Definition: TComDataCU.h:378
SChar * getPartitionSize()
Definition: TComDataCU.h:226
CU data structure class.
Definition: TComDataCU.h:64
ChannelType
Definition: TypeDef.h:301
Void encodeMvdPU(TComDataCU *pcSubCU, UInt uiAbsPartIdx, RefPicList eRefList)
encode motion vector difference for a PU block
Int getHor() const
Definition: TComMv.h:88
Int getInt() const
Definition: Debug.h:84
Defines version information, constants and small in-line functions.
virtual Void codeDeltaQP(TComDataCU *pcCU, UInt uiAbsPartIdx)=0
void Void
Definition: TypeDef.h:203
virtual Void codeCrossComponentPrediction(TComTU &rTu, ComponentID compID)=0
virtual Void codeQtRootCbfZero()=0
Void encodeTransformSubdivFlag(UInt uiSymbol, UInt uiCtx)
UChar * getTransformIdx()
Definition: TComDataCU.h:277
Void encodeChromaQpAdjustment(TComDataCU *pcCU, UInt uiAbsPartIdx, Bool bRD=false)
encode chroma qp adjustment
UChar getQtRootCbf(UInt uiIdx) const
Void encodePredMode(TComDataCU *pcCU, UInt uiAbsPartIdx, Bool bRD=false)
encode prediction mode
virtual Void codeSkipFlag(TComDataCU *pcCU, UInt uiAbsPartIdx)=0
Bool getUseChromaQpAdj() const
Definition: TComSlice.h:1364
Void encodeSplitFlag(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD=false)
encode split flag
virtual Void codeRefFrmIdx(TComDataCU *pcCU, UInt uiAbsPartIdx, RefPicList eRefList)=0
Void encodeSliceHeader(TComSlice *pcSlice)
Definition: TEncEntropy.cpp:56
unsigned int UInt
Definition: TypeDef.h:212
UInt getNumPartitionsInCtu() const
Definition: TComPic.h:130
virtual Void codeSPS(const TComSPS *pcSPS)=0
virtual Void codeCoeffNxN(TComTU &rTu, TCoeff *pcCoef, const ComponentID compID)=0
UInt getPCMLog2MaxSize() const
Definition: TComSlice.h:865
virtual Void codeCUTransquantBypassFlag(TComDataCU *pcCU, UInt uiAbsPartIdx)=0
UInt GetTransformDepthRel() const
Definition: TComTU.h:108
Int getNumberValidComponents() const
Definition: TComPic.h:140
TComMv const & getMvd(Int iIdx) const
UChar getCbf(UInt uiIdx, ComponentID eType) const
Definition: TComDataCU.h:307
UChar * getMergeIndex()
Definition: TComDataCU.h:330
virtual Void codeVPS(const TComVPS *pcVPS)=0
virtual Void codeIPCMInfo(TComDataCU *pcCU, UInt uiAbsPartIdx)=0
Bool nextSection(const TComTU &parent)
Definition: TComTU.cpp:178
UChar * getInterDir()
Definition: TComDataCU.h:350
virtual Void codePartSize(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)=0
Int getNumRefIdx(RefPicList e) const
Definition: TComSlice.h:1370
Void encodeQP(TComDataCU *pcCU, UInt uiAbsPartIdx, Bool bRD=false)
UInt GetSectionNumber() const
Definition: TComTU.h:101
Bool isInterB() const
Definition: TComSlice.h:1424
Bool isInter(UInt uiPartIdx) const
Definition: TComDataCU.h:451
Void encodeRefFrmIdxPU(TComDataCU *pcSubCU, UInt uiAbsPartIdx, RefPicList eRefList)
encode reference frame index for a PU block
UInt GetAbsPartIdxTU() const
Definition: TComTU.h:119
Void encodeCoeffNxN(TComTU &rTu, TCoeff *pcCoef, const ComponentID compID)
UInt getMaxTotalCUDepth() const
Definition: TComSlice.h:861
virtual Void codeTilesWPPEntryPoint(TComSlice *pSlice)=0
PartSize
supported partition shape
Definition: TypeDef.h:348
virtual Void codeQtCbfZero(TComTU &rTu, const ChannelType chType)=0
const UInt g_auiPUOffset[NUMBER_OF_PART_SIZES]
Definition: TComRom.cpp:289
Void xEncodeTransform(Bool &bCodeDQP, Bool &codeChromaQpAdj, TComTU &rTu)
static Bool enable4ChromaPUsInIntraNxNCU(const ChromaFormat chFmt)
Void encodePUWise(TComDataCU *pcCU, UInt uiAbsPartIdx)
encode motion information for every PU block
UChar * getIntraDir(const ChannelType channelType) const
Definition: TComDataCU.h:342
virtual Void codeSliceFinish()=0
symmetric motion partition, 2Nx2N
Definition: TypeDef.h:350
Void encodeCoeff(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool &bCodeDQP, Bool &codeChromaQpAdj)
encode coefficients
bool Bool
Definition: TypeDef.h:204
Bool isIntra(UInt uiPartIdx) const
Definition: TComDataCU.h:450
Void estimateBit(estBitsSbacStruct *pcEstBitsSbac, Int width, Int height, ChannelType chType, COEFF_SCAN_TYPE scanType)
Void encodeIPCMInfo(TComDataCU *pcCU, UInt uiAbsPartIdx, Bool bRD=false)
Void encodeSliceFinish()
Definition: TEncEntropy.cpp:74
virtual Void codeMvd(TComDataCU *pcCU, UInt uiAbsPartIdx, RefPicList eRefList)=0
Void encodeQtCbfZero(TComTU &rTu, const ChannelType chType)
PPS class.
Definition: TComSlice.h:1034
virtual Void codeMergeIndex(TComDataCU *pcCU, UInt uiAbsPartIdx)=0
UInt getPCMLog2MinSize() const
Definition: TComSlice.h:867
virtual Void codeSliceHeader(TComSlice *pcSlice)=0
Bool ProcessingAllQuadrants(const ComponentID compID) const
Definition: TComTU.h:98
Int TCoeff
transform coefficient
Definition: TypeDef.h:250
virtual Void estBit(estBitsSbacStruct *pcEstBitsSbac, Int width, Int height, ChannelType chType, COEFF_SCAN_TYPE scanType)=0
Bool getUseDQP() const
Definition: TComSlice.h:1099
RefPicList
reference list index
Definition: TypeDef.h:370
UInt GetLog2LumaTrSize() const
Definition: TComTU.h:130
UInt getCoefficientOffset(const ComponentID compID) const
Definition: TComTU.h:94
#define DTRACE_CABAC_VL(x)
Definition: TComRom.h:153
unsigned char UChar
Definition: TypeDef.h:208
UInt getQuadtreeTULog2MinSize() const
Definition: TComSlice.h:875
const TComRectangle & getRect(const ComponentID compID) const
Definition: TComTU.h:96
COEFF_SCAN_TYPE
coefficient scanning type used in ACS
Definition: TypeDef.h:473
UChar * getDepth()
Definition: TComDataCU.h:210
virtual Void codeChromaQpAdjustment(TComDataCU *pcCU, UInt uiAbsPartIdx)=0
const TComPPS * getPPS() const
Definition: TComSlice.h:1332
Void encodePPS(const TComPPS *pcPPS)
Definition: TEncEntropy.cpp:79
Int getVer() const
Definition: TComMv.h:89
entropy encoder pure class
Definition: TEncEntropy.h:59
ChromaFormat getChromaFormat() const
Definition: TComPic.h:139
virtual Void codeQtCbf(TComTU &rTu, const ComponentID compID, const Bool lowestLevel)=0
Bool isIntra() const
Definition: TComSlice.h:1423
TComDataCU * getCU()
Definition: TComTU.h:126
#define DTRACE_CABAC_T(x)
Definition: TComRom.h:154
Void encodeQtRootCbf(TComDataCU *pcCU, UInt uiAbsPartIdx)
Void encodeIntraDirModeChroma(TComDataCU *pcCU, UInt uiAbsPartIdx)
encode intra direction for chroma
virtual Void codeQtRootCbf(TComDataCU *pcCU, UInt uiAbsPartIdx)=0
virtual Void codeTransformSubdivFlag(UInt uiSymbol, UInt uiCtx)=0
Bool ProcessComponentSection(const ComponentID compID) const
Definition: TComTU.h:99
virtual Void codeSplitFlag(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)=0
Void encodeTilesWPPEntryPoint(TComSlice *pSlice)
Definition: TEncEntropy.cpp:62
Bool * getCUTransquantBypass()
Definition: TComDataCU.h:245
Bool getUsePCM() const
Definition: TComSlice.h:863
TComPic * getPic()
Definition: TComDataCU.h:200
Bool getFinalized() const
Definition: TComSlice.h:1500
Void setEntropyCoder(TEncEntropyIf *e)
Definition: TEncEntropy.cpp:51
Void encodeInterDirPU(TComDataCU *pcSubCU, UInt uiAbsPartIdx)
Definition: TComTU.h:48
virtual Void codeIntraDirChroma(TComDataCU *pcCU, UInt uiAbsPartIdx)=0
Void encodeCrossComponentPrediction(TComTU &rTu, ComponentID compID)
virtual Void codePredMode(TComDataCU *pcCU, UInt uiAbsPartIdx)=0
Void encodeQtCbf(TComTU &rTu, const ComponentID compID, const Bool lowestLevel)
Void encodeCUTransquantBypassFlag(TComDataCU *pcCU, UInt uiAbsPartIdx, Bool bRD=false)
Definition: TEncEntropy.cpp:91
Void encodePartSize(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD=false)
encode partition size
TComCUMvField * getCUMvField(RefPicList e)
Definition: TComDataCU.h:297
UChar * getWidth()
Definition: TComDataCU.h:248
TCoeff * getCoeff(ComponentID component)
Definition: TComDataCU.h:300
#define DTRACE_CABAC_V(x)
Definition: TComRom.h:152
int Int
Definition: TypeDef.h:211
static Bool isChroma(const ComponentID id)
UInt getQuadtreeTULog2MaxSize() const
Definition: TComSlice.h:873
Void encodeIntraDirModeLuma(TComDataCU *pcCU, UInt absPartIdx, Bool isMultiplePU=false)
encode intra direction for luma
ComponentID
Definition: TypeDef.h:308
UInt GetAbsPartIdxCU() const
Definition: TComTU.h:116
Bool * getMergeFlag()
Definition: TComDataCU.h:325
Void encodeMergeIndex(TComDataCU *pcCU, UInt uiAbsPartIdx, Bool bRD=false)
encode merge index
Void encodeTerminatingBit(UInt uiIsLast)
Definition: TEncEntropy.cpp:67
virtual Void codeMergeFlag(TComDataCU *pcCU, UInt uiAbsPartIdx)=0
symmetric motion partition, Nx N
Definition: TypeDef.h:353
virtual Void codeIntraDirLumaAng(TComDataCU *pcCU, UInt uiAbsPartIdx, Bool isMultiplePU)=0
Void encodeQtRootCbfZero()
UInt getQuadtreeTUMaxDepthInter() const
Definition: TComSlice.h:878
Void encodePredInfo(TComDataCU *pcCU, UInt uiAbsPartIdx)
Void encodeSkipFlag(TComDataCU *pcCU, UInt uiAbsPartIdx, Bool bRD=false)
slice header class
Definition: TComSlice.h:1225
Void encodeMVPIdxPU(TComDataCU *pcSubCU, UInt uiAbsPartIdx, RefPicList eRefList)
virtual Void codeTerminatingBit(UInt uilsLast)=0
virtual Void codePPS(const TComPPS *pcPPS)=0
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
Void encodeVPS(const TComVPS *pcVPS)
TEncEntropyIf * m_pcEntropyCoderIf
Definition: TEncEntropy.h:130
virtual Void codeInterDir(TComDataCU *pcCU, UInt uiAbsPartIdx)=0