experiment with minimise in insert

try minimising sub after we've passed it
This commit is contained in:
John Cupitt 2019-07-27 13:40:18 +01:00
parent 67f3cc13ec
commit 01a82646a1
5 changed files with 40 additions and 3 deletions

View File

@ -34,7 +34,8 @@ equal_vector( std::vector<double> a, std::vector<double> b )
printf( "%g", a[i] ); printf( "%g", a[i] );
} }
printf( "], is [" ); printf( "], is [" );
for( unsigned int i = 0; i < a.size(); i++ ) { if( i > 0 ) for( unsigned int i = 0; i < a.size(); i++ ) {
if( i > 0 )
printf( ", " ); printf( ", " );
printf( "%g", a[i] ); printf( "%g", a[i] );
} }

View File

@ -28,6 +28,8 @@
* 29/9/11 * 29/9/11
* - rewrite as a class * - rewrite as a class
* - add expand, bg options * - add expand, bg options
* 27/7/19
* - minimise sub when we're done with it
*/ */
/* /*
@ -103,6 +105,10 @@ typedef struct _VipsInsert {
VipsRect rout; /* Output space */ VipsRect rout; /* Output space */
VipsRect rmain; /* Position of main in output */ VipsRect rmain; /* Position of main in output */
VipsRect rsub; /* Position of sub in output */ VipsRect rsub; /* Position of sub in output */
/* TRUE if we've minimise sub.
*/
gboolean sub_minimised;
} VipsInsert; } VipsInsert;
typedef VipsConversionClass VipsInsertClass; typedef VipsConversionClass VipsInsertClass;
@ -187,9 +193,21 @@ vips_insert_gen( VipsRegion *or, void *seq, void *a, void *b, gboolean *stop )
*/ */
vips_rect_intersectrect( &or->valid, &insert->rsub, &ovl ); vips_rect_intersectrect( &or->valid, &insert->rsub, &ovl );
if( vips_rect_includesrect( &insert->rmain, &or->valid ) && if( vips_rect_includesrect( &insert->rmain, &or->valid ) &&
vips_rect_isempty( &ovl ) ) vips_rect_isempty( &ovl ) ) {
/* If we're now below the sub-image, and we're in sequential
* mode, and we've not minimised it before, we can shut down
* that input.
*/
if( vips_image_is_sequential( insert->sub ) &&
r->top > VIPS_RECT_BOTTOM( &insert->rsub ) &&
!insert->sub_minimised ) {
insert->sub_minimised = TRUE;
vips_image_minimise_all( insert->sub );
}
return( vips__insert_just_one( or, ir[0], return( vips__insert_just_one( or, ir[0],
insert->rmain.left, insert->rmain.top ) ); insert->rmain.left, insert->rmain.top ) );
}
/* Output requires both (or neither) input. If it is not entirely /* Output requires both (or neither) input. If it is not entirely
* inside both the main and the sub, then there is going to be some * inside both the main and the sub, then there is going to be some

View File

@ -426,6 +426,8 @@ void vips_image_invalidate_all( VipsImage *image );
void vips_image_minimise_all( VipsImage *image ); void vips_image_minimise_all( VipsImage *image );
gboolean vips_image_is_sequential( VipsImage *image );
void vips_image_set_progress( VipsImage *image, gboolean progress ); void vips_image_set_progress( VipsImage *image, gboolean progress );
gboolean vips_image_iskilled( VipsImage *image ); gboolean vips_image_iskilled( VipsImage *image );
void vips_image_set_kill( VipsImage *image, gboolean kill ); void vips_image_set_kill( VipsImage *image, gboolean kill );

View File

@ -1454,6 +1454,22 @@ vips_image_minimise_all( VipsImage *image )
(VipsSListMap2Fn) vips_image_minimise_all_cb, NULL, NULL ); (VipsSListMap2Fn) vips_image_minimise_all_cb, NULL, NULL );
} }
/**
* vips_image_is_sequential: (method)
* @image: #VipsImage to minimise
*
* TRUE if any of the images upstream from @image were opened in sequential
* mode. Some operations change behaviour slightly in sequential mode to
* optimise memory behaviour.
*
* Returns: %TRUE if @image is in sequential mode.
*/
gboolean
vips_image_is_sequential( VipsImage *image )
{
return( vips_image_get_typeof( image, VIPS_META_SEQUENTIAL ) );
}
/* Attach a new time struct, if necessary, and reset it. /* Attach a new time struct, if necessary, and reset it.
*/ */
static int static int

View File

@ -413,7 +413,7 @@ vips_shrinkv_build( VipsObject *object )
* always have the previous XX lines of the shrunk image, and we won't * always have the previous XX lines of the shrunk image, and we won't
* fetch out of order. * fetch out of order.
*/ */
if( vips_image_get_typeof( in, VIPS_META_SEQUENTIAL ) ) { if( vips_image_is_sequential( in ) ) {
g_info( "shrinkv sequential line cache" ); g_info( "shrinkv sequential line cache" );
shrink->sequential = TRUE; shrink->sequential = TRUE;