source: 3DVCSoftware/branches/HTM-5.0-dev0/source/Lib/TLibEncoder/TEncCu.cpp @ 207

Last change on this file since 207 was 189, checked in by tech, 12 years ago

Reintegrated branch 4.1-dev0 Rev. 188.

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