rasops1_putchar_width.h revision 1.5 1 /* $NetBSD: rasops1_putchar_width.h,v 1.5 2019/08/09 12:05:51 rin Exp $ */
2
3 /* NetBSD: rasops1.c,v 1.28 2019/07/25 03:02:44 rin Exp */
4 /*-
5 * Copyright (c) 1999 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Andrew Doran.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #if RASOPS_WIDTH != 8 && RASOPS_WIDTH != 16
34 #error "Width not supported"
35 #endif
36
37 #define PUTCHAR_WIDTH1(width) rasops1_putchar ## width
38 #define PUTCHAR_WIDTH(width) PUTCHAR_WIDTH1(width)
39
40 #if RASOPS_WIDTH == 8
41 #define COPY_UNIT uint8_t
42 #define GET_GLYPH tmp = fr[0]
43 #endif
44
45 #if RASOPS_WIDTH == 16
46 /*
47 * rp and hp are always half-word aligned, whereas
48 * fr may not be aligned in half-word boundary.
49 */
50 #define COPY_UNIT uint16_t
51 # if BYTE_ORDER == BIG_ENDIAN
52 #define GET_GLYPH tmp = (fr[0] << 8) | fr[1]
53 # else
54 #define GET_GLYPH tmp = fr[0] | (fr[1] << 8)
55 # endif
56 #endif /* RASOPS_WIDTH == 16 */
57
58 /*
59 * Width-optimized putchar function.
60 */
61 static void
62 PUTCHAR_WIDTH(RASOPS_WIDTH)(void *cookie, int row, int col, u_int uc, long attr)
63 {
64 struct rasops_info *ri = (struct rasops_info *)cookie;
65 struct wsdisplay_font *font = PICK_FONT(ri, uc);
66 int height, fs, rs, bg, fg;
67 uint8_t *fr;
68 COPY_UNIT *rp, *hp, tmp;
69
70 hp = NULL; /* XXX GCC */
71
72 if (__predict_false(!CHAR_IN_FONT(uc, font)))
73 return;
74
75 #ifdef RASOPS_CLIPPING
76 /* Catches 'row < 0' case too */
77 if ((unsigned)row >= (unsigned)ri->ri_rows)
78 return;
79
80 if ((unsigned)col >= (unsigned)ri->ri_cols)
81 return;
82 #endif
83
84 rp = (COPY_UNIT *)(ri->ri_bits + row * ri->ri_yscale +
85 col * sizeof(COPY_UNIT));
86 if (ri->ri_hwbits)
87 hp = (COPY_UNIT *)(ri->ri_hwbits + row * ri->ri_yscale +
88 col * sizeof(COPY_UNIT));
89 height = font->fontheight;
90 rs = ri->ri_stride;
91
92 bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
93 fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
94
95 /* If fg and bg match this becomes a space character */
96 if (uc == ' ' || fg == bg) {
97 while (height--) {
98 *rp = bg;
99 DELTA(rp, rs, COPY_UNIT *);
100 if (ri->ri_hwbits) {
101 *hp = bg;
102 DELTA(hp, rs, COPY_UNIT *);
103 }
104 }
105 } else {
106 fr = FONT_GLYPH(uc, font, ri);
107 fs = font->stride;
108
109 while (height--) {
110 GET_GLYPH;
111 if (bg)
112 tmp = ~tmp;
113 *rp = tmp;
114 DELTA(rp, rs, COPY_UNIT *);
115 if (ri->ri_hwbits) {
116 *hp = tmp;
117 DELTA(hp, rs, COPY_UNIT *);
118 }
119 fr += fs;
120 }
121 }
122
123 /* Do underline */
124 if ((attr & WSATTR_UNDERLINE) != 0) {
125 DELTA(rp, - ri->ri_stride * ri->ri_ul.off, COPY_UNIT *);
126 if (ri->ri_hwbits)
127 DELTA(hp, - ri->ri_stride * ri->ri_ul.off, COPY_UNIT *);
128 for (height = ri->ri_ul.height; height; height--) {
129 DELTA(rp, - ri->ri_stride, COPY_UNIT *);
130 *rp = fg;
131 if (ri->ri_hwbits) {
132 DELTA(hp, - ri->ri_stride, COPY_UNIT *);
133 *hp = fg;
134 }
135 }
136 }
137 }
138
139 #undef PUTCHAR_WIDTH1
140 #undef PUTCHAR_WIDTH
141
142 #undef COPY_UNIT
143 #undef GET_GLYPH
144