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).
86 87 88 |
# File 'lib/abachrome/color_mixins/to_lrgb.rb', line 86 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
76 77 78 |
# File 'lib/abachrome/color_mixins/to_lrgb.rb', line 76 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.
65 66 67 |
# File 'lib/abachrome/color_mixins/to_lrgb.rb', line 65 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.
94 95 96 |
# File 'lib/abachrome/color_mixins/to_lrgb.rb', line 94 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.
103 104 105 |
# File 'lib/abachrome/color_mixins/to_lrgb.rb', line 103 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"
113 114 115 116 |
# File 'lib/abachrome/color_mixins/to_lrgb.rb', line 113 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
36 37 38 39 40 |
# File 'lib/abachrome/color_mixins/to_lrgb.rb', line 36 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.
49 50 51 52 53 54 55 56 |
# File 'lib/abachrome/color_mixins/to_lrgb.rb', line 49 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 |