Class: Colorspace::CIELABColor

Inherits:
Object
  • Object
show all
Defined in:
lib/colorspace/colorlib.rb

Overview

A color in the CIE LAB color space.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_hexObject



141
142
143
# File 'lib/colorspace/colorlib.rb', line 141

def self.from_hex(...)
  SRGBColor.from_hex(...).to_xyz.to_cielab
end

Instance Method Details

#cie76(other) ⇒ Object

rubocop: enable Metrics/AbcSize



163
164
165
# File 'lib/colorspace/colorlib.rb', line 163

def cie76(other)
  (((other.l - l)**2) + ((other.a - a)**2) + ((other.b - b)**2))**0.5
end

#ciede2000(other) ⇒ Object



167
168
169
170
# File 'lib/colorspace/colorlib.rb', line 167

def ciede2000(other)
  # TODO: write this
  cie76(other)
end

#to_aObject



173
# File 'lib/colorspace/colorlib.rb', line 173

def to_a = to_ary

#to_aryObject



172
# File 'lib/colorspace/colorlib.rb', line 172

def to_ary = [l, a, b]

#to_hexObject



145
146
147
# File 'lib/colorspace/colorlib.rb', line 145

def to_hex
  to_xyz.to_srgb.to_hex
end

#to_xyz(illuminant: D65) ⇒ Object

rubocop: disable Metrics/AbcSize



150
151
152
153
154
155
156
157
158
159
160
# File 'lib/colorspace/colorlib.rb', line 150

def to_xyz(illuminant: D65)
  xn, yn, zn = illuminant.x, illuminant.y, illuminant.z

  p = (l + 16) / 116.0

  x = xn * ((p + (a / 500.0))**3) / 100.0
  y = yn * (p**3) / 100.0
  z = zn * ((p - (b / 200.0))**3) / 100.0

  XYZTristimulus.new(x:, y:, z:)
end