Class: Termin::ANSIColor::RGBColorMetrics::CIELab::CIELabTriple
- Inherits:
-
Struct
- Object
- Struct
- Termin::ANSIColor::RGBColorMetrics::CIELab::CIELabTriple
- Defined in:
- lib/termin/ansicolor/rgb_color_metrics.rb
Instance Attribute Summary collapse
-
#a ⇒ Object
Returns the value of attribute a.
-
#b ⇒ Object
Returns the value of attribute b.
-
#l ⇒ Object
Returns the value of attribute l.
Class Method Summary collapse
Methods included from Termin::ANSIColor::RGBColorMetricsHelpers::WeightedEuclideanDistance
#weighted_euclidean_distance_to
Instance Attribute Details
#a ⇒ Object
Returns the value of attribute a
123 124 125 |
# File 'lib/termin/ansicolor/rgb_color_metrics.rb', line 123 def a @a end |
#b ⇒ Object
Returns the value of attribute b
123 124 125 |
# File 'lib/termin/ansicolor/rgb_color_metrics.rb', line 123 def b @b end |
#l ⇒ Object
Returns the value of attribute l
123 124 125 |
# File 'lib/termin/ansicolor/rgb_color_metrics.rb', line 123 def l @l end |
Class Method Details
.from_rgb_triple(rgb_triple) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/termin/ansicolor/rgb_color_metrics.rb', line 127 def self.from_rgb_triple(rgb_triple) r, g, b = normalize_rgb_triple rgb_triple x = 0.436052025 * r + 0.385081593 * g + 0.143087414 * b y = 0.222491598 * r + 0.71688606 * g + 0.060621486 * b z = 0.013929122 * r + 0.097097002 * g + 0.71418547 * b xr = x / 0.964221 yr = y zr = z / 0.825211 eps = 216.0 / 24389 k = 24389.0 / 27 fx = xr > eps ? xr ** (1.0 / 3) : (k * xr + 16) / 116 fy = yr > eps ? yr ** (1.0 / 3) : (k * yr + 16) / 116 fz = zr > eps ? zr ** (1.0 / 3) : (k * zr + 16) / 116 l = 2.55 * ((116 * fy) - 16) a = 500 * (fx - fy) b = 200 * (fy - fz) new(l.round, a.round, b.round) end |