HEVC Test Model (HM)  HM-16.3
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-2015, ITU/ISO/IEC
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18  * be used to endorse or promote products derived from this software without
19  * specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31  * THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
38 #include "TEncEntropy.h"
39 #include "TLibCommon/TypeDef.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  m_pcEntropyCoderIf->setSlice ( pcSlice );
55 }
56 
58 {
60  return;
61 }
62 
64 {
66 }
67 
69 {
71 
72  return;
73 }
74 
76 {
78 }
79 
81 {
82  m_pcEntropyCoderIf->codePPS( pcPPS );
83  return;
84 }
85 
87 {
88  m_pcEntropyCoderIf->codeSPS( pcSPS );
89  return;
90 }
91 
93 {
94  if( bRD )
95  {
96  uiAbsPartIdx = 0;
97  }
98  m_pcEntropyCoderIf->codeCUTransquantBypassFlag( pcCU, uiAbsPartIdx );
99 }
100 
102 {
103  m_pcEntropyCoderIf->codeVPS( pcVPS );
104  return;
105 }
106 
108 {
109  if ( pcCU->getSlice()->isIntra() )
110  {
111  return;
112  }
113  if( bRD )
114  {
115  uiAbsPartIdx = 0;
116  }
117  m_pcEntropyCoderIf->codeSkipFlag( pcCU, uiAbsPartIdx );
118 }
119 
122 {
123  // at least one merge candidate exists
124  m_pcEntropyCoderIf->codeMergeFlag( pcCU, uiAbsPartIdx );
125 }
126 
129 {
130  if( bRD )
131  {
132  uiAbsPartIdx = 0;
133  assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
134  }
135  m_pcEntropyCoderIf->codeMergeIndex( pcCU, uiAbsPartIdx );
136 }
137 
138 
141 {
142  if( bRD )
143  {
144  uiAbsPartIdx = 0;
145  }
146 
147  if ( pcCU->getSlice()->isIntra() )
148  {
149  return;
150  }
151 
152  m_pcEntropyCoderIf->codePredMode( pcCU, uiAbsPartIdx );
153 }
154 
156 Void TEncEntropy::encodeSplitFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD )
157 {
158  if( bRD )
159  {
160  uiAbsPartIdx = 0;
161  }
162 
163  m_pcEntropyCoderIf->codeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
164 }
165 
167 Void TEncEntropy::encodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD )
168 {
169  if( bRD )
170  {
171  uiAbsPartIdx = 0;
172  }
173 
174  m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth );
175 }
176 
177 
184 {
185  if(!pcCU->getSlice()->getSPS()->getUsePCM()
186  || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize())
187  || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()))
188  {
189  return;
190  }
191 
192  if( bRD )
193  {
194  uiAbsPartIdx = 0;
195  }
196 
197  m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx );
198 
199 }
200 
201 Void TEncEntropy::xEncodeTransform( Bool& bCodeDQP, Bool& codeChromaQpAdj, TComTU &rTu )
202 {
203 //pcCU, absPartIdxCU, uiAbsPartIdx, uiDepth+1, uiTrIdx+1, quadrant,
204  TComDataCU *pcCU=rTu.getCU();
205  const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU();
206  const UInt numValidComponent = pcCU->getPic()->getNumberValidComponents();
207  const Bool bChroma = isChromaEnabled(pcCU->getPic()->getChromaFormat());
208  const UInt uiTrIdx = rTu.GetTransformDepthRel();
209  const UInt uiDepth = rTu.GetTransformDepthTotal();
210 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
211  const Bool bDebugRQT=g_bFinalEncode && DebugOptionList::DebugRQT.getInt()!=0;
212  if (bDebugRQT)
213  {
214  printf("x..codeTransform: offsetLuma=%d offsetChroma=%d absPartIdx=%d, uiDepth=%d\n width=%d, height=%d, uiTrIdx=%d, uiInnerQuadIdx=%d\n",
216  }
217 #endif
218  const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) > uiTrIdx;// + pcCU->getDepth( uiAbsPartIdx ) > uiDepth;
219  const UInt uiLog2TrafoSize = rTu.GetLog2LumaTrSize();
220 
221 
222  UInt cbf[MAX_NUM_COMPONENT] = {0,0,0};
223  Bool bHaveACodedBlock = false;
224  Bool bHaveACodedChromaBlock = false;
225 
226  for(UInt ch=0; ch<numValidComponent; ch++)
227  {
228  const ComponentID compID = ComponentID(ch);
229 
230  cbf[compID] = pcCU->getCbf( uiAbsPartIdx, compID , uiTrIdx );
231 
232  if (cbf[ch] != 0)
233  {
234  bHaveACodedBlock = true;
235  if (isChroma(compID))
236  {
237  bHaveACodedChromaBlock = true;
238  }
239  }
240  }
241 
242  if( pcCU->isIntra(uiAbsPartIdx) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
243  {
244  assert( uiSubdiv );
245  }
246  else if( pcCU->isInter(uiAbsPartIdx) && (pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N) && uiDepth == pcCU->getDepth(uiAbsPartIdx) && (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) )
247  {
248  if ( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
249  {
250  assert( uiSubdiv );
251  }
252  else
253  {
254  assert(!uiSubdiv );
255  }
256  }
257  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
258  {
259  assert( uiSubdiv );
260  }
261  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
262  {
263  assert( !uiSubdiv );
264  }
265  else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
266  {
267  assert( !uiSubdiv );
268  }
269  else
270  {
271  assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
272  m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
273  }
274 
275  const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx );
276  const Bool bFirstCbfOfCU = uiTrDepthCurr == 0;
277 
278  for(UInt ch=COMPONENT_Cb; ch<numValidComponent; ch++)
279  {
280  const ComponentID compID=ComponentID(ch);
281  if( bFirstCbfOfCU || rTu.ProcessingAllQuadrants(compID) )
282  {
283  if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, compID, uiTrDepthCurr - 1 ) )
284  {
285  m_pcEntropyCoderIf->codeQtCbf( rTu, compID, (uiSubdiv == 0) );
286  }
287  }
288  else
289  {
290  assert( pcCU->getCbf( uiAbsPartIdx, compID, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, compID, uiTrDepthCurr - 1 ) );
291  }
292  }
293 
294  if( uiSubdiv )
295  {
296  TComTURecurse tuRecurseChild(rTu, true);
297  do
298  {
299  xEncodeTransform( bCodeDQP, codeChromaQpAdj, tuRecurseChild );
300  } while (tuRecurseChild.nextSection(rTu));
301  }
302  else
303  {
304  {
306  DTRACE_CABAC_T( "\tTrIdx: abspart=" );
307  DTRACE_CABAC_V( uiAbsPartIdx );
308  DTRACE_CABAC_T( "\tdepth=" );
309  DTRACE_CABAC_V( uiDepth );
310  DTRACE_CABAC_T( "\ttrdepth=" );
311  DTRACE_CABAC_V( pcCU->getTransformIdx( uiAbsPartIdx ) );
312  DTRACE_CABAC_T( "\n" );
313  }
314 
315  if( !pcCU->isIntra(uiAbsPartIdx) && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && (!bChroma || (!pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cb, 0 ) && !pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cr, 0 ) ) ) )
316  {
317  assert( pcCU->getCbf( uiAbsPartIdx, COMPONENT_Y, 0 ) );
318  // printf( "saved one bin! " );
319  }
320  else
321  {
322  m_pcEntropyCoderIf->codeQtCbf( rTu, COMPONENT_Y, true ); //luma CBF is always at the lowest level
323  }
324 
325  if ( bHaveACodedBlock )
326  {
327  // dQP: only for CTU once
328  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
329  {
330  if ( bCodeDQP )
331  {
332  encodeQP( pcCU, rTu.GetAbsPartIdxCU() );
333  bCodeDQP = false;
334  }
335  }
336 
337  if ( pcCU->getSlice()->getUseChromaQpAdj() )
338  {
339  if ( bHaveACodedChromaBlock && codeChromaQpAdj && !pcCU->getCUTransquantBypass(rTu.GetAbsPartIdxCU()) )
340  {
342  codeChromaQpAdj = false;
343  }
344  }
345 
346  const UInt numValidComp=pcCU->getPic()->getNumberValidComponents();
347 
348  for(UInt ch=COMPONENT_Y; ch<numValidComp; ch++)
349  {
350  const ComponentID compID=ComponentID(ch);
351 
352  if (rTu.ProcessComponentSection(compID))
353  {
354 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
355  if (bDebugRQT)
356  {
357  printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, rTu.getRect(compID).width, rTu.getRect(compID).height, 1);
358  }
359 #endif
360 
361  if (rTu.getRect(compID).width != rTu.getRect(compID).height)
362  {
363  //code two sub-TUs
364  TComTURecurse subTUIterator(rTu, false, TComTU::VERTICAL_SPLIT, true, compID);
365 
366  do
367  {
368  const UChar subTUCBF = pcCU->getCbf(subTUIterator.GetAbsPartIdxTU(compID), compID, (uiTrIdx + 1));
369 
370  if (subTUCBF != 0)
371  {
372 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
373  if (bDebugRQT)
374  {
375  printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, subTUIterator.getRect(compID).width, subTUIterator.getRect(compID).height, 1);
376  }
377 #endif
378  m_pcEntropyCoderIf->codeCoeffNxN( subTUIterator, (pcCU->getCoeff(compID) + subTUIterator.getCoefficientOffset(compID)), compID );
379  }
380  }
381  while (subTUIterator.nextSection(rTu));
382  }
383  else
384  {
385  if (isChroma(compID) && (cbf[COMPONENT_Y] != 0))
386  {
388  }
389 
390  if (cbf[compID] != 0)
391  {
392  m_pcEntropyCoderIf->codeCoeffNxN( rTu, (pcCU->getCoeff(compID) + rTu.getCoefficientOffset(compID)), compID );
393  }
394  }
395  }
396  }
397  }
398  }
399 }
400 
401 
403 Void TEncEntropy::encodeIntraDirModeLuma ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiplePU )
404 {
405  m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, absPartIdx , isMultiplePU);
406 }
407 
408 
411 {
412  m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx );
413 
414 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
415  if (bDebugPredEnabled && g_bFinalEncode)
416  {
417  UInt cdir=pcCU->getIntraDir(CHANNEL_TYPE_CHROMA, uiAbsPartIdx);
418  if (cdir==36)
419  {
420  cdir=pcCU->getIntraDir(CHANNEL_TYPE_LUMA, uiAbsPartIdx);
421  }
422  printf("coding chroma Intra dir: %d, uiAbsPartIdx: %d, luma dir: %d\n", cdir, uiAbsPartIdx, pcCU->getIntraDir(CHANNEL_TYPE_LUMA, uiAbsPartIdx));
423  }
424 #endif
425 }
426 
427 
429 {
430  if( pcCU->isIntra( uiAbsPartIdx ) ) // If it is Intra mode, encode intra prediction mode.
431  {
432  encodeIntraDirModeLuma ( pcCU, uiAbsPartIdx,true );
433  if (pcCU->getPic()->getChromaFormat()!=CHROMA_400)
434  {
435  encodeIntraDirModeChroma( pcCU, uiAbsPartIdx );
436 
437  if (enable4ChromaPUsInIntraNxNCU(pcCU->getPic()->getChromaFormat()) && pcCU->getPartitionSize( uiAbsPartIdx )==SIZE_NxN)
438  {
439  UInt uiPartOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2;
440  encodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset );
441  encodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset*2 );
442  encodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset*3 );
443  }
444  }
445  }
446  else // if it is Inter mode, encode motion vector and reference index
447  {
448  encodePUWise( pcCU, uiAbsPartIdx );
449  }
450 }
451 
453 {
455 }
456 
459 {
460 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
461  const Bool bDebugPred = bDebugPredEnabled && g_bFinalEncode;
462 #endif
463 
464  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
465  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
466  UInt uiDepth = pcCU->getDepth( uiAbsPartIdx );
467  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
468 
469  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
470  {
471  encodeMergeFlag( pcCU, uiSubPartIdx );
472  if ( pcCU->getMergeFlag( uiSubPartIdx ) )
473  {
474  encodeMergeIndex( pcCU, uiSubPartIdx );
475 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
476  if (bDebugPred)
477  {
478  std::cout << "Coded merge flag, CU absPartIdx: " << uiAbsPartIdx << " PU(" << uiPartIdx << ") absPartIdx: " << uiSubPartIdx;
479  std::cout << " merge index: " << (UInt)pcCU->getMergeIndex(uiSubPartIdx) << std::endl;
480  }
481 #endif
482  }
483  else
484  {
485  encodeInterDirPU( pcCU, uiSubPartIdx );
486  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
487  {
488  if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
489  {
490  encodeRefFrmIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
491  encodeMvdPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
492  encodeMVPIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
493 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
494  if (bDebugPred)
495  {
496  std::cout << "refListIdx: " << uiRefListIdx << std::endl;
497  std::cout << "MVD horizontal: " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getHor() << std::endl;
498  std::cout << "MVD vertical: " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getVer() << std::endl;
499  std::cout << "MVPIdxPU: " << pcCU->getMVPIdx(RefPicList( uiRefListIdx ), uiSubPartIdx) << std::endl;
500  std::cout << "InterDir: " << (UInt)pcCU->getInterDir(uiSubPartIdx) << std::endl;
501  }
502 #endif
503  }
504  }
505  }
506  }
507 
508  return;
509 }
510 
512 {
513  if ( !pcCU->getSlice()->isInterB() )
514  {
515  return;
516  }
517 
518  m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx );
519 
520  return;
521 }
522 
525 {
526  assert( pcCU->isInter( uiAbsPartIdx ) );
527 
528  if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) )
529  {
530  return;
531  }
532 
533  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
534  {
535  m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
536  }
537 
538  return;
539 }
540 
542 Void TEncEntropy::encodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
543 {
544  assert( pcCU->isInter( uiAbsPartIdx ) );
545 
546  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
547  {
548  m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList );
549  }
550  return;
551 }
552 
554 {
555  if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) )
556  {
557  m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList );
558  }
559 
560  return;
561 }
562 
563 Void TEncEntropy::encodeQtCbf( TComTU &rTu, const ComponentID compID, const Bool lowestLevel )
564 {
565  m_pcEntropyCoderIf->codeQtCbf( rTu, compID, lowestLevel );
566 }
567 
569 {
570  m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSymbol, uiCtx );
571 }
572 
574 {
575  m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
576 }
577 
579 {
580  m_pcEntropyCoderIf->codeQtCbfZero( rTu, chType );
581 }
582 
584 {
586 }
587 
588 // dQP
589 Void TEncEntropy::encodeQP( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
590 {
591  if( bRD )
592  {
593  uiAbsPartIdx = 0;
594  }
595 
596  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
597  {
598  m_pcEntropyCoderIf->codeDeltaQP( pcCU, uiAbsPartIdx );
599  }
600 }
601 
604 {
605  if( inRd )
606  {
607  absPartIdx = 0;
608  }
609 
610  m_pcEntropyCoderIf->codeChromaQpAdjustment( cu, absPartIdx );
611 }
612 
613 // texture
614 
616 Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool& bCodeDQP, Bool& codeChromaQpAdj )
617 {
618 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
619  const Bool bDebugRQT=g_bFinalEncode && DebugOptionList::DebugRQT.getInt()!=0;
620 #endif
621 
622  if( pcCU->isIntra(uiAbsPartIdx) )
623  {
624  if (false)
625  {
627  DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" )
628  DTRACE_CABAC_V( uiDepth )
629  DTRACE_CABAC_T( "\n" )
630  }
631  }
632  else
633  {
634  if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) )
635  {
636  m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
637  }
638  if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) )
639  {
640  return;
641  }
642  }
643 
644  TComTURecurse tuRecurse(pcCU, uiAbsPartIdx, uiDepth);
645 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
646  if (bDebugRQT)
647  {
648  printf("..codeCoeff: uiAbsPartIdx=%d, PU format=%d, 2Nx2N=%d, NxN=%d\n", uiAbsPartIdx, pcCU->getPartitionSize(uiAbsPartIdx), SIZE_2Nx2N, SIZE_NxN);
649  }
650 #endif
651 
652  xEncodeTransform( bCodeDQP, codeChromaQpAdj, tuRecurse );
653 }
654 
656 {
657  TComDataCU *pcCU = rTu.getCU();
658 
659  if (pcCU->getCbf(rTu.GetAbsPartIdxTU(), compID, rTu.GetTransformDepthRel()) != 0)
660  {
661  if (rTu.getRect(compID).width != rTu.getRect(compID).height)
662  {
663  //code two sub-TUs
664  TComTURecurse subTUIterator(rTu, false, TComTU::VERTICAL_SPLIT, true, compID);
665 
666  const UInt subTUSize = subTUIterator.getRect(compID).width * subTUIterator.getRect(compID).height;
667 
668  do
669  {
670  const UChar subTUCBF = pcCU->getCbf(subTUIterator.GetAbsPartIdxTU(compID), compID, (subTUIterator.GetTransformDepthRel() + 1));
671 
672  if (subTUCBF != 0)
673  {
674  m_pcEntropyCoderIf->codeCoeffNxN( subTUIterator, (pcCoef + (subTUIterator.GetSectionNumber() * subTUSize)), compID);
675  }
676  }
677  while (subTUIterator.nextSection(rTu));
678  }
679  else
680  {
681  m_pcEntropyCoderIf->codeCoeffNxN(rTu, pcCoef, compID);
682  }
683  }
684 }
685 
686 Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, const ChannelType chType)
687 {
688  const UInt heightAtEntropyCoding = (width != height) ? (height >> 1) : height;
689 
690  m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, width, heightAtEntropyCoding, chType );
691 }
692 
694 {
695  Int count = 0;
696 
697  for ( Int i = 0; i < uiSize; i++ )
698  {
699  count += pcCoef[i] != 0;
700  }
701 
702  return count;
703 }
704 
virtual Void codeMVPIdx(TComDataCU *pcCU, UInt uiAbsPartIdx, RefPicList eRefList)=0
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:86
Void estimateBit(estBitsSbacStruct *pcEstBitsSbac, Int width, Int height, ChannelType chType)
static Int countNonZeroCoeffs(TCoeff *pcCoef, UInt uiSize)
CU data structure class.
Definition: TComDataCU.h:64
ChannelType
Definition: TypeDef.h:361
Bool g_bFinalEncode
Void encodeMvdPU(TComDataCU *pcSubCU, UInt uiAbsPartIdx, RefPicList eRefList)
encode motion vector difference for a PU block
UChar getQtRootCbf(UInt uiIdx)
Int getHor() const
Definition: TComMv.h:88
Int getInt() const
Definition: Debug.h:84
virtual Void codeDeltaQP(TComDataCU *pcCU, UInt uiAbsPartIdx)=0
void Void
Definition: TypeDef.h:285
virtual Void codeCrossComponentPrediction(TComTU &rTu, ComponentID compID)=0
Void encodeTransformSubdivFlag(UInt uiSymbol, UInt uiCtx)
UChar * getTransformIdx()
Definition: TComDataCU.h:274
Void encodeChromaQpAdjustment(TComDataCU *pcCU, UInt uiAbsPartIdx, Bool bRD=false)
encode chroma qp adjustment
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:1347
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:57
unsigned int UInt
Definition: TypeDef.h:297
UInt getNumPartitionsInCtu() const
Definition: TComPic.h:119
virtual Void codeQtRootCbfZero(TComDataCU *pcCU)=0
virtual Void codeSPS(const TComSPS *pcSPS)=0
virtual Void codeCoeffNxN(TComTU &rTu, TCoeff *pcCoef, const ComponentID compID)=0
Void setEntropyCoder(TEncEntropyIf *e, TComSlice *pcSlice)
Definition: TEncEntropy.cpp:51
UInt getPCMLog2MaxSize() const
Definition: TComSlice.h:853
Void encodeQtRootCbfZero(TComDataCU *pcCU)
virtual Void codeCUTransquantBypassFlag(TComDataCU *pcCU, UInt uiAbsPartIdx)=0
UInt GetTransformDepthRel() const
Definition: TComTU.h:108
Int getNumberValidComponents() const
Definition: TComPic.h:129
UInt getMaxCUDepth() const
Definition: TComSlice.h:849
UInt g_auiPUOffset[NUMBER_OF_PART_SIZES]
Definition: TComRom.cpp:260
TComMv const & getMvd(Int iIdx) const
UChar * getMergeIndex()
Definition: TComDataCU.h:326
virtual Void codeVPS(const TComVPS *pcVPS)=0
virtual Void codeIPCMInfo(TComDataCU *pcCU, UInt uiAbsPartIdx)=0
UInt64 g_nSymbolCounter
Definition: TComRom.cpp:566
Bool nextSection(const TComTU &parent)
Definition: TComTU.cpp:178
UChar * getInterDir()
Definition: TComDataCU.h:346
virtual Void codePartSize(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)=0
Int getNumRefIdx(RefPicList e) const
Definition: TComSlice.h:1353
UChar getCbf(UInt uiIdx, ComponentID eType)
Definition: TComDataCU.h:303
Void encodeQP(TComDataCU *pcCU, UInt uiAbsPartIdx, Bool bRD=false)
UInt GetSectionNumber() const
Definition: TComTU.h:101
Bool isInterB() const
Definition: TComSlice.h:1405
Bool isInter(UInt uiPartIdx) const
Definition: TComDataCU.h:444
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)
virtual Void setSlice(TComSlice *p)=0
virtual Void codeTilesWPPEntryPoint(TComSlice *pSlice)=0
PartSize
supported partition shape
Definition: TypeDef.h:393
virtual Void codeQtCbfZero(TComTU &rTu, const ChannelType chType)=0
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:338
#define DTRACE_CABAC_T(x)
Definition: TComRom.h:197
virtual Void codeSliceFinish()=0
symmetric motion partition, 2Nx2N
Definition: TypeDef.h:395
Void encodeCoeff(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool &bCodeDQP, Bool &codeChromaQpAdj)
encode coefficients
bool Bool
Definition: TypeDef.h:286
Bool isIntra(UInt uiPartIdx) const
Definition: TComDataCU.h:443
Void encodeIPCMInfo(TComDataCU *pcCU, UInt uiAbsPartIdx, Bool bRD=false)
Void encodeSliceFinish()
Definition: TEncEntropy.cpp:75
virtual Void codeMvd(TComDataCU *pcCU, UInt uiAbsPartIdx, RefPicList eRefList)=0
Void encodeQtCbfZero(TComTU &rTu, const ChannelType chType)
PPS class.
Definition: TComSlice.h:977
virtual Void codeMergeIndex(TComDataCU *pcCU, UInt uiAbsPartIdx)=0
UInt getPCMLog2MinSize() const
Definition: TComSlice.h:855
virtual Void codeSliceHeader(TComSlice *pcSlice)=0
Bool ProcessingAllQuadrants(const ComponentID compID) const
Definition: TComTU.h:98
Int TCoeff
transform coefficient
Definition: TypeDef.h:693
Bool getUseDQP() const
Definition: TComSlice.h:1048
RefPicList
reference list index
Definition: TypeDef.h:415
UInt GetLog2LumaTrSize() const
Definition: TComTU.h:130
UInt getCoefficientOffset(const ComponentID compID) const
Definition: TComTU.h:94
unsigned char UChar
Definition: TypeDef.h:293
UInt getQuadtreeTULog2MinSize() const
Definition: TComSlice.h:863
const TComRectangle & getRect(const ComponentID compID) const
Definition: TComTU.h:96
UChar * getDepth()
Definition: TComDataCU.h:213
virtual Void codeChromaQpAdjustment(TComDataCU *pcCU, UInt uiAbsPartIdx)=0
const TComPPS * getPPS() const
Definition: TComSlice.h:1309
#define DTRACE_CABAC_V(x)
Definition: TComRom.h:195
Void encodePPS(const TComPPS *pcPPS)
Definition: TEncEntropy.cpp:80
Int getVer() const
Definition: TComMv.h:89
entropy encoder pure class
Definition: TEncEntropy.h:59
ChromaFormat getChromaFormat() const
Definition: TComPic.h:128
virtual Void codeQtCbf(TComTU &rTu, const ComponentID compID, const Bool lowestLevel)=0
Bool isIntra() const
Definition: TComSlice.h:1404
TComDataCU * getCU()
Definition: TComTU.h:126
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:63
Bool * getCUTransquantBypass()
Definition: TComDataCU.h:242
Bool getUsePCM() const
Definition: TComSlice.h:851
TComPic * getPic()
Definition: TComDataCU.h:203
Int getMVPIdx(RefPicList eRefPicList, UInt uiIdx)
Definition: TComDataCU.h:374
Void encodeInterDirPU(TComDataCU *pcSubCU, UInt uiAbsPartIdx)
Definition: TComTU.h:48
Char * getPartitionSize()
Definition: TComDataCU.h:223
virtual Void codeIntraDirChroma(TComDataCU *pcCU, UInt uiAbsPartIdx)=0
#define DTRACE_CABAC_VL(x)
Definition: TComRom.h:196
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:92
Void encodePartSize(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD=false)
encode partition size
TComCUMvField * getCUMvField(RefPicList e)
Definition: TComDataCU.h:294
UChar * getWidth()
Definition: TComDataCU.h:245
TCoeff * getCoeff(ComponentID component)
Definition: TComDataCU.h:296
int Int
Definition: TypeDef.h:296
static Bool isChroma(const ComponentID id)
UInt getQuadtreeTULog2MaxSize() const
Definition: TComSlice.h:861
virtual Void estBit(estBitsSbacStruct *pcEstBitsSbac, Int width, Int height, ChannelType chType)=0
Void encodeIntraDirModeLuma(TComDataCU *pcCU, UInt absPartIdx, Bool isMultiplePU=false)
encode intra direction for luma
ComponentID
Definition: TypeDef.h:368
UInt GetAbsPartIdxCU() const
Definition: TComTU.h:116
Bool * getMergeFlag()
Definition: TComDataCU.h:321
Void encodeMergeIndex(TComDataCU *pcCU, UInt uiAbsPartIdx, Bool bRD=false)
encode merge index
Void encodeTerminatingBit(UInt uiIsLast)
Definition: TEncEntropy.cpp:68
UInt getQuadtreeTULog2MinSizeInCU(UInt uiIdx)
virtual Void codeMergeFlag(TComDataCU *pcCU, UInt uiAbsPartIdx)=0
symmetric motion partition, Nx N
Definition: TypeDef.h:398
virtual Void codeIntraDirLumaAng(TComDataCU *pcCU, UInt uiAbsPartIdx, Bool isMultiplePU)=0
UInt getQuadtreeTUMaxDepthInter() const
Definition: TComSlice.h:866
Void encodePredInfo(TComDataCU *pcCU, UInt uiAbsPartIdx)
Define basic types, new types and enumerations.
Void encodeSkipFlag(TComDataCU *pcCU, UInt uiAbsPartIdx, Bool bRD=false)
slice header class
Definition: TComSlice.h:1198
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:205
const TComSPS * getSPS() const
Definition: TComSlice.h:1306
SPS class.
Definition: TComSlice.h:722
Void encodeVPS(const TComVPS *pcVPS)
TEncEntropyIf * m_pcEntropyCoderIf
Definition: TEncEntropy.h:135
virtual Void codeInterDir(TComDataCU *pcCU, UInt uiAbsPartIdx)=0