RGB To YUV

This algorithm converts RGB color model to YUV color space.



									struct RGB
{
	unsigned char R;
	unsigned char G;
	unsigned char B;
};

struct YUV
{
	double Y;
	double U;
	double V;
};

struct YUV RGBToYUV(struct RGB rgb) {
	struct YUV yuv;
	yuv.Y = rgb.R * .299000 + rgb.G * .587000 + rgb.B * .114000;
	yuv.U = rgb.R * -.168736 + rgb.G * -.331264 + rgb.B * .500000 + 128;
	yuv.V = rgb.R * .500000 + rgb.G * -.418688 + rgb.B * -.081312 + 128;

	return yuv;
}
								


Example

									struct RGB data = { 82, 0, 87 };
struct YUV value = RGBToYUV(data);
								


Output

									Y: 34.436
U: 157.663648
V: 161.925856