support anti-aliased fonts in 8 bit, generate an appropriate colour map

This commit is contained in:
macallan 2012-01-04 20:18:28 +00:00
parent d0517cd235
commit 5eec1b0f55
1 changed files with 53 additions and 11 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: genfb.c,v 1.44 2011/12/28 18:37:58 macallan Exp $ */
/* $NetBSD: genfb.c,v 1.45 2012/01/04 20:18:28 macallan Exp $ */
/*-
* Copyright (c) 2007 Michael Lorenz
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.44 2011/12/28 18:37:58 macallan Exp $");
__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.45 2012/01/04 20:18:28 macallan Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -74,6 +74,7 @@ static int genfb_putcmap(struct genfb_softc *, struct wsdisplay_cmap *);
static int genfb_getcmap(struct genfb_softc *, struct wsdisplay_cmap *);
static int genfb_putpalreg(struct genfb_softc *, uint8_t, uint8_t,
uint8_t, uint8_t);
static void genfb_init_palette(struct genfb_softc *);
static void genfb_brightness_up(device_t);
static void genfb_brightness_down(device_t);
@ -196,9 +197,9 @@ genfb_attach(struct genfb_softc *sc, struct genfb_ops *ops)
struct rasops_info *ri;
uint16_t crow;
long defattr;
int i, j;
bool console;
#ifdef SPLASHSCREEN
int i, j;
int error = ENXIO;
#endif
@ -280,14 +281,9 @@ genfb_attach(struct genfb_softc *sc, struct genfb_ops *ops)
if (sc->sc_want_clear)
(*ri->ri_ops.eraserows)(ri, 0, ri->ri_rows, defattr);
#ifdef SPLASHSCREEN
j = 0;
for (i = 0; i < min(1 << sc->sc_depth, 256); i++) {
#ifndef SPLASHSCREEN
sc->sc_cmap_red[i] = rasops_cmap[j];
sc->sc_cmap_green[i] = rasops_cmap[j + 1];
sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
j += 3;
#else
if (i >= SPLASH_CMAP_OFFSET &&
i < SPLASH_CMAP_OFFSET + SPLASH_CMAP_SIZE) {
splash_get_cmap(i,
@ -300,11 +296,9 @@ genfb_attach(struct genfb_softc *sc, struct genfb_ops *ops)
sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
}
j += 3;
#endif
}
genfb_restore_palette(sc);
#ifdef SPLASHSCREEN
sc->sc_splash.si_depth = sc->sc_depth;
sc->sc_splash.si_bits = sc->sc_console_screen.scr_ri.ri_bits;
sc->sc_splash.si_hwbits = sc->sc_fbaddr;
@ -317,10 +311,12 @@ genfb_attach(struct genfb_softc *sc, struct genfb_ops *ops)
SPLASH_F_CENTER|SPLASH_F_FILL);
if (error) {
SCREEN_ENABLE_DRAWING(&sc->sc_console_screen);
genfb_init_palette(sc);
vcons_replay_msgbuf(&sc->sc_console_screen);
}
}
#else
genfb_init_palette(sc);
vcons_replay_msgbuf(&sc->sc_console_screen);
#endif
@ -406,6 +402,7 @@ genfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
SPLASH_F_CENTER|SPLASH_F_FILL);
} else {
SCREEN_ENABLE_DRAWING(&sc->sc_console_screen);
genfb_init_palette(sc);
}
vcons_redraw_screen(ms);
return 0;
@ -513,6 +510,10 @@ genfb_init_screen(void *cookie, struct vcons_screen *scr,
if (ri->ri_depth == 32)
ri->ri_flg |= RI_ENABLE_ALPHA;
if (ri->ri_depth == 8)
ri->ri_flg |= RI_ENABLE_ALPHA | RI_8BIT_IS_RGB;
rasops_init(ri, sc->sc_height / 8, sc->sc_width / 8);
ri->ri_caps = WSSCREEN_WSCOLORS;
@ -605,6 +606,47 @@ genfb_restore_palette(struct genfb_softc *sc)
}
}
static void
genfb_init_palette(struct genfb_softc *sc)
{
int i, j, tmp;
if (sc->sc_depth == 8) {
/* generate an r3g3b2 colour map */
for (i = 0; i < 256; i++) {
tmp = i & 0xe0;
/*
* replicate bits so 0xe0 maps to a red value of 0xff
* in order to make white look actually white
*/
tmp |= (tmp >> 3) | (tmp >> 6);
sc->sc_cmap_red[i] = tmp;
tmp = (i & 0x1c) << 3;
tmp |= (tmp >> 3) | (tmp >> 6);
sc->sc_cmap_green[i] = tmp;
tmp = (i & 0x03) << 6;
tmp |= tmp >> 2;
tmp |= tmp >> 4;
sc->sc_cmap_blue[i] = tmp;
genfb_putpalreg(sc, i, sc->sc_cmap_red[i],
sc->sc_cmap_green[i],
sc->sc_cmap_blue[i]);
}
} else {
/* steal rasops' ANSI cmap */
j = 0;
for (i = 0; i < 256; i++) {
sc->sc_cmap_red[i] = rasops_cmap[j];
sc->sc_cmap_green[i] = rasops_cmap[j + 1];
sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
j += 3;
}
}
}
static int
genfb_putpalreg(struct genfb_softc *sc, uint8_t idx, uint8_t r, uint8_t g,
uint8_t b)