grayphash 0.0.4.2 → 0.0.5

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.
@@ -1,6 +1,6 @@
1
1
  # Loads mkmf which is used to make makefiles for Ruby extensions
2
2
  require 'mkmf'
3
-
3
+
4
4
  # Give it a name
5
5
  extension_name = 'grayphash'
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grayphash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4.2
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -19,7 +19,6 @@ extensions:
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - lib/grayphash.rb
22
- - ext/grayhash/grayphash.c
23
22
  - ext/grayhash/extconf.rb
24
23
  homepage: http://github.com/tauraloke/grayphash
25
24
  licenses:
@@ -1,73 +0,0 @@
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
-
34
-
35
- unsigned long long x = hash1^hash2;
36
- const unsigned long long m1 = 0x5555555555555555ULL;
37
- const unsigned long long m2 = 0x3333333333333333ULL;
38
- const unsigned long long h01 = 0x0101010101010101ULL;
39
- const unsigned long long m4 = 0x0f0f0f0f0f0f0f0fULL;
40
- x -= (x >> 1) & m1;
41
- x = (x & m2) + ((x >> 2) & m2);
42
- x = (x + (x >> 4)) & m4;
43
- return INT2FIX((x * h01)>>56);
44
- }
45
-
46
-
47
- VALUE method_image_phash(int argc, VALUE * argv, VALUE self) {
48
- if(argc==0) return Qnil;
49
- char* file = StringValuePtr(*argv);
50
- unsigned long long hash = 0;
51
- int* (*phash_func)();
52
- phash_func = dlsym(sdl_library, "ph_dct_imagehash");
53
- ((*phash_func)(file, &hash));
54
-
55
- return ULL2NUM(hash);
56
- }
57
-
58
- VALUE method_close(VALUE self) {
59
- if(dlclose(sdl_library)==0) {
60
- return Qtrue;
61
- }
62
- else {
63
- return Qfalse;
64
- }
65
- }
66
-
67
- VALUE method_about(VALUE self) {
68
- return rb_str_new_cstr("pHash 0.9.4. Copyright 2008-2010 Aetilius, Inc. Included only some image functions (grayphash v-0.0.4.2).");
69
- //char* (*about)();
70
- //about = dlsym(sdl_library, "ph_about");
71
-
72
- //return rb_str_new_cstr((*about)());
73
- }