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