Changeset 845 in 3DVCSoftware


Ignore:
Timestamp:
11 Feb 2014, 22:15:54 (10 years ago)
Author:
tech
Message:

Fixed missing braces.
Added some generic functionality for debugging.

Location:
branches/HTM-10.0rc1-dev0/source
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • branches/HTM-10.0rc1-dev0/source/App/TAppDecoder/TAppDecTop.cpp

    r841 r845  
    288288          else
    289289          {
    290             g_disableHLSTrace = true;     // Trancing of second parsing of SH is not carried out
     290            g_disableHLSTrace = true;     // Tracing of second parsing of SH is not carried out
    291291          }     
    292292#endif
  • branches/HTM-10.0rc1-dev0/source/Lib/TLibCommon/TComRom.cpp

    r838 r845  
    372372Bool g_traceTU = true;
    373373Bool g_disableHLSTrace = false;
    374 UInt64 g_stopAtCounter       = 48;
     374UInt64 g_stopAtCounter       = 0;
    375375Bool g_traceCopyBack         = false;
    376376Bool g_decTraceDispDer       = false;
    377377Bool g_decTraceMvFromMerge   = false;
     378Bool g_stopAtPos             = false;
     379Bool g_outputPos             = false;
    378380#endif
    379381#endif
     
    562564#if H_MV_ENC_DEC_TRAC
    563565#if ENC_DEC_TRACE
     566Void stopAtPos( Int poc, Int layerId, Int cuPelX, Int cuPelY, Int cuWidth, Int cuHeight )
     567{
     568
     569  if ( g_outputPos )
     570  {
     571    std::cout << "POC\t"        << poc
     572              << "\tLayerId\t"  << layerId
     573              << "\tCuPelX\t"   << cuPelX 
     574              << "\tCuPelY\t"   << cuPelY
     575              << "\tCuWidth\t"  << cuWidth
     576              << "\tCuHeight\t" << cuHeight
     577              << std::endl;
     578  }
     579
     580  Bool stopFlag = false;
     581  if ( g_stopAtPos && poc == 0 && layerId == 4 )
     582  {
     583    Bool stopAtCU = true;
     584    if ( stopAtCU )        // Stop at CU with specific size
     585    {   
     586      stopFlag = ( cuPelX  == 16 ) && ( cuPelY  == 112 ) && ( cuWidth == 16 ) && ( cuHeight == 16);
     587    }
     588    else
     589    {                     // Stop at specific position
     590      Int xPos = 18;
     591      Int yPos = 112;
     592
     593      Int cuPelXEnd = cuPelX + cuWidth  - 1;
     594      Int cuPelYEnd = cuPelY + cuHeight - 1;
     595
     596      stopFlag = (cuPelX <= xPos ) && (cuPelXEnd >= xPos ) && (cuPelY <= yPos ) && (cuPelYEnd >= yPos );
     597    }
     598  }
     599 
     600  if ( stopFlag )
     601  { // Set breakpoint here.
     602    std::cout << "Stop position. Break point here." << std::endl;
     603  } 
     604}
     605
    564606Void writeToTraceFile( const Char* symbolName, Int val, Bool doIt )
    565607{
  • branches/HTM-10.0rc1-dev0/source/Lib/TLibCommon/TComRom.h

    r837 r845  
    219219 extern UInt64 g_stopAtCounter;         // Counter to set breakpoint.
    220220 extern Bool   g_traceCopyBack;         // Output samples on copy back 
    221  extern Bool   g_decTraceDispDer; // Trace derived disparity vectors (decoder only)
     221 extern Bool   g_decTraceDispDer;       // Trace derived disparity vectors (decoder only)
    222222 extern Bool   g_decTraceMvFromMerge;   // Trace motion vectors obtained from merge (decoder only)
     223 extern Bool   g_stopAtPos;             // Stop at position
     224 extern Bool   g_outputPos;             // Output position
    223225
    224226#define DTRACE_CU(x,y)             writeToTraceFile( x,y, g_traceCU );
     
    229231#define DTRACE_TU_S(x)             writeToTraceFile( x,   g_traceTU );
    230232
    231 
    232233 Void           writeToTraceFile( const Char* symbolName, Int val, Bool doIt );
    233234 Void           writeToTraceFile( const Char* symbolName, Bool doIt );
     235 Void           stopAtPos       ( Int poc, Int layerId, Int cuPelX, Int cuPelY, Int cuWidth, Int cuHeight );
    234236#endif
    235237#else
  • branches/HTM-10.0rc1-dev0/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp

    r837 r845  
    4141#include <stdio.h>
    4242#include <math.h>
    43 
    4443//! \ingroup TLibCommon
    4544//! \{
  • branches/HTM-10.0rc1-dev0/source/Lib/TLibCommon/TComSlice.cpp

    r837 r845  
    19421942  for ( i = 0; i < iNumViews ; i++ )
    19431943  {
     1944    m_bCamParInSliceHeader[i] = false;
    19441945    m_aaaiCodedScale[i] = new Int*[ 2 ];
    19451946    m_aaaiCodedOffset[i] = new Int*[ 2 ];
  • branches/HTM-10.0rc1-dev0/source/Lib/TLibCommon/TypeDef.h

    r840 r845  
    327327///////////////////////////////////   HTM-10.1 Integrations //////////////////////////////
    328328/////////////////////////////////////////////////////////////////////////////////////////
    329 
    330329#define UPDATE_HM13                       1
     330#define H_3D_FIX_G0148_BRACE              1
    331331/////////////////////////////////////////////////////////////////////////////////////////
    332332///////////////////////////////////   HM RELATED DEFINES ////////////////////////////////
  • branches/HTM-10.0rc1-dev0/source/Lib/TLibDecoder/TDecCu.cpp

    r837 r845  
    3737
    3838#include "TDecCu.h"
    39 
    4039//! \ingroup TLibDecoder
    4140//! \{
     
    639638 
    640639  m_ppcCU[uiDepth]->copySubCU( pcCU, uiAbsPartIdx, uiDepth );
    641  
     640
     641#if H_MV_ENC_DEC_TRAC
     642#if ENC_DEC_TRACE
     643  stopAtPos  ( m_ppcCU[uiDepth]->getSlice()->getPOC(),
     644    m_ppcCU[uiDepth]->getSlice()->getLayerId(),
     645    m_ppcCU[uiDepth]->getCUPelX(),
     646    m_ppcCU[uiDepth]->getCUPelY(),
     647    m_ppcCU[uiDepth]->getWidth(0),
     648    m_ppcCU[uiDepth]->getHeight(0) );
     649#endif
     650#endif
     651
    642652  switch( m_ppcCU[uiDepth]->getPredictionMode(0) )
    643653  {
  • branches/HTM-10.0rc1-dev0/source/Lib/TLibDecoder/TDecGop.cpp

    r837 r845  
    4343#include "libmd5/MD5.h"
    4444#include "TLibCommon/SEI.h"
    45 
    4645#include <time.h>
    4746
  • branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncCu.cpp

    r842 r845  
    4040#include "TEncCu.h"
    4141#include "TEncAnalyze.h"
    42 
    4342#include <cmath>
    4443#include <algorithm>
     
    422421  // get Original YUV data from picture
    423422  m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() );
    424 
     423 
    425424#if H_3D_QTLPC 
    426425  Bool    bTrySplit     = true;
     
    449448  UInt uiTPelY   = rpcBestCU->getCUPelY();
    450449  UInt uiBPelY   = uiTPelY + rpcBestCU->getHeight(0) - 1;
     450
     451#if H_MV_ENC_DEC_TRAC
     452#if ENC_DEC_TRACE
     453    stopAtPos  ( rpcBestCU->getSlice()->getPOC(),
     454                 rpcBestCU->getSlice()->getLayerId(),
     455                 rpcBestCU->getCUPelX(),
     456                 rpcBestCU->getCUPelY(),
     457                 rpcBestCU->getWidth(0),
     458                 rpcBestCU->getHeight(0) );
     459#endif
     460#endif
    451461
    452462  Int iBaseQP = xComputeQP( rpcBestCU, uiDepth );
     
    11881198        if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
    11891199        {
    1190             if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer
    1191             {
    1192               m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
    1193             }
    1194             else
    1195             {
    1196               m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
    1197             }
     1200          if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer
     1201          {
     1202            m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
     1203          }
     1204          else
     1205          {
     1206            m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
     1207          }
    11981208
    11991209#if AMP_ENC_SPEEDUP
     
    12261236
    12271237        rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits
    1228           rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    1229         }
     1238        rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
     1239      }
    12301240#if H_3D_VSO // M10
    12311241      if ( m_pcRdCost->getUseVSO() )
     
    12331243      else
    12341244#endif
    1235       rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
     1245        rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
    12361246
    12371247      if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() && rpcTempCU->getSlice()->getPPS()->getUseDQP())
     
    12411251        {
    12421252          if( ( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(uiBlkIdx+rpcTempCU->getZorderIdxInCU()) == rpcTempCU->getSlice()->getSliceSegmentCurStartCUAddr() ) &&
    1243               ( rpcTempCU->getCbf( uiBlkIdx, TEXT_LUMA ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_U ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_V ) ) )
     1253            ( rpcTempCU->getCbf( uiBlkIdx, TEXT_LUMA ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_U ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_V ) ) )
    12441254          {
    12451255            hasResidual = true;
     
    12631273          m_pcEntropyCoder->encodeQP( rpcTempCU, uiTargetPartIdx, false );
    12641274          rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits
    1265             rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
     1275          rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    12661276#if H_3D_VSO // M11
    12671277          if ( m_pcRdCost->getUseLambdaScaleVSO())         
     
    12691279          else
    12701280#endif
    1271           rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
     1281            rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
    12721282#endif
    12731283
     
    12821292      }
    12831293
    1284         m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
     1294      m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
    12851295      Bool isEndOfSlice        = rpcBestCU->getSlice()->getSliceMode()==FIXED_NUMBER_OF_BYTES
    1286                                  && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3);
     1296        && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3);
    12871297      Bool isEndOfSliceSegment = rpcBestCU->getSlice()->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES
    1288                                  && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceSegmentArgument()<<3);
     1298        && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceSegmentArgument()<<3);
    12891299      if(isEndOfSlice||isEndOfSliceSegment)
    12901300      {
     
    12931303      xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth);                                  // RD compare current larger prediction
    12941304    }                                                                                  // with sub partitioned prediction.
    1295     }
     1305  }
    12961306
    12971307#if H_3D_VSO // M12
     
    17761786#endif
    17771787#if H_3D_ARP
    1778 for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui )
    1779 #else
    1780 for( UInt ui = 0; ui < numValidMergeCand; ++ui )
     1788  for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui )
     1789#else
     1790  for( UInt ui = 0; ui < numValidMergeCand; ++ui )
    17811791#endif
    17821792  {
     
    18511861#endif
    18521862
    1853   for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual )
    1854   {
    1855     for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
    1856     {     
     1863    for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual )
     1864    {
     1865      for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
     1866      {     
    18571867#if H_3D_IC
    18581868        if( rpcTempCU->getSlice()->getApplyIC() && rpcTempCU->getSlice()->getIcSkipParseFlag() )
     
    18661876        if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1))
    18671877        {
    1868         if( !(bestIsSkip && uiNoResidual == 0) )
    1869         {
    1870           // set MC parameters
    1871           rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to LCU level
    1872           rpcTempCU->setCUTransquantBypassSubParts( bTransquantBypassFlag,     0, uhDepth );
    1873           rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
     1878          if( !(bestIsSkip && uiNoResidual == 0) )
     1879          {
     1880            // set MC parameters
     1881            rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to LCU level
     1882            rpcTempCU->setCUTransquantBypassSubParts( bTransquantBypassFlag,     0, uhDepth );
     1883            rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
    18741884#if H_3D_IC
    1875           rpcTempCU->setICFlagSubParts( bICFlag, 0, 0, uhDepth );
     1885            rpcTempCU->setICFlagSubParts( bICFlag, 0, 0, uhDepth );
    18761886#endif
    18771887#if H_3D_ARP
    1878           rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth );
    1879 #endif
    1880           rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level
    1881           rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level
     1888            rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth );
     1889#endif
     1890            rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level
     1891            rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level
    18821892#if H_3D_VSP
    1883           rpcTempCU->setVSPFlagSubParts( vspFlag[uiMergeCand], 0, 0, uhDepth );
    1884           rpcTempCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeCand].m_acDvInfo, 0, 0, uhDepth );
     1893            rpcTempCU->setVSPFlagSubParts( vspFlag[uiMergeCand], 0, 0, uhDepth );
     1894            rpcTempCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeCand].m_acDvInfo, 0, 0, uhDepth );
    18851895#endif
    18861896#if MTK_DDD_G0063
    1887           if( rpcTempCU->getSlice()->getIsDepth() && rpcTempCU->getSlice()->getViewIndex() != 0 && iDDDCand == uiMergeCand )
    1888           {
     1897            if( rpcTempCU->getSlice()->getIsDepth() && rpcTempCU->getSlice()->getViewIndex() != 0 && iDDDCand == uiMergeCand )
     1898            {
    18891899              rpcTempCU->setUseDDD( true, 0, 0, uhDepth );
    18901900              rpcTempCU->setDDDepthSubParts( ucDDDepth, 0, 0, uhDepth );
    1891           }
    1892           else
    1893           {
    1894               rpcTempCU->setUseDDD( false, 0, 0, uhDepth );
    1895           }
    1896 #endif
    1897 #if H_3D_SPIVMP
    1898           rpcTempCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMergeCand], 0, 0, uhDepth);
    1899           if (bSPIVMPFlag[uiMergeCand])
    1900           {
    1901             UInt uiSPAddr;
    1902             Int iWidth = rpcTempCU->getWidth(0);
    1903             Int iHeight = rpcTempCU->getHeight(0);
    1904             Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
    1905             rpcTempCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
    1906             for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++)
    1907             {
    1908               rpcTempCU->getSPAbsPartIdx(0, iSPWidth, iSPHeight, iPartitionIdx, iNumSPInOneLine, uiSPAddr);
    1909               rpcTempCU->setInterDirSP(puhInterDirSP[iPartitionIdx], uiSPAddr, iSPWidth, iSPHeight);
    1910               rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setMvFieldSP(rpcTempCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx], iSPWidth, iSPHeight);
    1911               rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(rpcTempCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight);
    1912             }
    1913           }
    1914           else
    1915 #endif
    1916 #if NTT_STORE_SPDV_VSP_G0148
    1917           if ( vspFlag[uiMergeCand] )
    1918           {
    1919             UInt partAddr;
    1920             Int vspSize;
    1921             Int width, height;
    1922             rpcTempCU->getPartIndexAndSize( 0, partAddr, width, height );
    1923             if( uhInterDirNeighbours[ uiMergeCand ] & 0x01 )
    1924             {
    1925               rpcTempCU->setMvFieldPUForVSP( rpcTempCU, partAddr, width, height, REF_PIC_LIST_0, cMvFieldNeighbours[ 2*uiMergeCand + 0 ].getRefIdx(), vspSize );
    1926               rpcTempCU->setVSPFlag( partAddr, vspSize );
    19271901            }
    19281902            else
    19291903            {
    1930               rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
     1904              rpcTempCU->setUseDDD( false, 0, 0, uhDepth );
    19311905            }
    1932             if( uhInterDirNeighbours[ uiMergeCand ] & 0x02 )
     1906#endif
     1907#if H_3D_SPIVMP
     1908            rpcTempCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMergeCand], 0, 0, uhDepth);
     1909            if (bSPIVMPFlag[uiMergeCand])
    19331910            {
    1934               rpcTempCU->setMvFieldPUForVSP( rpcTempCU, partAddr, width, height, REF_PIC_LIST_1 , cMvFieldNeighbours[ 2*uiMergeCand + 1 ].getRefIdx(), vspSize );
    1935               rpcTempCU->setVSPFlag( partAddr, vspSize );
     1911              UInt uiSPAddr;
     1912              Int iWidth = rpcTempCU->getWidth(0);
     1913              Int iHeight = rpcTempCU->getHeight(0);
     1914              Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
     1915              rpcTempCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
     1916              for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++)
     1917              {
     1918                rpcTempCU->getSPAbsPartIdx(0, iSPWidth, iSPHeight, iPartitionIdx, iNumSPInOneLine, uiSPAddr);
     1919                rpcTempCU->setInterDirSP(puhInterDirSP[iPartitionIdx], uiSPAddr, iSPWidth, iSPHeight);
     1920                rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setMvFieldSP(rpcTempCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx], iSPWidth, iSPHeight);
     1921                rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(rpcTempCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight);
     1922              }
    19361923            }
    19371924            else
     1925#endif
     1926#if NTT_STORE_SPDV_VSP_G0148
    19381927            {
    1939               rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
     1928              if ( vspFlag[uiMergeCand] )
     1929              {
     1930                UInt partAddr;
     1931                Int vspSize;
     1932                Int width, height;
     1933                rpcTempCU->getPartIndexAndSize( 0, partAddr, width, height );
     1934                if( uhInterDirNeighbours[ uiMergeCand ] & 0x01 )
     1935                {
     1936                  rpcTempCU->setMvFieldPUForVSP( rpcTempCU, partAddr, width, height, REF_PIC_LIST_0, cMvFieldNeighbours[ 2*uiMergeCand + 0 ].getRefIdx(), vspSize );
     1937                  rpcTempCU->setVSPFlag( partAddr, vspSize );
     1938                }
     1939                else
     1940                {
     1941                  rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
     1942                }
     1943                if( uhInterDirNeighbours[ uiMergeCand ] & 0x02 )
     1944                {
     1945                  rpcTempCU->setMvFieldPUForVSP( rpcTempCU, partAddr, width, height, REF_PIC_LIST_1 , cMvFieldNeighbours[ 2*uiMergeCand + 1 ].getRefIdx(), vspSize );
     1946                  rpcTempCU->setVSPFlag( partAddr, vspSize );
     1947                }
     1948                else
     1949                {
     1950                  rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
     1951                }
     1952                rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level
     1953              }
     1954              else
     1955              {
     1956#endif
     1957                rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level
     1958                rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
     1959                rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
     1960#if NTT_STORE_SPDV_VSP_G0148
     1961              }
    19401962            }
    1941             rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level
    1942           }
    1943           else
    1944           {
    1945 #endif
    1946             rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level
    1947             rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
    1948             rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
    1949 #if NTT_STORE_SPDV_VSP_G0148
    1950           }
    1951 #endif
    1952        // do MC
    1953        m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
    1954        // estimate residual and encode everything
     1963#endif
     1964            // do MC
     1965            m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
     1966            // estimate residual and encode everything
    19551967#if H_3D_VSO //M2
    1956        if( m_pcRdCost->getUseRenModel() )
    1957        { //Reset
    1958          UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth    ();
    1959          UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight   ();
    1960          Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr ();
    1961          UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride   ();
    1962          m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    1963        }
    1964 #endif
    1965        m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU,
    1966          m_ppcOrigYuv    [uhDepth],
    1967          m_ppcPredYuvTemp[uhDepth],
    1968          m_ppcResiYuvTemp[uhDepth],
    1969          m_ppcResiYuvBest[uhDepth],
    1970          m_ppcRecoYuvTemp[uhDepth],
    1971          (uiNoResidual? true:false));
    1972 
    1973 
    1974           if ( uiNoResidual == 0 && rpcTempCU->getQtRootCbf(0) == 0 )
    1975          {
    1976             // If no residual when allowing for one, then set mark to not try case where residual is forced to 0
    1977            mergeCandBuffer[uiMergeCand] = 1;
    1978          }
    1979 
    1980           rpcTempCU->setSkipFlagSubParts( rpcTempCU->getQtRootCbf(0) == 0, 0, uhDepth );
     1968            if( m_pcRdCost->getUseRenModel() )
     1969            { //Reset
     1970              UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth    ();
     1971              UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight   ();
     1972              Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr ();
     1973              UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride   ();
     1974              m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
     1975            }
     1976#endif
     1977            m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU,
     1978              m_ppcOrigYuv    [uhDepth],
     1979              m_ppcPredYuvTemp[uhDepth],
     1980              m_ppcResiYuvTemp[uhDepth],
     1981              m_ppcResiYuvBest[uhDepth],
     1982              m_ppcRecoYuvTemp[uhDepth],
     1983              (uiNoResidual? true:false));
     1984
     1985
     1986            if ( uiNoResidual == 0 && rpcTempCU->getQtRootCbf(0) == 0 )
     1987            {
     1988              // If no residual when allowing for one, then set mark to not try case where residual is forced to 0
     1989              mergeCandBuffer[uiMergeCand] = 1;
     1990            }
     1991
     1992            rpcTempCU->setSkipFlagSubParts( rpcTempCU->getQtRootCbf(0) == 0, 0, uhDepth );
    19811993#if NTT_STORE_SPDV_VSP_G0148 // possible bug fix
    1982           if( rpcTempCU->getSkipFlag(0) )
    1983           {
    1984             rpcTempCU->setTrIdxSubParts(0, 0, uhDepth);
    1985           }
     1994            if( rpcTempCU->getSkipFlag(0) )
     1995            {
     1996              rpcTempCU->setTrIdxSubParts(0, 0, uhDepth);
     1997            }
    19861998#endif
    19871999#if H_3D_INTER_SDC
    1988           TComDataCU *rpcTempCUPre = rpcTempCU;
    1989 #endif
    1990           Int orgQP = rpcTempCU->getQP( 0 );
    1991           xCheckDQP( rpcTempCU );
    1992           xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
     2000            TComDataCU *rpcTempCUPre = rpcTempCU;
     2001#endif
     2002            Int orgQP = rpcTempCU->getQP( 0 );
     2003            xCheckDQP( rpcTempCU );
     2004            xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
    19932005#if H_3D_INTER_SDC
    1994           if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) && rpcTempCU->getSlice()->getIsDepth() && !uiNoResidual )
    1995           {
     2006            if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) && rpcTempCU->getSlice()->getIsDepth() && !uiNoResidual )
     2007            {
    19962008#if SEC_INTER_SDC_G0101
    1997             for( Int uiOffest = -2 ; uiOffest <= 2 ; uiOffest++ )
    1998             {
     2009              for( Int uiOffest = -2 ; uiOffest <= 2 ; uiOffest++ )
     2010              {
     2011                if( rpcTempCU != rpcTempCUPre )
     2012                {
     2013                  rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag  );
     2014                  rpcTempCU->copyPartFrom( rpcBestCU, 0, uhDepth );
     2015                }
     2016                rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth );
     2017                rpcTempCU->setTrIdxSubParts( 0, 0, uhDepth );
     2018                rpcTempCU->setCbfSubParts( 1, 1, 1, 0, uhDepth );
     2019#if H_3D_VSO //M2
     2020                if( m_pcRdCost->getUseRenModel() )
     2021                { //Reset
     2022                  UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth    ();
     2023                  UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight   ();
     2024                  Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr ();
     2025                  UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride   ();
     2026                  m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
     2027                }
     2028#endif
     2029                m_pcPredSearch->encodeResAndCalcRdInterSDCCU( rpcTempCU,
     2030                  m_ppcOrigYuv[uhDepth],
     2031                  ( rpcTempCU != rpcTempCUPre ) ? m_ppcPredYuvBest[uhDepth] : m_ppcPredYuvTemp[uhDepth],
     2032                  m_ppcResiYuvTemp[uhDepth],
     2033                  m_ppcRecoYuvTemp[uhDepth],
     2034                  uiOffest,
     2035                  uhDepth );
     2036
     2037                xCheckDQP( rpcTempCU );
     2038                xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth );
     2039              }
     2040#else
    19992041              if( rpcTempCU != rpcTempCUPre )
    20002042              {
     
    20192061                ( rpcTempCU != rpcTempCUPre ) ? m_ppcPredYuvBest[uhDepth] : m_ppcPredYuvTemp[uhDepth],
    20202062                m_ppcResiYuvTemp[uhDepth],
    2021                 m_ppcRecoYuvTemp[uhDepth],
    2022                 uiOffest,
     2063                m_ppcRecoYuvTemp[uhDepth],
    20232064                uhDepth );
    20242065
    20252066              xCheckDQP( rpcTempCU );
    20262067              xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth );
     2068#endif
    20272069            }
    2028 #else
    2029             if( rpcTempCU != rpcTempCUPre )
     2070#endif
     2071            rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag );
     2072
     2073            if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip )
    20302074            {
    2031               rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag  );
    2032               rpcTempCU->copyPartFrom( rpcBestCU, 0, uhDepth );
     2075#if H_3D_INTER_SDC
     2076              if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) )
     2077              {
     2078                bestIsSkip = !rpcBestCU->getSDCFlag( 0 ) && ( rpcBestCU->getQtRootCbf(0) == 0 );
     2079              }
     2080              else
     2081              {
     2082#endif
     2083                bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0;
     2084#if H_3D_INTER_SDC
     2085              }
     2086#endif
    20332087            }
    2034             rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth );
    2035             rpcTempCU->setTrIdxSubParts( 0, 0, uhDepth );
    2036             rpcTempCU->setCbfSubParts( 1, 1, 1, 0, uhDepth );
    2037 #if H_3D_VSO //M2
    2038             if( m_pcRdCost->getUseRenModel() )
    2039             { //Reset
    2040               UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth    ();
    2041               UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight   ();
    2042               Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr ();
    2043               UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride   ();
    2044               m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    2045             }
    2046 #endif
    2047             m_pcPredSearch->encodeResAndCalcRdInterSDCCU( rpcTempCU,
    2048               m_ppcOrigYuv[uhDepth],
    2049               ( rpcTempCU != rpcTempCUPre ) ? m_ppcPredYuvBest[uhDepth] : m_ppcPredYuvTemp[uhDepth],
    2050               m_ppcResiYuvTemp[uhDepth],
    2051               m_ppcRecoYuvTemp[uhDepth],
    2052               uhDepth );
    2053 
    2054             xCheckDQP( rpcTempCU );
    2055             xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth );
    2056 #endif
    2057           }
    2058 #endif
    2059           rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag );
    2060 
    2061       if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip )
    2062       {
    2063 #if H_3D_INTER_SDC
    2064         if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) )
    2065         {
    2066           bestIsSkip = !rpcBestCU->getSDCFlag( 0 ) && ( rpcBestCU->getQtRootCbf(0) == 0 );
    2067         }
    2068         else
    2069         {
    2070 #endif
    2071         bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0;
    2072 #if H_3D_INTER_SDC
    2073         }
    2074 #endif
    2075       }
    2076     }
    2077    }
    2078   }
    2079 
    2080   if(uiNoResidual == 0 && m_pcEncCfg->getUseEarlySkipDetection())
    2081   {
    2082     if(rpcBestCU->getQtRootCbf( 0 ) == 0)
    2083     {
    2084       if( rpcBestCU->getMergeFlag( 0 ))
    2085       {
    2086         *earlyDetectionSkipMode = true;
    2087       }
    2088       else
    2089       {
    2090         Int absoulte_MV=0;
    2091         for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
    2092         {
    2093           if ( rpcBestCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
    2094           {
    2095             TComCUMvField* pcCUMvField = rpcBestCU->getCUMvField(RefPicList( uiRefListIdx ));
    2096             Int iHor = pcCUMvField->getMvd( 0 ).getAbsHor();
    2097             Int iVer = pcCUMvField->getMvd( 0 ).getAbsVer();
    2098             absoulte_MV+=iHor+iVer;
    20992088          }
    21002089        }
    2101 
    2102         if(absoulte_MV == 0)
     2090      }
     2091
     2092      if(uiNoResidual == 0 && m_pcEncCfg->getUseEarlySkipDetection())
     2093      {
     2094        if(rpcBestCU->getQtRootCbf( 0 ) == 0)
    21032095        {
    2104           *earlyDetectionSkipMode = true;
     2096          if( rpcBestCU->getMergeFlag( 0 ))
     2097          {
     2098            *earlyDetectionSkipMode = true;
     2099          }
     2100          else
     2101          {
     2102            Int absoulte_MV=0;
     2103            for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
     2104            {
     2105              if ( rpcBestCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
     2106              {
     2107                TComCUMvField* pcCUMvField = rpcBestCU->getCUMvField(RefPicList( uiRefListIdx ));
     2108                Int iHor = pcCUMvField->getMvd( 0 ).getAbsHor();
     2109                Int iVer = pcCUMvField->getMvd( 0 ).getAbsVer();
     2110                absoulte_MV+=iHor+iVer;
     2111              }
     2112            }
     2113
     2114            if(absoulte_MV == 0)
     2115            {
     2116              *earlyDetectionSkipMode = true;
     2117            }
     2118          }
    21052119        }
    21062120      }
    21072121    }
    2108   }
    2109  }
    21102122#if H_3D_SPIVMP
    2111  delete[] pcMvFieldSP;
    2112  delete[] puhInterDirSP;
     2123    delete[] pcMvFieldSP;
     2124    delete[] puhInterDirSP;
    21132125#endif
    21142126#if H_3D_ARP
    2115  }
     2127  }
    21162128#endif
    21172129}
  • branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncGOP.cpp

    r837 r845  
    4949#include <time.h>
    5050#include <math.h>
    51 
    5251using namespace std;
    5352//! \ingroup TLibEncoder
  • branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp

    r837 r845  
    4141#include <stdio.h>
    4242#include <math.h>
    43 
    4443//! \ingroup TLibEncoder
    4544//! \{
  • branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncSearch.cpp

    r843 r845  
    39503950        pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], ePartSize, uiAbsPartIdx, 0, iPUIdx );
    39513951        pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], ePartSize, uiAbsPartIdx, 0, iPUIdx );
    3952 
    39533952#if NTT_STORE_SPDV_VSP_G0148
    39543953      }
     
    40434042  m_cYuvPredTemp.clear();
    40444043  rpcPredYuv->clear();
    4045  
     4044
    40464045  if ( !bUseRes )
    40474046  {
    40484047    rpcResiYuv->clear();
    40494048  }
    4050  
     4049
    40514050  rpcRecoYuv->clear();
    4052  
     4051
    40534052  TComMv        cMvSrchRngLT;
    40544053  TComMv        cMvSrchRngRB;
    4055  
     4054
    40564055  TComMv        cMvZero;
    40574056  TComMv        TempMv; //kolya
    4058  
     4057
    40594058  TComMv        cMv[2];
    40604059  TComMv        cMvBi[2];
    40614060  TComMv        cMvTemp[2][33];
    4062  
     4061
    40634062  Int           iNumPart    = pcCU->getNumPartInter();
    40644063  Int           iNumPredDir = pcCU->getSlice()->isInterP() ? 1 : 2;
    4065  
     4064
    40664065  TComMv        cMvPred[2][33];
    4067  
     4066
    40684067  TComMv        cMvPredBi[2][33];
    40694068  Int           aaiMvpIdxBi[2][33];
    4070  
     4069
    40714070  Int           aaiMvpIdx[2][33];
    40724071  Int           aaiMvpNum[2][33];
    4073  
     4072
    40744073  AMVPInfo aacAMVPInfo[2][33];
    4075  
     4074
    40764075  Int           iRefIdx[2]={0,0}; //If un-initialized, may cause SEGV in bi-directional prediction iterative stage.
    40774076  Int           iRefIdxBi[2];
    4078  
     4077
    40794078  UInt          uiPartAddr;
    40804079  Int           iRoiWidth, iRoiHeight;
    4081  
     4080
    40824081  UInt          uiMbBits[3] = {1, 1, 0};
    4083  
     4082
    40844083  UInt          uiLastMode = 0;
    40854084  Int           iRefStart, iRefEnd;
    4086  
     4085
    40874086  PartSize      ePartSize = pcCU->getPartitionSize( 0 );
    40884087
     
    41114110    UInt          uiCostBi  =   MAX_UINT;
    41124111    UInt          uiCostTemp;
    4113    
     4112
    41144113    UInt          uiBits[3];
    41154114    UInt          uiBitsTemp;
     
    41364135
    41374136    xGetBlkBits( ePartSize, pcCU->getSlice()->isInterP(), iPartIdx, uiLastMode, uiMbBits);
    4138    
     4137
    41394138    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iRoiWidth, iRoiHeight );
    41404139
     
    41424141    pcCU->setVSPFlagSubParts( 0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr) );
    41434142#endif
    4144    
     4143
    41454144#if AMP_MRG
    41464145    Bool bTestNormalMC = true;
     
    41534152      bTestNormalMC = false;
    41544153    }
    4155    
     4154
    41564155    if (bTestNormalMC)
    41574156    {
    41584157#endif
    41594158
    4160     //  Uni-directional prediction
    4161     for ( Int iRefList = 0; iRefList < iNumPredDir; iRefList++ )
    4162     {
    4163       RefPicList  eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
    4164      
    4165       for ( Int iRefIdxTemp = 0; iRefIdxTemp < pcCU->getSlice()->getNumRefIdx(eRefPicList); iRefIdxTemp++ )
    4166       {
    4167         uiBitsTemp = uiMbBits[iRefList];
    4168         if ( pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1 )
    4169         {
    4170           uiBitsTemp += iRefIdxTemp+1;
    4171           if ( iRefIdxTemp == pcCU->getSlice()->getNumRefIdx(eRefPicList)-1 ) uiBitsTemp--;
    4172         }
     4159      //  Uni-directional prediction
     4160      for ( Int iRefList = 0; iRefList < iNumPredDir; iRefList++ )
     4161      {
     4162        RefPicList  eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
     4163
     4164        for ( Int iRefIdxTemp = 0; iRefIdxTemp < pcCU->getSlice()->getNumRefIdx(eRefPicList); iRefIdxTemp++ )
     4165        {
     4166          uiBitsTemp = uiMbBits[iRefList];
     4167          if ( pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1 )
     4168          {
     4169            uiBitsTemp += iRefIdxTemp+1;
     4170            if ( iRefIdxTemp == pcCU->getSlice()->getNumRefIdx(eRefPicList)-1 ) uiBitsTemp--;
     4171          }
    41734172#if ZERO_MVD_EST
    4174         xEstimateMvPredAMVP( pcCU, pcOrgYuv, iPartIdx, eRefPicList, iRefIdxTemp, cMvPred[iRefList][iRefIdxTemp], false, &biPDistTemp, &uiZeroMvdDistTemp);
     4173          xEstimateMvPredAMVP( pcCU, pcOrgYuv, iPartIdx, eRefPicList, iRefIdxTemp, cMvPred[iRefList][iRefIdxTemp], false, &biPDistTemp, &uiZeroMvdDistTemp);
    41754174#else
    4176         xEstimateMvPredAMVP( pcCU, pcOrgYuv, iPartIdx, eRefPicList, iRefIdxTemp, cMvPred[iRefList][iRefIdxTemp], false, &biPDistTemp);
    4177 #endif
    4178         aaiMvpIdx[iRefList][iRefIdxTemp] = pcCU->getMVPIdx(eRefPicList, uiPartAddr);
    4179         aaiMvpNum[iRefList][iRefIdxTemp] = pcCU->getMVPNum(eRefPicList, uiPartAddr);
    4180        
    4181         if(pcCU->getSlice()->getMvdL1ZeroFlag() && iRefList==1 && biPDistTemp < bestBiPDist)
    4182         {
    4183           bestBiPDist = biPDistTemp;
    4184           bestBiPMvpL1 = aaiMvpIdx[iRefList][iRefIdxTemp];
    4185           bestBiPRefIdxL1 = iRefIdxTemp;
    4186         }
    4187 
    4188         uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdx[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS];
     4175          xEstimateMvPredAMVP( pcCU, pcOrgYuv, iPartIdx, eRefPicList, iRefIdxTemp, cMvPred[iRefList][iRefIdxTemp], false, &biPDistTemp);
     4176#endif
     4177          aaiMvpIdx[iRefList][iRefIdxTemp] = pcCU->getMVPIdx(eRefPicList, uiPartAddr);
     4178          aaiMvpNum[iRefList][iRefIdxTemp] = pcCU->getMVPNum(eRefPicList, uiPartAddr);
     4179
     4180          if(pcCU->getSlice()->getMvdL1ZeroFlag() && iRefList==1 && biPDistTemp < bestBiPDist)
     4181          {
     4182            bestBiPDist = biPDistTemp;
     4183            bestBiPMvpL1 = aaiMvpIdx[iRefList][iRefIdxTemp];
     4184            bestBiPRefIdxL1 = iRefIdxTemp;
     4185          }
     4186
     4187          uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdx[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS];
    41894188#if ZERO_MVD_EST
    4190         if ( iRefList == 0 || pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp ) < 0 )
    4191         {
    4192           uiZeroMvdBitsTemp = uiBitsTemp;
    4193           uiZeroMvdBitsTemp += 2; //zero mvd bits
    4194 
    4195           m_pcRdCost->getMotionCost( 1, 0 );
    4196           uiZeroMvdCostTemp = uiZeroMvdDistTemp + m_pcRdCost->getCost(uiZeroMvdBitsTemp);
    4197 
    4198           if (uiZeroMvdCostTemp < uiZeroMvdCost)
     4189          if ( iRefList == 0 || pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp ) < 0 )
    41994190          {
    4200             uiZeroMvdCost = uiZeroMvdCostTemp;
    4201             iZeroMvdDir = iRefList + 1;
    4202             aiZeroMvdRefIdx[iRefList] = iRefIdxTemp;
    4203             aiZeroMvdMvpIdx[iRefList] = aaiMvpIdx[iRefList][iRefIdxTemp];
    4204             auiZeroMvdBits[iRefList] = uiZeroMvdBitsTemp;
    4205           }         
    4206         }
    4207 #endif
    4208        
     4191            uiZeroMvdBitsTemp = uiBitsTemp;
     4192            uiZeroMvdBitsTemp += 2; //zero mvd bits
     4193
     4194            m_pcRdCost->getMotionCost( 1, 0 );
     4195            uiZeroMvdCostTemp = uiZeroMvdDistTemp + m_pcRdCost->getCost(uiZeroMvdBitsTemp);
     4196
     4197            if (uiZeroMvdCostTemp < uiZeroMvdCost)
     4198            {
     4199              uiZeroMvdCost = uiZeroMvdCostTemp;
     4200              iZeroMvdDir = iRefList + 1;
     4201              aiZeroMvdRefIdx[iRefList] = iRefIdxTemp;
     4202              aiZeroMvdMvpIdx[iRefList] = aaiMvpIdx[iRefList][iRefIdxTemp];
     4203              auiZeroMvdBits[iRefList] = uiZeroMvdBitsTemp;
     4204            }         
     4205          }
     4206#endif
     4207
    42094208#if GPB_SIMPLE_UNI
    4210         if ( iRefList == 1 )    // list 1
    4211         {
    4212           if ( pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp ) >= 0 )
     4209          if ( iRefList == 1 )    // list 1
    42134210          {
    4214             cMvTemp[1][iRefIdxTemp] = cMvTemp[0][pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp )];
    4215             uiCostTemp = uiCostTempL0[pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp )];
    4216             /*first subtract the bit-rate part of the cost of the other list*/
    4217             uiCostTemp -= m_pcRdCost->getCost( uiBitsTempL0[pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp )] );
    4218             /*correct the bit-rate part of the current ref*/
    4219             m_pcRdCost->setPredictor  ( cMvPred[iRefList][iRefIdxTemp] );
    4220             uiBitsTemp += m_pcRdCost->getBits( cMvTemp[1][iRefIdxTemp].getHor(), cMvTemp[1][iRefIdxTemp].getVer() );
    4221             /*calculate the correct cost*/
    4222             uiCostTemp += m_pcRdCost->getCost( uiBitsTemp );
     4211            if ( pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp ) >= 0 )
     4212            {
     4213              cMvTemp[1][iRefIdxTemp] = cMvTemp[0][pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp )];
     4214              uiCostTemp = uiCostTempL0[pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp )];
     4215              /*first subtract the bit-rate part of the cost of the other list*/
     4216              uiCostTemp -= m_pcRdCost->getCost( uiBitsTempL0[pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp )] );
     4217              /*correct the bit-rate part of the current ref*/
     4218              m_pcRdCost->setPredictor  ( cMvPred[iRefList][iRefIdxTemp] );
     4219              uiBitsTemp += m_pcRdCost->getBits( cMvTemp[1][iRefIdxTemp].getHor(), cMvTemp[1][iRefIdxTemp].getVer() );
     4220              /*calculate the correct cost*/
     4221              uiCostTemp += m_pcRdCost->getCost( uiBitsTemp );
     4222            }
     4223            else
     4224            {
     4225              xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
     4226            }
    42234227          }
    42244228          else
     
    42264230            xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
    42274231          }
     4232#else
     4233          xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
     4234#endif
     4235          xCopyAMVPInfo(pcCU->getCUMvField(eRefPicList)->getAMVPInfo(), &aacAMVPInfo[iRefList][iRefIdxTemp]); // must always be done ( also when AMVP_MODE = AM_NONE )
     4236          xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPred[iRefList][iRefIdxTemp], aaiMvpIdx[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp);
     4237
     4238          if ( iRefList == 0 )
     4239          {
     4240            uiCostTempL0[iRefIdxTemp] = uiCostTemp;
     4241            uiBitsTempL0[iRefIdxTemp] = uiBitsTemp;
     4242          }
     4243          if ( uiCostTemp < uiCost[iRefList] )
     4244          {
     4245            uiCost[iRefList] = uiCostTemp;
     4246            uiBits[iRefList] = uiBitsTemp; // storing for bi-prediction
     4247
     4248            // set motion
     4249            cMv[iRefList]     = cMvTemp[iRefList][iRefIdxTemp];
     4250            iRefIdx[iRefList] = iRefIdxTemp;
     4251          }
     4252
     4253          if ( iRefList == 1 && uiCostTemp < costValidList1 && pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp ) < 0 )
     4254          {
     4255            costValidList1 = uiCostTemp;
     4256            bitsValidList1 = uiBitsTemp;
     4257
     4258            // set motion
     4259            mvValidList1     = cMvTemp[iRefList][iRefIdxTemp];
     4260            refIdxValidList1 = iRefIdxTemp;
     4261          }
     4262        }
     4263      }
     4264      //  Bi-directional prediction
     4265      if ( (pcCU->getSlice()->isInterB()) && (pcCU->isBipredRestriction(iPartIdx) == false) )
     4266      {
     4267
     4268        cMvBi[0] = cMv[0];            cMvBi[1] = cMv[1];
     4269        iRefIdxBi[0] = iRefIdx[0];    iRefIdxBi[1] = iRefIdx[1];
     4270
     4271        ::memcpy(cMvPredBi, cMvPred, sizeof(cMvPred));
     4272        ::memcpy(aaiMvpIdxBi, aaiMvpIdx, sizeof(aaiMvpIdx));
     4273
     4274        UInt uiMotBits[2];
     4275
     4276        if(pcCU->getSlice()->getMvdL1ZeroFlag())
     4277        {
     4278          xCopyAMVPInfo(&aacAMVPInfo[1][bestBiPRefIdxL1], pcCU->getCUMvField(REF_PIC_LIST_1)->getAMVPInfo());
     4279          pcCU->setMVPIdxSubParts( bestBiPMvpL1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     4280          aaiMvpIdxBi[1][bestBiPRefIdxL1] = bestBiPMvpL1;
     4281          cMvPredBi[1][bestBiPRefIdxL1]   = pcCU->getCUMvField(REF_PIC_LIST_1)->getAMVPInfo()->m_acMvCand[bestBiPMvpL1];
     4282
     4283          cMvBi[1] = cMvPredBi[1][bestBiPRefIdxL1];
     4284          iRefIdxBi[1] = bestBiPRefIdxL1;
     4285          pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( cMvBi[1], ePartSize, uiPartAddr, 0, iPartIdx );
     4286          pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( iRefIdxBi[1], ePartSize, uiPartAddr, 0, iPartIdx );
     4287          TComYuv* pcYuvPred = &m_acYuvPred[1];
     4288          motionCompensation( pcCU, pcYuvPred, REF_PIC_LIST_1, iPartIdx );
     4289
     4290          uiMotBits[0] = uiBits[0] - uiMbBits[0];
     4291          uiMotBits[1] = uiMbBits[1];
     4292
     4293          if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1) > 1 )
     4294          {
     4295            uiMotBits[1] += bestBiPRefIdxL1+1;
     4296            if ( bestBiPRefIdxL1 == pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1)-1 ) uiMotBits[1]--;
     4297          }
     4298
     4299          uiMotBits[1] += m_auiMVPIdxCost[aaiMvpIdxBi[1][bestBiPRefIdxL1]][AMVP_MAX_NUM_CANDS];
     4300
     4301          uiBits[2] = uiMbBits[2] + uiMotBits[0] + uiMotBits[1];
     4302
     4303          cMvTemp[1][bestBiPRefIdxL1] = cMvBi[1];
    42284304        }
    42294305        else
    42304306        {
    4231           xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
    4232         }
    4233 #else
    4234         xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
    4235 #endif
    4236         xCopyAMVPInfo(pcCU->getCUMvField(eRefPicList)->getAMVPInfo(), &aacAMVPInfo[iRefList][iRefIdxTemp]); // must always be done ( also when AMVP_MODE = AM_NONE )
    4237         xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPred[iRefList][iRefIdxTemp], aaiMvpIdx[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp);
    4238 
    4239         if ( iRefList == 0 )
    4240         {
    4241           uiCostTempL0[iRefIdxTemp] = uiCostTemp;
    4242           uiBitsTempL0[iRefIdxTemp] = uiBitsTemp;
    4243         }
    4244         if ( uiCostTemp < uiCost[iRefList] )
    4245         {
    4246           uiCost[iRefList] = uiCostTemp;
    4247           uiBits[iRefList] = uiBitsTemp; // storing for bi-prediction
    4248 
    4249           // set motion
    4250           cMv[iRefList]     = cMvTemp[iRefList][iRefIdxTemp];
    4251           iRefIdx[iRefList] = iRefIdxTemp;
    4252         }
    4253 
    4254         if ( iRefList == 1 && uiCostTemp < costValidList1 && pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp ) < 0 )
    4255         {
    4256           costValidList1 = uiCostTemp;
    4257           bitsValidList1 = uiBitsTemp;
    4258 
    4259           // set motion
    4260           mvValidList1     = cMvTemp[iRefList][iRefIdxTemp];
    4261           refIdxValidList1 = iRefIdxTemp;
    4262         }
    4263       }
    4264     }
    4265     //  Bi-directional prediction
    4266     if ( (pcCU->getSlice()->isInterB()) && (pcCU->isBipredRestriction(iPartIdx) == false) )
    4267     {
    4268      
    4269       cMvBi[0] = cMv[0];            cMvBi[1] = cMv[1];
    4270       iRefIdxBi[0] = iRefIdx[0];    iRefIdxBi[1] = iRefIdx[1];
    4271      
    4272       ::memcpy(cMvPredBi, cMvPred, sizeof(cMvPred));
    4273       ::memcpy(aaiMvpIdxBi, aaiMvpIdx, sizeof(aaiMvpIdx));
    4274      
    4275       UInt uiMotBits[2];
    4276 
    4277       if(pcCU->getSlice()->getMvdL1ZeroFlag())
    4278       {
    4279         xCopyAMVPInfo(&aacAMVPInfo[1][bestBiPRefIdxL1], pcCU->getCUMvField(REF_PIC_LIST_1)->getAMVPInfo());
    4280         pcCU->setMVPIdxSubParts( bestBiPMvpL1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    4281         aaiMvpIdxBi[1][bestBiPRefIdxL1] = bestBiPMvpL1;
    4282         cMvPredBi[1][bestBiPRefIdxL1]   = pcCU->getCUMvField(REF_PIC_LIST_1)->getAMVPInfo()->m_acMvCand[bestBiPMvpL1];
    4283 
    4284         cMvBi[1] = cMvPredBi[1][bestBiPRefIdxL1];
    4285         iRefIdxBi[1] = bestBiPRefIdxL1;
    4286         pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( cMvBi[1], ePartSize, uiPartAddr, 0, iPartIdx );
    4287         pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( iRefIdxBi[1], ePartSize, uiPartAddr, 0, iPartIdx );
    4288         TComYuv* pcYuvPred = &m_acYuvPred[1];
    4289         motionCompensation( pcCU, pcYuvPred, REF_PIC_LIST_1, iPartIdx );
    4290 
    4291         uiMotBits[0] = uiBits[0] - uiMbBits[0];
    4292         uiMotBits[1] = uiMbBits[1];
    4293 
    4294         if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1) > 1 )
    4295         {
    4296           uiMotBits[1] += bestBiPRefIdxL1+1;
    4297           if ( bestBiPRefIdxL1 == pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1)-1 ) uiMotBits[1]--;
    4298         }
    4299 
    4300         uiMotBits[1] += m_auiMVPIdxCost[aaiMvpIdxBi[1][bestBiPRefIdxL1]][AMVP_MAX_NUM_CANDS];
    4301 
    4302         uiBits[2] = uiMbBits[2] + uiMotBits[0] + uiMotBits[1];
    4303 
    4304         cMvTemp[1][bestBiPRefIdxL1] = cMvBi[1];
    4305       }
    4306       else
    4307       {
    4308         uiMotBits[0] = uiBits[0] - uiMbBits[0];
    4309         uiMotBits[1] = uiBits[1] - uiMbBits[1];
    4310         uiBits[2] = uiMbBits[2] + uiMotBits[0] + uiMotBits[1];
    4311       }
    4312 
    4313       // 4-times iteration (default)
    4314       Int iNumIter = 4;
    4315      
    4316       // fast encoder setting: only one iteration
    4317       if ( m_pcEncCfg->getUseFastEnc() || pcCU->getSlice()->getMvdL1ZeroFlag())
    4318       {
    4319         iNumIter = 1;
    4320       }
    4321      
    4322       for ( Int iIter = 0; iIter < iNumIter; iIter++ )
    4323       {
    4324        
    4325         Int         iRefList    = iIter % 2;
    4326         if ( m_pcEncCfg->getUseFastEnc() )
    4327         {
    4328           if( uiCost[0] <= uiCost[1] )
     4307          uiMotBits[0] = uiBits[0] - uiMbBits[0];
     4308          uiMotBits[1] = uiBits[1] - uiMbBits[1];
     4309          uiBits[2] = uiMbBits[2] + uiMotBits[0] + uiMotBits[1];
     4310        }
     4311
     4312        // 4-times iteration (default)
     4313        Int iNumIter = 4;
     4314
     4315        // fast encoder setting: only one iteration
     4316        if ( m_pcEncCfg->getUseFastEnc() || pcCU->getSlice()->getMvdL1ZeroFlag())
     4317        {
     4318          iNumIter = 1;
     4319        }
     4320
     4321        for ( Int iIter = 0; iIter < iNumIter; iIter++ )
     4322        {
     4323
     4324          Int         iRefList    = iIter % 2;
     4325          if ( m_pcEncCfg->getUseFastEnc() )
    43294326          {
    4330             iRefList = 1;
     4327            if( uiCost[0] <= uiCost[1] )
     4328            {
     4329              iRefList = 1;
     4330            }
     4331            else
     4332            {
     4333              iRefList = 0;
     4334            }
    43314335          }
    4332           else
     4336          else if ( iIter == 0 )
    43334337          {
    43344338            iRefList = 0;
    43354339          }
    4336         }
    4337         else if ( iIter == 0 )
    4338         {
    4339           iRefList = 0;
    4340         }
    4341         if ( iIter == 0 && !pcCU->getSlice()->getMvdL1ZeroFlag())
    4342         {
    4343           pcCU->getCUMvField(RefPicList(1-iRefList))->setAllMv( cMv[1-iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
    4344           pcCU->getCUMvField(RefPicList(1-iRefList))->setAllRefIdx( iRefIdx[1-iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
    4345           TComYuv*  pcYuvPred = &m_acYuvPred[1-iRefList];
    4346           motionCompensation ( pcCU, pcYuvPred, RefPicList(1-iRefList), iPartIdx );
    4347         }
    4348         RefPicList  eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
    4349 
    4350         if(pcCU->getSlice()->getMvdL1ZeroFlag())
    4351         {
    4352           iRefList = 0;
    4353           eRefPicList = REF_PIC_LIST_0;
    4354         }
    4355 
    4356         Bool bChanged = false;
    4357        
    4358         iRefStart = 0;
    4359         iRefEnd   = pcCU->getSlice()->getNumRefIdx(eRefPicList)-1;
    4360        
    4361         for ( Int iRefIdxTemp = iRefStart; iRefIdxTemp <= iRefEnd; iRefIdxTemp++ )
    4362         {
    4363           uiBitsTemp = uiMbBits[2] + uiMotBits[1-iRefList];
    4364           if ( pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1 )
     4340          if ( iIter == 0 && !pcCU->getSlice()->getMvdL1ZeroFlag())
    43654341          {
    4366             uiBitsTemp += iRefIdxTemp+1;
    4367             if ( iRefIdxTemp == pcCU->getSlice()->getNumRefIdx(eRefPicList)-1 ) uiBitsTemp--;
     4342            pcCU->getCUMvField(RefPicList(1-iRefList))->setAllMv( cMv[1-iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
     4343            pcCU->getCUMvField(RefPicList(1-iRefList))->setAllRefIdx( iRefIdx[1-iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
     4344            TComYuv*  pcYuvPred = &m_acYuvPred[1-iRefList];
     4345            motionCompensation ( pcCU, pcYuvPred, RefPicList(1-iRefList), iPartIdx );
    43684346          }
    4369           uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdxBi[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS];
    4370           // call ME
    4371           xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPredBi[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp, true );
    4372           xCopyAMVPInfo(&aacAMVPInfo[iRefList][iRefIdxTemp], pcCU->getCUMvField(eRefPicList)->getAMVPInfo());
    4373           xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPredBi[iRefList][iRefIdxTemp], aaiMvpIdxBi[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp);
    4374 
    4375           if ( uiCostTemp < uiCostBi )
     4347          RefPicList  eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
     4348
     4349          if(pcCU->getSlice()->getMvdL1ZeroFlag())
    43764350          {
    4377             bChanged = true;
    4378            
    4379             cMvBi[iRefList]     = cMvTemp[iRefList][iRefIdxTemp];
    4380             iRefIdxBi[iRefList] = iRefIdxTemp;
    4381            
    4382             uiCostBi            = uiCostTemp;
    4383             uiMotBits[iRefList] = uiBitsTemp - uiMbBits[2] - uiMotBits[1-iRefList];
    4384             uiBits[2]           = uiBitsTemp;
    4385            
    4386             if(iNumIter!=1)
     4351            iRefList = 0;
     4352            eRefPicList = REF_PIC_LIST_0;
     4353          }
     4354
     4355          Bool bChanged = false;
     4356
     4357          iRefStart = 0;
     4358          iRefEnd   = pcCU->getSlice()->getNumRefIdx(eRefPicList)-1;
     4359
     4360          for ( Int iRefIdxTemp = iRefStart; iRefIdxTemp <= iRefEnd; iRefIdxTemp++ )
     4361          {
     4362            uiBitsTemp = uiMbBits[2] + uiMotBits[1-iRefList];
     4363            if ( pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1 )
    43874364            {
    4388               //  Set motion
    4389               pcCU->getCUMvField( eRefPicList )->setAllMv( cMvBi[iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
    4390               pcCU->getCUMvField( eRefPicList )->setAllRefIdx( iRefIdxBi[iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
    4391 
    4392               TComYuv* pcYuvPred = &m_acYuvPred[iRefList];
    4393               motionCompensation( pcCU, pcYuvPred, eRefPicList, iPartIdx );
     4365              uiBitsTemp += iRefIdxTemp+1;
     4366              if ( iRefIdxTemp == pcCU->getSlice()->getNumRefIdx(eRefPicList)-1 ) uiBitsTemp--;
     4367            }
     4368            uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdxBi[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS];
     4369            // call ME
     4370            xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPredBi[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp, true );
     4371            xCopyAMVPInfo(&aacAMVPInfo[iRefList][iRefIdxTemp], pcCU->getCUMvField(eRefPicList)->getAMVPInfo());
     4372            xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPredBi[iRefList][iRefIdxTemp], aaiMvpIdxBi[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp);
     4373
     4374            if ( uiCostTemp < uiCostBi )
     4375            {
     4376              bChanged = true;
     4377
     4378              cMvBi[iRefList]     = cMvTemp[iRefList][iRefIdxTemp];
     4379              iRefIdxBi[iRefList] = iRefIdxTemp;
     4380
     4381              uiCostBi            = uiCostTemp;
     4382              uiMotBits[iRefList] = uiBitsTemp - uiMbBits[2] - uiMotBits[1-iRefList];
     4383              uiBits[2]           = uiBitsTemp;
     4384
     4385              if(iNumIter!=1)
     4386              {
     4387                //  Set motion
     4388                pcCU->getCUMvField( eRefPicList )->setAllMv( cMvBi[iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
     4389                pcCU->getCUMvField( eRefPicList )->setAllRefIdx( iRefIdxBi[iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
     4390
     4391                TComYuv* pcYuvPred = &m_acYuvPred[iRefList];
     4392                motionCompensation( pcCU, pcYuvPred, eRefPicList, iPartIdx );
     4393              }
     4394            }
     4395          } // for loop-iRefIdxTemp
     4396
     4397          if ( !bChanged )
     4398          {
     4399            if ( uiCostBi <= uiCost[0] && uiCostBi <= uiCost[1] )
     4400            {
     4401              xCopyAMVPInfo(&aacAMVPInfo[0][iRefIdxBi[0]], pcCU->getCUMvField(REF_PIC_LIST_0)->getAMVPInfo());
     4402              xCheckBestMVP(pcCU, REF_PIC_LIST_0, cMvBi[0], cMvPredBi[0][iRefIdxBi[0]], aaiMvpIdxBi[0][iRefIdxBi[0]], uiBits[2], uiCostBi);
     4403              if(!pcCU->getSlice()->getMvdL1ZeroFlag())
     4404              {
     4405                xCopyAMVPInfo(&aacAMVPInfo[1][iRefIdxBi[1]], pcCU->getCUMvField(REF_PIC_LIST_1)->getAMVPInfo());
     4406                xCheckBestMVP(pcCU, REF_PIC_LIST_1, cMvBi[1], cMvPredBi[1][iRefIdxBi[1]], aaiMvpIdxBi[1][iRefIdxBi[1]], uiBits[2], uiCostBi);
     4407              }
     4408            }
     4409            break;
     4410          }
     4411        } // for loop-iter
     4412      } // if (B_SLICE)
     4413#if ZERO_MVD_EST
     4414      if ( (pcCU->getSlice()->isInterB()) && (pcCU->isBipredRestriction(iPartIdx) == false) )
     4415      {
     4416        m_pcRdCost->getMotionCost( 1, 0 );
     4417
     4418        for ( Int iL0RefIdxTemp = 0; iL0RefIdxTemp <= pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0)-1; iL0RefIdxTemp++ )
     4419          for ( Int iL1RefIdxTemp = 0; iL1RefIdxTemp <= pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1)-1; iL1RefIdxTemp++ )
     4420          {
     4421            UInt uiRefIdxBitsTemp = 0;
     4422            if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0) > 1 )
     4423            {
     4424              uiRefIdxBitsTemp += iL0RefIdxTemp+1;
     4425              if ( iL0RefIdxTemp == pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0)-1 ) uiRefIdxBitsTemp--;
     4426            }
     4427            if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1) > 1 )
     4428            {
     4429              uiRefIdxBitsTemp += iL1RefIdxTemp+1;
     4430              if ( iL1RefIdxTemp == pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1)-1 ) uiRefIdxBitsTemp--;
     4431            }
     4432
     4433            Int iL0MVPIdx = 0;
     4434            Int iL1MVPIdx = 0;
     4435
     4436            for (iL0MVPIdx = 0; iL0MVPIdx < aaiMvpNum[0][iL0RefIdxTemp]; iL0MVPIdx++)
     4437            {
     4438              for (iL1MVPIdx = 0; iL1MVPIdx < aaiMvpNum[1][iL1RefIdxTemp]; iL1MVPIdx++)
     4439              {
     4440                uiZeroMvdBitsTemp = uiRefIdxBitsTemp;
     4441                uiZeroMvdBitsTemp += uiMbBits[2];
     4442                uiZeroMvdBitsTemp += m_auiMVPIdxCost[iL0MVPIdx][aaiMvpNum[0][iL0RefIdxTemp]] + m_auiMVPIdxCost[iL1MVPIdx][aaiMvpNum[1][iL1RefIdxTemp]];
     4443                uiZeroMvdBitsTemp += 4; //zero mvd for both directions
     4444                pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( aacAMVPInfo[0][iL0RefIdxTemp].m_acMvCand[iL0MVPIdx], iL0RefIdxTemp, ePartSize, uiPartAddr, iPartIdx, 0 );
     4445                pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( aacAMVPInfo[1][iL1RefIdxTemp].m_acMvCand[iL1MVPIdx], iL1RefIdxTemp, ePartSize, uiPartAddr, iPartIdx, 0 );
     4446
     4447                xGetInterPredictionError( pcCU, pcOrgYuv, iPartIdx, uiZeroMvdDistTemp, m_pcEncCfg->getUseHADME() );
     4448                uiZeroMvdCostTemp = uiZeroMvdDistTemp + m_pcRdCost->getCost( uiZeroMvdBitsTemp );
     4449                if (uiZeroMvdCostTemp < uiZeroMvdCost)
     4450                {
     4451                  uiZeroMvdCost = uiZeroMvdCostTemp;
     4452                  iZeroMvdDir = 3;
     4453                  aiZeroMvdMvpIdx[0] = iL0MVPIdx;
     4454                  aiZeroMvdMvpIdx[1] = iL1MVPIdx;
     4455                  aiZeroMvdRefIdx[0] = iL0RefIdxTemp;
     4456                  aiZeroMvdRefIdx[1] = iL1RefIdxTemp;
     4457                  auiZeroMvdBits[2] = uiZeroMvdBitsTemp;
     4458                }
     4459              }
    43944460            }
    43954461          }
    4396         } // for loop-iRefIdxTemp
    4397        
    4398         if ( !bChanged )
    4399         {
    4400           if ( uiCostBi <= uiCost[0] && uiCostBi <= uiCost[1] )
    4401           {
    4402             xCopyAMVPInfo(&aacAMVPInfo[0][iRefIdxBi[0]], pcCU->getCUMvField(REF_PIC_LIST_0)->getAMVPInfo());
    4403             xCheckBestMVP(pcCU, REF_PIC_LIST_0, cMvBi[0], cMvPredBi[0][iRefIdxBi[0]], aaiMvpIdxBi[0][iRefIdxBi[0]], uiBits[2], uiCostBi);
    4404             if(!pcCU->getSlice()->getMvdL1ZeroFlag())
    4405             {
    4406               xCopyAMVPInfo(&aacAMVPInfo[1][iRefIdxBi[1]], pcCU->getCUMvField(REF_PIC_LIST_1)->getAMVPInfo());
    4407               xCheckBestMVP(pcCU, REF_PIC_LIST_1, cMvBi[1], cMvPredBi[1][iRefIdxBi[1]], aaiMvpIdxBi[1][iRefIdxBi[1]], uiBits[2], uiCostBi);
    4408             }
    4409           }
    4410           break;
    4411         }
    4412       } // for loop-iter
    4413     } // if (B_SLICE)
    4414 #if ZERO_MVD_EST
    4415     if ( (pcCU->getSlice()->isInterB()) && (pcCU->isBipredRestriction(iPartIdx) == false) )
    4416     {
    4417       m_pcRdCost->getMotionCost( 1, 0 );
    4418 
    4419       for ( Int iL0RefIdxTemp = 0; iL0RefIdxTemp <= pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0)-1; iL0RefIdxTemp++ )
    4420       for ( Int iL1RefIdxTemp = 0; iL1RefIdxTemp <= pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1)-1; iL1RefIdxTemp++ )
    4421       {
    4422         UInt uiRefIdxBitsTemp = 0;
    4423         if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0) > 1 )
    4424         {
    4425           uiRefIdxBitsTemp += iL0RefIdxTemp+1;
    4426           if ( iL0RefIdxTemp == pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0)-1 ) uiRefIdxBitsTemp--;
    4427         }
    4428         if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1) > 1 )
    4429         {
    4430           uiRefIdxBitsTemp += iL1RefIdxTemp+1;
    4431           if ( iL1RefIdxTemp == pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1)-1 ) uiRefIdxBitsTemp--;
    4432         }
    4433 
    4434         Int iL0MVPIdx = 0;
    4435         Int iL1MVPIdx = 0;
    4436 
    4437         for (iL0MVPIdx = 0; iL0MVPIdx < aaiMvpNum[0][iL0RefIdxTemp]; iL0MVPIdx++)
    4438         {
    4439           for (iL1MVPIdx = 0; iL1MVPIdx < aaiMvpNum[1][iL1RefIdxTemp]; iL1MVPIdx++)
    4440           {
    4441             uiZeroMvdBitsTemp = uiRefIdxBitsTemp;
    4442             uiZeroMvdBitsTemp += uiMbBits[2];
    4443             uiZeroMvdBitsTemp += m_auiMVPIdxCost[iL0MVPIdx][aaiMvpNum[0][iL0RefIdxTemp]] + m_auiMVPIdxCost[iL1MVPIdx][aaiMvpNum[1][iL1RefIdxTemp]];
    4444             uiZeroMvdBitsTemp += 4; //zero mvd for both directions
    4445             pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( aacAMVPInfo[0][iL0RefIdxTemp].m_acMvCand[iL0MVPIdx], iL0RefIdxTemp, ePartSize, uiPartAddr, iPartIdx, 0 );
    4446             pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( aacAMVPInfo[1][iL1RefIdxTemp].m_acMvCand[iL1MVPIdx], iL1RefIdxTemp, ePartSize, uiPartAddr, iPartIdx, 0 );
    4447  
    4448             xGetInterPredictionError( pcCU, pcOrgYuv, iPartIdx, uiZeroMvdDistTemp, m_pcEncCfg->getUseHADME() );
    4449             uiZeroMvdCostTemp = uiZeroMvdDistTemp + m_pcRdCost->getCost( uiZeroMvdBitsTemp );
    4450             if (uiZeroMvdCostTemp < uiZeroMvdCost)
    4451             {
    4452               uiZeroMvdCost = uiZeroMvdCostTemp;
    4453               iZeroMvdDir = 3;
    4454               aiZeroMvdMvpIdx[0] = iL0MVPIdx;
    4455               aiZeroMvdMvpIdx[1] = iL1MVPIdx;
    4456               aiZeroMvdRefIdx[0] = iL0RefIdxTemp;
    4457               aiZeroMvdRefIdx[1] = iL1RefIdxTemp;
    4458               auiZeroMvdBits[2] = uiZeroMvdBitsTemp;
    4459             }
    4460           }
    4461         }
    4462       }
    4463     }
     4462      }
    44644463#endif
    44654464
     
    44774476    pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    44784477    pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    4479    
     4478
    44804479    UInt uiMEBits = 0;
    44814480    // Set Motion Field_
     
    44894488#endif
    44904489#if ZERO_MVD_EST
    4491     if (uiZeroMvdCost <= uiCostBi && uiZeroMvdCost <= uiCost[0] && uiZeroMvdCost <= uiCost[1])
    4492     {
    4493       if (iZeroMvdDir == 3)
    4494       {
    4495         uiLastMode = 2;
    4496 
    4497         pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( aacAMVPInfo[0][aiZeroMvdRefIdx[0]].m_acMvCand[aiZeroMvdMvpIdx[0]], aiZeroMvdRefIdx[0], ePartSize, uiPartAddr, iPartIdx, 0 );
    4498         pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( aacAMVPInfo[1][aiZeroMvdRefIdx[1]].m_acMvCand[aiZeroMvdMvpIdx[1]], aiZeroMvdRefIdx[1], ePartSize, uiPartAddr, iPartIdx, 0 );
    4499  
    4500         pcCU->setInterDirSubParts( 3, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
    4501        
    4502         pcCU->setMVPIdxSubParts( aiZeroMvdMvpIdx[0], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    4503         pcCU->setMVPNumSubParts( aaiMvpNum[0][aiZeroMvdRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    4504         pcCU->setMVPIdxSubParts( aiZeroMvdMvpIdx[1], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    4505         pcCU->setMVPNumSubParts( aaiMvpNum[1][aiZeroMvdRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    4506         uiMEBits = auiZeroMvdBits[2];
    4507       }
    4508       else if (iZeroMvdDir == 1)
    4509       {       
    4510         uiLastMode = 0;
    4511 
    4512         pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( aacAMVPInfo[0][aiZeroMvdRefIdx[0]].m_acMvCand[aiZeroMvdMvpIdx[0]], aiZeroMvdRefIdx[0], ePartSize, uiPartAddr, iPartIdx, 0 );
    4513 
    4514         pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
    4515        
    4516         pcCU->setMVPIdxSubParts( aiZeroMvdMvpIdx[0], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    4517         pcCU->setMVPNumSubParts( aaiMvpNum[0][aiZeroMvdRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    4518         uiMEBits = auiZeroMvdBits[0];
    4519       }
    4520       else if (iZeroMvdDir == 2)
    4521       {
    4522         uiLastMode = 1;
    4523 
    4524         pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( aacAMVPInfo[1][aiZeroMvdRefIdx[1]].m_acMvCand[aiZeroMvdMvpIdx[1]], aiZeroMvdRefIdx[1], ePartSize, uiPartAddr, iPartIdx, 0 );
    4525 
    4526         pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
    4527        
    4528         pcCU->setMVPIdxSubParts( aiZeroMvdMvpIdx[1], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    4529         pcCU->setMVPNumSubParts( aaiMvpNum[1][aiZeroMvdRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    4530         uiMEBits = auiZeroMvdBits[1];
     4490      if (uiZeroMvdCost <= uiCostBi && uiZeroMvdCost <= uiCost[0] && uiZeroMvdCost <= uiCost[1])
     4491      {
     4492        if (iZeroMvdDir == 3)
     4493        {
     4494          uiLastMode = 2;
     4495
     4496          pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( aacAMVPInfo[0][aiZeroMvdRefIdx[0]].m_acMvCand[aiZeroMvdMvpIdx[0]], aiZeroMvdRefIdx[0], ePartSize, uiPartAddr, iPartIdx, 0 );
     4497          pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( aacAMVPInfo[1][aiZeroMvdRefIdx[1]].m_acMvCand[aiZeroMvdMvpIdx[1]], aiZeroMvdRefIdx[1], ePartSize, uiPartAddr, iPartIdx, 0 );
     4498
     4499          pcCU->setInterDirSubParts( 3, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
     4500
     4501          pcCU->setMVPIdxSubParts( aiZeroMvdMvpIdx[0], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     4502          pcCU->setMVPNumSubParts( aaiMvpNum[0][aiZeroMvdRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     4503          pcCU->setMVPIdxSubParts( aiZeroMvdMvpIdx[1], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     4504          pcCU->setMVPNumSubParts( aaiMvpNum[1][aiZeroMvdRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     4505          uiMEBits = auiZeroMvdBits[2];
     4506        }
     4507        else if (iZeroMvdDir == 1)
     4508        {       
     4509          uiLastMode = 0;
     4510
     4511          pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( aacAMVPInfo[0][aiZeroMvdRefIdx[0]].m_acMvCand[aiZeroMvdMvpIdx[0]], aiZeroMvdRefIdx[0], ePartSize, uiPartAddr, iPartIdx, 0 );
     4512
     4513          pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
     4514
     4515          pcCU->setMVPIdxSubParts( aiZeroMvdMvpIdx[0], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     4516          pcCU->setMVPNumSubParts( aaiMvpNum[0][aiZeroMvdRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     4517          uiMEBits = auiZeroMvdBits[0];
     4518        }
     4519        else if (iZeroMvdDir == 2)
     4520        {
     4521          uiLastMode = 1;
     4522
     4523          pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( aacAMVPInfo[1][aiZeroMvdRefIdx[1]].m_acMvCand[aiZeroMvdMvpIdx[1]], aiZeroMvdRefIdx[1], ePartSize, uiPartAddr, iPartIdx, 0 );
     4524
     4525          pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
     4526
     4527          pcCU->setMVPIdxSubParts( aiZeroMvdMvpIdx[1], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     4528          pcCU->setMVPNumSubParts( aaiMvpNum[1][aiZeroMvdRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     4529          uiMEBits = auiZeroMvdBits[1];
     4530        }
     4531        else
     4532        {
     4533          assert(0);
     4534        }
    45314535      }
    45324536      else
    4533       {
    4534         assert(0);
    4535       }
    4536     }
    4537     else
    4538 #endif
    4539     if ( uiCostBi <= uiCost[0] && uiCostBi <= uiCost[1])
    4540     {
    4541       uiLastMode = 2;
    4542             pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMvBi[0], ePartSize, uiPartAddr, 0, iPartIdx );
    4543             pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdxBi[0], ePartSize, uiPartAddr, 0, iPartIdx );
    4544             pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMvBi[1], ePartSize, uiPartAddr, 0, iPartIdx );
    4545             pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdxBi[1], ePartSize, uiPartAddr, 0, iPartIdx );
    4546      
    4547         TempMv = cMvBi[0] - cMvPredBi[0][iRefIdxBi[0]];
    4548             pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    4549      
    4550         TempMv = cMvBi[1] - cMvPredBi[1][iRefIdxBi[1]];
    4551             pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    4552      
    4553       pcCU->setInterDirSubParts( 3, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
    4554      
    4555       pcCU->setMVPIdxSubParts( aaiMvpIdxBi[0][iRefIdxBi[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    4556       pcCU->setMVPNumSubParts( aaiMvpNum[0][iRefIdxBi[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    4557       pcCU->setMVPIdxSubParts( aaiMvpIdxBi[1][iRefIdxBi[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    4558       pcCU->setMVPNumSubParts( aaiMvpNum[1][iRefIdxBi[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    4559 
    4560       uiMEBits = uiBits[2];
    4561     }
    4562     else if ( uiCost[0] <= uiCost[1] )
    4563     {
    4564       uiLastMode = 0;
     4537#endif
     4538        if ( uiCostBi <= uiCost[0] && uiCostBi <= uiCost[1])
     4539        {
     4540          uiLastMode = 2;
     4541          pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMvBi[0], ePartSize, uiPartAddr, 0, iPartIdx );
     4542          pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdxBi[0], ePartSize, uiPartAddr, 0, iPartIdx );
     4543          pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMvBi[1], ePartSize, uiPartAddr, 0, iPartIdx );
     4544          pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdxBi[1], ePartSize, uiPartAddr, 0, iPartIdx );
     4545
     4546          TempMv = cMvBi[0] - cMvPredBi[0][iRefIdxBi[0]];
     4547          pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
     4548
     4549          TempMv = cMvBi[1] - cMvPredBi[1][iRefIdxBi[1]];
     4550          pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
     4551
     4552          pcCU->setInterDirSubParts( 3, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
     4553
     4554          pcCU->setMVPIdxSubParts( aaiMvpIdxBi[0][iRefIdxBi[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     4555          pcCU->setMVPNumSubParts( aaiMvpNum[0][iRefIdxBi[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     4556          pcCU->setMVPIdxSubParts( aaiMvpIdxBi[1][iRefIdxBi[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     4557          pcCU->setMVPNumSubParts( aaiMvpNum[1][iRefIdxBi[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     4558
     4559          uiMEBits = uiBits[2];
     4560        }
     4561        else if ( uiCost[0] <= uiCost[1] )
     4562        {
     4563          uiLastMode = 0;
    45654564          pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMv[0], ePartSize, uiPartAddr, 0, iPartIdx );
    45664565          pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdx[0], ePartSize, uiPartAddr, 0, iPartIdx );
    4567         TempMv = cMv[0] - cMvPred[0][iRefIdx[0]];
    4568             pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    4569       pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
    4570      
    4571       pcCU->setMVPIdxSubParts( aaiMvpIdx[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    4572       pcCU->setMVPNumSubParts( aaiMvpNum[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    4573 
    4574       uiMEBits = uiBits[0];
    4575     }
    4576     else
    4577     {
    4578       uiLastMode = 1;
     4566          TempMv = cMv[0] - cMvPred[0][iRefIdx[0]];
     4567          pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
     4568          pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
     4569
     4570          pcCU->setMVPIdxSubParts( aaiMvpIdx[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     4571          pcCU->setMVPNumSubParts( aaiMvpNum[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     4572
     4573          uiMEBits = uiBits[0];
     4574        }
     4575        else
     4576        {
     4577          uiLastMode = 1;
    45794578          pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMv[1], ePartSize, uiPartAddr, 0, iPartIdx );
    45804579          pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdx[1], ePartSize, uiPartAddr, 0, iPartIdx );
    4581         TempMv = cMv[1] - cMvPred[1][iRefIdx[1]];
    4582             pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    4583       pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
    4584      
    4585       pcCU->setMVPIdxSubParts( aaiMvpIdx[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    4586       pcCU->setMVPNumSubParts( aaiMvpNum[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    4587 
    4588       uiMEBits = uiBits[1];
    4589     }
     4580          TempMv = cMv[1] - cMvPred[1][iRefIdx[1]];
     4581          pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
     4582          pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
     4583
     4584          pcCU->setMVPIdxSubParts( aaiMvpIdx[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     4585          pcCU->setMVPNumSubParts( aaiMvpNum[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     4586
     4587          uiMEBits = uiBits[1];
     4588        }
    45904589#if AMP_MRG
    45914590    } // end if bTestNormalMC
     
    46504649      xMergeEstimation( pcCU, pcOrgYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost, cMvFieldNeighbours, uhInterDirNeighbours
    46514650#if H_3D_VSP
    4652                       , vspFlag
    4653                       , inheritedVSPDisInfo
     4651        , vspFlag
     4652        , inheritedVSPDisInfo
    46544653#endif
    46554654#if H_3D_SPIVMP
    4656                       , bSPIVMPFlag, pcMvFieldSP, puhInterDirSP
     4655        , bSPIVMPFlag, pcMvFieldSP, puhInterDirSP
    46574656#endif
    4658                       , numValidMergeCand
    4659                       );
     4657        , numValidMergeCand
     4658        );
    46604659      if ( uiMRGCost < uiMECost )
    46614660      {
     
    46704669        if( uiMRGIndex == pcCU->getUseDDDCandIdx() )
    46714670        {
    4672             assert( vspFlag[uiMRGIndex]     == 0 );
    4673             assert( bSPIVMPFlag[uiMRGIndex] == 0 );
    4674             pcCU->setUseDDD( true, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    4675             pcCU->setDDDepthSubParts( pcCU->getDDTmpDepth(), uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
     4671          assert( vspFlag[uiMRGIndex]     == 0 );
     4672          assert( bSPIVMPFlag[uiMRGIndex] == 0 );
     4673          pcCU->setUseDDD( true, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
     4674          pcCU->setDDDepthSubParts( pcCU->getDDTmpDepth(), uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    46764675        }
    46774676        else
    46784677        {
    4679             pcCU->setUseDDD( false, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
     4678          pcCU->setUseDDD( false, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    46804679        }
    46814680#endif
     
    47054704#if NTT_STORE_SPDV_VSP_G0148
    47064705#if H_3D_DBBP
    4707         if ( vspFlag[uiMRGIndex] && !pcCU->getDBBPFlag(uiPartAddr) )
     4706          if ( vspFlag[uiMRGIndex] && !pcCU->getDBBPFlag(uiPartAddr) )
    47084707#else
    4709         if ( vspFlag[uiMRGIndex] )
    4710 #endif
    4711         {
    4712           UInt partAddrTemp;
    4713           Int vspSize;
    4714           Int width, height;
    4715           pcCU->getPartIndexAndSize( iPartIdx, partAddrTemp, width, height ); // true or pcCU->getTotalNumPart()==256
    4716           if( uiMRGInterDir & 0x01 )
     4708          if ( vspFlag[uiMRGIndex] )
     4709#endif
    47174710          {
    4718             pcCU->setMvFieldPUForVSP( pcCU, partAddrTemp, width, height, REF_PIC_LIST_0, cMRGMvField[0].getRefIdx(), vspSize );
    4719             pcCU->setVSPFlag( partAddrTemp, vspSize );
     4711            UInt partAddrTemp;
     4712            Int vspSize;
     4713            Int width, height;
     4714            pcCU->getPartIndexAndSize( iPartIdx, partAddrTemp, width, height ); // true or pcCU->getTotalNumPart()==256
     4715            if( uiMRGInterDir & 0x01 )
     4716            {
     4717              pcCU->setMvFieldPUForVSP( pcCU, partAddrTemp, width, height, REF_PIC_LIST_0, cMRGMvField[0].getRefIdx(), vspSize );
     4718              pcCU->setVSPFlag( partAddrTemp, vspSize );
     4719            }
     4720            else
     4721            {
     4722              pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMRGMvField[0], ePartSize, uiPartAddr, 0, iPartIdx );
     4723            }
     4724            if( uiMRGInterDir & 0x02 )
     4725            {
     4726              pcCU->setMvFieldPUForVSP( pcCU, partAddrTemp, width, height, REF_PIC_LIST_1, cMRGMvField[1].getRefIdx(), vspSize );
     4727              pcCU->setVSPFlag( partAddrTemp, vspSize );
     4728            }
     4729            else
     4730            {
     4731              pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMRGMvField[1], ePartSize, uiPartAddr, 0, iPartIdx );
     4732            }
     4733            pcCU->setInterDirSubParts  ( uiMRGInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    47204734          }
    47214735          else
     4736#if H_3D_FIX_G0148_BRACE
    47224737          {
    4723             pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMRGMvField[0], ePartSize, uiPartAddr, 0, iPartIdx );
    4724           }
    4725           if( uiMRGInterDir & 0x02 )
    4726           {
    4727             pcCU->setMvFieldPUForVSP( pcCU, partAddrTemp, width, height, REF_PIC_LIST_1, cMRGMvField[1].getRefIdx(), vspSize );
    4728             pcCU->setVSPFlag( partAddrTemp, vspSize );
    4729           }
    4730           else
    4731           {
    4732             pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMRGMvField[1], ePartSize, uiPartAddr, 0, iPartIdx );
    4733           }
    4734           pcCU->setInterDirSubParts  ( uiMRGInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    4735         }
    4736         else
    4737 #endif
    4738           pcCU->setInterDirSubParts  ( uiMRGInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
     4738#endif
     4739#endif
     4740            pcCU->setInterDirSubParts  ( uiMRGInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    47394741            pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMRGMvField[0], ePartSize, uiPartAddr, 0, iPartIdx );
    47404742            pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMRGMvField[1], ePartSize, uiPartAddr, 0, iPartIdx );
    4741 
    4742         pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( cMvZero,            ePartSize, uiPartAddr, 0, iPartIdx );
    4743         pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( cMvZero,            ePartSize, uiPartAddr, 0, iPartIdx );
    4744 
    4745         pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    4746         pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    4747         pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    4748         pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     4743#if H_3D_FIX_G0148_BRACE
     4744          }
     4745#endif
     4746          pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( cMvZero,            ePartSize, uiPartAddr, 0, iPartIdx );
     4747          pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( cMvZero,            ePartSize, uiPartAddr, 0, iPartIdx );
     4748
     4749          pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     4750          pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     4751          pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     4752          pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    47494753      }
    47504754      else
     
    47634767        pcCU->setDvInfoSubParts(OriginalDvInfo, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    47644768#endif
    4765           pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMEMvField[0], ePartSize, uiPartAddr, 0, iPartIdx );
    4766           pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMEMvField[1], ePartSize, uiPartAddr, 0, iPartIdx );
    4767         }
     4769        pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMEMvField[0], ePartSize, uiPartAddr, 0, iPartIdx );
     4770        pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMEMvField[1], ePartSize, uiPartAddr, 0, iPartIdx );
     4771      }
    47684772#if H_3D_SPIVMP
    47694773      delete[] pcMvFieldSP;
     
    47744778    //  MC
    47754779    motionCompensation ( pcCU, rpcPredYuv, REF_PIC_LIST_X, iPartIdx );
    4776    
     4780
    47774781  } //  end of for ( Int iPartIdx = 0; iPartIdx < iNumPart; iPartIdx++ )
    47784782
Note: See TracChangeset for help on using the changeset viewer.