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

《周星星教你学ffmpeg》技巧

libyuv源码: 

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
}
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!打完收工!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

周星星的星

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值