1 /*
2 
3 Copyright (C) 2015-2018 Night Dive Studios, LLC.
4 
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 /*
20  * $Source: r:/prj/lib/src/2d/RCS/fl8wclin.h $
21  * $Revision: 1.1 $
22  * $Author: kevin $
23  * $Date: 1994/08/04 09:58:31 $
24  *
25  * Main shell for drawing wire poly rgb lines.
26  *
27  * This file is part of the 2d library.
28  *
29  */
30 
31 /* don't try to use this other than in fl8wclin.c */
32 
33 int d, y, y_max, x, x_new;
34 fix x0, y0, r0, b0, g0;
35 fix x1, y1, r1, b1, g1;
36 fix dr, dg, db, x_fix, dx;
37 uchar *p;
38 
39 if (v1->y > v0->y) {
40     y = fix_cint(v0->y);
41     y_max = fix_cint(v1->y);
42 } else {
43     y = fix_cint(v1->y);
44     y_max = fix_cint(v0->y);
45 }
46 p = grd_bm.bits + y * grd_bm.row;
47 
48 /* horizontal? */
49 if (y_max - y <= 1) {
50     if (v1->x > v0->x) {
51         x_new = fix_cint(v1->x), x = fix_cint(v0->x);
52         r0 = fix_make(v0->u, 0), g0 = fix_make(v0->v, 0), b0 = fix_make(v0->w, 0);
53         r1 = fix_make(v1->u, 0), g1 = fix_make(v1->v, 0), b1 = fix_make(v1->w, 0);
54     } else {
55         x_new = fix_cint(v0->x), x = fix_cint(v1->x);
56         r0 = fix_make(v1->u, 0), g0 = fix_make(v1->v, 0), b0 = fix_make(v1->w, 0);
57         r1 = fix_make(v0->u, 0), g1 = fix_make(v0->v, 0), b1 = fix_make(v0->w, 0);
58     }
59     d = x_new - x;
60     if (d > 0) {
61         dr = (r1 - r0) / d;
62         dg = (g1 - g0) / d;
63         db = (b1 - b0) / d;
64         do_hline_inc_x;
65     }
66     return;
67 }
68 
69 /* not horizontal */
70 if (v1->y > v0->y) {
71     y0 = v0->y, x0 = v0->x;
72     r0 = fix_make(v0->u, 0), g0 = fix_make(v0->v, 0), b0 = fix_make(v0->w, 0);
73     y1 = v1->y, x1 = v1->x;
74     r1 = fix_make(v1->u, 0), g1 = fix_make(v1->v, 0), b1 = fix_make(v1->w, 0);
75 } else {
76     y1 = v0->y, x1 = v0->x;
77     r1 = fix_make(v0->u, 0), g1 = fix_make(v0->v, 0), b1 = fix_make(v0->w, 0);
78     y0 = v1->y, x0 = v1->x;
79     r0 = fix_make(v1->u, 0), g0 = fix_make(v1->v, 0), b0 = fix_make(v1->w, 0);
80 }
81 dx = fix_div(x1 - x0, y1 - y0);
82 if (fix_abs(dx) > FIX_UNIT) {
83     d = fix_cint(x1) - fix_cint(x0);
84     if (d < 0)
85         d = -d;
86 } else {
87     d = y_max - y;
88 }
89 dr = (r1 - r0) / d;
90 dg = (g1 - g0) / d;
91 db = (b1 - b0) / d;
92 x = fix_cint(x0);
93 x_fix = x0 + fix_mul(fix_ceil(y0) - y0, dx);
94 x_new = fix_cint(x_fix);
95 
96 /* draw line */
97 if (dx >= 0) {
98     do_hline_inc_x;
99     do {
100         x = x_new;
101         x_new = fix_cint(x_fix += dx);
102         do_hline_inc_x;
103         p += grd_bm.row;
104     } while ((++y) < y_max - 1);
105     x = x_new;
106     x_new = fix_cint(x1);
107     do_hline_inc_x;
108 } else {
109     do {
110         do_hline_dec_x;
111         x_new = fix_cint(x_fix += dx);
112         p += grd_bm.row;
113     } while ((++y) < y_max - 1);
114     x_new = fix_cint(x1);
115     do_hline_dec_x;
116 }
117