colordom 0.1.0 → 0.2.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: e428a11ebd273b9e3f8867468f74eff34cc681426e97133ec4cbce666c9006ce
4
- data.tar.gz: e7d31a241c15cdd96b078f60ae8ae302d81206f691b0d50ff8208b2d526803e9
3
+ metadata.gz: 36630f3459a8b4c4ab4dc464bd98d9e6f90d5d3684c1520abc7241e5c6c5032c
4
+ data.tar.gz: ea5171ee0afce0635bb9bf1aa9b83d7b2499c3c4c8db6e433677ba5fc339b6a3
5
5
  SHA512:
6
- metadata.gz: 5545da4d90450efee71fb4b1d078760d4820a703497a2cc7c3ba785f6be6f8caef49e218dcf011052c8ee6affbb1cf6b736b5be5210e0209ef4d5179a3ff73e1
7
- data.tar.gz: 78350ba55457fc55e4429854b343a10a639137a8daeb3379e431425da93d48580bce4efed1707c744dd911a56b160664c0db6980eebe20802238d7e3d4ee3211
6
+ metadata.gz: 347d94b5bad2abf596203a1364e308803fcd509d110f0bbfd589da19043c47c1ce054f7c3dd40bcfd79f7cd931d52dbe18f10c1d2d9e957e9baf628df7ec99cf
7
+ data.tar.gz: b51088add6ccaffd435e2696e75d7096f18dd9472b82f19327956f02a0f569c13a1504be1be8b9aa732bbf2466f68ad19842169352f3c5a096f250c57dc6ca2b
data/Gemfile CHANGED
@@ -6,3 +6,6 @@ gemspec
6
6
  gem 'benchmark-ips'
7
7
  gem 'benchmark-memory'
8
8
  gem 'camalian'
9
+ gem 'colorscore'
10
+ gem 'miro', github: 'jonbuda/miro'
11
+ gem 'chunky_png', '1.3.15'
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Colordom
2
2
 
3
- Ruby gem to extract color palettes from images implemented in Rust. Rust must be available on your system to install this gem.
3
+ Ruby gem to extract dominant colors from images using native extension implemented in Rust. Rust must be available on your system to install this gem.
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/colordom.svg)](https://badge.fury.io/rb/colordom)
6
6
  [![Build Status](https://travis-ci.org/hardpixel/colordom.svg?branch=master)](https://travis-ci.org/hardpixel/colordom)
7
- [![Maintainability](https://api.codeclimate.com/v1/badges/7e307214d3c2e4d2056d/maintainability)](https://codeclimate.com/github/hardpixel/colordom/maintainability)
7
+ [![Maintainability](https://api.codeclimate.com/v1/badges/6040c6d79abf2d6e7efb/maintainability)](https://codeclimate.com/github/hardpixel/colordom/maintainability)
8
8
 
9
9
  ## Installation
10
10
 
data/bin/benchmark CHANGED
@@ -7,10 +7,25 @@ require 'benchmark/memory'
7
7
 
8
8
  require 'colordom'
9
9
  require 'camalian'
10
+ require 'colorscore'
11
+ require 'miro'
10
12
 
11
13
  COUNT = 5
12
14
  IMAGE = File.join(__dir__, '..', 'samples/sample.png')
13
15
 
16
+ def miro(method)
17
+ Miro.options[:color_count] = COUNT
18
+ Miro.options[:method] = method
19
+
20
+ colors = Miro::DominantColors.new(IMAGE)
21
+ colors.to_hex
22
+ end
23
+
24
+ def colorscore
25
+ histogram = Colorscore::Histogram.new(IMAGE, COUNT)
26
+ histogram.colors
27
+ end
28
+
14
29
  def camalian(quant)
15
30
  img = Camalian::load(IMAGE)
16
31
  img.prominent_colors(COUNT, quantization: quant)
@@ -29,6 +44,18 @@ reports = lambda do |x|
29
44
  Colordom.kmeans(IMAGE, COUNT)
30
45
  end
31
46
 
47
+ x.report('colorscore (HST)') do
48
+ colorscore
49
+ end
50
+
51
+ x.report('miro (HST)') do
52
+ miro('histogram')
53
+ end
54
+
55
+ x.report('miro (PXG)') do
56
+ miro('pixel_group')
57
+ end
58
+
32
59
  x.report('camalian (HST)') do
33
60
  camalian(Camalian::QUANTIZATION_HISTOGRAM)
34
61
  end
data/bin/compare ADDED
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+
5
+ require 'tempfile'
6
+ require 'base64'
7
+
8
+ require 'colordom'
9
+ require 'camalian'
10
+ require 'colorscore'
11
+ require 'miro'
12
+
13
+ COUNT = 6
14
+ IMAGE = File.join(__dir__, '..', 'samples/compare.png')
15
+ TEMPL = File.read File.join(__dir__, '..', 'samples/compare.svg')
16
+
17
+ TEMPL.sub!('compare.png', "data:image/png;base64,#{Base64.strict_encode64(File.read(IMAGE))}")
18
+
19
+ def replace(prefix, colors)
20
+ colors.each_with_index do |color, index|
21
+ TEMPL.sub!("{{#{prefix}-#{index}}}", color)
22
+ end
23
+ end
24
+
25
+ def miro(method, prefix)
26
+ Miro.options[:color_count] = COUNT
27
+ Miro.options[:method] = method
28
+
29
+ colors = Miro::DominantColors.new(IMAGE)
30
+ replace("miro-#{prefix}", colors.to_hex)
31
+ end
32
+
33
+ def colorscore(prefix)
34
+ histogram = Colorscore::Histogram.new(IMAGE, COUNT)
35
+ replace("colorscore-#{prefix}", histogram.colors.map(&:html))
36
+ end
37
+
38
+ def camalian(quant, prefix)
39
+ image = Camalian::load(IMAGE)
40
+ colors = image.prominent_colors(COUNT, quantization: quant)
41
+
42
+ replace("camalian-#{prefix}", colors.map(&:to_hex))
43
+ end
44
+
45
+ def colordom(method, prefix)
46
+ colors = Colordom.send(method, IMAGE, COUNT)
47
+ replace("colordom-#{prefix}", colors.map(&:to_hex))
48
+ end
49
+
50
+ colordom(:histogram, 'hst')
51
+ colordom(:mediancut, 'mcq')
52
+ colordom(:kmeans, 'kms')
53
+
54
+ camalian(Camalian::QUANTIZATION_HISTOGRAM, 'hst')
55
+ camalian(Camalian::QUANTIZATION_MEDIAN_CUT, 'mcq')
56
+ camalian(Camalian::QUANTIZATION_K_MEANS, 'kms')
57
+
58
+ colorscore('hst')
59
+
60
+ miro('histogram', 'hst')
61
+ miro('pixel_group', 'pxg')
62
+
63
+ tempfile = Tempfile.create(['colordom-compare', '.svg'])
64
+
65
+ tempfile.write(TEMPL)
66
+ tempfile.close
67
+
68
+ system("xdg-open #{tempfile.path}")
data/colordom.gemspec CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |spec|
6
6
  spec.authors = ['Jonian Guveli']
7
7
  spec.email = ['jonian@hardpixel.eu']
8
8
 
9
- spec.summary = %q{Ruby wrapper for dominant color utilities in Rust}
10
- spec.description = %q{This project is a wrapper for dominant color utilities implemented in Rust.}
9
+ spec.summary = %q{Extract dominant colors from images}
10
+ spec.description = %q{Extract dominant colors from images using native extension implemented in Rust.}
11
11
  spec.homepage = 'https://github.com/hardpixel/colordom'
12
12
  spec.license = 'MIT'
13
13
 
@@ -16,9 +16,7 @@ module Colordom
16
16
  end
17
17
 
18
18
  def hex
19
- rgb.inject('#') do |str, val|
20
- str + val.to_s(16).rjust(2, '0').upcase
21
- end
19
+ '#%02X%02X%02X' % rgb
22
20
  end
23
21
 
24
22
  alias to_rgb rgb
@@ -9,7 +9,7 @@ module Colordom
9
9
 
10
10
  attach_function :to_histogram, :to_histogram, [:string], Result
11
11
  attach_function :to_mediancut, :to_mediancut, [:string, :uint8], Result
12
- attach_function :to_kmeans, :to_kmeans, [:string, :uint8], Result
12
+ attach_function :to_kmeans, :to_kmeans, [:string, :uint], Result
13
13
 
14
14
  attach_function :free, :free_result, [Result], :void
15
15
  end
@@ -1,3 +1,3 @@
1
1
  module Colordom
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/src/lib.rs CHANGED
@@ -23,7 +23,6 @@ pub extern "C" fn to_histogram(path: *const c_char) -> *mut c_char {
23
23
  Err(ex) => return to_char(format!("Colordom::Error {:?}", ex.to_string()))
24
24
  };
25
25
 
26
-
27
26
  let has_alpha = match img.color() {
28
27
  image::ColorType::Rgba8 => true,
29
28
  image::ColorType::Rgba16 => true,
@@ -48,7 +47,7 @@ pub extern "C" fn to_mediancut(path: *const c_char, max_colors: u8) -> *mut c_ch
48
47
  let result = palette_extract::get_palette_with_options(
49
48
  &pixels,
50
49
  PixelEncoding::Rgb,
51
- Quality::default(),
50
+ Quality::new(6),
52
51
  MaxColors::new(max_colors),
53
52
  PixelFilter::None
54
53
  );
@@ -57,7 +56,7 @@ pub extern "C" fn to_mediancut(path: *const c_char, max_colors: u8) -> *mut c_ch
57
56
  }
58
57
 
59
58
  #[no_mangle]
60
- pub extern "C" fn to_kmeans(path: *const c_char, max_colors: u8) -> *mut c_char {
59
+ pub extern "C" fn to_kmeans(path: *const c_char, max_colors: usize) -> *mut c_char {
61
60
  let img = match image::open(&to_string(path)) {
62
61
  Ok(res) => res,
63
62
  Err(ex) => return to_char(format!("Colordom::Error {:?}", ex.to_string()))
@@ -75,7 +74,7 @@ pub extern "C" fn to_kmeans(path: *const c_char, max_colors: u8) -> *mut c_char
75
74
  .collect();
76
75
 
77
76
  let run_result = kmeans_colors::get_kmeans_hamerly(
78
- max_colors.into(),
77
+ max_colors,
79
78
  max_iterations,
80
79
  converge,
81
80
  verbose,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colordom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonian Guveli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-19 00:00:00.000000000 Z
11
+ date: 2022-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -80,8 +80,8 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '13.0'
83
- description: This project is a wrapper for dominant color utilities implemented in
84
- Rust.
83
+ description: Extract dominant colors from images using native extension implemented
84
+ in Rust.
85
85
  email:
86
86
  - jonian@hardpixel.eu
87
87
  executables: []
@@ -97,6 +97,7 @@ files:
97
97
  - README.md
98
98
  - Rakefile
99
99
  - bin/benchmark
100
+ - bin/compare
100
101
  - bin/console
101
102
  - bin/setup
102
103
  - colordom.gemspec
@@ -130,5 +131,5 @@ requirements: []
130
131
  rubygems_version: 3.1.6
131
132
  signing_key:
132
133
  specification_version: 4
133
- summary: Ruby wrapper for dominant color utilities in Rust
134
+ summary: Extract dominant colors from images
134
135
  test_files: []