YUV To RGB

This algorithm converts YUV color space to RGB color model.



									public struct RGB
{
	private byte _r;
	private byte _g;
	private byte _b;

	public RGB(byte r, byte g, byte b)
	{
		this._r = r;
		this._g = g;
		this._b = b;
	}

	public byte R
	{
		get { return this._r; }
		set { this._r = value; }
	}

	public byte G
	{
		get { return this._g; }
		set { this._g = value; }
	}

	public byte B
	{
		get { return this._b; }
		set { this._b = value; }
	}

	public bool Equals(RGB rgb)
	{
		return (this.R == rgb.R) && (this.G == rgb.G) && (this.B == rgb.B);
	}
}

public struct YUV
{
	private double _y;
	private double _u;
	private double _v;

	public YUV(double y, double u, double v)
	{
		this._y = y;
		this._u = u;
		this._v = v;
	}

	public double Y
	{
		get { return this._y; }
		set { this._y = value; }
	}

	public double U
	{
		get { return this._u; }
		set { this._u = value; }
	}

	public double V
	{
		get { return this._v; }
		set { this._v = value; }
	}

	public bool Equals(YUV yuv)
	{
		return (this.Y == yuv.Y) && (this.U == yuv.U) && (this.V == yuv.V);
	}
}

public static RGB YUVToRGB(YUV yuv)
{
	byte r = (byte)(yuv.Y + 1.4075 * (yuv.V - 128));
	byte g = (byte)(yuv.Y - 0.3455 * (yuv.U - 128) - (0.7169 * (yuv.V - 128)));
	byte b = (byte)(yuv.Y + 1.7790 * (yuv.U - 128));

	return new RGB(r, g, b);
}
								


Example

									YUV data = new YUV(82, 140, 87);
RGB value = YUVToRGB(data);
								


Output

									R: 24
G: 107
B: 103