KoColor && CMYK -> RGB

Leonard Rosenthol leonardr at lazerware.com
Thu Oct 23 21:10:27 CEST 2003


First, keep in mind that algorithmic color conversion between RGB & 
CMYK will NEVER give you colors that an pro considers acceptable - 
you MUST use ICCProfiles (see lcms- http://www.littlecms.org).

however, if you insist on algorithmic OR need a fallback for when 
ICC's arent' available, here are a set of algorithms that I use in my 
commercial color conversion software.


void ColorUtils::CMYKToRGB( ASFixed inCyan, ASFixed inMagenta, 
ASFixed inYellow, ASFixed inBlack,
 
	ASFixed& outRed, ASFixed& outGreen, ASFixed& outBlue )
{
#if 0	// standard/simple algorithm
	outRed = clip01( (1.0 - inCyan) * (1.0 - inBlack) );
	outGreen = clip01( (1.0 - inMagenta) * (1.0 - inBlack) );
	outBlue = clip01( (1.0 - inYellow) * (1.0 - inBlack) );
#else	// from Xpdf
	double c, m, y, aw, ac, am, ay, ar, ag, ab;

	c = clip01( inCyan + inBlack );
	m = clip01( inMagenta + inBlack );
	y = clip01( inYellow + inBlack );
	aw = (1-c) * (1-m) * (1-y);
	ac = c * (1-m) * (1-y);
	am = (1-c) * m * (1-y);
	ay = (1-c) * (1-m) * y;
	ar = (1-c) * m * y;
	ag = c * (1-m) * y;
	ab = c * m * (1-y);
	outRed = clip01(aw + 0.9137*am + 0.9961*ay + 0.9882*ar);
	outGreen = clip01(aw + 0.6196*ac + ay + 0.5176*ag);
	outBlue = clip01(aw + 0.7804*ac + 0.5412*am + 0.0667*ar + 
0.2118*ag + 0.4863*ab);
#endif
}

void ColorUtils::RGBToCMYK( ASFixed inRed, ASFixed inGreen, ASFixed inBlue,
 
	ASFixed& outCyan, ASFixed& outMagenta,
 
	ASFixed& outYellow, ASFixed& outBlack)
{
	double c, m, y, k;

	c = clip01( 1.0 - inRed );
	m = clip01( 1.0 - inGreen );
	y = clip01( 1.0 - inBlue );
	k = c;
	if (m < k) {
		k = m;
	}
	if (y < k) {
		k = y;
	}

	outCyan = c - k;
	outMagenta = m - k;
	outYellow = y - k;
	outBlack = k;
}


Leonard
-- 
---------------------------------------------------------------------------
Leonard Rosenthol                            <mailto:leonardr at lazerware.com>
                       			     <http://www.lazerware.com>


More information about the kimageshop mailing list