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:



82
83
84
# File 'lib/abachrome/color_mixins/to_oklab.rb', line 82

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



93
94
95
# File 'lib/abachrome/color_mixins/to_oklab.rb', line 93

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



71
72
73
# File 'lib/abachrome/color_mixins/to_oklab.rb', line 71

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



61
62
63
# File 'lib/abachrome/color_mixins/to_oklab.rb', line 61

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



108
109
110
# File 'lib/abachrome/color_mixins/to_oklab.rb', line 108

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



100
101
102
# File 'lib/abachrome/color_mixins/to_oklab.rb', line 100

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:



31
32
33
34
35
# File 'lib/abachrome/color_mixins/to_oklab.rb', line 31

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:



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

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