Module: Abachrome::ColorMixins::ToLrgb
- Defined in:
- lib/abachrome/color_mixins/to_lrgb.rb
Instance Method Summary collapse
-
#lblue ⇒ AbcDecimal
Returns the linear blue channel value of this color after conversion to linear RGB color space.
-
#lgreen ⇒ AbcDecimal
Retrieves the linear green (lgreen) coordinate from a color by converting it to linear RGB color space first.
-
#lred ⇒ AbcDecimal
Returns the linear red component value of the color.
-
#lrgb_values ⇒ Array<AbcDecimal>
Returns the coordinates of the color in the linear RGB color space.
-
#rgb_array ⇒ Array<Integer>
Returns an array of sRGB values as integers in the 0-255 range.
-
#rgb_hex ⇒ String
Returns a hexadecimal string representation of the color in RGB format.
-
#to_lrgb ⇒ Abachrome::Color
Converts this color to the Linear RGB (LRGB) color space.
-
#to_lrgb! ⇒ Abachrome::Color
Converts the current color to the linear RGB (LRGB) color space and updates the receiver’s state.
Instance Method Details
#lblue ⇒ AbcDecimal
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).
84 85 86 |
# File 'lib/abachrome/color_mixins/to_lrgb.rb', line 84 def lblue to_lrgb.coordinates[2] end |
#lgreen ⇒ AbcDecimal
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
74 75 76 |
# File 'lib/abachrome/color_mixins/to_lrgb.rb', line 74 def lgreen to_lrgb.coordinates[1] end |
#lred ⇒ AbcDecimal
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.
63 64 65 |
# File 'lib/abachrome/color_mixins/to_lrgb.rb', line 63 def lred to_lrgb.coordinates[0] end |
#lrgb_values ⇒ Array<AbcDecimal>
Returns the coordinates of the color in the linear RGB color space.
the red, green, and blue components in linear RGB color space.
92 93 94 |
# File 'lib/abachrome/color_mixins/to_lrgb.rb', line 92 def lrgb_values to_lrgb.coordinates end |
#rgb_array ⇒ Array<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.
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_hex ⇒ String
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”
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_lrgb ⇒ Abachrome::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
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.
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 |