Module: Abachrome::ColorMixins::ToXyz
- Defined in:
- lib/abachrome/color_mixins/to_xyz.rb
Instance Method Summary collapse
-
#to_xyz ⇒ Abachrome::Color
Converts the current color to the XYZ color space.
-
#to_xyz! ⇒ Abachrome::Color
Converts the color to the XYZ color space in place.
-
#x ⇒ AbcDecimal
Returns the X component from the XYZ color space.
-
#xyz_array ⇒ Array<AbcDecimal>
Returns an array representation of the color's coordinates in the XYZ color space.
-
#xyz_values ⇒ Array<AbcDecimal>
Returns the XYZ color space coordinates for this color.
-
#y ⇒ AbcDecimal
Returns the Y component from the XYZ color space.
-
#z ⇒ AbcDecimal
Returns the Z component from the XYZ color space.
Instance Method Details
#to_xyz ⇒ Abachrome::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.
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
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 |
#x ⇒ AbcDecimal
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.
64 65 66 |
# File 'lib/abachrome/color_mixins/to_xyz.rb', line 64 def x to_xyz.coordinates[0] end |
#xyz_array ⇒ Array<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]
99 100 101 |
# File 'lib/abachrome/color_mixins/to_xyz.rb', line 99 def xyz_array to_xyz.coordinates end |
#xyz_values ⇒ Array<AbcDecimal>
Returns the XYZ color space coordinates for this color.
91 92 93 |
# File 'lib/abachrome/color_mixins/to_xyz.rb', line 91 def xyz_values to_xyz.coordinates end |
#y ⇒ AbcDecimal
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.
74 75 76 |
# File 'lib/abachrome/color_mixins/to_xyz.rb', line 74 def y to_xyz.coordinates[1] end |
#z ⇒ AbcDecimal
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.
84 85 86 |
# File 'lib/abachrome/color_mixins/to_xyz.rb', line 84 def z to_xyz.coordinates[2] end |