Class: Abachrome::Converters::XyzToLrgb

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

Converts a color from XYZ color space to linear RGB color space.

This method implements the XYZ to linear RGB transformation using the inverse of the standard transformation matrix for the sRGB color space with D65 white point. The XYZ color space is the CIE 1931 color space that serves as a device-independent reference for color definitions.

the same alpha as the input color

Parameters:

Returns:

Raises:

  • (ArgumentError)

    If the input color is not in XYZ color space



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

def self.convert(xyz_color)
  raise_unless xyz_color, :xyz

  x, y, z = xyz_color.coordinates.map { |_| AbcDecimal(_) }

  # XYZ to Linear RGB transformation matrix (inverse of sRGB/D65)
  r = (x * AD("3.2404542")) + (y * AD("-1.5371385")) + (z * AD("-0.4985314"))
  g = (x * AD("-0.9692660")) + (y * AD("1.8760108")) + (z * AD("0.0415560"))
  b = (x * AD("0.0556434")) + (y * AD("-0.2040259")) + (z * AD("1.0572252"))

  Color.new(ColorSpace.find(:lrgb), [r, g, b], xyz_color.alpha)
end