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

相关推荐
Jayden_Ruan28 分钟前
C++逆向输出一个字符串(三)
开发语言·c++·算法
点云SLAM1 小时前
C++ 常见面试题汇总
java·开发语言·c++·算法·面试·内存管理
叙白冲冲1 小时前
哈希算法以及面试答法
算法·面试·哈希算法
YuTaoShao3 小时前
【LeetCode 每日一题】1277. 统计全为 1 的正方形子矩阵
算法·leetcode·矩阵
古译汉书3 小时前
嵌入式铁头山羊stm32-ADC实现定时器触发的注入序列的单通道转换-Day26
开发语言·数据结构·stm32·单片机·嵌入式硬件·算法
野犬寒鸦3 小时前
力扣hot100:相交链表与反转链表详细思路讲解(160,206)
java·数据结构·后端·算法·leetcode
阿昭L3 小时前
leetcode两数之和
算法·leetcode
周树皮不皮3 小时前
【Leetcode100】算法模板之二叉树
算法
无名客03 小时前
sentinel限流常见的几种算法以及优缺点
算法·sentinel·限流
Moonbit4 小时前
月报Vol.03: 新增Bitstring pattern支持,构造器模式匹配增强
后端·算法·github