diff --git a/TODO b/TODO index b4962d0c..77a2452c 100644 --- a/TODO +++ b/TODO @@ -1,9 +1,19 @@ -- python/try.py +- Vips.cache_operation_build() is not very wrapper friendly - - have a ref leak + make it work like: + + op2 = build(op1) + + return NULL on error, returns a new op on success + + always unref the old op + + + + +- grep for other vips_class_find() problems: do we use it for simple class + lookup anywhere else? - - try looping over operator props and looking up class and instance; - need to be able to get INPUT, OUTPUT, ASSIGNED etc diff --git a/libvips/arithmetic/measure.c b/libvips/arithmetic/measure.c index 4ba953a0..7fc800ef 100644 --- a/libvips/arithmetic/measure.c +++ b/libvips/arithmetic/measure.c @@ -111,11 +111,11 @@ vips_measure_build( VipsObject *object ) /* left/top/width/height default to the size of the image. */ - if( !vips_argument_get_assigned( object, "width" ) ) + if( !vips_object_get_assigned( object, "width" ) ) g_object_set( object, "width", vips_image_get_width( measure->in ), NULL ); - if( !vips_argument_get_assigned( object, "height" ) ) + if( !vips_object_get_assigned( object, "height" ) ) g_object_set( object, "height", vips_image_get_height( measure->in ), NULL ); diff --git a/libvips/deprecated/dispatch_types.c b/libvips/deprecated/dispatch_types.c index 82447244..696d0f63 100644 --- a/libvips/deprecated/dispatch_types.c +++ b/libvips/deprecated/dispatch_types.c @@ -872,7 +872,7 @@ input_interpolate_init( im_object *obj, char *str ) { GType type = g_type_from_name( "VipsInterpolate" ); VipsObjectClass *interpolate_class = - VIPS_INTERPOLATE_CLASS( g_type_class_ref( type ) ); + VIPS_OBJECT_CLASS( g_type_class_ref( type ) ); VipsObject *object; g_assert( interpolate_class ); diff --git a/libvips/foreign/tiffsave.c b/libvips/foreign/tiffsave.c index 34c373a3..8c0b116b 100644 --- a/libvips/foreign/tiffsave.c +++ b/libvips/foreign/tiffsave.c @@ -93,14 +93,14 @@ vips_foreign_save_tiff_build( VipsObject *object ) /* Default xres/yres to the values from the image. */ - if( !vips_argument_get_assigned( object, "xres" ) ) + if( !vips_object_get_assigned( object, "xres" ) ) tiff->xres = save->ready->Xres * 10.0; - if( !vips_argument_get_assigned( object, "yres" ) ) + if( !vips_object_get_assigned( object, "yres" ) ) tiff->yres = save->ready->Yres * 10.0; /* resunit param overrides resunit metadata. */ - if( !vips_argument_get_assigned( object, "resunit" ) && + if( !vips_object_get_assigned( object, "resunit" ) && vips_image_get_typeof( save->ready, VIPS_META_RESOLUTION_UNIT ) && !vips_image_get_string( save->ready, diff --git a/libvips/include/vips/object.h b/libvips/include/vips/object.h index 93ea17ee..5cf28702 100644 --- a/libvips/include/vips/object.h +++ b/libvips/include/vips/object.h @@ -293,7 +293,8 @@ int vips_object_get_argument( VipsObject *object, const char *name, GParamSpec **pspec, VipsArgumentClass **argument_class, VipsArgumentInstance **argument_instance ); -gboolean vips_argument_get_assigned( VipsObject *object, const char *name ); +gboolean vips_object_get_assigned( VipsObject *object, const char *name ); +VipsArgumentFlags vips_object_get_flags( VipsObject *object, const char *name ); /* We have to loop over an objects args in several places, and we can't always * use vips_argument_map(), the preferred looper. Have the loop code as a diff --git a/libvips/iofuncs/object.c b/libvips/iofuncs/object.c index 7993e643..56cff603 100644 --- a/libvips/iofuncs/object.c +++ b/libvips/iofuncs/object.c @@ -459,8 +459,15 @@ vips__argument_get_instance( VipsArgumentClass *argument_class, /** * vips_object_get_argument: (skip) + * @object: the object to fetch the args from + * @name: arg to fetch + * @pspec: (transfer none): the pspec for this arg + * @argument_class: (transfer none): the argument_class for this arg + * @argument_instance: (transfer none): the argument_instance for this arg * * Look up the three things you need to work with a vips argument. + * + * Returns: 0 on success, or -1 on error. */ int vips_object_get_argument( VipsObject *object, const char *name, @@ -497,10 +504,17 @@ vips_object_get_argument( VipsObject *object, const char *name, return( 0 ); } -/* Convenience: has an argument been assigned. +/** + * vips_object_get_assigned: + * @object: the object to fetch the args from + * @name: arg to fetch + * + * Convenience: has an argument been assigned. + * + * Returns: %TRUE if the arguent has been assigned. */ gboolean -vips_argument_get_assigned( VipsObject *object, const char *name ) +vips_object_get_assigned( VipsObject *object, const char *name ) { GParamSpec *pspec; VipsArgumentClass *argument_class; @@ -513,6 +527,29 @@ vips_argument_get_assigned( VipsObject *object, const char *name ) return( argument_instance->assigned ); } +/** + * vips_object_get_flags: + * @object: the object to fetch the args from + * @name: arg to fetch + * + * Convenience: get the flags for an argument. + * + * Returns: The #VipsArgmentFlags for this argument. + */ +VipsArgumentFlags +vips_object_get_flags( VipsObject *object, const char *name ) +{ + GParamSpec *pspec; + VipsArgumentClass *argument_class; + VipsArgumentInstance *argument_instance; + + if( vips_object_get_argument( object, name, + &pspec, &argument_class, &argument_instance ) ) + return( 0 ); + + return( argument_class->flags ); +} + static void vips_object_clear_member( VipsObject *object, GParamSpec *pspec, GObject **member ) diff --git a/python/try.py b/python/try.py index 1255bd37..a9915a47 100755 --- a/python/try.py +++ b/python/try.py @@ -30,13 +30,23 @@ print 'call operation:' op = Vips.Operation.new("add") for prop in op.props: - print 'prop =', prop + print 'prop.name =', prop.name + flags = op.get_flags(prop.name) + if flags & Vips.ArgumentFlags.OUTPUT: + print '\toutput' + if flags & Vips.ArgumentFlags.INPUT: + print '\tinput' + if flags & Vips.ArgumentFlags.REQUIRED: + print '\trequired' + print '\tassigned', op.get_assigned(prop.name) + op.props.left = a op.props.right = a if op.build() != 0: print Vips.error_buffer() sys.exit(-1) out = op.props.out +op.unref_outputs() print 'out.get_format() =', out.get_format() print 'out.props.format =', out.props.format