start unboxing returns from Python

This commit is contained in:
John Cupitt 2014-09-03 14:59:35 +01:00
parent 7608524f61
commit 8f39f8ba3b
3 changed files with 24 additions and 6 deletions

2
TODO
View File

@ -3,6 +3,8 @@
- turns blobs into strings on return with .get() - turns blobs into strings on return with .get()
finish get_value
- add more constructors - add more constructors
- need more writers - need more writers

View File

@ -513,7 +513,7 @@ vips_ref_string_get_type( void )
/** /**
* vips_blob_new: * 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 * @data: (array length=size) (element-type guint8) (transfer full): data to store
* @size: number of bytes in @data * @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. * 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 * int *
vips_array_int_get( VipsArrayInt *array, int *n ) 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. * 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 * double *
vips_array_double_get( VipsArrayDouble *array, int *n ) vips_array_double_get( VipsArrayDouble *array, int *n )

View File

@ -18,6 +18,7 @@ Vips.init(sys.argv[0])
vips_type_array_int = GObject.GType.from_name("VipsArrayInt") vips_type_array_int = GObject.GType.from_name("VipsArrayInt")
vips_type_array_double = GObject.GType.from_name("VipsArrayDouble") vips_type_array_double = GObject.GType.from_name("VipsArrayDouble")
vips_type_array_image = GObject.GType.from_name("VipsArrayImage") vips_type_array_image = GObject.GType.from_name("VipsArrayImage")
vips_type_blob = GObject.GType.from_name("VipsBlob")
class Error(Exception): 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_double, Vips.ArrayDouble.new, value)
value = self.arrayize(vips_type_array_image, Vips.ArrayImage.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) logging.debug('assigning %s' % self.prop.value_type)
self.op.props.__setattr__(self.name, value) 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): def _call_base(name, required, optional, self = None, option_string = None):
logging.debug('_call_base name=%s, required=%s optional=%s' % logging.debug('_call_base name=%s, required=%s optional=%s' %
(name, required, optional)) (name, required, optional))
@ -256,14 +267,17 @@ def vips_div(self, other):
def vips_rdiv(self, other): def vips_rdiv(self, other):
return (self ** -1) * other return (self ** -1) * other
def vips_floor(self):
self.round(Vips.OperationRound.FLOOR)
def vips_floordiv(self, other): def vips_floordiv(self, other):
if isinstance(other, Vips.Image): if isinstance(other, Vips.Image):
return self.divide(other).round(Vips.OperationRound.FLOOR) return self.divide(other).floor()
else: 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): def vips_rfloordiv(self, other):
return ((self ** -1) * other).round(Vips.OperationRound.FLOOR) return ((self ** -1) * other).floor()
def vips_mod(self, other): def vips_mod(self, other):
if isinstance(other, Vips.Image): 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_file = vips_image_write_to_file
Vips.Image.write_to_buffer = vips_image_write_to_buffer Vips.Image.write_to_buffer = vips_image_write_to_buffer
Vips.Image.floor = vips_floor
Vips.Image.__getattr__ = vips_image_getattr Vips.Image.__getattr__ = vips_image_getattr
Vips.Image.__add__ = vips_add Vips.Image.__add__ = vips_add
Vips.Image.__radd__ = vips_add Vips.Image.__radd__ = vips_add