vips_image_write() only refs input when it has to

when you write to a non-partial image, you create a sink ... so
vips_image_write() only needs to ref the input when writing to partials

this change makes it much easier to (for example) combine many images in
bounded space, see for example:

https://gist.github.com/jcupitt/c516325ebef7601b5da610af5619c9b2
This commit is contained in:
John Cupitt 2016-06-10 13:58:01 +01:00
parent 3ed174e9cb
commit 1909b31bd6
2 changed files with 15 additions and 6 deletions

View File

@ -17,6 +17,8 @@
- free pixel buffers on image close as well as thread exit ... stops main
thread buffers clogging up the system
- dzsave can write compressed zips [Felix Bünemann]
- vips_image_write() only refs the input when it has to ... makes it easier to
combine many images in bounded memory
18/5/16 started 8.3.2
- more robust vips image reading

View File

@ -8,6 +8,8 @@
* - add vips_image_copy_memory()
* 25/11/15
* - add vips_image_new_from_memory_copy()
* 10/6/16
* - vips_image_write() does not ref input for non-partial images
*/
/*
@ -2448,17 +2450,22 @@ vips_image_write( VipsImage *image, VipsImage *out )
VIPS_DEMAND_STYLE_THINSTRIP, image, NULL ) )
return( -1 );
/* We generate from @image partially, so we need to keep it about as
* long as @out is about.
*/
g_object_ref( image );
vips_object_local( out, image );
if( vips_image_generate( out,
vips_start_one, vips_image_write_gen, vips_stop_one,
image, NULL ) )
return( -1 );
/* If @out is a partial image, we need to make sure that @image stays
* alive as long as @out is alive.
*
* If it's not partial, perhaps a file we write to, or a memory image,
* it's fine for @image to go away.
*/
if( vips_image_ispartial( out ) ) {
g_object_ref( image );
vips_object_local( out, image );
}
return( 0 );
}