source: 3DVCSoftware/trunk/source/Lib/TLibEncoder/TEncCu.cpp @ 332

Last change on this file since 332 was 332, checked in by tech, 11 years ago

Merged branch 6.1-Cleanup@329.

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