vips 8.10.5 → 8.12.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +42 -0
- data/.github/workflows/development.yml +54 -0
- data/.standard.yml +17 -0
- data/.yardopts +0 -1
- data/CHANGELOG.md +330 -0
- data/Gemfile +8 -1
- data/README.md +52 -14
- data/Rakefile +23 -18
- data/TODO +43 -0
- data/example/annotate.rb +6 -6
- data/example/connection.rb +18 -9
- data/example/daltonize8.rb +6 -6
- data/example/draw_lines.rb +30 -0
- data/example/example1.rb +4 -4
- data/example/example2.rb +6 -6
- data/example/example3.rb +5 -5
- data/example/example4.rb +2 -2
- data/example/example5.rb +4 -4
- data/example/inheritance_with_refcount.rb +46 -39
- data/example/progress.rb +3 -3
- data/example/thumb.rb +6 -6
- data/example/trim8.rb +1 -1
- data/example/watermark.rb +2 -2
- data/example/wobble.rb +1 -1
- data/lib/vips/blend_mode.rb +29 -25
- data/lib/vips/connection.rb +4 -4
- data/lib/vips/gobject.rb +18 -11
- data/lib/vips/gvalue.rb +54 -54
- data/lib/vips/image.rb +362 -169
- data/lib/vips/interpolate.rb +3 -2
- data/lib/vips/methods.rb +2877 -2319
- data/lib/vips/mutableimage.rb +180 -0
- data/lib/vips/object.rb +81 -88
- data/lib/vips/operation.rb +175 -82
- data/lib/vips/region.rb +6 -6
- data/lib/vips/source.rb +11 -12
- data/lib/vips/sourcecustom.rb +7 -8
- data/lib/vips/target.rb +12 -13
- data/lib/vips/targetcustom.rb +9 -10
- data/lib/vips/version.rb +1 -1
- data/lib/vips.rb +216 -86
- data/vips.gemspec +9 -10
- metadata +22 -43
data/example/connection.rb
CHANGED
@@ -1,17 +1,26 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
|
-
require
|
3
|
+
require "vips"
|
4
|
+
require "down/http"
|
5
|
+
|
6
|
+
# byte_source = File.open ARGV[0], "rb"
|
7
|
+
# eg. https://images.unsplash.com/photo-1491933382434-500287f9b54b
|
8
|
+
byte_source = Down::Http.open(ARGV[0])
|
4
9
|
|
5
|
-
file = File.open ARGV[0], "rb"
|
6
10
|
source = Vips::SourceCustom.new
|
7
|
-
source.on_read
|
8
|
-
|
9
|
-
|
11
|
+
source.on_read do |length|
|
12
|
+
puts "reading #{length} bytes ..."
|
13
|
+
byte_source.read length
|
14
|
+
end
|
15
|
+
source.on_seek do |offset, whence|
|
16
|
+
puts "seeking to #{offset}, #{whence}"
|
17
|
+
byte_source.seek(offset, whence)
|
18
|
+
end
|
10
19
|
|
11
|
-
|
20
|
+
byte_target = File.open ARGV[1], "wb"
|
12
21
|
target = Vips::TargetCustom.new
|
13
|
-
target.on_write { |chunk|
|
14
|
-
target.on_finish {
|
22
|
+
target.on_write { |chunk| byte_target.write(chunk) }
|
23
|
+
target.on_finish { byte_target.close }
|
15
24
|
|
16
25
|
image = Vips::Image.new_from_source source, "", access: :sequential
|
17
|
-
image.write_to_target target, ".
|
26
|
+
image.write_to_target target, ".jpg"
|
data/example/daltonize8.rb
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
# http://libvips.blogspot.co.uk/2013/05/daltonize-in-ruby-vips-carrierwave-and.html
|
8
8
|
# for a discussion of this code
|
9
9
|
|
10
|
-
require
|
10
|
+
require "vips"
|
11
11
|
|
12
12
|
# Vips.set_debug true
|
13
13
|
|
@@ -29,13 +29,13 @@ im = Vips::Image.new_from_file ARGV[0]
|
|
29
29
|
alpha = nil
|
30
30
|
if im.bands == 4
|
31
31
|
alpha = im[3]
|
32
|
-
im = im.extract_band 0, :
|
32
|
+
im = im.extract_band 0, n: 3
|
33
33
|
end
|
34
34
|
|
35
35
|
begin
|
36
36
|
# import to XYZ with lcms
|
37
37
|
# if there's no profile there, we'll fall back to the thing below
|
38
|
-
xyz = im.icc_import :
|
38
|
+
xyz = im.icc_import embedded: true, pcs: :xyz
|
39
39
|
rescue Vips::Error
|
40
40
|
# nope .. use the built-in converter instead
|
41
41
|
xyz = im.colourspace :xyz
|
@@ -61,9 +61,9 @@ rgb = xyz.colourspace :srgb
|
|
61
61
|
err = im - rgb
|
62
62
|
|
63
63
|
# add the error back to other channels to make a compensated image
|
64
|
-
im
|
65
|
-
|
66
|
-
|
64
|
+
im += err.recomb([[0, 0, 0],
|
65
|
+
[0.7, 1, 0],
|
66
|
+
[0.7, 0, 1]])
|
67
67
|
|
68
68
|
# reattach any alpha we saved above
|
69
69
|
if alpha
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require "vips"
|
4
|
+
|
5
|
+
# load and stream into memory
|
6
|
+
image = Vips::Image.new_from_file(ARGV[0], access: :sequential).copy_memory
|
7
|
+
|
8
|
+
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
9
|
+
|
10
|
+
lines = image
|
11
|
+
(0..1).step 0.01 do |i|
|
12
|
+
lines = lines.draw_line 255, lines.width * i, 0, 0, lines.height * (1 - i)
|
13
|
+
end
|
14
|
+
|
15
|
+
ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
16
|
+
puts "non-destructive took #{ending - starting}s"
|
17
|
+
|
18
|
+
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
19
|
+
|
20
|
+
lines = image
|
21
|
+
lines = lines.mutate do |x|
|
22
|
+
(0..1).step 0.01 do |i|
|
23
|
+
x.draw_line! 255, x.width * i, 0, 0, x.height * (1 - i)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
28
|
+
puts "mutate took #{ending - starting}s"
|
29
|
+
|
30
|
+
lines.write_to_file ARGV[1]
|
data/example/example1.rb
CHANGED
data/example/example2.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "logger"
|
4
|
+
require "vips"
|
5
5
|
|
6
6
|
puts ""
|
7
7
|
puts "starting up:"
|
8
8
|
|
9
9
|
# this makes vips keep a list of all active objects which we can print out
|
10
|
-
Vips
|
10
|
+
Vips.leak_set true
|
11
11
|
|
12
12
|
# disable the operation cache
|
13
|
-
Vips
|
13
|
+
Vips.cache_set_max 0
|
14
14
|
|
15
15
|
# GLib::logger.level = Logger::DEBUG
|
16
16
|
|
@@ -20,7 +20,7 @@ n.times do |i|
|
|
20
20
|
puts ""
|
21
21
|
puts "call #{i} ..."
|
22
22
|
out = Vips::Operation.call "black", [200, 300]
|
23
|
-
if out.width != 200
|
23
|
+
if out.width != 200 || out.height != 300
|
24
24
|
puts "bad image result from black"
|
25
25
|
end
|
26
26
|
end
|
@@ -28,7 +28,7 @@ end
|
|
28
28
|
puts ""
|
29
29
|
puts "after #{n} calls:"
|
30
30
|
GC.start
|
31
|
-
Vips::Object
|
31
|
+
Vips::Object.print_all
|
32
32
|
|
33
33
|
puts ""
|
34
34
|
puts "shutting down:"
|
data/example/example3.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
|
-
require
|
3
|
+
require "vips"
|
4
4
|
|
5
5
|
# this makes vips keep a list of all active objects
|
6
|
-
Vips
|
6
|
+
Vips.leak_set true
|
7
7
|
|
8
8
|
# disable the operation cache
|
9
9
|
# Vips::cache_set_max 0
|
10
10
|
|
11
11
|
# turn on debug logging
|
12
|
-
GLib
|
12
|
+
GLib.logger.level = Logger::DEBUG
|
13
13
|
|
14
|
-
|
14
|
+
10.times do |i|
|
15
15
|
puts "loop #{i} ..."
|
16
16
|
im = Vips::Image.new_from_file ARGV[0]
|
17
|
-
im = im.embed 100, 100, 3000, 3000, :
|
17
|
+
im = im.embed 100, 100, 3000, 3000, extend: :mirror
|
18
18
|
im.write_to_file "x.v"
|
19
19
|
end
|
data/example/example4.rb
CHANGED
data/example/example5.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
|
-
require
|
3
|
+
require "vips"
|
4
4
|
|
5
5
|
# this makes vips keep a list of all active objects
|
6
6
|
# Vips::leak_set true
|
@@ -15,7 +15,7 @@ if ARGV.length < 2
|
|
15
15
|
raise "usage: #{$PROGRAM_NAME}: input-file output-file"
|
16
16
|
end
|
17
17
|
|
18
|
-
im = Vips::Image.new_from_file ARGV[0], :
|
18
|
+
im = Vips::Image.new_from_file ARGV[0], access: :sequential
|
19
19
|
|
20
20
|
im *= [1, 2, 1]
|
21
21
|
|
@@ -23,8 +23,8 @@ im *= [1, 2, 1]
|
|
23
23
|
# make it ourselves
|
24
24
|
# if you are OK with scale=1, you can just pass the array directly to .conv()
|
25
25
|
mask = Vips::Image.new_from_array [[-1, -1, -1],
|
26
|
-
|
27
|
-
|
26
|
+
[-1, 16, -1],
|
27
|
+
[-1, -1, -1]], 8
|
28
28
|
im = im.conv mask
|
29
29
|
|
30
30
|
im.write_to_file ARGV[1]
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "ffi"
|
4
|
+
require "forwardable"
|
5
5
|
|
6
6
|
# this is really very crude logging
|
7
7
|
|
@@ -29,7 +29,7 @@ end
|
|
29
29
|
|
30
30
|
module GLib
|
31
31
|
extend FFI::Library
|
32
|
-
ffi_lib
|
32
|
+
ffi_lib "gobject-2.0"
|
33
33
|
|
34
34
|
def self.set_log_domain(_domain)
|
35
35
|
# FIXME: this needs hooking up
|
@@ -68,8 +68,8 @@ module GLib
|
|
68
68
|
def self.included(base)
|
69
69
|
base.class_eval do
|
70
70
|
layout :g_type_instance, :pointer,
|
71
|
-
|
72
|
-
|
71
|
+
:ref_count, :uint,
|
72
|
+
:qdata, :pointer
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
@@ -85,7 +85,7 @@ module GLib
|
|
85
85
|
|
86
86
|
def self.release(ptr)
|
87
87
|
log "GLib::GObject::ManagedStruct.release: unreffing #{ptr}"
|
88
|
-
GLib
|
88
|
+
GLib.g_object_unref(ptr) unless ptr.null?
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
@@ -116,7 +116,7 @@ module GLib
|
|
116
116
|
|
117
117
|
class << self
|
118
118
|
def ffi_struct
|
119
|
-
|
119
|
+
const_get(:Struct)
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
@@ -127,24 +127,32 @@ module GLib
|
|
127
127
|
|
128
128
|
class << self
|
129
129
|
def ffi_managed_struct
|
130
|
-
|
130
|
+
const_get(:ManagedStruct)
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
-
#
|
136
|
-
|
135
|
+
# we can't just use ulong, windows has different int sizing rules
|
136
|
+
if FFI::Platform::ADDRESS_SIZE == 64
|
137
|
+
typedef :uint64, :GType
|
138
|
+
else
|
139
|
+
typedef :uint32, :GType
|
140
|
+
end
|
137
141
|
end
|
138
142
|
|
139
143
|
module Vips
|
140
144
|
extend FFI::Library
|
141
|
-
ffi_lib
|
145
|
+
ffi_lib "vips"
|
142
146
|
|
143
147
|
LOG_DOMAIN = "VIPS"
|
144
|
-
GLib
|
148
|
+
GLib.set_log_domain(LOG_DOMAIN)
|
145
149
|
|
146
150
|
# need to repeat this
|
147
|
-
|
151
|
+
if FFI::Platform::ADDRESS_SIZE == 64
|
152
|
+
typedef :uint64, :GType
|
153
|
+
else
|
154
|
+
typedef :uint32, :GType
|
155
|
+
end
|
148
156
|
|
149
157
|
attach_function :vips_init, [:string], :int
|
150
158
|
attach_function :vips_shutdown, [], :void
|
@@ -153,19 +161,19 @@ module Vips
|
|
153
161
|
attach_function :vips_error_clear, [], :void
|
154
162
|
|
155
163
|
def self.get_error
|
156
|
-
errstr = Vips
|
157
|
-
Vips
|
164
|
+
errstr = Vips.vips_error_buffer
|
165
|
+
Vips.vips_error_clear
|
158
166
|
errstr
|
159
167
|
end
|
160
168
|
|
161
|
-
if Vips
|
162
|
-
puts Vips
|
169
|
+
if Vips.vips_init($0) != 0
|
170
|
+
puts Vips.get_error
|
163
171
|
exit 1
|
164
172
|
end
|
165
173
|
|
166
|
-
at_exit
|
167
|
-
Vips
|
168
|
-
|
174
|
+
at_exit do
|
175
|
+
Vips.vips_shutdown
|
176
|
+
end
|
169
177
|
|
170
178
|
attach_function :vips_object_print_all, [], :void
|
171
179
|
attach_function :vips_leak_set, [:int], :void
|
@@ -188,15 +196,15 @@ module Vips
|
|
188
196
|
base.class_eval do
|
189
197
|
# don't actually need most of these, remove them later
|
190
198
|
layout :parent, GLib::GObject::Struct,
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
199
|
+
:constructed, :int,
|
200
|
+
:static_object, :int,
|
201
|
+
:argument_table, :pointer,
|
202
|
+
:nickname, :string,
|
203
|
+
:description, :string,
|
204
|
+
:preclose, :int,
|
205
|
+
:close, :int,
|
206
|
+
:postclose, :int,
|
207
|
+
:local_memory, :size_t
|
200
208
|
end
|
201
209
|
end
|
202
210
|
end
|
@@ -250,7 +258,7 @@ module Vips
|
|
250
258
|
end
|
251
259
|
|
252
260
|
def self.new_partial
|
253
|
-
VipsImage.new(Vips
|
261
|
+
VipsImage.new(Vips.vips_image_new)
|
254
262
|
end
|
255
263
|
end
|
256
264
|
|
@@ -258,12 +266,11 @@ module Vips
|
|
258
266
|
end
|
259
267
|
|
260
268
|
puts "creating image"
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
end
|
269
|
+
|
270
|
+
x = Vips::VipsImage.new_partial
|
271
|
+
puts "x = #{x}"
|
272
|
+
puts ""
|
273
|
+
puts "x[:parent] = #{x[:parent]}"
|
274
|
+
puts ""
|
275
|
+
puts "x[:parent][:description] = #{x[:parent][:description]}"
|
276
|
+
puts ""
|
data/example/progress.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
|
-
require
|
3
|
+
require "vips"
|
4
4
|
|
5
5
|
image = Vips::Image.black 1, 100000
|
6
6
|
image.set_progress true
|
@@ -12,11 +12,11 @@ def progress_to_s(name, progress)
|
|
12
12
|
puts " progress.tpels = #{progress[:tpels]}"
|
13
13
|
puts " progress.npels = #{progress[:npels]}"
|
14
14
|
puts " progress.percent = #{progress[:percent]}"
|
15
|
-
end
|
15
|
+
end
|
16
16
|
|
17
17
|
image.signal_connect :preeval do |progress|
|
18
18
|
progress_to_s("preeval", progress)
|
19
|
-
end
|
19
|
+
end
|
20
20
|
|
21
21
|
image.signal_connect :eval do |progress|
|
22
22
|
progress_to_s("eval", progress)
|
data/example/thumb.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
#!/usr/bin/
|
1
|
+
#!/usr/bin/ruby
|
2
2
|
|
3
3
|
# batch-process a lot of files
|
4
4
|
#
|
5
5
|
# this should run in constant memory -- if it doesn't, something has broken
|
6
6
|
|
7
|
-
require
|
7
|
+
require "vips"
|
8
8
|
|
9
9
|
# benchmark thumbnail via a memory buffer
|
10
10
|
def via_memory(filename, thumbnail_width)
|
11
11
|
data = IO.binread(filename)
|
12
12
|
|
13
|
-
thumb = Vips::Image.thumbnail_buffer data, thumbnail_width, crop:
|
13
|
+
thumb = Vips::Image.thumbnail_buffer data, thumbnail_width, crop: "centre"
|
14
14
|
|
15
|
-
thumb.write_to_buffer
|
15
|
+
thumb.write_to_buffer ".jpg"
|
16
16
|
end
|
17
17
|
|
18
18
|
# benchmark thumbnail via files
|
19
19
|
def via_files(filename, thumbnail_width)
|
20
|
-
thumb = Vips::Image.thumbnail filename, thumbnail_width, crop:
|
20
|
+
thumb = Vips::Image.thumbnail filename, thumbnail_width, crop: "centre"
|
21
21
|
|
22
|
-
thumb.write_to_buffer
|
22
|
+
thumb.write_to_buffer ".jpg"
|
23
23
|
end
|
24
24
|
|
25
25
|
ARGV.each do |filename|
|
data/example/trim8.rb
CHANGED
data/example/watermark.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
|
-
require
|
3
|
+
require "vips"
|
4
4
|
|
5
5
|
im = Vips::Image.new_from_file ARGV[0], access: :sequential
|
6
6
|
|
7
7
|
# make the text mask
|
8
|
-
text = Vips::Image.text ARGV[2], width: 200, dpi: 200, font:
|
8
|
+
text = Vips::Image.text ARGV[2], width: 200, dpi: 200, font: "sans bold"
|
9
9
|
text = text.rotate(-45)
|
10
10
|
# make the text transparent
|
11
11
|
text = (text * 0.3).cast(:uchar)
|
data/example/wobble.rb
CHANGED
data/lib/vips/blend_mode.rb
CHANGED
@@ -1,31 +1,35 @@
|
|
1
1
|
module Vips
|
2
2
|
# Blend mode to use when compositing images. See {Image#composite}.
|
3
3
|
#
|
4
|
-
# `:clear`
|
5
|
-
# `:source`
|
6
|
-
# `:over`
|
7
|
-
#
|
8
|
-
# `:
|
9
|
-
#
|
10
|
-
# `:
|
11
|
-
# `:
|
12
|
-
#
|
13
|
-
# `:
|
14
|
-
#
|
15
|
-
# `:
|
16
|
-
# `:
|
17
|
-
# `:
|
18
|
-
# `:
|
19
|
-
# `:
|
20
|
-
# `:
|
21
|
-
# `:
|
22
|
-
# `:
|
23
|
-
# `:
|
24
|
-
# `:
|
25
|
-
# `:
|
26
|
-
# `:
|
27
|
-
# `:
|
28
|
-
# `:
|
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
|
29
33
|
|
30
34
|
class BlendMode < Symbol
|
31
35
|
end
|
data/lib/vips/connection.rb
CHANGED
@@ -4,10 +4,10 @@
|
|
4
4
|
# Author:: John Cupitt (mailto:jcupitt@gmail.com)
|
5
5
|
# License:: MIT
|
6
6
|
|
7
|
-
require
|
7
|
+
require "ffi"
|
8
8
|
|
9
9
|
module Vips
|
10
|
-
if Vips
|
10
|
+
if Vips.at_least_libvips?(8, 9)
|
11
11
|
attach_function :vips_connection_filename, [:pointer], :string
|
12
12
|
attach_function :vips_connection_nick, [:pointer], :string
|
13
13
|
end
|
@@ -34,13 +34,13 @@ module Vips
|
|
34
34
|
|
35
35
|
# Get any filename associated with a connection, or nil.
|
36
36
|
def filename
|
37
|
-
Vips
|
37
|
+
Vips.vips_connection_filename self
|
38
38
|
end
|
39
39
|
|
40
40
|
# Get a nickname (short description) of a connection that could be shown to
|
41
41
|
# the user.
|
42
42
|
def nick
|
43
|
-
Vips
|
43
|
+
Vips.vips_connection_nick self
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
data/lib/vips/gobject.rb
CHANGED
@@ -4,8 +4,8 @@
|
|
4
4
|
# Author:: John Cupitt (mailto:jcupitt@gmail.com)
|
5
5
|
# License:: MIT
|
6
6
|
|
7
|
-
require
|
8
|
-
require
|
7
|
+
require "ffi"
|
8
|
+
require "forwardable"
|
9
9
|
|
10
10
|
module GObject
|
11
11
|
# we have a number of things we need to inherit in different ways:
|
@@ -37,13 +37,15 @@ module GObject
|
|
37
37
|
def_instance_delegators :@struct, :[], :to_ptr
|
38
38
|
def_single_delegators :ffi_struct, :ptr
|
39
39
|
|
40
|
+
attr_reader :references
|
41
|
+
|
40
42
|
# the layout of the GObject struct
|
41
43
|
module GObjectLayout
|
42
44
|
def self.included base
|
43
45
|
base.class_eval do
|
44
46
|
layout :g_type_instance, :pointer,
|
45
|
-
|
46
|
-
|
47
|
+
:ref_count, :uint,
|
48
|
+
:qdata, :pointer
|
47
49
|
end
|
48
50
|
end
|
49
51
|
end
|
@@ -56,7 +58,7 @@ module GObject
|
|
56
58
|
# GLib::logger.debug("GObject::GObject::ManagedStruct.release") {
|
57
59
|
# "unreffing #{ptr}"
|
58
60
|
# }
|
59
|
-
::GObject
|
61
|
+
::GObject.g_object_unref ptr
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|
@@ -72,6 +74,7 @@ module GObject
|
|
72
74
|
# need the unref
|
73
75
|
def initialize ptr
|
74
76
|
# GLib::logger.debug("GObject::GObject.initialize") {"ptr = #{ptr}"}
|
77
|
+
@ptr = ptr
|
75
78
|
@struct = ffi_managed_struct.new ptr
|
76
79
|
|
77
80
|
# sometimes we need to keep refs across C calls ... hide them here
|
@@ -83,9 +86,13 @@ module GObject
|
|
83
86
|
self.class.ffi_struct
|
84
87
|
end
|
85
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
|
+
|
86
93
|
class << self
|
87
94
|
def ffi_struct
|
88
|
-
|
95
|
+
const_get :Struct
|
89
96
|
end
|
90
97
|
end
|
91
98
|
|
@@ -96,7 +103,7 @@ module GObject
|
|
96
103
|
|
97
104
|
class << self
|
98
105
|
def ffi_managed_struct
|
99
|
-
|
106
|
+
const_get :ManagedStruct
|
100
107
|
end
|
101
108
|
end
|
102
109
|
end
|
@@ -104,10 +111,10 @@ module GObject
|
|
104
111
|
class GParamSpec < FFI::Struct
|
105
112
|
# the first few public fields
|
106
113
|
layout :g_type_instance, :pointer,
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
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
|