fix array double -> gstring

This commit is contained in:
John Cupitt 2011-10-28 15:13:55 +01:00
parent 2da5560992
commit d503e710e2
4 changed files with 28 additions and 39 deletions

7
TODO
View File

@ -1,12 +1,5 @@
- does transform_array_g_string() work? it seems to use
g_value_set_instance() incorrectly
try printing an array of double
- vips_image_new_array() needs to go ... replcae with vips_object_array()

View File

@ -1315,7 +1315,7 @@ vips_object_print_arg( VipsObject *object, GParamSpec *pspec, VipsBuf *buf )
{
GType type = G_PARAM_SPEC_VALUE_TYPE( pspec );
const char *name = g_param_spec_get_name( pspec );
GValue value = { 0 };
GValue value = { 0, };
char *str_value;
g_value_init( &value, type );

View File

@ -568,11 +568,6 @@ vips_call_split( const char *operation_name, va_list optional, ... )
if( !(operation = vips_operation_new( operation_name ) ) )
return( -1 );
#ifdef VIPS_DEBUG
VIPS_DEBUG_MSG( "where:\n" );
vips_object_print( VIPS_OBJECT( operation ) );
#endif /*VIPS_DEBUG*/
va_start( required, optional );
result = vips_call_required_optional( &operation, required, optional );
va_end( required );
@ -675,6 +670,24 @@ vips_call_options_set( const gchar *option_name, const gchar *value,
VIPS_OBJECT( operation ),
g_param_spec_get_name( pspec ), value ) )
return( FALSE );
#ifdef VIPS_DEBUG
{
GType type = G_PARAM_SPEC_VALUE_TYPE( pspec );
GValue gvalue = { 0, };
char *str;
g_value_init( &gvalue, type );
g_object_get_property( G_OBJECT( operation ),
g_param_spec_get_name( pspec ), &gvalue );
str = g_strdup_value_contents( &gvalue );
VIPS_DEBUG_MSG( "\tGValue %s = %s\n",
g_param_spec_get_name( pspec ), str );
g_free( str );
g_object_unref( &gvalue );
}
#endif /*VIPS_DEBUG*/
}
else if( (argument_class->flags & VIPS_ARGUMENT_OUTPUT) ) {
VipsCallOptionOutput *output;

View File

@ -667,37 +667,20 @@ vips_value_set_array_double( GValue *value, const double *array, int n )
}
static void
transform_array_g_string( const GValue *src_value, GValue *dest_value )
transform_array_double_g_string( const GValue *src_value, GValue *dest_value )
{
char *array;
int n;
GType type;
size_t sizeof_type;
double *array = vips_value_get_array_double( src_value, &n );
char txt[1024];
VipsBuf buf = VIPS_BUF_STATIC( txt );
int i;
array = (char *) vips_value_get_array( src_value,
&n, &type, &sizeof_type );
for( i = 0; i < n; i++ ) {
GValue value = { 0, };
char *str;
if( i > 0 )
vips_buf_appends( &buf, ", " );
g_value_init( &value, type );
g_value_set_instance( &value, array );
str = g_strdup_value_contents( &value );
vips_buf_appends( &buf, str );
g_free( str );
g_value_unset( &value );
array += sizeof_type;
}
for( i = 0; i < n; i++ )
/* Use space as a separator since ',' may be a decimal point
* in this locale.
*/
vips_buf_appends( &buf, "%g ", array[i] );
g_value_set_string( dest_value, vips_buf_all( &buf ) );
}
@ -747,7 +730,7 @@ vips_array_double_get_type( void )
(GBoxedCopyFunc) vips_area_copy,
(GBoxedFreeFunc) vips_area_unref );
g_value_register_transform_func( type, G_TYPE_STRING,
transform_array_g_string );
transform_array_double_g_string );
g_value_register_transform_func( G_TYPE_STRING, type,
transform_g_string_array_double );
}