Method: Color::CMYK#to_grayscale

Defined in:
lib/color/cmyk.rb

#to_grayscaleObject Also known as: to_greyscale

Converts the CMYK colour to a single greyscale value. There are undoubtedly multiple methods for this conversion, but only a minor variant of the Adobe conversion method will be used:

g = 1.0 - min(1.0, 0.299 * c + 0.587 * m + 0.114 * y + k)

This treats the CMY values similarly to YIQ (NTSC) values and then adds the level of black. This is a variant of the Adobe version because it uses the more precise YIQ (NTSC) conversion values for Y (intensity) rather than the approximates provided by Adobe (0.3, 0.59, and 0.11).

[View source]

143
144
145
146
147
148
149
# File 'lib/color/cmyk.rb', line 143

def to_grayscale
  c = 0.299 * @c.to_f
  m = 0.587 * @m.to_f
  y = 0.114 * @y.to_f
  g = 1.0 - [1.0, c + m + y + @k].min
  Color::GrayScale.from_fraction(g)
end