color_decomposition 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/color_decomposition/color/color.rb +24 -24
- data/lib/color_decomposition/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc3e803bc5908b9cb25b57251e06591ad0a62e37
|
4
|
+
data.tar.gz: 59e3d925eaadaf333b1d343b1f5ed31a286fa2eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79860c07be844b1533ef40103479c5480423fe6ecfea658336340a2f7537c17b1141bc60076884b82124a99d785189296071d0a14415da648a80c7dda7702722
|
7
|
+
data.tar.gz: 109c3186fc6287c349db46ae18ed668d11ce86379a0b70befd7362e83813f12940abdb5917dc95acaf30a6de2b3fd14e60df50774a7b99920094e7e8f46b822b
|
data/README.md
CHANGED
@@ -73,11 +73,11 @@ require 'color_decomposition'
|
|
73
73
|
|
74
74
|
include ColorDecomposition
|
75
75
|
|
76
|
-
color1 = Color.new(
|
76
|
+
color1 = Color.new(r: 255, g: 120, b: 60)
|
77
77
|
puts color1.xyz # {:x=>48.77208180663368, :y=>35.01918603060906, :z=>8.46377233268254}
|
78
78
|
puts color1.lab # {:l=>65.76360001472788, :a=>47.86642591164642, :b=>55.61626679147632}
|
79
79
|
|
80
|
-
color2 = Color.new(
|
80
|
+
color2 = Color.new(r: 80, g: 49, b: 220)
|
81
81
|
puts Comparator.ciede2000(color1.lab, color2.lab) # 57.24131929494836
|
82
82
|
```
|
83
83
|
|
@@ -9,37 +9,37 @@ module ColorDecomposition
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def xyz
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
12
|
+
@xyz ||= begin
|
13
|
+
r = xyz_channel(@rgb[:r] / 255.0)
|
14
|
+
g = xyz_channel(@rgb[:g] / 255.0)
|
15
|
+
b = xyz_channel(@rgb[:b] / 255.0)
|
16
|
+
|
17
|
+
# sRGB D65 illuminant and 2 degrees observer values
|
18
|
+
s = Matrix[[0.4124, 0.3576, 0.1805],
|
19
|
+
[0.2126, 0.7152, 0.0722],
|
20
|
+
[0.0193, 0.1192, 0.9505]]
|
21
|
+
|
22
|
+
xyz = s * Matrix[[r], [g], [b]] * 100
|
23
|
+
{ x: xyz[0, 0], y: xyz[1, 0], z: xyz[2, 0] }
|
24
|
+
end
|
23
25
|
end
|
24
26
|
|
25
27
|
def lab
|
26
|
-
|
28
|
+
@lab ||= begin
|
29
|
+
# CIEXYZ white point values (D65)
|
30
|
+
x = lab_channel(xyz[:x] / 95.047)
|
31
|
+
y = lab_channel(xyz[:y] / 100.000)
|
32
|
+
z = lab_channel(xyz[:z] / 108.883)
|
33
|
+
|
34
|
+
l = 116 * y - 16
|
35
|
+
a = 500 * (x - y)
|
36
|
+
b = 200 * (y - z)
|
37
|
+
{ l: l.clamp(0, 100), a: a, b: b }
|
38
|
+
end
|
27
39
|
end
|
28
40
|
|
29
41
|
private
|
30
42
|
|
31
|
-
def xyz_to_lab(xyz)
|
32
|
-
# CIEXYZ white point values (D65)
|
33
|
-
x = lab_channel(xyz[:x] / 95.047)
|
34
|
-
y = lab_channel(xyz[:y] / 100.000)
|
35
|
-
z = lab_channel(xyz[:z] / 108.883)
|
36
|
-
|
37
|
-
l = 116 * y - 16
|
38
|
-
a = 500 * (x - y)
|
39
|
-
b = 200 * (y - z)
|
40
|
-
{ l: l.clamp(0, 100), a: a, b: b }
|
41
|
-
end
|
42
|
-
|
43
43
|
def xyz_channel(color)
|
44
44
|
if color > 0.04045
|
45
45
|
((color + 0.055) / 1.055)**2.4
|