colourdistance 1.0.7 → 1.2.7

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
  SHA1:
3
- metadata.gz: a975c48f2d6a1dce74d9f8a0eeeb8643c1a26f31
4
- data.tar.gz: fdd1f5d5c9aca769fd809b47d9c28f39f978ab13
3
+ metadata.gz: 56d234d51aed6a067f2a4768fcf7d7d75a923a6b
4
+ data.tar.gz: ebf2c394fe639da436a5d7c48b24a6a624836a9c
5
5
  SHA512:
6
- metadata.gz: 3595ff36180543a429f72a9386e07ff13c67a0201e751d7eb25911f18282019fa0259bdc30b6988971b3014172313428c36975dc3394eb84339a75176514e80a
7
- data.tar.gz: cc04bc88a28ba4dfb792039059ea89ab4092cd2c0a79ccc2c4ed3474b5a17cfc9e9007819dc9a8be4f44595ab52a62b4ff3994e72c4886aa80457c7dd9fd0910
6
+ metadata.gz: c1a3f002932ab50ed0366e5212efe2239d2e162233d461585ba5f35841ff8ede3fbaf6d385c5aeb55525dd2755bd093834e769607a1fd50fc193b64309c9b753
7
+ data.tar.gz: 9845d5dfc51b00f5d9505fc41fb6dc1d372e03ff5bf1759a63143be597eddace43c38abba54f7d4911f51c144187ac7567ad46414b28b7fce3069e6b4fbc712d
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.email = ["theseventhorange@gmail.com"]
12
12
 
13
13
  spec.summary = "Measures the difference (as a distance between colors in lab space) between colours. Takes rgb input. Will add support for xyz and lab around version 1.0."
14
- spec.description = "Currently only contains three options (ciede 76, ciede94, and ciede2000), all weighted to (roughly) a [0,1] scale (actually possible to get slightly above 1). Will add more. All are my own implementations (although ciede2000 is based on a several dozen implementations found during research), and they may be wrong because of it. Thanks go out to Josh Clayton (https://robots.thoughtbot.com/get-your-c-on), for helping me to understand the structure I was attempting to acheive."
14
+ spec.description = "Currently contains four options (ciede 76, cmclc, ciede94, and ciede2000) (all here: https://en.wikipedia.org/wiki/Color_difference), all weighted so that the distance between rgb 0,0,0 and rgb 255,255,255 will be 1.000 (accurate to 4 decimal places). Will add more. All are my own implementations (although ciede2000 is based on several dozen implementations found during research), and they may be wrong because of it. If you see any problems, let me know. Thanks go out to Josh Clayton (https://robots.thoughtbot.com/get-your-c-on), for helping me to understand the structure I was attempting to acheive."
15
15
  spec.license = "MIT"
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
@@ -7,15 +7,13 @@
7
7
 
8
8
  void Init_colourdistance() {
9
9
  VALUE rb_mColourdistance = rb_define_module("Colourdistance");
10
- rb_define_singleton_method(rb_mColourdistance, "cie76", ciede2000, 2);
11
- rb_define_singleton_method(rb_mColourdistance, "cie94", ciede2000, 2);
10
+ rb_define_singleton_method(rb_mColourdistance, "cie76", cie76, 2);
11
+ rb_define_singleton_method(rb_mColourdistance, "cmclc", cmclc, 2);
12
+ rb_define_singleton_method(rb_mColourdistance, "cie94", cie94, 2);
12
13
  rb_define_singleton_method(rb_mColourdistance, "ciede2000", ciede2000, 2);
13
14
  }
14
15
 
15
16
  static VALUE cie76(const VALUE self, VALUE color1, VALUE color2) {
16
- double pi = 3.1415927;
17
- double e = 2.7182818;
18
- double conversion = pi/180.0;
19
17
  static double lab1[3];
20
18
  static double lab2[3];
21
19
 
@@ -39,10 +37,80 @@ static VALUE cie76(const VALUE self, VALUE color1, VALUE color2) {
39
37
  return DBL2NUM(val);
40
38
  }
41
39
 
42
- static VALUE cie94(const VALUE self, VALUE color1, VALUE color2) {
40
+ static VALUE cmclc(const VALUE self, VALUE color1, VALUE color2) {
43
41
  double pi = 3.1415927;
44
- double e = 2.7182818;
45
- double conversion = pi/180.0;
42
+ double kl = 2.0;
43
+ double k1 = 0.048;
44
+ double k2 = 0.014;
45
+
46
+ static double lab1[3];
47
+ static double lab2[3];
48
+
49
+ rgb_to_lab(color1, lab1);
50
+
51
+ double l1 = lab1[0];
52
+ double a1 = lab1[1];
53
+ double b1 = lab1[2];
54
+
55
+ rgb_to_lab(color2, lab2);
56
+ double l2 = lab2[0];
57
+ double a2 = lab2[1];
58
+ double b2 = lab2[2];
59
+
60
+ double ldiff = l1 - l2;
61
+ double adiff = a1 - a2;
62
+ double bdiff = b1 - b2;
63
+
64
+ double c1 = sqrt(a1*a1+b1*b1);
65
+ double c2 = sqrt(a2*a2+b2*b2);
66
+ double deltac = c1 - c2;
67
+
68
+ double cbar = (c1 + c2)/2.0;
69
+ double cbaradj = sqrt(pow(cbar,7)/(pow(cbar,7)+6103515625.0));
70
+
71
+ double a1prime = a1 + (a1/2.0) * (1.0-cbaradj);
72
+ double a2prime = a2 + (a2/2.0) * (1.0-cbaradj);
73
+
74
+ double h1;
75
+ double h2;
76
+ if(c1 == 0.0){
77
+ h1 = 0.0;
78
+ }else{
79
+ h1 = fmod(atan2(b1,a1prime)*180.0/pi,360.0);
80
+ }
81
+ if(c2 == 0.0){
82
+ h2 = 0.0;
83
+ }else{
84
+ h2 = fmod(atan2(b2,a2prime)*180.0/pi,360.0);
85
+ }
86
+
87
+ double deltah = sqrt(adiff*adiff+bdiff*bdiff-deltac*deltac);
88
+
89
+
90
+ double f = sqrt(pow(c1,4)/(pow(c1,4) + 1900.0));
91
+ double t;
92
+ if(164.0 <= h1 && h1 <= 345.0){
93
+ t = 0.56 + fabs(0.2*cos(h1+168.0));
94
+ }else{
95
+ t = 0.36 + fabs(0.4*cos(h1+35.0));
96
+ }
97
+
98
+ double sl = 0.511;
99
+ if(l1 >= 16.0){
100
+ sl = 0.040975 * l1 / (1.0 + 0.01765 * l1);
101
+ }
102
+ double sc = 0.0638 * c1 / (1.0 + 0.0131 * c1) + 0.638;
103
+ double sh = 1 + k2*c1;
104
+
105
+ double e1 = ldiff/sl;
106
+ double e2 = deltac / sc;
107
+ double e3 = deltah / sh;
108
+ double val = sqrt(e1*e1+e2*e2+e3*e3)/195.7;
109
+
110
+ return DBL2NUM(val);
111
+ }
112
+
113
+ static VALUE cie94(const VALUE self, VALUE color1, VALUE color2) {
46
114
  double kl = 2.0;
47
115
  double k1 = 0.048;
48
116
  double k2 = 0.014;
@@ -77,7 +145,7 @@ static VALUE cie94(const VALUE self, VALUE color1, VALUE color2) {
77
145
  double e1 = ldiff/kl;
78
146
  double e2 = deltac / (k1*sc);
79
147
  double e3 = deltah / (k2*sh);
80
- double val = sqrt(e1*e1+e2*e2+e3*e3)/100.0;
148
+ double val = sqrt(e1*e1+e2*e2+e3*e3)/50.0;
81
149
 
82
150
  return DBL2NUM(val);
83
151
  }
@@ -174,7 +242,6 @@ static VALUE ciede2000(const VALUE self, VALUE color1, VALUE color2) {
174
242
  return DBL2NUM(val);
175
243
  }
176
244
 
177
-
178
245
  void rgb_to_lab(VALUE color, double *lab) {
179
246
 
180
247
  double r = NUM2DBL(rb_hash_aref(color, rb_str_intern(rb_str_new2("r"))))/255.0;
@@ -1,7 +1,8 @@
1
1
  #ifndef __colourdistance_h__
2
2
  #define __colourdistance_h__
3
3
 
4
- static VALUE ciee76(VALUE,VALUE,VALUE);
4
+ static VALUE cie76(VALUE,VALUE,VALUE);
5
+ static VALUE cmclc(VALUE,VALUE,VALUE);
5
6
  static VALUE cie94(VALUE,VALUE,VALUE);
6
7
  static VALUE ciede2000(VALUE,VALUE,VALUE);
7
8
  void rgb_to_lab(VALUE, double *);
@@ -1,3 +1,3 @@
1
1
  module Colourdistance
2
- VERSION = "1.0.7"
2
+ VERSION = "1.2.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colourdistance
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Orange Seven
@@ -66,12 +66,14 @@ dependencies:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: Currently only contains three options (ciede 76, ciede94, and ciede2000),
70
- all weighted to (roughly) a [0,1] scale (actually possible to get slightly above
71
- 1). Will add more. All are my own implementations (although ciede2000 is based on
72
- a several dozen implementations found during research), and they may be wrong because
73
- of it. Thanks go out to Josh Clayton (https://robots.thoughtbot.com/get-your-c-on),
74
- for helping me to understand the structure I was attempting to acheive.
69
+ description: 'Currently contains four options (ciede 76, cmclc, ciede94, and ciede2000)
70
+ (all here: https://en.wikipedia.org/wiki/Color_difference), all weighted so that
71
+ the distance between rgb 0,0,0 and rgb 255,255,255 will be 1.000 (accurate to 4
72
+ decimal places). Will add more. All are my own implementations (although ciede2000
73
+ is based on several dozen implementations found during research), and they may be
74
+ wrong because of it. If you see any problems, let me know. Thanks go out to Josh
75
+ Clayton (https://robots.thoughtbot.com/get-your-c-on), for helping me to understand
76
+ the structure I was attempting to acheive.'
75
77
  email:
76
78
  - theseventhorange@gmail.com
77
79
  executables: []