spectrum 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +93 -0
- data/Install.txt +18 -0
- data/Licence.txt +27 -0
- data/README.txt +35 -0
- data/lib/spectrum.rb +145 -0
- data/lib/spectrum/cmyk.rb +281 -0
- data/lib/spectrum/css.rb +28 -0
- data/lib/spectrum/grayscale.rb +212 -0
- data/lib/spectrum/hsl.rb +221 -0
- data/lib/spectrum/palette.rb +16 -0
- data/lib/spectrum/palette/adobecolor.rb +272 -0
- data/lib/spectrum/palette/gimp.rb +116 -0
- data/lib/spectrum/palette/monocontrast.rb +180 -0
- data/lib/spectrum/rgb-colors.rb +355 -0
- data/lib/spectrum/rgb.rb +453 -0
- data/lib/spectrum/rgb/metallic.rb +43 -0
- data/lib/spectrum/yiq.rb +84 -0
- data/test/test_adobecolor.rb +419 -0
- data/test/test_all.rb +23 -0
- data/test/test_cmyk.rb +128 -0
- data/test/test_color.rb +141 -0
- data/test/test_css.rb +29 -0
- data/test/test_gimp.rb +101 -0
- data/test/test_grayscale.rb +121 -0
- data/test/test_hsl.rb +153 -0
- data/test/test_monocontrast.rb +142 -0
- data/test/test_rgb.rb +344 -0
- data/test/test_yiq.rb +73 -0
- metadata +108 -0
data/test/test_all.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#--
|
3
|
+
# Color
|
4
|
+
# Colour management with Ruby
|
5
|
+
# http://rubyforge.org/projects/color
|
6
|
+
# Version 1.5.0
|
7
|
+
#
|
8
|
+
# Licensed under a MIT-style licence. See Licence.txt in the main
|
9
|
+
# distribution for full licensing information.
|
10
|
+
#
|
11
|
+
# Copyright (c) 2005 - 2010 Austin Ziegler and Matt Lyon
|
12
|
+
#++
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
|
15
|
+
|
16
|
+
$stderr.puts "Checking for test cases:"
|
17
|
+
|
18
|
+
Dir[File.join(File.dirname($0), 'test_*.rb')].each do |testcase|
|
19
|
+
next if File.basename(testcase) == File.basename(__FILE__)
|
20
|
+
$stderr.puts "\t#{testcase}"
|
21
|
+
load testcase
|
22
|
+
end
|
23
|
+
$stderr.puts " "
|
data/test/test_cmyk.rb
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#--
|
3
|
+
# Color
|
4
|
+
# Colour management with Ruby
|
5
|
+
# http://rubyforge.org/projects/color
|
6
|
+
# Version 1.5.0
|
7
|
+
#
|
8
|
+
# Licensed under a MIT-style licence. See Licence.txt in the main
|
9
|
+
# distribution for full licensing information.
|
10
|
+
#
|
11
|
+
# Copyright (c) 2005 - 2010 Austin Ziegler and Matt Lyon
|
12
|
+
#++
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
|
15
|
+
require 'test/unit'
|
16
|
+
require 'spectrum'
|
17
|
+
|
18
|
+
module TestColor
|
19
|
+
class TestCMYK < Test::Unit::TestCase
|
20
|
+
def setup
|
21
|
+
@cmyk = Spectrum::CMYK.new(10, 20, 30, 40)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_cyan
|
25
|
+
assert_in_delta(0.1, @cmyk.c, Spectrum::COLOR_TOLERANCE)
|
26
|
+
assert_in_delta(10, @cmyk.cyan, Spectrum::COLOR_TOLERANCE)
|
27
|
+
assert_nothing_raised { @cmyk.cyan = 20 }
|
28
|
+
assert_in_delta(0.2, @cmyk.c, Spectrum::COLOR_TOLERANCE)
|
29
|
+
assert_nothing_raised { @cmyk.c = 2.0 }
|
30
|
+
assert_in_delta(100, @cmyk.cyan, Spectrum::COLOR_TOLERANCE)
|
31
|
+
assert_nothing_raised { @cmyk.c = -1.0 }
|
32
|
+
assert_in_delta(0.0, @cmyk.c, Spectrum::COLOR_TOLERANCE)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_magenta
|
36
|
+
assert_in_delta(0.2, @cmyk.m, Spectrum::COLOR_TOLERANCE)
|
37
|
+
assert_in_delta(20, @cmyk.magenta, Spectrum::COLOR_TOLERANCE)
|
38
|
+
assert_nothing_raised { @cmyk.magenta = 30 }
|
39
|
+
assert_in_delta(0.3, @cmyk.m, Spectrum::COLOR_TOLERANCE)
|
40
|
+
assert_nothing_raised { @cmyk.m = 2.0 }
|
41
|
+
assert_in_delta(100, @cmyk.magenta, Spectrum::COLOR_TOLERANCE)
|
42
|
+
assert_nothing_raised { @cmyk.m = -1.0 }
|
43
|
+
assert_in_delta(0.0, @cmyk.m, Spectrum::COLOR_TOLERANCE)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_yellow
|
47
|
+
assert_in_delta(0.3, @cmyk.y, Spectrum::COLOR_TOLERANCE)
|
48
|
+
assert_in_delta(30, @cmyk.yellow, Spectrum::COLOR_TOLERANCE)
|
49
|
+
assert_nothing_raised { @cmyk.yellow = 20 }
|
50
|
+
assert_in_delta(0.2, @cmyk.y, Spectrum::COLOR_TOLERANCE)
|
51
|
+
assert_nothing_raised { @cmyk.y = 2.0 }
|
52
|
+
assert_in_delta(100, @cmyk.yellow, Spectrum::COLOR_TOLERANCE)
|
53
|
+
assert_nothing_raised { @cmyk.y = -1.0 }
|
54
|
+
assert_in_delta(0.0, @cmyk.y, Spectrum::COLOR_TOLERANCE)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_black
|
58
|
+
assert_in_delta(0.4, @cmyk.k, Spectrum::COLOR_TOLERANCE)
|
59
|
+
assert_in_delta(40, @cmyk.black, Spectrum::COLOR_TOLERANCE)
|
60
|
+
assert_nothing_raised { @cmyk.black = 20 }
|
61
|
+
assert_in_delta(0.2, @cmyk.k, Spectrum::COLOR_TOLERANCE)
|
62
|
+
assert_nothing_raised { @cmyk.k = 2.0 }
|
63
|
+
assert_in_delta(100, @cmyk.black, Spectrum::COLOR_TOLERANCE)
|
64
|
+
assert_nothing_raised { @cmyk.k = -1.0 }
|
65
|
+
assert_in_delta(0.0, @cmyk.k, Spectrum::COLOR_TOLERANCE)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_pdf
|
69
|
+
assert_equal("0.100 0.200 0.300 0.400 k", @cmyk.pdf_fill)
|
70
|
+
assert_equal("0.100 0.200 0.300 0.400 K", @cmyk.pdf_stroke)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_to_cmyk
|
74
|
+
assert(@cmyk.to_cmyk == @cmyk)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_to_grayscale
|
78
|
+
gs = nil
|
79
|
+
assert_nothing_raised { gs = @cmyk.to_grayscale }
|
80
|
+
assert_kind_of(Spectrum::GrayScale, gs)
|
81
|
+
assert_in_delta(0.4185, gs.g, Spectrum::COLOR_TOLERANCE)
|
82
|
+
assert_kind_of(Spectrum::GreyScale, @cmyk.to_greyscale)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_to_hsl
|
86
|
+
hsl = nil
|
87
|
+
assert_nothing_raised { hsl = @cmyk.to_hsl }
|
88
|
+
assert_kind_of(Spectrum::HSL, hsl)
|
89
|
+
assert_in_delta(0.48, hsl.l, Spectrum::COLOR_TOLERANCE)
|
90
|
+
assert_in_delta(0.125, hsl.s, Spectrum::COLOR_TOLERANCE)
|
91
|
+
assert_in_delta(0.08333, hsl.h, Spectrum::COLOR_TOLERANCE)
|
92
|
+
assert_equal("hsl(30.00, 12.50%, 48.00%)", @cmyk.css_hsl)
|
93
|
+
assert_equal("hsla(30.00, 12.50%, 48.00%, 1.00)", @cmyk.css_hsla)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_to_rgb
|
97
|
+
rgb = nil
|
98
|
+
assert_nothing_raised { rgb = @cmyk.to_rgb(true) }
|
99
|
+
assert_kind_of(Spectrum::RGB, rgb)
|
100
|
+
assert_in_delta(0.5, rgb.r, Spectrum::COLOR_TOLERANCE)
|
101
|
+
assert_in_delta(0.4, rgb.g, Spectrum::COLOR_TOLERANCE)
|
102
|
+
assert_in_delta(0.3, rgb.b, Spectrum::COLOR_TOLERANCE)
|
103
|
+
|
104
|
+
assert_nothing_raised { rgb = @cmyk.to_rgb }
|
105
|
+
assert_kind_of(Spectrum::RGB, rgb)
|
106
|
+
assert_in_delta(0.54, rgb.r, Spectrum::COLOR_TOLERANCE)
|
107
|
+
assert_in_delta(0.48, rgb.g, Spectrum::COLOR_TOLERANCE)
|
108
|
+
assert_in_delta(0.42, rgb.b, Spectrum::COLOR_TOLERANCE)
|
109
|
+
|
110
|
+
assert_equal("#8a7a6b", @cmyk.html)
|
111
|
+
assert_equal("rgb(54.00%, 48.00%, 42.00%)", @cmyk.css_rgb)
|
112
|
+
assert_equal("rgba(54.00%, 48.00%, 42.00%, 1.00)", @cmyk.css_rgba)
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_inspect
|
116
|
+
assert_equal("CMYK [10.00%, 20.00%, 30.00%, 40.00%]", @cmyk.inspect)
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_to_yiq
|
120
|
+
yiq = nil
|
121
|
+
assert_nothing_raised { yiq = @cmyk.to_yiq }
|
122
|
+
assert_kind_of(Spectrum::YIQ, yiq)
|
123
|
+
assert_in_delta(0.4911, yiq.y, Spectrum::COLOR_TOLERANCE)
|
124
|
+
assert_in_delta(0.05502, yiq.i, Spectrum::COLOR_TOLERANCE)
|
125
|
+
assert_in_delta(0.0, yiq.q, Spectrum::COLOR_TOLERANCE)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
data/test/test_color.rb
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#--
|
3
|
+
# Color
|
4
|
+
# Colour management with Ruby
|
5
|
+
# http://rubyforge.org/projects/color
|
6
|
+
# Version 1.5.0
|
7
|
+
#
|
8
|
+
# Licensed under a MIT-style licence. See Licence.txt in the main
|
9
|
+
# distribution for full licensing information.
|
10
|
+
#
|
11
|
+
# Copyright (c) 2005 - 2010 Austin Ziegler and Matt Lyon
|
12
|
+
#++
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
|
15
|
+
require 'test/unit'
|
16
|
+
require 'spectrum'
|
17
|
+
require 'spectrum/css'
|
18
|
+
|
19
|
+
module TestColor
|
20
|
+
class TestColor < Test::Unit::TestCase
|
21
|
+
def setup
|
22
|
+
Kernel.module_eval do
|
23
|
+
alias old_warn warn
|
24
|
+
|
25
|
+
def warn(message)
|
26
|
+
$last_warn = message
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def teardown
|
32
|
+
Kernel.module_eval do
|
33
|
+
undef warn
|
34
|
+
alias warn old_warn
|
35
|
+
undef old_warn
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_const
|
40
|
+
$last_warn = nil
|
41
|
+
assert_equal(Spectrum::RGB::AliceBlue, Spectrum::AliceBlue)
|
42
|
+
assert_equal("Spectrum::AliceBlue has been deprecated. Use Spectrum::RGB::AliceBlue instead.", $last_warn)
|
43
|
+
|
44
|
+
$last_warn = nil # Do this twice to make sure it always happens...
|
45
|
+
assert(Spectrum::AliceBlue)
|
46
|
+
assert_equal("Spectrum::AliceBlue has been deprecated. Use Spectrum::RGB::AliceBlue instead.", $last_warn)
|
47
|
+
|
48
|
+
$last_warn = nil
|
49
|
+
assert_equal(Spectrum::COLOR_VERSION, Spectrum::VERSION)
|
50
|
+
assert_equal("Spectrum::VERSION has been deprecated. Use Spectrum::COLOR_VERSION instead.", $last_warn)
|
51
|
+
|
52
|
+
$last_warn = nil
|
53
|
+
assert_equal(Spectrum::COLOR_VERSION, Spectrum::COLOR_TOOLS_VERSION)
|
54
|
+
assert_equal("Spectrum::COLOR_TOOLS_VERSION has been deprecated. Use Spectrum::COLOR_VERSION instead.", $last_warn)
|
55
|
+
|
56
|
+
$last_warn = nil
|
57
|
+
assert(Spectrum::COLOR_VERSION)
|
58
|
+
assert_nil($last_warn)
|
59
|
+
assert(Spectrum::COLOR_EPSILON)
|
60
|
+
assert_nil($last_warn)
|
61
|
+
|
62
|
+
assert_raises(NameError) { assert(Spectrum::MISSING_VALUE) }
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_normalize
|
66
|
+
(1..10).each do |i|
|
67
|
+
assert_equal(0.0, Spectrum.normalize(-7 * i))
|
68
|
+
assert_equal(0.0, Spectrum.normalize(-7 / i))
|
69
|
+
assert_equal(0.0, Spectrum.normalize(0 - i))
|
70
|
+
assert_equal(1.0, Spectrum.normalize(255 + i))
|
71
|
+
assert_equal(1.0, Spectrum.normalize(256 * i))
|
72
|
+
assert_equal(1.0, Spectrum.normalize(65536 / i))
|
73
|
+
end
|
74
|
+
(0..255).each do |i|
|
75
|
+
assert_in_delta(i / 255.0, Spectrum.normalize(i / 255.0),
|
76
|
+
1e-2)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_normalize_range
|
81
|
+
assert_equal(0, Spectrum.normalize_8bit(-1))
|
82
|
+
assert_equal(0, Spectrum.normalize_8bit(0))
|
83
|
+
assert_equal(127, Spectrum.normalize_8bit(127))
|
84
|
+
assert_equal(172, Spectrum.normalize_8bit(172))
|
85
|
+
assert_equal(255, Spectrum.normalize_8bit(255))
|
86
|
+
assert_equal(255, Spectrum.normalize_8bit(256))
|
87
|
+
|
88
|
+
assert_equal(0, Spectrum.normalize_16bit(-1))
|
89
|
+
assert_equal(0, Spectrum.normalize_16bit(0))
|
90
|
+
assert_equal(127, Spectrum.normalize_16bit(127))
|
91
|
+
assert_equal(172, Spectrum.normalize_16bit(172))
|
92
|
+
assert_equal(255, Spectrum.normalize_16bit(255))
|
93
|
+
assert_equal(256, Spectrum.normalize_16bit(256))
|
94
|
+
assert_equal(65535, Spectrum.normalize_16bit(65535))
|
95
|
+
assert_equal(65535, Spectrum.normalize_16bit(66536))
|
96
|
+
|
97
|
+
assert_equal(-100, Spectrum.normalize_to_range(-101, -100..100))
|
98
|
+
assert_equal(-100, Spectrum.normalize_to_range(-100.5, -100..100))
|
99
|
+
assert_equal(-100, Spectrum.normalize_to_range(-100, -100..100))
|
100
|
+
assert_equal(-100, Spectrum.normalize_to_range(-100.0, -100..100))
|
101
|
+
assert_equal(-99.5, Spectrum.normalize_to_range(-99.5, -100..100))
|
102
|
+
assert_equal(-50, Spectrum.normalize_to_range(-50, -100..100))
|
103
|
+
assert_equal(-50.5, Spectrum.normalize_to_range(-50.5, -100..100))
|
104
|
+
assert_equal(0, Spectrum.normalize_to_range(0, -100..100))
|
105
|
+
assert_equal(50, Spectrum.normalize_to_range(50, -100..100))
|
106
|
+
assert_equal(50.5, Spectrum.normalize_to_range(50.5, -100..100))
|
107
|
+
assert_equal(99, Spectrum.normalize_to_range(99, -100..100))
|
108
|
+
assert_equal(99.5, Spectrum.normalize_to_range(99.5, -100..100))
|
109
|
+
assert_equal(100, Spectrum.normalize_to_range(100, -100..100))
|
110
|
+
assert_equal(100, Spectrum.normalize_to_range(100.0, -100..100))
|
111
|
+
assert_equal(100, Spectrum.normalize_to_range(100.5, -100..100))
|
112
|
+
assert_equal(100, Spectrum.normalize_to_range(101, -100..100))
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_new
|
116
|
+
$last_warn = nil
|
117
|
+
c = Spectrum.new("#fff")
|
118
|
+
assert_kind_of(Spectrum::HSL, c)
|
119
|
+
assert_equal(Spectrum::RGB::White.to_hsl, c)
|
120
|
+
assert_equal("Spectrum.new has been deprecated. Use Spectrum::RGB.new instead.", $last_warn)
|
121
|
+
|
122
|
+
$last_warn = nil
|
123
|
+
c = Spectrum.new([0, 0, 0])
|
124
|
+
assert_kind_of(Spectrum::HSL, c)
|
125
|
+
assert_equal(Spectrum::RGB::Black.to_hsl, c)
|
126
|
+
assert_equal("Spectrum.new has been deprecated. Use Spectrum::RGB.new instead.", $last_warn)
|
127
|
+
|
128
|
+
$last_warn = nil
|
129
|
+
c = Spectrum.new([10, 20, 30], :hsl)
|
130
|
+
assert_kind_of(Spectrum::HSL, c)
|
131
|
+
assert_equal(Spectrum::HSL.new(10, 20, 30), c)
|
132
|
+
assert_equal("Spectrum.new has been deprecated. Use Spectrum::HSL.new instead.", $last_warn)
|
133
|
+
|
134
|
+
$last_warn = nil
|
135
|
+
c = Spectrum.new([10, 20, 30, 40], :cmyk)
|
136
|
+
assert_kind_of(Spectrum::HSL, c)
|
137
|
+
assert_equal(Spectrum::CMYK.new(10, 20, 30, 40).to_hsl, c)
|
138
|
+
assert_equal("Spectrum.new has been deprecated. Use Spectrum::CMYK.new instead.", $last_warn)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
data/test/test_css.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#--
|
3
|
+
# Color
|
4
|
+
# Colour management with Ruby
|
5
|
+
# http://rubyforge.org/projects/color
|
6
|
+
# Version 1.5.0
|
7
|
+
#
|
8
|
+
# Licensed under a MIT-style licence. See Licence.txt in the main
|
9
|
+
# distribution for full licensing information.
|
10
|
+
#
|
11
|
+
# Copyright (c) 2005 - 2010 Austin Ziegler and Matt Lyon
|
12
|
+
#++
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
|
15
|
+
require 'test/unit'
|
16
|
+
require 'spectrum'
|
17
|
+
require 'spectrum/css'
|
18
|
+
|
19
|
+
module TestColor
|
20
|
+
class TestCSS < Test::Unit::TestCase
|
21
|
+
def test_index
|
22
|
+
assert_equal(Spectrum::RGB::AliceBlue, Spectrum::CSS[:aliceblue])
|
23
|
+
assert_equal(Spectrum::RGB::AliceBlue, Spectrum::CSS["AliceBlue"])
|
24
|
+
assert_equal(Spectrum::RGB::AliceBlue, Spectrum::CSS["aliceBlue"])
|
25
|
+
assert_equal(Spectrum::RGB::AliceBlue, Spectrum::CSS["aliceblue"])
|
26
|
+
assert_equal(Spectrum::RGB::AliceBlue, Spectrum::CSS[:AliceBlue])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/test/test_gimp.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#--
|
3
|
+
# Color
|
4
|
+
# Colour management with Ruby
|
5
|
+
# http://rubyforge.org/projects/color
|
6
|
+
# Version 1.5.0
|
7
|
+
#
|
8
|
+
# Licensed under a MIT-style licence. See Licence.txt in the main
|
9
|
+
# distribution for full licensing information.
|
10
|
+
#
|
11
|
+
# Copyright (c) 2005 - 2010 Austin Ziegler and Matt Lyon
|
12
|
+
#++
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
|
15
|
+
require 'test/unit'
|
16
|
+
require 'spectrum'
|
17
|
+
require 'spectrum/palette/gimp'
|
18
|
+
|
19
|
+
module TestColor
|
20
|
+
module TestPalette
|
21
|
+
class TestGimp < Test::Unit::TestCase
|
22
|
+
include Spectrum::Palette
|
23
|
+
|
24
|
+
GIMP_W3C = <<-EOS
|
25
|
+
GIMP Palette
|
26
|
+
Name: W3C Named Colors
|
27
|
+
Columns: 2
|
28
|
+
#
|
29
|
+
# ColorZilla W3C Named Colors
|
30
|
+
#
|
31
|
+
255 255 255 White
|
32
|
+
255 255 0 Yclow
|
33
|
+
255 0 255 Fuchsia
|
34
|
+
255 0 0 Red
|
35
|
+
192 192 192 Silver
|
36
|
+
128 128 128 Gray
|
37
|
+
128 128 0 Olive
|
38
|
+
128 0 128 Purple
|
39
|
+
128 0 0 Maroon
|
40
|
+
0 255 255 Aqua
|
41
|
+
0 255 0 Lime
|
42
|
+
0 128 128 Teal
|
43
|
+
0 128 0 Green
|
44
|
+
0 0 255 Blue
|
45
|
+
0 0 128 Navy
|
46
|
+
0 0 0 Black
|
47
|
+
EOS
|
48
|
+
|
49
|
+
def setup
|
50
|
+
@filename = "test#{Process.pid}.gimp"
|
51
|
+
end
|
52
|
+
|
53
|
+
def teardown
|
54
|
+
require 'fileutils'
|
55
|
+
FileUtils.rm_f @filename if File.exist? @filename
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_each
|
59
|
+
@gimp = Gimp.new(GIMP_W3C)
|
60
|
+
assert_equal(16, @gimp.instance_variable_get(:@colors).size)
|
61
|
+
@gimp.each { |c| assert_kind_of(Spectrum::RGB, c) }
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_each_name
|
65
|
+
@gimp = Gimp.new(GIMP_W3C)
|
66
|
+
assert_equal(16, @gimp.instance_variable_get(:@names).size)
|
67
|
+
|
68
|
+
@gimp.each_name { |color_name, color_set|
|
69
|
+
assert_kind_of(Array, color_set)
|
70
|
+
color_set.each { |c|
|
71
|
+
assert_kind_of(Spectrum::RGB, c)
|
72
|
+
}
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_index
|
77
|
+
assert_nothing_raised do
|
78
|
+
File.open(@filename, "wb") do |f|
|
79
|
+
f.write GIMP_W3C
|
80
|
+
end
|
81
|
+
end
|
82
|
+
assert_nothing_raised { @gimp = Gimp.from_file(@filename) }
|
83
|
+
assert_equal(Spectrum::RGB::White, @gimp[0])
|
84
|
+
assert_equal(Spectrum::RGB::White, @gimp["White"][0])
|
85
|
+
assert_equal([Spectrum::RGB::White, Spectrum::RGB::Black],
|
86
|
+
@gimp.values_at(0, -1))
|
87
|
+
assert_equal(16, @gimp.size)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_valid_eh
|
91
|
+
@gimp = Gimp.new(GIMP_W3C)
|
92
|
+
assert(@gimp.valid?)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_name
|
96
|
+
@gimp = Gimp.new(GIMP_W3C)
|
97
|
+
assert_equal("W3C Named Colors", @gimp.name)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#--
|
3
|
+
# Color
|
4
|
+
# Colour management with Ruby
|
5
|
+
# http://rubyforge.org/projects/color
|
6
|
+
# Version 1.5.0
|
7
|
+
#
|
8
|
+
# Licensed under a MIT-style licence. See Licence.txt in the main
|
9
|
+
# distribution for full licensing information.
|
10
|
+
#
|
11
|
+
# Copyright (c) 2005 - 2010 Austin Ziegler and Matt Lyon
|
12
|
+
#++
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
|
15
|
+
require 'test/unit'
|
16
|
+
require 'spectrum'
|
17
|
+
|
18
|
+
module TestColor
|
19
|
+
class TestGrayScale < Test::Unit::TestCase
|
20
|
+
def setup
|
21
|
+
@gs = Spectrum::GrayScale.from_percent(33)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_brightness
|
25
|
+
assert_in_delta(0.33, @gs.brightness, Spectrum::COLOR_TOLERANCE)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_darken_by
|
29
|
+
assert_in_delta(29.7, @gs.darken_by(10).gray, Spectrum::COLOR_TOLERANCE)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_g
|
33
|
+
assert_in_delta(0.33, @gs.g, Spectrum::COLOR_TOLERANCE)
|
34
|
+
assert_in_delta(33, @gs.grey, Spectrum::COLOR_TOLERANCE)
|
35
|
+
assert_nothing_raised { @gs.gray = 40 }
|
36
|
+
assert_in_delta(0.4, @gs.g, Spectrum::COLOR_TOLERANCE)
|
37
|
+
assert_nothing_raised { @gs.g = 2.0 }
|
38
|
+
assert_in_delta(100, @gs.gray, Spectrum::COLOR_TOLERANCE)
|
39
|
+
assert_nothing_raised { @gs.grey = -2.0 }
|
40
|
+
assert_in_delta(0.0, @gs.g, Spectrum::COLOR_TOLERANCE)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_html_css
|
44
|
+
assert_equal("#545454", @gs.html)
|
45
|
+
assert_equal("rgb(33.00%, 33.00%, 33.00%)", @gs.css_rgb)
|
46
|
+
assert_equal("rgba(33.00%, 33.00%, 33.00%, 1.00)", @gs.css_rgba)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_lighten_by
|
50
|
+
assert_in_delta(0.363, @gs.lighten_by(10).g, Spectrum::COLOR_TOLERANCE)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_pdf_fill
|
54
|
+
assert_equal("0.330 g", @gs.pdf_fill)
|
55
|
+
assert_equal("0.330 G", @gs.pdf_stroke)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_to_cmyk
|
59
|
+
cmyk = nil
|
60
|
+
assert_nothing_raised { cmyk = @gs.to_cmyk }
|
61
|
+
assert_kind_of(Spectrum::CMYK, cmyk)
|
62
|
+
assert_in_delta(0.0, cmyk.c, Spectrum::COLOR_TOLERANCE)
|
63
|
+
assert_in_delta(0.0, cmyk.m, Spectrum::COLOR_TOLERANCE)
|
64
|
+
assert_in_delta(0.0, cmyk.y, Spectrum::COLOR_TOLERANCE)
|
65
|
+
assert_in_delta(0.67, cmyk.k, Spectrum::COLOR_TOLERANCE)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_to_grayscale
|
69
|
+
assert_equal(@gs, @gs.to_grayscale)
|
70
|
+
assert_equal(@gs, @gs.to_greyscale)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_to_hsl
|
74
|
+
hsl = nil
|
75
|
+
assert_nothing_raised { hsl = @gs.to_hsl }
|
76
|
+
assert_kind_of(Spectrum::HSL, hsl)
|
77
|
+
assert_in_delta(0.0, hsl.h, Spectrum::COLOR_TOLERANCE)
|
78
|
+
assert_in_delta(0.0, hsl.s, Spectrum::COLOR_TOLERANCE)
|
79
|
+
assert_in_delta(0.33, hsl.l, Spectrum::COLOR_TOLERANCE)
|
80
|
+
assert_equal("hsl(0.00, 0.00%, 33.00%)", @gs.css_hsl)
|
81
|
+
assert_equal("hsla(0.00, 0.00%, 33.00%, 1.00)", @gs.css_hsla)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_to_rgb
|
85
|
+
rgb = nil
|
86
|
+
assert_nothing_raised { rgb = @gs.to_rgb }
|
87
|
+
assert_kind_of(Spectrum::RGB, rgb)
|
88
|
+
assert_in_delta(0.33, rgb.r, Spectrum::COLOR_TOLERANCE)
|
89
|
+
assert_in_delta(0.33, rgb.g, Spectrum::COLOR_TOLERANCE)
|
90
|
+
assert_in_delta(0.33, rgb.b, Spectrum::COLOR_TOLERANCE)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_to_yiq
|
94
|
+
yiq = nil
|
95
|
+
assert_nothing_raised { yiq = @gs.to_yiq }
|
96
|
+
assert_kind_of(Spectrum::YIQ, yiq)
|
97
|
+
assert_in_delta(0.33, yiq.y, Spectrum::COLOR_TOLERANCE)
|
98
|
+
assert_in_delta(0.0, yiq.i, Spectrum::COLOR_TOLERANCE)
|
99
|
+
assert_in_delta(0.0, yiq.q, Spectrum::COLOR_TOLERANCE)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_add
|
103
|
+
delta = @gs + Spectrum::GrayScale.new(20)
|
104
|
+
max = @gs + Spectrum::GrayScale.new(80)
|
105
|
+
|
106
|
+
assert_in_delta(1.0, max.g, Spectrum::COLOR_TOLERANCE)
|
107
|
+
assert_in_delta(0.53, delta.g, Spectrum::COLOR_TOLERANCE)
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_subtract
|
111
|
+
delta = @gs - Spectrum::GrayScale.new(20)
|
112
|
+
max = @gs - Spectrum::GrayScale.new(80)
|
113
|
+
assert_in_delta(0.0, max.g, Spectrum::COLOR_TOLERANCE)
|
114
|
+
assert_in_delta(0.13, delta.g, Spectrum::COLOR_TOLERANCE)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_inspect
|
118
|
+
assert_equal("Gray [33.00%]", @gs.inspect)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|