ruby-vips 2.0.15 → 2.1.2

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +42 -0
  3. data/.github/workflows/test.yml +80 -0
  4. data/.standard.yml +17 -0
  5. data/.yardopts +0 -1
  6. data/CHANGELOG.md +39 -0
  7. data/Gemfile +3 -1
  8. data/README.md +42 -41
  9. data/Rakefile +13 -21
  10. data/TODO +14 -14
  11. data/VERSION +1 -1
  12. data/example/annotate.rb +6 -6
  13. data/example/connection.rb +26 -0
  14. data/example/daltonize8.rb +6 -6
  15. data/example/draw_lines.rb +30 -0
  16. data/example/example1.rb +4 -4
  17. data/example/example2.rb +6 -6
  18. data/example/example3.rb +5 -5
  19. data/example/example4.rb +2 -2
  20. data/example/example5.rb +4 -4
  21. data/example/inheritance_with_refcount.rb +35 -36
  22. data/example/progress.rb +30 -0
  23. data/example/thumb.rb +6 -6
  24. data/example/trim8.rb +1 -1
  25. data/example/watermark.rb +2 -2
  26. data/example/wobble.rb +1 -1
  27. data/lib/ruby-vips.rb +1 -1
  28. data/lib/vips.rb +191 -79
  29. data/lib/vips/blend_mode.rb +29 -25
  30. data/lib/vips/connection.rb +46 -0
  31. data/lib/vips/gobject.rb +27 -12
  32. data/lib/vips/gvalue.rb +62 -50
  33. data/lib/vips/image.rb +475 -256
  34. data/lib/vips/interpolate.rb +3 -2
  35. data/lib/vips/methods.rb +788 -121
  36. data/lib/vips/mutableimage.rb +173 -0
  37. data/lib/vips/object.rb +171 -54
  38. data/lib/vips/operation.rb +272 -117
  39. data/lib/vips/region.rb +73 -0
  40. data/lib/vips/source.rb +88 -0
  41. data/lib/vips/sourcecustom.rb +89 -0
  42. data/lib/vips/target.rb +86 -0
  43. data/lib/vips/targetcustom.rb +77 -0
  44. data/lib/vips/version.rb +1 -1
  45. data/ruby-vips.gemspec +26 -20
  46. metadata +39 -50
  47. data/.rubocop.yml +0 -22
  48. data/.rubocop_todo.yml +0 -515
  49. data/.travis.yml +0 -62
  50. data/install-vips.sh +0 -26
data/example/annotate.rb CHANGED
@@ -1,17 +1,17 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- require 'vips'
3
+ require "vips"
4
4
 
5
- im = Vips::Image.new_from_file ARGV[0], :access => :sequential
5
+ im = Vips::Image.new_from_file ARGV[0], access: :sequential
6
6
 
7
- left_text = Vips::Image.text "left corner", :dpi => 300
7
+ left_text = Vips::Image.text "left corner", dpi: 300
8
8
  left = left_text.embed 50, 50, im.width, 150
9
9
 
10
- right_text = Vips::Image.text "right corner", :dpi => 300
10
+ right_text = Vips::Image.text "right corner", dpi: 300
11
11
  right = right_text.embed im.width - right_text.width - 50, 50, im.width, 150
12
12
 
13
- footer = (left | right).ifthenelse(0, [255, 0, 0], :blend => true)
13
+ footer = (left | right).ifthenelse(0, [255, 0, 0], blend: true)
14
14
 
15
- im = im.insert footer, 0, im.height, :expand => true
15
+ im = im.insert footer, 0, im.height, expand: true
16
16
 
17
17
  im.write_to_file ARGV[1]
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require "vips"
4
+ require "down/http"
5
+
6
+ # byte_source = File.open ARGV[0], "rb"
7
+ # eg. https://images.unsplash.com/photo-1491933382434-500287f9b54b
8
+ byte_source = Down::Http.open(ARGV[0])
9
+
10
+ source = Vips::SourceCustom.new
11
+ source.on_read do |length|
12
+ puts "reading #{length} bytes ..."
13
+ byte_source.read length
14
+ end
15
+ source.on_seek do |offset, whence|
16
+ puts "seeking to #{offset}, #{whence}"
17
+ byte_source.seek(offset, whence)
18
+ end
19
+
20
+ byte_target = File.open ARGV[1], "wb"
21
+ target = Vips::TargetCustom.new
22
+ target.on_write { |chunk| byte_target.write(chunk) }
23
+ target.on_finish { byte_target.close }
24
+
25
+ image = Vips::Image.new_from_source source, "", access: :sequential
26
+ image.write_to_target target, ".jpg"
@@ -7,7 +7,7 @@
7
7
  # http://libvips.blogspot.co.uk/2013/05/daltonize-in-ruby-vips-carrierwave-and.html
8
8
  # for a discussion of this code
9
9
 
10
- require 'vips'
10
+ require "vips"
11
11
 
12
12
  # Vips.set_debug true
13
13
 
@@ -29,13 +29,13 @@ im = Vips::Image.new_from_file ARGV[0]
29
29
  alpha = nil
30
30
  if im.bands == 4
31
31
  alpha = im[3]
32
- im = im.extract_band 0, :n => 3
32
+ im = im.extract_band 0, n: 3
33
33
  end
34
34
 
35
35
  begin
36
36
  # import to XYZ with lcms
37
37
  # if there's no profile there, we'll fall back to the thing below
38
- xyz = im.icc_import :embedded => true, :pcs => :xyz
38
+ xyz = im.icc_import embedded: true, pcs: :xyz
39
39
  rescue Vips::Error
40
40
  # nope .. use the built-in converter instead
41
41
  xyz = im.colourspace :xyz
@@ -61,9 +61,9 @@ rgb = xyz.colourspace :srgb
61
61
  err = im - rgb
62
62
 
63
63
  # add the error back to other channels to make a compensated image
64
- im = im + err.recomb([[0, 0, 0],
65
- [0.7, 1, 0],
66
- [0.7, 0, 1]])
64
+ im += err.recomb([[0, 0, 0],
65
+ [0.7, 1, 0],
66
+ [0.7, 0, 1]])
67
67
 
68
68
  # reattach any alpha we saved above
69
69
  if alpha
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require "vips"
4
+
5
+ # load and stream into memory
6
+ image = Vips::Image.new_from_file(ARGV[0], access: :sequential).copy_memory
7
+
8
+ starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
9
+
10
+ lines = image
11
+ (0..1).step 0.01 do |i|
12
+ lines = lines.draw_line 255, lines.width * i, 0, 0, lines.height * (1 - i)
13
+ end
14
+
15
+ ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
16
+ puts "non-destructive took #{ending - starting}s"
17
+
18
+ starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
19
+
20
+ lines = image
21
+ lines = lines.mutate do |x|
22
+ (0..1).step 0.01 do |i|
23
+ x.draw_line! 255, x.width * i, 0, 0, x.height * (1 - i)
24
+ end
25
+ end
26
+
27
+ ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
28
+ puts "mutate took #{ending - starting}s"
29
+
30
+ lines.write_to_file ARGV[1]
data/example/example1.rb CHANGED
@@ -1,9 +1,9 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/ruby
2
2
 
3
- require 'logger'
4
- require 'vips'
3
+ require "logger"
4
+ require "vips"
5
5
 
6
- GLib::logger.level = Logger::DEBUG
6
+ GLib.logger.level = Logger::DEBUG
7
7
 
8
8
  Vips::Operation.new "black"
9
9
 
data/example/example2.rb CHANGED
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- require 'logger'
4
- require 'vips'
3
+ require "logger"
4
+ require "vips"
5
5
 
6
6
  puts ""
7
7
  puts "starting up:"
8
8
 
9
9
  # this makes vips keep a list of all active objects which we can print out
10
- Vips::leak_set true
10
+ Vips.leak_set true
11
11
 
12
12
  # disable the operation cache
13
- Vips::cache_set_max 0
13
+ Vips.cache_set_max 0
14
14
 
15
15
  # GLib::logger.level = Logger::DEBUG
16
16
 
@@ -20,7 +20,7 @@ n.times do |i|
20
20
  puts ""
21
21
  puts "call #{i} ..."
22
22
  out = Vips::Operation.call "black", [200, 300]
23
- if out.width != 200 or out.height != 300
23
+ if out.width != 200 || out.height != 300
24
24
  puts "bad image result from black"
25
25
  end
26
26
  end
@@ -28,7 +28,7 @@ end
28
28
  puts ""
29
29
  puts "after #{n} calls:"
30
30
  GC.start
31
- Vips::Object::print_all
31
+ Vips::Object.print_all
32
32
 
33
33
  puts ""
34
34
  puts "shutting down:"
data/example/example3.rb CHANGED
@@ -1,19 +1,19 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- require 'vips'
3
+ require "vips"
4
4
 
5
5
  # this makes vips keep a list of all active objects
6
- Vips::leak_set true
6
+ Vips.leak_set true
7
7
 
8
8
  # disable the operation cache
9
9
  # Vips::cache_set_max 0
10
10
 
11
11
  # turn on debug logging
12
- GLib::logger.level = Logger::DEBUG
12
+ GLib.logger.level = Logger::DEBUG
13
13
 
14
- 1.times do |i|
14
+ 10.times do |i|
15
15
  puts "loop #{i} ..."
16
16
  im = Vips::Image.new_from_file ARGV[0]
17
- im = im.embed 100, 100, 3000, 3000, :extend => :mirror
17
+ im = im.embed 100, 100, 3000, 3000, extend: :mirror
18
18
  im.write_to_file "x.v"
19
19
  end
data/example/example4.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- require 'vips'
3
+ require "vips"
4
4
 
5
5
  # this makes vips keep a list of all active objects
6
- Vips::leak_set true
6
+ Vips.leak_set true
7
7
 
8
8
  # disable the operation cache
9
9
  # Vips::cache_set_max 0
data/example/example5.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- require 'vips'
3
+ require "vips"
4
4
 
5
5
  # this makes vips keep a list of all active objects
6
6
  # Vips::leak_set true
@@ -15,7 +15,7 @@ if ARGV.length < 2
15
15
  raise "usage: #{$PROGRAM_NAME}: input-file output-file"
16
16
  end
17
17
 
18
- im = Vips::Image.new_from_file ARGV[0], :access => :sequential
18
+ im = Vips::Image.new_from_file ARGV[0], access: :sequential
19
19
 
20
20
  im *= [1, 2, 1]
21
21
 
@@ -23,8 +23,8 @@ im *= [1, 2, 1]
23
23
  # make it ourselves
24
24
  # if you are OK with scale=1, you can just pass the array directly to .conv()
25
25
  mask = Vips::Image.new_from_array [[-1, -1, -1],
26
- [-1, 16, -1],
27
- [-1, -1, -1]], 8
26
+ [-1, 16, -1],
27
+ [-1, -1, -1]], 8
28
28
  im = im.conv mask
29
29
 
30
30
  im.write_to_file ARGV[1]
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- require 'ffi'
4
- require 'forwardable'
3
+ require "ffi"
4
+ require "forwardable"
5
5
 
6
6
  # this is really very crude logging
7
7
 
@@ -29,7 +29,7 @@ end
29
29
 
30
30
  module GLib
31
31
  extend FFI::Library
32
- ffi_lib 'gobject-2.0'
32
+ ffi_lib "gobject-2.0"
33
33
 
34
34
  def self.set_log_domain(_domain)
35
35
  # FIXME: this needs hooking up
@@ -68,8 +68,8 @@ module GLib
68
68
  def self.included(base)
69
69
  base.class_eval do
70
70
  layout :g_type_instance, :pointer,
71
- :ref_count, :uint,
72
- :qdata, :pointer
71
+ :ref_count, :uint,
72
+ :qdata, :pointer
73
73
  end
74
74
  end
75
75
  end
@@ -85,7 +85,7 @@ module GLib
85
85
 
86
86
  def self.release(ptr)
87
87
  log "GLib::GObject::ManagedStruct.release: unreffing #{ptr}"
88
- GLib::g_object_unref(ptr) unless ptr.null?
88
+ GLib.g_object_unref(ptr) unless ptr.null?
89
89
  end
90
90
  end
91
91
 
@@ -116,7 +116,7 @@ module GLib
116
116
 
117
117
  class << self
118
118
  def ffi_struct
119
- self.const_get(:Struct)
119
+ const_get(:Struct)
120
120
  end
121
121
  end
122
122
 
@@ -127,7 +127,7 @@ module GLib
127
127
 
128
128
  class << self
129
129
  def ffi_managed_struct
130
- self.const_get(:ManagedStruct)
130
+ const_get(:ManagedStruct)
131
131
  end
132
132
  end
133
133
  end
@@ -138,10 +138,10 @@ end
138
138
 
139
139
  module Vips
140
140
  extend FFI::Library
141
- ffi_lib 'vips'
141
+ ffi_lib "vips"
142
142
 
143
143
  LOG_DOMAIN = "VIPS"
144
- GLib::set_log_domain(LOG_DOMAIN)
144
+ GLib.set_log_domain(LOG_DOMAIN)
145
145
 
146
146
  # need to repeat this
147
147
  typedef :ulong, :GType
@@ -153,19 +153,19 @@ module Vips
153
153
  attach_function :vips_error_clear, [], :void
154
154
 
155
155
  def self.get_error
156
- errstr = Vips::vips_error_buffer
157
- Vips::vips_error_clear
156
+ errstr = Vips.vips_error_buffer
157
+ Vips.vips_error_clear
158
158
  errstr
159
159
  end
160
160
 
161
- if Vips::vips_init($0) != 0
162
- puts Vips::get_error
161
+ if Vips.vips_init($0) != 0
162
+ puts Vips.get_error
163
163
  exit 1
164
164
  end
165
165
 
166
- at_exit {
167
- Vips::vips_shutdown
168
- }
166
+ at_exit do
167
+ Vips.vips_shutdown
168
+ end
169
169
 
170
170
  attach_function :vips_object_print_all, [], :void
171
171
  attach_function :vips_leak_set, [:int], :void
@@ -188,15 +188,15 @@ module Vips
188
188
  base.class_eval do
189
189
  # don't actually need most of these, remove them later
190
190
  layout :parent, GLib::GObject::Struct,
191
- :constructed, :int,
192
- :static_object, :int,
193
- :argument_table, :pointer,
194
- :nickname, :string,
195
- :description, :string,
196
- :preclose, :int,
197
- :close, :int,
198
- :postclose, :int,
199
- :local_memory, :size_t
191
+ :constructed, :int,
192
+ :static_object, :int,
193
+ :argument_table, :pointer,
194
+ :nickname, :string,
195
+ :description, :string,
196
+ :preclose, :int,
197
+ :close, :int,
198
+ :postclose, :int,
199
+ :local_memory, :size_t
200
200
  end
201
201
  end
202
202
  end
@@ -250,7 +250,7 @@ module Vips
250
250
  end
251
251
 
252
252
  def self.new_partial
253
- VipsImage.new(Vips::vips_image_new)
253
+ VipsImage.new(Vips.vips_image_new)
254
254
  end
255
255
  end
256
256
 
@@ -258,12 +258,11 @@ module Vips
258
258
  end
259
259
 
260
260
  puts "creating image"
261
- begin
262
- x = Vips::VipsImage.new_partial
263
- puts "x = #{x}"
264
- puts ""
265
- puts "x[:parent] = #{x[:parent]}"
266
- puts ""
267
- puts "x[:parent][:description] = #{x[:parent][:description]}"
268
- puts ""
269
- end
261
+
262
+ x = Vips::VipsImage.new_partial
263
+ puts "x = #{x}"
264
+ puts ""
265
+ puts "x[:parent] = #{x[:parent]}"
266
+ puts ""
267
+ puts "x[:parent][:description] = #{x[:parent][:description]}"
268
+ puts ""
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require "vips"
4
+
5
+ image = Vips::Image.black 1, 100000
6
+ image.set_progress true
7
+
8
+ def progress_to_s(name, progress)
9
+ puts "#{name}:"
10
+ puts " progress.run = #{progress[:run]}"
11
+ puts " progress.eta = #{progress[:eta]}"
12
+ puts " progress.tpels = #{progress[:tpels]}"
13
+ puts " progress.npels = #{progress[:npels]}"
14
+ puts " progress.percent = #{progress[:percent]}"
15
+ end
16
+
17
+ image.signal_connect :preeval do |progress|
18
+ progress_to_s("preeval", progress)
19
+ end
20
+
21
+ image.signal_connect :eval do |progress|
22
+ progress_to_s("eval", progress)
23
+ image.set_kill(true) if progress[:percent] > 50
24
+ end
25
+
26
+ image.signal_connect :posteval do |progress|
27
+ progress_to_s("posteval", progress)
28
+ end
29
+
30
+ image.avg
data/example/thumb.rb CHANGED
@@ -1,25 +1,25 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/ruby
2
2
 
3
3
  # batch-process a lot of files
4
4
  #
5
5
  # this should run in constant memory -- if it doesn't, something has broken
6
6
 
7
- require 'vips'
7
+ require "vips"
8
8
 
9
9
  # benchmark thumbnail via a memory buffer
10
10
  def via_memory(filename, thumbnail_width)
11
11
  data = IO.binread(filename)
12
12
 
13
- thumb = Vips::Image.thumbnail_buffer data, thumbnail_width, crop: 'centre'
13
+ thumb = Vips::Image.thumbnail_buffer data, thumbnail_width, crop: "centre"
14
14
 
15
- thumb.write_to_buffer '.jpg'
15
+ thumb.write_to_buffer ".jpg"
16
16
  end
17
17
 
18
18
  # benchmark thumbnail via files
19
19
  def via_files(filename, thumbnail_width)
20
- thumb = Vips::Image.thumbnail filename, thumbnail_width, crop: 'centre'
20
+ thumb = Vips::Image.thumbnail filename, thumbnail_width, crop: "centre"
21
21
 
22
- thumb.write_to_buffer '.jpg'
22
+ thumb.write_to_buffer ".jpg"
23
23
  end
24
24
 
25
25
  ARGV.each do |filename|