Home | History | Annotate | Line # | Download | only in rasops
rasops32.c revision 1.20
      1  1.20  macallan /*	 $NetBSD: rasops32.c,v 1.20 2011/12/22 04:52:45 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.8        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.10     lukem #include <sys/cdefs.h>
     33  1.20  macallan __KERNEL_RCSID(0, "$NetBSD: rasops32.c,v 1.20 2011/12/22 04:52:45 macallan Exp $");
     34  1.10     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.13     perry static void 	rasops32_putchar(void *, int, int, u_int, long attr);
     46   1.3        ad 
     47   1.1        ad /*
     48   1.9       wiz  * Initialize a 'rasops_info' descriptor for this depth.
     49   1.1        ad  */
     50   1.1        ad void
     51  1.17       dsl rasops32_init(struct rasops_info *ri)
     52   1.1        ad {
     53   1.1        ad 
     54   1.3        ad 	if (ri->ri_rnum == 0) {
     55   1.3        ad 		ri->ri_rnum = 8;
     56   1.3        ad 		ri->ri_rpos = 0;
     57   1.3        ad 		ri->ri_gnum = 8;
     58   1.3        ad 		ri->ri_gpos = 8;
     59   1.3        ad 		ri->ri_bnum = 8;
     60   1.3        ad 		ri->ri_bpos = 16;
     61   1.1        ad 	}
     62   1.7        pk 
     63   1.3        ad 	ri->ri_ops.putchar = rasops32_putchar;
     64   1.1        ad }
     65   1.1        ad 
     66   1.1        ad /*
     67   1.1        ad  * Paint a single character.
     68   1.1        ad  */
     69   1.1        ad static void
     70  1.18       dsl rasops32_putchar(void *cookie, int row, int col, u_int uc, long attr)
     71   1.1        ad {
     72   1.5        ad 	int width, height, cnt, fs, fb, clr[2];
     73  1.19  macallan 	struct rasops_info *ri = (struct rasops_info *)cookie;
     74  1.19  macallan 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
     75  1.15  jmcneill 	int32_t *dp, *rp, *hp, *hrp;
     76   1.1        ad 	u_char *fr;
     77   1.7        pk 
     78  1.15  jmcneill 	hp = hrp = NULL;
     79   1.1        ad 
     80   1.7        pk #ifdef RASOPS_CLIPPING
     81   1.7        pk 	/* Catches 'row < 0' case too */
     82   1.1        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
     83   1.1        ad 		return;
     84   1.1        ad 
     85   1.1        ad 	if ((unsigned)col >= (unsigned)ri->ri_cols)
     86   1.1        ad 		return;
     87   1.1        ad #endif
     88  1.12    petrov 
     89  1.12    petrov 	/* check if character fits into font limits */
     90  1.19  macallan 	if (uc < font->firstchar ||
     91  1.19  macallan 	    (uc - font->firstchar) >= font->numchars)
     92  1.12    petrov 	    return;
     93   1.7        pk 
     94   1.1        ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
     95  1.15  jmcneill 	if (ri->ri_hwbits)
     96  1.15  jmcneill 		hrp = (int32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
     97  1.15  jmcneill 		    col*ri->ri_xscale);
     98   1.1        ad 
     99  1.19  macallan 	height = font->fontheight;
    100  1.19  macallan 	width = font->fontwidth;
    101   1.3        ad 
    102   1.7        pk 	clr[0] = ri->ri_devcmap[(attr >> 16) & 0xf];
    103   1.7        pk 	clr[1] = ri->ri_devcmap[(attr >> 24) & 0xf];
    104   1.7        pk 
    105   1.1        ad 	if (uc == ' ') {
    106   1.1        ad 		while (height--) {
    107   1.1        ad 			dp = rp;
    108   1.1        ad 			DELTA(rp, ri->ri_stride, int32_t *);
    109  1.15  jmcneill 			if (ri->ri_hwbits) {
    110  1.15  jmcneill 				hp = hrp;
    111  1.15  jmcneill 				DELTA(hrp, ri->ri_stride, int32_t *);
    112  1.15  jmcneill 			}
    113   1.1        ad 
    114  1.15  jmcneill 			for (cnt = width; cnt; cnt--) {
    115   1.1        ad 				*dp++ = clr[0];
    116  1.15  jmcneill 				if (ri->ri_hwbits)
    117  1.15  jmcneill 					*hp++ = clr[0];
    118  1.15  jmcneill 			}
    119   1.1        ad 		}
    120   1.1        ad 	} else {
    121  1.19  macallan 		uc -= font->firstchar;
    122  1.19  macallan 		fr = (u_char *)font->data + uc * ri->ri_fontscale;
    123  1.19  macallan 		fs = font->stride;
    124   1.1        ad 
    125  1.20  macallan 		if (font->stride < width) {
    126  1.20  macallan 			/* this is a mono font */
    127  1.20  macallan 			while (height--) {
    128  1.20  macallan 				dp = rp;
    129  1.20  macallan 				fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) |
    130  1.20  macallan 				    (fr[0] << 24);
    131  1.20  macallan 				fr += fs;
    132  1.20  macallan 				DELTA(rp, ri->ri_stride, int32_t *);
    133  1.20  macallan 				if (ri->ri_hwbits) {
    134  1.20  macallan 					hp = hrp;
    135  1.20  macallan 					DELTA(hrp, ri->ri_stride, int32_t *);
    136  1.20  macallan 				}
    137  1.20  macallan 
    138  1.20  macallan 				for (cnt = width; cnt; cnt--) {
    139  1.20  macallan 					*dp++ = clr[(fb >> 31) & 1];
    140  1.20  macallan 					if (ri->ri_hwbits)
    141  1.20  macallan 						*hp++ = clr[(fb >> 31) & 1];
    142  1.20  macallan 					fb <<= 1;
    143  1.20  macallan 				}
    144  1.15  jmcneill 			}
    145  1.20  macallan 		} else {
    146  1.20  macallan 			/* this is an alpha map */
    147  1.20  macallan 			int x, y, r, g, b, alpha;
    148  1.20  macallan 			int r1, g1, b1, r0, g0, b0;
    149  1.20  macallan 
    150  1.20  macallan 			r0 = (clr[0] >> 16) & 0xff;
    151  1.20  macallan 			r1 = (clr[1] >> 16) & 0xff;
    152  1.20  macallan 			g0 = (clr[0] >> 8) & 0xff;
    153  1.20  macallan 			g1 = (clr[1] >> 8) & 0xff;
    154  1.20  macallan 			b0 =  clr[0] & 0xff;
    155  1.20  macallan 			b1 =  clr[1] & 0xff;
    156  1.20  macallan 
    157  1.20  macallan 			for (y = 0; y < height; y++) {
    158  1.20  macallan 				dp = rp + ri->ri_width * y;
    159  1.20  macallan 				for (x = 0; x < width; x++) {
    160  1.20  macallan 					alpha = *fr;
    161  1.20  macallan 					r = alpha * r1 + (255 - alpha) * r0;
    162  1.20  macallan 					g = alpha * g1 + (255 - alpha) * g0;
    163  1.20  macallan 					b = alpha * b1 + (255 - alpha) * b0;
    164  1.20  macallan 					*dp = (r & 0xff00) << 8 |
    165  1.20  macallan 					      (g & 0xff00) |
    166  1.20  macallan 					      (b & 0xff00) >> 8;
    167  1.20  macallan 					dp++;
    168  1.20  macallan 					fr++;
    169  1.20  macallan 				}
    170   1.1        ad 			}
    171   1.1        ad 		}
    172   1.7        pk 	}
    173   1.1        ad 
    174   1.1        ad 	/* Do underline */
    175   1.5        ad 	if ((attr & 1) != 0) {
    176   1.1        ad 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    177  1.15  jmcneill 		if (ri->ri_hwbits)
    178  1.15  jmcneill 			DELTA(hrp, -(ri->ri_stride << 1), int32_t *);
    179   1.1        ad 
    180  1.15  jmcneill 		while (width--) {
    181   1.1        ad 			*rp++ = clr[1];
    182  1.15  jmcneill 			if (ri->ri_hwbits)
    183  1.15  jmcneill 				*hrp++ = clr[1];
    184  1.15  jmcneill 		}
    185   1.7        pk 	}
    186   1.1        ad }
    187