dhash-vips 0.2.4.0 → 0.2.5.0
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.
- checksums.yaml +4 -4
- data/dhash-vips.gemspec +1 -1
- data/extconf.rb +7 -12
- data/lib/dhash-vips.rb +17 -12
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 461fbfc5025ae787cb043f8eb7bb1be160ee9d2b0fe58888082d40391afe3338
|
|
4
|
+
data.tar.gz: a56a1ccba11077dec9f266f7ca743b1e678d32439a3eddde134c5ffb10ee7ec8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7ee718d04a02cfdd9176cbfdb75e57c1645cb44eae6ee3436c9f31f90f27b50b52a9469c24accb2135f2b3359a9f733ad59bb62e6a2046d8849674860021c374
|
|
7
|
+
data.tar.gz: 496b98297106bb8ca3d1bf43e1b67511ea424af5bbdd75afe47d050136f76ae584813fd8e7fb75696499ed0180ae9cc684f30a9a9104c9cc43b140f7f2d74396
|
data/dhash-vips.gemspec
CHANGED
data/extconf.rb
CHANGED
|
@@ -1,28 +1,23 @@
|
|
|
1
|
-
require "mkmf"
|
|
2
|
-
|
|
3
|
-
File.write "Makefile", dummy_makefile(?.).join
|
|
4
|
-
|
|
5
1
|
unless Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.3.8")
|
|
2
|
+
require "mkmf"
|
|
3
|
+
File.write "Makefile", dummy_makefile(?.).join
|
|
6
4
|
append_cppflags "-DRUBY_EXPORT" unless Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.4")
|
|
7
5
|
create_makefile "idhash"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
File.write "Makefile", <<~HEREDOC + File.read("Makefile")
|
|
12
|
-
.PHONY: test
|
|
13
|
-
test: all
|
|
6
|
+
File.write "Makefile", File.read("Makefile") + <<~HEREDOC
|
|
7
|
+
.PHONY: post_install_test
|
|
8
|
+
post_install_test: all
|
|
14
9
|
\t$(RUBY) -r./lib/dhash-vips.rb ./lib/dhash-vips-post-install-test.rb
|
|
15
10
|
HEREDOC
|
|
16
11
|
end
|
|
17
12
|
|
|
18
13
|
__END__
|
|
19
14
|
|
|
20
|
-
# this unlike using rake is building to current directory
|
|
15
|
+
# this unlike using `rake -rbundler/gem_tasks` is building to current directory
|
|
21
16
|
# that is vital to be able to require the native extension for benchmarking, etc.
|
|
22
17
|
$ ruby extconf.rb && make clean && make
|
|
23
18
|
|
|
24
19
|
# to test the installation:
|
|
25
|
-
$ rake clean && rake install
|
|
20
|
+
$ rake -rbundler/gem_tasks clean && rake -rbundler/gem_tasks install
|
|
26
21
|
|
|
27
22
|
$ ruby -e "require 'dhash-vips'; p DHashVips::IDHash.method(:distance3).source_location" # using -r makes bundler mad
|
|
28
23
|
# [".../dhash-vips.rb", 32] # if LoadError
|
data/lib/dhash-vips.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require "vips"
|
|
2
|
-
Vips.vector_set false
|
|
2
|
+
::Vips.vector_set false # TODO: document why?
|
|
3
3
|
|
|
4
4
|
module DHashVips
|
|
5
5
|
|
|
@@ -15,10 +15,10 @@ module DHashVips
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def pixelate input, hash_size
|
|
18
|
-
DHashVips.bw( if input.is_a? Vips::Image
|
|
18
|
+
::DHashVips.bw( if input.is_a? ::Vips::Image
|
|
19
19
|
input.thumbnail_image(hash_size + 1, height: hash_size, size: :force)
|
|
20
20
|
else
|
|
21
|
-
Vips::Image.thumbnail(input, hash_size + 1, height: hash_size, size: :force)
|
|
21
|
+
::Vips::Image.thumbnail(input, hash_size + 1, height: hash_size, size: :force)
|
|
22
22
|
end )
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -35,16 +35,18 @@ module DHashVips
|
|
|
35
35
|
((a ^ b) & (a | b) >> 128).to_s(2).count "1"
|
|
36
36
|
end
|
|
37
37
|
begin
|
|
38
|
-
require_relative "../idhash.#{Gem::Platform.local.os == "darwin" ? "bundle" : "
|
|
39
|
-
rescue LoadError
|
|
38
|
+
require_relative "../idhash.#{::Gem::Platform.local.os == "darwin" ? "bundle" : "so"}"
|
|
39
|
+
rescue ::LoadError
|
|
40
|
+
warn "C extension for IDHash is not available, using Ruby fallback"
|
|
40
41
|
class << self
|
|
41
42
|
alias distance3 distance3_ruby
|
|
42
43
|
end
|
|
43
44
|
else
|
|
45
|
+
|
|
44
46
|
# we can't just do `defined? Bignum` because it's defined but deprecated (some internal CONST_DEPRECATED flag)
|
|
45
|
-
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.4")
|
|
47
|
+
if ::Gem::Version.new(RUBY_VERSION) < ::Gem::Version.new("2.4")
|
|
46
48
|
def self.distance3 a, b
|
|
47
|
-
if a.is_a?(Bignum) && b.is_a?(Bignum)
|
|
49
|
+
if a.is_a?(::Bignum) && b.is_a?(::Bignum)
|
|
48
50
|
distance3_c a, b
|
|
49
51
|
else
|
|
50
52
|
distance3_ruby a, b
|
|
@@ -53,16 +55,19 @@ module DHashVips
|
|
|
53
55
|
else
|
|
54
56
|
# https://github.com/ruby/ruby/commit/de2f7416d2deb4166d78638a41037cb550d64484#diff-16b196bc6bfe8fba63951420f843cfb4R10
|
|
55
57
|
require "rbconfig/sizeof"
|
|
56
|
-
FIXNUM_MAX = (1 << (8 * RbConfig::SIZEOF["long"] - 2)) - 1
|
|
58
|
+
::FIXNUM_MAX = (1 << (8 * ::RbConfig::SIZEOF["long"] - 2)) - 1
|
|
57
59
|
def self.distance3 a, b
|
|
58
|
-
if a > FIXNUM_MAX && b > FIXNUM_MAX
|
|
60
|
+
if a > ::FIXNUM_MAX && b > ::FIXNUM_MAX
|
|
59
61
|
distance3_c a, b
|
|
60
62
|
else
|
|
61
63
|
distance3_ruby a, b
|
|
62
64
|
end
|
|
63
65
|
end
|
|
64
66
|
end
|
|
67
|
+
# TODO: maybe avoiding Ruby-level if-else would make it faster if we manage to call `#distance3_ruby` from C
|
|
68
|
+
|
|
65
69
|
end
|
|
70
|
+
|
|
66
71
|
def self.distance a, b
|
|
67
72
|
size_a, size_b = [a, b].map do |x|
|
|
68
73
|
# TODO write a test about possible hash sizes
|
|
@@ -98,12 +103,12 @@ module DHashVips
|
|
|
98
103
|
|
|
99
104
|
def self.fingerprint input, power = 3
|
|
100
105
|
size = 2 ** power
|
|
101
|
-
image = if input.is_a? Vips::Image
|
|
106
|
+
image = if input.is_a? ::Vips::Image
|
|
102
107
|
input.thumbnail_image(size, height: size, size: :force)
|
|
103
108
|
else
|
|
104
|
-
Vips::Image.thumbnail(input, size, height: size, size: :force)
|
|
109
|
+
::Vips::Image.thumbnail(input, size, height: size, size: :force)
|
|
105
110
|
end
|
|
106
|
-
array = DHashVips.bw(image).to_enum.map &:flatten
|
|
111
|
+
array = ::DHashVips.bw(image).to_enum.map &:flatten
|
|
107
112
|
d1, i1, d2, i2 = [array, array.transpose].flat_map do |a|
|
|
108
113
|
d = a.zip(a.rotate(1)).flat_map{ |r1, r2| r1.zip(r2).map{ |i, j| i - j } }
|
|
109
114
|
m = median d.map(&:abs).sort
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dhash-vips
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Victor Maslov aka Nakilon
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-09-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: ruby-vips
|
|
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
71
71
|
- !ruby/object:Gem::Version
|
|
72
72
|
version: '0'
|
|
73
73
|
requirements: []
|
|
74
|
-
rubygems_version: 3.
|
|
74
|
+
rubygems_version: 3.2.0
|
|
75
75
|
signing_key:
|
|
76
76
|
specification_version: 4
|
|
77
77
|
summary: dHash and IDHash perceptual image hashing/fingerprinting
|