From fd26b098b76fb550eeed8257825e47948760f380 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 7 Mar 2011 15:52:53 +0000 Subject: [PATCH] it runs! "vips im_avg poop.png" now works, amazing. Test a few more things before we merge back to master. --- TODO | 33 ++++++++++++++++++++++++++++++ libvips/include/vips/object.h | 1 + libvips/include/vips/vips7compat.h | 6 +++--- libvips/iofuncs/image.c | 16 +++++++++++++-- libvips/iofuncs/object.c | 17 ++++++++++----- libvips/iofuncs/region.c | 2 ++ libvips/iofuncs/sink.c | 14 ++++++------- libvips/iofuncs/sinkdisc.c | 9 ++++---- libvips/iofuncs/sinkmemory.c | 11 ++++------ libvips/iofuncs/vips7compat.c | 3 ++- tools/iofuncs/vips.c | 12 +++++++++++ 11 files changed, 94 insertions(+), 30 deletions(-) diff --git a/TODO b/TODO index f2dd7b1f..9fe457d2 100644 --- a/TODO +++ b/TODO @@ -18,6 +18,39 @@ - remove im__handle_eval etc. from headers + - png read/write needs redoing: + + http://www.libpng.org/pub/png/src/libpng-1.4.x-to-1.5.x-summary.txt + + ... the ability to directly access + the main libpng control structures, png_struct and png_info, deprecated + in earlier versions of libpng, has been completely removed from + libpng 1.5. + + argh + +- sink.c, sinkdisc.c, sinkmemory.c all define this function: + + static int + sink_progress( void *a ) + { + Sink *sink = (Sink *) a; + + VIPS_DEBUG_MSG( "sink_progress: %d x %d\n", + sink->tile_width, sink->tile_height ); + + /* Trigger any eval callbacks on our source image and + * check for errors. + */ + vips_image_eval( sink->im, + sink->tile_width, sink->tile_height ); + if( vips_image_get_kill( im ) ) + return( -1 ); + + return( 0 ); + } + + how dumb, common this up somehow - pre/post/close should be on VipsObject, not VipsImage diff --git a/libvips/include/vips/object.h b/libvips/include/vips/object.h index 856bdecf..2d1f22f3 100644 --- a/libvips/include/vips/object.h +++ b/libvips/include/vips/object.h @@ -248,6 +248,7 @@ void vips_object_set_property( GObject *gobject, void vips_object_get_property( GObject *gobject, guint property_id, GValue *value, GParamSpec *pspec ); +void vips_object_preclose( VipsObject *object ); int vips_object_build( VipsObject *object ); void vips_object_print_class( VipsObjectClass *klass ); void vips_object_print( VipsObject *object ); diff --git a/libvips/include/vips/vips7compat.h b/libvips/include/vips/vips7compat.h index a94429f9..5684b3df 100644 --- a/libvips/include/vips/vips7compat.h +++ b/libvips/include/vips/vips7compat.h @@ -155,10 +155,10 @@ extern "C" { #define im_image vips_image_new_from_memory #define im_binfile vips_image_new_from_file_raw #define im__open_temp vips_image_new_disc_temp -#define im__test_kill( I ) (!vips_image_get_kill( I )) -#define im__start_eval( I ) (vips_image_preeval( I ), !vips_image_get_kill( I )) +#define im__test_kill( I ) (vips_image_get_kill( I )) +#define im__start_eval( I ) (vips_image_preeval( I ), vips_image_get_kill( I )) #define im__handle_eval( I, W, H ) \ - (vips_image_eval( I, W, H ), !vips_image_get_kill( I )) + (vips_image_eval( I, W, H ), vips_image_get_kill( I )) #define im__end_eval vips_image_posteval #define im_invalidate vips_image_invalidate_all #define im_isfile vips_image_isfile diff --git a/libvips/iofuncs/image.c b/libvips/iofuncs/image.c index f4a74298..0cd1f101 100644 --- a/libvips/iofuncs/image.c +++ b/libvips/iofuncs/image.c @@ -422,6 +422,8 @@ vips_image_dispose( GObject *gobject ) vips_object_print( VIPS_OBJECT( gobject ) ); #endif /*VIPS_DEBUG*/ + vips_object_preclose( VIPS_OBJECT( gobject ) ); + G_OBJECT_CLASS( vips_image_parent_class )->dispose( gobject ); } @@ -479,6 +481,8 @@ lazy_new( VipsImage *image, { Lazy *lazy; + VIPS_DEBUG_MSG( "lazy_new: \"%s\"\n", filename ); + if( !(lazy = VIPS_NEW( image, Lazy )) ) return( NULL ); lazy->image = image; @@ -827,6 +831,11 @@ vips_image_build( VipsObject *object ) } } else { + /* Make this a partial, generate into it from the + * converter. + */ + image->dtype = VIPS_IMAGE_PARTIAL; + if( vips_image_open_lazy( image, format, filename, mode[1] == 'd' ) ) return( -1 ); @@ -970,6 +979,9 @@ vips_image_class_init( VipsImageClass *class ) gobject_class->set_property = vips_object_set_property; gobject_class->get_property = vips_object_get_property; + vobject_class->nickname = "image"; + vobject_class->description = _( "VIPS image class" ); + vobject_class->print = vips_image_print; vobject_class->build = vips_image_build; @@ -1342,8 +1354,8 @@ vips_image_get_kill( VipsImage *image ) void vips_image_set_kill( VipsImage *image, gboolean kill ) { - VIPS_DEBUG_MSG( "vips_image_set_kill: %s = %d\n", - image->filename, kill ); + if( !image->kill ) + VIPS_DEBUG_MSG( "vips_image_set_kill: %s\n", image->filename ); image->kill = kill; } diff --git a/libvips/iofuncs/object.c b/libvips/iofuncs/object.c index 51324aed..ae49a42d 100644 --- a/libvips/iofuncs/object.c +++ b/libvips/iofuncs/object.c @@ -30,8 +30,10 @@ */ /* -#define DEBUG */ +#define DEBUG +#define VIPS_DEBUG +#define DEBUG_REF #ifdef HAVE_CONFIG_H #include @@ -73,7 +75,7 @@ static guint vips_object_signals[SIG_LAST] = { 0 }; G_DEFINE_ABSTRACT_TYPE( VipsObject, vips_object, G_TYPE_OBJECT ); -static void +void vips_object_preclose( VipsObject *object ) { if( !object->preclose ) { @@ -152,7 +154,7 @@ vips_object_print( VipsObject *object ) vips_object_print_class( class ); vips_buf_init_static( &buf, str, 1000 ); class->print( object, &buf ); - printf( "\n%s (%p)\n", vips_buf_all( &buf ), object ); + printf( "%s\n", vips_buf_all( &buf ) ); } /* Extra stuff we track for properties to do our argument handling. @@ -394,9 +396,14 @@ vips_object_dispose( GObject *gobject ) /* Our subclasses should have already called this. Run it again, just * in case. */ - if( !object->preclose ) + if( !object->preclose ) { +#ifdef VIPS_DEBUG printf( "vips_object_dispose: no vips_object_preclose()\n" ); - vips_object_preclose( object ); + vips_object_print( VIPS_OBJECT( gobject ) ); +#endif /*VIPS_DEBUG*/ + + vips_object_preclose( object ); + } /* Clear all our arguments: they may be holding refs we should drop. */ diff --git a/libvips/iofuncs/region.c b/libvips/iofuncs/region.c index fe2667bf..b02f2089 100644 --- a/libvips/iofuncs/region.c +++ b/libvips/iofuncs/region.c @@ -274,6 +274,8 @@ vips_region_dispose( GObject *gobject ) vips_object_print( VIPS_OBJECT( gobject ) ); #endif /*VIPS_DEBUG*/ + vips_object_preclose( VIPS_OBJECT( gobject ) ); + /* Stop this sequence. */ vips__region_stop( region ); diff --git a/libvips/iofuncs/sink.c b/libvips/iofuncs/sink.c index d5ec94b4..7ae86db3 100644 --- a/libvips/iofuncs/sink.c +++ b/libvips/iofuncs/sink.c @@ -290,11 +290,14 @@ sink_progress( void *a ) { Sink *sink = (Sink *) a; + VIPS_DEBUG_MSG( "sink_progress: %d x %d\n", + sink->tile_width, sink->tile_height ); + /* Trigger any eval callbacks on our source image and * check for errors. */ - if( im__handle_eval( sink->im, - sink->tile_width, sink->tile_height ) ) + vips_image_eval( sink->im, sink->tile_width, sink->tile_height ); + if( vips_image_get_kill( sink->im ) ) return( -1 ); return( 0 ); @@ -350,10 +353,7 @@ vips_sink_tile( VipsImage *im, sink.tile_height = tile_height; } - if( im__start_eval( sink.t ) ) { - sink_free( &sink ); - return( -1 ); - } + vips_image_preeval( sink.t ); result = vips_threadpool_run( im, sink_thread_state_new, @@ -362,7 +362,7 @@ vips_sink_tile( VipsImage *im, sink_progress, &sink ); - im__end_eval( sink.t ); + vips_image_posteval( sink.t ); sink_free( &sink ); diff --git a/libvips/iofuncs/sinkdisc.c b/libvips/iofuncs/sinkdisc.c index 5f03bd64..1f6925c4 100644 --- a/libvips/iofuncs/sinkdisc.c +++ b/libvips/iofuncs/sinkdisc.c @@ -440,8 +440,8 @@ wbuffer_progress_fn( void *a ) /* Trigger any eval callbacks on our source image and * check for errors. */ - if( im__handle_eval( write->im, - write->tile_width, write->tile_height ) ) + vips_image_eval( write->im, write->tile_width, write->tile_height ); + if( vips_image_get_kill( write->im ) ) return( -1 ); return( 0 ); @@ -510,8 +510,7 @@ vips_sink_disc( VipsImage *im, VipsRegionWrite write_fn, void *a ) Write write; int result; - if( im__start_eval( im ) ) - return( -1 ); + vips_image_preeval( im ); write_init( &write, im, write_fn, a ); @@ -541,7 +540,7 @@ vips_sink_disc( VipsImage *im, VipsRegionWrite write_fn, void *a ) if( !result ) im_semaphore_down( &write.buf->done ); - im__end_eval( im ); + vips_image_posteval( im ); write_free( &write ); diff --git a/libvips/iofuncs/sinkmemory.c b/libvips/iofuncs/sinkmemory.c index 27c04420..ca8c89a2 100644 --- a/libvips/iofuncs/sinkmemory.c +++ b/libvips/iofuncs/sinkmemory.c @@ -166,8 +166,8 @@ sink_progress( void *a ) /* Trigger any eval callbacks on our source image and * check for errors. */ - if( im__handle_eval( sink->im, - sink->tile_width, sink->tile_height ) ) + vips_image_eval( sink->im, sink->tile_width, sink->tile_height ); + if( vips_image_get_kill( sink->im ) ) return( -1 ); return( 0 ); @@ -200,10 +200,7 @@ vips_sink_memory( VipsImage *im ) if( sink_init( &sink, im ) ) return( -1 ); - if( im__start_eval( im ) ) { - sink_free( &sink ); - return( -1 ); - } + vips_image_preeval( im ); result = vips_threadpool_run( im, vips_thread_state_new, @@ -212,7 +209,7 @@ vips_sink_memory( VipsImage *im ) sink_progress, &sink ); - im__end_eval( im ); + vips_image_posteval( im ); sink_free( &sink ); diff --git a/libvips/iofuncs/vips7compat.c b/libvips/iofuncs/vips7compat.c index 7a4d10ce..96a70964 100644 --- a/libvips/iofuncs/vips7compat.c +++ b/libvips/iofuncs/vips7compat.c @@ -91,7 +91,8 @@ typedef struct { static void im_add_callback_cb( VipsImage *im, Callback *callback ) { - callback->fn( callback->a, callback->b ); + if( callback->fn( callback->a, callback->b ) ) + vips_image_set_kill( im, TRUE ); } int diff --git a/tools/iofuncs/vips.c b/tools/iofuncs/vips.c index 5dd7bd86..aa3ee23f 100644 --- a/tools/iofuncs/vips.c +++ b/tools/iofuncs/vips.c @@ -65,6 +65,7 @@ /* #define DEBUG_FATAL +#define DEBUG_LEAK */ #ifdef HAVE_CONFIG_H @@ -78,6 +79,7 @@ #include #include +#include #ifdef OS_WIN32 #define strcasecmp(a,b) _stricmp(a,b) @@ -919,6 +921,10 @@ main( int argc, char **argv ) fprintf( stderr, "*** DEBUG_FATAL: will abort() on first warning\n" ); #endif /*!DEBUG_FATAL*/ +#ifdef DEBUG_LEAK + fprintf( stderr, "*** DEBUG_LEAK: will leak test on exit\n" ); +#endif /*!DEBUG_LEAK*/ + context = g_option_context_new( _( "- VIPS driver program" ) ); g_option_context_add_main_entries( context, @@ -1020,5 +1026,11 @@ main( int argc, char **argv ) im_close_plugins(); +#ifdef DEBUG_LEAK + printf( "** leak test on exit:\n" ); + im__print_all(); + printf( "** leak test done\n" ); +#endif /*DEBUG_LEAK*/ + return( 0 ); }