rasops_bitops.h revision 1.7 1 /* $NetBSD: rasops_bitops.h,v 1.7 2000/06/13 13:37:00 ad Exp $ */
2
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #ifndef _RASOPS_BITOPS_H_
40 #define _RASOPS_BITOPS_H_ 1
41
42 /*
43 * Erase columns.
44 */
45 static void
46 NAME(erasecols)(cookie, row, col, num, attr)
47 void *cookie;
48 int row, col, num;
49 long attr;
50 {
51 int lmask, rmask, lclr, rclr, clr;
52 struct rasops_info *ri;
53 int32_t *dp, *rp;
54 int height, cnt;
55
56 ri = (struct rasops_info *)cookie;
57
58 #ifdef RASOPS_CLIPPING
59 if ((unsigned)row >= (unsigned)ri->ri_rows)
60 return;
61
62 if (col < 0) {
63 num += col;
64 col = 0;
65 }
66
67 if ((col + num) > ri->ri_cols)
68 num = ri->ri_cols - col;
69
70 if (num <= 0)
71 return;
72 #endif
73 col *= ri->ri_font->fontwidth << PIXEL_SHIFT;
74 num *= ri->ri_font->fontwidth << PIXEL_SHIFT;
75 height = ri->ri_font->fontheight;
76 clr = ri->ri_devcmap[(attr >> 16) & 0xf];
77 rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + ((col >> 3) & ~3));
78
79 if ((col & 31) + num <= 32) {
80 lmask = ~rasops_pmask[col & 31][num];
81 lclr = clr & ~lmask;
82
83 while (height--) {
84 dp = rp;
85 DELTA(rp, ri->ri_stride, int32_t *);
86
87 *dp = (*dp & lmask) | lclr;
88 }
89 } else {
90 lmask = rasops_rmask[col & 31];
91 rmask = rasops_lmask[(col + num) & 31];
92
93 if (lmask)
94 num = (num - (32 - (col & 31))) >> 5;
95 else
96 num = num >> 5;
97
98 lclr = clr & ~lmask;
99 rclr = clr & ~rmask;
100
101 while (height--) {
102 dp = rp;
103 DELTA(rp, ri->ri_stride, int32_t *);
104
105 if (lmask)
106 *dp++ = (*dp & lmask) | lclr;
107
108 for (cnt = num; cnt > 0; cnt--)
109 *dp++ = clr;
110
111 if (rmask)
112 *dp = (*dp & rmask) | rclr;
113 }
114 }
115 }
116
117 /*
118 * Actually paint the cursor.
119 */
120 static void
121 NAME(do_cursor)(ri)
122 struct rasops_info *ri;
123 {
124 int lmask, rmask, height, row, col, num;
125 int32_t *dp, *rp;
126
127 row = ri->ri_crow;
128 col = ri->ri_ccol * ri->ri_font->fontwidth << PIXEL_SHIFT;
129 height = ri->ri_font->fontheight;
130 num = ri->ri_font->fontwidth << PIXEL_SHIFT;
131 rp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3));
132
133 if ((col & 31) + num <= 32) {
134 lmask = rasops_pmask[col & 31][num];
135
136 while (height--) {
137 dp = rp;
138 DELTA(rp, ri->ri_stride, int32_t *);
139 *dp ^= lmask;
140 }
141 } else {
142 lmask = ~rasops_rmask[col & 31];
143 rmask = ~rasops_lmask[(col + num) & 31];
144
145 while (height--) {
146 dp = rp;
147 DELTA(rp, ri->ri_stride, int32_t *);
148
149 if (lmask != -1)
150 *dp++ ^= lmask;
151
152 if (rmask != -1)
153 *dp ^= rmask;
154 }
155 }
156 }
157
158 /*
159 * Copy columns. Ick!
160 */
161 static void
162 NAME(copycols)(cookie, row, src, dst, num)
163 void *cookie;
164 int row, src, dst, num;
165 {
166 int tmp, lmask, rmask, height, lnum, rnum, sb, db, cnt, full;
167 int32_t *sp, *dp, *srp, *drp;
168 struct rasops_info *ri;
169
170 ri = (struct rasops_info *)cookie;
171
172 #ifdef RASOPS_CLIPPING
173 if (dst == src)
174 return;
175
176 /* Catches < 0 case too */
177 if ((unsigned)row >= (unsigned)ri->ri_rows)
178 return;
179
180 if (src < 0) {
181 num += src;
182 src = 0;
183 }
184
185 if ((src + num) > ri->ri_cols)
186 num = ri->ri_cols - src;
187
188 if (dst < 0) {
189 num += dst;
190 dst = 0;
191 }
192
193 if ((dst + num) > ri->ri_cols)
194 num = ri->ri_cols - dst;
195
196 if (num <= 0)
197 return;
198 #endif
199
200 cnt = ri->ri_font->fontwidth << PIXEL_SHIFT;
201 src *= cnt;
202 dst *= cnt;
203 num *= cnt;
204 row *= ri->ri_yscale;
205 height = ri->ri_font->fontheight;
206 db = dst & 31;
207
208 if (db + num <= 32) {
209 /* Destination is contained within a single word */
210 srp = (int32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
211 drp = (int32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
212 sb = src & 31;
213
214 while (height--) {
215 GETBITS(srp, sb, num, tmp);
216 PUTBITS(tmp, db, num, drp);
217 DELTA(srp, ri->ri_stride, int32_t *);
218 DELTA(drp, ri->ri_stride, int32_t *);
219 }
220
221 return;
222 }
223
224 lmask = rasops_rmask[db];
225 rmask = rasops_lmask[(dst + num) & 31];
226 lnum = (32 - db) & 31;
227 rnum = (dst + num) & 31;
228
229 if (lmask)
230 full = (num - (32 - (dst & 31))) >> 5;
231 else
232 full = num >> 5;
233
234 if (src < dst && src + num > dst) {
235 /* Copy right-to-left */
236 sb = src & 31;
237 src = src + num;
238 dst = dst + num;
239 srp = (int32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
240 drp = (int32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
241
242 src = src & 31;
243 rnum = 32 - lnum;
244 db = dst & 31;
245
246 if ((src -= db) < 0) {
247 sp--;
248 src += 32;
249 }
250
251 while (height--) {
252 sp = srp;
253 dp = drp;
254 DELTA(srp, ri->ri_stride, int32_t *);
255 DELTA(drp, ri->ri_stride, int32_t *);
256
257 if (db) {
258 GETBITS(sp, src, db, tmp);
259 PUTBITS(tmp, 0, db, dp);
260 dp--;
261 sp--;
262 }
263
264 /* Now aligned to 32-bits wrt dp */
265 for (cnt = full; cnt; cnt--, sp--) {
266 GETBITS(sp, src, 32, tmp);
267 *dp-- = tmp;
268 }
269
270 if (lmask) {
271 #if 0
272 if (src > sb)
273 sp++;
274 #endif
275 GETBITS(sp, sb, lnum, tmp);
276 PUTBITS(tmp, rnum, lnum, dp);
277 }
278 }
279 } else {
280 /* Copy left-to-right */
281 srp = (int32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
282 drp = (int32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
283 db = dst & 31;
284
285 while (height--) {
286 sb = src & 31;
287 sp = srp;
288 dp = drp;
289 DELTA(srp, ri->ri_stride, int32_t *);
290 DELTA(drp, ri->ri_stride, int32_t *);
291
292 if (lmask) {
293 GETBITS(sp, sb, lnum, tmp);
294 PUTBITS(tmp, db, lnum, dp);
295 dp++;
296
297 if ((sb += lnum) > 31) {
298 sp++;
299 sb -= 32;
300 }
301 }
302
303 /* Now aligned to 32-bits wrt dp */
304 for (cnt = full; cnt; cnt--, sp++) {
305 GETBITS(sp, sb, 32, tmp);
306 *dp++ = tmp;
307 }
308
309 if (rmask) {
310 GETBITS(sp, sb, rnum, tmp);
311 PUTBITS(tmp, 0, rnum, dp);
312 }
313 }
314 }
315 }
316
317 #endif /* _RASOPS_BITOPS_H_ */
318