HEVC Test Model (HM)  HM-16.3
TDecEntropy.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 "TDecEntropy.h"
39 #include "TLibCommon/TComTU.h"
41 
42 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
43 #include "../TLibCommon/Debug.h"
44 static const Bool bDebugRQT = DebugOptionList::DebugRQT.getInt()!=0;
45 static const Bool bDebugPredEnabled = DebugOptionList::DebugPred.getInt()!=0;
46 Bool g_bFinalEncode=true;
47 #endif
48 
51 
53 {
55 }
56 
58 
59 Void TDecEntropy::decodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
60 {
61  m_pcEntropyDecoderIf->parseSkipFlag( pcCU, uiAbsPartIdx, uiDepth );
62 }
63 
64 
66 {
67  m_pcEntropyDecoderIf->parseCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth );
68 }
69 
70 
78 Void TDecEntropy::decodeMergeFlag( TComDataCU* pcSubCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
79 {
80  // at least one merge candidate exists
81  m_pcEntropyDecoderIf->parseMergeFlag( pcSubCU, uiAbsPartIdx, uiDepth, uiPUIdx );
82 }
83 
91 Void TDecEntropy::decodeMergeIndex( TComDataCU* pcCU, UInt uiPartIdx, UInt uiAbsPartIdx, UInt uiDepth )
92 {
93  UInt uiMergeIndex = 0;
94  m_pcEntropyDecoderIf->parseMergeIndex( pcCU, uiMergeIndex );
95  pcCU->setMergeIndexSubParts( uiMergeIndex, uiAbsPartIdx, uiPartIdx, uiDepth );
96 }
97 
98 Void TDecEntropy::decodeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
99 {
100  m_pcEntropyDecoderIf->parseSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
101 }
102 
103 Void TDecEntropy::decodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
104 {
105  m_pcEntropyDecoderIf->parsePredMode( pcCU, uiAbsPartIdx, uiDepth );
106 }
107 
108 Void TDecEntropy::decodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
109 {
110  m_pcEntropyDecoderIf->parsePartSize( pcCU, uiAbsPartIdx, uiDepth );
111 }
112 
113 Void TDecEntropy::decodePredInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
114 {
115  if( pcCU->isIntra( uiAbsPartIdx ) ) // If it is Intra mode, encode intra prediction mode.
116  {
117  decodeIntraDirModeLuma ( pcCU, uiAbsPartIdx, uiDepth );
118  if (pcCU->getPic()->getChromaFormat()!=CHROMA_400)
119  {
120  decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth );
121  if (enable4ChromaPUsInIntraNxNCU(pcCU->getPic()->getChromaFormat()) && pcCU->getPartitionSize( uiAbsPartIdx )==SIZE_NxN)
122  {
123  UInt uiPartOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2;
124  decodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset, uiDepth+1 );
125  decodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset*2, uiDepth+1 );
126  decodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset*3, uiDepth+1 );
127  }
128  }
129  }
130  else // if it is Inter mode, encode motion vector and reference index
131  {
132  decodePUWise( pcCU, uiAbsPartIdx, uiDepth, pcSubCU );
133  }
134 }
135 
142 Void TDecEntropy::decodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
143 {
144  if(!pcCU->getSlice()->getSPS()->getUsePCM()
145  || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize())
146  || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()) )
147  {
148  return;
149  }
150 
151  m_pcEntropyDecoderIf->parseIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
152 }
153 
155 {
156  m_pcEntropyDecoderIf->parseIntraDirLumaAng( pcCU, uiAbsPartIdx, uiDepth );
157 }
158 
160 {
161  m_pcEntropyDecoderIf->parseIntraDirChroma( pcCU, uiAbsPartIdx, uiDepth );
162 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
163  if (bDebugPredEnabled)
164  {
165  UInt cdir=pcCU->getIntraDir(CHANNEL_TYPE_CHROMA, uiAbsPartIdx);
166  if (cdir==36)
167  {
168  cdir=pcCU->getIntraDir(CHANNEL_TYPE_LUMA, uiAbsPartIdx);
169  }
170  printf("coding chroma Intra dir: %d, uiAbsPartIdx: %d, luma dir: %d\n", cdir, uiAbsPartIdx, pcCU->getIntraDir(CHANNEL_TYPE_LUMA, uiAbsPartIdx));
171  }
172 #endif
173 }
174 
175 
183 Void TDecEntropy::decodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
184 {
185  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
186  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
187  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
188 
189  TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
190  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
191 
192  for ( UInt ui = 0; ui < pcCU->getSlice()->getMaxNumMergeCand(); ui++ )
193  {
194  uhInterDirNeighbours[ui] = 0;
195  }
196  Int numValidMergeCand = 0;
197  Bool hasMergedCandList = false;
198 
199  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
200  pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 );
201  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
202  {
203  decodeMergeFlag( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
204  if ( pcCU->getMergeFlag( uiSubPartIdx ) )
205  {
206  decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, uiDepth );
207 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
208  if (bDebugPredEnabled)
209  {
210  std::cout << "Coded merge flag, CU absPartIdx: " << uiAbsPartIdx << " PU(" << uiPartIdx << ") absPartIdx: " << uiSubPartIdx;
211  std::cout << " merge index: " << (UInt)pcCU->getMergeIndex(uiSubPartIdx) << std::endl;
212  }
213 #endif
214 
215  UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
216  if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 )
217  {
218  if ( !hasMergedCandList )
219  {
220  pcSubCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); // temporarily set.
221  pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
222  pcSubCU->setPartSizeSubParts( ePartSize, 0, uiDepth ); // restore.
223  hasMergedCandList = true;
224  }
225  }
226  else
227  {
228  uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
229  pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
230  }
231 
232  pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
233 
234  TComMv cTmpMv( 0, 0 );
235  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
236  {
237  if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
238  {
239  pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
240  pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth);
241  pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
242  pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
243 
244  }
245  }
246  }
247  else
248  {
249  decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
250  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
251  {
252  if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
253  {
254  decodeRefFrmIdxPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
255  decodeMvdPU ( pcCU, uiSubPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
256  decodeMVPIdxPU ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
257 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
258  if (bDebugPredEnabled)
259  {
260  std::cout << "refListIdx: " << uiRefListIdx << std::endl;
261  std::cout << "MVD horizontal: " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getHor() << std::endl;
262  std::cout << "MVD vertical: " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getVer() << std::endl;
263  std::cout << "MVPIdxPU: " << pcCU->getMVPIdx(RefPicList( uiRefListIdx ), uiSubPartIdx) << std::endl;
264  std::cout << "InterDir: " << (UInt)pcCU->getInterDir(uiSubPartIdx) << std::endl;
265  }
266 #endif
267  }
268  }
269  }
270 
271  if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) )
272  {
273  pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( TComMv(0,0), ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
274  pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( -1, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
275  pcCU->setInterDirSubParts( 1, uiSubPartIdx, uiPartIdx, uiDepth);
276  }
277  }
278  return;
279 }
280 
288 Void TDecEntropy::decodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx )
289 {
290  UInt uiInterDir;
291 
292  if ( pcCU->getSlice()->isInterP() )
293  {
294  uiInterDir = 1;
295  }
296  else
297  {
298  m_pcEntropyDecoderIf->parseInterDir( pcCU, uiInterDir, uiAbsPartIdx );
299  }
300 
301  pcCU->setInterDirSubParts( uiInterDir, uiAbsPartIdx, uiPartIdx, uiDepth );
302 }
303 
304 Void TDecEntropy::decodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
305 {
306  Int iRefFrmIdx = 0;
307  Int iParseRefFrmIdx = pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList );
308 
309  if ( pcCU->getSlice()->getNumRefIdx( eRefList ) > 1 && iParseRefFrmIdx )
310  {
311  m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, eRefList );
312  }
313  else if ( !iParseRefFrmIdx )
314  {
315  iRefFrmIdx = NOT_VALID;
316  }
317  else
318  {
319  iRefFrmIdx = 0;
320  }
321 
322  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
323  pcCU->getCUMvField( eRefList )->setAllRefIdx( iRefFrmIdx, ePartSize, uiAbsPartIdx, uiDepth, uiPartIdx );
324 }
325 
334 Void TDecEntropy::decodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
335 {
336  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
337  {
338  m_pcEntropyDecoderIf->parseMvd( pcCU, uiAbsPartIdx, uiPartIdx, uiDepth, eRefList );
339  }
340 }
341 
342 Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList )
343 {
344  Int iMVPIdx = -1;
345 
346  TComMv cZeroMv( 0, 0 );
347  TComMv cMv = cZeroMv;
348  Int iRefIdx = -1;
349 
350  TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList );
351  AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo();
352 
353  iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr);
354  cMv = cZeroMv;
355 
356  if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) )
357  {
358  m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx );
359  }
360  pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo);
361  pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth);
362  pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth );
363  if ( iRefIdx >= 0 )
364  {
365  m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, cMv);
366  cMv += pcSubCUMvField->getMvd( uiPartAddr );
367  }
368 
369  PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr );
370  pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx);
371 }
372 
373 Void TDecEntropy::xDecodeTransform ( Bool& bCodeDQP, Bool& isChromaQpAdjCoded, TComTU &rTu, const Int quadtreeTULog2MinSizeInCU )
374 {
375  TComDataCU *pcCU=rTu.getCU();
376  const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU();
377  const UInt uiDepth=rTu.GetTransformDepthTotal();
378  const UInt uiTrDepth = rTu.GetTransformDepthRel();
379 
380  UInt uiSubdiv;
381  const UInt numValidComponent = pcCU->getPic()->getNumberValidComponents();
382  const Bool bChroma = isChromaEnabled(pcCU->getPic()->getChromaFormat());
383 
384  const UInt uiLog2TrafoSize = rTu.GetLog2LumaTrSize();
385 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
386  if (bDebugRQT)
387  {
388  printf("x..codeTransform: offsetLuma=%d offsetChroma=%d absPartIdx=%d, uiDepth=%d\n width=%d, height=%d, uiTrIdx=%d, uiInnerQuadIdx=%d\n",
390  fflush(stdout);
391  }
392 #endif
393 
394  if( pcCU->isIntra(uiAbsPartIdx) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
395  {
396  uiSubdiv = 1;
397  }
398  else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->isInter(uiAbsPartIdx)) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) )
399  {
400  uiSubdiv = (uiLog2TrafoSize >quadtreeTULog2MinSizeInCU);
401  }
402  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
403  {
404  uiSubdiv = 1;
405  }
406  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
407  {
408  uiSubdiv = 0;
409  }
410  else if( uiLog2TrafoSize == quadtreeTULog2MinSizeInCU )
411  {
412  uiSubdiv = 0;
413  }
414  else
415  {
416  assert( uiLog2TrafoSize > quadtreeTULog2MinSizeInCU );
417  m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
418  }
419 
420  for(Int chan=COMPONENT_Cb; chan<numValidComponent; chan++)
421  {
422  const ComponentID compID=ComponentID(chan);
423  const UInt trDepthTotalAdj=rTu.GetTransformDepthTotalAdj(compID);
424 
425  const Bool bFirstCbfOfCU = uiTrDepth == 0;
426 
427  if( bFirstCbfOfCU )
428  {
429  pcCU->setCbfSubParts( 0, compID, rTu.GetAbsPartIdxTU(compID), trDepthTotalAdj);
430  }
431  if( bFirstCbfOfCU || rTu.ProcessingAllQuadrants(compID) )
432  {
433  if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, compID, uiTrDepth - 1 ) )
434  {
435  m_pcEntropyDecoderIf->parseQtCbf( rTu, compID, (uiSubdiv == 0) );
436  }
437  }
438  }
439 
440  if( uiSubdiv )
441  {
442  const UInt uiQPartNum = pcCU->getPic()->getNumPartitionsInCtu() >> ((uiDepth+1) << 1);
443  UInt uiYUVCbf[MAX_NUM_COMPONENT] = {0,0,0};
444 
445  TComTURecurse tuRecurseChild(rTu, true);
446 
447  do
448  {
449  xDecodeTransform( bCodeDQP, isChromaQpAdjCoded, tuRecurseChild, quadtreeTULog2MinSizeInCU );
450  UInt childTUAbsPartIdx=tuRecurseChild.GetAbsPartIdxTU();
451  for(UInt ch=0; ch<numValidComponent; ch++)
452  {
453  uiYUVCbf[ch] |= pcCU->getCbf(childTUAbsPartIdx , ComponentID(ch), uiTrDepth+1 );
454  }
455  } while (tuRecurseChild.nextSection(rTu) );
456 
457  for(UInt ch=0; ch<numValidComponent; ch++)
458  {
459  UChar *pBase = pcCU->getCbf( ComponentID(ch) ) + uiAbsPartIdx;
460  const UChar flag = uiYUVCbf[ch] << uiTrDepth;
461 
462  for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui )
463  {
464  pBase[ui] |= flag;
465  }
466  }
467  }
468  else
469  {
470  assert( uiDepth >= pcCU->getDepth( uiAbsPartIdx ) );
471  pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiDepth );
472 
473  {
475  DTRACE_CABAC_T( "\tTrIdx: abspart=" );
476  DTRACE_CABAC_V( uiAbsPartIdx );
477  DTRACE_CABAC_T( "\tdepth=" );
478  DTRACE_CABAC_V( uiDepth );
479  DTRACE_CABAC_T( "\ttrdepth=" );
480  DTRACE_CABAC_V( uiTrDepth );
481  DTRACE_CABAC_T( "\n" );
482  }
483 
484  pcCU->setCbfSubParts ( 0, COMPONENT_Y, uiAbsPartIdx, uiDepth );
485 
486  if( (!pcCU->isIntra(uiAbsPartIdx)) && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && ((!bChroma) || (!pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cb, 0 ) && !pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cr, 0 )) ))
487  {
488  pcCU->setCbfSubParts( 1 << uiTrDepth, COMPONENT_Y, uiAbsPartIdx, uiDepth );
489  }
490  else
491  {
493  }
494 
495 
496  // transform_unit begin
497  UInt cbf[MAX_NUM_COMPONENT]={0,0,0};
498  Bool validCbf = false;
499  Bool validChromaCbf = false;
500  const UInt uiTrIdx = rTu.GetTransformDepthRel();
501 
502  for(UInt ch=0; ch<pcCU->getPic()->getNumberValidComponents(); ch++)
503  {
504  const ComponentID compID = ComponentID(ch);
505 
506  cbf[compID] = pcCU->getCbf( uiAbsPartIdx, compID, uiTrIdx );
507 
508  if (cbf[compID] != 0)
509  {
510  validCbf = true;
511  if (isChroma(compID))
512  {
513  validChromaCbf = true;
514  }
515  }
516  }
517 
518  if ( validCbf )
519  {
520 
521  // dQP: only for CTU
522  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
523  {
524  if ( bCodeDQP )
525  {
526  const UInt uiAbsPartIdxCU=rTu.GetAbsPartIdxCU();
527  decodeQP( pcCU, uiAbsPartIdxCU);
528  bCodeDQP = false;
529  }
530  }
531 
532  if ( pcCU->getSlice()->getUseChromaQpAdj() )
533  {
534  if ( validChromaCbf && isChromaQpAdjCoded && !pcCU->getCUTransquantBypass(rTu.GetAbsPartIdxCU()) )
535  {
537  isChromaQpAdjCoded = false;
538  }
539  }
540 
541  const UInt numValidComp=pcCU->getPic()->getNumberValidComponents();
542 
543  for(UInt ch=COMPONENT_Y; ch<numValidComp; ch++)
544  {
545  const ComponentID compID=ComponentID(ch);
546 
547  if( rTu.ProcessComponentSection(compID) )
548  {
549 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
550  if (bDebugRQT)
551  {
552  printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, rTu.getRect(compID).width, rTu.getRect(compID).height, 1);
553  }
554 #endif
555 
556  if (rTu.getRect(compID).width != rTu.getRect(compID).height)
557  {
558  //code two sub-TUs
559  TComTURecurse subTUIterator(rTu, false, TComTU::VERTICAL_SPLIT, true, compID);
560 
561  do
562  {
563  const UInt subTUCBF = pcCU->getCbf(subTUIterator.GetAbsPartIdxTU(), compID, (uiTrIdx + 1));
564 
565  if (subTUCBF != 0)
566  {
567 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
568  if (bDebugRQT)
569  {
570  printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, subTUIterator.getRect(compID).width, subTUIterator.getRect(compID).height, 1);
571  }
572 #endif
573  m_pcEntropyDecoderIf->parseCoeffNxN( subTUIterator, compID );
574  }
575  } while (subTUIterator.nextSection(rTu));
576  }
577  else
578  {
579  if(isChroma(compID) && (cbf[COMPONENT_Y] != 0))
580  {
582  }
583 
584  if(cbf[compID] != 0)
585  {
586  m_pcEntropyDecoderIf->parseCoeffNxN( rTu, compID );
587  }
588  }
589  }
590  }
591  }
592  // transform_unit end
593  }
594 }
595 
596 Void TDecEntropy::decodeQP ( TComDataCU* pcCU, UInt uiAbsPartIdx )
597 {
598  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
599  {
600  m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
601  }
602 }
603 
605 {
606  if ( pcCU->getSlice()->getUseChromaQpAdj() )
607  {
608  m_pcEntropyDecoderIf->parseChromaQpAdjustment( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
609  }
610 }
611 
612 
614 Void TDecEntropy::decodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool& bCodeDQP, Bool& isChromaQpAdjCoded )
615 {
616  if( pcCU->isIntra(uiAbsPartIdx) )
617  {
618  }
619  else
620  {
621  UInt uiQtRootCbf = 1;
622  if( !( pcCU->getPartitionSize( uiAbsPartIdx) == SIZE_2Nx2N && pcCU->getMergeFlag( uiAbsPartIdx ) ) )
623  {
624  m_pcEntropyDecoderIf->parseQtRootCbf( uiAbsPartIdx, uiQtRootCbf );
625  }
626  if ( !uiQtRootCbf )
627  {
628  static const UInt cbfZero[MAX_NUM_COMPONENT]={0,0,0};
629  pcCU->setCbfSubParts( cbfZero, uiAbsPartIdx, uiDepth );
630  pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth );
631  return;
632  }
633 
634  }
635 
636  TComTURecurse tuRecurse(pcCU, uiAbsPartIdx, uiDepth);
637 
638 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
639  if (bDebugRQT)
640  {
641  printf("..codeCoeff: uiAbsPartIdx=%d, PU format=%d, 2Nx2N=%d, NxN=%d\n", uiAbsPartIdx, pcCU->getPartitionSize(uiAbsPartIdx), SIZE_2Nx2N, SIZE_NxN);
642  }
643 #endif
644 
645  Int quadtreeTULog2MinSizeInCU = pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx);
646 
647  xDecodeTransform( bCodeDQP, isChromaQpAdjCoded, tuRecurse, quadtreeTULog2MinSizeInCU );
648 }
649 
virtual Void parseTransformSubdivFlag(UInt &ruiSubdivFlag, UInt uiLog2TransformBlockSize)=0
static Bool isChromaEnabled(const ChromaFormat fmt)
sample adaptive offset class (header)
Void decodeRefFrmIdxPU(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList)
Void decodeSplitFlag(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
Definition: TDecEntropy.cpp:98
Void decodeSkipFlag(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
Definition: TDecEntropy.cpp:59
Int getRefIdx(Int iIdx) const
Void setMVPNumSubParts(Int iMVPNum, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
virtual Void parseIPCMInfo(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)=0
CU data structure class.
Definition: TComDataCU.h:64
Bool g_bFinalEncode
Int getHor() const
Definition: TComMv.h:88
prediction class (header)
Int getInt() const
Definition: Debug.h:84
virtual Void parseIntraDirChroma(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)=0
virtual Void parseQtCbf(TComTU &rTu, const ComponentID compID, const Bool lowestLevel)=0
void Void
Definition: TypeDef.h:285
Void getMvPredAMVP(TComDataCU *pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv &rcMvPred)
Void decodeMergeFlag(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx)
Definition: TDecEntropy.cpp:78
Void setAllRefIdx(Int iRefIdx, PartSize eMbMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0)
class for motion vector with reference index
Bool getUseChromaQpAdj() const
Definition: TComSlice.h:1347
unsigned int UInt
Definition: TypeDef.h:297
UInt getNumPartitionsInCtu() const
Definition: TComPic.h:119
Void decodeIntraDirModeLuma(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
Void decodePredMode(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
virtual Void parseChromaQpAdjustment(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)=0
UInt getPCMLog2MaxSize() const
Definition: TComSlice.h:853
Void decodePredInfo(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU *pcSubCU)
UInt GetTransformDepthRel() const
Definition: TComTU.h:108
Int getNumberValidComponents() const
Definition: TComPic.h:129
UInt getMaxCUDepth() const
Definition: TComSlice.h:849
virtual Void parseMergeIndex(TComDataCU *pcCU, UInt &ruiMergeIndex)=0
UInt g_auiPUOffset[NUMBER_OF_PART_SIZES]
Definition: TComRom.cpp:260
virtual Void parsePredMode(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)=0
TComMv const & getMvd(Int iIdx) const
UChar * getMergeIndex()
Definition: TComDataCU.h:326
UInt64 g_nSymbolCounter
Definition: TComRom.cpp:566
TDecEntropyIf * m_pcEntropyDecoderIf
Definition: TDecEntropy.h:119
Bool nextSection(const TComTU &parent)
Definition: TComTU.cpp:178
UChar * getInterDir()
Definition: TComDataCU.h:346
Int getNumRefIdx(RefPicList e) const
Definition: TComSlice.h:1353
entropy decoder pure class
Definition: TDecEntropy.h:61
UChar getCbf(UInt uiIdx, ComponentID eType)
Definition: TComDataCU.h:303
UInt GetSectionNumber() const
Definition: TComTU.h:101
Bool isInter(UInt uiPartIdx) const
Definition: TComDataCU.h:444
Void setEntropyDecoder(TDecEntropyIf *p)
Definition: TDecEntropy.cpp:52
virtual Void parseMVPIdx(Int &riMVPIdx)=0
UInt GetAbsPartIdxTU() const
Definition: TComTU.h:119
Void setPartSizeSubParts(PartSize eMode, UInt uiAbsPartIdx, UInt uiDepth)
class for motion information in one CU
entropy decoder class (header)
virtual Void parseDeltaQP(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)=0
virtual Void parseCUTransquantBypassFlag(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)=0
virtual Void parsePartSize(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)=0
PartSize
supported partition shape
Definition: TypeDef.h:393
virtual Void parseSkipFlag(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)=0
Void decodeMVPIdxPU(TComDataCU *pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList)
virtual Void parseSplitFlag(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)=0
virtual Void parseRefFrmIdx(TComDataCU *pcCU, Int &riRefFrmIdx, RefPicList eRefList)=0
static Bool enable4ChromaPUsInIntraNxNCU(const ChromaFormat chFmt)
virtual Void parseIntraDirLumaAng(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)=0
UChar * getIntraDir(const ChannelType channelType) const
Definition: TComDataCU.h:338
#define DTRACE_CABAC_T(x)
Definition: TComRom.h:197
#define NOT_VALID
Definition: CommonDef.h:129
UInt getMaxNumMergeCand() const
Definition: TComSlice.h:1451
Int iN
number of motion vector predictor candidates
symmetric motion partition, 2Nx2N
Definition: TypeDef.h:395
virtual Void parseQtRootCbf(UInt uiAbsPartIdx, UInt &uiQtRootCbf)=0
bool Bool
Definition: TypeDef.h:286
Void setAllMvField(TComMvField const &mvField, PartSize eMbMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0)
Bool isIntra(UInt uiPartIdx) const
Definition: TComDataCU.h:443
Void decodeIPCMInfo(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
Void setInterDirSubParts(UInt uiDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
Void copyInterPredInfoFrom(TComDataCU *pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList)
Definition: TComDataCU.cpp:827
parameters for AMVP
UInt getPCMLog2MinSize() const
Definition: TComSlice.h:855
Void decodeCUTransquantBypassFlag(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
Definition: TDecEntropy.cpp:65
reference list 0
Definition: TypeDef.h:417
Bool ProcessingAllQuadrants(const ComponentID compID) const
Definition: TComTU.h:98
Void setCbfSubParts(const UInt uiCbf[MAX_NUM_COMPONENT], UInt uiAbsPartIdx, UInt uiDepth)
Void decodeMvdPU(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList)
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
virtual Void parseMergeFlag(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx)=0
UChar * getDepth()
Definition: TComDataCU.h:213
Bool isBipredRestriction(UInt puIdx)
const TComPPS * getPPS() const
Definition: TComSlice.h:1309
Void decodeChromaQpAdjustment(TComDataCU *pcCU, UInt uiAbsPartIdx)
#define DTRACE_CABAC_V(x)
Definition: TComRom.h:195
Int getVer() const
Definition: TComMv.h:89
ChromaFormat getChromaFormat() const
Definition: TComPic.h:128
TComPrediction * m_pcPrediction
Definition: TDecEntropy.h:120
Void decodeQP(TComDataCU *pcCU, UInt uiAbsPartIdx)
TComDataCU * getCU()
Definition: TComTU.h:126
reference list 1
Definition: TypeDef.h:418
Bool ProcessComponentSection(const ComponentID compID) const
Definition: TComTU.h:99
Void decodePUWise(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU *pcSubCU)
Void xDecodeTransform(Bool &bCodeDQP, Bool &isChromaQpAdjCoded, TComTU &rTu, const Int quadtreeTULog2MinSizeInCU)
Bool isInterP() const
Definition: TComSlice.h:1406
Bool * getCUTransquantBypass()
Definition: TComDataCU.h:242
Void setMVPIdxSubParts(Int iMVPIdx, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
Void getInterMergeCandidates(UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField *pcMFieldNeighbours, UChar *puhInterDirNeighbours, Int &numValidMergeCand, Int mrgCandIdx=-1)
Construct a list of merging candidates.
Bool getUsePCM() const
Definition: TComSlice.h:851
TComPic * getPic()
Definition: TComDataCU.h:203
AMVPInfo * getAMVPInfo()
Void setAllMvd(TComMv const &rcMvd, PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0)
Int getMVPIdx(RefPicList eRefPicList, UInt uiIdx)
Definition: TComDataCU.h:374
Definition: TComTU.h:48
Char * getPartitionSize()
Definition: TComDataCU.h:223
#define DTRACE_CABAC_VL(x)
Definition: TComRom.h:196
Void decodeCoeff(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool &bCodeDQP, Bool &isChromaQpAdjCoded)
decode coefficients
Void fillMvpCand(UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, AMVPInfo *pInfo)
Void setTrIdxSubParts(UInt uiTrIdx, UInt uiAbsPartIdx, UInt uiDepth)
TComCUMvField * getCUMvField(RefPicList e)
Definition: TComDataCU.h:294
UInt getLog2ParallelMergeLevelMinus2() const
Definition: TComSlice.h:1164
UChar * getWidth()
Definition: TComDataCU.h:245
virtual Void parseInterDir(TComDataCU *pcCU, UInt &ruiInterDir, UInt uiAbsPartIdx)=0
int Int
Definition: TypeDef.h:296
basic motion vector class
Definition: TComMv.h:51
static Bool isChroma(const ComponentID id)
UInt getQuadtreeTULog2MaxSize() const
Definition: TComSlice.h:861
Void decodeIntraDirModeChroma(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
ComponentID
Definition: TypeDef.h:368
UInt GetAbsPartIdxCU() const
Definition: TComTU.h:116
virtual Void parseCrossComponentPrediction(class TComTU &rTu, ComponentID compID)=0
Bool * getMergeFlag()
Definition: TComDataCU.h:321
virtual Void parseCoeffNxN(class TComTU &rTu, ComponentID compID)=0
virtual Void parseMvd(TComDataCU *pcCU, UInt uiAbsPartAddr, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList)=0
#define MRG_MAX_NUM_CANDS
Definition: CommonDef.h:186
Void decodeMergeIndex(TComDataCU *pcSubCU, UInt uiPartIdx, UInt uiPartAddr, UInt uiDepth)
Definition: TDecEntropy.cpp:91
UInt getQuadtreeTULog2MinSizeInCU(UInt uiIdx)
symmetric motion partition, Nx N
Definition: TypeDef.h:398
Void setAllMv(TComMv const &rcMv, PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0)
UInt getQuadtreeTUMaxDepthInter() const
Definition: TComSlice.h:866
Void decodePartSize(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
Void setMergeIndexSubParts(UInt uiMergeIndex, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
Void decodeInterDirPU(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx)
UInt GetTransformDepthTotal() const
Definition: TComTU.h:105
TComSlice * getSlice()
Definition: TComDataCU.h:205
const TComSPS * getSPS() const
Definition: TComSlice.h:1306
UInt GetTransformDepthTotalAdj(const ComponentID compID) const
Definition: TComTU.h:106