forked from ghewgill/xearth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xearth.h
399 lines (347 loc) · 11.2 KB
/
xearth.h
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
/*
* xearth.h
* kirk johnson
* july 1993
*
* Copyright (C) 1989, 1990, 1993-1995, 1999 Kirk Lauritz Johnson
*
* Parts of the source code (as marked) are:
* Copyright (C) 1989, 1990, 1991 by Jim Frost
* Copyright (C) 1992 by Jamie Zawinski <[email protected]>
*
* Permission to use, copy, modify and freely distribute xearth for
* non-commercial and not-for-profit purposes is hereby granted
* without fee, provided that both the above copyright notice and this
* permission notice appear in all copies and in supporting
* documentation.
*
* Unisys Corporation holds worldwide patent rights on the Lempel Zev
* Welch (LZW) compression technique employed in the CompuServe GIF
* image file format as well as in other formats. Unisys has made it
* clear, however, that it does not require licensing or fees to be
* paid for freely distributed, non-commercial applications (such as
* xearth) that employ LZW/GIF technology. Those wishing further
* information about licensing the LZW patent should contact Unisys
* directly at ([email protected]) or by writing to
*
* Unisys Corporation
* Welch Licensing Department
* M/S-C1SW19
* P.O. Box 500
* Blue Bell, PA 19424
*
* The author makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*
* THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT
* OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef _XEARTH_H_
#define _XEARTH_H_
#ifdef HAVE_X11
#include <X11/Xos.h>
#else
typedef unsigned char u_char;
typedef unsigned short u_short;
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include <time.h>
#include <unistd.h>
#include "port.h"
#include "extarr.h"
#include "kljcpyrt.h"
#define VersionString "1.1"
#define HomePageURL "http://www.cs.colorado.edu/~tuna/xearth/index.html"
/* if NO_RANDOM is defined, use lrand48() and srand48()
* instead of random() and srandom()
*/
#ifdef NO_RANDOM
#define random() lrand48()
#define srandom(x) srand48((long) (x))
#endif /* NO_RANDOM */
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif /* !M_PI */
#define MAX_OVERLAY 5
/* a particularly large number
*/
#define BigNumber (1e6)
/* rotational period of the earth (seconds)
*/
#define EarthPeriod (86400)
/* default width and height, if not otherwise specified
*/
#define DefaultWdthHght (512)
/* default border width, if not otherwise specified
*/
#define DefaultBorderWidth (1)
/* types of pixels
*/
#define PixTypeSpace (0x80000000) /* black */
#define PixTypeLand (0x8100ff00) /* green */
#define PixTypeWater (0x820000ff) /* blue */
#define PixTypeStar (0x83ffffff) /* white */
#define PixTypeGridLand (0x84ffffff) /* white */
#define PixTypeGridWater (0x85ffffff) /* white */
#define PixRed(p) (((p) >> 16) & 0xff)
#define PixGreen(p) (((p) >> 8) & 0xff)
#define PixBlue(p) (((p) ) & 0xff)
#define PixRGB(r,g,b) ((((r) & 0xff) << 16) | (((g) & 0xff) << 8) | ((b) & 0xff))
/* types of dots
*/
#define DotTypeStar (0)
#define DotTypeGrid (1)
/* types of viewing positions
*/
#define ViewPosTypeFixed (0)
#define ViewPosTypeSun (1)
#define ViewPosTypeOrbit (2)
#define ViewPosTypeRandom (3)
#define ViewPosTypeMoon (4)
/* types of viewing rotations
*/
#define ViewRotNorth (0)
#define ViewRotGalactic (1)
/* types of projections
*/
#define ProjTypeOrthographic (0)
#define ProjTypeMercator (1)
#define ProjTypeCylindrical (2)
/* types of marker label alignment
*/
#define MarkerAlignDefault (0)
#define MarkerAlignLeft (1)
#define MarkerAlignRight (2)
#define MarkerAlignAbove (3)
#define MarkerAlignBelow (4)
/* true color indicator
* (actually is the number of colors in 24 bits)
*/
#define TRUE_COLOR (0x1000000)
/* vector rotation
*/
#define XFORM_ROTATE(p,vpi) \
do { \
double _p0_, _p1_, _p2_; \
double _c_, _s_, _t_; \
_p0_ = p[0]; \
_p1_ = p[1]; \
_p2_ = p[2]; \
_c_ = vpi.cos_lon; \
_s_ = vpi.sin_lon; \
_t_ = (_c_ * _p0_) - (_s_ * _p2_); \
_p2_ = (_s_ * _p0_) + (_c_ * _p2_); \
_p0_ = _t_; \
_c_ = vpi.cos_lat; \
_s_ = vpi.sin_lat; \
_t_ = (_c_ * _p1_) - (_s_ * _p2_); \
_p2_ = (_s_ * _p1_) + (_c_ * _p2_); \
_p1_ = _t_; \
_c_ = vpi.cos_rot; \
_s_ = vpi.sin_rot; \
_t_ = (_c_ * _p0_) - (_s_ * _p1_); \
_p1_ = (_s_ * _p0_) + (_c_ * _p1_); \
_p0_ = _t_; \
p[0] = _p0_; \
p[1] = _p1_; \
p[2] = _p2_; \
} while (0)
/* mercator projection (xyz->xy)
* [the argument to MERCATOR_Y() is thresholded against 0.9999999999
* and -0.9999999999 instead of 1.0 and -1.0 to avoid numerical
* difficulties that can arise when the argument of tan() gets close
* to PI/2; thanks to Bill Leonard for helping debug this.]
*/
#define MERCATOR_X(x, z) (atan2((x), (z)))
#define MERCATOR_Y(y) (((y) >= 0.9999999999) ? (BigNumber) \
: (((y) <= -0.9999999999) ? (-BigNumber) \
: log(tan((asin(y)/2) + (M_PI/4)))))
#define INV_MERCATOR_Y(y) (sin(2 * (atan(exp(y)) - (M_PI/4))))
/* cylindrical projection (xyz->xy)
*/
#define CYLINDRICAL_X(x, z) (atan2((x), (z)))
#define CYLINDRICAL_Y(y) (((y) >= 0.9999999999) ? (BigNumber) \
: (((y) <= -0.9999999999) ? (-BigNumber) \
: (tan(asin(y)))))
#define INV_CYLINDRICAL_Y(y) (sin(atan(y)))
/* xy->screen projections
*/
#define XPROJECT(x) ((proj_info.proj_scale*(x))+proj_info.proj_xofs)
#define YPROJECT(y) (proj_info.proj_yofs-(proj_info.proj_scale*(y)))
#define INV_XPROJECT(x) (((x)-proj_info.proj_xofs)*proj_info.inv_proj_scale)
#define INV_YPROJECT(y) ((proj_info.proj_yofs-(y))*proj_info.inv_proj_scale)
typedef int s8or32;
typedef unsigned u8or32;
typedef int s16or32;
typedef unsigned u16or32;
typedef struct
{
double cos_lat, sin_lat; /* cos/sin of view_lat */
double cos_lon, sin_lon; /* cos/sin of view_lon */
double cos_rot, sin_rot; /* cos/sin of view_rot */
} ViewPosInfo;
typedef struct
{
double proj_scale;
double proj_xofs;
double proj_yofs;
double inv_proj_scale;
} ProjInfo;
typedef struct
{
short y;
short lo_x;
short hi_x;
short val;
} ScanBit;
typedef struct
{
short x;
short y;
u_char type;
} ScanDot;
typedef struct
{
float lat;
float lon;
char *label;
int align;
} MarkerInfo;
/* bmp.c */
extern void bmp_output _P((void));
/* dither.c */
extern int dither_ncolors;
extern u_char *dither_colormap;
extern void dither_setup _P((int));
extern void dither_row _P((u_char *, u16or32 *));
extern void dither_cleanup _P((void));
extern void mono_dither_setup _P((void));
extern void mono_dither_row _P((u_char *, u16or32 *));
extern void mono_dither_cleanup _P((void));
/* font.c */
extern void font_extent _P((const char *, int *, int *));
extern void font_draw _P((int, int, const char *, ExtArr));
/* gif.c */
extern void gif_output _P((void));
/* jpeg.c */
extern void jpeg_output _P((void));
/* mapdata.c */
extern short map_data[];
/* markers.c */
extern MarkerInfo *marker_info;
extern void load_marker_info _P((char *));
extern void show_marker_info _P((char *));
/* overlay.c */
extern void overlay_init _P((void));
extern int map_pixel _P((double, double));
extern int overlay_pixel _P((double, double, int));
extern void overlay_close _P((void));
/* png.c */
extern void png_output _P((void));
/* ppm.c */
extern void ppm_output _P((void));
/* render.c */
extern void render _P((int (*)(u_char *)));
extern void do_dots _P((void));
/* resources.c */
extern char *get_string_resource _P((const char *, const char *));
extern int get_boolean_resource _P((const char *, const char *));
extern int get_integer_resource _P((const char *, const char *));
extern double get_float_resource _P((const char *, const char *));
extern unsigned int get_pixel_resource _P((const char *, const char *));
/* scan.c */
extern ViewPosInfo view_pos_info;
extern ProjInfo proj_info;
extern ExtArr scanbits;
extern void scan_map _P((void));
/* sunpos.c */
extern void sun_position _P((time_t, double *, double *));
extern void moon_position _P((time_t, double *, double *));
/* x11.c */
extern void command_line_x _P((int, char *[]));
extern void x11_output _P((void));
/* xearth.c */
extern char *progname;
extern int proj_type;
extern double view_lon;
extern double view_lat;
extern double view_rot;
extern double view_mag;
extern int do_shade;
extern double sun_lon;
extern double sun_lat;
extern int wdth;
extern int hght;
extern int shift_x;
extern int shift_y;
extern int do_stars;
extern double star_freq;
extern int big_stars;
extern int do_grid;
extern int grid_big;
extern int grid_small;
extern int do_label;
extern int do_markers;
extern char *markerfile;
extern char *mapfile;
extern char *overlayfile[MAX_OVERLAY];
extern int overlay_count;
extern int wait_time;
extern double time_warp;
extern int fixed_time;
extern int day;
extern int night;
extern int terminator;
extern double xgamma;
extern int use_two_pixmaps;
extern int num_colors;
extern int do_fork;
extern int priority;
extern time_t current_time;
extern void compute_positions _P((void));
extern char **tokenize _P((char *, int *, const char **));
extern void decode_proj_type _P((char *));
extern void decode_rotation _P((char *));
extern void decode_viewing_pos _P((char *));
extern void decode_sun_pos _P((char *));
extern void decode_size _P((char *));
extern void decode_shift _P((char *));
extern void decode_colors _P((char *));
extern void decode_overlay _P((char *));
extern void xearth_bzero _P((char *, unsigned));
extern void version_info _P((int));
extern void usage _P((const char *)) _noreturn;
extern void warning _P((const char *));
extern void fatal _P((const char *)) _noreturn;
#ifdef USE_EXACT_SQRT
#define SQRT(x) (((x) <= 0.0) ? (0.0) : (sqrt(x)))
#else
/*
* brute force approximation for sqrt() over [0,1]
* - two quadratic regions
* - returns zero for args less than zero
*/
#define SQRT(x) \
(((x) > 0.13) \
? ((((-0.3751672414*(x))+1.153263483)*(x))+0.2219037586) \
: (((x) > 0.0) \
? ((((-9.637346154*(x))+3.56143)*(x))+0.065372935) \
: (0.0)))
#endif /* USE_EXACT_SQRT */
#ifndef isupper
# define isupper(c) ((c) >= 'A' && (c) <= 'Z')
#endif
#ifndef _tolower
# define _tolower(c) ((c) - 'A' + 'a')
#endif
#endif