CMYK To RGB

This algorithm converts CMYK color model to RGB color model.



									public struct CMYK
{
	private double _c;
	private double _m;
	private double _y;
	private double _k;

	public CMYK(double c, double m, double y, double k)
	{
		this._c = c;
		this._m = m;
		this._y = y;
		this._k = k;
	}

	public double C
	{
		get { return this._c; }
		set { this._c = value; }
	}

	public double M
	{
		get { return this._m; }
		set { this._m = value; }
	}

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

	public double K
	{
		get { return this._k; }
		set { this._k = value; }
	}

	public bool Equals(CMYK cmyk)
	{
		return (this.C == cmyk.C) && (this.M == cmyk.M) && (this.Y == cmyk.Y) && (this.K == cmyk.K);
	}
}

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 static RGB CMYKToRGB(CMYK cmyk)
{
	byte r = (byte)(255 * (1 - cmyk.C) * (1 - cmyk.K));
	byte g = (byte)(255 * (1 - cmyk.M) * (1 - cmyk.K));
	byte b = (byte)(255 * (1 - cmyk.Y) * (1 - cmyk.K));

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


Example

									CMYK data = new CMYK(0.47, 1, 0.44, 0.39);
RGB value = CMYKToRGB(data);
								


Output

									R: 82
G: 0
B: 87