start another draw cleanup
This commit is contained in:
parent
a1e3a9e5cf
commit
d52d027c1a
@ -10,10 +10,7 @@ libdraw_la_SOURCES = \
|
||||
draw_mask.c \
|
||||
draw_image.c \
|
||||
draw_rect.c \
|
||||
draw_line.h \
|
||||
draw_line.c \
|
||||
draw_line_mask.c \
|
||||
draw_line_user.c \
|
||||
draw_smudge.c
|
||||
|
||||
AM_CPPFLAGS = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@
|
||||
|
@ -132,8 +132,6 @@ vips_draw_operation_init( void )
|
||||
extern GType vips_draw_image_get_type( void );
|
||||
extern GType vips_draw_mask_get_type( void );
|
||||
extern GType vips_draw_line_get_type( void );
|
||||
extern GType vips_draw_line_mask_get_type( void );
|
||||
extern GType vips_draw_line_user_get_type( void );
|
||||
extern GType vips_draw_circle_get_type( void );
|
||||
extern GType vips_draw_flood_get_type( void );
|
||||
extern GType vips_draw_smudge_get_type( void );
|
||||
@ -142,8 +140,6 @@ vips_draw_operation_init( void )
|
||||
vips_draw_image_get_type();
|
||||
vips_draw_mask_get_type();
|
||||
vips_draw_line_get_type();
|
||||
vips_draw_line_mask_get_type();
|
||||
vips_draw_line_user_get_type();
|
||||
vips_draw_circle_get_type();
|
||||
vips_draw_flood_get_type();
|
||||
vips_draw_smudge_get_type();
|
||||
|
@ -61,162 +61,176 @@
|
||||
|
||||
#include <vips/vips.h>
|
||||
|
||||
#include "draw_line.h"
|
||||
typedef struct _VipsDrawLine {
|
||||
VipsDrawink parent_object;
|
||||
|
||||
int x1;
|
||||
int y1;
|
||||
int x2;
|
||||
int y2;
|
||||
|
||||
} VipsDrawLine;
|
||||
|
||||
typedef struct _VipsDrawLineClass {
|
||||
VipsDrawinkClass parent_class;
|
||||
|
||||
} VipsDrawLineClass;
|
||||
|
||||
G_DEFINE_TYPE( VipsDrawLine, vips_draw_line, VIPS_TYPE_DRAWINK );
|
||||
|
||||
static int
|
||||
vips_draw_line_draw( VipsDrawLine *line )
|
||||
void
|
||||
vips__draw_line_direct( VipsImage *image, int x1, int y1, int x2, int y2,
|
||||
VipsDrawPoint draw_point, void *client )
|
||||
{
|
||||
VipsDrawink *drawink = VIPS_DRAWINK( line );
|
||||
VipsDrawLineClass *class = VIPS_DRAW_LINE_GET_CLASS( line );
|
||||
VipsDrawPoint draw_point = class->draw_point;
|
||||
|
||||
int dx, dy;
|
||||
int x, y, err;
|
||||
|
||||
/* Find offsets.
|
||||
*/
|
||||
line->dx = line->x2 - line->x1;
|
||||
line->dy = line->y2 - line->y1;
|
||||
dx = x2 - x1;
|
||||
dy = y2 - y1;
|
||||
|
||||
/* Swap endpoints to reduce number of cases.
|
||||
*/
|
||||
if( abs( line->dx ) >= abs( line->dy ) &&
|
||||
line->dx < 0 ) {
|
||||
if( abs( dx ) >= abs( dy ) &&
|
||||
dx < 0 ) {
|
||||
/* Swap to get all x greater or equal cases going to the
|
||||
* right. Do diagonals here .. just have up and right and down
|
||||
* and right now.
|
||||
*/
|
||||
VIPS_SWAP( int, line->x1, line->x2 );
|
||||
VIPS_SWAP( int, line->y1, line->y2 );
|
||||
VIPS_SWAP( int, x1, x2 );
|
||||
VIPS_SWAP( int, y1, y2 );
|
||||
}
|
||||
else if( abs( line->dx ) < abs( line->dy ) &&
|
||||
line->dy < 0 ) {
|
||||
else if( abs( dx ) < abs( dy ) &&
|
||||
dy < 0 ) {
|
||||
/* Swap to get all y greater cases going down the screen.
|
||||
*/
|
||||
VIPS_SWAP( int, line->x1, line->x2 );
|
||||
VIPS_SWAP( int, line->y1, line->y2 );
|
||||
VIPS_SWAP( int, x1, x2 );
|
||||
VIPS_SWAP( int, y1, y2 );
|
||||
}
|
||||
|
||||
/* Recalculate dx, dy.
|
||||
*/
|
||||
line->dx = line->x2 - line->x1;
|
||||
line->dy = line->y2 - line->y1;
|
||||
dx = x2 - x1;
|
||||
dy = y2 - y1;
|
||||
|
||||
/* Start point and offset.
|
||||
*/
|
||||
x = line->x1;
|
||||
y = line->y1;
|
||||
x = x1;
|
||||
y = y1;
|
||||
|
||||
/* Special case: zero width and height is single point.
|
||||
*/
|
||||
if( line->dx == 0 &&
|
||||
line->dy == 0 ) {
|
||||
if( draw_point( drawink, x, y ) )
|
||||
return( -1 );
|
||||
}
|
||||
if( dx == 0 &&
|
||||
dy == 0 )
|
||||
draw_point( image, x, y, client );
|
||||
/* Special case vertical and horizontal lines for speed.
|
||||
*/
|
||||
else if( line->dx == 0 ) {
|
||||
else if( dx == 0 ) {
|
||||
/* Vertical line going down.
|
||||
*/
|
||||
for( ; y <= line->y2; y++ ) {
|
||||
if( draw_point( drawink, x, y ) )
|
||||
return( -1 );
|
||||
}
|
||||
for( ; y <= y2; y++ )
|
||||
draw_point( image, x, y, client );
|
||||
}
|
||||
else if( line->dy == 0 ) {
|
||||
else if( dy == 0 ) {
|
||||
/* Horizontal line to the right.
|
||||
*/
|
||||
for( ; x <= line->x2; x++ ) {
|
||||
if( draw_point( drawink, x, y ) )
|
||||
return( -1 );
|
||||
}
|
||||
for( ; x <= x2; x++ )
|
||||
draw_point( image, x, y, client );
|
||||
}
|
||||
/* Special case diagonal lines.
|
||||
*/
|
||||
else if( abs( line->dy ) == abs( line->dx ) &&
|
||||
line->dy > 0 ) {
|
||||
else if( abs( dy ) == abs( dx ) &&
|
||||
dy > 0 ) {
|
||||
/* Diagonal line going down and right.
|
||||
*/
|
||||
for( ; x <= line->x2; x++, y++ ) {
|
||||
if( draw_point( drawink, x, y ) )
|
||||
return( -1 );
|
||||
}
|
||||
for( ; x <= x2; x++, y++ )
|
||||
draw_point( image, x, y, client );
|
||||
}
|
||||
else if( abs( line->dy ) == abs( line->dx ) &&
|
||||
line->dy < 0 ) {
|
||||
else if( abs( dy ) == abs( dx ) &&
|
||||
dy < 0 ) {
|
||||
/* Diagonal line going up and right.
|
||||
*/
|
||||
for( ; x <= line->x2; x++, y-- ) {
|
||||
if( draw_point( drawink, x, y ) )
|
||||
return( -1 );
|
||||
}
|
||||
for( ; x <= x2; x++, y-- )
|
||||
draw_point( image, x, y, client );
|
||||
}
|
||||
else if( abs( line->dy ) < abs( line->dx ) &&
|
||||
line->dy > 0 ) {
|
||||
else if( abs( dy ) < abs( dx ) &&
|
||||
dy > 0 ) {
|
||||
/* Between -45 and 0 degrees.
|
||||
*/
|
||||
for( err = 0; x <= line->x2; x++ ) {
|
||||
if( draw_point( drawink, x, y ) )
|
||||
return( -1 );
|
||||
for( err = 0; x <= x2; x++ ) {
|
||||
draw_point( image, x, y, client );
|
||||
|
||||
err += line->dy;
|
||||
if( err >= line->dx ) {
|
||||
err -= line->dx;
|
||||
err += dy;
|
||||
if( err >= dx ) {
|
||||
err -= dx;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( abs( line->dy ) < abs( line->dx ) &&
|
||||
line->dy < 0 ) {
|
||||
else if( abs( dy ) < abs( dx ) &&
|
||||
dy < 0 ) {
|
||||
/* Between 0 and 45 degrees.
|
||||
*/
|
||||
for( err = 0; x <= line->x2; x++ ) {
|
||||
if( draw_point( drawink, x, y ) )
|
||||
return( -1 );
|
||||
for( err = 0; x <= x2; x++ ) {
|
||||
draw_point( image, x, y, client );
|
||||
|
||||
err -= line->dy;
|
||||
if( err >= line->dx ) {
|
||||
err -= line->dx;
|
||||
err -= dy;
|
||||
if( err >= dx ) {
|
||||
err -= dx;
|
||||
y--;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( abs( line->dy ) > abs( line->dx ) &&
|
||||
line->dx > 0 ) {
|
||||
else if( abs( dy ) > abs( dx ) &&
|
||||
dx > 0 ) {
|
||||
/* Between -45 and -90 degrees.
|
||||
*/
|
||||
for( err = 0; y <= line->y2; y++ ) {
|
||||
if( draw_point( drawink, x, y ) )
|
||||
return( -1 );
|
||||
for( err = 0; y <= y2; y++ ) {
|
||||
draw_point( image, x, y, client );
|
||||
|
||||
err += line->dx;
|
||||
if( err >= line->dy ) {
|
||||
err -= line->dy;
|
||||
err += dx;
|
||||
if( err >= dy ) {
|
||||
err -= dy;
|
||||
x++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( abs( line->dy ) > abs( line->dx ) &&
|
||||
line->dx < 0 ) {
|
||||
else if( abs( dy ) > abs( dx ) &&
|
||||
dx < 0 ) {
|
||||
/* Between -90 and -135 degrees.
|
||||
*/
|
||||
for( err = 0; y <= line->y2; y++ ) {
|
||||
if( draw_point( drawink, x, y ) )
|
||||
return( -1 );
|
||||
for( err = 0; y <= y2; y++ ) {
|
||||
draw_point( image, x, y, client );
|
||||
|
||||
err -= line->dx;
|
||||
if( err >= line->dy ) {
|
||||
err -= line->dy;
|
||||
err -= dx;
|
||||
if( err >= dy ) {
|
||||
err -= dy;
|
||||
x--;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
g_assert( 0 );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
static void
|
||||
vips_draw_line_draw_point_noclip( VipsImage *image, int x, int y, void *client )
|
||||
{
|
||||
VipsPel *ink = (VipsPel *) client;
|
||||
VipsPel *q = VIPS_IMAGE_ADDR( image, x, y );
|
||||
int psize = VIPS_IMAGE_SIZEOF_PEL( image );
|
||||
|
||||
int j;
|
||||
|
||||
/* Faster than memcopy() for n < about 20.
|
||||
*/
|
||||
for( j = 0; j < psize; j++ )
|
||||
q[j] = ink[j];
|
||||
}
|
||||
|
||||
static void
|
||||
vips_draw_line_draw_point_clip( VipsImage *image, int x, int y, void *client )
|
||||
{
|
||||
if( x >= 0 &&
|
||||
x < image->Xsize &&
|
||||
y >= 0 &&
|
||||
y < image->Ysize )
|
||||
vips_draw_line_draw_point_noclip( image, x, y, client );
|
||||
}
|
||||
|
||||
static int
|
||||
@ -225,38 +239,11 @@ vips_draw_line_build( VipsObject *object )
|
||||
VipsDraw *draw = VIPS_DRAW( object );
|
||||
VipsDrawLine *line = (VipsDrawLine *) object;
|
||||
|
||||
VipsDrawPoint draw_point;
|
||||
|
||||
if( VIPS_OBJECT_CLASS( vips_draw_line_parent_class )->build( object ) )
|
||||
return( -1 );
|
||||
|
||||
/* Find offsets.
|
||||
*/
|
||||
line->dx = line->x2 - line->x1;
|
||||
line->dy = line->y2 - line->y1;
|
||||
|
||||
/* Swap endpoints to reduce number of cases.
|
||||
*/
|
||||
if( abs( line->dx ) >= abs( line->dy ) &&
|
||||
line->dx < 0 ) {
|
||||
/* Swap to get all x greater or equal cases going to the
|
||||
* right. Do diagonals here .. just have up and right and down
|
||||
* and right now.
|
||||
*/
|
||||
VIPS_SWAP( int, line->x1, line->x2 );
|
||||
VIPS_SWAP( int, line->y1, line->y2 );
|
||||
}
|
||||
else if( abs( line->dx ) < abs( line->dy ) &&
|
||||
line->dy < 0 ) {
|
||||
/* Swap to get all y greater cases going down the screen.
|
||||
*/
|
||||
VIPS_SWAP( int, line->x1, line->x2 );
|
||||
VIPS_SWAP( int, line->y1, line->y2 );
|
||||
}
|
||||
|
||||
/* Recalculate dx, dy.
|
||||
*/
|
||||
line->dx = line->x2 - line->x1;
|
||||
line->dy = line->y2 - line->y1;
|
||||
|
||||
if( line->x1 < draw->image->Xsize &&
|
||||
line->x1 >= 0 &&
|
||||
line->x2 < draw->image->Xsize &&
|
||||
@ -265,24 +252,13 @@ vips_draw_line_build( VipsObject *object )
|
||||
line->y1 >= 0 &&
|
||||
line->y2 < draw->image->Ysize &&
|
||||
line->y2 >= 0 )
|
||||
draw->noclip = TRUE;
|
||||
|
||||
if( vips_draw_line_draw( line ) )
|
||||
return( -1 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static int
|
||||
vips_draw_line_draw_point( VipsDrawink *drawink, int x, int y )
|
||||
{
|
||||
VipsDraw *draw = (VipsDraw *) drawink;
|
||||
|
||||
if( draw->noclip )
|
||||
vips__drawink_pel( drawink,
|
||||
VIPS_IMAGE_ADDR( draw->image, x, y ) );
|
||||
draw_point = vips_draw_line_draw_point_noclip;
|
||||
else
|
||||
vips__drawink_pel_clip( drawink, x, y );
|
||||
draw_point = vips_draw_line_draw_point_clip;
|
||||
|
||||
vips__draw_line_direct( draw->image,
|
||||
line->x1, line->y1, line->x2, line->y2,
|
||||
draw_point, drawink->pixel_ink );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -300,8 +276,6 @@ vips_draw_line_class_init( VipsDrawLineClass *class )
|
||||
vobject_class->description = _( "draw a draw_line on an image" );
|
||||
vobject_class->build = vips_draw_line_build;
|
||||
|
||||
class->draw_point = vips_draw_line_draw_point;
|
||||
|
||||
VIPS_ARG_INT( class, "x1", 3,
|
||||
_( "x1" ),
|
||||
_( "Start of draw_line" ),
|
||||
|
@ -1,81 +0,0 @@
|
||||
/* draw_line draw 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
|
||||
|
||||
*/
|
||||
|
||||
#ifndef VIPS_DRAW_LINE_H
|
||||
#define VIPS_DRAW_LINE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /*__cplusplus*/
|
||||
|
||||
#include "drawink.h"
|
||||
|
||||
#define VIPS_TYPE_DRAW_LINE (vips_draw_line_get_type())
|
||||
#define VIPS_DRAW_LINE( obj ) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST( (obj), \
|
||||
VIPS_TYPE_DRAW_LINE, VipsDrawLine ))
|
||||
#define VIPS_DRAW_LINE_CLASS( klass ) \
|
||||
(G_TYPE_CHECK_CLASS_CAST( (klass), \
|
||||
VIPS_TYPE_DRAW_LINE, VipsDrawLineClass))
|
||||
#define VIPS_IS_DRAW_LINE( obj ) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_DRAW_LINE ))
|
||||
#define VIPS_IS_DRAW_LINE_CLASS( klass ) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_DRAW_LINE ))
|
||||
#define VIPS_DRAW_LINE_GET_CLASS( obj ) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS( (obj), \
|
||||
VIPS_TYPE_DRAW_LINE, VipsDrawLineClass ))
|
||||
|
||||
typedef struct _VipsDrawLine {
|
||||
VipsDrawink parent_object;
|
||||
|
||||
int x1;
|
||||
int y1;
|
||||
int x2;
|
||||
int y2;
|
||||
|
||||
int dx;
|
||||
int dy;
|
||||
|
||||
} VipsDrawLine;
|
||||
|
||||
typedef struct _VipsDrawLineClass {
|
||||
VipsDrawinkClass parent_class;
|
||||
|
||||
VipsDrawPoint draw_point;
|
||||
} VipsDrawLineClass;
|
||||
|
||||
GType vips_draw_line_get_type( void );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus*/
|
||||
|
||||
#endif /*VIPS_PDRAW_H*/
|
||||
|
@ -1,197 +0,0 @@
|
||||
/* draw a mask along a line
|
||||
*
|
||||
* Copyright: J. Cupitt
|
||||
* Written: 15/06/1992
|
||||
* 22/7/93 JC
|
||||
* - im_incheck() added
|
||||
* 16/8/94 JC
|
||||
* - im_incheck() changed to im_makerw()
|
||||
* 24/10/03 JC
|
||||
* - now blends with 0-255 mask
|
||||
* 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
|
||||
* 28/9/10
|
||||
* - gtk-doc
|
||||
* - renamed as im_draw_mask()
|
||||
* - use Draw base class
|
||||
* 6/2/14
|
||||
* - now a subclass of VipsDrawLine
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
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 <vips/vips.h>
|
||||
|
||||
#include "draw_line.h"
|
||||
|
||||
typedef struct _VipsDrawLineMask {
|
||||
VipsDrawLine parent_object;
|
||||
|
||||
VipsImage *mask;
|
||||
|
||||
} VipsDrawLineMask;
|
||||
|
||||
typedef VipsDrawLineClass VipsDrawLineMaskClass;
|
||||
|
||||
G_DEFINE_TYPE( VipsDrawLineMask, vips_draw_line_mask, VIPS_TYPE_DRAW_LINE );
|
||||
|
||||
static int
|
||||
vips_draw_line_mask_draw_point( VipsDrawink *drawink, int x, int y )
|
||||
{
|
||||
VipsDraw *draw = (VipsDraw *) drawink;
|
||||
VipsDrawLineMask *mask = (VipsDrawLineMask *) drawink;
|
||||
|
||||
return( vips_draw_mask( draw->image,
|
||||
drawink->ink->data, drawink->ink->n,
|
||||
mask->mask, x, y, NULL ) );
|
||||
}
|
||||
|
||||
static void
|
||||
vips_draw_line_mask_class_init( VipsDrawLineMaskClass *class )
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
|
||||
VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class );
|
||||
|
||||
gobject_class->set_property = vips_object_set_property;
|
||||
gobject_class->get_property = vips_object_get_property;
|
||||
|
||||
vobject_class->nickname = "draw_line_mask";
|
||||
vobject_class->description = _( "draw a mask along a line" );
|
||||
|
||||
class->draw_point = vips_draw_line_mask_draw_point;
|
||||
|
||||
VIPS_ARG_IMAGE( class, "mask", 7,
|
||||
_( "Mask" ),
|
||||
_( "Mask image" ),
|
||||
VIPS_ARGUMENT_REQUIRED_INPUT,
|
||||
G_STRUCT_OFFSET( VipsDrawLineMask, mask ) );
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
vips_draw_line_mask_init( VipsDrawLineMask *draw_line_mask )
|
||||
{
|
||||
}
|
||||
|
||||
static int
|
||||
vips_draw_line_maskv( VipsImage *image,
|
||||
double *ink, int n, int x1, int y1, int x2, int y2, VipsImage *mask,
|
||||
va_list ap )
|
||||
{
|
||||
VipsArea *area_ink;
|
||||
int result;
|
||||
|
||||
area_ink = (VipsArea *) vips_array_double_new( ink, n );
|
||||
result = vips_call_split( "draw_line_mask", ap,
|
||||
image, area_ink, x1, y1, x2, y2, mask );
|
||||
vips_area_unref( area_ink );
|
||||
|
||||
return( result );
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_draw_line_mask:
|
||||
* @image: image to draw on
|
||||
* @ink: (array length=n): value to draw
|
||||
* @n: length of ink array
|
||||
* @x1: start of line
|
||||
* @y1: start of line
|
||||
* @x2: end of line
|
||||
* @y2: end of line
|
||||
* @mask: mask to draw along line
|
||||
*
|
||||
* Draws @mask at every point along a line.
|
||||
*
|
||||
* @ink is an array of double containing values to draw.
|
||||
*
|
||||
* See also: vips_draw_line_mask1(), vips_draw_line(), vips_draw_mask().
|
||||
*
|
||||
* Returns: 0 on success, or -1 on error.
|
||||
*/
|
||||
int
|
||||
vips_draw_line_mask( VipsImage *image,
|
||||
double *ink, int n, int x1, int y1, int x2, int y2,
|
||||
VipsImage *mask, ... )
|
||||
{
|
||||
va_list ap;
|
||||
int result;
|
||||
|
||||
va_start( ap, mask );
|
||||
result = vips_draw_line_maskv( image,
|
||||
ink, n, x1, y1, x2, y2, mask, ap );
|
||||
va_end( ap );
|
||||
|
||||
return( result );
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_draw_line_mask1:
|
||||
* @image: image to draw on
|
||||
* @ink: value to draw
|
||||
* @x1: start of line
|
||||
* @y1: start of line
|
||||
* @x2: end of line
|
||||
* @y2: end of line
|
||||
* @mask: mask to draw along line
|
||||
*
|
||||
* As vips_draw_line_mask(), but just takes a single double for @ink.
|
||||
*
|
||||
* See also: vips_draw_line_mask(), vips_circle().
|
||||
*
|
||||
* Returns: 0 on success, or -1 on error.
|
||||
*/
|
||||
int
|
||||
vips_draw_line_mask1( VipsImage *image,
|
||||
double ink, int x1, int y1, int x2, int y2, VipsImage *mask, ... )
|
||||
{
|
||||
double array_ink[1];
|
||||
va_list ap;
|
||||
int result;
|
||||
|
||||
array_ink[0] = ink;
|
||||
|
||||
va_start( ap, mask );
|
||||
result = vips_draw_line_maskv( image,
|
||||
array_ink, 1, x1, y1, x2, y2, mask, ap );
|
||||
va_end( ap );
|
||||
|
||||
return( result );
|
||||
}
|
@ -1,172 +0,0 @@
|
||||
/* call a user function along a draw_line ... useful for vips7 compat
|
||||
*
|
||||
* Copyright: J. Cupitt
|
||||
* Written: 15/06/1992
|
||||
* 22/7/93 JC
|
||||
* - im_incheck() added
|
||||
* 16/8/94 JC
|
||||
* - im_incheck() changed to im_makerw()
|
||||
* 24/10/03 JC
|
||||
* - now blends with 0-255 user
|
||||
* 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
|
||||
* 28/9/10
|
||||
* - gtk-doc
|
||||
* - renamed as im_draw_user()
|
||||
* - use Draw base class
|
||||
* 6/2/14
|
||||
* - now a subclass of VipsDrawLine
|
||||
* 9/2/14
|
||||
* - from draw_lineuser
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
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 <vips/vips.h>
|
||||
|
||||
#include "pdraw.h"
|
||||
#include "draw_line.h"
|
||||
|
||||
typedef struct _VipsDrawLineUser {
|
||||
VipsDrawLine parent_object;
|
||||
|
||||
VipsPlotFn plot_fn;
|
||||
void *a;
|
||||
void *b;
|
||||
void *c;
|
||||
|
||||
} VipsDrawLineUser;
|
||||
|
||||
typedef VipsDrawLineClass VipsDrawLineUserClass;
|
||||
|
||||
G_DEFINE_TYPE( VipsDrawLineUser, vips_draw_line_user, VIPS_TYPE_DRAW_LINE );
|
||||
|
||||
static int
|
||||
vips_draw_line_user_draw_point( VipsDrawink *drawink, int x, int y )
|
||||
{
|
||||
VipsDraw *draw = (VipsDraw *) drawink;
|
||||
VipsDrawLineUser *user = (VipsDrawLineUser *) drawink;
|
||||
|
||||
return( user->plot_fn( draw->image, x, y, user->a, user->b, user->c ) );
|
||||
}
|
||||
|
||||
static void
|
||||
vips_draw_line_user_class_init( VipsDrawLineUserClass *class )
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
|
||||
VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class );
|
||||
VipsOperationClass *operation_class = (VipsOperationClass *) class;
|
||||
|
||||
gobject_class->set_property = vips_object_set_property;
|
||||
gobject_class->get_property = vips_object_get_property;
|
||||
|
||||
vobject_class->nickname = "draw_line_user";
|
||||
vobject_class->description = _( "call a plot function along a line" );
|
||||
|
||||
operation_class->flags = VIPS_OPERATION_DEPRECATED;
|
||||
|
||||
class->draw_point = vips_draw_line_user_draw_point;
|
||||
|
||||
VIPS_ARG_POINTER( class, "plot_fn", 7,
|
||||
_( "Plot" ),
|
||||
_( "User plot function" ),
|
||||
VIPS_ARGUMENT_REQUIRED_INPUT,
|
||||
G_STRUCT_OFFSET( VipsDrawLineUser, plot_fn ) );
|
||||
|
||||
VIPS_ARG_POINTER( class, "a", 8,
|
||||
_( "a" ),
|
||||
_( "first user argument" ),
|
||||
VIPS_ARGUMENT_REQUIRED_INPUT,
|
||||
G_STRUCT_OFFSET( VipsDrawLineUser, a ) );
|
||||
|
||||
VIPS_ARG_POINTER( class, "b", 9,
|
||||
_( "b" ),
|
||||
_( "second user argument" ),
|
||||
VIPS_ARGUMENT_REQUIRED_INPUT,
|
||||
G_STRUCT_OFFSET( VipsDrawLineUser, b ) );
|
||||
|
||||
VIPS_ARG_POINTER( class, "c", 10,
|
||||
_( "c" ),
|
||||
_( "third user argument" ),
|
||||
VIPS_ARGUMENT_REQUIRED_INPUT,
|
||||
G_STRUCT_OFFSET( VipsDrawLineUser, c ) );
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
vips_draw_line_user_init( VipsDrawLineUser *draw_line_user )
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_draw_line_user:
|
||||
* @image: image to draw on
|
||||
* @x1: start of draw_line
|
||||
* @y1: start of draw_line
|
||||
* @x2: end of draw_line
|
||||
* @y2: end of draw_line
|
||||
* @user: plot function to call along draw_line
|
||||
* @a: user plot function argument
|
||||
* @b: user plot function argument
|
||||
* @c: user plot function argument
|
||||
*
|
||||
* Calls a user plot function for every point on a line. This is mostly useful
|
||||
* for vips7 compatibility.
|
||||
*
|
||||
* See also: vips_draw_line(), vips_draw_line_mask().
|
||||
*
|
||||
* Returns: 0 on success, or -1 on error.
|
||||
*/
|
||||
int
|
||||
vips_draw_line_user( VipsImage *image,
|
||||
int x1, int y1, int x2, int y2,
|
||||
VipsPlotFn plot_fn, void *a, void *b, void *c, ... )
|
||||
{
|
||||
va_list ap;
|
||||
int result;
|
||||
|
||||
va_start( ap, c );
|
||||
result = vips_call_split( "draw_line_user", ap,
|
||||
image, NULL, x1, y1, x2, y2, plot_fn, a, b, c );
|
||||
va_end( ap );
|
||||
|
||||
return( result );
|
||||
}
|
@ -69,10 +69,6 @@ typedef struct _VipsDrawinkClass {
|
||||
|
||||
GType vips_drawink_get_type( void );
|
||||
|
||||
typedef int (*VipsDrawPoint)( VipsDrawink *drawink, int x, int y );
|
||||
typedef void (*VipsDrawScanline)( VipsImage *image,
|
||||
int y, int x1, int x2, void *client );
|
||||
|
||||
static inline int
|
||||
vips__drawink_pel( VipsDrawink *drawink, VipsPel *q )
|
||||
{
|
||||
|
@ -274,6 +274,16 @@ int vips__draw_flood_direct( VipsImage *image, VipsImage *test,
|
||||
int vips__draw_mask_direct( VipsImage *image, VipsImage *mask,
|
||||
VipsPel *ink, int x, int y );
|
||||
|
||||
typedef void (*VipsDrawPoint)( VipsImage *image,
|
||||
int x, int y, void *client );
|
||||
typedef void (*VipsDrawScanline)( VipsImage *image,
|
||||
int y, int x1, int x2, void *client );
|
||||
|
||||
void vips__draw_line_direct( VipsImage *image, int x1, int y1, int x2, int y2,
|
||||
VipsDrawPoint draw_point, void *client );
|
||||
void vips__draw_circle_direct( VipsImage *image, int cx, int cy, int r,
|
||||
VipsDrawScanline draw_scanline, void *client );
|
||||
|
||||
/* Register base vips interpolators, called during startup.
|
||||
*/
|
||||
void vips__interpolate_init( void );
|
||||
|
Loading…
Reference in New Issue
Block a user