ruby-vips 2.1.1 → 2.1.2

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
  SHA256:
3
- metadata.gz: c77f69e33910d95f8f678cff9787066e2af91cd889f24ec3834dcfaf78ee5cfc
4
- data.tar.gz: 140effde4d987fff3e293034b0967245aa4f914ba603d8bce41010d0ec1a63ba
3
+ metadata.gz: 267111867f885404762f693512589879bf5f1a47ef0711e368aa6bf57acdb78d
4
+ data.tar.gz: 80b65db37293a9054f508a786f841fbce6f5638cd9e237cba68074cdf3455420
5
5
  SHA512:
6
- metadata.gz: 28b7309c3a0744b29c5d100b898aab3521cc07a17667d4041db3d5194db537336bdda578e25fddb79be929c0ac32a246fb47f08862c5273fc94c2e390cc5874c
7
- data.tar.gz: d428e645d302329a9544819a188b7b010f1e265086a064cd2480dc5213d61a9ef78b0da5381a6f8bd85754ac5c8f2ce6f253701afb27e3180e157d1e807294d3
6
+ metadata.gz: 62c7552e7372e35005cc2212d05471c30194511a06065c658aca6b63b5a1bdfe7b3fecece9231b533d274956981bc65e61c7fc5d4d3bc64268e723f10425c80c
7
+ data.tar.gz: a908583f08ed891280aaf94aa57275b04038b831027954298f7a8cb98e85c90bc3f61fb276e89f159bb874404022b015b3144e899f6c41170ed9ae082bc97903
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## Version 2.1.2 (2021-5-3)
6
+
7
+ * allow `FFI::Pointer` as an argument to `new_from_memory` etc. [sled]
8
+
5
9
  ## Version 2.1.1 (2021-5-3)
6
10
 
7
11
  * fix "mutate" with libvips 8.9 [jcupitt]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.1
1
+ 2.1.2
data/lib/vips/image.rb CHANGED
@@ -78,6 +78,11 @@ module Vips
78
78
  class Image < Vips::Object
79
79
  alias_method :parent_get_typeof, :get_typeof
80
80
 
81
+ # FFI sets a pointer's size to this magic value if the size of the memory
82
+ # chunk the pointer points to is unknown to FFI.
83
+ UNKNOWN_POINTER_SIZE = FFI::Pointer.new(1).size
84
+ private_constant :UNKNOWN_POINTER_SIZE
85
+
81
86
  private
82
87
 
83
88
  # the layout of the VipsImage struct
@@ -326,6 +331,24 @@ module Vips
326
331
  # image.width, image.height, image.bands, image.format
327
332
  # ```
328
333
  #
334
+ # Creating a new image from a memory pointer:
335
+ #
336
+ # ```
337
+ # ptr = FFI::MemoryPointer.new(:uchar, 10*10)
338
+ # # => #<FFI::MemoryPointer address=0x00007fc236db31d0 size=100>
339
+ # x = Vips::Image.new_from_memory(ptr, 10, 10, 1, :uchar)
340
+ # ```
341
+ #
342
+ # Creating a new image from an address only pointer:
343
+ #
344
+ # ```
345
+ # ptr = call_to_external_c_library(w: 10, h: 10)
346
+ # # => #<FFI::Pointer address=0x00007f9780813a00>
347
+ # ptr_slice = ptr.slice(0, 10*10)
348
+ # # => #<FFI::Pointer address=0x00007f9780813a00 size=100>
349
+ # x = Vips::Image.new_from_memory(ptr_slice, 10, 10, 1, :uchar)
350
+ # ```
351
+ #
329
352
  # {new_from_memory} keeps a reference to the array of pixels you pass in
330
353
  # to try to prevent that memory from being freed by the Ruby GC while it
331
354
  # is being used.
@@ -340,13 +363,23 @@ module Vips
340
363
  # @param format [Symbol] band format
341
364
  # @return [Image] the loaded image
342
365
  def self.new_from_memory data, width, height, bands, format
343
- size = data.bytesize
344
-
345
366
  # prevent data from being freed with JRuby FFI
346
367
  if defined?(JRUBY_VERSION) && !data.is_a?(FFI::Pointer)
347
368
  data = ::FFI::MemoryPointer.new(:char, data.bytesize).write_bytes data
348
369
  end
349
370
 
371
+ if data.is_a?(FFI::Pointer)
372
+ # A pointer needs to know about the size of the memory it points to.
373
+ # If you have an address-only pointer, use the .slice method to wrap
374
+ # the pointer in a size aware pointer.
375
+ if data.size == UNKNOWN_POINTER_SIZE
376
+ raise Vips::Error, "size of memory is unknown"
377
+ end
378
+ size = data.size
379
+ else
380
+ size = data.bytesize
381
+ end
382
+
350
383
  format_number = GObject::GValue.from_nick BAND_FORMAT_TYPE, format
351
384
  vi = Vips.vips_image_new_from_memory data, size,
352
385
  width, height, bands, format_number
@@ -373,7 +406,17 @@ module Vips
373
406
  # @return [Image] the loaded image
374
407
  def self.new_from_memory_copy data, width, height, bands, format
375
408
  format_number = GObject::GValue.from_nick BAND_FORMAT_TYPE, format
376
- vi = Vips.vips_image_new_from_memory_copy data, data.bytesize,
409
+
410
+ if data.is_a?(FFI::Pointer)
411
+ if data.size == UNKNOWN_POINTER_SIZE
412
+ raise Vips::Error, "size of memory is unknown"
413
+ end
414
+ size = data.size
415
+ else
416
+ size = data.bytesize
417
+ end
418
+
419
+ vi = Vips.vips_image_new_from_memory_copy data, size,
377
420
  width, height, bands, format_number
378
421
  raise Vips::Error if vi.null?
379
422
  new(vi)
data/lib/vips/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vips
2
- VERSION = "2.1.1"
2
+ VERSION = "2.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-vips
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Cupitt