图像处理算法大全(基于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!打完收工!

相关推荐
WaitWaitWait012 小时前
LeetCode每日一题4.20
算法·leetcode
蒟蒻小袁2 小时前
力扣面试150题--有效的括号和简化路径
算法·leetcode·面试
跳跳糖炒酸奶3 小时前
第十五讲、Isaaclab中在机器人上添加传感器
人工智能·python·算法·ubuntu·机器人
明月看潮生5 小时前
青少年编程与数学 02-018 C++数据结构与算法 06课题、树
数据结构·c++·算法·青少年编程·编程与数学
小指纹5 小时前
动态规划(一)【背包】
c++·算法·动态规划
_安晓5 小时前
数据结构 -- 图的应用(一)
数据结构·算法·图论
阳洞洞5 小时前
leetcode 二分查找应用
算法·leetcode·二分查找
猎猎长风5 小时前
【数据结构和算法】1. 数据结构和算法简介、二分搜索
数据结构·算法
Pasregret5 小时前
模板方法模式:定义算法骨架的设计模式
算法·设计模式·模板方法模式
左灯右行的爱情6 小时前
JVM-卡表
java·jvm·算法