Skip to content
Snippets Groups Projects
IntraSearch.cpp 442 KiB
Newer Older
  • Learn to ignore specific revisions
  •       cu.tmpLicFlag = uiBestPUMode.tmpLicFlag;
          cu.ibcLicFlag = uiBestPUMode.tmpLicFlag;
          cu.ibcLicIdx = uiBestPUMode.tmpLicIdc;
    #endif
    
          cu.tmpIsSubPel   = uiBestPUMode.tmpIsSubPel;
          cu.tmpSubPelIdx  = uiBestPUMode.tmpSubPelIdx;
    
    Vadim Seregin's avatar
    Vadim Seregin committed
    #endif
    
          cu.mipFlag = uiBestPUMode.mipFlg;
    
          pu.mipTransposedFlag             = uiBestPUMode.mipTrFlg;
    
          pu.multiRefIdx = uiBestPUMode.mRefId;
          pu.intraDir[ CHANNEL_TYPE_LUMA ] = uiBestPUMode.modeId;
    
    Vadim Seregin's avatar
    Vadim Seregin committed
    #if ENABLE_DIMD
          cu.dimd = bestDimdMode;
          if (cu.dimd)
          {
            CHECK(pu.multiRefIdx > 0, "use of DIMD");
          }
    #endif
    
          cu.bdpcmMode = bestBDPCMMode;
    
    Keming Cao's avatar
    Keming Cao committed
    #if JVET_W0123_TIMD_FUSION
          cu.timd = bestTimdMode;
          if (cu.timd)
          {
            pu.intraDir[ CHANNEL_TYPE_LUMA ] = cu.timdMode;
          }
    #endif
    
    fan wang's avatar
    fan wang committed
    #if JVET_AB0155_SGPM
          cu.sgpm = uiBestPUMode.sgpmFlag;
          if (cu.sgpm)
          {
            CHECK(!bestSgpmMode, "mode not same");
    
    #if JVET_AG0152_SGPM_ITMP_IBC
              pu.intraDir[CHANNEL_TYPE_LUMA] = uiBestPUMode.sgpmMode0 >= SGPM_BV_START_IDX ? 0 : uiBestPUMode.sgpmMode0;
              pu.intraDir1[CHANNEL_TYPE_LUMA] = uiBestPUMode.sgpmMode1 >= SGPM_BV_START_IDX ? 0 : uiBestPUMode.sgpmMode1;
    #else
    
    fan wang's avatar
    fan wang committed
            pu.intraDir[CHANNEL_TYPE_LUMA]  = uiBestPUMode.sgpmMode0;
            pu.intraDir1[CHANNEL_TYPE_LUMA] = uiBestPUMode.sgpmMode1;
    
    fan wang's avatar
    fan wang committed
            cu.sgpmSplitDir                 = uiBestPUMode.sgpmSplitDir;
            cu.sgpmMode0                    = uiBestPUMode.sgpmMode0;
            cu.sgpmMode1                    = uiBestPUMode.sgpmMode1;
            cu.sgpmIdx                      = uiBestPUMode.sgpmIdx;
    
    #if JVET_AG0152_SGPM_ITMP_IBC
            cu.sgpmBv0                       = uiBestPUMode.sgpmBv0;
            cu.sgpmBv1                      = uiBestPUMode.sgpmBv1;
    #endif
    
    #if JVET_AB0157_TMRL
          cu.tmrlFlag = uiBestPUMode.mRefId >= MAX_REF_LINE_IDX;
          if(cu.tmrlFlag)
          {
            int tmrlListIdx = uiBestPUMode.mRefId - MAX_REF_LINE_IDX;
            cu.tmrlListIdx = tmrlListIdx;
    
            pu.multiRefIdx = m_tmrlList[tmrlListIdx].multiRefIdx;
            pu.intraDir[0] = m_tmrlList[tmrlListIdx].intraDir;
    
    #if JVET_AG0058_EIP
          cu.eipFlag = (uiBestPUMode.modeId >= EIP_IDX) && (uiBestPUMode.modeId < EIP_IDX + std::max(NUM_DERIVED_EIP, MAX_MERGE_EIP));
          if (cu.eipFlag)
          {
            cu.eipMerge = uiBestPUMode.mipTrFlg;
            pu.intraDir[0] = uiBestPUMode.modeId - EIP_IDX;
            cu.eipModel = cu.eipMerge ? m_eipMergeModel[pu.intraDir[0]] : m_eipModel[pu.intraDir[0]];
          }
    #endif
    
    #if JVET_AC0115_INTRA_TMP_DIMD_MTS_LFNST 
          if (cu.tmpFlag)
          {
            cu.intraTmpDimdMode = intraTmpDimdMode;
          }
    
    #endif
    
    #if JVET_AC0105_DIRECTIONAL_PLANAR
          cu.plIdx = bestPlMode;
          if (cu.plIdx)
          {
            CHECK(pu.multiRefIdx > 0, "use of PL");
            CHECK(cu.mipFlag, "use of PL");
            CHECK(cu.dimd, "use of PL");
            CHECK(cu.tmpFlag, "use of PL");
            CHECK(cu.tmrlFlag, "use of PL");
            CHECK(cu.sgpm, "use of PL");
            CHECK(cu.timd, "use of PL");
          }
    #endif
    
    
          if (cu.colorTransform)
          {
            CHECK(pu.intraDir[CHANNEL_TYPE_CHROMA] != DM_CHROMA_IDX, "chroma should use DM mode for adaptive color transform");
          }
    
      }
    
      //===== reset context models =====
      m_CABACEstimator->getCtx() = ctxStart;
    
    #if JVET_AD0120_LBCCP
    void IntraSearch::fillLmPredFiltList(PredictionUnit pu, const PelUnitBuf& lmPredFilt, int &lmPredFiltIdx, std::vector<lmPredFiltModeInfo> &miLmPredFiltList)
    {
      const TempCtx ctxStart(m_ctxCache, m_CABACEstimator->getCtx());
      const double  sqrtLambdaForFirstPass = m_pcRdCost->getMotionLambda() * FRAC_BITS_SCALE;
    
      int64_t          sad = 0, sadCb = 0, satdCb = 0, sadCr = 0, satdCr = 0;
      CodingStructure &cs = *(pu.cs);
      DistParam        distParamSadCb, distParamSatdCb;
      DistParam        distParamSadCr, distParamSatdCr;
      m_pcRdCost->setDistParam(distParamSadCb, cs.getOrgBuf(pu.Cb()), lmPredFilt.Cb(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, false);
      m_pcRdCost->setDistParam(distParamSatdCb, cs.getOrgBuf(pu.Cb()), lmPredFilt.Cb(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, true);
      m_pcRdCost->setDistParam(distParamSadCr, cs.getOrgBuf(pu.Cr()), lmPredFilt.Cr(),  pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cr, false);
      m_pcRdCost->setDistParam(distParamSatdCr, cs.getOrgBuf(pu.Cr()), lmPredFilt.Cr(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cr, true);
      distParamSadCb.applyWeight  = false;
      distParamSatdCb.applyWeight = false;
      distParamSadCr.applyWeight  = false;
      distParamSatdCr.applyWeight = false;
    
      sadCb  = distParamSadCb.distFunc(distParamSadCb) * 2;
      satdCb = distParamSatdCb.distFunc(distParamSatdCb);
      sad    = std::min(sadCb, satdCb);
      sadCr  = distParamSadCr.distFunc(distParamSadCr) * 2;
      satdCr = distParamSatdCr.distFunc(distParamSatdCr);
      sad += std::min(sadCr, satdCr);
    
      m_CABACEstimator->getCtx() = ctxStart;
      uint64_t fracModeBits      = xFracModeBitsIntra(pu, MMLM_CHROMA_IDX, CHANNEL_TYPE_CHROMA);
      double   cost              = (double) sad + (double) fracModeBits * sqrtLambdaForFirstPass;
    
      int cccmFlag = 0, cccmNoSubFlag = 0, glCccmFlag = 0, cccmMultiFilterIdx = 0;
    #if JVET_AA0057_CCCM
      cccmFlag = pu.cccmFlag;
    #endif
    #if JVET_AC0147_CCCM_NO_SUBSAMPLING
      cccmNoSubFlag = pu.cccmNoSubFlag;
    #endif
    #if JVET_AC0054_GLCCCM
      glCccmFlag = pu.glCccmFlag;
    #endif
    #if JVET_AD0202_CCCM_MDF
      cccmMultiFilterIdx = pu.cccmMultiFilterIdx;
    #endif
      miLmPredFiltList.push_back({ lmPredFiltIdx, cccmFlag, cccmNoSubFlag, glCccmFlag, cccmMultiFilterIdx, cost });
      lmPredFiltIdx++;
    }
    #endif
    
    
    #if JVET_AG0059_CCP_MERGE_ENHANCEMENT
    void IntraSearch::getPredForCCPMrgFusion(PredictionUnit& pu, PelBuf& predCb, PelBuf& predCr)
    {
      int            width = predCb.width;
      int            height = predCb.height;
    
      const int      scaleX = getComponentScaleX(COMPONENT_Cb, pu.chromaFormat);
      const int      scaleY = getComponentScaleY(COMPONENT_Cb, pu.chromaFormat);
      const UnitArea localUnitArea(pu.chromaFormat, Area(0, 0, width << scaleX, height << scaleY));
    
      PredictionUnit pu2 = pu;
    
      if (pu.ccpMergeFusionType == 0)
      {
        const int                         bitDepth = pu.cu->slice->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA);
        static CccmModel cccmModelCb[2] = { CccmModel(CCCM_NUM_PARAMS, bitDepth), CccmModel(CCCM_NUM_PARAMS, bitDepth) };
        static CccmModel cccmModelCr[2] = { CccmModel(CCCM_NUM_PARAMS, bitDepth), CccmModel(CCCM_NUM_PARAMS, bitDepth) };
        pu2.cccmFlag = 1;
    #if JVET_AC0054_GLCCCM
        pu2.glCccmFlag = 0;
    #endif
    #if JVET_AD0202_CCCM_MDF
        pu2.cccmMultiFilterIdx = 0;
    #endif
    #if MMLM
        pu2.intraDir[1] = MMLM_CHROMA_IDX;
        static int modelThr = 0;
    
        modelThr = xCccmCalcRefAver(pu2);
        xCccmCalcModels(pu2, cccmModelCb[0], cccmModelCr[0], 1, modelThr);
        xCccmCalcModels(pu2, cccmModelCb[1], cccmModelCr[1], 2, modelThr);
    
        xCccmApplyModel(pu2, COMPONENT_Cb, cccmModelCb[0], 1, modelThr, predCb);
        xCccmApplyModel(pu2, COMPONENT_Cb, cccmModelCb[1], 2, modelThr, predCb);
    
        xCccmApplyModel(pu2, COMPONENT_Cr, cccmModelCr[0], 1, modelThr, predCr);
        xCccmApplyModel(pu2, COMPONENT_Cr, cccmModelCr[1], 2, modelThr, predCr);
    #else
        pu2.intraDir[1] = LM_CHROMA_IDX;
    
        xCccmCalcModels(pu2, cccmModelCb[0], cccmModelCr[0], 0, 0);
    
        xCccmApplyModel(pu2, COMPONENT_Cb, cccmModelCb[0], 0, 0, predCb);
        xCccmApplyModel(pu2, COMPONENT_Cr, cccmModelCr[0], 0, 0, predCr);
    #endif
      }
      else
      {
        pu.intraDir[1] = DIMD_CHROMA_IDX;
        initIntraPatternChType(*pu.cu, pu.blocks[COMPONENT_Cb]);
        initIntraPatternChType(*pu.cu, pu.blocks[COMPONENT_Cr]);
        predIntraAng(COMPONENT_Cb, predCb, pu);
        predIntraAng(COMPONENT_Cr, predCr, pu);
        pu.intraDir[1] = LM_CHROMA_IDX;
      }
    
    }
    void IntraSearch::xCalcCcpMrgPred(const PredictionUnit& pu, const ComponentID compID, PelBuf& piPred, PelBuf& piLm)
    {
      CHECK(compID == COMPONENT_Y, "");
    
      int width = piPred.width;
      int height = piPred.height;
      Pel* pelPred = piPred.buf;
      Pel* pelLm = piLm.buf;
    
      int  w0 = 2;
      int  w1 = 2;
      int  shift = 2;
    
      for (int y = 0; y < height; y++)
      {
        for (int x = 0; x < width; x++)
        {
          int blend = pelPred[x] * w0;
          blend += pelLm[x] * w1;
          blend += 2;
          pelLm[x] = (Pel)(blend >> shift);
        }
        pelPred += piPred.stride;
        pelLm += piLm.stride;
      }
    }
    #endif
    
    
    void IntraSearch::estIntraPredChromaQT( CodingUnit &cu, Partitioner &partitioner, const double maxCostAllowed 
    #if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS
                                          , InterPrediction* pcInterPred
    #endif
    )
    
    {
      const ChromaFormat format   = cu.chromaFormat;
      const uint32_t    numberValidComponents = getNumberValidComponents(format);
      CodingStructure &cs = *cu.cs;
    
    Vadim Seregin's avatar
    Vadim Seregin committed
      const TempCtx ctxStart  ( m_ctxCache, m_CABACEstimator->getCtx() );
    
      double    bestCostSoFar = maxCostAllowed;
    
    Vadim Seregin's avatar
    Vadim Seregin committed
    #if !INTRA_RM_SMALL_BLOCK_SIZE_CONSTRAINTS
    
      bool      lumaUsesISP   = !cu.isSepTree() && cu.ispMode;
    
    Vadim Seregin's avatar
    Vadim Seregin committed
    #else
      bool      lumaUsesISP = !CS::isDualITree(*cu.cs) && cu.ispMode;
    #endif
    
      PartSplit ispType       = lumaUsesISP ? CU::getISPType( cu, COMPONENT_Y ) : TU_NO_ISP;
      CHECK( cu.ispMode && bestCostSoFar < 0, "bestCostSoFar must be positive!" );
    
    #if JVET_AF0066_ENABLE_DBV_4_SINGLE_TREE
      bool singleTreeLumaIntraTmp = !CS::isDualITree(*cu.cs) && cu.tmpFlag;
    #endif
    
    #if JVET_AD0120_LBCCP
      int  bestCCInsideFilter = 0;
    #endif
    
      auto &pu = *cu.firstPU;
    
      {
        uint32_t       uiBestMode = 0;
        Distortion uiBestDist = 0;
        double     dBestCost = MAX_DOUBLE;
    
        int32_t bestBDPCMMode = 0;
    
    #if JVET_AG0154_DECODER_DERIVED_CCP_FUSION
        Distortion bestDist = ULLONG_MAX;
        int      decoderDerivedCcpModeBest = 0;
        int      bestDdNonLocalMergeFusion = 0;
    #endif
    
    Jani Lainema's avatar
    Jani Lainema committed
    #if JVET_AA0057_CCCM
        int      cccmModeBest = 0;
    
    #if JVET_AC0147_CCCM_NO_SUBSAMPLING
        int      cccmNoSubBest = 0;
    #endif
    
    #if JVET_AC0054_GLCCCM
        int      glCccmBest = 0;
    #endif
    
    #if JVET_AE0100_BVGCCCM
        int      bvgCccmBest = 0;
    #endif
    
    #if JVET_AD0202_CCCM_MDF
        int      cccmMultiFilterIdxBest = 0;
    #endif
    
    Jani Lainema's avatar
    Jani Lainema committed
    #endif
    
    #if JVET_Z0050_CCLM_SLOPE
        CclmOffsets bestCclmOffsets = {};
        CclmOffsets satdCclmOffsetsBest[NUM_CHROMA_MODE];
        int64_t     satdCclmCosts      [NUM_CHROMA_MODE] = { 0 };
    #endif
    
    Che-Wei Kuo's avatar
    Che-Wei Kuo committed
    #if JVET_AA0126_GLM
        GlmIdc      bestGlmIdc = {};
        GlmIdc      satdGlmIdcBest     [NUM_CHROMA_MODE];
        int64_t     satdGlmCosts       [NUM_CHROMA_MODE] = { 0 };
    #endif
    
    #if JVET_Z0050_DIMD_CHROMA_FUSION
    
    #if JVET_AC0119_LM_CHROMA_FUSION
        uint8_t isChromaFusion = 0;
    #else
    
        bool isChromaFusion = false;
    
    #endif
    #if JVET_AD0188_CCP_MERGE
        int               bestNonAdjCCCM = 0;
        CCPModelCandidate ccpModelBest;
    
    #if JVET_AG0059_CCP_MERGE_ENHANCEMENT
        int bestCcpMergeFusionFlag = 0;
        int bestCcpMergeFusionType = 0;
    #endif
    
          int32_t  uiMinMode = 0;
          int32_t  uiMaxMode = NUM_CHROMA_MODE;
    
          //----- check chroma modes -----
          uint32_t chromaCandModes[ NUM_CHROMA_MODE ];
          PU::getIntraChromaCandModes( pu, chromaCandModes );
    
    #if JVET_Z0050_DIMD_CHROMA_FUSION && ENABLE_DIMD
    
    #if JVET_AC0094_REF_SAMPLES_OPT
        if (!CS::isDualITree(*cu.cs))
        {
          const CompArea areaCb = pu.Cb();
          const CompArea areaCr = pu.Cr();
          const CompArea lumaArea = CompArea(COMPONENT_Y, pu.chromaFormat, areaCb.lumaPos(), recalcSize(pu.chromaFormat, CHANNEL_TYPE_CHROMA, CHANNEL_TYPE_LUMA, areaCb.size()));//needed for correct pos/size (4x4 Tus)
          IntraPrediction::deriveDimdChromaMode(cs.picture->getRecoBuf(lumaArea), cs.picture->getRecoBuf(areaCb), cs.picture->getRecoBuf(areaCr), lumaArea, areaCb, areaCr, *pu.cu);
        }
        if (PU::getCoLocatedIntraLumaMode(*cu.firstPU) == cu.dimdChromaMode)
        {
          if (cu.dimdChromaMode == cu.dimdChromaModeSecond)
          {
            cu.dimdChromaMode = DC_IDX;
          }
          else
          {
            cu.dimdChromaMode = cu.dimdChromaModeSecond;
          }
        }
    #else
    
          // derive DIMD chroma mode
          CompArea areaCb = pu.Cb();
          CompArea areaCr = pu.Cr();
          CompArea lumaArea = CompArea(COMPONENT_Y, pu.chromaFormat, areaCb.lumaPos(), recalcSize(pu.chromaFormat, CHANNEL_TYPE_CHROMA, CHANNEL_TYPE_LUMA, areaCb.size()));//needed for correct pos/size (4x4 Tus)
          IntraPrediction::deriveDimdChromaMode(cs.picture->getRecoBuf(lumaArea), cs.picture->getRecoBuf(areaCb), cs.picture->getRecoBuf(areaCr), lumaArea, areaCb, areaCr, *pu.cu);
    #endif
    
    #if JVET_AC0071_DBV
          if (PU::hasChromaBvFlag(pu))
          {
            PU::deriveChromaBv(pu);
          }
          else
          {
            uiMaxMode--;
          }
    #endif
    
    
          // create a temporary CS
          CodingStructure &saveCS = *m_pSaveCS[0];
          saveCS.pcv      = cs.pcv;
          saveCS.picture  = cs.picture;
    
    Seungwook Hong's avatar
    Seungwook Hong committed
    #if JVET_Z0118_GDR
          saveCS.m_pt = cs.m_pt;
    #endif
    
          saveCS.area.repositionTo( cs.area );
          saveCS.clearTUs();
    
    Vadim Seregin's avatar
    Vadim Seregin committed
    #if !INTRA_RM_SMALL_BLOCK_SIZE_CONSTRAINTS
    
          if( !cu.isSepTree() && cu.ispMode )
    
    Vadim Seregin's avatar
    Vadim Seregin committed
    #else
          if (!CS::isDualITree(cs) && cu.ispMode)
    #endif
    
    Vadim Seregin's avatar
    Vadim Seregin committed
    #if !INTRA_RM_SMALL_BLOCK_SIZE_CONSTRAINTS
    
          if( cu.isSepTree() )
    
    Vadim Seregin's avatar
    Vadim Seregin committed
    #else
          if (CS::isDualITree(cs))
    #endif
    
          {
            if( partitioner.canSplit( TU_MAX_TR_SPLIT, cs ) )
            {
              partitioner.splitCurrArea( TU_MAX_TR_SPLIT, cs );
    
              do
              {
                cs.addTU( CS::getArea( cs, partitioner.currArea(), partitioner.chType ), partitioner.chType ).depth = partitioner.currTrDepth;
              } while( partitioner.nextPart( cs ) );
    
              partitioner.exitCurrSplit();
            }
            else
            cs.addTU( CS::getArea( cs, partitioner.currArea(), partitioner.chType ), partitioner.chType );
          }
    
          std::vector<TransformUnit*> orgTUs;
    
    
          if( lumaUsesISP )
          {
            CodingUnit& auxCU = saveCS.addCU( cu, partitioner.chType );
            auxCU.ispMode = cu.ispMode;
            saveCS.sps = cu.cs->sps;
            saveCS.addPU( *cu.firstPU, partitioner.chType );
          }
    
    
    
          // create a store for the TUs
          for( const auto &ptu : cs.tus )
          {
            // for split TUs in HEVC, add the TUs without Chroma parts for correct setting of Cbfs
    
            if( lumaUsesISP || pu.contains( *ptu, CHANNEL_TYPE_CHROMA ) )
    
            {
              saveCS.addTU( *ptu, partitioner.chType );
              orgTUs.push_back( ptu );
            }
          }
    
          // SATD pre-selecting.
          int satdModeList[NUM_CHROMA_MODE];
          int64_t satdSortedCost[NUM_CHROMA_MODE];
          for (int i = 0; i < NUM_CHROMA_MODE; i++)
          {
            satdSortedCost[i] = 0; // for the mode not pre-select by SATD, do RDO by default, so set the initial value 0.
            satdModeList[i] = 0;
          }
    
    #if JVET_Z0050_DIMD_CHROMA_FUSION && ENABLE_DIMD
    
    #if JVET_AC0071_DBV
          bool modeIsEnable[NUM_INTRA_MODE + 3]; // use intra mode idx to check whether enable
          for (int i = 0; i < NUM_INTRA_MODE + 3; i++)
          {
            modeIsEnable[i] = 1;
          }
    #else
          bool modeIsEnable[NUM_INTRA_MODE + 2]; // use intra mode idx to check whether enable
          for (int i = 0; i < NUM_INTRA_MODE + 2; i++)
          {
            modeIsEnable[i] = 1;
          }
    #endif
    #else
    #if JVET_AC0071_DBV
    
          bool modeIsEnable[NUM_INTRA_MODE + 2]; // use intra mode idx to check whether enable
          for (int i = 0; i < NUM_INTRA_MODE + 2; i++)
          {
            modeIsEnable[i] = 1;
          }
    #else
    
          bool modeIsEnable[NUM_INTRA_MODE + 1]; // use intra mode idx to check whether enable
          for (int i = 0; i < NUM_INTRA_MODE + 1; i++)
          {
            modeIsEnable[i] = 1;
          }
    
          DistParam distParamSad;
          DistParam distParamSatd;
    
          pu.intraDir[1] = MDLM_L_IDX; // temporary assigned, just to indicate this is a MDLM mode. for luma down-sampling operation.
    
          initIntraPatternChType(cu, pu.Cb());
          initIntraPatternChType(cu, pu.Cr());
          xGetLumaRecPixels(pu, pu.Cb());
    
    Che-Wei Kuo's avatar
    Che-Wei Kuo committed
    
    #if JVET_AA0126_GLM
          if ( PU::isLMCModeEnabled( pu, LM_CHROMA_IDX ) && PU::hasGlmFlag( pu, LM_CHROMA_IDX ) )
          {
    
    #if JVET_AB0092_GLM_WITH_LUMA && JVET_AB0174_CCCM_DIV_FREE
            xGlmSetLumaRefValue(pu, pu.Cb());
    #endif
    
    Che-Wei Kuo's avatar
    Che-Wei Kuo committed
            // Generate all GLM templates at encoder
            xGetLumaRecPixelsGlmAll(pu, pu.Cb());
    
            pu.intraDir[1] = LM_CHROMA_IDX;
            xGetLumaRecPixels(pu, pu.Cb());
    
    Che-Wei Kuo's avatar
    Che-Wei Kuo committed
    
            for ( int mode = LM_CHROMA_IDX; mode <= MMLM_T_IDX; mode++ )
            {
              satdGlmIdcBest[mode - LM_CHROMA_IDX].setAllZero();
              
    
    #if JVET_AB0092_GLM_WITH_LUMA
              CodedCUInfo& relatedCU = ((EncModeCtrlMTnoRQT *)m_modeCtrl)->getBlkInfo(partitioner.currArea());
              if (PU::hasGlmFlag(pu, mode) && !relatedCU.skipGLM)
    #else
    
    Che-Wei Kuo's avatar
    Che-Wei Kuo committed
              if ( PU::hasGlmFlag( pu, mode ) )
    
    Che-Wei Kuo's avatar
    Che-Wei Kuo committed
              {
    
    #if !JVET_AB0092_GLM_WITH_LUMA
    
    Che-Wei Kuo's avatar
    Che-Wei Kuo committed
                for ( int comp = COMPONENT_Cb; comp <= COMPONENT_Cr; comp++ )
                {
                  ComponentID       compID = ComponentID( comp );
    
    Vadim Seregin's avatar
    Vadim Seregin committed
                  ComponentID       compID = COMPONENT_Cb;
    
    Che-Wei Kuo's avatar
    Che-Wei Kuo committed
                  int              idcBest = 0;
                  int64_t         satdBest = 0;
                  GlmIdc&         idcsBest = satdGlmIdcBest[mode - LM_CHROMA_IDX];
                  
                  pu.intraDir[1] = mode;
                  pu.glmIdc.setAllZero();
    
                  xFindBestGlmIdcSATD(pu, compID, idcBest, satdBest );
    
                  idcsBest.setIdc(compID, 0, idcBest);
                  idcsBest.setIdc(compID, 1, idcBest);
    
    
    #if JVET_AB0092_GLM_WITH_LUMA
                  idcsBest.setIdc(COMPONENT_Cr, 0, idcBest);
                  idcsBest.setIdc(COMPONENT_Cr, 1, idcBest);
    #endif
    
    Che-Wei Kuo's avatar
    Che-Wei Kuo committed
                  
                  satdGlmCosts[mode - LM_CHROMA_IDX] += satdBest; // Summing up Cb and Cr cost
    
    #if !JVET_AB0092_GLM_WITH_LUMA
    
    Che-Wei Kuo's avatar
    Che-Wei Kuo committed
                }
                
                if ( !satdGlmIdcBest[0].isActive() )
                {
                  break;
                }
    
    Che-Wei Kuo's avatar
    Che-Wei Kuo committed
              }
            }
          }
    
          pu.glmIdc.setAllZero();
    #endif
    
          
    #if JVET_Z0050_CCLM_SLOPE
          if ( PU::isLMCModeEnabled( pu, LM_CHROMA_IDX ) && PU::hasCclmDeltaFlag( pu, LM_CHROMA_IDX ) )
          {
            // Fill luma reference buffer for the two-sided CCLM
            pu.intraDir[1] = LM_CHROMA_IDX;
            xGetLumaRecPixels(pu, pu.Cb());
    
            for ( int mode = LM_CHROMA_IDX; mode <= MDLM_T_IDX; mode++ )
            {
              satdCclmOffsetsBest[mode - LM_CHROMA_IDX].setAllZero();
              
              if ( PU::hasCclmDeltaFlag( pu, mode ) )
              {
                for ( int comp = COMPONENT_Cb; comp <= COMPONENT_Cr; comp++ )
                {
                  ComponentID       compID = ComponentID( comp );
                  int            deltaBest = 0;
                  int64_t         satdBest = 0;
                  CclmOffsets& offsetsBest = satdCclmOffsetsBest[mode - LM_CHROMA_IDX];
                  
                  pu.intraDir[1] = mode;
                  pu.cclmOffsets.setAllZero();
    
                  xFindBestCclmDeltaSlopeSATD(pu, compID, 0, deltaBest, satdBest );
    
                  offsetsBest.setOffset(compID, 0, deltaBest);
    
    #if MMLM
                  if ( PU::isMultiModeLM( mode ) )
                  {
                    // Set best found values for the first model to get a matching second model
                    pu.cclmOffsets.setOffsets(offsetsBest.cb0, offsetsBest.cr0, 0, 0);
    
                    xFindBestCclmDeltaSlopeSATD(pu, compID, 1, deltaBest, satdBest );
    
                    offsetsBest.setOffset(compID, 1, deltaBest);
                  }
    #endif
    
                  satdCclmCosts[mode - LM_CHROMA_IDX] += satdBest; // Summing up Cb and Cr cost
                }
              }
            }
          }
    
          pu.cclmOffsets.setAllZero();
    #endif
    
    #if JVET_AD0120_LBCCP && MMLM
          std::vector<lmPredFiltModeInfo> miLmPredFiltList;
          miLmPredFiltList.clear();
    #if JVET_AD0188_CCP_MERGE
          CCPModelCandidate ccpCandlmPredFilt[LBCCP_FILTER_MMLMNUM];
    #endif
          PelUnitBuf lmPredFilterStorage[LBCCP_FILTER_MMLMNUM];
          const UnitArea tmpUnitArea(pu.chromaFormat, Area(0, 0, (pu.Cb().width) << getChannelTypeScaleX(CHANNEL_TYPE_CHROMA, pu.chromaFormat), (pu.Cb().height) << getChannelTypeScaleY(CHANNEL_TYPE_CHROMA, pu.chromaFormat)));
          for (uint32_t i = 0; i < LBCCP_FILTER_MMLMNUM; i++)
          {
            lmPredFilterStorage[i] = m_lmPredFiltStorage[i].getBuf(tmpUnitArea);
    #if JVET_AD0188_CCP_MERGE
            ccpCandlmPredFilt[i] = {};
    #endif
          }
          int lmPredFiltIdx = 0;
    #endif
    
    Vadim Seregin's avatar
    Vadim Seregin committed
    #if MMLM
          m_encPreRDRun = true;
    #endif
    
          for (int idx = uiMinMode; idx <= uiMaxMode - 1; idx++)
          {
            int mode = chromaCandModes[idx];
            satdModeList[idx] = mode;
            if (PU::isLMCMode(mode) && !PU::isLMCModeEnabled(pu, mode))
            {
              continue;
            }
    
            if ((mode == LM_CHROMA_IDX) || (mode == PLANAR_IDX) || (mode == DM_CHROMA_IDX)
    #if JVET_Z0050_DIMD_CHROMA_FUSION && ENABLE_DIMD
              || (mode == DIMD_CHROMA_IDX)
    
    #endif
    #if JVET_AC0071_DBV
              || (mode == DBV_CHROMA_IDX)
    
    #endif
              ) // only pre-check regular modes and MDLM modes, not including DM, DIMD, Planar, and LM
    
            {
              continue;
            }
            pu.intraDir[1] = mode; // temporary assigned, for SATD checking.
    
    
            int64_t sad = 0;
            int64_t sadCb = 0;
            int64_t satdCb = 0;
            int64_t sadCr = 0;
            int64_t satdCr = 0;
    
            CodingStructure& cs = *(pu.cs);
    
    #if JVET_AD0120_LBCCP && JVET_AD0188_CCP_MERGE
            pu.curCand = {};
    #endif
    
    
            CompArea areaCb = pu.Cb();
            PelBuf orgCb = cs.getOrgBuf(areaCb);
            PelBuf predCb = cs.getPredBuf(areaCb);
    
            m_pcRdCost->setDistParam(distParamSad, orgCb, predCb, pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, false);
            m_pcRdCost->setDistParam(distParamSatd, orgCb, predCb, pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, true);
            distParamSad.applyWeight = false;
            distParamSatd.applyWeight = false;
    
            if (PU::isLMCMode(mode))
            {
              predIntraChromaLM(COMPONENT_Cb, predCb, pu, areaCb, mode);
            }
            else
            {
    
              initPredIntraParams(pu, pu.Cb(), *pu.cs->sps);
              predIntraAng(COMPONENT_Cb, predCb, pu);
    
            sadCb = distParamSad.distFunc(distParamSad) * 2;
            satdCb = distParamSatd.distFunc(distParamSatd);
            sad += std::min(sadCb, satdCb);
    
            CompArea areaCr = pu.Cr();
            PelBuf orgCr = cs.getOrgBuf(areaCr);
            PelBuf predCr = cs.getPredBuf(areaCr);
    
            m_pcRdCost->setDistParam(distParamSad, orgCr, predCr, pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cr, false);
            m_pcRdCost->setDistParam(distParamSatd, orgCr, predCr, pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cr, true);
            distParamSad.applyWeight = false;
            distParamSatd.applyWeight = false;
    
            if (PU::isLMCMode(mode))
            {
              predIntraChromaLM(COMPONENT_Cr, predCr, pu, areaCr, mode);
            }
            else
            {
    
              initPredIntraParams(pu, pu.Cr(), *pu.cs->sps);
              predIntraAng(COMPONENT_Cr, predCr, pu);
    
            sadCr = distParamSad.distFunc(distParamSad) * 2;
            satdCr = distParamSatd.distFunc(distParamSatd);
            sad += std::min(sadCr, satdCr);
    
            satdSortedCost[idx] = sad;
    
    #if JVET_AD0120_LBCCP && MMLM
            if(mode == MMLM_CHROMA_IDX)
            {
              lmPredFilterStorage[lmPredFiltIdx].Cb().copyFrom(predCb);
              lmPredFilterStorage[lmPredFiltIdx].Cr().copyFrom(predCr);
    #if JVET_AD0188_CCP_MERGE
              ccpCandlmPredFilt[lmPredFiltIdx] = pu.curCand;
    #endif
            }
    #endif
    
    
    #if JVET_AB0143_CCCM_TS
    #if MMLM
    
    #if JVET_AC0054_GLCCCM
          uint32_t chromaCandCccmModes[CCCM_NUM_MODES] = { LM_CHROMA_IDX, MDLM_L_IDX, MDLM_T_IDX, MMLM_CHROMA_IDX, MMLM_L_IDX, MMLM_T_IDX
                                                         , LM_CHROMA_IDX, MDLM_L_IDX, MDLM_T_IDX, MMLM_CHROMA_IDX, MMLM_L_IDX, MMLM_T_IDX };
    #else
    
    Vadim Seregin's avatar
    Vadim Seregin committed
          uint32_t chromaCandCccmModes[CCCM_NUM_MODES] = { LM_CHROMA_IDX, MDLM_L_IDX, MDLM_T_IDX, MMLM_CHROMA_IDX, MMLM_L_IDX, MMLM_T_IDX };
    
    #endif
    #else
    #if JVET_AC0054_GLCCCM
          uint32_t chromaCandCccmModes[CCCM_NUM_MODES] = { LM_CHROMA_IDX, MDLM_L_IDX, MDLM_T_IDX
                                                         , LM_CHROMA_IDX, MDLM_L_IDX, MDLM_T_IDX };
    
    Vadim Seregin's avatar
    Vadim Seregin committed
          uint32_t chromaCandCccmModes[CCCM_NUM_MODES] = { LM_CHROMA_IDX, MDLM_L_IDX, MDLM_T_IDX };
    
    #if JVET_AD0202_CCCM_MDF   
          int satdCccmFilterIndex[TOTAL_NUM_CCCM_MODES];
    #if JVET_AC0054_GLCCCM
          int satdCccmFlagList[TOTAL_NUM_CCCM_MODES];
    #endif
    #else
    
    #if JVET_AC0054_GLCCCM
          int satdCccmFlagList[CCCM_NUM_MODES];
    #endif
    
    #if JVET_AC0147_CCCM_NO_SUBSAMPLING
    
    #if JVET_AD0202_CCCM_MDF  
          int64_t satdCccmSortedCost[2][TOTAL_NUM_CCCM_MODES];
          int satdCccmModeList[2][TOTAL_NUM_CCCM_MODES];
          for (int i = 0; i < CCCM_NUM_PRED_FILTER; i++)
          {
            int startIdx = i * CCCM_NUM_MODES;
            for (int j = 0; j < CCCM_NUM_MODES; j++)
            {
              int currCccmModeIdx = startIdx + j;
              satdCccmSortedCost[0][currCccmModeIdx] = LLONG_MAX; // for the mode not pre-select by SATD, do RDO by default, so set the initial value 0.
              satdCccmSortedCost[1][currCccmModeIdx] = LLONG_MAX; // for the mode not pre-select by SATD, do RDO by default, so set the initial value 0.
              satdCccmModeList[0][currCccmModeIdx] = chromaCandCccmModes[j];
              satdCccmModeList[1][currCccmModeIdx] = chromaCandCccmModes[j];
    #if JVET_AC0054_GLCCCM
              satdCccmFlagList[currCccmModeIdx] = j < (CCCM_NUM_MODES / 2) ? 1 : 2; // 1: cccm, 2: glCccm
    #endif
              satdCccmFilterIndex[currCccmModeIdx] = i;
            }
          }
    #else
    
          int64_t satdCccmSortedCost[2][CCCM_NUM_MODES];
          int satdCccmModeList[2][CCCM_NUM_MODES];
    
          for (int i = 0; i < CCCM_NUM_MODES; i++)
          {
            satdCccmSortedCost[0][i] = LLONG_MAX; // for the mode not pre-select by SATD, do RDO by default, so set the initial value 0.
            satdCccmSortedCost[1][i] = LLONG_MAX; // for the mode not pre-select by SATD, do RDO by default, so set the initial value 0.
            satdCccmModeList[0][i] = chromaCandCccmModes[i];
            satdCccmModeList[1][i] = chromaCandCccmModes[i];
    
    #if JVET_AC0054_GLCCCM
            satdCccmFlagList[i] = i < (CCCM_NUM_MODES / 2) ? 1 : 2; // 1: cccm, 2: glCccm
    #endif
    
          int64_t bestCccmCost[2] = { LLONG_MAX, LLONG_MAX};
    
          bool isCccmFullEnabled = PU::cccmSingleModeAvail(pu, LM_CHROMA_IDX);
          bool isCccmLeftEnabled = PU::isLeftCccmMode(pu, MDLM_L_IDX);
          bool isCccmTopEnabled = PU::isTopCccmMode(pu, MDLM_T_IDX);
    #if MMLM
          bool isMultiCccmFullEnabled = PU::cccmMultiModeAvail(pu, MMLM_CHROMA_IDX);
          bool isMultiCccmLeftEnabled = PU::cccmMultiModeAvail(pu, MMLM_L_IDX);
          bool isMultiCccmTopEnabled = PU::cccmMultiModeAvail(pu, MMLM_T_IDX);
    #endif
    
    #if JVET_AD0202_CCCM_MDF
          bool isMultiCccmFullEnabled2 = PU::isMultiCccmWithMdf(pu, MMLM_CHROMA_IDX);
          bool isMultiCccmLeftEnabled2 = PU::isMultiCccmWithMdf(pu, MMLM_L_IDX);
          bool isMultiCccmTopEnabled2 = PU::isMultiCccmWithMdf(pu, MMLM_T_IDX);
    #endif
    
    
          const UnitArea localUnitArea(cs.area.chromaFormat, Area(0, 0, (pu.Cb().width) << 1, (pu.Cb().height) << 1));
    
    #if JVET_AD0202_CCCM_MDF
          PelUnitBuf cccmStorage[2][TOTAL_NUM_CCCM_MODES];
    #else
    
          PelUnitBuf cccmStorage[2][CCCM_NUM_MODES];
    
    #if JVET_AD0202_CCCM_MDF
          pu.cccmNoSubFlag = 1;
          xGetLumaRecPixels(pu, pu.Cb());
          pu.cccmNoSubFlag = 0;
          xGetLumaRecPixels(pu, pu.Cb());
          xGetLumaRecPixels(pu, pu.Cb(), 1);
          xGetLumaRecPixels(pu, pu.Cb(), 2);
          xGetLumaRecPixels(pu, pu.Cb(), 3);
    #endif
    
    
          for (int sub = 0; sub < pu.cu->slice->getSPS()->getUseCccm(); sub++)
          {
            pu.cccmNoSubFlag = sub;
    
    
            xGetLumaRecPixels(pu, pu.Cb());
    
    
            bool isCCCMEnabled = false;
    
            for (int idx = 0; idx < CCCM_NUM_MODES; idx++)
            {
    
    #if JVET_AC0054_GLCCCM
              if (sub && idx >= CCCM_NUM_MODES / 2)
              {
                continue;
              }
    #endif
    
              int mode = chromaCandCccmModes[idx];
              if (idx == 0)
              {
                isCCCMEnabled = isCccmFullEnabled;
                pu.cccmFlag = 1;
              }
              else if (idx == 1)
              {
                isCCCMEnabled = isCccmLeftEnabled;
                pu.cccmFlag = 2;
              }
              else if (idx == 2)
              {
                isCCCMEnabled = isCccmTopEnabled;
                pu.cccmFlag = 3;
              }
    #if MMLM
              else if (idx == 3)
              {
                isCCCMEnabled = isMultiCccmFullEnabled;
                pu.cccmFlag = 1;
              }
              else if (idx == 4)
              {
                isCCCMEnabled = isMultiCccmLeftEnabled;
                pu.cccmFlag = 2;
              }
              else if (idx == 5)
              {
                isCCCMEnabled = isMultiCccmTopEnabled;
                pu.cccmFlag = 3;
              }
    #endif
    
                
    #if JVET_AC0054_GLCCCM
              if (idx < CCCM_NUM_MODES / 2)
              {
                pu.glCccmFlag = 0;
              }
              else
              {
                pu.glCccmFlag = 1;
    #if MMLM
                isCCCMEnabled = idx == 6 ? isCccmFullEnabled
                : idx == 7 ? isCccmLeftEnabled
                : idx == 8 ? isCccmTopEnabled
                : idx == 9 ? isMultiCccmFullEnabled
                : idx == 10 ? isMultiCccmLeftEnabled : isMultiCccmTopEnabled;
                pu.cccmFlag =  idx == 6 ? 1
                : idx == 7 ? 2
                : idx == 8 ? 3
                : idx == 9 ? 1
                : idx == 10 ? 2 : 3;
    #else
                isCCCMEnabled = idx == 3 ? isCccmFullEnabled
                : idx == 4 ? isCccmLeftEnabled : isCccmTopEnabled;
                pu.cccmFlag =   idx == 3 ? 1
                : idx == 4 ? 2 : 3;
    #endif
    
    
    #if JVET_AD0202_CCCM_MDF
                if (isCCCMEnabled)
                {
                  if (m_skipCCCMwithMdfSATD)
                  {
                    if (m_isCccmWithMdfEnabledInRdo[4][mode] == 0)
                    {
                      continue;
                    }
                  }
                }
    #endif
    
    #if JVET_AD0202_CCCM_MDF
                for (int32_t filterIdx = 0; filterIdx < CCCM_NUM_PRED_FILTER; filterIdx++)
                {
                if (filterIdx > 0)
                {
                  if (sub == 1 || idx > 5)
                  {
                    continue;
                  }
    
                  if (m_skipCCCMwithMdfSATD)
                  {
                    if (m_isCccmWithMdfEnabledInRdo[filterIdx][mode] == 0)
                    {
                      continue;
                    }
                  }
    
                  if (mode == MMLM_CHROMA_IDX && !isMultiCccmFullEnabled2)
                  {
                    continue;
                  }
                  else if (mode == MMLM_L_IDX && !isMultiCccmLeftEnabled2)
                  {
                    continue;
                  }
                  else if (mode == MMLM_T_IDX && !isMultiCccmTopEnabled2)
                  {
                    continue;
                  }
                }
                else if (sub == 0 && idx <= 5)
                {
                  if (m_skipCCCMwithMdfSATD)
                  {
                    if (m_isCccmWithMdfEnabledInRdo[filterIdx][mode] == 0)
                    {
                      continue;
                    }
                  }
                }
    
                pu.cccmMultiFilterIdx = filterIdx;
    #endif
    
                pu.intraDir[1] = mode; // temporary assigned, for SATD checking.
    
                if ( ( sub == 1 ) && m_skipCCCMSATD )
                {
                  if (m_isCccmNoSubModeEnabledInRdo[mode] == 0)
                  {
                    continue;
                  }
                }
    
                int64_t sad = 0;
                int64_t sadCb = 0;
                int64_t satdCb = 0;
                int64_t sadCr = 0;
                int64_t satdCr = 0;
                CodingStructure& cs = *(pu.cs);
    
                DistParam distParamSadCb;
                DistParam distParamSatdCb;
                DistParam distParamSadCr;
                DistParam distParamSatdCr;
    
    
    #if JVET_AD0202_CCCM_MDF
                const int cccmBufferIdx = filterIdx * CCCM_NUM_MODES + idx;
                cccmStorage[sub][cccmBufferIdx] = m_cccmStorage[sub][cccmBufferIdx].getBuf(localUnitArea);
    #else
    
                cccmStorage[sub][idx] = m_cccmStorage[sub][idx].getBuf(localUnitArea);
    
    
                CompArea areaCb = pu.Cb();
                PelBuf orgCb = cs.getOrgBuf(areaCb);
                CompArea areaCr = pu.Cr();
                PelBuf orgCr = cs.getOrgBuf(areaCr);
    
    
    #if JVET_AD0202_CCCM_MDF
                m_pcRdCost->setDistParam(distParamSadCb, orgCb, cccmStorage[sub][cccmBufferIdx].Cb(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, false);
                m_pcRdCost->setDistParam(distParamSatdCb, orgCb, cccmStorage[sub][cccmBufferIdx].Cb(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, true);
    #else
    
                m_pcRdCost->setDistParam(distParamSadCb, orgCb, cccmStorage[sub][idx].Cb(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, false);
                m_pcRdCost->setDistParam(distParamSatdCb, orgCb, cccmStorage[sub][idx].Cb(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, true);
    
                distParamSadCb.applyWeight = false;
                distParamSatdCb.applyWeight = false;
    
    #if JVET_AD0202_CCCM_MDF
                m_pcRdCost->setDistParam(distParamSadCr, orgCr, cccmStorage[sub][cccmBufferIdx].Cr(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cr, false);
                m_pcRdCost->setDistParam(distParamSatdCr, orgCr, cccmStorage[sub][cccmBufferIdx].Cr(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cr, true);
    #else
    
                m_pcRdCost->setDistParam(distParamSadCr, orgCr, cccmStorage[sub][idx].Cr(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cr, false);
                m_pcRdCost->setDistParam(distParamSatdCr, orgCr, cccmStorage[sub][idx].Cr(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cr, true);
    
                distParamSadCr.applyWeight = false;
                distParamSatdCr.applyWeight = false;
    
    
    #if JVET_AD0202_CCCM_MDF
                predIntraCCCM(pu, cccmStorage[sub][cccmBufferIdx].Cb(), cccmStorage[sub][cccmBufferIdx].Cr(), mode);
    #else
    
                predIntraCCCM(pu, cccmStorage[sub][idx].Cb(), cccmStorage[sub][idx].Cr(), mode);
    
    #if JVET_AD0188_CCP_MERGE
    #if JVET_AD0202_CCCM_MDF
                m_ccmParamsStorage[sub][cccmBufferIdx] = pu.curCand;
    #else
                m_ccmParamsStorage[sub][idx] = pu.curCand;
    #endif
    #endif
    
                sadCb = distParamSadCb.distFunc(distParamSadCb) * 2;
                satdCb = distParamSatdCb.distFunc(distParamSatdCb);
                sad += std::min(sadCb, satdCb);
                sadCr = distParamSadCr.distFunc(distParamSadCr) * 2;
                satdCr = distParamSatdCr.distFunc(distParamSatdCr);
                sad += std::min(sadCr, satdCr);
    
    
    #if JVET_AD0202_CCCM_MDF
                satdCccmSortedCost[sub][cccmBufferIdx] = sad;
    #else
    
                satdCccmSortedCost[sub][idx] = sad;