rasops8.c revision 1.31 1 1.31 macallan /* $NetBSD: rasops8.c,v 1.31 2012/01/25 16:38:27 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.31 macallan __KERNEL_RCSID(0, "$NetBSD: rasops8.c,v 1.31 2012/01/25 16:38:27 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.1 ad dp = rp;
148 1.1 ad rp += ri->ri_stride;
149 1.21 jmcneill if (ri->ri_hwbits) {
150 1.21 jmcneill hp = hrp;
151 1.21 jmcneill hrp += ri->ri_stride;
152 1.21 jmcneill }
153 1.8 pk
154 1.21 jmcneill for (cnt = width; cnt; cnt--) {
155 1.8 pk *dp++ = c;
156 1.21 jmcneill if (ri->ri_hwbits)
157 1.21 jmcneill *hp++ = c;
158 1.21 jmcneill }
159 1.1 ad }
160 1.1 ad } else {
161 1.29 macallan fr = WSFONT_GLYPH(uc, font);
162 1.27 macallan fs = font->stride;
163 1.1 ad
164 1.1 ad while (height--) {
165 1.1 ad dp = rp;
166 1.21 jmcneill if (ri->ri_hwbits)
167 1.21 jmcneill hp = hrp;
168 1.1 ad fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) | (fr[0] << 24);
169 1.1 ad fr += fs;
170 1.1 ad rp += ri->ri_stride;
171 1.21 jmcneill if (ri->ri_hwbits)
172 1.21 jmcneill hrp += ri->ri_stride;
173 1.8 pk
174 1.1 ad for (cnt = width; cnt; cnt--) {
175 1.1 ad *dp++ = clr[(fb >> 31) & 1];
176 1.21 jmcneill if (ri->ri_hwbits)
177 1.21 jmcneill *hp++ = clr[(fb >> 31) & 1];
178 1.1 ad fb <<= 1;
179 1.1 ad }
180 1.1 ad }
181 1.8 pk }
182 1.1 ad
183 1.1 ad /* Do underline */
184 1.7 ad if ((attr & 1) != 0) {
185 1.8 pk u_char c = clr[1];
186 1.8 pk
187 1.1 ad rp -= (ri->ri_stride << 1);
188 1.21 jmcneill if (ri->ri_hwbits)
189 1.21 jmcneill hrp -= (ri->ri_stride << 1);
190 1.1 ad
191 1.21 jmcneill while (width--) {
192 1.8 pk *rp++ = c;
193 1.21 jmcneill if (ri->ri_hwbits)
194 1.21 jmcneill *hrp++ = c;
195 1.21 jmcneill }
196 1.8 pk }
197 1.1 ad }
198 1.1 ad
199 1.30 macallan static void
200 1.30 macallan rasops8_putchar_aa(void *cookie, int row, int col, u_int uc, long attr)
201 1.30 macallan {
202 1.30 macallan int width, height, cnt, fs;
203 1.30 macallan u_char *dp, *rp, *hp, *hrp, *fr, bg, fg, pixel;
204 1.30 macallan struct rasops_info *ri = (struct rasops_info *)cookie;
205 1.30 macallan struct wsdisplay_font *font = PICK_FONT(ri, uc);
206 1.30 macallan int x, y, r, g, b, aval;
207 1.30 macallan int r1, g1, b1, r0, g0, b0, fgo, bgo;
208 1.31 macallan uint8_t scanline[32] __attribute__ ((aligned(8)));
209 1.30 macallan
210 1.30 macallan hp = hrp = NULL;
211 1.30 macallan
212 1.30 macallan if (!CHAR_IN_FONT(uc, font))
213 1.30 macallan return;
214 1.30 macallan
215 1.30 macallan #ifdef RASOPS_CLIPPING
216 1.30 macallan /* Catches 'row < 0' case too */
217 1.30 macallan if ((unsigned)row >= (unsigned)ri->ri_rows)
218 1.30 macallan return;
219 1.30 macallan
220 1.30 macallan if ((unsigned)col >= (unsigned)ri->ri_cols)
221 1.30 macallan return;
222 1.30 macallan #endif
223 1.30 macallan rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
224 1.30 macallan if (ri->ri_hwbits)
225 1.30 macallan hrp = ri->ri_hwbits + row * ri->ri_yscale + col *
226 1.30 macallan ri->ri_xscale;
227 1.30 macallan
228 1.30 macallan height = font->fontheight;
229 1.30 macallan width = font->fontwidth;
230 1.30 macallan bg = (u_char)ri->ri_devcmap[(attr >> 16) & 0xf];
231 1.30 macallan fg = (u_char)ri->ri_devcmap[(attr >> 24) & 0xf];
232 1.30 macallan
233 1.30 macallan if (uc == ' ') {
234 1.30 macallan
235 1.30 macallan while (height--) {
236 1.30 macallan dp = rp;
237 1.30 macallan rp += ri->ri_stride;
238 1.30 macallan if (ri->ri_hwbits) {
239 1.30 macallan hp = hrp;
240 1.30 macallan hrp += ri->ri_stride;
241 1.30 macallan }
242 1.30 macallan
243 1.30 macallan for (cnt = width; cnt; cnt--) {
244 1.30 macallan *dp++ = bg;
245 1.30 macallan if (ri->ri_hwbits)
246 1.30 macallan *hp++ = bg;
247 1.30 macallan }
248 1.30 macallan }
249 1.30 macallan } else {
250 1.30 macallan fr = WSFONT_GLYPH(uc, font);
251 1.30 macallan fs = font->stride;
252 1.30 macallan /*
253 1.30 macallan * we need the RGB colours here, get offsets into rasops_cmap
254 1.30 macallan */
255 1.30 macallan fgo = ((attr >> 24) & 0xf) * 3;
256 1.30 macallan bgo = ((attr >> 16) & 0xf) * 3;
257 1.30 macallan
258 1.30 macallan r0 = rasops_cmap[bgo];
259 1.30 macallan r1 = rasops_cmap[fgo];
260 1.30 macallan g0 = rasops_cmap[bgo + 1];
261 1.30 macallan g1 = rasops_cmap[fgo + 1];
262 1.30 macallan b0 = rasops_cmap[bgo + 2];
263 1.30 macallan b1 = rasops_cmap[fgo + 2];
264 1.30 macallan
265 1.30 macallan for (y = 0; y < height; y++) {
266 1.30 macallan dp = rp;
267 1.30 macallan for (x = 0; x < width; x++) {
268 1.30 macallan aval = *fr;
269 1.30 macallan fr++;
270 1.30 macallan if (aval == 0) {
271 1.30 macallan pixel = bg;
272 1.30 macallan } else if (aval == 255) {
273 1.30 macallan pixel = fg;
274 1.30 macallan } else {
275 1.30 macallan r = aval * r1 + (255 - aval) * r0;
276 1.30 macallan g = aval * g1 + (255 - aval) * g0;
277 1.30 macallan b = aval * b1 + (255 - aval) * b0;
278 1.30 macallan pixel = ((r & 0xe000) >> 8) |
279 1.30 macallan ((g & 0xe000) >> 11) |
280 1.30 macallan ((b & 0xc000) >> 14);
281 1.30 macallan }
282 1.31 macallan scanline[x] = pixel;
283 1.30 macallan }
284 1.31 macallan memcpy(rp, scanline, width);
285 1.30 macallan if (ri->ri_hwbits) {
286 1.31 macallan memcpy(hrp, scanline, width);
287 1.30 macallan hrp += ri->ri_stride;
288 1.30 macallan }
289 1.30 macallan rp += ri->ri_stride;
290 1.30 macallan
291 1.30 macallan }
292 1.30 macallan }
293 1.30 macallan
294 1.30 macallan /* Do underline */
295 1.30 macallan if ((attr & 1) != 0) {
296 1.30 macallan
297 1.30 macallan rp -= (ri->ri_stride << 1);
298 1.30 macallan if (ri->ri_hwbits)
299 1.30 macallan hrp -= (ri->ri_stride << 1);
300 1.30 macallan
301 1.30 macallan while (width--) {
302 1.30 macallan *rp++ = fg;
303 1.30 macallan if (ri->ri_hwbits)
304 1.30 macallan *hrp++ = fg;
305 1.30 macallan }
306 1.30 macallan }
307 1.30 macallan }
308 1.30 macallan
309 1.7 ad #ifndef RASOPS_SMALL
310 1.1 ad /*
311 1.1 ad * Recompute the 4x1 blitting stamp.
312 1.1 ad */
313 1.1 ad static void
314 1.25 dsl rasops8_makestamp(struct rasops_info *ri, long attr)
315 1.1 ad {
316 1.7 ad int32_t fg, bg;
317 1.1 ad int i;
318 1.5 ad
319 1.8 pk fg = ri->ri_devcmap[(attr >> 24) & 0xf] & 0xff;
320 1.8 pk bg = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xff;
321 1.1 ad stamp_attr = attr;
322 1.8 pk
323 1.1 ad for (i = 0; i < 16; i++) {
324 1.16 uwe #if BYTE_ORDER == BIG_ENDIAN
325 1.16 uwe #define NEED_LITTLE_ENDIAN_STAMP RI_BSWAP
326 1.1 ad #else
327 1.16 uwe #define NEED_LITTLE_ENDIAN_STAMP 0
328 1.1 ad #endif
329 1.16 uwe if ((ri->ri_flg & RI_BSWAP) == NEED_LITTLE_ENDIAN_STAMP) {
330 1.16 uwe /* little endian */
331 1.16 uwe stamp[i] = (i & 8 ? fg : bg);
332 1.16 uwe stamp[i] |= ((i & 4 ? fg : bg) << 8);
333 1.16 uwe stamp[i] |= ((i & 2 ? fg : bg) << 16);
334 1.16 uwe stamp[i] |= ((i & 1 ? fg : bg) << 24);
335 1.16 uwe } else {
336 1.16 uwe /* big endian */
337 1.16 uwe stamp[i] = (i & 1 ? fg : bg);
338 1.16 uwe stamp[i] |= ((i & 2 ? fg : bg) << 8);
339 1.16 uwe stamp[i] |= ((i & 4 ? fg : bg) << 16);
340 1.16 uwe stamp[i] |= ((i & 8 ? fg : bg) << 24);
341 1.16 uwe }
342 1.1 ad }
343 1.1 ad }
344 1.1 ad
345 1.1 ad /*
346 1.3 ad * Put a single character. This is for 8-pixel wide fonts.
347 1.1 ad */
348 1.1 ad static void
349 1.26 dsl rasops8_putchar8(void *cookie, int row, int col, u_int uc, long attr)
350 1.1 ad {
351 1.27 macallan struct rasops_info *ri = (struct rasops_info *)cookie;
352 1.27 macallan struct wsdisplay_font *font = PICK_FONT(ri, uc);
353 1.1 ad int height, fs;
354 1.21 jmcneill int32_t *rp, *hp;
355 1.1 ad u_char *fr;
356 1.8 pk
357 1.1 ad /* Can't risk remaking the stamp if it's already in use */
358 1.1 ad if (stamp_mutex++) {
359 1.1 ad stamp_mutex--;
360 1.1 ad rasops8_putchar(cookie, row, col, uc, attr);
361 1.1 ad return;
362 1.1 ad }
363 1.1 ad
364 1.21 jmcneill hp = NULL;
365 1.1 ad
366 1.27 macallan if (!CHAR_IN_FONT(uc, font))
367 1.17 petrov return;
368 1.17 petrov
369 1.8 pk #ifdef RASOPS_CLIPPING
370 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows) {
371 1.1 ad stamp_mutex--;
372 1.1 ad return;
373 1.1 ad }
374 1.1 ad
375 1.1 ad if ((unsigned)col >= (unsigned)ri->ri_cols) {
376 1.1 ad stamp_mutex--;
377 1.1 ad return;
378 1.1 ad }
379 1.1 ad #endif
380 1.1 ad
381 1.1 ad /* Recompute stamp? */
382 1.1 ad if (attr != stamp_attr)
383 1.6 ad rasops8_makestamp(ri, attr);
384 1.8 pk
385 1.1 ad rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
386 1.21 jmcneill if (ri->ri_hwbits)
387 1.21 jmcneill hp = (int32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
388 1.21 jmcneill col*ri->ri_xscale);
389 1.27 macallan height = font->fontheight;
390 1.8 pk
391 1.1 ad if (uc == ' ') {
392 1.1 ad while (height--) {
393 1.8 pk rp[0] = rp[1] = stamp[0];
394 1.1 ad DELTA(rp, ri->ri_stride, int32_t *);
395 1.21 jmcneill if (ri->ri_hwbits) {
396 1.23 jmcneill hp[0] = stamp[0];
397 1.23 jmcneill hp[1] = stamp[0];
398 1.21 jmcneill DELTA(hp, ri->ri_stride, int32_t *);
399 1.21 jmcneill }
400 1.8 pk }
401 1.1 ad } else {
402 1.29 macallan fr = WSFONT_GLYPH(uc, font);
403 1.27 macallan fs = font->stride;
404 1.8 pk
405 1.1 ad while (height--) {
406 1.1 ad rp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
407 1.1 ad rp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
408 1.21 jmcneill if (ri->ri_hwbits) {
409 1.21 jmcneill hp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) &
410 1.21 jmcneill STAMP_MASK);
411 1.21 jmcneill hp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) &
412 1.21 jmcneill STAMP_MASK);
413 1.21 jmcneill }
414 1.1 ad
415 1.1 ad fr += fs;
416 1.8 pk DELTA(rp, ri->ri_stride, int32_t *);
417 1.21 jmcneill if (ri->ri_hwbits)
418 1.21 jmcneill DELTA(hp, ri->ri_stride, int32_t *);
419 1.1 ad }
420 1.1 ad }
421 1.1 ad
422 1.1 ad /* Do underline */
423 1.7 ad if ((attr & 1) != 0) {
424 1.8 pk DELTA(rp, -(ri->ri_stride << 1), int32_t *);
425 1.8 pk rp[0] = rp[1] = stamp[15];
426 1.21 jmcneill if (ri->ri_hwbits) {
427 1.21 jmcneill DELTA(hp, -(ri->ri_stride << 1), int32_t *);
428 1.23 jmcneill hp[0] = stamp[15];
429 1.23 jmcneill hp[1] = stamp[15];
430 1.21 jmcneill }
431 1.8 pk }
432 1.8 pk
433 1.8 pk stamp_mutex--;
434 1.1 ad }
435 1.1 ad
436 1.1 ad /*
437 1.3 ad * Put a single character. This is for 12-pixel wide fonts.
438 1.1 ad */
439 1.1 ad static void
440 1.26 dsl rasops8_putchar12(void *cookie, int row, int col, u_int uc, long attr)
441 1.1 ad {
442 1.27 macallan struct rasops_info *ri = (struct rasops_info *)cookie;
443 1.27 macallan struct wsdisplay_font *font = PICK_FONT(ri, uc);
444 1.1 ad int height, fs;
445 1.21 jmcneill int32_t *rp, *hrp;
446 1.1 ad u_char *fr;
447 1.8 pk
448 1.1 ad /* Can't risk remaking the stamp if it's already in use */
449 1.1 ad if (stamp_mutex++) {
450 1.1 ad stamp_mutex--;
451 1.1 ad rasops8_putchar(cookie, row, col, uc, attr);
452 1.1 ad return;
453 1.1 ad }
454 1.1 ad
455 1.21 jmcneill hrp = NULL;
456 1.1 ad
457 1.27 macallan if (!CHAR_IN_FONT(uc, font))
458 1.17 petrov return;
459 1.17 petrov
460 1.8 pk #ifdef RASOPS_CLIPPING
461 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows) {
462 1.1 ad stamp_mutex--;
463 1.1 ad return;
464 1.1 ad }
465 1.1 ad
466 1.1 ad if ((unsigned)col >= (unsigned)ri->ri_cols) {
467 1.1 ad stamp_mutex--;
468 1.1 ad return;
469 1.1 ad }
470 1.1 ad #endif
471 1.1 ad
472 1.1 ad /* Recompute stamp? */
473 1.1 ad if (attr != stamp_attr)
474 1.6 ad rasops8_makestamp(ri, attr);
475 1.8 pk
476 1.1 ad rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
477 1.21 jmcneill if (ri->ri_hwbits)
478 1.21 jmcneill hrp = (int32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
479 1.21 jmcneill col*ri->ri_xscale);
480 1.27 macallan height = font->fontheight;
481 1.8 pk
482 1.1 ad if (uc == ' ') {
483 1.1 ad while (height--) {
484 1.8 pk int32_t c = stamp[0];
485 1.8 pk
486 1.8 pk rp[0] = rp[1] = rp[2] = c;
487 1.8 pk DELTA(rp, ri->ri_stride, int32_t *);
488 1.21 jmcneill if (ri->ri_hwbits) {
489 1.23 jmcneill hrp[0] = c;
490 1.23 jmcneill hrp[1] = c;
491 1.23 jmcneill hrp[2] = c;
492 1.21 jmcneill DELTA(hrp, ri->ri_stride, int32_t *);
493 1.21 jmcneill }
494 1.8 pk }
495 1.1 ad } else {
496 1.29 macallan fr = WSFONT_GLYPH(uc, font);
497 1.27 macallan fs = font->stride;
498 1.8 pk
499 1.1 ad while (height--) {
500 1.1 ad rp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
501 1.1 ad rp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
502 1.1 ad rp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) & STAMP_MASK);
503 1.21 jmcneill if (ri->ri_hwbits) {
504 1.21 jmcneill hrp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
505 1.21 jmcneill hrp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
506 1.21 jmcneill hrp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) & STAMP_MASK);
507 1.21 jmcneill }
508 1.8 pk
509 1.1 ad fr += fs;
510 1.8 pk DELTA(rp, ri->ri_stride, int32_t *);
511 1.21 jmcneill if (ri->ri_hwbits)
512 1.21 jmcneill DELTA(hrp, ri->ri_stride, int32_t *);
513 1.1 ad }
514 1.8 pk }
515 1.1 ad
516 1.1 ad /* Do underline */
517 1.7 ad if ((attr & 1) != 0) {
518 1.8 pk DELTA(rp, -(ri->ri_stride << 1), int32_t *);
519 1.8 pk rp[0] = rp[1] = rp[2] = stamp[15];
520 1.21 jmcneill if (ri->ri_hwbits) {
521 1.21 jmcneill DELTA(hrp, -(ri->ri_stride << 1), int32_t *);
522 1.23 jmcneill hrp[0] = stamp[15];
523 1.23 jmcneill hrp[1] = stamp[15];
524 1.23 jmcneill hrp[2] = stamp[15];
525 1.21 jmcneill }
526 1.8 pk }
527 1.8 pk
528 1.1 ad stamp_mutex--;
529 1.1 ad }
530 1.1 ad
531 1.1 ad /*
532 1.3 ad * Put a single character. This is for 16-pixel wide fonts.
533 1.1 ad */
534 1.1 ad static void
535 1.26 dsl rasops8_putchar16(void *cookie, int row, int col, u_int uc, long attr)
536 1.1 ad {
537 1.27 macallan struct rasops_info *ri = (struct rasops_info *)cookie;
538 1.27 macallan struct wsdisplay_font *font = PICK_FONT(ri, uc);
539 1.1 ad int height, fs;
540 1.21 jmcneill int32_t *rp, *hrp;
541 1.1 ad u_char *fr;
542 1.1 ad
543 1.1 ad /* Can't risk remaking the stamp if it's already in use */
544 1.1 ad if (stamp_mutex++) {
545 1.1 ad stamp_mutex--;
546 1.1 ad rasops8_putchar(cookie, row, col, uc, attr);
547 1.1 ad return;
548 1.1 ad }
549 1.1 ad
550 1.21 jmcneill hrp = NULL;
551 1.1 ad
552 1.27 macallan if (!CHAR_IN_FONT(uc, font))
553 1.17 petrov return;
554 1.17 petrov
555 1.8 pk #ifdef RASOPS_CLIPPING
556 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows) {
557 1.1 ad stamp_mutex--;
558 1.1 ad return;
559 1.1 ad }
560 1.1 ad
561 1.1 ad if ((unsigned)col >= (unsigned)ri->ri_cols) {
562 1.1 ad stamp_mutex--;
563 1.1 ad return;
564 1.1 ad }
565 1.1 ad #endif
566 1.1 ad
567 1.1 ad /* Recompute stamp? */
568 1.1 ad if (attr != stamp_attr)
569 1.6 ad rasops8_makestamp(ri, attr);
570 1.8 pk
571 1.1 ad rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
572 1.21 jmcneill if (ri->ri_hwbits)
573 1.21 jmcneill hrp = (int32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
574 1.21 jmcneill col*ri->ri_xscale);
575 1.21 jmcneill
576 1.27 macallan height = font->fontheight;
577 1.8 pk
578 1.1 ad if (uc == ' ') {
579 1.21 jmcneill while (height--) {
580 1.8 pk rp[0] = rp[1] = rp[2] = rp[3] = stamp[0];
581 1.23 jmcneill if (ri->ri_hwbits) {
582 1.23 jmcneill hrp[0] = stamp[0];
583 1.23 jmcneill hrp[1] = stamp[0];
584 1.23 jmcneill hrp[2] = stamp[0];
585 1.23 jmcneill hrp[3] = stamp[0];
586 1.23 jmcneill }
587 1.21 jmcneill }
588 1.1 ad } else {
589 1.29 macallan fr = WSFONT_GLYPH(uc, font);
590 1.27 macallan fs = font->stride;
591 1.8 pk
592 1.1 ad while (height--) {
593 1.1 ad rp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
594 1.1 ad rp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
595 1.1 ad rp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) & STAMP_MASK);
596 1.1 ad rp[3] = STAMP_READ(STAMP_SHIFT(fr[1], 0) & STAMP_MASK);
597 1.21 jmcneill if (ri->ri_hwbits) {
598 1.21 jmcneill hrp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
599 1.21 jmcneill hrp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
600 1.21 jmcneill hrp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) & STAMP_MASK);
601 1.21 jmcneill hrp[3] = STAMP_READ(STAMP_SHIFT(fr[1], 0) & STAMP_MASK);
602 1.21 jmcneill }
603 1.1 ad
604 1.1 ad fr += fs;
605 1.8 pk DELTA(rp, ri->ri_stride, int32_t *);
606 1.21 jmcneill if (ri->ri_hwbits)
607 1.21 jmcneill DELTA(hrp, ri->ri_stride, int32_t *);
608 1.1 ad }
609 1.8 pk }
610 1.1 ad
611 1.1 ad /* Do underline */
612 1.7 ad if ((attr & 1) != 0) {
613 1.8 pk DELTA(rp, -(ri->ri_stride << 1), int32_t *);
614 1.8 pk rp[0] = rp[1] = rp[2] = rp[3] = stamp[15];
615 1.21 jmcneill if (ri->ri_hwbits) {
616 1.21 jmcneill DELTA(hrp, -(ri->ri_stride << 1), int32_t *);
617 1.23 jmcneill hrp[0] = stamp[15];
618 1.23 jmcneill hrp[1] = stamp[15];
619 1.23 jmcneill hrp[2] = stamp[15];
620 1.23 jmcneill hrp[3] = stamp[15];
621 1.21 jmcneill }
622 1.8 pk }
623 1.8 pk
624 1.1 ad stamp_mutex--;
625 1.1 ad }
626 1.7 ad #endif /* !RASOPS_SMALL */
627