Converting RGB, CMY and CMYK
The simplest conversions in color theory: CMY is the inverse of RGB, and CMYK is CMY with black split out as a separate component. The formulas are short, but it is worth knowing what they do not handle.
All values are in 0..1. Divide 0..255 values by 255, percentages by 100.
RGB and CMY
CMY describes how much light each ink should absorb (see CMY and CMYK models). White is (0, 0, 0), black (1, 1, 1).
CMY and CMYK
The part common to all three inks makes gray, which can be replaced with black:
Dividing by (1 - K) rescales the remaining inks to the full range, so C', M', Y' describe the hue and K describes how much it is darkened.
RGB and CMYK directly
Example
RGB (200, 80, 40), #c85028:
Code
// r, g, b in 0..1
function rgbToCmyk(r, g, b) {
const k = 1 - Math.max(r, g, b);
if (k === 1) return { c: 0, m: 0, y: 0, k: 1 };
return {
c: (1 - r - k) / (1 - k),
m: (1 - g - k) / (1 - k),
y: (1 - b - k) / (1 - k),
k,
};
}
function cmykToRgb(c, m, y, k) {
return { r: (1 - c) * (1 - k), g: (1 - m) * (1 - k), b: (1 - y) * (1 - k) };
}
What these formulas do not do
These are geometric conversions between two descriptions of the same cube. They know nothing about inks, paper or the press, so:
- they always replace the whole common gray with black (100% GCR), while print usually replaces only part of it,
- they ignore the total ink limit: black (0, 0, 0) comes out as K = 100%, while a print shop's "rich black" is e.g. C 60, M 40, Y 40, K 100,
- they ignore the gamut: the result always "fits" CMYK, even if the printer cannot reproduce the color.
Print-ready files are made with the ICC profile of the print process (see color management). The formulas above suit screen graphics, visualization and understanding how the model works.