Class: Abachrome::Converters::OklchToOklab
- Defined in:
- lib/abachrome/converters/oklch_to_oklab.rb
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.convert(oklch_color) ⇒ Abachrome::Color
Converts a color from OKLCH color space to OKLAB color space.
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.
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 |