~ubuntu-branches/ubuntu/saucy/vips/saucy

« back to all changes in this revision

Viewing changes to libvips/inplace/im_circle.c

  • Committer: Bazaar Package Importer
  • Author(s): Jay Berkenbilt
  • Date: 2010-12-27 14:24:43 UTC
  • mfrom: (1.1.14 upstream) (2.1.10 sid)
  • Revision ID: james.westby@ubuntu.com-20101227142443-2o2fwf24zy0wkdo8
Tags: 7.24.1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
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)
5
 
 * @(#) IMAGE *pim;
6
 
 * @(#) int cx, cy, radius, intensity;
7
 
 * @(#)
8
 
 * @(#) Return -1 on error 0 on sucess.
9
 
 *
10
 
 * Copyright 1990, N. Dessipris.
11
 
 *
12
 
 * Author N. Dessipris
13
 
 * Written on 30/05/1990
14
 
 * Updated on:
15
 
 * 22/7/93 JC
16
 
 *      - im_incheck() call added
17
 
 * 16/8/94 JC
18
 
 *      - im_incheck() changed to im_makerw()
19
 
 * 5/12/06
20
 
 *      - im_invalidate() after paint
21
 
 * 6/3/10
22
 
 *      - don't im_invalidate() after paint, this now needs to be at a higher
23
 
 *        level
24
 
 */
25
 
 
26
 
/*
27
 
 
28
 
    This file is part of VIPS.
29
 
    
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.
34
 
 
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.
39
 
 
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
43
 
 
44
 
 */
45
 
 
46
 
/*
47
 
 
48
 
    These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
49
 
 
50
 
 */
51
 
 
52
 
#ifdef HAVE_CONFIG_H
53
 
#include <config.h>
54
 
#endif /*HAVE_CONFIG_H*/
55
 
#include <vips/intl.h>
56
 
 
57
 
#include <stdio.h>
58
 
#include <math.h>
59
 
#include <string.h>
60
 
 
61
 
#include <vips/vips.h>
62
 
 
63
 
#ifdef WITH_DMALLOC
64
 
#include <dmalloc.h>
65
 
#endif /*WITH_DMALLOC*/
66
 
 
67
 
int 
68
 
im_circle( IMAGE *im, int cx, int cy, int radius, int intensity )
69
 
{
70
 
        PEL *start;
71
 
        int size = 0;
72
 
        int x, y, d, offset;
73
 
 
74
 
        if( im_rwcheck( im ) )
75
 
                return( -1 );
76
 
 
77
 
/* Check args */
78
 
        if ( (im->data == NULL)||(im->BandFmt != IM_BANDFMT_UCHAR)||
79
 
           (im->Bands != 1))
80
 
                {
81
 
                im_error("im_circle: ", "%s", _( "able to write input image") );
82
 
                return(-1);
83
 
                }
84
 
        if ((intensity > 255)||(intensity <= 0))
85
 
                {
86
 
                im_error( "im_circle", "%s", _( "intensity between 0 and 255") );
87
 
                return(-1);
88
 
                }
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 )   )
92
 
                {
93
 
                im_error( "im_circle", "%s", _( "The circle does not fit in image") );
94
 
                return(-1);
95
 
                }
96
 
/* Draw the circle */
97
 
        size = im->Xsize;
98
 
        start = (PEL*)im->data;
99
 
        offset = cy * im->Xsize + cx; /* point at the center of the circle */
100
 
        x = 0;
101
 
        y = radius;
102
 
        d = 3 - 2 * radius;
103
 
        while ( x < y )
104
 
                {
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;
113
 
                if (d < 0 )
114
 
                        d += ( 4 * x + 6 );
115
 
                else
116
 
                        {
117
 
                        d += ( 4 * ( x - y ) + 10 );
118
 
                        y--;
119
 
                        }
120
 
                x++;
121
 
                }
122
 
        if ( x== y )
123
 
                {
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;
132
 
                }
133
 
 
134
 
        return(0);      
135
 
}