Module: Abachrome::ColorMixins::ToLrgb

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

Instance Method Summary collapse

Instance Method Details

#lblueAbcDecimal

Returns the linear blue channel value of this color after conversion to linear RGB color space.

This method converts the current color to the linear RGB color space and extracts the blue component (the third coordinate).

Returns:

  • (AbcDecimal)

    The linear blue component value, typically in the range [0, 1]



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

def lblue
  to_lrgb.coordinates[2]
end

#lgreenAbcDecimal

Retrieves the linear green (lgreen) coordinate from a color by converting it to linear RGB color space first. Linear RGB uses a different scale than standard sRGB, with values representing linear light energy rather than gamma-corrected values.

RGB representation

Returns:

  • (AbcDecimal)

    The linear green component value from the color’s linear



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

def lgreen
  to_lrgb.coordinates[1]
end

#lredAbcDecimal

Returns the linear red component value of the color.

This method accesses the first coordinate from the color in linear RGB space. Linear RGB values differ from standard RGB by using a non-gamma-corrected linear representation of luminance.

Returns:

  • (AbcDecimal)

    The linear red component value, typically in range [0, 1]



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

def lred
  to_lrgb.coordinates[0]
end

#lrgb_valuesArray<AbcDecimal>

Returns the coordinates of the color in the linear RGB color space.

the red, green, and blue components in linear RGB color space.

Returns:

  • (Array<AbcDecimal>)

    An array of three AbcDecimal values representing



92
93
94
# File 'lib/abachrome/color_mixins/to_lrgb.rb', line 92

def lrgb_values
  to_lrgb.coordinates
end

#rgb_arrayArray<Integer>

Returns an array of sRGB values as integers in the 0-255 range. This method converts the color to RGB, scales the values to the 0-255 range, rounds to integers, and ensures they are clamped within the valid range.

Returns:

  • (Array<Integer>)

    An array of three RGB integer values between 0-255



101
102
103
# File 'lib/abachrome/color_mixins/to_lrgb.rb', line 101

def rgb_array
  to_rgb.coordinates.map { |c| (c * 255).round.clamp(0, 255) }
end

#rgb_hexString

Returns a hexadecimal string representation of the color in RGB format.

are two-digit hexadecimal values for the red, green, and blue components respectively. color.rgb_hex # => “#1a2b3c”

Returns:

  • (String)

    A hexadecimal color code in the format ‘#RRGGBB’ where RR, GG, and BB



111
112
113
114
# File 'lib/abachrome/color_mixins/to_lrgb.rb', line 111

def rgb_hex
  r, g, b = rgb_array
  format("#%02x%02x%02x", r, g, b)
end

#to_lrgbAbachrome::Color

Converts this color to the Linear RGB (LRGB) color space. This method transforms the current color to the linear RGB color space, which uses a linear relationship between the stored numeric value and the actual light intensity. If the color is already in the LRGB space, it returns the current object without conversion.

or the original object if already in LRGB space

Returns:



34
35
36
37
38
# File 'lib/abachrome/color_mixins/to_lrgb.rb', line 34

def to_lrgb
  return self if color_space.name == :lrgb

  Converter.convert(self, :lrgb)
end

#to_lrgb!Abachrome::Color

Converts the current color to the linear RGB (LRGB) color space and updates the receiver’s state. If the color is already in LRGB space, this is a no-op.

Unlike #to_lrgb which returns a new color instance, this method modifies the current object by changing its color space and coordinates to the LRGB equivalent.

Returns:



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

def to_lrgb!
  unless color_space.name == :lrgb
    lrgb_color = to_lrgb
    @color_space = lrgb_color.color_space
    @coordinates = lrgb_color.coordinates
  end
  self
end