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