CMYK To RGB

This algorithm converts CMYK color model to RGB color model.



									class CMYK
{
public:
	double C;
	double M;
	double Y;
	double K;

	CMYK(double c, double m, double y, double k)
	{
		C = c;
		M = m;
		Y = y;
		K = k;
	}

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

class RGB
{
public:
	unsigned char R;
	unsigned char G;
	unsigned char B;

	RGB(unsigned char r, unsigned char g, unsigned char b)
	{
		R = r;
		G = g;
		B = b;
	}
	bool Equals(RGB rgb)
	{
		return (R == rgb.R) && (G == rgb.G) && (B == rgb.B);
	}
};

static RGB CMYKToRGB(CMYK cmyk) {
	unsigned char r = (unsigned char)(255 * (1 - cmyk.C) * (1 - cmyk.K));
	unsigned char g = (unsigned char)(255 * (1 - cmyk.M) * (1 - cmyk.K));
	unsigned char b = (unsigned char)(255 * (1 - cmyk.Y) * (1 - cmyk.K));

	return RGB(r, g, b);
}
								


Example

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


Output

									R: 82
G: 0
B: 87