rasops24.c revision 1.9 1 /* $NetBSD: rasops24.c,v 1.9 1999/10/23 23:14:14 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.9 1999/10/23 23:14:14 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(30);
326 rp[1] = STAMP_READ(30);
327 rp[2] = STAMP_READ(30);
328 rp[3] = STAMP_READ(30);
329 rp[4] = STAMP_READ(30);
330 rp[5] = STAMP_READ(30);
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(30);
422 rp[1] = STAMP_READ(30);
423 rp[2] = STAMP_READ(30);
424 rp[3] = STAMP_READ(30);
425 rp[4] = STAMP_READ(30);
426 rp[5] = STAMP_READ(30);
427 rp[6] = STAMP_READ(30);
428 rp[7] = STAMP_READ(30);
429 rp[8] = STAMP_READ(30);
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(30);
529 rp[1] = STAMP_READ(30);
530 rp[2] = STAMP_READ(30);
531 rp[3] = STAMP_READ(30);
532 rp[4] = STAMP_READ(30);
533 rp[5] = STAMP_READ(30);
534 rp[6] = STAMP_READ(30);
535 rp[7] = STAMP_READ(30);
536 rp[8] = STAMP_READ(30);
537 rp[9] = STAMP_READ(30);
538 rp[10] = STAMP_READ(30);
539 rp[11] = STAMP_READ(30);
540 }
541
542 stamp_mutex--;
543 }
544
545 /*
546 * Erase rows. This is nice and easy due to alignment.
547 */
548 static void
549 rasops24_eraserows(cookie, row, num, attr)
550 void *cookie;
551 int row, num;
552 long attr;
553 {
554 int n9, n3, n1, cnt, stride, delta;
555 u_int32_t *dp, clr, stamp[3];
556 struct rasops_info *ri;
557
558 /*
559 * If the color is gray, we can cheat and use the generic routines
560 * (which are faster, hopefully) since the r,g,b values are the same.
561 */
562 if ((attr & 4) != 0) {
563 rasops_eraserows(cookie, row, num, attr);
564 return;
565 }
566
567 ri = (struct rasops_info *)cookie;
568
569 #ifdef RASOPS_CLIPPING
570 if (row < 0) {
571 num += row;
572 row = 0;
573 }
574
575 if ((row + num) > ri->ri_rows)
576 num = ri->ri_rows - row;
577
578 if (num <= 0)
579 return;
580 #endif
581
582 clr = ri->ri_devcmap[(attr >> 16) & 15] & 0xffffff;
583 stamp[0] = (clr << 8) | (clr >> 16);
584 stamp[1] = (clr << 16) | (clr >> 8);
585 stamp[2] = (clr << 24) | clr;
586
587 #if BYTE_ORDER == LITTLE_ENDIAN
588 if ((ri->ri_flg & RI_BSWAP) == 0) {
589 #else
590 if ((ri->ri_flg & RI_BSWAP) != 0) {
591 #endif
592 stamp[0] = bswap32(stamp[0]);
593 stamp[1] = bswap32(stamp[1]);
594 stamp[2] = bswap32(stamp[2]);
595 }
596
597 /*
598 * XXX the wsdisplay_emulops interface seems a little deficient in
599 * that there is no way to clear the *entire* screen. We provide a
600 * workaround here: if the entire console area is being cleared, and
601 * the RI_FULLCLEAR flag is set, clear the entire display.
602 */
603 if (num == ri->ri_rows && (ri->ri_flg & RI_FULLCLEAR) != 0) {
604 stride = ri->ri_stride;
605 num = ri->ri_height;
606 dp = (int32_t *)ri->ri_origbits;
607 delta = 0;
608 } else {
609 stride = ri->ri_emustride;
610 num *= ri->ri_font->fontheight;
611 dp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale);
612 delta = ri->ri_delta;
613 }
614
615 n9 = stride / 36;
616 cnt = (n9 << 5) + (n9 << 2); /* (32*n9) + (4*n9) */
617 n3 = (stride - cnt) / 12;
618 cnt += (n3 << 3) + (n3 << 2); /* (8*n3) + (4*n3) */
619 n1 = (stride - cnt) >> 2;
620
621 while (num--) {
622 for (cnt = n9; cnt; cnt--) {
623 dp[0] = stamp[0];
624 dp[1] = stamp[1];
625 dp[2] = stamp[2];
626 dp[3] = stamp[0];
627 dp[4] = stamp[1];
628 dp[5] = stamp[2];
629 dp[6] = stamp[0];
630 dp[7] = stamp[1];
631 dp[8] = stamp[2];
632 dp += 9;
633 }
634
635 for (cnt = n3; cnt; cnt--) {
636 dp[0] = stamp[0];
637 dp[1] = stamp[1];
638 dp[2] = stamp[2];
639 dp += 3;
640 }
641
642 for (cnt = 0; cnt < n1; cnt++)
643 *dp++ = stamp[cnt];
644
645 DELTA(dp, delta, int32_t *);
646 }
647 }
648
649 /*
650 * Erase columns.
651 */
652 static void
653 rasops24_erasecols(cookie, row, col, num, attr)
654 void *cookie;
655 int row, col, num;
656 long attr;
657 {
658 int n12, n4, height, cnt, slop, clr, stamp[3];
659 struct rasops_info *ri;
660 int32_t *dp, *rp;
661 u_char *dbp;
662
663 /*
664 * If the color is gray, we can cheat and use the generic routines
665 * (which are faster, hopefully) since the r,g,b values are the same.
666 */
667 if ((attr & 4) != 0) {
668 rasops_erasecols(cookie, row, col, num, attr);
669 return;
670 }
671
672 ri = (struct rasops_info *)cookie;
673
674 #ifdef RASOPS_CLIPPING
675 /* Catches 'row < 0' case too */
676 if ((unsigned)row >= (unsigned)ri->ri_rows)
677 return;
678
679 if (col < 0) {
680 num += col;
681 col = 0;
682 }
683
684 if ((col + num) > ri->ri_cols)
685 num = ri->ri_cols - col;
686
687 if (num <= 0)
688 return;
689 #endif
690
691 rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
692 num *= ri->ri_font->fontwidth;
693 height = ri->ri_font->fontheight;
694
695 clr = ri->ri_devcmap[(attr >> 16) & 15] & 0xffffff;
696 stamp[0] = (clr << 8) | (clr >> 16);
697 stamp[1] = (clr << 16) | (clr >> 8);
698 stamp[2] = (clr << 24) | clr;
699
700 #if BYTE_ORDER == LITTLE_ENDIAN
701 if ((ri->ri_flg & RI_BSWAP) == 0) {
702 #else
703 if ((ri->ri_flg & RI_BSWAP) != 0) {
704 #endif
705 stamp[0] = bswap32(stamp[0]);
706 stamp[1] = bswap32(stamp[1]);
707 stamp[2] = bswap32(stamp[2]);
708 }
709
710 /*
711 * The current byte offset mod 4 tells us the number of 24-bit pels
712 * we need to write for alignment to 32-bits. Once we're aligned on
713 * a 32-bit boundary, we're also aligned on a 4 pixel boundary, so
714 * the stamp does not need to be rotated. The following shows the
715 * layout of 4 pels in a 3 word region and illustrates this:
716 *
717 * aaab bbcc cddd
718 */
719 slop = (int)rp & 3; num -= slop;
720 n12 = num / 12; num -= (n12 << 3) + (n12 << 2);
721 n4 = num >> 2; num &= 3;
722
723 while (height--) {
724 dbp = (u_char *)rp;
725 DELTA(rp, ri->ri_stride, int32_t *);
726
727 /* Align to 4 bytes */
728 /* XXX handle with masks, bring under control of RI_BSWAP */
729 for (cnt = slop; cnt; cnt--) {
730 *dbp++ = (clr >> 16);
731 *dbp++ = (clr >> 8);
732 *dbp++ = clr;
733 }
734
735 dp = (int32_t *)dbp;
736
737 /* 12 pels per loop */
738 for (cnt = n12; cnt; cnt--) {
739 dp[0] = stamp[0];
740 dp[1] = stamp[1];
741 dp[2] = stamp[2];
742 dp[3] = stamp[0];
743 dp[4] = stamp[1];
744 dp[5] = stamp[2];
745 dp[6] = stamp[0];
746 dp[7] = stamp[1];
747 dp[8] = stamp[2];
748 dp += 9;
749 }
750
751 /* 4 pels per loop */
752 for (cnt = n4; cnt; cnt--) {
753 dp[0] = stamp[0];
754 dp[1] = stamp[1];
755 dp[2] = stamp[2];
756 dp += 3;
757 }
758
759 /* Trailing slop */
760 /* XXX handle with masks, bring under control of RI_BSWAP */
761 dbp = (u_char *)dp;
762 for (cnt = num; cnt; cnt--) {
763 *dbp++ = (clr >> 16);
764 *dbp++ = (clr >> 8);
765 *dbp++ = clr;
766 }
767 }
768 }
769 #endif /* !RASOPS_SMALL */
770