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/fl8wlin.c $
21 * $Revision: 1.1 $
22 * $Author: kevin $
23 * $Date: 1994/08/04 09:53:09 $
24 *
25 * Routines to draw wire polys.
26 *
27 * This file is part of the 2d library.
28 *
29 */
30
31 #include "cnvdat.h"
32 #include "ctxmac.h"
33 #include "fill.h"
34 #include "plytyp.h"
35
36 #define gr_get_ipal_index(r, g, b) (long)((((r) >> 19) & 0x1f) | (((g) >> 14) & 0x3e0) | (((b) >> 9) & 0x7c00))
37 #define do_hline_inc_x \
38 do { \
39 p[x] = c; \
40 x++; \
41 } while (x < x_new)
42 #define do_hline_dec_x \
43 if (x == x_new) { \
44 p[x] = c; \
45 } else \
46 do { \
47 x--; \
48 p[x] = c; \
49 } while (x > x_new)
50
gri_flat8_wire_poly_uline(long c,long parm,grs_vertex * v0,grs_vertex * v1)51 void gri_flat8_wire_poly_uline(long c, long parm, grs_vertex *v0, grs_vertex *v1) {
52 int y, y_max, x, x_new;
53 fix x0, y0;
54 fix x1, y1;
55 fix x_fix, dx;
56 uchar *p;
57
58 if (gr_get_fill_type() == FILL_SOLID)
59 c = (uchar)parm;
60 else if (gr_get_fill_type() == FILL_CLUT)
61 c = ((uchar *)parm)[c];
62 if (v1->y > v0->y) {
63 y = fix_cint(v0->y);
64 y_max = fix_cint(v1->y);
65 } else {
66 y = fix_cint(v1->y);
67 y_max = fix_cint(v0->y);
68 }
69 p = grd_bm.bits + y * grd_bm.row;
70
71 /* horizontal? */
72 if (y_max - y <= 1) {
73 if (v1->x > v0->x) {
74 x_new = fix_cint(v1->x), x = fix_cint(v0->x);
75 } else {
76 x_new = fix_cint(v0->x), x = fix_cint(v1->x);
77 }
78 do_hline_inc_x;
79 return;
80 }
81
82 /* not horizontal */
83 if (v1->y > v0->y) {
84 y0 = v0->y, x0 = v0->x;
85 y1 = v1->y, x1 = v1->x;
86 } else {
87 y1 = v0->y, x1 = v0->x;
88 y0 = v1->y, x0 = v1->x;
89 }
90 dx = fix_div(x1 - x0, y1 - y0);
91 x = fix_cint(x0);
92 x_fix = x0 + fix_mul(fix_ceil(y0) - y0, dx);
93 x_new = fix_cint(x_fix);
94
95 /* draw line */
96 if (dx >= 0) {
97 do_hline_inc_x;
98 do {
99 x = x_new;
100 x_new = fix_cint(x_fix += dx);
101 do_hline_inc_x;
102 p += grd_bm.row;
103 } while ((++y) < y_max - 1);
104 x = x_new;
105 x_new = fix_cint(x1);
106 do_hline_inc_x;
107 } else {
108 do {
109 do_hline_dec_x;
110 x_new = fix_cint(x_fix += dx);
111 p += grd_bm.row;
112 } while ((++y) < y_max - 1);
113 x_new = fix_cint(x1);
114 do_hline_dec_x;
115 }
116 }
117