Home | History | Annotate | Line # | Download | only in rasops
rasops8.c revision 1.30
      1  1.30  macallan /* 	$NetBSD: rasops8.c,v 1.30 2012/01/04 20:16:20 macallan 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.30  macallan __KERNEL_RCSID(0, "$NetBSD: rasops8.c,v 1.30 2012/01/04 20:16:20 macallan 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.1        ad static int32_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.22  christos #define STAMP_READ(o)		(*(int32_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.30  macallan 	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.21  jmcneill 	u_char *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.8        pk 	clr[0] = (u_char)ri->ri_devcmap[(attr >> 16) & 0xf];
    141   1.8        pk 	clr[1] = (u_char)ri->ri_devcmap[(attr >> 24) & 0xf];
    142   1.8        pk 
    143   1.1        ad 	if (uc == ' ') {
    144   1.8        pk 		u_char c = clr[0];
    145   1.8        pk 
    146   1.1        ad 		while (height--) {
    147   1.1        ad 			dp = rp;
    148   1.1        ad 			rp += ri->ri_stride;
    149  1.21  jmcneill 			if (ri->ri_hwbits) {
    150  1.21  jmcneill 				hp = hrp;
    151  1.21  jmcneill 				hrp += ri->ri_stride;
    152  1.21  jmcneill 			}
    153   1.8        pk 
    154  1.21  jmcneill 			for (cnt = width; cnt; cnt--) {
    155   1.8        pk 				*dp++ = c;
    156  1.21  jmcneill 				if (ri->ri_hwbits)
    157  1.21  jmcneill 					*hp++ = c;
    158  1.21  jmcneill 			}
    159   1.1        ad 		}
    160   1.1        ad 	} else {
    161  1.29  macallan 		fr = WSFONT_GLYPH(uc, font);
    162  1.27  macallan 		fs = font->stride;
    163   1.1        ad 
    164   1.1        ad 		while (height--) {
    165   1.1        ad 			dp = rp;
    166  1.21  jmcneill 			if (ri->ri_hwbits)
    167  1.21  jmcneill 				hp = hrp;
    168   1.1        ad 			fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) | (fr[0] << 24);
    169   1.1        ad 			fr += fs;
    170   1.1        ad 			rp += ri->ri_stride;
    171  1.21  jmcneill 			if (ri->ri_hwbits)
    172  1.21  jmcneill 				hrp += ri->ri_stride;
    173   1.8        pk 
    174   1.1        ad 			for (cnt = width; cnt; cnt--) {
    175   1.1        ad 				*dp++ = clr[(fb >> 31) & 1];
    176  1.21  jmcneill 				if (ri->ri_hwbits)
    177  1.21  jmcneill 					*hp++ = clr[(fb >> 31) & 1];
    178   1.1        ad 				fb <<= 1;
    179   1.1        ad 			}
    180   1.1        ad 		}
    181   1.8        pk 	}
    182   1.1        ad 
    183   1.1        ad 	/* Do underline */
    184   1.7        ad 	if ((attr & 1) != 0) {
    185   1.8        pk 		u_char c = clr[1];
    186   1.8        pk 
    187   1.1        ad 		rp -= (ri->ri_stride << 1);
    188  1.21  jmcneill 		if (ri->ri_hwbits)
    189  1.21  jmcneill 			hrp -= (ri->ri_stride << 1);
    190   1.1        ad 
    191  1.21  jmcneill 		while (width--) {
    192   1.8        pk 			*rp++ = c;
    193  1.21  jmcneill 			if (ri->ri_hwbits)
    194  1.21  jmcneill 				*hrp++ = c;
    195  1.21  jmcneill 		}
    196   1.8        pk 	}
    197   1.1        ad }
    198   1.1        ad 
    199  1.30  macallan static void
    200  1.30  macallan rasops8_putchar_aa(void *cookie, int row, int col, u_int uc, long attr)
    201  1.30  macallan {
    202  1.30  macallan 	int width, height, cnt, fs;
    203  1.30  macallan 	u_char *dp, *rp, *hp, *hrp, *fr, bg, fg, pixel;
    204  1.30  macallan 	struct rasops_info *ri = (struct rasops_info *)cookie;
    205  1.30  macallan 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
    206  1.30  macallan 	int x, y, r, g, b, aval;
    207  1.30  macallan 	int r1, g1, b1, r0, g0, b0, fgo, bgo;
    208  1.30  macallan 
    209  1.30  macallan 	hp = hrp = NULL;
    210  1.30  macallan 
    211  1.30  macallan 	if (!CHAR_IN_FONT(uc, font))
    212  1.30  macallan 		return;
    213  1.30  macallan 
    214  1.30  macallan #ifdef RASOPS_CLIPPING
    215  1.30  macallan 	/* Catches 'row < 0' case too */
    216  1.30  macallan 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    217  1.30  macallan 		return;
    218  1.30  macallan 
    219  1.30  macallan 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    220  1.30  macallan 		return;
    221  1.30  macallan #endif
    222  1.30  macallan 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    223  1.30  macallan 	if (ri->ri_hwbits)
    224  1.30  macallan 		hrp = ri->ri_hwbits + row * ri->ri_yscale + col *
    225  1.30  macallan 		    ri->ri_xscale;
    226  1.30  macallan 
    227  1.30  macallan 	height = font->fontheight;
    228  1.30  macallan 	width = font->fontwidth;
    229  1.30  macallan 	bg = (u_char)ri->ri_devcmap[(attr >> 16) & 0xf];
    230  1.30  macallan 	fg = (u_char)ri->ri_devcmap[(attr >> 24) & 0xf];
    231  1.30  macallan 
    232  1.30  macallan 	if (uc == ' ') {
    233  1.30  macallan 
    234  1.30  macallan 		while (height--) {
    235  1.30  macallan 			dp = rp;
    236  1.30  macallan 			rp += ri->ri_stride;
    237  1.30  macallan 			if (ri->ri_hwbits) {
    238  1.30  macallan 				hp = hrp;
    239  1.30  macallan 				hrp += ri->ri_stride;
    240  1.30  macallan 			}
    241  1.30  macallan 
    242  1.30  macallan 			for (cnt = width; cnt; cnt--) {
    243  1.30  macallan 				*dp++ = bg;
    244  1.30  macallan 				if (ri->ri_hwbits)
    245  1.30  macallan 					*hp++ = bg;
    246  1.30  macallan 			}
    247  1.30  macallan 		}
    248  1.30  macallan 	} else {
    249  1.30  macallan 		fr = WSFONT_GLYPH(uc, font);
    250  1.30  macallan 		fs = font->stride;
    251  1.30  macallan 		/*
    252  1.30  macallan 		 * we need the RGB colours here, get offsets into rasops_cmap
    253  1.30  macallan 		 */
    254  1.30  macallan 		fgo = ((attr >> 24) & 0xf) * 3;
    255  1.30  macallan 		bgo = ((attr >> 16) & 0xf) * 3;
    256  1.30  macallan 
    257  1.30  macallan 		r0 = rasops_cmap[bgo];
    258  1.30  macallan 		r1 = rasops_cmap[fgo];
    259  1.30  macallan 		g0 = rasops_cmap[bgo + 1];
    260  1.30  macallan 		g1 = rasops_cmap[fgo + 1];
    261  1.30  macallan 		b0 = rasops_cmap[bgo + 2];
    262  1.30  macallan 		b1 = rasops_cmap[fgo + 2];
    263  1.30  macallan 
    264  1.30  macallan 		for (y = 0; y < height; y++) {
    265  1.30  macallan 			dp = rp;
    266  1.30  macallan 			for (x = 0; x < width; x++) {
    267  1.30  macallan 				aval = *fr;
    268  1.30  macallan 				fr++;
    269  1.30  macallan 				if (aval == 0) {
    270  1.30  macallan 					pixel = bg;
    271  1.30  macallan 				} else if (aval == 255) {
    272  1.30  macallan 					pixel = fg;
    273  1.30  macallan 				} else {
    274  1.30  macallan 					r = aval * r1 + (255 - aval) * r0;
    275  1.30  macallan 					g = aval * g1 + (255 - aval) * g0;
    276  1.30  macallan 					b = aval * b1 + (255 - aval) * b0;
    277  1.30  macallan 					pixel = ((r & 0xe000) >> 8) |
    278  1.30  macallan 						((g & 0xe000) >> 11) |
    279  1.30  macallan 						((b & 0xc000) >> 14);
    280  1.30  macallan 				}
    281  1.30  macallan 				*dp = pixel;
    282  1.30  macallan 				dp++;
    283  1.30  macallan 			}
    284  1.30  macallan 			if (ri->ri_hwbits) {
    285  1.30  macallan 				memcpy(rp, hrp, width);
    286  1.30  macallan 				hrp += ri->ri_stride;
    287  1.30  macallan 			}
    288  1.30  macallan 			rp += ri->ri_stride;
    289  1.30  macallan 
    290  1.30  macallan 		}
    291  1.30  macallan 	}
    292  1.30  macallan 
    293  1.30  macallan 	/* Do underline */
    294  1.30  macallan 	if ((attr & 1) != 0) {
    295  1.30  macallan 
    296  1.30  macallan 		rp -= (ri->ri_stride << 1);
    297  1.30  macallan 		if (ri->ri_hwbits)
    298  1.30  macallan 			hrp -= (ri->ri_stride << 1);
    299  1.30  macallan 
    300  1.30  macallan 		while (width--) {
    301  1.30  macallan 			*rp++ = fg;
    302  1.30  macallan 			if (ri->ri_hwbits)
    303  1.30  macallan 				*hrp++ = fg;
    304  1.30  macallan 		}
    305  1.30  macallan 	}
    306  1.30  macallan }
    307  1.30  macallan 
    308   1.7        ad #ifndef RASOPS_SMALL
    309   1.1        ad /*
    310   1.1        ad  * Recompute the 4x1 blitting stamp.
    311   1.1        ad  */
    312   1.1        ad static void
    313  1.25       dsl rasops8_makestamp(struct rasops_info *ri, long attr)
    314   1.1        ad {
    315   1.7        ad 	int32_t fg, bg;
    316   1.1        ad 	int i;
    317   1.5        ad 
    318   1.8        pk 	fg = ri->ri_devcmap[(attr >> 24) & 0xf] & 0xff;
    319   1.8        pk 	bg = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xff;
    320   1.1        ad 	stamp_attr = attr;
    321   1.8        pk 
    322   1.1        ad 	for (i = 0; i < 16; i++) {
    323  1.16       uwe #if BYTE_ORDER == BIG_ENDIAN
    324  1.16       uwe #define NEED_LITTLE_ENDIAN_STAMP RI_BSWAP
    325   1.1        ad #else
    326  1.16       uwe #define NEED_LITTLE_ENDIAN_STAMP 0
    327   1.1        ad #endif
    328  1.16       uwe 		if ((ri->ri_flg & RI_BSWAP) == NEED_LITTLE_ENDIAN_STAMP) {
    329  1.16       uwe 			/* little endian */
    330  1.16       uwe 			stamp[i] = (i & 8 ? fg : bg);
    331  1.16       uwe 			stamp[i] |= ((i & 4 ? fg : bg) << 8);
    332  1.16       uwe 			stamp[i] |= ((i & 2 ? fg : bg) << 16);
    333  1.16       uwe 			stamp[i] |= ((i & 1 ? fg : bg) << 24);
    334  1.16       uwe 		} else {
    335  1.16       uwe 			/* big endian */
    336  1.16       uwe 			stamp[i] = (i & 1 ? fg : bg);
    337  1.16       uwe 			stamp[i] |= ((i & 2 ? fg : bg) << 8);
    338  1.16       uwe 			stamp[i] |= ((i & 4 ? fg : bg) << 16);
    339  1.16       uwe 			stamp[i] |= ((i & 8 ? fg : bg) << 24);
    340  1.16       uwe 		}
    341   1.1        ad 	}
    342   1.1        ad }
    343   1.1        ad 
    344   1.1        ad /*
    345   1.3        ad  * Put a single character. This is for 8-pixel wide fonts.
    346   1.1        ad  */
    347   1.1        ad static void
    348  1.26       dsl rasops8_putchar8(void *cookie, int row, int col, u_int uc, long attr)
    349   1.1        ad {
    350  1.27  macallan 	struct rasops_info *ri = (struct rasops_info *)cookie;
    351  1.27  macallan 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
    352   1.1        ad 	int height, fs;
    353  1.21  jmcneill 	int32_t *rp, *hp;
    354   1.1        ad 	u_char *fr;
    355   1.8        pk 
    356   1.1        ad 	/* Can't risk remaking the stamp if it's already in use */
    357   1.1        ad 	if (stamp_mutex++) {
    358   1.1        ad 		stamp_mutex--;
    359   1.1        ad 		rasops8_putchar(cookie, row, col, uc, attr);
    360   1.1        ad 		return;
    361   1.1        ad 	}
    362   1.1        ad 
    363  1.21  jmcneill 	hp = NULL;
    364   1.1        ad 
    365  1.27  macallan 	if (!CHAR_IN_FONT(uc, font))
    366  1.17    petrov 		return;
    367  1.17    petrov 
    368   1.8        pk #ifdef RASOPS_CLIPPING
    369   1.1        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    370   1.1        ad 		stamp_mutex--;
    371   1.1        ad 		return;
    372   1.1        ad 	}
    373   1.1        ad 
    374   1.1        ad 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    375   1.1        ad 		stamp_mutex--;
    376   1.1        ad 		return;
    377   1.1        ad 	}
    378   1.1        ad #endif
    379   1.1        ad 
    380   1.1        ad 	/* Recompute stamp? */
    381   1.1        ad 	if (attr != stamp_attr)
    382   1.6        ad 		rasops8_makestamp(ri, attr);
    383   1.8        pk 
    384   1.1        ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    385  1.21  jmcneill 	if (ri->ri_hwbits)
    386  1.21  jmcneill 		hp = (int32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
    387  1.21  jmcneill 		    col*ri->ri_xscale);
    388  1.27  macallan 	height = font->fontheight;
    389   1.8        pk 
    390   1.1        ad 	if (uc == ' ') {
    391   1.1        ad 		while (height--) {
    392   1.8        pk 			rp[0] = rp[1] = stamp[0];
    393   1.1        ad 			DELTA(rp, ri->ri_stride, int32_t *);
    394  1.21  jmcneill 			if (ri->ri_hwbits) {
    395  1.23  jmcneill 				hp[0] = stamp[0];
    396  1.23  jmcneill 				hp[1] = stamp[0];
    397  1.21  jmcneill 				DELTA(hp, ri->ri_stride, int32_t *);
    398  1.21  jmcneill 			}
    399   1.8        pk 		}
    400   1.1        ad 	} else {
    401  1.29  macallan 		fr = WSFONT_GLYPH(uc, font);
    402  1.27  macallan 		fs = font->stride;
    403   1.8        pk 
    404   1.1        ad 		while (height--) {
    405   1.1        ad 			rp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
    406   1.1        ad 			rp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
    407  1.21  jmcneill 			if (ri->ri_hwbits) {
    408  1.21  jmcneill 				hp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) &
    409  1.21  jmcneill 				    STAMP_MASK);
    410  1.21  jmcneill 				hp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) &
    411  1.21  jmcneill 				    STAMP_MASK);
    412  1.21  jmcneill 			}
    413   1.1        ad 
    414   1.1        ad 			fr += fs;
    415   1.8        pk 			DELTA(rp, ri->ri_stride, int32_t *);
    416  1.21  jmcneill 			if (ri->ri_hwbits)
    417  1.21  jmcneill 				DELTA(hp, ri->ri_stride, int32_t *);
    418   1.1        ad 		}
    419   1.1        ad 	}
    420   1.1        ad 
    421   1.1        ad 	/* Do underline */
    422   1.7        ad 	if ((attr & 1) != 0) {
    423   1.8        pk 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    424   1.8        pk 		rp[0] = rp[1] = stamp[15];
    425  1.21  jmcneill 		if (ri->ri_hwbits) {
    426  1.21  jmcneill 			DELTA(hp, -(ri->ri_stride << 1), int32_t *);
    427  1.23  jmcneill 			hp[0] = stamp[15];
    428  1.23  jmcneill 			hp[1] = stamp[15];
    429  1.21  jmcneill 		}
    430   1.8        pk 	}
    431   1.8        pk 
    432   1.8        pk 	stamp_mutex--;
    433   1.1        ad }
    434   1.1        ad 
    435   1.1        ad /*
    436   1.3        ad  * Put a single character. This is for 12-pixel wide fonts.
    437   1.1        ad  */
    438   1.1        ad static void
    439  1.26       dsl rasops8_putchar12(void *cookie, int row, int col, u_int uc, long attr)
    440   1.1        ad {
    441  1.27  macallan 	struct rasops_info *ri = (struct rasops_info *)cookie;
    442  1.27  macallan 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
    443   1.1        ad 	int height, fs;
    444  1.21  jmcneill 	int32_t *rp,  *hrp;
    445   1.1        ad 	u_char *fr;
    446   1.8        pk 
    447   1.1        ad 	/* Can't risk remaking the stamp if it's already in use */
    448   1.1        ad 	if (stamp_mutex++) {
    449   1.1        ad 		stamp_mutex--;
    450   1.1        ad 		rasops8_putchar(cookie, row, col, uc, attr);
    451   1.1        ad 		return;
    452   1.1        ad 	}
    453   1.1        ad 
    454  1.21  jmcneill 	hrp = NULL;
    455   1.1        ad 
    456  1.27  macallan 	if (!CHAR_IN_FONT(uc, font))
    457  1.17    petrov 	    return;
    458  1.17    petrov 
    459   1.8        pk #ifdef RASOPS_CLIPPING
    460   1.1        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    461   1.1        ad 		stamp_mutex--;
    462   1.1        ad 		return;
    463   1.1        ad 	}
    464   1.1        ad 
    465   1.1        ad 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    466   1.1        ad 		stamp_mutex--;
    467   1.1        ad 		return;
    468   1.1        ad 	}
    469   1.1        ad #endif
    470   1.1        ad 
    471   1.1        ad 	/* Recompute stamp? */
    472   1.1        ad 	if (attr != stamp_attr)
    473   1.6        ad 		rasops8_makestamp(ri, attr);
    474   1.8        pk 
    475   1.1        ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    476  1.21  jmcneill 	if (ri->ri_hwbits)
    477  1.21  jmcneill 		hrp = (int32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
    478  1.21  jmcneill 		    col*ri->ri_xscale);
    479  1.27  macallan 	height = font->fontheight;
    480   1.8        pk 
    481   1.1        ad 	if (uc == ' ') {
    482   1.1        ad 		while (height--) {
    483   1.8        pk 			int32_t c = stamp[0];
    484   1.8        pk 
    485   1.8        pk 			rp[0] = rp[1] = rp[2] = c;
    486   1.8        pk 			DELTA(rp, ri->ri_stride, int32_t *);
    487  1.21  jmcneill 			if (ri->ri_hwbits) {
    488  1.23  jmcneill 				hrp[0] = c;
    489  1.23  jmcneill 				hrp[1] = c;
    490  1.23  jmcneill 				hrp[2] = c;
    491  1.21  jmcneill 				DELTA(hrp, ri->ri_stride, int32_t *);
    492  1.21  jmcneill 			}
    493   1.8        pk 		}
    494   1.1        ad 	} else {
    495  1.29  macallan 		fr = WSFONT_GLYPH(uc, font);
    496  1.27  macallan 		fs = font->stride;
    497   1.8        pk 
    498   1.1        ad 		while (height--) {
    499   1.1        ad 			rp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
    500   1.1        ad 			rp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
    501   1.1        ad 			rp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) & STAMP_MASK);
    502  1.21  jmcneill 			if (ri->ri_hwbits) {
    503  1.21  jmcneill 				hrp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
    504  1.21  jmcneill 				hrp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
    505  1.21  jmcneill 				hrp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) & STAMP_MASK);
    506  1.21  jmcneill 			}
    507   1.8        pk 
    508   1.1        ad 			fr += fs;
    509   1.8        pk 			DELTA(rp, ri->ri_stride, int32_t *);
    510  1.21  jmcneill 			if (ri->ri_hwbits)
    511  1.21  jmcneill 				DELTA(hrp, ri->ri_stride, int32_t *);
    512   1.1        ad 		}
    513   1.8        pk 	}
    514   1.1        ad 
    515   1.1        ad 	/* Do underline */
    516   1.7        ad 	if ((attr & 1) != 0) {
    517   1.8        pk 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    518   1.8        pk 		rp[0] = rp[1] = rp[2] = stamp[15];
    519  1.21  jmcneill 		if (ri->ri_hwbits) {
    520  1.21  jmcneill 			DELTA(hrp, -(ri->ri_stride << 1), int32_t *);
    521  1.23  jmcneill 			hrp[0] = stamp[15];
    522  1.23  jmcneill 			hrp[1] = stamp[15];
    523  1.23  jmcneill 			hrp[2] = stamp[15];
    524  1.21  jmcneill 		}
    525   1.8        pk 	}
    526   1.8        pk 
    527   1.1        ad 	stamp_mutex--;
    528   1.1        ad }
    529   1.1        ad 
    530   1.1        ad /*
    531   1.3        ad  * Put a single character. This is for 16-pixel wide fonts.
    532   1.1        ad  */
    533   1.1        ad static void
    534  1.26       dsl rasops8_putchar16(void *cookie, int row, int col, u_int uc, long attr)
    535   1.1        ad {
    536  1.27  macallan 	struct rasops_info *ri = (struct rasops_info *)cookie;
    537  1.27  macallan 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
    538   1.1        ad 	int height, fs;
    539  1.21  jmcneill 	int32_t *rp, *hrp;
    540   1.1        ad 	u_char *fr;
    541   1.1        ad 
    542   1.1        ad 	/* Can't risk remaking the stamp if it's already in use */
    543   1.1        ad 	if (stamp_mutex++) {
    544   1.1        ad 		stamp_mutex--;
    545   1.1        ad 		rasops8_putchar(cookie, row, col, uc, attr);
    546   1.1        ad 		return;
    547   1.1        ad 	}
    548   1.1        ad 
    549  1.21  jmcneill 	hrp = NULL;
    550   1.1        ad 
    551  1.27  macallan 	if (!CHAR_IN_FONT(uc, font))
    552  1.17    petrov 		return;
    553  1.17    petrov 
    554   1.8        pk #ifdef RASOPS_CLIPPING
    555   1.1        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    556   1.1        ad 		stamp_mutex--;
    557   1.1        ad 		return;
    558   1.1        ad 	}
    559   1.1        ad 
    560   1.1        ad 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    561   1.1        ad 		stamp_mutex--;
    562   1.1        ad 		return;
    563   1.1        ad 	}
    564   1.1        ad #endif
    565   1.1        ad 
    566   1.1        ad 	/* Recompute stamp? */
    567   1.1        ad 	if (attr != stamp_attr)
    568   1.6        ad 		rasops8_makestamp(ri, attr);
    569   1.8        pk 
    570   1.1        ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    571  1.21  jmcneill 	if (ri->ri_hwbits)
    572  1.21  jmcneill 		hrp = (int32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
    573  1.21  jmcneill 		    col*ri->ri_xscale);
    574  1.21  jmcneill 
    575  1.27  macallan 	height = font->fontheight;
    576   1.8        pk 
    577   1.1        ad 	if (uc == ' ') {
    578  1.21  jmcneill 		while (height--) {
    579   1.8        pk 			rp[0] = rp[1] = rp[2] = rp[3] = stamp[0];
    580  1.23  jmcneill 			if (ri->ri_hwbits) {
    581  1.23  jmcneill 				hrp[0] = stamp[0];
    582  1.23  jmcneill 				hrp[1] = stamp[0];
    583  1.23  jmcneill 				hrp[2] = stamp[0];
    584  1.23  jmcneill 				hrp[3] = stamp[0];
    585  1.23  jmcneill 			}
    586  1.21  jmcneill 		}
    587   1.1        ad 	} else {
    588  1.29  macallan 		fr = WSFONT_GLYPH(uc, font);
    589  1.27  macallan 		fs = font->stride;
    590   1.8        pk 
    591   1.1        ad 		while (height--) {
    592   1.1        ad 			rp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
    593   1.1        ad 			rp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
    594   1.1        ad 			rp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) & STAMP_MASK);
    595   1.1        ad 			rp[3] = STAMP_READ(STAMP_SHIFT(fr[1], 0) & STAMP_MASK);
    596  1.21  jmcneill 			if (ri->ri_hwbits) {
    597  1.21  jmcneill 				hrp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
    598  1.21  jmcneill 				hrp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
    599  1.21  jmcneill 				hrp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) & STAMP_MASK);
    600  1.21  jmcneill 				hrp[3] = STAMP_READ(STAMP_SHIFT(fr[1], 0) & STAMP_MASK);
    601  1.21  jmcneill 			}
    602   1.1        ad 
    603   1.1        ad 			fr += fs;
    604   1.8        pk 			DELTA(rp, ri->ri_stride, int32_t *);
    605  1.21  jmcneill 			if (ri->ri_hwbits)
    606  1.21  jmcneill 				DELTA(hrp, ri->ri_stride, int32_t *);
    607   1.1        ad 		}
    608   1.8        pk 	}
    609   1.1        ad 
    610   1.1        ad 	/* Do underline */
    611   1.7        ad 	if ((attr & 1) != 0) {
    612   1.8        pk 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    613   1.8        pk 		rp[0] = rp[1] = rp[2] = rp[3] = stamp[15];
    614  1.21  jmcneill 		if (ri->ri_hwbits) {
    615  1.21  jmcneill 			DELTA(hrp, -(ri->ri_stride << 1), int32_t *);
    616  1.23  jmcneill 			hrp[0] = stamp[15];
    617  1.23  jmcneill 			hrp[1] = stamp[15];
    618  1.23  jmcneill 			hrp[2] = stamp[15];
    619  1.23  jmcneill 			hrp[3] = stamp[15];
    620  1.21  jmcneill 		}
    621   1.8        pk 	}
    622   1.8        pk 
    623   1.1        ad 	stamp_mutex--;
    624   1.1        ad }
    625   1.7        ad #endif /* !RASOPS_SMALL */
    626