Imported Upstream version 4.6.0
[debian/atlc] / src / non_gui / calculate_colour_data.c
1 /* atlc - arbitrary transmission line calculator, for the analysis of
2 transmission lines are directional couplers. 
3
4 Copyright (C) 2002. Dr. David Kirkby, PhD (G8WRB).
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either package_version 2
9 of the License, or (at your option) any later package_version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
19 USA.
20
21 Dr. David Kirkby, e-mail drkirkby at ntlworld.com 
22
23 */
24 #include "config.h"
25
26 #ifdef HAVE_STRING_H
27 #include <string.h>
28 #endif
29
30 #ifdef HAVE_STRINGS_H
31 #include <strings.h>
32 #endif
33
34 #ifdef HAVE_STDLIB_h
35 #include <stdlib.h>
36 #endif
37
38 #ifdef HAVE_MATH_H
39 #include <math.h>
40 #endif
41
42 #include "definitions.h"
43
44 extern double **Vij;
45 extern double **Er;
46 extern unsigned char **oddity;
47
48 void calculate_colour_data(double x, double xmax, int w, int h, int offset, unsigned char *image_dat, int image_type,
49 unsigned char *red, unsigned char *green, unsigned char *blue, double image_fiddle_factor)
50 {
51   if(image_type==COLOUR) /*Ex, Ey, V */
52   {
53     if(fabs(x) < 1e-9) /* This is a bit of a fiddle I admit, but */
54     {                  /* Is needed to prevent problems at 'small' values */
55       *red=0;
56       *green=0;
57       *blue=0;
58     }
59     else if(x > 0.0)
60     {
61       *red=255*pow(x/xmax,1.0/image_fiddle_factor);
62       *green=0; 
63       *blue=0; 
64     }
65     else 
66     {
67       *red=0; 
68       *green=0; 
69       *blue=255*pow(-x/xmax,1.0/image_fiddle_factor); 
70     }
71   }
72   else if (image_type==MONOCHROME) /* E, energy, permittivity */
73   {
74     if(x > xmax)
75     {
76       *red=0; *green=0; *blue=0;
77     }
78     else
79     {
80       *red=255*pow(fabs(x/xmax),1.0/image_fiddle_factor);
81       *green=255*pow(fabs(x/xmax),1.0/image_fiddle_factor);
82       *blue=255*pow(fabs(x/xmax),1.0/image_fiddle_factor);
83      }
84   }
85   else if (image_type==MIXED) /* Only for permittivity*/
86   {
87     if(oddity[w][h]==CONDUCTOR_ZERO_V)
88     {
89       *red=0; *green=255; *blue=0;
90     }
91     else if(oddity[w][h]==CONDUCTOR_PLUS_ONE_V)
92     {
93       *red=255; *green=0; *blue=0;
94     }
95     else if(oddity[w][h]==CONDUCTOR_MINUS_ONE_V)
96     {
97       *red=0; *green=0; *blue=255;
98     }
99     else
100     {
101       *red=255*pow(fabs(x/xmax),1.0/image_fiddle_factor);
102       *green=255*pow(fabs(x/xmax),1.0/image_fiddle_factor);
103       *blue=255*pow(fabs(x/xmax),1.0/image_fiddle_factor);
104      }
105   }
106   image_dat[offset]=*blue; 
107   image_dat[offset+1]=*green; 
108   image_dat[offset+2]=*red; 
109 }