new cli working

some final testing needed
This commit is contained in:
John Cupitt 2011-05-13 14:47:23 +01:00
parent 825280b365
commit 1f3f20ee4e
5 changed files with 83 additions and 48 deletions

20
TODO
View File

@ -5,19 +5,14 @@
logic for things like create image from filename ... useful for object.c logic for things like create image from filename ... useful for object.c
as well? as well?
- try: test booltest and imtest flags
$ vips add
VipsAdd (add), add two images
VipsOperation.add (left, right, out)
where:
left :: VipsImage
right :: VipsImage
out :: VipsImage
check_required: required construct param left to VipsAdd not set
check_required: required construct param right to VipsAdd not set
why don't we get an error for out not set?
- vips_object_set_argument_from_string() leaks output images, because it has
to, does this matter?
@ -26,6 +21,9 @@
wrap new API for C++ wrap new API for C++
- add etc. should sizealike as well :(
- matlab write - matlab write

View File

@ -93,19 +93,25 @@ VIPS_ARGUMENT_OPTIONAL_OUTPUT Eg. the "width" of an image
*/ */
#define VIPS_ARGUMENT_REQUIRED_INPUT \ #define VIPS_ARGUMENT_REQUIRED_INPUT \
(VIPS_ARGUMENT_INPUT | VIPS_ARGUMENT_REQUIRED | \ (VIPS_ARGUMENT_INPUT | \
VIPS_ARGUMENT_CONSTRUCT | VIPS_ARGUMENT_SET_ONCE) VIPS_ARGUMENT_REQUIRED | \
VIPS_ARGUMENT_CONSTRUCT | \
VIPS_ARGUMENT_SET_ONCE)
#define VIPS_ARGUMENT_REQUIRED_OUTPUT \
(VIPS_ARGUMENT_OUTPUT | \
VIPS_ARGUMENT_REQUIRED | \
VIPS_ARGUMENT_CONSTRUCT | \
VIPS_ARGUMENT_SET_ONCE)
#define VIPS_ARGUMENT_OPTIONAL_INPUT \ #define VIPS_ARGUMENT_OPTIONAL_INPUT \
(VIPS_ARGUMENT_INPUT | \ (VIPS_ARGUMENT_INPUT | \
VIPS_ARGUMENT_CONSTRUCT | VIPS_ARGUMENT_SET_ONCE) VIPS_ARGUMENT_CONSTRUCT | \
#define VIPS_ARGUMENT_REQUIRED_OUTPUT \
(VIPS_ARGUMENT_OUTPUT | VIPS_ARGUMENT_REQUIRED | \
VIPS_ARGUMENT_SET_ONCE) VIPS_ARGUMENT_SET_ONCE)
#define VIPS_ARGUMENT_OPTIONAL_OUTPUT \ #define VIPS_ARGUMENT_OPTIONAL_OUTPUT \
(VIPS_ARGUMENT_OUTPUT | \ (VIPS_ARGUMENT_OUTPUT | \
VIPS_ARGUMENT_CONSTRUCT | \
VIPS_ARGUMENT_SET_ONCE) VIPS_ARGUMENT_SET_ONCE)
/* Keep one of these for every argument. /* Keep one of these for every argument.

View File

@ -603,6 +603,8 @@ vips_image_generate( VipsImage *image,
{ {
int res; int res;
VIPS_DEBUG_MSG( "vips_image_generate: %p\n", image );
g_assert( vips_object_sanity( VIPS_OBJECT( image ) ) ); g_assert( vips_object_sanity( VIPS_OBJECT( image ) ) );
if( !image->hint_set ) { if( !image->hint_set ) {
@ -626,7 +628,7 @@ vips_image_generate( VipsImage *image,
image->start || image->start ||
image->stop ) { image->stop ) {
vips_error( "VipsImage", vips_error( "VipsImage",
"%s", _( "func already attached" ) ); "%s", _( "generate() called twice" ) );
return( -1 ); return( -1 );
} }
@ -636,9 +638,8 @@ vips_image_generate( VipsImage *image,
image->client1 = a; image->client1 = a;
image->client2 = b; image->client2 = b;
#ifdef DEBUG_IO VIPS_DEBUG_MSG( "vips_image_generate: "
printf( "vips_image_generate: attaching partial callbacks\n" ); "attaching partial callbacks\n" );
#endif /*DEBUG_IO*/
break; break;
@ -652,7 +653,7 @@ vips_image_generate( VipsImage *image,
image->start || image->start ||
image->stop ) { image->stop ) {
vips_error( "VipsImage", vips_error( "VipsImage",
"%s", _( "func already attached" ) ); "%s", _( "generate() called twice" ) );
return( -1 ); return( -1 );
} }

View File

@ -45,6 +45,7 @@
#include <vips/vips.h> #include <vips/vips.h>
#include <vips/internal.h> #include <vips/internal.h>
#include <vips/debug.h>
#ifdef WITH_DMALLOC #ifdef WITH_DMALLOC
#include <dmalloc.h> #include <dmalloc.h>
@ -748,11 +749,22 @@ vips_object_check_required( VipsObject *object, GParamSpec *pspec,
{ {
int *result = (int *) a; int *result = (int *) a;
VIPS_DEBUG_MSG( "vips_object_check_required: %s\n",
g_param_spec_get_name( pspec ) );
VIPS_DEBUG_MSG( "\trequired: %d\n",
argument_class->flags & VIPS_ARGUMENT_REQUIRED );
VIPS_DEBUG_MSG( "\tconstruct: %d\n",
argument_class->flags & VIPS_ARGUMENT_CONSTRUCT );
VIPS_DEBUG_MSG( "\tassigned: %d\n",
argument_instance->assigned );
if( (argument_class->flags & VIPS_ARGUMENT_REQUIRED) && if( (argument_class->flags & VIPS_ARGUMENT_REQUIRED) &&
(argument_class->flags & VIPS_ARGUMENT_CONSTRUCT) && (argument_class->flags & VIPS_ARGUMENT_CONSTRUCT) &&
!argument_instance->assigned ) { !argument_instance->assigned ) {
vips_error( "check_required", vips_error( "VipsObject",
_( "required construct param %s to %s not set" ), /* used as eg. "parameter out to VipsAdd not set".
*/
_( "parameter %s to %s not set" ),
g_param_spec_get_name( pspec ), g_param_spec_get_name( pspec ),
G_OBJECT_TYPE_NAME( object ) ); G_OBJECT_TYPE_NAME( object ) );
*result = -1; *result = -1;
@ -986,8 +998,7 @@ vips_object_set_argument_from_string( VipsObject *object,
pspec = g_object_class_find_property( G_OBJECT_CLASS( class ), name ); pspec = g_object_class_find_property( G_OBJECT_CLASS( class ), name );
if( !pspec ) { if( !pspec ) {
vips_error( "vips_object_set_argument_from_string", vips_error( "VipsObject", _( "object %s has no argument %s" ),
_( "object %s has no argument %s" ),
G_OBJECT_TYPE_NAME( object ), name ); G_OBJECT_TYPE_NAME( object ), name );
return( -1 ); return( -1 );
} }
@ -1000,14 +1011,32 @@ vips_object_set_argument_from_string( VipsObject *object,
if( G_IS_PARAM_SPEC_OBJECT( pspec ) && if( G_IS_PARAM_SPEC_OBJECT( pspec ) &&
G_PARAM_SPEC_VALUE_TYPE( pspec ) == VIPS_TYPE_IMAGE ) { G_PARAM_SPEC_VALUE_TYPE( pspec ) == VIPS_TYPE_IMAGE ) {
VipsImage *image; VipsImage *image;
char *mode;
mode = (argument_class->flags & VIPS_ARGUMENT_OUTPUT) ?
"w" : "r";
if( !(image = vips_image_new_from_file( value, mode )) )
return( -1 );
g_value_init( &gvalue, G_TYPE_OBJECT ); g_value_init( &gvalue, G_TYPE_OBJECT );
g_value_set_object( &gvalue, image );
if( argument_class->flags & VIPS_ARGUMENT_OUTPUT ) {
if( !(image = vips_image_new_from_file( value, "w" )) )
return( -1 );
/* When we set an output image on an object, the image
* will take a ref to the object. In other words, the
* operation will stay alive until we unref all of
* the output objects.
*
* For now, we leave the output image ref at 1 to
* keep it alive. Perhaps we should capture and
* return these refs somehow?
*/
g_value_set_object( &gvalue, image );
}
else {
if( !(image = vips_image_new_from_file( value, "r" )) )
return( -1 );
/* gvalue now owns the ref to image.
*/
g_value_take_object( &gvalue, image );
}
} }
else if( G_IS_PARAM_SPEC_BOOLEAN( pspec ) ) { else if( G_IS_PARAM_SPEC_BOOLEAN( pspec ) ) {
gboolean b; gboolean b;
@ -1056,7 +1085,7 @@ vips_object_set_required( VipsObject *object, const char *value )
if( !(pspec = vips_argument_map( object, if( !(pspec = vips_argument_map( object,
vips_object_set_required_test, NULL, NULL )) ) { vips_object_set_required_test, NULL, NULL )) ) {
vips_error( "vips_object_set_required", vips_error( "VipsObject",
_( "no unset required arguments for %s" ), value ); _( "no unset required arguments for %s" ), value );
return( -1 ); return( -1 );
} }
@ -1106,15 +1135,15 @@ vips_object_set_args( VipsObject *object, const char *p )
/* Now must be a , or a ). /* Now must be a , or a ).
*/ */
if( token != VIPS_TOKEN_RIGHT && token != VIPS_TOKEN_COMMA ) { if( token != VIPS_TOKEN_RIGHT && token != VIPS_TOKEN_COMMA ) {
vips_error( "set_args", "%s", vips_error( "VipsObject",
_( "not , or ) after parameter" ) ); "%s", _( "not , or ) after parameter" ) );
return( -1 ); return( -1 );
} }
} while( token != VIPS_TOKEN_RIGHT ); } while( token != VIPS_TOKEN_RIGHT );
if( (p = vips__token_get( p, &token, string, PATH_MAX )) ) { if( (p = vips__token_get( p, &token, string, PATH_MAX )) ) {
vips_error( "set_args", "%s", vips_error( "VipsObject",
_( "extra tokens after ')'" ) ); "%s", _( "extra tokens after ')'" ) );
return( -1 ); return( -1 );
} }
@ -1151,8 +1180,8 @@ vips_object_new_from_string_set( VipsObject *object, void *a, void *b )
if( (p = vips__token_get( p, &token, string, PATH_MAX )) ) { if( (p = vips__token_get( p, &token, string, PATH_MAX )) ) {
if( token == VIPS_TOKEN_LEFT && if( token == VIPS_TOKEN_LEFT &&
vips_object_set_args( object, p ) ) { vips_object_set_args( object, p ) ) {
vips_error( "object_new", "%s", vips_error( "VipsObject",
_( "bad object arguments" ) ); "%s", _( "bad object arguments" ) );
return( object ); return( object );
} }
} }
@ -1358,7 +1387,7 @@ vips_class_map_concrete_all( GType type, VipsClassMap fn, void *a )
* classes. * classes.
*/ */
if( !(class = g_type_class_ref( type )) ) { if( !(class = g_type_class_ref( type )) ) {
vips_error( "vips_class_map_concrete_all", vips_error( "VipsObject",
"%s", _( "unable to build class" ) ); "%s", _( "unable to build class" ) );
return( NULL ); return( NULL );
} }
@ -1396,14 +1425,14 @@ vips_class_find( const char *basename, const char *nickname )
GType base; GType base;
if( !(base = g_type_from_name( basename )) ) { if( !(base = g_type_from_name( basename )) ) {
vips_error( "vips_class_find", vips_error( "VipsObject",
_( "base class \"%s\" not found" ), basename ); _( "base class \"%s\" not found" ), basename );
return( NULL ); return( NULL );
} }
if( !(class = vips_class_map_concrete_all( base, if( !(class = vips_class_map_concrete_all( base,
(VipsClassMap) test_name, (void *) nickname )) ) { (VipsClassMap) test_name, (void *) nickname )) ) {
vips_error( "vips_class_find", vips_error( "VipsObject",
_( "class \"%s\" not found" ), nickname ); _( "class \"%s\" not found" ), nickname );
return( NULL ); return( NULL );
} }

View File

@ -419,13 +419,14 @@ vips_call_options_add( VipsObject *object,
!argument_instance->assigned ) { !argument_instance->assigned ) {
GOptionEntry entry[2]; GOptionEntry entry[2];
entry[0].long_name = pspec->name; entry[0].long_name = g_param_spec_get_name( pspec );
entry[0].short_name = pspec->name[0]; entry[0].short_name = g_param_spec_get_name( pspec )[0];
entry[0].flags = G_OPTION_FLAG_OPTIONAL_ARG; entry[0].flags = G_OPTION_FLAG_OPTIONAL_ARG;
entry[0].arg = G_OPTION_ARG_CALLBACK; entry[0].arg = G_OPTION_ARG_CALLBACK;
entry[0].arg_data = (gpointer) vips_call_options_set; entry[0].arg_data = (gpointer) vips_call_options_set;
entry[0].description = pspec->name; entry[0].description = g_param_spec_get_blurb( pspec );
entry[0].arg_description = pspec->name; entry[0].arg_description =
g_type_name( G_PARAM_SPEC_VALUE_TYPE( pspec ) );
entry[1].long_name = NULL; entry[1].long_name = NULL;
@ -468,7 +469,7 @@ vips_call_argv( VipsOperation *operation, int argc, char **argv )
/* Now set required args from the rest of the command-line. /* Now set required args from the rest of the command-line.
*/ */
for( i = 1; i < argc; i++ ) for( i = 0; i < argc; i++ )
if( vips_call_argv_set_required( operation, argv[i] ) ) if( vips_call_argv_set_required( operation, argv[i] ) )
return( -1 ); return( -1 );