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.
- checksums.yaml +4 -4
- data/.travis.yml +27 -22
- data/CHANGELOG.md +273 -0
- data/example/annotate.rb +2 -2
- data/example/daltonize8.rb +26 -28
- data/example/example1.rb +1 -2
- data/example/example2.rb +6 -6
- data/example/example3.rb +5 -5
- data/example/example4.rb +6 -6
- data/example/example5.rb +6 -7
- data/example/inheritance_with_refcount.rb +201 -218
- data/example/thumb.rb +10 -12
- data/example/trim8.rb +6 -6
- data/example/watermark.rb +14 -35
- data/example/wobble.rb +24 -24
- data/lib/vips.rb +335 -312
- data/lib/vips/access.rb +9 -9
- data/lib/vips/align.rb +7 -8
- data/lib/vips/angle.rb +8 -9
- data/lib/vips/angle45.rb +12 -13
- data/lib/vips/bandformat.rb +16 -18
- data/lib/vips/blend_mode.rb +32 -0
- data/lib/vips/coding.rb +11 -12
- data/lib/vips/compass_direction.rb +13 -14
- data/lib/vips/direction.rb +7 -8
- data/lib/vips/extend.rb +13 -14
- data/lib/vips/gobject.rb +92 -96
- data/lib/vips/gvalue.rb +231 -237
- data/lib/vips/image.rb +1329 -1330
- data/lib/vips/interesting.rb +10 -11
- data/lib/vips/interpolate.rb +49 -54
- data/lib/vips/interpretation.rb +25 -26
- data/lib/vips/kernel.rb +18 -19
- data/lib/vips/methods.rb +2319 -2141
- data/lib/vips/object.rb +204 -213
- data/lib/vips/operation.rb +317 -323
- data/lib/vips/operationboolean.rb +10 -11
- data/lib/vips/operationcomplex.rb +8 -9
- data/lib/vips/operationcomplex2.rb +6 -7
- data/lib/vips/operationcomplexget.rb +7 -8
- data/lib/vips/operationmath.rb +14 -15
- data/lib/vips/operationmath2.rb +6 -7
- data/lib/vips/operationrelational.rb +11 -12
- data/lib/vips/operationround.rb +7 -8
- data/lib/vips/size.rb +9 -10
- data/lib/vips/version.rb +1 -1
- data/vips.gemspec +1 -1
- 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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
41
|
-
|
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
|
-
|
48
|
-
|
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
|
-
|
51
|
-
|
52
|
-
::GObject::g_value_unset ptr
|
53
|
-
end
|
46
|
+
enum_name.to_sym
|
47
|
+
end
|
54
48
|
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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
|
-
|
90
|
-
|
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
|
-
|
93
|
-
|
94
|
-
::GObject::g_value_set_boolean self, (value ? 1 : 0)
|
88
|
+
gtype = self[:gtype]
|
89
|
+
fundamental = ::GObject::g_type_fundamental gtype
|
95
90
|
|
96
|
-
|
97
|
-
|
91
|
+
case gtype
|
92
|
+
when GBOOL_TYPE
|
93
|
+
::GObject::g_value_set_boolean self, (value ? 1 : 0)
|
98
94
|
|
99
|
-
|
100
|
-
|
95
|
+
when GINT_TYPE
|
96
|
+
::GObject::g_value_set_int self, value
|
101
97
|
|
102
|
-
|
103
|
-
|
98
|
+
when GUINT64_TYPE
|
99
|
+
::GObject::g_value_set_uint64 self, value
|
104
100
|
|
105
|
-
|
106
|
-
|
101
|
+
when GDOUBLE_TYPE
|
102
|
+
::GObject::g_value_set_double self, value
|
107
103
|
|
108
|
-
|
109
|
-
|
104
|
+
when GSTR_TYPE
|
105
|
+
::GObject::g_value_set_string self, value
|
110
106
|
|
111
|
-
|
112
|
-
|
107
|
+
when Vips::REFSTR_TYPE
|
108
|
+
::Vips::vips_value_set_ref_string self, value
|
113
109
|
|
114
|
-
|
115
|
-
|
116
|
-
ptr.write_array_of_int32 value
|
110
|
+
when Vips::ARRAY_INT_TYPE
|
111
|
+
value = [value] unless value.is_a? Array
|
117
112
|
|
118
|
-
|
119
|
-
|
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
|
-
|
122
|
-
|
117
|
+
when Vips::ARRAY_DOUBLE_TYPE
|
118
|
+
value = [value] unless value.is_a? Array
|
123
119
|
|
124
|
-
|
125
|
-
|
120
|
+
# this will allocate an array in the gvalue
|
121
|
+
Vips::vips_value_set_array_double self, nil, value.length
|
126
122
|
|
127
|
-
|
123
|
+
# pull the array out and fill it
|
124
|
+
ptr = Vips::vips_value_get_array_double self, nil
|
128
125
|
|
129
|
-
|
130
|
-
value = [value] unless value.is_a? Array
|
126
|
+
ptr.write_array_of_double value
|
131
127
|
|
132
|
-
|
133
|
-
|
134
|
-
ptr.write_array_of_pointer value
|
128
|
+
when Vips::ARRAY_IMAGE_TYPE
|
129
|
+
value = [value] unless value.is_a? Array
|
135
130
|
|
136
|
-
|
137
|
-
|
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
|
-
|
140
|
-
|
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
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
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
|
-
|
151
|
-
|
152
|
-
|
144
|
+
else
|
145
|
+
case fundamental
|
146
|
+
when GFLAGS_TYPE
|
147
|
+
::GObject::g_value_set_flags self, value
|
153
148
|
|
154
|
-
|
155
|
-
|
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
|
-
|
158
|
-
|
159
|
-
"#{::GObject::g_type_name gtype} (#{gtype})"
|
153
|
+
when GOBJECT_TYPE
|
154
|
+
::GObject::g_value_set_object self, value
|
160
155
|
|
161
|
-
|
162
|
-
|
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
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
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
|
-
|
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
|
-
|
252
|
-
|
253
|
-
|
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
|