rasops_putchar_width.h revision 1.7 1 1.7 rin /* $NetBSD: rasops_putchar_width.h,v 1.7 2019/07/29 03:01:09 rin Exp $ */
2 1.1 rin
3 1.1 rin /* NetBSD: rasops8.c,v 1.41 2019/07/25 03:02:44 rin Exp */
4 1.1 rin /*-
5 1.1 rin * Copyright (c) 1999 The NetBSD Foundation, Inc.
6 1.1 rin * All rights reserved.
7 1.1 rin *
8 1.1 rin * This code is derived from software contributed to The NetBSD Foundation
9 1.1 rin * by Andrew Doran.
10 1.1 rin *
11 1.1 rin * Redistribution and use in source and binary forms, with or without
12 1.1 rin * modification, are permitted provided that the following conditions
13 1.1 rin * are met:
14 1.1 rin * 1. Redistributions of source code must retain the above copyright
15 1.1 rin * notice, this list of conditions and the following disclaimer.
16 1.1 rin * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 rin * notice, this list of conditions and the following disclaimer in the
18 1.1 rin * documentation and/or other materials provided with the distribution.
19 1.1 rin *
20 1.1 rin * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 1.1 rin * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.1 rin * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.1 rin * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 1.1 rin * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.1 rin * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.1 rin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.1 rin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.1 rin * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.1 rin * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.1 rin * POSSIBILITY OF SUCH DAMAGE.
31 1.1 rin */
32 1.1 rin
33 1.7 rin #if RASOPS_DEPTH != 2 && RASOPS_DEPTH != 4 && RASOPS_DEPTH != 8 && \
34 1.7 rin RASOPS_DEPTH != 15 && RASOPS_DEPTH != 24 && RASOPS_DEPTH != 32
35 1.1 rin #error "Depth not supported"
36 1.1 rin #endif
37 1.1 rin
38 1.1 rin #if RASOPS_WIDTH != 8 && RASOPS_WIDTH != 12 && RASOPS_WIDTH != 16
39 1.1 rin #error "Width not supported"
40 1.1 rin #endif
41 1.1 rin
42 1.1 rin #define PUTCHAR_WIDTH1(depth, width) rasops ## depth ## _putchar ## width
43 1.1 rin #define PUTCHAR_WIDTH(depth, width) PUTCHAR_WIDTH1(depth, width)
44 1.1 rin
45 1.1 rin #define PUTCHAR1(depth) rasops ## depth ## _putchar
46 1.1 rin #define PUTCHAR(depth) PUTCHAR1(depth)
47 1.1 rin
48 1.1 rin #define MAKESTAMP1(depth) rasops ## depth ## _makestamp
49 1.1 rin #define MAKESTAMP(depth) MAKESTAMP1(depth)
50 1.1 rin
51 1.7 rin #if RASOPS_DEPTH == 2
52 1.7 rin #define STAMP_TYPE uint8_t
53 1.7 rin #elif RASOPS_DEPTH == 4
54 1.7 rin #define STAMP_TYPE uint16_t
55 1.7 rin #else
56 1.7 rin #define STAMP_TYPE uint32_t
57 1.7 rin #endif
58 1.7 rin
59 1.7 rin #if RASOPS_DEPTH <= 8
60 1.7 rin #define FILLED_STAMP 15
61 1.7 rin #elif RASOPS_DEPTH == 15
62 1.7 rin #define FILLED_STAMP 30
63 1.7 rin #else
64 1.7 rin #define FILLED_STAMP 60
65 1.7 rin #endif
66 1.7 rin
67 1.1 rin /* ################################################################### */
68 1.1 rin
69 1.7 rin #if RASOPS_DEPTH <= 8
70 1.1 rin
71 1.5 rin #define SUBST_STAMP1(p, off, base) \
72 1.5 rin (p)[(off) * 1 + 0] = stamp[base]
73 1.1 rin
74 1.1 rin #define SUBST_GLYPH1(index, nibble, off) \
75 1.1 rin do { \
76 1.6 rin int so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK; \
77 1.1 rin rp[(off) * 1 + 0] = STAMP_READ(so); \
78 1.1 rin if (ri->ri_hwbits) { \
79 1.1 rin hrp[(off) * 1 + 0] = STAMP_READ(so); \
80 1.1 rin } \
81 1.5 rin } while (0 /* CONSTCOND */)
82 1.1 rin
83 1.7 rin #endif /* RASOPS_DEPTH <= 8 */
84 1.1 rin
85 1.1 rin /* ################################################################### */
86 1.1 rin
87 1.1 rin #if RASOPS_DEPTH == 15
88 1.1 rin
89 1.5 rin #define SUBST_STAMP1(p, off, base) \
90 1.5 rin (p)[(off) * 2 + 0] = (p)[(off) * 2 + 1] = stamp[base]
91 1.1 rin
92 1.1 rin #define SUBST_GLYPH1(index, nibble, off) \
93 1.1 rin do { \
94 1.6 rin int so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK; \
95 1.1 rin rp[(off) * 2 + 0] = STAMP_READ(so); \
96 1.1 rin rp[(off) * 2 + 1] = STAMP_READ(so + 4); \
97 1.1 rin if (ri->ri_hwbits) { \
98 1.1 rin hrp[(off) * 2 + 0] = STAMP_READ(so); \
99 1.1 rin hrp[(off) * 2 + 1] = STAMP_READ(so + 4); \
100 1.1 rin } \
101 1.5 rin } while (0 /* CONSTCOND */)
102 1.1 rin
103 1.1 rin #endif /* RASOPS_DEPTH == 15 */
104 1.1 rin
105 1.1 rin /* ################################################################### */
106 1.1 rin
107 1.1 rin #if RASOPS_DEPTH == 24
108 1.1 rin
109 1.4 rin #define SUBST_STAMP1(p, off, base) \
110 1.4 rin do { \
111 1.4 rin (p)[(off) * 3 + 0] = stamp[(base) + 0]; \
112 1.4 rin (p)[(off) * 3 + 1] = stamp[(base) + 1]; \
113 1.4 rin (p)[(off) * 3 + 2] = stamp[(base) + 2]; \
114 1.5 rin } while (0 /* CONSTCOND */)
115 1.1 rin
116 1.1 rin #define SUBST_GLYPH1(index, nibble, off) \
117 1.1 rin do { \
118 1.6 rin int so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK; \
119 1.1 rin rp[(off) * 3 + 0] = STAMP_READ(so); \
120 1.1 rin rp[(off) * 3 + 1] = STAMP_READ(so + 4); \
121 1.1 rin rp[(off) * 3 + 2] = STAMP_READ(so + 8); \
122 1.1 rin if (ri->ri_hwbits) { \
123 1.1 rin hrp[(off) * 3 + 0] = STAMP_READ(so); \
124 1.1 rin hrp[(off) * 3 + 1] = STAMP_READ(so + 4); \
125 1.1 rin hrp[(off) * 3 + 2] = STAMP_READ(so + 8); \
126 1.1 rin } \
127 1.5 rin } while (0 /* CONSTCOND */)
128 1.1 rin
129 1.1 rin #endif /* RASOPS_DEPTH == 24 */
130 1.1 rin
131 1.1 rin /* ################################################################### */
132 1.1 rin
133 1.1 rin #if RASOPS_DEPTH == 32
134 1.1 rin
135 1.5 rin #define SUBST_STAMP1(p, off, base) \
136 1.1 rin (p)[(off) * 4 + 0] = (p)[(off) * 4 + 1] = \
137 1.5 rin (p)[(off) * 4 + 2] = (p)[(off) * 4 + 3] = stamp[base]
138 1.1 rin
139 1.1 rin #define SUBST_GLYPH1(index, nibble, off) \
140 1.1 rin do { \
141 1.6 rin int so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK; \
142 1.1 rin rp[(off) * 4 + 0] = STAMP_READ(so); \
143 1.1 rin rp[(off) * 4 + 1] = STAMP_READ(so + 4); \
144 1.1 rin rp[(off) * 4 + 2] = STAMP_READ(so + 8); \
145 1.1 rin rp[(off) * 4 + 3] = STAMP_READ(so + 12); \
146 1.1 rin if (ri->ri_hwbits) { \
147 1.1 rin hrp[(off) * 4 + 0] = STAMP_READ(so); \
148 1.1 rin hrp[(off) * 4 + 1] = STAMP_READ(so + 4); \
149 1.1 rin hrp[(off) * 4 + 2] = STAMP_READ(so + 8); \
150 1.1 rin hrp[(off) * 4 + 3] = STAMP_READ(so + 12); \
151 1.1 rin } \
152 1.5 rin } while (0 /* CONSTCOND */)
153 1.1 rin
154 1.1 rin #endif /* RASOPS_DEPTH == 32 */
155 1.1 rin
156 1.1 rin /* ################################################################### */
157 1.1 rin
158 1.4 rin #if RASOPS_WIDTH == 8
159 1.5 rin #define SUBST_STAMP(p, base) \
160 1.5 rin do { \
161 1.5 rin SUBST_STAMP1(p, 0, base); \
162 1.5 rin SUBST_STAMP1(p, 1, base); \
163 1.5 rin } while (0 /* CONSTCOND */)
164 1.4 rin #elif RASOPS_WIDTH == 12
165 1.5 rin #define SUBST_STAMP(p, base) \
166 1.5 rin do { \
167 1.5 rin SUBST_STAMP1(p, 0, base); \
168 1.5 rin SUBST_STAMP1(p, 1, base); \
169 1.5 rin SUBST_STAMP1(p, 2, base); \
170 1.5 rin } while (0 /* CONSTCOND */)
171 1.4 rin #elif RASOPS_WIDTH == 16
172 1.5 rin #define SUBST_STAMP(p, base) \
173 1.5 rin do { \
174 1.5 rin SUBST_STAMP1(p, 0, base); \
175 1.5 rin SUBST_STAMP1(p, 1, base); \
176 1.5 rin SUBST_STAMP1(p, 2, base); \
177 1.5 rin SUBST_STAMP1(p, 3, base); \
178 1.5 rin } while (0 /* CONSTCOND */)
179 1.4 rin #endif
180 1.1 rin
181 1.1 rin #if RASOPS_WIDTH == 8
182 1.5 rin #define SUBST_GLYPH \
183 1.5 rin do { \
184 1.5 rin SUBST_GLYPH1(0, 1, 0); \
185 1.5 rin SUBST_GLYPH1(0, 0, 1); \
186 1.5 rin } while (0 /* CONSTCOND */)
187 1.1 rin #elif RASOPS_WIDTH == 12
188 1.5 rin #define SUBST_GLYPH \
189 1.5 rin do { \
190 1.5 rin SUBST_GLYPH1(0, 1, 0); \
191 1.5 rin SUBST_GLYPH1(0, 0, 1); \
192 1.5 rin SUBST_GLYPH1(1, 1, 2); \
193 1.5 rin } while (0 /* CONSTCOND */)
194 1.1 rin #elif RASOPS_WIDTH == 16
195 1.5 rin #define SUBST_GLYPH \
196 1.5 rin do { \
197 1.5 rin SUBST_GLYPH1(0, 1, 0); \
198 1.5 rin SUBST_GLYPH1(0, 0, 1); \
199 1.5 rin SUBST_GLYPH1(1, 1, 2); \
200 1.5 rin SUBST_GLYPH1(1, 0, 3); \
201 1.5 rin } while (0 /* CONSTCOND */)
202 1.1 rin #endif
203 1.1 rin
204 1.1 rin /*
205 1.1 rin * Width-optimized putchar function.
206 1.1 rin */
207 1.1 rin static void
208 1.1 rin PUTCHAR_WIDTH(RASOPS_DEPTH, RASOPS_WIDTH)(void *cookie, int row, int col,
209 1.1 rin u_int uc, long attr)
210 1.1 rin {
211 1.1 rin struct rasops_info *ri = (struct rasops_info *)cookie;
212 1.1 rin struct wsdisplay_font *font = PICK_FONT(ri, uc);
213 1.6 rin int height, fs;
214 1.7 rin STAMP_TYPE *rp, *hrp;
215 1.1 rin uint8_t *fr;
216 1.1 rin
217 1.1 rin hrp = NULL; /* XXX GCC */
218 1.1 rin
219 1.1 rin #ifdef RASOPS_CLIPPING
220 1.1 rin /* Catches 'row < 0' case too */
221 1.1 rin if ((unsigned)row >= (unsigned)ri->ri_rows)
222 1.1 rin return;
223 1.1 rin
224 1.1 rin if ((unsigned)col >= (unsigned)ri->ri_cols)
225 1.1 rin return;
226 1.1 rin #endif
227 1.1 rin
228 1.1 rin /* check if character fits into font limits */
229 1.1 rin if (!CHAR_IN_FONT(uc, font))
230 1.1 rin return;
231 1.1 rin
232 1.1 rin /* Can't risk remaking the stamp if it's already in use */
233 1.1 rin if (stamp_mutex++) {
234 1.1 rin stamp_mutex--;
235 1.1 rin PUTCHAR(RASOPS_DEPTH)(cookie, row, col, uc, attr);
236 1.1 rin return;
237 1.1 rin }
238 1.1 rin
239 1.1 rin /* Recompute stamp? */
240 1.1 rin if (attr != stamp_attr)
241 1.1 rin MAKESTAMP(RASOPS_DEPTH)(ri, attr);
242 1.1 rin
243 1.7 rin rp = (STAMP_TYPE *)(ri->ri_bits + row * ri->ri_yscale +
244 1.7 rin col * ri->ri_xscale);
245 1.1 rin if (ri->ri_hwbits)
246 1.7 rin hrp = (STAMP_TYPE *)(ri->ri_hwbits + row * ri->ri_yscale +
247 1.7 rin col * ri->ri_xscale);
248 1.1 rin
249 1.1 rin height = font->fontheight;
250 1.1 rin
251 1.1 rin if (uc == ' ') {
252 1.1 rin while (height--) {
253 1.4 rin SUBST_STAMP(rp, 0);
254 1.7 rin DELTA(rp, ri->ri_stride, STAMP_TYPE *);
255 1.7 rin }
256 1.7 rin if (ri->ri_hwbits) {
257 1.7 rin while (height--) {
258 1.4 rin SUBST_STAMP(hrp, 0);
259 1.7 rin DELTA(hrp, ri->ri_stride, STAMP_TYPE *);
260 1.1 rin }
261 1.1 rin }
262 1.4 rin } else {
263 1.1 rin fr = FONT_GLYPH(uc, font, ri);
264 1.1 rin fs = font->stride;
265 1.1 rin
266 1.1 rin while (height--) {
267 1.4 rin SUBST_GLYPH;
268 1.1 rin
269 1.1 rin fr += fs;
270 1.7 rin DELTA(rp, ri->ri_stride, STAMP_TYPE *);
271 1.1 rin if (ri->ri_hwbits)
272 1.7 rin DELTA(hrp, ri->ri_stride, STAMP_TYPE *);
273 1.1 rin }
274 1.1 rin }
275 1.1 rin
276 1.1 rin /* Do underline */
277 1.1 rin if ((attr & WSATTR_UNDERLINE) != 0) {
278 1.7 rin DELTA(rp, -(ri->ri_stride << 1), STAMP_TYPE *);
279 1.4 rin SUBST_STAMP(rp, FILLED_STAMP);
280 1.4 rin if (ri->ri_hwbits) {
281 1.7 rin DELTA(hrp, -(ri->ri_stride << 1), STAMP_TYPE *);
282 1.4 rin SUBST_STAMP(hrp, FILLED_STAMP);
283 1.4 rin }
284 1.1 rin }
285 1.1 rin
286 1.1 rin stamp_mutex--;
287 1.1 rin }
288 1.1 rin
289 1.7 rin #undef STAMP_TYPE
290 1.7 rin
291 1.1 rin #undef FILLED_STAMP
292 1.1 rin
293 1.1 rin #undef PUTCHAR_WIDTH1
294 1.1 rin #undef PUTCHAR_WIDTH
295 1.1 rin
296 1.1 rin #undef PUTCHAR1
297 1.1 rin #undef PUTCHAR
298 1.1 rin
299 1.1 rin #undef MAKESTAMP1
300 1.1 rin #undef MAKESTAMP
301 1.1 rin
302 1.1 rin #undef SUBST_STAMP1
303 1.1 rin #undef SUBST_STAMP
304 1.1 rin
305 1.1 rin #undef SUBST_GLYPH1
306 1.1 rin #undef SUBST_GLYPH
307