flood -> draw_flood

This commit is contained in:
John Cupitt 2010-10-01 10:47:48 +00:00
parent 3fbd002dc0
commit 4915fb0a83
6 changed files with 106 additions and 81 deletions

3
TODO
View File

@ -1,7 +1,5 @@
- check gtk-doc output - check gtk-doc output
- im_flood() -> im_draw_flood()? since it's inplace
- convsep / conv need to be able to do COMPLEX - convsep / conv need to be able to do COMPLEX
just double the bands just double the bands
@ -13,6 +11,7 @@
- can we make more use of im__draw_pel()? eg. im_draw_rect() etc. - can we make more use of im__draw_pel()? eg. im_draw_rect() etc.
- what's nip2's performance on wide lines like now?

View File

@ -695,3 +695,22 @@ im_smudge( VipsImage *image, int ix, int iy, Rect *r )
return( im_draw_smudge( image, return( im_draw_smudge( image,
r->left + ix, r->top + iy, r->width, r->height ) ); 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 ) );
}

View File

@ -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 im_flood_other_copy( IMAGE *test, IMAGE *mark, IMAGE *out,
int x, int y, int serial ); 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_fastline( IMAGE *im, int x1, int y1, int x2, int y2, PEL *pel );
int im_fastlineuser( IMAGE *im, int im_fastlineuser( IMAGE *im,
int x1, int y1, int x2, int y2, int x1, int y1, int x2, int y2,

View File

@ -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 im_lineset( VipsImage *in, VipsImage *out, VipsImage *mask, VipsImage *ink,
int n, int *x1v, int *y1v, int *x2v, int *y2v ); 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_draw_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_draw_flood_blob( VipsImage *image, int x, int y, PEL *ink, Rect *dout );
int im_flood_other( VipsImage *image, VipsImage *test, int im_draw_flood_other( VipsImage *image, VipsImage *test,
int x, int y, int serial, Rect *dout ); int x, int y, int serial, Rect *dout );
int im_draw_mask( VipsImage *image, int im_draw_mask( VipsImage *image,

View File

@ -406,31 +406,31 @@ flood_new( IMAGE *image, IMAGE *test, int x, int y, PEL *ink, Rect *dout )
} }
/** /**
* im_flood: * im_draw_flood:
* @im: image to fill * @image: image to fill
* @x: position to start fill * @x: position to start fill
* @y: position to start fill * @y: position to start fill
* @ink: colour to fill with * @ink: colour to fill with
* @dout: output the bounding box of the filled area * @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 * bounded by pixels that are equal to the ink colour, in other words, it
* searches for pixels enclosed by a line of @ink. * searches for pixels enclosed by a line of @ink.
* *
* The bounding box of the modified pixels is returned in @dout. @dout may be * The bounding box of the modified pixels is returned in @dout. @dout may be
* NULL. * 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. * Returns: 0 on success, or -1 on error.
*/ */
int 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; Flood *flood;
if( im_check_coding_known( "im_flood", im ) || if( im_check_coding_known( "im_draw_flood", image ) ||
!(flood = flood_new( im, im, x, y, ink, dout )) ) !(flood = flood_new( image, image, x, y, ink, dout )) )
return( -1 ); return( -1 );
/* Flood to != ink. /* Flood to != ink.
@ -446,37 +446,37 @@ im_flood( IMAGE *im, int x, int y, PEL *ink, Rect *dout )
} }
/** /**
* im_flood_blob: * im_draw_flood_blob:
* @im: image to fill * @image: image to fill
* @x: position to start fill * @x: position to start fill
* @y: position to start fill * @y: position to start fill
* @ink: colour to fill with * @ink: colour to fill with
* @dout: output the bounding box of the filled area * @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 * bounded by pixels that are equal to the start pixel, in other words, it
* searches for a blob of same-coloured pixels. * searches for a blob of same-coloured pixels.
* *
* The bounding box of the modified pixels is returned in @dout. @dout may be * The bounding box of the modified pixels is returned in @dout. @dout may be
* NULL. * 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. * Returns: 0 on success, or -1 on error.
*/ */
int 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; Flood *flood;
int j; int j;
if( im_check_coding_known( "im_flood", im ) || if( im_check_coding_known( "im_draw_flood_blob", image ) ||
!(flood = flood_new( im, im, x, y, ink, dout )) ) !(flood = flood_new( image, image, x, y, ink, dout )) )
return( -1 ); return( -1 );
/* Edge is set by colour of start pixel. /* 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; flood->equal = 1;
/* If edge == ink, we'll never stop :-( or rather, there's nothing to /* 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 * @image: image to mark
* @test: image to test * @test: image to test
* @x: position to start fill * @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 * The bounding box of the modified pixels is returned in @dout. @dout may be
* NULL. * 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. * Returns: 0 on success, or -1 on error.
*/ */
int int
im_flood_other( IMAGE *image, im_draw_flood_other( IMAGE *image,
IMAGE *test, int x, int y, int serial, Rect *dout ) IMAGE *test, int x, int y, int serial, Rect *dout )
{ {
int *m; int *m;
Flood *flood; Flood *flood;
if( im_incheck( test ) || if( im_incheck( test ) ||
im_check_coding_known( "im_flood_other", test ) || im_check_coding_known( "im_draw_flood_other", test ) ||
im_check_uncoded( "im_flood_other", image ) || im_check_uncoded( "im_draw_flood_other", image ) ||
im_check_mono( "im_flood_other", image ) || im_check_mono( "im_draw_flood_other", image ) ||
im_check_format( "im_flood_other", image, IM_BANDFMT_INT ) || im_check_format( "im_draw_flood_other", image,
im_check_size_same( "im_flood_other", test, image ) ) IM_BANDFMT_INT ) ||
im_check_size_same( "im_draw_flood_other", test, image ) )
return( -1 ); return( -1 );
/* Have we done this point already? /* Have we done this point already?

View File

@ -232,116 +232,117 @@ static im_function draw_mask_desc = {
draw_mask_args /* Arg list */ 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_RW_IMAGE( "image" ),
IM_INPUT_INT( "start_x" ), IM_INPUT_INT( "x" ),
IM_INPUT_INT( "start_y" ), IM_INPUT_INT( "y" ),
IM_INPUT_DOUBLEVEC( "ink" ) IM_INPUT_DOUBLEVEC( "ink" )
}; };
/* Call im_flood_blob() via arg vector. /* Call im_draw_flood_blob() via arg vector.
*/ */
static int static int
flood_blob_vec( im_object *argv ) draw_flood_blob_vec( im_object *argv )
{ {
IMAGE *image = argv[0]; IMAGE *image = argv[0];
int start_x = *((int *) argv[1]); int x = *((int *) argv[1]);
int start_y = *((int *) argv[2]); int y = *((int *) argv[2]);
im_doublevec_object *dv = (im_doublevec_object *) argv[3]; im_doublevec_object *dv = (im_doublevec_object *) argv[3];
PEL *ink; 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 )) ) image, dv->n, dv->vec )) )
return( -1 ); 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 = { static im_function draw_flood_blob_desc = {
"im_flood_blob", /* Name */ "im_draw_flood_blob", /* Name */
"flood with ink from start_x, start_y while pixel == start pixel", "flood with ink from x, y while pixel == start",
0, /* Flags */ 0, /* Flags */
flood_blob_vec, /* Dispatch function */ draw_flood_blob_vec, /* Dispatch function */
IM_NUMBER( flood_blob_args ),/* Size of arg list */ IM_NUMBER( draw_flood_blob_args ),/* Size of arg list */
flood_blob_args /* 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_RW_IMAGE( "image" ),
IM_INPUT_INT( "start_x" ), IM_INPUT_INT( "x" ),
IM_INPUT_INT( "start_y" ), IM_INPUT_INT( "y" ),
IM_INPUT_DOUBLEVEC( "ink" ) IM_INPUT_DOUBLEVEC( "ink" )
}; };
/* Call im_flood() via arg vector. /* Call im_draw_flood() via arg vector.
*/ */
static int static int
flood_vec( im_object *argv ) draw_flood_vec( im_object *argv )
{ {
IMAGE *image = argv[0]; IMAGE *image = argv[0];
int start_x = *((int *) argv[1]); int x = *((int *) argv[1]);
int start_y = *((int *) argv[2]); int y = *((int *) argv[2]);
im_doublevec_object *dv = (im_doublevec_object *) argv[3]; im_doublevec_object *dv = (im_doublevec_object *) argv[3];
PEL *ink; 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( -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 = { static im_function draw_flood_desc = {
"im_flood", /* Name */ "im_draw_flood", /* Name */
"flood with ink from start_x, start_y while pixel != ink", "flood with ink from x, y while pixel != ink",
0, /* Flags */ 0, /* Flags */
flood_vec, /* Dispatch function */ draw_flood_vec, /* Dispatch function */
IM_NUMBER( flood_args ),/* Size of arg list */ IM_NUMBER( draw_flood_args ),/* Size of arg list */
flood_args /* 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_RW_IMAGE( "image" ),
IM_INPUT_IMAGE( "test" ), IM_INPUT_IMAGE( "test" ),
IM_INPUT_INT( "start_x" ), IM_INPUT_INT( "x" ),
IM_INPUT_INT( "start_y" ), IM_INPUT_INT( "y" ),
IM_INPUT_INT( "serial" ) IM_INPUT_INT( "serial" )
}; };
/* Call im_flood_other() via arg vector. /* Call im_draw_flood_other() via arg vector.
*/ */
static int static int
flood_other_vec( im_object *argv ) draw_flood_other_vec( im_object *argv )
{ {
IMAGE *image = argv[0]; IMAGE *image = argv[0];
IMAGE *test = argv[1]; IMAGE *test = argv[1];
int start_x = *((int *) argv[2]); int x = *((int *) argv[2]);
int start_y = *((int *) argv[3]); int y = *((int *) argv[3]);
int serial = *((int *) argv[4]); 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 = { static im_function draw_flood_other_desc = {
"im_flood_other", /* Name */ "im_draw_flood_other", /* Name */
"flood mark with serial from start_x, start_y while pixel == start pixel", "flood image with serial from x, y while pixel == start",
0, /* Flags */ 0, /* Flags */
flood_other_vec, /* Dispatch function */ draw_flood_other_vec, /* Dispatch function */
IM_NUMBER( flood_other_args ),/* Size of arg list */ IM_NUMBER( draw_flood_other_args ),/* Size of arg list */
flood_other_args /* Arg list */ draw_flood_other_args /* Arg list */
}; };
/* Args for im_draw_point. /* Args for im_draw_point.
@ -599,9 +600,9 @@ static im_function *inplace_list[] = {
&draw_point_desc, &draw_point_desc,
&read_point_desc, &read_point_desc,
&draw_smudge_desc, &draw_smudge_desc,
&flood_desc, &draw_flood_desc,
&flood_blob_desc, &draw_flood_blob_desc,
&flood_other_desc, &draw_flood_other_desc,
&draw_image_desc, &draw_image_desc,
&draw_mask_desc, &draw_mask_desc,
&lineset_desc &lineset_desc