HEVC Test Model (HM)  HM-16.18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TEncCu.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 <stdio.h>
39 #include "TEncTop.h"
40 #include "TEncCu.h"
41 #include "TEncAnalyze.h"
42 #include "TLibCommon/Debug.h"
43 
44 #include <cmath>
45 #include <algorithm>
46 using namespace std;
47 
48 
51 
52 // ====================================================================================================================
53 // Constructor / destructor / create / destroy
54 // ====================================================================================================================
55 
62 Void TEncCu::create(UChar uhTotalDepth, UInt uiMaxWidth, UInt uiMaxHeight, ChromaFormat chromaFormat)
63 {
64  Int i;
65 
66  m_uhTotalDepth = uhTotalDepth + 1;
67  m_ppcBestCU = new TComDataCU*[m_uhTotalDepth-1];
68  m_ppcTempCU = new TComDataCU*[m_uhTotalDepth-1];
69 
70  m_ppcPredYuvBest = new TComYuv*[m_uhTotalDepth-1];
71  m_ppcResiYuvBest = new TComYuv*[m_uhTotalDepth-1];
72  m_ppcRecoYuvBest = new TComYuv*[m_uhTotalDepth-1];
73  m_ppcPredYuvTemp = new TComYuv*[m_uhTotalDepth-1];
74  m_ppcResiYuvTemp = new TComYuv*[m_uhTotalDepth-1];
75  m_ppcRecoYuvTemp = new TComYuv*[m_uhTotalDepth-1];
76  m_ppcOrigYuv = new TComYuv*[m_uhTotalDepth-1];
77 
78  UInt uiNumPartitions;
79  for( i=0 ; i<m_uhTotalDepth-1 ; i++)
80  {
81  uiNumPartitions = 1<<( ( m_uhTotalDepth - i - 1 )<<1 );
82  UInt uiWidth = uiMaxWidth >> i;
83  UInt uiHeight = uiMaxHeight >> i;
84 
85  m_ppcBestCU[i] = new TComDataCU; m_ppcBestCU[i]->create( chromaFormat, uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) );
86  m_ppcTempCU[i] = new TComDataCU; m_ppcTempCU[i]->create( chromaFormat, uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) );
87 
88  m_ppcPredYuvBest[i] = new TComYuv; m_ppcPredYuvBest[i]->create(uiWidth, uiHeight, chromaFormat);
89  m_ppcResiYuvBest[i] = new TComYuv; m_ppcResiYuvBest[i]->create(uiWidth, uiHeight, chromaFormat);
90  m_ppcRecoYuvBest[i] = new TComYuv; m_ppcRecoYuvBest[i]->create(uiWidth, uiHeight, chromaFormat);
91 
92  m_ppcPredYuvTemp[i] = new TComYuv; m_ppcPredYuvTemp[i]->create(uiWidth, uiHeight, chromaFormat);
93  m_ppcResiYuvTemp[i] = new TComYuv; m_ppcResiYuvTemp[i]->create(uiWidth, uiHeight, chromaFormat);
94  m_ppcRecoYuvTemp[i] = new TComYuv; m_ppcRecoYuvTemp[i]->create(uiWidth, uiHeight, chromaFormat);
95 
96  m_ppcOrigYuv [i] = new TComYuv; m_ppcOrigYuv [i]->create(uiWidth, uiHeight, chromaFormat);
97  }
98 
99  m_bEncodeDQP = false;
100  m_stillToCodeChromaQpOffsetFlag = false;
101  m_cuChromaQpOffsetIdxPlus1 = 0;
102  m_bFastDeltaQP = false;
103 
104  // initialize partition order.
105  UInt* piTmp = &g_auiZscanToRaster[0];
106  initZscanToRaster( m_uhTotalDepth, 1, 0, piTmp);
107  initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uhTotalDepth );
108 
109  // initialize conversion matrix from partition index to pel
110  initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uhTotalDepth );
111 }
112 
114 {
115  Int i;
116 
117  for( i=0 ; i<m_uhTotalDepth-1 ; i++)
118  {
119  if(m_ppcBestCU[i])
120  {
121  m_ppcBestCU[i]->destroy(); delete m_ppcBestCU[i]; m_ppcBestCU[i] = NULL;
122  }
123  if(m_ppcTempCU[i])
124  {
125  m_ppcTempCU[i]->destroy(); delete m_ppcTempCU[i]; m_ppcTempCU[i] = NULL;
126  }
127  if(m_ppcPredYuvBest[i])
128  {
129  m_ppcPredYuvBest[i]->destroy(); delete m_ppcPredYuvBest[i]; m_ppcPredYuvBest[i] = NULL;
130  }
131  if(m_ppcResiYuvBest[i])
132  {
133  m_ppcResiYuvBest[i]->destroy(); delete m_ppcResiYuvBest[i]; m_ppcResiYuvBest[i] = NULL;
134  }
135  if(m_ppcRecoYuvBest[i])
136  {
137  m_ppcRecoYuvBest[i]->destroy(); delete m_ppcRecoYuvBest[i]; m_ppcRecoYuvBest[i] = NULL;
138  }
139  if(m_ppcPredYuvTemp[i])
140  {
141  m_ppcPredYuvTemp[i]->destroy(); delete m_ppcPredYuvTemp[i]; m_ppcPredYuvTemp[i] = NULL;
142  }
143  if(m_ppcResiYuvTemp[i])
144  {
145  m_ppcResiYuvTemp[i]->destroy(); delete m_ppcResiYuvTemp[i]; m_ppcResiYuvTemp[i] = NULL;
146  }
147  if(m_ppcRecoYuvTemp[i])
148  {
149  m_ppcRecoYuvTemp[i]->destroy(); delete m_ppcRecoYuvTemp[i]; m_ppcRecoYuvTemp[i] = NULL;
150  }
151  if(m_ppcOrigYuv[i])
152  {
153  m_ppcOrigYuv[i]->destroy(); delete m_ppcOrigYuv[i]; m_ppcOrigYuv[i] = NULL;
154  }
155  }
156  if(m_ppcBestCU)
157  {
158  delete [] m_ppcBestCU;
159  m_ppcBestCU = NULL;
160  }
161  if(m_ppcTempCU)
162  {
163  delete [] m_ppcTempCU;
164  m_ppcTempCU = NULL;
165  }
166 
167  if(m_ppcPredYuvBest)
168  {
169  delete [] m_ppcPredYuvBest;
170  m_ppcPredYuvBest = NULL;
171  }
172  if(m_ppcResiYuvBest)
173  {
174  delete [] m_ppcResiYuvBest;
175  m_ppcResiYuvBest = NULL;
176  }
177  if(m_ppcRecoYuvBest)
178  {
179  delete [] m_ppcRecoYuvBest;
180  m_ppcRecoYuvBest = NULL;
181  }
182  if(m_ppcPredYuvTemp)
183  {
184  delete [] m_ppcPredYuvTemp;
185  m_ppcPredYuvTemp = NULL;
186  }
187  if(m_ppcResiYuvTemp)
188  {
189  delete [] m_ppcResiYuvTemp;
190  m_ppcResiYuvTemp = NULL;
191  }
192  if(m_ppcRecoYuvTemp)
193  {
194  delete [] m_ppcRecoYuvTemp;
195  m_ppcRecoYuvTemp = NULL;
196  }
197  if(m_ppcOrigYuv)
198  {
199  delete [] m_ppcOrigYuv;
200  m_ppcOrigYuv = NULL;
201  }
202 }
203 
207 {
208  m_pcEncCfg = pcEncTop;
209  m_pcPredSearch = pcEncTop->getPredSearch();
210  m_pcTrQuant = pcEncTop->getTrQuant();
211  m_pcRdCost = pcEncTop->getRdCost();
212 
213  m_pcEntropyCoder = pcEncTop->getEntropyCoder();
214  m_pcBinCABAC = pcEncTop->getBinCABAC();
215 
216  m_pppcRDSbacCoder = pcEncTop->getRDSbacCoder();
217  m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder();
218 
219  m_pcRateCtrl = pcEncTop->getRateCtrl();
220  m_lumaQPOffset = 0;
221  initLumaDeltaQpLUT();
222 }
223 
224 // ====================================================================================================================
225 // Public member functions
226 // ====================================================================================================================
227 
232 {
233  // initialize CU data
234  m_ppcBestCU[0]->initCtu( pCtu->getPic(), pCtu->getCtuRsAddr() );
235  m_ppcTempCU[0]->initCtu( pCtu->getPic(), pCtu->getCtuRsAddr() );
236 
237  // analysis of CU
238  DEBUG_STRING_NEW(sDebug)
239 
240  xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 DEBUG_STRING_PASS_INTO(sDebug) );
241  DEBUG_STRING_OUTPUT(std::cout, sDebug)
242 
243 #if ADAPTIVE_QP_SELECTION
244  if( m_pcEncCfg->getUseAdaptQpSelect() )
245  {
246  if(pCtu->getSlice()->getSliceType()!=I_SLICE) //IIII
247  {
248  xCtuCollectARLStats( pCtu );
249  }
250  }
251 #endif
252 }
256 {
257  if ( pCtu->getSlice()->getPPS()->getUseDQP() )
258  {
259  setdQPFlag(true);
260  }
261 
262  if ( pCtu->getSlice()->getUseChromaQpAdj() )
263  {
264  setCodeChromaQpAdjFlag(true);
265  }
266 
267  // Encode CU data
268  xEncodeCU( pCtu, 0, 0 );
269 }
270 
271 // ====================================================================================================================
272 // Protected member functions
273 // ====================================================================================================================
274 
276 {
277  const LumaLevelToDeltaQPMapping &mapping=m_pcEncCfg->getLumaLevelToDeltaQPMapping();
278 
279  if ( !mapping.isEnabled() )
280  {
281  return;
282  }
283 
284  // map the sparse LumaLevelToDeltaQPMapping.mapping to a fully populated linear table.
285 
286  Int lastDeltaQPValue=0;
287  std::size_t nextSparseIndex=0;
288  for(Int index=0; index<LUMA_LEVEL_TO_DQP_LUT_MAXSIZE; index++)
289  {
290  while (nextSparseIndex < mapping.mapping.size() && index>=mapping.mapping[nextSparseIndex].first)
291  {
292  lastDeltaQPValue=mapping.mapping[nextSparseIndex].second;
293  nextSparseIndex++;
294  }
295  m_lumaLevelToDeltaQPLUT[index]=lastDeltaQPValue;
296  }
297 }
298 
299 Int TEncCu::calculateLumaDQP(TComDataCU *pCU, const UInt absPartIdx, const TComYuv * pOrgYuv)
300 {
301  const Pel *pY = pOrgYuv->getAddr(COMPONENT_Y, absPartIdx);
302  const Int stride = pOrgYuv->getStride(COMPONENT_Y);
303  Int width = pCU->getWidth(absPartIdx);
304  Int height = pCU->getHeight(absPartIdx);
305  Double avg = 0;
306 
307  // limit the block by picture size
308  const TComSPS* pSPS = pCU->getSlice()->getSPS();
309  if ( pCU->getCUPelX() + width > pSPS->getPicWidthInLumaSamples() )
310  {
311  width = pSPS->getPicWidthInLumaSamples() - pCU->getCUPelX();
312  }
313  if ( pCU->getCUPelY() + height > pSPS->getPicHeightInLumaSamples() )
314  {
315  height = pSPS->getPicHeightInLumaSamples() - pCU->getCUPelY();
316  }
317 
318  // Get QP offset derived from Luma level
319  if ( m_pcEncCfg->getLumaLevelToDeltaQPMapping().mode == LUMALVL_TO_DQP_AVG_METHOD )
320  {
321  // Use avg method
322  Int sum = 0;
323  for (Int y = 0; y < height; y++)
324  {
325  for (Int x = 0; x < width; x++)
326  {
327  sum += pY[x];
328  }
329  pY += stride;
330  }
331  avg = (Double)sum/(width*height);
332  }
333  else
334  {
335  // Use maximum luma value
336  Int maxVal = 0;
337  for (Int y = 0; y < height; y++)
338  {
339  for (Int x = 0; x < width; x++)
340  {
341  if (pY[x] > maxVal)
342  {
343  maxVal = pY[x];
344  }
345  }
346  pY += stride;
347  }
348  // use a percentage of the maxVal
349  avg = (Double)maxVal * m_pcEncCfg->getLumaLevelToDeltaQPMapping().maxMethodWeight;
350  }
351 
352  Int lumaIdx = Clip3<Int>(0, Int(LUMA_LEVEL_TO_DQP_LUT_MAXSIZE)-1, Int(avg+0.5) );
353  Int QP = m_lumaLevelToDeltaQPLUT[lumaIdx];
354  return QP;
355 }
356 
358 #if AMP_ENC_SPEEDUP
359 #if AMP_MRG
360 Void TEncCu::deriveTestModeAMP (TComDataCU *pcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver, Bool &bTestMergeAMP_Hor, Bool &bTestMergeAMP_Ver)
361 #else
362 Void TEncCu::deriveTestModeAMP (TComDataCU *pcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver)
363 #endif
364 {
365  if ( pcBestCU->getPartitionSize(0) == SIZE_2NxN )
366  {
367  bTestAMP_Hor = true;
368  }
369  else if ( pcBestCU->getPartitionSize(0) == SIZE_Nx2N )
370  {
371  bTestAMP_Ver = true;
372  }
373  else if ( pcBestCU->getPartitionSize(0) == SIZE_2Nx2N && pcBestCU->getMergeFlag(0) == false && pcBestCU->isSkipped(0) == false )
374  {
375  bTestAMP_Hor = true;
376  bTestAMP_Ver = true;
377  }
378 
379 #if AMP_MRG
380  if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N )
382  {
383  bTestMergeAMP_Hor = true;
384  bTestMergeAMP_Ver = true;
385  }
386 
387  if ( eParentPartSize == NUMBER_OF_PART_SIZES )
388  {
389  if ( pcBestCU->getPartitionSize(0) == SIZE_2NxN )
390  {
391  bTestMergeAMP_Hor = true;
392  }
393  else if ( pcBestCU->getPartitionSize(0) == SIZE_Nx2N )
394  {
395  bTestMergeAMP_Ver = true;
396  }
397  }
398 
399  if ( pcBestCU->getPartitionSize(0) == SIZE_2Nx2N && pcBestCU->isSkipped(0) == false )
400  {
401  bTestMergeAMP_Hor = true;
402  bTestMergeAMP_Ver = true;
403  }
404 
405  if ( pcBestCU->getWidth(0) == 64 )
406  {
407  bTestAMP_Hor = false;
408  bTestAMP_Ver = false;
409  }
410 #else
411  if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N )
413  {
414  bTestAMP_Hor = true;
415  bTestAMP_Ver = true;
416  }
417 
418  if ( eParentPartSize == SIZE_2Nx2N )
419  {
420  bTestAMP_Hor = false;
421  bTestAMP_Ver = false;
422  }
423 #endif
424 }
425 #endif
426 
427 
428 // ====================================================================================================================
429 // Protected member functions
430 // ====================================================================================================================
434 #if AMP_ENC_SPEEDUP
435 Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, const UInt uiDepth DEBUG_STRING_FN_DECLARE(sDebug_), PartSize eParentPartSize )
436 #else
437 Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, const UInt uiDepth )
438 #endif
439 {
440  TComPic* pcPic = rpcBestCU->getPic();
441  DEBUG_STRING_NEW(sDebug)
442  const TComPPS &pps=*(rpcTempCU->getSlice()->getPPS());
443  const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS());
444 
445  // These are only used if getFastDeltaQp() is true
446  const UInt fastDeltaQPCuMaxSize = Clip3(sps.getMaxCUHeight()>>sps.getLog2DiffMaxMinCodingBlockSize(), sps.getMaxCUHeight(), 32u);
447 
448  // get Original YUV data from picture
449  m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getCtuRsAddr(), rpcBestCU->getZorderIdxInCtu() );
450 
451  // variable for Cbf fast mode PU decision
452  Bool doNotBlockPu = true;
453  Bool earlyDetectionSkipMode = false;
454 
455  const UInt uiLPelX = rpcBestCU->getCUPelX();
456  const UInt uiRPelX = uiLPelX + rpcBestCU->getWidth(0) - 1;
457  const UInt uiTPelY = rpcBestCU->getCUPelY();
458  const UInt uiBPelY = uiTPelY + rpcBestCU->getHeight(0) - 1;
459  const UInt uiWidth = rpcBestCU->getWidth(0);
460 
461  Int iBaseQP = xComputeQP( rpcBestCU, uiDepth );
462  Int iMinQP;
463  Int iMaxQP;
464  Bool isAddLowestQP = false;
465 
466  const UInt numberValidComponents = rpcBestCU->getPic()->getNumberValidComponents();
467 
468  if( uiDepth <= pps.getMaxCuDQPDepth() )
469  {
470  Int idQP = m_pcEncCfg->getMaxDeltaQP();
471  iMinQP = Clip3( -sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP-idQP );
472  iMaxQP = Clip3( -sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP+idQP );
473  }
474  else
475  {
476  iMinQP = rpcTempCU->getQP(0);
477  iMaxQP = rpcTempCU->getQP(0);
478  }
479 
480  if ( m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() )
481  {
482  if ( uiDepth <= pps.getMaxCuDQPDepth() )
483  {
484  // keep using the same m_QP_LUMA_OFFSET in the same CTU
485  m_lumaQPOffset = calculateLumaDQP(rpcTempCU, 0, m_ppcOrigYuv[uiDepth]);
486  }
487  iMinQP = Clip3(-sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP - m_lumaQPOffset);
488  iMaxQP = iMinQP; // force encode choose the modified QO
489  }
490 
491  if ( m_pcEncCfg->getUseRateCtrl() )
492  {
493  iMinQP = m_pcRateCtrl->getRCQP();
494  iMaxQP = m_pcRateCtrl->getRCQP();
495  }
496 
497  // transquant-bypass (TQB) processing loop variable initialisation ---
498 
499  const Int lowestQP = iMinQP; // For TQB, use this QP which is the lowest non TQB QP tested (rather than QP'=0) - that way delta QPs are smaller, and TQB can be tested at all CU levels.
500 
501  if ( (pps.getTransquantBypassEnabledFlag()) )
502  {
503  isAddLowestQP = true; // mark that the first iteration is to cost TQB mode.
504  iMinQP = iMinQP - 1; // increase loop variable range by 1, to allow testing of TQB mode along with other QPs
505  if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() )
506  {
507  iMaxQP = iMinQP;
508  }
509  }
510 
511  TComSlice * pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx());
512 
513  const Bool bBoundary = !( uiRPelX < sps.getPicWidthInLumaSamples() && uiBPelY < sps.getPicHeightInLumaSamples() );
514 
515  if ( !bBoundary )
516  {
517  for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
518  {
519  const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP);
520 
521  if (bIsLosslessMode)
522  {
523  iQP = lowestQP;
524  }
525  if ( m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() && uiDepth <= pps.getMaxCuDQPDepth() )
526  {
527  getSliceEncoder()->updateLambda(pcSlice, iQP);
528  }
529 
530  m_cuChromaQpOffsetIdxPlus1 = 0;
531  if (pcSlice->getUseChromaQpAdj())
532  {
533  /* Pre-estimation of chroma QP based on input block activity may be performed
534  * here, using for example m_ppcOrigYuv[uiDepth] */
535  /* To exercise the current code, the index used for adjustment is based on
536  * block position
537  */
538  Int lgMinCuSize = sps.getLog2MinCodingBlockSize() +
540  m_cuChromaQpOffsetIdxPlus1 = ((uiLPelX >> lgMinCuSize) + (uiTPelY >> lgMinCuSize)) % (pps.getPpsRangeExtension().getChromaQpOffsetListLen() + 1);
541  }
542 
543  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
544 
545  // do inter modes, SKIP and 2Nx2N
546  if( rpcBestCU->getSlice()->getSliceType() != I_SLICE )
547  {
548  // 2Nx2N
549  if(m_pcEncCfg->getUseEarlySkipDetection())
550  {
551  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) );
552  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );//by Competition for inter_2Nx2N
553  }
554  // SKIP
555  xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU DEBUG_STRING_PASS_INTO(sDebug), &earlyDetectionSkipMode );//by Merge for inter_2Nx2N
556  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
557 
558  if(!m_pcEncCfg->getUseEarlySkipDetection())
559  {
560  // 2Nx2N, NxN
561  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) );
562  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
563  if(m_pcEncCfg->getUseCbfFastMode())
564  {
565  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
566  }
567  }
568  }
569 
570  if (bIsLosslessMode) // Restore loop variable if lossless mode was searched.
571  {
572  iQP = iMinQP;
573  }
574  }
575 
576  if(!earlyDetectionSkipMode)
577  {
578  for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
579  {
580  const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP); // If lossless, then iQP is irrelevant for subsequent modules.
581 
582  if (bIsLosslessMode)
583  {
584  iQP = lowestQP;
585  }
586 
587  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
588 
589  // do inter modes, NxN, 2NxN, and Nx2N
590  if( rpcBestCU->getSlice()->getSliceType() != I_SLICE )
591  {
592  // 2Nx2N, NxN
593 
594  if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) ))
595  {
596  if( uiDepth == sps.getLog2DiffMaxMinCodingBlockSize() && doNotBlockPu)
597  {
598  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN DEBUG_STRING_PASS_INTO(sDebug) );
599  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
600  }
601  }
602 
603  if(doNotBlockPu)
604  {
605  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N DEBUG_STRING_PASS_INTO(sDebug) );
606  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
607  if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_Nx2N )
608  {
609  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
610  }
611  }
612  if(doNotBlockPu)
613  {
614  xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN DEBUG_STRING_PASS_INTO(sDebug) );
615  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
616  if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxN)
617  {
618  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
619  }
620  }
621 
623  if(sps.getUseAMP() && uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() )
624  {
625 #if AMP_ENC_SPEEDUP
626  Bool bTestAMP_Hor = false, bTestAMP_Ver = false;
627 
628 #if AMP_MRG
629  Bool bTestMergeAMP_Hor = false, bTestMergeAMP_Ver = false;
630 
631  deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver, bTestMergeAMP_Hor, bTestMergeAMP_Ver);
632 #else
633  deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver);
634 #endif
635 
637  if ( bTestAMP_Hor )
638  {
639  if(doNotBlockPu)
640  {
641  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU DEBUG_STRING_PASS_INTO(sDebug) );
642  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
643  if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU )
644  {
645  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
646  }
647  }
648  if(doNotBlockPu)
649  {
650  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD DEBUG_STRING_PASS_INTO(sDebug) );
651  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
652  if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD )
653  {
654  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
655  }
656  }
657  }
658 #if AMP_MRG
659  else if ( bTestMergeAMP_Hor )
660  {
661  if(doNotBlockPu)
662  {
663  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU DEBUG_STRING_PASS_INTO(sDebug), true );
664  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
665  if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU )
666  {
667  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
668  }
669  }
670  if(doNotBlockPu)
671  {
672  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD DEBUG_STRING_PASS_INTO(sDebug), true );
673  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
674  if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD )
675  {
676  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
677  }
678  }
679  }
680 #endif
681 
683  if ( bTestAMP_Ver )
684  {
685  if(doNotBlockPu)
686  {
687  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N DEBUG_STRING_PASS_INTO(sDebug) );
688  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
689  if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N )
690  {
691  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
692  }
693  }
694  if(doNotBlockPu)
695  {
696  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N DEBUG_STRING_PASS_INTO(sDebug) );
697  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
698  }
699  }
700 #if AMP_MRG
701  else if ( bTestMergeAMP_Ver )
702  {
703  if(doNotBlockPu)
704  {
705  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N DEBUG_STRING_PASS_INTO(sDebug), true );
706  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
707  if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N )
708  {
709  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
710  }
711  }
712  if(doNotBlockPu)
713  {
714  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N DEBUG_STRING_PASS_INTO(sDebug), true );
715  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
716  }
717  }
718 #endif
719 
720 #else
721  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU );
722  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
723  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD );
724  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
725  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N );
726  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
727 
728  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N );
729  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
730 
731 #endif
732  }
733  }
734 
735  // do normal intra modes
736  // speedup for inter frames
737 #if MCTS_ENC_CHECK
738  if ( m_pcEncCfg->getTMCTSSEITileConstraint() || (rpcBestCU->getSlice()->getSliceType() == I_SLICE) ||
739  ((!m_pcEncCfg->getDisableIntraPUsInInterSlices()) && (
740  (rpcBestCU->getCbf(0, COMPONENT_Y) != 0) ||
741  ((rpcBestCU->getCbf(0, COMPONENT_Cb) != 0) && (numberValidComponents > COMPONENT_Cb)) ||
742  ((rpcBestCU->getCbf(0, COMPONENT_Cr) != 0) && (numberValidComponents > COMPONENT_Cr)) // avoid very complex intra if it is unlikely
743  )))
744  {
745 #else
746  if((rpcBestCU->getSlice()->getSliceType() == I_SLICE) ||
747  ((!m_pcEncCfg->getDisableIntraPUsInInterSlices()) && (
748  (rpcBestCU->getCbf( 0, COMPONENT_Y ) != 0) ||
749  ((rpcBestCU->getCbf( 0, COMPONENT_Cb ) != 0) && (numberValidComponents > COMPONENT_Cb)) ||
750  ((rpcBestCU->getCbf( 0, COMPONENT_Cr ) != 0) && (numberValidComponents > COMPONENT_Cr)) // avoid very complex intra if it is unlikely
751  )))
752  {
753 #endif
754  xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) );
755  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
756  if( uiDepth == sps.getLog2DiffMaxMinCodingBlockSize() )
757  {
758  if( rpcTempCU->getWidth(0) > ( 1 << sps.getQuadtreeTULog2MinSize() ) )
759  {
760  xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN DEBUG_STRING_PASS_INTO(sDebug) );
761  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
762  }
763  }
764  }
765 
766  // test PCM
767  if(sps.getUsePCM()
768  && rpcTempCU->getWidth(0) <= (1<<sps.getPCMLog2MaxSize())
769  && rpcTempCU->getWidth(0) >= (1<<sps.getPCMLog2MinSize()) )
770  {
771  UInt uiRawBits = getTotalBits(rpcBestCU->getWidth(0), rpcBestCU->getHeight(0), rpcBestCU->getPic()->getChromaFormat(), sps.getBitDepths().recon);
772  UInt uiBestBits = rpcBestCU->getTotalBits();
773  if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > m_pcRdCost->calcRdCost(uiRawBits, 0)))
774  {
775  xCheckIntraPCM (rpcBestCU, rpcTempCU);
776  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
777  }
778  }
779 
780  if (bIsLosslessMode) // Restore loop variable if lossless mode was searched.
781  {
782  iQP = iMinQP;
783  }
784  }
785  }
786 
787  if( rpcBestCU->getTotalCost()!=MAX_DOUBLE )
788  {
789  m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]);
790  m_pcEntropyCoder->resetBits();
791  m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true );
792  rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits
793  rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
794  rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() );
795  m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]);
796  }
797  }
798 
799  // copy original YUV samples to PCM buffer
800  if( rpcBestCU->getTotalCost()!=MAX_DOUBLE && rpcBestCU->isLosslessCoded(0) && (rpcBestCU->getIPCMFlag(0) == false))
801  {
802  xFillPCMBuffer(rpcBestCU, m_ppcOrigYuv[uiDepth]);
803  }
804 
805  if( uiDepth == pps.getMaxCuDQPDepth() )
806  {
807  Int idQP = m_pcEncCfg->getMaxDeltaQP();
808  iMinQP = Clip3( -sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP-idQP );
809  iMaxQP = Clip3( -sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP+idQP );
810  }
811  else if( uiDepth < pps.getMaxCuDQPDepth() )
812  {
813  iMinQP = iBaseQP;
814  iMaxQP = iBaseQP;
815  }
816  else
817  {
818  const Int iStartQP = rpcTempCU->getQP(0);
819  iMinQP = iStartQP;
820  iMaxQP = iStartQP;
821  }
822 
823  if ( m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() )
824  {
825  iMinQP = Clip3(-sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP - m_lumaQPOffset);
826  iMaxQP = iMinQP;
827  }
828 
829  if ( m_pcEncCfg->getUseRateCtrl() )
830  {
831  iMinQP = m_pcRateCtrl->getRCQP();
832  iMaxQP = m_pcRateCtrl->getRCQP();
833  }
834 
835  if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() )
836  {
837  iMaxQP = iMinQP; // If all TUs are forced into using transquant bypass, do not loop here.
838  }
839 
840  const Bool bSubBranch = bBoundary || !( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->getTotalCost()!=MAX_DOUBLE && rpcBestCU->isSkipped(0) );
841 
842  if( bSubBranch && uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() && (!getFastDeltaQp() || uiWidth > fastDeltaQPCuMaxSize || bBoundary))
843  {
844  // further split
845  Double splitTotalCost = 0;
846 
847  for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
848  {
849  const Bool bIsLosslessMode = false; // False at this level. Next level down may set it to true.
850 
851  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
852 
853  UChar uhNextDepth = uiDepth+1;
854  TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth];
855  TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth];
856  DEBUG_STRING_NEW(sTempDebug)
857 
858  for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ )
859  {
860  pcSubBestPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init.
861  pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init.
862 
863  if( ( pcSubBestPartCU->getCUPelX() < sps.getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < sps.getPicHeightInLumaSamples() ) )
864  {
865  if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer
866  {
867  m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
868  }
869  else
870  {
871  m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
872  }
873 
874 #if AMP_ENC_SPEEDUP
875  DEBUG_STRING_NEW(sChild)
876  if ( !(rpcBestCU->getTotalCost()!=MAX_DOUBLE && rpcBestCU->isInter(0)) )
877  {
878  xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth DEBUG_STRING_PASS_INTO(sChild), NUMBER_OF_PART_SIZES );
879  }
880  else
881  {
882 
883  xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth DEBUG_STRING_PASS_INTO(sChild), rpcBestCU->getPartitionSize(0) );
884  }
885  DEBUG_STRING_APPEND(sTempDebug, sChild)
886 #else
887  xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth );
888 #endif
889 
890  rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data.
891  xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth );
892  if ( m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() && pps.getMaxCuDQPDepth() >= 1 )
893  {
894  splitTotalCost += pcSubBestPartCU->getTotalCost();
895  }
896  }
897  else
898  {
899  pcSubBestPartCU->copyToPic( uhNextDepth );
900  rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth );
901  }
902  }
903 
904  m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
905  if( !bBoundary )
906  {
907  m_pcEntropyCoder->resetBits();
908  m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth, true );
909  if ( m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() && pps.getMaxCuDQPDepth() >= 1 )
910  {
911  Int splitBits = m_pcEntropyCoder->getNumberOfWrittenBits();
912  Double splitBitCost = m_pcRdCost->calcRdCost( splitBits, 0 );
913  splitTotalCost += splitBitCost;
914  }
915 
916  rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits
917  rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
918  }
919 
920  if ( m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() && pps.getMaxCuDQPDepth() >= 1 )
921  {
922  rpcTempCU->getTotalCost() = splitTotalCost;
923  }
924  else
925  {
926  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
927  }
928 
929  if( uiDepth == pps.getMaxCuDQPDepth() && pps.getUseDQP())
930  {
931  Bool hasResidual = false;
932  for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++)
933  {
934  if( ( rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Y)
935  || (rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Cb) && (numberValidComponents > COMPONENT_Cb))
936  || (rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Cr) && (numberValidComponents > COMPONENT_Cr)) ) )
937  {
938  hasResidual = true;
939  break;
940  }
941  }
942 
943  if ( hasResidual )
944  {
945  m_pcEntropyCoder->resetBits();
946  m_pcEntropyCoder->encodeQP( rpcTempCU, 0, false );
947  rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits
948  rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
949  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
950 
951  Bool foundNonZeroCbf = false;
952  rpcTempCU->setQPSubCUs( rpcTempCU->getRefQP( 0 ), 0, uiDepth, foundNonZeroCbf );
953  assert( foundNonZeroCbf );
954  }
955  else
956  {
957  rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP
958  }
959  }
960 
961  m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
962 
963  // If the configuration being tested exceeds the maximum number of bytes for a slice / slice-segment, then
964  // a proper RD evaluation cannot be performed. Therefore, termination of the
965  // slice/slice-segment must be made prior to this CTU.
966  // This can be achieved by forcing the decision to be that of the rpcTempCU.
967  // The exception is each slice / slice-segment must have at least one CTU.
968  if (rpcBestCU->getTotalCost()!=MAX_DOUBLE)
969  {
970  const Bool isEndOfSlice = pcSlice->getSliceMode()==FIXED_NUMBER_OF_BYTES
971  && ((pcSlice->getSliceBits()+rpcBestCU->getTotalBits())>pcSlice->getSliceArgument()<<3)
972  && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceCurStartCtuTsAddr())
973  && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr());
974  const Bool isEndOfSliceSegment = pcSlice->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES
975  && ((pcSlice->getSliceSegmentBits()+rpcBestCU->getTotalBits()) > pcSlice->getSliceSegmentArgument()<<3)
976  && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr());
977  // Do not need to check slice condition for slice-segment since a slice-segment is a subset of a slice.
978  if(isEndOfSlice||isEndOfSliceSegment)
979  {
980  rpcBestCU->getTotalCost()=MAX_DOUBLE;
981  }
982  }
983 
984  xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTempDebug) DEBUG_STRING_PASS_INTO(false) ); // RD compare current larger prediction
985  // with sub partitioned prediction.
986  }
987  }
988 
989  DEBUG_STRING_APPEND(sDebug_, sDebug);
990 
991  rpcBestCU->copyToPic(uiDepth); // Copy Best data to Picture for next partition prediction.
992 
993  xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getCtuRsAddr(), rpcBestCU->getZorderIdxInCtu(), uiDepth, uiDepth ); // Copy Yuv data to picture Yuv
994  if (bBoundary)
995  {
996  return;
997  }
998 
999  // Assert if Best prediction mode is NONE
1000  // Selected mode's RD-cost must be not MAX_DOUBLE.
1001  assert( rpcBestCU->getPartitionSize ( 0 ) != NUMBER_OF_PART_SIZES );
1002  assert( rpcBestCU->getPredictionMode( 0 ) != NUMBER_OF_PREDICTION_MODES );
1003  assert( rpcBestCU->getTotalCost ( ) != MAX_DOUBLE );
1004 }
1005 
1012 Void TEncCu::finishCU( TComDataCU* pcCU, UInt uiAbsPartIdx )
1013 {
1014  TComPic* pcPic = pcCU->getPic();
1015  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
1016 
1017  //Calculate end address
1018  const Int currentCTUTsAddr = pcPic->getPicSym()->getCtuRsToTsAddrMap(pcCU->getCtuRsAddr());
1019  const Bool isLastSubCUOfCtu = pcCU->isLastSubCUOfCtu(uiAbsPartIdx);
1020  if ( isLastSubCUOfCtu )
1021  {
1022  // The 1-terminating bit is added to all streams, so don't add it here when it's 1.
1023  // i.e. when the slice segment CurEnd CTU address is the current CTU address+1.
1024  if (pcSlice->getSliceSegmentCurEndCtuTsAddr() != currentCTUTsAddr+1)
1025  {
1026  m_pcEntropyCoder->encodeTerminatingBit( 0 );
1027  }
1028  }
1029 }
1030 
1037 {
1038  Int iBaseQp = pcCU->getSlice()->getSliceQp();
1039  Int iQpOffset = 0;
1040  if ( m_pcEncCfg->getUseAdaptiveQP() )
1041  {
1042  TEncPic* pcEPic = dynamic_cast<TEncPic*>( pcCU->getPic() );
1043  UInt uiAQDepth = min( uiDepth, pcEPic->getMaxAQDepth()-1 );
1044  TEncPicQPAdaptationLayer* pcAQLayer = pcEPic->getAQLayer( uiAQDepth );
1045  UInt uiAQUPosX = pcCU->getCUPelX() / pcAQLayer->getAQPartWidth();
1046  UInt uiAQUPosY = pcCU->getCUPelY() / pcAQLayer->getAQPartHeight();
1047  UInt uiAQUStride = pcAQLayer->getAQPartStride();
1048  TEncQPAdaptationUnit* acAQU = pcAQLayer->getQPAdaptationUnit();
1049 
1050  Double dMaxQScale = pow(2.0, m_pcEncCfg->getQPAdaptationRange()/6.0);
1051  Double dAvgAct = pcAQLayer->getAvgActivity();
1052  Double dCUAct = acAQU[uiAQUPosY * uiAQUStride + uiAQUPosX].getActivity();
1053  Double dNormAct = (dMaxQScale*dCUAct + dAvgAct) / (dCUAct + dMaxQScale*dAvgAct);
1054  Double dQpOffset = log(dNormAct) / log(2.0) * 6.0;
1055  iQpOffset = Int(floor( dQpOffset + 0.49999 ));
1056  }
1057 
1058  return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQp+iQpOffset );
1059 }
1060 
1067 Void TEncCu::xEncodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1068 {
1069  TComPic *const pcPic = pcCU->getPic();
1070  TComSlice *const pcSlice = pcCU->getSlice();
1071  const TComSPS &sps =*(pcSlice->getSPS());
1072  const TComPPS &pps =*(pcSlice->getPPS());
1073 
1074  const UInt maxCUWidth = sps.getMaxCUWidth();
1075  const UInt maxCUHeight = sps.getMaxCUHeight();
1076 
1077  Bool bBoundary = false;
1078  UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
1079  const UInt uiRPelX = uiLPelX + (maxCUWidth>>uiDepth) - 1;
1080  UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
1081  const UInt uiBPelY = uiTPelY + (maxCUHeight>>uiDepth) - 1;
1082 
1083  if( ( uiRPelX < sps.getPicWidthInLumaSamples() ) && ( uiBPelY < sps.getPicHeightInLumaSamples() ) )
1084  {
1085  m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
1086  }
1087  else
1088  {
1089  bBoundary = true;
1090  }
1091 
1092  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() ) ) || bBoundary )
1093  {
1094  UInt uiQNumParts = ( pcPic->getNumPartitionsInCtu() >> (uiDepth<<1) )>>2;
1095  if( uiDepth == pps.getMaxCuDQPDepth() && pps.getUseDQP())
1096  {
1097  setdQPFlag(true);
1098  }
1099 
1100  if( uiDepth == pps.getPpsRangeExtension().getDiffCuChromaQpOffsetDepth() && pcSlice->getUseChromaQpAdj())
1101  {
1102  setCodeChromaQpAdjFlag(true);
1103  }
1104 
1105  for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts )
1106  {
1107  uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
1108  uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
1109  if( ( uiLPelX < sps.getPicWidthInLumaSamples() ) && ( uiTPelY < sps.getPicHeightInLumaSamples() ) )
1110  {
1111  xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 );
1112  }
1113  }
1114  return;
1115  }
1116 
1117  if( uiDepth <= pps.getMaxCuDQPDepth() && pps.getUseDQP())
1118  {
1119  setdQPFlag(true);
1120  }
1121 
1122  if( uiDepth <= pps.getPpsRangeExtension().getDiffCuChromaQpOffsetDepth() && pcSlice->getUseChromaQpAdj())
1123  {
1124  setCodeChromaQpAdjFlag(true);
1125  }
1126 
1128  {
1129  m_pcEntropyCoder->encodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx );
1130  }
1131 
1132  if( !pcSlice->isIntra() )
1133  {
1134  m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx );
1135  }
1136 
1137  if( pcCU->isSkipped( uiAbsPartIdx ) )
1138  {
1139  m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx );
1140  finishCU(pcCU,uiAbsPartIdx);
1141  return;
1142  }
1143 
1144  m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx );
1145  m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth );
1146 
1147  if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N )
1148  {
1149  m_pcEntropyCoder->encodeIPCMInfo( pcCU, uiAbsPartIdx );
1150 
1151  if(pcCU->getIPCMFlag(uiAbsPartIdx))
1152  {
1153  // Encode slice finish
1154  finishCU(pcCU,uiAbsPartIdx);
1155  return;
1156  }
1157  }
1158 
1159  // prediction Info ( Intra : direction mode, Inter : Mv, reference idx )
1160  m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx );
1161 
1162  // Encode Coefficients
1163  Bool bCodeDQP = getdQPFlag();
1164  Bool codeChromaQpAdj = getCodeChromaQpAdjFlag();
1165  m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, bCodeDQP, codeChromaQpAdj );
1166  setCodeChromaQpAdjFlag( codeChromaQpAdj );
1167  setdQPFlag( bCodeDQP );
1168 
1169  // --- write terminating bit ---
1170  finishCU(pcCU,uiAbsPartIdx);
1171 }
1172 
1173 Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg)
1174 {
1175  Int k, i, j, jj;
1176  Int diff[64], m1[8][8], m2[8][8], m3[8][8], iSumHad = 0;
1177 
1178  for( k = 0; k < 64; k += 8 )
1179  {
1180  diff[k+0] = piOrg[0] ;
1181  diff[k+1] = piOrg[1] ;
1182  diff[k+2] = piOrg[2] ;
1183  diff[k+3] = piOrg[3] ;
1184  diff[k+4] = piOrg[4] ;
1185  diff[k+5] = piOrg[5] ;
1186  diff[k+6] = piOrg[6] ;
1187  diff[k+7] = piOrg[7] ;
1188 
1189  piOrg += iStrideOrg;
1190  }
1191 
1192  //horizontal
1193  for (j=0; j < 8; j++)
1194  {
1195  jj = j << 3;
1196  m2[j][0] = diff[jj ] + diff[jj+4];
1197  m2[j][1] = diff[jj+1] + diff[jj+5];
1198  m2[j][2] = diff[jj+2] + diff[jj+6];
1199  m2[j][3] = diff[jj+3] + diff[jj+7];
1200  m2[j][4] = diff[jj ] - diff[jj+4];
1201  m2[j][5] = diff[jj+1] - diff[jj+5];
1202  m2[j][6] = diff[jj+2] - diff[jj+6];
1203  m2[j][7] = diff[jj+3] - diff[jj+7];
1204 
1205  m1[j][0] = m2[j][0] + m2[j][2];
1206  m1[j][1] = m2[j][1] + m2[j][3];
1207  m1[j][2] = m2[j][0] - m2[j][2];
1208  m1[j][3] = m2[j][1] - m2[j][3];
1209  m1[j][4] = m2[j][4] + m2[j][6];
1210  m1[j][5] = m2[j][5] + m2[j][7];
1211  m1[j][6] = m2[j][4] - m2[j][6];
1212  m1[j][7] = m2[j][5] - m2[j][7];
1213 
1214  m2[j][0] = m1[j][0] + m1[j][1];
1215  m2[j][1] = m1[j][0] - m1[j][1];
1216  m2[j][2] = m1[j][2] + m1[j][3];
1217  m2[j][3] = m1[j][2] - m1[j][3];
1218  m2[j][4] = m1[j][4] + m1[j][5];
1219  m2[j][5] = m1[j][4] - m1[j][5];
1220  m2[j][6] = m1[j][6] + m1[j][7];
1221  m2[j][7] = m1[j][6] - m1[j][7];
1222  }
1223 
1224  //vertical
1225  for (i=0; i < 8; i++)
1226  {
1227  m3[0][i] = m2[0][i] + m2[4][i];
1228  m3[1][i] = m2[1][i] + m2[5][i];
1229  m3[2][i] = m2[2][i] + m2[6][i];
1230  m3[3][i] = m2[3][i] + m2[7][i];
1231  m3[4][i] = m2[0][i] - m2[4][i];
1232  m3[5][i] = m2[1][i] - m2[5][i];
1233  m3[6][i] = m2[2][i] - m2[6][i];
1234  m3[7][i] = m2[3][i] - m2[7][i];
1235 
1236  m1[0][i] = m3[0][i] + m3[2][i];
1237  m1[1][i] = m3[1][i] + m3[3][i];
1238  m1[2][i] = m3[0][i] - m3[2][i];
1239  m1[3][i] = m3[1][i] - m3[3][i];
1240  m1[4][i] = m3[4][i] + m3[6][i];
1241  m1[5][i] = m3[5][i] + m3[7][i];
1242  m1[6][i] = m3[4][i] - m3[6][i];
1243  m1[7][i] = m3[5][i] - m3[7][i];
1244 
1245  m2[0][i] = m1[0][i] + m1[1][i];
1246  m2[1][i] = m1[0][i] - m1[1][i];
1247  m2[2][i] = m1[2][i] + m1[3][i];
1248  m2[3][i] = m1[2][i] - m1[3][i];
1249  m2[4][i] = m1[4][i] + m1[5][i];
1250  m2[5][i] = m1[4][i] - m1[5][i];
1251  m2[6][i] = m1[6][i] + m1[7][i];
1252  m2[7][i] = m1[6][i] - m1[7][i];
1253  }
1254 
1255  for (i = 0; i < 8; i++)
1256  {
1257  for (j = 0; j < 8; j++)
1258  {
1259  iSumHad += abs(m2[i][j]);
1260  }
1261  }
1262  iSumHad -= abs(m2[0][0]);
1263  iSumHad =(iSumHad+2)>>2;
1264  return(iSumHad);
1265 }
1266 
1268 {
1269  Int xBl, yBl;
1270  const Int iBlkSize = 8;
1271 
1272  Pel* pOrgInit = pCtu->getPic()->getPicYuvOrg()->getAddr(COMPONENT_Y, pCtu->getCtuRsAddr(), 0);
1273  Int iStrideOrig = pCtu->getPic()->getPicYuvOrg()->getStride(COMPONENT_Y);
1274  Pel *pOrg;
1275 
1276  Int iSumHad = 0;
1277  for ( yBl=0; (yBl+iBlkSize)<=height; yBl+= iBlkSize)
1278  {
1279  for ( xBl=0; (xBl+iBlkSize)<=width; xBl+= iBlkSize)
1280  {
1281  pOrg = pOrgInit + iStrideOrig*yBl + xBl;
1282  iSumHad += xCalcHADs8x8_ISlice(pOrg, iStrideOrig);
1283  }
1284  }
1285  return(iSumHad);
1286 }
1287 
1293 Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU DEBUG_STRING_FN_DECLARE(sDebug), Bool *earlyDetectionSkipMode )
1294 {
1295  assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE );
1296  if(getFastDeltaQp())
1297  {
1298  return; // never check merge in fast deltaqp mode
1299  }
1300  TComMvField cMvFieldNeighbours[2 * MRG_MAX_NUM_CANDS]; // double length for mv of both lists
1301  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
1302  Int numValidMergeCand = 0;
1303  const Bool bTransquantBypassFlag = rpcTempCU->getCUTransquantBypass(0);
1304 
1305  for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui )
1306  {
1307  uhInterDirNeighbours[ui] = 0;
1308  }
1309  UChar uhDepth = rpcTempCU->getDepth( 0 );
1310  rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to CTU level
1311 #if MCTS_ENC_CHECK
1312  UInt numSpatialMergeCandidates = 0;
1313  rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, numSpatialMergeCandidates );
1314 #else
1315  rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand );
1316 #endif
1317 
1318  Int mergeCandBuffer[MRG_MAX_NUM_CANDS];
1319  for( UInt ui = 0; ui < numValidMergeCand; ++ui )
1320  {
1321  mergeCandBuffer[ui] = 0;
1322  }
1323 #if MCTS_ENC_CHECK
1324  if (m_pcEncCfg->getTMCTSSEITileConstraint() && rpcTempCU->isLastColumnCTUInTile())
1325  {
1326  numValidMergeCand = numSpatialMergeCandidates;
1327  }
1328 #endif
1329 
1330  Bool bestIsSkip = false;
1331 
1332  UInt iteration;
1333  if ( rpcTempCU->isLosslessCoded(0))
1334  {
1335  iteration = 1;
1336  }
1337  else
1338  {
1339  iteration = 2;
1340  }
1341  DEBUG_STRING_NEW(bestStr)
1342 
1343  for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual )
1344  {
1345  for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
1346  {
1347  if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1))
1348  {
1349  if( !(bestIsSkip && uiNoResidual == 0) )
1350  {
1351  DEBUG_STRING_NEW(tmpStr)
1352  // set MC parameters
1353  rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to CTU level
1354  rpcTempCU->setCUTransquantBypassSubParts( bTransquantBypassFlag, 0, uhDepth );
1355  rpcTempCU->setChromaQpAdjSubParts( bTransquantBypassFlag ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uhDepth );
1356  rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to CTU level
1357  rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to CTU level
1358  rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to CTU level
1359  rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to CTU level
1360  rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
1361  rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
1362 
1363 #if MCTS_ENC_CHECK
1364  if ( m_pcEncCfg->getTMCTSSEITileConstraint () && (!(m_pcPredSearch->checkTMctsMvp(rpcTempCU))))
1365  {
1366  continue;
1367  }
1368 
1369 #endif
1370  // do MC
1371  m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
1372  // estimate residual and encode everything
1373  m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU,
1374  m_ppcOrigYuv [uhDepth],
1375  m_ppcPredYuvTemp[uhDepth],
1376  m_ppcResiYuvTemp[uhDepth],
1377  m_ppcResiYuvBest[uhDepth],
1378  m_ppcRecoYuvTemp[uhDepth],
1379  (uiNoResidual != 0) DEBUG_STRING_PASS_INTO(tmpStr) );
1380 
1381 #if DEBUG_STRING
1382  DebugInterPredResiReco(tmpStr, *(m_ppcPredYuvTemp[uhDepth]), *(m_ppcResiYuvBest[uhDepth]), *(m_ppcRecoYuvTemp[uhDepth]), DebugStringGetPredModeMask(rpcTempCU->getPredictionMode(0)));
1383 #endif
1384 
1385  if ((uiNoResidual == 0) && (rpcTempCU->getQtRootCbf(0) == 0))
1386  {
1387  // If no residual when allowing for one, then set mark to not try case where residual is forced to 0
1388  mergeCandBuffer[uiMergeCand] = 1;
1389  }
1390 
1391  Int orgQP = rpcTempCU->getQP( 0 );
1392  xCheckDQP( rpcTempCU );
1393  xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth DEBUG_STRING_PASS_INTO(bestStr) DEBUG_STRING_PASS_INTO(tmpStr));
1394 
1395  rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag );
1396 
1397  if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip )
1398  {
1399  bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0;
1400  }
1401  }
1402  }
1403  }
1404 
1405  if(uiNoResidual == 0 && m_pcEncCfg->getUseEarlySkipDetection())
1406  {
1407  if(rpcBestCU->getQtRootCbf( 0 ) == 0)
1408  {
1409  if( rpcBestCU->getMergeFlag( 0 ))
1410  {
1411  *earlyDetectionSkipMode = true;
1412  }
1413  else if(m_pcEncCfg->getMotionEstimationSearchMethod() != MESEARCH_SELECTIVE)
1414  {
1415  Int absoulte_MV=0;
1416  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
1417  {
1418  if ( rpcBestCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
1419  {
1420  TComCUMvField* pcCUMvField = rpcBestCU->getCUMvField(RefPicList( uiRefListIdx ));
1421  Int iHor = pcCUMvField->getMvd( 0 ).getAbsHor();
1422  Int iVer = pcCUMvField->getMvd( 0 ).getAbsVer();
1423  absoulte_MV+=iHor+iVer;
1424  }
1425  }
1426 
1427  if(absoulte_MV == 0)
1428  {
1429  *earlyDetectionSkipMode = true;
1430  }
1431  }
1432  }
1433  }
1434  }
1435  DEBUG_STRING_APPEND(sDebug, bestStr)
1436 }
1437 
1438 
1439 #if AMP_MRG
1440 Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize DEBUG_STRING_FN_DECLARE(sDebug), Bool bUseMRG)
1441 #else
1442 Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize )
1443 #endif
1444 {
1445  DEBUG_STRING_NEW(sTest)
1446 
1447  if(getFastDeltaQp())
1448  {
1449  const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS());
1450  const UInt fastDeltaQPCuMaxSize = Clip3(sps.getMaxCUHeight()>>(sps.getLog2DiffMaxMinCodingBlockSize()), sps.getMaxCUHeight(), 32u);
1451  if(ePartSize != SIZE_2Nx2N || rpcTempCU->getWidth( 0 ) > fastDeltaQPCuMaxSize)
1452  {
1453  return; // only check necessary 2Nx2N Inter in fast deltaqp mode
1454  }
1455  }
1456 
1457  // prior to this, rpcTempCU will have just been reset using rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
1458  UChar uhDepth = rpcTempCU->getDepth( 0 );
1459 
1460  rpcTempCU->setPartSizeSubParts ( ePartSize, 0, uhDepth );
1461  rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth );
1462  rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uhDepth );
1463 
1464 #if MCTS_ENC_CHECK
1465  rpcTempCU->setTMctsMvpIsValid(true);
1466 #endif
1467 
1468 #if AMP_MRG
1469  rpcTempCU->setMergeAMP (true);
1470  m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] DEBUG_STRING_PASS_INTO(sTest), false, bUseMRG );
1471 #else
1472  m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] );
1473 #endif
1474 
1475 #if AMP_MRG
1476  if ( !rpcTempCU->getMergeAMP() )
1477  {
1478  return;
1479  }
1480 #endif
1481 
1482 #if MCTS_ENC_CHECK
1483  if (m_pcEncCfg->getTMCTSSEITileConstraint() && (!rpcTempCU->getTMctsMvpIsValid()))
1484  {
1485  return;
1486  }
1487 #endif
1488 
1489  m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false DEBUG_STRING_PASS_INTO(sTest) );
1490  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
1491 
1492 #if DEBUG_STRING
1493  DebugInterPredResiReco(sTest, *(m_ppcPredYuvTemp[uhDepth]), *(m_ppcResiYuvBest[uhDepth]), *(m_ppcRecoYuvTemp[uhDepth]), DebugStringGetPredModeMask(rpcTempCU->getPredictionMode(0)));
1494 #endif
1495 
1496  xCheckDQP( rpcTempCU );
1497  xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest));
1498 }
1499 
1501  TComDataCU *&rpcTempCU,
1502  PartSize eSize
1503  DEBUG_STRING_FN_DECLARE(sDebug) )
1504 {
1505  DEBUG_STRING_NEW(sTest)
1506 
1507  if(getFastDeltaQp())
1508  {
1509  const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS());
1510  const UInt fastDeltaQPCuMaxSize = Clip3(sps.getMaxCUHeight()>>(sps.getLog2DiffMaxMinCodingBlockSize()), sps.getMaxCUHeight(), 32u);
1511  if(rpcTempCU->getWidth( 0 ) > fastDeltaQPCuMaxSize)
1512  {
1513  return; // only check necessary 2Nx2N Intra in fast deltaqp mode
1514  }
1515  }
1516 
1517  UInt uiDepth = rpcTempCU->getDepth( 0 );
1518 
1519  rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth );
1520 
1521  rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth );
1522  rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth );
1523  rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uiDepth );
1524 
1526 
1527  m_pcPredSearch->estIntraPredLumaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], resiLuma DEBUG_STRING_PASS_INTO(sTest) );
1528 
1529  m_ppcRecoYuvTemp[uiDepth]->copyToPicComponent(COMPONENT_Y, rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getCtuRsAddr(), rpcTempCU->getZorderIdxInCtu() );
1530 
1531  if (rpcBestCU->getPic()->getChromaFormat()!=CHROMA_400)
1532  {
1533  m_pcPredSearch->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], resiLuma DEBUG_STRING_PASS_INTO(sTest) );
1534  }
1535 
1536  m_pcEntropyCoder->resetBits();
1537 
1538  if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnabledFlag())
1539  {
1540  m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true );
1541  }
1542 
1543  m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true );
1544  m_pcEntropyCoder->encodePredMode( rpcTempCU, 0, true );
1545  m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true );
1546  m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0 );
1547  m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0, true );
1548 
1549  // Encode Coefficients
1550  Bool bCodeDQP = getdQPFlag();
1551  Bool codeChromaQpAdjFlag = getCodeChromaQpAdjFlag();
1552  m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, bCodeDQP, codeChromaQpAdjFlag );
1553  setCodeChromaQpAdjFlag( codeChromaQpAdjFlag );
1554  setdQPFlag( bCodeDQP );
1555 
1556  m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
1557 
1558  rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits();
1559  rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
1560  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
1561 
1562  xCheckDQP( rpcTempCU );
1563 
1564  xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest));
1565 }
1566 
1567 
1576 {
1577  if(getFastDeltaQp())
1578  {
1579  const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS());
1580  const UInt fastDeltaQPCuMaxPCMSize = Clip3((UInt)1<<sps.getPCMLog2MinSize(), (UInt)1<<sps.getPCMLog2MaxSize(), 32u);
1581  if (rpcTempCU->getWidth( 0 ) > fastDeltaQPCuMaxPCMSize)
1582  {
1583  return; // only check necessary PCM in fast deltaqp mode
1584  }
1585  }
1586 
1587  UInt uiDepth = rpcTempCU->getDepth( 0 );
1588 
1589  rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth );
1590 
1591  rpcTempCU->setIPCMFlag(0, true);
1592  rpcTempCU->setIPCMFlagSubParts (true, 0, rpcTempCU->getDepth(0));
1593  rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );
1594  rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth );
1595  rpcTempCU->setTrIdxSubParts ( 0, 0, uiDepth );
1596  rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uiDepth );
1597 
1598  m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]);
1599 
1600  m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
1601 
1602  m_pcEntropyCoder->resetBits();
1603 
1604  if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnabledFlag())
1605  {
1606  m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true );
1607  }
1608 
1609  m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true );
1610  m_pcEntropyCoder->encodePredMode ( rpcTempCU, 0, true );
1611  m_pcEntropyCoder->encodePartSize ( rpcTempCU, 0, uiDepth, true );
1612  m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true );
1613 
1614  m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
1615 
1616  rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits();
1617  rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
1618  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
1619 
1620  xCheckDQP( rpcTempCU );
1621  DEBUG_STRING_NEW(a)
1622  DEBUG_STRING_NEW(b)
1623  xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(a) DEBUG_STRING_PASS_INTO(b));
1624 }
1625 
1632 {
1633  if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() )
1634  {
1635  TComYuv* pcYuv;
1636  // Change Information data
1637  TComDataCU* pcCU = rpcBestCU;
1638  rpcBestCU = rpcTempCU;
1639  rpcTempCU = pcCU;
1640 
1641  // Change Prediction data
1642  pcYuv = m_ppcPredYuvBest[uiDepth];
1643  m_ppcPredYuvBest[uiDepth] = m_ppcPredYuvTemp[uiDepth];
1644  m_ppcPredYuvTemp[uiDepth] = pcYuv;
1645 
1646  // Change Reconstruction data
1647  pcYuv = m_ppcRecoYuvBest[uiDepth];
1648  m_ppcRecoYuvBest[uiDepth] = m_ppcRecoYuvTemp[uiDepth];
1649  m_ppcRecoYuvTemp[uiDepth] = pcYuv;
1650 
1651  pcYuv = NULL;
1652  pcCU = NULL;
1653 
1654  // store temp best CI for next CU coding
1655  m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]);
1656 
1657 
1658 #if DEBUG_STRING
1659  DEBUG_STRING_SWAP(sParent, sTest)
1660  const PredMode predMode=rpcBestCU->getPredictionMode(0);
1661  if ((DebugOptionList::DebugString_Structure.getInt()&DebugStringGetPredModeMask(predMode)) && bAddSizeInfo)
1662  {
1663  std::stringstream ss(stringstream::out);
1664  ss <<"###: " << (predMode==MODE_INTRA?"Intra ":"Inter ") << partSizeToString[rpcBestCU->getPartitionSize(0)] << " CU at " << rpcBestCU->getCUPelX() << ", " << rpcBestCU->getCUPelY() << " width=" << UInt(rpcBestCU->getWidth(0)) << std::endl;
1665  sParent+=ss.str();
1666  }
1667 #endif
1668  }
1669 }
1670 
1672 {
1673  UInt uiDepth = pcCU->getDepth( 0 );
1674 
1675  const TComPPS &pps = *(pcCU->getSlice()->getPPS());
1676  if ( pps.getUseDQP() && uiDepth <= pps.getMaxCuDQPDepth() )
1677  {
1678  if ( pcCU->getQtRootCbf( 0) )
1679  {
1680  m_pcEntropyCoder->resetBits();
1681  m_pcEntropyCoder->encodeQP( pcCU, 0, false );
1682  pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits
1683  pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
1684  pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() );
1685  }
1686  else
1687  {
1688  pcCU->setQPSubParts( pcCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP
1689  }
1690  }
1691 }
1692 
1694 {
1695  pDst->iN = pSrc->iN;
1696  for (Int i = 0; i < pSrc->iN; i++)
1697  {
1698  pDst->m_acMvCand[i] = pSrc->m_acMvCand[i];
1699  }
1700 }
1701 Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth )
1702 {
1703  UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx];
1704  UInt uiSrcBlkWidth = rpcPic->getNumPartInCtuWidth() >> (uiSrcDepth);
1705  UInt uiBlkWidth = rpcPic->getNumPartInCtuWidth() >> (uiDepth);
1706  UInt uiPartIdxX = ( ( uiAbsPartIdxInRaster % rpcPic->getNumPartInCtuWidth() ) % uiSrcBlkWidth) / uiBlkWidth;
1707  UInt uiPartIdxY = ( ( uiAbsPartIdxInRaster / rpcPic->getNumPartInCtuWidth() ) % uiSrcBlkWidth) / uiBlkWidth;
1708  UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX;
1709  m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx);
1710 
1711  m_ppcPredYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvPred (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx);
1712 }
1713 
1714 Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth )
1715 {
1716  UInt uiCurrDepth = uiNextDepth - 1;
1717  m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx );
1718  m_ppcPredYuvBest[uiNextDepth]->copyToPartYuv( m_ppcPredYuvBest[uiCurrDepth], uiPartUnitIdx);
1719 }
1720 
1726 {
1727  const ChromaFormat format = pCU->getPic()->getChromaFormat();
1728  const UInt numberValidComponents = getNumberValidComponents(format);
1729  for (UInt componentIndex = 0; componentIndex < numberValidComponents; componentIndex++)
1730  {
1731  const ComponentID component = ComponentID(componentIndex);
1732 
1733  const UInt width = pCU->getWidth(0) >> getComponentScaleX(component, format);
1734  const UInt height = pCU->getHeight(0) >> getComponentScaleY(component, format);
1735 
1736  Pel *source = pOrgYuv->getAddr(component, 0, width);
1737  Pel *destination = pCU->getPCMSample(component);
1738 
1739  const UInt sourceStride = pOrgYuv->getStride(component);
1740 
1741  for (Int line = 0; line < height; line++)
1742  {
1743  for (Int column = 0; column < width; column++)
1744  {
1745  destination[column] = source[column];
1746  }
1747 
1748  source += sourceStride;
1749  destination += width;
1750  }
1751  }
1752 }
1753 
1754 #if ADAPTIVE_QP_SELECTION
1755 
1757 Int TEncCu::xTuCollectARLStats(TCoeff* rpcCoeff, TCoeff* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples )
1758 {
1759  for( Int n = 0; n < NumCoeffInCU; n++ )
1760  {
1761  TCoeff u = abs( rpcCoeff[ n ] );
1762  TCoeff absc = rpcArlCoeff[ n ];
1763 
1764  if( u != 0 )
1765  {
1766  if( u < LEVEL_RANGE )
1767  {
1768  cSum[ u ] += ( Double )absc;
1769  numSamples[ u ]++;
1770  }
1771  else
1772  {
1773  cSum[ LEVEL_RANGE ] += ( Double )absc - ( Double )( u << ARL_C_PRECISION );
1774  numSamples[ LEVEL_RANGE ]++;
1775  }
1776  }
1777  }
1778 
1779  return 0;
1780 }
1781 
1784 {
1785  Double cSum[ LEVEL_RANGE + 1 ]; //: the sum of DCT coefficients corresponding to data type and quantization output
1786  UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to data type and quantization output
1787 
1788  TCoeff* pCoeffY = pCtu->getCoeff(COMPONENT_Y);
1789  TCoeff* pArlCoeffY = pCtu->getArlCoeff(COMPONENT_Y);
1790  const TComSPS &sps = *(pCtu->getSlice()->getSPS());
1791 
1792  const UInt uiMinCUWidth = sps.getMaxCUWidth() >> sps.getMaxTotalCUDepth(); // NOTE: ed - this is not the minimum CU width. It is the square-root of the number of coefficients per part.
1793  const UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth; // NOTE: ed - what is this?
1794 
1795  memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) );
1796  memset( numSamples, 0, sizeof( UInt )*(LEVEL_RANGE+1) );
1797 
1798  // Collect stats to cSum[][] and numSamples[][]
1799  for(Int i = 0; i < pCtu->getTotalNumPart(); i ++ )
1800  {
1801  UInt uiTrIdx = pCtu->getTransformIdx(i);
1802 
1803  if(pCtu->isInter(i) && pCtu->getCbf( i, COMPONENT_Y, uiTrIdx ) )
1804  {
1805  xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples);
1806  }//Note that only InterY is processed. QP rounding is based on InterY data only.
1807 
1808  pCoeffY += uiMinNumCoeffInCU;
1809  pArlCoeffY += uiMinNumCoeffInCU;
1810  }
1811 
1812  for(Int u=1; u<LEVEL_RANGE;u++)
1813  {
1814  m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ;
1815  m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ;
1816  }
1817  m_pcTrQuant->getSliceSumC()[LEVEL_RANGE] += cSum[ LEVEL_RANGE ] ;
1818  m_pcTrQuant->getSliceNSamples()[LEVEL_RANGE] += numSamples[ LEVEL_RANGE ] ;
1819 }
1820 #endif
1821 
Void copyPartFrom(TComDataCU *pcCU, UInt uiPartUnitIdx, UInt uiDepth)
Definition: TComDataCU.cpp:821
Void xCheckIntraPCM(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU)
Definition: TEncCu.cpp:1575
Void deriveTestModeAMP(TComDataCU *pcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver, Bool &bTestMergeAMP_Hor, Bool &bTestMergeAMP_Ver)
Derive small set of test modes for AMP encoder speed-up.
Definition: TEncCu.cpp:360
Void initEstData(const UInt uiDepth, const Int qp, const Bool bTransquantBypass)
Definition: TComDataCU.cpp:525
Void setIPCMFlag(UInt uiIdx, Bool b)
Definition: TComDataCU.h:356
TEncSbac *** getRDSbacCoder()
Definition: TEncTop.h:153
Int getLog2MinCodingBlockSize() const
Definition: TComSlice.h:851
Void xFillPCMBuffer(TComDataCU *pCU, TComYuv *pOrgYuv)
Definition: TEncCu.cpp:1725
Void setSkipFlagSubParts(Bool skip, UInt absPartIdx, UInt depth)
UInt & getTotalBins()
Definition: TComDataCU.h:474
SChar * getPartitionSize()
Definition: TComDataCU.h:226
UInt getCtuTsToRsAddrMap(Int ctuTsAddr) const
Definition: TComPicSym.h:183
static const Int ARL_C_PRECISION
G382: 7-bit arithmetic precision.
Definition: CommonDef.h:174
SliceType getSliceType() const
Definition: TComSlice.h:1353
CU data structure class.
Definition: TComDataCU.h:64
TCoeff * getArlCoeff(ComponentID component)
Definition: TComDataCU.h:303
Void encodeCtu(TComDataCU *pCtu)
CTU encoding function.
Definition: TEncCu.cpp:255
encoder analyzer class (header)
TEncRateCtrl * getRateCtrl()
Definition: TEncTop.h:155
Int updateCtuDataISlice(TComDataCU *pCtu, Int width, Int height)
Definition: TEncCu.cpp:1267
SliceConstraint getSliceMode() const
Definition: TComSlice.h:1477
picture class (symbol + YUV buffers)
Definition: TComPic.h:56
Void initSubCU(TComDataCU *pcCU, UInt uiPartUnitIdx, UInt uiDepth, Int qp)
Definition: TComDataCU.cpp:596
void Void
Definition: TypeDef.h:203
std::vector< std::pair< Int, Int > > mapping
first=luma level, second=delta QP.
Definition: TypeDef.h:893
Void getInterMergeCandidates(UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField *pcMFieldNeighbours, UChar *puhInterDirNeighbours, Int &numValidMergeCand, UInt &numSpatialMergeCandidates, Int mrgCandIdx=-1) const
Construct a list of merging candidates.
const TComPPSRExt & getPpsRangeExtension() const
Definition: TComSlice.h:1197
Int getStride(const ComponentID id) const
Definition: TComPicYuv.h:121
Void destroy()
destroy internal buffers
Definition: TEncCu.cpp:113
static const Int MRG_MAX_NUM_CANDS
MERGE.
Definition: CommonDef.h:131
best mode index
Definition: TypeDef.h:429
Void setMergeFlagSubParts(Bool bMergeFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
UChar * getTransformIdx()
Definition: TComDataCU.h:277
#define NULL
Definition: CommonDef.h:107
UChar getQtRootCbf(UInt uiIdx) const
Void xCopyAMVPInfo(AMVPInfo *pSrc, AMVPInfo *pDst)
Definition: TEncCu.cpp:1693
Coding Unit (CU) encoder class (header)
Void xCheckBestMode(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, UInt uiDepth)
Definition: TEncCu.cpp:1631
TComSlice * getSlice(Int i)
Definition: TComPic.h:113
class for motion vector with reference index
Int getAbsHor() const
Definition: TComMv.h:90
static UInt getComponentScaleY(const ComponentID id, const ChromaFormat fmt)
Bool getUseChromaQpAdj() const
Definition: TComSlice.h:1364
Void xCtuCollectARLStats(TComDataCU *pCtu)
Collect ARL statistics from one CTU.
Definition: TEncCu.cpp:1783
Void xCheckDQP(TComDataCU *pcCU)
Definition: TEncCu.cpp:1671
Int xTuCollectARLStats(TCoeff *rpcCoeff, TCoeff *rpcArlCoeff, Int NumCoeffInCU, Double *cSum, UInt *numSamples)
Definition: TEncCu.cpp:1757
Bool isLastColumnCTUInTile() const
unsigned int UInt
Definition: TypeDef.h:212
SliceConstraint getSliceSegmentMode() const
Definition: TComSlice.h:1488
SChar * getPredictionMode()
Definition: TComDataCU.h:237
UInt getNumPartitionsInCtu() const
Definition: TComPic.h:130
static const Int LEVEL_RANGE
G382: max coefficient level in statistics collection.
Definition: CommonDef.h:175
static UInt getComponentScaleX(const ComponentID id, const ChromaFormat fmt)
Void setQPSubCUs(Int qp, UInt absPartIdx, UInt depth, Bool &foundNonZeroCbf)
Short Pel
pixel type
Definition: TypeDef.h:249
Bool getTMctsMvpIsValid()
Definition: TComDataCU.h:218
UInt getPCMLog2MaxSize() const
Definition: TComSlice.h:865
symmetric motion partition, 2Nx N
Definition: TypeDef.h:351
UInt getMaxCUHeight() const
Definition: TComSlice.h:859
UInt getStride(const ComponentID id) const
Definition: TComYuv.h:199
Int getNumberValidComponents() const
Definition: TComPic.h:140
TComMv const & getMvd(Int iIdx) const
UChar getCbf(UInt uiIdx, ComponentID eType) const
Definition: TComDataCU.h:307
Picture class including local image characteristics information for QP adaptation.
Definition: TEncPic.h:95
TEncEntropy * getEntropyCoder()
Definition: TEncTop.h:147
#define DEBUG_STRING_SWAP(srt1, str2)
Definition: TypeDef.h:187
Int recon[MAX_NUM_CHANNEL_TYPE]
the bit depth as indicated in the SPS
Definition: TypeDef.h:793
Int getAbsVer() const
Definition: TComMv.h:91
Bool getTransquantBypassEnabledFlag() const
Definition: TComSlice.h:1142
Int getChromaQpOffsetListLen() const
Definition: TComSlice.h:1010
Int getNumRefIdx(RefPicList e) const
Definition: TComSlice.h:1370
UInt getCtuRsToTsAddrMap(Int ctuRsAddr) const
Definition: TComPicSym.h:185
Void xCheckRDCostIntra(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, PartSize ePartSize)
Definition: TEncCu.cpp:1500
TComMv m_acMvCand[AMVP_MAX_NUM_CANDS]
array of motion vector predictor candidates
UInt getDiffCuChromaQpOffsetDepth() const
Definition: TComSlice.h:1006
UInt getZorderIdxInCtu() const
Definition: TComDataCU.h:206
Distortion & getTotalDistortion()
Definition: TComDataCU.h:480
Void setCUTransquantBypassSubParts(Bool flag, UInt uiAbsPartIdx, UInt uiDepth)
Bool isInter(UInt uiPartIdx) const
Definition: TComDataCU.h:451
temporal index
Definition: TypeDef.h:431
Void setInterDirSubParts(UInt uiDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
TComPicYuv * getPicYuvRec()
Definition: TComPic.h:120
TEncSbac * getRDGoOnSbacCoder()
Definition: TEncTop.h:154
class for motion information in one CU
Void xEncodeCU(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
Definition: TEncCu.cpp:1067
UInt getMaxTotalCUDepth() const
Definition: TComSlice.h:861
Int calculateLumaDQP(TComDataCU *pCU, const UInt absPartIdx, const TComYuv *pOrgYuv)
Definition: TEncCu.cpp:299
Void setChromaQpAdjSubParts(UChar val, Int absPartIdx, Int depth)
PartSize
supported partition shape
Definition: TypeDef.h:348
UInt getNumPartInCtuWidth() const
Definition: TComPic.h:128
Bool * getIPCMFlag()
Definition: TComDataCU.h:354
Double & getTotalCost()
Definition: TComDataCU.h:479
Limit maximum number of bytes in a slice / slice segment.
Definition: TypeDef.h:518
Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg)
Definition: TEncCu.cpp:1173
UInt getMaxNumMergeCand() const
Definition: TComSlice.h:1465
Int iN
number of motion vector predictor candidates
symmetric motion partition, 2Nx2N
Definition: TypeDef.h:350
general YUV buffer class
Definition: TComYuv.h:54
Int getQpBDOffset(ChannelType type) const
Definition: TComSlice.h:904
Double getActivity()
Definition: TEncPic.h:62
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 setTMctsMvpIsValid(Bool b)
Definition: TComDataCU.h:217
Void xCopyYuv2Pic(TComPic *rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth)
Definition: TEncCu.cpp:1701
Void initRasterToPelXY(UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth)
Definition: TComRom.cpp:324
Bool isLosslessCoded(UInt absPartIdx) const
PPS class.
Definition: TComSlice.h:1034
asymmetric motion partition, 2Nx( N/2) + 2Nx(3N/2)
Definition: TypeDef.h:354
asymmetric motion partition, (3N/2)x2N + ( N/2)x2N
Definition: TypeDef.h:357
parameters for AMVP
UInt & getCtuRsAddr()
Definition: TComDataCU.h:204
UInt getPicHeightInLumaSamples() const
Definition: TComSlice.h:836
UInt getSliceBits() const
Definition: TComSlice.h:1496
UInt getPCMLog2MinSize() const
Definition: TComSlice.h:867
TComTrQuant * getTrQuant()
Definition: TEncTop.h:141
Void create(const UInt iWidth, const UInt iHeight, const ChromaFormat chromaFormatIDC)
Create YUV buffer.
Definition: TComYuv.cpp:64
UInt getCUPelY() const
Definition: TComDataCU.h:208
UInt getSliceSegmentBits() const
Definition: TComSlice.h:1498
T Clip3(const T minVal, const T maxVal, const T a)
general min/max clip
Definition: CommonDef.h:252
Void initRasterToZscan(UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth)
Definition: TComRom.cpp:310
#define DEBUG_STRING_APPEND(str1, str2)
Definition: TypeDef.h:186
TComPicYuv * getPicYuvOrg()
Definition: TComPic.h:119
reference list 0
Definition: TypeDef.h:372
Int TCoeff
transform coefficient
Definition: TypeDef.h:250
Void compressCtu(TComDataCU *pCtu)
CTU analysis function.
Definition: TEncCu.cpp:231
Bool getUseDQP() const
Definition: TComSlice.h:1099
Pel * getAddr(const ComponentID id)
Definition: TComYuv.h:150
RefPicList
reference list index
Definition: TypeDef.h:370
TComPicSym * getPicSym()
Definition: TComPic.h:111
UInt getMaxCuDQPDepth() const
Definition: TComSlice.h:1107
ChromaFormat
chroma formats (according to semantics of chroma_format_idc)
Definition: TypeDef.h:292
Void init(TEncTop *pcEncTop)
copy parameters from encoder class
Definition: TEncCu.cpp:206
intra-prediction mode
Definition: TypeDef.h:365
unsigned char UChar
Definition: TypeDef.h:208
UInt getQuadtreeTULog2MinSize() const
Definition: TComSlice.h:875
Void finishCU(TComDataCU *pcCU, UInt uiAbsPartIdx)
Definition: TEncCu.cpp:1012
Local image characteristics for CUs on a specific depth.
Definition: TEncPic.h:66
const BitDepths & getBitDepths() const
Definition: TComSlice.h:900
UInt getSliceSegmentCurStartCtuTsAddr() const
Definition: TComSlice.h:1492
UChar * getDepth()
Definition: TComDataCU.h:210
Bool isSkipped(UInt uiPartIdx) const
returns true, if the partiton is skipped
UInt g_auiZscanToRaster[MAX_NUM_PART_IDXS_IN_CTU_WIDTH *MAX_NUM_PART_IDXS_IN_CTU_WIDTH]
Definition: TComRom.cpp:284
const TComPPS * getPPS() const
Definition: TComSlice.h:1332
UInt getPicWidthInLumaSamples() const
Definition: TComSlice.h:834
Void setQPSubParts(Int qp, UInt uiAbsPartIdx, UInt uiDepth)
UInt & getTotalBits()
Definition: TComDataCU.h:481
Void copyToPic(UChar uiDepth)
Definition: TComDataCU.cpp:906
static const UInt LUMA_LEVEL_TO_DQP_LUT_MAXSIZE
max LUT size for QP offset based on luma
Definition: CommonDef.h:246
UInt getCUPelX() const
Definition: TComDataCU.h:207
#define DEBUG_STRING_PASS_INTO(name)
Definition: TypeDef.h:180
UInt getSliceArgument() const
Definition: TComSlice.h:1479
UInt getSliceSegmentArgument() const
Definition: TComSlice.h:1490
ChromaFormat getChromaFormat() const
Definition: TComPic.h:139
Void setIPCMFlagSubParts(Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth)
Bool isIntra() const
Definition: TComSlice.h:1423
static UInt getTotalBits(const UInt width, const UInt height, const ChromaFormat format, const Int bitDepths[MAX_NUM_CHANNEL_TYPE])
reference list 1
Definition: TypeDef.h:373
UChar * getHeight()
Definition: TComDataCU.h:252
UInt getCurrSliceIdx() const
Definition: TComPic.h:148
encoder class (header)
next best index
Definition: TypeDef.h:430
Int getLog2DiffMaxMinCodingBlockSize() const
Definition: TComSlice.h:853
Bool * getCUTransquantBypass()
Definition: TComDataCU.h:245
UInt getSliceCurStartCtuTsAddr() const
Definition: TComSlice.h:1481
asymmetric motion partition, ( N/2)x2N + (3N/2)x2N
Definition: TypeDef.h:356
Bool getUsePCM() const
Definition: TComSlice.h:863
TComPic * getPic()
Definition: TComDataCU.h:200
TComPicYuv * getPicYuvPred()
Definition: TComPic.h:122
Void xCheckRDCostMerge2Nx2N(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, Bool *earlyDetectionSkipMode)
Definition: TEncCu.cpp:1293
TComRdCost * getRdCost()
Definition: TEncTop.h:152
Void create(ChromaFormat chromaFormatIDC, UInt uiNumPartition, UInt uiWidth, UInt uiHeight, Bool bDecSubCu, Int unitSize, TCoeff *pParentARLBuffer=0)
Definition: TComDataCU.cpp:109
#define DEBUG_STRING_FN_DECLARE(name)
Definition: TypeDef.h:182
TEncPicQPAdaptationLayer * getAQLayer(UInt uiDepth)
Definition: TEncPic.h:112
static const Int MAX_CU_SIZE
= 1&lt;&lt;(MAX_CU_DEPTH)
Definition: CommonDef.h:221
Bool getUseAMP() const
Definition: TComSlice.h:870
Void xCompressCU(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, const UInt uiDepth, PartSize eParentPartSize=NUMBER_OF_PART_SIZES)
Definition: TEncCu.cpp:435
static const Double MAX_DOUBLE
max. value of Double-type value
Definition: CommonDef.h:116
Pel * getAddr(const ComponentID ch)
Definition: TComPicYuv.h:139
Void initZscanToRaster(Int iMaxDepth, Int iDepth, UInt uiStartVal, UInt *&rpuiCurrIdx)
Definition: TComRom.cpp:291
Void xCopyYuv2Tmp(UInt uhPartUnitIdx, UInt uiDepth)
Definition: TEncCu.cpp:1714
UInt getSliceSegmentCurEndCtuTsAddr() const
Definition: TComSlice.h:1494
Void xCheckRDCostInter(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, PartSize ePartSize, Bool bUseMRG=false)
Definition: TEncCu.cpp:1440
TComCUMvField * getCUMvField(RefPicList e)
Definition: TComDataCU.h:297
UChar * getWidth()
Definition: TComDataCU.h:248
TCoeff * getCoeff(ComponentID component)
Definition: TComDataCU.h:300
Bool isLastSubCUOfCtu(const UInt absPartIdx) const
Definition: TComDataCU.cpp:393
int Int
Definition: TypeDef.h:211
Void setMergeAMP(Bool b)
Definition: TComDataCU.h:338
encoder class
Definition: TEncTop.h:68
UInt & getTotalNumPart()
Definition: TComDataCU.h:482
ComponentID
Definition: TypeDef.h:308
PredMode
supported prediction type
Definition: TypeDef.h:362
Bool * getMergeFlag()
Definition: TComDataCU.h:325
Int getSliceQp() const
Definition: TComSlice.h:1355
Void setPredModeSubParts(PredMode eMode, UInt uiAbsPartIdx, UInt uiDepth)
Bool isEnabled() const
Definition: TypeDef.h:894
Void setMergeIndexSubParts(UInt uiMergeIndex, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
TEncSearch * getPredSearch()
Definition: TEncTop.h:139
SChar * getQP()
Definition: TComDataCU.h:258
UInt getMaxAQDepth()
Definition: TEncPic.h:113
Unit block for storing image characteristics.
Definition: TEncPic.h:52
SChar getRefQP(UInt uiCurrAbsIdxInCtu) const
Bool getMergeAMP() const
Definition: TComDataCU.h:339
asymmetric motion partition, 2Nx(3N/2) + 2Nx( N/2)
Definition: TypeDef.h:355
symmetric motion partition, Nx N
Definition: TypeDef.h:353
inter-prediction mode
Definition: TypeDef.h:364
Pel * getPCMSample(ComponentID component)
Definition: TComDataCU.h:305
SBAC encoder class.
Definition: TEncSbac.h:66
double Double
Definition: TypeDef.h:213
UInt g_auiRasterToPelX[MAX_NUM_PART_IDXS_IN_CTU_WIDTH *MAX_NUM_PART_IDXS_IN_CTU_WIDTH]
Definition: TComRom.cpp:286
static UInt getNumberValidComponents(const ChromaFormat fmt)
Void initLumaDeltaQpLUT()
Definition: TEncCu.cpp:275
slice header class
Definition: TComSlice.h:1225
TEncBinCABAC * getBinCABAC()
Definition: TEncTop.h:150
static const Int MAX_QP
Definition: CommonDef.h:126
Void create(UChar uhTotalDepth, UInt iMaxWidth, UInt iMaxHeight, ChromaFormat chromaFormat)
create internal buffers
Definition: TEncCu.cpp:62
#define DEBUG_STRING_OUTPUT(os, name)
Definition: TypeDef.h:185
symmetric motion partition, Nx2N
Definition: TypeDef.h:352
#define DEBUG_STRING_NEW(name)
Definition: TypeDef.h:184
Int xComputeQP(TComDataCU *pcCU, UInt uiDepth)
Definition: TEncCu.cpp:1036
Defines types and objects for environment-variable-based debugging and feature control.
UInt g_auiRasterToPelY[MAX_NUM_PART_IDXS_IN_CTU_WIDTH *MAX_NUM_PART_IDXS_IN_CTU_WIDTH]
Definition: TComRom.cpp:287
UInt getMaxCUWidth() const
Definition: TComSlice.h:857
TComSlice * getSlice()
Definition: TComDataCU.h:202
const TComSPS * getSPS() const
Definition: TComSlice.h:1329
SPS class.
Definition: TComSlice.h:740
Void setTrIdxSubParts(UInt uiTrIdx, UInt uiAbsPartIdx, UInt uiDepth)