rasops24.c revision 1.11 1 /* $NetBSD: rasops24.c,v 1.11 2000/02/12 22:06:54 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 #include "opt_rasops.h"
40 #include <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: rasops24.c,v 1.11 2000/02/12 22:06:54 ad Exp $");
42
43 #include <sys/types.h>
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/time.h>
47
48 #include <machine/endian.h>
49 #include <machine/bswap.h>
50
51 #include <dev/wscons/wsdisplayvar.h>
52 #include <dev/wscons/wsconsio.h>
53 #include <dev/rasops/rasops.h>
54
55 static void rasops24_erasecols __P((void *, int, int, int, long));
56 static void rasops24_eraserows __P((void *, int, int, long));
57 static void rasops24_putchar __P((void *, int, int, u_int, long attr));
58 #ifndef RASOPS_SMALL
59 static void rasops24_putchar8 __P((void *, int, int, u_int, long attr));
60 static void rasops24_putchar12 __P((void *, int, int, u_int, long attr));
61 static void rasops24_putchar16 __P((void *, int, int, u_int, long attr));
62 static void rasops24_makestamp __P((struct rasops_info *, long));
63 #endif
64
65 /*
66 * 4x1 stamp for optimized character blitting
67 */
68 static int32_t stamp[64];
69 static long stamp_attr;
70 static int stamp_mutex; /* XXX see note in readme */
71
72 /*
73 * XXX this confuses the hell out of gcc2 (not egcs) which always insists
74 * that the shift count is negative.
75 *
76 * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
77 * destination int32_t[0] = STAMP_READ(offset)
78 * destination int32_t[1] = STAMP_READ(offset + 4)
79 * destination int32_t[2] = STAMP_READ(offset + 8)
80 */
81 #define STAMP_SHIFT(fb,n) ((n*4-4) >= 0 ? (fb)>>(n*4-4):(fb)<<-(n*4-4))
82 #define STAMP_MASK (15 << 4)
83 #define STAMP_READ(o) (*(int32_t *)((caddr_t)stamp + (o)))
84
85 /*
86 * Initalize rasops_info struct for this colordepth.
87 */
88 void
89 rasops24_init(ri)
90 struct rasops_info *ri;
91 {
92
93 switch (ri->ri_font->fontwidth) {
94 #ifndef RASOPS_SMALL
95 case 8:
96 ri->ri_ops.putchar = rasops24_putchar8;
97 break;
98 case 12:
99 ri->ri_ops.putchar = rasops24_putchar12;
100 break;
101 case 16:
102 ri->ri_ops.putchar = rasops24_putchar16;
103 break;
104 #endif
105 default:
106 ri->ri_ops.putchar = rasops24_putchar;
107 break;
108 }
109
110 if (ri->ri_rnum == 0) {
111 ri->ri_rnum = 8;
112 ri->ri_rpos = 0;
113 ri->ri_gnum = 8;
114 ri->ri_gpos = 8;
115 ri->ri_bnum = 8;
116 ri->ri_bpos = 16;
117 }
118
119 ri->ri_ops.erasecols = rasops24_erasecols;
120 ri->ri_ops.eraserows = rasops24_eraserows;
121 }
122
123 /*
124 * Put a single character. This is the generic version.
125 * XXX this bites - we should use masks.
126 */
127 static void
128 rasops24_putchar(cookie, row, col, uc, attr)
129 void *cookie;
130 int row, col;
131 u_int uc;
132 long attr;
133 {
134 int fb, width, height, cnt, clr[2];
135 struct rasops_info *ri;
136 u_char *dp, *rp, *fr;
137
138 ri = (struct rasops_info *)cookie;
139
140 #ifdef RASOPS_CLIPPING
141 /* Catches 'row < 0' case too */
142 if ((unsigned)row >= (unsigned)ri->ri_rows)
143 return;
144
145 if ((unsigned)col >= (unsigned)ri->ri_cols)
146 return;
147 #endif
148
149 rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
150 height = ri->ri_font->fontheight;
151 width = ri->ri_font->fontwidth;
152
153 clr[1] = ri->ri_devcmap[((u_int)attr >> 24) & 15];
154 clr[0] = ri->ri_devcmap[((u_int)attr >> 16) & 15];
155
156 if (uc == ' ') {
157 while (height--) {
158 dp = rp;
159 rp += ri->ri_stride;
160
161 for (cnt = width; cnt; cnt--) {
162 *dp++ = clr[0] >> 16;
163 *dp++ = clr[0] >> 8;
164 *dp++ = clr[0];
165 }
166 }
167 } else {
168 uc -= ri->ri_font->firstchar;
169 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
170
171 while (height--) {
172 dp = rp;
173 fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) |
174 (fr[0] << 24);
175 fr += ri->ri_font->stride;
176 rp += ri->ri_stride;
177
178 for (cnt = width; cnt; cnt--, fb <<= 1) {
179 if ((fb >> 31) & 1) {
180 *dp++ = clr[1] >> 16;
181 *dp++ = clr[1] >> 8;
182 *dp++ = clr[1];
183 } else {
184 *dp++ = clr[0] >> 16;
185 *dp++ = clr[0] >> 8;
186 *dp++ = clr[0];
187 }
188 }
189 }
190 }
191
192 /* Do underline */
193 if ((attr & 1) != 0) {
194 rp -= ri->ri_stride << 1;
195
196 while (width--) {
197 *rp++ = clr[1] >> 16;
198 *rp++ = clr[1] >> 8;
199 *rp++ = clr[1];
200 }
201 }
202 }
203
204 #ifndef RASOPS_SMALL
205 /*
206 * Recompute the blitting stamp.
207 */
208 static void
209 rasops24_makestamp(ri, attr)
210 struct rasops_info *ri;
211 long attr;
212 {
213 u_int fg, bg, c1, c2, c3, c4;
214 int i;
215
216 fg = ri->ri_devcmap[((u_int)attr >> 24) & 15] & 0xffffff;
217 bg = ri->ri_devcmap[((u_int)attr >> 16) & 15] & 0xffffff;
218 stamp_attr = attr;
219
220 for (i = 0; i < 64; i += 4) {
221 #if BYTE_ORDER == LITTLE_ENDIAN
222 c1 = (i & 32 ? fg : bg);
223 c2 = (i & 16 ? fg : bg);
224 c3 = (i & 8 ? fg : bg);
225 c4 = (i & 4 ? fg : bg);
226 #else
227 c1 = (i & 8 ? fg : bg);
228 c2 = (i & 4 ? fg : bg);
229 c3 = (i & 16 ? fg : bg);
230 c4 = (i & 32 ? fg : bg);
231 #endif
232 stamp[i+0] = (c1 << 8) | (c2 >> 16);
233 stamp[i+1] = (c2 << 16) | (c3 >> 8);
234 stamp[i+2] = (c3 << 24) | c4;
235
236 #if BYTE_ORDER == LITTLE_ENDIAN
237 if ((ri->ri_flg & RI_BSWAP) == 0) {
238 #else
239 if ((ri->ri_flg & RI_BSWAP) != 0) {
240 #endif
241 stamp[i+0] = bswap32(stamp[i+0]);
242 stamp[i+1] = bswap32(stamp[i+1]);
243 stamp[i+2] = bswap32(stamp[i+2]);
244 }
245 }
246 }
247
248 /*
249 * Put a single character. This is for 8-pixel wide fonts.
250 */
251 static void
252 rasops24_putchar8(cookie, row, col, uc, attr)
253 void *cookie;
254 int row, col;
255 u_int uc;
256 long attr;
257 {
258 struct rasops_info *ri;
259 int height, so, fs;
260 int32_t *rp;
261 u_char *fr;
262
263 /* Can't risk remaking the stamp if it's already in use */
264 if (stamp_mutex++) {
265 stamp_mutex--;
266 rasops24_putchar(cookie, row, col, uc, attr);
267 return;
268 }
269
270 ri = (struct rasops_info *)cookie;
271
272 #ifdef RASOPS_CLIPPING
273 if ((unsigned)row >= (unsigned)ri->ri_rows) {
274 stamp_mutex--;
275 return;
276 }
277
278 if ((unsigned)col >= (unsigned)ri->ri_cols) {
279 stamp_mutex--;
280 return;
281 }
282 #endif
283
284 /* Recompute stamp? */
285 if (attr != stamp_attr)
286 rasops24_makestamp(ri, attr);
287
288 rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
289 height = ri->ri_font->fontheight;
290
291 if (uc == (u_int)-1) {
292 while (height--) {
293 rp[0] = stamp[0];
294 rp[1] = stamp[0];
295 rp[2] = stamp[0];
296 rp[3] = stamp[0];
297 rp[4] = stamp[0];
298 rp[5] = stamp[0];
299 DELTA(rp, ri->ri_stride, int32_t *);
300 }
301 } else {
302 uc -= ri->ri_font->firstchar;
303 fr = (u_char *)ri->ri_font->data + uc*ri->ri_fontscale;
304 fs = ri->ri_font->stride;
305
306 while (height--) {
307 so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
308 rp[0] = STAMP_READ(so);
309 rp[1] = STAMP_READ(so + 4);
310 rp[2] = STAMP_READ(so + 8);
311
312 so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
313 rp[3] = STAMP_READ(so);
314 rp[4] = STAMP_READ(so + 4);
315 rp[5] = STAMP_READ(so + 8);
316
317 fr += fs;
318 DELTA(rp, ri->ri_stride, int32_t *);
319 }
320 }
321
322 /* Do underline */
323 if ((attr & 1) != 0) {
324 DELTA(rp, -(ri->ri_stride << 1), int32_t *);
325 rp[0] = STAMP_READ(52);
326 rp[1] = STAMP_READ(52);
327 rp[2] = STAMP_READ(52);
328 rp[3] = STAMP_READ(52);
329 rp[4] = STAMP_READ(52);
330 rp[5] = STAMP_READ(52);
331 }
332
333 stamp_mutex--;
334 }
335
336 /*
337 * Put a single character. This is for 12-pixel wide fonts.
338 */
339 static void
340 rasops24_putchar12(cookie, row, col, uc, attr)
341 void *cookie;
342 int row, col;
343 u_int uc;
344 long attr;
345 {
346 struct rasops_info *ri;
347 int height, so, fs;
348 int32_t *rp;
349 u_char *fr;
350
351 /* Can't risk remaking the stamp if it's already in use */
352 if (stamp_mutex++) {
353 stamp_mutex--;
354 rasops24_putchar(cookie, row, col, uc, attr);
355 return;
356 }
357
358 ri = (struct rasops_info *)cookie;
359
360 #ifdef RASOPS_CLIPPING
361 if ((unsigned)row >= (unsigned)ri->ri_rows) {
362 stamp_mutex--;
363 return;
364 }
365
366 if ((unsigned)col >= (unsigned)ri->ri_cols) {
367 stamp_mutex--;
368 return;
369 }
370 #endif
371
372 /* Recompute stamp? */
373 if (attr != stamp_attr)
374 rasops24_makestamp(ri, attr);
375
376 rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
377 height = ri->ri_font->fontheight;
378
379 if (uc == (u_int)-1) {
380 while (height--) {
381 rp[0] = stamp[0];
382 rp[1] = stamp[0];
383 rp[2] = stamp[0];
384 rp[3] = stamp[0];
385 rp[4] = stamp[0];
386 rp[5] = stamp[0];
387 rp[6] = stamp[0];
388 rp[7] = stamp[0];
389 rp[8] = stamp[0];
390 DELTA(rp, ri->ri_stride, int32_t *);
391 }
392 } else {
393 uc -= ri->ri_font->firstchar;
394 fr = (u_char *)ri->ri_font->data + uc*ri->ri_fontscale;
395 fs = ri->ri_font->stride;
396
397 while (height--) {
398 so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
399 rp[0] = STAMP_READ(so);
400 rp[1] = STAMP_READ(so + 4);
401 rp[2] = STAMP_READ(so + 8);
402
403 so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
404 rp[3] = STAMP_READ(so);
405 rp[4] = STAMP_READ(so + 4);
406 rp[5] = STAMP_READ(so + 8);
407
408 so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
409 rp[6] = STAMP_READ(so);
410 rp[7] = STAMP_READ(so + 4);
411 rp[8] = STAMP_READ(so + 8);
412
413 fr += fs;
414 DELTA(rp, ri->ri_stride, int32_t *);
415 }
416 }
417
418 /* Do underline */
419 if ((attr & 1) != 0) {
420 DELTA(rp, -(ri->ri_stride << 1), int32_t *);
421 rp[0] = STAMP_READ(52);
422 rp[1] = STAMP_READ(52);
423 rp[2] = STAMP_READ(52);
424 rp[3] = STAMP_READ(52);
425 rp[4] = STAMP_READ(52);
426 rp[5] = STAMP_READ(52);
427 rp[6] = STAMP_READ(52);
428 rp[7] = STAMP_READ(52);
429 rp[8] = STAMP_READ(52);
430 }
431
432 stamp_mutex--;
433 }
434
435 /*
436 * Put a single character. This is for 16-pixel wide fonts.
437 */
438 static void
439 rasops24_putchar16(cookie, row, col, uc, attr)
440 void *cookie;
441 int row, col;
442 u_int uc;
443 long attr;
444 {
445 struct rasops_info *ri;
446 int height, so, fs;
447 int32_t *rp;
448 u_char *fr;
449
450 /* Can't risk remaking the stamp if it's already in use */
451 if (stamp_mutex++) {
452 stamp_mutex--;
453 rasops24_putchar(cookie, row, col, uc, attr);
454 return;
455 }
456
457 ri = (struct rasops_info *)cookie;
458
459 #ifdef RASOPS_CLIPPING
460 if ((unsigned)row >= (unsigned)ri->ri_rows) {
461 stamp_mutex--;
462 return;
463 }
464
465 if ((unsigned)col >= (unsigned)ri->ri_cols) {
466 stamp_mutex--;
467 return;
468 }
469 #endif
470
471 /* Recompute stamp? */
472 if (attr != stamp_attr)
473 rasops24_makestamp(ri, attr);
474
475 rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
476 height = ri->ri_font->fontheight;
477
478 if (uc == (u_int)-1) {
479 while (height--) {
480 rp[0] = stamp[0];
481 rp[1] = stamp[0];
482 rp[2] = stamp[0];
483 rp[3] = stamp[0];
484 rp[4] = stamp[0];
485 rp[5] = stamp[0];
486 rp[6] = stamp[0];
487 rp[7] = stamp[0];
488 rp[8] = stamp[0];
489 rp[9] = stamp[0];
490 rp[10] = stamp[0];
491 rp[11] = stamp[0];
492 DELTA(rp, ri->ri_stride, int32_t *);
493 }
494 } else {
495 uc -= ri->ri_font->firstchar;
496 fr = (u_char *)ri->ri_font->data + uc*ri->ri_fontscale;
497 fs = ri->ri_font->stride;
498
499 while (height--) {
500 so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
501 rp[0] = STAMP_READ(so);
502 rp[1] = STAMP_READ(so + 4);
503 rp[2] = STAMP_READ(so + 8);
504
505 so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
506 rp[3] = STAMP_READ(so);
507 rp[4] = STAMP_READ(so + 4);
508 rp[5] = STAMP_READ(so + 8);
509
510 so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
511 rp[6] = STAMP_READ(so);
512 rp[7] = STAMP_READ(so + 4);
513 rp[8] = STAMP_READ(so + 8);
514
515 so = STAMP_SHIFT(fr[1], 0) & STAMP_MASK;
516 rp[9] = STAMP_READ(so);
517 rp[10] = STAMP_READ(so + 4);
518 rp[11] = STAMP_READ(so + 8);
519
520 DELTA(rp, ri->ri_stride, int32_t *);
521 fr += fs;
522 }
523 }
524
525 /* Do underline */
526 if ((attr & 1) != 0) {
527 DELTA(rp, -(ri->ri_stride << 1), int32_t *);
528 rp[0] = STAMP_READ(52);
529 rp[1] = STAMP_READ(52);
530 rp[2] = STAMP_READ(52);
531 rp[3] = STAMP_READ(52);
532 rp[4] = STAMP_READ(52);
533 rp[5] = STAMP_READ(52);
534 rp[6] = STAMP_READ(52);
535 rp[7] = STAMP_READ(52);
536 rp[8] = STAMP_READ(52);
537 rp[9] = STAMP_READ(52);
538 rp[10] = STAMP_READ(52);
539 rp[11] = STAMP_READ(52);
540 }
541
542 stamp_mutex--;
543 }
544 #endif /* !RASOPS_SMALL */
545
546 /*
547 * Erase rows. This is nice and easy due to alignment.
548 */
549 static void
550 rasops24_eraserows(cookie, row, num, attr)
551 void *cookie;
552 int row, num;
553 long attr;
554 {
555 int n9, n3, n1, cnt, stride, delta;
556 u_int32_t *dp, clr, stamp[3];
557 struct rasops_info *ri;
558
559 /*
560 * If the color is gray, we can cheat and use the generic routines
561 * (which are faster, hopefully) since the r,g,b values are the same.
562 */
563 if ((attr & 4) != 0) {
564 rasops_eraserows(cookie, row, num, attr);
565 return;
566 }
567
568 ri = (struct rasops_info *)cookie;
569
570 #ifdef RASOPS_CLIPPING
571 if (row < 0) {
572 num += row;
573 row = 0;
574 }
575
576 if ((row + num) > ri->ri_rows)
577 num = ri->ri_rows - row;
578
579 if (num <= 0)
580 return;
581 #endif
582
583 clr = ri->ri_devcmap[(attr >> 16) & 15] & 0xffffff;
584 stamp[0] = (clr << 8) | (clr >> 16);
585 stamp[1] = (clr << 16) | (clr >> 8);
586 stamp[2] = (clr << 24) | clr;
587
588 #if BYTE_ORDER == LITTLE_ENDIAN
589 if ((ri->ri_flg & RI_BSWAP) == 0) {
590 #else
591 if ((ri->ri_flg & RI_BSWAP) != 0) {
592 #endif
593 stamp[0] = bswap32(stamp[0]);
594 stamp[1] = bswap32(stamp[1]);
595 stamp[2] = bswap32(stamp[2]);
596 }
597
598 /*
599 * XXX the wsdisplay_emulops interface seems a little deficient in
600 * that there is no way to clear the *entire* screen. We provide a
601 * workaround here: if the entire console area is being cleared, and
602 * the RI_FULLCLEAR flag is set, clear the entire display.
603 */
604 if (num == ri->ri_rows && (ri->ri_flg & RI_FULLCLEAR) != 0) {
605 stride = ri->ri_stride;
606 num = ri->ri_height;
607 dp = (int32_t *)ri->ri_origbits;
608 delta = 0;
609 } else {
610 stride = ri->ri_emustride;
611 num *= ri->ri_font->fontheight;
612 dp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale);
613 delta = ri->ri_delta;
614 }
615
616 n9 = stride / 36;
617 cnt = (n9 << 5) + (n9 << 2); /* (32*n9) + (4*n9) */
618 n3 = (stride - cnt) / 12;
619 cnt += (n3 << 3) + (n3 << 2); /* (8*n3) + (4*n3) */
620 n1 = (stride - cnt) >> 2;
621
622 while (num--) {
623 for (cnt = n9; cnt; cnt--) {
624 dp[0] = stamp[0];
625 dp[1] = stamp[1];
626 dp[2] = stamp[2];
627 dp[3] = stamp[0];
628 dp[4] = stamp[1];
629 dp[5] = stamp[2];
630 dp[6] = stamp[0];
631 dp[7] = stamp[1];
632 dp[8] = stamp[2];
633 dp += 9;
634 }
635
636 for (cnt = n3; cnt; cnt--) {
637 dp[0] = stamp[0];
638 dp[1] = stamp[1];
639 dp[2] = stamp[2];
640 dp += 3;
641 }
642
643 for (cnt = 0; cnt < n1; cnt++)
644 *dp++ = stamp[cnt];
645
646 DELTA(dp, delta, int32_t *);
647 }
648 }
649
650 /*
651 * Erase columns.
652 */
653 static void
654 rasops24_erasecols(cookie, row, col, num, attr)
655 void *cookie;
656 int row, col, num;
657 long attr;
658 {
659 int n12, n4, height, cnt, slop, clr, stamp[3];
660 struct rasops_info *ri;
661 int32_t *dp, *rp;
662 u_char *dbp;
663
664 /*
665 * If the color is gray, we can cheat and use the generic routines
666 * (which are faster, hopefully) since the r,g,b values are the same.
667 */
668 if ((attr & 4) != 0) {
669 rasops_erasecols(cookie, row, col, num, attr);
670 return;
671 }
672
673 ri = (struct rasops_info *)cookie;
674
675 #ifdef RASOPS_CLIPPING
676 /* Catches 'row < 0' case too */
677 if ((unsigned)row >= (unsigned)ri->ri_rows)
678 return;
679
680 if (col < 0) {
681 num += col;
682 col = 0;
683 }
684
685 if ((col + num) > ri->ri_cols)
686 num = ri->ri_cols - col;
687
688 if (num <= 0)
689 return;
690 #endif
691
692 rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
693 num *= ri->ri_font->fontwidth;
694 height = ri->ri_font->fontheight;
695
696 clr = ri->ri_devcmap[(attr >> 16) & 15] & 0xffffff;
697 stamp[0] = (clr << 8) | (clr >> 16);
698 stamp[1] = (clr << 16) | (clr >> 8);
699 stamp[2] = (clr << 24) | clr;
700
701 #if BYTE_ORDER == LITTLE_ENDIAN
702 if ((ri->ri_flg & RI_BSWAP) == 0) {
703 #else
704 if ((ri->ri_flg & RI_BSWAP) != 0) {
705 #endif
706 stamp[0] = bswap32(stamp[0]);
707 stamp[1] = bswap32(stamp[1]);
708 stamp[2] = bswap32(stamp[2]);
709 }
710
711 /*
712 * The current byte offset mod 4 tells us the number of 24-bit pels
713 * we need to write for alignment to 32-bits. Once we're aligned on
714 * a 32-bit boundary, we're also aligned on a 4 pixel boundary, so
715 * the stamp does not need to be rotated. The following shows the
716 * layout of 4 pels in a 3 word region and illustrates this:
717 *
718 * aaab bbcc cddd
719 */
720 slop = (int)rp & 3; num -= slop;
721 n12 = num / 12; num -= (n12 << 3) + (n12 << 2);
722 n4 = num >> 2; num &= 3;
723
724 while (height--) {
725 dbp = (u_char *)rp;
726 DELTA(rp, ri->ri_stride, int32_t *);
727
728 /* Align to 4 bytes */
729 /* XXX handle with masks, bring under control of RI_BSWAP */
730 for (cnt = slop; cnt; cnt--) {
731 *dbp++ = (clr >> 16);
732 *dbp++ = (clr >> 8);
733 *dbp++ = clr;
734 }
735
736 dp = (int32_t *)dbp;
737
738 /* 12 pels per loop */
739 for (cnt = n12; cnt; cnt--) {
740 dp[0] = stamp[0];
741 dp[1] = stamp[1];
742 dp[2] = stamp[2];
743 dp[3] = stamp[0];
744 dp[4] = stamp[1];
745 dp[5] = stamp[2];
746 dp[6] = stamp[0];
747 dp[7] = stamp[1];
748 dp[8] = stamp[2];
749 dp += 9;
750 }
751
752 /* 4 pels per loop */
753 for (cnt = n4; cnt; cnt--) {
754 dp[0] = stamp[0];
755 dp[1] = stamp[1];
756 dp[2] = stamp[2];
757 dp += 3;
758 }
759
760 /* Trailing slop */
761 /* XXX handle with masks, bring under control of RI_BSWAP */
762 dbp = (u_char *)dp;
763 for (cnt = num; cnt; cnt--) {
764 *dbp++ = (clr >> 16);
765 *dbp++ = (clr >> 8);
766 *dbp++ = clr;
767 }
768 }
769 }
770