do im_read_point() / im_draw_point()

This commit is contained in:
John Cupitt 2014-02-10 21:54:54 +00:00
parent 4c732ce369
commit 25fbe71c74
12 changed files with 287 additions and 113 deletions

View File

@ -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

46
TODO
View File

@ -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

View File

@ -6,6 +6,7 @@ libarithmetic_la_SOURCES = \
deviate.c \
divide.c \
measure.c \
getpoint.c \
multiply.c \
remainder.c \
sign.c \

View File

@ -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();

View File

@ -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 <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vips/vips.h>
#include <vips/internal.h>
#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 );
}

View File

@ -68,7 +68,7 @@
#include "statistic.h"
typedef struct _VipsStats {
typedef struct _VipsMeasure {
VipsOperation parent_instance;
VipsImage *in;

View File

@ -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 )
{

View File

@ -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 \

View File

@ -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 <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vips/vips.h>
#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 );
}

View File

@ -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, ... )

View File

@ -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 );

View File

@ -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*/