H.266/VVC代碼學習:MIP技術相關代碼

MIP技術原理介紹:https://blog.csdn.net/BigDream123/article/details/104939645

MIP的相關函數代碼在estIntraPredLumaQT函數中首次被調用,如下代碼所示,其中

  • initIntraMip函數用於對參考像素進行下采樣,爲MIP矩陣乘法準備輸入數據
  • getNumModesMip函數根據當前塊的尺寸獲取不同的MIP模式數目
  • predIntraMip函數進行矩陣運算,並進行上採樣插值,獲得整個塊的預測值

注意:MIP使用存在塊尺寸限制:寬高比不能超過1:8/8:1

    //MIP允許使用標誌
    const bool mipAllowed = sps.getUseMIP() && isLuma(partitioner.chType) && ((cu.lfnstIdx == 0) || allowLfnstWithMip(cu.firstPU->lumaSize()));
    //MIP模式測試標誌:寬高比不能超過1:8/8:1
    const bool testMip = mipAllowed && !(cu.lwidth() > (8 * cu.lheight()) || cu.lheight() > (8 * cu.lwidth()));
    //MIP支持的最大塊尺寸爲64
    const bool supportedMipBlkSize = pu.lwidth() <= MIP_MAX_WIDTH && pu.lheight() <= MIP_MAX_HEIGHT;
...
...
...
// 初始化Mip模式
              initIntraPatternChType(cu, pu.Y());//獲取參考像素並濾波
              initIntraMip(pu, pu.Y());
              // getNumModesMip函數根據當前CU的塊尺寸獲取不同的Mip模式數量16 8 6
              const int transpOff    = getNumModesMip(pu.Y());
              const int numModesFull = (transpOff << 1);//MIP模式總數分別是32 16 12
              
              for (uint32_t uiModeFull = 0; uiModeFull < numModesFull; uiModeFull++)
              {
                //對於另一半MIP模式,其需要進行轉置
                const bool     isTransposed = (uiModeFull >= transpOff ? true : false);
                const uint32_t uiMode       = (isTransposed ? uiModeFull - transpOff : uiModeFull);

                pu.mipTransposedFlag           = isTransposed;
                pu.intraDir[CHANNEL_TYPE_LUMA] = uiMode;
                // Mip預測模式的函數入口,進行MIP預測
                predIntraMip(COMPONENT_Y, piPred, pu);

                // Use the min between SAD and HAD as the cost criterion
                // SAD is scaled by 2 to align with the scaling of HAD
                Distortion minSadHad =
                  std::min(distParamSad.distFunc(distParamSad) * 2, distParamHad.distFunc(distParamHad));

                m_CABACEstimator->getCtx() = SubCtx(Ctx::MipFlag, ctxStartMipFlag);

                uint64_t fracModeBits = xFracModeBitsIntra(pu, uiMode, CHANNEL_TYPE_LUMA);

                double cost            = double(minSadHad) + double(fracModeBits) * sqrtLambdaForFirstPass;
                mipHadCost[uiModeFull] = cost;
                DTRACE(g_trace_ctx, D_INTRA_COST, "IntraMIP: %u, %llu, %f (%d)\n", minSadHad, fracModeBits, cost,
                       uiModeFull);
                // 更新候選列表,將最優的Mip模式加入到RDCost的候選列表中
                updateCandList(ModeInfo(true, isTransposed, 0, NOT_INTRA_SUBPARTITIONS, uiMode), cost, uiRdModeList,
                               CandCostList, numModesForFullRD + 1);
                updateCandList(ModeInfo(true, isTransposed, 0, NOT_INTRA_SUBPARTITIONS, uiMode),
                               0.8 * double(minSadHad), uiHadModeList, CandHadList, numHadCand);
              }

MIP根據塊尺寸可以分爲以下三種情況:

  塊尺寸 MIP模式
mipSizeId = 0 4x4 32
mipSizeId = 1 4xN、Nx4、8x8 16
mipSizeId = 2 其餘塊 12

其中,MIP的轉置標誌和MIP的模式號有關:

  • mipSizdId = 0時,前16種模式的mipTransposedFlag= 0,後16種模式的mipTransposedFlag = 1
  • mipSizeId = 1時,前8種模式的mipTransposedFlag= 0,後8種模式的mipTransposedFlag = 1
  • mipSizeId = 2時,前6種模式的mipTransposedFlag= 0,後6種模式的mipTransposedFlag = 1

getNumModesMip函數代碼如下:

int getNumModesMip(const Size& block)
{
  switch( getMipSizeId(block) )
  {
  case 0: return 16;
  case 1: return  8;
  case 2: return  6;
  default: THROW( "Invalid mipSizeId" );
  }
}

initIntraMip函數相關代碼參考:https://blog.csdn.net/BigDream123/article/details/107018446

predIntraMip函數相關代碼參考:https://blog.csdn.net/BigDream123/article/details/107019458

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章