From 3694a2edc549e53b68552a5d5b44ff0e16bf78b6 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sun, 24 Jun 2012 09:44:50 +0100 Subject: [PATCH] add sequential mode to vips7 the tiff and jpg readers let you give :seq as well --- ChangeLog | 1 + TODO | 9 +++++---- libvips/conversion/tilecache.c | 12 ++++++++++-- libvips/deprecated/im_jpeg2vips.c | 7 +++++++ libvips/deprecated/im_tiff2vips.c | 6 ++++++ libvips/foreign/foreign.c | 6 ++++++ libvips/foreign/jpeg2vips.c | 2 +- libvips/iofuncs/generate.c | 2 +- libvips/iofuncs/image.c | 2 -- libvips/iofuncs/threadpool.c | 2 -- 10 files changed, 37 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index eec4aa90..7c415935 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,7 @@ - vipsthumbnail no longer removes profiles by default - much more gentle sharpening in thumbnails - added "minimise" signal, used by tilecache to drop +- add :seq support to im_tiff2vips(), im_jpeg2vips() ... helps ruby-vips 18/6/12 started 7.28.9 - slightly more memory debugging output diff --git a/TODO b/TODO index d9d43420..ea35bf13 100644 --- a/TODO +++ b/TODO @@ -1,9 +1,10 @@ -- tile cache doesn't need to copy if request fits within a tile +- vips_image_minimise_all( im ); - though doing a copy means that we can safely drop the cache without leaving - dangling pointers + call this at the end of thereadpool_run(), doesnt seem to trigger the + minimise callback on tilecache? + + it does trigger it if we turn OFF seq mode??! how odd -- could jpeg load via memory buffer support minimise too? blocking bugs diff --git a/libvips/conversion/tilecache.c b/libvips/conversion/tilecache.c index 73e887a5..dc0ea4ad 100644 --- a/libvips/conversion/tilecache.c +++ b/libvips/conversion/tilecache.c @@ -15,6 +15,8 @@ * - use im_prepare_to() and avoid making a sequence for every cache tile * 5/12/11 * - rework as a class + * 23/6/12 + * - listen for "minimise" signal */ /* @@ -346,6 +348,14 @@ vips_tile_cache_gen( VipsRegion *or, g_mutex_lock( cache->lock ); + /* If the output region fits within a tile (tiles can become quite + * large for seq caches, for example), we could save a copy by routing + * the output region directly to the tile. + * + * However this would mean that tile drop on minimise could then leave + * dangling pointers, if minimuse was called on an active pipeline. + */ + VIPS_DEBUG_MSG( "vips_tile_cache_gen: " "left = %d, top = %d, width = %d, height = %d\n", r->left, r->top, r->width, r->height ); @@ -383,8 +393,6 @@ vips_tile_cache_gen( VipsRegion *or, static void vips_tile_cache_minimise( VipsImage *image, VipsTileCache *cache ) { - printf( "vips_tile_cache_minimise:\n" ); - vips_tile_cache_drop_all( cache ); } diff --git a/libvips/deprecated/im_jpeg2vips.c b/libvips/deprecated/im_jpeg2vips.c index 122fb9b1..e7a70485 100644 --- a/libvips/deprecated/im_jpeg2vips.c +++ b/libvips/deprecated/im_jpeg2vips.c @@ -52,6 +52,7 @@ im_jpeg2vips( const char *name, IMAGE *out ) char *p, *q; int shrink; gboolean fail_on_warn; + gboolean sequential; VipsImage *t; /* By default, we ignore any warnings. We want to get as much of @@ -64,6 +65,7 @@ im_jpeg2vips( const char *name, IMAGE *out ) im_filename_split( name, filename, mode ); p = &mode[0]; shrink = 1; + sequential = FALSE; if( (q = im_getnextoption( &p )) ) { shrink = atoi( q ); @@ -78,10 +80,15 @@ im_jpeg2vips( const char *name, IMAGE *out ) if( im_isprefix( "fail", q ) ) fail_on_warn = TRUE; } + if( (q = im_getnextoption( &p )) ) { + if( im_isprefix( "seq", q ) ) + sequential = TRUE; + } if( vips_jpegload( filename, &t, "shrink", shrink, "fail", fail_on_warn, + "sequential", sequential, NULL ) ) return( -1 ); diff --git a/libvips/deprecated/im_tiff2vips.c b/libvips/deprecated/im_tiff2vips.c index c701a1af..ba11e49f 100644 --- a/libvips/deprecated/im_tiff2vips.c +++ b/libvips/deprecated/im_tiff2vips.c @@ -55,6 +55,7 @@ im_tiff2vips( const char *name, IMAGE *out ) char mode[FILENAME_MAX]; char *p, *q; int page; + gboolean sequential; VipsImage *t; im_filename_split( name, filename, mode ); @@ -64,9 +65,14 @@ im_tiff2vips( const char *name, IMAGE *out ) if( (q = im_getnextoption( &p )) ) { page = atoi( q ); } + if( (q = im_getnextoption( &p )) ) { + if( im_isprefix( "seq", q ) ) + sequential = TRUE; + } if( vips_tiffload( filename, &t, "page", page, + "sequential", sequential, NULL ) ) return( -1 ); if( vips_image_write( t, out ) ) { diff --git a/libvips/foreign/foreign.c b/libvips/foreign/foreign.c index b0b0533e..15a09d3b 100644 --- a/libvips/foreign/foreign.c +++ b/libvips/foreign/foreign.c @@ -782,6 +782,12 @@ vips_foreign_load_start( VipsImage *out, void *a, void *b ) */ if( !vips_foreign_load_iscompat( load->real, out ) ) return( NULL ); + + /* We have to tell vips that out depends on real. We've set + * the demand hint below, but not given an input there. + */ + vips_demand_hint( load->out, load->out->dhint, + load->real, NULL ); } return( vips_region_new( load->real ) ); diff --git a/libvips/foreign/jpeg2vips.c b/libvips/foreign/jpeg2vips.c index 925c8018..6166dad6 100644 --- a/libvips/foreign/jpeg2vips.c +++ b/libvips/foreign/jpeg2vips.c @@ -905,7 +905,7 @@ read_jpeg_image( ReadJpeg *jpeg, VipsImage *out ) jpeg->decompressing = TRUE; #ifdef DEBUG - printf( "read_jpeg_image: starting deompress\n" ); + printf( "read_jpeg_image: starting decompress\n" ); #endif /*DEBUG*/ if( vips_image_generate( t[0], diff --git a/libvips/iofuncs/generate.c b/libvips/iofuncs/generate.c index 42f0c9bd..34b97581 100644 --- a/libvips/iofuncs/generate.c +++ b/libvips/iofuncs/generate.c @@ -329,7 +329,7 @@ vips_demand_hint_array( VipsImage *image, VipsDemandStyle hint, VipsImage **in ) for( i = 0; i < len; i++ ) vips__link_make( in[i], image ); - /* Set a flag on the image to say we remember to call this thing. + /* Set a flag on the image to say we remembered to call this thing. * vips_image_generate() and friends check this. */ image->hint_set = TRUE; diff --git a/libvips/iofuncs/image.c b/libvips/iofuncs/image.c index 5858c4bc..5e8105b4 100644 --- a/libvips/iofuncs/image.c +++ b/libvips/iofuncs/image.c @@ -1111,8 +1111,6 @@ vips_image_minimise_all_cb( VipsImage *image ) void vips_image_minimise_all( VipsImage *image ) { - printf( "vips_image_minimise_all:\n" ); - (void) vips__link_map( image, TRUE, (VipsSListMap2Fn) vips_image_minimise_all_cb, NULL, NULL ); } diff --git a/libvips/iofuncs/threadpool.c b/libvips/iofuncs/threadpool.c index d5f9098b..fa0f4eb3 100644 --- a/libvips/iofuncs/threadpool.c +++ b/libvips/iofuncs/threadpool.c @@ -913,8 +913,6 @@ vips_threadpool_run( VipsImage *im, vips_threadpool_free( pool ); - /* Ask the pipeline to drop into low-mem-use mode now we're done. - */ vips_image_minimise_all( im ); return( result );