colordom 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/ext/colordom/Cargo.lock +1036 -0
- data/{Cargo.toml → ext/colordom/Cargo.toml} +1 -0
- data/ext/colordom/extconf.rb +6 -0
- data/ext/colordom/src/lib.rs +156 -0
- data/lib/colordom/color.rb +40 -16
- data/lib/colordom/error.rb +2 -0
- data/lib/colordom/image.rb +27 -0
- data/lib/colordom/version.rb +3 -1
- data/lib/colordom.rb +35 -39
- metadata +14 -37
- data/.gitignore +0 -17
- data/.travis.yml +0 -13
- data/Gemfile +0 -11
- data/Rakefile +0 -13
- data/bin/benchmark +0 -80
- data/bin/compare +0 -68
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/colordom.gemspec +0 -29
- data/ext/Rakefile +0 -10
- data/lib/colordom/native.rb +0 -16
- data/lib/colordom/result.rb +0 -9
- data/src/lib.rs +0 -99
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'colordom'
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require 'pry'
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require 'irb'
|
14
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
data/colordom.gemspec
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require_relative 'lib/colordom/version'
|
2
|
-
|
3
|
-
Gem::Specification.new do |spec|
|
4
|
-
spec.name = 'colordom'
|
5
|
-
spec.version = Colordom::VERSION
|
6
|
-
spec.authors = ['Jonian Guveli']
|
7
|
-
spec.email = ['jonian@hardpixel.eu']
|
8
|
-
|
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
|
-
spec.homepage = 'https://github.com/hardpixel/colordom'
|
12
|
-
spec.license = 'MIT'
|
13
|
-
|
14
|
-
# Specify which files should be added to the gem when it is released.
|
15
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
16
|
-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
17
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|samples)/}) }
|
18
|
-
end
|
19
|
-
|
20
|
-
spec.extensions = ['ext/Rakefile']
|
21
|
-
spec.require_paths = ['lib']
|
22
|
-
|
23
|
-
spec.add_runtime_dependency 'ffi'
|
24
|
-
spec.add_runtime_dependency 'thermite'
|
25
|
-
|
26
|
-
spec.add_development_dependency 'bundler', '~> 2.0'
|
27
|
-
spec.add_development_dependency 'minitest', '~> 5.0'
|
28
|
-
spec.add_development_dependency 'rake', '~> 13.0'
|
29
|
-
end
|
data/ext/Rakefile
DELETED
data/lib/colordom/native.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module Colordom
|
2
|
-
module Native
|
3
|
-
extend FFI::Library
|
4
|
-
|
5
|
-
LIBNAME = "colordom.#{FFI::Platform::LIBSUFFIX}".freeze
|
6
|
-
LIBPATH = File.expand_path('..', __dir__).freeze
|
7
|
-
|
8
|
-
ffi_lib File.expand_path(LIBNAME, LIBPATH)
|
9
|
-
|
10
|
-
attach_function :to_histogram, :to_histogram, [:string], Result
|
11
|
-
attach_function :to_mediancut, :to_mediancut, [:string, :uint8], Result
|
12
|
-
attach_function :to_kmeans, :to_kmeans, [:string, :uint], Result
|
13
|
-
|
14
|
-
attach_function :free, :free_result, [Result], :void
|
15
|
-
end
|
16
|
-
end
|
data/lib/colordom/result.rb
DELETED
data/src/lib.rs
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
use std::os::raw::c_char;
|
2
|
-
use std::ffi::{CStr, CString};
|
3
|
-
|
4
|
-
use image;
|
5
|
-
use dominant_color;
|
6
|
-
use kmeans_colors;
|
7
|
-
|
8
|
-
use palette_extract::{Quality, MaxColors, PixelEncoding, PixelFilter};
|
9
|
-
use palette::{FromColor, IntoColor, Lab, Pixel, Srgb};
|
10
|
-
|
11
|
-
fn to_string(unsafe_string: *const c_char) -> String {
|
12
|
-
unsafe { CStr::from_ptr(unsafe_string) }.to_str().unwrap().to_string()
|
13
|
-
}
|
14
|
-
|
15
|
-
fn to_char(string: String) -> *mut c_char {
|
16
|
-
CString::new(string).unwrap().into_raw()
|
17
|
-
}
|
18
|
-
|
19
|
-
#[no_mangle]
|
20
|
-
pub extern "C" fn to_histogram(path: *const c_char) -> *mut c_char {
|
21
|
-
let img = match image::open(&to_string(path)) {
|
22
|
-
Ok(res) => res,
|
23
|
-
Err(ex) => return to_char(format!("Colordom::Error {:?}", ex.to_string()))
|
24
|
-
};
|
25
|
-
|
26
|
-
let has_alpha = match img.color() {
|
27
|
-
image::ColorType::Rgba8 => true,
|
28
|
-
image::ColorType::Rgba16 => true,
|
29
|
-
image::ColorType::Rgba32F => true,
|
30
|
-
_ => false
|
31
|
-
};
|
32
|
-
|
33
|
-
let pixels = img.as_bytes();
|
34
|
-
let result = dominant_color::get_colors(&pixels, has_alpha);
|
35
|
-
|
36
|
-
return to_char(format!("{:?}", result));
|
37
|
-
}
|
38
|
-
|
39
|
-
#[no_mangle]
|
40
|
-
pub extern "C" fn to_mediancut(path: *const c_char, max_colors: u8) -> *mut c_char {
|
41
|
-
let img = match image::open(&to_string(path)) {
|
42
|
-
Ok(res) => res,
|
43
|
-
Err(ex) => return to_char(format!("Colordom::Error {:?}", ex.to_string()))
|
44
|
-
};
|
45
|
-
|
46
|
-
let pixels = img.as_bytes();
|
47
|
-
let result = palette_extract::get_palette_with_options(
|
48
|
-
&pixels,
|
49
|
-
PixelEncoding::Rgb,
|
50
|
-
Quality::new(6),
|
51
|
-
MaxColors::new(max_colors),
|
52
|
-
PixelFilter::None
|
53
|
-
);
|
54
|
-
|
55
|
-
return to_char(format!("{:?}", result))
|
56
|
-
}
|
57
|
-
|
58
|
-
#[no_mangle]
|
59
|
-
pub extern "C" fn to_kmeans(path: *const c_char, max_colors: usize) -> *mut c_char {
|
60
|
-
let img = match image::open(&to_string(path)) {
|
61
|
-
Ok(res) => res,
|
62
|
-
Err(ex) => return to_char(format!("Colordom::Error {:?}", ex.to_string()))
|
63
|
-
};
|
64
|
-
|
65
|
-
let pixels = img.as_bytes();
|
66
|
-
let max_iterations = 20;
|
67
|
-
let converge = 1.0;
|
68
|
-
let verbose = false;
|
69
|
-
let seed: u64 = 0;
|
70
|
-
|
71
|
-
let lab: Vec<Lab> = Srgb::from_raw_slice(&pixels)
|
72
|
-
.iter()
|
73
|
-
.map(|x| x.into_format().into_color())
|
74
|
-
.collect();
|
75
|
-
|
76
|
-
let run_result = kmeans_colors::get_kmeans_hamerly(
|
77
|
-
max_colors,
|
78
|
-
max_iterations,
|
79
|
-
converge,
|
80
|
-
verbose,
|
81
|
-
&lab,
|
82
|
-
seed
|
83
|
-
);
|
84
|
-
|
85
|
-
let result = &run_result.centroids
|
86
|
-
.iter()
|
87
|
-
.map(|x| Srgb::from_color(*x).into_format())
|
88
|
-
.collect::<Vec<Srgb<u8>>>();
|
89
|
-
|
90
|
-
return to_char(format!("{:?}", result))
|
91
|
-
}
|
92
|
-
|
93
|
-
#[no_mangle]
|
94
|
-
pub extern "C" fn free_result(string: *mut c_char) {
|
95
|
-
unsafe {
|
96
|
-
if string.is_null() { return }
|
97
|
-
CString::from_raw(string)
|
98
|
-
};
|
99
|
-
}
|