diff --git a/ChangeLog b/ChangeLog index d3ba590b..3529f5df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 30/12/14 started 7.42.2 - allow c++ set enum from string +- display param default and range in usage 24/12/14 started 7.42.1 - add gobject-2.0 to Requires: in vips and vips-cpp .pc files diff --git a/TODO b/TODO index 35727173..6f65a300 100644 --- a/TODO +++ b/TODO @@ -1,34 +1,3 @@ -- display of optional params should show default value - - also display possible enum values? - - min and max for int/float params? - - maybe: - -$ vips embed -embed an image in a larger image -usage: - embed in out x y width height -where: - in - Input image, input VipsImage - out - Output image, output VipsImage - x - Left edge of input in output, input gint - (default: 0, min: -inf, max: inf) - y - Top edge of input in output, input gint - (default: 0, min: -inf, max: inf) - width - Image width in pixels, input gint - (default: 100, min: 0, max: inf) - height - Image height in pixels, input gint - (default: 100, min: 0, max: inf) -optional arguments: - extend - How to generate the extra pixels, input VipsExtend - (default: black, allowed: copy, extend, mirror) - background - Colour for background pixels, input VipsArrayDouble - (default: 0, min: 0, max: inf) -operation flags: sequential-unbuffered - - - use vips_resize() in vipsthumbnail? should the sharpening filter be selectable? diff --git a/doc/reference/using-command-line.xml b/doc/reference/using-command-line.xml index a199d5dd..9377c9cc 100644 --- a/doc/reference/using-command-line.xml +++ b/doc/reference/using-command-line.xml @@ -61,6 +61,8 @@ out - Output image, output VipsImage optional arguments: exponent - Gamma factor, input gdouble + default: 2.4 + min: 1e-06, max: 1000 operation flags: sequential-unbuffered diff --git a/libvips/iofuncs/operation.c b/libvips/iofuncs/operation.c index 44dbebca..c81cd18a 100644 --- a/libvips/iofuncs/operation.c +++ b/libvips/iofuncs/operation.c @@ -1,4 +1,7 @@ /* base class for all vips operations + * + * 30/12/14 + * - display default/min/max for pspec in usage */ /* @@ -275,6 +278,80 @@ vips_operation_class_usage_classify( VipsArgumentClass *argument_class ) return( USAGE_NONE ); } +static void +vips_operation_pspec_usage( VipsBuf *buf, GParamSpec *pspec ) +{ + GType type = G_PARAM_SPEC_VALUE_TYPE( pspec ); + + /* These are the pspecs that vips uses that have interesting values. + */ + if( G_IS_PARAM_SPEC_ENUM( pspec ) ) { + GTypeClass *class = g_type_class_ref( type ); + GParamSpecEnum *pspec_enum = (GParamSpecEnum *) pspec; + + GEnumClass *genum; + int i; + + /* Should be impossible, no need to warn. + */ + if( !class ) + return; + + genum = G_ENUM_CLASS( class ); + + vips_buf_appendf( buf, "\t\t\t" ); + vips_buf_appendf( buf, "%s", _( "default" ) ); + vips_buf_appendf( buf, ": %s\n", + vips_enum_nick( type, pspec_enum->default_value ) ); + vips_buf_appendf( buf, "\t\t\t" ); + vips_buf_appendf( buf, "%s", _( "allowed" ) ); + vips_buf_appendf( buf, ": " ); + + /* -1 since we always have a "last" member. + */ + for( i = 0; i < genum->n_values - 1; i++ ) { + if( i > 0 ) + vips_buf_appends( buf, ", " ); + vips_buf_appends( buf, genum->values[i].value_nick ); + } + + vips_buf_appendf( buf, "\n" ); + } + else if( G_IS_PARAM_SPEC_BOOLEAN( pspec ) ) { + GParamSpecBoolean *pspec_boolean = (GParamSpecBoolean *) pspec; + + vips_buf_appendf( buf, "\t\t\t" ); + vips_buf_appendf( buf, "%s", _( "default" ) ); + vips_buf_appendf( buf, ": %s\n", + pspec_boolean->default_value ? "true" : "false" ); + } + else if( G_IS_PARAM_SPEC_DOUBLE( pspec ) ) { + GParamSpecDouble *pspec_double = (GParamSpecDouble *) pspec; + + vips_buf_appendf( buf, "\t\t\t" ); + vips_buf_appendf( buf, "%s", _( "default" ) ); + vips_buf_appendf( buf, ": %g\n", pspec_double->default_value ); + vips_buf_appendf( buf, "\t\t\t" ); + vips_buf_appendf( buf, "%s", _( "min" ) ); + vips_buf_appendf( buf, ": %g, ", pspec_double->minimum ); + vips_buf_appendf( buf, "%s", _( "max" ) ); + vips_buf_appendf( buf, ": %g\n", pspec_double->maximum ); + } + else if( G_IS_PARAM_SPEC_INT( pspec ) ) { + GParamSpecInt *pspec_int = (GParamSpecInt *) pspec; + + vips_buf_appendf( buf, "\t\t\t" ); + vips_buf_appendf( buf, "%s", _( "default" ) ); + vips_buf_appendf( buf, ": %d\n", pspec_int->default_value ); + vips_buf_appendf( buf, "\t\t\t" ); + vips_buf_appendf( buf, "%s", _( "min" ) ); + vips_buf_appendf( buf, ": %d, ", pspec_int->minimum ); + vips_buf_appendf( buf, "%s", _( "max" ) ); + vips_buf_appendf( buf, ": %d\n", pspec_int->maximum ); + } + +} + static void * vips_operation_class_usage_arg( VipsObjectClass *object_class, GParamSpec *pspec, VipsArgumentClass *argument_class, @@ -286,7 +363,7 @@ vips_operation_class_usage_arg( VipsObjectClass *object_class, usage->n == 0 ) vips_buf_appendf( buf, "%s\n", usage->message ); - if( usage->oftype ) + if( usage->oftype ) { vips_buf_appendf( buf, " %-12s - %s, %s %s\n", g_param_spec_get_name( pspec ), g_param_spec_get_blurb( pspec ), @@ -294,6 +371,8 @@ vips_operation_class_usage_arg( VipsObjectClass *object_class, _( "input" ) : _( "output" ), g_type_name( G_PARAM_SPEC_VALUE_TYPE( pspec ) ) ); + vips_operation_pspec_usage( buf, pspec ); + } else { if( usage->n > 0 ) vips_buf_appends( buf, " " );