add gif, heif, rad, webp early close

This commit is contained in:
John Cupitt 2019-07-21 12:29:25 +01:00
parent 2c654060f9
commit 4f2f4b4577
5 changed files with 60 additions and 8 deletions

View File

@ -1009,6 +1009,12 @@ vips_foreign_load_gif_generate( VipsRegion *or,
return( 0 );
}
static void
vips_foreign_load_gif_minimise( VipsObject *object, VipsForeignLoadGif *gif )
{
vips_foreign_load_gif_close( gif );
}
static int
vips_foreign_load_gif_load( VipsForeignLoad *load )
{
@ -1052,6 +1058,11 @@ vips_foreign_load_gif_load( VipsForeignLoad *load )
if( vips_foreign_load_gif_set_header( gif, t[0] ) )
return( -1 );
/* CLose input immediately at end of read.
*/
g_signal_connect( t[0], "minimise",
G_CALLBACK( vips_foreign_load_gif_minimise ), gif );
/* Strips 8 pixels high to avoid too many tiny regions.
*/
if( vips_image_generate( t[0],

View File

@ -128,14 +128,21 @@ typedef VipsForeignLoadClass VipsForeignLoadHeifClass;
G_DEFINE_ABSTRACT_TYPE( VipsForeignLoadHeif, vips_foreign_load_heif,
VIPS_TYPE_FOREIGN_LOAD );
static void
vips_foreign_load_heif_close( VipsForeignLoadHeif *heif )
{
VIPS_FREEF( heif_image_release, heif->img );
heif->data = NULL;
VIPS_FREEF( heif_image_handle_release, heif->handle );
VIPS_FREEF( heif_context_free, heif->ctx );
}
static void
vips_foreign_load_heif_dispose( GObject *gobject )
{
VipsForeignLoadHeif *heif = (VipsForeignLoadHeif *) gobject;
VIPS_FREEF( heif_image_release, heif->img );
VIPS_FREEF( heif_image_handle_release, heif->handle );
VIPS_FREEF( heif_context_free, heif->ctx );
vips_foreign_load_heif_close( heif );
VIPS_FREE( heif->id );
G_OBJECT_CLASS( vips_foreign_load_heif_parent_class )->
@ -686,6 +693,12 @@ vips_foreign_load_heif_generate( VipsRegion *or,
return( 0 );
}
static void
vips_foreign_load_heif_minimise( VipsObject *object, VipsForeignLoadHeif *heif )
{
vips_foreign_load_heif_close( heif );
}
static int
vips_foreign_load_heif_load( VipsForeignLoad *load )
{
@ -701,6 +714,12 @@ vips_foreign_load_heif_load( VipsForeignLoad *load )
t[0] = vips_image_new();
if( vips_foreign_load_heif_set_header( heif, t[0] ) )
return( -1 );
/* CLose input immediately at end of read.
*/
g_signal_connect( t[0], "minimise",
G_CALLBACK( vips_foreign_load_heif_minimise ), heif );
if( vips_image_generate( t[0],
NULL, vips_foreign_load_heif_generate, NULL, heif, NULL ) ||
vips_sequential( t[0], &t[1], NULL ) ||

View File

@ -984,12 +984,17 @@ vips__rad_israd( const char *filename )
return( result == 1 );
}
static void
read_minimise( VipsObject *object, Read *read )
{
VIPS_FREEF( buffer_free, read->buffer );
VIPS_FREEF( fclose, read->fin );
}
static void
read_destroy( VipsObject *object, Read *read )
{
VIPS_FREE( read->filename );
VIPS_FREEF( fclose, read->fin );
VIPS_FREEF( buffer_free, read->buffer );
}
static Read *
@ -1019,6 +1024,8 @@ read_new( const char *filename, VipsImage *out )
read->prims[3][1] = CIE_y_w;
read->buffer = NULL;
g_signal_connect( out, "minimise",
G_CALLBACK( read_minimise ), read );
g_signal_connect( out, "close",
G_CALLBACK( read_destroy ), read );

View File

@ -342,8 +342,8 @@ vips__iswebp( const char *filename )
return( 0 );
}
static int
read_free( Read *read )
static void
read_minimise( Read *read )
{
WebPDemuxReleaseIterator( &read->iter );
VIPS_UNREF( read->frame );
@ -359,6 +359,13 @@ read_free( Read *read )
}
VIPS_FREEF( vips_tracked_close, read->fd );
}
static int
read_free( Read *read )
{
read_minimise( read );
VIPS_FREE( read->filename );
VIPS_FREE( read->delays );
VIPS_FREE( read );
@ -793,6 +800,12 @@ read_webp_generate( VipsRegion *or,
return( 0 );
}
static void
read_minimise_cb( VipsObject *object, Read *read )
{
read_minimise( read );
}
static int
read_image( Read *read, VipsImage *out )
{
@ -803,6 +816,9 @@ read_image( Read *read, VipsImage *out )
if( read_header( read, t[0] ) )
return( -1 );
g_signal_connect( t[0], "minimise",
G_CALLBACK( read_minimise_cb ), read );
if( vips_image_generate( t[0],
NULL, read_webp_generate, NULL, read, NULL ) ||
vips_sequential( t[0], &t[1], NULL ) ||

View File

@ -266,7 +266,6 @@ vips_shrinkv_gen( VipsRegion *or, void *vseq,
{
VipsShrinkvSequence *seq = (VipsShrinkvSequence *) vseq;
VipsShrinkv *shrink = (VipsShrinkv *) b;
VipsResample *resample = VIPS_RESAMPLE( shrink );
VipsRegion *ir = seq->ir;
VipsRect *r = &or->valid;