redgreenblue 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a61701a3122fc8e8b4f4352142862f7e3d63ed317cea1321cfe1bafd5d697a42
4
- data.tar.gz: 4a76d444f8080acb74656963654375e975eb91eb0068f6c4012e9233daf58bb7
3
+ metadata.gz: 0e6715019b7628fa8a5027295b3fb5e617f829d494eda1c4a0dad495adca6e44
4
+ data.tar.gz: 745987a3b640392f140bc6f7d3d18575f815a75a00d96162a0a9f3cdba64cc71
5
5
  SHA512:
6
- metadata.gz: 502bc188625f8df6fc3a55fa53454728602843ddd39f61c8199009f0e55c1fbd38a496d27c889c565b578ae85dd9cd051a457deec87979374d89006833f37707
7
- data.tar.gz: b811b0e1bc0bd366406be48eead2f11328c8304eee6eb34192bc92c40c31a4683dc5771a3944650749707df7e5a40e330d64c02b7f7818c0064dca5253ffe019
6
+ metadata.gz: 16538077413e35eeeae4d4da51bfd6eca7d7d3c9beba338df99742278762aa243dce8262fd9f95276154881dbdafe5ab26e4282ac2e485d82337f69a3bb61679
7
+ data.tar.gz: 5dabac01d2f52b4cd187f4248a4d3a520e76ff5c419ead409468bb01b14935b67b528375fca2ad338d79f8257c74489511609da792a88f52f4eb8de670377cd6
@@ -0,0 +1,55 @@
1
+ class RGB
2
+
3
+ # Returns the difference between this (reference) color and another color, according to the CIE 1994 delta E formula.
4
+ #
5
+ # By default uses parameters for use in graphic arts, and reference conditions.
6
+ # Parameters (k1, k2, kl, kc, kh) can be individually overriden for different applications and for variations in conditions.
7
+ #
8
+ # Based on:
9
+ # - http://www.brucelindbloom.com/Eqn_DeltaE_CIE94.html
10
+ # - https://archive.org/details/gov.law.cie.15.2004
11
+ # - https://en.wikipedia.org/wiki/Color_difference
12
+ def delta_e_cie_1994(another, k1: 0.045, k2: 0.015, kl: 1, kc: 1, kh: 1)
13
+
14
+ l , a , b = cie_lab(round: false)
15
+ l2, a2, b2 = another.cie_lab(round: false)
16
+
17
+ c = Math.hypot(a , b )
18
+ c2 = Math.hypot(a2, b2)
19
+
20
+ da = a - a2
21
+ db = b - b2
22
+ dc = c - c2
23
+
24
+ dh2 = (da ** 2) + (db ** 2) - (dc ** 2)
25
+ dl = l - l2
26
+
27
+ sl = 1
28
+ sc = 1 + k1 * c
29
+ sh = 1 + k2 * c
30
+
31
+ Math.sqrt(
32
+ ( (dl / ( kl*sl)) ** 2 ) +
33
+ ( (dc / ( kc*sc)) ** 2 ) +
34
+ ( dh2 / ((kh*sh) ** 2) )
35
+ ).round(6)
36
+
37
+ end
38
+
39
+ alias de94 delta_e_cie_1994
40
+
41
+ # Returns the difference between this (reference) color and another color, according to the CIE 1994 delta E formula.
42
+ #
43
+ # For use in graphic arts, under reference conditions.
44
+ def de94g(another)
45
+ delta_e_cie_1994(another)
46
+ end
47
+
48
+ # Returns the difference between this (reference) color and another color, according to the CIE 1994 delta E formula.
49
+ #
50
+ # For use with textiles, under reference conditions.
51
+ def de94t(another)
52
+ delta_e_cie_1994(another, k1: 0.048, k2: 0.014, kl: 2)
53
+ end
54
+
55
+ end
@@ -18,4 +18,32 @@ class RGB
18
18
  others.map { |c| [ c, de76(c) ] }.sort_by { |a| a[1] }
19
19
  end
20
20
 
21
+ # Matches this (reference) color to a set of colors using the CIE 1994 delta E formula.
22
+ #
23
+ # Returns the given set of colors with their difference from this color, sorted by difference (nearest color first).
24
+ #
25
+ # By default uses parameters for use in graphic arts, and reference conditions.
26
+ # Parameters (k1, k2, kl, kc, kh) can be individually overriden for different applications and for variations in conditions.
27
+ def match_de94(others, k1: 0.045, k2: 0.015, kl: 1, kc: 1, kh: 1)
28
+ others.map { |c| [ c, de94(c, k1: k1, k2: k2, kl: kl, kc: kc, kh: kh) ] }.sort_by { |a| a[1] }
29
+ end
30
+
31
+ # Matches this (reference) color to a set of colors using the CIE 1994 delta E formula.
32
+ #
33
+ # For use in graphic arts, under reference conditions.
34
+ #
35
+ # Returns the given set of colors with their difference from this color, sorted by difference (nearest color first).
36
+ def match_de94g(others)
37
+ others.map { |c| [ c, de94g(c) ] }.sort_by { |a| a[1] }
38
+ end
39
+
40
+ # Matches this (reference) color to a set of colors using the CIE 1994 delta E formula.
41
+ #
42
+ # For use with textiles, under reference conditions.
43
+ #
44
+ # Returns the given set of colors with their difference from this color, sorted by difference (nearest color first).
45
+ def match_de94t(others)
46
+ others.map { |c| [ c, de94t(c) ] }.sort_by { |a| a[1] }
47
+ end
48
+
21
49
  end
@@ -22,6 +22,8 @@ class RGB
22
22
  # @example Use
23
23
  # RGB.magenta.to_philips_hue_api_hsb_arguments
24
24
  # => {"on"=>true, "bri"=>254, "hue"=>54613, "sat"=>254}
25
+ # RGB.black.to_philips_hue_api_hsb_arguments
26
+ # => {"on"=>false}
25
27
  # @return [Hash] API arguments
26
28
  def to_philips_hue_api_hsb_arguments(black_off=true)
27
29
  my_hsb = hsb
@@ -1,7 +1,7 @@
1
1
  class RGB
2
2
 
3
3
  # redgreenblue version.
4
- VERSION = '0.14.0'
4
+ VERSION = '0.15.0'
5
5
 
6
6
  # Returns RGB::VERSION.
7
7
  def self.version
@@ -1,19 +1,25 @@
1
1
  class RGB
2
2
 
3
- # Prints details for the RGB object, using multiple lines.
4
- def view
5
- puts _inspect_view
3
+ # Prints a color swatch and details for the RGB object, using multiple lines.
4
+ #
5
+ # You can optionally supply a second color to be shown inside the swatch, for comparison.
6
+ def view(other=nil)
7
+ puts _inspect_view other
6
8
  end
7
9
 
8
10
  alias v view
9
11
 
10
12
  private
11
13
 
12
- def _inspect_view
14
+ def _inspect_view(other=nil)
13
15
  o = []
14
16
  o << 3.times.map { terminal_background + " \e[0m "}
15
17
  o << [ "#{_inspect_hex} ", '%-7.7s ' % color_space, ' ' ]
16
18
 
19
+ if other
20
+ o[0][1] = terminal_background + ' ' + other.terminal_background + ' ' + terminal_background + " \e[0m "
21
+ end
22
+
17
23
  o << components.map { |c| c.terminal_background + " \e[0m " }
18
24
  o << %w(R: G: B:)
19
25
  o << values.map { |v| '%1.5f ' % v }
@@ -106,4 +106,9 @@ class RGB
106
106
  round ? contrast_ratio.round(8) : contrast_ratio
107
107
  end
108
108
 
109
+ # Returns true if this is one of the 216 so-called "web safe" colors, otherwise false.
110
+ def web_safe?
111
+ ( values - [0.0, 0.2, 0.4, 0.6, 0.8, 1.0] ).empty?
112
+ end
113
+
109
114
  end
data/lib/redgreenblue.rb CHANGED
@@ -15,7 +15,7 @@ end
15
15
 
16
16
  gamma
17
17
 
18
- cie_1931 cie_1976
18
+ cie_1931 cie_1976 cie_1994
19
19
 
20
20
  name
21
21
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redgreenblue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - lllist.eu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-03 00:00:00.000000000 Z
11
+ date: 2021-11-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -23,6 +23,7 @@ files:
23
23
  - lib/redgreenblue/bgr24bit.rb
24
24
  - lib/redgreenblue/cie_1931.rb
25
25
  - lib/redgreenblue/cie_1976.rb
26
+ - lib/redgreenblue/cie_1994.rb
26
27
  - lib/redgreenblue/gamma.rb
27
28
  - lib/redgreenblue/gif.rb
28
29
  - lib/redgreenblue/gpl.rb
@@ -74,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
75
  - !ruby/object:Gem::Version
75
76
  version: '0'
76
77
  requirements: []
77
- rubygems_version: 3.1.4
78
+ rubygems_version: 3.2.22
78
79
  signing_key:
79
80
  specification_version: 4
80
81
  summary: A simple Ruby library for handling RGB colors.