2019-08-09 15:05:51 +03:00
|
|
|
/* $NetBSD: rasops_putchar.h,v 1.7 2019/08/09 12:05:51 rin Exp $ */
|
2019-07-25 18:18:53 +03:00
|
|
|
|
|
|
|
/* NetBSD: rasops8.c,v 1.41 2019/07/25 03:02:44 rin Exp */
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Andrew Doran.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if RASOPS_DEPTH != 8 && RASOPS_DEPTH != 15 && RASOPS_DEPTH != 24 && \
|
|
|
|
RASOPS_DEPTH != 32
|
|
|
|
#error "Depth not supported"
|
|
|
|
#endif
|
|
|
|
|
2019-07-30 18:29:40 +03:00
|
|
|
#if RASOPS_DEPTH == 8
|
|
|
|
#define COLOR_TYPE uint8_t
|
2019-07-25 18:18:53 +03:00
|
|
|
#elif RASOPS_DEPTH == 15
|
2019-07-30 18:29:40 +03:00
|
|
|
#define COLOR_TYPE uint16_t
|
2019-07-25 18:18:53 +03:00
|
|
|
#else
|
2019-07-30 18:29:40 +03:00
|
|
|
#define COLOR_TYPE uint32_t
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if RASOPS_DEPTH != 24
|
2019-08-07 15:33:48 +03:00
|
|
|
#define PIXEL_TYPE COLOR_TYPE
|
|
|
|
#define PIXEL_BYTES sizeof(PIXEL_TYPE)
|
|
|
|
#define SET_PIXEL(p, index) *(p)++ = clr[index]
|
|
|
|
#define SET_RGB(p, r, g, b) \
|
|
|
|
*(p)++ = (((r) >> (8 - ri->ri_rnum)) << ri->ri_rpos) | \
|
|
|
|
(((g) >> (8 - ri->ri_gnum)) << ri->ri_gpos) | \
|
|
|
|
(((b) >> (8 - ri->ri_bnum)) << ri->ri_bpos)
|
2019-07-25 18:18:53 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if RASOPS_DEPTH == 24
|
2019-08-07 15:33:48 +03:00
|
|
|
#define PIXEL_TYPE uint8_t
|
2019-07-30 18:29:40 +03:00
|
|
|
#define PIXEL_BYTES 3
|
|
|
|
#define SET_PIXEL(p, index) \
|
2019-07-25 18:18:53 +03:00
|
|
|
do { \
|
2019-07-30 18:29:40 +03:00
|
|
|
COLOR_TYPE c = clr[index]; \
|
2019-07-25 18:18:53 +03:00
|
|
|
*(p)++ = c >> 16; \
|
|
|
|
*(p)++ = c >> 8; \
|
|
|
|
*(p)++ = c; \
|
|
|
|
} while (0 /* CONSTCOND */)
|
2019-08-07 15:33:48 +03:00
|
|
|
#define SET_RGB(p, r, g, b) \
|
|
|
|
do { \
|
|
|
|
(p)[R_OFF] = (r); \
|
|
|
|
(p)[G_OFF] = (g); \
|
|
|
|
(p)[B_OFF] = (b); \
|
|
|
|
(p) += 3; \
|
|
|
|
} while (0 /* CONSTCOND */)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define AV(p, w) (((w) * (p)[1] + (0xff - (w)) * (p)[0]) >> 8)
|
|
|
|
|
|
|
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
|
|
|
#define R_OFF (ri->ri_rpos / 8)
|
|
|
|
#define G_OFF (ri->ri_gpos / 8)
|
|
|
|
#define B_OFF (ri->ri_bpos / 8)
|
|
|
|
#else /* BIG_ENDIAN XXX not tested */
|
|
|
|
#define R_OFF (2 - ri->ri_rpos / 8)
|
|
|
|
#define G_OFF (2 - ri->ri_gpos / 8)
|
|
|
|
#define B_OFF (2 - ri->ri_bpos / 8)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define NAME(depth) NAME1(depth)
|
|
|
|
#ifndef RASOPS_AA
|
|
|
|
#define NAME1(depth) rasops ## depth ## _putchar
|
|
|
|
#else
|
|
|
|
#define NAME1(depth) rasops ## depth ## _putchar_aa
|
2019-07-25 18:18:53 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Put a single character.
|
|
|
|
*/
|
|
|
|
static void
|
2019-08-07 15:33:48 +03:00
|
|
|
NAME(RASOPS_DEPTH)(void *cookie, int row, int col, u_int uc, long attr)
|
2019-07-25 18:18:53 +03:00
|
|
|
{
|
|
|
|
struct rasops_info *ri = (struct rasops_info *)cookie;
|
|
|
|
struct wsdisplay_font *font = PICK_FONT(ri, uc);
|
2019-08-07 15:33:48 +03:00
|
|
|
int height, width, cnt;
|
2019-07-30 18:29:40 +03:00
|
|
|
COLOR_TYPE clr[2];
|
2019-08-07 15:33:48 +03:00
|
|
|
PIXEL_TYPE *dp, *rp, *hp;
|
|
|
|
uint8_t *fr;
|
2019-07-25 18:18:53 +03:00
|
|
|
|
2019-07-30 18:29:40 +03:00
|
|
|
hp = NULL; /* XXX GCC */
|
2019-07-25 18:18:53 +03:00
|
|
|
|
2019-08-09 15:05:51 +03:00
|
|
|
if (__predict_false(!CHAR_IN_FONT(uc, font)))
|
2019-07-25 18:18:53 +03:00
|
|
|
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
|
|
|
|
|
2019-08-07 15:33:48 +03:00
|
|
|
rp = (PIXEL_TYPE *)(ri->ri_bits + row * ri->ri_yscale +
|
|
|
|
col * ri->ri_xscale);
|
2019-07-25 18:18:53 +03:00
|
|
|
if (ri->ri_hwbits)
|
2019-08-07 15:33:48 +03:00
|
|
|
hp = (PIXEL_TYPE *)(ri->ri_hwbits + row * ri->ri_yscale +
|
|
|
|
col * ri->ri_xscale);
|
2019-07-25 18:18:53 +03:00
|
|
|
|
|
|
|
height = font->fontheight;
|
|
|
|
width = font->fontwidth;
|
|
|
|
|
2019-07-30 18:29:40 +03:00
|
|
|
clr[0] = (COLOR_TYPE)ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
|
|
|
|
clr[1] = (COLOR_TYPE)ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf];
|
2019-07-25 18:18:53 +03:00
|
|
|
|
|
|
|
if (uc == ' ') {
|
|
|
|
while (height--) {
|
|
|
|
dp = rp;
|
2019-07-30 18:29:40 +03:00
|
|
|
for (cnt = width; cnt; cnt--)
|
|
|
|
SET_PIXEL(dp, 0);
|
|
|
|
if (ri->ri_hwbits) {
|
|
|
|
uint16_t bytes = width * PIXEL_BYTES;
|
|
|
|
/* XXX GCC */
|
|
|
|
memcpy(hp, rp, bytes);
|
2019-08-07 15:33:48 +03:00
|
|
|
DELTA(hp, ri->ri_stride, PIXEL_TYPE *);
|
2019-07-25 18:18:53 +03:00
|
|
|
}
|
2019-08-07 15:33:48 +03:00
|
|
|
DELTA(rp, ri->ri_stride, PIXEL_TYPE *);
|
2019-07-25 18:18:53 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fr = FONT_GLYPH(uc, font, ri);
|
2019-08-07 15:33:48 +03:00
|
|
|
|
|
|
|
#ifdef RASOPS_AA
|
|
|
|
int off[2];
|
|
|
|
uint8_t r[2], g[2], b[2];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is independent to positions/lengths of RGB in pixel.
|
|
|
|
*/
|
|
|
|
off[0] = (((uint32_t)attr >> 16) & 0xf) * 3;
|
|
|
|
off[1] = (((uint32_t)attr >> 24) & 0xf) * 3;
|
|
|
|
|
|
|
|
r[0] = rasops_cmap[off[0]];
|
|
|
|
r[1] = rasops_cmap[off[1]];
|
|
|
|
g[0] = rasops_cmap[off[0] + 1];
|
|
|
|
g[1] = rasops_cmap[off[1] + 1];
|
|
|
|
b[0] = rasops_cmap[off[0] + 2];
|
|
|
|
b[1] = rasops_cmap[off[1] + 2];
|
|
|
|
#endif
|
2019-07-25 18:18:53 +03:00
|
|
|
|
|
|
|
while (height--) {
|
|
|
|
dp = rp;
|
2019-08-07 15:33:48 +03:00
|
|
|
|
|
|
|
#ifndef RASOPS_AA
|
|
|
|
uint32_t fb = be32uatoh(fr);
|
|
|
|
fr += ri->ri_font->stride;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (cnt = width; cnt; cnt--)
|
|
|
|
#ifndef RASOPS_AA
|
|
|
|
{
|
2019-07-30 18:29:40 +03:00
|
|
|
SET_PIXEL(dp, (fb >> 31) & 1);
|
2019-07-25 18:18:53 +03:00
|
|
|
fb <<= 1;
|
|
|
|
}
|
2019-08-07 15:33:48 +03:00
|
|
|
#else
|
|
|
|
{
|
|
|
|
int w = *fr++;
|
|
|
|
if (w == 0xff)
|
|
|
|
SET_PIXEL(dp, 1);
|
|
|
|
else if (w == 0)
|
|
|
|
SET_PIXEL(dp, 0);
|
|
|
|
else
|
|
|
|
SET_RGB(dp,
|
|
|
|
AV(r, w), AV(g, w), AV(b, w));
|
|
|
|
}
|
|
|
|
#endif
|
2019-07-30 18:29:40 +03:00
|
|
|
if (ri->ri_hwbits) {
|
|
|
|
uint16_t bytes = width * PIXEL_BYTES;
|
|
|
|
/* XXX GCC */
|
|
|
|
memcpy(hp, rp, bytes);
|
2019-08-07 15:33:48 +03:00
|
|
|
DELTA(hp, ri->ri_stride, PIXEL_TYPE *);
|
2019-07-30 18:29:40 +03:00
|
|
|
}
|
2019-08-07 15:33:48 +03:00
|
|
|
DELTA(rp, ri->ri_stride, PIXEL_TYPE *);
|
2019-07-25 18:18:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do underline */
|
|
|
|
if ((attr & WSATTR_UNDERLINE) != 0) {
|
2019-08-07 15:33:48 +03:00
|
|
|
DELTA(rp, - ri->ri_stride * ri->ri_ul.off, PIXEL_TYPE *);
|
|
|
|
if (ri->ri_hwbits)
|
|
|
|
DELTA(hp, - ri->ri_stride * ri->ri_ul.off,
|
|
|
|
PIXEL_TYPE *);
|
|
|
|
for (height = ri->ri_ul.height; height; height--) {
|
|
|
|
DELTA(rp, - ri->ri_stride, PIXEL_TYPE *);
|
|
|
|
dp = rp;
|
|
|
|
for (cnt = width; cnt; cnt--)
|
|
|
|
SET_PIXEL(dp, 1);
|
|
|
|
if (ri->ri_hwbits) {
|
|
|
|
DELTA(hp, - ri->ri_stride, PIXEL_TYPE *);
|
|
|
|
uint16_t bytes = width * PIXEL_BYTES;
|
|
|
|
/* XXX GCC */
|
|
|
|
memcpy(hp, rp, bytes);
|
|
|
|
}
|
2019-07-25 18:18:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-30 18:29:40 +03:00
|
|
|
#undef COLOR_TYPE
|
2019-08-07 15:33:48 +03:00
|
|
|
|
|
|
|
#undef PIXEL_TYPE
|
2019-07-30 18:29:40 +03:00
|
|
|
#undef PIXEL_BYTES
|
|
|
|
#undef SET_PIXEL
|
2019-08-07 15:33:48 +03:00
|
|
|
#undef SET_RGB
|
|
|
|
|
|
|
|
#undef AV
|
|
|
|
|
|
|
|
#undef R_OFF
|
|
|
|
#undef G_OFF
|
|
|
|
#undef B_OFF
|
|
|
|
|
|
|
|
#undef NAME
|
|
|
|
#undef NAME1
|