diff --git a/TODO b/TODO index 4cb16877..5fb7763f 100644 --- a/TODO +++ b/TODO @@ -1,10 +1,6 @@ -- add a direct route to flood for label_regions, delay speeding up operation - dispatch for now, seems like a large job +- break vipsflood into a separate struct we can use directly - a direct path can also avoid things like vector_to_ink, which involve - running a pipeline to generate a single pixel - - almost working + same for draw_mask - it was quick .. @@ -14,9 +10,13 @@ user 0m0.173s sys 0m0.031s - now incredibly slow + best now: + + $ time vips labelregions babe.jpg x.v + real 0m3.951s + user 0m3.940s + sys 0m0.032s - can we speed up function dispatch at all? - ink to vec etc. should work for complex .. output or accept a double-length vector diff --git a/libvips/draw/draw_flood.c b/libvips/draw/draw_flood.c index c9cf97e5..0063242e 100644 --- a/libvips/draw/draw_flood.c +++ b/libvips/draw/draw_flood.c @@ -548,6 +548,9 @@ vips__draw_flood_direct( VipsImage *image, VipsImage *test, } ((VipsDraw *) flood)->image = image; + g_object_ref( image ); + ((VipsDraw *) flood)->lsize = VIPS_IMAGE_SIZEOF_LINE( image ); + ((VipsDraw *) flood)->psize = VIPS_IMAGE_SIZEOF_PEL( image ); if( !(((VipsDrawink *) flood)->pixel_ink = VIPS_ARRAY( flood, VIPS_IMAGE_SIZEOF_PEL( image ), VipsPel )) ) { @@ -556,12 +559,16 @@ vips__draw_flood_direct( VipsImage *image, VipsImage *test, } *((int *) (((VipsDrawink *) flood)->pixel_ink)) = serial; + flood->x = x; + flood->y = y; flood->test = test; + g_object_ref( test ); + flood->equal = TRUE; flood->tsize = VIPS_IMAGE_SIZEOF_PEL( test ); - flood->left = flood->x; - flood->top = flood->y; - flood->right = flood->x; - flood->bottom = flood->y; + flood->left = x; + flood->top = y; + flood->right = x; + flood->bottom = y; flood->in = buffer_build(); flood->out = buffer_build(); diff --git a/libvips/morphology/labelregions.c b/libvips/morphology/labelregions.c index e70be565..4db0efee 100644 --- a/libvips/morphology/labelregions.c +++ b/libvips/morphology/labelregions.c @@ -88,12 +88,7 @@ vips_labelregions_build( VipsObject *object ) for( y = 0; y < t[1]->Ysize; y++ ) { for( x = 0; x < t[1]->Xsize; x++ ) { if( !m[x] ) { - /* - if( vips_draw_flood1( t[1], serial, x, y, - "test", in, - "equal", TRUE, - NULL ) ) - return( -1 ); + /* Use a direct path for speed. */ if( vips__draw_flood_direct( t[1], in, serial, x, y ) )