chroma.js icon indicating copy to clipboard operation
chroma.js copied to clipboard

Add CMY color space

Open karenbennett opened this issue 7 years ago • 2 comments

Cyan, magenta, and yellow, the pigment primaries, are complements of the light primaries, red, green, and blue, respectively. Would it be possible to add the CMY color space?

karenbennett avatar Aug 02 '16 02:08 karenbennett

  • There is no single CMY color space; any combination of ink, process, and paper creates a new one.
  • Going from RGB to any particular CMY(K) color space is very much non-trivial.

Artoria2e5 avatar Apr 09 '21 15:04 Artoria2e5

That said, since there is support for a very naive version of CMYK, it only makes sense to make an equally naive version of CMY or to remove them both. For now you can use:

cmyk2cmy = function(cmyk) {
  const [c, m, y, k] = cmyk
  return [c + k, m + k, y + k]
}
cmy2cmyk = function(cmy) {
  const [c, m, y] = cmy
  const k = Math.max(...cmy)
  return [c - k, m - k, y - k, k]
}

const chroma = require('chroma-js')
const Color = chroma('black').__proto__ // big hack
Color.prototype.cmy = function() { cmyk2cmy(this.cmyk()); }
chroma.cmy = (...args) => new Color(...cmy2cmyk(args), 'cmyk')

Artoria2e5 avatar Apr 09 '21 22:04 Artoria2e5