rasops8.c revision 1.32 1 1.32 macallan /* $NetBSD: rasops8.c,v 1.32 2012/01/25 20:18:04 macallan Exp $ */
2 1.1 ad
3 1.4 ad /*-
4 1.4 ad * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 1.1 ad * All rights reserved.
6 1.1 ad *
7 1.4 ad * This code is derived from software contributed to The NetBSD Foundation
8 1.9 ad * by Andrew Doran.
9 1.4 ad *
10 1.1 ad * Redistribution and use in source and binary forms, with or without
11 1.1 ad * modification, are permitted provided that the following conditions
12 1.1 ad * are met:
13 1.1 ad * 1. Redistributions of source code must retain the above copyright
14 1.1 ad * notice, this list of conditions and the following disclaimer.
15 1.1 ad * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 ad * notice, this list of conditions and the following disclaimer in the
17 1.1 ad * documentation and/or other materials provided with the distribution.
18 1.1 ad *
19 1.4 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.4 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.4 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.4 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.4 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.4 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.4 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.4 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.4 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.4 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.4 ad * POSSIBILITY OF SUCH DAMAGE.
30 1.1 ad */
31 1.2 ad
32 1.12 lukem #include <sys/cdefs.h>
33 1.32 macallan __KERNEL_RCSID(0, "$NetBSD: rasops8.c,v 1.32 2012/01/25 20:18:04 macallan Exp $");
34 1.12 lukem
35 1.1 ad #include "opt_rasops.h"
36 1.1 ad
37 1.1 ad #include <sys/param.h>
38 1.1 ad #include <sys/systm.h>
39 1.1 ad #include <sys/time.h>
40 1.1 ad
41 1.1 ad #include <dev/wscons/wsdisplayvar.h>
42 1.1 ad #include <dev/wscons/wsconsio.h>
43 1.1 ad #include <dev/rasops/rasops.h>
44 1.1 ad
45 1.18 perry static void rasops8_putchar(void *, int, int, u_int, long attr);
46 1.30 macallan static void rasops8_putchar_aa(void *, int, int, u_int, long attr);
47 1.7 ad #ifndef RASOPS_SMALL
48 1.18 perry static void rasops8_putchar8(void *, int, int, u_int, long attr);
49 1.18 perry static void rasops8_putchar12(void *, int, int, u_int, long attr);
50 1.18 perry static void rasops8_putchar16(void *, int, int, u_int, long attr);
51 1.18 perry static void rasops8_makestamp(struct rasops_info *ri, long);
52 1.1 ad
53 1.8 pk /*
54 1.8 pk * 4x1 stamp for optimized character blitting
55 1.1 ad */
56 1.1 ad static int32_t stamp[16];
57 1.1 ad static long stamp_attr;
58 1.1 ad static int stamp_mutex; /* XXX see note in README */
59 1.10 bjh21 #endif
60 1.1 ad
61 1.1 ad /*
62 1.1 ad * XXX this confuses the hell out of gcc2 (not egcs) which always insists
63 1.1 ad * that the shift count is negative.
64 1.1 ad *
65 1.1 ad * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
66 1.1 ad * destination = STAMP_READ(offset)
67 1.1 ad */
68 1.1 ad #define STAMP_SHIFT(fb,n) ((n*4-2) >= 0 ? (fb)>>(n*4-2):(fb)<<-(n*4-2))
69 1.8 pk #define STAMP_MASK (0xf << 2)
70 1.22 christos #define STAMP_READ(o) (*(int32_t *)((char *)stamp + (o)))
71 1.1 ad
72 1.1 ad /*
73 1.11 wiz * Initialize a 'rasops_info' descriptor for this depth.
74 1.1 ad */
75 1.1 ad void
76 1.25 dsl rasops8_init(struct rasops_info *ri)
77 1.1 ad {
78 1.8 pk
79 1.30 macallan if FONT_IS_ALPHA(ri->ri_font) {
80 1.30 macallan ri->ri_ops.putchar = rasops8_putchar_aa;
81 1.30 macallan } else {
82 1.30 macallan switch (ri->ri_font->fontwidth) {
83 1.7 ad #ifndef RASOPS_SMALL
84 1.30 macallan case 8:
85 1.30 macallan ri->ri_ops.putchar = rasops8_putchar8;
86 1.30 macallan break;
87 1.30 macallan case 12:
88 1.30 macallan ri->ri_ops.putchar = rasops8_putchar12;
89 1.30 macallan break;
90 1.30 macallan case 16:
91 1.30 macallan ri->ri_ops.putchar = rasops8_putchar16;
92 1.30 macallan break;
93 1.7 ad #endif /* !RASOPS_SMALL */
94 1.30 macallan default:
95 1.30 macallan ri->ri_ops.putchar = rasops8_putchar;
96 1.30 macallan break;
97 1.30 macallan }
98 1.1 ad }
99 1.28 macallan if (ri->ri_flg & RI_8BIT_IS_RGB) {
100 1.28 macallan ri->ri_rnum = 3;
101 1.28 macallan ri->ri_rpos = 5;
102 1.28 macallan ri->ri_gnum = 3;
103 1.28 macallan ri->ri_gpos = 2;
104 1.28 macallan ri->ri_bnum = 2;
105 1.28 macallan ri->ri_bpos = 0;
106 1.28 macallan }
107 1.1 ad }
108 1.1 ad
109 1.1 ad /*
110 1.3 ad * Put a single character.
111 1.1 ad */
112 1.1 ad static void
113 1.26 dsl rasops8_putchar(void *cookie, int row, int col, u_int uc, long attr)
114 1.1 ad {
115 1.7 ad int width, height, cnt, fs, fb;
116 1.21 jmcneill u_char *dp, *rp, *hp, *hrp, *fr, clr[2];
117 1.27 macallan struct rasops_info *ri = (struct rasops_info *)cookie;
118 1.27 macallan struct wsdisplay_font *font = PICK_FONT(ri, uc);
119 1.8 pk
120 1.21 jmcneill hp = hrp = NULL;
121 1.1 ad
122 1.27 macallan if (!CHAR_IN_FONT(uc, font))
123 1.17 petrov return;
124 1.17 petrov
125 1.8 pk #ifdef RASOPS_CLIPPING
126 1.8 pk /* Catches 'row < 0' case too */
127 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows)
128 1.1 ad return;
129 1.1 ad
130 1.1 ad if ((unsigned)col >= (unsigned)ri->ri_cols)
131 1.1 ad return;
132 1.1 ad #endif
133 1.1 ad rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
134 1.21 jmcneill if (ri->ri_hwbits)
135 1.21 jmcneill hrp = ri->ri_hwbits + row * ri->ri_yscale + col *
136 1.21 jmcneill ri->ri_xscale;
137 1.1 ad
138 1.27 macallan height = font->fontheight;
139 1.27 macallan width = font->fontwidth;
140 1.8 pk clr[0] = (u_char)ri->ri_devcmap[(attr >> 16) & 0xf];
141 1.8 pk clr[1] = (u_char)ri->ri_devcmap[(attr >> 24) & 0xf];
142 1.8 pk
143 1.1 ad if (uc == ' ') {
144 1.8 pk u_char c = clr[0];
145 1.8 pk
146 1.1 ad while (height--) {
147 1.32 macallan memset(rp, c, width);
148 1.21 jmcneill if (ri->ri_hwbits) {
149 1.32 macallan memset(hrp, c, width);
150 1.21 jmcneill hrp += ri->ri_stride;
151 1.21 jmcneill }
152 1.32 macallan rp += ri->ri_stride;
153 1.1 ad }
154 1.1 ad } else {
155 1.29 macallan fr = WSFONT_GLYPH(uc, font);
156 1.27 macallan fs = font->stride;
157 1.1 ad
158 1.1 ad while (height--) {
159 1.1 ad dp = rp;
160 1.21 jmcneill if (ri->ri_hwbits)
161 1.21 jmcneill hp = hrp;
162 1.1 ad fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) | (fr[0] << 24);
163 1.1 ad fr += fs;
164 1.1 ad rp += ri->ri_stride;
165 1.21 jmcneill if (ri->ri_hwbits)
166 1.21 jmcneill hrp += ri->ri_stride;
167 1.8 pk
168 1.1 ad for (cnt = width; cnt; cnt--) {
169 1.1 ad *dp++ = clr[(fb >> 31) & 1];
170 1.21 jmcneill if (ri->ri_hwbits)
171 1.21 jmcneill *hp++ = clr[(fb >> 31) & 1];
172 1.1 ad fb <<= 1;
173 1.1 ad }
174 1.1 ad }
175 1.8 pk }
176 1.1 ad
177 1.1 ad /* Do underline */
178 1.7 ad if ((attr & 1) != 0) {
179 1.8 pk u_char c = clr[1];
180 1.8 pk
181 1.1 ad rp -= (ri->ri_stride << 1);
182 1.21 jmcneill if (ri->ri_hwbits)
183 1.21 jmcneill hrp -= (ri->ri_stride << 1);
184 1.1 ad
185 1.21 jmcneill while (width--) {
186 1.8 pk *rp++ = c;
187 1.21 jmcneill if (ri->ri_hwbits)
188 1.21 jmcneill *hrp++ = c;
189 1.21 jmcneill }
190 1.8 pk }
191 1.1 ad }
192 1.1 ad
193 1.30 macallan static void
194 1.30 macallan rasops8_putchar_aa(void *cookie, int row, int col, u_int uc, long attr)
195 1.30 macallan {
196 1.32 macallan int width, height, fs;
197 1.30 macallan u_char *dp, *rp, *hp, *hrp, *fr, bg, fg, pixel;
198 1.30 macallan struct rasops_info *ri = (struct rasops_info *)cookie;
199 1.30 macallan struct wsdisplay_font *font = PICK_FONT(ri, uc);
200 1.30 macallan int x, y, r, g, b, aval;
201 1.30 macallan int r1, g1, b1, r0, g0, b0, fgo, bgo;
202 1.31 macallan uint8_t scanline[32] __attribute__ ((aligned(8)));
203 1.30 macallan
204 1.30 macallan hp = hrp = NULL;
205 1.30 macallan
206 1.30 macallan if (!CHAR_IN_FONT(uc, font))
207 1.30 macallan return;
208 1.30 macallan
209 1.30 macallan #ifdef RASOPS_CLIPPING
210 1.30 macallan /* Catches 'row < 0' case too */
211 1.30 macallan if ((unsigned)row >= (unsigned)ri->ri_rows)
212 1.30 macallan return;
213 1.30 macallan
214 1.30 macallan if ((unsigned)col >= (unsigned)ri->ri_cols)
215 1.30 macallan return;
216 1.30 macallan #endif
217 1.30 macallan rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
218 1.30 macallan if (ri->ri_hwbits)
219 1.30 macallan hrp = ri->ri_hwbits + row * ri->ri_yscale + col *
220 1.30 macallan ri->ri_xscale;
221 1.30 macallan
222 1.30 macallan height = font->fontheight;
223 1.30 macallan width = font->fontwidth;
224 1.30 macallan bg = (u_char)ri->ri_devcmap[(attr >> 16) & 0xf];
225 1.30 macallan fg = (u_char)ri->ri_devcmap[(attr >> 24) & 0xf];
226 1.30 macallan
227 1.30 macallan if (uc == ' ') {
228 1.30 macallan
229 1.30 macallan while (height--) {
230 1.32 macallan memset(rp, bg, width);
231 1.30 macallan if (ri->ri_hwbits) {
232 1.32 macallan memset(hrp, bg, width);
233 1.30 macallan hrp += ri->ri_stride;
234 1.30 macallan }
235 1.32 macallan rp += ri->ri_stride;
236 1.30 macallan }
237 1.30 macallan } else {
238 1.30 macallan fr = WSFONT_GLYPH(uc, font);
239 1.30 macallan fs = font->stride;
240 1.30 macallan /*
241 1.30 macallan * we need the RGB colours here, get offsets into rasops_cmap
242 1.30 macallan */
243 1.30 macallan fgo = ((attr >> 24) & 0xf) * 3;
244 1.30 macallan bgo = ((attr >> 16) & 0xf) * 3;
245 1.30 macallan
246 1.30 macallan r0 = rasops_cmap[bgo];
247 1.30 macallan r1 = rasops_cmap[fgo];
248 1.30 macallan g0 = rasops_cmap[bgo + 1];
249 1.30 macallan g1 = rasops_cmap[fgo + 1];
250 1.30 macallan b0 = rasops_cmap[bgo + 2];
251 1.30 macallan b1 = rasops_cmap[fgo + 2];
252 1.30 macallan
253 1.30 macallan for (y = 0; y < height; y++) {
254 1.30 macallan dp = rp;
255 1.30 macallan for (x = 0; x < width; x++) {
256 1.30 macallan aval = *fr;
257 1.30 macallan fr++;
258 1.30 macallan if (aval == 0) {
259 1.30 macallan pixel = bg;
260 1.30 macallan } else if (aval == 255) {
261 1.30 macallan pixel = fg;
262 1.30 macallan } else {
263 1.30 macallan r = aval * r1 + (255 - aval) * r0;
264 1.30 macallan g = aval * g1 + (255 - aval) * g0;
265 1.30 macallan b = aval * b1 + (255 - aval) * b0;
266 1.30 macallan pixel = ((r & 0xe000) >> 8) |
267 1.30 macallan ((g & 0xe000) >> 11) |
268 1.30 macallan ((b & 0xc000) >> 14);
269 1.30 macallan }
270 1.31 macallan scanline[x] = pixel;
271 1.30 macallan }
272 1.31 macallan memcpy(rp, scanline, width);
273 1.30 macallan if (ri->ri_hwbits) {
274 1.31 macallan memcpy(hrp, scanline, width);
275 1.30 macallan hrp += ri->ri_stride;
276 1.30 macallan }
277 1.30 macallan rp += ri->ri_stride;
278 1.30 macallan
279 1.30 macallan }
280 1.30 macallan }
281 1.30 macallan
282 1.30 macallan /* Do underline */
283 1.30 macallan if ((attr & 1) != 0) {
284 1.30 macallan
285 1.30 macallan rp -= (ri->ri_stride << 1);
286 1.30 macallan if (ri->ri_hwbits)
287 1.30 macallan hrp -= (ri->ri_stride << 1);
288 1.30 macallan
289 1.30 macallan while (width--) {
290 1.30 macallan *rp++ = fg;
291 1.30 macallan if (ri->ri_hwbits)
292 1.30 macallan *hrp++ = fg;
293 1.30 macallan }
294 1.30 macallan }
295 1.30 macallan }
296 1.30 macallan
297 1.7 ad #ifndef RASOPS_SMALL
298 1.1 ad /*
299 1.1 ad * Recompute the 4x1 blitting stamp.
300 1.1 ad */
301 1.1 ad static void
302 1.25 dsl rasops8_makestamp(struct rasops_info *ri, long attr)
303 1.1 ad {
304 1.7 ad int32_t fg, bg;
305 1.1 ad int i;
306 1.5 ad
307 1.8 pk fg = ri->ri_devcmap[(attr >> 24) & 0xf] & 0xff;
308 1.8 pk bg = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xff;
309 1.1 ad stamp_attr = attr;
310 1.8 pk
311 1.1 ad for (i = 0; i < 16; i++) {
312 1.16 uwe #if BYTE_ORDER == BIG_ENDIAN
313 1.16 uwe #define NEED_LITTLE_ENDIAN_STAMP RI_BSWAP
314 1.1 ad #else
315 1.16 uwe #define NEED_LITTLE_ENDIAN_STAMP 0
316 1.1 ad #endif
317 1.16 uwe if ((ri->ri_flg & RI_BSWAP) == NEED_LITTLE_ENDIAN_STAMP) {
318 1.16 uwe /* little endian */
319 1.16 uwe stamp[i] = (i & 8 ? fg : bg);
320 1.16 uwe stamp[i] |= ((i & 4 ? fg : bg) << 8);
321 1.16 uwe stamp[i] |= ((i & 2 ? fg : bg) << 16);
322 1.16 uwe stamp[i] |= ((i & 1 ? fg : bg) << 24);
323 1.16 uwe } else {
324 1.16 uwe /* big endian */
325 1.16 uwe stamp[i] = (i & 1 ? fg : bg);
326 1.16 uwe stamp[i] |= ((i & 2 ? fg : bg) << 8);
327 1.16 uwe stamp[i] |= ((i & 4 ? fg : bg) << 16);
328 1.16 uwe stamp[i] |= ((i & 8 ? fg : bg) << 24);
329 1.16 uwe }
330 1.1 ad }
331 1.1 ad }
332 1.1 ad
333 1.1 ad /*
334 1.3 ad * Put a single character. This is for 8-pixel wide fonts.
335 1.1 ad */
336 1.1 ad static void
337 1.26 dsl rasops8_putchar8(void *cookie, int row, int col, u_int uc, long attr)
338 1.1 ad {
339 1.27 macallan struct rasops_info *ri = (struct rasops_info *)cookie;
340 1.27 macallan struct wsdisplay_font *font = PICK_FONT(ri, uc);
341 1.1 ad int height, fs;
342 1.21 jmcneill int32_t *rp, *hp;
343 1.1 ad u_char *fr;
344 1.8 pk
345 1.1 ad /* Can't risk remaking the stamp if it's already in use */
346 1.1 ad if (stamp_mutex++) {
347 1.1 ad stamp_mutex--;
348 1.1 ad rasops8_putchar(cookie, row, col, uc, attr);
349 1.1 ad return;
350 1.1 ad }
351 1.1 ad
352 1.21 jmcneill hp = NULL;
353 1.1 ad
354 1.27 macallan if (!CHAR_IN_FONT(uc, font))
355 1.17 petrov return;
356 1.17 petrov
357 1.8 pk #ifdef RASOPS_CLIPPING
358 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows) {
359 1.1 ad stamp_mutex--;
360 1.1 ad return;
361 1.1 ad }
362 1.1 ad
363 1.1 ad if ((unsigned)col >= (unsigned)ri->ri_cols) {
364 1.1 ad stamp_mutex--;
365 1.1 ad return;
366 1.1 ad }
367 1.1 ad #endif
368 1.1 ad
369 1.1 ad /* Recompute stamp? */
370 1.1 ad if (attr != stamp_attr)
371 1.6 ad rasops8_makestamp(ri, attr);
372 1.8 pk
373 1.1 ad rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
374 1.21 jmcneill if (ri->ri_hwbits)
375 1.21 jmcneill hp = (int32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
376 1.21 jmcneill col*ri->ri_xscale);
377 1.27 macallan height = font->fontheight;
378 1.8 pk
379 1.1 ad if (uc == ' ') {
380 1.1 ad while (height--) {
381 1.8 pk rp[0] = rp[1] = stamp[0];
382 1.1 ad DELTA(rp, ri->ri_stride, int32_t *);
383 1.21 jmcneill if (ri->ri_hwbits) {
384 1.23 jmcneill hp[0] = stamp[0];
385 1.23 jmcneill hp[1] = stamp[0];
386 1.21 jmcneill DELTA(hp, ri->ri_stride, int32_t *);
387 1.21 jmcneill }
388 1.8 pk }
389 1.1 ad } else {
390 1.29 macallan fr = WSFONT_GLYPH(uc, font);
391 1.27 macallan fs = font->stride;
392 1.8 pk
393 1.1 ad while (height--) {
394 1.1 ad rp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
395 1.1 ad rp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
396 1.21 jmcneill if (ri->ri_hwbits) {
397 1.21 jmcneill hp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) &
398 1.21 jmcneill STAMP_MASK);
399 1.21 jmcneill hp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) &
400 1.21 jmcneill STAMP_MASK);
401 1.21 jmcneill }
402 1.1 ad
403 1.1 ad fr += fs;
404 1.8 pk DELTA(rp, ri->ri_stride, int32_t *);
405 1.21 jmcneill if (ri->ri_hwbits)
406 1.21 jmcneill DELTA(hp, ri->ri_stride, int32_t *);
407 1.1 ad }
408 1.1 ad }
409 1.1 ad
410 1.1 ad /* Do underline */
411 1.7 ad if ((attr & 1) != 0) {
412 1.8 pk DELTA(rp, -(ri->ri_stride << 1), int32_t *);
413 1.8 pk rp[0] = rp[1] = stamp[15];
414 1.21 jmcneill if (ri->ri_hwbits) {
415 1.21 jmcneill DELTA(hp, -(ri->ri_stride << 1), int32_t *);
416 1.23 jmcneill hp[0] = stamp[15];
417 1.23 jmcneill hp[1] = stamp[15];
418 1.21 jmcneill }
419 1.8 pk }
420 1.8 pk
421 1.8 pk stamp_mutex--;
422 1.1 ad }
423 1.1 ad
424 1.1 ad /*
425 1.3 ad * Put a single character. This is for 12-pixel wide fonts.
426 1.1 ad */
427 1.1 ad static void
428 1.26 dsl rasops8_putchar12(void *cookie, int row, int col, u_int uc, long attr)
429 1.1 ad {
430 1.27 macallan struct rasops_info *ri = (struct rasops_info *)cookie;
431 1.27 macallan struct wsdisplay_font *font = PICK_FONT(ri, uc);
432 1.1 ad int height, fs;
433 1.21 jmcneill int32_t *rp, *hrp;
434 1.1 ad u_char *fr;
435 1.8 pk
436 1.1 ad /* Can't risk remaking the stamp if it's already in use */
437 1.1 ad if (stamp_mutex++) {
438 1.1 ad stamp_mutex--;
439 1.1 ad rasops8_putchar(cookie, row, col, uc, attr);
440 1.1 ad return;
441 1.1 ad }
442 1.1 ad
443 1.21 jmcneill hrp = NULL;
444 1.1 ad
445 1.27 macallan if (!CHAR_IN_FONT(uc, font))
446 1.17 petrov return;
447 1.17 petrov
448 1.8 pk #ifdef RASOPS_CLIPPING
449 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows) {
450 1.1 ad stamp_mutex--;
451 1.1 ad return;
452 1.1 ad }
453 1.1 ad
454 1.1 ad if ((unsigned)col >= (unsigned)ri->ri_cols) {
455 1.1 ad stamp_mutex--;
456 1.1 ad return;
457 1.1 ad }
458 1.1 ad #endif
459 1.1 ad
460 1.1 ad /* Recompute stamp? */
461 1.1 ad if (attr != stamp_attr)
462 1.6 ad rasops8_makestamp(ri, attr);
463 1.8 pk
464 1.1 ad rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
465 1.21 jmcneill if (ri->ri_hwbits)
466 1.21 jmcneill hrp = (int32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
467 1.21 jmcneill col*ri->ri_xscale);
468 1.27 macallan height = font->fontheight;
469 1.8 pk
470 1.1 ad if (uc == ' ') {
471 1.1 ad while (height--) {
472 1.8 pk int32_t c = stamp[0];
473 1.8 pk
474 1.8 pk rp[0] = rp[1] = rp[2] = c;
475 1.8 pk DELTA(rp, ri->ri_stride, int32_t *);
476 1.21 jmcneill if (ri->ri_hwbits) {
477 1.23 jmcneill hrp[0] = c;
478 1.23 jmcneill hrp[1] = c;
479 1.23 jmcneill hrp[2] = c;
480 1.21 jmcneill DELTA(hrp, ri->ri_stride, int32_t *);
481 1.21 jmcneill }
482 1.8 pk }
483 1.1 ad } else {
484 1.29 macallan fr = WSFONT_GLYPH(uc, font);
485 1.27 macallan fs = font->stride;
486 1.8 pk
487 1.1 ad while (height--) {
488 1.1 ad rp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
489 1.1 ad rp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
490 1.1 ad rp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) & STAMP_MASK);
491 1.21 jmcneill if (ri->ri_hwbits) {
492 1.21 jmcneill hrp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
493 1.21 jmcneill hrp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
494 1.21 jmcneill hrp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) & STAMP_MASK);
495 1.21 jmcneill }
496 1.8 pk
497 1.1 ad fr += fs;
498 1.8 pk DELTA(rp, ri->ri_stride, int32_t *);
499 1.21 jmcneill if (ri->ri_hwbits)
500 1.21 jmcneill DELTA(hrp, ri->ri_stride, int32_t *);
501 1.1 ad }
502 1.8 pk }
503 1.1 ad
504 1.1 ad /* Do underline */
505 1.7 ad if ((attr & 1) != 0) {
506 1.8 pk DELTA(rp, -(ri->ri_stride << 1), int32_t *);
507 1.8 pk rp[0] = rp[1] = rp[2] = stamp[15];
508 1.21 jmcneill if (ri->ri_hwbits) {
509 1.21 jmcneill DELTA(hrp, -(ri->ri_stride << 1), int32_t *);
510 1.23 jmcneill hrp[0] = stamp[15];
511 1.23 jmcneill hrp[1] = stamp[15];
512 1.23 jmcneill hrp[2] = stamp[15];
513 1.21 jmcneill }
514 1.8 pk }
515 1.8 pk
516 1.1 ad stamp_mutex--;
517 1.1 ad }
518 1.1 ad
519 1.1 ad /*
520 1.3 ad * Put a single character. This is for 16-pixel wide fonts.
521 1.1 ad */
522 1.1 ad static void
523 1.26 dsl rasops8_putchar16(void *cookie, int row, int col, u_int uc, long attr)
524 1.1 ad {
525 1.27 macallan struct rasops_info *ri = (struct rasops_info *)cookie;
526 1.27 macallan struct wsdisplay_font *font = PICK_FONT(ri, uc);
527 1.1 ad int height, fs;
528 1.21 jmcneill int32_t *rp, *hrp;
529 1.1 ad u_char *fr;
530 1.1 ad
531 1.1 ad /* Can't risk remaking the stamp if it's already in use */
532 1.1 ad if (stamp_mutex++) {
533 1.1 ad stamp_mutex--;
534 1.1 ad rasops8_putchar(cookie, row, col, uc, attr);
535 1.1 ad return;
536 1.1 ad }
537 1.1 ad
538 1.21 jmcneill hrp = NULL;
539 1.1 ad
540 1.27 macallan if (!CHAR_IN_FONT(uc, font))
541 1.17 petrov return;
542 1.17 petrov
543 1.8 pk #ifdef RASOPS_CLIPPING
544 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows) {
545 1.1 ad stamp_mutex--;
546 1.1 ad return;
547 1.1 ad }
548 1.1 ad
549 1.1 ad if ((unsigned)col >= (unsigned)ri->ri_cols) {
550 1.1 ad stamp_mutex--;
551 1.1 ad return;
552 1.1 ad }
553 1.1 ad #endif
554 1.1 ad
555 1.1 ad /* Recompute stamp? */
556 1.1 ad if (attr != stamp_attr)
557 1.6 ad rasops8_makestamp(ri, attr);
558 1.8 pk
559 1.1 ad rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
560 1.21 jmcneill if (ri->ri_hwbits)
561 1.21 jmcneill hrp = (int32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
562 1.21 jmcneill col*ri->ri_xscale);
563 1.21 jmcneill
564 1.27 macallan height = font->fontheight;
565 1.8 pk
566 1.1 ad if (uc == ' ') {
567 1.21 jmcneill while (height--) {
568 1.8 pk rp[0] = rp[1] = rp[2] = rp[3] = stamp[0];
569 1.23 jmcneill if (ri->ri_hwbits) {
570 1.23 jmcneill hrp[0] = stamp[0];
571 1.23 jmcneill hrp[1] = stamp[0];
572 1.23 jmcneill hrp[2] = stamp[0];
573 1.23 jmcneill hrp[3] = stamp[0];
574 1.23 jmcneill }
575 1.21 jmcneill }
576 1.1 ad } else {
577 1.29 macallan fr = WSFONT_GLYPH(uc, font);
578 1.27 macallan fs = font->stride;
579 1.8 pk
580 1.1 ad while (height--) {
581 1.1 ad rp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
582 1.1 ad rp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
583 1.1 ad rp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) & STAMP_MASK);
584 1.1 ad rp[3] = STAMP_READ(STAMP_SHIFT(fr[1], 0) & STAMP_MASK);
585 1.21 jmcneill if (ri->ri_hwbits) {
586 1.21 jmcneill hrp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
587 1.21 jmcneill hrp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
588 1.21 jmcneill hrp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) & STAMP_MASK);
589 1.21 jmcneill hrp[3] = STAMP_READ(STAMP_SHIFT(fr[1], 0) & STAMP_MASK);
590 1.21 jmcneill }
591 1.1 ad
592 1.1 ad fr += fs;
593 1.8 pk DELTA(rp, ri->ri_stride, int32_t *);
594 1.21 jmcneill if (ri->ri_hwbits)
595 1.21 jmcneill DELTA(hrp, ri->ri_stride, int32_t *);
596 1.1 ad }
597 1.8 pk }
598 1.1 ad
599 1.1 ad /* Do underline */
600 1.7 ad if ((attr & 1) != 0) {
601 1.8 pk DELTA(rp, -(ri->ri_stride << 1), int32_t *);
602 1.8 pk rp[0] = rp[1] = rp[2] = rp[3] = stamp[15];
603 1.21 jmcneill if (ri->ri_hwbits) {
604 1.21 jmcneill DELTA(hrp, -(ri->ri_stride << 1), int32_t *);
605 1.23 jmcneill hrp[0] = stamp[15];
606 1.23 jmcneill hrp[1] = stamp[15];
607 1.23 jmcneill hrp[2] = stamp[15];
608 1.23 jmcneill hrp[3] = stamp[15];
609 1.21 jmcneill }
610 1.8 pk }
611 1.8 pk
612 1.1 ad stamp_mutex--;
613 1.1 ad }
614 1.7 ad #endif /* !RASOPS_SMALL */
615