added im_draw_point() / im_read_point()

This commit is contained in:
John Cupitt 2010-09-29 13:45:09 +00:00
parent 1458021a95
commit 94763652ad
10 changed files with 226 additions and 147 deletions

View File

@ -27,6 +27,8 @@
- added im_draw_line(), now clips, moved im_fastline() to deprecated
- added im_draw_line_user(), now clips, moved im_fastlineuser() to deprecated
- added im_draw_mask(), now wrappable, moved im_plotmask() to deprecated
- added im_draw_point(), moved im_plotpoint() to deprecated
- added im_read_point(), now partial, moved im_readpoint() to deprecated
12/5/10 started 7.22.2
- the conditional image of ifthenelse can be any format, a (!=0) is added if

11
TODO
View File

@ -1,16 +1,7 @@
- im_draw_mask() should not take mx/my args, we can just displace x / y
- wrap im_read_point: output OUBLEVEC?
- im_plotmask() should take the mask as a mono uchar IMAGE perhaps
still need a rect for x/y/w/h of mask, since we use it with userline and an
offset circle to draw fatlines
- im_draw_line() should clip x1/y1 x2/y2, cf. im_draw_line_user()
perhaps just put a clip in the plot thing, or have two plotters and pick the
clip one if start/end are within the image

View File

@ -556,3 +556,15 @@ im_plotmask( IMAGE *im, int ix, int iy, PEL *ink, PEL *mask, Rect *r )
return( 0 );
}
int
im_readpoint( IMAGE *im, int x, int y, PEL *pel )
{
return( im_read_point( im, x, y, pel ) );
}
int
im_plotpoint( IMAGE *im, int x, int y, PEL *pel )
{
return( im_draw_point( im, x, y, pel ) );
}

View File

@ -245,6 +245,8 @@ int im_fastlineuser( IMAGE *im,
int (*fn)(), void *client1, void *client2, void *client3 );
int im_plotmask( IMAGE *im, int ix, int iy, PEL *ink, PEL *mask, Rect *r );
int im_readpoint( IMAGE *im, int x, int y, PEL *pel );
int im_plotpoint( IMAGE *im, int x, int y, PEL *pel );
#ifdef __cplusplus
}

View File

@ -61,7 +61,9 @@ int im_flood_other( VipsImage *image, VipsImage *test,
int im_draw_mask( VipsImage *image,
VipsImage *mask_im, int ix, int iy, PEL *ink );
int im_readpoint( VipsImage *im, int x, int y, PEL *pel );
int im_draw_point( VipsImage *image, int x, int y, PEL *ink );
int im_read_point( VipsImage *image, int x, int y, PEL *ink );
int im_smear( VipsImage *im, int ix, int iy, Rect *r );
int im_smudge( VipsImage *im, int ix, int iy, Rect *r );

View File

@ -8,9 +8,9 @@ libinplace_la_SOURCES = \
im_draw_image.c \
im_draw_rect.c \
im_draw_mask.c \
im_draw_point.c \
flood.c \
inplace_dispatch.c \
plot_point.c \
smudge_area.c
INCLUDES = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@

View File

@ -176,41 +176,43 @@ circle_draw( Circle *circle )
/**
* im_draw_circle:
* @im: image to draw on
* @image: image to draw on
* @cx: centre of circle
* @cy: centre of circle
* @radius: circle radius
* @fill: fill the circle
* @ink: value to draw
*
* Draws a circle on an image. If @fill is %TRUE then the circle is filled,
* Draws a circle on @image. If @fill is %TRUE then the circle is filled,
* otherwise a 1-pixel-wide perimeter is drawn.
*
* @ink is an array of bytes containing a valid pixel for the image's format.
* It must have at least IM_IMAGE_SIZEOF_PEL( @im ) bytes.
* It must have at least IM_IMAGE_SIZEOF_PEL( @image ) bytes.
*
* This an inplace operation, so @im is changed. It does not thread and will
* This an inplace operation, so @image is changed. It does not thread and will
* not work well as part of a pipeline. On 32-bit machines it will be limited
* to 2GB images.
*
* See also: im_fastline().
* See also: im_draw_line().
*
* Returns: 0 on success, or -1 on error.
*/
int
im_draw_circle( IMAGE *im, int cx, int cy, int radius, gboolean fill, PEL *ink )
im_draw_circle( VipsImage *image,
int cx, int cy, int radius, gboolean fill, PEL *ink )
{
Circle *circle;
if( cx + radius >= 0 && cx - radius < image->Xsize &&
cy + radius >= 0 && cy - radius < image->Ysize ) {
Circle *circle;
if( cx + radius < 0 || cx - radius >= im->Xsize ||
cy + radius < 0 || cy - radius >= im->Ysize )
return( 0 );
if( im_check_coding_known( "im_draw_circle", image ) ||
!(circle = circle_new( image,
cx, cy, radius, fill, ink )) )
return( -1 );
circle_draw( circle );
if( im_check_coding_known( "im_draw_circle", im ) ||
!(circle = circle_new( im, cx, cy, radius, fill, ink )) )
return( -1 );
circle_draw( circle );
circle_free( circle );
circle_free( circle );
}
return( 0 );
}

View File

@ -0,0 +1,148 @@
/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 "draw.h"
#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif /*WITH_DMALLOC*/
typedef struct _Point {
Draw draw;
} Point;
/**
* im_draw_point:
* @image: image to draw on
* @x: position to draw
* @y: position to draw
* @ink: value to draw
*
* Draws a single point on an image.
*
* @ink is an array of bytes containing a valid pixel for the image's format.
* It must have at least IM_IMAGE_SIZEOF_PEL( @im ) bytes.
*
* This an inplace operation, so @im is changed. It does not thread and will
* not work well as part of a pipeline. On 32-bit machines it will be limited
* to 2GB images.
*
* See also: im_draw_line().
*
* Returns: 0 on success, or -1 on error.
*/
int
im_draw_point( VipsImage *image, int x, int y, PEL *ink )
{
Point point;
if( im_check_coding_known( "im_draw_point", image ) ||
im__draw_init( DRAW( &point ), image, NULL ) )
return( -1 );
/* Check coordinates.
*/
if( x >= 0 && x < image->Xsize && y >= 0 && y < image->Ysize )
memcpy( IM_IMAGE_ADDR( image, x, y ), ink,
DRAW( image )->psize );
im__draw_free( DRAW( &point ) );
return( 0 );
}
/**
* 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, PEL *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

@ -311,6 +311,45 @@ static im_function flood_other_desc = {
flood_other_args /* Arg list */
};
/* Args for im_draw_point.
*/
static im_arg_desc draw_point_args[] = {
IM_RW_IMAGE( "image" ),
IM_INPUT_INT( "x" ),
IM_INPUT_INT( "y" ),
IM_INPUT_DOUBLEVEC( "ink" )
};
/* Call im_draw_point via arg vector.
*/
static int
draw_point_vec( im_object *argv )
{
IMAGE *image = argv[0];
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_draw_point",
image, dv->n, dv->vec )) )
return( -1 );
return( im_draw_point( image, x, y, ink ) );
}
/* Description of im_draw_point.
*/
static im_function draw_point_desc = {
"im_draw_point", /* Name */
"draw point on image",
0, /* Flags */
draw_point_vec, /* Dispatch function */
IM_NUMBER( draw_point_args ), /* Size of arg list */
draw_point_args /* Arg list */
};
/* Args for im_draw_line.
*/
static im_arg_desc draw_line_args[] = {
@ -456,6 +495,7 @@ static im_function *inplace_list[] = {
&draw_circle_desc,
&draw_rect_desc,
&draw_line_desc,
&draw_point_desc,
&flood_desc,
&flood_blob_desc,
&flood_other_desc,

View File

@ -1,120 +0,0 @@
/* @(#) Read a pel out of an image and into a buffer, plot a pel back into
* @(#) the image again.
* @(#)
* @(#) int
* @(#) im_readpoint( IMAGE *im, int x, int y, PEL *ink )
* @(#)
* @(#) int
* @(#) im_plotpoint( IMAGE *im, int x, int y, PEL *ink )
* @(#)
*
* 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
*/
/*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 <vips/vips.h>
#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif /*WITH_DMALLOC*/
/* Read a colour from an image.
*/
int
im_readpoint( IMAGE *im, int x, int y, PEL *pel )
{
int es = IM_IMAGE_SIZEOF_ELEMENT( im );
int ps = es * im->Bands;
int ls = ps * im->Xsize;
int b;
PEL *from;
if( im_rwcheck( im ) )
return( -1 );
/* Check coordinates in range.
*/
if( x > im->Xsize || x < 0 || y > im->Ysize || y < 0 ) {
im_error( "im_readpoint", "%s", _( "invalid cooordinates" ) );
return( 1 );
}
/* Suck single pixel.
*/
from = (PEL *) im->data + x * ps + y * ls;
for( b = 0; b < ps; b++ )
*pel++ = *from++;
return( 0 );
}
/* Plot a point in an image.
*/
int
im_plotpoint( IMAGE *im, int x, int y, PEL *pel )
{
int es = IM_IMAGE_SIZEOF_ELEMENT( im );
int ps = es * im->Bands;
int ls = ps * im->Xsize;
int b;
PEL *to;
if( im_rwcheck( im ) )
return( -1 );
/* Check coordinates in range.
*/
if( x > im->Xsize || x < 0 || y > im->Ysize || y < 0 )
return( 0 );
/* Paint single pixel.
*/
to = (PEL *) im->data + x * ps + y * ls;
for( b = 0; b < ps; b++ )
*to++ = *pel++;
return( 0 );
}