Class: Abachrome::Converters::OklchToOklab

Inherits:
Base
  • Object
show all
Defined in:
lib/abachrome/converters/oklch_to_oklab.rb

Instance Attribute Summary

Attributes inherited from Base

#from_space, #to_space

Class Method Summary collapse

Methods inherited from Base

#can_convert?, #convert, find_converter, #initialize, raise_unless, register

Constructor Details

This class inherits a constructor from Abachrome::Converters::Base

Class Method Details

.convert(oklch_color) ⇒ Abachrome::Color

Converts a color from OKLCH color space to OKLAB color space.

Parameters:

Returns:

Raises:

  • (StandardError)

    If the provided color is not in OKLCH color space



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/abachrome/converters/oklch_to_oklab.rb', line 31

def self.convert(oklch_color)
  raise_unless oklch_color, :oklch

  l, c, h = oklch_color.coordinates.map { |_| AbcDecimal(_) }

  h_rad = (h * Math::PI)/ AD(180)
  a = c * AD(Math.cos(h_rad.value))
  b = c * AD(Math.sin(h_rad.value))

  Color.new(
    ColorSpace.find(:oklab),
    [l, a, b],
    oklch_color.alpha
  )
end