redgreenblue 0.18.0 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redgreenblue/base.rb +69 -70
- data/lib/redgreenblue/version.rb +1 -1
- data/lib/redgreenblue/yuv.rb +24 -0
- data/lib/redgreenblue.rb +32 -15
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8ae59f94eaf3e3cfb8fd8610b95d8f14cc05f9902e565b0cc587ad03e560bc1
|
4
|
+
data.tar.gz: f34de8f1025a07deb03c6de996f2875cc3d72212151432dcbb811fbfe5093fd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eece5011d8efd21b6fd22eea58de73b2cb070f34093085049b61c847c8c88f462e4b79465222060bee5398cd5c7c5c80a9d3fb682c68dacaba017c8e6ca1a47c
|
7
|
+
data.tar.gz: 54eac4f2defd4841e5057c91308e0479ccb03a29d0645b9e0a6603d3ec479cdd96ac2369496d401d77a10dedb816d93f0cb6464edc95e6a76a2228535971ef29
|
data/lib/redgreenblue/base.rb
CHANGED
@@ -1,90 +1,89 @@
|
|
1
|
-
|
1
|
+
module RGB
|
2
2
|
|
3
|
-
|
4
|
-
self.values = a.any? ? a : [ 0.5, 0.5, 0.5 ]
|
5
|
-
end
|
3
|
+
class Color
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def color_space
|
11
|
-
'sRGB'
|
12
|
-
end
|
5
|
+
def initialize(*a)
|
6
|
+
self.values = a.any? ? a : [ 0.5, 0.5, 0.5 ]
|
7
|
+
end
|
13
8
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
# Returns the color space.
|
10
|
+
#
|
11
|
+
# Currently always 'sRGB'.
|
12
|
+
def color_space
|
13
|
+
'sRGB'
|
14
|
+
end
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
# Returns the red component as a value between 0 and 1.
|
17
|
+
def red
|
18
|
+
@red
|
19
|
+
end
|
23
20
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
# Returns the green component as a value between 0 and 1.
|
22
|
+
def green
|
23
|
+
@green
|
24
|
+
end
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
@red = limit(value)
|
34
|
-
end
|
26
|
+
# Returns the blue component as a value between 0 and 1.
|
27
|
+
def blue
|
28
|
+
@blue
|
29
|
+
end
|
35
30
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
31
|
+
# Sets the red component to a value between 0 and 1.
|
32
|
+
#
|
33
|
+
# Values outside the range 0..1 will be clipped.
|
34
|
+
def red=(value)
|
35
|
+
@red = limit(value)
|
36
|
+
end
|
42
37
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
38
|
+
# Sets the green component to a value between 0 and 1.
|
39
|
+
#
|
40
|
+
# Values outside the range 0..1 will be clipped.
|
41
|
+
def green=(value)
|
42
|
+
@green = limit(value)
|
43
|
+
end
|
49
44
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
45
|
+
# Sets the blue component to a value between 0 and 1.
|
46
|
+
#
|
47
|
+
# Values outside the range 0..1 will be clipped.
|
48
|
+
def blue=(value)
|
49
|
+
@blue = limit(value)
|
50
|
+
end
|
54
51
|
|
55
|
-
|
52
|
+
# Returns the red, green, and blue components as three values between 0 and 1.
|
53
|
+
def values
|
54
|
+
[ red, green, blue ]
|
55
|
+
end
|
56
56
|
|
57
|
-
|
58
|
-
#
|
59
|
-
# Values outside the range 0..1 will be clipped.
|
60
|
-
def values=(*a)
|
61
|
-
self.red, self.green, self.blue = a.flatten
|
62
|
-
end
|
57
|
+
alias to_a values
|
63
58
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
59
|
+
# Sets the red, green, and blue components using three values between 0 and 1.
|
60
|
+
#
|
61
|
+
# Values outside the range 0..1 will be clipped.
|
62
|
+
def values=(*a)
|
63
|
+
self.red, self.green, self.blue = a.flatten
|
64
|
+
end
|
68
65
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|k,v| [-v,[:red, :green, :blue].index(k)]
|
74
|
-
}.to_h
|
75
|
-
end
|
66
|
+
# Returns true if this object and another object represent exactly the same color. Otherwise returns false.
|
67
|
+
def ==(other)
|
68
|
+
( self.class == other.class ) && ( self.values == other.values )
|
69
|
+
end
|
76
70
|
|
77
|
-
|
71
|
+
# Returns a sorted hash of 3 key/value pairs for red, green, and blue,
|
72
|
+
# sorted in order of decreasing value.
|
73
|
+
def to_h
|
74
|
+
([:red, :green, :blue].zip values).sort_by {
|
75
|
+
|k,v| [-v,[:red, :green, :blue].index(k)]
|
76
|
+
}.to_h
|
77
|
+
end
|
78
78
|
|
79
|
-
|
80
|
-
def limit(n)
|
81
|
-
n <= 0 ? 0.0 : n >= 1 ? 1.0 : n
|
82
|
-
end
|
79
|
+
private
|
83
80
|
|
84
|
-
|
81
|
+
# limits to range 0..1
|
82
|
+
def limit(n)
|
83
|
+
n <= 0 ? 0.0 : n >= 1 ? 1.0 : n
|
84
|
+
end
|
85
85
|
|
86
|
-
|
87
|
-
module RGB
|
86
|
+
end
|
88
87
|
|
89
88
|
class << self
|
90
89
|
|
data/lib/redgreenblue/version.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'redgreenblue/base'
|
2
|
+
|
3
|
+
class RGB::Color
|
4
|
+
|
5
|
+
# Returns the color's YUV values.
|
6
|
+
#
|
7
|
+
# Based on:
|
8
|
+
# - http://www.martinreddy.net/gfx/faqs/colorconv.faq (section 6.1)
|
9
|
+
# - https://en.wikipedia.org/wiki/Y%E2%80%B2UV
|
10
|
+
def yuv(round: true)
|
11
|
+
[
|
12
|
+
red * 0.299 + green * 0.587 + blue * 0.114,
|
13
|
+
red * -0.147 + green * -0.289 + blue * 0.436,
|
14
|
+
red * 0.615 + green * -0.515 + blue * -0.100
|
15
|
+
].map { |v| round ? v.round(6) : v }
|
16
|
+
|
17
|
+
# Wikipedia (2024-Aug-7)
|
18
|
+
# suggests slightly different factors for U and V:
|
19
|
+
#
|
20
|
+
# U = red * -0.14713 + green * -0.28886 + blue * 0.436
|
21
|
+
# V = red * 0.615 + green * -0.51499 + blue * -0.10001
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/redgreenblue.rb
CHANGED
@@ -20,30 +20,47 @@ module RGB
|
|
20
20
|
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
require 'redgreenblue/version'
|
24
24
|
|
25
|
-
|
25
|
+
require 'redgreenblue/base'
|
26
26
|
|
27
|
-
|
27
|
+
require 'redgreenblue/24bit'
|
28
|
+
require 'redgreenblue/48bit'
|
29
|
+
require 'redgreenblue/hex'
|
30
|
+
require 'redgreenblue/int'
|
28
31
|
|
29
|
-
|
32
|
+
require 'redgreenblue/hsl'
|
33
|
+
require 'redgreenblue/hsv'
|
34
|
+
require 'redgreenblue/hsb'
|
30
35
|
|
31
|
-
|
36
|
+
require 'redgreenblue/ostwald'
|
37
|
+
require 'redgreenblue/hwb'
|
32
38
|
|
33
|
-
|
39
|
+
require 'redgreenblue/gamma'
|
34
40
|
|
35
|
-
|
41
|
+
require 'redgreenblue/cie_1931'
|
42
|
+
require 'redgreenblue/cie_1976'
|
43
|
+
require 'redgreenblue/cie_1994'
|
36
44
|
|
37
|
-
|
45
|
+
require 'redgreenblue/name'
|
38
46
|
|
39
|
-
|
47
|
+
require 'redgreenblue/inspect'
|
48
|
+
require 'redgreenblue/view'
|
49
|
+
require 'redgreenblue/lazy'
|
40
50
|
|
41
|
-
|
51
|
+
require 'redgreenblue/rgb565'
|
52
|
+
require 'redgreenblue/bgr24bit'
|
53
|
+
require 'redgreenblue/gif'
|
54
|
+
require 'redgreenblue/terminal'
|
55
|
+
require 'redgreenblue/web'
|
56
|
+
require 'redgreenblue/gpl'
|
57
|
+
require 'redgreenblue/mac'
|
42
58
|
|
43
|
-
|
59
|
+
require 'redgreenblue/yuv'
|
44
60
|
|
45
|
-
|
61
|
+
require 'redgreenblue/match'
|
62
|
+
require 'redgreenblue/mix'
|
63
|
+
require 'redgreenblue/misc'
|
64
|
+
require 'redgreenblue/random'
|
46
65
|
|
47
|
-
|
48
|
-
|
49
|
-
).each { |m| require "redgreenblue/#{m}" }
|
66
|
+
require 'redgreenblue/os'
|
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.
|
4
|
+
version: 0.19.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:
|
11
|
+
date: 2024-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- lib/redgreenblue/version.rb
|
54
54
|
- lib/redgreenblue/view.rb
|
55
55
|
- lib/redgreenblue/web.rb
|
56
|
+
- lib/redgreenblue/yuv.rb
|
56
57
|
homepage: https://github.com/lllisteu/redgreenblue
|
57
58
|
licenses:
|
58
59
|
- MIT
|