Introduction to MIP technology principle: https://blog.csdn.net/BigDream123/article/details/104939645
The related function code of MIP is called for the first time in the estIntraPredLumaQT function, as shown in the following code, where
- The initIntraMip function is used to downsample the reference pixels and prepare input data for MIP matrix multiplication
- The getNumModesMip function obtains the number of different MIP modes according to the size of the current block
- The predIntraMip function performs matrix operations and up-sampling interpolation to obtain the predicted value of the entire block
Note: There is a block size limitation for MIP use: the aspect ratio cannot exceed 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 can be divided into the following three cases according to the block size:
Block size | MIP mode | |
mipSizeId = 0 | 4x4 | 32 |
mipSizeId = 1 | 4xN, Nx4, 8x8 | 16 |
mipSizeId = 2 | Rest block | 12 |
Among them, the transposition mark of MIP is related to the mode number of MIP:
- When mipSizdId = 0, the mipTransposedFlag of the first 16 modes is 0, and the mipTransposedFlag of the last 16 modes is 1
- When mipSizeId = 1, the mipTransposedFlag of the first 8 modes is 0, and the mipTransposedFlag of the last 8 modes is 1
- When mipSizeId = 2, mipTransposedFlag = 0 for the first 6 modes and mipTransposedFlag = 1 for the last 6 modes
The getNumModesMip function code is as follows:
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 function related code reference: https://blog.csdn.net/BigDream123/article/details/107018446
PredIntraMip function related code reference: https://blog.csdn.net/BigDream123/article/details/107019458