rasops_bitops.h revision 1.4 1 /* $NetBSD: rasops_bitops.h,v 1.4 1999/07/21 19:19:04 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 Andy 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 int32_t *dp, *rp, lmask, rmask, lclr, rclr, clr;
52 struct rasops_info *ri;
53 int height, cnt;
54
55 ri = (struct rasops_info *)cookie;
56
57 #ifdef RASOPS_CLIPPING
58 if ((unsigned)row >= (unsigned)ri->ri_rows)
59 return;
60
61 if (col < 0) {
62 num += col;
63 col = 0;
64 }
65
66 if ((col + num) > ri->ri_cols)
67 num = ri->ri_cols - col;
68
69 if (num <= 0)
70 return;
71 #endif
72 col *= ri->ri_font->fontwidth << PIXEL_SHIFT;
73 num *= ri->ri_font->fontwidth << PIXEL_SHIFT;
74 height = ri->ri_font->fontheight;
75 clr = ri->ri_devcmap[(attr >> 16) & 15];
76 rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + ((col >> 3) & ~3));
77
78 if ((col & 31) + num <= 32) {
79 lmask = ~rasops_pmask[col & 31][num];
80 lclr = clr & ~lmask;
81
82 while (height--) {
83 dp = rp;
84 DELTA(rp, ri->ri_stride, int32_t *);
85
86 *dp = (*dp & lmask) | lclr;
87 }
88 } else {
89 lmask = rasops_rmask[col & 31];
90 rmask = rasops_lmask[(col + num) & 31];
91
92 if (lmask)
93 num = (num - (32 - (col & 31))) >> 5;
94 else
95 num = num >> 5;
96
97 lclr = clr & ~lmask;
98 rclr = clr & ~rmask;
99
100 while (height--) {
101 dp = rp;
102 DELTA(rp, ri->ri_stride, int32_t *);
103
104 if (lmask)
105 *dp++ = (*dp & lmask) | lclr;
106
107 for (cnt = num; cnt > 0; cnt--)
108 *dp++ = clr;
109
110 if (rmask)
111 *dp = (*dp & rmask) | rclr;
112 }
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 int32_t *dp, *rp, lmask, rmask;
125 int height, row, col, num;
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 /*
160 * Copy columns. Ick!
161 */
162 static void
163 NAME(copycols)(cookie, row, src, dst, num)
164 void *cookie;
165 int row, src, dst, num;
166 {
167 int32_t *sp, *dp, *srp, *drp, tmp, lmask, rmask;
168 int height, lnum, rnum, sb, db, cnt, full;
169 struct rasops_info *ri;
170
171 ri = (struct rasops_info *)cookie;
172
173 #ifdef RASOPS_CLIPPING
174 if (dst == src)
175 return;
176
177 /* Catches < 0 case too */
178 if ((unsigned)row >= (unsigned)ri->ri_rows)
179 return;
180
181 if (src < 0) {
182 num += src;
183 src = 0;
184 }
185
186 if ((src + num) > ri->ri_cols)
187 num = ri->ri_cols - src;
188
189 if (dst < 0) {
190 num += dst;
191 dst = 0;
192 }
193
194 if ((dst + num) > ri->ri_cols)
195 num = ri->ri_cols - dst;
196
197 if (num <= 0)
198 return;
199 #endif
200
201 cnt = ri->ri_font->fontwidth << PIXEL_SHIFT;
202 src *= cnt;
203 dst *= cnt;
204 num *= cnt;
205 row *= ri->ri_yscale;
206 height = ri->ri_font->fontheight;
207 db = dst & 31;
208
209 if (db + num <= 32) {
210 /* Destination is contained within a single word */
211 srp = (int32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
212 drp = (int32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
213 sb = src & 31;
214
215 while (height--) {
216 GETBITS(srp, sb, num, tmp);
217 PUTBITS(tmp, db, num, drp);
218 DELTA(srp, ri->ri_stride, int32_t *);
219 DELTA(drp, ri->ri_stride, int32_t *);
220 }
221
222 return;
223 }
224
225 lmask = rasops_rmask[db];
226 rmask = rasops_lmask[(dst + num) & 31];
227 lnum = (32 - db) & 31;
228 rnum = (dst + num) & 31;
229
230 if (lmask)
231 full = (num - (32 - (dst & 31))) >> 5;
232 else
233 full = num >> 5;
234
235 if (src < dst && src + num > dst) {
236 /* Copy right-to-left */
237 sb = src & 31;
238 src = src + num;
239 dst = dst + num;
240 srp = (int32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
241 drp = (int32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
242
243 src = src & 31;
244 rnum = 32 - lnum;
245 db = dst & 31;
246
247 if ((src -= db) < 0) {
248 sp--;
249 src += 32;
250 }
251
252 while (height--) {
253 sp = srp;
254 dp = drp;
255 DELTA(srp, ri->ri_stride, int32_t *);
256 DELTA(drp, ri->ri_stride, int32_t *);
257
258 if (db) {
259 GETBITS(sp, src, db, tmp);
260 PUTBITS(tmp, 0, db, dp);
261 dp--;
262 sp--;
263 }
264
265 /* Now aligned to 32-bits wrt dp */
266 for (cnt = full; cnt; cnt--, sp--) {
267 GETBITS(sp, src, 32, tmp);
268 *dp-- = tmp;
269 }
270
271 if (lmask) {
272 // if (src > sb)
273 // sp++;
274 GETBITS(sp, sb, lnum, tmp);
275 PUTBITS(tmp, rnum, lnum, dp);
276 }
277 }
278 } else {
279 /* Copy left-to-right */
280 srp = (int32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
281 drp = (int32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
282 db = dst & 31;
283
284 while (height--) {
285 sb = src & 31;
286 sp = srp;
287 dp = drp;
288 DELTA(srp, ri->ri_stride, int32_t *);
289 DELTA(drp, ri->ri_stride, int32_t *);
290
291 if (lmask) {
292 GETBITS(sp, sb, lnum, tmp);
293 PUTBITS(tmp, db, lnum, dp);
294 dp++;
295
296 if ((sb += lnum) > 31) {
297 sp++;
298 sb -= 32;
299 }
300 }
301
302 /* Now aligned to 32-bits wrt dp */
303 for (cnt = full; cnt; cnt--, sp++) {
304 GETBITS(sp, sb, 32, tmp);
305 *dp++ = tmp;
306 }
307
308 if (rmask) {
309 GETBITS(sp, sb, rnum, tmp);
310 PUTBITS(tmp, 0, rnum, dp);
311 }
312 }
313 }
314 }
315 #endif /* _RASOPS_BITOPS_H_ */
316