dhash-vips 0.1.1.4 → 0.2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1b98ca69a92ce7e640e4497399a906ec5a3cb53
4
- data.tar.gz: 2d3dffbbd39df0448114bb1b4f7d59afb729c162
3
+ metadata.gz: ffcb306bfad9804bd8f04b0e45be41792a31c631
4
+ data.tar.gz: 83cf911d2a2768694c7500101854c1b2d60dbac7
5
5
  SHA512:
6
- metadata.gz: '081328a940448d63e396ba141f1d897c5367de1e923410dd67e8de9da8e811e83f035b1094ba2b7e81eb9ed9cf61a9c23cc1f88a19ba3cb822dabd63160f345b'
7
- data.tar.gz: 59dbcdf54db72f70dc089b1b75c5574e3e06e41ec54ccfd04d270f7fd89d498a71346e62f97cf5c7aa807915f6a88bd542261243dbbdf19d4a72b9b85af9fb9e
6
+ metadata.gz: fa5d434886611ab65c4c5c957ec4a19953681ab2ebfded077d8dd6ea18bc756083e9abd9d7b04db6aea9f1cdce4805445f045c3dc882ee2af1b63c062726dd3f
7
+ data.tar.gz: d0e444171d64f461b6cb4fde6fc23b58f7ca91e4160f05347948a88b490d2f2d9f664da4aa69ab7d375ecba8f298adb13262e66e4ba286bfa3f96a7dd971db62
data/Gemfile CHANGED
@@ -1,11 +1,12 @@
1
1
  source "https://rubygems.org"
2
- gemspec
3
2
 
4
- gem "byebug", "<11.1.0" # for Ruby 2.3
5
3
  gem "rake"
6
- gem "minitest"
7
- gem "rmagick", "~>2.16"
4
+ gem "rmagick"
5
+ gem "dhash", github: "nakilon/dhash"
8
6
  gem "phamilie"
9
- gem "dhash"
10
7
  gem "get_process_mem"
11
8
  gem "mll"
9
+ gem "minitest"
10
+ gem "byebug", "<11.1.0" # for Ruby 2.3
11
+
12
+ gemspec
data/common.rb CHANGED
@@ -1,20 +1,10 @@
1
- def download_and_keep image # returns path
2
- require "open-uri"
3
- require "digest"
4
- File.join(FileUtils.mkdir_p(File.expand_path "images", __dir__()).first, image).tap do |path|
5
- open("https://storage.googleapis.com/dhash-vips.nakilon.pro/#{image}") do |link|
6
- File.open(path, "wb") do |file|
7
- IO.copy_stream link, file
8
- end
9
- end unless File.exist?(path) && Digest::MD5.file(path) == File.basename(image, ".jpg")
10
- end
11
- end
12
-
13
1
  def download_if_needed path
14
2
  require "open-uri"
15
3
  require "digest"
16
4
  FileUtils.mkdir_p File.dirname path
17
- open("https://storage.googleapis.com/dhash-vips.nakilon.pro/#{File.basename path}") do |link|
5
+ open("http://gems.nakilon.pro.storage.yandexcloud.net/dhash-vips/#{File.basename path}".tap do |url|
6
+ puts "downloading #{path} from #{url}"
7
+ end) do |link|
18
8
  File.open(path, "wb"){ |file| IO.copy_stream link, file }
19
9
  end unless File.exist?(path) && Digest::MD5.file(path) == File.basename(path, File.extname(path))
20
10
  path
data/dhash-vips.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "dhash-vips"
3
- spec.version = "0.1.1.4"
3
+ spec.version = "0.2.0.0"
4
4
  spec.summary = "dHash and IDHash perceptual image hashing/fingerprinting"
5
5
  # spec.homepage = "https://github.com/nakilon/dhash-vips"
6
6
 
data/extconf.rb CHANGED
@@ -3,14 +3,12 @@ require "mkmf"
3
3
  File.write "Makefile", dummy_makefile(?.).join
4
4
 
5
5
  unless Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.3.8")
6
- if ENV["RBENV_ROOT"] && ENV["RBENV_VERSION"]
7
- # https://github.com/rbenv/rbenv/issues/1199
8
- if found = Dir.glob("#{ENV["RBENV_ROOT"]}/sources/#{ENV["RBENV_VERSION"]}/ruby-*/").first
9
- append_cppflags "-I#{Dir.glob("#{ENV["RBENV_ROOT"]}/sources/#{ENV["RBENV_VERSION"]}/ruby-*/").first}"
10
- end
11
- else
12
- append_cppflags "-I/ruby/"
6
+ if ruby_source_dir = if File.directory? "/ruby"
7
+ "-I/ruby" # for Github Actions: docker (currently disabled) and benchmark
8
+ elsif ENV["RBENV_ROOT"] && ENV["RBENV_VERSION"] && File.exist?(t = "#{ENV["RBENV_ROOT"]}/sources/#{ENV["RBENV_VERSION"]}/ruby-#{ENV["RBENV_VERSION"]}/bignum.c") # https://github.com/rbenv/rbenv/issues/1199
9
+ "-I#{File.dirname t}"
13
10
  end
11
+ append_cppflags ruby_source_dir
14
12
  append_cppflags "-DRUBY_EXPORT" unless Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.4")
15
13
  create_makefile "idhash"
16
14
  # Why this hack?
@@ -21,15 +19,22 @@ unless Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.3.8")
21
19
  test: all
22
20
  \t$(RUBY) -r./lib/dhash-vips.rb ./lib/dhash-vips-post-install-test.rb
23
21
  HEREDOC
22
+ end
24
23
  end
25
24
 
26
- # How to test:
27
- # $ ruby extconf.rb && make clean && make
28
- # $ bundle exec rake -rdhash-vips -e "p DHashVips::IDHash.method(:distance3).source_location"
29
- # # ["/Users/nakilon/_/dhash-vips/lib/dhash-vips.rb", 52] # or 42 with Ruby<2.4
30
- # # ["/Users/nakilon/_/dhash-vips/lib/dhash-vips.rb", 32] # if LoadError
31
- # Other cases to check:
32
- # 1. not macOS && rbenv
33
- # 2. fail during append_cppflags
34
- # 3. failed compilation
35
- # 4. failed tests
25
+ __END__
26
+
27
+ to test: $ rake clean && rake install
28
+
29
+ # this unlike using rake is building to current directory
30
+ # that is vital to be able to require the native extention for benchmarking, etc.
31
+ $ ruby extconf.rb && make clean && make
32
+ $ ruby -e "require 'dhash-vips'; p DHashVips::IDHash.method(:distance3).source_location" # using -r makes bundler mad
33
+ # [".../dhash-vips.rb", 32] # if LoadError
34
+ # [".../dhash-vips.rb", 52] # if native (or 42 with Ruby<2.4)
35
+
36
+ Other cases to check:
37
+ 1. not macOS && rbenv
38
+ 2. fail during append_cppflags
39
+ 3. failed compilation
40
+ 4. failed tests
data/lib/dhash-vips.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "vips"
2
+ Vips.vector_set false
2
3
 
3
4
  module DHashVips
4
5
 
@@ -9,27 +10,25 @@ module DHashVips
9
10
  (a ^ b).to_s(2).count "1"
10
11
  end
11
12
 
12
- def pixelate file, hash_size, kernel = nil
13
- image = Vips::Image.new_from_file file, access: :sequential
14
- if kernel
15
- image.resize((hash_size + 1).fdiv(image.width), vscale: hash_size.fdiv(image.height), kernel: kernel).colourspace("b-w")
13
+ def pixelate input, hash_size
14
+ image = if input.is_a? Vips::Image
15
+ input.thumbnail_image(hash_size + 1, height: hash_size, size: :force)
16
16
  else
17
- image.resize((hash_size + 1).fdiv(image.width), vscale: hash_size.fdiv(image.height) ).colourspace("b-w")
17
+ Vips::Image.thumbnail(input, hash_size + 1, height: hash_size, size: :force)
18
18
  end
19
+ (image.has_alpha? ? image.flatten : image).colourspace("b-w")[0]
19
20
  end
20
21
 
21
- def calculate file, hash_size = 8, kernel = nil
22
- image = pixelate file, hash_size, kernel
23
-
22
+ def calculate file, hash_size = 8
23
+ image = pixelate file, hash_size
24
24
  image.cast("int").conv([[1, -1]]).crop(1, 0, hash_size, hash_size).>(0)./(255).cast("uchar").to_a.join.to_i(2)
25
25
  end
26
26
 
27
27
  end
28
28
 
29
29
  module IDHash
30
- extend self
31
30
 
32
- def distance3_ruby a, b
31
+ def self.distance3_ruby a, b
33
32
  ((a ^ b) & (a | b) >> 128).to_s(2).count "1"
34
33
  end
35
34
  begin
@@ -39,7 +38,7 @@ module DHashVips
39
38
  else
40
39
  # we can't just do `defined? Bignum` because it's defined but deprecated (some internal CONST_DEPRECATED flag)
41
40
  if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.4")
42
- def distance3 a, b
41
+ def self.distance3 a, b
43
42
  if a.is_a?(Bignum) && b.is_a?(Bignum)
44
43
  distance3_c a, b
45
44
  else
@@ -50,7 +49,7 @@ module DHashVips
50
49
  # https://github.com/ruby/ruby/commit/de2f7416d2deb4166d78638a41037cb550d64484#diff-16b196bc6bfe8fba63951420f843cfb4R10
51
50
  require "rbconfig/sizeof"
52
51
  FIXNUM_MAX = (1 << (8 * RbConfig::SIZEOF["long"] - 2)) - 1
53
- def distance3 a, b
52
+ def self.distance3 a, b
54
53
  if a > FIXNUM_MAX && b > FIXNUM_MAX
55
54
  distance3_c a, b
56
55
  else
@@ -59,7 +58,7 @@ module DHashVips
59
58
  end
60
59
  end
61
60
  end
62
- def distance a, b
61
+ def self.distance a, b
63
62
  size_a, size_b = [a, b].map do |x|
64
63
  # TODO write a test about possible hash sizes
65
64
  # they were 32 and 128, 124, 120 for MRI 2.0
@@ -71,7 +70,7 @@ module DHashVips
71
70
  ((a ^ b) & (a | b) >> 2 * size_a * size_a).to_s(2).count "1"
72
71
  end
73
72
 
74
- @@median = lambda do |array|
73
+ def self.median array
75
74
  h = array.size / 2
76
75
  return array[h] if array[h] != array[h - 1]
77
76
  right = array.dup
@@ -81,25 +80,28 @@ module DHashVips
81
80
  return right.uniq[1] if left.count(left.last) > right.count(right.first)
82
81
  left.last
83
82
  end
84
- fail unless 2 == @@median[[1, 2, 2, 2, 2, 2, 3]]
85
- fail unless 3 == @@median[[1, 2, 2, 2, 2, 3, 3]]
86
- fail unless 3 == @@median[[1, 1, 2, 2, 3, 3, 3]]
87
- fail unless 2 == @@median[[1, 1, 1, 2, 3, 3, 3]]
88
- fail unless 2 == @@median[[1, 1, 2, 2, 2, 2, 3]]
89
- fail unless 2 == @@median[[1, 2, 2, 2, 2, 3]]
90
- fail unless 3 == @@median[[1, 2, 2, 3, 3, 3]]
91
- fail unless 1 == @@median[[1, 1, 1]]
92
- fail unless 1 == @@median[[1, 1]]
83
+ private_class_method :median
84
+ fail unless 2 == median([1, 2, 2, 2, 2, 2, 3])
85
+ fail unless 3 == median([1, 2, 2, 2, 2, 3, 3])
86
+ fail unless 3 == median([1, 1, 2, 2, 3, 3, 3])
87
+ fail unless 2 == median([1, 1, 1, 2, 3, 3, 3])
88
+ fail unless 2 == median([1, 1, 2, 2, 2, 2, 3])
89
+ fail unless 2 == median([1, 2, 2, 2, 2, 3])
90
+ fail unless 3 == median([1, 2, 2, 3, 3, 3])
91
+ fail unless 1 == median([1, 1, 1])
92
+ fail unless 1 == median([1, 1])
93
93
 
94
- def fingerprint filename, power = 3
94
+ def self.fingerprint input, power = 3
95
95
  size = 2 ** power
96
- image = Vips::Image.new_from_file filename, access: :sequential
97
- image = image.resize(size.fdiv(image.width), vscale: size.fdiv(image.height)).colourspace("b-w").flatten
98
-
99
- array = image.to_a.map &:flatten
96
+ image = if input.is_a? Vips::Image
97
+ input.thumbnail_image(size, height: size, size: :force)
98
+ else
99
+ Vips::Image.thumbnail(input, size, height: size, size: :force)
100
+ end
101
+ array = (image.has_alpha? ? image.flatten : image).flatten.colourspace("b-w")[0].to_enum.map &:flatten
100
102
  d1, i1, d2, i2 = [array, array.transpose].flat_map do |a|
101
- d = a.zip(a.rotate(1)).flat_map{ |r1, r2| r1.zip(r2).map{ |i,j| i - j } }
102
- m = @@median.call d.map(&:abs).sort
103
+ d = a.zip(a.rotate(1)).flat_map{ |r1, r2| r1.zip(r2).map{ |i, j| i - j } }
104
+ m = median d.map(&:abs).sort
103
105
  [
104
106
  d.map{ |c| c < 0 ? 1 : 0 }.join.to_i(2),
105
107
  d.map{ |c| c.abs >= m ? 1 : 0 }.join.to_i(2),
data/test.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  require "minitest/autorun"
2
2
 
3
- require "dhash-vips"
3
+ require_relative "lib/dhash-vips"
4
4
 
5
5
  # TODO tests about `fingerprint(4)`
6
6
 
7
7
  [
8
- [DHashVips::DHash, :hamming, :calculate, 2, 23, 18, 50, 4],
8
+ [DHashVips::DHash, :hamming, :calculate, 2, 23, 9, 53, 7],
9
+
9
10
  # vips-8.9.1-Tue Jan 28 13:05:46 UTC 2020
10
11
  # [[0, 14, 26, 27, 31, 27, 32, 28, 43, 43, 34, 37, 37, 34, 35, 42],
11
12
  # [14, 0, 28, 25, 39, 35, 32, 32, 43, 43, 38, 41, 41, 38, 37, 50],
@@ -23,7 +24,63 @@ require "dhash-vips"
23
24
  # [34, 38, 32, 35, 33, 29, 32, 36, 31, 31, 26, 25, 19, 0, 21, 26],
24
25
  # [35, 37, 27, 26, 40, 34, 23, 27, 28, 28, 29, 30, 26, 21, 0, 23],
25
26
  # [42, 50, 36, 33, 31, 27, 34, 34, 27, 27, 18, 19, 23, 26, 23, 0]]
26
- [DHashVips::IDHash, :distance, :fingerprint, 6, 22, 23, 65, 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
65
+ # [[0, 18, 26, 28, 28, 24, 35, 31, 42, 42, 32, 34, 33, 29, 35, 40],
66
+ # [18, 0, 30, 24, 38, 34, 33, 33, 44, 42, 38, 42, 41, 37, 37, 50],
67
+ # [26, 30, 0, 16, 34, 38, 29, 35, 42, 40, 36, 38, 31, 31, 31, 36],
68
+ # [28, 24, 16, 0, 36, 36, 31, 35, 40, 38, 34, 34, 41, 37, 27, 34],
69
+ # [28, 38, 34, 36, 0, 14, 35, 33, 40, 42, 32, 26, 27, 33, 35, 28],
70
+ # [24, 34, 38, 36, 14, 0, 43, 39, 38, 40, 24, 28, 25, 31, 29, 28],
71
+ # [35, 33, 29, 31, 35, 43, 0, 8, 27, 25, 35, 33, 32, 32, 28, 31],
72
+ # [31, 33, 35, 35, 33, 39, 8, 0, 27, 27, 35, 33, 34, 34, 28, 33],
73
+ # [42, 44, 42, 40, 40, 38, 27, 27, 0, 2, 34, 32, 31, 33, 31, 28],
74
+ # [42, 42, 40, 38, 42, 40, 25, 27, 2, 0, 34, 34, 33, 35, 31, 28],
75
+ # [32, 38, 36, 34, 32, 24, 35, 35, 34, 34, 0, 10, 23, 31, 25, 18],
76
+ # [34, 42, 38, 34, 26, 28, 33, 33, 32, 34, 10, 0, 23, 29, 25, 16],
77
+ # [33, 41, 31, 41, 27, 25, 32, 34, 31, 33, 23, 23, 0, 20, 24, 19],
78
+ # [29, 37, 31, 37, 33, 31, 32, 34, 33, 35, 31, 29, 20, 0, 22, 27],
79
+ # [35, 37, 31, 27, 35, 29, 28, 28, 31, 31, 25, 25, 24, 22, 0, 23],
80
+ # [40, 50, 36, 34, 28, 28, 31, 33, 28, 28, 18, 16, 19, 27, 23, 0]]
81
+
82
+ [DHashVips::IDHash, :distance, :fingerprint, 8, 21, 23, 72, 0],
83
+
27
84
  # vips-8.9.1-Tue Jan 28 13:05:46 UTC 2020
28
85
  # [[0, 16, 32, 35, 57, 45, 51, 50, 48, 47, 54, 48, 60, 50, 47, 56],
29
86
  # [16, 0, 30, 34, 58, 47, 55, 56, 47, 50, 57, 49, 62, 52, 52, 61],
@@ -41,6 +98,61 @@ require "dhash-vips"
41
98
  # [50, 52, 44, 40, 43, 42, 45, 45, 47, 49, 36, 30, 20, 0, 35, 39],
42
99
  # [47, 52, 49, 41, 47, 43, 44, 41, 41, 44, 38, 37, 23, 35, 0, 19],
43
100
  # [56, 61, 49, 51, 48, 42, 47, 42, 46, 43, 25, 27, 28, 39, 19, 0]]
101
+
102
+ # vips-8.11.3-Wed Aug 11 09:29:27 UTC 2021
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
+
44
156
  ].each do |lib, dm, calc, min_similar, max_similar, min_not_similar, max_not_similar, bw_exceptional|
45
157
 
46
158
  describe lib do
@@ -62,14 +174,14 @@ require "dhash-vips"
62
174
  [ %w{
63
175
  71662d4d4029a3b41d47d5baf681ab9a.jpg ad8a37f872956666c3077a3e9e737984.jpg
64
176
  }, bw_exceptional, bw_exceptional], # these are the same photo but of different size and colorspace
65
- ].each do |images, min, max|
177
+ ].each do |_images, min, max|
66
178
 
67
179
  require "fileutils"
68
180
  require "digest"
69
181
  require "mll"
70
182
 
71
183
  require_relative "common"
72
- images = images.map &method(:download_and_keep)
184
+ images = _images.map{ |_| download_if_needed "test_images/#{_}" }
73
185
 
74
186
  hashes = images.map &lib.method(calc)
75
187
  table = MLL::table[lib.method(dm), [hashes], [hashes]]
@@ -80,7 +192,7 @@ require "dhash-vips"
80
192
  STDERR.puts ""
81
193
 
82
194
  hashes.size.times.to_a.repeated_combination(2) do |i, j|
83
- it do
195
+ it "#{_images[i]} #{_images[j]}" do
84
196
  case
85
197
  when i == j
86
198
  assert_predicate table[i][j], :zero?
@@ -96,6 +208,10 @@ require "dhash-vips"
96
208
 
97
209
  end
98
210
 
211
+ it "accepts Vips::Image" do
212
+ 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
+ end
214
+
99
215
  end
100
216
 
101
217
  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.1.1.4
4
+ version: 0.2.0.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-02-21 00:00:00.000000000 Z
11
+ date: 2022-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-vips