Home | History | Annotate | Line # | Download | only in rasops
rasops32.c revision 1.24.6.1
      1  1.24.6.1       tls /*	 $NetBSD: rasops32.c,v 1.24.6.1 2012/11/20 03:02:32 tls 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.24.6.1       tls __KERNEL_RCSID(0, "$NetBSD: rasops32.c,v 1.24.6.1 2012/11/20 03:02:32 tls 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.23  macallan static void 	rasops32_putchar_aa(void *, int, int, u_int, long attr);
     47       1.3        ad 
     48       1.1        ad /*
     49       1.9       wiz  * Initialize a 'rasops_info' descriptor for this depth.
     50       1.1        ad  */
     51       1.1        ad void
     52      1.17       dsl rasops32_init(struct rasops_info *ri)
     53       1.1        ad {
     54       1.1        ad 
     55       1.3        ad 	if (ri->ri_rnum == 0) {
     56       1.3        ad 		ri->ri_rnum = 8;
     57       1.3        ad 		ri->ri_rpos = 0;
     58       1.3        ad 		ri->ri_gnum = 8;
     59       1.3        ad 		ri->ri_gpos = 8;
     60       1.3        ad 		ri->ri_bnum = 8;
     61       1.3        ad 		ri->ri_bpos = 16;
     62       1.1        ad 	}
     63       1.7        pk 
     64      1.23  macallan 	if (FONT_IS_ALPHA(ri->ri_font)) {
     65      1.23  macallan 		ri->ri_ops.putchar = rasops32_putchar_aa;
     66      1.23  macallan 	} else
     67      1.23  macallan 		ri->ri_ops.putchar = rasops32_putchar;
     68       1.1        ad }
     69       1.1        ad 
     70       1.1        ad /*
     71       1.1        ad  * Paint a single character.
     72       1.1        ad  */
     73      1.23  macallan 
     74       1.1        ad static void
     75      1.18       dsl rasops32_putchar(void *cookie, int row, int col, u_int uc, long attr)
     76       1.1        ad {
     77       1.5        ad 	int width, height, cnt, fs, fb, clr[2];
     78      1.19  macallan 	struct rasops_info *ri = (struct rasops_info *)cookie;
     79      1.19  macallan 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
     80      1.15  jmcneill 	int32_t *dp, *rp, *hp, *hrp;
     81       1.1        ad 	u_char *fr;
     82       1.7        pk 
     83      1.15  jmcneill 	hp = hrp = NULL;
     84       1.1        ad 
     85       1.7        pk #ifdef RASOPS_CLIPPING
     86       1.7        pk 	/* Catches 'row < 0' case too */
     87       1.1        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
     88       1.1        ad 		return;
     89       1.1        ad 
     90       1.1        ad 	if ((unsigned)col >= (unsigned)ri->ri_cols)
     91       1.1        ad 		return;
     92       1.1        ad #endif
     93      1.12    petrov 
     94      1.12    petrov 	/* check if character fits into font limits */
     95      1.24  macallan 	if (!CHAR_IN_FONT(uc, font))
     96      1.24  macallan 		return;
     97       1.7        pk 
     98       1.1        ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
     99      1.15  jmcneill 	if (ri->ri_hwbits)
    100      1.15  jmcneill 		hrp = (int32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
    101      1.15  jmcneill 		    col*ri->ri_xscale);
    102       1.1        ad 
    103      1.19  macallan 	height = font->fontheight;
    104      1.19  macallan 	width = font->fontwidth;
    105       1.3        ad 
    106       1.7        pk 	clr[0] = ri->ri_devcmap[(attr >> 16) & 0xf];
    107       1.7        pk 	clr[1] = ri->ri_devcmap[(attr >> 24) & 0xf];
    108       1.7        pk 
    109       1.1        ad 	if (uc == ' ') {
    110       1.1        ad 		while (height--) {
    111       1.1        ad 			dp = rp;
    112       1.1        ad 			DELTA(rp, ri->ri_stride, int32_t *);
    113      1.15  jmcneill 			if (ri->ri_hwbits) {
    114      1.15  jmcneill 				hp = hrp;
    115      1.15  jmcneill 				DELTA(hrp, ri->ri_stride, int32_t *);
    116      1.15  jmcneill 			}
    117       1.1        ad 
    118      1.15  jmcneill 			for (cnt = width; cnt; cnt--) {
    119       1.1        ad 				*dp++ = clr[0];
    120      1.15  jmcneill 				if (ri->ri_hwbits)
    121      1.15  jmcneill 					*hp++ = clr[0];
    122      1.15  jmcneill 			}
    123       1.1        ad 		}
    124       1.1        ad 	} else {
    125      1.24  macallan 		fr = WSFONT_GLYPH(uc, font);
    126      1.19  macallan 		fs = font->stride;
    127       1.1        ad 
    128      1.23  macallan 		while (height--) {
    129      1.23  macallan 			dp = rp;
    130      1.23  macallan 			fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) |
    131      1.23  macallan 			    (fr[0] << 24);
    132      1.23  macallan 			fr += fs;
    133      1.23  macallan 			DELTA(rp, ri->ri_stride, int32_t *);
    134      1.23  macallan 			if (ri->ri_hwbits) {
    135      1.23  macallan 				hp = hrp;
    136      1.23  macallan 				DELTA(hrp, ri->ri_stride, int32_t *);
    137      1.23  macallan 			}
    138      1.23  macallan 
    139      1.23  macallan 			for (cnt = width; cnt; cnt--) {
    140      1.23  macallan 				*dp++ = clr[(fb >> 31) & 1];
    141      1.23  macallan 				if (ri->ri_hwbits)
    142      1.23  macallan 					*hp++ = clr[(fb >> 31) & 1];
    143      1.23  macallan 				fb <<= 1;
    144      1.23  macallan 			}
    145      1.23  macallan 		}
    146      1.23  macallan 	}
    147      1.23  macallan 
    148      1.23  macallan 	/* Do underline */
    149      1.23  macallan 	if ((attr & 1) != 0) {
    150      1.23  macallan 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    151      1.23  macallan 		if (ri->ri_hwbits)
    152      1.23  macallan 			DELTA(hrp, -(ri->ri_stride << 1), int32_t *);
    153      1.23  macallan 
    154      1.23  macallan 		while (width--) {
    155      1.23  macallan 			*rp++ = clr[1];
    156      1.23  macallan 			if (ri->ri_hwbits)
    157      1.23  macallan 				*hrp++ = clr[1];
    158      1.23  macallan 		}
    159      1.23  macallan 	}
    160      1.23  macallan }
    161      1.23  macallan 
    162      1.23  macallan static void
    163      1.23  macallan rasops32_putchar_aa(void *cookie, int row, int col, u_int uc, long attr)
    164      1.23  macallan {
    165      1.23  macallan 	int width, height, cnt, fs, clr[2];
    166      1.23  macallan 	struct rasops_info *ri = (struct rasops_info *)cookie;
    167      1.23  macallan 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
    168      1.23  macallan 	int32_t *dp, *rp, *hp, *hrp;
    169  1.24.6.1       tls 	uint8_t *rrp;
    170      1.23  macallan 	u_char *fr;
    171      1.23  macallan 	int x, y, r, g, b, aval;
    172      1.23  macallan 	int r1, g1, b1, r0, g0, b0;
    173      1.23  macallan 
    174      1.23  macallan 	hp = hrp = NULL;
    175      1.23  macallan 
    176      1.23  macallan #ifdef RASOPS_CLIPPING
    177      1.23  macallan 	/* Catches 'row < 0' case too */
    178      1.23  macallan 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    179      1.23  macallan 		return;
    180      1.23  macallan 
    181      1.23  macallan 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    182      1.23  macallan 		return;
    183      1.23  macallan #endif
    184      1.23  macallan 
    185      1.23  macallan 	/* check if character fits into font limits */
    186      1.24  macallan 	if (!CHAR_IN_FONT(uc, font))
    187      1.24  macallan 		return;
    188      1.23  macallan 
    189  1.24.6.1       tls 	rrp = (ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    190  1.24.6.1       tls 	rp = (int32_t *)rrp;
    191      1.23  macallan 	if (ri->ri_hwbits)
    192      1.23  macallan 		hrp = (int32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
    193      1.23  macallan 		    col*ri->ri_xscale);
    194      1.23  macallan 
    195      1.23  macallan 	height = font->fontheight;
    196      1.23  macallan 	width = font->fontwidth;
    197      1.23  macallan 
    198      1.23  macallan 	clr[0] = ri->ri_devcmap[(attr >> 16) & 0xf];
    199      1.23  macallan 	clr[1] = ri->ri_devcmap[(attr >> 24) & 0xf];
    200      1.23  macallan 
    201      1.23  macallan 	if (uc == ' ') {
    202      1.23  macallan 		while (height--) {
    203      1.23  macallan 			dp = rp;
    204      1.23  macallan 			DELTA(rp, ri->ri_stride, int32_t *);
    205      1.23  macallan 			if (ri->ri_hwbits) {
    206      1.23  macallan 				hp = hrp;
    207      1.23  macallan 				DELTA(hrp, ri->ri_stride, int32_t *);
    208      1.23  macallan 			}
    209      1.20  macallan 
    210      1.23  macallan 			for (cnt = width; cnt; cnt--) {
    211      1.23  macallan 				*dp++ = clr[0];
    212      1.23  macallan 				if (ri->ri_hwbits)
    213      1.23  macallan 					*hp++ = clr[0];
    214      1.15  jmcneill 			}
    215      1.23  macallan 		}
    216      1.23  macallan 	} else {
    217      1.24  macallan 		fr = WSFONT_GLYPH(uc, font);
    218      1.23  macallan 		fs = font->stride;
    219      1.23  macallan 
    220      1.23  macallan 		r0 = (clr[0] >> 16) & 0xff;
    221      1.23  macallan 		r1 = (clr[1] >> 16) & 0xff;
    222      1.23  macallan 		g0 = (clr[0] >> 8) & 0xff;
    223      1.23  macallan 		g1 = (clr[1] >> 8) & 0xff;
    224      1.23  macallan 		b0 =  clr[0] & 0xff;
    225      1.23  macallan 		b1 =  clr[1] & 0xff;
    226      1.23  macallan 
    227      1.23  macallan 		for (y = 0; y < height; y++) {
    228  1.24.6.1       tls 			dp = (uint32_t *)(rrp + ri->ri_stride * y);
    229      1.23  macallan 			for (x = 0; x < width; x++) {
    230      1.23  macallan 				aval = *fr;
    231      1.23  macallan 				if (aval == 0) {
    232      1.23  macallan 					*dp = clr[0];
    233      1.23  macallan 				} else if (aval == 255) {
    234      1.23  macallan 					*dp = clr[1];
    235      1.23  macallan 				} else {
    236      1.23  macallan 					r = aval * r1 + (255 - aval) * r0;
    237      1.23  macallan 					g = aval * g1 + (255 - aval) * g0;
    238      1.23  macallan 					b = aval * b1 + (255 - aval) * b0;
    239      1.23  macallan 					*dp = (r & 0xff00) << 8 |
    240      1.23  macallan 					      (g & 0xff00) |
    241      1.23  macallan 					      (b & 0xff00) >> 8;
    242      1.20  macallan 				}
    243      1.23  macallan 				dp++;
    244      1.23  macallan 				fr++;
    245       1.1        ad 			}
    246       1.1        ad 		}
    247       1.7        pk 	}
    248       1.1        ad 
    249       1.1        ad 	/* Do underline */
    250       1.5        ad 	if ((attr & 1) != 0) {
    251       1.1        ad 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    252      1.15  jmcneill 		if (ri->ri_hwbits)
    253      1.15  jmcneill 			DELTA(hrp, -(ri->ri_stride << 1), int32_t *);
    254       1.1        ad 
    255      1.15  jmcneill 		while (width--) {
    256       1.1        ad 			*rp++ = clr[1];
    257      1.15  jmcneill 			if (ri->ri_hwbits)
    258      1.15  jmcneill 				*hrp++ = clr[1];
    259      1.15  jmcneill 		}
    260       1.7        pk 	}
    261       1.1        ad }
    262