camalian 0.0.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/gpr-push.yml +30 -0
- data/.github/workflows/ruby.yml +32 -0
- data/.github/workflows/rubygems-push.yml +29 -0
- data/.gitignore +2 -1
- data/.overcommit.yml +33 -0
- data/.rubocop.yml +37 -0
- data/.tool-versions +1 -0
- data/.travis.yml +17 -0
- data/Gemfile +6 -0
- data/README.md +45 -5
- data/Rakefile +6 -3
- data/camalian.gemspec +16 -15
- data/lib/camalian.rb +20 -14
- data/lib/camalian/color.rb +47 -34
- data/lib/camalian/image.rb +24 -22
- data/lib/camalian/palette.rb +24 -5
- data/lib/camalian/quantization/histogram.rb +26 -0
- data/lib/camalian/quantization/k_means.rb +59 -0
- data/lib/camalian/quantization/median_cut.rb +74 -0
- data/lib/camalian/version.rb +3 -1
- data/test/assets/palette.png +0 -0
- data/test/color_test.rb +32 -0
- data/test/palette_test.rb +64 -0
- data/test/quantization/histogram_test.rb +61 -0
- data/test/quantization/k_means_test.rb +61 -0
- data/test/quantization/median_cut_test.rb +63 -0
- data/test/test_helper.rb +11 -0
- metadata +56 -23
- data/lib/chunky_png_patch/color.rb +0 -14
- data/test/test_color.rb +0 -29
- data/test/test_palette.rb +0 -28
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'minitest/spec'
|
6
|
+
require 'camalian'
|
7
|
+
|
8
|
+
describe Camalian::Quantization::KMeans do
|
9
|
+
describe 'palette with 15 colors extracted' do
|
10
|
+
before do
|
11
|
+
@image = Camalian.load(File.join(File.dirname(__FILE__), '../assets/palette.png'))
|
12
|
+
@palette = @image.prominent_colors(15, optimal: false, quantization: Camalian::QUANTIZATION_K_MEANS)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'must have 15 colors' do
|
16
|
+
_(@palette.size).must_equal 15
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'sort similar colors in order' do
|
20
|
+
_(@palette.sort_similar_colors.map(&:to_hex)).must_equal PALLET_IMAGE_COLORS
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should extract distinct colors' do
|
25
|
+
colors = %w[#FF0000 #00FF00 #0000FF].map { |c| Camalian::Color.from_hex(c) }
|
26
|
+
result = Camalian::Quantization::KMeans.new.process(colors, 3)
|
27
|
+
|
28
|
+
_(result.size).must_equal 3
|
29
|
+
_(result).must_equal colors
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should extract distinct colors lesser than pixels' do
|
33
|
+
colors = %w[#FF0000 #00FF00 #0000FF].map { |c| Camalian::Color.from_hex(c) }
|
34
|
+
result = Camalian::Quantization::KMeans.new.process(colors, 2)
|
35
|
+
|
36
|
+
_(result.size).must_equal 2
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should extract distinct colors not more than pixels' do
|
40
|
+
colors = %w[#FF0000 #00FF00 #0000FF].map { |c| Camalian::Color.from_hex(c) }
|
41
|
+
result = Camalian::Quantization::KMeans.new.process(colors, 4)
|
42
|
+
|
43
|
+
_(result.size).must_equal 3
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should extract same color' do
|
47
|
+
colors = %w[#FF0000 #FF0000 #FF0000].map { |c| Camalian::Color.from_hex(c) }
|
48
|
+
result = Camalian::Quantization::KMeans.new.process(colors, 3)
|
49
|
+
|
50
|
+
_(result.size).must_equal 1
|
51
|
+
_(result.to_hex).must_equal ['#ff0000']
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should extract multiple colors' do
|
55
|
+
colors = %w[#FF0000 #FF0000 #00FF00 #0000FF].map { |c| Camalian::Color.from_hex(c) }
|
56
|
+
result = Camalian::Quantization::KMeans.new.process(colors, 3)
|
57
|
+
|
58
|
+
_(result.size).must_equal 3
|
59
|
+
_(result.to_hex).must_equal %w[#ff0000 #00ff00 #0000ff]
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'minitest/spec'
|
6
|
+
require 'camalian'
|
7
|
+
|
8
|
+
describe Camalian::Quantization::MedianCut do
|
9
|
+
describe 'palette with 15 colors extracted' do
|
10
|
+
before do
|
11
|
+
@image = Camalian.load(File.join(File.dirname(__FILE__), '../assets/palette.png'))
|
12
|
+
@palette = @image.prominent_colors(15, optimal: false, quantization: Camalian::QUANTIZATION_MEDIAN_CUT)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'must have 15 colors' do
|
16
|
+
_(@palette.size).must_equal 15
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'sort similar colors in order' do
|
20
|
+
_(@palette.sort_similar_colors.map(&:to_hex)).must_equal ['#4dd915', '#49cc23', '#45c031', '#41b43f', '#3da84d',
|
21
|
+
'#399c5b', '#359069', '#318478', '#2d7886', '#296c94',
|
22
|
+
'#2560a2', '#2154b0', '#1d48be', '#193ccc', '#1530db']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should extract distinct colors' do
|
27
|
+
colors = %w[#FF0000 #00FF00 #0000FF].map { |c| Camalian::Color.from_hex(c) }
|
28
|
+
result = Camalian::Quantization::MedianCut.new.process(colors, 3)
|
29
|
+
|
30
|
+
_(result.size).must_equal 3
|
31
|
+
_(result.to_hex.sort).must_equal colors.map(&:to_hex).sort
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should extract distinct colors lesser than pixels' do
|
35
|
+
colors = %w[#FF0000 #00FF00 #0000FF].map { |c| Camalian::Color.from_hex(c) }
|
36
|
+
result = Camalian::Quantization::MedianCut.new.process(colors, 2)
|
37
|
+
|
38
|
+
_(result.size).must_equal 2
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should extract distinct colors not more than pixels' do
|
42
|
+
colors = %w[#FF0000 #00FF00 #0000FF].map { |c| Camalian::Color.from_hex(c) }
|
43
|
+
result = Camalian::Quantization::MedianCut.new.process(colors, 4)
|
44
|
+
|
45
|
+
_(result.size).must_equal 3
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should extract same color' do
|
49
|
+
colors = %w[#FF0000 #FF0000 #FF0000].map { |c| Camalian::Color.from_hex(c) }
|
50
|
+
result = Camalian::Quantization::MedianCut.new.process(colors, 3)
|
51
|
+
|
52
|
+
_(result.size).must_equal 1
|
53
|
+
_(result.to_hex).must_equal ['#ff0000']
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'only: should extract multiple colors' do
|
57
|
+
colors = %w[#FF0000 #FF0000 #00FF00 #0000FF].map { |c| Camalian::Color.from_hex(c) }
|
58
|
+
result = Camalian::Quantization::MedianCut.new.process(colors, 3)
|
59
|
+
|
60
|
+
_(result.size).must_equal 3
|
61
|
+
_(result.to_hex).must_equal ['#ff0000', '#0000ff', '#00ff00']
|
62
|
+
end
|
63
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
|
6
|
+
require 'minitest/autorun'
|
7
|
+
require 'minitest/spec'
|
8
|
+
require 'camalian'
|
9
|
+
|
10
|
+
PALLET_IMAGE_COLORS = %w[#4dd915 #49cc23 #45c031 #41b43f #3da84d #399c5b #359069 #318478 #2d7886 #296c94 #2560a2
|
11
|
+
#2154b0 #1d48be #193ccc #1530db].freeze
|
metadata
CHANGED
@@ -1,57 +1,75 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: camalian
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nazar Hussain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: chunky_png
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
17
20
|
- - ">="
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
22
|
+
version: 1.3.14
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
24
30
|
- - ">="
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
32
|
+
version: 1.3.14
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
34
|
+
name: minitest
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - "~>"
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
|
39
|
+
version: '5.14'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 5.14.2
|
43
|
+
type: :development
|
35
44
|
prerelease: false
|
36
45
|
version_requirements: !ruby/object:Gem::Requirement
|
37
46
|
requirements:
|
38
47
|
- - "~>"
|
39
48
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
49
|
+
version: '5.14'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 5.14.2
|
41
53
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
54
|
+
name: rake
|
43
55
|
requirement: !ruby/object:Gem::Requirement
|
44
56
|
requirements:
|
45
57
|
- - "~>"
|
46
58
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
48
|
-
|
59
|
+
version: '13.0'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 13.0.1
|
63
|
+
type: :development
|
49
64
|
prerelease: false
|
50
65
|
version_requirements: !ruby/object:Gem::Requirement
|
51
66
|
requirements:
|
52
67
|
- - "~>"
|
53
68
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
69
|
+
version: '13.0'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 13.0.1
|
55
73
|
description: Library used to deal with colors and images
|
56
74
|
email:
|
57
75
|
- nazarhussain@gmail.com
|
@@ -59,7 +77,14 @@ executables: []
|
|
59
77
|
extensions: []
|
60
78
|
extra_rdoc_files: []
|
61
79
|
files:
|
80
|
+
- ".github/workflows/gpr-push.yml"
|
81
|
+
- ".github/workflows/ruby.yml"
|
82
|
+
- ".github/workflows/rubygems-push.yml"
|
62
83
|
- ".gitignore"
|
84
|
+
- ".overcommit.yml"
|
85
|
+
- ".rubocop.yml"
|
86
|
+
- ".tool-versions"
|
87
|
+
- ".travis.yml"
|
63
88
|
- Gemfile
|
64
89
|
- LICENSE.txt
|
65
90
|
- README.md
|
@@ -69,11 +94,17 @@ files:
|
|
69
94
|
- lib/camalian/color.rb
|
70
95
|
- lib/camalian/image.rb
|
71
96
|
- lib/camalian/palette.rb
|
97
|
+
- lib/camalian/quantization/histogram.rb
|
98
|
+
- lib/camalian/quantization/k_means.rb
|
99
|
+
- lib/camalian/quantization/median_cut.rb
|
72
100
|
- lib/camalian/version.rb
|
73
|
-
- lib/chunky_png_patch/color.rb
|
74
101
|
- test/assets/palette.png
|
75
|
-
- test/
|
76
|
-
- test/
|
102
|
+
- test/color_test.rb
|
103
|
+
- test/palette_test.rb
|
104
|
+
- test/quantization/histogram_test.rb
|
105
|
+
- test/quantization/k_means_test.rb
|
106
|
+
- test/quantization/median_cut_test.rb
|
107
|
+
- test/test_helper.rb
|
77
108
|
homepage: https://github.com/nazarhussain/camalian
|
78
109
|
licenses:
|
79
110
|
- MIT
|
@@ -86,21 +117,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
117
|
requirements:
|
87
118
|
- - ">="
|
88
119
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
120
|
+
version: '2.5'
|
90
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
122
|
requirements:
|
92
123
|
- - ">="
|
93
124
|
- !ruby/object:Gem::Version
|
94
125
|
version: '0'
|
95
|
-
requirements:
|
96
|
-
|
97
|
-
rubyforge_project:
|
98
|
-
rubygems_version: 2.4.5
|
126
|
+
requirements: []
|
127
|
+
rubygems_version: 3.0.3.1
|
99
128
|
signing_key:
|
100
129
|
specification_version: 4
|
101
130
|
summary: Library used to deal with colors and images. You can extract colors from
|
102
131
|
images.
|
103
132
|
test_files:
|
104
133
|
- test/assets/palette.png
|
105
|
-
- test/
|
106
|
-
- test/
|
134
|
+
- test/color_test.rb
|
135
|
+
- test/palette_test.rb
|
136
|
+
- test/quantization/histogram_test.rb
|
137
|
+
- test/quantization/k_means_test.rb
|
138
|
+
- test/quantization/median_cut_test.rb
|
139
|
+
- test/test_helper.rb
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module ChunkyPNG::Color
|
2
|
-
# See http://en.wikipedia.org/wiki/Hue#Computing_hue_from_RGB
|
3
|
-
def self.hue(pixel)
|
4
|
-
r, g, b = r(pixel), g(pixel), b(pixel)
|
5
|
-
return 0 if r == b and b == g
|
6
|
-
((180 / Math::PI * Math.atan2((2 * r) - g - b, Math.sqrt(3) * (g - b))) - 90) % 360
|
7
|
-
end
|
8
|
-
|
9
|
-
# The modular distance, as the hue is circular
|
10
|
-
def self.distance(pixel, poxel)
|
11
|
-
hue_pixel, hue_poxel = hue(pixel), hue(poxel)
|
12
|
-
[(hue_pixel - hue_poxel) % 360, (hue_poxel - hue_pixel) % 360].min
|
13
|
-
end
|
14
|
-
end
|
data/test/test_color.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'minitest/spec'
|
3
|
-
require 'camalian'
|
4
|
-
|
5
|
-
describe Camalian::Color do
|
6
|
-
before do
|
7
|
-
@color = Camalian::Color.new(120,255,30)
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "Color initialized with 120, 255, 30 rgb values" do
|
11
|
-
it "hex value must be #78ff1e" do
|
12
|
-
@color.to_hex.must_equal "#78ff1e"
|
13
|
-
end
|
14
|
-
|
15
|
-
it "hsl color components must " do
|
16
|
-
[@color.h.to_i, @color.s.to_i, @color.l.to_i].must_equal [96, 100, 55]
|
17
|
-
end
|
18
|
-
|
19
|
-
it "hsv color components must " do
|
20
|
-
@color.hsv.map(&:to_i).must_equal [96, 88, 100]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "initialized with 1 integer rgb value" do
|
25
|
-
it "must have leading zero" do
|
26
|
-
Camalian::Color.new(7, 7, 7).to_hex.must_equal "#070707"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/test/test_palette.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'minitest/spec'
|
3
|
-
require 'camalian'
|
4
|
-
|
5
|
-
describe Camalian::Image do
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
describe Camalian::Palette do
|
10
|
-
before do
|
11
|
-
@image = Camalian::load( File.join( File.dirname(__FILE__), 'assets/palette.png'))
|
12
|
-
@palette = @image.prominent_colors(15)
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "palette with 15 colors extracted" do
|
16
|
-
it "must have 15 colors" do
|
17
|
-
@palette.size.must_equal 15
|
18
|
-
end
|
19
|
-
|
20
|
-
it "sort similar colors in order" do
|
21
|
-
@palette.sort_similar_colors.map(&:to_hex).must_equal %W(#4dda15 #45c131 #41b53f #3da94d #3da84e #359169 #318578 #2d7986 #296d94 #2560a3 #2154b1 #1d48bf #193dcd #193cce #1530dc)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "color with intensity 0-40 works well" do
|
25
|
-
@palette.light_colors(0, 40).map(&:to_hex).must_equal %W(#318578 #2560a3 #359169 #296d94 #2d7986)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|