better vips7 progress compat

make progress info on both the image being generated and the image we
signal on
This commit is contained in:
John Cupitt 2011-03-24 14:28:35 +00:00
parent 5da71c8336
commit 82dbdedd6e

View File

@ -1323,6 +1323,24 @@ vips_progress_add( VipsImage *image )
return( 0 ); return( 0 );
} }
void
vips_progress_update( VipsProgress *progress, int w, int h )
{
float prop;
g_assert( progress );
progress->run = g_timer_elapsed( progress->start, NULL );
progress->npels += w * h;
prop = (float) progress->npels / (float) progress->tpels;
progress->percent = 100 * prop;
/* Don't estiomate eta until we are 10% in.
*/
if( prop > 0.1 )
progress->eta = (1.0 / prop) * progress->run - progress->run;
}
void void
vips_image_preeval( VipsImage *image ) vips_image_preeval( VipsImage *image )
{ {
@ -1332,6 +1350,12 @@ vips_image_preeval( VipsImage *image )
g_assert( vips_object_sanity( g_assert( vips_object_sanity(
VIPS_OBJECT( image->progress_signal ) ) ); VIPS_OBJECT( image->progress_signal ) ) );
(void) vips_progress_add( image );
/* For vips7 compat, we also have to make sure ->time on the
* image that was originally marked with
* vips_image_set_progress() is valid.
*/
(void) vips_progress_add( image->progress_signal ); (void) vips_progress_add( image->progress_signal );
g_signal_emit( image->progress_signal, g_signal_emit( image->progress_signal,
@ -1346,25 +1370,21 @@ void
vips_image_eval( VipsImage *image, int w, int h ) vips_image_eval( VipsImage *image, int w, int h )
{ {
if( image->progress_signal ) { if( image->progress_signal ) {
VipsProgress *progress = image->progress_signal->time;
float prop;
VIPS_DEBUG_MSG( "vips_image_eval: %p\n", image ); VIPS_DEBUG_MSG( "vips_image_eval: %p\n", image );
g_assert( progress );
g_assert( vips_object_sanity( g_assert( vips_object_sanity(
VIPS_OBJECT( image->progress_signal ) ) ); VIPS_OBJECT( image->progress_signal ) ) );
progress->run = g_timer_elapsed( progress->start, NULL ); vips_progress_update( image->time, w, h );
progress->npels += w * h;
prop = (float) progress->npels / (float) progress->tpels; /* For vips7 compat, update the ->time on the signalling image
progress->percent = 100 * prop; * too, even though it may have a different width/height to
if( prop > 0.1 ) * the image we are actually generating.
progress->eta = (1.0 / prop) * progress->run - */
progress->run; vips_progress_update( image->progress_signal->time, w, h );
g_signal_emit( image->progress_signal, g_signal_emit( image->progress_signal,
vips_image_signals[SIG_EVAL], 0, progress ); vips_image_signals[SIG_EVAL], 0, image->time );
} }
} }