Multi-ApplicationOnlineProfiling  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Color_Scales.h
Go to the documentation of this file.
1 #ifndef COLOR_SCALE_H
2 #define COLOR_SCALE_H
3 
4 
5 typedef enum
6 {
17 
18 
19 static const char * const Color_Scale_names[SCALE_COUNT] =
20 {
21  "temperature",
22  "fire",
23  "ice",
24  "greyscale",
25  "three levels",
26  "three levels linear",
27  "three levels linear narrow",
28  "good and evil"
29 };
30 
31 
33 
34 
39 struct Color {
40  int r;
41  int g;
42  int b;
43 };
44 
45 
46 
47 
54 static inline void factor_to_color( struct Color *col, double factor, Color_Scale_t scale_type )
55 {
56  double h=factor * 255;
57  double f = 0;
58 
59  switch( scale_type ) {
60  case SCALE_TEMPERATURE : // TEMPERATURE
61  if ( h < 60 ) {
62  f = h /60.0;
63  col->b = 255;
64 
65  col->g = f * 255;
66  col->r = 0;
67 
68  }
69 
70  if ( 60 < h && h <= 120 ) {
71  f = (h /60.0) - 1;
72  col->b = (1 -f) *255;
73  col->g = 255;
74  col->r = 0;
75 
76  }
77 
78  if ( 120 < h && h <= 180 ) {
79  f = (h /60.0) - 2;
80  col->b = 0;
81  col->g = 255;
82  col->r = f * 255;
83 
84  }
85 
86  if ( h > 180) {
87  f = ((h /60.0) - 3)/1.25;
88  col->b = 0;
89  col->g = (1-f)*255;
90  col->r = 255;
91 
92  }
93  break;
94  case SCALE_FIRE : // FIRE
95  if( factor <= 0.5 ) {
96  col->r = 255 * factor;
97  col->g = 0;
98  col->b = 0;
99  } else {
100  col->r = 255 * factor;
101  col->g = (255 * (factor - 0.5)) * 1.8;
102  col->b = 0;
103  }
104  break;
105  case SCALE_ICE : // ICE
106  col->r = 0;
107  col->g = 255 * factor;
108  col->b = 255 * factor;
109  break;
110  case SCALE_GREYSCALE : //GREYSCALE
111  col->r = 255 * (1-factor);
112  col->g = 255 * (1-factor);
113  col->b = 255 * (1-factor);
114  break;
115  case SCALE_THREE_LVL : //THREE LEVELS STRICT
116  col->r = 0;
117  col->g = 0;
118  col->b = 0;
119 
120  if( factor < 0.3333 ) {
121  col->b = 255;
122  } else if( 0.6666 < factor ) {
123  col->r = 255;
124  } else {
125  col->r = 128;
126  col->g = 128;
127  col->b = 128;
128  }
129  break;
130  case SCALE_THREE_LVL_LINEAR : //THREE LEVELS LINEAR LARGE AVG
131  col->r = 0;
132  col->g = 0;
133  col->b = 0;
134 
135  if( factor < 0.3333 ) {
136  col->r = 0;
137  col->g = 0;
138  col->b = 255 * (1-(factor*3));
139  } else if( 0.6666 < factor ) {
140  col->r = 0;
141  col->g = 0;
142  col->r = 255 * (( factor - 0.6666 ) * 3);
143  } else {
144  col->r = 0;
145  col->g = 0;
146  col->b = 0;
147  }
148  break;
149  case SCALE_THREE_LVL_LINEAR_NARROW : //THREE LEVELS LINEAR NARROW AVG
150  col->r = 0;
151  col->g = 0;
152  col->b = 0;
153 
154  if( factor < 0.4705 ) {
155  col->r = 0;
156  col->g = 0;
157  col->b = 255 * (1-(factor*2.125));
158  } else if( 0.5294 < factor ) {
159  col->r = 0;
160  col->g = 0;
161  col->r = 255 * (( factor - 0.5294 ) * 2.125);
162  } else {
163  col->r = 0;
164  col->g = 0;
165  col->b = 0;
166  }
167  break;
168  case SCALE_GOOD_AND_EVIL : //GOOD AND EVIL
169  col->r = 0;
170  col->g = 0;
171  col->b = 0;
172 
173  if( factor < 0.5 ) {
174  col->b = 255;
175  } else {
176  col->r = 255;
177  }
178 
179  break;
180  default :
181  f = 0;
182  }
183 
184 
185 }
186 
187 
188 
189 
190 
191 
192 
193 
194 
195 
196 
197 
198 
199 
200 
201 
202 
203 #endif /* COLOR_SCALE_H */
Color_Scale_t Color_Scale_from_name(char *name)
Definition: Color_Scales.c:7
static void factor_to_color(struct Color *col, double factor, Color_Scale_t scale_type)
factor_to_color
Definition: Color_Scales.h:54
Color structure containing RGB values.
Definition: Color_Scales.h:39
int r
Definition: Color_Scales.h:40
static const char *const Color_Scale_names[SCALE_COUNT]
Definition: Color_Scales.h:19
int b
Definition: Color_Scales.h:42
int g
Definition: Color_Scales.h:41
Color_Scale_t
Definition: Color_Scales.h:5