class Gauguin::ColorSpace::XyzVector

Constants

EPSILON
KAPPA
WHITE_REFERENCE

Public Instance Methods

to_lab() click to toggle source
# File lib/gauguin/color_space/xyz_vector.rb, line 9
def to_lab
  zipped = self.zip(XyzVector::WHITE_REFERENCE)
  x, y, z = zipped.map do |component, white_component|
    component / white_component
  end

  l = 116 * f(y) - 16
  a = 500 * (f(x) - f(y))
  b = 200 * (f(y) - f(z))

  LabVector[l, a, b]
end

Private Instance Methods

f(x) click to toggle source
# File lib/gauguin/color_space/xyz_vector.rb, line 24
def f(x)
  if x > EPSILON
    x ** (1.0/3.0)
  else
    (KAPPA * x + 16.0) / 116.0
  end
end