source: 3DVCSoftware/branches/HTM-11.2-dev0/source/Lib/TLibEncoder/TEncCu.cpp @ 1029

Last change on this file since 1029 was 1029, checked in by tech, 10 years ago

Merged 11.2-dev1-MediaTek@1004.

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