Class: Abachrome::Converters::OklabToOklch
- Defined in:
- lib/abachrome/converters/oklab_to_oklch.rb
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.convert(oklab_color) ⇒ Abachrome::Color
Converts a color from OKLAB color space to OKLCH 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(oklab_color) ⇒ Abachrome::Color
Converts a color from OKLAB color space to OKLCH color space. The method performs a mathematical transformation from the rectangular coordinates (L, a, b) to cylindrical coordinates (L, C, h), where:
- L (lightness) remains the same
- C (chroma) is calculated as the Euclidean distance from the origin in the a-b plane
- h (hue) is calculated as the angle in the a-b plane
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/abachrome/converters/oklab_to_oklch.rb', line 37 def self.convert(oklab_color) raise_unless oklab_color, :oklab l, a, b = oklab_color.coordinates.map { |_| AbcDecimal(_) } c = ((a * a) + (b * b)).sqrt h = (AbcDecimal.atan2(b, a) * 180) / Math::PI h += 360 if h.negative? Color.new( ColorSpace.find(:oklch), [l, c, h], oklab_color.alpha ) end |