HM编码器代码阅读(15)——帧间预测之AMVP模式(三)xGetBlkBits函数

时间:2022-02-03 11:34:33

GetBlkBits函数的主要功能是计算使用某种PU划分模式的时候,该种模式占用的比特数

Void TEncSearch::xGetBlkBits( PartSize eCUMode, Bool bPSlice, Int iPartIdx, UInt uiLastMode, UInt uiBlkBit[3])
{
	if ( eCUMode == SIZE_2Nx2N )
	{
		uiBlkBit[0] = (! bPSlice) ? 3 : 1;
		uiBlkBit[1] = 3;
		uiBlkBit[2] = 5;
	}
	else if ( (eCUMode == SIZE_2NxN || eCUMode == SIZE_2NxnU) || eCUMode == SIZE_2NxnD )
	{
		UInt aauiMbBits[2][3][3] = { { {0,0,3}, {0,0,0}, {0,0,0} } , { {5,7,7}, {7,5,7}, {9-3,9-3,9-3} } };
		if ( bPSlice )
		{
			uiBlkBit[0] = 3;
			uiBlkBit[1] = 0;
			uiBlkBit[2] = 0;
		}
		else
		{
			::memcpy( uiBlkBit, aauiMbBits[iPartIdx][uiLastMode], 3*sizeof(UInt) );
		}
	}
	else if ( (eCUMode == SIZE_Nx2N || eCUMode == SIZE_nLx2N) || eCUMode == SIZE_nRx2N )
	{
		UInt aauiMbBits[2][3][3] = { { {0,2,3}, {0,0,0}, {0,0,0} } , { {5,7,7}, {7-2,7-2,9-2}, {9-3,9-3,9-3} } };
		if ( bPSlice )
		{
			uiBlkBit[0] = 3;
			uiBlkBit[1] = 0;
			uiBlkBit[2] = 0;
		}
		else
		{
			::memcpy( uiBlkBit, aauiMbBits[iPartIdx][uiLastMode], 3*sizeof(UInt) );
		}
	}
	else if ( eCUMode == SIZE_NxN )
	{
		uiBlkBit[0] = (! bPSlice) ? 3 : 1;
		uiBlkBit[1] = 3;
		uiBlkBit[2] = 5;
	}
	else
	{
		printf("Wrong!\n");
		assert( 0 );
	}
}