H264解析Demo11帧内预测编码_2_获得参考的像素值

Posted 叮咚咕噜

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了H264解析Demo11帧内预测编码_2_获得参考的像素值相关的知识,希望对你有一定的参考价值。

基础知识请参考:
十五、帧内编码:3、获取预测数据

知识储备

保存邻块像素值到数组中,数组的存放顺序如下图:(绿色为当前待解析的4 * 4宏块)
在这里插入图片描述

定义

//<预测编码><6>表示44=16个子宏块 * (44=16)每个子宏块中的4*4个像素 (先是列坐标)

UINT8 m_reconstructed_block[4][4][4][4];

代码实现

//<预测编码><5>获得参考像素:neighbors相邻宏块,当前宏块index,refPixBuf参考像素的值
int CMacroblock::get_reference_pixels(NeighborBlocks neighbors, UINT8 blkIdx, UINT8 *refPixBuf)
{
	bool available_left = neighbors.flags & 1, available_top = neighbors.flags & 2, available_top_right = neighbors.flags & 4, available_top_left = neighbors.flags & 8;
	UINT8 blk_row = -1, blk_column = -1;
	CMacroblock *ref_mb = NULL;

	block_index_to_position(blkIdx, blk_row, blk_column);	//<预测编码><6>根据index获得在当前宏块中的位置

	if (available_left)
	{
		ref_mb = m_slice->Get_macroblock_at_index(neighbors.left.target_mb_idx);
		refPixBuf[0] = ref_mb->m_reconstructed_block[neighbors.left.block_column][neighbors.left.block_row][3][3];
		refPixBuf[1] = ref_mb->m_reconstructed_block[neighbors.left.block_column][neighbors.left.block_row][2][3];
		refPixBuf[2] = ref_mb->m_reconstructed_block[neighbors.left.block_column][neighbors.left.block_row][1][3];
		refPixBuf[3] = ref_mb->m_reconstructed_block[neighbors.left.block_column][neighbors.left.block_row][0][3];
	} 
	else
	{
		refPixBuf[0] = refPixBuf[1] = refPixBuf[2] = refPixBuf[3] = 128;
	}

	if (available_top_left)
	{
		ref_mb = m_slice->Get_macroblock_at_index(neighbors.top_left.target_mb_idx);
		refPixBuf[4] = ref_mb->m_reconstructed_block[neighbors.top_left.block_column][neighbors.top_left.block_row][3][3];
	} 
	else
	{
		refPixBuf[4] = 128;
	}

	if (available_top)
	{
		ref_mb = m_slice->Get_macroblock_at_index(neighbors.top.target_mb_idx);
		refPixBuf[5] = ref_mb->m_reconstructed_block[neighbors.top.block_column][neighbors.top.block_row][3][0];
		refPixBuf[6] = ref_mb->m_reconstructed_block[neighbors.top.block_column][neighbors.top.block_row][3][1];
		refPixBuf[7] = ref_mb->m_reconstructed_block[neighbors.top.block_column][neighbors.top.block_row][3][2];
		refPixBuf[8] = ref_mb->m_reconstructed_block[neighbors.top.block_column][neighbors.top.block_row][3][3];
	} 
	else
	{
		refPixBuf[5] = refPixBuf[6] = refPixBuf[7] = refPixBuf[8] = 128;
	}

	if (available_top_right)
	{
		ref_mb = m_slice->Get_macroblock_at_index(neighbors.top_right.target_mb_idx);
		refPixBuf[9] = ref_mb->m_reconstructed_block[neighbors.top_right.block_column][neighbors.top_right.block_row][3][0];
		refPixBuf[10] = ref_mb->m_reconstructed_block[neighbors.top_right.block_column][neighbors.top_right.block_row][3][1];
		refPixBuf[11] = ref_mb->m_reconstructed_block[neighbors.top_right.block_column][neighbors.top_right.block_row][3][2];
		refPixBuf[12] = ref_mb->m_reconstructed_block[neighbors.top_right.block_column][neighbors.top_right.block_row][3][3];
	} 
	else
	{
		refPixBuf[9] = refPixBuf[10] = refPixBuf[11] = refPixBuf[12] = refPixBuf[8];		//<预测编码><6>如果右上是不可获取的,则将其像素值写为 refPixBuf[8],标准文档定义
	}

	return kPARSING_ERROR_NO_ERROR;
}

以上是关于H264解析Demo11帧内预测编码_2_获得参考的像素值的主要内容,如果未能解决你的问题,请参考以下文章

H264帧内预测模式编号的编码过程

H264编码原理之帧间预测与帧内预测

音视频 - H264结构

H264编码原理之帧间预测与帧内预测

文心一言 VS chatgpt (21)-- h264编码一帧数据的流程是怎样的?

H264解析Demo10变换量化_2_反量化