dhash-vips 0.2.1.0 → 0.2.3.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/common.rb +2 -2
- data/dhash-vips.gemspec +1 -1
- data/extconf.rb +3 -2
- data/lib/dhash-vips.rb +8 -8
- data/test.rb +46 -145
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
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
|
@@ -35,10 +38,7 @@ module DHashVips
|
|
35
38
|
require_relative "../idhash.#{Gem::Platform.local.os == "darwin" ? "bundle" : "o"}"
|
36
39
|
rescue LoadError
|
37
40
|
class << self
|
38
|
-
|
39
|
-
def distance3 a, b
|
40
|
-
distance3_ruby a, b
|
41
|
-
end
|
41
|
+
alias distance3 distance3_ruby
|
42
42
|
end
|
43
43
|
else
|
44
44
|
# we can't just do `defined? Bignum` because it's defined but deprecated (some internal CONST_DEPRECATED flag)
|
@@ -103,7 +103,7 @@ module DHashVips
|
|
103
103
|
else
|
104
104
|
Vips::Image.thumbnail(input, size, height: size, size: :force)
|
105
105
|
end
|
106
|
-
array = (image
|
106
|
+
array = DHashVips.bw(image).to_enum.map &:flatten
|
107
107
|
d1, i1, d2, i2 = [array, array.transpose].flat_map do |a|
|
108
108
|
d = a.zip(a.rotate(1)).flat_map{ |r1, r2| r1.zip(r2).map{ |i, j| i - j } }
|
109
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,92 +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
|
159
51
|
require "fileutils"
|
160
52
|
require "digest"
|
161
53
|
require "mll"
|
162
54
|
|
55
|
+
require_relative "common"
|
56
|
+
|
163
57
|
# these are false positive by idhash
|
164
|
-
# 6d97739b4a08f965dc9239dd24382e96.jpg
|
165
58
|
# 1b1d4bde376084011d027bba1c047a4b.jpg
|
59
|
+
# 6d97739b4a08f965dc9239dd24382e96.jpg
|
166
60
|
[
|
167
|
-
[ %w{
|
61
|
+
[:similar, %w{
|
168
62
|
1d468d064d2e26b5b5de9a0241ef2d4b.jpg 92d90b8977f813af803c78107e7f698e.jpg
|
169
63
|
309666c7b45ecbf8f13e85a0bd6b0a4c.jpg 3f9f3db06db20d1d9f8188cd753f6ef4.jpg
|
170
64
|
679634ff89a31279a39f03e278bc9a01.jpg df0a3b93e9412536ee8a11255f974141.jpg
|
@@ -173,13 +67,12 @@ require_relative "lib/dhash-vips"
|
|
173
67
|
21cd9a6986d98976b6b4655e1de7baf4.jpg 9b158c0d4953d47171a22ed84917f812.jpg
|
174
68
|
9c2c240ec02356472fb532f404d28dde.jpg fc762fa286489d8afc80adc8cdcb125e.jpg
|
175
69
|
7a833d873f8d49f12882e86af1cc6b79.jpg ac033cf01a3941dd1baa876082938bc9.jpg
|
176
|
-
}, min_similar, max_similar], # slightly silimar images
|
177
|
-
[ %w{
|
70
|
+
}, min_similar, max_similar, min_not_similar, max_not_similar], # slightly silimar images
|
71
|
+
[:bw_exceptional, %w{
|
178
72
|
71662d4d4029a3b41d47d5baf681ab9a.jpg ad8a37f872956666c3077a3e9e737984.jpg
|
179
73
|
}, bw_exceptional, bw_exceptional], # these are the same photo but of different size and colorspace
|
180
|
-
].each do |_images, min, max|
|
74
|
+
].each do |test_name, _images, min, max, min_not, max_not|
|
181
75
|
|
182
|
-
require_relative "common"
|
183
76
|
images = _images.map{ |_| download_if_needed "test_images/#{_}" }
|
184
77
|
|
185
78
|
hashes = images.map &lib.method(calc)
|
@@ -190,19 +83,23 @@ require_relative "lib/dhash-vips"
|
|
190
83
|
# PP.pp table, STDERR
|
191
84
|
# STDERR.puts ""
|
192
85
|
|
193
|
-
|
194
|
-
|
86
|
+
it test_name do
|
87
|
+
similar = []
|
88
|
+
not_similar = []
|
89
|
+
hashes.size.times.to_a.repeated_combination(2) do |i, j|
|
195
90
|
case
|
196
91
|
when i == j
|
197
92
|
assert_predicate table[i][j], :zero?
|
198
93
|
when (j - i).abs == 1 && (i + j - 1) % 4 == 0
|
199
94
|
# STDERR.puts [table[i][j], min, max].inspect
|
200
|
-
|
95
|
+
similar.push table[i][j]
|
201
96
|
else
|
202
97
|
# STDERR.puts [table[i][j], min_not_similar, max_not_similar].inspect
|
203
|
-
|
98
|
+
not_similar.push table[i][j]
|
204
99
|
end
|
205
100
|
end
|
101
|
+
assert_equal [min, max], similar.minmax
|
102
|
+
assert_equal [min_not, max_not], not_similar.minmax if min_not
|
206
103
|
end
|
207
104
|
|
208
105
|
end
|
@@ -212,14 +109,18 @@ require_relative "lib/dhash-vips"
|
|
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
|
218
121
|
|
219
122
|
describe DHashVips::IDHash do
|
220
123
|
it "does not call distance3_ruby" do
|
221
|
-
DHashVips::IDHash.
|
222
|
-
assert_equal 0, DHashVips::IDHash.distance3((2<<256)-1, (2<<256)-1)
|
223
|
-
end
|
124
|
+
assert_equal :distance3, DHashVips::IDHash.method(:distance3).original_name
|
224
125
|
end
|
225
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-12-
|
11
|
+
date: 2022-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-vips
|