-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckmap.c
92 lines (80 loc) · 2.1 KB
/
checkmap.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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "lodepng/lodepng.h"
#include "transform.h"
static void checktransform(unsigned int *image, unsigned width, unsigned height) {
for (double lon = 6.0; lon < 16.0; lon += 1.0/60) {
int x = fix2x(50.0, lon);
int y = fix2y(50.0, lon);
unsigned int *p = image + (y * width + x);
*p = 0xFFFFFFFF;
x = fix2x(45.0, lon);
y = fix2y(45.0, lon);
p = image + (y * width + x);
*p = 0xFFFFFFFF;
}
for (double lat = 45.0; lat < 50.0; lat += 1.0/60) {
int x = fix2x(lat, 6.0);
int y = fix2y(lat, 6.0);
unsigned int *p = image + (y * width + x);
*p = 0xFFFFFFFF;
x = fix2x(lat, 16.0);
y = fix2y(lat, 16.0);
p = image + (y * width + x);
*p = 0xFFFFFFFF;
}
}
static void checkforecast(unsigned int *image, unsigned width, unsigned height) {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
unsigned int *p = image + (y * width + x);
if (forecast(*p) != 99) {
*p = 0xFFFFFFFF;
}
}
}
}
static void doit(const char* infilename, const char* outfilename, int check)
{
unsigned error;
unsigned char* image;
unsigned width, height;
error = lodepng_decode32_file(&image, &width, &height, infilename);
if(error) printf("error %u: %s\n", error, lodepng_error_text(error));
switch(check) {
case 1:
checktransform((unsigned int *)image, width, height);
break;
case 2:
checkforecast((unsigned int *)image, width, height);
break;
}
error = lodepng_encode32_file(outfilename, image, width, height);
if(error) printf("error %u: %s\n", error, lodepng_error_text(error));
free(image);
}
int main(int argc, char *argv[])
{
int check = 0;
int opt;
while ((opt = getopt(argc, argv, "tf")) != -1) {
switch (opt) {
case 't':
check = 1;
break;
case 'f':
check = 2;
break;
default: /* '?' */
fprintf(stderr, "Invalid option\n");
exit(1);
}
}
const char* infilename = argc > optind ? argv[optind] : "test.png";
optind++;
const char* outfilename = argc > optind ? argv[optind] : "checkmap.png";
optind++;
doit(infilename, outfilename, check);
return 0;
}