From 8f60a3a957dee9b5c9877cf199774452f8bd9066 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 20 Oct 2009 12:58:45 +0000 Subject: [PATCH] added im_insertplaceset --- ChangeLog | 1 + TODO | 6 +--- libvips/inplace/inplace_dispatch.c | 50 ++++++++++++++++++++++++++++++ libvips/iofuncs/im_generate.c | 17 +++++++++- 4 files changed, 68 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index a0bebeeb..d5577be0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -67,6 +67,7 @@ - threadgroup no longer has any default action, you must attach a work function - added im_copy_file() +- added im_insertplaceset() 25/3/09 started 7.18.0 - revised version numbers diff --git a/TODO b/TODO index 2d5e7851..8fec1e3f 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,4 @@ -- im_cache() seems to kill threading? - - pipeline, im_cache(), output - - can we get >100% cpu? try a tiny test program +- im_lineset() could be simpler, see im_insertplaceset() - memory.c diff --git a/libvips/inplace/inplace_dispatch.c b/libvips/inplace/inplace_dispatch.c index d282fff2..a43ece59 100644 --- a/libvips/inplace/inplace_dispatch.c +++ b/libvips/inplace/inplace_dispatch.c @@ -186,6 +186,55 @@ static im_function lineset_desc = { lineset_args /* Arg list */ }; +/* Args for im_insertplaceset. + */ +static im_arg_desc insertplaceset_args[] = { + IM_INPUT_IMAGE( "main" ), + IM_INPUT_IMAGE( "sub" ), + IM_OUTPUT_IMAGE( "out" ), + IM_INPUT_INTVEC( "x" ), + IM_INPUT_INTVEC( "y" ) +}; + +/* Call im_insertplaceset via arg vector. + */ +static int +insertplaceset_vec( im_object *argv ) +{ + im_intvec_object *xv = (im_intvec_object *) argv[3]; + im_intvec_object *yv = (im_intvec_object *) argv[4]; + int i; + + if( xv->n != yv->n ) { + im_error( "im_insertplaceset", "%s", + _( "vectors not same length" ) ); + return( -1 ); + } + + /* Copy the image then repeatedly im_insertplace(). This will make + * "out" into a "t", usually. + */ + if( im_copy( argv[0], argv[2] ) ) + return( -1 ); + + for( i = 0; i < xv->n; i++ ) + if( im_insertplace( argv[2], argv[1], xv->vec[i], yv->vec[i] ) ) + return( -1 ); + + return( 0 ); +} + +/* Description of im_insertplaceset. + */ +static im_function insertplaceset_desc = { + "im_insertplaceset", /* Name */ + "insert sub into main at every position in x, y", + 0, /* Flags */ + insertplaceset_vec, /* Dispatch function */ + IM_NUMBER( insertplaceset_args ), /* Size of arg list */ + insertplaceset_args /* Arg list */ +}; + /* Calculate a pixel for an image from a vec of double. Valid while im is * valid. */ @@ -346,6 +395,7 @@ static im_function *inplace_list[] = { &flood_other_copy_desc, &segment_desc, &insertplace_desc, + &insertplaceset_desc, &line_desc, &lineset_desc }; diff --git a/libvips/iofuncs/im_generate.c b/libvips/iofuncs/im_generate.c index 567ffb55..5b8c2562 100644 --- a/libvips/iofuncs/im_generate.c +++ b/libvips/iofuncs/im_generate.c @@ -327,6 +327,13 @@ eval_to_region( REGION *or, im_threadgroup_t *tg ) int x, y; +#ifdef DEBUG_IO + int ntiles = 0; + printf( "eval_to_region: partial image output to region\n" ); + printf( "\tleft = %d, top = %d, width = %d, height = %d\n", + r->left, r->top, r->width, r->height ); +#endif /*DEBUG_IO*/ + image.left = 0; image.top = 0; image.width = or->im->Xsize; @@ -377,6 +384,10 @@ eval_to_region( REGION *or, im_threadgroup_t *tg ) im_threadgroup_wait( tg ); return( -1 ); } + +#ifdef DEBUG_IO + ntiles++; +#endif /*DEBUG_IO*/ } /* Wait for all threads to hit 'go' again. @@ -386,6 +397,10 @@ eval_to_region( REGION *or, im_threadgroup_t *tg ) if( im_threadgroup_iserror( tg ) ) return( -1 ); +#ifdef DEBUG_IO + printf( "eval_to_region: %d patches calculated\n", ntiles ); +#endif /*DEBUG_IO*/ + return( 0 ); } @@ -451,7 +466,7 @@ eval_to_memory( im_threadgroup_t *tg, REGION *or ) result |= im__end_eval( im ); #ifdef DEBUG_IO - printf( "eval_to_memory: %d patches written\n", ntiles ); + printf( "eval_to_memory: %d patches calculated\n", ntiles ); #endif /*DEBUG_IO*/ return( result );