Skip to content

Commit 7f8eaa7

Browse files
committed
allow set enums from strings
so we can call vips_reduce
1 parent 14794bc commit 7f8eaa7

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

TODO

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
- expose kernel option in vips_resize(), then use that in nip2 resize ... will
2-
need to be 8.4
1+
- wrap vips_reduce(), use it from resize
32

4-
need to be able to set enums to vips8 calls, maybe set as strings?
3+
need to add a new kernel selector thing
54

65
- sharpen should use new interface?
76

src/vipsobject.c

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,26 @@ vo_gather_required( PElement *item, Vo *vo )
116116
return( NULL );
117117
}
118118

119+
static int
120+
vo_set_property( Vo *vo,
121+
const char *name, GParamSpec *pspec, GValue *value )
122+
{
123+
/* If we're setting an enum from a string, look up the enum nickname.
124+
*/
125+
if( G_IS_PARAM_SPEC_ENUM( pspec ) &&
126+
G_VALUE_TYPE( value ) == VIPS_TYPE_REF_STRING ) {
127+
const char *str = vips_value_get_ref_string( value, NULL );
128+
129+
if( vips_object_set_argument_from_string( vo->object,
130+
name, str ) )
131+
return( -1 );
132+
}
133+
else
134+
g_object_set_property( G_OBJECT( vo->object ), name, value );
135+
136+
return( 0 );
137+
}
138+
119139
static void *
120140
vo_set_required_input( VipsObject *object, GParamSpec *pspec,
121141
VipsArgumentClass *argument_class,
@@ -132,12 +152,15 @@ vo_set_required_input( VipsObject *object, GParamSpec *pspec,
132152
const char *name = g_param_spec_get_name( pspec );
133153
int i = vo->nargs_required;
134154

135-
GValue value = { 0 };
155+
GValue gvalue = { 0 };
136156

137-
if( !heap_ip_to_gvalue( &vo->args[i], &value ) )
157+
if( !heap_ip_to_gvalue( &vo->args[i], &gvalue ) )
138158
return( object );
139-
g_object_set_property( G_OBJECT( object ), name, &value );
140-
g_value_unset( &value );
159+
if( vo_set_property( vo, name, pspec, &gvalue ) ) {
160+
g_value_unset( &gvalue );
161+
return( object );
162+
}
163+
g_value_unset( &gvalue );
141164

142165
vo->nargs_required += 1;
143166
}
@@ -173,7 +196,10 @@ vo_set_optional_arg( const char *name, PElement *value, Vo *vo )
173196
g_value_unset( &gvalue );
174197
return( value );
175198
}
176-
g_object_set_property( G_OBJECT( vo->object ), name, &gvalue );
199+
if( vo_set_property( vo, name, pspec, &gvalue ) ) {
200+
g_value_unset( &gvalue );
201+
return( value );
202+
}
177203
g_value_unset( &gvalue );
178204
}
179205

0 commit comments

Comments
 (0)