Skip to content

Commit

Permalink
vips_image_write() only refs input when it has to
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jcupitt committed Jun 10, 2016
1 parent 3ed174e commit 1909b31
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 13 additions & 6 deletions libvips/iofuncs/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

/*
Expand Down Expand Up @@ -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 );
}

Expand Down

0 comments on commit 1909b31

Please sign in to comment.