ruby-vips 2.0.13 → 2.0.14

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 (53) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +10 -0
  3. data/.rubocop_todo.yml +730 -0
  4. data/.travis.yml +13 -6
  5. data/CHANGELOG.md +8 -0
  6. data/README.md +5 -8
  7. data/Rakefile +6 -0
  8. data/VERSION +1 -1
  9. data/example/annotate.rb +2 -2
  10. data/example/daltonize8.rb +14 -14
  11. data/example/example2.rb +6 -6
  12. data/example/example3.rb +5 -5
  13. data/example/example4.rb +4 -4
  14. data/example/example5.rb +2 -2
  15. data/example/inheritance_with_refcount.rb +207 -207
  16. data/example/thumb.rb +10 -10
  17. data/example/trim8.rb +2 -2
  18. data/example/watermark.rb +14 -35
  19. data/example/wobble.rb +24 -24
  20. data/install-vips.sh +1 -1
  21. data/lib/vips.rb +335 -306
  22. data/lib/vips/access.rb +9 -9
  23. data/lib/vips/align.rb +7 -7
  24. data/lib/vips/angle.rb +8 -8
  25. data/lib/vips/angle45.rb +12 -12
  26. data/lib/vips/bandformat.rb +16 -16
  27. data/lib/vips/blend_mode.rb +34 -0
  28. data/lib/vips/coding.rb +11 -11
  29. data/lib/vips/compass_direction.rb +13 -13
  30. data/lib/vips/direction.rb +7 -7
  31. data/lib/vips/extend.rb +13 -13
  32. data/lib/vips/gobject.rb +94 -94
  33. data/lib/vips/gvalue.rb +232 -232
  34. data/lib/vips/image.rb +1329 -1335
  35. data/lib/vips/interesting.rb +10 -10
  36. data/lib/vips/interpolate.rb +51 -51
  37. data/lib/vips/interpretation.rb +25 -25
  38. data/lib/vips/kernel.rb +18 -18
  39. data/lib/vips/methods.rb +463 -283
  40. data/lib/vips/object.rb +208 -208
  41. data/lib/vips/operation.rb +323 -323
  42. data/lib/vips/operationboolean.rb +10 -10
  43. data/lib/vips/operationcomplex.rb +8 -8
  44. data/lib/vips/operationcomplex2.rb +6 -6
  45. data/lib/vips/operationcomplexget.rb +7 -7
  46. data/lib/vips/operationmath.rb +14 -14
  47. data/lib/vips/operationmath2.rb +6 -6
  48. data/lib/vips/operationrelational.rb +11 -11
  49. data/lib/vips/operationround.rb +7 -7
  50. data/lib/vips/size.rb +9 -9
  51. data/lib/vips/version.rb +1 -1
  52. data/ruby-vips.gemspec +6 -2
  53. metadata +29 -6
@@ -7,275 +7,275 @@ require 'ffi'
7
7
 
8
8
  module GObject
9
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.
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
21
36
 
22
- class GValue < FFI::ManagedStruct
23
- layout :gtype, :GType,
24
- :data, [:ulong_long, 2]
37
+ value
38
+ end
25
39
 
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
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
29
46
 
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
47
+ enum_name.to_sym
48
+ end
36
49
 
37
- value
38
- end
50
+ def self.release ptr
51
+ # GLib::logger.debug("GObject::GValue::release") {"ptr = #{ptr}"}
52
+ ::GObject::g_value_unset ptr
53
+ end
39
54
 
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
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
46
72
 
47
- enum_name.to_sym
48
- end
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
49
79
 
50
- def self.release ptr
51
- # GLib::logger.debug("GObject::GValue::release") {"ptr = #{ptr}"}
52
- ::GObject::g_value_unset ptr
53
- end
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
+ # }
54
88
 
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
89
+ gtype = self[:gtype]
90
+ fundamental = ::GObject::g_type_fundamental gtype
72
91
 
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
92
+ case gtype
93
+ when GBOOL_TYPE
94
+ ::GObject::g_value_set_boolean self, (value ? 1 : 0)
95
+
96
+ when GINT_TYPE
97
+ ::GObject::g_value_set_int self, value
98
+
99
+ when GUINT64_TYPE
100
+ ::GObject::g_value_set_uint64 self, value
101
+
102
+ when GDOUBLE_TYPE
103
+ ::GObject::g_value_set_double self, value
79
104
 
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
- # }
105
+ when GSTR_TYPE
106
+ ::GObject::g_value_set_string self, value
88
107
 
89
- gtype = self[:gtype]
90
- fundamental = ::GObject::g_type_fundamental gtype
108
+ when Vips::REFSTR_TYPE
109
+ ::Vips::vips_value_set_ref_string self, value
91
110
 
92
- case gtype
93
- when GBOOL_TYPE
94
- ::GObject::g_value_set_boolean self, (value ? 1 : 0)
111
+ when Vips::ARRAY_INT_TYPE
112
+ value = [value] unless value.is_a? Array
95
113
 
96
- when GINT_TYPE
97
- ::GObject::g_value_set_int self, value
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
98
117
 
99
- when GUINT64_TYPE
100
- ::GObject::g_value_set_uint64 self, value
118
+ when Vips::ARRAY_DOUBLE_TYPE
119
+ value = [value] unless value.is_a? Array
101
120
 
102
- when GDOUBLE_TYPE
103
- ::GObject::g_value_set_double self, value
121
+ # this will allocate an array in the gvalue
122
+ Vips::vips_value_set_array_double self, nil, value.length
104
123
 
105
- when GSTR_TYPE
106
- ::GObject::g_value_set_string self, value
124
+ # pull the array out and fill it
125
+ ptr = Vips::vips_value_get_array_double self, nil
107
126
 
108
- when Vips::REFSTR_TYPE
109
- ::Vips::vips_value_set_ref_string self, value
127
+ ptr.write_array_of_double value
110
128
 
111
- when Vips::ARRAY_INT_TYPE
112
- value = [value] unless value.is_a? Array
129
+ when Vips::ARRAY_IMAGE_TYPE
130
+ value = [value] unless value.is_a? Array
113
131
 
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
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
117
135
 
118
- when Vips::ARRAY_DOUBLE_TYPE
119
- value = [value] unless value.is_a? Array
136
+ # the gvalue needs a ref on each of the images
137
+ value.each {|image| ::GObject::g_object_ref image}
120
138
 
121
- # this will allocate an array in the gvalue
122
- Vips::vips_value_set_array_double self, nil, value.length
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
123
144
 
124
- # pull the array out and fill it
125
- ptr = Vips::vips_value_get_array_double self, nil
145
+ else
146
+ case fundamental
147
+ when GFLAGS_TYPE
148
+ ::GObject::g_value_set_flags self, value
126
149
 
127
- ptr.write_array_of_double value
150
+ when GENUM_TYPE
151
+ enum_value = GValue.from_nick(self[:gtype], value)
152
+ ::GObject::g_value_set_enum self, enum_value
128
153
 
129
- when Vips::ARRAY_IMAGE_TYPE
130
- value = [value] unless value.is_a? Array
154
+ when GOBJECT_TYPE
155
+ ::GObject::g_value_set_object self, value
131
156
 
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
157
+ else
158
+ raise Vips::Error, "unimplemented gtype for set: " +
159
+ "#{::GObject::g_type_name gtype} (#{gtype})"
135
160
 
136
- # the gvalue needs a ref on each of the images
137
- value.each {|image| ::GObject::g_object_ref image}
161
+ end
162
+ end
163
+ end
164
+
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
138
212
 
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
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]
144
217
 
145
- else
146
- case fundamental
147
- when GFLAGS_TYPE
148
- ::GObject::g_value_set_flags self, value
218
+ else
219
+ case fundamental
220
+ when GFLAGS_TYPE
221
+ result = ::GObject::g_value_get_flags self
149
222
 
150
- when GENUM_TYPE
151
- enum_value = GValue.from_nick(self[:gtype], value)
152
- ::GObject::g_value_set_enum self, enum_value
223
+ when GENUM_TYPE
224
+ enum_value = ::GObject::g_value_get_enum(self)
225
+ result = GValue.to_nick self[:gtype], enum_value
153
226
 
154
- when GOBJECT_TYPE
155
- ::GObject::g_value_set_object self, value
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
156
233
 
157
- else
158
- raise Vips::Error, "unimplemented gtype for set: " +
159
- "#{::GObject::g_type_name gtype} (#{gtype})"
234
+ else
235
+ raise Vips::Error, "unimplemented gtype for get: " +
236
+ "#{::GObject::g_type_name gtype} (#{gtype})"
160
237
 
161
- end
162
- end
163
238
  end
239
+ end
164
240
 
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
241
+ # GLib::logger.debug("GObject::GValue.get") {
242
+ # "result = #{result.inspect[0..50]}"
243
+ # }
246
244
 
247
- end
245
+ return result
248
246
 
249
247
  end
250
248
 
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
249
+ end
250
+
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
280
280
 
281
281
  end