From 3acf9fd2aabf6accaee8d3bbce8134c36a6ec0fe Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sun, 2 Oct 2011 10:22:21 +0100 Subject: [PATCH] vipscopy copies but some work still needed on arg processing, see TODO --- TODO | 4 ++-- libvips/conversion/copy.c | 2 ++ libvips/iofuncs/image.c | 7 ++++++- libvips/iofuncs/object.c | 34 ++++++++++++++++++++++++---------- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/TODO b/TODO index 726254d4..da44b6a7 100644 --- a/TODO +++ b/TODO @@ -2,9 +2,9 @@ how would we do meta sets? - copy_swap needs doing too, a separate class I guess + vips_object_set_argument_from_string() needs more arg types - or add a "swap" prop? we have a enum for native etc. somewhere + must be some way to make this more automatic diff --git a/libvips/conversion/copy.c b/libvips/conversion/copy.c index c4ff4189..fb13797b 100644 --- a/libvips/conversion/copy.c +++ b/libvips/conversion/copy.c @@ -346,6 +346,8 @@ vips_copy_class_init( VipsCopyClass *class ) GParamSpec *pspec; + VIPS_DEBUG_MSG( "vips_copy_class_init\n" ); + gobject_class->set_property = vips_object_set_property; gobject_class->get_property = vips_object_get_property; diff --git a/libvips/iofuncs/image.c b/libvips/iofuncs/image.c index 23c08075..b07a7a45 100644 --- a/libvips/iofuncs/image.c +++ b/libvips/iofuncs/image.c @@ -960,7 +960,7 @@ vips_image_class_init( VipsImageClass *class ) vobject_class->output_to_arg = vips_image_write_object; vobject_class->nickname = "image"; - vobject_class->description = _( "VIPS image class" ); + vobject_class->description = _( "image class" ); vobject_class->print = vips_image_print; vobject_class->sanity = vips_image_sanity; @@ -1581,6 +1581,9 @@ vips_image_new_mode( const char *filename, const char *mode ) { VipsImage *image; + g_assert( filename ); + g_assert( mode ); + vips_check_init(); image = VIPS_IMAGE( g_object_new( VIPS_TYPE_IMAGE, NULL ) ); @@ -1770,6 +1773,8 @@ vips_image_write( VipsImage *image, const char *filename ) { VipsImage *out; + g_assert( filename ); + if( !(out = vips_image_new_mode( filename, "w" )) ) return( -1 ); if( im_copy( image, out ) ) { diff --git a/libvips/iofuncs/object.c b/libvips/iofuncs/object.c index 1a1a5818..398ceead 100644 --- a/libvips/iofuncs/object.c +++ b/libvips/iofuncs/object.c @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -1243,6 +1244,14 @@ vips_object_set_argument_from_string( VipsObject *object, b = FALSE; g_value_set_boolean( &gvalue, b ); } + else if( G_IS_PARAM_SPEC_INT( pspec ) ) { + g_value_init( &gvalue, G_TYPE_INT ); + g_value_set_int( &gvalue, atoi( value ) ); + } + else if( G_IS_PARAM_SPEC_DOUBLE( pspec ) ) { + g_value_init( &gvalue, G_TYPE_DOUBLE ); + g_value_set_double( &gvalue, atof( value ) ); + } else { g_value_init( &gvalue, G_TYPE_STRING ); g_value_set_string( &gvalue, value ); @@ -1254,7 +1263,7 @@ vips_object_set_argument_from_string( VipsObject *object, return( 0 ); } -/* Does a named output arg need an argument to write to? For example, an image +/* Does an vipsargument need an argument to write to? For example, an image * output needs a filename, a double output just prints. */ gboolean @@ -1274,17 +1283,22 @@ vips_object_get_argument_needs_string( VipsObject *object, const char *name ) &pspec, &argument_class, &argument_instance ) ) return( -1 ); - otype = G_PARAM_SPEC_VALUE_TYPE( pspec ); - - g_assert( argument_class->flags & VIPS_ARGUMENT_OUTPUT ); - - /* For now, only vipsobject subclasses can ask for args. - */ - if( g_type_is_a( otype, VIPS_TYPE_OBJECT ) && + if( G_IS_PARAM_SPEC_BOOLEAN( pspec ) ) + /* Bools, input or output, don't need args. + */ + return( FALSE ); + else if( argument_class->flags & VIPS_ARGUMENT_INPUT ) + /* All other inputs need something. + */ + return( TRUE ); + if( (otype = G_PARAM_SPEC_VALUE_TYPE( pspec )) && + g_type_is_a( otype, VIPS_TYPE_OBJECT ) && (oclass = g_type_class_ref( otype )) ) + /* For now, only vipsobject subclasses can ask for args. + */ return( oclass->output_needs_arg ); - - return( FALSE ); + else + return( FALSE ); } static void