public software.sextractor

[/] [trunk/] [src/] [graph.c] - Blame information for rev 235

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 233 bertin
/*
2
*                               graph.c
3 2 bertin
*
4 233 bertin
* Add simple graphics to image rasters.
5 2 bertin
*
6 233 bertin
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 2 bertin
*
8 233 bertin
*       This file part of:      SExtractor
9 2 bertin
*
10 235 bertin
*       Copyright:              (C) 1993-2010 Emmanuel Bertin -- IAP/CNRS/UPMC
11 2 bertin
*
12 233 bertin
*       License:                GNU General Public License
13
*
14
*       SExtractor is free software: you can redistribute it and/or modify
15
*       it under the terms of the GNU General Public License as published by
16
*       the Free Software Foundation, either version 3 of the License, or
17
*       (at your option) any later version.
18
*       SExtractor is distributed in the hope that it will be useful,
19
*       but WITHOUT ANY WARRANTY; without even the implied warranty of
20
*       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
*       GNU General Public License for more details.
22
*       You should have received a copy of the GNU General Public License
23
*       along with SExtractor. If not, see <http://www.gnu.org/licenses/>.
24
*
25
*       Last modified:          11/10/2010
26
*
27
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
28 2 bertin
 
29
#ifdef HAVE_CONFIG_H
30
#include        "config.h"
31
#endif
32
 
33
#include        <math.h>
34
#include        <stdlib.h>
35
 
36
#include        "define.h"
37
#include        "globals.h"
38
 
39
double  sexx1, sexy1;
40
 
41
/********************************* sexmove **********************************/
42
/*
43
Move function (related to sexdraw)..
44
*/
45
void    sexmove(double x, double y)
46
 
47
  {
48
  sexx1 = x;
49
  sexy1 = y;
50
 
51
  return;
52
  }
53
 
54
 
55
/********************************* sexdraw **********************************/
56
/*
57
Draw a line in a PIXTYPE bitmap.
58
*/
59
void    sexdraw(PIXTYPE *bmp, int w, int h, double sexx2, double sexy2,
60
                PIXTYPE val)
61
 
62
  {
63
   double       dx,dy, slope;
64
   int          ix1,iy1, ix2,iy2, ix,iy;
65
 
66
  dx = sexx2-sexx1;
67
  dy = sexy2-sexy1;
68
  if (fabs(dx) > fabs(dy))
69
    {
70
    slope = dy/dx;
71
    ix1 = RINT(sexx1);
72
    ix2 = RINT(sexx2);
73
    if (ix2>ix1)
74
      {
75
      for (ix=ix1+1; ix<=ix2; ix++)
76
        if (ix>=0 && ix<w)
77
          {
78
          iy = RINT(sexy1+(ix-sexx1)*slope);
79
          if (iy>=0 && iy<h)
80
            bmp[ix+w*iy] += val;
81
          }
82
      }
83
    else
84
      {
85
      for (ix=ix1-1; ix>=ix2; ix--)
86
        if (ix>=0 && ix<w)
87
          {
88
          iy = RINT(sexy1+(ix-sexx1)*slope);
89
          if (iy>=0 && iy<h)
90
            bmp[ix+w*iy] += val;
91
          }
92
      }
93
    }
94
  else
95
    {
96
    slope = dx/(dy == 0.0? 1.0:dy);
97
    iy1 = RINT(sexy1);
98
    iy2 = RINT(sexy2);
99
    if (iy2>iy1)
100
      {
101
      for (iy=iy1+1; iy<=iy2; iy++)
102
        if (iy>=0 && iy<h)
103
          {
104
          ix = RINT(sexx1+(iy-sexy1)*slope);
105
          if (ix>=0 && ix<w)
106
            bmp[ix+w*iy] += val;
107
          }
108
      }
109
    else
110
      for (iy=iy1-1; iy>=iy2; iy--)
111
        {
112
        if (iy>=0 && iy<h)
113
          {
114
          ix = RINT(sexx1+(iy-sexy1)*slope);
115
          if (ix>=0 && ix<w)
116
            bmp[ix+w*iy] += val;
117
          }
118
        }
119
    }
120
 
121
  sexx1 = sexx2;
122
  sexy1 = sexy2;
123
  return;
124
  }
125
 
126
 
127
/******************************** sexcircle *********************************/
128
/*
129
Draw a circle in a PIXTYPE bitmap.
130
*/
131
void    sexcircle(PIXTYPE *bmp, int w, int h, double x, double y, double r,
132
                PIXTYPE val)
133
 
134
  {
135
   int i;
136
 
137
  sexmove(x+r, y);
138
  for (i=0; i<37; i++)
139
    sexdraw(bmp,w,h, x+r*ctg[i], y+r*stg[i], val);
140
 
141
  return;
142
  }
143
 
144
 
145
/******************************** sexellips *********************************/
146
/*
147
Draw an ellips in a PIXTYPE bitmap.
148
*/
149
void    sexellips(PIXTYPE *bmp, int w, int h, double x, double y, double a,
150
                double b, double theta, PIXTYPE val, int dotflag)
151
 
152
  {
153
   int          i;
154
   double       ct, st;
155
 
156
  ct = cos(PI*theta/180);
157
  st = sin(PI*theta/180);
158
 
159
  sexmove(x+a*ct, y+a*st);
160
  for (i=1; i<37; i++)
161
    if (dotflag && !(i&1))
162
      sexmove(x + a*ctg[i]*ct - b*stg[i]*st,
163
                y + a*ctg[i]*st + b*stg[i]*ct);
164
    else
165
      sexdraw(bmp,w,h, x + a*ctg[i]*ct - b*stg[i]*st,
166
                y + a*ctg[i]*st + b*stg[i]*ct, val);
167
 
168
  return;
169
  }
170