Class: ColorDiff::Color::Xyz
- Inherits:
-
Object
- Object
- ColorDiff::Color::Xyz
- Defined in:
- lib/color_diff/color/xyz.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
-
#z ⇒ Object
readonly
Returns the value of attribute z.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(x = 0, y = 0, z = 0) ⇒ Xyz
constructor
A new instance of Xyz.
- #to_lab ⇒ Object
Constructor Details
#initialize(x = 0, y = 0, z = 0) ⇒ Xyz
6 7 8 9 10 |
# File 'lib/color_diff/color/xyz.rb', line 6 def initialize(x = 0, y = 0, z = 0) @x = x @y = y @z = z end |
Instance Attribute Details
#x ⇒ Object (readonly)
Returns the value of attribute x.
4 5 6 |
# File 'lib/color_diff/color/xyz.rb', line 4 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
4 5 6 |
# File 'lib/color_diff/color/xyz.rb', line 4 def y @y end |
#z ⇒ Object (readonly)
Returns the value of attribute z.
4 5 6 |
# File 'lib/color_diff/color/xyz.rb', line 4 def z @z end |
Class Method Details
.from_rgb(rgb) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/color_diff/color/xyz.rb', line 16 def self.from_rgb(rgb) r = normalize_rgb_component rgb.r g = normalize_rgb_component rgb.g b = normalize_rgb_component rgb.b x = r * 0.4124 + g * 0.3576 + b * 0.1805 y = r * 0.2126 + g * 0.7152 + b * 0.0722 z = r * 0.0193 + g * 0.1192 + b * 0.9505 new(x, y, z) end |
.normalize_rgb_component(c) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/color_diff/color/xyz.rb', line 28 def self.normalize_rgb_component(c) c = c / 255.0 if c > 0.04045 c = ((c + 0.055) / 1.055) ** 2.4 else c = c / 12.92 end c * 100 end |
Instance Method Details
#to_lab ⇒ Object
12 13 14 |
# File 'lib/color_diff/color/xyz.rb', line 12 def to_lab Lab.from_xyz(self) end |