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