From cba1ea0024f9bae72049b93ff451ea6796b5029c Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 25 May 2011 13:43:53 +0100 Subject: [PATCH] vipsobject fallback for new_from_string() as well --- TODO | 23 +++++------------------ libvips/iofuncs/object.c | 25 +++++++++++++++++++++++++ libvips/resample/interpolate.c | 26 -------------------------- 3 files changed, 30 insertions(+), 44 deletions(-) diff --git a/TODO b/TODO index 0f3124ca..0dbeb6ea 100644 --- a/TODO +++ b/TODO @@ -1,28 +1,12 @@ -- interpolate needs stuff for new new_from_string etc. system - - also VipsFormat ... could this replace vips_image_new_from_string()? or +- also VipsFormat ... could this replace vips_image_new_from_string()? or could we call this from vips_image_new_from_string()? - vipsobject should have a fall-back implementation that does something, I - don't quite know what - -- vips_object_new_from_string() must go, use the vfunc thing instead - - at the moment, vips_object_new_from_string() is used for - - affinei bilinear{arg=12} - - instead, have a new_from_string vfunc on interpolate which takes off the - main part of the arg and uses that to look up the interpolate subclass - - parsing off required and optional sub-args could be moved somewhere else - - use this system to do file format options, eg. +- use this system to do file format options, eg. vips copy fred.v fred.jpg{quality=90} @@ -37,6 +21,9 @@ - perhaps we should have hard refs everywhere? it's very confusing having a mxture :-( use vips_object_local() to make hard refs autounref + what would the API look like? + + - try out: diff --git a/libvips/iofuncs/object.c b/libvips/iofuncs/object.c index 5bc513b2..8b2fc3b2 100644 --- a/libvips/iofuncs/object.c +++ b/libvips/iofuncs/object.c @@ -874,6 +874,29 @@ vips_object_real_rewind( VipsObject *object ) object->postclose = FALSE; } +static VipsObject * +vips_object_real_new_from_string( const char *string ) +{ + GType type; + + /* The main arg selects the subclass. + */ + if( !(type = vips_type_find( "VipsObject", string )) ) + return( NULL ); + + return( VIPS_OBJECT( g_object_new( type, NULL ) ) ); +} + +static void +vips_object_real_to_string( VipsObject *object, VipsBuf *buf ) +{ + VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object ); + + /* Just "bicubic" or whatever. + */ + vips_buf_appends( buf, class->nickname ); +} + static void transform_string_double( const GValue *src_value, GValue *dest_value ) { @@ -904,6 +927,8 @@ vips_object_class_init( VipsObjectClass *class ) class->print = vips_object_real_print; class->sanity = vips_object_real_sanity; class->rewind = vips_object_real_rewind; + class->new_from_string = vips_object_real_new_from_string; + class->to_string = vips_object_real_to_string; class->nickname = "object"; class->description = _( "VIPS base class" ); diff --git a/libvips/resample/interpolate.c b/libvips/resample/interpolate.c index 92d41e99..ade28442 100644 --- a/libvips/resample/interpolate.c +++ b/libvips/resample/interpolate.c @@ -167,43 +167,17 @@ vips_interpolate_real_get_window_offset( VipsInterpolate *interpolate ) } } -static VipsObject * -vips_interpolate_new_from_string( const char *string ) -{ - GType type; - - /* The main arg selects the subclass. - */ - if( !(type = vips_type_find( "VipsInterpolate", string )) ) - return( NULL ); - return( VIPS_OBJECT( g_object_new( type, NULL ) ) ); -} - -static void -vips_interpolate_to_string( VipsObject *object, VipsBuf *buf ) -{ - VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object ); - - /* Just "bicubic" or whatever. - */ - vips_buf_appends( buf, class->nickname ); -} - static void vips_interpolate_class_init( VipsInterpolateClass *class ) { #ifdef DEBUG GObjectClass *gobject_class = G_OBJECT_CLASS( class ); #endif /*DEBUG*/ - VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class ); #ifdef DEBUG gobject_class->finalize = vips_interpolate_finalize; #endif /*DEBUG*/ - vobject_class->new_from_string = vips_interpolate_new_from_string; - vobject_class->to_string = vips_interpolate_to_string; - class->interpolate = NULL; class->get_window_size = vips_interpolate_real_get_window_size; class->get_window_offset = vips_interpolate_real_get_window_offset;