Class: Abachrome::Converters::LmsToXyz

Inherits:
Base
  • Object
show all
Defined in:
lib/abachrome/converters/lms_to_xyz.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(lms_color) ⇒ Abachrome::Color

Converts a color from LMS color space to XYZ color space.

This method implements the LMS to XYZ transformation using the standard transformation matrix. The LMS color space represents the response of the three types of cone cells in the human eye (Long, Medium, Short), while XYZ is the CIE 1931 color space that forms the basis for most other color space definitions.

the same alpha as the input color

Raises:

  • (ArgumentError)

    If the input color is not in LMS color space



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/abachrome/converters/lms_to_xyz.rb', line 16

def self.convert(lms_color)
  raise_unless lms_color, :lms

  l, m, s = lms_color.coordinates.map { |_| AbcDecimal(_) }

  # LMS to XYZ transformation matrix
  x = (l * AD("1.86006661")) - (m * AD("1.12948190")) + (s * AD("0.21989740"))
  y = (l * AD("0.36122292")) + (m * AD("0.63881308")) - (s * AD("0.00000000"))
  z = (l * AD("0.00000000")) - (m * AD("0.00000000")) + (s * AD("1.08906362"))

  Color.new(ColorSpace.find(:xyz), [x, y, z], lms_color.alpha)
end