source: 3DVCSoftware/branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncCu.cpp @ 467

Last change on this file since 467 was 467, checked in by rwth, 11 years ago

Integration of depth intra methods in macro H_3D_DIM, including:

  • Simplified Depth Coding (SDC) in H_3D_DIM_SDC
  • Depth Lookup Table (DLT) in H_3D_DIM_DLT
  • Property svn:eol-style set to native
File size: 65.9 KB
Line 
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-2013, 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
34/** \file     TEncCu.cpp
35    \brief    Coding Unit (CU) encoder class
36*/
37
38#include <stdio.h>
39#include "TEncTop.h"
40#include "TEncCu.h"
41#include "TEncAnalyze.h"
42
43#include <cmath>
44#include <algorithm>
45using namespace std;
46
47//! \ingroup TLibEncoder
48//! \{
49
50// ====================================================================================================================
51// Constructor / destructor / create / destroy
52// ====================================================================================================================
53
54/**
55 \param    uiTotalDepth  total number of allowable depth
56 \param    uiMaxWidth    largest CU width
57 \param    uiMaxHeight   largest CU height
58 */
59Void TEncCu::create(UChar uhTotalDepth, UInt uiMaxWidth, UInt uiMaxHeight)
60{
61  Int i;
62 
63  m_uhTotalDepth   = uhTotalDepth + 1;
64  m_ppcBestCU      = new TComDataCU*[m_uhTotalDepth-1];
65  m_ppcTempCU      = new TComDataCU*[m_uhTotalDepth-1];
66   
67  m_ppcPredYuvBest = new TComYuv*[m_uhTotalDepth-1];
68  m_ppcResiYuvBest = new TComYuv*[m_uhTotalDepth-1];
69  m_ppcRecoYuvBest = new TComYuv*[m_uhTotalDepth-1];
70  m_ppcPredYuvTemp = new TComYuv*[m_uhTotalDepth-1];
71  m_ppcResiYuvTemp = new TComYuv*[m_uhTotalDepth-1];
72  m_ppcRecoYuvTemp = new TComYuv*[m_uhTotalDepth-1];
73  m_ppcOrigYuv     = new TComYuv*[m_uhTotalDepth-1];
74 
75  UInt uiNumPartitions;
76  for( i=0 ; i<m_uhTotalDepth-1 ; i++)
77  {
78    uiNumPartitions = 1<<( ( m_uhTotalDepth - i - 1 )<<1 );
79    UInt uiWidth  = uiMaxWidth  >> i;
80    UInt uiHeight = uiMaxHeight >> i;
81   
82    m_ppcBestCU[i] = new TComDataCU; m_ppcBestCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) );
83    m_ppcTempCU[i] = new TComDataCU; m_ppcTempCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) );
84   
85    m_ppcPredYuvBest[i] = new TComYuv; m_ppcPredYuvBest[i]->create(uiWidth, uiHeight);
86    m_ppcResiYuvBest[i] = new TComYuv; m_ppcResiYuvBest[i]->create(uiWidth, uiHeight);
87    m_ppcRecoYuvBest[i] = new TComYuv; m_ppcRecoYuvBest[i]->create(uiWidth, uiHeight);
88   
89    m_ppcPredYuvTemp[i] = new TComYuv; m_ppcPredYuvTemp[i]->create(uiWidth, uiHeight);
90    m_ppcResiYuvTemp[i] = new TComYuv; m_ppcResiYuvTemp[i]->create(uiWidth, uiHeight);
91    m_ppcRecoYuvTemp[i] = new TComYuv; m_ppcRecoYuvTemp[i]->create(uiWidth, uiHeight);
92   
93    m_ppcOrigYuv    [i] = new TComYuv; m_ppcOrigYuv    [i]->create(uiWidth, uiHeight);
94  }
95 
96  m_bEncodeDQP = false;
97#if RATE_CONTROL_LAMBDA_DOMAIN
98  m_LCUPredictionSAD = 0;
99  m_addSADDepth      = 0;
100  m_temporalSAD      = 0;
101#endif
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
112Void TEncCu::destroy()
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
203/** \param    pcEncTop      pointer of encoder class
204 */
205Void TEncCu::init( TEncTop* pcEncTop )
206{
207  m_pcEncCfg           = pcEncTop;
208  m_pcPredSearch       = pcEncTop->getPredSearch();
209  m_pcTrQuant          = pcEncTop->getTrQuant();
210  m_pcBitCounter       = pcEncTop->getBitCounter();
211  m_pcRdCost           = pcEncTop->getRdCost();
212 
213  m_pcEntropyCoder     = pcEncTop->getEntropyCoder();
214  m_pcCavlcCoder       = pcEncTop->getCavlcCoder();
215  m_pcSbacCoder       = pcEncTop->getSbacCoder();
216  m_pcBinCABAC         = pcEncTop->getBinCABAC();
217 
218  m_pppcRDSbacCoder   = pcEncTop->getRDSbacCoder();
219  m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder();
220 
221  m_bUseSBACRD        = pcEncTop->getUseSBACRD();
222  m_pcRateCtrl        = pcEncTop->getRateCtrl();
223}
224
225// ====================================================================================================================
226// Public member functions
227// ====================================================================================================================
228
229/** \param  rpcCU pointer of CU data class
230 */
231Void TEncCu::compressCU( TComDataCU*& rpcCU )
232{
233  // initialize CU data
234  m_ppcBestCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() );
235  m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() );
236
237#if RATE_CONTROL_LAMBDA_DOMAIN
238  m_addSADDepth      = 0;
239  m_LCUPredictionSAD = 0;
240  m_temporalSAD      = 0;
241#endif
242
243  // analysis of CU
244  xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 );
245
246#if ADAPTIVE_QP_SELECTION
247  if( m_pcEncCfg->getUseAdaptQpSelect() )
248  {
249    if(rpcCU->getSlice()->getSliceType()!=I_SLICE) //IIII
250    {
251      xLcuCollectARLStats( rpcCU);
252    }
253  }
254#endif
255}
256/** \param  pcCU  pointer of CU data class
257 */
258Void TEncCu::encodeCU ( TComDataCU* pcCU )
259{
260  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
261  {
262    setdQPFlag(true);
263  }
264
265  // Encode CU data
266  xEncodeCU( pcCU, 0, 0 );
267}
268
269// ====================================================================================================================
270// Protected member functions
271// ====================================================================================================================
272/** Derive small set of test modes for AMP encoder speed-up
273 *\param   rpcBestCU
274 *\param   eParentPartSize
275 *\param   bTestAMP_Hor
276 *\param   bTestAMP_Ver
277 *\param   bTestMergeAMP_Hor
278 *\param   bTestMergeAMP_Ver
279 *\returns Void
280*/
281#if AMP_ENC_SPEEDUP
282#if AMP_MRG
283Void TEncCu::deriveTestModeAMP (TComDataCU *&rpcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver, Bool &bTestMergeAMP_Hor, Bool &bTestMergeAMP_Ver)
284#else
285Void TEncCu::deriveTestModeAMP (TComDataCU *&rpcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver)
286#endif
287{
288  if ( rpcBestCU->getPartitionSize(0) == SIZE_2NxN )
289  {
290    bTestAMP_Hor = true;
291  }
292  else if ( rpcBestCU->getPartitionSize(0) == SIZE_Nx2N )
293  {
294    bTestAMP_Ver = true;
295  }
296  else if ( rpcBestCU->getPartitionSize(0) == SIZE_2Nx2N && rpcBestCU->getMergeFlag(0) == false && rpcBestCU->isSkipped(0) == false )
297  {
298    bTestAMP_Hor = true;         
299    bTestAMP_Ver = true;         
300  }
301
302#if AMP_MRG
303  //! Utilizing the partition size of parent PU   
304  if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N )
305  { 
306    bTestMergeAMP_Hor = true;
307    bTestMergeAMP_Ver = true;
308  }
309
310  if ( eParentPartSize == SIZE_NONE ) //! if parent is intra
311  {
312    if ( rpcBestCU->getPartitionSize(0) == SIZE_2NxN )
313    {
314      bTestMergeAMP_Hor = true;
315    }
316    else if ( rpcBestCU->getPartitionSize(0) == SIZE_Nx2N )
317    {
318      bTestMergeAMP_Ver = true;
319    }
320  }
321
322  if ( rpcBestCU->getPartitionSize(0) == SIZE_2Nx2N && rpcBestCU->isSkipped(0) == false )
323  {
324    bTestMergeAMP_Hor = true;         
325    bTestMergeAMP_Ver = true;         
326  }
327
328  if ( rpcBestCU->getWidth(0) == 64 )
329  { 
330    bTestAMP_Hor = false;
331    bTestAMP_Ver = false;
332  }   
333#else
334  //! Utilizing the partition size of parent PU       
335  if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N )
336  { 
337    bTestAMP_Hor = true;
338    bTestAMP_Ver = true;
339  }
340
341  if ( eParentPartSize == SIZE_2Nx2N )
342  { 
343    bTestAMP_Hor = false;
344    bTestAMP_Ver = false;
345  }     
346#endif
347}
348#endif
349
350// ====================================================================================================================
351// Protected member functions
352// ====================================================================================================================
353/** Compress a CU block recursively with enabling sub-LCU-level delta QP
354 *\param   rpcBestCU
355 *\param   rpcTempCU
356 *\param   uiDepth
357 *\returns Void
358 *
359 *- for loop of QP value to compress the current CU with all possible QP
360*/
361#if AMP_ENC_SPEEDUP
362Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth, PartSize eParentPartSize )
363#else
364Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth )
365#endif
366{
367  TComPic* pcPic = rpcBestCU->getPic();
368
369  // get Original YUV data from picture
370  m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() );
371
372  // variables for fast encoder decision
373  Bool    bEarlySkip  = false;
374  Bool    bTrySplit    = true;
375  Double  fRD_Skip    = MAX_DOUBLE;
376
377  // variable for Early CU determination
378  Bool    bSubBranch = true;
379
380  // variable for Cbf fast mode PU decision
381  Bool    doNotBlockPu = true;
382  Bool earlyDetectionSkipMode = false;
383
384  Bool    bTrySplitDQP  = true;
385
386  static  Double  afCost[ MAX_CU_DEPTH ];
387  static  Int      aiNum [ MAX_CU_DEPTH ];
388
389  if ( rpcBestCU->getAddr() == 0 )
390  {
391    ::memset( afCost, 0, sizeof( afCost ) );
392    ::memset( aiNum,  0, sizeof( aiNum  ) );
393  }
394
395  Bool bBoundary = false;
396  UInt uiLPelX   = rpcBestCU->getCUPelX();
397  UInt uiRPelX   = uiLPelX + rpcBestCU->getWidth(0)  - 1;
398  UInt uiTPelY   = rpcBestCU->getCUPelY();
399  UInt uiBPelY   = uiTPelY + rpcBestCU->getHeight(0) - 1;
400
401  Int iBaseQP = xComputeQP( rpcBestCU, uiDepth );
402  Int iMinQP;
403  Int iMaxQP;
404  Bool isAddLowestQP = false;
405  Int lowestQP = -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY();
406
407  if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
408  {
409    Int idQP = m_pcEncCfg->getMaxDeltaQP();
410    iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
411    iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
412    if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() )
413    {
414      isAddLowestQP = true; 
415      iMinQP = iMinQP - 1;
416    }
417  }
418  else
419  {
420    iMinQP = rpcTempCU->getQP(0);
421    iMaxQP = rpcTempCU->getQP(0);
422  }
423
424#if RATE_CONTROL_LAMBDA_DOMAIN
425  if ( m_pcEncCfg->getUseRateCtrl() )
426  {
427    iMinQP = m_pcRateCtrl->getRCQP();
428    iMaxQP = m_pcRateCtrl->getRCQP();
429  }
430#else
431  if(m_pcEncCfg->getUseRateCtrl())
432  {
433    Int qp = m_pcRateCtrl->getUnitQP();
434    iMinQP  = Clip3( MIN_QP, MAX_QP, qp);
435    iMaxQP  = Clip3( MIN_QP, MAX_QP, qp);
436  }
437#endif
438
439  // If slice start or slice end is within this cu...
440  TComSlice * pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx());
441  Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurStartCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart();
442  Bool bSliceEnd = (pcSlice->getSliceSegmentCurEndCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurEndCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart());
443  Bool bInsidePicture = ( uiRPelX < rpcBestCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < rpcBestCU->getSlice()->getSPS()->getPicHeightInLumaSamples() );
444  // We need to split, so don't try these modes.
445  if(!bSliceEnd && !bSliceStart && bInsidePicture )
446  {
447    for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
448    {
449      if (isAddLowestQP && (iQP == iMinQP))
450      {
451        iQP = lowestQP;
452      }
453      // variables for fast encoder decision
454      bEarlySkip  = false;
455      bTrySplit    = true;
456      fRD_Skip    = MAX_DOUBLE;
457
458      rpcTempCU->initEstData( uiDepth, iQP );
459
460      // do inter modes, SKIP and 2Nx2N
461      if( rpcBestCU->getSlice()->getSliceType() != I_SLICE )
462      {
463        // 2Nx2N
464        if(m_pcEncCfg->getUseEarlySkipDetection())
465        {
466          xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );  rpcTempCU->initEstData( uiDepth, iQP );//by Competition for inter_2Nx2N
467        }
468        // SKIP
469        xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode );//by Merge for inter_2Nx2N
470        rpcTempCU->initEstData( uiDepth, iQP );
471
472        // fast encoder decision for early skip
473        if ( m_pcEncCfg->getUseFastEnc() )
474        {
475          Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ];
476          if ( aiNum [ iIdx ] > 5 && fRD_Skip < EARLY_SKIP_THRES*afCost[ iIdx ]/aiNum[ iIdx ] )
477          {
478            bEarlySkip = true;
479            bTrySplit  = false;
480          }
481        }
482
483        if(!m_pcEncCfg->getUseEarlySkipDetection())
484        {
485          // 2Nx2N, NxN
486          if ( !bEarlySkip )
487          {
488            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );  rpcTempCU->initEstData( uiDepth, iQP );
489            if(m_pcEncCfg->getUseCbfFastMode())
490            {
491              doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
492            }
493          }
494        }
495      }
496
497      if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
498      {
499        if(iQP == iBaseQP)
500        {
501          bTrySplitDQP = bTrySplit;
502        }
503      }
504      else
505      {
506        bTrySplitDQP = bTrySplit;
507      }
508      if (isAddLowestQP && (iQP == lowestQP))
509      {
510        iQP = iMinQP;
511      }
512    }
513
514#if RATE_CONTROL_LAMBDA_DOMAIN
515    if ( uiDepth <= m_addSADDepth )
516    {
517      m_LCUPredictionSAD += m_temporalSAD;
518      m_addSADDepth = uiDepth;
519    }
520#endif
521
522#if H_3D_DIM_ENC
523    if( rpcBestCU->getSlice()->getIsDepth() && rpcBestCU->getSlice()->isIRAP() )
524    {
525      earlyDetectionSkipMode = false;
526    }
527#endif
528
529    if(!earlyDetectionSkipMode)
530    {
531      for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
532      {
533        if (isAddLowestQP && (iQP == iMinQP))
534        {
535          iQP = lowestQP;
536        }
537        rpcTempCU->initEstData( uiDepth, iQP );
538
539        // do inter modes, NxN, 2NxN, and Nx2N
540        if( rpcBestCU->getSlice()->getSliceType() != I_SLICE )
541        {
542          // 2Nx2N, NxN
543          if ( !bEarlySkip )
544          {
545            if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) ))
546            {
547              if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu)
548              {
549                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN   );
550                rpcTempCU->initEstData( uiDepth, iQP );
551              }
552            }
553          }
554
555          // 2NxN, Nx2N
556          if(doNotBlockPu)
557          {
558            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N  );
559            rpcTempCU->initEstData( uiDepth, iQP );
560            if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_Nx2N )
561            {
562              doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
563            }
564          }
565          if(doNotBlockPu)
566          {
567            xCheckRDCostInter      ( rpcBestCU, rpcTempCU, SIZE_2NxN  );
568            rpcTempCU->initEstData( uiDepth, iQP );
569            if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxN)
570            {
571              doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
572            }
573          }
574
575#if 1
576          //! Try AMP (SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N, SIZE_nRx2N)
577          if( pcPic->getSlice(0)->getSPS()->getAMPAcc(uiDepth) )
578          {
579#if AMP_ENC_SPEEDUP       
580            Bool bTestAMP_Hor = false, bTestAMP_Ver = false;
581
582#if AMP_MRG
583            Bool bTestMergeAMP_Hor = false, bTestMergeAMP_Ver = false;
584
585            deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver, bTestMergeAMP_Hor, bTestMergeAMP_Ver);
586#else
587            deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver);
588#endif
589
590            //! Do horizontal AMP
591            if ( bTestAMP_Hor )
592            {
593              if(doNotBlockPu)
594              {
595                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU );
596                rpcTempCU->initEstData( uiDepth, iQP );
597                if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU )
598                {
599                  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
600                }
601              }
602              if(doNotBlockPu)
603              {
604                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD );
605                rpcTempCU->initEstData( uiDepth, iQP );
606                if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD )
607                {
608                  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
609                }
610              }
611            }
612#if AMP_MRG
613            else if ( bTestMergeAMP_Hor ) 
614            {
615              if(doNotBlockPu)
616              {
617                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, true );
618                rpcTempCU->initEstData( uiDepth, iQP );
619                if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU )
620                {
621                  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
622                }
623              }
624              if(doNotBlockPu)
625              {
626                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, true );
627                rpcTempCU->initEstData( uiDepth, iQP );
628                if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD )
629                {
630                  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
631                }
632              }
633            }
634#endif
635
636            //! Do horizontal AMP
637            if ( bTestAMP_Ver )
638            {
639              if(doNotBlockPu)
640              {
641                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N );
642                rpcTempCU->initEstData( uiDepth, iQP );
643                if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N )
644                {
645                  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
646                }
647              }
648              if(doNotBlockPu)
649              {
650                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N );
651                rpcTempCU->initEstData( uiDepth, iQP );
652              }
653            }
654#if AMP_MRG
655            else if ( bTestMergeAMP_Ver )
656            {
657              if(doNotBlockPu)
658              {
659                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, true );
660                rpcTempCU->initEstData( uiDepth, iQP );
661                if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N )
662                {
663                  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
664                }
665              }
666              if(doNotBlockPu)
667              {
668                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, true );
669                rpcTempCU->initEstData( uiDepth, iQP );
670              }
671            }
672#endif
673
674#else
675            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU );
676            rpcTempCU->initEstData( uiDepth, iQP );
677            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD );
678            rpcTempCU->initEstData( uiDepth, iQP );
679            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N );
680            rpcTempCU->initEstData( uiDepth, iQP );
681
682            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N );
683            rpcTempCU->initEstData( uiDepth, iQP );
684
685#endif
686          }   
687#endif
688        }
689
690        // do normal intra modes
691#if H_3D_DIM_ENC
692        if ( !bEarlySkip || ( rpcBestCU->getSlice()->getIsDepth() && rpcBestCU->getSlice()->isIRAP() ) )
693#else
694        if ( !bEarlySkip )
695#endif
696        {
697          // speedup for inter frames
698          if( rpcBestCU->getSlice()->getSliceType() == I_SLICE || 
699            rpcBestCU->getCbf( 0, TEXT_LUMA     ) != 0   ||
700            rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0   ||
701              rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0     
702#if H_3D_DIM_ENC
703            || ( rpcBestCU->getSlice()->getIsDepth() && rpcBestCU->getSlice()->isIRAP() )
704#endif
705            ) // avoid very complex intra if it is unlikely
706          {
707            xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N );
708            rpcTempCU->initEstData( uiDepth, iQP );
709            if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
710            {
711              if( rpcTempCU->getWidth(0) > ( 1 << rpcTempCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) )
712              {
713                xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN   );
714                rpcTempCU->initEstData( uiDepth, iQP );
715              }
716            }
717          }
718        }
719
720        // test PCM
721        if(pcPic->getSlice(0)->getSPS()->getUsePCM()
722          && rpcTempCU->getWidth(0) <= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MaxSize())
723          && rpcTempCU->getWidth(0) >= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MinSize()) )
724        {
725          UInt uiRawBits = (2 * g_bitDepthY + g_bitDepthC) * rpcBestCU->getWidth(0) * rpcBestCU->getHeight(0) / 2;
726          UInt uiBestBits = rpcBestCU->getTotalBits();
727#if H_3D_VSO // M7
728          Double dRDCostTemp = m_pcRdCost->getUseVSO() ? m_pcRdCost->calcRdCostVSO(uiRawBits, 0) : m_pcRdCost->calcRdCost(uiRawBits, 0);
729          if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > dRDCostTemp ))
730#else
731          if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > m_pcRdCost->calcRdCost(uiRawBits, 0)))
732#endif
733          {
734            xCheckIntraPCM (rpcBestCU, rpcTempCU);
735            rpcTempCU->initEstData( uiDepth, iQP );
736          }
737        }
738        if (isAddLowestQP && (iQP == lowestQP))
739        {
740          iQP = iMinQP;
741        }
742      }
743    }
744
745    m_pcEntropyCoder->resetBits();
746    m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true );
747    rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits
748    if(m_pcEncCfg->getUseSBACRD())
749    {
750      rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
751    }
752
753#if H_3D_VSO // M8
754    if ( m_pcRdCost->getUseVSO() )   
755      rpcBestCU->getTotalCost()  = m_pcRdCost->calcRdCostVSO( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() );   
756    else
757#endif
758    rpcBestCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() );
759
760    // accumulate statistics for early skip
761    if ( m_pcEncCfg->getUseFastEnc() )
762    {
763      if ( rpcBestCU->isSkipped(0) )
764      {
765        Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ];
766        afCost[ iIdx ] += rpcBestCU->getTotalCost();
767        aiNum [ iIdx ] ++;
768      }
769    }
770
771    // Early CU determination
772    if( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->isSkipped(0) )
773    {
774      bSubBranch = false;
775    }
776    else
777    {
778      bSubBranch = true;
779    }
780  }
781  else if(!(bSliceEnd && bInsidePicture))
782  {
783    bBoundary = true;
784#if RATE_CONTROL_LAMBDA_DOMAIN
785    m_addSADDepth++;
786#endif
787  }
788
789  // copy orginal YUV samples to PCM buffer
790  if( rpcBestCU->isLosslessCoded(0) && (rpcBestCU->getIPCMFlag(0) == false))
791  {
792    xFillPCMBuffer(rpcBestCU, m_ppcOrigYuv[uiDepth]);
793  }
794  if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
795  {
796    Int idQP = m_pcEncCfg->getMaxDeltaQP();
797    iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
798    iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
799    if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() )
800    {
801      isAddLowestQP = true;
802      iMinQP = iMinQP - 1;     
803    }
804  }
805  else if( (g_uiMaxCUWidth>>uiDepth) > rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
806  {
807    iMinQP = iBaseQP;
808    iMaxQP = iBaseQP;
809  }
810  else
811  {
812    Int iStartQP;
813    if( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(rpcTempCU->getZorderIdxInCU()) == pcSlice->getSliceSegmentCurStartCUAddr())
814    {
815      iStartQP = rpcTempCU->getQP(0);
816    }
817    else
818    {
819      UInt uiCurSliceStartPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU();
820      iStartQP = rpcTempCU->getQP(uiCurSliceStartPartIdx);
821    }
822    iMinQP = iStartQP;
823    iMaxQP = iStartQP;
824  }
825#if RATE_CONTROL_LAMBDA_DOMAIN
826  if ( m_pcEncCfg->getUseRateCtrl() )
827  {
828    iMinQP = m_pcRateCtrl->getRCQP();
829    iMaxQP = m_pcRateCtrl->getRCQP();
830  }
831#else
832  if(m_pcEncCfg->getUseRateCtrl())
833  {
834    Int qp = m_pcRateCtrl->getUnitQP();
835    iMinQP  = Clip3( MIN_QP, MAX_QP, qp);
836    iMaxQP  = Clip3( MIN_QP, MAX_QP, qp);
837  }
838#endif
839  for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
840  {
841    if (isAddLowestQP && (iQP == iMinQP))
842    {
843      iQP = lowestQP;
844    }
845    rpcTempCU->initEstData( uiDepth, iQP );
846
847    // further split
848    if( bSubBranch && bTrySplitDQP && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth )
849    {
850#if H_3D_VSO // M9
851      // reset Model
852      if( m_pcRdCost->getUseRenModel() )
853      {
854        UInt  uiWidth     = m_ppcOrigYuv[uiDepth]->getWidth ( );
855        UInt  uiHeight    = m_ppcOrigYuv[uiDepth]->getHeight( );
856        Pel*  piSrc       = m_ppcOrigYuv[uiDepth]->getLumaAddr( 0 );
857        UInt  uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride();
858        m_pcRdCost->setRenModelData( m_ppcBestCU[uiDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight );
859      }
860#endif
861
862      UChar       uhNextDepth         = uiDepth+1;
863      TComDataCU* pcSubBestPartCU     = m_ppcBestCU[uhNextDepth];
864      TComDataCU* pcSubTempPartCU     = m_ppcTempCU[uhNextDepth];
865
866      for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ )
867      {
868        pcSubBestPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP );           // clear sub partition datas or init.
869        pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP );           // clear sub partition datas or init.
870
871        Bool bInSlice = pcSubBestPartCU->getSCUAddr()+pcSubBestPartCU->getTotalNumPart()>pcSlice->getSliceSegmentCurStartCUAddr()&&pcSubBestPartCU->getSCUAddr()<pcSlice->getSliceSegmentCurEndCUAddr();
872        if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
873        {
874          if( m_bUseSBACRD )
875          {
876            if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer
877            {
878              m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
879            }
880            else
881            {
882              m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
883            }
884          }
885
886#if AMP_ENC_SPEEDUP
887          if ( rpcBestCU->isIntra(0) )
888          {
889            xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth, SIZE_NONE );
890          }
891          else
892          {
893            xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth, rpcBestCU->getPartitionSize(0) );
894          }
895#else
896          xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth );
897#endif
898
899          rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth );         // Keep best part data to current temporary data.
900          xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth );
901        }
902        else if (bInSlice)
903        {
904          pcSubBestPartCU->copyToPic( uhNextDepth );
905          rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth );
906        }
907      }
908
909      if( !bBoundary )
910      {
911        m_pcEntropyCoder->resetBits();
912        m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth, true );
913
914        rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits
915        if(m_pcEncCfg->getUseSBACRD())
916        {
917          rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
918        }
919      }
920
921#if H_3D_VSO // M10
922      if ( m_pcRdCost->getUseVSO() )
923        rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
924      else
925#endif
926      rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
927
928      if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() && rpcTempCU->getSlice()->getPPS()->getUseDQP())
929      {
930        Bool hasResidual = false;
931        for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++)
932        {
933          if( ( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(uiBlkIdx+rpcTempCU->getZorderIdxInCU()) == rpcTempCU->getSlice()->getSliceSegmentCurStartCUAddr() ) && 
934              ( rpcTempCU->getCbf( uiBlkIdx, TEXT_LUMA ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_U ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_V ) ) )
935          {
936            hasResidual = true;
937            break;
938          }
939        }
940
941        UInt uiTargetPartIdx;
942        if ( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(rpcTempCU->getZorderIdxInCU()) != pcSlice->getSliceSegmentCurStartCUAddr() )
943        {
944          uiTargetPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU();
945        }
946        else
947        {
948          uiTargetPartIdx = 0;
949        }
950        if ( hasResidual )
951        {
952#if !RDO_WITHOUT_DQP_BITS
953          m_pcEntropyCoder->resetBits();
954          m_pcEntropyCoder->encodeQP( rpcTempCU, uiTargetPartIdx, false );
955          rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits
956          if(m_pcEncCfg->getUseSBACRD())
957          {
958            rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
959          }
960#if H_3D_VSO // M11
961          if ( m_pcRdCost->getUseLambdaScaleVSO())         
962            rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );         
963          else
964#endif
965          rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
966#endif
967
968          Bool foundNonZeroCbf = false;
969          rpcTempCU->setQPSubCUs( rpcTempCU->getRefQP( uiTargetPartIdx ), rpcTempCU, 0, uiDepth, foundNonZeroCbf );
970          assert( foundNonZeroCbf );
971        }
972        else
973        {
974          rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uiDepth ); // set QP to default QP
975        }
976      }
977
978      if( m_bUseSBACRD )
979      {
980        m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
981      }
982      Bool isEndOfSlice        = rpcBestCU->getSlice()->getSliceMode()==FIXED_NUMBER_OF_BYTES
983                                 && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3);
984      Bool isEndOfSliceSegment = rpcBestCU->getSlice()->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES
985                                 && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceSegmentArgument()<<3);
986      if(isEndOfSlice||isEndOfSliceSegment)
987      {
988        rpcBestCU->getTotalCost()=rpcTempCU->getTotalCost()+1;
989      }
990      xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth);                                  // RD compare current larger prediction
991    }                                                                                  // with sub partitioned prediction.
992    if (isAddLowestQP && (iQP == lowestQP))
993    {
994      iQP = iMinQP;
995    }
996  }
997
998
999#if H_3D_VSO // M12
1000  if( m_pcRdCost->getUseRenModel() )
1001  {
1002    UInt  uiWidth     = m_ppcRecoYuvBest[uiDepth]->getWidth   ( );
1003    UInt  uiHeight    = m_ppcRecoYuvBest[uiDepth]->getHeight  ( );
1004    Pel*  piSrc       = m_ppcRecoYuvBest[uiDepth]->getLumaAddr( 0 );
1005    UInt  uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride  ( );
1006    m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
1007  }
1008#endif
1009
1010  rpcBestCU->copyToPic(uiDepth);                                                     // Copy Best data to Picture for next partition prediction.
1011
1012  xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU(), uiDepth, uiDepth, rpcBestCU, uiLPelX, uiTPelY );   // Copy Yuv data to picture Yuv
1013  if( bBoundary ||(bSliceEnd && bInsidePicture))
1014  {
1015    return;
1016  }
1017
1018  // Assert if Best prediction mode is NONE
1019  // Selected mode's RD-cost must be not MAX_DOUBLE.
1020  assert( rpcBestCU->getPartitionSize ( 0 ) != SIZE_NONE  );
1021  assert( rpcBestCU->getPredictionMode( 0 ) != MODE_NONE  );
1022  assert( rpcBestCU->getTotalCost     (   ) != MAX_DOUBLE );
1023}
1024
1025/** finish encoding a cu and handle end-of-slice conditions
1026 * \param pcCU
1027 * \param uiAbsPartIdx
1028 * \param uiDepth
1029 * \returns Void
1030 */
1031Void TEncCu::finishCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1032{
1033  TComPic* pcPic = pcCU->getPic();
1034  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
1035
1036  //Calculate end address
1037  UInt uiCUAddr = pcCU->getSCUAddr()+uiAbsPartIdx;
1038
1039  UInt uiInternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) % pcPic->getNumPartInCU();
1040  UInt uiExternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) / pcPic->getNumPartInCU();
1041  UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
1042  UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
1043  UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
1044  UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
1045  while(uiPosX>=uiWidth||uiPosY>=uiHeight)
1046  {
1047    uiInternalAddress--;
1048    uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
1049    uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
1050  }
1051  uiInternalAddress++;
1052  if(uiInternalAddress==pcCU->getPic()->getNumPartInCU())
1053  {
1054    uiInternalAddress = 0;
1055    uiExternalAddress = pcPic->getPicSym()->getCUOrderMap(pcPic->getPicSym()->getInverseCUOrderMap(uiExternalAddress)+1);
1056  }
1057  UInt uiRealEndAddress = pcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress);
1058
1059  // Encode slice finish
1060  Bool bTerminateSlice = false;
1061  if (uiCUAddr+(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1)) == uiRealEndAddress)
1062  {
1063    bTerminateSlice = true;
1064  }
1065  UInt uiGranularityWidth = g_uiMaxCUWidth;
1066  uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
1067  uiPosY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
1068  Bool granularityBoundary=((uiPosX+pcCU->getWidth(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosX+pcCU->getWidth(uiAbsPartIdx)==uiWidth))
1069    &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight));
1070 
1071  if(granularityBoundary)
1072  {
1073    // The 1-terminating bit is added to all streams, so don't add it here when it's 1.
1074    if (!bTerminateSlice)
1075      m_pcEntropyCoder->encodeTerminatingBit( bTerminateSlice ? 1 : 0 );
1076  }
1077 
1078  Int numberOfWrittenBits = 0;
1079  if (m_pcBitCounter)
1080  {
1081    numberOfWrittenBits = m_pcEntropyCoder->getNumberOfWrittenBits();
1082  }
1083 
1084  // Calculate slice end IF this CU puts us over slice bit size.
1085  UInt iGranularitySize = pcCU->getPic()->getNumPartInCU();
1086  Int iGranularityEnd = ((pcCU->getSCUAddr()+uiAbsPartIdx)/iGranularitySize)*iGranularitySize;
1087  if(iGranularityEnd<=pcSlice->getSliceSegmentCurStartCUAddr()) 
1088  {
1089    iGranularityEnd+=max(iGranularitySize,(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1)));
1090  }
1091  // Set slice end parameter
1092  if(pcSlice->getSliceMode()==FIXED_NUMBER_OF_BYTES&&!pcSlice->getFinalized()&&pcSlice->getSliceBits()+numberOfWrittenBits>pcSlice->getSliceArgument()<<3) 
1093  {
1094    pcSlice->setSliceSegmentCurEndCUAddr(iGranularityEnd);
1095    pcSlice->setSliceCurEndCUAddr(iGranularityEnd);
1096    return;
1097  }
1098  // Set dependent slice end parameter
1099  if(pcSlice->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES&&!pcSlice->getFinalized()&&pcSlice->getSliceSegmentBits()+numberOfWrittenBits > pcSlice->getSliceSegmentArgument()<<3) 
1100  {
1101    pcSlice->setSliceSegmentCurEndCUAddr(iGranularityEnd);
1102    return;
1103  }
1104  if(granularityBoundary)
1105  {
1106    pcSlice->setSliceBits( (UInt)(pcSlice->getSliceBits() + numberOfWrittenBits) );
1107    pcSlice->setSliceSegmentBits(pcSlice->getSliceSegmentBits()+numberOfWrittenBits);
1108    if (m_pcBitCounter)
1109    {
1110      m_pcEntropyCoder->resetBits();     
1111    }
1112  }
1113}
1114
1115/** Compute QP for each CU
1116 * \param pcCU Target CU
1117 * \param uiDepth CU depth
1118 * \returns quantization parameter
1119 */
1120Int TEncCu::xComputeQP( TComDataCU* pcCU, UInt uiDepth )
1121{
1122  Int iBaseQp = pcCU->getSlice()->getSliceQp();
1123  Int iQpOffset = 0;
1124  if ( m_pcEncCfg->getUseAdaptiveQP() )
1125  {
1126    TEncPic* pcEPic = dynamic_cast<TEncPic*>( pcCU->getPic() );
1127    UInt uiAQDepth = min( uiDepth, pcEPic->getMaxAQDepth()-1 );
1128    TEncPicQPAdaptationLayer* pcAQLayer = pcEPic->getAQLayer( uiAQDepth );
1129    UInt uiAQUPosX = pcCU->getCUPelX() / pcAQLayer->getAQPartWidth();
1130    UInt uiAQUPosY = pcCU->getCUPelY() / pcAQLayer->getAQPartHeight();
1131    UInt uiAQUStride = pcAQLayer->getAQPartStride();
1132    TEncQPAdaptationUnit* acAQU = pcAQLayer->getQPAdaptationUnit();
1133
1134    Double dMaxQScale = pow(2.0, m_pcEncCfg->getQPAdaptationRange()/6.0);
1135    Double dAvgAct = pcAQLayer->getAvgActivity();
1136    Double dCUAct = acAQU[uiAQUPosY * uiAQUStride + uiAQUPosX].getActivity();
1137    Double dNormAct = (dMaxQScale*dCUAct + dAvgAct) / (dCUAct + dMaxQScale*dAvgAct);
1138    Double dQpOffset = log(dNormAct) / log(2.0) * 6.0;
1139    iQpOffset = Int(floor( dQpOffset + 0.49999 ));
1140  }
1141  return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQp+iQpOffset );
1142}
1143
1144/** encode a CU block recursively
1145 * \param pcCU
1146 * \param uiAbsPartIdx
1147 * \param uiDepth
1148 * \returns Void
1149 */
1150Void TEncCu::xEncodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1151{
1152  TComPic* pcPic = pcCU->getPic();
1153 
1154  Bool bBoundary = false;
1155  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
1156  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
1157  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
1158  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
1159 
1160  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
1161  // If slice start is within this cu...
1162  Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr() > pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && 
1163    pcSlice->getSliceSegmentCurStartCUAddr() < pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcPic->getNumPartInCU() >> (uiDepth<<1) );
1164  // We need to split, so don't try these modes.
1165  if(!bSliceStart&&( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
1166  {
1167    m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
1168  }
1169  else
1170  {
1171    bBoundary = true;
1172  }
1173 
1174  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < (g_uiMaxCUDepth-g_uiAddCUDepth) ) ) || bBoundary )
1175  {
1176    UInt uiQNumParts = ( pcPic->getNumPartInCU() >> (uiDepth<<1) )>>2;
1177    if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
1178    {
1179      setdQPFlag(true);
1180    }
1181    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts )
1182    {
1183      uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
1184      uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
1185      Bool bInSlice = pcCU->getSCUAddr()+uiAbsPartIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurEndCUAddr();
1186      if(bInSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
1187      {
1188        xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 );
1189      }
1190    }
1191    return;
1192  }
1193 
1194  if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
1195  {
1196    setdQPFlag(true);
1197  }
1198  if (pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
1199  {
1200    m_pcEntropyCoder->encodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx );
1201  }
1202  if( !pcCU->getSlice()->isIntra() )
1203  {
1204    m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx );
1205  }
1206 
1207  if( pcCU->isSkipped( uiAbsPartIdx ) )
1208  {
1209    m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx );
1210    finishCU(pcCU,uiAbsPartIdx,uiDepth);
1211    return;
1212  }
1213  m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx );
1214 
1215  m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth );
1216 
1217  if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N )
1218  {
1219    m_pcEntropyCoder->encodeIPCMInfo( pcCU, uiAbsPartIdx );
1220
1221    if(pcCU->getIPCMFlag(uiAbsPartIdx))
1222    {
1223      // Encode slice finish
1224      finishCU(pcCU,uiAbsPartIdx,uiDepth);
1225      return;
1226    }
1227  }
1228
1229  // prediction Info ( Intra : direction mode, Inter : Mv, reference idx )
1230  m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx );
1231 
1232  // Encode Coefficients
1233  Bool bCodeDQP = getdQPFlag();
1234  m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, pcCU->getWidth (uiAbsPartIdx), pcCU->getHeight(uiAbsPartIdx), bCodeDQP );
1235  setdQPFlag( bCodeDQP );
1236
1237  // --- write terminating bit ---
1238  finishCU(pcCU,uiAbsPartIdx,uiDepth);
1239}
1240
1241/** check RD costs for a CU block encoded with merge
1242 * \param rpcBestCU
1243 * \param rpcTempCU
1244 * \returns Void
1245 */
1246Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool *earlyDetectionSkipMode )
1247{
1248  assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE );
1249  TComMvField  cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
1250  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
1251  Int numValidMergeCand = 0;
1252
1253  for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui )
1254  {
1255    uhInterDirNeighbours[ui] = 0;
1256  }
1257  UChar uhDepth = rpcTempCU->getDepth( 0 );
1258
1259#if H_3D_VSO // M1  //nececcary here?
1260  if( m_pcRdCost->getUseRenModel() )
1261  {
1262    UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth ( );
1263    UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight( );
1264    Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr( );
1265    UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
1266    m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
1267  }
1268#endif
1269
1270  rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
1271  rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth );
1272  rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand );
1273
1274  Int mergeCandBuffer[MRG_MAX_NUM_CANDS];
1275  for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui )
1276  {
1277    mergeCandBuffer[ui] = 0;
1278  }
1279
1280  Bool bestIsSkip = false;
1281
1282  UInt iteration;
1283  if ( rpcTempCU->isLosslessCoded(0))
1284  {
1285    iteration = 1;
1286  }
1287  else 
1288  {
1289    iteration = 2;
1290  }
1291
1292  for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual )
1293  {
1294    for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
1295    {
1296      {
1297        if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1))
1298        {
1299
1300        if( !(bestIsSkip && uiNoResidual == 0) )
1301        {
1302          // set MC parameters
1303          rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to LCU level
1304          rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(),     0, uhDepth );
1305          rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
1306          rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level
1307          rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level
1308          rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level
1309          rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
1310          rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
1311
1312       // do MC
1313       m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
1314       // estimate residual and encode everything
1315
1316#if H_3D_VSO //M2
1317       if( m_pcRdCost->getUseRenModel() )
1318       { //Reset
1319         UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth    ();
1320         UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight   ();
1321         Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr ();
1322         UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride   ();
1323         m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
1324       }
1325#endif
1326
1327       m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU,
1328         m_ppcOrigYuv    [uhDepth],
1329         m_ppcPredYuvTemp[uhDepth],
1330         m_ppcResiYuvTemp[uhDepth],
1331         m_ppcResiYuvBest[uhDepth],
1332         m_ppcRecoYuvTemp[uhDepth],
1333         (uiNoResidual? true:false));
1334
1335
1336       if(uiNoResidual==0)
1337       {
1338         if(rpcTempCU->getQtRootCbf(0) == 0)
1339         {
1340           mergeCandBuffer[uiMergeCand] = 1;
1341         }
1342       }
1343
1344       rpcTempCU->setSkipFlagSubParts( rpcTempCU->getQtRootCbf(0) == 0, 0, uhDepth );
1345          Int orgQP = rpcTempCU->getQP( 0 );
1346          xCheckDQP( rpcTempCU );
1347          xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
1348          rpcTempCU->initEstData( uhDepth, orgQP );
1349
1350
1351      if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip )
1352      {
1353        bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0;
1354      }
1355
1356    }
1357    }
1358   }
1359  }
1360
1361  if(uiNoResidual == 0 && m_pcEncCfg->getUseEarlySkipDetection())
1362  {
1363    if(rpcBestCU->getQtRootCbf( 0 ) == 0)
1364    {
1365      if( rpcBestCU->getMergeFlag( 0 ))
1366      {
1367        *earlyDetectionSkipMode = true;
1368      }
1369      else
1370      {
1371        Int absoulte_MV=0;
1372        for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
1373        {
1374          if ( rpcBestCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
1375          {
1376            TComCUMvField* pcCUMvField = rpcBestCU->getCUMvField(RefPicList( uiRefListIdx ));
1377            Int iHor = pcCUMvField->getMvd( 0 ).getAbsHor();
1378            Int iVer = pcCUMvField->getMvd( 0 ).getAbsVer();
1379            absoulte_MV+=iHor+iVer;
1380          }
1381        }
1382
1383        if(absoulte_MV == 0)
1384        {
1385          *earlyDetectionSkipMode = true;
1386        }
1387      }
1388    }
1389  }
1390 }
1391}
1392
1393
1394#if AMP_MRG
1395Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bUseMRG)
1396#else
1397Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize )
1398#endif
1399{
1400  UChar uhDepth = rpcTempCU->getDepth( 0 );
1401#if H_3D_VSO // M3
1402  if( m_pcRdCost->getUseRenModel() )
1403  {
1404    UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth ( );
1405    UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight( );
1406    Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr( );
1407    UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
1408    m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
1409  }
1410#endif
1411
1412  rpcTempCU->setDepthSubParts( uhDepth, 0 );
1413 
1414  rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth );
1415
1416  rpcTempCU->setPartSizeSubParts  ( ePartSize,  0, uhDepth );
1417  rpcTempCU->setPredModeSubParts  ( MODE_INTER, 0, uhDepth );
1418  rpcTempCU->setCUTransquantBypassSubParts  ( m_pcEncCfg->getCUTransquantBypassFlagValue(),      0, uhDepth );
1419 
1420#if AMP_MRG
1421  rpcTempCU->setMergeAMP (true);
1422  m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], false, bUseMRG );
1423#else 
1424  m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] );
1425#endif
1426
1427#if AMP_MRG
1428  if ( !rpcTempCU->getMergeAMP() )
1429  {
1430    return;
1431  }
1432#endif
1433
1434#if RATE_CONTROL_LAMBDA_DOMAIN
1435  if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
1436  {
1437    UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
1438      m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
1439      rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
1440    m_temporalSAD = (Int)SAD;
1441  }
1442#endif
1443
1444  m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false );
1445
1446
1447#if H_3D_VSO // M4
1448  if( m_pcRdCost->getUseLambdaScaleVSO() )
1449    rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
1450  else
1451#endif
1452  rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
1453
1454  xCheckDQP( rpcTempCU );
1455  xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
1456}
1457
1458Void TEncCu::xCheckRDCostIntra( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize )
1459{
1460  UInt uiDepth = rpcTempCU->getDepth( 0 );
1461 
1462#if H_3D_VSO // M5
1463  if( m_pcRdCost->getUseRenModel() )
1464  {
1465    UInt  uiWidth     = m_ppcOrigYuv[uiDepth]->getWidth   ();
1466    UInt  uiHeight    = m_ppcOrigYuv[uiDepth]->getHeight  ();
1467    Pel*  piSrc       = m_ppcOrigYuv[uiDepth]->getLumaAddr();
1468    UInt  uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride  ();
1469    m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
1470  }
1471#endif
1472
1473  rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth );
1474
1475  rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth );
1476  rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth );
1477  rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth );
1478 
1479  Bool bSeparateLumaChroma = true; // choose estimation mode
1480  UInt uiPreCalcDistC      = 0;
1481  if( !bSeparateLumaChroma )
1482  {
1483    m_pcPredSearch->preestChromaPredMode( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth] );
1484  }
1485  m_pcPredSearch  ->estIntraPredQT      ( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, bSeparateLumaChroma );
1486
1487  m_ppcRecoYuvTemp[uiDepth]->copyToPicLuma(rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU() );
1488 
1489#if H_3D_DIM_SDC
1490  if( !rpcTempCU->getSDCFlag( 0 ) )
1491#endif
1492  m_pcPredSearch  ->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC );
1493 
1494  m_pcEntropyCoder->resetBits();
1495  if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
1496  {
1497    m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0,          true );
1498  }
1499  m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0,          true );
1500  m_pcEntropyCoder->encodePredMode( rpcTempCU, 0,          true );
1501  m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true );
1502  m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0,          true );
1503  m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0, true );
1504
1505  // Encode Coefficients
1506  Bool bCodeDQP = getdQPFlag();
1507  m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, rpcTempCU->getWidth (0), rpcTempCU->getHeight(0), bCodeDQP );
1508  setdQPFlag( bCodeDQP );
1509 
1510  if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
1511 
1512  rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits();
1513  if(m_pcEncCfg->getUseSBACRD())
1514  {
1515    rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
1516  }
1517
1518#if H_3D_VSO // M6
1519  if( m_pcRdCost->getUseLambdaScaleVSO()) 
1520    rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); 
1521  else
1522#endif
1523  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
1524 
1525  xCheckDQP( rpcTempCU );
1526  xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth);
1527}
1528
1529/** Check R-D costs for a CU with PCM mode.
1530 * \param rpcBestCU pointer to best mode CU data structure
1531 * \param rpcTempCU pointer to testing mode CU data structure
1532 * \returns Void
1533 *
1534 * \note Current PCM implementation encodes sample values in a lossless way. The distortion of PCM mode CUs are zero. PCM mode is selected if the best mode yields bits greater than that of PCM mode.
1535 */
1536Void TEncCu::xCheckIntraPCM( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU )
1537{
1538  UInt uiDepth = rpcTempCU->getDepth( 0 );
1539
1540  rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth );
1541
1542  rpcTempCU->setIPCMFlag(0, true);
1543  rpcTempCU->setIPCMFlagSubParts (true, 0, rpcTempCU->getDepth(0));
1544  rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );
1545  rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth );
1546  rpcTempCU->setTrIdxSubParts ( 0, 0, uiDepth );
1547  rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth );
1548
1549  m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]);
1550
1551  if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
1552
1553  m_pcEntropyCoder->resetBits();
1554  if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
1555  {
1556    m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0,          true );
1557  }
1558  m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0,          true );
1559  m_pcEntropyCoder->encodePredMode ( rpcTempCU, 0,          true );
1560  m_pcEntropyCoder->encodePartSize ( rpcTempCU, 0, uiDepth, true );
1561  m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true );
1562
1563  if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
1564
1565  rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits();
1566  if(m_pcEncCfg->getUseSBACRD())
1567  {
1568    rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
1569  }
1570#if H_3D_VSO // M44
1571  if ( m_pcRdCost->getUseVSO() )
1572    rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
1573  else
1574#endif
1575  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
1576
1577  xCheckDQP( rpcTempCU );
1578  xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth );
1579}
1580
1581/** check whether current try is the best with identifying the depth of current try
1582 * \param rpcBestCU
1583 * \param rpcTempCU
1584 * \returns Void
1585 */
1586Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth )
1587{
1588  if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() )
1589  {
1590    TComYuv* pcYuv;
1591    // Change Information data
1592    TComDataCU* pcCU = rpcBestCU;
1593    rpcBestCU = rpcTempCU;
1594    rpcTempCU = pcCU;
1595
1596    // Change Prediction data
1597    pcYuv = m_ppcPredYuvBest[uiDepth];
1598    m_ppcPredYuvBest[uiDepth] = m_ppcPredYuvTemp[uiDepth];
1599    m_ppcPredYuvTemp[uiDepth] = pcYuv;
1600
1601    // Change Reconstruction data
1602    pcYuv = m_ppcRecoYuvBest[uiDepth];
1603    m_ppcRecoYuvBest[uiDepth] = m_ppcRecoYuvTemp[uiDepth];
1604    m_ppcRecoYuvTemp[uiDepth] = pcYuv;
1605
1606    pcYuv = NULL;
1607    pcCU  = NULL;
1608
1609    if( m_bUseSBACRD )  // store temp best CI for next CU coding
1610      m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]);
1611  }
1612}
1613
1614Void TEncCu::xCheckDQP( TComDataCU* pcCU )
1615{
1616  UInt uiDepth = pcCU->getDepth( 0 );
1617
1618  if( pcCU->getSlice()->getPPS()->getUseDQP() && (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() )
1619  {
1620    if ( pcCU->getCbf( 0, TEXT_LUMA, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_U, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_V, 0 ) )
1621    {
1622#if !RDO_WITHOUT_DQP_BITS
1623      m_pcEntropyCoder->resetBits();
1624      m_pcEntropyCoder->encodeQP( pcCU, 0, false );
1625      pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits
1626      if(m_pcEncCfg->getUseSBACRD())
1627      {
1628        pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
1629      }
1630#if H_3D_VSO // M45
1631      if ( m_pcRdCost->getUseVSO() )     
1632        pcCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( pcCU->getTotalBits(), pcCU->getTotalDistortion() );     
1633      else
1634#endif
1635      pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() );
1636#endif
1637    }
1638    else
1639    {
1640      pcCU->setQPSubParts( pcCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP
1641    }
1642  }
1643}
1644
1645Void TEncCu::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst)
1646{
1647  pDst->iN = pSrc->iN;
1648  for (Int i = 0; i < pSrc->iN; i++)
1649  {
1650    pDst->m_acMvCand[i] = pSrc->m_acMvCand[i];
1651  }
1652}
1653Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth, TComDataCU* pcCU, UInt uiLPelX, UInt uiTPelY )
1654{
1655  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
1656  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
1657  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
1658  Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && 
1659    pcSlice->getSliceSegmentCurStartCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) );
1660  Bool bSliceEnd   = pcSlice->getSliceSegmentCurEndCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && 
1661    pcSlice->getSliceSegmentCurEndCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) );
1662  if(!bSliceEnd && !bSliceStart && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
1663  {
1664    UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx];
1665    UInt uiSrcBlkWidth = rpcPic->getNumPartInWidth() >> (uiSrcDepth);
1666    UInt uiBlkWidth    = rpcPic->getNumPartInWidth() >> (uiDepth);
1667    UInt uiPartIdxX = ( ( uiAbsPartIdxInRaster % rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth;
1668    UInt uiPartIdxY = ( ( uiAbsPartIdxInRaster / rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth;
1669    UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX;
1670    m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx);
1671  }
1672  else
1673  {
1674    UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) )>>2;
1675
1676    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts )
1677    {
1678      UInt uiSubCULPelX   = uiLPelX + ( g_uiMaxCUWidth >>(uiDepth+1) )*( uiPartUnitIdx &  1 );
1679      UInt uiSubCUTPelY   = uiTPelY + ( g_uiMaxCUHeight>>(uiDepth+1) )*( uiPartUnitIdx >> 1 );
1680
1681      Bool bInSlice = rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+uiQNumParts > pcSlice->getSliceSegmentCurStartCUAddr() && 
1682        rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx < pcSlice->getSliceSegmentCurEndCUAddr();
1683      if(bInSlice&&( uiSubCULPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiSubCUTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
1684      {
1685        xCopyYuv2Pic( rpcPic, uiCUAddr, uiAbsPartIdx, uiDepth+1, uiSrcDepth, pcCU, uiSubCULPelX, uiSubCUTPelY );   // Copy Yuv data to picture Yuv
1686      }
1687    }
1688  }
1689}
1690
1691Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth )
1692{
1693  UInt uiCurrDepth = uiNextDepth - 1;
1694  m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx );
1695}
1696
1697/** Function for filling the PCM buffer of a CU using its original sample array
1698 * \param pcCU pointer to current CU
1699 * \param pcOrgYuv pointer to original sample array
1700 * \returns Void
1701 */
1702Void TEncCu::xFillPCMBuffer     ( TComDataCU*& pCU, TComYuv* pOrgYuv )
1703{
1704
1705  UInt   width        = pCU->getWidth(0);
1706  UInt   height       = pCU->getHeight(0);
1707
1708  Pel*   pSrcY = pOrgYuv->getLumaAddr(0, width); 
1709  Pel*   pDstY = pCU->getPCMSampleY();
1710  UInt   srcStride = pOrgYuv->getStride();
1711
1712  for(Int y = 0; y < height; y++ )
1713  {
1714    for(Int x = 0; x < width; x++ )
1715    {
1716      pDstY[x] = pSrcY[x];
1717    }
1718    pDstY += width;
1719    pSrcY += srcStride;
1720  }
1721
1722  Pel* pSrcCb       = pOrgYuv->getCbAddr();
1723  Pel* pSrcCr       = pOrgYuv->getCrAddr();;
1724
1725  Pel* pDstCb       = pCU->getPCMSampleCb();
1726  Pel* pDstCr       = pCU->getPCMSampleCr();;
1727
1728  UInt srcStrideC = pOrgYuv->getCStride();
1729  UInt heightC   = height >> 1;
1730  UInt widthC    = width  >> 1;
1731
1732  for(Int y = 0; y < heightC; y++ )
1733  {
1734    for(Int x = 0; x < widthC; x++ )
1735    {
1736      pDstCb[x] = pSrcCb[x];
1737      pDstCr[x] = pSrcCr[x];
1738    }
1739    pDstCb += widthC;
1740    pDstCr += widthC;
1741    pSrcCb += srcStrideC;
1742    pSrcCr += srcStrideC;
1743  }
1744}
1745
1746#if ADAPTIVE_QP_SELECTION
1747/** Collect ARL statistics from one block
1748  */
1749Int TEncCu::xTuCollectARLStats(TCoeff* rpcCoeff, Int* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples )
1750{
1751  for( Int n = 0; n < NumCoeffInCU; n++ )
1752  {
1753    Int u = abs( rpcCoeff[ n ] );
1754    Int absc = rpcArlCoeff[ n ];
1755
1756    if( u != 0 )
1757    {
1758      if( u < LEVEL_RANGE )
1759      {
1760        cSum[ u ] += ( Double )absc;
1761        numSamples[ u ]++;
1762      }
1763      else 
1764      {
1765        cSum[ LEVEL_RANGE ] += ( Double )absc - ( Double )( u << ARL_C_PRECISION );
1766        numSamples[ LEVEL_RANGE ]++;
1767      }
1768    }
1769  }
1770
1771  return 0;
1772}
1773
1774/** Collect ARL statistics from one LCU
1775 * \param pcCU
1776 */
1777Void TEncCu::xLcuCollectARLStats(TComDataCU* rpcCU )
1778{
1779  Double cSum[ LEVEL_RANGE + 1 ];     //: the sum of DCT coefficients corresponding to datatype and quantization output
1780  UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to datatype and quantization output
1781
1782  TCoeff* pCoeffY = rpcCU->getCoeffY();
1783  Int* pArlCoeffY = rpcCU->getArlCoeffY();
1784
1785  UInt uiMinCUWidth = g_uiMaxCUWidth >> g_uiMaxCUDepth;
1786  UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth;
1787
1788  memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) );
1789  memset( numSamples, 0, sizeof( UInt )*(LEVEL_RANGE+1) );
1790
1791  // Collect stats to cSum[][] and numSamples[][]
1792  for(Int i = 0; i < rpcCU->getTotalNumPart(); i ++ )
1793  {
1794    UInt uiTrIdx = rpcCU->getTransformIdx(i);
1795
1796    if(rpcCU->getPredictionMode(i) == MODE_INTER)
1797    if( rpcCU->getCbf( i, TEXT_LUMA, uiTrIdx ) )
1798    {
1799      xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples);
1800    }//Note that only InterY is processed. QP rounding is based on InterY data only.
1801   
1802    pCoeffY  += uiMinNumCoeffInCU;
1803    pArlCoeffY  += uiMinNumCoeffInCU;
1804  }
1805
1806  for(Int u=1; u<LEVEL_RANGE;u++)
1807  {
1808    m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ;
1809    m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ;
1810  }
1811  m_pcTrQuant->getSliceSumC()[LEVEL_RANGE] += cSum[ LEVEL_RANGE ] ;
1812  m_pcTrQuant->getSliceNSamples()[LEVEL_RANGE] += numSamples[ LEVEL_RANGE ] ;
1813}
1814#endif
1815//! \}
Note: See TracBrowser for help on using the repository browser.