From de026e07501453a67de36d3e4e9823b20403ea15 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 22 Sep 2010 12:51:52 +0000 Subject: [PATCH] deprecate _copy() inplace ops --- ChangeLog | 2 + TODO | 2 - libvips/deprecated/deprecated_dispatch.c | 131 +++++++++++++++++ libvips/deprecated/rename.c | 48 ++++++ libvips/include/vips/almostdeprecated.h | 5 + libvips/include/vips/inplace.h | 7 - libvips/include/vips/internal.h | 1 + libvips/inplace/flood.c | 48 ------ libvips/inplace/im_circle.c | 19 --- libvips/inplace/inplace_dispatch.c | 178 ++++++++--------------- 10 files changed, 249 insertions(+), 192 deletions(-) diff --git a/ChangeLog b/ChangeLog index bb76e04e..7b29c2f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,8 @@ - add IM_TYPE_RW flag for im__rw_image, helps nip2 auto-wrap inplace ops - im_insertplace() casts and bandalikes - copy iconv.m4 and friends in bootstrap, thanks Mike +- moved the stupid _copy() versions of the inplace ops to deprecated, since + nip2 can call inplace ops directly now 12/5/10 started 7.22.2 - the conditional image of ifthenelse can be any format, a (!=0) is added if diff --git a/TODO b/TODO index 69d89f78..0c6b108c 100644 --- a/TODO +++ b/TODO @@ -4,8 +4,6 @@ - use im__inplace_base() in more places -- nip2 should be able to call RW image ops by copying them, see - im_draw_circle_copy() diff --git a/libvips/deprecated/deprecated_dispatch.c b/libvips/deprecated/deprecated_dispatch.c index 0a66305f..315c5e0d 100644 --- a/libvips/deprecated/deprecated_dispatch.c +++ b/libvips/deprecated/deprecated_dispatch.c @@ -1251,9 +1251,140 @@ static im_function circle_desc = { circle_args /* Arg list */ }; +/* Args for im_flood_blob_copy(). + */ +static im_arg_desc flood_blob_copy_args[] = { + IM_INPUT_IMAGE( "in" ), + IM_OUTPUT_IMAGE( "out" ), + IM_INPUT_INT( "start_x" ), + IM_INPUT_INT( "start_y" ), + IM_INPUT_DOUBLEVEC( "ink" ) +}; + +/* Call im_flood_blob_copy() via arg vector. + */ +static int +flood_blob_copy_vec( im_object *argv ) +{ + IMAGE *in = argv[0]; + IMAGE *out = argv[1]; + int start_x = *((int *) argv[2]); + int start_y = *((int *) argv[3]); + im_doublevec_object *dv = (im_doublevec_object *) argv[4]; + + PEL *ink; + + if( dv->n != in->Bands ) { + im_error( "im_flood_blob_copy", + "%s", _( "bad vector length" ) ); + return( -1 ); + } + if( !(ink = im__vector_to_ink( in, dv->vec )) ) + return( -1 ); + + return( im_flood_blob_copy( in, out, start_x, start_y, ink ) ); +} + +/* Description of im_flood_blob_copy(). + */ +static im_function flood_blob_copy_desc = { + "im_flood_blob_copy", /* Name */ + "flood with ink from start_x, start_y while pixel == start pixel", + 0, /* Flags */ + flood_blob_copy_vec, /* Dispatch function */ + IM_NUMBER( flood_blob_copy_args ),/* Size of arg list */ + flood_blob_copy_args /* Arg list */ +}; + +/* Args for im_flood_copy(). + */ +static im_arg_desc flood_copy_args[] = { + IM_INPUT_IMAGE( "in" ), + IM_OUTPUT_IMAGE( "out" ), + IM_INPUT_INT( "start_x" ), + IM_INPUT_INT( "start_y" ), + IM_INPUT_DOUBLEVEC( "ink" ) +}; + +/* Call im_flood_copy() via arg vector. + */ +static int +flood_copy_vec( im_object *argv ) +{ + IMAGE *in = argv[0]; + IMAGE *out = argv[1]; + int start_x = *((int *) argv[2]); + int start_y = *((int *) argv[3]); + im_doublevec_object *dv = (im_doublevec_object *) argv[4]; + + PEL *ink; + + if( dv->n != in->Bands ) { + im_error( "im_flood_copy", + "%s", _( "bad vector length" ) ); + return( -1 ); + } + if( !(ink = im__vector_to_ink( in, dv->vec )) ) + return( -1 ); + + return( im_flood_copy( in, out, start_x, start_y, ink ) ); +} + +/* Description of im_flood_copy(). + */ +static im_function flood_copy_desc = { + "im_flood_copy", /* Name */ + "flood with ink from start_x, start_y while pixel == start pixel", + 0, /* Flags */ + flood_copy_vec, /* Dispatch function */ + IM_NUMBER( flood_copy_args ),/* Size of arg list */ + flood_copy_args /* Arg list */ +}; + +/* Args for im_flood_other_copy(). + */ +static im_arg_desc flood_other_copy_args[] = { + IM_INPUT_IMAGE( "test" ), + IM_INPUT_IMAGE( "mark" ), + IM_OUTPUT_IMAGE( "out" ), + IM_INPUT_INT( "start_x" ), + IM_INPUT_INT( "start_y" ), + IM_INPUT_INT( "serial" ) +}; + +/* Call im_flood_other_copy() via arg vector. + */ +static int +flood_other_copy_vec( im_object *argv ) +{ + IMAGE *test = argv[0]; + IMAGE *mark = argv[1]; + IMAGE *out = argv[2]; + int start_x = *((int *) argv[3]); + int start_y = *((int *) argv[4]); + int serial = *((int *) argv[5]); + + return( im_flood_other_copy( test, mark, out, + start_x, start_y, serial ) ); +} + +/* Description of im_flood_other_copy(). + */ +static im_function flood_other_copy_desc = { + "im_flood_other_copy", /* Name */ + "flood mark with serial from start_x, start_y while pixel == start pixel", + 0, /* Flags */ + flood_other_copy_vec, /* Dispatch function */ + IM_NUMBER( flood_other_copy_args ),/* Size of arg list */ + flood_other_copy_args /* Arg list */ +}; + /* Package up all these functions. */ static im_function *deprecated_list[] = { + &flood_copy_desc, + &flood_blob_copy_desc, + &flood_other_copy_desc, &clip_desc, &c2ps_desc, &resize_linear_desc, diff --git a/libvips/deprecated/rename.c b/libvips/deprecated/rename.c index 205c0675..db0407b9 100644 --- a/libvips/deprecated/rename.c +++ b/libvips/deprecated/rename.c @@ -458,3 +458,51 @@ im_circle( IMAGE *im, int cx, int cy, int radius, int intensity ) return( im_draw_circle( im, cx, cy, radius, FALSE, ink ) ); } + +/* A flood blob we can call from nip. Grr! Should be a way to wrap these + * automatically. Maybe nip could do it if it sees a RW image argument? + */ + +int +im_flood_copy( IMAGE *in, IMAGE *out, int x, int y, PEL *ink ) +{ + IMAGE *t; + + if( !(t = im_open_local( out, "im_flood_blob_copy", "t" )) || + im_copy( in, t ) || + im_flood( t, x, y, ink, NULL ) || + im_copy( t, out ) ) + return( -1 ); + + return( 0 ); +} + +int +im_flood_blob_copy( IMAGE *in, IMAGE *out, int x, int y, PEL *ink ) +{ + IMAGE *t; + + if( !(t = im_open_local( out, "im_flood_blob_copy", "t" )) || + im_copy( in, t ) || + im_flood_blob( t, x, y, ink, NULL ) || + im_copy( t, out ) ) + return( -1 ); + + return( 0 ); +} + +int +im_flood_other_copy( IMAGE *test, IMAGE *mark, IMAGE *out, + int x, int y, int serial ) +{ + IMAGE *t; + + if( !(t = im_open_local( out, "im_flood_other_copy", "t" )) || + im_copy( mark, t ) || + im_flood_other( test, t, x, y, serial, NULL ) || + im_copy( t, out ) ) + return( -1 ); + + return( 0 ); +} + diff --git a/libvips/include/vips/almostdeprecated.h b/libvips/include/vips/almostdeprecated.h index 1b522549..751f81d2 100644 --- a/libvips/include/vips/almostdeprecated.h +++ b/libvips/include/vips/almostdeprecated.h @@ -232,6 +232,11 @@ int im_circle( IMAGE *im, int cx, int cy, int radius, int intensity ); int im_line( IMAGE *, int, int, int, int, int ); int im_segment( IMAGE *test, IMAGE *mask, int *segments ); +int im_flood_copy( IMAGE *in, IMAGE *out, int x, int y, PEL *ink ); +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 ); + #ifdef __cplusplus } #endif /*__cplusplus*/ diff --git a/libvips/include/vips/inplace.h b/libvips/include/vips/inplace.h index a156ef32..5d617d3c 100644 --- a/libvips/include/vips/inplace.h +++ b/libvips/include/vips/inplace.h @@ -43,8 +43,6 @@ int im_smudge( IMAGE *im, int ix, int iy, Rect *r ); int im_paintrect( IMAGE *im, Rect *r, PEL *ink ); int im_draw_circle( IMAGE *im, int cx, int cy, int radius, gboolean fill, PEL *ink ); -int im_draw_circle_copy( IMAGE *in, IMAGE *out, - int cx, int cy, int radius, gboolean fill, PEL *ink ); int im_insertplace( IMAGE *main, IMAGE *sub, int x, int y ); int im_fastline( IMAGE *im, int x1, int y1, int x2, int y2, PEL *pel ); int im_fastlineuser( IMAGE *im, @@ -57,11 +55,6 @@ 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_flood_copy( IMAGE *in, IMAGE *out, int x, int y, PEL *ink ); -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_lineset( IMAGE *in, IMAGE *out, IMAGE *mask, IMAGE *ink, int n, int *x1v, int *y1v, int *x2v, int *y2v ); diff --git a/libvips/include/vips/internal.h b/libvips/include/vips/internal.h index 160ff04d..893de0d8 100644 --- a/libvips/include/vips/internal.h +++ b/libvips/include/vips/internal.h @@ -277,6 +277,7 @@ int im__fmaskcir( IMAGE *out, VipsMaskType flag, va_list ap ); /* inplace */ +PEL *im__vector_to_ink( IMAGE *im, double *vec ); IMAGE *im__inplace_base( const char *domain, IMAGE *main, IMAGE *sub, IMAGE *out ); diff --git a/libvips/inplace/flood.c b/libvips/inplace/flood.c index 24dc93ed..9ac6ca71 100644 --- a/libvips/inplace/flood.c +++ b/libvips/inplace/flood.c @@ -593,51 +593,3 @@ im_flood_other( IMAGE *test, IMAGE *mark, int x, int y, int serial, Rect *dout ) return( 0 ); } - -/* A flood blob we can call from nip. Grr! Should be a way to wrap these - * automatically. Maybe nip could do it if it sees a RW image argument? - */ - -int -im_flood_copy( IMAGE *in, IMAGE *out, int x, int y, PEL *ink ) -{ - IMAGE *t; - - if( !(t = im_open_local( out, "im_flood_blob_copy", "t" )) || - im_copy( in, t ) || - im_flood( t, x, y, ink, NULL ) || - im_copy( t, out ) ) - return( -1 ); - - return( 0 ); -} - -int -im_flood_blob_copy( IMAGE *in, IMAGE *out, int x, int y, PEL *ink ) -{ - IMAGE *t; - - if( !(t = im_open_local( out, "im_flood_blob_copy", "t" )) || - im_copy( in, t ) || - im_flood_blob( t, x, y, ink, NULL ) || - im_copy( t, out ) ) - return( -1 ); - - return( 0 ); -} - -int -im_flood_other_copy( IMAGE *test, IMAGE *mark, IMAGE *out, - int x, int y, int serial ) -{ - IMAGE *t; - - if( !(t = im_open_local( out, "im_flood_other_copy", "t" )) || - im_copy( mark, t ) || - im_flood_other( test, t, x, y, serial, NULL ) || - im_copy( t, out ) ) - return( -1 ); - - return( 0 ); -} - diff --git a/libvips/inplace/im_circle.c b/libvips/inplace/im_circle.c index 075f5c48..0132dd1f 100644 --- a/libvips/inplace/im_circle.c +++ b/libvips/inplace/im_circle.c @@ -277,22 +277,3 @@ im_draw_circle( IMAGE *im, int cx, int cy, int radius, gboolean fill, PEL *ink ) return( 0 ); } - -/* One we can call from nip. Grr! Should be a way to wrap these - * automatically. Maybe nip could do it if it sees a RW image argument? - */ - -int -im_draw_circle_copy( IMAGE *in, IMAGE *out, - int cx, int cy, int radius, gboolean fill, PEL *ink ) -{ - IMAGE *t; - - if( !(t = im_open_local( out, "im_flood_blob_copy", "t" )) || - im_copy( in, t ) || - im_draw_circle( t, cx, cy, radius, fill, ink ) || - im_copy( t, out ) ) - return( -1 ); - - return( 0 ); -} diff --git a/libvips/inplace/inplace_dispatch.c b/libvips/inplace/inplace_dispatch.c index 31f9e73e..d1e4f568 100644 --- a/libvips/inplace/inplace_dispatch.c +++ b/libvips/inplace/inplace_dispatch.c @@ -131,8 +131,8 @@ static im_function lineset_desc = { /* Calculate a pixel for an image from a vec of double. Valid while im is * valid. */ -static PEL * -vector_to_ink( IMAGE *im, double *vec ) +PEL * +im__vector_to_ink( IMAGE *im, double *vec ) { const int n = im->Bands; @@ -154,132 +154,123 @@ vector_to_ink( IMAGE *im, double *vec ) return( (PEL *) t[2]->data ); } -/* Args for im_flood_blob_copy(). +/* Args for im_flood_blob(). */ -static im_arg_desc flood_blob_copy_args[] = { - IM_INPUT_IMAGE( "in" ), - IM_OUTPUT_IMAGE( "out" ), +static im_arg_desc flood_blob_args[] = { + IM_RW_IMAGE( "image" ), IM_INPUT_INT( "start_x" ), IM_INPUT_INT( "start_y" ), IM_INPUT_DOUBLEVEC( "ink" ) }; -/* Call im_flood_blob_copy() via arg vector. +/* Call im_flood_blob() via arg vector. */ static int -flood_blob_copy_vec( im_object *argv ) +flood_blob_vec( im_object *argv ) { - IMAGE *in = argv[0]; - IMAGE *out = argv[1]; - int start_x = *((int *) argv[2]); - int start_y = *((int *) argv[3]); - im_doublevec_object *dv = (im_doublevec_object *) argv[4]; + IMAGE *image = argv[0]; + int start_x = *((int *) argv[1]); + int start_y = *((int *) argv[2]); + im_doublevec_object *dv = (im_doublevec_object *) argv[3]; PEL *ink; - if( dv->n != in->Bands ) { - im_error( "im_flood_blob_copy", - "%s", _( "bad vector length" ) ); + if( dv->n != image->Bands ) { + im_error( "im_flood_blob", "%s", _( "bad vector length" ) ); return( -1 ); } - if( !(ink = vector_to_ink( in, dv->vec )) ) + if( !(ink = im__vector_to_ink( image, dv->vec )) ) return( -1 ); - return( im_flood_blob_copy( in, out, start_x, start_y, ink ) ); + return( im_flood_blob( image, start_x, start_y, ink, NULL ) ); } -/* Description of im_flood_blob_copy(). +/* Description of im_flood_blob(). */ -static im_function flood_blob_copy_desc = { - "im_flood_blob_copy", /* Name */ +static im_function flood_blob_desc = { + "im_flood_blob", /* Name */ "flood with ink from start_x, start_y while pixel == start pixel", 0, /* Flags */ - flood_blob_copy_vec, /* Dispatch function */ - IM_NUMBER( flood_blob_copy_args ),/* Size of arg list */ - flood_blob_copy_args /* Arg list */ + flood_blob_vec, /* Dispatch function */ + IM_NUMBER( flood_blob_args ),/* Size of arg list */ + flood_blob_args /* Arg list */ }; -/* Args for im_flood_copy(). +/* Args for im_flood(). */ -static im_arg_desc flood_copy_args[] = { - IM_INPUT_IMAGE( "in" ), - IM_OUTPUT_IMAGE( "out" ), +static im_arg_desc flood_args[] = { + IM_RW_IMAGE( "image" ), IM_INPUT_INT( "start_x" ), IM_INPUT_INT( "start_y" ), IM_INPUT_DOUBLEVEC( "ink" ) }; -/* Call im_flood_copy() via arg vector. +/* Call im_flood() via arg vector. */ static int -flood_copy_vec( im_object *argv ) +flood_vec( im_object *argv ) { - IMAGE *in = argv[0]; - IMAGE *out = argv[1]; - int start_x = *((int *) argv[2]); - int start_y = *((int *) argv[3]); - im_doublevec_object *dv = (im_doublevec_object *) argv[4]; + IMAGE *image = argv[0]; + int start_x = *((int *) argv[1]); + int start_y = *((int *) argv[2]); + im_doublevec_object *dv = (im_doublevec_object *) argv[3]; PEL *ink; - if( dv->n != in->Bands ) { - im_error( "im_flood_copy", - "%s", _( "bad vector length" ) ); + if( dv->n != image->Bands ) { + im_error( "im_flood", "%s", _( "bad vector length" ) ); return( -1 ); } - if( !(ink = vector_to_ink( in, dv->vec )) ) + if( !(ink = im__vector_to_ink( image, dv->vec )) ) return( -1 ); - return( im_flood_copy( in, out, start_x, start_y, ink ) ); + return( im_flood( image, start_x, start_y, ink, NULL ) ); } -/* Description of im_flood_copy(). +/* Description of im_flood(). */ -static im_function flood_copy_desc = { - "im_flood_copy", /* Name */ - "flood with ink from start_x, start_y while pixel == start pixel", +static im_function flood_desc = { + "im_flood", /* Name */ + "flood with ink from start_x, start_y while pixel != ink", 0, /* Flags */ - flood_copy_vec, /* Dispatch function */ - IM_NUMBER( flood_copy_args ),/* Size of arg list */ - flood_copy_args /* Arg list */ + flood_vec, /* Dispatch function */ + IM_NUMBER( flood_args ),/* Size of arg list */ + flood_args /* Arg list */ }; -/* Args for im_flood_other_copy(). +/* Args for im_flood_other(). */ -static im_arg_desc flood_other_copy_args[] = { +static im_arg_desc flood_other_args[] = { IM_INPUT_IMAGE( "test" ), - IM_INPUT_IMAGE( "mark" ), - IM_OUTPUT_IMAGE( "out" ), + IM_RW_IMAGE( "mark" ), IM_INPUT_INT( "start_x" ), IM_INPUT_INT( "start_y" ), IM_INPUT_INT( "serial" ) }; -/* Call im_flood_other_copy() via arg vector. +/* Call im_flood_other() via arg vector. */ static int -flood_other_copy_vec( im_object *argv ) +flood_other_vec( im_object *argv ) { IMAGE *test = argv[0]; IMAGE *mark = argv[1]; - IMAGE *out = argv[2]; - int start_x = *((int *) argv[3]); - int start_y = *((int *) argv[4]); - int serial = *((int *) argv[5]); + int start_x = *((int *) argv[2]); + int start_y = *((int *) argv[3]); + int serial = *((int *) argv[4]); - return( im_flood_other_copy( test, mark, out, - start_x, start_y, serial ) ); + return( im_flood_other( test, mark, start_x, start_y, serial, NULL ) ); } -/* Description of im_flood_other_copy(). +/* Description of im_flood_other(). */ -static im_function flood_other_copy_desc = { - "im_flood_other_copy", /* Name */ +static im_function flood_other_desc = { + "im_flood_other", /* Name */ "flood mark with serial from start_x, start_y while pixel == start pixel", 0, /* Flags */ - flood_other_copy_vec, /* Dispatch function */ - IM_NUMBER( flood_other_copy_args ),/* Size of arg list */ - flood_other_copy_args /* Arg list */ + flood_other_vec, /* Dispatch function */ + IM_NUMBER( flood_other_args ),/* Size of arg list */ + flood_other_args /* Arg list */ }; /* Args for im_draw_circle. @@ -298,7 +289,7 @@ static im_arg_desc draw_circle_args[] = { static int draw_circle_vec( im_object *argv ) { - IMAGE *in = argv[0]; + IMAGE *image = argv[0]; int cx = *((int *) argv[1]); int cy = *((int *) argv[2]); int radius = *((int *) argv[3]); @@ -307,10 +298,10 @@ draw_circle_vec( im_object *argv ) PEL *ink; - if( !(ink = vector_to_ink( in, dv->vec )) ) + if( !(ink = im__vector_to_ink( image, dv->vec )) ) return( -1 ); - return( im_draw_circle( in, cx, cy, radius, fill, ink ) ); + return( im_draw_circle( image, cx, cy, radius, fill, ink ) ); } /* Description of im_draw_circle. @@ -324,50 +315,6 @@ static im_function draw_circle_desc = { draw_circle_args /* Arg list */ }; -/* Args for im_draw_circle_copy. - */ -static im_arg_desc draw_circle_copy_args[] = { - IM_INPUT_IMAGE( "in" ), - IM_OUTPUT_IMAGE( "out" ), - IM_INPUT_INT( "cx" ), - IM_INPUT_INT( "cy" ), - IM_INPUT_INT( "radius" ), - IM_INPUT_INT( "fill" ), - IM_INPUT_DOUBLEVEC( "ink" ) -}; - -/* Call im_draw_circle_copy via arg vector. - */ -static int -draw_circle_copy_vec( im_object *argv ) -{ - IMAGE *in = argv[0]; - IMAGE *out = argv[1]; - int cx = *((int *) argv[2]); - int cy = *((int *) argv[3]); - int radius = *((int *) argv[4]); - int fill = *((int *) argv[5]); - im_doublevec_object *dv = (im_doublevec_object *) argv[6]; - - PEL *ink; - - if( !(ink = vector_to_ink( in, dv->vec )) ) - return( -1 ); - - return( im_draw_circle_copy( in, out, cx, cy, radius, fill, ink ) ); -} - -/* Description of im_draw_circle_copy. - */ -static im_function draw_circle_copy_desc = { - "im_draw_circle_copy", /* Name */ - "draw circle on image", - 0, /* Flags */ - draw_circle_copy_vec, /* Dispatch function */ - IM_NUMBER( draw_circle_copy_args ), /* Size of arg list */ - draw_circle_copy_args /* Arg list */ -}; - /* To do: * these all need some kind of pel type * @@ -384,10 +331,9 @@ static im_function draw_circle_copy_desc = { */ static im_function *inplace_list[] = { &draw_circle_desc, - &draw_circle_copy_desc, - &flood_copy_desc, - &flood_blob_copy_desc, - &flood_other_copy_desc, + &flood_desc, + &flood_blob_desc, + &flood_other_desc, &insertplace_desc, &lineset_desc };