dhash-vips 0.2.0.0 → 0.2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/common.rb +2 -2
- data/dhash-vips.gemspec +1 -1
- data/extconf.rb +3 -2
- data/lib/dhash-vips.rb +10 -5
- data/test.rb +59 -150
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ce70f825a89117f682dad1e5ae6400ec3cd430d08d8bb34b36719dff4905894e
|
4
|
+
data.tar.gz: 17ff221fad7650632cefc04f7421efc79b4f0fe0f2f884d6f1019fc82d360c94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '019fa1a1b89a5e734332eb1993ea4ccd9dd18b6add3677f065c41cbf0b624986220a094ee5e055cf4f965b56292abe9275ee96fdcbdae53481ea557b0317ad46'
|
7
|
+
data.tar.gz: 4fa0705056bc27ef272b9a4ca93657bada9646486e0a9532b21d4f53f8d23847188e0b156d66c105054d9a0f2745be4be89b3c9b0244e8e52bc593abd8757a96
|
data/common.rb
CHANGED
@@ -2,9 +2,9 @@ def download_if_needed path
|
|
2
2
|
require "open-uri"
|
3
3
|
require "digest"
|
4
4
|
FileUtils.mkdir_p File.dirname path
|
5
|
-
|
5
|
+
URI("http://gems.nakilon.pro.storage.yandexcloud.net/dhash-vips/#{File.basename path}".tap do |url|
|
6
6
|
puts "downloading #{path} from #{url}"
|
7
|
-
end) do |link|
|
7
|
+
end).open do |link|
|
8
8
|
File.open(path, "wb"){ |file| IO.copy_stream link, file }
|
9
9
|
end unless File.exist?(path) && Digest::MD5.file(path) == File.basename(path, File.extname(path))
|
10
10
|
path
|
data/dhash-vips.gemspec
CHANGED
data/extconf.rb
CHANGED
@@ -24,11 +24,12 @@ end
|
|
24
24
|
|
25
25
|
__END__
|
26
26
|
|
27
|
-
to test: $ rake clean && rake install
|
28
|
-
|
29
27
|
# this unlike using rake is building to current directory
|
30
28
|
# that is vital to be able to require the native extention for benchmarking, etc.
|
31
29
|
$ ruby extconf.rb && make clean && make
|
30
|
+
|
31
|
+
# to test: $ rake clean && rake install
|
32
|
+
|
32
33
|
$ ruby -e "require 'dhash-vips'; p DHashVips::IDHash.method(:distance3).source_location" # using -r makes bundler mad
|
33
34
|
# [".../dhash-vips.rb", 32] # if LoadError
|
34
35
|
# [".../dhash-vips.rb", 52] # if native (or 42 with Ruby<2.4)
|
data/lib/dhash-vips.rb
CHANGED
@@ -3,6 +3,10 @@ Vips.vector_set false
|
|
3
3
|
|
4
4
|
module DHashVips
|
5
5
|
|
6
|
+
def self.bw image
|
7
|
+
(image.has_alpha? ? image.flatten(background: 255) : image).colourspace("b-w")[0]
|
8
|
+
end
|
9
|
+
|
6
10
|
module DHash
|
7
11
|
extend self
|
8
12
|
|
@@ -11,12 +15,11 @@ module DHashVips
|
|
11
15
|
end
|
12
16
|
|
13
17
|
def pixelate input, hash_size
|
14
|
-
|
18
|
+
DHashVips.bw( if input.is_a? Vips::Image
|
15
19
|
input.thumbnail_image(hash_size + 1, height: hash_size, size: :force)
|
16
20
|
else
|
17
21
|
Vips::Image.thumbnail(input, hash_size + 1, height: hash_size, size: :force)
|
18
|
-
end
|
19
|
-
(image.has_alpha? ? image.flatten : image).colourspace("b-w")[0]
|
22
|
+
end )
|
20
23
|
end
|
21
24
|
|
22
25
|
def calculate file, hash_size = 8
|
@@ -34,7 +37,9 @@ module DHashVips
|
|
34
37
|
begin
|
35
38
|
require_relative "../idhash.#{Gem::Platform.local.os == "darwin" ? "bundle" : "o"}"
|
36
39
|
rescue LoadError
|
37
|
-
|
40
|
+
class << self
|
41
|
+
alias distance3 distance3_ruby
|
42
|
+
end
|
38
43
|
else
|
39
44
|
# we can't just do `defined? Bignum` because it's defined but deprecated (some internal CONST_DEPRECATED flag)
|
40
45
|
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.4")
|
@@ -98,7 +103,7 @@ module DHashVips
|
|
98
103
|
else
|
99
104
|
Vips::Image.thumbnail(input, size, height: size, size: :force)
|
100
105
|
end
|
101
|
-
array = (image
|
106
|
+
array = DHashVips.bw(image).to_enum.map &:flatten
|
102
107
|
d1, i1, d2, i2 = [array, array.transpose].flat_map do |a|
|
103
108
|
d = a.zip(a.rotate(1)).flat_map{ |r1, r2| r1.zip(r2).map{ |i, j| i - j } }
|
104
109
|
m = median d.map(&:abs).sort
|
data/test.rb
CHANGED
@@ -5,63 +5,9 @@ require_relative "lib/dhash-vips"
|
|
5
5
|
# TODO tests about `fingerprint(4)`
|
6
6
|
|
7
7
|
[
|
8
|
-
[DHashVips::DHash, :hamming, :calculate, 2, 23,
|
9
|
-
|
10
|
-
#
|
11
|
-
# [[0, 14, 26, 27, 31, 27, 32, 28, 43, 43, 34, 37, 37, 34, 35, 42],
|
12
|
-
# [14, 0, 28, 25, 39, 35, 32, 32, 43, 43, 38, 41, 41, 38, 37, 50],
|
13
|
-
# [26, 28, 0, 13, 35, 41, 28, 30, 41, 41, 36, 33, 35, 32, 27, 36],
|
14
|
-
# [27, 25, 13, 0, 36, 36, 31, 35, 40, 40, 33, 32, 42, 35, 26, 33],
|
15
|
-
# [31, 39, 35, 36, 0, 16, 33, 33, 40, 40, 31, 24, 28, 33, 40, 31],
|
16
|
-
# [27, 35, 41, 36, 16, 0, 41, 41, 38, 38, 23, 26, 24, 29, 34, 27],
|
17
|
-
# [32, 32, 28, 31, 33, 41, 0, 10, 27, 25, 38, 35, 37, 32, 23, 34],
|
18
|
-
# [28, 32, 30, 35, 33, 41, 10, 0, 27, 27, 34, 31, 37, 36, 27, 34],
|
19
|
-
# [43, 43, 41, 40, 40, 38, 27, 27, 0, 2, 35, 34, 30, 31, 28, 27],
|
20
|
-
# [43, 43, 41, 40, 40, 38, 25, 27, 2, 0, 35, 34, 30, 31, 28, 27],
|
21
|
-
# [34, 38, 36, 33, 31, 23, 38, 34, 35, 35, 0, 9, 23, 26, 29, 18],
|
22
|
-
# [37, 41, 33, 32, 24, 26, 35, 31, 34, 34, 9, 0, 22, 25, 30, 19],
|
23
|
-
# [37, 41, 35, 42, 28, 24, 37, 37, 30, 30, 23, 22, 0, 19, 26, 23],
|
24
|
-
# [34, 38, 32, 35, 33, 29, 32, 36, 31, 31, 26, 25, 19, 0, 21, 26],
|
25
|
-
# [35, 37, 27, 26, 40, 34, 23, 27, 28, 28, 29, 30, 26, 21, 0, 23],
|
26
|
-
# [42, 50, 36, 33, 31, 27, 34, 34, 27, 27, 18, 19, 23, 26, 23, 0]]
|
27
|
-
|
28
|
-
# vips-8.11.3-Wed Aug 11 09:29:27 UTC 2021
|
29
|
-
# [[0, 17, 25, 30, 30, 26, 35, 30, 42, 42, 35, 32, 36, 32, 34, 42],
|
30
|
-
# [17, 0, 28, 27, 39, 35, 32, 29, 43, 43, 38, 39, 43, 37, 37, 49],
|
31
|
-
# [25, 28, 0, 13, 35, 41, 28, 29, 41, 41, 38, 35, 33, 31, 27, 37],
|
32
|
-
# [30, 27, 13, 0, 36, 36, 31, 34, 38, 38, 35, 32, 40, 34, 26, 32],
|
33
|
-
# [30, 39, 35, 36, 0, 16, 35, 34, 40, 40, 31, 26, 28, 34, 40, 30],
|
34
|
-
# [26, 35, 41, 36, 16, 0, 41, 44, 38, 38, 23, 28, 26, 30, 34, 24],
|
35
|
-
# [35, 32, 28, 31, 35, 41, 0, 11, 27, 27, 38, 35, 33, 33, 21, 35],
|
36
|
-
# [30, 29, 29, 34, 34, 44, 11, 0, 28, 28, 37, 32, 36, 40, 30, 38],
|
37
|
-
# [42, 43, 41, 38, 40, 38, 27, 28, 0, 0, 33, 34, 30, 32, 28, 30],
|
38
|
-
# [42, 43, 41, 38, 40, 38, 27, 28, 0, 0, 33, 34, 30, 32, 28, 30],
|
39
|
-
# [35, 38, 38, 35, 31, 23, 38, 37, 33, 33, 0, 11, 23, 27, 31, 17],
|
40
|
-
# [32, 39, 35, 32, 26, 28, 35, 32, 34, 34, 11, 0, 24, 26, 30, 20],
|
41
|
-
# [36, 43, 33, 40, 28, 26, 33, 36, 30, 30, 23, 24, 0, 20, 26, 22],
|
42
|
-
# [32, 37, 31, 34, 34, 30, 33, 40, 32, 32, 27, 26, 20, 0, 20, 26],
|
43
|
-
# [34, 37, 27, 26, 40, 34, 21, 30, 28, 28, 31, 30, 26, 20, 0, 24],
|
44
|
-
# [42, 49, 37, 32, 30, 24, 35, 38, 30, 30, 17, 20, 22, 26, 24, 0]]
|
45
|
-
|
46
|
-
# v0.1.2.0
|
47
|
-
# [[0, 18, 25, 27, 28, 25, 33, 31, 39, 40, 33, 35, 32, 28, 36, 47],
|
48
|
-
# [18, 0, 31, 25, 34, 33, 33, 33, 39, 38, 37, 43, 40, 36, 40, 53],
|
49
|
-
# [25, 31, 0, 16, 31, 38, 26, 32, 42, 41, 36, 38, 31, 31, 31, 32],
|
50
|
-
# [27, 25, 16, 0, 35, 36, 26, 32, 38, 37, 34, 34, 41, 37, 27, 34],
|
51
|
-
# [28, 34, 31, 35, 0, 17, 39, 37, 41, 44, 31, 27, 26, 32, 32, 33],
|
52
|
-
# [25, 33, 38, 36, 17, 0, 46, 40, 38, 39, 24, 28, 25, 31, 25, 30],
|
53
|
-
# [33, 33, 26, 26, 39, 46, 0, 10, 26, 25, 34, 32, 31, 35, 33, 30],
|
54
|
-
# [31, 33, 32, 32, 37, 40, 10, 0, 26, 27, 34, 32, 33, 33, 33, 34],
|
55
|
-
# [39, 39, 42, 38, 41, 38, 26, 26, 0, 3, 36, 34, 35, 33, 37, 28],
|
56
|
-
# [40, 38, 41, 37, 44, 39, 25, 27, 3, 0, 35, 35, 36, 36, 36, 27],
|
57
|
-
# [33, 37, 36, 34, 31, 24, 34, 34, 36, 35, 0, 10, 23, 31, 23, 22],
|
58
|
-
# [35, 43, 38, 34, 27, 28, 32, 32, 34, 35, 10, 0, 23, 29, 23, 20],
|
59
|
-
# [32, 40, 31, 41, 26, 25, 31, 33, 35, 36, 23, 23, 0, 20, 24, 21],
|
60
|
-
# [28, 36, 31, 37, 32, 31, 35, 33, 33, 36, 31, 29, 20, 0, 20, 25],
|
61
|
-
# [36, 40, 31, 27, 32, 25, 33, 33, 37, 36, 23, 23, 24, 20, 0, 17],
|
62
|
-
# [47, 53, 32, 34, 33, 30, 30, 34, 28, 27, 22, 20, 21, 25, 17, 0]]
|
63
|
-
|
64
|
-
# v0.2.0.0
|
8
|
+
[DHashVips::DHash, :hamming, :calculate, 2, 23, 16, 50, 7, 0x7919395919191919],
|
9
|
+
|
10
|
+
# v0.2.3.0
|
65
11
|
# [[0, 18, 26, 28, 28, 24, 35, 31, 42, 42, 32, 34, 33, 29, 35, 40],
|
66
12
|
# [18, 0, 30, 24, 38, 34, 33, 33, 44, 42, 38, 42, 41, 37, 37, 50],
|
67
13
|
# [26, 30, 0, 16, 34, 38, 29, 35, 42, 40, 36, 38, 31, 31, 31, 36],
|
@@ -79,89 +25,40 @@ require_relative "lib/dhash-vips"
|
|
79
25
|
# [35, 37, 31, 27, 35, 29, 28, 28, 31, 31, 25, 25, 24, 22, 0, 23],
|
80
26
|
# [40, 50, 36, 34, 28, 28, 31, 33, 28, 28, 18, 16, 19, 27, 23, 0]]
|
81
27
|
|
82
|
-
[DHashVips::IDHash, :distance, :fingerprint, 8,
|
83
|
-
|
84
|
-
#
|
85
|
-
# [[0,
|
86
|
-
# [
|
87
|
-
# [
|
88
|
-
# [
|
89
|
-
# [57,
|
90
|
-
# [
|
91
|
-
# [
|
92
|
-
# [
|
93
|
-
# [
|
94
|
-
# [
|
95
|
-
# [
|
96
|
-
# [
|
97
|
-
# [60, 62, 51, 50, 35,
|
98
|
-
# [
|
99
|
-
# [
|
100
|
-
# [
|
101
|
-
|
102
|
-
|
103
|
-
# [[0, 17, 30, 35, 55, 46, 51, 54, 48, 46, 57, 48, 59, 52, 49, 54],
|
104
|
-
# [17, 0, 30, 37, 57, 46, 54, 55, 46, 49, 60, 50, 61, 54, 51, 58],
|
105
|
-
# [30, 30, 0, 12, 46, 57, 47, 42, 66, 59, 44, 37, 49, 44, 48, 49],
|
106
|
-
# [35, 37, 12, 0, 54, 67, 44, 41, 58, 53, 48, 41, 56, 42, 46, 48],
|
107
|
-
# [55, 57, 46, 54, 0, 23, 45, 43, 65, 63, 48, 48, 34, 42, 48, 47],
|
108
|
-
# [46, 46, 57, 67, 23, 0, 57, 56, 51, 50, 42, 48, 37, 38, 46, 40],
|
109
|
-
# [51, 54, 47, 44, 45, 57, 0, 6, 33, 34, 49, 43, 49, 41, 45, 47],
|
110
|
-
# [54, 55, 42, 41, 43, 56, 6, 0, 40, 39, 51, 50, 49, 40, 44, 44],
|
111
|
-
# [48, 46, 66, 58, 65, 51, 33, 40, 0, 10, 47, 53, 48, 46, 40, 46],
|
112
|
-
# [46, 49, 59, 53, 63, 50, 34, 39, 10, 0, 50, 57, 50, 49, 40, 43],
|
113
|
-
# [57, 60, 44, 48, 48, 42, 49, 51, 47, 50, 0, 9, 33, 32, 40, 23],
|
114
|
-
# [48, 50, 37, 41, 48, 48, 43, 50, 53, 57, 9, 0, 28, 27, 38, 28],
|
115
|
-
# [59, 61, 49, 56, 34, 37, 49, 49, 48, 50, 33, 28, 0, 21, 24, 27],
|
116
|
-
# [52, 54, 44, 42, 42, 38, 41, 40, 46, 49, 32, 27, 21, 0, 36, 35],
|
117
|
-
# [49, 51, 48, 46, 48, 46, 45, 44, 40, 40, 40, 38, 24, 36, 0, 21],
|
118
|
-
# [54, 58, 49, 48, 47, 40, 47, 44, 46, 43, 23, 28, 27, 35, 21, 0]]
|
119
|
-
|
120
|
-
# v0.1.2.0
|
121
|
-
# [[0, 17, 34, 40, 53, 43, 53, 52, 47, 47, 56, 44, 54, 51, 47, 57],
|
122
|
-
# [17, 0, 35, 33, 56, 45, 56, 52, 48, 49, 58, 49, 64, 57, 53, 58],
|
123
|
-
# [34, 35, 0, 8, 51, 57, 45, 40, 57, 54, 47, 40, 49, 47, 47, 48],
|
124
|
-
# [40, 33, 8, 0, 56, 62, 44, 40, 53, 47, 50, 41, 53, 41, 42, 47],
|
125
|
-
# [53, 56, 51, 56, 0, 21, 41, 48, 72, 65, 46, 47, 36, 43, 43, 43],
|
126
|
-
# [43, 45, 57, 62, 21, 0, 54, 56, 61, 60, 41, 47, 38, 39, 43, 39],
|
127
|
-
# [53, 56, 45, 44, 41, 54, 0, 12, 39, 40, 47, 44, 44, 38, 48, 41],
|
128
|
-
# [52, 52, 40, 40, 48, 56, 12, 0, 35, 36, 51, 50, 47, 39, 41, 43],
|
129
|
-
# [47, 48, 57, 53, 72, 61, 39, 35, 0, 11, 53, 53, 57, 48, 42, 51],
|
130
|
-
# [47, 49, 54, 47, 65, 60, 40, 36, 11, 0, 50, 54, 51, 49, 45, 47],
|
131
|
-
# [56, 58, 47, 50, 46, 41, 47, 51, 53, 50, 0, 13, 32, 36, 38, 23],
|
132
|
-
# [44, 49, 40, 41, 47, 47, 44, 50, 53, 54, 13, 0, 28, 30, 35, 27],
|
133
|
-
# [54, 64, 49, 53, 36, 38, 44, 47, 57, 51, 32, 28, 0, 21, 24, 28],
|
134
|
-
# [51, 57, 47, 41, 43, 39, 38, 39, 48, 49, 36, 30, 21, 0, 31, 35],
|
135
|
-
# [47, 53, 47, 42, 43, 43, 48, 41, 42, 45, 38, 35, 24, 31, 0, 19],
|
136
|
-
# [57, 58, 48, 47, 43, 39, 41, 43, 51, 47, 23, 27, 28, 35, 19, 0]]
|
137
|
-
|
138
|
-
# v0.2.0.0
|
139
|
-
# [[0, 17, 34, 40, 53, 43, 53, 52, 47, 47, 56, 44, 54, 51, 47, 57],
|
140
|
-
# [17, 0, 35, 33, 56, 45, 56, 52, 48, 49, 58, 49, 64, 57, 53, 58],
|
141
|
-
# [34, 35, 0, 8, 51, 57, 45, 40, 57, 54, 47, 40, 49, 47, 47, 48],
|
142
|
-
# [40, 33, 8, 0, 56, 62, 44, 40, 53, 47, 50, 41, 53, 41, 42, 47],
|
143
|
-
# [53, 56, 51, 56, 0, 21, 41, 48, 72, 65, 46, 47, 36, 43, 43, 43],
|
144
|
-
# [43, 45, 57, 62, 21, 0, 54, 56, 61, 60, 41, 47, 38, 39, 43, 39],
|
145
|
-
# [53, 56, 45, 44, 41, 54, 0, 12, 39, 40, 47, 44, 44, 38, 48, 41],
|
146
|
-
# [52, 52, 40, 40, 48, 56, 12, 0, 35, 36, 51, 50, 47, 39, 41, 43],
|
147
|
-
# [47, 48, 57, 53, 72, 61, 39, 35, 0, 11, 53, 53, 57, 48, 42, 51],
|
148
|
-
# [47, 49, 54, 47, 65, 60, 40, 36, 11, 0, 50, 54, 51, 49, 45, 47],
|
149
|
-
# [56, 58, 47, 50, 46, 41, 47, 51, 53, 50, 0, 13, 32, 36, 38, 23],
|
150
|
-
# [44, 49, 40, 41, 47, 47, 44, 50, 53, 54, 13, 0, 28, 30, 35, 27],
|
151
|
-
# [54, 64, 49, 53, 36, 38, 44, 47, 57, 51, 32, 28, 0, 21, 24, 28],
|
152
|
-
# [51, 57, 47, 41, 43, 39, 38, 39, 48, 49, 36, 30, 21, 0, 31, 35],
|
153
|
-
# [47, 53, 47, 42, 43, 43, 48, 41, 42, 45, 38, 35, 24, 31, 0, 19],
|
154
|
-
# [57, 58, 48, 47, 43, 39, 41, 43, 51, 47, 23, 27, 28, 35, 19, 0]]
|
155
|
-
|
156
|
-
].each do |lib, dm, calc, min_similar, max_similar, min_not_similar, max_not_similar, bw_exceptional|
|
28
|
+
[DHashVips::IDHash, :distance, :fingerprint, 8, 22, 25, 70, 0, 0x1d5cdc0d1d0c1d9f5720a6fff2fe02013f00df9f005e1dc0ff670000ffff0080],
|
29
|
+
|
30
|
+
# v0.2.3.0
|
31
|
+
# [[0, 19, 34, 38, 57, 47, 50, 49, 45, 42, 55, 45, 60, 49, 51, 53],
|
32
|
+
# [19, 0, 34, 33, 55, 47, 52, 49, 46, 49, 59, 46, 62, 54, 50, 57],
|
33
|
+
# [34, 34, 0, 8, 48, 55, 46, 42, 55, 57, 45, 35, 51, 45, 46, 47],
|
34
|
+
# [38, 33, 8, 0, 52, 61, 43, 38, 49, 50, 50, 37, 50, 39, 43, 51],
|
35
|
+
# [57, 55, 48, 52, 0, 22, 46, 42, 70, 63, 51, 50, 35, 41, 46, 46],
|
36
|
+
# [47, 47, 55, 61, 22, 0, 54, 54, 57, 53, 39, 44, 43, 41, 45, 38],
|
37
|
+
# [50, 52, 46, 43, 46, 54, 0, 8, 35, 38, 51, 45, 50, 42, 43, 43],
|
38
|
+
# [49, 49, 42, 38, 42, 54, 8, 0, 34, 36, 54, 49, 49, 42, 43, 44],
|
39
|
+
# [45, 46, 55, 49, 70, 57, 35, 34, 0, 10, 53, 55, 56, 50, 49, 49],
|
40
|
+
# [42, 49, 57, 50, 63, 53, 38, 36, 10, 0, 50, 52, 55, 48, 46, 45],
|
41
|
+
# [55, 59, 45, 50, 51, 39, 51, 54, 53, 50, 0, 10, 32, 35, 40, 25],
|
42
|
+
# [45, 46, 35, 37, 50, 44, 45, 49, 55, 52, 10, 0, 30, 27, 37, 26],
|
43
|
+
# [60, 62, 51, 50, 35, 43, 50, 49, 56, 55, 32, 30, 0, 22, 26, 28],
|
44
|
+
# [49, 54, 45, 39, 41, 41, 42, 42, 50, 48, 35, 27, 22, 0, 37, 35],
|
45
|
+
# [51, 50, 46, 43, 46, 45, 43, 43, 49, 46, 40, 37, 26, 37, 0, 22],
|
46
|
+
# [53, 57, 47, 51, 46, 38, 43, 44, 49, 45, 25, 26, 28, 35, 22, 0]]
|
47
|
+
|
48
|
+
].each do |lib, dm, calc, min_similar, max_similar, min_not_similar, max_not_similar, bw_exceptional, hash|
|
157
49
|
|
158
50
|
describe lib do
|
51
|
+
require "fileutils"
|
52
|
+
require "digest"
|
53
|
+
require "mll"
|
54
|
+
|
55
|
+
require_relative "common"
|
159
56
|
|
160
57
|
# these are false positive by idhash
|
161
|
-
# 6d97739b4a08f965dc9239dd24382e96.jpg
|
162
58
|
# 1b1d4bde376084011d027bba1c047a4b.jpg
|
59
|
+
# 6d97739b4a08f965dc9239dd24382e96.jpg
|
163
60
|
[
|
164
|
-
[ %w{
|
61
|
+
[:similar, %w{
|
165
62
|
1d468d064d2e26b5b5de9a0241ef2d4b.jpg 92d90b8977f813af803c78107e7f698e.jpg
|
166
63
|
309666c7b45ecbf8f13e85a0bd6b0a4c.jpg 3f9f3db06db20d1d9f8188cd753f6ef4.jpg
|
167
64
|
679634ff89a31279a39f03e278bc9a01.jpg df0a3b93e9412536ee8a11255f974141.jpg
|
@@ -170,48 +67,60 @@ require_relative "lib/dhash-vips"
|
|
170
67
|
21cd9a6986d98976b6b4655e1de7baf4.jpg 9b158c0d4953d47171a22ed84917f812.jpg
|
171
68
|
9c2c240ec02356472fb532f404d28dde.jpg fc762fa286489d8afc80adc8cdcb125e.jpg
|
172
69
|
7a833d873f8d49f12882e86af1cc6b79.jpg ac033cf01a3941dd1baa876082938bc9.jpg
|
173
|
-
}, min_similar, max_similar], # slightly silimar images
|
174
|
-
[ %w{
|
70
|
+
}, min_similar, max_similar, min_not_similar, max_not_similar], # slightly silimar images
|
71
|
+
[:bw_exceptional, %w{
|
175
72
|
71662d4d4029a3b41d47d5baf681ab9a.jpg ad8a37f872956666c3077a3e9e737984.jpg
|
176
73
|
}, bw_exceptional, bw_exceptional], # these are the same photo but of different size and colorspace
|
177
|
-
].each do |_images, min, max|
|
178
|
-
|
179
|
-
require "fileutils"
|
180
|
-
require "digest"
|
181
|
-
require "mll"
|
74
|
+
].each do |test_name, _images, min, max, min_not, max_not|
|
182
75
|
|
183
|
-
require_relative "common"
|
184
76
|
images = _images.map{ |_| download_if_needed "test_images/#{_}" }
|
185
77
|
|
186
78
|
hashes = images.map &lib.method(calc)
|
187
79
|
table = MLL::table[lib.method(dm), [hashes], [hashes]]
|
188
80
|
|
189
|
-
|
190
|
-
|
191
|
-
PP.pp table, STDERR
|
192
|
-
STDERR.puts ""
|
81
|
+
# STDERR.puts ""
|
82
|
+
# require "pp"
|
83
|
+
# PP.pp table, STDERR
|
84
|
+
# STDERR.puts ""
|
193
85
|
|
194
|
-
|
195
|
-
|
86
|
+
it test_name do
|
87
|
+
similar = []
|
88
|
+
not_similar = []
|
89
|
+
hashes.size.times.to_a.repeated_combination(2) do |i, j|
|
196
90
|
case
|
197
91
|
when i == j
|
198
92
|
assert_predicate table[i][j], :zero?
|
199
93
|
when (j - i).abs == 1 && (i + j - 1) % 4 == 0
|
200
94
|
# STDERR.puts [table[i][j], min, max].inspect
|
201
|
-
|
95
|
+
similar.push table[i][j]
|
202
96
|
else
|
203
97
|
# STDERR.puts [table[i][j], min_not_similar, max_not_similar].inspect
|
204
|
-
|
98
|
+
not_similar.push table[i][j]
|
205
99
|
end
|
206
100
|
end
|
101
|
+
assert_equal [min, max], similar.minmax
|
102
|
+
assert_equal [min_not, max_not], not_similar.minmax if min_not
|
207
103
|
end
|
208
104
|
|
209
105
|
end
|
210
106
|
|
211
107
|
it "accepts Vips::Image" do
|
108
|
+
# https://github.com/libvips/ruby-vips/issues/349
|
212
109
|
lib.public_send calc, Vips::Image.new_from_buffer("GIF89a\x01\x00\x01\x00\x80\x01\x00\xFF\xFF\xFF\x00\x00\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;", "")
|
213
110
|
end
|
214
111
|
|
112
|
+
it "correct calculation" do
|
113
|
+
download_if_needed "alpha_only.png"
|
114
|
+
t = lib.public_send calc, "alpha_only.png"
|
115
|
+
assert_equal hash, t, ->{ "0x#{hash.to_s 16} != 0x#{t.to_s 16}" }
|
116
|
+
end
|
117
|
+
|
215
118
|
end
|
216
119
|
|
217
120
|
end
|
121
|
+
|
122
|
+
describe DHashVips::IDHash do
|
123
|
+
it "does not call distance3_ruby" do
|
124
|
+
assert_equal :distance3, DHashVips::IDHash.method(:distance3).original_name
|
125
|
+
end
|
126
|
+
end
|
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.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-vips
|
@@ -71,8 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: '0'
|
73
73
|
requirements: []
|
74
|
-
|
75
|
-
rubygems_version: 2.5.2.3
|
74
|
+
rubygems_version: 3.3.25
|
76
75
|
signing_key:
|
77
76
|
specification_version: 4
|
78
77
|
summary: dHash and IDHash perceptual image hashing/fingerprinting
|