Skip to content
Snippets Groups Projects
IntraSearch.cpp 589 KiB
Newer Older
  • Learn to ignore specific revisions
  •                     CHECK(!m_intraModeReady[iMode], "OBIC mode is not ready!");
                        PelBuf predBufTmp(m_intraPredBuf[iMode], pu.Y());
                        predFusion[idx].copyFrom(predBufTmp);
                        if (iMode == PLANAR_IDX)
                        {
                          planarIdx = idx;
                        }
                      }
                      else
                      {
                        PelBuf planarBuf(m_intraPredBuf[PLANAR_IDX], pu.Y());
                        predFusion[idx].copyFrom(planarBuf);
                      }
                    }
                    if (cu.obicIsBlended)
                    {
                      generateObicBlending(piPred, pu, predFusion, blendModes, planarIdx);
                    }
                    else
                    {
                      initIntraPatternChType(cu, pu.Y(), false);
                      predIntraAng(COMPONENT_Y, piPred, pu);
                    }
                    PelBuf obicSaveBuf(m_obicPredBuf, pu.Y());
                    obicSaveBuf.copyFrom(piPred);
    
    #if JVET_AJ0249_NEURAL_NETWORK_BASED
                    m_isObicPredictionSaved = true;
    #endif
    
                    Distortion sadCost = distParamSad.distFunc(distParamSad);
                    Distortion minSadHadObic = std::min(sadCost * 2, distParamHad.distFunc(distParamHad));
                    m_satdCostOBIC = minSadHadObic;
                  }
                  if (dimdSaveFlag)
                  {
                    cu.obicFlag = false;
                    int dimdMode = cu.dimdMode;
                    pu.intraDir[CHANNEL_TYPE_LUMA] = dimdMode;
                    if (cu.dimdBlending)
                    {
    #if JVET_AH0209_PDP
                      PelBuf predBuf(m_pdpIntraPredReady[dimdMode]? m_pdpIntraPredBuf[dimdMode] : m_intraPredBuf[dimdMode], tmpArea);
    #else
                     PelBuf predBuf(m_intraPredBuf[dimdMode], tmpArea);
    #endif
                      piPred.copyFrom(predBuf);
    
    Vadim Seregin's avatar
    Vadim Seregin committed
    #if JVET_AJ0267_ADAPTIVE_HOG
                      PelBuf predFusion[ DIMD_FUSION_NUM - 2 ];
                      const UnitArea localUnitArea( pu.chromaFormat, Area( 0, 0, iWidth, iHeight ) );
                      for( int i = 0; i < DIMD_FUSION_NUM - 2; i++ )
                      {
                        predFusion[ i ] = m_tempBuffer[ i + 1 ].getBuf( localUnitArea.Y() );
    #if JVET_AH0209_PDP
                        dimdMode = cu.dimdBlendMode[ i ] > 0 ? cu.dimdBlendMode[ i ] : PLANAR_IDX;
                        PelBuf predBufTmp( dimdMode && m_pdpIntraPredReady[ dimdMode ] ? m_pdpIntraPredBuf[ dimdMode ] : m_intraPredBuf[ dimdMode ], tmpArea );
    #else
                        PelBuf predBufTmp( ( m_intraPredBuf[ cu.dimdBlendMode[ i ] > 0 ? cu.dimdBlendMode[ i ] : PLANAR_IDX ] ), tmpArea );
    #endif
                        predFusion[ i ].copyFrom( predBufTmp );
                      }
                      PelBuf planarBuf( m_intraPredBuf[ PLANAR_IDX ], tmpArea );
                      generateDimdBlending( piPred, pu, predFusion, planarBuf );
    #else
    
    #if JVET_AH0209_PDP
                      dimdMode = cu.dimdBlendMode[0] > 0 ? cu.dimdBlendMode[0] : PLANAR_IDX;
                      PelBuf blendBuf0(dimdMode && m_pdpIntraPredReady[dimdMode] ? m_pdpIntraPredBuf[dimdMode] : m_intraPredBuf[dimdMode], tmpArea);
                      dimdMode = cu.dimdBlendMode[1] > 0 ? cu.dimdBlendMode[1] : PLANAR_IDX;
                      PelBuf blendBuf1(dimdMode && m_pdpIntraPredReady[dimdMode] ? m_pdpIntraPredBuf[dimdMode] : m_intraPredBuf[dimdMode], tmpArea);
                      dimdMode = cu.dimdBlendMode[2] > 0 ? cu.dimdBlendMode[2] : PLANAR_IDX;
                      PelBuf blendBuf2(dimdMode && m_pdpIntraPredReady[dimdMode] ? m_pdpIntraPredBuf[dimdMode] : m_intraPredBuf[dimdMode], tmpArea);
                      dimdMode = cu.dimdBlendMode[3] > 0 ? cu.dimdBlendMode[3] : PLANAR_IDX;
                      PelBuf blendBuf3(dimdMode && m_pdpIntraPredReady[dimdMode] ? m_pdpIntraPredBuf[dimdMode] : m_intraPredBuf[dimdMode], tmpArea);
                      PelBuf planarBuf(m_intraPredBuf[PLANAR_IDX], tmpArea);
      #else
                      PelBuf blendBuf0((m_intraPredBuf[cu.dimdBlendMode[0] > 0 ?cu.dimdBlendMode[0] : PLANAR_IDX]), tmpArea);
                      PelBuf blendBuf1((m_intraPredBuf[cu.dimdBlendMode[1] > 0 ?cu.dimdBlendMode[1] : PLANAR_IDX]), tmpArea);
                      PelBuf blendBuf2((m_intraPredBuf[cu.dimdBlendMode[2] > 0 ?cu.dimdBlendMode[2] : PLANAR_IDX]), tmpArea);
                      PelBuf blendBuf3((m_intraPredBuf[cu.dimdBlendMode[3] > 0 ?cu.dimdBlendMode[3] : PLANAR_IDX]), tmpArea);
                      PelBuf planarBuf(m_intraPredBuf[PLANAR_IDX], tmpArea);
      #endif
                      generateDimdBlending(piPred, pu, blendBuf0, blendBuf1, blendBuf2, blendBuf3, planarBuf);
    
    Vadim Seregin's avatar
    Vadim Seregin committed
    #endif
    
                    }
                    else
                    {
                      initIntraPatternChType(cu, pu.Y(), false);
                      predIntraAng(COMPONENT_Y, piPred, pu);
                    }
                    PelBuf dimdSaveBuf(m_dimdPredBuf, pu.Y());
                    dimdSaveBuf.copyFrom(piPred);
    
    #if JVET_AJ0249_NEURAL_NETWORK_BASED
                    m_isDimdPredictionSaved = true;
    #endif
    
                    Distortion sadCost = distParamSad.distFunc(distParamSad);
                    Distortion minSadHadDimd = std::min(sadCost * 2, distParamHad.distFunc(distParamHad));
                    m_satdCostDIMD = minSadHadDimd;
                  }
                }
                cu.dimd = false;
                cu.obicFlag = false;
    #endif
                if (!cu.lfnstIdx && !cu.mtsFlag && testMip)
                {
                  // now reduce the candidates
                  const double thresholdHadCost = 1.0 + 1.4 / sqrt((double) (pu.lwidth() * pu.lheight()));
                  reduceHadCandList(uiRdModeList, candCostList, numModesForFullRD, thresholdHadCost, mipHadCostStore, pu, fastMip
    #if JVET_AB0157_TMRL
                   , tmrlCostList
    #endif
    #if JVET_AC0105_DIRECTIONAL_PLANAR
                    , dirPlanarCostList
    
    #endif
    #if JVET_AJ0146_TIMDSAD
                    , (modList ? 1 : 0)
    
                if (sps.getUseMIP() && LFNSTSaveFlag)
    
                  // save found best modes
                  m_uiSavedNumRdModesLFNST = numModesForFullRD;
                  m_uiSavedRdModeListLFNST = uiRdModeList;
    
                  m_dSavedModeCostLFNST    = candCostList;
    
                  // PBINTRA fast
                  m_uiSavedHadModeListLFNST = uiHadModeList;
    
                  LFNSTSaveFlag             = false;
    
    #if JVET_AJ0061_TIMD_MERGE
                  m_uiSavedRdModeListTimd   = timdModes;
                  m_uiSavedModeCostTimd     = timdCosts;
                  for (int i = numTimdSatd - 1; i >= 0; i--)
                  {
                    if(timdModes[i].mRefId > 0)
                    {
                      m_uiSavedRdModeListTimd.erase(m_uiSavedRdModeListTimd.begin() + i);
                      m_uiSavedModeCostTimd.erase(m_uiSavedModeCostTimd.begin() + i);
                    }
                  }
                  ModeInfo m;
                  for (int i = numModesForFullRD - 1; i >= 0; i--)
                  {
                    m = m_uiSavedRdModeListLFNST.at(i);
                    if (m.modeId == TIMD_IDX && m.mRefId)
                    {
                      m_uiSavedRdModeListLFNST.erase(m_uiSavedRdModeListLFNST.begin() + i);
                      m_dSavedModeCostLFNST.erase(m_dSavedModeCostLFNST.begin() + i);
                      m_uiSavedNumRdModesLFNST--;
                    }
                  }
                  for (int i = (int)(uiHadModeList.size()) - 1; i >= 0; i--)
                  {
                    m = m_uiSavedHadModeListLFNST.at(i);
                    if (m.modeId == TIMD_IDX && m.mRefId)
                    {
                      m_uiSavedHadModeListLFNST.erase(m_uiSavedHadModeListLFNST.begin() + i);
                      m_dSavedHadListLFNST.erase(m_dSavedHadListLFNST.begin() + i);
                    }
                  }
    #endif
    
              else   // if( sps.getUseMIP() && LFNSTLoadFlag)
              {
                // restore saved modes
                numModesForFullRD = m_uiSavedNumRdModesLFNST;
                uiRdModeList      = m_uiSavedRdModeListLFNST;
    
                candCostList      = m_dSavedModeCostLFNST;
    
                // PBINTRA fast
                uiHadModeList = m_uiSavedHadModeListLFNST;
    
    #if JVET_AJ0061_TIMD_MERGE
                timdModes     = m_uiSavedRdModeListTimd;
                timdCosts     = m_uiSavedModeCostTimd;
                if (cu.mtsFlag)
                {
                  for (int i = (int)timdModes.size() - 1; i >= 0; i--)
                  {
                    if (timdModes[i].modeId == TIMDM_IDX)
                    {
                      timdModes.erase(timdModes.begin() + i);
                      timdCosts.erase(timdCosts.begin() + i);
                    }
                  }
                }
    #endif
    
    #if JVET_AH0076_OBIC && !JVET_AJ0061_TIMD_MERGE
    
              if (obicSaveFlag || dimdSaveFlag)
              {
                cu.dimd = true;
                cu.obicFlag = false;
                cu.timd = false;
                cu.mipFlag = false;
                cu.tmpFlag = false;
                cu.tmrlFlag = false;
                cu.firstPU->multiRefIdx = 0;
                cu.ispMode = NOT_INTRA_SUBPARTITIONS;
                int iWidth = cu.lwidth();
                int iHeight = cu.lheight();
                if (obicSaveFlag)
                {
                  cu.obicFlag = true;
                  int obicMode = cu.obicMode[0];
                  pu.intraDir[CHANNEL_TYPE_LUMA] = obicMode;
                  bool blendModes[OBIC_FUSION_NUM - 1] = {false};
                  PelBuf predFusion[OBIC_FUSION_NUM - 1];
    
    #if JVET_AH0209_PDP
                  CHECK(!m_intraModeReady[obicMode] && !m_pdpIntraPredReady[obicMode], "OBIC mode is not ready!");
    #else
    
                  CHECK(!m_intraModeReady[obicMode], "OBIC mode is not ready!");
    
                  const UnitArea localUnitArea( pu.chromaFormat, Area( 0, 0, iWidth, iHeight ) );
    
    #if JVET_AH0209_PDP
                  PelBuf predBuf(m_pdpIntraPredReady[obicMode]? m_pdpIntraPredBuf[obicMode]: m_intraPredBuf[obicMode], pu.Y());
    #else
    
                  PelBuf predBuf(m_intraPredBuf[obicMode], pu.Y());
    
                  piPred.copyFrom(predBuf);
                  int planarIdx = 0;
                  for (int idx = 0; idx < OBIC_FUSION_NUM - 1; idx++)
                  {
                    blendModes[idx] = false;
                    predFusion[idx] = m_tempBuffer[idx].getBuf( localUnitArea.Y() );
                    int iMode = cu.obicMode[idx + 1];
                    if (iMode >= 0)
                    {
                      blendModes[idx] = true;
                      CHECK(!m_intraModeReady[iMode], "OBIC mode is not ready!");
                      PelBuf predBufTmp(m_intraPredBuf[iMode], pu.Y());
                      predFusion[idx].copyFrom(predBufTmp);
                      if (iMode == PLANAR_IDX)
                      {
                        planarIdx = idx;
                      }
                    }
                    else
                    {
                      PelBuf planarBuf(m_intraPredBuf[PLANAR_IDX], pu.Y());
                      predFusion[idx].copyFrom(planarBuf);
                    }
                  }
                  if (cu.obicIsBlended)
                  {
                    generateObicBlending(piPred, pu, predFusion, blendModes, planarIdx);
                  }
                  else
                  {
                    initIntraPatternChType(cu, pu.Y(), false);
                    predIntraAng(COMPONENT_Y, piPred, pu);
                  }
                  PelBuf obicSaveBuf(m_obicPredBuf, pu.Y());
                  obicSaveBuf.copyFrom(piPred);
    
    #if JVET_AJ0249_NEURAL_NETWORK_BASED
                  m_isObicPredictionSaved = true;
    #endif
    
                }
                if (dimdSaveFlag)
                {
                  cu.obicFlag = false;
                  int dimdMode = cu.dimdMode;
                  pu.intraDir[CHANNEL_TYPE_LUMA] = dimdMode;
                  if (cu.dimdBlending)
                  {
    
    #if JVET_AH0209_PDP
                    PelBuf predBuf(m_pdpIntraPredReady[dimdMode]? m_pdpIntraPredBuf[dimdMode] : m_intraPredBuf[dimdMode], tmpArea);
    #else
    
                    PelBuf predBuf(m_intraPredBuf[dimdMode], tmpArea);
    
    #if JVET_AJ0267_ADAPTIVE_HOG
                    PelBuf predFusion[DIMD_FUSION_NUM - 2];
                    const UnitArea localUnitArea( pu.chromaFormat, Area( 0, 0, iWidth, iHeight ) );
                    for (int i = 0; i < DIMD_FUSION_NUM - 2; i++)
                    {
                      predFusion[i] = m_tempBuffer[i+1].getBuf( localUnitArea.Y() );
    #if JVET_AH0209_PDP
                      dimdMode = cu.dimdBlendMode[i] > 0 ? cu.dimdBlendMode[i] : PLANAR_IDX;
                      PelBuf predBufTmp(dimdMode && m_pdpIntraPredReady[dimdMode] ? m_pdpIntraPredBuf[dimdMode] : m_intraPredBuf[dimdMode], tmpArea);
    #else
                      PelBuf predBufTmp((m_intraPredBuf[cu.dimdBlendMode[i] > 0 ?cu.dimdBlendMode[i] : PLANAR_IDX]), tmpArea);
    #endif
                      predFusion[i].copyFrom(predBufTmp);
                    }
                    PelBuf planarBuf(m_intraPredBuf[PLANAR_IDX], tmpArea);
                    generateDimdBlending(piPred, pu, predFusion, planarBuf);
    #else
    
    #if JVET_AH0209_PDP
                    dimdMode = cu.dimdBlendMode[0] > 0 ? cu.dimdBlendMode[0] : PLANAR_IDX;
                    PelBuf blendBuf0(dimdMode && m_pdpIntraPredReady[dimdMode] ? m_pdpIntraPredBuf[dimdMode] : m_intraPredBuf[dimdMode], tmpArea);
                    dimdMode = cu.dimdBlendMode[1] > 0 ? cu.dimdBlendMode[1] : PLANAR_IDX;
                    PelBuf blendBuf1(dimdMode && m_pdpIntraPredReady[dimdMode] ? m_pdpIntraPredBuf[dimdMode] : m_intraPredBuf[dimdMode], tmpArea);
                    dimdMode = cu.dimdBlendMode[2] > 0 ? cu.dimdBlendMode[2] : PLANAR_IDX;
                    PelBuf blendBuf2(dimdMode && m_pdpIntraPredReady[dimdMode] ? m_pdpIntraPredBuf[dimdMode] : m_intraPredBuf[dimdMode], tmpArea);
                    dimdMode = cu.dimdBlendMode[3] > 0 ? cu.dimdBlendMode[3] : PLANAR_IDX;
                    PelBuf blendBuf3(dimdMode && m_pdpIntraPredReady[dimdMode] ? m_pdpIntraPredBuf[dimdMode] : m_intraPredBuf[dimdMode], tmpArea);
                    PelBuf planarBuf(m_intraPredBuf[PLANAR_IDX], tmpArea);
    #else
    
                    PelBuf blendBuf0((m_intraPredBuf[cu.dimdBlendMode[0] > 0 ?cu.dimdBlendMode[0] : PLANAR_IDX]), tmpArea);
                    PelBuf blendBuf1((m_intraPredBuf[cu.dimdBlendMode[1] > 0 ?cu.dimdBlendMode[1] : PLANAR_IDX]), tmpArea);
                    PelBuf blendBuf2((m_intraPredBuf[cu.dimdBlendMode[2] > 0 ?cu.dimdBlendMode[2] : PLANAR_IDX]), tmpArea);
                    PelBuf blendBuf3((m_intraPredBuf[cu.dimdBlendMode[3] > 0 ?cu.dimdBlendMode[3] : PLANAR_IDX]), tmpArea);
                    PelBuf planarBuf(m_intraPredBuf[PLANAR_IDX], tmpArea);
    
                    generateDimdBlending(piPred, pu, blendBuf0, blendBuf1, blendBuf2, blendBuf3, planarBuf);
    
                  }
                  else
                  {
                    initIntraPatternChType(cu, pu.Y(), false);
                    predIntraAng(COMPONENT_Y, piPred, pu);
                  }
                  PelBuf dimdSaveBuf(m_dimdPredBuf, pu.Y());
                  dimdSaveBuf.copyFrom(piPred);
    
    #if JVET_AJ0249_NEURAL_NETWORK_BASED
                  m_isDimdPredictionSaved = true;
    #endif
    
    #if JVET_AJ0112_REGRESSION_SGPM
    
              if ((m_pcEncCfg->getUseFastLFNST() && !LFNSTLoadFlag) || !m_pcEncCfg->getUseFastLFNST() || mtsUsageFlag == 0)
    
    fan wang's avatar
    fan wang committed
              {
    
    #endif
    #if JVET_AB0155_SGPM
                if (testSgpm)
    
    fan wang's avatar
    fan wang committed
                {
    
                  if (SGPMSaveFlag)
                  {
                    m_uiSavedRdModeListSGPM.clear();
                    m_dSavedModeCostSGPM.clear();
                    m_uiSavedHadModeListSGPM.clear();
                    m_dSavedHadListSGPM.clear();
    
    #if JVET_V0130_INTRA_TMP
    
                    pu.multiRefIdx = 0;
                    cu.mipFlag = false;
    
    
    #if JVET_AJ0249_NEURAL_NETWORK_BASED
                    cu.sgpm = true;
    #endif
    
    #if JVET_AB0157_INTRA_FUSION
    
                    initIntraPatternChType(cu, pu.Y(), true, 0, false);
    
                    initIntraPatternChType(cu, pu.Y(), true);
    
    #if JVET_AJ0249_NEURAL_NETWORK_BASED
                    cu.sgpm = false;
    #endif
    
                    // get single mode predictions
                    for (int sgpmIdx = 0; sgpmIdx < SGPM_NUM; sgpmIdx++)
                    {
                      int      sgpmMode[2];
                      sgpmMode[0] = sgpmInfoList[sgpmIdx].sgpmMode0;
                      sgpmMode[1] = sgpmInfoList[sgpmIdx].sgpmMode1;
    
    #if JVET_AG0152_SGPM_ITMP_IBC
    
                      Mv      sgpmBV[2];
                      sgpmBV[0] = sgpmInfoList[sgpmIdx].sgpmBv0;
                      sgpmBV[1] = sgpmInfoList[sgpmIdx].sgpmBv1;
    
                      for (int idxIn2 = 0; idxIn2 < 2; idxIn2++)
    
    fan wang's avatar
    fan wang committed
                      {
    
                        if (!m_intraModeReady[sgpmMode[idxIn2]])
    
    #if JVET_AG0152_SGPM_ITMP_IBC 
                          if (sgpmMode[idxIn2] >= SGPM_BV_START_IDX)
                          {
                            // BV based mode
                            Mv timdBv = sgpmBV[idxIn2];
    
                            predUsingBv(piPred.buf, piPred.stride, timdBv, cu, false);
    
                            predUsingBv(piPred.buf, piPred.stride, timdBv, cu);
    
                            pu.intraDir[0] = sgpmMode[idxIn2];
    
                            initPredIntraParams(pu, pu.Y(), sps);
    
    #if JVET_AK0118_BF_FOR_INTRA_PRED
                            predIntraAng(COMPONENT_Y, piPred, pu, true, false, false);
    #else
    
                            predIntraAng(COMPONENT_Y, piPred, pu, false, false);
    
                            predIntraAng(COMPONENT_Y, piPred, pu, false);
    
                            predIntraAng(COMPONENT_Y, piPred, pu);
    
    #if JVET_AG0152_SGPM_ITMP_IBC
    
                          PelBuf predBuf(m_intraPredBuf[sgpmMode[idxIn2]], tmpArea);
                          predBuf.copyFrom(piPred);
                          m_intraModeReady[sgpmMode[idxIn2]] = 1;
                        }
    
                    cu.sgpm = true;
                    // frac bits calculate once because all are the same
                    cu.sgpmIdx = 0;
                    cu.sgpmSplitDir = sgpmInfoList[0].sgpmSplitDir;
                    cu.sgpmMode0 = sgpmInfoList[0].sgpmMode0;
                    cu.sgpmMode1 = sgpmInfoList[0].sgpmMode1;
    
    #if JVET_AG0152_SGPM_ITMP_IBC
    
                    cu.sgpmBv0 = sgpmInfoList[0].sgpmBv0;
                    cu.sgpmBv1 = sgpmInfoList[0].sgpmBv1;
                    pu.intraDir[0] = cu.sgpmMode0 >= SGPM_BV_START_IDX ? 0 : cu.sgpmMode0;
                    pu.intraDir1[0] = cu.sgpmMode1 >= SGPM_BV_START_IDX ? 0 : cu.sgpmMode1;
    
                    pu.intraDir[0] = cu.sgpmMode0;
                    pu.intraDir1[0] = cu.sgpmMode1;
    
    #if JVET_AJ0112_REGRESSION_SGPM
                    cu.blendModel = sgpmInfoList[0].blendModel;
    #endif
    #if !JVET_AJ0112_REGRESSION_SGPM
                    loadStartStates();
    
                    uint64_t fracModeBits = xFracModeBitsIntra(pu, 0, CHANNEL_TYPE_LUMA);
    #endif
    
                    for (int sgpmIdx = 0; sgpmIdx < SGPM_NUM; sgpmIdx++)
                    {
                      int sgpmMode0 = sgpmInfoList[sgpmIdx].sgpmMode0;
                      int sgpmMode1 = sgpmInfoList[sgpmIdx].sgpmMode1;
                      PelBuf src0(m_intraPredBuf[sgpmMode0], tmpArea);
                      PelBuf src1(m_intraPredBuf[sgpmMode1], tmpArea);
    #if JVET_AJ0112_REGRESSION_SGPM
                      cu.sgpmIdx = sgpmIdx;
                      loadStartStates();
                      uint64_t fracModeBits = xFracModeBitsIntra(pu, 0, CHANNEL_TYPE_LUMA);
                      if (sgpmInfoList[sgpmIdx].isRegression)
                      {
                        PelUnitBuf pred = PelUnitBuf(pu.chromaFormat, piPred);
                        PelUnitBuf pred0 = PelUnitBuf(pu.chromaFormat, src0);
                        PelUnitBuf pred1 = PelUnitBuf(pu.chromaFormat, src1);
                        m_blendBuf.resize(pu.lwidth() * pu.lheight());
                        int16_t* blendBuf = m_blendBuf.data();
                        WeightBuf bufWeight = WeightBuf(blendBuf, pu.lumaSize());
                        const int geoBlendingLog2WeightBase = 5;
                        pcInterPred->weightedAffineBlk(pu, bufWeight, geoBlendingLog2WeightBase, sgpmInfoList[sgpmIdx].blendModel);
                        pcInterPred->weightedBlendBlk(pu, 0, pred, pred0, pred1, bufWeight, geoBlendingLog2WeightBase, false);
                      }
                      else
                      {
    #if JVET_AJ0107_GPM_SHAPE_ADAPT
                        m_if.m_weightedSgpm(pu, width, height, COMPONENT_Y, g_sgpmSplitDir[sgpmInfoList[sgpmIdx].sgpmSplitDir], piPred, src0, src1);
    #else
                        m_if.m_weightedSgpm(pu, width, height, COMPONENT_Y, sgpmInfoList[sgpmIdx].sgpmSplitDir, piPred, src0, src1);
    #endif
                      }
    #else
    
    #if JVET_AJ0107_GPM_SHAPE_ADAPT
    
                      m_if.m_weightedSgpm(pu, width, height, COMPONENT_Y, g_sgpmSplitDir[sgpmInfoList[sgpmIdx].sgpmSplitDir], piPred, src0, src1);
    
                      m_if.m_weightedSgpm(pu, width, height, COMPONENT_Y, sgpmInfoList[sgpmIdx].sgpmSplitDir, piPred, src0, src1);
    #endif
    
                      PelBuf predBuf(m_sgpmPredBuf[sgpmIdx], tmpArea);
                      predBuf.copyFrom(piPred);
    
                      Distortion minSadHad = 0;
    
    #if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS
    
                      Distortion sadCost = distParamSad.distFunc(distParamSad);
                      minSadHad += std::min(sadCost * 2, distParamHad.distFunc(distParamHad));
    
                      minSadHad += std::min(distParamSad.distFunc(distParamSad) * 2, distParamHad.distFunc(distParamHad));
    
                      double cost = (double)minSadHad + (double)fracModeBits * sqrtLambdaForFirstPass;
    
    #if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS
    
                      m_bestIntraSADCost = std::min(m_bestIntraSADCost, cost - (double)minSadHad + (double)sadCost);
    
                      updateCandList(ModeInfo(false, false, 0, NOT_INTRA_SUBPARTITIONS, SGPM_IDX,
    
    #if JVET_V0130_INTRA_TMP
    
    #endif
    #if JVET_AD0086_ENHANCED_INTRA_TMP
    
    #if JVET_AG0136_INTRA_TMP_LIC
    
                        true, sgpmInfoList[sgpmIdx].sgpmSplitDir, sgpmInfoList[sgpmIdx].sgpmMode0,
                        sgpmInfoList[sgpmIdx].sgpmMode1, sgpmIdx
    
    #if JVET_AG0152_SGPM_ITMP_IBC
    
                        , sgpmInfoList[sgpmIdx].sgpmBv0, sgpmInfoList[sgpmIdx].sgpmBv1
    
    #if JVET_AJ0112_REGRESSION_SGPM
                        , sgpmInfoList[sgpmIdx].isRegression, sgpmInfoList[sgpmIdx].blendModel
    #endif
                      ),
                        cost, m_uiSavedRdModeListSGPM, m_dSavedModeCostSGPM, SGPM_NUM);
                      updateCandList(ModeInfo(false, false, 0, NOT_INTRA_SUBPARTITIONS, SGPM_IDX,
    
    #if JVET_V0130_INTRA_TMP
    
    #endif
    #if JVET_AD0086_ENHANCED_INTRA_TMP
    
    #if JVET_AG0136_INTRA_TMP_LIC
    
                        true, sgpmInfoList[sgpmIdx].sgpmSplitDir, sgpmInfoList[sgpmIdx].sgpmMode0,
                        sgpmInfoList[sgpmIdx].sgpmMode1, sgpmIdx
    
    #if JVET_AG0152_SGPM_ITMP_IBC
    
                        , sgpmInfoList[sgpmIdx].sgpmBv0, sgpmInfoList[sgpmIdx].sgpmBv1
    
    #if JVET_AJ0112_REGRESSION_SGPM
                        , sgpmInfoList[sgpmIdx].isRegression, sgpmInfoList[sgpmIdx].blendModel
    #endif
                      ),
                        double(minSadHad), m_uiSavedHadModeListSGPM, m_dSavedHadListSGPM, SGPM_NUM);
                    }
    
                    cu.sgpm = false;
                  }
    #if JVET_AJ0112_REGRESSION_SGPM
                  numModesForFullRD++;
                  int updateNum = (int)m_uiSavedRdModeListSGPM.size();
    #else
                  int updateNum = std::min<int>((numModesForFullRD + 1) / 2, (int)m_uiSavedRdModeListSGPM.size());
    #endif
                  for (auto listIdx = 0; listIdx < updateNum; listIdx++)
                  {
                    updateCandList(m_uiSavedRdModeListSGPM[listIdx], m_dSavedModeCostSGPM[listIdx], uiRdModeList,
                      candCostList, numModesForFullRD);
                    updateCandList(m_uiSavedHadModeListSGPM[listIdx], m_dSavedHadListSGPM[listIdx], uiHadModeList,
                      candHadList, numHadCand);
                  }
    
    fan wang's avatar
    fan wang committed
                }
    #endif
    
    #if JVET_AJ0146_TIMDSAD
              cu.timd = false;
              cu.timdSad = false;
    #if !JVET_AJ0061_TIMD_MERGE		  
              if (testTimd)
              {
                if (timdSaveFlag)
                {
                  cu.timdSad = false;
                  cu.timd = true;
                  cu.dimd = false;
                  cu.mipFlag = false;
                  cu.tmpFlag = false;
                  cu.tmrlFlag = false;
                  cu.sgpm = false;
                  cu.eipFlag = false;
                  cu.firstPU->multiRefIdx = 0;
                  cu.ispMode = NOT_INTRA_SUBPARTITIONS;
                  cu.firstPU->intraDir[CHANNEL_TYPE_LUMA] = cu.timdMode;
                  initIntraPatternChType(cu, pu.Y());
                  predIntraAng(COMPONENT_Y, piPred, pu);
                  PelBuf timdSaveBuf(m_timdPredBuf, pu.Y());
                  timdSaveBuf.copyFrom(piPred);
                }
                cu.timd = false;
                cu.timdSad = false;
              }
    #endif
              if (testTimdSad)
              {
    #if JVET_AJ0061_TIMD_MERGE		
                cu.timdMrg = false;
    #endif
                cu.timdSad = true;
                cu.timd = true;
                if (timdSadSaveFlag)
                {
                  cu.dimd = false;
                  cu.mipFlag = false;
                  cu.tmpFlag = false;
                  cu.tmrlFlag = false;
                  cu.sgpm = false;
                  cu.eipFlag = false;
                  cu.firstPU->multiRefIdx = 0;
                  cu.ispMode = NOT_INTRA_SUBPARTITIONS;
                  cu.firstPU->intraDir[CHANNEL_TYPE_LUMA] = cu.timdModeSad;
                  initIntraPatternChType(cu, pu.Y());
                  predIntraAng(COMPONENT_Y, piPred, pu);
                  PelBuf timdSadSaveBuf(m_timdSadPredBuf, pu.Y());
                  timdSadSaveBuf.copyFrom(piPred);
    
    #if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS
                  Distortion sadCost = distParamSad.distFunc(distParamSad);
                  Distortion minSadHad = sadCost * 2;
    #else
                  Distortion minSadHad = std::min(distParamSad.distFunc(distParamSad) * 2, distParamHad.distFunc(distParamHad));
    #endif
                  loadStartStates();
                  uint64_t fracModeBits = xFracModeBitsIntra(pu, cu.timdModeSad, CHANNEL_TYPE_LUMA);
                  double cost = double(minSadHad) + double(fracModeBits) * sqrtLambdaForFirstPass;
    #if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS
                  m_bestIntraSADCost = std::min(m_bestIntraSADCost, cost - (double)minSadHad + (double)sadCost);
    #endif
                  m_dSavedRDCostTimdSad = cost;
                  m_dSavedHadTimdSad = double(minSadHad);
                }
                updateCandList(ModeInfo(false, false, 0, NOT_INTRA_SUBPARTITIONS, TIMDSAD_IDX), m_dSavedRDCostTimdSad, uiRdModeList,
                  candCostList, numModesForFullRD
    #if JVET_AJ0061_TIMD_MERGE
                               +1
    #endif			  
    			        );
                updateCandList(ModeInfo(false, false, 0, NOT_INTRA_SUBPARTITIONS, TIMDSAD_IDX), m_dSavedHadTimdSad, uiHadModeList, candHadList, numHadCand);
                cu.timd = false;
                cu.timdSad = false;
              }
    #endif
    
    #if JVET_AK0059_MDIP
              numModesForFullRD = int(uiRdModeList.size());
              if (testMdip)
              {           
                if (mdipSaveFlag)
                {
                  uint32_t uiMode = cu.mdipMode;
                  cu.mdip        = true;
                  cu.dimd        = false;
                  cu.obicFlag    = false;
                  cu.timd        = false;
                  cu.sgpm        = false;
                  cu.ispMode     = 0;
                  cu.tmpFlag     = false;
                  cu.tmrlFlag    = false;
                  pu.multiRefIdx = 0;
                  cu.mipFlag     = false;
                  cu.eipFlag     = false;
                  pu.intraDir[0] = uiMode;
    
                  Distortion sadCost;
                  Distortion minSadHad;
    #if JVET_AH0209_PDP
                  const int sizeKey = (area.width << 8) + area.height;
                  const int sizeIdx = g_size.find(sizeKey) != g_size.end() ? g_size[sizeKey] : -1;
                  bool isPDPMode = sizeIdx >= 0 && !pu.cu->ispMode && pu.cu->cs->sps->getUsePDP();
                  if (isPDPMode)
                  {
                    const int m = sizeIdx > 12 ? 2 : 0;
                    const int s = sizeIdx > 12 ? 4 : 2;
                    isPDPMode &= (g_pdpFilters[uiMode][sizeIdx] && !(uiMode > 1 && (uiMode % s != m)));
                  }
                  isPDPMode &= m_refAvailable;
                  
                  if(isPDPMode)
                  {
                    sadCost = (Distortion)m_dSavedSadPdp;
                    minSadHad = (Distortion)m_dSavedSadHadPdp;
                  }
                  else
                  {
    #endif
                    initIntraPatternChType(cu, area, false, 0, true, !isPDPMode, isPDPMode);
                    predIntraAng(COMPONENT_Y, piPred, pu);
                    if (mdipNeededMode[uiMode])
                    {                  
                      PelBuf predBuf(m_mdipPredBuf, tmpArea);
                      predBuf.copyFrom(piPred);                  
                    }
                    // Use the min between SAD and SATD as the cost criterion
                    // SAD is scaled by 2 to align with the scaling of HAD
    #if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS
                    sadCost = distParamSad.distFunc(distParamSad);
                    minSadHad = std::min(sadCost * 2, distParamHad.distFunc(distParamHad));              
    #else
                    minSadHad =
                      std::min(distParamSad.distFunc(distParamSad) * 2, distParamHad.distFunc(distParamHad));
    #endif                
    #if JVET_AH0209_PDP
                  }
    #endif
                  loadStartStates();
                  uint64_t fracModeBits = xFracModeBitsIntra(pu, pu.intraDir[0], CHANNEL_TYPE_LUMA);
     
                  double cost = (double) minSadHad + (double) fracModeBits * sqrtLambdaForFirstPass;
    #if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS
                  m_bestIntraSADCost = std::min(m_bestIntraSADCost, cost - (double)minSadHad + (double)sadCost);
    #endif
                  m_dSavedSadHadRdCostMdip = cost;
                  m_dSavedSadHadMdip = double(minSadHad);
                  cu.mdip = false;
                }
                updateCandList(ModeInfo(false, false, 0, NOT_INTRA_SUBPARTITIONS, MDIP_IDX), m_dSavedSadHadRdCostMdip, uiRdModeList,
                  candCostList, numModesForFullRD);
                updateCandList(ModeInfo(false, false, 0, NOT_INTRA_SUBPARTITIONS, MDIP_IDX), m_dSavedSadHadMdip, uiHadModeList, candHadList, numHadCand);
              }
    #endif
    
    #if JVET_AH0076_OBIC && JVET_AJ0249_NEURAL_NETWORK_BASED
              if (testObic && isNnIn)
              {
                PelBuf obicSaveBuf(m_obicPredBuf, pu.Y());
                CHECK(!m_isObicPredictionSaved, "A prediction buffer for OBIC is not saved before loading.");
                piPred.copyFrom(obicSaveBuf);
                cu.dimd = true;
                cu.obicFlag = true;
                cu.tmpFlag = false;
                cu.mipFlag = false;
                cu.sgpm = false;
                pu.multiRefIdx = 0;
                const uint32_t uiMode = cu.obicMode[0];
                pu.intraDir[CHANNEL_TYPE_LUMA] = uiMode;
                CHECK(!m_intraModeReady[uiMode], "`m_intraModeReady[uiMode]` is false.");
                const Distortion sadCost = distParamSad.distFunc(distParamSad);
                const Distortion minSadHad = std::min(sadCost * 2, distParamHad.distFunc(distParamHad));
                loadStartStates();
                const uint64_t fracModeBits = xFracModeBitsIntra(pu, uiMode, CHANNEL_TYPE_LUMA);
                const double cost = (double)minSadHad + (double)fracModeBits * sqrtLambdaForFirstPass;
    #if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS
                m_bestIntraSADCost = std::min(m_bestIntraSADCost, cost - (double)minSadHad + (double)sadCost);
    #endif
                updateCandList(ModeInfo(false, false, 0, NOT_INTRA_SUBPARTITIONS, OBIC_IDX), cost, uiRdModeList, candCostList, numModesForFullRD);
                updateCandList(ModeInfo(false, false, 0, NOT_INTRA_SUBPARTITIONS, OBIC_IDX), double(minSadHad), uiHadModeList, candHadList, numHadCand);
                cu.dimd = false;
                cu.obicFlag = false;
              }
    #endif
    
                  if (eipSaveFlag)
                  {
                    m_uiSavedRdModeListEip.clear();
                    m_uiSavedHadModeListEip.clear();
                    m_dSavedModeCostEip.clear();
                    m_dSavedHadListEip.clear();
    
    #if JVET_AJ0082_MM_EIP
    
                    m_encBestEipCost = MAX_DOUBLE;
                    cu.eipMmFlag = false;
                    m_numSigEip = 0;
    
                    cu.tmpFlag = false;
                    cu.mipFlag = false;
                    cu.sgpm = false;
                    pu.multiRefIdx = 0;
    
                    cu.eipFlag = true;
                    cu.eipMerge = false;
                    initEipParams(pu, COMPONENT_Y);
                    static_vector<EipModelCandidate, NUM_DERIVED_EIP> eipModelCandList;
                    static_vector<EipModelCandidate, MAX_MERGE_EIP> eipMergeCandList;
                    getCurEipCands(pu, eipModelCandList);
                    getNeiEipCands(pu, eipMergeCandList);
                    reorderEipCands(pu, eipMergeCandList);
                    const int numRdEIP = std::max(NUM_EIP_MERGE_SIGNAL + NUM_DERIVED_EIP, (numModesForFullRD + 1) / 2);
                    for (int mergeFlag = 0; mergeFlag < 2; mergeFlag++)
    
                      cu.eipMerge = bool(mergeFlag);
                      for (int i = 0; i < (cu.eipMerge ? eipMergeCandList.size() : eipModelCandList.size()); i++)
    
                        pu.intraDir[0] = i;
    #if JVET_AJ0082_MM_EIP
                        cu.eipMmFlag = (!cu.eipMerge) && (i >= m_numSigEip);
                        if (cu.eipMmFlag)
                        {
                          pu.intraDir[0] -= m_numSigEip;
                        }
    
                        cu.eipModel = cu.eipMerge ? eipMergeCandList[i] : eipModelCandList[i];
                        if (cu.eipMerge)
                        {
                          m_eipMergeModel[i] = cu.eipModel;
    
    #if JVET_AJ0082_MM_EIP
    
                          m_eipMergeModel[i].eipDimdMode = -1;
    
    #if JVET_AK0217_INTRA_MTSS || JVET_AK0187_IMPLICIT_MTS_LUT_EXTENSION
    
                          m_eipMergeModel[i].eipDimdMode2nd = -1;
    
                        }
                        else
                        {
                          m_eipModel[i] = cu.eipModel;
                        }
                        eipPred(pu, piPred);
    
    #if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS
    
                        Distortion sadCost = distParamSad.distFunc(distParamSad);
                        Distortion minSadHad = std::min(sadCost * 2, distParamHad.distFunc(distParamHad));
    
                        Distortion minSadHad = std::min(distParamSad.distFunc(distParamSad) * 2, distParamHad.distFunc(distParamHad));
    
    #if JVET_AJ0082_MM_EIP
    
                        uint64_t fracModeBits = xFracModeBitsIntra(pu, pu.intraDir[0], CHANNEL_TYPE_LUMA);
    
                        uint64_t fracModeBits = xFracModeBitsIntra(pu, i, CHANNEL_TYPE_LUMA);
    
                        double cost = double(minSadHad) + double(fracModeBits) * sqrtLambdaForFirstPass;
    
    #if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS
    
                        m_bestIntraSADCost = std::min(m_bestIntraSADCost, cost - (double)minSadHad + (double)sadCost);
    
                        ModeInfo modeInfo(false, cu.eipMerge, 0, NOT_INTRA_SUBPARTITIONS, EIP_IDX + i);
                        PelBuf eipSaveBuf(cu.eipMerge ? m_eipMergePredBuf[i] : m_eipPredBuf[i], pu.Y());
                        eipSaveBuf.copyFrom(piPred);
    
    #if JVET_AJ0082_MM_EIP
    
                        if (!cu.eipModel.bMm && cost < m_encBestEipCost)
                        {
                          m_encBestEipCost = cost;
                        }
    
                        updateCandList(modeInfo, cost, m_uiSavedRdModeListEip, m_dSavedModeCostEip, numRdEIP);
                        updateCandList(modeInfo, double(minSadHad * 0.8), m_uiSavedHadModeListEip, m_dSavedHadListEip, numRdEIP);
                      }
    
    #if !JVET_AJ0082_MM_EIP
    
                    for (const auto& modeInfo : m_uiSavedRdModeListEip)
    
                      CHECK(modeInfo.modeId < EIP_IDX || modeInfo.modeId >= EIP_IDX + std::max(NUM_DERIVED_EIP, MAX_MERGE_EIP), "A non-EIP mode is in EIP mode list")
                        const auto modeIdx = modeInfo.modeId - EIP_IDX;
                      if (modeInfo.mipTrFlg)
                      {
                        PelBuf eipSaveBuf(m_eipMergePredBuf[modeIdx], pu.Y());
    
    #if JVET_AI0050_INTER_MTSS
    
                        int secondDimdIntraDir = 0;
    
                        m_eipMergeModel[modeIdx].eipDimdMode = deriveIpmForTransform(eipSaveBuf, cu
    
    #if JVET_AI0050_INTER_MTSS
    
    #if JVET_AI0050_INTER_MTSS
    
                        cu.dimdDerivedIntraDir2nd = secondDimdIntraDir;
    
    #endif
    #if JVET_AK0217_INTRA_MTSS
                        m_eipMergeModel[modeIdx].eipDimdMode2nd = secondDimdIntraDir;
    
                        CHECK(modeIdx >= NUM_EIP_MERGE_SIGNAL, "modeIdx >= NUM_EIP_MERGE_SIGNAL");
                      }
                      else
                      {
                        PelBuf eipSaveBuf(m_eipPredBuf[modeIdx], pu.Y());
    
    #if JVET_AI0050_INTER_MTSS
    
                        int secondDimdIntraDir = 0;
    
                        m_eipModel[modeIdx].eipDimdMode = deriveIpmForTransform(eipSaveBuf, cu
    
    #if JVET_AI0050_INTER_MTSS
    
    #if JVET_AI0050_INTER_MTSS
    
                        cu.dimdDerivedIntraDir2nd = secondDimdIntraDir;
    
    #endif
    #if JVET_AK0217_INTRA_MTSS
                        m_eipModel[modeIdx].eipDimdMode2nd = secondDimdIntraDir;
    
                        CHECK(modeIdx >= NUM_DERIVED_EIP, "modeIdx >= NUM_DERIVED_EIP");
                      }
                      }
    
    #endif
    #if JVET_AJ0082_MM_EIP
    
                    if (m_dSavedModeCostEip.size() > 0)
                    {
                      isEipModeTested = true;
                      eipBestSatdCost = m_dSavedModeCostEip[0];
                    }
    
                    cu.eipFlag = false;
                    cu.eipMerge = false;
    
    #if JVET_AJ0082_MM_EIP
    
                  }
                  for (auto i = 0; i < m_uiSavedRdModeListEip.size(); i++)
                  {
                    updateCandList(m_uiSavedRdModeListEip[i], m_dSavedModeCostEip[i], uiRdModeList, candCostList, numModesForFullRD);
                    updateCandList(m_uiSavedHadModeListEip[i], m_dSavedHadListEip[i], uiHadModeList, candHadList, numHadCand);
                  }
                  int numEip = 0;
                  for (int i = 0; i < numModesForFullRD - 1; i++)
                  {
                    bool isEip = (uiRdModeList[i].modeId >= EIP_IDX && uiRdModeList[i].modeId < EIP_IDX + std::max(NUM_DERIVED_EIP, MAX_MERGE_EIP));
                    numEip += (isEip ? 1 : 0);
                  }
                  int numNonEip = numModesForFullRD - numEip;
                  int lastModeId = uiRdModeList[numModesForFullRD - 1].modeId;
                  bool lastModeIsEip = (lastModeId >= EIP_IDX && lastModeId < EIP_IDX + std::max(NUM_DERIVED_EIP, MAX_MERGE_EIP));
    
    #if JVET_AJ0082_MM_EIP
    
                  bool reduceRD = m_dSavedModeCostEip.size() ? (pu.Y().area() < 256) && (m_encBestEipCost < candCostList[numModesForFullRD - 1]) && (lastModeIsEip || (numNonEip > 1)) : false;
                  if (reduceRD && m_pcEncCfg->getIntraPeriod() == 1)
    
                  bool reduceRD = m_dSavedModeCostEip.size() ? (pu.Y().area() < 256) && (m_dSavedModeCostEip[0] < candCostList[numModesForFullRD - 1]) && (lastModeIsEip || (numNonEip > 1)) : false;
                  if (reduceRD && pu.cs->slice->isIntra())
    
                  {
                    uiRdModeList.pop_back();
                    candCostList.pop_back();
                    numModesForFullRD = int(uiRdModeList.size());
                  }
    
    #if JVET_AE0169_BIPREDICTIVE_IBC
    
                m_bestIntraSADHADCost = candCostList[numModesForFullRD - 1];
    
    #if JVET_AI0136_ADAPTIVE_DUAL_TREE
                  if (relatedCU && !relatedCU->skipFracTmp && (tmpBestSatdCost > m_bestIntraSADHADCost * TMP_ENC_REFINE_THRESHOLD))
                  {
                    relatedCU->skipFracTmp = true;
                  }
    
                  if (!relatedCU.skipFracTmp && (tmpBestSatdCost > m_bestIntraSADHADCost * TMP_ENC_REFINE_THRESHOLD))
                  {
                    relatedCU.skipFracTmp = true;
                  }
    
    #if JVET_AJ0082_MM_EIP
    
                if (isEipModeTested && m_pcEncCfg->getIntraPeriod() == 1)
    
    #if JVET_AI0136_ADAPTIVE_DUAL_TREE
                  if (relatedCU && !relatedCU->skipEip && (eipBestSatdCost > m_bestIntraSADHADCost * ENC_EIP_SAD_CHK_RATE))
                  {
                    relatedCU->skipEip = true;
                  }
    
                  if (!relatedCU.skipEip && (eipBestSatdCost > m_bestIntraSADHADCost * ENC_EIP_SAD_CHK_RATE))
                  {
                    relatedCU.skipEip = true;
                  }
    
                  if((testTimdSad && uiRdModeList[numModesForFullRD - 1].modeId == TIMDSAD_IDX) || (candCostList[numModesForFullRD - 1] > candCostList[0] * 1.015))
                  {
                    numModesForFullRD--;
                    uiRdModeList.pop_back();
                    candCostList.pop_back();
                  }
    
    #endif
    #if JVET_AK0059_MDIP
              cu.mdip = false;
              if (testMdip)
              {
                bool mdipIncluded = false;
                ModeInfo mdipCandidate( false, false, 0, NOT_INTRA_SUBPARTITIONS, MDIP_IDX);
                for(int j = 0; j < numModesForFullRD; j++)
                {
                  mdipIncluded |= (mdipCandidate == uiRdModeList[j]);
                }
                
                const double thresholdMdip = 1.5;
                if(!mdipIncluded)
                {
                  if(m_dSavedSadHadRdCostMdip < candCostList[0] * thresholdMdip)
                  {
                    numModesForFullRD++;
                    uiRdModeList.push_back(mdipCandidate);
                    candCostList.push_back(0);             
                  }
                }
              }
    
                if (m_pcEncCfg->getFastUDIUseMPMEnabled())
                {
    
    Vadim Seregin's avatar
    Vadim Seregin committed
    
    #if SECONDARY_MPM
    
                  auto uiPreds = m_intraMPM;
    
    Vadim Seregin's avatar
    Vadim Seregin committed
    #else
    
                  const int numMPMs = NUM_MOST_PROBABLE_MODES;
                  unsigned  uiPreds[numMPMs];
    
    Vadim Seregin's avatar
    Vadim Seregin committed
    #endif
    
    #if JVET_AB0157_TMRL
    
    Vadim Seregin's avatar
    Vadim Seregin committed
    #if SECONDARY_MPM
    
                  int numCand = m_mpmListSize;
    
                  numCand = (numCand > 2) ? 2 : numCand;
    
    Vadim Seregin's avatar
    Vadim Seregin committed
    #else
    
                  const int numCand = PU::getIntraMPMs(pu, uiPreds);
    
    Vadim Seregin's avatar
    Vadim Seregin committed
    #endif