From 3673808aa44203db7d1378371637741ec952ce26 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 22 Jan 2010 16:56:57 +0000 Subject: [PATCH] flood fixes --- ChangeLog | 1 + TODO | 8 ++++++++ libvips/inplace/flood.c | 12 ++++++++++++ libvips/iofuncs/check.c | 7 +++++-- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index a0ee3a7b..637f9af4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -21,6 +21,7 @@ - added "written" callbacks, used to implement write to non-vips formats - "invalidate" is careful to keep images alive, so invalidate callbacks can do im_close() +- flood_blob could loop if start point == ink 26/11/09 started 7.20.3 - updated en_GB.po translation diff --git a/TODO b/TODO index bedff8b3..ad793dec 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,14 @@ - how about im_invalidate_area()? we currently repaint the whole window on every paint action in nip2 :-( + we'd need to have coordinate transforms broken out for this :-( + +- should im_rwcheck() copy to disc? + + maybe im_rwcheck_disc() copies to im->filename and maps that + + rather awfward to do atm + - flood blob with ink == initial click loops - we sill have the old flood-fill code there, move to deprecated diff --git a/libvips/inplace/flood.c b/libvips/inplace/flood.c index 205ed324..d9ced19c 100644 --- a/libvips/inplace/flood.c +++ b/libvips/inplace/flood.c @@ -21,6 +21,8 @@ * 21/12/09 * - rewrite for a scanline based fill, about 4x faster! * - allow separate test and mark images + * 22/1/10 + * - flood_blob could loop if start point == ink */ /* @@ -501,6 +503,7 @@ int im_flood_blob( IMAGE *im, int x, int y, PEL *ink, Rect *dout ) { Flood *flood; + int j; if( im_rwcheck( im ) || im_check_known_coded( "im_flood", im ) ) @@ -513,6 +516,15 @@ im_flood_blob( IMAGE *im, int x, int y, PEL *ink, Rect *dout ) memcpy( flood->edge, IM_IMAGE_ADDR( im, x, y ), flood->tsize ); flood->equal = 1; + /* If edge == ink, we'll never stop :-( or rather, there's nothing to + * do. + */ + for( j = 0; j < flood->tsize; j++ ) + if( flood->edge[j] != flood->ink[j] ) + break; + if( j == flood->tsize ) + return( 0 ); + flood_all( flood, x, y ); flood_free( flood ); diff --git a/libvips/iofuncs/check.c b/libvips/iofuncs/check.c index acf7ef9b..4e0b8ad8 100644 --- a/libvips/iofuncs/check.c +++ b/libvips/iofuncs/check.c @@ -225,12 +225,15 @@ im_incheck( IMAGE *im ) break; case IM_OPENOUT: - /* Close file down and reopen as input. + /* Close file down and reopen as input. I guess this will only + * work for vips files? */ #ifdef DEBUG_IO printf( "im_incheck: auto-rewind of %s\n", im->filename ); #endif/*DEBUG_IO*/ - if( im__close( im ) || im_openin( im ) ) { + if( im__close( im ) || + im_openin( im ) || + im_incheck( im ) ) { im_error( "im_incheck", _( "auto-rewind for %s failed" ), im->filename );