0
|
1
|
|
2 #ifdef DM_USE_SIMD
|
|
3 static int DM_DRAWLINE_NAME_ASM (SDL_Surface *screen, int x0, int y0, int x1, int y1, const Uint32 col);
|
|
4 #endif
|
|
5
|
|
6 #ifdef DM_USE_C
|
|
7 static int DM_DRAWLINE_NAME_C (SDL_Surface *screen, int x0, int y0, int x1, int y1, const Uint32 col)
|
|
8 {
|
|
9 int dx, dy, xstep, ystep;
|
|
10 const int qpitch = screen->pitch / DM_DRAWLINE_DST_BYTES;
|
|
11
|
|
12 // Clipping
|
|
13 if (dmClipLineCoords(&x0, &y0, &x1, &y1, screen))
|
|
14 return -1;
|
|
15
|
|
16 // Compute initial deltas
|
|
17 dx = (x1 - x0) * 2;
|
|
18 dy = (y1 - y0) * 2;
|
|
19
|
|
20 if (dx < 0)
|
|
21 {
|
|
22 dx = -dx;
|
|
23 xstep = -1;
|
|
24 }
|
|
25 else
|
|
26 xstep = 1;
|
|
27
|
|
28 if (dy < 0)
|
|
29 {
|
|
30 dy = -dy;
|
|
31 ystep = -qpitch;
|
|
32 }
|
|
33 else
|
|
34 ystep = qpitch;
|
|
35
|
|
36 // Compute offsets
|
|
37 y0 *= qpitch;
|
|
38 y1 *= qpitch;
|
|
39
|
|
40 DM_DRAWLINE_DST_TYPE *pix = screen->pixels;
|
|
41
|
|
42 // Continue based on which delta is larger
|
|
43 if (dx > dy)
|
|
44 {
|
|
45 int afrac = dy - (dx / 2);
|
|
46 while (x0 != x1)
|
|
47 {
|
|
48 if (afrac >= 0)
|
|
49 {
|
|
50 y0 += ystep;
|
|
51 afrac -= dx;
|
|
52 }
|
|
53
|
|
54 x0 += xstep;
|
|
55 afrac += dy;
|
|
56
|
|
57 DM_DRAWLINE_INNER
|
|
58 }
|
|
59 }
|
|
60 else
|
|
61 {
|
|
62 int afrac = dx - (dy / 2);
|
|
63 while (y0 != y1)
|
|
64 {
|
|
65 if (afrac >= 0)
|
|
66 {
|
|
67 x0 += xstep;
|
|
68 afrac -= dy;
|
|
69 }
|
|
70
|
|
71 y0 += ystep;
|
|
72 afrac += dx;
|
|
73
|
|
74 DM_DRAWLINE_INNER
|
|
75 }
|
|
76 }
|
|
77
|
|
78 return 0;
|
|
79 }
|
|
80 #endif
|
|
81
|
|
82 #undef DM_DRAWLINE_NAME
|
|
83 #undef DM_DRAWLINE_NAME_ASM
|
|
84 #undef DM_DRAWLINE_NAME_C
|
|
85 #undef DM_DRAWLINE_DST_BYTES
|
|
86 #undef DM_DRAWLINE_DST_TYPE
|