Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/rasops add support for anti-aliased fonts in r3g3b2
details: https://anonhg.NetBSD.org/src/rev/f344f500e950
branches: trunk
changeset: 772470:f344f500e950
user: macallan <macallan%NetBSD.org@localhost>
date: Wed Jan 04 20:16:20 2012 +0000
description:
add support for anti-aliased fonts in r3g3b2
diffstat:
sys/dev/rasops/rasops8.c | 144 ++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 129 insertions(+), 15 deletions(-)
diffs (181 lines):
diff -r 10ef50bbc97c -r f344f500e950 sys/dev/rasops/rasops8.c
--- a/sys/dev/rasops/rasops8.c Wed Jan 04 17:26:21 2012 +0000
+++ b/sys/dev/rasops/rasops8.c Wed Jan 04 20:16:20 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rasops8.c,v 1.29 2012/01/04 17:01:52 macallan Exp $ */
+/* $NetBSD: rasops8.c,v 1.30 2012/01/04 20:16:20 macallan Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops8.c,v 1.29 2012/01/04 17:01:52 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops8.c,v 1.30 2012/01/04 20:16:20 macallan Exp $");
#include "opt_rasops.h"
@@ -43,6 +43,7 @@
#include <dev/rasops/rasops.h>
static void rasops8_putchar(void *, int, int, u_int, long attr);
+static void rasops8_putchar_aa(void *, int, int, u_int, long attr);
#ifndef RASOPS_SMALL
static void rasops8_putchar8(void *, int, int, u_int, long attr);
static void rasops8_putchar12(void *, int, int, u_int, long attr);
@@ -75,21 +76,25 @@
rasops8_init(struct rasops_info *ri)
{
- switch (ri->ri_font->fontwidth) {
+ if FONT_IS_ALPHA(ri->ri_font) {
+ ri->ri_ops.putchar = rasops8_putchar_aa;
+ } else {
+ switch (ri->ri_font->fontwidth) {
#ifndef RASOPS_SMALL
- case 8:
- ri->ri_ops.putchar = rasops8_putchar8;
- break;
- case 12:
- ri->ri_ops.putchar = rasops8_putchar12;
- break;
- case 16:
- ri->ri_ops.putchar = rasops8_putchar16;
- break;
+ case 8:
+ ri->ri_ops.putchar = rasops8_putchar8;
+ break;
+ case 12:
+ ri->ri_ops.putchar = rasops8_putchar12;
+ break;
+ case 16:
+ ri->ri_ops.putchar = rasops8_putchar16;
+ break;
#endif /* !RASOPS_SMALL */
- default:
- ri->ri_ops.putchar = rasops8_putchar;
- break;
+ default:
+ ri->ri_ops.putchar = rasops8_putchar;
+ break;
+ }
}
if (ri->ri_flg & RI_8BIT_IS_RGB) {
ri->ri_rnum = 3;
@@ -191,6 +196,115 @@
}
}
+static void
+rasops8_putchar_aa(void *cookie, int row, int col, u_int uc, long attr)
+{
+ int width, height, cnt, fs;
+ u_char *dp, *rp, *hp, *hrp, *fr, bg, fg, pixel;
+ struct rasops_info *ri = (struct rasops_info *)cookie;
+ struct wsdisplay_font *font = PICK_FONT(ri, uc);
+ int x, y, r, g, b, aval;
+ int r1, g1, b1, r0, g0, b0, fgo, bgo;
+
+ hp = hrp = NULL;
+
+ if (!CHAR_IN_FONT(uc, font))
+ return;
+
+#ifdef RASOPS_CLIPPING
+ /* Catches 'row < 0' case too */
+ if ((unsigned)row >= (unsigned)ri->ri_rows)
+ return;
+
+ if ((unsigned)col >= (unsigned)ri->ri_cols)
+ return;
+#endif
+ rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
+ if (ri->ri_hwbits)
+ hrp = ri->ri_hwbits + row * ri->ri_yscale + col *
+ ri->ri_xscale;
+
+ height = font->fontheight;
+ width = font->fontwidth;
+ bg = (u_char)ri->ri_devcmap[(attr >> 16) & 0xf];
+ fg = (u_char)ri->ri_devcmap[(attr >> 24) & 0xf];
+
+ if (uc == ' ') {
+
+ while (height--) {
+ dp = rp;
+ rp += ri->ri_stride;
+ if (ri->ri_hwbits) {
+ hp = hrp;
+ hrp += ri->ri_stride;
+ }
+
+ for (cnt = width; cnt; cnt--) {
+ *dp++ = bg;
+ if (ri->ri_hwbits)
+ *hp++ = bg;
+ }
+ }
+ } else {
+ fr = WSFONT_GLYPH(uc, font);
+ fs = font->stride;
+ /*
+ * we need the RGB colours here, get offsets into rasops_cmap
+ */
+ fgo = ((attr >> 24) & 0xf) * 3;
+ bgo = ((attr >> 16) & 0xf) * 3;
+
+ r0 = rasops_cmap[bgo];
+ r1 = rasops_cmap[fgo];
+ g0 = rasops_cmap[bgo + 1];
+ g1 = rasops_cmap[fgo + 1];
+ b0 = rasops_cmap[bgo + 2];
+ b1 = rasops_cmap[fgo + 2];
+
+ for (y = 0; y < height; y++) {
+ dp = rp;
+ for (x = 0; x < width; x++) {
+ aval = *fr;
+ fr++;
+ if (aval == 0) {
+ pixel = bg;
+ } else if (aval == 255) {
+ pixel = fg;
+ } else {
+ r = aval * r1 + (255 - aval) * r0;
+ g = aval * g1 + (255 - aval) * g0;
+ b = aval * b1 + (255 - aval) * b0;
+ pixel = ((r & 0xe000) >> 8) |
+ ((g & 0xe000) >> 11) |
+ ((b & 0xc000) >> 14);
+ }
+ *dp = pixel;
+ dp++;
+ }
+ if (ri->ri_hwbits) {
+ memcpy(rp, hrp, width);
+ hrp += ri->ri_stride;
+ }
+ rp += ri->ri_stride;
+
+ }
+ }
+
+ /* Do underline */
+ if ((attr & 1) != 0) {
+
+ rp -= (ri->ri_stride << 1);
+ if (ri->ri_hwbits)
+ hrp -= (ri->ri_stride << 1);
+
+ while (width--) {
+ *rp++ = fg;
+ if (ri->ri_hwbits)
+ *hrp++ = fg;
+ }
+ }
+}
+
#ifndef RASOPS_SMALL
/*
* Recompute the 4x1 blitting stamp.
Home |
Main Index |
Thread Index |
Old Index