1 /*
2 	d_fill.c
3 
4 	clears a specified rectangle to the specified color
5 
6 	Copyright (C) 1996-1997  Id Software, Inc.
7 
8 	This program is free software; you can redistribute it and/or
9 	modify it under the terms of the GNU General Public License
10 	as published by the Free Software Foundation; either version 2
11 	of the License, or (at your option) any later version.
12 
13 	This program is distributed in the hope that it will be useful,
14 	but WITHOUT ANY WARRANTY; without even the implied warranty of
15 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 	See the GNU General Public License for more details.
18 
19 	You should have received a copy of the GNU General Public License
20 	along with this program; if not, write to:
21 
22 		Free Software Foundation, Inc.
23 		59 Temple Place - Suite 330
24 		Boston, MA  02111-1307, USA
25 
26 */
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30 
31 #define NH_DEFINE
32 #include "namehack.h"
33 
34 #include "QF/sys.h"
35 
36 #include "d_iface.h"
37 #include "r_internal.h"
38 #include "vid_internal.h"
39 
40 
41 void
sw32_D_FillRect(vrect_t * rect,int color)42 sw32_D_FillRect (vrect_t *rect, int color)
43 {
44 	switch (sw32_r_pixbytes)
45 	{
46 	case 1:
47 		{
48 			int rx, ry, rwidth, rheight;
49 			byte *dest, pix;
50 
51 			pix = color;
52 
53 			rx = rect->x;
54 			ry = rect->y;
55 			rwidth = rect->width;
56 			rheight = rect->height;
57 
58 			if (rx < 0) {
59 				rwidth += rx;
60 				rx = 0;
61 			}
62 			if (ry < 0) {
63 				rheight += ry;
64 				ry = 0;
65 			}
66 			if (rx + rwidth > vid.width)
67 				rwidth = vid.width - rx;
68 			if (ry + rheight > vid.height)
69 				rheight = vid.height - rx;
70 
71 			if (rwidth < 1 || rheight < 1)
72 				return;
73 
74 			dest = (byte *) vid.buffer + ry * vid.rowbytes + rx;
75 
76 			for (ry = 0; ry < rheight; ry++)
77 			{
78 				for (rx = 0; rx < rwidth; rx++)
79 					dest[rx] = pix;
80 				dest += vid.rowbytes;
81 			}
82 		}
83 		break;
84 	case 2:
85 		{
86 			int rx, ry, rwidth, rheight;
87 			unsigned short *dest, pix;
88 
89 			pix = sw32_8to16table[color];
90 
91 			rx = rect->x;
92 			ry = rect->y;
93 			rwidth = rect->width;
94 			rheight = rect->height;
95 
96 			if (rx < 0) {
97 				rwidth += rx;
98 				rx = 0;
99 			}
100 			if (ry < 0) {
101 				rheight += ry;
102 				ry = 0;
103 			}
104 			if (rx + rwidth > vid.width)
105 				rwidth = vid.width - rx;
106 			if (ry + rheight > vid.height)
107 				rheight = vid.height - rx;
108 
109 			if (rwidth < 1 || rheight < 1)
110 				return;
111 
112 			dest = (unsigned short *) vid.buffer + ry * (vid.rowbytes >> 1) +
113 				rx;
114 
115 			for (ry = 0; ry < rheight; ry++)
116 			{
117 				for (rx = 0; rx < rwidth; rx++)
118 					dest[rx] = pix;
119 				dest += (vid.rowbytes >> 1);
120 			}
121 		}
122 		break;
123 	case 4:
124 		{
125 			int rx, ry, rwidth, rheight;
126 			unsigned int *dest, pix;
127 
128 			pix = d_8to24table[color];
129 
130 			rx = rect->x;
131 			ry = rect->y;
132 			rwidth = rect->width;
133 			rheight = rect->height;
134 
135 			if (rx < 0) {
136 				rwidth += rx;
137 				rx = 0;
138 			}
139 			if (ry < 0) {
140 				rheight += ry;
141 				ry = 0;
142 			}
143 			if (rx + rwidth > vid.width)
144 				rwidth = vid.width - rx;
145 			if (ry + rheight > vid.height)
146 				rheight = vid.height - rx;
147 
148 			if (rwidth < 1 || rheight < 1)
149 				return;
150 
151 			dest = (unsigned int *) vid.buffer + ry * (vid.rowbytes >> 2) + rx;
152 
153 			for (ry = 0; ry < rheight; ry++)
154 			{
155 				for (rx = 0; rx < rwidth; rx++)
156 					dest[rx] = pix;
157 				dest += (vid.rowbytes >> 2);
158 			}
159 		}
160 		break;
161 	default:
162 		Sys_Error("D_FillRect: unsupported r_pixbytes %i", sw32_r_pixbytes);
163 	}
164 }
165