#if RASOPS_WIDTH != 8 && RASOPS_WIDTH != 16
#error "Width not supported"
#endif
#if RASOPS_WIDTH == 8
#define SUBST_UNIT uint8_t
#define GET_GLYPH(fr) (fr)[0]
#endif
#if RASOPS_WIDTH == 16
#define SUBST_UNIT uint16_t
# if BYTE_ORDER == BIG_ENDIAN
#define GET_GLYPH(fr) ((fr)[0] << 8) | (fr)[1]
# else
#define GET_GLYPH(fr) (fr)[0] | ((fr)[1] << 8)
# endif
#endif
#define NAME(width) NAME1(width)
#define NAME1(width) rasops1_putchar ## width
static void
NAME(RASOPS_WIDTH)(void *cookie, int row, int col, u_int uc, long attr)
{
struct rasops_info *ri = (struct rasops_info *)cookie;
struct wsdisplay_font *font = PICK_FONT(ri, uc);
int height;
uint32_t bg, fg;
uint8_t *fr;
SUBST_UNIT tmp, *rp, *hp;
hp = NULL;
if (__predict_false(!CHAR_IN_FONT(uc, font)))
return;
#ifdef RASOPS_CLIPPING
if ((unsigned)row >= (unsigned)ri->ri_rows)
return;
if ((unsigned)col >= (unsigned)ri->ri_cols)
return;
#endif
height = font->fontheight;
rp = (SUBST_UNIT *)(ri->ri_bits + row * ri->ri_yscale +
col * sizeof(SUBST_UNIT));
if (ri->ri_hwbits)
hp = (SUBST_UNIT *)(ri->ri_hwbits + row * ri->ri_yscale +
col * sizeof(SUBST_UNIT));
bg = ATTR_BG(ri, attr);
fg = ATTR_FG(ri, attr);
if (uc == ' ' || __predict_false(fg == bg)) {
while (height--) {
*rp = bg;
if (ri->ri_hwbits) {
*hp = bg;
DELTA(hp, ri->ri_stride, SUBST_UNIT *);
}
DELTA(rp, ri->ri_stride, SUBST_UNIT *);
}
} else {
fr = FONT_GLYPH(uc, font, ri);
while (height--) {
tmp = GET_GLYPH(fr);
fr += font->stride;
if (bg)
tmp = ~tmp;
*rp = tmp;
if (ri->ri_hwbits) {
*hp = tmp;
DELTA(hp, ri->ri_stride, SUBST_UNIT *);
}
DELTA(rp, ri->ri_stride, SUBST_UNIT *);
}
}
if ((attr & WSATTR_UNDERLINE) != 0) {
DELTA(rp, - ri->ri_stride * ri->ri_ul.off, SUBST_UNIT *);
if (ri->ri_hwbits)
DELTA(hp, - ri->ri_stride * ri->ri_ul.off,
SUBST_UNIT *);
for (height = ri->ri_ul.height; height; height--) {
DELTA(rp, - ri->ri_stride, SUBST_UNIT *);
*rp = fg;
if (ri->ri_hwbits) {
DELTA(hp, - ri->ri_stride, SUBST_UNIT *);
*hp = fg;
}
}
}
}
#undef SUBST_UNIT
#undef GET_GLYPH
#undef NAME
#undef NAME1