Class: ColorConverters::CielabConverter
Constant Summary
BaseConverter::IMPORT_DP, BaseConverter::OUTPUT_DP
Instance Attribute Summary
#original_value, #rgba
Class Method Summary
collapse
#alpha, #cielab, #cielch, #cmyk, factory, #hex, #hsb, #hsl, #hsv, inherited, #initialize, #name, #oklab, #oklch, #rgb, #xyz
Class Method Details
.bounds ⇒ Object
11
12
13
|
# File 'lib/color_converters/converters/cielab_converter.rb', line 11
def self.bounds
{ l: [0.0, 100.0], a: [-128.0, 127.0], b: [-128.0, 127.0] }
end
|
.cielab_to_xyz(colour_input) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/color_converters/converters/cielab_converter.rb', line 34
def self.cielab_to_xyz(colour_input)
l = colour_input[:l].to_d
a = colour_input[:a].to_d
b = colour_input[:b].to_d
yy = (l + 16.0.to_d) / 116.0.to_d
xx = (a / 500.0.to_d) + yy
zz = yy - (b / 200.0.to_d)
e = 216.0.to_d / 24_389.0.to_d
x, y, z = [xx, yy, zz].map do
if _1**3.to_d <= e
(3.0.to_d * (6.0.to_d / 29.0.to_d) * (6.0.to_d / 29.0.to_d) * (_1 - (4.0.to_d / 29.0.to_d)))
else
_1**3.to_d
end
end
x *= 95.047.to_d
y *= 100.0.to_d
z *= 108.883.to_d
[x, y, z]
end
|
.matches?(colour_input) ⇒ Boolean
5
6
7
8
9
|
# File 'lib/color_converters/converters/cielab_converter.rb', line 5
def self.matches?(colour_input)
return false unless colour_input.is_a?(Hash)
colour_input.keys - [:l, :a, :b, :space] == [] && colour_input[:space].to_s == 'cie'
end
|
.xyz_to_cielab(xyz_array) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/color_converters/converters/cielab_converter.rb', line 60
def self.xyz_to_cielab(xyz_array)
x, y, z = xyz_array.map(&:to_d)
wp_rel = [0.3127.to_d / 0.3290.to_d, 1.0.to_d, (1.0.to_d - 0.3127.to_d - 0.3290.to_d) / 0.3290.to_d].map { _1 * 100.0.to_d }
xr, yr, zr = wp_rel
rel = [x / xr, y / yr, z / zr]
e = 216.0.to_d / 24_389.0.to_d
k = 841.0.to_d / 108.0.to_d
xx, yy, zz = rel.map do
if _1 > e
_1**(1.0.to_d / 3.0.to_d)
else
(k * _1) + (4.0.to_d / 29.0.to_d)
end
end
l = ((116.0.to_d * yy) - 16.0.to_d)
a = (500.0.to_d * (xx - yy))
b = (200.0.to_d * (yy - zz))
[l, a, b]
end
|