From 8f39f8ba3bb7faa8a5e0bbc99b6854b1104333de Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 3 Sep 2014 14:59:35 +0100 Subject: [PATCH] start unboxing returns from Python --- TODO | 2 ++ libvips/iofuncs/type.c | 6 +++--- python/vips8/vips.py | 22 +++++++++++++++++++--- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/TODO b/TODO index d8f7a038..08cad3bd 100644 --- a/TODO +++ b/TODO @@ -3,6 +3,8 @@ - turns blobs into strings on return with .get() + finish get_value + - add more constructors - need more writers diff --git a/libvips/iofuncs/type.c b/libvips/iofuncs/type.c index b21a47b9..f89d6a00 100644 --- a/libvips/iofuncs/type.c +++ b/libvips/iofuncs/type.c @@ -513,7 +513,7 @@ vips_ref_string_get_type( void ) /** * vips_blob_new: - * @free_fn: (scope async): (allow-none): @data will be freed with this function + * @free_fn: (scope async) (allow-none): @data will be freed with this function * @data: (array length=size) (element-type guint8) (transfer full): data to store * @size: number of bytes in @data * @@ -684,7 +684,7 @@ vips_array_int_newv( int n, ... ) * * Fetch an int array from a #VipsArrayInt. Useful for language bindings. * - * Returns: (array length=n): (transfer none): array of int + * Returns: (array length=n) (transfer none): array of int */ int * vips_array_int_get( VipsArrayInt *array, int *n ) @@ -851,7 +851,7 @@ vips_array_double_newv( int n, ... ) * * Fetch a double array from a #VipsArrayDouble. Useful for language bindings. * - * Returns: (array length=n): (transfer none): array of double + * Returns: (array length=n) (transfer none): array of double */ double * vips_array_double_get( VipsArrayDouble *array, int *n ) diff --git a/python/vips8/vips.py b/python/vips8/vips.py index 0b1c0dac..067b705b 100644 --- a/python/vips8/vips.py +++ b/python/vips8/vips.py @@ -18,6 +18,7 @@ Vips.init(sys.argv[0]) vips_type_array_int = GObject.GType.from_name("VipsArrayInt") vips_type_array_double = GObject.GType.from_name("VipsArrayDouble") vips_type_array_image = GObject.GType.from_name("VipsArrayImage") +vips_type_blob = GObject.GType.from_name("VipsBlob") class Error(Exception): @@ -65,10 +66,20 @@ class Argument: value = self.arrayize(vips_type_array_double, Vips.ArrayDouble.new, value) value = self.arrayize(vips_type_array_image, Vips.ArrayImage.new, value) + # blob-ize + if GObject.type_is_a(self.prop.value_type, vips_type_blob): + if not isinstance(gi.repository.Vips.Blob, value): + value = Vips.Blob.new(None, value) + logging.debug('assigning %s' % self.prop.value_type) self.op.props.__setattr__(self.name, value) + def get_value(self): + x = self.op.props.__getattribute__(self.name) + + return x + def _call_base(name, required, optional, self = None, option_string = None): logging.debug('_call_base name=%s, required=%s optional=%s' % (name, required, optional)) @@ -256,14 +267,17 @@ def vips_div(self, other): def vips_rdiv(self, other): return (self ** -1) * other +def vips_floor(self): + self.round(Vips.OperationRound.FLOOR) + def vips_floordiv(self, other): if isinstance(other, Vips.Image): - return self.divide(other).round(Vips.OperationRound.FLOOR) + return self.divide(other).floor() else: - return self.linear(smap(lambda x: 1.0 / x, other), 0).round(Vips.OperationRound.FLOOR) + return self.linear(smap(lambda x: 1.0 / x, other), 0).floor() def vips_rfloordiv(self, other): - return ((self ** -1) * other).round(Vips.OperationRound.FLOOR) + return ((self ** -1) * other).floor() def vips_mod(self, other): if isinstance(other, Vips.Image): @@ -331,6 +345,8 @@ setattr(Vips.Image, 'new_from_file', classmethod(vips_image_new_from_file)) Vips.Image.write_to_file = vips_image_write_to_file Vips.Image.write_to_buffer = vips_image_write_to_buffer +Vips.Image.floor = vips_floor + Vips.Image.__getattr__ = vips_image_getattr Vips.Image.__add__ = vips_add Vips.Image.__radd__ = vips_add