-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcolor.c
executable file
·401 lines (378 loc) · 11 KB
/
color.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
/*
* by DJ0ABR
*
* assign colors to each pixel of the waterfall
*
* */
#include <gd.h>
#include <math.h>
#include "color.h"
#include "gdfontt.h"
#include "gdfonts.h"
#include "gdfontmb.h"
#include "gdfontl.h"
#include "gdfontg.h"
#include "config.h"
double coltab[256][3] = {
{0.5000,0.7000,1.0000},
{0.6000,0.9000,1.0000},
{0.0000,0.0000,1.0000},
{0.0157,0.0000,0.0000},
{0.0235,0.0000,0.0000},
{0.0314,0.0000,0.0000},
{0.0392,0.0000,0.0000},
{0.0471,0.0000,0.0000},
{0.0549,0.0000,0.0000},
{0.0627,0.0000,0.0000},
{0.0706,0.0000,0.0000},
{0.0784,0.0000,0.0000},
{0.0863,0.0000,0.0000},
{0.0941,0.0000,0.0000},
{0.1020,0.0000,0.0000},
{0.1098,0.0000,0.0000},
{0.1176,0.0000,0.0000},
{0.1255,0.0000,0.0000},
{0.1333,0.0000,0.0000},
{0.1412,0.0000,0.0000},
{0.1490,0.0000,0.0000},
{0.1569,0.0000,0.0000},
{0.1647,0.0000,0.0000},
{0.1725,0.0000,0.0000},
{0.1804,0.0000,0.0000},
{0.1882,0.0000,0.0000},
{0.1961,0.0000,0.0000},
{0.2039,0.0000,0.0000},
{0.2118,0.0000,0.0000},
{0.2196,0.0000,0.0000},
{0.2275,0.0000,0.0000},
{0.2353,0.0000,0.0000},
{0.2431,0.0000,0.0000},
{0.2510,0.0000,0.0000},
{0.2588,0.0000,0.0000},
{0.2667,0.0000,0.0000},
{0.2745,0.0000,0.0000},
{0.2824,0.0000,0.0000},
{0.2902,0.0000,0.0000},
{0.2980,0.0000,0.0000},
{0.3059,0.0000,0.0000},
{0.3137,0.0000,0.0000},
{0.3216,0.0000,0.0000},
{0.3294,0.0000,0.0000},
{0.3373,0.0000,0.0000},
{0.3451,0.0000,0.0000},
{0.3529,0.0000,0.0000},
{0.3608,0.0000,0.0000},
{0.3686,0.0000,0.0000},
{0.3765,0.0000,0.0000},
{0.3843,0.0000,0.0000},
{0.3922,0.0000,0.0000},
{0.4000,0.0000,0.0000},
{0.4078,0.0000,0.0000},
{0.4157,0.0000,0.0000},
{0.4235,0.0000,0.0000},
{0.4314,0.0000,0.0000},
{0.4392,0.0000,0.0000},
{0.4471,0.0000,0.0000},
{0.4549,0.0000,0.0000},
{0.4627,0.0000,0.0000},
{0.4706,0.0000,0.0000},
{0.4784,0.0000,0.0000},
{0.4863,0.0000,0.0000},
{0.4941,0.0000,0.0000},
{0.5020,0.0000,0.0000},
{0.5098,0.0098,0.0000},
{0.5176,0.0176,0.0000},
{0.5255,0.0255,0.0000},
{0.5333,0.0333,0.0000},
{0.5412,0.0412,0.0000},
{0.5490,0.0490,0.0000},
{0.5569,0.0569,0.0000},
{0.5647,0.0647,0.0000},
{0.5725,0.0725,0.0000},
{0.5804,0.0804,0.0000},
{0.5882,0.0882,0.0000},
{0.5961,0.0961,0.0000},
{0.6039,0.1039,0.0000},
{0.6118,0.1118,0.0000},
{0.6196,0.1196,0.0000},
{0.6275,0.1275,0.0000},
{0.6353,0.1353,0.0000},
{0.6431,0.1431,0.0000},
{0.6510,0.1510,0.0000},
{0.6588,0.1588,0.0000},
{0.6667,0.1667,0.0000},
{0.6745,0.1745,0.0000},
{0.6824,0.1824,0.0000},
{0.6902,0.1902,0.0000},
{0.6980,0.1980,0.0000},
{0.7059,0.2059,0.0000},
{0.7137,0.2137,0.0000},
{0.7216,0.2216,0.0000},
{0.7294,0.2294,0.0000},
{0.7373,0.2373,0.0000},
{0.7451,0.2451,0.0000},
{0.7529,0.2529,0.0000},
{0.7608,0.2608,0.0000},
{0.7686,0.2686,0.0000},
{0.7765,0.2765,0.0000},
{0.7843,0.2843,0.0000},
{0.7922,0.2922,0.0000},
{0.8000,0.3000,0.0000},
{0.8078,0.3078,0.0000},
{0.8157,0.3157,0.0000},
{0.8235,0.3235,0.0000},
{0.8314,0.3314,0.0000},
{0.8392,0.3392,0.0000},
{0.8471,0.3471,0.0000},
{0.8549,0.3549,0.0000},
{0.8627,0.3627,0.0000},
{0.8706,0.3706,0.0000},
{0.8784,0.3784,0.0000},
{0.8863,0.3863,0.0000},
{0.8941,0.3941,0.0000},
{0.9020,0.4020,0.0000},
{0.9098,0.4098,0.0000},
{0.9176,0.4176,0.0000},
{0.9255,0.4255,0.0000},
{0.9333,0.4333,0.0000},
{0.9412,0.4412,0.0000},
{0.9490,0.4490,0.0000},
{0.9569,0.4569,0.0000},
{0.9647,0.4647,0.0000},
{0.9725,0.4725,0.0000},
{0.9804,0.4804,0.0000},
{0.9882,0.4882,0.0000},
{0.9961,0.4961,0.0000},
{1.0000,0.5039,0.0000},
{1.0000,0.5118,0.0118},
{1.0000,0.5196,0.0196},
{1.0000,0.5275,0.0275},
{1.0000,0.5353,0.0353},
{1.0000,0.5431,0.0431},
{1.0000,0.5510,0.0510},
{1.0000,0.5588,0.0588},
{1.0000,0.5667,0.0667},
{1.0000,0.5745,0.0745},
{1.0000,0.5824,0.0824},
{1.0000,0.5902,0.0902},
{1.0000,0.5980,0.0980},
{1.0000,0.6059,0.1059},
{1.0000,0.6137,0.1137},
{1.0000,0.6216,0.1216},
{1.0000,0.6294,0.1294},
{1.0000,0.6373,0.1373},
{1.0000,0.6451,0.1451},
{1.0000,0.6529,0.1529},
{1.0000,0.6608,0.1608},
{1.0000,0.6686,0.1686},
{1.0000,0.6765,0.1765},
{1.0000,0.6843,0.1843},
{1.0000,0.6922,0.1922},
{1.0000,0.7000,0.2000},
{1.0000,0.7078,0.2078},
{1.0000,0.7157,0.2157},
{1.0000,0.7235,0.2235},
{1.0000,0.7314,0.2314},
{1.0000,0.7392,0.2392},
{1.0000,0.7471,0.2471},
{1.0000,0.7549,0.2549},
{1.0000,0.7627,0.2627},
{1.0000,0.7706,0.2706},
{1.0000,0.7784,0.2784},
{1.0000,0.7863,0.2863},
{1.0000,0.7941,0.2941},
{1.0000,0.8020,0.3020},
{1.0000,0.8098,0.3098},
{1.0000,0.8176,0.3176},
{1.0000,0.8255,0.3255},
{1.0000,0.8333,0.3333},
{1.0000,0.8412,0.3412},
{1.0000,0.8490,0.3490},
{1.0000,0.8569,0.3569},
{1.0000,0.8647,0.3647},
{1.0000,0.8725,0.3725},
{1.0000,0.8804,0.3804},
{1.0000,0.8882,0.3882},
{1.0000,0.8961,0.3961},
{1.0000,0.9039,0.4039},
{1.0000,0.9118,0.4118},
{1.0000,0.9196,0.4196},
{1.0000,0.9275,0.4275},
{1.0000,0.9353,0.4353},
{1.0000,0.9431,0.4431},
{1.0000,0.9510,0.4510},
{1.0000,0.9588,0.4588},
{1.0000,0.9667,0.4667},
{1.0000,0.9745,0.4745},
{1.0000,0.9824,0.4824},
{1.0000,0.9902,0.4902},
{1.0000,0.9980,0.4980},
{1.0000,1.0000,0.5059},
{1.0000,1.0000,0.5137},
{1.0000,1.0000,0.5216},
{1.0000,1.0000,0.5294},
{1.0000,1.0000,0.5373},
{1.0000,1.0000,0.5451},
{1.0000,1.0000,0.5529},
{1.0000,1.0000,0.5608},
{1.0000,1.0000,0.5686},
{1.0000,1.0000,0.5765},
{1.0000,1.0000,0.5843},
{1.0000,1.0000,0.5922},
{1.0000,1.0000,0.6000},
{1.0000,1.0000,0.6078},
{1.0000,1.0000,0.6157},
{1.0000,1.0000,0.6235},
{1.0000,1.0000,0.6314},
{1.0000,1.0000,0.6392},
{1.0000,1.0000,0.6471},
{1.0000,1.0000,0.6549},
{1.0000,1.0000,0.6627},
{1.0000,1.0000,0.6706},
{1.0000,1.0000,0.6784},
{1.0000,1.0000,0.6863},
{1.0000,1.0000,0.6941},
{1.0000,1.0000,0.7020},
{1.0000,1.0000,0.7098},
{1.0000,1.0000,0.7176},
{1.0000,1.0000,0.7255},
{1.0000,1.0000,0.7333},
{1.0000,1.0000,0.7412},
{1.0000,1.0000,0.7490},
{1.0000,1.0000,0.7569},
{1.0000,1.0000,0.7647},
{1.0000,1.0000,0.7725},
{1.0000,1.0000,0.7804},
{1.0000,1.0000,0.7882},
{1.0000,1.0000,0.7961},
{1.0000,1.0000,0.8039},
{1.0000,1.0000,0.8118},
{1.0000,1.0000,0.8196},
{1.0000,1.0000,0.8275},
{1.0000,1.0000,0.8353},
{1.0000,1.0000,0.8431},
{1.0000,1.0000,0.8510},
{1.0000,1.0000,0.8588},
{1.0000,1.0000,0.8667},
{1.0000,1.0000,0.8745},
{1.0000,1.0000,0.8824},
{1.0000,1.0000,0.8902},
{1.0000,1.0000,0.8980},
{1.0000,1.0000,0.9059},
{1.0000,1.0000,0.9137},
{1.0000,1.0000,0.9216},
{1.0000,1.0000,0.9294},
{1.0000,1.0000,0.9373},
{1.0000,1.0000,0.9451},
{1.0000,1.0000,0.9529},
{1.0000,1.0000,0.9608},
{1.0000,1.0000,0.9686},
{1.0000,1.0000,0.9765},
{ 1.0,0.0,0.0},
{ 1.0,0.0,0.0}
};
// allocate the color table
void allocatePalette(gdImagePtr img)
{
// low values blue only
for(int i=0; i<256; i++)
{
gdImageColorAllocate(img, (int)(coltab[i][0] * 255), (int)(coltab[i][1] * 255),(int)(coltab[i][2] * 255));
}
}
#define ARRMIDLEN 20
struct {
double cmaxvalarr[ARRMIDLEN];
double cminvalarr[ARRMIDLEN];
double cmaxval;
double cminval;
double hWFrefval; // shifts the black value (higher=darker)
double hWFgain; // contrast (must be > 0, low=high contrast)
double minlog;
double factor;
} colordef[10];
// find min/max the values of one pixel line
void calcColorParms(int id, int fstart, int fend, double *d)
{
double max = -9999;
double min = 9999;
static int f[10] = {1,1,1,1,1,1,1,1,1,1};
colordef[id].hWFrefval = hWFrefval; //150; // shifts the black value (higher=darker)
colordef[id].hWFgain = (double)hWFgain/100.0; //0.00001;
if(hWFgain == 0) colordef[id].hWFgain = 0.00001;
for(int i=fstart; i<fend; i++)
{
// d[i] is the dBm value at the antenna input (if calibrated and AGC off)
// it is a negative value, max range: -180 ... 0
double da = d[i];
if(da < min) min = da;
if(da > max) max = da;
}
if(f[id])
{
// init array
f[id]=0;
for(int i=0; i<ARRMIDLEN; i++)
{
colordef[id].cminvalarr[i] = min;
colordef[id].cmaxvalarr[i] = max;
}
}
// insert into mid array
for(int i=(ARRMIDLEN-1); i>=1; i--)
{
colordef[id].cminvalarr[i] = colordef[id].cminvalarr[i-1];
colordef[id].cmaxvalarr[i] = colordef[id].cmaxvalarr[i-1];
}
colordef[id].cminvalarr[0] = min;
colordef[id].cmaxvalarr[0] = max;
colordef[id].cminval = 0;
colordef[id].cmaxval = 0;
for(int i=0; i<ARRMIDLEN; i++)
{
colordef[id].cminval += colordef[id].cminvalarr[i];
colordef[id].cmaxval += colordef[id].cmaxvalarr[i];
}
colordef[id].cminval /= ARRMIDLEN;
colordef[id].cmaxval /= ARRMIDLEN;
//printf("min:%.1f max:%.1f\r\n",colordef[id].cminval,colordef[id].cmaxval);
// prepare values used my getPixelColor
colordef[id].factor = colordef[id].hWFgain/10;
colordef[id].minlog = log(colordef[id].factor + 1) / 255;
}
int getPixelColor(int id, double val)
{
//printf("%.1f:",val);
if(hWFauto)
{
// === black value, no signal, background noise ===
// shift the value up, so that cminval is color=0
val -= colordef[id].cminval;
val -= (colordef[id].hWFrefval/10);
// === max level, strongest signal ===
// make the loudest signal to 255
// shift cmaxval the same factor as the signal value, so both start at 0
double cmax = (colordef[id].cmaxval - colordef[id].cminval);
// expand the signal value so that the maxval is 255
// do this with a log formular, high values are more effected
double lin = val * colordef[id].factor / cmax;
double revlin = colordef[id].factor - lin + 1;
double mylog = log(revlin);
double logTo255 = mylog/ colordef[id].minlog;
double val1 = 255 - logTo255;
int v = (int)val1;
//printf("%d ",v);
// low colors reserver for other purposes
if (v <= 2) v = 3;
if (v > 250) v = 255;
return v;
}
// schiebe den Nullpunkt auf den gewünschten Zero
double val1 = val - hWFrefval;
// mache den Gain, zeige die max. dBm bei 255 an
int v = (int)(val1 * hWFgain / 10.0);
// colors < 3 are for other purposes (spectrum)
if (v <= 2) v = 3;
if (v > 255) v = 255;
return v;
}