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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a3e2459586c1089713d950211118369334dd380
4
- data.tar.gz: 7febaebbff5ed6b25d45fff3b0a724d29ecf984a
3
+ metadata.gz: fc3e803bc5908b9cb25b57251e06591ad0a62e37
4
+ data.tar.gz: 59e3d925eaadaf333b1d343b1f5ed31a286fa2eb
5
5
  SHA512:
6
- metadata.gz: 786af0e7a8fb9d336f4be8aec8f6a873607ac98d150d5111576bf0f41691355f823f876dcd9b0e0793c44a1f49698c7f5b1a4315efe9019d2003b9cfa956a6e7
7
- data.tar.gz: b5cf8c04d802782c02c262b1eb278e3453955503d5c2d684e7306b57c390d48cbcda6fa44dd8ddf2ea7663d19b0c5c6c09f52d082b84e6ef671a847300e296cc
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({r: 255, g: 120, b: 60})
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({r: 80, g: 49, b: 220})
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
- r = xyz_channel(@rgb[:r] / 255.0)
13
- g = xyz_channel(@rgb[:g] / 255.0)
14
- b = xyz_channel(@rgb[:b] / 255.0)
15
-
16
- # sRGB D65 illuminant and 2 degrees observer values
17
- s = Matrix[[0.4124, 0.3576, 0.1805],
18
- [0.2126, 0.7152, 0.0722],
19
- [0.0193, 0.1192, 0.9505]]
20
-
21
- xyz = s * Matrix[[r], [g], [b]] * 100
22
- { x: xyz[0, 0], y: xyz[1, 0], z: xyz[2, 0] }
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
- xyz_to_lab(xyz)
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
@@ -1,3 +1,3 @@
1
1
  module ColorDecomposition
2
- VERSION = '0.0.1'.freeze
2
+ VERSION = '0.0.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: color_decomposition
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Bleyl