-
Notifications
You must be signed in to change notification settings - Fork 0
/
line.h
119 lines (95 loc) · 3.01 KB
/
line.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
#ifndef LINE_H
#define LINE_H
static inline void draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint8_t c) {
uint8_t steep = 0;
int16_t dx, dy, error2, derror2;
if (abs16(x0 - x1) < abs16(y0 - y1)) {
swap16(x0, y0);
swap16(x1, y1);
steep = 1;
}
if (x0 > x1) {
swap16(x0, x1);
swap16(y0, y1);
}
dx = x1 - x0;
dy = y1 - y0;
derror2 = abs16(dy) << 1;
error2 = 0;
if (steep) {
int32_t x, x0i, x1i;
int16_t y = y0;
if (y1 > y0) {
if (y >= SCREEN_WIDTH)
return;
x0i = mul_by_screen_stride32(x0);
x1i = mul_by_screen_stride32(x1);
for (x = x0i; x <= x1i; x += SCREEN_WIDTH) {
if (x >= 0 && y >= 0 && x < (int32_t)SCREEN_WIDTH * SCREEN_HEIGHT)
dblbuf[y + x] = c;
error2 += derror2;
if (error2 > dx) {
if (y == SCREEN_WIDTH - 1)
return;
y++;
aw_assert(y < SCREEN_WIDTH);
error2 -= dx << 1;
}
}
} else {
if (y < 0)
return;
x0i = mul_by_screen_stride32(x0);
x1i = mul_by_screen_stride32(x1);
for (x = x0i; x <= x1i; x += SCREEN_WIDTH) {
if (x >= 0 && y < SCREEN_WIDTH && x < (int32_t)SCREEN_WIDTH * SCREEN_HEIGHT)
dblbuf[y + x] = c;
error2 += derror2;
if (error2 > dx) {
if (y == 0)
return;
y--;
aw_assert(y >= 0);
error2 -= dx << 1;
}
}
}
} else {
int16_t x;
int32_t y;
if (y1 > y0) {
if (y0 >= SCREEN_HEIGHT)
return;
y = mul_by_screen_stride32(y0);
for (x = x0; x <= x1; x++) {
if (x >= 0 && y >= 0 && x < SCREEN_WIDTH)
dblbuf[x + y] = c;
error2 += derror2;
if (error2 > dx) {
if (y == (int32_t)SCREEN_WIDTH * (SCREEN_HEIGHT - 1))
return;
y += SCREEN_WIDTH;
aw_assert(y < (int32_t)SCREEN_WIDTH * SCREEN_HEIGHT);
error2 -= dx << 1;
}
}
} else {
if (y0 < 0)
return;
y = mul_by_screen_stride32(y0);
for (x = x0; x <= x1; x++) {
if (x >= 0 && x < SCREEN_WIDTH && y < (int32_t)SCREEN_WIDTH * SCREEN_HEIGHT)
dblbuf[x + y] = c;
error2 += derror2;
if (error2 > dx) {
if (y == 0)
return;
y -= SCREEN_WIDTH;
aw_assert(y >= 0);
error2 -= dx << 1;
}
}
}
}
}
#endif