Skip to content

Commit 6af58e4

Browse files
committed
more image done
still needs mutually recursive classes fixing
1 parent b476791 commit 6af58e4

File tree

7 files changed

+44
-41
lines changed

7 files changed

+44
-41
lines changed

Vips/__init__.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,29 @@ def log(msg):
2222

2323
is_PY2 = sys.version_info.major == 2
2424

25+
# GType is an int the size of a pointer ... I don't think we can just use
26+
# size_t, sadly
27+
if is_64bits:
28+
ffi.cdef('''
29+
typedef uint64_t GType;
30+
''')
31+
else:
32+
ffi.cdef('''
33+
typedef uint32_t GType;
34+
''')
35+
2536
ffi.cdef('''
2637
const char* vips_error_buffer (void);
2738
void vips_error_clear (void);
2839
2940
int vips_init (const char* argv0);
3041
3142
typedef struct _VipsImage VipsImage;
43+
typedef struct _GValue GValue;
3244
3345
void* g_malloc(size_t size);
3446
void g_free(void* data);
3547
36-
3748
''')
3849

3950
def error(msg):

Vips/gobject.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
3131
''')
3232

33-
class GObject:
33+
class GObject(object):
3434

3535
def __init__(self, pointer):
3636
# record the pointer we were given to manage

Vips/gvalue.py

+4-15
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@
44

55
from Vips import *
66

7-
# GType is an int the size of a pointer ... I don't think we can just use
8-
# size_t, sadly
9-
if is_64bits:
10-
ffi.cdef('''
11-
typedef uint64_t GType;
12-
''')
13-
else:
14-
ffi.cdef('''
15-
typedef uint32_t GType;
16-
''')
17-
187
ffi.cdef('''
198
typedef struct _GValue {
209
GType gtype;
@@ -65,7 +54,7 @@
6554
6655
''')
6756

68-
class GValue:
57+
class GValue(object):
6958

7059
# look up some common gtypes at init for speed
7160
gbool_type = gobject_lib.g_type_from_name('gboolean')
@@ -205,10 +194,10 @@ def get(self):
205194

206195
# we want a ref that will last with the life of the vimage:
207196
# this ref is matched by the unref that's attached to finalize
208-
# by Image.new()
197+
# by Image()
209198
gobject_lib.g_object_ref(go)
210199

211-
result = Image.new(vi)
200+
result = Image(vi)
212201
elif gtype == GValue.array_int_type:
213202
pint = ffi.new("int *")
214203

@@ -232,7 +221,7 @@ def get(self):
232221
# this will make a new cdata object
233222
vi = array[i]
234223

235-
result.append(Image.new(vi))
224+
result.append(Image(vi))
236225
elif gtype == GValue.blob_type:
237226
psize = ffi.new("size_t *")
238227

Vips/image.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def imageize(self, value):
8080

8181
def __init__(self, pointer):
8282
log('Image.__init__: pointer = {0}'.format(pointer))
83-
VipsObject.__init__(self, pointer)
83+
super(Image, self).__init__(pointer)
8484

8585
@staticmethod
8686
def new_from_file(vips_filename, **kwargs):

Vips/operation.py

+6-14
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
VipsOperation* vips_cache_operation_build (VipsOperation* operation);
2424
void vips_object_unref_outputs (VipsOperation *operation);
2525
26-
int vips_object_set_from_string (VipsObject* object, const char* options);
27-
2826
''')
2927

3028
# values for VipsOperationFlags
@@ -55,7 +53,7 @@ class Operation(VipsObject):
5553

5654
def __init__(self, pointer):
5755
log('Operation.__init__: pointer = {0}'.format(pointer))
58-
VipsObject.__init__(self, pointer)
56+
super(Operation, self).__init__(pointer)
5957

6058
def set(self, name, flags, match_image, value):
6159
# if the object wants an image and we have a constant, imageize it
@@ -76,7 +74,7 @@ def set(self, name, flags, match_image, value):
7674
# make sure we have a unique copy
7775
value = value.copy().copy_memory()
7876

79-
return self.set(name, value)
77+
super(Operation, self).set(name, value)
8078

8179
# this is slow ... call as little as possible
8280
def getargs(self):
@@ -147,7 +145,7 @@ def call(name, *args, **kwargs):
147145

148146
# set any string options before any args so they can't be
149147
# overridden
150-
if vips_lib.vips_object_set_from_string(op.pointer, string_options) != 0:
148+
if not op.set_string(string_options):
151149
error('unable to call {0}\n{1}'.format(name, vips_get_error()))
152150

153151
# set required and optional args
@@ -156,22 +154,16 @@ def call(name, *args, **kwargs):
156154
if ((flags & INPUT) != 0 and
157155
(flags & REQUIRED) != 0 and
158156
(flags & DEPRECATED) == 0):
159-
if not op.set(name, flags, match_image, args[n]):
160-
error('unable to call {0}\n{1]'.
161-
format(name, vips_get_error()))
162-
157+
op.set(name, flags, match_image, args[n])
163158
n += 1
164159

165160
for name, value in kwargs:
166-
flags = flags_from_name[name]
167-
168-
if not op.set(name, flags, match_image, value):
169-
error('unable to call {0}\n{1]'.format(name, vips_get_error()))
161+
op.set(name, flags_from_name[name], match_image, value)
170162

171163
# build operation
172164
vop2 = vips_lib.vips_cache_operation_build(op.pointer)
173165
if vop2 == ffi.NULL:
174-
error('unable to call {0}\n{1]'.format(name, vips_get_error()))
166+
error('unable to call {0}\n{1}'.format(name, vips_get_error()))
175167
op2 = Operation(vop2)
176168
op = op2
177169
op2 = None

Vips/vobject.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@
5656
5757
void vips_object_print_all (void);
5858
59+
int vips_object_set_from_string (VipsObject* object, const char* options);
60+
5961
''')
6062

6163
class VipsObject(GObject):
6264

6365
def __init__(self, pointer):
6466
log('VipsObject.__init__: pointer = {0}'.format(pointer))
65-
GObject.__init__(self, pointer)
67+
super(VipsObject, self).__init__(pointer)
6668

6769
@staticmethod
6870
def print_all(msg):
@@ -74,10 +76,11 @@ def print_all(msg):
7476
def get_typeof(self, name):
7577
log('VipsObject.get_typeof: self = {0}, name = {1}'.format(self, name))
7678

77-
pspec = ffi.new("(GParamSpec *)[1]");
78-
argument_class = ffi.new("(VipsArgumentClass *)[1]");
79-
argument_instance = ffi.new("(VipsArgumentInstance *)[1]");
80-
result = vips_lib.vips_object_get_argument(self.gobject, name,
79+
pspec = ffi.new("GParamSpec **");
80+
argument_class = ffi.new("VipsArgumentClass **");
81+
argument_instance = ffi.new("VipsArgumentInstance **");
82+
vo = ffi.cast("VipsObject *", self.pointer)
83+
result = vips_lib.vips_object_get_argument(vo, name,
8184
pspec, argument_class, argument_instance)
8285

8386
if result != 0:
@@ -92,16 +95,24 @@ def get(self, name):
9295

9396
gv = GValue()
9497
gv.init(gtype)
95-
gobject_lib.g_object_get_property(self.pointer, name, gv.pointer)
98+
go = ffi.cast("GObject *", self.pointer)
99+
gobject_lib.g_object_get_property(go, name, gv.pointer)
96100

97101
return gv.get()
98102

99103
def set(self, name, value):
100-
log('VipsObject.set: self = {0}, name = {1}, value = {2}'.format(self, name, value))
104+
log('VipsObject.set: self = {0}, name = {1}, value = {2}'.
105+
format(self, name, value))
101106

102107
gtype = self.get_typeof(name)
103108

104109
gv = GValue()
105110
gv.init(gtype)
106111
gv.set(value)
107-
gobject_lib.g_object_set_property(self.pointer, name, gv.pointer)
112+
go = ffi.cast("GObject *", self.pointer)
113+
gobject_lib.g_object_set_property(go, name, gv.pointer)
114+
115+
# set a series of options using a string, perhaps "fred=12, tile"
116+
def set_string(self, string_options):
117+
vo = ffi.cast("VipsObject *", self.pointer)
118+
return vips_lib.vips_object_set_from_string(vo, string_options) == 0

try1.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
print ''
7777

7878
print 'test Image'
79-
result = Vips.Image.new_from_file('/home/john/pics/k2.jpg')
79+
result = Vips.Image.new_from_file('/data/john/pics/k2.jpg')
8080
print 'result =', result
8181
print ''
8282

0 commit comments

Comments
 (0)