put close-on-last-line back for jpg/tif/png

consider something like:

$ vips arrayjoin "$(echo *.jpg)" x.tif --across 10 --vips-progress

close on minimise won't close until the whole pipeline finishes, so
we'll need to keep every input file open

close on last line will shut down inputs as we are done with them, so we
save a lot of file descriptors

this patch puts close-on-last-line back for jpg/tif/png
This commit is contained in:
John Cupitt 2019-07-28 11:34:40 +01:00
parent 55ae22608f
commit 5ef14db544
3 changed files with 38 additions and 9 deletions

View File

@ -299,20 +299,17 @@ readjpeg_file( ReadJpeg *jpeg, const char *filename )
static const char *
find_chroma_subsample( struct jpeg_decompress_struct *cinfo )
{
gboolean has_subsample;
/* libjpeg only uses 4:4:4 and 4:2:0, confusingly.
*
* http://poynton.ca/PDFs/Chroma_subsampling_notation.pdf
*/
has_subsample = cinfo->max_h_samp_factor > 1 ||
gboolean has_subsample = cinfo->max_h_samp_factor > 1 ||
cinfo->max_v_samp_factor > 1;
if( cinfo->num_components > 3 )
/* A cmyk image.
*/
return( has_subsample ? "4:2:0:4" : "4:4:4:4" );
else
return( has_subsample ? "4:2:0" : "4:4:4" );
gboolean is_cmyk = cinfo->num_components > 3;
return( is_cmyk ?
(has_subsample ? "4:2:0:4" : "4:4:4:4" ) :
(has_subsample ? "4:2:0" : "4:4:4") );
}
static int
@ -727,6 +724,10 @@ read_jpeg_generate( VipsRegion *or,
jpeg->y_pos += 1;
}
/* Shut down the input file.
*/
if( jpeg->y_pos >= or->im->Ysize )
readjpeg_close_input( jpeg );
VIPS_GATE_STOP( "read_jpeg_generate: work" );

View File

@ -1963,6 +1963,15 @@ rtiff_stripwise_generate( VipsRegion *or,
rtiff->y_pos += hit.height;
}
/* Shut down the input file as soon as we can.
*/
if( rtiff->y_pos >= or->im->Ysize ) {
#ifdef DEBUG
printf( "rtiff_stripwise_generate: early shutdown\n" );
#endif /*DEBUG*/
rtiff_free( rtiff );
}
VIPS_GATE_STOP( "rtiff_stripwise_generate: work" );
return( 0 );

View File

@ -660,6 +660,25 @@ png2vips_generate( VipsRegion *or,
read->y_pos += 1;
}
/* Catch errors from png_read_end(). This can fail on a truncated
* file.
*/
if( setjmp( png_jmpbuf( read->pPng ) ) ) {
if( read->fail ) {
vips_error( "vipspng", "%s", _( "libpng read error" ) );
return( -1 );
}
return( 0 );
}
/* Early close to free the fd as soon as we can.
*/
if( read->y_pos >= read->out->Ysize ) {
png_read_end( read->pPng, NULL );
read_destroy( read );
}
return( 0 );
}