Changeset 189 in 3DVCSoftware for trunk/source/Lib/TLibEncoder/TEncSbac.cpp


Ignore:
Timestamp:
18 Nov 2012, 22:11:37 (13 years ago)
Author:
tech
Message:

Reintegrated branch 4.1-dev0 Rev. 188.

File:
1 edited

Legend:

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

    r116 r189  
    4242#include <algorithm>
    4343
     44#if RWTH_SDC_DLT_B0036
     45#define GetNumDepthValues()     (pcCU->getSlice()->getSPS()->getNumDepthValues())
     46#define GetBitsPerDepthValue()  (pcCU->getSlice()->getSPS()->getBitsPerDepthValue())
     47#endif
     48
    4449//! \ingroup TLibEncoder
    4550//! \{
     
    6065, m_cCUSplitFlagSCModel       ( 1,             1,               NUM_SPLIT_FLAG_CTX            , m_contextModels + m_numContextModels, m_numContextModels )
    6166, m_cCUSkipFlagSCModel        ( 1,             1,               NUM_SKIP_FLAG_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
     67#if LGE_ILLUCOMP_B0045
     68, m_cCUICFlagSCModel          ( 1,             1,               NUM_IC_FLAG_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
     69#endif
    6270, m_cCUMergeFlagExtSCModel    ( 1,             1,               NUM_MERGE_FLAG_EXT_CTX        , m_contextModels + m_numContextModels, m_numContextModels)
    6371, m_cCUMergeIdxExtSCModel     ( 1,             1,               NUM_MERGE_IDX_EXT_CTX         , m_contextModels + m_numContextModels, m_numContextModels)
     
    106114, m_cDmmDataSCModel           ( 1,             1,               NUM_DMM_DATA_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    107115#endif
    108 #if LGE_EDGE_INTRA
     116#if LGE_EDGE_INTRA_A0070
    109117, m_cEdgeIntraSCModel         ( 1,             1,               NUM_EDGE_INTRA_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
    110118#if LGE_EDGE_INTRA_DELTA_DC
     
    112120#endif
    113121#endif
     122#if RWTH_SDC_DLT_B0036
     123, m_cSDCFlagSCModel             ( 1,             1,                 SDC_NUM_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
     124, m_cSDCResidualFlagSCModel     ( 1,             2,  SDC_NUM_RESIDUAL_FLAG_CTX  , m_contextModels + m_numContextModels, m_numContextModels)
     125, m_cSDCResidualSignFlagSCModel ( 1,             2,  SDC_NUM_SIGN_FLAG_CTX      , m_contextModels + m_numContextModels, m_numContextModels)
     126, m_cSDCResidualSCModel         ( 1,             2,  SDC_NUM_RESIDUAL_CTX       , m_contextModels + m_numContextModels, m_numContextModels)
     127, m_cSDCPredModeSCModel             ( 1,             3,                 SDC_NUM_PRED_MODE_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
     128#endif
    114129{
    115130  assert( m_numContextModels <= MAX_NUM_CTX_MOD );
     
    141156 
    142157  m_cCUSkipFlagSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG );
     158#if LGE_ILLUCOMP_B0045
     159  m_cCUICFlagSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_IC_FLAG );
     160#endif
    143161  m_cCUAlfCtrlFlagSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_ALF_CTRL_FLAG );
    144162  m_cCUMergeFlagExtSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT);
     
    187205  m_cDmmDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_DATA );
    188206#endif
    189 #if LGE_EDGE_INTRA
     207#if LGE_EDGE_INTRA_A0070
    190208  m_cEdgeIntraSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_EDGE_INTRA );
    191209#if LGE_EDGE_INTRA_DELTA_DC
    192210  m_cEdgeIntraDeltaDCSCModel.initBuffer  ( eSliceType, iQp, (UChar*)INIT_EDGE_INTRA_DELTA_DC );
    193211#endif
     212#endif
     213#if RWTH_SDC_DLT_B0036
     214  m_cSDCFlagSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG );
     215  m_cSDCResidualFlagSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
     216  m_cSDCResidualSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL );
     217  m_cSDCResidualSignFlagSCModel.initBuffer  ( eSliceType, iQp, (UChar*)INIT_SDC_SIGN_FLAG );
     218  m_cSDCPredModeSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_SDC_PRED_MODE );
    194219#endif
    195220
     
    224249      curCost  = m_cCUSplitFlagSCModel.calcCost       ( curSliceType, qp, (UChar*)INIT_SPLIT_FLAG );
    225250      curCost += m_cCUSkipFlagSCModel.calcCost        ( curSliceType, qp, (UChar*)INIT_SKIP_FLAG );
     251#if LGE_ILLUCOMP_B0045
     252      curCost += m_cCUICFlagSCModel.calcCost          ( curSliceType, qp, (UChar*)INIT_IC_FLAG );
     253#endif
    226254      curCost += m_cCUAlfCtrlFlagSCModel.calcCost     ( curSliceType, qp, (UChar*)INIT_ALF_CTRL_FLAG );
    227255      curCost += m_cCUMergeFlagExtSCModel.calcCost    ( curSliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT);
     
    279307  } 
    280308
    281   #if CABAC_INIT_FLAG && POZNAN_CABAC_INIT_FLAG_FIX
     309  #if CABAC_INIT_FLAG && FIX_POZNAN_CABAC_INIT_FLAG
    282310    m_pcSlice->getPPS()->setEncPrevPOC( m_pcSlice->getPOC() );
    283311  #endif
     
    295323 
    296324  m_cCUSkipFlagSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG );
     325#if LGE_ILLUCOMP_B0045
     326  m_cCUICFlagSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_IC_FLAG );
     327#endif
    297328  m_cCUAlfCtrlFlagSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_ALF_CTRL_FLAG );
    298329  m_cCUMergeFlagExtSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT);
     
    341372  m_cDmmDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_DATA );
    342373#endif
     374#if RWTH_SDC_DLT_B0036
     375  m_cSDCFlagSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG );
     376  m_cSDCResidualFlagSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
     377  m_cSDCResidualSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL );
     378  m_cSDCResidualSignFlagSCModel.initBuffer  ( eSliceType, iQp, (UChar*)INIT_SDC_SIGN_FLAG );
     379  m_cSDCPredModeSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_SDC_PRED_MODE );
     380#endif
    343381 
    344382  m_pcBinIf->start();
     
    580618{
    581619  PartSize eSize         = pcCU->getPartitionSize( uiAbsPartIdx );
    582 #if OL_DEPTHLIMIT_A0044
    583   UInt uiSymbol;
    584 #endif
     620
     621#if OL_QTLIMIT_PREDCODING_B0068
     622  TComSPS *sps           = pcCU->getPic()->getSlice(0)->getSPS();
     623  TComPic *pcTexture     = pcCU->getSlice()->getTexturePic();
     624  Bool bDepthMapDetect   = (pcTexture != NULL);
     625  Bool bIntraSliceDetect = (pcCU->getSlice()->getSliceType() == I_SLICE);
     626 
     627  if(bDepthMapDetect && !bIntraSliceDetect && sps->getUseQTLPC() && pcCU->getPic()->getReduceBitsFlag())
     628  {
     629    TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr());
     630    UInt uiCUIdx            = (pcCU->getZorderIdxInCU() == 0) ? uiAbsPartIdx : pcCU->getZorderIdxInCU();
     631    assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth);
     632    if (pcTextureCU->getDepth(uiCUIdx) == uiDepth && pcTextureCU->getPartitionSize( uiCUIdx ) != SIZE_NxN)
     633    {
     634      assert( eSize == SIZE_2Nx2N );
     635      return;
     636    }
     637  }
     638#endif
     639
    585640  if ( pcCU->isIntra( uiAbsPartIdx ) )
    586641  {
     
    588643    {
    589644      m_pcBinIf->encodeBin( eSize == SIZE_2Nx2N? 1 : 0, m_cCUPartSizeSCModel.get( 0, 0, 0 ) );
    590 #if OL_DEPTHLIMIT_A0044
    591       if(pcCU->getPartDumpFlag())
    592       {
    593         uiSymbol = (UInt)(eSize == SIZE_2Nx2N? 1 : 0);
    594         pcCU->updatePartInfo(uiSymbol?0:1,uiDepth); //0 for 2Nx2N and 1 for NxN
    595         pcCU->incrementPartInfo();
    596       }
    597 #endif
    598     }
    599 #if OL_DEPTHLIMIT_A0044
    600     if(pcCU->getPartDumpFlag() && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth && !pcCU->getSlice()->isIntra())
    601     {
    602       pcCU->updatePartInfo(0,uiDepth); //0 for 2Nx2N and 1 for NxN
    603       pcCU->incrementPartInfo();
    604     }
    605 #endif
     645    }
    606646    return;
    607647  }
     
    612652    {
    613653      m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) );
    614 #if OL_DEPTHLIMIT_A0044
    615       if(pcCU->getPartDumpFlag())
    616       {
    617         pcCU->updatePartInfo(0,uiDepth); //0 for 2Nx2N
    618         pcCU->incrementPartInfo();
    619       }
    620 #endif
    621654      break;
    622655    }
     
    648681        }
    649682      }
    650 #if OL_DEPTHLIMIT_A0044
    651       if(pcCU->getPartDumpFlag())
    652       {
    653         pcCU->updatePartInfo(2,uiDepth); //2 for 2NxN
    654         pcCU->incrementPartInfo();
    655       }
    656 #endif
    657683      break;
    658684    }
     
    688714        }
    689715      }
    690 #if OL_DEPTHLIMIT_A0044
    691       if(pcCU->getPartDumpFlag())
    692       {
    693         pcCU->updatePartInfo(3,uiDepth); //3 for Nx2N
    694         pcCU->incrementPartInfo();
    695       }
    696 #endif
    697716      break;
    698717    }
     
    704723        m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) );
    705724        m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 2) );
    706 #if OL_DEPTHLIMIT_A0044
    707         if(pcCU->getPartDumpFlag())
    708         {
    709           pcCU->updatePartInfo(1,uiDepth); //2Nx2N here since we disable NxN in Inter
    710           pcCU->incrementPartInfo();         
    711         }
    712 #endif
    713       }
    714       else
    715       {
    716 #if OL_DEPTHLIMIT_A0044
    717         if(pcCU->getPartDumpFlag())
    718         {
    719           pcCU->updatePartInfo(0,uiDepth); //2Nx2N here since we disable NxN in Inter
    720           pcCU->incrementPartInfo();
    721         }
    722 #endif
    723725      }
    724726      break;
     
    738740Void TEncSbac::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx )
    739741{
     742#if RWTH_SDC_DLT_B0036
     743  if ( pcCU->getSlice()->isIntra() )
     744  {
     745    assert( pcCU->isIntra(uiAbsPartIdx) );
     746    return;
     747  }
     748#endif
     749 
    740750  // get context function is here
    741751  Int iPredMode = pcCU->getPredictionMode( uiAbsPartIdx );
     
    786796}
    787797
     798#if LGE_ILLUCOMP_B0045
     799/** code Illumination Compensation flag
     800 * \param pcCU
     801 * \param uiAbsPartIdx
     802 * \returns Void
     803 */
     804Void TEncSbac::codeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
     805{
     806  // get context function is here
     807  UInt uiSymbol = pcCU->getICFlag( uiAbsPartIdx ) ? 1 : 0;
     808  UInt uiCtxIC  = pcCU->getCtxICFlag( uiAbsPartIdx ) ;
     809  m_pcBinIf->encodeBin( uiSymbol, m_cCUICFlagSCModel.get( 0, 0, uiCtxIC ) );
     810  DTRACE_CABAC_VL( g_nSymbolCounter++ );
     811  DTRACE_CABAC_T( "\tICFlag" );
     812  DTRACE_CABAC_T( "\tuiCtxIC: ");
     813  DTRACE_CABAC_V( uiCtxIC );
     814  DTRACE_CABAC_T( "\tuiSymbol: ");
     815  DTRACE_CABAC_V( uiSymbol );
     816  DTRACE_CABAC_T( "\n");
     817}
     818#endif
     819
    788820/** code merge flag
    789821 * \param pcCU
     
    883915 
    884916  assert( uiCtx < 3 );
     917
     918#if OL_QTLIMIT_PREDCODING_B0068
     919  Bool bCodeSplitFlag    = true;
     920
     921  TComSPS *sps           = pcCU->getPic()->getSlice(0)->getSPS();
     922  TComPic *pcTexture     = pcCU->getSlice()->getTexturePic();
     923  Bool bDepthMapDetect   = (pcTexture != NULL);
     924  Bool bIntraSliceDetect = (pcCU->getSlice()->getSliceType() == I_SLICE);
     925
     926  if(bDepthMapDetect && !bIntraSliceDetect && sps->getUseQTLPC() && pcCU->getPic()->getReduceBitsFlag())
     927  {
     928    TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr());
     929    UInt uiCUIdx            = (pcCU->getZorderIdxInCU() == 0) ? uiAbsPartIdx : pcCU->getZorderIdxInCU();
     930    assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth);
     931    bCodeSplitFlag          = (pcTextureCU->getDepth(uiCUIdx) > uiDepth);
     932  }
     933
     934  if(!bCodeSplitFlag)
     935  {
     936    assert(uiCurrSplitFlag == 0);
     937    return;
     938  }
     939#endif
     940
    885941  m_pcBinIf->encodeBin( uiCurrSplitFlag, m_cCUSplitFlagSCModel.get( 0, 0, uiCtx ) );
    886 #if OL_DEPTHLIMIT_A0044
    887   if(pcCU->getPartDumpFlag())
    888   {
    889     if(pcCU->getSlice()->isIntra() || (!pcCU->getSlice()->isIntra() && uiCurrSplitFlag!=0))
    890     {
    891       pcCU->updatePartInfo(uiCurrSplitFlag,uiDepth);
    892       pcCU->incrementPartInfo();
    893     }
    894   }
    895 #endif
    896942  DTRACE_CABAC_VL( g_nSymbolCounter++ )
    897943  DTRACE_CABAC_T( "\tSplitFlag\n" )
     
    911957}
    912958
    913 #if LGE_EDGE_INTRA
     959#if LGE_EDGE_INTRA_A0070
    914960Void TEncSbac::xCodeEdgeIntraInfo( TComDataCU* pcCU, UInt uiPartIdx )
    915961{
     
    9921038  if( pcCU->getSlice()->getSPS()->getUseDMM() && pcCU->getWidth( uiAbsPartIdx ) <= DMM_WEDGEMODEL_MAX_SIZE )
    9931039  {
    994 #if LGE_EDGE_INTRA
     1040#if LGE_EDGE_INTRA_A0070
    9951041    m_pcBinIf->encodeBin( uiDir >= NUM_INTRA_MODE && uiDir < EDGE_INTRA_IDX, m_cDmmFlagSCModel.get(0, 0, 0) );
    9961042#else
     
    9981044#endif
    9991045  }
    1000 #if LGE_EDGE_INTRA
     1046#if LGE_EDGE_INTRA_A0070
    10011047  if( uiDir >= NUM_INTRA_MODE && uiDir < EDGE_INTRA_IDX )
    10021048#else
     
    10351081  }
    10361082  else
    1037 #if LGE_EDGE_INTRA
     1083#if LGE_EDGE_INTRA_A0070
    10381084    if ( uiDir >= EDGE_INTRA_IDX)
    10391085    {
     
    10701116  Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx);
    10711117#endif
    1072 #if LGE_EDGE_INTRA
     1118#if LGE_EDGE_INTRA_A0070
    10731119  Bool bCodeEdgeIntra = false;
    10741120  if( pcCU->getSlice()->getSPS()->isDepth() )
     
    11361182#if LOGI_INTRA_NAME_3MPM
    11371183    m_pcBinIf->encodeBinsEP( uiDir, 5 );
    1138 #if LGE_EDGE_INTRA
     1184#if LGE_EDGE_INTRA_A0070
    11391185  if (bCodeEdgeIntra)
    11401186    if (uiDir == 31) m_pcBinIf->encodeBinsEP(0,1);
     
    24782524}
    24792525
    2480 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX || (LGE_EDGE_INTRA && LGE_EDGE_INTRA_DELTA_DC)
     2526#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX || (LGE_EDGE_INTRA_A0070 && LGE_EDGE_INTRA_DELTA_DC)
    24812527Void TEncSbac::xWriteExGolombLevel( UInt uiSymbol, ContextModel& rcSCModel  )
    24822528{
     
    26442690}
    26452691#endif
     2692
     2693#if RWTH_SDC_DLT_B0036
     2694Void TEncSbac::codeSDCPredMode( TComDataCU* pcCU, UInt uiAbsPartIdx )
     2695{
     2696  assert( pcCU->getSlice()->getSPS()->isDepth() );
     2697  assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
     2698  assert( pcCU->getSDCFlag(uiAbsPartIdx) );
     2699 
     2700  UInt uiPredMode     = pcCU->getLumaIntraDir(uiAbsPartIdx);
     2701  UInt uiCtx          = 0;
     2702 
     2703  UInt uiMPModeIdx    = 0;
     2704 
     2705  for(Int i=0; i<RWTH_SDC_NUM_PRED_MODES-1; i++)
     2706  {
     2707    UInt uiBit = (uiPredMode == g_auiSDCPredModes[uiMPModeIdx]) ? 1 : 0;
     2708    m_pcBinIf->encodeBin( uiBit, m_cSDCPredModeSCModel.get( 0, i, uiCtx ) );
     2709   
     2710    // if mode is most probable mode, we are done here
     2711    if ( uiBit == 1 )
     2712      break;
     2713   
     2714    // else: get next most probable pred mode
     2715    uiMPModeIdx = (uiMPModeIdx+1)%RWTH_SDC_NUM_PRED_MODES;
     2716  }
     2717 
     2718#if HHI_DMM_WEDGE_INTRA
     2719  if( uiPredMode == DMM_WEDGE_FULL_IDX )          { xCodeWedgeFullInfo          ( pcCU, uiAbsPartIdx ); }
     2720  if( uiPredMode == DMM_WEDGE_PREDDIR_IDX )       { xCodeWedgePredDirInfo       ( pcCU, uiAbsPartIdx ); }
     2721#endif
     2722 
     2723  AOF(uiPredMode == g_auiSDCPredModes[uiMPModeIdx]);
     2724}
     2725
     2726Void TEncSbac::codeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
     2727{
     2728  // get context function is here
     2729  UInt uiSymbol = pcCU->getSDCFlag( uiAbsPartIdx ) ? 1 : 0;
     2730  UInt uiCtxSDCFlag = pcCU->getCtxSDCFlag( uiAbsPartIdx );
     2731  m_pcBinIf->encodeBin( uiSymbol, m_cSDCFlagSCModel.get( 0, 0, uiCtxSDCFlag ) );
     2732 
     2733}
     2734
     2735Void TEncSbac::codeSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment )
     2736{
     2737  assert( pcCU->getSlice()->getSPS()->isDepth() );
     2738  assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
     2739  assert( pcCU->getSDCFlag(uiAbsPartIdx) );
     2740  assert( uiSegment < 2 );
     2741 
     2742  Pel segmentDCOffset = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
     2743 
     2744  UInt uiResidual = segmentDCOffset == 0 ? 0 : 1;
     2745  UInt uiSign     = segmentDCOffset < 0 ? 1 : 0;
     2746  UInt uiAbsIdx   = abs(segmentDCOffset);
     2747  UInt uiBit = 0;
     2748 
     2749  UInt uiMaxResidualBits  = GetBitsPerDepthValue();
     2750  assert( uiMaxResidualBits <= g_uiBitDepth );
     2751 
     2752  // residual flag
     2753  m_pcBinIf->encodeBin( uiResidual, m_cSDCResidualFlagSCModel.get( 0, uiSegment, 0 ) ); //TODO depthmap: more sophisticated context selection
     2754 
     2755  if (uiResidual)
     2756  {
     2757    // encode sign bit of residual
     2758    m_pcBinIf->encodeBin( uiSign, m_cSDCResidualSignFlagSCModel.get( 0, uiSegment, 0 ) ); //TODO depthmap: more sophisticated context selection
     2759       
     2760    assert(uiAbsIdx < GetNumDepthValues());
     2761   
     2762    // encode residual magnitude
     2763    uiAbsIdx -= 1;
     2764    for (Int i=0; i<uiMaxResidualBits; i++)
     2765    {
     2766      uiBit = (uiAbsIdx & (1<<i))>>i;
     2767     
     2768      m_pcBinIf->encodeBin( uiBit, m_cSDCResidualSCModel.get( 0, uiSegment, i ) ); //TODO depthmap: more sophisticated context selection
     2769    }
     2770   
     2771  }
     2772}
     2773#endif
    26462774//! \}
Note: See TracChangeset for help on using the changeset viewer.