ruby-vips 2.0.5 → 2.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38b222b12b892a0cfbd9532a25e977c14e20ca4b
4
- data.tar.gz: f21db53783fb278d10c03293b3e356a9b22c5bed
3
+ metadata.gz: 977fd4194df253aca0b38025de9dcf563e9050fb
4
+ data.tar.gz: 6f675830bc3809d3e9b73656607ebc688d8e2cb8
5
5
  SHA512:
6
- metadata.gz: fad99e35598db1433300247d531d4fa6d2fbe82b47ce0ee7d5a9fe1224f28833d83832774db52a8b50de91b65f51e98410eaad7dda55fb76eb1757daa7e3372c
7
- data.tar.gz: 784a0f8a3e8b4fcea5688b5c72e8b92d8901ea6ce8aa2c3d3453a660c14815871e008ad010333475748ce88b8102ab9b80e8ff308b0631a82ee8b59fe85e6a8b
6
+ metadata.gz: ee2eed6adc45832a11c316b136076df8b6a0d7032b9d96cde61ef2fbd21829022e84f8a9b290df432bd36369914f58d92e2edb4c136f3f96fe4d1c1aeb5ec636
7
+ data.tar.gz: dc22e1b1fdec424250c77f7a08953d5a77c085e116ee875f29cbba8f71d98b1649199f5c7b6d41bb7fa8aef101be187fec55683d3df43d0b19e358e8e04b2bcc
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## Version 2.0.6 (2017-09-02)
6
+
7
+ * improve get() behaviour on error with older libvipses
8
+
5
9
  ## Version 2.0.5 (2017-09-02)
6
10
 
7
11
  * fix get() with older libvipses
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.5
1
+ 2.0.6
data/example/wobble.rb CHANGED
@@ -8,8 +8,8 @@ module Vips
8
8
  class Image
9
9
  def wobble
10
10
  # this makes an image where pixel (0, 0) (at the top-left) has
11
- # value [0, 0], and pixel (image.width, image.height) at the
12
- # bottom-right has value [image.width, image.height]
11
+ # value [0, 0], and pixel (image.width - 1, image.height - 1) at the
12
+ # bottom-right has value [image.width - 1, image.height - 1]
13
13
  index = Vips::Image.xyz width, height
14
14
 
15
15
  # make a version with (0, 0) at the centre, negative values up
data/lib/vips.rb CHANGED
@@ -546,6 +546,14 @@ module Vips
546
546
  attach_function :version, :vips_version, [:int], :int
547
547
  attach_function :version_string, :vips_version_string, [], :string
548
548
 
549
+ # True if this is at least libvips x.y
550
+ def self.at_least_libvips?(x, y)
551
+ major = version(0)
552
+ minor = version(1)
553
+
554
+ major > x or (major == x and minor >= y)
555
+ end
556
+
549
557
  LIBRARY_VERSION = Vips::version_string
550
558
 
551
559
  end
data/lib/vips/image.rb CHANGED
@@ -51,6 +51,8 @@ module Vips
51
51
  # for an introduction to using this class.
52
52
 
53
53
  class Image < Vips::Object
54
+ alias_method :parent_get_typeof, :get_typeof
55
+
54
56
  private
55
57
 
56
58
  # the layout of the VipsImage struct
@@ -473,19 +475,14 @@ module Vips
473
475
  # @param name [String] Metadata field to fetch
474
476
  # @return [Integer] GType
475
477
  def get_typeof name
476
- # libvips 8.5+ has a fast path for this
477
- if Vips::version(0) > 8 or Vips::version(1) > 4
478
- Vips::vips_image_get_typeof self, name
479
- else
480
- # with older libvips, we have to look in properties first, then
481
- # fall back to metadata
482
- gtype = get_typeof_property name
483
- if gtype != 0
484
- gtype
485
- else
486
- Vips::vips_image_get_typeof self, name
487
- end
478
+ # on libvips before 8.5, property types must be searched first,
479
+ # since vips_image_get_typeof returned built-in enums as int
480
+ if not Vips::at_least_libvips?(8, 5)
481
+ gtype = parent_get_typeof name
482
+ return gtype if gtype != 0
488
483
  end
484
+
485
+ Vips::vips_image_get_typeof self, name
489
486
  end
490
487
 
491
488
  # Get a metadata item from an image. Ruby types are constructed
@@ -504,19 +501,13 @@ module Vips
504
501
  def get name
505
502
  # with old libvips, we must fetch properties (as opposed to
506
503
  # metadata) via VipsObject
507
- unless Vips::version(0) > 8 or Vips::version(1) > 4
508
- gtype = get_typeof_property name
509
- if gtype != 0
510
- # found a property
511
- return super
512
- end
504
+ if not Vips::at_least_libvips?(8, 5)
505
+ return super if parent_get_typeof(name) != 0
513
506
  end
514
507
 
515
508
  gvalue = GObject::GValue.alloc
516
509
  result = Vips::vips_image_get self, name, gvalue
517
- if result != 0
518
- raise Vips::Error
519
- end
510
+ raise Vips::Error if result != 0
520
511
 
521
512
  return gvalue.get
522
513
  end
@@ -527,9 +518,7 @@ module Vips
527
518
  # @return [[String]] array of field names
528
519
  def get_fields
529
520
  # vips_image_get_fields() was added in libvips 8.5
530
- if not Vips.respond_to? :vips_image_get_fields
531
- return []
532
- end
521
+ return [] if not Vips.respond_to? :vips_image_get_fields
533
522
 
534
523
  array = Vips::vips_image_get_fields self
535
524
 
data/lib/vips/object.rb CHANGED
@@ -108,24 +108,41 @@ module Vips
108
108
 
109
109
  end
110
110
 
111
- def get_typeof_property name
111
+ # return a pspec, or nil ... nil wil leave a message in the error log
112
+ # which you must clear
113
+ def get_pspec name
112
114
  pspec = GObject::GParamSpecPtr.new
113
115
  argument_class = Vips::ArgumentClassPtr.new
114
116
  argument_instance = Vips::ArgumentInstancePtr.new
115
117
 
116
118
  result = Vips::vips_object_get_argument self, name,
117
119
  pspec, argument_class, argument_instance
118
- return 0 if result != 0
120
+ return nil if result != 0
121
+
122
+ pspec
123
+ end
124
+
125
+ # return a gtype, raise an error on not found
126
+ def get_typeof_error name
127
+ pspec = get_pspec name
128
+ raise Vips::Error if not pspec
119
129
 
120
130
  pspec[:value][:value_type]
121
131
  end
122
132
 
133
+ # return a gtype, 0 on not found
123
134
  def get_typeof name
124
- get_typeof_property name
135
+ pspec = get_pspec name
136
+ if not pspec
137
+ Vips::vips_error_clear
138
+ return 0
139
+ end
140
+
141
+ pspec[:value][:value_type]
125
142
  end
126
143
 
127
144
  def get name
128
- gtype = get_typeof_property name
145
+ gtype = get_typeof_error name
129
146
  gvalue = GObject::GValue.alloc
130
147
  gvalue.init gtype
131
148
  GObject::g_object_get_property self, name, gvalue
@@ -139,7 +156,7 @@ module Vips
139
156
  def set name, value
140
157
  GLib::logger.debug("Vips::Object.set") {"#{name} = #{value}"}
141
158
 
142
- gtype = get_typeof_property name
159
+ gtype = get_typeof_error name
143
160
  gvalue = GObject::GValue.alloc
144
161
  gvalue.init gtype
145
162
  gvalue.set value
data/lib/vips/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Vips
2
- VERSION = "2.0.5"
2
+ VERSION = "2.0.6"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-vips
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ version: 2.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Cupitt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-02 00:00:00.000000000 Z
11
+ date: 2017-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi