Home | History | Annotate | Line # | Download | only in rasops
rasops8.c revision 1.40
      1  1.40       rin /* 	$NetBSD: rasops8.c,v 1.40 2019/07/25 02:26:32 rin Exp $	*/
      2   1.1        ad 
      3   1.4        ad /*-
      4   1.4        ad  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5   1.1        ad  * All rights reserved.
      6   1.1        ad  *
      7   1.4        ad  * This code is derived from software contributed to The NetBSD Foundation
      8   1.9        ad  * by Andrew Doran.
      9   1.4        ad  *
     10   1.1        ad  * Redistribution and use in source and binary forms, with or without
     11   1.1        ad  * modification, are permitted provided that the following conditions
     12   1.1        ad  * are met:
     13   1.1        ad  * 1. Redistributions of source code must retain the above copyright
     14   1.1        ad  *    notice, this list of conditions and the following disclaimer.
     15   1.1        ad  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1        ad  *    notice, this list of conditions and the following disclaimer in the
     17   1.1        ad  *    documentation and/or other materials provided with the distribution.
     18   1.1        ad  *
     19   1.4        ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.4        ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.4        ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.4        ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.4        ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.4        ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.4        ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.4        ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.4        ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.4        ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.4        ad  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1        ad  */
     31   1.2        ad 
     32  1.12     lukem #include <sys/cdefs.h>
     33  1.40       rin __KERNEL_RCSID(0, "$NetBSD: rasops8.c,v 1.40 2019/07/25 02:26:32 rin Exp $");
     34  1.12     lukem 
     35   1.1        ad #include "opt_rasops.h"
     36   1.1        ad 
     37   1.1        ad #include <sys/param.h>
     38   1.1        ad #include <sys/systm.h>
     39   1.1        ad #include <sys/time.h>
     40   1.1        ad 
     41   1.1        ad #include <dev/wscons/wsdisplayvar.h>
     42   1.1        ad #include <dev/wscons/wsconsio.h>
     43   1.1        ad #include <dev/rasops/rasops.h>
     44   1.1        ad 
     45  1.18     perry static void 	rasops8_putchar(void *, int, int, u_int, long attr);
     46  1.30  macallan static void 	rasops8_putchar_aa(void *, int, int, u_int, long attr);
     47   1.7        ad #ifndef RASOPS_SMALL
     48  1.18     perry static void 	rasops8_putchar8(void *, int, int, u_int, long attr);
     49  1.18     perry static void 	rasops8_putchar12(void *, int, int, u_int, long attr);
     50  1.18     perry static void 	rasops8_putchar16(void *, int, int, u_int, long attr);
     51  1.18     perry static void	rasops8_makestamp(struct rasops_info *ri, long);
     52   1.1        ad 
     53   1.8        pk /*
     54   1.8        pk  * 4x1 stamp for optimized character blitting
     55   1.1        ad  */
     56  1.37       rin static uint32_t	stamp[16];
     57   1.1        ad static long	stamp_attr;
     58   1.1        ad static int	stamp_mutex;	/* XXX see note in README */
     59  1.10     bjh21 #endif
     60   1.1        ad 
     61   1.1        ad /*
     62   1.1        ad  * XXX this confuses the hell out of gcc2 (not egcs) which always insists
     63   1.1        ad  * that the shift count is negative.
     64   1.1        ad  *
     65   1.1        ad  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
     66   1.1        ad  * destination = STAMP_READ(offset)
     67   1.1        ad  */
     68   1.1        ad #define STAMP_SHIFT(fb,n)	((n*4-2) >= 0 ? (fb)>>(n*4-2):(fb)<<-(n*4-2))
     69   1.8        pk #define STAMP_MASK		(0xf << 2)
     70  1.37       rin #define STAMP_READ(o)		(*(uint32_t *)((char *)stamp + (o)))
     71   1.1        ad 
     72   1.1        ad /*
     73  1.11       wiz  * Initialize a 'rasops_info' descriptor for this depth.
     74   1.1        ad  */
     75   1.1        ad void
     76  1.25       dsl rasops8_init(struct rasops_info *ri)
     77   1.1        ad {
     78   1.8        pk 
     79  1.33    martin 	if (FONT_IS_ALPHA(ri->ri_font)) {
     80  1.30  macallan 		ri->ri_ops.putchar = rasops8_putchar_aa;
     81  1.30  macallan 	} else {
     82  1.30  macallan 		switch (ri->ri_font->fontwidth) {
     83   1.7        ad #ifndef RASOPS_SMALL
     84  1.30  macallan 		case 8:
     85  1.30  macallan 			ri->ri_ops.putchar = rasops8_putchar8;
     86  1.30  macallan 			break;
     87  1.30  macallan 		case 12:
     88  1.30  macallan 			ri->ri_ops.putchar = rasops8_putchar12;
     89  1.30  macallan 			break;
     90  1.30  macallan 		case 16:
     91  1.30  macallan 			ri->ri_ops.putchar = rasops8_putchar16;
     92  1.30  macallan 			break;
     93   1.7        ad #endif /* !RASOPS_SMALL */
     94  1.30  macallan 		default:
     95  1.30  macallan 			ri->ri_ops.putchar = rasops8_putchar;
     96  1.30  macallan 			break;
     97  1.30  macallan 		}
     98   1.1        ad 	}
     99  1.28  macallan 	if (ri->ri_flg & RI_8BIT_IS_RGB) {
    100  1.28  macallan 		ri->ri_rnum = 3;
    101  1.28  macallan 		ri->ri_rpos = 5;
    102  1.28  macallan 		ri->ri_gnum = 3;
    103  1.28  macallan 		ri->ri_gpos = 2;
    104  1.28  macallan 		ri->ri_bnum = 2;
    105  1.28  macallan 		ri->ri_bpos = 0;
    106  1.28  macallan 	}
    107   1.1        ad }
    108   1.1        ad 
    109   1.1        ad /*
    110   1.3        ad  * Put a single character.
    111   1.1        ad  */
    112   1.1        ad static void
    113  1.26       dsl rasops8_putchar(void *cookie, int row, int col, u_int uc, long attr)
    114   1.1        ad {
    115   1.7        ad 	int width, height, cnt, fs, fb;
    116  1.36       rin 	uint8_t *dp, *rp, *hp, *hrp, *fr, clr[2];
    117  1.27  macallan 	struct rasops_info *ri = (struct rasops_info *)cookie;
    118  1.27  macallan 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
    119   1.8        pk 
    120  1.21  jmcneill 	hp = hrp = NULL;
    121   1.1        ad 
    122  1.27  macallan 	if (!CHAR_IN_FONT(uc, font))
    123  1.17    petrov 		return;
    124  1.17    petrov 
    125   1.8        pk #ifdef RASOPS_CLIPPING
    126   1.8        pk 	/* Catches 'row < 0' case too */
    127   1.1        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    128   1.1        ad 		return;
    129   1.1        ad 
    130   1.1        ad 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    131   1.1        ad 		return;
    132   1.1        ad #endif
    133   1.1        ad 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    134  1.21  jmcneill 	if (ri->ri_hwbits)
    135  1.21  jmcneill 		hrp = ri->ri_hwbits + row * ri->ri_yscale + col *
    136  1.21  jmcneill 		    ri->ri_xscale;
    137   1.1        ad 
    138  1.27  macallan 	height = font->fontheight;
    139  1.27  macallan 	width = font->fontwidth;
    140  1.36       rin 	clr[0] = (uint8_t)ri->ri_devcmap[(attr >> 16) & 0xf];
    141  1.36       rin 	clr[1] = (uint8_t)ri->ri_devcmap[(attr >> 24) & 0xf];
    142   1.8        pk 
    143   1.1        ad 	if (uc == ' ') {
    144  1.36       rin 		uint8_t c = clr[0];
    145   1.8        pk 
    146   1.1        ad 		while (height--) {
    147  1.32  macallan 			memset(rp, c, width);
    148  1.21  jmcneill 			if (ri->ri_hwbits) {
    149  1.32  macallan 				memset(hrp, c, width);
    150  1.21  jmcneill 				hrp += ri->ri_stride;
    151  1.21  jmcneill 			}
    152  1.32  macallan 			rp += ri->ri_stride;
    153   1.1        ad 		}
    154   1.1        ad 	} else {
    155  1.29  macallan 		fr = WSFONT_GLYPH(uc, font);
    156  1.27  macallan 		fs = font->stride;
    157   1.1        ad 
    158   1.1        ad 		while (height--) {
    159   1.1        ad 			dp = rp;
    160  1.21  jmcneill 			if (ri->ri_hwbits)
    161  1.21  jmcneill 				hp = hrp;
    162  1.39       rin 			fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) |
    163  1.39       rin 			    (fr[0] << 24);
    164   1.1        ad 			fr += fs;
    165   1.1        ad 			rp += ri->ri_stride;
    166  1.21  jmcneill 			if (ri->ri_hwbits)
    167  1.21  jmcneill 				hrp += ri->ri_stride;
    168   1.8        pk 
    169   1.1        ad 			for (cnt = width; cnt; cnt--) {
    170   1.1        ad 				*dp++ = clr[(fb >> 31) & 1];
    171  1.21  jmcneill 				if (ri->ri_hwbits)
    172  1.21  jmcneill 					*hp++ = clr[(fb >> 31) & 1];
    173   1.1        ad 				fb <<= 1;
    174   1.1        ad 			}
    175   1.1        ad 		}
    176   1.8        pk 	}
    177   1.1        ad 
    178   1.1        ad 	/* Do underline */
    179  1.35   mlelstv 	if ((attr & WSATTR_UNDERLINE) != 0) {
    180  1.36       rin 		uint8_t c = clr[1];
    181   1.8        pk 
    182   1.1        ad 		rp -= (ri->ri_stride << 1);
    183  1.21  jmcneill 		if (ri->ri_hwbits)
    184  1.21  jmcneill 			hrp -= (ri->ri_stride << 1);
    185   1.1        ad 
    186  1.21  jmcneill 		while (width--) {
    187   1.8        pk 			*rp++ = c;
    188  1.21  jmcneill 			if (ri->ri_hwbits)
    189  1.21  jmcneill 				*hrp++ = c;
    190  1.21  jmcneill 		}
    191   1.8        pk 	}
    192   1.1        ad }
    193   1.1        ad 
    194  1.30  macallan static void
    195  1.30  macallan rasops8_putchar_aa(void *cookie, int row, int col, u_int uc, long attr)
    196  1.30  macallan {
    197  1.34    martin 	int width, height;
    198  1.36       rin 	uint8_t *rp, *hrp, *fr, bg, fg, pixel;
    199  1.30  macallan 	struct rasops_info *ri = (struct rasops_info *)cookie;
    200  1.30  macallan 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
    201  1.30  macallan 	int x, y, r, g, b, aval;
    202  1.30  macallan 	int r1, g1, b1, r0, g0, b0, fgo, bgo;
    203  1.31  macallan 	uint8_t scanline[32] __attribute__ ((aligned(8)));
    204  1.30  macallan 
    205  1.34    martin 	hrp = NULL;
    206  1.30  macallan 
    207  1.30  macallan 	if (!CHAR_IN_FONT(uc, font))
    208  1.30  macallan 		return;
    209  1.30  macallan 
    210  1.30  macallan #ifdef RASOPS_CLIPPING
    211  1.30  macallan 	/* Catches 'row < 0' case too */
    212  1.30  macallan 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    213  1.30  macallan 		return;
    214  1.30  macallan 
    215  1.30  macallan 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    216  1.30  macallan 		return;
    217  1.30  macallan #endif
    218  1.30  macallan 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    219  1.30  macallan 	if (ri->ri_hwbits)
    220  1.30  macallan 		hrp = ri->ri_hwbits + row * ri->ri_yscale + col *
    221  1.30  macallan 		    ri->ri_xscale;
    222  1.30  macallan 
    223  1.30  macallan 	height = font->fontheight;
    224  1.30  macallan 	width = font->fontwidth;
    225  1.36       rin 	bg = (uint8_t)ri->ri_devcmap[(attr >> 16) & 0xf];
    226  1.36       rin 	fg = (uint8_t)ri->ri_devcmap[(attr >> 24) & 0xf];
    227  1.30  macallan 
    228  1.30  macallan 	if (uc == ' ') {
    229  1.30  macallan 
    230  1.30  macallan 		while (height--) {
    231  1.32  macallan 			memset(rp, bg, width);
    232  1.30  macallan 			if (ri->ri_hwbits) {
    233  1.32  macallan 				memset(hrp, bg, width);
    234  1.30  macallan 				hrp += ri->ri_stride;
    235  1.30  macallan 			}
    236  1.32  macallan 			rp += ri->ri_stride;
    237  1.30  macallan 		}
    238  1.30  macallan 	} else {
    239  1.30  macallan 		fr = WSFONT_GLYPH(uc, font);
    240  1.30  macallan 		/*
    241  1.30  macallan 		 * we need the RGB colours here, get offsets into rasops_cmap
    242  1.30  macallan 		 */
    243  1.30  macallan 		fgo = ((attr >> 24) & 0xf) * 3;
    244  1.30  macallan 		bgo = ((attr >> 16) & 0xf) * 3;
    245  1.30  macallan 
    246  1.30  macallan 		r0 = rasops_cmap[bgo];
    247  1.30  macallan 		r1 = rasops_cmap[fgo];
    248  1.30  macallan 		g0 = rasops_cmap[bgo + 1];
    249  1.30  macallan 		g1 = rasops_cmap[fgo + 1];
    250  1.30  macallan 		b0 = rasops_cmap[bgo + 2];
    251  1.30  macallan 		b1 = rasops_cmap[fgo + 2];
    252  1.30  macallan 
    253  1.30  macallan 		for (y = 0; y < height; y++) {
    254  1.30  macallan 			for (x = 0; x < width; x++) {
    255  1.30  macallan 				aval = *fr;
    256  1.30  macallan 				fr++;
    257  1.30  macallan 				if (aval == 0) {
    258  1.30  macallan 					pixel = bg;
    259  1.30  macallan 				} else if (aval == 255) {
    260  1.30  macallan 					pixel = fg;
    261  1.30  macallan 				} else {
    262  1.30  macallan 					r = aval * r1 + (255 - aval) * r0;
    263  1.30  macallan 					g = aval * g1 + (255 - aval) * g0;
    264  1.30  macallan 					b = aval * b1 + (255 - aval) * b0;
    265  1.30  macallan 					pixel = ((r & 0xe000) >> 8) |
    266  1.30  macallan 						((g & 0xe000) >> 11) |
    267  1.30  macallan 						((b & 0xc000) >> 14);
    268  1.30  macallan 				}
    269  1.31  macallan 				scanline[x] = pixel;
    270  1.30  macallan 			}
    271  1.31  macallan 			memcpy(rp, scanline, width);
    272  1.30  macallan 			if (ri->ri_hwbits) {
    273  1.31  macallan 				memcpy(hrp, scanline, width);
    274  1.30  macallan 				hrp += ri->ri_stride;
    275  1.30  macallan 			}
    276  1.30  macallan 			rp += ri->ri_stride;
    277  1.30  macallan 
    278  1.30  macallan 		}
    279  1.30  macallan 	}
    280  1.30  macallan 
    281  1.30  macallan 	/* Do underline */
    282  1.35   mlelstv 	if ((attr & WSATTR_UNDERLINE) != 0) {
    283  1.30  macallan 
    284  1.30  macallan 		rp -= (ri->ri_stride << 1);
    285  1.30  macallan 		if (ri->ri_hwbits)
    286  1.30  macallan 			hrp -= (ri->ri_stride << 1);
    287  1.30  macallan 
    288  1.30  macallan 		while (width--) {
    289  1.30  macallan 			*rp++ = fg;
    290  1.30  macallan 			if (ri->ri_hwbits)
    291  1.30  macallan 				*hrp++ = fg;
    292  1.30  macallan 		}
    293  1.30  macallan 	}
    294  1.30  macallan }
    295  1.30  macallan 
    296   1.7        ad #ifndef RASOPS_SMALL
    297   1.1        ad /*
    298   1.1        ad  * Recompute the 4x1 blitting stamp.
    299   1.1        ad  */
    300   1.1        ad static void
    301  1.25       dsl rasops8_makestamp(struct rasops_info *ri, long attr)
    302   1.1        ad {
    303  1.37       rin 	uint32_t fg, bg;
    304   1.1        ad 	int i;
    305   1.5        ad 
    306   1.8        pk 	fg = ri->ri_devcmap[(attr >> 24) & 0xf] & 0xff;
    307   1.8        pk 	bg = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xff;
    308   1.1        ad 	stamp_attr = attr;
    309   1.8        pk 
    310   1.1        ad 	for (i = 0; i < 16; i++) {
    311  1.16       uwe #if BYTE_ORDER == BIG_ENDIAN
    312  1.16       uwe #define NEED_LITTLE_ENDIAN_STAMP RI_BSWAP
    313   1.1        ad #else
    314  1.16       uwe #define NEED_LITTLE_ENDIAN_STAMP 0
    315   1.1        ad #endif
    316  1.16       uwe 		if ((ri->ri_flg & RI_BSWAP) == NEED_LITTLE_ENDIAN_STAMP) {
    317  1.16       uwe 			/* little endian */
    318  1.16       uwe 			stamp[i] = (i & 8 ? fg : bg);
    319  1.16       uwe 			stamp[i] |= ((i & 4 ? fg : bg) << 8);
    320  1.16       uwe 			stamp[i] |= ((i & 2 ? fg : bg) << 16);
    321  1.16       uwe 			stamp[i] |= ((i & 1 ? fg : bg) << 24);
    322  1.16       uwe 		} else {
    323  1.16       uwe 			/* big endian */
    324  1.16       uwe 			stamp[i] = (i & 1 ? fg : bg);
    325  1.16       uwe 			stamp[i] |= ((i & 2 ? fg : bg) << 8);
    326  1.16       uwe 			stamp[i] |= ((i & 4 ? fg : bg) << 16);
    327  1.16       uwe 			stamp[i] |= ((i & 8 ? fg : bg) << 24);
    328  1.16       uwe 		}
    329   1.1        ad 	}
    330   1.1        ad }
    331   1.1        ad 
    332   1.1        ad /*
    333   1.3        ad  * Put a single character. This is for 8-pixel wide fonts.
    334   1.1        ad  */
    335   1.1        ad static void
    336  1.26       dsl rasops8_putchar8(void *cookie, int row, int col, u_int uc, long attr)
    337   1.1        ad {
    338  1.27  macallan 	struct rasops_info *ri = (struct rasops_info *)cookie;
    339  1.27  macallan 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
    340   1.1        ad 	int height, fs;
    341  1.37       rin 	uint32_t *rp, *hp;
    342  1.36       rin 	uint8_t *fr;
    343   1.8        pk 
    344   1.1        ad 	/* Can't risk remaking the stamp if it's already in use */
    345   1.1        ad 	if (stamp_mutex++) {
    346   1.1        ad 		stamp_mutex--;
    347   1.1        ad 		rasops8_putchar(cookie, row, col, uc, attr);
    348   1.1        ad 		return;
    349   1.1        ad 	}
    350   1.1        ad 
    351  1.21  jmcneill 	hp = NULL;
    352   1.1        ad 
    353  1.27  macallan 	if (!CHAR_IN_FONT(uc, font))
    354  1.17    petrov 		return;
    355  1.17    petrov 
    356   1.8        pk #ifdef RASOPS_CLIPPING
    357   1.1        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    358   1.1        ad 		stamp_mutex--;
    359   1.1        ad 		return;
    360   1.1        ad 	}
    361   1.1        ad 
    362   1.1        ad 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    363   1.1        ad 		stamp_mutex--;
    364   1.1        ad 		return;
    365   1.1        ad 	}
    366   1.1        ad #endif
    367   1.1        ad 
    368   1.1        ad 	/* Recompute stamp? */
    369   1.1        ad 	if (attr != stamp_attr)
    370   1.6        ad 		rasops8_makestamp(ri, attr);
    371   1.8        pk 
    372  1.37       rin 	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    373  1.21  jmcneill 	if (ri->ri_hwbits)
    374  1.37       rin 		hp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
    375  1.21  jmcneill 		    col*ri->ri_xscale);
    376  1.27  macallan 	height = font->fontheight;
    377   1.8        pk 
    378   1.1        ad 	if (uc == ' ') {
    379   1.1        ad 		while (height--) {
    380   1.8        pk 			rp[0] = rp[1] = stamp[0];
    381  1.37       rin 			DELTA(rp, ri->ri_stride, uint32_t *);
    382  1.21  jmcneill 			if (ri->ri_hwbits) {
    383  1.39       rin 				hp[0] = hp[1] = stamp[0];
    384  1.37       rin 				DELTA(hp, ri->ri_stride, uint32_t *);
    385  1.21  jmcneill 			}
    386   1.8        pk 		}
    387   1.1        ad 	} else {
    388  1.29  macallan 		fr = WSFONT_GLYPH(uc, font);
    389  1.27  macallan 		fs = font->stride;
    390   1.8        pk 
    391   1.1        ad 		while (height--) {
    392   1.1        ad 			rp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
    393   1.1        ad 			rp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
    394  1.21  jmcneill 			if (ri->ri_hwbits) {
    395  1.21  jmcneill 				hp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) &
    396  1.21  jmcneill 				    STAMP_MASK);
    397  1.21  jmcneill 				hp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) &
    398  1.21  jmcneill 				    STAMP_MASK);
    399  1.21  jmcneill 			}
    400   1.1        ad 
    401   1.1        ad 			fr += fs;
    402  1.37       rin 			DELTA(rp, ri->ri_stride, uint32_t *);
    403  1.21  jmcneill 			if (ri->ri_hwbits)
    404  1.37       rin 				DELTA(hp, ri->ri_stride, uint32_t *);
    405   1.1        ad 		}
    406   1.1        ad 	}
    407   1.1        ad 
    408   1.1        ad 	/* Do underline */
    409  1.35   mlelstv 	if ((attr & WSATTR_UNDERLINE) != 0) {
    410  1.37       rin 		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
    411   1.8        pk 		rp[0] = rp[1] = stamp[15];
    412  1.21  jmcneill 		if (ri->ri_hwbits) {
    413  1.37       rin 			DELTA(hp, -(ri->ri_stride << 1), uint32_t *);
    414  1.39       rin 			hp[0] = hp[1] = stamp[15];
    415  1.21  jmcneill 		}
    416   1.8        pk 	}
    417   1.8        pk 
    418   1.8        pk 	stamp_mutex--;
    419   1.1        ad }
    420   1.1        ad 
    421   1.1        ad /*
    422   1.3        ad  * Put a single character. This is for 12-pixel wide fonts.
    423   1.1        ad  */
    424   1.1        ad static void
    425  1.26       dsl rasops8_putchar12(void *cookie, int row, int col, u_int uc, long attr)
    426   1.1        ad {
    427  1.27  macallan 	struct rasops_info *ri = (struct rasops_info *)cookie;
    428  1.27  macallan 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
    429   1.1        ad 	int height, fs;
    430  1.37       rin 	uint32_t *rp,  *hrp;
    431  1.36       rin 	uint8_t *fr;
    432   1.8        pk 
    433   1.1        ad 	/* Can't risk remaking the stamp if it's already in use */
    434   1.1        ad 	if (stamp_mutex++) {
    435   1.1        ad 		stamp_mutex--;
    436   1.1        ad 		rasops8_putchar(cookie, row, col, uc, attr);
    437   1.1        ad 		return;
    438   1.1        ad 	}
    439   1.1        ad 
    440  1.21  jmcneill 	hrp = NULL;
    441   1.1        ad 
    442  1.27  macallan 	if (!CHAR_IN_FONT(uc, font))
    443  1.39       rin 		return;
    444  1.17    petrov 
    445   1.8        pk #ifdef RASOPS_CLIPPING
    446   1.1        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    447   1.1        ad 		stamp_mutex--;
    448   1.1        ad 		return;
    449   1.1        ad 	}
    450   1.1        ad 
    451   1.1        ad 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    452   1.1        ad 		stamp_mutex--;
    453   1.1        ad 		return;
    454   1.1        ad 	}
    455   1.1        ad #endif
    456   1.1        ad 
    457   1.1        ad 	/* Recompute stamp? */
    458   1.1        ad 	if (attr != stamp_attr)
    459   1.6        ad 		rasops8_makestamp(ri, attr);
    460   1.8        pk 
    461  1.37       rin 	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    462  1.21  jmcneill 	if (ri->ri_hwbits)
    463  1.37       rin 		hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
    464  1.21  jmcneill 		    col*ri->ri_xscale);
    465  1.27  macallan 	height = font->fontheight;
    466   1.8        pk 
    467   1.1        ad 	if (uc == ' ') {
    468   1.1        ad 		while (height--) {
    469  1.39       rin 			rp[0] = rp[1] = rp[2] = stamp[0];
    470  1.37       rin 			DELTA(rp, ri->ri_stride, uint32_t *);
    471  1.21  jmcneill 			if (ri->ri_hwbits) {
    472  1.39       rin 				hrp[0] = hrp[1] = hrp[2] = stamp[0];
    473  1.37       rin 				DELTA(hrp, ri->ri_stride, uint32_t *);
    474  1.21  jmcneill 			}
    475   1.8        pk 		}
    476   1.1        ad 	} else {
    477  1.29  macallan 		fr = WSFONT_GLYPH(uc, font);
    478  1.27  macallan 		fs = font->stride;
    479   1.8        pk 
    480   1.1        ad 		while (height--) {
    481   1.1        ad 			rp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
    482   1.1        ad 			rp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
    483   1.1        ad 			rp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) & STAMP_MASK);
    484  1.21  jmcneill 			if (ri->ri_hwbits) {
    485  1.40       rin 				hrp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) &
    486  1.40       rin 				    STAMP_MASK);
    487  1.40       rin 				hrp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) &
    488  1.40       rin 				    STAMP_MASK);
    489  1.40       rin 				hrp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) &
    490  1.40       rin 				    STAMP_MASK);
    491  1.21  jmcneill 			}
    492   1.8        pk 
    493   1.1        ad 			fr += fs;
    494  1.37       rin 			DELTA(rp, ri->ri_stride, uint32_t *);
    495  1.21  jmcneill 			if (ri->ri_hwbits)
    496  1.37       rin 				DELTA(hrp, ri->ri_stride, uint32_t *);
    497   1.1        ad 		}
    498   1.8        pk 	}
    499   1.1        ad 
    500   1.1        ad 	/* Do underline */
    501  1.35   mlelstv 	if ((attr & WSATTR_UNDERLINE) != 0) {
    502  1.37       rin 		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
    503   1.8        pk 		rp[0] = rp[1] = rp[2] = stamp[15];
    504  1.21  jmcneill 		if (ri->ri_hwbits) {
    505  1.37       rin 			DELTA(hrp, -(ri->ri_stride << 1), uint32_t *);
    506  1.39       rin 			hrp[0] = hrp[1] = hrp[2] = stamp[15];
    507  1.21  jmcneill 		}
    508   1.8        pk 	}
    509   1.8        pk 
    510   1.1        ad 	stamp_mutex--;
    511   1.1        ad }
    512   1.1        ad 
    513   1.1        ad /*
    514   1.3        ad  * Put a single character. This is for 16-pixel wide fonts.
    515   1.1        ad  */
    516   1.1        ad static void
    517  1.26       dsl rasops8_putchar16(void *cookie, int row, int col, u_int uc, long attr)
    518   1.1        ad {
    519  1.27  macallan 	struct rasops_info *ri = (struct rasops_info *)cookie;
    520  1.27  macallan 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
    521   1.1        ad 	int height, fs;
    522  1.37       rin 	uint32_t *rp, *hrp;
    523  1.36       rin 	uint8_t *fr;
    524   1.1        ad 
    525   1.1        ad 	/* Can't risk remaking the stamp if it's already in use */
    526   1.1        ad 	if (stamp_mutex++) {
    527   1.1        ad 		stamp_mutex--;
    528   1.1        ad 		rasops8_putchar(cookie, row, col, uc, attr);
    529   1.1        ad 		return;
    530   1.1        ad 	}
    531   1.1        ad 
    532  1.21  jmcneill 	hrp = NULL;
    533   1.1        ad 
    534  1.27  macallan 	if (!CHAR_IN_FONT(uc, font))
    535  1.17    petrov 		return;
    536  1.17    petrov 
    537   1.8        pk #ifdef RASOPS_CLIPPING
    538   1.1        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    539   1.1        ad 		stamp_mutex--;
    540   1.1        ad 		return;
    541   1.1        ad 	}
    542   1.1        ad 
    543   1.1        ad 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    544   1.1        ad 		stamp_mutex--;
    545   1.1        ad 		return;
    546   1.1        ad 	}
    547   1.1        ad #endif
    548   1.1        ad 
    549   1.1        ad 	/* Recompute stamp? */
    550   1.1        ad 	if (attr != stamp_attr)
    551   1.6        ad 		rasops8_makestamp(ri, attr);
    552   1.8        pk 
    553  1.37       rin 	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    554  1.21  jmcneill 	if (ri->ri_hwbits)
    555  1.37       rin 		hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
    556  1.21  jmcneill 		    col*ri->ri_xscale);
    557  1.27  macallan 	height = font->fontheight;
    558   1.8        pk 
    559   1.1        ad 	if (uc == ' ') {
    560  1.21  jmcneill 		while (height--) {
    561   1.8        pk 			rp[0] = rp[1] = rp[2] = rp[3] = stamp[0];
    562  1.38       rin 			DELTA(rp, ri->ri_stride, uint32_t *);
    563  1.23  jmcneill 			if (ri->ri_hwbits) {
    564  1.39       rin 				hrp[0] = hrp[1] = hrp[2] = hrp[3] = stamp[0];
    565  1.38       rin 				DELTA(hrp, ri->ri_stride, uint32_t *);
    566  1.23  jmcneill 			}
    567  1.21  jmcneill 		}
    568   1.1        ad 	} else {
    569  1.29  macallan 		fr = WSFONT_GLYPH(uc, font);
    570  1.27  macallan 		fs = font->stride;
    571   1.8        pk 
    572   1.1        ad 		while (height--) {
    573   1.1        ad 			rp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
    574   1.1        ad 			rp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
    575   1.1        ad 			rp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) & STAMP_MASK);
    576   1.1        ad 			rp[3] = STAMP_READ(STAMP_SHIFT(fr[1], 0) & STAMP_MASK);
    577  1.21  jmcneill 			if (ri->ri_hwbits) {
    578  1.40       rin 				hrp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) &
    579  1.40       rin 				    STAMP_MASK);
    580  1.40       rin 				hrp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) &
    581  1.40       rin 				    STAMP_MASK);
    582  1.40       rin 				hrp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) &
    583  1.40       rin 				    STAMP_MASK);
    584  1.40       rin 				hrp[3] = STAMP_READ(STAMP_SHIFT(fr[1], 0) &
    585  1.40       rin 				    STAMP_MASK);
    586  1.21  jmcneill 			}
    587   1.1        ad 
    588   1.1        ad 			fr += fs;
    589  1.37       rin 			DELTA(rp, ri->ri_stride, uint32_t *);
    590  1.21  jmcneill 			if (ri->ri_hwbits)
    591  1.37       rin 				DELTA(hrp, ri->ri_stride, uint32_t *);
    592   1.1        ad 		}
    593   1.8        pk 	}
    594   1.1        ad 
    595   1.1        ad 	/* Do underline */
    596  1.35   mlelstv 	if ((attr & WSATTR_UNDERLINE) != 0) {
    597  1.37       rin 		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
    598   1.8        pk 		rp[0] = rp[1] = rp[2] = rp[3] = stamp[15];
    599  1.21  jmcneill 		if (ri->ri_hwbits) {
    600  1.37       rin 			DELTA(hrp, -(ri->ri_stride << 1), uint32_t *);
    601  1.39       rin 			hrp[0] = hrp[1] = hrp[2] = hrp[3] = stamp[15];
    602  1.21  jmcneill 		}
    603   1.8        pk 	}
    604   1.8        pk 
    605   1.1        ad 	stamp_mutex--;
    606   1.1        ad }
    607   1.7        ad #endif /* !RASOPS_SMALL */
    608