Class: Color::XYZ
- Inherits:
-
Base
show all
- Defined in:
- lib/quadtone/color/xyz.rb
Instance Attribute Summary
Attributes inherited from Base
#components
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#<=>, average, colorspace_name, #eql?, from_cgats, #hash, #initialize, num_components, #to_s, #to_str
Methods included from Math
#deg2rad, #rad2deg
Constructor Details
This class inherits a constructor from Color::Base
Class Method Details
.cgats_fields ⇒ Object
14
15
16
|
# File 'lib/quadtone/color/xyz.rb', line 14
def self.cgats_fields
%w{XYZ_X XYZ_Y XYZ_Z}
end
|
.component_names ⇒ Object
10
11
12
|
# File 'lib/quadtone/color/xyz.rb', line 10
def self.component_names
[:x, :y, :z]
end
|
.standard_reference ⇒ Object
Observer= 2°, Illuminant= D65
6
7
8
|
# File 'lib/quadtone/color/xyz.rb', line 6
def self.standard_reference
@@reference ||= new([95.047, 100.000, 108.883])
end
|
Instance Method Details
#to_cgats ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/quadtone/color/xyz.rb', line 70
def to_cgats
{
'XYZ_X' => x,
'XYZ_Y' => y,
'XYZ_Z' => z,
}
end
|
#to_lab ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/quadtone/color/xyz.rb', line 30
def to_lab
ref = self.class.standard_reference
x = self.x / ref.x
y = self.y / ref.y
z = self.z / ref.z
x, y, z = [x, y, z].map do |n|
if n > 0.008856
n ** (1.0 / 3)
else
(7.787 * n) + (16 / 116)
end
end
l = (116 * y) - 16
a = 500 * (x - y)
b = 200 * (y - z)
Color::Lab.new([l, a, b])
end
|
#to_rgb ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/quadtone/color/xyz.rb', line 54
def to_rgb
rgb = [
(x * 3.2406) + (y * -1.5372) + (z * -0.4986),
(x * -0.9689) + (y * 1.8758) + (z * 0.0415),
(x * 0.0557) + (y * -0.2040) + (z * 1.0570),
]
rgb = rgb.map do |n|
if n > 0.0031308
1.055 * (n ** (1 / 2.4)) - 0.055
else
12.92 * rgb[0]
end
end
Color::RGB.new(rgb)
end
|
#x ⇒ Object
18
19
20
|
# File 'lib/quadtone/color/xyz.rb', line 18
def x
@components[0]
end
|
#y ⇒ Object
22
23
24
|
# File 'lib/quadtone/color/xyz.rb', line 22
def y
@components[1]
end
|
#z ⇒ Object
26
27
28
|
# File 'lib/quadtone/color/xyz.rb', line 26
def z
@components[2]
end
|