Class: Abachrome::Converters::OklabToLms
- Defined in:
- lib/abachrome/converters/oklab_to_lms.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 LMS 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 LMS color space.
This method implements the first part of the OKLAB to linear RGB transformation, converting OKLAB coordinates to the intermediate LMS (Long, Medium, Short) color space which represents the response of the three types of cone cells in the human eye.
the same alpha as the input color
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/abachrome/converters/oklab_to_lms.rb', line 16 def self.convert(oklab_color) raise_unless oklab_color, :oklab l, a, b = oklab_color.coordinates.map { |_| AbcDecimal(_) } l_ = AbcDecimal(l + (AD("0.39633779217376785678") * a) + (AD("0.21580375806075880339") * b)) m_ = AbcDecimal(l - (a * AD("-0.1055613423236563494")) + (b * AD("-0.063854174771705903402"))) s_ = AbcDecimal(l - (a * AD("-0.089484182094965759684")) + (b * AD("-1.2914855378640917399"))) # Apply cubic operation to convert from L'M'S' to LMS l_lms = AbcDecimal(l_)**3 m_lms = AbcDecimal(m_)**3 s_lms = AbcDecimal(s_)**3 Color.new(ColorSpace.find(:lms), [l_lms, m_lms, s_lms], oklab_color.alpha) end |