1
/* @(#) writes a circle in a vasari file
2
* @(#) The circle is centred in the middle of the file (xsize/2, ysize/2)
3
* @(#) im must be a valid image
4
* @(#) int im_circle(pim, cx, cy, radius, intensity)
6
* @(#) int cx, cy, radius, intensity;
8
* @(#) Return -1 on error 0 on sucess.
10
* Copyright 1990, N. Dessipris.
13
* Written on 30/05/1990
16
* - im_incheck() call added
18
* - im_incheck() changed to im_makerw()
20
* - im_invalidate() after paint
22
* - don't im_invalidate() after paint, this now needs to be at a higher
28
This file is part of VIPS.
30
VIPS is free software; you can redistribute it and/or modify
31
it under the terms of the GNU Lesser General Public License as published by
32
the Free Software Foundation; either version 2 of the License, or
33
(at your option) any later version.
35
This program is distributed in the hope that it will be useful,
36
but WITHOUT ANY WARRANTY; without even the implied warranty of
37
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38
GNU Lesser General Public License for more details.
40
You should have received a copy of the GNU Lesser General Public License
41
along with this program; if not, write to the Free Software
42
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
48
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
54
#endif /*HAVE_CONFIG_H*/
55
#include <vips/intl.h>
61
#include <vips/vips.h>
65
#endif /*WITH_DMALLOC*/
68
im_circle( IMAGE *im, int cx, int cy, int radius, int intensity )
74
if( im_rwcheck( im ) )
78
if ( (im->data == NULL)||(im->BandFmt != IM_BANDFMT_UCHAR)||
81
im_error("im_circle: ", "%s", _( "able to write input image") );
84
if ((intensity > 255)||(intensity <= 0))
86
im_error( "im_circle", "%s", _( "intensity between 0 and 255") );
89
/* Check if circle fits into image */
90
if ( ((radius+cy)> im->Ysize - 1) || ((cy-radius)< 0 ) ||
91
((radius+cx)> im->Xsize - 1) || ((cx-radius) < 0 ) )
93
im_error( "im_circle", "%s", _( "The circle does not fit in image") );
98
start = (PEL*)im->data;
99
offset = cy * im->Xsize + cx; /* point at the center of the circle */
105
*(start + offset + size * y + x) = (PEL)intensity;
106
*(start + offset + size * x + y) = (PEL)intensity;
107
*(start + offset + size * y - x) = (PEL)intensity;
108
*(start + offset + size * x - y) = (PEL)intensity;
109
*(start + offset - size * y - x) = (PEL)intensity;
110
*(start + offset - size * x - y) = (PEL)intensity;
111
*(start + offset - size * y + x) = (PEL)intensity;
112
*(start + offset - size * x + y) = (PEL)intensity;
117
d += ( 4 * ( x - y ) + 10 );
124
*(start + offset + size * y + x) = (PEL)intensity;
125
*(start + offset + size * x + y) = (PEL)intensity;
126
*(start + offset + size * y - x) = (PEL)intensity;
127
*(start + offset + size * x - y) = (PEL)intensity;
128
*(start + offset - size * y - x) = (PEL)intensity;
129
*(start + offset - size * x - y) = (PEL)intensity;
130
*(start + offset - size * y + x) = (PEL)intensity;
131
*(start + offset - size * x + y) = (PEL)intensity;