HEVC Test Model (HM)  HM-16.3
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-2015, ITU/ISO/IEC
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18  * be used to endorse or promote products derived from this software without
19  * specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31  * THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
38 #include <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_CodeChromaQpAdjFlag = false;
101  m_ChromaQpAdjIdc = 0;
102 
103  // initialize partition order.
104  UInt* piTmp = &g_auiZscanToRaster[0];
105  initZscanToRaster( m_uhTotalDepth, 1, 0, piTmp);
106  initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uhTotalDepth );
107 
108  // initialize conversion matrix from partition index to pel
109  initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uhTotalDepth );
110 }
111 
113 {
114  Int i;
115 
116  for( i=0 ; i<m_uhTotalDepth-1 ; i++)
117  {
118  if(m_ppcBestCU[i])
119  {
120  m_ppcBestCU[i]->destroy(); delete m_ppcBestCU[i]; m_ppcBestCU[i] = NULL;
121  }
122  if(m_ppcTempCU[i])
123  {
124  m_ppcTempCU[i]->destroy(); delete m_ppcTempCU[i]; m_ppcTempCU[i] = NULL;
125  }
126  if(m_ppcPredYuvBest[i])
127  {
128  m_ppcPredYuvBest[i]->destroy(); delete m_ppcPredYuvBest[i]; m_ppcPredYuvBest[i] = NULL;
129  }
130  if(m_ppcResiYuvBest[i])
131  {
132  m_ppcResiYuvBest[i]->destroy(); delete m_ppcResiYuvBest[i]; m_ppcResiYuvBest[i] = NULL;
133  }
134  if(m_ppcRecoYuvBest[i])
135  {
136  m_ppcRecoYuvBest[i]->destroy(); delete m_ppcRecoYuvBest[i]; m_ppcRecoYuvBest[i] = NULL;
137  }
138  if(m_ppcPredYuvTemp[i])
139  {
140  m_ppcPredYuvTemp[i]->destroy(); delete m_ppcPredYuvTemp[i]; m_ppcPredYuvTemp[i] = NULL;
141  }
142  if(m_ppcResiYuvTemp[i])
143  {
144  m_ppcResiYuvTemp[i]->destroy(); delete m_ppcResiYuvTemp[i]; m_ppcResiYuvTemp[i] = NULL;
145  }
146  if(m_ppcRecoYuvTemp[i])
147  {
148  m_ppcRecoYuvTemp[i]->destroy(); delete m_ppcRecoYuvTemp[i]; m_ppcRecoYuvTemp[i] = NULL;
149  }
150  if(m_ppcOrigYuv[i])
151  {
152  m_ppcOrigYuv[i]->destroy(); delete m_ppcOrigYuv[i]; m_ppcOrigYuv[i] = NULL;
153  }
154  }
155  if(m_ppcBestCU)
156  {
157  delete [] m_ppcBestCU;
158  m_ppcBestCU = NULL;
159  }
160  if(m_ppcTempCU)
161  {
162  delete [] m_ppcTempCU;
163  m_ppcTempCU = NULL;
164  }
165 
166  if(m_ppcPredYuvBest)
167  {
168  delete [] m_ppcPredYuvBest;
169  m_ppcPredYuvBest = NULL;
170  }
171  if(m_ppcResiYuvBest)
172  {
173  delete [] m_ppcResiYuvBest;
174  m_ppcResiYuvBest = NULL;
175  }
176  if(m_ppcRecoYuvBest)
177  {
178  delete [] m_ppcRecoYuvBest;
179  m_ppcRecoYuvBest = NULL;
180  }
181  if(m_ppcPredYuvTemp)
182  {
183  delete [] m_ppcPredYuvTemp;
184  m_ppcPredYuvTemp = NULL;
185  }
186  if(m_ppcResiYuvTemp)
187  {
188  delete [] m_ppcResiYuvTemp;
189  m_ppcResiYuvTemp = NULL;
190  }
191  if(m_ppcRecoYuvTemp)
192  {
193  delete [] m_ppcRecoYuvTemp;
194  m_ppcRecoYuvTemp = NULL;
195  }
196  if(m_ppcOrigYuv)
197  {
198  delete [] m_ppcOrigYuv;
199  m_ppcOrigYuv = NULL;
200  }
201 }
202 
206 {
207  m_pcEncCfg = pcEncTop;
208  m_pcPredSearch = pcEncTop->getPredSearch();
209  m_pcTrQuant = pcEncTop->getTrQuant();
210  m_pcRdCost = pcEncTop->getRdCost();
211 
212  m_pcEntropyCoder = pcEncTop->getEntropyCoder();
213  m_pcBinCABAC = pcEncTop->getBinCABAC();
214 
215  m_pppcRDSbacCoder = pcEncTop->getRDSbacCoder();
216  m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder();
217 
218  m_pcRateCtrl = pcEncTop->getRateCtrl();
219 }
220 
221 // ====================================================================================================================
222 // Public member functions
223 // ====================================================================================================================
224 
229 {
230  // initialize CU data
231  m_ppcBestCU[0]->initCtu( pCtu->getPic(), pCtu->getCtuRsAddr() );
232  m_ppcTempCU[0]->initCtu( pCtu->getPic(), pCtu->getCtuRsAddr() );
233 
234  // analysis of CU
235  DEBUG_STRING_NEW(sDebug)
236 
237  xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 DEBUG_STRING_PASS_INTO(sDebug) );
238  DEBUG_STRING_OUTPUT(std::cout, sDebug)
239 
240 #if ADAPTIVE_QP_SELECTION
241  if( m_pcEncCfg->getUseAdaptQpSelect() )
242  {
243  if(pCtu->getSlice()->getSliceType()!=I_SLICE) //IIII
244  {
245  xCtuCollectARLStats( pCtu );
246  }
247  }
248 #endif
249 }
253 {
254  if ( pCtu->getSlice()->getPPS()->getUseDQP() )
255  {
256  setdQPFlag(true);
257  }
258 
259  if ( pCtu->getSlice()->getUseChromaQpAdj() )
260  {
261  setCodeChromaQpAdjFlag(true);
262  }
263 
264  // Encode CU data
265  xEncodeCU( pCtu, 0, 0 );
266 }
267 
268 // ====================================================================================================================
269 // Protected member functions
270 // ====================================================================================================================
272 #if AMP_ENC_SPEEDUP
273 #if AMP_MRG
274 Void TEncCu::deriveTestModeAMP (TComDataCU *pcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver, Bool &bTestMergeAMP_Hor, Bool &bTestMergeAMP_Ver)
275 #else
276 Void TEncCu::deriveTestModeAMP (TComDataCU *pcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver)
277 #endif
278 {
279  if ( pcBestCU->getPartitionSize(0) == SIZE_2NxN )
280  {
281  bTestAMP_Hor = true;
282  }
283  else if ( pcBestCU->getPartitionSize(0) == SIZE_Nx2N )
284  {
285  bTestAMP_Ver = true;
286  }
287  else if ( pcBestCU->getPartitionSize(0) == SIZE_2Nx2N && pcBestCU->getMergeFlag(0) == false && pcBestCU->isSkipped(0) == false )
288  {
289  bTestAMP_Hor = true;
290  bTestAMP_Ver = true;
291  }
292 
293 #if AMP_MRG
294  if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N )
296  {
297  bTestMergeAMP_Hor = true;
298  bTestMergeAMP_Ver = true;
299  }
300 
301  if ( eParentPartSize == NUMBER_OF_PART_SIZES )
302  {
303  if ( pcBestCU->getPartitionSize(0) == SIZE_2NxN )
304  {
305  bTestMergeAMP_Hor = true;
306  }
307  else if ( pcBestCU->getPartitionSize(0) == SIZE_Nx2N )
308  {
309  bTestMergeAMP_Ver = true;
310  }
311  }
312 
313  if ( pcBestCU->getPartitionSize(0) == SIZE_2Nx2N && pcBestCU->isSkipped(0) == false )
314  {
315  bTestMergeAMP_Hor = true;
316  bTestMergeAMP_Ver = true;
317  }
318 
319  if ( pcBestCU->getWidth(0) == 64 )
320  {
321  bTestAMP_Hor = false;
322  bTestAMP_Ver = false;
323  }
324 #else
325  if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N )
327  {
328  bTestAMP_Hor = true;
329  bTestAMP_Ver = true;
330  }
331 
332  if ( eParentPartSize == SIZE_2Nx2N )
333  {
334  bTestAMP_Hor = false;
335  bTestAMP_Ver = false;
336  }
337 #endif
338 }
339 #endif
340 
341 
342 // ====================================================================================================================
343 // Protected member functions
344 // ====================================================================================================================
348 #if AMP_ENC_SPEEDUP
349 Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth DEBUG_STRING_FN_DECLARE(sDebug_), PartSize eParentPartSize )
350 #else
351 Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth )
352 #endif
353 {
354  TComPic* pcPic = rpcBestCU->getPic();
355  DEBUG_STRING_NEW(sDebug)
356 
357  // get Original YUV data from picture
358  m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getCtuRsAddr(), rpcBestCU->getZorderIdxInCtu() );
359 
360  // variable for Early CU determination
361  Bool bSubBranch = true;
362 
363  // variable for Cbf fast mode PU decision
364  Bool doNotBlockPu = true;
365  Bool earlyDetectionSkipMode = false;
366 
367  Bool bBoundary = false;
368  UInt uiLPelX = rpcBestCU->getCUPelX();
369  UInt uiRPelX = uiLPelX + rpcBestCU->getWidth(0) - 1;
370  UInt uiTPelY = rpcBestCU->getCUPelY();
371  UInt uiBPelY = uiTPelY + rpcBestCU->getHeight(0) - 1;
372 
373  Int iBaseQP = xComputeQP( rpcBestCU, uiDepth );
374  Int iMinQP;
375  Int iMaxQP;
376  Bool isAddLowestQP = false;
377 
378  const UInt numberValidComponents = rpcBestCU->getPic()->getNumberValidComponents();
379 
380  if( (g_uiMaxCUWidth>>uiDepth) >= (g_uiMaxCUWidth >> ( rpcTempCU->getSlice()->getPPS()->getMaxCuDQPDepth())) )
381  {
382  Int idQP = m_pcEncCfg->getMaxDeltaQP();
383  iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP-idQP );
384  iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP+idQP );
385  }
386  else
387  {
388  iMinQP = rpcTempCU->getQP(0);
389  iMaxQP = rpcTempCU->getQP(0);
390  }
391 
392  if ( m_pcEncCfg->getUseRateCtrl() )
393  {
394  iMinQP = m_pcRateCtrl->getRCQP();
395  iMaxQP = m_pcRateCtrl->getRCQP();
396  }
397 
398  // transquant-bypass (TQB) processing loop variable initialisation ---
399 
400  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.
401 
402  if ( (rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) )
403  {
404  isAddLowestQP = true; // mark that the first iteration is to cost TQB mode.
405  iMinQP = iMinQP - 1; // increase loop variable range by 1, to allow testing of TQB mode along with other QPs
406  if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() )
407  {
408  iMaxQP = iMinQP;
409  }
410  }
411 
412  TComSlice * pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx());
413  // We need to split, so don't try these modes.
414  if ( ( uiRPelX < rpcBestCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) &&
415  ( uiBPelY < rpcBestCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
416  {
417  for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
418  {
419  const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP);
420 
421  if (bIsLosslessMode)
422  {
423  iQP = lowestQP;
424  }
425 
426  m_ChromaQpAdjIdc = 0;
427  if (pcSlice->getUseChromaQpAdj())
428  {
429  /* Pre-estimation of chroma QP based on input block activity may be performed
430  * here, using for example m_ppcOrigYuv[uiDepth] */
431  /* To exercise the current code, the index used for adjustment is based on
432  * block position
433  */
434  Int lgMinCuSize = pcSlice->getSPS()->getLog2MinCodingBlockSize() +
435  std::max<Int>(0, pcSlice->getSPS()->getLog2DiffMaxMinCodingBlockSize()-Int(pcSlice->getPPS()->getMaxCuChromaQpAdjDepth()));
436  m_ChromaQpAdjIdc = ((uiLPelX >> lgMinCuSize) + (uiTPelY >> lgMinCuSize)) % (pcSlice->getPPS()->getChromaQpAdjTableSize() + 1);
437  }
438 
439  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
440 
441  // do inter modes, SKIP and 2Nx2N
442  if( rpcBestCU->getSlice()->getSliceType() != I_SLICE )
443  {
444  // 2Nx2N
445  if(m_pcEncCfg->getUseEarlySkipDetection())
446  {
447  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) );
448  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );//by Competition for inter_2Nx2N
449  }
450  // SKIP
451  xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU DEBUG_STRING_PASS_INTO(sDebug), &earlyDetectionSkipMode );//by Merge for inter_2Nx2N
452  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
453 
454  if(!m_pcEncCfg->getUseEarlySkipDetection())
455  {
456  // 2Nx2N, NxN
457  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) );
458  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
459  if(m_pcEncCfg->getUseCbfFastMode())
460  {
461  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
462  }
463  }
464  }
465 
466  if (bIsLosslessMode) // Restore loop variable if lossless mode was searched.
467  {
468  iQP = iMinQP;
469  }
470  }
471 
472  if(!earlyDetectionSkipMode)
473  {
474  for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
475  {
476  const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP); // If lossless, then iQP is irrelevant for subsequent modules.
477 
478  if (bIsLosslessMode)
479  {
480  iQP = lowestQP;
481  }
482 
483  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
484 
485  // do inter modes, NxN, 2NxN, and Nx2N
486  if( rpcBestCU->getSlice()->getSliceType() != I_SLICE )
487  {
488  // 2Nx2N, NxN
489  if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) ))
490  {
491  if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu)
492  {
493  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN DEBUG_STRING_PASS_INTO(sDebug) );
494  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
495  }
496  }
497 
498  if(doNotBlockPu)
499  {
500  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N DEBUG_STRING_PASS_INTO(sDebug) );
501  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
502  if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_Nx2N )
503  {
504  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
505  }
506  }
507  if(doNotBlockPu)
508  {
509  xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN DEBUG_STRING_PASS_INTO(sDebug) );
510  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
511  if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxN)
512  {
513  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
514  }
515  }
516 
518  if(pcSlice->getSPS()->getUseAMP() && uiDepth < g_uiMaxCUDepth-g_uiAddCUDepth )
519  {
520 #if AMP_ENC_SPEEDUP
521  Bool bTestAMP_Hor = false, bTestAMP_Ver = false;
522 
523 #if AMP_MRG
524  Bool bTestMergeAMP_Hor = false, bTestMergeAMP_Ver = false;
525 
526  deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver, bTestMergeAMP_Hor, bTestMergeAMP_Ver);
527 #else
528  deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver);
529 #endif
530 
532  if ( bTestAMP_Hor )
533  {
534  if(doNotBlockPu)
535  {
536  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU DEBUG_STRING_PASS_INTO(sDebug) );
537  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
538  if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU )
539  {
540  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
541  }
542  }
543  if(doNotBlockPu)
544  {
545  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD DEBUG_STRING_PASS_INTO(sDebug) );
546  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
547  if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD )
548  {
549  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
550  }
551  }
552  }
553 #if AMP_MRG
554  else if ( bTestMergeAMP_Hor )
555  {
556  if(doNotBlockPu)
557  {
558  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU DEBUG_STRING_PASS_INTO(sDebug), true );
559  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
560  if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU )
561  {
562  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
563  }
564  }
565  if(doNotBlockPu)
566  {
567  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD DEBUG_STRING_PASS_INTO(sDebug), true );
568  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
569  if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD )
570  {
571  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
572  }
573  }
574  }
575 #endif
576 
578  if ( bTestAMP_Ver )
579  {
580  if(doNotBlockPu)
581  {
582  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N DEBUG_STRING_PASS_INTO(sDebug) );
583  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
584  if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N )
585  {
586  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
587  }
588  }
589  if(doNotBlockPu)
590  {
591  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N DEBUG_STRING_PASS_INTO(sDebug) );
592  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
593  }
594  }
595 #if AMP_MRG
596  else if ( bTestMergeAMP_Ver )
597  {
598  if(doNotBlockPu)
599  {
600  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N DEBUG_STRING_PASS_INTO(sDebug), true );
601  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
602  if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N )
603  {
604  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
605  }
606  }
607  if(doNotBlockPu)
608  {
609  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N DEBUG_STRING_PASS_INTO(sDebug), true );
610  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
611  }
612  }
613 #endif
614 
615 #else
616  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU );
617  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
618  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD );
619  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
620  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N );
621  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
622 
623  xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N );
624  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
625 
626 #endif
627  }
628  }
629 
630  // do normal intra modes
631  // speedup for inter frames
632  Double intraCost = 0.0;
633 
634  if((rpcBestCU->getSlice()->getSliceType() == I_SLICE) ||
635  (rpcBestCU->getCbf( 0, COMPONENT_Y ) != 0) ||
636  ((rpcBestCU->getCbf( 0, COMPONENT_Cb ) != 0) && (numberValidComponents > COMPONENT_Cb)) ||
637  ((rpcBestCU->getCbf( 0, COMPONENT_Cr ) != 0) && (numberValidComponents > COMPONENT_Cr)) ) // avoid very complex intra if it is unlikely
638  {
639  xCheckRDCostIntra( rpcBestCU, rpcTempCU, intraCost, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) );
640  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
641  if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
642  {
643  if( rpcTempCU->getWidth(0) > ( 1 << rpcTempCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) )
644  {
645  Double tmpIntraCost;
646  xCheckRDCostIntra( rpcBestCU, rpcTempCU, tmpIntraCost, SIZE_NxN DEBUG_STRING_PASS_INTO(sDebug) );
647  intraCost = std::min(intraCost, tmpIntraCost);
648  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
649  }
650  }
651  }
652 
653  // test PCM
654  if(pcPic->getSlice(0)->getSPS()->getUsePCM()
655  && rpcTempCU->getWidth(0) <= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MaxSize())
656  && rpcTempCU->getWidth(0) >= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MinSize()) )
657  {
658  UInt uiRawBits = getTotalBits(rpcBestCU->getWidth(0), rpcBestCU->getHeight(0), rpcBestCU->getPic()->getChromaFormat(), g_bitDepth);
659  UInt uiBestBits = rpcBestCU->getTotalBits();
660  if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > m_pcRdCost->calcRdCost(uiRawBits, 0)))
661  {
662  xCheckIntraPCM (rpcBestCU, rpcTempCU);
663  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
664  }
665  }
666 
667  if (bIsLosslessMode) // Restore loop variable if lossless mode was searched.
668  {
669  iQP = iMinQP;
670  }
671  }
672  }
673 
674  m_pcEntropyCoder->resetBits();
675  m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true );
676  rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits
677  rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
678  rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() );
679 
680  // Early CU determination
681  if( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->isSkipped(0) )
682  {
683  bSubBranch = false;
684  }
685  else
686  {
687  bSubBranch = true;
688  }
689  }
690  else
691  {
692  bBoundary = true;
693  }
694 
695  // copy orginal YUV samples to PCM buffer
696  if( rpcBestCU->isLosslessCoded(0) && (rpcBestCU->getIPCMFlag(0) == false))
697  {
698  xFillPCMBuffer(rpcBestCU, m_ppcOrigYuv[uiDepth]);
699  }
700 
701  if( (g_uiMaxCUWidth>>uiDepth) == (g_uiMaxCUWidth >> ( rpcTempCU->getSlice()->getPPS()->getMaxCuDQPDepth())) )
702  {
703  Int idQP = m_pcEncCfg->getMaxDeltaQP();
704  iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP-idQP );
705  iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP+idQP );
706  }
707  else if( (g_uiMaxCUWidth>>uiDepth) > (g_uiMaxCUWidth >> ( rpcTempCU->getSlice()->getPPS()->getMaxCuDQPDepth())) )
708  {
709  iMinQP = iBaseQP;
710  iMaxQP = iBaseQP;
711  }
712  else
713  {
714  const Int iStartQP = rpcTempCU->getQP(0);
715  iMinQP = iStartQP;
716  iMaxQP = iStartQP;
717  }
718 
719  if ( m_pcEncCfg->getUseRateCtrl() )
720  {
721  iMinQP = m_pcRateCtrl->getRCQP();
722  iMaxQP = m_pcRateCtrl->getRCQP();
723  }
724 
725  if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() )
726  {
727  iMaxQP = iMinQP; // If all TUs are forced into using transquant bypass, do not loop here.
728  }
729 
730  for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
731  {
732  const Bool bIsLosslessMode = false; // False at this level. Next level down may set it to true.
733 
734  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
735 
736  // further split
737  if( bSubBranch && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth )
738  {
739  UChar uhNextDepth = uiDepth+1;
740  TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth];
741  TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth];
742  DEBUG_STRING_NEW(sTempDebug)
743 
744  for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ )
745  {
746  pcSubBestPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init.
747  pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init.
748 
749  if( ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
750  {
751  if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer
752  {
753  m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
754  }
755  else
756  {
757  m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
758  }
759 
760 #if AMP_ENC_SPEEDUP
761  DEBUG_STRING_NEW(sChild)
762  if ( !rpcBestCU->isInter(0) )
763  {
764  xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth DEBUG_STRING_PASS_INTO(sChild), NUMBER_OF_PART_SIZES );
765  }
766  else
767  {
768 
769  xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth DEBUG_STRING_PASS_INTO(sChild), rpcBestCU->getPartitionSize(0) );
770  }
771  DEBUG_STRING_APPEND(sTempDebug, sChild)
772 #else
773  xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth );
774 #endif
775 
776  rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data.
777  xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth );
778  }
779  else
780  {
781  pcSubBestPartCU->copyToPic( uhNextDepth );
782  rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth );
783  }
784  }
785 
786  if( !bBoundary )
787  {
788  m_pcEntropyCoder->resetBits();
789  m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth, true );
790 
791  rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits
792  rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
793  }
794  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
795 
796  if( (g_uiMaxCUWidth>>uiDepth) == (g_uiMaxCUWidth >> ( rpcTempCU->getSlice()->getPPS()->getMaxCuDQPDepth())) && rpcTempCU->getSlice()->getPPS()->getUseDQP())
797  {
798  Bool hasResidual = false;
799  for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++)
800  {
801  if( ( rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Y)
802  || (rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Cb) && (numberValidComponents > COMPONENT_Cb))
803  || (rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Cr) && (numberValidComponents > COMPONENT_Cr)) ) )
804  {
805  hasResidual = true;
806  break;
807  }
808  }
809 
810  UInt uiTargetPartIdx = 0;
811  if ( hasResidual )
812  {
813 #if !RDO_WITHOUT_DQP_BITS
814  m_pcEntropyCoder->resetBits();
815  m_pcEntropyCoder->encodeQP( rpcTempCU, uiTargetPartIdx, false );
816  rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits
817  rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
818  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
819 #endif
820 
821  Bool foundNonZeroCbf = false;
822  rpcTempCU->setQPSubCUs( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uiDepth, foundNonZeroCbf );
823  assert( foundNonZeroCbf );
824  }
825  else
826  {
827  rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uiDepth ); // set QP to default QP
828  }
829  }
830 
831  m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
832 
833  // TODO: this does not account for the slice bytes already written. See other instances of FIXED_NUMBER_OF_BYTES
834  Bool isEndOfSlice = rpcBestCU->getSlice()->getSliceMode()==FIXED_NUMBER_OF_BYTES
835  && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3);
836  Bool isEndOfSliceSegment = rpcBestCU->getSlice()->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES
837  && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceSegmentArgument()<<3);
838  if(isEndOfSlice||isEndOfSliceSegment)
839  {
840  if (m_pcEncCfg->getCostMode()==COST_MIXED_LOSSLESS_LOSSY_CODING)
841  {
842  rpcBestCU->getTotalCost()=rpcTempCU->getTotalCost() + (1.0 / m_pcRdCost->getLambda());
843  }
844  else
845  {
846  rpcBestCU->getTotalCost()=rpcTempCU->getTotalCost()+1;
847  }
848  }
849 
850  xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTempDebug) DEBUG_STRING_PASS_INTO(false) ); // RD compare current larger prediction
851  // with sub partitioned prediction.
852  }
853  }
854 
855  DEBUG_STRING_APPEND(sDebug_, sDebug);
856 
857  rpcBestCU->copyToPic(uiDepth); // Copy Best data to Picture for next partition prediction.
858 
859  xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getCtuRsAddr(), rpcBestCU->getZorderIdxInCtu(), uiDepth, uiDepth, rpcBestCU, uiLPelX, uiTPelY ); // Copy Yuv data to picture Yuv
860  if (bBoundary)
861  {
862  return;
863  }
864 
865  // Assert if Best prediction mode is NONE
866  // Selected mode's RD-cost must be not MAX_DOUBLE.
867  assert( rpcBestCU->getPartitionSize ( 0 ) != NUMBER_OF_PART_SIZES );
868  assert( rpcBestCU->getPredictionMode( 0 ) != NUMBER_OF_PREDICTION_MODES );
869  assert( rpcBestCU->getTotalCost ( ) != MAX_DOUBLE );
870 }
871 
878 Void TEncCu::finishCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
879 {
880  TComPic* pcPic = pcCU->getPic();
881  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
882 
883  //Calculate end address
884  const Int currentCTUTsAddr = pcPic->getPicSym()->getCtuRsToTsAddrMap(pcCU->getCtuRsAddr());
885  const Bool isLastSubCUOfCtu = pcCU->isLastSubCUOfCtu(uiAbsPartIdx);
886  if ( isLastSubCUOfCtu )
887  {
888  // The 1-terminating bit is added to all streams, so don't add it here when it's 1.
889  // i.e. when the slice segment CurEnd CTU address is the current CTU address+1.
890  if (pcSlice->getSliceSegmentCurEndCtuTsAddr() != currentCTUTsAddr+1)
891  {
892  m_pcEntropyCoder->encodeTerminatingBit( 0 );
893  }
894  }
895 }
896 
903 {
904  Int iBaseQp = pcCU->getSlice()->getSliceQp();
905  Int iQpOffset = 0;
906  if ( m_pcEncCfg->getUseAdaptiveQP() )
907  {
908  TEncPic* pcEPic = dynamic_cast<TEncPic*>( pcCU->getPic() );
909  UInt uiAQDepth = min( uiDepth, pcEPic->getMaxAQDepth()-1 );
910  TEncPicQPAdaptationLayer* pcAQLayer = pcEPic->getAQLayer( uiAQDepth );
911  UInt uiAQUPosX = pcCU->getCUPelX() / pcAQLayer->getAQPartWidth();
912  UInt uiAQUPosY = pcCU->getCUPelY() / pcAQLayer->getAQPartHeight();
913  UInt uiAQUStride = pcAQLayer->getAQPartStride();
914  TEncQPAdaptationUnit* acAQU = pcAQLayer->getQPAdaptationUnit();
915 
916  Double dMaxQScale = pow(2.0, m_pcEncCfg->getQPAdaptationRange()/6.0);
917  Double dAvgAct = pcAQLayer->getAvgActivity();
918  Double dCUAct = acAQU[uiAQUPosY * uiAQUStride + uiAQUPosX].getActivity();
919  Double dNormAct = (dMaxQScale*dCUAct + dAvgAct) / (dCUAct + dMaxQScale*dAvgAct);
920  Double dQpOffset = log(dNormAct) / log(2.0) * 6.0;
921  iQpOffset = Int(floor( dQpOffset + 0.49999 ));
922  }
923 
924  return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQp+iQpOffset );
925 }
926 
933 Void TEncCu::xEncodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
934 {
935  TComPic* pcPic = pcCU->getPic();
936 
937  Bool bBoundary = false;
938  UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
939  UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1;
940  UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
941  UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
942 
943  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
944  if( ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
945  {
946  m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
947  }
948  else
949  {
950  bBoundary = true;
951  }
952 
953  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < (g_uiMaxCUDepth-g_uiAddCUDepth) ) ) || bBoundary )
954  {
955  UInt uiQNumParts = ( pcPic->getNumPartitionsInCtu() >> (uiDepth<<1) )>>2;
956  if( (g_uiMaxCUWidth>>uiDepth) == (g_uiMaxCUWidth >> ( pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())) && pcCU->getSlice()->getPPS()->getUseDQP())
957  {
958  setdQPFlag(true);
959  }
960 
961  if( (g_uiMaxCUWidth>>uiDepth) == (g_uiMaxCUWidth >> ( pcCU->getSlice()->getPPS()->getMaxCuChromaQpAdjDepth())) && pcCU->getSlice()->getUseChromaQpAdj())
962  {
963  setCodeChromaQpAdjFlag(true);
964  }
965 
966  for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts )
967  {
968  uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
969  uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
970  if( ( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
971  {
972  xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 );
973  }
974  }
975  return;
976  }
977 
978  if( (g_uiMaxCUWidth>>uiDepth) >= (g_uiMaxCUWidth >> ( pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())) && pcCU->getSlice()->getPPS()->getUseDQP())
979  {
980  setdQPFlag(true);
981  }
982 
983  if( (g_uiMaxCUWidth>>uiDepth) >= (g_uiMaxCUWidth >> ( pcCU->getSlice()->getPPS()->getMaxCuChromaQpAdjDepth())) && pcCU->getSlice()->getUseChromaQpAdj())
984  {
985  setCodeChromaQpAdjFlag(true);
986  }
987 
989  {
990  m_pcEntropyCoder->encodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx );
991  }
992 
993  if( !pcCU->getSlice()->isIntra() )
994  {
995  m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx );
996  }
997 
998  if( pcCU->isSkipped( uiAbsPartIdx ) )
999  {
1000  m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx );
1001  finishCU(pcCU,uiAbsPartIdx,uiDepth);
1002  return;
1003  }
1004 
1005  m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx );
1006  m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth );
1007 
1008  if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N )
1009  {
1010  m_pcEntropyCoder->encodeIPCMInfo( pcCU, uiAbsPartIdx );
1011 
1012  if(pcCU->getIPCMFlag(uiAbsPartIdx))
1013  {
1014  // Encode slice finish
1015  finishCU(pcCU,uiAbsPartIdx,uiDepth);
1016  return;
1017  }
1018  }
1019 
1020  // prediction Info ( Intra : direction mode, Inter : Mv, reference idx )
1021  m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx );
1022 
1023  // Encode Coefficients
1024  Bool bCodeDQP = getdQPFlag();
1025  Bool codeChromaQpAdj = getCodeChromaQpAdjFlag();
1026  m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, bCodeDQP, codeChromaQpAdj );
1027  setCodeChromaQpAdjFlag( codeChromaQpAdj );
1028  setdQPFlag( bCodeDQP );
1029 
1030  // --- write terminating bit ---
1031  finishCU(pcCU,uiAbsPartIdx,uiDepth);
1032 }
1033 
1034 Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg)
1035 {
1036  Int k, i, j, jj;
1037  Int diff[64], m1[8][8], m2[8][8], m3[8][8], iSumHad = 0;
1038 
1039  for( k = 0; k < 64; k += 8 )
1040  {
1041  diff[k+0] = piOrg[0] ;
1042  diff[k+1] = piOrg[1] ;
1043  diff[k+2] = piOrg[2] ;
1044  diff[k+3] = piOrg[3] ;
1045  diff[k+4] = piOrg[4] ;
1046  diff[k+5] = piOrg[5] ;
1047  diff[k+6] = piOrg[6] ;
1048  diff[k+7] = piOrg[7] ;
1049 
1050  piOrg += iStrideOrg;
1051  }
1052 
1053  //horizontal
1054  for (j=0; j < 8; j++)
1055  {
1056  jj = j << 3;
1057  m2[j][0] = diff[jj ] + diff[jj+4];
1058  m2[j][1] = diff[jj+1] + diff[jj+5];
1059  m2[j][2] = diff[jj+2] + diff[jj+6];
1060  m2[j][3] = diff[jj+3] + diff[jj+7];
1061  m2[j][4] = diff[jj ] - diff[jj+4];
1062  m2[j][5] = diff[jj+1] - diff[jj+5];
1063  m2[j][6] = diff[jj+2] - diff[jj+6];
1064  m2[j][7] = diff[jj+3] - diff[jj+7];
1065 
1066  m1[j][0] = m2[j][0] + m2[j][2];
1067  m1[j][1] = m2[j][1] + m2[j][3];
1068  m1[j][2] = m2[j][0] - m2[j][2];
1069  m1[j][3] = m2[j][1] - m2[j][3];
1070  m1[j][4] = m2[j][4] + m2[j][6];
1071  m1[j][5] = m2[j][5] + m2[j][7];
1072  m1[j][6] = m2[j][4] - m2[j][6];
1073  m1[j][7] = m2[j][5] - m2[j][7];
1074 
1075  m2[j][0] = m1[j][0] + m1[j][1];
1076  m2[j][1] = m1[j][0] - m1[j][1];
1077  m2[j][2] = m1[j][2] + m1[j][3];
1078  m2[j][3] = m1[j][2] - m1[j][3];
1079  m2[j][4] = m1[j][4] + m1[j][5];
1080  m2[j][5] = m1[j][4] - m1[j][5];
1081  m2[j][6] = m1[j][6] + m1[j][7];
1082  m2[j][7] = m1[j][6] - m1[j][7];
1083  }
1084 
1085  //vertical
1086  for (i=0; i < 8; i++)
1087  {
1088  m3[0][i] = m2[0][i] + m2[4][i];
1089  m3[1][i] = m2[1][i] + m2[5][i];
1090  m3[2][i] = m2[2][i] + m2[6][i];
1091  m3[3][i] = m2[3][i] + m2[7][i];
1092  m3[4][i] = m2[0][i] - m2[4][i];
1093  m3[5][i] = m2[1][i] - m2[5][i];
1094  m3[6][i] = m2[2][i] - m2[6][i];
1095  m3[7][i] = m2[3][i] - m2[7][i];
1096 
1097  m1[0][i] = m3[0][i] + m3[2][i];
1098  m1[1][i] = m3[1][i] + m3[3][i];
1099  m1[2][i] = m3[0][i] - m3[2][i];
1100  m1[3][i] = m3[1][i] - m3[3][i];
1101  m1[4][i] = m3[4][i] + m3[6][i];
1102  m1[5][i] = m3[5][i] + m3[7][i];
1103  m1[6][i] = m3[4][i] - m3[6][i];
1104  m1[7][i] = m3[5][i] - m3[7][i];
1105 
1106  m2[0][i] = m1[0][i] + m1[1][i];
1107  m2[1][i] = m1[0][i] - m1[1][i];
1108  m2[2][i] = m1[2][i] + m1[3][i];
1109  m2[3][i] = m1[2][i] - m1[3][i];
1110  m2[4][i] = m1[4][i] + m1[5][i];
1111  m2[5][i] = m1[4][i] - m1[5][i];
1112  m2[6][i] = m1[6][i] + m1[7][i];
1113  m2[7][i] = m1[6][i] - m1[7][i];
1114  }
1115 
1116  for (i = 0; i < 8; i++)
1117  {
1118  for (j = 0; j < 8; j++)
1119  {
1120  iSumHad += abs(m2[i][j]);
1121  }
1122  }
1123  iSumHad -= abs(m2[0][0]);
1124  iSumHad =(iSumHad+2)>>2;
1125  return(iSumHad);
1126 }
1127 
1129 {
1130  Int xBl, yBl;
1131  const Int iBlkSize = 8;
1132 
1133  Pel* pOrgInit = pCtu->getPic()->getPicYuvOrg()->getAddr(COMPONENT_Y, pCtu->getCtuRsAddr(), 0);
1134  Int iStrideOrig = pCtu->getPic()->getPicYuvOrg()->getStride(COMPONENT_Y);
1135  Pel *pOrg;
1136 
1137  Int iSumHad = 0;
1138  for ( yBl=0; (yBl+iBlkSize)<=height; yBl+= iBlkSize)
1139  {
1140  for ( xBl=0; (xBl+iBlkSize)<=width; xBl+= iBlkSize)
1141  {
1142  pOrg = pOrgInit + iStrideOrig*yBl + xBl;
1143  iSumHad += xCalcHADs8x8_ISlice(pOrg, iStrideOrig);
1144  }
1145  }
1146  return(iSumHad);
1147 }
1148 
1154 Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU DEBUG_STRING_FN_DECLARE(sDebug), Bool *earlyDetectionSkipMode )
1155 {
1156  assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE );
1157  TComMvField cMvFieldNeighbours[2 * MRG_MAX_NUM_CANDS]; // double length for mv of both lists
1158  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
1159  Int numValidMergeCand = 0;
1160  const Bool bTransquantBypassFlag = rpcTempCU->getCUTransquantBypass(0);
1161 
1162  for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui )
1163  {
1164  uhInterDirNeighbours[ui] = 0;
1165  }
1166  UChar uhDepth = rpcTempCU->getDepth( 0 );
1167  rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to CTU level
1168  rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand );
1169 
1170  Int mergeCandBuffer[MRG_MAX_NUM_CANDS];
1171  for( UInt ui = 0; ui < numValidMergeCand; ++ui )
1172  {
1173  mergeCandBuffer[ui] = 0;
1174  }
1175 
1176  Bool bestIsSkip = false;
1177 
1178  UInt iteration;
1179  if ( rpcTempCU->isLosslessCoded(0))
1180  {
1181  iteration = 1;
1182  }
1183  else
1184  {
1185  iteration = 2;
1186  }
1187  DEBUG_STRING_NEW(bestStr)
1188 
1189  for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual )
1190  {
1191  for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
1192  {
1193  if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1))
1194  {
1195  if( !(bestIsSkip && uiNoResidual == 0) )
1196  {
1197  DEBUG_STRING_NEW(tmpStr)
1198  // set MC parameters
1199  rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to CTU level
1200  rpcTempCU->setCUTransquantBypassSubParts( bTransquantBypassFlag, 0, uhDepth );
1201  rpcTempCU->setChromaQpAdjSubParts( bTransquantBypassFlag ? 0 : m_ChromaQpAdjIdc, 0, uhDepth );
1202  rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to CTU level
1203  rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to CTU level
1204  rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to CTU level
1205  rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to CTU level
1206  rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
1207  rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
1208 
1209  // do MC
1210  m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
1211  // estimate residual and encode everything
1212  m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU,
1213  m_ppcOrigYuv [uhDepth],
1214  m_ppcPredYuvTemp[uhDepth],
1215  m_ppcResiYuvTemp[uhDepth],
1216  m_ppcResiYuvBest[uhDepth],
1217  m_ppcRecoYuvTemp[uhDepth],
1218  (uiNoResidual != 0) DEBUG_STRING_PASS_INTO(tmpStr) );
1219 
1220 #ifdef DEBUG_STRING
1221  DebugInterPredResiReco(tmpStr, *(m_ppcPredYuvTemp[uhDepth]), *(m_ppcResiYuvBest[uhDepth]), *(m_ppcRecoYuvTemp[uhDepth]), DebugStringGetPredModeMask(rpcTempCU->getPredictionMode(0)));
1222 #endif
1223 
1224  if ((uiNoResidual == 0) && (rpcTempCU->getQtRootCbf(0) == 0))
1225  {
1226  // If no residual when allowing for one, then set mark to not try case where residual is forced to 0
1227  mergeCandBuffer[uiMergeCand] = 1;
1228  }
1229 
1230  Int orgQP = rpcTempCU->getQP( 0 );
1231  xCheckDQP( rpcTempCU );
1232  xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth DEBUG_STRING_PASS_INTO(bestStr) DEBUG_STRING_PASS_INTO(tmpStr));
1233 
1234  rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag );
1235 
1236  if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip )
1237  {
1238  bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0;
1239  }
1240  }
1241  }
1242  }
1243 
1244  if(uiNoResidual == 0 && m_pcEncCfg->getUseEarlySkipDetection())
1245  {
1246  if(rpcBestCU->getQtRootCbf( 0 ) == 0)
1247  {
1248  if( rpcBestCU->getMergeFlag( 0 ))
1249  {
1250  *earlyDetectionSkipMode = true;
1251  }
1252  else if(m_pcEncCfg->getFastSearch() != SELECTIVE)
1253  {
1254  Int absoulte_MV=0;
1255  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
1256  {
1257  if ( rpcBestCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
1258  {
1259  TComCUMvField* pcCUMvField = rpcBestCU->getCUMvField(RefPicList( uiRefListIdx ));
1260  Int iHor = pcCUMvField->getMvd( 0 ).getAbsHor();
1261  Int iVer = pcCUMvField->getMvd( 0 ).getAbsVer();
1262  absoulte_MV+=iHor+iVer;
1263  }
1264  }
1265 
1266  if(absoulte_MV == 0)
1267  {
1268  *earlyDetectionSkipMode = true;
1269  }
1270  }
1271  }
1272  }
1273  }
1274  DEBUG_STRING_APPEND(sDebug, bestStr)
1275 }
1276 
1277 
1278 #if AMP_MRG
1279 Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize DEBUG_STRING_FN_DECLARE(sDebug), Bool bUseMRG)
1280 #else
1281 Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize )
1282 #endif
1283 {
1284  DEBUG_STRING_NEW(sTest)
1285 
1286  // prior to this, rpcTempCU will have just been reset using rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
1287  UChar uhDepth = rpcTempCU->getDepth( 0 );
1288 
1289  rpcTempCU->setPartSizeSubParts ( ePartSize, 0, uhDepth );
1290  rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth );
1291  rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_ChromaQpAdjIdc, 0, uhDepth );
1292 
1293 #if AMP_MRG
1294  rpcTempCU->setMergeAMP (true);
1295  m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] DEBUG_STRING_PASS_INTO(sTest), false, bUseMRG );
1296 #else
1297  m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] );
1298 #endif
1299 
1300 #if AMP_MRG
1301  if ( !rpcTempCU->getMergeAMP() )
1302  {
1303  return;
1304  }
1305 #endif
1306 
1307  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) );
1308  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
1309 
1310 #ifdef DEBUG_STRING
1311  DebugInterPredResiReco(sTest, *(m_ppcPredYuvTemp[uhDepth]), *(m_ppcResiYuvBest[uhDepth]), *(m_ppcRecoYuvTemp[uhDepth]), DebugStringGetPredModeMask(rpcTempCU->getPredictionMode(0)));
1312 #endif
1313 
1314  xCheckDQP( rpcTempCU );
1315  xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest));
1316 }
1317 
1319  TComDataCU *&rpcTempCU,
1320  Double &cost,
1321  PartSize eSize
1322  DEBUG_STRING_FN_DECLARE(sDebug) )
1323 {
1324  DEBUG_STRING_NEW(sTest)
1325 
1326  UInt uiDepth = rpcTempCU->getDepth( 0 );
1327 
1328  rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth );
1329 
1330  rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth );
1331  rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth );
1332  rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_ChromaQpAdjIdc, 0, uiDepth );
1333 
1335 
1336  m_pcPredSearch->estIntraPredLumaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], resiLuma DEBUG_STRING_PASS_INTO(sTest) );
1337 
1338  m_ppcRecoYuvTemp[uiDepth]->copyToPicComponent(COMPONENT_Y, rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getCtuRsAddr(), rpcTempCU->getZorderIdxInCtu() );
1339 
1340  if (rpcBestCU->getPic()->getChromaFormat()!=CHROMA_400)
1341  {
1342  m_pcPredSearch->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], resiLuma DEBUG_STRING_PASS_INTO(sTest) );
1343  }
1344 
1345  m_pcEntropyCoder->resetBits();
1346 
1347  if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
1348  {
1349  m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true );
1350  }
1351 
1352  m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true );
1353  m_pcEntropyCoder->encodePredMode( rpcTempCU, 0, true );
1354  m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true );
1355  m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0 );
1356  m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0, true );
1357 
1358  // Encode Coefficients
1359  Bool bCodeDQP = getdQPFlag();
1360  Bool codeChromaQpAdjFlag = getCodeChromaQpAdjFlag();
1361  m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, bCodeDQP, codeChromaQpAdjFlag );
1362  setCodeChromaQpAdjFlag( codeChromaQpAdjFlag );
1363  setdQPFlag( bCodeDQP );
1364 
1365  m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
1366 
1367  rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits();
1368  rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
1369  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
1370 
1371  xCheckDQP( rpcTempCU );
1372 
1373  cost = rpcTempCU->getTotalCost();
1374 
1375  xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest));
1376 }
1377 
1378 
1387 {
1388  UInt uiDepth = rpcTempCU->getDepth( 0 );
1389 
1390  rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth );
1391 
1392  rpcTempCU->setIPCMFlag(0, true);
1393  rpcTempCU->setIPCMFlagSubParts (true, 0, rpcTempCU->getDepth(0));
1394  rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );
1395  rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth );
1396  rpcTempCU->setTrIdxSubParts ( 0, 0, uiDepth );
1397  rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_ChromaQpAdjIdc, 0, uiDepth );
1398 
1399  m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]);
1400 
1401  m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
1402 
1403  m_pcEntropyCoder->resetBits();
1404 
1405  if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
1406  {
1407  m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true );
1408  }
1409 
1410  m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true );
1411  m_pcEntropyCoder->encodePredMode ( rpcTempCU, 0, true );
1412  m_pcEntropyCoder->encodePartSize ( rpcTempCU, 0, uiDepth, true );
1413  m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true );
1414 
1415  m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
1416 
1417  rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits();
1418  rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
1419  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
1420 
1421  xCheckDQP( rpcTempCU );
1422  DEBUG_STRING_NEW(a)
1423  DEBUG_STRING_NEW(b)
1424  xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(a) DEBUG_STRING_PASS_INTO(b));
1425 }
1426 
1433 {
1434  if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() )
1435  {
1436  TComYuv* pcYuv;
1437  // Change Information data
1438  TComDataCU* pcCU = rpcBestCU;
1439  rpcBestCU = rpcTempCU;
1440  rpcTempCU = pcCU;
1441 
1442  // Change Prediction data
1443  pcYuv = m_ppcPredYuvBest[uiDepth];
1444  m_ppcPredYuvBest[uiDepth] = m_ppcPredYuvTemp[uiDepth];
1445  m_ppcPredYuvTemp[uiDepth] = pcYuv;
1446 
1447  // Change Reconstruction data
1448  pcYuv = m_ppcRecoYuvBest[uiDepth];
1449  m_ppcRecoYuvBest[uiDepth] = m_ppcRecoYuvTemp[uiDepth];
1450  m_ppcRecoYuvTemp[uiDepth] = pcYuv;
1451 
1452  pcYuv = NULL;
1453  pcCU = NULL;
1454 
1455  // store temp best CI for next CU coding
1456  m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]);
1457 
1458 
1459 #ifdef DEBUG_STRING
1460  DEBUG_STRING_SWAP(sParent, sTest)
1461  const PredMode predMode=rpcBestCU->getPredictionMode(0);
1462  if ((DebugOptionList::DebugString_Structure.getInt()&DebugStringGetPredModeMask(predMode)) && bAddSizeInfo)
1463  {
1464  std::stringstream ss(stringstream::out);
1465  ss <<"###: " << (predMode==MODE_INTRA?"Intra ":"Inter ") << partSizeToString[rpcBestCU->getPartitionSize(0)] << " CU at " << rpcBestCU->getCUPelX() << ", " << rpcBestCU->getCUPelY() << " width=" << UInt(rpcBestCU->getWidth(0)) << std::endl;
1466  sParent+=ss.str();
1467  }
1468 #endif
1469  }
1470 }
1471 
1473 {
1474  UInt uiDepth = pcCU->getDepth( 0 );
1475 
1476  if( pcCU->getSlice()->getPPS()->getUseDQP() && (g_uiMaxCUWidth>>uiDepth) >= (g_uiMaxCUWidth >> ( pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())) )
1477  {
1478  if ( pcCU->getQtRootCbf( 0) )
1479  {
1480 #if !RDO_WITHOUT_DQP_BITS
1481  m_pcEntropyCoder->resetBits();
1482  m_pcEntropyCoder->encodeQP( pcCU, 0, false );
1483  pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits
1484  pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
1485  pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() );
1486 #endif
1487  }
1488  else
1489  {
1490  pcCU->setQPSubParts( pcCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP
1491  }
1492  }
1493 }
1494 
1496 {
1497  pDst->iN = pSrc->iN;
1498  for (Int i = 0; i < pSrc->iN; i++)
1499  {
1500  pDst->m_acMvCand[i] = pSrc->m_acMvCand[i];
1501  }
1502 }
1503 Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth, TComDataCU* pcCU, UInt uiLPelX, UInt uiTPelY )
1504 {
1505  UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx];
1506  UInt uiSrcBlkWidth = rpcPic->getNumPartInCtuWidth() >> (uiSrcDepth);
1507  UInt uiBlkWidth = rpcPic->getNumPartInCtuWidth() >> (uiDepth);
1508  UInt uiPartIdxX = ( ( uiAbsPartIdxInRaster % rpcPic->getNumPartInCtuWidth() ) % uiSrcBlkWidth) / uiBlkWidth;
1509  UInt uiPartIdxY = ( ( uiAbsPartIdxInRaster / rpcPic->getNumPartInCtuWidth() ) % uiSrcBlkWidth) / uiBlkWidth;
1510  UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX;
1511  m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx);
1512 
1513  m_ppcPredYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvPred (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx);
1514 }
1515 
1516 Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth )
1517 {
1518  UInt uiCurrDepth = uiNextDepth - 1;
1519  m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx );
1520  m_ppcPredYuvBest[uiNextDepth]->copyToPartYuv( m_ppcPredYuvBest[uiCurrDepth], uiPartUnitIdx);
1521 }
1522 
1528 {
1529  const ChromaFormat format = pCU->getPic()->getChromaFormat();
1530  const UInt numberValidComponents = getNumberValidComponents(format);
1531  for (UInt componentIndex = 0; componentIndex < numberValidComponents; componentIndex++)
1532  {
1533  const ComponentID component = ComponentID(componentIndex);
1534 
1535  const UInt width = pCU->getWidth(0) >> getComponentScaleX(component, format);
1536  const UInt height = pCU->getHeight(0) >> getComponentScaleY(component, format);
1537 
1538  Pel *source = pOrgYuv->getAddr(component, 0, width);
1539  Pel *destination = pCU->getPCMSample(component);
1540 
1541  const UInt sourceStride = pOrgYuv->getStride(component);
1542 
1543  for (Int line = 0; line < height; line++)
1544  {
1545  for (Int column = 0; column < width; column++)
1546  {
1547  destination[column] = source[column];
1548  }
1549 
1550  source += sourceStride;
1551  destination += width;
1552  }
1553  }
1554 }
1555 
1556 #if ADAPTIVE_QP_SELECTION
1557 
1559 Int TEncCu::xTuCollectARLStats(TCoeff* rpcCoeff, TCoeff* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples )
1560 {
1561  for( Int n = 0; n < NumCoeffInCU; n++ )
1562  {
1563  TCoeff u = abs( rpcCoeff[ n ] );
1564  TCoeff absc = rpcArlCoeff[ n ];
1565 
1566  if( u != 0 )
1567  {
1568  if( u < LEVEL_RANGE )
1569  {
1570  cSum[ u ] += ( Double )absc;
1571  numSamples[ u ]++;
1572  }
1573  else
1574  {
1575  cSum[ LEVEL_RANGE ] += ( Double )absc - ( Double )( u << ARL_C_PRECISION );
1576  numSamples[ LEVEL_RANGE ]++;
1577  }
1578  }
1579  }
1580 
1581  return 0;
1582 }
1583 
1586 {
1587  Double cSum[ LEVEL_RANGE + 1 ]; //: the sum of DCT coefficients corresponding to data type and quantization output
1588  UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to data type and quantization output
1589 
1590  TCoeff* pCoeffY = pCtu->getCoeff(COMPONENT_Y);
1591  TCoeff* pArlCoeffY = pCtu->getArlCoeff(COMPONENT_Y);
1592 
1593  UInt uiMinCUWidth = g_uiMaxCUWidth >> g_uiMaxCUDepth;
1594  UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth;
1595 
1596  memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) );
1597  memset( numSamples, 0, sizeof( UInt )*(LEVEL_RANGE+1) );
1598 
1599  // Collect stats to cSum[][] and numSamples[][]
1600  for(Int i = 0; i < pCtu->getTotalNumPart(); i ++ )
1601  {
1602  UInt uiTrIdx = pCtu->getTransformIdx(i);
1603 
1604  if(pCtu->isInter(i) && pCtu->getCbf( i, COMPONENT_Y, uiTrIdx ) )
1605  {
1606  xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples);
1607  }//Note that only InterY is processed. QP rounding is based on InterY data only.
1608 
1609  pCoeffY += uiMinNumCoeffInCU;
1610  pArlCoeffY += uiMinNumCoeffInCU;
1611  }
1612 
1613  for(Int u=1; u<LEVEL_RANGE;u++)
1614  {
1615  m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ;
1616  m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ;
1617  }
1618  m_pcTrQuant->getSliceSumC()[LEVEL_RANGE] += cSum[ LEVEL_RANGE ] ;
1619  m_pcTrQuant->getSliceNSamples()[LEVEL_RANGE] += numSamples[ LEVEL_RANGE ] ;
1620 }
1621 #endif
1622 
#define MAX_CU_SIZE
Definition: TComRom.h:54
Void xCopyYuv2Pic(TComPic *rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth, TComDataCU *pcCU, UInt uiLPelX, UInt uiTPelY)
Definition: TEncCu.cpp:1503
Void xCheckIntraPCM(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU)
Definition: TEncCu.cpp:1386
UInt g_uiMaxCUDepth
Definition: TComRom.cpp:253
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:274
Void setIPCMFlag(UInt uiIdx, Bool b)
Definition: TComDataCU.h:352
Char * getQP()
Definition: TComDataCU.h:255
TEncSbac *** getRDSbacCoder()
Definition: TEncTop.h:152
Int getLog2MinCodingBlockSize() const
Definition: TComSlice.h:839
Void xFillPCMBuffer(TComDataCU *pCU, TComYuv *pOrgYuv)
Definition: TEncCu.cpp:1527
UInt & getTotalBins()
Definition: TComDataCU.h:467
SliceType getSliceType() const
Definition: TComSlice.h:1337
CU data structure class.
Definition: TComDataCU.h:64
TCoeff * getArlCoeff(ComponentID component)
Definition: TComDataCU.h:299
Void encodeCtu(TComDataCU *pCtu)
CTU encoding function.
Definition: TEncCu.cpp:252
encoder analyzer class (header)
TEncRateCtrl * getRateCtrl()
Definition: TEncTop.h:154
UChar getQtRootCbf(UInt uiIdx)
Int updateCtuDataISlice(TComDataCU *pCtu, Int width, Int height)
Definition: TEncCu.cpp:1128
Void setMergeFlagSubParts(Bool bMergeFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
SliceConstraint getSliceMode() const
Definition: TComSlice.h:1463
picture class (symbol + YUV buffers)
Definition: TComPic.h:56
void Void
Definition: TypeDef.h:285
Void create(ChromaFormat chromaFormatIDC, UInt uiNumPartition, UInt uiWidth, UInt uiHeight, Bool bDecSubCu, Int unitSize, Bool bGlobalRMARLBuffer=false)
Definition: TComDataCU.cpp:114
Int getStride(const ComponentID id) const
Definition: TComPicYuv.h:113
Void destroy()
destroy internal buffers
Definition: TEncCu.cpp:112
best mode index
Definition: TypeDef.h:479
UInt g_auiRasterToPelX[((1<<(6))/4)*((1<<(6))/4)]
Definition: TComRom.cpp:257
UChar * getTransformIdx()
Definition: TComDataCU.h:274
#define NULL
Definition: CommonDef.h:100
Void xCopyAMVPInfo(AMVPInfo *pSrc, AMVPInfo *pDst)
Definition: TEncCu.cpp:1495
Coding Unit (CU) encoder class (header)
Bool isSkipped(UInt uiPartIdx)
returns true, if the partiton is skipped
Void xCheckBestMode(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, UInt uiDepth)
Definition: TEncCu.cpp:1432
TComSlice * getSlice(Int i)
Definition: TComPic.h:103
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:1347
Void xCtuCollectARLStats(TComDataCU *pCtu)
Collect ARL statistics from one CTU.
Definition: TEncCu.cpp:1585
Void xCheckDQP(TComDataCU *pcCU)
Definition: TEncCu.cpp:1472
Int xTuCollectARLStats(TCoeff *rpcCoeff, TCoeff *rpcArlCoeff, Int NumCoeffInCU, Double *cSum, UInt *numSamples)
Definition: TEncCu.cpp:1559
unsigned int UInt
Definition: TypeDef.h:297
SliceConstraint getSliceSegmentMode() const
Definition: TComSlice.h:1474
UInt getNumPartitionsInCtu() const
Definition: TComPic.h:119
static UInt getComponentScaleX(const ComponentID id, const ChromaFormat fmt)
Short Pel
pixel type
Definition: TypeDef.h:692
UInt getPCMLog2MaxSize() const
Definition: TComSlice.h:853
symmetric motion partition, 2Nx N
Definition: TypeDef.h:396
Void initSubCU(TComDataCU *pcCU, UInt uiPartUnitIdx, UInt uiDepth, Int qp)
Definition: TComDataCU.cpp:635
STL namespace.
UInt getStride(const ComponentID id) const
Definition: TComYuv.h:197
UInt g_uiAddCUDepth
Definition: TComRom.cpp:254
Int getNumberValidComponents() const
Definition: TComPic.h:129
Void copyPartFrom(TComDataCU *pcCU, UInt uiPartUnitIdx, UInt uiDepth)
Definition: TComDataCU.cpp:871
TComMv const & getMvd(Int iIdx) const
Picture class including local image characteristics information for QP adaptation.
Definition: TEncPic.h:95
TEncEntropy * getEntropyCoder()
Definition: TEncTop.h:146
#define DEBUG_STRING_SWAP(srt1, str2)
Definition: TypeDef.h:76
Int getAbsVer() const
Definition: TComMv.h:91
#define MAX_QP
Definition: CommonDef.h:127
Int getNumRefIdx(RefPicList e) const
Definition: TComSlice.h:1353
UInt getCtuRsToTsAddrMap(Int ctuRsAddr) const
Definition: TComPicSym.h:152
UChar getCbf(UInt uiIdx, ComponentID eType)
Definition: TComDataCU.h:303
UInt getZorderIdxInCtu() const
Definition: TComDataCU.h:209
#define LEVEL_RANGE
G382: max coefficient level in statistics collection.
Definition: TypeDef.h:151
Distortion & getTotalDistortion()
Definition: TComDataCU.h:473
Bool isInter(UInt uiPartIdx) const
Definition: TComDataCU.h:444
temporal index
Definition: TypeDef.h:481
Bool getTransquantBypassEnableFlag() const
Definition: TComSlice.h:1116
TComPicYuv * getPicYuvRec()
Definition: TComPic.h:109
TEncSbac * getRDGoOnSbacCoder()
Definition: TEncTop.h:153
Void setPartSizeSubParts(PartSize eMode, UInt uiAbsPartIdx, UInt uiDepth)
class for motion information in one CU
Void xEncodeCU(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
Definition: TEncCu.cpp:933
PartSize
supported partition shape
Definition: TypeDef.h:393
UInt getNumPartInCtuWidth() const
Definition: TComPic.h:117
Bool * getIPCMFlag()
Definition: TComDataCU.h:350
Double & getTotalCost()
Definition: TComDataCU.h:472
Limit maximum number of bytes in a slice / slice segment.
Definition: TypeDef.h:566
Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg)
Definition: TEncCu.cpp:1034
UInt getMaxNumMergeCand() const
Definition: TComSlice.h:1451
Int iN
number of motion vector predictor candidates
symmetric motion partition, 2Nx2N
Definition: TypeDef.h:395
general YUV buffer class
Definition: TComYuv.h:54
Int getQpBDOffset(ChannelType type) const
Definition: TComSlice.h:885
Void copyToPic(UChar uiDepth)
Definition: TComDataCU.cpp:957
Double getActivity()
Definition: TEncPic.h:62
bool Bool
Definition: TypeDef.h:286
Void setAllMvField(TComMvField const &mvField, PartSize eMbMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0)
Bool isIntra(UInt uiPartIdx) const
Definition: TComDataCU.h:443
Void setQPSubCUs(Int qp, UInt absPartIdx, UInt depth, Bool &foundNonZeroCbf)
Void initRasterToPelXY(UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth)
Definition: TComRom.cpp:295
Void setCUTransquantBypassSubParts(Bool flag, UInt uiAbsPartIdx, UInt uiDepth)
UInt g_uiMaxCUHeight
Definition: TComRom.cpp:252
Selective search.
Definition: TypeDef.h:517
Void setInterDirSubParts(UInt uiDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
UInt g_uiMaxCUWidth
Definition: TComRom.cpp:251
asymmetric motion partition, 2Nx( N/2) + 2Nx(3N/2)
Definition: TypeDef.h:399
Char getRefQP(UInt uiCurrAbsIdxInCtu)
asymmetric motion partition, (3N/2)x2N + ( N/2)x2N
Definition: TypeDef.h:402
parameters for AMVP
UInt & getCtuRsAddr()
Definition: TComDataCU.h:207
UInt getPicHeightInLumaSamples() const
Definition: TComSlice.h:824
UInt getPCMLog2MinSize() const
Definition: TComSlice.h:855
TComTrQuant * getTrQuant()
Definition: TEncTop.h:140
Void create(const UInt iWidth, const UInt iHeight, const ChromaFormat chromaFormatIDC)
Create YUV buffer.
Definition: TComYuv.cpp:63
UInt getCUPelY() const
Definition: TComDataCU.h:211
T Clip3(const T minVal, const T maxVal, const T a)
general min/max clip
Definition: CommonDef.h:137
Void initRasterToZscan(UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth)
Definition: TComRom.cpp:281
#define DEBUG_STRING_APPEND(str1, str2)
Definition: TypeDef.h:75
TComPicYuv * getPicYuvOrg()
Definition: TComPic.h:108
reference list 0
Definition: TypeDef.h:417
Int TCoeff
transform coefficient
Definition: TypeDef.h:693
Void compressCtu(TComDataCU *pCtu)
CTU analysis function.
Definition: TEncCu.cpp:228
UInt g_auiZscanToRaster[((1<<(6))/4)*((1<<(6))/4)]
Definition: TComRom.cpp:255
Bool getUseDQP() const
Definition: TComSlice.h:1048
Pel * getAddr(const ComponentID id)
Definition: TComYuv.h:148
RefPicList
reference list index
Definition: TypeDef.h:415
TComPicSym * getPicSym()
Definition: TComPic.h:102
UInt getMaxCuDQPDepth() const
Definition: TComSlice.h:1056
ChromaFormat
chroma formats (according to semantics of chroma_format_idc)
Definition: TypeDef.h:352
Void init(TEncTop *pcEncTop)
copy parameters from encoder class
Definition: TEncCu.cpp:205
intra-prediction mode
Definition: TypeDef.h:410
unsigned char UChar
Definition: TypeDef.h:293
UInt getQuadtreeTULog2MinSize() const
Definition: TComSlice.h:863
Local image characteristics for CUs on a specific depth.
Definition: TEncPic.h:66
UInt g_auiRasterToPelY[((1<<(6))/4)*((1<<(6))/4)]
Definition: TComRom.cpp:258
UChar * getDepth()
Definition: TComDataCU.h:213
Void setChromaQpAdjSubParts(UChar val, Int absPartIdx, Int depth)
const TComPPS * getPPS() const
Definition: TComSlice.h:1309
UInt getPicWidthInLumaSamples() const
Definition: TComSlice.h:822
UInt & getTotalBits()
Definition: TComDataCU.h:474
Int getChromaQpAdjTableSize() const
Definition: TComSlice.h:1081
UInt getCUPelX() const
Definition: TComDataCU.h:210
#define DEBUG_STRING_PASS_INTO(name)
Definition: TypeDef.h:69
UInt getSliceArgument() const
Definition: TComSlice.h:1465
UInt getSliceSegmentArgument() const
Definition: TComSlice.h:1476
ChromaFormat getChromaFormat() const
Definition: TComPic.h:128
Bool isIntra() const
Definition: TComSlice.h:1404
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:418
#define ARL_C_PRECISION
G382: 7-bit arithmetic precision.
Definition: TypeDef.h:150
UChar * getHeight()
Definition: TComDataCU.h:249
Void xCompressCU(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, UInt uiDepth, PartSize eParentPartSize=NUMBER_OF_PART_SIZES)
Definition: TEncCu.cpp:349
UInt getCurrSliceIdx() const
Definition: TComPic.h:137
encoder class (header)
next best index
Definition: TypeDef.h:480
Int getLog2DiffMaxMinCodingBlockSize() const
Definition: TComSlice.h:841
Bool * getCUTransquantBypass()
Definition: TComDataCU.h:242
asymmetric motion partition, ( N/2)x2N + (3N/2)x2N
Definition: TypeDef.h:401
Void getInterMergeCandidates(UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField *pcMFieldNeighbours, UChar *puhInterDirNeighbours, Int &numValidMergeCand, Int mrgCandIdx=-1)
Construct a list of merging candidates.
Bool getUsePCM() const
Definition: TComSlice.h:851
TComPic * getPic()
Definition: TComDataCU.h:203
TComPicYuv * getPicYuvPred()
Definition: TComPic.h:111
Int g_bitDepth[MAX_NUM_CHANNEL_TYPE]
Definition: TComRom.cpp:548
Void xCheckRDCostMerge2Nx2N(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, Bool *earlyDetectionSkipMode)
Definition: TEncCu.cpp:1154
TComRdCost * getRdCost()
Definition: TEncTop.h:151
#define DEBUG_STRING_FN_DECLARE(name)
Definition: TypeDef.h:71
Char * getPartitionSize()
Definition: TComDataCU.h:223
TEncPicQPAdaptationLayer * getAQLayer(UInt uiDepth)
Definition: TEncPic.h:108
Void setIPCMFlagSubParts(Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth)
Void setQPSubParts(Int qp, UInt uiAbsPartIdx, UInt uiDepth)
Char * getPredictionMode()
Definition: TComDataCU.h:234
Bool getUseAMP() const
Definition: TComSlice.h:858
Pel * getAddr(const ComponentID ch)
Definition: TComPicYuv.h:127
Void initZscanToRaster(Int iMaxDepth, Int iDepth, UInt uiStartVal, UInt *&rpuiCurrIdx)
Definition: TComRom.cpp:262
Void xCopyYuv2Tmp(UInt uhPartUnitIdx, UInt uiDepth)
Definition: TEncCu.cpp:1516
UInt getSliceSegmentCurEndCtuTsAddr() const
Definition: TComSlice.h:1480
UInt getMaxCuChromaQpAdjDepth() const
Definition: TComSlice.h:1079
Void setTrIdxSubParts(UInt uiTrIdx, UInt uiAbsPartIdx, UInt uiDepth)
Void xCheckRDCostInter(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, PartSize ePartSize, Bool bUseMRG=false)
Definition: TEncCu.cpp:1279
TComCUMvField * getCUMvField(RefPicList e)
Definition: TComDataCU.h:294
Void finishCU(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
Definition: TEncCu.cpp:878
UChar * getWidth()
Definition: TComDataCU.h:245
TCoeff * getCoeff(ComponentID component)
Definition: TComDataCU.h:296
int Int
Definition: TypeDef.h:296
Void setMergeAMP(Bool b)
Definition: TComDataCU.h:334
encoder class
Definition: TEncTop.h:68
UInt & getTotalNumPart()
Definition: TComDataCU.h:475
ComponentID
Definition: TypeDef.h:368
PredMode
supported prediction type
Definition: TypeDef.h:407
Void xCheckRDCostIntra(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, Double &cost, PartSize ePartSize)
Definition: TEncCu.cpp:1318
Bool * getMergeFlag()
Definition: TComDataCU.h:321
Int getSliceQp() const
Definition: TComSlice.h:1339
TEncSearch * getPredSearch()
Definition: TEncTop.h:138
#define MAX_DOUBLE
max. value of Double-type value
Definition: CommonDef.h:124
#define MRG_MAX_NUM_CANDS
Definition: CommonDef.h:186
UInt getMaxAQDepth()
Definition: TEncPic.h:109
Void setSkipFlagSubParts(Bool skip, UInt absPartIdx, UInt depth)
Unit block for storing image characteristics.
Definition: TEncPic.h:52
asymmetric motion partition, 2Nx(3N/2) + 2Nx( N/2)
Definition: TypeDef.h:400
symmetric motion partition, Nx N
Definition: TypeDef.h:398
inter-prediction mode
Definition: TypeDef.h:409
Pel * getPCMSample(ComponentID component)
Definition: TComDataCU.h:301
SBAC encoder class.
Definition: TEncSbac.h:66
double Double
Definition: TypeDef.h:298
Void initEstData(const UInt uiDepth, const Int qp, const Bool bTransquantBypass)
Definition: TComDataCU.cpp:564
static UInt getNumberValidComponents(const ChromaFormat fmt)
slice header class
Definition: TComSlice.h:1198
Bool isLastSubCUOfCtu(const UInt absPartIdx)
Definition: TComDataCU.cpp:418
Bool isLosslessCoded(UInt absPartIdx)
TEncBinCABAC * getBinCABAC()
Definition: TEncTop.h:149
TComMv m_acMvCand[3]
array of motion vector predictor candidates
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:74
symmetric motion partition, Nx2N
Definition: TypeDef.h:397
#define DEBUG_STRING_NEW(name)
Definition: TypeDef.h:73
Void setMergeIndexSubParts(UInt uiMergeIndex, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
Int xComputeQP(TComDataCU *pcCU, UInt uiDepth)
Definition: TEncCu.cpp:902
Defines types and objects for environment-variable-based debugging and feature control.
Bool getMergeAMP()
Definition: TComDataCU.h:335
TComSlice * getSlice()
Definition: TComDataCU.h:205
const TComSPS * getSPS() const
Definition: TComSlice.h:1306
Void setPredModeSubParts(PredMode eMode, UInt uiAbsPartIdx, UInt uiDepth)