vips 8.6.3.2 → 8.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +27 -22
  3. data/CHANGELOG.md +273 -0
  4. data/example/annotate.rb +2 -2
  5. data/example/daltonize8.rb +26 -28
  6. data/example/example1.rb +1 -2
  7. data/example/example2.rb +6 -6
  8. data/example/example3.rb +5 -5
  9. data/example/example4.rb +6 -6
  10. data/example/example5.rb +6 -7
  11. data/example/inheritance_with_refcount.rb +201 -218
  12. data/example/thumb.rb +10 -12
  13. data/example/trim8.rb +6 -6
  14. data/example/watermark.rb +14 -35
  15. data/example/wobble.rb +24 -24
  16. data/lib/vips.rb +335 -312
  17. data/lib/vips/access.rb +9 -9
  18. data/lib/vips/align.rb +7 -8
  19. data/lib/vips/angle.rb +8 -9
  20. data/lib/vips/angle45.rb +12 -13
  21. data/lib/vips/bandformat.rb +16 -18
  22. data/lib/vips/blend_mode.rb +32 -0
  23. data/lib/vips/coding.rb +11 -12
  24. data/lib/vips/compass_direction.rb +13 -14
  25. data/lib/vips/direction.rb +7 -8
  26. data/lib/vips/extend.rb +13 -14
  27. data/lib/vips/gobject.rb +92 -96
  28. data/lib/vips/gvalue.rb +231 -237
  29. data/lib/vips/image.rb +1329 -1330
  30. data/lib/vips/interesting.rb +10 -11
  31. data/lib/vips/interpolate.rb +49 -54
  32. data/lib/vips/interpretation.rb +25 -26
  33. data/lib/vips/kernel.rb +18 -19
  34. data/lib/vips/methods.rb +2319 -2141
  35. data/lib/vips/object.rb +204 -213
  36. data/lib/vips/operation.rb +317 -323
  37. data/lib/vips/operationboolean.rb +10 -11
  38. data/lib/vips/operationcomplex.rb +8 -9
  39. data/lib/vips/operationcomplex2.rb +6 -7
  40. data/lib/vips/operationcomplexget.rb +7 -8
  41. data/lib/vips/operationmath.rb +14 -15
  42. data/lib/vips/operationmath2.rb +6 -7
  43. data/lib/vips/operationrelational.rb +11 -12
  44. data/lib/vips/operationround.rb +7 -8
  45. data/lib/vips/size.rb +9 -10
  46. data/lib/vips/version.rb +1 -1
  47. data/vips.gemspec +1 -1
  48. metadata +9 -8
data/lib/vips/gvalue.rb CHANGED
@@ -6,276 +6,270 @@
6
6
  require 'ffi'
7
7
 
8
8
  module GObject
9
-
10
- # Represent a GValue. Example use:
11
- #
12
- # ```ruby
13
- # gvalue = GValue::alloc
14
- # gvalue.init GObject::GDOUBLE_TYPE
15
- # gvalue.set 3.1415
16
- # value = gvalue.get
17
- # ```
18
- #
19
- # Lifetime is managed automatically. It doesn't know about all GType values,
20
- # but it does know the ones that libvips uses.
21
-
22
- class GValue < FFI::ManagedStruct
23
- layout :gtype, :GType,
24
- :data, [:ulong_long, 2]
25
-
26
- # convert an enum value (str/symb/int) into an int ready for libvips
27
- def self.from_nick(gtype, value)
28
- value = value.to_s if value.is_a? Symbol
29
-
30
- if value.is_a? String
31
- value = Vips::vips_enum_from_nick "ruby-vips", gtype, value
32
- if value == -1
33
- raise Vips::Error
34
- end
35
- end
36
-
37
- value
9
+ # Represent a GValue. Example use:
10
+ #
11
+ # ```ruby
12
+ # gvalue = GValue::alloc
13
+ # gvalue.init GObject::GDOUBLE_TYPE
14
+ # gvalue.set 3.1415
15
+ # value = gvalue.get
16
+ # ```
17
+ #
18
+ # Lifetime is managed automatically. It doesn't know about all GType values,
19
+ # but it does know the ones that libvips uses.
20
+
21
+ class GValue < FFI::ManagedStruct
22
+ layout :gtype, :GType,
23
+ :data, [:ulong_long, 2]
24
+
25
+ # convert an enum value (str/symb/int) into an int ready for libvips
26
+ def self.from_nick(gtype, value)
27
+ value = value.to_s if value.is_a? Symbol
28
+
29
+ if value.is_a? String
30
+ value = Vips::vips_enum_from_nick "ruby-vips", gtype, value
31
+ if value == -1
32
+ raise Vips::Error
38
33
  end
34
+ end
39
35
 
40
- # convert an int enum back into a symbol
41
- def self.to_nick(gtype, enum_value)
42
- enum_name = Vips::vips_enum_nick gtype, enum_value
43
- if enum_name == nil
44
- raise Vips::Error
45
- end
36
+ value
37
+ end
46
38
 
47
- enum_name.to_sym
48
- end
39
+ # convert an int enum back into a symbol
40
+ def self.to_nick(gtype, enum_value)
41
+ enum_name = Vips::vips_enum_nick gtype, enum_value
42
+ if enum_name == nil
43
+ raise Vips::Error
44
+ end
49
45
 
50
- def self.release ptr
51
- # GLib::logger.debug("GObject::GValue::release") {"ptr = #{ptr}"}
52
- ::GObject::g_value_unset ptr
53
- end
46
+ enum_name.to_sym
47
+ end
54
48
 
55
- # Allocate memory for a GValue and return a class wrapper. Memory will
56
- # be freed automatically when it goes out of scope. The GValue is inited
57
- # to 0, use {GValue.init} to set a type.
58
- #
59
- # @return [GValue] a new gvalue set to 0
60
- def self.alloc
61
- # allocate memory
62
- memory = FFI::MemoryPointer.new GValue
63
-
64
- # make this alloc autorelease ... we mustn't release in
65
- # GValue::release, since we are used to wrap GValue pointers
66
- # made by other people
67
- pointer = FFI::Pointer.new GValue, memory
68
-
69
- # ... and wrap in a GValue
70
- return GValue.new pointer
71
- end
49
+ def self.release ptr
50
+ # GLib::logger.debug("GObject::GValue::release") {"ptr = #{ptr}"}
51
+ ::GObject::g_value_unset ptr
52
+ end
72
53
 
73
- # Set the type of thing a gvalue can hold.
74
- #
75
- # @param gtype [GType] the type of thing this GValue can hold.
76
- def init gtype
77
- ::GObject::g_value_init self, gtype
78
- end
54
+ # Allocate memory for a GValue and return a class wrapper. Memory will
55
+ # be freed automatically when it goes out of scope. The GValue is inited
56
+ # to 0, use {GValue.init} to set a type.
57
+ #
58
+ # @return [GValue] a new gvalue set to 0
59
+ def self.alloc
60
+ # allocate memory
61
+ memory = FFI::MemoryPointer.new GValue
62
+
63
+ # make this alloc autorelease ... we mustn't release in
64
+ # GValue::release, since we are used to wrap GValue pointers
65
+ # made by other people
66
+ pointer = FFI::Pointer.new GValue, memory
67
+
68
+ # ... and wrap in a GValue
69
+ return GValue.new pointer
70
+ end
79
71
 
80
- # Set the value of a GValue. The value is converted to the type of the
81
- # GValue, if possible.
82
- #
83
- # @param value [Any] The value to set
84
- def set value
85
- # GLib::logger.debug("GObject::GValue.set") {
86
- # "value = #{value.inspect[0..50]}"
87
- # }
72
+ # Set the type of thing a gvalue can hold.
73
+ #
74
+ # @param gtype [GType] the type of thing this GValue can hold.
75
+ def init gtype
76
+ ::GObject::g_value_init self, gtype
77
+ end
88
78
 
89
- gtype = self[:gtype]
90
- fundamental = ::GObject::g_type_fundamental gtype
79
+ # Set the value of a GValue. The value is converted to the type of the
80
+ # GValue, if possible.
81
+ #
82
+ # @param value [Any] The value to set
83
+ def set value
84
+ # GLib::logger.debug("GObject::GValue.set") {
85
+ # "value = #{value.inspect[0..50]}"
86
+ # }
91
87
 
92
- case gtype
93
- when GBOOL_TYPE
94
- ::GObject::g_value_set_boolean self, (value ? 1 : 0)
88
+ gtype = self[:gtype]
89
+ fundamental = ::GObject::g_type_fundamental gtype
95
90
 
96
- when GINT_TYPE
97
- ::GObject::g_value_set_int self, value
91
+ case gtype
92
+ when GBOOL_TYPE
93
+ ::GObject::g_value_set_boolean self, (value ? 1 : 0)
98
94
 
99
- when GUINT64_TYPE
100
- ::GObject::g_value_set_uint64 self, value
95
+ when GINT_TYPE
96
+ ::GObject::g_value_set_int self, value
101
97
 
102
- when GDOUBLE_TYPE
103
- ::GObject::g_value_set_double self, value
98
+ when GUINT64_TYPE
99
+ ::GObject::g_value_set_uint64 self, value
104
100
 
105
- when GSTR_TYPE
106
- ::GObject::g_value_set_string self, value
101
+ when GDOUBLE_TYPE
102
+ ::GObject::g_value_set_double self, value
107
103
 
108
- when Vips::REFSTR_TYPE
109
- ::Vips::vips_value_set_ref_string self, value
104
+ when GSTR_TYPE
105
+ ::GObject::g_value_set_string self, value
110
106
 
111
- when Vips::ARRAY_INT_TYPE
112
- value = [value] unless value.is_a? Array
107
+ when Vips::REFSTR_TYPE
108
+ ::Vips::vips_value_set_ref_string self, value
113
109
 
114
- Vips::vips_value_set_array_int self, nil, value.length
115
- ptr = Vips::vips_value_get_array_int self, nil
116
- ptr.write_array_of_int32 value
110
+ when Vips::ARRAY_INT_TYPE
111
+ value = [value] unless value.is_a? Array
117
112
 
118
- when Vips::ARRAY_DOUBLE_TYPE
119
- value = [value] unless value.is_a? Array
113
+ Vips::vips_value_set_array_int self, nil, value.length
114
+ ptr = Vips::vips_value_get_array_int self, nil
115
+ ptr.write_array_of_int32 value
120
116
 
121
- # this will allocate an array in the gvalue
122
- Vips::vips_value_set_array_double self, nil, value.length
117
+ when Vips::ARRAY_DOUBLE_TYPE
118
+ value = [value] unless value.is_a? Array
123
119
 
124
- # pull the array out and fill it
125
- ptr = Vips::vips_value_get_array_double self, nil
120
+ # this will allocate an array in the gvalue
121
+ Vips::vips_value_set_array_double self, nil, value.length
126
122
 
127
- ptr.write_array_of_double value
123
+ # pull the array out and fill it
124
+ ptr = Vips::vips_value_get_array_double self, nil
128
125
 
129
- when Vips::ARRAY_IMAGE_TYPE
130
- value = [value] unless value.is_a? Array
126
+ ptr.write_array_of_double value
131
127
 
132
- Vips::vips_value_set_array_image self, value.length
133
- ptr = Vips::vips_value_get_array_image self, nil
134
- ptr.write_array_of_pointer value
128
+ when Vips::ARRAY_IMAGE_TYPE
129
+ value = [value] unless value.is_a? Array
135
130
 
136
- # the gvalue needs a ref on each of the images
137
- value.each {|image| ::GObject::g_object_ref image}
131
+ Vips::vips_value_set_array_image self, value.length
132
+ ptr = Vips::vips_value_get_array_image self, nil
133
+ ptr.write_array_of_pointer value
138
134
 
139
- when Vips::BLOB_TYPE
140
- len = value.bytesize
141
- ptr = GLib::g_malloc len
142
- Vips::vips_value_set_blob self, GLib::G_FREE, ptr, len
143
- ptr.write_bytes value
135
+ # the gvalue needs a ref on each of the images
136
+ value.each { |image| ::GObject::g_object_ref image }
144
137
 
145
- else
146
- case fundamental
147
- when GFLAGS_TYPE
148
- ::GObject::g_value_set_flags self, value
138
+ when Vips::BLOB_TYPE
139
+ len = value.bytesize
140
+ ptr = GLib::g_malloc len
141
+ Vips::vips_value_set_blob self, GLib::G_FREE, ptr, len
142
+ ptr.write_bytes value
149
143
 
150
- when GENUM_TYPE
151
- enum_value = GValue.from_nick(self[:gtype], value)
152
- ::GObject::g_value_set_enum self, enum_value
144
+ else
145
+ case fundamental
146
+ when GFLAGS_TYPE
147
+ ::GObject::g_value_set_flags self, value
153
148
 
154
- when GOBJECT_TYPE
155
- ::GObject::g_value_set_object self, value
149
+ when GENUM_TYPE
150
+ enum_value = GValue.from_nick(self[:gtype], value)
151
+ ::GObject::g_value_set_enum self, enum_value
156
152
 
157
- else
158
- raise Vips::Error, "unimplemented gtype for set: " +
159
- "#{::GObject::g_type_name gtype} (#{gtype})"
153
+ when GOBJECT_TYPE
154
+ ::GObject::g_value_set_object self, value
160
155
 
161
- end
162
- end
156
+ else
157
+ raise Vips::Error, "unimplemented gtype for set: " +
158
+ "#{::GObject::g_type_name gtype} (#{gtype})"
163
159
  end
160
+ end
161
+ end
164
162
 
165
- # Get the value of a GValue. The value is converted to a Ruby type in
166
- # the obvious way.
167
- #
168
- # @return [Any] the value held by the GValue
169
- def get
170
- gtype = self[:gtype]
171
- fundamental = ::GObject::g_type_fundamental gtype
172
- result = nil
173
-
174
- case gtype
175
- when GBOOL_TYPE
176
- result = ::GObject::g_value_get_boolean(self) != 0 ? true : false
177
-
178
- when GINT_TYPE
179
- result = ::GObject::g_value_get_int self
180
-
181
- when GUINT64_TYPE
182
- result = ::GObject::g_value_get_uint64 self
183
-
184
- when GDOUBLE_TYPE
185
- result = ::GObject::g_value_get_double self
186
-
187
- when GSTR_TYPE
188
- result = ::GObject::g_value_get_string self
189
-
190
- when Vips::REFSTR_TYPE
191
- len = Vips::SizeStruct.new
192
- result = ::Vips::vips_value_get_ref_string self, len
193
-
194
- when Vips::ARRAY_INT_TYPE
195
- len = Vips::IntStruct.new
196
- array = Vips::vips_value_get_array_int self, len
197
- result = array.get_array_of_int32 0, len[:value]
198
-
199
- when Vips::ARRAY_DOUBLE_TYPE
200
- len = Vips::IntStruct.new
201
- array = Vips::vips_value_get_array_double self, len
202
- result = array.get_array_of_double 0, len[:value]
203
-
204
- when Vips::ARRAY_IMAGE_TYPE
205
- len = Vips::IntStruct.new
206
- array = Vips::vips_value_get_array_image self, len
207
- result = array.get_array_of_pointer 0, len[:value]
208
- result.map! do |pointer|
209
- ::GObject::g_object_ref pointer
210
- Vips::Image.new pointer
211
- end
212
-
213
- when Vips::BLOB_TYPE
214
- len = Vips::SizeStruct.new
215
- array = Vips::vips_value_get_blob self, len
216
- result = array.get_bytes 0, len[:value]
217
-
218
- else
219
- case fundamental
220
- when GFLAGS_TYPE
221
- result = ::GObject::g_value_get_flags self
222
-
223
- when GENUM_TYPE
224
- enum_value = ::GObject::g_value_get_enum(self)
225
- result = GValue.to_nick self[:gtype], enum_value
226
-
227
- when GOBJECT_TYPE
228
- obj = ::GObject::g_value_get_object self
229
- # g_value_get_object() does not add a ref ... we need to add
230
- # one to match the unref in gobject release
231
- ::GObject::g_object_ref obj
232
- result = Vips::Image.new obj
233
-
234
- else
235
- raise Vips::Error, "unimplemented gtype for get: " +
236
- "#{::GObject::g_type_name gtype} (#{gtype})"
237
-
238
- end
239
- end
240
-
241
- # GLib::logger.debug("GObject::GValue.get") {
242
- # "result = #{result.inspect[0..50]}"
243
- # }
244
-
245
- return result
246
-
163
+ # Get the value of a GValue. The value is converted to a Ruby type in
164
+ # the obvious way.
165
+ #
166
+ # @return [Any] the value held by the GValue
167
+ def get
168
+ gtype = self[:gtype]
169
+ fundamental = ::GObject::g_type_fundamental gtype
170
+ result = nil
171
+
172
+ case gtype
173
+ when GBOOL_TYPE
174
+ result = ::GObject::g_value_get_boolean(self) != 0 ? true : false
175
+
176
+ when GINT_TYPE
177
+ result = ::GObject::g_value_get_int self
178
+
179
+ when GUINT64_TYPE
180
+ result = ::GObject::g_value_get_uint64 self
181
+
182
+ when GDOUBLE_TYPE
183
+ result = ::GObject::g_value_get_double self
184
+
185
+ when GSTR_TYPE
186
+ result = ::GObject::g_value_get_string self
187
+
188
+ when Vips::REFSTR_TYPE
189
+ len = Vips::SizeStruct.new
190
+ result = ::Vips::vips_value_get_ref_string self, len
191
+
192
+ when Vips::ARRAY_INT_TYPE
193
+ len = Vips::IntStruct.new
194
+ array = Vips::vips_value_get_array_int self, len
195
+ result = array.get_array_of_int32 0, len[:value]
196
+
197
+ when Vips::ARRAY_DOUBLE_TYPE
198
+ len = Vips::IntStruct.new
199
+ array = Vips::vips_value_get_array_double self, len
200
+ result = array.get_array_of_double 0, len[:value]
201
+
202
+ when Vips::ARRAY_IMAGE_TYPE
203
+ len = Vips::IntStruct.new
204
+ array = Vips::vips_value_get_array_image self, len
205
+ result = array.get_array_of_pointer 0, len[:value]
206
+ result.map! do |pointer|
207
+ ::GObject::g_object_ref pointer
208
+ Vips::Image.new pointer
247
209
  end
248
210
 
249
- end
211
+ when Vips::BLOB_TYPE
212
+ len = Vips::SizeStruct.new
213
+ array = Vips::vips_value_get_blob self, len
214
+ result = array.get_bytes 0, len[:value]
215
+
216
+ else
217
+ case fundamental
218
+ when GFLAGS_TYPE
219
+ result = ::GObject::g_value_get_flags self
220
+
221
+ when GENUM_TYPE
222
+ enum_value = ::GObject::g_value_get_enum(self)
223
+ result = GValue.to_nick self[:gtype], enum_value
224
+
225
+ when GOBJECT_TYPE
226
+ obj = ::GObject::g_value_get_object self
227
+ # g_value_get_object() does not add a ref ... we need to add
228
+ # one to match the unref in gobject release
229
+ ::GObject::g_object_ref obj
230
+ result = Vips::Image.new obj
231
+
232
+ else
233
+ raise Vips::Error, "unimplemented gtype for get: " +
234
+ "#{::GObject::g_type_name gtype} (#{gtype})"
235
+ end
236
+ end
250
237
 
251
- attach_function :g_value_init, [GValue.ptr, :GType], :void
252
-
253
- # we must use a plain :pointer here, since we call this from #release, which
254
- # just gives us the unwrapped pointer, not the ruby class
255
- attach_function :g_value_unset, [:pointer], :void
256
-
257
- attach_function :g_value_set_boolean, [GValue.ptr, :int], :void
258
- attach_function :g_value_set_int, [GValue.ptr, :int], :void
259
- attach_function :g_value_set_uint64, [GValue.ptr, :uint64], :void
260
- attach_function :g_value_set_double, [GValue.ptr, :double], :void
261
- attach_function :g_value_set_enum, [GValue.ptr, :int], :void
262
- attach_function :g_value_set_flags, [GValue.ptr, :uint], :void
263
- attach_function :g_value_set_string, [GValue.ptr, :string], :void
264
- attach_function :g_value_set_object, [GValue.ptr, :pointer], :void
265
-
266
- attach_function :g_value_get_boolean, [GValue.ptr], :int
267
- attach_function :g_value_get_int, [GValue.ptr], :int
268
- attach_function :g_value_get_uint64, [GValue.ptr], :uint64
269
- attach_function :g_value_get_double, [GValue.ptr], :double
270
- attach_function :g_value_get_enum, [GValue.ptr], :int
271
- attach_function :g_value_get_flags, [GValue.ptr], :int
272
- attach_function :g_value_get_string, [GValue.ptr], :string
273
- attach_function :g_value_get_object, [GValue.ptr], :pointer
274
-
275
- # use :pointer rather than GObject.ptr to avoid casting later
276
- attach_function :g_object_set_property,
277
- [:pointer, :string, GValue.ptr], :void
278
- attach_function :g_object_get_property,
279
- [:pointer, :string, GValue.ptr], :void
238
+ # GLib::logger.debug("GObject::GValue.get") {
239
+ # "result = #{result.inspect[0..50]}"
240
+ # }
280
241
 
242
+ return result
243
+ end
244
+ end
245
+
246
+ attach_function :g_value_init, [GValue.ptr, :GType], :void
247
+
248
+ # we must use a plain :pointer here, since we call this from #release, which
249
+ # just gives us the unwrapped pointer, not the ruby class
250
+ attach_function :g_value_unset, [:pointer], :void
251
+
252
+ attach_function :g_value_set_boolean, [GValue.ptr, :int], :void
253
+ attach_function :g_value_set_int, [GValue.ptr, :int], :void
254
+ attach_function :g_value_set_uint64, [GValue.ptr, :uint64], :void
255
+ attach_function :g_value_set_double, [GValue.ptr, :double], :void
256
+ attach_function :g_value_set_enum, [GValue.ptr, :int], :void
257
+ attach_function :g_value_set_flags, [GValue.ptr, :uint], :void
258
+ attach_function :g_value_set_string, [GValue.ptr, :string], :void
259
+ attach_function :g_value_set_object, [GValue.ptr, :pointer], :void
260
+
261
+ attach_function :g_value_get_boolean, [GValue.ptr], :int
262
+ attach_function :g_value_get_int, [GValue.ptr], :int
263
+ attach_function :g_value_get_uint64, [GValue.ptr], :uint64
264
+ attach_function :g_value_get_double, [GValue.ptr], :double
265
+ attach_function :g_value_get_enum, [GValue.ptr], :int
266
+ attach_function :g_value_get_flags, [GValue.ptr], :int
267
+ attach_function :g_value_get_string, [GValue.ptr], :string
268
+ attach_function :g_value_get_object, [GValue.ptr], :pointer
269
+
270
+ # use :pointer rather than GObject.ptr to avoid casting later
271
+ attach_function :g_object_set_property,
272
+ [:pointer, :string, GValue.ptr], :void
273
+ attach_function :g_object_get_property,
274
+ [:pointer, :string, GValue.ptr], :void
281
275
  end