vips 8.8.0.3 → 8.8.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,6 @@
6
6
  require 'ffi'
7
7
 
8
8
  module GObject
9
-
10
9
  # Represent a GValue. Example use:
11
10
  #
12
11
  # ```ruby
@@ -134,7 +133,7 @@ module GObject
134
133
  ptr.write_array_of_pointer value
135
134
 
136
135
  # the gvalue needs a ref on each of the images
137
- value.each {|image| ::GObject::g_object_ref image}
136
+ value.each { |image| ::GObject::g_object_ref image }
138
137
 
139
138
  when Vips::BLOB_TYPE
140
139
  len = value.bytesize
@@ -156,8 +155,7 @@ module GObject
156
155
 
157
156
  else
158
157
  raise Vips::Error, "unimplemented gtype for set: " +
159
- "#{::GObject::g_type_name gtype} (#{gtype})"
160
-
158
+ "#{::GObject::g_type_name gtype} (#{gtype})"
161
159
  end
162
160
  end
163
161
  end
@@ -233,8 +231,7 @@ module GObject
233
231
 
234
232
  else
235
233
  raise Vips::Error, "unimplemented gtype for get: " +
236
- "#{::GObject::g_type_name gtype} (#{gtype})"
237
-
234
+ "#{::GObject::g_type_name gtype} (#{gtype})"
238
235
  end
239
236
  end
240
237
 
@@ -243,9 +240,7 @@ module GObject
243
240
  # }
244
241
 
245
242
  return result
246
-
247
243
  end
248
-
249
244
  end
250
245
 
251
246
  attach_function :g_value_init, [GValue.ptr, :GType], :void
@@ -277,5 +272,4 @@ module GObject
277
272
  [:pointer, :string, GValue.ptr], :void
278
273
  attach_function :g_object_get_property,
279
274
  [:pointer, :string, GValue.ptr], :void
280
-
281
275
  end
@@ -81,12 +81,10 @@ module Vips
81
81
 
82
82
  class Struct < Vips::Object::Struct
83
83
  include ImageLayout
84
-
85
84
  end
86
85
 
87
86
  class ManagedStruct < Vips::Object::ManagedStruct
88
87
  include ImageLayout
89
-
90
88
  end
91
89
 
92
90
  class GenericPtr < FFI::Struct
@@ -96,7 +94,7 @@ module Vips
96
94
  # handy for overloads ... want to be able to apply a function to an
97
95
  # array or to a scalar
98
96
  def self.smap x, &block
99
- x.is_a?(Array) ? x.map {|y| smap(y, &block)} : block.(x)
97
+ x.is_a?(Array) ? x.map { |y| smap(y, &block) } : block.(x)
100
98
  end
101
99
 
102
100
  def self.complex? format
@@ -178,15 +176,15 @@ module Vips
178
176
  public
179
177
 
180
178
  def inspect
181
- "#<Image #{width}x#{height} #{format}, #{bands} bands, " +
182
- "#{interpretation}>"
179
+ "#<Image #{width}x#{height} #{format}, #{bands} bands, #{interpretation}>"
183
180
  end
184
181
 
185
182
  def respond_to? name, include_all = false
186
183
  # To support keyword args, we need to tell Ruby that final image
187
184
  # arguments cannot be hashes of keywords.
188
185
  #
189
- # https://makandracards.com/makandra/36013-heads-up-ruby-implicitly-converts-a-hash-to-keyword-arguments
186
+ # https://makandracards.com/makandra/
187
+ # 36013-heads-up-ruby-implicitly-converts-a-hash-to-keyword-arguments
190
188
  return false if name == :to_hash
191
189
 
192
190
  # respond to all vips operations by nickname
@@ -347,19 +345,20 @@ module Vips
347
345
  if array[0].is_a? Array
348
346
  height = array.length
349
347
  width = array[0].length
350
- unless array.all? {|x| x.is_a? Array}
348
+ unless array.all? { |x| x.is_a? Array }
351
349
  raise Vips::Error, "Not a 2D array."
352
350
  end
353
- unless array.all? {|x| x.length == width}
351
+ unless array.all? { |x| x.length == width }
354
352
  raise Vips::Error, "Array not rectangular."
355
353
  end
354
+
356
355
  array = array.flatten
357
356
  else
358
357
  height = 1
359
358
  width = array.length
360
359
  end
361
360
 
362
- unless array.all? {|x| x.is_a? Numeric}
361
+ unless array.all? { |x| x.is_a? Numeric }
363
362
  raise Vips::Error, "Not all array elements are Numeric."
364
363
  end
365
364
 
@@ -385,8 +384,8 @@ module Vips
385
384
  def new_from_image value
386
385
  pixel = (Vips::Image.black(1, 1) + value).cast(format)
387
386
  image = pixel.embed 0, 0, width, height, extend: :copy
388
- image.copy interpretation: interpretation,
389
- xres: xres, yres: yres, xoffset: xoffset, yoffset: yoffset
387
+ image.copy interpretation: interpretation, xres: xres, yres: yres,
388
+ xoffset: xoffset, yoffset: yoffset
390
389
  end
391
390
 
392
391
  # Write this image to a file. Save options may be encoded in the
@@ -457,10 +456,8 @@ module Vips
457
456
  # @macro vips.saveopts
458
457
  # @return [String] the image saved in the specified format
459
458
  def write_to_buffer format_string, **opts
460
- filename =
461
- Vips::p2str(Vips::vips_filename_get_filename format_string)
462
- option_string =
463
- Vips::p2str(Vips::vips_filename_get_options format_string)
459
+ filename = Vips::p2str(Vips::vips_filename_get_filename format_string)
460
+ option_string = Vips::p2str(Vips::vips_filename_get_options format_string)
464
461
  saver = Vips::vips_foreign_find_save_buffer filename
465
462
  if saver == nil
466
463
  raise Vips::Error, "No known saver for '#{filename}'."
@@ -480,6 +477,7 @@ module Vips
480
477
  def write_to_memory
481
478
  len = Vips::SizeStruct.new
482
479
  ptr = Vips::vips_image_write_to_memory self, len
480
+ raise Vips::Error if ptr == nil
483
481
 
484
482
  # wrap up as an autopointer
485
483
  ptr = FFI::AutoPointer.new(ptr, GLib::G_FREE)
@@ -772,7 +770,7 @@ module Vips
772
770
  # @return [Image] result of subtraction
773
771
  def - other
774
772
  other.is_a?(Vips::Image) ?
775
- subtract(other) : linear(1, Image::smap(other) {|x| x * -1})
773
+ subtract(other) : linear(1, Image::smap(other) { |x| x * -1 })
776
774
  end
777
775
 
778
776
  # Multiply an image, constant or array.
@@ -790,7 +788,7 @@ module Vips
790
788
  # @return [Image] result of division
791
789
  def / other
792
790
  other.is_a?(Vips::Image) ?
793
- divide(other) : linear(Image::smap(other) {|x| 1.0 / x}, 0)
791
+ divide(other) : linear(Image::smap(other) { |x| 1.0 / x }, 0)
794
792
  end
795
793
 
796
794
  # Remainder after integer division with an image, constant or array.
@@ -961,16 +959,16 @@ module Vips
961
959
 
962
960
  # make the template for unpack
963
961
  template = {
964
- :char => 'c',
965
- :uchar => 'C',
966
- :short => 's_',
967
- :ushort => 'S_',
968
- :int => 'i_',
969
- :uint => 'I_',
970
- :float => 'f',
971
- :double => 'd',
972
- :complex => 'f',
973
- :dpcomplex => 'd'
962
+ char: 'c',
963
+ uchar: 'C',
964
+ short: 's_',
965
+ ushort: 'S_',
966
+ int: 'i_',
967
+ uint: 'I_',
968
+ float: 'f',
969
+ double: 'd',
970
+ complex: 'f',
971
+ dpcomplex: 'd'
974
972
  }[format] + '*'
975
973
 
976
974
  # and unpack into something like [1, 2, 3, 4 ..]
@@ -1031,7 +1029,7 @@ module Vips
1031
1029
  #
1032
1030
  # @return [Array<Image>] Array of n one-band images
1033
1031
  def bandsplit
1034
- (0...bands).map {|i| extract_band i}
1032
+ (0...bands).map { |i| extract_band i }
1035
1033
  end
1036
1034
 
1037
1035
  # Join a set of images bandwise.
@@ -1044,7 +1042,7 @@ module Vips
1044
1042
  end
1045
1043
 
1046
1044
  # if other is just Numeric, we can use bandjoin_const
1047
- not_all_real = !other.all?{|x| x.is_a? Numeric}
1045
+ not_all_real = !other.all? { |x| x.is_a? Numeric }
1048
1046
 
1049
1047
  if not_all_real
1050
1048
  Vips::Image.bandjoin([self] + other)
@@ -1130,7 +1128,7 @@ module Vips
1130
1128
  # @see xyz
1131
1129
  # @return [Image] image converted to polar coordinates
1132
1130
  def polar
1133
- Image::run_cmplx(self) {|x| x.complex :polar}
1131
+ Image::run_cmplx(self) { |x| x.complex :polar }
1134
1132
  end
1135
1133
 
1136
1134
  # Return an image with polar pixels converted to rectangular.
@@ -1143,7 +1141,7 @@ module Vips
1143
1141
  # @see xyz
1144
1142
  # @return [Image] image converted to rectangular coordinates
1145
1143
  def rect
1146
- Image::run_cmplx(self) {|x| x.complex :rect}
1144
+ Image::run_cmplx(self) { |x| x.complex :rect }
1147
1145
  end
1148
1146
 
1149
1147
  # Return the complex conjugate of an image.
@@ -1155,7 +1153,7 @@ module Vips
1155
1153
  #
1156
1154
  # @return [Image] complex conjugate
1157
1155
  def conj
1158
- Image::run_cmplx(self) {|x| x.complex :conj}
1156
+ Image::run_cmplx(self) { |x| x.complex :conj }
1159
1157
  end
1160
1158
 
1161
1159
  # Calculate the cross phase of two images.
@@ -1305,7 +1303,7 @@ module Vips
1305
1303
  # @option opts [Boolean] :blend (false) Blend smoothly between th and el
1306
1304
  # @return [Image] merged image
1307
1305
  def ifthenelse(th, el, **opts)
1308
- match_image = [th, el, self].find {|x| x.is_a? Vips::Image}
1306
+ match_image = [th, el, self].find { |x| x.is_a? Vips::Image }
1309
1307
 
1310
1308
  unless th.is_a? Vips::Image
1311
1309
  th = Operation.imageize match_image, th
@@ -1325,12 +1323,10 @@ module Vips
1325
1323
  def scaleimage **opts
1326
1324
  Vips::Image.scale self, opts
1327
1325
  end
1328
-
1329
1326
  end
1330
1327
  end
1331
1328
 
1332
1329
  module Vips
1333
-
1334
1330
  # This method generates yard comments for all the dynamically bound
1335
1331
  # vips operations.
1336
1332
  #
@@ -1348,23 +1344,24 @@ module Vips
1348
1344
 
1349
1345
  # map gobject's type names to Ruby
1350
1346
  map_go_to_ruby = {
1351
- "gboolean" => "Boolean",
1352
- "gint" => "Integer",
1353
- "gdouble" => "Float",
1354
- "gfloat" => "Float",
1355
- "gchararray" => "String",
1356
- "VipsImage" => "Vips::Image",
1357
- "VipsInterpolate" => "Vips::Interpolate",
1358
- "VipsArrayDouble" => "Array<Double>",
1359
- "VipsArrayInt" => "Array<Integer>",
1360
- "VipsArrayImage" => "Array<Image>",
1361
- "VipsArrayString" => "Array<String>",
1347
+ "gboolean" => "Boolean",
1348
+ "gint" => "Integer",
1349
+ "gdouble" => "Float",
1350
+ "gfloat" => "Float",
1351
+ "gchararray" => "String",
1352
+ "VipsImage" => "Vips::Image",
1353
+ "VipsInterpolate" => "Vips::Interpolate",
1354
+ "VipsArrayDouble" => "Array<Double>",
1355
+ "VipsArrayInt" => "Array<Integer>",
1356
+ "VipsArrayImage" => "Array<Image>",
1357
+ "VipsArrayString" => "Array<String>",
1362
1358
  }
1363
1359
 
1364
1360
  generate_operation = lambda do |gtype, nickname, op|
1365
1361
  op_flags = op.get_flags
1366
1362
  return if (op_flags & OPERATION_DEPRECATED) != 0
1367
1363
  return if no_generate.include? nickname
1364
+
1368
1365
  description = Vips::vips_object_get_description op
1369
1366
 
1370
1367
  # find and classify all the arguments the operator can take
@@ -1373,7 +1370,7 @@ module Vips
1373
1370
  required_output = []
1374
1371
  optional_output = []
1375
1372
  member_x = nil
1376
- op.argument_map do |pspec, argument_class, argument_instance|
1373
+ op.argument_map do |pspec, argument_class, _argument_instance|
1377
1374
  arg_flags = argument_class[:flags]
1378
1375
  next if (arg_flags & ARGUMENT_CONSTRUCT) == 0
1379
1376
  next if (arg_flags & ARGUMENT_DEPRECATED) != 0
@@ -1388,15 +1385,17 @@ module Vips
1388
1385
  type_name = map_go_to_ruby[type_name]
1389
1386
  end
1390
1387
  if fundamental == GObject::GFLAGS_TYPE ||
1391
- fundamental == GObject::GENUM_TYPE
1388
+ fundamental == GObject::GENUM_TYPE
1392
1389
  type_name = "Vips::" + type_name[/Vips(.*)/, 1]
1393
1390
  end
1394
1391
  blurb = GObject::g_param_spec_get_blurb pspec
1395
- value = {:name => name,
1396
- :flags => arg_flags,
1397
- :gtype => gtype,
1398
- :type_name => type_name,
1399
- :blurb => blurb}
1392
+ value = {
1393
+ name: name,
1394
+ flags: arg_flags,
1395
+ gtype: gtype,
1396
+ type_name: type_name,
1397
+ blurb: blurb
1398
+ }
1400
1399
 
1401
1400
  if (arg_flags & ARGUMENT_INPUT) != 0
1402
1401
  if (arg_flags & ARGUMENT_REQUIRED) != 0
@@ -1414,35 +1413,33 @@ module Vips
1414
1413
 
1415
1414
  # MODIFY INPUT args count as OUTPUT as well
1416
1415
  if (arg_flags & ARGUMENT_OUTPUT) != 0 ||
1417
- ((arg_flags & ARGUMENT_INPUT) != 0 &&
1418
- (arg_flags & ARGUMENT_MODIFY) != 0)
1416
+ ((arg_flags & ARGUMENT_INPUT) != 0 &&
1417
+ (arg_flags & ARGUMENT_MODIFY) != 0)
1419
1418
  if (arg_flags & ARGUMENT_REQUIRED) != 0
1420
1419
  required_output << value
1421
1420
  else
1422
1421
  optional_output << value
1423
1422
  end
1424
1423
  end
1425
-
1426
1424
  end
1427
1425
 
1428
1426
  print "# @!method "
1429
1427
  print "self." unless member_x
1430
1428
  print "#{nickname}("
1431
- print required_input.map{|x| x[:name]}.join(", ")
1429
+ print required_input.map { |x| x[:name] }.join(", ")
1432
1430
  print ", " if required_input.length > 0
1433
1431
  puts "**opts)"
1434
1432
 
1435
1433
  puts "# #{description.capitalize}."
1436
1434
 
1437
1435
  required_input.each do |arg|
1438
- puts "# @param #{arg[:name]} [#{arg[:type_name]}] " +
1439
- "#{arg[:blurb]}"
1436
+ puts "# @param #{arg[:name]} [#{arg[:type_name]}] #{arg[:blurb]}"
1440
1437
  end
1441
1438
 
1442
1439
  puts "# @param opts [Hash] Set of options"
1443
1440
  optional_input.each do |arg|
1444
1441
  puts "# @option opts [#{arg[:type_name]}] :#{arg[:name]} " +
1445
- "#{arg[:blurb]}"
1442
+ "#{arg[:blurb]}"
1446
1443
  end
1447
1444
  optional_output.each do |arg|
1448
1445
  print "# @option opts [#{arg[:type_name]}] :#{arg[:name]}"
@@ -1454,16 +1451,16 @@ module Vips
1454
1451
  print "nil"
1455
1452
  elsif required_output.length == 1
1456
1453
  print required_output.first[:type_name]
1457
- elsif
1458
- print "Array<"
1459
- print required_output.map{|x| x[:type_name]}.join(", ")
1454
+ else
1455
+ print "Array<"
1456
+ print required_output.map { |x| x[:type_name] }.join(", ")
1460
1457
  print ">"
1461
1458
  end
1462
1459
  if optional_output.length > 0
1463
1460
  print ", Hash<Symbol => Object>"
1464
1461
  end
1465
1462
  print "] "
1466
- print required_output.map{|x| x[:blurb]}.join(", ")
1463
+ print required_output.map { |x| x[:blurb] }.join(", ")
1467
1464
  if optional_output.length > 0
1468
1465
  print ", " if required_output.length > 0
1469
1466
  print "Hash of optional output items"
@@ -1473,14 +1470,15 @@ module Vips
1473
1470
  puts ""
1474
1471
  end
1475
1472
 
1476
- generate_class = lambda do |gtype, a|
1473
+ generate_class = lambda do |gtype, _|
1477
1474
  nickname = Vips::nickname_find gtype
1478
1475
 
1479
1476
  if nickname
1480
1477
  begin
1481
1478
  # can fail for abstract types
1482
1479
  op = Vips::Operation.new nickname
1483
- rescue
1480
+ rescue Vips::Error
1481
+ nil
1484
1482
  end
1485
1483
 
1486
1484
  generate_operation.(gtype, nickname, op) if op
@@ -1498,5 +1496,4 @@ module Vips
1498
1496
  puts " end"
1499
1497
  puts "end"
1500
1498
  end
1501
-
1502
1499
  end
@@ -1,5 +1,4 @@
1
1
  module Vips
2
-
3
2
  # Pick the algorithm vips uses to decide image "interestingness". This is
4
3
  # used by {Image#smartcrop}, for example, to decide what parts of the image
5
4
  # to keep.
@@ -1,5 +1,4 @@
1
1
  module Vips
2
-
3
2
  attach_function :vips_interpolate_new, [:string], :pointer
4
3
 
5
4
  # An interpolator. One of these can be given to operations like
@@ -30,7 +29,6 @@ module Vips
30
29
  # ```
31
30
 
32
31
  class Interpolate < Vips::Object
33
-
34
32
  # the layout of the VipsInterpolate struct
35
33
  module InterpolateLayout
36
34
  def self.included base
@@ -43,12 +41,10 @@ module Vips
43
41
 
44
42
  class Struct < Vips::Object::Struct
45
43
  include InterpolateLayout
46
-
47
44
  end
48
45
 
49
46
  class ManagedStruct < Vips::Object::ManagedStruct
50
47
  include InterpolateLayout
51
-
52
48
  end
53
49
 
54
50
  def initialize name
@@ -57,6 +53,5 @@ module Vips
57
53
 
58
54
  super ptr
59
55
  end
60
-
61
56
  end
62
57
  end
@@ -1,5 +1,4 @@
1
1
  module Vips
2
-
3
2
  # How the values in an image should be interpreted. For example, a
4
3
  # three-band float image of type :lab should have its
5
4
  # pixels interpreted as coordinates in CIE Lab space.
@@ -1,5 +1,4 @@
1
1
  module Vips
2
-
3
2
  # A resizing kernel. One of these can be given to operations like
4
3
  # {Image#reduceh} or {Image#resize} to select the resizing kernel to use.
5
4
  #