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

你可能感兴趣的:(图像处理,算法,ffmpeg,录屏软件,libyuv,dxgi)