图像处理算法大全(基于libyuv或IPP)----RGB32(ARGB)转成yuv420,RGB24,nv12,yuv422集合

《周星星教你学ffmpeg》技巧

libyuv源码:

cpp 复制代码
static void RGB32_2_YUV420(BYTE* pRGBAPtr, BYTE* pYUYVPtr, int width, int height)
{
#ifdef LIBYUV
	uint8_t* yplane = pYUYVPtr;
	uint8_t* uplane = pYUYVPtr + width * height;
	uint8_t* vplane = pYUYVPtr + (width * height*5 / 4);
	int n = libyuv::ARGBToI420( pRGBAPtr, width * 4,yplane, width, uplane, width / 2, vplane, width / 2, width, height);
#else
	DWORD dwTime = ::GetTickCount();
	IppiSize imgSize;
	imgSize.width = width;
	imgSize.height = height;
	Ipp8u* pDes[3] = { pYUYVPtr,pYUYVPtr + height * width * 5 / 4,pYUYVPtr + height * width };
	int Des[3] = { width,width * 1 / 2,width * 1 / 2 };//YUV420->1,1/2,1/2

	int* pInt = Des;
	IppStatus is = ippiBGRToYCrCb420_8u_AC4P3R(pRGBAPtr, width*4, pDes, Des, imgSize);
	if (is != ippStsNoErr)
	{
		return;
	}
#endif
}
static void RGB32_2_YUV422(BYTE* pRGBAPtr, BYTE* pYUYVPtr, int width, int height)//yuv422
{
#ifdef LIBYUV
	int n = libyuv::ARGBToYUY2(pRGBAPtr, width * 4, pYUYVPtr, width*2, width, height);
#else
	DWORD dwTime = ::GetTickCount();
	IppiSize imgSize;
	imgSize.width = width;
	imgSize.height = height;
	IppStatus is = ippiBGRToYCbCr422_8u_AC4C2R(pRGBAPtr, width*4, pYUYVPtr, width*2, imgSize);
	if (is != ippStsNoErr)
	{
		return;
	}
#endif
}
cpp 复制代码
static void RGB32ToNV12(BYTE* pRGBA, BYTE* pNV12, int width, int height)
{
	uint8_t* yplane = pNV12;
	uint8_t* uvplane = pNV12 + width * height;
	int n = libyuv::ARGBToNV12(pRGBA, width * 4, yplane, width, uvplane, width, width,
}

static void RGB32ToRGB24(BYTE *input_rgba, BYTE *output_rgb24, int width, int height)
{
	const int input_stride_rgba = width * 4; // 输入图像的步长,每个像素4字节
	const int output_stride_rgb24 = width * 3; // 输出图像的步长,每个像素3字节
	libyuv::ARGBToRGB24(input_rgba, input_stride_rgba, output_rgb24, output_stride_rgb24,
		width, height);
}

ok!打完收工!

相关推荐
代码小将38 分钟前
Leetcode209做题笔记
java·笔记·算法
Musennn2 小时前
leetcode 15.三数之和 思路分析
算法·leetcode·职场和发展
CM莫问4 小时前
<论文>(微软)避免推荐域外物品:基于LLM的受限生成式推荐
人工智能·算法·大模型·推荐算法·受限生成
康谋自动驾驶5 小时前
康谋分享 | 自动驾驶仿真进入“标准时代”:aiSim全面对接ASAM OpenX
人工智能·科技·算法·机器学习·自动驾驶·汽车
C++ 老炮儿的技术栈6 小时前
什么是函数重载?为什么 C 不支持函数重载,而 C++能支持函数重载?
c语言·开发语言·c++·qt·算法
yychen_java6 小时前
R-tree详解
java·算法·r-tree
MarkHard1237 小时前
Leetcode (力扣)做题记录 hot100(62,64,287,108)
算法·leetcode·职场和发展
一只鱼^_8 小时前
牛客练习赛138(首篇万字题解???)
数据结构·c++·算法·贪心算法·动态规划·广度优先·图搜索算法
一只码代码的章鱼8 小时前
Spring的 @Validate注解详细分析
前端·spring boot·算法
邹诗钰-电子信息工程8 小时前
嵌入式自学第二十一天(5.14)
java·开发语言·算法