-
Notifications
You must be signed in to change notification settings - Fork 53
/
raster.c
104 lines (82 loc) · 2.54 KB
/
raster.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "util.h"
#include "graphics.h"
#include "clip.h"
struct graphics {
int width;
int height;
};
struct graphics *graphics_init(int width, int height, char **filetype) {
struct graphics *g = malloc(sizeof(struct graphics));
g->width = width;
g->height = height;
*filetype = "txt";
return g;
}
void out(struct graphics *gc, int transparency, double gamma, int invert, int bg, int color, int color2, int saturate, int mask, double color_cap, int cie) {
}
// http://rosettacode.org/wiki/Bitmap/Bresenham's_line_algorithm#C
void drawLine(int x0, int y0, int x1, int y1, struct graphics *g, double bright, double hue, long long meta, double thick, struct tilecontext *tc) {
int dx = abs(x1 - x0), sx = (x0 < x1) ? 1 : -1;
int dy = abs(y1 - y0), sy = (y0 < y1) ? 1 : -1;
int err = ((dx > dy) ? dx : -dy) / 2, e2;
while (1) {
if (x0 == x1 && y0 == y1) {
break;
}
drawPixel(x0, y0, g, bright, hue, meta, tc);
int n;
for (n = 1; n < ceil(thick / 2); n++) {
if (dx > dy) {
drawPixel(x0, y0 - n, g, bright, hue, meta, tc);
drawPixel(x0, y0 + n, g, bright, hue, meta, tc);
} else {
drawPixel(x0 - n, y0, g, bright, hue, meta, tc);
drawPixel(x0 + n, y0, g, bright, hue, meta, tc);
}
}
e2 = err;
if (e2 > -dx) {
err -= dy;
x0 += sx;
}
if (e2 < dy) {
err += dx;
y0 += sy;
}
}
}
int drawClip(double x0, double y0, double x1, double y1, struct graphics *g, double bright, double hue, long long meta, int antialias, double thick, struct tilecontext *tc) {
double xmin = -1 - thick;
double ymin = -1 - thick;
double xmax = g->width + thick;
double ymax = g->height + thick;
int accept = clip(&x0, &y0, &x1, &y1, xmin, ymin, xmax, ymax);
if (accept) {
if (g != NULL) {
drawLine(x0, y0, x1, y1, g, bright, hue, meta, thick, tc);
}
return 1;
}
return 0;
}
void drawPixel(double x, double y, struct graphics *g, double bright, double hue, long long meta, struct tilecontext *tc) {
x -= tc->xoff;
y -= tc->yoff;
long long scale = 1LL << (32 - tc->z);
long long bx = tc->x * scale;
long long by = tc->y * scale;
bx += x / g->width * scale;
by += y / g->height * scale;
double lat, lon;
tile2latlon(bx, by, 32, &lat, &lon);
printf("%.6f,%.6f\n", lat, lon);
}
void drawBrush(double x, double y, struct graphics *g, double bright, double brush, double hue, long long meta, int gaussian, struct tilecontext *tc) {
drawPixel(x, y, g, bright, hue, meta, tc);
}
void setClip(struct graphics *gc, int x, int y, int w, int h) {
}