Skip to content

Commit 661eeee

Browse files
committed
lots of small fixups
- regen autodocs with 8.5 - clean up code - add VipsInterpolation support, plus a test - Operation.new can take a name - remove a lot of debug logging - fixes for imageize
1 parent f546fcd commit 661eeee

File tree

10 files changed

+234
-244
lines changed

10 files changed

+234
-244
lines changed

TODO

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
# Notes
22

3-
- regen docs with 8.5
3+
- speed up to_a, see the issue on this
44

5-
- revise docs ... we have a few undocumented still, they should probably be
5+
change should be in master as well
6+
7+
- check over docs ... we have a few undocumented still, they should probably be
68
private
79

8-
- look over code and use eg. select in thing that searches for match_image
10+
- make inspect output prettier
11+
12+
irb(main):002:0> im = Vips::Image.black(100, 100)
13+
=> #<Vips::Image:0x005607119ce000 @struct=#<Vips::Image::ManagedStruct:0x005607119cdf88>>
914

10-
- check VipsInterpolation and affine with bicubic etc.
15+
bit crap
1116

12-
- make Operation.new take a nick, not a pointer
17+
same for gvalue?
1318

1419
- support complex constants, eg.
1520

lib/vips.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def self.set_log_domain(domain)
3434
GENUM_TYPE = g_type_from_name("GEnum")
3535
GFLAGS_TYPE = g_type_from_name("GFlags")
3636
GSTR_TYPE = g_type_from_name("gchararray")
37+
GOBJECT_TYPE = g_type_from_name("GObject")
3738
end
3839

3940
require 'vips/gobject'
@@ -130,6 +131,7 @@ def self.showall
130131
require 'vips/object'
131132
require 'vips/operation'
132133
require 'vips/image'
134+
require 'vips/interpolate'
133135
require 'vips/version'
134136

135137

lib/vips/gobject.rb

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class GObject
3838

3939
# the layout of the GObject struct
4040
module GObjectLayout
41-
def self.included(base)
41+
def self.included base
4242
base.class_eval do
4343
layout :g_type_instance, :pointer,
4444
:ref_count, :uint,
@@ -51,14 +51,9 @@ def self.included(base)
5151
class ManagedStruct < FFI::ManagedStruct
5252
include GObjectLayout
5353

54-
def initialize(ptr)
55-
Vips::log "GLib::GObject::ManagedStruct.new: #{ptr}"
56-
super
57-
end
58-
59-
def self.release(ptr)
60-
Vips::log "GLib::GObject::ManagedStruct.release: " +
61-
"unreffing #{ptr}"
54+
def self.release ptr
55+
# Vips::log "GLib::GObject::ManagedStruct.release: " +
56+
# "unreffing #{ptr}"
6257
GLib::g_object_unref(ptr) unless ptr.null?
6358
end
6459
end
@@ -67,21 +62,16 @@ def self.release(ptr)
6762
class Struct < FFI::Struct
6863
include GObjectLayout
6964

70-
def initialize(ptr)
71-
Vips::log "GLib::GObject::Struct.new: #{ptr}"
72-
super
73-
end
74-
7565
end
7666

7767
# don't allow ptr == nil, we never want to allocate a GObject struct
7868
# ourselves, we just want to wrap GLib-allocated GObjects
7969
#
8070
# here we use ManagedStruct, not Struct, since this is the ref that will
8171
# need the unref
82-
def initialize(ptr)
83-
Vips::log "GLib::GObject.initialize: ptr = #{ptr}"
84-
@struct = ffi_managed_struct.new(ptr)
72+
def initialize ptr
73+
# Vips::log "GLib::GObject.initialize: ptr = #{ptr}"
74+
@struct = ffi_managed_struct.new ptr
8575
end
8676

8777
# access to the casting struct for this class
@@ -91,7 +81,7 @@ def ffi_struct
9181

9282
class << self
9383
def ffi_struct
94-
self.const_get(:Struct)
84+
self.const_get :Struct
9585
end
9686
end
9787

@@ -102,7 +92,7 @@ def ffi_managed_struct
10292

10393
class << self
10494
def ffi_managed_struct
105-
self.const_get(:ManagedStruct)
95+
self.const_get :ManagedStruct
10696
end
10797
end
10898

lib/vips/gvalue.rb

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,59 @@ class GValue < FFI::ManagedStruct
1010
layout :gtype, :GType,
1111
:data, [:ulong_long, 2]
1212

13-
def self.release(ptr)
14-
Vips::log "GLib::GValue::release ptr = #{ptr}"
15-
GLib::g_value_unset(ptr)
13+
def self.release ptr
14+
# Vips::log "GLib::GValue::release ptr = #{ptr}"
15+
GLib::g_value_unset ptr
1616
end
1717

1818
G_FREE_CALLBACK = Proc.new do |ptr|
1919
Vips::g_free ptr
2020
end
2121

2222
def self.alloc
23-
# we seem to need the extra cast, I'm not sure why
23+
# allocate memory
2424
memory = FFI::MemoryPointer.new GValue
25+
26+
# make this alloc autorelease ... we mustn't release in
27+
# GValue::release, since we are used to wrap GValue pointers
28+
# made by other people
2529
pointer = FFI::Pointer.new GValue, memory
26-
GValue.new(pointer)
30+
31+
# ... and wrap in a GValue
32+
GValue.new pointer
2733
end
2834

29-
def init(gtype)
30-
GLib::g_value_init(self, gtype)
35+
def init gtype
36+
GLib::g_value_init self, gtype
3137
end
3238

33-
def set(value)
34-
Vips::log "GLib::GValue.set: value = #{value}"
39+
def set value
40+
# Vips::log "GLib::GValue.set: value = #{value}"
3541

3642
gtype = self[:gtype]
3743
fundamental = GLib::g_type_fundamental gtype
3844

3945
case gtype
4046
when GBOOL_TYPE
4147
GLib::g_value_set_boolean self, (value ? 1 : 0)
48+
4249
when GINT_TYPE
4350
GLib::g_value_set_int self, value
51+
4452
when GDOUBLE_TYPE
4553
GLib::g_value_set_double self, value
54+
4655
when GSTR_TYPE
4756
# set_string takes a copy, no lifetime worries
4857
GLib::g_value_set_string self, value
49-
when Vips::IMAGE_TYPE
50-
# g_value_set_object() will add an extra ref
51-
GLib::g_value_set_object self, value
52-
GLib::g_object_unref value
58+
5359
when Vips::ARRAY_INT_TYPE
5460
value = [value] if not value.is_a? Array
5561

5662
Vips::vips_value_set_array_int self, nil, value.length
5763
ptr = Vips::vips_value_get_array_int self, nil
5864
ptr.write_array_of_int32 value
65+
5966
when Vips::ARRAY_DOUBLE_TYPE
6067
value = [value] if not value.is_a? Array
6168

@@ -66,6 +73,7 @@ def set(value)
6673
ptr = Vips::vips_value_get_array_double self, nil
6774

6875
ptr.write_array_of_double value
76+
6977
when Vips::ARRAY_IMAGE_TYPE
7078
value = [value] if not value.is_a? Array
7179

@@ -75,15 +83,18 @@ def set(value)
7583

7684
# the gvalue needs a ref on each of the images
7785
value.each {|image| GLib::g_object_ref image}
86+
7887
when Vips::BLOB_TYPE
79-
ptr = GLib::g_malloc value.length
80-
ptr.write_bytes(value)
81-
Vips::vips_value_set_blob self,
82-
G_FREE_CALLBACK, ptr, value.length
88+
len = value.length
89+
ptr = GLib::g_malloc len
90+
ptr.write_bytes value
91+
Vips::vips_value_set_blob self, G_FREE_CALLBACK, ptr, len
92+
8393
else
8494
case fundamental
8595
when GFLAGS_TYPE
8696
GLib::g_value_set_flags self, value
97+
8798
when GENUM_TYPE
8899
value = value.to_s if value.is_a? Symbol
89100

@@ -96,6 +107,12 @@ def set(value)
96107
end
97108

98109
GLib::g_value_set_enum self, value
110+
111+
when GOBJECT_TYPE
112+
# g_value_set_object() will add an extra ref
113+
GLib::g_value_set_object self, value
114+
GLib::g_object_unref value
115+
99116
else
100117
raise Vips::Error, "unimplemented gtype for set: #{gtype}"
101118
end
@@ -110,25 +127,27 @@ def get
110127
case gtype
111128
when GBOOL_TYPE
112129
result = GLib::g_value_get_boolean(self) != 0 ? true : false
130+
113131
when GINT_TYPE
114-
result = GLib::g_value_get_int(self)
132+
result = GLib::g_value_get_int self
133+
115134
when GDOUBLE_TYPE
116-
result = GLib::g_value_get_double(self)
135+
result = GLib::g_value_get_double self
136+
117137
when GSTR_TYPE
118138
# FIXME do we need to strdup here?
119139
result = GLib::g_value_get_string self
120-
when Vips::IMAGE_TYPE
121-
# g_value_get_object() does not add a ref
122-
obj = GLib::g_value_get_object self
123-
result = Vips::Image.new obj
140+
124141
when Vips::ARRAY_INT_TYPE
125142
len = Vips::IntStruct.new
126143
array = Vips::vips_value_get_array_int self, len
127144
result = array.get_array_of_int32 0, len[:value]
145+
128146
when Vips::ARRAY_DOUBLE_TYPE
129147
len = Vips::IntStruct.new
130148
array = Vips::vips_value_get_array_double self, len
131149
result = array.get_array_of_double 0, len[:value]
150+
132151
when Vips::ARRAY_IMAGE_TYPE
133152
len = Vips::IntStruct.new
134153
array = Vips::vips_value_get_array_image self, len
@@ -137,29 +156,39 @@ def get
137156
GLib::g_object_ref pointer
138157
Vips::Image.new pointer
139158
end
159+
140160
when Vips::BLOB_TYPE
141161
len = Vips::SizeStruct.new
142162
array = Vips::vips_value_get_blob self, len
143163
result = array.get_bytes 0, len[:value]
164+
144165
else
145166
case fundamental
146167
when GFLAGS_TYPE
147-
result = GLib::g_value_get_flags(self)
168+
result = GLib::g_value_get_flags self
169+
148170
when GENUM_TYPE
149-
enum_value = GLib::g_value_get_enum(self)
171+
enum_value = GLib::g_value_get_enum self
150172
# this returns a static string, no need to worry about
151173
# lifetime
152174
enum_name = Vips::vips_enum_nick self[:gtype], enum_value
153175
if enum_name == nil
154176
raise Vips::Error
155177
end
156178
result = enum_name.to_sym
179+
180+
when GOBJECT_TYPE
181+
# g_value_get_object() does not add a ref
182+
obj = GLib::g_value_get_object self
183+
result = Vips::Image.new obj
184+
157185
else
158186
raise Vips::Error, "unimplemented gtype for get: #{gtype}"
187+
159188
end
160189
end
161190

162-
Vips::log "GLib::GValue.get: result = #{result}"
191+
# Vips::log "GLib::GValue.get: result = #{result}"
163192

164193
return result
165194
end

0 commit comments

Comments
 (0)