2010
Jun
13
CMYK to RGB conversion
Posted by David Zaslavsky on — EditedIt certainly took long enough, but after an hour or so of hunting I finally tracked down the formula that the ImageMagick color converter uses to convert CMYK colors into RGB. I rewrote it a little to make the expression more illuminating:
$$r = Q_R (1 - c / Q_R)(1 - k / Q_R)$$
$$g = Q_R (1 - m / Q_R)(1 - k / Q_R)$$
$$b = Q_R (1 - y / Q_R)(1 - k / Q_R)$$
for a CMYK color point \((c,m,y,k)\) and RGB color point \((r,g,b)\). The tricky part to locate was the constant \(Q_R\), and a related constant \(Q_S\), which ImageMagick calls QuantumRange
and QuantumScale
respectively.
- \(Q_R\) is the range that each of the color values can take on, so if each of your channels (red, green, blue, cyan, magenta, yellow, black) is given by a number from 0–255, for example, \(Q_R\) would be 255.
- \(Q_S\) is actually just the reciprocal of \(Q_R\). I suspect they give it a different name only because floating-point division is pretty inefficient so it saves some CPU cycles to precompute \(1/Q_R\).
If anyone wants to track it down themselves, the algorithm is in the ConvertCMYKToRGB
function in the ImageMagick source code (line 1327 of colorspace …