From 4915fb0a83500b5d8c8ee1514c607b6321fe9724 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 1 Oct 2010 10:47:48 +0000 Subject: [PATCH] flood -> draw_flood --- TODO | 3 +- libvips/deprecated/rename.c | 19 +++++ libvips/include/vips/almostdeprecated.h | 5 ++ libvips/include/vips/inplace.h | 6 +- libvips/inplace/flood.c | 47 ++++++----- libvips/inplace/inplace_dispatch.c | 107 ++++++++++++------------ 6 files changed, 106 insertions(+), 81 deletions(-) diff --git a/TODO b/TODO index c3e09d97..b6817458 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,5 @@ - check gtk-doc output -- im_flood() -> im_draw_flood()? since it's inplace - - convsep / conv need to be able to do COMPLEX just double the bands @@ -13,6 +11,7 @@ - can we make more use of im__draw_pel()? eg. im_draw_rect() etc. +- what's nip2's performance on wide lines like now? diff --git a/libvips/deprecated/rename.c b/libvips/deprecated/rename.c index b1cbe1c0..a50a557e 100644 --- a/libvips/deprecated/rename.c +++ b/libvips/deprecated/rename.c @@ -695,3 +695,22 @@ im_smudge( VipsImage *image, int ix, int iy, Rect *r ) return( im_draw_smudge( image, r->left + ix, r->top + iy, r->width, r->height ) ); } + +int +im_flood( IMAGE *im, int x, int y, PEL *ink, Rect *dout ) +{ + return( im_draw_flood( im, x, y, ink, dout ) ); +} + +int +im_flood_blob( IMAGE *im, int x, int y, PEL *ink, Rect *dout ) +{ + return( im_draw_flood_blob( im, x, y, ink, dout ) ); +} + +int +im_flood_other( IMAGE *test, IMAGE *mark, + int x, int y, int serial, Rect *dout ) +{ + return( im_draw_flood_other( mark, test, x, y, serial, dout ) ); +} diff --git a/libvips/include/vips/almostdeprecated.h b/libvips/include/vips/almostdeprecated.h index 129261b0..d91699e5 100644 --- a/libvips/include/vips/almostdeprecated.h +++ b/libvips/include/vips/almostdeprecated.h @@ -239,6 +239,11 @@ int im_flood_blob_copy( IMAGE *in, IMAGE *out, int x, int y, PEL *ink ); int im_flood_other_copy( IMAGE *test, IMAGE *mark, IMAGE *out, int x, int y, int serial ); +int im_flood( IMAGE *im, int x, int y, PEL *ink, Rect *dout ); +int im_flood_blob( IMAGE *im, int x, int y, PEL *ink, Rect *dout ); +int im_flood_other( IMAGE *test, IMAGE *mark, + int x, int y, int serial, Rect *dout ); + int im_fastline( IMAGE *im, int x1, int y1, int x2, int y2, PEL *pel ); int im_fastlineuser( IMAGE *im, int x1, int y1, int x2, int y2, diff --git a/libvips/include/vips/inplace.h b/libvips/include/vips/inplace.h index 878167c0..fa47d32f 100644 --- a/libvips/include/vips/inplace.h +++ b/libvips/include/vips/inplace.h @@ -53,9 +53,9 @@ int im_draw_line( VipsImage *image, int x1, int y1, int x2, int y2, PEL *ink ); int im_lineset( VipsImage *in, VipsImage *out, VipsImage *mask, VipsImage *ink, int n, int *x1v, int *y1v, int *x2v, int *y2v ); -int im_flood( VipsImage *image, int x, int y, PEL *ink, Rect *dout ); -int im_flood_blob( VipsImage *image, int x, int y, PEL *ink, Rect *dout ); -int im_flood_other( VipsImage *image, VipsImage *test, +int im_draw_flood( VipsImage *image, int x, int y, PEL *ink, Rect *dout ); +int im_draw_flood_blob( VipsImage *image, int x, int y, PEL *ink, Rect *dout ); +int im_draw_flood_other( VipsImage *image, VipsImage *test, int x, int y, int serial, Rect *dout ); int im_draw_mask( VipsImage *image, diff --git a/libvips/inplace/flood.c b/libvips/inplace/flood.c index 395d8222..d62967bf 100644 --- a/libvips/inplace/flood.c +++ b/libvips/inplace/flood.c @@ -406,31 +406,31 @@ flood_new( IMAGE *image, IMAGE *test, int x, int y, PEL *ink, Rect *dout ) } /** - * im_flood: - * @im: image to fill + * im_draw_flood: + * @image: image to fill * @x: position to start fill * @y: position to start fill * @ink: colour to fill with * @dout: output the bounding box of the filled area * - * Flood-fill @im with @ink, starting at position @x, @y. The filled area is + * Flood-fill @image with @ink, starting at position @x, @y. The filled area is * bounded by pixels that are equal to the ink colour, in other words, it * searches for pixels enclosed by a line of @ink. * * The bounding box of the modified pixels is returned in @dout. @dout may be * NULL. * - * See also: im_flood_blob(), im_flood_other(), im_flood_blob_copy(). + * See also: im_draw_flood_blob(), im_draw_flood_other(). * * Returns: 0 on success, or -1 on error. */ int -im_flood( IMAGE *im, int x, int y, PEL *ink, Rect *dout ) +im_draw_flood( IMAGE *image, int x, int y, PEL *ink, Rect *dout ) { Flood *flood; - if( im_check_coding_known( "im_flood", im ) || - !(flood = flood_new( im, im, x, y, ink, dout )) ) + if( im_check_coding_known( "im_draw_flood", image ) || + !(flood = flood_new( image, image, x, y, ink, dout )) ) return( -1 ); /* Flood to != ink. @@ -446,37 +446,37 @@ im_flood( IMAGE *im, int x, int y, PEL *ink, Rect *dout ) } /** - * im_flood_blob: - * @im: image to fill + * im_draw_flood_blob: + * @image: image to fill * @x: position to start fill * @y: position to start fill * @ink: colour to fill with * @dout: output the bounding box of the filled area * - * Flood-fill @im with @ink, starting at position @x, @y. The filled area is + * Flood-fill @image with @ink, starting at position @x, @y. The filled area is * bounded by pixels that are equal to the start pixel, in other words, it * searches for a blob of same-coloured pixels. * * The bounding box of the modified pixels is returned in @dout. @dout may be * NULL. * - * See also: im_flood(), im_flood_other(), im_flood_blob_copy(). + * See also: im_draw_flood(), im_draw_flood_other(), im_draw_flood_blob(). * * Returns: 0 on success, or -1 on error. */ int -im_flood_blob( IMAGE *im, int x, int y, PEL *ink, Rect *dout ) +im_draw_flood_blob( IMAGE *image, int x, int y, PEL *ink, Rect *dout ) { Flood *flood; int j; - if( im_check_coding_known( "im_flood", im ) || - !(flood = flood_new( im, im, x, y, ink, dout )) ) + if( im_check_coding_known( "im_draw_flood_blob", image ) || + !(flood = flood_new( image, image, x, y, ink, dout )) ) return( -1 ); /* Edge is set by colour of start pixel. */ - memcpy( flood->edge, IM_IMAGE_ADDR( im, x, y ), flood->tsize ); + memcpy( flood->edge, IM_IMAGE_ADDR( image, x, y ), flood->tsize ); flood->equal = 1; /* If edge == ink, we'll never stop :-( or rather, there's nothing to @@ -496,7 +496,7 @@ im_flood_blob( IMAGE *im, int x, int y, PEL *ink, Rect *dout ) } /** - * im_flood_other: + * im_draw_flood_other: * @image: image to mark * @test: image to test * @x: position to start fill @@ -512,23 +512,24 @@ im_flood_blob( IMAGE *im, int x, int y, PEL *ink, Rect *dout ) * The bounding box of the modified pixels is returned in @dout. @dout may be * NULL. * - * See also: im_flood(), im_label_regions(), im_flood_blob_copy(). + * See also: im_draw_flood(), im_label_regions(), im_draw_flood_blob(). * * Returns: 0 on success, or -1 on error. */ int -im_flood_other( IMAGE *image, +im_draw_flood_other( IMAGE *image, IMAGE *test, int x, int y, int serial, Rect *dout ) { int *m; Flood *flood; if( im_incheck( test ) || - im_check_coding_known( "im_flood_other", test ) || - im_check_uncoded( "im_flood_other", image ) || - im_check_mono( "im_flood_other", image ) || - im_check_format( "im_flood_other", image, IM_BANDFMT_INT ) || - im_check_size_same( "im_flood_other", test, image ) ) + im_check_coding_known( "im_draw_flood_other", test ) || + im_check_uncoded( "im_draw_flood_other", image ) || + im_check_mono( "im_draw_flood_other", image ) || + im_check_format( "im_draw_flood_other", image, + IM_BANDFMT_INT ) || + im_check_size_same( "im_draw_flood_other", test, image ) ) return( -1 ); /* Have we done this point already? diff --git a/libvips/inplace/inplace_dispatch.c b/libvips/inplace/inplace_dispatch.c index 9d2511ce..2ad68e62 100644 --- a/libvips/inplace/inplace_dispatch.c +++ b/libvips/inplace/inplace_dispatch.c @@ -232,116 +232,117 @@ static im_function draw_mask_desc = { draw_mask_args /* Arg list */ }; -/* Args for im_flood_blob(). +/* Args for im_draw_flood_blob(). */ -static im_arg_desc flood_blob_args[] = { +static im_arg_desc draw_flood_blob_args[] = { IM_RW_IMAGE( "image" ), - IM_INPUT_INT( "start_x" ), - IM_INPUT_INT( "start_y" ), + IM_INPUT_INT( "x" ), + IM_INPUT_INT( "y" ), IM_INPUT_DOUBLEVEC( "ink" ) }; -/* Call im_flood_blob() via arg vector. +/* Call im_draw_flood_blob() via arg vector. */ static int -flood_blob_vec( im_object *argv ) +draw_flood_blob_vec( im_object *argv ) { IMAGE *image = argv[0]; - int start_x = *((int *) argv[1]); - int start_y = *((int *) argv[2]); + int x = *((int *) argv[1]); + int y = *((int *) argv[2]); im_doublevec_object *dv = (im_doublevec_object *) argv[3]; PEL *ink; - if( !(ink = im__vector_to_ink( "im_flood_blob", + if( !(ink = im__vector_to_ink( "im_draw_flood_blob", image, dv->n, dv->vec )) ) return( -1 ); - return( im_flood_blob( image, start_x, start_y, ink, NULL ) ); + return( im_draw_flood_blob( image, x, y, ink, NULL ) ); } -/* Description of im_flood_blob(). +/* Description of im_draw_flood_blob(). */ -static im_function flood_blob_desc = { - "im_flood_blob", /* Name */ - "flood with ink from start_x, start_y while pixel == start pixel", +static im_function draw_flood_blob_desc = { + "im_draw_flood_blob", /* Name */ + "flood with ink from x, y while pixel == start", 0, /* Flags */ - flood_blob_vec, /* Dispatch function */ - IM_NUMBER( flood_blob_args ),/* Size of arg list */ - flood_blob_args /* Arg list */ + draw_flood_blob_vec, /* Dispatch function */ + IM_NUMBER( draw_flood_blob_args ),/* Size of arg list */ + draw_flood_blob_args /* Arg list */ }; -/* Args for im_flood(). +/* Args for im_draw_flood(). */ -static im_arg_desc flood_args[] = { +static im_arg_desc draw_flood_args[] = { IM_RW_IMAGE( "image" ), - IM_INPUT_INT( "start_x" ), - IM_INPUT_INT( "start_y" ), + IM_INPUT_INT( "x" ), + IM_INPUT_INT( "y" ), IM_INPUT_DOUBLEVEC( "ink" ) }; -/* Call im_flood() via arg vector. +/* Call im_draw_flood() via arg vector. */ static int -flood_vec( im_object *argv ) +draw_flood_vec( im_object *argv ) { IMAGE *image = argv[0]; - int start_x = *((int *) argv[1]); - int start_y = *((int *) argv[2]); + int x = *((int *) argv[1]); + int y = *((int *) argv[2]); im_doublevec_object *dv = (im_doublevec_object *) argv[3]; PEL *ink; - if( !(ink = im__vector_to_ink( "im_flood", image, dv->n, dv->vec )) ) + if( !(ink = im__vector_to_ink( "im_draw_flood", + image, dv->n, dv->vec )) ) return( -1 ); - return( im_flood( image, start_x, start_y, ink, NULL ) ); + return( im_draw_flood( image, x, y, ink, NULL ) ); } -/* Description of im_flood(). +/* Description of im_draw_flood(). */ -static im_function flood_desc = { - "im_flood", /* Name */ - "flood with ink from start_x, start_y while pixel != ink", +static im_function draw_flood_desc = { + "im_draw_flood", /* Name */ + "flood with ink from x, y while pixel != ink", 0, /* Flags */ - flood_vec, /* Dispatch function */ - IM_NUMBER( flood_args ),/* Size of arg list */ - flood_args /* Arg list */ + draw_flood_vec, /* Dispatch function */ + IM_NUMBER( draw_flood_args ),/* Size of arg list */ + draw_flood_args /* Arg list */ }; -/* Args for im_flood_other(). +/* Args for im_draw_flood_other(). */ -static im_arg_desc flood_other_args[] = { +static im_arg_desc draw_flood_other_args[] = { IM_RW_IMAGE( "image" ), IM_INPUT_IMAGE( "test" ), - IM_INPUT_INT( "start_x" ), - IM_INPUT_INT( "start_y" ), + IM_INPUT_INT( "x" ), + IM_INPUT_INT( "y" ), IM_INPUT_INT( "serial" ) }; -/* Call im_flood_other() via arg vector. +/* Call im_draw_flood_other() via arg vector. */ static int -flood_other_vec( im_object *argv ) +draw_flood_other_vec( im_object *argv ) { IMAGE *image = argv[0]; IMAGE *test = argv[1]; - int start_x = *((int *) argv[2]); - int start_y = *((int *) argv[3]); + int x = *((int *) argv[2]); + int y = *((int *) argv[3]); int serial = *((int *) argv[4]); - return( im_flood_other( image, test, start_x, start_y, serial, NULL ) ); + return( im_draw_flood_other( image, test, x, y, serial, NULL ) ); } -/* Description of im_flood_other(). +/* Description of im_draw_flood_other(). */ -static im_function flood_other_desc = { - "im_flood_other", /* Name */ - "flood mark with serial from start_x, start_y while pixel == start pixel", +static im_function draw_flood_other_desc = { + "im_draw_flood_other", /* Name */ + "flood image with serial from x, y while pixel == start", 0, /* Flags */ - flood_other_vec, /* Dispatch function */ - IM_NUMBER( flood_other_args ),/* Size of arg list */ - flood_other_args /* Arg list */ + draw_flood_other_vec, /* Dispatch function */ + IM_NUMBER( draw_flood_other_args ),/* Size of arg list */ + draw_flood_other_args /* Arg list */ }; /* Args for im_draw_point. @@ -599,9 +600,9 @@ static im_function *inplace_list[] = { &draw_point_desc, &read_point_desc, &draw_smudge_desc, - &flood_desc, - &flood_blob_desc, - &flood_other_desc, + &draw_flood_desc, + &draw_flood_blob_desc, + &draw_flood_other_desc, &draw_image_desc, &draw_mask_desc, &lineset_desc