Module: Abachrome::ColorMixins::ToOklab

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

Instance Method Summary collapse

Instance Method Details

#aAbcDecimal

Returns the 'a' component from the OKLAB color space (green-red axis).

The 'a' component in OKLAB represents the position on the green-red axis, with negative values being more green and positive values being more red.

Returns:

  • (AbcDecimal)

    The 'a' component value from the OKLAB color space.

See Also:



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

def a
  to_oklab.coordinates[1]
end

#bAbcDecimal

Returns the B value of the color in OKLAB color space.

This method first converts the color to OKLAB color space if needed, then extracts the B component (blue-yellow axis), which is the third coordinate in the OKLAB model.

Returns:

  • (AbcDecimal)

    The B component value in OKLAB color space



95
96
97
# File 'lib/abachrome/color_mixins/to_oklab.rb', line 95

def b
  to_oklab.coordinates[2]
end

#lAbcDecimal

Returns the L (Lightness) component from the OKLAB color space.

The L value represents perceptual lightness in the OKLAB color space, typically ranging from 0 (black) to 1 (white).

Returns:

  • (AbcDecimal)

    The L (Lightness) component from the OKLAB color space



73
74
75
# File 'lib/abachrome/color_mixins/to_oklab.rb', line 73

def l
  to_oklab.coordinates[0]
end

#lightnessAbcDecimal

Returns the lightness component (L) of the color in the OKLAB color space. The lightness value ranges from 0 (black) to 1 (white) and represents the perceived lightness of the color.

Returns:

  • (AbcDecimal)

    The lightness (L) value from the OKLAB color space



63
64
65
# File 'lib/abachrome/color_mixins/to_oklab.rb', line 63

def lightness
  to_oklab.coordinates[0]
end

#oklab_arrayArray<AbcDecimal>

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

in the OKLAB color space in the order [L, a, b]

Returns:

  • (Array<AbcDecimal>)

    An array containing the coordinates of the color



110
111
112
# File 'lib/abachrome/color_mixins/to_oklab.rb', line 110

def oklab_array
  to_oklab.coordinates
end

#oklab_valuesArray

Returns the OKLAB color space coordinates for this color.

Returns:

  • (Array)

    An array of OKLAB coordinates [L, a, b] representing the color in OKLAB color space



102
103
104
# File 'lib/abachrome/color_mixins/to_oklab.rb', line 102

def oklab_values
  to_oklab.coordinates
end

#to_oklabAbachrome::Color

Converts the current color to the OKLAB color space.

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

Returns:



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

def to_oklab
  return self if color_space.name == :oklab

  Converter.convert(self, :oklab)
end

#to_oklab!Abachrome::Color

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

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

Returns:



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

def to_oklab!
  unless color_space.name == :oklab
    oklab_color = to_oklab
    @color_space = oklab_color.color_space
    @coordinates = oklab_color.coordinates
  end
  self
end