source: 3DVCSoftware/branches/HTM-9.0-Fix/source/Lib/TLibEncoder/TEncCu.cpp @ 728

Last change on this file since 728 was 728, checked in by mediatek-htm, 10 years ago

One added macro is “MTK_F0110_FIX”.
The added macro disabled sub-PU IVMP for depth and fixed some delete problems.

  • Property svn:eol-style set to native
File size: 94.8 KB
RevLine 
[5]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
[56]4 * granted under this license. 
[5]5 *
[608]6 * Copyright (c) 2010-2013, ITU/ISO/IEC
[5]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.
[56]17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
[5]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 */
[2]33
[56]34/** \file     TEncCu.cpp
35    \brief    Coding Unit (CU) encoder class
[2]36*/
37
38#include <stdio.h>
39#include "TEncTop.h"
40#include "TEncCu.h"
41#include "TEncAnalyze.h"
42
[56]43#include <cmath>
44#include <algorithm>
45using namespace std;
46
47//! \ingroup TLibEncoder
48//! \{
49
[2]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;
[56]62 
[2]63  m_uhTotalDepth   = uhTotalDepth + 1;
64  m_ppcBestCU      = new TComDataCU*[m_uhTotalDepth-1];
65  m_ppcTempCU      = new TComDataCU*[m_uhTotalDepth-1];
[608]66   
67#if H_3D_ARP
[443]68  m_ppcWeightedTempCU = new TComDataCU*[m_uhTotalDepth-1];
69#endif
[608]70
[2]71  m_ppcPredYuvBest = new TComYuv*[m_uhTotalDepth-1];
72  m_ppcResiYuvBest = new TComYuv*[m_uhTotalDepth-1];
73  m_ppcRecoYuvBest = new TComYuv*[m_uhTotalDepth-1];
74  m_ppcPredYuvTemp = new TComYuv*[m_uhTotalDepth-1];
75  m_ppcResiYuvTemp = new TComYuv*[m_uhTotalDepth-1];
76  m_ppcRecoYuvTemp = new TComYuv*[m_uhTotalDepth-1];
77  m_ppcOrigYuv     = new TComYuv*[m_uhTotalDepth-1];
[56]78 
[2]79  UInt uiNumPartitions;
80  for( i=0 ; i<m_uhTotalDepth-1 ; i++)
81  {
82    uiNumPartitions = 1<<( ( m_uhTotalDepth - i - 1 )<<1 );
83    UInt uiWidth  = uiMaxWidth  >> i;
84    UInt uiHeight = uiMaxHeight >> i;
[56]85   
86    m_ppcBestCU[i] = new TComDataCU; m_ppcBestCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) );
87    m_ppcTempCU[i] = new TComDataCU; m_ppcTempCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) );
[608]88   
89#if H_3D_ARP
[443]90    m_ppcWeightedTempCU[i] = new TComDataCU; m_ppcWeightedTempCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) );
[608]91#endif 
92
[2]93    m_ppcPredYuvBest[i] = new TComYuv; m_ppcPredYuvBest[i]->create(uiWidth, uiHeight);
94    m_ppcResiYuvBest[i] = new TComYuv; m_ppcResiYuvBest[i]->create(uiWidth, uiHeight);
95    m_ppcRecoYuvBest[i] = new TComYuv; m_ppcRecoYuvBest[i]->create(uiWidth, uiHeight);
[56]96   
[2]97    m_ppcPredYuvTemp[i] = new TComYuv; m_ppcPredYuvTemp[i]->create(uiWidth, uiHeight);
98    m_ppcResiYuvTemp[i] = new TComYuv; m_ppcResiYuvTemp[i]->create(uiWidth, uiHeight);
99    m_ppcRecoYuvTemp[i] = new TComYuv; m_ppcRecoYuvTemp[i]->create(uiWidth, uiHeight);
[56]100   
[2]101    m_ppcOrigYuv    [i] = new TComYuv; m_ppcOrigYuv    [i]->create(uiWidth, uiHeight);
102  }
[56]103 
104  m_bEncodeDQP = false;
[655]105#if RATE_CONTROL_LAMBDA_DOMAIN
106#if !M0036_RC_IMPROVEMENT
[608]107  m_LCUPredictionSAD = 0;
108  m_addSADDepth      = 0;
109  m_temporalSAD      = 0;
110#endif
[655]111#if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
112  m_LCUPredictionSAD = 0;
113  m_addSADDepth      = 0;
114  m_temporalSAD      = 0;
115  m_spatialSAD       = 0;
116#endif
117#endif
118#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
119  m_LCUPredictionSAD = 0;
120  m_addSADDepth      = 0;
121  m_temporalSAD      = 0;
122  m_spatialSAD       = 0;
123#endif
[2]124
125  // initialize partition order.
126  UInt* piTmp = &g_auiZscanToRaster[0];
127  initZscanToRaster( m_uhTotalDepth, 1, 0, piTmp);
128  initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uhTotalDepth );
[56]129 
[2]130  // initialize conversion matrix from partition index to pel
131  initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uhTotalDepth );
132}
133
134Void TEncCu::destroy()
135{
136  Int i;
[56]137 
[2]138  for( i=0 ; i<m_uhTotalDepth-1 ; i++)
139  {
140    if(m_ppcBestCU[i])
141    {
142      m_ppcBestCU[i]->destroy();      delete m_ppcBestCU[i];      m_ppcBestCU[i] = NULL;
143    }
144    if(m_ppcTempCU[i])
145    {
146      m_ppcTempCU[i]->destroy();      delete m_ppcTempCU[i];      m_ppcTempCU[i] = NULL;
147    }
[608]148#if H_3D_ARP
149    if(m_ppcWeightedTempCU[i])
150    {
151      m_ppcWeightedTempCU[i]->destroy(); delete m_ppcWeightedTempCU[i]; m_ppcWeightedTempCU[i] = NULL;
152    }
153#endif
[2]154    if(m_ppcPredYuvBest[i])
155    {
156      m_ppcPredYuvBest[i]->destroy(); delete m_ppcPredYuvBest[i]; m_ppcPredYuvBest[i] = NULL;
157    }
158    if(m_ppcResiYuvBest[i])
159    {
160      m_ppcResiYuvBest[i]->destroy(); delete m_ppcResiYuvBest[i]; m_ppcResiYuvBest[i] = NULL;
161    }
162    if(m_ppcRecoYuvBest[i])
163    {
164      m_ppcRecoYuvBest[i]->destroy(); delete m_ppcRecoYuvBest[i]; m_ppcRecoYuvBest[i] = NULL;
165    }
166    if(m_ppcPredYuvTemp[i])
167    {
168      m_ppcPredYuvTemp[i]->destroy(); delete m_ppcPredYuvTemp[i]; m_ppcPredYuvTemp[i] = NULL;
169    }
170    if(m_ppcResiYuvTemp[i])
171    {
172      m_ppcResiYuvTemp[i]->destroy(); delete m_ppcResiYuvTemp[i]; m_ppcResiYuvTemp[i] = NULL;
173    }
174    if(m_ppcRecoYuvTemp[i])
175    {
176      m_ppcRecoYuvTemp[i]->destroy(); delete m_ppcRecoYuvTemp[i]; m_ppcRecoYuvTemp[i] = NULL;
177    }
178    if(m_ppcOrigYuv[i])
179    {
180      m_ppcOrigYuv[i]->destroy();     delete m_ppcOrigYuv[i];     m_ppcOrigYuv[i] = NULL;
181    }
182  }
183  if(m_ppcBestCU)
184  {
185    delete [] m_ppcBestCU;
186    m_ppcBestCU = NULL;
187  }
188  if(m_ppcTempCU)
189  {
190    delete [] m_ppcTempCU;
191    m_ppcTempCU = NULL;
192  }
[608]193
194#if H_3D_ARP
195  if(m_ppcWeightedTempCU)
196  {
197    delete [] m_ppcWeightedTempCU; 
198    m_ppcWeightedTempCU = NULL; 
199  }
200#endif
[2]201  if(m_ppcPredYuvBest)
202  {
203    delete [] m_ppcPredYuvBest;
204    m_ppcPredYuvBest = NULL;
205  }
206  if(m_ppcResiYuvBest)
207  {
208    delete [] m_ppcResiYuvBest;
209    m_ppcResiYuvBest = NULL;
210  }
211  if(m_ppcRecoYuvBest)
212  {
213    delete [] m_ppcRecoYuvBest;
214    m_ppcRecoYuvBest = NULL;
215  }
216  if(m_ppcPredYuvTemp)
217  {
218    delete [] m_ppcPredYuvTemp;
219    m_ppcPredYuvTemp = NULL;
220  }
221  if(m_ppcResiYuvTemp)
222  {
223    delete [] m_ppcResiYuvTemp;
224    m_ppcResiYuvTemp = NULL;
225  }
226  if(m_ppcRecoYuvTemp)
227  {
228    delete [] m_ppcRecoYuvTemp;
229    m_ppcRecoYuvTemp = NULL;
230  }
231  if(m_ppcOrigYuv)
232  {
233    delete [] m_ppcOrigYuv;
234    m_ppcOrigYuv = NULL;
235  }
236}
237
238/** \param    pcEncTop      pointer of encoder class
239 */
240Void TEncCu::init( TEncTop* pcEncTop )
241{
242  m_pcEncCfg           = pcEncTop;
243  m_pcPredSearch       = pcEncTop->getPredSearch();
244  m_pcTrQuant          = pcEncTop->getTrQuant();
245  m_pcBitCounter       = pcEncTop->getBitCounter();
246  m_pcRdCost           = pcEncTop->getRdCost();
[56]247 
[2]248  m_pcEntropyCoder     = pcEncTop->getEntropyCoder();
249  m_pcCavlcCoder       = pcEncTop->getCavlcCoder();
250  m_pcSbacCoder       = pcEncTop->getSbacCoder();
251  m_pcBinCABAC         = pcEncTop->getBinCABAC();
[56]252 
[2]253  m_pppcRDSbacCoder   = pcEncTop->getRDSbacCoder();
254  m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder();
[56]255 
[2]256  m_bUseSBACRD        = pcEncTop->getUseSBACRD();
[608]257  m_pcRateCtrl        = pcEncTop->getRateCtrl();
[2]258}
259
260// ====================================================================================================================
261// Public member functions
262// ====================================================================================================================
263
264/** \param  rpcCU pointer of CU data class
265 */
266Void TEncCu::compressCU( TComDataCU*& rpcCU )
267{
[56]268  // initialize CU data
269  m_ppcBestCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() );
270  m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() );
271
[655]272#if RATE_CONTROL_LAMBDA_DOMAIN
273#if !M0036_RC_IMPROVEMENT
[608]274  m_addSADDepth      = 0;
275  m_LCUPredictionSAD = 0;
276  m_temporalSAD      = 0;
277#endif
[655]278#if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
279  m_LCUPredictionSAD = 0;
280  m_addSADDepth      = 0;
281  m_temporalSAD      = 0;
282  m_spatialSAD       = 0;
283#endif
284#endif
285#if KWU_RC_MADPRED_E0227
286  m_LCUPredictionSAD = 0;
287  m_addSADDepth      = 0;
288  m_temporalSAD      = 0;
289  m_spatialSAD       = 0;
290#endif
[608]291
[56]292  // analysis of CU
293  xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 );
294
295#if ADAPTIVE_QP_SELECTION
296  if( m_pcEncCfg->getUseAdaptQpSelect() )
[2]297  {
[56]298    if(rpcCU->getSlice()->getSliceType()!=I_SLICE) //IIII
299    {
300      xLcuCollectARLStats( rpcCU);
301    }
[2]302  }
[56]303#endif
304}
[608]305/** \param  pcCU  pointer of CU data class
[56]306 */
[608]307Void TEncCu::encodeCU ( TComDataCU* pcCU )
[56]308{
309  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
[2]310  {
[56]311    setdQPFlag(true);
312  }
[2]313
[56]314  // Encode CU data
315  xEncodeCU( pcCU, 0, 0 );
[2]316}
317
[56]318// ====================================================================================================================
319// Protected member functions
320// ====================================================================================================================
321/** Derive small set of test modes for AMP encoder speed-up
322 *\param   rpcBestCU
323 *\param   eParentPartSize
324 *\param   bTestAMP_Hor
325 *\param   bTestAMP_Ver
326 *\param   bTestMergeAMP_Hor
327 *\param   bTestMergeAMP_Ver
328 *\returns Void
329*/
330#if AMP_ENC_SPEEDUP
331#if AMP_MRG
332Void TEncCu::deriveTestModeAMP (TComDataCU *&rpcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver, Bool &bTestMergeAMP_Hor, Bool &bTestMergeAMP_Ver)
333#else
334Void TEncCu::deriveTestModeAMP (TComDataCU *&rpcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver)
335#endif
[2]336{
[56]337  if ( rpcBestCU->getPartitionSize(0) == SIZE_2NxN )
[2]338  {
[56]339    bTestAMP_Hor = true;
[2]340  }
[56]341  else if ( rpcBestCU->getPartitionSize(0) == SIZE_Nx2N )
[2]342  {
[56]343    bTestAMP_Ver = true;
344  }
345  else if ( rpcBestCU->getPartitionSize(0) == SIZE_2Nx2N && rpcBestCU->getMergeFlag(0) == false && rpcBestCU->isSkipped(0) == false )
346  {
347    bTestAMP_Hor = true;         
348    bTestAMP_Ver = true;         
349  }
[2]350
[56]351#if AMP_MRG
352  //! Utilizing the partition size of parent PU   
353  if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N )
354  { 
355    bTestMergeAMP_Hor = true;
356    bTestMergeAMP_Ver = true;
[2]357  }
[56]358
359  if ( eParentPartSize == SIZE_NONE ) //! if parent is intra
[2]360  {
[56]361    if ( rpcBestCU->getPartitionSize(0) == SIZE_2NxN )
[2]362    {
[56]363      bTestMergeAMP_Hor = true;
[2]364    }
[56]365    else if ( rpcBestCU->getPartitionSize(0) == SIZE_Nx2N )
[2]366    {
[56]367      bTestMergeAMP_Ver = true;
[2]368    }
369  }
370
[56]371  if ( rpcBestCU->getPartitionSize(0) == SIZE_2Nx2N && rpcBestCU->isSkipped(0) == false )
372  {
373    bTestMergeAMP_Hor = true;         
374    bTestMergeAMP_Ver = true;         
375  }
[2]376
[56]377  if ( rpcBestCU->getWidth(0) == 64 )
378  { 
379    bTestAMP_Hor = false;
380    bTestAMP_Ver = false;
381  }   
382#else
383  //! Utilizing the partition size of parent PU       
384  if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N )
385  { 
386    bTestAMP_Hor = true;
387    bTestAMP_Ver = true;
388  }
[2]389
[56]390  if ( eParentPartSize == SIZE_2Nx2N )
391  { 
392    bTestAMP_Hor = false;
393    bTestAMP_Ver = false;
394  }     
395#endif
[2]396}
[56]397#endif
[2]398
399// ====================================================================================================================
400// Protected member functions
401// ====================================================================================================================
[56]402/** Compress a CU block recursively with enabling sub-LCU-level delta QP
403 *\param   rpcBestCU
404 *\param   rpcTempCU
405 *\param   uiDepth
406 *\returns Void
407 *
408 *- for loop of QP value to compress the current CU with all possible QP
409*/
410#if AMP_ENC_SPEEDUP
411Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth, PartSize eParentPartSize )
412#else
[2]413Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth )
[56]414#endif
[2]415{
416  TComPic* pcPic = rpcBestCU->getPic();
417
[608]418#if H_3D_QTLPC
419  TComSPS *sps            = pcPic->getSlice(0)->getSPS();
420  TComPic *pcTexture      = rpcBestCU->getSlice()->getTexturePic();
[189]421
422  Bool  depthMapDetect    = (pcTexture != NULL);
423  Bool  bIntraSliceDetect = (rpcBestCU->getSlice()->getSliceType() == I_SLICE);
424
[608]425  Bool rapPic             = (rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA);
[296]426
[608]427  Bool bTry2NxN           = true;
428  Bool bTryNx2N           = true;
[115]429#endif
[2]430  // get Original YUV data from picture
431  m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() );
432
433  // variables for fast encoder decision
[655]434#if H_3D_QTLPC 
435  Bool    bTrySplit     = true;
436  Bool    bTrySplitDQP  = true;
437#endif
[2]438
[56]439  // variable for Early CU determination
440  Bool    bSubBranch = true;
441
442  // variable for Cbf fast mode PU decision
443  Bool    doNotBlockPu = true;
[608]444  Bool earlyDetectionSkipMode = false;
[56]445
[622]446#if H_3D_VSP
[608]447  DisInfo DvInfo; 
448  DvInfo.bDV = false;
449  DvInfo.m_acNBDV.setZero();
450  DvInfo.m_aVIdxCan = 0;
451#if H_3D_NBDV_REF
452  DvInfo.m_acDoNBDV.setZero();
453#endif
454#endif
[2]455  Bool bBoundary = false;
456  UInt uiLPelX   = rpcBestCU->getCUPelX();
457  UInt uiRPelX   = uiLPelX + rpcBestCU->getWidth(0)  - 1;
458  UInt uiTPelY   = rpcBestCU->getCUPelY();
459  UInt uiBPelY   = uiTPelY + rpcBestCU->getHeight(0) - 1;
460
[56]461  Int iBaseQP = xComputeQP( rpcBestCU, uiDepth );
462  Int iMinQP;
463  Int iMaxQP;
464  Bool isAddLowestQP = false;
465  Int lowestQP = -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY();
466
467  if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
[2]468  {
[56]469    Int idQP = m_pcEncCfg->getMaxDeltaQP();
470    iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
471    iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
472    if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() )
[2]473    {
[56]474      isAddLowestQP = true; 
475      iMinQP = iMinQP - 1;
476    }
477  }
478  else
479  {
480    iMinQP = rpcTempCU->getQP(0);
481    iMaxQP = rpcTempCU->getQP(0);
482  }
483
[608]484#if RATE_CONTROL_LAMBDA_DOMAIN
485  if ( m_pcEncCfg->getUseRateCtrl() )
486  {
487    iMinQP = m_pcRateCtrl->getRCQP();
488    iMaxQP = m_pcRateCtrl->getRCQP();
489  }
490#else
491  if(m_pcEncCfg->getUseRateCtrl())
492  {
493    Int qp = m_pcRateCtrl->getUnitQP();
494    iMinQP  = Clip3( MIN_QP, MAX_QP, qp);
495    iMaxQP  = Clip3( MIN_QP, MAX_QP, qp);
496  }
497#endif
498#if H_3D_IC
[724]499#if SEC_ONLY_TEXTURE_IC_F0151
500  Bool bICEnabled = rpcTempCU->getSlice()->getViewIndex() && ( rpcTempCU->getSlice()->getSliceType() == P_SLICE || rpcTempCU->getSlice()->getSliceType() == B_SLICE ) && !rpcTempCU->getSlice()->getIsDepth();
501#else
[608]502  Bool bICEnabled = rpcTempCU->getSlice()->getViewIndex() && ( rpcTempCU->getSlice()->getSliceType() == P_SLICE || rpcTempCU->getSlice()->getSliceType() == B_SLICE );
[724]503#endif
[608]504  bICEnabled = bICEnabled && rpcTempCU->getSlice()->getApplyIC();
505#endif
[56]506  // If slice start or slice end is within this cu...
507  TComSlice * pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx());
[608]508  Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurStartCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart();
509  Bool bSliceEnd = (pcSlice->getSliceSegmentCurEndCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurEndCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart());
[56]510  Bool bInsidePicture = ( uiRPelX < rpcBestCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < rpcBestCU->getSlice()->getSPS()->getPicHeightInLumaSamples() );
511  // We need to split, so don't try these modes.
512  if(!bSliceEnd && !bSliceStart && bInsidePicture )
513  {
[655]514#if  H_3D_FAST_TEXTURE_ENCODING
[608]515    Bool bIVFMerge = false;
516    Int  iIVFMaxD = 0;
517    Bool bFMD = false;
518#endif
[56]519    for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
520    {
521      if (isAddLowestQP && (iQP == iMinQP))
[2]522      {
[56]523        iQP = lowestQP;
[2]524      }
[56]525      // variables for fast encoder decision
[655]526#if H_3D_QTLPC
[608]527      bTrySplit    = true;
[655]528#endif
[2]529
[56]530      rpcTempCU->initEstData( uiDepth, iQP );
[608]531#if H_3D_QTLPC
[116]532      //logic for setting bTrySplit using the partition information that is stored of the texture colocated CU
[296]533
[608]534      if(depthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTL())
[116]535      {
[189]536        TComDataCU* pcTextureCU = pcTexture->getCU( rpcBestCU->getAddr() ); //Corresponding texture LCU
537        UInt uiCUIdx            = rpcBestCU->getZorderIdxInCU();
538        assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth); //Depth cannot be more partitionned than the texture.
539        if (pcTextureCU->getDepth(uiCUIdx) > uiDepth || pcTextureCU->getPartitionSize(uiCUIdx) == SIZE_NxN) //Texture was split.
[116]540        {
541          bTrySplit = true;
[189]542          bTryNx2N  = true;
543          bTry2NxN  = true;
[116]544        }
[189]545        else
[116]546        {
547          bTrySplit = false;
[189]548          bTryNx2N  = false;
549          bTry2NxN  = false;
[116]550        }
551      }
[115]552#endif
[608]553
554#if H_3D_NBDV
[443]555      if( rpcTempCU->getSlice()->getSliceType() != I_SLICE )
556      {
[608]557#if H_3D_ARP && H_3D_IV_MERGE
558        if( rpcTempCU->getSlice()->getVPS()->getUseAdvRP(rpcTempCU->getSlice()->getLayerId()) || rpcTempCU->getSlice()->getVPS()->getIvMvPredFlag(rpcTempCU->getSlice()->getLayerId()) )
559#else
560#if H_3D_ARP
561        if( rpcTempCU->getSlice()->getVPS()->getUseAdvRP(rpcTempCU->getSlice()->getLayerId()) )
[443]562#else
[608]563#if H_3D_IV_MERGE
564        if( rpcTempCU->getSlice()->getVPS()->getIvMvPredFlag(rpcTempCU->getSlice()->getLayerId()) )
565#else
566        if (0)
[443]567#endif
[608]568#endif
569#endif
570        {
[443]571          PartSize ePartTemp = rpcTempCU->getPartitionSize(0);
572          rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );     
[724]573#if QC_DEPTH_IV_MRG_F0125
574          if (rpcTempCU->getSlice()->getIsDepth() )
575          {
576            DvInfo.bDV = rpcTempCU->getDispNeighBlocks(0, 0, &DvInfo);
577          }
578          else
579          {
580#endif
[608]581#if H_3D_NBDV_REF
582          if(rpcTempCU->getSlice()->getVPS()->getDepthRefinementFlag( rpcTempCU->getSlice()->getLayerIdInVps()))
583            DvInfo.bDV = rpcTempCU->getDisMvpCandNBDV(&DvInfo, true);
584          else
585#endif
586            DvInfo.bDV = rpcTempCU->getDisMvpCandNBDV(&DvInfo);
587
[724]588#if QC_DEPTH_IV_MRG_F0125
589          }
590#endif
[443]591          rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
592          rpcBestCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
593          rpcTempCU->setPartSizeSubParts( ePartTemp, 0, uiDepth );
594        }
[608]595      }
[655]596#if  H_3D_FAST_TEXTURE_ENCODING
[608]597      if(rpcTempCU->getSlice()->getViewIndex() && !rpcTempCU->getSlice()->getIsDepth())
598      {
599        PartSize ePartTemp = rpcTempCU->getPartitionSize(0);
600        rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); 
601        rpcTempCU->getIVNStatus( 0, &DvInfo,  bIVFMerge, iIVFMaxD);
602        rpcTempCU->setPartSizeSubParts( ePartTemp, 0, uiDepth );
603      }
[443]604#endif
605#endif
[56]606      // do inter modes, SKIP and 2Nx2N
607      if( rpcBestCU->getSlice()->getSliceType() != I_SLICE )
[2]608      {
[608]609#if H_3D_IC
610        for( UInt uiICId = 0; uiICId < ( bICEnabled ? 2 : 1 ); uiICId++ )
[443]611        {
[608]612          Bool bICFlag = uiICId ? true : false;
[443]613#endif
[608]614        // 2Nx2N
615        if(m_pcEncCfg->getUseEarlySkipDetection())
[56]616        {
[608]617#if H_3D_IC
618          rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
[56]619#endif
[655]620#if  H_3D_FAST_TEXTURE_ENCODING
[608]621          xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD );  rpcTempCU->initEstData( uiDepth, iQP );//by Competition for inter_2Nx2N
622#else
623          xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );  rpcTempCU->initEstData( uiDepth, iQP );//by Competition for inter_2Nx2N
[189]624#endif
[622]625#if H_3D_VSP
[608]626          rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
[5]627#endif
[608]628        }
629        // SKIP
630#if H_3D_IC
631        rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
[2]632#endif
[608]633        xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode );//by Merge for inter_2Nx2N
[655]634#if  H_3D_FAST_TEXTURE_ENCODING
[608]635        bFMD = bIVFMerge && rpcBestCU->isSkipped(0);
636#endif
637        rpcTempCU->initEstData( uiDepth, iQP );
[622]638#if H_3D_VSP
[608]639        rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
640#endif
641
642        if(!m_pcEncCfg->getUseEarlySkipDetection())
643        {
[116]644          // 2Nx2N, NxN
[608]645#if H_3D_IC
[296]646            rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
647#endif
[655]648#if  H_3D_FAST_TEXTURE_ENCODING
[608]649            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD );  rpcTempCU->initEstData( uiDepth, iQP );
[2]650#else
[608]651            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );  rpcTempCU->initEstData( uiDepth, iQP );
[2]652#endif
[622]653#if H_3D_VSP
[608]654            rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
655#endif
[116]656            if(m_pcEncCfg->getUseCbfFastMode())
657            {
658              doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
659            }
[608]660        }
661#if H_3D_IC
662        }
[189]663#endif
[608]664      }
[56]665
[655]666#if H_3D_QTLPC     
[608]667      if(depthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTL())
[116]668      {
669        bTrySplitDQP = bTrySplit;
670      }
[189]671#endif
[56]672      if (isAddLowestQP && (iQP == lowestQP))
673      {
674        iQP = iMinQP;
675      }
[608]676    }
677
678#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
679    if ( uiDepth <= m_addSADDepth )
680    {
681      m_LCUPredictionSAD += m_temporalSAD;
682      m_addSADDepth = uiDepth;
683    }
[5]684#endif
[655]685#if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
686    if ( uiDepth <= m_addSADDepth )
687    {
688      m_LCUPredictionSAD += m_temporalSAD;
689      m_addSADDepth = uiDepth;
690    }
691#endif
692#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
693if ( uiDepth <= m_addSADDepth )
694{
695  m_LCUPredictionSAD += m_temporalSAD;
696  m_addSADDepth = uiDepth;
697}
698#endif
699#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_FIX_URQ
700    if(m_pcEncCfg->getUseRateCtrl())
701    {
702      Int qp = m_pcRateCtrl->getUnitQP();
703      iMinQP  = Clip3( MIN_QP, MAX_QP, qp);
704      iMaxQP  = Clip3( MIN_QP, MAX_QP, qp);
705    }
706#endif
[56]707
[608]708#if H_3D_DIM_ENC
709    if( rpcBestCU->getSlice()->getIsDepth() && rpcBestCU->getSlice()->isIRAP() )
[56]710    {
[608]711      earlyDetectionSkipMode = false;
712    }
[56]713#endif
[2]714
[608]715    if(!earlyDetectionSkipMode)
716    {
717      for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
[2]718      {
[608]719        if (isAddLowestQP && (iQP == iMinQP))
[443]720        {
[608]721          iQP = lowestQP;
[443]722        }
[608]723        rpcTempCU->initEstData( uiDepth, iQP );
724
725        // do inter modes, NxN, 2NxN, and Nx2N
726        if( rpcBestCU->getSlice()->getSliceType() != I_SLICE )
[2]727        {
[116]728          // 2Nx2N, NxN
[608]729            if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) ))
[116]730            {
[608]731              if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu
732#if H_3D_QTLPC
733                && bTrySplit
734#endif
735                )
[116]736              {
[655]737#if  H_3D_FAST_TEXTURE_ENCODING
[608]738                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN, bFMD  );
[115]739#else
[608]740                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN   );
[115]741#endif
[608]742                rpcTempCU->initEstData( uiDepth, iQP );
[622]743#if H_3D_VSP
[608]744                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
[116]745#endif
[608]746              }
[116]747            }
[56]748
[608]749          // 2NxN, Nx2N
750          if(doNotBlockPu
751#if H_3D_QTLPC
752            && bTryNx2N
[115]753#endif
[608]754            )
755          {
[655]756#if  H_3D_FAST_TEXTURE_ENCODING
[608]757            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N, bFMD  );
[115]758#else
[608]759            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N  );
[115]760#endif
[608]761            rpcTempCU->initEstData( uiDepth, iQP );
[622]762#if H_3D_VSP
[608]763            rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
[115]764#endif
[608]765            if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_Nx2N )
[116]766            {
[608]767              doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
768            }
769          }
770          if(doNotBlockPu
771#if H_3D_QTLPC
772            && bTry2NxN
[115]773#endif
[608]774            )
775          {
[655]776#if  H_3D_FAST_TEXTURE_ENCODING
[608]777            xCheckRDCostInter      ( rpcBestCU, rpcTempCU, SIZE_2NxN, bFMD  );
778#else
779            xCheckRDCostInter      ( rpcBestCU, rpcTempCU, SIZE_2NxN  );
[115]780#endif
[608]781            rpcTempCU->initEstData( uiDepth, iQP );
[622]782#if H_3D_VSP
[608]783            rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
[296]784#endif
[608]785            if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxN)
786            {
787              doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
[115]788            }
789          }
[56]790
791#if 1
[116]792          //! Try AMP (SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N, SIZE_nRx2N)
793          if( pcPic->getSlice(0)->getSPS()->getAMPAcc(uiDepth) )
794          {
[56]795#if AMP_ENC_SPEEDUP       
[116]796            Bool bTestAMP_Hor = false, bTestAMP_Ver = false;
[56]797
798#if AMP_MRG
[116]799            Bool bTestMergeAMP_Hor = false, bTestMergeAMP_Ver = false;
[56]800
[116]801            deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver, bTestMergeAMP_Hor, bTestMergeAMP_Ver);
[2]802#else
[116]803            deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver);
[56]804#endif
805
[116]806            //! Do horizontal AMP
807            if ( bTestAMP_Hor )
808            {
[608]809              if(doNotBlockPu
810#if H_3D_QTLPC
811                && bTry2NxN
812#endif
813                )
[116]814              {
[655]815#if  H_3D_FAST_TEXTURE_ENCODING
[608]816                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFMD );
817#else
818                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU );
[115]819#endif
[608]820                rpcTempCU->initEstData( uiDepth, iQP );
[622]821#if H_3D_VSP
[608]822                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
823#endif
824                if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU )
[116]825                {
[608]826                  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
827                }
828              }
829              if(doNotBlockPu
830#if H_3D_QTLPC
831                && bTry2NxN
[115]832#endif
[608]833                )
834              {
[655]835#if  H_3D_FAST_TEXTURE_ENCODING
[608]836                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFMD );
[115]837#else
[608]838                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD );
[115]839#endif
[608]840                rpcTempCU->initEstData( uiDepth, iQP );
[622]841#if H_3D_VSP
[608]842                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
843#endif
844                if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD )
[116]845                {
[608]846                  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
[116]847                }
[115]848              }
849            }
[56]850#if AMP_MRG
[116]851            else if ( bTestMergeAMP_Hor ) 
852            {
[608]853              if(doNotBlockPu
854#if H_3D_QTLPC
855                && bTry2NxN
856#endif
857                )
[116]858              {
[655]859#if  H_3D_FAST_TEXTURE_ENCODING
[608]860                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFMD, true );
861#else
862                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, true );
[115]863#endif
[608]864                rpcTempCU->initEstData( uiDepth, iQP );
[622]865#if H_3D_VSP
[608]866                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
867#endif
868                if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU )
[116]869                {
[608]870                  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
871                }
872              }
873              if(doNotBlockPu
874#if H_3D_QTLPC
875                && bTry2NxN
[115]876#endif
[608]877                )
878              {
[655]879#if  H_3D_FAST_TEXTURE_ENCODING
[608]880                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFMD, true );
[115]881#else
[608]882                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, true );
[115]883#endif
[608]884                rpcTempCU->initEstData( uiDepth, iQP );
[622]885#if H_3D_VSP
[608]886                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
887#endif
888                if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD )
[116]889                {
[608]890                  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
[116]891                }
[115]892              }
893            }
894#endif
[2]895
[116]896            //! Do horizontal AMP
897            if ( bTestAMP_Ver )
898            {
[608]899              if(doNotBlockPu
900#if H_3D_QTLPC
901                && bTryNx2N
902#endif
903                )
[116]904              {
[655]905#if  H_3D_FAST_TEXTURE_ENCODING
[608]906                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFMD );
907#else
908                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N );
[115]909#endif
[608]910                rpcTempCU->initEstData( uiDepth, iQP );
[622]911#if H_3D_VSP
[608]912                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
913#endif
914                if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N )
[116]915                {
[608]916                  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
917                }
918              }
919              if(doNotBlockPu
920#if H_3D_QTLPC
921                && bTryNx2N
[115]922#endif
[608]923                )
924              {
[655]925#if  H_3D_FAST_TEXTURE_ENCODING
[608]926                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFMD );
[115]927#else
[608]928                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N );
[115]929#endif
[608]930                rpcTempCU->initEstData( uiDepth, iQP );
[622]931#if H_3D_VSP
[608]932                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
[115]933#endif
[116]934              }
[115]935            }
[56]936#if AMP_MRG
[116]937            else if ( bTestMergeAMP_Ver )
938            {
[608]939              if(doNotBlockPu
940#if H_3D_QTLPC
941                && bTryNx2N
942#endif
943                )
[116]944              {
[655]945#if  H_3D_FAST_TEXTURE_ENCODING
[608]946                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFMD, true );
947#else
948                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, true );
[115]949#endif
[608]950                rpcTempCU->initEstData( uiDepth, iQP );
[622]951#if H_3D_VSP
[608]952                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
953#endif
954                if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N )
[116]955                {
[608]956                  doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
957                }
958              }
959              if(doNotBlockPu
960#if H_3D_QTLPC
961                && bTryNx2N
[115]962#endif
[608]963                )
964              {
[655]965#if  H_3D_FAST_TEXTURE_ENCODING
[608]966                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFMD, true );
[115]967#else
[608]968                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, true );
[115]969#endif
[608]970                rpcTempCU->initEstData( uiDepth, iQP );
[622]971#if H_3D_VSP
[608]972                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
[115]973#endif
[116]974              }
[115]975            }
[56]976#endif
[2]977
[56]978#else
[608]979#if H_3D_QTLPC
980            if (bTry2NxN)
981            {
[5]982#endif
[608]983              xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU );
984              rpcTempCU->initEstData( uiDepth, iQP );
[622]985#if H_3D_VSP
[608]986              rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
[56]987#endif
[608]988              xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD );
989              rpcTempCU->initEstData( uiDepth, iQP );
[622]990#if H_3D_VSP
[608]991              rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
[56]992#endif
[608]993#if H_3D_QTLPC
994            }
995            if (bTryNx2N)
996            {
[56]997#endif
[608]998              xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N );
999              rpcTempCU->initEstData( uiDepth, iQP );
[622]1000#if H_3D_VSP
[608]1001              rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
[56]1002#endif
[608]1003              xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N );
1004              rpcTempCU->initEstData( uiDepth, iQP );
[622]1005#if H_3D_VSP
[608]1006              rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
[56]1007#endif
[608]1008#if H_3D_QTLPC
1009            }
[56]1010#endif
[2]1011
[56]1012#endif
[608]1013          }   
[56]1014#endif
[608]1015        }
[655]1016#if  H_3D_FAST_TEXTURE_ENCODING
[608]1017        if(!bFMD)
1018        {
[189]1019#endif
[608]1020        // do normal intra modes
[655]1021       
[608]1022          // speedup for inter frames
1023          if( rpcBestCU->getSlice()->getSliceType() == I_SLICE || 
1024            rpcBestCU->getCbf( 0, TEXT_LUMA     ) != 0   ||
1025            rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0   ||
1026              rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0     
1027#if H_3D_DIM_ENC
1028            || ( rpcBestCU->getSlice()->getIsDepth() && rpcBestCU->getSlice()->isIRAP() )
[189]1029#endif
[608]1030            ) // avoid very complex intra if it is unlikely
[2]1031          {
[608]1032            xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N );
[655]1033
1034#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
1035            if ( uiDepth <= m_addSADDepth )
1036            {
1037              m_LCUPredictionSAD += m_spatialSAD;
1038              m_addSADDepth = uiDepth;
1039            }
1040#endif
1041#if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
1042            if ( uiDepth <= m_addSADDepth )
1043            {
1044              m_LCUPredictionSAD += m_spatialSAD;
1045              m_addSADDepth = uiDepth;
1046            }
1047#endif
1048
1049#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
1050            if ( uiDepth <= m_addSADDepth )
1051            {
1052              m_LCUPredictionSAD += m_spatialSAD;
1053              m_addSADDepth = uiDepth;
1054            }
1055#endif
[608]1056            rpcTempCU->initEstData( uiDepth, iQP );
1057            if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
[116]1058            {
[608]1059#if H_3D_QTLPC //Try IntraNxN
1060              if(bTrySplit)
[116]1061              {
[189]1062#endif
[608]1063                if( rpcTempCU->getWidth(0) > ( 1 << rpcTempCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) )
1064                {
1065                  xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN   );
1066                  rpcTempCU->initEstData( uiDepth, iQP );
1067                }
1068#if H_3D_QTLPC
[116]1069              }
[608]1070#endif
[56]1071            }
[2]1072          }
[608]1073        // test PCM
1074        if(pcPic->getSlice(0)->getSPS()->getUsePCM()
1075          && rpcTempCU->getWidth(0) <= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MaxSize())
1076          && rpcTempCU->getWidth(0) >= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MinSize()) )
1077        {
1078          UInt uiRawBits = (2 * g_bitDepthY + g_bitDepthC) * rpcBestCU->getWidth(0) * rpcBestCU->getHeight(0) / 2;
1079          UInt uiBestBits = rpcBestCU->getTotalBits();
1080#if H_3D_VSO // M7
1081          Double dRDCostTemp = m_pcRdCost->getUseVSO() ? m_pcRdCost->calcRdCostVSO(uiRawBits, 0) : m_pcRdCost->calcRdCost(uiRawBits, 0);
1082          if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > dRDCostTemp ))
[56]1083#else
[608]1084          if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > m_pcRdCost->calcRdCost(uiRawBits, 0)))
[56]1085#endif
[608]1086          {
1087            xCheckIntraPCM (rpcBestCU, rpcTempCU);
1088            rpcTempCU->initEstData( uiDepth, iQP );
1089          }
1090        }
[655]1091#if  H_3D_FAST_TEXTURE_ENCODING
[608]1092        }
[189]1093#endif
[608]1094        if (isAddLowestQP && (iQP == lowestQP))
[296]1095        {
[608]1096          iQP = iMinQP;
[296]1097        }
[56]1098      }
[2]1099    }
1100
1101    m_pcEntropyCoder->resetBits();
1102    m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true );
1103    rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits
[56]1104    if(m_pcEncCfg->getUseSBACRD())
1105    {
1106      rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
1107    }
[2]1108
[608]1109#if H_3D_VSO // M8
1110    if ( m_pcRdCost->getUseVSO() )   
1111      rpcBestCU->getTotalCost()  = m_pcRdCost->calcRdCostVSO( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() );   
[2]1112    else
[5]1113#endif
[608]1114    rpcBestCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() );
[2]1115
[56]1116    // Early CU determination
[608]1117    if( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->isSkipped(0) )
[2]1118    {
[56]1119      bSubBranch = false;
[2]1120    }
[56]1121    else
1122    {
1123      bSubBranch = true;
1124    }
[655]1125#if  H_3D_FAST_TEXTURE_ENCODING
[608]1126    if(rpcBestCU->getSlice()->getViewIndex() && !rpcBestCU->getSlice()->getIsDepth() && (uiDepth >=iIVFMaxD) && rpcBestCU->isSkipped(0))
1127    {
1128      bSubBranch = false;
1129    }
[2]1130#endif
1131  }
[56]1132  else if(!(bSliceEnd && bInsidePicture))
[2]1133  {
1134    bBoundary = true;
[608]1135#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
1136    m_addSADDepth++;
1137#endif
[2]1138  }
1139
[56]1140  // copy orginal YUV samples to PCM buffer
1141  if( rpcBestCU->isLosslessCoded(0) && (rpcBestCU->getIPCMFlag(0) == false))
[2]1142  {
[56]1143    xFillPCMBuffer(rpcBestCU, m_ppcOrigYuv[uiDepth]);
1144  }
1145  if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
1146  {
1147    Int idQP = m_pcEncCfg->getMaxDeltaQP();
1148    iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
1149    iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
1150    if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() )
[2]1151    {
[56]1152      isAddLowestQP = true;
1153      iMinQP = iMinQP - 1;     
[2]1154    }
[56]1155  }
1156  else if( (g_uiMaxCUWidth>>uiDepth) > rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
1157  {
1158    iMinQP = iBaseQP;
1159    iMaxQP = iBaseQP;
1160  }
1161  else
1162  {
1163    Int iStartQP;
[608]1164    if( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(rpcTempCU->getZorderIdxInCU()) == pcSlice->getSliceSegmentCurStartCUAddr())
[56]1165    {
1166      iStartQP = rpcTempCU->getQP(0);
1167    }
1168    else
1169    {
[608]1170      UInt uiCurSliceStartPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU();
[56]1171      iStartQP = rpcTempCU->getQP(uiCurSliceStartPartIdx);
1172    }
1173    iMinQP = iStartQP;
1174    iMaxQP = iStartQP;
1175  }
[608]1176#if RATE_CONTROL_LAMBDA_DOMAIN
1177  if ( m_pcEncCfg->getUseRateCtrl() )
1178  {
1179    iMinQP = m_pcRateCtrl->getRCQP();
1180    iMaxQP = m_pcRateCtrl->getRCQP();
1181  }
1182#else
1183  if(m_pcEncCfg->getUseRateCtrl())
1184  {
1185    Int qp = m_pcRateCtrl->getUnitQP();
1186    iMinQP  = Clip3( MIN_QP, MAX_QP, qp);
1187    iMaxQP  = Clip3( MIN_QP, MAX_QP, qp);
1188  }
1189#endif
[56]1190  for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
1191  {
[116]1192    if (isAddLowestQP && (iQP == iMinQP))
1193    {
1194      iQP = lowestQP;
1195    }
[56]1196    rpcTempCU->initEstData( uiDepth, iQP );
[2]1197
[56]1198    // further split
[655]1199#if H_3D_QTLPC
[56]1200    if( bSubBranch && bTrySplitDQP && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth )
[655]1201#else
1202    if( bSubBranch && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth )
1203#endif
[2]1204    {
[608]1205#if H_3D_VSO // M9
[56]1206      // reset Model
1207      if( m_pcRdCost->getUseRenModel() )
1208      {
[81]1209        UInt  uiWidth     = m_ppcOrigYuv[uiDepth]->getWidth ( );
1210        UInt  uiHeight    = m_ppcOrigYuv[uiDepth]->getHeight( );
1211        Pel*  piSrc       = m_ppcOrigYuv[uiDepth]->getLumaAddr( 0 );
1212        UInt  uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride();
1213        m_pcRdCost->setRenModelData( m_ppcBestCU[uiDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight );
[56]1214      }
1215#endif
[608]1216
[56]1217      UChar       uhNextDepth         = uiDepth+1;
1218      TComDataCU* pcSubBestPartCU     = m_ppcBestCU[uhNextDepth];
1219      TComDataCU* pcSubTempPartCU     = m_ppcTempCU[uhNextDepth];
[2]1220
[56]1221      for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ )
[2]1222      {
[56]1223        pcSubBestPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP );           // clear sub partition datas or init.
1224        pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP );           // clear sub partition datas or init.
1225
[608]1226        Bool bInSlice = pcSubBestPartCU->getSCUAddr()+pcSubBestPartCU->getTotalNumPart()>pcSlice->getSliceSegmentCurStartCUAddr()&&pcSubBestPartCU->getSCUAddr()<pcSlice->getSliceSegmentCurEndCUAddr();
[56]1227        if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
[2]1228        {
[56]1229          if( m_bUseSBACRD )
[2]1230          {
[56]1231            if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer
1232            {
1233              m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
1234            }
1235            else
1236            {
1237              m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
1238            }
[2]1239          }
[56]1240
1241#if AMP_ENC_SPEEDUP
1242          if ( rpcBestCU->isIntra(0) )
1243          {
1244            xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth, SIZE_NONE );
1245          }
[2]1246          else
1247          {
[56]1248            xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth, rpcBestCU->getPartitionSize(0) );
[2]1249          }
[56]1250#else
1251          xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth );
1252#endif
[2]1253
[56]1254          rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth );         // Keep best part data to current temporary data.
1255          xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth );
1256        }
1257        else if (bInSlice)
[2]1258        {
[56]1259          pcSubBestPartCU->copyToPic( uhNextDepth );
1260          rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth );
[2]1261        }
1262      }
1263
[56]1264      if( !bBoundary )
1265      {
1266        m_pcEntropyCoder->resetBits();
1267        m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth, true );
[2]1268
[56]1269        rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits
1270        if(m_pcEncCfg->getUseSBACRD())
1271        {
1272          rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
1273        }
1274      }
1275
[608]1276#if H_3D_VSO // M10
[56]1277      if ( m_pcRdCost->getUseVSO() )
1278        rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
1279      else
[5]1280#endif
[608]1281      rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
[2]1282
[56]1283      if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() && rpcTempCU->getSlice()->getPPS()->getUseDQP())
1284      {
[608]1285        Bool hasResidual = false;
[56]1286        for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++)
1287        {
[608]1288          if( ( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(uiBlkIdx+rpcTempCU->getZorderIdxInCU()) == rpcTempCU->getSlice()->getSliceSegmentCurStartCUAddr() ) && 
1289              ( rpcTempCU->getCbf( uiBlkIdx, TEXT_LUMA ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_U ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_V ) ) )
[56]1290          {
[608]1291            hasResidual = true;
[56]1292            break;
1293          }
1294        }
[2]1295
[56]1296        UInt uiTargetPartIdx;
[608]1297        if ( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(rpcTempCU->getZorderIdxInCU()) != pcSlice->getSliceSegmentCurStartCUAddr() )
[56]1298        {
[608]1299          uiTargetPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU();
[56]1300        }
1301        else
1302        {
1303          uiTargetPartIdx = 0;
1304        }
[608]1305        if ( hasResidual )
[56]1306        {
1307#if !RDO_WITHOUT_DQP_BITS
1308          m_pcEntropyCoder->resetBits();
1309          m_pcEntropyCoder->encodeQP( rpcTempCU, uiTargetPartIdx, false );
1310          rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits
1311          if(m_pcEncCfg->getUseSBACRD())
1312          {
1313            rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
1314          }
[608]1315#if H_3D_VSO // M11
1316          if ( m_pcRdCost->getUseLambdaScaleVSO())         
1317            rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );         
[56]1318          else
[5]1319#endif
[608]1320          rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
[56]1321#endif
[608]1322
1323          Bool foundNonZeroCbf = false;
1324          rpcTempCU->setQPSubCUs( rpcTempCU->getRefQP( uiTargetPartIdx ), rpcTempCU, 0, uiDepth, foundNonZeroCbf );
1325          assert( foundNonZeroCbf );
[56]1326        }
1327        else
1328        {
1329          rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uiDepth ); // set QP to default QP
1330        }
1331      }
[2]1332
[56]1333      if( m_bUseSBACRD )
1334      {
1335        m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
1336      }
[608]1337      Bool isEndOfSlice        = rpcBestCU->getSlice()->getSliceMode()==FIXED_NUMBER_OF_BYTES
1338                                 && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3);
1339      Bool isEndOfSliceSegment = rpcBestCU->getSlice()->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES
1340                                 && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceSegmentArgument()<<3);
1341      if(isEndOfSlice||isEndOfSliceSegment)
[56]1342      {
1343        rpcBestCU->getTotalCost()=rpcTempCU->getTotalCost()+1;
1344      }
1345      xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth);                                  // RD compare current larger prediction
1346    }                                                                                  // with sub partitioned prediction.
[116]1347    if (isAddLowestQP && (iQP == lowestQP))
1348    {
1349      iQP = iMinQP;
1350    }
[608]1351  }
[56]1352
[608]1353
1354#if H_3D_VSO // M12
[56]1355  if( m_pcRdCost->getUseRenModel() )
1356  {
[116]1357    UInt  uiWidth     = m_ppcRecoYuvBest[uiDepth]->getWidth   ( );
1358    UInt  uiHeight    = m_ppcRecoYuvBest[uiDepth]->getHeight  ( );
1359    Pel*  piSrc       = m_ppcRecoYuvBest[uiDepth]->getLumaAddr( 0 );
1360    UInt  uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride  ( );
1361    m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
[56]1362  }
1363#endif
1364
[2]1365  rpcBestCU->copyToPic(uiDepth);                                                     // Copy Best data to Picture for next partition prediction.
1366
[56]1367  xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU(), uiDepth, uiDepth, rpcBestCU, uiLPelX, uiTPelY );   // Copy Yuv data to picture Yuv
1368  if( bBoundary ||(bSliceEnd && bInsidePicture))
1369  {
[2]1370    return;
[56]1371  }
[2]1372
1373  // Assert if Best prediction mode is NONE
1374  // Selected mode's RD-cost must be not MAX_DOUBLE.
1375  assert( rpcBestCU->getPartitionSize ( 0 ) != SIZE_NONE  );
1376  assert( rpcBestCU->getPredictionMode( 0 ) != MODE_NONE  );
1377  assert( rpcBestCU->getTotalCost     (   ) != MAX_DOUBLE );
1378}
1379
[56]1380/** finish encoding a cu and handle end-of-slice conditions
1381 * \param pcCU
1382 * \param uiAbsPartIdx
1383 * \param uiDepth
1384 * \returns Void
1385 */
1386Void TEncCu::finishCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1387{
1388  TComPic* pcPic = pcCU->getPic();
1389  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
1390
1391  //Calculate end address
1392  UInt uiCUAddr = pcCU->getSCUAddr()+uiAbsPartIdx;
1393
[608]1394  UInt uiInternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) % pcPic->getNumPartInCU();
1395  UInt uiExternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) / pcPic->getNumPartInCU();
[56]1396  UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
1397  UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
1398  UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
1399  UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
1400  while(uiPosX>=uiWidth||uiPosY>=uiHeight)
1401  {
1402    uiInternalAddress--;
1403    uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
1404    uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
1405  }
1406  uiInternalAddress++;
1407  if(uiInternalAddress==pcCU->getPic()->getNumPartInCU())
1408  {
1409    uiInternalAddress = 0;
1410    uiExternalAddress = pcPic->getPicSym()->getCUOrderMap(pcPic->getPicSym()->getInverseCUOrderMap(uiExternalAddress)+1);
1411  }
1412  UInt uiRealEndAddress = pcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress);
1413
1414  // Encode slice finish
1415  Bool bTerminateSlice = false;
1416  if (uiCUAddr+(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1)) == uiRealEndAddress)
1417  {
1418    bTerminateSlice = true;
1419  }
[608]1420  UInt uiGranularityWidth = g_uiMaxCUWidth;
[56]1421  uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
1422  uiPosY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
1423  Bool granularityBoundary=((uiPosX+pcCU->getWidth(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosX+pcCU->getWidth(uiAbsPartIdx)==uiWidth))
1424    &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight));
1425 
[608]1426  if(granularityBoundary)
[56]1427  {
1428    // The 1-terminating bit is added to all streams, so don't add it here when it's 1.
1429    if (!bTerminateSlice)
1430      m_pcEntropyCoder->encodeTerminatingBit( bTerminateSlice ? 1 : 0 );
1431  }
1432 
1433  Int numberOfWrittenBits = 0;
1434  if (m_pcBitCounter)
1435  {
1436    numberOfWrittenBits = m_pcEntropyCoder->getNumberOfWrittenBits();
1437  }
1438 
1439  // Calculate slice end IF this CU puts us over slice bit size.
[608]1440  UInt iGranularitySize = pcCU->getPic()->getNumPartInCU();
1441  Int iGranularityEnd = ((pcCU->getSCUAddr()+uiAbsPartIdx)/iGranularitySize)*iGranularitySize;
1442  if(iGranularityEnd<=pcSlice->getSliceSegmentCurStartCUAddr()) 
[56]1443  {
1444    iGranularityEnd+=max(iGranularitySize,(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1)));
1445  }
1446  // Set slice end parameter
[608]1447  if(pcSlice->getSliceMode()==FIXED_NUMBER_OF_BYTES&&!pcSlice->getFinalized()&&pcSlice->getSliceBits()+numberOfWrittenBits>pcSlice->getSliceArgument()<<3) 
[56]1448  {
[608]1449    pcSlice->setSliceSegmentCurEndCUAddr(iGranularityEnd);
[56]1450    pcSlice->setSliceCurEndCUAddr(iGranularityEnd);
1451    return;
1452  }
[608]1453  // Set dependent slice end parameter
1454  if(pcSlice->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES&&!pcSlice->getFinalized()&&pcSlice->getSliceSegmentBits()+numberOfWrittenBits > pcSlice->getSliceSegmentArgument()<<3) 
[56]1455  {
[608]1456    pcSlice->setSliceSegmentCurEndCUAddr(iGranularityEnd);
1457    return;
[56]1458  }
1459  if(granularityBoundary)
1460  {
1461    pcSlice->setSliceBits( (UInt)(pcSlice->getSliceBits() + numberOfWrittenBits) );
[608]1462    pcSlice->setSliceSegmentBits(pcSlice->getSliceSegmentBits()+numberOfWrittenBits);
[56]1463    if (m_pcBitCounter)
1464    {
1465      m_pcEntropyCoder->resetBits();     
1466    }
1467  }
1468}
1469
1470/** Compute QP for each CU
1471 * \param pcCU Target CU
1472 * \param uiDepth CU depth
1473 * \returns quantization parameter
1474 */
1475Int TEncCu::xComputeQP( TComDataCU* pcCU, UInt uiDepth )
1476{
1477  Int iBaseQp = pcCU->getSlice()->getSliceQp();
1478  Int iQpOffset = 0;
1479  if ( m_pcEncCfg->getUseAdaptiveQP() )
1480  {
1481    TEncPic* pcEPic = dynamic_cast<TEncPic*>( pcCU->getPic() );
1482    UInt uiAQDepth = min( uiDepth, pcEPic->getMaxAQDepth()-1 );
1483    TEncPicQPAdaptationLayer* pcAQLayer = pcEPic->getAQLayer( uiAQDepth );
1484    UInt uiAQUPosX = pcCU->getCUPelX() / pcAQLayer->getAQPartWidth();
1485    UInt uiAQUPosY = pcCU->getCUPelY() / pcAQLayer->getAQPartHeight();
1486    UInt uiAQUStride = pcAQLayer->getAQPartStride();
1487    TEncQPAdaptationUnit* acAQU = pcAQLayer->getQPAdaptationUnit();
1488
1489    Double dMaxQScale = pow(2.0, m_pcEncCfg->getQPAdaptationRange()/6.0);
1490    Double dAvgAct = pcAQLayer->getAvgActivity();
1491    Double dCUAct = acAQU[uiAQUPosY * uiAQUStride + uiAQUPosX].getActivity();
1492    Double dNormAct = (dMaxQScale*dCUAct + dAvgAct) / (dCUAct + dMaxQScale*dAvgAct);
1493    Double dQpOffset = log(dNormAct) / log(2.0) * 6.0;
1494    iQpOffset = Int(floor( dQpOffset + 0.49999 ));
1495  }
1496  return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQp+iQpOffset );
1497}
1498
[2]1499/** encode a CU block recursively
1500 * \param pcCU
1501 * \param uiAbsPartIdx
[56]1502 * \param uiDepth
[2]1503 * \returns Void
1504 */
1505Void TEncCu::xEncodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1506{
1507  TComPic* pcPic = pcCU->getPic();
[56]1508 
[2]1509  Bool bBoundary = false;
1510  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
1511  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
1512  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
1513  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
[608]1514 
1515#if H_MV_ENC_DEC_TRAC
1516  DTRACE_CU_S("=========== coding_quadtree ===========\n")
1517  DTRACE_CU("x0", uiLPelX)
1518  DTRACE_CU("x1", uiTPelY)
1519  DTRACE_CU("log2CbSize", g_uiMaxCUWidth>>uiDepth)
1520  DTRACE_CU("cqtDepth"  , uiDepth)
1521#endif
[443]1522
[56]1523  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
1524  // If slice start is within this cu...
[608]1525  Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr() > pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && 
1526    pcSlice->getSliceSegmentCurStartCUAddr() < pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcPic->getNumPartInCU() >> (uiDepth<<1) );
[56]1527  // We need to split, so don't try these modes.
1528  if(!bSliceStart&&( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
[2]1529  {
[56]1530    m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
[2]1531  }
1532  else
1533  {
1534    bBoundary = true;
1535  }
[56]1536 
[2]1537  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < (g_uiMaxCUDepth-g_uiAddCUDepth) ) ) || bBoundary )
1538  {
1539    UInt uiQNumParts = ( pcPic->getNumPartInCU() >> (uiDepth<<1) )>>2;
[56]1540    if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
1541    {
1542      setdQPFlag(true);
1543    }
[2]1544    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts )
1545    {
1546      uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
1547      uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
[608]1548      Bool bInSlice = pcCU->getSCUAddr()+uiAbsPartIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurEndCUAddr();
[56]1549      if(bInSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
1550      {
[2]1551        xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 );
[56]1552      }
[2]1553    }
1554    return;
1555  }
[56]1556 
[608]1557#if H_MV_ENC_DEC_TRAC
1558  DTRACE_CU_S("=========== coding_unit ===========\n")
1559#endif
1560
[56]1561  if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
1562  {
1563    setdQPFlag(true);
1564  }
[608]1565  if (pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
1566  {
1567    m_pcEntropyCoder->encodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx );
1568  }
[5]1569  if( !pcCU->getSlice()->isIntra() )
[2]1570  {
1571    m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx );
1572  }
[56]1573 
[2]1574  if( pcCU->isSkipped( uiAbsPartIdx ) )
1575  {
[608]1576#if H_MV_ENC_DEC_TRAC
1577    DTRACE_PU_S("=========== prediction_unit ===========\n")
1578    DTRACE_PU("x0", uiLPelX)
1579    DTRACE_PU("x1", uiTPelY)
[115]1580#endif
[608]1581    m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx );
1582#if H_3D_IC
1583    m_pcEntropyCoder->encodeICFlag  ( pcCU, uiAbsPartIdx );
[296]1584#endif
[608]1585#if H_3D_ARP
1586    m_pcEntropyCoder->encodeARPW( pcCU , uiAbsPartIdx );
[443]1587#endif
[56]1588    finishCU(pcCU,uiAbsPartIdx,uiDepth);
[2]1589    return;
1590  }
[56]1591  m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx );
[608]1592 
[56]1593  m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth );
[608]1594 
[56]1595  if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N )
1596  {
1597    m_pcEntropyCoder->encodeIPCMInfo( pcCU, uiAbsPartIdx );
[2]1598
[56]1599    if(pcCU->getIPCMFlag(uiAbsPartIdx))
1600    {
1601      // Encode slice finish
1602      finishCU(pcCU,uiAbsPartIdx,uiDepth);
1603      return;
1604    }
1605  }
[2]1606
[56]1607  // prediction Info ( Intra : direction mode, Inter : Mv, reference idx )
1608  m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx );
[608]1609#if H_3D_IC
1610  m_pcEntropyCoder->encodeICFlag  ( pcCU, uiAbsPartIdx );
[189]1611#endif
[608]1612#if H_3D_ARP
1613  m_pcEntropyCoder->encodeARPW( pcCU , uiAbsPartIdx );
[296]1614#endif
[655]1615#if H_3D_INTER_SDC
[608]1616  m_pcEntropyCoder->encodeInterSDCFlag( pcCU, uiAbsPartIdx, false );
[5]1617#endif
[608]1618
[2]1619  // Encode Coefficients
[56]1620  Bool bCodeDQP = getdQPFlag();
1621  m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, pcCU->getWidth (uiAbsPartIdx), pcCU->getHeight(uiAbsPartIdx), bCodeDQP );
1622  setdQPFlag( bCodeDQP );
[2]1623
[56]1624  // --- write terminating bit ---
1625  finishCU(pcCU,uiAbsPartIdx,uiDepth);
[2]1626}
1627
[608]1628#if RATE_CONTROL_INTRA
1629Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg) 
1630{
1631  Int k, i, j, jj;
1632  Int diff[64], m1[8][8], m2[8][8], m3[8][8], iSumHad = 0;
1633
1634  for( k = 0; k < 64; k += 8 )
1635  {
1636    diff[k+0] = piOrg[0] ;
1637    diff[k+1] = piOrg[1] ;
1638    diff[k+2] = piOrg[2] ;
1639    diff[k+3] = piOrg[3] ;
1640    diff[k+4] = piOrg[4] ;
1641    diff[k+5] = piOrg[5] ;
1642    diff[k+6] = piOrg[6] ;
1643    diff[k+7] = piOrg[7] ;
1644 
1645    piOrg += iStrideOrg;
1646  }
1647 
1648  //horizontal
1649  for (j=0; j < 8; j++)
1650  {
1651    jj = j << 3;
1652    m2[j][0] = diff[jj  ] + diff[jj+4];
1653    m2[j][1] = diff[jj+1] + diff[jj+5];
1654    m2[j][2] = diff[jj+2] + diff[jj+6];
1655    m2[j][3] = diff[jj+3] + diff[jj+7];
1656    m2[j][4] = diff[jj  ] - diff[jj+4];
1657    m2[j][5] = diff[jj+1] - diff[jj+5];
1658    m2[j][6] = diff[jj+2] - diff[jj+6];
1659    m2[j][7] = diff[jj+3] - diff[jj+7];
1660   
1661    m1[j][0] = m2[j][0] + m2[j][2];
1662    m1[j][1] = m2[j][1] + m2[j][3];
1663    m1[j][2] = m2[j][0] - m2[j][2];
1664    m1[j][3] = m2[j][1] - m2[j][3];
1665    m1[j][4] = m2[j][4] + m2[j][6];
1666    m1[j][5] = m2[j][5] + m2[j][7];
1667    m1[j][6] = m2[j][4] - m2[j][6];
1668    m1[j][7] = m2[j][5] - m2[j][7];
1669   
1670    m2[j][0] = m1[j][0] + m1[j][1];
1671    m2[j][1] = m1[j][0] - m1[j][1];
1672    m2[j][2] = m1[j][2] + m1[j][3];
1673    m2[j][3] = m1[j][2] - m1[j][3];
1674    m2[j][4] = m1[j][4] + m1[j][5];
1675    m2[j][5] = m1[j][4] - m1[j][5];
1676    m2[j][6] = m1[j][6] + m1[j][7];
1677    m2[j][7] = m1[j][6] - m1[j][7];
1678  }
1679 
1680  //vertical
1681  for (i=0; i < 8; i++)
1682  {
1683    m3[0][i] = m2[0][i] + m2[4][i];
1684    m3[1][i] = m2[1][i] + m2[5][i];
1685    m3[2][i] = m2[2][i] + m2[6][i];
1686    m3[3][i] = m2[3][i] + m2[7][i];
1687    m3[4][i] = m2[0][i] - m2[4][i];
1688    m3[5][i] = m2[1][i] - m2[5][i];
1689    m3[6][i] = m2[2][i] - m2[6][i];
1690    m3[7][i] = m2[3][i] - m2[7][i];
1691   
1692    m1[0][i] = m3[0][i] + m3[2][i];
1693    m1[1][i] = m3[1][i] + m3[3][i];
1694    m1[2][i] = m3[0][i] - m3[2][i];
1695    m1[3][i] = m3[1][i] - m3[3][i];
1696    m1[4][i] = m3[4][i] + m3[6][i];
1697    m1[5][i] = m3[5][i] + m3[7][i];
1698    m1[6][i] = m3[4][i] - m3[6][i];
1699    m1[7][i] = m3[5][i] - m3[7][i];
1700   
1701    m2[0][i] = m1[0][i] + m1[1][i];
1702    m2[1][i] = m1[0][i] - m1[1][i];
1703    m2[2][i] = m1[2][i] + m1[3][i];
1704    m2[3][i] = m1[2][i] - m1[3][i];
1705    m2[4][i] = m1[4][i] + m1[5][i];
1706    m2[5][i] = m1[4][i] - m1[5][i];
1707    m2[6][i] = m1[6][i] + m1[7][i];
1708    m2[7][i] = m1[6][i] - m1[7][i];
1709  }
1710 
1711  for (i = 0; i < 8; i++)
1712  {
1713    for (j = 0; j < 8; j++)
1714    {
1715      iSumHad += abs(m2[i][j]);
1716    }
1717  }
1718  iSumHad -= abs(m2[0][0]);
1719  iSumHad =(iSumHad+2)>>2;
1720  return(iSumHad);
1721}
1722
1723Int  TEncCu::updateLCUDataISlice(TComDataCU* pcCU, Int LCUIdx, Int width, Int height)
1724{
1725  Int  xBl, yBl; 
1726  const Int iBlkSize = 8;
1727
1728  Pel* pOrgInit   = pcCU->getPic()->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
1729  Int  iStrideOrig = pcCU->getPic()->getPicYuvOrg()->getStride();
1730  Pel  *pOrg;
1731
1732  Int iSumHad = 0;
1733  for ( yBl=0; (yBl+iBlkSize)<=height; yBl+= iBlkSize)
1734  {
1735    for ( xBl=0; (xBl+iBlkSize)<=width; xBl+= iBlkSize)
1736    {
1737      pOrg = pOrgInit + iStrideOrig*yBl + xBl; 
1738      iSumHad += xCalcHADs8x8_ISlice(pOrg, iStrideOrig);
1739    }
1740  }
1741  return(iSumHad);
1742}
1743#endif
1744
[2]1745/** check RD costs for a CU block encoded with merge
1746 * \param rpcBestCU
1747 * \param rpcTempCU
1748 * \returns Void
1749 */
[608]1750Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool *earlyDetectionSkipMode )
[2]1751{
1752  assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE );
[608]1753#if H_3D_IV_MERGE
[56]1754  TComMvField  cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
1755  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
1756#else
[608]1757  TComMvField  cMvFieldNeighbours[2 * MRG_MAX_NUM_CANDS]; // double length for mv of both lists
[2]1758  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
[56]1759#endif
1760  Int numValidMergeCand = 0;
[2]1761
[608]1762  for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui )
[2]1763  {
1764    uhInterDirNeighbours[ui] = 0;
1765  }
1766  UChar uhDepth = rpcTempCU->getDepth( 0 );
[608]1767#if H_3D_IC
1768  Bool bICFlag = rpcTempCU->getICFlag( 0 );
1769#endif
1770#if H_3D_VSO // M1  //nececcary here?
[2]1771  if( m_pcRdCost->getUseRenModel() )
1772  {
[81]1773    UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth ( );
1774    UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight( );
1775    Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr( );
1776    UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
1777    m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
[2]1778  }
[5]1779#endif
[2]1780
[724]1781#if H_3D_ARP && LGE_SHARP_VSP_INHERIT_F0104
1782  DisInfo cOrigDisInfo = rpcTempCU->getDvInfo(0);
1783#else
[2]1784  rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
[608]1785  rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth );
[724]1786#endif
[608]1787
1788#if H_3D_VSP
[724]1789#if !(H_3D_ARP && LGE_SHARP_VSP_INHERIT_F0104)
[608]1790  Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
1791  memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
1792  InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
[724]1793#if ETRIKHU_MERGE_REUSE_F0093
1794  rpcTempCU->m_bAvailableFlagA1 = 0;
1795  rpcTempCU->m_bAvailableFlagB1 = 0;
1796  rpcTempCU->m_bAvailableFlagB0 = 0;
1797  rpcTempCU->m_bAvailableFlagA0 = 0;
1798  rpcTempCU->m_bAvailableFlagB2 = 0;
1799  rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
1800  rpcTempCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, vspFlag,inheritedVSPDisInfo, numValidMergeCand );
[443]1801#else
[724]1802  rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo, numValidMergeCand );
1803#endif
1804#endif
1805#else
1806#if ETRIKHU_MERGE_REUSE_F0093
1807  rpcTempCU->m_bAvailableFlagA1 = 0;
1808  rpcTempCU->m_bAvailableFlagB1 = 0;
1809  rpcTempCU->m_bAvailableFlagB0 = 0;
1810  rpcTempCU->m_bAvailableFlagA0 = 0;
1811  rpcTempCU->m_bAvailableFlagB2 = 0;
1812  rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
1813  rpcTempCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand );
1814#else
[608]1815  rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand );
[443]1816#endif
[724]1817#endif
[608]1818
1819#if H_3D_IV_MERGE
1820  Int mergeCandBuffer[MRG_MAX_NUM_CANDS_MEM];
[296]1821#else
[608]1822  Int mergeCandBuffer[MRG_MAX_NUM_CANDS];
[296]1823#endif
[724]1824#if H_3D_ARP && LGE_SHARP_VSP_INHERIT_F0104
1825for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui )
1826#else
[608]1827for( UInt ui = 0; ui < numValidMergeCand; ++ui )
[724]1828#endif
[608]1829  {
1830    mergeCandBuffer[ui] = 0;
1831  }
[2]1832
[56]1833  Bool bestIsSkip = false;
[608]1834
1835  UInt iteration;
1836  if ( rpcTempCU->isLosslessCoded(0))
[443]1837  {
[608]1838    iteration = 1;
1839  }
1840  else 
[2]1841  {
[608]1842    iteration = 2;
1843  }
1844
1845#if H_3D_ARP
1846  Int nARPWMax = rpcTempCU->getSlice()->getARPStepNum() - 1;
1847  if( nARPWMax < 0 || !rpcTempCU->getDvInfo(0).bDV )
1848  {
1849    nARPWMax = 0;
1850  }
1851  for( Int nARPW=nARPWMax; nARPW >= 0 ; nARPW-- )
1852  {
[724]1853#if FIX_MISSING_MACRO_R690
1854    memset( mergeCandBuffer, 0, MRG_MAX_NUM_CANDS_MEM*sizeof(Int) );
1855#else
[608]1856    memset( mergeCandBuffer, 0, MRG_MAX_NUM_CANDS*sizeof(Int) );
1857#endif
[724]1858#if LGE_SHARP_VSP_INHERIT_F0104
1859    rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
1860    rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth );
1861    rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth );
1862#if H_3D_IC
1863    rpcTempCU->setICFlagSubParts( bICFlag, 0, 0, uhDepth );
1864#endif
1865    rpcTempCU->getDvInfo(0) = cOrigDisInfo;
1866    rpcTempCU->setDvInfoSubParts(cOrigDisInfo, 0, 0, uhDepth );
1867    Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
1868    memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
1869    InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
1870#if MTK_SPIVMP_F0110
1871    Bool bSPIVMPFlag[MRG_MAX_NUM_CANDS_MEM];
1872    memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM);
1873    TComMvField*  pcMvFieldSP;
1874    UChar* puhInterDirSP;
1875    pcMvFieldSP = new TComMvField[rpcTempCU->getPic()->getPicSym()->getNumPartition()*2]; 
1876    puhInterDirSP = new UChar[rpcTempCU->getPic()->getPicSym()->getNumPartition()]; 
1877#endif
1878#if ETRIKHU_MERGE_REUSE_F0093
1879    rpcTempCU->initAvailableFlags();
1880    rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
1881    rpcTempCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, vspFlag,inheritedVSPDisInfo
1882#if MTK_SPIVMP_F0110
1883      , bSPIVMPFlag, pcMvFieldSP, puhInterDirSP
1884#endif
1885      , numValidMergeCand
1886      );
1887#else
1888    rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo, numValidMergeCand );
1889#endif
1890#endif
1891#endif
[608]1892  for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual )
1893  {
1894    for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
1895    {     
1896#if H_3D_IC
1897        if( rpcTempCU->getSlice()->getApplyIC() && rpcTempCU->getSlice()->getIcSkipParseFlag() )
[443]1898        {
[608]1899          if( bICFlag && uiMergeCand == 0 ) 
1900          {
1901            continue;
1902          }
[443]1903        }
1904#endif
[608]1905        if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1))
1906        {
[56]1907        if( !(bestIsSkip && uiNoResidual == 0) )
1908        {
1909          // set MC parameters
[608]1910          rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to LCU level
1911          rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(),     0, uhDepth );
[56]1912          rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
[608]1913#if H_3D_IC
1914          rpcTempCU->setICFlagSubParts( bICFlag, 0, 0, uhDepth );
[443]1915#endif
[608]1916#if H_3D_ARP
1917          rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth );
1918#endif
[56]1919          rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level
1920          rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level
[608]1921#if H_3D_VSP
1922          rpcTempCU->setVSPFlagSubParts( vspFlag[uiMergeCand], 0, 0, uhDepth );
1923          rpcTempCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeCand].m_acDvInfo, 0, 0, uhDepth );
[443]1924#endif
[724]1925#if MTK_SPIVMP_F0110
1926          rpcTempCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMergeCand], 0, 0, uhDepth);
1927          if (bSPIVMPFlag[uiMergeCand])
1928          {
1929            UInt uiSPAddr;
1930            Int iWidth = rpcTempCU->getWidth(0);
1931            Int iHeight = rpcTempCU->getHeight(0);
[2]1932
[724]1933            Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
1934
1935            rpcTempCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
1936
1937            for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++)
1938            {
1939              rpcTempCU->getSPAbsPartIdx(0, iSPWidth, iSPHeight, iPartitionIdx, iNumSPInOneLine, uiSPAddr);
1940              rpcTempCU->setInterDirSP(puhInterDirSP[iPartitionIdx], uiSPAddr, iSPWidth, iSPHeight);
1941              rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setMvFieldSP(rpcTempCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx], iSPWidth, iSPHeight);
1942              rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(rpcTempCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight);
1943            }
1944          }
1945          else
1946          {
1947#endif
1948            rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level
1949            rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
1950            rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
1951#if MTK_SPIVMP_F0110
1952          }
1953#endif
1954#if H_3D_ARP && !QC_MTK_INTERVIEW_ARP_F0123_F0108
[608]1955          if( nARPW )
[443]1956          {
[608]1957            Bool bSignalflag[2] = { true, true };
1958            for( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx ++ )
[443]1959            {
1960              Int iRefIdx = cMvFieldNeighbours[uiRefListIdx + 2*uiMergeCand].getRefIdx();
1961              RefPicList eRefList = uiRefListIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
[608]1962              if( iRefIdx < 0 || rpcTempCU->getSlice()->getPOC() == rpcTempCU->getSlice()->getRefPOC(eRefList, iRefIdx) )
1963              {
[443]1964                bSignalflag[uiRefListIdx] = false;
[608]1965              }
[443]1966            }
[608]1967            if( !bSignalflag[0] && !bSignalflag[1] )
[443]1968            {
[724]1969#if LGE_SHARP_VSP_INHERIT_F0104
1970              continue;
1971#else
[443]1972              rpcTempCU->setARPWSubParts( 0 , 0 , uhDepth );
[724]1973#endif
[443]1974            }
1975          }
1976#endif
[608]1977       // do MC
1978       m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
1979       // estimate residual and encode everything
1980#if H_3D_VSO //M2
1981       if( m_pcRdCost->getUseRenModel() )
1982       { //Reset
1983         UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth    ();
1984         UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight   ();
1985         Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr ();
1986         UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride   ();
1987         m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
1988       }
[2]1989#endif
[608]1990       m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU,
1991         m_ppcOrigYuv    [uhDepth],
1992         m_ppcPredYuvTemp[uhDepth],
1993         m_ppcResiYuvTemp[uhDepth],
1994         m_ppcResiYuvBest[uhDepth],
1995         m_ppcRecoYuvTemp[uhDepth],
1996         (uiNoResidual? true:false));
1997
1998
1999          if ( uiNoResidual == 0 && rpcTempCU->getQtRootCbf(0) == 0 )
2000         {
2001            // If no residual when allowing for one, then set mark to not try case where residual is forced to 0
2002           mergeCandBuffer[uiMergeCand] = 1;
2003         }
2004
2005          rpcTempCU->setSkipFlagSubParts( rpcTempCU->getQtRootCbf(0) == 0, 0, uhDepth );
[655]2006#if H_3D_INTER_SDC
[608]2007          TComDataCU *rpcTempCUPre = rpcTempCU;
[296]2008#endif
[608]2009          Int orgQP = rpcTempCU->getQP( 0 );
2010          xCheckDQP( rpcTempCU );
2011          xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
[655]2012#if H_3D_INTER_SDC
[608]2013          if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) && rpcTempCU->getSlice()->getIsDepth() && !uiNoResidual )
2014          {
2015            if( rpcTempCU != rpcTempCUPre )
[296]2016            {
[608]2017              rpcTempCU->initEstData( uhDepth, orgQP );
2018              rpcTempCU->copyPartFrom( rpcBestCU, 0, uhDepth );
[296]2019            }
[608]2020            rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth );
2021            rpcTempCU->setTrIdxSubParts( 0, 0, uhDepth );
2022            rpcTempCU->setCbfSubParts( 1, 1, 1, 0, uhDepth );
2023#if H_3D_VSO //M2
2024            if( m_pcRdCost->getUseRenModel() )
2025            { //Reset
2026              UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth    ();
2027              UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight   ();
2028              Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr ();
2029              UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride   ();
2030              m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
2031            }
[296]2032#endif
[608]2033            m_pcPredSearch->encodeResAndCalcRdInterSDCCU( rpcTempCU, 
2034              m_ppcOrigYuv[uhDepth], 
2035              ( rpcTempCU != rpcTempCUPre ) ? m_ppcPredYuvBest[uhDepth] : m_ppcPredYuvTemp[uhDepth], 
2036              m_ppcResiYuvTemp[uhDepth], 
2037              m_ppcRecoYuvTemp[uhDepth], 
2038              uhDepth );
[2]2039
[608]2040            xCheckDQP( rpcTempCU );
2041            xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth );
[56]2042          }
[296]2043#endif
[608]2044          rpcTempCU->initEstData( uhDepth, orgQP );
2045
2046      if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip )
2047      {
[655]2048#if H_3D_INTER_SDC
[608]2049        if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) )
2050        {
2051          bestIsSkip = !rpcBestCU->getSDCFlag( 0 ) && ( rpcBestCU->getQtRootCbf(0) == 0 );
2052        }
2053        else
2054        {
[296]2055#endif
[608]2056        bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0;
[655]2057#if H_3D_INTER_SDC
[608]2058        }
[5]2059#endif
[608]2060      }
2061    }
2062   }
2063  }
[2]2064
[608]2065  if(uiNoResidual == 0 && m_pcEncCfg->getUseEarlySkipDetection())
2066  {
2067    if(rpcBestCU->getQtRootCbf( 0 ) == 0)
2068    {
2069      if( rpcBestCU->getMergeFlag( 0 ))
2070      {
2071        *earlyDetectionSkipMode = true;
2072      }
2073      else
2074      {
2075        Int absoulte_MV=0;
2076        for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
2077        {
2078          if ( rpcBestCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
[56]2079          {
[608]2080            TComCUMvField* pcCUMvField = rpcBestCU->getCUMvField(RefPicList( uiRefListIdx ));
2081            Int iHor = pcCUMvField->getMvd( 0 ).getAbsHor();
2082            Int iVer = pcCUMvField->getMvd( 0 ).getAbsVer();
2083            absoulte_MV+=iHor+iVer;
[56]2084          }
[608]2085        }
[2]2086
[608]2087        if(absoulte_MV == 0)
2088        {
2089          *earlyDetectionSkipMode = true;
[56]2090        }
[2]2091      }
2092    }
2093  }
[608]2094 }
[724]2095#if MTK_SPIVMP_F0110
[728]2096#if MTK_F0110_FIX
2097 delete[] pcMvFieldSP;
2098 delete[] puhInterDirSP;
2099#else
[724]2100 delete pcMvFieldSP;
2101 delete puhInterDirSP;
2102#endif
[728]2103#endif
[608]2104#if H_3D_ARP
2105 }
[443]2106#endif
[2]2107}
2108
[608]2109
[56]2110#if AMP_MRG
[655]2111#if  H_3D_FAST_TEXTURE_ENCODING
[608]2112Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bFMD, Bool bUseMRG)
[56]2113#else
2114Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bUseMRG)
2115#endif
2116#else
[2]2117Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize )
2118#endif
[608]2119{
[655]2120#if  H_3D_FAST_TEXTURE_ENCODING
[608]2121  if(!(bFMD && (ePartSize == SIZE_2Nx2N)))  //have  motion estimation or merge check
2122  {
[56]2123#endif
[2]2124  UChar uhDepth = rpcTempCU->getDepth( 0 );
[608]2125#if H_3D_ARP
2126  Int iLayerId    = rpcTempCU->getSlice()->getLayerId();
[443]2127  Bool bFirstTime = true;
[608]2128  Int nARPWMax    = rpcTempCU->getSlice()->getARPStepNum() - 1;
2129
2130  if( nARPWMax < 0 || ePartSize != SIZE_2Nx2N || !rpcTempCU->getDvInfo(0).bDV  )
2131  {
[443]2132    nARPWMax = 0;
[608]2133  }
2134
2135  for( Int nARPW = 0; nARPW <= nARPWMax; nARPW++ )
[443]2136  {
[608]2137    if( bFirstTime == false && rpcTempCU->getSlice()->getVPS()->getUseAdvRP( iLayerId ) )
2138    {
[443]2139      rpcTempCU->initEstData( rpcTempCU->getDepth(0), rpcTempCU->getQP(0) );
[608]2140    }
2141#endif
2142#if H_3D_VSO // M3
[2]2143  if( m_pcRdCost->getUseRenModel() )
2144  {
[81]2145    UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth ( );
2146    UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight( );
2147    Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr( );
2148    UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
2149    m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
[2]2150  }
[608]2151#endif
[2]2152
2153  rpcTempCU->setDepthSubParts( uhDepth, 0 );
[56]2154 
[608]2155  rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth );
2156
2157  rpcTempCU->setPartSizeSubParts  ( ePartSize,  0, uhDepth );
2158  rpcTempCU->setPredModeSubParts  ( MODE_INTER, 0, uhDepth );
2159  rpcTempCU->setCUTransquantBypassSubParts  ( m_pcEncCfg->getCUTransquantBypassFlagValue(),      0, uhDepth );
[56]2160 
[608]2161#if H_3D_ARP
2162  rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth );
[5]2163#endif
[56]2164
[608]2165#if H_3D_ARP
2166  if( bFirstTime == false && nARPWMax )
[443]2167  {
[608]2168    rpcTempCU->copyPartFrom( m_ppcWeightedTempCU[uhDepth] , 0 , uhDepth );
2169    rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth );
2170
[443]2171    m_pcPredSearch->motionCompensation( rpcTempCU , m_ppcPredYuvTemp[uhDepth] );
[608]2172
[724]2173#if !QC_MTK_INTERVIEW_ARP_F0123_F0108
[443]2174    if(rpcTempCU->getPartitionSize(0)==SIZE_2Nx2N)
2175    {
[608]2176      Bool bSignalflag[2] = { true, true };
[443]2177      for(UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx ++ )
2178      {
2179        RefPicList eRefList = uiRefListIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
2180        Int iRefIdx = rpcTempCU->getCUMvField(eRefList)->getRefIdx(0);
[608]2181        if( iRefIdx < 0 || rpcTempCU->getSlice()->getPOC() == rpcTempCU->getSlice()->getRefPOC(eRefList, iRefIdx) )
2182        {
[443]2183          bSignalflag[uiRefListIdx] = false;
[608]2184        }
[443]2185      }
[608]2186      if( !bSignalflag[0] && !bSignalflag[1] )
2187      {
[443]2188        rpcTempCU->setARPWSubParts( 0 , 0 , uhDepth );
[608]2189      }
[443]2190    }
[724]2191#endif
[443]2192  }
2193  else
2194  {
2195    bFirstTime = false;
2196#endif
[56]2197#if AMP_MRG
2198  rpcTempCU->setMergeAMP (true);
[655]2199#if  H_3D_FAST_TEXTURE_ENCODING
[608]2200  m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bFMD, false, bUseMRG );
[56]2201#else
2202  m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], false, bUseMRG );
2203#endif
2204#else 
[2]2205  m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] );
2206#endif
[608]2207#if H_3D_ARP
2208   if( nARPWMax )
[443]2209   {
2210     m_ppcWeightedTempCU[uhDepth]->copyPartFrom( rpcTempCU , 0 , uhDepth );
[608]2211
[724]2212#if !QC_MTK_INTERVIEW_ARP_F0123_F0108
[608]2213     Bool bSignalflag[2] = { true, true };
2214     for(UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx ++ )
[443]2215     {
[608]2216       RefPicList eRefList = uiRefListIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
2217       Int iRefIdx = rpcTempCU->getCUMvField(eRefList)->getRefIdx(0);
2218       if( iRefIdx < 0 || rpcTempCU->getSlice()->getPOC() == rpcTempCU->getSlice()->getRefPOC(eRefList, iRefIdx) )
[443]2219       {
[608]2220         bSignalflag[uiRefListIdx] = false;
[443]2221       }
2222     }
[608]2223     if( !bSignalflag[0] && !bSignalflag[1])
2224     {
2225       rpcTempCU->setARPWSubParts( 0 , 0 , uhDepth );
2226     }
[724]2227#endif
[443]2228   }
2229  }
2230#endif
[56]2231
2232#if AMP_MRG
2233  if ( !rpcTempCU->getMergeAMP() )
[2]2234  {
[608]2235#if H_3D_ARP
2236    if( nARPWMax )
2237    {
[443]2238      continue;
[608]2239    }
[443]2240    else
2241#endif
[2]2242    return;
2243  }
2244#endif
[56]2245
[655]2246#if RATE_CONTROL_LAMBDA_DOMAIN  && (!M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227)
[608]2247  if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
2248  {
2249    UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
2250      m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
2251      rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
2252    m_temporalSAD = (Int)SAD;
2253  }
[56]2254#endif
[655]2255#if !RATE_CONTROL_LAMBDA_DOMAIN  && KWU_RC_MADPRED_E0227
2256  if ( m_pcEncCfg->getUseRateCtrl() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
2257  {
2258    UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
2259      m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
2260      rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
2261    m_temporalSAD = (Int)SAD;
2262  }
2263#endif
[608]2264
2265  m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false );
2266
2267
2268#if H_3D_VSO // M4
[2]2269  if( m_pcRdCost->getUseLambdaScaleVSO() )
2270    rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
2271  else
[5]2272#endif
[608]2273  rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
[655]2274#if H_3D_INTER_SDC
[608]2275  TComDataCU *rpcTempCUPre = rpcTempCU;
2276#endif
2277  xCheckDQP( rpcTempCU );
2278  xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
[655]2279#if H_3D_INTER_SDC
[608]2280  if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) && rpcTempCU->getSlice()->getIsDepth() )
[2]2281  {
[608]2282    if( rpcTempCU != rpcTempCUPre )
2283    {
2284      Int orgQP = rpcBestCU->getQP( 0 );
2285      rpcTempCU->initEstData( uhDepth, orgQP );
2286      rpcTempCU->copyPartFrom( rpcBestCU, 0, uhDepth );
2287    }
2288    rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth );
2289    rpcTempCU->setTrIdxSubParts( 0, 0, uhDepth );
2290    rpcTempCU->setCbfSubParts( 1, 1, 1, 0, uhDepth );
2291#if H_3D_VSO // M3
2292    if( m_pcRdCost->getUseRenModel() )
2293    {
2294      UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth ( );
2295      UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight( );
2296      Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr( );
2297      UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
2298      m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
2299    }
2300#endif
[2]2301
[608]2302    m_pcPredSearch->encodeResAndCalcRdInterSDCCU( rpcTempCU, 
2303      m_ppcOrigYuv[uhDepth],
2304      ( rpcTempCU != rpcTempCUPre ) ? m_ppcPredYuvBest[uhDepth] : m_ppcPredYuvTemp[uhDepth],
2305      m_ppcResiYuvTemp[uhDepth],
2306      m_ppcRecoYuvTemp[uhDepth],
2307      uhDepth );
2308
[56]2309  xCheckDQP( rpcTempCU );
2310  xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
[443]2311  }
2312#endif
[608]2313#if H_3D_ARP
2314  }
2315#endif
[655]2316#if  H_3D_FAST_TEXTURE_ENCODING
[608]2317  }
2318#endif
[2]2319}
2320
2321Void TEncCu::xCheckRDCostIntra( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize )
2322{
2323  UInt uiDepth = rpcTempCU->getDepth( 0 );
[56]2324 
[608]2325#if H_3D_VSO // M5
[2]2326  if( m_pcRdCost->getUseRenModel() )
2327  {
[81]2328    UInt  uiWidth     = m_ppcOrigYuv[uiDepth]->getWidth   ();
2329    UInt  uiHeight    = m_ppcOrigYuv[uiDepth]->getHeight  ();
2330    Pel*  piSrc       = m_ppcOrigYuv[uiDepth]->getLumaAddr();
2331    UInt  uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride  ();
2332    m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
[2]2333  }
[5]2334#endif
[2]2335
[608]2336  rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth );
2337
[2]2338  rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth );
2339  rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth );
[608]2340  rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth );
[56]2341 
[2]2342  Bool bSeparateLumaChroma = true; // choose estimation mode
[608]2343  UInt uiPreCalcDistC      = 0;
[2]2344  if( !bSeparateLumaChroma )
2345  {
2346    m_pcPredSearch->preestChromaPredMode( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth] );
2347  }
2348  m_pcPredSearch  ->estIntraPredQT      ( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, bSeparateLumaChroma );
2349
2350  m_ppcRecoYuvTemp[uiDepth]->copyToPicLuma(rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU() );
[56]2351 
[608]2352#if H_3D_DIM_SDC
[189]2353  if( !rpcTempCU->getSDCFlag( 0 ) )
2354#endif
[2]2355  m_pcPredSearch  ->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC );
[56]2356 
[2]2357  m_pcEntropyCoder->resetBits();
[608]2358  if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
2359  {
2360    m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0,          true );
2361  }
[2]2362  m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0,          true );
2363  m_pcEntropyCoder->encodePredMode( rpcTempCU, 0,          true );
2364  m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true );
2365  m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0,          true );
[56]2366  m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0, true );
[2]2367
2368  // Encode Coefficients
[56]2369  Bool bCodeDQP = getdQPFlag();
2370  m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, rpcTempCU->getWidth (0), rpcTempCU->getHeight(0), bCodeDQP );
2371  setdQPFlag( bCodeDQP );
2372 
[2]2373  if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
[56]2374 
[2]2375  rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits();
[56]2376  if(m_pcEncCfg->getUseSBACRD())
2377  {
2378    rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
2379  }
[608]2380
2381#if H_3D_VSO // M6
2382  if( m_pcRdCost->getUseLambdaScaleVSO()) 
2383    rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); 
[2]2384  else
[5]2385#endif
[56]2386  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
2387 
[655]2388#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
2389  UChar uhDepth = rpcTempCU->getDepth( 0 );
2390  if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
2391  {
2392    UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
2393      m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
2394      rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
2395    m_spatialSAD = (Int)SAD;
2396  }
2397#endif
2398#if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
2399  UChar uhDepth = rpcTempCU->getDepth( 0 );
2400  if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
2401  {
2402    UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
2403      m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
2404      rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
2405    m_spatialSAD = (Int)SAD;
2406  }
2407#endif
2408#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
2409  UChar uhDepth = rpcTempCU->getDepth( 0 );
2410  if ( m_pcEncCfg->getUseRateCtrl() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
2411  {
2412    UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
2413      m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
2414      rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
2415    m_spatialSAD = (Int)SAD;
2416  }
2417#endif
[56]2418  xCheckDQP( rpcTempCU );
2419  xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth);
2420}
[2]2421
[56]2422/** Check R-D costs for a CU with PCM mode.
2423 * \param rpcBestCU pointer to best mode CU data structure
2424 * \param rpcTempCU pointer to testing mode CU data structure
2425 * \returns Void
2426 *
2427 * \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.
2428 */
2429Void TEncCu::xCheckIntraPCM( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU )
2430{
2431  UInt uiDepth = rpcTempCU->getDepth( 0 );
2432
[608]2433  rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth );
2434
[56]2435  rpcTempCU->setIPCMFlag(0, true);
2436  rpcTempCU->setIPCMFlagSubParts (true, 0, rpcTempCU->getDepth(0));
2437  rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );
2438  rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth );
[608]2439  rpcTempCU->setTrIdxSubParts ( 0, 0, uiDepth );
2440  rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth );
[56]2441
2442  m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]);
2443
2444  if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
2445
2446  m_pcEntropyCoder->resetBits();
[608]2447  if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
2448  {
2449    m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0,          true );
2450  }
[56]2451  m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0,          true );
2452  m_pcEntropyCoder->encodePredMode ( rpcTempCU, 0,          true );
2453  m_pcEntropyCoder->encodePartSize ( rpcTempCU, 0, uiDepth, true );
2454  m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true );
2455
2456  if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
2457
2458  rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits();
2459  if(m_pcEncCfg->getUseSBACRD())
2460  {
2461    rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
2462  }
[608]2463#if H_3D_VSO // M44
[56]2464  if ( m_pcRdCost->getUseVSO() )
2465    rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
2466  else
2467#endif
2468  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
2469
2470  xCheckDQP( rpcTempCU );
[2]2471  xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth );
2472}
2473
[56]2474/** check whether current try is the best with identifying the depth of current try
2475 * \param rpcBestCU
2476 * \param rpcTempCU
2477 * \returns Void
2478 */
2479Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth )
[2]2480{
[56]2481  if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() )
2482  {
2483    TComYuv* pcYuv;
2484    // Change Information data
2485    TComDataCU* pcCU = rpcBestCU;
2486    rpcBestCU = rpcTempCU;
2487    rpcTempCU = pcCU;
[2]2488
[56]2489    // Change Prediction data
2490    pcYuv = m_ppcPredYuvBest[uiDepth];
2491    m_ppcPredYuvBest[uiDepth] = m_ppcPredYuvTemp[uiDepth];
2492    m_ppcPredYuvTemp[uiDepth] = pcYuv;
[2]2493
[56]2494    // Change Reconstruction data
2495    pcYuv = m_ppcRecoYuvBest[uiDepth];
2496    m_ppcRecoYuvBest[uiDepth] = m_ppcRecoYuvTemp[uiDepth];
2497    m_ppcRecoYuvTemp[uiDepth] = pcYuv;
[2]2498
[56]2499    pcYuv = NULL;
2500    pcCU  = NULL;
[2]2501
[56]2502    if( m_bUseSBACRD )  // store temp best CI for next CU coding
2503      m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]);
2504  }
2505}
2506
2507Void TEncCu::xCheckDQP( TComDataCU* pcCU )
2508{
2509  UInt uiDepth = pcCU->getDepth( 0 );
2510
2511  if( pcCU->getSlice()->getPPS()->getUseDQP() && (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() )
[2]2512  {
[56]2513    if ( pcCU->getCbf( 0, TEXT_LUMA, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_U, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_V, 0 ) )
2514    {
2515#if !RDO_WITHOUT_DQP_BITS
2516      m_pcEntropyCoder->resetBits();
2517      m_pcEntropyCoder->encodeQP( pcCU, 0, false );
2518      pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits
2519      if(m_pcEncCfg->getUseSBACRD())
2520      {
2521        pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
2522      }
[608]2523#if H_3D_VSO // M45
2524      if ( m_pcRdCost->getUseVSO() )     
2525        pcCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( pcCU->getTotalBits(), pcCU->getTotalDistortion() );     
[56]2526      else
2527#endif
2528      pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() );
2529#endif
[2]2530    }
[56]2531    else
[2]2532    {
[56]2533      pcCU->setQPSubParts( pcCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP
[2]2534    }
[56]2535  }
2536}
2537
[2]2538Void TEncCu::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst)
2539{
2540  pDst->iN = pSrc->iN;
2541  for (Int i = 0; i < pSrc->iN; i++)
2542  {
2543    pDst->m_acMvCand[i] = pSrc->m_acMvCand[i];
2544  }
2545}
[56]2546Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth, TComDataCU* pcCU, UInt uiLPelX, UInt uiTPelY )
2547{
2548  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
2549  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
2550  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
[608]2551  Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && 
2552    pcSlice->getSliceSegmentCurStartCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) );
2553  Bool bSliceEnd   = pcSlice->getSliceSegmentCurEndCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && 
2554    pcSlice->getSliceSegmentCurEndCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) );
[56]2555  if(!bSliceEnd && !bSliceStart && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
2556  {
2557    UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx];
2558    UInt uiSrcBlkWidth = rpcPic->getNumPartInWidth() >> (uiSrcDepth);
2559    UInt uiBlkWidth    = rpcPic->getNumPartInWidth() >> (uiDepth);
2560    UInt uiPartIdxX = ( ( uiAbsPartIdxInRaster % rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth;
2561    UInt uiPartIdxY = ( ( uiAbsPartIdxInRaster / rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth;
2562    UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX;
2563    m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx);
2564  }
2565  else
2566  {
2567    UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) )>>2;
[2]2568
[56]2569    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts )
2570    {
2571      UInt uiSubCULPelX   = uiLPelX + ( g_uiMaxCUWidth >>(uiDepth+1) )*( uiPartUnitIdx &  1 );
2572      UInt uiSubCUTPelY   = uiTPelY + ( g_uiMaxCUHeight>>(uiDepth+1) )*( uiPartUnitIdx >> 1 );
2573
[608]2574      Bool bInSlice = rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+uiQNumParts > pcSlice->getSliceSegmentCurStartCUAddr() && 
2575        rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx < pcSlice->getSliceSegmentCurEndCUAddr();
[56]2576      if(bInSlice&&( uiSubCULPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiSubCUTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
2577      {
2578        xCopyYuv2Pic( rpcPic, uiCUAddr, uiAbsPartIdx, uiDepth+1, uiSrcDepth, pcCU, uiSubCULPelX, uiSubCUTPelY );   // Copy Yuv data to picture Yuv
2579      }
2580    }
2581  }
[2]2582}
2583
2584Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth )
2585{
2586  UInt uiCurrDepth = uiNextDepth - 1;
2587  m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx );
2588}
2589
[56]2590/** Function for filling the PCM buffer of a CU using its original sample array
2591 * \param pcCU pointer to current CU
2592 * \param pcOrgYuv pointer to original sample array
2593 * \returns Void
2594 */
2595Void TEncCu::xFillPCMBuffer     ( TComDataCU*& pCU, TComYuv* pOrgYuv )
2596{
2597
2598  UInt   width        = pCU->getWidth(0);
2599  UInt   height       = pCU->getHeight(0);
2600
2601  Pel*   pSrcY = pOrgYuv->getLumaAddr(0, width); 
2602  Pel*   pDstY = pCU->getPCMSampleY();
2603  UInt   srcStride = pOrgYuv->getStride();
2604
2605  for(Int y = 0; y < height; y++ )
2606  {
2607    for(Int x = 0; x < width; x++ )
2608    {
2609      pDstY[x] = pSrcY[x];
2610    }
2611    pDstY += width;
2612    pSrcY += srcStride;
2613  }
2614
2615  Pel* pSrcCb       = pOrgYuv->getCbAddr();
2616  Pel* pSrcCr       = pOrgYuv->getCrAddr();;
2617
2618  Pel* pDstCb       = pCU->getPCMSampleCb();
2619  Pel* pDstCr       = pCU->getPCMSampleCr();;
2620
2621  UInt srcStrideC = pOrgYuv->getCStride();
2622  UInt heightC   = height >> 1;
2623  UInt widthC    = width  >> 1;
2624
2625  for(Int y = 0; y < heightC; y++ )
2626  {
2627    for(Int x = 0; x < widthC; x++ )
2628    {
2629      pDstCb[x] = pSrcCb[x];
2630      pDstCr[x] = pSrcCr[x];
2631    }
2632    pDstCb += widthC;
2633    pDstCr += widthC;
2634    pSrcCb += srcStrideC;
2635    pSrcCr += srcStrideC;
2636  }
2637}
2638
2639#if ADAPTIVE_QP_SELECTION
2640/** Collect ARL statistics from one block
2641  */
2642Int TEncCu::xTuCollectARLStats(TCoeff* rpcCoeff, Int* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples )
2643{
2644  for( Int n = 0; n < NumCoeffInCU; n++ )
2645  {
2646    Int u = abs( rpcCoeff[ n ] );
2647    Int absc = rpcArlCoeff[ n ];
2648
2649    if( u != 0 )
2650    {
2651      if( u < LEVEL_RANGE )
2652      {
2653        cSum[ u ] += ( Double )absc;
2654        numSamples[ u ]++;
2655      }
2656      else 
2657      {
2658        cSum[ LEVEL_RANGE ] += ( Double )absc - ( Double )( u << ARL_C_PRECISION );
2659        numSamples[ LEVEL_RANGE ]++;
2660      }
2661    }
2662  }
2663
2664  return 0;
2665}
2666
2667/** Collect ARL statistics from one LCU
2668 * \param pcCU
2669 */
2670Void TEncCu::xLcuCollectARLStats(TComDataCU* rpcCU )
2671{
2672  Double cSum[ LEVEL_RANGE + 1 ];     //: the sum of DCT coefficients corresponding to datatype and quantization output
2673  UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to datatype and quantization output
2674
2675  TCoeff* pCoeffY = rpcCU->getCoeffY();
2676  Int* pArlCoeffY = rpcCU->getArlCoeffY();
2677
2678  UInt uiMinCUWidth = g_uiMaxCUWidth >> g_uiMaxCUDepth;
2679  UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth;
2680
2681  memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) );
2682  memset( numSamples, 0, sizeof( UInt )*(LEVEL_RANGE+1) );
2683
2684  // Collect stats to cSum[][] and numSamples[][]
2685  for(Int i = 0; i < rpcCU->getTotalNumPart(); i ++ )
2686  {
2687    UInt uiTrIdx = rpcCU->getTransformIdx(i);
2688
2689    if(rpcCU->getPredictionMode(i) == MODE_INTER)
2690    if( rpcCU->getCbf( i, TEXT_LUMA, uiTrIdx ) )
2691    {
2692      xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples);
2693    }//Note that only InterY is processed. QP rounding is based on InterY data only.
2694   
2695    pCoeffY  += uiMinNumCoeffInCU;
2696    pArlCoeffY  += uiMinNumCoeffInCU;
2697  }
2698
2699  for(Int u=1; u<LEVEL_RANGE;u++)
2700  {
2701    m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ;
2702    m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ;
2703  }
2704  m_pcTrQuant->getSliceSumC()[LEVEL_RANGE] += cSum[ LEVEL_RANGE ] ;
2705  m_pcTrQuant->getSliceNSamples()[LEVEL_RANGE] += numSamples[ LEVEL_RANGE ] ;
2706}
2707#endif
2708//! \}
Note: See TracBrowser for help on using the repository browser.