ruby-vips 2.0.14 → 2.1.1

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 (70) 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 +41 -0
  7. data/Gemfile +3 -1
  8. data/README.md +42 -41
  9. data/Rakefile +13 -21
  10. data/TODO +18 -10
  11. data/VERSION +1 -1
  12. data/example/annotate.rb +6 -6
  13. data/example/connection.rb +26 -0
  14. data/example/daltonize8.rb +16 -18
  15. data/example/draw_lines.rb +30 -0
  16. data/example/example1.rb +5 -6
  17. data/example/example2.rb +6 -6
  18. data/example/example3.rb +5 -5
  19. data/example/example4.rb +4 -4
  20. data/example/example5.rb +6 -7
  21. data/example/inheritance_with_refcount.rb +36 -54
  22. data/example/progress.rb +30 -0
  23. data/example/thumb.rb +8 -10
  24. data/example/trim8.rb +5 -5
  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 +199 -93
  29. data/lib/vips/align.rb +0 -1
  30. data/lib/vips/angle.rb +0 -1
  31. data/lib/vips/angle45.rb +0 -1
  32. data/lib/vips/bandformat.rb +0 -2
  33. data/lib/vips/blend_mode.rb +29 -27
  34. data/lib/vips/coding.rb +0 -1
  35. data/lib/vips/compass_direction.rb +0 -1
  36. data/lib/vips/connection.rb +46 -0
  37. data/lib/vips/direction.rb +0 -1
  38. data/lib/vips/extend.rb +0 -1
  39. data/lib/vips/gobject.rb +26 -15
  40. data/lib/vips/gvalue.rb +61 -55
  41. data/lib/vips/image.rb +455 -282
  42. data/lib/vips/interesting.rb +0 -1
  43. data/lib/vips/interpolate.rb +3 -7
  44. data/lib/vips/interpretation.rb +0 -1
  45. data/lib/vips/kernel.rb +0 -1
  46. data/lib/vips/methods.rb +791 -124
  47. data/lib/vips/mutableimage.rb +173 -0
  48. data/lib/vips/object.rb +178 -68
  49. data/lib/vips/operation.rb +277 -130
  50. data/lib/vips/operationboolean.rb +0 -1
  51. data/lib/vips/operationcomplex.rb +0 -1
  52. data/lib/vips/operationcomplex2.rb +0 -1
  53. data/lib/vips/operationcomplexget.rb +0 -1
  54. data/lib/vips/operationmath.rb +0 -1
  55. data/lib/vips/operationmath2.rb +0 -1
  56. data/lib/vips/operationrelational.rb +0 -1
  57. data/lib/vips/operationround.rb +0 -1
  58. data/lib/vips/region.rb +73 -0
  59. data/lib/vips/size.rb +0 -1
  60. data/lib/vips/source.rb +88 -0
  61. data/lib/vips/sourcecustom.rb +89 -0
  62. data/lib/vips/target.rb +86 -0
  63. data/lib/vips/targetcustom.rb +77 -0
  64. data/lib/vips/version.rb +1 -2
  65. data/ruby-vips.gemspec +26 -21
  66. metadata +39 -51
  67. data/.rubocop.yml +0 -10
  68. data/.rubocop_todo.yml +0 -730
  69. data/.travis.yml +0 -62
  70. data/install-vips.sh +0 -26
data/lib/vips/align.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  module Vips
2
-
3
2
  # Various types of alignment. See {Image#join}, for example.
4
3
  #
5
4
  # * `:low` Align on the low coordinate edge
data/lib/vips/angle.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  module Vips
2
-
3
2
  # Various fixed 90 degree rotation angles. See {Image#rot}.
4
3
  #
5
4
  # * `:d0` no rotate
data/lib/vips/angle45.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  module Vips
2
-
3
2
  # Various fixed 45 degree rotation angles. See {Image#rot45}.
4
3
  #
5
4
  # * `:d0` no rotate
@@ -1,5 +1,4 @@
1
1
  module Vips
2
-
3
2
  # The format used for each band element. Each corresponds to a native C type
4
3
  # for the current machine.
5
4
  #
@@ -16,5 +15,4 @@ module Vips
16
15
  # * `:dpcomplex` double complex (two double) format
17
16
  class BandFormat < Symbol
18
17
  end
19
-
20
18
  end
@@ -1,34 +1,36 @@
1
1
  module Vips
2
-
3
2
  # Blend mode to use when compositing images. See {Image#composite}.
4
3
  #
5
- # `:clear` - where the second object is drawn, the first is removed
6
- # `:source` - the second object is drawn as if nothing were below
7
- # `:over` - the image shows what you would expect if you held two semi-transparent slides on top of each other
8
- # `:in` - the first object is removed completely, the second is only drawn where the first was
9
- # `:out` - the second is drawn only where the first isn't
10
- # `:atop` - this leaves the first object mostly intact, but mixes both objects in the overlapping area
11
- # `:dest` - leaves the first object untouched, the second is discarded completely
12
- # `:dest_over` - like `:over`, but swaps the arguments
13
- # `:dest_in` - like `:in`, but swaps the arguments
14
- # `:dest_out` - like `:out`, but swaps the arguments
15
- # `:dest_atop` - like `:atop`, but swaps the arguments
16
- # `:xor` - something like a difference operator
17
- # `:add` - a bit like adding the two images
18
- # `:saturate` - a bit like the darker of the two
19
- # `:multiply` - at least as dark as the darker of the two inputs
20
- # `:screen` - at least as light as the lighter of the inputs
21
- # `:overlay` - multiplies or screens colors, depending on the lightness
22
- # `:darken` - the darker of each component
23
- # `:lighten` - the lighter of each component
24
- # `:colour_dodge` - brighten first by a factor second
25
- # `:colour_burn` - darken first by a factor of second
26
- # `:hard_light` - multiply or screen, depending on lightness
27
- # `:soft_light` - darken or lighten, depending on lightness
28
- # `:difference` - difference of the two
29
- # `:exclusion` - somewhat like `:difference`, but lower-contrast
4
+ # * `:clear` where the second object is drawn, the first is removed
5
+ # * `:source` the second object is drawn as if nothing were below
6
+ # * `:over` the image shows what you would expect if you held two
7
+ # semi-transparent slides on top of each other
8
+ # * `:in` the first object is removed completely, the second is only
9
+ # drawn where the first was
10
+ # * `:out` the second is drawn only where the first isn't
11
+ # * `:atop` this leaves the first object mostly intact, but mixes both
12
+ # objects in the overlapping area
13
+ # * `:dest` leaves the first object untouched, the second is discarded
14
+ # completely
15
+ # * `:dest_over` like `:over`, but swaps the arguments
16
+ # * `:dest_in` like `:in`, but swaps the arguments
17
+ # * `:dest_out` like `:out`, but swaps the arguments
18
+ # * `:dest_atop` like `:atop`, but swaps the arguments
19
+ # * `:xor` something like a difference operator
20
+ # * `:add` a bit like adding the two images
21
+ # * `:saturate` a bit like the darker of the two
22
+ # * `:multiply` at least as dark as the darker of the two inputs
23
+ # * `:screen` at least as light as the lighter of the inputs
24
+ # * `:overlay` multiplies or screens colors, depending on the lightness
25
+ # * `:darken` the darker of each component
26
+ # * `:lighten` the lighter of each component
27
+ # * `:colour_dodge` brighten first by a factor second
28
+ # * `:colour_burn` darken first by a factor of second
29
+ # * `:hard_light` multiply or screen, depending on lightness
30
+ # * `:soft_light` darken or lighten, depending on lightness
31
+ # * `:difference` difference of the two
32
+ # * `:exclusion` somewhat like `:difference`, but lower-contrast
30
33
 
31
34
  class BlendMode < Symbol
32
35
  end
33
36
  end
34
-
data/lib/vips/coding.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  module Vips
2
-
3
2
  # How pixels are coded.
4
3
  #
5
4
  # Normally, pixels are uncoded and can be manipulated as you would expect.
@@ -1,5 +1,4 @@
1
1
  module Vips
2
-
3
2
  # A direction on a compass used for placing images. See {Image#gravity}.
4
3
  #
5
4
  # * `:centre`
@@ -0,0 +1,46 @@
1
+ # This module provides an interface to the top level bits of libvips
2
+ # via ruby-ffi.
3
+ #
4
+ # Author:: John Cupitt (mailto:jcupitt@gmail.com)
5
+ # License:: MIT
6
+
7
+ require "ffi"
8
+
9
+ module Vips
10
+ if Vips.at_least_libvips?(8, 9)
11
+ attach_function :vips_connection_filename, [:pointer], :string
12
+ attach_function :vips_connection_nick, [:pointer], :string
13
+ end
14
+
15
+ # Abstract base class for connections.
16
+ class Connection < Vips::Object
17
+ # The layout of the VipsRegion struct.
18
+ module ConnectionLayout
19
+ def self.included(base)
20
+ base.class_eval do
21
+ layout :parent, Vips::Object::Struct
22
+ # rest opaque
23
+ end
24
+ end
25
+ end
26
+
27
+ class Struct < Vips::Object::Struct
28
+ include ConnectionLayout
29
+ end
30
+
31
+ class ManagedStruct < Vips::Object::ManagedStruct
32
+ include ConnectionLayout
33
+ end
34
+
35
+ # Get any filename associated with a connection, or nil.
36
+ def filename
37
+ Vips.vips_connection_filename self
38
+ end
39
+
40
+ # Get a nickname (short description) of a connection that could be shown to
41
+ # the user.
42
+ def nick
43
+ Vips.vips_connection_nick self
44
+ end
45
+ end
46
+ end
@@ -1,5 +1,4 @@
1
1
  module Vips
2
-
3
2
  # Operations like {Image#flip} need to be told whether to flip
4
3
  # left-right or top-bottom.
5
4
  #
data/lib/vips/extend.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  module Vips
2
-
3
2
  # When the edges of an image are extended, you can specify
4
3
  # how you want the extension done.
5
4
  # See {Image#embed}, {Image#conv}, {Image#affine} and
data/lib/vips/gobject.rb CHANGED
@@ -4,11 +4,10 @@
4
4
  # Author:: John Cupitt (mailto:jcupitt@gmail.com)
5
5
  # License:: MIT
6
6
 
7
- require 'ffi'
8
- require 'forwardable'
7
+ require "ffi"
8
+ require "forwardable"
9
9
 
10
10
  module GObject
11
-
12
11
  # we have a number of things we need to inherit in different ways:
13
12
  #
14
13
  # - we want to be able to subclass GObject in Ruby in a simple way
@@ -38,13 +37,15 @@ module GObject
38
37
  def_instance_delegators :@struct, :[], :to_ptr
39
38
  def_single_delegators :ffi_struct, :ptr
40
39
 
40
+ attr_reader :references
41
+
41
42
  # the layout of the GObject struct
42
43
  module GObjectLayout
43
44
  def self.included base
44
45
  base.class_eval do
45
46
  layout :g_type_instance, :pointer,
46
- :ref_count, :uint,
47
- :qdata, :pointer
47
+ :ref_count, :uint,
48
+ :qdata, :pointer
48
49
  end
49
50
  end
50
51
  end
@@ -57,14 +58,13 @@ module GObject
57
58
  # GLib::logger.debug("GObject::GObject::ManagedStruct.release") {
58
59
  # "unreffing #{ptr}"
59
60
  # }
60
- ::GObject::g_object_unref ptr
61
+ ::GObject.g_object_unref ptr
61
62
  end
62
63
  end
63
64
 
64
65
  # the plain struct ... cast with this
65
66
  class Struct < FFI::Struct
66
67
  include GObjectLayout
67
-
68
68
  end
69
69
 
70
70
  # don't allow ptr == nil, we never want to allocate a GObject struct
@@ -74,7 +74,11 @@ module GObject
74
74
  # need the unref
75
75
  def initialize ptr
76
76
  # GLib::logger.debug("GObject::GObject.initialize") {"ptr = #{ptr}"}
77
+ @ptr = ptr
77
78
  @struct = ffi_managed_struct.new ptr
79
+
80
+ # sometimes we need to keep refs across C calls ... hide them here
81
+ @references = []
78
82
  end
79
83
 
80
84
  # access to the casting struct for this class
@@ -82,9 +86,13 @@ module GObject
82
86
  self.class.ffi_struct
83
87
  end
84
88
 
89
+ # get the pointer we were built from ... #to_ptr gets the pointer after we
90
+ # have wrapped it up with an auto unref
91
+ attr_reader :ptr
92
+
85
93
  class << self
86
94
  def ffi_struct
87
- self.const_get :Struct
95
+ const_get :Struct
88
96
  end
89
97
  end
90
98
 
@@ -95,28 +103,31 @@ module GObject
95
103
 
96
104
  class << self
97
105
  def ffi_managed_struct
98
- self.const_get :ManagedStruct
106
+ const_get :ManagedStruct
99
107
  end
100
108
  end
101
-
102
109
  end
103
110
 
104
111
  class GParamSpec < FFI::Struct
105
112
  # the first few public fields
106
113
  layout :g_type_instance, :pointer,
107
- :name, :string,
108
- :flags, :uint,
109
- :value_type, :GType,
110
- :owner_type, :GType
114
+ :name, :string,
115
+ :flags, :uint,
116
+ :value_type, :GType,
117
+ :owner_type, :GType
111
118
  end
112
119
 
113
120
  class GParamSpecPtr < FFI::Struct
114
121
  layout :value, GParamSpec.ptr
115
122
  end
116
123
 
117
- attach_function :g_param_spec_get_blurb, [GParamSpec.ptr], :string
124
+ attach_function :g_param_spec_get_blurb, [:pointer], :string
118
125
 
119
126
  attach_function :g_object_ref, [:pointer], :void
120
127
  attach_function :g_object_unref, [:pointer], :void
121
128
 
129
+ # we just use one gcallback type for every signal, hopefully this is OK
130
+ callback :gcallback, [:pointer], :void
131
+ attach_function :g_signal_connect_data,
132
+ [:pointer, :string, :gcallback, :pointer, :pointer, :int], :long
122
133
  end
data/lib/vips/gvalue.rb CHANGED
@@ -3,10 +3,9 @@
3
3
  # Author:: John Cupitt (mailto:jcupitt@gmail.com)
4
4
  # License:: MIT
5
5
 
6
- require 'ffi'
6
+ require "ffi"
7
7
 
8
8
  module GObject
9
-
10
9
  # Represent a GValue. Example use:
11
10
  #
12
11
  # ```ruby
@@ -14,6 +13,8 @@ module GObject
14
13
  # gvalue.init GObject::GDOUBLE_TYPE
15
14
  # gvalue.set 3.1415
16
15
  # value = gvalue.get
16
+ # # optional -- drop any ref the gvalue had
17
+ # gvalue.unset
17
18
  # ```
18
19
  #
19
20
  # Lifetime is managed automatically. It doesn't know about all GType values,
@@ -21,14 +22,16 @@ module GObject
21
22
 
22
23
  class GValue < FFI::ManagedStruct
23
24
  layout :gtype, :GType,
24
- :data, [:ulong_long, 2]
25
+ :data, [:ulong_long, 2]
25
26
 
26
27
  # convert an enum value (str/symb/int) into an int ready for libvips
27
28
  def self.from_nick(gtype, value)
28
29
  value = value.to_s if value.is_a? Symbol
29
30
 
30
31
  if value.is_a? String
31
- value = Vips::vips_enum_from_nick "ruby-vips", gtype, value
32
+ # libvips expects "-" as a separator in enum names, but "_" is more
33
+ # convenient for ruby, eg. :b_w
34
+ value = Vips.vips_enum_from_nick "ruby-vips", gtype, value.tr("_", "-")
32
35
  if value == -1
33
36
  raise Vips::Error
34
37
  end
@@ -39,8 +42,8 @@ module GObject
39
42
 
40
43
  # convert an int enum back into a symbol
41
44
  def self.to_nick(gtype, enum_value)
42
- enum_name = Vips::vips_enum_nick gtype, enum_value
43
- if enum_name == nil
45
+ enum_name = Vips.vips_enum_nick gtype, enum_value
46
+ if enum_name.nil?
44
47
  raise Vips::Error
45
48
  end
46
49
 
@@ -49,7 +52,7 @@ module GObject
49
52
 
50
53
  def self.release ptr
51
54
  # GLib::logger.debug("GObject::GValue::release") {"ptr = #{ptr}"}
52
- ::GObject::g_value_unset ptr
55
+ ::GObject.g_value_unset ptr
53
56
  end
54
57
 
55
58
  # Allocate memory for a GValue and return a class wrapper. Memory will
@@ -67,14 +70,14 @@ module GObject
67
70
  pointer = FFI::Pointer.new GValue, memory
68
71
 
69
72
  # ... and wrap in a GValue
70
- return GValue.new pointer
73
+ GValue.new pointer
71
74
  end
72
75
 
73
76
  # Set the type of thing a gvalue can hold.
74
77
  #
75
78
  # @param gtype [GType] the type of thing this GValue can hold.
76
79
  def init gtype
77
- ::GObject::g_value_init self, gtype
80
+ ::GObject.g_value_init self, gtype
78
81
  end
79
82
 
80
83
  # Set the value of a GValue. The value is converted to the type of the
@@ -87,77 +90,76 @@ module GObject
87
90
  # }
88
91
 
89
92
  gtype = self[:gtype]
90
- fundamental = ::GObject::g_type_fundamental gtype
93
+ fundamental = ::GObject.g_type_fundamental gtype
91
94
 
92
95
  case gtype
93
96
  when GBOOL_TYPE
94
- ::GObject::g_value_set_boolean self, (value ? 1 : 0)
97
+ ::GObject.g_value_set_boolean self, (value ? 1 : 0)
95
98
 
96
99
  when GINT_TYPE
97
- ::GObject::g_value_set_int self, value
100
+ ::GObject.g_value_set_int self, value
98
101
 
99
102
  when GUINT64_TYPE
100
- ::GObject::g_value_set_uint64 self, value
103
+ ::GObject.g_value_set_uint64 self, value
101
104
 
102
105
  when GDOUBLE_TYPE
103
- ::GObject::g_value_set_double self, value
106
+ ::GObject.g_value_set_double self, value
104
107
 
105
108
  when GSTR_TYPE
106
- ::GObject::g_value_set_string self, value
109
+ ::GObject.g_value_set_string self, value
107
110
 
108
111
  when Vips::REFSTR_TYPE
109
- ::Vips::vips_value_set_ref_string self, value
112
+ ::Vips.vips_value_set_ref_string self, value
110
113
 
111
114
  when Vips::ARRAY_INT_TYPE
112
115
  value = [value] unless value.is_a? Array
113
116
 
114
- Vips::vips_value_set_array_int self, nil, value.length
115
- ptr = Vips::vips_value_get_array_int self, nil
117
+ Vips.vips_value_set_array_int self, nil, value.length
118
+ ptr = Vips.vips_value_get_array_int self, nil
116
119
  ptr.write_array_of_int32 value
117
120
 
118
121
  when Vips::ARRAY_DOUBLE_TYPE
119
122
  value = [value] unless value.is_a? Array
120
123
 
121
124
  # this will allocate an array in the gvalue
122
- Vips::vips_value_set_array_double self, nil, value.length
125
+ Vips.vips_value_set_array_double self, nil, value.length
123
126
 
124
127
  # pull the array out and fill it
125
- ptr = Vips::vips_value_get_array_double self, nil
128
+ ptr = Vips.vips_value_get_array_double self, nil
126
129
 
127
130
  ptr.write_array_of_double value
128
131
 
129
132
  when Vips::ARRAY_IMAGE_TYPE
130
133
  value = [value] unless value.is_a? Array
131
134
 
132
- Vips::vips_value_set_array_image self, value.length
133
- ptr = Vips::vips_value_get_array_image self, nil
135
+ Vips.vips_value_set_array_image self, value.length
136
+ ptr = Vips.vips_value_get_array_image self, nil
134
137
  ptr.write_array_of_pointer value
135
138
 
136
139
  # the gvalue needs a ref on each of the images
137
- value.each {|image| ::GObject::g_object_ref image}
140
+ value.each { |image| ::GObject.g_object_ref image }
138
141
 
139
142
  when Vips::BLOB_TYPE
140
143
  len = value.bytesize
141
- ptr = GLib::g_malloc len
142
- Vips::vips_value_set_blob self, GLib::G_FREE, ptr, len
144
+ ptr = GLib.g_malloc len
145
+ Vips.vips_value_set_blob self, GLib::G_FREE, ptr, len
143
146
  ptr.write_bytes value
144
147
 
145
148
  else
146
149
  case fundamental
147
150
  when GFLAGS_TYPE
148
- ::GObject::g_value_set_flags self, value
151
+ ::GObject.g_value_set_flags self, value
149
152
 
150
153
  when GENUM_TYPE
151
154
  enum_value = GValue.from_nick(self[:gtype], value)
152
- ::GObject::g_value_set_enum self, enum_value
155
+ ::GObject.g_value_set_enum self, enum_value
153
156
 
154
157
  when GOBJECT_TYPE
155
- ::GObject::g_value_set_object self, value
158
+ ::GObject.g_value_set_object self, value
156
159
 
157
160
  else
158
- raise Vips::Error, "unimplemented gtype for set: " +
159
- "#{::GObject::g_type_name gtype} (#{gtype})"
160
-
161
+ raise Vips::Error, "unimplemented gtype for set: " \
162
+ "#{::GObject.g_type_name gtype} (#{gtype})"
161
163
  end
162
164
  end
163
165
  end
@@ -168,73 +170,72 @@ module GObject
168
170
  # @return [Any] the value held by the GValue
169
171
  def get
170
172
  gtype = self[:gtype]
171
- fundamental = ::GObject::g_type_fundamental gtype
173
+ fundamental = ::GObject.g_type_fundamental gtype
172
174
  result = nil
173
175
 
174
176
  case gtype
175
177
  when GBOOL_TYPE
176
- result = ::GObject::g_value_get_boolean(self) != 0 ? true : false
178
+ result = ::GObject.g_value_get_boolean(self) != 0
177
179
 
178
180
  when GINT_TYPE
179
- result = ::GObject::g_value_get_int self
181
+ result = ::GObject.g_value_get_int self
180
182
 
181
183
  when GUINT64_TYPE
182
- result = ::GObject::g_value_get_uint64 self
184
+ result = ::GObject.g_value_get_uint64 self
183
185
 
184
186
  when GDOUBLE_TYPE
185
- result = ::GObject::g_value_get_double self
187
+ result = ::GObject.g_value_get_double self
186
188
 
187
189
  when GSTR_TYPE
188
- result = ::GObject::g_value_get_string self
190
+ result = ::GObject.g_value_get_string self
189
191
 
190
192
  when Vips::REFSTR_TYPE
191
193
  len = Vips::SizeStruct.new
192
- result = ::Vips::vips_value_get_ref_string self, len
194
+ result = ::Vips.vips_value_get_ref_string self, len
193
195
 
194
196
  when Vips::ARRAY_INT_TYPE
195
197
  len = Vips::IntStruct.new
196
- array = Vips::vips_value_get_array_int self, len
198
+ array = Vips.vips_value_get_array_int self, len
197
199
  result = array.get_array_of_int32 0, len[:value]
198
200
 
199
201
  when Vips::ARRAY_DOUBLE_TYPE
200
202
  len = Vips::IntStruct.new
201
- array = Vips::vips_value_get_array_double self, len
203
+ array = Vips.vips_value_get_array_double self, len
202
204
  result = array.get_array_of_double 0, len[:value]
203
205
 
204
206
  when Vips::ARRAY_IMAGE_TYPE
205
207
  len = Vips::IntStruct.new
206
- array = Vips::vips_value_get_array_image self, len
208
+ array = Vips.vips_value_get_array_image self, len
207
209
  result = array.get_array_of_pointer 0, len[:value]
208
210
  result.map! do |pointer|
209
- ::GObject::g_object_ref pointer
211
+ ::GObject.g_object_ref pointer
210
212
  Vips::Image.new pointer
211
213
  end
212
214
 
213
215
  when Vips::BLOB_TYPE
214
216
  len = Vips::SizeStruct.new
215
- array = Vips::vips_value_get_blob self, len
217
+ array = Vips.vips_value_get_blob self, len
216
218
  result = array.get_bytes 0, len[:value]
217
219
 
218
220
  else
219
221
  case fundamental
220
222
  when GFLAGS_TYPE
221
- result = ::GObject::g_value_get_flags self
223
+ result = ::GObject.g_value_get_flags self
222
224
 
223
225
  when GENUM_TYPE
224
- enum_value = ::GObject::g_value_get_enum(self)
226
+ enum_value = ::GObject.g_value_get_enum(self)
225
227
  result = GValue.to_nick self[:gtype], enum_value
226
228
 
227
229
  when GOBJECT_TYPE
228
- obj = ::GObject::g_value_get_object self
230
+ obj = ::GObject.g_value_get_object self
229
231
  # g_value_get_object() does not add a ref ... we need to add
230
232
  # one to match the unref in gobject release
231
- ::GObject::g_object_ref obj
233
+ ::GObject.g_object_ref obj
232
234
  result = Vips::Image.new obj
233
235
 
234
236
  else
235
- raise Vips::Error, "unimplemented gtype for get: " +
236
- "#{::GObject::g_type_name gtype} (#{gtype})"
237
-
237
+ raise Vips::Error, "unimplemented gtype for get: " \
238
+ "#{::GObject.g_type_name gtype} (#{gtype})"
238
239
  end
239
240
  end
240
241
 
@@ -242,10 +243,16 @@ module GObject
242
243
  # "result = #{result.inspect[0..50]}"
243
244
  # }
244
245
 
245
- return result
246
-
246
+ result
247
247
  end
248
248
 
249
+ # Clear the thing held by a GValue.
250
+ #
251
+ # This happens automatically when a GValue is GCed, but this method can be
252
+ # handy if you need to drop a reference explicitly for some reason.
253
+ def unset
254
+ ::GObject.g_value_unset self
255
+ end
249
256
  end
250
257
 
251
258
  attach_function :g_value_init, [GValue.ptr, :GType], :void
@@ -274,8 +281,7 @@ module GObject
274
281
 
275
282
  # use :pointer rather than GObject.ptr to avoid casting later
276
283
  attach_function :g_object_set_property,
277
- [:pointer, :string, GValue.ptr], :void
284
+ [:pointer, :string, GValue.ptr], :void
278
285
  attach_function :g_object_get_property,
279
- [:pointer, :string, GValue.ptr], :void
280
-
286
+ [:pointer, :string, GValue.ptr], :void
281
287
  end