module Chromate::RGB

Constants

COLORS

RGB array representations of the 256 xterm colors

CONVERSION_MATRIX

D65 conversion matrix

RX

CIE D65 standard illuminant

RY
RZ

Public Class Methods

to_lab(rgb) click to toggle source

Convert an RGB array into an array representing coordinates in L*a*b* color space. @param rgb [<Integer>] an RGB array

@return [<Integer>] a L*a*b* array

# File lib/chromate/rgb.rb, line 93
def self.to_lab(rgb)
  xyz_matrix = CONVERSION_MATRIX * Matrix[*rgb.map do |c|
    c = c / 255.0
    if c > 0.04045
      [(c + 0.055 / 1.055) ** 2.4]
    else
      [c / 12.92]
    end
  end]
  f_x, f_y, f_z = *[
    xyz_matrix[0, 0] / RX,
    xyz_matrix[1, 0] / RY,
    xyz_matrix[2, 0] / RZ
  ].map do |c|
    if c > 0.008856
      Math.cbrt(c)
    else
      (903.3 * c + 16) / 116
    end
  end
  [116 * f_y - 16, 500 * (f_x - f_y), 200 * (f_y - f_z)]
end