Changeset 100 in 3DVCSoftware for trunk/source/Lib/TLibEncoder


Ignore:
Timestamp:
9 Aug 2012, 12:53:16 (13 years ago)
Author:
tech
Message:

Adopted modifications:

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

+ Clean ups + Bug fixes

Update of cfg files (A0033 modification 2)

Location:
trunk/source/Lib/TLibEncoder
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibEncoder/TEncCavlc.cpp

    r77 r100  
    378378Void TEncCavlc::codeVPS( TComVPS* pcVPS )
    379379{
    380         WRITE_CODE( pcVPS->getMaxTLayers() - 1,     3,        "max_temporal_layers_minus1" );
     380  WRITE_CODE( pcVPS->getMaxTLayers() - 1,     3,        "max_temporal_layers_minus1" );
    381381  WRITE_CODE( pcVPS->getMaxLayers() - 1,      5,        "max_layers_minus1" );
    382382  WRITE_FLAG( pcVPS->getTemporalNestingFlag() - 1,      "temporal_id_nesting_flag" );
     
    775775    {
    776776      WRITE_CODE( (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC()), pcSlice->getSPS()->getBitsForPOC(), "pic_order_cnt_lsb");
    777 #if HHI_FIX
    778777      if( pcSlice->getPOC() == 0 && pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDV )
    779778      {
     
    848847      }
    849848      if( pcSlice->getPOC() != 0 )
    850 #else
    851       if( pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDV )
    852 #endif
    853849      {
    854850        TComReferencePictureSet* rps = pcSlice->getRPS();
  • trunk/source/Lib/TLibEncoder/TEncCfg.h

    r77 r100  
    205205  UInt      m_uiVSOMode;
    206206#endif
     207#if SAIT_VSO_EST_A0033
     208  Bool      m_bUseEstimatedVSD;
     209  Double    m_dDispCoeff;
     210#endif
     211
    207212
    208213  //====== Tool list ========
     
    568573#endif
    569574
     575#if SAIT_VSO_EST_A0033
     576  Void      setUseEstimatedVSD              ( Bool  b )     { m_bUseEstimatedVSD = b; }
     577  Void      setDispCoeff                    ( Double  d )   { m_dDispCoeff  = d; }
     578#endif
     579
    570580  Void      setUseFastEnc                   ( Bool  b )     { m_bUseFastEnc = b; }
    571581  Void      setUseEarlyCU                   ( Bool  b )     { m_bUseEarlyCU = b; }
     
    608618  Bool      getUseVSO                       ()      { return m_bUseVSO;     }
    609619#endif
     620#if SAIT_VSO_EST_A0033
     621  Bool      getUseEstimatedVSD              ()      { return m_bUseEstimatedVSD; }
     622  Double    getDispCoeff                    ()      { return m_dDispCoeff;    }
     623#endif
     624
    610625  Bool      getUseFastEnc                   ()      { return m_bUseFastEnc; }
    611626  Bool      getUseEarlyCU                   ()      { return m_bUseEarlyCU; }
  • trunk/source/Lib/TLibEncoder/TEncCu.cpp

    r81 r100  
    11561156      if( m_pcRdCost->getUseRenModel() )
    11571157      {
    1158 #if HHI_FIX
    11591158        UInt  uiWidth     = m_ppcOrigYuv[uiDepth]->getWidth ( );
    11601159        UInt  uiHeight    = m_ppcOrigYuv[uiDepth]->getHeight( );
     
    11621161        UInt  uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride();
    11631162        m_pcRdCost->setRenModelData( m_ppcBestCU[uiDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    1164 #else
    1165         UInt  uiWidth     = m_ppcBestCU[uiDepth]->getWidth ( 0 );
    1166         UInt  uiHeight    = m_ppcBestCU[uiDepth]->getHeight( 0 );
    1167         Pel*  piSrc       = m_ppcOrigYuv[uiDepth]->getLumaAddr( 0 );
    1168         UInt  uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride();
    1169         m_pcRdCost->setRenModelData( m_ppcBestCU[uiDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    1170 #endif
    11711163      }
    11721164#endif
     
    12121204
    12131205#if HHI_VSO
     1206#if HHI_VSO_SET_OPTIM
     1207#else
    12141208          if( m_pcRdCost->getUseRenModel() ) // necessary ??
    12151209          {
    1216 #if HHI_FIX
    12171210            UInt  uiWidth     = m_ppcRecoYuvBest[uhNextDepth]->getWidth   (  );
    12181211            UInt  uiHeight    = m_ppcRecoYuvBest[uhNextDepth]->getHeight  (   );
     
    12201213            UInt  uiSrcStride = m_ppcRecoYuvBest[uhNextDepth]->getStride  (   );
    12211214            m_pcRdCost->setRenModelData( pcSubBestPartCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    1222 #else
    1223             UInt  uiWidth     = pcSubBestPartCU->getWidth ( 0 );
    1224             UInt  uiHeight    = pcSubBestPartCU->getHeight( 0 );
    1225             Pel*  piSrc       = m_ppcRecoYuvBest[pcSubBestPartCU->getDepth(0)]->getLumaAddr( 0 );
    1226             UInt  uiSrcStride = m_ppcRecoYuvBest[pcSubBestPartCU->getDepth(0)]->getStride();
    1227             m_pcRdCost->setRenModelData( pcSubBestPartCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    1228 #endif
    1229           }
     1215          }
     1216#endif
    12301217#endif
    12311218        }
     
    13691356  if( m_pcRdCost->getUseRenModel() )
    13701357  {
    1371 #if HHI_FIX
    13721358      UInt  uiWidth     = m_ppcRecoYuvBest[uiDepth]->getWidth   ( );
    13731359      UInt  uiHeight    = m_ppcRecoYuvBest[uiDepth]->getHeight  ( );
     
    13751361      UInt  uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride  ( );
    13761362      m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    1377 #else
    1378     UInt  uiWidth     = rpcBestCU->getWidth ( 0 );
    1379     UInt  uiHeight    = rpcBestCU->getHeight( 0 );
    1380     Pel*  piSrc       = m_ppcRecoYuvBest[uiDepth]->getLumaAddr( 0 );
    1381     UInt  uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride();
    1382     m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    1383 #endif
    13841363  }
    13851364#endif
     
    17471726  if( m_pcRdCost->getUseRenModel() )
    17481727  {
    1749 #if HHI_FIX
    17501728    UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth ( );
    17511729    UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight( );
     
    17531731    UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
    17541732    m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    1755 #else
    1756     UInt  uiWidth     = rpcTempCU->getWidth ( 0 );
    1757     UInt  uiHeight    = rpcTempCU->getHeight( 0 );
    1758     Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr( );
    1759     UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
    1760     m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    1761 #endif
    17621733  }
    17631734#endif
     
    18511822          if( m_pcRdCost->getUseRenModel() )
    18521823          { //Reset
    1853 #if HHI_FIX
    18541824            UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth    ();
    18551825            UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight   ();
     
    18571827            UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride   ();
    18581828            m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    1859 #else
    1860             UInt  uiWidth     = rpcTempCU->getWidth ( 0 );
    1861             UInt  uiHeight    = rpcTempCU->getHeight( 0 );
    1862             Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr( );
    1863             UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
    1864             m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    1865 #endif
    18661829          }
    18671830#endif
     
    19271890  if( m_pcRdCost->getUseRenModel() )
    19281891  {
    1929 #if HHI_FIX
    19301892    UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth ( );
    19311893    UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight( );
     
    19331895    UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
    19341896    m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    1935 #else
    1936     UInt  uiWidth     = rpcTempCU->getWidth ( 0 );
    1937     UInt  uiHeight    = rpcTempCU->getHeight( 0 );
    1938     Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr( );
    1939     UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
    1940     m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    1941 #endif
    19421897  }
    19431898#endif 
     
    20462001  if( m_pcRdCost->getUseRenModel() )
    20472002  {
    2048 #if HHI_FIX
    20492003    UInt  uiWidth     = m_ppcOrigYuv[uiDepth]->getWidth   ();
    20502004    UInt  uiHeight    = m_ppcOrigYuv[uiDepth]->getHeight  ();
     
    20522006    UInt  uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride  ();
    20532007    m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    2054 #else
    2055     UInt  uiWidth     = rpcTempCU->getWidth ( 0 );
    2056     UInt  uiHeight    = rpcTempCU->getHeight( 0 );
    2057     Pel*  piSrc       = m_ppcOrigYuv[uiDepth]->getLumaAddr( );
    2058     UInt  uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride();
    2059     m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    2060 #endif
    20612008  }
    20622009#endif
     
    25572504  if( m_pcRdCost->getUseRenModel() && !bRecursiveCall)
    25582505  {
    2559 #if HHI_FIX
    25602506    UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth   ();
    25612507    UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight  ();
     
    25632509    UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride  ();
    25642510    m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    2565 #else
    2566     UInt  uiWidth     = m_ppcTempCU [uhDepth]->getWidth ( 0 );
    2567     UInt  uiHeight    = m_ppcTempCU [uhDepth]->getHeight( 0 );
    2568     Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr( 0 );
    2569     UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
    2570     m_pcRdCost->setRenModelData( m_ppcTempCU[uhDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    2571 #endif
    25722511  }
    25732512#endif
     
    27172656  if( !bSplit && bRecursiveCall && m_pcRdCost->getUseRenModel() )
    27182657  {
    2719 #if HHI_FIX
    27202658    UInt  uiWidth     = m_ppcRecoYuvBest[uhDepth]->getWidth   (   );
    27212659    UInt  uiHeight    = m_ppcRecoYuvBest[uhDepth]->getHeight  (   );
     
    27232661    Pel*  piSrc       = m_ppcRecoYuvBest[uhDepth]->getLumaAddr( 0 );
    27242662    m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    2725 #else
    2726     UInt  uiWidth     = rpcBestCU->getWidth ( 0 );
    2727     UInt  uiHeight    = rpcBestCU->getHeight( 0 );
    2728     Pel*  piSrc       = m_ppcRecoYuvBest[uhDepth]->getLumaAddr( 0 );
    2729     UInt  uiSrcStride = m_ppcRecoYuvBest[uhDepth]->getStride();
    2730     m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    2731 #endif
    27322663  }
    27332664#endif
  • trunk/source/Lib/TLibEncoder/TEncEntropy.h

    r77 r100  
    7777
    7878#if VIDYO_VPS_INTEGRATION
    79         virtual Void  codeVPS                 ( TComVPS* pcVPS )                                      = 0;
    80 #endif
    81        
     79  virtual Void  codeVPS                 ( TComVPS* pcVPS )                                      = 0;
     80#endif
     81
    8282#if HHI_MPI
    8383  virtual Void  codeSPS                 ( TComSPS* pcSPS, Bool bIsDepth )                       = 0;
     
    234234public:
    235235#if VIDYO_VPS_INTEGRATION
    236         Void encodeVPS               ( TComVPS* pcVPS);
     236  Void encodeVPS               ( TComVPS* pcVPS);
    237237#endif
    238238  // SPS
  • trunk/source/Lib/TLibEncoder/TEncGOP.cpp

    r77 r100  
    436436  Bool bUseVSO = m_pcEncTop->getUseVSO();
    437437  m_pcRdCost->setUseVSO( bUseVSO );
     438#if SAIT_VSO_EST_A0033
     439  m_pcRdCost->setUseEstimatedVSD( m_pcEncTop->getUseEstimatedVSD() );
     440#endif
    438441
    439442  if ( bUseVSO )
     
    445448#endif
    446449
     450#if HHI_VSO_SPEEDUP_A033
     451#else
    447452    if ( iVSOMode == 4 )
    448453    {
     
    453458      AOT(true);
    454459    }
     460#endif
     461
     462#if SAIT_VSO_EST_A0033
     463    m_pcRdCost->setVideoRecPicYuv( m_pcEncTop->getEncTop()->xGetPicYuvFromViewTemp( pcSlice->getViewId(), pcSlice->getPOC(), false, true ) );
     464    m_pcRdCost->setDepthPicYuv   ( m_pcEncTop->getEncTop()->xGetPicYuvFromViewTemp( pcSlice->getViewId(), pcSlice->getPOC(), true, false ) );
     465#endif
     466
     467
    455468  }
    456469#endif
     
    691704      // init view component and predict virtual depth map
    692705      m_pcDepthMapGenerator->initViewComponent( pcPic );
     706#if !QC_MULTI_DIS_CAN
    693707      m_pcDepthMapGenerator->predictDepthMap  ( pcPic );
     708#endif
    694709#endif
    695710#if HHI_INTER_VIEW_MOTION_PRED
     
    758773#endif
    759774#if DEPTH_MAP_GENERATION
     775#if !QC_MULTI_DIS_CAN
    760776      // update virtual depth map
    761777      m_pcDepthMapGenerator->updateDepthMap( pcPic );
     778#endif
    762779#endif
    763780
     
    24752492    if( hasModification )
    24762493    {
    2477             Int temporalRefIdx = 0;
    2478             for( Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_0 ); i++ )
    2479             {
    2480               if( tempListEntryL0[i] >= 0 )
    2481               {
    2482                 refPicListModification->setRefPicSetIdxL0( i, tempListEntryL0[i] );
    2483               }
    2484               else
    2485               {
    2486                 refPicListModification->setRefPicSetIdxL0( i, temporalRefIdx );
    2487                 temporalRefIdx++;
    2488               }
    2489             }
    2490           }
     2494      Int temporalRefIdx = 0;
     2495      for( Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_0 ); i++ )
     2496      {
     2497        if( tempListEntryL0[i] >= 0 )
     2498        {
     2499          refPicListModification->setRefPicSetIdxL0( i, tempListEntryL0[i] );
     2500        }
     2501        else
     2502        {
     2503          refPicListModification->setRefPicSetIdxL0( i, temporalRefIdx );
     2504          temporalRefIdx++;
     2505        }
     2506      }
     2507    }
    24912508    else
    24922509    {
     
    25202537    if( hasModification )
    25212538    {
    2522             Int temporalRefIdx = 0;
    2523             for( Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_1 ); i++ )
    2524             {
    2525               if( tempListEntryL1[i] >= 0 )
    2526               {
    2527                 refPicListModification->setRefPicSetIdxL1( i, tempListEntryL1[i] );
    2528               }
    2529               else
    2530               {
    2531                 refPicListModification->setRefPicSetIdxL1( i, temporalRefIdx );
    2532                 temporalRefIdx++;
    2533               }
    2534             }
     2539      Int temporalRefIdx = 0;
     2540      for( Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_1 ); i++ )
     2541      {
     2542        if( tempListEntryL1[i] >= 0 )
     2543        {
     2544          refPicListModification->setRefPicSetIdxL1( i, tempListEntryL1[i] );
     2545        }
     2546        else
     2547        {
     2548          refPicListModification->setRefPicSetIdxL1( i, temporalRefIdx );
     2549          temporalRefIdx++;
     2550        }
     2551      }
    25352552    }
    25362553    else
  • trunk/source/Lib/TLibEncoder/TEncGOP.h

    r56 r100  
    137137 
    138138  Void  preLoopFilterPicAll  ( TComPic* pcPic, UInt64& ruiDist, UInt64& ruiBits );
     139#if HHI_VSO_SPEEDUP_A033
     140  TEncTop* getEncTop() { return m_pcEncTop; }
     141#endif
    139142 
    140143  TEncSlice*  getSliceEncoder()   { return m_pcSliceEncoder; }
  • trunk/source/Lib/TLibEncoder/TEncSbac.cpp

    r77 r100  
    106106, m_cDmmDataSCModel           ( 1,             1,               NUM_DMM_DATA_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    107107#endif
     108#if LGE_EDGE_INTRA
     109, m_cEdgeIntraSCModel         ( 1,             1,               NUM_EDGE_INTRA_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
     110#if LGE_EDGE_INTRA_DELTA_DC
     111, m_cEdgeIntraDeltaDCSCModel  ( 1,             1,               NUM_EDGE_INTRA_DELTA_DC_CTX   , m_contextModels + m_numContextModels, m_numContextModels)
     112#endif
     113#endif
    108114{
    109115  assert( m_numContextModels <= MAX_NUM_CTX_MOD );
     
    181187  m_cDmmDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_DATA );
    182188#endif
     189#if LGE_EDGE_INTRA
     190  m_cEdgeIntraSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_EDGE_INTRA );
     191#if LGE_EDGE_INTRA_DELTA_DC
     192  m_cEdgeIntraDeltaDCSCModel.initBuffer  ( eSliceType, iQp, (UChar*)INIT_EDGE_INTRA_DELTA_DC );
     193#endif
     194#endif
    183195
    184196  // new structure
     
    345357Void TEncSbac::codeVPS( TComVPS* pcVPS )
    346358{
    347         assert (0);
     359  assert (0);
    348360  return;
    349361}
     
    828840  DTRACE_CABAC_T( "\n" )
    829841}
     842
     843#if LGE_EDGE_INTRA
     844Void TEncSbac::xCodeEdgeIntraInfo( TComDataCU* pcCU, UInt uiPartIdx )
     845{
     846  UInt   uiDepth        = pcCU->getDepth( uiPartIdx ) + (pcCU->getPartitionSize( uiPartIdx ) == SIZE_NxN ? 1 : 0);
     847  UInt   uiCtxEdgeIntra = pcCU->getCtxEdgeIntra( uiPartIdx );
     848  UChar* pucSymbolList  = pcCU->getEdgeCode( uiPartIdx );
     849  UChar  ucEdgeNumber   = pcCU->getEdgeNumber( uiPartIdx );
     850  Bool   bLeft          = pcCU->getEdgeLeftFirst( uiPartIdx );
     851  UChar  ucStart        = pcCU->getEdgeStartPos( uiPartIdx );
     852  UInt   uiSymbol;
     853
     854  // 1. Top(0) or Left(1)
     855  uiSymbol = (bLeft == false) ? 0 : 1;
     856  m_pcBinIf->encodeBinEP( uiSymbol );
     857
     858  // 2. Start position (lowest bit first)
     859  uiSymbol = ucStart;
     860  for( UInt ui = 6; ui > uiDepth; ui-- ) // 64(0)->6, 32(1)->5, 16(2)->4, 8(3)->3, 4(4)->2
     861  {
     862    m_pcBinIf->encodeBinEP( uiSymbol & 0x1 );
     863    uiSymbol >>= 1;
     864  }
     865
     866  // 3. Number of edges
     867  uiSymbol = ucEdgeNumber > 0 ? ucEdgeNumber - 1 : 0;
     868  for( UInt ui = 7; ui > uiDepth; ui-- ) // 64(0)->7, 32(1)->6, 16(2)->5, 8(3)->4, 4(4)->3
     869  {
     870    m_pcBinIf->encodeBinEP( uiSymbol & 0x1 );
     871    uiSymbol >>= 1;
     872  }
     873
     874  if(uiSymbol != 0)
     875  {
     876    printf(" ucEdgeNumber %d at depth %d\n",ucEdgeNumber, uiDepth);
     877    assert(false);
     878  }
     879
     880  // 4. Edges
     881  for( Int iPtr2 = 0; iPtr2 < ucEdgeNumber; iPtr2++ )
     882  {
     883    UInt uiReorderSymbol = pucSymbolList[iPtr2];
     884
     885    //printf ("Ptr = %d, Symbol = %d\n", iPtr2, uiSymbol);
     886
     887    // Left-friendly direction (Top start)
     888    // 0 (   0deg) => 0
     889    // 1 (  45deg) => 10
     890    // 2 ( -45deg) => 110
     891    // 3 (  90deg) => 1110
     892    // 4 ( -90deg) => 11110
     893    // 5 ( 135deg) => 111110
     894    // 6 (-135deg) => 111111
     895    // Right-friendly direction (Left start)
     896    // 0 (   0deg) => 0
     897    // 2 ( -45deg) => 10
     898    // 1 (  45deg) => 110
     899    // 4 ( -90deg) => 1110
     900    // 3 (  90deg) => 11110
     901    // 6 (-135deg) => 111110
     902    // 5 ( 135deg) => 111111
     903
     904    // refer to a paper "An efficient chain code with Huffman coding"
     905
     906    for( UInt ui = 0; ui < uiReorderSymbol; ui++ )
     907    {
     908      m_pcBinIf->encodeBin( 1, m_cEdgeIntraSCModel.get( 0, 0, uiCtxEdgeIntra ) );
     909    }
     910
     911    if( uiReorderSymbol != 6 )
     912      m_pcBinIf->encodeBin( 0, m_cEdgeIntraSCModel.get( 0, 0, uiCtxEdgeIntra ) );
     913  }
     914}
     915#endif
     916
    830917Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx )
    831918{
     
    835922  if( pcCU->getSlice()->getSPS()->getUseDMM() && pcCU->getWidth( uiAbsPartIdx ) <= DMM_WEDGEMODEL_MAX_SIZE )
    836923  {
     924#if LGE_EDGE_INTRA
     925    m_pcBinIf->encodeBin( uiDir >= NUM_INTRA_MODE && uiDir < EDGE_INTRA_IDX, m_cDmmFlagSCModel.get(0, 0, 0) );
     926#else
    837927    m_pcBinIf->encodeBin( uiDir >= NUM_INTRA_MODE, m_cDmmFlagSCModel.get(0, 0, 0) );
    838   }
     928#endif
     929  }
     930#if LGE_EDGE_INTRA
     931  if( uiDir >= NUM_INTRA_MODE && uiDir < EDGE_INTRA_IDX )
     932#else
    839933  if( uiDir >= NUM_INTRA_MODE )
     934#endif
    840935  {
    841936    assert( pcCU->getWidth( uiAbsPartIdx ) <= DMM_WEDGEMODEL_MAX_SIZE );
     
    870965  }
    871966  else
     967#if LGE_EDGE_INTRA
     968    if ( uiDir >= EDGE_INTRA_IDX)
     969    {
     970      m_pcBinIf->encodeBin( 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) );
     971      m_pcBinIf->encodeBinsEP( 63, 6 );
     972      xCodeEdgeIntraInfo( pcCU, uiAbsPartIdx );
     973#if LGE_EDGE_INTRA_DELTA_DC
     974      m_pcBinIf->encodeBin( (uiDir == EDGE_INTRA_DELTA_IDX), m_cEdgeIntraDeltaDCSCModel.get(0, 0, 0) );
     975      if( uiDir == EDGE_INTRA_DELTA_IDX )
     976      {
     977        Int iDeltaDC0 = pcCU->getEdgeDeltaDC0( uiAbsPartIdx );
     978        Int iDeltaDC1 = pcCU->getEdgeDeltaDC1( uiAbsPartIdx );
     979
     980        xWriteExGolombLevel( UInt( abs( iDeltaDC0 ) ), m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) );
     981        if ( iDeltaDC0 != 0 )
     982        {
     983          UInt uiSign = iDeltaDC0 > 0 ? 0 : 1;
     984          m_pcBinIf->encodeBinEP( uiSign );
     985        }
     986        xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) );
     987        if ( iDeltaDC1 != 0 )
     988        {
     989          UInt uiSign = iDeltaDC1 > 0 ? 0 : 1;
     990          m_pcBinIf->encodeBinEP( uiSign );
     991        }
     992      }
     993#endif
     994    }
     995    else
     996#endif // LGE_EDGE_INTRA
    872997  {
    873998#endif
    874999#if !LOGI_INTRA_NAME_3MPM
    8751000  Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx);
     1001#endif
     1002#if LGE_EDGE_INTRA
     1003  Bool bCodeEdgeIntra = false;
     1004  if( pcCU->getSlice()->getSPS()->isDepth() )
     1005  {
     1006    UInt uiPUWidth = pcCU->getWidth( uiAbsPartIdx ) >> (pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 1 : 0);
     1007    if( uiPUWidth <= LGE_EDGE_INTRA_MAX_SIZE && uiPUWidth >= LGE_EDGE_INTRA_MIN_SIZE )
     1008      bCodeEdgeIntra = true;
     1009  }
    8761010#endif
    8771011 
     
    9321066#if LOGI_INTRA_NAME_3MPM
    9331067    m_pcBinIf->encodeBinsEP( uiDir, 5 );
     1068#if LGE_EDGE_INTRA
     1069  if (bCodeEdgeIntra)
     1070    if (uiDir == 31) m_pcBinIf->encodeBinsEP(0,1);
     1071#endif
    9341072#else
    9351073    if ( uiDir < 31 )
     
    22702408}
    22712409
    2272 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
     2410#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX || (LGE_EDGE_INTRA && LGE_EDGE_INTRA_DELTA_DC)
    22732411Void TEncSbac::xWriteExGolombLevel( UInt uiSymbol, ContextModel& rcSCModel  )
    22742412{
  • trunk/source/Lib/TLibEncoder/TEncSbac.h

    r77 r100  
    101101  Void  codeVPS                 ( TComVPS* pcVPS );
    102102#endif
    103        
     103 
    104104#if HHI_MPI
    105105  Void  codeSPS                 ( TComSPS* pcSPS, Bool bIsDepth );
     
    174174  Void  xCodeWedgePredTexDeltaInfo  ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    175175  Void  xCodeContourPredTexDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx );
     176#endif
     177#if LGE_EDGE_INTRA
     178  Void  xCodeEdgeIntraInfo( TComDataCU* pcCU, UInt uiPartIdx );
    176179#endif
    177180
     
    307310  ContextModel3DBuffer m_cDmmDataSCModel;
    308311#endif
     312#if LGE_EDGE_INTRA
     313  ContextModel3DBuffer m_cEdgeIntraSCModel;
     314#if LGE_EDGE_INTRA_DELTA_DC
     315  ContextModel3DBuffer m_cEdgeIntraDeltaDCSCModel;
     316#endif
     317#endif
    309318};
    310319
  • trunk/source/Lib/TLibEncoder/TEncSearch.cpp

    r81 r100  
    304304  // motion cost
    305305  uiSad += m_pcRdCost->getCost( iSearchX, iSearchY );
    306 #if HHI_FIX 
     306
    307307  // regularization cost
    308308  if( m_pcRdCost->useMultiviewReg() )
     
    310310    uiSad += m_pcRdCost->getMultiviewRegCost( iSearchX, iSearchY );
    311311  }
    312 #endif
    313312  if( uiSad < rcStruct.uiBestSad )
    314313  {
     
    957956                                TComYuv*    pcPredYuv,
    958957                                TComYuv*    pcResiYuv,
    959                                 Dist&       ruiDist )
     958                                Dist&       ruiDist
     959#if LG_ZEROINTRADEPTHRESI_M26039
     960                                ,Bool        bZeroResi
     961#endif
     962                                )
    960963{
    961964  UInt    uiLumaPredMode    = pcCU     ->getLumaIntraDir     ( uiAbsPartIdx );
     
    989992  pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth, m_piYuvExt, m_iYuvExtStride, m_iYuvExtHeight, bAboveAvail, bLeftAvail );
    990993 
     994#if LGE_EDGE_INTRA
     995  if( uiLumaPredMode >= EDGE_INTRA_IDX )
     996  {
     997#if LGE_EDGE_INTRA_DELTA_DC
     998    if( uiLumaPredMode == EDGE_INTRA_DELTA_IDX )
     999      xAssignEdgeIntraDeltaDCs( pcCU, uiAbsPartIdx, piOrg, uiStride, piPred, uiWidth, uiHeight );
     1000#endif
     1001
     1002    predIntraLumaEdge( pcCU, pcCU->getPattern(), uiAbsPartIdx, uiWidth, uiHeight, piPred, uiStride
     1003#if LGE_EDGE_INTRA_DELTA_DC
     1004     , uiLumaPredMode == EDGE_INTRA_DELTA_IDX
     1005#endif
     1006    );
     1007  }
     1008  else
     1009#endif
     1010 
    9911011  //===== get prediction signal =====
    9921012#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
     
    10201040    }
    10211041  }
     1042#if LG_ZEROINTRADEPTHRESI_M26039
     1043  if(bZeroResi)
     1044  {
     1045    Pel* pResi = piResi;
     1046
     1047    for( UInt uiY = 0; uiY < uiHeight; uiY++ )
     1048    {
     1049      memset( pResi, 0, sizeof( Pel ) * uiWidth );
     1050      pResi += uiStride;
     1051    }
     1052  }
     1053#endif
    10221054 
    10231055  //===== transform and quantization =====
     
    13111343                                Bool         bCheckFirst,
    13121344#endif
    1313                                 Double&      dRDCost )
     1345                                Double&      dRDCost
     1346#if LG_ZEROINTRADEPTHRESI_M26039
     1347                               ,Bool         bZeroResi
     1348#endif
     1349                              )
    13141350{
    13151351  UInt    uiFullDepth   = pcCU->getDepth( 0 ) +  uiTrDepth;
     
    13261362#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    13271363  if( pcCU->getLumaIntraDir( uiAbsPartIdx ) >= NUM_INTRA_MODE )
     1364  {
     1365    bCheckSplit = false;
     1366  }
     1367#endif
     1368#if LGE_EDGE_INTRA
     1369  if( pcCU->getLumaIntraDir( uiAbsPartIdx ) >= EDGE_INTRA_IDX )
    13281370  {
    13291371    bCheckSplit = false;
     
    13461388    //----- code luma block with given intra prediction mode and store Cbf-----
    13471389    dSingleCost   = 0.0;
     1390#if LG_ZEROINTRADEPTHRESI_M26039
     1391    xIntraCodingLumaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcOrgYuv, pcPredYuv, pcResiYuv, uiSingleDistY, bZeroResi );
     1392#else
    13481393    xIntraCodingLumaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcOrgYuv, pcPredYuv, pcResiYuv, uiSingleDistY );
     1394#endif
    13491395    if( bCheckSplit )
    13501396    {
     
    18081854    Int numModesForFullRD = g_aucIntraModeNumFast[ uiWidthBit ];
    18091855   
     1856#if LGE_EDGE_INTRA
     1857  Bool bTestEdgeIntra = false;
     1858  if ( m_pcEncCfg->isDepthCoder() && uiWidth >= LGE_EDGE_INTRA_MIN_SIZE && uiWidth <= LGE_EDGE_INTRA_MAX_SIZE && uiWidth == uiHeight )
     1859  {
     1860    bTestEdgeIntra = true;
     1861
     1862    Bool bEdgeExist;
     1863
     1864    bEdgeExist = xEdgePartition( pcCU, uiPartOffset, pcCU->getPartitionSize(0) == SIZE_NxN );
     1865
     1866    if( !bEdgeExist )
     1867      bTestEdgeIntra = false;
     1868  }
     1869#endif
     1870   
    18101871#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    18111872    Bool bTestDmm = ( m_pcEncCfg->getUseDMM() );
     
    18281889
    18291890        predIntraLumaAng( pcCU->getPattern(), uiMode, piPred, uiStride, uiWidth, uiHeight, pcCU, bAboveAvail, bLeftAvail );
    1830        
     1891
    18311892        // use hadamard transform here
    1832       Dist uiSad;
     1893        Dist uiSad;
    18331894#if HHI_VSO
    1834       if ( m_pcRdCost->getUseVSO() )
    1835       {
    1836         Bool bSad = !m_pcRdCost->getUseRenModel();
    1837         uiSad = m_pcRdCost->getDistVS(pcCU, uiPartOffset, piPred, uiStride, piOrg, uiStride, uiWidth, uiHeight, bSad, 0 );
    1838       }
    1839       else
    1840 #endif
    1841       {
    1842         uiSad = (Dist) m_pcRdCost->calcHAD( piOrg, uiStride, piPred, uiStride, uiWidth, uiHeight );
    1843       }
    1844        
     1895        if ( m_pcRdCost->getUseVSO() )
     1896        {
     1897#if SAIT_VSO_EST_A0033
     1898          if ( m_pcRdCost->getUseEstimatedVSD() )
     1899          {         
     1900            TComPicYuv* pcVirRec = m_pcRdCost->getVideoRecPicYuv();
     1901            TComPicYuv* pcVirOrg = m_pcRdCost->getDepthPicYuv();
     1902
     1903            uiSad = (Dist) ( m_pcRdCost->getDistPart( piPred, uiStride, piOrg, uiStride, pcVirRec->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()+uiPartOffset), pcVirOrg->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()+uiPartOffset), pcVirRec->getStride(), uiWidth, uiHeight ) );
     1904          }
     1905          else
     1906#endif
     1907          {         
     1908            Bool bSad = !m_pcRdCost->getUseRenModel();
     1909            uiSad = m_pcRdCost->getDistVS(pcCU, uiPartOffset, piPred, uiStride, piOrg, uiStride, uiWidth, uiHeight, bSad, 0 );
     1910          }
     1911
     1912        }
     1913        else
     1914#endif
     1915        {
     1916          uiSad = (Dist) m_pcRdCost->calcHAD( piOrg, uiStride, piPred, uiStride, uiWidth, uiHeight );
     1917        }
     1918
    18451919        UInt   iModeBits = xModeBitsIntra( pcCU, uiMode, uiPU, uiPartOffset, uiDepth, uiInitTrDepth );
    18461920
    1847       Double dLambda;
     1921        Double dLambda;
    18481922#if HHI_VSO
    1849       if ( m_pcRdCost->getUseLambdaScaleVSO() )
    1850       {
    1851         dLambda = m_pcRdCost->getUseRenModel() ? m_pcRdCost->getLambdaVSO() : m_pcRdCost->getSqrtLambdaVSO();
    1852         //GT: Sad is SSE for VSO4
    1853       }
    1854       else
    1855       {
     1923        if ( m_pcRdCost->getUseLambdaScaleVSO() )
     1924        {
     1925          dLambda = m_pcRdCost->getUseRenModel() ? m_pcRdCost->getLambdaVSO() : m_pcRdCost->getSqrtLambdaVSO();
     1926          //GT: Sad is SSE for VSO4
     1927        }
     1928        else
     1929        {
     1930          dLambda = m_pcRdCost->getSqrtLambda();
     1931        }
     1932#else
    18561933        dLambda = m_pcRdCost->getSqrtLambda();
    1857       }
    1858 #else
    1859       dLambda = m_pcRdCost->getSqrtLambda();
    1860 #endif
    1861 
    1862       Double cost = (Double)uiSad + (Double)iModeBits *  dLambda;
    1863        
     1934#endif
     1935
     1936        Double cost = (Double)uiSad + (Double)iModeBits *  dLambda;
     1937
    18641938        CandNum += xUpdateCandList( uiMode, cost, numModesForFullRD, uiRdModeList, CandCostList );
    18651939
    18661940#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    18671941        if( bTestDmm ) bTestDmm = uiSad ? true : false;
     1942#endif
     1943#if LGE_EDGE_INTRA
     1944        if ( bTestEdgeIntra ) bTestEdgeIntra = uiSad ? true : false;
    18681945#endif
    18691946      }
     
    19742051    }
    19752052#endif
     2053#if LGE_EDGE_INTRA
     2054  if( bTestEdgeIntra )
     2055  {
     2056    uiRdModeList[ numModesForFullRD++ ] = EDGE_INTRA_IDX;
     2057#if LGE_EDGE_INTRA_DELTA_DC
     2058    uiRdModeList[ numModesForFullRD++ ] = EDGE_INTRA_DELTA_IDX;
     2059#endif
     2060  }
     2061#endif
    19762062
    19772063    //===== check modes (using r-d costs) =====
     
    19872073    for( UInt uiMode = 0; uiMode < numModesForFullRD; uiMode++ )
    19882074    {
     2075#if LG_ZEROINTRADEPTHRESI_M26039
     2076    Bool bAllowZeroResi = pcCU->getSlice()->getIsDepth() && (pcCU->getSlice()->getPOC()%pcCU->getPic()->getIntraPeriod());// && (uiMode < NUM_INTRA_MODE);
     2077    for(UInt uiCnt = 0; uiCnt < (bAllowZeroResi ? 2 : 1); uiCnt++)
     2078    {
     2079      Bool bZeroResi = uiCnt ? true : false;
     2080#endif
    19892081      // set luma prediction mode
    19902082      UInt uiOrgMode = uiRdModeList[uiMode];
    1991      
     2083
    19922084#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    1993       if( m_pcEncCfg->getIsDepth() && !predIntraLumaDMMAvailable( uiOrgMode, uiWidth, uiHeight ) )
     2085      if( m_pcEncCfg->getIsDepth() && !predIntraLumaDMMAvailable( uiOrgMode, uiWidth, uiHeight )
     2086#if LGE_EDGE_INTRA
     2087        && uiOrgMode < EDGE_INTRA_IDX
     2088#endif
     2089        )
    19942090      {
    19952091        continue;
     
    20202116
    20212117#if HHI_RQT_INTRA_SPEEDUP
     2118#if LG_ZEROINTRADEPTHRESI_M26039
     2119      xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, true, dPUCost, bZeroResi );
     2120#else
    20222121      xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, true, dPUCost );
     2122#endif
    20232123#else
    20242124      xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, dPUCost );
     
    20522152        dSecondBestPUCost = dPUCost;
    20532153      }
     2154#endif
     2155#if LG_ZEROINTRADEPTHRESI_M26039
     2156    }
    20542157#endif
    20552158    } // Mode loop
     
    25792682      pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], ePartSize, uiAbsPartIdx, 0, iPUIdx );
    25802683#if LG_RESTRICTEDRESPRED_M24766
    2581           Int iAddResiShift;
    2582           UInt uiPartAddr;
    2583           Int iRoiWidth, iRoiHeight;
    2584 
    2585           pcCU->getPartIndexAndSize( iPUIdx, uiPartAddr, iRoiWidth, iRoiHeight );
    2586           iAddResiShift = pcCU->getResiPredMode(uiPartAddr);
    2587           iAddResiShift = (pcCU->getSlice()->getPPS()->getUseWP() || pcCU->getInterDir(uiPartAddr) != 3) ? (iAddResiShift >= 0 ? 0 : -1) : (iAddResiShift >= 0 ? 1 - iAddResiShift : -1);
    2588 
    2589           if( pcCU->getResPredFlag( 0 ))
    2590           { // subtract residual prediction from original in motion search
    2591                   if(iLastAddResiShift != iAddResiShift)
    2592                   {
    2593                           //add subtracted residual last time
    2594                           if(iLastAddResiShift >= 0)
    2595                           {
    2596                                   iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iLastAddResiShift;
    2597                                   pcYuvOrg->add(iPUResiPredShift, ePartSize, rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
    2598                           }
    2599                           //subtract residual
    2600                           if(iAddResiShift >= 0)
    2601                           {
    2602                                   iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iAddResiShift;
    2603                                   pcYuvOrg->add(iPUResiPredShift, ePartSize, rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ), true );
    2604                           }
    2605                           iLastAddResiShift = iAddResiShift;
    2606                   }
    2607           }
     2684      Int iAddResiShift;
     2685      UInt uiPartAddr;
     2686      Int iRoiWidth, iRoiHeight;
     2687
     2688      pcCU->getPartIndexAndSize( iPUIdx, uiPartAddr, iRoiWidth, iRoiHeight );
     2689      iAddResiShift = pcCU->getResiPredMode(uiPartAddr);
     2690      iAddResiShift = (pcCU->getSlice()->getPPS()->getUseWP() || pcCU->getInterDir(uiPartAddr) != 3) ? (iAddResiShift >= 0 ? 0 : -1) : (iAddResiShift >= 0 ? 1 - iAddResiShift : -1);
     2691
     2692      if( pcCU->getResPredFlag( 0 ))
     2693      { // subtract residual prediction from original in motion search
     2694        if(iLastAddResiShift != iAddResiShift)
     2695        {
     2696          //add subtracted residual last time
     2697          if(iLastAddResiShift >= 0)
     2698          {
     2699            iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iLastAddResiShift;
     2700            pcYuvOrg->add(iPUResiPredShift, ePartSize, rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
     2701          }
     2702          //subtract residual
     2703          if(iAddResiShift >= 0)
     2704          {
     2705            iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iAddResiShift;
     2706            pcYuvOrg->add(iPUResiPredShift, ePartSize, rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ), true );
     2707          }
     2708          iLastAddResiShift = iAddResiShift;
     2709        }
     2710      }
    26082711#endif
    26092712      xGetInterPredictionError( pcCU, pcYuvOrg, iPUIdx, uiCostCand, m_pcEncCfg->getUseHADME() );
     
    26312734  if( pcCU->getResPredFlag( 0 ) && iLastAddResiShift >= 0)
    26322735  {
    2633           iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iLastAddResiShift;
    2634           pcYuvOrg->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
     2736    iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iLastAddResiShift;
     2737    pcYuvOrg->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
    26352738  }
    26362739#endif
     
    27552858    UInt          uiBitsTempL0[MAX_NUM_REF];
    27562859#if LG_RESTRICTEDRESPRED_M24766
    2757         Int iPUResiPredShift[4] = {0, 0, 0, 0};
     2860    Int iPUResiPredShift[4] = {0, 0, 0, 0};
    27582861#endif
    27592862    xGetBlkBits( ePartSize, pcCU->getSlice()->isInterP(), iPartIdx, uiLastMode, uiMbBits);
     
    27732876#endif
    27742877#if LG_RESTRICTEDRESPRED_M24766
    2775                 Bool bLastResiFlag = false;
     2878      Bool bLastResiFlag = false;
    27762879#endif
    27772880    //  Uni-directional prediction
     
    27832886      {
    27842887#if LG_RESTRICTEDRESPRED_M24766
    2785                   if( pcCU->getResPredFlag( 0 ))
    2786                   {
    2787                           if(pcCU->getSlice()->getViewId() == pcCU->getSlice()->getRefViewId(eRefPicList, iRefIdxTemp))
    2788                           { // subtract residual prediction from original in motion search
    2789                                   if(!bLastResiFlag)
    2790                                           pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ), true );
    2791                                   bLastResiFlag = true;
    2792                           }
    2793                           else
    2794                           {
    2795                                   if(bLastResiFlag)
    2796                                           pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
    2797                                   bLastResiFlag = false;
    2798                           }
    2799                   }
     2888        if( pcCU->getResPredFlag( 0 ))
     2889        {
     2890          if(pcCU->getSlice()->getViewId() == pcCU->getSlice()->getRefViewId(eRefPicList, iRefIdxTemp))
     2891          { // subtract residual prediction from original in motion search
     2892            if(!bLastResiFlag)
     2893              pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ), true );
     2894            bLastResiFlag = true;
     2895          }
     2896          else
     2897          {
     2898            if(bLastResiFlag)
     2899              pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
     2900            bLastResiFlag = false;
     2901          }
     2902        }
    28002903#endif
    28012904        uiBitsTemp = uiMbBits[iRefList];
     
    29633066    }
    29643067#if LG_RESTRICTEDRESPRED_M24766
    2965         if( pcCU->getResPredFlag( 0 ) && bLastResiFlag)
    2966         { // subtract residual prediction from original in motion search
    2967                 pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
    2968         }
     3068    if( pcCU->getResPredFlag( 0 ) && bLastResiFlag)
     3069    { // subtract residual prediction from original in motion search
     3070      pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
     3071    }
    29693072#endif
    29703073    //  Bi-directional prediction
     
    29723075    {
    29733076#if LG_RESTRICTEDRESPRED_M24766
    2974                 Int iLastAddResiShift = -1000;
     3077      Int iLastAddResiShift = -1000;
    29753078#endif
    29763079      cMvBi[0] = cMv[0];            cMvBi[1] = cMv[1];
     
    30773180#endif
    30783181#if LG_RESTRICTEDRESPRED_M24766
    3079                   Int iAddResiShift = -1, iPredFrom = 0;
    3080                   Int iBestRefIdx = pcCU->getCUMvField(eRefPicList == REF_PIC_LIST_0 ? REF_PIC_LIST_1 : REF_PIC_LIST_0)->getRefIdx(uiPartAddr);
    3081 
    3082                   iPredFrom = iBestRefIdx >= 0 ? 3 : 1;
    3083                   if(iBestRefIdx >= 0 && pcCU->getSlice()->getViewId() == pcCU->getSlice()->getRefViewId(eRefPicList == REF_PIC_LIST_0 ? REF_PIC_LIST_1 : REF_PIC_LIST_0, iBestRefIdx))
    3084                           iAddResiShift++;
    3085                   if(pcCU->getSlice()->getViewId() == pcCU->getSlice()->getRefViewId(eRefPicList, iRefIdxTemp))
    3086                           iAddResiShift++;
    3087                   iAddResiShift = (pcCU->getSlice()->getPPS()->getUseWP() || iPredFrom != 3) ? (iAddResiShift >= 0 ? 0 : -1) : (iAddResiShift >= 0 ? 1-iAddResiShift : -1);
    3088 
    3089                   if( pcCU->getResPredFlag( 0 ) )
    3090                   {
    3091                           if(iLastAddResiShift != iAddResiShift)
    3092                           {
    3093                                   //add substracted residual last time
    3094                                   if(iLastAddResiShift >= 0 )
    3095                                   {
    3096                                           iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iLastAddResiShift;
    3097                                           pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
    3098                                   }
    3099                                   //substract residual
    3100                                   if(iAddResiShift >= 0)
    3101                                   {
    3102                                           iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iAddResiShift;
    3103                                           pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ), true );
    3104                                   }
    3105                                   iLastAddResiShift = iAddResiShift;
    3106                           }
    3107                   }
     3182          Int iAddResiShift = -1, iPredFrom = 0;
     3183          Int iBestRefIdx = pcCU->getCUMvField(eRefPicList == REF_PIC_LIST_0 ? REF_PIC_LIST_1 : REF_PIC_LIST_0)->getRefIdx(uiPartAddr);
     3184
     3185          iPredFrom = iBestRefIdx >= 0 ? 3 : 1;
     3186          if(iBestRefIdx >= 0 && pcCU->getSlice()->getViewId() == pcCU->getSlice()->getRefViewId(eRefPicList == REF_PIC_LIST_0 ? REF_PIC_LIST_1 : REF_PIC_LIST_0, iBestRefIdx))
     3187            iAddResiShift++;
     3188          if(pcCU->getSlice()->getViewId() == pcCU->getSlice()->getRefViewId(eRefPicList, iRefIdxTemp))
     3189            iAddResiShift++;
     3190          iAddResiShift = (pcCU->getSlice()->getPPS()->getUseWP() || iPredFrom != 3) ? (iAddResiShift >= 0 ? 0 : -1) : (iAddResiShift >= 0 ? 1-iAddResiShift : -1);
     3191
     3192          if( pcCU->getResPredFlag( 0 ) )
     3193          {
     3194            if(iLastAddResiShift != iAddResiShift)
     3195            {
     3196              //add substracted residual last time
     3197              if(iLastAddResiShift >= 0 )
     3198              {
     3199                iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iLastAddResiShift;
     3200                pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
     3201              }
     3202              //substract residual
     3203              if(iAddResiShift >= 0)
     3204              {
     3205                iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iAddResiShift;
     3206                pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ), true );
     3207              }
     3208              iLastAddResiShift = iAddResiShift;
     3209            }
     3210          }
    31083211#endif
    31093212          // call ME
     
    31623265      } // for loop-iter
    31633266#if LG_RESTRICTEDRESPRED_M24766
    3164           if( pcCU->getResPredFlag( 0 ) && iLastAddResiShift >= 0)
    3165           {
    3166                   iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iLastAddResiShift;
    3167                   pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
    3168           }
     3267      if( pcCU->getResPredFlag( 0 ) && iLastAddResiShift >= 0)
     3268      {
     3269        iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iLastAddResiShift;
     3270        pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
     3271      }
    31693272#endif
    31703273    } // if (B_SLICE)
     
    33753478      {
    33763479#if LG_RESTRICTEDRESPRED_M24766
    3377                   Int iAddResiShift = pcCU->getResiPredMode(uiPartAddr);
    3378                   iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = \
    3379                           (pcCU->getSlice()->getPPS()->getUseWP() || pcCU->getInterDir(uiPartAddr) != 3)? (iAddResiShift >= 0 ? 0 : -1) : (iAddResiShift >= 0 ? 1-iAddResiShift : -1);
    3380                   if(pcCU->getResPredFlag(0) && iAddResiShift >= 0)
    3381                   {
    3382                           pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ), true);
    3383                   }
     3480        Int iAddResiShift = pcCU->getResiPredMode(uiPartAddr);
     3481        iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = \
     3482          (pcCU->getSlice()->getPPS()->getUseWP() || pcCU->getInterDir(uiPartAddr) != 3)? (iAddResiShift >= 0 ? 0 : -1) : (iAddResiShift >= 0 ? 1-iAddResiShift : -1);
     3483        if(pcCU->getResPredFlag(0) && iAddResiShift >= 0)
     3484        {
     3485          pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ), true);
     3486        }
    33843487#endif
    33853488        xGetInterPredictionError( pcCU, pcOrgYuv, iPartIdx, uiMEError, m_pcEncCfg->getUseHADME() );
    33863489        uiMECost = uiMEError + m_pcRdCost->getCost( uiMEBits );
    33873490#if LG_RESTRICTEDRESPRED_M24766
    3388                 if(pcCU->getResPredFlag(0) && iAddResiShift >= 0)
    3389                 {
    3390                         pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
    3391                 }
     3491        if(pcCU->getResPredFlag(0) && iAddResiShift >= 0)
     3492        {
     3493          pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
     3494        }
    33923495#endif
    33933496      }
     
    38713974  else
    38723975  {
    3873 #if HHI_FIX
    38743976    rcMv = ( m_pcRdCost->useMultiviewReg() ? m_pcRdCost->getMultiviewOrgMvPred() : *pcMvPred );
    3875 #else
    3876     rcMv = *pcMvPred;
    3877 #endif
    38783977    xPatternSearchFast  ( pcCU, pcPatternKey, piRefY, iRefStride, &cMvSrchRngLT, &cMvSrchRngRB, rcMv, ruiCost );
    38793978  }
     
    39774076      uiSad += m_pcRdCost->getCost( x, y );
    39784077     
    3979 #if HHI_FIX
    39804078      // regularization cost
    39814079      if( m_pcRdCost->useMultiviewReg() )
     
    39834081        uiSad += m_pcRdCost->getMultiviewRegCost( x, y );
    39844082      }
    3985 #endif
    39864083
    39874084      if ( uiSad < uiSadBest )
     
    42814378    {
    42824379#if LG_RESTRICTEDRESPRED_M24766
    4283                 pcCU->getPUResiPredShift(iPUResiPredShift, 0);
    4284                 rpcYuvRec->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcYuvResPrd, uiWidth, uiHeight );
     4380      pcCU->getPUResiPredShift(iPUResiPredShift, 0);
     4381      rpcYuvRec->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcYuvResPrd, uiWidth, uiHeight );
    42854382#else
    42864383      rpcYuvRec->add( rpcYuvResPrd, uiWidth, uiHeight );
     
    42944391    {
    42954392      uiDistortion = m_pcRdCost->getDistVS( pcCU, 0, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(),  pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(),  uiWidth,      uiHeight     , false, 0 );
    4296         }
     4393    }
    42974394    else   
    42984395    {
     
    43494446    pcCU->setTrIdxSubParts( 0, 0, pcCU->getDepth(0) );
    43504447   
     4448
    43514449#if HHI_VSO // necessary?
    43524450    // set Model
     4451#if SAIT_VSO_EST_A0033
     4452    if( !m_pcRdCost->getUseEstimatedVSD()&& m_pcRdCost->getUseRenModel() )
     4453#else
    43534454    if( m_pcRdCost->getUseRenModel() )
     4455#endif
    43544456    {
    43554457      Pel*  piSrc       = rpcYuvRec->getLumaAddr();
     
    43954497  {
    43964498#if LG_RESTRICTEDRESPRED_M24766
    4397           iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = 0;
    4398           rpcYuvResi->subtract(iPUResiPredShift, pcCU->getPartitionSize(0), pcYuvOrg, pcYuvPred, 0, uiWidth );
     4499    iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = 0;
     4500    rpcYuvResi->subtract(iPUResiPredShift, pcCU->getPartitionSize(0), pcYuvOrg, pcYuvPred, 0, uiWidth );
    43994501#else
    44004502  rpcYuvResi->subtract( pcYuvOrg, pcYuvPred, 0, uiWidth );
     
    44054507    {
    44064508#if LG_RESTRICTEDRESPRED_M24766
    4407                 pcCU->getPUResiPredShift(iPUResiPredShift, 0);
    4408                 rpcYuvResi->subtract(iPUResiPredShift, pcCU->getPartitionSize(0), rpcYuvResi, rpcYuvResPrd, 0, uiWidth );
     4509      pcCU->getPUResiPredShift(iPUResiPredShift, 0);
     4510      rpcYuvResi->subtract(iPUResiPredShift, pcCU->getPartitionSize(0), rpcYuvResi, rpcYuvResPrd, 0, uiWidth );
    44094511#else
    44104512      rpcYuvResi->subtract( rpcYuvResi, rpcYuvResPrd, 0, uiWidth );
     
    45794681    }
    45804682
     4683
    45814684#if HHI_VSO
    4582     // GT: reset Model, only fordQP necessary??
     4685#if SAIT_VSO_EST_A0033   
     4686    if( m_pcRdCost->getUseRenModel() && !m_pcRdCost->getUseEstimatedVSD() )
     4687#else
    45834688    if( m_pcRdCost->getUseRenModel() )
     4689#endif
    45844690    {
    45854691      Pel*  piSrc       = pcYuvOrg->getLumaAddr();
     
    46244730    pcYuvPred->copyToPartYuv( rpcYuvRec, 0 );
    46254731#if LG_RESTRICTEDRESPRED_M24766
    4626         pcCU->getPUResiPredShift(iPUResiPredShift, 0);
    4627         rpcYuvRec->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcYuvResPrd,   uiWidth, uiHeight );
    4628         iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = 0;
     4732    pcCU->getPUResiPredShift(iPUResiPredShift, 0);
     4733    rpcYuvRec->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcYuvResPrd,   uiWidth, uiHeight );
     4734    iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = 0;
    46294735    rpcYuvRec->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcYuvResiBest, uiWidth, uiHeight );
    46304736#else
     
    46854791
    46864792  // set Model
     4793
    46874794#if HHI_VSO // necessary??
     4795#if SAIT_VSO_EST_A0033   
     4796  if( m_pcRdCost->getUseRenModel() && !m_pcRdCost->getUseEstimatedVSD() )
     4797#else
    46884798  if( m_pcRdCost->getUseRenModel() )
     4799#endif
    46894800  {
    46904801    Pel*  piSrc       = rpcYuvRec->getLumaAddr();
     
    46934804}
    46944805#endif
    4695 
    46964806}
    46974807
     
    48694979    if ( m_pcRdCost->getUseVSO() )
    48704980    {
    4871       uiDistY = m_pcRdCost->getDistVS  ( pcCU, uiAbsPartIdx, pcPred->getLumaAddr( uiAbsPartIdx ), pcPred->getStride(), pcOrg->getLumaAddr( uiAbsPartIdx), pcOrg->getStride(), 1<< uiLog2TrSize, 1<< uiLog2TrSize, false, 0 ); // initialized with zero residual distortion
     4981#if SAIT_VSO_EST_A0033
     4982      if( m_pcRdCost->getUseEstimatedVSD() )
     4983      {
     4984        TComPicYuv* pcVirRec = m_pcRdCost->getVideoRecPicYuv();
     4985        TComPicYuv* pcVirOrg = m_pcRdCost->getDepthPicYuv();
     4986        uiDistY = m_pcRdCost->getDistPart( m_pTempPel, 1<< uiLog2TrSize, pcResi->getLumaAddr( uiAbsPartIdx ), pcResi->getStride(), pcVirRec->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()+uiAbsPartIdx), pcVirOrg->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()+uiAbsPartIdx), pcVirRec->getStride(), 1<< uiLog2TrSize, 1<< uiLog2TrSize );
     4987      }
     4988      else
     4989#endif
     4990      {     
     4991        uiDistY = m_pcRdCost->getDistVS  ( pcCU, uiAbsPartIdx, pcPred->getLumaAddr( uiAbsPartIdx ), pcPred->getStride(), pcOrg->getLumaAddr( uiAbsPartIdx), pcOrg->getStride(), 1<< uiLog2TrSize, 1<< uiLog2TrSize, false, 0 ); // initialized with zero residual distortion
     4992      }
    48724993    }
    48734994    else
     
    48805001#endif
    48815002    }
    4882 
    48835003
    48845004    if ( puiZeroDist )
     
    49095029      if ( m_pcRdCost->getUseVSO() )
    49105030      {
    4911         static int iCount = 1;
    4912         iCount++;
    4913         m_cYuvRecTemp.addClipPartLuma( &m_pcQTTempTComYuv[uiQTTempAccessLayer], pcPred, uiAbsPartIdx, 1<< uiLog2TrSize  );
    4914         uiNonzeroDistY = m_pcRdCost->getDistVS( pcCU, uiAbsPartIdx, m_cYuvRecTemp.getLumaAddr(uiAbsPartIdx), m_cYuvRecTemp.getStride(),
    4915                                                 pcOrg->getLumaAddr( uiAbsPartIdx ), pcOrg->getStride(), 1<< uiLog2TrSize,   1<< uiLog2TrSize, false, 0 );
     5031#if SAIT_VSO_EST_A0033
     5032        if ( m_pcRdCost->getUseEstimatedVSD() )
     5033        {         
     5034          TComPicYuv* pcVirRec = m_pcRdCost->getVideoRecPicYuv();
     5035          TComPicYuv* pcVirOrg = m_pcRdCost->getDepthPicYuv();
     5036          uiNonzeroDistY = m_pcRdCost->getDistPart( m_pcQTTempTComYuv[uiQTTempAccessLayer].getLumaAddr( uiAbsPartIdx ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(), pcResi->getLumaAddr( uiAbsPartIdx ), pcResi->getStride(), pcVirRec->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiAbsPartIdx ), pcVirOrg->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiAbsPartIdx ), pcVirRec->getStride(), 1<< uiLog2TrSize,    1<< uiLog2TrSize );
     5037        }
     5038        else
     5039#endif
     5040        {       
     5041          m_cYuvRecTemp.addClipPartLuma( &m_pcQTTempTComYuv[uiQTTempAccessLayer], pcPred, uiAbsPartIdx, 1<< uiLog2TrSize  );
     5042          uiNonzeroDistY = m_pcRdCost->getDistVS( pcCU, uiAbsPartIdx, m_cYuvRecTemp.getLumaAddr(uiAbsPartIdx), m_cYuvRecTemp.getStride(),
     5043                                                  pcOrg->getLumaAddr( uiAbsPartIdx ), pcOrg->getStride(), 1<< uiLog2TrSize,   1<< uiLog2TrSize, false, 0 );
     5044        }
    49165045      }
    49175046      else
     
    53075436  }
    53085437
     5438
    53095439#if HHI_VSO
     5440#if SAIT_VSO_EST_A0033
     5441  if( m_pcRdCost->getUseRenModel() && !m_pcRdCost->getUseEstimatedVSD() )
     5442#else
    53105443  if ( m_pcRdCost->getUseRenModel() ) //Only done if not split ( see return above )
     5444#endif
    53115445  {
    53125446    UInt  uiWidth     = 1<< uiLog2TrSize;
     
    59776111
    59786112        assignWedgeDCs2Pred( pcWedgelet, piPredic, uiStride, iTestDC1, iTestDC2 );
    5979 
    5980         Dist uiActDist = m_pcRdCost->getDistVS( pcCU, 0, piPredic, uiStride,  piOrig, uiStride, uiWidth, uiHeight, false, 0 );
     6113       
     6114        Dist uiActDist = RDO_DIST_MAX;
     6115#if SAIT_VSO_EST_A0033
     6116        if ( m_pcRdCost->getUseEstimatedVSD() )
     6117        {         
     6118          TComPicYuv* pcVirRec = m_pcRdCost->getVideoRecPicYuv();
     6119          TComPicYuv* pcVirOrg = m_pcRdCost->getDepthPicYuv();
     6120          uiActDist = m_pcRdCost->getDistPart( piPredic, uiStride, piOrig, uiStride, pcVirRec->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()), pcVirOrg->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()), pcVirRec->getStride(), uiWidth, uiHeight );
     6121        }
     6122        else       
     6123#else
     6124        {       
     6125          uiActDist = m_pcRdCost->getDistVS( pcCU, 0, piPredic, uiStride,  piOrig, uiStride, uiWidth, uiHeight, false, 0 );
     6126        }
     6127#endif
     6128
    59816129        if( uiActDist < uiBestDist || uiBestDist == RDO_DIST_MAX )
    59826130        {
     
    60786226    if( m_pcRdCost->getUseVSO() )
    60796227    {
    6080       uiActDist = m_pcRdCost->getDistVS( pcCU, 0, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false, 0 );
     6228#if SAIT_VSO_EST_A0033
     6229      if ( m_pcRdCost->getUseEstimatedVSD() )
     6230      {         
     6231        TComPicYuv* pcVirRec = m_pcRdCost->getVideoRecPicYuv();
     6232        TComPicYuv* pcVirOrg = m_pcRdCost->getDepthPicYuv();
     6233        uiActDist = m_pcRdCost->getDistPart( piPred, uiPredStride, piRef, uiRefStride, pcVirRec->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()), pcVirOrg->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()), pcVirRec->getStride(), uiWidth, uiHeight );
     6234      }
     6235      else
     6236#endif
     6237      {     
     6238        uiActDist = m_pcRdCost->getDistVS( pcCU, 0, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false, 0 );
     6239      }
    60816240    }
    60826241    else
     
    61336292    if( m_pcRdCost->getUseVSO() )
    61346293    {
    6135       uiActDist = m_pcRdCost->getDistVS( pcCU, 0, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false, 0 );
     6294#if SAIT_VSO_EST_A0033
     6295      if ( m_pcRdCost->getUseEstimatedVSD() )
     6296      {         
     6297        TComPicYuv* pcVirRec = m_pcRdCost->getVideoRecPicYuv();
     6298        TComPicYuv* pcVirOrg = m_pcRdCost->getDepthPicYuv();
     6299        uiActDist = m_pcRdCost->getDistPart( piPred, uiPredStride, piRef, uiRefStride, pcVirRec->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()+uiAbsPtIdx), pcVirOrg->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()+uiAbsPtIdx), pcVirRec->getStride(), uiWidth, uiHeight );
     6300      }
     6301      else
     6302#endif
     6303      {     
     6304        uiActDist = m_pcRdCost->getDistVS( pcCU, 0, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false, 0 );
     6305      }
    61366306    }
    61376307    else
     
    62076377}
    62086378#endif
     6379
     6380#if LGE_EDGE_INTRA
     6381Bool TEncSearch::xCheckTerminatedEdge( Bool* pbEdge, Int iX, Int iY, Int iWidth, Int iHeight )
     6382{
     6383  if( (iY % 2) == 0 ) // vertical edge
     6384  {
     6385    Bool bTopConnected = false;
     6386    Bool bBottomConnected = false;
     6387
     6388    if( iY != 0 )
     6389    {
     6390      if( pbEdge[ iX + (iY - 2) * 2 * iWidth ] )
     6391        bTopConnected = true;
     6392      if( pbEdge[ (iX - 1) + (iY - 1) * 2 * iWidth ] )
     6393        bTopConnected = true;
     6394      if( pbEdge[ (iX + 1) + (iY - 1) * 2 * iWidth ] )
     6395        bTopConnected = true;
     6396    }
     6397    else
     6398    {
     6399      bTopConnected = true;
     6400    }
     6401
     6402
     6403    if( iY != 2 * iHeight - 2 )
     6404    {
     6405      if( pbEdge[ iX + (iY + 2) * 2 * iWidth ] )
     6406        bBottomConnected = true;
     6407      if( pbEdge[ (iX - 1) + (iY + 1) * 2 * iWidth ] )
     6408        bBottomConnected = true;
     6409      if( pbEdge[ (iX + 1) + (iY + 1) * 2 * iWidth ] )
     6410        bBottomConnected = true;
     6411    }
     6412    else
     6413    {
     6414      bBottomConnected = true;
     6415    }
     6416
     6417
     6418    if( bTopConnected && bBottomConnected )
     6419    {
     6420      return true;
     6421    }
     6422    else
     6423    {
     6424      return false;
     6425    }
     6426  }
     6427  else
     6428  {
     6429    Bool bLeftConnected = false;
     6430    Bool bRightConnected = false;
     6431
     6432    if( iX != 0 )
     6433    {
     6434      if( pbEdge[ (iX - 2) + iY * 2 * iWidth ] )
     6435        bLeftConnected = true;
     6436      if( pbEdge[ (iX - 1) + (iY - 1) * 2 * iWidth ] )
     6437        bLeftConnected = true;
     6438      if( pbEdge[ (iX - 1) + (iY + 1) * 2 * iWidth ] )
     6439        bLeftConnected = true;
     6440    }
     6441    else
     6442    {
     6443      bLeftConnected = true;
     6444    }
     6445
     6446    if( iX != 2 * iWidth - 2 )
     6447    {
     6448      if( pbEdge[ (iX + 2) + iY * 2 * iWidth ] )
     6449        bRightConnected = true;
     6450      if( pbEdge[ (iX + 1) + (iY - 1) * 2 * iWidth ] )
     6451        bRightConnected = true;
     6452      if( pbEdge[ (iX + 1) + (iY + 1) * 2 * iWidth ] )
     6453        bRightConnected = true;
     6454    }
     6455    else
     6456    {
     6457      bRightConnected = true;
     6458    }
     6459
     6460
     6461    if( bLeftConnected && bRightConnected )
     6462    {
     6463      return true;
     6464    }
     6465    else
     6466    {
     6467      return false;
     6468    }
     6469  }
     6470}
     6471
     6472#if LGE_EDGE_INTRA_PIXEL_DIFFERENCE
     6473Bool TEncSearch::xEdgePartition( TComDataCU* pcCU, UInt uiPartIdx, Bool bPU4x4 )
     6474{
     6475  Pel* pcOrgY   = pcCU->getPic()->getPicYuvOrg()->getLumaAddr(pcCU->getAddr());
     6476  UInt uiStride = pcCU->getPic()->getPicYuvOrg()->getStride();
     6477  Int iWidth    = pcCU->getWidth(uiPartIdx) >> (bPU4x4 ? 1 : 0);
     6478  Int iHeight   = pcCU->getHeight(uiPartIdx) >> (bPU4x4 ? 1 : 0);
     6479  Bool* pbEdge  = (Bool*) xMalloc( Bool, iWidth * iHeight * 4 );
     6480
     6481  {
     6482    UInt uiOffsetX = 0;
     6483    UInt uiOffsetY = 0;
     6484    UInt uiAbsPartIdx = pcCU->getZorderIdxInCU() + uiPartIdx;
     6485
     6486    uiOffsetX =  (uiAbsPartIdx & 0x1) |
     6487      ((uiAbsPartIdx & 0x4)  >> 1) |
     6488      ((uiAbsPartIdx & 0x10) >> 2) |
     6489      ((uiAbsPartIdx & 0x40) >> 3);
     6490    uiOffsetY = ((uiAbsPartIdx & 0x2)  >> 1) |
     6491      ((uiAbsPartIdx & 0x8)  >> 2) |
     6492      ((uiAbsPartIdx & 0x20) >> 3) |
     6493      ((uiAbsPartIdx & 0x80) >> 4);
     6494    uiOffsetX *= 4;
     6495    uiOffsetY *= 4;
     6496    pcOrgY += (uiOffsetX + uiOffsetY * uiStride);
     6497
     6498  }
     6499
     6500  Short* psDiffX = new Short[ iWidth * iHeight ];
     6501  Short* psDiffY = new Short[ iWidth * iHeight ];
     6502  Bool*  pbEdgeX = new Bool [ iWidth * iHeight ];
     6503  Bool*  pbEdgeY = new Bool [ iWidth * iHeight ];
     6504
     6505  // Find Horizontal Gradient & Edge Detection ((x+1, y) - (x,y))
     6506  for( Int y=0; y<iHeight; y++ )
     6507  {
     6508    Short* psDiffXPtr = &psDiffX[ y * iHeight ];
     6509    Bool*  pbEdgeXPtr = &pbEdgeX[ y * iHeight ];
     6510    for(Int x=0; x<iWidth-1; x++ )
     6511    {
     6512      *psDiffXPtr = pcOrgY[ x+1 + y*uiStride ] - pcOrgY[ x + y*uiStride ];
     6513      if(*psDiffXPtr >= LGE_EDGE_INTRA_THRESHOLD || *psDiffXPtr <= (-1)*LGE_EDGE_INTRA_THRESHOLD)
     6514      {
     6515        *pbEdgeXPtr = true;
     6516      }
     6517      else
     6518      {
     6519        *pbEdgeXPtr = false;
     6520      }
     6521
     6522      psDiffXPtr++;
     6523      pbEdgeXPtr++;
     6524    }
     6525  }
     6526
     6527  // Find Vertical Gradient & Edge Detection((x,y+1) - (x,y))
     6528  for( Int y=0; y<iHeight-1; y++ )
     6529  {
     6530    Short* psDiffYPtr = &psDiffY[ y * iHeight ];
     6531    Bool*  pbEdgeYPtr = &pbEdgeY[ y * iHeight ];
     6532    for(Int x=0; x<iWidth; x++ )
     6533    {
     6534      *psDiffYPtr = pcOrgY[ x + (y+1)*uiStride ] - pcOrgY [ x + y*uiStride ];
     6535      if(*psDiffYPtr >= LGE_EDGE_INTRA_THRESHOLD || *psDiffYPtr <= (-1)*LGE_EDGE_INTRA_THRESHOLD)
     6536      {
     6537        *pbEdgeYPtr = true;
     6538      }
     6539      else
     6540      {
     6541        *pbEdgeYPtr = false;
     6542      }
     6543
     6544      psDiffYPtr++;
     6545      pbEdgeYPtr++;
     6546    }
     6547  }
     6548
     6549  // Eliminate local maximum
     6550  for( Int y=0; y<iHeight; y++ )
     6551  {
     6552    Short* psDiffXPtr = &psDiffX[ y * iHeight ];
     6553    Bool*  pbEdgeXPtr = &pbEdgeX[ y * iHeight ];
     6554    for( Int x=0; x<iWidth-1; x++ )
     6555    {
     6556      UShort usAbs0=0, usAbs1=0, usAbs2=0;  // 0 : left, 1 : current, 2 : right
     6557
     6558      if( x > 0 && *(pbEdgeXPtr-1) == true )
     6559      {
     6560        if( *(psDiffXPtr-1) >= 0)
     6561        {
     6562          usAbs0 = *(psDiffXPtr-1);
     6563
     6564        }
     6565        else
     6566        {
     6567          usAbs0 = (-1) * *(psDiffXPtr-1);
     6568        }
     6569      }
     6570      if( *pbEdgeXPtr == true )
     6571      {
     6572        if( *(psDiffXPtr) >= 0)
     6573        {
     6574          usAbs1 = *(psDiffXPtr);
     6575        }
     6576        else
     6577        {
     6578          usAbs1 = (-1) * *(psDiffXPtr);
     6579        }
     6580      }
     6581      if( x < iWidth-2 && *(pbEdgeXPtr+1) == true )
     6582      {
     6583        if( *(psDiffXPtr+1) >= 0)
     6584        {
     6585          usAbs2 = *(psDiffXPtr+1);
     6586          //bSign2 = true;
     6587        }
     6588        else
     6589        {
     6590          usAbs2 = (-1) * *(psDiffXPtr+1);
     6591        }
     6592      }
     6593
     6594      if( x == 0 )
     6595      {
     6596        if( usAbs1 < usAbs2 )
     6597        {
     6598          *pbEdgeXPtr = false;
     6599        }
     6600      }
     6601      else if( x == iWidth-2 )
     6602      {
     6603        if( usAbs1 <= usAbs0 )
     6604          *pbEdgeXPtr = false;
     6605      }
     6606      else
     6607      {
     6608        if( usAbs2 > usAbs0 )
     6609        {
     6610          if( usAbs1 < usAbs2 )
     6611            *pbEdgeXPtr = false;
     6612        }
     6613        else
     6614        {
     6615          if( usAbs1 <= usAbs0 )
     6616            *pbEdgeXPtr = false;
     6617        }
     6618      }
     6619
     6620      psDiffXPtr++;
     6621      pbEdgeXPtr++;
     6622    }
     6623  }
     6624
     6625  for( Int y=0; y<iHeight-1; y++ )
     6626  {
     6627    Short* psDiffYPtr = &psDiffY[ y * iWidth ];
     6628    Bool*  pbEdgeYPtr = &pbEdgeY[ y * iWidth ];
     6629    for( Int x=0; x<iWidth; x++ )
     6630    {
     6631      UShort usAbs0=0, usAbs1=0, usAbs2=0;  // 0 : upper, 1 : current, 2 : bottom
     6632      if( y > 0 && *(pbEdgeYPtr-iWidth) == true )
     6633      {
     6634        if( *(psDiffYPtr-iWidth) >= 0)
     6635        {
     6636          usAbs0 = *(psDiffYPtr-iWidth);
     6637        }
     6638        else
     6639        {
     6640          usAbs0 = (-1) * *(psDiffYPtr-iWidth);         
     6641        }
     6642      }
     6643      if( *pbEdgeYPtr == true )
     6644      {
     6645        if( *(psDiffYPtr) >= 0)
     6646        {
     6647          usAbs1 = *(psDiffYPtr);
     6648        }
     6649        else
     6650        {
     6651          usAbs1 = (-1) * *(psDiffYPtr);
     6652        }
     6653      }
     6654      if( y < iHeight-2 && *(pbEdgeYPtr+iWidth) == true )
     6655      {
     6656        if( *(psDiffYPtr+iWidth) >= 0)
     6657        {
     6658          usAbs2 = *(psDiffYPtr+iWidth);         
     6659        }
     6660        else
     6661        {
     6662          usAbs2 = (-1) * *(psDiffYPtr+iWidth);
     6663        }
     6664      }
     6665
     6666      if( y == 0 )
     6667      {
     6668        if( usAbs1 < usAbs2 )
     6669          *pbEdgeYPtr = false;
     6670      }
     6671      else if( y == iHeight-2 )
     6672      {
     6673        if( usAbs1 <= usAbs0 )
     6674          *pbEdgeYPtr = false;
     6675      }
     6676      else
     6677      {
     6678        if( usAbs2 > usAbs0 )
     6679        {
     6680          if( usAbs1 < usAbs2 )
     6681            *pbEdgeYPtr = false;
     6682        }
     6683        else
     6684        {
     6685          if( usAbs1 <= usAbs0 )
     6686            *pbEdgeYPtr = false;
     6687        }
     6688      }
     6689
     6690      psDiffYPtr++;
     6691      pbEdgeYPtr++;
     6692    }
     6693  }
     6694
     6695  // Edge Merging
     6696  for( Int i=0; i< 4 * iWidth * iHeight; i++ )
     6697    pbEdge[ i ] = false;
     6698  /// Even Line (0,2,4,6,...) => Vertical Edge
     6699  for( Int i=0; i<iHeight; i++)
     6700  {
     6701    for( Int j=0; j<iWidth-1; j++)
     6702    {
     6703      pbEdge[ (2 * j + 1) + (2 * i) * 2 * iWidth ] = pbEdgeX[ j + i * iHeight ];
     6704    }
     6705  }
     6706  /// Odd Line (1,3,5,7,...) => Horizontal Edge
     6707  for( Int i=0; i<iHeight-1; i++)
     6708  {
     6709    for( Int j=0; j<iWidth; j++)
     6710    {
     6711      pbEdge[ (2 * j) + (2 * i + 1) * 2 * iWidth ] = pbEdgeY[ j + i * iHeight ];
     6712    }
     6713  }
     6714
     6715  // Intersection Filling
     6716  /// Vertical Edge between Horizontal Edges
     6717  for( Int i = 1; i < 2 * iHeight - 3; i += 2)
     6718  {
     6719    for( Int j = 0; j < 2 * iWidth - 1; j += 2)
     6720    {
     6721      if( pbEdge[ j + i * 2 * iWidth ] )
     6722      {
     6723        if( j != 0 && pbEdge[ (j - 2) + ((i + 2) * 2 * iWidth) ] )
     6724        {
     6725          if( !pbEdge[ (j - 1) + ((i - 1) * 2 * iWidth) ] && !pbEdge[ (j - 1) + ((i + 3) * 2 * iWidth) ] )
     6726            pbEdge[ (j - 1) + ((i + 1) * 2 * iWidth) ] = true;
     6727        }
     6728        if( j != 2 * iWidth - 2 && pbEdge[ (j + 2) + ((i + 2) * 2 * iWidth) ] )
     6729        {
     6730          if( !pbEdge[ (j + 1) + ((i - 1) * 2 * iWidth) ] && !pbEdge[ (j + 1) + ((i + 3) * 2 * iWidth) ] )
     6731            pbEdge[ (j + 1) + ((i + 1) * 2 * iWidth) ] = true;
     6732        }
     6733      }
     6734    }
     6735  }
     6736  /// Horizontal Edge between Vertical Edges
     6737  for( Int j = 1; j < 2 * iWidth - 3; j += 2)
     6738  {
     6739    for( Int i = 0; i < 2 * iHeight - 1; i += 2)
     6740    {
     6741      if( pbEdge[ j + i * 2 * iWidth ] )
     6742      {
     6743        if( i != 0 && pbEdge[ (j + 2) + ((i - 2) * 2 * iWidth) ] )
     6744        {
     6745          if( !pbEdge[ (j - 1) + ((i - 1) * 2 * iWidth) ] && !pbEdge[ (j + 3) + ((i - 1) * 2 * iWidth) ] )
     6746            pbEdge[ (j + 1) + ((i - 1) * 2 * iWidth) ] = true;
     6747        }
     6748        if( i != 2 * iHeight - 2 && pbEdge[ (j + 2) + ((i + 2) * 2 * iWidth) ] )
     6749        {
     6750          if( !pbEdge[ (j - 1) + ((i + 1) * 2 * iWidth) ] && !pbEdge[ (j + 3) + ((i + 1) * 2 * iWidth) ] )
     6751            pbEdge[ (j + 1) + ((i + 1) * 2 * iWidth) ] = true;
     6752        }
     6753      }
     6754    }
     6755  }
     6756
     6757  // Static Pruning Unnecessary Edges
     6758  /// Step1. Stack push the unconnected edges
     6759  UShort* pusUnconnectedEdgeStack = new UShort[ 4 * iWidth * iHeight ]; // approximate size calculation
     6760  Int iUnconnectedEdgeStackPtr = 0;
     6761  //// Vertical Edges
     6762  for( Int i = 0; i < 2 * iHeight - 1; i += 2 )
     6763  {
     6764    for( Int j = 1; j < 2 * iWidth - 2; j += 2 )
     6765    {
     6766      if( pbEdge[ j + i * 2 * iWidth ] )
     6767      {
     6768        if( !xCheckTerminatedEdge( pbEdge, j, i, iWidth, iHeight ) )
     6769        {
     6770          pusUnconnectedEdgeStack[iUnconnectedEdgeStackPtr] = (i << 8) | (j);
     6771          iUnconnectedEdgeStackPtr++;
     6772        }
     6773      }
     6774    }
     6775  }
     6776
     6777  //// Horizontal Edges
     6778  for( Int i = 1; i < 2 * iHeight - 2; i += 2 )
     6779  {
     6780    for( Int j = 0; j < 2 * iWidth - 1; j += 2 )
     6781    {
     6782      if( pbEdge[ j + i * 2 * iWidth ] )
     6783      {
     6784        if( !xCheckTerminatedEdge( pbEdge, j, i, iWidth, iHeight ) )
     6785        {
     6786          pusUnconnectedEdgeStack[iUnconnectedEdgeStackPtr] = (i << 8) | (j);
     6787          iUnconnectedEdgeStackPtr++;
     6788        }
     6789      }
     6790    }
     6791  }
     6792
     6793  /// Step2. Remove the edges from the stack and push the new unconnected edges
     6794  //// (This step may contain duplicated edges already in the stack)
     6795  //// (But it doesn't cause any functional problems)
     6796  while( iUnconnectedEdgeStackPtr != 0 )
     6797  {
     6798    iUnconnectedEdgeStackPtr--;
     6799    Int iX = pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] & 0xff;
     6800    Int iY = pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] >> 8;
     6801
     6802    pbEdge[ iX + iY * 2 * iWidth ] = false;
     6803
     6804    if( iY % 2 == 1 && iX > 0 && pbEdge[ iX - 2 + iY * 2 * iWidth ] &&
     6805      !xCheckTerminatedEdge( pbEdge, iX - 2, iY, iWidth, iHeight ) ) // left
     6806    {
     6807      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 0) << 8) | (iX - 2);
     6808      iUnconnectedEdgeStackPtr++;
     6809    }
     6810    if( iY % 2 == 1 && iX < 2 * iWidth - 2 && pbEdge[ iX + 2 + iY * 2 * iWidth ] &&
     6811      !xCheckTerminatedEdge( pbEdge, iX + 2, iY, iWidth, iHeight ) ) // right
     6812    {
     6813      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 0) << 8) | (iX + 2);
     6814      iUnconnectedEdgeStackPtr++;
     6815    }
     6816    if( iY % 2 == 0 && iY > 0 && pbEdge[ iX + (iY - 2) * 2 * iWidth ] &&
     6817      !xCheckTerminatedEdge( pbEdge, iX, iY - 2, iWidth, iHeight ) ) // top
     6818    {
     6819      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY - 2) << 8) | (iX + 0);
     6820      iUnconnectedEdgeStackPtr++;
     6821    }
     6822    if( iY % 2 == 0 && iY < 2 * iHeight - 2 && pbEdge[ iX + (iY + 2) * 2 * iWidth ] &&
     6823      !xCheckTerminatedEdge( pbEdge, iX, iY + 2, iWidth, iHeight ) ) // bottom
     6824    {
     6825      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 2) << 8) | (iX + 0);
     6826      iUnconnectedEdgeStackPtr++;
     6827    }
     6828    if( iX > 0 && iY > 0 && pbEdge[ iX - 1 + (iY - 1) * 2 * iWidth ] &&
     6829      !xCheckTerminatedEdge( pbEdge, iX - 1, iY - 1, iWidth, iHeight ) ) // left-top
     6830    {
     6831      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY - 1) << 8) | (iX - 1);
     6832      iUnconnectedEdgeStackPtr++;
     6833    }
     6834    if( iX < 2 * iWidth - 1 && iY > 0 && pbEdge[ iX + 1 + (iY - 1) * 2 * iWidth ] &&
     6835      !xCheckTerminatedEdge( pbEdge, iX + 1, iY - 1, iWidth, iHeight ) ) // right-top
     6836    {
     6837      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY - 1) << 8) | (iX + 1);
     6838      iUnconnectedEdgeStackPtr++;
     6839    }
     6840    if( iX > 0 && iY < 2 * iHeight - 1 && pbEdge[ iX - 1 + (iY + 1) * 2 * iWidth ] &&
     6841      !xCheckTerminatedEdge( pbEdge, iX - 1, iY + 1, iWidth, iHeight ) ) // left-bottom
     6842    {
     6843      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 1) << 8) | (iX - 1);
     6844      iUnconnectedEdgeStackPtr++;
     6845    }
     6846    if( iX < 2 * iWidth - 1 && iY < 2 * iHeight - 1 && pbEdge[ iX + 1 + (iY + 1) * 2 * iWidth ] &&
     6847      !xCheckTerminatedEdge( pbEdge, iX + 1, iY + 1, iWidth, iHeight ) ) // right-bottom
     6848    {
     6849      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 1) << 8) | (iX + 1);
     6850      iUnconnectedEdgeStackPtr++;
     6851    }
     6852  }
     6853
     6854
     6855  // Region Generation ( edge -> region )
     6856  Bool* pbRegion = pcCU->getEdgePartition( uiPartIdx );
     6857  Bool* pbVisit  = new Bool[ iWidth * iHeight ];
     6858
     6859  for( UInt ui = 0; ui < iWidth * iHeight; ui++ )
     6860  {
     6861    pbRegion[ ui ] = true; // fill it as region 1 (we'll discover region 0 next)
     6862    pbVisit [ ui ] = false;
     6863  }
     6864
     6865  Int* piStack = new Int[ iWidth * iHeight ];
     6866
     6867  Int iPtr = 0;
     6868
     6869  piStack[iPtr++] = (0 << 8) | (0);
     6870  pbRegion[ 0 ] = false;
     6871
     6872  while(iPtr > 0)
     6873  {
     6874    Int iTmp = piStack[--iPtr];
     6875    Int iX1, iY1;
     6876    iX1 = iTmp & 0xff;
     6877    iY1 = (iTmp >> 8) & 0xff;
     6878
     6879    pbVisit[ iX1 + iY1 * iWidth ] = true;
     6880
     6881    assert( iX1 >= 0 && iX1 < iWidth );
     6882    assert( iY1 >= 0 && iY1 < iHeight );
     6883
     6884    if( iX1 > 0 && !pbEdge[ 2 * iX1 - 1 + 4 * iY1 * iWidth ] && !pbVisit[ iX1 - 1 + iY1 * iWidth ] )
     6885    {
     6886      piStack[iPtr++] = (iY1 << 8) | (iX1 - 1);
     6887      pbRegion[ iX1 - 1 + iY1 * iWidth ] = false;
     6888    }
     6889    if( iX1 < iWidth - 1 && !pbEdge[ 2 * iX1 + 1 + 4 * iY1 * iWidth ] && !pbVisit[ iX1 + 1 + iY1 * iWidth ] )
     6890    {
     6891      piStack[iPtr++] = (iY1 << 8) | (iX1 + 1);
     6892      pbRegion[ iX1 + 1 + iY1 * iWidth ] = false;
     6893    }
     6894    if( iY1 > 0 && !pbEdge[ 2 * iX1 + 2 * (2 * iY1 - 1) * iWidth ] && !pbVisit[ iX1 + (iY1 - 1) * iWidth ] )
     6895    {
     6896      piStack[iPtr++] = ((iY1 - 1) << 8) | iX1;
     6897      pbRegion[ iX1 + (iY1 - 1) * iWidth ] = false;
     6898    }
     6899    if( iY1 < iHeight - 1 && !pbEdge[ 2 * iX1 + 2 * (2 * iY1 + 1) * iWidth ] && !pbVisit[ iX1 + (iY1 + 1) * iWidth ] )
     6900    {
     6901      piStack[iPtr++] = ((iY1 + 1) << 8) | iX1;
     6902      pbRegion[ iX1 + (iY1 + 1) * iWidth ] = false;
     6903    }
     6904  }
     6905
     6906  ///////////
     6907  iPtr = 0;
     6908  for( Int i = 0; i < iWidth * iHeight; i++ )
     6909    pbVisit[ i ] = false;
     6910  piStack[ iPtr++ ] = (0 << 8) | (0); // initial seed
     6911  while( iPtr > 0 && iPtr < iWidth * iHeight )
     6912  {
     6913    Int iX;
     6914    Int iY;
     6915    iPtr--;
     6916    iX = piStack[ iPtr ] & 0xff;
     6917    iY = piStack[ iPtr ] >> 8;
     6918    pbVisit[ iY * iWidth + iX ] = true;
     6919
     6920    if( iY > 0 && !pbVisit[ (iY - 1) * iWidth + iX ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ (iY - 1) * iWidth + iX ] )
     6921    {
     6922      piStack[ iPtr++ ] = ((iY - 1) << 8) | iX;
     6923    }
     6924    if( iY < iHeight - 1 && !pbVisit[ (iY + 1) * iWidth + iX ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ (iY + 1) * iWidth + iX ] )
     6925    {
     6926      piStack[ iPtr++ ] = ((iY + 1) << 8) | iX;
     6927    }
     6928    if( iX > 0 && !pbVisit[ iY * iWidth + (iX - 1) ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ iY * iWidth + (iX - 1) ] )
     6929    {
     6930      piStack[ iPtr++ ] = (iY << 8) | (iX - 1);
     6931    }
     6932    if( iX < iWidth - 1 && !pbVisit[ iY * iWidth + (iX + 1) ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ iY * iWidth + (iX + 1) ] )
     6933    {
     6934      piStack[ iPtr++ ] = (iY << 8) | (iX + 1);
     6935    }
     6936  }
     6937  assert( iPtr == 0 || iPtr == iWidth * iHeight );
     6938
     6939  Bool bBipartition;
     6940  if( iPtr == iWidth * iHeight )
     6941  {
     6942    bBipartition = false; // single partition
     6943  }
     6944  else
     6945  {
     6946    for( Int i = 0; i < iWidth * iHeight; i++ )
     6947    {
     6948      if( !pbVisit[ i ] )
     6949      {
     6950        piStack[ iPtr++ ] = (( i / iWidth ) << 8) | ( i % iWidth );
     6951        pbVisit[ i ] = true;
     6952        break;
     6953      }
     6954    }
     6955    while( iPtr > 0 )
     6956    {
     6957      Int iX;
     6958      Int iY;
     6959      iPtr--;
     6960      iX = piStack[ iPtr ] & 0xff;
     6961      iY = piStack[ iPtr ] >> 8;
     6962      pbVisit[ iY * iWidth + iX ] = true;
     6963
     6964      if( iY > 0 && !pbVisit[ (iY - 1) * iWidth + iX ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ (iY - 1) * iWidth + iX ] )
     6965      {
     6966        piStack[ iPtr++ ] = ((iY - 1) << 8) | iX;
     6967      }
     6968      if( iY < iHeight - 1 && !pbVisit[ (iY + 1) * iWidth + iX ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ (iY + 1) * iWidth + iX ] )
     6969      {
     6970        piStack[ iPtr++ ] = ((iY + 1) << 8) | iX;
     6971      }
     6972      if( iX > 0 && !pbVisit[ iY * iWidth + (iX - 1) ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ iY * iWidth + (iX - 1) ] )
     6973      {
     6974        piStack[ iPtr++ ] = (iY << 8) | (iX - 1);
     6975      }
     6976      if( iX < iWidth - 1 && !pbVisit[ iY * iWidth + (iX + 1) ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ iY * iWidth + (iX + 1) ] )
     6977      {
     6978        piStack[ iPtr++ ] = (iY << 8) | (iX + 1);
     6979      }
     6980    }
     6981    bBipartition = true;
     6982    for( Int i = 0; i < iWidth * iHeight; i++ )
     6983    {
     6984      if( !pbVisit[ i ] )
     6985      {
     6986        bBipartition = false;
     6987        break;
     6988      }
     6989    }
     6990  }
     6991
     6992  xFree( pbEdge );
     6993  delete[] pbEdgeX; pbEdgeX = NULL;
     6994  delete[] pbEdgeY; pbEdgeY = NULL;
     6995  delete[] psDiffX; psDiffX = NULL;
     6996  delete[] psDiffY; psDiffY = NULL;
     6997  delete[] pusUnconnectedEdgeStack; pusUnconnectedEdgeStack = NULL;
     6998  delete[] pbVisit; pbVisit = NULL;
     6999  delete[] piStack; piStack = NULL;
     7000
     7001  Bool bCheckPossibleChain;
     7002
     7003  if( bBipartition )
     7004    bCheckPossibleChain = xConstructChainCode( pcCU, uiPartIdx, bPU4x4 );
     7005  else
     7006    bCheckPossibleChain = false;
     7007
     7008  return bCheckPossibleChain;
     7009}
     7010
     7011#endif
     7012
     7013Bool TEncSearch::xConstructChainCode( TComDataCU* pcCU, UInt uiPartIdx, Bool bPU4x4 )
     7014{
     7015  UInt   uiWidth    = pcCU->getWidth( uiPartIdx ) >> (bPU4x4 ? 1 : 0);
     7016  UInt   uiHeight   = pcCU->getHeight( uiPartIdx ) >> (bPU4x4 ? 1 : 0);
     7017  Bool*  pbEdge     = (Bool*) xMalloc( Bool, uiWidth * uiHeight * 4 );
     7018  Bool*  pbVisit    = (Bool*) xMalloc( Bool, uiWidth * uiHeight * 4 );
     7019  UInt   uiMaxEdge  = uiWidth * (LGE_EDGE_INTRA_MAX_EDGE_NUM_PER_4x4 / 4);
     7020  Bool*  pbRegion   = pcCU->getEdgePartition( uiPartIdx );
     7021  UChar* piEdgeCode = pcCU->getEdgeCode( uiPartIdx );
     7022  Bool   bStartLeft = false;
     7023  Bool   bPossible  = false;
     7024  Bool   bFinish    = false;
     7025  Int    iStartPosition = -1;
     7026  Int    iPtr = 0;
     7027  Int    iDir = -1, iNextDir = -1;
     7028  Int    iArrow = -1, iNextArrow = -1;
     7029  Int    iX = -1, iY = -1;
     7030  Int    iDiffX = 0, iDiffY = 0;
     7031  UChar  iCode = 255;
     7032  UInt   uiWidth2 = uiWidth * 2;
     7033
     7034  for( Int i = 0; i < uiWidth * uiHeight * 4; i++ )
     7035    pbEdge[ i ] = false;
     7036
     7037  for( Int i = 0; i < uiHeight; i++ )
     7038  {
     7039    for( Int j = 0; j < uiWidth - 1; j++ )
     7040    {
     7041      if( pbRegion[ i * uiWidth + j ] != pbRegion[ i * uiWidth + j + 1 ] )
     7042        pbEdge[ i * uiWidth * 4 + j * 2 + 1 ] = true;
     7043    }
     7044  }
     7045
     7046  for( Int i = 0; i < uiHeight - 1; i++ )
     7047  {
     7048    for( Int j = 0; j < uiWidth; j++ )
     7049    {
     7050      if( pbRegion[ (i + 0) * uiWidth + j ] != pbRegion[ (i + 1) * uiWidth + j ] )
     7051        pbEdge[ (2 * i + 1) * 2 * uiWidth + j * 2 ] = true;
     7052    }
     7053  }
     7054
     7055  for( Int i = 1; i < uiWidth2 - 2; i+=2 )
     7056  {
     7057    if(pbEdge[ i ])
     7058    {
     7059      bPossible  = true;
     7060      bStartLeft = false;
     7061      iStartPosition = iX = i;
     7062      iY = 0;
     7063      iDir = 3;
     7064      iArrow = 3;
     7065      break;
     7066    }
     7067  }
     7068
     7069  if( !bPossible )
     7070  {
     7071    for( Int i = 1; i < uiWidth2 - 2; i+=2 )
     7072    {
     7073      if(pbEdge[ i * uiWidth2 ])
     7074      {
     7075        bPossible  = true;
     7076        bStartLeft = true;
     7077        iX = 0;
     7078        iStartPosition = iY = i;
     7079        iDir = 1;
     7080        iArrow = 1;
     7081        break;
     7082      }
     7083    }
     7084  }
     7085
     7086  if( bPossible )
     7087  {
     7088    for( Int i = 0; i < 4 * uiWidth * uiHeight; i++ )
     7089      pbVisit[ i ] = false;
     7090
     7091    while( !bFinish )
     7092    {
     7093      Bool bArrowSkip = false;
     7094      pbVisit[ iX + iY * uiWidth2 ] = true;
     7095
     7096      switch( iDir )
     7097      {
     7098      case 0: // left
     7099        if( iX > 0 && !pbVisit[ (iX - 2) + iY * uiWidth2 ] && pbEdge[ (iX - 2) + iY * uiWidth2 ] ) // left
     7100        {
     7101          iDiffX = -2;
     7102          iDiffY =  0;
     7103          iNextDir = 0;
     7104          iNextArrow = 0;
     7105        }
     7106        else if( iX > 0 && !pbVisit[ (iX - 1) + (iY - 1) * uiWidth2 ] && pbEdge[ (iX - 1) + (iY - 1) * uiWidth2 ] ) // top
     7107        {
     7108          iDiffX = -1;
     7109          iDiffY = -1;
     7110          iNextDir = 2;
     7111          iNextArrow = 4;
     7112        }
     7113        else if( iX > 0 && !pbVisit[ (iX - 1) + (iY + 1) * uiWidth2 ] && pbEdge[ (iX - 1) + (iY + 1) * uiWidth2 ] ) // bottom
     7114        {
     7115          iDiffX = -1;
     7116          iDiffY = +1;
     7117          iNextDir = 3;
     7118          iNextArrow = iArrow;
     7119          if( !(iPtr == 0 && iX == uiWidth2 - 2 && iY == uiHeight * 2 - 3) )
     7120            bArrowSkip = true;
     7121          else
     7122            iNextArrow = 3;
     7123        }
     7124        else if( iX == 0 )
     7125        {
     7126          iDiffX = 0;
     7127          iDiffY = 0;
     7128          iNextDir = iDir;
     7129          iNextArrow = iArrow;
     7130          bFinish = true;
     7131          continue;
     7132        }
     7133        else
     7134        {
     7135          iPtr = 0; // edge loop or unwanted case
     7136          bFinish = true;
     7137          //continue;
     7138          assert(false);
     7139        }
     7140        break;
     7141      case 1: // right
     7142        if( iX < uiWidth2 - 2 && !pbVisit[ (iX + 2) + iY * uiWidth2 ] && pbEdge[ (iX + 2) + iY * uiWidth2 ] ) // right
     7143        {
     7144          iDiffX = +2;
     7145          iDiffY =  0;
     7146          iNextDir = 1;
     7147          iNextArrow = 1;
     7148        }
     7149        else if( iX < uiWidth2 - 2 && !pbVisit[ (iX + 1) + (iY - 1) * uiWidth2 ] && pbEdge[ (iX + 1) + (iY - 1) * uiWidth2 ] ) // top
     7150        {
     7151          iDiffX = +1;
     7152          iDiffY = -1;
     7153          iNextDir = 2;
     7154          iNextArrow = iArrow;
     7155          if( !(iPtr == 0 && iX == 0 && iY == 1) )
     7156            bArrowSkip = true;
     7157          else
     7158            iNextArrow = 2;
     7159        }
     7160        else if( iX < uiWidth2 - 2 && !pbVisit[ (iX + 1) + (iY + 1) * uiWidth2 ] && pbEdge[ (iX + 1) + (iY + 1) * uiWidth2 ] ) // bottom
     7161        {
     7162          iDiffX = +1;
     7163          iDiffY = +1;
     7164          iNextDir = 3;
     7165          iNextArrow = 7;
     7166        }
     7167        else if( iX == uiWidth2 - 2 )
     7168        {
     7169          iDiffX = 0;
     7170          iDiffY = 0;
     7171          iNextDir = iDir;
     7172          iNextArrow = iArrow;
     7173          bFinish = true;
     7174          continue;
     7175        }
     7176        else
     7177        {
     7178          iPtr = 0; // edge loop or unwanted case
     7179          bFinish = true;
     7180          //continue;
     7181          assert(false);
     7182        }
     7183        break;
     7184      case 2: // top
     7185        if( iY > 0 && !pbVisit[ (iX - 1) + (iY - 1) * uiWidth2 ] && pbEdge[ (iX - 1) + (iY - 1) * uiWidth2 ] ) // left
     7186        {
     7187          iDiffX = -1;
     7188          iDiffY = -1;
     7189          iNextDir = 0;
     7190          iNextArrow = iArrow;
     7191          if( !(iPtr == 0 && iX == 1 && iY == uiHeight * 2 - 2) )
     7192            bArrowSkip = true;
     7193          else
     7194            iNextArrow = 0;
     7195        }
     7196        else if( iY > 0 && !pbVisit[ (iX + 1) + (iY - 1) * uiWidth2 ] && pbEdge[ (iX + 1) + (iY - 1) * uiWidth2 ] ) // right
     7197        {
     7198          iDiffX = +1;
     7199          iDiffY = -1;
     7200          iNextDir = 1;
     7201          iNextArrow = 5;
     7202        }
     7203        else if( iY > 0 && !pbVisit[ iX + (iY - 2) * uiWidth2 ] && pbEdge[ iX + (iY - 2) * uiWidth2 ] ) // top
     7204        {
     7205          iDiffX =  0;
     7206          iDiffY = -2;
     7207          iNextDir = 2;
     7208          iNextArrow = 2;
     7209        }
     7210        else if( iY == 0 )
     7211        {
     7212          iDiffX = 0;
     7213          iDiffY = 0;
     7214          iNextDir = iDir;
     7215          iNextArrow = iArrow;
     7216          bFinish = true;
     7217          continue;
     7218        }
     7219        else
     7220        {
     7221          iPtr = 0; // edge loop or unwanted case
     7222          bFinish = true;
     7223          //continue;
     7224          assert(false);
     7225        }
     7226        break;
     7227      case 3: // bottom
     7228        if( iY < uiWidth2 - 2 && !pbVisit[ (iX - 1) + (iY + 1) * uiWidth2 ] && pbEdge[ (iX - 1) + (iY + 1) * uiWidth2 ] ) // left
     7229        {
     7230          iDiffX = -1;
     7231          iDiffY = +1;
     7232          iNextDir = 0;
     7233          iNextArrow = 6;
     7234        }
     7235        else if( iY < uiWidth2 - 2 && !pbVisit[ (iX + 1) + (iY + 1) * uiWidth2 ] && pbEdge[ (iX + 1) + (iY + 1) * uiWidth2 ] ) // right
     7236        {
     7237          iDiffX = +1;
     7238          iDiffY = +1;
     7239          iNextDir = 1;
     7240          iNextArrow = iArrow;
     7241          if( !(iPtr == 0 && iX == uiWidth * 2 - 3 && iY == 0) )
     7242            bArrowSkip = true;
     7243          else
     7244            iNextArrow = 1;
     7245        }
     7246        else if( iY < uiWidth2 - 2 && !pbVisit[ iX + (iY + 2) * uiWidth2 ] && pbEdge[ iX + (iY + 2) * uiWidth2 ] ) // bottom
     7247        {
     7248          iDiffX =  0;
     7249          iDiffY = +2;
     7250          iNextDir = 3;
     7251          iNextArrow = 3;
     7252        }
     7253        else if( iY == uiWidth2 - 2 )
     7254        {
     7255          iDiffX = 0;
     7256          iDiffY = 0;
     7257          iNextDir = iDir;
     7258          iNextArrow = iArrow;
     7259          bFinish = true;
     7260          continue;
     7261        }
     7262        else
     7263        {
     7264          iPtr = 0; // edge loop or unwanted case
     7265          bFinish = true;
     7266          //continue;
     7267          assert(false);
     7268        }
     7269        break;
     7270      }
     7271
     7272      const UChar tableCode[8][8] = { { 0, -1, 4, 3, 2, 6, 1, 5 }, // iArrow(current direction), iNextArrow(next direction)
     7273      { -1, 0, 3, 4, 5, 1, 6, 2 },
     7274      { 3, 4, 0, -1, 1, 2, 5, 6 },
     7275      { 4, 3, -1, 0, 6, 5, 2, 1 },
     7276      { 1, 6, 2, 5, 0, 4, 3, -1 },
     7277      { 5, 2, 1, 6, 3, 0, -1, 4 },
     7278      { 2, 5, 6, 1, 4, -1, 0, 3 },
     7279      { 6, 1, 5, 2, -1, 3, 4, 0 } };
     7280
     7281      iCode = tableCode[iArrow][iNextArrow];
     7282
     7283      if(iPtr >= uiMaxEdge)
     7284      {
     7285        iPtr = 0; // over the maximum number of edge
     7286        bPossible = false;
     7287        break;
     7288      }
     7289
     7290      if( !bArrowSkip )
     7291      {
     7292        piEdgeCode[iPtr++] = iCode; // first edge coding
     7293        //printf("xEdgeCoding: (%d,%d)->(%d,%d) code %d\n",iX,iY, iX+iDiffX, iY+iDiffY, iCode);
     7294      }
     7295
     7296      iX += iDiffX;
     7297      iY += iDiffY;
     7298      iDir = iNextDir;
     7299      iArrow = iNextArrow;
     7300    }
     7301  }
     7302
     7303  pcCU->setEdgeLeftFirst( uiPartIdx, bStartLeft );
     7304  pcCU->setEdgeStartPos ( uiPartIdx, bStartLeft ? (iStartPosition - 1) >> 1 : (iStartPosition + 1) >> 1);
     7305  pcCU->setEdgeNumber   ( uiPartIdx, iPtr );
     7306
     7307  xFree( pbEdge );
     7308  xFree( pbVisit );
     7309
     7310  return (iPtr != 0);
     7311}
     7312
     7313#if LGE_EDGE_INTRA_DELTA_DC
     7314Void TEncSearch::xAssignEdgeIntraDeltaDCs( TComDataCU*   pcCU,
     7315                                          UInt          uiAbsPartIdx,
     7316                                          Pel*          piOrig,
     7317                                          UInt          uiStride,
     7318                                          Pel*          piPredic,
     7319                                          UInt          uiWidth,
     7320                                          UInt          uiHeight )
     7321{
     7322  Int iDC0 = 0;
     7323  Int iDC1 = 0;
     7324  Int iPredDC0 = 0;
     7325  Int iPredDC1 = 0;
     7326  Int iDeltaDC0 = 0;
     7327  Int iDeltaDC1 = 0;
     7328
     7329  Bool* pbRegion = pcCU->getEdgePartition( uiAbsPartIdx );
     7330
     7331  Int* piMask = pcCU->getPattern()->getAdiOrgBuf( uiWidth, uiHeight, m_piYuvExt );
     7332  Int iMaskStride = ( uiWidth<<1 ) + 1;
     7333
     7334  // DC Calculation
     7335  {
     7336    UInt uiSum0 = 0;
     7337    UInt uiSum1 = 0;
     7338    UInt uiCount0 = 0;
     7339    UInt uiCount1 = 0;
     7340
     7341    Pel* piTemp = piOrig;
     7342    for( UInt ui = 0; ui < uiHeight; ui++ )
     7343    {
     7344      for( UInt uii = 0; uii < uiWidth; uii++ )
     7345      {
     7346        if( pbRegion[ ui * uiWidth + uii ] == false )
     7347        {
     7348          uiSum0 += (piTemp[ uii ]);
     7349          uiCount0++;
     7350        }
     7351        else
     7352        {
     7353          uiSum1 += (piTemp[ uii ]);
     7354          uiCount1++;
     7355        }
     7356      }
     7357      piTemp += uiStride;
     7358    }
     7359    if( uiCount0 == 0 )
     7360      assert(false);
     7361    if( uiCount1 == 0 )
     7362      assert(false);
     7363    iDC0 = uiSum0 / uiCount0; // TODO : integer op.
     7364    iDC1 = uiSum1 / uiCount1;
     7365  }
     7366
     7367  // PredDC Calculation
     7368  {
     7369    UInt uiSum0 = 0;
     7370    UInt uiSum1 = 0;
     7371    UInt uiCount0 = 0;
     7372    UInt uiCount1 = 0;
     7373
     7374    for( UInt ui = 0; ui < uiWidth; ui++ )
     7375    {
     7376      if( pbRegion[ ui ] == false )
     7377      {
     7378        uiSum0 += (piMask[ ui + 1 ]);
     7379        uiCount0++;
     7380      }
     7381      else
     7382      {
     7383        uiSum1 += (piMask[ ui + 1 ]);
     7384        uiCount1++;
     7385      }
     7386    }
     7387    for( UInt ui = 0; ui < uiHeight; ui++ ) // (0,0) recount (to avoid division)
     7388    {
     7389      if( pbRegion[ ui * uiWidth ] == false )
     7390      {
     7391        uiSum0 += (piMask[ (ui + 1) * iMaskStride ]);
     7392        uiCount0++;
     7393      }
     7394      else
     7395      {
     7396        uiSum1 += (piMask[ (ui + 1) * iMaskStride ]);
     7397        uiCount1++;
     7398      }
     7399    }
     7400    if( uiCount0 == 0 )
     7401      assert(false);
     7402    if( uiCount1 == 0 )
     7403      assert(false);
     7404    iPredDC0 = uiSum0 / uiCount0; // TODO : integer op.
     7405    iPredDC1 = uiSum1 / uiCount1;
     7406  }
     7407
     7408  iDeltaDC0 = iDC0 - iPredDC0;
     7409  iDeltaDC1 = iDC1 - iPredDC1;
     7410
     7411#if HHI_VSO
     7412  if( m_pcRdCost->getUseVSO() )
     7413  {
     7414    Int iFullDeltaDC0 = iDeltaDC0;
     7415    Int iFullDeltaDC1 = iDeltaDC1;
     7416
     7417    xDeltaDCQuantScaleDown( pcCU, iFullDeltaDC0 );
     7418    xDeltaDCQuantScaleDown( pcCU, iFullDeltaDC1 );
     7419
     7420    Dist  uiBestDist     = RDO_DIST_MAX;
     7421    UInt  uiBestQStepDC0 = 0;
     7422    UInt  uiBestQStepDC1 = 0;
     7423
     7424    UInt uiDeltaDC0Max = abs(iFullDeltaDC0);
     7425    UInt uiDeltaDC1Max = abs(iFullDeltaDC1);
     7426
     7427    //VSO Level delta DC check range extension
     7428    uiDeltaDC0Max += (uiDeltaDC0Max>>1);
     7429    uiDeltaDC1Max += (uiDeltaDC1Max>>1);
     7430
     7431    for( UInt uiQStepDC0 = 1; uiQStepDC0 <= uiDeltaDC0Max; uiQStepDC0++  )
     7432    {
     7433      Int iLevelDeltaDC0 = (Int)(uiQStepDC0) * (Int)(( iFullDeltaDC0 < 0 ) ? -1 : 1);
     7434      xDeltaDCQuantScaleUp( pcCU, iLevelDeltaDC0 );
     7435
     7436      Int iTestDC0 = Clip( iPredDC0 + iLevelDeltaDC0 );
     7437      for( UInt uiQStepDC1 = 1; uiQStepDC1 <= uiDeltaDC1Max; uiQStepDC1++  )
     7438      {
     7439        Int iLevelDeltaDC1 = (Int)(uiQStepDC1) * (Int)(( iFullDeltaDC1 < 0 ) ? -1 : 1);
     7440        xDeltaDCQuantScaleUp( pcCU, iLevelDeltaDC1 );
     7441
     7442        Int iTestDC1 = Clip( iPredDC1 + iLevelDeltaDC1 );
     7443
     7444        Pel* piTemp = piPredic;
     7445        for( UInt ui = 0; ui < uiHeight; ui++ )
     7446        {
     7447          for( UInt uii = 0; uii < uiWidth; uii++ )
     7448          {
     7449            if( pbRegion[ ui * uiWidth + uii ] == false )
     7450            {
     7451              piTemp[ uii ] = iTestDC0;
     7452            }
     7453            else
     7454            {
     7455              piTemp[ uii ] = iTestDC1;
     7456            }
     7457          }
     7458          piTemp += uiStride;
     7459        }
     7460
     7461        Dist uiActDist = m_pcRdCost->getDistVS( pcCU, 0, piPredic, uiStride,  piOrig, uiStride, uiWidth, uiHeight, false, 0 );
     7462        if( uiActDist < uiBestDist || uiBestDist == RDO_DIST_MAX )
     7463        {
     7464          uiBestDist     = uiActDist;
     7465          uiBestQStepDC0 = uiQStepDC0;
     7466          uiBestQStepDC1 = uiQStepDC1;
     7467        }
     7468      }
     7469    }
     7470
     7471    iFullDeltaDC0 = (Int)(uiBestQStepDC0) * (Int)(( iFullDeltaDC0 < 0 ) ? -1 : 1);
     7472    iFullDeltaDC1 = (Int)(uiBestQStepDC1) * (Int)(( iFullDeltaDC1 < 0 ) ? -1 : 1);
     7473    xDeltaDCQuantScaleUp( pcCU, iFullDeltaDC0 );
     7474    xDeltaDCQuantScaleUp( pcCU, iFullDeltaDC1 );
     7475    iDeltaDC0 = iFullDeltaDC0;
     7476    iDeltaDC1 = iFullDeltaDC1;
     7477  }
     7478#endif
     7479
     7480  xDeltaDCQuantScaleDown( pcCU, iDeltaDC0 );
     7481  xDeltaDCQuantScaleDown( pcCU, iDeltaDC1 );
     7482
     7483  pcCU->setEdgeDeltaDC0( uiAbsPartIdx, iDeltaDC0 );
     7484  pcCU->setEdgeDeltaDC1( uiAbsPartIdx, iDeltaDC1 );
     7485}
     7486#endif
     7487#endif
     7488
    62097489//! \}
  • trunk/source/Lib/TLibEncoder/TEncSearch.h

    r77 r100  
    189189                                  TComYuv*    pcOrgYuv,
    190190#if LG_RESTRICTEDRESPRED_M24766
    191                                                                   TComYuv*     rpcResiPredYuv,
     191                                  TComYuv*    rpcResiPredYuv,
    192192#endif
    193193                                  TComYuv*&   rpcPredYuv,
     
    259259                                    TComYuv*     pcPredYuv,
    260260                                    TComYuv*     pcResiYuv,
    261                                     Dist&        ruiDist );
     261                                    Dist&        ruiDist
     262#if LG_ZEROINTRADEPTHRESI_M26039
     263                                   ,Bool        bZeroResi = false
     264#endif
     265                                   );
    262266  Void  xIntraCodingChromaBlk     ( TComDataCU*  pcCU,
    263267                                    UInt         uiTrDepth,
     
    278282                                    Dist&        ruiDistC,
    279283#if HHI_RQT_INTRA_SPEEDUP
    280                                    Bool         bCheckFirst,
    281 #endif
    282                                    Double&      dRDCost );
     284                                    Bool         bCheckFirst,
     285#endif
     286                                    Double&      dRDCost
     287#if LG_ZEROINTRADEPTHRESI_M26039
     288                                   ,Bool         bZeroResi = false
     289#endif
     290                                  );
    283291 
    284292  Void  xSetIntraResultQT         ( TComDataCU*  pcCU,
     
    321329                                    Bool           bLeftAvail );
    322330#endif
     331
     332#if LGE_EDGE_INTRA
     333  Bool  xEdgePartition       ( TComDataCU* pcCU, UInt uiPartIdx, Bool bPU4x4 );
     334  Bool  xCheckTerminatedEdge ( Bool* pbEdge, Int iX, Int iY, Int iWidth, Int iHeight );
     335  Bool  xConstructChainCode  ( TComDataCU* pcCU, UInt uiPartIdx, Bool bPU4x4 );
     336#if LGE_EDGE_INTRA_DELTA_DC
     337  Void  xAssignEdgeIntraDeltaDCs( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piOrig, UInt uiStride, Pel* piPredic, UInt uiWidth, UInt uiHeight );
     338#endif
     339#endif
     340
    323341#if HHI_DMM_WEDGE_INTRA
    324342  Void findWedgeFullMinDist       ( TComDataCU*    pcCU,
     
    444462                                    TComYuv*        pcYuvOrg,
    445463#if LG_RESTRICTEDRESPRED_M24766
    446                                                                         TComYuv*        rpcResiPredYuv,
     464                                    TComYuv*        rpcResiPredYuv,
    447465#endif
    448466                                    Int             iPartIdx,
  • trunk/source/Lib/TLibEncoder/TEncSlice.cpp

    r77 r100  
    3838#include "TEncTop.h"
    3939#include "TEncSlice.h"
     40#if HHI_VSO_SPEEDUP_A033
     41#include "../../App/TAppEncoder/TAppEncTop.h"
     42#endif
    4043#include <math.h>
     44#if SAIT_VSO_EST_A0033
     45extern Double g_dDispCoeff;
     46#endif
    4147
    4248//! \ingroup TLibEncoder
     
    627633  TComSlice* pcSlice            = rpcPic->getSlice(getSliceIdx());
    628634  xDetermineStartAndBoundingCUAddr ( uiStartCUAddr, uiBoundingCUAddr, rpcPic, false );
     635#if LG_ZEROINTRADEPTHRESI_M26039
     636  rpcPic->setIntraPeriod(this->m_pcCfg->getIntraPeriod());
     637#endif
    629638 
    630639  // initialize cost values
     
    702711  m_pcEntropyCoder->setMaxAlfCtrlDepth(0); //unnecessary
    703712 
     713#if SAIT_VSO_EST_A0033
     714 if( m_pcCfg->getUseVSO() )
     715 {
     716   m_pcRdCost->setDisparityCoeff( g_dDispCoeff );  // Temp. code!!!
     717   //printf( "Disp Coeff : %3.4f \n", m_pcRdCost->getDisparityCoeff() );
     718
     719   Int frameWidth = m_pcCfg->getSourceWidth();
     720   Pel* pVideoRec = m_pcRdCost->getVideoRecPicYuv()->getLumaAddr();
     721   Int iVideoRecStride = m_pcRdCost->getVideoRecPicYuv()->getStride();
     722
     723   Pel* pDepthOrg = m_pcRdCost->getDepthPicYuv()->getLumaAddr();
     724   Int iDepthOrgStride = m_pcRdCost->getDepthPicYuv()->getStride();
     725
     726   for( Int y = 0 ; y < m_pcCfg->getSourceHeight() ; y++ )
     727   {
     728     pVideoRec[-4] = pVideoRec[-3] = pVideoRec[-2] = pVideoRec[-1] = pVideoRec[0];
     729     pVideoRec[frameWidth+3] = pVideoRec[frameWidth+2] = pVideoRec[frameWidth+1] = pVideoRec[frameWidth] = pVideoRec[frameWidth-1];
     730     pDepthOrg[-4] = pDepthOrg[-3] = pDepthOrg[-2] = pDepthOrg[-1] = pDepthOrg[0];
     731     pDepthOrg[frameWidth+3] = pDepthOrg[frameWidth+2] = pDepthOrg[frameWidth+1] = pDepthOrg[frameWidth] = pDepthOrg[frameWidth-1];
     732
     733     pVideoRec += iVideoRecStride;
     734     pDepthOrg += iDepthOrgStride;
     735   }
     736 }
     737#endif
    704738  TEncTop* pcEncTop = (TEncTop*) m_pcCfg;
    705739  TEncSbac**** ppppcRDSbacCoders    = pcEncTop->getRDSbacCoders();
     
    753787  UInt uiTileLCUX     = 0;
    754788
     789#if HHI_VSO_SPEEDUP_A033
     790  Int iLastPosY = -1;
     791#endif
     792
    755793  // for every CU in slice
    756794  UInt uiEncCUOrder;
     
    763801    TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );
    764802    pcCU->initCU( rpcPic, uiCUAddr );
     803
     804#if HHI_VSO_SPEEDUP_A033
     805    if ( m_pcRdCost->getUseRenModel() )
     806    {
     807      // updated renderer model if necessary
     808      Int iCurPosX;
     809      Int iCurPosY;
     810      pcCU->getPosInPic(0, iCurPosX, iCurPosY );
     811      if ( iCurPosY != iLastPosY )
     812      {
     813        iLastPosY = iCurPosY;
     814       
     815        m_pcGOPEncoder->getEncTop()->getEncTop()->setupRenModel( rpcPic->getCurrSlice()->getPOC() , rpcPic->getCurrSlice()->getSPS()->getViewId(), rpcPic->getCurrSlice()->getSPS()->isDepth() ? 1 : 0, iCurPosY );
     816      }
     817    }   
     818#endif
     819
    765820
    766821    // inherit from TR if necessary, select substream to use.
  • trunk/source/Lib/TLibEncoder/TEncTop.cpp

    r77 r100  
    597597  // mark it should be extended
    598598  rpcPic->getPicYuvRec()->setBorderExtension(false);
     599#if FIXES
     600  rpcPic->getPicYuvOrg()->setBorderExtension(false);
     601#endif
    599602}
    600603
     
    981984Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid,TComList<TComPic*>& listPic )
    982985{
    983 #if HHI_FIX
    984986  if( slice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDV && POCCurr == 0 )
    985 #else
    986   if( slice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDV )
    987 #endif
    988987  {
    989988    TComReferencePictureSet* rps = slice->getLocalRPS();
Note: See TracChangeset for help on using the changeset viewer.