diff --git a/ChangeLog b/ChangeLog index a488e54b..6e72d235 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,7 +4,7 @@ - colourspace has a source_space option - operations can be tagged as "deprecated" - redo im_draw_circle(), im_draw_flood(), im_draw_line(), im_draw_mask(), - im_draw_image(), im_draw_rect() as classes + im_draw_image(), im_draw_rect(), im_draw_point(), im_read_point() as classes - better rounding in vips_flatten() - VipsStatistic operations are sequential diff --git a/TODO b/TODO index aa6ce7a0..fde8741d 100644 --- a/TODO +++ b/TODO @@ -1,11 +1,45 @@ -- get/set point next +- try -- rename vips_paintrect as vips_draw_rect() - vips_circle() as vips_draw_circle() - etc. + $ vips getpoint + usage: + getpoint in out-array x y + read a point from an image + where: + in - Input image, input VipsImage + out-array - Array of output values, output VipsArrayDouble + x - Getpoint to read from, input gint + y - Getpoint to read from, input gint + + $ vips max + usage: + max in out + find image maximum + where: + in - Input image, input VipsImage + out - Output value, output gdouble + optional arguments: + x - Horizontal position of maximum, output gint + y - Vertical position of maximum, output gint + size - Number of maximum values to find, input gint + out-array - Array of output values, output VipsArrayDouble + x-array - Array of horizontal positions, output VipsArrayInt + y-array - Array of vertical positions, output VipsArrayInt + + don't list out-array or out as args in the usage line, since they don't need + an arg ... these args should be in a separet section I guess? + + put description first + +- try: + + $ vips max babe.v --x-array --size 0 + Segmentation fault (core dumped) + + + + +- swap VipsArea ink for VipsArrayDouble? - best to have them obviously in the same namespace, and draw is clearer than - paint diff --git a/libvips/arithmetic/Makefile.am b/libvips/arithmetic/Makefile.am index 52222136..f7cfc96d 100644 --- a/libvips/arithmetic/Makefile.am +++ b/libvips/arithmetic/Makefile.am @@ -6,6 +6,7 @@ libarithmetic_la_SOURCES = \ deviate.c \ divide.c \ measure.c \ + getpoint.c \ multiply.c \ remainder.c \ sign.c \ diff --git a/libvips/arithmetic/arithmetic.c b/libvips/arithmetic/arithmetic.c index e273cea0..59d7b7f4 100644 --- a/libvips/arithmetic/arithmetic.c +++ b/libvips/arithmetic/arithmetic.c @@ -709,6 +709,7 @@ vips_arithmetic_operation_init( void ) extern GType vips_project_get_type( void ); extern GType vips_profile_get_type( void ); extern GType vips_measure_get_type( void ); + extern GType vips_getpoint_get_type( void ); extern GType vips_round_get_type( void ); extern GType vips_relational_get_type( void ); extern GType vips_relational_const_get_type( void ); @@ -743,6 +744,7 @@ vips_arithmetic_operation_init( void ) vips_project_get_type(); vips_profile_get_type(); vips_measure_get_type(); + vips_getpoint_get_type(); vips_round_get_type(); vips_relational_get_type(); vips_relational_const_get_type(); diff --git a/libvips/arithmetic/getpoint.c b/libvips/arithmetic/getpoint.c new file mode 100644 index 00000000..aad161cc --- /dev/null +++ b/libvips/arithmetic/getpoint.c @@ -0,0 +1,214 @@ +/* read a single getpoint + * + * Copyright: J. Cupitt + * Written: 15/06/1992 + * 22/7/93 JC + * - im_incheck() added + * 16/8/94 JC + * - im_incheck() changed to im_makerw() + * 5/12/06 + * - im_invalidate() after paint + * 6/3/10 + * - don't im_invalidate() after paint, this now needs to be at a higher + * level + * 29/9/10 + * - gtk-doc + * - use Draw base class + * - read_getpoint partial-ised + * 10/2/14 + * - redo as a class + */ + +/* + + This file is part of VIPS. + + VIPS is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA + + */ + +/* + + These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk + + */ + +/* +#define VIPS_DEBUG + */ + +#ifdef HAVE_CONFIG_H +#include +#endif /*HAVE_CONFIG_H*/ +#include + +#include +#include +#include + +#include +#include + +#include "statistic.h" + +typedef struct _VipsGetpoint { + VipsOperation parent_instance; + + VipsImage *in; + int x; + int y; + VipsArrayDouble *out_array; + +} VipsGetpoint; + +typedef VipsOperationClass VipsGetpointClass; + +G_DEFINE_TYPE( VipsGetpoint, vips_getpoint, VIPS_TYPE_OPERATION ); + +static int +vips_getpoint_build( VipsObject *object ) +{ + VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object ); + VipsGetpoint *getpoint = (VipsGetpoint *) object; + + VipsRect area; + VipsRegion *region; + double *vector; + int n; + VipsArrayDouble *out_array; + + if( VIPS_OBJECT_CLASS( vips_getpoint_parent_class )->build( object ) ) + return( -1 ); + + if( vips_check_coding_known( class->nickname, getpoint->in ) || + !(region = vips_region_new( getpoint->in )) ) + return( -1 ); + vips_object_local( object, region ); + + area.left = getpoint->x; + area.top = getpoint->y; + area.width = 1; + area.height = 1; + if( vips_region_prepare( region, &area ) ) + return( -1 ); + if( !(vector = vips__ink_to_vector( class->nickname, getpoint->in, + VIPS_REGION_ADDR( region, getpoint->x, getpoint->y ), &n )) ) + return( -1 ); + + out_array = vips_array_double_new( vector, n ); + g_object_set( object, + "out_array", out_array, + NULL ); + vips_area_unref( (VipsArea *) out_array ); + + return( 0 ); +} + +/* xy range we sanity check on ... just to stop crazy numbers from 1/0 etc. + * causing g_assert() failures later. + */ +#define RANGE (100000000) + +static void +vips_getpoint_class_init( VipsGetpointClass *class ) +{ + GObjectClass *gobject_class = (GObjectClass *) class; + VipsObjectClass *object_class = (VipsObjectClass *) class; + + gobject_class->set_property = vips_object_set_property; + gobject_class->get_property = vips_object_get_property; + + object_class->nickname = "getpoint"; + object_class->description = _( "read a point from an image" ); + object_class->build = vips_getpoint_build; + + VIPS_ARG_IMAGE( class, "in", 1, + _( "in" ), + _( "Input image" ), + VIPS_ARGUMENT_REQUIRED_INPUT, + G_STRUCT_OFFSET( VipsGetpoint, in ) ); + + VIPS_ARG_BOXED( class, "out_array", 2, + _( "Output array" ), + _( "Array of output values" ), + VIPS_ARGUMENT_REQUIRED_OUTPUT, + G_STRUCT_OFFSET( VipsGetpoint, out_array ), + VIPS_TYPE_ARRAY_DOUBLE ); + + VIPS_ARG_INT( class, "x", 5, + _( "x" ), + _( "Getpoint to read from" ), + VIPS_ARGUMENT_REQUIRED_INPUT, + G_STRUCT_OFFSET( VipsGetpoint, x ), + 1, RANGE, 1 ); + + VIPS_ARG_INT( class, "y", 6, + _( "y" ), + _( "Getpoint to read from" ), + VIPS_ARGUMENT_REQUIRED_INPUT, + G_STRUCT_OFFSET( VipsGetpoint, y ), + 1, RANGE, 1 ); + +} + +static void +vips_getpoint_init( VipsGetpoint *getpoint ) +{ +} + +/** + * vips_getpoint: + * @image: image to read from + * @vector: array length=n: output pixel value here + * @n: length of output vector + * @x: position to read + * @y: position to read + * + * Reads a single pixel on an image. + * + * The pixel values are returned in @vector, the length of the + * array in @n. You must free the array with g_free() when you are done with + * it. + * + * See also: vips_draw_point(). + * + * Returns: 0 on success, or -1 on error. + */ +int +vips_getpoint( VipsImage *in, double **vector, int *n, int x, int y, ... ) +{ + va_list ap; + VipsArrayDouble *out_array; + int result; + int i; + + va_start( ap, y ); + result = vips_call_split( "getpoint", ap, in, &out_array, x, y ); + va_end( ap ); + + if( !result ) + return( -1 ); + + if( !(*vector = VIPS_ARRAY( NULL, out_array->n, double )) ) { + vips_area_unref( (VipsArea *) out_array ); + return( -1 ); + } + for( i = 0; i < out_array->n; i++ ) + (*vector)[i] = ((double *) out_array->data)[i]; + *n = out_array->n; + + return( 0 ); +} diff --git a/libvips/arithmetic/measure.c b/libvips/arithmetic/measure.c index 417ddb28..b279e48a 100644 --- a/libvips/arithmetic/measure.c +++ b/libvips/arithmetic/measure.c @@ -68,7 +68,7 @@ #include "statistic.h" -typedef struct _VipsStats { +typedef struct _VipsMeasure { VipsOperation parent_instance; VipsImage *in; diff --git a/libvips/deprecated/vips7compat.c b/libvips/deprecated/vips7compat.c index 944ccd3e..8951085c 100644 --- a/libvips/deprecated/vips7compat.c +++ b/libvips/deprecated/vips7compat.c @@ -4603,6 +4603,29 @@ im_draw_point( VipsImage *image, int x, int y, VipsPel *ink ) return( vips_draw_point( image, vec, n, x, y, NULL ) ); } +int +im_read_point( VipsImage *image, int x, int y, VipsPel *ink ) +{ + double *vector; + int n; + VipsPel *pixel_vector; + + if( vips_getpoint( image, &vector, &n, x, y, NULL ) ) + return( -1 ); + + if( !(pixel_vector = vips__vector_to_ink( "im_read_point", + image, vector, n )) ) { + g_free( vector ); + return( -1 ); + } + + memcpy( ink, pixel_vector, VIPS_IMAGE_SIZEOF_PEL( image ) ); + + g_free( vector ); + + return( 0 ); +} + int im_draw_flood( IMAGE *image, int x, int y, VipsPel *ink, Rect *dout ) { diff --git a/libvips/draw/Makefile.am b/libvips/draw/Makefile.am index 77f0103c..fd7fc2da 100644 --- a/libvips/draw/Makefile.am +++ b/libvips/draw/Makefile.am @@ -12,7 +12,6 @@ libdraw_la_SOURCES = \ draw_line.c \ draw_line_mask.c \ draw_line_user.c \ - im_draw_point.c \ im_draw_smudge.c \ inplace_dispatch.c \ old_draw.c \ diff --git a/libvips/draw/im_draw_point.c b/libvips/draw/im_draw_point.c deleted file mode 100644 index bf01cb06..00000000 --- a/libvips/draw/im_draw_point.c +++ /dev/null @@ -1,101 +0,0 @@ -/* draw / read single points - * - * Copyright: J. Cupitt - * Written: 15/06/1992 - * 22/7/93 JC - * - im_incheck() added - * 16/8/94 JC - * - im_incheck() changed to im_makerw() - * 5/12/06 - * - im_invalidate() after paint - * 6/3/10 - * - don't im_invalidate() after paint, this now needs to be at a higher - * level - * 29/9/10 - * - gtk-doc - * - use Draw base class - * - read_point partial-ised - */ - -/* - - This file is part of VIPS. - - VIPS is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA - - */ - -/* - - These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk - - */ - -#ifdef HAVE_CONFIG_H -#include -#endif /*HAVE_CONFIG_H*/ -#include - -#include -#include -#include - -#include - -#include "old_draw.h" - -/** - * im_read_point: - * @image: image to read from - * @x: position to read - * @y: position to read - * @ink: read value here - * - * Reads a single point on an image. - * - * @ink is an array of bytes to contain a valid pixel for the image's format. - * It must have at least IM_IMAGE_SIZEOF_PEL( @im ) bytes. - * - * See also: im_draw_point(). - * - * Returns: 0 on success, or -1 on error. - */ -int -im_read_point( VipsImage *image, int x, int y, VipsPel *ink ) -{ - REGION *reg; - Rect area; - - if( im_check_coding_known( "im_draw_point", image ) || - !(reg = im_region_create( image )) ) - return( -1 ); - - area.left = x; - area.top = y; - area.width = 1; - area.height = 1; - if( im_prepare( reg, &area ) ) { - im_region_free( reg ); - return( -1 ); - } - - memcpy( ink, IM_REGION_ADDR( reg, x, y ), - IM_IMAGE_SIZEOF_PEL( image ) ); - - im_region_free( reg ); - - return( 0 ); -} diff --git a/libvips/include/vips/arithmetic.h b/libvips/include/vips/arithmetic.h index 9ff2d153..c56d9d7b 100644 --- a/libvips/include/vips/arithmetic.h +++ b/libvips/include/vips/arithmetic.h @@ -377,6 +377,8 @@ int vips_stats( VipsImage *in, VipsImage **out, ... ) __attribute__((sentinel)); int vips_measure( VipsImage *in, VipsImage **out, int h, int v, ... ) __attribute__((sentinel)); +int vips_getpoint( VipsImage *in, double **vector, int *n, int x, int y, ... ) + __attribute__((sentinel)); int vips_hist_find( VipsImage *in, VipsImage **out, ... ) __attribute__((sentinel)); int vips_hist_find_ndim( VipsImage *in, VipsImage **out, ... ) diff --git a/libvips/include/vips/draw.h b/libvips/include/vips/draw.h index c75bf9ac..847bc3f3 100644 --- a/libvips/include/vips/draw.h +++ b/libvips/include/vips/draw.h @@ -92,9 +92,6 @@ int vips_draw_flood1( VipsImage *image, double ink, int x, int y, ... ) -int im_draw_point( VipsImage *image, int x, int y, VipsPel *ink ); -int im_read_point( VipsImage *image, int x, int y, VipsPel *ink ); - int im_draw_smudge( VipsImage *image, int left, int top, int width, int height ); diff --git a/libvips/include/vips/vips7compat.h b/libvips/include/vips/vips7compat.h index c9ebbfc9..308dc893 100644 --- a/libvips/include/vips/vips7compat.h +++ b/libvips/include/vips/vips7compat.h @@ -1026,6 +1026,9 @@ int im_draw_flood_blob( VipsImage *image, int im_draw_flood_other( VipsImage *image, VipsImage *test, int x, int y, int serial, VipsRect *dout ); +int im_draw_point( VipsImage *image, int x, int y, VipsPel *ink ); +int im_read_point( VipsImage *image, int x, int y, VipsPel *ink ); + #ifdef __cplusplus } #endif /*__cplusplus*/