grayphash 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/grayhash/extconf.rb +11 -0
- data/ext/grayhash/grayphash.c +66 -0
- data/lib/grayphash.rb +5 -0
- metadata +81 -0
@@ -0,0 +1,11 @@
|
|
1
|
+
# Loads mkmf which is used to make makefiles for Ruby extensions
|
2
|
+
require 'mkmf'
|
3
|
+
|
4
|
+
# Give it a name
|
5
|
+
extension_name = 'grayphash'
|
6
|
+
|
7
|
+
# The destination
|
8
|
+
#dir_config(extension_name)
|
9
|
+
|
10
|
+
# Do the work
|
11
|
+
create_makefile("#{extension_name}/#{extension_name}")
|
@@ -0,0 +1,66 @@
|
|
1
|
+
// Include the Ruby headers and goodies
|
2
|
+
#include "ruby.h"
|
3
|
+
#include <dlfcn.h>
|
4
|
+
|
5
|
+
// Defining a space for information and references about the module to be stored internally
|
6
|
+
VALUE Grayphash = Qnil;
|
7
|
+
|
8
|
+
// Prototype for the initialization method - Ruby calls this, not you
|
9
|
+
void Init_grayphash();
|
10
|
+
|
11
|
+
VALUE method_about(VALUE self);
|
12
|
+
VALUE method_close(VALUE self);
|
13
|
+
VALUE method_image_phash(int argc, VALUE * argv, VALUE self);
|
14
|
+
VALUE method_hamming(int argc, VALUE * argv, VALUE self);
|
15
|
+
void* sdl_library = NULL;
|
16
|
+
|
17
|
+
// The initialization method for this module
|
18
|
+
void Init_grayphash() {
|
19
|
+
Grayphash = rb_define_module("Grayphash");
|
20
|
+
rb_define_method(Grayphash, "about", method_about, 0);
|
21
|
+
rb_define_method(Grayphash, "close", method_close, 0);
|
22
|
+
rb_define_method(Grayphash, "image_phash", &method_image_phash, -1);
|
23
|
+
rb_define_method(Grayphash, "hamming", &method_hamming, -1);
|
24
|
+
sdl_library = dlopen("/usr/lib/libpHash.so", RTLD_LAZY);
|
25
|
+
}
|
26
|
+
|
27
|
+
VALUE method_hamming(int argc, VALUE * argv, VALUE self) {
|
28
|
+
if (argc !=2) { // there should only be 1 or 2 arguments
|
29
|
+
rb_raise(rb_eArgError, "wrong number of arguments");
|
30
|
+
}
|
31
|
+
unsigned long long hash1 = rb_num2ull(argv[0]);
|
32
|
+
unsigned long long hash2 = rb_num2ull(argv[1]);
|
33
|
+
int* (*phash_func)();
|
34
|
+
phash_func = dlsym(sdl_library, "ph_hamming_distance");
|
35
|
+
|
36
|
+
return INT2FIX(
|
37
|
+
((*phash_func)(hash1, hash2))
|
38
|
+
);
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
VALUE method_image_phash(int argc, VALUE * argv, VALUE self) {
|
43
|
+
if(argc==0) return Qnil;
|
44
|
+
char* file = StringValuePtr(*argv);
|
45
|
+
unsigned long long hash = 0;
|
46
|
+
int* (*phash_func)();
|
47
|
+
phash_func = dlsym(sdl_library, "ph_dct_imagehash");
|
48
|
+
((*phash_func)(file, &hash));
|
49
|
+
|
50
|
+
return ULL2NUM(hash);
|
51
|
+
}
|
52
|
+
|
53
|
+
VALUE method_close(VALUE self) {
|
54
|
+
if(dlclose(sdl_library)==0) {
|
55
|
+
return Qtrue;
|
56
|
+
}
|
57
|
+
else {
|
58
|
+
return Qfalse;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
VALUE method_about(VALUE self) {
|
63
|
+
char* (*about)();
|
64
|
+
about = dlsym(sdl_library, "ph_about");
|
65
|
+
return rb_str_new_cstr((*about)());
|
66
|
+
}
|
data/lib/grayphash.rb
ADDED
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: grayphash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tauraloke
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: fspath
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: pHash image wrapper
|
47
|
+
email: tauraloke@gmail.com
|
48
|
+
executables: []
|
49
|
+
extensions:
|
50
|
+
- ext/grayhash/extconf.rb
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- lib/grayphash.rb
|
54
|
+
- ext/grayhash/grayphash.c
|
55
|
+
- ext/grayhash/extconf.rb
|
56
|
+
homepage: http://github.com/tauraloke/grayphash
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project: grayphash
|
77
|
+
rubygems_version: 1.8.24
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: Simple wrapper for some pHash image functions
|
81
|
+
test_files: []
|