Module: Abachrome::ColorMixins::ToXyz

Defined in:
lib/abachrome/color_mixins/to_xyz.rb

Instance Method Summary collapse

Instance Method Details

#to_xyzAbachrome::Color

Converts the current color to the XYZ color space.

If the color is already in XYZ, it returns the color unchanged. Otherwise, it uses the Converter to transform the color to XYZ.

Returns:



33
34
35
36
37
# File 'lib/abachrome/color_mixins/to_xyz.rb', line 33

def to_xyz
  return self if color_space.name == :xyz

  Converter.convert(self, :xyz)
end

#to_xyz!Abachrome::Color

Converts the color to the XYZ color space in place. This method transforms the current color into XYZ space, modifying the original object by updating its color space and coordinates if not already in XYZ.

color = Abachrome::Color.from_hex("#ff5500") color.to_xyz! # Color now uses XYZ color space

Returns:



49
50
51
52
53
54
55
56
# File 'lib/abachrome/color_mixins/to_xyz.rb', line 49

def to_xyz!
  unless color_space.name == :xyz
    xyz_color = to_xyz
    @color_space = xyz_color.color_space
    @coordinates = xyz_color.coordinates
  end
  self
end

#xAbcDecimal

Returns the X component from the XYZ color space.

The X component represents the mix of cone response curves chosen to be nonnegative and represents a scale of the CIE RGB red primary.

Returns:

  • (AbcDecimal)

    The X tristimulus value from the XYZ color space



64
65
66
# File 'lib/abachrome/color_mixins/to_xyz.rb', line 64

def x
  to_xyz.coordinates[0]
end

#xyz_arrayArray<AbcDecimal>

Returns an array representation of the color's coordinates in the XYZ color space.

in the XYZ color space in the order [X, Y, Z]

Returns:

  • (Array<AbcDecimal>)

    An array containing the coordinates of the color



99
100
101
# File 'lib/abachrome/color_mixins/to_xyz.rb', line 99

def xyz_array
  to_xyz.coordinates
end

#xyz_valuesArray<AbcDecimal>

Returns the XYZ color space coordinates for this color.

Returns:

  • (Array<AbcDecimal>)

    An array of XYZ coordinates [X, Y, Z] representing the color in XYZ color space



91
92
93
# File 'lib/abachrome/color_mixins/to_xyz.rb', line 91

def xyz_values
  to_xyz.coordinates
end

#yAbcDecimal

Returns the Y component from the XYZ color space.

The Y component represents luminance, which closely matches human perception of brightness. It corresponds to the CIE RGB green primary.

Returns:

  • (AbcDecimal)

    The Y tristimulus value from the XYZ color space



74
75
76
# File 'lib/abachrome/color_mixins/to_xyz.rb', line 74

def y
  to_xyz.coordinates[1]
end

#zAbcDecimal

Returns the Z component from the XYZ color space.

The Z component represents the CIE RGB blue primary and is roughly equal to blue stimulation.

Returns:

  • (AbcDecimal)

    The Z tristimulus value from the XYZ color space



84
85
86
# File 'lib/abachrome/color_mixins/to_xyz.rb', line 84

def z
  to_xyz.coordinates[2]
end