source: 3DVCSoftware/branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncCu.cpp @ 137

Last change on this file since 137 was 100, checked in by tech, 12 years ago

Adopted modifications:

  • disparity vector generation (A0097)
  • inter-view motion prediction modification (A0049)
  • simplification of disparity vector derivation (A0126)
  • region boundary chain coding (A0070)
  • residual skip intra (A0087)
  • VSO modification (A0033/A0093)

+ Clean ups + Bug fixes

Update of cfg files (A0033 modification 2)

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