Class: ColorDecomposition::Color
- Inherits:
-
Object
- Object
- ColorDecomposition::Color
- Defined in:
- lib/color_decomposition/color/color.rb
Instance Attribute Summary collapse
-
#rgb ⇒ Object
readonly
Returns the value of attribute rgb.
Instance Method Summary collapse
-
#initialize(rgb) ⇒ Color
constructor
A new instance of Color.
- #lab ⇒ Object
- #xyz ⇒ Object
Constructor Details
#initialize(rgb) ⇒ Color
Returns a new instance of Color.
7 8 9 |
# File 'lib/color_decomposition/color/color.rb', line 7 def initialize(rgb) @rgb = rgb end |
Instance Attribute Details
#rgb ⇒ Object (readonly)
Returns the value of attribute rgb.
5 6 7 |
# File 'lib/color_decomposition/color/color.rb', line 5 def rgb @rgb end |
Instance Method Details
#lab ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/color_decomposition/color/color.rb', line 27 def lab @lab ||= begin # CIEXYZ white point values (D65) x = lab_channel(xyz[:x] / 95.047) y = lab_channel(xyz[:y] / 100.000) z = lab_channel(xyz[:z] / 108.883) l = 116 * y - 16 a = 500 * (x - y) b = 200 * (y - z) { l: l.clamp(0, 100), a: a, b: b } end end |
#xyz ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/color_decomposition/color/color.rb', line 11 def xyz @xyz ||= begin r = xyz_channel(@rgb[:r] / 255.0) g = xyz_channel(@rgb[:g] / 255.0) b = xyz_channel(@rgb[:b] / 255.0) # sRGB D65 illuminant and 2 degrees observer values s = Matrix[[0.4124, 0.3576, 0.1805], [0.2126, 0.7152, 0.0722], [0.0193, 0.1192, 0.9505]] xyz = s * Matrix[[r], [g], [b]] * 100 { x: xyz[0, 0], y: xyz[1, 0], z: xyz[2, 0] } end end |